annotate pnm.c @ 1607:edb923014029 libavformat

do not base frame rate guess on just one duration
author michael
date Fri, 29 Dec 2006 21:16:21 +0000
parents 0899bfe4105c
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
20
3d52de18ecc3 added still image support
bellard
parents:
diff changeset
1 /*
3d52de18ecc3 added still image support
bellard
parents:
diff changeset
2 * PNM image format
3d52de18ecc3 added still image support
bellard
parents:
diff changeset
3 * Copyright (c) 2002, 2003 Fabrice Bellard.
3d52de18ecc3 added still image support
bellard
parents:
diff changeset
4 *
1358
0899bfe4105c Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents: 896
diff changeset
5 * This file is part of FFmpeg.
0899bfe4105c Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents: 896
diff changeset
6 *
0899bfe4105c Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents: 896
diff changeset
7 * FFmpeg is free software; you can redistribute it and/or
20
3d52de18ecc3 added still image support
bellard
parents:
diff changeset
8 * modify it under the terms of the GNU Lesser General Public
3d52de18ecc3 added still image support
bellard
parents:
diff changeset
9 * License as published by the Free Software Foundation; either
1358
0899bfe4105c Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents: 896
diff changeset
10 * version 2.1 of the License, or (at your option) any later version.
20
3d52de18ecc3 added still image support
bellard
parents:
diff changeset
11 *
1358
0899bfe4105c Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents: 896
diff changeset
12 * FFmpeg is distributed in the hope that it will be useful,
20
3d52de18ecc3 added still image support
bellard
parents:
diff changeset
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
3d52de18ecc3 added still image support
bellard
parents:
diff changeset
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
3d52de18ecc3 added still image support
bellard
parents:
diff changeset
15 * Lesser General Public License for more details.
3d52de18ecc3 added still image support
bellard
parents:
diff changeset
16 *
3d52de18ecc3 added still image support
bellard
parents:
diff changeset
17 * You should have received a copy of the GNU Lesser General Public
1358
0899bfe4105c Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents: 896
diff changeset
18 * License along with FFmpeg; if not, write to the Free Software
896
edbe5c3717f9 Update licensing information: The FSF changed postal address.
diego
parents: 885
diff changeset
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20
3d52de18ecc3 added still image support
bellard
parents:
diff changeset
20 */
3d52de18ecc3 added still image support
bellard
parents:
diff changeset
21 #include "avformat.h"
3d52de18ecc3 added still image support
bellard
parents:
diff changeset
22
885
da1d5db0ce5c COSMETICS: Remove all trailing whitespace.
diego
parents: 320
diff changeset
23 static inline int pnm_space(int c)
20
3d52de18ecc3 added still image support
bellard
parents:
diff changeset
24 {
3d52de18ecc3 added still image support
bellard
parents:
diff changeset
25 return (c == ' ' || c == '\n' || c == '\r' || c == '\t');
3d52de18ecc3 added still image support
bellard
parents:
diff changeset
26 }
3d52de18ecc3 added still image support
bellard
parents:
diff changeset
27
885
da1d5db0ce5c COSMETICS: Remove all trailing whitespace.
diego
parents: 320
diff changeset
28 static void pnm_get(ByteIOContext *f, char *str, int buf_size)
20
3d52de18ecc3 added still image support
bellard
parents:
diff changeset
29 {
3d52de18ecc3 added still image support
bellard
parents:
diff changeset
30 char *s;
3d52de18ecc3 added still image support
bellard
parents:
diff changeset
31 int c;
885
da1d5db0ce5c COSMETICS: Remove all trailing whitespace.
diego
parents: 320
diff changeset
32
20
3d52de18ecc3 added still image support
bellard
parents:
diff changeset
33 /* skip spaces and comments */
3d52de18ecc3 added still image support
bellard
parents:
diff changeset
34 for(;;) {
3d52de18ecc3 added still image support
bellard
parents:
diff changeset
35 c = url_fgetc(f);
3d52de18ecc3 added still image support
bellard
parents:
diff changeset
36 if (c == '#') {
3d52de18ecc3 added still image support
bellard
parents:
diff changeset
37 do {
3d52de18ecc3 added still image support
bellard
parents:
diff changeset
38 c = url_fgetc(f);
3d52de18ecc3 added still image support
bellard
parents:
diff changeset
39 } while (c != '\n' && c != URL_EOF);
3d52de18ecc3 added still image support
bellard
parents:
diff changeset
40 } else if (!pnm_space(c)) {
3d52de18ecc3 added still image support
bellard
parents:
diff changeset
41 break;
3d52de18ecc3 added still image support
bellard
parents:
diff changeset
42 }
3d52de18ecc3 added still image support
bellard
parents:
diff changeset
43 }
885
da1d5db0ce5c COSMETICS: Remove all trailing whitespace.
diego
parents: 320
diff changeset
44
20
3d52de18ecc3 added still image support
bellard
parents:
diff changeset
45 s = str;
3d52de18ecc3 added still image support
bellard
parents:
diff changeset
46 while (c != URL_EOF && !pnm_space(c)) {
3d52de18ecc3 added still image support
bellard
parents:
diff changeset
47 if ((s - str) < buf_size - 1)
3d52de18ecc3 added still image support
bellard
parents:
diff changeset
48 *s++ = c;
3d52de18ecc3 added still image support
bellard
parents:
diff changeset
49 c = url_fgetc(f);
3d52de18ecc3 added still image support
bellard
parents:
diff changeset
50 }
3d52de18ecc3 added still image support
bellard
parents:
diff changeset
51 *s = '\0';
3d52de18ecc3 added still image support
bellard
parents:
diff changeset
52 }
3d52de18ecc3 added still image support
bellard
parents:
diff changeset
53
885
da1d5db0ce5c COSMETICS: Remove all trailing whitespace.
diego
parents: 320
diff changeset
54 static int pnm_read1(ByteIOContext *f,
20
3d52de18ecc3 added still image support
bellard
parents:
diff changeset
55 int (*alloc_cb)(void *opaque, AVImageInfo *info), void *opaque,
3d52de18ecc3 added still image support
bellard
parents:
diff changeset
56 int allow_yuv)
3d52de18ecc3 added still image support
bellard
parents:
diff changeset
57 {
3d52de18ecc3 added still image support
bellard
parents:
diff changeset
58 int i, n, linesize, h;
3d52de18ecc3 added still image support
bellard
parents:
diff changeset
59 char buf1[32];
3d52de18ecc3 added still image support
bellard
parents:
diff changeset
60 unsigned char *ptr;
3d52de18ecc3 added still image support
bellard
parents:
diff changeset
61 AVImageInfo info1, *info = &info1;
3d52de18ecc3 added still image support
bellard
parents:
diff changeset
62 int ret;
3d52de18ecc3 added still image support
bellard
parents:
diff changeset
63
3d52de18ecc3 added still image support
bellard
parents:
diff changeset
64 pnm_get(f, buf1, sizeof(buf1));
3d52de18ecc3 added still image support
bellard
parents:
diff changeset
65 if (!strcmp(buf1, "P4")) {
3d52de18ecc3 added still image support
bellard
parents:
diff changeset
66 info->pix_fmt = PIX_FMT_MONOWHITE;
3d52de18ecc3 added still image support
bellard
parents:
diff changeset
67 } else if (!strcmp(buf1, "P5")) {
885
da1d5db0ce5c COSMETICS: Remove all trailing whitespace.
diego
parents: 320
diff changeset
68 if (allow_yuv)
20
3d52de18ecc3 added still image support
bellard
parents:
diff changeset
69 info->pix_fmt = PIX_FMT_YUV420P;
3d52de18ecc3 added still image support
bellard
parents:
diff changeset
70 else
3d52de18ecc3 added still image support
bellard
parents:
diff changeset
71 info->pix_fmt = PIX_FMT_GRAY8;
3d52de18ecc3 added still image support
bellard
parents:
diff changeset
72 } else if (!strcmp(buf1, "P6")) {
3d52de18ecc3 added still image support
bellard
parents:
diff changeset
73 info->pix_fmt = PIX_FMT_RGB24;
3d52de18ecc3 added still image support
bellard
parents:
diff changeset
74 } else {
3d52de18ecc3 added still image support
bellard
parents:
diff changeset
75 return AVERROR_INVALIDDATA;
3d52de18ecc3 added still image support
bellard
parents:
diff changeset
76 }
3d52de18ecc3 added still image support
bellard
parents:
diff changeset
77 pnm_get(f, buf1, sizeof(buf1));
3d52de18ecc3 added still image support
bellard
parents:
diff changeset
78 info->width = atoi(buf1);
3d52de18ecc3 added still image support
bellard
parents:
diff changeset
79 if (info->width <= 0)
3d52de18ecc3 added still image support
bellard
parents:
diff changeset
80 return AVERROR_INVALIDDATA;
3d52de18ecc3 added still image support
bellard
parents:
diff changeset
81 pnm_get(f, buf1, sizeof(buf1));
3d52de18ecc3 added still image support
bellard
parents:
diff changeset
82 info->height = atoi(buf1);
3d52de18ecc3 added still image support
bellard
parents:
diff changeset
83 if (info->height <= 0)
3d52de18ecc3 added still image support
bellard
parents:
diff changeset
84 return AVERROR_INVALIDDATA;
3d52de18ecc3 added still image support
bellard
parents:
diff changeset
85 if (info->pix_fmt != PIX_FMT_MONOWHITE) {
3d52de18ecc3 added still image support
bellard
parents:
diff changeset
86 pnm_get(f, buf1, sizeof(buf1));
3d52de18ecc3 added still image support
bellard
parents:
diff changeset
87 }
3d52de18ecc3 added still image support
bellard
parents:
diff changeset
88
3d52de18ecc3 added still image support
bellard
parents:
diff changeset
89 /* more check if YUV420 */
3d52de18ecc3 added still image support
bellard
parents:
diff changeset
90 if (info->pix_fmt == PIX_FMT_YUV420P) {
3d52de18ecc3 added still image support
bellard
parents:
diff changeset
91 if ((info->width & 1) != 0)
3d52de18ecc3 added still image support
bellard
parents:
diff changeset
92 return AVERROR_INVALIDDATA;
3d52de18ecc3 added still image support
bellard
parents:
diff changeset
93 h = (info->height * 2);
3d52de18ecc3 added still image support
bellard
parents:
diff changeset
94 if ((h % 3) != 0)
3d52de18ecc3 added still image support
bellard
parents:
diff changeset
95 return AVERROR_INVALIDDATA;
3d52de18ecc3 added still image support
bellard
parents:
diff changeset
96 h /= 3;
3d52de18ecc3 added still image support
bellard
parents:
diff changeset
97 info->height = h;
3d52de18ecc3 added still image support
bellard
parents:
diff changeset
98 }
885
da1d5db0ce5c COSMETICS: Remove all trailing whitespace.
diego
parents: 320
diff changeset
99
20
3d52de18ecc3 added still image support
bellard
parents:
diff changeset
100 ret = alloc_cb(opaque, info);
3d52de18ecc3 added still image support
bellard
parents:
diff changeset
101 if (ret)
3d52de18ecc3 added still image support
bellard
parents:
diff changeset
102 return ret;
885
da1d5db0ce5c COSMETICS: Remove all trailing whitespace.
diego
parents: 320
diff changeset
103
20
3d52de18ecc3 added still image support
bellard
parents:
diff changeset
104 switch(info->pix_fmt) {
3d52de18ecc3 added still image support
bellard
parents:
diff changeset
105 default:
3d52de18ecc3 added still image support
bellard
parents:
diff changeset
106 return AVERROR_INVALIDDATA;
3d52de18ecc3 added still image support
bellard
parents:
diff changeset
107 case PIX_FMT_RGB24:
3d52de18ecc3 added still image support
bellard
parents:
diff changeset
108 n = info->width * 3;
3d52de18ecc3 added still image support
bellard
parents:
diff changeset
109 goto do_read;
3d52de18ecc3 added still image support
bellard
parents:
diff changeset
110 case PIX_FMT_GRAY8:
3d52de18ecc3 added still image support
bellard
parents:
diff changeset
111 n = info->width;
3d52de18ecc3 added still image support
bellard
parents:
diff changeset
112 goto do_read;
3d52de18ecc3 added still image support
bellard
parents:
diff changeset
113 case PIX_FMT_MONOWHITE:
3d52de18ecc3 added still image support
bellard
parents:
diff changeset
114 n = (info->width + 7) >> 3;
3d52de18ecc3 added still image support
bellard
parents:
diff changeset
115 do_read:
3d52de18ecc3 added still image support
bellard
parents:
diff changeset
116 ptr = info->pict.data[0];
3d52de18ecc3 added still image support
bellard
parents:
diff changeset
117 linesize = info->pict.linesize[0];
3d52de18ecc3 added still image support
bellard
parents:
diff changeset
118 for(i = 0; i < info->height; i++) {
3d52de18ecc3 added still image support
bellard
parents:
diff changeset
119 get_buffer(f, ptr, n);
3d52de18ecc3 added still image support
bellard
parents:
diff changeset
120 ptr += linesize;
3d52de18ecc3 added still image support
bellard
parents:
diff changeset
121 }
3d52de18ecc3 added still image support
bellard
parents:
diff changeset
122 break;
3d52de18ecc3 added still image support
bellard
parents:
diff changeset
123 case PIX_FMT_YUV420P:
3d52de18ecc3 added still image support
bellard
parents:
diff changeset
124 {
3d52de18ecc3 added still image support
bellard
parents:
diff changeset
125 unsigned char *ptr1, *ptr2;
3d52de18ecc3 added still image support
bellard
parents:
diff changeset
126
3d52de18ecc3 added still image support
bellard
parents:
diff changeset
127 n = info->width;
3d52de18ecc3 added still image support
bellard
parents:
diff changeset
128 ptr = info->pict.data[0];
3d52de18ecc3 added still image support
bellard
parents:
diff changeset
129 linesize = info->pict.linesize[0];
3d52de18ecc3 added still image support
bellard
parents:
diff changeset
130 for(i = 0; i < info->height; i++) {
3d52de18ecc3 added still image support
bellard
parents:
diff changeset
131 get_buffer(f, ptr, n);
3d52de18ecc3 added still image support
bellard
parents:
diff changeset
132 ptr += linesize;
3d52de18ecc3 added still image support
bellard
parents:
diff changeset
133 }
3d52de18ecc3 added still image support
bellard
parents:
diff changeset
134 ptr1 = info->pict.data[1];
3d52de18ecc3 added still image support
bellard
parents:
diff changeset
135 ptr2 = info->pict.data[2];
3d52de18ecc3 added still image support
bellard
parents:
diff changeset
136 n >>= 1;
3d52de18ecc3 added still image support
bellard
parents:
diff changeset
137 h = info->height >> 1;
3d52de18ecc3 added still image support
bellard
parents:
diff changeset
138 for(i = 0; i < h; i++) {
3d52de18ecc3 added still image support
bellard
parents:
diff changeset
139 get_buffer(f, ptr1, n);
3d52de18ecc3 added still image support
bellard
parents:
diff changeset
140 get_buffer(f, ptr2, n);
3d52de18ecc3 added still image support
bellard
parents:
diff changeset
141 ptr1 += info->pict.linesize[1];
3d52de18ecc3 added still image support
bellard
parents:
diff changeset
142 ptr2 += info->pict.linesize[2];
3d52de18ecc3 added still image support
bellard
parents:
diff changeset
143 }
3d52de18ecc3 added still image support
bellard
parents:
diff changeset
144 }
3d52de18ecc3 added still image support
bellard
parents:
diff changeset
145 break;
3d52de18ecc3 added still image support
bellard
parents:
diff changeset
146 }
3d52de18ecc3 added still image support
bellard
parents:
diff changeset
147 return 0;
3d52de18ecc3 added still image support
bellard
parents:
diff changeset
148 }
3d52de18ecc3 added still image support
bellard
parents:
diff changeset
149
885
da1d5db0ce5c COSMETICS: Remove all trailing whitespace.
diego
parents: 320
diff changeset
150 static int pnm_read(ByteIOContext *f,
20
3d52de18ecc3 added still image support
bellard
parents:
diff changeset
151 int (*alloc_cb)(void *opaque, AVImageInfo *info), void *opaque)
3d52de18ecc3 added still image support
bellard
parents:
diff changeset
152 {
3d52de18ecc3 added still image support
bellard
parents:
diff changeset
153 return pnm_read1(f, alloc_cb, opaque, 0);
3d52de18ecc3 added still image support
bellard
parents:
diff changeset
154 }
3d52de18ecc3 added still image support
bellard
parents:
diff changeset
155
885
da1d5db0ce5c COSMETICS: Remove all trailing whitespace.
diego
parents: 320
diff changeset
156 static int pgmyuv_read(ByteIOContext *f,
20
3d52de18ecc3 added still image support
bellard
parents:
diff changeset
157 int (*alloc_cb)(void *opaque, AVImageInfo *info), void *opaque)
3d52de18ecc3 added still image support
bellard
parents:
diff changeset
158 {
3d52de18ecc3 added still image support
bellard
parents:
diff changeset
159 return pnm_read1(f, alloc_cb, opaque, 1);
3d52de18ecc3 added still image support
bellard
parents:
diff changeset
160 }
3d52de18ecc3 added still image support
bellard
parents:
diff changeset
161
3d52de18ecc3 added still image support
bellard
parents:
diff changeset
162 static int pnm_write(ByteIOContext *pb, AVImageInfo *info)
3d52de18ecc3 added still image support
bellard
parents:
diff changeset
163 {
3d52de18ecc3 added still image support
bellard
parents:
diff changeset
164 int i, h, h1, c, n, linesize;
3d52de18ecc3 added still image support
bellard
parents:
diff changeset
165 char buf[100];
65
a58a8a53eb46 * UINTX -> uintx_t INTX -> intx_t
kabi
parents: 20
diff changeset
166 uint8_t *ptr, *ptr1, *ptr2;
20
3d52de18ecc3 added still image support
bellard
parents:
diff changeset
167
3d52de18ecc3 added still image support
bellard
parents:
diff changeset
168 h = info->height;
3d52de18ecc3 added still image support
bellard
parents:
diff changeset
169 h1 = h;
3d52de18ecc3 added still image support
bellard
parents:
diff changeset
170 switch(info->pix_fmt) {
3d52de18ecc3 added still image support
bellard
parents:
diff changeset
171 case PIX_FMT_MONOWHITE:
3d52de18ecc3 added still image support
bellard
parents:
diff changeset
172 c = '4';
3d52de18ecc3 added still image support
bellard
parents:
diff changeset
173 n = (info->width + 7) >> 3;
3d52de18ecc3 added still image support
bellard
parents:
diff changeset
174 break;
3d52de18ecc3 added still image support
bellard
parents:
diff changeset
175 case PIX_FMT_GRAY8:
3d52de18ecc3 added still image support
bellard
parents:
diff changeset
176 c = '5';
3d52de18ecc3 added still image support
bellard
parents:
diff changeset
177 n = info->width;
3d52de18ecc3 added still image support
bellard
parents:
diff changeset
178 break;
3d52de18ecc3 added still image support
bellard
parents:
diff changeset
179 case PIX_FMT_RGB24:
3d52de18ecc3 added still image support
bellard
parents:
diff changeset
180 c = '6';
3d52de18ecc3 added still image support
bellard
parents:
diff changeset
181 n = info->width * 3;
3d52de18ecc3 added still image support
bellard
parents:
diff changeset
182 break;
3d52de18ecc3 added still image support
bellard
parents:
diff changeset
183 case PIX_FMT_YUV420P:
3d52de18ecc3 added still image support
bellard
parents:
diff changeset
184 c = '5';
3d52de18ecc3 added still image support
bellard
parents:
diff changeset
185 n = info->width;
3d52de18ecc3 added still image support
bellard
parents:
diff changeset
186 h1 = (h * 3) / 2;
3d52de18ecc3 added still image support
bellard
parents:
diff changeset
187 break;
3d52de18ecc3 added still image support
bellard
parents:
diff changeset
188 default:
3d52de18ecc3 added still image support
bellard
parents:
diff changeset
189 return AVERROR_INVALIDDATA;
3d52de18ecc3 added still image support
bellard
parents:
diff changeset
190 }
885
da1d5db0ce5c COSMETICS: Remove all trailing whitespace.
diego
parents: 320
diff changeset
191 snprintf(buf, sizeof(buf),
20
3d52de18ecc3 added still image support
bellard
parents:
diff changeset
192 "P%c\n%d %d\n",
3d52de18ecc3 added still image support
bellard
parents:
diff changeset
193 c, info->width, h1);
3d52de18ecc3 added still image support
bellard
parents:
diff changeset
194 put_buffer(pb, buf, strlen(buf));
3d52de18ecc3 added still image support
bellard
parents:
diff changeset
195 if (info->pix_fmt != PIX_FMT_MONOWHITE) {
885
da1d5db0ce5c COSMETICS: Remove all trailing whitespace.
diego
parents: 320
diff changeset
196 snprintf(buf, sizeof(buf),
20
3d52de18ecc3 added still image support
bellard
parents:
diff changeset
197 "%d\n", 255);
3d52de18ecc3 added still image support
bellard
parents:
diff changeset
198 put_buffer(pb, buf, strlen(buf));
3d52de18ecc3 added still image support
bellard
parents:
diff changeset
199 }
885
da1d5db0ce5c COSMETICS: Remove all trailing whitespace.
diego
parents: 320
diff changeset
200
20
3d52de18ecc3 added still image support
bellard
parents:
diff changeset
201 ptr = info->pict.data[0];
3d52de18ecc3 added still image support
bellard
parents:
diff changeset
202 linesize = info->pict.linesize[0];
3d52de18ecc3 added still image support
bellard
parents:
diff changeset
203 for(i=0;i<h;i++) {
3d52de18ecc3 added still image support
bellard
parents:
diff changeset
204 put_buffer(pb, ptr, n);
3d52de18ecc3 added still image support
bellard
parents:
diff changeset
205 ptr += linesize;
3d52de18ecc3 added still image support
bellard
parents:
diff changeset
206 }
885
da1d5db0ce5c COSMETICS: Remove all trailing whitespace.
diego
parents: 320
diff changeset
207
20
3d52de18ecc3 added still image support
bellard
parents:
diff changeset
208 if (info->pix_fmt == PIX_FMT_YUV420P) {
3d52de18ecc3 added still image support
bellard
parents:
diff changeset
209 h >>= 1;
3d52de18ecc3 added still image support
bellard
parents:
diff changeset
210 n >>= 1;
3d52de18ecc3 added still image support
bellard
parents:
diff changeset
211 ptr1 = info->pict.data[1];
3d52de18ecc3 added still image support
bellard
parents:
diff changeset
212 ptr2 = info->pict.data[2];
3d52de18ecc3 added still image support
bellard
parents:
diff changeset
213 for(i=0;i<h;i++) {
3d52de18ecc3 added still image support
bellard
parents:
diff changeset
214 put_buffer(pb, ptr1, n);
3d52de18ecc3 added still image support
bellard
parents:
diff changeset
215 put_buffer(pb, ptr2, n);
109
c82a6062485e added new netpbm pam format support (needed for alpha plane support)
bellard
parents: 65
diff changeset
216 ptr1 += info->pict.linesize[1];
c82a6062485e added new netpbm pam format support (needed for alpha plane support)
bellard
parents: 65
diff changeset
217 ptr2 += info->pict.linesize[2];
20
3d52de18ecc3 added still image support
bellard
parents:
diff changeset
218 }
3d52de18ecc3 added still image support
bellard
parents:
diff changeset
219 }
3d52de18ecc3 added still image support
bellard
parents:
diff changeset
220 put_flush_packet(pb);
3d52de18ecc3 added still image support
bellard
parents:
diff changeset
221 return 0;
3d52de18ecc3 added still image support
bellard
parents:
diff changeset
222 }
109
c82a6062485e added new netpbm pam format support (needed for alpha plane support)
bellard
parents: 65
diff changeset
223
885
da1d5db0ce5c COSMETICS: Remove all trailing whitespace.
diego
parents: 320
diff changeset
224 static int pam_read(ByteIOContext *f,
109
c82a6062485e added new netpbm pam format support (needed for alpha plane support)
bellard
parents: 65
diff changeset
225 int (*alloc_cb)(void *opaque, AVImageInfo *info), void *opaque)
c82a6062485e added new netpbm pam format support (needed for alpha plane support)
bellard
parents: 65
diff changeset
226 {
c82a6062485e added new netpbm pam format support (needed for alpha plane support)
bellard
parents: 65
diff changeset
227 int i, n, linesize, h, w, depth, maxval;
c82a6062485e added new netpbm pam format support (needed for alpha plane support)
bellard
parents: 65
diff changeset
228 char buf1[32], tuple_type[32];
c82a6062485e added new netpbm pam format support (needed for alpha plane support)
bellard
parents: 65
diff changeset
229 unsigned char *ptr;
c82a6062485e added new netpbm pam format support (needed for alpha plane support)
bellard
parents: 65
diff changeset
230 AVImageInfo info1, *info = &info1;
c82a6062485e added new netpbm pam format support (needed for alpha plane support)
bellard
parents: 65
diff changeset
231 int ret;
c82a6062485e added new netpbm pam format support (needed for alpha plane support)
bellard
parents: 65
diff changeset
232
c82a6062485e added new netpbm pam format support (needed for alpha plane support)
bellard
parents: 65
diff changeset
233 pnm_get(f, buf1, sizeof(buf1));
c82a6062485e added new netpbm pam format support (needed for alpha plane support)
bellard
parents: 65
diff changeset
234 if (strcmp(buf1, "P7") != 0)
c82a6062485e added new netpbm pam format support (needed for alpha plane support)
bellard
parents: 65
diff changeset
235 return AVERROR_INVALIDDATA;
c82a6062485e added new netpbm pam format support (needed for alpha plane support)
bellard
parents: 65
diff changeset
236 w = -1;
c82a6062485e added new netpbm pam format support (needed for alpha plane support)
bellard
parents: 65
diff changeset
237 h = -1;
c82a6062485e added new netpbm pam format support (needed for alpha plane support)
bellard
parents: 65
diff changeset
238 maxval = -1;
c82a6062485e added new netpbm pam format support (needed for alpha plane support)
bellard
parents: 65
diff changeset
239 depth = -1;
c82a6062485e added new netpbm pam format support (needed for alpha plane support)
bellard
parents: 65
diff changeset
240 tuple_type[0] = '\0';
c82a6062485e added new netpbm pam format support (needed for alpha plane support)
bellard
parents: 65
diff changeset
241 for(;;) {
c82a6062485e added new netpbm pam format support (needed for alpha plane support)
bellard
parents: 65
diff changeset
242 pnm_get(f, buf1, sizeof(buf1));
c82a6062485e added new netpbm pam format support (needed for alpha plane support)
bellard
parents: 65
diff changeset
243 if (!strcmp(buf1, "WIDTH")) {
c82a6062485e added new netpbm pam format support (needed for alpha plane support)
bellard
parents: 65
diff changeset
244 pnm_get(f, buf1, sizeof(buf1));
c82a6062485e added new netpbm pam format support (needed for alpha plane support)
bellard
parents: 65
diff changeset
245 w = strtol(buf1, NULL, 10);
c82a6062485e added new netpbm pam format support (needed for alpha plane support)
bellard
parents: 65
diff changeset
246 } else if (!strcmp(buf1, "HEIGHT")) {
c82a6062485e added new netpbm pam format support (needed for alpha plane support)
bellard
parents: 65
diff changeset
247 pnm_get(f, buf1, sizeof(buf1));
c82a6062485e added new netpbm pam format support (needed for alpha plane support)
bellard
parents: 65
diff changeset
248 h = strtol(buf1, NULL, 10);
c82a6062485e added new netpbm pam format support (needed for alpha plane support)
bellard
parents: 65
diff changeset
249 } else if (!strcmp(buf1, "DEPTH")) {
c82a6062485e added new netpbm pam format support (needed for alpha plane support)
bellard
parents: 65
diff changeset
250 pnm_get(f, buf1, sizeof(buf1));
c82a6062485e added new netpbm pam format support (needed for alpha plane support)
bellard
parents: 65
diff changeset
251 depth = strtol(buf1, NULL, 10);
c82a6062485e added new netpbm pam format support (needed for alpha plane support)
bellard
parents: 65
diff changeset
252 } else if (!strcmp(buf1, "MAXVAL")) {
c82a6062485e added new netpbm pam format support (needed for alpha plane support)
bellard
parents: 65
diff changeset
253 pnm_get(f, buf1, sizeof(buf1));
c82a6062485e added new netpbm pam format support (needed for alpha plane support)
bellard
parents: 65
diff changeset
254 maxval = strtol(buf1, NULL, 10);
c82a6062485e added new netpbm pam format support (needed for alpha plane support)
bellard
parents: 65
diff changeset
255 } else if (!strcmp(buf1, "TUPLETYPE")) {
c82a6062485e added new netpbm pam format support (needed for alpha plane support)
bellard
parents: 65
diff changeset
256 pnm_get(f, buf1, sizeof(buf1));
c82a6062485e added new netpbm pam format support (needed for alpha plane support)
bellard
parents: 65
diff changeset
257 pstrcpy(tuple_type, sizeof(tuple_type), buf1);
c82a6062485e added new netpbm pam format support (needed for alpha plane support)
bellard
parents: 65
diff changeset
258 } else if (!strcmp(buf1, "ENDHDR")) {
c82a6062485e added new netpbm pam format support (needed for alpha plane support)
bellard
parents: 65
diff changeset
259 break;
c82a6062485e added new netpbm pam format support (needed for alpha plane support)
bellard
parents: 65
diff changeset
260 } else {
c82a6062485e added new netpbm pam format support (needed for alpha plane support)
bellard
parents: 65
diff changeset
261 return AVERROR_INVALIDDATA;
c82a6062485e added new netpbm pam format support (needed for alpha plane support)
bellard
parents: 65
diff changeset
262 }
c82a6062485e added new netpbm pam format support (needed for alpha plane support)
bellard
parents: 65
diff changeset
263 }
c82a6062485e added new netpbm pam format support (needed for alpha plane support)
bellard
parents: 65
diff changeset
264 /* check that all tags are present */
c82a6062485e added new netpbm pam format support (needed for alpha plane support)
bellard
parents: 65
diff changeset
265 if (w <= 0 || h <= 0 || maxval <= 0 || depth <= 0 || tuple_type[0] == '\0')
c82a6062485e added new netpbm pam format support (needed for alpha plane support)
bellard
parents: 65
diff changeset
266 return AVERROR_INVALIDDATA;
c82a6062485e added new netpbm pam format support (needed for alpha plane support)
bellard
parents: 65
diff changeset
267 info->width = w;
c82a6062485e added new netpbm pam format support (needed for alpha plane support)
bellard
parents: 65
diff changeset
268 info->height = h;
c82a6062485e added new netpbm pam format support (needed for alpha plane support)
bellard
parents: 65
diff changeset
269 if (depth == 1) {
c82a6062485e added new netpbm pam format support (needed for alpha plane support)
bellard
parents: 65
diff changeset
270 if (maxval == 1)
c82a6062485e added new netpbm pam format support (needed for alpha plane support)
bellard
parents: 65
diff changeset
271 info->pix_fmt = PIX_FMT_MONOWHITE;
885
da1d5db0ce5c COSMETICS: Remove all trailing whitespace.
diego
parents: 320
diff changeset
272 else
109
c82a6062485e added new netpbm pam format support (needed for alpha plane support)
bellard
parents: 65
diff changeset
273 info->pix_fmt = PIX_FMT_GRAY8;
c82a6062485e added new netpbm pam format support (needed for alpha plane support)
bellard
parents: 65
diff changeset
274 } else if (depth == 3) {
c82a6062485e added new netpbm pam format support (needed for alpha plane support)
bellard
parents: 65
diff changeset
275 info->pix_fmt = PIX_FMT_RGB24;
c82a6062485e added new netpbm pam format support (needed for alpha plane support)
bellard
parents: 65
diff changeset
276 } else if (depth == 4) {
c82a6062485e added new netpbm pam format support (needed for alpha plane support)
bellard
parents: 65
diff changeset
277 info->pix_fmt = PIX_FMT_RGBA32;
c82a6062485e added new netpbm pam format support (needed for alpha plane support)
bellard
parents: 65
diff changeset
278 } else {
c82a6062485e added new netpbm pam format support (needed for alpha plane support)
bellard
parents: 65
diff changeset
279 return AVERROR_INVALIDDATA;
c82a6062485e added new netpbm pam format support (needed for alpha plane support)
bellard
parents: 65
diff changeset
280 }
c82a6062485e added new netpbm pam format support (needed for alpha plane support)
bellard
parents: 65
diff changeset
281 ret = alloc_cb(opaque, info);
c82a6062485e added new netpbm pam format support (needed for alpha plane support)
bellard
parents: 65
diff changeset
282 if (ret)
c82a6062485e added new netpbm pam format support (needed for alpha plane support)
bellard
parents: 65
diff changeset
283 return ret;
885
da1d5db0ce5c COSMETICS: Remove all trailing whitespace.
diego
parents: 320
diff changeset
284
109
c82a6062485e added new netpbm pam format support (needed for alpha plane support)
bellard
parents: 65
diff changeset
285 switch(info->pix_fmt) {
c82a6062485e added new netpbm pam format support (needed for alpha plane support)
bellard
parents: 65
diff changeset
286 default:
c82a6062485e added new netpbm pam format support (needed for alpha plane support)
bellard
parents: 65
diff changeset
287 return AVERROR_INVALIDDATA;
c82a6062485e added new netpbm pam format support (needed for alpha plane support)
bellard
parents: 65
diff changeset
288 case PIX_FMT_RGB24:
c82a6062485e added new netpbm pam format support (needed for alpha plane support)
bellard
parents: 65
diff changeset
289 n = info->width * 3;
c82a6062485e added new netpbm pam format support (needed for alpha plane support)
bellard
parents: 65
diff changeset
290 goto do_read;
c82a6062485e added new netpbm pam format support (needed for alpha plane support)
bellard
parents: 65
diff changeset
291 case PIX_FMT_GRAY8:
c82a6062485e added new netpbm pam format support (needed for alpha plane support)
bellard
parents: 65
diff changeset
292 n = info->width;
c82a6062485e added new netpbm pam format support (needed for alpha plane support)
bellard
parents: 65
diff changeset
293 goto do_read;
c82a6062485e added new netpbm pam format support (needed for alpha plane support)
bellard
parents: 65
diff changeset
294 case PIX_FMT_MONOWHITE:
c82a6062485e added new netpbm pam format support (needed for alpha plane support)
bellard
parents: 65
diff changeset
295 n = (info->width + 7) >> 3;
c82a6062485e added new netpbm pam format support (needed for alpha plane support)
bellard
parents: 65
diff changeset
296 do_read:
c82a6062485e added new netpbm pam format support (needed for alpha plane support)
bellard
parents: 65
diff changeset
297 ptr = info->pict.data[0];
c82a6062485e added new netpbm pam format support (needed for alpha plane support)
bellard
parents: 65
diff changeset
298 linesize = info->pict.linesize[0];
c82a6062485e added new netpbm pam format support (needed for alpha plane support)
bellard
parents: 65
diff changeset
299 for(i = 0; i < info->height; i++) {
c82a6062485e added new netpbm pam format support (needed for alpha plane support)
bellard
parents: 65
diff changeset
300 get_buffer(f, ptr, n);
c82a6062485e added new netpbm pam format support (needed for alpha plane support)
bellard
parents: 65
diff changeset
301 ptr += linesize;
c82a6062485e added new netpbm pam format support (needed for alpha plane support)
bellard
parents: 65
diff changeset
302 }
c82a6062485e added new netpbm pam format support (needed for alpha plane support)
bellard
parents: 65
diff changeset
303 break;
c82a6062485e added new netpbm pam format support (needed for alpha plane support)
bellard
parents: 65
diff changeset
304 case PIX_FMT_RGBA32:
c82a6062485e added new netpbm pam format support (needed for alpha plane support)
bellard
parents: 65
diff changeset
305 ptr = info->pict.data[0];
c82a6062485e added new netpbm pam format support (needed for alpha plane support)
bellard
parents: 65
diff changeset
306 linesize = info->pict.linesize[0];
c82a6062485e added new netpbm pam format support (needed for alpha plane support)
bellard
parents: 65
diff changeset
307 for(i = 0; i < info->height; i++) {
c82a6062485e added new netpbm pam format support (needed for alpha plane support)
bellard
parents: 65
diff changeset
308 int j, r, g, b, a;
c82a6062485e added new netpbm pam format support (needed for alpha plane support)
bellard
parents: 65
diff changeset
309
c82a6062485e added new netpbm pam format support (needed for alpha plane support)
bellard
parents: 65
diff changeset
310 for(j = 0;j < w; j++) {
c82a6062485e added new netpbm pam format support (needed for alpha plane support)
bellard
parents: 65
diff changeset
311 r = get_byte(f);
c82a6062485e added new netpbm pam format support (needed for alpha plane support)
bellard
parents: 65
diff changeset
312 g = get_byte(f);
c82a6062485e added new netpbm pam format support (needed for alpha plane support)
bellard
parents: 65
diff changeset
313 b = get_byte(f);
c82a6062485e added new netpbm pam format support (needed for alpha plane support)
bellard
parents: 65
diff changeset
314 a = get_byte(f);
c82a6062485e added new netpbm pam format support (needed for alpha plane support)
bellard
parents: 65
diff changeset
315 ((uint32_t *)ptr)[j] = (a << 24) | (r << 16) | (g << 8) | b;
c82a6062485e added new netpbm pam format support (needed for alpha plane support)
bellard
parents: 65
diff changeset
316 }
c82a6062485e added new netpbm pam format support (needed for alpha plane support)
bellard
parents: 65
diff changeset
317 ptr += linesize;
c82a6062485e added new netpbm pam format support (needed for alpha plane support)
bellard
parents: 65
diff changeset
318 }
c82a6062485e added new netpbm pam format support (needed for alpha plane support)
bellard
parents: 65
diff changeset
319 break;
c82a6062485e added new netpbm pam format support (needed for alpha plane support)
bellard
parents: 65
diff changeset
320 }
c82a6062485e added new netpbm pam format support (needed for alpha plane support)
bellard
parents: 65
diff changeset
321 return 0;
c82a6062485e added new netpbm pam format support (needed for alpha plane support)
bellard
parents: 65
diff changeset
322 }
c82a6062485e added new netpbm pam format support (needed for alpha plane support)
bellard
parents: 65
diff changeset
323
c82a6062485e added new netpbm pam format support (needed for alpha plane support)
bellard
parents: 65
diff changeset
324 static int pam_write(ByteIOContext *pb, AVImageInfo *info)
c82a6062485e added new netpbm pam format support (needed for alpha plane support)
bellard
parents: 65
diff changeset
325 {
c82a6062485e added new netpbm pam format support (needed for alpha plane support)
bellard
parents: 65
diff changeset
326 int i, h, w, n, linesize, depth, maxval;
c82a6062485e added new netpbm pam format support (needed for alpha plane support)
bellard
parents: 65
diff changeset
327 const char *tuple_type;
c82a6062485e added new netpbm pam format support (needed for alpha plane support)
bellard
parents: 65
diff changeset
328 char buf[100];
c82a6062485e added new netpbm pam format support (needed for alpha plane support)
bellard
parents: 65
diff changeset
329 uint8_t *ptr;
c82a6062485e added new netpbm pam format support (needed for alpha plane support)
bellard
parents: 65
diff changeset
330
c82a6062485e added new netpbm pam format support (needed for alpha plane support)
bellard
parents: 65
diff changeset
331 h = info->height;
c82a6062485e added new netpbm pam format support (needed for alpha plane support)
bellard
parents: 65
diff changeset
332 w = info->width;
c82a6062485e added new netpbm pam format support (needed for alpha plane support)
bellard
parents: 65
diff changeset
333 switch(info->pix_fmt) {
c82a6062485e added new netpbm pam format support (needed for alpha plane support)
bellard
parents: 65
diff changeset
334 case PIX_FMT_MONOWHITE:
c82a6062485e added new netpbm pam format support (needed for alpha plane support)
bellard
parents: 65
diff changeset
335 n = (info->width + 7) >> 3;
c82a6062485e added new netpbm pam format support (needed for alpha plane support)
bellard
parents: 65
diff changeset
336 depth = 1;
c82a6062485e added new netpbm pam format support (needed for alpha plane support)
bellard
parents: 65
diff changeset
337 maxval = 1;
c82a6062485e added new netpbm pam format support (needed for alpha plane support)
bellard
parents: 65
diff changeset
338 tuple_type = "BLACKANDWHITE";
c82a6062485e added new netpbm pam format support (needed for alpha plane support)
bellard
parents: 65
diff changeset
339 break;
c82a6062485e added new netpbm pam format support (needed for alpha plane support)
bellard
parents: 65
diff changeset
340 case PIX_FMT_GRAY8:
c82a6062485e added new netpbm pam format support (needed for alpha plane support)
bellard
parents: 65
diff changeset
341 n = info->width;
c82a6062485e added new netpbm pam format support (needed for alpha plane support)
bellard
parents: 65
diff changeset
342 depth = 1;
c82a6062485e added new netpbm pam format support (needed for alpha plane support)
bellard
parents: 65
diff changeset
343 maxval = 255;
c82a6062485e added new netpbm pam format support (needed for alpha plane support)
bellard
parents: 65
diff changeset
344 tuple_type = "GRAYSCALE";
c82a6062485e added new netpbm pam format support (needed for alpha plane support)
bellard
parents: 65
diff changeset
345 break;
c82a6062485e added new netpbm pam format support (needed for alpha plane support)
bellard
parents: 65
diff changeset
346 case PIX_FMT_RGB24:
c82a6062485e added new netpbm pam format support (needed for alpha plane support)
bellard
parents: 65
diff changeset
347 n = info->width * 3;
c82a6062485e added new netpbm pam format support (needed for alpha plane support)
bellard
parents: 65
diff changeset
348 depth = 3;
c82a6062485e added new netpbm pam format support (needed for alpha plane support)
bellard
parents: 65
diff changeset
349 maxval = 255;
c82a6062485e added new netpbm pam format support (needed for alpha plane support)
bellard
parents: 65
diff changeset
350 tuple_type = "RGB";
c82a6062485e added new netpbm pam format support (needed for alpha plane support)
bellard
parents: 65
diff changeset
351 break;
c82a6062485e added new netpbm pam format support (needed for alpha plane support)
bellard
parents: 65
diff changeset
352 case PIX_FMT_RGBA32:
c82a6062485e added new netpbm pam format support (needed for alpha plane support)
bellard
parents: 65
diff changeset
353 n = info->width * 4;
c82a6062485e added new netpbm pam format support (needed for alpha plane support)
bellard
parents: 65
diff changeset
354 depth = 4;
c82a6062485e added new netpbm pam format support (needed for alpha plane support)
bellard
parents: 65
diff changeset
355 maxval = 255;
c82a6062485e added new netpbm pam format support (needed for alpha plane support)
bellard
parents: 65
diff changeset
356 tuple_type = "RGB_ALPHA";
c82a6062485e added new netpbm pam format support (needed for alpha plane support)
bellard
parents: 65
diff changeset
357 break;
c82a6062485e added new netpbm pam format support (needed for alpha plane support)
bellard
parents: 65
diff changeset
358 default:
c82a6062485e added new netpbm pam format support (needed for alpha plane support)
bellard
parents: 65
diff changeset
359 return AVERROR_INVALIDDATA;
c82a6062485e added new netpbm pam format support (needed for alpha plane support)
bellard
parents: 65
diff changeset
360 }
885
da1d5db0ce5c COSMETICS: Remove all trailing whitespace.
diego
parents: 320
diff changeset
361 snprintf(buf, sizeof(buf),
109
c82a6062485e added new netpbm pam format support (needed for alpha plane support)
bellard
parents: 65
diff changeset
362 "P7\nWIDTH %d\nHEIGHT %d\nDEPTH %d\nMAXVAL %d\nTUPLETYPE %s\nENDHDR\n",
c82a6062485e added new netpbm pam format support (needed for alpha plane support)
bellard
parents: 65
diff changeset
363 w, h, depth, maxval, tuple_type);
c82a6062485e added new netpbm pam format support (needed for alpha plane support)
bellard
parents: 65
diff changeset
364 put_buffer(pb, buf, strlen(buf));
885
da1d5db0ce5c COSMETICS: Remove all trailing whitespace.
diego
parents: 320
diff changeset
365
109
c82a6062485e added new netpbm pam format support (needed for alpha plane support)
bellard
parents: 65
diff changeset
366 ptr = info->pict.data[0];
c82a6062485e added new netpbm pam format support (needed for alpha plane support)
bellard
parents: 65
diff changeset
367 linesize = info->pict.linesize[0];
885
da1d5db0ce5c COSMETICS: Remove all trailing whitespace.
diego
parents: 320
diff changeset
368
109
c82a6062485e added new netpbm pam format support (needed for alpha plane support)
bellard
parents: 65
diff changeset
369 if (info->pix_fmt == PIX_FMT_RGBA32) {
c82a6062485e added new netpbm pam format support (needed for alpha plane support)
bellard
parents: 65
diff changeset
370 int j;
c82a6062485e added new netpbm pam format support (needed for alpha plane support)
bellard
parents: 65
diff changeset
371 unsigned int v;
c82a6062485e added new netpbm pam format support (needed for alpha plane support)
bellard
parents: 65
diff changeset
372
c82a6062485e added new netpbm pam format support (needed for alpha plane support)
bellard
parents: 65
diff changeset
373 for(i=0;i<h;i++) {
c82a6062485e added new netpbm pam format support (needed for alpha plane support)
bellard
parents: 65
diff changeset
374 for(j=0;j<w;j++) {
c82a6062485e added new netpbm pam format support (needed for alpha plane support)
bellard
parents: 65
diff changeset
375 v = ((uint32_t *)ptr)[j];
c82a6062485e added new netpbm pam format support (needed for alpha plane support)
bellard
parents: 65
diff changeset
376 put_byte(pb, (v >> 16) & 0xff);
c82a6062485e added new netpbm pam format support (needed for alpha plane support)
bellard
parents: 65
diff changeset
377 put_byte(pb, (v >> 8) & 0xff);
c82a6062485e added new netpbm pam format support (needed for alpha plane support)
bellard
parents: 65
diff changeset
378 put_byte(pb, (v) & 0xff);
c82a6062485e added new netpbm pam format support (needed for alpha plane support)
bellard
parents: 65
diff changeset
379 put_byte(pb, (v >> 24) & 0xff);
c82a6062485e added new netpbm pam format support (needed for alpha plane support)
bellard
parents: 65
diff changeset
380 }
c82a6062485e added new netpbm pam format support (needed for alpha plane support)
bellard
parents: 65
diff changeset
381 ptr += linesize;
c82a6062485e added new netpbm pam format support (needed for alpha plane support)
bellard
parents: 65
diff changeset
382 }
c82a6062485e added new netpbm pam format support (needed for alpha plane support)
bellard
parents: 65
diff changeset
383 } else {
c82a6062485e added new netpbm pam format support (needed for alpha plane support)
bellard
parents: 65
diff changeset
384 for(i=0;i<h;i++) {
c82a6062485e added new netpbm pam format support (needed for alpha plane support)
bellard
parents: 65
diff changeset
385 put_buffer(pb, ptr, n);
c82a6062485e added new netpbm pam format support (needed for alpha plane support)
bellard
parents: 65
diff changeset
386 ptr += linesize;
c82a6062485e added new netpbm pam format support (needed for alpha plane support)
bellard
parents: 65
diff changeset
387 }
c82a6062485e added new netpbm pam format support (needed for alpha plane support)
bellard
parents: 65
diff changeset
388 }
c82a6062485e added new netpbm pam format support (needed for alpha plane support)
bellard
parents: 65
diff changeset
389 put_flush_packet(pb);
c82a6062485e added new netpbm pam format support (needed for alpha plane support)
bellard
parents: 65
diff changeset
390 return 0;
c82a6062485e added new netpbm pam format support (needed for alpha plane support)
bellard
parents: 65
diff changeset
391 }
c82a6062485e added new netpbm pam format support (needed for alpha plane support)
bellard
parents: 65
diff changeset
392
20
3d52de18ecc3 added still image support
bellard
parents:
diff changeset
393 static int pnm_probe(AVProbeData *pd)
3d52de18ecc3 added still image support
bellard
parents:
diff changeset
394 {
3d52de18ecc3 added still image support
bellard
parents:
diff changeset
395 const char *p = pd->buf;
3d52de18ecc3 added still image support
bellard
parents:
diff changeset
396 if (pd->buf_size >= 8 &&
3d52de18ecc3 added still image support
bellard
parents:
diff changeset
397 p[0] == 'P' &&
3d52de18ecc3 added still image support
bellard
parents:
diff changeset
398 p[1] >= '4' && p[1] <= '6' &&
320
4b01f2d7a90c Patch for PPM probing by (Rob Joyce <rjoyce at twcny dot rr dot com>)
michael
parents: 200
diff changeset
399 pnm_space(p[2]) )
200
c0d49b5d246c accepts pgmyuv extension
bellard
parents: 109
diff changeset
400 return AVPROBE_SCORE_MAX - 1; /* to permit pgmyuv probe */
20
3d52de18ecc3 added still image support
bellard
parents:
diff changeset
401 else
3d52de18ecc3 added still image support
bellard
parents:
diff changeset
402 return 0;
3d52de18ecc3 added still image support
bellard
parents:
diff changeset
403 }
3d52de18ecc3 added still image support
bellard
parents:
diff changeset
404
3d52de18ecc3 added still image support
bellard
parents:
diff changeset
405 static int pgmyuv_probe(AVProbeData *pd)
3d52de18ecc3 added still image support
bellard
parents:
diff changeset
406 {
3d52de18ecc3 added still image support
bellard
parents:
diff changeset
407 if (match_ext(pd->filename, "pgmyuv"))
3d52de18ecc3 added still image support
bellard
parents:
diff changeset
408 return AVPROBE_SCORE_MAX;
3d52de18ecc3 added still image support
bellard
parents:
diff changeset
409 else
3d52de18ecc3 added still image support
bellard
parents:
diff changeset
410 return 0;
3d52de18ecc3 added still image support
bellard
parents:
diff changeset
411 }
3d52de18ecc3 added still image support
bellard
parents:
diff changeset
412
109
c82a6062485e added new netpbm pam format support (needed for alpha plane support)
bellard
parents: 65
diff changeset
413 static int pam_probe(AVProbeData *pd)
c82a6062485e added new netpbm pam format support (needed for alpha plane support)
bellard
parents: 65
diff changeset
414 {
c82a6062485e added new netpbm pam format support (needed for alpha plane support)
bellard
parents: 65
diff changeset
415 const char *p = pd->buf;
c82a6062485e added new netpbm pam format support (needed for alpha plane support)
bellard
parents: 65
diff changeset
416 if (pd->buf_size >= 8 &&
c82a6062485e added new netpbm pam format support (needed for alpha plane support)
bellard
parents: 65
diff changeset
417 p[0] == 'P' &&
c82a6062485e added new netpbm pam format support (needed for alpha plane support)
bellard
parents: 65
diff changeset
418 p[1] == '7' &&
c82a6062485e added new netpbm pam format support (needed for alpha plane support)
bellard
parents: 65
diff changeset
419 p[2] == '\n')
c82a6062485e added new netpbm pam format support (needed for alpha plane support)
bellard
parents: 65
diff changeset
420 return AVPROBE_SCORE_MAX;
c82a6062485e added new netpbm pam format support (needed for alpha plane support)
bellard
parents: 65
diff changeset
421 else
c82a6062485e added new netpbm pam format support (needed for alpha plane support)
bellard
parents: 65
diff changeset
422 return 0;
c82a6062485e added new netpbm pam format support (needed for alpha plane support)
bellard
parents: 65
diff changeset
423 }
c82a6062485e added new netpbm pam format support (needed for alpha plane support)
bellard
parents: 65
diff changeset
424
20
3d52de18ecc3 added still image support
bellard
parents:
diff changeset
425 AVImageFormat pnm_image_format = {
3d52de18ecc3 added still image support
bellard
parents:
diff changeset
426 "pnm",
3d52de18ecc3 added still image support
bellard
parents:
diff changeset
427 NULL,
3d52de18ecc3 added still image support
bellard
parents:
diff changeset
428 pnm_probe,
3d52de18ecc3 added still image support
bellard
parents:
diff changeset
429 pnm_read,
3d52de18ecc3 added still image support
bellard
parents:
diff changeset
430 0,
3d52de18ecc3 added still image support
bellard
parents:
diff changeset
431 NULL,
3d52de18ecc3 added still image support
bellard
parents:
diff changeset
432 };
3d52de18ecc3 added still image support
bellard
parents:
diff changeset
433
3d52de18ecc3 added still image support
bellard
parents:
diff changeset
434 AVImageFormat pbm_image_format = {
3d52de18ecc3 added still image support
bellard
parents:
diff changeset
435 "pbm",
3d52de18ecc3 added still image support
bellard
parents:
diff changeset
436 "pbm",
3d52de18ecc3 added still image support
bellard
parents:
diff changeset
437 NULL,
3d52de18ecc3 added still image support
bellard
parents:
diff changeset
438 NULL,
3d52de18ecc3 added still image support
bellard
parents:
diff changeset
439 (1 << PIX_FMT_MONOWHITE),
3d52de18ecc3 added still image support
bellard
parents:
diff changeset
440 pnm_write,
3d52de18ecc3 added still image support
bellard
parents:
diff changeset
441 };
3d52de18ecc3 added still image support
bellard
parents:
diff changeset
442
3d52de18ecc3 added still image support
bellard
parents:
diff changeset
443 AVImageFormat pgm_image_format = {
3d52de18ecc3 added still image support
bellard
parents:
diff changeset
444 "pgm",
3d52de18ecc3 added still image support
bellard
parents:
diff changeset
445 "pgm",
3d52de18ecc3 added still image support
bellard
parents:
diff changeset
446 NULL,
3d52de18ecc3 added still image support
bellard
parents:
diff changeset
447 NULL,
3d52de18ecc3 added still image support
bellard
parents:
diff changeset
448 (1 << PIX_FMT_GRAY8),
3d52de18ecc3 added still image support
bellard
parents:
diff changeset
449 pnm_write,
3d52de18ecc3 added still image support
bellard
parents:
diff changeset
450 };
3d52de18ecc3 added still image support
bellard
parents:
diff changeset
451
3d52de18ecc3 added still image support
bellard
parents:
diff changeset
452 AVImageFormat ppm_image_format = {
3d52de18ecc3 added still image support
bellard
parents:
diff changeset
453 "ppm",
3d52de18ecc3 added still image support
bellard
parents:
diff changeset
454 "ppm",
3d52de18ecc3 added still image support
bellard
parents:
diff changeset
455 NULL,
3d52de18ecc3 added still image support
bellard
parents:
diff changeset
456 NULL,
3d52de18ecc3 added still image support
bellard
parents:
diff changeset
457 (1 << PIX_FMT_RGB24),
3d52de18ecc3 added still image support
bellard
parents:
diff changeset
458 pnm_write,
3d52de18ecc3 added still image support
bellard
parents:
diff changeset
459 };
3d52de18ecc3 added still image support
bellard
parents:
diff changeset
460
109
c82a6062485e added new netpbm pam format support (needed for alpha plane support)
bellard
parents: 65
diff changeset
461 AVImageFormat pam_image_format = {
c82a6062485e added new netpbm pam format support (needed for alpha plane support)
bellard
parents: 65
diff changeset
462 "pam",
c82a6062485e added new netpbm pam format support (needed for alpha plane support)
bellard
parents: 65
diff changeset
463 "pam",
c82a6062485e added new netpbm pam format support (needed for alpha plane support)
bellard
parents: 65
diff changeset
464 pam_probe,
c82a6062485e added new netpbm pam format support (needed for alpha plane support)
bellard
parents: 65
diff changeset
465 pam_read,
885
da1d5db0ce5c COSMETICS: Remove all trailing whitespace.
diego
parents: 320
diff changeset
466 (1 << PIX_FMT_MONOWHITE) | (1 << PIX_FMT_GRAY8) | (1 << PIX_FMT_RGB24) |
109
c82a6062485e added new netpbm pam format support (needed for alpha plane support)
bellard
parents: 65
diff changeset
467 (1 << PIX_FMT_RGBA32),
c82a6062485e added new netpbm pam format support (needed for alpha plane support)
bellard
parents: 65
diff changeset
468 pam_write,
c82a6062485e added new netpbm pam format support (needed for alpha plane support)
bellard
parents: 65
diff changeset
469 };
c82a6062485e added new netpbm pam format support (needed for alpha plane support)
bellard
parents: 65
diff changeset
470
20
3d52de18ecc3 added still image support
bellard
parents:
diff changeset
471 AVImageFormat pgmyuv_image_format = {
3d52de18ecc3 added still image support
bellard
parents:
diff changeset
472 "pgmyuv",
200
c0d49b5d246c accepts pgmyuv extension
bellard
parents: 109
diff changeset
473 "pgmyuv",
20
3d52de18ecc3 added still image support
bellard
parents:
diff changeset
474 pgmyuv_probe,
3d52de18ecc3 added still image support
bellard
parents:
diff changeset
475 pgmyuv_read,
3d52de18ecc3 added still image support
bellard
parents:
diff changeset
476 (1 << PIX_FMT_YUV420P),
3d52de18ecc3 added still image support
bellard
parents:
diff changeset
477 pnm_write,
3d52de18ecc3 added still image support
bellard
parents:
diff changeset
478 };