Line | Branch | Exec | Source |
---|---|---|---|
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 | |||
22 | #include "libavutil/avstring.h" | ||
23 | #include "libavutil/intreadwrite.h" | ||
24 | #include "libavutil/intfloat.h" | ||
25 | #include "libavutil/imgutils.h" | ||
26 | #include "libavutil/timecode.h" | ||
27 | #include "avcodec.h" | ||
28 | #include "codec_internal.h" | ||
29 | #include "decode.h" | ||
30 | |||
31 | enum DPX_TRC { | ||
32 | DPX_TRC_USER_DEFINED = 0, | ||
33 | DPX_TRC_PRINTING_DENSITY = 1, | ||
34 | DPX_TRC_LINEAR = 2, | ||
35 | DPX_TRC_LOGARITHMIC = 3, | ||
36 | DPX_TRC_UNSPECIFIED_VIDEO = 4, | ||
37 | DPX_TRC_SMPTE_274 = 5, | ||
38 | DPX_TRC_ITU_R_709_4 = 6, | ||
39 | DPX_TRC_ITU_R_601_625 = 7, | ||
40 | DPX_TRC_ITU_R_601_525 = 8, | ||
41 | DPX_TRC_SMPTE_170 = 9, | ||
42 | DPX_TRC_ITU_R_624_4_PAL = 10, | ||
43 | DPX_TRC_Z_LINEAR = 11, | ||
44 | DPX_TRC_Z_HOMOGENEOUS = 12, | ||
45 | }; | ||
46 | |||
47 | enum DPX_COL_SPEC { | ||
48 | DPX_COL_SPEC_USER_DEFINED = 0, | ||
49 | DPX_COL_SPEC_PRINTING_DENSITY = 1, | ||
50 | /* 2 = N/A */ | ||
51 | /* 3 = N/A */ | ||
52 | DPX_COL_SPEC_UNSPECIFIED_VIDEO = 4, | ||
53 | DPX_COL_SPEC_SMPTE_274 = 5, | ||
54 | DPX_COL_SPEC_ITU_R_709_4 = 6, | ||
55 | DPX_COL_SPEC_ITU_R_601_625 = 7, | ||
56 | DPX_COL_SPEC_ITU_R_601_525 = 8, | ||
57 | DPX_COL_SPEC_SMPTE_170 = 9, | ||
58 | DPX_COL_SPEC_ITU_R_624_4_PAL = 10, | ||
59 | /* 11 = N/A */ | ||
60 | /* 12 = N/A */ | ||
61 | }; | ||
62 | |||
63 | 4257978 | static unsigned int read16(const uint8_t **ptr, int is_big) | |
64 | { | ||
65 | unsigned int temp; | ||
66 |
2/2✓ Branch 0 taken 4 times.
✓ Branch 1 taken 4257974 times.
|
4257978 | if (is_big) { |
67 | 4 | temp = AV_RB16(*ptr); | |
68 | } else { | ||
69 | 4257974 | temp = AV_RL16(*ptr); | |
70 | } | ||
71 | 4257978 | *ptr += 2; | |
72 | 4257978 | return temp; | |
73 | } | ||
74 | |||
75 | 3044637 | static unsigned int read32(const uint8_t **ptr, int is_big) | |
76 | { | ||
77 | unsigned int temp; | ||
78 |
2/2✓ Branch 0 taken 22 times.
✓ Branch 1 taken 3044615 times.
|
3044637 | if (is_big) { |
79 | 22 | temp = AV_RB32(*ptr); | |
80 | } else { | ||
81 | 3044615 | temp = AV_RL32(*ptr); | |
82 | } | ||
83 | 3044637 | *ptr += 4; | |
84 | 3044637 | return temp; | |
85 | } | ||
86 | |||
87 | ✗ | static uint16_t read10in32_gray(const uint8_t **ptr, uint32_t *lbuf, | |
88 | int *n_datum, int is_big, int shift) | ||
89 | { | ||
90 | uint16_t temp; | ||
91 | |||
92 | ✗ | if (*n_datum) | |
93 | ✗ | (*n_datum)--; | |
94 | else { | ||
95 | ✗ | *lbuf = read32(ptr, is_big); | |
96 | ✗ | *n_datum = 2; | |
97 | } | ||
98 | |||
99 | ✗ | temp = *lbuf >> shift & 0x3FF; | |
100 | ✗ | *lbuf = *lbuf >> 10; | |
101 | |||
102 | ✗ | return temp; | |
103 | } | ||
104 | |||
105 | 9131904 | static uint16_t read10in32(const uint8_t **ptr, uint32_t *lbuf, | |
106 | int *n_datum, int is_big, int shift) | ||
107 | { | ||
108 |
2/2✓ Branch 0 taken 6087936 times.
✓ Branch 1 taken 3043968 times.
|
9131904 | if (*n_datum) |
109 | 6087936 | (*n_datum)--; | |
110 | else { | ||
111 | 3043968 | *lbuf = read32(ptr, is_big); | |
112 | 3043968 | *n_datum = 2; | |
113 | } | ||
114 | |||
115 | 9131904 | *lbuf = *lbuf << 10 | *lbuf >> shift & 0x3FFFFF; | |
116 | |||
117 | 9131904 | return *lbuf & 0x3FF; | |
118 | } | ||
119 | |||
120 | ✗ | static uint16_t read12in32(const uint8_t **ptr, uint32_t *lbuf, | |
121 | int *n_datum, int is_big) | ||
122 | { | ||
123 | ✗ | if (*n_datum) | |
124 | ✗ | (*n_datum)--; | |
125 | else { | ||
126 | ✗ | *lbuf = read32(ptr, is_big); | |
127 | ✗ | *n_datum = 7; | |
128 | } | ||
129 | |||
130 | ✗ | switch (*n_datum){ | |
131 | ✗ | case 7: return *lbuf & 0xFFF; | |
132 | ✗ | case 6: return (*lbuf >> 12) & 0xFFF; | |
133 | ✗ | case 5: { | |
134 | ✗ | uint32_t c = *lbuf >> 24; | |
135 | ✗ | *lbuf = read32(ptr, is_big); | |
136 | ✗ | c |= *lbuf << 8; | |
137 | ✗ | return c & 0xFFF; | |
138 | } | ||
139 | ✗ | case 4: return (*lbuf >> 4) & 0xFFF; | |
140 | ✗ | case 3: return (*lbuf >> 16) & 0xFFF; | |
141 | ✗ | case 2: { | |
142 | ✗ | uint32_t c = *lbuf >> 28; | |
143 | ✗ | *lbuf = read32(ptr, is_big); | |
144 | ✗ | c |= *lbuf << 4; | |
145 | ✗ | return c & 0xFFF; | |
146 | } | ||
147 | ✗ | case 1: return (*lbuf >> 8) & 0xFFF; | |
148 | ✗ | default: return *lbuf >> 20; | |
149 | } | ||
150 | } | ||
151 | |||
152 | 93 | static int decode_frame(AVCodecContext *avctx, AVFrame *p, | |
153 | int *got_frame, AVPacket *avpkt) | ||
154 | { | ||
155 | 93 | const uint8_t *buf = avpkt->data; | |
156 | 93 | int buf_size = avpkt->size; | |
157 | uint8_t *ptr[AV_NUM_DATA_POINTERS]; | ||
158 | 93 | uint32_t header_version, version = 0; | |
159 | 93 | char creator[101] = { 0 }; | |
160 | 93 | char input_device[33] = { 0 }; | |
161 | |||
162 | unsigned int offset; | ||
163 | int magic_num, endian; | ||
164 | int x, y, stride, i, j, ret; | ||
165 | int w, h, bits_per_color, descriptor, elements, packing; | ||
166 | int yuv, color_trc, color_spec; | ||
167 | 93 | int encoding, need_align = 0, unpadded_10bit = 0; | |
168 | |||
169 | 93 | unsigned int rgbBuffer = 0; | |
170 | 93 | int n_datum = 0; | |
171 | |||
172 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 93 times.
|
93 | if (avpkt->size <= 1634) { |
173 | ✗ | av_log(avctx, AV_LOG_ERROR, "Packet too small for DPX header\n"); | |
174 | ✗ | return AVERROR_INVALIDDATA; | |
175 | } | ||
176 | |||
177 | 93 | magic_num = AV_RB32(buf); | |
178 | 93 | buf += 4; | |
179 | |||
180 | /* Check if the files "magic number" is "SDPX" which means it uses | ||
181 | * big-endian or XPDS which is for little-endian files */ | ||
182 |
2/2✓ Branch 0 taken 91 times.
✓ Branch 1 taken 2 times.
|
93 | if (magic_num == AV_RL32("SDPX")) { |
183 | 91 | endian = 0; | |
184 |
1/2✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
|
2 | } else if (magic_num == AV_RB32("SDPX")) { |
185 | 2 | endian = 1; | |
186 | } else { | ||
187 | ✗ | av_log(avctx, AV_LOG_ERROR, "DPX marker not found\n"); | |
188 | ✗ | return AVERROR_INVALIDDATA; | |
189 | } | ||
190 | |||
191 | 93 | offset = read32(&buf, endian); | |
192 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 93 times.
|
93 | if (avpkt->size <= offset) { |
193 | ✗ | av_log(avctx, AV_LOG_ERROR, "Invalid data start offset\n"); | |
194 | ✗ | return AVERROR_INVALIDDATA; | |
195 | } | ||
196 | |||
197 | 93 | header_version = read32(&buf, 0); | |
198 |
2/2✓ Branch 0 taken 89 times.
✓ Branch 1 taken 4 times.
|
93 | if (header_version == MKTAG('V','1','.','0')) |
199 | 89 | version = 1; | |
200 |
2/2✓ Branch 0 taken 4 times.
✓ Branch 1 taken 89 times.
|
93 | if (header_version == MKTAG('V','2','.','0')) |
201 | 4 | version = 2; | |
202 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 93 times.
|
93 | if (!version) |
203 | ✗ | av_log(avctx, AV_LOG_WARNING, "Unknown header format version %s.\n", | |
204 | ✗ | av_fourcc2str(header_version)); | |
205 | |||
206 | // Check encryption | ||
207 | 93 | buf = avpkt->data + 660; | |
208 | 93 | ret = read32(&buf, endian); | |
209 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 93 times.
|
93 | if (ret != 0xFFFFFFFF) { |
210 | ✗ | avpriv_report_missing_feature(avctx, "Encryption"); | |
211 | ✗ | av_log(avctx, AV_LOG_WARNING, "The image is encrypted and may " | |
212 | "not properly decode.\n"); | ||
213 | } | ||
214 | |||
215 | // Need to end in 0x304 offset from start of file | ||
216 | 93 | buf = avpkt->data + 0x304; | |
217 | 93 | w = read32(&buf, endian); | |
218 | 93 | h = read32(&buf, endian); | |
219 | |||
220 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 93 times.
|
93 | if ((ret = ff_set_dimensions(avctx, w, h)) < 0) |
221 | ✗ | return ret; | |
222 | |||
223 | // Need to end in 0x320 to read the descriptor | ||
224 | 93 | buf += 20; | |
225 | 93 | descriptor = buf[0]; | |
226 | 93 | color_trc = buf[1]; | |
227 | 93 | color_spec = buf[2]; | |
228 | |||
229 | // Need to end in 0x323 to read the bits per color | ||
230 | 93 | buf += 3; | |
231 | 93 | avctx->bits_per_raw_sample = | |
232 | 93 | bits_per_color = buf[0]; | |
233 | 93 | buf++; | |
234 | 93 | packing = read16(&buf, endian); | |
235 | 93 | encoding = read16(&buf, endian); | |
236 | |||
237 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 93 times.
|
93 | if (encoding) { |
238 | ✗ | avpriv_report_missing_feature(avctx, "Encoding %d", encoding); | |
239 | ✗ | return AVERROR_PATCHWELCOME; | |
240 | } | ||
241 | |||
242 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 93 times.
|
93 | if (bits_per_color > 31) |
243 | ✗ | return AVERROR_INVALIDDATA; | |
244 | |||
245 | 93 | buf += 820; | |
246 | 93 | avctx->sample_aspect_ratio.num = read32(&buf, endian); | |
247 | 93 | avctx->sample_aspect_ratio.den = read32(&buf, endian); | |
248 |
3/4✓ Branch 0 taken 2 times.
✓ Branch 1 taken 91 times.
✓ Branch 2 taken 2 times.
✗ Branch 3 not taken.
|
93 | if (avctx->sample_aspect_ratio.num > 0 && avctx->sample_aspect_ratio.den > 0) |
249 | 2 | av_reduce(&avctx->sample_aspect_ratio.num, &avctx->sample_aspect_ratio.den, | |
250 | 2 | avctx->sample_aspect_ratio.num, avctx->sample_aspect_ratio.den, | |
251 | 0x10000); | ||
252 | else | ||
253 | 91 | avctx->sample_aspect_ratio = (AVRational){ 0, 1 }; | |
254 | |||
255 | /* preferred frame rate from Motion-picture film header */ | ||
256 |
2/2✓ Branch 0 taken 4 times.
✓ Branch 1 taken 89 times.
|
93 | if (offset >= 1724 + 4) { |
257 | 4 | buf = avpkt->data + 1724; | |
258 | 4 | i = read32(&buf, endian); | |
259 |
3/4✓ Branch 0 taken 2 times.
✓ Branch 1 taken 2 times.
✓ Branch 2 taken 2 times.
✗ Branch 3 not taken.
|
4 | if(i && i != 0xFFFFFFFF) { |
260 | 2 | AVRational q = av_d2q(av_int2float(i), 4096); | |
261 |
2/4✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
✗ Branch 3 not taken.
|
2 | if (q.num > 0 && q.den > 0) |
262 | 2 | avctx->framerate = q; | |
263 | } | ||
264 | } | ||
265 | |||
266 | /* alternative frame rate from television header */ | ||
267 |
2/2✓ Branch 0 taken 4 times.
✓ Branch 1 taken 89 times.
|
93 | if (offset >= 1940 + 4 && |
268 |
3/4✓ Branch 0 taken 2 times.
✓ Branch 1 taken 2 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 2 times.
|
4 | !(avctx->framerate.num && avctx->framerate.den)) { |
269 | 2 | buf = avpkt->data + 1940; | |
270 | 2 | i = read32(&buf, endian); | |
271 |
1/4✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
|
2 | if(i && i != 0xFFFFFFFF) { |
272 | ✗ | AVRational q = av_d2q(av_int2float(i), 4096); | |
273 | ✗ | if (q.num > 0 && q.den > 0) | |
274 | ✗ | avctx->framerate = q; | |
275 | } | ||
276 | } | ||
277 | |||
278 | /* SMPTE TC from television header */ | ||
279 |
2/2✓ Branch 0 taken 4 times.
✓ Branch 1 taken 89 times.
|
93 | if (offset >= 1920 + 4) { |
280 | uint32_t tc; | ||
281 | uint32_t *tc_sd; | ||
282 | char tcbuf[AV_TIMECODE_STR_SIZE]; | ||
283 | |||
284 | 4 | buf = avpkt->data + 1920; | |
285 | // read32 to native endian, av_bswap32 to opposite of native for | ||
286 | // compatibility with av_timecode_make_smpte_tc_string2 etc | ||
287 | 4 | tc = av_bswap32(read32(&buf, endian)); | |
288 | |||
289 |
1/2✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
|
4 | if (i != 0xFFFFFFFF) { |
290 | AVFrameSideData *tcside; | ||
291 | 4 | ret = ff_frame_new_side_data(avctx, p, AV_FRAME_DATA_S12M_TIMECODE, | |
292 | sizeof(uint32_t) * 4, &tcside); | ||
293 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 4 times.
|
4 | if (ret < 0) |
294 | ✗ | return ret; | |
295 | |||
296 |
1/2✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
|
4 | if (tcside) { |
297 | 4 | tc_sd = (uint32_t*)tcside->data; | |
298 | 4 | tc_sd[0] = 1; | |
299 | 4 | tc_sd[1] = tc; | |
300 | |||
301 | 4 | av_timecode_make_smpte_tc_string2(tcbuf, avctx->framerate, | |
302 | 4 | tc_sd[1], 0, 0); | |
303 | 4 | av_dict_set(&p->metadata, "timecode", tcbuf, 0); | |
304 | } | ||
305 | } | ||
306 | } | ||
307 | |||
308 | /* color range from television header */ | ||
309 |
2/2✓ Branch 0 taken 4 times.
✓ Branch 1 taken 89 times.
|
93 | if (offset >= 1964 + 4) { |
310 | 4 | buf = avpkt->data + 1952; | |
311 | 4 | i = read32(&buf, endian); | |
312 | |||
313 | 4 | buf = avpkt->data + 1964; | |
314 | 4 | j = read32(&buf, endian); | |
315 | |||
316 |
2/4✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 4 times.
✗ Branch 3 not taken.
|
4 | if (i != 0xFFFFFFFF && j != 0xFFFFFFFF) { |
317 | float minCV, maxCV; | ||
318 | 4 | minCV = av_int2float(i); | |
319 | 4 | maxCV = av_int2float(j); | |
320 |
2/4✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 4 times.
✗ Branch 3 not taken.
|
4 | if (bits_per_color >= 1 && |
321 |
2/2✓ Branch 0 taken 2 times.
✓ Branch 1 taken 2 times.
|
4 | minCV == 0.0f && maxCV == ((1U<<bits_per_color) - 1)) { |
322 | 2 | avctx->color_range = AVCOL_RANGE_JPEG; | |
323 |
1/2✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
|
2 | } else if (bits_per_color >= 8 && |
324 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
|
2 | minCV == (1 <<(bits_per_color - 4)) && |
325 | ✗ | maxCV == (235<<(bits_per_color - 8))) { | |
326 | ✗ | avctx->color_range = AVCOL_RANGE_MPEG; | |
327 | } | ||
328 | } | ||
329 | } | ||
330 | |||
331 |
2/7✗ Branch 0 not taken.
✓ Branch 1 taken 79 times.
✓ Branch 2 taken 14 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
|
93 | switch (descriptor) { |
332 | ✗ | case 1: // R | |
333 | case 2: // G | ||
334 | case 3: // B | ||
335 | case 4: // A | ||
336 | case 6: // Y | ||
337 | ✗ | elements = 1; | |
338 | ✗ | yuv = 1; | |
339 | ✗ | break; | |
340 | 79 | case 50: // RGB | |
341 | 79 | elements = 3; | |
342 | 79 | yuv = 0; | |
343 | 79 | break; | |
344 | 14 | case 52: // ABGR | |
345 | case 51: // RGBA | ||
346 | 14 | elements = 4; | |
347 | 14 | yuv = 0; | |
348 | 14 | break; | |
349 | ✗ | case 100: // UYVY422 | |
350 | ✗ | elements = 2; | |
351 | ✗ | yuv = 1; | |
352 | ✗ | break; | |
353 | ✗ | case 102: // UYV444 | |
354 | ✗ | elements = 3; | |
355 | ✗ | yuv = 1; | |
356 | ✗ | break; | |
357 | ✗ | case 103: // UYVA4444 | |
358 | ✗ | elements = 4; | |
359 | ✗ | yuv = 1; | |
360 | ✗ | break; | |
361 | ✗ | default: | |
362 | ✗ | avpriv_report_missing_feature(avctx, "Descriptor %d", descriptor); | |
363 | ✗ | return AVERROR_PATCHWELCOME; | |
364 | } | ||
365 | |||
366 |
4/7✓ Branch 0 taken 19 times.
✓ Branch 1 taken 30 times.
✓ Branch 2 taken 14 times.
✓ Branch 3 taken 30 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
|
93 | switch (bits_per_color) { |
367 | 19 | case 8: | |
368 | 19 | stride = avctx->width * elements; | |
369 | 19 | break; | |
370 | 30 | case 10: | |
371 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 30 times.
|
30 | if (!packing) { |
372 | ✗ | av_log(avctx, AV_LOG_ERROR, "Packing to 32bit required\n"); | |
373 | ✗ | return -1; | |
374 | } | ||
375 | 30 | stride = (avctx->width * elements + 2) / 3 * 4; | |
376 | 30 | break; | |
377 | 14 | case 12: | |
378 | 14 | stride = avctx->width * elements; | |
379 |
1/2✓ Branch 0 taken 14 times.
✗ Branch 1 not taken.
|
14 | if (packing) { |
380 | 14 | stride *= 2; | |
381 | } else { | ||
382 | ✗ | stride *= 3; | |
383 | ✗ | if (stride % 8) { | |
384 | ✗ | stride /= 8; | |
385 | ✗ | stride++; | |
386 | ✗ | stride *= 8; | |
387 | } | ||
388 | ✗ | stride /= 2; | |
389 | } | ||
390 | 14 | break; | |
391 | 30 | case 16: | |
392 | 30 | stride = 2 * avctx->width * elements; | |
393 | 30 | break; | |
394 | ✗ | case 32: | |
395 | ✗ | stride = 4 * avctx->width * elements; | |
396 | ✗ | break; | |
397 | ✗ | case 1: | |
398 | case 64: | ||
399 | ✗ | avpriv_report_missing_feature(avctx, "Depth %d", bits_per_color); | |
400 | ✗ | return AVERROR_PATCHWELCOME; | |
401 | ✗ | default: | |
402 | ✗ | return AVERROR_INVALIDDATA; | |
403 | } | ||
404 | |||
405 |
3/6✓ Branch 0 taken 89 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✓ Branch 4 taken 2 times.
✓ Branch 5 taken 2 times.
|
93 | switch (color_trc) { |
406 | 89 | case DPX_TRC_LINEAR: | |
407 | 89 | avctx->color_trc = AVCOL_TRC_LINEAR; | |
408 | 89 | break; | |
409 | ✗ | case DPX_TRC_SMPTE_274: | |
410 | case DPX_TRC_ITU_R_709_4: | ||
411 | ✗ | avctx->color_trc = AVCOL_TRC_BT709; | |
412 | ✗ | break; | |
413 | ✗ | case DPX_TRC_ITU_R_601_625: | |
414 | case DPX_TRC_ITU_R_601_525: | ||
415 | case DPX_TRC_SMPTE_170: | ||
416 | ✗ | avctx->color_trc = AVCOL_TRC_SMPTE170M; | |
417 | ✗ | break; | |
418 | ✗ | case DPX_TRC_ITU_R_624_4_PAL: | |
419 | ✗ | avctx->color_trc = AVCOL_TRC_GAMMA28; | |
420 | ✗ | break; | |
421 | 2 | case DPX_TRC_USER_DEFINED: | |
422 | case DPX_TRC_UNSPECIFIED_VIDEO: | ||
423 | /* Nothing to do */ | ||
424 | 2 | break; | |
425 | 2 | default: | |
426 | 2 | av_log(avctx, AV_LOG_VERBOSE, "Cannot map DPX transfer characteristic " | |
427 | "%d to color_trc.\n", color_trc); | ||
428 | 2 | break; | |
429 | } | ||
430 | |||
431 |
3/5✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 2 times.
✓ Branch 4 taken 89 times.
|
93 | switch (color_spec) { |
432 | 2 | case DPX_COL_SPEC_SMPTE_274: | |
433 | case DPX_COL_SPEC_ITU_R_709_4: | ||
434 | 2 | avctx->color_primaries = AVCOL_PRI_BT709; | |
435 | 2 | break; | |
436 | ✗ | case DPX_COL_SPEC_ITU_R_601_625: | |
437 | case DPX_COL_SPEC_ITU_R_624_4_PAL: | ||
438 | ✗ | avctx->color_primaries = AVCOL_PRI_BT470BG; | |
439 | ✗ | break; | |
440 | ✗ | case DPX_COL_SPEC_ITU_R_601_525: | |
441 | case DPX_COL_SPEC_SMPTE_170: | ||
442 | ✗ | avctx->color_primaries = AVCOL_PRI_SMPTE170M; | |
443 | ✗ | break; | |
444 | 2 | case DPX_COL_SPEC_USER_DEFINED: | |
445 | case DPX_COL_SPEC_UNSPECIFIED_VIDEO: | ||
446 | /* Nothing to do */ | ||
447 | 2 | break; | |
448 | 89 | default: | |
449 | 89 | av_log(avctx, AV_LOG_VERBOSE, "Cannot map DPX color specification " | |
450 | "%d to color_primaries.\n", color_spec); | ||
451 | 89 | break; | |
452 | } | ||
453 | |||
454 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 93 times.
|
93 | if (yuv) { |
455 | ✗ | switch (color_spec) { | |
456 | ✗ | case DPX_COL_SPEC_SMPTE_274: | |
457 | case DPX_COL_SPEC_ITU_R_709_4: | ||
458 | ✗ | avctx->colorspace = AVCOL_SPC_BT709; | |
459 | ✗ | break; | |
460 | ✗ | case DPX_COL_SPEC_ITU_R_601_625: | |
461 | case DPX_COL_SPEC_ITU_R_624_4_PAL: | ||
462 | ✗ | avctx->colorspace = AVCOL_SPC_BT470BG; | |
463 | ✗ | break; | |
464 | ✗ | case DPX_COL_SPEC_ITU_R_601_525: | |
465 | case DPX_COL_SPEC_SMPTE_170: | ||
466 | ✗ | avctx->colorspace = AVCOL_SPC_SMPTE170M; | |
467 | ✗ | break; | |
468 | ✗ | case DPX_COL_SPEC_USER_DEFINED: | |
469 | case DPX_COL_SPEC_UNSPECIFIED_VIDEO: | ||
470 | /* Nothing to do */ | ||
471 | ✗ | break; | |
472 | ✗ | default: | |
473 | ✗ | av_log(avctx, AV_LOG_INFO, "Cannot map DPX color specification " | |
474 | "%d to colorspace.\n", color_spec); | ||
475 | ✗ | break; | |
476 | } | ||
477 | } else { | ||
478 | 93 | avctx->colorspace = AVCOL_SPC_RGB; | |
479 | } | ||
480 | |||
481 | 93 | av_strlcpy(creator, avpkt->data + 160, 100); | |
482 | 93 | creator[100] = '\0'; | |
483 | 93 | av_dict_set(&p->metadata, "Creator", creator, 0); | |
484 | |||
485 | 93 | av_strlcpy(input_device, avpkt->data + 1556, 32); | |
486 | 93 | input_device[32] = '\0'; | |
487 | 93 | av_dict_set(&p->metadata, "Input Device", input_device, 0); | |
488 | |||
489 | // Some devices do not pad 10bit samples to whole 32bit words per row | ||
490 |
1/2✓ Branch 0 taken 93 times.
✗ Branch 1 not taken.
|
93 | if (!memcmp(input_device, "Scanity", 7) || |
491 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 93 times.
|
93 | !memcmp(creator, "Lasergraphics Inc.", 18)) { |
492 | ✗ | if (bits_per_color == 10) | |
493 | ✗ | unpadded_10bit = 1; | |
494 | } | ||
495 | |||
496 | // Table 3c: Runs will always break at scan line boundaries. Packing | ||
497 | // will always break to the next 32-bit word at scan-line boundaries. | ||
498 | // Unfortunately, the encoder produced invalid files, so attempt | ||
499 | // to detect it | ||
500 | // Also handle special case with unpadded content | ||
501 | 93 | need_align = FFALIGN(stride, 4); | |
502 |
1/4✗ Branch 0 not taken.
✓ Branch 1 taken 93 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
|
93 | if (need_align*avctx->height + (int64_t)offset > avpkt->size && |
503 | ✗ | (!unpadded_10bit || (avctx->width * avctx->height * elements + 2) / 3 * 4 + (int64_t)offset > avpkt->size)) { | |
504 | // Alignment seems unappliable, try without | ||
505 | ✗ | if (stride*avctx->height + (int64_t)offset > avpkt->size || unpadded_10bit) { | |
506 | ✗ | av_log(avctx, AV_LOG_ERROR, "Overread buffer. Invalid header?\n"); | |
507 | ✗ | return AVERROR_INVALIDDATA; | |
508 | } else { | ||
509 | ✗ | av_log(avctx, AV_LOG_INFO, "Decoding DPX without scanline " | |
510 | "alignment.\n"); | ||
511 | ✗ | need_align = 0; | |
512 | } | ||
513 | } else { | ||
514 | 93 | need_align -= stride; | |
515 | 93 | stride = FFALIGN(stride, 4); | |
516 | } | ||
517 | |||
518 |
6/26✗ Branch 0 not taken.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✓ Branch 4 taken 19 times.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✓ Branch 7 taken 30 times.
✗ Branch 8 not taken.
✓ Branch 9 taken 14 times.
✗ Branch 10 not taken.
✗ Branch 11 not taken.
✗ Branch 12 not taken.
✗ Branch 13 not taken.
✓ Branch 14 taken 2 times.
✓ Branch 15 taken 14 times.
✗ Branch 16 not taken.
✓ Branch 17 taken 14 times.
✗ Branch 18 not taken.
✗ Branch 19 not taken.
✗ Branch 20 not taken.
✗ Branch 21 not taken.
✗ Branch 22 not taken.
✗ Branch 23 not taken.
✗ Branch 24 not taken.
✗ Branch 25 not taken.
|
93 | switch (1000 * descriptor + 10 * bits_per_color + endian) { |
519 | ✗ | case 1081: | |
520 | case 1080: | ||
521 | case 2081: | ||
522 | case 2080: | ||
523 | case 3081: | ||
524 | case 3080: | ||
525 | case 4081: | ||
526 | case 4080: | ||
527 | case 6081: | ||
528 | case 6080: | ||
529 | ✗ | avctx->pix_fmt = AV_PIX_FMT_GRAY8; | |
530 | ✗ | break; | |
531 | ✗ | case 6121: | |
532 | case 6120: | ||
533 | ✗ | avctx->pix_fmt = AV_PIX_FMT_GRAY12; | |
534 | ✗ | break; | |
535 | ✗ | case 1320: | |
536 | case 2320: | ||
537 | case 3320: | ||
538 | case 4320: | ||
539 | case 6320: | ||
540 | ✗ | avctx->pix_fmt = AV_PIX_FMT_GRAYF32LE; | |
541 | ✗ | break; | |
542 | ✗ | case 1321: | |
543 | case 2321: | ||
544 | case 3321: | ||
545 | case 4321: | ||
546 | case 6321: | ||
547 | ✗ | avctx->pix_fmt = AV_PIX_FMT_GRAYF32BE; | |
548 | ✗ | break; | |
549 | 19 | case 50081: | |
550 | case 50080: | ||
551 | 19 | avctx->pix_fmt = AV_PIX_FMT_RGB24; | |
552 | 19 | break; | |
553 | ✗ | case 52081: | |
554 | case 52080: | ||
555 | ✗ | avctx->pix_fmt = AV_PIX_FMT_ABGR; | |
556 | ✗ | break; | |
557 | ✗ | case 51081: | |
558 | case 51080: | ||
559 | ✗ | avctx->pix_fmt = AV_PIX_FMT_RGBA; | |
560 | ✗ | break; | |
561 | 30 | case 50100: | |
562 | case 50101: | ||
563 | 30 | avctx->pix_fmt = AV_PIX_FMT_GBRP10; | |
564 | 30 | break; | |
565 | ✗ | case 51100: | |
566 | case 51101: | ||
567 | ✗ | avctx->pix_fmt = AV_PIX_FMT_GBRAP10; | |
568 | ✗ | break; | |
569 | 14 | case 50120: | |
570 | case 50121: | ||
571 | 14 | avctx->pix_fmt = AV_PIX_FMT_GBRP12; | |
572 | 14 | break; | |
573 | ✗ | case 51120: | |
574 | case 51121: | ||
575 | ✗ | avctx->pix_fmt = AV_PIX_FMT_GBRAP12; | |
576 | ✗ | break; | |
577 | ✗ | case 6100: | |
578 | case 6101: | ||
579 | ✗ | avctx->pix_fmt = AV_PIX_FMT_GRAY10; | |
580 | ✗ | break; | |
581 | ✗ | case 6161: | |
582 | ✗ | avctx->pix_fmt = AV_PIX_FMT_GRAY16BE; | |
583 | ✗ | break; | |
584 | ✗ | case 6160: | |
585 | ✗ | avctx->pix_fmt = AV_PIX_FMT_GRAY16LE; | |
586 | ✗ | break; | |
587 | 2 | case 50161: | |
588 | 2 | avctx->pix_fmt = AV_PIX_FMT_RGB48BE; | |
589 | 2 | break; | |
590 | 14 | case 50160: | |
591 | 14 | avctx->pix_fmt = AV_PIX_FMT_RGB48LE; | |
592 | 14 | break; | |
593 | ✗ | case 51161: | |
594 | ✗ | avctx->pix_fmt = AV_PIX_FMT_RGBA64BE; | |
595 | ✗ | break; | |
596 | 14 | case 51160: | |
597 | 14 | avctx->pix_fmt = AV_PIX_FMT_RGBA64LE; | |
598 | 14 | break; | |
599 | ✗ | case 50320: | |
600 | ✗ | avctx->pix_fmt = AV_PIX_FMT_GBRPF32LE; | |
601 | ✗ | break; | |
602 | ✗ | case 50321: | |
603 | ✗ | avctx->pix_fmt = AV_PIX_FMT_GBRPF32BE; | |
604 | ✗ | break; | |
605 | ✗ | case 51320: | |
606 | ✗ | avctx->pix_fmt = AV_PIX_FMT_GBRAPF32LE; | |
607 | ✗ | break; | |
608 | ✗ | case 51321: | |
609 | ✗ | avctx->pix_fmt = AV_PIX_FMT_GBRAPF32BE; | |
610 | ✗ | break; | |
611 | ✗ | case 100081: | |
612 | ✗ | avctx->pix_fmt = AV_PIX_FMT_UYVY422; | |
613 | ✗ | break; | |
614 | ✗ | case 102081: | |
615 | ✗ | avctx->pix_fmt = AV_PIX_FMT_YUV444P; | |
616 | ✗ | break; | |
617 | ✗ | case 103081: | |
618 | ✗ | avctx->pix_fmt = AV_PIX_FMT_YUVA444P; | |
619 | ✗ | break; | |
620 | ✗ | default: | |
621 | ✗ | av_log(avctx, AV_LOG_ERROR, "Unsupported format %d\n", | |
622 | ✗ | 1000 * descriptor + 10 * bits_per_color + endian); | |
623 | ✗ | return AVERROR_PATCHWELCOME; | |
624 | } | ||
625 | |||
626 | 93 | ff_set_sar(avctx, avctx->sample_aspect_ratio); | |
627 | |||
628 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 93 times.
|
93 | if ((ret = ff_get_buffer(avctx, p, 0)) < 0) |
629 | ✗ | return ret; | |
630 | |||
631 | // Move pointer to offset from start of file | ||
632 | 93 | buf = avpkt->data + offset; | |
633 | |||
634 |
2/2✓ Branch 0 taken 744 times.
✓ Branch 1 taken 93 times.
|
837 | for (i=0; i<AV_NUM_DATA_POINTERS; i++) |
635 | 744 | ptr[i] = p->data[i]; | |
636 | |||
637 |
4/6✓ Branch 0 taken 30 times.
✓ Branch 1 taken 14 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 30 times.
✓ Branch 4 taken 19 times.
✗ Branch 5 not taken.
|
93 | switch (bits_per_color) { |
638 | 30 | case 10: | |
639 |
2/2✓ Branch 0 taken 8544 times.
✓ Branch 1 taken 30 times.
|
8574 | for (x = 0; x < avctx->height; x++) { |
640 | 8544 | uint16_t *dst[4] = {(uint16_t*)ptr[0], | |
641 | 8544 | (uint16_t*)ptr[1], | |
642 | 8544 | (uint16_t*)ptr[2], | |
643 | 8544 | (uint16_t*)ptr[3]}; | |
644 |
2/6✓ Branch 0 taken 8544 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 8544 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
|
8544 | int shift = elements > 1 ? packing == 1 ? 22 : 20 : packing == 1 ? 2 : 0; |
645 |
2/2✓ Branch 0 taken 3043968 times.
✓ Branch 1 taken 8544 times.
|
3052512 | for (y = 0; y < avctx->width; y++) { |
646 |
1/2✓ Branch 0 taken 3043968 times.
✗ Branch 1 not taken.
|
3043968 | if (elements >= 3) |
647 | 3043968 | *dst[2]++ = read10in32(&buf, &rgbBuffer, | |
648 | &n_datum, endian, shift); | ||
649 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 3043968 times.
|
3043968 | if (elements == 1) |
650 | ✗ | *dst[0]++ = read10in32_gray(&buf, &rgbBuffer, | |
651 | &n_datum, endian, shift); | ||
652 | else | ||
653 | 3043968 | *dst[0]++ = read10in32(&buf, &rgbBuffer, | |
654 | &n_datum, endian, shift); | ||
655 |
1/2✓ Branch 0 taken 3043968 times.
✗ Branch 1 not taken.
|
3043968 | if (elements >= 2) |
656 | 3043968 | *dst[1]++ = read10in32(&buf, &rgbBuffer, | |
657 | &n_datum, endian, shift); | ||
658 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 3043968 times.
|
3043968 | if (elements == 4) |
659 | ✗ | *dst[3]++ = | |
660 | ✗ | read10in32(&buf, &rgbBuffer, | |
661 | &n_datum, endian, shift); | ||
662 | } | ||
663 |
1/2✓ Branch 0 taken 8544 times.
✗ Branch 1 not taken.
|
8544 | if (!unpadded_10bit) |
664 | 8544 | n_datum = 0; | |
665 |
2/2✓ Branch 0 taken 25632 times.
✓ Branch 1 taken 8544 times.
|
34176 | for (i = 0; i < elements; i++) |
666 | 25632 | ptr[i] += p->linesize[i]; | |
667 | } | ||
668 | 30 | break; | |
669 | 14 | case 12: | |
670 |
2/2✓ Branch 0 taken 4032 times.
✓ Branch 1 taken 14 times.
|
4046 | for (x = 0; x < avctx->height; x++) { |
671 | 4032 | uint16_t *dst[4] = {(uint16_t*)ptr[0], | |
672 | 4032 | (uint16_t*)ptr[1], | |
673 | 4032 | (uint16_t*)ptr[2], | |
674 | 4032 | (uint16_t*)ptr[3]}; | |
675 |
1/2✓ Branch 0 taken 4032 times.
✗ Branch 1 not taken.
|
4032 | int shift = packing == 1 ? 4 : 0; |
676 |
2/2✓ Branch 0 taken 1419264 times.
✓ Branch 1 taken 4032 times.
|
1423296 | for (y = 0; y < avctx->width; y++) { |
677 |
1/2✓ Branch 0 taken 1419264 times.
✗ Branch 1 not taken.
|
1419264 | if (packing) { |
678 |
1/2✓ Branch 0 taken 1419264 times.
✗ Branch 1 not taken.
|
1419264 | if (elements >= 3) |
679 | 1419264 | *dst[2]++ = read16(&buf, endian) >> shift & 0xFFF; | |
680 | 1419264 | *dst[0]++ = read16(&buf, endian) >> shift & 0xFFF; | |
681 |
1/2✓ Branch 0 taken 1419264 times.
✗ Branch 1 not taken.
|
1419264 | if (elements >= 2) |
682 | 1419264 | *dst[1]++ = read16(&buf, endian) >> shift & 0xFFF; | |
683 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1419264 times.
|
1419264 | if (elements == 4) |
684 | ✗ | *dst[3]++ = read16(&buf, endian) >> shift & 0xFFF; | |
685 | } else { | ||
686 | ✗ | if (elements >= 3) | |
687 | ✗ | *dst[2]++ = read12in32(&buf, &rgbBuffer, | |
688 | &n_datum, endian); | ||
689 | ✗ | *dst[0]++ = read12in32(&buf, &rgbBuffer, | |
690 | &n_datum, endian); | ||
691 | ✗ | if (elements >= 2) | |
692 | ✗ | *dst[1]++ = read12in32(&buf, &rgbBuffer, | |
693 | &n_datum, endian); | ||
694 | ✗ | if (elements == 4) | |
695 | ✗ | *dst[3]++ = read12in32(&buf, &rgbBuffer, | |
696 | &n_datum, endian); | ||
697 | } | ||
698 | } | ||
699 | 4032 | n_datum = 0; | |
700 |
2/2✓ Branch 0 taken 12096 times.
✓ Branch 1 taken 4032 times.
|
16128 | for (i = 0; i < elements; i++) |
701 | 12096 | ptr[i] += p->linesize[i]; | |
702 | // Jump to next aligned position | ||
703 | 4032 | buf += need_align; | |
704 | } | ||
705 | 14 | break; | |
706 | ✗ | case 32: | |
707 | ✗ | if (elements == 1) { | |
708 | ✗ | av_image_copy_plane(ptr[0], p->linesize[0], | |
709 | buf, stride, | ||
710 | ✗ | elements * avctx->width * 4, avctx->height); | |
711 | } else { | ||
712 | ✗ | for (y = 0; y < avctx->height; y++) { | |
713 | ✗ | ptr[0] = p->data[0] + y * p->linesize[0]; | |
714 | ✗ | ptr[1] = p->data[1] + y * p->linesize[1]; | |
715 | ✗ | ptr[2] = p->data[2] + y * p->linesize[2]; | |
716 | ✗ | ptr[3] = p->data[3] + y * p->linesize[3]; | |
717 | ✗ | for (x = 0; x < avctx->width; x++) { | |
718 | ✗ | AV_WN32(ptr[2], AV_RN32(buf)); | |
719 | ✗ | AV_WN32(ptr[0], AV_RN32(buf + 4)); | |
720 | ✗ | AV_WN32(ptr[1], AV_RN32(buf + 8)); | |
721 | ✗ | if (avctx->pix_fmt == AV_PIX_FMT_GBRAPF32BE || | |
722 | ✗ | avctx->pix_fmt == AV_PIX_FMT_GBRAPF32LE) { | |
723 | ✗ | AV_WN32(ptr[3], AV_RN32(buf + 12)); | |
724 | ✗ | buf += 4; | |
725 | ✗ | ptr[3] += 4; | |
726 | } | ||
727 | |||
728 | ✗ | buf += 12; | |
729 | ✗ | ptr[2] += 4; | |
730 | ✗ | ptr[0] += 4; | |
731 | ✗ | ptr[1] += 4; | |
732 | } | ||
733 | } | ||
734 | } | ||
735 | ✗ | break; | |
736 | 30 | case 16: | |
737 | 30 | elements *= 2; | |
738 | 49 | case 8: | |
739 |
1/2✓ Branch 0 taken 49 times.
✗ Branch 1 not taken.
|
49 | if ( avctx->pix_fmt == AV_PIX_FMT_YUVA444P |
740 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 49 times.
|
49 | || avctx->pix_fmt == AV_PIX_FMT_YUV444P) { |
741 | ✗ | for (x = 0; x < avctx->height; x++) { | |
742 | ✗ | ptr[0] = p->data[0] + x * p->linesize[0]; | |
743 | ✗ | ptr[1] = p->data[1] + x * p->linesize[1]; | |
744 | ✗ | ptr[2] = p->data[2] + x * p->linesize[2]; | |
745 | ✗ | ptr[3] = p->data[3] + x * p->linesize[3]; | |
746 | ✗ | for (y = 0; y < avctx->width; y++) { | |
747 | ✗ | *ptr[1]++ = *buf++; | |
748 | ✗ | *ptr[0]++ = *buf++; | |
749 | ✗ | *ptr[2]++ = *buf++; | |
750 | ✗ | if (avctx->pix_fmt == AV_PIX_FMT_YUVA444P) | |
751 | ✗ | *ptr[3]++ = *buf++; | |
752 | } | ||
753 | } | ||
754 | } else { | ||
755 | 49 | av_image_copy_plane(ptr[0], p->linesize[0], | |
756 | buf, stride, | ||
757 | 49 | elements * avctx->width, avctx->height); | |
758 | } | ||
759 | 49 | break; | |
760 | } | ||
761 | |||
762 | 93 | *got_frame = 1; | |
763 | |||
764 | 93 | return buf_size; | |
765 | } | ||
766 | |||
767 | const FFCodec ff_dpx_decoder = { | ||
768 | .p.name = "dpx", | ||
769 | CODEC_LONG_NAME("DPX (Digital Picture Exchange) image"), | ||
770 | .p.type = AVMEDIA_TYPE_VIDEO, | ||
771 | .p.id = AV_CODEC_ID_DPX, | ||
772 | FF_CODEC_DECODE_CB(decode_frame), | ||
773 | .p.capabilities = AV_CODEC_CAP_DR1, | ||
774 | }; | ||
775 |