This repository has been archived on 2023-10-09. You can view files and clone it, but cannot push or open issues or pull requests.
Files
blender-archive/source/blender/imbuf/intern/openexr/openexr_api.cpp

1085 lines
30 KiB
C++
Raw Normal View History

/*
* ***** 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
2012-06-13 17:27:49 +00:00
* 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,
2010-02-12 13:34:04 +00:00
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, 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 *****
*/
2012-03-09 18:28:30 +00:00
/** \file blender/imbuf/intern/openexr/openexr_api.cpp
* \ingroup openexr
*/
#include <stdlib.h>
#include <stdio.h>
#include <stddef.h>
#include <string>
#include <set>
#include <openexr_api.h>
extern "C"
{
// The following prevents a linking error in debug mode for MSVC using the libs in CVS
#if defined(WITH_OPENEXR) && defined(_WIN32) && defined(_DEBUG) && !defined(__MINGW32__) && !defined(__CYGWIN__)
_CRTIMP void __cdecl _invalid_parameter_noinfo(void)
{
}
#endif
Four-in-one commit: (NOTE: new include dependency in Render module, might need MSVC update! It has to include the imbuf/intern/openexr/ directory in search path) -> New Composite node: "Hue Saturation". Works like the former 'post process' menu. There's no gamma, brightness or multiply needed in this node, for that the Curves Node functions better. -> Enabled Toolbox in Node editor This now also replaces the SHIFT+A for adding nodes. The nodes are automatically added to the menus, using the 'class' category from the type definition. Current classes are (compositor examples): Inputs: RenderResult, Image Outputs: Composite, Viewer Color Ops: RGB Curves, Mix, Hue Saturation, AlphaOver Vector Ops: Normal, Vector Curves, Map Value Filters: Filter, Blur, VectorBlur Convertors: ColorRamp, RGBtoBW, Separate RGBA, Separate HSVA, Set Alpha Generators: RGB, Value, Time Groups: the list of custom defined nodes -> OpenEXR tile saving support Created an API for for saving tile-based Images with an unlimited amount of layers/channels. I've tested it for 'render result' now, with the idea that this can (optionally) replace the current inserting of tiles in the main result buffers. Especially with a lot of layers, the used memory for these buffers can easily go into the 100s of megs. Two other advantages: - all 'render result' layers can be saved entirely in a single file, for later use in compositing, also for animation output. - on each render, per scene, a unique temp file can be stored, allowing to re-use these temp files on starting Blender or loading files, showing the last result of a render command. The option is currently disabled, needs more work... but I had to commit this because of the rest of the work I did! -> Bug fix The Image node didn't call an execute event when browsing another image.
2006-02-18 13:28:44 +00:00
#include "MEM_guardedalloc.h"
#include "BLI_blenlib.h"
#include "BLI_math_color.h"
#include "BLI_threads.h"
Four-in-one commit: (NOTE: new include dependency in Render module, might need MSVC update! It has to include the imbuf/intern/openexr/ directory in search path) -> New Composite node: "Hue Saturation". Works like the former 'post process' menu. There's no gamma, brightness or multiply needed in this node, for that the Curves Node functions better. -> Enabled Toolbox in Node editor This now also replaces the SHIFT+A for adding nodes. The nodes are automatically added to the menus, using the 'class' category from the type definition. Current classes are (compositor examples): Inputs: RenderResult, Image Outputs: Composite, Viewer Color Ops: RGB Curves, Mix, Hue Saturation, AlphaOver Vector Ops: Normal, Vector Curves, Map Value Filters: Filter, Blur, VectorBlur Convertors: ColorRamp, RGBtoBW, Separate RGBA, Separate HSVA, Set Alpha Generators: RGB, Value, Time Groups: the list of custom defined nodes -> OpenEXR tile saving support Created an API for for saving tile-based Images with an unlimited amount of layers/channels. I've tested it for 'render result' now, with the idea that this can (optionally) replace the current inserting of tiles in the main result buffers. Especially with a lot of layers, the used memory for these buffers can easily go into the 100s of megs. Two other advantages: - all 'render result' layers can be saved entirely in a single file, for later use in compositing, also for animation output. - on each render, per scene, a unique temp file can be stored, allowing to re-use these temp files on starting Blender or loading files, showing the last result of a render command. The option is currently disabled, needs more work... but I had to commit this because of the rest of the work I did! -> Bug fix The Image node didn't call an execute event when browsing another image.
2006-02-18 13:28:44 +00:00
#include "IMB_imbuf_types.h"
#include "IMB_imbuf.h"
#include "IMB_allocimbuf.h"
#include "IMB_metadata.h"
#include "openexr_multi.h"
}
#include <iostream>
2012-06-13 17:27:49 +00:00
#if defined(_WIN32) && !defined(FREE_WINDOWS)
2006-01-10 06:29:57 +00:00
#include <half.h>
#include <IlmImf/ImfVersion.h>
#include <IlmImf/ImfArray.h>
#include <IlmImf/ImfIO.h>
#include <IlmImf/ImfChannelList.h>
#include <IlmImf/ImfPixelType.h>
#include <IlmImf/ImfInputFile.h>
#include <IlmImf/ImfOutputFile.h>
#include <IlmImf/ImfCompression.h>
#include <IlmImf/ImfCompressionAttribute.h>
Four-in-one commit: (NOTE: new include dependency in Render module, might need MSVC update! It has to include the imbuf/intern/openexr/ directory in search path) -> New Composite node: "Hue Saturation". Works like the former 'post process' menu. There's no gamma, brightness or multiply needed in this node, for that the Curves Node functions better. -> Enabled Toolbox in Node editor This now also replaces the SHIFT+A for adding nodes. The nodes are automatically added to the menus, using the 'class' category from the type definition. Current classes are (compositor examples): Inputs: RenderResult, Image Outputs: Composite, Viewer Color Ops: RGB Curves, Mix, Hue Saturation, AlphaOver Vector Ops: Normal, Vector Curves, Map Value Filters: Filter, Blur, VectorBlur Convertors: ColorRamp, RGBtoBW, Separate RGBA, Separate HSVA, Set Alpha Generators: RGB, Value, Time Groups: the list of custom defined nodes -> OpenEXR tile saving support Created an API for for saving tile-based Images with an unlimited amount of layers/channels. I've tested it for 'render result' now, with the idea that this can (optionally) replace the current inserting of tiles in the main result buffers. Especially with a lot of layers, the used memory for these buffers can easily go into the 100s of megs. Two other advantages: - all 'render result' layers can be saved entirely in a single file, for later use in compositing, also for animation output. - on each render, per scene, a unique temp file can be stored, allowing to re-use these temp files on starting Blender or loading files, showing the last result of a render command. The option is currently disabled, needs more work... but I had to commit this because of the rest of the work I did! -> Bug fix The Image node didn't call an execute event when browsing another image.
2006-02-18 13:28:44 +00:00
#include <IlmImf/ImfStringAttribute.h>
2006-01-10 06:29:57 +00:00
#include <Imath/ImathBox.h>
#else
#include <half.h>
#include <ImfVersion.h>
#include <ImathBox.h>
#include <ImfArray.h>
#include <ImfIO.h>
#include <ImfChannelList.h>
#include <ImfPixelType.h>
#include <ImfInputFile.h>
#include <ImfOutputFile.h>
#include <ImfCompression.h>
#include <ImfCompressionAttribute.h>
#include <ImfStringAttribute.h>
2006-01-10 06:29:57 +00:00
#endif
using namespace Imf;
using namespace Imath;
2012-06-13 17:27:49 +00:00
class Mem_IStream : public Imf::IStream
{
public:
2012-06-13 17:27:49 +00:00
Mem_IStream (unsigned char *exrbuf, size_t 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
2012-06-13 17:27:49 +00:00
private:
Int64 _exrpos;
Int64 _exrsize;
unsigned char *_exrbuf;
};
2012-06-13 17:27:49 +00:00
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;
}
2012-06-13 17:27:49 +00:00
Int64 Mem_IStream::tellg()
{
return _exrpos;
}
2012-06-13 17:27:49 +00:00
void Mem_IStream::seekg(Int64 pos)
{
_exrpos = pos;
}
2012-06-13 17:27:49 +00:00
void Mem_IStream::clear()
{
}
2012-06-13 17:27:49 +00:00
struct _RGBAZ {
half r;
half g;
half b;
half a;
half z;
};
typedef struct _RGBAZ RGBAZ;
extern "C"
{
2012-06-13 17:27:49 +00:00
int imb_is_a_openexr(unsigned char *mem)
{
2012-06-13 17:27:49 +00:00
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() = ZIP_COMPRESSION;
2012-06-13 17:27:49 +00:00
break;
}
}
static void openexr_header_metadata(Header *header, struct ImBuf *ibuf)
{
2012-06-13 17:27:49 +00:00
ImMetaData *info;
2012-06-13 17:27:49 +00:00
for (info = ibuf->metadata; info; info = info->next)
header->insert(info->key, StringAttribute(info->value));
}
static int imb_save_openexr_half(struct ImBuf *ibuf, const char *name, int flags)
{
2012-06-14 11:44:05 +00:00
const int channels = ibuf->channels;
const int is_alpha = (channels >= 4) && (ibuf->planes == 32);
const int is_zbuf = (flags & IB_zbuffloat) && ibuf->zbuf_float != NULL; /* summarize */
const int width = ibuf->x;
const int height = ibuf->y;
2012-06-13 17:27:49 +00:00
try
{
2012-06-13 17:27:49 +00:00
Header header(width, height);
openexr_header_compression(&header, ibuf->ftype & OPENEXR_COMPRESS);
openexr_header_metadata(&header, ibuf);
2012-06-13 17:27:49 +00:00
header.channels().insert("R", Channel(HALF));
header.channels().insert("G", Channel(HALF));
header.channels().insert("B", Channel(HALF));
2012-06-14 11:44:05 +00:00
if (is_alpha)
2012-06-13 17:27:49 +00:00
header.channels().insert("A", Channel(HALF));
2012-06-14 11:44:05 +00:00
if (is_zbuf) // z we do as float always
2012-06-13 17:27:49 +00:00
header.channels().insert("Z", Channel(Imf::FLOAT));
FrameBuffer frameBuffer;
OutputFile *file = new OutputFile(name, header);
/* we store first everything in half array */
RGBAZ *pixels = new RGBAZ[height * width];
RGBAZ *to = pixels;
2012-06-14 11:44:05 +00:00
int xstride = sizeof(RGBAZ);
2012-06-13 17:27:49 +00:00
int ystride = xstride * width;
/* indicate used buffers */
2012-06-13 17:27:49 +00:00
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));
2012-06-14 11:44:05 +00:00
if (is_alpha)
2012-06-13 17:27:49 +00:00
frameBuffer.insert("A", Slice(HALF, (char *) &pixels[0].a, xstride, ystride));
2012-06-14 11:44:05 +00:00
if (is_zbuf)
2012-06-13 17:27:49 +00:00
frameBuffer.insert("Z", Slice(Imf::FLOAT, (char *)(ibuf->zbuf_float + (height - 1) * width),
sizeof(float), sizeof(float) * -width));
if (ibuf->rect_float) {
float *from;
2012-06-13 17:27:49 +00:00
for (int i = ibuf->y - 1; i >= 0; i--) {
from = ibuf->rect_float + channels * i * width;
for (int j = ibuf->x; j > 0; j--) {
to->r = from[0];
to->g = from[1];
to->b = from[2];
2012-06-13 17:27:49 +00:00
to->a = (channels >= 4) ? from[3] : 1.0f;
to++; from += 4;
}
}
}
else {
unsigned char *from;
if (ibuf->profile == IB_PROFILE_LINEAR_RGB) {
2012-06-13 17:27:49 +00:00
for (int i = ibuf->y - 1; i >= 0; i--) {
from = (unsigned char *)ibuf->rect + channels * i * width;
for (int j = ibuf->x; j > 0; j--) {
2012-06-13 17:27:49 +00:00
to->r = (float)(from[0]) / 255.0;
to->g = (float)(from[1]) / 255.0;
to->b = (float)(from[2]) / 255.0;
to->a = (float)(channels >= 4) ? from[3] / 255.0 : 1.0f;
to++; from += 4;
}
}
}
else {
2012-06-13 17:27:49 +00:00
for (int i = ibuf->y - 1; i >= 0; i--) {
from = (unsigned char *)ibuf->rect + channels * i * width;
for (int j = ibuf->x; j > 0; j--) {
to->r = srgb_to_linearrgb((float)from[0] / 255.0);
to->g = srgb_to_linearrgb((float)from[1] / 255.0);
to->b = srgb_to_linearrgb((float)from[2] / 255.0);
2012-06-13 17:27:49 +00:00
to->a = channels >= 4 ? (float)from[3] / 255.0 : 1.0f;
to++; from += 4;
}
}
}
}
2012-06-13 17:27:49 +00:00
// printf("OpenEXR-save: Writing OpenEXR file of height %d.\n", height);
2012-06-13 17:27:49 +00:00
file->setFrameBuffer(frameBuffer);
file->writePixels(height);
delete file;
2012-06-13 17:27:49 +00:00
delete[] pixels;
}
catch (const std::exception &exc)
{
printf("OpenEXR-save: ERROR: %s\n", exc.what());
if (ibuf) IMB_freeImBuf(ibuf);
2012-06-13 17:27:49 +00:00
return (0);
}
2012-06-13 17:27:49 +00:00
return (1);
}
static int imb_save_openexr_float(struct ImBuf *ibuf, const char *name, int flags)
{
2012-06-14 11:44:05 +00:00
const int channels = ibuf->channels;
const int is_alpha = (channels >= 4) && (ibuf->planes == 32);
const int is_zbuf = (flags & IB_zbuffloat) && ibuf->zbuf_float != NULL; /* summarize */
const int width = ibuf->x;
const int height = ibuf->y;
try
{
2012-06-13 17:27:49 +00:00
Header header(width, height);
openexr_header_compression(&header, ibuf->ftype & OPENEXR_COMPRESS);
openexr_header_metadata(&header, ibuf);
2012-06-13 17:27:49 +00:00
header.channels().insert("R", Channel(Imf::FLOAT));
header.channels().insert("G", Channel(Imf::FLOAT));
header.channels().insert("B", Channel(Imf::FLOAT));
2012-06-14 11:44:05 +00:00
if (is_alpha)
2012-06-13 17:27:49 +00:00
header.channels().insert("A", Channel(Imf::FLOAT));
2012-06-14 11:44:05 +00:00
if (is_zbuf)
2012-06-13 17:27:49 +00:00
header.channels().insert("Z", Channel(Imf::FLOAT));
FrameBuffer frameBuffer;
OutputFile *file = new OutputFile(name, header);
int xstride = sizeof(float) * channels;
2012-06-13 17:27:49 +00:00
int ystride = -xstride * width;
float *rect[4] = {NULL, NULL, NULL, NULL};
/* last scanline, stride negative */
2012-06-13 17:27:49 +00:00
rect[0] = ibuf->rect_float + channels * (height - 1) * width;
rect[1] = rect[0] + 1;
rect[2] = rect[0] + 2;
rect[3] = (channels >= 4) ? rect[0] + 3 : rect[0]; /* red as alpha, is this needed since alpha isn't written? */
frameBuffer.insert("R", Slice(Imf::FLOAT, (char *)rect[0], xstride, ystride));
frameBuffer.insert("G", Slice(Imf::FLOAT, (char *)rect[1], xstride, ystride));
frameBuffer.insert("B", Slice(Imf::FLOAT, (char *)rect[2], xstride, ystride));
2012-06-14 11:44:05 +00:00
if (is_alpha)
2012-06-13 17:27:49 +00:00
frameBuffer.insert("A", Slice(Imf::FLOAT, (char *)rect[3], xstride, ystride));
2012-06-14 11:44:05 +00:00
if (is_zbuf)
2012-06-13 17:27:49 +00:00
frameBuffer.insert("Z", Slice(Imf::FLOAT, (char *) (ibuf->zbuf_float + (height - 1) * width),
sizeof(float), sizeof(float) * -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);
2012-06-13 17:27:49 +00:00
return (0);
}
2012-06-13 17:27:49 +00:00
return (1);
// printf("OpenEXR-save: Done.\n");
}
int imb_save_openexr(struct ImBuf *ibuf, const char *name, int flags)
{
if (flags & IB_mem) {
printf("OpenEXR-save: Create EXR in memory CURRENTLY NOT SUPPORTED !\n");
imb_addencodedbufferImBuf(ibuf);
2012-06-13 17:27:49 +00:00
ibuf->encodedsize = 0;
return(0);
2012-06-13 17:27:49 +00:00
}
if (ibuf->ftype & OPENEXR_HALF)
return imb_save_openexr_half(ibuf, name, flags);
else {
/* when no float rect, we save as half (16 bits is sufficient) */
2012-06-13 17:27:49 +00:00
if (ibuf->rect_float == NULL)
return imb_save_openexr_half(ibuf, name, flags);
else
return imb_save_openexr_float(ibuf, name, flags);
}
}
/* ********************* Nicer API, MultiLayer and with Tile file support ************************************ */
/* naming rules:
2012-03-09 18:28:30 +00:00
* - parse name from right to left
* - last character is channel ID, 1 char like 'A' 'R' 'G' 'B' 'X' 'Y' 'Z' 'W' 'U' 'V'
* - separated with a dot; the Pass name (like "Depth", "Color", "Diffuse" or "Combined")
* - separated with a dot: the Layer name (like "Lamp1" or "Walls" or "Characters")
*/
2012-06-13 17:27:49 +00:00
static ListBase exrhandles = {NULL, NULL};
Four-in-one commit: (NOTE: new include dependency in Render module, might need MSVC update! It has to include the imbuf/intern/openexr/ directory in search path) -> New Composite node: "Hue Saturation". Works like the former 'post process' menu. There's no gamma, brightness or multiply needed in this node, for that the Curves Node functions better. -> Enabled Toolbox in Node editor This now also replaces the SHIFT+A for adding nodes. The nodes are automatically added to the menus, using the 'class' category from the type definition. Current classes are (compositor examples): Inputs: RenderResult, Image Outputs: Composite, Viewer Color Ops: RGB Curves, Mix, Hue Saturation, AlphaOver Vector Ops: Normal, Vector Curves, Map Value Filters: Filter, Blur, VectorBlur Convertors: ColorRamp, RGBtoBW, Separate RGBA, Separate HSVA, Set Alpha Generators: RGB, Value, Time Groups: the list of custom defined nodes -> OpenEXR tile saving support Created an API for for saving tile-based Images with an unlimited amount of layers/channels. I've tested it for 'render result' now, with the idea that this can (optionally) replace the current inserting of tiles in the main result buffers. Especially with a lot of layers, the used memory for these buffers can easily go into the 100s of megs. Two other advantages: - all 'render result' layers can be saved entirely in a single file, for later use in compositing, also for animation output. - on each render, per scene, a unique temp file can be stored, allowing to re-use these temp files on starting Blender or loading files, showing the last result of a render command. The option is currently disabled, needs more work... but I had to commit this because of the rest of the work I did! -> Bug fix The Image node didn't call an execute event when browsing another image.
2006-02-18 13:28:44 +00:00
typedef struct ExrHandle {
struct ExrHandle *next, *prev;
2012-06-13 17:27:49 +00:00
InputFile *ifile;
TiledOutputFile *tofile;
OutputFile *ofile;
Four-in-one commit: (NOTE: new include dependency in Render module, might need MSVC update! It has to include the imbuf/intern/openexr/ directory in search path) -> New Composite node: "Hue Saturation". Works like the former 'post process' menu. There's no gamma, brightness or multiply needed in this node, for that the Curves Node functions better. -> Enabled Toolbox in Node editor This now also replaces the SHIFT+A for adding nodes. The nodes are automatically added to the menus, using the 'class' category from the type definition. Current classes are (compositor examples): Inputs: RenderResult, Image Outputs: Composite, Viewer Color Ops: RGB Curves, Mix, Hue Saturation, AlphaOver Vector Ops: Normal, Vector Curves, Map Value Filters: Filter, Blur, VectorBlur Convertors: ColorRamp, RGBtoBW, Separate RGBA, Separate HSVA, Set Alpha Generators: RGB, Value, Time Groups: the list of custom defined nodes -> OpenEXR tile saving support Created an API for for saving tile-based Images with an unlimited amount of layers/channels. I've tested it for 'render result' now, with the idea that this can (optionally) replace the current inserting of tiles in the main result buffers. Especially with a lot of layers, the used memory for these buffers can easily go into the 100s of megs. Two other advantages: - all 'render result' layers can be saved entirely in a single file, for later use in compositing, also for animation output. - on each render, per scene, a unique temp file can be stored, allowing to re-use these temp files on starting Blender or loading files, showing the last result of a render command. The option is currently disabled, needs more work... but I had to commit this because of the rest of the work I did! -> Bug fix The Image node didn't call an execute event when browsing another image.
2006-02-18 13:28:44 +00:00
int tilex, tiley;
int width, height;
int mipmap;
2012-06-13 17:27:49 +00:00
ListBase channels; /* flattened out, ExrChannel */
ListBase layers; /* hierarchical, pointing in end to ExrChannel */
} ExrHandle;
Four-in-one commit: (NOTE: new include dependency in Render module, might need MSVC update! It has to include the imbuf/intern/openexr/ directory in search path) -> New Composite node: "Hue Saturation". Works like the former 'post process' menu. There's no gamma, brightness or multiply needed in this node, for that the Curves Node functions better. -> Enabled Toolbox in Node editor This now also replaces the SHIFT+A for adding nodes. The nodes are automatically added to the menus, using the 'class' category from the type definition. Current classes are (compositor examples): Inputs: RenderResult, Image Outputs: Composite, Viewer Color Ops: RGB Curves, Mix, Hue Saturation, AlphaOver Vector Ops: Normal, Vector Curves, Map Value Filters: Filter, Blur, VectorBlur Convertors: ColorRamp, RGBtoBW, Separate RGBA, Separate HSVA, Set Alpha Generators: RGB, Value, Time Groups: the list of custom defined nodes -> OpenEXR tile saving support Created an API for for saving tile-based Images with an unlimited amount of layers/channels. I've tested it for 'render result' now, with the idea that this can (optionally) replace the current inserting of tiles in the main result buffers. Especially with a lot of layers, the used memory for these buffers can easily go into the 100s of megs. Two other advantages: - all 'render result' layers can be saved entirely in a single file, for later use in compositing, also for animation output. - on each render, per scene, a unique temp file can be stored, allowing to re-use these temp files on starting Blender or loading files, showing the last result of a render command. The option is currently disabled, needs more work... but I had to commit this because of the rest of the work I did! -> Bug fix The Image node didn't call an execute event when browsing another image.
2006-02-18 13:28:44 +00:00
/* flattened out channel */
typedef struct ExrChannel {
struct ExrChannel *next, *prev;
2012-06-13 17:27:49 +00:00
char name[EXR_TOT_MAXNAME + 1]; /* full name of layer+pass */
int xstride, ystride; /* step to next pixel, to next scanline */
float *rect; /* first pointer to write in */
char chan_id; /* quick lookup of channel char */
} ExrChannel;
Four-in-one commit: (NOTE: new include dependency in Render module, might need MSVC update! It has to include the imbuf/intern/openexr/ directory in search path) -> New Composite node: "Hue Saturation". Works like the former 'post process' menu. There's no gamma, brightness or multiply needed in this node, for that the Curves Node functions better. -> Enabled Toolbox in Node editor This now also replaces the SHIFT+A for adding nodes. The nodes are automatically added to the menus, using the 'class' category from the type definition. Current classes are (compositor examples): Inputs: RenderResult, Image Outputs: Composite, Viewer Color Ops: RGB Curves, Mix, Hue Saturation, AlphaOver Vector Ops: Normal, Vector Curves, Map Value Filters: Filter, Blur, VectorBlur Convertors: ColorRamp, RGBtoBW, Separate RGBA, Separate HSVA, Set Alpha Generators: RGB, Value, Time Groups: the list of custom defined nodes -> OpenEXR tile saving support Created an API for for saving tile-based Images with an unlimited amount of layers/channels. I've tested it for 'render result' now, with the idea that this can (optionally) replace the current inserting of tiles in the main result buffers. Especially with a lot of layers, the used memory for these buffers can easily go into the 100s of megs. Two other advantages: - all 'render result' layers can be saved entirely in a single file, for later use in compositing, also for animation output. - on each render, per scene, a unique temp file can be stored, allowing to re-use these temp files on starting Blender or loading files, showing the last result of a render command. The option is currently disabled, needs more work... but I had to commit this because of the rest of the work I did! -> Bug fix The Image node didn't call an execute event when browsing another image.
2006-02-18 13:28:44 +00:00
/* hierarchical; layers -> passes -> channels[] */
typedef struct ExrPass {
struct ExrPass *next, *prev;
char name[EXR_PASS_MAXNAME];
int totchan;
float *rect;
struct ExrChannel *chan[EXR_PASS_MAXCHAN];
char chan_id[EXR_PASS_MAXCHAN];
} ExrPass;
typedef struct ExrLayer {
struct ExrLayer *next, *prev;
2012-06-13 17:27:49 +00:00
char name[EXR_LAY_MAXNAME + 1];
ListBase passes;
} ExrLayer;
/* ********************** */
void *IMB_exr_get_handle(void)
Four-in-one commit: (NOTE: new include dependency in Render module, might need MSVC update! It has to include the imbuf/intern/openexr/ directory in search path) -> New Composite node: "Hue Saturation". Works like the former 'post process' menu. There's no gamma, brightness or multiply needed in this node, for that the Curves Node functions better. -> Enabled Toolbox in Node editor This now also replaces the SHIFT+A for adding nodes. The nodes are automatically added to the menus, using the 'class' category from the type definition. Current classes are (compositor examples): Inputs: RenderResult, Image Outputs: Composite, Viewer Color Ops: RGB Curves, Mix, Hue Saturation, AlphaOver Vector Ops: Normal, Vector Curves, Map Value Filters: Filter, Blur, VectorBlur Convertors: ColorRamp, RGBtoBW, Separate RGBA, Separate HSVA, Set Alpha Generators: RGB, Value, Time Groups: the list of custom defined nodes -> OpenEXR tile saving support Created an API for for saving tile-based Images with an unlimited amount of layers/channels. I've tested it for 'render result' now, with the idea that this can (optionally) replace the current inserting of tiles in the main result buffers. Especially with a lot of layers, the used memory for these buffers can easily go into the 100s of megs. Two other advantages: - all 'render result' layers can be saved entirely in a single file, for later use in compositing, also for animation output. - on each render, per scene, a unique temp file can be stored, allowing to re-use these temp files on starting Blender or loading files, showing the last result of a render command. The option is currently disabled, needs more work... but I had to commit this because of the rest of the work I did! -> Bug fix The Image node didn't call an execute event when browsing another image.
2006-02-18 13:28:44 +00:00
{
2012-06-13 17:27:49 +00:00
ExrHandle *data = (ExrHandle *)MEM_callocN(sizeof(ExrHandle), "exr handle");
BLI_addtail(&exrhandles, data);
return data;
Four-in-one commit: (NOTE: new include dependency in Render module, might need MSVC update! It has to include the imbuf/intern/openexr/ directory in search path) -> New Composite node: "Hue Saturation". Works like the former 'post process' menu. There's no gamma, brightness or multiply needed in this node, for that the Curves Node functions better. -> Enabled Toolbox in Node editor This now also replaces the SHIFT+A for adding nodes. The nodes are automatically added to the menus, using the 'class' category from the type definition. Current classes are (compositor examples): Inputs: RenderResult, Image Outputs: Composite, Viewer Color Ops: RGB Curves, Mix, Hue Saturation, AlphaOver Vector Ops: Normal, Vector Curves, Map Value Filters: Filter, Blur, VectorBlur Convertors: ColorRamp, RGBtoBW, Separate RGBA, Separate HSVA, Set Alpha Generators: RGB, Value, Time Groups: the list of custom defined nodes -> OpenEXR tile saving support Created an API for for saving tile-based Images with an unlimited amount of layers/channels. I've tested it for 'render result' now, with the idea that this can (optionally) replace the current inserting of tiles in the main result buffers. Especially with a lot of layers, the used memory for these buffers can easily go into the 100s of megs. Two other advantages: - all 'render result' layers can be saved entirely in a single file, for later use in compositing, also for animation output. - on each render, per scene, a unique temp file can be stored, allowing to re-use these temp files on starting Blender or loading files, showing the last result of a render command. The option is currently disabled, needs more work... but I had to commit this because of the rest of the work I did! -> Bug fix The Image node didn't call an execute event when browsing another image.
2006-02-18 13:28:44 +00:00
}
/* adds flattened ExrChannels */
/* xstride, ystride and rect can be done in set_channel too, for tile writing */
void IMB_exr_add_channel(void *handle, const char *layname, const char *passname, int xstride, int ystride, float *rect)
Four-in-one commit: (NOTE: new include dependency in Render module, might need MSVC update! It has to include the imbuf/intern/openexr/ directory in search path) -> New Composite node: "Hue Saturation". Works like the former 'post process' menu. There's no gamma, brightness or multiply needed in this node, for that the Curves Node functions better. -> Enabled Toolbox in Node editor This now also replaces the SHIFT+A for adding nodes. The nodes are automatically added to the menus, using the 'class' category from the type definition. Current classes are (compositor examples): Inputs: RenderResult, Image Outputs: Composite, Viewer Color Ops: RGB Curves, Mix, Hue Saturation, AlphaOver Vector Ops: Normal, Vector Curves, Map Value Filters: Filter, Blur, VectorBlur Convertors: ColorRamp, RGBtoBW, Separate RGBA, Separate HSVA, Set Alpha Generators: RGB, Value, Time Groups: the list of custom defined nodes -> OpenEXR tile saving support Created an API for for saving tile-based Images with an unlimited amount of layers/channels. I've tested it for 'render result' now, with the idea that this can (optionally) replace the current inserting of tiles in the main result buffers. Especially with a lot of layers, the used memory for these buffers can easily go into the 100s of megs. Two other advantages: - all 'render result' layers can be saved entirely in a single file, for later use in compositing, also for animation output. - on each render, per scene, a unique temp file can be stored, allowing to re-use these temp files on starting Blender or loading files, showing the last result of a render command. The option is currently disabled, needs more work... but I had to commit this because of the rest of the work I did! -> Bug fix The Image node didn't call an execute event when browsing another image.
2006-02-18 13:28:44 +00:00
{
2012-06-13 17:27:49 +00:00
ExrHandle *data = (ExrHandle *)handle;
ExrChannel *echan;
2012-06-13 17:27:49 +00:00
echan = (ExrChannel *)MEM_callocN(sizeof(ExrChannel), "exr tile channel");
if (layname) {
2012-06-13 17:27:49 +00:00
char lay[EXR_LAY_MAXNAME + 1], pass[EXR_PASS_MAXNAME + 1];
BLI_strncpy(lay, layname, EXR_LAY_MAXNAME);
BLI_strncpy(pass, passname, EXR_PASS_MAXNAME);
2012-06-13 17:27:49 +00:00
BLI_snprintf(echan->name, sizeof(echan->name), "%s.%s", lay, pass);
}
2012-06-13 17:27:49 +00:00
else {
BLI_strncpy(echan->name, passname, EXR_TOT_MAXNAME - 1);
}
echan->xstride = xstride;
echan->ystride = ystride;
echan->rect = rect;
// printf("added channel %s\n", echan->name);
Four-in-one commit: (NOTE: new include dependency in Render module, might need MSVC update! It has to include the imbuf/intern/openexr/ directory in search path) -> New Composite node: "Hue Saturation". Works like the former 'post process' menu. There's no gamma, brightness or multiply needed in this node, for that the Curves Node functions better. -> Enabled Toolbox in Node editor This now also replaces the SHIFT+A for adding nodes. The nodes are automatically added to the menus, using the 'class' category from the type definition. Current classes are (compositor examples): Inputs: RenderResult, Image Outputs: Composite, Viewer Color Ops: RGB Curves, Mix, Hue Saturation, AlphaOver Vector Ops: Normal, Vector Curves, Map Value Filters: Filter, Blur, VectorBlur Convertors: ColorRamp, RGBtoBW, Separate RGBA, Separate HSVA, Set Alpha Generators: RGB, Value, Time Groups: the list of custom defined nodes -> OpenEXR tile saving support Created an API for for saving tile-based Images with an unlimited amount of layers/channels. I've tested it for 'render result' now, with the idea that this can (optionally) replace the current inserting of tiles in the main result buffers. Especially with a lot of layers, the used memory for these buffers can easily go into the 100s of megs. Two other advantages: - all 'render result' layers can be saved entirely in a single file, for later use in compositing, also for animation output. - on each render, per scene, a unique temp file can be stored, allowing to re-use these temp files on starting Blender or loading files, showing the last result of a render command. The option is currently disabled, needs more work... but I had to commit this because of the rest of the work I did! -> Bug fix The Image node didn't call an execute event when browsing another image.
2006-02-18 13:28:44 +00:00
BLI_addtail(&data->channels, echan);
}
/* only used for writing temp. render results (not image files) */
int IMB_exr_begin_write(void *handle, const char *filename, int width, int height, int compress)
Four-in-one commit: (NOTE: new include dependency in Render module, might need MSVC update! It has to include the imbuf/intern/openexr/ directory in search path) -> New Composite node: "Hue Saturation". Works like the former 'post process' menu. There's no gamma, brightness or multiply needed in this node, for that the Curves Node functions better. -> Enabled Toolbox in Node editor This now also replaces the SHIFT+A for adding nodes. The nodes are automatically added to the menus, using the 'class' category from the type definition. Current classes are (compositor examples): Inputs: RenderResult, Image Outputs: Composite, Viewer Color Ops: RGB Curves, Mix, Hue Saturation, AlphaOver Vector Ops: Normal, Vector Curves, Map Value Filters: Filter, Blur, VectorBlur Convertors: ColorRamp, RGBtoBW, Separate RGBA, Separate HSVA, Set Alpha Generators: RGB, Value, Time Groups: the list of custom defined nodes -> OpenEXR tile saving support Created an API for for saving tile-based Images with an unlimited amount of layers/channels. I've tested it for 'render result' now, with the idea that this can (optionally) replace the current inserting of tiles in the main result buffers. Especially with a lot of layers, the used memory for these buffers can easily go into the 100s of megs. Two other advantages: - all 'render result' layers can be saved entirely in a single file, for later use in compositing, also for animation output. - on each render, per scene, a unique temp file can be stored, allowing to re-use these temp files on starting Blender or loading files, showing the last result of a render command. The option is currently disabled, needs more work... but I had to commit this because of the rest of the work I did! -> Bug fix The Image node didn't call an execute event when browsing another image.
2006-02-18 13:28:44 +00:00
{
2012-06-13 17:27:49 +00:00
ExrHandle *data = (ExrHandle *)handle;
Header header(width, height);
ExrChannel *echan;
2012-06-13 17:27:49 +00:00
data->width = width;
data->height = height;
for (echan = (ExrChannel *)data->channels.first; echan; echan = echan->next)
header.channels().insert(echan->name, Channel(Imf::FLOAT));
openexr_header_compression(&header, compress);
// openexr_header_metadata(&header, ibuf); // no imbuf. cant write
/* header.lineOrder() = DECREASING_Y; this crashes in windows for file read! */
2012-06-13 17:27:49 +00:00
header.insert("BlenderMultiChannel", StringAttribute("Blender V2.55.1 and newer"));
2012-03-18 07:38:51 +00:00
/* avoid crash/abort when we don't have permission to write here */
try {
data->ofile = new OutputFile(filename, header);
}
catch (const std::exception &exc) {
std::cerr << "IMB_exr_begin_write: ERROR: " << exc.what() << std::endl;
data->ofile = NULL;
}
return (data->ofile != NULL);
}
void IMB_exrtile_begin_write(void *handle, const char *filename, int mipmap, int width, int height, int tilex, int tiley)
{
2012-06-13 17:27:49 +00:00
ExrHandle *data = (ExrHandle *)handle;
Header header(width, height);
ExrChannel *echan;
2012-06-13 17:27:49 +00:00
data->tilex = tilex;
data->tiley = tiley;
data->width = width;
data->height = height;
data->mipmap = mipmap;
for (echan = (ExrChannel *)data->channels.first; echan; echan = echan->next)
header.channels().insert(echan->name, Channel(Imf::FLOAT));
header.setTileDescription(TileDescription(tilex, tiley, (mipmap) ? MIPMAP_LEVELS : ONE_LEVEL));
header.lineOrder() = RANDOM_Y;
header.compression() = RLE_COMPRESSION;
2012-06-13 17:27:49 +00:00
header.insert("BlenderMultiChannel", StringAttribute("Blender V2.43"));
data->tofile = new TiledOutputFile(filename, header);
Four-in-one commit: (NOTE: new include dependency in Render module, might need MSVC update! It has to include the imbuf/intern/openexr/ directory in search path) -> New Composite node: "Hue Saturation". Works like the former 'post process' menu. There's no gamma, brightness or multiply needed in this node, for that the Curves Node functions better. -> Enabled Toolbox in Node editor This now also replaces the SHIFT+A for adding nodes. The nodes are automatically added to the menus, using the 'class' category from the type definition. Current classes are (compositor examples): Inputs: RenderResult, Image Outputs: Composite, Viewer Color Ops: RGB Curves, Mix, Hue Saturation, AlphaOver Vector Ops: Normal, Vector Curves, Map Value Filters: Filter, Blur, VectorBlur Convertors: ColorRamp, RGBtoBW, Separate RGBA, Separate HSVA, Set Alpha Generators: RGB, Value, Time Groups: the list of custom defined nodes -> OpenEXR tile saving support Created an API for for saving tile-based Images with an unlimited amount of layers/channels. I've tested it for 'render result' now, with the idea that this can (optionally) replace the current inserting of tiles in the main result buffers. Especially with a lot of layers, the used memory for these buffers can easily go into the 100s of megs. Two other advantages: - all 'render result' layers can be saved entirely in a single file, for later use in compositing, also for animation output. - on each render, per scene, a unique temp file can be stored, allowing to re-use these temp files on starting Blender or loading files, showing the last result of a render command. The option is currently disabled, needs more work... but I had to commit this because of the rest of the work I did! -> Bug fix The Image node didn't call an execute event when browsing another image.
2006-02-18 13:28:44 +00:00
}
/* read from file */
int IMB_exr_begin_read(void *handle, const char *filename, int *width, int *height)
{
2012-06-13 17:27:49 +00:00
ExrHandle *data = (ExrHandle *)handle;
if (BLI_exists(filename) && BLI_file_size(filename) > 32) { /* 32 is arbitrary, but zero length files crashes exr */
data->ifile = new InputFile(filename);
if (data->ifile) {
Box2i dw = data->ifile->header().dataWindow();
2012-06-13 17:27:49 +00:00
data->width = *width = dw.max.x - dw.min.x + 1;
data->height = *height = dw.max.y - dw.min.y + 1;
const ChannelList &channels = data->ifile->header().channels();
2012-06-13 17:27:49 +00:00
for (ChannelList::ConstIterator i = channels.begin(); i != channels.end(); ++i)
IMB_exr_add_channel(data, NULL, i.name(), 0, 0, NULL);
2012-06-13 17:27:49 +00:00
return 1;
}
}
return 0;
}
Four-in-one commit: (NOTE: new include dependency in Render module, might need MSVC update! It has to include the imbuf/intern/openexr/ directory in search path) -> New Composite node: "Hue Saturation". Works like the former 'post process' menu. There's no gamma, brightness or multiply needed in this node, for that the Curves Node functions better. -> Enabled Toolbox in Node editor This now also replaces the SHIFT+A for adding nodes. The nodes are automatically added to the menus, using the 'class' category from the type definition. Current classes are (compositor examples): Inputs: RenderResult, Image Outputs: Composite, Viewer Color Ops: RGB Curves, Mix, Hue Saturation, AlphaOver Vector Ops: Normal, Vector Curves, Map Value Filters: Filter, Blur, VectorBlur Convertors: ColorRamp, RGBtoBW, Separate RGBA, Separate HSVA, Set Alpha Generators: RGB, Value, Time Groups: the list of custom defined nodes -> OpenEXR tile saving support Created an API for for saving tile-based Images with an unlimited amount of layers/channels. I've tested it for 'render result' now, with the idea that this can (optionally) replace the current inserting of tiles in the main result buffers. Especially with a lot of layers, the used memory for these buffers can easily go into the 100s of megs. Two other advantages: - all 'render result' layers can be saved entirely in a single file, for later use in compositing, also for animation output. - on each render, per scene, a unique temp file can be stored, allowing to re-use these temp files on starting Blender or loading files, showing the last result of a render command. The option is currently disabled, needs more work... but I had to commit this because of the rest of the work I did! -> Bug fix The Image node didn't call an execute event when browsing another image.
2006-02-18 13:28:44 +00:00
/* still clumsy name handling, layers/channels can be ordered as list in list later */
void IMB_exr_set_channel(void *handle, const char *layname, const char *passname, int xstride, int ystride, float *rect)
Four-in-one commit: (NOTE: new include dependency in Render module, might need MSVC update! It has to include the imbuf/intern/openexr/ directory in search path) -> New Composite node: "Hue Saturation". Works like the former 'post process' menu. There's no gamma, brightness or multiply needed in this node, for that the Curves Node functions better. -> Enabled Toolbox in Node editor This now also replaces the SHIFT+A for adding nodes. The nodes are automatically added to the menus, using the 'class' category from the type definition. Current classes are (compositor examples): Inputs: RenderResult, Image Outputs: Composite, Viewer Color Ops: RGB Curves, Mix, Hue Saturation, AlphaOver Vector Ops: Normal, Vector Curves, Map Value Filters: Filter, Blur, VectorBlur Convertors: ColorRamp, RGBtoBW, Separate RGBA, Separate HSVA, Set Alpha Generators: RGB, Value, Time Groups: the list of custom defined nodes -> OpenEXR tile saving support Created an API for for saving tile-based Images with an unlimited amount of layers/channels. I've tested it for 'render result' now, with the idea that this can (optionally) replace the current inserting of tiles in the main result buffers. Especially with a lot of layers, the used memory for these buffers can easily go into the 100s of megs. Two other advantages: - all 'render result' layers can be saved entirely in a single file, for later use in compositing, also for animation output. - on each render, per scene, a unique temp file can be stored, allowing to re-use these temp files on starting Blender or loading files, showing the last result of a render command. The option is currently disabled, needs more work... but I had to commit this because of the rest of the work I did! -> Bug fix The Image node didn't call an execute event when browsing another image.
2006-02-18 13:28:44 +00:00
{
2012-06-13 17:27:49 +00:00
ExrHandle *data = (ExrHandle *)handle;
ExrChannel *echan;
char name[EXR_TOT_MAXNAME + 1];
2012-06-13 17:27:49 +00:00
if (layname) {
2012-06-13 17:27:49 +00:00
char lay[EXR_LAY_MAXNAME + 1], pass[EXR_PASS_MAXNAME + 1];
BLI_strncpy(lay, layname, EXR_LAY_MAXNAME);
BLI_strncpy(pass, passname, EXR_PASS_MAXNAME);
2012-06-13 17:27:49 +00:00
BLI_snprintf(name, sizeof(name), "%s.%s", lay, pass);
}
else
2012-06-13 17:27:49 +00:00
BLI_strncpy(name, passname, EXR_TOT_MAXNAME - 1);
2012-06-13 17:27:49 +00:00
echan = (ExrChannel *)BLI_findstring(&data->channels, name, offsetof(ExrChannel, name));
if (echan) {
2012-06-13 17:27:49 +00:00
echan->xstride = xstride;
echan->ystride = ystride;
echan->rect = rect;
Four-in-one commit: (NOTE: new include dependency in Render module, might need MSVC update! It has to include the imbuf/intern/openexr/ directory in search path) -> New Composite node: "Hue Saturation". Works like the former 'post process' menu. There's no gamma, brightness or multiply needed in this node, for that the Curves Node functions better. -> Enabled Toolbox in Node editor This now also replaces the SHIFT+A for adding nodes. The nodes are automatically added to the menus, using the 'class' category from the type definition. Current classes are (compositor examples): Inputs: RenderResult, Image Outputs: Composite, Viewer Color Ops: RGB Curves, Mix, Hue Saturation, AlphaOver Vector Ops: Normal, Vector Curves, Map Value Filters: Filter, Blur, VectorBlur Convertors: ColorRamp, RGBtoBW, Separate RGBA, Separate HSVA, Set Alpha Generators: RGB, Value, Time Groups: the list of custom defined nodes -> OpenEXR tile saving support Created an API for for saving tile-based Images with an unlimited amount of layers/channels. I've tested it for 'render result' now, with the idea that this can (optionally) replace the current inserting of tiles in the main result buffers. Especially with a lot of layers, the used memory for these buffers can easily go into the 100s of megs. Two other advantages: - all 'render result' layers can be saved entirely in a single file, for later use in compositing, also for animation output. - on each render, per scene, a unique temp file can be stored, allowing to re-use these temp files on starting Blender or loading files, showing the last result of a render command. The option is currently disabled, needs more work... but I had to commit this because of the rest of the work I did! -> Bug fix The Image node didn't call an execute event when browsing another image.
2006-02-18 13:28:44 +00:00
}
else
printf("IMB_exrtile_set_channel error %s\n", name);
Four-in-one commit: (NOTE: new include dependency in Render module, might need MSVC update! It has to include the imbuf/intern/openexr/ directory in search path) -> New Composite node: "Hue Saturation". Works like the former 'post process' menu. There's no gamma, brightness or multiply needed in this node, for that the Curves Node functions better. -> Enabled Toolbox in Node editor This now also replaces the SHIFT+A for adding nodes. The nodes are automatically added to the menus, using the 'class' category from the type definition. Current classes are (compositor examples): Inputs: RenderResult, Image Outputs: Composite, Viewer Color Ops: RGB Curves, Mix, Hue Saturation, AlphaOver Vector Ops: Normal, Vector Curves, Map Value Filters: Filter, Blur, VectorBlur Convertors: ColorRamp, RGBtoBW, Separate RGBA, Separate HSVA, Set Alpha Generators: RGB, Value, Time Groups: the list of custom defined nodes -> OpenEXR tile saving support Created an API for for saving tile-based Images with an unlimited amount of layers/channels. I've tested it for 'render result' now, with the idea that this can (optionally) replace the current inserting of tiles in the main result buffers. Especially with a lot of layers, the used memory for these buffers can easily go into the 100s of megs. Two other advantages: - all 'render result' layers can be saved entirely in a single file, for later use in compositing, also for animation output. - on each render, per scene, a unique temp file can be stored, allowing to re-use these temp files on starting Blender or loading files, showing the last result of a render command. The option is currently disabled, needs more work... but I had to commit this because of the rest of the work I did! -> Bug fix The Image node didn't call an execute event when browsing another image.
2006-02-18 13:28:44 +00:00
}
void IMB_exrtile_clear_channels(void *handle)
{
2012-06-13 17:27:49 +00:00
ExrHandle *data = (ExrHandle *)handle;
BLI_freelistN(&data->channels);
}
Four-in-one commit: (NOTE: new include dependency in Render module, might need MSVC update! It has to include the imbuf/intern/openexr/ directory in search path) -> New Composite node: "Hue Saturation". Works like the former 'post process' menu. There's no gamma, brightness or multiply needed in this node, for that the Curves Node functions better. -> Enabled Toolbox in Node editor This now also replaces the SHIFT+A for adding nodes. The nodes are automatically added to the menus, using the 'class' category from the type definition. Current classes are (compositor examples): Inputs: RenderResult, Image Outputs: Composite, Viewer Color Ops: RGB Curves, Mix, Hue Saturation, AlphaOver Vector Ops: Normal, Vector Curves, Map Value Filters: Filter, Blur, VectorBlur Convertors: ColorRamp, RGBtoBW, Separate RGBA, Separate HSVA, Set Alpha Generators: RGB, Value, Time Groups: the list of custom defined nodes -> OpenEXR tile saving support Created an API for for saving tile-based Images with an unlimited amount of layers/channels. I've tested it for 'render result' now, with the idea that this can (optionally) replace the current inserting of tiles in the main result buffers. Especially with a lot of layers, the used memory for these buffers can easily go into the 100s of megs. Two other advantages: - all 'render result' layers can be saved entirely in a single file, for later use in compositing, also for animation output. - on each render, per scene, a unique temp file can be stored, allowing to re-use these temp files on starting Blender or loading files, showing the last result of a render command. The option is currently disabled, needs more work... but I had to commit this because of the rest of the work I did! -> Bug fix The Image node didn't call an execute event when browsing another image.
2006-02-18 13:28:44 +00:00
void IMB_exrtile_write_channels(void *handle, int partx, int party, int level)
Four-in-one commit: (NOTE: new include dependency in Render module, might need MSVC update! It has to include the imbuf/intern/openexr/ directory in search path) -> New Composite node: "Hue Saturation". Works like the former 'post process' menu. There's no gamma, brightness or multiply needed in this node, for that the Curves Node functions better. -> Enabled Toolbox in Node editor This now also replaces the SHIFT+A for adding nodes. The nodes are automatically added to the menus, using the 'class' category from the type definition. Current classes are (compositor examples): Inputs: RenderResult, Image Outputs: Composite, Viewer Color Ops: RGB Curves, Mix, Hue Saturation, AlphaOver Vector Ops: Normal, Vector Curves, Map Value Filters: Filter, Blur, VectorBlur Convertors: ColorRamp, RGBtoBW, Separate RGBA, Separate HSVA, Set Alpha Generators: RGB, Value, Time Groups: the list of custom defined nodes -> OpenEXR tile saving support Created an API for for saving tile-based Images with an unlimited amount of layers/channels. I've tested it for 'render result' now, with the idea that this can (optionally) replace the current inserting of tiles in the main result buffers. Especially with a lot of layers, the used memory for these buffers can easily go into the 100s of megs. Two other advantages: - all 'render result' layers can be saved entirely in a single file, for later use in compositing, also for animation output. - on each render, per scene, a unique temp file can be stored, allowing to re-use these temp files on starting Blender or loading files, showing the last result of a render command. The option is currently disabled, needs more work... but I had to commit this because of the rest of the work I did! -> Bug fix The Image node didn't call an execute event when browsing another image.
2006-02-18 13:28:44 +00:00
{
2012-06-13 17:27:49 +00:00
ExrHandle *data = (ExrHandle *)handle;
Four-in-one commit: (NOTE: new include dependency in Render module, might need MSVC update! It has to include the imbuf/intern/openexr/ directory in search path) -> New Composite node: "Hue Saturation". Works like the former 'post process' menu. There's no gamma, brightness or multiply needed in this node, for that the Curves Node functions better. -> Enabled Toolbox in Node editor This now also replaces the SHIFT+A for adding nodes. The nodes are automatically added to the menus, using the 'class' category from the type definition. Current classes are (compositor examples): Inputs: RenderResult, Image Outputs: Composite, Viewer Color Ops: RGB Curves, Mix, Hue Saturation, AlphaOver Vector Ops: Normal, Vector Curves, Map Value Filters: Filter, Blur, VectorBlur Convertors: ColorRamp, RGBtoBW, Separate RGBA, Separate HSVA, Set Alpha Generators: RGB, Value, Time Groups: the list of custom defined nodes -> OpenEXR tile saving support Created an API for for saving tile-based Images with an unlimited amount of layers/channels. I've tested it for 'render result' now, with the idea that this can (optionally) replace the current inserting of tiles in the main result buffers. Especially with a lot of layers, the used memory for these buffers can easily go into the 100s of megs. Two other advantages: - all 'render result' layers can be saved entirely in a single file, for later use in compositing, also for animation output. - on each render, per scene, a unique temp file can be stored, allowing to re-use these temp files on starting Blender or loading files, showing the last result of a render command. The option is currently disabled, needs more work... but I had to commit this because of the rest of the work I did! -> Bug fix The Image node didn't call an execute event when browsing another image.
2006-02-18 13:28:44 +00:00
FrameBuffer frameBuffer;
ExrChannel *echan;
Four-in-one commit: (NOTE: new include dependency in Render module, might need MSVC update! It has to include the imbuf/intern/openexr/ directory in search path) -> New Composite node: "Hue Saturation". Works like the former 'post process' menu. There's no gamma, brightness or multiply needed in this node, for that the Curves Node functions better. -> Enabled Toolbox in Node editor This now also replaces the SHIFT+A for adding nodes. The nodes are automatically added to the menus, using the 'class' category from the type definition. Current classes are (compositor examples): Inputs: RenderResult, Image Outputs: Composite, Viewer Color Ops: RGB Curves, Mix, Hue Saturation, AlphaOver Vector Ops: Normal, Vector Curves, Map Value Filters: Filter, Blur, VectorBlur Convertors: ColorRamp, RGBtoBW, Separate RGBA, Separate HSVA, Set Alpha Generators: RGB, Value, Time Groups: the list of custom defined nodes -> OpenEXR tile saving support Created an API for for saving tile-based Images with an unlimited amount of layers/channels. I've tested it for 'render result' now, with the idea that this can (optionally) replace the current inserting of tiles in the main result buffers. Especially with a lot of layers, the used memory for these buffers can easily go into the 100s of megs. Two other advantages: - all 'render result' layers can be saved entirely in a single file, for later use in compositing, also for animation output. - on each render, per scene, a unique temp file can be stored, allowing to re-use these temp files on starting Blender or loading files, showing the last result of a render command. The option is currently disabled, needs more work... but I had to commit this because of the rest of the work I did! -> Bug fix The Image node didn't call an execute event when browsing another image.
2006-02-18 13:28:44 +00:00
2012-06-13 17:27:49 +00:00
for (echan = (ExrChannel *)data->channels.first; echan; echan = echan->next) {
float *rect = echan->rect - echan->xstride * partx - echan->ystride * party;
frameBuffer.insert(echan->name, Slice(Imf::FLOAT, (char *)rect,
echan->xstride * sizeof(float), echan->ystride * sizeof(float)));
Four-in-one commit: (NOTE: new include dependency in Render module, might need MSVC update! It has to include the imbuf/intern/openexr/ directory in search path) -> New Composite node: "Hue Saturation". Works like the former 'post process' menu. There's no gamma, brightness or multiply needed in this node, for that the Curves Node functions better. -> Enabled Toolbox in Node editor This now also replaces the SHIFT+A for adding nodes. The nodes are automatically added to the menus, using the 'class' category from the type definition. Current classes are (compositor examples): Inputs: RenderResult, Image Outputs: Composite, Viewer Color Ops: RGB Curves, Mix, Hue Saturation, AlphaOver Vector Ops: Normal, Vector Curves, Map Value Filters: Filter, Blur, VectorBlur Convertors: ColorRamp, RGBtoBW, Separate RGBA, Separate HSVA, Set Alpha Generators: RGB, Value, Time Groups: the list of custom defined nodes -> OpenEXR tile saving support Created an API for for saving tile-based Images with an unlimited amount of layers/channels. I've tested it for 'render result' now, with the idea that this can (optionally) replace the current inserting of tiles in the main result buffers. Especially with a lot of layers, the used memory for these buffers can easily go into the 100s of megs. Two other advantages: - all 'render result' layers can be saved entirely in a single file, for later use in compositing, also for animation output. - on each render, per scene, a unique temp file can be stored, allowing to re-use these temp files on starting Blender or loading files, showing the last result of a render command. The option is currently disabled, needs more work... but I had to commit this because of the rest of the work I did! -> Bug fix The Image node didn't call an execute event when browsing another image.
2006-02-18 13:28:44 +00:00
}
2012-06-13 17:27:49 +00:00
data->tofile->setFrameBuffer(frameBuffer);
try {
// printf("write tile %d %d\n", partx/data->tilex, party/data->tiley);
2012-06-13 17:27:49 +00:00
data->tofile->writeTile(partx / data->tilex, party / data->tiley, level);
}
catch (const std::exception &exc) {
std::cerr << "OpenEXR-writeTile: ERROR: " << exc.what() << std::endl;
}
Four-in-one commit: (NOTE: new include dependency in Render module, might need MSVC update! It has to include the imbuf/intern/openexr/ directory in search path) -> New Composite node: "Hue Saturation". Works like the former 'post process' menu. There's no gamma, brightness or multiply needed in this node, for that the Curves Node functions better. -> Enabled Toolbox in Node editor This now also replaces the SHIFT+A for adding nodes. The nodes are automatically added to the menus, using the 'class' category from the type definition. Current classes are (compositor examples): Inputs: RenderResult, Image Outputs: Composite, Viewer Color Ops: RGB Curves, Mix, Hue Saturation, AlphaOver Vector Ops: Normal, Vector Curves, Map Value Filters: Filter, Blur, VectorBlur Convertors: ColorRamp, RGBtoBW, Separate RGBA, Separate HSVA, Set Alpha Generators: RGB, Value, Time Groups: the list of custom defined nodes -> OpenEXR tile saving support Created an API for for saving tile-based Images with an unlimited amount of layers/channels. I've tested it for 'render result' now, with the idea that this can (optionally) replace the current inserting of tiles in the main result buffers. Especially with a lot of layers, the used memory for these buffers can easily go into the 100s of megs. Two other advantages: - all 'render result' layers can be saved entirely in a single file, for later use in compositing, also for animation output. - on each render, per scene, a unique temp file can be stored, allowing to re-use these temp files on starting Blender or loading files, showing the last result of a render command. The option is currently disabled, needs more work... but I had to commit this because of the rest of the work I did! -> Bug fix The Image node didn't call an execute event when browsing another image.
2006-02-18 13:28:44 +00:00
}
void IMB_exr_write_channels(void *handle)
Four-in-one commit: (NOTE: new include dependency in Render module, might need MSVC update! It has to include the imbuf/intern/openexr/ directory in search path) -> New Composite node: "Hue Saturation". Works like the former 'post process' menu. There's no gamma, brightness or multiply needed in this node, for that the Curves Node functions better. -> Enabled Toolbox in Node editor This now also replaces the SHIFT+A for adding nodes. The nodes are automatically added to the menus, using the 'class' category from the type definition. Current classes are (compositor examples): Inputs: RenderResult, Image Outputs: Composite, Viewer Color Ops: RGB Curves, Mix, Hue Saturation, AlphaOver Vector Ops: Normal, Vector Curves, Map Value Filters: Filter, Blur, VectorBlur Convertors: ColorRamp, RGBtoBW, Separate RGBA, Separate HSVA, Set Alpha Generators: RGB, Value, Time Groups: the list of custom defined nodes -> OpenEXR tile saving support Created an API for for saving tile-based Images with an unlimited amount of layers/channels. I've tested it for 'render result' now, with the idea that this can (optionally) replace the current inserting of tiles in the main result buffers. Especially with a lot of layers, the used memory for these buffers can easily go into the 100s of megs. Two other advantages: - all 'render result' layers can be saved entirely in a single file, for later use in compositing, also for animation output. - on each render, per scene, a unique temp file can be stored, allowing to re-use these temp files on starting Blender or loading files, showing the last result of a render command. The option is currently disabled, needs more work... but I had to commit this because of the rest of the work I did! -> Bug fix The Image node didn't call an execute event when browsing another image.
2006-02-18 13:28:44 +00:00
{
2012-06-13 17:27:49 +00:00
ExrHandle *data = (ExrHandle *)handle;
FrameBuffer frameBuffer;
ExrChannel *echan;
2012-06-13 17:27:49 +00:00
if (data->channels.first) {
2012-06-13 17:27:49 +00:00
for (echan = (ExrChannel *)data->channels.first; echan; echan = echan->next) {
/* last scanline, stride negative */
2012-06-13 17:27:49 +00:00
float *rect = echan->rect + echan->xstride * (data->height - 1) * data->width;
frameBuffer.insert(echan->name, Slice(Imf::FLOAT, (char *)rect,
echan->xstride * sizeof(float), -echan->ystride * sizeof(float)));
}
2012-06-13 17:27:49 +00:00
data->ofile->setFrameBuffer(frameBuffer);
try {
2012-06-13 17:27:49 +00:00
data->ofile->writePixels(data->height);
}
catch (const std::exception &exc) {
std::cerr << "OpenEXR-writePixels: ERROR: " << exc.what() << std::endl;
}
}
else {
printf("Error: attempt to save MultiLayer without layers.\n");
}
}
void IMB_exr_read_channels(void *handle)
{
2012-06-13 17:27:49 +00:00
ExrHandle *data = (ExrHandle *)handle;
FrameBuffer frameBuffer;
ExrChannel *echan;
2012-06-13 17:27:49 +00:00
/* check if exr was saved with previous versions of blender which flipped images */
const StringAttribute *ta = data->ifile->header().findTypedAttribute <StringAttribute> ("BlenderMultiChannel");
2012-06-13 17:27:49 +00:00
short flip = (ta && strncmp(ta->value().c_str(), "Blender V2.43", 13) == 0); /* 'previous multilayer attribute, flipped */
for (echan = (ExrChannel *)data->channels.first; echan; echan = echan->next) {
if (echan->rect) {
if (flip)
2012-06-13 17:27:49 +00:00
frameBuffer.insert(echan->name, Slice(Imf::FLOAT, (char *)echan->rect,
echan->xstride * sizeof(float), echan->ystride * sizeof(float)));
else
2012-06-13 17:27:49 +00:00
frameBuffer.insert(echan->name, Slice(Imf::FLOAT, (char *)(echan->rect + echan->xstride * (data->height - 1) * data->width),
echan->xstride * sizeof(float), -echan->ystride * sizeof(float)));
}
2012-06-13 17:27:49 +00:00
else
printf("warning, channel with no rect set %s\n", echan->name);
}
2012-06-13 17:27:49 +00:00
data->ifile->setFrameBuffer(frameBuffer);
try {
2012-06-13 17:27:49 +00:00
data->ifile->readPixels(0, data->height - 1);
}
catch (const std::exception &exc) {
std::cerr << "OpenEXR-readPixels: ERROR: " << exc.what() << std::endl;
}
}
2012-06-13 17:27:49 +00:00
void IMB_exr_multilayer_convert(void *handle, void *base,
void * (*addlayer)(void *base, char *str),
void (*addpass)(void *base, void *lay, char *str,
float *rect, int totchan, char *chan_id))
{
2012-06-13 17:27:49 +00:00
ExrHandle *data = (ExrHandle *)handle;
ExrLayer *lay;
ExrPass *pass;
2012-06-13 17:27:49 +00:00
if (data->layers.first == NULL) {
printf("cannot convert multilayer, no layers in handle\n");
return;
}
2012-06-13 17:27:49 +00:00
for (lay = (ExrLayer *)data->layers.first; lay; lay = lay->next) {
void *laybase = addlayer(base, lay->name);
if (laybase) {
2012-06-13 17:27:49 +00:00
for (pass = (ExrPass *)lay->passes.first; pass; pass = pass->next) {
addpass(base, laybase, pass->name, pass->rect, pass->totchan, pass->chan_id);
2012-06-13 17:27:49 +00:00
pass->rect = NULL;
}
}
}
}
void IMB_exr_close(void *handle)
{
2012-06-13 17:27:49 +00:00
ExrHandle *data = (ExrHandle *)handle;
ExrLayer *lay;
ExrPass *pass;
2012-06-13 17:27:49 +00:00
if (data->ifile)
delete data->ifile;
else if (data->ofile)
delete data->ofile;
else if (data->tofile)
delete data->tofile;
2012-06-13 17:27:49 +00:00
data->ifile = NULL;
data->ofile = NULL;
data->tofile = NULL;
Four-in-one commit: (NOTE: new include dependency in Render module, might need MSVC update! It has to include the imbuf/intern/openexr/ directory in search path) -> New Composite node: "Hue Saturation". Works like the former 'post process' menu. There's no gamma, brightness or multiply needed in this node, for that the Curves Node functions better. -> Enabled Toolbox in Node editor This now also replaces the SHIFT+A for adding nodes. The nodes are automatically added to the menus, using the 'class' category from the type definition. Current classes are (compositor examples): Inputs: RenderResult, Image Outputs: Composite, Viewer Color Ops: RGB Curves, Mix, Hue Saturation, AlphaOver Vector Ops: Normal, Vector Curves, Map Value Filters: Filter, Blur, VectorBlur Convertors: ColorRamp, RGBtoBW, Separate RGBA, Separate HSVA, Set Alpha Generators: RGB, Value, Time Groups: the list of custom defined nodes -> OpenEXR tile saving support Created an API for for saving tile-based Images with an unlimited amount of layers/channels. I've tested it for 'render result' now, with the idea that this can (optionally) replace the current inserting of tiles in the main result buffers. Especially with a lot of layers, the used memory for these buffers can easily go into the 100s of megs. Two other advantages: - all 'render result' layers can be saved entirely in a single file, for later use in compositing, also for animation output. - on each render, per scene, a unique temp file can be stored, allowing to re-use these temp files on starting Blender or loading files, showing the last result of a render command. The option is currently disabled, needs more work... but I had to commit this because of the rest of the work I did! -> Bug fix The Image node didn't call an execute event when browsing another image.
2006-02-18 13:28:44 +00:00
BLI_freelistN(&data->channels);
2012-06-13 17:27:49 +00:00
for (lay = (ExrLayer *)data->layers.first; lay; lay = lay->next) {
for (pass = (ExrPass *)lay->passes.first; pass; pass = pass->next)
if (pass->rect)
MEM_freeN(pass->rect);
BLI_freelistN(&lay->passes);
}
BLI_freelistN(&data->layers);
2012-06-13 17:27:49 +00:00
BLI_remlink(&exrhandles, data);
MEM_freeN(data);
}
/* ********* */
A couple more changes to the file and image nodes to improve access to layers that don't follow Blender's rlayer.rpass naming scheme. --- Changes to File Output node --- * Flat layer names in EXR multilayer files. For a socket with name "AAA" the previous resulting EXR layer name would be "AAA.AAA", i.e. the render layer as well as render pass would use the socket name. Now the "render_layer.render_pass" scheme is ignored in multilayer files, socket names are directly written to EXR layers (EXR layer name is "AAA" in this example). If sockets should have a notion of "render layer" this can still be achieved by explicitly adding a separator, e.g. "AAA.BBB". When loading such layers into a Blender Image struct, the name is interpreted as a "render_layer.render_pass" again (although the image node does not care about it, see below). * Socket sub-paths (for singlelayer) or layer names (for multilayer) are stored in dedicated string variables in the socket storage data. This way the RNA can define precise string subtypes (PROP_FILEPATH) and length. The file/layer slots are defined as separate structs with own name properties in the RNA as well, so they can be used nicely with the list template. * Ensure unique socket paths/layer names to prevent overwriting of files and layers respectively. --- Changes to Image node --- * Loading multilayer OpenEXR files has improved layer name splitting into render layer + render pass names now. This properly supports arbitrary EXR layer names now. Example: OpenEXR layer name: AAA.BBB.CCC is split into Render layer name: AAA.BBB Render pass name: CCC If the layer name has no '.' separators the render layer name is empty. * Image node ignores the selected render layer in the image user data. Instead all existing layers are displayed at the same time by combining the render layer names with render pass names again, to reconstruct the original EXR layer name. This avoids the problem that render layers with empty name are not selectetable in the dropdown and allows using all image layers at the same time without duplicating the node.
2012-05-11 08:06:01 +00:00
/* get a substring from the end of the name, separated by '.' */
static int imb_exr_split_token(const char *str, const char *end, const char **token)
{
2012-06-13 17:27:49 +00:00
int maxlen = end - str;
A couple more changes to the file and image nodes to improve access to layers that don't follow Blender's rlayer.rpass naming scheme. --- Changes to File Output node --- * Flat layer names in EXR multilayer files. For a socket with name "AAA" the previous resulting EXR layer name would be "AAA.AAA", i.e. the render layer as well as render pass would use the socket name. Now the "render_layer.render_pass" scheme is ignored in multilayer files, socket names are directly written to EXR layers (EXR layer name is "AAA" in this example). If sockets should have a notion of "render layer" this can still be achieved by explicitly adding a separator, e.g. "AAA.BBB". When loading such layers into a Blender Image struct, the name is interpreted as a "render_layer.render_pass" again (although the image node does not care about it, see below). * Socket sub-paths (for singlelayer) or layer names (for multilayer) are stored in dedicated string variables in the socket storage data. This way the RNA can define precise string subtypes (PROP_FILEPATH) and length. The file/layer slots are defined as separate structs with own name properties in the RNA as well, so they can be used nicely with the list template. * Ensure unique socket paths/layer names to prevent overwriting of files and layers respectively. --- Changes to Image node --- * Loading multilayer OpenEXR files has improved layer name splitting into render layer + render pass names now. This properly supports arbitrary EXR layer names now. Example: OpenEXR layer name: AAA.BBB.CCC is split into Render layer name: AAA.BBB Render pass name: CCC If the layer name has no '.' separators the render layer name is empty. * Image node ignores the selected render layer in the image user data. Instead all existing layers are displayed at the same time by combining the render layer names with render pass names again, to reconstruct the original EXR layer name. This avoids the problem that render layers with empty name are not selectetable in the dropdown and allows using all image layers at the same time without duplicating the node.
2012-05-11 08:06:01 +00:00
int len = 0;
2012-06-13 17:27:49 +00:00
while (len < maxlen && *(end - len - 1) != '.')
A couple more changes to the file and image nodes to improve access to layers that don't follow Blender's rlayer.rpass naming scheme. --- Changes to File Output node --- * Flat layer names in EXR multilayer files. For a socket with name "AAA" the previous resulting EXR layer name would be "AAA.AAA", i.e. the render layer as well as render pass would use the socket name. Now the "render_layer.render_pass" scheme is ignored in multilayer files, socket names are directly written to EXR layers (EXR layer name is "AAA" in this example). If sockets should have a notion of "render layer" this can still be achieved by explicitly adding a separator, e.g. "AAA.BBB". When loading such layers into a Blender Image struct, the name is interpreted as a "render_layer.render_pass" again (although the image node does not care about it, see below). * Socket sub-paths (for singlelayer) or layer names (for multilayer) are stored in dedicated string variables in the socket storage data. This way the RNA can define precise string subtypes (PROP_FILEPATH) and length. The file/layer slots are defined as separate structs with own name properties in the RNA as well, so they can be used nicely with the list template. * Ensure unique socket paths/layer names to prevent overwriting of files and layers respectively. --- Changes to Image node --- * Loading multilayer OpenEXR files has improved layer name splitting into render layer + render pass names now. This properly supports arbitrary EXR layer names now. Example: OpenEXR layer name: AAA.BBB.CCC is split into Render layer name: AAA.BBB Render pass name: CCC If the layer name has no '.' separators the render layer name is empty. * Image node ignores the selected render layer in the image user data. Instead all existing layers are displayed at the same time by combining the render layer names with render pass names again, to reconstruct the original EXR layer name. This avoids the problem that render layers with empty name are not selectetable in the dropdown and allows using all image layers at the same time without duplicating the node.
2012-05-11 08:06:01 +00:00
++len;
2012-06-13 17:27:49 +00:00
*token = end - len;
A couple more changes to the file and image nodes to improve access to layers that don't follow Blender's rlayer.rpass naming scheme. --- Changes to File Output node --- * Flat layer names in EXR multilayer files. For a socket with name "AAA" the previous resulting EXR layer name would be "AAA.AAA", i.e. the render layer as well as render pass would use the socket name. Now the "render_layer.render_pass" scheme is ignored in multilayer files, socket names are directly written to EXR layers (EXR layer name is "AAA" in this example). If sockets should have a notion of "render layer" this can still be achieved by explicitly adding a separator, e.g. "AAA.BBB". When loading such layers into a Blender Image struct, the name is interpreted as a "render_layer.render_pass" again (although the image node does not care about it, see below). * Socket sub-paths (for singlelayer) or layer names (for multilayer) are stored in dedicated string variables in the socket storage data. This way the RNA can define precise string subtypes (PROP_FILEPATH) and length. The file/layer slots are defined as separate structs with own name properties in the RNA as well, so they can be used nicely with the list template. * Ensure unique socket paths/layer names to prevent overwriting of files and layers respectively. --- Changes to Image node --- * Loading multilayer OpenEXR files has improved layer name splitting into render layer + render pass names now. This properly supports arbitrary EXR layer names now. Example: OpenEXR layer name: AAA.BBB.CCC is split into Render layer name: AAA.BBB Render pass name: CCC If the layer name has no '.' separators the render layer name is empty. * Image node ignores the selected render layer in the image user data. Instead all existing layers are displayed at the same time by combining the render layer names with render pass names again, to reconstruct the original EXR layer name. This avoids the problem that render layers with empty name are not selectetable in the dropdown and allows using all image layers at the same time without duplicating the node.
2012-05-11 08:06:01 +00:00
return len;
}
static int imb_exr_split_channel_name(ExrChannel *echan, char *layname, char *passname)
{
const char *name = echan->name;
const char *end = name + strlen(name);
const char *token;
char tokenbuf[EXR_TOT_MAXNAME];
int len;
2012-06-13 17:27:49 +00:00
A couple more changes to the file and image nodes to improve access to layers that don't follow Blender's rlayer.rpass naming scheme. --- Changes to File Output node --- * Flat layer names in EXR multilayer files. For a socket with name "AAA" the previous resulting EXR layer name would be "AAA.AAA", i.e. the render layer as well as render pass would use the socket name. Now the "render_layer.render_pass" scheme is ignored in multilayer files, socket names are directly written to EXR layers (EXR layer name is "AAA" in this example). If sockets should have a notion of "render layer" this can still be achieved by explicitly adding a separator, e.g. "AAA.BBB". When loading such layers into a Blender Image struct, the name is interpreted as a "render_layer.render_pass" again (although the image node does not care about it, see below). * Socket sub-paths (for singlelayer) or layer names (for multilayer) are stored in dedicated string variables in the socket storage data. This way the RNA can define precise string subtypes (PROP_FILEPATH) and length. The file/layer slots are defined as separate structs with own name properties in the RNA as well, so they can be used nicely with the list template. * Ensure unique socket paths/layer names to prevent overwriting of files and layers respectively. --- Changes to Image node --- * Loading multilayer OpenEXR files has improved layer name splitting into render layer + render pass names now. This properly supports arbitrary EXR layer names now. Example: OpenEXR layer name: AAA.BBB.CCC is split into Render layer name: AAA.BBB Render pass name: CCC If the layer name has no '.' separators the render layer name is empty. * Image node ignores the selected render layer in the image user data. Instead all existing layers are displayed at the same time by combining the render layer names with render pass names again, to reconstruct the original EXR layer name. This avoids the problem that render layers with empty name are not selectetable in the dropdown and allows using all image layers at the same time without duplicating the node.
2012-05-11 08:06:01 +00:00
/* last token is single character channel identifier */
len = imb_exr_split_token(name, end, &token);
if (len == 0) {
printf("multilayer read: bad channel name: %s\n", name);
return 0;
}
A couple more changes to the file and image nodes to improve access to layers that don't follow Blender's rlayer.rpass naming scheme. --- Changes to File Output node --- * Flat layer names in EXR multilayer files. For a socket with name "AAA" the previous resulting EXR layer name would be "AAA.AAA", i.e. the render layer as well as render pass would use the socket name. Now the "render_layer.render_pass" scheme is ignored in multilayer files, socket names are directly written to EXR layers (EXR layer name is "AAA" in this example). If sockets should have a notion of "render layer" this can still be achieved by explicitly adding a separator, e.g. "AAA.BBB". When loading such layers into a Blender Image struct, the name is interpreted as a "render_layer.render_pass" again (although the image node does not care about it, see below). * Socket sub-paths (for singlelayer) or layer names (for multilayer) are stored in dedicated string variables in the socket storage data. This way the RNA can define precise string subtypes (PROP_FILEPATH) and length. The file/layer slots are defined as separate structs with own name properties in the RNA as well, so they can be used nicely with the list template. * Ensure unique socket paths/layer names to prevent overwriting of files and layers respectively. --- Changes to Image node --- * Loading multilayer OpenEXR files has improved layer name splitting into render layer + render pass names now. This properly supports arbitrary EXR layer names now. Example: OpenEXR layer name: AAA.BBB.CCC is split into Render layer name: AAA.BBB Render pass name: CCC If the layer name has no '.' separators the render layer name is empty. * Image node ignores the selected render layer in the image user data. Instead all existing layers are displayed at the same time by combining the render layer names with render pass names again, to reconstruct the original EXR layer name. This avoids the problem that render layers with empty name are not selectetable in the dropdown and allows using all image layers at the same time without duplicating the node.
2012-05-11 08:06:01 +00:00
else if (len > 1) {
BLI_strncpy(tokenbuf, token, len);
printf("multilayer read: channel token too long: %s\n", tokenbuf);
return 0;
}
A couple more changes to the file and image nodes to improve access to layers that don't follow Blender's rlayer.rpass naming scheme. --- Changes to File Output node --- * Flat layer names in EXR multilayer files. For a socket with name "AAA" the previous resulting EXR layer name would be "AAA.AAA", i.e. the render layer as well as render pass would use the socket name. Now the "render_layer.render_pass" scheme is ignored in multilayer files, socket names are directly written to EXR layers (EXR layer name is "AAA" in this example). If sockets should have a notion of "render layer" this can still be achieved by explicitly adding a separator, e.g. "AAA.BBB". When loading such layers into a Blender Image struct, the name is interpreted as a "render_layer.render_pass" again (although the image node does not care about it, see below). * Socket sub-paths (for singlelayer) or layer names (for multilayer) are stored in dedicated string variables in the socket storage data. This way the RNA can define precise string subtypes (PROP_FILEPATH) and length. The file/layer slots are defined as separate structs with own name properties in the RNA as well, so they can be used nicely with the list template. * Ensure unique socket paths/layer names to prevent overwriting of files and layers respectively. --- Changes to Image node --- * Loading multilayer OpenEXR files has improved layer name splitting into render layer + render pass names now. This properly supports arbitrary EXR layer names now. Example: OpenEXR layer name: AAA.BBB.CCC is split into Render layer name: AAA.BBB Render pass name: CCC If the layer name has no '.' separators the render layer name is empty. * Image node ignores the selected render layer in the image user data. Instead all existing layers are displayed at the same time by combining the render layer names with render pass names again, to reconstruct the original EXR layer name. This avoids the problem that render layers with empty name are not selectetable in the dropdown and allows using all image layers at the same time without duplicating the node.
2012-05-11 08:06:01 +00:00
echan->chan_id = token[0];
2012-06-13 17:27:49 +00:00
end -= len + 1; /* +1 to skip '.' separator */
A couple more changes to the file and image nodes to improve access to layers that don't follow Blender's rlayer.rpass naming scheme. --- Changes to File Output node --- * Flat layer names in EXR multilayer files. For a socket with name "AAA" the previous resulting EXR layer name would be "AAA.AAA", i.e. the render layer as well as render pass would use the socket name. Now the "render_layer.render_pass" scheme is ignored in multilayer files, socket names are directly written to EXR layers (EXR layer name is "AAA" in this example). If sockets should have a notion of "render layer" this can still be achieved by explicitly adding a separator, e.g. "AAA.BBB". When loading such layers into a Blender Image struct, the name is interpreted as a "render_layer.render_pass" again (although the image node does not care about it, see below). * Socket sub-paths (for singlelayer) or layer names (for multilayer) are stored in dedicated string variables in the socket storage data. This way the RNA can define precise string subtypes (PROP_FILEPATH) and length. The file/layer slots are defined as separate structs with own name properties in the RNA as well, so they can be used nicely with the list template. * Ensure unique socket paths/layer names to prevent overwriting of files and layers respectively. --- Changes to Image node --- * Loading multilayer OpenEXR files has improved layer name splitting into render layer + render pass names now. This properly supports arbitrary EXR layer names now. Example: OpenEXR layer name: AAA.BBB.CCC is split into Render layer name: AAA.BBB Render pass name: CCC If the layer name has no '.' separators the render layer name is empty. * Image node ignores the selected render layer in the image user data. Instead all existing layers are displayed at the same time by combining the render layer names with render pass names again, to reconstruct the original EXR layer name. This avoids the problem that render layers with empty name are not selectetable in the dropdown and allows using all image layers at the same time without duplicating the node.
2012-05-11 08:06:01 +00:00
/* second token is pass name */
len = imb_exr_split_token(name, end, &token);
if (len == 0) {
printf("multilayer read: bad channel name: %s\n", name);
return 0;
}
2012-06-13 17:27:49 +00:00
BLI_strncpy(passname, token, len + 1);
end -= len + 1; /* +1 to skip '.' separator */
A couple more changes to the file and image nodes to improve access to layers that don't follow Blender's rlayer.rpass naming scheme. --- Changes to File Output node --- * Flat layer names in EXR multilayer files. For a socket with name "AAA" the previous resulting EXR layer name would be "AAA.AAA", i.e. the render layer as well as render pass would use the socket name. Now the "render_layer.render_pass" scheme is ignored in multilayer files, socket names are directly written to EXR layers (EXR layer name is "AAA" in this example). If sockets should have a notion of "render layer" this can still be achieved by explicitly adding a separator, e.g. "AAA.BBB". When loading such layers into a Blender Image struct, the name is interpreted as a "render_layer.render_pass" again (although the image node does not care about it, see below). * Socket sub-paths (for singlelayer) or layer names (for multilayer) are stored in dedicated string variables in the socket storage data. This way the RNA can define precise string subtypes (PROP_FILEPATH) and length. The file/layer slots are defined as separate structs with own name properties in the RNA as well, so they can be used nicely with the list template. * Ensure unique socket paths/layer names to prevent overwriting of files and layers respectively. --- Changes to Image node --- * Loading multilayer OpenEXR files has improved layer name splitting into render layer + render pass names now. This properly supports arbitrary EXR layer names now. Example: OpenEXR layer name: AAA.BBB.CCC is split into Render layer name: AAA.BBB Render pass name: CCC If the layer name has no '.' separators the render layer name is empty. * Image node ignores the selected render layer in the image user data. Instead all existing layers are displayed at the same time by combining the render layer names with render pass names again, to reconstruct the original EXR layer name. This avoids the problem that render layers with empty name are not selectetable in the dropdown and allows using all image layers at the same time without duplicating the node.
2012-05-11 08:06:01 +00:00
/* all preceding tokens combined as layer name */
if (end > name)
2012-06-13 17:27:49 +00:00
BLI_strncpy(layname, name, (int)(end - name) + 1);
A couple more changes to the file and image nodes to improve access to layers that don't follow Blender's rlayer.rpass naming scheme. --- Changes to File Output node --- * Flat layer names in EXR multilayer files. For a socket with name "AAA" the previous resulting EXR layer name would be "AAA.AAA", i.e. the render layer as well as render pass would use the socket name. Now the "render_layer.render_pass" scheme is ignored in multilayer files, socket names are directly written to EXR layers (EXR layer name is "AAA" in this example). If sockets should have a notion of "render layer" this can still be achieved by explicitly adding a separator, e.g. "AAA.BBB". When loading such layers into a Blender Image struct, the name is interpreted as a "render_layer.render_pass" again (although the image node does not care about it, see below). * Socket sub-paths (for singlelayer) or layer names (for multilayer) are stored in dedicated string variables in the socket storage data. This way the RNA can define precise string subtypes (PROP_FILEPATH) and length. The file/layer slots are defined as separate structs with own name properties in the RNA as well, so they can be used nicely with the list template. * Ensure unique socket paths/layer names to prevent overwriting of files and layers respectively. --- Changes to Image node --- * Loading multilayer OpenEXR files has improved layer name splitting into render layer + render pass names now. This properly supports arbitrary EXR layer names now. Example: OpenEXR layer name: AAA.BBB.CCC is split into Render layer name: AAA.BBB Render pass name: CCC If the layer name has no '.' separators the render layer name is empty. * Image node ignores the selected render layer in the image user data. Instead all existing layers are displayed at the same time by combining the render layer names with render pass names again, to reconstruct the original EXR layer name. This avoids the problem that render layers with empty name are not selectetable in the dropdown and allows using all image layers at the same time without duplicating the node.
2012-05-11 08:06:01 +00:00
else
layname[0] = '\0';
2012-06-13 17:27:49 +00:00
return 1;
}
static ExrLayer *imb_exr_get_layer(ListBase *lb, char *layname)
{
2012-06-13 17:27:49 +00:00
ExrLayer *lay = (ExrLayer *)BLI_findstring(lb, layname, offsetof(ExrLayer, name));
2012-06-13 17:27:49 +00:00
if (lay == NULL) {
lay = (ExrLayer *)MEM_callocN(sizeof(ExrLayer), "exr layer");
BLI_addtail(lb, lay);
BLI_strncpy(lay->name, layname, EXR_LAY_MAXNAME);
}
return lay;
}
static ExrPass *imb_exr_get_pass(ListBase *lb, char *passname)
{
2012-06-13 17:27:49 +00:00
ExrPass *pass = (ExrPass *)BLI_findstring(lb, passname, offsetof(ExrPass, name));
2012-06-13 17:27:49 +00:00
if (pass == NULL) {
pass = (ExrPass *)MEM_callocN(sizeof(ExrPass), "exr pass");
if (strcmp(passname, "Combined") == 0)
BLI_addhead(lb, pass);
else
BLI_addtail(lb, pass);
}
BLI_strncpy(pass->name, passname, EXR_LAY_MAXNAME);
2012-06-13 17:27:49 +00:00
return pass;
}
/* creates channels, makes a hierarchy and assigns memory to channels */
static ExrHandle *imb_exr_begin_read_mem(InputFile *file, int width, int height)
{
ExrLayer *lay;
ExrPass *pass;
ExrChannel *echan;
2012-06-13 17:27:49 +00:00
ExrHandle *data = (ExrHandle *)IMB_exr_get_handle();
int a;
char layname[EXR_TOT_MAXNAME], passname[EXR_TOT_MAXNAME];
2012-06-13 17:27:49 +00:00
data->ifile = file;
data->width = width;
data->height = height;
const ChannelList &channels = data->ifile->header().channels();
for (ChannelList::ConstIterator i = channels.begin(); i != channels.end(); ++i)
IMB_exr_add_channel(data, NULL, i.name(), 0, 0, NULL);
2012-06-13 17:27:49 +00:00
/* now try to sort out how to assign memory to the channels */
/* first build hierarchical layer list */
2012-06-13 17:27:49 +00:00
for (echan = (ExrChannel *)data->channels.first; echan; echan = echan->next) {
if (imb_exr_split_channel_name(echan, layname, passname) ) {
ExrLayer *lay = imb_exr_get_layer(&data->layers, layname);
ExrPass *pass = imb_exr_get_pass(&lay->passes, passname);
pass->chan[pass->totchan] = echan;
pass->totchan++;
2012-06-13 17:27:49 +00:00
if (pass->totchan >= EXR_PASS_MAXCHAN)
break;
}
}
if (echan) {
printf("error, too many channels in one pass: %s\n", echan->name);
IMB_exr_close(data);
return NULL;
}
2012-06-13 17:27:49 +00:00
/* with some heuristics, try to merge the channels in buffers */
2012-06-13 17:27:49 +00:00
for (lay = (ExrLayer *)data->layers.first; lay; lay = lay->next) {
for (pass = (ExrPass *)lay->passes.first; pass; pass = pass->next) {
if (pass->totchan) {
2012-06-13 17:27:49 +00:00
pass->rect = (float *)MEM_mapallocN(width * height * pass->totchan * sizeof(float), "pass rect");
if (pass->totchan == 1) {
echan = pass->chan[0];
echan->rect = pass->rect;
echan->xstride = 1;
echan->ystride = width;
pass->chan_id[0] = echan->chan_id;
}
else {
char lookup[256];
2012-06-13 17:27:49 +00:00
memset(lookup, 0, sizeof(lookup));
2012-06-13 17:27:49 +00:00
/* we can have RGB(A), XYZ(W), UVA */
2012-06-13 17:27:49 +00:00
if (pass->totchan == 3 || pass->totchan == 4) {
if (pass->chan[0]->chan_id == 'B' || pass->chan[1]->chan_id == 'B' || pass->chan[2]->chan_id == 'B') {
lookup[(unsigned int)'R'] = 0;
lookup[(unsigned int)'G'] = 1;
lookup[(unsigned int)'B'] = 2;
lookup[(unsigned int)'A'] = 3;
}
2012-06-13 17:27:49 +00:00
else if (pass->chan[0]->chan_id == 'Y' || pass->chan[1]->chan_id == 'Y' || pass->chan[2]->chan_id == 'Y') {
lookup[(unsigned int)'X'] = 0;
lookup[(unsigned int)'Y'] = 1;
lookup[(unsigned int)'Z'] = 2;
lookup[(unsigned int)'W'] = 3;
}
else {
2012-06-13 17:27:49 +00:00
lookup[(unsigned int)'U'] = 0;
lookup[(unsigned int)'V'] = 1;
lookup[(unsigned int)'A'] = 2;
}
2012-06-13 17:27:49 +00:00
for (a = 0; a < pass->totchan; a++) {
echan = pass->chan[a];
echan->rect = pass->rect + lookup[(unsigned int)echan->chan_id];
echan->xstride = pass->totchan;
echan->ystride = width * pass->totchan;
pass->chan_id[(unsigned int)lookup[(unsigned int)echan->chan_id]] = echan->chan_id;
}
}
else { /* unknown */
2012-06-13 17:27:49 +00:00
for (a = 0; a < pass->totchan; a++) {
echan = pass->chan[a];
echan->rect = pass->rect + a;
echan->xstride = pass->totchan;
echan->ystride = width * pass->totchan;
pass->chan_id[a] = echan->chan_id;
}
}
}
}
}
}
2012-06-13 17:27:49 +00:00
return data;
Four-in-one commit: (NOTE: new include dependency in Render module, might need MSVC update! It has to include the imbuf/intern/openexr/ directory in search path) -> New Composite node: "Hue Saturation". Works like the former 'post process' menu. There's no gamma, brightness or multiply needed in this node, for that the Curves Node functions better. -> Enabled Toolbox in Node editor This now also replaces the SHIFT+A for adding nodes. The nodes are automatically added to the menus, using the 'class' category from the type definition. Current classes are (compositor examples): Inputs: RenderResult, Image Outputs: Composite, Viewer Color Ops: RGB Curves, Mix, Hue Saturation, AlphaOver Vector Ops: Normal, Vector Curves, Map Value Filters: Filter, Blur, VectorBlur Convertors: ColorRamp, RGBtoBW, Separate RGBA, Separate HSVA, Set Alpha Generators: RGB, Value, Time Groups: the list of custom defined nodes -> OpenEXR tile saving support Created an API for for saving tile-based Images with an unlimited amount of layers/channels. I've tested it for 'render result' now, with the idea that this can (optionally) replace the current inserting of tiles in the main result buffers. Especially with a lot of layers, the used memory for these buffers can easily go into the 100s of megs. Two other advantages: - all 'render result' layers can be saved entirely in a single file, for later use in compositing, also for animation output. - on each render, per scene, a unique temp file can be stored, allowing to re-use these temp files on starting Blender or loading files, showing the last result of a render command. The option is currently disabled, needs more work... but I had to commit this because of the rest of the work I did! -> Bug fix The Image node didn't call an execute event when browsing another image.
2006-02-18 13:28:44 +00:00
}
/* ********************************************************* */
2012-06-06 22:38:39 +00:00
typedef struct RGBA {
float r;
float g;
float b;
float a;
} RGBA;
/* debug only */
static void exr_print_filecontents(InputFile *file)
{
const ChannelList &channels = file->header().channels();
2012-06-13 17:27:49 +00:00
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);
}
}
/* for non-multilayer, map R G B A channel names to something that's in this file */
static const char *exr_rgba_channelname(InputFile *file, const char *chan)
{
const ChannelList &channels = file->header().channels();
2012-06-13 17:27:49 +00:00
for (ChannelList::ConstIterator i = channels.begin(); i != channels.end(); ++i) {
/* const Channel &channel = i.channel(); */ /* Not used yet */
2012-06-13 17:27:49 +00:00
const char *str = i.name();
int len = strlen(str);
if (len) {
2012-06-13 17:27:49 +00:00
if (BLI_strcasecmp(chan, str + len - 1) == 0) {
return str;
}
}
}
return chan;
}
static int exr_has_zbuffer(InputFile *file)
{
return !(file->header().channels().findChannel("Z") == NULL);
}
static int exr_is_multilayer(InputFile *file)
Four-in-one commit: (NOTE: new include dependency in Render module, might need MSVC update! It has to include the imbuf/intern/openexr/ directory in search path) -> New Composite node: "Hue Saturation". Works like the former 'post process' menu. There's no gamma, brightness or multiply needed in this node, for that the Curves Node functions better. -> Enabled Toolbox in Node editor This now also replaces the SHIFT+A for adding nodes. The nodes are automatically added to the menus, using the 'class' category from the type definition. Current classes are (compositor examples): Inputs: RenderResult, Image Outputs: Composite, Viewer Color Ops: RGB Curves, Mix, Hue Saturation, AlphaOver Vector Ops: Normal, Vector Curves, Map Value Filters: Filter, Blur, VectorBlur Convertors: ColorRamp, RGBtoBW, Separate RGBA, Separate HSVA, Set Alpha Generators: RGB, Value, Time Groups: the list of custom defined nodes -> OpenEXR tile saving support Created an API for for saving tile-based Images with an unlimited amount of layers/channels. I've tested it for 'render result' now, with the idea that this can (optionally) replace the current inserting of tiles in the main result buffers. Especially with a lot of layers, the used memory for these buffers can easily go into the 100s of megs. Two other advantages: - all 'render result' layers can be saved entirely in a single file, for later use in compositing, also for animation output. - on each render, per scene, a unique temp file can be stored, allowing to re-use these temp files on starting Blender or loading files, showing the last result of a render command. The option is currently disabled, needs more work... but I had to commit this because of the rest of the work I did! -> Bug fix The Image node didn't call an execute event when browsing another image.
2006-02-18 13:28:44 +00:00
{
2012-06-13 17:27:49 +00:00
const StringAttribute *comments = file->header().findTypedAttribute<StringAttribute>("BlenderMultiChannel");
const ChannelList &channels = file->header().channels();
std::set <std::string> layerNames;
channels.layers(layerNames);
2012-06-13 17:27:49 +00:00
if (comments || layerNames.size() > 1)
return 1;
Four-in-one commit: (NOTE: new include dependency in Render module, might need MSVC update! It has to include the imbuf/intern/openexr/ directory in search path) -> New Composite node: "Hue Saturation". Works like the former 'post process' menu. There's no gamma, brightness or multiply needed in this node, for that the Curves Node functions better. -> Enabled Toolbox in Node editor This now also replaces the SHIFT+A for adding nodes. The nodes are automatically added to the menus, using the 'class' category from the type definition. Current classes are (compositor examples): Inputs: RenderResult, Image Outputs: Composite, Viewer Color Ops: RGB Curves, Mix, Hue Saturation, AlphaOver Vector Ops: Normal, Vector Curves, Map Value Filters: Filter, Blur, VectorBlur Convertors: ColorRamp, RGBtoBW, Separate RGBA, Separate HSVA, Set Alpha Generators: RGB, Value, Time Groups: the list of custom defined nodes -> OpenEXR tile saving support Created an API for for saving tile-based Images with an unlimited amount of layers/channels. I've tested it for 'render result' now, with the idea that this can (optionally) replace the current inserting of tiles in the main result buffers. Especially with a lot of layers, the used memory for these buffers can easily go into the 100s of megs. Two other advantages: - all 'render result' layers can be saved entirely in a single file, for later use in compositing, also for animation output. - on each render, per scene, a unique temp file can be stored, allowing to re-use these temp files on starting Blender or loading files, showing the last result of a render command. The option is currently disabled, needs more work... but I had to commit this because of the rest of the work I did! -> Bug fix The Image node didn't call an execute event when browsing another image.
2006-02-18 13:28:44 +00:00
return 0;
}
2012-06-13 17:27:49 +00:00
struct ImBuf *imb_load_openexr(unsigned char *mem, size_t size, int flags){
struct ImBuf *ibuf = NULL;
InputFile *file = NULL;
2012-06-13 17:27:49 +00:00
if (imb_is_a_openexr(mem) == 0) return(NULL);
2012-06-13 17:27:49 +00:00
try
{
2012-06-13 17:27:49 +00:00
Mem_IStream *membuf = new Mem_IStream(mem, size);
int is_multi;
file = new InputFile(*membuf);
2012-06-13 17:27:49 +00:00
Box2i dw = file->header().dataWindow();
int width = dw.max.x - dw.min.x + 1;
int height = dw.max.y - dw.min.y + 1;
2012-06-13 17:27:49 +00:00
//printf("OpenEXR-load: image data window %d %d %d %d\n",
// dw.min.x, dw.min.y, dw.max.x, dw.max.y);
if (0) // debug
exr_print_filecontents(file);
2012-06-13 17:27:49 +00:00
is_multi = exr_is_multilayer(file);
/* do not make an ibuf when */
if (is_multi && !(flags & IB_test) && !(flags & IB_multilayer)) {
printf("Error: can't process EXR multilayer file\n");
}
else {
2012-06-13 17:27:49 +00:00
ibuf = IMB_allocImBuf(width, height, 32, 0);
ibuf->ftype = OPENEXR;
/* openEXR is linear as per EXR spec */
ibuf->profile = IB_PROFILE_LINEAR_RGB;
2012-06-13 17:27:49 +00:00
if (!(flags & IB_test)) {
if (is_multi) { /* only enters with IB_multilayer flag set */
/* constructs channels for reading, allocates memory in channels */
2012-06-13 17:27:49 +00:00
ExrHandle *handle = imb_exr_begin_read_mem(file, width, height);
if (handle) {
IMB_exr_read_channels(handle);
2012-06-13 17:27:49 +00:00
ibuf->userdata = handle; /* potential danger, the caller has to check for this! */
}
}
else {
FrameBuffer frameBuffer;
float *first;
int xstride = sizeof(float) * 4;
2012-06-13 17:27:49 +00:00
int ystride = -xstride * width;
imb_addrectfloatImBuf(ibuf);
2012-06-13 17:27:49 +00:00
/* inverse correct first pixel for datawindow coordinates (- dw.min.y because of y flip) */
2012-06-13 17:27:49 +00:00
first = ibuf->rect_float - 4 * (dw.min.x - dw.min.y * width);
/* but, since we read y-flipped (negative y stride) we move to last scanline */
2012-06-13 17:27:49 +00:00
first += 4 * (height - 1) * width;
frameBuffer.insert(exr_rgba_channelname(file, "R"),
Slice(Imf::FLOAT, (char *) first, xstride, ystride));
frameBuffer.insert(exr_rgba_channelname(file, "G"),
Slice(Imf::FLOAT, (char *) (first + 1), xstride, ystride));
frameBuffer.insert(exr_rgba_channelname(file, "B"),
Slice(Imf::FLOAT, (char *) (first + 2), xstride, ystride));
frameBuffer.insert(exr_rgba_channelname(file, "A"),
Slice(Imf::FLOAT, (char *) (first + 3), xstride, ystride, 1, 1, 1.0f)); /* 1.0 is fill value */
if (exr_has_zbuffer(file)) {
float *firstz;
2012-06-13 17:27:49 +00:00
addzbuffloatImBuf(ibuf);
2012-06-13 17:27:49 +00:00
firstz = ibuf->zbuf_float - (dw.min.x - dw.min.y * width);
firstz += (height - 1) * width;
frameBuffer.insert("Z", Slice(Imf::FLOAT, (char *)firstz, sizeof(float), -width * sizeof(float)));
}
2012-06-13 17:27:49 +00:00
file->setFrameBuffer(frameBuffer);
file->readPixels(dw.min.y, dw.max.y);
// XXX, ImBuf has no nice way to deal with this.
// ideally IM_rect would be used when the caller wants a rect BUT
// at the moment all functions use IM_rect.
// Disabling this is ok because all functions should check if a rect exists and create one on demand.
//
// Disabling this because the sequencer frees immediate.
//
// if (flag & IM_rect)
// IMB_rect_from_float(ibuf);
2012-06-13 17:27:49 +00:00
/* file is no longer needed */
delete file;
}
}
}
return(ibuf);
}
catch (const std::exception &exc)
{
std::cerr << exc.what() << std::endl;
if (ibuf) IMB_freeImBuf(ibuf);
delete file;
2012-06-13 17:27:49 +00:00
return (0);
}
2012-06-13 17:27:49 +00:00
}
void imb_initopenexr(void)
{
int num_threads = BLI_system_thread_count();
setGlobalThreadCount(num_threads);
}
} // export "C"