degate  0.1.2
IPCopy.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 __IPCOPY_H__
00023 #define __IPCOPY_H__
00024 
00025 #include <string>
00026 #include <ImageProcessorBase.h>
00027 
00028 namespace degate {
00029 
00030   /**
00031    * Processor: Copy an image with auto conversion.
00032    */
00033 
00034   template<typename ImageTypeIn, typename ImageTypeOut>
00035   class IPCopy : public ImageProcessorBase {
00036 
00037   private:
00038 
00039     unsigned int min_x, max_x, min_y, max_y;
00040     bool work_on_region;
00041 
00042   public:
00043 
00044     /**
00045      * The constructor for processing the whole image.
00046      */
00047 
00048     IPCopy() :
00049       ImageProcessorBase("IPCopy",
00050                          "Copy an image with pixel type auto conversion",
00051                          false,
00052                          typeid(typename ImageTypeIn::pixel_type),
00053                          typeid(typename ImageTypeOut::pixel_type)),
00054       work_on_region(false) { }
00055 
00056     /**
00057      * The constructor for working on an image region.
00058      */
00059 
00060     IPCopy(unsigned int _min_x, unsigned int _max_x, unsigned int _min_y, unsigned int _max_y) :
00061       ImageProcessorBase("IPCopy",
00062                          "Copy an image with pixel type auto conversion",
00063                          false,
00064                          typeid(typename ImageTypeIn::pixel_type),
00065                          typeid(typename ImageTypeOut::pixel_type)),
00066       min_x(_min_x),
00067       max_x(_max_x),
00068       min_y(_min_y),
00069       max_y(_max_y),
00070       work_on_region(true) {
00071     }
00072 
00073     /**
00074      * The destructor.
00075      */
00076 
00077     virtual ~IPCopy() {}
00078 
00079 
00080 
00081     virtual ImageBase_shptr run(ImageBase_shptr _in) {
00082 
00083       assert(_in != NULL);
00084 
00085       std::shared_ptr<ImageTypeIn> img_in =
00086         std::dynamic_pointer_cast<ImageTypeIn>(_in);
00087 
00088       std::shared_ptr<ImageTypeOut> img_out
00089         (work_on_region ?
00090          new ImageTypeOut(max_x - min_x, max_y - min_y) :
00091          new ImageTypeOut(_in->get_width(), _in->get_height()));
00092 
00093       assert(img_in != NULL);
00094       assert(img_out != NULL);
00095 
00096       std::cout << "Copy image." << std::endl;
00097 
00098       if(work_on_region == true) {
00099         extract_partial_image<ImageTypeOut,
00100           ImageTypeIn>(img_out, img_in,
00101                        min_x, max_x,
00102                        min_y, max_y);
00103       }
00104       else {
00105         copy_image<ImageTypeOut, ImageTypeIn>(img_out, img_in);
00106       }
00107 
00108       return img_out;
00109     }
00110 
00111 
00112   };
00113 
00114 }
00115 
00116 #endif
00117