void read_image(liq_attr *attr, FILE *source, png24_image *png, liq_image **image) { rwpng_read_image24(source, png); *image = liq_image_create_rgba_rows(attr, (void **) png->row_pointers, png->width, png->height, png->gamma); }
/* Reads image into png24_image struct. Returns non-zero on error */ static int read_image(const char *filename, png24_image *image) { FILE *fp = fopen(filename, "rb"); if (!fp) { return 1; } int retval = rwpng_read_image24(fp, image, 0); fclose(fp); return retval; }
static pngquant_error read_image(liq_attr *options, const char *filename, int using_stdin, png24_image *input_image_p, liq_image **liq_image_p, bool keep_input_pixels, bool verbose) { FILE *infile; if (using_stdin) { set_binary_mode(stdin); infile = stdin; } else if ((infile = fopen(filename, "rb")) == NULL) { fprintf(stderr, " error: cannot open %s for reading\n", filename); return READ_ERROR; } pngquant_error retval; #pragma omp critical (libpng) { retval = rwpng_read_image24(infile, input_image_p, verbose); } if (!using_stdin) { fclose(infile); } if (retval) { fprintf(stderr, " error: cannot decode image %s\n", using_stdin ? "from stdin" : filename_part(filename)); return retval; } *liq_image_p = liq_image_create_rgba_rows(options, (void**)input_image_p->row_pointers, input_image_p->width, input_image_p->height, input_image_p->gamma); if (!*liq_image_p) { return OUT_OF_MEMORY_ERROR; } if (!keep_input_pixels) { if (LIQ_OK != liq_image_set_memory_ownership(*liq_image_p, LIQ_OWN_ROWS | LIQ_OWN_PIXELS)) { return OUT_OF_MEMORY_ERROR; } input_image_p->row_pointers = NULL; input_image_p->rgba_data = NULL; } return SUCCESS; }
static int read_image(const char *filename, png24_image *image) { int retval=1; bool using_stdin = false; FILE *fh; unsigned char buffer[8]; if (0 == strcmp("-", filename)) { using_stdin = true; fh = stdin; } else { fh = fopen(filename, "rb"); if (!fh) { return 1; } } setvbuf(fh, (char *)buffer, _IOFBF, 8); // the first read fills the buffer up, but put char back on after int c = fgetc(fh); ungetc(c, fh); // the png number is not really precise but I guess the situation where this would falsely pass is almost equal to 0 if (png_check_sig(buffer, 8)) { /* Reads image into png24_image struct. Returns non-zero on error */ retval = rwpng_read_image24(fh, image, 0); } #ifdef USE_LIBJPEG else { retval=read_image_jpeg(fh,image); } #endif if(!using_stdin) { fclose(fh); } return retval; }