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,17 @@
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
CVS

View File

@ -0,0 +1,32 @@
ADD_EXECUTABLE ( exrdisplay
main.cpp
ImageView.cpp
ImageView.h
loadImage.cpp
loadImage.h
scaleImage.cpp
scaleImage.h
applyCtl.cpp
applyCtl.h
GlWindow3d.h
GlWindow3d.cpp
)
INCLUDE_DIRECTORIES (
${FLTK_INCLUDE_DIR}
)
TARGET_LINK_LIBRARIES ( exrdisplay
IlmImf${OPENEXR_LIBSUFFIX}
Iex${ILMBASE_LIBSUFFIX}
Half
${FLTK_LIBRARIES}
${OPENGL_LIBRARIES}
)
INSTALL ( TARGETS
exrdisplay
DESTINATION
${CMAKE_INSTALL_PREFIX}/bin
)

View File

@ -0,0 +1,400 @@
///////////////////////////////////////////////////////////////////////////
//
// 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.
//
///////////////////////////////////////////////////////////////////////////
//----------------------------------------------------------------------------
//
// class GlWindow3d -- reconstructs deep image in a 3D OpenGl window
//
//----------------------------------------------------------------------------
#include "GlWindow3d.h"
#include <FL/fl_draw.H>
#include <string.h>
#include <algorithm>
using std::max;
using std::min;
using std::cout;
using std::endl;
using std::cerr;
GlWindow::GlWindow (int x,int y,
int w,int h,
const char *l,
const IMF::Rgba pixels[],
float* dataZ[],
unsigned int sampleCount[],
int dx, int dy,
float zmax, float zmin,
float farPlane)
:
Fl_Gl_Window (x,y,w,h,l),
_rawPixels (pixels),
_dataZ (dataZ),
_sampleCount (sampleCount),
_dx (dx),
_dy (dy),
_zmax (zmax),
_zmin (zmin),
_farPlane (farPlane)
{
Fl::add_timeout (FPS, Timer_CallBack, (void*)this); // 24fps timer
// check zmax and zmin
if (zmax < zmin)
{
cerr << "z max: "<< zmax << ", z min: " << zmin << endl;
cerr << "z value bound error" << endl;
exit(1);
}
_fitTran = -(_zmax + _zmin) / 2.0;
_fitScale = 1.0;
if (_zmax != _zmin)
_fitScale = 1.0 / (_zmax - _zmin);
}
GlWindow::~GlWindow ()
{
for (int y = 0; y < _dy; y++)
{
for (int x = 0; x < _dx; x++)
{
delete _dataZ[y * _dx + x];
}
}
delete [] _sampleCount;
delete [] _rawPixels;
}
void
GlWindow::Perspective (GLdouble focal, GLdouble aspect,
GLdouble zNear, GLdouble zFar)
{
GLdouble xmin, xmax, ymin, ymax;
ymax = zNear * tan (focal * M_PI / 360.0);
ymin = -ymax;
xmin = ymin * aspect;
xmax = ymax * aspect;
glFrustum (xmin, xmax, ymin, ymax, zNear, zFar);
}
void
GlWindow::ReshapeViewport()
{
glViewport (0, 0, w(), h());
glMatrixMode (GL_PROJECTION);
glLoadIdentity();
GLfloat ratio = w() / h();
Perspective(min (max (30.0 + _zoom, 1.0), 179.0),
1.0 * ratio, 1.0, _farPlane);
glTranslatef(0.0, 0.0, -8.0);
glMatrixMode (GL_MODELVIEW);
glLoadIdentity();
}
void
GlWindow::GlInit()
{
glShadeModel (GL_FLAT);
_zoom = 0;
_translateX = 0;
_translateY = 0;
_scaleZ = 1.0;
_elevation = 0;
_azimuth = 0;
_inverted = 0;
_displayFactor = 1;
}
void
drawRefPlan()
{
glBegin (GL_LINES);
glColor3f (0.6, 0.6, 0.6);
for (int i = 0; i <= 10; i++)
{
glVertex3f (1.0 - 0.2 * i, 0.0, 1.0);
glVertex3f (1.0 - 0.2 * i, 0.0, -1.0);
glVertex3f (1.0, 0.0, 1.0 - 0.2 * i);
glVertex3f (-1.0, 0.0, 1.0 - 0.2 * i);
}
glEnd();
glBegin (GL_LINES);
glColor3f (0.3, 0.3, 0.3);
glVertex3f (0.0, 0.0, 1.0);
glVertex3f (0.0, 0.0, -1.0);
glVertex3f (1.0, 0.0, 0.0);
glVertex3f (-1.0, 0.0, 0.0);
glEnd();
}
void
drawCoord()
{
glBegin (GL_LINES);
glColor3f (0.0, 0.0, 1.0);
glVertex3f (-1.0, 0.0, 1.0);
glVertex3f (-1.0, 0.0, 0.8);
glColor3f (1.0, 0.0, 0.0);
glVertex3f (-1.0, 0.0, 1.0);
glVertex3f (-0.8, 0.0, 1.0);
glColor3f (0.0, 1.0, 0.0);
glVertex3f (-1.0, 0.0, 1.0);
glVertex3f (-1.0, 0.2, 1.0);
glEnd();
glPointSize(6);
glBegin (GL_POINTS);
glColor3f (1.0, 1.0, 0.0);
glVertex3f (-1.0, 0.0, 1.0);
glColor3f (0.0, 0.0, 1.0);
glVertex3f (-1.0, 0.0, 0.8);
glColor3f (1.0, 0.0, 0.0);
glVertex3f (-0.8, 0.0, 1.0);
glColor3f (0.0, 1.0, 0.0);
glVertex3f (-1.0, 0.2, 1.0);
glEnd();
}
void
drawOutLine(float dx, float dy, float z)
{
glBegin (GL_LINE_LOOP);
glColor3f (0.6, 0.0, 0.6);
glVertex3f (0, 0, z);
glVertex3f (0, dy, z);
glVertex3f (dx, dy, z);
glVertex3f (dx, 0, z);
glEnd();
}
void
GlWindow::draw()
{
if ( !valid() )
{
valid (1);
GlInit();
}
ReshapeViewport();
glClearColor (.5,.5,.5, 0.0);
glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glLoadIdentity();
glTranslatef (_translateX, 0.0, 0.0);
glTranslatef (0.0, -_translateY, 0.0);
glRotatef (_elevation, 1.0, 0.0, 0.0);
glRotatef (_azimuth, 0.0, 1.0, 0.0);
// draw the reference plane
drawRefPlan();
// draw the coordinate
drawCoord();
// scale z value
glScalef (1.0, 1.0, _scaleZ);
// display the objects
// move the objects to the center of display
glScalef (1.0 / _dx, 1.0 / _dx, 1.0 / 2.0);
glTranslatef (-_dx / 2.0, -_dy / 2.0, 0.0);
glScalef (1.0, 1.0, _fitScale);
glTranslatef (0.0, 0.0, -_fitTran);
// loop dataZ to draw points
glPointSize (2);
glBegin (GL_POINTS);
glColor3f (0.0, 1.0, 1.0);
for (int y = 0; y < _dy; y++)
{
for (int x = 0; x < _dx; x++)
{
if( x % (10 * _displayFactor) == 0 && y % (10 * _displayFactor) == 0)
{
float* z = _dataZ[y * _dx + x];
unsigned int count = _sampleCount[y * _dx + x];
for (unsigned int i = 0; i < count; i++)
{
float val = z[i];
glVertex3f (float(x), _dy - float(y) -1, -val);
}
}
}
}
glEnd();
// draw the display window OutLine
drawOutLine (_dx, _dy, -(_zmax + _zmin) / 2.0);
// Check gl errors
GLenum err = glGetError();
if ( err != GL_NO_ERROR )
{
cerr << "GLGETERROR = " << (int)err << endl;
}
}
int
GlWindow::handle (int event)
{
if (Fl::event_button() == FL_LEFT_MOUSE)
{
switch (event)
{
case FL_PUSH:
_mouseStartX = Fl::event_x();
_mouseStartY = Fl::event_y();
if (fabs(_elevation) > 90.0)
{
_inverted = 1;
}
else
{
_inverted = 0;
}
break;
case FL_DRAG:
case FL_RELEASE:
{
int x = Fl::event_x();
int y = Fl::event_y();
if (_inverted)
{
_azimuth -= (double)(x - _mouseStartX) * 0.2;
}
else
{
_azimuth += (double)(x - _mouseStartX) * 0.2;
}
_elevation += (double)(y - _mouseStartY) * 0.2;
while (_elevation < -180.0)
_elevation += 360.0;
while (_elevation > 180.0)
_elevation -= 360.0;
_mouseStartX = x;
_mouseStartY = y;
break;
}
default:
break;
}
}
if ( Fl::event_button() == FL_MIDDLE_MOUSE )
{
switch (event)
{
case FL_PUSH:
fl_cursor (FL_CURSOR_MOVE);
break;
case FL_RELEASE:
fl_cursor (FL_CURSOR_DEFAULT);
break;
case FL_DRAG:
int x = Fl::event_x();
int y = Fl::event_y();
_translateX += (x - _mouseX) * 0.01;
_translateY += (y - _mouseY) * 0.01;
break;
}
}
if ( event == FL_DRAG && Fl::event_button() == FL_RIGHT_MOUSE )
{
int x = Fl::event_x();
int dx = x - _mouseX;
int delta = -dx;
_zoom += delta * 0.2;
}
_mouseX = Fl::event_x();
_mouseY = Fl::event_y();
if (event == FL_KEYUP)
{
const char* text = Fl::event_text();
if (!strcmp (text, "A")) //scale up
{
_scaleZ *= 1.2;
}
if (!strcmp (text, "S")) //scale down
{
_scaleZ /= 1.2;
}
if (!strcmp (text, "F")) //fit
{
GlInit();
}
if (!strcmp (text, "D")) //decrease pixel samples
{
_displayFactor *= 2;
if (_displayFactor > (_dx/10) || _displayFactor > (_dy/10) )
_displayFactor /= 2;
}
if (!strcmp (text, "C")) //increase pixel samples
{
_displayFactor /= 2;
if (_displayFactor < 1)
_displayFactor = 1;
}
}
return Fl_Gl_Window::handle (event);
}

