Image.h
Go to the documentation of this file.
1 /* ========================================================================
2  * Copyright (C) 2004-2005 Graz University of Technology
3  *
4  * This framework is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation; either version 2 of the License, or
7  * (at your option) any later version.
8  *
9  * This framework is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this framework; if not, write to the Free Software
16  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17  *
18  * For further information please contact Dieter Schmalstieg under
19  * <schmalstieg@icg.tu-graz.ac.at> or write to Dieter Schmalstieg,
20  * Graz University of Technology, Institut für Maschinelles Sehen und Darstellen,
21  * Inffeldgasse 16a, 8010 Graz, Austria.
22  * ========================================================================
23  * PROJECT: PocketKnife
24  * ======================================================================== */
29 /* ======================================================================== */
30 
31 
32 #ifndef __IMAGE_HEADERFILE__
33 #define __IMAGE_HEADERFILE__
34 
35 #include "PocketKnife.h"
36 
37 
38 namespace PN {
39 
41 
42 class Image
43 {
44 public:
46 
50  static Image* createFromPixelBuffer(int nWidth, int nHeight, unsigned short* nPixels, bool nOwner);
51 
52  virtual ~Image()
53  {
54  if( pixelsOwner )
55  delete[] pixels;
56  }
57 
59  int getWidth() const { return width; }
60 
62  int getHeight() const { return height; }
63 
65  void setTransparentColor(int nRed, int nGreen, int nBlue);
66 
68  void clear(int nRed, int nGreen, int nBlue);
69 
71  void clear(unsigned short nColor);
72 
74 
81  void drawImage(int nX, int nY, const Image* nImage,
82  int nSx0, int nSy0, int nSx1, int nSy1,
83  bool nTransparent=false);
84 
86 
91  void drawImage(int nX, int nY, const Image* nImage, bool nTransparent=false);
92 
93 
95 
99  void fillRect(int nX0, int nY0, int nX1, int nY1, int nRed, int nGreen, int nBlue, int nTransparency=0);
100 
102 
106  void fillRect(int nX0, int nY0, int nX1, int nY1, unsigned short nColor, int nTransparency=0);
107 
109 
112  void drawLine(int x1, int y1, int x2, int y2, unsigned short col);
113 
115 
118  void drawLine(int x1, int y1, int x2, int y2, int r, int g, int b);
119 
121 
124  void setPixel(int x, int y, unsigned short col);
125 
127 
130  void setPixel(int x, int y, int r, int g, int b);
131 
133  unsigned short* getPixels() { return pixels; }
134 
136  const unsigned short* getPixels() const { return pixels; }
137 
139 
142  unsigned short getPixel(int nX, int nY) const { return pixels[nY*width+nX]; }
143 
145 
149  void setPixels(int nWidth, int nHeight, unsigned short* nPixels, bool nPixelsOwner);
150 
151  unsigned short getColorKey() const { return colorKey; }
152 
153 protected:
154  Image(int nWidth, int nHeight, unsigned short* nPixels, bool nPixelsOwner)
155  : width(nWidth), height(nHeight), pixels(nPixels), pixelsOwner(nPixelsOwner)
156  {}
157 
158  // used by Font, initialize from passed Image
159  Image(Image* nImage)
160  : width(nImage->width), height(nImage->height), pixels(nImage->pixels), pixelsOwner(true)
161  {
162  nImage->pixelsOwner = false;
163  }
164 
165  int width, height;
166  unsigned short* pixels;
168 
169  unsigned short colorKey;
170 };
171 
172 } //namespace PN
173 
174 
175 #endif //__IMAGE_HEADERFILE__
void setPixel(int x, int y, unsigned short col)
Sets a pixel.
Definition: Image.cpp:274
int getHeight() const
Returns the height of the image.
Definition: Image.h:62
unsigned short colorKey
Definition: Image.h:169
void drawLine(int x1, int y1, int x2, int y2, unsigned short col)
Renders a straight line from x1/y1 to x2/y1 with the color &#39;col&#39;.
Definition: Image.cpp:204
virtual ~Image()
Definition: Image.h:52
void drawImage(int nX, int nY, const Image *nImage, int nSx0, int nSy0, int nSx1, int nSy1, bool nTransparent=false)
Draws another bitmap inside this bitmap.
Definition: Image.cpp:88
Definition: Image.cpp:46
static Image * createFromPixelBuffer(int nWidth, int nHeight, unsigned short *nPixels, bool nOwner)
Creates an Image object directly from a pixel buffer.
Definition: Image.cpp:288
void fillRect(int nX0, int nY0, int nX1, int nY1, int nRed, int nGreen, int nBlue, int nTransparency=0)
Fills a rectangle with the given color ans transparency.
Definition: Image.cpp:153
TFSIMD_FORCE_INLINE const tfScalar & y() const
unsigned short getColorKey() const
Definition: Image.h:151
void clear(int nRed, int nGreen, int nBlue)
Clears the bitmap with the given RGB color.
Definition: Image.cpp:81
unsigned short * pixels
Definition: Image.h:166
void setPixels(int nWidth, int nHeight, unsigned short *nPixels, bool nPixelsOwner)
Sets a new pixel buffer.
Definition: Image.cpp:296
void setTransparentColor(int nRed, int nGreen, int nBlue)
Sets the color key that is treated as transparent.
Image(Image *nImage)
Definition: Image.h:159
TFSIMD_FORCE_INLINE const tfScalar & x() const
Image(int nWidth, int nHeight, unsigned short *nPixels, bool nPixelsOwner)
Definition: Image.h:154
int getWidth() const
Returns the width of the image.
Definition: Image.h:59
const unsigned short * getPixels() const
Returns the pixel buffer.
Definition: Image.h:136
The Image class provides basic RGB565 image handing capabilities.
Definition: Image.h:42
bool pixelsOwner
Definition: Image.h:167
unsigned short * getPixels()
Returns the pixel buffer.
Definition: Image.h:133
int width
Definition: Image.h:165
unsigned short getPixel(int nX, int nY) const
Returns a pixel.
Definition: Image.h:142
int height
Definition: Image.h:165


tuw_artoolkitplus
Author(s): Markus Bader
autogenerated on Sun Sep 4 2016 03:24:33