From 014aa7261e29810b35b3d65c759f9d255bf8a277 Mon Sep 17 00:00:00 2001 From: Ton Roosendaal Date: Mon, 9 Jan 2006 00:40:35 +0000 Subject: Orange branch: OpenEXR finally in Blender! Credits go to Gernot Ziegler, who originally coded EXR support, and to Austin Benesh for bringing it further. Kent Mein provided a lot of code for integrating float buffers in Blender imbuf and ImBuf API cleanup, and provided Make and Scons and static linking. At this moment; the EXR libraries are a *dependency*, so you cannot get the Orange branch compiled without having OpenEXR installed. Get the (precompiled or sources) stuff from www.openexr.com. Current default is that the headers and lib resides in /user/local/ Several changes/additions/fixes were added: - EXR code only supported 'half' format (16 bits per channel). I've added float writing, but for reading it I need tomorrow. :) - Quite some clumsy copying of data happened in EXR code. - cleaned up the api calls already a bit, preparing for more advanced support - Zbuffers were saved 16 bits, now 32 bits - automatic adding of .exr extensions went wrong Imbuf: - added proper imbuf->flags and imbuf->mall support for float buffers, it was created for *each* imbuf. :) - found bugs for float buffers in scaling and flipping. Code there will need more checks still - imbuf also needs to be verified to behave properly when no 32 bits rect exists (for saving for example) TODO: - support internal float images for textures, backbuf, AO probes, and display in Image window Hope this commit won't screwup syncing with bf-blender... :/ --- source/blender/imbuf/intern/IMB_allocimbuf.h | 2 + source/blender/imbuf/intern/Makefile | 12 + source/blender/imbuf/intern/allocimbuf.c | 131 ++++-- source/blender/imbuf/intern/amiga.c | 2 +- source/blender/imbuf/intern/anim.c | 2 +- source/blender/imbuf/intern/anim5.c | 2 +- source/blender/imbuf/intern/bitplanes.c | 6 +- source/blender/imbuf/intern/divers.c | 31 +- source/blender/imbuf/intern/filter.c | 74 ++- source/blender/imbuf/intern/imageprocess.c | 20 +- source/blender/imbuf/intern/iris.c | 6 +- source/blender/imbuf/intern/jpeg.c | 7 +- source/blender/imbuf/intern/openexr/Makefile | 51 ++ source/blender/imbuf/intern/openexr/SConscript | 22 + .../blender/imbuf/intern/openexr/openexr_api.cpp | 441 ++++++++++++++++++ source/blender/imbuf/intern/openexr/openexr_api.h | 63 +++ source/blender/imbuf/intern/radiance_hdr.c | 126 ++--- source/blender/imbuf/intern/readimage.c | 7 + source/blender/imbuf/intern/rectop.c | 77 +-- source/blender/imbuf/intern/rotate.c | 42 +- source/blender/imbuf/intern/scaling.c | 517 +++++++++++++++++---- source/blender/imbuf/intern/targa.c | 6 +- source/blender/imbuf/intern/tiff.c | 2 +- source/blender/imbuf/intern/util.c | 8 +- source/blender/imbuf/intern/writeimage.c | 27 +- 25 files changed, 1388 insertions(+), 296 deletions(-) create mode 100644 source/blender/imbuf/intern/openexr/Makefile create mode 100644 source/blender/imbuf/intern/openexr/SConscript create mode 100644 source/blender/imbuf/intern/openexr/openexr_api.cpp create mode 100644 source/blender/imbuf/intern/openexr/openexr_api.h (limited to 'source/blender/imbuf/intern') diff --git a/source/blender/imbuf/intern/IMB_allocimbuf.h b/source/blender/imbuf/intern/IMB_allocimbuf.h index c01c9d60dd7..7ff44ef29f9 100644 --- a/source/blender/imbuf/intern/IMB_allocimbuf.h +++ b/source/blender/imbuf/intern/IMB_allocimbuf.h @@ -43,12 +43,14 @@ struct ImBuf; short imb_addrectImBuf(struct ImBuf * ibuf); +short imb_addrectfloatImBuf(struct ImBuf * ibuf); short imb_addplanesImBuf(struct ImBuf *ibuf); short imb_addencodedbufferImBuf(struct ImBuf *ibuf); short imb_enlargeencodedbufferImBuf(struct ImBuf *ibuf); void imb_freerectImBuf(struct ImBuf *ibuf); +void imb_freerectfloatImBuf(struct ImBuf *ibuf); void imb_freeplanesImBuf(struct ImBuf *ibuf); short imb_addcmapImBuf(struct ImBuf *ibuf); diff --git a/source/blender/imbuf/intern/Makefile b/source/blender/imbuf/intern/Makefile index 859f7c4cd34..839bb4df4c3 100644 --- a/source/blender/imbuf/intern/Makefile +++ b/source/blender/imbuf/intern/Makefile @@ -33,13 +33,25 @@ LIBNAME = imbuf DIR = $(OCGDIR)/blender/imbuf +SOURCEDIR = source/blender/imbuf/intern +include nan_subdirs.mk include nan_compile.mk +include nan_definitions.mk + +ifeq ($(WITH_OPENEXR), true) + DIRS = openexr +endif + ifeq ($(OS),$(findstring $(OS), "beos darwin freebsd linux openbsd solaris windows")) CFLAGS += -funsigned-char endif +ifeq ($(WITH_OPENEXR), true) + CFLAGS += -DWITH_OPENEXR +endif + CFLAGS += $(LEVEL_1_C_WARNINGS) CPPFLAGS += -I$(NAN_JPEG)/include diff --git a/source/blender/imbuf/intern/allocimbuf.c b/source/blender/imbuf/intern/allocimbuf.c index 3178e15ffee..8344e9753a2 100644 --- a/source/blender/imbuf/intern/allocimbuf.c +++ b/source/blender/imbuf/intern/allocimbuf.c @@ -53,30 +53,48 @@ static unsigned int dfltcmap[16] = { void imb_freeplanesImBuf(struct ImBuf * ibuf) { - if (ibuf==0) return; + if (ibuf==NULL) return; if (ibuf->planes){ - if (ibuf->mall & IB_planes) free(ibuf->planes); + if (ibuf->mall & IB_planes) MEM_freeN(ibuf->planes); } ibuf->planes = 0; ibuf->mall &= ~IB_planes; } +void imb_freerectfloatImBuf(struct ImBuf * ibuf) +{ + if (ibuf==NULL) return; + + if (ibuf->rect_float) { + if (ibuf->mall & IB_rectfloat) { + MEM_freeN(ibuf->rect_float); + ibuf->rect_float=NULL; + } + } + + ibuf->rect_float= NULL; + ibuf->mall &= ~IB_rectfloat; +} void imb_freerectImBuf(struct ImBuf * ibuf) { - if (ibuf==0) return; - if (ibuf->rect){ - if (ibuf->mall & IB_rect) free(ibuf->rect); + if (ibuf==NULL) return; + + if (ibuf->rect) { + if (ibuf->mall & IB_rect) { + MEM_freeN(ibuf->rect); + } } - ibuf->rect=0; + + ibuf->rect= NULL; ibuf->mall &= ~IB_rect; } static void freeencodedbufferImBuf(struct ImBuf * ibuf) { - if (ibuf==0) return; + if (ibuf==NULL) return; if (ibuf->encodedbuffer){ - if (ibuf->mall & IB_mem) free(ibuf->encodedbuffer); + if (ibuf->mall & IB_mem) MEM_freeN(ibuf->encodedbuffer); } ibuf->encodedbuffer = 0; ibuf->encodedbuffersize = 0; @@ -86,34 +104,34 @@ static void freeencodedbufferImBuf(struct ImBuf * ibuf) void IMB_freezbufImBuf(struct ImBuf * ibuf) { - if (ibuf==0) return; + if (ibuf==NULL) return; if (ibuf->zbuf){ - if (ibuf->mall & IB_zbuf) free(ibuf->zbuf); + if (ibuf->mall & IB_zbuf) MEM_freeN(ibuf->zbuf); } - ibuf->zbuf=0; + ibuf->zbuf= NULL; ibuf->mall &= ~IB_zbuf; } void IMB_freecmapImBuf(struct ImBuf * ibuf) { - if (ibuf == 0) return; + if (ibuf==NULL) return; if (ibuf->cmap){ - if (ibuf->mall & IB_cmap) free(ibuf->cmap); + if (ibuf->mall & IB_cmap) MEM_freeN(ibuf->cmap); } ibuf->cmap = 0; ibuf->mall &= ~IB_cmap; } - void IMB_freeImBuf(struct ImBuf * ibuf) { if (ibuf){ imb_freeplanesImBuf(ibuf); imb_freerectImBuf(ibuf); + imb_freerectfloatImBuf(ibuf); IMB_freezbufImBuf(ibuf); IMB_freecmapImBuf(ibuf); freeencodedbufferImBuf(ibuf); - free(ibuf); + MEM_freeN(ibuf); } } @@ -121,7 +139,8 @@ short addzbufImBuf(struct ImBuf * ibuf) { int size; - if (ibuf==0) return(FALSE); + if (ibuf==NULL) return(FALSE); + IMB_freezbufImBuf(ibuf); size = ibuf->x * ibuf->y * sizeof(unsigned int); @@ -136,7 +155,7 @@ short addzbufImBuf(struct ImBuf * ibuf) short imb_addencodedbufferImBuf(struct ImBuf * ibuf) { - if (ibuf==0) return(FALSE); + if (ibuf==NULL) return(FALSE); freeencodedbufferImBuf(ibuf); @@ -159,7 +178,7 @@ short imb_enlargeencodedbufferImBuf(struct ImBuf * ibuf) unsigned int newsize, encodedsize; void *newbuffer; - if (ibuf==0) return(FALSE); + if (ibuf==NULL) return(FALSE); if (ibuf->encodedbuffersize < ibuf->encodedsize) { printf("imb_enlargeencodedbufferImBuf: error in parameters\n"); @@ -190,15 +209,36 @@ short imb_enlargeencodedbufferImBuf(struct ImBuf * ibuf) return (TRUE); } +short imb_addrectfloatImBuf(struct ImBuf * ibuf) +{ + int size; + + if (ibuf==NULL) return(FALSE); + + imb_freerectfloatImBuf(ibuf); + + size = ibuf->x * ibuf->y; + size = size * 4 * sizeof(float); + + if ( (ibuf->rect_float = MEM_mallocN(size, "imb_addrectImBuf")) ){ + ibuf->mall |= IB_rectfloat; + return (TRUE); + } + + return (FALSE); +} +/* question; why also add zbuf? */ short imb_addrectImBuf(struct ImBuf * ibuf) { int size; - if (ibuf==0) return(FALSE); + if (ibuf==NULL) return(FALSE); imb_freerectImBuf(ibuf); - size = ibuf->x * ibuf->y * sizeof(unsigned int); + size = ibuf->x * ibuf->y; + size = size * sizeof(unsigned int); + if ( (ibuf->rect = MEM_mallocN(size, "imb_addrectImBuf")) ){ ibuf->mall |= IB_rect; if (ibuf->depth > 32) return (addzbufImBuf(ibuf)); @@ -213,7 +253,7 @@ short imb_addcmapImBuf(struct ImBuf *ibuf) { int min; - if (ibuf==0) return(FALSE); + if (ibuf==NULL) return(FALSE); IMB_freecmapImBuf(ibuf); imb_checkncols(ibuf); @@ -238,7 +278,7 @@ short imb_addplanesImBuf(struct ImBuf *ibuf) unsigned int **planes; unsigned int *point2; - if (ibuf==0) return(FALSE); + if (ibuf==NULL) return(FALSE); imb_freeplanesImBuf(ibuf); skipx = ((ibuf->x+31) >> 5); @@ -264,7 +304,7 @@ short imb_addplanesImBuf(struct ImBuf *ibuf) } -struct ImBuf *IMB_allocImBuf(short x,short y,uchar d,unsigned int flags,uchar bitmap) +struct ImBuf *IMB_allocImBuf(short x, short y, uchar d, unsigned int flags, uchar bitmap) { struct ImBuf *ibuf; @@ -272,29 +312,36 @@ struct ImBuf *IMB_allocImBuf(short x,short y,uchar d,unsigned int flags,uchar bi if (bitmap) flags |= IB_planes; if (ibuf){ - ibuf->x=x; - ibuf->y=y; - ibuf->depth=d; - ibuf->ftype=TGA; + ibuf->x= x; + ibuf->y= y; + ibuf->depth= d; + ibuf->ftype= TGA; if (flags & IB_rect){ if (imb_addrectImBuf(ibuf)==FALSE){ IMB_freeImBuf(ibuf); - return (0); + return NULL; + } + } + + if (flags & IB_rectfloat){ + if (imb_addrectfloatImBuf(ibuf)==FALSE){ + IMB_freeImBuf(ibuf); + return NULL; } } if (flags & IB_zbuf){ if (addzbufImBuf(ibuf)==FALSE){ IMB_freeImBuf(ibuf); - return (0); + return NULL; } } if (flags & IB_planes){ if (imb_addplanesImBuf(ibuf)==FALSE){ IMB_freeImBuf(ibuf); - return (0); + return NULL; } } } @@ -307,9 +354,10 @@ struct ImBuf *IMB_dupImBuf(struct ImBuf *ibuf1) int flags = 0; int x, y; - if (ibuf1 == 0) return (0); + if (ibuf1 == NULL) return NULL; if (ibuf1->rect) flags |= IB_rect; + if (ibuf1->rect_float) flags |= IB_rectfloat; if (ibuf1->planes) flags |= IB_planes; x = ibuf1->x; @@ -317,31 +365,38 @@ struct ImBuf *IMB_dupImBuf(struct ImBuf *ibuf1) if (ibuf1->flags & IB_fields) y *= 2; ibuf2 = IMB_allocImBuf(x, y, ibuf1->depth, flags, 0); - if (ibuf2 == 0) return (0); + if (ibuf2 == NULL) return NULL; - if (flags & IB_rect) memcpy(ibuf2->rect,ibuf1->rect,x * y * sizeof(int)); - if (flags & IB_planes) memcpy(*(ibuf2->planes),*(ibuf1->planes),ibuf1->depth * ibuf1->skipx * y * sizeof(int)); + if (flags & IB_rect) + memcpy(ibuf2->rect, ibuf1->rect, x * y * sizeof(int)); + + if (flags & IB_rectfloat) + memcpy(ibuf2->rect_float, ibuf1->rect_float, x * y * sizeof(float)); + + if (flags & IB_planes) + memcpy(*(ibuf2->planes),*(ibuf1->planes),ibuf1->depth * ibuf1->skipx * y * sizeof(int)); if (ibuf1->encodedbuffer) { ibuf2->encodedbuffersize = ibuf1->encodedbuffersize; if (imb_addencodedbufferImBuf(ibuf2) == FALSE) { IMB_freeImBuf(ibuf2); - return(0); + return NULL; } memcpy(ibuf2->encodedbuffer, ibuf1->encodedbuffer, ibuf1->encodedsize); } - + /* silly trick to copy the entire contents of ibuf1 struct over to ibuf */ tbuf = *ibuf1; - // pointers goedzetten + // fix pointers tbuf.rect = ibuf2->rect; + tbuf.rect_float = ibuf2->rect_float; tbuf.planes = ibuf2->planes; tbuf.cmap = ibuf2->cmap; tbuf.encodedbuffer = ibuf2->encodedbuffer; - // malloc flag goed zetten + // set malloc flag tbuf.mall = ibuf2->mall; *ibuf2 = tbuf; diff --git a/source/blender/imbuf/intern/amiga.c b/source/blender/imbuf/intern/amiga.c index 20655b3a211..d0b794c23ec 100644 --- a/source/blender/imbuf/intern/amiga.c +++ b/source/blender/imbuf/intern/amiga.c @@ -531,7 +531,7 @@ struct ImBuf *imb_loadamiga(int *iffmem,int flags) if (ibuf) { if (ibuf->rect) - if (G.order == B_ENDIAN) IMB_convert_rgba_to_abgr(ibuf->x*ibuf->y, ibuf->rect); + if (G.order == B_ENDIAN) IMB_convert_rgba_to_abgr(ibuf); } return (ibuf); diff --git a/source/blender/imbuf/intern/anim.c b/source/blender/imbuf/intern/anim.c index 284339ece48..51fadc5c06a 100644 --- a/source/blender/imbuf/intern/anim.c +++ b/source/blender/imbuf/intern/anim.c @@ -572,7 +572,7 @@ struct ImBuf * IMB_anim_absolute(struct anim * anim, int position) { ibuf = movie_fetchibuf(anim, position); if (ibuf) { anim->curposition = position; - IMB_convert_rgba_to_abgr(ibuf->x*ibuf->y, ibuf->rect); + IMB_convert_rgba_to_abgr(ibuf); } break; case ANIM_AVI: diff --git a/source/blender/imbuf/intern/anim5.c b/source/blender/imbuf/intern/anim5.c index 9f87ba09f5f..89ddf177efe 100644 --- a/source/blender/imbuf/intern/anim5.c +++ b/source/blender/imbuf/intern/anim5.c @@ -161,7 +161,7 @@ static void planes_to_rect(struct ImBuf * ibuf, int flags) { if (ibuf->cmap){ if ((flags & IB_cmap) == 0) { IMB_applycmap(ibuf); - IMB_convert_rgba_to_abgr(ibuf->x*ibuf->y, ibuf->rect); + IMB_convert_rgba_to_abgr(ibuf); } } else if (ibuf->depth == 18){ int i,col; diff --git a/source/blender/imbuf/intern/bitplanes.c b/source/blender/imbuf/intern/bitplanes.c index 6bc2155c949..b80e829da08 100644 --- a/source/blender/imbuf/intern/bitplanes.c +++ b/source/blender/imbuf/intern/bitplanes.c @@ -178,6 +178,8 @@ void imb_bptolong(struct ImBuf *ibuf) { int nobp,i,x; unsigned int *rect,offset; + float black[4] = {0.0,0.0,0.0,1.0}; + float clear[4] = {0.0,0.0,0.0,0.0}; /* first clear all ints */ @@ -187,8 +189,8 @@ void imb_bptolong(struct ImBuf *ibuf) nobp=ibuf->depth; if (nobp != 32){ - if (nobp == 24) IMB_rectoptot(ibuf, 0, IMB_rectfill, 0xff000000); /* set alpha */ - else IMB_rectoptot(ibuf, 0, IMB_rectfill, 0); + if (nobp == 24) IMB_rectfill(ibuf, black); /* set alpha */ + else IMB_rectfill(ibuf, clear); } rect= ibuf->rect; diff --git a/source/blender/imbuf/intern/divers.c b/source/blender/imbuf/intern/divers.c index 8c579156691..a56f16f71db 100644 --- a/source/blender/imbuf/intern/divers.c +++ b/source/blender/imbuf/intern/divers.c @@ -95,12 +95,12 @@ void IMB_de_interlace(struct ImBuf *ibuf) tbuf2 = IMB_allocImBuf(ibuf->x, ibuf->y / 2, 32, IB_rect, 0); ibuf->x *= 2; - IMB_rectop(tbuf1, ibuf, 0, 0, 0, 0, 32767, 32767, IMB_rectcpy, 0); - IMB_rectop(tbuf2, ibuf, 0, 0, tbuf2->x, 0, 32767, 32767, IMB_rectcpy, 0); + IMB_rectcpy(tbuf1, ibuf, 0, 0, 0, 0, ibuf->x, ibuf->y); + IMB_rectcpy(tbuf2, ibuf, 0, 0, tbuf2->x, 0, ibuf->x, ibuf->y); ibuf->x /= 2; - IMB_rectop(ibuf, tbuf1, 0, 0, 0, 0, 32767, 32767, IMB_rectcpy, 0); - IMB_rectop(ibuf, tbuf2, 0, tbuf2->y, 0, 0, 32767, 32767, IMB_rectcpy, 0); + IMB_rectcpy(ibuf, tbuf1, 0, 0, 0, 0, tbuf1->x, tbuf1->y); + IMB_rectcpy(ibuf, tbuf2, 0, tbuf2->y, 0, 0, tbuf2->x, tbuf2->y); IMB_freeImBuf(tbuf1); IMB_freeImBuf(tbuf2); @@ -122,16 +122,12 @@ void IMB_interlace(struct ImBuf *ibuf) tbuf1 = IMB_allocImBuf(ibuf->x, ibuf->y / 2, 32, IB_rect, 0); tbuf2 = IMB_allocImBuf(ibuf->x, ibuf->y / 2, 32, IB_rect, 0); - IMB_rectop(tbuf1, ibuf, 0, 0, 0, 0, 32767, 32767, IMB_rectcpy, - 0); - IMB_rectop(tbuf2, ibuf, 0, 0, 0, tbuf2->y, 32767, 32767, - IMB_rectcpy,0); + IMB_rectcpy(tbuf1, ibuf, 0, 0, 0, 0, ibuf->x, ibuf->y); + IMB_rectcpy(tbuf2, ibuf, 0, 0, 0, tbuf2->y, ibuf->x, ibuf->y); ibuf->x *= 2; - IMB_rectop(ibuf, tbuf1, 0, 0, 0, 0, 32767, 32767, IMB_rectcpy, - 0); - IMB_rectop(ibuf, tbuf2, tbuf2->x, 0, 0, 0, 32767, 32767, - IMB_rectcpy,0); + IMB_rectcpy(ibuf, tbuf1, 0, 0, 0, 0, tbuf1->x, tbuf1->y); + IMB_rectcpy(ibuf, tbuf2, tbuf2->x, 0, 0, 0, tbuf2->x, tbuf2->y); ibuf->x /= 2; IMB_freeImBuf(tbuf1); @@ -143,11 +139,13 @@ void IMB_interlace(struct ImBuf *ibuf) void IMB_gamwarp(struct ImBuf *ibuf, double gamma) { uchar gam[256]; - int i; - uchar *rect; + int i, do_float=0; + uchar *rect = (uchar *) ibuf->rect; + float *rectf = ibuf->rect_float; if (ibuf == 0) return; if (ibuf->rect == 0) return; + if (ibuf->rect != NULL) do_float = 1; if (gamma == 1.0) return; gamma = 1.0 / gamma; @@ -159,5 +157,10 @@ void IMB_gamwarp(struct ImBuf *ibuf, double gamma) rect[0] = gam[rect[0]]; rect[1] = gam[rect[1]]; rect[2] = gam[rect[2]]; + if (do_float) { + rectf[0] = pow(rectf[0] / 255.0, gamma); + rectf[1] = pow(rectf[1] / 255.0, gamma); + rectf[2] = pow(rectf[2] / 255.0, gamma); + } } } diff --git a/source/blender/imbuf/intern/filter.c b/source/blender/imbuf/intern/filter.c index 8aea42c7008..e51f85ab2d6 100644 --- a/source/blender/imbuf/intern/filter.c +++ b/source/blender/imbuf/intern/filter.c @@ -65,6 +65,26 @@ static void filtrow(unsigned char *point, int x) } } +static void filtrowf(float *point, int x) +{ + float c1,c2,c3,error; + + if (x>1){ + c1 = c2 = *point; + error = 2; + for(x--;x>0;x--){ + c3 = point[4]; + c1 += (c2 * 2) + c3 + error; + *point = c1 / 4.0; + point += 4; + c1=c2; + c2=c3; + } + *point = (c1 + (c2 * 2) + c2 + error) / 4.0; + } +} + + static void filtcolum(unsigned char *point, int y, int skip) { @@ -89,13 +109,38 @@ static void filtcolum(unsigned char *point, int y, int skip) } } +static void filtcolumf(float *point, int y, int skip) +{ + float c1,c2,c3,error, *point2; + + if (y>1){ + c1 = c2 = *point; + point2 = point; + error = 2; + for(y--;y>0;y--){ + point2 += skip; + c3 = *point2; + c1 += (c2 * 2) + c3 +error; + *point = c1 / 4; + point=point2; + c1=c2; + c2=c3; + } + *point = (c1 + (c2 * 2) + c2 + error) / 4; + } +} void IMB_filtery(struct ImBuf *ibuf) { unsigned char *point; - int x, y, skip; + float *pointf; + int x, y, skip, do_float = 0; point = (unsigned char *)ibuf->rect; + pointf = ibuf->rect_float; + + if (ibuf->rect_float != NULL) do_float = 1; + x = ibuf->x; y = ibuf->y; skip = x<<2; @@ -109,6 +154,16 @@ void IMB_filtery(struct ImBuf *ibuf) point++; filtcolum(point,y,skip); point++; + if (do_float) { + if (ibuf->depth > 24) filtcolumf(pointf,y,skip); + pointf++; + filtcolumf(pointf,y,skip); + pointf++; + filtcolumf(pointf,y,skip); + pointf++; + filtcolumf(pointf,y,skip); + point++; + } } } @@ -116,9 +171,14 @@ void IMB_filtery(struct ImBuf *ibuf) void imb_filterx(struct ImBuf *ibuf) { unsigned char *point; - int x, y, skip; + float *pointf; + int x, y, skip, do_float =0; point = (unsigned char *)ibuf->rect; + pointf = ibuf->rect_float; + + if (ibuf->rect_float != NULL) do_float = 1; + x = ibuf->x; y = ibuf->y; skip = (x<<2) - 3; @@ -132,6 +192,16 @@ void imb_filterx(struct ImBuf *ibuf) point++; filtrow(point,x); point+=skip; + if (do_float) { + if (ibuf->depth > 24) filtrowf(pointf,x); + pointf++; + filtrowf(pointf,x); + pointf++; + filtrowf(pointf,x); + pointf++; + filtrowf(pointf,x); + pointf+=skip; + } } } diff --git a/source/blender/imbuf/intern/imageprocess.c b/source/blender/imbuf/intern/imageprocess.c index dcdd0692fc4..f98244c5a0f 100644 --- a/source/blender/imbuf/intern/imageprocess.c +++ b/source/blender/imbuf/intern/imageprocess.c @@ -40,13 +40,19 @@ * $Id$ */ +#include "IMB_imbuf_types.h" #include "IMB_imbuf.h" /* Only this one is used liberally here, and in imbuf */ -void IMB_convert_rgba_to_abgr(int size, unsigned int *rect) +void IMB_convert_rgba_to_abgr(struct ImBuf *ibuf) { - char *cp= (char *)rect, rt; + int size, do_float=0; + unsigned char rt, *cp = (unsigned char *)ibuf->rect; + float rtf, *cpf = ibuf->rect_float; + if (ibuf->rect_float) do_float = 1; + size = ibuf->x * ibuf->y; + while(size-- > 0) { rt= cp[0]; cp[0]= cp[3]; @@ -55,5 +61,15 @@ void IMB_convert_rgba_to_abgr(int size, unsigned int *rect) cp[1]= cp[2]; cp[2]= rt; cp+= 4; + if (do_float) { + rtf= cpf[0]; + cpf[0]= cpf[3]; + cpf[3]= rtf; + rtf= cpf[1]; + cpf[1]= cpf[2]; + cpf[2]= rtf; + cpf+= 4; + } } } + diff --git a/source/blender/imbuf/intern/iris.c b/source/blender/imbuf/intern/iris.c index 20aa9d75fd2..5c0a3f94a0e 100644 --- a/source/blender/imbuf/intern/iris.c +++ b/source/blender/imbuf/intern/iris.c @@ -398,7 +398,7 @@ struct ImBuf *imb_loadiris(unsigned char *mem, int flags) if (ibuf) { if (ibuf->rect) - IMB_convert_rgba_to_abgr(ibuf->x*ibuf->y, ibuf->rect); + IMB_convert_rgba_to_abgr(ibuf); } return(ibuf); @@ -639,13 +639,13 @@ short imb_saveiris(struct ImBuf * ibuf, char *name, int flags) zsize = (ibuf->depth + 7) >> 3; if (flags & IB_zbuf && ibuf->zbuf != 0) zsize = 8; - IMB_convert_rgba_to_abgr(ibuf->x*ibuf->y, ibuf->rect); + IMB_convert_rgba_to_abgr(ibuf); test_endian_zbuf(ibuf); ret = output_iris(ibuf->rect, ibuf->x, ibuf->y, zsize, name, ibuf->zbuf); /* restore! Quite clumsy, 2 times a switch... maybe better a malloc ? */ - IMB_convert_rgba_to_abgr(ibuf->x*ibuf->y, ibuf->rect); + IMB_convert_rgba_to_abgr(ibuf); test_endian_zbuf(ibuf); return(ret); diff --git a/source/blender/imbuf/intern/jpeg.c b/source/blender/imbuf/intern/jpeg.c index 34796bac9d5..afd1038a80f 100644 --- a/source/blender/imbuf/intern/jpeg.c +++ b/source/blender/imbuf/intern/jpeg.c @@ -553,15 +553,12 @@ static int save_jstjpeg(char * name, struct ImBuf * ibuf) ibuf->x *= 2; ibuf->y /= 2; - /* extra argument assumed to be 0 (nzc) */ - IMB_rectop(tbuf, ibuf, 0, 0, 0, 0, 32767, 32767, IMB_rectcpy, 0); + IMB_rectcpy(tbuf, ibuf, 0, 0, 0, 0, ibuf->x, ibuf->y); sprintf(fieldname, "%s.jf0", name); returnval = save_vidjpeg(fieldname, tbuf) ; if (returnval == 1) { - /* extra argument assumed to be 0 (nzc) */ - IMB_rectop(tbuf, ibuf, 0, 0, tbuf->x, 0, 32767, 32767, - IMB_rectcpy, 0); + IMB_rectcpy(tbuf, ibuf, 0, 0, tbuf->x, 0, ibuf->x, ibuf->y); sprintf(fieldname, "%s.jf1", name); returnval = save_vidjpeg(fieldname, tbuf); } diff --git a/source/blender/imbuf/intern/openexr/Makefile b/source/blender/imbuf/intern/openexr/Makefile new file mode 100644 index 00000000000..48abc4c4331 --- /dev/null +++ b/source/blender/imbuf/intern/openexr/Makefile @@ -0,0 +1,51 @@ +# +# $Id$ +# +# ***** BEGIN GPL/BL DUAL LICENSE BLOCK ***** +# +# This program is free software; you can redistribute it and/or +# modify it under the terms of the GNU General Public License +# as published by the Free Software Foundation; either version 2 +# of the License, or (at your option) any later version. The Blender +# Foundation also sells licenses for use in proprietary software under +# the Blender License. See http://www.blender.org/BL/ for information +# about this. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software Foundation, +# Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +# +# The Original Code is Copyright (C) 2001-2002 by NaN Holding BV. +# All rights reserved. +# +# The Original Code is: all of this file. +# +# Contributor(s): Gernot Ziegler +# +# ***** END GPL/BL DUAL LICENSE BLOCK ***** +# +# + +LIBNAME = openexr +DIR = $(OCGDIR)/blender/imbuf/openexr + +include nan_compile.mk + +ifeq ($(OS),$(findstring $(OS), "beos darwin freebsd linux openbsd solaris windows")) + CFLAGS += -funsigned-char +endif + +CFLAGS += $(LEVEL_1_C_WARNINGS) + +CPPFLAGS += -I../../../makesdna +CPPFLAGS += -I../../../blenkernel +CPPFLAGS += -I../../../blenlib +CPPFLAGS += -I../../../imbuf +CPPFLAGS += -I../../../imbuf/intern +CPPFLAGS += $(NAN_OPENEXR_INC) +CPPFLAGS += -I. diff --git a/source/blender/imbuf/intern/openexr/SConscript b/source/blender/imbuf/intern/openexr/SConscript new file mode 100644 index 00000000000..ee834669b04 --- /dev/null +++ b/source/blender/imbuf/intern/openexr/SConscript @@ -0,0 +1,22 @@ +#!/usr/bin/python +Import ('extra_includes') +Import ('user_options_dict') +Import ('library_env') + +openexr_env = library_env.Copy () + +source_files = ['openexr_api.cpp' + ] + +include_paths = ['.', + '../blenkernel', + '../imbuf', + '../imbuf/intern', + '../blenlib', + '../makesdna'] + +openexr_env.Append(CPPPATH = extra_includes) +openexr_env.Append(CPPPATH = include_paths) +openexr_env.Prepend (CPPPATH = user_options_dict['OPENEXR_INCLUDE']) +#ftf_env.Append(CPPDEFINES = 'FTGL_STATIC_LIBRARY') +openexr_env.Library (target='#'+user_options_dict['BUILD_DIR']+'/lib/blender_openexr', source=source_files) diff --git a/source/blender/imbuf/intern/openexr/openexr_api.cpp b/source/blender/imbuf/intern/openexr/openexr_api.cpp new file mode 100644 index 00000000000..86beab537ef --- /dev/null +++ b/source/blender/imbuf/intern/openexr/openexr_api.cpp @@ -0,0 +1,441 @@ +/** +* + * ***** BEGIN GPLLICENSE BLOCK ***** + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + * Copyright by Gernot Ziegler . + * All rights reserved. + * + * The Original Code is: all of this file. + * + * Contributor(s): Austin Benesh, Ton Roosendaal (float, half, speedup, cleanup...). + * + * ***** END GPL LICENSE BLOCK ***** + */ + +#include +#include +#include + + +#include + +extern "C" +{ +#include "IMB_imbuf_types.h" +#include "IMB_imbuf.h" + +#include "IMB_allocimbuf.h" +#include "BKE_global.h" +#include "DNA_scene_types.h" +} + +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +using namespace Imf; +using namespace Imath; + +class Mem_IStream: public IStream +{ +public: + + Mem_IStream (unsigned char *exrbuf, int exrsize): + IStream("dummy"), _exrpos (0), _exrsize(exrsize) { _exrbuf = exrbuf; } + + virtual bool read (char c[], int n); + virtual Int64 tellg (); + virtual void seekg (Int64 pos); + virtual void clear (); + //virtual ~Mem_IStream() {}; // unused + +private: + + Int64 _exrpos; + Int64 _exrsize; + unsigned char *_exrbuf; +}; + +bool Mem_IStream::read (char c[], int n) +{ + if (n + _exrpos <= _exrsize) + { + memcpy(c, (void *)(&_exrbuf[_exrpos]), n); + _exrpos += n; + return true; + } + else + return false; +} + +Int64 Mem_IStream::tellg () +{ + return _exrpos; +} + +void Mem_IStream::seekg (Int64 pos) +{ + _exrpos = pos; +} + +void Mem_IStream::clear () +{ +} + +struct _RGBAZ +{ + half r; + half g; + half b; + half a; + half z; +}; + +typedef struct _RGBAZ RGBAZ; + +extern "C" +{ + +int imb_is_a_openexr(unsigned char *mem) +{ + return Imf::isImfMagic ((const char *)mem); +} + +static void openexr_header_compression(Header *header, int compression) +{ + switch(compression) + { + case 0: + header->compression() = NO_COMPRESSION; + break; + case 1: + header->compression() = PXR24_COMPRESSION; + break; + case 2: + header->compression() = ZIP_COMPRESSION; + break; + case 3: + header->compression() = PIZ_COMPRESSION; + break; + case 4: + header->compression() = RLE_COMPRESSION; + break; + default: + header->compression() = NO_COMPRESSION; + break; + } +} + +short imb_save_openexr_half(struct ImBuf *ibuf, char *name, int flags) +{ + + int width = ibuf->x; + int height = ibuf->y; + + if (flags & IB_mem) + { + printf("OpenEXR-save: Create EXR in memory CURRENTLY NOT SUPPORTED !\n"); + imb_addencodedbufferImBuf(ibuf); + ibuf->encodedsize = 0; + return(0); + } + + int write_zbuf = (flags & IB_zbuf) && ibuf->zbuf != NULL; // summarize + + try + { + Header header (width, height); + + openexr_header_compression(&header, G.scene->r.quality); + + header.channels().insert ("R", Channel (HALF)); + header.channels().insert ("G", Channel (HALF)); + header.channels().insert ("B", Channel (HALF)); + header.channels().insert ("A", Channel (HALF)); + if (write_zbuf) // z we do as uint always + header.channels().insert ("Z", Channel (UINT)); + + FrameBuffer frameBuffer; + OutputFile *file = new OutputFile(name, header); + + /* we store first everything in half array */ + RGBAZ *pixels = new RGBAZ[height * width]; + RGBAZ *to = pixels; + int xstride= sizeof (RGBAZ); + int ystride= xstride*width; + + /* indicate used buffers */ + frameBuffer.insert ("R", Slice (HALF, (char *) &pixels[0].r, xstride, ystride)); + frameBuffer.insert ("G", Slice (HALF, (char *) &pixels[0].g, xstride, ystride)); + frameBuffer.insert ("B", Slice (HALF, (char *) &pixels[0].b, xstride, ystride)); + frameBuffer.insert ("A", Slice (HALF, (char *) &pixels[0].a, xstride, ystride)); + + if (write_zbuf) + frameBuffer.insert ("Z", Slice (UINT, (char *) ibuf->zbuf + 4*(height-1)*width, + sizeof(int), sizeof(int) * -width)); + if(ibuf->rect_float) { + float *from; + + for (int i = ibuf->y-1; i >= 0; i--) + { + from= ibuf->rect_float + 4*i*width; + + for (int j = ibuf->x; j > 0; j--) + { + to->r = from[0]; + to->g = from[1]; + to->b = from[2]; + to->a = from[3]; + to++; from += 4; + } + } + } + else { + unsigned char *from; + + for (int i = ibuf->y-1; i >= 0; i--) + { + from= (unsigned char *)(ibuf->rect + i*width); + + for (int j = ibuf->x; j > 0; j--) + { + to->r = (float)(from[0])/255.0; + to->g = (float)(from[1])/255.0; + to->b = (float)(from[2])/255.0; + to->a = (float)(from[3])/255.0; + to++; from += 4; + } + } + } + +// printf("OpenEXR-save: Writing OpenEXR file of height %d.\n", height); + + file->setFrameBuffer (frameBuffer); + file->writePixels (height); + delete file; + } + catch (const std::exception &exc) + { + printf("OpenEXR-save: ERROR: %s\n", exc.what()); + if (ibuf) IMB_freeImBuf(ibuf); + + return (0); + } + + return (1); +} + +short imb_save_openexr_float(struct ImBuf *ibuf, char *name, int flags) +{ + + int width = ibuf->x; + int height = ibuf->y; + + if (flags & IB_mem) + { + printf("OpenEXR-save: Create EXR in memory CURRENTLY NOT SUPPORTED !\n"); + imb_addencodedbufferImBuf(ibuf); + ibuf->encodedsize = 0; + return(0); + } + + if (ibuf->rect_float==NULL) + return(0); + + int write_zbuf = (flags & IB_zbuf) && ibuf->zbuf != NULL; // summarize + + try + { + Header header (width, height); + + openexr_header_compression(&header, G.scene->r.quality); + + header.channels().insert ("R", Channel (FLOAT)); + header.channels().insert ("G", Channel (FLOAT)); + header.channels().insert ("B", Channel (FLOAT)); + header.channels().insert ("A", Channel (FLOAT)); + if (write_zbuf) + header.channels().insert ("Z", Channel (UINT)); + + FrameBuffer frameBuffer; + OutputFile *file = new OutputFile(name, header); + float *first= ibuf->rect_float + 4*(height-1)*width; + int xstride = sizeof(float) * 4; + int ystride = - xstride*width; + + frameBuffer.insert ("R", Slice (FLOAT, (char *) first, xstride, ystride)); + frameBuffer.insert ("G", Slice (FLOAT, (char *) (first+1), xstride, ystride)); + frameBuffer.insert ("B", Slice (FLOAT, (char *) (first+2), xstride, ystride)); + frameBuffer.insert ("A", Slice (FLOAT, (char *) (first+3), xstride, ystride)); + + if (write_zbuf) + frameBuffer.insert ("Z", Slice (UINT, (char *) ibuf->zbuf + 4*(height-1)*width, + sizeof(int), sizeof(int) * -width)); + + file->setFrameBuffer (frameBuffer); + file->writePixels (height); + delete file; + } + catch (const std::exception &exc) + { + printf("OpenEXR-save: ERROR: %s\n", exc.what()); + if (ibuf) IMB_freeImBuf(ibuf); + + return (0); + } + + return (1); + // printf("OpenEXR-save: Done.\n"); +} + + + +struct ImBuf *imb_load_openexr(unsigned char *mem, int size, int flags) +{ + struct ImBuf *ibuf = 0; + InputFile *file = NULL; + +// printf("OpenEXR-load: testing input, size is %d\n", size); + if (imb_is_a_openexr(mem) == 0) return(NULL); + + try + { +// printf("OpenEXR-load: Creating InputFile from mem source\n"); + Mem_IStream membuf(mem, size); + file = new InputFile(membuf); + + Box2i dw = file->header().dataWindow(); + int width = dw.max.x - dw.min.x + 1; + int height = dw.max.y - dw.min.y + 1; + +// printf("OpenEXR-load: image data window %d %d %d %d\n", +// dw.min.x, dw.min.y, dw.max.x, dw.max.y); + + const ChannelList &channels = file->header().channels(); + + for (ChannelList::ConstIterator i = channels.begin(); i != channels.end(); ++i) + { + const Channel &channel = i.channel(); +// printf("OpenEXR-load: Found channel %s of type %d\n", i.name(), channel.type); + if (channel.type != 1) + { + printf("OpenEXR-load: Can only process HALF input !!\n"); + return(NULL); + } + } + + RGBAZ *pixels = new RGBAZ[height * width]; + + FrameBuffer frameBuffer; + + frameBuffer.insert ("R", + Slice (HALF, + (char *) &pixels[0].r, + sizeof (pixels[0]) * 1, + sizeof (pixels[0]) * width)); + + frameBuffer.insert ("G", + Slice (HALF, + (char *) &pixels[0].g, + sizeof (pixels[0]) * 1, + sizeof (pixels[0]) * width)); + + frameBuffer.insert ("B", + Slice (HALF, + (char *) &pixels[0].b, + sizeof (pixels[0]) * 1, + sizeof (pixels[0]) * width)); + + frameBuffer.insert ("A", + Slice (HALF, + (char *) &pixels[0].a, + sizeof (pixels[0]) * 1, + sizeof (pixels[0]) * width)); + + // FIXME ? Would be able to read Z data or other channels here ! + +// printf("OpenEXR-load: Reading pixel data\n"); + file->setFrameBuffer (frameBuffer); + file->readPixels (dw.min.y, dw.max.y); + +// printf("OpenEXR-load: Converting to Blender float ibuf\n"); + + int bytesperpixel = 4; // since OpenEXR fills in unknown channels + ibuf = IMB_allocImBuf(width, height, 8 * bytesperpixel, 0, 0); + + if (ibuf) + { + ibuf->ftype = OPENEXR; + + imb_addrectImBuf(ibuf); + imb_addrectfloatImBuf(ibuf); + + if (!(flags & IB_test)) + { + unsigned char *to = (unsigned char *) ibuf->rect; + float *tof = ibuf->rect_float; + RGBAZ *from = pixels; + RGBAZ prescale; + + for (int i = ibuf->x * ibuf->y; i > 0; i--) + { + to[0] = (unsigned char)(from->r > 1.0 ? 1.0 : (float)from->r) * 255; + to[1] = (unsigned char)(from->g > 1.0 ? 1.0 : (float)from->g) * 255; + to[2] = (unsigned char)(from->b > 1.0 ? 1.0 : (float)from->b) * 255; + to[3] = (unsigned char)(from->a > 1.0 ? 1.0 : (float)from->a) * 255; + to += 4; + + tof[0] = from->r; + tof[1] = from->g; + tof[2] = from->b; + tof[3] = from->a; + + from++; + } + } + + IMB_flipy(ibuf); + + } + else + printf("Couldn't allocate memory for OpenEXR image\n"); + +// printf("OpenEXR-load: Done\n"); + + return(ibuf); + } + catch (const std::exception &exc) + { + std::cerr << exc.what() << std::endl; + if (ibuf) IMB_freeImBuf(ibuf); + + return (0); + } + +} + +} // export "C" diff --git a/source/blender/imbuf/intern/openexr/openexr_api.h b/source/blender/imbuf/intern/openexr/openexr_api.h new file mode 100644 index 00000000000..882b9d98a06 --- /dev/null +++ b/source/blender/imbuf/intern/openexr/openexr_api.h @@ -0,0 +1,63 @@ +/** + * $Id$ + * + * ***** BEGIN GPL/BL DUAL LICENSE BLOCK ***** + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. The Blender + * Foundation also sells licenses for use in proprietary software under + * the Blender License. See http://www.blender.org/BL/ for information + * about this. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV. + * All rights reserved. + * + * The Original Code is: all of this file. + * + * Contributor(s): Austin Benesh. + * + * ***** END GPL/BL DUAL LICENSE BLOCK ***** + */ + +#ifndef _OPENEXR_API_H +#define _OPENEXR_API_H + +#ifdef __cplusplus +extern "C" { +#endif + +#define OPENEXR_FLOATRGB 0x1 +#define OPENEXR_ZBUF 0x2 + +#include + + /** + * Test presence of OpenEXR file. + * @param mem pointer to loaded OpenEXR bitstream + */ + +int imb_is_a_openexr(unsigned char *mem); + +short imb_save_openexr_half(struct ImBuf *ibuf, char *name, int flags); +short imb_save_openexr_float(struct ImBuf *ibuf, char *name, int flags); + +struct ImBuf *imb_load_openexr(unsigned char *mem, int size, int flags); + +#ifdef __cplusplus +} +#endif + + + +#endif /* __OPENEXR_API_H */ diff --git a/source/blender/imbuf/intern/radiance_hdr.c b/source/blender/imbuf/intern/radiance_hdr.c index fe18d4e3574..a90d7d651f8 100644 --- a/source/blender/imbuf/intern/radiance_hdr.c +++ b/source/blender/imbuf/intern/radiance_hdr.c @@ -29,13 +29,12 @@ * ***** END GPL LICENSE BLOCK ***** */ - -/* - ------------------------------------------------------------------------------------------------- +/* ---------------------------------------------------------------------- Radiance High Dynamic Range image file IO - For description and code for reading/writing of radiance hdr files by Greg Ward, refer to: + For description and code for reading/writing of radiance hdr files + by Greg Ward, refer to: http://radsite.lbl.gov/radiance/refer/Notes/picture_format.html - ------------------------------------------------------------------------------------------------- +---------------------------------------------------------------------- */ #ifdef WIN32 @@ -68,9 +67,7 @@ typedef float fCOLOR[3]; #define copy_rgbe(c1, c2) (c2[RED]=c1[RED], c2[GRN]=c1[GRN], c2[BLU]=c1[BLU], c2[EXP]=c1[EXP]) #define copy_fcol(f1, f2) (f2[RED]=f1[RED], f2[GRN]=f1[GRN], f2[BLU]=f1[BLU]) -/*-------------------------------------------------------------------------------------------------*/ /* read routines */ - static unsigned char* oldreadcolrs(RGBE *scan, unsigned char *mem, int xmax) { int i, rshift = 0, len = xmax; @@ -127,7 +124,6 @@ static unsigned char* freadcolrs(RGBE *scan, unsigned char* mem, int xmax) return mem; } -/*-------------------------------------------------------------------------------------------------*/ /* helper functions */ /* rgbe -> float color */ @@ -161,7 +157,6 @@ static void FLOAT2RGBE(fCOLOR fcol, RGBE rgbe) } } -/*-------------------------------------------------------------------------------------------------*/ /* ImBuf read */ int imb_is_a_hdr(void *buf) @@ -174,16 +169,17 @@ int imb_is_a_hdr(void *buf) struct ImBuf *imb_loadhdr(unsigned char *mem, int size, int flags) { + struct ImBuf* ibuf; + RGBE* sline; + fCOLOR fcol; + float* rect_float; int found=0; - char oriY[80], oriX[80]; int width=0, height=0; - RGBE* sline; int x, y; - char* ptr; - fCOLOR fcol; int ir, ig, ib; + unsigned char* ptr; unsigned char* rect; - struct ImBuf* ibuf; + char oriY[80], oriX[80]; if (imb_is_a_hdr((void*)mem)) { @@ -198,11 +194,11 @@ struct ImBuf *imb_loadhdr(unsigned char *mem, int size, int flags) sscanf((char*)&mem[x+1], "%s %d %s %d", (char*)&oriY, &height, (char*)&oriX, &width); /* find end of this line, data right behind it */ - ptr = strchr((char*)&mem[x+1], '\n'); + ptr = (unsigned char *)strchr((char*)&mem[x+1], '\n'); ptr++; if (flags & IB_test) ibuf = IMB_allocImBuf(width, height, 24, 0, 0); - else ibuf = IMB_allocImBuf(width, height, 24, 1, 0); + else ibuf = IMB_allocImBuf(width, height, 24, IB_rect|IB_rectfloat, 0); if (ibuf==NULL) return NULL; ibuf->ftype = RADHDR; @@ -213,6 +209,8 @@ struct ImBuf *imb_loadhdr(unsigned char *mem, int size, int flags) /* read in and decode the actual data */ sline = (RGBE*)MEM_mallocN(sizeof(RGBE)*width, "radhdr_read_tmpscan"); rect = (unsigned char*)ibuf->rect; + rect_float = (float *)ibuf->rect_float; + for (y=0;y255) ? 255 : ig)); *rect++ = (unsigned char)((ib<0) ? 0 : ((ib>255) ? 255 : ib)); *rect++ = 255; - /*--------------------------------------------------------------------------------------*/ } } MEM_freeN(sline); @@ -251,36 +251,39 @@ struct ImBuf *imb_loadhdr(unsigned char *mem, int size, int flags) return NULL; } -/*-------------------------------------------------------------------------------------------------*/ /* ImBuf write */ - - -static int fwritecolrs(FILE* file, int width, RGBE* rgbe_scan, unsigned char* ibufscan, float* fpscan) +static int fwritecolrs(FILE* file, int width, unsigned char* ibufscan, float* fpscan) { - int i, j, beg, c2, cnt=0; + int x, i, j, beg, c2, cnt=0; fCOLOR fcol; - RGBE rgbe; + RGBE rgbe, *rgbe_scan; if ((ibufscan==NULL) && (fpscan==NULL)) return 0; + rgbe_scan = (RGBE*)MEM_mallocN(sizeof(RGBE)*width, "radhdr_write_tmpscan"); + /* convert scanline */ - for (i=0, j=0;i MAXELEN)) /* OOBs, write out flat */ - return (fwrite((char *)rgbe_scan, sizeof(RGBE), width, file) - width); + if ((width < MINELEN) | (width > MAXELEN)) { /* OOBs, write out flat */ + x=fwrite((char *)rgbe_scan, sizeof(RGBE), width, file) - width; + MEM_freeN(rgbe_scan); + return x; + } /* put magic header */ putc(2, file); putc(2, file); @@ -315,6 +318,7 @@ static int fwritecolrs(FILE* file, int width, RGBE* rgbe_scan, unsigned char* ib else cnt = 0; } } + MEM_freeN(rgbe_scan); return(ferror(file) ? -1 : 0); } @@ -336,57 +340,21 @@ static void writeHeader(FILE *file, int width, int height) short imb_savehdr(struct ImBuf *ibuf, char *name, int flags) { int y, width=ibuf->x, height=ibuf->y; - RGBE* sline; - FILE* file = fopen(name, "wb"); - if (file==NULL) return 0; - writeHeader(file, width, height); - - sline = (RGBE*)MEM_mallocN(sizeof(RGBE)*width, "radhdr_write_tmpscan"); - - for (y=height-1;y>=0;y--) { - if (fwritecolrs(file, width, sline, (unsigned char*)&ibuf->rect[y*width], NULL) < 0) - { // error - fclose(file); - MEM_freeN(sline); - printf("HDR write error\n"); - return 0; - } - } - - fclose(file); - MEM_freeN(sline); - return 1; -} - -/* Temporary routine to save directly from render floatbuffer. - Called by schrijfplaatje() in toets.c */ -short imb_savehdr_fromfloat(float *fbuf, char *name, int width, int height) -{ - int y; - RGBE* sline; - - FILE* file = fopen(name, "wb"); if (file==NULL) return 0; writeHeader(file, width, height); - sline = (RGBE*)MEM_mallocN(sizeof(RGBE)*width, "radhdr_write_tmpscan"); - for (y=height-1;y>=0;y--) { - if (fwritecolrs(file, width, sline, NULL, &fbuf[y*width*4]) < 0) - { // error + if (fwritecolrs(file, width,(unsigned char *)&ibuf->rect[y*width*4], &ibuf->rect_float[y*width*4]) < 0) { fclose(file); - MEM_freeN(sline); printf("HDR write error\n"); return 0; } } fclose(file); - MEM_freeN(sline); return 1; } -/*-------------------------------------------------------------------------------------------------*/ diff --git a/source/blender/imbuf/intern/readimage.c b/source/blender/imbuf/intern/readimage.c index 779401c3183..117dd54cfdd 100644 --- a/source/blender/imbuf/intern/readimage.c +++ b/source/blender/imbuf/intern/readimage.c @@ -54,6 +54,10 @@ #include "IMB_radiance_hdr.h" #include "BKE_global.h" +#ifdef WITH_OPENEXR +#include "openexr/openexr_api.h" +#endif + #ifdef WITH_QUICKTIME #if defined(_WIN32) || defined (__APPLE__) #include "quicktime_import.h" @@ -138,6 +142,9 @@ ImBuf *IMB_ibImageFromMemory(int *mem, int size, int flags) { ibuf = imb_loadhdr((uchar*)mem, size, flags); if (ibuf) return (ibuf); + ibuf = imb_load_openexr((uchar *)mem, size, flags); + if (ibuf) return (ibuf); + #ifdef WITH_QUICKTIME #if defined(_WIN32) || defined (__APPLE__) if(G.have_quicktime) { diff --git a/source/blender/imbuf/intern/rectop.c b/source/blender/imbuf/intern/rectop.c index 22f2698a8c5..4ddd7ca4814 100644 --- a/source/blender/imbuf/intern/rectop.c +++ b/source/blender/imbuf/intern/rectop.c @@ -41,33 +41,17 @@ #include "IMB_allocimbuf.h" -void IMB_rectcpy(unsigned int *drect, unsigned int *srect, int x, int dummy) +void IMB_rectcpy(struct ImBuf *dbuf, struct ImBuf *sbuf, int destx, + int desty, int srcx, int srcy, int width, int height) { - memcpy(drect,srect, x * sizeof(int)); -} - - -void IMB_rectfill(unsigned int *drect, unsigned int *srect, int x, int value) -{ - for (;x > 0; x--) *drect++ = value; -} - -void IMB_rectop(struct ImBuf *dbuf, - struct ImBuf *sbuf, - int destx, - int desty, - int srcx, - int srcy, - int width, - int height, - void (*operation)(unsigned int *, unsigned int*, int, int), - int value) -{ - unsigned int *drect,*srect; - int tmp; + unsigned int *drect, *srect; + float *drectf = NULL; + float *srectf = NULL; + int tmp, do_float = 0; - if (dbuf == 0) return; - if (operation == 0) return; + if (dbuf == NULL) return; + + if (sbuf->rect_float) do_float = 1; if (destx < 0){ srcx -= destx ; @@ -96,6 +80,7 @@ void IMB_rectop(struct ImBuf *dbuf, if (height > tmp) height = tmp; drect = dbuf->rect + desty * dbuf->x + destx; + if (do_float) drectf = dbuf->rect_float + desty * dbuf->x + destx; destx = dbuf->x; if (sbuf){ @@ -110,25 +95,53 @@ void IMB_rectop(struct ImBuf *dbuf, srect = sbuf->rect; srect += srcy * sbuf->x; srect += srcx; + if (do_float) { + srectf = sbuf->rect_float; + srectf += srcy * sbuf->x; + srectf += srcx; + } srcx = sbuf->x; } else{ if (width <= 0) return; if (height <= 0) return; srect = drect; + srectf = drectf; srcx = destx; } for (;height > 0; height--){ - operation(drect,srect,width, value); - drect += destx; - srect += srcx; + + memcpy(drect,srect, width * sizeof(int)); + if (do_float) memcpy(drectf,srectf, width * sizeof(float) * 4); } } - -void IMB_rectoptot(struct ImBuf *dbuf, struct ImBuf *sbuf, - void (*operation)(unsigned int *, unsigned int*, int, int), int value) +void IMB_rectfill(struct ImBuf *drect, float col[4]) { - IMB_rectop(dbuf,sbuf,0,0,0,0,32767,32767,operation, value); + int num; + unsigned int *rrect = drect->rect; + unsigned char *spot; + + num = drect->x * drect->y; + for (;num > 0; num--) { + spot = (unsigned char *)rrect; + spot[0] = (int)(col[0]*255); + spot[1] = (int)(col[1]*255); + spot[2] = (int)(col[2]*255); + spot[3] = (int)(col[3]*255); + *rrect++; + } + if(drect->rect_float) { + float *rrectf = drect->rect_float; + + num = drect->x * drect->y; + for (;num > 0; num--) { + *rrectf++ = col[0]; + *rrectf++ = col[1]; + *rrectf++ = col[2]; + *rrectf++ = col[3]; + } + } } + diff --git a/source/blender/imbuf/intern/rotate.c b/source/blender/imbuf/intern/rotate.c index f8d01789cdc..13edfbf0a33 100644 --- a/source/blender/imbuf/intern/rotate.c +++ b/source/blender/imbuf/intern/rotate.c @@ -43,26 +43,46 @@ void IMB_flipy(struct ImBuf * ibuf) { - short x,y,backx; - unsigned int *top,*bottom,temp; + short x, y; + unsigned int *top, *bottom, do_float=0, *line; + float *topf=NULL, *bottomf=NULL, *linef=NULL; - if (ibuf == 0) return; - if (ibuf->rect == 0) return; + if (ibuf == NULL) return; + if (ibuf->rect == NULL) return; + + if (ibuf->rect_float) do_float =1; x = ibuf->x; y = ibuf->y; - backx = x<<1; top = ibuf->rect; bottom = top + ((y-1) * x); + line= MEM_mallocN(x*sizeof(int), "linebuf"); + + if (do_float) { + topf= ibuf->rect_float; + bottomf = topf + 4*((y-1) * x); + linef= MEM_mallocN(4*x*sizeof(float), "linebuff"); + } y >>= 1; - for(;y>0;y--){ - for(x = ibuf->x; x > 0; x--){ - temp = *top; - *(top++) = *bottom; - *(bottom++) = temp; + for(;y>0;y--) { + + memcpy(line, top, x*sizeof(int)); + memcpy(top, bottom, x*sizeof(int)); + memcpy(bottom, line, x*sizeof(int)); + bottom -= x; + top+= x; + + if(do_float) { + memcpy(linef, topf, 4*x*sizeof(float)); + memcpy(topf, bottomf, 4*x*sizeof(float)); + memcpy(bottomf, linef, 4*x*sizeof(float)); + bottomf -= 4*x; + topf+= 4*x; } - bottom -= backx; } + + MEM_freeN(line); + if(linef) MEM_freeN(linef); } diff --git a/source/blender/imbuf/intern/scaling.c b/source/blender/imbuf/intern/scaling.c index 7749dadb2ca..539ea0377b3 100644 --- a/source/blender/imbuf/intern/scaling.c +++ b/source/blender/imbuf/intern/scaling.c @@ -52,20 +52,27 @@ struct ImBuf *IMB_half_x(struct ImBuf *ibuf1) struct ImBuf *ibuf2; uchar *p1,*_p1,*dest; short a,r,g,b,x,y; + float af,rf,gf,bf, *p1f, *_p1f, *destf; + int do_float = 0; - if (ibuf1==0) return (0); - if (ibuf1->rect == 0) return (0); + if (ibuf1==NULL) return (0); + if (ibuf1->rect==NULL) return (0); + if (ibuf1->rect_float) do_float = 1; if (ibuf1->x <= 1) return(IMB_dupImBuf(ibuf1)); - ibuf2 = IMB_allocImBuf((ibuf1->x)/2 , ibuf1->y , ibuf1->depth,1,0); - if (ibuf2==0) return (0); + ibuf2 = IMB_allocImBuf((ibuf1->x)/2, ibuf1->y, ibuf1->depth, ibuf1->flags, 0); + if (ibuf2==NULL) return (0); _p1 = (uchar *) ibuf1->rect; dest=(uchar *) ibuf2->rect; + + _p1f = ibuf1->rect_float; + destf= ibuf2->rect_float; for(y=ibuf2->y;y>0;y--){ p1 = _p1; + p1f = _p1f; for(x = ibuf2->x ; x>0 ; x--){ a = *(p1++) ; b = *(p1++) ; @@ -79,8 +86,23 @@ struct ImBuf *IMB_half_x(struct ImBuf *ibuf1) *(dest++) = b >> 1; *(dest++) = g >> 1; *(dest++) = r >> 1; + if (do_float) { + af = *(p1f++); + bf = *(p1f++); + gf = *(p1f++); + rf = *(p1f++); + af += *(p1f++); + bf += *(p1f++); + gf += *(p1f++); + rf += *(p1f++); + *(destf++) = 0.5f*af; + *(destf++) = 0.5f*bf; + *(destf++) = 0.5f*gf; + *(destf++) = 0.5f*rf; + } } _p1 += (ibuf1->x << 2); + if (do_float) _p1f += (ibuf1->x << 2); } return (ibuf2); } @@ -89,21 +111,30 @@ struct ImBuf *IMB_half_x(struct ImBuf *ibuf1) struct ImBuf *IMB_double_fast_x(struct ImBuf *ibuf1) { struct ImBuf *ibuf2; - int *p1,*dest, i, col; + int *p1,*dest, i, col, do_float=0; + float *p1f, *destf, colf; - if (ibuf1==0) return (0); - if (ibuf1->rect == 0) return (0); + if (ibuf1==NULL) return (0); + if (ibuf1->rect==NULL) return (0); + if (ibuf1->rect_float) do_float = 1; - ibuf2 = IMB_allocImBuf(2 * ibuf1->x , ibuf1->y , ibuf1->depth,1,0); - if (ibuf2==0) return (0); + ibuf2 = IMB_allocImBuf(2 * ibuf1->x , ibuf1->y , ibuf1->depth, ibuf1->flags, 0); + if (ibuf2==NULL) return (0); p1 = (int *) ibuf1->rect; dest=(int *) ibuf2->rect; + p1f = ibuf1->rect_float; + destf = ibuf2->rect_float; for(i = ibuf1->y * ibuf1->x ; i>0 ; i--) { col = *p1++; *dest++ = col; *dest++ = col; + if (do_float) { + colf = *p1f++; + *destf++ = col; + *destf++ = col; + } } return (ibuf2); @@ -113,8 +144,8 @@ struct ImBuf *IMB_double_x(struct ImBuf *ibuf1) { struct ImBuf *ibuf2; - if (ibuf1==0) return (0); - if (ibuf1->rect == 0) return (0); + if (ibuf1==NULL) return (0); + if (ibuf1->rect==NULL) return (0); ibuf2 = IMB_double_fast_x(ibuf1); @@ -128,20 +159,30 @@ struct ImBuf *IMB_half_y(struct ImBuf *ibuf1) struct ImBuf *ibuf2; uchar *p1,*p2,*_p1,*dest; short a,r,g,b,x,y; + int do_float = 0; + float af,rf,gf,bf,*p1f,*p2f,*_p1f,*destf; - if (ibuf1==0) return (0); - if (ibuf1->rect == 0) return (0); + p1f = NULL; p2f = NULL; + if (ibuf1==NULL) return (0); + if (ibuf1->rect==NULL) return (0); + if (ibuf1->rect_float) do_float = 1; if (ibuf1->y <= 1) return(IMB_dupImBuf(ibuf1)); - ibuf2 = IMB_allocImBuf(ibuf1->x , (ibuf1->y) / 2 , ibuf1->depth,1,0); - if (ibuf2==0) return (0); + ibuf2 = IMB_allocImBuf(ibuf1->x , (ibuf1->y) / 2 , ibuf1->depth, ibuf1->flags, 0); + if (ibuf2==NULL) return (0); _p1 = (uchar *) ibuf1->rect; dest=(uchar *) ibuf2->rect; + _p1f = ibuf1->rect_float; + destf= ibuf2->rect_float; for(y=ibuf2->y ; y>0 ; y--){ p1 = _p1; p2 = _p1 + (ibuf1->x << 2); + if (do_float) { + p1f = _p1f; + p2f = _p1f + (ibuf1->x << 2); + } for(x = ibuf2->x ; x>0 ; x--){ a = *(p1++) ; b = *(p1++) ; @@ -155,8 +196,23 @@ struct ImBuf *IMB_half_y(struct ImBuf *ibuf1) *(dest++) = b >> 1; *(dest++) = g >> 1; *(dest++) = r >> 1; + if (do_float) { + af = *(p1f++) ; + bf = *(p1f++) ; + gf = *(p1f++) ; + rf = *(p1f++); + af += *(p2f++) ; + bf += *(p2f++) ; + gf += *(p2f++) ; + rf += *(p2f++); + *(destf++) = 0.5f*af; + *(destf++) = 0.5f*bf; + *(destf++) = 0.5f*gf; + *(destf++) = 0.5f*rf; + } } _p1 += (ibuf1->x << 3); + if (do_float) _p1f += (ibuf1->x << 3); } return (ibuf2); } @@ -166,21 +222,31 @@ struct ImBuf *IMB_double_fast_y(struct ImBuf *ibuf1) { struct ImBuf *ibuf2; int *p1, *dest1, *dest2; + float *p1f, *dest1f, *dest2f; short x,y; + int do_float =0; - if (ibuf1==0) return (0); - if (ibuf1->rect == 0) return (0); + if (ibuf1==NULL) return (0); + if (ibuf1->rect==NULL) return (0); + if (ibuf1->rect_float) do_float =1; - ibuf2 = IMB_allocImBuf(ibuf1->x , 2 * ibuf1->y , ibuf1->depth,1,0); - if (ibuf2==0) return (0); + ibuf2 = IMB_allocImBuf(ibuf1->x , 2 * ibuf1->y , ibuf1->depth, ibuf1->flags, 0); + if (ibuf2==NULL) return (0); p1 = (int *) ibuf1->rect; dest1=(int *) ibuf2->rect; + p1f = ibuf1->rect_float; + dest1f= ibuf2->rect_float; for(y = ibuf1->y ; y>0 ; y--){ dest2 = dest1 + ibuf2->x; for(x = ibuf2->x ; x>0 ; x--) *dest1++ = *dest2++ = *p1++; dest1 = dest2; + if (do_float) { + dest2f = dest1f + ibuf2->x; + for(x = ibuf2->x ; x>0 ; x--) *dest1f++ = *dest2f++ = *p1f++; + dest1f = dest2f; + } } return (ibuf2); @@ -190,8 +256,8 @@ struct ImBuf *IMB_double_y(struct ImBuf *ibuf1) { struct ImBuf *ibuf2; - if (ibuf1==0) return (0); - if (ibuf1->rect == 0) return (0); + if (ibuf1==NULL) return (0); + if (ibuf1->rect==NULL) return (0); ibuf2 = IMB_double_fast_y(ibuf1); @@ -203,23 +269,29 @@ struct ImBuf *IMB_double_y(struct ImBuf *ibuf1) struct ImBuf *IMB_onehalf(struct ImBuf *ibuf1) { struct ImBuf *ibuf2; - uchar *p1,*p2,*dest; + uchar *p1, *p2, *dest; + float *p1f, *destf, *p2f = NULL; int x,y; + int do_float =0; - if (ibuf1 == 0) return (0); - if (ibuf1->rect == 0) return (0); + if (ibuf1==NULL) return (0); + if (ibuf1->rect==NULL) return (0); + if (ibuf1->rect_float) do_float = 1; if (ibuf1->x <= 1) return(IMB_half_y(ibuf1)); if (ibuf1->y <= 1) return(IMB_half_x(ibuf1)); - ibuf2=IMB_allocImBuf((ibuf1->x)/2,(ibuf1->y)/2,ibuf1->depth,1,0); - if (ibuf2==0) return (0); + ibuf2=IMB_allocImBuf((ibuf1->x)/2, (ibuf1->y)/2, ibuf1->depth, ibuf1->flags, 0); + if (ibuf2==NULL) return (0); + p1f = ibuf1->rect_float; + destf=ibuf2->rect_float; p1 = (uchar *) ibuf1->rect; dest=(uchar *) ibuf2->rect; for(y=ibuf2->y;y>0;y--){ p2 = p1 + (ibuf1->x << 2); + if (do_float) p2f = p1f + (ibuf1->x << 2); for(x=ibuf2->x;x>0;x--){ dest[0] = (p1[0] + p2[0] + p1[4] + p2[4]) >> 2; dest[1] = (p1[1] + p2[1] + p1[5] + p2[5]) >> 2; @@ -228,10 +300,21 @@ struct ImBuf *IMB_onehalf(struct ImBuf *ibuf1) p1 += 8; p2 += 8; dest += 4; + if (do_float){ + destf[0] = 0.25f*(p1f[0] + p2f[0] + p1f[4] + p2f[4]); + destf[1] = 0.25f*(p1f[1] + p2f[1] + p1f[5] + p2f[5]); + destf[2] = 0.25f*(p1f[2] + p2f[2] + p1f[6] + p2f[6]); + destf[3] = 0.25f*(p1f[3] + p2f[3] + p1f[7] + p2f[7]); + p1f += 8; + p2f += 8; + destf += 4; + } } p1=p2; + if (do_float) p1f=p2f; if(ibuf1->x & 1) { p1+=4; + if (do_float) p1f+=4; } } return (ibuf2); @@ -243,34 +326,59 @@ struct ImBuf *IMB_onethird(struct ImBuf *ibuf1) { struct ImBuf *ibuf2; uchar *p1,*p2,*p3,*dest; + float *p1f, *p2f, *p3f, *destf; + int do_float=0; short a,r,g,b,x,y,i; + float af,rf,gf,bf; - if (ibuf1 == 0) return (0); - if (ibuf1->rect == 0) return (0); + p2f = NULL; p3f = NULL; + if (ibuf1==NULL) return (0); + if (ibuf1->rect==NULL) return (0); + if (ibuf1->rect_float) do_float = 1; - ibuf2=IMB_allocImBuf((ibuf1->x)/3,(ibuf1->y)/3,ibuf1->depth,1,0); - if (ibuf2==0) return (0); + ibuf2=IMB_allocImBuf((ibuf1->x)/3, (ibuf1->y)/3, ibuf1->depth, ibuf1->flags, 0); + if (ibuf2==NULL) return (0); + p1f = ibuf1->rect_float; + destf = ibuf2->rect_float; p1 = (uchar *) ibuf1->rect; dest=(uchar *) ibuf2->rect; for(y=ibuf2->y;y>0;y--){ p2 = p1 + (ibuf1->x << 2); p3 = p2 + (ibuf1->x << 2); + if (do_float) { + p2f = p1f + (ibuf1->x <<2); + p3f = p2f + (ibuf1->x <<2); + } for(x=ibuf2->x;x>0;x--){ a=r=g=b=0; + af=rf=gf=bf=0; for (i=3;i>0;i--){ a += *(p1++) + *(p2++) + *(p3++); b += *(p1++) + *(p2++) + *(p3++); g += *(p1++) + *(p2++) + *(p3++); r += *(p1++) + *(p2++) + *(p3++); + if (do_float) { + af += *(p1f++) + *(p2f++) + *(p3f++); + bf += *(p1f++) + *(p2f++) + *(p3f++); + gf += *(p1f++) + *(p2f++) + *(p3f++); + rf += *(p1f++) + *(p2f++) + *(p3f++); + } } *(dest++) = a/9; *(dest++) = b/9; *(dest++) = g/9; *(dest++) = r/9; + if (do_float) { + *(destf++) = af/9.0f; + *(destf++) = bf/9.0f; + *(destf++) = gf/9.0f; + *(destf++) = rf/9.0f; + } } p1=p3; + if (do_float) p1f = p3f; } return (ibuf2); } @@ -280,33 +388,55 @@ struct ImBuf *IMB_halflace(struct ImBuf *ibuf1) { struct ImBuf *ibuf2; uchar *p1,*p2,*dest; + float *p1f,*p2f,*destf; short a,r,g,b,x,y,i; + float af,rf,gf,bf; + int do_float = 0; - if (ibuf1 == 0) return (0); - if (ibuf1->rect == 0) return (0); + p2f = NULL; + if (ibuf1==NULL) return (0); + if (ibuf1->rect==NULL) return (0); + if (ibuf1->rect_float) do_float = 1; - ibuf2=IMB_allocImBuf((ibuf1->x)/4,(ibuf1->y)/2,ibuf1->depth,1,0); - if (ibuf2==0) return (0); + ibuf2=IMB_allocImBuf((ibuf1->x)/4, (ibuf1->y)/2, ibuf1->depth, ibuf1->flags, 0); + if (ibuf2==NULL) return (0); + p1f = ibuf1->rect_float; + destf= ibuf2->rect_float; p1 = (uchar *) ibuf1->rect; dest=(uchar *) ibuf2->rect; for(y= ibuf2->y / 2 ; y>0;y--){ p2 = p1 + (ibuf1->x << 3); + if (do_float) p2f = p1f + (ibuf1->x << 3); for(x = 2 * ibuf2->x;x>0;x--){ a=r=g=b=0; + af=rf=gf=bf=0; for (i=4;i>0;i--){ a += *(p1++) + *(p2++); b += *(p1++) + *(p2++); g += *(p1++) + *(p2++); r += *(p1++) + *(p2++); + if (do_float) { + af += *(p1f++) + *(p2f++); + bf += *(p1f++) + *(p2f++); + gf += *(p1f++) + *(p2f++); + rf += *(p1f++) + *(p2f++); + } } *(dest++) = a >> 3; *(dest++) = b >> 3; *(dest++) = g >> 3; *(dest++) = r >> 3; + if (do_float) { + *(destf++) = 0.125f*af; + *(destf++) = 0.125f*bf; + *(destf++) = 0.125f*gf; + *(destf++) = 0.125f*rf; + } } p1 = p2; + if (do_float) p1f = p2f; } return (ibuf2); } @@ -315,14 +445,23 @@ struct ImBuf *IMB_halflace(struct ImBuf *ibuf1) static struct ImBuf *scaledownx(struct ImBuf *ibuf, int newx) { uchar *rect,*_newrect,*newrect; - float sample, add, val, nval; - int x, y, i; + float *rectf,*_newrectf,*newrectf; + float sample, add, val, nval, valf, nvalf; + int x, y, i, do_float=0; - if (ibuf == 0) return(0); - if (ibuf->rect == 0) return(ibuf); + rectf = NULL; _newrectf= NULL; newrectf = NULL; + nval = 0; nvalf = 0; + + if (ibuf==NULL) return(0); + if (ibuf->rect==NULL) return(ibuf); + if (ibuf->rect_float) { + do_float = 1; + _newrectf = MEM_mallocN(newx * ibuf->y * sizeof(float) * 4, "scaledownxf"); + if (_newrectf==NULL) return(ibuf); + } - _newrect = (uchar *) malloc(newx * ibuf->y * sizeof(int)); - if (_newrect == 0) return(ibuf); + _newrect = MEM_mallocN(newx * ibuf->y * sizeof(int), "scaledownx"); + if (_newrect==NULL) return(ibuf); add = (ibuf->x - 0.001) / newx; @@ -331,22 +470,39 @@ static struct ImBuf *scaledownx(struct ImBuf *ibuf, int newx) rect = (uchar *) ibuf->rect; rect += i; newrect = _newrect + i; + if (do_float) { + rectf = ibuf->rect_float; + rectf += i; + newrectf = _newrectf + i; + } for (y = ibuf->y; y>0 ; y--){ - val = sample = 0.0; + val = sample = valf = 0.0; for (x = newx ; x>0 ; x--){ nval = - val * sample; + if (do_float) nvalf = - valf * sample; sample += add; while (sample >= 1.0){ sample -= 1.0; nval += *rect; rect += 4; + if (do_float) { + nvalf += *rectf; + rectf += 4; + } } val = *rect; rect += 4; nval += sample * val; + if (do_float) { + valf = *rectf; + rectf += 4; + nvalf += sample * valf; + *newrectf = (nvalf/add) + 0.5; + newrectf += 4; + } sample -= 1.0; *newrect = (nval/add) + 0.5; newrect += 4; @@ -357,6 +513,13 @@ static struct ImBuf *scaledownx(struct ImBuf *ibuf, int newx) imb_freerectImBuf(ibuf); ibuf->mall |= IB_rect; ibuf->rect = (unsigned int *) _newrect; + + if (do_float) { + imb_freerectfloatImBuf(ibuf); + ibuf->mall |= IB_rectfloat; + ibuf->rect_float = _newrectf; + } + ibuf->x = newx; return(ibuf); } @@ -364,15 +527,25 @@ static struct ImBuf *scaledownx(struct ImBuf *ibuf, int newx) static struct ImBuf *scaledowny(struct ImBuf *ibuf, int newy) { - uchar *rect,*_newrect,*newrect; - float sample,add,val,nval; - int x,y,i,skipx; + uchar *rect, *_newrect, *newrect; + float *rectf, *_newrectf, *newrectf; + float sample, add, val, nval, valf, nvalf; + int x, y, i, skipx, do_float = 0; - if (ibuf == 0) return(0); - if (ibuf->rect == 0) return(ibuf); + rectf= NULL; _newrectf = NULL; newrectf = NULL; + nval = 0; nvalf = 0; - _newrect = (uchar *) malloc(newy * ibuf->x * sizeof(int)); - if (_newrect == 0) return(ibuf); + if (ibuf==NULL) return(0); + if (ibuf->rect==NULL) return(ibuf); + + if (ibuf->rect_float) { + do_float = 1; + _newrectf = MEM_mallocN(newy * ibuf->x * sizeof(float) * 4, "scaldownyf"); + if (_newrectf==NULL) return(ibuf); + } + + _newrect = MEM_mallocN(newy * ibuf->x * sizeof(int), "scaledowny"); + if (_newrect==NULL) return(ibuf); add = (ibuf->y - 0.001) / newy; skipx = 4 * ibuf->x; @@ -382,23 +555,39 @@ static struct ImBuf *scaledowny(struct ImBuf *ibuf, int newy) for (x = skipx - 4; x>=0 ; x-= 4){ rect = ((uchar *) ibuf->rect) + i + x; newrect = _newrect + i + x; + if (do_float) { + rectf = ((float *) ibuf->rect_float) + i + x; + newrectf = _newrectf + i + x; + } val = sample = 0.0; for (y = newy ; y>0 ; y--){ nval = - val * sample; + if (do_float) nvalf = - val * sample; sample += add; while (sample >= 1.0){ sample -= 1.0; nval += *rect; rect += skipx; + if (do_float) { + nvalf += *rectf; + rectf += skipx; + } } val = *rect; rect += skipx; nval += sample * val; - sample -= 1.0; *newrect = (nval/add) + 0.5; newrect += skipx; + if (do_float) { + valf = *rectf; + rectf += skipx; + nvalf += sample * valf; + *newrectf = (nvalf/add) + 0.5; + newrectf += skipx; + } + sample -= 1.0; } } } @@ -406,6 +595,13 @@ static struct ImBuf *scaledowny(struct ImBuf *ibuf, int newy) imb_freerectImBuf(ibuf); ibuf->mall |= IB_rect; ibuf->rect = (unsigned int *) _newrect; + + if (do_float) { + imb_freerectfloatImBuf(ibuf); + ibuf->mall |= IB_rectfloat; + ibuf->rect_float = (float *) _newrectf; + } + ibuf->y = newy; return(ibuf); } @@ -414,23 +610,39 @@ static struct ImBuf *scaledowny(struct ImBuf *ibuf, int newy) static struct ImBuf *scaleupx(struct ImBuf *ibuf, int newx) { uchar *rect,*_newrect,*newrect; + float *rectf,*_newrectf,*newrectf; float sample,add; float val_a,nval_a,diff_a; float val_b,nval_b,diff_b; float val_g,nval_g,diff_g; float val_r,nval_r,diff_r; - int x,y; - - if (ibuf == 0) return(0); - if (ibuf->rect == 0) return(ibuf); + float val_af,nval_af,diff_af; + float val_bf,nval_bf,diff_bf; + float val_gf,nval_gf,diff_gf; + float val_rf,nval_rf,diff_rf; + int x,y, do_float = 0; + + val_af = nval_af = diff_af = val_bf = nval_bf = diff_bf = 0; + val_gf = nval_gf = diff_gf = val_rf = nval_rf = diff_rf = 0; + if (ibuf==NULL) return(0); + if (ibuf->rect==NULL) return(ibuf); + + _newrect = MEM_mallocN(newx * ibuf->y * sizeof(int), "scaleupx"); + if (_newrect==NULL) return(ibuf); + + if (ibuf->rect_float) { + do_float = 1; + _newrectf = MEM_mallocN(newx * ibuf->y * sizeof(float) * 4, "scaleupxf"); + if (_newrectf==NULL) return(ibuf); + } - _newrect = (uchar *) malloc(newx * ibuf->y * sizeof(int)); - if (_newrect == 0) return(ibuf); add = (ibuf->x - 1.001) / (newx - 1.0); rect = (uchar *) ibuf->rect; + rectf = (float *) ibuf->rect_float; newrect = _newrect; + newrectf = _newrectf = NULL; for (y = ibuf->y; y>0 ; y--){ @@ -456,9 +668,34 @@ static struct ImBuf *scaleupx(struct ImBuf *ibuf, int newx) val_r += 0.5; rect += 8; + + if (do_float) { + val_af = rectf[0] ; + nval_af = rectf[4]; + diff_af = nval_af - val_af; + val_af += 0.5; + + val_bf = rectf[1] ; + nval_bf = rectf[5]; + diff_bf = nval_bf - val_bf; + val_bf += 0.5; + + val_gf = rectf[2] ; + nval_gf = rectf[6]; + diff_gf = nval_gf - val_gf; + val_gf += 0.5; + + val_rf = rectf[3] ; + nval_rf = rectf[7]; + diff_rf = nval_rf - val_rf; + val_rf += 0.5; + + rectf += 8; + } for (x = newx ; x>0 ; x--){ if (sample >= 1.0){ sample -= 1.0; + val_a = nval_a ; nval_a = rect[0] ; diff_a = nval_a - val_a ; @@ -479,12 +716,42 @@ static struct ImBuf *scaleupx(struct ImBuf *ibuf, int newx) diff_r = nval_r - val_r ; val_r += 0.5; rect += 4; + + if (do_float) { + val_af = nval_af ; + nval_af = rectf[0] ; + diff_af = nval_af - val_af ; + val_af += 0.5; + + val_bf = nval_bf ; + nval_bf = rectf[1] ; + diff_bf = nval_bf - val_bf ; + val_bf += 0.5; + + val_gf = nval_gf ; + nval_gf = rectf[2] ; + diff_gf = nval_gf - val_gf ; + val_gf += 0.5; + + val_rf = nval_rf ; + nval_rf = rectf[3] ; + diff_rf = nval_rf - val_rf; + val_rf += 0.5; + rectf += 4; + } } newrect[0] = val_a + sample * diff_a; newrect[1] = val_b + sample * diff_b; newrect[2] = val_g + sample * diff_g; newrect[3] = val_r + sample * diff_r; newrect += 4; + if (do_float) { + newrectf[0] = val_af + sample * diff_af; + newrectf[1] = val_bf + sample * diff_bf; + newrectf[2] = val_gf + sample * diff_gf; + newrectf[3] = val_rf + sample * diff_rf; + newrectf += 4; + } sample += add; } } @@ -492,6 +759,13 @@ static struct ImBuf *scaleupx(struct ImBuf *ibuf, int newx) imb_freerectImBuf(ibuf); ibuf->mall |= IB_rect; ibuf->rect = (unsigned int *) _newrect; + + if (do_float) { + imb_freerectfloatImBuf(ibuf); + ibuf->mall |= IB_rectfloat; + ibuf->rect_float = (float *) _newrectf; + } + ibuf->x = newx; return(ibuf); } @@ -500,24 +774,44 @@ static struct ImBuf *scaleupx(struct ImBuf *ibuf, int newx) static struct ImBuf *scaleupy(struct ImBuf *ibuf, int newy) { uchar *rect,*_newrect,*newrect; - float sample,add,val,nval,diff; - int x,y,i,skipx; + float *rectf = NULL, *newrectf = NULL, *_newrectf = NULL; + float sample,add,val,nval,diff, valf=0.0f, nvalf=0.0f, difff=0.0f; + int x,y,i,skipx, do_float = 0; - if (ibuf == 0) return(0); - if (ibuf->rect == 0) return(ibuf); + if (ibuf==NULL) return(0); + if (ibuf->rect==NULL) return(ibuf); - _newrect = (uchar *)malloc(newy * ibuf->x * sizeof(int)); - if (_newrect == 0) return(ibuf); + _newrect = MEM_mallocN(newy * ibuf->x * sizeof(int), "scaleupy"); + if (_newrect==NULL) return(ibuf); + if (ibuf->rect_float) { + do_float = 1; + _newrectf = MEM_mallocN(newy * ibuf->y * sizeof(float) * 4, "scaleupyf"); + if (_newrectf==NULL) return(ibuf); + } + add = (ibuf->y - 1.001) / (newy - 1.0); skipx = 4 * ibuf->x; /* all four components, rgba/abgr */ for(i=3 ; i>=0 ; i--){ for (x = skipx - 4; x >= 0 ; x -= 4){ + rect = (uchar *) ibuf->rect; rect += i + x; newrect = _newrect + i + x; + + if (do_float) { + rectf = ibuf->rect_float; + rectf += i * x; + newrectf = _newrectf + i + x; + valf = *rectf; + rectf += skipx; + nvalf = *rectf; + rectf += skipx; + difff = nvalf - valf; + valf += 0.5; + } sample = 0; val = *rect ; @@ -535,9 +829,22 @@ static struct ImBuf *scaleupy(struct ImBuf *ibuf, int newy) rect += skipx; diff = nval - val; val += 0.5; + + if (do_float) { + valf = nvalf; + nvalf = *rectf; + rectf += skipx; + difff = nvalf - valf; + valf += 0.5; + } } *newrect = val + sample * diff; newrect += skipx; + + if (do_float) { + *newrectf = valf + sample * difff; + newrectf += skipx; + } sample += add; } } @@ -546,20 +853,28 @@ static struct ImBuf *scaleupy(struct ImBuf *ibuf, int newy) imb_freerectImBuf(ibuf); ibuf->mall |= IB_rect; ibuf->rect = (unsigned int *) _newrect; + + if(do_float) { + imb_freerectfloatImBuf(ibuf); + ibuf->mall |= IB_rectfloat; + ibuf->rect_float = _newrectf; + } + ibuf->y = newy; return(ibuf); } +/* no float buf needed here! */ static void scalefast_Z_ImBuf(ImBuf *ibuf, short newx, short newy) { - unsigned int *rect,*_newrect,*newrect; - int x,y; - int ofsx,ofsy,stepx,stepy; + unsigned int *rect, *_newrect, *newrect; + int x, y; + int ofsx, ofsy, stepx, stepy; if (ibuf->zbuf) { - _newrect = malloc(newx * newy * sizeof(int)); - if (_newrect == 0) return; - + _newrect = MEM_mallocN(newx * newy * sizeof(int), "z rect"); + if (_newrect==NULL) return; + stepx = (65536.0 * (ibuf->x - 1.0) / (newx - 1.0)) + 0.5; stepy = (65536.0 * (ibuf->y - 1.0) / (newy - 1.0)) + 0.5; ofsy = 32768; @@ -585,8 +900,8 @@ static void scalefast_Z_ImBuf(ImBuf *ibuf, short newx, short newy) struct ImBuf *IMB_scaleImBuf(struct ImBuf * ibuf, short newx, short newy) { - if (ibuf == 0) return (0); - if (ibuf->rect == 0) return (ibuf); + if (ibuf==NULL) return (0); + if (ibuf->rect==NULL) return (ibuf); // scaleup / scaledown functions below change ibuf->x and ibuf->y // so we first scale the Z-buffer (if any) @@ -604,18 +919,28 @@ struct ImBuf *IMB_scaleImBuf(struct ImBuf * ibuf, short newx, short newy) struct ImBuf *IMB_scalefastImBuf(struct ImBuf *ibuf, short newx, short newy) { unsigned int *rect,*_newrect,*newrect; - int x,y; + float *rectf,*_newrectf,*newrectf; + int x,y, do_float=0; int ofsx,ofsy,stepx,stepy; - if (ibuf == 0) return(0); - if (ibuf->rect == 0) return(ibuf); + rectf = NULL; _newrectf = NULL; newrectf = NULL; - if (newx == ibuf->x && newy == ibuf->y) return(ibuf); + if (ibuf==NULL) return(0); + if (ibuf->rect==NULL) return(ibuf); + if (ibuf->rect_float) do_float = 1; - _newrect = malloc(newx * newy * sizeof(int)); - if (_newrect == 0) return(ibuf); + if (newx == ibuf->x && newy == ibuf->y) return(ibuf); + _newrect = MEM_mallocN(newx * newy * sizeof(int), "scalefastimbuf"); + if (_newrect==NULL) return(ibuf); newrect = _newrect; + + if (do_float) { + _newrectf = MEM_mallocN(newx * newy * sizeof(float) * 4, "scalefastimbuf f"); + if (_newrectf==NULL) return(ibuf); + newrectf = _newrectf; + } + stepx = (65536.0 * (ibuf->x - 1.0) / (newx - 1.0)) + 0.5; stepy = (65536.0 * (ibuf->y - 1.0) / (newy - 1.0)) + 0.5; ofsy = 32768; @@ -623,10 +948,16 @@ struct ImBuf *IMB_scalefastImBuf(struct ImBuf *ibuf, short newx, short newy) for (y = newy; y > 0 ; y--){ rect = ibuf->rect; rect += (ofsy >> 16) * ibuf->x; + if (do_float) { + rectf = ibuf->rect_float; + rectf += (ofsy >> 16) * ibuf->x; + } ofsy += stepy; ofsx = 32768; + for (x = newx ; x>0 ; x--){ *newrect++ = rect[ofsx >> 16]; + if (do_float) *newrectf++ = rectf[ofsx >> 16]; ofsx += stepx; } } @@ -635,6 +966,12 @@ struct ImBuf *IMB_scalefastImBuf(struct ImBuf *ibuf, short newx, short newy) ibuf->mall |= IB_rect; ibuf->rect = _newrect; + if (do_float) { + imb_freerectfloatImBuf(ibuf); + ibuf->mall |= IB_rectfloat; + ibuf->rect_float = _newrectf; + } + scalefast_Z_ImBuf(ibuf, newx, newy); ibuf->x = newx; @@ -646,33 +983,34 @@ struct ImBuf *IMB_scalefastImBuf(struct ImBuf *ibuf, short newx, short newy) static struct ImBuf *generic_fieldscale(struct ImBuf *ibuf, short newx, short newy, struct ImBuf *(*scalefunc)(ImBuf *, short, short) ) { struct ImBuf *sbuf1, *sbuf2; -/* extern void rectcpy(); */ - sbuf1 = IMB_allocImBuf(ibuf->x, ibuf->y / 2, ibuf->depth, IB_rect, 0); - sbuf2 = IMB_allocImBuf(ibuf->x, ibuf->y / 2, ibuf->depth, IB_rect, 0); + sbuf1 = IMB_allocImBuf(ibuf->x, ibuf->y / 2, ibuf->depth, ibuf->flags, 0); + sbuf2 = IMB_allocImBuf(ibuf->x, ibuf->y / 2, ibuf->depth, ibuf->flags, 0); ibuf->x *= 2; + /* more args needed, 0 assumed... (nzc) */ -/* rectop(sbuf1, ibuf, 0, 0, 0, 0, 32767, 32767, rectcpy); */ -/* rectop(sbuf2, ibuf, 0, 0, sbuf2->x, 0, 32767, 32767, rectcpy); */ - IMB_rectop(sbuf1, ibuf, 0, 0, 0, 0, 32767, 32767, IMB_rectcpy, 0); - IMB_rectop(sbuf2, ibuf, 0, 0, sbuf2->x, 0, 32767, 32767, IMB_rectcpy, 0); + IMB_rectcpy(sbuf1, ibuf, 0, 0, 0, 0, ibuf->x, ibuf->y); + IMB_rectcpy(sbuf2, ibuf, 0, 0, sbuf2->x, 0, ibuf->x, ibuf->y); imb_freerectImBuf(ibuf); + imb_freerectfloatImBuf(ibuf); + ibuf->x = newx; ibuf->y = newy; - imb_addrectImBuf(ibuf); + imb_addrectImBuf(ibuf); + if(ibuf->flags & IB_rectfloat) + imb_addrectfloatImBuf(ibuf); + scalefunc(sbuf1, newx, newy / 2); scalefunc(sbuf2, newx, newy / 2); ibuf->x *= 2; /* more args needed, 0 assumed... (nzc) */ -/* rectop(ibuf, sbuf1, 0, 0, 0, 0, 32767, 32767, rectcpy); */ -/* rectop(ibuf, sbuf2, sbuf2->x, 0, 0, 0, 32767, 32767, rectcpy); */ - IMB_rectop(ibuf, sbuf1, 0, 0, 0, 0, 32767, 32767, IMB_rectcpy, 0); - IMB_rectop(ibuf, sbuf2, sbuf2->x, 0, 0, 0, 32767, 32767, IMB_rectcpy, 0); + IMB_rectcpy(ibuf, sbuf1, 0, 0, 0, 0, sbuf1->x, sbuf1->y); + IMB_rectcpy(ibuf, sbuf2, sbuf2->x, 0, 0, 0, sbuf2->x, sbuf2->y); ibuf->x /= 2; @@ -683,9 +1021,7 @@ static struct ImBuf *generic_fieldscale(struct ImBuf *ibuf, short newx, short ne } -struct ImBuf *IMB_scalefastfieldImBuf(struct ImBuf *ibuf, - short newx, - short newy) +struct ImBuf *IMB_scalefastfieldImBuf(struct ImBuf *ibuf, short newx, short newy) { return(generic_fieldscale(ibuf, newx, newy, IMB_scalefastImBuf)); } @@ -694,3 +1030,4 @@ struct ImBuf *IMB_scalefieldImBuf(struct ImBuf *ibuf, short newx, short newy) { return(generic_fieldscale(ibuf, newx, newy, IMB_scaleImBuf)); } + diff --git a/source/blender/imbuf/intern/targa.c b/source/blender/imbuf/intern/targa.c index 5c064098671..331c1031599 100644 --- a/source/blender/imbuf/intern/targa.c +++ b/source/blender/imbuf/intern/targa.c @@ -518,8 +518,8 @@ struct ImBuf *imb_loadtarga(unsigned char *mem, int flags) if (checktarga(&tga,mem) == 0) return(0); - if (flags & IB_test) ibuf = IMB_allocImBuf(tga.xsize,tga.ysize,tga.pixsize,0,0); - else ibuf = IMB_allocImBuf(tga.xsize,tga.ysize,(tga.pixsize + 0x7) & ~0x7,1,0); + if (flags & IB_test) ibuf = IMB_allocImBuf(tga.xsize,tga.ysize,tga.pixsize, 0, 0); + else ibuf = IMB_allocImBuf(tga.xsize,tga.ysize,(tga.pixsize + 0x7) & ~0x7, IB_rect, 0); if (ibuf == 0) return(0); ibuf->ftype = TGA; @@ -629,7 +629,7 @@ struct ImBuf *imb_loadtarga(unsigned char *mem, int flags) if (ibuf) { if (ibuf->rect && (flags & IB_cmap)==0) - IMB_convert_rgba_to_abgr((ibuf->x+ibuf->skipx)*ibuf->y, ibuf->rect); + IMB_convert_rgba_to_abgr(ibuf); } return(ibuf); diff --git a/source/blender/imbuf/intern/tiff.c b/source/blender/imbuf/intern/tiff.c index 616531b3a77..6fc5fb99f8b 100644 --- a/source/blender/imbuf/intern/tiff.c +++ b/source/blender/imbuf/intern/tiff.c @@ -399,7 +399,7 @@ struct ImBuf *imb_loadtiff(unsigned char *mem, int size, int flags) /* close the client layer interface to the in-memory file */ libtiff_TIFFClose(image); - if (G.order == B_ENDIAN) IMB_convert_rgba_to_abgr(ibuf->x*ibuf->y, ibuf->rect); + if (G.order == B_ENDIAN) IMB_convert_rgba_to_abgr(ibuf); /* return successfully */ return (ibuf); diff --git a/source/blender/imbuf/intern/util.c b/source/blender/imbuf/intern/util.c index 4cdfa852df1..8110a115471 100644 --- a/source/blender/imbuf/intern/util.c +++ b/source/blender/imbuf/intern/util.c @@ -50,6 +50,10 @@ #include "IMB_anim.h" +#ifdef WITH_OPENEXR +#include "openexr/openexr_api.h" +#endif + #ifdef WITH_QUICKTIME #include "quicktime_import.h" #endif @@ -97,7 +101,9 @@ static int IMB_ispic_name(char *name) } if (imb_is_a_png(buf)) return(PNG); if (imb_is_a_targa(buf)) return(TGA); - +#ifdef WITH_OPENEXR + if (imb_is_a_openexr((uchar *)buf)) return(OPENEXR); +#endif if (imb_is_a_tiff(buf)) return(TIF); /* radhdr: check if hdr format */ diff --git a/source/blender/imbuf/intern/writeimage.c b/source/blender/imbuf/intern/writeimage.c index 340f8ace415..b752dbf9dd0 100644 --- a/source/blender/imbuf/intern/writeimage.c +++ b/source/blender/imbuf/intern/writeimage.c @@ -57,12 +57,15 @@ #include "IMB_bmp.h" #include "IMB_tiff.h" #include "IMB_radiance_hdr.h" +#ifdef WITH_OPENEXR +#include "openexr/openexr_api.h" +#endif #include "IMB_iff.h" #include "IMB_bitplanes.h" #include "IMB_divers.h" -short IMB_saveiff(struct ImBuf *ibuf,char *naam,int flags) +short IMB_saveiff(struct ImBuf *ibuf, char *name, int flags) { short ok=TRUE,delpl=FALSE; int file = -1; @@ -72,28 +75,33 @@ short IMB_saveiff(struct ImBuf *ibuf,char *naam,int flags) /* Put formats that take a filename here */ if (IS_jpg(ibuf)) { - return imb_savejpeg(ibuf, naam, flags); + return imb_savejpeg(ibuf, name, flags); } if (IS_radhdr(ibuf)) { - return imb_savehdr(ibuf, naam, flags); + return imb_savehdr(ibuf, name, flags); } if (IS_png(ibuf)) { - return imb_savepng(ibuf,naam,flags); + return imb_savepng(ibuf, name, flags); } if (IS_bmp(ibuf)) { - return imb_savebmp(ibuf,naam,flags); + return imb_savebmp(ibuf, name, flags); } if (IS_tga(ibuf)) { - return imb_savetarga(ibuf,naam,flags); + return imb_savetarga(ibuf, name, flags); } if (IS_iris(ibuf)) { - return imb_saveiris(ibuf,naam,flags); + return imb_saveiris(ibuf, name, flags); } if (G.have_libtiff && IS_tiff(ibuf)) { - return imb_savetiff(ibuf,naam,flags); + return imb_savetiff(ibuf, name, flags); + } +#ifdef WITH_OPENEXR + if (IS_openexr(ibuf)) { + return imb_save_openexr_half(ibuf, name, flags); } +#endif - file = open(naam, O_BINARY | O_RDWR | O_CREAT | O_TRUNC, 0666); + file = open(name, O_BINARY | O_RDWR | O_CREAT | O_TRUNC, 0666); if (file < 0) return (FALSE); if (flags & IB_rect){ @@ -103,7 +111,6 @@ short IMB_saveiff(struct ImBuf *ibuf,char *naam,int flags) } /* Put formats that take a filehandle here */ - ok = imb_start_iff(ibuf,file); if (IS_amiga(ibuf)){ IMB_flipy(ibuf); -- cgit v1.2.3