View File

@ -0,0 +1,119 @@
///////////////////////////////////////////////////////////////////////////
//
// 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 INCLUDED_GLWINDOW3D_H
#define INCLUDED_GLWINDOW3D_H
//----------------------------------------------------------------------------
//
// class GlWindow3d -- reconstructs deep image in a 3D OpenGl window
//
//----------------------------------------------------------------------------
#include "namespaceAlias.h"
#include <stdio.h>
#include <math.h>
#include <FL/Fl.H>
#include <FL/Fl_Window.H>
#include <FL/Fl_Gl_Window.H>
#include <FL/gl.h>
#include <ImfRgba.h>
#include <ImfArray.h>
#include <ImfNamespace.h>
#define FPS (1.0/24.0) // frames per second
class GlWindow : public Fl_Gl_Window
{
public:
GlWindow (int x,int y,
int w,int h,
const char *l,
const IMF::Rgba pixels[],
float* dataZ[],
unsigned int sampleCount[],
int dx, int dy, // data window
float zmax, float zmin,
float farPlane // zfar plane in Deep 3D window
);
~GlWindow ();
void Perspective (GLdouble focal, GLdouble aspect,
GLdouble zNear, GLdouble zFar);
void ReshapeViewport();
void GlInit();
void draw();
int handle (int event);
protected:
const IMF::Rgba * _rawPixels;
float** _dataZ;
unsigned int * _sampleCount;
int _dx;
int _dy;
float _zmax;
float _zmin;
float _farPlane;
private:
double _zoom;
double _translateX;
double _translateY;
double _scaleZ;
double _fitTran;
double _fitScale;
double _elevation; // for rotation
double _azimuth; // for rotation
int _mouseX;
int _mouseY;
int _mouseStartX;
int _mouseStartY;
int _inverted; // for rotation
int _displayFactor; // for display pixel samples
// TIMER CALLBACK
// Handles rotation of the object
//
static void Timer_CallBack (void *data)
{
GlWindow *glwin = (GlWindow*)data;
glwin->redraw();
Fl::repeat_timeout(FPS, Timer_CallBack, data);
}
};
#endif

View File

