1 /*
2 * Copyright (c) 1990 James Ashton - Sydney University
3 * Copyright (c) 2012 Stefano Sabatini
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 /**
23 * @file
24 * X-Face encoder, based on libcompface, by James Ashton.
25 */
26
31
38
39 static int all_same(
char *bitmap,
int w,
int h)
40 {
42 int x;
43
44 val = *bitmap;
45 while (h--) {
46 row = bitmap;
47 x = w;
48 while (x--)
49 if (*(row++) != val)
50 return 0;
52 }
53 return 1;
54 }
55
57 {
58 if (w > 3) {
59 w /= 2;
60 h /= 2;
64 } else {
65 /* at least one pixel in the 2x2 grid is non-zero */
66 return *bitmap || *(bitmap + 1) ||
68 }
69 }
70
72 {
73 return *bitmap == 0 &&
all_same(bitmap, w, h);
74 }
75
80
82 {
84 return -1;
86 return 0;
87 }
88
90 {
91 if (w > 3) {
92 w /= 2;
93 h /= 2;
98 } else {
100 *bitmap +
101 2 * *(bitmap + 1) +
105 }
106 }
107
109 {
115 } else {
117 w /= 2;
118 h /= 2;
119 level++;
123 encode_block(bitmap + w + h * XFACE_WIDTH, w, h, level, pq);
124 }
125 }
126
128 {
133
134 return 0;
135 }
136
138 {
140
144 }
145
148 {
153 int i, j, k,
ret = 0;
157
161 "Size value %dx%d not supported, only accepts a size of %dx%d\n",
164 }
165 }
168
169 /* convert image from MONOWHITE to 1=black 0=white bitmap */
170 buf = frame->
data[0];
171 i = j = 0;
172 do {
173 for (k = 0; k < 8; k++)
174 xface->
bitmap[i++] = (buf[j]>>(7-k))&1;
177 j = 0;
178 }
180
181 /* create a copy of bitmap */
184
194
197
198 /* write the inverted big integer in b to intbuf */
199 i = 0;
206 }
207
210
211 /* revert the number, and close the buffer */
213 while (--i >= 0)
214 *(p++) = intbuf[i];
215 *(p++) = '\n';
216 *(p++) = 0;
217
219 *got_packet = 1;
220
221 return 0;
222 }
223
225 {
227
228 return 0;
229 }
230
241 };