huffyuvenc.c
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2002-2003 Michael Niedermayer <michaelni@gmx.at>
3  *
4  * see http://www.pcisys.net/~melanson/codecs/huffyuv.txt for a description of
5  * the algorithm used
6  *
7  * This file is part of Libav.
8  *
9  * Libav is free software; you can redistribute it and/or
10  * modify it under the terms of the GNU Lesser General Public
11  * License as published by the Free Software Foundation; either
12  * version 2.1 of the License, or (at your option) any later version.
13  *
14  * Libav is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17  * Lesser General Public License for more details.
18  *
19  * You should have received a copy of the GNU Lesser General Public
20  * License along with Libav; if not, write to the Free Software
21  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
22  */
23 
29 #include "avcodec.h"
30 #include "huffyuv.h"
31 #include "huffman.h"
32 #include "put_bits.h"
33 
34 static inline int sub_left_prediction(HYuvContext *s, uint8_t *dst,
35  uint8_t *src, int w, int left)
36 {
37  int i;
38  if (w < 32) {
39  for (i = 0; i < w; i++) {
40  const int temp = src[i];
41  dst[i] = temp - left;
42  left = temp;
43  }
44  return left;
45  } else {
46  for (i = 0; i < 16; i++) {
47  const int temp = src[i];
48  dst[i] = temp - left;
49  left = temp;
50  }
51  s->dsp.diff_bytes(dst + 16, src + 16, src + 15, w - 16);
52  return src[w-1];
53  }
54 }
55 
56 static inline void sub_left_prediction_bgr32(HYuvContext *s, uint8_t *dst,
57  uint8_t *src, int w,
58  int *red, int *green, int *blue)
59 {
60  int i;
61  int r,g,b;
62  r = *red;
63  g = *green;
64  b = *blue;
65 
66  for (i = 0; i < FFMIN(w, 4); i++) {
67  const int rt = src[i * 4 + R];
68  const int gt = src[i * 4 + G];
69  const int bt = src[i * 4 + B];
70  dst[i * 4 + R] = rt - r;
71  dst[i * 4 + G] = gt - g;
72  dst[i * 4 + B] = bt - b;
73  r = rt;
74  g = gt;
75  b = bt;
76  }
77 
78  s->dsp.diff_bytes(dst + 16, src + 16, src + 12, w * 4 - 16);
79 
80  *red = src[(w - 1) * 4 + R];
81  *green = src[(w - 1) * 4 + G];
82  *blue = src[(w - 1) * 4 + B];
83 }
84 
85 static int store_table(HYuvContext *s, const uint8_t *len, uint8_t *buf)
86 {
87  int i;
88  int index = 0;
89 
90  for (i = 0; i < 256;) {
91  int val = len[i];
92  int repeat = 0;
93 
94  for (; i < 256 && len[i] == val && repeat < 255; i++)
95  repeat++;
96 
97  assert(val < 32 && val >0 && repeat<256 && repeat>0);
98  if ( repeat > 7) {
99  buf[index++] = val;
100  buf[index++] = repeat;
101  } else {
102  buf[index++] = val | (repeat << 5);
103  }
104  }
105 
106  return index;
107 }
108 
110 {
111  HYuvContext *s = avctx->priv_data;
112  int i, j;
113 
114  ff_huffyuv_common_init(avctx);
115 
116  avctx->extradata = av_mallocz(1024*30); // 256*3+4 == 772
117  avctx->stats_out = av_mallocz(1024*30); // 21*256*3(%llu ) + 3(\n) + 1(0) = 16132
118  s->version = 2;
119 
120  avctx->coded_frame = &s->picture;
121 
122  switch (avctx->pix_fmt) {
123  case AV_PIX_FMT_YUV420P:
124  s->bitstream_bpp = 12;
125  break;
126  case AV_PIX_FMT_YUV422P:
127  s->bitstream_bpp = 16;
128  break;
129  case AV_PIX_FMT_RGB32:
130  s->bitstream_bpp = 24;
131  break;
132  default:
133  av_log(avctx, AV_LOG_ERROR, "format not supported\n");
134  return -1;
135  }
137  s->decorrelate = s->bitstream_bpp >= 24;
138  s->predictor = avctx->prediction_method;
139  s->interlaced = avctx->flags&CODEC_FLAG_INTERLACED_ME ? 1 : 0;
140  if (avctx->context_model == 1) {
141  s->context = avctx->context_model;
143  av_log(avctx, AV_LOG_ERROR,
144  "context=1 is not compatible with "
145  "2 pass huffyuv encoding\n");
146  return -1;
147  }
148  }else s->context= 0;
149 
150  if (avctx->codec->id == AV_CODEC_ID_HUFFYUV) {
151  if (avctx->pix_fmt == AV_PIX_FMT_YUV420P) {
152  av_log(avctx, AV_LOG_ERROR,
153  "Error: YV12 is not supported by huffyuv; use "
154  "vcodec=ffvhuff or format=422p\n");
155  return -1;
156  }
157  if (avctx->context_model) {
158  av_log(avctx, AV_LOG_ERROR,
159  "Error: per-frame huffman tables are not supported "
160  "by huffyuv; use vcodec=ffvhuff\n");
161  return -1;
162  }
163  if (s->interlaced != ( s->height > 288 ))
164  av_log(avctx, AV_LOG_INFO,
165  "using huffyuv 2.2.0 or newer interlacing flag\n");
166  }
167 
168  if (s->bitstream_bpp >= 24 && s->predictor == MEDIAN) {
169  av_log(avctx, AV_LOG_ERROR,
170  "Error: RGB is incompatible with median predictor\n");
171  return -1;
172  }
173 
174  ((uint8_t*)avctx->extradata)[0] = s->predictor | (s->decorrelate << 6);
175  ((uint8_t*)avctx->extradata)[1] = s->bitstream_bpp;
176  ((uint8_t*)avctx->extradata)[2] = s->interlaced ? 0x10 : 0x20;
177  if (s->context)
178  ((uint8_t*)avctx->extradata)[2] |= 0x40;
179  ((uint8_t*)avctx->extradata)[3] = 0;
180  s->avctx->extradata_size = 4;
181 
182  if (avctx->stats_in) {
183  char *p = avctx->stats_in;
184 
185  for (i = 0; i < 3; i++)
186  for (j = 0; j < 256; j++)
187  s->stats[i][j] = 1;
188 
189  for (;;) {
190  for (i = 0; i < 3; i++) {
191  char *next;
192 
193  for (j = 0; j < 256; j++) {
194  s->stats[i][j] += strtol(p, &next, 0);
195  if (next == p) return -1;
196  p = next;
197  }
198  }
199  if (p[0] == 0 || p[1] == 0 || p[2] == 0) break;
200  }
201  } else {
202  for (i = 0; i < 3; i++)
203  for (j = 0; j < 256; j++) {
204  int d = FFMIN(j, 256 - j);
205 
206  s->stats[i][j] = 100000000 / (d + 1);
207  }
208  }
209 
210  for (i = 0; i < 3; i++) {
211  ff_huff_gen_len_table(s->len[i], s->stats[i]);
212 
213  if (ff_huffyuv_generate_bits_table(s->bits[i], s->len[i]) < 0) {
214  return -1;
215  }
216 
217  s->avctx->extradata_size +=
218  store_table(s, s->len[i], &((uint8_t*)s->avctx->extradata)[s->avctx->extradata_size]);
219  }
220 
221  if (s->context) {
222  for (i = 0; i < 3; i++) {
223  int pels = s->width * s->height / (i ? 40 : 10);
224  for (j = 0; j < 256; j++) {
225  int d = FFMIN(j, 256 - j);
226  s->stats[i][j] = pels/(d + 1);
227  }
228  }
229  } else {
230  for (i = 0; i < 3; i++)
231  for (j = 0; j < 256; j++)
232  s->stats[i][j]= 0;
233  }
234 
236 
237  s->picture_number=0;
238 
239  return 0;
240 }
241 static int encode_422_bitstream(HYuvContext *s, int offset, int count)
242 {
243  int i;
244  const uint8_t *y = s->temp[0] + offset;
245  const uint8_t *u = s->temp[1] + offset / 2;
246  const uint8_t *v = s->temp[2] + offset / 2;
247 
248  if (s->pb.buf_end - s->pb.buf - (put_bits_count(&s->pb) >> 3) < 2 * 4 * count) {
249  av_log(s->avctx, AV_LOG_ERROR, "encoded frame too large\n");
250  return -1;
251  }
252 
253 #define LOAD4\
254  int y0 = y[2 * i];\
255  int y1 = y[2 * i + 1];\
256  int u0 = u[i];\
257  int v0 = v[i];
258 
259  count /= 2;
260 
261  if (s->flags & CODEC_FLAG_PASS1) {
262  for(i = 0; i < count; i++) {
263  LOAD4;
264  s->stats[0][y0]++;
265  s->stats[1][u0]++;
266  s->stats[0][y1]++;
267  s->stats[2][v0]++;
268  }
269  }
271  return 0;
272  if (s->context) {
273  for (i = 0; i < count; i++) {
274  LOAD4;
275  s->stats[0][y0]++;
276  put_bits(&s->pb, s->len[0][y0], s->bits[0][y0]);
277  s->stats[1][u0]++;
278  put_bits(&s->pb, s->len[1][u0], s->bits[1][u0]);
279  s->stats[0][y1]++;
280  put_bits(&s->pb, s->len[0][y1], s->bits[0][y1]);
281  s->stats[2][v0]++;
282  put_bits(&s->pb, s->len[2][v0], s->bits[2][v0]);
283  }
284  } else {
285  for(i = 0; i < count; i++) {
286  LOAD4;
287  put_bits(&s->pb, s->len[0][y0], s->bits[0][y0]);
288  put_bits(&s->pb, s->len[1][u0], s->bits[1][u0]);
289  put_bits(&s->pb, s->len[0][y1], s->bits[0][y1]);
290  put_bits(&s->pb, s->len[2][v0], s->bits[2][v0]);
291  }
292  }
293  return 0;
294 }
295 
296 static int encode_gray_bitstream(HYuvContext *s, int count)
297 {
298  int i;
299 
300  if (s->pb.buf_end - s->pb.buf - (put_bits_count(&s->pb) >> 3) < 4 * count) {
301  av_log(s->avctx, AV_LOG_ERROR, "encoded frame too large\n");
302  return -1;
303  }
304 
305 #define LOAD2\
306  int y0 = s->temp[0][2 * i];\
307  int y1 = s->temp[0][2 * i + 1];
308 #define STAT2\
309  s->stats[0][y0]++;\
310  s->stats[0][y1]++;
311 #define WRITE2\
312  put_bits(&s->pb, s->len[0][y0], s->bits[0][y0]);\
313  put_bits(&s->pb, s->len[0][y1], s->bits[0][y1]);
314 
315  count /= 2;
316 
317  if (s->flags & CODEC_FLAG_PASS1) {
318  for (i = 0; i < count; i++) {
319  LOAD2;
320  STAT2;
321  }
322  }
324  return 0;
325 
326  if (s->context) {
327  for (i = 0; i < count; i++) {
328  LOAD2;
329  STAT2;
330  WRITE2;
331  }
332  } else {
333  for (i = 0; i < count; i++) {
334  LOAD2;
335  WRITE2;
336  }
337  }
338  return 0;
339 }
340 
341 static int encode_bgr_bitstream(HYuvContext *s, int count)
342 {
343  int i;
344 
345  if (s->pb.buf_end - s->pb.buf - (put_bits_count(&s->pb) >> 3) < 3 * 4 * count) {
346  av_log(s->avctx, AV_LOG_ERROR, "encoded frame too large\n");
347  return -1;
348  }
349 
350 #define LOAD3\
351  int g = s->temp[0][4 * i + G];\
352  int b = (s->temp[0][4 * i + B] - g) & 0xff;\
353  int r = (s->temp[0][4 * i + R] - g) & 0xff;
354 #define STAT3\
355  s->stats[0][b]++;\
356  s->stats[1][g]++;\
357  s->stats[2][r]++;
358 #define WRITE3\
359  put_bits(&s->pb, s->len[1][g], s->bits[1][g]);\
360  put_bits(&s->pb, s->len[0][b], s->bits[0][b]);\
361  put_bits(&s->pb, s->len[2][r], s->bits[2][r]);
362 
363  if ((s->flags & CODEC_FLAG_PASS1) &&
365  for (i = 0; i < count; i++) {
366  LOAD3;
367  STAT3;
368  }
369  } else if (s->context || (s->flags & CODEC_FLAG_PASS1)) {
370  for (i = 0; i < count; i++) {
371  LOAD3;
372  STAT3;
373  WRITE3;
374  }
375  } else {
376  for (i = 0; i < count; i++) {
377  LOAD3;
378  WRITE3;
379  }
380  }
381  return 0;
382 }
383 
384 static int encode_frame(AVCodecContext *avctx, AVPacket *pkt,
385  const AVFrame *pict, int *got_packet)
386 {
387  HYuvContext *s = avctx->priv_data;
388  const int width = s->width;
389  const int width2 = s->width>>1;
390  const int height = s->height;
391  const int fake_ystride = s->interlaced ? pict->linesize[0]*2 : pict->linesize[0];
392  const int fake_ustride = s->interlaced ? pict->linesize[1]*2 : pict->linesize[1];
393  const int fake_vstride = s->interlaced ? pict->linesize[2]*2 : pict->linesize[2];
394  AVFrame * const p = &s->picture;
395  int i, j, size = 0, ret;
396 
397  if (!pkt->data &&
398  (ret = av_new_packet(pkt, width * height * 3 * 4 + FF_MIN_BUFFER_SIZE)) < 0) {
399  av_log(avctx, AV_LOG_ERROR, "Error allocating output packet.\n");
400  return ret;
401  }
402 
403  *p = *pict;
405  p->key_frame = 1;
406 
407  if (s->context) {
408  for (i = 0; i < 3; i++) {
409  ff_huff_gen_len_table(s->len[i], s->stats[i]);
410  if (ff_huffyuv_generate_bits_table(s->bits[i], s->len[i]) < 0)
411  return -1;
412  size += store_table(s, s->len[i], &pkt->data[size]);
413  }
414 
415  for (i = 0; i < 3; i++)
416  for (j = 0; j < 256; j++)
417  s->stats[i][j] >>= 1;
418  }
419 
420  init_put_bits(&s->pb, pkt->data + size, pkt->size - size);
421 
422  if (avctx->pix_fmt == AV_PIX_FMT_YUV422P ||
423  avctx->pix_fmt == AV_PIX_FMT_YUV420P) {
424  int lefty, leftu, leftv, y, cy;
425 
426  put_bits(&s->pb, 8, leftv = p->data[2][0]);
427  put_bits(&s->pb, 8, lefty = p->data[0][1]);
428  put_bits(&s->pb, 8, leftu = p->data[1][0]);
429  put_bits(&s->pb, 8, p->data[0][0]);
430 
431  lefty = sub_left_prediction(s, s->temp[0], p->data[0], width , 0);
432  leftu = sub_left_prediction(s, s->temp[1], p->data[1], width2, 0);
433  leftv = sub_left_prediction(s, s->temp[2], p->data[2], width2, 0);
434 
435  encode_422_bitstream(s, 2, width-2);
436 
437  if (s->predictor==MEDIAN) {
438  int lefttopy, lefttopu, lefttopv;
439  cy = y = 1;
440  if (s->interlaced) {
441  lefty = sub_left_prediction(s, s->temp[0], p->data[0] + p->linesize[0], width , lefty);
442  leftu = sub_left_prediction(s, s->temp[1], p->data[1] + p->linesize[1], width2, leftu);
443  leftv = sub_left_prediction(s, s->temp[2], p->data[2] + p->linesize[2], width2, leftv);
444 
445  encode_422_bitstream(s, 0, width);
446  y++; cy++;
447  }
448 
449  lefty = sub_left_prediction(s, s->temp[0], p->data[0] + fake_ystride, 4, lefty);
450  leftu = sub_left_prediction(s, s->temp[1], p->data[1] + fake_ustride, 2, leftu);
451  leftv = sub_left_prediction(s, s->temp[2], p->data[2] + fake_vstride, 2, leftv);
452 
453  encode_422_bitstream(s, 0, 4);
454 
455  lefttopy = p->data[0][3];
456  lefttopu = p->data[1][1];
457  lefttopv = p->data[2][1];
458  s->dsp.sub_hfyu_median_prediction(s->temp[0], p->data[0]+4, p->data[0] + fake_ystride + 4, width - 4 , &lefty, &lefttopy);
459  s->dsp.sub_hfyu_median_prediction(s->temp[1], p->data[1]+2, p->data[1] + fake_ustride + 2, width2 - 2, &leftu, &lefttopu);
460  s->dsp.sub_hfyu_median_prediction(s->temp[2], p->data[2]+2, p->data[2] + fake_vstride + 2, width2 - 2, &leftv, &lefttopv);
461  encode_422_bitstream(s, 0, width - 4);
462  y++; cy++;
463 
464  for (; y < height; y++,cy++) {
465  uint8_t *ydst, *udst, *vdst;
466 
467  if (s->bitstream_bpp == 12) {
468  while (2 * cy > y) {
469  ydst = p->data[0] + p->linesize[0] * y;
470  s->dsp.sub_hfyu_median_prediction(s->temp[0], ydst - fake_ystride, ydst, width , &lefty, &lefttopy);
471  encode_gray_bitstream(s, width);
472  y++;
473  }
474  if (y >= height) break;
475  }
476  ydst = p->data[0] + p->linesize[0] * y;
477  udst = p->data[1] + p->linesize[1] * cy;
478  vdst = p->data[2] + p->linesize[2] * cy;
479 
480  s->dsp.sub_hfyu_median_prediction(s->temp[0], ydst - fake_ystride, ydst, width , &lefty, &lefttopy);
481  s->dsp.sub_hfyu_median_prediction(s->temp[1], udst - fake_ustride, udst, width2, &leftu, &lefttopu);
482  s->dsp.sub_hfyu_median_prediction(s->temp[2], vdst - fake_vstride, vdst, width2, &leftv, &lefttopv);
483 
484  encode_422_bitstream(s, 0, width);
485  }
486  } else {
487  for (cy = y = 1; y < height; y++, cy++) {
488  uint8_t *ydst, *udst, *vdst;
489 
490  /* encode a luma only line & y++ */
491  if (s->bitstream_bpp == 12) {
492  ydst = p->data[0] + p->linesize[0] * y;
493 
494  if (s->predictor == PLANE && s->interlaced < y) {
495  s->dsp.diff_bytes(s->temp[1], ydst, ydst - fake_ystride, width);
496 
497  lefty = sub_left_prediction(s, s->temp[0], s->temp[1], width , lefty);
498  } else {
499  lefty = sub_left_prediction(s, s->temp[0], ydst, width , lefty);
500  }
501  encode_gray_bitstream(s, width);
502  y++;
503  if (y >= height) break;
504  }
505 
506  ydst = p->data[0] + p->linesize[0] * y;
507  udst = p->data[1] + p->linesize[1] * cy;
508  vdst = p->data[2] + p->linesize[2] * cy;
509 
510  if (s->predictor == PLANE && s->interlaced < cy) {
511  s->dsp.diff_bytes(s->temp[1], ydst, ydst - fake_ystride, width);
512  s->dsp.diff_bytes(s->temp[2], udst, udst - fake_ustride, width2);
513  s->dsp.diff_bytes(s->temp[2] + width2, vdst, vdst - fake_vstride, width2);
514 
515  lefty = sub_left_prediction(s, s->temp[0], s->temp[1], width , lefty);
516  leftu = sub_left_prediction(s, s->temp[1], s->temp[2], width2, leftu);
517  leftv = sub_left_prediction(s, s->temp[2], s->temp[2] + width2, width2, leftv);
518  } else {
519  lefty = sub_left_prediction(s, s->temp[0], ydst, width , lefty);
520  leftu = sub_left_prediction(s, s->temp[1], udst, width2, leftu);
521  leftv = sub_left_prediction(s, s->temp[2], vdst, width2, leftv);
522  }
523 
524  encode_422_bitstream(s, 0, width);
525  }
526  }
527  } else if(avctx->pix_fmt == AV_PIX_FMT_RGB32) {
528  uint8_t *data = p->data[0] + (height - 1) * p->linesize[0];
529  const int stride = -p->linesize[0];
530  const int fake_stride = -fake_ystride;
531  int y;
532  int leftr, leftg, leftb;
533 
534  put_bits(&s->pb, 8, leftr = data[R]);
535  put_bits(&s->pb, 8, leftg = data[G]);
536  put_bits(&s->pb, 8, leftb = data[B]);
537  put_bits(&s->pb, 8, 0);
538 
539  sub_left_prediction_bgr32(s, s->temp[0], data + 4, width - 1, &leftr, &leftg, &leftb);
540  encode_bgr_bitstream(s, width - 1);
541 
542  for (y = 1; y < s->height; y++) {
543  uint8_t *dst = data + y*stride;
544  if (s->predictor == PLANE && s->interlaced < y) {
545  s->dsp.diff_bytes(s->temp[1], dst, dst - fake_stride, width * 4);
546  sub_left_prediction_bgr32(s, s->temp[0], s->temp[1], width, &leftr, &leftg, &leftb);
547  } else {
548  sub_left_prediction_bgr32(s, s->temp[0], dst, width, &leftr, &leftg, &leftb);
549  }
550  encode_bgr_bitstream(s, width);
551  }
552  } else {
553  av_log(avctx, AV_LOG_ERROR, "Format not supported!\n");
554  }
555  emms_c();
556 
557  size += (put_bits_count(&s->pb) + 31) / 8;
558  put_bits(&s->pb, 16, 0);
559  put_bits(&s->pb, 15, 0);
560  size /= 4;
561 
562  if ((s->flags&CODEC_FLAG_PASS1) && (s->picture_number & 31) == 0) {
563  int j;
564  char *p = avctx->stats_out;
565  char *end = p + 1024*30;
566  for (i = 0; i < 3; i++) {
567  for (j = 0; j < 256; j++) {
568  snprintf(p, end-p, "%"PRIu64" ", s->stats[i][j]);
569  p += strlen(p);
570  s->stats[i][j]= 0;
571  }
572  snprintf(p, end-p, "\n");
573  p++;
574  }
575  } else
576  avctx->stats_out[0] = '\0';
577  if (!(s->avctx->flags2 & CODEC_FLAG2_NO_OUTPUT)) {
578  flush_put_bits(&s->pb);
579  s->dsp.bswap_buf((uint32_t*)pkt->data, (uint32_t*)pkt->data, size);
580  }
581 
582  s->picture_number++;
583 
584  pkt->size = size * 4;
585  pkt->flags |= AV_PKT_FLAG_KEY;
586  *got_packet = 1;
587 
588  return 0;
589 }
590 
592 {
593  HYuvContext *s = avctx->priv_data;
594 
596 
597  av_freep(&avctx->extradata);
598  av_freep(&avctx->stats_out);
599 
600  return 0;
601 }
602 
603 #if CONFIG_HUFFYUV_ENCODER
604 AVCodec ff_huffyuv_encoder = {
605  .name = "huffyuv",
606  .type = AVMEDIA_TYPE_VIDEO,
607  .id = AV_CODEC_ID_HUFFYUV,
608  .priv_data_size = sizeof(HYuvContext),
609  .init = encode_init,
610  .encode2 = encode_frame,
611  .close = encode_end,
612  .pix_fmts = (const enum AVPixelFormat[]){
614  },
615  .long_name = NULL_IF_CONFIG_SMALL("Huffyuv / HuffYUV"),
616 };
617 #endif
618 
619 #if CONFIG_FFVHUFF_ENCODER
620 AVCodec ff_ffvhuff_encoder = {
621  .name = "ffvhuff",
622  .type = AVMEDIA_TYPE_VIDEO,
623  .id = AV_CODEC_ID_FFVHUFF,
624  .priv_data_size = sizeof(HYuvContext),
625  .init = encode_init,
626  .encode2 = encode_frame,
627  .close = encode_end,
628  .pix_fmts = (const enum AVPixelFormat[]){
630  },
631  .long_name = NULL_IF_CONFIG_SMALL("Huffyuv FFmpeg variant"),
632 };
633 #endif
const struct AVCodec * codec
Definition: avcodec.h:1348
int size
This structure describes decoded (raw) audio or video data.
Definition: avcodec.h:989
static av_cold int encode_init(AVCodecContext *avctx)
Definition: huffyuvenc.c:109
struct HYuvContext HYuvContext
static int sub_left_prediction(HYuvContext *s, uint8_t *dst, uint8_t *src, int w, int left)
Definition: huffyuvenc.c:34
#define B
Definition: dsputil.c:1897
int bitstream_bpp
Definition: huffyuv.h:66
AVFrame * coded_frame
the picture in the bitstream
Definition: avcodec.h:2725
int size
Definition: avcodec.h:916
void ff_huff_gen_len_table(uint8_t *dst, const uint64_t *stats)
Definition: huffman.c:53
enum AVPixelFormat pix_fmt
Pixel format, see AV_PIX_FMT_xxx.
Definition: avcodec.h:1533
char * stats_in
pass2 encoding statistics input buffer Concatenated stuff from stats_out of pass1 should be placed he...
Definition: avcodec.h:2510
int context
Definition: huffyuv.h:72
void ff_huffyuv_common_end(HYuvContext *s)
Definition: huffyuv.c:90
int stride
Definition: mace.c:144
AVCodec.
Definition: avcodec.h:2960
int height
Definition: huffyuv.h:70
uint8_t len[3][256]
Definition: huffyuv.h:77
void av_freep(void *arg)
Free a memory block which has been allocated with av_malloc(z)() or av_realloc() and set the pointer ...
Definition: mem.c:151
int context_model
context model
Definition: avcodec.h:2395
static void sub_left_prediction_bgr32(HYuvContext *s, uint8_t *dst, uint8_t *src, int w, int *red, int *green, int *blue)
Definition: huffyuvenc.c:56
uint8_t
#define b
Definition: input.c:52
#define emms_c()
Definition: internal.h:145
uint8_t * extradata
some codecs need / can use extradata like Huffman tables.
Definition: avcodec.h:1454
const char data[16]
Definition: mxf.c:66
#define R
Definition: dsputil.c:1899
uint8_t * data
Definition: avcodec.h:915
int bits_per_coded_sample
bits per sample/pixel from the demuxer (needed for huffyuv).
Definition: avcodec.h:2704
#define LOAD2
char * stats_out
pass1 encoding statistics output buffer
Definition: avcodec.h:2502
static int init(AVCodecParserContext *s)
Definition: h264_parser.c:335
#define r
Definition: input.c:51
static int encode_frame(AVCodecContext *avctx, AVPacket *pkt, const AVFrame *pict, int *got_packet)
Definition: huffyuvenc.c:384
int av_new_packet(AVPacket *pkt, int size)
Allocate the payload of a packet and initialize its fields with default values.
Definition: avpacket.c:56
av_cold int ff_huffyuv_alloc_temp(HYuvContext *s)
Definition: huffyuv.c:58
enum AVCodecID id
Definition: avcodec.h:2974
uint64_t stats[3][256]
Definition: huffyuv.h:76
Definition: huffyuv.h:55
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]
Definition: dsputil.h:339
void(* bswap_buf)(uint32_t *dst, const uint32_t *src, int w)
Definition: dsputil.h:343
int flags
Definition: huffyuv.h:71
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification. ...
Definition: internal.h:88
g
Definition: yuv2rgb.c:540
int flags
CODEC_FLAG_*.
Definition: avcodec.h:1434
uint8_t * buf
Definition: put_bits.h:42
void av_log(void *avcl, int level, const char *fmt,...)
Definition: log.c:146
const char * name
Name of the codec implementation.
Definition: avcodec.h:2967
static void put_bits(PutBitContext *s, int n, unsigned int value)
Write up to 31 bits into a bitstream.
Definition: put_bits.h:136
huffyuv codec for libavcodec.
int flags
A combination of AV_PKT_FLAG values.
Definition: avcodec.h:921
static int put_bits_count(PutBitContext *s)
Definition: put_bits.h:70
planar YUV 4:2:2, 16bpp, (1 Cr & Cb sample per 2x1 Y samples)
Definition: pixfmt.h:69
uint32_t bits[3][256]
Definition: huffyuv.h:78
#define WRITE2
int decorrelate
Definition: huffyuv.h:65
enum AVPictureType pict_type
Picture type of the frame, see ?_TYPE below.
Definition: avcodec.h:1065
int width
Definition: huffyuv.h:70
uint8_t * temp[3]
Definition: huffyuv.h:75
static av_cold int encode_end(AVCodecContext *avctx)
Definition: huffyuvenc.c:591
static int width
Definition: utils.c:156
int picture_number
Definition: huffyuv.h:73
external API header
static int encode_422_bitstream(HYuvContext *s, int offset, int count)
Definition: huffyuvenc.c:241
int linesize[AV_NUM_DATA_POINTERS]
Size, in bytes, of the data for each picture/channel plane.
Definition: avcodec.h:1008
main external API structure.
Definition: avcodec.h:1339
#define LOAD3
static void close(AVCodecParserContext *s)
Definition: h264_parser.c:326
#define STAT2
uint8_t * buf_end
Definition: put_bits.h:42
#define STAT3
int interlaced
Definition: huffyuv.h:64
int extradata_size
Definition: avcodec.h:1455
int index
Definition: gxfenc.c:72
#define WRITE3
huffman tree builder and VLC generator
#define LOAD4
int version
Definition: huffyuv.h:67
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
Definition: avcodec.h:997
Predictor predictor
Definition: huffyuv.h:61
int height
Definition: gxfenc.c:72
#define v0
Definition: regdef.h:26
AVCodecContext * avctx
Definition: huffyuv.h:60
void(* diff_bytes)(uint8_t *dst, uint8_t *src1, uint8_t *src2, int w)
Definition: dsputil.h:334
PutBitContext pb
Definition: huffyuv.h:63
planar YUV 4:2:0, 12bpp, (1 Cr & Cb sample per 2x2 Y samples)
Definition: pixfmt.h:65
Definition: huffyuv.h:56
static void flush_put_bits(PutBitContext *s)
Pad the end of the output stream with zeros.
Definition: put_bits.h:86
static int store_table(HYuvContext *s, const uint8_t *len, uint8_t *buf)
Definition: huffyuvenc.c:85
int prediction_method
prediction method (needed for huffyuv)
Definition: avcodec.h:1705
static int encode_gray_bitstream(HYuvContext *s, int count)
Definition: huffyuvenc.c:296
static void init_put_bits(PutBitContext *s, uint8_t *buffer, int buffer_size)
Initialize the PutBitContext s.
Definition: put_bits.h:52
av_cold void ff_huffyuv_common_init(AVCodecContext *avctx)
Definition: huffyuv.c:76
void * priv_data
Definition: avcodec.h:1382
int len
int key_frame
1 -> keyframe, 0-> not
Definition: avcodec.h:1058
#define G
Definition: dsputil.c:1898
int flags2
CODEC_FLAG2_*.
Definition: avcodec.h:1441
AVFrame picture
Definition: huffyuv.h:81
static int encode_bgr_bitstream(HYuvContext *s, int count)
Definition: huffyuvenc.c:341
DSPContext dsp
Definition: huffyuv.h:84
AVPixelFormat
Pixel format.
Definition: pixfmt.h:63
This structure stores compressed data.
Definition: avcodec.h:898
void * av_mallocz(size_t size)
Allocate a block of size bytes with alignment suitable for all memory accesses (including vectors if ...
Definition: mem.c:158
for(j=16;j >0;--j)
int ff_huffyuv_generate_bits_table(uint32_t *dst, const uint8_t *len_table)
Definition: huffyuv.c:39
bitstream writer API