@ -0,0 +1,718 @@
///////////////////////////////////////////////////////////////////////////
//
// 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.
//
///////////////////////////////////////////////////////////////////////////
//----------------------------------------------------------------------------
//
// class ImageView
//
//----------------------------------------------------------------------------
#include "ImageView.h"
#include <ImathMath.h>
#include <ImathFun.h>
#include <ImathLimits.h>
#include <halfFunction.h>
#include <algorithm>
#include <stdio.h>
#if defined PLATFORM_WINDOWS || defined _WIN32
#include <windows.h>
#include <FL/Fl.H>
#include <GL/gl.h>
#elif defined __APPLE__
#include <FL/Fl.H>
#include <OpenGL/gl.h>
#else
#include <FL/Fl.H>
#include <GL/gl.h>
#endif
using std::min;
using std::max;
using std::cout;
using std::endl;
using std::cerr;
using namespace IMATH;
ImageView::ImageView (int x, int y,
int w, int h,
const char label[],
const IMF::Rgba pixels[],
float* dataZ[],
unsigned int sampleCount[],
int zsize,
int dw, int dh,
int dx, int dy,
Fl_Box *rgbaBox,
float farPlane,
float gamma,
float exposure,
float defog,
float kneeLow,
float kneeHigh)
:
Fl_Gl_Window (x, y, w, h, label),
_gamma (gamma),
_exposure (exposure),
_defog (defog),
_kneeLow (kneeLow),
_kneeHigh (kneeHigh),
_rawPixels (pixels),
_dataZ (dataZ),
_sampleCount (sampleCount),
_fogR (0),
_fogG (0),
_fogB (0),
_farPlane (farPlane),
_dw (dw),
_dh (dh),
_dx (dx),
_dy (dy),
_zsize (zsize),
_rgbaBox (rgbaBox),
_screenPixels (dw * dh * 3)
{
computeFogColor();
updateScreenPixels();
//
// initialize z value chart
//
_chartwin = new Fl_Window (600, 300);
_chartwin->label("Deep Pixel Display");
_chart = new Fl_Chart (20, 20,
_chartwin->w()-40,
_chartwin->h()-40,
"Sample #");
_chartMax = new Fl_Chart (20, 20,
_chartwin->w()-40,
_chartwin->h()-40,
"");
_chartMin = new Fl_Chart (20, 20,
_chartwin->w()-40,
_chartwin->h()-40,
"");
findZbound();
//
// initialize Deep 3d window
//
_gl3d = NULL;
}
void
ImageView::setExposure (float exposure)
{
_exposure = exposure;
updateScreenPixels();
redraw();
}
void
ImageView::setDefog (float defog)
{
_defog = defog;
updateScreenPixels();
redraw();
}
void
ImageView::setKneeLow (float kneeLow)
{
_kneeLow = kneeLow;
updateScreenPixels();
redraw();
}
void
ImageView::findZbound()
{
//
// find zmax and zmin values of deep data to set bound
//
float zmax = limits<float>::min();
float zmin = limits<float>::max();
_maxCount = 0;
for (int k = 0; k < _zsize; k++)
{
float* z = _dataZ[k];
unsigned int count = _sampleCount[k];
if (_maxCount < count)
_maxCount = count;
for (unsigned int i = 0; i < count; i++)
{
double val = double(z[i]);
if (val > zmax && val < _farPlane)
zmax = val;
if (val < zmin)
zmin = val;
}
}
if ( zmax > zmin)
{
cout << "z max: "<< zmax << ", z min: " << zmin << endl;
_chart->bounds (zmin, zmax);
}
_zmax = zmax;
_zmin = zmin;
}
void
ImageView::setPixels(const IMF::Rgba pixels[/* w*h */],
float* dataZ[/* w*h */],
unsigned int sampleCount[/* w*h */],
int zsize,
int dw, int dh, int dx, int dy)
{
//
// update data of imageview
//
_rawPixels = pixels;
_dw = dw;
_dh = dh;
_dx = dx;
_dy = dy;
_dataZ = dataZ;
_sampleCount = sampleCount;
_zsize = zsize;
_screenPixels.resizeErase(dw*dh*3);
findZbound();
//
// update Deep 3d window
//
GlWindow* temp;
temp = _gl3d;
_gl3d = NULL;
if (_gl3d != NULL){
delete temp;
}
updateScreenPixels();
redraw();
}
void
ImageView::clearDataDisplay()
{
_chart->clear();
if (_gl3d != NULL)
_gl3d->hide();
}
void
ImageView::setKneeHigh (float kneeHigh)
{
_kneeHigh = kneeHigh;
updateScreenPixels();
redraw();
}
void
ImageView::draw()
{
if (!valid())
{
glLoadIdentity();
glViewport (0, 0, w(), h());
glOrtho(0, w(), h(), 0, -1, 1);
}
glClearColor (0.3, 0.3, 0.3, 1.0);
glClear (GL_COLOR_BUFFER_BIT);
if (_dx + _dw <= 0 || _dx >= w())
return;
for (int y = 0; y < _dh; ++y)
{
if (y + _dy < 0 || y + _dy >= h())
continue;
glRasterPos2i (max (0, _dx), y + _dy + 1);
glDrawPixels (_dw + min (0, _dx), // width
1, // height
GL_RGB, // format
GL_UNSIGNED_BYTE, // type
_screenPixels + // pixels
static_cast <ptrdiff_t> ((y * _dw - min (0, _dx)) * 3));
}
}
void
ImageView::computeFogColor ()
{
_fogR = 0;
_fogG = 0;
_fogB = 0;
for (int j = 0; j < _dw * _dh; ++j)
{
const IMF::Rgba &rp = _rawPixels[j];
if (rp.r.isFinite())
_fogR += rp.r;
if (rp.g.isFinite())
_fogG += rp.g;
if (rp.b.isFinite())
_fogB += rp.b;
}
_fogR /= _dw * _dh;
_fogG /= _dw * _dh;
_fogB /= _dw * _dh;
}
void
ImageView::drawChart (int x, int y, bool initChart)
{
if (x >= 0 && x < w() && y >= 0 && y < h())
{
int px = x - _dx;
int py = y - _dy;
if (px >= 0 && px < _dw && py >= 0 && py < _dh)
{
float* z = _dataZ[py * _dw + px];
unsigned int count = _sampleCount[py * _dw + px];
cout << "\nsample Count: " << count << endl;
cout << "x: " << px << ", y: " << py << endl;
for (unsigned int i = 0; i < count; i++)
{
printf ("pixel Z value %d: %.3f\n", i, float(z[i]));
}
const IMF::Rgba &p = _rawPixels[py * _dw + px];
cout << "R = " << p.r << ", G = " << p.g << ","
" B = " << p.b <<endl;
//
// draw the chart
//
drawChartRef();
for (unsigned int i = 0; i < count; i++)
{
double val = double(z[i]);
if (val < _farPlane)
{
static char val_str[20];
sprintf (val_str, "%.3lf", val);
_chart->add (val, val_str, FL_BLUE);
}
}
redraw();
if (initChart)
{
_chartwin->resizable (_chartwin);
_chartwin->set_non_modal(); // make chart on top
if (!_chartwin->shown())
_chartwin->show();
}
}
}
}
void
ImageView::drawChartRef ()
{
_chart->clear();
_chart->bounds(_zmin, _zmax);
_chart->type (FL_LINE_CHART);
_chart->label("Sample #");
_chartMax->clear();
_chartMax->type (FL_SPIKE_CHART);
static char val_str[20];
sprintf (val_str, "Zmax : %.3lf", _zmax);
_chartMax->label(val_str);
_chartMax->align(FL_ALIGN_TOP_LEFT);
_chartMax->box(FL_NO_BOX);
_chartMin->clear();
_chartMin->type (FL_SPIKE_CHART);
static char val_str1[20];
sprintf (val_str1, "Zmin : %.3lf", _zmin);
_chartMin->label(val_str1);
_chartMin->align(FL_ALIGN_BOTTOM_LEFT);
_chartMin->box(FL_NO_BOX);
}
int
ImageView::handle (int event)
{
if (event == FL_PUSH)
{
// We want to get the other associated events for this widget so
// return a non-zero value here.
return 1;
}
if (event == FL_MOVE)
{
//
// Print the red, green and blue values of
// the pixel at the current cursor location.
//
int x = Fl::event_x();
int y = Fl::event_y();
if (x >= 0 && x < w() && y >= 0 && y < h())
{
int px = x - _dx;
int py = y - _dy;
if (px >= 0 && px < _dw && py >= 0 && py < _dh)
{
const IMF::Rgba &p = _rawPixels[py * _dw + px];
sprintf (_rgbaBoxLabel,
"r = %.3g g = %.3g b = %.3g",
float (p.r), float (p.g), float (p.b));
}
else
{
sprintf (_rgbaBoxLabel, " ");
}
_rgbaBox->label (_rgbaBoxLabel);
if (_chartwin->shown() && _zsize > 0)
{
int x = Fl::event_x();
int y = Fl::event_y();
drawChart (x, y, false);
}
}
}
if (event == FL_RELEASE && Fl::event_button() == FL_LEFT_MOUSE)
{
//
// Open a sample chart and print the z values of
// the pixel at the current cursor location
//
if(_zsize > 0)
{
int x = Fl::event_x();
int y = Fl::event_y();
drawChart (x, y, true);
}
}
if (event == FL_RELEASE && Fl::event_button() == FL_RIGHT_MOUSE)
{
if(_zsize > 0)
{
if (_gl3d == NULL)
{
//
// initialize Deep 3d display
//
_gl3d = new GlWindow(10, 10, 500, 500,
"3D View", _rawPixels,
_dataZ, _sampleCount,
_dw, _dh, _zmax, _zmin,
_farPlane);
_gl3d->show();
}
else
{
_gl3d->show();
}
}
}
return Fl_Gl_Window::handle (event);
}
namespace {
//
// Conversion from raw pixel data to data for the OpenGL frame buffer:
//
// 1) Compensate for fogging by subtracting defog
// from the raw pixel values.
//
// 2) Multiply the defogged pixel values by
// 2^(exposure + 2.47393).
//
// 3) Values that are now 1.0 are called "middle gray".
// If defog and exposure are both set to 0.0, then
// middle gray corresponds to a raw pixel value of 0.18.
// In step 6, middle gray values will be mapped to an
// intensity 3.5 f-stops below the display's maximum
// intensity.
//
// 4) Apply a knee function. The knee function has two
// parameters, kneeLow and kneeHigh. Pixel values
// below 2^kneeLow are not changed by the knee
// function. Pixel values above kneeLow are lowered
// according to a logarithmic curve, such that the
// value 2^kneeHigh is mapped to 2^3.5. (In step 6,
// this value will be mapped to the the display's
// maximum intensity.)
//
// 5) Gamma-correct the pixel values, according to the
// screen's gamma. (We assume that the gamma curve
// is a simple power function.)
//
// 6) Scale the values such that middle gray pixels are
// mapped to a frame buffer value that is 3.5 f-stops
// below the display's maximum intensity. (84.65 if
// the screen's gamma is 2.2)
//
// 7) Clamp the values to [0, 255].
//
float
knee (double x, double f)
{
return float (IMATH::Math<double>::log (x * f + 1) / f);
}
float
findKneeF (float x, float y)
{
float f0 = 0;
float f1 = 1;
while (knee (x, f1) > y)
{
f0 = f1;
f1 = f1 * 2;
}
for (int i = 0; i < 30; ++i)
{
float f2 = (f0 + f1) / 2;
float y2 = knee (x, f2);
if (y2 < y)
f1 = f2;
else
f0 = f2;
}
return (f0 + f1) / 2;
}
struct Gamma
{
float g, m, d, kl, f, s;
Gamma (float gamma,
float exposure,
float defog,
float kneeLow,
float kneeHigh);
float operator () (half h);
};
Gamma::Gamma
(float gamma,
float exposure,
float defog,
float kneeLow,
float kneeHigh)
:
g (gamma),
m (IMATH::Math<float>::pow (2, exposure + 2.47393)),
d (defog),
kl (IMATH::Math<float>::pow (2, kneeLow)),
f (findKneeF (IMATH::Math<float>::pow (2, kneeHigh) - kl,
IMATH::Math<float>::pow (2, 3.5) - kl)),
s (255.0 * IMATH::Math<float>::pow (2, -3.5 * g))
{}
float
Gamma::operator () (half h)
{
//
// Defog
//
float x = max (0.f, (h - d));
//
// Exposure
//
x *= m;
//
// Knee
//
if (x > kl)
x = kl + knee (x - kl, f);
//
// Gamma
//
x = IMATH::Math<float>::pow (x, g);
//
// Scale and clamp
//
return clamp (x * s, 0.f, 255.f);
}
//
// Dithering: Reducing the raw 16-bit pixel data to 8 bits for the
// OpenGL frame buffer can sometimes lead to contouring in smooth
// color ramps. Dithering with a simple Bayer pattern eliminates
// visible contouring.
//
unsigned char
dither (float v, int x, int y)
{
static const float d[4][4] =
{
{0.f / 16, 8.f / 16, 2.f / 16, 10.f / 16},
{12.f / 16, 4.f / 16, 14.f / 16, 6.f / 16},
{3.f / 16, 11.f / 16, 1.f / 16, 9.f / 16},
{15.f / 16, 7.f / 16, 13.f / 16, 5.f / 16}
};
return (unsigned char) (v + d[y & 3][x & 3]);
}
} // namespace
float
ImageView::findKnee (float x, float y)
{
return findKneeF (x, y);
}
void
ImageView::updateScreenPixels ()
{
halfFunction<float>
rGamma (Gamma (_gamma,
_exposure,
_defog * _fogR,
_kneeLow,
_kneeHigh),
-HALF_MAX, HALF_MAX,
0.f, 255.f, 0.f, 0.f);
halfFunction<float>
gGamma (Gamma (_gamma,
_exposure,
_defog * _fogG,
_kneeLow,
_kneeHigh),
-HALF_MAX, HALF_MAX,
0.f, 255.f, 0.f, 0.f);
halfFunction<float>
bGamma (Gamma (_gamma,
_exposure,
_defog * _fogB,
_kneeLow,
_kneeHigh),
-HALF_MAX, HALF_MAX,
0.f, 255.f, 0.f, 0.f);
for (int y = 0; y < _dh; ++y)
{
int i = y * _dw;
for (int x = 0; x < _dw; ++x)
{
int j = i + x;
const IMF::Rgba &rp = _rawPixels[j];
unsigned char *sp = _screenPixels + j * 3;
sp[0] = dither (rGamma (rp.r), x, y);
sp[1] = dither (gGamma (rp.g), x, y);
sp[2] = dither (bGamma (rp.b), x, y);
}
}
}

