1 /*
2 * PAM 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 const AVFrame *p,
int *got_packet)
29 {
30 int i,
h,
w, n, linesize, depth, maxval,
ret, header_size;
31 uint8_t *bytestream, *ptr;
32 const char *tuple_type;
34
40 depth = 1;
41 maxval = 1;
42 tuple_type = "BLACKANDWHITE";
43 break;
46 depth = 1;
47 maxval = 255;
48 tuple_type = "GRAYSCALE";
49 break;
52 depth = 1;
53 maxval = 0xFFFF;
54 tuple_type = "GRAYSCALE";
55 break;
58 depth = 2;
59 maxval = 255;
60 tuple_type = "GRAYSCALE_ALPHA";
61 break;
64 depth = 2;
65 maxval = 0xFFFF;
66 tuple_type = "GRAYSCALE_ALPHA";
67 break;
70 depth = 3;
71 maxval = 255;
72 tuple_type = "RGB";
73 break;
76 depth = 4;
77 maxval = 255;
78 tuple_type = "RGB_ALPHA";
79 break;
82 depth = 3;
83 maxval = 0xFFFF;
84 tuple_type = "RGB";
85 break;
88 depth = 4;
89 maxval = 0xFFFF;
90 tuple_type = "RGB_ALPHA";
91 break;
92 default:
93 return -1;
94 }
95
97 "P7\nWIDTH %d\nHEIGHT %d\nDEPTH %d\nMAXVAL %d\nTUPLTYPE %s\nENDHDR\n",
98 w,
h, depth, maxval, tuple_type);
100
103
105 memcpy(bytestream,
header, header_size);
106 bytestream += header_size;
107
110
112 int j;
113 for (
i = 0;
i <
h;
i++) {
114 for (j = 0; j <
w; j++)
115 *bytestream++ = ptr[j >> 3] >> (7 - j & 7) & 1;
116 ptr += linesize;
117 }
118 } else {
119 for (
i = 0;
i <
h;
i++) {
120 memcpy(bytestream, ptr, n);
121 bytestream += n;
122 ptr += linesize;
123 }
124 }
125
126 *got_packet = 1;
127 return 0;
128 }
129
143 },
145 };