I was able to use OpenImageIO's OCIO support to apply a 3d LUT to my "raw image 
data" using the following code:

        // Create lutted buffer
        ImageSpec luttedBufSpec = ImageSpec ( seqSpec->width, seqSpec->height, 
3, TypeDesc::UINT8 );
        ImageBuf luttedBuf = ImageBuf( luttedBufSpec );
        ROI srcRoi = get_roi_full (*seqSpec);
        luttedBuf.set_pixels( srcRoi, TypeDesc::UINT8, someUnsignedCharImgData 
);

//        ImageBufAlgo::colorconvert (luttedBuf, luttedBuf, "AlexaV3LogC",  
"sRGB", false, ROI::All(), 3);
        ImageBufAlgo::ociofiletransform (luttedBuf, luttedBuf, 
"C:/temp/049x050_lut.3dl");

        // Dump lutted buffer as unsign char* data
        unsigned char* luttedPixelData = (unsigned char*)malloc( 
luttedBuf.spec().width*luttedBuf.spec().height*3 );
        ROI luttedRoi = get_roi_full (luttedBuf.spec());
        luttedBuf.get_pixels( luttedRoi, TypeDesc::UINT8 , luttedPixelData );

        QImage::Format QIFormat = QImage::Format_RGB888;
        QImage *img = new QImage (luttedPixelData, seqSpec->width, 
seqSpec->height, QIFormat);
The issue with this method is that it forces me to dump my "raw image data" 
back into an ImageBuf to apply the "filetransform" and then dump my ImageBuf 
data back into an "unsigned char*" object to use in Qt.
This is a pretty slow process and unfortunately it takes too long for what I'm 
trying to achieve.
Is there a better and mostly faster way to apply a "filetransform" or 
"colorconvert" to an image and dump the result data in an "unisgned char*" 
object ?



On a different note, I had a hard time finding the "ociofiletransform" method 
in the documentation. What threw me off was the "wording" used to describe the 
"LUT" file path:

OIIO 1.8 Documentation:
bool ociofiletransform (ImageBuf &dst, const ImageBuf &src,
string_view name, bool inverse=false, bool unpremult=false,
ColorConfig *colorconfig=NULL,
ROI roi=ROI::All(), int nthreads=0)

wouldn't it be easier to call the third argument something like: "string 
lut_file_path" ?
What is "string_view name" ?

Thanks,

Renaud

From: Renaud TALON
Sent: Tuesday, April 11, 2017 1:06 PM
To: [email protected]
Subject: [Oiio-dev] OCIO : problem applying 3D LUT from file

Hi !
I have problems applying a 3D LUT using "FileTransformRcPtr".

1 - I load my image using OpenImageIO : 
_____________________________________________________________________________________________________________________

ImageInput *srcImg = ImageInput::open(filename);
ImageSpec *srcSpec = new ImageSpec(srcImg->spec());
unsigned char* srcRGBpixelData = (unsigned 
char*)malloc(srcSpec->width*srcSpec->height*3 );

srcImg->read_scanlines( srcSpec->y, srcSpec->y+srcSpec->height, 0, 0, 3, 
TypeDesc::UINT8, srcRGBpixelData );

ImageSpec srcBufSpec = ImageSpec ( srcSpec->width, srcSpec->height, 3, 
TypeDesc::UINT8 );
ImageBuf srcBuf = ImageBuf( srcBufSpec );
ROI srcRoi = get_roi_full (*srcSpec);
srcBuf.set_pixels( srcRoi, TypeDesc::UINT8, srcRGBpixelData );

srcImg->close();

______________________________________________________________________________________________________________________

2 - store my image in RAM as "unsigned char*"

I would like to apply a 3D LUT to this "raw data" (unsigned char*) and return 
the result as "unsigned char*" since this is what Qt supports for QImage data.
Here is what I came up with, it's currently crashing on the 
"m_processor->apply(luttedImg); line"

______________________________________________________________________________________________________________________

        OCIO::PackedImageDesc 
luttedImg(reinterpret_cast<float*>(imgCache[curFrame]), seqSpec->width, 
seqSpec->height, 3);

        try
        {
            OCIO::ConstConfigRcPtr config = OCIO::GetCurrentConfig();

            // Create File Transform
            const char *lutPath = "C:/temp/049x050_lut.3dl";
            OCIO::FileTransformRcPtr transform = OCIO::FileTransform::Create();
            transform->setSrc(lutPath);
            transform->setDirection(OCIO::TRANSFORM_DIR_FORWARD);
            transform->setInterpolation(OCIO::INTERP_LINEAR);

            OCIO::ConstProcessorRcPtr m_processor = 
config->getProcessor(transform, OCIO::TRANSFORM_DIR_FORWARD);

            // Apply transform
            m_processor->apply(luttedImg);
        }
        catch(OCIO::Exception &e)
        {
            qDebug() << e.what();
        }

      // not sure how to go back to "unsigned char*" after transform is 
applied. reinterpret_cast<unsigned char*> ????
__________________________________________________________________________________________________________________________

As usual, any help would be greatly appreciated.
Thanks,

Renaud

_______________________________________________
Oiio-dev mailing list
[email protected]
http://lists.openimageio.org/listinfo.cgi/oiio-dev-openimageio.org

Reply via email to