View File

@ -0,0 +1,133 @@
///////////////////////////////////////////////////////////////////////////
//
// 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 INCLUDED_IMAGE_VIEW_H
#define INCLUDED_IMAGE_VIEW_H
//----------------------------------------------------------------------------
//
// class ImageView -- draws an Imf::Rgba image in an OpenGl window
//
//----------------------------------------------------------------------------
#include "namespaceAlias.h"
#include "GlWindow3d.h"
#include <FL/Fl_Chart.H>
#include <FL/Fl_Gl_Window.H>
#include <FL/Fl_Box.H>
#include <ImfRgba.h>
#include <ImfArray.h>
class ImageView: public Fl_Gl_Window
{
public:
ImageView (int x, int y,
int w, int h, // display window width and height
const char label[],
const IMF::Rgba pixels[/* w*h */],
float* dataZ[/* w*h */],
unsigned int sampleCount[/* w*h */],
int zsize,
int dw, int dh, // data window width and height
int dx, int dy, // data window offset
Fl_Box *rgbaBox,
float farPlane, // zfar plane in Deep 3D window
float gamma,
float exposure,
float defog,
float kneeLow,
float kneeHigh);
virtual void setExposure (float exposure);
virtual void setDefog (float defog);
virtual void setKneeLow (float low);
virtual void setKneeHigh (float high);
virtual void setPixels(const IMF::Rgba pixels[],
float* dataZ[/* w*h */],
unsigned int sampleCount[/* w*h */],
int zsize,
int dw, int dh, int dx, int dy);
virtual void draw();
virtual int handle (int event);
void clearDataDisplay();
protected:
virtual void updateScreenPixels ();
void computeFogColor ();
void findZbound ();
float findKnee (float x, float y);
void drawChart (int x, int y, bool initChart);
void drawChartRef ();
float _gamma;
float _exposure;
float _defog;
float _kneeLow;
float _kneeHigh;
const IMF::Rgba * _rawPixels;
float** _dataZ;
unsigned int * _sampleCount;
float _fogR;
float _fogG;
float _fogB;
float _zmax;
float _zmin;
float _farPlane;
int _dw;
int _dh;
int _dx;
int _dy;
int _zsize;
unsigned int _maxCount;
private:
GlWindow* _gl3d;
Fl_Window * _chartwin;
Fl_Chart * _chart;
Fl_Chart * _chartMax;
Fl_Chart * _chartMin;
Fl_Box * _rgbaBox;
char _rgbaBoxLabel[200];
IMF::Array<unsigned char> _screenPixels;
};
#endif

