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
30
37
38 static int all_same(
char *bitmap,
int w,
int h)
39 {
41 int x;
42
43 val = *bitmap;
44 while (h--) {
45 row = bitmap;
46 x = w;
47 while (x--)
48 if (*(row++) != val)
49 return 0;
51 }
52 return 1;
53 }
54
56 {
57 if (w > 3) {
58 w /= 2;
59 h /= 2;
63 } else {
64 /* at least one pixel in the 2x2 grid is non-zero */
65 return *bitmap || *(bitmap + 1) ||
67 }
68 }
69
71 {
72 return *bitmap == 0 &&
all_same(bitmap, w, h);
73 }
74
79
81 {
83 return -1;
85 return 0;
86 }
87
89 {
90 if (w > 3) {
91 w /= 2;
92 h /= 2;
97 } else {
99 *bitmap +
100 2 * *(bitmap + 1) +
104 }
105 }
106
108 {
114 } else {
116 w /= 2;
117 h /= 2;
118 level++;
122 encode_block(bitmap + w + h * XFACE_WIDTH, w, h, level, pq);
123 }
124 }
125
127 {
132
133 return 0;
134 }
135
137 {
139
143 }
144
147 {
152 int i, j, k,
ret = 0;
156
160 "Size value %dx%d not supported, only accepts a size of %dx%d\n",
163 }
164 }
167
168 /* convert image from MONOWHITE to 1=black 0=white bitmap */
169 buf = frame->
data[0];
170 i = j = 0;
171 do {
172 for (k = 0; k < 8; k++)
173 xface->
bitmap[i++] = (buf[j]>>(7-k))&1;
176 j = 0;
177 }
179
180 /* create a copy of bitmap */
183
193
196
197 /* write the inverted big integer in b to intbuf */
198 i = 0;
203 }
204
207
208 /* revert the number, and close the buffer */
210 while (--i >= 0)
211 *(p++) = intbuf[i];
212 *(p++) = '\n';
213 *(p++) = 0;
214
216 *got_packet = 1;
217
218 return 0;
219 }
220
222 {
224
225 return 0;
226 }
227
238 };