Line | Branch | Exec | Source |
---|---|---|---|
1 | /* | ||
2 | * PNM image format | ||
3 | * Copyright (c) 2002, 2003 Fabrice Bellard | ||
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 "config_components.h" | ||
23 | |||
24 | #include "libavutil/half2float.h" | ||
25 | #include "libavutil/intfloat.h" | ||
26 | |||
27 | #include "avcodec.h" | ||
28 | #include "codec_internal.h" | ||
29 | #include "decode.h" | ||
30 | #include "put_bits.h" | ||
31 | #include "pnm.h" | ||
32 | |||
33 | 21123184 | static void samplecpy(uint8_t *dst, const uint8_t *src, int n, int maxval) | |
34 | { | ||
35 |
2/2✓ Branch 0 taken 21115696 times.
✓ Branch 1 taken 7488 times.
|
21123184 | if (maxval <= 255) { |
36 | 21115696 | memcpy(dst, src, n); | |
37 | } else { | ||
38 | int i; | ||
39 |
2/2✓ Branch 0 taken 5271552 times.
✓ Branch 1 taken 7488 times.
|
5279040 | for (i=0; i<n/2; i++) { |
40 | 5271552 | ((uint16_t *)dst)[i] = AV_RB16(src+2*i); | |
41 | } | ||
42 | } | ||
43 | 21123184 | } | |
44 | |||
45 | 39819 | static int pnm_decode_frame(AVCodecContext *avctx, AVFrame *p, | |
46 | int *got_frame, AVPacket *avpkt) | ||
47 | { | ||
48 | 39819 | const uint8_t *buf = avpkt->data; | |
49 | 39819 | int buf_size = avpkt->size; | |
50 | 39819 | PNMContext * const s = avctx->priv_data; | |
51 | 39819 | int i, j, k, n, linesize, h, upgrade = 0, is_mono = 0; | |
52 | unsigned char *ptr; | ||
53 | int components, sample_len, ret; | ||
54 | float scale; | ||
55 | |||
56 | 39819 | s->bytestream_start = | |
57 | 39819 | s->bytestream = buf; | |
58 | 39819 | s->bytestream_end = buf + buf_size; | |
59 | |||
60 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 39819 times.
|
39819 | if ((ret = ff_pnm_decode_header(avctx, s)) < 0) |
61 | ✗ | return ret; | |
62 | |||
63 |
2/2✓ Branch 0 taken 2959 times.
✓ Branch 1 taken 36860 times.
|
39819 | if (avctx->skip_frame >= AVDISCARD_ALL) |
64 | 2959 | return avpkt->size; | |
65 | |||
66 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 36860 times.
|
36860 | if ((ret = ff_get_buffer(avctx, p, 0)) < 0) |
67 | ✗ | return ret; | |
68 | 36860 | avctx->bits_per_raw_sample = av_log2(s->maxval) + 1; | |
69 | |||
70 |
9/14✗ Branch 0 not taken.
✗ Branch 1 not taken.
✓ Branch 2 taken 13 times.
✓ Branch 3 taken 13 times.
✓ Branch 4 taken 52 times.
✓ Branch 5 taken 208 times.
✗ Branch 6 not taken.
✓ Branch 7 taken 13 times.
✗ Branch 8 not taken.
✓ Branch 9 taken 38 times.
✓ Branch 10 taken 36471 times.
✗ Branch 11 not taken.
✓ Branch 12 taken 26 times.
✓ Branch 13 taken 26 times.
|
36860 | switch (avctx->pix_fmt) { |
71 | ✗ | default: | |
72 | ✗ | return AVERROR(EINVAL); | |
73 | ✗ | case AV_PIX_FMT_RGBA64: | |
74 | ✗ | n = avctx->width * 8; | |
75 | ✗ | components=4; | |
76 | ✗ | sample_len=16; | |
77 | ✗ | if (s->maxval < 65535) | |
78 | ✗ | upgrade = 2; | |
79 | ✗ | goto do_read; | |
80 | 13 | case AV_PIX_FMT_RGB48: | |
81 | 13 | n = avctx->width * 6; | |
82 | 13 | components=3; | |
83 | 13 | sample_len=16; | |
84 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 13 times.
|
13 | if (s->maxval < 65535) |
85 | ✗ | upgrade = 2; | |
86 | 13 | goto do_read; | |
87 | 13 | case AV_PIX_FMT_RGBA: | |
88 | 13 | n = avctx->width * 4; | |
89 | 13 | components=4; | |
90 | 13 | sample_len=8; | |
91 | 13 | goto do_read; | |
92 | 52 | case AV_PIX_FMT_RGB24: | |
93 | 52 | n = avctx->width * 3; | |
94 | 52 | components=3; | |
95 | 52 | sample_len=8; | |
96 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 52 times.
|
52 | if (s->maxval < 255) |
97 | ✗ | upgrade = 1; | |
98 | 52 | goto do_read; | |
99 | 208 | case AV_PIX_FMT_GRAY8: | |
100 | 208 | n = avctx->width; | |
101 | 208 | components=1; | |
102 | 208 | sample_len=8; | |
103 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 208 times.
|
208 | if (s->maxval < 255) |
104 | ✗ | upgrade = 1; | |
105 | 208 | goto do_read; | |
106 | ✗ | case AV_PIX_FMT_GRAY8A: | |
107 | ✗ | n = avctx->width * 2; | |
108 | ✗ | components=2; | |
109 | ✗ | sample_len=8; | |
110 | ✗ | goto do_read; | |
111 | 13 | case AV_PIX_FMT_GRAY16: | |
112 | 13 | n = avctx->width * 2; | |
113 | 13 | components=1; | |
114 | 13 | sample_len=16; | |
115 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 13 times.
|
13 | if (s->maxval < 65535) |
116 | ✗ | upgrade = 2; | |
117 | 13 | goto do_read; | |
118 | ✗ | case AV_PIX_FMT_YA16: | |
119 | ✗ | n = avctx->width * 4; | |
120 | ✗ | components=2; | |
121 | ✗ | sample_len=16; | |
122 | ✗ | if (s->maxval < 65535) | |
123 | ✗ | upgrade = 2; | |
124 | ✗ | goto do_read; | |
125 | 38 | case AV_PIX_FMT_MONOWHITE: | |
126 | case AV_PIX_FMT_MONOBLACK: | ||
127 | 38 | n = (avctx->width + 7) >> 3; | |
128 | 38 | components=1; | |
129 | 38 | sample_len=1; | |
130 | 38 | is_mono = 1; | |
131 | 337 | do_read: | |
132 | 337 | ptr = p->data[0]; | |
133 | 337 | linesize = p->linesize[0]; | |
134 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 337 times.
|
337 | if (n * avctx->height > s->bytestream_end - s->bytestream) |
135 | ✗ | return AVERROR_INVALIDDATA; | |
136 |
5/6✓ Branch 0 taken 337 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 38 times.
✓ Branch 3 taken 299 times.
✓ Branch 4 taken 13 times.
✓ Branch 5 taken 25 times.
|
337 | if(s->type < 4 || (is_mono && s->type==7)){ |
137 |
2/2✓ Branch 0 taken 3744 times.
✓ Branch 1 taken 13 times.
|
3757 | for (i=0; i<avctx->height; i++) { |
138 | PutBitContext pb; | ||
139 | 3744 | init_put_bits(&pb, ptr, FFABS(linesize)); | |
140 |
2/2✓ Branch 0 taken 1317888 times.
✓ Branch 1 taken 3744 times.
|
1321632 | for(j=0; j<avctx->width * components; j++){ |
141 | 1317888 | unsigned int c=0; | |
142 | 1317888 | unsigned v=0; | |
143 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1317888 times.
|
1317888 | if(s->type < 4) |
144 | ✗ | while(s->bytestream < s->bytestream_end && (*s->bytestream < '0' || *s->bytestream > '9' )) | |
145 | ✗ | s->bytestream++; | |
146 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1317888 times.
|
1317888 | if(s->bytestream >= s->bytestream_end) |
147 | ✗ | return AVERROR_INVALIDDATA; | |
148 |
1/2✓ Branch 0 taken 1317888 times.
✗ Branch 1 not taken.
|
1317888 | if (is_mono) { |
149 | /* read a single digit */ | ||
150 | 1317888 | v = (*s->bytestream++)&1; | |
151 | } else { | ||
152 | /* read a sequence of digits */ | ||
153 | ✗ | for (k = 0; k < 6 && c <= 9; k += 1) { | |
154 | ✗ | v = 10*v + c; | |
155 | ✗ | c = (*s->bytestream++) - '0'; | |
156 | } | ||
157 | ✗ | if (v > s->maxval) { | |
158 | ✗ | av_log(avctx, AV_LOG_ERROR, "value %d larger than maxval %d\n", v, s->maxval); | |
159 | ✗ | return AVERROR_INVALIDDATA; | |
160 | } | ||
161 | } | ||
162 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1317888 times.
|
1317888 | if (sample_len == 16) { |
163 | ✗ | ((uint16_t*)ptr)[j] = (((1<<sample_len)-1)*v + (s->maxval>>1))/s->maxval; | |
164 | } else | ||
165 | 1317888 | put_bits(&pb, sample_len, (((1<<sample_len)-1)*v + (s->maxval>>1))/s->maxval); | |
166 | } | ||
167 |
1/2✓ Branch 0 taken 3744 times.
✗ Branch 1 not taken.
|
3744 | if (sample_len != 16) |
168 | 3744 | flush_put_bits(&pb); | |
169 | 3744 | ptr+= linesize; | |
170 | } | ||
171 | }else{ | ||
172 |
2/2✓ Branch 0 taken 115888 times.
✓ Branch 1 taken 324 times.
|
116212 | for (int i = 0; i < avctx->height; i++) { |
173 |
1/2✓ Branch 0 taken 115888 times.
✗ Branch 1 not taken.
|
115888 | if (!upgrade) |
174 | 115888 | samplecpy(ptr, s->bytestream, n, s->maxval); | |
175 | ✗ | else if (upgrade == 1) { | |
176 | ✗ | unsigned int f = (255 * 128 + s->maxval / 2) / s->maxval; | |
177 | ✗ | for (unsigned j = 0; j < n; j++) | |
178 | ✗ | ptr[j] = (s->bytestream[j] * f + 64) >> 7; | |
179 | ✗ | } else if (upgrade == 2) { | |
180 | ✗ | unsigned int f = (65535 * 32768 + s->maxval / 2) / s->maxval; | |
181 | ✗ | for (unsigned j = 0; j < n / 2; j++) { | |
182 | ✗ | unsigned v = AV_RB16(s->bytestream + 2*j); | |
183 | ✗ | ((uint16_t *)ptr)[j] = (v * f + 16384) >> 15; | |
184 | } | ||
185 | } | ||
186 | 115888 | s->bytestream += n; | |
187 | 115888 | ptr += linesize; | |
188 | } | ||
189 | } | ||
190 | 337 | break; | |
191 | 36471 | case AV_PIX_FMT_YUV420P: | |
192 | case AV_PIX_FMT_YUV420P9: | ||
193 | case AV_PIX_FMT_YUV420P10: | ||
194 | { | ||
195 | unsigned char *ptr1, *ptr2; | ||
196 | |||
197 | 36471 | n = avctx->width; | |
198 | 36471 | ptr = p->data[0]; | |
199 | 36471 | linesize = p->linesize[0]; | |
200 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 36471 times.
|
36471 | if (s->maxval >= 256) |
201 | ✗ | n *= 2; | |
202 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 36471 times.
|
36471 | if (n * avctx->height * 3 / 2 > s->bytestream_end - s->bytestream) |
203 | ✗ | return AVERROR_INVALIDDATA; | |
204 |
2/2✓ Branch 0 taken 10503648 times.
✓ Branch 1 taken 36471 times.
|
10540119 | for (i = 0; i < avctx->height; i++) { |
205 | 10503648 | samplecpy(ptr, s->bytestream, n, s->maxval); | |
206 | 10503648 | s->bytestream += n; | |
207 | 10503648 | ptr += linesize; | |
208 | } | ||
209 | 36471 | ptr1 = p->data[1]; | |
210 | 36471 | ptr2 = p->data[2]; | |
211 | 36471 | n >>= 1; | |
212 | 36471 | h = avctx->height >> 1; | |
213 |
2/2✓ Branch 0 taken 5251824 times.
✓ Branch 1 taken 36471 times.
|
5288295 | for (i = 0; i < h; i++) { |
214 | 5251824 | samplecpy(ptr1, s->bytestream, n, s->maxval); | |
215 | 5251824 | s->bytestream += n; | |
216 | 5251824 | samplecpy(ptr2, s->bytestream, n, s->maxval); | |
217 | 5251824 | s->bytestream += n; | |
218 | 5251824 | ptr1 += p->linesize[1]; | |
219 | 5251824 | ptr2 += p->linesize[2]; | |
220 | } | ||
221 | } | ||
222 | 36471 | break; | |
223 | ✗ | case AV_PIX_FMT_YUV420P16: | |
224 | { | ||
225 | uint16_t *ptr1, *ptr2; | ||
226 | ✗ | const int f = (65535 * 32768 + s->maxval / 2) / s->maxval; | |
227 | unsigned int j, v; | ||
228 | |||
229 | ✗ | n = avctx->width * 2; | |
230 | ✗ | ptr = p->data[0]; | |
231 | ✗ | linesize = p->linesize[0]; | |
232 | ✗ | if (n * avctx->height * 3 / 2 > s->bytestream_end - s->bytestream) | |
233 | ✗ | return AVERROR_INVALIDDATA; | |
234 | ✗ | for (i = 0; i < avctx->height; i++) { | |
235 | ✗ | for (j = 0; j < n / 2; j++) { | |
236 | ✗ | v = AV_RB16(s->bytestream + 2*j); | |
237 | ✗ | ((uint16_t *)ptr)[j] = (v * f + 16384) >> 15; | |
238 | } | ||
239 | ✗ | s->bytestream += n; | |
240 | ✗ | ptr += linesize; | |
241 | } | ||
242 | ✗ | ptr1 = (uint16_t*)p->data[1]; | |
243 | ✗ | ptr2 = (uint16_t*)p->data[2]; | |
244 | ✗ | n >>= 1; | |
245 | ✗ | h = avctx->height >> 1; | |
246 | ✗ | for (i = 0; i < h; i++) { | |
247 | ✗ | for (j = 0; j < n / 2; j++) { | |
248 | ✗ | v = AV_RB16(s->bytestream + 2*j); | |
249 | ✗ | ptr1[j] = (v * f + 16384) >> 15; | |
250 | } | ||
251 | ✗ | s->bytestream += n; | |
252 | |||
253 | ✗ | for (j = 0; j < n / 2; j++) { | |
254 | ✗ | v = AV_RB16(s->bytestream + 2*j); | |
255 | ✗ | ptr2[j] = (v * f + 16384) >> 15; | |
256 | } | ||
257 | ✗ | s->bytestream += n; | |
258 | |||
259 | ✗ | ptr1 += p->linesize[1] / 2; | |
260 | ✗ | ptr2 += p->linesize[2] / 2; | |
261 | } | ||
262 | } | ||
263 | ✗ | break; | |
264 | 26 | case AV_PIX_FMT_GBRPF32: | |
265 |
1/2✓ Branch 0 taken 26 times.
✗ Branch 1 not taken.
|
26 | if (!s->half) { |
266 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 26 times.
|
26 | if (avctx->width * avctx->height * 12LL > s->bytestream_end - s->bytestream) |
267 | ✗ | return AVERROR_INVALIDDATA; | |
268 | 26 | scale = 1.f / s->scale; | |
269 |
2/2✓ Branch 0 taken 13 times.
✓ Branch 1 taken 13 times.
|
26 | if (s->endian) { |
270 | float *r, *g, *b; | ||
271 | |||
272 | 13 | r = (float *)p->data[2]; | |
273 | 13 | g = (float *)p->data[0]; | |
274 | 13 | b = (float *)p->data[1]; | |
275 |
2/2✓ Branch 0 taken 3744 times.
✓ Branch 1 taken 13 times.
|
3757 | for (int i = 0; i < avctx->height; i++) { |
276 |
2/2✓ Branch 0 taken 1317888 times.
✓ Branch 1 taken 3744 times.
|
1321632 | for (int j = 0; j < avctx->width; j++) { |
277 | 1317888 | r[j] = av_int2float(AV_RL32(s->bytestream+0)) * scale; | |
278 | 1317888 | g[j] = av_int2float(AV_RL32(s->bytestream+4)) * scale; | |
279 | 1317888 | b[j] = av_int2float(AV_RL32(s->bytestream+8)) * scale; | |
280 | 1317888 | s->bytestream += 12; | |
281 | } | ||
282 | |||
283 | 3744 | r += p->linesize[2] / 4; | |
284 | 3744 | g += p->linesize[0] / 4; | |
285 | 3744 | b += p->linesize[1] / 4; | |
286 | } | ||
287 | } else { | ||
288 | float *r, *g, *b; | ||
289 | |||
290 | 13 | r = (float *)p->data[2]; | |
291 | 13 | g = (float *)p->data[0]; | |
292 | 13 | b = (float *)p->data[1]; | |
293 |
2/2✓ Branch 0 taken 3744 times.
✓ Branch 1 taken 13 times.
|
3757 | for (int i = 0; i < avctx->height; i++) { |
294 |
2/2✓ Branch 0 taken 1317888 times.
✓ Branch 1 taken 3744 times.
|
1321632 | for (int j = 0; j < avctx->width; j++) { |
295 | 1317888 | r[j] = av_int2float(AV_RB32(s->bytestream+0)) * scale; | |
296 | 1317888 | g[j] = av_int2float(AV_RB32(s->bytestream+4)) * scale; | |
297 | 1317888 | b[j] = av_int2float(AV_RB32(s->bytestream+8)) * scale; | |
298 | 1317888 | s->bytestream += 12; | |
299 | } | ||
300 | |||
301 | 3744 | r += p->linesize[2] / 4; | |
302 | 3744 | g += p->linesize[0] / 4; | |
303 | 3744 | b += p->linesize[1] / 4; | |
304 | } | ||
305 | } | ||
306 | } else { | ||
307 | ✗ | if (avctx->width * avctx->height * 6 > s->bytestream_end - s->bytestream) | |
308 | ✗ | return AVERROR_INVALIDDATA; | |
309 | ✗ | scale = 1.f / s->scale; | |
310 | ✗ | if (s->endian) { | |
311 | float *r, *g, *b; | ||
312 | |||
313 | ✗ | r = (float *)p->data[2]; | |
314 | ✗ | g = (float *)p->data[0]; | |
315 | ✗ | b = (float *)p->data[1]; | |
316 | ✗ | for (int i = 0; i < avctx->height; i++) { | |
317 | ✗ | for (int j = 0; j < avctx->width; j++) { | |
318 | ✗ | r[j] = av_int2float(half2float(AV_RL16(s->bytestream+0), &s->h2f_tables)) * scale; | |
319 | ✗ | g[j] = av_int2float(half2float(AV_RL16(s->bytestream+2), &s->h2f_tables)) * scale; | |
320 | ✗ | b[j] = av_int2float(half2float(AV_RL16(s->bytestream+4), &s->h2f_tables)) * scale; | |
321 | ✗ | s->bytestream += 6; | |
322 | } | ||
323 | |||
324 | ✗ | r += p->linesize[2] / 4; | |
325 | ✗ | g += p->linesize[0] / 4; | |
326 | ✗ | b += p->linesize[1] / 4; | |
327 | } | ||
328 | } else { | ||
329 | float *r, *g, *b; | ||
330 | |||
331 | ✗ | r = (float *)p->data[2]; | |
332 | ✗ | g = (float *)p->data[0]; | |
333 | ✗ | b = (float *)p->data[1]; | |
334 | ✗ | for (int i = 0; i < avctx->height; i++) { | |
335 | ✗ | for (int j = 0; j < avctx->width; j++) { | |
336 | ✗ | r[j] = av_int2float(half2float(AV_RB16(s->bytestream+0), &s->h2f_tables)) * scale; | |
337 | ✗ | g[j] = av_int2float(half2float(AV_RB16(s->bytestream+2), &s->h2f_tables)) * scale; | |
338 | ✗ | b[j] = av_int2float(half2float(AV_RB16(s->bytestream+4), &s->h2f_tables)) * scale; | |
339 | ✗ | s->bytestream += 6; | |
340 | } | ||
341 | |||
342 | ✗ | r += p->linesize[2] / 4; | |
343 | ✗ | g += p->linesize[0] / 4; | |
344 | ✗ | b += p->linesize[1] / 4; | |
345 | } | ||
346 | } | ||
347 | } | ||
348 | /* PFM is encoded from bottom to top */ | ||
349 | 26 | p->data[0] += (avctx->height - 1) * p->linesize[0]; | |
350 | 26 | p->data[1] += (avctx->height - 1) * p->linesize[1]; | |
351 | 26 | p->data[2] += (avctx->height - 1) * p->linesize[2]; | |
352 | 26 | p->linesize[0] = -p->linesize[0]; | |
353 | 26 | p->linesize[1] = -p->linesize[1]; | |
354 | 26 | p->linesize[2] = -p->linesize[2]; | |
355 | 26 | break; | |
356 | 26 | case AV_PIX_FMT_GRAYF32: | |
357 |
1/2✓ Branch 0 taken 26 times.
✗ Branch 1 not taken.
|
26 | if (!s->half) { |
358 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 26 times.
|
26 | if (avctx->width * avctx->height * 4 > s->bytestream_end - s->bytestream) |
359 | ✗ | return AVERROR_INVALIDDATA; | |
360 | 26 | scale = 1.f / s->scale; | |
361 |
2/2✓ Branch 0 taken 13 times.
✓ Branch 1 taken 13 times.
|
26 | if (s->endian) { |
362 | 13 | float *g = (float *)p->data[0]; | |
363 |
2/2✓ Branch 0 taken 3744 times.
✓ Branch 1 taken 13 times.
|
3757 | for (int i = 0; i < avctx->height; i++) { |
364 |
2/2✓ Branch 0 taken 1317888 times.
✓ Branch 1 taken 3744 times.
|
1321632 | for (int j = 0; j < avctx->width; j++) { |
365 | 1317888 | g[j] = av_int2float(AV_RL32(s->bytestream)) * scale; | |
366 | 1317888 | s->bytestream += 4; | |
367 | } | ||
368 | 3744 | g += p->linesize[0] / 4; | |
369 | } | ||
370 | } else { | ||
371 | 13 | float *g = (float *)p->data[0]; | |
372 |
2/2✓ Branch 0 taken 3744 times.
✓ Branch 1 taken 13 times.
|
3757 | for (int i = 0; i < avctx->height; i++) { |
373 |
2/2✓ Branch 0 taken 1317888 times.
✓ Branch 1 taken 3744 times.
|
1321632 | for (int j = 0; j < avctx->width; j++) { |
374 | 1317888 | g[j] = av_int2float(AV_RB32(s->bytestream)) * scale; | |
375 | 1317888 | s->bytestream += 4; | |
376 | } | ||
377 | 3744 | g += p->linesize[0] / 4; | |
378 | } | ||
379 | } | ||
380 | } else { | ||
381 | ✗ | if (avctx->width * avctx->height * 2 > s->bytestream_end - s->bytestream) | |
382 | ✗ | return AVERROR_INVALIDDATA; | |
383 | ✗ | scale = 1.f / s->scale; | |
384 | ✗ | if (s->endian) { | |
385 | ✗ | float *g = (float *)p->data[0]; | |
386 | ✗ | for (int i = 0; i < avctx->height; i++) { | |
387 | ✗ | for (int j = 0; j < avctx->width; j++) { | |
388 | ✗ | g[j] = av_int2float(half2float(AV_RL16(s->bytestream), &s->h2f_tables)) * scale; | |
389 | ✗ | s->bytestream += 2; | |
390 | } | ||
391 | ✗ | g += p->linesize[0] / 4; | |
392 | } | ||
393 | } else { | ||
394 | ✗ | float *g = (float *)p->data[0]; | |
395 | ✗ | for (int i = 0; i < avctx->height; i++) { | |
396 | ✗ | for (int j = 0; j < avctx->width; j++) { | |
397 | ✗ | g[j] = av_int2float(half2float(AV_RB16(s->bytestream), &s->h2f_tables)) * scale; | |
398 | ✗ | s->bytestream += 2; | |
399 | } | ||
400 | ✗ | g += p->linesize[0] / 4; | |
401 | } | ||
402 | } | ||
403 | } | ||
404 | /* PFM is encoded from bottom to top */ | ||
405 | 26 | p->data[0] += (avctx->height - 1) * p->linesize[0]; | |
406 | 26 | p->linesize[0] = -p->linesize[0]; | |
407 | 26 | break; | |
408 | } | ||
409 | 36860 | *got_frame = 1; | |
410 | |||
411 | 36860 | return s->bytestream - s->bytestream_start; | |
412 | } | ||
413 | |||
414 | |||
415 | #if CONFIG_PGM_DECODER | ||
416 | const FFCodec ff_pgm_decoder = { | ||
417 | .p.name = "pgm", | ||
418 | CODEC_LONG_NAME("PGM (Portable GrayMap) image"), | ||
419 | .p.type = AVMEDIA_TYPE_VIDEO, | ||
420 | .p.id = AV_CODEC_ID_PGM, | ||
421 | .p.capabilities = AV_CODEC_CAP_DR1, | ||
422 | .priv_data_size = sizeof(PNMContext), | ||
423 | .caps_internal = FF_CODEC_CAP_SKIP_FRAME_FILL_PARAM, | ||
424 | FF_CODEC_DECODE_CB(pnm_decode_frame), | ||
425 | }; | ||
426 | #endif | ||
427 | |||
428 | #if CONFIG_PGMYUV_DECODER | ||
429 | const FFCodec ff_pgmyuv_decoder = { | ||
430 | .p.name = "pgmyuv", | ||
431 | CODEC_LONG_NAME("PGMYUV (Portable GrayMap YUV) image"), | ||
432 | .p.type = AVMEDIA_TYPE_VIDEO, | ||
433 | .p.id = AV_CODEC_ID_PGMYUV, | ||
434 | .p.capabilities = AV_CODEC_CAP_DR1, | ||
435 | .priv_data_size = sizeof(PNMContext), | ||
436 | .caps_internal = FF_CODEC_CAP_SKIP_FRAME_FILL_PARAM, | ||
437 | FF_CODEC_DECODE_CB(pnm_decode_frame), | ||
438 | }; | ||
439 | #endif | ||
440 | |||
441 | #if CONFIG_PPM_DECODER | ||
442 | const FFCodec ff_ppm_decoder = { | ||
443 | .p.name = "ppm", | ||
444 | CODEC_LONG_NAME("PPM (Portable PixelMap) image"), | ||
445 | .p.type = AVMEDIA_TYPE_VIDEO, | ||
446 | .p.id = AV_CODEC_ID_PPM, | ||
447 | .p.capabilities = AV_CODEC_CAP_DR1, | ||
448 | .priv_data_size = sizeof(PNMContext), | ||
449 | .caps_internal = FF_CODEC_CAP_SKIP_FRAME_FILL_PARAM, | ||
450 | FF_CODEC_DECODE_CB(pnm_decode_frame), | ||
451 | }; | ||
452 | #endif | ||
453 | |||
454 | #if CONFIG_PBM_DECODER | ||
455 | const FFCodec ff_pbm_decoder = { | ||
456 | .p.name = "pbm", | ||
457 | CODEC_LONG_NAME("PBM (Portable BitMap) image"), | ||
458 | .p.type = AVMEDIA_TYPE_VIDEO, | ||
459 | .p.id = AV_CODEC_ID_PBM, | ||
460 | .p.capabilities = AV_CODEC_CAP_DR1, | ||
461 | .priv_data_size = sizeof(PNMContext), | ||
462 | .caps_internal = FF_CODEC_CAP_SKIP_FRAME_FILL_PARAM, | ||
463 | FF_CODEC_DECODE_CB(pnm_decode_frame), | ||
464 | }; | ||
465 | #endif | ||
466 | |||
467 | #if CONFIG_PAM_DECODER | ||
468 | const FFCodec ff_pam_decoder = { | ||
469 | .p.name = "pam", | ||
470 | CODEC_LONG_NAME("PAM (Portable AnyMap) image"), | ||
471 | .p.type = AVMEDIA_TYPE_VIDEO, | ||
472 | .p.id = AV_CODEC_ID_PAM, | ||
473 | .p.capabilities = AV_CODEC_CAP_DR1, | ||
474 | .priv_data_size = sizeof(PNMContext), | ||
475 | .caps_internal = FF_CODEC_CAP_SKIP_FRAME_FILL_PARAM, | ||
476 | FF_CODEC_DECODE_CB(pnm_decode_frame), | ||
477 | }; | ||
478 | #endif | ||
479 | |||
480 | #if CONFIG_PFM_DECODER | ||
481 | const FFCodec ff_pfm_decoder = { | ||
482 | .p.name = "pfm", | ||
483 | CODEC_LONG_NAME("PFM (Portable FloatMap) image"), | ||
484 | .p.type = AVMEDIA_TYPE_VIDEO, | ||
485 | .p.id = AV_CODEC_ID_PFM, | ||
486 | .p.capabilities = AV_CODEC_CAP_DR1, | ||
487 | .priv_data_size = sizeof(PNMContext), | ||
488 | .caps_internal = FF_CODEC_CAP_SKIP_FRAME_FILL_PARAM, | ||
489 | FF_CODEC_DECODE_CB(pnm_decode_frame), | ||
490 | }; | ||
491 | #endif | ||
492 | |||
493 | #if CONFIG_PHM_DECODER | ||
494 | ✗ | static av_cold int phm_dec_init(AVCodecContext *avctx) | |
495 | { | ||
496 | ✗ | PNMContext *s = avctx->priv_data; | |
497 | |||
498 | ✗ | ff_init_half2float_tables(&s->h2f_tables); | |
499 | |||
500 | ✗ | return 0; | |
501 | } | ||
502 | |||
503 | const FFCodec ff_phm_decoder = { | ||
504 | .p.name = "phm", | ||
505 | CODEC_LONG_NAME("PHM (Portable HalfFloatMap) image"), | ||
506 | .p.type = AVMEDIA_TYPE_VIDEO, | ||
507 | .p.id = AV_CODEC_ID_PHM, | ||
508 | .p.capabilities = AV_CODEC_CAP_DR1, | ||
509 | .priv_data_size = sizeof(PNMContext), | ||
510 | .init = phm_dec_init, | ||
511 | .caps_internal = FF_CODEC_CAP_SKIP_FRAME_FILL_PARAM, | ||
512 | FF_CODEC_DECODE_CB(pnm_decode_frame), | ||
513 | }; | ||
514 | #endif | ||
515 |