View File

@ -0,0 +1,52 @@
## Process this file with automake to produce Makefile.in
if HAVE_FLTK
bin_PROGRAMS = exrdisplay
INCLUDES = @OPENEXR_CXXFLAGS@ \
@GL_CXXFLAGS@ @CG_CXXFLAGS@ @FLTK_CXXFLAGS@ -I$(top_builddir) \
@OPENEXR_CTL_CXXFLAGS@
LDADD = @OPENEXR_LDFLAGS@ @OPENEXR_LIBS@ \
@OPENEXR_CTL_LDFLAGS@ @OPENEXR_CTL_LIBS@ \
@CG_LDFLAGS@ @FLTK_LDFLAGS@
all-local:
@FLTK_CONFIG@ --post exrdisplay
install-exec-hook:
@FLTK_CONFIG@ --post $(DESTDIR)$(bindir)/exrdisplay
else
install-exec-hook:
endif
exrdisplay_SOURCES = \
main.cpp \
ImageView.cpp \
ImageView.h \
loadImage.cpp \
loadImage.h \
scaleImage.cpp \
scaleImage.h \
applyCtl.cpp \
applyCtl.h \
GlWindow3d.h \
GlWindow3d.cpp
noinst_HEADERS = \
ImageView.h \
loadImage.h \
scaleImage.h \
applyCtl.h \
GlWindow3d.h \
namespaceAlias.h
EXTRA_DIST = $(exrdisplay_SOURCES)

View File

