Disabled external gits

This commit is contained in:
2022-04-07 18:46:57 +02:00
parent 88cb3426ad
commit 15e7120d6d
5316 changed files with 4563444 additions and 6 deletions

View File

@ -0,0 +1,16 @@
Makefile
Makefile.in
config.h.in
config.h
config.log
config.status
configure
libtool
stamp-h
aclocal.m4
OpenEXR.pc
autom4te.cache
ltmain.sh
stamp-h.in
depcomp
.deps

View File

@ -0,0 +1,23 @@
# yue.nicholas@gmail.com
ADD_EXECUTABLE ( IlmImfExamples
drawImage.cpp
generalInterfaceExamples.cpp
generalInterfaceTiledExamples.cpp
lowLevelIoExamples.cpp
main.cpp
previewImageExamples.cpp
rgbaInterfaceExamples.cpp
rgbaInterfaceTiledExamples.cpp
)
TARGET_LINK_LIBRARIES ( IlmImfExamples
IlmImf
Half
Iex${ILMBASE_LIBSUFFIX}
Imath${ILMBASE_LIBSUFFIX}
IlmThread${ILMBASE_LIBSUFFIX}
${PTHREAD_LIB} ${ZLIB_LIBRARIES}
)

View File

@ -0,0 +1,32 @@
## Process this file with automake to produce Makefile.in
if BUILD_IMFEXAMPLES
noinst_PROGRAMS = imfexamples
endif
INCLUDES = -I$(top_builddir) \
-I$(top_srcdir)/IlmImf -I$(top_srcdir)/config \
@ILMBASE_CXXFLAGS@
LDADD = -L$(top_builddir)/IlmImf \
@ILMBASE_LDFLAGS@ @ILMBASE_LIBS@ \
-lIlmImf -lz
imfexamples_SOURCES = main.cpp drawImage.cpp rgbaInterfaceExamples.cpp \
rgbaInterfaceTiledExamples.cpp \
generalInterfaceExamples.cpp \
lowLevelIoExamples.cpp previewImageExamples.cpp \
generalInterfaceTiledExamples.cpp \
generalInterfaceTiledExamples.h drawImage.h \
rgbaInterfaceExamples.h generalInterfaceExamples.h \
rgbaInterfaceTiledExamples.h \
lowLevelIoExamples.h previewImageExamples.h \
namespaceAlias.h
examplesdir = $(datadir)/doc/OpenEXR-@OPENEXR_VERSION@/examples
examples_DATA = $(imfexamples_SOURCES)
imfexamplesdir = $(examplesdir)
EXTRA_DIST = CMakeLists.txt

View File

