FloatImage.cpp
Go to the documentation of this file.
00001 // ****************************************************************************
00002 // This file is part of the Integrating Vision Toolkit (IVT).
00003 //
00004 // The IVT is maintained by the Karlsruhe Institute of Technology (KIT)
00005 // (www.kit.edu) in cooperation with the company Keyetech (www.keyetech.de).
00006 //
00007 // Copyright (C) 2014 Karlsruhe Institute of Technology (KIT).
00008 // All rights reserved.
00009 //
00010 // Redistribution and use in source and binary forms, with or without
00011 // modification, are permitted provided that the following conditions are met:
00012 //
00013 // 1. Redistributions of source code must retain the above copyright
00014 //    notice, this list of conditions and the following disclaimer.
00015 //
00016 // 2. Redistributions in binary form must reproduce the above copyright
00017 //    notice, this list of conditions and the following disclaimer in the
00018 //    documentation and/or other materials provided with the distribution.
00019 //
00020 // 3. Neither the name of the KIT nor the names of its contributors may be
00021 //    used to endorse or promote products derived from this software
00022 //    without specific prior written permission.
00023 //
00024 // THIS SOFTWARE IS PROVIDED BY THE KIT AND CONTRIBUTORS “AS IS” AND ANY
00025 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
00026 // WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
00027 // DISCLAIMED. IN NO EVENT SHALL THE KIT OR CONTRIBUTORS BE LIABLE FOR ANY
00028 // DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
00029 // (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
00030 // LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
00031 // ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
00032 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
00033 // THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00034 // ****************************************************************************
00035 // ****************************************************************************
00036 // Filename:  FloatImage.cpp
00037 // Author:    Jan Issac
00038 // Date:      2011
00039 // ****************************************************************************
00040 
00041 
00042 // ****************************************************************************
00043 // Includes
00044 // ****************************************************************************
00045 
00046 #include <new> // for explicitly using correct new/delete operators on VC DSPs
00047 
00048 #include "FloatImage.h"
00049 #include "ByteImage.h"
00050 #include "Image/ImageProcessor.h"
00051 
00052 #include "Helpers/helpers.h"
00053 
00054 #include <string.h>
00055 #include <stdio.h>
00056 #include <stdlib.h>
00057 #include <ctype.h>
00058 
00059 
00060 
00061 
00062 // ****************************************************************************
00063 // Defines
00064 // ****************************************************************************
00065 
00066 // ****************************************************************************
00067 // Constructors / Destructor
00068 // ****************************************************************************
00069 
00070 CFloatImage::CFloatImage()
00071 {
00072         width = 0;
00073         height = 0;
00074         bytesPerPixel = 0;
00075         pixels = 0;
00076         numberOfChannels = 1;
00077         m_bOwnMemory = false;
00078 }
00079 
00080 CFloatImage::CFloatImage(int nImageWidth, int nImageHeight, int nNumberOfChannels, bool bHeaderOnly)
00081 {
00082     bytesPerPixel = nNumberOfChannels * sizeof(float);
00083 
00084         width = nImageWidth;
00085         height = nImageHeight;
00086         numberOfChannels = nNumberOfChannels;
00087 
00088         if (bHeaderOnly)
00089         {
00090                 pixels = 0;
00091                 m_bOwnMemory = false;
00092         }
00093         else
00094         {
00095                 pixels = new float[width * height * numberOfChannels];
00096                 m_bOwnMemory = true;
00097         }
00098 }
00099 
00100 CFloatImage::CFloatImage(const CFloatImage &image, bool bHeaderOnly)
00101 {
00102         width = image.width;
00103         height = image.height;
00104         bytesPerPixel = image.bytesPerPixel;
00105         numberOfChannels = image.numberOfChannels;
00106         
00107         if (bHeaderOnly)
00108         {
00109                 pixels = 0;
00110                 m_bOwnMemory = false;
00111         }
00112         else
00113         {
00114             pixels = new float[width * height * numberOfChannels];
00115                 m_bOwnMemory = true;
00116         }
00117 }
00118 
00119 CFloatImage::CFloatImage(const CFloatImage *pImage, bool bHeaderOnly)
00120 {
00121         width = pImage->width;
00122         height = pImage->height;
00123         bytesPerPixel = pImage->bytesPerPixel;
00124         numberOfChannels = pImage->numberOfChannels;
00125         
00126         if (bHeaderOnly)
00127         {
00128                 pixels = 0;
00129                 m_bOwnMemory = false;
00130         }
00131         else
00132         {
00133             pixels = new float[width * height * numberOfChannels];
00134                 m_bOwnMemory = true;
00135         }
00136 }
00137 
00138 CFloatImage::~CFloatImage()
00139 {
00140     FreeMemory();
00141 }
00142 
00143 
00144 // ****************************************************************************
00145 // Methods
00146 // ****************************************************************************
00147 
00148 void CFloatImage::FreeMemory()
00149 {
00150         if (pixels)
00151         {
00152                 if (m_bOwnMemory)
00153                 delete [] pixels;
00154 
00155                 pixels = 0;
00156                 m_bOwnMemory = false;
00157         }
00158 }
00159 
00160 bool CFloatImage::IsCompatible(const CFloatImage *pImage) const
00161 {
00162         return width == pImage->width && height == pImage->height && numberOfChannels == pImage->numberOfChannels;
00163 }
00164 
00165 
00166 bool CFloatImage::LoadFromFile(const char *pFileName)
00167 {
00168     // first free memory, in any case
00169     FreeMemory();
00170 
00171     CByteImage im;
00172     if (im.LoadFromFile(pFileName))
00173     {
00174         switch(im.type)
00175         {
00176         case CByteImage::eGrayScale:
00177             numberOfChannels = 1;
00178             break;
00179         case CByteImage::eRGB24:
00180             numberOfChannels = 3;
00181             break;
00182         case CByteImage::eRGB24Split:
00183             printf("error: CByteImage::eRGB24Split to 3-Channel CFloatImage not supported.");
00184             return false;
00185         }
00186 
00187         width = im.width;
00188         height = im.height;
00189         pixels = new float[width * height * numberOfChannels];
00190         m_bOwnMemory = true;
00191 
00192         ImageProcessor::ConvertImage(&im, this);
00193         return true;
00194     }
00195 
00196         return false;
00197 }
00198 
00199 
00200 bool CFloatImage::SaveToFile(const char *pFileName) const
00201 {
00202     CByteImage::ImageType imType;
00203 
00204     switch(numberOfChannels)
00205     {
00206     case 1:
00207         imType = CByteImage::eGrayScale;
00208         break;
00209     case 3:
00210         imType = CByteImage::eRGB24;
00211         break;
00212     }
00213 
00214     CByteImage im(width, height, imType);
00215 
00216     ImageProcessor::ConvertImage(this, &im);
00217 
00218     return im.SaveToFile(pFileName);
00219 }


asr_ivt
Author(s): Allgeyer Tobias, Hutmacher Robin, Kleinert Daniel, Meißner Pascal, Scholz Jonas, Stöckle Patrick
autogenerated on Thu Jun 6 2019 21:46:57