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 <stdlib.h>
23 #include <string.h>
24
28
30 {
31 return c == ' ' || c == '\n' || c == '\r' || c == '\t';
32 }
33
35 {
38
39 /* skip spaces and comments */
42 if (c == '#') {
45 }
47 break;
48 }
49 }
50
51 s = str;
53 if ((s - str) < buf_size - 1)
56 }
57 *s = '0円';
58 }
59
61 {
62 char buf1[32], tuple_type[32];
63 int h, w,
depth, maxval;
64
66 if(buf1[0] != 'P')
69
72 }
else if (s->
type==2 || s->
type==5) {
75 else
77 }
else if (s->
type==3 || s->
type==6) {
79 }
else if (s->
type==7) {
80 w = -1;
81 h = -1;
82 maxval = -1;
83 depth = -1;
84 tuple_type[0] = '0円';
85 for (;;) {
87 if (!strcmp(buf1, "WIDTH")) {
89 w = strtol(buf1,
NULL, 10);
90 } else if (!strcmp(buf1, "HEIGHT")) {
92 h = strtol(buf1,
NULL, 10);
93 } else if (!strcmp(buf1, "DEPTH")) {
95 depth = strtol(buf1,
NULL, 10);
96 } else if (!strcmp(buf1, "MAXVAL")) {
98 maxval = strtol(buf1,
NULL, 10);
99 } else if (!strcmp(buf1, "TUPLTYPE") ||
100 /* libavcodec used to write invalid files */
101 !strcmp(buf1, "TUPLETYPE")) {
102 pnm_get(s, tuple_type,
sizeof(tuple_type));
103 } else if (!strcmp(buf1, "ENDHDR")) {
104 break;
105 } else {
107 }
108 }
109 /* check that all tags are present */
112
116 if (depth == 1) {
117 if (maxval == 1) {
119 } else if (maxval < 256) {
121 } else {
123 }
124 } else if (depth == 2) {
125 if (maxval < 256) {
127 } else {
129 }
130 } else if (depth == 3) {
131 if (maxval < 256) {
133 } else {
135 }
136 } else if (depth == 4) {
137 if (maxval < 256) {
139 } else {
141 }
142 } else {
144 }
145 return 0;
146 } else {
148 }
149 pnm_get(s, buf1,
sizeof(buf1));
150 w = atoi(buf1);
151 pnm_get(s, buf1,
sizeof(buf1));
152 h = atoi(buf1);
155
158
160 pnm_get(s, buf1,
sizeof(buf1));
165 }
174 else if (s->
maxval < 1024)
176 else
178 } else {
182 }
183 }
184 }else
186 /* more check if YUV420 */
188 if ((avctx->
width & 1) != 0)
191 if ((h % 3) != 0)
193 h /= 3;
195 }
196 return 0;
197 }