@ -0,0 +1,475 @@
///////////////////////////////////////////////////////////////////////////
//
// Copyright (c) 2004, Industrial Light & Magic, a division of Lucas
// Digital Ltd. LLC
//
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are
// met:
// * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above
// copyright notice, this list of conditions and the following disclaimer
// in the documentation and/or other materials provided with the
// distribution.
// * Neither the name of Industrial Light & Magic nor the names of
// its contributors may be used to endorse or promote products derived
// from this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
//
///////////////////////////////////////////////////////////////////////////
//-----------------------------------------------------------------------------
//
// Functions that algorithmically generate images, so that
// the code examples for image file reading and writing have
// data they can work with.
// Note that it is not necessary to study the code below in
// order to understand how the file I/O code examples work.
//
//-----------------------------------------------------------------------------
#include "drawImage.h"
#include <math.h>
#include <stdlib.h>
#include <float.h>
#include <algorithm>
#include "namespaceAlias.h"
using namespace IMF;
using namespace std;
namespace
{
float
pw (float x, int y)
{
float p = 1;
while (y)
{
if (y & 1)
p *= x;
x *= x;
y >>= 1;
}
return p;
}
void
sp (Array2D<Rgba> &px, int w, int h,
float xc, float yc, float rc,
float rd, float gn, float bl, float lm)
{
int x1 = int (max ((float) floor (xc - rc), 0.0f));
int x2 = int (min ((float) ceil (xc + rc), w - 1.0f));
int y1 = int (max ((float) floor (yc - rc), 0.0f));
int y2 = int (min ((float) ceil (yc + rc), h - 1.0f));
for (int y = y1; y <= y2; ++y)
{
for (int x = x1; x <= x2; ++x)
{
float xl = (x - xc) / rc;
float yl = (y - yc) / rc;
float r = sqrt (xl * xl + yl * yl);
if (r >= 1)
continue;
float a = 1;
if (r * rc > rc - 1)
a = rc - r * rc;
float zl = sqrt (1 - r * r);
float dl = xl * 0.42426 - yl * 0.56568 + zl * 0.70710;
if (dl < 0)
dl *= -0.1;
float hl = pw (dl, 50) * 4;
float dr = (dl + hl) * rd;
float dg = (dl + hl) * gn;
float db = (dl + hl) * bl;
Rgba &p = px[y][x];
p.r = p.r * (1 - a) + dr * lm * a;
p.g = p.g * (1 - a) + dg * lm * a;
p.b = p.b * (1 - a) + db * lm * a;
p.a = 1 - (1 - p.a) * (1 - a);
}
}
}
void
zsp (Array2D<half> &gpx, Array2D<float> &zpx, int w, int h,
float xc, float yc, float zc, float rc, float gn)
{
int x1 = int (max ((float) floor (xc - rc), 0.0f));
int x2 = int (min ((float) ceil (xc + rc), w - 1.0f));
int y1 = int (max ((float) floor (yc - rc), 0.0f));
int y2 = int (min ((float) ceil (yc + rc), h - 1.0f));
for (int x = x1; x <= x2; ++x)
{
for (int y = y1; y <= y2; ++y)
{
float xl = (x - xc) / rc;
float yl = (y - yc) / rc;
float r = sqrt (xl * xl + yl * yl);
if (r >= 1)
continue;
float a = 1;
if (r * rc > rc - 1)
a = rc - r * rc;
float zl = sqrt (1 - r * r);
float zp = zc - rc * zl;
if (zp >= zpx[y][x])
continue;
float dl = xl * 0.42426 - yl * 0.56568 + zl * 0.70710;
if (dl < 0)
dl *= -0.1;
float hl = pw (dl, 50) * 4;
float dg = (dl + hl) * gn;
gpx[y][x] = dg;
zpx[y][x] = zp;
}
}
}
inline float
z (float k)
{
k = 2 * (k - int (k));
return (k < 1)? k: 2 - k;
}
inline void
clear (Rgba &color)
{
color.r = 0;
color.g = 0;
color.b = 0;
}
inline void
clear (GZ &gz)
{
gz.g = 0;
gz.z = 0;
}
void
add (float k, Rgba &color)
{
color.a = k;
k *= 4;
color.r += 0.1f + 4 * z (k);
color.g += 0.1f + 4 * z (k + .33333f);
color.b += 0.1f + 4 * z (k + .66667f);
}
void
add (float k, GZ &gz)
{
k *= 5;
gz.g += 4 * z (k);
gz.z = k;
}
inline void
scale (float f, Rgba &color)
{
color.r *= f;
color.g *= f;
color.b *= f;
color.a *= f;
}
inline void
scale (float f, GZ &gz)
{
gz.g *= f;
gz.z *= f;
}
template <class P>
void
mndl (Array2D <P> &px,
int w, int h,
int xMin, int xMax,
int yMin, int yMax,
int xSamples, int ySamples,
double rMin,
double rMax,
double iMin,
double aspect,
double rSeed,
double iSeed)
{
if (xSamples > 6)
xSamples = 6;
if (ySamples > 6)
ySamples = 6;
double iMax = iMin + aspect * (rMax - rMin) * h / w;
double sx = double (rMax - rMin) / w;
double sy = double (iMax - iMin) / h;
double tx = 1.f / xSamples;
double ty = 1.f / ySamples;
float t = tx * ty;
for (int y = yMin; y < yMax; ++y)
{
for (int x = xMin; x < xMax; ++x)
{
P &p = px[y - yMin][x - xMin];
clear (p);
for (int i = 0; i < xSamples; ++i)
{
for (int j = 0; j < ySamples; ++j)
{
const double a = rMin + sx * (x + i * tx);
const double b = iMin + sy * (y + j * ty);
const double sMax = 100;
const int kMax = 256;
double r = rSeed;
double i = iSeed;
double s = 0;
int k = 0;
while (k < kMax && s < sMax)
{
s = r * r - i * i;
i = 2 * r * i + b;
r = s + a;
k++;
}
add (k / float (kMax), p);
}
}
scale (t, p);
}
}
}
} // namespace
void
drawImage1 (Array2D<Rgba> &px, int w, int h)
{
for (int y = 0; y < h; ++y)
{
for (int x = 0; x < w; ++x)
{
Rgba &p = px[y][x];
p.r = 0;
p.g = 0;
p.b = 0;
p.a = 0;
}
}
int n = 5600;
for (int i = 0; i < n; ++i)
{
float t = (i * 2.0 * M_PI) / n;
float xp = sin (t * 2.0) + 0.2 * sin (t * 15.0);
float yp = cos (t * 3.0) + 0.2 * cos (t * 15.0);
float r = float (i + 1) / float (n);
float xq = xp + 0.3 * r * sin (t * 80.0);
float yq = yp + 0.3 * r * cos (t * 80.0);
float xr = xp + 0.3 * r * sin (t * 80.0 + M_PI / 2);
float yr = yp + 0.3 * r * cos (t * 80.0 + M_PI / 2);
if (i % 10 == 0)
sp (px, w, h,
xp * w / 3 + w / 2, yp * h / 3 + h / 2,
w * 0.05 * r,
2.0, 0.8, 0.1,
0.5 * r * r);
sp (px, w, h,
xq * w / 3 + w / 2, yq * h / 3 + h / 2,
w * 0.01 * r,
0.7, 0.2, 2.0,
0.5 * r * r);
sp (px, w, h,
xr * w / 3 + w / 2, yr * h / 3 + h / 2,
w * 0.01 * r,
0.2, 1.5, 0.1,
0.5 * r * r);
}
}
void
drawImage2 (Array2D<half> &gpx, Array2D<float> &zpx, int w, int h)
{
for (int y = 0; y < h; ++y)
{
for (int x = 0; x < w; ++x)
{
gpx[y][x] = 0;
zpx[y][x] = FLT_MAX;
}
}
int n = 2000;
for (int i = 0; i < n; ++i)
{
float t = (i * 2.0 * M_PI) / n;
float xp = sin (t * 4.0) + 0.2 * sin (t * 15.0);
float yp = cos (t * 3.0) + 0.2 * cos (t * 15.0);
float zp = sin (t * 5.0);
float rd = 0.7 + 0.3 * sin (t * 15.0);
float gn = 0.5 - 0.5 * zp + 0.2;
zsp (gpx, zpx, w, h,
xp * w / 3 + w / 2,
yp * h / 3 + h / 2,
zp * w + 3 * w,
w * rd * 0.05,
2.5 * gn * gn);
}
}
void
drawImage3 (Array2D<Rgba> &px,
int w, int h,
int xMin, int xMax,
int yMin, int yMax,
int xLevel, int yLevel)
{
mndl (px,
w, h,
xMin, xMax,
yMin, yMax,
(1 << xLevel), (1 << yLevel),
0.328, 0.369,
0.5,
double (1 << yLevel) / double (1 << xLevel),
-0.713, 0.9738);
}
void
drawImage4 (Array2D<Rgba> &px,
int w, int h,
int xMin, int xMax,
int yMin, int yMax,
int xLevel, int yLevel)
{
mndl (px,
w, h,
xMin, xMax,
yMin, yMax,
(1 << xLevel), (1 << yLevel),
0.3247, 0.33348,
0.4346,
double (1 << yLevel) / double (1 << xLevel),
0.4, -0.765);
}
void
drawImage5 (Array2D<Rgba> &px,
int w, int h,
int xMin, int xMax,
int yMin, int yMax,
int xLevel, int yLevel)
{
mndl (px,
w, h,
xMin, xMax,
yMin, yMax,
(1 << xLevel), (1 << yLevel),
0.2839, 0.2852,
0.00961,
double (1 << yLevel) / double (1 << xLevel),
0.25, 0.31);
}
void
drawImage6 (Array2D<GZ> &px, int w, int h)
{
mndl (px,
w, h,
0, w,
0, h,
3, 3,
-2.5, 1.0,
-1.3333,
1,
0, 0);
}
void
drawImage7 (Array<Rgba> &px, int w, int h, int y)
{
for (int x = 0; x < w; ++x)
{
float xc = x - w / 2;
float yc = y - h / 2;
float a = atan2 (xc, yc);
float r = sqrt (xc * xc + yc * yc);
Rgba &p = px[x];
p.r = sin (3.0f * a + 0.3f * sin (0.10f * r)) * 0.5f + 0.5f;
p.g = sin (3.0f * a + 0.3f * sin (0.11f * r)) * 0.5f + 0.5f;
p.b = sin (3.0f * a + 0.3f * sin (0.12f * r)) * 0.5f + 0.5f;
p.a = 1;
}
}

View File

@ -0,0 +1,87 @@
///////////////////////////////////////////////////////////////////////////
//
// Copyright (c) 2004, Industrial Light & Magic, a division of Lucas
// Digital Ltd. LLC
//
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are
// met:
// * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above
// copyright notice, this list of conditions and the following disclaimer
// in the documentation and/or other materials provided with the
// distribution.
// * Neither the name of Industrial Light & Magic nor the names of
// its contributors may be used to endorse or promote products derived
// from this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
//
///////////////////////////////////////////////////////////////////////////
#include <OpenEXRConfig.h>
#include <ImfRgbaFile.h>
#include <ImfArray.h>
#include "namespaceAlias.h"
struct GZ
{
half g;
float z;
};
void drawImage1 (IMF::Array2D<IMF::Rgba> &pixels,
int width,
int height);
void drawImage2 (IMF::Array2D<half> &gPixels,
IMF::Array2D<float> &zPixels,
int width,
int height);
void drawImage3 (IMF::Array2D<IMF::Rgba> &pixels,
int width,
int height,
int xMin, int xMax,
int yMin, int yMax,
int xLevel = 0, int yLevel = 0);
void drawImage4 (IMF::Array2D<IMF::Rgba> &pixels,
int width,
int height,
int xMin, int xMax,
int yMin, int yMax,
int xLevel = 0, int yLevel = 0);
void drawImage5 (IMF::Array2D<IMF::Rgba> &pixels,
int width,
int height,
int xMin, int xMax,
int yMin, int yMax,
int xLevel = 0, int yLevel = 0);
void drawImage6 (IMF::Array2D<GZ> &pixels,
int width,
int height);
void drawImage7 (IMF::Array<IMF::Rgba> &pixels,
int width,
int height,
int y);

