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
26
28 {
29 if (maxval <= 255) {
30 memcpy(dst, src, n);
31 } else {
32 int i;
33 for (i=0; i<n/2; i++) {
34 ((uint16_t *)dst)[i] =
AV_RB16(src+2*i);
35 }
36 }
37 }
38
41 {
43 int buf_size = avpkt->
size;
46 int i, j,
n, linesize, h, upgrade = 0, is_mono = 0;
47 unsigned char *ptr;
48 int components, sample_len,
ret;
49
53
56
62
64 default:
68 components=4;
69 sample_len=16;
71 upgrade = 2;
72 goto do_read;
75 components=3;
76 sample_len=16;
78 upgrade = 2;
79 goto do_read;
82 components=4;
83 sample_len=8;
84 goto do_read;
87 components=3;
88 sample_len=8;
90 upgrade = 1;
91 goto do_read;
94 components=1;
95 sample_len=8;
97 upgrade = 1;
98 goto do_read;
100 n = avctx->
width * 2;
101 components=2;
102 sample_len=8;
103 goto do_read;
105 n = avctx->
width * 2;
106 components=1;
107 sample_len=16;
109 upgrade = 2;
110 goto do_read;
113 n = (avctx->
width + 7) >> 3;
114 components=1;
115 sample_len=1;
116 is_mono = 1;
117 do_read:
122 if(s->
type < 4 || (is_mono && s->
type==7)){
123 for (i=0; i<avctx->
height; i++) {
126 for(j=0; j<avctx->
width * components; j++){
134 if (is_mono) {
135 /* read a single digit */
137 } else {
138 /* read a sequence of digits */
139 do {
142 } while (c <= 9);
143 }
144 if (sample_len == 16) {
145 ((uint16_t*)ptr)[j] = (((1<<sample_len)-1)*v + (s->
maxval>>1))/s->
maxval;
146 } else
148 }
149 if (sample_len != 16)
151 ptr+= linesize;
152 }
153 }else{
154 for (i = 0; i < avctx->
height; i++) {
155 if (!upgrade)
157 else if (upgrade == 1) {
158 unsigned int j, f = (255 * 128 + s->
maxval / 2) / s->
maxval;
159 for (j = 0; j <
n; j++)
161 } else if (upgrade == 2) {
162 unsigned int j,
v, f = (65535 * 32768 + s->
maxval / 2) / s->
maxval;
163 for (j = 0; j < n / 2; j++) {
165 ((uint16_t *)ptr)[j] = (v * f + 16384) >> 15;
166 }
167 }
169 ptr += linesize;
170 }
171 }
172 break;
176 {
177 unsigned char *ptr1, *ptr2;
178
183 n *= 2;
186 for (i = 0; i < avctx->
height; i++) {
189 ptr += linesize;
190 }
193 n >>= 1;
195 for (i = 0; i < h; i++) {
202 }
203 }
204 break;
206 {
207 uint16_t *ptr1, *ptr2;
208 const int f = (65535 * 32768 + s->
maxval / 2) / s->
maxval;
210
211 n = avctx->
width * 2;
216 for (i = 0; i < avctx->
height; i++) {
217 for (j = 0; j < n / 2; j++) {
219 ((uint16_t *)ptr)[j] = (
v * f + 16384) >> 15;
220 }
222 ptr += linesize;
223 }
224 ptr1 = (uint16_t*)p->
data[1];
225 ptr2 = (uint16_t*)p->
data[2];
226 n >>= 1;
228 for (i = 0; i < h; i++) {
229 for (j = 0; j < n / 2; j++) {
231 ptr1[j] = (
v * f + 16384) >> 15;
232 }
234
235 for (j = 0; j < n / 2; j++) {
237 ptr2[j] = (
v * f + 16384) >> 15;
238 }
240
243 }
244 }
245 break;
246 }
247 *got_frame = 1;
248
250 }
251
252
253 #if CONFIG_PGM_DECODER
262 };
263 #endif
264
265 #if CONFIG_PGMYUV_DECODER
274 };
275 #endif
276
277 #if CONFIG_PPM_DECODER
286 };
287 #endif
288
289 #if CONFIG_PBM_DECODER
298 };
299 #endif
300
301 #if CONFIG_PAM_DECODER
310 };
311 #endif