Manta Interactive Ray Tracer Development Mailing List

Text archives Help


[Manta] r1835 - trunk/Image


Chronological Thread 
  • From: kmorley@sci.utah.edu
  • To: manta@sci.utah.edu
  • Subject: [Manta] r1835 - trunk/Image
  • Date: Wed, 7 Nov 2007 21:33:26 -0700 (MST)

Author: kmorley
Date: Wed Nov  7 21:33:25 2007
New Revision: 1835

Modified:
   trunk/Image/EXRFile.cc
   trunk/Image/RGBEFile.cc
Log:
Added RGBE writer

Modified: trunk/Image/EXRFile.cc
==============================================================================
--- trunk/Image/EXRFile.cc      (original)
+++ trunk/Image/EXRFile.cc      Wed Nov  7 21:33:25 2007
@@ -206,7 +206,8 @@
 #endif
   
   EXR::InputFile input_file( filename );
-  return input_file.getImage();
+  Image* image = input_file.getImage();
+  return image;
 }
 
 

Modified: trunk/Image/RGBEFile.cc
==============================================================================
--- trunk/Image/RGBEFile.cc     (original)
+++ trunk/Image/RGBEFile.cc     Wed Nov  7 21:33:25 2007
@@ -1,3 +1,4 @@
+
 #include <Image/RGBEFile.h>
 #include <Core/Util/rgbe.h>
 
@@ -34,8 +35,8 @@
     float* image = new float[3*w*h];
     if (!image) {
       fclose(file);
-      throw InternalError("RGBEFile::readRGBE failed to allocate temporary 
raster for file: " + filename,
-                          __FILE__, __LINE__);
+      throw InternalError("RGBEFile::readRGBE failed to allocate temporary \
+          raster for file: " + filename, __FILE__, __LINE__);
     }
 
     error = RGBE_ReadPixels_RLE(file, image, w, h);
@@ -48,11 +49,12 @@
 
     fclose(file);
 
-    SimpleImage< RGBfloatPixel > *result = new SimpleImage< RGBfloatPixel >( 
false, width, height );
+    SimpleImage< RGBfloatPixel > *result = 
+      new SimpleImage< RGBfloatPixel >( false, width, height );
     if (!result) {
       delete[] image;
-      throw InternalError("RGBEFile::readRGBE failed to allocate Image" + 
filename,
-                          __FILE__, __LINE__);
+      throw InternalError("RGBEFile::readRGBE failed to allocate Image" + 
+          filename, __FILE__, __LINE__);
     }
 
     for (unsigned int y = 0; y < h; y++ ) {
@@ -70,6 +72,63 @@
 }
 
 void Manta::writeRGBE(Image const *image, std::string const &filename,
-                      int which) {
-  throw OutputError( "RGBE writing not yet supported.");
+                      int which) 
+{
+    FILE* out = fopen( filename.c_str(), "wb" );
+    if ( !out )
+      throw OutputError( " RBGEIO::writeImage(" + filename + 
+          ") failed to open file." );
+
+    // Determine the resolution.
+    bool stereo;
+    int w, h;
+    image->getResolution( stereo, w, h );
+
+    float* raster = new(std::nothrow)float[3*w*h];
+    if (!raster) {
+      fclose(out);
+      throw InternalError("RGBEIO::writeImage failed to allocate raster.",
+          __FILE__, __LINE__ );
+    }
+
+    const SimpleImage<RGBAfloatPixel>* si = 
+      dynamic_cast<const SimpleImage<RGBAfloatPixel> *>(image);
+    if ( !si ) {
+      throw InternalError("RGBEIO::writeImage only Simple RGBAfloatPixel \
+          images supported.", __FILE__, __LINE__ );
+    }
+
+    
+    for (int y = 0; y < h; y++) {
+      for (int x = 0; x < w; x++) {
+        const RGBAfloatPixel p = si->get(x, y, which);
+        int index = ( (h-y-1)*w + x ) * 3;
+
+        raster[index+0] = p.r;
+        raster[index+1] = p.g;
+        raster[index+2] = p.b;
+      }
+    }
+
+    int error_code = RGBE_WriteHeader(out, w, h, NULL);
+    if (error_code != RGBE_RETURN_SUCCESS)
+    {
+      delete[] raster;
+      fclose(out);
+      throw OutputError( " RBGEIO::writeImage(" + filename + 
+          ") failed to write header." );
+    }
+
+    error_code = RGBE_WritePixels(out, raster, w*h);
+    if (error_code != RGBE_RETURN_SUCCESS)
+    {
+      delete[] raster;
+      fclose(out);
+      throw OutputError( " RBGEIO::writeImage(" + filename + 
+          ") failed to write pixels." );
+    }
+
+    delete[] raster;
+    fclose(out);
 }
+




  • [Manta] r1835 - trunk/Image, kmorley, 11/08/2007

Archive powered by MHonArc 2.6.16.

Top of page