Hugintrunk  0.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
ImageFile.cpp
Go to the documentation of this file.
1 /* Import from Gabor API
2 
3 Copyright (c) 2002-3 Adriaan Tijsseling
4 
5 
6  All Rights Reserved
7 
8  This program is free software; you can redistribute it and/or modify
9  it under the terms of the GNU General Public License as published by
10  the Free Software Foundation; either version 2 of the License, or
11  (at your option) any later version.
12 
13  This program is distributed in the hope that it will be useful,
14  but WITHOUT ANY WARRANTY; without even the implied warranty of
15  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  GNU General Public License for more details.
17 
18  You should have received a copy of the GNU General Public License
19  along with this program. If not, see <http://www.gnu.org/licenses/>.
20 */
21 
22 /*
23  Description: Abstract class for reading and storing images
24  Original Author: Mickael Pic
25  Modifications by: Adriaan Tijsseling (AGT)
26 */
27 
28 
29 #include "ImageFile.h"
30 
31 namespace celeste
32 {
34 {
35  mPixels = NULL;
36  mFloats = NULL;
37  mRGB = NULL;
38  mWidth = 0;
39  mHeight = 0;
40  mVerbosity = true;
41 }
42 
44 {
45  Deallocate();
46 }
47 
48 
49 // allocate pixel storage
50 void ImageFile::Allocate( int dataset )
51 {
52  int i, j;
53 
54  if ( dataset & kChars )
55  {
56  mPixels = new unsigned char*[mHeight];
57  for ( i = 0; i < mHeight; i++ )
58  {
59  mPixels[i] = new unsigned char[mWidth];
60  for ( j = 0; j < mWidth; j++ )
61  mPixels[i][j] = 0;
62  }
63  }
64  if ( dataset & kFloats )
65  {
66  mFloats = new float*[mHeight];
67  for ( i = 0; i < mHeight; i++ )
68  {
69  mFloats[i] = new float[mWidth];
70  for ( j = 0; j < mWidth; j++ )
71  mFloats[i][j] = 0.0;
72  }
73  }
74  if ( dataset & kRGB )
75  {
76  mRGB = new int**[3];
77  for ( i = 0; i < 3; i++ )
78  {
79  mRGB[i] = new int*[mHeight];
80  for ( j = 0; j < mHeight; j++ )
81  {
82  mRGB[i][j] = new int[mWidth];
83  for ( int k = 0; k < mWidth; k++ )
84  mRGB[i][j][k] = 255;
85  }
86  }
87  }
88 }
89 
90 
91 // allocate pixel storage
93 {
94  int i;
95 
96  if ( mPixels != NULL )
97  {
98  for ( i = 0; i < mHeight; i++ )
99  delete[] mPixels[i];
100  delete[] mPixels;
101  }
102  if ( mFloats != NULL )
103  {
104  for ( i = 0; i < mHeight; i++ )
105  delete[] mFloats[i];
106  delete[] mFloats;
107  }
108  if ( mRGB == NULL ) return;
109  for ( i = 0; i < 3; i++ )
110  {
111  for ( int j = 0; j < mHeight; j++ )
112  delete[] mRGB[i][j];
113  delete[] mRGB[i];
114  }
115  delete[] mRGB;
116 }
117 
118 
119 // get one single pixel
120 unsigned char ImageFile::GetPixel( int x, int y )
121 {
122  if ( mPixels != NULL )
123  return mPixels[x][y];
124  else
125  return 0;
126 }
127 
128 
129 // Set the image from a table of float
130 void ImageFile::SetPixels( float** pixels )
131 {
132  for ( int i = 0; i < mHeight; i++ )
133  for ( int j = 0; j < mWidth; j++ )
134  mPixels[i][j] = (unsigned char)pixels[i][j];
135 }
136 
137 
138 // return float cast of pixel storage
139 float** ImageFile::GetPixels( void )
140 {
141  // allocate pixel storage
142  Allocate( kFloats );
143 
144  for ( int i = 0; i < mHeight; i++ )
145  for ( int j = 0; j < mWidth; j++ )
146  mFloats[i][j] = (float)mPixels[i][j];
147 
148  return mFloats;
149 }
150 }; // namespace
unsigned char ** mPixels
Definition: ImageFile.h:82
virtual ~ImageFile()
Definition: ImageFile.cpp:43
float ** GetPixels(void)
Definition: ImageFile.cpp:139
void Allocate(int dataset)
Definition: ImageFile.cpp:50
void SetPixels(float **)
Definition: ImageFile.cpp:130
unsigned char GetPixel(int x, int y)
Definition: ImageFile.cpp:120
float ** mFloats
Definition: ImageFile.h:83