[Libdlo] libtubecable 0.1.1
Henrik Bjerregaard Pedersen
hbp at xinc.dk
Mon Jun 8 00:22:35 PDT 2009
Hi Florian.
> But this still is a hack nevertheless.. especially when considering that
> this code doesn't yet support images shorter than the screen width.
I've tried writing a small routine to support just that, but there are
quite a lot of pixel errors in the result. I've included it anyway, in
case someone might have an idea why that happens. Most likely it has
something to do with all the weird adjustments you have added in your
dl_huffman_compress() and which I have removed - all that is probably
necessary but it is not quite clear why.
Call it from tubecable_demo.c as:
dl_draw_image_huffman(&cs, XRES, YRES, 100, 100, img16, 640, 480);
In tubecable.c:
// Append one <512-byte block of compressed data to the stream.
int dl_huffman_compress2( dl_cmdstream* cs, int addr, int pcount,
uint16_t* pixels ) {
int start = cs->pos, pixel = 0;
uint16_t prev = 0, thispix;
if (pcount > 248) pcount = 248;
cs->bitpos = 0;
memset(cs->buffer+cs->pos, 0x00, 512);
dl_gfx_base( cs, DL_GFX_WRITE | DL_GFX_WORD | DL_GFX_COMP, addr,
pcount );
// this loop generates sub-blocks of max. 248 pixels
for ( pixel = 0; pixel < pcount; pixel++ ) {
thispix = pixels[pixel];
dl_huffman_append( cs, thispix - prev );
prev = thispix;
}
if (cs->bitpos) // include last few bits
cs->pos++;
// return total number of encoded pixels
return pcount;
}
int dl_draw_image_huffman(dl_cmdstream *cs, uint16_t screenw, uint16_t
screenh, uint16_t plotx, uint16_t ploty, uint16_t *img16, uint16_t imgw,
uint16_t imgh) {
uint16_t y;
for (y = 0; y < imgh; y++) {
uint16_t remaining, x;
int addr;
addr = screenw*(y+ploty);
remaining = imgw;
x = plotx;
while (remaining) {
int pixels;
pixels = remaining;
pixels = dl_huffman_compress2(cs, (addr+x)*2, pixels,
img16);
x += pixels;
img16 += pixels;
remaining -= pixels;
}
}
return 0;
}
--
Henrik Bjerregaard Pedersen
phone: +45 38606892 mail: hbp at xinc.dk
More information about the Libdlo
mailing list