FFmpeg
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
huffyuvenc.c
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2002-2014 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 FFmpeg.
8  *
9  * FFmpeg 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  * FFmpeg 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 FFmpeg; if not, write to the Free Software
21  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
22  *
23  * yuva, gray, 4:4:4, 4:1:1, 4:1:0 and >8 bit per sample support sponsored by NOA
24  */
25 
26 /**
27  * @file
28  * huffyuv encoder
29  */
30 
31 #include "avcodec.h"
32 #include "huffyuv.h"
33 #include "huffman.h"
34 #include "huffyuvencdsp.h"
35 #include "internal.h"
36 #include "lossless_videoencdsp.h"
37 #include "put_bits.h"
38 #include "libavutil/opt.h"
39 #include "libavutil/pixdesc.h"
40 
41 static inline void diff_bytes(HYuvContext *s, uint8_t *dst,
42  const uint8_t *src0, const uint8_t *src1, int w)
43 {
44  if (s->bps <= 8) {
45  s->llvidencdsp.diff_bytes(dst, src0, src1, w);
46  } else {
47  s->hencdsp.diff_int16((uint16_t *)dst, (const uint16_t *)src0, (const uint16_t *)src1, s->n - 1, w);
48  }
49 }
50 
51 static inline int sub_left_prediction(HYuvContext *s, uint8_t *dst,
52  const uint8_t *src, int w, int left)
53 {
54  int i;
55  if (s->bps <= 8) {
56  if (w < 32) {
57  for (i = 0; i < w; i++) {
58  const int temp = src[i];
59  dst[i] = temp - left;
60  left = temp;
61  }
62  return left;
63  } else {
64  for (i = 0; i < 32; i++) {
65  const int temp = src[i];
66  dst[i] = temp - left;
67  left = temp;
68  }
69  s->llvidencdsp.diff_bytes(dst + 32, src + 32, src + 31, w - 32);
70  return src[w-1];
71  }
72  } else {
73  const uint16_t *src16 = (const uint16_t *)src;
74  uint16_t *dst16 = ( uint16_t *)dst;
75  if (w < 32) {
76  for (i = 0; i < w; i++) {
77  const int temp = src16[i];
78  dst16[i] = temp - left;
79  left = temp;
80  }
81  return left;
82  } else {
83  for (i = 0; i < 16; i++) {
84  const int temp = src16[i];
85  dst16[i] = temp - left;
86  left = temp;
87  }
88  s->hencdsp.diff_int16(dst16 + 16, src16 + 16, src16 + 15, s->n - 1, w - 16);
89  return src16[w-1];
90  }
91  }
92 }
93 
94 static inline void sub_left_prediction_bgr32(HYuvContext *s, uint8_t *dst,
95  const uint8_t *src, int w,
96  int *red, int *green, int *blue,
97  int *alpha)
98 {
99  int i;
100  int r, g, b, a;
101  r = *red;
102  g = *green;
103  b = *blue;
104  a = *alpha;
105 
106  for (i = 0; i < FFMIN(w, 4); i++) {
107  const int rt = src[i * 4 + R];
108  const int gt = src[i * 4 + G];
109  const int bt = src[i * 4 + B];
110  const int at = src[i * 4 + A];
111  dst[i * 4 + R] = rt - r;
112  dst[i * 4 + G] = gt - g;
113  dst[i * 4 + B] = bt - b;
114  dst[i * 4 + A] = at - a;
115  r = rt;
116  g = gt;
117  b = bt;
118  a = at;
119  }
120 
121  s->llvidencdsp.diff_bytes(dst + 16, src + 16, src + 12, w * 4 - 16);
122 
123  *red = src[(w - 1) * 4 + R];
124  *green = src[(w - 1) * 4 + G];
125  *blue = src[(w - 1) * 4 + B];
126  *alpha = src[(w - 1) * 4 + A];
127 }
128 
129 static inline void sub_left_prediction_rgb24(HYuvContext *s, uint8_t *dst,
130  uint8_t *src, int w,
131  int *red, int *green, int *blue)
132 {
133  int i;
134  int r, g, b;
135  r = *red;
136  g = *green;
137  b = *blue;
138  for (i = 0; i < FFMIN(w, 16); i++) {
139  const int rt = src[i * 3 + 0];
140  const int gt = src[i * 3 + 1];
141  const int bt = src[i * 3 + 2];
142  dst[i * 3 + 0] = rt - r;
143  dst[i * 3 + 1] = gt - g;
144  dst[i * 3 + 2] = bt - b;
145  r = rt;
146  g = gt;
147  b = bt;
148  }
149 
150  s->llvidencdsp.diff_bytes(dst + 48, src + 48, src + 48 - 3, w * 3 - 48);
151 
152  *red = src[(w - 1) * 3 + 0];
153  *green = src[(w - 1) * 3 + 1];
154  *blue = src[(w - 1) * 3 + 2];
155 }
156 
157 static void sub_median_prediction(HYuvContext *s, uint8_t *dst, const uint8_t *src1, const uint8_t *src2, int w, int *left, int *left_top)
158 {
159  if (s->bps <= 8) {
160  s->llvidencdsp.sub_median_pred(dst, src1, src2, w , left, left_top);
161  } else {
162  s->hencdsp.sub_hfyu_median_pred_int16((uint16_t *)dst, (const uint16_t *)src1, (const uint16_t *)src2, s->n - 1, w , left, left_top);
163  }
164 }
165 
167 {
168  int i;
169  int index = 0;
170  int n = s->vlc_n;
171 
172  for (i = 0; i < n;) {
173  int val = len[i];
174  int repeat = 0;
175 
176  for (; i < n && len[i] == val && repeat < 255; i++)
177  repeat++;
178 
179  av_assert0(val < 32 && val >0 && repeat < 256 && repeat>0);
180  if (repeat > 7) {
181  buf[index++] = val;
182  buf[index++] = repeat;
183  } else {
184  buf[index++] = val | (repeat << 5);
185  }
186  }
187 
188  return index;
189 }
190 
192 {
193  int i, ret;
194  int size = 0;
195  int count = 3;
196 
197  if (s->version > 2)
198  count = 1 + s->alpha + 2*s->chroma;
199 
200  for (i = 0; i < count; i++) {
201  if ((ret = ff_huff_gen_len_table(s->len[i], s->stats[i], s->vlc_n, 0)) < 0)
202  return ret;
203 
204  if (ff_huffyuv_generate_bits_table(s->bits[i], s->len[i], s->vlc_n) < 0) {
205  return -1;
206  }
207 
208  size += store_table(s, s->len[i], buf + size);
209  }
210  return size;
211 }
212 
214 {
215  HYuvContext *s = avctx->priv_data;
216  int i, j;
217  int ret;
219 
220  ff_huffyuv_common_init(avctx);
221  ff_huffyuvencdsp_init(&s->hencdsp, avctx);
223 
224  avctx->extradata = av_mallocz(3*MAX_N + 4);
225  if (s->flags&AV_CODEC_FLAG_PASS1) {
226 #define STATS_OUT_SIZE 21*MAX_N*3 + 4
227  avctx->stats_out = av_mallocz(STATS_OUT_SIZE); // 21*256*3(%llu ) + 3(\n) + 1(0) = 16132
228  if (!avctx->stats_out)
229  return AVERROR(ENOMEM);
230  }
231  s->version = 2;
232 
233  if (!avctx->extradata)
234  return AVERROR(ENOMEM);
235 
236 #if FF_API_CODED_FRAME
239  avctx->coded_frame->key_frame = 1;
241 #endif
242 #if FF_API_PRIVATE_OPT
244  if (avctx->context_model == 1)
245  s->context = avctx->context_model;
247 #endif
248 
249  s->bps = desc->comp[0].depth;
250  s->yuv = !(desc->flags & AV_PIX_FMT_FLAG_RGB) && desc->nb_components >= 2;
251  s->chroma = desc->nb_components > 2;
252  s->alpha = !!(desc->flags & AV_PIX_FMT_FLAG_ALPHA);
254  &s->chroma_h_shift,
255  &s->chroma_v_shift);
256 
257  switch (avctx->pix_fmt) {
258  case AV_PIX_FMT_YUV420P:
259  case AV_PIX_FMT_YUV422P:
260  if (s->width & 1) {
261  av_log(avctx, AV_LOG_ERROR, "Width must be even for this colorspace.\n");
262  return AVERROR(EINVAL);
263  }
264  s->bitstream_bpp = avctx->pix_fmt == AV_PIX_FMT_YUV420P ? 12 : 16;
265  break;
266  case AV_PIX_FMT_YUV444P:
267  case AV_PIX_FMT_YUV410P:
268  case AV_PIX_FMT_YUV411P:
269  case AV_PIX_FMT_YUV440P:
270  case AV_PIX_FMT_GBRP:
271  case AV_PIX_FMT_GBRP9:
272  case AV_PIX_FMT_GBRP10:
273  case AV_PIX_FMT_GBRP12:
274  case AV_PIX_FMT_GBRP14:
275  case AV_PIX_FMT_GBRP16:
276  case AV_PIX_FMT_GRAY8:
277  case AV_PIX_FMT_GRAY16:
278  case AV_PIX_FMT_YUVA444P:
279  case AV_PIX_FMT_YUVA420P:
280  case AV_PIX_FMT_YUVA422P:
281  case AV_PIX_FMT_GBRAP:
282  case AV_PIX_FMT_GRAY8A:
283  case AV_PIX_FMT_YUV420P9:
288  case AV_PIX_FMT_YUV422P9:
293  case AV_PIX_FMT_YUV444P9:
307  s->version = 3;
308  break;
309  case AV_PIX_FMT_RGB32:
310  s->bitstream_bpp = 32;
311  break;
312  case AV_PIX_FMT_RGB24:
313  s->bitstream_bpp = 24;
314  break;
315  default:
316  av_log(avctx, AV_LOG_ERROR, "format not supported\n");
317  return AVERROR(EINVAL);
318  }
319  s->n = 1<<s->bps;
320  s->vlc_n = FFMIN(s->n, MAX_VLC_N);
321 
323  s->decorrelate = s->bitstream_bpp >= 24 && !s->yuv && !(desc->flags & AV_PIX_FMT_FLAG_PLANAR);
324 #if FF_API_PRIVATE_OPT
326  if (avctx->prediction_method)
327  s->predictor = avctx->prediction_method;
329 #endif
330  s->interlaced = avctx->flags & AV_CODEC_FLAG_INTERLACED_ME ? 1 : 0;
331  if (s->context) {
333  av_log(avctx, AV_LOG_ERROR,
334  "context=1 is not compatible with "
335  "2 pass huffyuv encoding\n");
336  return AVERROR(EINVAL);
337  }
338  }
339 
340  if (avctx->codec->id == AV_CODEC_ID_HUFFYUV) {
341  if (avctx->pix_fmt == AV_PIX_FMT_YUV420P) {
342  av_log(avctx, AV_LOG_ERROR,
343  "Error: YV12 is not supported by huffyuv; use "
344  "vcodec=ffvhuff or format=422p\n");
345  return AVERROR(EINVAL);
346  }
347 #if FF_API_PRIVATE_OPT
348  if (s->context) {
349  av_log(avctx, AV_LOG_ERROR,
350  "Error: per-frame huffman tables are not supported "
351  "by huffyuv; use vcodec=ffvhuff\n");
352  return AVERROR(EINVAL);
353  }
354  if (s->version > 2) {
355  av_log(avctx, AV_LOG_ERROR,
356  "Error: ver>2 is not supported "
357  "by huffyuv; use vcodec=ffvhuff\n");
358  return AVERROR(EINVAL);
359  }
360 #endif
361  if (s->interlaced != ( s->height > 288 ))
362  av_log(avctx, AV_LOG_INFO,
363  "using huffyuv 2.2.0 or newer interlacing flag\n");
364  }
365 
367  av_log(avctx, AV_LOG_ERROR, "Ver > 3 is under development, files encoded with it may not be decodable with future versions!!!\n"
368  "Use vstrict=-2 / -strict -2 to use it anyway.\n");
369  return AVERROR(EINVAL);
370  }
371 
372  if (s->bitstream_bpp >= 24 && s->predictor == MEDIAN && s->version <= 2) {
373  av_log(avctx, AV_LOG_ERROR,
374  "Error: RGB is incompatible with median predictor\n");
375  return AVERROR(EINVAL);
376  }
377 
378  ((uint8_t*)avctx->extradata)[0] = s->predictor | (s->decorrelate << 6);
379  ((uint8_t*)avctx->extradata)[2] = s->interlaced ? 0x10 : 0x20;
380  if (s->context)
381  ((uint8_t*)avctx->extradata)[2] |= 0x40;
382  if (s->version < 3) {
383  ((uint8_t*)avctx->extradata)[1] = s->bitstream_bpp;
384  ((uint8_t*)avctx->extradata)[3] = 0;
385  } else {
386  ((uint8_t*)avctx->extradata)[1] = ((s->bps-1)<<4) | s->chroma_h_shift | (s->chroma_v_shift<<2);
387  if (s->chroma)
388  ((uint8_t*)avctx->extradata)[2] |= s->yuv ? 1 : 2;
389  if (s->alpha)
390  ((uint8_t*)avctx->extradata)[2] |= 4;
391  ((uint8_t*)avctx->extradata)[3] = 1;
392  }
393  s->avctx->extradata_size = 4;
394 
395  if (avctx->stats_in) {
396  char *p = avctx->stats_in;
397 
398  for (i = 0; i < 4; i++)
399  for (j = 0; j < s->vlc_n; j++)
400  s->stats[i][j] = 1;
401 
402  for (;;) {
403  for (i = 0; i < 4; i++) {
404  char *next;
405 
406  for (j = 0; j < s->vlc_n; j++) {
407  s->stats[i][j] += strtol(p, &next, 0);
408  if (next == p) return -1;
409  p = next;
410  }
411  }
412  if (p[0] == 0 || p[1] == 0 || p[2] == 0) break;
413  }
414  } else {
415  for (i = 0; i < 4; i++)
416  for (j = 0; j < s->vlc_n; j++) {
417  int d = FFMIN(j, s->vlc_n - j);
418 
419  s->stats[i][j] = 100000000 / (d*d + 1);
420  }
421  }
422 
424  if (ret < 0)
425  return ret;
426  s->avctx->extradata_size += ret;
427 
428  if (s->context) {
429  for (i = 0; i < 4; i++) {
430  int pels = s->width * s->height / (i ? 40 : 10);
431  for (j = 0; j < s->vlc_n; j++) {
432  int d = FFMIN(j, s->vlc_n - j);
433  s->stats[i][j] = pels/(d*d + 1);
434  }
435  }
436  } else {
437  for (i = 0; i < 4; i++)
438  for (j = 0; j < s->vlc_n; j++)
439  s->stats[i][j]= 0;
440  }
441 
442  if (ff_huffyuv_alloc_temp(s)) {
444  return AVERROR(ENOMEM);
445  }
446 
447  s->picture_number=0;
448 
449  return 0;
450 }
452 {
453  int i;
454  const uint8_t *y = s->temp[0] + offset;
455  const uint8_t *u = s->temp[1] + offset / 2;
456  const uint8_t *v = s->temp[2] + offset / 2;
457 
458  if (s->pb.buf_end - s->pb.buf - (put_bits_count(&s->pb) >> 3) < 2 * 4 * count) {
459  av_log(s->avctx, AV_LOG_ERROR, "encoded frame too large\n");
460  return -1;
461  }
462 
463 #define LOAD4\
464  int y0 = y[2 * i];\
465  int y1 = y[2 * i + 1];\
466  int u0 = u[i];\
467  int v0 = v[i];
468 
469  count /= 2;
470 
471  if (s->flags & AV_CODEC_FLAG_PASS1) {
472  for(i = 0; i < count; i++) {
473  LOAD4;
474  s->stats[0][y0]++;
475  s->stats[1][u0]++;
476  s->stats[0][y1]++;
477  s->stats[2][v0]++;
478  }
479  }
481  return 0;
482  if (s->context) {
483  for (i = 0; i < count; i++) {
484  LOAD4;
485  s->stats[0][y0]++;
486  put_bits(&s->pb, s->len[0][y0], s->bits[0][y0]);
487  s->stats[1][u0]++;
488  put_bits(&s->pb, s->len[1][u0], s->bits[1][u0]);
489  s->stats[0][y1]++;
490  put_bits(&s->pb, s->len[0][y1], s->bits[0][y1]);
491  s->stats[2][v0]++;
492  put_bits(&s->pb, s->len[2][v0], s->bits[2][v0]);
493  }
494  } else {
495  for(i = 0; i < count; i++) {
496  LOAD4;
497  put_bits(&s->pb, s->len[0][y0], s->bits[0][y0]);
498  put_bits(&s->pb, s->len[1][u0], s->bits[1][u0]);
499  put_bits(&s->pb, s->len[0][y1], s->bits[0][y1]);
500  put_bits(&s->pb, s->len[2][v0], s->bits[2][v0]);
501  }
502  }
503  return 0;
504 }
505 
507 {
508  int i, count = width/2;
509 
510  if (s->pb.buf_end - s->pb.buf - (put_bits_count(&s->pb) >> 3) < count * s->bps / 2) {
511  av_log(s->avctx, AV_LOG_ERROR, "encoded frame too large\n");
512  return -1;
513  }
514 
515 #define LOADEND\
516  int y0 = s->temp[0][width-1];
517 #define LOADEND_14\
518  int y0 = s->temp16[0][width-1] & mask;
519 #define LOADEND_16\
520  int y0 = s->temp16[0][width-1];
521 #define STATEND\
522  s->stats[plane][y0]++;
523 #define STATEND_16\
524  s->stats[plane][y0>>2]++;
525 #define WRITEEND\
526  put_bits(&s->pb, s->len[plane][y0], s->bits[plane][y0]);
527 #define WRITEEND_16\
528  put_bits(&s->pb, s->len[plane][y0>>2], s->bits[plane][y0>>2]);\
529  put_bits(&s->pb, 2, y0&3);
530 
531 #define LOAD2\
532  int y0 = s->temp[0][2 * i];\
533  int y1 = s->temp[0][2 * i + 1];
534 #define LOAD2_14\
535  int y0 = s->temp16[0][2 * i] & mask;\
536  int y1 = s->temp16[0][2 * i + 1] & mask;
537 #define LOAD2_16\
538  int y0 = s->temp16[0][2 * i];\
539  int y1 = s->temp16[0][2 * i + 1];
540 #define STAT2\
541  s->stats[plane][y0]++;\
542  s->stats[plane][y1]++;
543 #define STAT2_16\
544  s->stats[plane][y0>>2]++;\
545  s->stats[plane][y1>>2]++;
546 #define WRITE2\
547  put_bits(&s->pb, s->len[plane][y0], s->bits[plane][y0]);\
548  put_bits(&s->pb, s->len[plane][y1], s->bits[plane][y1]);
549 #define WRITE2_16\
550  put_bits(&s->pb, s->len[plane][y0>>2], s->bits[plane][y0>>2]);\
551  put_bits(&s->pb, 2, y0&3);\
552  put_bits(&s->pb, s->len[plane][y1>>2], s->bits[plane][y1>>2]);\
553  put_bits(&s->pb, 2, y1&3);
554 
555  if (s->bps <= 8) {
556  if (s->flags & AV_CODEC_FLAG_PASS1) {
557  for (i = 0; i < count; i++) {
558  LOAD2;
559  STAT2;
560  }
561  if (width&1) {
562  LOADEND;
563  STATEND;
564  }
565  }
567  return 0;
568 
569  if (s->context) {
570  for (i = 0; i < count; i++) {
571  LOAD2;
572  STAT2;
573  WRITE2;
574  }
575  if (width&1) {
576  LOADEND;
577  STATEND;
578  WRITEEND;
579  }
580  } else {
581  for (i = 0; i < count; i++) {
582  LOAD2;
583  WRITE2;
584  }
585  if (width&1) {
586  LOADEND;
587  WRITEEND;
588  }
589  }
590  } else if (s->bps <= 14) {
591  int mask = s->n - 1;
592  if (s->flags & AV_CODEC_FLAG_PASS1) {
593  for (i = 0; i < count; i++) {
594  LOAD2_14;
595  STAT2;
596  }
597  if (width&1) {
598  LOADEND_14;
599  STATEND;
600  }
601  }
603  return 0;
604 
605  if (s->context) {
606  for (i = 0; i < count; i++) {
607  LOAD2_14;
608  STAT2;
609  WRITE2;
610  }
611  if (width&1) {
612  LOADEND_14;
613  STATEND;
614  WRITEEND;
615  }
616  } else {
617  for (i = 0; i < count; i++) {
618  LOAD2_14;
619  WRITE2;
620  }
621  if (width&1) {
622  LOADEND_14;
623  WRITEEND;
624  }
625  }
626  } else {
627  if (s->flags & AV_CODEC_FLAG_PASS1) {
628  for (i = 0; i < count; i++) {
629  LOAD2_16;
630  STAT2_16;
631  }
632  if (width&1) {
633  LOADEND_16;
634  STATEND_16;
635  }
636  }
638  return 0;
639 
640  if (s->context) {
641  for (i = 0; i < count; i++) {
642  LOAD2_16;
643  STAT2_16;
644  WRITE2_16;
645  }
646  if (width&1) {
647  LOADEND_16;
648  STATEND_16;
649  WRITEEND_16;
650  }
651  } else {
652  for (i = 0; i < count; i++) {
653  LOAD2_16;
654  WRITE2_16;
655  }
656  if (width&1) {
657  LOADEND_16;
658  WRITEEND_16;
659  }
660  }
661  }
662 #undef LOAD2
663 #undef STAT2
664 #undef WRITE2
665  return 0;
666 }
667 
669 {
670  int i;
671 
672  if (s->pb.buf_end - s->pb.buf - (put_bits_count(&s->pb) >> 3) < 4 * count) {
673  av_log(s->avctx, AV_LOG_ERROR, "encoded frame too large\n");
674  return -1;
675  }
676 
677 #define LOAD2\
678  int y0 = s->temp[0][2 * i];\
679  int y1 = s->temp[0][2 * i + 1];
680 #define STAT2\
681  s->stats[0][y0]++;\
682  s->stats[0][y1]++;
683 #define WRITE2\
684  put_bits(&s->pb, s->len[0][y0], s->bits[0][y0]);\
685  put_bits(&s->pb, s->len[0][y1], s->bits[0][y1]);
686 
687  count /= 2;
688 
689  if (s->flags & AV_CODEC_FLAG_PASS1) {
690  for (i = 0; i < count; i++) {
691  LOAD2;
692  STAT2;
693  }
694  }
696  return 0;
697 
698  if (s->context) {
699  for (i = 0; i < count; i++) {
700  LOAD2;
701  STAT2;
702  WRITE2;
703  }
704  } else {
705  for (i = 0; i < count; i++) {
706  LOAD2;
707  WRITE2;
708  }
709  }
710  return 0;
711 }
712 
713 static inline int encode_bgra_bitstream(HYuvContext *s, int count, int planes)
714 {
715  int i;
716 
717  if (s->pb.buf_end - s->pb.buf - (put_bits_count(&s->pb) >> 3) <
718  4 * planes * count) {
719  av_log(s->avctx, AV_LOG_ERROR, "encoded frame too large\n");
720  return -1;
721  }
722 
723 #define LOAD_GBRA \
724  int g = s->temp[0][planes == 3 ? 3 * i + 1 : 4 * i + G]; \
725  int b =(s->temp[0][planes == 3 ? 3 * i + 2 : 4 * i + B] - g) & 0xFF;\
726  int r =(s->temp[0][planes == 3 ? 3 * i + 0 : 4 * i + R] - g) & 0xFF;\
727  int a = s->temp[0][planes * i + A];
728 
729 #define STAT_BGRA \
730  s->stats[0][b]++; \
731  s->stats[1][g]++; \
732  s->stats[2][r]++; \
733  if (planes == 4) \
734  s->stats[2][a]++;
735 
736 #define WRITE_GBRA \
737  put_bits(&s->pb, s->len[1][g], s->bits[1][g]); \
738  put_bits(&s->pb, s->len[0][b], s->bits[0][b]); \
739  put_bits(&s->pb, s->len[2][r], s->bits[2][r]); \
740  if (planes == 4) \
741  put_bits(&s->pb, s->len[2][a], s->bits[2][a]);
742 
743  if ((s->flags & AV_CODEC_FLAG_PASS1) &&
745  for (i = 0; i < count; i++) {
746  LOAD_GBRA;
747  STAT_BGRA;
748  }
749  } else if (s->context || (s->flags & AV_CODEC_FLAG_PASS1)) {
750  for (i = 0; i < count; i++) {
751  LOAD_GBRA;
752  STAT_BGRA;
753  WRITE_GBRA;
754  }
755  } else {
756  for (i = 0; i < count; i++) {
757  LOAD_GBRA;
758  WRITE_GBRA;
759  }
760  }
761  return 0;
762 }
763 
765  const AVFrame *pict, int *got_packet)
766 {
767  HYuvContext *s = avctx->priv_data;
768  const int width = s->width;
769  const int width2 = s->width>>1;
770  const int height = s->height;
771  const int fake_ystride = s->interlaced ? pict->linesize[0]*2 : pict->linesize[0];
772  const int fake_ustride = s->interlaced ? pict->linesize[1]*2 : pict->linesize[1];
773  const int fake_vstride = s->interlaced ? pict->linesize[2]*2 : pict->linesize[2];
774  const AVFrame * const p = pict;
775  int i, j, size = 0, ret;
776 
777  if ((ret = ff_alloc_packet2(avctx, pkt, width * height * 3 * 4 + AV_INPUT_BUFFER_MIN_SIZE, 0)) < 0)
778  return ret;
779 
780  if (s->context) {
781  size = store_huffman_tables(s, pkt->data);
782  if (size < 0)
783  return size;
784 
785  for (i = 0; i < 4; i++)
786  for (j = 0; j < s->vlc_n; j++)
787  s->stats[i][j] >>= 1;
788  }
789 
790  init_put_bits(&s->pb, pkt->data + size, pkt->size - size);
791 
792  if (avctx->pix_fmt == AV_PIX_FMT_YUV422P ||
793  avctx->pix_fmt == AV_PIX_FMT_YUV420P) {
794  int lefty, leftu, leftv, y, cy;
795 
796  put_bits(&s->pb, 8, leftv = p->data[2][0]);
797  put_bits(&s->pb, 8, lefty = p->data[0][1]);
798  put_bits(&s->pb, 8, leftu = p->data[1][0]);
799  put_bits(&s->pb, 8, p->data[0][0]);
800 
801  lefty = sub_left_prediction(s, s->temp[0], p->data[0], width , 0);
802  leftu = sub_left_prediction(s, s->temp[1], p->data[1], width2, 0);
803  leftv = sub_left_prediction(s, s->temp[2], p->data[2], width2, 0);
804 
805  encode_422_bitstream(s, 2, width-2);
806 
807  if (s->predictor==MEDIAN) {
808  int lefttopy, lefttopu, lefttopv;
809  cy = y = 1;
810  if (s->interlaced) {
811  lefty = sub_left_prediction(s, s->temp[0], p->data[0] + p->linesize[0], width , lefty);
812  leftu = sub_left_prediction(s, s->temp[1], p->data[1] + p->linesize[1], width2, leftu);
813  leftv = sub_left_prediction(s, s->temp[2], p->data[2] + p->linesize[2], width2, leftv);
814 
815  encode_422_bitstream(s, 0, width);
816  y++; cy++;
817  }
818 
819  lefty = sub_left_prediction(s, s->temp[0], p->data[0] + fake_ystride, 4, lefty);
820  leftu = sub_left_prediction(s, s->temp[1], p->data[1] + fake_ustride, 2, leftu);
821  leftv = sub_left_prediction(s, s->temp[2], p->data[2] + fake_vstride, 2, leftv);
822 
823  encode_422_bitstream(s, 0, 4);
824 
825  lefttopy = p->data[0][3];
826  lefttopu = p->data[1][1];
827  lefttopv = p->data[2][1];
828  s->llvidencdsp.sub_median_pred(s->temp[0], p->data[0] + 4, p->data[0] + fake_ystride + 4, width - 4, &lefty, &lefttopy);
829  s->llvidencdsp.sub_median_pred(s->temp[1], p->data[1] + 2, p->data[1] + fake_ustride + 2, width2 - 2, &leftu, &lefttopu);
830  s->llvidencdsp.sub_median_pred(s->temp[2], p->data[2] + 2, p->data[2] + fake_vstride + 2, width2 - 2, &leftv, &lefttopv);
831  encode_422_bitstream(s, 0, width - 4);
832  y++; cy++;
833 
834  for (; y < height; y++,cy++) {
835  uint8_t *ydst, *udst, *vdst;
836 
837  if (s->bitstream_bpp == 12) {
838  while (2 * cy > y) {
839  ydst = p->data[0] + p->linesize[0] * y;
840  s->llvidencdsp.sub_median_pred(s->temp[0], ydst - fake_ystride, ydst, width, &lefty, &lefttopy);
841  encode_gray_bitstream(s, width);
842  y++;
843  }
844  if (y >= height) break;
845  }
846  ydst = p->data[0] + p->linesize[0] * y;
847  udst = p->data[1] + p->linesize[1] * cy;
848  vdst = p->data[2] + p->linesize[2] * cy;
849 
850  s->llvidencdsp.sub_median_pred(s->temp[0], ydst - fake_ystride, ydst, width, &lefty, &lefttopy);
851  s->llvidencdsp.sub_median_pred(s->temp[1], udst - fake_ustride, udst, width2, &leftu, &lefttopu);
852  s->llvidencdsp.sub_median_pred(s->temp[2], vdst - fake_vstride, vdst, width2, &leftv, &lefttopv);
853 
854  encode_422_bitstream(s, 0, width);
855  }
856  } else {
857  for (cy = y = 1; y < height; y++, cy++) {
858  uint8_t *ydst, *udst, *vdst;
859 
860  /* encode a luma only line & y++ */
861  if (s->bitstream_bpp == 12) {
862  ydst = p->data[0] + p->linesize[0] * y;
863 
864  if (s->predictor == PLANE && s->interlaced < y) {
865  s->llvidencdsp.diff_bytes(s->temp[1], ydst, ydst - fake_ystride, width);
866 
867  lefty = sub_left_prediction(s, s->temp[0], s->temp[1], width , lefty);
868  } else {
869  lefty = sub_left_prediction(s, s->temp[0], ydst, width , lefty);
870  }
871  encode_gray_bitstream(s, width);
872  y++;
873  if (y >= height) break;
874  }
875 
876  ydst = p->data[0] + p->linesize[0] * y;
877  udst = p->data[1] + p->linesize[1] * cy;
878  vdst = p->data[2] + p->linesize[2] * cy;
879 
880  if (s->predictor == PLANE && s->interlaced < cy) {
881  s->llvidencdsp.diff_bytes(s->temp[1], ydst, ydst - fake_ystride, width);
882  s->llvidencdsp.diff_bytes(s->temp[2], udst, udst - fake_ustride, width2);
883  s->llvidencdsp.diff_bytes(s->temp[2] + width2, vdst, vdst - fake_vstride, width2);
884 
885  lefty = sub_left_prediction(s, s->temp[0], s->temp[1], width , lefty);
886  leftu = sub_left_prediction(s, s->temp[1], s->temp[2], width2, leftu);
887  leftv = sub_left_prediction(s, s->temp[2], s->temp[2] + width2, width2, leftv);
888  } else {
889  lefty = sub_left_prediction(s, s->temp[0], ydst, width , lefty);
890  leftu = sub_left_prediction(s, s->temp[1], udst, width2, leftu);
891  leftv = sub_left_prediction(s, s->temp[2], vdst, width2, leftv);
892  }
893 
894  encode_422_bitstream(s, 0, width);
895  }
896  }
897  } else if(avctx->pix_fmt == AV_PIX_FMT_RGB32) {
898  uint8_t *data = p->data[0] + (height - 1) * p->linesize[0];
899  const int stride = -p->linesize[0];
900  const int fake_stride = -fake_ystride;
901  int y;
902  int leftr, leftg, leftb, lefta;
903 
904  put_bits(&s->pb, 8, lefta = data[A]);
905  put_bits(&s->pb, 8, leftr = data[R]);
906  put_bits(&s->pb, 8, leftg = data[G]);
907  put_bits(&s->pb, 8, leftb = data[B]);
908 
909  sub_left_prediction_bgr32(s, s->temp[0], data + 4, width - 1,
910  &leftr, &leftg, &leftb, &lefta);
911  encode_bgra_bitstream(s, width - 1, 4);
912 
913  for (y = 1; y < s->height; y++) {
914  uint8_t *dst = data + y*stride;
915  if (s->predictor == PLANE && s->interlaced < y) {
916  s->llvidencdsp.diff_bytes(s->temp[1], dst, dst - fake_stride, width * 4);
917  sub_left_prediction_bgr32(s, s->temp[0], s->temp[1], width,
918  &leftr, &leftg, &leftb, &lefta);
919  } else {
920  sub_left_prediction_bgr32(s, s->temp[0], dst, width,
921  &leftr, &leftg, &leftb, &lefta);
922  }
923  encode_bgra_bitstream(s, width, 4);
924  }
925  } else if (avctx->pix_fmt == AV_PIX_FMT_RGB24) {
926  uint8_t *data = p->data[0] + (height - 1) * p->linesize[0];
927  const int stride = -p->linesize[0];
928  const int fake_stride = -fake_ystride;
929  int y;
930  int leftr, leftg, leftb;
931 
932  put_bits(&s->pb, 8, leftr = data[0]);
933  put_bits(&s->pb, 8, leftg = data[1]);
934  put_bits(&s->pb, 8, leftb = data[2]);
935  put_bits(&s->pb, 8, 0);
936 
937  sub_left_prediction_rgb24(s, s->temp[0], data + 3, width - 1,
938  &leftr, &leftg, &leftb);
939  encode_bgra_bitstream(s, width-1, 3);
940 
941  for (y = 1; y < s->height; y++) {
942  uint8_t *dst = data + y * stride;
943  if (s->predictor == PLANE && s->interlaced < y) {
944  s->llvidencdsp.diff_bytes(s->temp[1], dst, dst - fake_stride,
945  width * 3);
946  sub_left_prediction_rgb24(s, s->temp[0], s->temp[1], width,
947  &leftr, &leftg, &leftb);
948  } else {
949  sub_left_prediction_rgb24(s, s->temp[0], dst, width,
950  &leftr, &leftg, &leftb);
951  }
952  encode_bgra_bitstream(s, width, 3);
953  }
954  } else if (s->version > 2) {
955  int plane;
956  for (plane = 0; plane < 1 + 2*s->chroma + s->alpha; plane++) {
957  int left, y;
958  int w = width;
959  int h = height;
960  int fake_stride = fake_ystride;
961 
962  if (s->chroma && (plane == 1 || plane == 2)) {
963  w >>= s->chroma_h_shift;
964  h >>= s->chroma_v_shift;
965  fake_stride = plane == 1 ? fake_ustride : fake_vstride;
966  }
967 
968  left = sub_left_prediction(s, s->temp[0], p->data[plane], w , 0);
969 
970  encode_plane_bitstream(s, w, plane);
971 
972  if (s->predictor==MEDIAN) {
973  int lefttop;
974  y = 1;
975  if (s->interlaced) {
976  left = sub_left_prediction(s, s->temp[0], p->data[plane] + p->linesize[plane], w , left);
977 
978  encode_plane_bitstream(s, w, plane);
979  y++;
980  }
981 
982  lefttop = p->data[plane][0];
983 
984  for (; y < h; y++) {
985  uint8_t *dst = p->data[plane] + p->linesize[plane] * y;
986 
987  sub_median_prediction(s, s->temp[0], dst - fake_stride, dst, w , &left, &lefttop);
988 
989  encode_plane_bitstream(s, w, plane);
990  }
991  } else {
992  for (y = 1; y < h; y++) {
993  uint8_t *dst = p->data[plane] + p->linesize[plane] * y;
994 
995  if (s->predictor == PLANE && s->interlaced < y) {
996  diff_bytes(s, s->temp[1], dst, dst - fake_stride, w);
997 
998  left = sub_left_prediction(s, s->temp[0], s->temp[1], w , left);
999  } else {
1000  left = sub_left_prediction(s, s->temp[0], dst, w , left);
1001  }
1002 
1003  encode_plane_bitstream(s, w, plane);
1004  }
1005  }
1006  }
1007  } else {
1008  av_log(avctx, AV_LOG_ERROR, "Format not supported!\n");
1009  }
1010  emms_c();
1011 
1012  size += (put_bits_count(&s->pb) + 31) / 8;
1013  put_bits(&s->pb, 16, 0);
1014  put_bits(&s->pb, 15, 0);
1015  size /= 4;
1016 
1017  if ((s->flags & AV_CODEC_FLAG_PASS1) && (s->picture_number & 31) == 0) {
1018  int j;
1019  char *p = avctx->stats_out;
1020  char *end = p + STATS_OUT_SIZE;
1021  for (i = 0; i < 4; i++) {
1022  for (j = 0; j < s->vlc_n; j++) {
1023  snprintf(p, end-p, "%"PRIu64" ", s->stats[i][j]);
1024  p += strlen(p);
1025  s->stats[i][j]= 0;
1026  }
1027  snprintf(p, end-p, "\n");
1028  p++;
1029  if (end <= p)
1030  return AVERROR(ENOMEM);
1031  }
1032  } else if (avctx->stats_out)
1033  avctx->stats_out[0] = '\0';
1034  if (!(s->avctx->flags2 & AV_CODEC_FLAG2_NO_OUTPUT)) {
1035  flush_put_bits(&s->pb);
1036  s->bdsp.bswap_buf((uint32_t *) pkt->data, (uint32_t *) pkt->data, size);
1037  }
1038 
1039  s->picture_number++;
1040 
1041  pkt->size = size * 4;
1042  pkt->flags |= AV_PKT_FLAG_KEY;
1043  *got_packet = 1;
1044 
1045  return 0;
1046 }
1047 
1049 {
1050  HYuvContext *s = avctx->priv_data;
1051 
1053 
1054  av_freep(&avctx->extradata);
1055  av_freep(&avctx->stats_out);
1056 
1057  return 0;
1058 }
1059 
1060 #define OFFSET(x) offsetof(HYuvContext, x)
1061 #define VE AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_ENCODING_PARAM
1062 
1063 #define COMMON_OPTIONS \
1064  { "non_deterministic", "Allow multithreading for e.g. context=1 at the expense of determinism", \
1065  OFFSET(non_determ), AV_OPT_TYPE_BOOL, { .i64 = 1 }, \
1066  0, 1, VE }, \
1067  { "pred", "Prediction method", OFFSET(predictor), AV_OPT_TYPE_INT, { .i64 = LEFT }, LEFT, MEDIAN, VE, "pred" }, \
1068  { "left", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = LEFT }, INT_MIN, INT_MAX, VE, "pred" }, \
1069  { "plane", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = PLANE }, INT_MIN, INT_MAX, VE, "pred" }, \
1070  { "median", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = MEDIAN }, INT_MIN, INT_MAX, VE, "pred" }, \
1071 
1072 static const AVOption normal_options[] = {
1074  { NULL },
1075 };
1076 
1077 static const AVOption ff_options[] = {
1079  { "context", "Set per-frame huffman tables", OFFSET(context), AV_OPT_TYPE_INT, { .i64 = 0 }, 0, 1, VE },
1080  { NULL },
1081 };
1082 
1083 static const AVClass normal_class = {
1084  .class_name = "huffyuv",
1085  .item_name = av_default_item_name,
1086  .option = normal_options,
1087  .version = LIBAVUTIL_VERSION_INT,
1088 };
1089 
1090 static const AVClass ff_class = {
1091  .class_name = "ffvhuff",
1092  .item_name = av_default_item_name,
1093  .option = ff_options,
1094  .version = LIBAVUTIL_VERSION_INT,
1095 };
1096 
1098  .name = "huffyuv",
1099  .long_name = NULL_IF_CONFIG_SMALL("Huffyuv / HuffYUV"),
1100  .type = AVMEDIA_TYPE_VIDEO,
1101  .id = AV_CODEC_ID_HUFFYUV,
1102  .priv_data_size = sizeof(HYuvContext),
1103  .init = encode_init,
1104  .encode2 = encode_frame,
1105  .close = encode_end,
1107  .priv_class = &normal_class,
1108  .pix_fmts = (const enum AVPixelFormat[]){
1111  },
1112  .caps_internal = FF_CODEC_CAP_INIT_THREADSAFE |
1114 };
1115 
1116 #if CONFIG_FFVHUFF_ENCODER
1117 AVCodec ff_ffvhuff_encoder = {
1118  .name = "ffvhuff",
1119  .long_name = NULL_IF_CONFIG_SMALL("Huffyuv FFmpeg variant"),
1120  .type = AVMEDIA_TYPE_VIDEO,
1121  .id = AV_CODEC_ID_FFVHUFF,
1122  .priv_data_size = sizeof(HYuvContext),
1123  .init = encode_init,
1124  .encode2 = encode_frame,
1125  .close = encode_end,
1127  .priv_class = &ff_class,
1128  .pix_fmts = (const enum AVPixelFormat[]){
1145  },
1146  .caps_internal = FF_CODEC_CAP_INIT_THREADSAFE |
1148 };
1149 #endif
#define FF_CODEC_CAP_INIT_CLEANUP
The codec allows calling the close function for deallocation even if the init function returned a fai...
Definition: internal.h:48
#define AV_CODEC_FLAG_INTERLACED_ME
interlaced motion estimation
Definition: avcodec.h:930
void(* bswap_buf)(uint32_t *dst, const uint32_t *src, int w)
Definition: bswapdsp.h:25
int plane
Definition: avisynth_c.h:422
#define FF_COMPLIANCE_EXPERIMENTAL
Allow nonstandardized experimental things.
Definition: avcodec.h:2956
#define NULL
Definition: coverity.c:32
const struct AVCodec * codec
Definition: avcodec.h:1741
const char const char void * val
Definition: avisynth_c.h:771
#define AV_PIX_FMT_YUVA422P16
Definition: pixfmt.h:388
const char * s
Definition: avisynth_c.h:768
void(* sub_hfyu_median_pred_int16)(uint16_t *dst, const uint16_t *src1, const uint16_t *src2, unsigned mask, int w, int *left, int *left_top)
Definition: huffyuvencdsp.h:32
#define AV_PIX_FMT_YUVA422P9
Definition: pixfmt.h:382
const AVPixFmtDescriptor * av_pix_fmt_desc_get(enum AVPixelFormat pix_fmt)
Definition: pixdesc.c:2333
This structure describes decoded (raw) audio or video data.
Definition: frame.h:187
static av_cold int encode_init(AVCodecContext *avctx)
Definition: huffyuvenc.c:213
AVOption.
Definition: opt.h:246
ptrdiff_t const GLvoid * data
Definition: opengl_enc.c:101
#define AV_PIX_FMT_YUVA420P10
Definition: pixfmt.h:384
#define AV_PIX_FMT_YUV444P14
Definition: pixfmt.h:361
#define AV_PIX_FMT_YUVA422P10
Definition: pixfmt.h:385
int bitstream_bpp
Definition: huffyuv.h:63
planar YUV 4:4:4, 24bpp, (1 Cr & Cb sample per 1x1 Y samples)
Definition: pixfmt.h:67
static void put_bits(Jpeg2000EncoderContext *s, int val, int n)
put n times val bit
Definition: j2kenc.c:206
#define LIBAVUTIL_VERSION_INT
Definition: version.h:85
packed RGB 8:8:8, 24bpp, RGBRGB...
Definition: pixfmt.h:64
#define STATEND
else temp
Definition: vf_mcdeint.c:259
const char * g
Definition: vf_curves.c:112
Definition: vf_geq.c:46
const char * desc
Definition: nvenc.c:60
static av_cold int init(AVCodecContext *avctx)
Definition: avrndec.c:35
void(* diff_int16)(uint16_t *dst, const uint16_t *src1, const uint16_t *src2, unsigned mask, int w)
Definition: huffyuvencdsp.h:27
planar GBR 4:4:4 24bpp
Definition: pixfmt.h:180
int size
Definition: avcodec.h:1658
const char * b
Definition: vf_curves.c:113
#define AV_PIX_FMT_GBRP10
Definition: pixfmt.h:367
static int encode_plane_bitstream(HYuvContext *s, int width, int plane)
Definition: huffyuvenc.c:506
enum AVPixelFormat pix_fmt
Pixel format, see AV_PIX_FMT_xxx.
Definition: avcodec.h:1960
#define AV_PIX_FMT_YUV420P12
Definition: pixfmt.h:355
char * stats_in
pass2 encoding statistics input buffer Concatenated stuff from stats_out of pass1 should be placed he...
Definition: avcodec.h:2909
#define MAX_VLC_N
Definition: huffyuv.h:47
int context
Definition: huffyuv.h:77
void * av_mallocz(size_t size)
Allocate a memory block with alignment suitable for all memory accesses (including vectors if availab...
Definition: mem.c:222
GLfloat v0
Definition: opengl_enc.c:107
static AVPacket pkt
#define src
Definition: vp8dsp.c:254
LLVidEncDSPContext llvidencdsp
Definition: huffyuv.h:93
AVCodec.
Definition: avcodec.h:3681
int height
Definition: huffyuv.h:75
#define AV_CODEC_CAP_INTRA_ONLY
Codec is intra only.
Definition: avcodec.h:1087
#define LOAD_GBRA
av_cold void ff_huffyuvencdsp_init(HuffYUVEncDSPContext *c, AVCodecContext *avctx)
Definition: huffyuvencdsp.c:71
av_cold void ff_llvidencdsp_init(LLVidEncDSPContext *c)
void(* diff_bytes)(uint8_t *dst, const uint8_t *src1, const uint8_t *src2, intptr_t w)
const char * class_name
The name of the class; usually it is the same name as the context structure type to which the AVClass...
Definition: log.h:72
#define av_assert0(cond)
assert() equivalent, that is always enabled.
Definition: avassert.h:37
#define FF_CODEC_CAP_INIT_THREADSAFE
The codec does not modify any global variables in the init function, allowing to call the init functi...
Definition: internal.h:40
planar YUV 4:2:0, 20bpp, (1 Cr & Cb sample per 2x2 Y & A samples)
Definition: pixfmt.h:102
AVComponentDescriptor comp[4]
Parameters that describe how pixels are packed.
Definition: pixdesc.h:117
uint8_t
#define av_cold
Definition: attributes.h:82
#define AV_PIX_FMT_FLAG_ALPHA
The pixel format has an alpha channel.
Definition: pixdesc.h:173
AVOptions.
#define STATEND_16
static av_cold int end(AVCodecContext *avctx)
Definition: avrndec.c:90
int bps
Definition: huffyuv.h:67
uint8_t * extradata
some codecs need / can use extradata like Huffman tables.
Definition: avcodec.h:1847
#define AV_PIX_FMT_YUVA420P9
Definition: pixfmt.h:381
#define AV_PIX_FMT_GBRP9
Definition: pixfmt.h:366
static void sub_median_prediction(HYuvContext *s, uint8_t *dst, const uint8_t *src1, const uint8_t *src2, int w, int *left, int *left_top)
Definition: huffyuvenc.c:157
#define height
uint8_t * data
Definition: avcodec.h:1657
attribute_deprecated int context_model
Definition: avcodec.h:2791
#define STATS_OUT_SIZE
int vlc_n
Definition: huffyuv.h:69
#define AV_PIX_FMT_YUV444P16
Definition: pixfmt.h:364
static void sub_left_prediction_rgb24(HYuvContext *s, uint8_t *dst, uint8_t *src, int w, int *red, int *green, int *blue)
Definition: huffyuvenc.c:129
ptrdiff_t size
Definition: opengl_enc.c:101
int chroma_h_shift
Definition: huffyuv.h:73
int bits_per_coded_sample
bits per sample/pixel from the demuxer (needed for huffyuv).
Definition: avcodec.h:3126
#define LOAD2
#define AV_PIX_FMT_YUV422P12
Definition: pixfmt.h:356
char * stats_out
pass1 encoding statistics output buffer
Definition: avcodec.h:2901
#define AV_PIX_FMT_YUVA420P16
Definition: pixfmt.h:387
#define A(x)
Definition: vp56_arith.h:28
#define AV_INPUT_BUFFER_MIN_SIZE
minimum encoding buffer size Used to avoid some checks during header writing.
Definition: avcodec.h:776
#define av_log(a,...)
#define AV_PKT_FLAG_KEY
The packet contains a keyframe.
Definition: avcodec.h:1689
uint8_t len[4][MAX_VLC_N]
Definition: huffyuv.h:83
#define MAX_N
Definition: huffyuv.h:46
static int encode_frame(AVCodecContext *avctx, AVPacket *pkt, const AVFrame *pict, int *got_packet)
Definition: huffyuvenc.c:764
#define LOAD2_14
av_cold int ff_huffyuv_alloc_temp(HYuvContext *s)
Definition: huffyuv.c:58
enum AVCodecID id
Definition: avcodec.h:3695
planar YUV 4:2:2 24bpp, (1 Cr & Cb sample per 2x1 Y & A samples)
Definition: pixfmt.h:188
static double alpha(void *priv, double x, double y)
Definition: vf_geq.c:99
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition: log.h:176
int chroma_v_shift
Definition: huffyuv.h:74
Definition: huffyuv.h:51
av_cold void ff_huffyuv_common_end(HYuvContext *s)
Definition: huffyuv.c:86
static const uint16_t mask[17]
Definition: lzw.c:38
av_default_item_name
#define AVERROR(e)
Definition: error.h:43
int flags
Definition: huffyuv.h:76
#define AV_PIX_FMT_FLAG_RGB
The pixel format contains RGB-like data (as opposed to YUV/grayscale).
Definition: pixdesc.h:148
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.
Definition: pixdesc.c:2361
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification. ...
Definition: internal.h:179
const char * r
Definition: vf_curves.c:111
static const AVClass ff_class
Definition: huffyuvenc.c:1090
#define AV_PIX_FMT_YUVA444P16
Definition: pixfmt.h:389
int flags
AV_CODEC_FLAG_*.
Definition: avcodec.h:1827
uint8_t * buf
Definition: put_bits.h:38
const char * name
Name of the codec implementation.
Definition: avcodec.h:3688
#define AV_PIX_FMT_YUV444P10
Definition: pixfmt.h:354
static const AVClass normal_class
Definition: huffyuvenc.c:1083
int chroma
Definition: huffyuv.h:71
static const uint8_t offset[127][2]
Definition: vf_spp.c:92
GLsizei count
Definition: opengl_enc.c:109
#define COMMON_OPTIONS
Definition: huffyuvenc.c:1063
huffyuv codec for libavcodec.
#define AV_CODEC_CAP_FRAME_THREADS
Codec supports frame-level multithreading.
Definition: avcodec.h:1057
int flags
A combination of AV_PKT_FLAG values.
Definition: avcodec.h:1663
static int put_bits_count(PutBitContext *s)
Definition: put_bits.h:85
planar YUV 4:2:2, 16bpp, (1 Cr & Cb sample per 2x1 Y samples)
Definition: pixfmt.h:66
void(* sub_median_pred)(uint8_t *dst, const uint8_t *src1, const uint8_t *src2, intptr_t w, int *left, int *left_top)
Subtract HuffYUV's variant of median prediction.
#define WRITE_GBRA
uint64_t flags
Combination of AV_PIX_FMT_FLAG_...
Definition: pixdesc.h:106
#define AV_PIX_FMT_YUV422P9
Definition: pixfmt.h:349
uint8_t nb_components
The number of components each pixel has, (1-4)
Definition: pixdesc.h:83
#define WRITE2
int decorrelate
Definition: huffyuv.h:62
enum AVPictureType pict_type
Picture type of the frame.
Definition: frame.h:261
#define AV_PIX_FMT_GBRP16
Definition: pixfmt.h:370
alias for AV_PIX_FMT_YA8
Definition: pixfmt.h:157
#define AV_PIX_FMT_GRAY16
Definition: pixfmt.h:335
#define FFMIN(a, b)
Definition: common.h:96
int width
Definition: huffyuv.h:75
AVCodec ff_huffyuv_encoder
Definition: huffyuvenc.c:1097
#define width
#define AV_CODEC_FLAG_PASS1
Use internal 2pass ratecontrol in first pass mode.
Definition: avcodec.h:884
int ff_huffyuv_generate_bits_table(uint32_t *dst, const uint8_t *len_table, int n)
Definition: huffyuv.c:39
int n
Definition: avisynth_c.h:684
#define AV_PIX_FMT_YUVA444P10
Definition: pixfmt.h:386
uint8_t * temp[3]
Definition: huffyuv.h:80
static av_cold int encode_end(AVCodecContext *avctx)
Definition: huffyuvenc.c:1048
#define AV_PIX_FMT_YUV444P9
Definition: pixfmt.h:350
#define AV_PIX_FMT_GBRP14
Definition: pixfmt.h:369
int alpha
Definition: huffyuv.h:70
#define AV_PIX_FMT_YUV420P16
Definition: pixfmt.h:362
#define src1
Definition: h264pred.c:139
#define AV_LOG_INFO
Standard information.
Definition: log.h:187
#define AV_PIX_FMT_YUV420P14
Definition: pixfmt.h:359
int picture_number
Definition: huffyuv.h:78
int ff_huff_gen_len_table(uint8_t *dst, const uint64_t *stats, int stats_size, int skip0)
Definition: huffman.c:58
static int sub_left_prediction(HYuvContext *s, uint8_t *dst, const uint8_t *src, int w, int left)
Definition: huffyuvenc.c:51
Libavcodec external API header.
static int encode_422_bitstream(HYuvContext *s, int offset, int count)
Definition: huffyuvenc.c:451
attribute_deprecated int prediction_method
Definition: avcodec.h:2123
int yuv
Definition: huffyuv.h:72
int linesize[AV_NUM_DATA_POINTERS]
For video, size in bytes of each picture line.
Definition: frame.h:218
static const AVOption ff_options[]
Definition: huffyuvenc.c:1077
planar YUV 4:4:4 32bpp, (1 Cr & Cb sample per 1x1 Y & A samples)
Definition: pixfmt.h:189
Descriptor that unambiguously describes how the bits of a pixel are stored in the up to 4 data planes...
Definition: pixdesc.h:81
main external API structure.
Definition: avcodec.h:1732
Definition: vf_geq.c:46
#define AV_PIX_FMT_RGB32
Definition: pixfmt.h:326
#define STAT2
uint8_t * buf_end
Definition: put_bits.h:38
void * buf
Definition: avisynth_c.h:690
int interlaced
Definition: huffyuv.h:61
int extradata_size
Definition: avcodec.h:1848
#define AV_PIX_FMT_YUV420P10
Definition: pixfmt.h:351
planar YUV 4:1:0, 9bpp, (1 Cr & Cb sample per 4x4 Y samples)
Definition: pixfmt.h:68
Describe the class of an AVClass context structure.
Definition: log.h:67
int index
Definition: gxfenc.c:89
#define WRITEEND
Definition: vf_geq.c:46
huffman tree builder and VLC generator
#define STAT2_16
#define src0
Definition: h264pred.c:138
static int encode_bgra_bitstream(HYuvContext *s, int count, int planes)
Definition: huffyuvenc.c:713
#define LOAD4
#define STAT_BGRA
#define AV_PIX_FMT_YUV420P9
Definition: pixfmt.h:348
#define snprintf
Definition: snprintf.h:34
int ff_alloc_packet2(AVCodecContext *avctx, AVPacket *avpkt, int64_t size, int64_t min_size)
Check AVPacket size and/or allocate data.
Definition: utils.c:1736
#define u(width,...)
static enum AVPixelFormat pix_fmts[]
Definition: libkvazaar.c:262
#define AV_PIX_FMT_YUV422P14
Definition: pixfmt.h:360
#define AV_PIX_FMT_GBRP12
Definition: pixfmt.h:368
HuffYUVEncDSPContext hencdsp
Definition: huffyuv.h:91
int version
Definition: huffyuv.h:64
#define AV_PIX_FMT_YUV422P10
Definition: pixfmt.h:352
#define AV_PIX_FMT_YUV444P12
Definition: pixfmt.h:358
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
Definition: frame.h:201
Predictor predictor
Definition: huffyuv.h:58
static void diff_bytes(HYuvContext *s, uint8_t *dst, const uint8_t *src0, const uint8_t *src1, int w)
Definition: huffyuvenc.c:41
AVCodecContext * avctx
Definition: huffyuv.h:57
#define WRITE2_16
GLint GLenum GLboolean GLsizei stride
Definition: opengl_enc.c:105
PutBitContext pb
Definition: huffyuv.h:60
planar YUV 4:2:0, 12bpp, (1 Cr & Cb sample per 2x2 Y samples)
Definition: pixfmt.h:62
Y , 8bpp.
Definition: pixfmt.h:70
Definition: huffyuv.h:52
#define OFFSET(x)
Definition: huffyuvenc.c:1060
#define FF_DISABLE_DEPRECATION_WARNINGS
Definition: internal.h:83
common internal api header.
static void flush_put_bits(PutBitContext *s)
Pad the end of the output stream with zeros.
Definition: put_bits.h:101
static int store_huffman_tables(HYuvContext *s, uint8_t *buf)
Definition: huffyuvenc.c:191
#define VE
Definition: huffyuvenc.c:1061
planar GBRA 4:4:4:4 32bpp
Definition: pixfmt.h:229
static int store_table(HYuvContext *s, const uint8_t *len, uint8_t *buf)
Definition: huffyuvenc.c:166
#define LOAD2_16
#define AV_CODEC_FLAG2_NO_OUTPUT
Skip bitstream encoding.
Definition: avcodec.h:940
#define AV_PIX_FMT_YUVA444P9
Definition: pixfmt.h:383
attribute_deprecated AVFrame * coded_frame
the picture in the bitstream
Definition: avcodec.h:3152
planar YUV 4:1:1, 12bpp, (1 Cr & Cb sample per 4x1 Y samples)
Definition: pixfmt.h:69
static int encode_gray_bitstream(HYuvContext *s, int count)
Definition: huffyuvenc.c:668
static void init_put_bits(PutBitContext *s, uint8_t *buffer, int buffer_size)
Initialize the PutBitContext s.
Definition: put_bits.h:48
static void sub_left_prediction_bgr32(HYuvContext *s, uint8_t *dst, const uint8_t *src, int w, int *red, int *green, int *blue, int *alpha)
Definition: huffyuvenc.c:94
av_cold void ff_huffyuv_common_init(AVCodecContext *avctx)
Definition: huffyuv.c:71
#define AV_CODEC_FLAG_PASS2
Use internal 2pass ratecontrol in second pass mode.
Definition: avcodec.h:888
void * priv_data
Definition: avcodec.h:1774
#define FF_ENABLE_DEPRECATION_WARNINGS
Definition: internal.h:84
int len
int key_frame
1 -> keyframe, 0-> not
Definition: frame.h:256
int flags2
AV_CODEC_FLAG2_*.
Definition: avcodec.h:1834
#define WRITEEND_16
#define LOADEND_16
#define av_freep(p)
planar YUV 4:4:0 (1 Cr & Cb sample per 1x2 Y samples)
Definition: pixfmt.h:100
#define LOADEND
uint32_t bits[4][MAX_VLC_N]
Definition: huffyuv.h:84
uint64_t stats[4][MAX_VLC_N]
Definition: huffyuv.h:82
#define stride
static const AVOption normal_options[]
Definition: huffyuvenc.c:1072
int depth
Number of bits in the component.
Definition: pixdesc.h:58
#define LOADEND_14
AVPixelFormat
Pixel format.
Definition: pixfmt.h:60
This structure stores compressed data.
Definition: avcodec.h:1634
BswapDSPContext bdsp
Definition: huffyuv.h:89
#define AV_PIX_FMT_FLAG_PLANAR
At least one pixel component is not in the first data plane.
Definition: pixdesc.h:144
int strict_std_compliance
strictly follow the standard (MPEG-4, ...).
Definition: avcodec.h:2951
#define AV_PIX_FMT_YUV422P16
Definition: pixfmt.h:363
for(j=16;j >0;--j)
bitstream writer API