40 #define ALPHA_COMPAND_DC_OFFSET 256
41 #define ALPHA_COMPAND_GAIN 9400
108 if (codebook == 0 || codebook == 1) {
109 int64_t abslevel = abs(level);
111 return (abslevel + ((768 * abslevel * abslevel * abslevel) / (255 * 255 * 255))) *
112 FFSIGN(level) * quantisation;
114 return level * quantisation;
116 return level * quantisation;
123 for (i = 0; i <
height; i++) {
124 for (j = 1; j <
width; j++) {
125 band[j] += band[j-1];
134 for (i = 0; i <
length; i++)
135 if (abs(band[i]) > peak->
level)
136 band[i] = bytestream2_get_le16(&peak->
base);
142 for (i = 0; i <
width; i++) {
148 channel = av_clip_uintp2(channel, 12);
153 static inline void filter(int16_t *output, ptrdiff_t out_stride,
154 int16_t *low, ptrdiff_t low_stride,
155 int16_t *high, ptrdiff_t high_stride,
161 for (i = 0; i <
len; i++) {
163 tmp = (11*low[0*low_stride] - 4*low[1*low_stride] + low[2*low_stride] + 4) >> 3;
164 output[(2*i+0)*out_stride] = (tmp + high[0*high_stride]) >> 1;
168 tmp = ( 5*low[0*low_stride] + 4*low[1*low_stride] - low[2*low_stride] + 4) >> 3;
169 output[(2*i+1)*out_stride] = (tmp - high[0*high_stride]) >> 1;
172 }
else if (i == len-1) {
173 tmp = ( 5*low[i*low_stride] + 4*low[(i-1)*low_stride] - low[(i-2)*low_stride] + 4) >> 3;
174 output[(2*i+0)*out_stride] = (tmp + high[i*high_stride]) >> 1;
178 tmp = (11*low[i*low_stride] - 4*low[(i-1)*low_stride] + low[(i-2)*low_stride] + 4) >> 3;
179 output[(2*i+1)*out_stride] = (tmp - high[i*high_stride]) >> 1;
183 tmp = (low[(i-1)*low_stride] - low[(i+1)*low_stride] + 4) >> 3;
184 output[(2*i+0)*out_stride] = (tmp + low[i*low_stride] + high[i*high_stride]) >> 1;
188 tmp = (low[(i+1)*low_stride] - low[(i-1)*low_stride] + 4) >> 3;
189 output[(2*i+1)*out_stride] = (tmp + low[i*low_stride] - high[i*high_stride]) >> 1;
201 for (i = 0; i <
width; i++) {
202 even = (low[i] - high[i])/2;
203 odd = (low[i] + high[i])/2;
204 output[i] = av_clip_uintp2(even, 10);
205 output[i + linesize] = av_clip_uintp2(odd, 10);
211 filter(output, 1, low, 1, high, 1, width, 0);
217 filter(output, 1, low, 1, high, 1, width, clip);
221 int16_t *low, ptrdiff_t low_stride,
222 int16_t *high, ptrdiff_t high_stride,
int len)
224 filter(output, out_stride, low, low_stride, high, high_stride, len, 0);
235 for (j = 0; j < 9; j++)
238 for (j = 0; j < 8; j++)
249 int chroma_x_shift, chroma_y_shift;
258 &chroma_y_shift)) < 0)
262 for (i = 0; i <
planes; i++) {
263 int w8, h8, w4, h4, w2, h2;
268 height =
FFALIGN(height / 8, 2) * 8;
341 uint16_t tagu = bytestream2_get_be16(&gb);
342 int16_t
tag = (int16_t)tagu;
343 int8_t tag8 = (int8_t)(tagu >> 8);
344 uint16_t abstag = abs(tag);
345 int8_t abs_tag8 = abs(tag8);
346 uint16_t data = bytestream2_get_be16(&gb);
347 if (abs_tag8 >= 0x60 && abs_tag8 <= 0x6f) {
358 }
else if (tag == 101) {
405 }
else if (tag == 51) {
423 }
else if (tag == 27) {
432 }
else if (tag == 28) {
442 else if (tag == 10) {
449 }
else if (abstag >= 0x4000 && abstag <= 0x40ff) {
450 if (abstag == 0x4001)
452 av_log(avctx,
AV_LOG_DEBUG,
"Small chunk length %d %s\n", data * 4, tag < 0 ?
"optional" :
"required");
454 }
else if (tag == 23) {
459 }
else if (tag == 2) {
466 for (i = 0; i <
data; i++) {
467 uint16_t tag2 = bytestream2_get_be16(&gb);
468 uint16_t val2 = bytestream2_get_be16(&gb);
471 }
else if (tag == 41) {
480 }
else if (tag == 42) {
488 }
else if (tag == 49) {
497 }
else if (tag == 50) {
505 }
else if (tag == 71) {
508 }
else if (tag == 72) {
512 }
else if (tag == 70) {
514 if (!(data == 10 || data == 12)) {
520 }
else if (tag == 84) {
534 }
else if (tag == -85) {
537 }
else if (tag == -75) {
542 }
else if (tag == -76) {
595 if (lowpass_height > lowpass_a_height || lowpass_width > lowpass_a_width ||
603 for (i = 0; i < lowpass_height; i++) {
604 for (j = 0; j < lowpass_width; j++)
605 coeff_data[j] = bytestream2_get_be16u(&gb);
607 coeff_data += lowpass_width;
614 if (lowpass_height & 1) {
615 memcpy(&coeff_data[lowpass_height * lowpass_width],
616 &coeff_data[(lowpass_height - 1) * lowpass_width],
617 lowpass_width *
sizeof(*coeff_data));
620 av_log(avctx,
AV_LOG_DEBUG,
"Lowpass coefficients %d\n", lowpass_width * lowpass_height);
630 int a_expected = highpass_a_height * highpass_a_width;
632 int count = 0, bytes;
640 if (highpass_height > highpass_a_height || highpass_width > highpass_a_width || a_expected < highpass_height * (uint64_t)highpass_stride) {
645 expected = highpass_height * highpass_stride;
664 if (count > expected)
668 for (i = 0; i <
run; i++)
669 *coeff_data++ = coeff;
678 if (level == 255 && run == 2)
683 if (count > expected)
687 for (i = 0; i <
run; i++)
688 *coeff_data++ = coeff;
694 if (count > expected) {
712 av_log(avctx,
AV_LOG_DEBUG,
"End subband coeffs %i extra %i\n", count, count - expected);
716 if (highpass_height & 1) {
717 memcpy(&coeff_data[highpass_height * highpass_stride],
718 &coeff_data[(highpass_height - 1) * highpass_stride],
719 highpass_stride *
sizeof(*coeff_data));
738 for (plane = 0; plane < planes && !ret; plane++) {
743 int act_plane = plane == 1 ? 2 : plane == 2 ? 1 :
plane;
744 int16_t *low, *high, *output, *dst;
753 av_log(avctx,
AV_LOG_DEBUG,
"Decoding level 1 plane %i %i %i %i\n", plane, lowpass_height, lowpass_width, highpass_stride);
758 for (i = 0; i < lowpass_width; i++) {
759 vert_filter(output, lowpass_width, low, lowpass_width, high, highpass_stride, lowpass_height);
769 for (i = 0; i < lowpass_width; i++) {
771 vert_filter(output, lowpass_width, low, highpass_stride, high, highpass_stride, lowpass_height);
780 for (i = 0; i < lowpass_height * 2; i++) {
782 low += lowpass_width;
783 high += lowpass_width;
784 output += lowpass_width * 2;
788 for (i = 0; i < lowpass_height * 2; i++) {
789 for (j = 0; j < lowpass_width * 2; j++)
792 output += lowpass_width * 2;
808 av_log(avctx,
AV_LOG_DEBUG,
"Level 2 plane %i %i %i %i\n", plane, lowpass_height, lowpass_width, highpass_stride);
813 for (i = 0; i < lowpass_width; i++) {
814 vert_filter(output, lowpass_width, low, lowpass_width, high, highpass_stride, lowpass_height);
823 for (i = 0; i < lowpass_width; i++) {
824 vert_filter(output, lowpass_width, low, highpass_stride, high, highpass_stride, lowpass_height);
833 for (i = 0; i < lowpass_height * 2; i++) {
835 low += lowpass_width;
836 high += lowpass_width;
837 output += lowpass_width * 2;
841 for (i = 0; i < lowpass_height * 2; i++) {
842 for (j = 0; j < lowpass_width * 2; j++)
845 output += lowpass_width * 2;
860 av_log(avctx,
AV_LOG_DEBUG,
"Level 3 plane %i %i %i %i\n", plane, lowpass_height, lowpass_width, highpass_stride);
865 for (i = 0; i < lowpass_width; i++) {
866 vert_filter(output, lowpass_width, low, lowpass_width, high, highpass_stride, lowpass_height);
875 for (i = 0; i < lowpass_width; i++) {
876 vert_filter(output, lowpass_width, low, highpass_stride, high, highpass_stride, lowpass_height);
882 dst = (int16_t *)pic->
data[act_plane];
885 for (i = 0; i < lowpass_height * 2; i++) {
887 low += lowpass_width;
888 high += lowpass_width;
889 dst += pic->
linesize[act_plane] / 2;
897 for (i = 0; i < lowpass_height; i++) {
899 low += lowpass_width;
900 high += lowpass_width;
901 output += lowpass_width * 2;
907 for (i = 0; i < lowpass_height; i++) {
909 low += lowpass_width;
910 high += lowpass_width;
911 output += lowpass_width * 2;
914 dst = (int16_t *)pic->
data[act_plane];
917 for (i = 0; i < lowpass_height; i++) {
919 low += lowpass_width * 2;
920 high += lowpass_width * 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
static void peak_table(int16_t *band, Peak *peak, int length)
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
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)
static void interlaced_vertical_filter(int16_t *output, int16_t *low, int16_t *high, int width, int linesize, int plane)
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.
int interlaced_frame
The content of the picture is interlaced.
static int dequant_and_decompand(int level, int quantisation, int codebook)
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)
static const struct @304 planes[]
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.
static const int16_t alpha[]
main external API structure.
#define OPEN_READER(name, gb)
static av_always_inline int even(uint64_t layout)
static void difference_coding(int16_t *band, int width, int height)
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().
struct AVCodecInternal * internal
Private context used for internal data.
static void init_peak_table_defaults(CFHDContext *s)
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.
#define AV_CEIL_RSHIFT(a, b)
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.