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
27
30 {
32 int buf_size = avpkt->
size;
35 int i, j,
n, linesize, h, upgrade = 0, is_mono = 0;
36 unsigned char *ptr;
37 int components, sample_len,
ret;
38
42
45
50
52 default:
56 components=4;
57 sample_len=16;
58 goto do_read;
61 components=3;
62 sample_len=16;
63 goto do_read;
66 components=4;
67 sample_len=8;
68 goto do_read;
71 components=3;
72 sample_len=8;
73 goto do_read;
76 components=1;
77 sample_len=8;
79 upgrade = 1;
80 goto do_read;
83 components=2;
84 sample_len=8;
85 goto do_read;
89 components=1;
90 sample_len=16;
92 upgrade = 2;
93 goto do_read;
96 n = (avctx->
width + 7) >> 3;
97 components=1;
98 sample_len=1;
99 is_mono = 1;
100 do_read:
105 if(s->
type < 4 || (is_mono && s->
type==7)){
106 for (i=0; i<avctx->
height; i++) {
109 for(j=0; j<avctx->
width * components; j++){
117 if (is_mono) {
118 /* read a single digit */
120 } else {
121 /* read a sequence of digits */
122 do {
125 } while (c <= 9);
126 }
128 }
130 ptr+= linesize;
131 }
132 }else{
133 for (i = 0; i < avctx->
height; i++) {
134 if (!upgrade)
136 else if (upgrade == 1) {
137 unsigned int j, f = (255 * 128 + s->
maxval / 2) / s->
maxval;
138 for (j = 0; j <
n; j++)
140 } else if (upgrade == 2) {
141 unsigned int j,
v, f = (65535 * 32768 + s->
maxval / 2) / s->
maxval;
142 for (j = 0; j < n / 2; j++) {
144 ((uint16_t *)ptr)[j] = (v * f + 16384) >> 15;
145 }
146 }
148 ptr += linesize;
149 }
150 }
151 break;
155 {
156 unsigned char *ptr1, *ptr2;
157
162 n *= 2;
165 for (i = 0; i < avctx->
height; i++) {
168 ptr += linesize;
169 }
172 n >>= 1;
174 for (i = 0; i < h; i++) {
181 }
182 }
183 break;
185 {
186 uint16_t *ptr1, *ptr2;
187 const int f = (65535 * 32768 + s->
maxval / 2) / s->
maxval;
189
190 n = avctx->
width * 2;
195 for (i = 0; i < avctx->
height; i++) {
196 for (j = 0; j < n / 2; j++) {
198 ((uint16_t *)ptr)[j] = (
v * f + 16384) >> 15;
199 }
201 ptr += linesize;
202 }
203 ptr1 = (uint16_t*)p->
data[1];
204 ptr2 = (uint16_t*)p->
data[2];
205 n >>= 1;
207 for (i = 0; i < h; i++) {
208 for (j = 0; j < n / 2; j++) {
210 ptr1[j] = (
v * f + 16384) >> 15;
211 }
213
214 for (j = 0; j < n / 2; j++) {
216 ptr2[j] = (
v * f + 16384) >> 15;
217 }
219
222 }
223 }
224 break;
225 }
226 *got_frame = 1;
227
229 }
230
231
232 #if CONFIG_PGM_DECODER
241 };
242 #endif
243
244 #if CONFIG_PGMYUV_DECODER
253 };
254 #endif
255
256 #if CONFIG_PPM_DECODER
265 };
266 #endif
267
268 #if CONFIG_PBM_DECODER
277 };
278 #endif
279
280 #if CONFIG_PAM_DECODER
289 };
290 #endif