Writing code using IFL

Writing code using IFL

Post by Nik Vukovl » Sat, 21 Feb 2004 11:19:20


I'm trying to use the Image Format Library for reading/writing GIF
images. To get to know how to use it I used the example code in the man
page for reading and writing a file, and modified it slightly to just
load an image and output it to another file.

Now, the code works for SGI-format images or JPG format images, but for
GIF images, the loading works, but it just won't save. iflFileSetTile
returns BADPARAM always.
Note, I can use the code to convert from JPG to SGI format, but not from
any format to GIF...

Anyone have any ideas ?

Any info appreciated...

The code example I'm working with is below...

#include <stdio.h>
#include <stdlib.h>
#include <ifl/iflCdefs.h>

int read_write_image(const char* filein, const char* fileout);


int main(int argc, char* argv[])
{
char* filein;
char* fileout;
int status;


if(argc < 3)
{
printf("Usage: %s filein fileout\n", argv[0]);
exit(0);
}


/* not testing existence of filenames */

filein = argv[1];
fileout = argv[2];

status = read_write_image(filein, fileout);
if(status == -1)
{
printf("failed\n");
}

return 0;
}


int read_write_image(const char* filein, const char* fileout)
{

iflStatus sts;
iflFile *file;
iflFile *file2;
iflSize dims;
unsigned char *data;
iflConfig* cfg;
iflFileConfig *fc;
iflFormat *outputformat;


file = iflFileOpen(filein, O_RDONLY, &sts);
if (sts != iflOKAY) {
printf("Error opening image\n");
return -1;/* handle the error */
}

/*
read the entire image (just the first plane in z if image
has depth) into a buffer of unsiged chars
*/

iflFileGetDimensions(file, &dims);
data = (unsigned char*)malloc(dims.x*dims.y*dims.c);
cfg = iflConfigCreate(iflUChar, iflInterleaved, 0, NULL, 0, 0);
sts = iflFileGetTile(file, 0, 0, 0, dims.x, dims.y, 1, data, cfg);
if (sts != iflOKAY) {
printf("Error reading image!\n");/* handle error */
return -1;
}

/* now write the image out */

fc = iflFileConfigCreate(&dims, iflUChar, 0, 0, 0, 0, NULL);
file2 = iflFileCreate(fileout, file, fc, NULL, &sts);
if (sts != iflOKAY) {
printf("Error creating output image!\n");/* handle error */
return -1;
}

/* close the original file */
iflFileClose(file, 0);


sts = iflFileSetTile(file2, 0, 0, 0, dims.x, dims.y, 1, data, NULL);
if (sts != iflOKAY) {
printf("Error creating the final image\n");/* handle error */
return -1;
}

/* make sure the data gets written out to disk (or you can close
here) */
sts = iflFileFlush(file2);
if (sts != iflOKAY) {
printf("Error writing the final image\n");/* handle error */
return -1;
}

return 0;
}
 
 
 

Writing code using IFL

Post by Nik Vukovl » Sat, 21 Feb 2004 17:37:52

Sorry for posting this to this group.
I've reposted to comp.sys.sgi.graphics where it belongs.
It as very late at night....

Nik.