From b94ba21f2eeb3ff3f59a0c86e9eace89c1db0576 Mon Sep 17 00:00:00 2001 From: elektrahesse Date: Tue, 2 Nov 2010 01:04:47 +0100 Subject: Fixed a bunch of problems with images uploads on mac, including transparent pngs and tgas not rendering correctly. --- linden/indra/llwindow/llwindowmacosx-objc.h | 2 +- linden/indra/llwindow/llwindowmacosx-objc.mm | 37 ++++++++++------------------ 2 files changed, 14 insertions(+), 25 deletions(-) diff --git a/linden/indra/llwindow/llwindowmacosx-objc.h b/linden/indra/llwindow/llwindowmacosx-objc.h index 14c9c92..a96246e 100644 --- a/linden/indra/llwindow/llwindowmacosx-objc.h +++ b/linden/indra/llwindow/llwindowmacosx-objc.h @@ -49,4 +49,4 @@ CursorRef createImageCursor(const char *fullpath, int hotspotX, int hotspotY); OSErr releaseImageCursor(CursorRef ref); OSErr setImageCursor(CursorRef ref); BOOL decodeImageQuartz(std::string filename, LLImageRaw *raw_image); -BOOL decodeImageQuartz(const UInt8* data, int len, LLImageRaw *raw_image); +BOOL decodeImageQuartz(const UInt8* data, int len, LLImageRaw *raw_image, std::string ext); diff --git a/linden/indra/llwindow/llwindowmacosx-objc.mm b/linden/indra/llwindow/llwindowmacosx-objc.mm index abe8c5d..80ad087 100644 --- a/linden/indra/llwindow/llwindowmacosx-objc.mm +++ b/linden/indra/llwindow/llwindowmacosx-objc.mm @@ -43,12 +43,15 @@ */ #include "llwindowmacosx-objc.h" +#include "lldir.h" -BOOL decodeImageQuartz(const UInt8* data, int len, LLImageRaw *raw_image) +BOOL decodeImageQuartz(const UInt8* data, int len, LLImageRaw *raw_image, std::string ext) { CFDataRef theData = CFDataCreate(kCFAllocatorDefault, data, len); + CGImageSourceRef srcRef = CGImageSourceCreateWithData(theData, NULL); CGImageRef image_ref = CGImageSourceCreateImageAtIndex(srcRef, 0, NULL); + CFRelease(srcRef); size_t width = CGImageGetWidth(image_ref); size_t height = CGImageGetHeight(image_ref); @@ -58,7 +61,7 @@ BOOL decodeImageQuartz(const UInt8* data, int len, LLImageRaw *raw_image) UInt8* bitmap = (UInt8*)CFDataGetBytePtr(result); CGImageAlphaInfo format = CGImageGetAlphaInfo(image_ref); - if (format != kCGImageAlphaNone) + if (comps == 4) { vImage_Buffer vb; vb.data = bitmap; @@ -68,29 +71,13 @@ BOOL decodeImageQuartz(const UInt8* data, int len, LLImageRaw *raw_image) if (format & kCGImageAlphaPremultipliedFirst) { - // Ele: ARGB -> BGRA on Intel, need to first reorder the bytes, then unpremultiply as RGBA :) - llinfos << "Unpremultiplying BGRA8888" << llendl; - - for (int i=0; iverticalFlip(); CFRelease(theData); - CFRelease(srcRef); CGImageRelease(image_ref); CFRelease(result); @@ -112,7 +98,10 @@ BOOL decodeImageQuartz(std::string filename, LLImageRaw *raw_image) NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; NSURL *url = [[NSURL alloc] initFileURLWithPath:[NSString stringWithCString:filename.c_str()]]; NSData *data = [NSData dataWithContentsOfURL:url]; - BOOL result = decodeImageQuartz((UInt8*)[data bytes], [data length], raw_image); + + std::string ext = gDirUtilp->getExtension(filename); + + BOOL result = decodeImageQuartz((UInt8*)[data bytes], [data length], raw_image, ext); [pool release]; return result; } -- cgit v1.1