FFmpeg  4.4.7
cfhd.c
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2015-2016 Kieran Kunhya <kieran@kunhya.com>
3  *
4  * This file is part of FFmpeg.
5  *
6  * FFmpeg is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or (at your option) any later version.
10  *
11  * FFmpeg is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with FFmpeg; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19  */
20 
21 /**
22  * @file
23  * Cineform HD video decoder
24  */
25 
26 #include "libavutil/attributes.h"
27 #include "libavutil/buffer.h"
28 #include "libavutil/common.h"
29 #include "libavutil/imgutils.h"
30 #include "libavutil/intreadwrite.h"
31 #include "libavutil/opt.h"
32 
33 #include "avcodec.h"
34 #include "bytestream.h"
35 #include "get_bits.h"
36 #include "internal.h"
37 #include "thread.h"
38 #include "cfhd.h"
39 
40 #define ALPHA_COMPAND_DC_OFFSET 256
41 #define ALPHA_COMPAND_GAIN 9400
42 
43 static av_cold int cfhd_init(AVCodecContext *avctx)
44 {
45  CFHDContext *s = avctx->priv_data;
46 
47  s->avctx = avctx;
48 
49  for (int i = 0; i < 64; i++) {
50  int val = i;
51 
52  if (val >= 40) {
53  if (val >= 54) {
54  val -= 54;
55  val <<= 2;
56  val += 54;
57  }
58 
59  val -= 40;
60  val <<= 2;
61  val += 40;
62  }
63 
64  s->lut[0][i] = val;
65  }
66 
67  for (int i = 0; i < 256; i++)
68  s->lut[1][i] = i + ((768LL * i * i * i) / (256 * 256 * 256));
69 
70  return ff_cfhd_init_vlcs(s);
71 }
72 
74 {
75  s->subband_num = 0;
76  s->level = 0;
77  s->subband_num_actual = 0;
78 }
79 
81 {
82  s->peak.level = 0;
83  s->peak.offset = 0;
84  memset(&s->peak.base, 0, sizeof(s->peak.base));
85 }
86 
88 {
89  s->coded_width = 0;
90  s->coded_height = 0;
91  s->coded_format = AV_PIX_FMT_YUV422P10;
92  s->cropped_height = 0;
93  s->bpc = 10;
94  s->channel_cnt = 3;
95  s->subband_cnt = SUBBAND_COUNT;
96  s->channel_num = 0;
97  s->lowpass_precision = 16;
98  s->quantisation = 1;
99  s->codebook = 0;
100  s->difference_coding = 0;
101  s->frame_type = 0;
102  s->sample_type = 0;
103  if (s->transform_type != 2)
104  s->transform_type = -1;
107 }
108 
109 static inline int dequant_and_decompand(CFHDContext *s, int level, int quantisation, int codebook)
110 {
111  if (codebook == 0 || codebook == 1) {
112  return s->lut[codebook][abs(level)] * FFSIGN(level) * quantisation;
113  } else
114  return level * quantisation;
115 }
116 
117 static inline void difference_coding(int16_t *band, int width, int height)
118 {
119 
120  int i,j;
121  for (i = 0; i < height; i++) {
122  for (j = 1; j < width; j++) {
123  band[j] += band[j-1];
124  }
125  band += width;
126  }
127 }
128 
129 static inline void peak_table(int16_t *band, Peak *peak, int length)
130 {
131  int i;
132  for (i = 0; i < length; i++)
133  if (abs(band[i]) > peak->level)
134  band[i] = bytestream2_get_le16(&peak->base);
135 }
136 
137 static inline void process_alpha(int16_t *alpha, int width)
138 {
139  int i, channel;
140  for (i = 0; i < width; i++) {
141  channel = alpha[i];
143  channel <<= 3;
145  channel >>= 16;
147  alpha[i] = channel;
148  }
149 }
150 
151 static inline void process_bayer(AVFrame *frame, int bpc)
152 {
153  const int linesize = frame->linesize[0];
154  uint16_t *r = (uint16_t *)frame->data[0];
155  uint16_t *g1 = (uint16_t *)(frame->data[0] + 2);
156  uint16_t *g2 = (uint16_t *)(frame->data[0] + frame->linesize[0]);
157  uint16_t *b = (uint16_t *)(frame->data[0] + frame->linesize[0] + 2);
158  const int mid = 1 << (bpc - 1);
159  const int factor = 1 << (16 - bpc);
160 
161  for (int y = 0; y < frame->height >> 1; y++) {
162  for (int x = 0; x < frame->width; x += 2) {
163  int R, G1, G2, B;
164  int g, rg, bg, gd;
165 
166  g = r[x];
167  rg = g1[x];
168  bg = g2[x];
169  gd = b[x];
170  gd -= mid;
171 
172  R = (rg - mid) * 2 + g;
173  G1 = g + gd;
174  G2 = g - gd;
175  B = (bg - mid) * 2 + g;
176 
177  R = av_clip_uintp2(R * factor, 16);
178  G1 = av_clip_uintp2(G1 * factor, 16);
179  G2 = av_clip_uintp2(G2 * factor, 16);
180  B = av_clip_uintp2(B * factor, 16);
181 
182  r[x] = R;
183  g1[x] = G1;
184  g2[x] = G2;
185  b[x] = B;
186  }
187 
188  r += linesize;
189  g1 += linesize;
190  g2 += linesize;
191  b += linesize;
192  }
193 }
194 
195 static inline void interlaced_vertical_filter(int16_t *output, int16_t *low, int16_t *high,
196  int width, int linesize, int plane)
197 {
198  int i;
199  int16_t even, odd;
200  for (i = 0; i < width; i++) {
201  even = (low[i] - high[i])/2;
202  odd = (low[i] + high[i])/2;
203  output[i] = av_clip_uintp2(even, 10);
204  output[i + linesize] = av_clip_uintp2(odd, 10);
205  }
206 }
207 
208 static inline void inverse_temporal_filter(int16_t *low, int16_t *high, int width)
209 {
210  for (int i = 0; i < width; i++) {
211  int even = (low[i] - high[i]) / 2;
212  int odd = (low[i] + high[i]) / 2;
213 
214  low[i] = even;
215  high[i] = odd;
216  }
217 }
218 
220 {
221  int i, j;
222 
223  for (i = 0; i < FF_ARRAY_ELEMS(s->plane); i++) {
224  Plane *p = &s->plane[i];
225  av_freep(&s->plane[i].idwt_buf);
226  av_freep(&s->plane[i].idwt_tmp);
227  s->plane[i].idwt_size = 0;
228 
229  for (j = 0; j < SUBBAND_COUNT_3D; j++)
230  s->plane[i].subband[j] = NULL;
231 
232  for (j = 0; j < 10; j++)
233  s->plane[i].l_h[j] = NULL;
234 
235  for (j = 0; j < DWT_LEVELS_3D; j++)
236  p->band[j][0].read_ok =
237  p->band[j][1].read_ok =
238  p->band[j][2].read_ok =
239  p->band[j][3].read_ok = 0;
240  }
241  s->a_height = 0;
242  s->a_width = 0;
243  s->a_transform_type = INT_MIN;
244 }
245 
246 static int alloc_buffers(AVCodecContext *avctx)
247 {
248  CFHDContext *s = avctx->priv_data;
249  int i, j, ret, planes, bayer = 0;
250  int chroma_x_shift, chroma_y_shift;
251  unsigned k;
252 
253  if ((ret = ff_set_dimensions(avctx, s->coded_width, s->coded_height)) < 0)
254  return ret;
255  avctx->pix_fmt = s->coded_format;
256 
257  ff_cfhddsp_init(&s->dsp, s->bpc, avctx->pix_fmt == AV_PIX_FMT_BAYER_RGGB16);
258 
259  if ((ret = av_pix_fmt_get_chroma_sub_sample(s->coded_format,
260  &chroma_x_shift,
261  &chroma_y_shift)) < 0)
262  return ret;
263  planes = av_pix_fmt_count_planes(s->coded_format);
264  if (s->coded_format == AV_PIX_FMT_BAYER_RGGB16) {
265  planes = 4;
266  chroma_x_shift = 1;
267  chroma_y_shift = 1;
268  bayer = 1;
269  }
270 
271  for (i = 0; i < planes; i++) {
272  int w8, h8, w4, h4, w2, h2;
273  int width = (i || bayer) ? s->coded_width >> chroma_x_shift : s->coded_width;
274  int height = (i || bayer) ? s->coded_height >> chroma_y_shift : s->coded_height;
275  ptrdiff_t stride = (FFALIGN(width / 8, 8) + 64) * 8;
276 
277  if ((ret = av_image_check_size2(stride, height, avctx->max_pixels, s->coded_format, 0, avctx)) < 0)
278  return ret;
279 
280  if (chroma_y_shift && !bayer)
281  height = FFALIGN(height / 8, 2) * 8;
282  s->plane[i].width = width;
283  s->plane[i].height = height;
284  s->plane[i].stride = stride;
285 
286  w8 = FFALIGN(s->plane[i].width / 8, 8) + 64;
287  h8 = FFALIGN(height, 8) / 8;
288  w4 = w8 * 2;
289  h4 = h8 * 2;
290  w2 = w4 * 2;
291  h2 = h4 * 2;
292 
293  if (s->transform_type == 0) {
294  s->plane[i].idwt_size = FFALIGN(height, 8) * stride;
295  s->plane[i].idwt_buf =
296  av_mallocz_array(s->plane[i].idwt_size, sizeof(*s->plane[i].idwt_buf));
297  s->plane[i].idwt_tmp =
298  av_malloc_array(s->plane[i].idwt_size, sizeof(*s->plane[i].idwt_tmp));
299  } else {
300  s->plane[i].idwt_size = FFALIGN(height, 8) * stride * 2;
301  s->plane[i].idwt_buf =
302  av_mallocz_array(s->plane[i].idwt_size, sizeof(*s->plane[i].idwt_buf));
303  s->plane[i].idwt_tmp =
304  av_malloc_array(s->plane[i].idwt_size, sizeof(*s->plane[i].idwt_tmp));
305  }
306 
307  if (!s->plane[i].idwt_buf || !s->plane[i].idwt_tmp)
308  return AVERROR(ENOMEM);
309 
310  s->plane[i].subband[0] = s->plane[i].idwt_buf;
311  s->plane[i].subband[1] = s->plane[i].idwt_buf + 2 * w8 * h8;
312  s->plane[i].subband[2] = s->plane[i].idwt_buf + 1 * w8 * h8;
313  s->plane[i].subband[3] = s->plane[i].idwt_buf + 3 * w8 * h8;
314  s->plane[i].subband[4] = s->plane[i].idwt_buf + 2 * w4 * h4;
315  s->plane[i].subband[5] = s->plane[i].idwt_buf + 1 * w4 * h4;
316  s->plane[i].subband[6] = s->plane[i].idwt_buf + 3 * w4 * h4;
317  if (s->transform_type == 0) {
318  s->plane[i].subband[7] = s->plane[i].idwt_buf + 2 * w2 * h2;
319  s->plane[i].subband[8] = s->plane[i].idwt_buf + 1 * w2 * h2;
320  s->plane[i].subband[9] = s->plane[i].idwt_buf + 3 * w2 * h2;
321  } else {
322  int16_t *frame2 =
323  s->plane[i].subband[7] = s->plane[i].idwt_buf + 4 * w2 * h2;
324  s->plane[i].subband[8] = frame2 + 2 * w4 * h4;
325  s->plane[i].subband[9] = frame2 + 1 * w4 * h4;
326  s->plane[i].subband[10] = frame2 + 3 * w4 * h4;
327  s->plane[i].subband[11] = frame2 + 2 * w2 * h2;
328  s->plane[i].subband[12] = frame2 + 1 * w2 * h2;
329  s->plane[i].subband[13] = frame2 + 3 * w2 * h2;
330  s->plane[i].subband[14] = s->plane[i].idwt_buf + 2 * w2 * h2;
331  s->plane[i].subband[15] = s->plane[i].idwt_buf + 1 * w2 * h2;
332  s->plane[i].subband[16] = s->plane[i].idwt_buf + 3 * w2 * h2;
333  }
334 
335  if (s->transform_type == 0) {
336  for (j = 0; j < DWT_LEVELS; j++) {
337  for (k = 0; k < FF_ARRAY_ELEMS(s->plane[i].band[j]); k++) {
338  s->plane[i].band[j][k].a_width = w8 << j;
339  s->plane[i].band[j][k].a_height = h8 << j;
340  }
341  }
342  } else {
343  for (j = 0; j < DWT_LEVELS_3D; j++) {
344  int t = j < 1 ? 0 : (j < 3 ? 1 : 2);
345 
346  for (k = 0; k < FF_ARRAY_ELEMS(s->plane[i].band[j]); k++) {
347  s->plane[i].band[j][k].a_width = w8 << t;
348  s->plane[i].band[j][k].a_height = h8 << t;
349  }
350  }
351  }
352 
353  /* ll2 and ll1 commented out because they are done in-place */
354  s->plane[i].l_h[0] = s->plane[i].idwt_tmp;
355  s->plane[i].l_h[1] = s->plane[i].idwt_tmp + 2 * w8 * h8;
356  // s->plane[i].l_h[2] = ll2;
357  s->plane[i].l_h[3] = s->plane[i].idwt_tmp;
358  s->plane[i].l_h[4] = s->plane[i].idwt_tmp + 2 * w4 * h4;
359  // s->plane[i].l_h[5] = ll1;
360  s->plane[i].l_h[6] = s->plane[i].idwt_tmp;
361  s->plane[i].l_h[7] = s->plane[i].idwt_tmp + 2 * w2 * h2;
362  if (s->transform_type != 0) {
363  int16_t *frame2 = s->plane[i].idwt_tmp + 4 * w2 * h2;
364 
365  s->plane[i].l_h[8] = frame2;
366  s->plane[i].l_h[9] = frame2 + 2 * w2 * h2;
367  }
368  }
369 
370  s->a_transform_type = s->transform_type;
371  s->a_height = s->coded_height;
372  s->a_width = s->coded_width;
373  s->a_format = s->coded_format;
374 
375  return 0;
376 }
377 
378 static int cfhd_decode(AVCodecContext *avctx, void *data, int *got_frame,
379  AVPacket *avpkt)
380 {
381  CFHDContext *s = avctx->priv_data;
382  CFHDDSPContext *dsp = &s->dsp;
383  GetByteContext gb;
384  ThreadFrame frame = { .f = data };
385  AVFrame *pic = data;
386  int ret = 0, i, j, plane, got_buffer = 0;
387  int16_t *coeff_data;
388 
390  s->planes = av_pix_fmt_count_planes(s->coded_format);
391 
392  bytestream2_init(&gb, avpkt->data, avpkt->size);
393 
394  while (bytestream2_get_bytes_left(&gb) >= 4) {
395  /* Bit weird but implement the tag parsing as the spec says */
396  uint16_t tagu = bytestream2_get_be16(&gb);
397  int16_t tag = (int16_t)tagu;
398  int8_t tag8 = (int8_t)(tagu >> 8);
399  uint16_t abstag = abs(tag);
400  int8_t abs_tag8 = abs(tag8);
401  uint16_t data = bytestream2_get_be16(&gb);
402  if (abs_tag8 >= 0x60 && abs_tag8 <= 0x6f) {
403  av_log(avctx, AV_LOG_DEBUG, "large len %x\n", ((tagu & 0xff) << 16) | data);
404  } else if (tag == SampleFlags) {
405  av_log(avctx, AV_LOG_DEBUG, "Progressive? %"PRIu16"\n", data);
406  s->progressive = data & 0x0001;
407  } else if (tag == FrameType) {
408  s->frame_type = data;
409  av_log(avctx, AV_LOG_DEBUG, "Frame type %"PRIu16"\n", data);
410  } else if (abstag == VersionMajor) {
411  av_log(avctx, AV_LOG_DEBUG, "Version major %"PRIu16"\n", data);
412  } else if (abstag == VersionMinor) {
413  av_log(avctx, AV_LOG_DEBUG, "Version minor %"PRIu16"\n", data);
414  } else if (abstag == VersionRevision) {
415  av_log(avctx, AV_LOG_DEBUG, "Version revision %"PRIu16"\n", data);
416  } else if (abstag == VersionEdit) {
417  av_log(avctx, AV_LOG_DEBUG, "Version edit %"PRIu16"\n", data);
418  } else if (abstag == Version) {
419  av_log(avctx, AV_LOG_DEBUG, "Version %"PRIu16"\n", data);
420  } else if (tag == ImageWidth) {
421  av_log(avctx, AV_LOG_DEBUG, "Width %"PRIu16"\n", data);
422  s->coded_width = data;
423  } else if (tag == ImageHeight) {
424  av_log(avctx, AV_LOG_DEBUG, "Height %"PRIu16"\n", data);
425  s->coded_height = data;
426  } else if (tag == ChannelCount) {
427  av_log(avctx, AV_LOG_DEBUG, "Channel Count: %"PRIu16"\n", data);
428  s->channel_cnt = data;
429  if (data > 4) {
430  av_log(avctx, AV_LOG_ERROR, "Channel Count of %"PRIu16" is unsupported\n", data);
431  ret = AVERROR_PATCHWELCOME;
432  goto end;
433  }
434  } else if (tag == SubbandCount) {
435  av_log(avctx, AV_LOG_DEBUG, "Subband Count: %"PRIu16"\n", data);
436  if (data != SUBBAND_COUNT && data != SUBBAND_COUNT_3D) {
437  av_log(avctx, AV_LOG_ERROR, "Subband Count of %"PRIu16" is unsupported\n", data);
438  ret = AVERROR_PATCHWELCOME;
439  goto end;
440  }
441  } else if (tag == ChannelNumber) {
442  s->channel_num = data;
443  av_log(avctx, AV_LOG_DEBUG, "Channel number %"PRIu16"\n", data);
444  if (s->channel_num >= s->planes) {
445  av_log(avctx, AV_LOG_ERROR, "Invalid channel number\n");
446  ret = AVERROR(EINVAL);
447  goto end;
448  }
450  } else if (tag == SubbandNumber) {
451  if (s->subband_num != 0 && data == 1 && (s->transform_type == 0 || s->transform_type == 2)) // hack
452  s->level++;
453  av_log(avctx, AV_LOG_DEBUG, "Subband number %"PRIu16"\n", data);
454  s->subband_num = data;
455  if ((s->transform_type == 0 && s->level >= DWT_LEVELS) ||
456  (s->transform_type == 2 && s->level >= DWT_LEVELS_3D)) {
457  av_log(avctx, AV_LOG_ERROR, "Invalid level\n");
458  ret = AVERROR(EINVAL);
459  goto end;
460  }
461  if (s->subband_num > 3) {
462  av_log(avctx, AV_LOG_ERROR, "Invalid subband number\n");
463  ret = AVERROR(EINVAL);
464  goto end;
465  }
466  } else if (tag == SubbandBand) {
467  av_log(avctx, AV_LOG_DEBUG, "Subband number actual %"PRIu16"\n", data);
468  if ((s->transform_type == 0 && data >= SUBBAND_COUNT) ||
469  (s->transform_type == 2 && data >= SUBBAND_COUNT_3D && data != 255)) {
470  av_log(avctx, AV_LOG_ERROR, "Invalid subband number actual\n");
471  ret = AVERROR(EINVAL);
472  goto end;
473  }
474  if (s->transform_type == 0 || s->transform_type == 2)
475  s->subband_num_actual = data;
476  else
477  av_log(avctx, AV_LOG_WARNING, "Ignoring subband num actual %"PRIu16"\n", data);
478  } else if (tag == LowpassPrecision)
479  av_log(avctx, AV_LOG_DEBUG, "Lowpass precision bits: %"PRIu16"\n", data);
480  else if (tag == Quantization) {
481  s->quantisation = data;
482  av_log(avctx, AV_LOG_DEBUG, "Quantisation: %"PRIu16"\n", data);
483  } else if (tag == PrescaleTable) {
484  for (i = 0; i < 8; i++)
485  s->prescale_table[i] = (data >> (14 - i * 2)) & 0x3;
486  av_log(avctx, AV_LOG_DEBUG, "Prescale table: %x\n", data);
487  } else if (tag == BandEncoding) {
488  if (!data || data > 5) {
489  av_log(avctx, AV_LOG_ERROR, "Invalid band encoding\n");
490  ret = AVERROR(EINVAL);
491  goto end;
492  }
493  s->band_encoding = data;
494  av_log(avctx, AV_LOG_DEBUG, "Encode Method for Subband %d : %x\n", s->subband_num_actual, data);
495  } else if (tag == LowpassWidth) {
496  av_log(avctx, AV_LOG_DEBUG, "Lowpass width %"PRIu16"\n", data);
497  s->plane[s->channel_num].band[0][0].width = data;
498  s->plane[s->channel_num].band[0][0].stride = data;
499  } else if (tag == LowpassHeight) {
500  av_log(avctx, AV_LOG_DEBUG, "Lowpass height %"PRIu16"\n", data);
501  s->plane[s->channel_num].band[0][0].height = data;
502  } else if (tag == SampleType) {
503  s->sample_type = data;
504  av_log(avctx, AV_LOG_DEBUG, "Sample type? %"PRIu16"\n", data);
505  } else if (tag == TransformType) {
506  if (data > 2) {
507  av_log(avctx, AV_LOG_ERROR, "Invalid transform type\n");
508  ret = AVERROR(EINVAL);
509  goto end;
510  } else if (data == 1) {
511  av_log(avctx, AV_LOG_ERROR, "unsupported transform type\n");
512  ret = AVERROR_PATCHWELCOME;
513  goto end;
514  }
515  if (s->transform_type == -1) {
516  s->transform_type = data;
517  av_log(avctx, AV_LOG_DEBUG, "Transform type %"PRIu16"\n", data);
518  } else {
519  av_log(avctx, AV_LOG_DEBUG, "Ignoring additional transform type %"PRIu16"\n", data);
520  }
521  } else if (abstag >= 0x4000 && abstag <= 0x40ff) {
522  if (abstag == 0x4001)
523  s->peak.level = 0;
524  av_log(avctx, AV_LOG_DEBUG, "Small chunk length %d %s\n", data * 4, tag < 0 ? "optional" : "required");
525  bytestream2_skipu(&gb, data * 4);
526  } else if (tag == FrameIndex) {
527  av_log(avctx, AV_LOG_DEBUG, "Frame index %"PRIu16"\n", data);
528  s->frame_index = data;
529  } else if (tag == SampleIndexTable) {
530  av_log(avctx, AV_LOG_DEBUG, "Sample index table - skipping %i values\n", data);
531  if (data > bytestream2_get_bytes_left(&gb) / 4) {
532  av_log(avctx, AV_LOG_ERROR, "too many values (%d)\n", data);
533  ret = AVERROR_INVALIDDATA;
534  goto end;
535  }
536  for (i = 0; i < data; i++) {
537  uint32_t offset = bytestream2_get_be32(&gb);
538  av_log(avctx, AV_LOG_DEBUG, "Offset = %"PRIu32"\n", offset);
539  }
540  } else if (tag == HighpassWidth) {
541  av_log(avctx, AV_LOG_DEBUG, "Highpass width %i channel %i level %i subband %i\n", data, s->channel_num, s->level, s->subband_num);
542  if (data < 3) {
543  av_log(avctx, AV_LOG_ERROR, "Invalid highpass width\n");
544  ret = AVERROR(EINVAL);
545  goto end;
546  }
547  s->plane[s->channel_num].band[s->level][s->subband_num].width = data;
548  s->plane[s->channel_num].band[s->level][s->subband_num].stride = FFALIGN(data, 8);
549  } else if (tag == HighpassHeight) {
550  av_log(avctx, AV_LOG_DEBUG, "Highpass height %i\n", data);
551  if (data < 3) {
552  av_log(avctx, AV_LOG_ERROR, "Invalid highpass height\n");
553  ret = AVERROR(EINVAL);
554  goto end;
555  }
556  s->plane[s->channel_num].band[s->level][s->subband_num].height = data;
557  } else if (tag == BandWidth) {
558  av_log(avctx, AV_LOG_DEBUG, "Highpass width2 %i\n", data);
559  if (data < 3) {
560  av_log(avctx, AV_LOG_ERROR, "Invalid highpass width2\n");
561  ret = AVERROR(EINVAL);
562  goto end;
563  }
564  s->plane[s->channel_num].band[s->level][s->subband_num].width = data;
565  s->plane[s->channel_num].band[s->level][s->subband_num].stride = FFALIGN(data, 8);
566  } else if (tag == BandHeight) {
567  av_log(avctx, AV_LOG_DEBUG, "Highpass height2 %i\n", data);
568  if (data < 3) {
569  av_log(avctx, AV_LOG_ERROR, "Invalid highpass height2\n");
570  ret = AVERROR(EINVAL);
571  goto end;
572  }
573  s->plane[s->channel_num].band[s->level][s->subband_num].height = data;
574  } else if (tag == InputFormat) {
575  av_log(avctx, AV_LOG_DEBUG, "Input format %i\n", data);
576  if (s->coded_format == AV_PIX_FMT_NONE ||
577  s->coded_format == AV_PIX_FMT_YUV422P10) {
578  if (data >= 100 && data <= 105) {
579  s->coded_format = AV_PIX_FMT_BAYER_RGGB16;
580  } else if (data >= 122 && data <= 128) {
581  s->coded_format = AV_PIX_FMT_GBRP12;
582  } else if (data == 30) {
583  s->coded_format = AV_PIX_FMT_GBRAP12;
584  } else {
585  s->coded_format = AV_PIX_FMT_YUV422P10;
586  }
587  s->planes = s->coded_format == AV_PIX_FMT_BAYER_RGGB16 ? 4 : av_pix_fmt_count_planes(s->coded_format);
588  }
589  } else if (tag == BandCodingFlags) {
590  s->codebook = data & 0xf;
591  s->difference_coding = (data >> 4) & 1;
592  av_log(avctx, AV_LOG_DEBUG, "Other codebook? %i\n", s->codebook);
593  } else if (tag == Precision) {
594  av_log(avctx, AV_LOG_DEBUG, "Precision %i\n", data);
595  if (!(data == 10 || data == 12)) {
596  av_log(avctx, AV_LOG_ERROR, "Invalid bits per channel\n");
597  ret = AVERROR(EINVAL);
598  goto end;
599  }
600  avctx->bits_per_raw_sample = s->bpc = data;
601  } else if (tag == EncodedFormat) {
602  av_log(avctx, AV_LOG_DEBUG, "Sample format? %i\n", data);
603  if (data == 1) {
604  s->coded_format = AV_PIX_FMT_YUV422P10;
605  } else if (data == 2) {
606  s->coded_format = AV_PIX_FMT_BAYER_RGGB16;
607  } else if (data == 3) {
608  s->coded_format = AV_PIX_FMT_GBRP12;
609  } else if (data == 4) {
610  s->coded_format = AV_PIX_FMT_GBRAP12;
611  } else {
612  avpriv_report_missing_feature(avctx, "Sample format of %"PRIu16, data);
613  ret = AVERROR_PATCHWELCOME;
614  goto end;
615  }
616  s->planes = data == 2 ? 4 : av_pix_fmt_count_planes(s->coded_format);
617  } else if (tag == -DisplayHeight) {
618  av_log(avctx, AV_LOG_DEBUG, "Cropped height %"PRIu16"\n", data);
619  s->cropped_height = data;
620  } else if (tag == -PeakOffsetLow) {
621  s->peak.offset &= ~0xffff;
622  s->peak.offset |= (data & 0xffff);
623  s->peak.base = gb;
624  s->peak.level = 0;
625  } else if (tag == -PeakOffsetHigh) {
626  s->peak.offset &= 0xffff;
627  s->peak.offset |= (data & 0xffffU)<<16;
628  s->peak.base = gb;
629  s->peak.level = 0;
630  } else if (tag == -PeakLevel && s->peak.offset) {
631  s->peak.level = data;
632  if (s->peak.offset < 4 - bytestream2_tell(&s->peak.base) ||
633  s->peak.offset > 4 + bytestream2_get_bytes_left(&s->peak.base)
634  ) {
635  ret = AVERROR_INVALIDDATA;
636  goto end;
637  }
638  bytestream2_seek(&s->peak.base, s->peak.offset - 4, SEEK_CUR);
639  } else
640  av_log(avctx, AV_LOG_DEBUG, "Unknown tag %i data %x\n", tag, data);
641 
643  s->coded_format != AV_PIX_FMT_NONE) {
644  int lowpass_height = s->plane[s->channel_num].band[0][0].height;
645  int lowpass_width = s->plane[s->channel_num].band[0][0].width;
646  int factor = s->coded_format == AV_PIX_FMT_BAYER_RGGB16 ? 2 : 1;
647 
648  if (s->coded_width) {
649  s->coded_width *= factor;
650  }
651 
652  if (s->coded_height) {
653  s->coded_height *= factor;
654  }
655 
656  if (!s->a_width && !s->coded_width) {
657  s->coded_width = lowpass_width * factor * 8;
658  }
659 
660  if (!s->a_height && !s->coded_height) {
661  s->coded_height = lowpass_height * factor * 8;
662  }
663 
664  if (s->a_width && !s->coded_width)
665  s->coded_width = s->a_width;
666  if (s->a_height && !s->coded_height)
667  s->coded_height = s->a_height;
668 
669  if (s->a_width != s->coded_width || s->a_height != s->coded_height ||
670  s->a_format != s->coded_format ||
671  s->transform_type != s->a_transform_type) {
672  free_buffers(s);
673  if ((ret = alloc_buffers(avctx)) < 0) {
674  free_buffers(s);
675  return ret;
676  }
677  }
678  ret = ff_set_dimensions(avctx, s->coded_width, s->coded_height);
679  if (ret < 0)
680  return ret;
681  if (s->cropped_height) {
682  unsigned height = s->cropped_height << (avctx->pix_fmt == AV_PIX_FMT_BAYER_RGGB16);
683  if (avctx->height < height)
684  return AVERROR_INVALIDDATA;
685  avctx->height = height;
686  }
687  frame.f->width =
688  frame.f->height = 0;
689 
690  if ((ret = ff_thread_get_buffer(avctx, &frame, 0)) < 0)
691  return ret;
692 
693  s->coded_width = 0;
694  s->coded_height = 0;
695  s->coded_format = AV_PIX_FMT_NONE;
696  got_buffer = 1;
697  } else if (tag == FrameIndex && data == 1 && s->sample_type == 1 && s->frame_type == 2) {
698  frame.f->width =
699  frame.f->height = 0;
700 
701  if ((ret = ff_thread_get_buffer(avctx, &frame, 0)) < 0)
702  return ret;
703  s->coded_width = 0;
704  s->coded_height = 0;
705  s->coded_format = AV_PIX_FMT_NONE;
706  got_buffer = 1;
707  }
708 
709  if (s->subband_num_actual == 255)
710  goto finish;
711 
712  if (tag == BitstreamMarker && data == CoefficientSegment || tag == BandHeader || tag == BandSecondPass || s->peak.level)
713  if (s->transform_type != s->a_transform_type)
714  return AVERROR_PATCHWELCOME;
715 
716  coeff_data = s->plane[s->channel_num].subband[s->subband_num_actual];
717 
718  /* Lowpass coefficients */
720  int lowpass_height, lowpass_width, lowpass_a_height, lowpass_a_width;
721 
722  if (!s->a_width || !s->a_height) {
723  ret = AVERROR_INVALIDDATA;
724  goto end;
725  }
726 
727  lowpass_height = s->plane[s->channel_num].band[0][0].height;
728  lowpass_width = s->plane[s->channel_num].band[0][0].width;
729  lowpass_a_height = s->plane[s->channel_num].band[0][0].a_height;
730  lowpass_a_width = s->plane[s->channel_num].band[0][0].a_width;
731 
732  if (lowpass_width < 3 ||
733  lowpass_width > lowpass_a_width) {
734  av_log(avctx, AV_LOG_ERROR, "Invalid lowpass width\n");
735  ret = AVERROR(EINVAL);
736  goto end;
737  }
738 
739  if (lowpass_height < 3 ||
740  lowpass_height > lowpass_a_height) {
741  av_log(avctx, AV_LOG_ERROR, "Invalid lowpass height\n");
742  ret = AVERROR(EINVAL);
743  goto end;
744  }
745 
746  if (!got_buffer) {
747  av_log(avctx, AV_LOG_ERROR, "No end of header tag found\n");
748  ret = AVERROR(EINVAL);
749  goto end;
750  }
751 
752  if (lowpass_height > lowpass_a_height || lowpass_width > lowpass_a_width ||
753  lowpass_width * lowpass_height * sizeof(int16_t) > bytestream2_get_bytes_left(&gb)) {
754  av_log(avctx, AV_LOG_ERROR, "Too many lowpass coefficients\n");
755  ret = AVERROR(EINVAL);
756  goto end;
757  }
758 
759  av_log(avctx, AV_LOG_DEBUG, "Start of lowpass coeffs component %d height:%d, width:%d\n", s->channel_num, lowpass_height, lowpass_width);
760  for (i = 0; i < lowpass_height; i++) {
761  for (j = 0; j < lowpass_width; j++)
762  coeff_data[j] = bytestream2_get_be16u(&gb);
763 
764  coeff_data += lowpass_width;
765  }
766 
767  /* Align to mod-4 position to continue reading tags */
768  bytestream2_seek(&gb, bytestream2_tell(&gb) & 3, SEEK_CUR);
769 
770  /* Copy last line of coefficients if odd height */
771  if (lowpass_height & 1) {
772  memcpy(&coeff_data[lowpass_height * lowpass_width],
773  &coeff_data[(lowpass_height - 1) * lowpass_width],
774  lowpass_width * sizeof(*coeff_data));
775  }
776 
777  s->plane[s->channel_num].band[0][0].read_ok = 1;
778 
779  av_log(avctx, AV_LOG_DEBUG, "Lowpass coefficients %d\n", lowpass_width * lowpass_height);
780  }
781 
782  av_assert0(s->subband_num_actual != 255);
783  if (tag == BandHeader || tag == BandSecondPass) {
784  int highpass_height, highpass_width, highpass_a_width, highpass_a_height, highpass_stride, a_expected;
785  int expected;
786  int level, run, coeff;
787  int count = 0, bytes;
788 
789  if (!s->a_width || !s->a_height) {
790  ret = AVERROR_INVALIDDATA;
791  goto end;
792  }
793 
794  highpass_height = s->plane[s->channel_num].band[s->level][s->subband_num].height;
795  highpass_width = s->plane[s->channel_num].band[s->level][s->subband_num].width;
796  highpass_a_width = s->plane[s->channel_num].band[s->level][s->subband_num].a_width;
797  highpass_a_height = s->plane[s->channel_num].band[s->level][s->subband_num].a_height;
798  highpass_stride = s->plane[s->channel_num].band[s->level][s->subband_num].stride;
799  a_expected = highpass_a_height * highpass_a_width;
800 
801  if (!got_buffer) {
802  av_log(avctx, AV_LOG_ERROR, "No end of header tag found\n");
803  ret = AVERROR(EINVAL);
804  goto end;
805  }
806 
807  if (highpass_height > highpass_a_height || highpass_width > highpass_a_width || a_expected < highpass_height * (uint64_t)highpass_stride) {
808  av_log(avctx, AV_LOG_ERROR, "Too many highpass coefficients\n");
809  ret = AVERROR(EINVAL);
810  goto end;
811  }
812  expected = highpass_height * highpass_stride;
813 
814  av_log(avctx, AV_LOG_DEBUG, "Start subband coeffs plane %i level %i codebook %i expected %i\n", s->channel_num, s->level, s->codebook, expected);
815 
816  ret = init_get_bits8(&s->gb, gb.buffer, bytestream2_get_bytes_left(&gb));
817  if (ret < 0)
818  goto end;
819  {
820  OPEN_READER(re, &s->gb);
821 
822  const int lossless = s->band_encoding == 5;
823 
824  if (s->codebook == 0 && s->transform_type == 2 && s->subband_num_actual == 7)
825  s->codebook = 1;
826  if (!s->codebook) {
827  while (1) {
828  UPDATE_CACHE(re, &s->gb);
829  GET_RL_VLC(level, run, re, &s->gb, s->table_9_rl_vlc,
830  VLC_BITS, 3, 1);
831 
832  /* escape */
833  if (level == 64)
834  break;
835 
836  count += run;
837 
838  if (count > expected)
839  break;
840 
841  if (!lossless)
842  coeff = dequant_and_decompand(s, level, s->quantisation, 0);
843  else
844  coeff = level;
845  if (tag == BandSecondPass) {
846  const uint16_t q = s->quantisation;
847 
848  for (i = 0; i < run; i++) {
849  *coeff_data |= coeff * 256U;
850  *coeff_data++ *= q;
851  }
852  } else {
853  for (i = 0; i < run; i++)
854  *coeff_data++ = coeff;
855  }
856  }
857  } else {
858  while (1) {
859  UPDATE_CACHE(re, &s->gb);
860  GET_RL_VLC(level, run, re, &s->gb, s->table_18_rl_vlc,
861  VLC_BITS, 3, 1);
862 
863  /* escape */
864  if (level == 255 && run == 2)
865  break;
866 
867  count += run;
868 
869  if (count > expected)
870  break;
871 
872  if (!lossless)
873  coeff = dequant_and_decompand(s, level, s->quantisation, s->codebook);
874  else
875  coeff = level;
876  if (tag == BandSecondPass) {
877  const uint16_t q = s->quantisation;
878 
879  for (i = 0; i < run; i++) {
880  *coeff_data |= coeff * 256U;
881  *coeff_data++ *= q;
882  }
883  } else {
884  for (i = 0; i < run; i++)
885  *coeff_data++ = coeff;
886  }
887  }
888  }
889  CLOSE_READER(re, &s->gb);
890  }
891 
892  if (count > expected) {
893  av_log(avctx, AV_LOG_ERROR, "Escape codeword not found, probably corrupt data\n");
894  ret = AVERROR(EINVAL);
895  goto end;
896  }
897  if (s->peak.level)
898  peak_table(coeff_data - count, &s->peak, count);
899  if (s->difference_coding)
900  difference_coding(s->plane[s->channel_num].subband[s->subband_num_actual], highpass_width, highpass_height);
901 
902  bytes = FFALIGN(AV_CEIL_RSHIFT(get_bits_count(&s->gb), 3), 4);
903  if (bytes > bytestream2_get_bytes_left(&gb)) {
904  av_log(avctx, AV_LOG_ERROR, "Bitstream overread error\n");
905  ret = AVERROR(EINVAL);
906  goto end;
907  } else
908  bytestream2_seek(&gb, bytes, SEEK_CUR);
909 
910  av_log(avctx, AV_LOG_DEBUG, "End subband coeffs %i extra %i\n", count, count - expected);
911  s->plane[s->channel_num].band[s->level][s->subband_num].read_ok = 1;
912 finish:
913  if (s->subband_num_actual != 255)
914  s->codebook = 0;
915  }
916  }
917 
918  s->planes = av_pix_fmt_count_planes(avctx->pix_fmt);
919  if (avctx->pix_fmt == AV_PIX_FMT_BAYER_RGGB16) {
920  s->progressive = 1;
921  s->planes = 4;
922  }
923 
924  ff_thread_finish_setup(avctx);
925 
926  if (!s->a_width || !s->a_height || s->a_format == AV_PIX_FMT_NONE ||
927  s->a_transform_type == INT_MIN ||
928  s->coded_width || s->coded_height || s->coded_format != AV_PIX_FMT_NONE) {
929  av_log(avctx, AV_LOG_ERROR, "Invalid dimensions\n");
930  ret = AVERROR(EINVAL);
931  goto end;
932  }
933 
934  if (!got_buffer) {
935  av_log(avctx, AV_LOG_ERROR, "No end of header tag found\n");
936  ret = AVERROR(EINVAL);
937  goto end;
938  }
939 
940  for (plane = 0; plane < s->planes; plane++) {
941  int o, level;
942 
943  for (level = 0; level < (s->transform_type == 0 ? DWT_LEVELS : DWT_LEVELS_3D) ; level++) {
944  if (s->transform_type == 2)
945  if (level == 2 || level == 5)
946  continue;
947  for (o = !!level; o < 4 ; o++) {
948  if (!s->plane[plane].band[level][o].read_ok) {
949  ret = AVERROR_INVALIDDATA;
950  goto end;
951  }
952  }
953  }
954  }
955 
956  if (s->transform_type == 0 && s->sample_type != 1) {
957  for (plane = 0; plane < s->planes && !ret; plane++) {
958  /* level 1 */
959  int lowpass_height = s->plane[plane].band[0][0].height;
960  int output_stride = s->plane[plane].band[0][0].a_width;
961  int lowpass_width = s->plane[plane].band[0][0].width;
962  int highpass_stride = s->plane[plane].band[0][1].stride;
963  int act_plane = plane == 1 ? 2 : plane == 2 ? 1 : plane;
964  ptrdiff_t dst_linesize;
965  int16_t *low, *high, *output, *dst;
966 
967  if (avctx->pix_fmt == AV_PIX_FMT_BAYER_RGGB16) {
968  act_plane = 0;
969  dst_linesize = pic->linesize[act_plane];
970  } else {
971  dst_linesize = pic->linesize[act_plane] / 2;
972  }
973 
974  if (lowpass_height > s->plane[plane].band[0][0].a_height || lowpass_width > s->plane[plane].band[0][0].a_width ||
975  !highpass_stride || s->plane[plane].band[0][1].width > s->plane[plane].band[0][1].a_width ||
976  lowpass_width < 3 || lowpass_height < 3) {
977  av_log(avctx, AV_LOG_ERROR, "Invalid plane dimensions\n");
978  ret = AVERROR(EINVAL);
979  goto end;
980  }
981 
982  av_log(avctx, AV_LOG_DEBUG, "Decoding level 1 plane %i %i %i %i\n", plane, lowpass_height, lowpass_width, highpass_stride);
983 
984  low = s->plane[plane].subband[0];
985  high = s->plane[plane].subband[2];
986  output = s->plane[plane].l_h[0];
987  dsp->vert_filter(output, output_stride, low, lowpass_width, high, highpass_stride, lowpass_width, lowpass_height);
988 
989  low = s->plane[plane].subband[1];
990  high = s->plane[plane].subband[3];
991  output = s->plane[plane].l_h[1];
992 
993  dsp->vert_filter(output, output_stride, low, highpass_stride, high, highpass_stride, lowpass_width, lowpass_height);
994 
995  low = s->plane[plane].l_h[0];
996  high = s->plane[plane].l_h[1];
997  output = s->plane[plane].subband[0];
998  dsp->horiz_filter(output, output_stride, low, output_stride, high, output_stride, lowpass_width, lowpass_height * 2);
999  if (s->bpc == 12) {
1000  output = s->plane[plane].subband[0];
1001  for (i = 0; i < lowpass_height * 2; i++) {
1002  for (j = 0; j < lowpass_width * 2; j++)
1003  output[j] *= 4;
1004 
1005  output += output_stride * 2;
1006  }
1007  }
1008 
1009  /* level 2 */
1010  lowpass_height = s->plane[plane].band[1][1].height;
1011  output_stride = s->plane[plane].band[1][1].a_width;
1012  lowpass_width = s->plane[plane].band[1][1].width;
1013  highpass_stride = s->plane[plane].band[1][1].stride;
1014 
1015  if (lowpass_height > s->plane[plane].band[1][1].a_height || lowpass_width > s->plane[plane].band[1][1].a_width ||
1016  !highpass_stride || s->plane[plane].band[1][1].width > s->plane[plane].band[1][1].a_width ||
1017  lowpass_width < 3 || lowpass_height < 3) {
1018  av_log(avctx, AV_LOG_ERROR, "Invalid plane dimensions\n");
1019  ret = AVERROR(EINVAL);
1020  goto end;
1021  }
1022 
1023  av_log(avctx, AV_LOG_DEBUG, "Level 2 plane %i %i %i %i\n", plane, lowpass_height, lowpass_width, highpass_stride);
1024 
1025  low = s->plane[plane].subband[0];
1026  high = s->plane[plane].subband[5];
1027  output = s->plane[plane].l_h[3];
1028  dsp->vert_filter(output, output_stride, low, output_stride, high, highpass_stride, lowpass_width, lowpass_height);
1029 
1030  low = s->plane[plane].subband[4];
1031  high = s->plane[plane].subband[6];
1032  output = s->plane[plane].l_h[4];
1033  dsp->vert_filter(output, output_stride, low, highpass_stride, high, highpass_stride, lowpass_width, lowpass_height);
1034 
1035  low = s->plane[plane].l_h[3];
1036  high = s->plane[plane].l_h[4];
1037  output = s->plane[plane].subband[0];
1038  dsp->horiz_filter(output, output_stride, low, output_stride, high, output_stride, lowpass_width, lowpass_height * 2);
1039 
1040  output = s->plane[plane].subband[0];
1041  for (i = 0; i < lowpass_height * 2; i++) {
1042  for (j = 0; j < lowpass_width * 2; j++)
1043  output[j] *= 4;
1044 
1045  output += output_stride * 2;
1046  }
1047 
1048  /* level 3 */
1049  lowpass_height = s->plane[plane].band[2][1].height;
1050  output_stride = s->plane[plane].band[2][1].a_width;
1051  lowpass_width = s->plane[plane].band[2][1].width;
1052  highpass_stride = s->plane[plane].band[2][1].stride;
1053 
1054  if (lowpass_height > s->plane[plane].band[2][1].a_height || lowpass_width > s->plane[plane].band[2][1].a_width ||
1055  !highpass_stride || s->plane[plane].band[2][1].width > s->plane[plane].band[2][1].a_width ||
1056  lowpass_height < 3 || lowpass_width < 3 || lowpass_width * 2 > s->plane[plane].width) {
1057  av_log(avctx, AV_LOG_ERROR, "Invalid plane dimensions\n");
1058  ret = AVERROR(EINVAL);
1059  goto end;
1060  }
1061 
1062  av_log(avctx, AV_LOG_DEBUG, "Level 3 plane %i %i %i %i\n", plane, lowpass_height, lowpass_width, highpass_stride);
1063  if (s->progressive) {
1064  low = s->plane[plane].subband[0];
1065  high = s->plane[plane].subband[8];
1066  output = s->plane[plane].l_h[6];
1067  dsp->vert_filter(output, output_stride, low, output_stride, high, highpass_stride, lowpass_width, lowpass_height);
1068 
1069  low = s->plane[plane].subband[7];
1070  high = s->plane[plane].subband[9];
1071  output = s->plane[plane].l_h[7];
1072  dsp->vert_filter(output, output_stride, low, highpass_stride, high, highpass_stride, lowpass_width, lowpass_height);
1073 
1074  dst = (int16_t *)pic->data[act_plane];
1075  if (avctx->pix_fmt == AV_PIX_FMT_BAYER_RGGB16) {
1076  if (plane & 1)
1077  dst++;
1078  if (plane > 1)
1079  dst += pic->linesize[act_plane] >> 1;
1080  }
1081  low = s->plane[plane].l_h[6];
1082  high = s->plane[plane].l_h[7];
1083 
1084  if (avctx->pix_fmt == AV_PIX_FMT_BAYER_RGGB16 &&
1085  (lowpass_height * 2 > avctx->coded_height / 2 ||
1086  lowpass_width * 2 > avctx->coded_width / 2 )
1087  ) {
1088  ret = AVERROR_INVALIDDATA;
1089  goto end;
1090  }
1091 
1092  for (i = 0; i < s->plane[act_plane].height; i++) {
1093  dsp->horiz_filter_clip(dst, low, high, lowpass_width, s->bpc);
1094  if (avctx->pix_fmt == AV_PIX_FMT_GBRAP12 && act_plane == 3)
1095  process_alpha(dst, lowpass_width * 2);
1096  low += output_stride;
1097  high += output_stride;
1098  dst += dst_linesize;
1099  }
1100  } else {
1101  av_log(avctx, AV_LOG_DEBUG, "interlaced frame ? %d", pic->interlaced_frame);
1102  pic->interlaced_frame = 1;
1103  low = s->plane[plane].subband[0];
1104  high = s->plane[plane].subband[7];
1105  output = s->plane[plane].l_h[6];
1106  dsp->horiz_filter(output, output_stride, low, output_stride, high, highpass_stride, lowpass_width, lowpass_height);
1107 
1108  low = s->plane[plane].subband[8];
1109  high = s->plane[plane].subband[9];
1110  output = s->plane[plane].l_h[7];
1111  dsp->horiz_filter(output, output_stride, low, highpass_stride, high, highpass_stride, lowpass_width, lowpass_height);
1112 
1113  dst = (int16_t *)pic->data[act_plane];
1114  low = s->plane[plane].l_h[6];
1115  high = s->plane[plane].l_h[7];
1116  for (i = 0; i < s->plane[act_plane].height / 2; i++) {
1117  interlaced_vertical_filter(dst, low, high, lowpass_width * 2, pic->linesize[act_plane]/2, act_plane);
1118  low += output_stride * 2;
1119  high += output_stride * 2;
1120  dst += pic->linesize[act_plane];
1121  }
1122  }
1123  }
1124  } else if (s->transform_type == 2 && (avctx->internal->is_copy || s->frame_index == 1 || s->sample_type != 1)) {
1125  for (plane = 0; plane < s->planes && !ret; plane++) {
1126  int lowpass_height = s->plane[plane].band[0][0].height;
1127  int output_stride = s->plane[plane].band[0][0].a_width;
1128  int lowpass_width = s->plane[plane].band[0][0].width;
1129  int highpass_stride = s->plane[plane].band[0][1].stride;
1130  int act_plane = plane == 1 ? 2 : plane == 2 ? 1 : plane;
1131  int16_t *low, *high, *output, *dst;
1132  ptrdiff_t dst_linesize;
1133 
1134  if (avctx->pix_fmt == AV_PIX_FMT_BAYER_RGGB16) {
1135  act_plane = 0;
1136  dst_linesize = pic->linesize[act_plane];
1137  } else {
1138  dst_linesize = pic->linesize[act_plane] / 2;
1139  }
1140 
1141  if (lowpass_height > s->plane[plane].band[0][0].a_height || lowpass_width > s->plane[plane].band[0][0].a_width ||
1142  !highpass_stride || s->plane[plane].band[0][1].width > s->plane[plane].band[0][1].a_width ||
1143  lowpass_width < 3 || lowpass_height < 3) {
1144  av_log(avctx, AV_LOG_ERROR, "Invalid plane dimensions\n");
1145  ret = AVERROR(EINVAL);
1146  goto end;
1147  }
1148 
1149  av_log(avctx, AV_LOG_DEBUG, "Decoding level 1 plane %i %i %i %i\n", plane, lowpass_height, lowpass_width, highpass_stride);
1150 
1151  low = s->plane[plane].subband[0];
1152  high = s->plane[plane].subband[2];
1153  output = s->plane[plane].l_h[0];
1154  dsp->vert_filter(output, output_stride, low, lowpass_width, high, highpass_stride, lowpass_width, lowpass_height);
1155 
1156  low = s->plane[plane].subband[1];
1157  high = s->plane[plane].subband[3];
1158  output = s->plane[plane].l_h[1];
1159  dsp->vert_filter(output, output_stride, low, highpass_stride, high, highpass_stride, lowpass_width, lowpass_height);
1160 
1161  low = s->plane[plane].l_h[0];
1162  high = s->plane[plane].l_h[1];
1163  output = s->plane[plane].l_h[7];
1164  dsp->horiz_filter(output, output_stride, low, output_stride, high, output_stride, lowpass_width, lowpass_height * 2);
1165  if (s->bpc == 12) {
1166  output = s->plane[plane].l_h[7];
1167  for (i = 0; i < lowpass_height * 2; i++) {
1168  for (j = 0; j < lowpass_width * 2; j++)
1169  output[j] *= 4;
1170 
1171  output += output_stride * 2;
1172  }
1173  }
1174 
1175  lowpass_height = s->plane[plane].band[1][1].height;
1176  output_stride = s->plane[plane].band[1][1].a_width;
1177  lowpass_width = s->plane[plane].band[1][1].width;
1178  highpass_stride = s->plane[plane].band[1][1].stride;
1179 
1180  if (lowpass_height > s->plane[plane].band[1][1].a_height || lowpass_width > s->plane[plane].band[1][1].a_width ||
1181  !highpass_stride || s->plane[plane].band[1][1].width > s->plane[plane].band[1][1].a_width ||
1182  lowpass_width < 3 || lowpass_height < 3) {
1183  av_log(avctx, AV_LOG_ERROR, "Invalid plane dimensions\n");
1184  ret = AVERROR(EINVAL);
1185  goto end;
1186  }
1187 
1188  av_log(avctx, AV_LOG_DEBUG, "Level 2 lowpass plane %i %i %i %i\n", plane, lowpass_height, lowpass_width, highpass_stride);
1189 
1190  low = s->plane[plane].l_h[7];
1191  high = s->plane[plane].subband[5];
1192  output = s->plane[plane].l_h[3];
1193  dsp->vert_filter(output, output_stride, low, output_stride, high, highpass_stride, lowpass_width, lowpass_height);
1194 
1195  low = s->plane[plane].subband[4];
1196  high = s->plane[plane].subband[6];
1197  output = s->plane[plane].l_h[4];
1198  dsp->vert_filter(output, output_stride, low, highpass_stride, high, highpass_stride, lowpass_width, lowpass_height);
1199 
1200  low = s->plane[plane].l_h[3];
1201  high = s->plane[plane].l_h[4];
1202  output = s->plane[plane].l_h[7];
1203  dsp->horiz_filter(output, output_stride, low, output_stride, high, output_stride, lowpass_width, lowpass_height * 2);
1204 
1205  output = s->plane[plane].l_h[7];
1206  for (i = 0; i < lowpass_height * 2; i++) {
1207  for (j = 0; j < lowpass_width * 2; j++)
1208  output[j] *= 4;
1209  output += output_stride * 2;
1210  }
1211 
1212  low = s->plane[plane].subband[7];
1213  high = s->plane[plane].subband[9];
1214  output = s->plane[plane].l_h[3];
1215  dsp->vert_filter(output, output_stride, low, highpass_stride, high, highpass_stride, lowpass_width, lowpass_height);
1216 
1217  low = s->plane[plane].subband[8];
1218  high = s->plane[plane].subband[10];
1219  output = s->plane[plane].l_h[4];
1220  dsp->vert_filter(output, output_stride, low, highpass_stride, high, highpass_stride, lowpass_width, lowpass_height);
1221 
1222  low = s->plane[plane].l_h[3];
1223  high = s->plane[plane].l_h[4];
1224  output = s->plane[plane].l_h[9];
1225  dsp->horiz_filter(output, output_stride, low, output_stride, high, output_stride, lowpass_width, lowpass_height * 2);
1226 
1227  lowpass_height = s->plane[plane].band[4][1].height;
1228  output_stride = s->plane[plane].band[4][1].a_width;
1229  lowpass_width = s->plane[plane].band[4][1].width;
1230  highpass_stride = s->plane[plane].band[4][1].stride;
1231  av_log(avctx, AV_LOG_DEBUG, "temporal level %i %i %i %i\n", plane, lowpass_height, lowpass_width, highpass_stride);
1232 
1233  if (lowpass_height > s->plane[plane].band[4][1].a_height || lowpass_width > s->plane[plane].band[4][1].a_width ||
1234  !highpass_stride || s->plane[plane].band[4][1].width > s->plane[plane].band[4][1].a_width ||
1235  lowpass_width < 3 || lowpass_height < 3) {
1236  av_log(avctx, AV_LOG_ERROR, "Invalid plane dimensions\n");
1237  ret = AVERROR(EINVAL);
1238  goto end;
1239  }
1240 
1241  low = s->plane[plane].l_h[7];
1242  high = s->plane[plane].l_h[9];
1243  output = s->plane[plane].l_h[7];
1244  for (i = 0; i < lowpass_height; i++) {
1245  inverse_temporal_filter(low, high, lowpass_width);
1246  low += output_stride;
1247  high += output_stride;
1248  }
1249  if (s->progressive) {
1250  low = s->plane[plane].l_h[7];
1251  high = s->plane[plane].subband[15];
1252  output = s->plane[plane].l_h[6];
1253  dsp->vert_filter(output, output_stride, low, output_stride, high, highpass_stride, lowpass_width, lowpass_height);
1254 
1255  low = s->plane[plane].subband[14];
1256  high = s->plane[plane].subband[16];
1257  output = s->plane[plane].l_h[7];
1258  dsp->vert_filter(output, output_stride, low, highpass_stride, high, highpass_stride, lowpass_width, lowpass_height);
1259 
1260  low = s->plane[plane].l_h[9];
1261  high = s->plane[plane].subband[12];
1262  output = s->plane[plane].l_h[8];
1263  dsp->vert_filter(output, output_stride, low, output_stride, high, highpass_stride, lowpass_width, lowpass_height);
1264 
1265  low = s->plane[plane].subband[11];
1266  high = s->plane[plane].subband[13];
1267  output = s->plane[plane].l_h[9];
1268  dsp->vert_filter(output, output_stride, low, highpass_stride, high, highpass_stride, lowpass_width, lowpass_height);
1269 
1270  if (s->sample_type == 1)
1271  continue;
1272 
1273  dst = (int16_t *)pic->data[act_plane];
1274  if (avctx->pix_fmt == AV_PIX_FMT_BAYER_RGGB16) {
1275  if (plane & 1)
1276  dst++;
1277  if (plane > 1)
1278  dst += pic->linesize[act_plane] >> 1;
1279  }
1280 
1281  if (avctx->pix_fmt == AV_PIX_FMT_BAYER_RGGB16 &&
1282  (lowpass_height * 2 > avctx->coded_height / 2 ||
1283  lowpass_width * 2 > avctx->coded_width / 2 )
1284  ) {
1285  ret = AVERROR_INVALIDDATA;
1286  goto end;
1287  }
1288 
1289  low = s->plane[plane].l_h[6];
1290  high = s->plane[plane].l_h[7];
1291  for (i = 0; i < s->plane[act_plane].height; i++) {
1292  dsp->horiz_filter_clip(dst, low, high, lowpass_width, s->bpc);
1293  low += output_stride;
1294  high += output_stride;
1295  dst += dst_linesize;
1296  }
1297  } else {
1298  pic->interlaced_frame = 1;
1299  low = s->plane[plane].l_h[7];
1300  high = s->plane[plane].subband[14];
1301  output = s->plane[plane].l_h[6];
1302  dsp->horiz_filter(output, output_stride, low, output_stride, high, highpass_stride, lowpass_width, lowpass_height);
1303 
1304  low = s->plane[plane].subband[15];
1305  high = s->plane[plane].subband[16];
1306  output = s->plane[plane].l_h[7];
1307  dsp->horiz_filter(output, output_stride, low, highpass_stride, high, highpass_stride, lowpass_width, lowpass_height);
1308 
1309  low = s->plane[plane].l_h[9];
1310  high = s->plane[plane].subband[11];
1311  output = s->plane[plane].l_h[8];
1312  dsp->horiz_filter(output, output_stride, low, output_stride, high, highpass_stride, lowpass_width, lowpass_height);
1313 
1314  low = s->plane[plane].subband[12];
1315  high = s->plane[plane].subband[13];
1316  output = s->plane[plane].l_h[9];
1317  dsp->horiz_filter(output, output_stride, low, highpass_stride, high, highpass_stride, lowpass_width, lowpass_height);
1318 
1319  if (s->sample_type == 1)
1320  continue;
1321 
1322  dst = (int16_t *)pic->data[act_plane];
1323  low = s->plane[plane].l_h[6];
1324  high = s->plane[plane].l_h[7];
1325  for (i = 0; i < s->plane[act_plane].height / 2; i++) {
1326  interlaced_vertical_filter(dst, low, high, lowpass_width * 2, pic->linesize[act_plane]/2, act_plane);
1327  low += output_stride * 2;
1328  high += output_stride * 2;
1329  dst += pic->linesize[act_plane];
1330  }
1331  }
1332  }
1333  }
1334 
1335  if (s->transform_type == 2 && s->sample_type == 1) {
1336  int16_t *low, *high, *dst;
1337  int output_stride, lowpass_height, lowpass_width;
1338  ptrdiff_t dst_linesize;
1339 
1340  for (plane = 0; plane < s->planes; plane++) {
1341  int act_plane = plane == 1 ? 2 : plane == 2 ? 1 : plane;
1342 
1343  if (avctx->pix_fmt == AV_PIX_FMT_BAYER_RGGB16) {
1344  act_plane = 0;
1345  dst_linesize = pic->linesize[act_plane];
1346  } else {
1347  dst_linesize = pic->linesize[act_plane] / 2;
1348  }
1349 
1350  lowpass_height = s->plane[plane].band[4][1].height;
1351  output_stride = s->plane[plane].band[4][1].a_width;
1352  lowpass_width = s->plane[plane].band[4][1].width;
1353 
1354  if (lowpass_height > s->plane[plane].band[4][1].a_height || lowpass_width > s->plane[plane].band[4][1].a_width ||
1355  s->plane[plane].band[4][1].width > s->plane[plane].band[4][1].a_width ||
1356  lowpass_width < 3 || lowpass_height < 3) {
1357  av_log(avctx, AV_LOG_ERROR, "Invalid plane dimensions\n");
1358  ret = AVERROR(EINVAL);
1359  goto end;
1360  }
1361 
1362  if (s->progressive) {
1363  dst = (int16_t *)pic->data[act_plane];
1364  low = s->plane[plane].l_h[8];
1365  high = s->plane[plane].l_h[9];
1366 
1367  if (avctx->pix_fmt == AV_PIX_FMT_BAYER_RGGB16) {
1368  if (plane & 1)
1369  dst++;
1370  if (plane > 1)
1371  dst += pic->linesize[act_plane] >> 1;
1372  }
1373 
1374  if (avctx->pix_fmt == AV_PIX_FMT_BAYER_RGGB16 &&
1375  (lowpass_height * 2 > avctx->coded_height / 2 ||
1376  lowpass_width * 2 > avctx->coded_width / 2 )
1377  ) {
1378  ret = AVERROR_INVALIDDATA;
1379  goto end;
1380  }
1381 
1382  for (i = 0; i < s->plane[act_plane].height; i++) {
1383  dsp->horiz_filter_clip(dst, low, high, lowpass_width, s->bpc);
1384  low += output_stride;
1385  high += output_stride;
1386  dst += dst_linesize;
1387  }
1388  } else {
1389  dst = (int16_t *)pic->data[act_plane];
1390  low = s->plane[plane].l_h[8];
1391  high = s->plane[plane].l_h[9];
1392  for (i = 0; i < s->plane[act_plane].height / 2; i++) {
1393  interlaced_vertical_filter(dst, low, high, lowpass_width * 2, pic->linesize[act_plane]/2, act_plane);
1394  low += output_stride * 2;
1395  high += output_stride * 2;
1396  dst += pic->linesize[act_plane];
1397  }
1398  }
1399  }
1400  }
1401 
1402  if (avctx->pix_fmt == AV_PIX_FMT_BAYER_RGGB16)
1403  process_bayer(pic, s->bpc);
1404 end:
1405  if (ret < 0)
1406  return ret;
1407 
1408  *got_frame = 1;
1409  return avpkt->size;
1410 }
1411 
1413 {
1414  CFHDContext *s = avctx->priv_data;
1415 
1416  free_buffers(s);
1417 
1418  ff_free_vlc(&s->vlc_9);
1419  ff_free_vlc(&s->vlc_18);
1420 
1421  return 0;
1422 }
1423 
1424 #if HAVE_THREADS
1425 static int update_thread_context(AVCodecContext *dst, const AVCodecContext *src)
1426 {
1427  CFHDContext *psrc = src->priv_data;
1428  CFHDContext *pdst = dst->priv_data;
1429  int ret;
1430 
1431  if (dst == src || psrc->transform_type == 0)
1432  return 0;
1433 
1434  if (pdst->plane[0].idwt_size != psrc->plane[0].idwt_size ||
1435  pdst->a_format != psrc->a_format ||
1436  pdst->a_width != psrc->a_width ||
1437  pdst->a_height != psrc->a_height ||
1438  pdst->a_transform_type != psrc->a_transform_type)
1439  free_buffers(pdst);
1440 
1441  pdst->a_format = psrc->a_format;
1442  pdst->a_width = psrc->a_width;
1443  pdst->a_height = psrc->a_height;
1444  pdst->a_transform_type = psrc->a_transform_type;
1445  pdst->transform_type = psrc->transform_type;
1446  pdst->progressive = psrc->progressive;
1447  pdst->planes = psrc->planes;
1448 
1449  if (!pdst->plane[0].idwt_buf) {
1450  pdst->coded_width = pdst->a_width;
1451  pdst->coded_height = pdst->a_height;
1452  pdst->coded_format = pdst->a_format;
1453  pdst->transform_type = pdst->a_transform_type;
1454  ret = alloc_buffers(dst);
1455  if (ret < 0)
1456  return ret;
1457  }
1458 
1459  for (int plane = 0; plane < pdst->planes; plane++) {
1460  memcpy(pdst->plane[plane].band, psrc->plane[plane].band, sizeof(pdst->plane[plane].band));
1461  memcpy(pdst->plane[plane].idwt_buf, psrc->plane[plane].idwt_buf,
1462  pdst->plane[plane].idwt_size * sizeof(int16_t));
1463  }
1464 
1465  return 0;
1466 }
1467 #endif
1468 
1470  .name = "cfhd",
1471  .long_name = NULL_IF_CONFIG_SMALL("GoPro CineForm HD"),
1472  .type = AVMEDIA_TYPE_VIDEO,
1473  .id = AV_CODEC_ID_CFHD,
1474  .priv_data_size = sizeof(CFHDContext),
1475  .init = cfhd_init,
1476  .close = cfhd_close,
1477  .decode = cfhd_decode,
1478  .update_thread_context = ONLY_IF_THREADS_ENABLED(update_thread_context),
1479  .capabilities = AV_CODEC_CAP_DR1 | AV_CODEC_CAP_FRAME_THREADS,
1481 };
int32_t SampleType
Definition: ac3enc.h:63
static double val(void *priv, double ch)
Definition: aeval.c:76
Macro definitions for various function/variable attributes.
#define av_cold
Definition: attributes.h:88
static av_always_inline int even(uint64_t layout)
#define av_assert0(cond)
assert() equivalent, that is always enabled.
Definition: avassert.h:37
Libavcodec external API header.
static av_cold int init(AVCodecContext *avctx)
Definition: avrndec.c:31
void ff_free_vlc(VLC *vlc)
Definition: bitstream.c:431
refcounted data buffer API
static av_always_inline void bytestream2_skipu(GetByteContext *g, unsigned int size)
Definition: bytestream.h:174
static av_always_inline int bytestream2_get_bytes_left(GetByteContext *g)
Definition: bytestream.h:158
static av_always_inline void bytestream2_init(GetByteContext *g, const uint8_t *buf, int buf_size)
Definition: bytestream.h:137
static av_always_inline int bytestream2_seek(GetByteContext *g, int offset, int whence)
Definition: bytestream.h:212
static av_always_inline int bytestream2_tell(GetByteContext *g)
Definition: bytestream.h:192
#define s(width, name)
Definition: cbs_vp9.c:257
static void difference_coding(int16_t *band, int width, int height)
Definition: cfhd.c:117
static av_cold int cfhd_init(AVCodecContext *avctx)
Definition: cfhd.c:43
static void interlaced_vertical_filter(int16_t *output, int16_t *low, int16_t *high, int width, int linesize, int plane)
Definition: cfhd.c:195
static void inverse_temporal_filter(int16_t *low, int16_t *high, int width)
Definition: cfhd.c:208
#define ALPHA_COMPAND_GAIN
Definition: cfhd.c:41
static void init_plane_defaults(CFHDContext *s)
Definition: cfhd.c:73
static void process_alpha(int16_t *alpha, int width)
Definition: cfhd.c:137
static int cfhd_decode(AVCodecContext *avctx, void *data, int *got_frame, AVPacket *avpkt)
Definition: cfhd.c:378
static int alloc_buffers(AVCodecContext *avctx)
Definition: cfhd.c:246
static void init_frame_defaults(CFHDContext *s)
Definition: cfhd.c:87
#define ALPHA_COMPAND_DC_OFFSET
Definition: cfhd.c:40
static void process_bayer(AVFrame *frame, int bpc)
Definition: cfhd.c:151
static void peak_table(int16_t *band, Peak *peak, int length)
Definition: cfhd.c:129
static av_cold int cfhd_close(AVCodecContext *avctx)
Definition: cfhd.c:1412
static void init_peak_table_defaults(CFHDContext *s)
Definition: cfhd.c:80
static void free_buffers(CFHDContext *s)
Definition: cfhd.c:219
AVCodec ff_cfhd_decoder
Definition: cfhd.c:1469
static int dequant_and_decompand(CFHDContext *s, int level, int quantisation, int codebook)
Definition: cfhd.c:109
#define DWT_LEVELS
Definition: cfhd.h:117
@ CoefficientSegment
Definition: cfhd.h:104
int ff_cfhd_init_vlcs(CFHDContext *s)
Definition: cfhddata.c:276
#define SUBBAND_COUNT
Definition: cfhd.h:108
#define VLC_BITS
Definition: cfhd.h:107
@ Quantization
Definition: cfhd.h:76
@ SampleFlags
Definition: cfhd.h:81
@ BandHeight
Definition: cfhd.h:73
@ HighpassWidth
Definition: cfhd.h:65
@ SampleIndexTable
Definition: cfhd.h:36
@ VersionMajor
Definition: cfhd.h:38
@ EncodedFormat
Definition: cfhd.h:92
@ BandWidth
Definition: cfhd.h:72
@ PeakOffsetLow
Definition: cfhd.h:87
@ LowpassHeight
Definition: cfhd.h:57
@ BandSecondPass
Definition: cfhd.h:90
@ LowpassPrecision
Definition: cfhd.h:60
@ SubbandNumber
Definition: cfhd.h:71
@ BandHeader
Definition: cfhd.h:78
@ BitstreamMarker
Definition: cfhd.h:37
@ PeakLevel
Definition: cfhd.h:86
@ PrescaleTable
Definition: cfhd.h:91
@ HighpassHeight
Definition: cfhd.h:66
@ VersionEdit
Definition: cfhd.h:41
@ ImageWidth
Definition: cfhd.h:51
@ LowpassWidth
Definition: cfhd.h:56
@ BandEncoding
Definition: cfhd.h:75
@ DisplayHeight
Definition: cfhd.h:93
@ PeakOffsetHigh
Definition: cfhd.h:88
@ BandCodingFlags
Definition: cfhd.h:85
@ Version
Definition: cfhd.h:89
@ Precision
Definition: cfhd.h:83
@ VersionRevision
Definition: cfhd.h:40
@ ChannelCount
Definition: cfhd.h:44
@ ImageHeight
Definition: cfhd.h:52
@ SubbandBand
Definition: cfhd.h:74
@ ChannelNumber
Definition: cfhd.h:80
@ VersionMinor
Definition: cfhd.h:39
@ SubbandCount
Definition: cfhd.h:46
@ InputFormat
Definition: cfhd.h:84
@ FrameIndex
Definition: cfhd.h:53
#define DWT_LEVELS_3D
Definition: cfhd.h:118
#define SUBBAND_COUNT_3D
Definition: cfhd.h:109
av_cold void ff_cfhddsp_init(CFHDDSPContext *c, int depth, int bayer)
Definition: cfhddsp.c:106
static const unsigned codebook[256][2]
Definition: cfhdenc.c:42
common internal and external API header
#define AV_CEIL_RSHIFT(a, b)
Definition: common.h:58
#define av_clip_uintp2
Definition: common.h:146
#define FFSIGN(a)
Definition: common.h:73
#define NULL
Definition: coverity.c:32
#define abs(x)
Definition: cuda_runtime.h:35
static void decode(AVCodecContext *dec_ctx, AVPacket *pkt, AVFrame *frame, FILE *outfile)
Definition: decode_audio.c:71
static AVFrame * frame
channel
Use these values when setting the channel map with ebur128_set_channel().
Definition: ebur128.h:39
float re
Definition: fft.c:82
FrameType
G723.1 frame types.
Definition: g723_1.h:63
bitstream reader API header.
#define CLOSE_READER(name, gb)
Definition: get_bits.h:149
#define OPEN_READER(name, gb)
Definition: get_bits.h:138
#define GET_RL_VLC(level, run, name, gb, table, bits, max_depth, need_update)
Definition: get_bits.h:738
#define UPDATE_CACHE(name, gb)
Definition: get_bits.h:178
static int init_get_bits8(GetBitContext *s, const uint8_t *buffer, int byte_size)
Initialize GetBitContext.
Definition: get_bits.h:677
static int get_bits_count(const GetBitContext *s)
Definition: get_bits.h:219
#define AV_CODEC_CAP_DR1
Codec uses get_buffer() or get_encode_buffer() for allocating buffers and supports custom allocators.
Definition: codec.h:52
#define AV_CODEC_CAP_FRAME_THREADS
Codec supports frame-level multithreading.
Definition: codec.h:108
@ AV_CODEC_ID_CFHD
Definition: codec_id.h:266
#define AVERROR_PATCHWELCOME
Not yet implemented in FFmpeg, patches welcome.
Definition: error.h:62
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
Definition: error.h:59
#define AVERROR(e)
Definition: error.h:43
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
Definition: log.h:215
#define AV_LOG_WARNING
Something somehow does not look correct.
Definition: log.h:200
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition: log.h:194
void * av_mallocz_array(size_t nmemb, size_t size)
Allocate a memory block for an array with av_mallocz().
Definition: mem.c:190
@ AVMEDIA_TYPE_VIDEO
Definition: avutil.h:201
int av_image_check_size2(unsigned int w, unsigned int h, int64_t max_pixels, enum AVPixelFormat pix_fmt, int log_offset, void *log_ctx)
Check if the given dimension of an image is valid, meaning that all bytes of a plane of an image with...
Definition: imgutils.c:288
for(j=16;j >0;--j)
#define B
Definition: huffyuvdsp.h:32
#define R
Definition: huffyuvdsp.h:34
static const int16_t alpha[]
Definition: ilbcdata.h:55
misc image utilities
int i
Definition: input.c:407
#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:41
#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:49
int ff_set_dimensions(AVCodecContext *s, int width, int height)
Check that the provided frame dimensions are valid and set them on the codec context.
Definition: utils.c:84
common internal API header
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification.
Definition: internal.h:117
void avpriv_report_missing_feature(void *avc, const char *msg,...) av_printf_format(2
Log a generic warning message about a missing feature.
#define ONLY_IF_THREADS_ENABLED(x)
Define a function with only the non-default version specified.
Definition: internal.h:156
static const struct @322 planes[]
int stride
Definition: mace.c:144
#define FFALIGN(x, a)
Definition: macros.h:48
uint32_t tag
Definition: movenc.c:1611
const char data[16]
Definition: mxf.c:142
AVOptions.
int av_pix_fmt_count_planes(enum AVPixelFormat pix_fmt)
Definition: pixdesc.c:2613
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:2601
#define AV_PIX_FMT_GBRAP12
Definition: pixfmt.h:420
#define AV_PIX_FMT_YUV422P10
Definition: pixfmt.h:400
#define AV_PIX_FMT_GBRP12
Definition: pixfmt.h:416
#define AV_PIX_FMT_BAYER_RGGB16
Definition: pixfmt.h:424
@ AV_PIX_FMT_NONE
Definition: pixfmt.h:65
FF_ENABLE_DEPRECATION_WARNINGS int ff_thread_get_buffer(AVCodecContext *avctx, ThreadFrame *f, int flags)
Wrapper around get_buffer() for frame-multithreaded codecs.
void ff_thread_finish_setup(AVCodecContext *avctx)
If the codec defines update_thread_context(), call this when they are ready for the next thread to st...
#define FF_ARRAY_ELEMS(a)
main external API structure.
Definition: avcodec.h:536
enum AVPixelFormat pix_fmt
Pixel format, see AV_PIX_FMT_xxx.
Definition: avcodec.h:746
int64_t max_pixels
The number of pixels per image to maximally accept.
Definition: avcodec.h:2252
int bits_per_raw_sample
Bits per sample/pixel of internal libavcodec pixel/sample format.
Definition: avcodec.h:1751
int coded_height
Definition: avcodec.h:724
int coded_width
Bitstream width / height, may be different from width/height e.g.
Definition: avcodec.h:724
struct AVCodecInternal * internal
Private context used for internal data.
Definition: avcodec.h:571
void * priv_data
Definition: avcodec.h:563
int is_copy
Whether the parent AVCodecContext is a copy of the context which had init() called on it.
Definition: internal.h:136
AVCodec.
Definition: codec.h:197
const char * name
Name of the codec implementation.
Definition: codec.h:204
This structure describes decoded (raw) audio or video data.
Definition: frame.h:318
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
Definition: frame.h:332
int width
Definition: frame.h:376
int height
Definition: frame.h:376
int interlaced_frame
The content of the picture is interlaced.
Definition: frame.h:465
int linesize[AV_NUM_DATA_POINTERS]
For video, size in bytes of each picture line.
Definition: frame.h:349
This structure stores compressed data.
Definition: packet.h:346
int size
Definition: packet.h:370
uint8_t * data
Definition: packet.h:369
enum AVPixelFormat coded_format
Definition: cfhd.h:172
int a_format
Definition: cfhd.h:177
Plane plane[4]
Definition: cfhd.h:195
int coded_width
Definition: cfhd.h:169
int planes
Definition: cfhd.h:164
int a_transform_type
Definition: cfhd.h:178
int progressive
Definition: cfhd.h:173
int transform_type
Definition: cfhd.h:168
int a_height
Definition: cfhd.h:176
int a_width
Definition: cfhd.h:175
int coded_height
Definition: cfhd.h:170
void(* horiz_filter_clip)(int16_t *output, const int16_t *low, const int16_t *high, int width, int bpc)
Definition: cfhddsp.h:36
void(* vert_filter)(int16_t *output, ptrdiff_t out_stride, const int16_t *low, ptrdiff_t low_stride, const int16_t *high, ptrdiff_t high_stride, int width, int height)
Definition: cfhddsp.h:31
void(* horiz_filter)(int16_t *output, ptrdiff_t out_stride, const int16_t *low, ptrdiff_t low_stride, const int16_t *high, ptrdiff_t high_stride, int width, int height)
Definition: cfhddsp.h:26
const uint8_t * buffer
Definition: bytestream.h:34
Definition: cfhd.h:145
GetByteContext base
Definition: cfhd.h:148
int level
Definition: cfhd.h:146
Definition: cfhd.h:129
int idwt_size
Definition: cfhd.h:136
SubBand band[DWT_LEVELS_3D][4]
Definition: cfhd.h:142
int16_t * idwt_buf
Definition: cfhd.h:134
int8_t read_ok
Definition: cfhd.h:126
uint8_t run
Definition: svq3.c:205
uint8_t level
Definition: svq3.c:206
#define av_malloc_array(a, b)
#define av_freep(p)
#define av_log(a,...)
#define src
Definition: vp8dsp.c:255
static void finish(void)
Definition: movenc.c:342
#define height
#define width
const char * b
Definition: vf_curves.c:118
const char * g
Definition: vf_curves.c:117
const char * r
Definition: vf_curves.c:116
if(ret< 0)
Definition: vf_mcdeint.c:282
static const double coeff[2][5]
Definition: vf_owdenoise.c:73
static const int factor[16]
Definition: vf_pp7.c:77
static const uint8_t offset[127][2]
Definition: vf_spp.c:107
TransformType
Definition: webp.c:110