@ -0,0 +1,436 @@
///////////////////////////////////////////////////////////////////////////
//
// Copyright (c) 2006, 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.
//
///////////////////////////////////////////////////////////////////////////
//-----------------------------------------------------------------------------
//
// Apply CTL transforms
//
//-----------------------------------------------------------------------------
#include "applyCtl.h"
#if HAVE_CTL_INTERPRETER
#include <ImfCtlApplyTransforms.h>
#include <CtlSimdInterpreter.h>
#include <ImfStandardAttributes.h>
#include <ImfHeader.h>
#include <ImfFrameBuffer.h>
#include <stdlib.h>
#include <cassert>
#include <cstdio>
#include <iostream>
#include<stdio.h>
using namespace std;
using namespace Ctl;
using namespace IMATH;
#else
#include <ImfStandardAttributes.h>
#include <ImfHeader.h>
#include <stdlib.h>
#include <cassert>
#include <cstdio>
#include <iostream>
#include <stdio.h>
using namespace std;
using namespace IMATH;
#endif
using namespace IMF;
#define WARNING(message) (cerr << "Warning: " << message << endl)
float
displayVideoGamma ()
{
//
// Get the display's video gamma from an environment variable.
// If this fails, use a default value (1/2.2).
//
const char gammaEnv[] = "EXR_DISPLAY_VIDEO_GAMMA";
float g = 2.2f;
if (const char *gamma = getenv (gammaEnv))
{
float tmp;
int n = sscanf (gamma, " %f", &tmp);
if (n != 1)
WARNING ("Cannot parse environment variable " << gammaEnv << "; "
"using default value (" << g << ").");
else if (tmp < 1.f)
WARNING ("Display video gamma, specified in environment "
"variable " << gammaEnv << " is out of range; "
"using default value (" << g << ").");
else
g = tmp;
}
else
{
WARNING ("Environment variable " << gammaEnv << " is not set; "
"using default value (" << g << ").");
}
return 1.f / g;
}
namespace {
Chromaticities
displayChromaticities ()
{
//
// Get the chromaticities of the display's primaries and
// white point from an environment variable. If this fails,
// assume chromaticities according to Rec. ITU-R BT.709.
//
static const char chromaticitiesEnv[] = "CTL_DISPLAY_CHROMATICITIES";
Chromaticities c; // default-initialized according to Rec. 709
if (const char *chromaticities = getenv (chromaticitiesEnv))
{
Chromaticities tmp;
int n = sscanf (chromaticities,
" red %f %f green %f %f blue %f %f white %f %f",
&tmp.red.x, &tmp.red.y,
&tmp.green.x, &tmp.green.y,
&tmp.blue.x, &tmp.blue.y,
&tmp.white.x, &tmp.white.y);
if (n == 8)
c = tmp;
else
WARNING ("Cannot parse environment variable " <<
chromaticitiesEnv << "; using default value "
"(chromaticities according to Rec. ITU-R BT.709).");
}
else
{
WARNING ("Environment variable " << chromaticitiesEnv << " is "
"not set; using default value (chromaticities according "
"to Rec. ITU-R BT.709).");
}
return c;
}
} // namespace
#if HAVE_CTL_INTERPRETER
namespace {
void
initializeEnvHeader (Header &envHeader)
{
//
// Initialize the "environment header" for the CTL
// transforms by adding displayChromaticities,
// displayWhiteLuminance and displaySurroundLuminance
// attributes.
//
Chromaticities c = displayChromaticities();
envHeader.insert ("displayChromaticities", ChromaticitiesAttribute (c));
//
// Get the display's white luminance from an environment variable.
// If this fails, assume 120 candelas per square meter.
// (Screen aim luminance according to SMPTE RP 166.)
//
static const char whiteLuminanceEnv[] = "CTL_DISPLAY_WHITE_LUMINANCE";
static const float whiteLuminanceDefault = 120.0;
float wl = whiteLuminanceDefault;
if (const char *whiteLuminance = getenv (whiteLuminanceEnv))
{
int n = sscanf (whiteLuminance, " %f", &wl);
if (n != 1)
WARNING ("Cannot parse environment variable " <<
whiteLuminanceEnv << "; using default value "
"(" << wl << " candelas per square meter).");
}
else
{
WARNING ("Environment variable " << whiteLuminanceEnv << " is "
"is not set; using default value (" << wl << " candelas "
"per square meter).");
}
envHeader.insert ("displayWhiteLuminance", FloatAttribute (wl));
//
// Get the display's surround luminance from an environment variable.
// If this fails, assume 10% of the display's white luminance.
// (Recommended setup according to SMPTE RP 166.)
//
static const char surroundLuminanceEnv[] = "CTL_DISPLAY_SURROUND_LUMINANCE";
float sl = wl * 0.1f;
if (const char *surroundLuminance = getenv (surroundLuminanceEnv))
{
int n = sscanf (surroundLuminance, " %f", &sl);
if (n != 1)
WARNING ("Cannot parse environment variable " <<
surroundLuminanceEnv << "; using default value "
"(" << sl << " candelas per square meter).");
}
else
{
WARNING ("Environment variable " << surroundLuminanceEnv << " is "
"is not set; using default value (" << sl << " candelas "
"per square meter).");
}
envHeader.insert ("displaySurroundLuminance", FloatAttribute (sl));
}
string
displayTransformName ()
{
//
// Get the name of the display transform from an environment
// variable. If this fails, use a default name.
//
static const char displayTransformEnv[] = "CTL_DISPLAY_TRANSFORM";
static const char displayTransformDefault[] = "transform_display_video";
const char *displayTransform = getenv (displayTransformEnv);
if (!displayTransform)
{
displayTransform = displayTransformDefault;
WARNING ("Environment variable " << displayTransformEnv << " "
"is not set; using default value "
"(\"" << displayTransform << "\").");
}
return displayTransform;
}
void
initializeInFrameBuffer
(int w,
int h,
const Array<Rgba> &pixels,
FrameBuffer &fb)
{
fb.insert ("R", Slice (HALF, // type
(char *)(&pixels[0].r), // base
sizeof (pixels[0]), // xStride
sizeof (pixels[0]) * w)); // yStride
fb.insert ("G", Slice (HALF, // type
(char *)(&pixels[0].g), // base
sizeof (pixels[0]), // xStride
sizeof (pixels[0]) * w)); // yStride
fb.insert ("B", Slice (HALF, // type
(char *)(&pixels[0].b), // base
sizeof (pixels[0]), // xStride
sizeof (pixels[0]) * w)); // yStride
}
void
initializeOutFrameBuffer
(int w,
int h,
const Array<Rgba> &pixels,
FrameBuffer &fb)
{
fb.insert ("R_display", Slice (HALF, // type
(char *)(&pixels[0].r), // base
sizeof (pixels[0]), // xStride
sizeof (pixels[0]) * w)); // yStride
fb.insert ("G_display", Slice (HALF, // type
(char *)(&pixels[0].g), // base
sizeof (pixels[0]), // xStride
sizeof (pixels[0]) * w)); // yStride
fb.insert ("B_display", Slice (HALF, // type
(char *)(&pixels[0].b), // base
sizeof (pixels[0]), // xStride
sizeof (pixels[0]) * w)); // yStride
}
} // namespace
void
applyCtl (vector<string> transformNames,
Header inHeader,
const Array<Rgba> &inPixels,
int w,
int h,
Array<Rgba> &outPixels)
{
//
// If we do not have an explicit set of transform names
// then find suitable look modification, rendering and
// display transforms.
//
if (transformNames.empty())
{
if (hasLookModTransform (inHeader))
transformNames.push_back (lookModTransform (inHeader));
if (hasRenderingTransform (inHeader))
transformNames.push_back (renderingTransform (inHeader));
else
transformNames.push_back ("transform_RRT");
transformNames.push_back (displayTransformName());
}
//
// Initialize an input and an environment header:
// Make sure that the headers contain information about the primaries
// and the white point of the image files an the display, and about
// the display's white luminance and surround luminance.
//
if (!hasChromaticities (inHeader))
addChromaticities (inHeader, Chromaticities());
if (!hasAdoptedNeutral (inHeader))
addAdoptedNeutral (inHeader, chromaticities(inHeader).white);
Header envHeader;
initializeEnvHeader (envHeader);
//
// Set up input and output FrameBuffer objects for the transforms.
//
FrameBuffer inFb;
initializeInFrameBuffer (w, h, inPixels, inFb);
FrameBuffer outFb;
initializeOutFrameBuffer (w, h, outPixels, outFb);
//
// Run the CTL transforms
//
Box2i transformWindow (V2i (0, 0), V2i (w - 1, h - 1));
SimdInterpreter interpreter;
#ifdef CTL_MODULE_BASE_PATH
//
// The configuration scripts has defined a default
// location for CTL modules. Include this location
// in the CTL module search path.
//
vector<string> paths = interpreter.modulePaths();
paths.push_back (CTL_MODULE_BASE_PATH);
interpreter.setModulePaths (paths);
#endif
Header outHeader;
ImfCtl::applyTransforms (interpreter,
transformNames,
transformWindow,
envHeader,
inHeader,
inFb,
outHeader,
outFb);
}
#endif
void
adjustChromaticities (const Header &header,
const Array<Rgba> &inPixels,
int w, int h,
Array<Rgba> &outPixels)
{
Chromaticities fileChroma; // default-initialized according to Rec. 709
if (hasChromaticities (header))
fileChroma = chromaticities (header);
Chromaticities displayChroma = displayChromaticities();
if (fileChroma.red == displayChroma.red &&
fileChroma.green == displayChroma.green &&
fileChroma.blue == displayChroma.blue &&
fileChroma.white == displayChroma.white)
{
return;
}
M44f M = RGBtoXYZ (fileChroma, 1) * XYZtoRGB (displayChroma, 1);
size_t numPixels = w * h;
for (size_t i = 0; i < numPixels; ++i)
{
const Rgba &in = inPixels[i];
Rgba &out = outPixels[i];
V3f rgb = V3f (in.r, in.g, in.b) * M;
out.r = rgb[0];
out.g = rgb[1];
out.b = rgb[2];
}
}

