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