View File

@ -0,0 +1,296 @@
///////////////////////////////////////////////////////////////////////////
//
// Copyright (c) 2004, Industrial Light & Magic, a division of Lucas
// Digital Ltd. LLC
//
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are
// met:
// * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above
// copyright notice, this list of conditions and the following disclaimer
// in the documentation and/or other materials provided with the
// distribution.
// * Neither the name of Industrial Light & Magic nor the names of
// its contributors may be used to endorse or promote products derived
// from this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
//
///////////////////////////////////////////////////////////////////////////
//-----------------------------------------------------------------------------
//
// Code examples that show how class InputFile and class OutputFile
// can be used to read and write OpenEXR image files with an arbitrary
// set of channels.
//
//-----------------------------------------------------------------------------
#include <ImfOutputFile.h>
#include <ImfInputFile.h>
#include <ImfChannelList.h>
#include <ImfStringAttribute.h>
#include <ImfMatrixAttribute.h>
#include <ImfArray.h>
#include "drawImage.h"
#include <iostream>
#include "namespaceAlias.h"
using namespace IMF;
using namespace std;
using namespace IMATH_NAMESPACE;
void
writeGZ1 (const char fileName[],
const half *gPixels,
const float *zPixels,
int width,
int height)
{
//
// Write an image with only a G (green) and a Z (depth) channel,
// using class OutputFile.
//
// - create a file header
// - add G and Z channels to the header
// - open the file, and store the header in the file
// - describe the memory layout of the G anx Z pixels
// - store the pixels in the file
//
Header header (width, height);
header.channels().insert ("G", Channel (IMF::HALF));
header.channels().insert ("Z", Channel (IMF::FLOAT));
OutputFile file (fileName, header);
FrameBuffer frameBuffer;
frameBuffer.insert ("G", // name
Slice (IMF::HALF, // type
(char *) gPixels, // base
sizeof (*gPixels) * 1, // xStride
sizeof (*gPixels) * width)); // yStride
frameBuffer.insert ("Z", // name
Slice (IMF::FLOAT, // type
(char *) zPixels, // base
sizeof (*zPixels) * 1, // xStride
sizeof (*zPixels) * width)); // yStride
file.setFrameBuffer (frameBuffer);
file.writePixels (height);
}
void
writeGZ2 (const char fileName[],
const half *gPixels,
const float *zPixels,
int width,
int height,
const Box2i &dataWindow)
{
//
// Write an image with only a G (green) and a Z (depth) channel,
// using class OutputFile. Don't store the whole image in the
// file, but crop it according to the given data window.
//
// - create a file header
// - set the header's data window
// - add G and Z channels to the header
// - open the file, and store the header in the file
// - describe the memory layout of the G anx Z pixels
// - store the pixels in the file
//
Header header (width, height);
header.dataWindow() = dataWindow;
header.channels().insert ("G", Channel (IMF::HALF));
header.channels().insert ("Z", Channel (IMF::FLOAT));
OutputFile file (fileName, header);
FrameBuffer frameBuffer;
frameBuffer.insert ("G", // name
Slice (IMF::HALF, // type
(char *) gPixels, // base
sizeof (*gPixels) * 1, // xStride
sizeof (*gPixels) * width)); // yStride
frameBuffer.insert ("Z", // name
Slice (IMF::FLOAT, // type
(char *) zPixels, // base
sizeof (*zPixels) * 1, // xStride
sizeof (*zPixels) * width)); // yStride
file.setFrameBuffer (frameBuffer);
file.writePixels (dataWindow.max.y - dataWindow.min.y + 1);
}
void
readGZ1 (const char fileName[],
Array2D<half> &rPixels,
Array2D<half> &gPixels,
Array2D<float> &zPixels,
int &width, int &height)
{
//
// Read an image using class InputFile. Try to read two
// channels, R and G, of type HALF, and one channel, Z,
// of type FLOAT. Store the R, G, and Z pixels in three
// separate memory buffers.
// If a channel is missing in the file, the buffer for that
// channel will be filled with an appropriate default value.
//
// - open the file
// - allocate memory for the pixels
// - describe the layout of the R, G, and Z pixel buffers
// - read the pixels from the file
//
InputFile file (fileName);
Box2i dw = file.header().dataWindow();
width = dw.max.x - dw.min.x + 1;
height = dw.max.y - dw.min.y + 1;
rPixels.resizeErase (height, width);
gPixels.resizeErase (height, width);
zPixels.resizeErase (height, width);
FrameBuffer frameBuffer;
frameBuffer.insert ("R", // name
Slice (IMF::HALF, // type
(char *) (&rPixels[0][0] - // base
dw.min.x -
dw.min.y * width),
sizeof (rPixels[0][0]) * 1, // xStride
sizeof (rPixels[0][0]) * width, // yStride
1, 1, // x/y sampling
0.0)); // fillValue
frameBuffer.insert ("G", // name
Slice (IMF::HALF, // type
(char *) (&gPixels[0][0] - // base
dw.min.x -
dw.min.y * width),
sizeof (gPixels[0][0]) * 1, // xStride
sizeof (gPixels[0][0]) * width, // yStride
1, 1, // x/y sampling
0.0)); // fillValue
frameBuffer.insert ("Z", // name
Slice (IMF::FLOAT, // type
(char *) (&zPixels[0][0] - // base
dw.min.x -
dw.min.y * width),
sizeof (zPixels[0][0]) * 1, // xStride
sizeof (zPixels[0][0]) * width, // yStride
1, 1, // x/y sampling
FLT_MAX)); // fillValue
file.setFrameBuffer (frameBuffer);
file.readPixels (dw.min.y, dw.max.y);
}
void
readGZ2 (const char fileName[],
Array2D<GZ> &pixels,
int &width, int &height)
{
//
// Read an image using class InputFile. Try to read one channel,
// G, of type HALF, and one channel, Z, of type FLOAT. In memory,
// the G and Z channels will be interleaved in a single buffer.
//
// - open the file
// - allocate memory for the pixels
// - describe the layout of the GZ pixel buffer
// - read the pixels from the file
//
InputFile file (fileName);
Box2i dw = file.header().dataWindow();
width = dw.max.x - dw.min.x + 1;
height = dw.max.y - dw.min.y + 1;
int dx = dw.min.x;
int dy = dw.min.y;
pixels.resizeErase (height, width);
FrameBuffer frameBuffer;
frameBuffer.insert ("G", // name
Slice (IMF::HALF, // type
(char *) &pixels[-dy][-dx].g, // base
sizeof (pixels[0][0]) * 1, // xStride
sizeof (pixels[0][0]) * width)); // yStride
frameBuffer.insert ("Z", // name
Slice (IMF::FLOAT, // type
(char *) &pixels[-dy][-dx].z, // base
sizeof (pixels[0][0]) * 1, // xStride
sizeof (pixels[0][0]) * width)); // yStride
file.setFrameBuffer (frameBuffer);
file.readPixels (dw.min.y, dw.max.y);
}
void
generalInterfaceExamples ()
{
cout << "\nGZ (green, depth) images\n" << endl;
cout << "drawing image" << endl;
int w = 800;
int h = 600;
Array2D<half> gp (h, w);
Array2D<float> zp (h, w);
drawImage2 (gp, zp, w, h);
cout << "writing entire image" << endl;
writeGZ1 ("gz1.exr", &gp[0][0], &zp[0][0], w, h);
cout << "writing cropped image" << endl;
writeGZ2 ("gz2.exr", &gp[0][0], &zp[0][0], w, h,
Box2i (V2i (w/6, h/6), V2i (w/2, h/2)));
cout << "reading file into separate per-channel buffers" << endl;
Array2D<half> rp (1, 1);
readGZ1 ("gz2.exr", rp, gp, zp, w, h);
cout << "reading file into interleaved multi-channel buffer" << endl;
Array2D<GZ> gzp (1, 1);
readGZ2 ("gz2.exr", gzp, w, h);
}

