aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/linden/indra/llwindow/llwindowmacosx-objc.mm
diff options
context:
space:
mode:
authorMcCabe Maxsted2010-11-01 17:08:26 -0700
committerMcCabe Maxsted2010-11-01 17:08:26 -0700
commit451d7cfeb862c1be69a76e8f9a5ff9b4ad1ca6d6 (patch)
tree09658db5240517f27897689cf06505d126c4a194 /linden/indra/llwindow/llwindowmacosx-objc.mm
parentFixes a missing help button, adds ability to edit trees like normal objects. ... (diff)
parentFixed a bunch of problems with images uploads on mac, including transparent p... (diff)
downloadmeta-impy-451d7cfeb862c1be69a76e8f9a5ff9b4ad1ca6d6.zip
meta-impy-451d7cfeb862c1be69a76e8f9a5ff9b4ad1ca6d6.tar.gz
meta-impy-451d7cfeb862c1be69a76e8f9a5ff9b4ad1ca6d6.tar.bz2
meta-impy-451d7cfeb862c1be69a76e8f9a5ff9b4ad1ca6d6.tar.xz
Merge remote branch 'elektra/weekly' into weekly
Diffstat (limited to 'linden/indra/llwindow/llwindowmacosx-objc.mm')
-rw-r--r--linden/indra/llwindow/llwindowmacosx-objc.mm37
1 files changed, 13 insertions, 24 deletions
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}