View File

@ -0,0 +1,123 @@
#ifndef INCLUDED_APPLY_CTL_H
#define INCLUDED_APPLY_CTL_H
//////////////////////////////////////////////////////////////////////////////
//
// Copyright (c) 2005, Industrial Light & Magic, a division of Lucasfilm
// Entertainment Company Ltd. Portions contributed and copyright held by
// others as indicated. 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
// any other contributors to this software 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.
//
//////////////////////////////////////////////////////////////////////////////
//----------------------------------------------------------------------------
//
// Apply CTL transforms
//
//----------------------------------------------------------------------------
#include "namespaceAlias.h"
#include <ImfRgba.h>
#include <ImfArray.h>
#include <ImfHeader.h>
#include <vector>
#include <cstdlib>
//
// Apply a series of CTL transforms to the raw pixel data from an image file
// in order to generate pixel data that can be displayed on the screen.
//
// transformNames A list of the names of the CTL transforms that will
// be applied to raw pixels. If this list is empty,
// applyCtl() looks for a rendering transform and a
// display transform:
//
// If inHeader contains a string attribute called
// "renderingTransform" then the value of this attribute
// is the name of the rendering transform.
// If inHeader contains no such attribute, then the
// name of the rendering transform is "transform_RRT".
//
// If the environment variable CTL_DISPLAY_TRANSFORM
// is set, the value of the environment variable is
// the name of the display transform.
// If the environment variable is not set, then the name
// of the display transform is "transform_display_video".
//
// inHeader The header of the image file.
//
// inPixels Raw pixels from the image file.
//
// w, h Width and height of the inPixels and outPixels
// arrays. (The caller must set the size of the
// arrays to w*h, before calling applyCtl().)
//
// outPixels Output -- pixels for display on the screen.
// The data in outPixels represent relative
// luminance values; an R, G or B value of 1.0
// represents the maximum red, green or blue
// luminance that the display can achieve.
//
void applyCtl (std::vector<std::string> transformNames,
IMF::Header inHeader,
const IMF::Array<IMF::Rgba> &inPixels,
int w,
int h,
IMF::Array<IMF::Rgba> &outPixels);
//
// If the chromaticities of the RGB pixel loaded from a file
// are not the same as the chromaticities of the display,
// then transform the pixels from the RGB coordinate system
// of the file to the RGB coordinate system of the display.
//
void adjustChromaticities (const IMF::Header &header,
const IMF::Array<IMF::Rgba> &inPixels,
int w,
int h,
IMF::Array<IMF::Rgba> &outPixels);
//
// Get the gamma factor that must be used in order to convert luminance
// values output by applyCtl() into display frame buffer values.
//
float displayVideoGamma ();
#endif

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,99 @@
#ifndef INCLUDED_LOAD_IMAGE_H
#define INCLUDED_LOAD_IMAGE_H
//////////////////////////////////////////////////////////////////////////////
//
// Copyright (c) 2012, Industrial Light & Magic, a division of Lucasfilm
// Entertainment Company Ltd. Portions contributed and copyright held by
// others as indicated. 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
// any other contributors to this software 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.
//
//////////////////////////////////////////////////////////////////////////////
//----------------------------------------------------------------------------
//
// Load an OpenEXR image into a pixel array.
//
//----------------------------------------------------------------------------
#include "namespaceAlias.h"
#include <ImfRgba.h>
#include <ImfArray.h>
#include <ImfHeader.h>
//
// Load an OpenEXR image file:
//
// fileName The name of the file to be loaded.
//
// channel If channel is 0, load the R, G and B channels,
// otherwise channel must point to the name of the
// image channel to be loaded; the channel is copied
// into the R, G and B components of the frame buffer.
//
// layer Used only if channel is 0: if layer is 0, load
// the R, G and B channels, otherwise load layer.R,
// layer.G and layer.B.
//
// preview If preview is true load the file's preview image,
// otherwise load the main image.
//
// lx, ly If lx != 0 or ly != 0 then assume that the input
// file is tiled and load level (0, 0).
//
// header Output -- the header of the input file, but with
// the dataWindow, displayWindow and pixelAspectRatio
// attributes adjusted to match what parts of the file
// were actually loaded.
//
// pixels Output -- the pixels loaded from the file.
// loadImage() resizes the pixels array to fit
// the dataWindow attribute of the header.
//
void loadImage (const char fileName[],
const char channel[],
const char layer[],
bool preview,
int lx,
int ly,
int partnum,
int &zsize,
IMF::Header &header,
IMF::Array<IMF::Rgba> &pixels,
IMF::Array<float*> &zbuffer,
IMF::Array<unsigned int> &sampleCount,
bool deepComp);
#endif

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,45 @@
///////////////////////////////////////////////////////////////////////////
//
// 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"
#include "ImathNamespace.h"
#include "IexNamespace.h"
namespace IMF = OPENEXR_IMF_NAMESPACE;
namespace IMATH = IMATH_NAMESPACE;
namespace IEX = IEX_NAMESPACE;
#endif /* NAMESPACEALIAS_H_ */

View File

