28 #define PUTNIBBLE(val)\
31 *q++ = bitbuf | ((val) & 0x0f);\
37 const uint8_t *bitmap,
int linesize,
42 unsigned int bitbuf = 0;
48 for (y = 0; y < h; ++y) {
50 for(x = 0; x < w; x +=
len) {
52 for (len=1; x+len < w; ++
len)
53 if (bitmap[x+len] != color)
59 }
else if (len < 0x10) {
62 }
else if (len < 0x40) {
66 }
else if (x+len == w) {
94 int offset1[20], offset2[20];
97 unsigned long hist[256];
106 for (i=0; i<256; ++i) {
110 for (object_id = 0; object_id < rects; object_id++)
111 for (i=0; i<h->
rects[object_id]->
w*h->
rects[object_id]->
h; ++i) {
115 hist[
color] += alpha;
117 for (color=3;; --
color) {
120 for (i=0; i<256; ++i)
121 if (hist[i] > hmax) {
130 imax, hist[imax], color);
138 for (object_id = 0; object_id < rects; object_id++) {
139 offset1[object_id] = q - outbuf;
141 if ((q - outbuf) + h->
rects[object_id]->
w*h->
rects[object_id]->
h/2
142 + 17*rects + 21 > outbuf_size) {
150 offset2[object_id] = q - outbuf;
159 bytestream_put_be16(&qq, q - outbuf);
163 bytestream_put_be16(&q, (q - outbuf) + 8 + 12*rects + 2);
165 *q++ = 0x03; *q++ = 0x7f;
167 *q++ = 0xf0; *q++ = 0x00;
172 for (object_id = 0; object_id < rects; object_id++) {
173 int x2 = h->
rects[object_id]->
x + h->
rects[object_id]->
w - 1;
174 int y2 = h->
rects[object_id]->
y + h->
rects[object_id]->
h - 1;
178 *q++ = h->
rects[object_id]->
x >> 4;
179 *q++ = (h->
rects[object_id]->
x << 4) | ((x2 >> 8) & 0xf);
182 *q++ = h->
rects[object_id]->
y >> 4;
183 *q++ = (h->
rects[object_id]->
y << 4) | ((y2 >> 8) & 0xf);
188 bytestream_put_be16(&q, offset1[object_id]);
189 bytestream_put_be16(&q, offset2[object_id]);
196 bytestream_put_be16(&q, (q - outbuf) - 2 );
201 bytestream_put_be16(&qq, q - outbuf);
208 unsigned char *buf,
int buf_size,
void *
data)