degate  0.1.2
ImageReaderBase.h
Go to the documentation of this file.
00001 /* -*-c++-*-
00002 
00003  This file is part of the IC reverse engineering tool degate.
00004 
00005  Copyright 2008, 2009, 2010 by Martin Schobert
00006 
00007  Degate is free software: you can redistribute it and/or modify
00008  it under the terms of the GNU General Public License as published by
00009  the Free Software Foundation, either version 3 of the License, or
00010  any later version.
00011 
00012  Degate is distributed in the hope that it will be useful,
00013  but WITHOUT ANY WARRANTY; without even the implied warranty of
00014  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015  GNU General Public License for more details.
00016 
00017  You should have received a copy of the GNU General Public License
00018  along with degate. If not, see <http://www.gnu.org/licenses/>.
00019 
00020 */
00021 
00022 #ifndef __IMAGEREADERBASE_H__
00023 #define __IMAGEREADERBASE_H__
00024 
00025 #include <list>
00026 #include <memory>
00027 #include <degate_exceptions.h>
00028 
00029 #include <TypeTraits.h>
00030 #include <StoragePolicies.h>
00031 #include <PixelPolicies.h>
00032 #include <FileSystem.h>
00033 
00034 namespace degate {
00035 
00036   /**
00037    * The base class for image readers.
00038    */
00039 
00040   template<class ImageType>
00041   class ImageReaderBase {
00042   private:
00043 
00044     std::string filename;
00045     unsigned int width, height;
00046 
00047   protected:
00048 
00049     /**
00050      * Set the width of the image.
00051      * This method should be called by derived image readers to set
00052      * the image size.
00053      */
00054     void set_width(unsigned int _width) { width = _width; }
00055 
00056 
00057     /**
00058      * Set the height of the image.
00059      * This method should be called by derived image readers to set
00060      * the image size.
00061      */
00062     void set_height(unsigned int _height) { height = _height; }
00063 
00064 
00065   public:
00066 
00067     /**
00068      * Constructor.
00069      */
00070 
00071     ImageReaderBase(std::string const & _filename) :
00072       filename(_filename),
00073       width(0),
00074       height(0) {}
00075 
00076     /**
00077      * The destructor.
00078      */
00079 
00080     virtual ~ImageReaderBase() {}
00081 
00082     /**
00083      * Get the filename.
00084      */
00085 
00086     std::string get_filename() const { return filename; }
00087 
00088     /**
00089      * Read the image ot at least its meta data.
00090      *
00091      * If you derive from class ImageReaderBase, you can implement a full image read
00092      * operation here. But it is also possible to implement just the read of meta data,
00093      * such as width and height.
00094      *
00095      * @return The function returns true, if the image file was read. Else false
00096      *      is returned. If read() was successful you can
00097      */
00098 
00099     virtual bool read() = 0;
00100 
00101     /**
00102      * Get the image width.
00103      * You have to call read() before.
00104      * @see read()
00105      */
00106 
00107     unsigned int get_width() const { return width; }
00108 
00109     /**
00110      * Get the image height.
00111      * You have to call read() before.
00112      * @see read()
00113      */
00114 
00115     unsigned int get_height() const { return height; }
00116 
00117     /**
00118      * Read the file content into image.
00119      */
00120 
00121     virtual bool get_image(std::shared_ptr<ImageType> img) = 0;
00122 
00123   };
00124 
00125 
00126 
00127 }
00128 
00129 #endif