Gray C++ Libraries  0.0.2
A set of C++ libraries for MSVC, GNU on Windows, WinCE, Linux
cSurfaceDC.h
Go to the documentation of this file.
1 //
4 //
5 
6 #ifndef _INC_cSurfaceDC_H
7 #define _INC_cSurfaceDC_H
8 #ifndef NO_PRAGMA_ONCE
9 #pragma once
10 #endif
11 
12 #include "cSurfaceBase.h"
13 #include "../Geometry/cRectI.h"
14 
15 namespace GrayLib
16 {
18 
20  {
24  SURF_FILTER_LIGHT, // just make darker.
25  SURF_FILTER_HUE, // just add color.
29 
31  SURF_FILTER_TRANSPARENT, // transparent.
34  };
35 
36  struct cSurfaceTextureVert // pack ?
37  {
40  int m_u;
41  int m_v;
42  int m_x;
43  int m_y;
44  };
45 
46  typedef COLOR16_t HUE16_t;
47  typedef COLOR16_t(GRAYCALL* SURF_CvtHueToColor_t)(HUE16_t iHue, int iGamma);
48 
50  {
56 
57  typedef cSurfaceDC THIS_t;
58 
59  public: // protected:
62 
65 
66  public:
67  cSurfaceDC() noexcept;
68  cSurfaceDC(COLOR16_t* pDataDest, PIXELS_t cx, PIXELS_t cy, size_t iPitchBytes);
69  cSurfaceDC(cSurfaceBase* pSurfDest);
70  cSurfaceDC(PIXELS_t x, PIXELS_t y); // nullptr trap at x,y
71  virtual ~cSurfaceDC();
72 
73  virtual void OnParamsChanged()
74  {
75  // m_eFilterType or m_rClipDest has changed.
76  }
77 
78  // clipping.
79  inline bool IsInsideClipX(PIXELS_t x) const noexcept
80  {
82  return m_rClipDest.IsInsideX(x);
83  }
84  inline bool IsInsideClipY(PIXELS_t y) const noexcept
85  {
87  return m_rClipDest.IsInsideY(y);
88  }
89 
91  {
92  m_rClipDest = cRectI(SHRT_MAX, SHRT_MAX, 0, 0); // SHRT_MAX
93  OnParamsChanged();
94  }
96  {
98  m_rClipDest = cRectI(0, 0, m_SurfDest.get_Width(), m_SurfDest.get_Height());
99  OnParamsChanged();
100  }
101  void SetClipDest(const cRectI& rect);
102 
103  virtual void DrawEraseClip();
104  virtual void DrawBlt(PIXELS_t x, PIXELS_t y, cSurfaceBase* pSrc, const cRectI& srcRect, DWORD rop);
105 
106  // DrawXLine
107  // DrawLine
108 
109 #ifdef _WIN32
110  int FlipToDC(HDC hDC, PIXELS_t XDest, PIXELS_t YDest) const
111  {
113  return m_SurfDest.FlipToDC(hDC, XDest, YDest);
114  }
115 #endif
116 
118  };
119 
121  {
125 
126  typedef cSurfaceDC2 THIS_t;
127 
128  public: // protected:
129 
134  signed char m_nGreyScaleCount;
138 
139  private:
140  void DrawXLineTexture(PIXELS_t xstart, PIXELS_t xend, COLOR16_t* pDstLine, int u, int v, int du, int dv, const COLOR16_t* pSrc, int iWidth);
141  bool DrawTextureTriangle(const COLOR16_t* pSrc, int iWidth, const cSurfaceTextureVert Vert[3]);
142 
143  protected:
144  void InitFilter();
145 
146  public:
147  cSurfaceDC2();
148  cSurfaceDC2(COLOR16_t* pDataDest, PIXELS_t cx, PIXELS_t cy, size_t iPitchBytes);
149  cSurfaceDC2(cSurfaceBase* pSurfDest);
150  cSurfaceDC2(PIXELS_t x, PIXELS_t y); // nullptr trap will throw.
151  ~cSurfaceDC2();
152 
153  static COLOR16_t GRAYCALL CvtHueToColor_Stub(HUE16_t iHue, WORD iGamma) noexcept
154  {
156  UNREFERENCED_PARAMETER(iGamma);
157  return iHue;
158  }
159 
160  THIS_t& operator = (const THIS_t& SurfDC)
161  {
162  CopyBase(SurfDC);
163  return *this;
164  }
165 
166  // Filtered drawing/copying routines.
167  void DrawXLine(COLOR16_t* pDst, const COLOR16_t* pSrc, int iWidth);
168  void DrawXLine(PIXELS_t x, PIXELS_t y, const COLOR16_t* pSrc, int iWidth);
169 
170  void DrawXClip(PIXELS_t x, COLOR16_t* pDstLine, const COLOR16_t* pSrc, int iWidth = 1);
171  void DrawXYClip(PIXELS_t x, PIXELS_t y, const COLOR16_t* pSrc, int iWidth);
172 
173  bool DrawSurf(PIXELS_t x, PIXELS_t y, const cSurfaceBase& SrcSurf, PIXELS_t iWidth, PIXELS_t iHeight);
174  bool DrawSurf(PIXELS_t x, PIXELS_t y, const cSurfaceBase& SrcSurf);
175 
176  bool DrawTexture(const cSurfaceBase& SrcSurf,
177  int x1, int y1,
178  int x2, int y2,
179  int x3, int y3,
180  int x4, int y4);
181 
182  void CopyBase(const THIS_t& SurfDC);
183 
184  void DrawColorSpaceToRGB565();
185  bool SetClipSrc(PIXELS_t x, PIXELS_t y, PIXELS_t iWidth, PIXELS_t iHeight);
186 
187  // filtering.
188  HUE16_t GetFilterHue() const noexcept
189  {
190  return m_wHueColor;
191  }
192  SURF_FILTER_TYPE get_Filter() const noexcept
193  {
194  return m_eFilterType;
195  }
196  COLOR_ELEM_t get_FilterLight() const noexcept
197  {
198  return m_Light;
199  }
200 
201  void UpdateFilters();
203  {
204  m_eFilterType = filter;
205  OnParamsChanged();
206  }
207  void put_FilterLight(COLOR_ELEM_t lightlevel = 0);
208  void SetFilterHue(HUE16_t wHue = 0); // HUE_DEFAULT
209 
210  void SetFilter565Color(bool b565Color);
211  void SetFilterCloth(bool bClothGray);
212  void SetFilterGrayCount(signed char iVal);
213  };
214 }
215 #endif // cSurfaceDC
#define GRAYCALL
declare calling convention for static functions so everyone knows the arg passing scheme....
Definition: GrayCore.h:36
#define GRAYLIB_LINK
Definition: GrayLibBase.h:35
#define UNREFERENCED_PARAMETER(P)
< _WIN32 type thing. get rid of stupid warning.
Definition: SysTypes.h:299
Definition: cColorRef.h:44
Definition: cRectI.h:22
bool IsInsideX(DVALUE_t x) const noexcept
Definition: cRectI.h:63
bool IsInsideY(DVALUE_t y) const noexcept
Definition: cRectI.h:68
Definition: cSurfaceBase.h:26
PIXELS_t get_Height() const noexcept
Definition: cSurfaceBase.h:88
PIXELS_t get_Width() const noexcept
Definition: cSurfaceBase.h:83
Definition: cSurfaceDC.h:121
COLOR_ELEM_t m_Light
light level filter. 0 = none.
Definition: cSurfaceDC.h:135
bool m_b565Color
Definition: cSurfaceDC.h:137
COLOR_ELEM_t get_FilterLight() const noexcept
Definition: cSurfaceDC.h:196
void put_Filter(SURF_FILTER_TYPE filter)
Definition: cSurfaceDC.h:202
SURF_FILTER_TYPE get_Filter() const noexcept
Definition: cSurfaceDC.h:192
static COLOR16_t GRAYCALL CvtHueToColor_Stub(HUE16_t iHue, WORD iGamma) noexcept
Definition: cSurfaceDC.h:153
HUE16_t GetFilterHue() const noexcept
Definition: cSurfaceDC.h:188
bool m_bClothGrey
only colorize the Grey scale parts.
Definition: cSurfaceDC.h:136
HUE16_t m_wHueColor
colorize/palletized this ? 0 = none.
Definition: cSurfaceDC.h:133
signed char m_nGreyScaleCount
Definition: cSurfaceDC.h:134
cRectI m_rClipSrc
Source Surface/Raster Filter Params.
Definition: cSurfaceDC.h:131
SURF_FILTER_TYPE m_eFilterType
SURF_FILTER_NONE filter operation. similar to BitBlt ROP.
Definition: cSurfaceDC.h:132
Definition: cSurfaceDC.h:50
cSurfaceBase m_SurfDest
The destination surface. NOT freed on destruct. "Unlink" this when done.
Definition: cSurfaceDC.h:60
cColorRef m_ColorFore
Foreground pen.
Definition: cSurfaceDC.h:63
cRectI m_rClipDest
clip to this rectangle for draws to m_Dest. (m_Dest surface coordinate system)
Definition: cSurfaceDC.h:61
void SetClipDestEmpty()
Definition: cSurfaceDC.h:90
cColorRef m_ColorBack
Background color (if any) Use Alpha channel. isValidColor()
Definition: cSurfaceDC.h:64
bool IsInsideClipY(PIXELS_t y) const noexcept
Definition: cSurfaceDC.h:84
bool IsInsideClipX(PIXELS_t x) const noexcept
Definition: cSurfaceDC.h:79
UNITTEST_FRIEND(cSurfaceDC)
void SetClipDestAll()
Definition: cSurfaceDC.h:95
Definition: cMesh.h:22
WORD COLOR16_t
A 16 bit greyscale color.
Definition: cColorRef.h:39
SURF_FILTER_TYPE
Definition: cSurfaceDC.h:20
@ SURF_FILTER_TRANSPARENT
Definition: cSurfaceDC.h:31
@ SURF_FILTER_SHADOW
Definition: cSurfaceDC.h:32
@ SURF_FILTER_BLACK
Definition: cSurfaceDC.h:33
@ SURF_FILTER_NONE
Definition: cSurfaceDC.h:23
@ SURF_FILTER_HUE_CLOTH_AND_LIGHT
Definition: cSurfaceDC.h:27
@ SURF_FILTER_HUE_CLOTH
Definition: cSurfaceDC.h:28
@ SURF_FILTER_HUE
Definition: cSurfaceDC.h:25
@ SURF_FILTER_HUE_AND_LIGHT
Definition: cSurfaceDC.h:26
@ SURF_FILTER_GREYSCALE
Definition: cSurfaceDC.h:30
@ SURF_FILTER_LIGHT
Definition: cSurfaceDC.h:24
UNITTEST2_PREDEF(cQuadtree)
COLOR16_t(GRAYCALL * SURF_CvtHueToColor_t)(HUE16_t iHue, int iGamma)
Definition: cSurfaceDC.h:47
COLOR16_t HUE16_t
Index into a hues table. (or palette) uses SURF_CvtHueToColor_t.
Definition: cSurfaceDC.h:46
BYTE COLOR_ELEM_t
A single 8 bit color element. alpha, red, green, or blue intensity as 0-255.
Definition: cColorRef.h:34
interface const RECTQ_t & rect
Definition: cQuadtree.h:44
int PIXELS_t
Count of pixels in a dimension of some image/surface.
Definition: cSurfaceInfo.h:20
Definition: cSurfaceDC.h:37
int m_u
source image. cPoint2
Definition: cSurfaceDC.h:40
int m_y
destination draw
Definition: cSurfaceDC.h:43
int m_v
source image.
Definition: cSurfaceDC.h:41
int m_x
destination draw
Definition: cSurfaceDC.h:42