00001
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026 #ifndef INCL_IMAGEBUF
00027 #define INCL_IMAGEBUF 1
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037 class Xform_palette
00038 {
00039 public:
00040 unsigned char colors[256];
00041 unsigned char r,g,b,a;
00042 void set_color(int cr, int cg, int cb, int ca)
00043 { r = cr; g = cg; b = cb; a = ca; }
00044 unsigned char operator[](int i) const
00045 { return colors[i]; }
00046 };
00047
00048
00049
00050
00051
00052 class Image_buffer
00053 {
00054 protected:
00055 unsigned int width, height;
00056 int depth;
00057 int pixel_size;
00058 unsigned char *bits;
00059 unsigned int line_width;
00060 private:
00061 int clipx, clipy, clipw, cliph;
00062
00063 int clip_internal(int& srcx, int& srcw, int& destx,
00064 int clips, int clipl)
00065 {
00066 if (destx < clips)
00067 {
00068 if ((srcw += (destx - clips)) <= 0)
00069 return (0);
00070 srcx -= (destx - clips);
00071 destx = clips;
00072 }
00073 if (destx + srcw > (clips + clipl))
00074 if ((srcw = ((clips + clipl) - destx)) <= 0)
00075 return (0);
00076 return (1);
00077 }
00078 protected:
00079 int clip_x(int& srcx, int& srcw, int& destx, int desty)
00080 { return desty < clipy || desty >= clipy + cliph ? 0
00081 : clip_internal(srcx, srcw, destx, clipx, clipw); }
00082 int clip(int& srcx, int& srcy, int& srcw, int& srch,
00083 int& destx, int& desty)
00084 {
00085
00086 return (clip_internal(srcx, srcw, destx, clipx, clipw) &&
00087 clip_internal(srcy, srch, desty, clipy, cliph));
00088 }
00089 Image_buffer(unsigned int w, unsigned int h, int dpth);
00090 public:
00091 friend class Image_buffer8;
00092 friend class Image_buffer16;
00093 virtual ~Image_buffer()
00094 {
00095 delete [] bits;
00096 }
00097 friend class Image_window;
00098 unsigned char *get_bits()
00099 { return bits; }
00100 unsigned int get_width()
00101 { return width; }
00102 unsigned int get_height()
00103 { return height; }
00104 unsigned int get_line_width()
00105 { return line_width; }
00106 void clear_clip()
00107 { clipx = clipy = 0; clipw = width; cliph = height; }
00108
00109 void set_clip(int x, int y, int w, int h)
00110 {
00111 clipx = x;
00112 clipy = y;
00113 clipw = w;
00114 cliph = h;
00115 }
00116
00117 int is_visible(int x, int y, int w, int h)
00118 { return (!(x >= clipx + clipw || y >= clipy + cliph ||
00119 x + w <= clipx || y + h <= clipy)); }
00120
00121
00122
00123
00124 virtual void fill16(unsigned short pix)
00125 { }
00126
00127 virtual void fill16(unsigned short pix, int srcw, int srch,
00128 int destx, int desty)
00129 { }
00130
00131 virtual void copy16(unsigned short *src_pixels,
00132 int srcw, int srch, int destx, int desty)
00133 { }
00134
00135 virtual void copy_transparent16(unsigned char *src_pixels, int srcw,
00136 int srch, int destx, int desty)
00137 { }
00138
00139
00140
00141
00142 virtual void fill8(unsigned char val) = 0;
00143
00144 virtual void fill8(unsigned char val, int srcw, int srch,
00145 int destx, int desty) = 0;
00146
00147 virtual void fill_line8(unsigned char val, int srcw,
00148 int destx, int desty) = 0;
00149
00150 virtual void copy8(unsigned char *src_pixels,
00151 int srcw, int srch, int destx, int desty) = 0;
00152
00153 virtual void copy_line8(unsigned char *src_pixels, int srcw,
00154 int destx, int desty) = 0;
00155
00156 virtual void copy_line_translucent8(
00157 unsigned char *src_pixels, int srcw,
00158 int destx, int desty, int first_translucent,
00159 int last_translucent, Xform_palette *xforms) = 0;
00160
00161 virtual void fill_line_translucent8(unsigned char val,
00162 int srcw, int destx, int desty, Xform_palette& xform) = 0;
00163
00164 virtual void fill_translucent8(unsigned char val, int srcw, int srch,
00165 int destx, int desty, Xform_palette& xform) = 0;
00166
00167 virtual void copy_transparent8(unsigned char *src_pixels, int srcw,
00168 int srch, int destx, int desty) = 0;
00169
00170
00171
00172 virtual Image_buffer *create_another(int w, int h) = 0;
00173
00174 virtual void copy(int srcx, int srcy, int srcw, int srch,
00175 int destx, int desty) = 0;
00176
00177 virtual void get(Image_buffer *dest, int srcx, int srcy) = 0;
00178
00179 virtual void put(Image_buffer *src, int destx, int desty) = 0;
00180
00181 virtual void fill_static(int black, int gray, int white) = 0;
00182
00183 };
00184
00185 #endif