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
24
26 const AVFrame *p,
int *got_packet)
27 {
28 uint8_t *bytestream_start, *bytestream, *bytestream_end;
29 int i, h, w,
n, linesize,
depth, maxval,
ret;
30 const char *tuple_type;
32
37 n = w;
38 depth = 1;
39 maxval = 1;
40 tuple_type = "BLACKANDWHITE";
41 break;
43 n = w;
44 depth = 1;
45 maxval = 255;
46 tuple_type = "GRAYSCALE";
47 break;
49 n = w * 2;
50 depth = 1;
51 maxval = 0xFFFF;
52 tuple_type = "GRAYSCALE";
53 break;
55 n = w * 2;
56 depth = 2;
57 maxval = 255;
58 tuple_type = "GRAYSCALE_ALPHA";
59 break;
61 n = w * 3;
62 depth = 3;
63 maxval = 255;
64 tuple_type = "RGB";
65 break;
67 n = w * 4;
68 depth = 4;
69 maxval = 255;
70 tuple_type = "RGB_ALPHA";
71 break;
73 n = w * 6;
74 depth = 3;
75 maxval = 0xFFFF;
76 tuple_type = "RGB";
77 break;
79 n = w * 8;
80 depth = 4;
81 maxval = 0xFFFF;
82 tuple_type = "RGB_ALPHA";
83 break;
84 default:
85 return -1;
86 }
87
90
91 bytestream_start =
92 bytestream = pkt->
data;
93 bytestream_end = pkt->
data + pkt->
size;
94
95 snprintf(bytestream, bytestream_end - bytestream,
96 "P7\nWIDTH %d\nHEIGHT %d\nDEPTH %d\nMAXVAL %d\nTUPLTYPE %s\nENDHDR\n",
97 w, h, depth, maxval, tuple_type);
98 bytestream += strlen(bytestream);
99
102
104 int j;
105 for (i = 0; i < h; i++) {
106 for (j = 0; j < w; j++)
107 *bytestream++ = ptr[j >> 3] >> (7 - j & 7) & 1;
108 ptr += linesize;
109 }
110 } else {
111 for (i = 0; i < h; i++) {
112 memcpy(bytestream, ptr, n);
114 ptr += linesize;
115 }
116 }
117
118 pkt->
size = bytestream - bytestream_start;
120 *got_packet = 1;
121 return 0;
122 }
123
125 {
129
132
133 return 0;
134 }
135
137 {
139 return 0;
140 }
141
152 },
153 };