FFmpeg  4.4.9
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  for (unsigned k = 0; k < FF_ARRAY_ELEMS(p->band[j]); k++) {
237  p->band[j][k].a_width = 0;
238  p->band[j][k].a_height = 0;
239  p->band[j][k].read_ok = 0;
240  }
241  }
242  s->a_height = 0;
243  s->a_width = 0;
244  s->a_transform_type = INT_MIN;
245 }
246 
247 static int alloc_buffers(AVCodecContext *avctx)
248 {
249  CFHDContext *s = avctx->priv_data;
250  int i, j, ret, planes, bayer = 0;
251  int chroma_x_shift, chroma_y_shift;
252  unsigned k;
253 
254  if ((ret = ff_set_dimensions(avctx, s->coded_width, s->coded_height)) < 0)
255  return ret;
256  avctx->pix_fmt = s->coded_format;
257 
258  ff_cfhddsp_init(&s->dsp, s->bpc, avctx->pix_fmt == AV_PIX_FMT_BAYER_RGGB16);
259 
260  if ((ret = av_pix_fmt_get_chroma_sub_sample(s->coded_format,
261  &chroma_x_shift,
262  &chroma_y_shift)) < 0)
263  return ret;
264  planes = av_pix_fmt_count_planes(s->coded_format);
265  if (s->coded_format == AV_PIX_FMT_BAYER_RGGB16) {
266  planes = 4;
267  chroma_x_shift = 1;
268  chroma_y_shift = 1;
269  bayer = 1;
270  }
271 
272  for (i = 0; i < planes; i++) {
273  int w8, h8, w4, h4, w2, h2;
274  int width = (i || bayer) ? s->coded_width >> chroma_x_shift : s->coded_width;
275  int height = (i || bayer) ? s->coded_height >> chroma_y_shift : s->coded_height;
276  ptrdiff_t stride = (FFALIGN(width / 8, 8) + 64) * 8;
277 
278  if ((ret = av_image_check_size2(stride, height, avctx->max_pixels, s->coded_format, 0, avctx)) < 0)
279  return ret;
280 
281  if (chroma_y_shift && !bayer)
282  height = FFALIGN(height / 8, 2) * 8;
283  s->plane[i].width = width;
284  s->plane[i].height = height;
285  s->plane[i].stride = stride;
286 
287  w8 = FFALIGN(s->plane[i].width / 8, 8) + 64;
288  h8 = FFALIGN(height, 8) / 8;
289  w4 = w8 * 2;
290  h4 = h8 * 2;
291  w2 = w4 * 2;
292  h2 = h4 * 2;
293 
294  if (s->transform_type == 0) {
295  s->plane[i].idwt_size = FFALIGN(height, 8) * stride;
296  s->plane[i].idwt_buf =
297  av_mallocz_array(s->plane[i].idwt_size, sizeof(*s->plane[i].idwt_buf));
298  s->plane[i].idwt_tmp =
299  av_calloc(s->plane[i].idwt_size, sizeof(*s->plane[i].idwt_tmp));
300  } else {
301  s->plane[i].idwt_size = FFALIGN(height, 8) * stride * 2;
302  s->plane[i].idwt_buf =
303  av_mallocz_array(s->plane[i].idwt_size, sizeof(*s->plane[i].idwt_buf));
304  s->plane[i].idwt_tmp =
305  av_calloc(s->plane[i].idwt_size, sizeof(*s->plane[i].idwt_tmp));
306  }
307 
308  if (!s->plane[i].idwt_buf || !s->plane[i].idwt_tmp)
309  return AVERROR(ENOMEM);
310 
311  s->plane[i].subband[0] = s->plane[i].idwt_buf;
312  s->plane[i].subband[1] = s->plane[i].idwt_buf + 2 * w8 * h8;
313  s->plane[i].subband[2] = s->plane[i].idwt_buf + 1 * w8 * h8;
314  s->plane[i].subband[3] = s->plane[i].idwt_buf + 3 * w8 * h8;
315  s->plane[i].subband[4] = s->plane[i].idwt_buf + 2 * w4 * h4;
316  s->plane[i].subband[5] = s->plane[i].idwt_buf + 1 * w4 * h4;
317  s->plane[i].subband[6] = s->plane[i].idwt_buf + 3 * w4 * h4;
318  if (s->transform_type == 0) {
319  s->plane[i].subband[7] = s->plane[i].idwt_buf + 2 * w2 * h2;
320  s->plane[i].subband[8] = s->plane[i].idwt_buf + 1 * w2 * h2;
321  s->plane[i].subband[9] = s->plane[i].idwt_buf + 3 * w2 * h2;
322  } else {
323  int16_t *frame2 =
324  s->plane[i].subband[7] = s->plane[i].idwt_buf + 4 * w2 * h2;
325  s->plane[i].subband[8] = frame2 + 2 * w4 * h4;
326  s->plane[i].subband[9] = frame2 + 1 * w4 * h4;
327  s->plane[i].subband[10] = frame2 + 3 * w4 * h4;
328  s->plane[i].subband[11] = frame2 + 2 * w2 * h2;
329  s->plane[i].subband[12] = frame2 + 1 * w2 * h2;
330  s->plane[i].subband[13] = frame2 + 3 * w2 * h2;
331  s->plane[i].subband[14] = s->plane[i].idwt_buf + 2 * w2 * h2;
332  s->plane[i].subband[15] = s->plane[i].idwt_buf + 1 * w2 * h2;
333  s->plane[i].subband[16] = s->plane[i].idwt_buf + 3 * w2 * h2;
334  }
335 
336  if (s->transform_type == 0) {
337  for (j = 0; j < DWT_LEVELS; j++) {
338  for (k = 0; k < FF_ARRAY_ELEMS(s->plane[i].band[j]); k++) {
339  s->plane[i].band[j][k].a_width = w8 << j;
340  s->plane[i].band[j][k].a_height = h8 << j;
341  }
342  }
343  } else {
344  for (j = 0; j < DWT_LEVELS_3D; j++) {
345  int t = j < 1 ? 0 : (j < 3 ? 1 : 2);
346 
347  for (k = 0; k < FF_ARRAY_ELEMS(s->plane[i].band[j]); k++) {
348  s->plane[i].band[j][k].a_width = w8 << t;
349  s->plane[i].band[j][k].a_height = h8 << t;
350  }
351  }
352  }
353 
354  /* ll2 and ll1 commented out because they are done in-place */
355  s->plane[i].l_h[0] = s->plane[i].idwt_tmp;
356  s->plane[i].l_h[1] = s->plane[i].idwt_tmp + 2 * w8 * h8;
357  // s->plane[i].l_h[2] = ll2;
358  s->plane[i].l_h[3] = s->plane[i].idwt_tmp;
359  s->plane[i].l_h[4] = s->plane[i].idwt_tmp + 2 * w4 * h4;
360  // s->plane[i].l_h[5] = ll1;
361  s->plane[i].l_h[6] = s->plane[i].idwt_tmp;
362  s->plane[i].l_h[7] = s->plane[i].idwt_tmp + 2 * w2 * h2;
363  if (s->transform_type != 0) {
364  int16_t *frame2 = s->plane[i].idwt_tmp + 4 * w2 * h2;
365 
366  s->plane[i].l_h[8] = frame2;
367  s->plane[i].l_h[9] = frame2 + 2 * w2 * h2;
368  }
369  }
370 
371  s->a_transform_type = s->transform_type;
372  s->a_height = s->coded_height;
373  s->a_width = s->coded_width;
374  s->a_format = s->coded_format;
375 
376  return 0;
377 }
378 
379 static int cfhd_decode(AVCodecContext *avctx, void *data, int *got_frame,
380  AVPacket *avpkt)
381 {
382  CFHDContext *s = avctx->priv_data;
383  CFHDDSPContext *dsp = &s->dsp;
384  GetByteContext gb;
385  ThreadFrame frame = { .f = data };
386  AVFrame *pic = data;
387  int ret = 0, i, j, plane, got_buffer = 0;
388  int16_t *coeff_data;
389 
391  s->planes = av_pix_fmt_count_planes(s->coded_format);
392 
393  bytestream2_init(&gb, avpkt->data, avpkt->size);
394 
395  while (bytestream2_get_bytes_left(&gb) >= 4) {
396  /* Bit weird but implement the tag parsing as the spec says */
397  uint16_t tagu = bytestream2_get_be16(&gb);
398  int16_t tag = (int16_t)tagu;
399  int8_t tag8 = (int8_t)(tagu >> 8);
400  uint16_t abstag = abs(tag);
401  int8_t abs_tag8 = abs(tag8);
402  uint16_t data = bytestream2_get_be16(&gb);
403  if (abs_tag8 >= 0x60 && abs_tag8 <= 0x6f) {
404  av_log(avctx, AV_LOG_DEBUG, "large len %x\n", ((tagu & 0xff) << 16) | data);
405  } else if (tag == SampleFlags) {
406  av_log(avctx, AV_LOG_DEBUG, "Progressive? %"PRIu16"\n", data);
407  s->progressive = data & 0x0001;
408  } else if (tag == FrameType) {
409  s->frame_type = data;
410  av_log(avctx, AV_LOG_DEBUG, "Frame type %"PRIu16"\n", data);
411  } else if (abstag == VersionMajor) {
412  av_log(avctx, AV_LOG_DEBUG, "Version major %"PRIu16"\n", data);
413  } else if (abstag == VersionMinor) {
414  av_log(avctx, AV_LOG_DEBUG, "Version minor %"PRIu16"\n", data);
415  } else if (abstag == VersionRevision) {
416  av_log(avctx, AV_LOG_DEBUG, "Version revision %"PRIu16"\n", data);
417  } else if (abstag == VersionEdit) {
418  av_log(avctx, AV_LOG_DEBUG, "Version edit %"PRIu16"\n", data);
419  } else if (abstag == Version) {
420  av_log(avctx, AV_LOG_DEBUG, "Version %"PRIu16"\n", data);
421  } else if (tag == ImageWidth) {
422  av_log(avctx, AV_LOG_DEBUG, "Width %"PRIu16"\n", data);
423  s->coded_width = data;
424  } else if (tag == ImageHeight) {
425  av_log(avctx, AV_LOG_DEBUG, "Height %"PRIu16"\n", data);
426  s->coded_height = data;
427  } else if (tag == ChannelCount) {
428  av_log(avctx, AV_LOG_DEBUG, "Channel Count: %"PRIu16"\n", data);
429  s->channel_cnt = data;
430  if (data > 4) {
431  av_log(avctx, AV_LOG_ERROR, "Channel Count of %"PRIu16" is unsupported\n", data);
432  ret = AVERROR_PATCHWELCOME;
433  goto end;
434  }
435  } else if (tag == SubbandCount) {
436  av_log(avctx, AV_LOG_DEBUG, "Subband Count: %"PRIu16"\n", data);
437  if (data != SUBBAND_COUNT && data != SUBBAND_COUNT_3D) {
438  av_log(avctx, AV_LOG_ERROR, "Subband Count of %"PRIu16" is unsupported\n", data);
439  ret = AVERROR_PATCHWELCOME;
440  goto end;
441  }
442  } else if (tag == ChannelNumber) {
443  s->channel_num = data;
444  av_log(avctx, AV_LOG_DEBUG, "Channel number %"PRIu16"\n", data);
446  } else if (tag == SubbandNumber) {
447  if (s->subband_num != 0 && data == 1 && (s->transform_type == 0 || s->transform_type == 2)) // hack
448  s->level++;
449  av_log(avctx, AV_LOG_DEBUG, "Subband number %"PRIu16"\n", data);
450  s->subband_num = data;
451  if ((s->transform_type == 0 && s->level >= DWT_LEVELS) ||
452  (s->transform_type == 2 && s->level >= DWT_LEVELS_3D)) {
453  av_log(avctx, AV_LOG_ERROR, "Invalid level\n");
454  ret = AVERROR(EINVAL);
455  goto end;
456  }
457  if (s->subband_num > 3) {
458  av_log(avctx, AV_LOG_ERROR, "Invalid subband number\n");
459  ret = AVERROR(EINVAL);
460  goto end;
461  }
462  } else if (tag == SubbandBand) {
463  av_log(avctx, AV_LOG_DEBUG, "Subband number actual %"PRIu16"\n", data);
464  if ((s->transform_type == 0 && data >= SUBBAND_COUNT) ||
465  (s->transform_type == 2 && data >= SUBBAND_COUNT_3D && data != 255)) {
466  av_log(avctx, AV_LOG_ERROR, "Invalid subband number actual\n");
467  ret = AVERROR(EINVAL);
468  goto end;
469  }
470  if (s->transform_type == 0 || s->transform_type == 2)
471  s->subband_num_actual = data;
472  else
473  av_log(avctx, AV_LOG_WARNING, "Ignoring subband num actual %"PRIu16"\n", data);
474  } else if (tag == LowpassPrecision)
475  av_log(avctx, AV_LOG_DEBUG, "Lowpass precision bits: %"PRIu16"\n", data);
476  else if (tag == Quantization) {
477  s->quantisation = data;
478  av_log(avctx, AV_LOG_DEBUG, "Quantisation: %"PRIu16"\n", data);
479  } else if (tag == PrescaleTable) {
480  for (i = 0; i < 8; i++)
481  s->prescale_table[i] = (data >> (14 - i * 2)) & 0x3;
482  av_log(avctx, AV_LOG_DEBUG, "Prescale table: %x\n", data);
483  } else if (tag == BandEncoding) {
484  if (!data || data > 5) {
485  av_log(avctx, AV_LOG_ERROR, "Invalid band encoding\n");
486  ret = AVERROR(EINVAL);
487  goto end;
488  }
489  s->band_encoding = data;
490  av_log(avctx, AV_LOG_DEBUG, "Encode Method for Subband %d : %x\n", s->subband_num_actual, data);
491  } else if (tag == LowpassWidth) {
492  av_log(avctx, AV_LOG_DEBUG, "Lowpass width %"PRIu16"\n", data);
493  s->plane[s->channel_num].band[0][0].width = data;
494  s->plane[s->channel_num].band[0][0].stride = data;
495  } else if (tag == LowpassHeight) {
496  av_log(avctx, AV_LOG_DEBUG, "Lowpass height %"PRIu16"\n", data);
497  s->plane[s->channel_num].band[0][0].height = data;
498  } else if (tag == SampleType) {
499  s->sample_type = data;
500  av_log(avctx, AV_LOG_DEBUG, "Sample type? %"PRIu16"\n", data);
501  } else if (tag == TransformType) {
502  if (data > 2) {
503  av_log(avctx, AV_LOG_ERROR, "Invalid transform type\n");
504  ret = AVERROR(EINVAL);
505  goto end;
506  } else if (data == 1) {
507  av_log(avctx, AV_LOG_ERROR, "unsupported transform type\n");
508  ret = AVERROR_PATCHWELCOME;
509  goto end;
510  }
511  if (s->transform_type == -1) {
512  s->transform_type = data;
513  av_log(avctx, AV_LOG_DEBUG, "Transform type %"PRIu16"\n", data);
514  } else {
515  av_log(avctx, AV_LOG_DEBUG, "Ignoring additional transform type %"PRIu16"\n", data);
516  }
517  } else if (abstag >= 0x4000 && abstag <= 0x40ff) {
518  if (abstag == 0x4001)
519  s->peak.level = 0;
520  av_log(avctx, AV_LOG_DEBUG, "Small chunk length %d %s\n", data * 4, tag < 0 ? "optional" : "required");
521  bytestream2_skipu(&gb, data * 4);
522  } else if (tag == FrameIndex) {
523  av_log(avctx, AV_LOG_DEBUG, "Frame index %"PRIu16"\n", data);
524  s->frame_index = data;
525  } else if (tag == SampleIndexTable) {
526  av_log(avctx, AV_LOG_DEBUG, "Sample index table - skipping %i values\n", data);
527  if (data > bytestream2_get_bytes_left(&gb) / 4) {
528  av_log(avctx, AV_LOG_ERROR, "too many values (%d)\n", data);
529  ret = AVERROR_INVALIDDATA;
530  goto end;
531  }
532  for (i = 0; i < data; i++) {
533  uint32_t offset = bytestream2_get_be32(&gb);
534  av_log(avctx, AV_LOG_DEBUG, "Offset = %"PRIu32"\n", offset);
535  }
536  } else if (tag == HighpassWidth) {
537  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);
538  if (data < 3) {
539  av_log(avctx, AV_LOG_ERROR, "Invalid highpass width\n");
540  ret = AVERROR(EINVAL);
541  goto end;
542  }
543  s->plane[s->channel_num].band[s->level][s->subband_num].width = data;
544  s->plane[s->channel_num].band[s->level][s->subband_num].stride = FFALIGN(data, 8);
545  } else if (tag == HighpassHeight) {
546  av_log(avctx, AV_LOG_DEBUG, "Highpass height %i\n", data);
547  if (data < 3) {
548  av_log(avctx, AV_LOG_ERROR, "Invalid highpass height\n");
549  ret = AVERROR(EINVAL);
550  goto end;
551  }
552  s->plane[s->channel_num].band[s->level][s->subband_num].height = data;
553  } else if (tag == BandWidth) {
554  av_log(avctx, AV_LOG_DEBUG, "Highpass width2 %i\n", data);
555  if (data < 3) {
556  av_log(avctx, AV_LOG_ERROR, "Invalid highpass width2\n");
557  ret = AVERROR(EINVAL);
558  goto end;
559  }
560  s->plane[s->channel_num].band[s->level][s->subband_num].width = data;
561  s->plane[s->channel_num].band[s->level][s->subband_num].stride = FFALIGN(data, 8);
562  } else if (tag == BandHeight) {
563  av_log(avctx, AV_LOG_DEBUG, "Highpass height2 %i\n", data);
564  if (data < 3) {
565  av_log(avctx, AV_LOG_ERROR, "Invalid highpass height2\n");
566  ret = AVERROR(EINVAL);
567  goto end;
568  }
569  s->plane[s->channel_num].band[s->level][s->subband_num].height = data;
570  } else if (tag == InputFormat) {
571  av_log(avctx, AV_LOG_DEBUG, "Input format %i\n", data);
572  if (s->coded_format == AV_PIX_FMT_NONE ||
573  s->coded_format == AV_PIX_FMT_YUV422P10) {
574  if (data >= 100 && data <= 105) {
575  s->coded_format = AV_PIX_FMT_BAYER_RGGB16;
576  } else if (data >= 122 && data <= 128) {
577  s->coded_format = AV_PIX_FMT_GBRP12;
578  } else if (data == 30) {
579  s->coded_format = AV_PIX_FMT_GBRAP12;
580  } else {
581  s->coded_format = AV_PIX_FMT_YUV422P10;
582  }
583  s->planes = s->coded_format == AV_PIX_FMT_BAYER_RGGB16 ? 4 : av_pix_fmt_count_planes(s->coded_format);
584  }
585  } else if (tag == BandCodingFlags) {
586  s->codebook = data & 0xf;
587  s->difference_coding = (data >> 4) & 1;
588  av_log(avctx, AV_LOG_DEBUG, "Other codebook? %i\n", s->codebook);
589  } else if (tag == Precision) {
590  av_log(avctx, AV_LOG_DEBUG, "Precision %i\n", data);
591  if (!(data == 10 || data == 12)) {
592  av_log(avctx, AV_LOG_ERROR, "Invalid bits per channel\n");
593  ret = AVERROR(EINVAL);
594  goto end;
595  }
596  avctx->bits_per_raw_sample = s->bpc = data;
597  } else if (tag == EncodedFormat) {
598  av_log(avctx, AV_LOG_DEBUG, "Sample format? %i\n", data);
599  if (data == 1) {
600  s->coded_format = AV_PIX_FMT_YUV422P10;
601  } else if (data == 2) {
602  s->coded_format = AV_PIX_FMT_BAYER_RGGB16;
603  } else if (data == 3) {
604  s->coded_format = AV_PIX_FMT_GBRP12;
605  } else if (data == 4) {
606  s->coded_format = AV_PIX_FMT_GBRAP12;
607  } else {
608  avpriv_report_missing_feature(avctx, "Sample format of %"PRIu16, data);
609  ret = AVERROR_PATCHWELCOME;
610  goto end;
611  }
612  s->planes = data == 2 ? 4 : av_pix_fmt_count_planes(s->coded_format);
613  } else if (tag == -DisplayHeight) {
614  av_log(avctx, AV_LOG_DEBUG, "Cropped height %"PRIu16"\n", data);
615  s->cropped_height = data;
616  } else if (tag == -PeakOffsetLow) {
617  s->peak.offset &= ~0xffff;
618  s->peak.offset |= (data & 0xffff);
619  s->peak.base = gb;
620  s->peak.level = 0;
621  } else if (tag == -PeakOffsetHigh) {
622  s->peak.offset &= 0xffff;
623  s->peak.offset |= (data & 0xffffU)<<16;
624  s->peak.base = gb;
625  s->peak.level = 0;
626  } else if (tag == -PeakLevel && s->peak.offset) {
627  s->peak.level = data;
628  if (s->peak.offset < 4 - bytestream2_tell(&s->peak.base) ||
629  s->peak.offset > 4 + bytestream2_get_bytes_left(&s->peak.base)
630  ) {
631  ret = AVERROR_INVALIDDATA;
632  goto end;
633  }
634  bytestream2_seek(&s->peak.base, s->peak.offset - 4, SEEK_CUR);
635  } else
636  av_log(avctx, AV_LOG_DEBUG, "Unknown tag %i data %x\n", tag, data);
637 
638  if (s->channel_num >= s->planes) {
639  av_log(avctx, AV_LOG_ERROR, "Invalid channel number\n");
640  ret = AVERROR(EINVAL);
641  goto end;
642  }
643 
644  if (got_buffer && (s->coded_width || s->coded_height || s->coded_format != AV_PIX_FMT_NONE)) {
645  av_log(avctx, AV_LOG_ERROR, "Header tag after end of header\n");
646  ret = AVERROR(EINVAL);
647  goto end;
648  }
649 
651  s->coded_format != AV_PIX_FMT_NONE) {
652  int lowpass_height = s->plane[s->channel_num].band[0][0].height;
653  int lowpass_width = s->plane[s->channel_num].band[0][0].width;
654  int factor = s->coded_format == AV_PIX_FMT_BAYER_RGGB16 ? 2 : 1;
655 
656  if (s->coded_width) {
657  s->coded_width *= factor;
658  }
659 
660  if (s->coded_height) {
661  s->coded_height *= factor;
662  }
663 
664  if (!s->a_width && !s->coded_width) {
665  s->coded_width = lowpass_width * factor * 8;
666  }
667 
668  if (!s->a_height && !s->coded_height) {
669  s->coded_height = lowpass_height * factor * 8;
670  }
671 
672  if (s->a_width && !s->coded_width)
673  s->coded_width = s->a_width;
674  if (s->a_height && !s->coded_height)
675  s->coded_height = s->a_height;
676 
677  if (s->a_width != s->coded_width || s->a_height != s->coded_height ||
678  s->a_format != s->coded_format ||
679  s->transform_type != s->a_transform_type) {
680  free_buffers(s);
681  if ((ret = alloc_buffers(avctx)) < 0) {
682  free_buffers(s);
683  return ret;
684  }
685  }
686  ret = ff_set_dimensions(avctx, s->coded_width, s->coded_height);
687  if (ret < 0)
688  return ret;
689  avctx->pix_fmt = s->coded_format;
690  if (s->cropped_height) {
691  unsigned height = s->cropped_height << (avctx->pix_fmt == AV_PIX_FMT_BAYER_RGGB16);
692  if (avctx->height < height)
693  return AVERROR_INVALIDDATA;
694  avctx->height = height;
695  }
696  frame.f->width =
697  frame.f->height = 0;
698 
699  if ((ret = ff_thread_get_buffer(avctx, &frame, 0)) < 0)
700  return ret;
701 
702  s->coded_width = 0;
703  s->coded_height = 0;
704  s->coded_format = AV_PIX_FMT_NONE;
705  got_buffer = 1;
706  } else if (tag == FrameIndex && data == 1 && s->sample_type == 1 && s->frame_type == 2) {
707  if (avctx->coded_width != s->a_width ||
708  avctx->coded_height != s->a_height ||
709  avctx->pix_fmt != s->a_format) {
710  av_log(avctx, AV_LOG_ERROR, "Frame parameters do not match the allocated buffers\n");
711  ret = AVERROR_INVALIDDATA;
712  goto end;
713  }
714  frame.f->width =
715  frame.f->height = 0;
716 
717  if ((ret = ff_thread_get_buffer(avctx, &frame, 0)) < 0)
718  return ret;
719  s->coded_width = 0;
720  s->coded_height = 0;
721  s->coded_format = AV_PIX_FMT_NONE;
722  got_buffer = 1;
723  }
724 
725  if (s->subband_num_actual == 255)
726  goto finish;
727 
728  if (tag == BitstreamMarker && data == CoefficientSegment || tag == BandHeader || tag == BandSecondPass || s->peak.level)
729  if (s->transform_type != s->a_transform_type)
730  return AVERROR_PATCHWELCOME;
731 
732  coeff_data = s->plane[s->channel_num].subband[s->subband_num_actual];
733 
734  /* Lowpass coefficients */
736  int lowpass_height, lowpass_width, lowpass_a_height, lowpass_a_width;
737 
738  if (!s->a_width || !s->a_height) {
739  ret = AVERROR_INVALIDDATA;
740  goto end;
741  }
742 
743  lowpass_height = s->plane[s->channel_num].band[0][0].height;
744  lowpass_width = s->plane[s->channel_num].band[0][0].width;
745  lowpass_a_height = s->plane[s->channel_num].band[0][0].a_height;
746  lowpass_a_width = s->plane[s->channel_num].band[0][0].a_width;
747 
748  if (lowpass_width < 3 ||
749  lowpass_width > lowpass_a_width) {
750  av_log(avctx, AV_LOG_ERROR, "Invalid lowpass width\n");
751  ret = AVERROR(EINVAL);
752  goto end;
753  }
754 
755  if (lowpass_height < 3 ||
756  lowpass_height > lowpass_a_height) {
757  av_log(avctx, AV_LOG_ERROR, "Invalid lowpass height\n");
758  ret = AVERROR(EINVAL);
759  goto end;
760  }
761 
762  if (!got_buffer) {
763  av_log(avctx, AV_LOG_ERROR, "No end of header tag found\n");
764  ret = AVERROR(EINVAL);
765  goto end;
766  }
767 
768  if (lowpass_height > lowpass_a_height || lowpass_width > lowpass_a_width ||
769  lowpass_width * lowpass_height * sizeof(int16_t) > bytestream2_get_bytes_left(&gb)) {
770  av_log(avctx, AV_LOG_ERROR, "Too many lowpass coefficients\n");
771  ret = AVERROR(EINVAL);
772  goto end;
773  }
774 
775  av_log(avctx, AV_LOG_DEBUG, "Start of lowpass coeffs component %d height:%d, width:%d\n", s->channel_num, lowpass_height, lowpass_width);
776  for (i = 0; i < lowpass_height; i++) {
777  for (j = 0; j < lowpass_width; j++)
778  coeff_data[j] = bytestream2_get_be16u(&gb);
779 
780  coeff_data += lowpass_width;
781  }
782 
783  /* Align to mod-4 position to continue reading tags */
784  bytestream2_seek(&gb, bytestream2_tell(&gb) & 3, SEEK_CUR);
785 
786  /* Copy last line of coefficients if odd height */
787  if (lowpass_height & 1) {
788  memcpy(&coeff_data[lowpass_height * lowpass_width],
789  &coeff_data[(lowpass_height - 1) * lowpass_width],
790  lowpass_width * sizeof(*coeff_data));
791  }
792 
793  s->plane[s->channel_num].band[0][0].read_ok = 1;
794 
795  av_log(avctx, AV_LOG_DEBUG, "Lowpass coefficients %d\n", lowpass_width * lowpass_height);
796  }
797 
798  av_assert0(s->subband_num_actual != 255);
799  if (tag == BandHeader || tag == BandSecondPass) {
800  int highpass_height, highpass_width, highpass_a_width, highpass_a_height, highpass_stride, a_expected;
801  int expected;
802  int level, run, coeff;
803  int count = 0, bytes;
804 
805  if (!s->a_width || !s->a_height) {
806  ret = AVERROR_INVALIDDATA;
807  goto end;
808  }
809 
810  highpass_height = s->plane[s->channel_num].band[s->level][s->subband_num].height;
811  highpass_width = s->plane[s->channel_num].band[s->level][s->subband_num].width;
812  highpass_a_width = s->plane[s->channel_num].band[s->level][s->subband_num].a_width;
813  highpass_a_height = s->plane[s->channel_num].band[s->level][s->subband_num].a_height;
814  highpass_stride = s->plane[s->channel_num].band[s->level][s->subband_num].stride;
815  a_expected = highpass_a_height * highpass_a_width;
816 
817  if (!got_buffer) {
818  av_log(avctx, AV_LOG_ERROR, "No end of header tag found\n");
819  ret = AVERROR(EINVAL);
820  goto end;
821  }
822 
823  if (highpass_height > highpass_a_height || highpass_width > highpass_a_width || a_expected < highpass_height * (uint64_t)highpass_stride) {
824  av_log(avctx, AV_LOG_ERROR, "Too many highpass coefficients\n");
825  ret = AVERROR(EINVAL);
826  goto end;
827  }
828  expected = highpass_height * highpass_stride;
829 
830  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);
831 
832  ret = init_get_bits8(&s->gb, gb.buffer, bytestream2_get_bytes_left(&gb));
833  if (ret < 0)
834  goto end;
835  {
836  OPEN_READER(re, &s->gb);
837 
838  const int lossless = s->band_encoding == 5;
839 
840  if (s->codebook == 0 && s->transform_type == 2 && s->subband_num_actual == 7)
841  s->codebook = 1;
842  if (!s->codebook) {
843  while (1) {
844  UPDATE_CACHE(re, &s->gb);
845  GET_RL_VLC(level, run, re, &s->gb, s->table_9_rl_vlc,
846  VLC_BITS, 3, 1);
847 
848  /* escape */
849  if (level == 64 && run == 2)
850  break;
851 
852  count += run;
853 
854  if (count > expected)
855  break;
856 
857  if (!lossless)
858  coeff = dequant_and_decompand(s, level, s->quantisation, 0);
859  else
860  coeff = level;
861  if (tag == BandSecondPass) {
862  const uint16_t q = s->quantisation;
863 
864  for (i = 0; i < run; i++) {
865  *coeff_data |= coeff * 256U;
866  *coeff_data++ *= q;
867  }
868  } else {
869  for (i = 0; i < run; i++)
870  *coeff_data++ = coeff;
871  }
872  }
873  } else {
874  while (1) {
875  UPDATE_CACHE(re, &s->gb);
876  GET_RL_VLC(level, run, re, &s->gb, s->table_18_rl_vlc,
877  VLC_BITS, 3, 1);
878 
879  /* escape */
880  if (level == 255 && run == 2)
881  break;
882 
883  count += run;
884 
885  if (count > expected)
886  break;
887 
888  if (!lossless)
889  coeff = dequant_and_decompand(s, level, s->quantisation, s->codebook);
890  else
891  coeff = level;
892  if (tag == BandSecondPass) {
893  const uint16_t q = s->quantisation;
894 
895  for (i = 0; i < run; i++) {
896  *coeff_data |= coeff * 256U;
897  *coeff_data++ *= q;
898  }
899  } else {
900  for (i = 0; i < run; i++)
901  *coeff_data++ = coeff;
902  }
903  }
904  }
905  CLOSE_READER(re, &s->gb);
906  }
907 
908  if (count > expected) {
909  av_log(avctx, AV_LOG_ERROR, "Escape codeword not found, probably corrupt data\n");
910  ret = AVERROR(EINVAL);
911  goto end;
912  }
913  if (s->peak.level)
914  peak_table(coeff_data - count, &s->peak, count);
915  if (s->difference_coding)
916  difference_coding(s->plane[s->channel_num].subband[s->subband_num_actual], highpass_width, highpass_height);
917 
918  bytes = FFALIGN(AV_CEIL_RSHIFT(get_bits_count(&s->gb), 3), 4);
919  if (bytes > bytestream2_get_bytes_left(&gb)) {
920  av_log(avctx, AV_LOG_ERROR, "Bitstream overread error\n");
921  ret = AVERROR(EINVAL);
922  goto end;
923  } else
924  bytestream2_seek(&gb, bytes, SEEK_CUR);
925 
926  av_log(avctx, AV_LOG_DEBUG, "End subband coeffs %i extra %i\n", count, count - expected);
927  s->plane[s->channel_num].band[s->level][s->subband_num].read_ok = 1;
928 finish:
929  if (s->subband_num_actual != 255)
930  s->codebook = 0;
931  }
932  }
933 
934  s->planes = av_pix_fmt_count_planes(avctx->pix_fmt);
935  if (avctx->pix_fmt == AV_PIX_FMT_BAYER_RGGB16) {
936  s->progressive = 1;
937  s->planes = 4;
938  }
939 
940  ff_thread_finish_setup(avctx);
941 
942  if (!s->a_width || !s->a_height || s->a_format == AV_PIX_FMT_NONE ||
943  s->a_transform_type == INT_MIN) {
944  av_log(avctx, AV_LOG_ERROR, "Invalid dimensions\n");
945  ret = AVERROR(EINVAL);
946  goto end;
947  }
948 
949  if (!got_buffer) {
950  av_log(avctx, AV_LOG_ERROR, "No end of header tag found\n");
951  ret = AVERROR(EINVAL);
952  goto end;
953  }
954 
955  for (plane = 0; plane < s->planes; plane++) {
956  int o, level;
957 
958  for (level = 0; level < (s->transform_type == 0 ? DWT_LEVELS : DWT_LEVELS_3D) ; level++) {
959  if (s->transform_type == 2)
960  if (level == 2 || level == 5)
961  continue;
962  for (o = !!level; o < 4 ; o++) {
963  if (!s->plane[plane].band[level][o].read_ok) {
964  ret = AVERROR_INVALIDDATA;
965  goto end;
966  }
967  }
968  }
969  }
970 
971  if (s->transform_type == 0 && s->sample_type != 1) {
972  for (plane = 0; plane < s->planes && !ret; plane++) {
973  /* level 1 */
974  int lowpass_height = s->plane[plane].band[0][0].height;
975  int output_stride = s->plane[plane].band[0][0].a_width;
976  int lowpass_width = s->plane[plane].band[0][0].width;
977  int highpass_stride = s->plane[plane].band[0][1].stride;
978  int act_plane = plane == 1 ? 2 : plane == 2 ? 1 : plane;
979  ptrdiff_t dst_linesize;
980  int16_t *low, *high, *output, *dst;
981 
982  if (avctx->pix_fmt == AV_PIX_FMT_BAYER_RGGB16) {
983  act_plane = 0;
984  dst_linesize = pic->linesize[act_plane];
985  } else {
986  dst_linesize = pic->linesize[act_plane] / 2;
987  }
988 
989  if (lowpass_height > s->plane[plane].band[0][0].a_height || lowpass_width > s->plane[plane].band[0][0].a_width ||
990  !highpass_stride || s->plane[plane].band[0][1].width > s->plane[plane].band[0][1].a_width ||
991  lowpass_width < 3 || lowpass_height < 3) {
992  av_log(avctx, AV_LOG_ERROR, "Invalid plane dimensions\n");
993  ret = AVERROR(EINVAL);
994  goto end;
995  }
996 
997  av_log(avctx, AV_LOG_DEBUG, "Decoding level 1 plane %i %i %i %i\n", plane, lowpass_height, lowpass_width, highpass_stride);
998 
999  low = s->plane[plane].subband[0];
1000  high = s->plane[plane].subband[2];
1001  output = s->plane[plane].l_h[0];
1002  dsp->vert_filter(output, output_stride, low, lowpass_width, high, highpass_stride, lowpass_width, lowpass_height);
1003 
1004  low = s->plane[plane].subband[1];
1005  high = s->plane[plane].subband[3];
1006  output = s->plane[plane].l_h[1];
1007 
1008  dsp->vert_filter(output, output_stride, low, highpass_stride, high, highpass_stride, lowpass_width, lowpass_height);
1009 
1010  low = s->plane[plane].l_h[0];
1011  high = s->plane[plane].l_h[1];
1012  output = s->plane[plane].subband[0];
1013  dsp->horiz_filter(output, output_stride, low, output_stride, high, output_stride, lowpass_width, lowpass_height * 2);
1014  if (s->bpc == 12) {
1015  output = s->plane[plane].subband[0];
1016  for (i = 0; i < lowpass_height * 2; i++) {
1017  for (j = 0; j < lowpass_width * 2; j++)
1018  output[j] *= 4;
1019 
1020  output += output_stride * 2;
1021  }
1022  }
1023 
1024  /* level 2 */
1025  lowpass_height = s->plane[plane].band[1][1].height;
1026  output_stride = s->plane[plane].band[1][1].a_width;
1027  lowpass_width = s->plane[plane].band[1][1].width;
1028  highpass_stride = s->plane[plane].band[1][1].stride;
1029 
1030  if (lowpass_height > s->plane[plane].band[1][1].a_height || lowpass_width > s->plane[plane].band[1][1].a_width ||
1031  !highpass_stride || s->plane[plane].band[1][1].width > s->plane[plane].band[1][1].a_width ||
1032  lowpass_width < 3 || lowpass_height < 3) {
1033  av_log(avctx, AV_LOG_ERROR, "Invalid plane dimensions\n");
1034  ret = AVERROR(EINVAL);
1035  goto end;
1036  }
1037 
1038  av_log(avctx, AV_LOG_DEBUG, "Level 2 plane %i %i %i %i\n", plane, lowpass_height, lowpass_width, highpass_stride);
1039 
1040  low = s->plane[plane].subband[0];
1041  high = s->plane[plane].subband[5];
1042  output = s->plane[plane].l_h[3];
1043  dsp->vert_filter(output, output_stride, low, output_stride, high, highpass_stride, lowpass_width, lowpass_height);
1044 
1045  low = s->plane[plane].subband[4];
1046  high = s->plane[plane].subband[6];
1047  output = s->plane[plane].l_h[4];
1048  dsp->vert_filter(output, output_stride, low, highpass_stride, high, highpass_stride, lowpass_width, lowpass_height);
1049 
1050  low = s->plane[plane].l_h[3];
1051  high = s->plane[plane].l_h[4];
1052  output = s->plane[plane].subband[0];
1053  dsp->horiz_filter(output, output_stride, low, output_stride, high, output_stride, lowpass_width, lowpass_height * 2);
1054 
1055  output = s->plane[plane].subband[0];
1056  for (i = 0; i < lowpass_height * 2; i++) {
1057  for (j = 0; j < lowpass_width * 2; j++)
1058  output[j] *= 4;
1059 
1060  output += output_stride * 2;
1061  }
1062 
1063  /* level 3 */
1064  lowpass_height = s->plane[plane].band[2][1].height;
1065  output_stride = s->plane[plane].band[2][1].a_width;
1066  lowpass_width = s->plane[plane].band[2][1].width;
1067  highpass_stride = s->plane[plane].band[2][1].stride;
1068 
1069  if (lowpass_height > s->plane[plane].band[2][1].a_height || lowpass_width > s->plane[plane].band[2][1].a_width ||
1070  !highpass_stride || s->plane[plane].band[2][1].width > s->plane[plane].band[2][1].a_width ||
1071  lowpass_height < 3 || lowpass_width < 3 || lowpass_width * 2 > s->plane[plane].width) {
1072  av_log(avctx, AV_LOG_ERROR, "Invalid plane dimensions\n");
1073  ret = AVERROR(EINVAL);
1074  goto end;
1075  }
1076 
1077  av_log(avctx, AV_LOG_DEBUG, "Level 3 plane %i %i %i %i\n", plane, lowpass_height, lowpass_width, highpass_stride);
1078  if (s->progressive) {
1079  low = s->plane[plane].subband[0];
1080  high = s->plane[plane].subband[8];
1081  output = s->plane[plane].l_h[6];
1082  dsp->vert_filter(output, output_stride, low, output_stride, high, highpass_stride, lowpass_width, lowpass_height);
1083 
1084  low = s->plane[plane].subband[7];
1085  high = s->plane[plane].subband[9];
1086  output = s->plane[plane].l_h[7];
1087  dsp->vert_filter(output, output_stride, low, highpass_stride, high, highpass_stride, lowpass_width, lowpass_height);
1088 
1089  dst = (int16_t *)pic->data[act_plane];
1090  if (avctx->pix_fmt == AV_PIX_FMT_BAYER_RGGB16) {
1091  if (plane & 1)
1092  dst++;
1093  if (plane > 1)
1094  dst += pic->linesize[act_plane] >> 1;
1095  }
1096  low = s->plane[plane].l_h[6];
1097  high = s->plane[plane].l_h[7];
1098 
1099  if (avctx->pix_fmt == AV_PIX_FMT_BAYER_RGGB16 &&
1100  (lowpass_height * 2 > avctx->coded_height / 2 ||
1101  lowpass_width * 2 > avctx->coded_width / 2 )
1102  ) {
1103  ret = AVERROR_INVALIDDATA;
1104  goto end;
1105  }
1106 
1107  for (i = 0; i < s->plane[act_plane].height; i++) {
1108  dsp->horiz_filter_clip(dst, low, high, lowpass_width, s->bpc);
1109  if (avctx->pix_fmt == AV_PIX_FMT_GBRAP12 && act_plane == 3)
1110  process_alpha(dst, lowpass_width * 2);
1111  low += output_stride;
1112  high += output_stride;
1113  dst += dst_linesize;
1114  }
1115  } else {
1116  av_log(avctx, AV_LOG_DEBUG, "interlaced frame ? %d", pic->interlaced_frame);
1117  pic->interlaced_frame = 1;
1118  low = s->plane[plane].subband[0];
1119  high = s->plane[plane].subband[7];
1120  output = s->plane[plane].l_h[6];
1121  dsp->horiz_filter(output, output_stride, low, output_stride, high, highpass_stride, lowpass_width, lowpass_height);
1122 
1123  low = s->plane[plane].subband[8];
1124  high = s->plane[plane].subband[9];
1125  output = s->plane[plane].l_h[7];
1126  dsp->horiz_filter(output, output_stride, low, highpass_stride, high, highpass_stride, lowpass_width, lowpass_height);
1127 
1128  dst = (int16_t *)pic->data[act_plane];
1129  low = s->plane[plane].l_h[6];
1130  high = s->plane[plane].l_h[7];
1131  for (i = 0; i < s->plane[act_plane].height / 2; i++) {
1132  interlaced_vertical_filter(dst, low, high, lowpass_width * 2, pic->linesize[act_plane]/2, act_plane);
1133  low += output_stride * 2;
1134  high += output_stride * 2;
1135  dst += pic->linesize[act_plane];
1136  }
1137  }
1138  }
1139  } else if (s->transform_type == 2 && (avctx->internal->is_copy || s->frame_index == 1 || s->sample_type != 1)) {
1140  for (plane = 0; plane < s->planes && !ret; plane++) {
1141  int lowpass_height = s->plane[plane].band[0][0].height;
1142  int output_stride = s->plane[plane].band[0][0].a_width;
1143  int lowpass_width = s->plane[plane].band[0][0].width;
1144  int highpass_stride = s->plane[plane].band[0][1].stride;
1145  int act_plane = plane == 1 ? 2 : plane == 2 ? 1 : plane;
1146  int16_t *low, *high, *output, *dst;
1147  ptrdiff_t dst_linesize;
1148 
1149  if (avctx->pix_fmt == AV_PIX_FMT_BAYER_RGGB16) {
1150  act_plane = 0;
1151  dst_linesize = pic->linesize[act_plane];
1152  } else {
1153  dst_linesize = pic->linesize[act_plane] / 2;
1154  }
1155 
1156  if (lowpass_height > s->plane[plane].band[0][0].a_height || lowpass_width > s->plane[plane].band[0][0].a_width ||
1157  !highpass_stride || s->plane[plane].band[0][1].width > s->plane[plane].band[0][1].a_width ||
1158  lowpass_width < 3 || lowpass_height < 3) {
1159  av_log(avctx, AV_LOG_ERROR, "Invalid plane dimensions\n");
1160  ret = AVERROR(EINVAL);
1161  goto end;
1162  }
1163 
1164  av_log(avctx, AV_LOG_DEBUG, "Decoding level 1 plane %i %i %i %i\n", plane, lowpass_height, lowpass_width, highpass_stride);
1165 
1166  low = s->plane[plane].subband[0];
1167  high = s->plane[plane].subband[2];
1168  output = s->plane[plane].l_h[0];
1169  dsp->vert_filter(output, output_stride, low, lowpass_width, high, highpass_stride, lowpass_width, lowpass_height);
1170 
1171  low = s->plane[plane].subband[1];
1172  high = s->plane[plane].subband[3];
1173  output = s->plane[plane].l_h[1];
1174  dsp->vert_filter(output, output_stride, low, highpass_stride, high, highpass_stride, lowpass_width, lowpass_height);
1175 
1176  low = s->plane[plane].l_h[0];
1177  high = s->plane[plane].l_h[1];
1178  output = s->plane[plane].l_h[7];
1179  dsp->horiz_filter(output, output_stride, low, output_stride, high, output_stride, lowpass_width, lowpass_height * 2);
1180  if (s->bpc == 12) {
1181  output = s->plane[plane].l_h[7];
1182  for (i = 0; i < lowpass_height * 2; i++) {
1183  for (j = 0; j < lowpass_width * 2; j++)
1184  output[j] *= 4;
1185 
1186  output += output_stride * 2;
1187  }
1188  }
1189 
1190  lowpass_height = s->plane[plane].band[1][1].height;
1191  output_stride = s->plane[plane].band[1][1].a_width;
1192  lowpass_width = s->plane[plane].band[1][1].width;
1193  highpass_stride = s->plane[plane].band[1][1].stride;
1194 
1195  if (lowpass_height > s->plane[plane].band[1][1].a_height || lowpass_width > s->plane[plane].band[1][1].a_width ||
1196  !highpass_stride || s->plane[plane].band[1][1].width > s->plane[plane].band[1][1].a_width ||
1197  lowpass_width < 3 || lowpass_height < 3) {
1198  av_log(avctx, AV_LOG_ERROR, "Invalid plane dimensions\n");
1199  ret = AVERROR(EINVAL);
1200  goto end;
1201  }
1202 
1203  av_log(avctx, AV_LOG_DEBUG, "Level 2 lowpass plane %i %i %i %i\n", plane, lowpass_height, lowpass_width, highpass_stride);
1204 
1205  low = s->plane[plane].l_h[7];
1206  high = s->plane[plane].subband[5];
1207  output = s->plane[plane].l_h[3];
1208  dsp->vert_filter(output, output_stride, low, output_stride, high, highpass_stride, lowpass_width, lowpass_height);
1209 
1210  low = s->plane[plane].subband[4];
1211  high = s->plane[plane].subband[6];
1212  output = s->plane[plane].l_h[4];
1213  dsp->vert_filter(output, output_stride, low, highpass_stride, high, highpass_stride, lowpass_width, lowpass_height);
1214 
1215  low = s->plane[plane].l_h[3];
1216  high = s->plane[plane].l_h[4];
1217  output = s->plane[plane].l_h[7];
1218  dsp->horiz_filter(output, output_stride, low, output_stride, high, output_stride, lowpass_width, lowpass_height * 2);
1219 
1220  output = s->plane[plane].l_h[7];
1221  for (i = 0; i < lowpass_height * 2; i++) {
1222  for (j = 0; j < lowpass_width * 2; j++)
1223  output[j] *= 4;
1224  output += output_stride * 2;
1225  }
1226 
1227  low = s->plane[plane].subband[7];
1228  high = s->plane[plane].subband[9];
1229  output = s->plane[plane].l_h[3];
1230  dsp->vert_filter(output, output_stride, low, highpass_stride, high, highpass_stride, lowpass_width, lowpass_height);
1231 
1232  low = s->plane[plane].subband[8];
1233  high = s->plane[plane].subband[10];
1234  output = s->plane[plane].l_h[4];
1235  dsp->vert_filter(output, output_stride, low, highpass_stride, high, highpass_stride, lowpass_width, lowpass_height);
1236 
1237  low = s->plane[plane].l_h[3];
1238  high = s->plane[plane].l_h[4];
1239  output = s->plane[plane].l_h[9];
1240  dsp->horiz_filter(output, output_stride, low, output_stride, high, output_stride, lowpass_width, lowpass_height * 2);
1241 
1242  lowpass_height = s->plane[plane].band[4][1].height;
1243  output_stride = s->plane[plane].band[4][1].a_width;
1244  lowpass_width = s->plane[plane].band[4][1].width;
1245  highpass_stride = s->plane[plane].band[4][1].stride;
1246  av_log(avctx, AV_LOG_DEBUG, "temporal level %i %i %i %i\n", plane, lowpass_height, lowpass_width, highpass_stride);
1247 
1248  if (lowpass_height > s->plane[plane].band[4][1].a_height || lowpass_width > s->plane[plane].band[4][1].a_width ||
1249  !highpass_stride || s->plane[plane].band[4][1].width > s->plane[plane].band[4][1].a_width ||
1250  lowpass_width < 3 || lowpass_height < 3 || lowpass_width * 2 > s->plane[plane].width) {
1251  av_log(avctx, AV_LOG_ERROR, "Invalid plane dimensions\n");
1252  ret = AVERROR(EINVAL);
1253  goto end;
1254  }
1255 
1256  low = s->plane[plane].l_h[7];
1257  high = s->plane[plane].l_h[9];
1258  output = s->plane[plane].l_h[7];
1259  for (i = 0; i < lowpass_height; i++) {
1260  inverse_temporal_filter(low, high, lowpass_width);
1261  low += output_stride;
1262  high += output_stride;
1263  }
1264  if (s->progressive) {
1265  low = s->plane[plane].l_h[7];
1266  high = s->plane[plane].subband[15];
1267  output = s->plane[plane].l_h[6];
1268  dsp->vert_filter(output, output_stride, low, output_stride, high, highpass_stride, lowpass_width, lowpass_height);
1269 
1270  low = s->plane[plane].subband[14];
1271  high = s->plane[plane].subband[16];
1272  output = s->plane[plane].l_h[7];
1273  dsp->vert_filter(output, output_stride, low, highpass_stride, high, highpass_stride, lowpass_width, lowpass_height);
1274 
1275  low = s->plane[plane].l_h[9];
1276  high = s->plane[plane].subband[12];
1277  output = s->plane[plane].l_h[8];
1278  dsp->vert_filter(output, output_stride, low, output_stride, high, highpass_stride, lowpass_width, lowpass_height);
1279 
1280  low = s->plane[plane].subband[11];
1281  high = s->plane[plane].subband[13];
1282  output = s->plane[plane].l_h[9];
1283  dsp->vert_filter(output, output_stride, low, highpass_stride, high, highpass_stride, lowpass_width, lowpass_height);
1284 
1285  if (s->sample_type == 1)
1286  continue;
1287 
1288  dst = (int16_t *)pic->data[act_plane];
1289  if (avctx->pix_fmt == AV_PIX_FMT_BAYER_RGGB16) {
1290  if (plane & 1)
1291  dst++;
1292  if (plane > 1)
1293  dst += pic->linesize[act_plane] >> 1;
1294  }
1295 
1296  if (avctx->pix_fmt == AV_PIX_FMT_BAYER_RGGB16 &&
1297  (lowpass_height * 2 > avctx->coded_height / 2 ||
1298  lowpass_width * 2 > avctx->coded_width / 2 )
1299  ) {
1300  ret = AVERROR_INVALIDDATA;
1301  goto end;
1302  }
1303 
1304  low = s->plane[plane].l_h[6];
1305  high = s->plane[plane].l_h[7];
1306  for (i = 0; i < s->plane[act_plane].height; i++) {
1307  dsp->horiz_filter_clip(dst, low, high, lowpass_width, s->bpc);
1308  low += output_stride;
1309  high += output_stride;
1310  dst += dst_linesize;
1311  }
1312  } else {
1313  pic->interlaced_frame = 1;
1314  low = s->plane[plane].l_h[7];
1315  high = s->plane[plane].subband[14];
1316  output = s->plane[plane].l_h[6];
1317  dsp->horiz_filter(output, output_stride, low, output_stride, high, highpass_stride, lowpass_width, lowpass_height);
1318 
1319  low = s->plane[plane].subband[15];
1320  high = s->plane[plane].subband[16];
1321  output = s->plane[plane].l_h[7];
1322  dsp->horiz_filter(output, output_stride, low, highpass_stride, high, highpass_stride, lowpass_width, lowpass_height);
1323 
1324  low = s->plane[plane].l_h[9];
1325  high = s->plane[plane].subband[11];
1326  output = s->plane[plane].l_h[8];
1327  dsp->horiz_filter(output, output_stride, low, output_stride, high, highpass_stride, lowpass_width, lowpass_height);
1328 
1329  low = s->plane[plane].subband[12];
1330  high = s->plane[plane].subband[13];
1331  output = s->plane[plane].l_h[9];
1332  dsp->horiz_filter(output, output_stride, low, highpass_stride, high, highpass_stride, lowpass_width, lowpass_height);
1333 
1334  if (s->sample_type == 1)
1335  continue;
1336 
1337  dst = (int16_t *)pic->data[act_plane];
1338  low = s->plane[plane].l_h[6];
1339  high = s->plane[plane].l_h[7];
1340  for (i = 0; i < s->plane[act_plane].height / 2; i++) {
1341  interlaced_vertical_filter(dst, low, high, lowpass_width * 2, pic->linesize[act_plane]/2, act_plane);
1342  low += output_stride * 2;
1343  high += output_stride * 2;
1344  dst += pic->linesize[act_plane];
1345  }
1346  }
1347  }
1348  }
1349 
1350  if (s->transform_type == 2 && s->sample_type == 1) {
1351  int16_t *low, *high, *dst;
1352  int output_stride, lowpass_height, lowpass_width;
1353  ptrdiff_t dst_linesize;
1354 
1355  for (plane = 0; plane < s->planes; plane++) {
1356  int act_plane = plane == 1 ? 2 : plane == 2 ? 1 : plane;
1357 
1358  if (avctx->pix_fmt == AV_PIX_FMT_BAYER_RGGB16) {
1359  act_plane = 0;
1360  dst_linesize = pic->linesize[act_plane];
1361  } else {
1362  dst_linesize = pic->linesize[act_plane] / 2;
1363  }
1364 
1365  lowpass_height = s->plane[plane].band[4][1].height;
1366  output_stride = s->plane[plane].band[4][1].a_width;
1367  lowpass_width = s->plane[plane].band[4][1].width;
1368 
1369  if (lowpass_height > s->plane[plane].band[4][1].a_height || lowpass_width > s->plane[plane].band[4][1].a_width ||
1370  s->plane[plane].band[4][1].width > s->plane[plane].band[4][1].a_width ||
1371  lowpass_width < 3 || lowpass_height < 3 || lowpass_width * 2 > s->plane[plane].width) {
1372  av_log(avctx, AV_LOG_ERROR, "Invalid plane dimensions\n");
1373  ret = AVERROR(EINVAL);
1374  goto end;
1375  }
1376 
1377  if (s->progressive) {
1378  dst = (int16_t *)pic->data[act_plane];
1379  low = s->plane[plane].l_h[8];
1380  high = s->plane[plane].l_h[9];
1381 
1382  if (avctx->pix_fmt == AV_PIX_FMT_BAYER_RGGB16) {
1383  if (plane & 1)
1384  dst++;
1385  if (plane > 1)
1386  dst += pic->linesize[act_plane] >> 1;
1387  }
1388 
1389  if (avctx->pix_fmt == AV_PIX_FMT_BAYER_RGGB16 &&
1390  (lowpass_height * 2 > avctx->coded_height / 2 ||
1391  lowpass_width * 2 > avctx->coded_width / 2 )
1392  ) {
1393  ret = AVERROR_INVALIDDATA;
1394  goto end;
1395  }
1396 
1397  for (i = 0; i < s->plane[act_plane].height; i++) {
1398  dsp->horiz_filter_clip(dst, low, high, lowpass_width, s->bpc);
1399  low += output_stride;
1400  high += output_stride;
1401  dst += dst_linesize;
1402  }
1403  } else {
1404  dst = (int16_t *)pic->data[act_plane];
1405  low = s->plane[plane].l_h[8];
1406  high = s->plane[plane].l_h[9];
1407  for (i = 0; i < s->plane[act_plane].height / 2; i++) {
1408  interlaced_vertical_filter(dst, low, high, lowpass_width * 2, pic->linesize[act_plane]/2, act_plane);
1409  low += output_stride * 2;
1410  high += output_stride * 2;
1411  dst += pic->linesize[act_plane];
1412  }
1413  }
1414  }
1415  }
1416 
1417  if (avctx->pix_fmt == AV_PIX_FMT_BAYER_RGGB16)
1418  process_bayer(pic, s->bpc);
1419 end:
1420  if (ret < 0)
1421  return ret;
1422 
1423  *got_frame = 1;
1424  return avpkt->size;
1425 }
1426 
1428 {
1429  CFHDContext *s = avctx->priv_data;
1430 
1431  free_buffers(s);
1432 
1433  ff_free_vlc(&s->vlc_9);
1434  ff_free_vlc(&s->vlc_18);
1435 
1436  return 0;
1437 }
1438 
1439 #if HAVE_THREADS
1440 static int update_thread_context(AVCodecContext *dst, const AVCodecContext *src)
1441 {
1442  CFHDContext *psrc = src->priv_data;
1443  CFHDContext *pdst = dst->priv_data;
1444  int ret;
1445 
1446  if (dst == src || psrc->transform_type == 0)
1447  return 0;
1448 
1449  if (pdst->plane[0].idwt_size != psrc->plane[0].idwt_size ||
1450  pdst->a_format != psrc->a_format ||
1451  pdst->a_width != psrc->a_width ||
1452  pdst->a_height != psrc->a_height ||
1453  pdst->a_transform_type != psrc->a_transform_type)
1454  free_buffers(pdst);
1455 
1456  pdst->a_format = psrc->a_format;
1457  pdst->a_width = psrc->a_width;
1458  pdst->a_height = psrc->a_height;
1459  pdst->a_transform_type = psrc->a_transform_type;
1460  pdst->transform_type = psrc->transform_type;
1461  pdst->progressive = psrc->progressive;
1462  pdst->planes = psrc->planes;
1463 
1464  if (!psrc->plane[0].idwt_buf)
1465  return 0;
1466 
1467  if (!pdst->plane[0].idwt_buf) {
1468  pdst->coded_width = pdst->a_width;
1469  pdst->coded_height = pdst->a_height;
1470  pdst->coded_format = pdst->a_format;
1471  pdst->transform_type = pdst->a_transform_type;
1472  ret = alloc_buffers(dst);
1473  if (ret < 0)
1474  return ret;
1475  }
1476 
1477  for (int plane = 0; plane < pdst->planes; plane++) {
1478  memcpy(pdst->plane[plane].band, psrc->plane[plane].band, sizeof(pdst->plane[plane].band));
1479  memcpy(pdst->plane[plane].idwt_buf, psrc->plane[plane].idwt_buf,
1480  pdst->plane[plane].idwt_size * sizeof(int16_t));
1481  }
1482 
1483  return 0;
1484 }
1485 #endif
1486 
1488  .name = "cfhd",
1489  .long_name = NULL_IF_CONFIG_SMALL("GoPro CineForm HD"),
1490  .type = AVMEDIA_TYPE_VIDEO,
1491  .id = AV_CODEC_ID_CFHD,
1492  .priv_data_size = sizeof(CFHDContext),
1493  .init = cfhd_init,
1494  .close = cfhd_close,
1495  .decode = cfhd_decode,
1496  .update_thread_context = ONLY_IF_THREADS_ENABLED(update_thread_context),
1497  .capabilities = AV_CODEC_CAP_DR1 | AV_CODEC_CAP_FRAME_THREADS,
1499 };
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:379
static int alloc_buffers(AVCodecContext *avctx)
Definition: cfhd.c:247
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:1427
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:1487
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_calloc(size_t nmemb, size_t size)
Non-inlined equivalent of av_mallocz_array().
Definition: mem.c:245
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:291
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 @323 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
int a_height
Definition: cfhd.h:124
int8_t read_ok
Definition: cfhd.h:126
int a_width
Definition: cfhd.h:122
uint8_t run
Definition: svq3.c:205
uint8_t level
Definition: svq3.c:206
#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:119
const char * g
Definition: vf_curves.c:118
const char * r
Definition: vf_curves.c:117
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