View File

@ -0,0 +1,35 @@
///////////////////////////////////////////////////////////////////////////
//
// Copyright (c) 2012, Industrial Light & Magic, a division of Lucas
// Digital Ltd. LLC
//
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are
// met:
// * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above
// copyright notice, this list of conditions and the following disclaimer
// in the documentation and/or other materials provided with the
// distribution.
// * Neither the name of Industrial Light & Magic nor the names of
// its contributors may be used to endorse or promote products derived
// from this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
//
///////////////////////////////////////////////////////////////////////////
void generalInterfaceExamples ();

View File

@ -0,0 +1,148 @@
///////////////////////////////////////////////////////////////////////////
//
// Copyright (c) 2002, Industrial Light & Magic, a division of Lucas
// Digital Ltd. LLC
//
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are
// met:
// * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above
// copyright notice, this list of conditions and the following disclaimer
// in the documentation and/or other materials provided with the
// distribution.
// * Neither the name of Industrial Light & Magic nor the names of
// its contributors may be used to endorse or promote products derived
// from this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
//
///////////////////////////////////////////////////////////////////////////
//-----------------------------------------------------------------------------
//
// Code examples that show how class TiledInputFile and
// class TiledOutputFile can be used to read and write
// OpenEXR image files with an arbitrary set of channels.
//
//-----------------------------------------------------------------------------
#include <ImfTiledOutputFile.h>
#include <ImfTiledInputFile.h>
#include <ImfChannelList.h>
#include <ImfStringAttribute.h>
#include <ImfMatrixAttribute.h>
#include <ImfArray.h>
#include "drawImage.h"
#include <iostream>
#include "namespaceAlias.h"
using namespace IMF;
using namespace std;
using namespace IMATH_NAMESPACE;
void
writeTiled1 (const char fileName[],
Array2D<GZ> &pixels,
int width, int height,
int tileWidth, int tileHeight)
{
Header header (width, height);
header.channels().insert ("G", Channel (IMF::HALF));
header.channels().insert ("Z", Channel (IMF::FLOAT));
header.setTileDescription
(TileDescription (tileWidth, tileHeight, ONE_LEVEL));
TiledOutputFile out (fileName, header);
FrameBuffer frameBuffer;
frameBuffer.insert ("G", // name
Slice (IMF::HALF, // type
(char *) &pixels[0][0].g, // base
sizeof (pixels[0][0]) * 1, // xStride
sizeof (pixels[0][0]) * width)); // yStride
frameBuffer.insert ("Z", // name
Slice (IMF::FLOAT, // type
(char *) &pixels[0][0].z, // base
sizeof (pixels[0][0]) * 1, // xStride
sizeof (pixels[0][0]) * width)); // yStride
out.setFrameBuffer (frameBuffer);
out.writeTiles (0, out.numXTiles() - 1, 0, out.numYTiles() - 1);
}
void
readTiled1 (const char fileName[],
Array2D<GZ> &pixels,
int &width, int &height)
{
TiledInputFile in (fileName);
Box2i dw = in.header().dataWindow();
width = dw.max.x - dw.min.x + 1;
height = dw.max.y - dw.min.y + 1;
int dx = dw.min.x;
int dy = dw.min.y;
pixels.resizeErase (height, width);
FrameBuffer frameBuffer;
frameBuffer.insert ("G", // name
Slice (IMF::HALF, // type
(char *) &pixels[-dy][-dx].g, // base
sizeof (pixels[0][0]) * 1, // xStride
sizeof (pixels[0][0]) * width)); // yStride
frameBuffer.insert ("Z", // name
Slice (IMF::FLOAT, // type
(char *) &pixels[-dy][-dx].z, // base
sizeof (pixels[0][0]) * 1, // xStride
sizeof (pixels[0][0]) * width)); // yStride
in.setFrameBuffer (frameBuffer);
in.readTiles (0, in.numXTiles() - 1, 0, in.numYTiles() - 1);
}
void
generalInterfaceTiledExamples ()
{
cout << "\nGZ (green, depth) tiled files\n" << endl;
cout << "drawing image" << endl;
int w = 800;
int h = 600;
Array2D<GZ> pixels (h, w);
drawImage6 (pixels, w, h);
cout << "writing file" << endl;
writeTiled1 ("tiledgz1.exr", pixels, w, h, 64, 64);
cout << "reading file" << endl;
readTiled1 ("tiledgz1.exr", pixels, w, h);
}

View File

@ -0,0 +1,36 @@
///////////////////////////////////////////////////////////////////////////
//
// Copyright (c) 2012, Industrial Light & Magic, a division of Lucas
// Digital Ltd. LLC
//
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are
// met:
// * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above
// copyright notice, this list of conditions and the following disclaimer
// in the documentation and/or other materials provided with the
// distribution.
// * Neither the name of Industrial Light & Magic nor the names of
// its contributors may be used to endorse or promote products derived
// from this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
//
///////////////////////////////////////////////////////////////////////////
void generalInterfaceTiledExamples ();

View File

