Canola  0.8.D001
lib/image.h
Go to the documentation of this file.
00001 //
00002 // canola - canon canola 1614p emulator
00003 // Copyright (C) 2011 Peter Miller
00004 //
00005 // This program is free software; you can redistribute it and/or modify
00006 // it under the terms of the GNU General Public License, version 3, as
00007 // published by the Free Software Foundation.
00008 //
00009 // This program is distributed in the hope that it will be useful,
00010 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00011 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00012 // General Public License for more details.
00013 //
00014 // You should have received a copy of the GNU General Public License along
00015 // with this program. If not, see <http://www.gnu.org/licenses/>.
00016 //
00017 
00018 #ifndef LIB_IMAGE_H
00019 #define LIB_IMAGE_H
00020 
00021 #include <lib/config.h>
00022 #include <boost/shared_ptr.hpp>
00023 #include <string>
00024 
00025 #include <lib/icon_pixel.h>
00026 
00030 class image
00031 {
00032 public:
00036     typedef boost::shared_ptr<image> pointer;
00037 
00041     virtual ~image();
00042 
00050     static pointer create_from_file(const std::string &filename);
00051 
00061     static bool known_file_extension(const std::string &ext);
00062 
00076     static pointer create_blank_from_file(const std::string &filename,
00077         int width, int height);
00078 
00083     virtual const char *type_name(void) const = 0;
00084 
00097     void copy(const image::pointer &src);
00098 
00115     void copy(const image::pointer &src, int ox, int oy);
00116 
00134     void overlay(const image::pointer &src, int ox, int oy);
00135 
00147     virtual void get_pixel(int x, int y, icon_pixel &value) const = 0;
00148 
00160     icon_pixel
00161     get_pixel(int x, int y)
00162         const
00163     {
00164         icon_pixel result;
00165         get_pixel(x, y, result);
00166         return result;
00167     }
00168 
00182     virtual void set_pixel(int x, int y, const icon_pixel &value) = 0;
00183 
00195     void set_pixel(int x, int y);
00196 
00209     virtual void overlay_pixel(int x, int y, const icon_pixel &value);
00210 
00221     virtual void overlay_pixel(int x, int y);
00222 
00227     virtual unsigned get_width(void) const = 0;
00228 
00233     virtual unsigned get_height(void) const = 0;
00234 
00242     virtual void save_to_file(const std::string &filename) const = 0;
00243 
00244     void
00245     get_pen_position(int &x, int &y)
00246     {
00247         x = pen_x;
00248         y = pen_y;
00249     }
00250 
00251     void
00252     set_pen_position(int x, int y)
00253     {
00254         pen_x = x;
00255         pen_y = y;
00256     }
00257 
00258     void
00259     set_pen_color(const icon_pixel &clr)
00260     {
00261         pen_clr = clr;
00262     }
00263 
00277     void draw_rectangle(int x, int y, int w, int h);
00278 
00294     void draw_rectangle(int x, int y, int w, int h, const icon_pixel &clr);
00295 
00301     bool same(const image::pointer &rhs) const;
00302 
00307     icon_pixel average(void) const;
00308 
00309 protected:
00313     image();
00314 
00315 private:
00316     int pen_x;
00317     int pen_y;
00318     icon_pixel pen_clr;
00319 
00323     image(const image &);
00324 
00328     image &operator=(const image &);
00329 };
00330 
00331 #endif // LIB_IMAGE_H