Page 1 of 1

Reading RenderPreviewBuffer from CmaxwellMxi

Posted: Wed Jun 24, 2015 11:48 am
by ArmanZak
I'm trying read RenderPreviewBuffer from existing mxi file, but I get incorrect image
First image is a real render preview,
second image what i get
Image
Image
Used files
Can anyone help? What I doing wrong?
Code: Select all
CmaxwellMxi mxi;
    mxi.read("D:/test.mxi");
    dword xRes, yRes;
    dword xPrevRes = xRes, yPrevRes = yRes;
    mxi.getPreviewResolution(xRes, yRes, xPrevRes, yPrevRes);
    mxi.updateDisplay();
    mxi.updatePreview();

    Crgb8 *pRgb8 = mxi.getRenderPreviewBuffer();;

    QImage image(xPrevRes, yPrevRes, QImage::Format_RGB888);
    for(int y = 0; y < yPrevRes; y++)
    {
        for(int x = 0; x < xPrevRes; x++)
        {
            Crgb pRgb;
            pRgb8->toRGB(pRgb);

            QColor color;
            color.setRgbF(pRgb.r, pRgb.g, pRgb.b);

            image.setPixel(x,y, color.rgb());

            pRgb8++;
        }
    }
    m_graphicsScene->addPixmap(QPixmap::fromImage(image));
    image.save("D:/test.png", "PNG");

Re: Reading RenderPreviewBuffer from CmaxwellMxi

Posted: Wed Jun 24, 2015 1:12 pm
by Brany
Hi,

The beginning of your code is not correct. Is not importat to your problem but it can be confusing for other users ;)
Code: Select all
dword xRes, yRes;
dword xPrevRes = xRes, yPrevRes = yRes;
mxi.getPreviewResolution(xRes, yRes, xPrevRes, yPrevRes);
should be something like
Code: Select all
dword xRes = mxi.xRes(), yRes = mxi.yRes();
dword xPrevRes, yPrevRes;
mxi.getPreviewResolution(xRes, yRes, xPrevRes, yPrevRes);

Regarding the blue image, it seems that it is a RGB/BGR issue, try this
Code: Select all
color.setRgbF(pRgb.b, pRgb.g, pRgb.r);

Re: Reading RenderPreviewBuffer from CmaxwellMxi

Posted: Wed Jun 24, 2015 2:42 pm
by ArmanZak
Thanks for reply.
I try your code, and it's help.
But I can't understand, why???
color.setRgbF take params in this sequence red, green , blue, but in working code it to blue, green, red.
Absurdly

Re: Reading RenderPreviewBuffer from CmaxwellMxi

Posted: Wed Jun 24, 2015 3:32 pm
by Brany
I used Qt a couple of times to handle images like you are doing, and it always happens something weird like that RGB-BGR thing... QImage can be a little bit confusing sometimes :P