@ -0,0 +1,292 @@
///////////////////////////////////////////////////////////////////////////
//
// Copyright (c) 2004, Industrial Light & Magic, a division of Lucas
// Digital Ltd. LLC
//
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are
// met:
// * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above
// copyright notice, this list of conditions and the following disclaimer
// in the documentation and/or other materials provided with the
// distribution.
// * Neither the name of Industrial Light & Magic nor the names of
// its contributors may be used to endorse or promote products derived
// from this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
//
///////////////////////////////////////////////////////////////////////////
//-----------------------------------------------------------------------------
//
// Code examples that show how implement custom low-level
// file input and output for OpenEXR files:
//
// Classes C_IStream and C_OStream are derived from IlmImf's
// abstract IStream and OStreamd classes. They allow OpenEXR
// file input and output via C stdio files (FILE *).
//
//-----------------------------------------------------------------------------
#include <ImfRgbaFile.h>
#include <ImfIO.h>
#include "Iex.h"
#include "drawImage.h"
#include <iostream>
#include <stdio.h>
#include "namespaceAlias.h"
using namespace IMF;
using namespace std;
using namespace IMATH_NAMESPACE;
class C_IStream: public IStream
{
public:
C_IStream (FILE *file, const char fileName[]):
IStream (fileName), _file (file) {}
virtual bool read (char c[/*n*/], int n);
virtual Int64 tellg ();
virtual void seekg (Int64 pos);
virtual void clear ();
private:
FILE * _file;
};
class C_OStream: public OStream
{
public:
C_OStream (FILE *file, const char fileName[]):
OStream (fileName), _file (file) {}
virtual void write (const char c[/*n*/], int n);
virtual Int64 tellp ();
virtual void seekp (Int64 pos);
private:
FILE * _file;
};
bool
C_IStream::read (char c[/*n*/], int n)
{
if (n != fread (c, 1, n, _file))
{
//
// fread() failed, but the return value does not distinguish
// between I/O errors and end of file, so we call ferror() to
// determine what happened.
//
if (ferror (_file))
IEX_NAMESPACE::throwErrnoExc();
else
throw IEX_NAMESPACE::InputExc ("Unexpected end of file.");
}
return feof (_file);
}
Int64
C_IStream::tellg ()
{
return ftell (_file);
}
void
C_IStream::seekg (Int64 pos)
{
clearerr (_file);
fseek (_file, pos, SEEK_SET);
}
void
C_IStream::clear ()
{
clearerr (_file);
}
void
C_OStream::write (const char c[/*n*/], int n)
{
clearerr (_file);
if (n != fwrite (c, 1, n, _file))
IEX_NAMESPACE::throwErrnoExc();
}
Int64
C_OStream::tellp ()
{
return ftell (_file);
}
void
C_OStream::seekp (Int64 pos)
{
clearerr (_file);
fseek (_file, pos, SEEK_SET);
}
void
writeRgbaFILE (FILE *cfile,
const char fileName[],
const Rgba *pixels,
int width,
int height)
{
//
// Store an RGBA image in a C stdio file that has already been opened:
//
// - create a C_OStream object for writing to the file
// - create an RgbaOutputFile object, and attach it to the C_OStream
// - describe the memory layout of the pixels
// - store the pixels in the file
//
C_OStream ostr (cfile, fileName);
RgbaOutputFile file (ostr, Header (width, height), WRITE_RGBA);
file.setFrameBuffer (pixels, 1, width);
file.writePixels (height);
}
void
readRgbaFILE (FILE *cfile,
const char fileName[],
Array2D<Rgba> &pixels,
int &width,
int &height)
{
//
// Read an RGBA image from a C stdio file that has already been opened:
//
// - create a C_IStream object for reading from the file
// - create an RgbaInputFile object, and attach it to the C_IStream
// - allocate memory for the pixels
// - describe the memory layout of the pixels
// - read the pixels from the file
//
C_IStream istr (cfile, fileName);
RgbaInputFile file (istr);
Box2i dw = file.dataWindow();
width = dw.max.x - dw.min.x + 1;
height = dw.max.y - dw.min.y + 1;
pixels.resizeErase (height, width);
file.setFrameBuffer (&pixels[0][0] - dw.min.x - dw.min.y * width, 1, width);
file.readPixels (dw.min.y, dw.max.y);
}
void
lowLevelIoExamples ()
{
cout << "\nCustom low-level file I/O\n" << endl;
cout << "drawing image" << endl;
int w = 800;
int h = 600;
const char *fileName = "rgba4.exr";
Array2D<Rgba> p (h, w);
drawImage1 (p, w, h);
//
// The following code is somewhat complicated because
// fopen() returns 0 on error, but writeRgbaFILE() and
// readRgbaFILE() throw exceptions. Also, if a FILE *
// goes out of scope, the corresponding file is not
// automatically closed. In order to avoid leaking
// file descriptors, we have to make sure fclose() is
// called in all cases.
//
cout << "writing image" << endl;
{
FILE *file = fopen (fileName, "wb");
if (file == 0)
{
THROW_ERRNO ("Cannot open file " << fileName << " (%T).");
}
else
{
try
{
writeRgbaFILE (file, fileName, &p[0][0], w, h);
}
catch (...)
{
fclose (file);
throw;
}
fclose (file);
}
}
cout << "reading image" << endl;
{
FILE *file = fopen (fileName, "rb");
if (file == 0)
{
THROW_ERRNO ("Cannot open file " << fileName << " (%T).");
}
else
{
try
{
readRgbaFILE (file, fileName, p, w, h);
}
catch (...)
{
fclose (file);
throw;
}
fclose (file);
}
}
}

View File

@ -0,0 +1,35 @@
///////////////////////////////////////////////////////////////////////////
//
// Copyright (c) 2012, Industrial Light & Magic, a division of Lucas
// Digital Ltd. LLC
//
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are
// met:
// * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above
// copyright notice, this list of conditions and the following disclaimer
// in the documentation and/or other materials provided with the
// distribution.
// * Neither the name of Industrial Light & Magic nor the names of
// its contributors may be used to endorse or promote products derived
// from this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
//
///////////////////////////////////////////////////////////////////////////
void lowLevelIoExamples ();

View File

@ -0,0 +1,70 @@
///////////////////////////////////////////////////////////////////////////
//
// Copyright (c) 2002, Industrial Light & Magic, a division of Lucas
// Digital Ltd. LLC
//
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are
// met:
// * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above
// copyright notice, this list of conditions and the following disclaimer
// in the documentation and/or other materials provided with the
// distribution.
// * Neither the name of Industrial Light & Magic nor the names of
// its contributors may be used to endorse or promote products derived
// from this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
//
///////////////////////////////////////////////////////////////////////////
#include "rgbaInterfaceExamples.h"
#include "rgbaInterfaceTiledExamples.h"
#include "generalInterfaceExamples.h"
#include "generalInterfaceTiledExamples.h"
#include "lowLevelIoExamples.h"
#include "previewImageExamples.h"
#include <iostream>
#include <stdexcept>
int
main (int argc, char *argv[])
{
try
{
rgbaInterfaceExamples();
generalInterfaceExamples();
rgbaInterfaceTiledExamples();
generalInterfaceTiledExamples();
lowLevelIoExamples();
previewImageExamples();
}
catch (const std::exception &exc)
{
std::cerr << exc.what() << std::endl;
return 1;
}
return 0;
}

View File

@ -0,0 +1,41 @@
///////////////////////////////////////////////////////////////////////////
//
// Copyright (c) 2012, Industrial Light & Magic, a division of Lucas
// Digital Ltd. LLC
//
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are
// met:
// * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above
// copyright notice, this list of conditions and the following disclaimer
// in the documentation and/or other materials provided with the
// distribution.
// * Neither the name of Industrial Light & Magic nor the names of
// its contributors may be used to endorse or promote products derived
// from this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
//
///////////////////////////////////////////////////////////////////////////
#ifndef NAMESPACEALIAS_H_
#define NAMESPACEALIAS_H_
#include <ImfNamespace.h>
namespace IMF = OPENEXR_IMF_NAMESPACE;
#endif /* NAMESPACEALIAS_H_ */

View File

