|
Packit |
0d464f |
//////////////////////////////////////////////////////////////////////////////
|
|
Packit |
0d464f |
//
|
|
Packit |
0d464f |
// Copyright (c) 2004-2012, Industrial Light & Magic, a division of Lucasfilm
|
|
Packit |
0d464f |
// Entertainment Company Ltd. Portions contributed and copyright held by
|
|
Packit |
0d464f |
// others as indicated. All rights reserved.
|
|
Packit |
0d464f |
//
|
|
Packit |
0d464f |
// Redistribution and use in source and binary forms, with or without
|
|
Packit |
0d464f |
// modification, are permitted provided that the following conditions are
|
|
Packit |
0d464f |
// met:
|
|
Packit |
0d464f |
//
|
|
Packit |
0d464f |
// * Redistributions of source code must retain the above
|
|
Packit |
0d464f |
// copyright notice, this list of conditions and the following
|
|
Packit |
0d464f |
// disclaimer.
|
|
Packit |
0d464f |
//
|
|
Packit |
0d464f |
// * Redistributions in binary form must reproduce the above
|
|
Packit |
0d464f |
// copyright notice, this list of conditions and the following
|
|
Packit |
0d464f |
// disclaimer in the documentation and/or other materials provided with
|
|
Packit |
0d464f |
// the distribution.
|
|
Packit |
0d464f |
//
|
|
Packit |
0d464f |
// * Neither the name of Industrial Light & Magic nor the names of
|
|
Packit |
0d464f |
// any other contributors to this software may be used to endorse or
|
|
Packit |
0d464f |
// promote products derived from this software without specific prior
|
|
Packit |
0d464f |
// written permission.
|
|
Packit |
0d464f |
//
|
|
Packit |
0d464f |
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
|
|
Packit |
0d464f |
// IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
|
Packit |
0d464f |
// THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
|
Packit |
0d464f |
// PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
|
|
Packit |
0d464f |
// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
|
Packit |
0d464f |
// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
|
Packit |
0d464f |
// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
|
Packit |
0d464f |
// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
|
Packit |
0d464f |
// LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
|
Packit |
0d464f |
// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
|
Packit |
0d464f |
// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
Packit |
0d464f |
//
|
|
Packit |
0d464f |
//////////////////////////////////////////////////////////////////////////////
|
|
Packit |
0d464f |
|
|
Packit |
0d464f |
|
|
Packit |
0d464f |
#include <ImfTiledRgbaFile.h>
|
|
Packit |
0d464f |
#include <ImfArray.h>
|
|
Packit |
0d464f |
#include <ImfThreading.h>
|
|
Packit |
0d464f |
#include "IlmThread.h"
|
|
Packit |
0d464f |
#include <stdio.h>
|
|
Packit |
0d464f |
#include <assert.h>
|
|
Packit |
0d464f |
#include <math.h>
|
|
Packit |
0d464f |
|
|
Packit |
0d464f |
|
|
Packit |
0d464f |
using namespace OPENEXR_IMF_NAMESPACE;
|
|
Packit |
0d464f |
using namespace std;
|
|
Packit |
0d464f |
using namespace IMATH_NAMESPACE;
|
|
Packit |
0d464f |
|
|
Packit |
0d464f |
|
|
Packit |
0d464f |
namespace {
|
|
Packit |
0d464f |
|
|
Packit |
0d464f |
void
|
|
Packit |
0d464f |
waves (Array2D<Rgba> &pixels, int w, int h)
|
|
Packit |
0d464f |
{
|
|
Packit |
0d464f |
for (int y = 0; y < h; ++y)
|
|
Packit |
0d464f |
{
|
|
Packit |
0d464f |
for (int x = 0; x < w; ++x)
|
|
Packit |
0d464f |
{
|
|
Packit |
0d464f |
Rgba &p = pixels[y][x];
|
|
Packit |
0d464f |
|
|
Packit |
0d464f |
p.r = (0.5 + 0.5 * sin (0.1 * x + 0.1 * y)) +
|
|
Packit |
0d464f |
(0.5 + 0.5 * sin (-0.1 * x + 0.2 * y));
|
|
Packit |
0d464f |
|
|
Packit |
0d464f |
p.g = p.r;
|
|
Packit |
0d464f |
p.b = p.r;
|
|
Packit |
0d464f |
|
|
Packit |
0d464f |
p.a = (0.5 + 0.5 * sin (1.1 * x + 0.5 * y));
|
|
Packit |
0d464f |
}
|
|
Packit |
0d464f |
}
|
|
Packit |
0d464f |
}
|
|
Packit |
0d464f |
|
|
Packit |
0d464f |
|
|
Packit |
0d464f |
void
|
|
Packit |
0d464f |
wheel (Array2D<Rgba> &pixels, int w, int h)
|
|
Packit |
0d464f |
{
|
|
Packit |
0d464f |
float n = 40;
|
|
Packit |
0d464f |
float m = 0.5;
|
|
Packit |
0d464f |
float radMin = 2 * n / M_PI;
|
|
Packit |
0d464f |
float xCen = w * 0.5;
|
|
Packit |
0d464f |
float yCen = h * 0.5;
|
|
Packit |
0d464f |
float radMax = (xCen < yCen)? xCen: yCen;
|
|
Packit |
0d464f |
|
|
Packit |
0d464f |
for (int y = 0; y < h; ++y)
|
|
Packit |
0d464f |
{
|
|
Packit |
0d464f |
for (int x = 0; x < w; ++x)
|
|
Packit |
0d464f |
{
|
|
Packit |
0d464f |
Rgba &p = pixels[y][x];
|
|
Packit |
0d464f |
float rad = sqrt ((x-xCen) * (x-xCen) + (y-yCen) * (y-yCen));
|
|
Packit |
0d464f |
|
|
Packit |
0d464f |
if (rad <= radMax && rad >= radMin)
|
|
Packit |
0d464f |
{
|
|
Packit |
0d464f |
float phi = atan2 (y - yCen, x - xCen);
|
|
Packit |
0d464f |
float c = 0.5 + 0.5 * sin (phi * n + rad * m);
|
|
Packit |
0d464f |
|
|
Packit |
0d464f |
p.r = 0.5 + 0.5 * c;
|
|
Packit |
0d464f |
p.g = p.r;
|
|
Packit |
0d464f |
p.b = p.r;
|
|
Packit |
0d464f |
p.a = 0.5 - 0.5 * c;
|
|
Packit |
0d464f |
}
|
|
Packit |
0d464f |
else
|
|
Packit |
0d464f |
{
|
|
Packit |
0d464f |
p.r = 0.5;
|
|
Packit |
0d464f |
p.g = p.r;
|
|
Packit |
0d464f |
p.b = p.r;
|
|
Packit |
0d464f |
p.a = p.r;
|
|
Packit |
0d464f |
}
|
|
Packit |
0d464f |
}
|
|
Packit |
0d464f |
}
|
|
Packit |
0d464f |
}
|
|
Packit |
0d464f |
|
|
Packit |
0d464f |
|
|
Packit |
0d464f |
void
|
|
Packit |
0d464f |
writeReadYa (Box2i &dw,
|
|
Packit |
0d464f |
int tileSizeX,
|
|
Packit |
0d464f |
int tileSizeY,
|
|
Packit |
0d464f |
const char fileName[],
|
|
Packit |
0d464f |
void (* fillPixels) (Array2D<Rgba> &pixels, int w, int h))
|
|
Packit |
0d464f |
{
|
|
Packit |
0d464f |
int w = dw.max.x - dw.min.x + 1;
|
|
Packit |
0d464f |
int h = dw.max.y - dw.min.y + 1;
|
|
Packit |
0d464f |
Array2D <Rgba> pixels1 (h, w);
|
|
Packit |
0d464f |
Array2D <Rgba> pixels2 (h, w);
|
|
Packit |
0d464f |
|
|
Packit |
0d464f |
fillPixels (pixels1, w, h);
|
|
Packit |
0d464f |
|
|
Packit |
0d464f |
cout << "writing " << flush;
|
|
Packit |
0d464f |
|
|
Packit |
0d464f |
{
|
|
Packit |
0d464f |
TiledRgbaOutputFile out (fileName,
|
|
Packit |
0d464f |
tileSizeX, tileSizeY,
|
|
Packit |
0d464f |
ONE_LEVEL, ROUND_DOWN,
|
|
Packit |
0d464f |
dw, dw,
|
|
Packit |
0d464f |
WRITE_YA);
|
|
Packit |
0d464f |
|
|
Packit |
0d464f |
out.setFrameBuffer (&pixels1[-dw.min.y][-dw.min.x], 1, w);
|
|
Packit |
0d464f |
out.writeTiles (0, out.numXTiles() - 1, 0, out.numYTiles() - 1);
|
|
Packit |
0d464f |
}
|
|
Packit |
0d464f |
|
|
Packit |
0d464f |
cout << "reading " << flush;
|
|
Packit |
0d464f |
|
|
Packit |
0d464f |
{
|
|
Packit |
0d464f |
TiledRgbaInputFile in (fileName);
|
|
Packit |
0d464f |
|
|
Packit |
0d464f |
in.setFrameBuffer (&pixels2[-dw.min.y][-dw.min.x], 1, w);
|
|
Packit |
0d464f |
in.readTiles (0, in.numXTiles() - 1, 0, in.numYTiles() - 1);
|
|
Packit |
0d464f |
}
|
|
Packit |
0d464f |
|
|
Packit |
0d464f |
cout << "comparing" << endl;
|
|
Packit |
0d464f |
|
|
Packit |
0d464f |
for (int y = 0; y < h; ++y)
|
|
Packit |
0d464f |
{
|
|
Packit |
0d464f |
for (int x = 0; x < w; ++x)
|
|
Packit |
0d464f |
{
|
|
Packit |
0d464f |
const Rgba &p1 = pixels1[y][x];
|
|
Packit |
0d464f |
const Rgba &p2 = pixels2[y][x];
|
|
Packit |
0d464f |
|
|
Packit |
0d464f |
assert (p1.r == p2.r);
|
|
Packit |
0d464f |
assert (p1.g == p2.g);
|
|
Packit |
0d464f |
assert (p1.b == p2.b);
|
|
Packit |
0d464f |
assert (p1.a == p2.a);
|
|
Packit |
0d464f |
}
|
|
Packit |
0d464f |
}
|
|
Packit |
0d464f |
|
|
Packit |
0d464f |
remove (fileName);
|
|
Packit |
0d464f |
}
|
|
Packit |
0d464f |
|
|
Packit |
0d464f |
} // namespace
|
|
Packit |
0d464f |
|
|
Packit |
0d464f |
|
|
Packit |
0d464f |
void
|
|
Packit |
0d464f |
testTiledYa (const std::string &tempDir)
|
|
Packit |
0d464f |
{
|
|
Packit |
0d464f |
try
|
|
Packit |
0d464f |
{
|
|
Packit |
0d464f |
cout << "Testing tiled luminance input and output" << endl;
|
|
Packit |
0d464f |
|
|
Packit |
0d464f |
std::string fileName = tempDir + "imf_test_tiled_ya.exr";
|
|
Packit |
0d464f |
|
|
Packit |
0d464f |
int maxThreads = ILMTHREAD_NAMESPACE::supportsThreads()? 3: 0;
|
|
Packit |
0d464f |
|
|
Packit |
0d464f |
for (int n = 0; n <= maxThreads; ++n)
|
|
Packit |
0d464f |
{
|
|
Packit |
0d464f |
if (ILMTHREAD_NAMESPACE::supportsThreads())
|
|
Packit |
0d464f |
{
|
|
Packit |
0d464f |
setGlobalThreadCount (n);
|
|
Packit |
0d464f |
cout << "\nnumber of threads: " << globalThreadCount() << endl;
|
|
Packit |
0d464f |
}
|
|
Packit |
0d464f |
|
|
Packit |
0d464f |
Box2i dataWindow (V2i (-17, -29), V2i (348, 556));
|
|
Packit |
0d464f |
writeReadYa (dataWindow, 19, 27, fileName.c_str(), waves);
|
|
Packit |
0d464f |
writeReadYa (dataWindow, 19, 27, fileName.c_str(), wheel);
|
|
Packit |
0d464f |
}
|
|
Packit |
0d464f |
|
|
Packit |
0d464f |
cout << "ok\n" << endl;
|
|
Packit |
0d464f |
}
|
|
Packit |
0d464f |
catch (const std::exception &e)
|
|
Packit |
0d464f |
{
|
|
Packit |
0d464f |
cerr << "ERROR -- caught exception: " << e.what() << endl;
|
|
Packit |
0d464f |
assert (false);
|
|
Packit |
0d464f |
}
|
|
Packit |
0d464f |
}
|