1 2 /* 3 * picture-object... 4 * Copyright (c) 2002-2006 by Mattias Hultgren <mattias_hultgren@tele2.se> 5 * 6 * 7 * This program is free software; you can redistribute it and/or modify 8 * it under the terms of the GNU General Public License as published by 9 * the Free Software Foundation; version 2 of the License. 10 * 11 * This program is distributed in the hope that it will be useful, 12 * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 * GNU General Public License for more details. 15 * 16 * You should have received a copy of the GNU General Public 17 * License along with this program; if not, write to the Free Software 18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 19 */ 20 21 22 #ifndef PICTURE_H_ 23 #define PICTURE_H_ 24 25 #include "vartypes.h" 26 27 #define PICTURE_H_VERSION "v16" 28 #define PICTURE_H_DATE "2002-12 - 2006-07" 29 30 namespace picture_h 31 { 32 33 enum PictureType { PictureType_RGB, PictureType_GRAYSCALE }; 34 35 36 struct colorrgb 37 { 38 uint8 red,green,blue; 39 40 bool operator==(const colorrgb &color) const; 41 }; 42 43 namespace color 44 { 45 extern const colorrgb RED; 46 extern const colorrgb GREEN; 47 extern const colorrgb BLUE; 48 extern const colorrgb DARK_RED; 49 extern const colorrgb DARK_GREEN; 50 extern const colorrgb DARK_BLUE; 51 extern const colorrgb YELLOW; 52 extern const colorrgb WHITE; 53 extern const colorrgb LIGHT_GRAY; 54 extern const colorrgb DARK_GRAY; 55 extern const colorrgb BLACK; 56 extern const colorrgb PURPLE; 57 extern const colorrgb PINK; 58 extern const colorrgb ORANGE; 59 } 60 61 class picture 62 { 63 protected: 64 int32 width,height; 65 PictureType type; 66 bool isBackground; 67 68 struct 69 { 70 uint8 *buffer; 71 int32 buffersize; 72 }data[3],solidness; 73 74 public: 75 76 picture(); 77 picture(const picture &src) throw(error_obj); 78 virtual ~picture(); 79 80 void set_isBackground(bool value) throw(error_obj); get_isBackground(void)81 bool get_isBackground(void) const { return isBackground; } 82 83 84 void set_size(int32 newwidth,int32 newheight) throw(error_obj); 85 void erase(void); 86 get_height(void)87 inline int32 get_height(void) const { return height; } get_width(void)88 inline int32 get_width(void) const { return width; } get_type(void)89 inline PictureType get_type(void) const { return type; } 90 91 colorrgb get_pixel(int32 x,int32 y) const; 92 uint8 get_solidness(int32 x,int32 y) const; 93 94 void convto_rgb(void) throw(error_obj); 95 void convto_grayscale(void) throw(error_obj); 96 97 void set_solidness(int32 x,int32 y,uint8 newsolidness) throw(error_obj); 98 void set_solidness_color(const colorrgb &color,uint8 newsolidness) throw(error_obj); 99 void set_solidness_all(uint8 newsolidness) throw(error_obj); 100 void set_pixel(int32 x,int32 y,const colorrgb &color = color::WHITE, 101 uint8 solid = 255) throw(error_obj); 102 void set_pixel_grayscale(int32 x,int32 y,uint8 grey = 255,uint8 solid = 255) throw(error_obj); 103 void clear(const colorrgb &color = color::BLACK) throw(error_obj); 104 105 void draw_lines( const float *vertex, const uint32 *lines, uint32 nroflines, 106 const colorrgb &color = color::WHITE, 107 bool antialiased = false, uint8 solid = 255 ) throw(error_obj); 108 109 void line(int32 x1,int32 y1,int32 x2,int32 y2,const colorrgb &color = color::WHITE, 110 uint8 solid = 255) throw(error_obj); 111 112 void line_antialiasing(float x1,float y1,float x2,float y2,const colorrgb &color = color::WHITE, 113 uint8 solid = 255) throw(error_obj); 114 115 void box(int32 x,int32 y,int32 width,int32 height,const colorrgb &color = color::WHITE, 116 uint8 solid = 255) throw(error_obj); 117 118 void filled_box(int32 x,int32 y,int32 width,int32 height,const colorrgb &color = color::WHITE, 119 uint8 solid = 255) throw(error_obj); 120 121 void circle( int32 x, int32 y, uint32 r, const colorrgb &color = color::WHITE, 122 bool antialiased = false ) throw(error_obj); 123 void filled_circle( int32 x, int32 y, uint32 r, const colorrgb &color = color::WHITE, 124 bool antialiased = false ) throw(error_obj); 125 126 void ellipse(int32 x, int32 y, uint32 rx, uint32 ry, const colorrgb &color = color::WHITE, 127 bool antialiased = false) throw(error_obj); 128 129 void draw(int32 x,int32 y) const throw(error_obj); 130 void draw_shadow(int32 x,int32 y,const colorrgb &color = color::BLACK) const throw(error_obj); 131 132 void mirror(void) throw(error_obj); 133 void upside_down(void) throw(error_obj); 134 void rotate90(void) throw(error_obj); 135 void rotate180(void) throw(error_obj); 136 void rotate270(void) throw(error_obj); 137 138 void capture(const picture &source,int32 x,int32 y,int32 width,int32 height) throw(error_obj); 139 140 void load_pcx(const char *filename) throw(error_obj); 141 142 void save_pcx(const char *filename) const throw(error_obj); 143 144 void save_ppm(const char *filename, bool save_as_ascii = false) const throw(error_obj); 145 146 void operator=(const picture &source) throw(error_obj); 147 148 bool operator==(const picture &pic) const; 149 }; 150 151 extern picture *dest; // this is a pointer to the picture that all pictures will be drawn to 152 153 } // end of namespace picture_h 154 155 #endif 156