ImageFile.cpp

Go to the documentation of this file.
00001 /* Import from Gabor API
00002 
00003 Copyright (c) 2002-3 Adriaan Tijsseling
00004 
00005 
00006                              All Rights Reserved
00007 
00008     This program is free software; you can redistribute it and/or modify
00009     it under the terms of the GNU General Public License as published by
00010     the Free Software Foundation; either version 2 of the License, or
00011     (at your option) any later version.
00012 
00013     This program is distributed in the hope that it will be useful,
00014     but WITHOUT ANY WARRANTY; without even the implied warranty of
00015     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00016     GNU General Public License for more details.
00017 
00018     You should have received a copy of the GNU General Public License
00019     along with this program. If not, see <http://www.gnu.org/licenses/>.
00020 */
00021 
00022 /*
00023         Description:            Abstract class for reading and storing images
00024         Original Author:        Mickael Pic
00025         Modifications by:       Adriaan Tijsseling (AGT)
00026 */
00027 
00028 
00029 #include "ImageFile.h"
00030 
00031 namespace celeste
00032 {
00033 ImageFile::ImageFile()
00034 {
00035     mPixels = NULL;
00036     mFloats = NULL;
00037     mRGB = NULL;
00038     mWidth = 0;
00039     mHeight = 0;
00040     mVerbosity = true;
00041 }
00042 
00043 ImageFile::~ImageFile()
00044 {
00045     Deallocate();
00046 }
00047 
00048 
00049 // allocate pixel storage
00050 void ImageFile::Allocate( int dataset )
00051 {
00052         int i, j;
00053 
00054         if ( dataset & kChars )
00055         {       
00056                 mPixels = new unsigned char*[mHeight];
00057                 for ( i = 0; i < mHeight; i++ )
00058                 {
00059                         mPixels[i] = new unsigned char[mWidth];
00060                         for ( j = 0; j < mWidth; j++ )
00061                                 mPixels[i][j] = 0;
00062                 }
00063         }
00064         if ( dataset & kFloats )
00065         {
00066                 mFloats = new float*[mHeight];
00067                 for ( i = 0; i < mHeight; i++ )
00068                 {
00069                         mFloats[i] = new float[mWidth];
00070                         for ( j = 0; j < mWidth; j++ )
00071                                 mFloats[i][j] = 0.0;
00072                 }
00073         }
00074         if ( dataset & kRGB )
00075         {
00076                 mRGB = new int**[3];
00077                 for ( i = 0; i < 3; i++ )
00078                 {
00079                         mRGB[i] = new int*[mHeight];
00080                         for ( j = 0; j < mHeight; j++ )
00081                         {
00082                                 mRGB[i][j] = new int[mWidth];
00083                                 for ( int k = 0; k < mWidth; k++ )
00084                                         mRGB[i][j][k] = 255;
00085                         }                       
00086                 }       
00087         }
00088 }
00089 
00090 
00091 // allocate pixel storage
00092 void ImageFile::Deallocate()
00093 {
00094         int i;
00095         
00096         if ( mPixels != NULL )
00097         {
00098         for ( i = 0; i < mHeight; i++ )
00099                 delete[] mPixels[i];
00100                  delete[] mPixels; 
00101         }
00102         if ( mFloats != NULL )
00103         {
00104         for ( i = 0; i < mHeight; i++ )
00105                 delete[] mFloats[i];
00106                  delete[] mFloats; 
00107         }
00108         if ( mRGB == NULL ) return;
00109         for ( i = 0; i < 3; i++ )
00110         {
00111                 for ( int j = 0; j < mHeight; j++ )
00112                         delete[] mRGB[i][j];
00113                 delete[] mRGB[i];
00114         }       
00115         delete[] mRGB;
00116 }
00117 
00118 
00119 // get one single pixel
00120 unsigned char ImageFile::GetPixel( int x, int y )
00121 {
00122         if ( mPixels != NULL )
00123                 return mPixels[x][y];
00124         else 
00125                 return 0;
00126 }
00127 
00128 
00129 // Set the image from a table of float
00130 void ImageFile::SetPixels( float** pixels )
00131 {
00132         for ( int i = 0; i < mHeight; i++ )
00133                 for ( int j = 0; j < mWidth; j++ )
00134                         mPixels[i][j] = (unsigned char)pixels[i][j];
00135 }
00136 
00137 
00138 // return float cast of pixel storage
00139 float** ImageFile::GetPixels( void )
00140 {
00141         // allocate pixel storage
00142         Allocate( kFloats );
00143 
00144         for ( int i = 0; i < mHeight; i++ )
00145                 for ( int j = 0; j < mWidth; j++ )
00146                         mFloats[i][j] = (float)mPixels[i][j];
00147 
00148         return mFloats;
00149 }
00150 }; // namespace

Generated on Thu Oct 2 01:25:31 2014 for Hugintrunk by  doxygen 1.3.9.1