00001 
00002 
00003 
00004 
00005 
00006 
00007 
00008 
00009 
00010 
00011 
00012 
00013 
00014 
00015 
00016 
00017 
00018 
00019 
00020 
00021 
00022 #ifndef _FL_IMAGE_H_
00023 #define _FL_IMAGE_H_
00024 
00025 #include "Enumerations.h"
00026 #include "Fl_Renderer.h"
00027 #include "Fl_PtrList.h"
00028 #include "Fl_Export.h"
00029 #include "Fl_Flags.h"
00030 #include "Fl_Image_IO.h"
00031 
00032 #include <stdio.h> 
00033 
00034 class Fl_Image;
00035 
00036 typedef bool (check_mask_pixel)(const Fl_Image *i, uint8 *buf);
00037 
00041 class Fl_Image {
00042     friend class Fl_Image_Filter;
00043 
00044 public:
00045     
00046     
00047     static Fl_Image *read(const char *filename, const uint8 *data = 0, uint32 data_size=0);
00048     
00049     static Fl_Image *read_xpm(const char *filename, const char * const *data=0);
00050 
00056     Fl_Image(const char *filename, int quality=FL_QUALITY_NORMAL);
00057 
00064     Fl_Image(const uint8 *data, uint32 data_size, int quality=FL_QUALITY_NORMAL);
00065 
00069     Fl_Image(const char * const *data, int quality=FL_QUALITY_NORMAL); 
00070 
00076     Fl_Image(int W, int H, Fl_PixelFormat *fmt, uint8 *data, bool allow_free=false);
00077 
00086     Fl_Image(int W, int H, int bits_pp, uint8 *data=0, bool allow_free=false, uint32 Rmask=0, uint32 Gmask=0, uint32 Bmask=0, uint32 Amask=0);
00087 
00091     Fl_Image(Fl_Image &i);
00092 
00098     virtual ~Fl_Image();
00099 
00100     
00101     
00102     bool read_image(const char *filename, const uint8 *data = 0, uint32 data_size=0);
00103     bool read_image(const char *filename, const char * const *data);
00104     bool read_image(const char *filename, char **data) { return read_image(filename, (const char **)data); }
00105 
00106     
00107     bool write_image(const char *filename, const char *io_name);
00108     bool write_image(const char *filename, Fl_Image_IO *io);
00109 
00110     
00111     bool write_image(uint8 *&data, int &data_size, const char *io_name);
00112     bool write_image(uint8 *&data, int &data_size, Fl_Image_IO *io);
00113 
00114     
00115     int quality() const { return m_quality; }
00116     void quality(int q) { m_quality = q; }
00117 
00118     
00119     void copy(Fl_Image &src, Fl_Image &dst);
00120 
00129     virtual void measure(int &W, int &H) { W=width(); H=height(); }
00130 
00137     void draw(int dx, int dy, int dw, int dh, int sx, int sy, int sw, int sh, Fl_Flags f) { _draw(dx, dy, dw, dh, sx, sy, sw, sh, f); }
00143     void draw(int x, int y, int w=0, int h=0, Fl_Flags f=0) { if(!w) w=width(); if(!h) h=height(); _draw(x,y,w,h,0,0,0,0,f); }
00144 
00145     
00146     int mask_type() const { return m_fmt.masktype; }
00147     void mask_type(int mask) { m_fmt.masktype = mask; }
00148 
00149     void set_mask(Pixmap m, bool allow_free=false);
00150     Pixmap get_mask() const { return (Pixmap)mask; }
00151 
00152     void set_offscreen(Pixmap p, bool allow_free=false);
00153     Pixmap get_offscreen() const { return (Pixmap)id; }
00154 
00155     Region create_region_mask(check_mask_pixel *func = 0) const;
00156     Region create_scaled_region_mask(int w, int h, check_mask_pixel *func = 0);
00157 
00158     
00159     Pixmap create_bitmap_mask(check_mask_pixel *func = 0) const;
00160     Pixmap create_scaled_bitmap_mask(int w, int h, check_mask_pixel *func = 0);
00161     Pixmap create_mask(int w, int h) { return create_scaled_bitmap_mask(w,h); }
00162 
00167     Fl_Image *scale(int W, int H);
00168 
00173     Fl_Image *grayscale();
00174 
00180     Fl_Image *fore_blend(uint color);
00181 
00187     Fl_Image *back_blend(uint color);
00188 
00193     Fl_Image *blend(Fl_Image *back, int x, int y);
00194 
00195     
00196     void clear();
00197 
00198     
00199     void invalidate();
00200 
00201     
00202     void system_convert();
00203 
00204     
00205     uint8 *data() { return m_data; }
00206 
00207     int width()  const { return m_width; }
00208     int height() const { return m_height; }
00209 
00210     int pitch()   const { return m_pitch; }
00211     int bytespp() const { return m_fmt.bytespp; } 
00212     int bitspp()  const { return m_fmt.bitspp;  } 
00213 
00214     int state() const { return m_state; }
00215     void state(int s) { m_state = s; }
00216 
00217     
00218     inline uint32 colorkey() const { return m_fmt.colorkey; }
00219     inline void colorkey(uint32 c) { m_fmt.colorkey = c; }
00220 
00221     
00222     inline uint8 alpha() const { return m_fmt.alpha; }
00223     inline void alpha(uint8 a) { m_fmt.alpha = a; }
00224 
00225     
00226     inline uint8 threshold() const { return m_threshold; }
00227     inline void threshold(uint8 t) { m_threshold = t; }
00228 
00229     
00230     inline Fl_Colormap *colormap() const { return m_fmt.palette; }
00231     Fl_Colormap *colormap(Fl_Colormap *new_map) { Fl_Colormap *old = m_fmt.palette; m_fmt.palette = new_map; return old; }
00232 
00233     Fl_PixelFormat *format() const { return (Fl_PixelFormat*)&m_fmt; }
00234 
00235     
00236     bool check_map(Fl_PixelFormat *cur_fmt, Fl_PixelFormat *new_fmt);
00237     bool check_map(Fl_PixelFormat *new_fmt);
00238 
00239     
00240     void no_screen(bool v) { m_no_screen = v; }
00241     bool no_screen() const { return m_no_screen; }
00242 
00243     
00244     void state_effect(bool value) { m_state_effect = value; }
00245     bool state_effect() const { return m_state_effect; }
00246 
00247     
00248     static bool state_effect_all() { return m_state_effect_all; }
00249     static void state_effect_all(bool value) { m_state_effect_all = value; }
00250 
00251 protected:
00255     Fl_Image();
00256 
00257     void init(int W, int H, int bits_pp, uint8 *data, uint32 Rmask, uint32 Gmask, uint32 Bmask, uint32 Amask);
00258     virtual void _draw(int dx, int dy, int dw, int dh,
00259                        int sx, int sy, int sw, int sh,
00260                        Fl_Flags f);
00261 
00262     
00263     void to_screen(int X, int Y, int W, int H, int cx, int cy);
00264     void to_screen_tiled(int X, int Y, int W, int H, int cx, int cy);
00265 
00266     int m_width;  
00267     int m_height; 
00268     int m_pitch;  
00269 
00270     uint8 *m_data; 
00271 
00272     bool m_data_alloc;   
00273     bool m_id_alloc;     
00274     bool m_mask_alloc;   
00275 
00276     void *id;   
00277     void *mask; 
00278 
00279 private:
00280     bool m_no_screen;
00281     uint8 m_threshold;
00282 
00283     Fl_PixelFormat m_fmt;
00284 
00285     bool m_state_effect;
00286     static bool m_state_effect_all;
00287 
00288     int m_state;
00289     int m_quality;
00290 
00291     int m_old_drawflags;  
00292     int m_lastw, m_lasth; 
00293     
00294     Fl_Image *m_mod_data;
00295 };
00296 
00297 #endif