40 #define ALPHA_COMPAND_DC_OFFSET 256
41 #define ALPHA_COMPAND_GAIN 9400
95 int64_t abslevel = abs(level);
96 return (abslevel + ((768 * abslevel * abslevel * abslevel) / (255 * 255 * 255))) *
97 FFSIGN(level) * quantisation;
103 for (i = 0; i <
width; i++) {
109 channel = av_clip_uintp2(channel, 12);
114 static inline void filter(int16_t *output, ptrdiff_t out_stride,
115 int16_t *low, ptrdiff_t low_stride,
116 int16_t *high, ptrdiff_t high_stride,
122 for (i = 0; i <
len; i++) {
124 tmp = (11*low[0*low_stride] - 4*low[1*low_stride] + low[2*low_stride] + 4) >> 3;
125 output[(2*i+0)*out_stride] = (tmp + high[0*high_stride]) >> 1;
129 tmp = ( 5*low[0*low_stride] + 4*low[1*low_stride] - low[2*low_stride] + 4) >> 3;
130 output[(2*i+1)*out_stride] = (tmp - high[0*high_stride]) >> 1;
133 }
else if (i == len-1) {
134 tmp = ( 5*low[i*low_stride] + 4*low[(i-1)*low_stride] - low[(i-2)*low_stride] + 4) >> 3;
135 output[(2*i+0)*out_stride] = (tmp + high[i*high_stride]) >> 1;
139 tmp = (11*low[i*low_stride] - 4*low[(i-1)*low_stride] + low[(i-2)*low_stride] + 4) >> 3;
140 output[(2*i+1)*out_stride] = (tmp - high[i*high_stride]) >> 1;
144 tmp = (low[(i-1)*low_stride] - low[(i+1)*low_stride] + 4) >> 3;
145 output[(2*i+0)*out_stride] = (tmp + low[i*low_stride] + high[i*high_stride]) >> 1;
149 tmp = (low[(i+1)*low_stride] - low[(i-1)*low_stride] + 4) >> 3;
150 output[(2*i+1)*out_stride] = (tmp + low[i*low_stride] - high[i*high_stride]) >> 1;
160 filter(output, 1, low, 1, high, 1, width, 0);
166 filter(output, 1, low, 1, high, 1, width, clip);
170 int16_t *low, ptrdiff_t low_stride,
171 int16_t *high, ptrdiff_t high_stride,
int len)
173 filter(output, out_stride, low, low_stride, high, high_stride, len, 0);
184 for (j = 0; j < 9; j++)
187 for (j = 0; j < 8; j++)
198 int chroma_x_shift, chroma_y_shift;
207 &chroma_y_shift)) < 0)
211 for (i = 0; i <
planes; i++) {
212 int w8, h8, w4, h4, w2, h2;
217 height =
FFALIGN(height / 8, 2) * 8;
290 uint16_t tagu = bytestream2_get_be16(&gb);
291 int16_t
tag = (int16_t)tagu;
292 int8_t tag8 = (int8_t)(tagu >> 8);
293 uint16_t abstag = abs(tag);
294 int8_t abs_tag8 = abs(tag8);
295 uint16_t data = bytestream2_get_be16(&gb);
296 if (abs_tag8 >= 0x60 && abs_tag8 <= 0x6f) {
304 }
else if (tag == 101) {
351 }
else if (tag == 51) {
369 }
else if (tag == 27) {
378 }
else if (tag == 28) {
388 else if (tag == 10) {
395 }
else if (abstag >= 0x4000 && abstag <= 0x40ff) {
396 av_log(avctx,
AV_LOG_DEBUG,
"Small chunk length %d %s\n", data * 4, tag < 0 ?
"optional" :
"required");
398 }
else if (tag == 23) {
403 }
else if (tag == 2) {
410 for (i = 0; i <
data; i++) {
411 uint16_t tag2 = bytestream2_get_be16(&gb);
412 uint16_t val2 = bytestream2_get_be16(&gb);
415 }
else if (tag == 41) {
424 }
else if (tag == 42) {
432 }
else if (tag == 49) {
441 }
else if (tag == 50) {
449 }
else if (tag == 71) {
452 }
else if (tag == 72) {
455 }
else if (tag == 70) {
457 if (!(data == 10 || data == 12)) {
463 }
else if (tag == 84) {
477 }
else if (tag == -85) {
525 if (lowpass_height > lowpass_a_height || lowpass_width > lowpass_a_width ||
533 for (i = 0; i < lowpass_height; i++) {
534 for (j = 0; j < lowpass_width; j++)
535 coeff_data[j] = bytestream2_get_be16u(&gb);
537 coeff_data += lowpass_width;
544 if (lowpass_height & 1) {
545 memcpy(&coeff_data[lowpass_height * lowpass_width],
546 &coeff_data[(lowpass_height - 1) * lowpass_width],
547 lowpass_width *
sizeof(*coeff_data));
550 av_log(avctx,
AV_LOG_DEBUG,
"Lowpass coefficients %d\n", lowpass_width * lowpass_height);
560 int a_expected = highpass_a_height * highpass_a_width;
562 int count = 0, bytes;
570 if (highpass_height > highpass_a_height || highpass_width > highpass_a_width || a_expected < highpass_height * (uint64_t)highpass_stride) {
575 expected = highpass_height * highpass_stride;
594 if (count > expected)
598 for (i = 0; i <
run; i++)
599 *coeff_data++ = coeff;
608 if (level == 255 && run == 2)
613 if (count > expected)
617 for (i = 0; i <
run; i++)
618 *coeff_data++ = coeff;
624 if (count > expected) {
638 av_log(avctx,
AV_LOG_DEBUG,
"End subband coeffs %i extra %i\n", count, count - expected);
642 if (highpass_height & 1) {
643 memcpy(&coeff_data[highpass_height * highpass_stride],
644 &coeff_data[(highpass_height - 1) * highpass_stride],
645 highpass_stride *
sizeof(*coeff_data));
664 for (plane = 0; plane < planes && !ret; plane++) {
669 int act_plane = plane == 1 ? 2 : plane == 2 ? 1 :
plane;
670 int16_t *low, *high, *output, *dst;
679 av_log(avctx,
AV_LOG_DEBUG,
"Decoding level 1 plane %i %i %i %i\n", plane, lowpass_height, lowpass_width, highpass_stride);
684 for (i = 0; i < lowpass_width; i++) {
685 vert_filter(output, lowpass_width, low, lowpass_width, high, highpass_stride, lowpass_height);
695 for (i = 0; i < lowpass_width; i++) {
697 vert_filter(output, lowpass_width, low, highpass_stride, high, highpass_stride, lowpass_height);
706 for (i = 0; i < lowpass_height * 2; i++) {
708 low += lowpass_width;
709 high += lowpass_width;
710 output += lowpass_width * 2;
714 for (i = 0; i < lowpass_height * 2; i++) {
715 for (j = 0; j < lowpass_width * 2; j++)
718 output += lowpass_width * 2;
734 av_log(avctx,
AV_LOG_DEBUG,
"Level 2 plane %i %i %i %i\n", plane, lowpass_height, lowpass_width, highpass_stride);
739 for (i = 0; i < lowpass_width; i++) {
740 vert_filter(output, lowpass_width, low, lowpass_width, high, highpass_stride, lowpass_height);
749 for (i = 0; i < lowpass_width; i++) {
750 vert_filter(output, lowpass_width, low, highpass_stride, high, highpass_stride, lowpass_height);
759 for (i = 0; i < lowpass_height * 2; i++) {
761 low += lowpass_width;
762 high += lowpass_width;
763 output += lowpass_width * 2;
767 for (i = 0; i < lowpass_height * 2; i++) {
768 for (j = 0; j < lowpass_width * 2; j++)
771 output += lowpass_width * 2;
786 av_log(avctx,
AV_LOG_DEBUG,
"Level 3 plane %i %i %i %i\n", plane, lowpass_height, lowpass_width, highpass_stride);
791 for (i = 0; i < lowpass_width; i++) {
792 vert_filter(output, lowpass_width, low, lowpass_width, high, highpass_stride, lowpass_height);
801 for (i = 0; i < lowpass_width; i++) {
802 vert_filter(output, lowpass_width, low, highpass_stride, high, highpass_stride, lowpass_height);
808 dst = (int16_t *)pic->
data[act_plane];
811 for (i = 0; i < lowpass_height * 2; i++) {
815 low += lowpass_width;
816 high += lowpass_width;
817 dst += pic->
linesize[act_plane] / 2;
#define FF_CODEC_CAP_INIT_CLEANUP
The codec allows calling the close function for deallocation even if the init function returned a fai...
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
static int cfhd_decode(AVCodecContext *avctx, void *data, int *got_frame, AVPacket *avpkt)
static float alpha(float a)
This structure describes decoded (raw) audio or video data.
ptrdiff_t const GLvoid * data
int av_pix_fmt_count_planes(enum AVPixelFormat pix_fmt)
int ff_set_dimensions(AVCodecContext *s, int width, int height)
Check that the provided frame dimensions are valid and set them on the codec context.
static av_cold int init(AVCodecContext *avctx)
#define ALPHA_COMPAND_GAIN
static int dequant_and_decompand(int level, int quantisation)
enum AVPixelFormat pix_fmt
Pixel format, see AV_PIX_FMT_xxx.
static av_always_inline void bytestream2_init(GetByteContext *g, const uint8_t *buf, int buf_size)
static void horiz_filter_clip(int16_t *output, int16_t *low, int16_t *high, int width, int clip)
int bits_per_raw_sample
Bits per sample/pixel of internal libavcodec pixel/sample format.
static void decode(AVCodecContext *dec_ctx, AVPacket *pkt, AVFrame *frame, FILE *outfile)
Macro definitions for various function/variable attributes.
static void filter(int16_t *output, ptrdiff_t out_stride, int16_t *low, ptrdiff_t low_stride, int16_t *high, ptrdiff_t high_stride, int len, int clip)
static void horiz_filter(int16_t *output, int16_t *low, int16_t *high, int width)
#define FF_CODEC_CAP_INIT_THREADSAFE
The codec does not modify any global variables in the init function, allowing to call the init functi...
static av_cold int end(AVCodecContext *avctx)
Multithreading support functions.
static int alloc_buffers(AVCodecContext *avctx)
static int get_bits_count(const GetBitContext *s)
static av_always_inline void bytestream2_skipu(GetByteContext *g, unsigned int size)
bitstream reader API header.
CFHD_RL_VLC_ELEM table_18_rl_vlc[4572]
CFHD_RL_VLC_ELEM table_9_rl_vlc[2088]
uint8_t prescale_shift[3]
#define UPDATE_CACHE(name, gb)
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
int is_copy
Whether the parent AVCodecContext is a copy of the context which had init() called on it...
int av_pix_fmt_get_chroma_sub_sample(enum AVPixelFormat pix_fmt, int *h_shift, int *v_shift)
Utility function to access log2_chroma_w log2_chroma_h from the pixel format AVPixFmtDescriptor.
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification. ...
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
static av_always_inline unsigned int bytestream2_get_bytes_left(GetByteContext *g)
#define AV_PIX_FMT_GBRAP12
const char * name
Name of the codec implementation.
#define CLOSE_READER(name, gb)
#define AV_CODEC_CAP_FRAME_THREADS
Codec supports frame-level multithreading.
#define GET_RL_VLC(level, run, name, gb, table, bits,max_depth, need_update)
static av_cold int cfhd_close(AVCodecContext *avctx)
static void init_frame_defaults(CFHDContext *s)
SubBand band[DWT_LEVELS][4]
int width
picture width / height.
static void init_plane_defaults(CFHDContext *s)
static av_cold int cfhd_init(AVCodecContext *avctx)
#define FF_ARRAY_ELEMS(a)
static void vert_filter(int16_t *output, ptrdiff_t out_stride, int16_t *low, ptrdiff_t low_stride, int16_t *high, ptrdiff_t high_stride, int len)
#define AVERROR_PATCHWELCOME
Not yet implemented in FFmpeg, patches welcome.
static av_always_inline int bytestream2_tell(GetByteContext *g)
Libavcodec external API header.
#define ALPHA_COMPAND_DC_OFFSET
int linesize[AV_NUM_DATA_POINTERS]
For video, size in bytes of each picture line.
int ff_thread_get_buffer(AVCodecContext *avctx, ThreadFrame *f, int flags)
Wrapper around get_buffer() for frame-multithreaded codecs.
main external API structure.
#define OPEN_READER(name, gb)
enum AVPixelFormat coded_format
static int init_get_bits(GetBitContext *s, const uint8_t *buffer, int bit_size)
Initialize GetBitContext.
refcounted data buffer API
#define AV_PIX_FMT_GBRP12
void avpriv_report_missing_feature(void *avc, const char *msg,...) av_printf_format(2
Log a generic warning message about a missing feature.
#define AV_PIX_FMT_YUV422P10
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
GLint GLenum GLboolean GLsizei stride
common internal api header.
common internal and external API header
static double clip(void *opaque, double val)
Clip value val in the minval - maxval range.
static void process_alpha(int16_t *alpha, int width)
channel
Use these values when setting the channel map with ebur128_set_channel().
static const struct @272 planes[]
struct AVCodecInternal * internal
Private context used for internal data.
static const double coeff[2][5]
static av_always_inline int bytestream2_seek(GetByteContext *g, int offset, int whence)
static void free_buffers(CFHDContext *s)
int ff_cfhd_init_vlcs(CFHDContext *s)
#define av_malloc_array(a, b)
uint8_t lowpass_precision
int16_t * subband[SUBBAND_COUNT]
This structure stores compressed data.
void ff_free_vlc(VLC *vlc)
#define AV_CODEC_CAP_DR1
Codec uses get_buffer() for allocating buffers and supports custom allocators.
void * av_mallocz_array(size_t nmemb, size_t size)
static av_always_inline av_const unsigned av_clip_uintp2_c(int a, int p)
Clip a signed integer to an unsigned power of two range.