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 class QImage;
11 
12 namespace Imagine {
15 
16  // ====================================================
17  // ImageIO: displaying, loading, saving, capturing, ...
18 
19  // Image displaying functions
20 
32  void putColorImage(int x, int y, const Color* cols, int w, int h, bool xorMode = false, double fact = 1.);
44  inline void putColorImage(const IntPoint2& p, const Color* cols, int w, int h, bool xorMode = false, double fact = 1.)
45  { putColorImage(p.x(), p.y(), cols, w, h, xorMode, fact); }
57  void putColorImage(int x, int y, const byte *rgb, int w, int h, bool xorMode = false, double fact = 1.);
69  inline void putColorImage(const IntPoint2& p, const byte *rgb, int w, int h, bool xorMode = false, double fact = 1.)
70  { putColorImage(p.x(), p.y(), rgb, w, h, xorMode, fact); }
82  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.);
83 
95  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.)
96  { putColorImage(p.x(), p.y(), r, g, b, w, h, xorMode, fact); }
97 
98  // Color Image whith transparency displaying functions
110  void putAlphaColorImage(int x, int y, Imagine::AlphaColor *cols, int w, int h, bool xorMode = false, double fact = 1.);
122  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.);
134  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.)
135  { putColorImage(p.x(), p.y(), r, g, b, a ,w, h, xorMode, fact); }
147  void putAlphaColorImage(int x, int y, byte *rgba, int w, int h, bool xorMode = false, double fact = 1.);
159  void putAlphaColorImage(const IntPoint2& p, byte *rgba, int w, int h, bool xorMode = false, double fact = 1.);
171  void putGreyImage(int x, int y, const byte* g, int w, int h, bool xorMode = false, double fact = 1.);
183  inline void putGreyImage(const IntPoint2& p, const byte* g, int w, int h, bool xorMode = false, double fact = 1.)
184  { putGreyImage(p.x(), p.y(), g, w, h, xorMode, fact); }
194  void setMaskFromColor(byte *&r, byte *&g, byte *&b, byte *&a, int w, int h, const Color &col);
204  void setMaskFromColor(byte *&rgba, int w, int h, const Color &col);
214  void setMaskFromColor(AlphaColor *&acols, int w, int h, AlphaColor col);
223  AlphaColor* convertColorToAlphaColor(const Imagine::Color *cols, int w, int h);
224  // Image loading functions
235  bool loadColorImage(const std::string& name, Color *&cols, int& w, int& h);
246  bool loadAlphaColorImage(const std::string& name, AlphaColor *&acols, int& w, int& h);
257  bool loadColorImage(const std::string &name, byte *&rgb, int &w, int &h);
268  bool loadAlphaColorImage(const std::string &name, byte *&rgba, int &w, int &h);
279  bool loadColorImage(const std::string &name, byte *&r, byte *&g, byte *&b, int &w, int &h);
290  bool loadColorImage(const std::string &name, byte *&r, byte *&g, byte *&b, byte*&a, int &w, int &h);
301  bool loadGreyImage(const std::string& name, byte*& g, int& w, int& h);
302 
303  // Image saving functions
304 
316  bool saveColorImage(const std::string& name,const Color* cols, int w, int h, int quality = 85);
328  bool saveAlphaColorImage(const std::string& name, Imagine::AlphaColor *cols, int w, int h, int quality = 85);
340  bool saveColorImage(const std::string &name, const byte *rgb, int w, int h, int quality = 85);
352  bool saveAlphaColorImage(const std::string &name, byte *rgba, int w, int h, int quality = 85);
364  bool saveColorImage(const std::string &name, const byte *r, const byte *g, const byte *b, int w, int h, int quality = 85);
376  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);
388  bool saveGreyImage(const std::string& name, const byte* g, int w, int h, int quality = 85);
389 
390  // Image capture functions
391 
399  Color capturePoint(int x, int y);
407  inline Color capturePoint(const IntPoint2& p)
408  { return capturePoint(p.x(), p.y()); }
417  void captureRectangle(int x, int y, Color *c, int w, int h);
426  inline void captureRectangle(const IntPoint2& p, Color *c, int w, int h)
427  { captureRectangle(p.x(), p.y(), c, w, h); }
436  void captureRectangle(int x, int y, byte *RGB, int w, int h);
445  inline void captureRectangle(const IntPoint2& p, byte *RGB, int w, int h)
446  { captureRectangle(p.x(), p.y(), RGB, w, h); }
455  void captureRectangle(int x, int y, byte *R, byte *G, byte *B, int w, int h);
465  inline void captureRectangle(const IntPoint2& p, byte *R, byte *G, byte *B, int w, int h)
466  { captureRectangle(p.x(), p.y(), R, G, B, w, h); }
475  void captureWindow(Color *&cols, int &w, int &h);
484  void captureWindow(byte *&RGB, int &w, int &h);
493  void captureWindow(byte *&R, byte *&G, byte *&B, int &w, int &h);
494 
495  // ====================================================
496  // NativeBitmap class
497 #ifndef DOXYGEN_SHOULD_SKIP_THIS
498  class NativeBitmapInternal; // Private
499  class NativeBitmap;
500 #endif
501  void putNativeBitmap(int x,int y,const NativeBitmap &bm,bool xorMode=false,double fact=1.);
512 
517  class NativeBitmap {
518  NativeBitmapInternal* priv;
519  public:
521  NativeBitmap();
528  NativeBitmap(int w,int h);
530  NativeBitmap(const NativeBitmap& I);
532  ~NativeBitmap();
534  const NativeBitmap& operator=(const NativeBitmap& I);
544  void setColorImage(int x,int y,const byte *r,const byte *g,const byte *b,int w,int h);
554  inline void setColorImage(const IntPoint2&p,const byte *r,const byte *g,const byte *b,int w,int h)
555  { setColorImage(p.x(),p.y(),r,g,b,w,h); }
565  void setColorImage(int x,int y,const Color *cols,int w,int h);
575  inline void setColorImage(const IntPoint2& p,const Color *cols,int w,int h)
576  { setColorImage(p.x(),p.y(),cols,w,h); }
586  inline void setColorImage(int x,int y,const byte *rgb,int w,int h)
587  { setColorImage(x,y,(const Color*)rgb,w,h); }
597  inline void setColorImage(const IntPoint2& p,const byte *rgb,int w,int h)
598  { setColorImage(p.x(),p.y(),(const Color*)rgb,w,h); }
608  void setGreyImage(int x,int y,const byte *g,int w,int h);
618  inline void setGreyImage(const IntPoint2 &p,const byte *g,int w,int h)
619  { setGreyImage(p.x(),p.y(),g,w,h); }
628  void setPoint(int x,int y,Color col);
637  inline void setPoint(const IntPoint2&p,Color col)
638  { setPoint(p.x(),p.y(),col); }
639  friend void putNativeBitmap(int x,int y,const NativeBitmap &bm,bool xorMode,double fact);
650  friend inline void putNativeBitmap(const IntPoint2& p,const NativeBitmap &bm,bool xorMode=false,double fact=1.) // Variant with IntPoint2
651  { putNativeBitmap(p.x(),p.y(),bm,xorMode,fact); }
652  };
653 
655 } /* namespace Imagine */
656 
657 #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:517
Coords< 2 > IntPoint2
Plane point with integral coordinates.
Definition: Types.h:17
void setGreyImage(const IntPoint2 &p, const byte *g, int w, int h)
Set grey image.
Definition: ImageIO.h:618
RGBA< byte > AlphaColor
RGBA alias.
Definition: Color.h:354
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 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.
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:637
void setColorImage(const IntPoint2 &p, const byte *r, const byte *g, const byte *b, int w, int h)
Set color image.
Definition: ImageIO.h:554
void setColorImage(int x, int y, const byte *rgb, int w, int h)
Set color image.
Definition: ImageIO.h:586
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:597
friend void putNativeBitmap(const IntPoint2 &p, const NativeBitmap &bm, bool xorMode=false, double fact=1.)
Display native bitmap.
Definition: ImageIO.h:650
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:575
const T & x() const
Read alias.
Definition: FVector.h:104
Imagine++ namespace.
Definition: Array.h:7
RED GREEN BLUE color.
Definition: Color.h:26
const T & y() const
Read alias.
Definition: FVector.h:118
friend void putNativeBitmap(int x, int y, const NativeBitmap &bm, bool xorMode, double fact)
Display native bitmap.