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