Text archives Help
- From: arobison@sci.utah.edu
- To: manta@sci.utah.edu
- Subject: [Manta] r1886 - in trunk: Image Model/Textures
- Date: Wed, 28 Nov 2007 16:57:40 -0700 (MST)
Author: arobison
Date: Wed Nov 28 16:57:38 2007
New Revision: 1886
Added:
trunk/Image/CoreGraphicsFile-stub.cc
trunk/Image/CoreGraphicsFile.cc
trunk/Image/CoreGraphicsFile.h
Modified:
trunk/Image/CMakeLists.txt
trunk/Image/EXRFile-stub.cc
trunk/Model/Textures/ImageTexture.cc
Log:
Initial implementation of CoreGraphics image loading on OS X. Currently
disabled in CMake.
Modified: trunk/Image/CMakeLists.txt
==============================================================================
--- trunk/Image/CMakeLists.txt (original)
+++ trunk/Image/CMakeLists.txt Wed Nov 28 16:57:38 2007
@@ -27,18 +27,39 @@
SET (ImageMagick_SRC ImageMagickFile.h ImageMagickFile-stub.cc)
ENDIF(ImageMagickPP_FOUND)
+###############################################################################
+# Locate CoreGraphics
+IF(APPLE)
+ SET(USE_COREGRAPHICS OFF CACHE BOOL "Enable CoreGraphics support")
+
+ FIND_LIBRARY(COREGRAPHICS_FRAMEWORK ApplicationServices)
+
+ IF(USE_COREGRAPHICS)
+ SET(CoreGraphics_SRC CoreGraphicsFile.h CoreGraphicsFile.cc)
+ ELSE(USE_COREGRAPHICS)
+ SET(CoreGraphics_SRC CoreGraphicsFile.h CoreGraphicsFile-stub.cc)
+ ENDIF(USE_COREGRAPHICS)
+
+ELSE(APPLE)
+ SET(CoreGraphics_SRC CoreGraphicsFile.h CoreGraphicsFile-stub.cc)
+ENDIF(APPLE)
+
###############################################################################
# Locate OpenEXR
-INCLUDE (${CMAKE_SOURCE_DIR}/CMake/FindOpenEXR.cmake)
+IF(NOT APPLE)
+ INCLUDE (${CMAKE_SOURCE_DIR}/CMake/FindOpenEXR.cmake)
-IF (OpenEXR_FOUND)
- # Add the EXR files
- SET (EXR_SRC EXRFile.h EXRFile.cc)
- INCLUDE_DIRECTORIES(${OpenEXR_Include_Dir})
-ELSE(OpenEXR_FOUND)
+ IF (OpenEXR_FOUND)
+ # Add the EXR files
+ SET (EXR_SRC EXRFile.h EXRFile.cc)
+ INCLUDE_DIRECTORIES(${OpenEXR_Include_Dir})
+ ELSE(OpenEXR_FOUND)
+ SET (EXR_SRC EXRFile.h EXRFile-stub.cc)
+ ENDIF(OpenEXR_FOUND)
+ELSE(NOT APPLE)
SET (EXR_SRC EXRFile.h EXRFile-stub.cc)
-ENDIF(OpenEXR_FOUND)
+ENDIF(NOT APPLE)
@@ -62,6 +83,7 @@
${NRRD_IMAGE_SRC}
${ImageMagick_SRC}
${EXR_SRC}
+ ${CoreGraphics_SRC}
)
TARGET_LINK_LIBRARIES(Manta_Image
@@ -82,3 +104,6 @@
TARGET_LINK_LIBRARIES(Manta_Image ${TEEM_LIBRARY})
ENDIF(FOUND_TEEM)
+IF(APPLE)
+ TARGET_LINK_LIBRARIES(Manta_Image ${COREGRAPHICS_FRAMEWORK})
+ENDIF(APPLE)
Added: trunk/Image/CoreGraphicsFile-stub.cc
==============================================================================
--- (empty file)
+++ trunk/Image/CoreGraphicsFile-stub.cc Wed Nov 28 16:57:38 2007
@@ -0,0 +1,32 @@
+
+#include <Image/CoreGraphicsFile.h>
+
+#include <Core/Exceptions/InputError.h>
+#include <Core/Exceptions/OutputError.h>
+
+class Manta::Image;
+
+extern "C"
+bool isCoreGraphics( const std::string& filename )
+{
+ return false;
+}
+
+extern "C"
+void writeCoreGraphics( const Manta::Image* image, const std::string
&filename, int which=0 )
+{
+ throw Manta::OutputError("CoreGraphics is not supported on this platform");
+}
+
+extern "C"
+Manta::Image* readCoreGraphics( const std::string& filename )
+{
+ throw Manta::OutputError("CoreGraphics is not supported on this platform");
+}
+
+// Returns true if this reader is supported
+extern "C"
+bool CoreGraphicsSupported()
+{
+ return false;
+}
Added: trunk/Image/CoreGraphicsFile.cc
==============================================================================
--- (empty file)
+++ trunk/Image/CoreGraphicsFile.cc Wed Nov 28 16:57:38 2007
@@ -0,0 +1,150 @@
+
+#include <Image/CoreGraphicsFile.h>
+
+#include <Core/Color/RGBColor.h>
+#include <Image/Pixel.h>
+#include <Image/SimpleImage.h>
+
+#include <Core/Exceptions/InputError.h>
+#include <Core/Exceptions/OutputError.h>
+
+#include <ApplicationServices/ApplicationServices.h>
+
+using namespace Manta;
+
+namespace /* anonymous */ {
+
+ CGImageRef loadImage(const std::string& filename)
+ {
+ CFStringRef path = CFStringCreateWithCString(NULL, filename.c_str(), 0);
+ CFURLRef url = CFURLCreateWithFileSystemPath(NULL, path,
kCFURLPOSIXPathStyle, false);
+ CGImageRef image = NULL;
+ CGImageSourceRef image_source;
+ CFDictionaryRef options = NULL;
+ CFStringRef keys[2];
+ CFTypeRef values[2];
+
+ keys[0] = kCGImageSourceShouldCache;
+ values[0] = (CFTypeRef)kCFBooleanTrue;
+ keys[1] = kCGImageSourceShouldAllowFloat;
+ values[1] = (CFTypeRef)kCFBooleanTrue;
+
+ options = CFDictionaryCreate(NULL, (const void**)keys, (const
void**)values, 2,
+ &kCFTypeDictionaryKeyCallBacks,
+ &kCFTypeDictionaryValueCallBacks);
+
+ image_source = CGImageSourceCreateWithURL(url, options);
+
+ if(image_source == NULL) {
+ throw InputError("Error loading CoreGraphics File: "+filename);
+ }
+
+ image = CGImageSourceCreateImageAtIndex(image_source, 0, NULL);
+
+ CFRelease(image_source);
+
+ return image;
+ }
+
+ CGContextRef createRGBABitmapContext(CGImageRef image, void* data)
+ {
+ CGContextRef context = NULL;
+ CGColorSpaceRef color_space;
+ int byte_count;
+ int bytes_per_row;
+
+ size_t w = CGImageGetWidth(image);
+ size_t h = CGImageGetHeight(image);
+
+ bytes_per_row = (w * 4 * sizeof(float));
+ byte_count = bytes_per_row * h;
+
+ color_space = CGColorSpaceCreateWithName(kCGColorSpaceGenericRGB);
+ if(color_space == NULL) {
+ throw InternalError("Could not create CoreGraphics bitmap context");
+ }
+
+ context = CGBitmapContextCreate(data,
+ w, h,
+ 32,
+ bytes_per_row,
+ color_space,
+ kCGImageAlphaNoneSkipLast |
kCGBitmapFloatComponents);
+
+
+ CGColorSpaceRelease(color_space);
+
+ return context;
+ }
+}
+
+extern "C"
+bool isCoreGraphics( const std::string& filename )
+{
+ // try to create an image source for the file
+ CFStringRef path = CFStringCreateWithCString(NULL, filename.c_str(), 0);
+ CFURLRef url = CFURLCreateWithFileSystemPath(NULL, path,
kCFURLPOSIXPathStyle, false);
+ CGImageSourceRef image_source;
+ CFDictionaryRef options = NULL;
+ CFStringRef keys[2];
+ CFTypeRef values[2];
+
+ keys[0] = kCGImageSourceShouldCache;
+ values[0] = (CFTypeRef)kCFBooleanTrue;
+ keys[1] = kCGImageSourceShouldAllowFloat;
+ values[1] = (CFTypeRef)kCFBooleanTrue;
+
+ options = CFDictionaryCreate(NULL, (const void**)keys, (const
void**)values, 2,
+ &kCFTypeDictionaryKeyCallBacks,
+ &kCFTypeDictionaryValueCallBacks);
+
+ image_source = CGImageSourceCreateWithURL(url, options);
+
+ bool readable = (image_source ? true : false);
+
+ CFRelease(image_source);
+
+ return readable;
+}
+
+extern "C"
+void writeCoreGraphics( const Image* image, const std::string &filename, int
which=0 )
+{
+ throw OutputError("CoreGraphics File I/O does not currently support
writing");
+}
+
+extern "C"
+Image* readCoreGraphics( const std::string& filename )
+{
+ CGImageRef cg_image = loadImage(filename);
+
+ if(cg_image == NULL) {
+ throw InputError("Error reading image from CoreGraphics source:
"+filename);
+ }
+
+ size_t width = CGImageGetWidth(cg_image);
+ size_t height = CGImageGetHeight(cg_image);
+
+ SimpleImage<RGBAfloatPixel>* image = new
SimpleImage<RGBAfloatPixel>(false, width, height);
+ void* pixels = image->getRawData(0);
+
+ CGContextRef context = createRGBABitmapContext(cg_image, pixels);
+ if(context == NULL) {
+ throw InternalError("Could not create CoreGraphics image context");
+ }
+
+ CGRect rect = {{0,0},{width,height}};
+ CGContextDrawImage(context, rect, cg_image);
+
+ CGContextRelease(context);
+ CGImageRelease(cg_image);
+
+ return image;
+}
+
+// Returns true if this reader is supported
+extern "C"
+bool CoreGraphicsSupported()
+{
+ return true;
+}
Added: trunk/Image/CoreGraphicsFile.h
==============================================================================
--- (empty file)
+++ trunk/Image/CoreGraphicsFile.h Wed Nov 28 16:57:38 2007
@@ -0,0 +1,53 @@
+
+/*
+ For more information, please see:
http://software.sci.utah.edu
+
+ The MIT License
+
+ Copyright (c) 2005
+ Scientific Computing and Imaging Institue, University of Utah
+
+ License for the specific language governing rights and limitations under
+ Permission is hereby granted, free of charge, to any person obtaining a
+ copy of this software and associated documentation files (the "Software"),
+ to deal in the Software without restriction, including without limitation
+ the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ and/or sell copies of the Software, and to permit persons to whom the
+ Software is furnished to do so, subject to the following conditions:
+
+ The above copyright notice and this permission notice shall be included
+ in all copies or substantial portions of the Software.
+
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+ OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ DEALINGS IN THE SOFTWARE.
+*/
+
+#ifndef _Manta_Image_CoreGraphics_File_h_
+#define _Manta_Image_CoreGraphics_File_h_
+
+#include <string>
+
+namespace Manta
+{
+ class Image;
+
+ extern "C"
+ bool isCoreGraphics( const std::string& filename );
+
+ extern "C"
+ void writeCoreGraphics( const Image* image, const std::string &filename,
int which=0 );
+
+ extern "C"
+ Image* readCoreGraphics( const std::string& filename );
+
+ // Returns true if this reader is supported
+ extern "C"
+ bool CoreGraphicsSupported();
+};
+
+#endif
Modified: trunk/Image/EXRFile-stub.cc
==============================================================================
--- trunk/Image/EXRFile-stub.cc (original)
+++ trunk/Image/EXRFile-stub.cc Wed Nov 28 16:57:38 2007
@@ -56,14 +56,14 @@
std::string const &file_name, int which )
{
throw Manta::OutputError( "EXR writing not supported by this build.
Perhaps \
- you need to add the path to the Teem libraries.");
+ you need to add the path to the OpenEXR libraries.");
}
extern "C" Manta::Image *readEXR( const std::string &file_name )
{
throw Manta::InputError( "EXR reading not supported by this build.
Perhaps \
- you need to add the path to the Teem libraries.");
+ you need to add the path to the OpenEXR libraries.");
return NULL;
}
Modified: trunk/Model/Textures/ImageTexture.cc
==============================================================================
--- trunk/Model/Textures/ImageTexture.cc (original)
+++ trunk/Model/Textures/ImageTexture.cc Wed Nov 28 16:57:38 2007
@@ -36,6 +36,7 @@
#include <Core/Math/MiscMath.h>
#include <Core/Math/Trig.h>
+#include <Image/CoreGraphicsFile.h>
#include <Image/ImageMagickFile.h>
#include <Image/NRRDFile.h>
#include <Image/RGBEFile.h>
@@ -73,6 +74,9 @@
} else if (isRGBE) {
image = readRGBE(file_name);
if (stream) (*stream) << "Read by readRGBE\n";
+ } else if ( CoreGraphicsSupported() && isCoreGraphics(file_name) ) {
+ image = readCoreGraphics(file_name);
+ if (stream) (*stream) << "Read by readCoreGraphics\n";
} else if ( isEXR( file_name ) && EXRSupported() ) {
image = readEXR(file_name);
if (stream) (*stream) << "Read by readEXR\n";
- [Manta] r1886 - in trunk: Image Model/Textures, arobison, 11/28/2007
Archive powered by MHonArc 2.6.16.