]> icculus.org git repositories - icculus/iodoom3.git/blob - neo/tools/comafx/CDIB.h
hello world
[icculus/iodoom3.git] / neo / tools / comafx / CDIB.h
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,
40                 TIFF
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;
113         BOOL                    m_bUseGamma;
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__ */