ImageTool.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 
33 #ifndef __IMAGETOOL_HEADERFILE__
34 #define __IMAGETOOL_HEADERFILE__
35 
36 #include "PocketKnife.h"
37 #include "Image.h"
38 
39 
40 namespace PN
41 {
42 
43 
45 namespace ImageTool
46 {
47 
49 
53  void flipImageY(unsigned char* nDstBuffer, unsigned const char* nSrcBuffer, int nWidth, int nHeight, int nPixelSize);
54 
55 
57  inline unsigned short convertPixel24To16(int nRed, int nGreen, int nBlue)
58  {
59  return (unsigned short)(((nRed << 8) & RED_MASK) | ((nGreen << 3) & GREEN_MASK) | (nBlue >> 3));
60  }
61 
62 
64  inline void convertPixel16To24(unsigned short nPixel, unsigned char& nRed, unsigned char& nGreen, unsigned char& nBlue)
65  {
66  nRed = (unsigned char)((nPixel&RED_MASK) >> 8);
67  nGreen = (unsigned char)((nPixel&GREEN_MASK) >> 3);
68  nBlue = (unsigned char)((nPixel&BLUE_MASK) << 3);
69  }
70 
71 
73  inline unsigned short blendPixel16(unsigned short nSrc, unsigned short nDst, int nOpacity)
74  {
75  // shamelessly stolen from Thierry Tremblay's PocketFrog...
76  //
77  unsigned short RB1 = (unsigned short)(nDst & (RED_MASK | BLUE_MASK));
78  unsigned short G1 = (unsigned short)(nDst & (GREEN_MASK ));
79  unsigned short RB2 = (unsigned short)(nSrc & (RED_MASK | BLUE_MASK));
80  unsigned short G2 = (unsigned short)(nSrc & (GREEN_MASK));
81  unsigned short RB = (unsigned short)(RB1 + (((RB2-RB1) * (nOpacity>>3)) >> 5));
82  unsigned short G = (unsigned short)(G1 + (((G2-G1)*(nOpacity>>2))>>6));
83 
84  RB &= (RED_MASK | BLUE_MASK);
85  G &= (GREEN_MASK);
86 
87  return (unsigned short)(RB | G);
88  }
89 
90 
92 
95  bool saveAsTGA(Image* nImage, const char* nFileName);
96 
97 
98 }; // namespace ImageTool
99 
100 
101 }; // namespace PN
102 
103 
104 #endif //__IMAGETOOL_HEADERFILE__
Definition: Image.cpp:46
unsigned short convertPixel24To16(int nRed, int nGreen, int nBlue)
Converts a single pixel from 24-bits RGB to 16-bits (565) RGB.
Definition: ImageTool.h:57
bool saveAsTGA(Image *nImage, const char *nFileName)
Save an Image into a TGA file.
Definition: ImageTool.cpp:96
const unsigned short GREEN_MASK
Definition: PocketKnife.h:65
void flipImageY(unsigned char *nDstBuffer, unsigned const char *nSrcBuffer, int nWidth, int nHeight, int nPixelSize)
Flips an image in Y-direction.
Definition: ImageTool.cpp:65
unsigned short blendPixel16(unsigned short nSrc, unsigned short nDst, int nOpacity)
Blends a single pixel in 16-bits RGB565 format.
Definition: ImageTool.h:73
The Image class provides basic RGB565 image handing capabilities.
Definition: Image.h:42
const unsigned short BLUE_MASK
Definition: PocketKnife.h:66
const unsigned short RED_MASK
Definition: PocketKnife.h:64
void convertPixel16To24(unsigned short nPixel, unsigned char &nRed, unsigned char &nGreen, unsigned char &nBlue)
Converts a single pixel from 16-bits (565) RGB to 24-bits RGB.
Definition: ImageTool.h:64


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