Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBrecht Van Lommel <brechtvanlommel@pandora.be>2010-05-07 19:18:04 +0400
committerBrecht Van Lommel <brechtvanlommel@pandora.be>2010-05-07 19:18:04 +0400
commit008863daec1249d1f17bc69e1105e336db690d63 (patch)
tree78a4001857b26a287125a3f5fa31496052f6ebdd /source/blender/imbuf/intern/readimage.c
parent1613829e8e821321da99cad4790b7e6a1d90cea8 (diff)
Merge image related changes from the render branch. This includes the image
tile cache code in imbuf, but it is not hooked up to the render engine. Imbuf module: some small refactoring and removing a lot of unused or old code (about 6.5k lines). * Added a ImFileType struct with callbacks to make adding an file format type, or making changes to the API easier. * Move imbuf init/exit code into IMB_init()/IMB_exit() functions. * Increased mipmap levels from 10 to 20, you run into this limit already with a 2k image. * Removed hamx, amiga, anim5 format support. * Removed colormap saving, only simple colormap code now for reading tga. * Removed gen_dynlibtiff.py, editing this is almost as much work as just editing the code directly. * Functions removed that were only used for sequencer plugin API: IMB_anim_nextpic, IMB_clever_double, IMB_antialias, IMB_gamwarp, IMB_scalefieldImBuf, IMB_scalefastfieldImBuf, IMB_onethird, IMB_halflace, IMB_dit0, IMB_dit2, IMB_cspace * Write metadata info into OpenEXR images. Can be viewed with the command line utility 'exrheader' For the image tile cache code, see this page: http://wiki.blender.org/index.php/Dev:2.5/Source/Imaging/ImageTileCache
Diffstat (limited to 'source/blender/imbuf/intern/readimage.c')
-rw-r--r--source/blender/imbuf/intern/readimage.c326
1 files changed, 105 insertions, 221 deletions
diff --git a/source/blender/imbuf/intern/readimage.c b/source/blender/imbuf/intern/readimage.c
index c23daacb919..3f4e177c78b 100644
--- a/source/blender/imbuf/intern/readimage.c
+++ b/source/blender/imbuf/intern/readimage.c
@@ -42,275 +42,159 @@
#include "BLI_blenlib.h"
#include "imbuf.h"
-#include "imbuf_patch.h"
#include "IMB_imbuf_types.h"
#include "IMB_imbuf.h"
+#include "IMB_filetype.h"
-#include "IMB_amiga.h"
-#include "IMB_iris.h"
-#include "IMB_targa.h"
-#include "IMB_png.h"
-#include "IMB_hamx.h"
-#include "IMB_jpeg.h"
-#include "IMB_bmp.h"
-#include "IMB_radiance_hdr.h"
-#include "IMB_dpxcineon.h"
-#include "BKE_global.h"
-
-#if defined(__APPLE__) && defined(IMBUF_COCOA)
-#include "IMB_cocoa.h"
-#else
-#include "IMB_tiff.h"
-#endif
-
-#ifdef WITH_OPENJPEG
-#include "IMB_jp2.h"
-#endif
-
-#ifdef WITH_OPENEXR
-#include "openexr/openexr_api.h"
-#endif
-
-#ifdef WITH_DDS
-#include "dds/dds_api.h"
-#endif
+ImBuf *IMB_ibImageFromMemory(unsigned char *mem, int size, int flags)
+{
+ ImBuf *ibuf;
+ ImFileType *type;
-#ifdef WITH_QUICKTIME
-#if defined(_WIN32) || defined (__APPLE__)
-#include "quicktime_import.h"
-#endif
-#endif
-
-/* actually hard coded endianness */
-#define GET_BIG_LONG(x) (((uchar *) (x))[0] << 24 | ((uchar *) (x))[1] << 16 | ((uchar *) (x))[2] << 8 | ((uchar *) (x))[3])
-#define GET_LITTLE_LONG(x) (((uchar *) (x))[3] << 24 | ((uchar *) (x))[2] << 16 | ((uchar *) (x))[1] << 8 | ((uchar *) (x))[0])
-#define SWAP_L(x) (((x << 24) & 0xff000000) | ((x << 8) & 0xff0000) | ((x >> 8) & 0xff00) | ((x >> 24) & 0xff))
-#define SWAP_S(x) (((x << 8) & 0xff00) | ((x >> 8) & 0xff))
-
-/* more endianness... should move to a separate file... */
-#if defined(__sgi) || defined (__sparc) || defined (__sparc__) || defined (__PPC__) || defined (__ppc__) || defined(__hppa__) || defined (__BIG_ENDIAN__)
-#define GET_ID GET_BIG_LONG
-#define LITTLE_LONG SWAP_LONG
-#else
-#define GET_ID GET_LITTLE_LONG
-#define LITTLE_LONG ENDIAN_NOP
-#endif
-
-/* from misc_util: flip the bytes from x */
-#define GS(x) (((unsigned char *)(x))[0] << 8 | ((unsigned char *)(x))[1])
-
-/* this one is only def-ed once, strangely... */
-#define GSS(x) (((uchar *)(x))[1] << 8 | ((uchar *)(x))[0])
-
-int IB_verbose = TRUE;
+ if(mem == NULL) {
+ printf("Error in ibImageFromMemory: NULL pointer\n");
+ return NULL;
+ }
-ImBuf *IMB_ibImageFromMemory(int *mem, int size, int flags) {
- int len;
- struct ImBuf *ibuf;
+ for(type=IMB_FILE_TYPES; type->is_a; type++) {
+ if(type->load) {
+ ibuf= type->load(mem, size, flags);
+ if(ibuf) {
+ if(flags & IB_premul) {
+ IMB_premultiply_alpha(ibuf);
+ ibuf->flags |= IB_premul;
+ }
- 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);
+ return ibuf;
}
}
+ }
+
+ fprintf(stderr, "Unknown fileformat\n");
- 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));
- }
- }
- }
+ return NULL;
+}
- ibuf = imb_loadpng((uchar *)mem, size, flags);
- if (ibuf) return(ibuf);
+ImBuf *IMB_loadifffile(int file, int flags)
+{
+ ImBuf *ibuf;
+ unsigned char *mem;
+ int size;
- ibuf = imb_bmp_decode((uchar *)mem, size, flags);
- if (ibuf) return(ibuf);
+ if(file == -1) return 0;
- ibuf = imb_loadtarga((uchar *)mem, size, flags);
- if (ibuf) return(ibuf);
+ size= BLI_filesize(file);
- ibuf = imb_loaddpx((uchar *)mem, size, flags);
- if (ibuf) return(ibuf);
+ mem= mmap(0, size, PROT_READ, MAP_SHARED, file, 0);
+ if(mem==(unsigned char*)-1) {
+ fprintf(stderr, "Couldn't get mapping\n");
+ return 0;
+ }
- ibuf = imb_loadcineon((uchar *)mem, size, flags);
- if (ibuf) return(ibuf);
-
-#if defined(__APPLE__) && defined(IMBUF_COCOA)
- ibuf = imb_cocoaLoadImage((uchar *)mem, size, flags);
- if(ibuf) {
- ibuf->ftype = TIF;
- ibuf->profile = IB_PROFILE_SRGB;
- return ibuf;
- }
-#else
- if (G.have_libtiff) {
- ibuf = imb_loadtiff((uchar *)mem, size, flags);
- if (ibuf) return(ibuf);
- }
-#endif
-
- ibuf = imb_loadhdr((uchar*)mem, size, flags);
- if (ibuf) return (ibuf);
+ ibuf= IMB_ibImageFromMemory(mem, size, flags);
-#ifdef WITH_OPENEXR
- ibuf = imb_load_openexr((uchar *)mem, size, flags);
- if (ibuf) return (ibuf);
-#endif
+ if(munmap(mem, size))
+ fprintf(stderr, "Couldn't unmap file.\n");
-#ifdef WITH_OPENJPEG
- ibuf = imb_jp2_decode((uchar *)mem, size, flags);
- if (ibuf) return (ibuf);
-#endif
+ return ibuf;
+}
-#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
+static void imb_cache_filename(char *filename, const char *name, int flags)
+{
+ /* read .tx instead if it exists and is not older */
+ if(flags & IB_tilecache) {
+ BLI_strncpy(filename, name, IB_FILENAME_SIZE);
+ if(!BLI_replace_extension(filename, IB_FILENAME_SIZE, ".tx"))
+ return;
- if (IB_verbose) fprintf(stderr, "Unknown fileformat\n");
+ if(BLI_file_older(name, filename))
+ return;
}
-
- return (0);
+
+ BLI_strncpy(filename, name, IB_FILENAME_SIZE);
}
+ImBuf *IMB_loadiffname(const char *name, int flags)
+{
+ ImBuf *ibuf;
+ int file, a;
+ char filename[IB_FILENAME_SIZE];
-struct ImBuf *IMB_loadiffmem(int *mem, int flags) {
- int len,maxlen;
- struct ImBuf *ibuf;
+ imb_cache_filename(filename, name, flags);
- // IMB_loadiffmem shouldn't be used anymore in new development
- // it's still here to be backwards compatible...
+ file = open(filename, O_BINARY|O_RDONLY);
+ if(file < 0) return 0;
- maxlen= (GET_BIG_LONG(mem+1) + 1) & ~1;
+ ibuf= IMB_loadifffile(file, flags);
- if (GET_ID(mem) == CAT){
- mem += 3;
- maxlen -= 4;
- while(maxlen > 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);
- maxlen -= len;
- } else return(0);
- }
+ if(ibuf) {
+ BLI_strncpy(ibuf->name, name, sizeof(ibuf->name));
+ BLI_strncpy(ibuf->cachename, filename, sizeof(ibuf->cachename));
+ for(a=1; a<ibuf->miptot; a++)
+ BLI_strncpy(ibuf->mipmap[a-1]->cachename, filename, sizeof(ibuf->cachename));
+ if(flags & IB_fields) IMB_de_interlace(ibuf);
}
- if (maxlen > 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));
- }
- } else if ((GS(mem) == IMAGIC) || (GSS(mem) == IMAGIC)){
- return (imb_loadiris((uchar *) mem,flags));
- } else if ((BIG_LONG(mem[0]) & 0xfffffff0) == 0xffd8ffe0) {
- return (0);
- }
- }
-
- ibuf = imb_loadtarga((uchar *) mem,maxlen,flags);
- if (ibuf) return(ibuf);
+ close(file);
- if (IB_verbose) fprintf(stderr,"Unknown fileformat\n");
- return (0);
+ return ibuf;
}
-struct ImBuf *IMB_loadifffile(int file, int flags) {
- struct ImBuf *ibuf;
- int size, *mem;
+ImBuf *IMB_testiffname(char *name, int flags)
+{
+ ImBuf *ibuf;
+ int file;
+ char filename[IB_FILENAME_SIZE];
- if (file == -1) return (0);
+ imb_cache_filename(filename, name, flags);
- size = BLI_filesize(file);
+ file = open(filename,O_BINARY|O_RDONLY);
+ if(file < 0) return 0;
- mem= (int *)mmap(0,size,PROT_READ,MAP_SHARED,file,0);
- if (mem==(int *)-1){
- printf("Couldn't get mapping\n");
- return (0);
+ ibuf=IMB_loadifffile(file, flags|IB_test);
+ if(ibuf) {
+ BLI_strncpy(ibuf->name, name, sizeof(ibuf->name));
+ BLI_strncpy(ibuf->cachename, filename, sizeof(ibuf->cachename));
}
- ibuf = IMB_ibImageFromMemory(mem, size, flags);
+ close(file);
- if (munmap( (void *) mem, size)){
- printf("Couldn't unmap file.\n");
- }
- return(ibuf);
+ return ibuf;
}
+static void imb_loadtilefile(ImBuf *ibuf, int file, int tx, int ty, unsigned int *rect)
+{
+ ImFileType *type;
+ unsigned char *mem;
+ int size;
-struct ImBuf *IMB_loadiffname(const char *naam, int flags) {
- int file;
- struct ImBuf *ibuf;
- int buf[1];
-
- file = open(naam, O_BINARY|O_RDONLY);
-
- if (file < 0) return (0);
+ if(file == -1) return;
- ibuf= IMB_loadifffile(file, flags);
+ size= BLI_filesize(file);
- if (ibuf == NULL) {
- if (read(file, buf, 4) != 4) buf[0] = 0;
- if ((BIG_LONG(buf[0]) & 0xfffffff0) == 0xffd8ffe0)
- ibuf = imb_ibJpegImageFromFilename(naam, flags);
+ mem= mmap(0, size, PROT_READ, MAP_SHARED, file, 0);
+ if(mem==(unsigned char*)-1) {
+ fprintf(stderr, "Couldn't get memory mapping for %s\n", ibuf->cachename);
+ return;
}
- if (ibuf) {
- strncpy(ibuf->name, naam, sizeof(ibuf->name));
- if (flags & IB_fields) IMB_de_interlace(ibuf);
- }
- close(file);
- return(ibuf);
+ for(type=IMB_FILE_TYPES; type->is_a; type++)
+ if(type->load_tile && type->ftype(type, ibuf))
+ type->load_tile(ibuf, mem, size, tx, ty, rect);
+
+ if(munmap(mem, size))
+ fprintf(stderr, "Couldn't unmap memory for %s.\n", ibuf->cachename);
}
-struct ImBuf *IMB_testiffname(char *naam,int flags) {
+void imb_loadtile(ImBuf *ibuf, int tx, int ty, unsigned int *rect)
+{
int file;
- struct ImBuf *ibuf;
- flags |= IB_test;
- file = open(naam,O_BINARY|O_RDONLY);
+ file = open(ibuf->cachename, O_BINARY|O_RDONLY);
+ if(file < 0) return;
- if (file < 0) return (0);
+ imb_loadtilefile(ibuf, file, tx, ty, rect);
- ibuf=IMB_loadifffile(file,flags);
- if (ibuf) {
- strncpy(ibuf->name, naam, sizeof(ibuf->name));
- }
close(file);
- return(ibuf);
}
+