FFmpeg
Loading...
Searching...
No Matches
dpx.c
Go to the documentation of this file.
1/*
2 * DPX (.dpx) image decoder
3 * Copyright (c) 2009 Jimmy Christensen
4 *
5 * This file is part of FFmpeg.
6 *
7 * FFmpeg is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
11 *
12 * FFmpeg is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
16 *
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with FFmpeg; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20 */
21
23#include "libavutil/avstring.h"
25#include "libavutil/intfloat.h"
26#include "libavutil/imgutils.h"
27#include "libavutil/timecode.h"
28#include "avcodec.h"
29#include "codec_internal.h"
30#include "decode.h"
31#include "dpx.h"
32
33#include "thread.h"
34#include "hwconfig.h"
35#include "hwaccel_internal.h"
36#include "config_components.h"
37
38static unsigned int read16(const uint8_t **ptr, int is_big)
39{
40 unsigned int temp;
41 if (is_big) {
42 temp = AV_RB16(*ptr);
43 } else {
44 temp = AV_RL16(*ptr);
45 }
46 *ptr += 2;
47 return temp;
48}
49
50static unsigned int read32(const uint8_t **ptr, int is_big)
51{
52 unsigned int temp;
53 if (is_big) {
54 temp = AV_RB32(*ptr);
55 } else {
56 temp = AV_RL32(*ptr);
57 }
58 *ptr += 4;
59 return temp;
60}
61
62static uint16_t read10in32_gray(const uint8_t **ptr, uint32_t *lbuf,
63 int *n_datum, int is_big, int shift)
64{
65 uint16_t temp;
66
67 if (*n_datum)
68 (*n_datum)--;
69 else {
70 *lbuf = read32(ptr, is_big);
71 *n_datum = 2;
72 }
73
74 temp = *lbuf >> shift & 0x3FF;
75 *lbuf = *lbuf >> 10;
76
77 return temp;
78}
79
80static uint16_t read10in32(const uint8_t **ptr, uint32_t *lbuf,
81 int *n_datum, int is_big, int shift)
82{
83 if (*n_datum)
84 (*n_datum)--;
85 else {
86 *lbuf = read32(ptr, is_big);
87 *n_datum = 2;
88 }
89
90 *lbuf = *lbuf << 10 | *lbuf >> shift & 0x3FFFFF;
91
92 return *lbuf & 0x3FF;
93}
94
95static uint16_t read12in32(const uint8_t **ptr, uint32_t *lbuf,
96 int *n_datum, int is_big)
97{
98 if (*n_datum)
99 (*n_datum)--;
100 else {
101 *lbuf = read32(ptr, is_big);
102 *n_datum = 7;
103 }
104
105 switch (*n_datum){
106 case 7: return *lbuf & 0xFFF;
107 case 6: return (*lbuf >> 12) & 0xFFF;
108 case 5: {
109 uint32_t c = *lbuf >> 24;
110 *lbuf = read32(ptr, is_big);
111 c |= *lbuf << 8;
112 return c & 0xFFF;
113 }
114 case 4: return (*lbuf >> 4) & 0xFFF;
115 case 3: return (*lbuf >> 16) & 0xFFF;
116 case 2: {
117 uint32_t c = *lbuf >> 28;
118 *lbuf = read32(ptr, is_big);
119 c |= *lbuf << 4;
120 return c & 0xFFF;
121 }
122 case 1: return (*lbuf >> 8) & 0xFFF;
123 default: return *lbuf >> 20;
124 }
125}
126
127static void unpack_frame(AVCodecContext *avctx, AVFrame *p, const uint8_t *buf,
128 int elements, int endian)
129{
130 int i, x, y;
131 DPXDecContext *dpx = avctx->priv_data;
132
133 uint8_t *ptr[AV_NUM_DATA_POINTERS];
134 unsigned int rgbBuffer = 0;
135 int n_datum = 0;
136
137 for (i=0; i<AV_NUM_DATA_POINTERS; i++)
138 ptr[i] = p->data[i];
139
140 switch (avctx->bits_per_raw_sample) {
141 case 10:
142 for (x = 0; x < avctx->height; x++) {
143 uint16_t *dst[4] = {(uint16_t*)ptr[0],
144 (uint16_t*)ptr[1],
145 (uint16_t*)ptr[2],
146 (uint16_t*)ptr[3]};
147 int shift = elements > 1 ? dpx->packing == 1 ? 22 : 20 : dpx->packing == 1 ? 2 : 0;
148 for (y = 0; y < avctx->width; y++) {
149 if (elements >= 3)
150 *dst[2]++ = read10in32(&buf, &rgbBuffer,
151 &n_datum, endian, shift);
152 if (elements == 1)
153 *dst[0]++ = read10in32_gray(&buf, &rgbBuffer,
154 &n_datum, endian, shift);
155 else
156 *dst[0]++ = read10in32(&buf, &rgbBuffer,
157 &n_datum, endian, shift);
158 if (elements >= 2)
159 *dst[1]++ = read10in32(&buf, &rgbBuffer,
160 &n_datum, endian, shift);
161 if (elements == 4)
162 *dst[3]++ =
163 read10in32(&buf, &rgbBuffer,
164 &n_datum, endian, shift);
165 }
166 if (!dpx->unpadded_10bit)
167 n_datum = 0;
168 for (i = 0; i < elements; i++)
169 ptr[i] += p->linesize[i];
170 }
171 break;
172 case 12:
173 for (x = 0; x < avctx->height; x++) {
174 uint16_t *dst[4] = {(uint16_t*)ptr[0],
175 (uint16_t*)ptr[1],
176 (uint16_t*)ptr[2],
177 (uint16_t*)ptr[3]};
178 int shift = dpx->packing == 1 ? 4 : 0;
179 for (y = 0; y < avctx->width; y++) {
180 if (dpx->packing) {
181 if (elements >= 3)
182 *dst[2]++ = read16(&buf, endian) >> shift & 0xFFF;
183 *dst[0]++ = read16(&buf, endian) >> shift & 0xFFF;
184 if (elements >= 2)
185 *dst[1]++ = read16(&buf, endian) >> shift & 0xFFF;
186 if (elements == 4)
187 *dst[3]++ = read16(&buf, endian) >> shift & 0xFFF;
188 } else {
189 if (elements >= 3)
190 *dst[2]++ = read12in32(&buf, &rgbBuffer,
191 &n_datum, endian);
192 *dst[0]++ = read12in32(&buf, &rgbBuffer,
193 &n_datum, endian);
194 if (elements >= 2)
195 *dst[1]++ = read12in32(&buf, &rgbBuffer,
196 &n_datum, endian);
197 if (elements == 4)
198 *dst[3]++ = read12in32(&buf, &rgbBuffer,
199 &n_datum, endian);
200 }
201 }
202 n_datum = 0;
203 for (i = 0; i < elements; i++)
204 ptr[i] += p->linesize[i];
205 // Jump to next aligned position
206 buf += dpx->need_align;
207 }
208 break;
209 case 32:
210 if (elements == 1) {
211 av_image_copy_plane(ptr[0], p->linesize[0],
212 buf, dpx->stride,
213 elements * avctx->width * 4, avctx->height);
214 } else {
215 for (y = 0; y < avctx->height; y++) {
216 ptr[0] = p->data[0] + y * p->linesize[0];
217 ptr[1] = p->data[1] + y * p->linesize[1];
218 ptr[2] = p->data[2] + y * p->linesize[2];
219 ptr[3] = p->data[3] + y * p->linesize[3];
220 for (x = 0; x < avctx->width; x++) {
221 AV_WN32(ptr[2], AV_RN32(buf));
222 AV_WN32(ptr[0], AV_RN32(buf + 4));
223 AV_WN32(ptr[1], AV_RN32(buf + 8));
224 if (avctx->pix_fmt == AV_PIX_FMT_GBRAPF32BE ||
225 avctx->pix_fmt == AV_PIX_FMT_GBRAPF32LE) {
226 AV_WN32(ptr[3], AV_RN32(buf + 12));
227 buf += 4;
228 ptr[3] += 4;
229 }
230
231 buf += 12;
232 ptr[2] += 4;
233 ptr[0] += 4;
234 ptr[1] += 4;
235 }
236 }
237 }
238 break;
239 case 16:
240 elements *= 2;
242 case 8:
243 if ( avctx->pix_fmt == AV_PIX_FMT_YUVA444P
244 || avctx->pix_fmt == AV_PIX_FMT_YUV444P) {
245 for (x = 0; x < avctx->height; x++) {
246 ptr[0] = p->data[0] + x * p->linesize[0];
247 ptr[1] = p->data[1] + x * p->linesize[1];
248 ptr[2] = p->data[2] + x * p->linesize[2];
249 ptr[3] = p->data[3] + x * p->linesize[3];
250 for (y = 0; y < avctx->width; y++) {
251 *ptr[1]++ = *buf++;
252 *ptr[0]++ = *buf++;
253 *ptr[2]++ = *buf++;
254 if (avctx->pix_fmt == AV_PIX_FMT_YUVA444P)
255 *ptr[3]++ = *buf++;
256 }
257 }
258 } else {
259 av_image_copy_plane(ptr[0], p->linesize[0],
260 buf, dpx->stride,
261 elements * avctx->width, avctx->height);
262 }
263 break;
264 }
265}
266
269{
270 enum AVPixelFormat pix_fmts[] = {
271#if CONFIG_DPX_VULKAN_HWACCEL
273#endif
274 pix_fmt,
276 };
277
278 return ff_get_format(avctx, pix_fmts);
279}
280
281static int decode_frame(AVCodecContext *avctx, AVFrame *p,
282 int *got_frame, AVPacket *avpkt)
283{
284 DPXDecContext *dpx = avctx->priv_data;
285
287 const uint8_t *buf = avpkt->data;
288 int buf_size = avpkt->size;
289 uint32_t header_version, version = 0;
290 char creator[101] = { 0 };
291 char input_device[33] = { 0 };
292
293 unsigned int offset;
294 int magic_num;
295 int i, j, ret;
296 int w, h, descriptor;
297 int yuv, color_trc, color_spec;
298 int encoding;
299
300 if (avpkt->size <= 1634) {
301 av_log(avctx, AV_LOG_ERROR, "Packet too small for DPX header\n");
302 return AVERROR_INVALIDDATA;
303 }
304
305 magic_num = AV_RB32(buf);
306 buf += 4;
307
308 /* Check if the files "magic number" is "SDPX" which means it uses
309 * big-endian or XPDS which is for little-endian files */
310 if (magic_num == AV_RL32("SDPX")) {
311 dpx->endian = 0;
312 } else if (magic_num == AV_RB32("SDPX")) {
313 dpx->endian = 1;
314 } else {
315 av_log(avctx, AV_LOG_ERROR, "DPX marker not found\n");
316 return AVERROR_INVALIDDATA;
317 }
318
319 offset = read32(&buf, dpx->endian);
320 if (avpkt->size <= offset) {
321 av_log(avctx, AV_LOG_ERROR, "Invalid data start offset\n");
322 return AVERROR_INVALIDDATA;
323 }
324
325 header_version = read32(&buf, 0);
326 if (header_version == MKTAG('V','1','.','0'))
327 version = 1;
328 if (header_version == MKTAG('V','2','.','0'))
329 version = 2;
330 if (!version)
331 av_log(avctx, AV_LOG_WARNING, "Unknown header format version %s.\n",
332 av_fourcc2str(header_version));
333
334 // Check encryption
335 buf = avpkt->data + 660;
336 ret = read32(&buf, dpx->endian);
337 if (ret != 0xFFFFFFFF) {
338 avpriv_report_missing_feature(avctx, "Encryption");
339 av_log(avctx, AV_LOG_WARNING, "The image is encrypted and may "
340 "not properly decode.\n");
341 }
342
343 // Need to end in 0x304 offset from start of file
344 buf = avpkt->data + 0x304;
345 w = read32(&buf, dpx->endian);
346 h = read32(&buf, dpx->endian);
347
348 if ((ret = ff_set_dimensions(avctx, w, h)) < 0)
349 return ret;
350
351 // Need to end in 0x320 to read the descriptor
352 buf += 20;
353 descriptor = buf[0];
354 color_trc = buf[1];
355 color_spec = buf[2];
356
357 // Need to end in 0x323 to read the bits per color
358 buf += 3;
359 avctx->bits_per_raw_sample = buf[0];
360 buf++;
361 dpx->packing = read16(&buf, dpx->endian);
362 encoding = read16(&buf, dpx->endian);
363
364 if (encoding) {
365 avpriv_report_missing_feature(avctx, "Encoding %d", encoding);
367 }
368
369 if (avctx->bits_per_raw_sample > 31)
370 return AVERROR_INVALIDDATA;
371
372 buf += 820;
373 avctx->sample_aspect_ratio.num = read32(&buf, dpx->endian);
374 avctx->sample_aspect_ratio.den = read32(&buf, dpx->endian);
375 if (avctx->sample_aspect_ratio.num > 0 && avctx->sample_aspect_ratio.den > 0)
378 0x10000);
379 else
380 avctx->sample_aspect_ratio = (AVRational){ 0, 1 };
381
382 /* preferred frame rate from Motion-picture film header */
383 if (offset >= 1724 + 4) {
384 buf = avpkt->data + 1724;
385 i = read32(&buf, dpx->endian);
386 if(i && i != 0xFFFFFFFF) {
387 AVRational q = av_d2q(av_int2float(i), 4096);
388 if (q.num > 0 && q.den > 0)
389 avctx->framerate = q;
390 }
391 }
392
393 /* alternative frame rate from television header */
394 if (offset >= 1940 + 4 &&
395 !(avctx->framerate.num && avctx->framerate.den)) {
396 buf = avpkt->data + 1940;
397 i = read32(&buf, dpx->endian);
398 if(i && i != 0xFFFFFFFF) {
399 AVRational q = av_d2q(av_int2float(i), 4096);
400 if (q.num > 0 && q.den > 0)
401 avctx->framerate = q;
402 }
403 }
404
405 /* SMPTE TC from television header */
406 if (offset >= 1920 + 4) {
407 uint32_t tc;
408 uint32_t *tc_sd;
409 char tcbuf[AV_TIMECODE_STR_SIZE];
410
411 buf = avpkt->data + 1920;
412 // read32 to native endian, av_bswap32 to opposite of native for
413 // compatibility with av_timecode_make_smpte_tc_string2 etc
414 tc = av_bswap32(read32(&buf, dpx->endian));
415
416 if (i != 0xFFFFFFFF) {
417 AVFrameSideData *tcside;
419 sizeof(uint32_t) * 4, &tcside);
420 if (ret < 0)
421 return ret;
422
423 if (tcside) {
424 tc_sd = (uint32_t*)tcside->data;
425 tc_sd[0] = 1;
426 tc_sd[1] = tc;
427
429 tc_sd[1], 0, 0);
430 av_dict_set(&p->metadata, "timecode", tcbuf, 0);
431 }
432 }
433 }
434
435 /* color range from television header */
436 if (offset >= 1964 + 4) {
437 buf = avpkt->data + 1952;
438 i = read32(&buf, dpx->endian);
439
440 buf = avpkt->data + 1964;
441 j = read32(&buf, dpx->endian);
442
443 if (i != 0xFFFFFFFF && j != 0xFFFFFFFF) {
444 float minCV, maxCV;
445 minCV = av_int2float(i);
446 maxCV = av_int2float(j);
447 if (avctx->bits_per_raw_sample >= 1 &&
448 minCV == 0.0f && maxCV == ((1U<<avctx->bits_per_raw_sample) - 1)) {
450 } else if (avctx->bits_per_raw_sample >= 8 &&
451 minCV == (1 <<(avctx->bits_per_raw_sample - 4)) &&
452 maxCV == (235<<(avctx->bits_per_raw_sample - 8))) {
454 }
455 }
456 }
457
458 switch (descriptor) {
459 case 1: // R
460 case 2: // G
461 case 3: // B
462 case 4: // A
463 case 6: // Y
464 dpx->components = 1;
465 yuv = 1;
466 break;
467 case 50: // RGB
468 dpx->components = 3;
469 yuv = 0;
470 break;
471 case 52: // ABGR
472 case 51: // RGBA
473 dpx->components = 4;
474 yuv = 0;
475 break;
476 case 100: // UYVY422
477 dpx->components = 2;
478 yuv = 1;
479 break;
480 case 102: // UYV444
481 dpx->components = 3;
482 yuv = 1;
483 break;
484 case 103: // UYVA4444
485 dpx->components = 4;
486 yuv = 1;
487 break;
488 default:
489 avpriv_report_missing_feature(avctx, "Descriptor %d", descriptor);
491 }
492
493 switch (avctx->bits_per_raw_sample) {
494 case 8:
495 dpx->stride = avctx->width * dpx->components;
496 break;
497 case 10:
498 if (!dpx->packing) {
499 av_log(avctx, AV_LOG_ERROR, "Packing to 32bit required\n");
500 return -1;
501 }
502 dpx->stride = (avctx->width * dpx->components + 2) / 3 * 4;
503 break;
504 case 12:
505 dpx->stride = avctx->width * dpx->components;
506 if (dpx->packing) {
507 dpx->stride *= 2;
508 } else {
509 dpx->stride *= 3;
510 if (dpx->stride % 8) {
511 dpx->stride /= 8;
512 dpx->stride++;
513 dpx->stride *= 8;
514 }
515 dpx->stride /= 2;
516 }
517 break;
518 case 16:
519 dpx->stride = 2 * avctx->width * dpx->components;
520 break;
521 case 32:
522 dpx->stride = 4 * avctx->width * dpx->components;
523 break;
524 case 1:
525 case 64:
526 avpriv_report_missing_feature(avctx, "Depth %d", avctx->bits_per_raw_sample);
528 default:
529 return AVERROR_INVALIDDATA;
530 }
531
532 switch (color_trc) {
533 case DPX_TRC_LINEAR:
535 break;
538 avctx->color_trc = AVCOL_TRC_BT709;
539 break;
544 break;
547 break;
550 /* Nothing to do */
551 break;
552 default:
553 av_log(avctx, AV_LOG_VERBOSE, "Cannot map DPX transfer characteristic "
554 "%d to color_trc.\n", color_trc);
555 break;
556 }
557
558 switch (color_spec) {
562 break;
566 break;
570 break;
573 /* Nothing to do */
574 break;
575 default:
576 av_log(avctx, AV_LOG_VERBOSE, "Cannot map DPX color specification "
577 "%d to color_primaries.\n", color_spec);
578 break;
579 }
580
581 if (yuv) {
582 switch (color_spec) {
586 break;
590 break;
594 break;
597 /* Nothing to do */
598 break;
599 default:
600 av_log(avctx, AV_LOG_INFO, "Cannot map DPX color specification "
601 "%d to colorspace.\n", color_spec);
602 break;
603 }
604 } else {
605 avctx->colorspace = AVCOL_SPC_RGB;
606 }
607
608 av_strlcpy(creator, avpkt->data + 160, 100);
609 creator[100] = '\0';
610 av_dict_set(&p->metadata, "Creator", creator, 0);
611
612 av_strlcpy(input_device, avpkt->data + 1556, 32);
613 input_device[32] = '\0';
614 av_dict_set(&p->metadata, "Input Device", input_device, 0);
615
616 // Some devices do not pad 10bit samples to whole 32bit words per row
617 dpx->unpadded_10bit = 0;
618 if (!memcmp(input_device, "Scanity", 7) ||
619 !memcmp(creator, "Lasergraphics Inc.", 18)) {
620 if (avctx->bits_per_raw_sample == 10)
621 dpx->unpadded_10bit = 1;
622 }
623
624 // Table 3c: Runs will always break at scan line boundaries. Packing
625 // will always break to the next 32-bit word at scan-line boundaries.
626 // Unfortunately, the encoder produced invalid files, so attempt
627 // to detect it
628 // Also handle special case with unpadded content
629 dpx->need_align = FFALIGN(dpx->stride, 4);
630 if (dpx->need_align*avctx->height + (int64_t)offset > avpkt->size &&
631 (!dpx->unpadded_10bit || (avctx->width * avctx->height * dpx->components + 2) / 3 * 4 + (int64_t)offset > avpkt->size)) {
632 // Alignment seems unappliable, try without
633 if (dpx->stride*avctx->height + (int64_t)offset > avpkt->size || dpx->unpadded_10bit) {
634 av_log(avctx, AV_LOG_ERROR, "Overread buffer. Invalid header?\n");
635 return AVERROR_INVALIDDATA;
636 } else {
637 av_log(avctx, AV_LOG_INFO, "Decoding DPX without scanline "
638 "alignment.\n");
639 dpx->need_align = 0;
640 }
641 } else {
642 dpx->need_align -= dpx->stride;
643 dpx->stride = FFALIGN(dpx->stride, 4);
644 }
645
646 switch (1000 * descriptor + 10 * avctx->bits_per_raw_sample + dpx->endian) {
647 case 1081:
648 case 1080:
649 case 2081:
650 case 2080:
651 case 3081:
652 case 3080:
653 case 4081:
654 case 4080:
655 case 6081:
656 case 6080:
658 break;
659 case 6121:
660 case 6120:
662 break;
663 case 1320:
664 case 2320:
665 case 3320:
666 case 4320:
667 case 6320:
669 break;
670 case 1321:
671 case 2321:
672 case 3321:
673 case 4321:
674 case 6321:
676 break;
677 case 50081:
678 case 50080:
680 break;
681 case 52081:
682 case 52080:
684 break;
685 case 51081:
686 case 51080:
688 break;
689 case 50100:
690 case 50101:
692 break;
693 case 51100:
694 case 51101:
696 break;
697 case 50120:
698 case 50121:
700 break;
701 case 51120:
702 case 51121:
704 break;
705 case 6100:
706 case 6101:
708 break;
709 case 6161:
711 break;
712 case 6160:
714 break;
715 case 50161:
717 break;
718 case 50160:
720 break;
721 case 51161:
723 break;
724 case 51160:
726 break;
727 case 50320:
729 break;
730 case 50321:
732 break;
733 case 51320:
735 break;
736 case 51321:
738 break;
739 case 100081:
741 break;
742 case 102081:
744 break;
745 case 103081:
747 break;
748 default:
749 av_log(avctx, AV_LOG_ERROR, "Unsupported format %d\n",
750 1000 * descriptor + 10 * avctx->bits_per_raw_sample + dpx->endian);
752 }
753
754 if (pix_fmt != dpx->pix_fmt) {
755 dpx->pix_fmt = pix_fmt;
756
757 ret = get_pixel_format(avctx, pix_fmt);
758 if (ret < 0)
759 return ret;
760
761 avctx->pix_fmt = ret;
762 }
763
764 ff_set_sar(avctx, avctx->sample_aspect_ratio);
765
766 if ((ret = ff_get_buffer(avctx, p, 0)) < 0)
767 return ret;
768
769 // Move pointer to offset from start of file
770 buf = avpkt->data + offset;
771 dpx->frame = p;
772
773 /* Start */
774 if (avctx->hwaccel) {
775 const FFHWAccel *hwaccel = ffhwaccel(avctx->hwaccel);
776
778 if (ret < 0)
779 return ret;
780
781 ret = hwaccel->start_frame(avctx, avpkt->buf, buf, avpkt->size - offset);
782 if (ret < 0)
783 return ret;
784
785 ret = hwaccel->decode_slice(avctx, buf, avpkt->size - offset);
786 if (ret < 0)
787 return ret;
788
789 ret = hwaccel->end_frame(avctx);
790 if (ret < 0)
791 return ret;
792
794 } else {
795 unpack_frame(avctx, p, buf, dpx->components, dpx->endian);
796 }
797
798 p->pict_type = AV_PICTURE_TYPE_I;
799 p->flags |= AV_FRAME_FLAG_KEY;
800
801 *got_frame = 1;
802
803 return buf_size;
804}
805
806#if HAVE_THREADS
807static int update_thread_context(AVCodecContext *dst, const AVCodecContext *src)
808{
809 DPXDecContext *ssrc = src->priv_data;
810 DPXDecContext *sdst = dst->priv_data;
811
812 sdst->pix_fmt = ssrc->pix_fmt;
813
814 return 0;
815}
816#endif
817
819{
820 DPXDecContext *dpx = avctx->priv_data;
822 return 0;
823}
824
826{
827 DPXDecContext *dpx = avctx->priv_data;
829 return 0;
830}
831
833 .p.name = "dpx",
834 CODEC_LONG_NAME("DPX (Digital Picture Exchange) image"),
835 .priv_data_size = sizeof(DPXDecContext),
836 .p.type = AVMEDIA_TYPE_VIDEO,
837 .p.id = AV_CODEC_ID_DPX,
839 .init = decode_init,
840 .close = decode_end,
841 UPDATE_THREAD_CONTEXT(update_thread_context),
843 .caps_internal = FF_CODEC_CAP_INIT_CLEANUP |
845 .hw_configs = (const AVCodecHWConfigInternal *const []) {
846#if CONFIG_DPX_VULKAN_HWACCEL
847 HWACCEL_VULKAN(dpx),
848#endif
849 NULL
850 },
851};
uint8_t ptrdiff_t const uint8_t ptrdiff_t int intptr_t intptr_t int int16_t * dst
Definition dsp.h:87
const FFCodec ff_dpx_decoder
Definition dpx.c:832
Libavcodec external API header.
#define i(width, name, range_min, range_max)
Definition cbs_h264.c:63
#define UPDATE_THREAD_CONTEXT(func)
#define FF_CODEC_CAP_SKIP_FRAME_FILL_PARAM
The decoder extracts and fills its parameters even if the frame is skipped due to the skip_frame sett...
#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...
#define NULL
Definition coverity.c:32
long long int64_t
Definition coverity.c:34
int ff_get_buffer(AVCodecContext *avctx, AVFrame *frame, int flags)
Get a buffer for a frame.
Definition decode.c:1777
int ff_get_format(AVCodecContext *avctx, const enum AVPixelFormat *fmt)
Select the (possibly hardware accelerated) pixel format.
Definition decode.c:1229
int ff_hwaccel_frame_priv_alloc(AVCodecContext *avctx, void **hwaccel_picture_private)
Allocate a hwaccel frame private data if the provided avctx uses a hwaccel method that needs it.
Definition decode.c:2336
int ff_frame_new_side_data(const AVCodecContext *avctx, AVFrame *frame, enum AVFrameSideDataType type, size_t size, AVFrameSideData **psd)
Wrapper around av_frame_new_side_data, which rejects side data overridden by the demuxer.
Definition decode.c:2184
int ff_set_sar(AVCodecContext *avctx, AVRational sar)
Check that the provided sample aspect ratio is valid and set it on the codec context.
Definition utils.c:106
int ff_set_dimensions(AVCodecContext *s, int width, int height)
Definition utils.c:91
static enum AVPixelFormat pix_fmt
static void unpack_frame(AVCodecContext *avctx, AVFrame *p, const uint8_t *buf, int elements, int endian)
Definition dpx.c:127
static uint16_t read12in32(const uint8_t **ptr, uint32_t *lbuf, int *n_datum, int is_big)
Definition dpx.c:95
static enum AVPixelFormat get_pixel_format(AVCodecContext *avctx, enum AVPixelFormat pix_fmt)
Definition dpx.c:267
static av_cold int decode_init(AVCodecContext *avctx)
Definition dpx.c:825
static av_cold int decode_end(AVCodecContext *avctx)
Definition dpx.c:818
static int decode_frame(AVCodecContext *avctx, AVFrame *p, int *got_frame, AVPacket *avpkt)
Definition dpx.c:281
static unsigned int read16(const uint8_t **ptr, int is_big)
Definition dpx.c:38
static uint16_t read10in32_gray(const uint8_t **ptr, uint32_t *lbuf, int *n_datum, int is_big, int shift)
Definition dpx.c:62
static unsigned int read32(const uint8_t **ptr, int is_big)
Definition dpx.c:50
static uint16_t read10in32(const uint8_t **ptr, uint32_t *lbuf, int *n_datum, int is_big, int shift)
Definition dpx.c:80
@ DPX_COL_SPEC_USER_DEFINED
Definition dpx.h:45
@ DPX_COL_SPEC_SMPTE_170
Definition dpx.h:54
@ DPX_COL_SPEC_UNSPECIFIED_VIDEO
Definition dpx.h:49
@ DPX_COL_SPEC_ITU_R_624_4_PAL
Definition dpx.h:55
@ DPX_COL_SPEC_ITU_R_601_525
Definition dpx.h:53
@ DPX_COL_SPEC_ITU_R_601_625
Definition dpx.h:52
@ DPX_COL_SPEC_SMPTE_274
Definition dpx.h:50
@ DPX_COL_SPEC_ITU_R_709_4
Definition dpx.h:51
@ DPX_TRC_ITU_R_601_625
Definition dpx.h:36
@ DPX_TRC_UNSPECIFIED_VIDEO
Definition dpx.h:33
@ DPX_TRC_ITU_R_624_4_PAL
Definition dpx.h:39
@ DPX_TRC_ITU_R_601_525
Definition dpx.h:37
@ DPX_TRC_ITU_R_709_4
Definition dpx.h:35
@ DPX_TRC_SMPTE_274
Definition dpx.h:34
@ DPX_TRC_LINEAR
Definition dpx.h:31
@ DPX_TRC_USER_DEFINED
Definition dpx.h:29
@ DPX_TRC_SMPTE_170
Definition dpx.h:38
static const char * hwaccel
Definition ffplay.c:357
#define AV_NUM_DATA_POINTERS
Definition frame.h:473
#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_DPX
Definition codec_id.h:178
int av_dict_set(AVDictionary **pm, const char *key, const char *value, int flags)
Set the given entry in *pm, overwriting an existing entry.
Definition dict.c:86
#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 AV_FRAME_FLAG_KEY
A flag to mark frames that are keyframes.
Definition frame.h:687
@ AV_FRAME_DATA_S12M_TIMECODE
Timecode which conforms to SMPTE ST 12-1.
Definition frame.h:152
#define AV_LOG_WARNING
Something somehow does not look correct.
Definition log.h:216
#define AV_LOG_VERBOSE
Detailed information.
Definition log.h:226
#define AV_LOG_INFO
Standard information.
Definition log.h:221
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition log.h:210
int av_reduce(int *dst_num, int *dst_den, int64_t num, int64_t den, int64_t max)
Reduce a fraction.
Definition rational.c:35
AVRational av_d2q(double d, int max)
Convert a double precision floating point number to a rational.
Definition rational.c:110
#define av_fourcc2str(fourcc)
Definition avutil.h:323
@ AVMEDIA_TYPE_VIDEO
Definition avutil.h:200
void av_image_copy_plane(uint8_t *dst, int dst_linesize, const uint8_t *src, int src_linesize, int bytewidth, int height)
Copy image plane from src to dst.
Definition imgutils.c:374
@ AV_PICTURE_TYPE_I
Intra.
Definition avutil.h:278
size_t av_strlcpy(char *dst, const char *src, size_t size)
Copy the string src to dst, but no more than size - 1 bytes, and null-terminate dst.
Definition avstring.c:85
static const FFHWAccel * ffhwaccel(const AVHWAccel *codec)
#define HWACCEL_VULKAN(codec)
Definition hwconfig.h:78
misc image utilities
static av_always_inline float av_int2float(uint32_t i)
Reinterpret a 32-bit integer as a float.
Definition intfloat.h:40
#define AV_WN32(p, v)
#define AV_RN32(p)
#define AV_RL32(p)
#define AV_RB32(p)
#define AV_RL16(p)
#define AV_RB16(p)
unsigned offset
Definition libaomenc.c:763
static av_cold int decode_init(AVCodecContext *avctx)
Definition 4xm.c:998
static av_cold int decode_end(AVCodecContext *avctx)
Definition 4xm.c:980
static int decode_frame(AVCodecContext *avctx, AVFrame *picture, int *got_frame, AVPacket *avpkt)
Definition 4xm.c:837
static int shift(int a, int b)
Definition bonk.c:261
Multithreading API for decoders.
Macro definitions for various function/variable attributes.
#define av_fallthrough
Definition attributes.h:67
#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.
version
Definition libkvazaar.c:313
static enum AVPixelFormat pix_fmts[]
Definition libkvazaar.c:296
uint8_t w
Definition llvidencdsp.c:39
#define MKTAG(a, b, c, d)
Definition macros.h:55
#define FFALIGN(x, a)
Definition macros.h:78
#define AV_PIX_FMT_GBRAP12
Definition pixfmt.h:569
@ AVCOL_RANGE_MPEG
Narrow or limited range content.
Definition pixfmt.h:766
@ AVCOL_RANGE_JPEG
Full range content.
Definition pixfmt.h:783
#define AV_PIX_FMT_GBRP10
Definition pixfmt.h:564
#define AV_PIX_FMT_GRAY12
Definition pixfmt.h:526
#define AV_PIX_FMT_GBRP12
Definition pixfmt.h:565
AVPixelFormat
Pixel format.
Definition pixfmt.h:71
@ AV_PIX_FMT_GRAY16BE
Y , 16bpp, big-endian.
Definition pixfmt.h:104
@ AV_PIX_FMT_NONE
Definition pixfmt.h:72
@ AV_PIX_FMT_VULKAN
Vulkan hardware images.
Definition pixfmt.h:379
@ AV_PIX_FMT_RGB24
packed RGB 8:8:8, 24bpp, RGBRGB...
Definition pixfmt.h:75
@ AV_PIX_FMT_GRAYF32LE
IEEE-754 single precision Y, 32bpp, little-endian.
Definition pixfmt.h:364
@ AV_PIX_FMT_GBRPF32BE
IEEE-754 single precision planar GBR 4:4:4, 96bpp, big-endian.
Definition pixfmt.h:341
@ AV_PIX_FMT_GRAY8
Y , 8bpp.
Definition pixfmt.h:81
@ AV_PIX_FMT_UYVY422
packed YUV 4:2:2, 16bpp, Cb Y0 Cr Y1
Definition pixfmt.h:88
@ AV_PIX_FMT_RGB48BE
packed RGB 16:16:16, 48bpp, 16R, 16G, 16B, the 2-byte value for each R/G/B component is stored as big...
Definition pixfmt.h:109
@ AV_PIX_FMT_ABGR
packed ABGR 8:8:8:8, 32bpp, ABGRABGR...
Definition pixfmt.h:101
@ AV_PIX_FMT_RGBA64BE
packed RGBA 16:16:16:16, 64bpp, 16R, 16G, 16B, 16A, the 2-byte value for each R/G/B/A component is st...
Definition pixfmt.h:202
@ AV_PIX_FMT_RGBA64LE
packed RGBA 16:16:16:16, 64bpp, 16R, 16G, 16B, 16A, the 2-byte value for each R/G/B/A component is st...
Definition pixfmt.h:203
@ AV_PIX_FMT_GBRPF32LE
IEEE-754 single precision planar GBR 4:4:4, 96bpp, little-endian.
Definition pixfmt.h:342
@ AV_PIX_FMT_RGBA
packed RGBA 8:8:8:8, 32bpp, RGBARGBA...
Definition pixfmt.h:100
@ AV_PIX_FMT_YUV444P
planar YUV 4:4:4, 24bpp, (1 Cr & Cb sample per 1x1 Y samples)
Definition pixfmt.h:78
@ AV_PIX_FMT_YUVA444P
planar YUV 4:4:4 32bpp, (1 Cr & Cb sample per 1x1 Y & A samples)
Definition pixfmt.h:174
@ AV_PIX_FMT_RGB48LE
packed RGB 16:16:16, 48bpp, 16R, 16G, 16B, the 2-byte value for each R/G/B component is stored as lit...
Definition pixfmt.h:110
@ AV_PIX_FMT_GBRAPF32BE
IEEE-754 single precision planar GBRA 4:4:4:4, 128bpp, big-endian.
Definition pixfmt.h:343
@ AV_PIX_FMT_GBRAPF32LE
IEEE-754 single precision planar GBRA 4:4:4:4, 128bpp, little-endian.
Definition pixfmt.h:344
@ AV_PIX_FMT_GRAYF32BE
IEEE-754 single precision Y, 32bpp, big-endian.
Definition pixfmt.h:363
@ AV_PIX_FMT_GRAY16LE
Y , 16bpp, little-endian.
Definition pixfmt.h:105
#define AV_PIX_FMT_GRAY10
Definition pixfmt.h:525
#define AV_PIX_FMT_GBRAP10
Definition pixfmt.h:568
@ AVCOL_PRI_BT470BG
also ITU-R BT601-6 625 / ITU-R BT1358 625 / ITU-R BT1700 625 PAL & SECAM
Definition pixfmt.h:649
@ AVCOL_PRI_BT709
also ITU-R BT1361 / IEC 61966-2-4 / SMPTE RP 177 Annex B
Definition pixfmt.h:644
@ AVCOL_PRI_SMPTE170M
also ITU-R BT601-6 525 / ITU-R BT1358 525 / ITU-R BT1700 NTSC
Definition pixfmt.h:650
@ AVCOL_TRC_SMPTE170M
also ITU-R BT601-6 525 or 625 / ITU-R BT1358 525 or 625 / ITU-R BT1700 NTSC
Definition pixfmt.h:679
@ AVCOL_TRC_LINEAR
"Linear transfer characteristics"
Definition pixfmt.h:681
@ AVCOL_TRC_GAMMA28
also ITU-R BT470BG
Definition pixfmt.h:678
@ AVCOL_TRC_BT709
also ITU-R BT1361
Definition pixfmt.h:674
@ AVCOL_SPC_BT709
also ITU-R BT1361 / IEC 61966-2-4 xvYCC709 / derived in SMPTE RP 177 Annex B
Definition pixfmt.h:708
@ AVCOL_SPC_BT470BG
also ITU-R BT601-6 625 / ITU-R BT1358 625 / ITU-R BT1700 625 PAL & SECAM / IEC 61966-2-4 xvYCC601
Definition pixfmt.h:712
@ AVCOL_SPC_RGB
order of coefficients is actually GBR, also IEC 61966-2-1 (sRGB), YZX and ST 428-1
Definition pixfmt.h:707
@ AVCOL_SPC_SMPTE170M
also ITU-R BT601-6 525 / ITU-R BT1358 525 / ITU-R BT1700 NTSC / functionally identical to above
Definition pixfmt.h:713
void av_refstruct_unref(void *objp)
Decrement the reference count of the underlying object and automatically free the object if there are...
Definition refstruct.c:120
#define av_bswap32
Definition bswap.h:47
static const ElemCat * elements[ELEMENT_COUNT]
Definition signature.h:565
main external API structure.
Definition avcodec.h:443
enum AVPixelFormat pix_fmt
Pixel format, see AV_PIX_FMT_xxx.
Definition avcodec.h:643
int width
picture width / height.
Definition avcodec.h:604
enum AVColorRange color_range
MPEG vs JPEG YUV range.
Definition avcodec.h:681
enum AVColorPrimaries color_primaries
Chromaticity coordinates of the source primaries.
Definition avcodec.h:657
AVRational framerate
Definition avcodec.h:563
AVRational sample_aspect_ratio
sample aspect ratio (0 if unknown) That is the width of a pixel divided by the height of the pixel.
Definition avcodec.h:628
const struct AVHWAccel * hwaccel
Hardware accelerator in use.
Definition avcodec.h:1423
int bits_per_raw_sample
Bits per sample/pixel of internal libavcodec pixel/sample format.
Definition avcodec.h:1571
enum AVColorSpace colorspace
YUV colorspace type.
Definition avcodec.h:671
enum AVColorTransferCharacteristic color_trc
Color Transfer Characteristic.
Definition avcodec.h:664
void * priv_data
Definition avcodec.h:470
Structure to hold side data for an AVFrame.
Definition frame.h:327
uint8_t * data
Definition frame.h:329
This structure describes decoded (raw) audio or video data.
Definition frame.h:472
This structure stores compressed data.
Definition packet.h:580
AVBufferRef * buf
A reference to the reference-counted buffer where the packet data is stored.
Definition packet.h:586
int size
Definition packet.h:604
uint8_t * data
Definition packet.h:603
Rational number (pair of numerator and denominator).
Definition rational.h:58
int num
Numerator.
Definition rational.h:59
int den
Denominator.
Definition rational.h:60
int need_align
Definition dpx.h:70
void * hwaccel_picture_private
Definition dpx.h:62
AVFrame * frame
Definition dpx.h:61
int packing
Definition dpx.h:65
int endian
Definition dpx.h:67
enum AVPixelFormat pix_fmt
Definition dpx.h:63
int unpadded_10bit
Definition dpx.h:69
int components
Definition dpx.h:68
int stride
Definition dpx.h:66
#define av_log(a,...)
#define src
Definition vp8dsp.c:248
char * av_timecode_make_smpte_tc_string2(char *buf, AVRational rate, uint32_t tcsmpte, int prevent_df, int skip_field)
Get the timecode string from the SMPTE timecode format.
Definition timecode.c:131
Timecode helpers header.
#define AV_TIMECODE_STR_SIZE
Definition timecode.h:33
else temp
Definition vf_mcdeint.c:275
static double c[64]