src/vamos/geometry/Texture_Image.cc

Go to the documentation of this file.
00001 //      Vamos Automotive Simulator
00002 //  Copyright (C) 2001--2003 Sam Varner
00003 //
00004 //  This program is free software; you can redistribute it and/or modify
00005 //  it under the terms of the GNU General Public License as published by
00006 //  the Free Software Foundation; either version 2 of the License, or
00007 //  (at your option) any later version.
00008 //
00009 //  This program is distributed in the hope that it will be useful,
00010 //  but WITHOUT ANY WARRANTY; without even the implied warranty of
00011 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012 //  GNU General Public License for more details.
00013 //
00014 //  You should have received a copy of the GNU General Public License
00015 //  along with this program; if not, write to the Free Software
00016 //  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00017 
00018 #include <vamos/geometry/Texture_Image.h>
00019 
00020 //#include <stdio.h> // libpng uses FILE.
00021 //#include <png.h>
00022 
00023 Vamos_Geometry::Texture_Image::
00024 Texture_Image (std::string file_name, double width, double height) : 
00025   m_width (width),
00026   m_height (height)
00027 {
00028   // See if the file is a PNG file.
00029 /*  FILE *fp = fopen (file_name.c_str (), "rb");
00030   if (!fp)
00031     {
00032           throw Missing_Texture_File (file_name);
00033     }
00034 
00035   png_byte header [8];
00036   fread (header, 1, 8, fp);
00037   bool is_png = !png_sig_cmp (header, 0, 8);
00038   if (!is_png)
00039     {
00040           throw Missing_Texture_File (file_name);
00041     }
00042   
00043   // Initialize the structures.
00044   png_structp png_ptr = 
00045         png_create_read_struct (PNG_LIBPNG_VER_STRING, 0, 0, 0);
00046   if (png_ptr == 0)
00047         {
00048           throw Missing_Texture_File (file_name);
00049         }
00050 
00051   png_infop info_ptr = png_create_info_struct (png_ptr);
00052   if (info_ptr == 0)
00053         {
00054           png_destroy_read_struct (&png_ptr, 0, 0);
00055           throw Missing_Texture_File (file_name);
00056         }
00057 
00058   png_infop end_info = png_create_info_struct (png_ptr);
00059   if (end_info == 0)
00060         {
00061           png_destroy_read_struct(&png_ptr, &info_ptr, 0);
00062           throw Missing_Texture_File (file_name);
00063         }
00064   
00065   png_init_io (png_ptr, fp);
00066   png_set_sig_bytes (png_ptr, 8);
00067   png_read_png (png_ptr, info_ptr, PNG_TRANSFORM_IDENTITY, 0);
00068 
00069   fclose (fp);
00070 
00071   png_bytep* row_pointers = png_get_rows (png_ptr, info_ptr);
00072 
00073   m_width_pixels = info_ptr->width;
00074   m_height_pixels = info_ptr->height;
00075   m_channels = info_ptr->channels;
00076   size_t row_size = info_ptr->width * info_ptr->channels;
00077 
00078   m_data_size = row_size * m_height_pixels;
00079   m_data = new unsigned char [m_data_size];
00080 
00081   for (size_t i = 0; i < info_ptr->height; i++)
00082         {
00083           for (size_t j = 0; j < row_size; j++)
00084                 {
00085                   m_data [i * row_size + j] = row_pointers [i][j];
00086                 }
00087         }
00088 
00089   png_destroy_read_struct (&png_ptr, &info_ptr, &end_info);*/
00090   
00091   m_width_pixels = 256;
00092   m_height_pixels = 256;
00093   m_data_size = 0;
00094 //  m_data = NULL;
00095   m_channels = 3;
00096 }
00097 
00098 Vamos_Geometry::Texture_Image::
00099 Texture_Image (const Texture_Image& image)
00100 {
00101   m_height_pixels = image.m_height_pixels;
00102   m_width_pixels = image.m_width_pixels;
00103   m_channels = image.m_channels;
00104   m_data_size = image.m_data_size;
00105 
00106 }
00107 
00108 const Vamos_Geometry::Texture_Image& Vamos_Geometry::Texture_Image::
00109 operator = (const Texture_Image& image)
00110 {
00111   if (&image != this)
00112         {
00113           m_height_pixels = image.m_height_pixels;
00114           m_width_pixels = image.m_width_pixels;
00115           m_channels = image.m_channels;
00116           m_data_size = image.m_data_size;
00117         }
00118   return *this;
00119 }

Generated on Thu Oct 19 04:05:55 2006 by  doxygen 1.4.6