41
#include "../Threads/tonemapper_thread.h"
41
#include "../Threads/tonemapperThread.h"
42
42
QImage TonemapperThread::fromLDRPFStoQImage( pfs::Frame* inpfsframe ) {
43
43
assert(inpfsframe!=NULL);
46
pfs::Channel *X, *Y, *Z;
47
inpfsframe->getXYZChannels( X,Y,Z );
48
assert( X!=NULL && Y!=NULL && Z!=NULL );
50
//we are modifying the input buffer here!!!
51
//but it should be ok since this is the endpoint
52
//keep SRGB for compatibility with pfstmo...
53
pfs::transformColorSpace( pfs::CS_XYZ, X,Y,Z, pfs::CS_SRGB, X,Y,Z );
55
int width = X->getCols();
56
int height = X->getRows();
46
pfs::Channel *R, *G, *B;
47
inpfsframe->getRGBChannels( R,G,B );
48
assert( R!=NULL && G!=NULL && B!=NULL );
50
//inpfsframe's colorspace is either sRGB or RGB.
51
//sRGB is used for compatibility with pfstmo.
52
//fattal, reinhard05 and ashickmin (somewhat) prefer a RGB colorspace
54
int width = R->getCols();
55
int height = R->getRows();
57
56
uchar *data=new uchar[width*height*4]; //this will contain the image data: data must be 32-bit aligned, in Format: 0xffRRGGBB
58
57
for( int y = 0; y < height; y++ ) { // For each row of the image
59
58
for( int x = 0; x < width; x++ ) {
60
59
if (QSysInfo::ByteOrder == QSysInfo::LittleEndian) {
61
*(data + 0 + (y*width+x)*4) = ( clamp( (*Z)( x, y )*255.f, 0, 255) );
62
*(data + 1 + (y*width+x)*4) = ( clamp( (*Y)( x, y )*255.f, 0, 255) );
63
*(data + 2 + (y*width+x)*4) = ( clamp( (*X)( x, y )*255.f, 0, 255) );
60
*(data + 0 + (y*width+x)*4) = ( clamp( (*B)( x, y )*255.f, 0, 255) );
61
*(data + 1 + (y*width+x)*4) = ( clamp( (*G)( x, y )*255.f, 0, 255) );
62
*(data + 2 + (y*width+x)*4) = ( clamp( (*R)( x, y )*255.f, 0, 255) );
64
63
*(data + 3 + (y*width+x)*4) = 0xff;
66
*(data + 3 + (y*width+x)*4) = ( clamp( (*Z)( x, y )*255.f, 0, 255) );
67
*(data + 2 + (y*width+x)*4) = ( clamp( (*Y)( x, y )*255.f, 0, 255) );
68
*(data + 1 + (y*width+x)*4) = ( clamp( (*X)( x, y )*255.f, 0, 255) );
65
*(data + 3 + (y*width+x)*4) = ( clamp( (*B)( x, y )*255.f, 0, 255) );
66
*(data + 2 + (y*width+x)*4) = ( clamp( (*G)( x, y )*255.f, 0, 255) );
67
*(data + 1 + (y*width+x)*4) = ( clamp( (*R)( x, y )*255.f, 0, 255) );
69
68
*(data + 0 + (y*width+x)*4) = 0xff;
73
73
//special treament for qt 4.2.1... removing "const" doesn't seem to work.
74
74
#if QT_VERSION == 0x040201
75
75
QImage toreturn(const_cast<const uchar *>(data),width,height,QImage::Format_ARGB32);