1 /*
2 * XBM image format
3 *
4 * Copyright (c) 2012 Paul B Mahol
5 *
6 * This file is part of FFmpeg.
7 *
8 * FFmpeg is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either
11 * version 2.1 of the License, or (at your option) any later version.
12 *
13 * FFmpeg is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
17 *
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with FFmpeg; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
21 */
22
26
27 #define ANSI_MIN_READLINE 509
28
31 {
32 int i, j, l, commas,
ret,
size, linesize, lineout, rowsout;
33 const uint8_t *ptr;
34 uint8_t *buf;
35
36 linesize = lineout = (avctx->
width + 7) / 8;
37 commas = avctx->
height * linesize;
38
39 /* ANSI worst case minimum readline is 509 chars. */
43 rowsout = (commas + lineout - 1) / lineout;
44 }
45
46 size = rowsout * (lineout * 6 + 1) + 106;
49
52
53 buf +=
snprintf(buf, 32,
"#define image_width %u\n", avctx->
width);
54 buf +=
snprintf(buf, 33,
"#define image_height %u\n", avctx->
height);
55 buf +=
snprintf(buf, 39,
"static unsigned char image_bits[] = {\n");
56 for (
i = 0, l = lineout;
i < avctx->
height;
i++) {
57 for (j = 0; j < linesize; j++) {
58 // 0..15 bitreversed as chars
59 static const char lut[] = {
60 '0', '8', '4', 'C', '2', 'A', '6', 'E',
61 '1', '9', '5', 'D', '3', 'B', '7', 'F'
62 };
63 buf[0] = ' ';
64 buf[1] = '0';
65 buf[2] = 'x';
66 buf[3] = lut[*ptr & 0xF];
67 buf[4] = lut[*ptr >> 4];
68 buf += 5;
69 ptr++;
70 if (--commas <= 0) {
71 *buf++ = '\n';
72 break;
73 }
74 *buf++ = ',';
75 if (--l <= 0) {
76 *buf++ = '\n';
77 l = lineout;
78 }
79 }
80 ptr +=
p->linesize[0] - linesize;
81 }
83
85 *got_packet = 1;
86 return 0;
87 }
88
97 };