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... :/
This commit is contained in:
2006-01-09 00:40:35 +00:00
parent 104ab9b103
commit 014aa7261e
53 changed files with 1754 additions and 661 deletions

View File

@@ -17,6 +17,9 @@ SConscript(['avi/SConscript',
'src/SConscript', 'src/SConscript',
'yafray/SConscript']) 'yafray/SConscript'])
if user_options_dict['USE_OPENEXR'] == 1:
SConscript (['imbuf/intern/openexr/SConscript'])
if user_options_dict['USE_INTERNATIONAL'] == 1: if user_options_dict['USE_INTERNATIONAL'] == 1:
SConscript (['ftfont/SConscript']) SConscript (['ftfont/SConscript'])

View File

@@ -124,7 +124,7 @@ typedef struct Global {
struct VFont *selfont; struct VFont *selfont;
struct ListBase ttfdata; struct ListBase ttfdata;
/* libtiff flag */ /* libtiff flag used to determine if shared library loaded for libtiff*/
int have_libtiff; int have_libtiff;
/* this variable is written to / read from FileGlobal->fileflags */ /* this variable is written to / read from FileGlobal->fileflags */

View File

@@ -83,3 +83,7 @@ ifeq ($(WITH_FREETYPE2), true)
CPPFLAGS += -I$(NAN_FREETYPE)/include/freetype2 CPPFLAGS += -I$(NAN_FREETYPE)/include/freetype2
endif endif
ifeq ($(WITH_OPENEXR), true)
CPPFLAGS += -DWITH_OPENEXR
endif

View File

@@ -341,8 +341,15 @@ void addImageExtension(char *string)
extension= ".bmp"; extension= ".bmp";
} }
else if(G.have_libtiff && (G.scene->r.imtype==R_TIFF)) { else if(G.have_libtiff && (G.scene->r.imtype==R_TIFF)) {
if(!BLI_testextensie(string, ".tif"))
extension= ".tif"; extension= ".tif";
} }
#ifdef WITH_OPENEXR
else if(G.scene->r.imtype==R_OPENEXR) {
if(!BLI_testextensie(string, ".exr"))
extension= ".exr";
}
#endif
strcat(string, extension); strcat(string, extension);
} }
@@ -449,13 +456,13 @@ static void de_interlace_ng(struct ImBuf *ibuf) /* neogeo fields */
tbuf2 = IMB_allocImBuf(ibuf->x, (short)(ibuf->y >> 1), (unsigned char)32, (int)IB_rect, (unsigned char)0); tbuf2 = IMB_allocImBuf(ibuf->x, (short)(ibuf->y >> 1), (unsigned char)32, (int)IB_rect, (unsigned char)0);
ibuf->x *= 2; ibuf->x *= 2;
/* These rectop calls are broken!!! I added a trailing 0 arg... */
IMB_rectop(tbuf1, ibuf, 0, 0, 0, 0, 32767, 32767, IMB_rectcpy, 0); IMB_rectcpy(tbuf1, ibuf, 0, 0, 0, 0, ibuf->x, ibuf->y);
IMB_rectop(tbuf2, ibuf, 0, 0, tbuf2->x, 0, 32767, 32767, IMB_rectcpy, 0); IMB_rectcpy(tbuf2, ibuf, 0, 0, tbuf2->x, 0, ibuf->x, ibuf->y);
ibuf->x /= 2; ibuf->x /= 2;
IMB_rectop(ibuf, tbuf1, 0, 0, 0, 0, 32767, 32767, IMB_rectcpy, 0); IMB_rectcpy(ibuf, tbuf1, 0, 0, 0, 0, tbuf1->x, tbuf1->y);
IMB_rectop(ibuf, tbuf2, 0, tbuf2->y, 0, 0, 32767, 32767, IMB_rectcpy, 0); IMB_rectcpy(ibuf, tbuf2, 0, tbuf2->y, 0, 0, tbuf2->x, tbuf2->y);
IMB_freeImBuf(tbuf1); IMB_freeImBuf(tbuf1);
IMB_freeImBuf(tbuf2); IMB_freeImBuf(tbuf2);
@@ -477,13 +484,13 @@ static void de_interlace_st(struct ImBuf *ibuf) /* standard fields */
tbuf2 = IMB_allocImBuf(ibuf->x, (short)(ibuf->y >> 1), (unsigned char)32, IB_rect, 0); tbuf2 = IMB_allocImBuf(ibuf->x, (short)(ibuf->y >> 1), (unsigned char)32, IB_rect, 0);
ibuf->x *= 2; ibuf->x *= 2;
/* These are brolenm as well... */
IMB_rectop(tbuf1, ibuf, 0, 0, 0, 0, 32767, 32767, IMB_rectcpy, 0); IMB_rectcpy(tbuf1, ibuf, 0, 0, 0, 0, ibuf->x, ibuf->y);
IMB_rectop(tbuf2, ibuf, 0, 0, tbuf2->x, 0, 32767, 32767, IMB_rectcpy, 0); IMB_rectcpy(tbuf2, ibuf, 0, 0, tbuf2->x, 0, ibuf->x, ibuf->y);
ibuf->x /= 2; ibuf->x /= 2;
IMB_rectop(ibuf, tbuf2, 0, 0, 0, 0, 32767, 32767, IMB_rectcpy, 0); IMB_rectcpy(ibuf, tbuf2, 0, 0, 0, 0, tbuf2->x, tbuf2->y);
IMB_rectop(ibuf, tbuf1, 0, tbuf2->y, 0, 0, 32767, 32767, IMB_rectcpy, 0); IMB_rectcpy(ibuf, tbuf1, 0, tbuf2->y, 0, 0, tbuf1->x, tbuf1->y);
IMB_freeImBuf(tbuf1); IMB_freeImBuf(tbuf1);
IMB_freeImBuf(tbuf2); IMB_freeImBuf(tbuf2);
@@ -559,7 +566,7 @@ void ima_ibuf_is_nul(Tex *tex, Image *ima)
} }
IMB_applycmap(ima->ibuf); IMB_applycmap(ima->ibuf);
IMB_convert_rgba_to_abgr(ima->ibuf->x*ima->ibuf->y, ima->ibuf->rect); IMB_convert_rgba_to_abgr(ima->ibuf);
} }

View File

@@ -35,10 +35,6 @@
#include <string.h> #include <string.h>
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
#include "MEM_guardedalloc.h" #include "MEM_guardedalloc.h"
#include "BLI_blenlib.h" #include "BLI_blenlib.h"
@@ -122,7 +118,8 @@ void start_avi(void)
void append_avi(int frame) void append_avi(int frame)
{ {
unsigned int *rt1, *rt2, *temp; unsigned int *rt1, *rt2;
struct ImBuf *temp;
int y; int y;
if (avi == NULL) { if (avi == NULL) {
@@ -131,19 +128,19 @@ void append_avi(int frame)
} }
/* note that libavi free's the buffer... stupid interface - zr */ /* note that libavi free's the buffer... stupid interface - zr */
temp = MEM_mallocN(R.rectx*R.recty*4, "append_avi buf"); temp = IMB_allocImBuf(R.rectx,R.recty*4,32, IB_rect, 0);
rt1= temp; rt1= temp->rect;
rt2= R.rectot + (R.recty-1)*R.rectx; rt2= R.rectot + (R.recty-1)*R.rectx;
for (y=0; y < R.recty; y++, rt1+= R.rectx, rt2-= R.rectx) { for (y=0; y < R.recty; y++, rt1+= R.rectx, rt2-= R.rectx) {
memcpy (rt1, rt2, R.rectx*4); memcpy (rt1, rt2, R.rectx*4);
} }
IMB_convert_rgba_to_abgr(R.rectx*R.recty, temp); IMB_convert_rgba_to_abgr(temp);
AVI_write_frame (avi, (frame-sframe), AVI_FORMAT_RGB32, AVI_write_frame (avi, (frame-sframe), AVI_FORMAT_RGB32, temp->rect, R.rectx*R.recty*4);
temp, R.rectx*R.recty*4);
printf ("added frame %3d (frame %3d in avi): ", frame, frame-sframe); printf ("added frame %3d (frame %3d in avi): ", frame, frame-sframe);
IMB_freeImBuf(temp);
} }
void end_avi(void) void end_avi(void)

View File

@@ -139,6 +139,7 @@ int BLI_stringdec(char *string, char *kop, char *staart, unsigned short *numlen)
else if (BLI_strncasecmp(string + len - 4, ".rgb", 4) == 0) len -= 4; else if (BLI_strncasecmp(string + len - 4, ".rgb", 4) == 0) len -= 4;
else if (BLI_strncasecmp(string + len - 4, ".psx", 4) == 0) len -= 4; else if (BLI_strncasecmp(string + len - 4, ".psx", 4) == 0) len -= 4;
else if (BLI_strncasecmp(string + len - 4, ".ble", 4) == 0) len -= 4; else if (BLI_strncasecmp(string + len - 4, ".ble", 4) == 0) len -= 4;
else if (BLI_strncasecmp(string + len - 4, ".exr", 4) == 0) len -= 4;
} }
} }

View File

@@ -45,9 +45,15 @@
#define IB_rgba (1 << 14) #define IB_rgba (1 << 14)
#define AMI (1 << 31) #define AMI (1 << 31)
#define PNG (1 << 30)
#define Anim (1 << 29) #define Anim (1 << 29)
#define TGA (1 << 28) #define TGA (1 << 28)
#define JPG (1 << 27) #define JPG (1 << 27)
#define BMP (1 << 26)
#ifdef WITH_QUICKTIME
#define QUICKTIME (1 << 25)
#endif
#define RADHDR (1<<24)
#define RAWTGA (TGA | 1) #define RAWTGA (TGA | 1)
@@ -90,6 +96,7 @@
#define IS_amiga(x) (x->ftype & AMI) #define IS_amiga(x) (x->ftype & AMI)
#define IS_ham(x) ((x->ftype & AM_ham) == AM_ham) #define IS_ham(x) ((x->ftype & AM_ham) == AM_ham)
#define IS_hbrite(x) ((x->ftype & AM_hbrite) == AM_hbrite) #define IS_hbrite(x) ((x->ftype & AM_hbrite) == AM_hbrite)
#define IS_lace(x) ((x->ftype & AM_lace) == AM_lace) #define IS_lace(x) ((x->ftype & AM_lace) == AM_lace)
#define IS_hires(x) ((x->ftype & AM_hires) == AM_hires) #define IS_hires(x) ((x->ftype & AM_hires) == AM_hires)
#define IS_hblace(x) ((x->ftype & AM_hblace) == AM_hblace) #define IS_hblace(x) ((x->ftype & AM_hblace) == AM_hblace)
@@ -98,9 +105,14 @@
#define IS_anim(x) (x->ftype & Anim) #define IS_anim(x) (x->ftype & Anim)
#define IS_hamx(x) (x->ftype == AN_hamx) #define IS_hamx(x) (x->ftype == AN_hamx)
#define IS_tga(x) (x->ftype & TGA) #define IS_tga(x) (x->ftype & TGA)
#define IS_png(x) (x->ftype & PNG)
#define IS_bmp(x) (x->ftype & BMP)
#define IS_radhdr(x) (x->ftype & RADHDR)
#define IS_tim(x) (x->ftype & TIM) #define IS_tim(x) (x->ftype & TIM)
#define IS_tiff(x) (x->ftype & TIFF)
#define IS_openexr(x) (x->ftype & OPENEXR)
#define IMAGIC 0732 #define IMAGIC 0732
#define IS_iris(x) (x->ftype == IMAGIC) #define IS_iris(x) (x->ftype == IMAGIC)
@@ -136,6 +148,7 @@ typedef struct ImBuf{
unsigned char *encodedbuffer; unsigned char *encodedbuffer;
unsigned int encodedsize; unsigned int encodedsize;
unsigned int encodedbuffersize; unsigned int encodedbuffersize;
float *rect_float;
} ImBuf; } ImBuf;
extern struct ImBuf *allocImBuf(short,short,uchar,uint,uchar); extern struct ImBuf *allocImBuf(short,short,uchar,uint,uchar);

View File

@@ -41,10 +41,6 @@
* - util.h : Useful defines, memory management. * - util.h : Useful defines, memory management.
*/ */
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
#ifdef WIN32 #ifdef WIN32
#include "blenpluginapi\util.h" #include "blenpluginapi\util.h"
#else #else
@@ -250,20 +246,6 @@ void de_interlace(struct ImBuf *ib)
IMB_de_interlace(ib); IMB_de_interlace(ib);
} }
void 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)
{
IMB_rectop(dbuf, sbuf, destx, desty, srcx, srcy, width, height, operation, value);
}
/* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */
/* stuff from plugin.h */ /* stuff from plugin.h */
/* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */
@@ -354,6 +336,5 @@ int pluginapi_force_ref(void)
(int) turbulence1 + (int) turbulence1 +
(int) de_interlace + (int) de_interlace +
(int) interlace + (int) interlace +
(int) gamwarp + (int) gamwarp;
(int) rectop;
} }

View File

@@ -196,31 +196,8 @@ void IMB_freecmapImBuf(struct ImBuf * ibuf);
* *
* @attention Defined in rectop.c * @attention Defined in rectop.c
*/ */
void IMB_rectop(struct ImBuf *dbuf, void IMB_rectcpy(struct ImBuf *drect, struct ImBuf *srect, int destx,
struct ImBuf *sbuf, int desty, int srcx, int srcy, int width, int height);
int destx,
int desty,
int srcx,
int srcy,
int width,
int height,
void (*operation)(unsigned int *, unsigned int*, int, int),
int value);
/**
*
* @attention Defined in rectop.c
*/
void IMB_rectoptot(struct ImBuf *dbuf,
struct ImBuf *sbuf,
void (*operation)(unsigned int *, unsigned int*, int, int),
int value);
/**
*
* @attention Defined in rectop.c
*/
void IMB_rectcpy(unsigned int *drect, unsigned int *srect, int x, int dummy);
/** /**
* Return the length (in frames) of the given @a anim. * Return the length (in frames) of the given @a anim.
@@ -360,7 +337,7 @@ void IMB_gamwarp(struct ImBuf *ibuf, double gamma);
* *
* @attention Defined in imageprocess.c * @attention Defined in imageprocess.c
*/ */
void IMB_convert_rgba_to_abgr(int size, unsigned int *rect); void IMB_convert_rgba_to_abgr(struct ImBuf *ibuf);
/** /**
* Change the ordering of the colour bytes pointed to by rect from * Change the ordering of the colour bytes pointed to by rect from
@@ -495,7 +472,7 @@ void IMB_freezbufImBuf(struct ImBuf * ibuf);
* *
* @attention Defined in rectop.c * @attention Defined in rectop.c
*/ */
void IMB_rectfill(unsigned int *drect, unsigned int *srect, int x, int value); void IMB_rectfill(struct ImBuf *drect, float col[4]);
#ifdef WITH_QUICKTIME #ifdef WITH_QUICKTIME
@@ -513,12 +490,6 @@ void quicktime_exit(void);
#endif //WITH_QUICKTIME #endif //WITH_QUICKTIME
/* radhdr: Temporary routine to save directly from render floatbuffer.
Defined in radiance_hdr.c
Called by schrijfplaatje() in toets.c */
short imb_savehdr_fromfloat(float *fbuf, char *name, int width, int height);
/* intern/dynlibtiff.c */ /* intern/dynlibtiff.c */
void libtiff_exit(void); void libtiff_exit(void);

View File

