aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/linden/indra/llwindow
diff options
context:
space:
mode:
authorelektrahesse2010-10-09 19:05:40 +0200
committerelektrahesse2010-10-09 19:07:11 +0200
commit565d2e1389b0a72e6eca7068988a9312991abfb1 (patch)
tree7103015e3c024cbeb48ff1e7c89dd14bb6ce12ff /linden/indra/llwindow
parentChanged version to Experimental 2010.10.09 (diff)
downloadmeta-impy-565d2e1389b0a72e6eca7068988a9312991abfb1.zip
meta-impy-565d2e1389b0a72e6eca7068988a9312991abfb1.tar.gz
meta-impy-565d2e1389b0a72e6eca7068988a9312991abfb1.tar.bz2
meta-impy-565d2e1389b0a72e6eca7068988a9312991abfb1.tar.xz
Mac Only: Implemented initial CoreGraphics image decoding to support uploads, both single and bulk, bypassing viewer's internal decoding classes and using osx native frameworks. Also pushing non-fully-working-yet (and thus disabled) code for native j2c decoding.
Diffstat (limited to 'linden/indra/llwindow')
-rw-r--r--linden/indra/llwindow/llwindowmacosx-objc.h10
-rw-r--r--linden/indra/llwindow/llwindowmacosx-objc.mm60
2 files changed, 70 insertions, 0 deletions
diff --git a/linden/indra/llwindow/llwindowmacosx-objc.h b/linden/indra/llwindow/llwindowmacosx-objc.h
index 14cddaa..14c9c92 100644
--- a/linden/indra/llwindow/llwindowmacosx-objc.h
+++ b/linden/indra/llwindow/llwindowmacosx-objc.h
@@ -31,6 +31,14 @@
31 * $/LicenseInfo$ 31 * $/LicenseInfo$
32 */ 32 */
33 33
34#include "llimagej2c.h"
35#include <Carbon/Carbon.h>
36
37#ifdef __OBJC__
38#ifdef BOOL
39#undef BOOL
40#endif
41#endif // __OBJC__
34 42
35// This will actually hold an NSCursor*, but that type is only available in objective C. 43// This will actually hold an NSCursor*, but that type is only available in objective C.
36typedef void *CursorRef; 44typedef void *CursorRef;
@@ -40,3 +48,5 @@ void setupCocoa();
40CursorRef createImageCursor(const char *fullpath, int hotspotX, int hotspotY); 48CursorRef createImageCursor(const char *fullpath, int hotspotX, int hotspotY);
41OSErr releaseImageCursor(CursorRef ref); 49OSErr releaseImageCursor(CursorRef ref);
42OSErr setImageCursor(CursorRef ref); 50OSErr setImageCursor(CursorRef ref);
51BOOL decodeImageQuartz(std::string filename, LLImageRaw *raw_image);
52BOOL decodeImageQuartz(const UInt8* data, int len, LLImageRaw *raw_image);
diff --git a/linden/indra/llwindow/llwindowmacosx-objc.mm b/linden/indra/llwindow/llwindowmacosx-objc.mm
index bc47164..5f33764 100644
--- a/linden/indra/llwindow/llwindowmacosx-objc.mm
+++ b/linden/indra/llwindow/llwindowmacosx-objc.mm
@@ -32,6 +32,8 @@
32 */ 32 */
33 33
34#include <AppKit/AppKit.h> 34#include <AppKit/AppKit.h>
35#include <Accelerate/Accelerate.h>
36#include <Quartz/Quartz.h>
35 37
36/* 38/*
37 * These functions are broken out into a separate file because the 39 * These functions are broken out into a separate file because the
@@ -42,6 +44,64 @@
42 44
43#include "llwindowmacosx-objc.h" 45#include "llwindowmacosx-objc.h"
44 46
47BOOL decodeImageQuartz(const UInt8* data, int len, LLImageRaw *raw_image)
48{
49 CFDataRef theData = CFDataCreate(kCFAllocatorDefault, data, len);
50 CGImageSourceRef srcRef = CGImageSourceCreateWithData(theData, NULL);
51 CGImageRef image_ref = CGImageSourceCreateImageAtIndex(srcRef, 0, NULL);
52
53 size_t width = CGImageGetWidth(image_ref);
54 size_t height = CGImageGetHeight(image_ref);
55 size_t comps = CGImageGetBitsPerPixel(image_ref) / 8;
56 size_t bytes_per_row = CGImageGetBytesPerRow(image_ref);
57 CFDataRef result = CGDataProviderCopyData(CGImageGetDataProvider(image_ref));
58 UInt8* bitmap = (UInt8*)CFDataGetBytePtr(result);
59
60 CGImageAlphaInfo format = CGImageGetAlphaInfo(image_ref);
61 if (format & kCGImageAlphaPremultipliedFirst)
62 {
63 vImage_Buffer vb;
64 vb.data = bitmap;
65 vb.height = height;
66 vb.width = width;
67 vb.rowBytes = bytes_per_row;
68 llinfos << "Unpremultiplying ARGB888" << llendl;
69 vImageUnpremultiplyData_ARGB8888(&vb, &vb, 0);
70 }
71 else if (format & kCGImageAlphaPremultipliedLast)
72 {
73 vImage_Buffer vb;
74 vb.data = bitmap;
75 vb.height = height;
76 vb.width = width;
77 vb.rowBytes = bytes_per_row;
78 llinfos << "Unpremultiplying RGBA888" << llendl;
79 vImageUnpremultiplyData_RGBA8888(&vb, &vb, 0);
80 }
81
82 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);
85 raw_image->verticalFlip();
86
87 CFRelease(theData);
88 CFRelease(srcRef);
89 CGImageRelease(image_ref);
90 CFRelease(result);
91
92 return TRUE;
93}
94
95BOOL decodeImageQuartz(std::string filename, LLImageRaw *raw_image)
96{
97 NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
98 NSURL *url = [[NSURL alloc] initFileURLWithPath:[NSString stringWithCString:filename.c_str()]];
99 NSData *data = [NSData dataWithContentsOfURL:url];
100 BOOL result = decodeImageQuartz((UInt8*)[data bytes], [data length], raw_image);
101 [pool release];
102 return result;
103}
104
45void setupCocoa() 105void setupCocoa()
46{ 106{
47 static bool inited = false; 107 static bool inited = false;