#34 ilCopyPixels and a way to get pixel

closed
nobody
None
5
2006-06-14
2006-06-14
Romulo Fernandes
No

Hi, im trying to copy a single pixel from my image that
is already allocated, i checked and the image format is
IL_RGBA, so i allocated some ILubyte(*4) and got the
data with ilCopyPixels...Now i want to access each
color channel alone, how i do this?I tried:

ILint srcSize =
ilGetInteger(IL_IMAGE_BPP)*ilGetInteger(IL_IMAGE_BPC);
ILubyte* data = (ILubyte*)malloc(srcSize);

ilCopyPixels(x, y, 0, 1, 1, 1, IL_RGBA,
IL_UNSIGNED_BYTE, data);

int r,g,b,a;

r = (*data >> 24) & 0xFF;
g = (*data >> 16) & 0xFF;
b = (*data >> 8) & 0xFF;
a = (*data)&0xFF;

but it doesnt return the correct information about the
pixel..can anyone help me?

Discussion

  • Dario Meloni
    Dario Meloni
    2006-06-14

    Logged In: YES
    user_id=710897

    My code works:

    ILuint data;
    ilCopyPixels(x, y, 0, 1, 1, 1, IL_RGBA,IL_UNSIGNED_BYTE, &data);
    int r,g,b,a;

    a = (data >> 24) & 0xFF;
    b = (data >> 16) & 0xFF;
    g = (data >> 8 ) & 0xFF;
    r = (data ) & 0xFF;

    That's the correct byte ordering. It's written RGBA, but the
    first byte is R.

     
  • Dario Meloni
    Dario Meloni
    2006-06-14

    • status: open --> closed
     
  • Logged In: NO

    thanks, worked like a charm :D