DIM_UINT dimPngReadImageProc ( TDimFormatHandle *fmtHndl, DIM_UINT page ) { if (fmtHndl == NULL) return 1; if (fmtHndl->stream == NULL) return 1; fmtHndl->pageNumber = page; return read_png_image( fmtHndl ); }
/* * Creates and returns a texture based on a bundled image filename */ GLuint read_png_texture(const char *name, bool pixel_texture) { char *data = NULL; int width = 0; int height= 0; bool success = read_png_image(name,&data,&width,&height); if (!success) return 0; GLuint texture_object = create_texture(data, width, height, pixel_texture); delete data; return texture_object; }
image_t * read_image(image_t * image) { FILE * infile; if ((infile = fopen(image->path, "rb")) == NULL) { fprintf(stderr, "can't open %s\n", image->path); return NULL; } unsigned char sig[8]; fread(sig, 1, 8, infile); if (png_sig_cmp(sig, 0, 8) == 0) { image = read_png_image(image, infile); } else if (sig[0] == 0xFF && sig[1] == 0xd8) { fseek(infile, 0, 0); image = read_jpeg_image(image, infile); } else { printf("%s is not a jpeg file\n", image->path); return NULL; } fclose(infile); return image; }