Jump to content

RGBA16 pixel data


SpiderPig
 Share

Go to solution Solved by Josh,

Recommended Posts

How can I access the pixel data from a pixmap generated with TextureBuffer::Capture()?  I want to access the pixel data directly like this:

auto captures = texture_buffer->GetCaptures();
if (captures.size() != 0) {
    auto pixmap = captures[0];
    auto data = pixmap->pixels->Data();

    int x = 0, y = 0, stride = 4;
    auto i = ((y * pixmap->size.x) + x) * stride;

    auto r = data[0];
    auto g = data[1];
    auto b = data[2];
    auto a = data[3];
}

I've also tried this but it shows an error saying it "Bytes per block must be four or less"

auto pix = pixmap->ReadPixel(x, y);
auto r = Red(pix);
auto g = Green(pix);
auto b = Blue(pix);
auto a = Alpha(pix);

I can convert the pixmap from TEXTURE_RGB16 to TEXTURE_RGBA and both code will work but it's far too slow for my situation (I'm doing it once per frame).

 

Link to comment
Share on other sites

Thanks.  It's actually 3 times slower to do that per pixel than to convert the whole pixmap and access the pixel data directly.

I am I correct in saying that for an RGBA16 format, the data here 2 bytes per channel?

char* data = pixmap->pixels->Data();

I need a value between 0 and 255 but I'm not positive if bit shifting like this is the right way.  And then I'm not positive how to get back the 0 - 255 range.

auto r = (data[index] << 8) | data[index + 1];
auto g = (data[index + 2] << 8) | data[index + 3];
auto b = (data[index + 4] << 8) | data[index + 5];
auto a = (data[index + 6] << 8) | data[index + 7];

index += 8;

 

Link to comment
Share on other sites

  • Solution

Do it like this:
unsigned short* data = (unsigned short*)pixmap->pixels->Data();

Each channel will be a half float. Use halfToFloat() to convert that to a floating point number.

  • Thanks 1

My job is to make tools you love, with the features you want, and performance you can't live without.

Link to comment
Share on other sites

RGBA16 is used because it supports values outside the range of 0-1. This is important if post-processing effects are used, and it also important for environment probes.

  • Thanks 1

My job is to make tools you love, with the features you want, and performance you can't live without.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...