the RLE stuff still doesn't exactly work, but I'm getting somewhere
git-svn-id: file:///srv/svn/repos/haiku/trunk/current@1350 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
@@ -893,107 +893,61 @@ pix_bits_to_tgarle(uint8 *pbits, uint8 *ptga, color_space fromspace,
|
|||||||
if (width == 0)
|
if (width == 0)
|
||||||
return B_ERROR;
|
return B_ERROR;
|
||||||
|
|
||||||
uint32 keypixel = 0, pixel = 0;
|
uint32 pixel = 0, lastpixel = 0, nextpixel = 0;
|
||||||
uint16 nread = 0;
|
uint16 nread = 0;
|
||||||
status_t result, bytescopied = 0;
|
status_t result, bytescopied = 0;
|
||||||
uint8 *prawbuf, *praw;
|
uint8 *prawbuf, *praw;
|
||||||
prawbuf = new uint8[bitsBytesPerPixel * 128];
|
prawbuf = new uint8[bitsBytesPerPixel * 128];
|
||||||
|
praw = prawbuf;
|
||||||
if (!prawbuf)
|
if (!prawbuf)
|
||||||
return B_ERROR;
|
return B_ERROR;
|
||||||
|
|
||||||
memcpy(&keypixel, pbits, bitsBytesPerPixel);
|
uint8 rlecount = 1, rawcount = 0;
|
||||||
|
|
||||||
|
memcpy(&pixel, pbits, bitsBytesPerPixel);
|
||||||
pbits += bitsBytesPerPixel;
|
pbits += bitsBytesPerPixel;
|
||||||
nread++;
|
|
||||||
|
|
||||||
// special case
|
|
||||||
if (width == 1) {
|
|
||||||
result = copy_raw_packet(ptga,
|
|
||||||
(uint8 *) &keypixel, 1, fromspace,
|
|
||||||
pmap, bitsBytesPerPixel);
|
|
||||||
ptga += result;
|
|
||||||
bytescopied += result;
|
|
||||||
}
|
|
||||||
|
|
||||||
uint8 count = 1;
|
|
||||||
while (nread < width) {
|
while (nread < width) {
|
||||||
|
|
||||||
memcpy(&pixel, pbits, bitsBytesPerPixel);
|
if (nread < width - 1) {
|
||||||
pbits += bitsBytesPerPixel;
|
memcpy(&nextpixel, pbits, bitsBytesPerPixel);
|
||||||
nread++;
|
|
||||||
|
|
||||||
//////
|
|
||||||
// RLE
|
|
||||||
//////
|
|
||||||
|
|
||||||
// Read while string of pixels is identical
|
|
||||||
while (keypixel == pixel && count < 128) {
|
|
||||||
count++;
|
|
||||||
if (nread == width)
|
|
||||||
break;
|
|
||||||
|
|
||||||
memcpy(&pixel, pbits, bitsBytesPerPixel);
|
|
||||||
pbits += bitsBytesPerPixel;
|
pbits += bitsBytesPerPixel;
|
||||||
nread++;
|
|
||||||
}
|
}
|
||||||
|
nread++;
|
||||||
|
|
||||||
// if there are some adjacent identical pixels
|
if (nread > 1 && lastpixel == pixel) {
|
||||||
if (count > 1) {
|
rlecount++;
|
||||||
result = copy_rle_packet(ptga, keypixel,
|
|
||||||
count, fromspace, pmap, bitsBytesPerPixel);
|
|
||||||
ptga += result;
|
|
||||||
bytescopied += result;
|
|
||||||
|
|
||||||
// If last pixel in row does not match
|
if (rlecount == 128 || nread == width || pixel != nextpixel) {
|
||||||
// with current RLE packet, write out
|
result = copy_rle_packet(ptga, pixel, rlecount,
|
||||||
// RAW packet for the last pixel on the line
|
fromspace, pmap, bitsBytesPerPixel);
|
||||||
if (nread == width && keypixel != pixel) {
|
|
||||||
result = copy_raw_packet(ptga, (uint8 *) &pixel,
|
|
||||||
1, fromspace, pmap, bitsBytesPerPixel);
|
|
||||||
ptga += result;
|
ptga += result;
|
||||||
bytescopied += result;
|
bytescopied += result;
|
||||||
|
rlecount = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
count = 1;
|
} else {
|
||||||
keypixel = pixel;
|
if ((nread < width && pixel != nextpixel) || nread == width) {
|
||||||
}
|
rawcount++;
|
||||||
|
memcpy(praw, &pixel, bitsBytesPerPixel);
|
||||||
//////
|
praw += bitsBytesPerPixel;
|
||||||
// RAW
|
}
|
||||||
//////
|
|
||||||
|
|
||||||
praw = prawbuf;
|
|
||||||
memcpy(praw, &keypixel, bitsBytesPerPixel);
|
|
||||||
praw += bitsBytesPerPixel;
|
|
||||||
|
|
||||||
// Read while adjacent pixels do not match
|
if (rawcount == 128 || nread == width || (pixel == nextpixel && rawcount > 0)) {
|
||||||
while (keypixel != pixel && count < 128) {
|
result = copy_raw_packet(ptga,
|
||||||
memcpy(praw, &pixel, bitsBytesPerPixel);
|
prawbuf, rawcount, fromspace, pmap,
|
||||||
praw += bitsBytesPerPixel;
|
bitsBytesPerPixel);
|
||||||
count++;
|
|
||||||
if (nread == width)
|
ptga += result;
|
||||||
break;
|
bytescopied += result;
|
||||||
|
rawcount = 0;
|
||||||
keypixel = pixel;
|
praw = prawbuf;
|
||||||
memcpy(&pixel, pbits, bitsBytesPerPixel);
|
|
||||||
pbits += bitsBytesPerPixel;
|
|
||||||
nread++;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (count > 1) {
|
|
||||||
if (keypixel == pixel)
|
|
||||||
count--;
|
|
||||||
result = copy_raw_packet(ptga, prawbuf, count,
|
|
||||||
fromspace, pmap, bitsBytesPerPixel);
|
|
||||||
ptga += result;
|
|
||||||
bytescopied += result;
|
|
||||||
|
|
||||||
if (keypixel == pixel)
|
|
||||||
count = 2;
|
|
||||||
else {
|
|
||||||
count = 1;
|
|
||||||
keypixel = pixel;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
lastpixel = pixel;
|
||||||
|
pixel = nextpixel;
|
||||||
}
|
}
|
||||||
|
|
||||||
delete[] prawbuf;
|
delete[] prawbuf;
|
||||||
|
|||||||
Reference in New Issue
Block a user