Writing code using IFL - SGI

This is a discussion on Writing code using IFL - SGI ; 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 ...

+ Reply to Thread
Results 1 to 2 of 2

Thread: Writing code using IFL

  1. Writing code using IFL

    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
    #include
    #include

    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;
    }

  2. Re: Writing code using IFL

    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.

+ Reply to Thread