FloatImage.cpp
Go to the documentation of this file.
1 // ****************************************************************************
2 // This file is part of the Integrating Vision Toolkit (IVT).
3 //
4 // The IVT is maintained by the Karlsruhe Institute of Technology (KIT)
5 // (www.kit.edu) in cooperation with the company Keyetech (www.keyetech.de).
6 //
7 // Copyright (C) 2014 Karlsruhe Institute of Technology (KIT).
8 // All rights reserved.
9 //
10 // Redistribution and use in source and binary forms, with or without
11 // modification, are permitted provided that the following conditions are met:
12 //
13 // 1. Redistributions of source code must retain the above copyright
14 // notice, this list of conditions and the following disclaimer.
15 //
16 // 2. Redistributions in binary form must reproduce the above copyright
17 // notice, this list of conditions and the following disclaimer in the
18 // documentation and/or other materials provided with the distribution.
19 //
20 // 3. Neither the name of the KIT nor the names of its contributors may be
21 // used to endorse or promote products derived from this software
22 // without specific prior written permission.
23 //
24 // THIS SOFTWARE IS PROVIDED BY THE KIT AND CONTRIBUTORS “AS IS” AND ANY
25 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
26 // WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
27 // DISCLAIMED. IN NO EVENT SHALL THE KIT OR CONTRIBUTORS BE LIABLE FOR ANY
28 // DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
29 // (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
30 // LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
31 // ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
32 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
33 // THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34 // ****************************************************************************
35 // ****************************************************************************
36 // Filename: FloatImage.cpp
37 // Author: Jan Issac
38 // Date: 2011
39 // ****************************************************************************
40 
41 
42 // ****************************************************************************
43 // Includes
44 // ****************************************************************************
45 
46 #include <new> // for explicitly using correct new/delete operators on VC DSPs
47 
48 #include "FloatImage.h"
49 #include "ByteImage.h"
50 #include "Image/ImageProcessor.h"
51 
52 #include "Helpers/helpers.h"
53 
54 #include <string.h>
55 #include <stdio.h>
56 #include <stdlib.h>
57 #include <ctype.h>
58 
59 
60 
61 
62 // ****************************************************************************
63 // Defines
64 // ****************************************************************************
65 
66 // ****************************************************************************
67 // Constructors / Destructor
68 // ****************************************************************************
69 
71 {
72  width = 0;
73  height = 0;
74  bytesPerPixel = 0;
75  pixels = 0;
76  numberOfChannels = 1;
77  m_bOwnMemory = false;
78 }
79 
80 CFloatImage::CFloatImage(int nImageWidth, int nImageHeight, int nNumberOfChannels, bool bHeaderOnly)
81 {
82  bytesPerPixel = nNumberOfChannels * sizeof(float);
83 
84  width = nImageWidth;
85  height = nImageHeight;
86  numberOfChannels = nNumberOfChannels;
87 
88  if (bHeaderOnly)
89  {
90  pixels = 0;
91  m_bOwnMemory = false;
92  }
93  else
94  {
95  pixels = new float[width * height * numberOfChannels];
96  m_bOwnMemory = true;
97  }
98 }
99 
100 CFloatImage::CFloatImage(const CFloatImage &image, bool bHeaderOnly)
101 {
102  width = image.width;
103  height = image.height;
106 
107  if (bHeaderOnly)
108  {
109  pixels = 0;
110  m_bOwnMemory = false;
111  }
112  else
113  {
114  pixels = new float[width * height * numberOfChannels];
115  m_bOwnMemory = true;
116  }
117 }
118 
119 CFloatImage::CFloatImage(const CFloatImage *pImage, bool bHeaderOnly)
120 {
121  width = pImage->width;
122  height = pImage->height;
123  bytesPerPixel = pImage->bytesPerPixel;
125 
126  if (bHeaderOnly)
127  {
128  pixels = 0;
129  m_bOwnMemory = false;
130  }
131  else
132  {
133  pixels = new float[width * height * numberOfChannels];
134  m_bOwnMemory = true;
135  }
136 }
137 
139 {
140  FreeMemory();
141 }
142 
143 
144 // ****************************************************************************
145 // Methods
146 // ****************************************************************************
147 
149 {
150  if (pixels)
151  {
152  if (m_bOwnMemory)
153  delete [] pixels;
154 
155  pixels = 0;
156  m_bOwnMemory = false;
157  }
158 }
159 
160 bool CFloatImage::IsCompatible(const CFloatImage *pImage) const
161 {
162  return width == pImage->width && height == pImage->height && numberOfChannels == pImage->numberOfChannels;
163 }
164 
165 
166 bool CFloatImage::LoadFromFile(const char *pFileName)
167 {
168  // first free memory, in any case
169  FreeMemory();
170 
171  CByteImage im;
172  if (im.LoadFromFile(pFileName))
173  {
174  switch(im.type)
175  {
177  numberOfChannels = 1;
178  break;
179  case CByteImage::eRGB24:
180  numberOfChannels = 3;
181  break;
183  printf("error: CByteImage::eRGB24Split to 3-Channel CFloatImage not supported.");
184  return false;
185  }
186 
187  width = im.width;
188  height = im.height;
189  pixels = new float[width * height * numberOfChannels];
190  m_bOwnMemory = true;
191 
192  ImageProcessor::ConvertImage(&im, this);
193  return true;
194  }
195 
196  return false;
197 }
198 
199 
200 bool CFloatImage::SaveToFile(const char *pFileName) const
201 {
202  CByteImage::ImageType imType;
203 
204  switch(numberOfChannels)
205  {
206  case 1:
207  imType = CByteImage::eGrayScale;
208  break;
209  case 3:
210  imType = CByteImage::eRGB24;
211  break;
212  }
213 
214  CByteImage im(width, height, imType);
215 
216  ImageProcessor::ConvertImage(this, &im);
217 
218  return im.SaveToFile(pFileName);
219 }
void FreeMemory()
Definition: FloatImage.cpp:148
bool SaveToFile(const char *pFileName) const
Saves an image to a file.
Definition: FloatImage.cpp:200
float * pixels
The pointer to the the pixels.
Definition: FloatImage.h:203
bool IsCompatible(const CFloatImage *pImage) const
Checks whether two images are compatible or not.
Definition: FloatImage.cpp:160
int width
The width of the image in pixels.
Definition: ByteImage.h:257
GLenum GLsizei GLenum GLenum const GLvoid * image
Definition: glext.h:3131
bool LoadFromFile(const char *pFileName)
Loads an image from a file.
Definition: ByteImage.cpp:232
bool LoadFromFile(const char *pFileName)
Loads an image from a file.
Definition: FloatImage.cpp:166
Data structure for the representation of 8-bit grayscale images and 24-bit RGB (or HSV) color images ...
Definition: ByteImage.h:80
int numberOfChannels
Number of channels per pixel.
Definition: FloatImage.h:212
~CFloatImage()
The destructor.
Definition: FloatImage.cpp:138
bool ConvertImage(const CByteImage *pInputImage, CByteImage *pOutputImage, bool bFast=false, const MyRegion *pROI=0)
Converts a grayscale CByteImage to an RGB CByteImage image and vice versa.
int width
The width of the image in pixels.
Definition: FloatImage.h:177
int height
The height of the image in pixels.
Definition: FloatImage.h:184
GLint GLint GLsizei GLsizei GLsizei GLint GLenum GLenum const GLvoid * pixels
Definition: glext.h:3154
int height
The height of the image in pixels.
Definition: ByteImage.h:264
GLenum GLsizei width
Definition: glext.h:3122
GLenum GLsizei GLsizei height
Definition: glext.h:3132
ImageType
Enum specifying the supported image types.
Definition: ByteImage.h:86
bool SaveToFile(const char *pFileName) const
Saves an image to a file.
Definition: ByteImage.cpp:243
ImageType type
The type of the image.
Definition: ByteImage.h:292
int bytesPerPixel
The number of bytes used for encoding one pixel.
Definition: FloatImage.h:193
bool m_bOwnMemory
Flag signaling if memory is to be freed or not.
Definition: FloatImage.h:221
CFloatImage()
The default constructor.
Definition: FloatImage.cpp:70
Data structure for the representation of any image type (arbitrary number of channels) using the data...
Definition: FloatImage.h:62


asr_ivt
Author(s): Allgeyer Tobias, Hutmacher Robin, Kleinert Daniel, Meißner Pascal, Scholz Jonas, Stöckle Patrick
autogenerated on Mon Dec 2 2019 03:47:27