/** * Load entire image into memory using fileaccess load method. * Faster than open+read+close. */ static image_t * fa_imageloader2(const char *url, const char **vpaths, char *errbuf, size_t errlen, int *cache_control, cancellable_t *c) { buf_t *buf; buf = fa_load(url, FA_LOAD_VPATHS(vpaths), FA_LOAD_ERRBUF(errbuf, errlen), FA_LOAD_CACHE_CONTROL(cache_control), FA_LOAD_CANCELLABLE(c), FA_LOAD_FLAGS(FA_CONTENT_ON_ERROR), NULL); if(buf == NULL || buf == NOT_MODIFIED) return (image_t *)buf; image_t *img = fa_imageloader_buf(buf, errbuf, errlen); buf_release(buf); return img; }
/** * Load entire image into memory using fileaccess load method. * Faster than open+read+close. */ static pixmap_t * fa_imageloader2(const char *url, const char **vpaths, char *errbuf, size_t errlen, int *cache_control, cancellable_t *c) { buf_t *buf; jpeg_meminfo_t mi; pixmap_type_t fmt; int width = -1, height = -1, orientation = 0; buf = fa_load(url, FA_LOAD_VPATHS(vpaths), FA_LOAD_ERRBUF(errbuf, errlen), FA_LOAD_CACHE_CONTROL(cache_control), FA_LOAD_CANCELLABLE(c), NULL); if(buf == NULL || buf == NOT_MODIFIED) return (pixmap_t *)buf; const uint8_t *p = buf_c8(buf); mi.data = p; mi.size = buf->b_size; if(buf->b_size < 16) goto bad; /* Probe format */ if((p[6] == 'J' && p[7] == 'F' && p[8] == 'I' && p[9] == 'F') || (p[6] == 'E' && p[7] == 'x' && p[8] == 'i' && p[9] == 'f')) { jpeginfo_t ji; if(jpeg_info(&ji, jpeginfo_mem_reader, &mi, JPEG_INFO_DIMENSIONS | JPEG_INFO_ORIENTATION, p, buf->b_size, errbuf, errlen)) { buf_release(buf); return NULL; } fmt = PIXMAP_JPEG; width = ji.ji_width; height = ji.ji_height; orientation = ji.ji_orientation; jpeg_info_clear(&ji); } else if(!memcmp(pngsig, p, 8)) { fmt = PIXMAP_PNG; } else if(!memcmp(gif87sig, p, sizeof(gif87sig)) || !memcmp(gif89sig, p, sizeof(gif89sig))) { fmt = PIXMAP_GIF; } else if(!memcmp(svgsig1, p, sizeof(svgsig1)) || !memcmp(svgsig2, p, sizeof(svgsig2))) { fmt = PIXMAP_SVG; } else { bad: snprintf(errbuf, errlen, "Unknown format"); buf_release(buf); return NULL; } pixmap_t *pm = pixmap_alloc_coded(p, buf->b_size, fmt); if(pm != NULL) { pm->pm_width = width; pm->pm_height = height; pm->pm_orientation = orientation; } else { snprintf(errbuf, errlen, "Out of memory"); } buf_release(buf); return pm; }