@@ -93,6 +93,7 @@ typedef struct ImBuf{
unsigned char *encodedbuffer; /**< Compressed image only used with png currently */ unsigned char *encodedbuffer; /**< Compressed image only used with png currently */
unsigned int encodedsize; /**< Size of data written to encodedbuffer */ unsigned int encodedsize; /**< Size of data written to encodedbuffer */
unsigned int encodedbuffersize; /**< Size of encodedbuffer */ unsigned int encodedbuffersize; /**< Size of encodedbuffer */
float *rect_float; /**< floating point Rect equivilant */
} ImBuf; } ImBuf;
/* Moved from BKE_bmfont_types.h because it is a userflag bit mask. */ /* Moved from BKE_bmfont_types.h because it is a userflag bit mask. */
@@ -131,6 +132,8 @@ typedef enum {
#define IB_zbuf (1 << 13) #define IB_zbuf (1 << 13)
#define IB_mem (1 << 14) #define IB_mem (1 << 14)
#define IB_rectfloat (1 << 15)
/**@}*/ /**@}*/
/** \name imbuf_formats Image file formats /** \name imbuf_formats Image file formats
@@ -147,11 +150,14 @@ typedef enum {
#define TGA (1 << 28) #define TGA (1 << 28)
#define JPG (1 << 27) #define JPG (1 << 27)
#define BMP (1 << 26) #define BMP (1 << 26)
#ifdef WITH_QUICKTIME #ifdef WITH_QUICKTIME
#define QUICKTIME (1 << 25) #define QUICKTIME (1 << 25)
#endif #endif
#define RADHDR (1 << 24) #define RADHDR (1 << 24)
#define TIF (1 << 23) #define TIF (1 << 23)
#define OPENEXR (1 << 22)
#define RAWTGA (TGA | 1) #define RAWTGA (TGA | 1)
@@ -188,6 +194,7 @@ typedef enum {
#define IS_hamx(x) (x->ftype == AN_hamx) #define IS_hamx(x) (x->ftype == AN_hamx)
#define IS_tga(x) (x->ftype & TGA) #define IS_tga(x) (x->ftype & TGA)
#define IS_png(x) (x->ftype & PNG) #define IS_png(x) (x->ftype & PNG)
#define IS_openexr(x) (x->ftype & OPENEXR)
#define IS_bmp(x) (x->ftype & BMP) #define IS_bmp(x) (x->ftype & BMP)
#define IS_tiff(x) (x->ftype & TIF) #define IS_tiff(x) (x->ftype & TIF)
#define IS_radhdr(x) (x->ftype & RADHDR) #define IS_radhdr(x) (x->ftype & RADHDR)

View File

@@ -5,6 +5,9 @@ Import ('library_env')
imbuf_env = library_env.Copy () imbuf_env = library_env.Copy ()
#if user_options_dict['USE_OPENEXR'] == 1:
# SConscript (['intern/openexr/SConscript'])
source_files = ['intern/allocimbuf.c', source_files = ['intern/allocimbuf.c',
'intern/amiga.c', 'intern/amiga.c',
'intern/anim.c', 'intern/anim.c',

View File

@@ -43,12 +43,14 @@
struct ImBuf; struct ImBuf;
short imb_addrectImBuf(struct ImBuf * ibuf); short imb_addrectImBuf(struct ImBuf * ibuf);
short imb_addrectfloatImBuf(struct ImBuf * ibuf);
short imb_addplanesImBuf(struct ImBuf *ibuf); short imb_addplanesImBuf(struct ImBuf *ibuf);
short imb_addencodedbufferImBuf(struct ImBuf *ibuf); short imb_addencodedbufferImBuf(struct ImBuf *ibuf);
short imb_enlargeencodedbufferImBuf(struct ImBuf *ibuf); short imb_enlargeencodedbufferImBuf(struct ImBuf *ibuf);
void imb_freerectImBuf(struct ImBuf *ibuf); void imb_freerectImBuf(struct ImBuf *ibuf);
void imb_freerectfloatImBuf(struct ImBuf *ibuf);
void imb_freeplanesImBuf(struct ImBuf *ibuf); void imb_freeplanesImBuf(struct ImBuf *ibuf);
short imb_addcmapImBuf(struct ImBuf *ibuf); short imb_addcmapImBuf(struct ImBuf *ibuf);

View File

@@ -33,13 +33,25 @@
LIBNAME = imbuf LIBNAME = imbuf
DIR = $(OCGDIR)/blender/imbuf DIR = $(OCGDIR)/blender/imbuf
SOURCEDIR = source/blender/imbuf/intern
include nan_subdirs.mk
include nan_compile.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")) ifeq ($(OS),$(findstring $(OS), "beos darwin freebsd linux openbsd solaris windows"))
CFLAGS += -funsigned-char CFLAGS += -funsigned-char
endif endif
ifeq ($(WITH_OPENEXR), true)
CFLAGS += -DWITH_OPENEXR
endif
CFLAGS += $(LEVEL_1_C_WARNINGS) CFLAGS += $(LEVEL_1_C_WARNINGS)
CPPFLAGS += -I$(NAN_JPEG)/include CPPFLAGS += -I$(NAN_JPEG)/include

View File

@@ -53,30 +53,48 @@ static unsigned int dfltcmap[16] = {
void imb_freeplanesImBuf(struct ImBuf * ibuf) void imb_freeplanesImBuf(struct ImBuf * ibuf)
{ {
if (ibuf==0) return; if (ibuf==NULL) return;
if (ibuf->planes){ if (ibuf->planes){
if (ibuf->mall & IB_planes) free(ibuf->planes); if (ibuf->mall & IB_planes) MEM_freeN(ibuf->planes);
} }
ibuf->planes = 0; ibuf->planes = 0;
ibuf->mall &= ~IB_planes; 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) void imb_freerectImBuf(struct ImBuf * ibuf)
{ {
if (ibuf==0) return; if (ibuf==NULL) return;
if (ibuf->rect) { if (ibuf->rect) {
if (ibuf->mall & IB_rect) free(ibuf->rect); if (ibuf->mall & IB_rect) {
MEM_freeN(ibuf->rect);
} }
ibuf->rect=0; }
ibuf->rect= NULL;
ibuf->mall &= ~IB_rect; ibuf->mall &= ~IB_rect;
} }
static void freeencodedbufferImBuf(struct ImBuf * ibuf) static void freeencodedbufferImBuf(struct ImBuf * ibuf)
{ {
if (ibuf==0) return; if (ibuf==NULL) return;
if (ibuf->encodedbuffer){ if (ibuf->encodedbuffer){
if (ibuf->mall & IB_mem) free(ibuf->encodedbuffer); if (ibuf->mall & IB_mem) MEM_freeN(ibuf->encodedbuffer);
} }
ibuf->encodedbuffer = 0; ibuf->encodedbuffer = 0;
ibuf->encodedbuffersize = 0; ibuf->encodedbuffersize = 0;
@@ -86,34 +104,34 @@ static void freeencodedbufferImBuf(struct ImBuf * ibuf)
void IMB_freezbufImBuf(struct ImBuf * ibuf) void IMB_freezbufImBuf(struct ImBuf * ibuf)
{ {
if (ibuf==0) return; if (ibuf==NULL) return;
if (ibuf->zbuf){ 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; ibuf->mall &= ~IB_zbuf;
} }
void IMB_freecmapImBuf(struct ImBuf * ibuf) void IMB_freecmapImBuf(struct ImBuf * ibuf)
{ {
if (ibuf == 0) return; if (ibuf==NULL) return;
if (ibuf->cmap){ if (ibuf->cmap){
if (ibuf->mall & IB_cmap) free(ibuf->cmap); if (ibuf->mall & IB_cmap) MEM_freeN(ibuf->cmap);
} }
ibuf->cmap = 0; ibuf->cmap = 0;
ibuf->mall &= ~IB_cmap; ibuf->mall &= ~IB_cmap;
} }
void IMB_freeImBuf(struct ImBuf * ibuf) void IMB_freeImBuf(struct ImBuf * ibuf)
{ {
if (ibuf){ if (ibuf){
imb_freeplanesImBuf(ibuf); imb_freeplanesImBuf(ibuf);
imb_freerectImBuf(ibuf); imb_freerectImBuf(ibuf);
imb_freerectfloatImBuf(ibuf);
IMB_freezbufImBuf(ibuf); IMB_freezbufImBuf(ibuf);
IMB_freecmapImBuf(ibuf); IMB_freecmapImBuf(ibuf);
freeencodedbufferImBuf(ibuf); freeencodedbufferImBuf(ibuf);
free(ibuf); MEM_freeN(ibuf);
} }
} }
@@ -121,7 +139,8 @@ short addzbufImBuf(struct ImBuf * ibuf)
{ {
int size; int size;
if (ibuf==0) return(FALSE); if (ibuf==NULL) return(FALSE);
IMB_freezbufImBuf(ibuf); IMB_freezbufImBuf(ibuf);
size = ibuf->x * ibuf->y * sizeof(unsigned int); size = ibuf->x * ibuf->y * sizeof(unsigned int);
@@ -136,7 +155,7 @@ short addzbufImBuf(struct ImBuf * ibuf)
short imb_addencodedbufferImBuf(struct ImBuf * ibuf) short imb_addencodedbufferImBuf(struct ImBuf * ibuf)
{ {
if (ibuf==0) return(FALSE); if (ibuf==NULL) return(FALSE);
freeencodedbufferImBuf(ibuf); freeencodedbufferImBuf(ibuf);
@@ -159,7 +178,7 @@ short imb_enlargeencodedbufferImBuf(struct ImBuf * ibuf)
unsigned int newsize, encodedsize; unsigned int newsize, encodedsize;
void *newbuffer; void *newbuffer;
if (ibuf==0) return(FALSE); if (ibuf==NULL) return(FALSE);
if (ibuf->encodedbuffersize < ibuf->encodedsize) { if (ibuf->encodedbuffersize < ibuf->encodedsize) {
printf("imb_enlargeencodedbufferImBuf: error in parameters\n"); printf("imb_enlargeencodedbufferImBuf: error in parameters\n");
@@ -190,15 +209,36 @@ short imb_enlargeencodedbufferImBuf(struct ImBuf * ibuf)
return (TRUE); 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) short imb_addrectImBuf(struct ImBuf * ibuf)
{ {
int size; int size;
if (ibuf==0) return(FALSE); if (ibuf==NULL) return(FALSE);
imb_freerectImBuf(ibuf); 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")) ){ if ( (ibuf->rect = MEM_mallocN(size, "imb_addrectImBuf")) ){
ibuf->mall |= IB_rect; ibuf->mall |= IB_rect;
if (ibuf->depth > 32) return (addzbufImBuf(ibuf)); if (ibuf->depth > 32) return (addzbufImBuf(ibuf));
@@ -213,7 +253,7 @@ short imb_addcmapImBuf(struct ImBuf *ibuf)
{ {
int min; int min;
if (ibuf==0) return(FALSE); if (ibuf==NULL) return(FALSE);
IMB_freecmapImBuf(ibuf); IMB_freecmapImBuf(ibuf);
imb_checkncols(ibuf); imb_checkncols(ibuf);
@@ -238,7 +278,7 @@ short imb_addplanesImBuf(struct ImBuf *ibuf)
unsigned int **planes; unsigned int **planes;
unsigned int *point2; unsigned int *point2;
if (ibuf==0) return(FALSE); if (ibuf==NULL) return(FALSE);
imb_freeplanesImBuf(ibuf); imb_freeplanesImBuf(ibuf);
skipx = ((ibuf->x+31) >> 5); skipx = ((ibuf->x+31) >> 5);
@@ -280,21 +320,28 @@ struct ImBuf *IMB_allocImBuf(short x,short y,uchar d,unsigned int flags,uchar bi
if (flags & IB_rect){ if (flags & IB_rect){
if (imb_addrectImBuf(ibuf)==FALSE){ if (imb_addrectImBuf(ibuf)==FALSE){
IMB_freeImBuf(ibuf); 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 (flags & IB_zbuf){
if (addzbufImBuf(ibuf)==FALSE){ if (addzbufImBuf(ibuf)==FALSE){
IMB_freeImBuf(ibuf); IMB_freeImBuf(ibuf);
return (0); return NULL;
} }
} }
if (flags & IB_planes){ if (flags & IB_planes){
if (imb_addplanesImBuf(ibuf)==FALSE){ if (imb_addplanesImBuf(ibuf)==FALSE){
IMB_freeImBuf(ibuf); IMB_freeImBuf(ibuf);
return (0); return NULL;
} }
} }
} }
@@ -307,9 +354,10 @@ struct ImBuf *IMB_dupImBuf(struct ImBuf *ibuf1)
int flags = 0; int flags = 0;
int x, y; int x, y;
if (ibuf1 == 0) return (0); if (ibuf1 == NULL) return NULL;
if (ibuf1->rect) flags |= IB_rect; if (ibuf1->rect) flags |= IB_rect;
if (ibuf1->rect_float) flags |= IB_rectfloat;
if (ibuf1->planes) flags |= IB_planes; if (ibuf1->planes) flags |= IB_planes;
x = ibuf1->x; x = ibuf1->x;
@@ -317,31 +365,38 @@ struct ImBuf *IMB_dupImBuf(struct ImBuf *ibuf1)
if (ibuf1->flags & IB_fields) y *= 2; if (ibuf1->flags & IB_fields) y *= 2;
ibuf2 = IMB_allocImBuf(x, y, ibuf1->depth, flags, 0); 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_rect)
if (flags & IB_planes) memcpy(*(ibuf2->planes),*(ibuf1->planes),ibuf1->depth * ibuf1->skipx * y * sizeof(int)); 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) { if (ibuf1->encodedbuffer) {
ibuf2->encodedbuffersize = ibuf1->encodedbuffersize; ibuf2->encodedbuffersize = ibuf1->encodedbuffersize;
if (imb_addencodedbufferImBuf(ibuf2) == FALSE) { if (imb_addencodedbufferImBuf(ibuf2) == FALSE) {
IMB_freeImBuf(ibuf2); IMB_freeImBuf(ibuf2);
return(0); return NULL;
} }
memcpy(ibuf2->encodedbuffer, ibuf1->encodedbuffer, ibuf1->encodedsize); memcpy(ibuf2->encodedbuffer, ibuf1->encodedbuffer, ibuf1->encodedsize);
} }
/* silly trick to copy the entire contents of ibuf1 struct over to ibuf */
tbuf = *ibuf1; tbuf = *ibuf1;
// pointers goedzetten // fix pointers
tbuf.rect = ibuf2->rect; tbuf.rect = ibuf2->rect;
tbuf.rect_float = ibuf2->rect_float;
tbuf.planes = ibuf2->planes; tbuf.planes = ibuf2->planes;
tbuf.cmap = ibuf2->cmap; tbuf.cmap = ibuf2->cmap;
tbuf.encodedbuffer = ibuf2->encodedbuffer; tbuf.encodedbuffer = ibuf2->encodedbuffer;
// malloc flag goed zetten // set malloc flag
tbuf.mall = ibuf2->mall; tbuf.mall = ibuf2->mall;
*ibuf2 = tbuf; *ibuf2 = tbuf;

View File

@@ -531,7 +531,7 @@ struct ImBuf *imb_loadamiga(int *iffmem,int flags)
if (ibuf) { if (ibuf) {
if (ibuf->rect) 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); return (ibuf);

View File

@@ -572,7 +572,7 @@ struct ImBuf * IMB_anim_absolute(struct anim * anim, int position) {
ibuf = movie_fetchibuf(anim, position); ibuf = movie_fetchibuf(anim, position);
if (ibuf) { if (ibuf) {
anim->curposition = position; anim->curposition = position;
IMB_convert_rgba_to_abgr(ibuf->x*ibuf->y, ibuf->rect); IMB_convert_rgba_to_abgr(ibuf);
} }
break; break;
case ANIM_AVI: case ANIM_AVI:

View File

@@ -161,7 +161,7 @@ static void planes_to_rect(struct ImBuf * ibuf, int flags) {
if (ibuf->cmap){ if (ibuf->cmap){
if ((flags & IB_cmap) == 0) { if ((flags & IB_cmap) == 0) {
IMB_applycmap(ibuf); 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){ } else if (ibuf->depth == 18){
int i,col; int i,col;

View File

@@ -178,6 +178,8 @@ void imb_bptolong(struct ImBuf *ibuf)
{ {
int nobp,i,x; int nobp,i,x;
unsigned int *rect,offset; 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 */ /* first clear all ints */
@@ -187,8 +189,8 @@ void imb_bptolong(struct ImBuf *ibuf)
nobp=ibuf->depth; nobp=ibuf->depth;
if (nobp != 32){ if (nobp != 32){
if (nobp == 24) IMB_rectoptot(ibuf, 0, IMB_rectfill, 0xff000000); /* set alpha */ if (nobp == 24) IMB_rectfill(ibuf, black); /* set alpha */
else IMB_rectoptot(ibuf, 0, IMB_rectfill, 0); else IMB_rectfill(ibuf, clear);
} }
rect= ibuf->rect; rect= ibuf->rect;

View File

@@ -95,12 +95,12 @@ void IMB_de_interlace(struct ImBuf *ibuf)
tbuf2 = IMB_allocImBuf(ibuf->x, ibuf->y / 2, 32, IB_rect, 0); tbuf2 = IMB_allocImBuf(ibuf->x, ibuf->y / 2, 32, IB_rect, 0);
ibuf->x *= 2; ibuf->x *= 2;
IMB_rectop(tbuf1, ibuf, 0, 0, 0, 0, 32767, 32767, IMB_rectcpy, 0); IMB_rectcpy(tbuf1, ibuf, 0, 0, 0, 0, ibuf->x, ibuf->y);
IMB_rectop(tbuf2, ibuf, 0, 0, tbuf2->x, 0, 32767, 32767, IMB_rectcpy, 0); IMB_rectcpy(tbuf2, ibuf, 0, 0, tbuf2->x, 0, ibuf->x, ibuf->y);
ibuf->x /= 2; ibuf->x /= 2;
IMB_rectop(ibuf, tbuf1, 0, 0, 0, 0, 32767, 32767, IMB_rectcpy, 0); IMB_rectcpy(ibuf, tbuf1, 0, 0, 0, 0, tbuf1->x, tbuf1->y);
IMB_rectop(ibuf, tbuf2, 0, tbuf2->y, 0, 0, 32767, 32767, IMB_rectcpy, 0); IMB_rectcpy(ibuf, tbuf2, 0, tbuf2->y, 0, 0, tbuf2->x, tbuf2->y);
IMB_freeImBuf(tbuf1); IMB_freeImBuf(tbuf1);
IMB_freeImBuf(tbuf2); 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); tbuf1 = IMB_allocImBuf(ibuf->x, ibuf->y / 2, 32, IB_rect, 0);
tbuf2 = 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, IMB_rectcpy(tbuf1, ibuf, 0, 0, 0, 0, ibuf->x, ibuf->y);
0); IMB_rectcpy(tbuf2, ibuf, 0, 0, 0, tbuf2->y, ibuf->x, ibuf->y);
IMB_rectop(tbuf2, ibuf, 0, 0, 0, tbuf2->y, 32767, 32767,
IMB_rectcpy,0);
ibuf->x *= 2; ibuf->x *= 2;
IMB_rectop(ibuf, tbuf1, 0, 0, 0, 0, 32767, 32767, IMB_rectcpy, IMB_rectcpy(ibuf, tbuf1, 0, 0, 0, 0, tbuf1->x, tbuf1->y);
0); IMB_rectcpy(ibuf, tbuf2, tbuf2->x, 0, 0, 0, tbuf2->x, tbuf2->y);
IMB_rectop(ibuf, tbuf2, tbuf2->x, 0, 0, 0, 32767, 32767,
IMB_rectcpy,0);
ibuf->x /= 2; ibuf->x /= 2;
IMB_freeImBuf(tbuf1); IMB_freeImBuf(tbuf1);
@@ -143,11 +139,13 @@ void IMB_interlace(struct ImBuf *ibuf)
void IMB_gamwarp(struct ImBuf *ibuf, double gamma) void IMB_gamwarp(struct ImBuf *ibuf, double gamma)
{ {
uchar gam[256]; uchar gam[256];
int i; int i, do_float=0;
uchar *rect; uchar *rect = (uchar *) ibuf->rect;
float *rectf = ibuf->rect_float;
if (ibuf == 0) return; if (ibuf == 0) return;
if (ibuf->rect == 0) return; if (ibuf->rect == 0) return;
if (ibuf->rect != NULL) do_float = 1;
if (gamma == 1.0) return; if (gamma == 1.0) return;
gamma = 1.0 / gamma; gamma = 1.0 / gamma;
@@ -159,5 +157,10 @@ void IMB_gamwarp(struct ImBuf *ibuf, double gamma)
rect[0] = gam[rect[0]]; rect[0] = gam[rect[0]];
rect[1] = gam[rect[1]]; rect[1] = gam[rect[1]];
rect[2] = gam[rect[2]]; 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);
}
} }
} }

View File

@@ -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) 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) void IMB_filtery(struct ImBuf *ibuf)
{ {
unsigned char *point; unsigned char *point;
int x, y, skip; float *pointf;
int x, y, skip, do_float = 0;
point = (unsigned char *)ibuf->rect; point = (unsigned char *)ibuf->rect;
pointf = ibuf->rect_float;
if (ibuf->rect_float != NULL) do_float = 1;
x = ibuf->x; x = ibuf->x;
y = ibuf->y; y = ibuf->y;
skip = x<<2; skip = x<<2;
@@ -109,6 +154,16 @@ void IMB_filtery(struct ImBuf *ibuf)
point++; point++;
filtcolum(point,y,skip); filtcolum(point,y,skip);
point++; 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) void imb_filterx(struct ImBuf *ibuf)
{ {
unsigned char *point; unsigned char *point;
int x, y, skip; float *pointf;
int x, y, skip, do_float =0;
point = (unsigned char *)ibuf->rect; point = (unsigned char *)ibuf->rect;
pointf = ibuf->rect_float;
if (ibuf->rect_float != NULL) do_float = 1;
x = ibuf->x; x = ibuf->x;
y = ibuf->y; y = ibuf->y;
skip = (x<<2) - 3; skip = (x<<2) - 3;
@@ -132,6 +192,16 @@ void imb_filterx(struct ImBuf *ibuf)
point++; point++;
filtrow(point,x); filtrow(point,x);
point+=skip; 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;
}
} }
} }

