doom3-gpl
Doom 3 GPL source release
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
CDIB.h
Go to the documentation of this file.
1 /*
2 ===========================================================================
3 
4 Doom 3 GPL Source Code
5 Copyright (C) 1999-2011 id Software LLC, a ZeniMax Media company.
6 
7 This file is part of the Doom 3 GPL Source Code (?Doom 3 Source Code?).
8 
9 Doom 3 Source Code is free software: you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation, either version 3 of the License, or
12 (at your option) any later version.
13 
14 Doom 3 Source Code is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
18 
19 You should have received a copy of the GNU General Public License
20 along with Doom 3 Source Code. If not, see <http://www.gnu.org/licenses/>.
21 
22 In addition, the Doom 3 Source Code is also subject to certain additional terms. You should have received a copy of these additional terms immediately following the terms and conditions of the GNU General Public License which accompanied the Doom 3 Source Code. If not, please request a copy in writing from id Software at the address below.
23 
24 If you have questions concerning this license or the applicable additional terms, you may contact in writing id Software LLC, c/o ZeniMax Media Inc., Suite 120, Rockville, Maryland 20850 USA.
25 
26 ===========================================================================
27 */
28 
29 #ifndef __CDIB__
30 #define __CDIB__
31 
32 // Original ColorPicker/DIB source by Rajiv Ramachandran <rrajivram@hotmail.com>
33 // included with permission from the author
34 
35 class CDIB {
36 public:
37  enum BitmapType {
38  BMP,
39  GIF,
41  };
42  CDIB( HANDLE hDib = NULL,int nBits = 8 );
43  virtual ~CDIB();
44 
45  CDIB & operator=( CDIB& dib );
46  BOOL IsValid() { return ( m_pVoid && Width() && Height() ); }
47  void UseGamma( float fg, BOOL bUse = TRUE );
48  BOOL CreateFromHandle( HANDLE hDib, int nBits );
49  BOOL Create( int width, int height, int bits = 24 );
50  BOOL Create( BITMAPINFOHEADER& bmInfo );
51  BOOL CopyDIB( CDIB& dib );
52  BOOL OpenDIB( CString &fileName );
53  BOOL SaveDIB( CString &fileName, BitmapType type );
54  void ReplaceColor(unsigned char oldColor,unsigned char newColor);
55  HANDLE GetDIBits(int nStartX=-1,int nStartY=-1,int nCx=-1,int nCy=-1);
56  CBitmap * GetBitmap(CDC& dc);
57  CBitmap * GetTempBitmap(CDC& dc);
58  DWORD GetDIBSize();
59  int GetPaletteSize(BITMAPINFOHEADER& bmInfo);
60  int GetPaletteSize();
61  int CountColors();
62  int EnumColors(BYTE *colors);
63  void InitDIB(COLORREF color);
64  void CopyLine(int source,int dest);
65  void DestroyDIB();
66  void SetPalette(unsigned char *palette);
67  void SetPalette(RGBQUAD *pRGB);
68  COLORREF PaletteColor(int index);
69  void SetPixel(int x,int y,COLORREF color);
70  void SetPixel8(int x,int y,unsigned char color);
71  COLORREF GetPixel(int x,int y);
72  void GetPixel(UINT x,UINT y,int& pixel);
73  void BitBlt(HDC hDest,int nXDest,int nYDest,int nWidth,int nHeight,int xSrc,int ySrc);
74  void BitBlt(int nXDest,int nYDest,int nWidth,int nHeight,CDIB& dibSrc,int nSrcX,int nSrcY,BYTE *colors=NULL);
75  void StretchBlt(HDC hDest,int nXDest,int nYDest,int nDWidth,int nDHeight,int xSrc,int ySrc,int nSWidth,int nSHeight);
76  void StretchBlt(int nXDest,int nYDest,int nDWidth,int nDHeight,CDIB& dibSrc,int xSrc,int ySrc,int nSWidth,int nSHeight);
77  void ExpandBlt(int nXDest,int nYDest,int xRatio,int yRatio,CDIB& dibSrc,int xSrc,int ySrc,int nSWidth,int nSHeight);
78  void SetFlags(int flag) { m_nFlags = flag; }
79  int Height() { return height ; }
80  int Width() { return width ; }
81  unsigned char *GetLinePtr(int line);
82  inline int GetBitCount() { return m_pInfo->bmiHeader.biBitCount; }
83  BOOL Make8Bit( CDIB &dib );
84  BOOL SwitchFromOne( CDIB &dib );
85  BOOL SwitchFromFour( CDIB &dib );
86  BOOL SwitchFrom24( CDIB &dib );
87  BOOL SwitchPalette( CDIB &dib );
88  int ClosestColor(RGBQUAD *pRgb );
89  LPBITMAPINFO GetBitmapInfo() { return m_pInfo; }
90  static unsigned int Distance( RGBQUAD& rgb1, RGBQUAD& rgb2 );
91 
92 protected:
93  HANDLE DIBHandle();
94  BOOL OpenBMP( CString &csFileName );
95  BOOL OpenGIF( CString &csFileName );
96  BOOL OpenTIFF( CString &csFileName );
97  BOOL SaveBMP( CString &csFileName );
98  BOOL SaveGIF( CString &csFileName );
99  BOOL SaveTIFF( CString &csFileName );
100  void CreateGammaCurve();
101  void Expand( int nXDest, int nYDest, int xRatio, int yRatio, CDIB &dibSrc, int xSrc, int ySrc, int nSWidth, int nSHeight );
102 
103  unsigned char * m_pBits;
104  PBITMAPINFO m_pInfo;
105  RGBQUAD * m_pRGB;
106  void * m_pVoid;
107  BYTE ** m_pLinePtr;
108  int height;
109  int bytes;
110  int width;
111  int m_nBits;
112  int m_nFlags;
114  float m_fGamma;
115  float m_fOldGamma;
116  unsigned char Gamma[256];
117  RGBQUAD CacheQuad[256];
118  char CachePtr[256];
119 };
120 
121 #endif /* !__CDIB__ */
byte color[4]
Definition: MegaTexture.cpp:54
int width
Definition: CDIB.h:110
BOOL OpenBMP(CString &csFileName)
Definition: CDIB.cpp:909
HANDLE DIBHandle()
Definition: CDIB.cpp:601
void SetPalette(unsigned char *palette)
Definition: CDIB.cpp:132
BOOL CopyDIB(CDIB &dib)
Definition: CDIB.cpp:548
static unsigned int Distance(RGBQUAD &rgb1, RGBQUAD &rgb2)
Definition: CDIB.cpp:849
void DestroyDIB()
Definition: CDIB.cpp:71
int int int int int int ySrc
Definition: wglext.h:335
CONST PIXELFORMATDESCRIPTOR UINT
Definition: win_qgl.cpp:47
RGBQUAD * m_pRGB
Definition: CDIB.h:105
COLORREF GetPixel(int x, int y)
Definition: CDIB.cpp:216
virtual ~CDIB()
Definition: CDIB.cpp:66
int Height()
Definition: CDIB.h:79
BOOL IsValid()
Definition: CDIB.h:46
DWORD
Definition: win_qgl.cpp:61
GLenum GLint GLint y
Definition: glext.h:2849
typedef HANDLE(WINAPI *PFNWGLCREATEBUFFERREGIONARBPROC)(HDC hDC
PBITMAPINFO m_pInfo
Definition: CDIB.h:104
int height
Definition: CDIB.h:108
BOOL SwitchFromFour(CDIB &dib)
Definition: CDIB.cpp:759
float m_fGamma
Definition: CDIB.h:114
int GetBitCount()
Definition: CDIB.h:82
void StretchBlt(HDC hDest, int nXDest, int nYDest, int nDWidth, int nDHeight, int xSrc, int ySrc, int nSWidth, int nSHeight)
Definition: CDIB.cpp:325
void UseGamma(float fg, BOOL bUse=TRUE)
Definition: CDIB.cpp:659
BOOL SaveTIFF(CString &csFileName)
HANDLE GetDIBits(int nStartX=-1, int nStartY=-1, int nCx=-1, int nCy=-1)
Definition: CDIB.cpp:580
GLuint GLuint GLsizei GLenum type
Definition: glext.h:2845
Definition: CDIB.h:39
GLenum GLint x
Definition: glext.h:2849
#define BOOL
Definition: mprintf.c:71
unsigned char * GetLinePtr(int line)
Definition: CDIB.cpp:540
int ClosestColor(RGBQUAD *pRgb)
Definition: CDIB.cpp:814
void SetPixel8(int x, int y, unsigned char color)
Definition: CDIB.cpp:201
void * m_pVoid
Definition: CDIB.h:106
BOOL Make8Bit(CDIB &dib)
Definition: CDIB.cpp:688
unsigned char Gamma[256]
Definition: CDIB.h:116
GLsizei GLsizei GLcharARB * source
Definition: glext.h:3633
BOOL SwitchFromOne(CDIB &dib)
Definition: CDIB.cpp:736
BOOL OpenDIB(CString &fileName)
Definition: CDIB.cpp:858
void ReplaceColor(unsigned char oldColor, unsigned char newColor)
Definition: CDIB.cpp:559
BOOL SwitchPalette(CDIB &dib)
Definition: CDIB.cpp:789
void Expand(int nXDest, int nYDest, int xRatio, int yRatio, CDIB &dibSrc, int xSrc, int ySrc, int nSWidth, int nSHeight)
Definition: CDIB.cpp:341
int m_nBits
Definition: CDIB.h:111
GLuint index
Definition: glext.h:3476
BOOL SaveBMP(CString &csFileName)
Definition: CDIB.cpp:890
BitmapType
Definition: CDIB.h:37
void CopyLine(int source, int dest)
Definition: CDIB.cpp:279
unsigned char * m_pBits
Definition: CDIB.h:103
#define NULL
Definition: Lib.h:88
int GetPaletteSize()
Definition: CDIB.cpp:165
COLORREF PaletteColor(int index)
Definition: CDIB.cpp:985
int m_nFlags
Definition: CDIB.h:112
void BitBlt(HDC hDest, int nXDest, int nYDest, int nWidth, int nHeight, int xSrc, int ySrc)
Definition: CDIB.cpp:320
void SetPixel(int x, int y, COLORREF color)
Definition: CDIB.cpp:187
GLenum GLsizei width
Definition: glext.h:2846
typedef HDC(WINAPI *PFNWGLGETCURRENTREADDCARBPROC)(void)
int EnumColors(BYTE *colors)
Definition: CDIB.cpp:962
Definition: CDIB.h:38
BOOL SaveGIF(CString &csFileName)
GLenum GLsizei GLsizei height
Definition: glext.h:2856
int bytes
Definition: CDIB.h:109
void ExpandBlt(int nXDest, int nYDest, int xRatio, int yRatio, CDIB &dibSrc, int xSrc, int ySrc, int nSWidth, int nSHeight)
Definition: CDIB.cpp:331
void InitDIB(COLORREF color)
Definition: CDIB.cpp:290
CDIB & operator=(CDIB &dib)
Definition: CDIB.cpp:574
#define bits
Definition: Unzip.cpp:3797
BOOL SwitchFrom24(CDIB &dib)
Definition: CDIB.cpp:992
BOOL OpenTIFF(CString &csFileName)
void CreateGammaCurve()
Definition: CDIB.cpp:668
int Width()
Definition: CDIB.h:80
int int int int int xSrc
Definition: wglext.h:335
BOOL Create(int width, int height, int bits=24)
Definition: CDIB.cpp:80
float m_fOldGamma
Definition: CDIB.h:115
Definition: CDIB.h:35
void SetFlags(int flag)
Definition: CDIB.h:78
char CachePtr[256]
Definition: CDIB.h:118
BYTE ** m_pLinePtr
Definition: CDIB.h:107
DWORD GetDIBSize()
Definition: CDIB.cpp:596
#define TRUE
Definition: mprintf.c:69
LPBITMAPINFO GetBitmapInfo()
Definition: CDIB.h:89
CBitmap * GetBitmap(CDC &dc)
Definition: CDIB.cpp:247
CBitmap * GetTempBitmap(CDC &dc)
Definition: CDIB.cpp:230
CDIB(HANDLE hDib=NULL, int nBits=8)
Definition: CDIB.cpp:54
BOOL OpenGIF(CString &csFileName)
BOOL CreateFromHandle(HANDLE hDib, int nBits)
Definition: CDIB.cpp:622
BOOL SaveDIB(CString &fileName, BitmapType type)
Definition: CDIB.cpp:872
BOOL m_bUseGamma
Definition: CDIB.h:113
int CountColors()
Definition: CDIB.cpp:939
RGBQUAD CacheQuad[256]
Definition: CDIB.h:117