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) {
267 }
else if (tag == 12) {
275 }
else if (tag == 14) {
282 }
else if (tag == 62) {
291 }
else if (tag == 48) {
306 }
else if (tag == 51) {
314 }
else if (tag == 35)
316 else if (tag == 53) {
319 }
else if (tag == 109) {
324 }
else if (tag == 27) {
333 }
else if (tag == 28) {
343 else if (tag == 10) {
350 }
else if (abstag >= 0x4000 && abstag <= 0x40ff) {
351 av_log(avctx,
AV_LOG_DEBUG,
"Small chunk length %d %s\n", data * 4, tag < 0 ?
"optional" :
"required");
353 }
else if (tag == 23) {
358 }
else if (tag == 2) {
365 for (i = 0; i <
data; i++) {
366 uint16_t tag2 = bytestream2_get_be16(&gb);
367 uint16_t val2 = bytestream2_get_be16(&gb);
370 }
else if (tag == 41) {
379 }
else if (tag == 42) {
387 }
else if (tag == 49) {
396 }
else if (tag == 50) {
404 }
else if (tag == 71) {
407 }
else if (tag == 72) {
410 }
else if (tag == 70) {
412 if (!(data == 10 || data == 12)) {
418 }
else if (tag == 84) {
475 if (lowpass_height > lowpass_a_height || lowpass_width > lowpass_a_width ||
483 for (i = 0; i < lowpass_height; i++) {
484 for (j = 0; j < lowpass_width; j++)
485 coeff_data[j] = bytestream2_get_be16u(&gb);
487 coeff_data += lowpass_width;
494 if (lowpass_height & 1) {
495 memcpy(&coeff_data[lowpass_height * lowpass_width],
496 &coeff_data[(lowpass_height - 1) * lowpass_width],
497 lowpass_width *
sizeof(*coeff_data));
500 av_log(avctx,
AV_LOG_DEBUG,
"Lowpass coefficients %d\n", lowpass_width * lowpass_height);
510 int a_expected = highpass_a_height * highpass_a_width;
512 int count = 0, bytes;
520 if (highpass_height > highpass_a_height || highpass_width > highpass_a_width || a_expected < highpass_height * (uint64_t)highpass_stride) {
525 expected = highpass_height * highpass_stride;
544 if (count > expected)
548 for (i = 0; i <
run; i++)
549 *coeff_data++ = coeff;
558 if (level == 255 && run == 2)
563 if (count > expected)
567 for (i = 0; i <
run; i++)
568 *coeff_data++ = coeff;
574 if (count > expected) {
588 av_log(avctx,
AV_LOG_DEBUG,
"End subband coeffs %i extra %i\n", count, count - expected);
592 if (highpass_height & 1) {
593 memcpy(&coeff_data[highpass_height * highpass_stride],
594 &coeff_data[(highpass_height - 1) * highpass_stride],
595 highpass_stride *
sizeof(*coeff_data));
614 for (plane = 0; plane < planes && !ret; plane++) {
619 int act_plane = plane == 1 ? 2 : plane == 2 ? 1 :
plane;
620 int16_t *low, *high, *output, *dst;
629 av_log(avctx,
AV_LOG_DEBUG,
"Decoding level 1 plane %i %i %i %i\n", plane, lowpass_height, lowpass_width, highpass_stride);
634 for (i = 0; i < lowpass_width; i++) {
635 vert_filter(output, lowpass_width, low, lowpass_width, high, highpass_stride, lowpass_height);
645 for (i = 0; i < lowpass_width; i++) {
647 vert_filter(output, lowpass_width, low, highpass_stride, high, highpass_stride, lowpass_height);
656 for (i = 0; i < lowpass_height * 2; i++) {
658 low += lowpass_width;
659 high += lowpass_width;
660 output += lowpass_width * 2;
664 for (i = 0; i < lowpass_height * 2; i++) {
665 for (j = 0; j < lowpass_width * 2; j++)
668 output += lowpass_width * 2;
684 av_log(avctx,
AV_LOG_DEBUG,
"Level 2 plane %i %i %i %i\n", plane, lowpass_height, lowpass_width, highpass_stride);
689 for (i = 0; i < lowpass_width; i++) {
690 vert_filter(output, lowpass_width, low, lowpass_width, high, highpass_stride, lowpass_height);
699 for (i = 0; i < lowpass_width; i++) {
700 vert_filter(output, lowpass_width, low, highpass_stride, high, highpass_stride, lowpass_height);
709 for (i = 0; i < lowpass_height * 2; i++) {
711 low += lowpass_width;
712 high += lowpass_width;
713 output += lowpass_width * 2;
717 for (i = 0; i < lowpass_height * 2; i++) {
718 for (j = 0; j < lowpass_width * 2; j++)
721 output += lowpass_width * 2;
736 av_log(avctx,
AV_LOG_DEBUG,
"Level 3 plane %i %i %i %i\n", plane, lowpass_height, lowpass_width, highpass_stride);
741 for (i = 0; i < lowpass_width; i++) {
742 vert_filter(output, lowpass_width, low, lowpass_width, high, highpass_stride, lowpass_height);
751 for (i = 0; i < lowpass_width; i++) {
752 vert_filter(output, lowpass_width, low, highpass_stride, high, highpass_stride, lowpass_height);
758 dst = (int16_t *)pic->
data[act_plane];
761 for (i = 0; i < lowpass_height * 2; i++) {
763 low += lowpass_width;
764 high += lowpass_width;
765 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.