View File

@@ -40,12 +40,18 @@
* $Id$ * $Id$
*/ */
#include "IMB_imbuf_types.h"
#include "IMB_imbuf.h" #include "IMB_imbuf.h"
/* Only this one is used liberally here, and in imbuf */ /* 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) { while(size-- > 0) {
rt= cp[0]; rt= cp[0];
@@ -55,5 +61,15 @@ void IMB_convert_rgba_to_abgr(int size, unsigned int *rect)
cp[1]= cp[2]; cp[1]= cp[2];
cp[2]= rt; cp[2]= rt;
cp+= 4; 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;
} }
} }
}

View File

@@ -398,7 +398,7 @@ struct ImBuf *imb_loadiris(unsigned char *mem, int flags)
if (ibuf) { if (ibuf) {
if (ibuf->rect) if (ibuf->rect)
IMB_convert_rgba_to_abgr(ibuf->x*ibuf->y, ibuf->rect); IMB_convert_rgba_to_abgr(ibuf);
} }
return(ibuf); return(ibuf);
@@ -639,13 +639,13 @@ short imb_saveiris(struct ImBuf * ibuf, char *name, int flags)
zsize = (ibuf->depth + 7) >> 3; zsize = (ibuf->depth + 7) >> 3;
if (flags & IB_zbuf && ibuf->zbuf != 0) zsize = 8; 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); test_endian_zbuf(ibuf);
ret = output_iris(ibuf->rect, ibuf->x, ibuf->y, zsize, name, ibuf->zbuf); ret = output_iris(ibuf->rect, ibuf->x, ibuf->y, zsize, name, ibuf->zbuf);
/* restore! Quite clumsy, 2 times a switch... maybe better a malloc ? */ /* 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); test_endian_zbuf(ibuf);
return(ret); return(ret);

View File

@@ -553,15 +553,12 @@ static int save_jstjpeg(char * name, struct ImBuf * ibuf)
ibuf->x *= 2; ibuf->x *= 2;
ibuf->y /= 2; ibuf->y /= 2;
/* extra argument assumed to be 0 (nzc) */ IMB_rectcpy(tbuf, ibuf, 0, 0, 0, 0, ibuf->x, ibuf->y);
IMB_rectop(tbuf, ibuf, 0, 0, 0, 0, 32767, 32767, IMB_rectcpy, 0);
sprintf(fieldname, "%s.jf0", name); sprintf(fieldname, "%s.jf0", name);
returnval = save_vidjpeg(fieldname, tbuf) ; returnval = save_vidjpeg(fieldname, tbuf) ;
if (returnval == 1) { if (returnval == 1) {
/* extra argument assumed to be 0 (nzc) */ IMB_rectcpy(tbuf, ibuf, 0, 0, tbuf->x, 0, ibuf->x, ibuf->y);
IMB_rectop(tbuf, ibuf, 0, 0, tbuf->x, 0, 32767, 32767,
IMB_rectcpy, 0);
sprintf(fieldname, "%s.jf1", name); sprintf(fieldname, "%s.jf1", name);
returnval = save_vidjpeg(fieldname, tbuf); returnval = save_vidjpeg(fieldname, tbuf);
} }

View File

@@ -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 <gz@lysator.liu.se>
#
# ***** 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.

View File

@@ -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)

View File

@@ -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 <gz@lysator.liu.se>.
* 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 <stdlib.h>
#include <stdio.h>
#include <string>
#include <openexr_api.h>
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 <iostream>
#include <OpenEXR/half.h>
#include <OpenEXR/ImfVersion.h>
#include <OpenEXR/ImathBox.h>
#include <OpenEXR/ImfArray.h>
#include <OpenEXR/ImfIO.h>
#include <OpenEXR/ImfChannelList.h>
#include <OpenEXR/ImfPixelType.h>
#include <OpenEXR/ImfInputFile.h>
#include <OpenEXR/ImfOutputFile.h>
#include <OpenEXR/ImfCompression.h>
#include <OpenEXR/ImfCompressionAttribute.h>
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"

View File

@@ -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 <stdio.h>
/**
* 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 */

View File

@@ -29,13 +29,12 @@
* ***** END GPL LICENSE BLOCK ***** * ***** END GPL LICENSE BLOCK *****
*/ */
/* ----------------------------------------------------------------------
/*
-------------------------------------------------------------------------------------------------
Radiance High Dynamic Range image file IO 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 http://radsite.lbl.gov/radiance/refer/Notes/picture_format.html
------------------------------------------------------------------------------------------------- ----------------------------------------------------------------------
*/ */
#ifdef WIN32 #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_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]) #define copy_fcol(f1, f2) (f2[RED]=f1[RED], f2[GRN]=f1[GRN], f2[BLU]=f1[BLU])
/*-------------------------------------------------------------------------------------------------*/
/* read routines */ /* read routines */
static unsigned char* oldreadcolrs(RGBE *scan, unsigned char *mem, int xmax) static unsigned char* oldreadcolrs(RGBE *scan, unsigned char *mem, int xmax)
{ {
int i, rshift = 0, len = xmax; int i, rshift = 0, len = xmax;
@@ -127,7 +124,6 @@ static unsigned char* freadcolrs(RGBE *scan, unsigned char* mem, int xmax)
return mem; return mem;
} }
/*-------------------------------------------------------------------------------------------------*/
/* helper functions */ /* helper functions */
/* rgbe -> float color */ /* rgbe -> float color */
@@ -161,7 +157,6 @@ static void FLOAT2RGBE(fCOLOR fcol, RGBE rgbe)
} }
} }
/*-------------------------------------------------------------------------------------------------*/
/* ImBuf read */ /* ImBuf read */
int imb_is_a_hdr(void *buf) 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 *imb_loadhdr(unsigned char *mem, int size, int flags)
{ {
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* rect;
struct ImBuf* ibuf; struct ImBuf* ibuf;
RGBE* sline;
fCOLOR fcol;
float* rect_float;
int found=0;
int width=0, height=0;
int x, y;
int ir, ig, ib;
unsigned char* ptr;
unsigned char* rect;
char oriY[80], oriX[80];
if (imb_is_a_hdr((void*)mem)) 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); sscanf((char*)&mem[x+1], "%s %d %s %d", (char*)&oriY, &height, (char*)&oriX, &width);
/* find end of this line, data right behind it */ /* 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++; ptr++;
if (flags & IB_test) ibuf = IMB_allocImBuf(width, height, 24, 0, 0); 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; if (ibuf==NULL) return NULL;
ibuf->ftype = RADHDR; 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 */ /* read in and decode the actual data */
sline = (RGBE*)MEM_mallocN(sizeof(RGBE)*width, "radhdr_read_tmpscan"); sline = (RGBE*)MEM_mallocN(sizeof(RGBE)*width, "radhdr_read_tmpscan");
rect = (unsigned char*)ibuf->rect; rect = (unsigned char*)ibuf->rect;
rect_float = (float *)ibuf->rect_float;
for (y=0;y<height;y++) { for (y=0;y<height;y++) {
ptr = freadcolrs(sline, ptr, width); ptr = freadcolrs(sline, ptr, width);
if (ptr==NULL) { if (ptr==NULL) {
@@ -223,10 +221,13 @@ struct ImBuf *imb_loadhdr(unsigned char *mem, int size, int flags)
for (x=0;x<width;x++) { for (x=0;x<width;x++) {
/* convert to ldr */ /* convert to ldr */
RGBE2FLOAT(sline[x], fcol); RGBE2FLOAT(sline[x], fcol);
/*--------------------------------------------------------------------------------------*/ *rect_float++ = fcol[RED];
/* THIS PART NEEDS TO BE ADAPTED TO WRITE TO IMBUF FLOATBUFFER ONCE THAT IS IMPLEMENTED *rect_float++ = fcol[GRN];
* temporarily now loads as regular image using simple tone mapping *rect_float++ = fcol[BLU];
* (of course this should NOT be done when loading to floatbuffer!) */ *rect_float++ = 255;
/* Also old oldstyle for the rest of blender which is not using floats yet */
/* very weird mapping! (ton) */
fcol[RED] = 1.f-exp(fcol[RED]*-1.414213562f); fcol[RED] = 1.f-exp(fcol[RED]*-1.414213562f);
fcol[GRN] = 1.f-exp(fcol[GRN]*-1.414213562f); fcol[GRN] = 1.f-exp(fcol[GRN]*-1.414213562f);
fcol[BLU] = 1.f-exp(fcol[BLU]*-1.414213562f); fcol[BLU] = 1.f-exp(fcol[BLU]*-1.414213562f);
@@ -237,7 +238,6 @@ struct ImBuf *imb_loadhdr(unsigned char *mem, int size, int flags)
*rect++ = (unsigned char)((ig<0) ? 0 : ((ig>255) ? 255 : ig)); *rect++ = (unsigned char)((ig<0) ? 0 : ((ig>255) ? 255 : ig));
*rect++ = (unsigned char)((ib<0) ? 0 : ((ib>255) ? 255 : ib)); *rect++ = (unsigned char)((ib<0) ? 0 : ((ib>255) ? 255 : ib));
*rect++ = 255; *rect++ = 255;
/*--------------------------------------------------------------------------------------*/
} }
} }
MEM_freeN(sline); MEM_freeN(sline);
@@ -251,36 +251,39 @@ struct ImBuf *imb_loadhdr(unsigned char *mem, int size, int flags)
return NULL; return NULL;
} }
/*-------------------------------------------------------------------------------------------------*/
/* ImBuf write */ /* ImBuf write */
static int fwritecolrs(FILE* file, int width, unsigned char* ibufscan, float* fpscan)
static int fwritecolrs(FILE* file, int width, RGBE* rgbe_scan, unsigned char* ibufscan, float* fpscan)
{ {
int i, j, beg, c2, cnt=0; int x, i, j, beg, c2, cnt=0;
fCOLOR fcol; fCOLOR fcol;
RGBE rgbe; RGBE rgbe, *rgbe_scan;
if ((ibufscan==NULL) && (fpscan==NULL)) return 0; if ((ibufscan==NULL) && (fpscan==NULL)) return 0;
rgbe_scan = (RGBE*)MEM_mallocN(sizeof(RGBE)*width, "radhdr_write_tmpscan");
/* convert scanline */ /* convert scanline */
for (i=0, j=0;i<width;i++, j+=4) { j= 0;
if (ibufscan) { for (i=0;i<width;i++) {
if (fpscan) {
fcol[RED] = fpscan[j];
fcol[GRN] = fpscan[j+1];
fcol[BLU] = fpscan[j+2];
} else {
fcol[RED] = (float)ibufscan[j] / 255.f; fcol[RED] = (float)ibufscan[j] / 255.f;
fcol[GRN] = (float)ibufscan[j+1] / 255.f; fcol[GRN] = (float)ibufscan[j+1] / 255.f;
fcol[BLU] = (float)ibufscan[j+2] /255.f; fcol[BLU] = (float)ibufscan[j+2] /255.f;
} }
else {
fcol[RED] = fpscan[j];
fcol[GRN] = fpscan[j+1];
fcol[BLU] = fpscan[j+2];
}
FLOAT2RGBE(fcol, rgbe); FLOAT2RGBE(fcol, rgbe);
copy_rgbe(rgbe, rgbe_scan[i]); copy_rgbe(rgbe, rgbe_scan[i]);
j+=4;
} }
if ((width < MINELEN) | (width > MAXELEN)) /* OOBs, write out flat */ if ((width < MINELEN) | (width > MAXELEN)) { /* OOBs, write out flat */
return (fwrite((char *)rgbe_scan, sizeof(RGBE), width, file) - width); x=fwrite((char *)rgbe_scan, sizeof(RGBE), width, file) - width;
MEM_freeN(rgbe_scan);
return x;
}
/* put magic header */ /* put magic header */
putc(2, file); putc(2, file);
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; else cnt = 0;
} }
} }
MEM_freeN(rgbe_scan);
return(ferror(file) ? -1 : 0); 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) short imb_savehdr(struct ImBuf *ibuf, char *name, int flags)
{ {
int y, width=ibuf->x, height=ibuf->y; int y, width=ibuf->x, height=ibuf->y;
RGBE* sline;
FILE* file = fopen(name, "wb"); FILE* file = fopen(name, "wb");
if (file==NULL) return 0; if (file==NULL) return 0;
writeHeader(file, width, height); writeHeader(file, width, height);
sline = (RGBE*)MEM_mallocN(sizeof(RGBE)*width, "radhdr_write_tmpscan");
for (y=height-1;y>=0;y--) { for (y=height-1;y>=0;y--) {
if (fwritecolrs(file, width, sline, (unsigned char*)&ibuf->rect[y*width], NULL) < 0) if (fwritecolrs(file, width,(unsigned char *)&ibuf->rect[y*width*4], &ibuf->rect_float[y*width*4]) < 0) {
{ // error
fclose(file); fclose(file);
MEM_freeN(sline);
printf("HDR write error\n"); printf("HDR write error\n");
return 0; return 0;
} }
} }
fclose(file); fclose(file);
MEM_freeN(sline);
return 1; 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
fclose(file);
MEM_freeN(sline);
printf("HDR write error\n");
return 0;
}
}
fclose(file);
MEM_freeN(sline);
return 1;
}
/*-------------------------------------------------------------------------------------------------*/

View File

