Text archives Help
- From: arobison@sci.utah.edu
- To: manta@sci.utah.edu
- Subject: [Manta] r1889 - trunk/Image
- Date: Wed, 28 Nov 2007 17:48:06 -0700 (MST)
Author: arobison
Date: Wed Nov 28 17:48:04 2007
New Revision: 1889
Modified:
trunk/Image/CMakeLists.txt
trunk/Image/CoreGraphicsFile.cc
Log:
Fixing a padding issue with the CoreGraphicsFile and enabling it by default
for OS X.
Modified: trunk/Image/CMakeLists.txt
==============================================================================
--- trunk/Image/CMakeLists.txt (original)
+++ trunk/Image/CMakeLists.txt Wed Nov 28 17:48:04 2007
@@ -30,7 +30,7 @@
###############################################################################
# Locate CoreGraphics
IF(APPLE)
- SET(MANTA_USE_COREGRAPHICS OFF CACHE BOOL "Enable CoreGraphics support")
+ SET(MANTA_USE_COREGRAPHICS ON CACHE BOOL "Enable CoreGraphics support")
FIND_LIBRARY(COREGRAPHICS_FRAMEWORK ApplicationServices)
Modified: trunk/Image/CoreGraphicsFile.cc
==============================================================================
--- trunk/Image/CoreGraphicsFile.cc (original)
+++ trunk/Image/CoreGraphicsFile.cc Wed Nov 28 17:48:04 2007
@@ -10,6 +10,8 @@
#include <ApplicationServices/ApplicationServices.h>
+#include <iostream>
+
using namespace Manta;
namespace /* anonymous */ {
@@ -127,10 +129,11 @@
size_t width = CGImageGetWidth(cg_image);
size_t height = CGImageGetHeight(cg_image);
+ float* raw_pixels = new float[width*height*4];
+
SimpleImage<RGBAfloatPixel>* image = new
SimpleImage<RGBAfloatPixel>(false, width, height);
- void* pixels = image->getRawData(0);
- CGContextRef context = createRGBABitmapContext(cg_image, pixels);
+ CGContextRef context = createRGBABitmapContext(cg_image, raw_pixels);
if(context == NULL) {
throw InternalError("Could not create CoreGraphics image context");
}
@@ -140,8 +143,19 @@
CGContextScaleCTM(context, 1.0, -1.0);
CGContextDrawImage(context, rect, cg_image);
+ // we must perform a pixel by pixel copy because of SimpleImage's padding
scheme.
+ RGBAfloatPixel* pixels = (RGBAfloatPixel*)raw_pixels;
+ for(unsigned int j = 0; j < height; ++j) {
+ for(unsigned int i = 0; i < width; ++i) {
+ RGBAfloatPixel* p = &pixels[i + width*j];
+ image->set(*p, i, j, 0);
+ }
+ }
+
CGContextRelease(context);
CGImageRelease(cg_image);
+
+ delete[] raw_pixels;
return image;
}
- [Manta] r1889 - trunk/Image, arobison, 11/28/2007
Archive powered by MHonArc 2.6.16.