38 #define SUBBAND_COUNT 10
76 int64_t abslevel = abs(level);
77 return (abslevel + ((768 * abslevel * abslevel * abslevel) / (255 * 255 * 255))) *
FFSIGN(level) * quantisation;
80 static inline void filter(int16_t *output, ptrdiff_t out_stride, int16_t *low, ptrdiff_t low_stride,
86 for (i = 0; i <
len; i++) {
88 tmp = (11*low[0*low_stride] - 4*low[1*low_stride] + low[2*low_stride] + 4) >> 3;
89 output[(2*i+0)*out_stride] = (tmp + high[0*high_stride]) >> 1;
93 tmp = ( 5*low[0*low_stride] + 4*low[1*low_stride] - low[2*low_stride] + 4) >> 3;
94 output[(2*i+1)*out_stride] = (tmp - high[0*high_stride]) >> 1;
97 }
else if (i == len-1) {
98 tmp = ( 5*low[i*low_stride] + 4*low[(i-1)*low_stride] - low[(i-2)*low_stride] + 4) >> 3;
99 output[(2*i+0)*out_stride] = (tmp + high[i*high_stride]) >> 1;
103 tmp = (11*low[i*low_stride] - 4*low[(i-1)*low_stride] + low[(i-2)*low_stride] + 4) >> 3;
104 output[(2*i+1)*out_stride] = (tmp - high[i*high_stride]) >> 1;
108 tmp = (low[(i-1)*low_stride] - low[(i+1)*low_stride] + 4) >> 3;
109 output[(2*i+0)*out_stride] = (tmp + low[i*low_stride] + high[i*high_stride]) >> 1;
113 tmp = (low[(i+1)*low_stride] - low[(i-1)*low_stride] + 4) >> 3;
114 output[(2*i+1)*out_stride] = (tmp + low[i*low_stride] - high[i*high_stride]) >> 1;
123 filter(output, 1, low, 1, high, 1, width, 0);
128 filter(output, 1, low, 1, high, 1, width, clip);
131 static void vert_filter(int16_t *output,
int out_stride, int16_t *low,
int low_stride,
132 int16_t *high,
int high_stride,
int len)
134 filter(output, out_stride, low, low_stride, high, high_stride, len, 0);
142 for (i = 0; i < 4; i++) {
146 for (j = 0; j < 9; j++)
149 for (j = 0; j < 8; j++)
159 int i, j, k, ret, planes;
168 for (i = 0; i < planes; i++) {
172 int w8, h8, w4, h4, w2, h2;
173 height =
FFALIGN(height / 8, 2) * 8;
203 for(k = 0; k < 4; k++) {
234 int ret = 0, i, j, planes,
plane, got_buffer = 0;
245 uint16_t tagu = bytestream2_get_be16(&gb);
246 int16_t
tag = (int16_t)tagu;
247 int8_t tag8 = (int8_t)(tagu >> 8);
248 uint16_t abstag = abs(tag);
249 int8_t abs_tag8 = abs(tag8);
250 uint16_t data = bytestream2_get_be16(&gb);
251 if (abs_tag8 >= 0x60 && abs_tag8 <= 0x6f) {
253 }
else if (tag == 20) {
256 }
else if (tag == 21) {
259 }
else if (tag == 101) {
262 }
else if (tag == 12) {
270 }
else if (tag == 14) {
277 }
else if (tag == 62) {
286 }
else if (tag == 48) {
301 }
else if (tag == 51) {
309 }
else if (tag == 35)
311 else if (tag == 53) {
314 }
else if (tag == 109) {
319 }
else if (tag == 27) {
328 }
else if (tag == 28) {
338 else if (tag == 10) {
345 }
else if (abstag >= 0x4000 && abstag <= 0x40ff) {
346 av_log(avctx,
AV_LOG_DEBUG,
"Small chunk length %d %s\n", data * 4, tag < 0 ?
"optional" :
"required");
348 }
else if (tag == 23) {
353 }
else if (tag == 2) {
360 for (i = 0; i <
data; i++) {
361 uint16_t tag2 = bytestream2_get_be16(&gb);
362 uint16_t val2 = bytestream2_get_be16(&gb);
365 }
else if (tag == 41) {
374 }
else if (tag == 42) {
382 }
else if (tag == 49) {
391 }
else if (tag == 50) {
399 }
else if (tag == 71) {
402 }
else if (tag == 72) {
405 }
else if (tag == 70) {
408 if (!(s->
bpc == 10 || s->
bpc == 12)) {
413 }
else if (tag == 84) {
470 if (lowpass_height > lowpass_a_height || lowpass_width > lowpass_a_width ||
478 for (i = 0; i < lowpass_height; i++) {
479 for (j = 0; j < lowpass_width; j++)
480 coeff_data[j] = bytestream2_get_be16u(&gb);
482 coeff_data += lowpass_width;
489 if (lowpass_height & 1) {
490 memcpy(&coeff_data[lowpass_height * lowpass_width],
491 &coeff_data[(lowpass_height - 1) * lowpass_width],
492 lowpass_width *
sizeof(*coeff_data));
495 av_log(avctx,
AV_LOG_DEBUG,
"Lowpass coefficients %d\n", lowpass_width * lowpass_height);
504 int expected = highpass_height * highpass_stride;
505 int a_expected = highpass_a_height * highpass_a_width;
507 int count = 0, bytes;
515 if (highpass_height > highpass_a_height || highpass_width > highpass_a_width || a_expected < expected) {
538 if (count > expected)
542 for (i = 0; i <
run; i++)
543 *coeff_data++ = coeff;
552 if (level == 255 && run == 2)
557 if (count > expected)
561 for (i = 0; i <
run; i++)
562 *coeff_data++ = coeff;
568 if (count > expected) {
582 av_log(avctx,
AV_LOG_DEBUG,
"End subband coeffs %i extra %i\n", count, count - expected);
586 if (highpass_height & 1) {
587 memcpy(&coeff_data[highpass_height * highpass_stride],
588 &coeff_data[(highpass_height - 1) * highpass_stride],
589 highpass_stride *
sizeof(*coeff_data));
608 for (plane = 0; plane < planes && !ret; plane++) {
613 int act_plane = plane == 1 ? 2 : plane == 2 ? 1 :
plane;
614 int16_t *low, *high, *output, *dst;
623 av_log(avctx,
AV_LOG_DEBUG,
"Decoding level 1 plane %i %i %i %i\n", plane, lowpass_height, lowpass_width, highpass_stride);
628 for (i = 0; i < lowpass_width; i++) {
629 vert_filter(output, lowpass_width, low, lowpass_width, high, highpass_stride, lowpass_height);
639 for (i = 0; i < lowpass_width; i++) {
641 vert_filter(output, lowpass_width, low, highpass_stride, high, highpass_stride, lowpass_height);
650 for (i = 0; i < lowpass_height * 2; i++) {
652 low += lowpass_width;
653 high += lowpass_width;
654 output += lowpass_width * 2;
658 for (i = 0; i < lowpass_height * 2; i++) {
659 for (j = 0; j < lowpass_width * 2; j++)
662 output += lowpass_width * 2;
678 av_log(avctx,
AV_LOG_DEBUG,
"Level 2 plane %i %i %i %i\n", plane, lowpass_height, lowpass_width, highpass_stride);
683 for (i = 0; i < lowpass_width; i++) {
684 vert_filter(output, lowpass_width, low, lowpass_width, high, highpass_stride, lowpass_height);
693 for (i = 0; i < lowpass_width; i++) {
694 vert_filter(output, lowpass_width, low, highpass_stride, high, highpass_stride, lowpass_height);
703 for (i = 0; i < lowpass_height * 2; i++) {
705 low += lowpass_width;
706 high += lowpass_width;
707 output += lowpass_width * 2;
711 for (i = 0; i < lowpass_height * 2; i++) {
712 for (j = 0; j < lowpass_width * 2; j++)
715 output += lowpass_width * 2;
730 av_log(avctx,
AV_LOG_DEBUG,
"Level 3 plane %i %i %i %i\n", plane, lowpass_height, lowpass_width, highpass_stride);
735 for (i = 0; i < lowpass_width; i++) {
736 vert_filter(output, lowpass_width, low, lowpass_width, high, highpass_stride, lowpass_height);
745 for (i = 0; i < lowpass_width; i++) {
746 vert_filter(output, lowpass_width, low, highpass_stride, high, highpass_stride, lowpass_height);
752 dst = (int16_t *)pic->
data[act_plane];
755 for (i = 0; i < lowpass_height * 2; i++) {
757 low += lowpass_width;
758 high += lowpass_width;
759 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)
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)
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)
int bits_per_raw_sample
Bits per sample/pixel of internal libavcodec pixel/sample format.
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 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, uint8_t clip)
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)
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)
int width
width and height of the video frame
#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...
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification. ...
static void vert_filter(int16_t *output, int out_stride, int16_t *low, int low_stride, int16_t *high, int high_stride, int len)
static void horiz_filter_clip(int16_t *output, int16_t *low, int16_t *high, int width, uint8_t clip)
#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)
static void * av_mallocz_array(size_t nmemb, size_t size)
#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 void init_frame_defaults(CFHDContext *s)
SubBand band[DWT_LEVELS][4]
int width
picture width / height.
static void init_plane_defaults(CFHDContext *s)
void avcodec_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 AVERROR_PATCHWELCOME
Not yet implemented in FFmpeg, patches welcome.
static av_always_inline int bytestream2_tell(GetByteContext *g)
Libavcodec external API header.
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)
static av_cold int cfhd_close_decoder(AVCodecContext *avctx)
static int init_get_bits(GetBitContext *s, const uint8_t *buffer, int bit_size)
Initialize GetBitContext.
refcounted data buffer API
static av_cold int cfhd_decode_init(AVCodecContext *avctx)
#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.
static void free_buffers(AVCodecContext *avctx)
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.
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)
int ff_cfhd_init_vlcs(CFHDContext *s)
static int decode(AVCodecContext *avctx, AVFrame *frame, int *got_frame, AVPacket *pkt)
#define av_malloc_array(a, b)
uint8_t lowpass_precision
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.
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.