@ -0,0 +1,276 @@
///////////////////////////////////////////////////////////////////////////
//
// 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.
//
///////////////////////////////////////////////////////////////////////////
//----------------------------------------------------------------------------
//
// Image scaling and filtering functions.
//
//----------------------------------------------------------------------------
#include "scaleImage.h"
#include <ImathLimits.h>
#include <ImathFun.h>
#include <algorithm>
#include <math.h>
using namespace IMF;
using namespace IMATH;
using std::min;
using std::max;
int
scaleInt (float f, int i)
{
return int (f * i + 0.5);
}
void
scaleX (float f,
int &w, int &h,
int &dw, int &dh,
int &dx, int &dy,
Array<Rgba> &pixels)
{
int dw1 = scaleInt (f, dw);
if (dw1 <= dw)
{
//
// Do nothing if the width of the data window
// woudn't increase by at least one pixel.
//
return;
}
w = scaleInt (f, w);
dx = scaleInt (f, dx);
//
// Copy the pixels to a temporary array
//
Array<Rgba> tmp (dw * dh);
for (int i = 0; i < dw * dh; ++i)
tmp[i] = pixels[i];
//
// Resize the original pixel array,
// and copy the pixels back into the
// resized array.
//
pixels.resizeErase (dw1 * dh);
f = float (dw - 1) / float (dw1 - 1);
for (int x = 0; x < dw1; ++x)
{
float x1 = x * f;
int xs = int (x1);
int xt = min (xs + 1, dw - 1);
float t = x1 - xs;
float s = 1 - t;
for (int y = 0; y < dh; ++y)
{
const Rgba &ps = tmp [y * dw + xs];
const Rgba &pt = tmp [y * dw + xt];
Rgba &p = pixels[y * dw1 + x];
p.r = ps.r * s + pt.r * t;
p.g = ps.g * s + pt.g * t;
p.b = ps.b * s + pt.b * t;
p.a = ps.a * s + pt.a * t;
}
}
dw = dw1;
}
void
scaleY (float f,
int &w, int &h,
int &dw, int &dh,
int &dx, int &dy,
Array<Rgba> &pixels)
{
int dh1 = scaleInt (f, dh);
if (dh1 <= dh)
{
//
// Do nothing if the height of the data window
// woudn't increase by at least one pixel.
//
return;
}
h = scaleInt (f, h);
dy = scaleInt (f, dy);
//
// Copy the pixels to a temporary array
//
Array<Rgba> tmp (dw * dh);
for (int i = 0; i < dw * dh; ++i)
tmp[i] = pixels[i];
//
// Resize the original pixel array,
// and copy the pixels back into the
// resized array.
//
pixels.resizeErase (dw * dh1);
f = float (dh - 1) / float (dh1 - 1);
for (int y = 0; y < dh1; ++y)
{
float y1 = y * f;
int ys = int (y1);
int yt = min (ys + 1, dh - 1);
float t = y1 - ys;
float s = 1 - t;
for (int x = 0; x < dw; ++x)
{
const Rgba &ps = tmp [ys * dw + x];
const Rgba &pt = tmp [yt * dw + x];
Rgba &p = pixels[y * dw + x];
p.r = ps.r * s + pt.r * t;
p.g = ps.g * s + pt.g * t;
p.b = ps.b * s + pt.b * t;
p.a = ps.a * s + pt.a * t;
}
}
dh = dh1;
}
void
normalizePixels (int dw, int dh, Array<Rgba> &pixels)
{
float pMax = -IMATH::limits<float>::max ();
float pMin = IMATH::limits<float>::max ();
for (int i = 0; i < dw * dh; ++i)
{
const Rgba &p = pixels[i];
if (p.r.isFinite())
{
pMax = max (float (p.r), pMax);
pMin = min (float (p.r), pMin);
}
if (p.g.isFinite())
{
pMax = max (float (p.g), pMax);
pMin = min (float (p.g), pMin);
}
if (p.b.isFinite())
{
pMax = max (float (p.b), pMax);
pMin = min (float (p.b), pMin);
}
}
if (pMax <= pMin)
pMax = pMin + 1;
for (int i = 0; i < dw * dh; ++i)
{
Rgba &p = pixels[i];
if (p.r.isFinite())
p.r = (p.r - pMin) / (pMax - pMin);
if (p.g.isFinite())
p.g = (p.g - pMin) / (pMax - pMin);
if (p.b.isFinite())
p.b = (p.b - pMin) / (pMax - pMin);
}
}
void
swapPixels (int dw, int dh, Array<Rgba> &pixels)
{
Array<Rgba> tmp (max (dw, dh));
int dw2 = dw / 2;
int dh2 = dh / 2;
//
// Swap top and bottom half
//
for (int x = 0; x < dw; ++x)
{
for (int y = 0; y < dh; ++y)
tmp[(y + dh2) % dh] = pixels[dw * y + x];
for (int y = 0; y < dh; ++y)
pixels[dw * y + x] = tmp[y];
}
//
// Swap left and right half
//
for (int y = 0; y < dh; ++y)
{
for (int x = 0; x < dw; ++x)
tmp[(x + dw2) % dw] = pixels[dw * y + x];
for (int x = 0; x < dw; ++x)
pixels[dw * y + x] = tmp[x];
}
}

View File

@ -0,0 +1,99 @@
///////////////////////////////////////////////////////////////////////////
//
// 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.
//
///////////////////////////////////////////////////////////////////////////
#ifndef INCLUDED_SCALE_IMAGE_H
#define INCLUDED_SCALE_IMAGE_H
//----------------------------------------------------------------------------
//
// Image scaling and filtering functions.
//
//----------------------------------------------------------------------------
#include "namespaceAlias.h"
#include <ImfRgba.h>
#include <ImfArray.h>
//
// Scale an image horizontally or vertically, by a factor of
// approximately f (f is adjusted slightly so that the corners
// of the display window and the data window fall on integer
// pixel locations).
//
// f scale factor; must be >= 1.0
//
// w, h width and height of the display window
//
// dw, dh width and height of the data window
//
// dx, dy offset of the data window's upper left
// corner from the display window's upper
// left corner
//
// pixels the image's pixel array
//
void scaleX (float f,
int &w, int &h,
int &dw, int &dh,
int &dx, int &dy,
IMF::Array<IMF::Rgba> &pixels);
void scaleY (float f,
int &w, int &h,
int &dw, int &dh,
int &dx, int &dy,
IMF::Array<IMF::Rgba> &pixels);
//
// Normalize the pixel values in an image so that the smallest
// value becomes 0.0 and the largest value becomes 1.0.
//
void normalizePixels (int dw, int dh, IMF::Array<IMF::Rgba> &pixels);
//
// Swap the left and right half of and image; then swap the
// top and bottom half, so that the four corners of the image
// end up in the center.
//
void swapPixels (int dw, int dh, IMF::Array<IMF::Rgba> &pixels);
#endif