31#define CACHED_BITSTREAM_READER !ARCH_X86_32
33#include "config_components.h"
72 const int16_t switch_bits =
codebook >> 8;
73 const int16_t rice_order =
codebook & 0xf;
74 const int16_t exp_order = (
codebook >> 4) & 0xf;
84 return (
b & 0x7FFFFFFF) >> (31 - rice_order);
87 if (q <= switch_bits) {
89 return (q << rice_order) +
90 (((
b << (q + 1)) >> 1) >> (31 - rice_order));
93 bits = exp_order + (q << 1) - switch_bits;
97 return (
b >> (32 -
bits)) +
98 ((switch_bits + 1) << rice_order) -
102#define TODCCODEBOOK(x) ((x + 1) >> 1)
106 0x010, 0x021, 0x032, 0x033, 0x033, 0x033, 0x044, 0x044, 0x044, 0x044, 0x044, 0x044, 0x076,
111 0x000, 0x211, 0x111, 0x111, 0x222, 0x222, 0x222, 0x122, 0x122, 0x122,
112 0x233, 0x233, 0x233, 0x233, 0x233, 0x233, 0x233, 0x233, 0x133, 0x133,
113 0x244, 0x244, 0x244, 0x244, 0x244, 0x244, 0x244, 0x244, 0x244, 0x244, 0x244,
114 0x244, 0x244, 0x244, 0x244, 0x244, 0x244, 0x244, 0x244, 0x244, 0x244, 0x244,
115 0x355, 0x355, 0x355, 0x355, 0x355, 0x355, 0x355, 0x355, 0x355, 0x355, 0x355, 0x355, 0x355,
116 0x355, 0x355, 0x355, 0x355, 0x355, 0x355, 0x355, 0x355, 0x355, 0x355, 0x355, 0x355, 0x355,
117 0x355, 0x355, 0x355, 0x355, 0x355, 0x355, 0x355, 0x355, 0x355, 0x355, 0x355, 0x355, 0x355,
118 0x355, 0x355, 0x355, 0x355, 0x355, 0x355, 0x355, 0x355, 0x355, 0x355, 0x355, 0x355, 0x355, 0x166,
123 0x200, 0x100, 0x000, 0x000, 0x211, 0x211, 0x111, 0x111, 0x011, 0x011, 0x021, 0x021, 0x222, 0x022,
124 0x022, 0x022, 0x022, 0x022, 0x022, 0x022, 0x022, 0x022, 0x022, 0x022, 0x022, 0x032, 0x032, 0x044
129 0x100, 0x111, 0x222, 0x222, 0x122, 0x122, 0x433, 0x433, 0x233, 0x233, 0x233, 0x233, 0x233, 0x233, 0x033,
134 int component, int16_t *qmat)
138 const ptrdiff_t linesize =
frame->linesize[0] >> 1;
142 const int log2_nb_blocks =
tile->log2_nb_blocks;
143 const int nb_blocks = 1 << log2_nb_blocks;
144 const int block_mask = nb_blocks - 1;
145 const int nb_codes = 64 * nb_blocks;
154 int16_t ac_codebook = 49;
155 int16_t rn_codebook = 0;
156 int16_t ln_codebook = 66;
158 const uint8_t *scan =
s->scan;
163 dst += component & 1;
168 memset(
block, 0, nb_blocks * 64 *
sizeof(*
block));
172 int prev_dc = (dc >> 1) ^ -(dc & 1);
173 block[0] = (((dc&1) + (dc>>1) ^ -(int)(dc & 1)) + (dc & 1)) + 1;
175 for (
int n = 1; n < nb_blocks; n++) {
186 sign = sign ^ dc & 1;
191 block[n*64] = prev_dc + 1;
194 for (
int n = nb_blocks; n <= nb_codes;) {
200 for (
int i = 0;
i < ln;
i++) {
204 if ((n +
i) >= nb_codes)
211 idx = scan[(n +
i) >> log2_nb_blocks] + (((n +
i) & block_mask) << 6);
212 block[idx] = ((ac + 1) ^ sign) - sign;
232 idx = scan[n >> log2_nb_blocks] + ((n & block_mask) << 6);
233 block[idx] = ((ac + 1) ^ sign) - sign;
241 for (
int n = 0; n < nb_blocks; n++) {
242 uint16_t *ptr =
dst + n*16;
243 s->prodsp.idct_put_bayer(ptr, linesize,
block + n*64, qmat,
s->lin_curve);
262 int header_len = bytestream2_get_byteu(gb) >> 3;
263 int16_t
scale = bytestream2_get_byteu(gb);
266 size[0] = bytestream2_get_be16(gb);
267 size[1] = bytestream2_get_be16(gb);
268 size[2] = bytestream2_get_be16(gb);
273 for (
int i = 0;
i < 64;
i++)
276 const uint8_t *comp_start = gb->
buffer_start + header_len;
305 int n,
int thread_nb)
318#if CONFIG_PRORES_RAW_VULKAN_HWACCEL
321#if CONFIG_PRORES_RAW_VIDEOTOOLBOX_HWACCEL
336 int ret, dimensions_changed = 0, old_version =
s->version;
346 case MKTAG(
'a',
'p',
'r',
'n'):
349 case MKTAG(
'a',
'p',
'r',
'h'):
360 if (bytestream2_get_be32(&gb) != avpkt->
size)
364 if (bytestream2_get_be32(&gb) !=
MKBETAG(
'p',
'r',
'r',
'f'))
367 int header_len = bytestream2_get_be16(&gb);
376 s->version = bytestream2_get_byte(&gb_hdr);
377 if (
s->version > 1) {
386 int w = bytestream2_get_be16(&gb_hdr);
387 int h = bytestream2_get_be16(&gb_hdr);
388 if ((
w & 1) || (
h & 1))
396 dimensions_changed = 1;
403 if (
pix_fmt !=
s->pix_fmt || dimensions_changed ||
404 s->version != old_version) {
416 uint8_t crop_l = bytestream2_get_byte(&gb_hdr);
417 uint8_t crop_r = bytestream2_get_byte(&gb_hdr);
418 uint8_t crop_t = bytestream2_get_byte(&gb_hdr);
419 uint8_t crop_b = bytestream2_get_byte(&gb_hdr);
422 int bayer_pattern = bytestream2_get_be16(&gb_hdr) & 0x3;
423 if (bayer_pattern != 0) {
430 uint16_t black_level = 0x100;
431 uint16_t white_level = bytestream2_get_be16(&gb_hdr) + 0x100;
433 float wb_red =
av_int2float(bytestream2_get_be32(&gb_hdr));
434 float wb_blue =
av_int2float(bytestream2_get_be32(&gb_hdr));
437 float color_matrix[3][3];
438 for (
int r = 0;
r < 3;
r++)
439 for (
int c = 0;
c < 3;
c++)
442 float gain =
av_int2float(bytestream2_get_be32(&gb_hdr));
443 uint16_t wb_cct = bytestream2_get_be16(&gb_hdr);
446 int flags = bytestream2_get_be16(&gb_hdr);
450 "Invalid tile alignment %d (max 4)\n",
align);
458 if ((
flags >> 4) & 1) {
461 for (
int i = 0;
i < 8;
i++)
462 s->lin_curve[
i] = bytestream2_get_be16(&gb_hdr);
465 static const uint16_t default_lin_curve[8] =
466 { 0, 512, 1024, 2048, 4096, 8192, 16384, 32768 };
467 memcpy(
s->lin_curve, default_lin_curve,
sizeof(
s->lin_curve));
472 int tw16 = (
w + 15) >> 4;
474 s->nb_th = (
h + 15) >> 4;
475 s->nb_tiles =
s->nb_tw *
s->nb_th;
491 for (
int ty = 0; ty <
s->nb_th; ty++) {
494 for (
int e =
align; rem > 0; e--) {
496 while (unit <= rem) {
498 int size = bytestream2_get_be16(&gb);
509 tile->y = ty *
s->th;
510 tile->log2_nb_blocks = e;
552 for (
int n = 0; n <
s->nb_tiles; n++) {
554 ret =
hwaccel->decode_slice(avctx,
tile->gb.buffer,
555 tile->gb.buffer_end -
tile->gb.buffer);
560 ret =
hwaccel->end_frame(avctx);
571 frame->crop_left = crop_l;
572 frame->crop_right = crop_r;
573 frame->crop_top = crop_t;
574 frame->crop_bottom = crop_b;
588 for (
int r = 0;
r < 3;
r++)
589 for (
int c = 0;
c < 3;
c++)
619 .p.name =
"prores_raw",
634#if CONFIG_PRORES_RAW_VULKAN_HWACCEL
637#if CONFIG_PRORES_RAW_VIDEOTOOLBOX_HWACCEL
uint8_t ptrdiff_t const uint8_t ptrdiff_t int intptr_t intptr_t int int16_t * dst
const FFCodec ff_prores_raw_decoder
static av_cold void close(AVCodecParserContext *s)
simple assert() macros that are a bit more flexible than ISO C assert().
#define av_assert1(cond)
assert() equivalent, that does not lie in speed critical code.
Libavcodec external API header.
static const uint8_t *BS_FUNC align(BSCTX *bc)
Skip bits to a byte boundary.
static av_always_inline unsigned int bytestream2_get_buffer(GetByteContext *g, uint8_t *dst, unsigned int size)
static av_always_inline int bytestream2_get_bytes_left(const GetByteContext *g)
static av_always_inline void bytestream2_init(GetByteContext *g, const uint8_t *buf, int buf_size)
static av_always_inline void bytestream2_skip(GetByteContext *g, unsigned int size)
static av_always_inline int bytestream2_tell(const GetByteContext *g)
static av_always_inline int bytestream2_size(const GetByteContext *g)
static int FUNC tile(CodedBitstreamContext *ctx, RWContext *rw, APVRawTile *current, int tile_idx, uint32_t tile_size)
#define flags(name, subs,...)
#define i(width, name, range_min, range_max)
static const unsigned codebook[256][2]
#define UPDATE_THREAD_CONTEXT(func)
#define FF_CODEC_CAP_SKIP_FRAME_FILL_PARAM
The decoder extracts and fills its parameters even if the frame is skipped due to the skip_frame sett...
#define FF_CODEC_DECODE_CB(func)
#define CODEC_LONG_NAME(str)
#define FF_CODEC_CAP_INIT_CLEANUP
The codec allows calling the close function for deallocation even if the init function returned a fai...
int ff_get_format(AVCodecContext *avctx, const enum AVPixelFormat *fmt)
Select the (possibly hardware accelerated) pixel format.
int ff_hwaccel_frame_priv_alloc(AVCodecContext *avctx, void **hwaccel_picture_private)
Allocate a hwaccel frame private data if the provided avctx uses a hwaccel method that needs it.
int ff_set_dimensions(AVCodecContext *s, int width, int height)
#define AV_PROFILE_PRORES_RAW_HQ
#define AV_PROFILE_PRORES_RAW
static enum AVPixelFormat pix_fmt
int(* init)(AVBSFContext *ctx)
static const uint8_t bits[8]
static const char * hwaccel
bitstream reader API header.
static unsigned int show_bits_long(GetBitContext *s, int n)
Show 0-32 bits.
static int get_bits_left(GetBitContext *gb)
static void skip_bits_long(GetBitContext *s, int n)
Skips the specified number of bits.
static unsigned int get_bits1(GetBitContext *s)
static int init_get_bits8(GetBitContext *s, const uint8_t *buffer, int byte_size)
Initialize GetBitContext.
#define AV_CODEC_CAP_DR1
Codec uses get_buffer() or get_encode_buffer() for allocating buffers and supports custom allocators.
#define AV_CODEC_CAP_SLICE_THREADS
Codec supports slice-based (or partition-based) multithreading.
#define AV_CODEC_CAP_FRAME_THREADS
Codec supports frame-level multithreading.
@ AVDISCARD_ALL
discard all
#define AVERROR_PATCHWELCOME
Not yet implemented in FFmpeg, patches welcome.
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
#define AV_FRAME_FLAG_KEY
A flag to mark frames that are keyframes.
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
#define AV_LOG_WARNING
Something somehow does not look correct.
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
static AVRational av_make_q(int num, int den)
Create an AVRational.
AVRational av_d2q(double d, int max)
Convert a double precision floating point number to a rational.
void av_fast_mallocz(void *ptr, unsigned int *size, size_t min_size)
Allocate and clear a buffer, reusing the given one if large enough.
@ AV_PICTURE_TYPE_I
Intra.
static const FFHWAccel * ffhwaccel(const AVHWAccel *codec)
#define HWACCEL_VULKAN(codec)
#define HWACCEL_VIDEOTOOLBOX(codec)
static av_always_inline float av_int2float(uint32_t i)
Reinterpret a 32-bit integer as a float.
static void scale(int *out, const int *in, const int w, const int h, const int shift)
static av_cold int decode_init(AVCodecContext *avctx)
static av_cold int decode_end(AVCodecContext *avctx)
static int decode_frame(AVCodecContext *avctx, AVFrame *picture, int *got_frame, AVPacket *avpkt)
av_cold void ff_blockdsp_init(BlockDSPContext *c)
av_cold void ff_permute_scantable(uint8_t dst[64], const uint8_t src[64], const uint8_t permutation[64])
Multithreading API for decoders.
static enum AVPixelFormat pix_fmts[]
#define MKTAG(a, b, c, d)
#define MKBETAG(a, b, c, d)
Memory handling functions.
#define LOCAL_ALIGNED_32(t, v,...)
#define DECLARE_ALIGNED(n, t, v)
Declare a variable that is aligned in memory.
#define AV_PIX_FMT_BAYER_RGGB16
AVPixelFormat
Pixel format.
@ AV_PIX_FMT_VULKAN
Vulkan hardware images.
@ AV_PIX_FMT_VIDEOTOOLBOX
hardware decoding through Videotoolbox
@ AVCOL_TRC_LINEAR
"Linear transfer characteristics"
const int16_t ff_prores_raw_rn_cb[RN_CB_MAX+1]
const int16_t ff_prores_raw_ac_cb[AC_CB_MAX+1]
static int decode_frame(AVCodecContext *avctx, AVFrame *frame, int *got_frame_ptr, AVPacket *avpkt)
static int decode_comp(AVCodecContext *avctx, TileContext *tile, AVFrame *frame, const uint8_t *data, int size, int component, int16_t *qmat)
static uint16_t get_value(GetBitContext *gb, int16_t codebook)
static enum AVPixelFormat get_pixel_format(AVCodecContext *avctx, enum AVPixelFormat pix_fmt)
static av_cold int decode_init(AVCodecContext *avctx)
static int decode_tile(AVCodecContext *avctx, TileContext *tile, AVFrame *frame)
static av_cold int decode_end(AVCodecContext *avctx)
const int16_t ff_prores_raw_ln_cb[LN_CB_MAX+1]
const uint8_t ff_prores_raw_dc_cb[DC_CB_MAX+1]
static int decode_tiles(AVCodecContext *avctx, void *arg, int n, int thread_nb)
const uint8_t ff_prores_interlaced_scan[64]
static const uint8_t dc_codebook[7]
av_cold void ff_proresdsp_init(ProresDSPContext *dsp, int bits_per_raw_sample)
int ff_thread_get_buffer(AVCodecContext *avctx, AVFrame *f, int flags)
Wrapper around get_buffer() for frame-multithreaded codecs.
Utilities for rational number calculation.
AVRawColorParams * av_raw_color_params_create_side_data(AVFrame *frame)
Allocate and add an AVRawColorParams structure to an existing AVFrame as AV_FRAME_DATA_RAW_COLOR_PARA...
@ AV_RAW_COLOR_PARAMS_PRORES_RAW
The union is valid when interpreted as AVProResRawColorParams (codec.prores_raw).
void av_refstruct_unref(void *objp)
Decrement the reference count of the underlying object and automatically free the object if there are...
main external API structure.
enum AVPixelFormat pix_fmt
Pixel format, see AV_PIX_FMT_xxx.
int width
picture width / height.
unsigned int codec_tag
fourcc (LSB first, so "ABCD" -> ('D'<<24) + ('C'<<16) + ('B'<<8) + 'A').
enum AVColorPrimaries color_primaries
Chromaticity coordinates of the source primaries.
const struct AVHWAccel * hwaccel
Hardware accelerator in use.
int bits_per_raw_sample
Bits per sample/pixel of internal libavcodec pixel/sample format.
enum AVColorSpace colorspace
YUV colorspace type.
enum AVColorTransferCharacteristic color_trc
Color Transfer Characteristic.
int(* execute2)(struct AVCodecContext *c, int(*func)(struct AVCodecContext *c2, void *arg, int jobnr, int threadnr), void *arg2, int *ret, int count)
The codec may call this to execute several independent things.
int coded_width
Bitstream width / height, may be different from width/height e.g.
enum AVDiscard skip_frame
Skip decoding for selected frames.
This structure describes decoded (raw) audio or video data.
This structure stores compressed data.
AVBufferRef * buf
A reference to the reference-counted buffer where the packet data is stored.
ProRes RAW per-frame color transform, parsed from the prrf frame header.
AVRational wb_red
White balance multiplier for the red channel, applied pre-debayer.
AVRational color_matrix[3][3]
3x3 row-major color matrix from camera RGB to linear-light CIE 1931 XYZ relative to the D65 illuminan...
AVRational wb_blue
White balance multiplier for the blue channel, applied pre-debayer.
AVRational gain
Post-matrix scene-linear scaling factor.
Per-frame color information for a RAW camera codec.
AVProResRawColorParams prores_raw
AVRational black_level
Lowest valid raw sample code (sensor black point)
enum AVRawColorParamsType type
Selects which member of codec is valid.
union AVRawColorParams::@064000052037250306123267111255172234366153040136 codec
Additional codec-specific fields.
AVRational white_level
Highest valid raw sample code (sensor white point)
uint32_t wb_cct
Color temperature in Kelvin from with the camera's white balance.
const uint8_t * buffer_start
enum AVPixelFormat pix_fmt
#define avpriv_request_sample(...)