FFmpeg
scpr.c
Go to the documentation of this file.
1 /*
2  * ScreenPressor decoder
3  *
4  * Copyright (c) 2017 Paul B Mahol
5  *
6  * This file is part of FFmpeg.
7  *
8  * FFmpeg is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU Lesser General Public
10  * License as published by the Free Software Foundation; either
11  * version 2.1 of the License, or (at your option) any later version.
12  *
13  * FFmpeg is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16  * Lesser General Public License for more details.
17  *
18  * You should have received a copy of the GNU Lesser General Public
19  * License along with FFmpeg; if not, write to the Free Software
20  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
21  */
22 
23 #include <string.h>
24 
25 #include "avcodec.h"
26 #include "bytestream.h"
27 #include "codec_internal.h"
28 #include "decode.h"
29 #include "scpr.h"
30 #include "scpr3.h"
31 
32 #define TOP 0x01000000
33 #define BOT 0x010000
34 
35 #include "scpr3.c"
36 
38 {
39  rc->code1 = 0;
40  rc->range = 0xFFFFFFFFU;
41  rc->code = bytestream2_get_be32(gb);
42 }
43 
45 {
46  int comp, i, j;
47 
48  for (comp = 0; comp < 3; comp++) {
49  for (j = 0; j < 4096; j++) {
50  if (s->pixel_model[comp][j].total_freq != 256) {
51  for (i = 0; i < 256; i++)
52  s->pixel_model[comp][j].freq[i] = 1;
53  for (i = 0; i < 16; i++)
54  s->pixel_model[comp][j].lookup[i] = 16;
55  s->pixel_model[comp][j].total_freq = 256;
56  }
57  }
58  }
59 
60  for (j = 0; j < 6; j++) {
61  uint32_t *p = s->run_model[j];
62  for (i = 0; i < 256; i++)
63  p[i] = 1;
64  p[256] = 256;
65  }
66 
67  for (j = 0; j < 6; j++) {
68  uint32_t *op = s->op_model[j];
69  for (i = 0; i < 6; i++)
70  op[i] = 1;
71  op[6] = 6;
72  }
73 
74  for (i = 0; i < 256; i++) {
75  s->range_model[i] = 1;
76  s->count_model[i] = 1;
77  }
78  s->range_model[256] = 256;
79  s->count_model[256] = 256;
80 
81  for (i = 0; i < 5; i++) {
82  s->fill_model[i] = 1;
83  }
84  s->fill_model[5] = 5;
85 
86  for (j = 0; j < 4; j++) {
87  for (i = 0; i < 16; i++) {
88  s->sxy_model[j][i] = 1;
89  }
90  s->sxy_model[j][16] = 16;
91  }
92 
93  for (i = 0; i < 512; i++) {
94  s->mv_model[0][i] = 1;
95  s->mv_model[1][i] = 1;
96  }
97  s->mv_model[0][512] = 512;
98  s->mv_model[1][512] = 512;
99 }
100 
101 static int decode(GetByteContext *gb, RangeCoder *rc, uint32_t cumFreq, uint32_t freq, uint32_t total_freq)
102 {
103  rc->code -= cumFreq * rc->range;
104  rc->range *= freq;
105 
106  while (rc->range < TOP && bytestream2_get_bytes_left(gb) > 0) {
107  uint32_t byte = bytestream2_get_byteu(gb);
108  rc->code = (rc->code << 8) | byte;
109  rc->range <<= 8;
110  }
111 
112  return 0;
113 }
114 
115 static int get_freq(RangeCoder *rc, uint32_t total_freq, uint32_t *freq)
116 {
117  if (total_freq == 0)
118  return AVERROR_INVALIDDATA;
119 
120  rc->range = rc->range / total_freq;
121 
122  if (rc->range == 0)
123  return AVERROR_INVALIDDATA;
124 
125  *freq = rc->code / rc->range;
126 
127  return 0;
128 }
129 
130 static int decode0(GetByteContext *gb, RangeCoder *rc, uint32_t cumFreq, uint32_t freq, uint32_t total_freq)
131 {
132  uint32_t t;
133 
134  if (total_freq == 0)
135  return AVERROR_INVALIDDATA;
136 
137  t = rc->range * (uint64_t)cumFreq / total_freq;
138 
139  rc->code1 += t + 1;
140  rc->range = rc->range * (uint64_t)(freq + cumFreq) / total_freq - (t + 1);
141 
142  while (rc->range < TOP && bytestream2_get_bytes_left(gb) > 0) {
143  uint32_t byte = bytestream2_get_byteu(gb);
144  rc->code = (rc->code << 8) | byte;
145  rc->code1 <<= 8;
146  rc->range <<= 8;
147  }
148 
149  return 0;
150 }
151 
152 static int get_freq0(RangeCoder *rc, uint32_t total_freq, uint32_t *freq)
153 {
154  if (rc->range == 0)
155  return AVERROR_INVALIDDATA;
156 
157  *freq = total_freq * (uint64_t)(rc->code - rc->code1) / rc->range;
158 
159  return 0;
160 }
161 
162 static int decode_value(SCPRContext *s, uint32_t *cnt, uint32_t maxc, uint32_t step, uint32_t *rval)
163 {
164  GetByteContext *gb = &s->gb;
165  RangeCoder *rc = &s->rc;
166  uint32_t totfr = cnt[maxc];
167  uint32_t value;
168  uint32_t c = 0, cumfr = 0, cnt_c = 0;
169  int i, ret;
170 
171  if ((ret = s->get_freq(rc, totfr, &value)) < 0)
172  return ret;
173 
174  while (c < maxc) {
175  cnt_c = cnt[c];
176  if (value >= cumfr + cnt_c)
177  cumfr += cnt_c;
178  else
179  break;
180  c++;
181  }
182 
183  if (c >= maxc)
184  return AVERROR_INVALIDDATA;
185 
186  if ((ret = s->decode(gb, rc, cumfr, cnt_c, totfr)) < 0)
187  return ret;
188 
189  cnt[c] = cnt_c + step;
190  totfr += step;
191  if (totfr > BOT) {
192  totfr = 0;
193  for (i = 0; i < maxc; i++) {
194  uint32_t nc = (cnt[i] >> 1) + 1;
195  cnt[i] = nc;
196  totfr += nc;
197  }
198  }
199 
200  cnt[maxc] = totfr;
201  *rval = c;
202 
203  return 0;
204 }
205 
206 static int decode_unit(SCPRContext *s, PixelModel *pixel, uint32_t step, uint32_t *rval)
207 {
208  GetByteContext *gb = &s->gb;
209  RangeCoder *rc = &s->rc;
210  uint32_t totfr = pixel->total_freq;
211  uint32_t value, x = 0, cumfr = 0, cnt_x = 0;
212  int i, j, ret, c, cnt_c;
213 
214  if ((ret = s->get_freq(rc, totfr, &value)) < 0)
215  return ret;
216 
217  while (x < 16) {
218  cnt_x = pixel->lookup[x];
219  if (value >= cumfr + cnt_x)
220  cumfr += cnt_x;
221  else
222  break;
223  x++;
224  }
225 
226  c = x * 16;
227  cnt_c = 0;
228  while (c < 256) {
229  cnt_c = pixel->freq[c];
230  if (value >= cumfr + cnt_c)
231  cumfr += cnt_c;
232  else
233  break;
234  c++;
235  }
236  if (x >= 16 || c >= 256) {
237  return AVERROR_INVALIDDATA;
238  }
239 
240  if ((ret = s->decode(gb, rc, cumfr, cnt_c, totfr)) < 0)
241  return ret;
242 
243  pixel->freq[c] = cnt_c + step;
244  pixel->lookup[x] = cnt_x + step;
245  totfr += step;
246  if (totfr > BOT) {
247  totfr = 0;
248  for (i = 0; i < 256; i++) {
249  uint32_t nc = (pixel->freq[i] >> 1) + 1;
250  pixel->freq[i] = nc;
251  totfr += nc;
252  }
253  for (i = 0; i < 16; i++) {
254  uint32_t sum = 0;
255  uint32_t i16_17 = i << 4;
256  for (j = 0; j < 16; j++)
257  sum += pixel->freq[i16_17 + j];
258  pixel->lookup[i] = sum;
259  }
260  }
261  pixel->total_freq = totfr;
262 
263  *rval = c & s->cbits;
264 
265  return 0;
266 }
267 
268 static int decode_units(SCPRContext *s, uint32_t *r, uint32_t *g, uint32_t *b,
269  int *cx, int *cx1)
270 {
271  const int cxshift = s->cxshift;
272  int ret;
273 
274  ret = decode_unit(s, &s->pixel_model[0][*cx + *cx1], 400, r);
275  if (ret < 0)
276  return ret;
277 
278  *cx1 = (*cx << 6) & 0xFC0;
279  *cx = *r >> cxshift;
280  ret = decode_unit(s, &s->pixel_model[1][*cx + *cx1], 400, g);
281  if (ret < 0)
282  return ret;
283 
284  *cx1 = (*cx << 6) & 0xFC0;
285  *cx = *g >> cxshift;
286  ret = decode_unit(s, &s->pixel_model[2][*cx + *cx1], 400, b);
287  if (ret < 0)
288  return ret;
289 
290  *cx1 = (*cx << 6) & 0xFC0;
291  *cx = *b >> cxshift;
292 
293  return 0;
294 }
295 
296 static int decompress_i(AVCodecContext *avctx, uint32_t *dst, int linesize)
297 {
298  SCPRContext *s = avctx->priv_data;
299  GetByteContext *gb = &s->gb;
300  int cx = 0, cx1 = 0, k = 0;
301  int run, off, y = 0, x = 0, ret;
302  uint32_t clr = 0, r, g, b, backstep = linesize - avctx->width;
303  uint32_t lx, ly, ptype;
304 
305  reinit_tables(s);
306  bytestream2_skip(gb, 2);
307  init_rangecoder(&s->rc, gb);
308 
309  while (k < avctx->width + 1) {
310  ret = decode_units(s, &r, &g, &b, &cx, &cx1);
311  if (ret < 0)
312  return ret;
313 
314  ret = decode_value(s, s->run_model[0], 256, 400, &run);
315  if (ret < 0)
316  return ret;
317  if (run <= 0)
318  return AVERROR_INVALIDDATA;
319 
320  clr = (b << 16) + (g << 8) + r;
321  k += run;
322  while (run-- > 0) {
323  if (y >= avctx->height)
324  return AVERROR_INVALIDDATA;
325 
326  dst[y * linesize + x] = clr;
327  lx = x;
328  ly = y;
329  x++;
330  if (x >= avctx->width) {
331  x = 0;
332  y++;
333  }
334  }
335  }
336  off = -linesize - 1;
337  ptype = 0;
338 
339  while (x < avctx->width && y < avctx->height) {
340  ret = decode_value(s, s->op_model[ptype], 6, 1000, &ptype);
341  if (ret < 0)
342  return ret;
343  if (ptype == 0) {
344  ret = decode_units(s, &r, &g, &b, &cx, &cx1);
345  if (ret < 0)
346  return ret;
347 
348  clr = (b << 16) + (g << 8) + r;
349  }
350  if (ptype > 5)
351  return AVERROR_INVALIDDATA;
352  ret = decode_value(s, s->run_model[ptype], 256, 400, &run);
353  if (ret < 0)
354  return ret;
355  if (run <= 0)
356  return AVERROR_INVALIDDATA;
357 
358  ret = decode_run_i(avctx, ptype, run, &x, &y, clr,
359  dst, linesize, &lx, &ly,
360  backstep, off, &cx, &cx1);
361  if (ret < 0)
362  return ret;
363  }
364 
365  return 0;
366 }
367 
368 static int decompress_p(AVCodecContext *avctx,
369  uint32_t *dst, int linesize,
370  uint32_t *prev, int plinesize)
371 {
372  SCPRContext *s = avctx->priv_data;
373  GetByteContext *gb = &s->gb;
374  int ret, temp = 0, min, max, x, y, cx = 0, cx1 = 0;
375  int backstep = linesize - avctx->width;
376 
377  if (bytestream2_get_byte(gb) == 0)
378  return 1;
379  bytestream2_skip(gb, 1);
380  init_rangecoder(&s->rc, gb);
381 
382  ret = decode_value(s, s->range_model, 256, 1, &min);
383  ret |= decode_value(s, s->range_model, 256, 1, &temp);
384  if (ret < 0)
385  return ret;
386 
387  min += temp << 8;
388  ret = decode_value(s, s->range_model, 256, 1, &max);
389  ret |= decode_value(s, s->range_model, 256, 1, &temp);
390  if (ret < 0)
391  return ret;
392 
393  max += temp << 8;
394  if (min > max || min >= s->nbcount)
395  return AVERROR_INVALIDDATA;
396 
397  memset(s->blocks, 0, sizeof(*s->blocks) * s->nbcount);
398 
399  while (min <= max) {
400  int fill, count;
401 
402  ret = decode_value(s, s->fill_model, 5, 10, &fill);
403  ret |= decode_value(s, s->count_model, 256, 20, &count);
404  if (ret < 0)
405  return ret;
406  if (count <= 0)
407  return AVERROR_INVALIDDATA;
408 
409  while (min < s->nbcount && count-- > 0) {
410  s->blocks[min++] = fill;
411  }
412  }
413 
414  ret = av_frame_copy(s->current_frame, s->last_frame);
415  if (ret < 0)
416  return ret;
417 
418  for (y = 0; y < s->nby; y++) {
419  for (x = 0; x < s->nbx; x++) {
420  int sy1 = 0, sy2 = 16, sx1 = 0, sx2 = 16;
421 
422  if (s->blocks[y * s->nbx + x] == 0)
423  continue;
424 
425  if (((s->blocks[y * s->nbx + x] - 1) & 1) > 0) {
426  ret = decode_value(s, s->sxy_model[0], 16, 100, &sx1);
427  ret |= decode_value(s, s->sxy_model[1], 16, 100, &sy1);
428  ret |= decode_value(s, s->sxy_model[2], 16, 100, &sx2);
429  ret |= decode_value(s, s->sxy_model[3], 16, 100, &sy2);
430  if (ret < 0)
431  return ret;
432 
433  sx2++;
434  sy2++;
435  }
436  if (((s->blocks[y * s->nbx + x] - 1) & 2) > 0) {
437  int i, j, by = y * 16, bx = x * 16;
438  int mvx, mvy;
439 
440  ret = decode_value(s, s->mv_model[0], 512, 100, &mvx);
441  ret |= decode_value(s, s->mv_model[1], 512, 100, &mvy);
442  if (ret < 0)
443  return ret;
444 
445  mvx -= 256;
446  mvy -= 256;
447 
448  if (by + mvy + sy1 < 0 || bx + mvx + sx1 < 0 ||
449  by + mvy + sy1 >= avctx->height || bx + mvx + sx1 >= avctx->width)
450  return AVERROR_INVALIDDATA;
451 
452  for (i = 0; i < sy2 - sy1 && (by + sy1 + i) < avctx->height && (by + mvy + sy1 + i) < avctx->height; i++) {
453  for (j = 0; j < sx2 - sx1 && (bx + sx1 + j) < avctx->width && (bx + mvx + sx1 + j) < avctx->width; j++) {
454  dst[(by + i + sy1) * linesize + bx + sx1 + j] = prev[(by + mvy + sy1 + i) * plinesize + bx + sx1 + mvx + j];
455  }
456  }
457  } else {
458  int run, bx = x * 16 + sx1, by = y * 16 + sy1;
459  uint32_t r, g, b, clr, ptype = 0;
460 
461  if (bx >= avctx->width)
462  return AVERROR_INVALIDDATA;
463 
464  for (; by < y * 16 + sy2 && by < avctx->height;) {
465  ret = decode_value(s, s->op_model[ptype], 6, 1000, &ptype);
466  if (ret < 0)
467  return ret;
468  if (ptype == 0) {
469  ret = decode_units(s, &r, &g, &b, &cx, &cx1);
470  if (ret < 0)
471  return ret;
472 
473  clr = (b << 16) + (g << 8) + r;
474  }
475  if (ptype > 5)
476  return AVERROR_INVALIDDATA;
477  ret = decode_value(s, s->run_model[ptype], 256, 400, &run);
478  if (ret < 0)
479  return ret;
480  if (run <= 0)
481  return AVERROR_INVALIDDATA;
482 
483  ret = decode_run_p(avctx, ptype, run, x, y, clr,
484  dst, prev, linesize, plinesize, &bx, &by,
485  backstep, sx1, sx2, &cx, &cx1);
486  if (ret < 0)
487  return ret;
488  }
489  }
490  }
491  }
492 
493  return 0;
494 }
495 
497  int *got_frame, AVPacket *avpkt)
498 {
499  SCPRContext *s = avctx->priv_data;
500  GetByteContext *gb = &s->gb;
501  int ret, type;
502 
503  if (avctx->bits_per_coded_sample == 16) {
504  if ((ret = ff_get_buffer(avctx, frame, 0)) < 0)
505  return ret;
506  }
507 
508  if ((ret = ff_reget_buffer(avctx, s->current_frame, 0)) < 0)
509  return ret;
510 
511  bytestream2_init(gb, avpkt->data, avpkt->size);
512 
513  type = bytestream2_peek_byte(gb);
514 
515  if (type == 2) {
516  s->version = 1;
517  s->get_freq = get_freq0;
518  s->decode = decode0;
519  frame->key_frame = 1;
520  ret = decompress_i(avctx, (uint32_t *)s->current_frame->data[0],
521  s->current_frame->linesize[0] / 4);
522  } else if (type == 18) {
523  s->version = 2;
524  s->get_freq = get_freq;
525  s->decode = decode;
526  frame->key_frame = 1;
527  ret = decompress_i(avctx, (uint32_t *)s->current_frame->data[0],
528  s->current_frame->linesize[0] / 4);
529  } else if (type == 34) {
530  frame->key_frame = 1;
531  s->version = 3;
532  ret = decompress_i3(avctx, (uint32_t *)s->current_frame->data[0],
533  s->current_frame->linesize[0] / 4);
534  } else if (type == 17 || type == 33) {
535  uint32_t clr, *dst = (uint32_t *)s->current_frame->data[0];
536  int y;
537 
539  return AVERROR_INVALIDDATA;
540 
541  frame->key_frame = 1;
542  bytestream2_skip(gb, 1);
543  if (avctx->bits_per_coded_sample == 16) {
544  uint16_t value = bytestream2_get_le16(gb);
545  int r, g, b;
546 
547  r = (value ) & 31;
548  g = (value >> 5) & 31;
549  b = (value >> 10) & 31;
550  clr = (r << 16) + (g << 8) + b;
551  } else {
552  clr = bytestream2_get_le24(gb);
553  }
554  for (y = 0; y < avctx->height; y++) {
555  dst[0] = clr;
556  av_memcpy_backptr((uint8_t*)(dst+1), 4, 4*avctx->width - 4);
557  dst += s->current_frame->linesize[0] / 4;
558  }
559  } else if (type == 0 || type == 1) {
560  frame->key_frame = 0;
561 
562  if (s->version == 1 || s->version == 2)
563  ret = decompress_p(avctx, (uint32_t *)s->current_frame->data[0],
564  s->current_frame->linesize[0] / 4,
565  (uint32_t *)s->last_frame->data[0],
566  s->last_frame->linesize[0] / 4);
567  else
568  ret = decompress_p3(avctx, (uint32_t *)s->current_frame->data[0],
569  s->current_frame->linesize[0] / 4,
570  (uint32_t *)s->last_frame->data[0],
571  s->last_frame->linesize[0] / 4);
572  if (ret == 1)
573  return avpkt->size;
574  } else {
575  return AVERROR_PATCHWELCOME;
576  }
577 
578  if (ret < 0)
579  return ret;
580 
581  if (bytestream2_get_bytes_left(gb) > 5)
582  return AVERROR_INVALIDDATA;
583 
584  if (avctx->bits_per_coded_sample != 16) {
585  ret = av_frame_ref(frame, s->current_frame);
586  if (ret < 0)
587  return ret;
588  } else {
589  uint8_t *dst = frame->data[0];
590  int x, y;
591 
592  ret = av_frame_copy(frame, s->current_frame);
593  if (ret < 0)
594  return ret;
595 
596  // scale up each sample by 8
597  for (y = 0; y < avctx->height; y++) {
598  // If the image is sufficiently aligned, compute 8 samples at once
599  if (!(((uintptr_t)dst) & 7)) {
600  uint64_t *dst64 = (uint64_t *)dst;
601  int w = avctx->width>>1;
602  for (x = 0; x < w; x++) {
603  dst64[x] = (dst64[x] << 3) & 0xFCFCFCFCFCFCFCFCULL;
604  }
605  x *= 8;
606  } else
607  x = 0;
608  for (; x < avctx->width * 4; x++) {
609  dst[x] = dst[x] << 3;
610  }
611  dst += frame->linesize[0];
612  }
613  }
614 
615  frame->pict_type = frame->key_frame ? AV_PICTURE_TYPE_I : AV_PICTURE_TYPE_P;
616 
617  FFSWAP(AVFrame *, s->current_frame, s->last_frame);
618 
619  frame->data[0] += frame->linesize[0] * (avctx->height - 1);
620  frame->linesize[0] *= -1;
621 
622  *got_frame = 1;
623 
624  return avpkt->size;
625 }
626 
628 {
629  SCPRContext *s = avctx->priv_data;
630 
631  switch (avctx->bits_per_coded_sample) {
632  case 16: avctx->pix_fmt = AV_PIX_FMT_RGB0; break;
633  case 24:
634  case 32: avctx->pix_fmt = AV_PIX_FMT_BGR0; break;
635  default:
636  av_log(avctx, AV_LOG_ERROR, "Unsupported bitdepth %i\n", avctx->bits_per_coded_sample);
637  return AVERROR_INVALIDDATA;
638  }
639 
640  s->get_freq = get_freq0;
641  s->decode = decode0;
642 
643  s->cxshift = avctx->bits_per_coded_sample == 16 ? 0 : 2;
644  s->cbits = avctx->bits_per_coded_sample == 16 ? 0x1F : 0xFF;
645  s->nbx = (avctx->width + 15) / 16;
646  s->nby = (avctx->height + 15) / 16;
647  s->nbcount = s->nbx * s->nby;
648  s->blocks = av_malloc_array(s->nbcount, sizeof(*s->blocks));
649  if (!s->blocks)
650  return AVERROR(ENOMEM);
651 
652  s->last_frame = av_frame_alloc();
653  s->current_frame = av_frame_alloc();
654  if (!s->last_frame || !s->current_frame)
655  return AVERROR(ENOMEM);
656 
657  return 0;
658 }
659 
661 {
662  SCPRContext *s = avctx->priv_data;
663 
664  av_freep(&s->blocks);
665  av_frame_free(&s->last_frame);
666  av_frame_free(&s->current_frame);
667 
668  return 0;
669 }
670 
672  .p.name = "scpr",
673  CODEC_LONG_NAME("ScreenPressor"),
674  .p.type = AVMEDIA_TYPE_VIDEO,
675  .p.id = AV_CODEC_ID_SCPR,
676  .priv_data_size = sizeof(SCPRContext),
677  .init = decode_init,
678  .close = decode_close,
680  .p.capabilities = AV_CODEC_CAP_DR1,
681  .caps_internal = FF_CODEC_CAP_INIT_CLEANUP,
682 };
RangeCoder::range
uint32_t range
Definition: mss3.c:65
TOP
#define TOP
Definition: scpr.c:32
FF_CODEC_CAP_INIT_CLEANUP
#define FF_CODEC_CAP_INIT_CLEANUP
The codec allows calling the close function for deallocation even if the init function returned a fai...
Definition: codec_internal.h:42
r
const char * r
Definition: vf_curves.c:126
AVERROR
Filter the word “frame” indicates either a video frame or a group of audio as stored in an AVFrame structure Format for each input and each output the list of supported formats For video that means pixel format For audio that means channel sample they are references to shared objects When the negotiation mechanism computes the intersection of the formats supported at each end of a all references to both lists are replaced with a reference to the intersection And when a single format is eventually chosen for a link amongst the remaining all references to the list are updated That means that if a filter requires that its input and output have the same format amongst a supported all it has to do is use a reference to the same list of formats query_formats can leave some formats unset and return AVERROR(EAGAIN) to cause the negotiation mechanism toagain later. That can be used by filters with complex requirements to use the format negotiated on one link to set the formats supported on another. Frame references ownership and permissions
comp
static void comp(unsigned char *dst, ptrdiff_t dst_stride, unsigned char *src, ptrdiff_t src_stride, int add)
Definition: eamad.c:80
GetByteContext
Definition: bytestream.h:33
decode_close
static av_cold int decode_close(AVCodecContext *avctx)
Definition: scpr.c:660
av_frame_free
void av_frame_free(AVFrame **frame)
Free the frame and any dynamically allocated objects in it, e.g.
Definition: frame.c:99
get_freq0
static int get_freq0(RangeCoder *rc, uint32_t total_freq, uint32_t *freq)
Definition: scpr.c:152
AVFrame
This structure describes decoded (raw) audio or video data.
Definition: frame.h:330
step
trying all byte sequences megabyte in length and selecting the best looking sequence will yield cases to try But a word about which is also called distortion Distortion can be quantified by almost any quality measurement one chooses the sum of squared differences is used but more complex methods that consider psychovisual effects can be used as well It makes no difference in this discussion First step
Definition: rate_distortion.txt:58
w
uint8_t w
Definition: llviddspenc.c:38
AVPacket::data
uint8_t * data
Definition: packet.h:374
b
#define b
Definition: input.c:41
FFCodec
Definition: codec_internal.h:127
RangeCoder::code1
uint32_t code1
Definition: scpr.h:33
max
#define max(a, b)
Definition: cuda_runtime.h:33
bytestream2_skip
static av_always_inline void bytestream2_skip(GetByteContext *g, unsigned int size)
Definition: bytestream.h:168
FFCodec::p
AVCodec p
The public AVCodec.
Definition: codec_internal.h:131
type
it s the only field you need to keep assuming you have a context There is some magic you don t need to care about around this just let it vf type
Definition: writing_filters.txt:86
PixelModel
Definition: scpr.h:36
av_frame_alloc
AVFrame * av_frame_alloc(void)
Allocate an AVFrame and set its fields to default values.
Definition: frame.c:87
AV_LOG_ERROR
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition: log.h:180
av_cold
#define av_cold
Definition: attributes.h:90
decompress_p
static int decompress_p(AVCodecContext *avctx, uint32_t *dst, int linesize, uint32_t *prev, int plinesize)
Definition: scpr.c:368
av_memcpy_backptr
void av_memcpy_backptr(uint8_t *dst, int back, int cnt)
Overlapping memcpy() implementation.
Definition: mem.c:445
width
#define width
FF_CODEC_DECODE_CB
#define FF_CODEC_DECODE_CB(func)
Definition: codec_internal.h:306
s
#define s(width, name)
Definition: cbs_vp9.c:256
g
const char * g
Definition: vf_curves.c:127
op
static int op(uint8_t **dst, const uint8_t *dst_end, GetByteContext *gb, int pixel, int count, int *x, int width, int linesize)
Perform decode operation.
Definition: anm.c:76
init
int(* init)(AVBSFContext *ctx)
Definition: dts2pts_bsf.c:365
decode.h
decode_run_i
static int decode_run_i(AVCodecContext *avctx, uint32_t ptype, int run, int *px, int *py, uint32_t clr, uint32_t *dst, int linesize, uint32_t *plx, uint32_t *ply, uint32_t backstep, int off, int *cx, int *cx1)
Definition: scpr.h:75
BOT
#define BOT
Definition: scpr.c:33
decode_init
static av_cold int decode_init(AVCodecContext *avctx)
Definition: scpr.c:627
CODEC_LONG_NAME
#define CODEC_LONG_NAME(str)
Definition: codec_internal.h:272
if
if(ret)
Definition: filter_design.txt:179
AVERROR_PATCHWELCOME
#define AVERROR_PATCHWELCOME
Not yet implemented in FFmpeg, patches welcome.
Definition: error.h:64
run
uint8_t run
Definition: svq3.c:203
pixel
uint8_t pixel
Definition: tiny_ssim.c:41
scpr3.h
AV_PICTURE_TYPE_I
@ AV_PICTURE_TYPE_I
Intra.
Definition: avutil.h:274
get_freq
static int get_freq(RangeCoder *rc, uint32_t total_freq, uint32_t *freq)
Definition: scpr.c:115
AV_PIX_FMT_BGR0
@ AV_PIX_FMT_BGR0
packed BGR 8:8:8, 32bpp, BGRXBGRX... X=unused/undefined
Definition: pixfmt.h:258
reinit_tables
static void reinit_tables(SCPRContext *s)
Definition: scpr.c:44
c
Undefined Behavior In the C some operations are like signed integer dereferencing freed accessing outside allocated Undefined Behavior must not occur in a C it is not safe even if the output of undefined operations is unused The unsafety may seem nit picking but Optimizing compilers have in fact optimized code on the assumption that no undefined Behavior occurs Optimizing code based on wrong assumptions can and has in some cases lead to effects beyond the output of computations The signed integer overflow problem in speed critical code Code which is highly optimized and works with signed integers sometimes has the problem that often the output of the computation does not c
Definition: undefined.txt:32
bytestream2_get_bytes_left
static av_always_inline int bytestream2_get_bytes_left(GetByteContext *g)
Definition: bytestream.h:158
scpr3.c
decompress_i
static int decompress_i(AVCodecContext *avctx, uint32_t *dst, int linesize)
Definition: scpr.c:296
ff_get_buffer
int ff_get_buffer(AVCodecContext *avctx, AVFrame *frame, int flags)
Get a buffer for a frame.
Definition: decode.c:1473
AV_CODEC_CAP_DR1
#define AV_CODEC_CAP_DR1
Codec uses get_buffer() or get_encode_buffer() for allocating buffers and supports custom allocators.
Definition: codec.h:52
AV_CODEC_ID_SCPR
@ AV_CODEC_ID_SCPR
Definition: codec_id.h:280
AVPacket::size
int size
Definition: packet.h:375
av_frame_ref
int av_frame_ref(AVFrame *dst, const AVFrame *src)
Set up a new reference to the data described by the source frame.
Definition: frame.c:344
codec_internal.h
av_frame_copy
int av_frame_copy(AVFrame *dst, const AVFrame *src)
Copy the frame data from src to dst.
Definition: frame.c:762
for
for(k=2;k<=8;++k)
Definition: h264pred_template.c:425
ff_scpr_decoder
const FFCodec ff_scpr_decoder
Definition: scpr.c:671
decode_run_p
static int decode_run_p(AVCodecContext *avctx, uint32_t ptype, int run, int x, int y, uint32_t clr, uint32_t *dst, uint32_t *prev, int linesize, int plinesize, uint32_t *bx, uint32_t *by, uint32_t backstep, int sx1, int sx2, int *cx, int *cx1)
Definition: scpr.h:217
decode_value
static int decode_value(SCPRContext *s, uint32_t *cnt, uint32_t maxc, uint32_t step, uint32_t *rval)
Definition: scpr.c:162
SCPRContext
Definition: scpr.h:42
height
#define height
AV_PIX_FMT_RGB0
@ AV_PIX_FMT_RGB0
packed RGB 8:8:8, 32bpp, RGBXRGBX... X=unused/undefined
Definition: pixfmt.h:256
decode_units
static int decode_units(SCPRContext *s, uint32_t *r, uint32_t *g, uint32_t *b, int *cx, int *cx1)
Definition: scpr.c:268
decompress_i3
static int decompress_i3(AVCodecContext *avctx, uint32_t *dst, int linesize)
Definition: scpr3.c:928
RangeCoder::code
uint32_t code
Definition: scpr.h:31
AVCodecContext::bits_per_coded_sample
int bits_per_coded_sample
bits per sample/pixel from the demuxer (needed for huffyuv).
Definition: avcodec.h:1480
i
#define i(width, name, range_min, range_max)
Definition: cbs_h2645.c:269
decode_unit
static int decode_unit(SCPRContext *s, PixelModel *pixel, uint32_t step, uint32_t *rval)
Definition: scpr.c:206
av_malloc_array
#define av_malloc_array(a, b)
Definition: tableprint_vlc.h:31
decompress_p3
static int decompress_p3(AVCodecContext *avctx, uint32_t *dst, int linesize, uint32_t *prev, int plinesize)
Definition: scpr3.c:1011
value
it s the only field you need to keep assuming you have a context There is some magic you don t need to care about around this just let it vf default value
Definition: writing_filters.txt:86
AVCodec::name
const char * name
Name of the codec implementation.
Definition: codec.h:191
AVCodecContext::height
int height
Definition: avcodec.h:598
AVCodecContext::pix_fmt
enum AVPixelFormat pix_fmt
Pixel format, see AV_PIX_FMT_xxx.
Definition: avcodec.h:635
avcodec.h
ff_reget_buffer
int ff_reget_buffer(AVCodecContext *avctx, AVFrame *frame, int flags)
Identical in function to ff_get_buffer(), except it reuses the existing buffer if available.
Definition: decode.c:1591
ret
ret
Definition: filter_design.txt:187
FFSWAP
#define FFSWAP(type, a, b)
Definition: macros.h:52
frame
these buffered frames must be flushed immediately if a new input produces new the filter must not call request_frame to get more It must just process the frame or queue it The task of requesting more frames is left to the filter s request_frame method or the application If a filter has several the filter must be ready for frames arriving randomly on any input any filter with several inputs will most likely require some kind of queuing mechanism It is perfectly acceptable to have a limited queue and to drop frames when the inputs are too unbalanced request_frame For filters that do not use the this method is called when a frame is wanted on an output For a it should directly call filter_frame on the corresponding output For a if there are queued frames already one of these frames should be pushed If the filter should request a frame on one of its repeatedly until at least one frame has been pushed Return or at least make progress towards producing a frame
Definition: filter_design.txt:264
U
#define U(x)
Definition: vpx_arith.h:37
decode0
static int decode0(GetByteContext *gb, RangeCoder *rc, uint32_t cumFreq, uint32_t freq, uint32_t total_freq)
Definition: scpr.c:130
decode
static int decode(GetByteContext *gb, RangeCoder *rc, uint32_t cumFreq, uint32_t freq, uint32_t total_freq)
Definition: scpr.c:101
AVCodecContext
main external API structure.
Definition: avcodec.h:426
scpr.h
temp
else temp
Definition: vf_mcdeint.c:248
AV_PICTURE_TYPE_P
@ AV_PICTURE_TYPE_P
Predicted.
Definition: avutil.h:275
AVMEDIA_TYPE_VIDEO
@ AVMEDIA_TYPE_VIDEO
Definition: avutil.h:201
AVPacket
This structure stores compressed data.
Definition: packet.h:351
AVCodecContext::priv_data
void * priv_data
Definition: avcodec.h:453
av_freep
#define av_freep(p)
Definition: tableprint_vlc.h:34
AVCodecContext::width
int width
picture width / height.
Definition: avcodec.h:598
bytestream.h
bytestream2_init
static av_always_inline void bytestream2_init(GetByteContext *g, const uint8_t *buf, int buf_size)
Definition: bytestream.h:137
av_log
#define av_log(a,...)
Definition: tableprint_vlc.h:27
AVERROR_INVALIDDATA
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
Definition: error.h:61
RangeCoder
Definition: mss3.c:62
init_rangecoder
static void init_rangecoder(RangeCoder *rc, GetByteContext *gb)
Definition: scpr.c:37
decode_frame
static int decode_frame(AVCodecContext *avctx, AVFrame *frame, int *got_frame, AVPacket *avpkt)
Definition: scpr.c:496
min
float min
Definition: vorbis_enc_data.h:429