ImBuf * imb_load_jpeg (unsigned char * buffer, size_t size, int flags) { struct jpeg_decompress_struct _cinfo, *cinfo = &_cinfo; struct my_error_mgr jerr; ImBuf * ibuf; if(!imb_is_a_jpeg(buffer)) return NULL; cinfo->err = jpeg_std_error(&jerr.pub); jerr.pub.error_exit = jpeg_error; /* Establish the setjmp return context for my_error_exit to use. */ if (setjmp(jerr.setjmp_buffer)) { /* If we get here, the JPEG code has signaled an error. * We need to clean up the JPEG object, close the input file, and return. */ jpeg_destroy_decompress(cinfo); return NULL; } jpeg_create_decompress(cinfo); memory_source(cinfo, buffer, size); ibuf = ibJpegImageFromCinfo(cinfo, flags); return(ibuf); }
ImBuf *IMB_ibImageFromMemory(int *mem, int size, int flags) { int len; struct ImBuf *ibuf; if (mem == NULL) { printf("Error in ibImageFromMemory: NULL pointer\n"); } else { if ((GS(mem) == IMAGIC) || (GSS(mem) == IMAGIC)) { return (imb_loadiris((uchar *) mem, flags)); } else if (imb_is_a_jpeg((uchar *)mem)) { return (imb_ibJpegImageFromMemory((uchar *)mem, size, flags)); } if (GET_ID(mem) == CAT) { mem += 3; size -= 4; while (size > 0) { if (GET_ID(mem) == FORM) { len = ((GET_BIG_LONG(mem+1) + 1) & ~1) + 8; if ((GET_ID(mem+2) == ILBM) || (GET_ID(mem+2) == ANIM)) break; mem = (int *)((uchar *)mem +len); size -= len; } else return(0); } } if (size > 0) { if (GET_ID(mem) == FORM) { if (GET_ID(mem+2) == ILBM) { return (imb_loadamiga(mem, flags)); } else if (GET_ID(mem+5) == ILBM) { /* animaties */ return (imb_loadamiga(mem+3, flags)); } else if (GET_ID(mem+2) == ANIM) { return (imb_loadanim(mem, flags)); } } } ibuf = imb_loadpng((uchar *)mem, size, flags); if (ibuf) return(ibuf); ibuf = imb_bmp_decode((uchar *)mem, size, flags); if (ibuf) return(ibuf); ibuf = imb_loadtarga((uchar *)mem, size, flags); if (ibuf) return(ibuf); ibuf = imb_loaddpx((uchar *)mem, size, flags); if (ibuf) return(ibuf); ibuf = imb_loadcineon((uchar *)mem, size, flags); if (ibuf) return(ibuf); if (G.have_libtiff) { ibuf = imb_loadtiff((uchar *)mem, size, flags); if (ibuf) return(ibuf); } ibuf = imb_loadhdr((uchar*)mem, size, flags); if (ibuf) return (ibuf); #ifdef WITH_OPENEXR ibuf = imb_load_openexr((uchar *)mem, size, flags); if (ibuf) return (ibuf); #endif #ifdef WITH_OPENJPEG ibuf = imb_jp2_decode((uchar *)mem, size, flags); if (ibuf) return (ibuf); #endif #ifdef WITH_DDS ibuf = imb_load_dds((uchar *)mem, size, flags); if (ibuf) return (ibuf); #endif #ifdef WITH_QUICKTIME #if defined(_WIN32) || defined (__APPLE__) if(G.have_quicktime) { ibuf = imb_quicktime_decode((uchar *)mem, size, flags); if (ibuf) return(ibuf); } #endif #endif if (IB_verbose) fprintf(stderr, "Unknown fileformat\n"); } return (0); }