On Fri, Jun 30, 2000 at 12:32:13PM -0400, Jason Davidson wrote:
> There is not much documentation on the palm RLE compression support
> for Bitmaps, so I just wanted to see if anyone knows what Palm
> supports. Does palms RLE support absolute mode for RLE compression?
> Does Palms RLE uncompression algorithm expect that the Bitmap start
> with a end of line notation (0000).
Oops...
Here is the routine (gpl), unpqa.tgz is at
www.execpc.com/~tz/unpqa.zip, or at palmboxer.sourceforge.net at the
bottom of the page (the top link is to download it to your VII).
---------------------
#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
#include <string.h>
#include <fcntl.h>
#include <sys/types.h>
#include <netinet/in.h>
#include <time.h>
#pragma pack(2)
// at start, bp points to the buffer, bitc is zero (most significant bit), ubuf has a
URL, len has length of buffer in bytes
extern unsigned char *bp, bitc;
extern unsigned short len;
extern FILE *ofp;
static inline int bitget()
{
register unsigned char t;
// if (!len && bitc == 7)
// exit(-1);
t = 1 & (*bp >> (7 - bitc++));
if (bitc == 8)
bp++, bitc = 0, len--;
#ifdef debug
fprintf(ofp, "%d", t);
#endif
return t;
}
static inline int getbits(int n)
{
int t8 = 0;
#ifdef debug
fprintf(ofp, "[");
#endif
while (n--) {
t8 <<= 1;
t8 |= bitget();
}
#ifdef debug
fprintf(ofp, "]");
#endif
return t8;
}
static int cmap[256][4];
void dobitmap()
{
short unsigned int w, h, r, fl, sz, a2, a3, a4, a5, a6;
unsigned char o, x;
int i, j, k, l, k1, deep;
w = getbits(16);
h = getbits(16);
r = getbits(16);
fl = getbits(16);
deep = getbits(8);
a2 = getbits(8);
a3 = getbits(16);
a4 = getbits(16);
a5 = getbits(16);
sz = (1 << deep) - 1;
if (deep == 1)
fprintf(ofp, "P1 %d %d\n", w, h);
else if ((fl & 0x4000)) {
a6 = getbits(16);
fprintf(ofp, "Cmap: %d\n", a6);
for (i = 0; i < a6; i++)
for (j = 0; j < 4; j++)
cmap[i][j] = getbits(8);
fprintf(ofp, "P3 %d %d 255\n", w, h);
} else
fprintf(ofp, "P2 %d %d %d\n", w, h, sz);
if (!(fl & 0x8000))
while (h--) {
k1 = w;
// for (i = 0; i < r * 8 / deep && k1--; i++)
while (k1--)
fprintf(ofp, " %d", sz - getbits(deep));
fputc('\n', ofp);
} else {
// THIS IS THE COMPRESSED BITMAP DECOMPRESSOR
unsigned char memrow[256], f;
memset(memrow, 0, 256);
a6 = getbits(16);
while (h--) {
k1 = w;
i = 0;
while (i < r) {
f = getbits(8);
for (k = 0; k < 8 && i < r; k++, i++) {
if ((f << k) & 0x80)
memrow[i] = getbits(8);
o = memrow[i];
for (j = 7; j >= 0;) {
x = 0;
for (l = 0; l < deep; l++)
x = (x << 1) | (1 & (o >> j--));
if (k1-- > 0)
fprintf(ofp, " %d", sz - x);
}
}
}
fputc('\n', ofp);
}
}
}
--
For information on using the Palm Developer Forums, or to unsubscribe, please see
http://www.palmos.com/dev/tech/support/forums/