All pastes #536386 Raw Edit

Mine

public c v1 · immutable
·published 2007-06-04 11:16 UTC
rendered paste body
typedef struct Image{    int width;    int height;    unsigned char *data;} Image;Image *load_image(char *filename){    Image  *img;    ILuint image_name;    ILenum error;    char   *error_str;    ILint cur_format;    ilGenImages(1, &image_name);    ilBindImage(image_name);    // Force OpenGL-compatible row order.    ilEnable(IL_ORIGIN_SET);    ilOriginFunc(IL_ORIGIN_LOWER_LEFT);    cur_format = ilGetInteger(IL_IMAGE_FORMAT);    printf("DEBUG: Image format is %x.\n", cur_format);    if (ilLoadImage(filename)) {        img = (Image *) malloc(sizeof(Image));        img->width  = ilGetInteger(IL_IMAGE_WIDTH);        img->height = ilGetInteger(IL_IMAGE_HEIGHT);        img->data   = (unsigned char *) malloc(img->width * img->height * 4);        if( !ilCopyPixels(0, 0, 0, img->width, img->height, 1, IL_RGBA, IL_UNSIGNED_BYTE, img->data) ) {            error = ilGetError();            error_str = iluErrorString(error);            fprintf(stderr, "load_image: Failed to read image data for \"%s\". (Last error given by DevIL was \"%s (code %d)\".)\n", filename, error_str, error);            free( (void *) img->data );            free(img);            ilDeleteImages(1, &image_name);            return NULL;        }    } else {        fprintf(stderr, "load_image: Failed to load image \"%s\".\n", filename);        ilDeleteImages(1, &image_name);        return NULL;    }    ilDeleteImages(1, &image_name);    return img;}