1998.09.01 20:52 "Anyone use xil librarys on a sun to do G4 compression?", by Bill Jeffers
Hello,
I am attempting to use the xil library on a sun to do faxG4 compression for inclusion in a tiff.
The following code compress's a 16x5 bitmap and then uncompress's it. The problem is that the compressed data doesn't look like the G4 code I am expecting. Does anyone know what I'm missing?
Thanks
Bill J
output:
Raw Data: e1 e3 e1 e3 e1 e3 c0 e3 ff c1
Comp Data: 30 cd df fd 3e 29 c0 4 0 40
XIL Raw data: e1 e3 e1 e3 e1 e3 c0 e3 ff c1
read frame 0
Prefered CIS has width=16 height=5 nbands=1 datatype=0
XIL Compressed data: 26 b1 b6 17 ff e9 f8 a7 0 10 1
XIL output buffer: 0 0 0 0 0 0 0 0 0 0
read frame 0
XIL Raw data: e1 e3 e1 e3 e1 e3 c0 e3 ff c1
source code follows
/* Try to compress and uncompress a bitmap using XIL libraries */
#include <errno.h>
#include <xil/xil.h>
void DumpData();
void Compress();
void Decompress();
void CopyData();
unsigned int rawWidth = 16;
unsigned int rawHeight = 5;
unsigned int rawLen = 10;
unsigned char raw[]=
{
0xE1, 0xE3, 0xE1, 0xE3, 0xE1, 0xE3, 0xC0, 0xE3, 0xFF, 0xC1
};
int compressedLen = 10;
unsigned char compressed[] =
{
0x30, 0xCD, 0xDF, 0xFD, 0x3E, 0x29, 0xC0, 0x04, 0x00, 0x40
};
int main()
{
XilSystemState state = NULL;
printf("Raw Data: "); DumpData(rawLen, raw);
printf("Comp Data: "); DumpData(compressedLen, compressed);
state = xil_open();
if ( state == NULL )
{
printf("xil_open failed\n");
return -1;
}
Compress(state);
xil_close(state); state = NULL;
return 0;
}
void Compress(XilSystemState state)
{
XilCis cis;
XilImage image, dst;
XilMemoryStorage storage, dstor;
XilImageType type;
XilDataType cis_datatype;
unsigned int cis_xsize, cis_ysize, cis_nbands;
int size, nbands;
void *datap;
float values[1]={0};
cis = xil_cis_create(state, "faxG4");
xil_cis_set_attribute(cis, "WIDTH", (void *) rawWidth);
xil_cis_set_attribute(cis, "HEIGHT", (void *) rawHeight);
xil_cis_set_attribute(cis, "BANDS", (void *) 1);
/*xil_cis_put_bits_ptr(cis, compressedLen, 1, (void *) compressed, NULL);*/
image = xil_create(state, rawWidth, rawHeight, 1, XIL_BIT);
if ( xil_export(image) != XIL_SUCCESS )
{
printf("image could not be exported\n");
return;
};
if ( !xil_get_memory_storage(image, &storage))
{
printf("couldn't get memory storage\n");
return;
};
xil_set_value(image, values);
CopyData(rawWidth*rawHeight/8, raw, storage.bit.data);
printf("XIL Raw data: ");
DumpData(storage.bit.band_stride, storage.bit.data + storage.bit.offset);
/* xil_import(image, 0);*/
xil_compress(image, cis);
xil_cis_sync(cis); /* force it to happen now */
printf("read frame %d\n", xil_cis_get_read_frame(cis));
xil_cis_seek(cis, 0, 0);
type=xil_cis_get_input_type(cis);
xil_imagetype_get_info(type, &cis_xsize, &cis_ysize,
&cis_nbands, &cis_datatype);
printf("Prefered CIS has width=%d height=%d nbands=%d datatype=%d\n",
cis_xsize, cis_ysize, cis_nbands, cis_datatype);
datap=xil_cis_get_bits_ptr(cis, &size, &nbands);
printf("XIL Compressed data: ");
DumpData(size, datap);
dst = xil_create(state, cis_xsize, cis_ysize, cis_nbands, XIL_BIT);
if ( xil_export(dst) != XIL_SUCCESS )
{
printf("image could not be exported\n");
return;
};
xil_set_value(dst, values);
if ( !xil_get_memory_storage(dst, &dstor))
{
printf("couldn't get memory storage\n");
return;
};
printf("XIL output buffer: ");
DumpData(dstor.bit.band_stride, dstor.bit.data + dstor.bit.offset);
xil_import(dst,1);
xil_cis_seek(cis, 0, 0);
printf("read frame %d\n", xil_cis_get_read_frame(cis));
xil_decompress(cis, dst);
if ( xil_export(dst) != XIL_SUCCESS )
{
printf("image could not be exported\n");
return;
};
if ( !xil_get_memory_storage(dst, &dstor))
{
printf("couldn't get memory storage\n");
return;
};
printf("XIL Raw data: ");
DumpData(dstor.bit.band_stride, dstor.bit.data + dstor.bit.offset);
xil_destroy(image); image = NULL;
xil_cis_destroy(cis); cis = NULL;
}
void Decompress(XilSystemState state)
{
}
void DumpData(int len, unsigned char *data)
{
int i;
for (i=0; i<len; i++)
printf("%2x ", (unsigned int) data[i]);
printf("\n");
}
void CopyData(int len, unsigned char *data, unsigned char *dest)
{
int i;
for (i=0; i<len; i++)
dest[i] = data[i];
}