Manta Interactive Ray Tracer Development Mailing List

Text archives Help


[MANTA] r1293 - trunk/Image


Chronological Thread 
  • From: bigler@sci.utah.edu
  • To: manta@sci.utah.edu
  • Subject: [MANTA] r1293 - trunk/Image
  • Date: Thu, 22 Feb 2007 17:01:27 -0700 (MST)

Author: bigler
Date: Thu Feb 22 17:01:22 2007
New Revision: 1293

Modified:
   trunk/Image/NRRDFile.cc
   trunk/Image/TGAFile.cc
Log:

NRRDFile.cc

  Fix the copying of data to the Image.  You can't just copy the
  memory buffer, because the memory in Image is padded.

TGAFile.cc

  Removed two lines that weren't being used anymore.


Modified: trunk/Image/NRRDFile.cc
==============================================================================
--- trunk/Image/NRRDFile.cc     (original)
+++ trunk/Image/NRRDFile.cc     Thu Feb 22 17:01:22 2007
@@ -139,59 +139,56 @@
                throw InputError( "nrrd must have three dimensions" );
        }
   
-  Image *image = 0;
-  
        
/////////////////////////////////////////////////////////////////////////////
        // Obtain the data.
        int width  = new_nrrd->axis[1].size;
        int height = new_nrrd->axis[2].size;
   int pixel_dimension = new_nrrd->axis[0].size;
-  int scalar_size = 0;
-
-  char *dest_ptr = 0;
-
+  unsigned char* data = static_cast<unsigned char*>(new_nrrd->data);
+  
   
/////////////////////////////////////////////////////////////////////////////
   // Determine what type of pixels to use.
   if (new_nrrd->type == nrrdTypeUChar) {
-    scalar_size = sizeof( unsigned char );
-
     // RGB Pixels
     if (pixel_dimension == 3) {
-      image = new SimpleImage<RGB8Pixel>( false, width, height );
-      
-      dest_ptr = (char *)(dynamic_cast<SimpleImage<RGB8Pixel> const 
*>(image)->getRawData( 0 ) );
+      SimpleImage<RGB8Pixel>* si = new SimpleImage<RGB8Pixel>( false, width, 
height );
+      for ( int y = 0; y < height; ++y )
+        for ( int x = 0; x < width; ++x ) {
+          RGB8Pixel pixel;
+          pixel.r = static_cast<unsigned char>(data[0]);
+          pixel.g = static_cast<unsigned char>(data[1]);
+          pixel.b = static_cast<unsigned char>(data[2]);
+          si->set(pixel, x, (height-1-y), 0);
+          data+=3;
+        }
+      nrrdNuke(new_nrrd);
+      return si;
     }
     
     // RGBA Pixels
     else if (pixel_dimension == 4) {
-      image = new SimpleImage<RGBA8Pixel>( false, width, height );
-
-      dest_ptr = (char *)(dynamic_cast<SimpleImage<RGBA8Pixel> const 
*>(image)->getRawData( 0 ) );      
+      SimpleImage<RGBA8Pixel>* si = new SimpleImage<RGBA8Pixel>( false, 
width, height );
+      for ( int y = 0; y < height; ++y )
+        for ( int x = 0; x < width; ++x ) {
+          RGBA8Pixel pixel;
+          pixel.r = static_cast<unsigned char>(data[0]);
+          pixel.g = static_cast<unsigned char>(data[1]);
+          pixel.b = static_cast<unsigned char>(data[2]);
+          pixel.a = static_cast<unsigned char>(data[3]);
+          si->set(pixel, x, (height-1-y), 0);
+          data+=4;
+        }
+      nrrdNuke(new_nrrd);
+      return si;
     }
-  }
 
-  // Check to see if an image was created.
-  if (image == 0) {
-    nrrdNuke( new_nrrd );
-    throw InputError( "Could not find pixel type for nrrd data." );
-  }
-  
-  
/////////////////////////////////////////////////////////////////////////////
-  // Copy image data into the simple image.  We need to invert the images.
-  char* nrrd_data = static_cast<char*>(new_nrrd->data);
-  size_t stripe_size = width*pixel_dimension*scalar_size;
-  // Move the pointer to the start of the last stripe
-  nrrd_data += (height-1)*stripe_size;
-  for(int i = 0; i < height; ++i) {
-    memcpy( dest_ptr, nrrd_data, stripe_size);
-    // Move the pointer down a stripe
-    nrrd_data -= stripe_size;
-    dest_ptr  += stripe_size;
+    else {
+      nrrdNuke(new_nrrd);
+      throw InputError("Unknown pixel dimension");
+    }
+  } else {
+    nrrdNuke(new_nrrd);
+    throw InputError("Unknown type for nrrd load.");
   }
-  
-       // Delete the data.
-       nrrdNuke( new_nrrd );
-  
-  return image;
 }
 

Modified: trunk/Image/TGAFile.cc
==============================================================================
--- trunk/Image/TGAFile.cc      (original)
+++ trunk/Image/TGAFile.cc      Thu Feb 22 17:01:22 2007
@@ -275,7 +275,6 @@
     bool flip_image = !!(image_descriptor & 32); // bit 5 says flip in y
     if ( pixel_depth == 24 && ( image_descriptor & 15 ) == 0 ) {
       SimpleImage< RGB8Pixel > *si = new SimpleImage< RGB8Pixel >( false, 
width, height );
-      RGB8Pixel *buffer = const_cast< RGB8Pixel * >( si->getRawPixels( 0 ) );
       for ( int y = 0; y < height; ++y )
         for ( int x = 0; x < width; ++x ) {
           RGB8Pixel pixel;
@@ -287,7 +286,6 @@
       return si;
     } else if ( pixel_depth == 32 && ( image_descriptor & 15 ) == 8 ) {
       SimpleImage< RGBA8Pixel > *si = new SimpleImage< RGBA8Pixel >( false, 
width, height );
-      RGBA8Pixel *buffer = const_cast< RGBA8Pixel * >( si->getRawPixels( 0 ) 
);
       for ( int y = 0; y < height; ++y )
         for ( int x = 0; x < width; ++x ) {
           RGBA8Pixel pixel;




  • [MANTA] r1293 - trunk/Image, bigler, 02/22/2007

Archive powered by MHonArc 2.6.16.

Top of page