Monday, September 10, 2012

OpenGL es 16 bits 스크린 캡쳐하기 (iOS)


short* buffer = (short*)malloc(myDataLength);
glReadPixels(startx, starty, width, height, GL_RGB, GL_UNSIGNED_SHORT_5_6_5, buffer);
    
int* buffer2 = (int*)malloc(width * height * 4);
    
int table5[] = { 0, 8, 16, 25, 33, 41, 4958, 66, 74, 82, 90, 99, 107, 115, 123, 132, 140, 148, 156, 165, 173, 181, 189197, 206, 214, 222, 230, 239, 247, 255 };

int table6[] = { 0, 4, 8, 12, 16, 20, 2428, 32, 36, 40, 45, 49, 53, 57, 61, 65, 69, 73, 77, 81, 85, 89, 93, 97, 101105, 109, 113, 117, 121, 125, 130, 134, 138, 142, 146, 150, 154, 158, 162, 166170, 174, 178, 182, 186, 190, 194, 198, 202, 206, 210, 215, 219, 223, 227, 231235, 239, 243, 247, 251, 255 };
    
for ( int y = 0; y < height; ++y )
{
    for ( int x = 0; x < width; ++x )
    {
        int b8 = table5[buffer[y * width + x] & 0x001F];
        int g8 = table6[(buffer[y * width + x] & 0x07E0) >> 5];
        int r8 = table5[(buffer[y * width + x] & 0xF800) >> 11];
            
        buffer2[((height-1) - y) * width + x] = b8 << 16 | g8 << 8 | r8;
    }
}

buffer에는 RGB형태로 들어오고 buffer2에 넣어줄 때는 BGR형태로 넣어 주어야 한다. Alpha는 그냥 0으로 셋팅하게 되어 있다.

No comments:

Post a Comment

Task in UnrealEngine

 https://www.youtube.com/watch?v=1lBadANnJaw