@ -0,0 +1,219 @@
///////////////////////////////////////////////////////////////////////////
//
// Copyright (c) 2004, Industrial Light & Magic, a division of Lucas
// Digital Ltd. LLC
//
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are
// met:
// * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above
// copyright notice, this list of conditions and the following disclaimer
// in the documentation and/or other materials provided with the
// distribution.
// * Neither the name of Industrial Light & Magic nor the names of
// its contributors may be used to endorse or promote products derived
// from this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
//
///////////////////////////////////////////////////////////////////////////
//-----------------------------------------------------------------------------
//
// Code examples that show how to add preview images
// (also known as thumbnais) to OpenEXR image files.
//
//-----------------------------------------------------------------------------
#include <ImfRgbaFile.h>
#include <ImfArray.h>
#include <ImfPreviewImage.h>
#include "ImathFun.h"
#include "drawImage.h"
#include <iostream>
#include <algorithm>
#include "namespaceAlias.h"
using namespace IMF;
using namespace std;
using namespace IMATH_NAMESPACE;
unsigned char
gamma (float x)
{
//
// Convert a floating-point pixel value to an 8-bit gamma-2.2
// preview pixel. (This routine is a simplified version of
// how the exrdisplay program transforms floating-point pixel
// values in order to display them on the screen.)
//
x = pow (5.5555f * max (0.f, x), 0.4545f) * 84.66f;
return (unsigned char) clamp (x, 0.f, 255.f);
}
void
makePreviewImage (const Array2D <Rgba> &pixels,
int width,
int height,
Array2D <PreviewRgba> &previewPixels,
int &previewWidth,
int &previewHeight)
{
const int N = 8;
previewWidth = width / N;
previewHeight = height / N;
previewPixels.resizeErase (previewHeight, previewWidth);
for (int y = 0; y < previewHeight; ++y)
{
for (int x = 0; x < previewWidth; ++x)
{
const Rgba &inPixel = pixels[y * N][x * N];
PreviewRgba &outPixel = previewPixels[y][x];
outPixel.r = gamma (inPixel.r);
outPixel.g = gamma (inPixel.g);
outPixel.b = gamma (inPixel.b);
outPixel.a = int (clamp (inPixel.a * 255.f, 0.f, 255.f) + 0.5f);
}
}
}
void
writeRgbaWithPreview1 (const char fileName[],
const Array2D <Rgba> &pixels,
int width,
int height)
{
//
// Write an image file with a preview image, version 1:
//
// - generate the preview image by subsampling the main image
// - generate a file header
// - add the preview image to the file header
// - open the file (this stores the header with the
// preview image in the file)
// - describe the memory layout of the main image's pixels
// - store the main image's pixels in the file
//
Array2D <PreviewRgba> previewPixels;
int previewWidth;
int previewHeight;
makePreviewImage (pixels, width, height,
previewPixels, previewWidth, previewHeight);
Header header (width, height);
header.setPreviewImage
(PreviewImage (previewWidth, previewHeight, &previewPixels[0][0]));
RgbaOutputFile file (fileName, header, WRITE_RGBA);
file.setFrameBuffer (&pixels[0][0], 1, width);
file.writePixels (height);
}
void
writeRgbaWithPreview2 (const char fileName[],
int width,
int height)
{
//
// Write an image file with a preview image, version 2:
//
// - generate a file header
// - add a dummy preview image to the file header
// - open the file (this stores the header with the dummy
// preview image in the file)
// - render the main image's pixels one scan line at a time,
// and store each scan line in the file before rendering
// the next scan line
// - generate the preview image on the fly, while the main
// image is being rendered
// - once the main image has been rendered, store the preview
// image in the file, overwriting the dummy preview
//
Array <Rgba> pixels (width);
const int N = 8;
int previewWidth = width / N;
int previewHeight = height / N;
Array2D <PreviewRgba> previewPixels (previewHeight, previewWidth);
Header header (width, height);
header.setPreviewImage (PreviewImage (previewWidth, previewHeight));
RgbaOutputFile file (fileName, header, WRITE_RGBA);
file.setFrameBuffer (pixels, 1, 0);
for (int y = 0; y < height; ++y)
{
drawImage7 (pixels, width, height, y);
file.writePixels (1);
if (y % N == 0)
{
for (int x = 0; x < width; x += N)
{
const Rgba &inPixel = pixels[x];
PreviewRgba &outPixel = previewPixels[y / N][x / N];
outPixel.r = gamma (inPixel.r);
outPixel.g = gamma (inPixel.g);
outPixel.b = gamma (inPixel.b);
outPixel.a = int (clamp (inPixel.a * 255.f, 0.f, 255.f) + 0.5f);
}
}
}
file.updatePreviewImage (&previewPixels[0][0]);
}
void
previewImageExamples ()
{
cout << "\nfiles with preview images\n" << endl;
cout << "drawing image then writing file" << endl;
int w = 800;
int h = 600;
Array2D<Rgba> p (h, w);
drawImage1 (p, w, h);
writeRgbaWithPreview1 ("rgbaWithPreview1.exr", p, w, h);
cout << "drawing image while writing file" << endl;
writeRgbaWithPreview2 ("rgbaWithPreview2.exr", w, h);
cout << endl;
}

View File

@ -0,0 +1,35 @@
///////////////////////////////////////////////////////////////////////////
//
// Copyright (c) 2012, Industrial Light & Magic, a division of Lucas
// Digital Ltd. LLC
//
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are
// met:
// * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above
// copyright notice, this list of conditions and the following disclaimer
// in the documentation and/or other materials provided with the
// distribution.
// * Neither the name of Industrial Light & Magic nor the names of
// its contributors may be used to endorse or promote products derived
// from this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
//
///////////////////////////////////////////////////////////////////////////
void previewImageExamples ();

View File

