FFmpeg  4.0
magicyuvenc.c
Go to the documentation of this file.
1 /*
2  * MagicYUV encoder
3  * Copyright (c) 2017 Paul B Mahol
4  *
5  * This file is part of FFmpeg.
6  *
7  * FFmpeg is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU Lesser General Public
9  * License as published by the Free Software Foundation; either
10  * version 2.1 of the License, or (at your option) any later version.
11  *
12  * FFmpeg is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15  * Lesser General Public License for more details.
16  *
17  * You should have received a copy of the GNU Lesser General Public
18  * License along with FFmpeg; if not, write to the Free Software
19  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20  */
21 
22 #include <stdlib.h>
23 #include <string.h>
24 
25 #include "libavutil/opt.h"
26 #include "libavutil/pixdesc.h"
27 #include "libavutil/qsort.h"
28 
29 #include "avcodec.h"
30 #include "bytestream.h"
31 #include "put_bits.h"
32 #include "internal.h"
33 #include "thread.h"
34 #include "lossless_videoencdsp.h"
35 
36 typedef enum Prediction {
37  LEFT = 1,
40 } Prediction;
41 
42 typedef struct HuffEntry {
44  uint8_t len;
45  uint32_t code;
46 } HuffEntry;
47 
48 typedef struct PTable {
49  int value; ///< input value
50  int64_t prob; ///< number of occurences of this value in input
51 } PTable;
52 
53 typedef struct MagicYUVContext {
54  const AVClass *class;
57  int planes;
59  AVFrame *p;
60  int max;
61  int slice_height;
62  int nb_slices;
63  int correlate;
64  int hshift[4];
65  int vshift[4];
66  uint8_t *slices[4];
67  unsigned slice_pos[4];
68  unsigned tables_size;
69  HuffEntry he[4][256];
72  ptrdiff_t stride, int width, int height);
74 
76  uint8_t *src, uint8_t *dst, ptrdiff_t stride,
77  int width, int height)
78 {
79  uint8_t prev = 0;
80  int i, j;
81 
82  for (i = 0; i < width; i++) {
83  dst[i] = src[i] - prev;
84  prev = src[i];
85  }
86  dst += width;
87  src += stride;
88  for (j = 1; j < height; j++) {
89  prev = src[-stride];
90  for (i = 0; i < width; i++) {
91  dst[i] = src[i] - prev;
92  prev = src[i];
93  }
94  dst += width;
95  src += stride;
96  }
97 }
98 
100  uint8_t *src, uint8_t *dst, ptrdiff_t stride,
101  int width, int height)
102 {
103  int left = 0, top, lefttop;
104  int i, j;
105 
106  for (i = 0; i < width; i++) {
107  dst[i] = src[i] - left;
108  left = src[i];
109  }
110  dst += width;
111  src += stride;
112  for (j = 1; j < height; j++) {
113  top = src[-stride];
114  left = src[0] - top;
115  dst[0] = left;
116  for (i = 1; i < width; i++) {
117  top = src[i - stride];
118  lefttop = src[i - (stride + 1)];
119  left = src[i-1];
120  dst[i] = (src[i] - top) - left + lefttop;
121  }
122  dst += width;
123  src += stride;
124  }
125 }
126 
128  uint8_t *src, uint8_t *dst, ptrdiff_t stride,
129  int width, int height)
130 {
131  int left = 0, lefttop;
132  int i, j;
133 
134  for (i = 0; i < width; i++) {
135  dst[i] = src[i] - left;
136  left = src[i];
137  }
138  dst += width;
139  src += stride;
140  for (j = 1; j < height; j++) {
141  left = lefttop = src[-stride];
142  s->llvidencdsp.sub_median_pred(dst, src - stride, src, width, &left, &lefttop);
143  dst += width;
144  src += stride;
145  }
146 }
147 
149 {
150  MagicYUVContext *s = avctx->priv_data;
151  int i;
152 
153  switch (avctx->pix_fmt) {
154  case AV_PIX_FMT_GBRP:
155  avctx->codec_tag = MKTAG('M', '8', 'R', 'G');
156  s->correlate = 1;
157  s->format = 0x65;
158  break;
159  case AV_PIX_FMT_GBRAP:
160  avctx->codec_tag = MKTAG('M', '8', 'R', 'A');
161  s->correlate = 1;
162  s->format = 0x66;
163  break;
164  case AV_PIX_FMT_YUV420P:
165  avctx->codec_tag = MKTAG('M', '8', 'Y', '0');
166  s->hshift[1] =
167  s->vshift[1] =
168  s->hshift[2] =
169  s->vshift[2] = 1;
170  s->format = 0x69;
171  break;
172  case AV_PIX_FMT_YUV422P:
173  avctx->codec_tag = MKTAG('M', '8', 'Y', '2');
174  s->hshift[1] =
175  s->hshift[2] = 1;
176  s->format = 0x68;
177  break;
178  case AV_PIX_FMT_YUV444P:
179  avctx->codec_tag = MKTAG('M', '8', 'Y', '4');
180  s->format = 0x67;
181  break;
182  case AV_PIX_FMT_YUVA444P:
183  avctx->codec_tag = MKTAG('M', '8', 'Y', 'A');
184  s->format = 0x6a;
185  break;
186  case AV_PIX_FMT_GRAY8:
187  avctx->codec_tag = MKTAG('M', '8', 'G', '0');
188  s->format = 0x6b;
189  break;
190  default:
191  av_log(avctx, AV_LOG_ERROR, "Unsupported pixel format: %d\n",
192  avctx->pix_fmt);
193  return AVERROR_INVALIDDATA;
194  }
195 
197 
199 
200  s->nb_slices = 1;
201 
202  for (i = 0; i < s->planes; i++) {
203  s->slices[i] = av_malloc(avctx->width * (avctx->height + 2) +
205  if (!s->slices[i]) {
206  av_log(avctx, AV_LOG_ERROR, "Cannot allocate temporary buffer.\n");
207  return AVERROR(ENOMEM);
208  }
209  }
210 
211  switch (s->frame_pred) {
212  case LEFT: s->predict = left_predict; break;
213  case GRADIENT: s->predict = gradient_predict; break;
214  case MEDIAN: s->predict = median_predict; break;
215  }
216 
217  return 0;
218 }
219 
220 static int magy_huff_cmp_len(const void *a, const void *b)
221 {
222  const HuffEntry *aa = a, *bb = b;
223  return (aa->len - bb->len) * 256 + aa->sym - bb->sym;
224 }
225 
226 static int huff_cmp_sym(const void *a, const void *b)
227 {
228  const HuffEntry *aa = a, *bb = b;
229  return bb->sym - aa->sym;
230 }
231 
233 {
234  uint32_t code;
235  int i;
236 
238 
239  code = 1;
240  for (i = 255; i >= 0; i--) {
241  he[i].code = code >> (32 - he[i].len);
242  code += 0x80000000u >> (he[i].len - 1);
243  }
244 
245  AV_QSORT(he, 256, HuffEntry, huff_cmp_sym);
246 }
247 
248 static void count_usage(uint8_t *src, int width,
249  int height, PTable *counts)
250 {
251  int i, j;
252 
253  for (j = 0; j < height; j++) {
254  for (i = 0; i < width; i++) {
255  counts[src[i]].prob++;
256  }
257  src += width;
258  }
259 }
260 
261 typedef struct PackageMergerList {
262  int nitems; ///< number of items in the list and probability ex. 4
263  int item_idx[515]; ///< index range for each item in items 0, 2, 5, 9, 13
264  int probability[514]; ///< probability of each item 3, 8, 18, 46
265  int items[257 * 16]; ///< chain of all individual values that make up items A, B, A, B, C, A, B, C, D, C, D, D, E
267 
268 static int compare_by_prob(const void *a, const void *b)
269 {
270  PTable a_val = *(PTable *)a;
271  PTable b_val = *(PTable *)b;
272  return a_val.prob - b_val.prob;
273 }
274 
275 static void magy_huffman_compute_bits(PTable *prob_table, HuffEntry *distincts,
276  int size, int max_length)
277 {
278  PackageMergerList list_a, list_b, *to = &list_a, *from = &list_b, *temp;
279  int times, i, j, k;
280  int nbits[257] = {0};
281  int min;
282 
283  av_assert0(max_length > 0);
284 
285  to->nitems = 0;
286  from->nitems = 0;
287  to->item_idx[0] = 0;
288  from->item_idx[0] = 0;
289  AV_QSORT(prob_table, size, PTable, compare_by_prob);
290 
291  for (times = 0; times <= max_length; times++) {
292  to->nitems = 0;
293  to->item_idx[0] = 0;
294 
295  j = 0;
296  k = 0;
297 
298  if (times < max_length) {
299  i = 0;
300  }
301  while (i < size || j + 1 < from->nitems) {
302  to->nitems++;
303  to->item_idx[to->nitems] = to->item_idx[to->nitems - 1];
304  if (i < size &&
305  (j + 1 >= from->nitems ||
306  prob_table[i].prob <
307  from->probability[j] + from->probability[j + 1])) {
308  to->items[to->item_idx[to->nitems]++] = prob_table[i].value;
309  to->probability[to->nitems - 1] = prob_table[i].prob;
310  i++;
311  } else {
312  for (k = from->item_idx[j]; k < from->item_idx[j + 2]; k++) {
313  to->items[to->item_idx[to->nitems]++] = from->items[k];
314  }
315  to->probability[to->nitems - 1] =
316  from->probability[j] + from->probability[j + 1];
317  j += 2;
318  }
319  }
320  temp = to;
321  to = from;
322  from = temp;
323  }
324 
325  min = (size - 1 < from->nitems) ? size - 1 : from->nitems;
326  for (i = 0; i < from->item_idx[min]; i++) {
327  nbits[from->items[i]]++;
328  }
329 
330  for (i = 0; i < size; i++) {
331  distincts[i].sym = i;
332  distincts[i].len = nbits[i];
333  }
334 }
335 
336 static int encode_table(AVCodecContext *avctx, uint8_t *dst,
337  int width, int height,
338  PutBitContext *pb, HuffEntry *he)
339 {
340  PTable counts[256] = { {0} };
341  int i;
342 
343  count_usage(dst, width, height, counts);
344 
345  for (i = 0; i < 256; i++) {
346  counts[i].prob++;
347  counts[i].value = 255 - i;
348  }
349 
350  magy_huffman_compute_bits(counts, he, 256, 16);
351 
352  calculate_codes(he);
353 
354  for (i = 0; i < 256; i++) {
355  put_bits(pb, 1, 0);
356  put_bits(pb, 7, he[i].len);
357  }
358 
359  return 0;
360 }
361 
362 static int encode_slice(uint8_t *src, uint8_t *dst, int dst_size,
363  int width, int height, HuffEntry *he, int prediction)
364 {
365  PutBitContext pb;
366  int i, j;
367  int count;
368 
369  init_put_bits(&pb, dst, dst_size);
370 
371  put_bits(&pb, 8, 0);
372  put_bits(&pb, 8, prediction);
373 
374  for (j = 0; j < height; j++) {
375  for (i = 0; i < width; i++) {
376  const int idx = src[i];
377  put_bits(&pb, he[idx].len, he[idx].code);
378  }
379 
380  src += width;
381  }
382 
383  count = put_bits_count(&pb) & 0x1F;
384 
385  if (count)
386  put_bits(&pb, 32 - count, 0);
387 
388  count = put_bits_count(&pb);
389 
390  flush_put_bits(&pb);
391 
392  return count >> 3;
393 }
394 
396  const AVFrame *frame, int *got_packet)
397 {
398  MagicYUVContext *s = avctx->priv_data;
399  PutByteContext pb;
400  const int width = avctx->width, height = avctx->height;
401  int pos, slice, i, j, ret = 0;
402 
403  ret = ff_alloc_packet2(avctx, pkt, (256 + 4 * s->nb_slices + width * height) *
404  s->planes + 256, 0);
405  if (ret < 0)
406  return ret;
407 
408  bytestream2_init_writer(&pb, pkt->data, pkt->size);
409  bytestream2_put_le32(&pb, MKTAG('M', 'A', 'G', 'Y'));
410  bytestream2_put_le32(&pb, 32);
411  bytestream2_put_byte(&pb, 7);
412  bytestream2_put_byte(&pb, s->format);
413  bytestream2_put_byte(&pb, 0);
414  bytestream2_put_byte(&pb, 0);
415  bytestream2_put_le32(&pb, 0);
416 
417  bytestream2_put_le32(&pb, avctx->width);
418  bytestream2_put_le32(&pb, avctx->height);
419  bytestream2_put_le32(&pb, avctx->width);
420  bytestream2_put_le32(&pb, avctx->height);
421  bytestream2_put_le32(&pb, 0);
422 
423  for (i = 0; i < s->planes; i++) {
424  bytestream2_put_le32(&pb, 0);
425  for (j = 1; j < s->nb_slices; j++) {
426  bytestream2_put_le32(&pb, 0);
427  }
428  }
429 
430  bytestream2_put_byte(&pb, s->planes);
431 
432  for (i = 0; i < s->planes; i++) {
433  for (slice = 0; slice < s->nb_slices; slice++) {
434  bytestream2_put_byte(&pb, i);
435  }
436  }
437 
438  if (s->correlate) {
439  uint8_t *r, *g, *b;
440  AVFrame *p = av_frame_clone(frame);
441 
442  g = p->data[0];
443  b = p->data[1];
444  r = p->data[2];
445 
446  for (i = 0; i < height; i++) {
447  s->llvidencdsp.diff_bytes(b, b, g, width);
448  s->llvidencdsp.diff_bytes(r, r, g, width);
449  g += p->linesize[0];
450  b += p->linesize[1];
451  r += p->linesize[2];
452  }
453 
454  FFSWAP(uint8_t*, p->data[0], p->data[1]);
455  FFSWAP(int, p->linesize[0], p->linesize[1]);
456 
457  for (i = 0; i < s->planes; i++) {
458  for (slice = 0; slice < s->nb_slices; slice++) {
459  s->predict(s, p->data[i], s->slices[i], p->linesize[i],
460  p->width, p->height);
461  }
462  }
463 
464  av_frame_free(&p);
465  } else {
466  for (i = 0; i < s->planes; i++) {
467  for (slice = 0; slice < s->nb_slices; slice++) {
468  s->predict(s, frame->data[i], s->slices[i], frame->linesize[i],
469  AV_CEIL_RSHIFT(frame->width, s->hshift[i]),
470  AV_CEIL_RSHIFT(frame->height, s->vshift[i]));
471  }
472  }
473  }
474 
476 
477  for (i = 0; i < s->planes; i++) {
478  encode_table(avctx, s->slices[i],
479  AV_CEIL_RSHIFT(frame->width, s->hshift[i]),
480  AV_CEIL_RSHIFT(frame->height, s->vshift[i]),
481  &s->pb, s->he[i]);
482  }
483  s->tables_size = (put_bits_count(&s->pb) + 7) >> 3;
485 
486  for (i = 0; i < s->planes; i++) {
487  unsigned slice_size;
488 
489  s->slice_pos[i] = bytestream2_tell_p(&pb);
490  slice_size = encode_slice(s->slices[i], pkt->data + bytestream2_tell_p(&pb),
492  AV_CEIL_RSHIFT(frame->width, s->hshift[i]),
493  AV_CEIL_RSHIFT(frame->height, s->vshift[i]),
494  s->he[i], s->frame_pred);
495  bytestream2_skip_p(&pb, slice_size);
496  }
497 
498  pos = bytestream2_tell_p(&pb);
499  bytestream2_seek_p(&pb, 32, SEEK_SET);
500  bytestream2_put_le32(&pb, s->slice_pos[0] - 32);
501  for (i = 0; i < s->planes; i++) {
502  bytestream2_put_le32(&pb, s->slice_pos[i] - 32);
503  }
504  bytestream2_seek_p(&pb, pos, SEEK_SET);
505 
506  pkt->size = bytestream2_tell_p(&pb);
507  pkt->flags |= AV_PKT_FLAG_KEY;
508 
509  *got_packet = 1;
510 
511  return 0;
512 }
513 
515 {
516  MagicYUVContext *s = avctx->priv_data;
517  int i;
518 
519  for (i = 0; i < s->planes; i++)
520  av_freep(&s->slices[i]);
521 
522  return 0;
523 }
524 
525 #define OFFSET(x) offsetof(MagicYUVContext, x)
526 #define VE AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_ENCODING_PARAM
527 static const AVOption options[] = {
528  { "pred", "Prediction method", OFFSET(frame_pred), AV_OPT_TYPE_INT, {.i64=LEFT}, LEFT, MEDIAN, VE, "pred" },
529  { "left", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = LEFT }, 0, 0, VE, "pred" },
530  { "gradient", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = GRADIENT }, 0, 0, VE, "pred" },
531  { "median", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = MEDIAN }, 0, 0, VE, "pred" },
532  { NULL},
533 };
534 
535 static const AVClass magicyuv_class = {
536  .class_name = "magicyuv",
537  .item_name = av_default_item_name,
538  .option = options,
539  .version = LIBAVUTIL_VERSION_INT,
540 };
541 
543  .name = "magicyuv",
544  .long_name = NULL_IF_CONFIG_SMALL("MagicYUV video"),
545  .type = AVMEDIA_TYPE_VIDEO,
546  .id = AV_CODEC_ID_MAGICYUV,
547  .priv_data_size = sizeof(MagicYUVContext),
548  .priv_class = &magicyuv_class,
550  .close = magy_encode_close,
551  .encode2 = magy_encode_frame,
553  .pix_fmts = (const enum AVPixelFormat[]) {
557  },
558 };
#define NULL
Definition: coverity.c:32
#define OFFSET(x)
Definition: magicyuvenc.c:525
const char * s
Definition: avisynth_c.h:768
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
Definition: error.h:59
int size
This structure describes decoded (raw) audio or video data.
Definition: frame.h:218
AVOption.
Definition: opt.h:246
static const AVOption options[]
Definition: magicyuvenc.c:527
static void calculate_codes(HuffEntry *he)
Definition: magicyuvenc.c:232
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:207
int av_pix_fmt_count_planes(enum AVPixelFormat pix_fmt)
Definition: pixdesc.c:2403
#define LIBAVUTIL_VERSION_INT
Definition: version.h:85
else temp
Definition: vf_mcdeint.c:256
const char * g
Definition: vf_curves.c:112
static av_cold int init(AVCodecContext *avctx)
Definition: avrndec.c:35
planar GBR 4:4:4 24bpp
Definition: pixfmt.h:164
int size
Definition: avcodec.h:1431
const char * b
Definition: vf_curves.c:113
static av_always_inline void bytestream2_init_writer(PutByteContext *p, uint8_t *buf, int buf_size)
Definition: bytestream.h:143
const char * av_default_item_name(void *ptr)
Return the context name.
Definition: log.c:191
unsigned tables_size
Definition: magicyuvenc.c:68
enum AVPixelFormat pix_fmt
Pixel format, see AV_PIX_FMT_xxx.
Definition: avcodec.h:1727
#define AV_CODEC_CAP_EXPERIMENTAL
Codec is experimental and is thus avoided in favor of non experimental encoders.
Definition: avcodec.h:1007
static void left_predict(MagicYUVContext *s, uint8_t *src, uint8_t *dst, ptrdiff_t stride, int width, int height)
Definition: magicyuvenc.c:75
static AVPacket pkt
static av_always_inline void predict(PredictorState *ps, float *coef, int output_enable)
Definition: aacdec.c:174
#define src
Definition: vp8dsp.c:254
int stride
Definition: mace.c:144
AVCodec.
Definition: avcodec.h:3408
#define AV_CODEC_CAP_INTRA_ONLY
Codec is intra only.
Definition: avcodec.h:1045
av_cold void ff_llvidencdsp_init(LLVidEncDSPContext *c)
unsigned slice_pos[4]
Definition: magicyuvenc.c:67
PutBitContext pb
Definition: magicyuvenc.c:56
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 value
input value
Definition: magicyuvenc.c:49
#define av_assert0(cond)
assert() equivalent, that is always enabled.
Definition: avassert.h:37
int ff_alloc_packet2(AVCodecContext *avctx, AVPacket *avpkt, int64_t size, int64_t min_size)
Check AVPacket size and/or allocate data.
Definition: encode.c:32
uint8_t
#define av_cold
Definition: attributes.h:82
#define av_malloc(s)
AVOptions.
Multithreading support functions.
const char * from
Definition: jacosubdec.c:65
static av_cold int magy_encode_init(AVCodecContext *avctx)
Definition: magicyuvenc.c:148
#define u(width, name, range_min, range_max)
Definition: cbs_h2645.c:344
HuffEntry he[4][256]
Definition: magicyuvenc.c:69
static AVFrame * frame
void(* diff_bytes)(uint8_t *dst, const uint8_t *src1, const uint8_t *src2, intptr_t w)
#define height
uint8_t * data
Definition: avcodec.h:1430
static int encode_table(AVCodecContext *avctx, uint8_t *dst, int width, int height, PutBitContext *pb, HuffEntry *he)
Definition: magicyuvenc.c:336
#define VE
Definition: magicyuvenc.c:526
int hshift[4]
Definition: magicyuv.c:65
uint32_t code
Definition: magicyuv.c:50
int nitems
number of items in the list and probability ex. 4
Definition: magicyuvenc.c:262
#define av_log(a,...)
const char * to
Definition: webvttdec.c:34
#define AV_PKT_FLAG_KEY
The packet contains a keyframe.
Definition: avcodec.h:1462
static void median_predict(MagicYUVContext *s, uint8_t *src, uint8_t *dst, ptrdiff_t stride, int width, int height)
Definition: magicyuvenc.c:127
int width
Definition: frame.h:276
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition: log.h:176
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&#39;s variant of median prediction.
static void magy_huffman_compute_bits(PTable *prob_table, HuffEntry *distincts, int size, int max_length)
Definition: magicyuvenc.c:275
void(* predict)(struct MagicYUVContext *s, uint8_t *src, uint8_t *dst, ptrdiff_t stride, int width, int height)
Definition: magicyuvenc.c:71
static av_always_inline unsigned int bytestream2_get_bytes_left_p(PutByteContext *p)
Definition: bytestream.h:159
static av_cold int magy_encode_close(AVCodecContext *avctx)
Definition: magicyuvenc.c:514
#define AVERROR(e)
Definition: error.h:43
void av_frame_free(AVFrame **frame)
Free the frame and any dynamically allocated objects in it, e.g.
Definition: frame.c:202
uint8_t sym
Definition: magicyuvenc.c:43
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification. ...
Definition: internal.h:186
const char * r
Definition: vf_curves.c:111
uint16_t width
Definition: gdv.c:47
const char * name
Name of the codec implementation.
Definition: avcodec.h:3415
int64_t prob
number of occurences of this value in input
Definition: magicyuvenc.c:50
static av_always_inline int bytestream2_tell_p(PutByteContext *p)
Definition: bytestream.h:193
#define AV_CODEC_CAP_FRAME_THREADS
Codec supports frame-level multithreading.
Definition: avcodec.h:1015
int flags
A combination of AV_PKT_FLAG values.
Definition: avcodec.h:1436
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
Slice * slices[4]
Definition: magicyuv.c:67
LLVidEncDSPContext llvidencdsp
Definition: magicyuvenc.c:70
static av_always_inline void bytestream2_skip_p(PutByteContext *p, unsigned int size)
Definition: bytestream.h:176
static void gradient_predict(MagicYUVContext *s, uint8_t *src, uint8_t *dst, ptrdiff_t stride, int width, int height)
Definition: magicyuvenc.c:99
int item_idx[515]
index range for each item in items 0, 2, 5, 9, 13
Definition: magicyuvenc.c:263
int vshift[4]
Definition: magicyuv.c:66
static int encode_slice(uint8_t *src, uint8_t *dst, int dst_size, int width, int height, HuffEntry *he, int prediction)
Definition: magicyuvenc.c:362
int width
picture width / height.
Definition: avcodec.h:1690
static int magy_encode_frame(AVCodecContext *avctx, AVPacket *pkt, const AVFrame *frame, int *got_packet)
Definition: magicyuvenc.c:395
AVCodec ff_magicyuv_encoder
Definition: magicyuvenc.c:542
AVFrame * av_frame_clone(const AVFrame *src)
Create a new frame that references the same data as src.
Definition: frame.c:538
Used to store intermediate lists in the package merge algorithm.
Definition: magicyuvenc.c:261
static av_always_inline int bytestream2_seek_p(PutByteContext *p, int offset, int whence)
Definition: bytestream.h:232
static int compare_by_prob(const void *a, const void *b)
Definition: magicyuvenc.c:268
uint8_t len
Definition: magicyuv.c:49
Libavcodec external API header.
typedef void(RENAME(mix_any_func_type))
int linesize[AV_NUM_DATA_POINTERS]
For video, size in bytes of each picture line.
Definition: frame.h:249
planar YUV 4:4:4 32bpp, (1 Cr & Cb sample per 1x1 Y & A samples)
Definition: pixfmt.h:173
main external API structure.
Definition: avcodec.h:1518
Used to assign a occurrence count or "probability" to an input value.
Definition: magicyuvenc.c:48
unsigned int codec_tag
fourcc (LSB first, so "ABCD" -> (&#39;D&#39;<<24) + (&#39;C&#39;<<16) + (&#39;B&#39;<<8) + &#39;A&#39;).
Definition: avcodec.h:1543
Describe the class of an AVClass context structure.
Definition: log.h:67
static enum AVPixelFormat pix_fmts[]
Definition: libkvazaar.c:266
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
Definition: frame.h:232
int probability[514]
probability of each item 3, 8, 18, 46
Definition: magicyuvenc.c:264
uint8_t format
Definition: magicyuvenc.c:58
static int huff_cmp_sym(const void *a, const void *b)
Definition: magicyuvenc.c:226
planar YUV 4:2:0, 12bpp, (1 Cr & Cb sample per 2x2 Y samples)
Definition: pixfmt.h:62
Y , 8bpp.
Definition: pixfmt.h:70
common internal api header.
Prediction
Definition: magicyuvenc.c:36
static void flush_put_bits(PutBitContext *s)
Pad the end of the output stream with zeros.
Definition: put_bits.h:101
planar GBRA 4:4:4:4 32bpp
Definition: pixfmt.h:211
static int magy_huff_cmp_len(const void *a, const void *b)
Definition: magicyuvenc.c:220
uint16_t sym
Definition: magicyuv.c:48
static void init_put_bits(PutBitContext *s, uint8_t *buffer, int buffer_size)
Initialize the PutBitContext s.
Definition: put_bits.h:48
static const struct @272 planes[]
#define AV_INPUT_BUFFER_PADDING_SIZE
Required number of additionally allocated bytes at the end of the input bitstream for decoding...
Definition: avcodec.h:773
static const AVClass magicyuv_class
Definition: magicyuvenc.c:535
void * priv_data
Definition: avcodec.h:1545
static void count_usage(uint8_t *src, int width, int height, PTable *counts)
Definition: magicyuvenc.c:248
int items[257 *16]
chain of all individual values that make up items A, B, A, B, C, A, B, C, D, C, D, D, E
Definition: magicyuvenc.c:265
int height
Definition: frame.h:276
#define av_freep(p)
void INT64 INT64 count
Definition: avisynth_c.h:690
#define FFSWAP(type, a, b)
Definition: common.h:99
#define MKTAG(a, b, c, d)
Definition: common.h:366
float min
AVPixelFormat
Pixel format.
Definition: pixfmt.h:60
This structure stores compressed data.
Definition: avcodec.h:1407
#define AV_QSORT(p, num, type, cmp)
Quicksort This sort is fast, and fully inplace but not stable and it is possible to construct input t...
Definition: qsort.h:33
for(j=16;j >0;--j)
#define AV_CEIL_RSHIFT(a, b)
Definition: common.h:58
bitstream writer API