aboutsummaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--linden/indra/llcommon/stdtypes.h9
-rw-r--r--linden/indra/llimagej2coj/CMakeLists.txt19
-rw-r--r--linden/indra/llimagej2coj/llimagej2cquartz.h9
-rw-r--r--linden/indra/llimagej2coj/llimagej2cquartz.mm147
-rw-r--r--linden/indra/llwindow/llwindowmacosx-objc.h10
-rw-r--r--linden/indra/llwindow/llwindowmacosx-objc.mm60
-rw-r--r--linden/indra/newview/floaterlocalassetbrowse.cpp11
-rw-r--r--linden/indra/newview/llfloaterimagepreview.cpp12
-rw-r--r--linden/indra/newview/llviewerimagelist.cpp11
9 files changed, 282 insertions, 6 deletions
diff --git a/linden/indra/llcommon/stdtypes.h b/linden/indra/llcommon/stdtypes.h
index af0b4dd..aed1e46 100644
--- a/linden/indra/llcommon/stdtypes.h
+++ b/linden/indra/llcommon/stdtypes.h
@@ -64,10 +64,17 @@ typedef long long unsigned int U64;
64#endif 64#endif
65#endif 65#endif
66 66
67#ifdef LL_DARWIN
68 #ifndef BOOL
69 #define BOOL S32
70 #endif
71#else
72 typedef S32 BOOL;
73#endif
74
67typedef float F32; 75typedef float F32;
68typedef double F64; 76typedef double F64;
69 77
70typedef S32 BOOL;
71typedef U8 KEY; 78typedef U8 KEY;
72typedef U32 MASK; 79typedef U32 MASK;
73typedef U32 TPACKETID; 80typedef U32 TPACKETID;
diff --git a/linden/indra/llimagej2coj/CMakeLists.txt b/linden/indra/llimagej2coj/CMakeLists.txt
index 97d22cf..30f73ab 100644
--- a/linden/indra/llimagej2coj/CMakeLists.txt
+++ b/linden/indra/llimagej2coj/CMakeLists.txt
@@ -19,10 +19,26 @@ set(llimagej2coj_SOURCE_FILES
19 19
20set(llimagej2coj_HEADER_FILES 20set(llimagej2coj_HEADER_FILES
21 CMakeLists.txt 21 CMakeLists.txt
22
23 llimagej2coj.h 22 llimagej2coj.h
24 ) 23 )
25 24
25set(COREIMAGE_LIBRARIES)
26
27if (DARWIN)
28 list(APPEND llimagej2coj_SOURCE_FILES
29 llimagej2cquartz.mm
30 )
31 list(APPEND llimagej2coj_HEADER_FILES
32 llimagej2cquartz.h
33 )
34
35 find_library(QUARTZCORE_LIBRARY QuartzCore)
36 find_library(ACCELERATE_LIBRARY Accelerate)
37
38 list(APPEND COREIMAGE_LIBRARIES ${QUARTZCORE_LIBRARY})
39 list(APPEND COREIMAGE_LIBRARIES ${ACCELERATE_LIBRARY})
40endif (DARWIN)
41
26set_source_files_properties(${llimagej2coj_HEADER_FILES} 42set_source_files_properties(${llimagej2coj_HEADER_FILES}
27 PROPERTIES HEADER_FILE_ONLY TRUE) 43 PROPERTIES HEADER_FILE_ONLY TRUE)
28 44
@@ -32,4 +48,5 @@ add_library (llimagej2coj ${llimagej2coj_SOURCE_FILES})
32target_link_libraries( 48target_link_libraries(
33 llimagej2coj 49 llimagej2coj
34 ${OPENJPEG_LIBRARIES} 50 ${OPENJPEG_LIBRARIES}
51 ${COREIMAGE_LIBRARIES}
35 ) 52 )
diff --git a/linden/indra/llimagej2coj/llimagej2cquartz.h b/linden/indra/llimagej2coj/llimagej2cquartz.h
new file mode 100644
index 0000000..ba11bfd
--- /dev/null
+++ b/linden/indra/llimagej2coj/llimagej2cquartz.h
@@ -0,0 +1,9 @@
1#include "llimagej2c.h"
2
3#ifdef __OBJC__
4 #ifdef BOOL
5 #undef BOOL
6 #endif
7#endif // __OBJC__
8
9BOOL decodeJ2CQuartz(LLImageJ2C &base, LLImageRaw &raw_image, F32 decode_time, S32 first_channel, S32 max_channel_count); \ No newline at end of file
diff --git a/linden/indra/llimagej2coj/llimagej2cquartz.mm b/linden/indra/llimagej2coj/llimagej2cquartz.mm
new file mode 100644
index 0000000..d5eefd1
--- /dev/null
+++ b/linden/indra/llimagej2coj/llimagej2cquartz.mm
@@ -0,0 +1,147 @@
1#import <Accelerate/Accelerate.h>
2#import <QuartzCore/QuartzCore.h>
3#import <Quartz/Quartz.h>
4
5#include "llimagej2cquartz.h"
6
7#if defined(__BIG_ENDIAN__)
8 CGImageAlphaInfo const kDefaultAlphaLocation = kCGImageAlphaPremultipliedLast;
9#else
10 CGImageAlphaInfo const kDefaultAlphaLocation = kCGImageAlphaPremultipliedFirst;
11#endif
12
13BOOL decodeJ2CQuartz(LLImageJ2C &base, LLImageRaw &raw_image, F32 decode_time, S32 first_channel, S32 max_channel_count)
14{
15 U8 *srcData = (U8*)base.getData();
16 int srcLen = base.getDataSize();
17
18 llinfos << "[1] compressed image size: '" << srcLen << "'" << llendl;
19
20 int width = base.getWidth();
21 int height = base.getHeight();
22 int components = base.getComponents();
23
24 S32 channels = components - first_channel;
25 if( channels > max_channel_count )
26 channels = max_channel_count;
27
28 llinfos << "[2] components: '" << components << "' - channels: '" << channels << "' - first_channel: '" << first_channel << "' - max_channel_count: '" << max_channel_count << "'" << llendl;
29
30 if(components <= first_channel || components > 4)
31 return FALSE;
32
33 llinfos << "[3] attempting to decode a texture: '" << width << "'X'" << height << "'@'" << components * 8 << "'" << llendl;
34
35 U8 *tgt = (U8*)raw_image.getData();
36 if (!tgt)
37 return FALSE;
38
39 raw_image.resize(width, height, channels);
40
41 size_t rowBytes = width * components;
42 int realLen = width * height * components;
43
44 llinfos << "[4] allocating buffer of size: '" << realLen << "' to hold temp texture data" << llendl;
45 unsigned char* dataplane;
46
47 NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
48 NSBitmapImageRep *rep = [NSBitmapImageRep alloc];
49
50 switch (components)
51 {
52 case 1:
53 {
54 rep = [[rep
55 initWithBitmapDataPlanes:nil
56 pixelsWide:width
57 pixelsHigh:height
58 bitsPerSample:8
59 samplesPerPixel:1
60 hasAlpha:NO
61 isPlanar:NO
62 colorSpaceName:NSDeviceWhiteColorSpace
63 bytesPerRow:rowBytes
64 bitsPerPixel:8
65 ] autorelease];
66
67 memcpy([rep bitmapData], srcData, srcLen);
68
69 dataplane = (unsigned char*)malloc(realLen);
70 memcpy(dataplane, [rep bitmapData], realLen);
71
72 [rep release];
73 }
74 break;
75
76 case 3:
77 {
78 NSData *data = [NSData dataWithBytes:srcData length:srcLen];
79 rep = [rep initWithData:data];
80
81 dataplane = (unsigned char*)malloc(realLen);
82 memcpy(dataplane, [rep bitmapData], realLen);
83
84 [data release];
85 [rep release];
86 }
87 break;
88
89 case 4:
90 {
91 NSData *data = [NSData dataWithBytes:srcData length:srcLen];
92 rep = [rep initWithData:data];
93
94 int imgLen = [rep pixelsHigh] * [rep bytesPerRow];
95 if (imgLen != realLen)
96 {
97 llwarns << "decoded image buffer size (" << imgLen << ") != expected buffer size (" << realLen << ") !" << llendl;
98 [rep release];
99 [data release];
100 return FALSE;
101 }
102
103 dataplane = (unsigned char*)malloc(realLen);
104 memcpy(dataplane, [rep bitmapData], realLen);
105
106 vImage_Buffer vb;
107 vb.data = dataplane;
108 vb.height = [rep pixelsHigh];
109 vb.width = [rep pixelsWide];
110 vb.rowBytes = [rep bytesPerRow];
111
112 llinfos << "Attempting Alpha Unpremultiplication" << llendl;
113 vImageUnpremultiplyData_RGBA8888(&vb, &vb, 0);
114 llinfos << "Unpremultiplied Alpha" << llendl;
115
116 llwarns << "after decoding: " << [rep pixelsWide] << "'X'" << [rep pixelsHigh] << "'@'" << [rep bitsPerPixel] << "'" << llendl;
117
118 [rep release];
119 [data release];
120 }
121 break;
122 }
123
124 if (dataplane)
125 {
126 for (int h=height-1; h>=0; h--)
127 {
128 for (int w=0; w<rowBytes; w+=(first_channel + channels))
129 {
130 for (int c=first_channel; c<(first_channel + channels); c++)
131 memcpy(tgt++, &dataplane[h*rowBytes + w + c], sizeof(unsigned char));
132 }
133 }
134
135 free(dataplane);
136
137 llinfos << "[5] size of decoded image is: '" << width*height*channels << "'" << llendl;
138
139 return TRUE;
140 }
141 else
142 {
143 llwarns << "[5] cannot decode image !" << llendl;
144 }
145
146 return FALSE;
147}
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;
diff --git a/linden/indra/newview/floaterlocalassetbrowse.cpp b/linden/indra/newview/floaterlocalassetbrowse.cpp
index 6564528..443b5bf 100644
--- a/linden/indra/newview/floaterlocalassetbrowse.cpp
+++ b/linden/indra/newview/floaterlocalassetbrowse.cpp
@@ -74,6 +74,9 @@ this feature is still a work in progress.
74#include "llvovolume.h" 74#include "llvovolume.h"
75#include "llface.h" 75#include "llface.h"
76 76
77#ifdef LL_DARWIN
78#include "llwindowmacosx-objc.h"
79#endif
77 80
78/*=======================================*/ 81/*=======================================*/
79/* Instantiating manager class */ 82/* Instantiating manager class */
@@ -227,6 +230,13 @@ void LocalBitmap::updateSelf()
227 230
228bool LocalBitmap::decodeSelf(LLImageRaw* rawimg) 231bool LocalBitmap::decodeSelf(LLImageRaw* rawimg)
229{ 232{
233#ifdef LL_DARWIN
234 if (decodeImageQuartz(filename, rawimg))
235 {
236 rawimg->biasedScaleToPowerOfTwo( LLViewerImage::MAX_IMAGE_SIZE_DEFAULT );
237 return true;
238 }
239#else
230 switch (this->extension) 240 switch (this->extension)
231 { 241 {
232 case IMG_EXTEN_BMP: 242 case IMG_EXTEN_BMP:
@@ -275,6 +285,7 @@ bool LocalBitmap::decodeSelf(LLImageRaw* rawimg)
275 default: 285 default:
276 break; 286 break;
277 } 287 }
288#endif
278 return false; 289 return false;
279} 290}
280 291
diff --git a/linden/indra/newview/llfloaterimagepreview.cpp b/linden/indra/newview/llfloaterimagepreview.cpp
index 9827a31..c81081f 100644
--- a/linden/indra/newview/llfloaterimagepreview.cpp
+++ b/linden/indra/newview/llfloaterimagepreview.cpp
@@ -62,6 +62,10 @@
62 62
63#include "hippoGridManager.h" 63#include "hippoGridManager.h"
64 64
65#ifdef LL_DARWIN
66#include "llwindowmacosx-objc.h"
67#endif
68
65//static 69//static
66S32 LLFloaterImagePreview::sUploadAmount = 10; 70S32 LLFloaterImagePreview::sUploadAmount = 10;
67 71
@@ -353,7 +357,10 @@ bool LLFloaterImagePreview::loadImage(const std::string& src_filename)
353 } 357 }
354 358
355 LLPointer<LLImageRaw> raw_image = new LLImageRaw; 359 LLPointer<LLImageRaw> raw_image = new LLImageRaw;
356 360#ifdef LL_DARWIN
361 if (! decodeImageQuartz(src_filename, raw_image))
362 return false;
363#else
357 switch (codec) 364 switch (codec)
358 { 365 {
359 case IMG_CODEC_BMP: 366 case IMG_CODEC_BMP:
@@ -428,8 +435,9 @@ bool LLFloaterImagePreview::loadImage(const std::string& src_filename)
428 } 435 }
429 436
430 raw_image->biasedScaleToPowerOfTwo(1024); 437 raw_image->biasedScaleToPowerOfTwo(1024);
438#endif
439
431 mRawImagep = raw_image; 440 mRawImagep = raw_image;
432
433 return true; 441 return true;
434} 442}
435 443
diff --git a/linden/indra/newview/llviewerimagelist.cpp b/linden/indra/newview/llviewerimagelist.cpp
index cb02b09..869c9d7 100644
--- a/linden/indra/newview/llviewerimagelist.cpp
+++ b/linden/indra/newview/llviewerimagelist.cpp
@@ -65,6 +65,10 @@
65 65
66#include <sys/stat.h> 66#include <sys/stat.h>
67 67
68#ifdef LL_DARWIN
69#include "llwindowmacosx-objc.h"
70#endif
71
68//////////////////////////////////////////////////////////////////////////// 72////////////////////////////////////////////////////////////////////////////
69 73
70void (*LLViewerImageList::sUUIDCallback)(void **, const LLUUID&) = NULL; 74void (*LLViewerImageList::sUUIDCallback)(void **, const LLUUID&) = NULL;
@@ -920,7 +924,10 @@ BOOL LLViewerImageList::createUploadFile(const std::string& filename,
920{ 924{
921 // First, load the image. 925 // First, load the image.
922 LLPointer<LLImageRaw> raw_image = new LLImageRaw; 926 LLPointer<LLImageRaw> raw_image = new LLImageRaw;
923 927#ifdef LL_DARWIN
928 if (!decodeImageQuartz(filename, raw_image))
929 return FALSE;
930#else
924 switch (codec) 931 switch (codec)
925 { 932 {
926 case IMG_CODEC_BMP: 933 case IMG_CODEC_BMP:
@@ -993,7 +1000,7 @@ BOOL LLViewerImageList::createUploadFile(const std::string& filename,
993 default: 1000 default:
994 return FALSE; 1001 return FALSE;
995 } 1002 }
996 1003#endif
997 LLPointer<LLImageJ2C> compressedImage = convertToUploadFile(raw_image); 1004 LLPointer<LLImageJ2C> compressedImage = convertToUploadFile(raw_image);
998 1005
999 if( !compressedImage->save(out_filename) ) 1006 if( !compressedImage->save(out_filename) )