GCC Code Coverage Report | |||||||||||||||||||||
|
|||||||||||||||||||||
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 "bytestream.h" |
||
28 |
#include "avcodec.h" |
||
29 |
#include "internal.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 |
✓✓ | 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 |
3044636 |
static unsigned int read32(const uint8_t **ptr, int is_big) |
|
76 |
{ |
||
77 |
unsigned int temp; |
||
78 |
✓✓ | 3044636 |
if (is_big) { |
79 |
21 |
temp = AV_RB32(*ptr); |
|
80 |
} else { |
||
81 |
3044615 |
temp = AV_RL32(*ptr); |
|
82 |
} |
||
83 |
3044636 |
*ptr += 4; |
|
84 |
3044636 |
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 |
✓✓ | 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, |
|
153 |
void *data, |
||
154 |
int *got_frame, |
||
155 |
AVPacket *avpkt) |
||
156 |
{ |
||
157 |
93 |
const uint8_t *buf = avpkt->data; |
|
158 |
93 |
int buf_size = avpkt->size; |
|
159 |
93 |
AVFrame *const p = data; |
|
160 |
uint8_t *ptr[AV_NUM_DATA_POINTERS]; |
||
161 |
93 |
uint32_t header_version, version = 0; |
|
162 |
char creator[101]; |
||
163 |
char input_device[33]; |
||
164 |
|||
165 |
unsigned int offset; |
||
166 |
int magic_num, endian; |
||
167 |
int x, y, stride, i, j, ret; |
||
168 |
int w, h, bits_per_color, descriptor, elements, packing; |
||
169 |
int yuv, color_trc, color_spec; |
||
170 |
93 |
int encoding, need_align = 0, unpadded_10bit = 0; |
|
171 |
|||
172 |
93 |
unsigned int rgbBuffer = 0; |
|
173 |
93 |
int n_datum = 0; |
|
174 |
|||
175 |
✗✓ | 93 |
if (avpkt->size <= 1634) { |
176 |
av_log(avctx, AV_LOG_ERROR, "Packet too small for DPX header\n"); |
||
177 |
return AVERROR_INVALIDDATA; |
||
178 |
} |
||
179 |
|||
180 |
93 |
magic_num = AV_RB32(buf); |
|
181 |
93 |
buf += 4; |
|
182 |
|||
183 |
/* Check if the files "magic number" is "SDPX" which means it uses |
||
184 |
* big-endian or XPDS which is for little-endian files */ |
||
185 |
✓✓ | 93 |
if (magic_num == AV_RL32("SDPX")) { |
186 |
91 |
endian = 0; |
|
187 |
✓✗ | 2 |
} else if (magic_num == AV_RB32("SDPX")) { |
188 |
2 |
endian = 1; |
|
189 |
} else { |
||
190 |
av_log(avctx, AV_LOG_ERROR, "DPX marker not found\n"); |
||
191 |
return AVERROR_INVALIDDATA; |
||
192 |
} |
||
193 |
|||
194 |
93 |
offset = read32(&buf, endian); |
|
195 |
✗✓ | 93 |
if (avpkt->size <= offset) { |
196 |
av_log(avctx, AV_LOG_ERROR, "Invalid data start offset\n"); |
||
197 |
return AVERROR_INVALIDDATA; |
||
198 |
} |
||
199 |
|||
200 |
93 |
header_version = read32(&buf, 0); |
|
201 |
✓✓ | 93 |
if (header_version == MKTAG('V','1','.','0')) |
202 |
89 |
version = 1; |
|
203 |
✓✓ | 93 |
if (header_version == MKTAG('V','2','.','0')) |
204 |
4 |
version = 2; |
|
205 |
✗✓ | 93 |
if (!version) |
206 |
av_log(avctx, AV_LOG_WARNING, "Unknown header format version %s.\n", |
||
207 |
av_fourcc2str(header_version)); |
||
208 |
|||
209 |
// Check encryption |
||
210 |
93 |
buf = avpkt->data + 660; |
|
211 |
93 |
ret = read32(&buf, endian); |
|
212 |
✗✓ | 93 |
if (ret != 0xFFFFFFFF) { |
213 |
avpriv_report_missing_feature(avctx, "Encryption"); |
||
214 |
av_log(avctx, AV_LOG_WARNING, "The image is encrypted and may " |
||
215 |
"not properly decode.\n"); |
||
216 |
} |
||
217 |
|||
218 |
// Need to end in 0x304 offset from start of file |
||
219 |
93 |
buf = avpkt->data + 0x304; |
|
220 |
93 |
w = read32(&buf, endian); |
|
221 |
93 |
h = read32(&buf, endian); |
|
222 |
|||
223 |
✗✓ | 93 |
if ((ret = ff_set_dimensions(avctx, w, h)) < 0) |
224 |
return ret; |
||
225 |
|||
226 |
// Need to end in 0x320 to read the descriptor |
||
227 |
93 |
buf += 20; |
|
228 |
93 |
descriptor = buf[0]; |
|
229 |
93 |
color_trc = buf[1]; |
|
230 |
93 |
color_spec = buf[2]; |
|
231 |
|||
232 |
// Need to end in 0x323 to read the bits per color |
||
233 |
93 |
buf += 3; |
|
234 |
93 |
avctx->bits_per_raw_sample = |
|
235 |
93 |
bits_per_color = buf[0]; |
|
236 |
93 |
buf++; |
|
237 |
93 |
packing = read16(&buf, endian); |
|
238 |
93 |
encoding = read16(&buf, endian); |
|
239 |
|||
240 |
✗✓ | 93 |
if (encoding) { |
241 |
avpriv_report_missing_feature(avctx, "Encoding %d", encoding); |
||
242 |
return AVERROR_PATCHWELCOME; |
||
243 |
} |
||
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 |
✓✓✓✗ |
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 |
✓✓ | 93 |
if (offset >= 1724 + 4) { |
257 |
4 |
buf = avpkt->data + 1724; |
|
258 |
4 |
i = read32(&buf, endian); |
|
259 |
✓✓✓✗ |
4 |
if(i && i != 0xFFFFFFFF) { |
260 |
2 |
AVRational q = av_d2q(av_int2float(i), 4096); |
|
261 |
✓✗✓✗ |
2 |
if (q.num > 0 && q.den > 0) |
262 |
2 |
avctx->framerate = q; |
|
263 |
} |
||
264 |
} |
||
265 |
|||
266 |
/* alternative frame rate from television header */ |
||
267 |
✓✓ | 93 |
if (offset >= 1940 + 4 && |
268 |
✓✓✗✓ |
4 |
!(avctx->framerate.num && avctx->framerate.den)) { |
269 |
1 |
buf = avpkt->data + 1940; |
|
270 |
1 |
i = read32(&buf, endian); |
|
271 |
✗✓✗✗ |
1 |
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 |
✓✓ | 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 |
✓✗ | 4 |
if (i != 0xFFFFFFFF) { |
290 |
AVFrameSideData *tcside = |
||
291 |
4 |
av_frame_new_side_data(p, AV_FRAME_DATA_S12M_TIMECODE, |
|
292 |
sizeof(uint32_t) * 4); |
||
293 |
✗✓ | 4 |
if (!tcside) |
294 |
return AVERROR(ENOMEM); |
||
295 |
|||
296 |
4 |
tc_sd = (uint32_t*)tcside->data; |
|
297 |
4 |
tc_sd[0] = 1; |
|
298 |
4 |
tc_sd[1] = tc; |
|
299 |
|||
300 |
4 |
av_timecode_make_smpte_tc_string2(tcbuf, avctx->framerate, |
|
301 |
4 |
tc_sd[1], 0, 0); |
|
302 |
4 |
av_dict_set(&p->metadata, "timecode", tcbuf, 0); |
|
303 |
} |
||
304 |
} |
||
305 |
|||
306 |
/* color range from television header */ |
||
307 |
✓✓ | 93 |
if (offset >= 1964 + 4) { |
308 |
4 |
buf = avpkt->data + 1952; |
|
309 |
4 |
i = read32(&buf, endian); |
|
310 |
|||
311 |
4 |
buf = avpkt->data + 1964; |
|
312 |
4 |
j = read32(&buf, endian); |
|
313 |
|||
314 |
✓✗✓✗ |
4 |
if (i != 0xFFFFFFFF && j != 0xFFFFFFFF) { |
315 |
float minCV, maxCV; |
||
316 |
4 |
minCV = av_int2float(i); |
|
317 |
4 |
maxCV = av_int2float(j); |
|
318 |
✓✗✓✗ |
4 |
if (bits_per_color >= 1 && |
319 |
✓✓ | 4 |
minCV == 0.0f && maxCV == ((1<<bits_per_color) - 1)) { |
320 |
2 |
avctx->color_range = AVCOL_RANGE_JPEG; |
|
321 |
✓✗ | 2 |
} else if (bits_per_color >= 8 && |
322 |
✗✓ | 2 |
minCV == (1 <<(bits_per_color - 4)) && |
323 |
maxCV == (235<<(bits_per_color - 8))) { |
||
324 |
avctx->color_range = AVCOL_RANGE_MPEG; |
||
325 |
} |
||
326 |
} |
||
327 |
} |
||
328 |
|||
329 |
✗✓✓✗ ✗✗✗ |
93 |
switch (descriptor) { |
330 |
case 6: // Y |
||
331 |
elements = 1; |
||
332 |
yuv = 1; |
||
333 |
break; |
||
334 |
79 |
case 50: // RGB |
|
335 |
79 |
elements = 3; |
|
336 |
79 |
yuv = 0; |
|
337 |
79 |
break; |
|
338 |
14 |
case 52: // ABGR |
|
339 |
case 51: // RGBA |
||
340 |
14 |
elements = 4; |
|
341 |
14 |
yuv = 0; |
|
342 |
14 |
break; |
|
343 |
case 100: // UYVY422 |
||
344 |
elements = 2; |
||
345 |
yuv = 1; |
||
346 |
break; |
||
347 |
case 102: // UYV444 |
||
348 |
elements = 3; |
||
349 |
yuv = 1; |
||
350 |
break; |
||
351 |
case 103: // UYVA4444 |
||
352 |
elements = 4; |
||
353 |
yuv = 1; |
||
354 |
break; |
||
355 |
default: |
||
356 |
avpriv_report_missing_feature(avctx, "Descriptor %d", descriptor); |
||
357 |
return AVERROR_PATCHWELCOME; |
||
358 |
} |
||
359 |
|||
360 |
✓✓✓✓ ✗✗ |
93 |
switch (bits_per_color) { |
361 |
19 |
case 8: |
|
362 |
19 |
stride = avctx->width * elements; |
|
363 |
19 |
break; |
|
364 |
30 |
case 10: |
|
365 |
✗✓ | 30 |
if (!packing) { |
366 |
av_log(avctx, AV_LOG_ERROR, "Packing to 32bit required\n"); |
||
367 |
return -1; |
||
368 |
} |
||
369 |
30 |
stride = (avctx->width * elements + 2) / 3 * 4; |
|
370 |
30 |
break; |
|
371 |
14 |
case 12: |
|
372 |
14 |
stride = avctx->width * elements; |
|
373 |
✓✗ | 14 |
if (packing) { |
374 |
14 |
stride *= 2; |
|
375 |
} else { |
||
376 |
stride *= 3; |
||
377 |
if (stride % 8) { |
||
378 |
stride /= 8; |
||
379 |
stride++; |
||
380 |
stride *= 8; |
||
381 |
} |
||
382 |
stride /= 2; |
||
383 |
} |
||
384 |
14 |
break; |
|
385 |
30 |
case 16: |
|
386 |
30 |
stride = 2 * avctx->width * elements; |
|
387 |
30 |
break; |
|
388 |
case 1: |
||
389 |
case 32: |
||
390 |
case 64: |
||
391 |
avpriv_report_missing_feature(avctx, "Depth %d", bits_per_color); |
||
392 |
return AVERROR_PATCHWELCOME; |
||
393 |
default: |
||
394 |
return AVERROR_INVALIDDATA; |
||
395 |
} |
||
396 |
|||
397 |
✓✗✗✗ ✓✓ |
93 |
switch (color_trc) { |
398 |
89 |
case DPX_TRC_LINEAR: |
|
399 |
89 |
avctx->color_trc = AVCOL_TRC_LINEAR; |
|
400 |
89 |
break; |
|
401 |
case DPX_TRC_SMPTE_274: |
||
402 |
case DPX_TRC_ITU_R_709_4: |
||
403 |
avctx->color_trc = AVCOL_TRC_BT709; |
||
404 |
break; |
||
405 |
case DPX_TRC_ITU_R_601_625: |
||
406 |
case DPX_TRC_ITU_R_601_525: |
||
407 |
case DPX_TRC_SMPTE_170: |
||
408 |
avctx->color_trc = AVCOL_TRC_SMPTE170M; |
||
409 |
break; |
||
410 |
case DPX_TRC_ITU_R_624_4_PAL: |
||
411 |
avctx->color_trc = AVCOL_TRC_GAMMA28; |
||
412 |
break; |
||
413 |
2 |
case DPX_TRC_USER_DEFINED: |
|
414 |
case DPX_TRC_UNSPECIFIED_VIDEO: |
||
415 |
/* Nothing to do */ |
||
416 |
2 |
break; |
|
417 |
2 |
default: |
|
418 |
2 |
av_log(avctx, AV_LOG_VERBOSE, "Cannot map DPX transfer characteristic " |
|
419 |
"%d to color_trc.\n", color_trc); |
||
420 |
2 |
break; |
|
421 |
} |
||
422 |
|||
423 |
✓✗✗✓ ✓ |
93 |
switch (color_spec) { |
424 |
2 |
case DPX_COL_SPEC_SMPTE_274: |
|
425 |
case DPX_COL_SPEC_ITU_R_709_4: |
||
426 |
2 |
avctx->color_primaries = AVCOL_PRI_BT709; |
|
427 |
2 |
break; |
|
428 |
case DPX_COL_SPEC_ITU_R_601_625: |
||
429 |
case DPX_COL_SPEC_ITU_R_624_4_PAL: |
||
430 |
avctx->color_primaries = AVCOL_PRI_BT470BG; |
||
431 |
break; |
||
432 |
case DPX_COL_SPEC_ITU_R_601_525: |
||
433 |
case DPX_COL_SPEC_SMPTE_170: |
||
434 |
avctx->color_primaries = AVCOL_PRI_SMPTE170M; |
||
435 |
break; |
||
436 |
2 |
case DPX_COL_SPEC_USER_DEFINED: |
|
437 |
case DPX_COL_SPEC_UNSPECIFIED_VIDEO: |
||
438 |
/* Nothing to do */ |
||
439 |
2 |
break; |
|
440 |
89 |
default: |
|
441 |
89 |
av_log(avctx, AV_LOG_VERBOSE, "Cannot map DPX color specification " |
|
442 |
"%d to color_primaries.\n", color_spec); |
||
443 |
89 |
break; |
|
444 |
} |
||
445 |
|||
446 |
✗✓ | 93 |
if (yuv) { |
447 |
switch (color_spec) { |
||
448 |
case DPX_COL_SPEC_SMPTE_274: |
||
449 |
case DPX_COL_SPEC_ITU_R_709_4: |
||
450 |
avctx->colorspace = AVCOL_SPC_BT709; |
||
451 |
break; |
||
452 |
case DPX_COL_SPEC_ITU_R_601_625: |
||
453 |
case DPX_COL_SPEC_ITU_R_624_4_PAL: |
||
454 |
avctx->colorspace = AVCOL_SPC_BT470BG; |
||
455 |
break; |
||
456 |
case DPX_COL_SPEC_ITU_R_601_525: |
||
457 |
case DPX_COL_SPEC_SMPTE_170: |
||
458 |
avctx->colorspace = AVCOL_SPC_SMPTE170M; |
||
459 |
break; |
||
460 |
case DPX_COL_SPEC_USER_DEFINED: |
||
461 |
case DPX_COL_SPEC_UNSPECIFIED_VIDEO: |
||
462 |
/* Nothing to do */ |
||
463 |
break; |
||
464 |
default: |
||
465 |
av_log(avctx, AV_LOG_INFO, "Cannot map DPX color specification " |
||
466 |
"%d to colorspace.\n", color_spec); |
||
467 |
break; |
||
468 |
} |
||
469 |
} else { |
||
470 |
93 |
avctx->colorspace = AVCOL_SPC_RGB; |
|
471 |
} |
||
472 |
|||
473 |
// Table 3c: Runs will always break at scan line boundaries. Packing |
||
474 |
// will always break to the next 32-bit word at scan-line boundaries. |
||
475 |
// Unfortunately, the encoder produced invalid files, so attempt |
||
476 |
// to detect it |
||
477 |
93 |
need_align = FFALIGN(stride, 4); |
|
478 |
✗✓ | 93 |
if (need_align*avctx->height + (int64_t)offset > avpkt->size) { |
479 |
// Alignment seems unappliable, try without |
||
480 |
if (stride*avctx->height + (int64_t)offset > avpkt->size) { |
||
481 |
av_log(avctx, AV_LOG_ERROR, "Overread buffer. Invalid header?\n"); |
||
482 |
return AVERROR_INVALIDDATA; |
||
483 |
} else { |
||
484 |
av_log(avctx, AV_LOG_INFO, "Decoding DPX without scanline " |
||
485 |
"alignment.\n"); |
||
486 |
need_align = 0; |
||
487 |
} |
||
488 |
} else { |
||
489 |
93 |
need_align -= stride; |
|
490 |
93 |
stride = FFALIGN(stride, 4); |
|
491 |
} |
||
492 |
|||
493 |
✗✗✓✗ ✗✓✗✓ ✗✗✗✗ ✓✓✗✓ ✗✗✗✗ |
93 |
switch (1000 * descriptor + 10 * bits_per_color + endian) { |
494 |
case 6081: |
||
495 |
case 6080: |
||
496 |
avctx->pix_fmt = AV_PIX_FMT_GRAY8; |
||
497 |
break; |
||
498 |
case 6121: |
||
499 |
case 6120: |
||
500 |
avctx->pix_fmt = AV_PIX_FMT_GRAY12; |
||
501 |
break; |
||
502 |
19 |
case 50081: |
|
503 |
case 50080: |
||
504 |
19 |
avctx->pix_fmt = AV_PIX_FMT_RGB24; |
|
505 |
19 |
break; |
|
506 |
case 52081: |
||
507 |
case 52080: |
||
508 |
avctx->pix_fmt = AV_PIX_FMT_ABGR; |
||
509 |
break; |
||
510 |
case 51081: |
||
511 |
case 51080: |
||
512 |
avctx->pix_fmt = AV_PIX_FMT_RGBA; |
||
513 |
break; |
||
514 |
30 |
case 50100: |
|
515 |
case 50101: |
||
516 |
30 |
avctx->pix_fmt = AV_PIX_FMT_GBRP10; |
|
517 |
30 |
break; |
|
518 |
case 51100: |
||
519 |
case 51101: |
||
520 |
avctx->pix_fmt = AV_PIX_FMT_GBRAP10; |
||
521 |
break; |
||
522 |
14 |
case 50120: |
|
523 |
case 50121: |
||
524 |
14 |
avctx->pix_fmt = AV_PIX_FMT_GBRP12; |
|
525 |
14 |
break; |
|
526 |
case 51120: |
||
527 |
case 51121: |
||
528 |
avctx->pix_fmt = AV_PIX_FMT_GBRAP12; |
||
529 |
break; |
||
530 |
case 6100: |
||
531 |
case 6101: |
||
532 |
avctx->pix_fmt = AV_PIX_FMT_GRAY10; |
||
533 |
break; |
||
534 |
case 6161: |
||
535 |
avctx->pix_fmt = AV_PIX_FMT_GRAY16BE; |
||
536 |
break; |
||
537 |
case 6160: |
||
538 |
avctx->pix_fmt = AV_PIX_FMT_GRAY16LE; |
||
539 |
break; |
||
540 |
2 |
case 50161: |
|
541 |
2 |
avctx->pix_fmt = AV_PIX_FMT_RGB48BE; |
|
542 |
2 |
break; |
|
543 |
14 |
case 50160: |
|
544 |
14 |
avctx->pix_fmt = AV_PIX_FMT_RGB48LE; |
|
545 |
14 |
break; |
|
546 |
case 51161: |
||
547 |
avctx->pix_fmt = AV_PIX_FMT_RGBA64BE; |
||
548 |
break; |
||
549 |
14 |
case 51160: |
|
550 |
14 |
avctx->pix_fmt = AV_PIX_FMT_RGBA64LE; |
|
551 |
14 |
break; |
|
552 |
case 100081: |
||
553 |
avctx->pix_fmt = AV_PIX_FMT_UYVY422; |
||
554 |
break; |
||
555 |
case 102081: |
||
556 |
avctx->pix_fmt = AV_PIX_FMT_YUV444P; |
||
557 |
break; |
||
558 |
case 103081: |
||
559 |
avctx->pix_fmt = AV_PIX_FMT_YUVA444P; |
||
560 |
break; |
||
561 |
default: |
||
562 |
av_log(avctx, AV_LOG_ERROR, "Unsupported format\n"); |
||
563 |
return AVERROR_PATCHWELCOME; |
||
564 |
} |
||
565 |
|||
566 |
93 |
ff_set_sar(avctx, avctx->sample_aspect_ratio); |
|
567 |
|||
568 |
✗✓ | 93 |
if ((ret = ff_get_buffer(avctx, p, 0)) < 0) |
569 |
return ret; |
||
570 |
|||
571 |
93 |
av_strlcpy(creator, avpkt->data + 160, 100); |
|
572 |
93 |
creator[100] = '\0'; |
|
573 |
93 |
av_dict_set(&p->metadata, "Creator", creator, 0); |
|
574 |
|||
575 |
93 |
av_strlcpy(input_device, avpkt->data + 1556, 32); |
|
576 |
93 |
input_device[32] = '\0'; |
|
577 |
93 |
av_dict_set(&p->metadata, "Input Device", input_device, 0); |
|
578 |
|||
579 |
// Some devices do not pad 10bit samples to whole 32bit words per row |
||
580 |
✓✗ | 93 |
if (!memcmp(input_device, "Scanity", 7) || |
581 |
✗✓ | 93 |
!memcmp(creator, "Lasergraphics Inc.", 18)) { |
582 |
unpadded_10bit = 1; |
||
583 |
} |
||
584 |
|||
585 |
// Move pointer to offset from start of file |
||
586 |
93 |
buf = avpkt->data + offset; |
|
587 |
|||
588 |
✓✓ | 837 |
for (i=0; i<AV_NUM_DATA_POINTERS; i++) |
589 |
744 |
ptr[i] = p->data[i]; |
|
590 |
|||
591 |
✓✓✓✓ ✗ |
93 |
switch (bits_per_color) { |
592 |
30 |
case 10: |
|
593 |
✓✓ | 8574 |
for (x = 0; x < avctx->height; x++) { |
594 |
8544 |
uint16_t *dst[4] = {(uint16_t*)ptr[0], |
|
595 |
8544 |
(uint16_t*)ptr[1], |
|
596 |
8544 |
(uint16_t*)ptr[2], |
|
597 |
8544 |
(uint16_t*)ptr[3]}; |
|
598 |
✓✗✓✗ ✗✗ |
8544 |
int shift = elements > 1 ? packing == 1 ? 22 : 20 : packing == 1 ? 2 : 0; |
599 |
✓✓ | 3052512 |
for (y = 0; y < avctx->width; y++) { |
600 |
✓✗ | 3043968 |
if (elements >= 3) |
601 |
3043968 |
*dst[2]++ = read10in32(&buf, &rgbBuffer, |
|
602 |
&n_datum, endian, shift); |
||
603 |
✗✓ | 3043968 |
if (elements == 1) |
604 |
*dst[0]++ = read10in32_gray(&buf, &rgbBuffer, |
||
605 |
&n_datum, endian, shift); |
||
606 |
else |
||
607 |
3043968 |
*dst[0]++ = read10in32(&buf, &rgbBuffer, |
|
608 |
&n_datum, endian, shift); |
||
609 |
✓✗ | 3043968 |
if (elements >= 2) |
610 |
3043968 |
*dst[1]++ = read10in32(&buf, &rgbBuffer, |
|
611 |
&n_datum, endian, shift); |
||
612 |
✗✓ | 3043968 |
if (elements == 4) |
613 |
*dst[3]++ = |
||
614 |
read10in32(&buf, &rgbBuffer, |
||
615 |
&n_datum, endian, shift); |
||
616 |
} |
||
617 |
✓✗ | 8544 |
if (!unpadded_10bit) |
618 |
8544 |
n_datum = 0; |
|
619 |
✓✓ | 34176 |
for (i = 0; i < elements; i++) |
620 |
25632 |
ptr[i] += p->linesize[i]; |
|
621 |
} |
||
622 |
30 |
break; |
|
623 |
14 |
case 12: |
|
624 |
✓✓ | 4046 |
for (x = 0; x < avctx->height; x++) { |
625 |
4032 |
uint16_t *dst[4] = {(uint16_t*)ptr[0], |
|
626 |
4032 |
(uint16_t*)ptr[1], |
|
627 |
4032 |
(uint16_t*)ptr[2], |
|
628 |
4032 |
(uint16_t*)ptr[3]}; |
|
629 |
✓✗ | 4032 |
int shift = packing == 1 ? 4 : 0; |
630 |
✓✓ | 1423296 |
for (y = 0; y < avctx->width; y++) { |
631 |
✓✗ | 1419264 |
if (packing) { |
632 |
✓✗ | 1419264 |
if (elements >= 3) |
633 |
1419264 |
*dst[2]++ = read16(&buf, endian) >> shift & 0xFFF; |
|
634 |
1419264 |
*dst[0]++ = read16(&buf, endian) >> shift & 0xFFF; |
|
635 |
✓✗ | 1419264 |
if (elements >= 2) |
636 |
1419264 |
*dst[1]++ = read16(&buf, endian) >> shift & 0xFFF; |
|
637 |
✗✓ | 1419264 |
if (elements == 4) |
638 |
*dst[3]++ = read16(&buf, endian) >> shift & 0xFFF; |
||
639 |
} else { |
||
640 |
if (elements >= 3) |
||
641 |
*dst[2]++ = read12in32(&buf, &rgbBuffer, |
||
642 |
&n_datum, endian); |
||
643 |
*dst[0]++ = read12in32(&buf, &rgbBuffer, |
||
644 |
&n_datum, endian); |
||
645 |
if (elements >= 2) |
||
646 |
*dst[1]++ = read12in32(&buf, &rgbBuffer, |
||
647 |
&n_datum, endian); |
||
648 |
if (elements == 4) |
||
649 |
*dst[3]++ = read12in32(&buf, &rgbBuffer, |
||
650 |
&n_datum, endian); |
||
651 |
} |
||
652 |
} |
||
653 |
4032 |
n_datum = 0; |
|
654 |
✓✓ | 16128 |
for (i = 0; i < elements; i++) |
655 |
12096 |
ptr[i] += p->linesize[i]; |
|
656 |
// Jump to next aligned position |
||
657 |
4032 |
buf += need_align; |
|
658 |
} |
||
659 |
14 |
break; |
|
660 |
30 |
case 16: |
|
661 |
30 |
elements *= 2; |
|
662 |
49 |
case 8: |
|
663 |
✓✗ | 49 |
if ( avctx->pix_fmt == AV_PIX_FMT_YUVA444P |
664 |
✗✓ | 49 |
|| avctx->pix_fmt == AV_PIX_FMT_YUV444P) { |
665 |
for (x = 0; x < avctx->height; x++) { |
||
666 |
ptr[0] = p->data[0] + x * p->linesize[0]; |
||
667 |
ptr[1] = p->data[1] + x * p->linesize[1]; |
||
668 |
ptr[2] = p->data[2] + x * p->linesize[2]; |
||
669 |
ptr[3] = p->data[3] + x * p->linesize[3]; |
||
670 |
for (y = 0; y < avctx->width; y++) { |
||
671 |
*ptr[1]++ = *buf++; |
||
672 |
*ptr[0]++ = *buf++; |
||
673 |
*ptr[2]++ = *buf++; |
||
674 |
if (avctx->pix_fmt == AV_PIX_FMT_YUVA444P) |
||
675 |
*ptr[3]++ = *buf++; |
||
676 |
} |
||
677 |
} |
||
678 |
} else { |
||
679 |
49 |
av_image_copy_plane(ptr[0], p->linesize[0], |
|
680 |
buf, stride, |
||
681 |
49 |
elements * avctx->width, avctx->height); |
|
682 |
} |
||
683 |
49 |
break; |
|
684 |
} |
||
685 |
|||
686 |
93 |
*got_frame = 1; |
|
687 |
|||
688 |
93 |
return buf_size; |
|
689 |
} |
||
690 |
|||
691 |
AVCodec ff_dpx_decoder = { |
||
692 |
.name = "dpx", |
||
693 |
.long_name = NULL_IF_CONFIG_SMALL("DPX (Digital Picture Exchange) image"), |
||
694 |
.type = AVMEDIA_TYPE_VIDEO, |
||
695 |
.id = AV_CODEC_ID_DPX, |
||
696 |
.decode = decode_frame, |
||
697 |
.capabilities = AV_CODEC_CAP_DR1, |
||
698 |
}; |
Generated by: GCOVR (Version 4.2) |