Author: boulos
Date: Mon Jan 7 10:35:27 2008
New Revision: 1973
Added:
trunk/scenes/macbeth.cc
Modified:
trunk/Image/CoreGraphicsFile.cc
trunk/Image/SimpleImage_special.cc
trunk/scenes/CMakeLists.txt
Log:
Image/CoreGraphicsFile.cc
Someone left tabs in this file, but more importantly on Leopard we
can tell CoreGraphics to give us SRGB (on earlier systems only
GenericRGB is available and is slightly off).
Image/SimpleImage_special.cc
Leaving a note about how I tried PowSSE, but have found it to be
inadequate for color matching.
scenes/CMakeLists.txt
scenes/macbeth.cc
Adding a macbeth color checker scene. You specify your image texture,
and it renders it. My image is flipped for some reason (mirrored
across Y), but the colors now come out right.
Modified: trunk/Image/CoreGraphicsFile.cc
= = = = = = = = ======================================================================
--- trunk/Image/CoreGraphicsFile.cc (original)
+++ trunk/Image/CoreGraphicsFile.cc Mon Jan 7 10:35:27 2008
@@ -16,7 +16,7 @@
namespace /* anonymous */ {
- CGImageRef loadImage(const std::string& filename)
+ CGImageRef loadImage(const std::string& filename)
{
CFStringRef path = CFStringCreateWithCString(NULL, filename.c_str(), 0);
CFURLRef url = CFURLCreateWithFileSystemPath(NULL, path, kCFURLPOSIXPathStyle, false);
@@ -31,7 +31,7 @@
keys[1] = kCGImageSourceShouldAllowFloat;
values[1] = (CFTypeRef)kCFBooleanTrue;
- options = CFDictionaryCreate(NULL, (const void**)keys, (const void**)values, 2,
+ options = CFDictionaryCreate(NULL, (const void**)keys, (const void**)values, 2,
&kCFTypeDictionaryKeyCallBacks,
&kCFTypeDictionaryValueCallBacks);
@@ -48,7 +48,7 @@
return image;
}
- CGContextRef createRGBABitmapContext(CGImageRef image, void* data)
+ CGContextRef createRGBABitmapContext(CGImageRef image, void* data)
{
CGContextRef context = NULL;
CGColorSpaceRef color_space;
@@ -61,7 +61,11 @@
bytes_per_row = (w * 4 * sizeof(float));
byte_count = bytes_per_row * h;
+#ifdef APPLE_LEOPARD
+ color_space = CGColorSpaceCreateWithName(kCGColorSpaceSRGB);
+#else
color_space = CGColorSpaceCreateWithName(kCGColorSpaceGenericRGB);
+#endif
if(color_space == NULL) {
throw InternalError("Could not create CoreGraphics bitmap context");
}
@@ -72,7 +76,7 @@
bytes_per_row,
color_space,
kCGImageAlphaNoneSkipLast |
- kCGBitmapFloatComponents |
+ kCGBitmapFloatComponents |
kCGBitmapByteOrder32Host);
@@ -82,7 +86,7 @@
}
}
-extern "C"
+extern "C"
bool isCoreGraphics( const std::string& filename )
{
// try to create an image source for the file
@@ -92,16 +96,16 @@
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,
+
+ options = CFDictionaryCreate(NULL, (const void**)keys, (const void**)values, 2,
&kCFTypeDictionaryKeyCallBacks,
&kCFTypeDictionaryValueCallBacks);
-
+
image_source = CGImageSourceCreateWithURL(url, options);
bool readable = (image_source ? true : false);
@@ -111,13 +115,13 @@
return readable;
}
-extern "C"
+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"
+extern "C"
Image* readCoreGraphics( const std::string& filename )
{
CGImageRef cg_image = loadImage(filename);
@@ -161,7 +165,7 @@
}
// Returns true if this reader is supported
-extern "C"
+extern "C"
bool CoreGraphicsSupported()
{
return true;
Modified: trunk/Image/SimpleImage_special.cc
= = = = = = = = ======================================================================
--- trunk/Image/SimpleImage_special.cc (original)
+++ trunk/Image/SimpleImage_special.cc Mon Jan 7 10:35:27 2008
@@ -19,6 +19,8 @@
// http://www.opengl.org/registry/specs/EXT/framebuffer_sRGB.txt
__m128 use_gamma = _mm_cmplt_ps(_mm_set1_ps(.0031308f), val);
__m128 linear_ver = _mm_mul_ps(val, _mm_set1_ps(12.92f));
+ // NOTE(boulos): PowSSE doesn't seem to cut it for this exponent..,
+ // we might want to do a lookup table or a separate SSE pow...
__m128 gamma_ver = _mm_sub_ps(_mm_mul_ps(_mm_set1_ps(1.055f), PowSSEMathH(val, _mm_set1_ps(0.41666f), use_gamma)), _mm_set1_ps(. 055f));
return mask4(use_gamma, gamma_ver, linear_ver);
#else
Modified: trunk/scenes/CMakeLists.txt
= = = = = = = = ======================================================================
--- trunk/scenes/CMakeLists.txt (original)
+++ trunk/scenes/CMakeLists.txt Mon Jan 7 10:35:27 2008
@@ -115,3 +115,10 @@
ADD_LIBRARY(scene_area_light area_light.cc)
TARGET_LINK_LIBRARIES(scene_area_light ${MANTA_SCENE_LINK})
ENDIF(SCENE_AREA_LIGHT)
+
+# macbeth color checker scene
+SET(SCENE_MACBETH TRUE CACHE BOOL "Macbeth test")
+IF(SCENE_MACBETH)
+ ADD_LIBRARY(scene_macbeth macbeth.cc)
+ TARGET_LINK_LIBRARIES(scene_macbeth ${MANTA_SCENE_LINK})
+ENDIF(SCENE_MACBETH)
Added: trunk/scenes/macbeth.cc
= = = = = = = = ======================================================================
--- (empty file)
+++ trunk/scenes/macbeth.cc Mon Jan 7 10:35:27 2008
@@ -0,0 +1,75 @@
+#include <Core/Exceptions/IllegalArgument.h>
+#include <Core/Exceptions/IllegalValue.h>
+#include <Core/Exceptions/InputError.h>
+#include <Core/Util/Args.h>
+#include <Core/Util/Preprocessor.h>
+#include <Interface/LightSet.h>
+#include <Interface/Scene.h>
+#include <Model/AmbientLights/ConstantAmbient.h>
+#include <Model/Backgrounds/ConstantBackground.h>
+#include <Model/Groups/Group.h>
+#include <Model/Lights/DirectionalLight.h>
+#include <Model/Materials/CopyTextureMaterial.h>
+#include <Model/Primitives/Parallelogram.h>
+#include <Model/TexCoordMappers/LinearMapper.h>
+#include <Model/Textures/ImageTexture.h>
+
+#include <iostream>
+
+using namespace Manta;
+
+void addLights( LightSet* lights)
+{
+ lights->add(new DirectionalLight(Vector(0, 0, 1), Color::white()));
+}
+
+MANTA_PLUGINEXPORT
+Scene* make_scene(const ReadContext&, const vector<string>& args)
+{
+ std::string filename;
+ for(size_t i = 0; i < args.size(); ++i) {
+ std::string arg = args[i];
+ if(arg == "-file") {
+ if(!getStringArg(i, args, filename))
+ throw IllegalArgument("scene macbeth -file", i , args);
+ } else {
+ std::cerr << "Unknown option: " << arg << "\n";
+ }
+ }
+
+ if (filename == "") {
+ throw InputError("Filename required for macbeth scene");
+ }
+
+ Vector up( 0.0f, 1.0f, 0.0f );
+ Vector right( 1.0f, 0.0f, 0.0f );
+
+ // Start adding geometry
+ Group* group = new Group();
+ Scene* scene = new Scene();
+
+ scene->setBackground( new ConstantBackground( Color(RGB(.5, .5, . 5) ) ) );
+
+ ImageTexture<Color>* texture = LoadColorImageTexture(filename, &std::cerr, true);
+ Material* image = new CopyTextureMaterial(texture);
+ Primitive* board = new Parallelogram(image, Vector(0, 0, 0), Vector(6, 0, 0), Vector(0, 4, 0));
+ board->setTexCoordMapper( new LinearMapper( Vector(0, 0, 0), Vector(6,0,0), Vector(0, 4, 0), Vector(0,0,1)) );
+
+ group->add(board);
+ scene->setObject(group);
+
+ LightSet* lights = new LightSet();
+ addLights( lights );
+
+ lights->setAmbientLight(new ConstantAmbient( Color::black()));
+ scene->setLights(lights);
+
+ // Add a default camera
+ Vector eye(3,2,-10);
+ Vector lookat(3,2,0);
+ Real fov=45;
+ scene->addBookmark("default view", eye, lookat, up, fov, fov);
+
+ return scene;
+}
+
Archive powered by MHonArc 2.6.16.