aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/linden/indra/llwindow
diff options
context:
space:
mode:
authorelektrahesse2010-10-13 04:09:26 +0200
committerelektrahesse2010-10-13 04:09:26 +0200
commitd39b5c51f3a7cd36a4dc86423ce099e421263bcc (patch)
tree1f8703cd9e938acff57c158873d5819ceb6dc5b5 /linden/indra/llwindow
parentAdded CodeBastard Redgrave and Elektra Hesse as Imp Devels on the minimap :) (diff)
downloadmeta-impy-d39b5c51f3a7cd36a4dc86423ce099e421263bcc.zip
meta-impy-d39b5c51f3a7cd36a4dc86423ce099e421263bcc.tar.gz
meta-impy-d39b5c51f3a7cd36a4dc86423ce099e421263bcc.tar.bz2
meta-impy-d39b5c51f3a7cd36a4dc86423ce099e421263bcc.tar.xz
Added support for upload and local usage of PSD (Photoshop, including layers and native transparency) and TIFF images (including alpha channel) on any Intel Mac using native Quartz/vImage routines
Diffstat (limited to 'linden/indra/llwindow')
-rw-r--r--linden/indra/llwindow/llwindowmacosx-objc.mm45
1 files changed, 30 insertions, 15 deletions
diff --git a/linden/indra/llwindow/llwindowmacosx-objc.mm b/linden/indra/llwindow/llwindowmacosx-objc.mm
index 5f33764..e961070 100644
--- a/linden/indra/llwindow/llwindowmacosx-objc.mm
+++ b/linden/indra/llwindow/llwindowmacosx-objc.mm
@@ -49,7 +49,7 @@ BOOL decodeImageQuartz(const UInt8* data, int len, LLImageRaw *raw_image)
49 CFDataRef theData = CFDataCreate(kCFAllocatorDefault, data, len); 49 CFDataRef theData = CFDataCreate(kCFAllocatorDefault, data, len);
50 CGImageSourceRef srcRef = CGImageSourceCreateWithData(theData, NULL); 50 CGImageSourceRef srcRef = CGImageSourceCreateWithData(theData, NULL);
51 CGImageRef image_ref = CGImageSourceCreateImageAtIndex(srcRef, 0, NULL); 51 CGImageRef image_ref = CGImageSourceCreateImageAtIndex(srcRef, 0, NULL);
52 52 CFShow(CGImageGetColorSpace(image_ref));
53 size_t width = CGImageGetWidth(image_ref); 53 size_t width = CGImageGetWidth(image_ref);
54 size_t height = CGImageGetHeight(image_ref); 54 size_t height = CGImageGetHeight(image_ref);
55 size_t comps = CGImageGetBitsPerPixel(image_ref) / 8; 55 size_t comps = CGImageGetBitsPerPixel(image_ref) / 8;
@@ -58,29 +58,44 @@ BOOL decodeImageQuartz(const UInt8* data, int len, LLImageRaw *raw_image)
58 UInt8* bitmap = (UInt8*)CFDataGetBytePtr(result); 58 UInt8* bitmap = (UInt8*)CFDataGetBytePtr(result);
59 59
60 CGImageAlphaInfo format = CGImageGetAlphaInfo(image_ref); 60 CGImageAlphaInfo format = CGImageGetAlphaInfo(image_ref);
61 if (format & kCGImageAlphaPremultipliedFirst) 61 if (format != kCGImageAlphaNone)
62 { 62 {
63 vImage_Buffer vb; 63 vImage_Buffer vb;
64 vb.data = bitmap; 64 vb.data = bitmap;
65 vb.height = height; 65 vb.height = height;
66 vb.width = width; 66 vb.width = width;
67 vb.rowBytes = bytes_per_row; 67 vb.rowBytes = bytes_per_row;
68 llinfos << "Unpremultiplying ARGB888" << llendl; 68
69 vImageUnpremultiplyData_ARGB8888(&vb, &vb, 0); 69 if (format & kCGImageAlphaPremultipliedFirst)
70 } 70 {
71 else if (format & kCGImageAlphaPremultipliedLast) 71 // Ele: ARGB -> BGRA on Intel, need to first reorder the bytes, then unpremultiply as RGBA :)
72 { 72 llinfos << "Unpremultiplying BGRA8888" << llendl;
73 vImage_Buffer vb; 73
74 vb.data = bitmap; 74 for (int i=0; i<height; i++)
75 vb.height = height; 75 {
76 vb.width = width; 76 for (int j=0; j<bytes_per_row; j+=4)
77 vb.rowBytes = bytes_per_row; 77 {
78 llinfos << "Unpremultiplying RGBA888" << llendl; 78 unsigned char tmp[4];
79 vImageUnpremultiplyData_RGBA8888(&vb, &vb, 0); 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 }
91 else if (format & kCGImageAlphaPremultipliedLast)
92 {
93 llinfos << "Unpremultiplying RGBA8888" << llendl;
94 vImageUnpremultiplyData_RGBA8888(&vb, &vb, 0);
95 }
80 } 96 }
81 97
82 raw_image->resize(width, height, comps); 98 raw_image->resize(width, height, comps);
83 llinfos << "Decoding an image of width: " << width << " and height: " << height << " and components: " << comps << llendl;
84 memcpy(raw_image->getData(), bitmap, height * bytes_per_row); 99 memcpy(raw_image->getData(), bitmap, height * bytes_per_row);
85 raw_image->verticalFlip(); 100 raw_image->verticalFlip();
86 101