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&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  avctx->coded_frame = av_frame_alloc();
232  if (!avctx->extradata || !avctx->coded_frame)
233  return AVERROR(ENOMEM);
234 
236  avctx->coded_frame->key_frame = 1;
237 
238  s->bps = desc->comp[0].depth_minus1 + 1;
239  s->yuv = !(desc->flags & AV_PIX_FMT_FLAG_RGB) && desc->nb_components >= 2;
240  s->chroma = desc->nb_components > 2;
241  s->alpha = !!(desc->flags & AV_PIX_FMT_FLAG_ALPHA);
243  &s->chroma_h_shift,
244  &s->chroma_v_shift);
245 
246  switch (avctx->pix_fmt) {
247  case AV_PIX_FMT_YUV420P:
248  case AV_PIX_FMT_YUV422P:
249  if (s->width & 1) {
250  av_log(avctx, AV_LOG_ERROR, "Width must be even for this colorspace.\n");
251  return AVERROR(EINVAL);
252  }
253  s->bitstream_bpp = avctx->pix_fmt == AV_PIX_FMT_YUV420P ? 12 : 16;
254  break;
255  case AV_PIX_FMT_YUV444P:
256  case AV_PIX_FMT_YUV410P:
257  case AV_PIX_FMT_YUV411P:
258  case AV_PIX_FMT_YUV440P:
259  case AV_PIX_FMT_GBRP:
260  case AV_PIX_FMT_GBRP9:
261  case AV_PIX_FMT_GBRP10:
262  case AV_PIX_FMT_GBRP12:
263  case AV_PIX_FMT_GBRP14:
264  case AV_PIX_FMT_GBRP16:
265  case AV_PIX_FMT_GRAY8:
266  case AV_PIX_FMT_GRAY16:
267  case AV_PIX_FMT_YUVA444P:
268  case AV_PIX_FMT_YUVA420P:
269  case AV_PIX_FMT_YUVA422P:
270  case AV_PIX_FMT_GBRAP:
271  case AV_PIX_FMT_GRAY8A:
272  case AV_PIX_FMT_YUV420P9:
277  case AV_PIX_FMT_YUV422P9:
282  case AV_PIX_FMT_YUV444P9:
296  s->version = 3;
297  break;
298  case AV_PIX_FMT_RGB32:
299  s->bitstream_bpp = 32;
300  break;
301  case AV_PIX_FMT_RGB24:
302  s->bitstream_bpp = 24;
303  break;
304  default:
305  av_log(avctx, AV_LOG_ERROR, "format not supported\n");
306  return AVERROR(EINVAL);
307  }
308  s->n = 1<<s->bps;
309  s->vlc_n = FFMIN(s->n, MAX_VLC_N);
310 
312  s->decorrelate = s->bitstream_bpp >= 24 && !s->yuv && !(desc->flags & AV_PIX_FMT_FLAG_PLANAR);
313  s->predictor = avctx->prediction_method;
314  s->interlaced = avctx->flags&CODEC_FLAG_INTERLACED_ME ? 1 : 0;
315  if (avctx->context_model == 1) {
316  s->context = avctx->context_model;
318  av_log(avctx, AV_LOG_ERROR,
319  "context=1 is not compatible with "
320  "2 pass huffyuv encoding\n");
321  return AVERROR(EINVAL);
322  }
323  }else s->context= 0;
324 
325  if (avctx->codec->id == AV_CODEC_ID_HUFFYUV) {
326  if (avctx->pix_fmt == AV_PIX_FMT_YUV420P) {
327  av_log(avctx, AV_LOG_ERROR,
328  "Error: YV12 is not supported by huffyuv; use "
329  "vcodec=ffvhuff or format=422p\n");
330  return AVERROR(EINVAL);
331  }
332  if (avctx->context_model) {
333  av_log(avctx, AV_LOG_ERROR,
334  "Error: per-frame huffman tables are not supported "
335  "by huffyuv; use vcodec=ffvhuff\n");
336  return AVERROR(EINVAL);
337  }
338  if (s->version > 2) {
339  av_log(avctx, AV_LOG_ERROR,
340  "Error: ver>2 is not supported "
341  "by huffyuv; use vcodec=ffvhuff\n");
342  return AVERROR(EINVAL);
343  }
344  if (s->interlaced != ( s->height > 288 ))
345  av_log(avctx, AV_LOG_INFO,
346  "using huffyuv 2.2.0 or newer interlacing flag\n");
347  }
348 
350  av_log(avctx, AV_LOG_ERROR, "Ver > 3 is under development, files encoded with it may not be decodable with future versions!!!\n"
351  "Use vstrict=-2 / -strict -2 to use it anyway.\n");
352  return AVERROR(EINVAL);
353  }
354 
355  if (s->bitstream_bpp >= 24 && s->predictor == MEDIAN && s->version <= 2) {
356  av_log(avctx, AV_LOG_ERROR,
357  "Error: RGB is incompatible with median predictor\n");
358  return AVERROR(EINVAL);
359  }
360 
361  ((uint8_t*)avctx->extradata)[0] = s->predictor | (s->decorrelate << 6);
362  ((uint8_t*)avctx->extradata)[2] = s->interlaced ? 0x10 : 0x20;
363  if (s->context)
364  ((uint8_t*)avctx->extradata)[2] |= 0x40;
365  if (s->version < 3) {
366  ((uint8_t*)avctx->extradata)[1] = s->bitstream_bpp;
367  ((uint8_t*)avctx->extradata)[3] = 0;
368  } else {
369  ((uint8_t*)avctx->extradata)[1] = ((s->bps-1)<<4) | s->chroma_h_shift | (s->chroma_v_shift<<2);
370  if (s->chroma)
371  ((uint8_t*)avctx->extradata)[2] |= s->yuv ? 1 : 2;
372  if (s->alpha)
373  ((uint8_t*)avctx->extradata)[2] |= 4;
374  ((uint8_t*)avctx->extradata)[3] = 1;
375  }
376  s->avctx->extradata_size = 4;
377 
378  if (avctx->stats_in) {
379  char *p = avctx->stats_in;
380 
381  for (i = 0; i < 4; i++)
382  for (j = 0; j < s->vlc_n; j++)
383  s->stats[i][j] = 1;
384 
385  for (;;) {
386  for (i = 0; i < 4; i++) {
387  char *next;
388 
389  for (j = 0; j < s->vlc_n; j++) {
390  s->stats[i][j] += strtol(p, &next, 0);
391  if (next == p) return -1;
392  p = next;
393  }
394  }
395  if (p[0] == 0 || p[1] == 0 || p[2] == 0) break;
396  }
397  } else {
398  for (i = 0; i < 4; i++)
399  for (j = 0; j < s->vlc_n; j++) {
400  int d = FFMIN(j, s->vlc_n - j);
401 
402  s->stats[i][j] = 100000000 / (d*d + 1);
403  }
404  }
405 
407  if (ret < 0)
408  return ret;
409  s->avctx->extradata_size += ret;
410 
411  if (s->context) {
412  for (i = 0; i < 4; i++) {
413  int pels = s->width * s->height / (i ? 40 : 10);
414  for (j = 0; j < s->vlc_n; j++) {
415  int d = FFMIN(j, s->vlc_n - j);
416  s->stats[i][j] = pels/(d*d + 1);
417  }
418  }
419  } else {
420  for (i = 0; i < 4; i++)
421  for (j = 0; j < s->vlc_n; j++)
422  s->stats[i][j]= 0;
423  }
424 
425  if (ff_huffyuv_alloc_temp(s)) {
427  return AVERROR(ENOMEM);
428  }
429 
430  s->picture_number=0;
431 
432  return 0;
433 }
435 {
436  int i;
437  const uint8_t *y = s->temp[0] + offset;
438  const uint8_t *u = s->temp[1] + offset / 2;
439  const uint8_t *v = s->temp[2] + offset / 2;
440 
441  if (s->pb.buf_end - s->pb.buf - (put_bits_count(&s->pb) >> 3) < 2 * 4 * count) {
442  av_log(s->avctx, AV_LOG_ERROR, "encoded frame too large\n");
443  return -1;
444  }
445 
446 #define LOAD4\
447  int y0 = y[2 * i];\
448  int y1 = y[2 * i + 1];\
449  int u0 = u[i];\
450  int v0 = v[i];
451 
452  count /= 2;
453 
454  if (s->flags & CODEC_FLAG_PASS1) {
455  for(i = 0; i < count; i++) {
456  LOAD4;
457  s->stats[0][y0]++;
458  s->stats[1][u0]++;
459  s->stats[0][y1]++;
460  s->stats[2][v0]++;
461  }
462  }
464  return 0;
465  if (s->context) {
466  for (i = 0; i < count; i++) {
467  LOAD4;
468  s->stats[0][y0]++;
469  put_bits(&s->pb, s->len[0][y0], s->bits[0][y0]);
470  s->stats[1][u0]++;
471  put_bits(&s->pb, s->len[1][u0], s->bits[1][u0]);
472  s->stats[0][y1]++;
473  put_bits(&s->pb, s->len[0][y1], s->bits[0][y1]);
474  s->stats[2][v0]++;
475  put_bits(&s->pb, s->len[2][v0], s->bits[2][v0]);
476  }
477  } else {
478  for(i = 0; i < count; i++) {
479  LOAD4;
480  put_bits(&s->pb, s->len[0][y0], s->bits[0][y0]);
481  put_bits(&s->pb, s->len[1][u0], s->bits[1][u0]);
482  put_bits(&s->pb, s->len[0][y1], s->bits[0][y1]);
483  put_bits(&s->pb, s->len[2][v0], s->bits[2][v0]);
484  }
485  }
486  return 0;
487 }
488 
490 {
491  int i, count = width/2;
492 
493  if (s->pb.buf_end - s->pb.buf - (put_bits_count(&s->pb) >> 3) < count * s->bps / 2) {
494  av_log(s->avctx, AV_LOG_ERROR, "encoded frame too large\n");
495  return -1;
496  }
497 
498 #define LOADEND\
499  int y0 = s->temp[0][width-1];
500 #define LOADEND_14\
501  int y0 = s->temp16[0][width-1] & mask;
502 #define LOADEND_16\
503  int y0 = s->temp16[0][width-1];
504 #define STATEND\
505  s->stats[plane][y0]++;
506 #define STATEND_16\
507  s->stats[plane][y0>>2]++;
508 #define WRITEEND\
509  put_bits(&s->pb, s->len[plane][y0], s->bits[plane][y0]);
510 #define WRITEEND_16\
511  put_bits(&s->pb, s->len[plane][y0>>2], s->bits[plane][y0>>2]);\
512  put_bits(&s->pb, 2, y0&3);
513 
514 #define LOAD2\
515  int y0 = s->temp[0][2 * i];\
516  int y1 = s->temp[0][2 * i + 1];
517 #define LOAD2_14\
518  int y0 = s->temp16[0][2 * i] & mask;\
519  int y1 = s->temp16[0][2 * i + 1] & mask;
520 #define LOAD2_16\
521  int y0 = s->temp16[0][2 * i];\
522  int y1 = s->temp16[0][2 * i + 1];
523 #define STAT2\
524  s->stats[plane][y0]++;\
525  s->stats[plane][y1]++;
526 #define STAT2_16\
527  s->stats[plane][y0>>2]++;\
528  s->stats[plane][y1>>2]++;
529 #define WRITE2\
530  put_bits(&s->pb, s->len[plane][y0], s->bits[plane][y0]);\
531  put_bits(&s->pb, s->len[plane][y1], s->bits[plane][y1]);
532 #define WRITE2_16\
533  put_bits(&s->pb, s->len[plane][y0>>2], s->bits[plane][y0>>2]);\
534  put_bits(&s->pb, 2, y0&3);\
535  put_bits(&s->pb, s->len[plane][y1>>2], s->bits[plane][y1>>2]);\
536  put_bits(&s->pb, 2, y1&3);
537 
538  if (s->bps <= 8) {
539  if (s->flags & CODEC_FLAG_PASS1) {
540  for (i = 0; i < count; i++) {
541  LOAD2;
542  STAT2;
543  }
544  if (width&1) {
545  LOADEND;
546  STATEND;
547  }
548  }
550  return 0;
551 
552  if (s->context) {
553  for (i = 0; i < count; i++) {
554  LOAD2;
555  STAT2;
556  WRITE2;
557  }
558  if (width&1) {
559  LOADEND;
560  STATEND;
561  WRITEEND;
562  }
563  } else {
564  for (i = 0; i < count; i++) {
565  LOAD2;
566  WRITE2;
567  }
568  if (width&1) {
569  LOADEND;
570  WRITEEND;
571  }
572  }
573  } else if (s->bps <= 14) {
574  int mask = s->n - 1;
575  if (s->flags & CODEC_FLAG_PASS1) {
576  for (i = 0; i < count; i++) {
577  LOAD2_14;
578  STAT2;
579  }
580  if (width&1) {
581  LOADEND_14;
582  STATEND;
583  }
584  }
586  return 0;
587 
588  if (s->context) {
589  for (i = 0; i < count; i++) {
590  LOAD2_14;
591  STAT2;
592  WRITE2;
593  }
594  if (width&1) {
595  LOADEND_14;
596  STATEND;
597  WRITEEND;
598  }
599  } else {
600  for (i = 0; i < count; i++) {
601  LOAD2_14;
602  WRITE2;
603  }
604  if (width&1) {
605  LOADEND_14;
606  WRITEEND;
607  }
608  }
609  } else {
610  if (s->flags & CODEC_FLAG_PASS1) {
611  for (i = 0; i < count; i++) {
612  LOAD2_16;
613  STAT2_16;
614  }
615  if (width&1) {
616  LOADEND_16;
617  STATEND_16;
618  }
619  }
621  return 0;
622 
623  if (s->context) {
624  for (i = 0; i < count; i++) {
625  LOAD2_16;
626  STAT2_16;
627  WRITE2_16;
628  }
629  if (width&1) {
630  LOADEND_16;
631  STATEND_16;
632  WRITEEND_16;
633  }
634  } else {
635  for (i = 0; i < count; i++) {
636  LOAD2_16;
637  WRITE2_16;
638  }
639  if (width&1) {
640  LOADEND_16;
641  WRITEEND_16;
642  }
643  }
644  }
645 #undef LOAD2
646 #undef STAT2
647 #undef WRITE2
648  return 0;
649 }
650 
652 {
653  int i;
654 
655  if (s->pb.buf_end - s->pb.buf - (put_bits_count(&s->pb) >> 3) < 4 * count) {
656  av_log(s->avctx, AV_LOG_ERROR, "encoded frame too large\n");
657  return -1;
658  }
659 
660 #define LOAD2\
661  int y0 = s->temp[0][2 * i];\
662  int y1 = s->temp[0][2 * i + 1];
663 #define STAT2\
664  s->stats[0][y0]++;\
665  s->stats[0][y1]++;
666 #define WRITE2\
667  put_bits(&s->pb, s->len[0][y0], s->bits[0][y0]);\
668  put_bits(&s->pb, s->len[0][y1], s->bits[0][y1]);
669 
670  count /= 2;
671 
672  if (s->flags & CODEC_FLAG_PASS1) {
673  for (i = 0; i < count; i++) {
674  LOAD2;
675  STAT2;
676  }
677  }
679  return 0;
680 
681  if (s->context) {
682  for (i = 0; i < count; i++) {
683  LOAD2;
684  STAT2;
685  WRITE2;
686  }
687  } else {
688  for (i = 0; i < count; i++) {
689  LOAD2;
690  WRITE2;
691  }
692  }
693  return 0;
694 }
695 
696 static inline int encode_bgra_bitstream(HYuvContext *s, int count, int planes)
697 {
698  int i;
699 
700  if (s->pb.buf_end - s->pb.buf - (put_bits_count(&s->pb) >> 3) <
701  4 * planes * count) {
702  av_log(s->avctx, AV_LOG_ERROR, "encoded frame too large\n");
703  return -1;
704  }
705 
706 #define LOAD_GBRA \
707  int g = s->temp[0][planes == 3 ? 3 * i + 1 : 4 * i + G]; \
708  int b =(s->temp[0][planes == 3 ? 3 * i + 2 : 4 * i + B] - g) & 0xFF;\
709  int r =(s->temp[0][planes == 3 ? 3 * i + 0 : 4 * i + R] - g) & 0xFF;\
710  int a = s->temp[0][planes * i + A];
711 
712 #define STAT_BGRA \
713  s->stats[0][b]++; \
714  s->stats[1][g]++; \
715  s->stats[2][r]++; \
716  if (planes == 4) \
717  s->stats[2][a]++;
718 
719 #define WRITE_GBRA \
720  put_bits(&s->pb, s->len[1][g], s->bits[1][g]); \
721  put_bits(&s->pb, s->len[0][b], s->bits[0][b]); \
722  put_bits(&s->pb, s->len[2][r], s->bits[2][r]); \
723  if (planes == 4) \
724  put_bits(&s->pb, s->len[2][a], s->bits[2][a]);
725 
726  if ((s->flags & CODEC_FLAG_PASS1) &&
728  for (i = 0; i < count; i++) {
729  LOAD_GBRA;
730  STAT_BGRA;
731  }
732  } else if (s->context || (s->flags & CODEC_FLAG_PASS1)) {
733  for (i = 0; i < count; i++) {
734  LOAD_GBRA;
735  STAT_BGRA;
736  WRITE_GBRA;
737  }
738  } else {
739  for (i = 0; i < count; i++) {
740  LOAD_GBRA;
741  WRITE_GBRA;
742  }
743  }
744  return 0;
745 }
746 
748  const AVFrame *pict, int *got_packet)
749 {
750  HYuvContext *s = avctx->priv_data;
751  const int width = s->width;
752  const int width2 = s->width>>1;
753  const int height = s->height;
754  const int fake_ystride = s->interlaced ? pict->linesize[0]*2 : pict->linesize[0];
755  const int fake_ustride = s->interlaced ? pict->linesize[1]*2 : pict->linesize[1];
756  const int fake_vstride = s->interlaced ? pict->linesize[2]*2 : pict->linesize[2];
757  const AVFrame * const p = pict;
758  int i, j, size = 0, ret;
759 
760  if ((ret = ff_alloc_packet2(avctx, pkt, width * height * 3 * 4 + FF_MIN_BUFFER_SIZE)) < 0)
761  return ret;
762 
763  if (s->context) {
764  size = store_huffman_tables(s, pkt->data);
765  if (size < 0)
766  return size;
767 
768  for (i = 0; i < 4; i++)
769  for (j = 0; j < s->vlc_n; j++)
770  s->stats[i][j] >>= 1;
771  }
772 
773  init_put_bits(&s->pb, pkt->data + size, pkt->size - size);
774 
775  if (avctx->pix_fmt == AV_PIX_FMT_YUV422P ||
776  avctx->pix_fmt == AV_PIX_FMT_YUV420P) {
777  int lefty, leftu, leftv, y, cy;
778 
779  put_bits(&s->pb, 8, leftv = p->data[2][0]);
780  put_bits(&s->pb, 8, lefty = p->data[0][1]);
781  put_bits(&s->pb, 8, leftu = p->data[1][0]);
782  put_bits(&s->pb, 8, p->data[0][0]);
783 
784  lefty = sub_left_prediction(s, s->temp[0], p->data[0], width , 0);
785  leftu = sub_left_prediction(s, s->temp[1], p->data[1], width2, 0);
786  leftv = sub_left_prediction(s, s->temp[2], p->data[2], width2, 0);
787 
788  encode_422_bitstream(s, 2, width-2);
789 
790  if (s->predictor==MEDIAN) {
791  int lefttopy, lefttopu, lefttopv;
792  cy = y = 1;
793  if (s->interlaced) {
794  lefty = sub_left_prediction(s, s->temp[0], p->data[0] + p->linesize[0], width , lefty);
795  leftu = sub_left_prediction(s, s->temp[1], p->data[1] + p->linesize[1], width2, leftu);
796  leftv = sub_left_prediction(s, s->temp[2], p->data[2] + p->linesize[2], width2, leftv);
797 
798  encode_422_bitstream(s, 0, width);
799  y++; cy++;
800  }
801 
802  lefty = sub_left_prediction(s, s->temp[0], p->data[0] + fake_ystride, 4, lefty);
803  leftu = sub_left_prediction(s, s->temp[1], p->data[1] + fake_ustride, 2, leftu);
804  leftv = sub_left_prediction(s, s->temp[2], p->data[2] + fake_vstride, 2, leftv);
805 
806  encode_422_bitstream(s, 0, 4);
807 
808  lefttopy = p->data[0][3];
809  lefttopu = p->data[1][1];
810  lefttopv = p->data[2][1];
811  s->hencdsp.sub_hfyu_median_pred(s->temp[0], p->data[0] + 4, p->data[0] + fake_ystride + 4, width - 4, &lefty, &lefttopy);
812  s->hencdsp.sub_hfyu_median_pred(s->temp[1], p->data[1] + 2, p->data[1] + fake_ustride + 2, width2 - 2, &leftu, &lefttopu);
813  s->hencdsp.sub_hfyu_median_pred(s->temp[2], p->data[2] + 2, p->data[2] + fake_vstride + 2, width2 - 2, &leftv, &lefttopv);
814  encode_422_bitstream(s, 0, width - 4);
815  y++; cy++;
816 
817  for (; y < height; y++,cy++) {
818  uint8_t *ydst, *udst, *vdst;
819 
820  if (s->bitstream_bpp == 12) {
821  while (2 * cy > y) {
822  ydst = p->data[0] + p->linesize[0] * y;
823  s->hencdsp.sub_hfyu_median_pred(s->temp[0], ydst - fake_ystride, ydst, width, &lefty, &lefttopy);
824  encode_gray_bitstream(s, width);
825  y++;
826  }
827  if (y >= height) break;
828  }
829  ydst = p->data[0] + p->linesize[0] * y;
830  udst = p->data[1] + p->linesize[1] * cy;
831  vdst = p->data[2] + p->linesize[2] * cy;
832 
833  s->hencdsp.sub_hfyu_median_pred(s->temp[0], ydst - fake_ystride, ydst, width, &lefty, &lefttopy);
834  s->hencdsp.sub_hfyu_median_pred(s->temp[1], udst - fake_ustride, udst, width2, &leftu, &lefttopu);
835  s->hencdsp.sub_hfyu_median_pred(s->temp[2], vdst - fake_vstride, vdst, width2, &leftv, &lefttopv);
836 
837  encode_422_bitstream(s, 0, width);
838  }
839  } else {
840  for (cy = y = 1; y < height; y++, cy++) {
841  uint8_t *ydst, *udst, *vdst;
842 
843  /* encode a luma only line & y++ */
844  if (s->bitstream_bpp == 12) {
845  ydst = p->data[0] + p->linesize[0] * y;
846 
847  if (s->predictor == PLANE && s->interlaced < y) {
848  s->hencdsp.diff_bytes(s->temp[1], ydst, ydst - fake_ystride, width);
849 
850  lefty = sub_left_prediction(s, s->temp[0], s->temp[1], width , lefty);
851  } else {
852  lefty = sub_left_prediction(s, s->temp[0], ydst, width , lefty);
853  }
854  encode_gray_bitstream(s, width);
855  y++;
856  if (y >= height) break;
857  }
858 
859  ydst = p->data[0] + p->linesize[0] * y;
860  udst = p->data[1] + p->linesize[1] * cy;
861  vdst = p->data[2] + p->linesize[2] * cy;
862 
863  if (s->predictor == PLANE && s->interlaced < cy) {
864  s->hencdsp.diff_bytes(s->temp[1], ydst, ydst - fake_ystride, width);
865  s->hencdsp.diff_bytes(s->temp[2], udst, udst - fake_ustride, width2);
866  s->hencdsp.diff_bytes(s->temp[2] + width2, vdst, vdst - fake_vstride, width2);
867 
868  lefty = sub_left_prediction(s, s->temp[0], s->temp[1], width , lefty);
869  leftu = sub_left_prediction(s, s->temp[1], s->temp[2], width2, leftu);
870  leftv = sub_left_prediction(s, s->temp[2], s->temp[2] + width2, width2, leftv);
871  } else {
872  lefty = sub_left_prediction(s, s->temp[0], ydst, width , lefty);
873  leftu = sub_left_prediction(s, s->temp[1], udst, width2, leftu);
874  leftv = sub_left_prediction(s, s->temp[2], vdst, width2, leftv);
875  }
876 
877  encode_422_bitstream(s, 0, width);
878  }
879  }
880  } else if(avctx->pix_fmt == AV_PIX_FMT_RGB32) {
881  uint8_t *data = p->data[0] + (height - 1) * p->linesize[0];
882  const int stride = -p->linesize[0];
883  const int fake_stride = -fake_ystride;
884  int y;
885  int leftr, leftg, leftb, lefta;
886 
887  put_bits(&s->pb, 8, lefta = data[A]);
888  put_bits(&s->pb, 8, leftr = data[R]);
889  put_bits(&s->pb, 8, leftg = data[G]);
890  put_bits(&s->pb, 8, leftb = data[B]);
891 
892  sub_left_prediction_bgr32(s, s->temp[0], data + 4, width - 1,
893  &leftr, &leftg, &leftb, &lefta);
894  encode_bgra_bitstream(s, width - 1, 4);
895 
896  for (y = 1; y < s->height; y++) {
897  uint8_t *dst = data + y*stride;
898  if (s->predictor == PLANE && s->interlaced < y) {
899  s->hencdsp.diff_bytes(s->temp[1], dst, dst - fake_stride, width * 4);
900  sub_left_prediction_bgr32(s, s->temp[0], s->temp[1], width,
901  &leftr, &leftg, &leftb, &lefta);
902  } else {
903  sub_left_prediction_bgr32(s, s->temp[0], dst, width,
904  &leftr, &leftg, &leftb, &lefta);
905  }
906  encode_bgra_bitstream(s, width, 4);
907  }
908  } else if (avctx->pix_fmt == AV_PIX_FMT_RGB24) {
909  uint8_t *data = p->data[0] + (height - 1) * p->linesize[0];
910  const int stride = -p->linesize[0];
911  const int fake_stride = -fake_ystride;
912  int y;
913  int leftr, leftg, leftb;
914 
915  put_bits(&s->pb, 8, leftr = data[0]);
916  put_bits(&s->pb, 8, leftg = data[1]);
917  put_bits(&s->pb, 8, leftb = data[2]);
918  put_bits(&s->pb, 8, 0);
919 
920  sub_left_prediction_rgb24(s, s->temp[0], data + 3, width - 1,
921  &leftr, &leftg, &leftb);
922  encode_bgra_bitstream(s, width-1, 3);
923 
924  for (y = 1; y < s->height; y++) {
925  uint8_t *dst = data + y * stride;
926  if (s->predictor == PLANE && s->interlaced < y) {
927  s->hencdsp.diff_bytes(s->temp[1], dst, dst - fake_stride,
928  width * 3);
929  sub_left_prediction_rgb24(s, s->temp[0], s->temp[1], width,
930  &leftr, &leftg, &leftb);
931  } else {
932  sub_left_prediction_rgb24(s, s->temp[0], dst, width,
933  &leftr, &leftg, &leftb);
934  }
935  encode_bgra_bitstream(s, width, 3);
936  }
937  } else if (s->version > 2) {
938  int plane;
939  for (plane = 0; plane < 1 + 2*s->chroma + s->alpha; plane++) {
940  int left, y;
941  int w = width;
942  int h = height;
943  int fake_stride = fake_ystride;
944 
945  if (s->chroma && (plane == 1 || plane == 2)) {
946  w >>= s->chroma_h_shift;
947  h >>= s->chroma_v_shift;
948  fake_stride = plane == 1 ? fake_ustride : fake_vstride;
949  }
950 
951  left = sub_left_prediction(s, s->temp[0], p->data[plane], w , 0);
952 
953  encode_plane_bitstream(s, w, plane);
954 
955  if (s->predictor==MEDIAN) {
956  int lefttop;
957  y = 1;
958  if (s->interlaced) {
959  left = sub_left_prediction(s, s->temp[0], p->data[plane] + p->linesize[plane], w , left);
960 
961  encode_plane_bitstream(s, w, plane);
962  y++;
963  }
964 
965  lefttop = p->data[plane][0];
966 
967  for (; y < h; y++) {
968  uint8_t *dst = p->data[plane] + p->linesize[plane] * y;
969 
970  sub_median_prediction(s, s->temp[0], dst - fake_stride, dst, w , &left, &lefttop);
971 
972  encode_plane_bitstream(s, w, plane);
973  }
974  } else {
975  for (y = 1; y < h; y++) {
976  uint8_t *dst = p->data[plane] + p->linesize[plane] * y;
977 
978  if (s->predictor == PLANE && s->interlaced < y) {
979  diff_bytes(s, s->temp[1], dst, dst - fake_stride, w);
980 
981  left = sub_left_prediction(s, s->temp[0], s->temp[1], w , left);
982  } else {
983  left = sub_left_prediction(s, s->temp[0], dst, w , left);
984  }
985 
986  encode_plane_bitstream(s, w, plane);
987  }
988  }
989  }
990  } else {
991  av_log(avctx, AV_LOG_ERROR, "Format not supported!\n");
992  }
993  emms_c();
994 
995  size += (put_bits_count(&s->pb) + 31) / 8;
996  put_bits(&s->pb, 16, 0);
997  put_bits(&s->pb, 15, 0);
998  size /= 4;
999 
1000  if ((s->flags&CODEC_FLAG_PASS1) && (s->picture_number & 31) == 0) {
1001  int j;
1002  char *p = avctx->stats_out;
1003  char *end = p + STATS_OUT_SIZE;
1004  for (i = 0; i < 4; i++) {
1005  for (j = 0; j < s->vlc_n; j++) {
1006  snprintf(p, end-p, "%"PRIu64" ", s->stats[i][j]);
1007  p += strlen(p);
1008  s->stats[i][j]= 0;
1009  }
1010  snprintf(p, end-p, "\n");
1011  p++;
1012  if (end <= p)
1013  return AVERROR(ENOMEM);
1014  }
1015  } else if (avctx->stats_out)
1016  avctx->stats_out[0] = '\0';
1017  if (!(s->avctx->flags2 & CODEC_FLAG2_NO_OUTPUT)) {
1018  flush_put_bits(&s->pb);
1019  s->bdsp.bswap_buf((uint32_t *) pkt->data, (uint32_t *) pkt->data, size);
1020  }
1021 
1022  s->picture_number++;
1023 
1024  pkt->size = size * 4;
1025  pkt->flags |= AV_PKT_FLAG_KEY;
1026  *got_packet = 1;
1027 
1028  return 0;
1029 }
1030 
1032 {
1033  HYuvContext *s = avctx->priv_data;
1034 
1036 
1037  av_freep(&avctx->extradata);
1038  av_freep(&avctx->stats_out);
1039 
1040  av_frame_free(&avctx->coded_frame);
1041 
1042  return 0;
1043 }
1044 
1045 static const AVOption options[] = {
1046  { "non_deterministic", "Allow multithreading for e.g. context=1 at the expense of determinism",
1047  offsetof(HYuvContext, non_determ), AV_OPT_TYPE_INT, { .i64 = 1 },
1049  { NULL },
1050 };
1051 
1052 static const AVClass normal_class = {
1053  .class_name = "huffyuv",
1054  .item_name = av_default_item_name,
1055  .option = options,
1056  .version = LIBAVUTIL_VERSION_INT,
1057 };
1058 
1059 static const AVClass ff_class = {
1060  .class_name = "ffvhuff",
1061  .item_name = av_default_item_name,
1062  .option = options,
1063  .version = LIBAVUTIL_VERSION_INT,
1064 };
1065 
1067  .name = "huffyuv",
1068  .long_name = NULL_IF_CONFIG_SMALL("Huffyuv / HuffYUV"),
1069  .type = AVMEDIA_TYPE_VIDEO,
1070  .id = AV_CODEC_ID_HUFFYUV,
1071  .priv_data_size = sizeof(HYuvContext),
1072  .init = encode_init,
1073  .encode2 = encode_frame,
1074  .close = encode_end,
1076  .priv_class = &normal_class,
1077  .pix_fmts = (const enum AVPixelFormat[]){
1080  },
1081  .caps_internal = FF_CODEC_CAP_INIT_THREADSAFE |
1083 };
1084 
1085 #if CONFIG_FFVHUFF_ENCODER
1086 AVCodec ff_ffvhuff_encoder = {
1087  .name = "ffvhuff",
1088  .long_name = NULL_IF_CONFIG_SMALL("Huffyuv FFmpeg variant"),
1089  .type = AVMEDIA_TYPE_VIDEO,
1090  .id = AV_CODEC_ID_FFVHUFF,
1091  .priv_data_size = sizeof(HYuvContext),
1092  .init = encode_init,
1093  .encode2 = encode_frame,
1094  .close = encode_end,
1096  .priv_class = &ff_class,
1097  .pix_fmts = (const enum AVPixelFormat[]){
1114  },
1115  .caps_internal = FF_CODEC_CAP_INIT_THREADSAFE |
1117 };
1118 #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
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
int ff_alloc_packet2(AVCodecContext *avctx, AVPacket *avpkt, int64_t size)
Check AVPacket size and/or allocate data.
Definition: utils.c:1736
const struct AVCodec * codec
Definition: avcodec.h:1250
const char const char void * val
Definition: avisynth_c.h:634
float v
#define AV_PIX_FMT_YUVA422P16
Definition: pixfmt.h:399
const char * s
Definition: avisynth_c.h:631
#define AV_PIX_FMT_YUVA422P9
Definition: pixfmt.h:393
const AVPixFmtDescriptor * av_pix_fmt_desc_get(enum AVPixelFormat pix_fmt)
Definition: pixdesc.c:2090
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:395
#define AV_PIX_FMT_YUV444P14
Definition: pixfmt.h:374
#define CODEC_FLAG_PASS2
Use internal 2pass ratecontrol in second pass mode.
Definition: avcodec.h:737
#define AV_PIX_FMT_YUVA422P10
Definition: pixfmt.h:396
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:160
#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
#define CODEC_FLAG_PASS1
Use internal 2pass ratecontrol in first pass mode.
Definition: avcodec.h:736
AVFrame * coded_frame
the picture in the bitstream
Definition: avcodec.h:2745
static av_cold int init(AVCodecContext *avctx)
Definition: avrndec.c:35
planar GBR 4:4:4 24bpp
Definition: pixfmt.h:176
int size
Definition: avcodec.h:1163
const char * b
Definition: vf_curves.c:109
#define AV_PIX_FMT_GBRP10
Definition: pixfmt.h:380
static int encode_plane_bitstream(HYuvContext *s, int width, int plane)
Definition: huffyuvenc.c:489
enum AVPixelFormat pix_fmt
Pixel format, see AV_PIX_FMT_xxx.
Definition: avcodec.h:1444
#define AV_PIX_FMT_YUV420P12
Definition: pixfmt.h:368
char * stats_in
pass2 encoding statistics input buffer Concatenated stuff from stats_out of pass1 should be placed he...
Definition: avcodec.h:2502
#define MAX_VLC_N
Definition: huffyuv.h:46
int context
Definition: huffyuv.h:76
Definition: vf_geq.c:45
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:3181
int height
Definition: huffyuv.h:74
av_cold void ff_huffyuvencdsp_init(HuffYUVEncDSPContext *c)
Definition: huffyuvencdsp.c:77
#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:2387
#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
AVFrame * av_frame_alloc(void)
Allocate an AVFrame and set its fields to default values.
Definition: frame.c:135
AVOptions.
#define CODEC_CAP_INTRA_ONLY
Codec is intra only.
Definition: avcodec.h:886
#define STATEND_16
static av_cold int end(AVCodecContext *avctx)
Definition: avrndec.c:67
int bps
Definition: huffyuv.h:66
uint8_t * extradata
some codecs need / can use extradata like Huffman tables.
Definition: avcodec.h:1355
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:392
#define AV_PIX_FMT_GBRP9
Definition: pixfmt.h:379
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:1162
#define STATS_OUT_SIZE
int vlc_n
Definition: huffyuv.h:68
#define AV_PIX_FMT_YUV444P16
Definition: pixfmt.h:377
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:2720
#define LOAD2
#define AV_PIX_FMT_YUV422P12
Definition: pixfmt.h:369
char * stats_out
pass1 encoding statistics output buffer
Definition: avcodec.h:2494
#define AV_PIX_FMT_YUVA420P16
Definition: pixfmt.h:398
#define A(x)
Definition: vp56_arith.h:28
#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:1208
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:747
#define LOAD2_14
av_cold int ff_huffyuv_alloc_temp(HYuvContext *s)
Definition: huffyuv.c:58
enum AVCodecID id
Definition: avcodec.h:3195
planar YUV 4:2:2 24bpp, (1 Cr & Cb sample per 2x1 Y & A samples)
Definition: pixfmt.h:269
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:98
#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
#define CODEC_FLAG_INTERLACED_ME
interlaced motion estimation
Definition: avcodec.h:763
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
void av_frame_free(AVFrame **frame)
Free the frame and any dynamically allocated objects in it, e.g.
Definition: frame.c: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:2118
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:1059
#define AV_PIX_FMT_YUVA444P16
Definition: pixfmt.h:400
int flags
CODEC_FLAG_*.
Definition: avcodec.h:1335
uint8_t * buf
Definition: put_bits.h:38
const char * name
Name of the codec implementation.
Definition: avcodec.h:3188
#define AV_PIX_FMT_YUV444P10
Definition: pixfmt.h:367
static const AVClass normal_class
Definition: huffyuvenc.c:1052
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.
int flags
A combination of AV_PKT_FLAG values.
Definition: avcodec.h:1168
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:362
#define FF_COMPLIANCE_EXPERIMENTAL
Allow nonstandardized experimental things.
Definition: avcodec.h:2548
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:383
alias for AV_PIX_FMT_YA8
Definition: pixfmt.h:146
#define AV_PIX_FMT_GRAY16
Definition: pixfmt.h:348
#define FFMIN(a, b)
Definition: common.h:66
int width
Definition: huffyuv.h:74
AVCodec ff_huffyuv_encoder
Definition: huffyuvenc.c:1066
float y
#define FF_MIN_BUFFER_SIZE
minimum encoding buffer size Used to avoid some checks during header writing.
Definition: avcodec.h:637
ret
Definition: avfilter.c:974
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:397
uint8_t * temp[3]
Definition: huffyuv.h:79
static av_cold int encode_end(AVCodecContext *avctx)
Definition: huffyuvenc.c:1031
#define AV_PIX_FMT_YUV444P9
Definition: pixfmt.h:363
#define AV_PIX_FMT_GBRP14
Definition: pixfmt.h:382
int alpha
Definition: huffyuv.h:69
#define AV_PIX_FMT_YUV420P16
Definition: pixfmt.h:375
#define AV_LOG_INFO
Standard information.
Definition: log.h:187
Definition: vf_geq.c:45
#define AV_PIX_FMT_YUV420P14
Definition: pixfmt.h:372
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:434
int yuv
Definition: huffyuv.h:71
static const AVOption options[]
Definition: huffyuvenc.c:1045
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:268
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:1241
#define AV_PIX_FMT_RGB32
Definition: pixfmt.h:341
#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:1356
BYTE int const BYTE int int int height
Definition: avisynth_c.h:676
#define AV_PIX_FMT_YUV420P10
Definition: pixfmt.h:364
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
static int encode_bgra_bitstream(HYuvContext *s, int count, int planes)
Definition: huffyuvenc.c:696
#define LOAD4
#define STAT_BGRA
#define AV_PIX_FMT_YUV420P9
Definition: pixfmt.h:361
#define snprintf
Definition: snprintf.h:34
#define AV_PIX_FMT_YUV422P14
Definition: pixfmt.h:373
#define AV_PIX_FMT_GBRP12
Definition: pixfmt.h:381
HuffYUVEncDSPContext hencdsp
Definition: huffyuv.h:90
int version
Definition: huffyuv.h:63
#define AV_PIX_FMT_YUV422P10
Definition: pixfmt.h:365
#define AV_PIX_FMT_YUV444P12
Definition: pixfmt.h:371
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
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
#define CODEC_CAP_FRAME_THREADS
Codec supports frame-level multithreading.
Definition: avcodec.h:866
#define CODEC_FLAG2_NO_OUTPUT
Skip bitstream encoding.
Definition: avcodec.h:766
planar GBRA 4:4:4:4 32bpp
Definition: pixfmt.h:287
static int store_table(HYuvContext *s, const uint8_t *len, uint8_t *buf)
Definition: huffyuvenc.c:165
#define LOAD2_16
int prediction_method
prediction method (needed for huffyuv)
Definition: avcodec.h:1604
#define AV_PIX_FMT_YUVA444P9
Definition: pixfmt.h:394
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:651
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
void * priv_data
Definition: avcodec.h:1283
int len
int key_frame
1 -> keyframe, 0-> not
Definition: frame.h:237
int flags2
CODEC_FLAG2_*.
Definition: avcodec.h:1342
#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
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:1139
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:250
int strict_std_compliance
strictly follow the standard (MPEG4, ...).
Definition: avcodec.h:2543
Definition: vf_geq.c:45
#define AV_PIX_FMT_YUV422P16
Definition: pixfmt.h:376
for(j=16;j >0;--j)
static int width
bitstream writer API