@ -0,0 +1,265 @@
///////////////////////////////////////////////////////////////////////////
//
// Copyright (c) 2004, Industrial Light & Magic, a division of Lucas
// Digital Ltd. LLC
//
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are
// met:
// * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above
// copyright notice, this list of conditions and the following disclaimer
// in the documentation and/or other materials provided with the
// distribution.
// * Neither the name of Industrial Light & Magic nor the names of
// its contributors may be used to endorse or promote products derived
// from this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
//
///////////////////////////////////////////////////////////////////////////
//-----------------------------------------------------------------------------
//
// Code examples that show how class RgbaInputFile and
// class RgbaOutputFile can be used to read and write
// OpenEXR image files with 16-bit floating-point red,
// green, blue and alpha channels.
//
//-----------------------------------------------------------------------------
#include <ImfRgbaFile.h>
#include <ImfStringAttribute.h>
#include <ImfMatrixAttribute.h>
#include <ImfArray.h>
#include "drawImage.h"
#include <iostream>
#include <algorithm>
#include "namespaceAlias.h"
using namespace IMF;
using namespace std;
using namespace IMATH_NAMESPACE;
void
writeRgba1 (const char fileName[],
const Rgba *pixels,
int width,
int height)
{
//
// Write an RGBA image using class RgbaOutputFile.
//
// - open the file
// - describe the memory layout of the pixels
// - store the pixels in the file
//
RgbaOutputFile file (fileName, width, height, WRITE_RGBA);
file.setFrameBuffer (pixels, 1, width);
file.writePixels (height);
}
void
writeRgba2 (const char fileName[],
const Rgba *pixels,
int width,
int height,
const Box2i &dataWindow)
{
//
// Write an RGBA image using class RgbaOutputFile.
// Don't store the whole image in the file, but
// crop it according to the given data window.
//
// - open the file
// - describe the memory layout of the pixels
// - store the pixels in the file
//
Box2i displayWindow (V2i (0, 0), V2i (width - 1, height - 1));
RgbaOutputFile file (fileName, displayWindow, dataWindow, WRITE_RGBA);
file.setFrameBuffer (pixels, 1, width);
file.writePixels (dataWindow.max.y - dataWindow.min.y + 1);
}
void
writeRgba3 (const char fileName[],
const Rgba *pixels,
int width,
int height,
const char comments[],
const M44f &cameraTransform)
{
//
// Write an RGBA image using class RgbaOutputFile.
// Store two extra attributes in the image header:
// a string and a 4x4 transformation matrix.
//
// - open the file
// - describe the memory layout of the pixels
// - store the pixels in the file
//
Header header (width, height);
header.insert ("comments", StringAttribute (comments));
header.insert ("cameraTransform", M44fAttribute (cameraTransform));
RgbaOutputFile file (fileName, header, WRITE_RGBA);
file.setFrameBuffer (pixels, 1, width);
file.writePixels (height);
}
void
readRgba1 (const char fileName[],
Array2D<Rgba> &pixels,
int &width,
int &height)
{
//
// Read an RGBA image using class RgbaInputFile:
//
// - open the file
// - allocate memory for the pixels
// - describe the memory layout of the pixels
// - read the pixels from the file
//
RgbaInputFile file (fileName);
Box2i dw = file.dataWindow();
width = dw.max.x - dw.min.x + 1;
height = dw.max.y - dw.min.y + 1;
pixels.resizeErase (height, width);
file.setFrameBuffer (&pixels[0][0] - dw.min.x - dw.min.y * width, 1, width);
file.readPixels (dw.min.y, dw.max.y);
}
void
readRgba2 (const char fileName[])
{
//
// Read an RGBA image using class RgbaInputFile.
// Read the pixels, 10 scan lines at a time, and
// store the pixel data in a buffer that is just
// large enough to hold 10 scan lines worth of data.
//
// - open the file
// - allocate memory for the pixels
// - for each block of 10 scan lines,
// describe the memory layout of the pixels,
// read the pixels from the file,
// process the pixels and discard them
//
RgbaInputFile file (fileName);
Box2i dw = file.dataWindow();
int width = dw.max.x - dw.min.x + 1;
int height = dw.max.y - dw.min.y + 1;
Array2D<Rgba> pixels (10, width);
while (dw.min.y <= dw.max.y)
{
file.setFrameBuffer (&pixels[0][0] - dw.min.x - dw.min.y * width,
1, width);
file.readPixels (dw.min.y, min (dw.min.y + 9, dw.max.y));
// processPixels (pixels)
dw.min.y += 10;
}
}
void
readHeader (const char fileName[])
{
//
// Read an image's header from a file, and if the header
// contains comments and camera transformation attributes,
// print the values of those attributes.
//
// - open the file
// - get the file header
// - look for the attributes
//
RgbaInputFile file (fileName);
const StringAttribute *comments =
file.header().findTypedAttribute <StringAttribute> ("comments");
const M44fAttribute *cameraTransform =
file.header().findTypedAttribute <M44fAttribute> ("cameraTransform");
if (comments)
cout << "comments\n " << comments->value() << endl;
if (cameraTransform)
cout << "cameraTransform\n" << cameraTransform->value() << flush;
}
void
rgbaInterfaceExamples ()
{
cout << "\nRGBA images\n" << endl;
cout << "drawing image" << endl;
int w = 800;
int h = 600;
Array2D<Rgba> p (h, w);
drawImage1 (p, w, h);
cout << "writing entire image" << endl;
writeRgba1 ("rgba1.exr", &p[0][0], w, h);
cout << "writing cropped image" << endl;
writeRgba2 ("rgba2.exr", &p[0][0], w, h,
Box2i (V2i (w/6, h/6), V2i (w/2, h/2)));
cout << "writing image with extra header attributes" << endl;
writeRgba3 ("rgba3.exr", &p[0][0], w, h,
"may contain peanuts", M44f());
cout << "reading rgba file" << endl;
readRgba1 ("rgba2.exr", p, w, h);
cout << "reading rgba file into 10-scanline buffer" << endl;
readRgba2 ("rgba2.exr");
cout << "reading extra file header attributes" << endl;
readHeader ("rgba3.exr");
}

View File

@ -0,0 +1,35 @@
///////////////////////////////////////////////////////////////////////////
//
// Copyright (c) 2012, Industrial Light & Magic, a division of Lucas
// Digital Ltd. LLC
//
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are
// met:
// * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above
// copyright notice, this list of conditions and the following disclaimer
// in the documentation and/or other materials provided with the
// distribution.
// * Neither the name of Industrial Light & Magic nor the names of
// its contributors may be used to endorse or promote products derived
// from this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
//
///////////////////////////////////////////////////////////////////////////
void rgbaInterfaceExamples ();

View File

