| | 382 | // |
| | 383 | // Reverse the premultiplied alpha for avoiding unexpected darker edges |
| | 384 | // by Tatsuhiro Nishioka (based on SDL's workaround on the similar issue) |
| | 385 | // http://bugzilla.libsdl.org/show_bug.cgi?id=868 |
| | 386 | // |
| | 387 | if (bits_per_pixel > 8 && (bitmap_info & kCGBitmapAlphaInfoMask) == kCGImageAlphaPremultipliedFirst) { |
| | 388 | int i, j; |
| | 389 | GLubyte *pixels = (GLubyte *)image_data; |
| | 390 | for (i = the_height * the_width; i--; ) { |
| | 391 | GLuint *value = (GLuint *)pixels; |
| | 392 | #if __BIG_ENDIAN__ |
| | 393 | // |
| | 394 | // swap endian of each pixel for avoiding weird colors on ppc macs |
| | 395 | // by Tatsuhiro Nishioka |
| | 396 | // FIXME: I've tried many combinations of pixel_format, internal_format, and data_type |
| | 397 | // but none worked well. Therefore I tried endian swapping, which seems working with gif,png,tiff,tga,and psd. |
| | 398 | // (for grayscaled tga and non-power-of-two tga, I can't guarantee since test images (made with Gimp) |
| | 399 | // get corrupted on Preview.app ... |
| | 400 | *value = ((*value) >> 24) | (((*value) << 8) & 0x00FF0000) | (((*value) >> 8) & 0x0000FF00) | ((*value) << 24); |
| | 401 | #endif |
| | 402 | GLubyte alpha = pixels[3]; |
| | 403 | if (alpha) { |
| | 404 | for (j = 0; j < 3; ++j) { |
| | 405 | pixels[j] = (pixels[j] * 255) / alpha; |
| | 406 | } |
| | 407 | } |
| | 408 | pixels += 4; |
| | 409 | } |
| | 410 | } |
| | 411 | |
| | 412 | // |
| | 413 | // Workaround for ignored alpha channel |
| | 414 | // by Tatsuhiro Nishioka |
| | 415 | // FIXME: specifying GL_UNSIGNED_INT_8_8_8_8_REV or GL_UNSIGNED_INT_8_8_8_8 ignores the alpha channel. |
| | 416 | // changing it to GL_UNSIGNED_BYTE seems working, but I'm not sure if this is a right way. |
| | 417 | // |
| | 418 | data_type = GL_UNSIGNED_BYTE; |