aboutsummaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
authorelektrahesse2010-11-02 01:04:47 +0100
committerelektrahesse2010-11-02 01:04:47 +0100
commitb94ba21f2eeb3ff3f59a0c86e9eace89c1db0576 (patch)
treef16c699c61e04fa869a1eef9d462efcacf5859d1
parentUpdated Info.plist for 2010.10.23 release date (diff)
downloadmeta-impy-b94ba21f2eeb3ff3f59a0c86e9eace89c1db0576.zip
meta-impy-b94ba21f2eeb3ff3f59a0c86e9eace89c1db0576.tar.gz
meta-impy-b94ba21f2eeb3ff3f59a0c86e9eace89c1db0576.tar.bz2
meta-impy-b94ba21f2eeb3ff3f59a0c86e9eace89c1db0576.tar.xz
Fixed a bunch of problems with images uploads on mac, including transparent pngs and tgas not rendering correctly.
-rw-r--r--linden/indra/llwindow/llwindowmacosx-objc.h2
-rw-r--r--linden/indra/llwindow/llwindowmacosx-objc.mm37
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);
49OSErr releaseImageCursor(CursorRef ref); 49OSErr releaseImageCursor(CursorRef ref);
50OSErr setImageCursor(CursorRef ref); 50OSErr setImageCursor(CursorRef ref);
51BOOL decodeImageQuartz(std::string filename, LLImageRaw *raw_image); 51BOOL decodeImageQuartz(std::string filename, LLImageRaw *raw_image);
52BOOL decodeImageQuartz(const UInt8* data, int len, LLImageRaw *raw_image); 52BOOL 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 @@
43 */ 43 */
44 44
45#include "llwindowmacosx-objc.h" 45#include "llwindowmacosx-objc.h"
46#include "lldir.h"
46 47
47BOOL decodeImageQuartz(const UInt8* data, int len, LLImageRaw *raw_image) 48BOOL decodeImageQuartz(const UInt8* data, int len, LLImageRaw *raw_image, std::string ext)
48{ 49{
49 CFDataRef theData = CFDataCreate(kCFAllocatorDefault, data, len); 50 CFDataRef theData = CFDataCreate(kCFAllocatorDefault, data, len);
51
50 CGImageSourceRef srcRef = CGImageSourceCreateWithData(theData, NULL); 52 CGImageSourceRef srcRef = CGImageSourceCreateWithData(theData, NULL);
51 CGImageRef image_ref = CGImageSourceCreateImageAtIndex(srcRef, 0, NULL); 53 CGImageRef image_ref = CGImageSourceCreateImageAtIndex(srcRef, 0, NULL);
54 CFRelease(srcRef);
52 55
53 size_t width = CGImageGetWidth(image_ref); 56 size_t width = CGImageGetWidth(image_ref);
54 size_t height = CGImageGetHeight(image_ref); 57 size_t height = CGImageGetHeight(image_ref);
@@ -58,7 +61,7 @@ BOOL decodeImageQuartz(const UInt8* data, int len, LLImageRaw *raw_image)
58 UInt8* bitmap = (UInt8*)CFDataGetBytePtr(result); 61 UInt8* bitmap = (UInt8*)CFDataGetBytePtr(result);
59 62
60 CGImageAlphaInfo format = CGImageGetAlphaInfo(image_ref); 63 CGImageAlphaInfo format = CGImageGetAlphaInfo(image_ref);
61 if (format != kCGImageAlphaNone) 64 if (comps == 4)
62 { 65 {
63 vImage_Buffer vb; 66 vImage_Buffer vb;
64 vb.data = bitmap; 67 vb.data = bitmap;
@@ -68,29 +71,13 @@ BOOL decodeImageQuartz(const UInt8* data, int len, LLImageRaw *raw_image)
68 71
69 if (format & kCGImageAlphaPremultipliedFirst) 72 if (format & kCGImageAlphaPremultipliedFirst)
70 { 73 {
71 // Ele: ARGB -> BGRA on Intel, need to first reorder the bytes, then unpremultiply as RGBA :) 74 // Ele: Skip unpremultiplication for PSD, PNG and TGA files
72 llinfos << "Unpremultiplying BGRA8888" << llendl; 75 if (ext != std::string("psd") && ext != std::string("tga") && ext != std::string("png"))
73 76 vImageUnpremultiplyData_ARGB8888(&vb, &vb, 0);
74 for (int i=0; i<height; i++)
75 {
76 for (int j=0; j<bytes_per_row; j+=4)
77 {
78 unsigned char tmp[4];
79
80 tmp[0] = bitmap[j*height+3];
81 tmp[1] = bitmap[j*height+2];
82 tmp[2] = bitmap[j*height+1];
83 tmp[3] = bitmap[j*height];
84
85 memcpy(&bitmap[j*height], &tmp, 4);
86 }
87 }
88
89 vImageUnpremultiplyData_RGBA8888(&vb, &vb, 0);
90 } 77 }
91 else if (format & kCGImageAlphaPremultipliedLast) 78 else if (format & kCGImageAlphaPremultipliedLast)
92 { 79 {
93 llinfos << "Unpremultiplying RGBA8888" << llendl; 80 // Ele: Photoshop Native Transparency needs unmultiplication
94 vImageUnpremultiplyData_RGBA8888(&vb, &vb, 0); 81 vImageUnpremultiplyData_RGBA8888(&vb, &vb, 0);
95 } 82 }
96 } 83 }
@@ -100,7 +87,6 @@ BOOL decodeImageQuartz(const UInt8* data, int len, LLImageRaw *raw_image)
100 raw_image->verticalFlip(); 87 raw_image->verticalFlip();
101 88
102 CFRelease(theData); 89 CFRelease(theData);
103 CFRelease(srcRef);
104 CGImageRelease(image_ref); 90 CGImageRelease(image_ref);
105 CFRelease(result); 91 CFRelease(result);
106 92
@@ -112,7 +98,10 @@ BOOL decodeImageQuartz(std::string filename, LLImageRaw *raw_image)
112 NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; 98 NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
113 NSURL *url = [[NSURL alloc] initFileURLWithPath:[NSString stringWithCString:filename.c_str()]]; 99 NSURL *url = [[NSURL alloc] initFileURLWithPath:[NSString stringWithCString:filename.c_str()]];
114 NSData *data = [NSData dataWithContentsOfURL:url]; 100 NSData *data = [NSData dataWithContentsOfURL:url];
115 BOOL result = decodeImageQuartz((UInt8*)[data bytes], [data length], raw_image); 101
102 std::string ext = gDirUtilp->getExtension(filename);
103
104 BOOL result = decodeImageQuartz((UInt8*)[data bytes], [data length], raw_image, ext);
116 [pool release]; 105 [pool release];
117 return result; 106 return result;
118} 107}