85 #define classic_shift_luma_table_size 42
87 34,36,35,69,135,232,9,16,10,24,11,23,12,16,13,10,14,8,15,8,
88 16,8,17,20,16,10,207,206,205,236,11,8,10,21,9,23,8,8,199,70,
92 #define classic_shift_chroma_table_size 59
94 66,36,37,38,39,40,41,75,76,77,110,239,144,81,82,83,84,85,118,183,
95 56,57,88,89,56,89,154,57,58,57,26,141,57,56,58,57,58,57,184,119,
96 214,245,116,83,82,49,80,79,78,77,44,75,41,40,39,38,37,36,34, 0
100 3, 9, 5, 12, 10, 35, 32, 29, 27, 50, 48, 45, 44, 41, 39, 37,
101 73, 70, 68, 65, 64, 61, 58, 56, 53, 50, 49, 46, 44, 41, 38, 36,
102 68, 65, 63, 61, 58, 55, 53, 51, 48, 46, 45, 43, 41, 39, 38, 36,
103 35, 33, 32, 30, 29, 27, 26, 25, 48, 47, 46, 44, 43, 41, 40, 39,
104 37, 36, 35, 34, 32, 31, 30, 28, 27, 26, 24, 23, 22, 20, 19, 37,
105 35, 34, 33, 31, 30, 29, 27, 26, 24, 23, 21, 20, 18, 17, 15, 29,
106 27, 26, 24, 22, 21, 19, 17, 16, 14, 26, 25, 23, 21, 19, 18, 16,
107 15, 27, 25, 23, 21, 19, 17, 16, 14, 26, 25, 23, 21, 18, 17, 14,
108 12, 17, 19, 13, 4, 9, 2, 11, 1, 7, 8, 0, 16, 3, 14, 6,
109 12, 10, 5, 15, 18, 11, 10, 13, 15, 16, 19, 20, 22, 24, 27, 15,
110 18, 20, 22, 24, 26, 14, 17, 20, 22, 24, 27, 15, 18, 20, 23, 25,
111 28, 16, 19, 22, 25, 28, 32, 36, 21, 25, 29, 33, 38, 42, 45, 49,
112 28, 31, 34, 37, 40, 42, 44, 47, 49, 50, 52, 54, 56, 57, 59, 60,
113 62, 64, 66, 67, 69, 35, 37, 39, 40, 42, 43, 45, 47, 48, 51, 52,
114 54, 55, 57, 59, 60, 62, 63, 66, 67, 69, 71, 72, 38, 40, 42, 43,
115 46, 47, 49, 51, 26, 28, 30, 31, 33, 34, 18, 19, 11, 13, 7, 8,
119 3, 1, 2, 2, 2, 2, 3, 3, 7, 5, 7, 5, 8, 6, 11, 9,
120 7, 13, 11, 10, 9, 8, 7, 5, 9, 7, 6, 4, 7, 5, 8, 7,
121 11, 8, 13, 11, 19, 15, 22, 23, 20, 33, 32, 28, 27, 29, 51, 77,
122 43, 45, 76, 81, 46, 82, 75, 55, 56,144, 58, 80, 60, 74,147, 63,
123 143, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79,
124 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 27, 30, 21, 22,
125 17, 14, 5, 6,100, 54, 47, 50, 51, 53,106,107,108,109,110,111,
126 112,113,114,115, 4,117,118, 92, 94,121,122, 3,124,103, 2, 1,
127 0,129,130,131,120,119,126,125,136,137,138,139,140,141,142,134,
128 135,132,133,104, 64,101, 62, 57,102, 95, 93, 59, 61, 28, 97, 96,
129 52, 49, 48, 29, 32, 25, 24, 46, 23, 98, 45, 44, 43, 20, 42, 41,
130 19, 18, 99, 40, 15, 39, 38, 16, 13, 12, 11, 37, 10, 9, 8, 36,
131 7,128,127,105,123,116, 35, 34, 33,145, 31, 79, 42,146, 78, 26,
132 83, 48, 49, 50, 44, 47, 26, 31, 30, 18, 17, 19, 21, 24, 25, 13,
133 14, 16, 17, 18, 20, 21, 12, 14, 15, 9, 10, 6, 9, 6, 5, 8,
134 6, 12, 8, 10, 7, 9, 6, 4, 6, 2, 2, 3, 3, 3, 3, 2,
141 const int temp= src[i];
148 const int temp= src[i];
163 for(i=0; i<
FFMIN(w,4); i++){
164 const int rt= src[i*4+
R];
165 const int gt= src[i*4+
G];
166 const int bt= src[i*4+
B];
175 *red= src[(w-1)*4+
R];
176 *green= src[(w-1)*4+
G];
177 *blue= src[(w-1)*4+
B];
203 for(len=32; len>0; len--){
204 for(index=0; index<256; index++){
205 if(len_table[index]==len)
217 #if CONFIG_HUFFYUV_ENCODER || CONFIG_FFVHUFF_ENCODER
223 static void heap_sift(HeapElem *h,
int root,
int size)
225 while(root*2+1 < size) {
226 int child = root*2+1;
227 if(child < size-1 && h[child].val > h[child+1].val)
229 if(h[root].val > h[child].val) {
230 FFSWAP(HeapElem, h[root], h[child]);
237 static void generate_len_table(uint8_t *dst,
const uint64_t *stats){
244 for(offset=1; ; offset<<=1){
245 for(i=0; i<
size; i++){
247 h[i].val = (stats[i] << 8) + offset;
249 for(i=size/2-1; i>=0; i--)
250 heap_sift(h, i, size);
252 for(next=size; next<size*2-1; next++){
254 uint64_t min1v = h[0].val;
255 up[h[0].name] = next;
257 heap_sift(h, 0, size);
258 up[h[0].name] = next;
261 heap_sift(h, 0, size);
265 for(i=2*size-3; i>=
size; i--)
266 len[i] = len[up[i]] + 1;
267 for(i=0; i<
size; i++) {
268 dst[i] = len[up[i]] + 1;
269 if(dst[i] >= 32)
break;
285 for(i=y=0; y<256; y++){
286 int len0 = s->
len[0][y];
290 for(u=0; u<256; u++){
291 int len1 = s->
len[p][u];
294 len[i] = len0 + len1;
295 bits[i] = (s->
bits[0][y] << len1) + s->
bits[p][u];
296 symbols[i] = (y<<8) + u;
297 if(symbols[i] != 0xffff)
303 bits, 2, 2, symbols, 2, 2, 0)) < 0)
308 int i,
b,
g,
r, code;
314 for(i=0,
g=-16;
g<16;
g++){
315 int len0 = s->
len[p0][
g&255];
319 for(
b=-16;
b<16;
b++){
320 int len1 = s->
len[p1][
b&255];
321 int limit1 = limit0 - len1;
324 code = (s->
bits[p0][
g&255] << len1) + s->
bits[p1][
b&255];
325 for(
r=-16;
r<16;
r++){
326 int len2 = s->
len[2][
r&255];
329 len[i] = len0 + len1 + len2;
330 bits[i] = (code << len2) + s->
bits[2][
r&255];
366 s->
bits[i], 4, 4, 0)) < 0)
396 memcpy(s->
bits[1], s->
bits[0], 256*
sizeof(uint32_t));
397 memcpy(s->
len[1] , s->
len [0], 256*
sizeof(uint8_t));
399 memcpy(s->
bits[2], s->
bits[1], 256*
sizeof(uint32_t));
400 memcpy(s->
len[2] , s->
len [1], 256*
sizeof(uint8_t));
405 s->
bits[i], 4, 4, 0)) < 0)
446 #if CONFIG_HUFFYUV_DECODER || CONFIG_FFVHUFF_DECODER
453 memset(s->
vlc, 0, 3*
sizeof(
VLC));
470 int method, interlace;
481 interlace= (((uint8_t*)avctx->
extradata)[2] & 0x30) >> 4;
544 "for this combination of colorspace and predictor type.\n");
563 for (i = 0; i < 6; i++)
579 #if CONFIG_HUFFYUV_ENCODER || CONFIG_FFVHUFF_ENCODER
580 static int store_table(
HYuvContext *s,
const uint8_t *len, uint8_t *buf){
588 for(; i<256 && len[i]==val && repeat<255; i++)
591 assert(val < 32 && val >0 && repeat<256 && repeat>0);
594 buf[index++]= repeat;
596 buf[index++]= val | (repeat<<5);
637 av_log(avctx,
AV_LOG_ERROR,
"context=1 is not compatible with 2 pass huffyuv encoding\n");
644 av_log(avctx,
AV_LOG_ERROR,
"Error: YV12 is not supported by huffyuv; use vcodec=ffvhuff or format=422p\n");
648 av_log(avctx,
AV_LOG_ERROR,
"Error: per-frame huffman tables are not supported by huffyuv; use vcodec=ffvhuff\n");
679 for(j=0; j<256; j++){
680 s->
stats[i][j]+= strtol(p, &next, 0);
681 if(next==p)
return -1;
685 if(p[0]==0 || p[1]==0 || p[2]==0)
break;
689 for(j=0; j<256; j++){
690 int d=
FFMIN(j, 256-j);
692 s->
stats[i][j]= 100000000/(d+1);
697 generate_len_table(s->
len[i], s->
stats[i]);
710 for(j=0; j<256; j++){
711 int d=
FFMIN(j, 256-j);
712 s->
stats[i][j]= pels/(d+1);
733 #define READ_2PIX(dst0, dst1, plane1){\
734 uint16_t code = get_vlc2(&s->gb, s->vlc[3+plane1].table, VLC_BITS, 1);\
739 dst0 = get_vlc2(&s->gb, s->vlc[0].table, VLC_BITS, 3);\
740 dst1 = get_vlc2(&s->gb, s->vlc[plane1].table, VLC_BITS, 3);\
755 for(i=0; i<count; i++){
772 for(i=0; i<count; i++){
778 #if CONFIG_HUFFYUV_ENCODER || CONFIG_FFVHUFF_ENCODER
779 static int encode_422_bitstream(
HYuvContext *s,
int offset,
int count){
781 const uint8_t *y = s->
temp[0] + offset;
782 const uint8_t *u = s->
temp[1] + offset/2;
783 const uint8_t *
v = s->
temp[2] + offset/2;
798 for(i=0; i<count; i++){
809 for(i=0; i<count; i++){
821 for(i=0; i<count; i++){
832 static int encode_gray_bitstream(
HYuvContext *s,
int count){
841 int y0 = s->temp[0][2*i];\
842 int y1 = s->temp[0][2*i+1];
847 put_bits(&s->pb, s->len[0][y0], s->bits[0][y0]);\
848 put_bits(&s->pb, s->len[0][y1], s->bits[0][y1]);
852 for(i=0; i<count; i++){
861 for(i=0; i<count; i++){
867 for(i=0; i<count; i++){
878 for(i=0; i<count; i++){
882 }
else if(decorrelate){
919 int g= s->temp[0][4*i+G];\
920 int b= (s->temp[0][4*i+B] - g) & 0xff;\
921 int r= (s->temp[0][4*i+R] - g) & 0xff;
927 put_bits(&s->pb, s->len[1][g], s->bits[1][g]);\
928 put_bits(&s->pb, s->len[0][b], s->bits[0][b]);\
929 put_bits(&s->pb, s->len[2][r], s->bits[2][r]);
932 for(i=0; i<count; i++){
937 for(i=0; i<count; i++){
943 for(i=0; i<count; i++){
951 #if CONFIG_HUFFYUV_DECODER || CONFIG_FFVHUFF_DECODER
981 const uint8_t *buf = avpkt->
data;
982 int buf_size = avpkt->
size;
985 const int width2= s->
width>>1;
987 int fake_ystride, fake_ustride, fake_vstride;
989 int table_size = 0, ret;
1015 if((
unsigned)(buf_size-table_size) >= INT_MAX/8)
1019 (buf_size - table_size) * 8)) < 0)
1030 int lefty, leftu, leftv;
1031 int lefttopy, lefttopu, lefttopv;
1058 for(cy=y=1; y<s->
height; y++,cy++){
1059 uint8_t *ydst, *udst, *vdst;
1131 lefttopy= p->
data[0][3];
1135 lefttopu= p->
data[1][1];
1136 lefttopv= p->
data[2][1];
1142 for(; y<
height; y++,cy++){
1143 uint8_t *ydst, *udst, *vdst;
1152 if(y>=height)
break;
1175 int leftr, leftg, leftb, lefta;
1176 const int last_line= (height-1)*p->
linesize[0];
1187 lefta= p->
data[0][last_line+
A]= 255;
1198 for(y=s->
height-2; y>=0; y--){
1206 p->
data[0] + p->
linesize[0]*y + fake_ystride, fake_ystride);
1239 #if CONFIG_HUFFYUV_DECODER || CONFIG_FFVHUFF_DECODER
1259 #if CONFIG_HUFFYUV_ENCODER || CONFIG_FFVHUFF_ENCODER
1263 const int width= s->
width;
1264 const int width2= s->
width>>1;
1265 const int height= s->
height;
1278 generate_len_table(s->
len[i], s->
stats[i]);
1281 size+= store_table(s, s->
len[i], &buf[size]);
1285 for(j=0; j<256; j++)
1286 s->
stats[i][j] >>= 1;
1292 int lefty, leftu, leftv, y, cy;
1303 encode_422_bitstream(s, 2, width-2);
1306 int lefttopy, lefttopu, lefttopv;
1313 encode_422_bitstream(s, 0, width);
1321 encode_422_bitstream(s, 0, 4);
1323 lefttopy= p->
data[0][3];
1324 lefttopu= p->
data[1][1];
1325 lefttopv= p->
data[2][1];
1329 encode_422_bitstream(s, 0, width-4);
1332 for(; y<
height; y++,cy++){
1333 uint8_t *ydst, *udst, *vdst;
1339 encode_gray_bitstream(s, width);
1342 if(y>=height)
break;
1352 encode_422_bitstream(s, 0, width);
1355 for(cy=y=1; y<
height; y++,cy++){
1356 uint8_t *ydst, *udst, *vdst;
1369 encode_gray_bitstream(s, width);
1371 if(y>=height)
break;
1392 encode_422_bitstream(s, 0, width);
1396 uint8_t *data = p->
data[0] + (height-1)*p->
linesize[0];
1398 const int fake_stride = -fake_ystride;
1400 int leftr, leftg, leftb;
1410 for(y=1; y<s->
height; y++){
1411 uint8_t *dst = data + y*
stride;
1433 char *end= p + 1024*30;
1435 for(j=0; j<256; j++){
1436 snprintf(p, end-p,
"%"PRIu64
" ", s->
stats[i][j]);
1440 snprintf(p, end-p,
"\n");
1447 s->
dsp.
bswap_buf((uint32_t*)buf, (uint32_t*)buf, size);
1468 #if CONFIG_HUFFYUV_DECODER
1469 AVCodec ff_huffyuv_decoder = {
1483 #if CONFIG_FFVHUFF_DECODER
1484 AVCodec ff_ffvhuff_decoder = {
1498 #if CONFIG_HUFFYUV_ENCODER
1499 AVCodec ff_huffyuv_encoder = {
1512 #if CONFIG_FFVHUFF_ENCODER
1513 AVCodec ff_ffvhuff_encoder = {
planar YUV 4:2:2, 16bpp, (1 Cr & Cb sample per 2x1 Y samples)
void * av_mallocz(size_t size)
Allocate a block of size bytes with alignment suitable for all memory accesses (including vectors if ...
enum PixelFormat pix_fmt
Pixel format, see PIX_FMT_xxx.
static void sub_left_prediction_bgr32(HYuvContext *s, uint8_t *dst, uint8_t *src, int w, int *red, int *green, int *blue)
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
static int common_end(HYuvContext *s)
void(* add_hfyu_left_prediction_bgr32)(uint8_t *dst, const uint8_t *src, int w, int *red, int *green, int *blue, int *alpha)
void(* release_buffer)(struct AVCodecContext *c, AVFrame *pic)
Called to release buffers which were allocated with get_buffer.
static int generate_bits_table(uint32_t *dst, const uint8_t *len_table)
static unsigned int get_bits(GetBitContext *s, int n)
Read 1-25 bits.
static const unsigned char classic_shift_luma[classic_shift_luma_table_size+FF_INPUT_BUFFER_PADDING_SIZE]
#define CODEC_CAP_FRAME_THREADS
Codec supports frame-level multithreading.
AVFrame * coded_frame
the picture in the bitstream
static av_cold int encode_end(AVCodecContext *avctx)
static av_cold int encode_init(AVCodecContext *avctx)
char * stats_in
pass2 encoding statistics input buffer Concatenated stuff from stats_out of pass1 should be placed he...
static av_always_inline void decode_bgr_1(HYuvContext *s, int count, int decorrelate, int alpha)
unsigned int bitstream_buffer_size
#define CODEC_FLAG_PASS1
Use internal 2pass ratecontrol in first pass mode.
void av_fast_malloc(void *ptr, unsigned int *size, size_t min_size)
Allocate a buffer, reusing the given one if large enough.
void av_freep(void *arg)
Free a memory block which has been allocated with av_malloc(z)() or av_realloc() and set the pointer ...
static int decode_init_thread_copy(AVCodecContext *avctx)
int context_model
context model
static int decode(MimicContext *ctx, int quality, int num_coeffs, int is_iframe)
uint32_t pix_bgr_map[1<< VLC_BITS]
int ff_init_vlc_sparse(VLC *vlc, int nb_bits, int nb_codes, const void *bits, int bits_wrap, int bits_size, const void *codes, int codes_wrap, int codes_size, const void *symbols, int symbols_wrap, int symbols_size, int flags)
planar YUV 4:2:0, 12bpp, (1 Cr & Cb sample per 2x2 Y samples)
static int sub_left_prediction(HYuvContext *s, uint8_t *dst, uint8_t *src, int w, int left)
uint8_t * extradata
some codecs need / can use extradata like Huffman tables.
void(* add_bytes)(uint8_t *dst, uint8_t *src, int w)
static av_cold int decode_init(AVCodecContext *avctx)
static int get_bits_count(const GetBitContext *s)
bitstream reader API header.
static int read_huffman_tables(HYuvContext *s, const uint8_t *src, int length)
static void decode_gray_bitstream(HYuvContext *s, int count)
int bits_per_coded_sample
bits per sample/pixel from the demuxer (needed for huffyuv).
static void draw_slice(AVFilterLink *inlink, int y, int h, int slice_dir)
char * stats_out
pass1 encoding statistics output buffer
av_cold void dsputil_init(DSPContext *c, AVCodecContext *avctx)
static int encode_bgr_bitstream(HYuvContext *s, int count)
static int init(AVCodecParserContext *s)
#define CODEC_FLAG_GRAY
Only decode/encode grayscale.
#define LOAD4(vec, address)
#define CODEC_CAP_DR1
Codec uses get_buffer() for allocating buffers and supports custom allocators.
static int get_bits_left(GetBitContext *gb)
#define CODEC_FLAG_PASS2
Use internal 2pass ratecontrol in second pass mode.
void(* sub_hfyu_median_prediction)(uint8_t *dst, const uint8_t *src1, const uint8_t *src2, int w, int *left, int *left_top)
subtract huffyuv's variant of median prediction note, this might read from src1[-1], src2[-1]
Multithreading support functions.
int reference
is this picture used as reference The values for this are the same as the MpegEncContext.picture_structure variable, that is 1->top field, 2->bottom field, 3->frame/both fields.
void(* bswap_buf)(uint32_t *dst, const uint32_t *src, int w)
uint8_t * bitstream_buffer
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification. ...
#define READ_2PIX(dst0, dst1, plane1)
void av_log(void *avcl, int level, const char *fmt,...)
int(* add_hfyu_left_prediction)(uint8_t *dst, const uint8_t *src, int w, int left)
const char * name
Name of the codec implementation.
static void put_bits(PutBitContext *s, int n, unsigned int value)
Write up to 31 bits into a bitstream.
#define AV_NUM_DATA_POINTERS
static void decode_bgr_bitstream(HYuvContext *s, int count)
static int put_bits_count(PutBitContext *s)
#define ONLY_IF_THREADS_ENABLED(x)
Define a function with only the non-default version specified.
static av_always_inline void emms_c(void)
Empty mmx state.
static void decode_422_bitstream(HYuvContext *s, int count)
void(* add_hfyu_median_prediction)(uint8_t *dst, const uint8_t *top, const uint8_t *diff, int w, int *left, int *left_top)
void(* draw_horiz_band)(struct AVCodecContext *s, const AVFrame *src, int offset[AV_NUM_DATA_POINTERS], int y, int type, int height)
If non NULL, 'draw_horiz_band' is called by the libavcodec decoder to draw a horizontal band...
enum AVPictureType pict_type
Picture type of the frame, see ?_TYPE below.
static int decode_frame(AVCodecContext *avctx, void *data, int *data_size, AVPacket *avpkt)
int width
picture width / height.
struct AVFrame AVFrame
Audio Video Frame.
static av_always_inline int get_vlc2(GetBitContext *s, VLC_TYPE(*table)[2], int bits, int max_depth)
Parse a vlc code.
static av_cold void alloc_temp(HYuvContext *s)
int AC3_NAME() encode_frame(AVCodecContext *avctx, unsigned char *frame, int buf_size, void *data)
int linesize[AV_NUM_DATA_POINTERS]
Size, in bytes, of the data for each picture/channel plane.
main external API structure.
static void close(AVCodecParserContext *s)
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
packed YUV 4:2:2, 16bpp, Y0 Cb Y1 Cr
#define init_vlc(vlc, nb_bits, nb_codes,bits, bits_wrap, bits_size,codes, codes_wrap, codes_size,flags)
void * av_malloc(size_t size)
Allocate a block of size bytes with alignment suitable for all memory accesses (including vectors if ...
static void skip_bits(GetBitContext *s, int n)
#define CODEC_CAP_DRAW_HORIZ_BAND
static int init_get_bits(GetBitContext *s, const uint8_t *buffer, int bit_size)
Initialize GetBitContext.
#define FF_INPUT_BUFFER_PADDING_SIZE
Required number of additionally allocated bytes at the end of the input bitstream for decoding...
packed RGB 8:8:8, 24bpp, BGRBGR...
static int read_len_table(uint8_t *dst, GetBitContext *gb)
static av_cold int decode_end(AVCodecContext *avctx)
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
#define CODEC_FLAG_INTERLACED_ME
interlaced motion estimation
static int generate_joint_tables(HYuvContext *s)
struct HYuvContext HYuvContext
static int read_old_huffman_tables(HYuvContext *s)
void(* diff_bytes)(uint8_t *dst, uint8_t *src1, uint8_t *src2, int w)
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
static void flush_put_bits(PutBitContext *s)
Pad the end of the output stream with zeros.
#define CODEC_FLAG2_NO_OUTPUT
Skip bitstream encoding.
static const unsigned char classic_shift_chroma[classic_shift_chroma_table_size+FF_INPUT_BUFFER_PADDING_SIZE]
int prediction_method
prediction method (needed for huffyuv)
static void init_put_bits(PutBitContext *s, uint8_t *buffer, int buffer_size)
Initialize the PutBitContext s.
#define classic_shift_luma_table_size
VLC_TYPE(* table)[2]
code, bits
int key_frame
1 -> keyframe, 0-> not
static const unsigned char classic_add_luma[256]
static av_cold int common_init(AVCodecContext *avctx)
#define classic_shift_chroma_table_size
int ff_thread_get_buffer(AVCodecContext *avctx, AVFrame *f)
Wrapper around get_buffer() for frame-multithreaded codecs.
#define FFSWAP(type, a, b)
static const unsigned char classic_add_chroma[256]
void ff_free_vlc(VLC *vlc)
void ff_thread_release_buffer(AVCodecContext *avctx, AVFrame *f)
Wrapper around release_buffer() frame-for multithreaded codecs.