31#define CACHED_BITSTREAM_READER !ARCH_X86_32
33#include "config_components.h"
75 const int switch_bits =
codebook >> 8;
76 const int rice_order =
codebook & 0xf;
77 const int exp_order = (
codebook >> 4) & 0xf;
87 b &= 0xFFFFFFFFu << (32 -
left);
96 return (
b & 0x7FFFFFFF) >> (31 - rice_order);
99 if (q <= switch_bits) {
101 return (q << rice_order) +
102 (((
b << (q + 1)) >> 1) >> (31 - rice_order));
106 bits = exp_order + (q << 1) - switch_bits;
110 return (
b >> (32 -
bits)) +
111 ((switch_bits + 1) << rice_order) -
115#define TODCCODEBOOK(x) ((x + 1) >> 1)
119 0x010, 0x021, 0x032, 0x033, 0x033, 0x033, 0x044, 0x044, 0x044, 0x044, 0x044, 0x044, 0x076,
124 0x000, 0x211, 0x111, 0x111, 0x222, 0x222, 0x222, 0x122, 0x122, 0x122,
125 0x233, 0x233, 0x233, 0x233, 0x233, 0x233, 0x233, 0x233, 0x133, 0x133,
126 0x244, 0x244, 0x244, 0x244, 0x244, 0x244, 0x244, 0x244, 0x244, 0x244, 0x244,
127 0x244, 0x244, 0x244, 0x244, 0x244, 0x244, 0x244, 0x244, 0x244, 0x244, 0x244,
128 0x355, 0x355, 0x355, 0x355, 0x355, 0x355, 0x355, 0x355, 0x355, 0x355, 0x355, 0x355, 0x355,
129 0x355, 0x355, 0x355, 0x355, 0x355, 0x355, 0x355, 0x355, 0x355, 0x355, 0x355, 0x355, 0x355,
130 0x355, 0x355, 0x355, 0x355, 0x355, 0x355, 0x355, 0x355, 0x355, 0x355, 0x355, 0x355, 0x355,
131 0x355, 0x355, 0x355, 0x355, 0x355, 0x355, 0x355, 0x355, 0x355, 0x355, 0x355, 0x355, 0x355, 0x166,
136 0x200, 0x100, 0x000, 0x000, 0x211, 0x211, 0x111, 0x111, 0x011, 0x011, 0x021, 0x021, 0x222, 0x022,
137 0x022, 0x022, 0x022, 0x022, 0x022, 0x022, 0x022, 0x022, 0x022, 0x022, 0x022, 0x032, 0x032, 0x044
142 0x100, 0x111, 0x222, 0x222, 0x122, 0x122, 0x433, 0x433, 0x233, 0x233, 0x233, 0x233, 0x233, 0x233, 0x033,
147 int component, int16_t *qmat)
151 const ptrdiff_t linesize =
frame->linesize[0] >> 1;
155 const int log2_nb_blocks =
tile->log2_nb_blocks;
156 const int nb_blocks = 1 << log2_nb_blocks;
157 const int block_mask = nb_blocks - 1;
158 const int nb_codes = 64 * nb_blocks;
167 int16_t ac_codebook = 49;
168 int16_t rn_codebook = 0;
169 int16_t ln_codebook = 66;
171 const uint8_t *scan =
s->scan;
176 dst += component & 1;
181 memset(
block, 0, nb_blocks * 64 *
sizeof(*
block));
187 int prev_dc = (dc >> 1) ^ -(dc & 1);
188 block[0] = prev_dc + 1;
190 for (
int n = 1; n < nb_blocks; n++) {
200 sign = sign ^ dc & 1;
205 block[n*64] = prev_dc + 1;
208 for (
int n = nb_blocks; n < nb_codes;) {
213 for (
int i = 0;
i < ln;
i++) {
220 idx = scan[n >> log2_nb_blocks] + ((n & block_mask) << 6);
221 block[idx] = ((ac + 1) ^ sign) - sign;
243 idx = scan[n >> log2_nb_blocks] + ((n & block_mask) << 6);
244 block[idx] = ((ac + 1) ^ sign) - sign;
250 for (
int n = 0; n < nb_blocks; n++) {
251 uint16_t *ptr =
dst + n*16;
252 s->prodsp.idct_put_bayer(ptr, linesize,
block + n*64, qmat,
s->lin_curve);
271 int header_len = bytestream2_get_byteu(gb) >> 3;
272 int16_t
scale = bytestream2_get_byteu(gb);
275 size[0] = bytestream2_get_be16(gb);
276 size[1] = bytestream2_get_be16(gb);
277 size[2] = bytestream2_get_be16(gb);
282 for (
int i = 0;
i < 64;
i++)
285 const uint8_t *comp_start = gb->
buffer_start + header_len;
314 int n,
int thread_nb)
327#if CONFIG_PRORES_RAW_VULKAN_HWACCEL
330#if CONFIG_PRORES_RAW_VIDEOTOOLBOX_HWACCEL
345 int ret, dimensions_changed = 0, old_version =
s->version;
352 case MKTAG(
'a',
'p',
'r',
'n'):
355 case MKTAG(
'a',
'p',
'r',
'h'):
366 if (bytestream2_get_be32(&gb) != avpkt->
size)
370 if (bytestream2_get_be32(&gb) !=
MKBETAG(
'p',
'r',
'r',
'f'))
373 int header_len = bytestream2_get_be16(&gb);
382 s->version = bytestream2_get_byte(&gb_hdr);
383 if (
s->version > 1) {
392 int w = bytestream2_get_be16(&gb_hdr);
393 int h = bytestream2_get_be16(&gb_hdr);
394 if ((
w & 1) || (
h & 1))
402 dimensions_changed = 1;
409 if (
pix_fmt !=
s->pix_fmt || dimensions_changed ||
410 s->version != old_version) {
422 uint8_t crop_l = bytestream2_get_byte(&gb_hdr);
423 uint8_t crop_r = bytestream2_get_byte(&gb_hdr);
424 uint8_t crop_t = bytestream2_get_byte(&gb_hdr);
425 uint8_t crop_b = bytestream2_get_byte(&gb_hdr);
428 int bayer_pattern = bytestream2_get_be16(&gb_hdr) & 0x3;
429 if (bayer_pattern != 0) {
436 uint16_t black_level = 0x100;
437 uint16_t white_level = bytestream2_get_be16(&gb_hdr) + 0x100;
439 float wb_red =
av_int2float(bytestream2_get_be32(&gb_hdr));
440 float wb_blue =
av_int2float(bytestream2_get_be32(&gb_hdr));
443 float color_matrix[3][3];
444 for (
int r = 0;
r < 3;
r++)
445 for (
int c = 0;
c < 3;
c++)
448 float gain =
av_int2float(bytestream2_get_be32(&gb_hdr));
449 uint16_t wb_cct = bytestream2_get_be16(&gb_hdr);
452 int flags = bytestream2_get_be16(&gb_hdr);
456 "Invalid tile alignment %d (max 4)\n",
align);
464 if ((
flags >> 4) & 1) {
467 for (
int i = 0;
i < 8;
i++)
468 s->lin_curve[
i] = bytestream2_get_be16(&gb_hdr);
471 static const uint16_t default_lin_curve[8] =
472 { 0, 512, 1024, 2048, 4096, 8192, 16384, 32768 };
473 memcpy(
s->lin_curve, default_lin_curve,
sizeof(
s->lin_curve));
478 int tw16 = (
w + 15) >> 4;
480 s->nb_th = (
h + 15) >> 4;
481 s->nb_tiles =
s->nb_tw *
s->nb_th;
497 for (
int ty = 0; ty <
s->nb_th; ty++) {
500 for (
int e =
align; rem > 0; e--) {
502 while (unit <= rem) {
504 int size = bytestream2_get_be16(&gb);
515 tile->y = ty *
s->th;
516 tile->log2_nb_blocks = e;
566 for (
int n = 0; n <
s->nb_tiles; n++) {
568 ret =
hwaccel->decode_slice(avctx,
tile->gb.buffer,
569 tile->gb.buffer_end -
tile->gb.buffer);
574 ret =
hwaccel->end_frame(avctx);
585 frame->crop_left = crop_l;
586 frame->crop_right = crop_r;
587 frame->crop_top = crop_t;
588 frame->crop_bottom = crop_b;
602 for (
int r = 0;
r < 3;
r++)
603 for (
int c = 0;
c < 3;
c++)
633 .p.name =
"prores_raw",
648#if CONFIG_PRORES_RAW_VULKAN_HWACCEL
651#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 int BS_FUNC left(const BSCTX *bc)
Return the number of the bits left in a buffer.
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 if all frames are skipped due to the skip_frame setting...
#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 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)
static av_always_inline int get_value(GetBitContext *gb, int16_t codebook)
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.
void ff_thread_finish_setup(AVCodecContext *avctx)
If the codec defines update_thread_context(), call this when they are ready for the next thread to st...
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(...)