Manta Interactive Ray Tracer Development Mailing List

Text archives Help


[MANTA] r383 - in branches/itanium2: Engine/Control Engine/Display Image


Chronological Thread 
  • From: rocky@sci.utah.edu
  • To: manta@sci.utah.edu
  • Subject: [MANTA] r383 - in branches/itanium2: Engine/Control Engine/Display Image
  • Date: Wed, 15 Jun 2005 18:50:10 -0600 (MDT)

Author: rocky
Date: Wed Jun 15 18:50:08 2005
New Revision: 383

Added:
   branches/itanium2/Image/TGAFile.cc
   branches/itanium2/Image/TGAFile.h
Modified:
   branches/itanium2/Engine/Control/RTRT_register.cc
   branches/itanium2/Engine/Display/CMakeLists.txt
   branches/itanium2/Image/CMakeLists.txt
Log:
copied over FileDisplay stuff from main trunk

Modified: branches/itanium2/Engine/Control/RTRT_register.cc
==============================================================================
--- branches/itanium2/Engine/Control/RTRT_register.cc   (original)
+++ branches/itanium2/Engine/Control/RTRT_register.cc   Wed Jun 15 18:50:08 
2005
@@ -1,6 +1,7 @@
 #include <Interface/RTRTInterface.h>
 #include <Engine/Display/NullDisplay.h>
 #include <Engine/Display/OpenGLDisplay.h>
+#include <Engine/Display/FileDisplay.h>
 #include <Engine/IdleModes/ZoomIdleMode.h>
 #include <Engine/ImageTraversers/NullImageTraverser.h>
 #include <Engine/ImageTraversers/TiledImageTraverser.h>
@@ -42,6 +43,7 @@
     // Register display components
     rtrt->registerComponent("null", &NullDisplay::create);
     rtrt->registerComponent("opengl", &OpenGLDisplay::create);
+    rtrt->registerComponent("file", &FileDisplay::create);
 
     // Register image traversers
     rtrt->registerComponent("null", &NullImageTraverser::create);

Modified: branches/itanium2/Engine/Display/CMakeLists.txt
==============================================================================
--- branches/itanium2/Engine/Display/CMakeLists.txt     (original)
+++ branches/itanium2/Engine/Display/CMakeLists.txt     Wed Jun 15 18:50:08 
2005
@@ -2,5 +2,6 @@
 SET (Manta_Display_SRCS
      Display/NullDisplay.cc
      Display/OpenGLDisplay.cc
+     Display/FileDisplay.cc
      Display/XHelper.cc
      )

Modified: branches/itanium2/Image/CMakeLists.txt
==============================================================================
--- branches/itanium2/Image/CMakeLists.txt      (original)
+++ branches/itanium2/Image/CMakeLists.txt      Wed Jun 15 18:50:08 2005
@@ -1,3 +1,3 @@
 
-ADD_LIBRARY (Manta_Image NullImage.cc)
+ADD_LIBRARY (Manta_Image NullImage.cc TGAFile.cc)
 TARGET_LINK_LIBRARIES(Manta_Image Manta_Interface SCIRun_Core)