@@ -54,6 +54,10 @@
#include "IMB_radiance_hdr.h" #include "IMB_radiance_hdr.h"
#include "BKE_global.h" #include "BKE_global.h"
#ifdef WITH_OPENEXR
#include "openexr/openexr_api.h"
#endif
#ifdef WITH_QUICKTIME #ifdef WITH_QUICKTIME
#if defined(_WIN32) || defined (__APPLE__) #if defined(_WIN32) || defined (__APPLE__)
#include "quicktime_import.h" #include "quicktime_import.h"
@@ -138,6 +142,9 @@ ImBuf *IMB_ibImageFromMemory(int *mem, int size, int flags) {
ibuf = imb_loadhdr((uchar*)mem, size, flags); ibuf = imb_loadhdr((uchar*)mem, size, flags);
if (ibuf) return (ibuf); if (ibuf) return (ibuf);
ibuf = imb_load_openexr((uchar *)mem, size, flags);
if (ibuf) return (ibuf);
#ifdef WITH_QUICKTIME #ifdef WITH_QUICKTIME
#if defined(_WIN32) || defined (__APPLE__) #if defined(_WIN32) || defined (__APPLE__)
if(G.have_quicktime) { if(G.have_quicktime) {

View File

@@ -41,33 +41,17 @@
#include "IMB_allocimbuf.h" #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; unsigned int *drect, *srect;
int tmp; float *drectf = NULL;
float *srectf = NULL;
int tmp, do_float = 0;
if (dbuf == 0) return; if (dbuf == NULL) return;
if (operation == 0) return;
if (sbuf->rect_float) do_float = 1;
if (destx < 0){ if (destx < 0){
srcx -= destx ; srcx -= destx ;
@@ -96,6 +80,7 @@ void IMB_rectop(struct ImBuf *dbuf,
if (height > tmp) height = tmp; if (height > tmp) height = tmp;
drect = dbuf->rect + desty * dbuf->x + destx; drect = dbuf->rect + desty * dbuf->x + destx;
if (do_float) drectf = dbuf->rect_float + desty * dbuf->x + destx;
destx = dbuf->x; destx = dbuf->x;
if (sbuf){ if (sbuf){
@@ -110,25 +95,53 @@ void IMB_rectop(struct ImBuf *dbuf,
srect = sbuf->rect; srect = sbuf->rect;
srect += srcy * sbuf->x; srect += srcy * sbuf->x;
srect += srcx; srect += srcx;
if (do_float) {
srectf = sbuf->rect_float;
srectf += srcy * sbuf->x;
srectf += srcx;
}
srcx = sbuf->x; srcx = sbuf->x;
} else{ } else{
if (width <= 0) return; if (width <= 0) return;
if (height <= 0) return; if (height <= 0) return;
srect = drect; srect = drect;
srectf = drectf;
srcx = destx; srcx = destx;
} }
for (;height > 0; height--){ for (;height > 0; height--){
operation(drect,srect,width, value);
drect += destx; memcpy(drect,srect, width * sizeof(int));
srect += srcx; if (do_float) memcpy(drectf,srectf, width * sizeof(float) * 4);
} }
} }
void IMB_rectfill(struct ImBuf *drect, float col[4])
void IMB_rectoptot(struct ImBuf *dbuf, struct ImBuf *sbuf,
void (*operation)(unsigned int *, unsigned int*, int, int), int value)
{ {
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];
}
}
}

View File

@@ -43,26 +43,46 @@
void IMB_flipy(struct ImBuf * ibuf) void IMB_flipy(struct ImBuf * ibuf)
{ {
short x,y,backx; short x, y;
unsigned int *top,*bottom,temp; unsigned int *top, *bottom, do_float=0, *line;
float *topf=NULL, *bottomf=NULL, *linef=NULL;
if (ibuf == 0) return; if (ibuf == NULL) return;
if (ibuf->rect == 0) return; if (ibuf->rect == NULL) return;
if (ibuf->rect_float) do_float =1;
x = ibuf->x; x = ibuf->x;
y = ibuf->y; y = ibuf->y;
backx = x<<1;
top = ibuf->rect; top = ibuf->rect;
bottom = top + ((y-1) * x); 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; y >>= 1;
for(;y>0;y--) { for(;y>0;y--) {
for(x = ibuf->x; x > 0; x--){
temp = *top; memcpy(line, top, x*sizeof(int));
*(top++) = *bottom; memcpy(top, bottom, x*sizeof(int));
*(bottom++) = temp; memcpy(bottom, line, x*sizeof(int));
} bottom -= x;
bottom -= backx; 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;
} }
} }
MEM_freeN(line);
if(linef) MEM_freeN(linef);
}

View File

@@ -52,20 +52,27 @@ struct ImBuf *IMB_half_x(struct ImBuf *ibuf1)
struct ImBuf *ibuf2; struct ImBuf *ibuf2;
uchar *p1,*_p1,*dest; uchar *p1,*_p1,*dest;
short a,r,g,b,x,y; 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==NULL) return (0);
if (ibuf1->rect == 0) return (0); if (ibuf1->rect==NULL) return (0);
if (ibuf1->rect_float) do_float = 1;
if (ibuf1->x <= 1) return(IMB_dupImBuf(ibuf1)); if (ibuf1->x <= 1) return(IMB_dupImBuf(ibuf1));
ibuf2 = IMB_allocImBuf((ibuf1->x)/2 , ibuf1->y , ibuf1->depth,1,0); ibuf2 = IMB_allocImBuf((ibuf1->x)/2, ibuf1->y, ibuf1->depth, ibuf1->flags, 0);
if (ibuf2==0) return (0); if (ibuf2==NULL) return (0);
_p1 = (uchar *) ibuf1->rect; _p1 = (uchar *) ibuf1->rect;
dest=(uchar *) ibuf2->rect; dest=(uchar *) ibuf2->rect;
_p1f = ibuf1->rect_float;
destf= ibuf2->rect_float;
for(y=ibuf2->y;y>0;y--){ for(y=ibuf2->y;y>0;y--){
p1 = _p1; p1 = _p1;
p1f = _p1f;
for(x = ibuf2->x ; x>0 ; x--){ for(x = ibuf2->x ; x>0 ; x--){
a = *(p1++) ; a = *(p1++) ;
b = *(p1++) ; b = *(p1++) ;
@@ -79,8 +86,23 @@ struct ImBuf *IMB_half_x(struct ImBuf *ibuf1)
*(dest++) = b >> 1; *(dest++) = b >> 1;
*(dest++) = g >> 1; *(dest++) = g >> 1;
*(dest++) = r >> 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); _p1 += (ibuf1->x << 2);
if (do_float) _p1f += (ibuf1->x << 2);
} }
return (ibuf2); 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 *IMB_double_fast_x(struct ImBuf *ibuf1)
{ {
struct ImBuf *ibuf2; 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==NULL) return (0);
if (ibuf1->rect == 0) 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); ibuf2 = IMB_allocImBuf(2 * ibuf1->x , ibuf1->y , ibuf1->depth, ibuf1->flags, 0);
if (ibuf2==0) return (0); if (ibuf2==NULL) return (0);
p1 = (int *) ibuf1->rect; p1 = (int *) ibuf1->rect;
dest=(int *) ibuf2->rect; dest=(int *) ibuf2->rect;
p1f = ibuf1->rect_float;
destf = ibuf2->rect_float;
for(i = ibuf1->y * ibuf1->x ; i>0 ; i--) { for(i = ibuf1->y * ibuf1->x ; i>0 ; i--) {
col = *p1++; col = *p1++;
*dest++ = col; *dest++ = col;
*dest++ = col; *dest++ = col;
if (do_float) {
colf = *p1f++;
*destf++ = col;
*destf++ = col;
}
} }
return (ibuf2); return (ibuf2);
@@ -113,8 +144,8 @@ struct ImBuf *IMB_double_x(struct ImBuf *ibuf1)
{ {
struct ImBuf *ibuf2; struct ImBuf *ibuf2;
if (ibuf1==0) return (0); if (ibuf1==NULL) return (0);
if (ibuf1->rect == 0) return (0); if (ibuf1->rect==NULL) return (0);
ibuf2 = IMB_double_fast_x(ibuf1); ibuf2 = IMB_double_fast_x(ibuf1);
@@ -128,20 +159,30 @@ struct ImBuf *IMB_half_y(struct ImBuf *ibuf1)
struct ImBuf *ibuf2; struct ImBuf *ibuf2;
uchar *p1,*p2,*_p1,*dest; uchar *p1,*p2,*_p1,*dest;
short a,r,g,b,x,y; 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); p1f = NULL; p2f = NULL;
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->y <= 1) return(IMB_dupImBuf(ibuf1)); if (ibuf1->y <= 1) return(IMB_dupImBuf(ibuf1));
ibuf2 = IMB_allocImBuf(ibuf1->x , (ibuf1->y) / 2 , ibuf1->depth,1,0); ibuf2 = IMB_allocImBuf(ibuf1->x , (ibuf1->y) / 2 , ibuf1->depth, ibuf1->flags, 0);
if (ibuf2==0) return (0); if (ibuf2==NULL) return (0);
_p1 = (uchar *) ibuf1->rect; _p1 = (uchar *) ibuf1->rect;
dest=(uchar *) ibuf2->rect; dest=(uchar *) ibuf2->rect;
_p1f = ibuf1->rect_float;
destf= ibuf2->rect_float;
for(y=ibuf2->y ; y>0 ; y--){ for(y=ibuf2->y ; y>0 ; y--){
p1 = _p1; p1 = _p1;
p2 = _p1 + (ibuf1->x << 2); p2 = _p1 + (ibuf1->x << 2);
if (do_float) {
p1f = _p1f;
p2f = _p1f + (ibuf1->x << 2);
}
for(x = ibuf2->x ; x>0 ; x--){ for(x = ibuf2->x ; x>0 ; x--){
a = *(p1++) ; a = *(p1++) ;
b = *(p1++) ; b = *(p1++) ;
@@ -155,8 +196,23 @@ struct ImBuf *IMB_half_y(struct ImBuf *ibuf1)
*(dest++) = b >> 1; *(dest++) = b >> 1;
*(dest++) = g >> 1; *(dest++) = g >> 1;
*(dest++) = r >> 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); _p1 += (ibuf1->x << 3);
if (do_float) _p1f += (ibuf1->x << 3);
} }
return (ibuf2); return (ibuf2);
} }
@@ -166,21 +222,31 @@ struct ImBuf *IMB_double_fast_y(struct ImBuf *ibuf1)
{ {
struct ImBuf *ibuf2; struct ImBuf *ibuf2;
int *p1, *dest1, *dest2; int *p1, *dest1, *dest2;
float *p1f, *dest1f, *dest2f;
short x,y; short x,y;
int do_float =0;
if (ibuf1==0) return (0); if (ibuf1==NULL) return (0);
if (ibuf1->rect == 0) 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); ibuf2 = IMB_allocImBuf(ibuf1->x , 2 * ibuf1->y , ibuf1->depth, ibuf1->flags, 0);
if (ibuf2==0) return (0); if (ibuf2==NULL) return (0);
p1 = (int *) ibuf1->rect; p1 = (int *) ibuf1->rect;
dest1=(int *) ibuf2->rect; dest1=(int *) ibuf2->rect;
p1f = ibuf1->rect_float;
dest1f= ibuf2->rect_float;
for(y = ibuf1->y ; y>0 ; y--){ for(y = ibuf1->y ; y>0 ; y--){
dest2 = dest1 + ibuf2->x; dest2 = dest1 + ibuf2->x;
for(x = ibuf2->x ; x>0 ; x--) *dest1++ = *dest2++ = *p1++; for(x = ibuf2->x ; x>0 ; x--) *dest1++ = *dest2++ = *p1++;
dest1 = dest2; dest1 = dest2;
if (do_float) {
dest2f = dest1f + ibuf2->x;
for(x = ibuf2->x ; x>0 ; x--) *dest1f++ = *dest2f++ = *p1f++;
dest1f = dest2f;
}
} }
return (ibuf2); return (ibuf2);
@@ -190,8 +256,8 @@ struct ImBuf *IMB_double_y(struct ImBuf *ibuf1)
{ {
struct ImBuf *ibuf2; struct ImBuf *ibuf2;
if (ibuf1==0) return (0); if (ibuf1==NULL) return (0);
if (ibuf1->rect == 0) return (0); if (ibuf1->rect==NULL) return (0);
ibuf2 = IMB_double_fast_y(ibuf1); ibuf2 = IMB_double_fast_y(ibuf1);
@@ -204,22 +270,28 @@ struct ImBuf *IMB_onehalf(struct ImBuf *ibuf1)
{ {
struct ImBuf *ibuf2; struct ImBuf *ibuf2;
uchar *p1, *p2, *dest; uchar *p1, *p2, *dest;
float *p1f, *destf, *p2f = NULL;
int x,y; int x,y;
int do_float =0;
if (ibuf1 == 0) return (0); if (ibuf1==NULL) return (0);
if (ibuf1->rect == 0) 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->x <= 1) return(IMB_half_y(ibuf1));
if (ibuf1->y <= 1) return(IMB_half_x(ibuf1)); if (ibuf1->y <= 1) return(IMB_half_x(ibuf1));
ibuf2=IMB_allocImBuf((ibuf1->x)/2,(ibuf1->y)/2,ibuf1->depth,1,0); ibuf2=IMB_allocImBuf((ibuf1->x)/2, (ibuf1->y)/2, ibuf1->depth, ibuf1->flags, 0);
if (ibuf2==0) return (0); if (ibuf2==NULL) return (0);
p1f = ibuf1->rect_float;
destf=ibuf2->rect_float;
p1 = (uchar *) ibuf1->rect; p1 = (uchar *) ibuf1->rect;
dest=(uchar *) ibuf2->rect; dest=(uchar *) ibuf2->rect;
for(y=ibuf2->y;y>0;y--){ for(y=ibuf2->y;y>0;y--){
p2 = p1 + (ibuf1->x << 2); p2 = p1 + (ibuf1->x << 2);
if (do_float) p2f = p1f + (ibuf1->x << 2);
for(x=ibuf2->x;x>0;x--){ for(x=ibuf2->x;x>0;x--){
dest[0] = (p1[0] + p2[0] + p1[4] + p2[4]) >> 2; dest[0] = (p1[0] + p2[0] + p1[4] + p2[4]) >> 2;
dest[1] = (p1[1] + p2[1] + p1[5] + p2[5]) >> 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; p1 += 8;
p2 += 8; p2 += 8;
dest += 4; 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; p1=p2;
if (do_float) p1f=p2f;
if(ibuf1->x & 1) { if(ibuf1->x & 1) {
p1+=4; p1+=4;
if (do_float) p1f+=4;
} }
} }
return (ibuf2); return (ibuf2);
@@ -243,34 +326,59 @@ struct ImBuf *IMB_onethird(struct ImBuf *ibuf1)
{ {
struct ImBuf *ibuf2; struct ImBuf *ibuf2;
uchar *p1,*p2,*p3,*dest; uchar *p1,*p2,*p3,*dest;
float *p1f, *p2f, *p3f, *destf;
int do_float=0;
short a,r,g,b,x,y,i; short a,r,g,b,x,y,i;
float af,rf,gf,bf;
if (ibuf1 == 0) return (0); p2f = NULL; p3f = NULL;
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)/3,(ibuf1->y)/3,ibuf1->depth,1,0); ibuf2=IMB_allocImBuf((ibuf1->x)/3, (ibuf1->y)/3, ibuf1->depth, ibuf1->flags, 0);
if (ibuf2==0) return (0); if (ibuf2==NULL) return (0);
p1f = ibuf1->rect_float;
destf = ibuf2->rect_float;
p1 = (uchar *) ibuf1->rect; p1 = (uchar *) ibuf1->rect;
dest=(uchar *) ibuf2->rect; dest=(uchar *) ibuf2->rect;
for(y=ibuf2->y;y>0;y--){ for(y=ibuf2->y;y>0;y--){
p2 = p1 + (ibuf1->x << 2); p2 = p1 + (ibuf1->x << 2);
p3 = p2 + (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--){ for(x=ibuf2->x;x>0;x--){
a=r=g=b=0; a=r=g=b=0;
af=rf=gf=bf=0;
for (i=3;i>0;i--){ for (i=3;i>0;i--){
a += *(p1++) + *(p2++) + *(p3++); a += *(p1++) + *(p2++) + *(p3++);
b += *(p1++) + *(p2++) + *(p3++); b += *(p1++) + *(p2++) + *(p3++);
g += *(p1++) + *(p2++) + *(p3++); g += *(p1++) + *(p2++) + *(p3++);
r += *(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++) = a/9;
*(dest++) = b/9; *(dest++) = b/9;
*(dest++) = g/9; *(dest++) = g/9;
*(dest++) = r/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; p1=p3;
if (do_float) p1f = p3f;
} }
return (ibuf2); return (ibuf2);
} }
@@ -280,33 +388,55 @@ struct ImBuf *IMB_halflace(struct ImBuf *ibuf1)
{ {
struct ImBuf *ibuf2; struct ImBuf *ibuf2;
uchar *p1,*p2,*dest; uchar *p1,*p2,*dest;
float *p1f,*p2f,*destf;
short a,r,g,b,x,y,i; short a,r,g,b,x,y,i;
float af,rf,gf,bf;
int do_float = 0;
if (ibuf1 == 0) return (0); p2f = NULL;
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)/4,(ibuf1->y)/2,ibuf1->depth,1,0); ibuf2=IMB_allocImBuf((ibuf1->x)/4, (ibuf1->y)/2, ibuf1->depth, ibuf1->flags, 0);
if (ibuf2==0) return (0); if (ibuf2==NULL) return (0);
p1f = ibuf1->rect_float;
destf= ibuf2->rect_float;
p1 = (uchar *) ibuf1->rect; p1 = (uchar *) ibuf1->rect;
dest=(uchar *) ibuf2->rect; dest=(uchar *) ibuf2->rect;
for(y= ibuf2->y / 2 ; y>0;y--){ for(y= ibuf2->y / 2 ; y>0;y--){
p2 = p1 + (ibuf1->x << 3); p2 = p1 + (ibuf1->x << 3);
if (do_float) p2f = p1f + (ibuf1->x << 3);
for(x = 2 * ibuf2->x;x>0;x--){ for(x = 2 * ibuf2->x;x>0;x--){
a=r=g=b=0; a=r=g=b=0;
af=rf=gf=bf=0;
for (i=4;i>0;i--){ for (i=4;i>0;i--){
a += *(p1++) + *(p2++); a += *(p1++) + *(p2++);
b += *(p1++) + *(p2++); b += *(p1++) + *(p2++);
g += *(p1++) + *(p2++); g += *(p1++) + *(p2++);
r += *(p1++) + *(p2++); r += *(p1++) + *(p2++);
if (do_float) {
af += *(p1f++) + *(p2f++);
bf += *(p1f++) + *(p2f++);
gf += *(p1f++) + *(p2f++);
rf += *(p1f++) + *(p2f++);
}
} }
*(dest++) = a >> 3; *(dest++) = a >> 3;
*(dest++) = b >> 3; *(dest++) = b >> 3;
*(dest++) = g >> 3; *(dest++) = g >> 3;
*(dest++) = r >> 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; p1 = p2;
if (do_float) p1f = p2f;
} }
return (ibuf2); return (ibuf2);
} }
@@ -315,14 +445,23 @@ struct ImBuf *IMB_halflace(struct ImBuf *ibuf1)
static struct ImBuf *scaledownx(struct ImBuf *ibuf, int newx) static struct ImBuf *scaledownx(struct ImBuf *ibuf, int newx)
{ {
uchar *rect,*_newrect,*newrect; uchar *rect,*_newrect,*newrect;
float sample, add, val, nval; float *rectf,*_newrectf,*newrectf;
int x, y, i; float sample, add, val, nval, valf, nvalf;
int x, y, i, do_float=0;
if (ibuf == 0) return(0); rectf = NULL; _newrectf= NULL; newrectf = NULL;
if (ibuf->rect == 0) return(ibuf); nval = 0; nvalf = 0;
_newrect = (uchar *) malloc(newx * ibuf->y * sizeof(int)); if (ibuf==NULL) return(0);
if (_newrect == 0) return(ibuf); 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 = MEM_mallocN(newx * ibuf->y * sizeof(int), "scaledownx");
if (_newrect==NULL) return(ibuf);
add = (ibuf->x - 0.001) / newx; add = (ibuf->x - 0.001) / newx;
@@ -331,22 +470,39 @@ static struct ImBuf *scaledownx(struct ImBuf *ibuf, int newx)
rect = (uchar *) ibuf->rect; rect = (uchar *) ibuf->rect;
rect += i; rect += i;
newrect = _newrect + i; newrect = _newrect + i;
if (do_float) {
rectf = ibuf->rect_float;
rectf += i;
newrectf = _newrectf + i;
}
for (y = ibuf->y; y>0 ; y--){ for (y = ibuf->y; y>0 ; y--){
val = sample = 0.0; val = sample = valf = 0.0;
for (x = newx ; x>0 ; x--){ for (x = newx ; x>0 ; x--){
nval = - val * sample; nval = - val * sample;
if (do_float) nvalf = - valf * sample;
sample += add; sample += add;
while (sample >= 1.0){ while (sample >= 1.0){
sample -= 1.0; sample -= 1.0;
nval += *rect; nval += *rect;
rect += 4; rect += 4;
if (do_float) {
nvalf += *rectf;
rectf += 4;
}
} }
val = *rect; val = *rect;
rect += 4; rect += 4;
nval += sample * val; nval += sample * val;
if (do_float) {
valf = *rectf;
rectf += 4;
nvalf += sample * valf;
*newrectf = (nvalf/add) + 0.5;
newrectf += 4;
}
sample -= 1.0; sample -= 1.0;
*newrect = (nval/add) + 0.5; *newrect = (nval/add) + 0.5;
newrect += 4; newrect += 4;
@@ -357,6 +513,13 @@ static struct ImBuf *scaledownx(struct ImBuf *ibuf, int newx)
imb_freerectImBuf(ibuf); imb_freerectImBuf(ibuf);
ibuf->mall |= IB_rect; ibuf->mall |= IB_rect;
ibuf->rect = (unsigned int *) _newrect; ibuf->rect = (unsigned int *) _newrect;
if (do_float) {
imb_freerectfloatImBuf(ibuf);
ibuf->mall |= IB_rectfloat;
ibuf->rect_float = _newrectf;
}
ibuf->x = newx; ibuf->x = newx;
return(ibuf); return(ibuf);
} }
@@ -365,14 +528,24 @@ static struct ImBuf *scaledownx(struct ImBuf *ibuf, int newx)
static struct ImBuf *scaledowny(struct ImBuf *ibuf, int newy) static struct ImBuf *scaledowny(struct ImBuf *ibuf, int newy)
{ {
uchar *rect, *_newrect, *newrect; uchar *rect, *_newrect, *newrect;
float sample,add,val,nval; float *rectf, *_newrectf, *newrectf;
int x,y,i,skipx; float sample, add, val, nval, valf, nvalf;
int x, y, i, skipx, do_float = 0;
if (ibuf == 0) return(0); rectf= NULL; _newrectf = NULL; newrectf = NULL;
if (ibuf->rect == 0) return(ibuf); nval = 0; nvalf = 0;
_newrect = (uchar *) malloc(newy * ibuf->x * sizeof(int)); if (ibuf==NULL) return(0);
if (_newrect == 0) return(ibuf); 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; add = (ibuf->y - 0.001) / newy;
skipx = 4 * ibuf->x; 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){ for (x = skipx - 4; x>=0 ; x-= 4){
rect = ((uchar *) ibuf->rect) + i + x; rect = ((uchar *) ibuf->rect) + i + x;
newrect = _newrect + i + x; newrect = _newrect + i + x;
if (do_float) {
rectf = ((float *) ibuf->rect_float) + i + x;
newrectf = _newrectf + i + x;
}
val = sample = 0.0; val = sample = 0.0;
for (y = newy ; y>0 ; y--){ for (y = newy ; y>0 ; y--){
nval = - val * sample; nval = - val * sample;
if (do_float) nvalf = - val * sample;
sample += add; sample += add;
while (sample >= 1.0){ while (sample >= 1.0){
sample -= 1.0; sample -= 1.0;
nval += *rect; nval += *rect;
rect += skipx; rect += skipx;
if (do_float) {
nvalf += *rectf;
rectf += skipx;
}
} }
val = *rect; val = *rect;
rect += skipx; rect += skipx;
nval += sample * val; nval += sample * val;
sample -= 1.0;
*newrect = (nval/add) + 0.5; *newrect = (nval/add) + 0.5;
newrect += skipx; 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); imb_freerectImBuf(ibuf);
ibuf->mall |= IB_rect; ibuf->mall |= IB_rect;
ibuf->rect = (unsigned int *) _newrect; ibuf->rect = (unsigned int *) _newrect;
if (do_float) {
imb_freerectfloatImBuf(ibuf);
ibuf->mall |= IB_rectfloat;
ibuf->rect_float = (float *) _newrectf;
}
ibuf->y = newy; ibuf->y = newy;
return(ibuf); return(ibuf);
} }
@@ -414,23 +610,39 @@ static struct ImBuf *scaledowny(struct ImBuf *ibuf, int newy)
static struct ImBuf *scaleupx(struct ImBuf *ibuf, int newx) static struct ImBuf *scaleupx(struct ImBuf *ibuf, int newx)
{ {
uchar *rect,*_newrect,*newrect; uchar *rect,*_newrect,*newrect;
float *rectf,*_newrectf,*newrectf;
float sample,add; float sample,add;
float val_a,nval_a,diff_a; float val_a,nval_a,diff_a;
float val_b,nval_b,diff_b; float val_b,nval_b,diff_b;
float val_g,nval_g,diff_g; float val_g,nval_g,diff_g;
float val_r,nval_r,diff_r; float val_r,nval_r,diff_r;
int x,y; 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;
if (ibuf == 0) return(0); val_af = nval_af = diff_af = val_bf = nval_bf = diff_bf = 0;
if (ibuf->rect == 0) return(ibuf); 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); add = (ibuf->x - 1.001) / (newx - 1.0);
rect = (uchar *) ibuf->rect; rect = (uchar *) ibuf->rect;
rectf = (float *) ibuf->rect_float;
newrect = _newrect; newrect = _newrect;
newrectf = _newrectf = NULL;
for (y = ibuf->y; y>0 ; y--){ for (y = ibuf->y; y>0 ; y--){
@@ -456,9 +668,34 @@ static struct ImBuf *scaleupx(struct ImBuf *ibuf, int newx)
val_r += 0.5; val_r += 0.5;
rect += 8; 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--){ for (x = newx ; x>0 ; x--){
if (sample >= 1.0){ if (sample >= 1.0){
sample -= 1.0; sample -= 1.0;
val_a = nval_a ; val_a = nval_a ;
nval_a = rect[0] ; nval_a = rect[0] ;
diff_a = nval_a - val_a ; 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 ; diff_r = nval_r - val_r ;
val_r += 0.5; val_r += 0.5;
rect += 4; 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[0] = val_a + sample * diff_a;
newrect[1] = val_b + sample * diff_b; newrect[1] = val_b + sample * diff_b;
newrect[2] = val_g + sample * diff_g; newrect[2] = val_g + sample * diff_g;
newrect[3] = val_r + sample * diff_r; newrect[3] = val_r + sample * diff_r;
newrect += 4; 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; sample += add;
} }
} }
@@ -492,6 +759,13 @@ static struct ImBuf *scaleupx(struct ImBuf *ibuf, int newx)
imb_freerectImBuf(ibuf); imb_freerectImBuf(ibuf);
ibuf->mall |= IB_rect; ibuf->mall |= IB_rect;
ibuf->rect = (unsigned int *) _newrect; ibuf->rect = (unsigned int *) _newrect;
if (do_float) {
imb_freerectfloatImBuf(ibuf);
ibuf->mall |= IB_rectfloat;
ibuf->rect_float = (float *) _newrectf;
}
ibuf->x = newx; ibuf->x = newx;
return(ibuf); return(ibuf);
} }
@@ -500,14 +774,21 @@ static struct ImBuf *scaleupx(struct ImBuf *ibuf, int newx)
static struct ImBuf *scaleupy(struct ImBuf *ibuf, int newy) static struct ImBuf *scaleupy(struct ImBuf *ibuf, int newy)
{ {
uchar *rect,*_newrect,*newrect; uchar *rect,*_newrect,*newrect;
float sample,add,val,nval,diff; float *rectf = NULL, *newrectf = NULL, *_newrectf = NULL;
int x,y,i,skipx; 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==NULL) return(0);
if (ibuf->rect == 0) return(ibuf); if (ibuf->rect==NULL) return(ibuf);
_newrect = (uchar *)malloc(newy * ibuf->x * sizeof(int)); _newrect = MEM_mallocN(newy * ibuf->x * sizeof(int), "scaleupy");
if (_newrect == 0) return(ibuf); 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); add = (ibuf->y - 1.001) / (newy - 1.0);
skipx = 4 * ibuf->x; skipx = 4 * ibuf->x;
@@ -515,10 +796,23 @@ static struct ImBuf *scaleupy(struct ImBuf *ibuf, int newy)
/* all four components, rgba/abgr */ /* all four components, rgba/abgr */
for(i=3 ; i>=0 ; i--){ for(i=3 ; i>=0 ; i--){
for (x = skipx - 4; x >= 0 ; x -= 4){ for (x = skipx - 4; x >= 0 ; x -= 4){
rect = (uchar *) ibuf->rect; rect = (uchar *) ibuf->rect;
rect += i + x; rect += i + x;
newrect = _newrect + 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; sample = 0;
val = *rect ; val = *rect ;
rect += skipx; rect += skipx;
@@ -535,9 +829,22 @@ static struct ImBuf *scaleupy(struct ImBuf *ibuf, int newy)
rect += skipx; rect += skipx;
diff = nval - val; diff = nval - val;
val += 0.5; val += 0.5;
if (do_float) {
valf = nvalf;
nvalf = *rectf;
rectf += skipx;
difff = nvalf - valf;
valf += 0.5;
}
} }
*newrect = val + sample * diff; *newrect = val + sample * diff;
newrect += skipx; newrect += skipx;
if (do_float) {
*newrectf = valf + sample * difff;
newrectf += skipx;
}
sample += add; sample += add;
} }
} }
@@ -546,10 +853,18 @@ static struct ImBuf *scaleupy(struct ImBuf *ibuf, int newy)
imb_freerectImBuf(ibuf); imb_freerectImBuf(ibuf);
ibuf->mall |= IB_rect; ibuf->mall |= IB_rect;
ibuf->rect = (unsigned int *) _newrect; ibuf->rect = (unsigned int *) _newrect;
if(do_float) {
imb_freerectfloatImBuf(ibuf);
ibuf->mall |= IB_rectfloat;
ibuf->rect_float = _newrectf;
}
ibuf->y = newy; ibuf->y = newy;
return(ibuf); return(ibuf);
} }
/* no float buf needed here! */
static void scalefast_Z_ImBuf(ImBuf *ibuf, short newx, short newy) static void scalefast_Z_ImBuf(ImBuf *ibuf, short newx, short newy)
{ {
unsigned int *rect, *_newrect, *newrect; unsigned int *rect, *_newrect, *newrect;
@@ -557,8 +872,8 @@ static void scalefast_Z_ImBuf(ImBuf *ibuf, short newx, short newy)
int ofsx, ofsy, stepx, stepy; int ofsx, ofsy, stepx, stepy;
if (ibuf->zbuf) { if (ibuf->zbuf) {
_newrect = malloc(newx * newy * sizeof(int)); _newrect = MEM_mallocN(newx * newy * sizeof(int), "z rect");
if (_newrect == 0) return; if (_newrect==NULL) return;
stepx = (65536.0 * (ibuf->x - 1.0) / (newx - 1.0)) + 0.5; stepx = (65536.0 * (ibuf->x - 1.0) / (newx - 1.0)) + 0.5;
stepy = (65536.0 * (ibuf->y - 1.0) / (newy - 1.0)) + 0.5; stepy = (65536.0 * (ibuf->y - 1.0) / (newy - 1.0)) + 0.5;
@@ -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) struct ImBuf *IMB_scaleImBuf(struct ImBuf * ibuf, short newx, short newy)
{ {
if (ibuf == 0) return (0); if (ibuf==NULL) return (0);
if (ibuf->rect == 0) return (ibuf); if (ibuf->rect==NULL) return (ibuf);
// scaleup / scaledown functions below change ibuf->x and ibuf->y // scaleup / scaledown functions below change ibuf->x and ibuf->y
// so we first scale the Z-buffer (if any) // 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) struct ImBuf *IMB_scalefastImBuf(struct ImBuf *ibuf, short newx, short newy)
{ {
unsigned int *rect,*_newrect,*newrect; unsigned int *rect,*_newrect,*newrect;
int x,y; float *rectf,*_newrectf,*newrectf;
int x,y, do_float=0;
int ofsx,ofsy,stepx,stepy; int ofsx,ofsy,stepx,stepy;
if (ibuf == 0) return(0); rectf = NULL; _newrectf = NULL; newrectf = NULL;
if (ibuf->rect == 0) return(ibuf);
if (ibuf==NULL) return(0);
if (ibuf->rect==NULL) return(ibuf);
if (ibuf->rect_float) do_float = 1;
if (newx == ibuf->x && newy == ibuf->y) return(ibuf); if (newx == ibuf->x && newy == ibuf->y) return(ibuf);
_newrect = malloc(newx * newy * sizeof(int)); _newrect = MEM_mallocN(newx * newy * sizeof(int), "scalefastimbuf");
if (_newrect == 0) return(ibuf); if (_newrect==NULL) return(ibuf);
newrect = _newrect; 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; stepx = (65536.0 * (ibuf->x - 1.0) / (newx - 1.0)) + 0.5;
stepy = (65536.0 * (ibuf->y - 1.0) / (newy - 1.0)) + 0.5; stepy = (65536.0 * (ibuf->y - 1.0) / (newy - 1.0)) + 0.5;
ofsy = 32768; ofsy = 32768;
@@ -623,10 +948,16 @@ struct ImBuf *IMB_scalefastImBuf(struct ImBuf *ibuf, short newx, short newy)
for (y = newy; y > 0 ; y--){ for (y = newy; y > 0 ; y--){
rect = ibuf->rect; rect = ibuf->rect;
rect += (ofsy >> 16) * ibuf->x; rect += (ofsy >> 16) * ibuf->x;
if (do_float) {
rectf = ibuf->rect_float;
rectf += (ofsy >> 16) * ibuf->x;
}
ofsy += stepy; ofsy += stepy;
ofsx = 32768; ofsx = 32768;
for (x = newx ; x>0 ; x--){ for (x = newx ; x>0 ; x--){
*newrect++ = rect[ofsx >> 16]; *newrect++ = rect[ofsx >> 16];
if (do_float) *newrectf++ = rectf[ofsx >> 16];
ofsx += stepx; ofsx += stepx;
} }
} }
@@ -635,6 +966,12 @@ struct ImBuf *IMB_scalefastImBuf(struct ImBuf *ibuf, short newx, short newy)
ibuf->mall |= IB_rect; ibuf->mall |= IB_rect;
ibuf->rect = _newrect; ibuf->rect = _newrect;
if (do_float) {
imb_freerectfloatImBuf(ibuf);
ibuf->mall |= IB_rectfloat;
ibuf->rect_float = _newrectf;
}
scalefast_Z_ImBuf(ibuf, newx, newy); scalefast_Z_ImBuf(ibuf, newx, newy);
ibuf->x = newx; ibuf->x = newx;
@@ -646,22 +983,25 @@ 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) ) static struct ImBuf *generic_fieldscale(struct ImBuf *ibuf, short newx, short newy, struct ImBuf *(*scalefunc)(ImBuf *, short, short) )
{ {
struct ImBuf *sbuf1, *sbuf2; struct ImBuf *sbuf1, *sbuf2;
/* extern void rectcpy(); */
sbuf1 = 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, IB_rect, 0); sbuf2 = IMB_allocImBuf(ibuf->x, ibuf->y / 2, ibuf->depth, ibuf->flags, 0);
ibuf->x *= 2; ibuf->x *= 2;
/* more args needed, 0 assumed... (nzc) */ /* more args needed, 0 assumed... (nzc) */
/* rectop(sbuf1, ibuf, 0, 0, 0, 0, 32767, 32767, rectcpy); */ IMB_rectcpy(sbuf1, ibuf, 0, 0, 0, 0, ibuf->x, ibuf->y);
/* rectop(sbuf2, ibuf, 0, 0, sbuf2->x, 0, 32767, 32767, rectcpy); */ IMB_rectcpy(sbuf2, ibuf, 0, 0, sbuf2->x, 0, ibuf->x, ibuf->y);
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_freerectImBuf(ibuf); imb_freerectImBuf(ibuf);
imb_freerectfloatImBuf(ibuf);
ibuf->x = newx; ibuf->x = newx;
ibuf->y = newy; ibuf->y = newy;
imb_addrectImBuf(ibuf); imb_addrectImBuf(ibuf);
if(ibuf->flags & IB_rectfloat)
imb_addrectfloatImBuf(ibuf);
scalefunc(sbuf1, newx, newy / 2); scalefunc(sbuf1, newx, newy / 2);
scalefunc(sbuf2, newx, newy / 2); scalefunc(sbuf2, newx, newy / 2);
@@ -669,10 +1009,8 @@ static struct ImBuf *generic_fieldscale(struct ImBuf *ibuf, short newx, short ne
ibuf->x *= 2; ibuf->x *= 2;
/* more args needed, 0 assumed... (nzc) */ /* more args needed, 0 assumed... (nzc) */
/* rectop(ibuf, sbuf1, 0, 0, 0, 0, 32767, 32767, rectcpy); */ IMB_rectcpy(ibuf, sbuf1, 0, 0, 0, 0, sbuf1->x, sbuf1->y);
/* rectop(ibuf, sbuf2, sbuf2->x, 0, 0, 0, 32767, 32767, rectcpy); */ IMB_rectcpy(ibuf, sbuf2, sbuf2->x, 0, 0, 0, sbuf2->x, sbuf2->y);
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);
ibuf->x /= 2; 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, struct ImBuf *IMB_scalefastfieldImBuf(struct ImBuf *ibuf, short newx, short newy)
short newx,
short newy)
{ {
return(generic_fieldscale(ibuf, newx, newy, IMB_scalefastImBuf)); 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)); return(generic_fieldscale(ibuf, newx, newy, IMB_scaleImBuf));
} }

View File

@@ -519,7 +519,7 @@ struct ImBuf *imb_loadtarga(unsigned char *mem, int flags)
if (checktarga(&tga,mem) == 0) return(0); if (checktarga(&tga,mem) == 0) return(0);
if (flags & IB_test) ibuf = IMB_allocImBuf(tga.xsize,tga.ysize,tga.pixsize, 0, 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); else ibuf = IMB_allocImBuf(tga.xsize,tga.ysize,(tga.pixsize + 0x7) & ~0x7, IB_rect, 0);
if (ibuf == 0) return(0); if (ibuf == 0) return(0);
ibuf->ftype = TGA; ibuf->ftype = TGA;
@@ -629,7 +629,7 @@ struct ImBuf *imb_loadtarga(unsigned char *mem, int flags)
if (ibuf) { if (ibuf) {
if (ibuf->rect && (flags & IB_cmap)==0) 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); return(ibuf);

View File

@@ -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 */ /* close the client layer interface to the in-memory file */
libtiff_TIFFClose(image); 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 successfully */
return (ibuf); return (ibuf);

View File

@@ -50,6 +50,10 @@
#include "IMB_anim.h" #include "IMB_anim.h"
#ifdef WITH_OPENEXR
#include "openexr/openexr_api.h"
#endif
#ifdef WITH_QUICKTIME #ifdef WITH_QUICKTIME
#include "quicktime_import.h" #include "quicktime_import.h"
#endif #endif
@@ -97,7 +101,9 @@ static int IMB_ispic_name(char *name)
} }
if (imb_is_a_png(buf)) return(PNG); if (imb_is_a_png(buf)) return(PNG);
if (imb_is_a_targa(buf)) return(TGA); 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); if (imb_is_a_tiff(buf)) return(TIF);
/* radhdr: check if hdr format */ /* radhdr: check if hdr format */

View File

@@ -57,12 +57,15 @@
#include "IMB_bmp.h" #include "IMB_bmp.h"
#include "IMB_tiff.h" #include "IMB_tiff.h"
#include "IMB_radiance_hdr.h" #include "IMB_radiance_hdr.h"
#ifdef WITH_OPENEXR
#include "openexr/openexr_api.h"
#endif
#include "IMB_iff.h" #include "IMB_iff.h"
#include "IMB_bitplanes.h" #include "IMB_bitplanes.h"
#include "IMB_divers.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; short ok=TRUE,delpl=FALSE;
int file = -1; int file = -1;
@@ -72,28 +75,33 @@ short IMB_saveiff(struct ImBuf *ibuf,char *naam,int flags)
/* Put formats that take a filename here */ /* Put formats that take a filename here */
if (IS_jpg(ibuf)) { if (IS_jpg(ibuf)) {
return imb_savejpeg(ibuf, naam, flags); return imb_savejpeg(ibuf, name, flags);
} }
if (IS_radhdr(ibuf)) { if (IS_radhdr(ibuf)) {
return imb_savehdr(ibuf, naam, flags); return imb_savehdr(ibuf, name, flags);
} }
if (IS_png(ibuf)) { if (IS_png(ibuf)) {
return imb_savepng(ibuf,naam,flags); return imb_savepng(ibuf, name, flags);
} }
if (IS_bmp(ibuf)) { if (IS_bmp(ibuf)) {
return imb_savebmp(ibuf,naam,flags); return imb_savebmp(ibuf, name, flags);
} }
if (IS_tga(ibuf)) { if (IS_tga(ibuf)) {
return imb_savetarga(ibuf,naam,flags); return imb_savetarga(ibuf, name, flags);
} }
if (IS_iris(ibuf)) { if (IS_iris(ibuf)) {
return imb_saveiris(ibuf,naam,flags); return imb_saveiris(ibuf, name, flags);
} }
if (G.have_libtiff && IS_tiff(ibuf)) { 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 (file < 0) return (FALSE);
if (flags & IB_rect){ 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 */ /* Put formats that take a filehandle here */
ok = imb_start_iff(ibuf,file); ok = imb_start_iff(ibuf,file);
if (IS_amiga(ibuf)){ if (IS_amiga(ibuf)){
IMB_flipy(ibuf); IMB_flipy(ibuf);

View File

@@ -320,6 +320,7 @@ void curvemap_buttons(struct uiBlock *block, struct CurveMapping *cumap, char la
#define B_SET_EDGE 1643 #define B_SET_EDGE 1643
#define B_SET_ZBLUR 1644 #define B_SET_ZBLUR 1644
#define B_SET_OPENEXR 1645
/* *********************** */ /* *********************** */
#define B_ARMATUREBUTS 1800 #define B_ARMATUREBUTS 1800
@@ -652,14 +653,9 @@ enum {
#define B_MODIFIER_RECALC 3501 #define B_MODIFIER_RECALC 3501
#define B_MODIFIER_REDRAW 3502 #define B_MODIFIER_REDRAW 3502
/* *********************** */
/* *********************** */ /* *********************** */
/* BUTTON BUT: > 4000 */ /* BUTTON BUT: > 4000 */
/* BUTTON 4001-4032: layers */ /* BUTTON 4001-4032: layers */
#endif #endif

View File

@@ -405,6 +405,7 @@ typedef struct Scene {
#define R_BMP 20 #define R_BMP 20
#define R_RADHDR 21 #define R_RADHDR 21
#define R_TIFF 22 #define R_TIFF 22
#define R_OPENEXR 23
/* **************** SCENE ********************* */ /* **************** SCENE ********************* */
#define RAD_PHASE_PATCHES 1 #define RAD_PHASE_PATCHES 1

View File

@@ -37,10 +37,6 @@
#include <math.h> #include <math.h>
#include <string.h> #include <string.h>
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
/* external modules: */ /* external modules: */
#include "MEM_guardedalloc.h" #include "MEM_guardedalloc.h"
#include "BLI_arithb.h" #include "BLI_arithb.h"
@@ -168,18 +164,18 @@ static void envmap_split_ima(EnvMap *env)
ima->ok= 1; ima->ok= 1;
env->cube[part]= ima; env->cube[part]= ima;
} }
IMB_rectop(env->cube[0]->ibuf, env->ima->ibuf, IMB_rectcpy(env->cube[0]->ibuf, env->ima->ibuf,
0, 0, 0, 0, dx, dx, IMB_rectcpy, 0); 0, 0, 0, 0, dx, dx);
IMB_rectop(env->cube[1]->ibuf, env->ima->ibuf, IMB_rectcpy(env->cube[1]->ibuf, env->ima->ibuf,
0, 0, dx, 0, dx, dx, IMB_rectcpy, 0); 0, 0, dx, 0, dx, dx);
IMB_rectop(env->cube[2]->ibuf, env->ima->ibuf, IMB_rectcpy(env->cube[2]->ibuf, env->ima->ibuf,
0, 0, 2*dx, 0, dx, dx, IMB_rectcpy, 0); 0, 0, 2*dx, 0, dx, dx);
IMB_rectop(env->cube[3]->ibuf, env->ima->ibuf, IMB_rectcpy(env->cube[3]->ibuf, env->ima->ibuf,
0, 0, 0, dx, dx, dx, IMB_rectcpy, 0); 0, 0, 0, dx, dx, dx);
IMB_rectop(env->cube[4]->ibuf, env->ima->ibuf, IMB_rectcpy(env->cube[4]->ibuf, env->ima->ibuf,
0, 0, dx, dx, dx, dx, IMB_rectcpy, 0); 0, 0, dx, dx, dx, dx);
IMB_rectop(env->cube[5]->ibuf, env->ima->ibuf, IMB_rectcpy(env->cube[5]->ibuf, env->ima->ibuf,
0, 0, 2*dx, dx, dx, dx, IMB_rectcpy, 0); 0, 0, 2*dx, dx, dx, dx);
env->ok= 2; env->ok= 2;
} }
} }
@@ -414,9 +410,12 @@ static void render_envmap(EnvMap *env)
MTC_Mat4Invert(oldviewinv, R.viewmat); MTC_Mat4Invert(oldviewinv, R.viewmat);
/* do first, envmap_renderdata copies entire R struct */ /* do first, envmap_renderdata copies entire R struct */
if(R.rectz) MEM_freeN(R.rectz); R.rectz= NULL; if(R.rectz) MEM_freeN(R.rectz);
if(R.rectot) MEM_freeN(R.rectot); R.rectot= NULL; if(R.rectot) MEM_freeN(R.rectot);
if(R.rectftot) MEM_freeN(R.rectftot); R.rectftot= NULL; if(R.rectftot) MEM_freeN(R.rectftot);
R.rectftot= NULL;
R.rectz= NULL;
R.rectot= NULL;
/* setup necessary globals */ /* setup necessary globals */
envmap_renderdata(env); envmap_renderdata(env);
@@ -478,9 +477,12 @@ static void render_envmap(EnvMap *env)
} }
if(R.rectz) MEM_freeN(R.rectz); R.rectz= NULL; if(R.rectz) MEM_freeN(R.rectz);
if(R.rectot) MEM_freeN(R.rectot); R.rectot= NULL; if(R.rectot) MEM_freeN(R.rectot);
if(R.rectftot) MEM_freeN(R.rectftot); R.rectftot= NULL; if(R.rectftot) MEM_freeN(R.rectftot);
R.rectz= NULL;
R.rectot= NULL;
R.rectftot= NULL;
if(RE_local_test_break()) RE_free_envmapdata(env); if(RE_local_test_break()) RE_free_envmapdata(env);
else { else {

View File

@@ -38,10 +38,6 @@
#include <string.h> #include <string.h>
#include <stdio.h> #include <stdio.h>
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
#include "blendef.h" #include "blendef.h"
#include "MEM_guardedalloc.h" #include "MEM_guardedalloc.h"
@@ -897,6 +893,7 @@ static void yafrayRender(void)
/* float rgba buf */ /* float rgba buf */
if (R.rectftot) MEM_freeN(R.rectftot); if (R.rectftot) MEM_freeN(R.rectftot);
if (R.r.mode & R_FBUF) R.rectftot= MEM_callocN(4*sizeof(float)*R.rectx*R.recty, "rectftot"); if (R.r.mode & R_FBUF) R.rectftot= MEM_callocN(4*sizeof(float)*R.rectx*R.recty, "rectftot");
else R.rectftot = NULL;
// switch must be done before prepareScene() // switch must be done before prepareScene()
if (!R.r.YFexportxml) if (!R.r.YFexportxml)
@@ -1054,6 +1051,7 @@ static void mainRenderLoop(void) /* here the PART and FIELD loops */
if(R.rectftot) MEM_freeN(R.rectftot); if(R.rectftot) MEM_freeN(R.rectftot);
if(R.r.mode & R_FBUF) R.rectftot= MEM_callocN(4*sizeof(float)*R.rectx*R.recty, "rectftot"); if(R.r.mode & R_FBUF) R.rectftot= MEM_callocN(4*sizeof(float)*R.rectx*R.recty, "rectftot");
else R.rectftot = NULL;
if(R.r.mode & R_MBLUR) { if(R.r.mode & R_MBLUR) {
RE_local_printrenderinfo(0.0, R.osa - blur); RE_local_printrenderinfo(0.0, R.osa - blur);

View File

@@ -112,6 +112,10 @@ ifeq ($(WITH_QUICKTIME),true)
CPPFLAGS += -DWITH_QUICKTIME CPPFLAGS += -DWITH_QUICKTIME
endif endif
ifeq ($(WITH_OPENEXR),true)
CPPFLAGS += -DWITH_OPENEXR
endif
ifeq ($(INTERNATIONAL), true) ifeq ($(INTERNATIONAL), true)
CPPFLAGS += -DINTERNATIONAL CPPFLAGS += -DINTERNATIONAL
endif endif

View File

@@ -979,14 +979,19 @@ static char *imagetype_pup(void)
"HamX", R_HAMX, "HamX", R_HAMX,
"Iris", R_IRIS, "Iris", R_IRIS,
"Iris + Zbuffer", R_IRIZ, "Iris + Zbuffer", R_IRIZ,
"Radiance HDR", R_RADHDR, "Radiance HDR", R_RADHDR
#ifdef __sgi #ifdef __sgi
"Movie", R_MOVIE, ,"Movie", R_MOVIE
#endif #endif
"Ftype", R_FTYPE
); );
} }
#ifdef WITH_OPENEXR
strcpy(formatstring, "|%s %%x%d");
sprintf(appendstring, formatstring, "OpenEXR", R_OPENEXR);
strcat(string, appendstring);
#endif
if (G.have_libtiff) { if (G.have_libtiff) {
strcpy(formatstring, "|%s %%x%d"); strcpy(formatstring, "|%s %%x%d");
sprintf(appendstring, formatstring, "TIFF", R_TIFF); sprintf(appendstring, formatstring, "TIFF", R_TIFF);
@@ -1252,7 +1257,14 @@ static void render_panel_format(void)
#endif #endif
uiDefBut(block, BUT,B_SELECTCODEC, "Set codec", 892,yofs,112,20, 0, 0, 0, 0, 0, "Set codec settings for AVI"); uiDefBut(block, BUT,B_SELECTCODEC, "Set codec", 892,yofs,112,20, 0, 0, 0, 0, 0, "Set codec settings for AVI");
} }
#ifdef WITH_OPENEXR
} else if (G.scene->r.imtype == R_OPENEXR ) {
if (G.scene->r.quality > 5) G.scene->r.quality = 0;
uiDefButS(block, MENU,B_SET_OPENEXR, "Codec %t|None %x0|Pxr24 (lossy) %x1|ZIP (lossless) %x2|PIZ (lossless) %x3|RLE (lossless) %x4", 892,yofs,112,20, &G.scene->r.quality, 0, 0, 0, 0, "Set codec settings for OpenEXR");
#endif
} else { } else {
if(G.scene->r.quality < 5) G.scene->r.quality = 90; // temp
uiDefButS(block, NUM,B_DIFF, "Quality:", 892,yofs,112,20, &G.scene->r.quality, 10.0, 100.0, 0, 0, "Quality setting for JPEG images, AVI Jpeg and SGI movies"); uiDefButS(block, NUM,B_DIFF, "Quality:", 892,yofs,112,20, &G.scene->r.quality, 10.0, 100.0, 0, 0, "Quality setting for JPEG images, AVI Jpeg and SGI movies");
} }
uiDefButS(block, NUM,B_FRAMEMAP,"Frs/sec:", 1006,yofs,113,20, &G.scene->r.frs_sec, 1.0, 120.0, 100.0, 0, "Frames per second"); uiDefButS(block, NUM,B_FRAMEMAP,"Frs/sec:", 1006,yofs,113,20, &G.scene->r.frs_sec, 1.0, 120.0, 100.0, 0, "Frames per second");

View File

@@ -34,10 +34,6 @@
#include <math.h> #include <math.h>
#include <string.h> #include <string.h>
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
#include "MEM_guardedalloc.h" #include "MEM_guardedalloc.h"
#include "BLI_blenlib.h" #include "BLI_blenlib.h"
@@ -1023,7 +1019,8 @@ void face_borderselect()
Mesh *me; Mesh *me;
TFace *tface; TFace *tface;
rcti rect; rcti rect;
unsigned int *rectm, *rt; struct ImBuf *ibuf;
unsigned int *rt;
int a, sx, sy, index, val; int a, sx, sy, index, val;
char *selar; char *selar;
@@ -1046,9 +1043,10 @@ void face_borderselect()
sy= (rect.ymax-rect.ymin+1); sy= (rect.ymax-rect.ymin+1);
if(sx*sy<=0) return; if(sx*sy<=0) return;
rt=rectm= MEM_mallocN(sizeof(int)*sx*sy, "selrect"); ibuf = IMB_allocImBuf(sx,sy,32,0,0);
glReadPixels(rect.xmin+curarea->winrct.xmin, rect.ymin+curarea->winrct.ymin, sx, sy, GL_RGBA, GL_UNSIGNED_BYTE, rectm); rt = ibuf->rect;
if(G.order==B_ENDIAN) IMB_convert_rgba_to_abgr(sx*sy, rectm); glReadPixels(rect.xmin+curarea->winrct.xmin, rect.ymin+curarea->winrct.ymin, sx, sy, GL_RGBA, GL_UNSIGNED_BYTE, ibuf->rect);
if(G.order==B_ENDIAN) IMB_convert_rgba_to_abgr(ibuf);
a= sx*sy; a= sx*sy;
while(a--) { while(a--) {
@@ -1070,7 +1068,7 @@ void face_borderselect()
} }
} }
MEM_freeN(rectm); IMB_freeImBuf(ibuf);
MEM_freeN(selar); MEM_freeN(selar);
BIF_undo_push("Border Select UV face"); BIF_undo_push("Border Select UV face");

View File

@@ -40,10 +40,6 @@ editmesh_mods.c, UI level access, no geometry changes
#include <string.h> #include <string.h>
#include <math.h> #include <math.h>
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
#include "MEM_guardedalloc.h" #include "MEM_guardedalloc.h"
#include "MTC_matrixops.h" #include "MTC_matrixops.h"
@@ -92,6 +88,7 @@ editmesh_mods.c, UI level access, no geometry changes
#include "BSE_edit.h" #include "BSE_edit.h"
#include "BSE_view.h" #include "BSE_view.h"
#include "IMB_imbuf_types.h"
#include "IMB_imbuf.h" #include "IMB_imbuf.h"
#include "mydevice.h" #include "mydevice.h"
@@ -155,11 +152,12 @@ static unsigned int sample_backbuf(int x, int y)
} }
/* reads full rect, converts indices */ /* reads full rect, converts indices */
static unsigned int *read_backbuf(short xmin, short ymin, short xmax, short ymax) struct ImBuf *read_backbuf(short xmin, short ymin, short xmax, short ymax)
{ {
unsigned int *dr, *buf; unsigned int *dr, *rd;
struct ImBuf *ibuf, *ibuf1;
int a; int a;
short xminc, yminc, xmaxc, ymaxc; short xminc, yminc, xmaxc, ymaxc, xs, ys;
/* clip */ /* clip */
if(xmin<0) xminc= 0; else xminc= xmin; if(xmin<0) xminc= 0; else xminc= xmin;
@@ -170,34 +168,30 @@ static unsigned int *read_backbuf(short xmin, short ymin, short xmax, short ymax
if(ymax>=curarea->winy) ymaxc= curarea->winy-1; else ymaxc= ymax; if(ymax>=curarea->winy) ymaxc= curarea->winy-1; else ymaxc= ymax;
if(yminc > ymaxc) return NULL; if(yminc > ymaxc) return NULL;
buf= MEM_mallocN( (xmaxc-xminc+1)*(ymaxc-yminc+1)*sizeof(int), "sample rect"); ibuf= IMB_allocImBuf((xmaxc-xminc+1),(ymaxc-yminc+1),32,IB_rect,0);
check_backbuf(); // actually not needed for apple check_backbuf(); // actually not needed for apple
#ifdef __APPLE__ #ifdef __APPLE__
glReadBuffer(GL_AUX0); glReadBuffer(GL_AUX0);
#endif #endif
glReadPixels(curarea->winrct.xmin+xminc, curarea->winrct.ymin+yminc, (xmaxc-xminc+1), (ymaxc-yminc+1), GL_RGBA, GL_UNSIGNED_BYTE, buf); glReadPixels(curarea->winrct.xmin+xminc, curarea->winrct.ymin+yminc, (xmaxc-xminc+1), (ymaxc-yminc+1), GL_RGBA, GL_UNSIGNED_BYTE, ibuf->rect);
glReadBuffer(GL_BACK); glReadBuffer(GL_BACK);
if(G.order==B_ENDIAN) IMB_convert_rgba_to_abgr((xmaxc-xminc+1)*(ymaxc-yminc+1), buf); if(G.order==B_ENDIAN) IMB_convert_rgba_to_abgr(ibuf);
a= (xmaxc-xminc+1)*(ymaxc-yminc+1); a= (xmaxc-xminc+1)*(ymaxc-yminc+1);
dr= buf; dr= ibuf->rect;
while(a--) { while(a--) {
if(*dr) *dr= framebuffer_to_index(*dr); if(*dr) *dr= framebuffer_to_index(*dr);
dr++; dr++;
} }
/* put clipped result back, if needed */ /* put clipped result back, if needed */
if(xminc==xmin && xmaxc==xmax && yminc==ymin && ymaxc==ymax) return buf; if(xminc==xmin && xmaxc==xmax && yminc==ymin && ymaxc==ymax) return ibuf;
else { ibuf1= IMB_allocImBuf( (xmax-xmin+1),(ymax-ymin+1),32,IB_rect,0);
unsigned int *buf1= MEM_callocN( (xmax-xmin+1)*(ymax-ymin+1)*sizeof(int), "sample rect2"); rd= ibuf->rect;
unsigned int *rd; dr= ibuf1->rect;
short xs, ys;
rd= buf;
dr= buf1;
for(ys= ymin; ys<=ymax; ys++) { for(ys= ymin; ys<=ymax; ys++) {
for(xs= xmin; xs<=xmax; xs++, dr++) { for(xs= xmin; xs<=xmax; xs++, dr++) {
@@ -207,18 +201,16 @@ static unsigned int *read_backbuf(short xmin, short ymin, short xmax, short ymax
} }
} }
} }
MEM_freeN(buf); IMB_freeImBuf(ibuf);
return buf1; return ibuf1;
}
return buf;
} }
/* smart function to sample a rect spiralling outside, nice for backbuf selection */ /* smart function to sample a rect spiralling outside, nice for backbuf selection */
static unsigned int sample_backbuf_rect(short mval[2], int size, unsigned int min, unsigned int max, short *dist) static unsigned int sample_backbuf_rect(short mval[2], int size, unsigned int min, unsigned int max, short *dist)
{ {
unsigned int *buf, *bufmin, *bufmax; struct ImBuf *buf;
unsigned int *bufmin, *bufmax, *tbuf;
int minx, miny; int minx, miny;
int a, b, rc, nr, amount, dirvec[4][2]; int a, b, rc, nr, amount, dirvec[4][2];
short distance=0; short distance=0;
@@ -229,8 +221,7 @@ static unsigned int sample_backbuf_rect(short mval[2], int size, unsigned int mi
minx = mval[0]-(amount+1); minx = mval[0]-(amount+1);
miny = mval[1]-(amount+1); miny = mval[1]-(amount+1);
buf = read_backbuf(minx, miny, minx+size-1, miny+size-1); buf = read_backbuf(minx, miny, minx+size-1, miny+size-1);
if (!buf) if (!buf) return 0;
return 0;
rc= 0; rc= 0;
@@ -239,23 +230,24 @@ static unsigned int sample_backbuf_rect(short mval[2], int size, unsigned int mi
dirvec[2][0]= -1; dirvec[2][1]= 0; dirvec[2][0]= -1; dirvec[2][1]= 0;
dirvec[3][0]= 0; dirvec[3][1]= size; dirvec[3][0]= 0; dirvec[3][1]= size;
bufmin= buf; bufmin = buf->rect;
bufmax= buf+ size*size; tbuf = buf->rect;
buf+= amount*size+ amount; bufmax = buf->rect + size*size;
tbuf+= amount*size+ amount;
for(nr=1; nr<=size; nr++) { for(nr=1; nr<=size; nr++) {
for(a=0; a<2; a++) { for(a=0; a<2; a++) {
for(b=0; b<nr; b++, distance++) { for(b=0; b<nr; b++, distance++) {
if (*buf && *buf>=min && *buf<max) { if (*tbuf && *tbuf>=min && *tbuf<max) {
*dist= (short) sqrt( (float)distance ); // XXX, this distance is wrong - zr *dist= (short) sqrt( (float)distance ); // XXX, this distance is wrong - zr
index = *buf - min+1; // messy yah, but indices start at 1 index = *tbuf - min+1; // messy yah, but indices start at 1
goto exit; goto exit;
} }
buf+= (dirvec[rc][0]+dirvec[rc][1]); tbuf+= (dirvec[rc][0]+dirvec[rc][1]);
if(buf<bufmin || buf>=bufmax) { if(tbuf<bufmin || tbuf>=bufmax) {
goto exit; goto exit;
} }
} }
@@ -265,7 +257,7 @@ static unsigned int sample_backbuf_rect(short mval[2], int size, unsigned int mi
} }
exit: exit:
MEM_freeN(bufmin); IMB_freeImBuf(buf);
return index; return index;
} }
@@ -322,15 +314,18 @@ static void draw_triangulated(short mcords[][2], short tot)
/* returns if all is OK */ /* returns if all is OK */
int EM_init_backbuf_border(short xmin, short ymin, short xmax, short ymax) int EM_init_backbuf_border(short xmin, short ymin, short xmax, short ymax)
{ {
unsigned int *buf, *dr; struct ImBuf *buf;
unsigned int *dr;
int a; int a;
if(G.obedit==NULL || G.vd->drawtype<OB_SOLID || (G.vd->flag & V3D_ZBUF_SELECT)==0) return 0; if(G.obedit==NULL || G.vd->drawtype<OB_SOLID || (G.vd->flag & V3D_ZBUF_SELECT)==0) return 0;
if(em_vertoffs==0) return 0; if(em_vertoffs==0) return 0;
dr= buf= read_backbuf(xmin, ymin, xmax, ymax); buf= read_backbuf(xmin, ymin, xmax, ymax);
if(buf==NULL) return 0; if(buf==NULL) return 0;
dr = buf->rect;
/* build selection lookup */ /* build selection lookup */
selbuf= MEM_callocN(em_vertoffs+1, "selbuf"); selbuf= MEM_callocN(em_vertoffs+1, "selbuf");
@@ -340,7 +335,7 @@ int EM_init_backbuf_border(short xmin, short ymin, short xmax, short ymax)
selbuf[*dr]= 1; selbuf[*dr]= 1;
dr++; dr++;
} }
MEM_freeN(buf); IMB_freeImBuf(buf);
return 1; return 1;
} }
@@ -366,7 +361,8 @@ void EM_free_backbuf(void)
*/ */
int EM_mask_init_backbuf_border(short mcords[][2], short tot, short xmin, short ymin, short xmax, short ymax) int EM_mask_init_backbuf_border(short mcords[][2], short tot, short xmin, short ymin, short xmax, short ymax)
{ {
unsigned int *buf, *bufmask, *dr, *drm; unsigned int *dr, *drm;
struct ImBuf *buf, *bufmask;
int a; int a;
/* method in use for face selecting too */ /* method in use for face selecting too */
@@ -378,9 +374,11 @@ int EM_mask_init_backbuf_border(short mcords[][2], short tot, short xmin, short
if(em_vertoffs==0) return 0; if(em_vertoffs==0) return 0;
dr= buf= read_backbuf(xmin, ymin, xmax, ymax); buf= read_backbuf(xmin, ymin, xmax, ymax);
if(buf==NULL) return 0; if(buf==NULL) return 0;
dr = buf->rect;
/* draw the mask */ /* draw the mask */
#ifdef __APPLE__ #ifdef __APPLE__
glDrawBuffer(GL_AUX0); glDrawBuffer(GL_AUX0);
@@ -403,7 +401,8 @@ int EM_mask_init_backbuf_border(short mcords[][2], short tot, short xmin, short
glDrawBuffer(GL_BACK); glDrawBuffer(GL_BACK);
/* grab mask */ /* grab mask */
drm= bufmask= read_backbuf(xmin, ymin, xmax, ymax); bufmask= read_backbuf(xmin, ymin, xmax, ymax);
drm = bufmask->rect;
if(bufmask==NULL) return 0; // only when mem alloc fails, go crash somewhere else! if(bufmask==NULL) return 0; // only when mem alloc fails, go crash somewhere else!
/* build selection lookup */ /* build selection lookup */
@@ -414,8 +413,8 @@ int EM_mask_init_backbuf_border(short mcords[][2], short tot, short xmin, short
if(*dr>0 && *dr<=em_vertoffs && *drm==0) selbuf[*dr]= 1; if(*dr>0 && *dr<=em_vertoffs && *drm==0) selbuf[*dr]= 1;
dr++; drm++; dr++; drm++;
} }
MEM_freeN(buf); IMB_freeImBuf(buf);
MEM_freeN(bufmask); IMB_freeImBuf(bufmask);
return 1; return 1;
} }
@@ -423,7 +422,8 @@ int EM_mask_init_backbuf_border(short mcords[][2], short tot, short xmin, short
/* circle shaped sample area */ /* circle shaped sample area */
int EM_init_backbuf_circle(short xs, short ys, short rads) int EM_init_backbuf_circle(short xs, short ys, short rads)
{ {
unsigned int *buf, *dr; struct ImBuf *buf;
unsigned int *dr;
short xmin, ymin, xmax, ymax, xc, yc; short xmin, ymin, xmax, ymax, xc, yc;
int radsq; int radsq;
@@ -437,9 +437,11 @@ int EM_init_backbuf_circle(short xs, short ys, short rads)
xmin= xs-rads; xmax= xs+rads; xmin= xs-rads; xmax= xs+rads;
ymin= ys-rads; ymax= ys+rads; ymin= ys-rads; ymax= ys+rads;
dr= buf= read_backbuf(xmin, ymin, xmax, ymax); buf= read_backbuf(xmin, ymin, xmax, ymax);
if(buf==NULL) return 0; if(buf==NULL) return 0;
dr = buf->rect;
/* build selection lookup */ /* build selection lookup */
selbuf= MEM_callocN(em_vertoffs+1, "selbuf"); selbuf= MEM_callocN(em_vertoffs+1, "selbuf");
radsq= rads*rads; radsq= rads*rads;
@@ -451,7 +453,7 @@ int EM_init_backbuf_circle(short xs, short ys, short rads)
} }
} }
MEM_freeN(buf); IMB_freeImBuf(buf);
return 1; return 1;
} }

View File

@@ -502,10 +502,13 @@ void test_flags_file(SpaceFile *sfile)
(BLI_testextensie(file->relname, ".tif") (BLI_testextensie(file->relname, ".tif")
|| BLI_testextensie(file->relname, ".tiff"))) { || BLI_testextensie(file->relname, ".tiff"))) {
file->flags |= IMAGEFILE; file->flags |= IMAGEFILE;
} else if (BLI_testextensie(file->relname, ".exr")) {
file->flags |= IMAGEFILE;
} else if (G.have_quicktime){ } else if (G.have_quicktime){
if( BLI_testextensie(file->relname, ".jpg") if( BLI_testextensie(file->relname, ".jpg")
|| BLI_testextensie(file->relname, ".jpeg") || BLI_testextensie(file->relname, ".jpeg")
|| BLI_testextensie(file->relname, ".hdr") || BLI_testextensie(file->relname, ".hdr")
|| BLI_testextensie(file->relname, ".exr")
|| BLI_testextensie(file->relname, ".tga") || BLI_testextensie(file->relname, ".tga")
|| BLI_testextensie(file->relname, ".rgb") || BLI_testextensie(file->relname, ".rgb")
|| BLI_testextensie(file->relname, ".bmp") || BLI_testextensie(file->relname, ".bmp")
@@ -533,6 +536,7 @@ void test_flags_file(SpaceFile *sfile)
} else { // no quicktime } else { // no quicktime
if(BLI_testextensie(file->relname, ".jpg") if(BLI_testextensie(file->relname, ".jpg")
|| BLI_testextensie(file->relname, ".hdr") || BLI_testextensie(file->relname, ".hdr")
|| BLI_testextensie(file->relname, ".exr")
|| BLI_testextensie(file->relname, ".tga") || BLI_testextensie(file->relname, ".tga")
|| BLI_testextensie(file->relname, ".rgb") || BLI_testextensie(file->relname, ".rgb")
|| BLI_testextensie(file->relname, ".bmp") || BLI_testextensie(file->relname, ".bmp")

View File

@@ -34,10 +34,6 @@
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
#ifndef WIN32 #ifndef WIN32
#include <unistd.h> #include <unistd.h>
#else #else
@@ -538,7 +534,7 @@ void get_next_image(SpaceImaSel *simasel)
/* the whole cmap system is wacko */ /* the whole cmap system is wacko */
if (G.order==B_ENDIAN) if (G.order==B_ENDIAN)
IMB_convert_rgba_to_abgr(ima->dw*ima->dh, ibuf->rect); IMB_convert_rgba_to_abgr(ibuf);
ibuf->mincol = 0; ibuf->mincol = 0;
ibuf->maxcol = 256; ibuf->maxcol = 256;
@@ -555,7 +551,7 @@ void get_next_image(SpaceImaSel *simasel)
longtochar(ima->pict_rect, ibuf->rect, size); longtochar(ima->pict_rect, ibuf->rect, size);
IMB_applycmap(ibuf); IMB_applycmap(ibuf);
IMB_convert_rgba_to_abgr(size, ibuf->rect); IMB_convert_rgba_to_abgr(ibuf);
if (ima->pict) IMB_freeImBuf(ima->pict); if (ima->pict) IMB_freeImBuf(ima->pict);
ima->pict = ibuf; ima->pict = ibuf;
@@ -797,7 +793,7 @@ void get_pib_file(SpaceImaSel *simasel)
ima->pict->cmap = simasel->cmap->cmap; ima->pict->cmap = simasel->cmap->cmap;
ima->pict->maxcol = 256; ima->pict->maxcol = 256;
IMB_applycmap(ima->pict); IMB_applycmap(ima->pict);
IMB_convert_rgba_to_abgr(size, ima->pict->rect); IMB_convert_rgba_to_abgr(ima->pict);
} }
ima->selected = 0; ima->selected = 0;
ima->selectable = 0; ima->selectable = 0;

View File

@@ -733,8 +733,11 @@ void BIF_icon_draw(float x, float y, int icon_id)
ui_rasterpos_safe(x, y, di->aspect); ui_rasterpos_safe(x, y, di->aspect);
if(di->w<1 || di->h<1) {
printf("what the heck!\n");
}
/* di->rect contains image in 'rendersize', we only scale if needed */ /* di->rect contains image in 'rendersize', we only scale if needed */
if(di->rw!=di->w && di->rh!=di->h) { else if(di->rw!=di->w && di->rh!=di->h) {
ImBuf *ima; ImBuf *ima;
/* first allocate imbuf for scaling and copy preview into it */ /* first allocate imbuf for scaling and copy preview into it */
ima = IMB_allocImBuf(di->rw, di->rh, 32, IB_rect, 0); ima = IMB_allocImBuf(di->rw, di->rh, 32, IB_rect, 0);

View File

@@ -87,6 +87,9 @@ void write_screendump(char *name)
else if(G.scene->r.imtype==R_PNG) ibuf->ftype= PNG; else if(G.scene->r.imtype==R_PNG) ibuf->ftype= PNG;
else if((G.have_libtiff) && else if((G.have_libtiff) &&
(G.scene->r.imtype==R_TIFF)) ibuf->ftype= TIF; (G.scene->r.imtype==R_TIFF)) ibuf->ftype= TIF;
#ifdef WITH_OPENEXR
else if(G.scene->r.imtype==R_OPENEXR) ibuf->ftype= OPENEXR;
#endif
else if(G.scene->r.imtype==R_HAMX) ibuf->ftype= AN_hamx; else if(G.scene->r.imtype==R_HAMX) ibuf->ftype= AN_hamx;
else if(ELEM5(G.scene->r.imtype, R_MOVIE, R_AVICODEC, R_AVIRAW, R_AVIJPEG, R_JPEG90)) { else if(ELEM5(G.scene->r.imtype, R_MOVIE, R_AVICODEC, R_AVIRAW, R_AVIJPEG, R_JPEG90)) {
ibuf->ftype= JPG|G.scene->r.quality; ibuf->ftype= JPG|G.scene->r.quality;

View File

@@ -34,10 +34,6 @@
#include <math.h> #include <math.h>
#include <stdlib.h> #include <stdlib.h>
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
#include "MEM_guardedalloc.h" #include "MEM_guardedalloc.h"
#include "PIL_dynlib.h" #include "PIL_dynlib.h"
@@ -1655,19 +1651,19 @@ void do_effect(int cfra, Sequence *seq, StripElem *se)
if(cp) strncpy(cp, seq->name+2, 22); if(cp) strncpy(cp, seq->name+2, 22);
if (seq->plugin->version<=2) { if (seq->plugin->version<=2) {
if(se1->ibuf) IMB_convert_rgba_to_abgr(se1->ibuf->x*se1->ibuf->y, se1->ibuf->rect); if(se1->ibuf) IMB_convert_rgba_to_abgr(se1->ibuf);
if(se2->ibuf) IMB_convert_rgba_to_abgr(se2->ibuf->x*se2->ibuf->y, se2->ibuf->rect); if(se2->ibuf) IMB_convert_rgba_to_abgr(se2->ibuf);
if(se3->ibuf) IMB_convert_rgba_to_abgr(se3->ibuf->x*se3->ibuf->y, se3->ibuf->rect); if(se3->ibuf) IMB_convert_rgba_to_abgr(se3->ibuf);
} }
((SeqDoit)seq->plugin->doit)(seq->plugin->data, fac, facf, x, y, ((SeqDoit)seq->plugin->doit)(seq->plugin->data, fac, facf, x, y,
se1->ibuf, se2->ibuf, se->ibuf, se3->ibuf); se1->ibuf, se2->ibuf, se->ibuf, se3->ibuf);
if (seq->plugin->version<=2) { if (seq->plugin->version<=2) {
if(se1->ibuf) IMB_convert_rgba_to_abgr(se1->ibuf->x*se1->ibuf->y, se1->ibuf->rect); if(se1->ibuf) IMB_convert_rgba_to_abgr(se1->ibuf);
if(se2->ibuf) IMB_convert_rgba_to_abgr(se2->ibuf->x*se2->ibuf->y, se2->ibuf->rect); if(se2->ibuf) IMB_convert_rgba_to_abgr(se2->ibuf);
if(se3->ibuf) IMB_convert_rgba_to_abgr(se3->ibuf->x*se3->ibuf->y, se3->ibuf->rect); if(se3->ibuf) IMB_convert_rgba_to_abgr(se3->ibuf);
IMB_convert_rgba_to_abgr(se->ibuf->x*se->ibuf->y, se->ibuf->rect); IMB_convert_rgba_to_abgr(se->ibuf);
} }
if((G.f & G_PLAYANIM)==0) waitcursor(0); if((G.f & G_PLAYANIM)==0) waitcursor(0);

View File

@@ -147,13 +147,6 @@ void schrijfplaatje(char *name)
unsigned int *temprect=0; unsigned int *temprect=0;
char str[FILE_MAXDIR+FILE_MAXFILE]; char str[FILE_MAXDIR+FILE_MAXFILE];
/* radhdr: temporary call for direct float buffer save for HDR format */
if ((R.r.imtype==R_RADHDR) && (R.rectftot))
{
imb_savehdr_fromfloat(R.rectftot, name, R.rectx, R.recty);
return;
}
/* has RGBA been set? If so: use alpha channel for color zero */ /* has RGBA been set? If so: use alpha channel for color zero */
IMB_alpha_to_col0(FALSE); IMB_alpha_to_col0(FALSE);
@@ -188,7 +181,7 @@ void schrijfplaatje(char *name)
if(ibuf) { if(ibuf) {
ibuf->rect= (unsigned int *) R.rectot; ibuf->rect= (unsigned int *) R.rectot;
// ibuf->rect_float = R.rectftot; ibuf->rect_float = R.rectftot;
if(R.r.planes == 8) IMB_cspace(ibuf, rgb_to_bw); if(R.r.planes == 8) IMB_cspace(ibuf, rgb_to_bw);
@@ -205,8 +198,6 @@ void schrijfplaatje(char *name)
} }
} }
else if(R.r.imtype==R_RADHDR) { else if(R.r.imtype==R_RADHDR) {
/* radhdr: save hdr from rgba buffer, not really recommended, probably mistake, so warn user */
error("Will save, but you might want to enable the floatbuffer to save a real HDRI...");
ibuf->ftype= RADHDR; ibuf->ftype= RADHDR;
} }
else if(R.r.imtype==R_PNG) { else if(R.r.imtype==R_PNG) {
@@ -218,6 +209,11 @@ void schrijfplaatje(char *name)
else if((G.have_libtiff) && (R.r.imtype==R_TIFF)) { else if((G.have_libtiff) && (R.r.imtype==R_TIFF)) {
ibuf->ftype= TIF; ibuf->ftype= TIF;
} }
#ifdef WITH_OPENEXR
else if(R.r.imtype==R_OPENEXR) {
ibuf->ftype= OPENEXR;
}
#endif
else if((R.r.imtype==R_TARGA) || (R.r.imtype==R_PNG)) { else if((R.r.imtype==R_TARGA) || (R.r.imtype==R_PNG)) {
ibuf->ftype= TGA; ibuf->ftype= TGA;
} }
@@ -500,6 +496,10 @@ int save_image_filesel_str(char *str)
if (G.have_libtiff) { if (G.have_libtiff) {
strcpy(str, "Save TIFF"); return 1; strcpy(str, "Save TIFF"); return 1;
} }
#ifdef WITH_OPENEXR
case R_OPENEXR:
strcpy(str, "Save OpenEXR"); return 1;
#endif
case R_TARGA: case R_TARGA:
strcpy(str, "Save Targa"); return 1; strcpy(str, "Save Targa"); return 1;
case R_RAWTGA: case R_RAWTGA:

View File

@@ -33,10 +33,6 @@
#include <math.h> #include <math.h>
#include <string.h> #include <string.h>
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
#ifdef WIN32 #ifdef WIN32
#include <io.h> #include <io.h>
#else #else
@@ -46,6 +42,7 @@
#include "MEM_guardedalloc.h" #include "MEM_guardedalloc.h"
#include "IMB_imbuf.h" #include "IMB_imbuf.h"
#include "IMB_imbuf_types.h"
#include "BLI_blenlib.h" #include "BLI_blenlib.h"
#include "BLI_arithb.h" #include "BLI_arithb.h"
@@ -599,7 +596,8 @@ static void vpaint_blend( unsigned int *col, unsigned int *colorig, unsigned int
static int sample_backbuf_area(int x, int y, float size) static int sample_backbuf_area(int x, int y, float size)
{ {
unsigned int rect[129*129], *rt; unsigned int *rt;
struct ImBuf *ibuf;
int x1, y1, x2, y2, a, tot=0, index; int x1, y1, x2, y2, a, tot=0, index;
if(totvpaintundo>=MAXINDEX) return 0; if(totvpaintundo>=MAXINDEX) return 0;
@@ -617,12 +615,15 @@ static int sample_backbuf_area(int x, int y, float size)
#ifdef __APPLE__ #ifdef __APPLE__
glReadBuffer(GL_AUX0); glReadBuffer(GL_AUX0);
#endif #endif
glReadPixels(x1+curarea->winrct.xmin, y1+curarea->winrct.ymin, x2-x1+1, y2-y1+1, GL_RGBA, GL_UNSIGNED_BYTE, rect); ibuf = IMB_allocImBuf(size,size,32,IB_rect,0);
glReadPixels(x1+curarea->winrct.xmin, y1+curarea->winrct.ymin, x2-x1+1, y2-y1+1, GL_RGBA, GL_UNSIGNED_BYTE, ibuf->rect);
glReadBuffer(GL_BACK); glReadBuffer(GL_BACK);
if(G.order==B_ENDIAN) IMB_convert_rgba_to_abgr( (int)(4*size*size), rect); if(G.order==B_ENDIAN) {
IMB_convert_rgba_to_abgr(ibuf);
}
rt= rect; rt= ibuf->rect;
size= (y2-y1)*(x2-x1); size= (y2-y1)*(x2-x1);
if(size<=0) return 0; if(size<=0) return 0;
@@ -643,6 +644,8 @@ static int sample_backbuf_area(int x, int y, float size)
if(indexar[a]) indexar[tot++]= a; if(indexar[a]) indexar[tot++]= a;
} }
IMB_freeImBuf(ibuf);
return tot; return tot;
} }

View File

@@ -63,6 +63,11 @@ int BIF_write_ibuf(ImBuf *ibuf, char *name)
else if ((G.have_libtiff) && (G.scene->r.imtype==R_TIFF)) { else if ((G.have_libtiff) && (G.scene->r.imtype==R_TIFF)) {
ibuf->ftype= TIF; ibuf->ftype= TIF;
} }
#ifdef WITH_OPENEXR
else if (G.scene->r.imtype==R_OPENEXR) {
ibuf->ftype= OPENEXR;
}
#endif
else if ((G.scene->r.imtype==R_TARGA) || (G.scene->r.imtype==R_PNG)) { else if ((G.scene->r.imtype==R_TARGA) || (G.scene->r.imtype==R_PNG)) {
// fall back to Targa if PNG writing is not supported // fall back to Targa if PNG writing is not supported
ibuf->ftype= TGA; ibuf->ftype= TGA;
@@ -105,18 +110,12 @@ void BIF_save_envmap(EnvMap *env, char *str)
dx= env->cube[0]->ibuf->x; dx= env->cube[0]->ibuf->x;
ibuf= IMB_allocImBuf(3*dx, 2*dx, 24, IB_rect, 0); ibuf= IMB_allocImBuf(3*dx, 2*dx, 24, IB_rect, 0);
IMB_rectop(ibuf, env->cube[0]->ibuf, IMB_rectcpy(ibuf, env->cube[0]->ibuf, 0, 0, 0, 0, dx, dx);
0, 0, 0, 0, dx, dx, IMB_rectcpy, 0); IMB_rectcpy(ibuf, env->cube[1]->ibuf, dx, 0, 0, 0, dx, dx);
IMB_rectop(ibuf, env->cube[1]->ibuf, IMB_rectcpy(ibuf, env->cube[2]->ibuf, 2*dx, 0, 0, 0, dx, dx);
dx, 0, 0, 0, dx, dx, IMB_rectcpy, 0); IMB_rectcpy(ibuf, env->cube[3]->ibuf, 0, dx, 0, 0, dx, dx);
IMB_rectop(ibuf, env->cube[2]->ibuf, IMB_rectcpy(ibuf, env->cube[4]->ibuf, dx, dx, 0, 0, dx, dx);
2*dx, 0, 0, 0, dx, dx, IMB_rectcpy, 0); IMB_rectcpy(ibuf, env->cube[5]->ibuf, 2*dx, dx, 0, 0, dx, dx);
IMB_rectop(ibuf, env->cube[3]->ibuf,
0, dx, 0, 0, dx, dx, IMB_rectcpy, 0);
IMB_rectop(ibuf, env->cube[4]->ibuf,
dx, dx, 0, 0, dx, dx, IMB_rectcpy, 0);
IMB_rectop(ibuf, env->cube[5]->ibuf,
2*dx, dx, 0, 0, dx, dx, IMB_rectcpy, 0);
BIF_write_ibuf(ibuf, str); BIF_write_ibuf(ibuf, str);
IMB_freeImBuf(ibuf); IMB_freeImBuf(ibuf);

View File

@@ -30,10 +30,6 @@
* ***** END GPL/BL DUAL LICENSE BLOCK ***** * ***** END GPL/BL DUAL LICENSE BLOCK *****
*/ */
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
#ifdef __sgi #ifdef __sgi
#include <unistd.h> #include <unistd.h>
@@ -364,6 +360,7 @@ void append_movie(int cfra)
char name[FILE_MAXDIR+FILE_MAXFILE]; char name[FILE_MAXDIR+FILE_MAXFILE];
const char *string; const char *string;
int fd; int fd;
float col[4] = {0.0,0.0,0.0,0.0};
set_sfra_efra(); set_sfra_efra();
make_movie_name(name); make_movie_name(name);
@@ -377,28 +374,28 @@ void append_movie(int cfra)
if (ibuf->x != mv_outx || ibuf->y != mv_outy) { if (ibuf->x != mv_outx || ibuf->y != mv_outy) {
tbuf = IMB_allocImBuf(mv_outx, mv_outy, 32, IB_rect, 0); tbuf = IMB_allocImBuf(mv_outx, mv_outy, 32, IB_rect, 0);
IMB_rectoptot(tbuf, 0, IMB_rectfill, 0x00); IMB_rectfill(tbuf,col);
ofsx = (tbuf->x - ibuf->x) / 2; ofsx = (tbuf->x - ibuf->x) / 2;
ofsy = (tbuf->y - ibuf->y) / 2; ofsy = (tbuf->y - ibuf->y) / 2;
if (numfields == 2) ofsy &= ~1; if (numfields == 2) ofsy &= ~1;
IMB_rectop(tbuf, ibuf, ofsx, ofsy, 0, 0, 32767, 32767, IMB_rectcpy, 0); IMB_rectcpy(tbuf, ibuf, ofsx, ofsy, 0, 0, ibuf->x, ibuf->y);
IMB_freeImBuf(ibuf); IMB_freeImBuf(ibuf);
strcpy(tbuf->name, ibuf->name); strcpy(tbuf->name, ibuf->name);
ibuf = tbuf; ibuf = tbuf;
} }
IMB_convert_rgba_to_abgr(ibuf->x*ibuf->y, ibuf->rect); IMB_convert_rgba_to_abgr(ibuf);
if (numfields == 2) { if (numfields == 2) {
if (ntsc) { if (ntsc) {
IMB_rectop(ibuf, ibuf, 0, 0, 0, 1, 32767, 32767, IMB_rectcpy, 0); IMB_rectcpy(ibuf, ibuf, 0, 0, 0, 1, ibuf->x, ibuf->y);
IMB_flipy(ibuf); IMB_flipy(ibuf);
IMB_de_interlace(ibuf); IMB_de_interlace(ibuf);
if (ntsc) IMB_rectop(ibuf, ibuf, 0, 0, 0, 1, 32767, 32767, IMB_rectcpy, 0); if (ntsc) IMB_rectcpy(ibuf, ibuf, 0, 0, 0, 1, ibuf->x, ibuf->y);
} else { } else {
IMB_flipy(ibuf); IMB_flipy(ibuf);
IMB_rectop(ibuf, ibuf, 0, 0, 0, 1, 32767, 32767, IMB_rectcpy, 0); IMB_rectcpy(ibuf, ibuf, 0, 0, 0, 1, ibuf->x, ibuf->y);
IMB_de_interlace(ibuf); IMB_de_interlace(ibuf);
} }
} }