@ -0,0 +1,346 @@
///////////////////////////////////////////////////////////////////////////
//
// Copyright (c) 2004, Industrial Light & Magic, a division of Lucas
// Digital Ltd. LLC
//
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are
// met:
// * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above
// copyright notice, this list of conditions and the following disclaimer
// in the documentation and/or other materials provided with the
// distribution.
// * Neither the name of Industrial Light & Magic nor the names of
// its contributors may be used to endorse or promote products derived
// from this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
//
///////////////////////////////////////////////////////////////////////////
//-----------------------------------------------------------------------------
//
// Code examples that show how class TiledRgbaInputFile and
// class TiledRgbaOutputFile can be used to read and write
// OpenEXR image files with 16-bit floating-point red,
// green, blue and alpha channels.
//
//-----------------------------------------------------------------------------
#include <ImfTiledRgbaFile.h>
#include <ImfStringAttribute.h>
#include <ImfMatrixAttribute.h>
#include <ImfArray.h>
#include "drawImage.h"
#include <iostream>
#include "namespaceAlias.h"
using namespace IMF;
using namespace std;
using namespace IMATH_NAMESPACE;
void
writeTiledRgbaONE1 (const char fileName[],
const Rgba *pixels,
int width, int height,
int tileWidth, int tileHeight)
{
//
// Write a tiled image with one level using an image-sized framebuffer.
//
TiledRgbaOutputFile out (fileName,
width, height, // image size
tileWidth, tileHeight, // tile size
ONE_LEVEL, // level mode
ROUND_DOWN, // rounding mode
WRITE_RGBA); // channels in file
out.setFrameBuffer (pixels, 1, width);
out.writeTiles (0, out.numXTiles() - 1, 0, out.numYTiles() - 1);
}
void
writeTiledRgbaONE2 (const char fileName[],
int width, int height,
int tileWidth, int tileHeight)
{
//
// Write a tiled image with one level using a tile-sized framebuffer.
//
TiledRgbaOutputFile out (fileName,
width, height, // image size
tileWidth, tileHeight, // tile size
ONE_LEVEL, // level mode
ROUND_DOWN, // rounding mode
WRITE_RGBA); // channels in file
Array2D<Rgba> pixels (tileHeight, tileWidth);
for (int tileY = 0; tileY < out.numYTiles (); ++tileY)
{
for (int tileX = 0; tileX < out.numXTiles (); ++tileX)
{
Box2i range = out.dataWindowForTile (tileX, tileY);
drawImage3 (pixels,
width, height,
range.min.x, range.max.x + 1,
range.min.y, range.max.y + 1,
0, 0);
out.setFrameBuffer (&pixels[-range.min.y][-range.min.x],
1, // xStride
tileWidth); // yStride
out.writeTile (tileX, tileY);
}
}
}
void
writeTiledRgbaMIP1 (const char fileName[],
int width, int height,
int tileWidth, int tileHeight)
{
//
// Write a tiled image with mipmap levels using an image-sized framebuffer.
//
TiledRgbaOutputFile out (fileName,
width, height, // image size
tileWidth, tileHeight, // tile size
MIPMAP_LEVELS, // level mode
ROUND_DOWN, // rounding mode
WRITE_RGBA); // channels in file
Array2D<Rgba> pixels (height, width);
out.setFrameBuffer (&pixels[0][0], 1, width);
for (int level = 0; level < out.numLevels (); ++level)
{
drawImage4 (pixels,
out.levelWidth (level), out.levelHeight (level),
0, out.levelWidth (level),
0, out.levelHeight (level),
level, level);
out.writeTiles (0, out.numXTiles (level) - 1,
0, out.numYTiles (level) - 1,
level);
}
}
void
writeTiledRgbaMIP2 (const char fileName[],
int width, int height,
int tileWidth, int tileHeight)
{
//
// Write a tiled image with mipmap levels using a tile-sized framebuffer.
//
TiledRgbaOutputFile out (fileName,
width, height, // image size
tileWidth, tileHeight, // tile size
MIPMAP_LEVELS, // level mode
ROUND_DOWN, // rounding mode
WRITE_RGBA); // channels in file
Array2D<Rgba> pixels (tileHeight, tileWidth);
for (int level = 0; level < out.numLevels (); ++level)
{
for (int tileY = 0; tileY < out.numYTiles (level); ++tileY)
{
for (int tileX = 0; tileX < out.numXTiles (level); ++tileX)
{
Box2i range = out.dataWindowForTile (tileX, tileY, level);
drawImage4 (pixels,
out.levelWidth (level), out.levelHeight (level),
range.min.x, range.max.x + 1,
range.min.y, range.max.y + 1,
level, level);
out.setFrameBuffer (&pixels[-range.min.y][-range.min.x],
1, // xStride
tileWidth); // yStride
out.writeTile (tileX, tileY, level);
}
}
}
}
void
writeTiledRgbaRIP1 (const char fileName[],
int width, int height,
int tileWidth, int tileHeight)
{
//
// Write a tiled image with ripmap levels using an image-sized framebuffer.
//
TiledRgbaOutputFile out (fileName,
width, height, // image size
tileWidth, tileHeight, // tile size
RIPMAP_LEVELS, // level mode
ROUND_DOWN, // rounding mode
WRITE_RGBA); // channels in file
Array2D<Rgba> pixels (height, width);
out.setFrameBuffer (&pixels[0][0], 1, width);
for (int yLevel = 0; yLevel < out.numYLevels (); ++yLevel)
{
for (int xLevel = 0; xLevel < out.numXLevels (); ++xLevel)
{
drawImage5 (pixels,
out.levelWidth (xLevel), out.levelHeight (yLevel),
0, out.levelWidth (xLevel),
0, out.levelHeight (yLevel),
xLevel, yLevel);
out.writeTiles (0, out.numXTiles (xLevel) - 1,
0, out.numYTiles (yLevel) - 1,
xLevel,
yLevel);
}
}
}
void
writeTiledRgbaRIP2 (const char fileName[],
int width, int height,
int tileWidth, int tileHeight)
{
//
// Write a tiled image with ripmap levels using a tile-sized framebuffer.
//
TiledRgbaOutputFile out (fileName,
width, height, // image size
tileWidth, tileHeight, // tile size
RIPMAP_LEVELS, // level mode
ROUND_DOWN, // rounding mode
WRITE_RGBA); // channels in file
Array2D<Rgba> pixels (tileHeight, tileWidth);
for (int yLevel = 0; yLevel < out.numYLevels(); ++yLevel)
{
for (int xLevel = 0; xLevel < out.numXLevels(); ++xLevel)
{
for (int tileY = 0; tileY < out.numYTiles (yLevel); ++tileY)
{
for (int tileX = 0; tileX < out.numXTiles (xLevel); ++tileX)
{
Box2i range = out.dataWindowForTile (tileX, tileY,
xLevel, yLevel);
drawImage5 (pixels ,
out.levelWidth(xLevel), out.levelHeight(yLevel),
range.min.x, range.max.x + 1,
range.min.y, range.max.y + 1,
xLevel, yLevel);
out.setFrameBuffer (&pixels[-range.min.y][-range.min.x],
1, // xStride
tileWidth); // yStride
out.writeTile (tileX, tileY, xLevel, yLevel);
}
}
}
}
}
void
readTiledRgba1 (const char fileName[],
Array2D<Rgba> &pixels,
int &width,
int &height)
{
TiledRgbaInputFile in (fileName);
Box2i dw = in.dataWindow();
width = dw.max.x - dw.min.x + 1;
height = dw.max.y - dw.min.y + 1;
int dx = dw.min.x;
int dy = dw.min.y;
pixels.resizeErase (height, width);
in.setFrameBuffer (&pixels[-dy][-dx], 1, width);
in.readTiles (0, in.numXTiles() - 1, 0, in.numYTiles() - 1);
}
void
rgbaInterfaceTiledExamples ()
{
cout << "\nRGBA tiled images\n" << endl;
const int tw = 100;
const int th = 75;
int w = 600;
int h = 400;
cout << "writing tiled image with image-size framebuffer" << endl;
Array2D<Rgba> pixels (h, w);
drawImage3 (pixels, w, h, 0, w, 0, h, 0);
writeTiledRgbaONE1 ("tiledrgba1.exr", &pixels[0][0], w, h, tw, th);
cout << "writing tiled image with tile-size framebuffer" << endl;
writeTiledRgbaONE2 ("tiledrgba2.exr", w, h, tw, th);
cout << "writing tiled mipmap image with image-size framebuffer" << endl;
writeTiledRgbaMIP1 ("tiledrgba3.exr", 512, 512, tw, th);
cout << "writing tiled mipmap image with tile-size framebuffer" << endl;
writeTiledRgbaMIP2 ("tiledrgba4.exr", 512, 512, tw, th);
cout << "writing tiled ripmap image with image-size framebuffer" << endl;
writeTiledRgbaRIP1 ("tiledrgba5.exr", 256, 256, tw, th);
cout << "writing tiled ripmap image with tile-size framebuffer" << endl;
writeTiledRgbaRIP2 ("tiledrgba6.exr", 256, 256, tw, th);
cout << "reading tiled rgba file" << endl;
readTiledRgba1 ("tiledrgba1.exr", pixels, w, h);
}

View File

@ -0,0 +1,36 @@
///////////////////////////////////////////////////////////////////////////
//
// Copyright (c) 2012, Industrial Light & Magic, a division of Lucas
// Digital Ltd. LLC
//
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are
// met:
// * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above
// copyright notice, this list of conditions and the following disclaimer
// in the documentation and/or other materials provided with the
// distribution.
// * Neither the name of Industrial Light & Magic nor the names of
// its contributors may be used to endorse or promote products derived
// from this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
//
///////////////////////////////////////////////////////////////////////////
void rgbaInterfaceTiledExamples ();