Added: branches/itanium2/Image/TGAFile.cc
==============================================================================
--- (empty file)
+++ branches/itanium2/Image/TGAFile.cc  Wed Jun 15 18:50:08 2005
@@ -0,0 +1,204 @@
+
+#include <fstream>
+#include <Core/Exceptions/IllegalArgument.h>
+#include <Core/Exceptions/InternalError.h>
+#include <Core/Util/NotFinished.h>
+#include <Image/NullImage.h>
+#include <Image/Pixel.h>
+#include <Image/SimpleImage.h>
+
+using namespace std;
+using SCIRun::IllegalValue;
+using SCIRun::InternalError;
+
+namespace Manta
+{
+
+  static inline void writeShort(
+    ofstream &out,
+    int const value )
+  {
+    out.put( value & 0xFF );
+    out.put( ( value >> 8 ) & 0xFF );
+  }
+
+  static inline void writeLong(
+    ofstream &out,
+    int const value )
+  {
+    out.put( value & 0xFF );
+    out.put( ( value >> 8 ) & 0xFF );
+    out.put( ( value >> 16 ) & 0xFF );
+    out.put( ( value >> 24 ) & 0xFF );
+  }
+
+  void writeTGA(
+    Image const *image,
+    string const &filename,
+    int const eye )
+  {
+    ofstream out( filename.c_str(), ios::out | ios::binary );
+    if ( !out )
+      throw InternalError( "Couldn't open TGA file for writing: " + filename 
);
+    out.put( 0 );                 // ID length: 0
+    out.put( 0 );                 // Color map type: None
+    out.put( 2 );                 // Image type: uncompressed, true-color 
image
+    writeShort( out, 0 );         // Color map first entry index
+    writeShort( out, 0 );         // Color map length
+    out.put( 0 );                 // Color map entry size
+    writeShort( out, 0 );         // X-origin of image (left)
+    writeShort( out, 0 );         // Y-origin of image (bottom)
+    bool stereo;
+    int xres, yres;
+    image->getResolution( stereo, xres, yres );
+    writeShort( out, xres );      // Image width
+    writeShort( out, yres );      // Image height
+    if ( typeid( *image ) == typeid( SimpleImage< RGBA8Pixel > ) ) {
+      out.put( 32 );              // Pixel depth: 32bpp
+      out.put( 8 );               // Image descriptor: 8 bits of alpha, 
bottom-left origin
+      const SimpleImage< RGBA8Pixel > *si = dynamic_cast< const SimpleImage< 
RGBA8Pixel > * >( image );
+      RGBA8Pixel const *buffer = si->getRaw( eye );
+      for ( int y = 0; y < yres; ++y )
+        for ( int x = 0; x < xres; ++x ) {
+          out.put( buffer->b );
+          out.put( buffer->g );
+          out.put( buffer->r );
+          out.put( buffer->a );
+          ++buffer;
+        }
+    } else if ( typeid( *image ) == typeid( SimpleImage< RGB8Pixel > ) ) {
+      out.put( 24 );              // Pixel depth: 24bpp
+      out.put( 0 );               // Image descriptor: 0 bits of alpha, 
bottom-left origin
+      const SimpleImage< RGB8Pixel > *si = dynamic_cast< const SimpleImage< 
RGB8Pixel > * >( image );
+      RGB8Pixel const *buffer = si->getRaw( eye );
+      for ( int y = 0; y < yres; ++y )
+        for ( int x = 0; x < xres; ++x ) {
+          out.put( buffer->b );
+          out.put( buffer->g );
+          out.put( buffer->r );
+          ++buffer;
+        }
+    } else if ( typeid( *image ) == typeid( SimpleImage< RGBAfloatPixel > ) 
) {
+      out.put( 32 );              // Pixel depth: 32bpp
+      out.put( 8 );               // Image descriptor: 8 bits of alpha, 
bottom-left origin
+      const SimpleImage< RGBAfloatPixel > *si = dynamic_cast< const 
SimpleImage< RGBAfloatPixel > * >( image );
+      RGBAfloatPixel const *buffer = si->getRaw( eye );
+      for ( int y = 0; y < yres; ++y )
+        for ( int x = 0; x < xres; ++x ) {
+          float b = buffer->b;
+          b = b < 0.0f ? 0.0f : b;
+          b = b > 1.0f ? 1.0f : b;
+          out.put( static_cast< unsigned char >( b * 255.0f ) );
+          float g = buffer->g;
+          g = g < 0.0f ? 0.0f : g;
+          g = g > 1.0f ? 1.0f : g;
+          out.put( static_cast< unsigned char >( g * 255.0f ) );
+          float r = buffer->r;
+          r = r < 0.0f ? 0.0f : r;
+          r = r > 1.0f ? 1.0f : r;
+          out.put( static_cast< unsigned char >( r * 255.0f ) );
+          float a = buffer->a;
+          a = a < 0.0f ? 0.0f : a;
+          a = a > 1.0f ? 1.0f : a;
+          out.put( static_cast< unsigned char >( a * 255.0f ) );
+          ++buffer;
+        }
+    } else if ( typeid( *image ) == typeid( SimpleImage< RGBfloatPixel > ) ) 
{
+      out.put( 24 );              // Pixel depth: 24bpp
+      out.put( 0 );               // Image descriptor: 0 bits of alpha, 
bottom-left origin
+      const SimpleImage< RGBfloatPixel > *si = dynamic_cast< const 
SimpleImage< RGBfloatPixel > * >( image );
+      RGBfloatPixel const *buffer = si->getRaw( eye );
+      for ( int y = 0; y < yres; ++y )
+        for ( int x = 0; x < xres; ++x ) {
+          float b = buffer->b;
+          b = b < 0.0f ? 0.0f : b;
+          b = b > 1.0f ? 1.0f : b;
+          out.put( static_cast< unsigned char >( b * 255.0f ) );
+          float g = buffer->g;
+          g = g < 0.0f ? 0.0f : g;
+          g = g > 1.0f ? 1.0f : g;
+          out.put( static_cast< unsigned char >( g * 255.0f ) );
+          float r = buffer->r;
+          r = r < 0.0f ? 0.0f : r;
+          r = r > 1.0f ? 1.0f : r;
+          out.put( static_cast< unsigned char >( r * 255.0f ) );
+          ++buffer;
+        }
+    } else {
+      throw InternalError( "Unknown image type in writeTGA()" );
+    }
+  }
+
+  static inline int readShort(
+    ifstream &in )
+  {
+    int byte_1 = in.get();
+    int byte_2 = in.get();
+    return byte_1 | ( byte_2 << 8 );
+  }
+
+  static inline int readLong(
+    ifstream &in )
+  {
+    int byte_1 = in.get();
+    int byte_2 = in.get();
+    int byte_3 = in.get();
+    int byte_4 = in.get();
+    return byte_1 | ( byte_2 << 8 ) | ( byte_2 << 16 ) | ( byte_2 << 24 );
+  }
+
+  Image *readTGA(
+    string const &filename )
+  {
+    ifstream in( filename.c_str(), ios::in | ios::binary );
+    if ( !in )
+      throw InternalError( "Couldn't open TGA file for reading: " + filename 
);
+    int id_length = in.get();
+    int color_map_type = in.get();
+    if ( color_map_type != 0 )
+      throw InternalError( "Color map TGA files currently unsupported" );
+    int image_type = in.get();
+    if ( image_type != 2 )
+      throw InternalError( "Only uncompressed true-color TGA files currently 
supported" );
+    int color_map_first_entry_index = readShort( in );
+    int color_map_length = readShort( in );
+    int color_map_entry_size = in.get();
+    int x_origin = readShort( in );
+    int y_origin = readShort( in );
+    int width = readShort( in );
+    int height = readShort( in );
+    int pixel_depth = in.get();
+    int image_descriptor = in.get();
+    in.ignore( id_length );
+    if ( pixel_depth == 24 && ( image_descriptor & 15 ) == 0 ) {
+      SimpleImage< RGB8Pixel > *si = new SimpleImage< RGB8Pixel >( false, 
width, height );
+      RGB8Pixel *buffer = const_cast< RGB8Pixel * >( si->getRaw( 0 ) );
+      for ( int y = 0; y < height; ++y )
+        for ( int x = 0; x < width; ++x ) {
+          RGB8Pixel *offset = ( buffer +
+                                ( image_descriptor & 32 ? height - y : y ) * 
width +
+                                ( image_descriptor & 16 ? width - x : x ) );
+          offset->b = in.get();
+          offset->g = in.get();
+          offset->r = in.get();
+        }
+      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->getRaw( 0 ) );
+      for ( int y = 0; y < height; ++y )
+        for ( int x = 0; x < width; ++x ) {
+          RGBA8Pixel *offset = ( buffer +
+                                 ( image_descriptor & 32 ? height - y : y ) 
* width +
+                                 ( image_descriptor & 16 ? width - x : x ) );
+          offset->b = in.get();
+          offset->g = in.get();
+          offset->r = in.get();
+          offset->a = in.get();
+        }
+      return si;
+    }
+    throw InternalError( "Unhandled pixel depth and alpha for TGA files" );
+  }
+
+}

Added: branches/itanium2/Image/TGAFile.h
==============================================================================
--- (empty file)
+++ branches/itanium2/Image/TGAFile.h   Wed Jun 15 18:50:08 2005
@@ -0,0 +1,16 @@
+
+#ifndef Manta_Engine_TGAFile_h
+#define Manta_Engine_TGAFile_h
+
+#include <string>
+
+namespace Manta {
+
+    class Image;
+
+    void writeTGA( Image const *image, std::string const &filename, int 
const eye );
+    Image *readTGA( std::string const &filename );
+
+}
+
+#endif




  • [MANTA] r383 - in branches/itanium2: Engine/Control Engine/Display Image, rocky, 06/15/2005

Archive powered by MHonArc 2.6.16.

Top of page