Imagine++
ImageIO.h
1 // ===========================================================================
2 // Imagine++ Libraries
3 // Copyright (C) Imagine
4 // For detailed information: http://imagine.enpc.fr/software
5 // ===========================================================================
6 
7 #ifndef IMAGINE_GRAPHICS_IMAGEIO_H
8 #define IMAGINE_GRAPHICS_IMAGEIO_H
9 
10 namespace Imagine {
13 
14  // ====================================================
15  // ImageIO: displaying, loading, saving, capturing, ...
16 
17  // Image displaying functions
18 
30  void putColorImage(int x, int y, const Color* cols, int w, int h, bool xorMode = false, double fact = 1.);
42  inline void putColorImage(const IntPoint2& p, const Color* cols, int w, int h, bool xorMode = false, double fact = 1.)
43  { putColorImage(p.x(), p.y(), cols, w, h, xorMode, fact); }
55  void putColorImage(int x, int y, const byte *rgb, int w, int h, bool xorMode = false, double fact = 1.);
67  inline void putColorImage(const IntPoint2& p, const byte *rgb, int w, int h, bool xorMode = false, double fact = 1.)
68  { putColorImage(p.x(), p.y(), rgb, w, h, xorMode, fact); }
80  void putColorImage(int x, int y, const byte *r, const byte *g, const byte *b, int w, int h, bool xorMode = false, double fact = 1.);
81 
93  inline void putColorImage(const IntPoint2& p, const byte *r, const byte *g, const byte *b, int w, int h, bool xorMode = false, double fact = 1.)
94  { putColorImage(p.x(), p.y(), r, g, b, w, h, xorMode, fact); }
95 
96  // Color Image whith transparency displaying functions
108  void putAlphaColorImage(int x, int y, Imagine::AlphaColor *cols, int w, int h, bool xorMode = false, double fact = 1.);
120  void putColorImage(int x, int y, const byte *r, const byte *g, const byte *b, const byte *a,int w, int h, bool xorMode = false, double fact = 1.);
132  inline void putColorImage(const IntPoint2& p, const byte *r, const byte *g, const byte *b, const byte *a,int w, int h, bool xorMode = false, double fact = 1.)
133  { putColorImage(p.x(), p.y(), r, g, b, a ,w, h, xorMode, fact); }
145  void putAlphaColorImage(int x, int y, byte *rgba, int w, int h, bool xorMode = false, double fact = 1.);
157  void putAlphaColorImage(const IntPoint2& p, byte *rgba, int w, int h, bool xorMode = false, double fact = 1.);
169  void putGreyImage(int x, int y, const byte* g, int w, int h, bool xorMode = false, double fact = 1.);
181  inline void putGreyImage(const IntPoint2& p, const byte* g, int w, int h, bool xorMode = false, double fact = 1.)
182  { putGreyImage(p.x(), p.y(), g, w, h, xorMode, fact); }
192  void setMaskFromColor(byte *&r, byte *&g, byte *&b, byte *&a, int w, int h, const Color &col);
202  void setMaskFromColor(byte *&rgba, int w, int h, const Color &col);
212  void setMaskFromColor(AlphaColor *&acols, int w, int h, AlphaColor col);
221  AlphaColor* convertColorToAlphaColor(const Imagine::Color *cols, int w, int h);
222  // Image loading functions
233  bool loadColorImage(const std::string& name, Color *&cols, int& w, int& h);
244  bool loadAlphaColorImage(const std::string& name, AlphaColor *&acols, int& w, int& h);
255  bool loadColorImage(const std::string &name, byte *&rgb, int &w, int &h);
266  bool loadAlphaColorImage(const std::string &name, byte *&rgba, int &w, int &h);
277  bool loadColorImage(const std::string &name, byte *&r, byte *&g, byte *&b, int &w, int &h);
288  bool loadColorImage(const std::string &name, byte *&r, byte *&g, byte *&b, byte*&a, int &w, int &h);
299  bool loadGreyImage(const std::string& name, byte*& g, int& w, int& h);
300 
301  // Image saving functions
302 
314  bool saveColorImage(const std::string& name,const Color* cols, int w, int h, int quality = 85);
326  bool saveAlphaColorImage(const std::string& name, Imagine::AlphaColor *cols, int w, int h, int quality = 85);
338  bool saveColorImage(const std::string &name, const byte *rgb, int w, int h, int quality = 85);
350  bool saveAlphaColorImage(const std::string &name, byte *rgba, int w, int h, int quality = 85);
362  bool saveColorImage(const std::string &name, const byte *r, const byte *g, const byte *b, int w, int h, int quality = 85);
374  bool saveAlphaColorImage(const std::string &name, const byte *r, const byte *g, const byte *b, const byte *a,int w, int h, int quality = 85);
386  bool saveGreyImage(const std::string& name, const byte* g, int w, int h, int quality = 85);
387 
388  // Image capture functions
389 
397  Color capturePoint(int x, int y);
405  inline Color capturePoint(const IntPoint2& p)
406  { return capturePoint(p.x(), p.y()); }
415  void captureRectangle(int x, int y, Color *c, int w, int h);
424  inline void captureRectangle(const IntPoint2& p, Color *c, int w, int h)
425  { captureRectangle(p.x(), p.y(), c, w, h); }
434  void captureRectangle(int x, int y, byte *RGB, int w, int h);
443  inline void captureRectangle(const IntPoint2& p, byte *RGB, int w, int h)
444  { captureRectangle(p.x(), p.y(), RGB, w, h); }
453  void captureRectangle(int x, int y, byte *R, byte *G, byte *B, int w, int h);
462  inline void captureRectangle(const IntPoint2& p, byte *R, byte *G, byte *B, int w, int h)
463  { captureRectangle(p.x(), p.y(), R, G, B, w, h); }
472  void captureWindow(Color *&cols, int &w, int &h);
481  void captureWindow(byte *&RGB, int &w, int &h);
490  void captureWindow(byte *&R, byte *&G, byte *&B, int &w, int &h);
491 
492  // ====================================================
493  // NativeBitmap class
494 #ifndef DOXYGEN_SHOULD_SKIP_THIS
495  class NativeBitmapInternal; // Private
496  class NativeBitmap;
497 #endif
498  void putNativeBitmap(int x,int y,const NativeBitmap &bm,bool xorMode=false,double fact=1.);
509 
514  class NativeBitmap {
515  NativeBitmapInternal* priv;
516  public:
518  NativeBitmap();
525  NativeBitmap(int w,int h);
527  NativeBitmap(const NativeBitmap& I);
529  ~NativeBitmap();
531  const NativeBitmap& operator=(const NativeBitmap& I);
541  void setColorImage(int x,int y,const byte *r,const byte *g,const byte *b,int w,int h);
551  inline void setColorImage(const IntPoint2&p,const byte *r,const byte *g,const byte *b,int w,int h)
552  { setColorImage(p.x(),p.y(),r,g,b,w,h); }
562  void setColorImage(int x,int y,const Color *cols,int w,int h);
572  inline void setColorImage(const IntPoint2& p,const Color *cols,int w,int h)
573  { setColorImage(p.x(),p.y(),cols,w,h); }
583  inline void setColorImage(int x,int y,const byte *rgb,int w,int h)
584  { setColorImage(x,y,(const Color*)rgb,w,h); }
594  inline void setColorImage(const IntPoint2& p,const byte *rgb,int w,int h)
595  { setColorImage(p.x(),p.y(),(const Color*)rgb,w,h); }
605  void setGreyImage(int x,int y,const byte *g,int w,int h);
615  inline void setGreyImage(const IntPoint2 &p,const byte *g,int w,int h)
616  { setGreyImage(p.x(),p.y(),g,w,h); }
625  void setPoint(int x,int y,Color col);
634  inline void setPoint(const IntPoint2&p,Color col)
635  { setPoint(p.x(),p.y(),col); }
636  friend void putNativeBitmap(int x,int y,const NativeBitmap &bm,bool xorMode,double fact);
647  friend inline void putNativeBitmap(const IntPoint2& p,const NativeBitmap &bm,bool xorMode=false,double fact=1.) // Variant with IntPoint2
648  { putNativeBitmap(p.x(),p.y(),bm,xorMode,fact); }
649  };
650 
652 } /* namespace Imagine */
653 
654 #endif // IMAGINE_GRAPHICS_IMAGEIO_H
bool saveColorImage(const std::string &name, const Color *cols, int w, int h, int quality=85)
Save color image.
void captureRectangle(int x, int y, Color *c, int w, int h)
Capture (sub window).
AlphaColor * convertColorToAlphaColor(const Imagine::Color *cols, int w, int h)
Convert a Color Image to a AlphaColor Image.
Native bitmap: image stored in graphics card format, fast to display.
Definition: ImageIO.h:514
void setGreyImage(const IntPoint2 &p, const byte *g, int w, int h)
Set grey image.
Definition: ImageIO.h:615
bool loadColorImage(const std::string &name, Color *&cols, int &w, int &h)
Load color image.
void putNativeBitmap(int x, int y, const NativeBitmap &bm, bool xorMode=false, double fact=1.)
Display native bitmap.
NativeBitmap()
Empty constructor.
RGB< byte > Color
RGB<byte> alias.
Definition: Color.h:281
const NativeBitmap & operator=(const NativeBitmap &I)
Assignment.
void setColorImage(int x, int y, const byte *r, const byte *g, const byte *b, int w, int h)
Set color image.
void captureWindow(Color *&cols, int &w, int &h)
Window capture.
Color capturePoint(int x, int y)
Capture (point).
bool loadGreyImage(const std::string &name, byte *&g, int &w, int &h)
Load grey image.
bool saveAlphaColorImage(const std::string &name, Imagine::AlphaColor *cols, int w, int h, int quality=85)
Save color image with alpha channel.
const T & x() const
Read alias.
Definition: FVector.h:104
void putAlphaColorImage(int x, int y, Imagine::AlphaColor *cols, int w, int h, bool xorMode=false, double fact=1.)
Display color bitmap with alpha channel.
RED GREEN BLUE Alpha color.
Definition: Color.h:138
void setMaskFromColor(byte *&r, byte *&g, byte *&b, byte *&a, int w, int h, const Color &col)
Create a transparency mask from a specified color-key.
void setPoint(const IntPoint2 &p, Color col)
Set point.
Definition: ImageIO.h:634
void setColorImage(const IntPoint2 &p, const byte *r, const byte *g, const byte *b, int w, int h)
Set color image.
Definition: ImageIO.h:551
void setColorImage(int x, int y, const byte *rgb, int w, int h)
Set color image.
Definition: ImageIO.h:583
void putColorImage(int x, int y, const Color *cols, int w, int h, bool xorMode=false, double fact=1.)
Display color bitmap.
~NativeBitmap()
Destructor.
void setGreyImage(int x, int y, const byte *g, int w, int h)
Set grey image.
bool saveGreyImage(const std::string &name, const byte *g, int w, int h, int quality=85)
Save grey image.
void setColorImage(const IntPoint2 &p, const byte *rgb, int w, int h)
Set color image.
Definition: ImageIO.h:594
friend void putNativeBitmap(const IntPoint2 &p, const NativeBitmap &bm, bool xorMode=false, double fact=1.)
Display native bitmap.
Definition: ImageIO.h:647
void putGreyImage(int x, int y, const byte *g, int w, int h, bool xorMode=false, double fact=1.)
Display grey bitmap.
bool loadAlphaColorImage(const std::string &name, AlphaColor *&acols, int &w, int &h)
Load color image with alpha channel.
void setPoint(int x, int y, Color col)
Set point.
void setColorImage(const IntPoint2 &p, const Color *cols, int w, int h)
Set color image.
Definition: ImageIO.h:572
const T & y() const
Read alias.
Definition: FVector.h:118
Imagine++ namespace.
Definition: Array.h:7
RED GREEN BLUE color.
Definition: Color.h:26
friend void putNativeBitmap(int x, int y, const NativeBitmap &bm, bool xorMode, double fact)
Display native bitmap.