CFx SDK Documentation  2023 SP0
GiPalette.h
Go to the documentation of this file.
1 // Copyright (C) 2002-2017, Open Design Alliance (the "Alliance").
3 // All rights reserved.
4 //
5 // This software and its documentation and related materials are owned by
6 // the Alliance. The software may only be incorporated into application
7 // programs owned by members of the Alliance, subject to a signed
8 // Membership Agreement and Supplemental Software License Agreement with the
9 // Alliance. The structure and organization of this software are the valuable
10 // trade secrets of the Alliance and its suppliers. The software is also
11 // protected by copyright law and international treaty provisions. Application
12 // programs incorporating this software must include the following statement
13 // with their copyright notices:
14 //
15 // This application incorporates Teigha(R) software pursuant to a license
16 // agreement with Open Design Alliance.
17 // Teigha(R) Copyright (C) 2002-2017 by Open Design Alliance.
18 // All rights reserved.
19 //
20 // By use of this software, its documentation or related materials, you
21 // acknowledge and accept the above terms.
23 
24 #ifndef __ODGIPALETTE_H__
25 #define __ODGIPALETTE_H__
26 
27 #include "TD_PackPush.h"
28 
29 #include "GiExport.h"
30 #include "OdArray.h"
31 #include "SharedPtr.h"
32 
38 struct OdGiIntRGB
39 {
40  OdInt32 r, g, b;
41 
43  : r(_r), g(_g), b(_b)
44  { }
45  OdGiIntRGB() { }
47  {
48  setColor(cref);
49  }
50 
54  OdInt32 red() const { return r; }
58  OdInt32 green() const { return g; }
62  OdInt32 blue() const { return b; }
63 
68  void setRed(OdInt32 _r) { r = _r; }
73  void setGreen(OdInt32 _g) { g = _g; }
78  void setBlue(OdInt32 _b) { b = _b; }
85  void setRGB(OdInt32 _r, OdInt32 _g, OdInt32 _b) { r = _r; g = _g; b = _b; }
86 
91  void setColor(ODCOLORREF cref)
92  {
93  setRGB((OdInt32)ODGETRED(cref), (OdInt32)ODGETGREEN(cref), (OdInt32)ODGETBLUE(cref));
94  }
98  ODCOLORREF color() const
99  {
100  return ODRGB(r, g, b);
101  }
102 };
103 
110 {
111  protected:
118  public:
119  OdGiColorCube(OdGiIntRGB nGridDivs = OdGiIntRGB(2, 2, 2), float fIntensity = 1.0f, OdInt32 nBaseOffset = 0)
120  : m_nBaseOffset(nBaseOffset)
121  , m_nGridDivs(nGridDivs)
122  , m_fIntensity(fIntensity)
123  {
124  validate();
125  }
126 
130  OdInt32 baseOffset() const { return m_nBaseOffset; }
134  const OdGiIntRGB &gridDivisions() const { return m_nGridDivs; }
138  float intensity() const { return m_fIntensity; }
142  OdInt32 gridSize() const { return m_nGridSize; }
146  const OdGiIntRGB &offsets() const { return m_nOffsets; }
150  const OdGiIntRGB &dimensions() const { return m_nDims; }
151 
156  ODCOLORREF color(OdInt32 nColor) const;
157 
163 
165  {
166  OdInt32 m_fitColors[4];
167  OdInt32 m_pattern[4];
168  };
169 
178  protected:
179  void validate();
180 };
181 
188 {
189  protected:
194  public:
195  OdGiGrayRamp(OdInt32 nGridDivs = 2, float fIntensity = 1.0f, OdInt32 nBaseOffset = 0)
196  : m_nBaseOffset(nBaseOffset)
197  , m_nGridDivs(nGridDivs)
198  , m_fIntensity(fIntensity)
199  {
200  validate();
201  }
202 
206  OdInt32 baseOffset() const { return m_nBaseOffset; }
210  OdInt32 gridDivisions() const { return m_nGridDivs; }
214  float intensity() const { return m_fIntensity; }
218  OdInt32 dimension() const { return m_nDim; }
219 
224  ODCOLORREF color(OdInt32 nColor) const;
225 
231  protected:
232  void validate();
233 };
234 
241 {
242  protected:
243  struct PalEntry
244  {
247  };
249  protected:
253  public:
255  : m_palette(256, 1)
256  {
257  initPalette();
258  }
259 
264  ODCOLORREF color(OdUInt32 nColor) const
265  {
266  return m_palette[nColor].m_color;
267  }
273  {
274  return m_palette[nColor].m_entryHelper;
275  }
276 
282  void setColor(OdUInt32 nColor, ODCOLORREF color)
283  {
284  m_palette[nColor].m_color = color;
285  }
291  void setEntryHelper(OdUInt32 nColor, OdInt32 entryHelper)
292  {
293  m_palette[nColor].m_entryHelper = entryHelper;
294  }
295 
299  const OdGiColorCube *colorCube() const
300  {
301  return m_pColorCube.get();
302  }
306  void setColorCube(const OdGiColorCube &colorCube)
307  {
308  resetColorCube(new OdGiColorCube(colorCube));
309  }
314  {
315  resetColorCube(NULL);
316  }
317 
321  const OdGiGrayRamp *grayRamp() const
322  {
323  return m_pGrayRamp.get();
324  }
328  void setGrayRamp(const OdGiGrayRamp &grayRamp)
329  {
330  resetGrayRamp(new OdGiGrayRamp(grayRamp));
331  }
336  {
337  resetGrayRamp(NULL);
338  }
339 
344  bool install(const OdGiColorCube &cb);
349  bool install(const OdGiGrayRamp &gr);
354  bool install(const OdGiPalette &pal2);
355 
361  OdInt32 closestMatch(ODCOLORREF cref, bool bThroughPal = false) const;
362 
368 
373  bool isEqualTo(const OdGiPalette &pal2) const;
378  bool remove(const OdGiPalette &pal2);
379 
383  void clear();
384  protected:
385  void initPalette();
386 
387  void resetColorCube(OdGiColorCube *pColorCube);
388  void resetGrayRamp(OdGiGrayRamp *pGrayRamp);
389 
390  void setColor(OdInt32 nColor, ODCOLORREF color);
391 };
392 
393 #include "TD_PackPop.h"
394 
395 #endif //#ifndef __ODGIPALETTE_H__
#define ODGI_EXPORT
Definition: GiExport.h:35
#define NULL
Definition: GsProperties.h:177
#define ODGETBLUE(rgb)
Definition: OdPlatform.h:889
#define ODRGB(r, g, b)
Definition: OdPlatform.h:884
#define ODCOLORREF
Definition: OdPlatform.h:883
#define ODGETGREEN(rgb)
Definition: OdPlatform.h:888
#define ODGETRED(rgb)
Definition: OdPlatform.h:887
unsigned int OdUInt32
int OdInt32
float intensity() const
Definition: GiPalette.h:138
float m_fIntensity
Definition: GiPalette.h:114
OdInt32 baseOffset() const
Definition: GiPalette.h:130
OdInt32 m_nGridSize
Definition: GiPalette.h:115
OdGiIntRGB m_nDims
Definition: GiPalette.h:117
const OdGiIntRGB & gridDivisions() const
Definition: GiPalette.h:134
OdGiIntRGB m_nOffsets
Definition: GiPalette.h:116
const OdGiIntRGB & dimensions() const
Definition: GiPalette.h:150
ODCOLORREF color(OdInt32 nColor) const
OdInt32 closestMatch(ODCOLORREF cref) const
OdGiColorCube(OdGiIntRGB nGridDivs=OdGiIntRGB(2, 2, 2), float fIntensity=1.0f, OdInt32 nBaseOffset=0)
Definition: GiPalette.h:119
const OdGiIntRGB & offsets() const
Definition: GiPalette.h:146
OdGiIntRGB m_nGridDivs
Definition: GiPalette.h:113
OdInt32 ditheredMatch(ODCOLORREF cref, DtMatchResult &results) const
OdInt32 gridSize() const
Definition: GiPalette.h:142
OdInt32 m_nBaseOffset
Definition: GiPalette.h:112
float m_fIntensity
Definition: GiPalette.h:192
float intensity() const
Definition: GiPalette.h:214
OdInt32 m_nBaseOffset
Definition: GiPalette.h:190
OdInt32 m_nDim
Definition: GiPalette.h:193
void validate()
OdGiGrayRamp(OdInt32 nGridDivs=2, float fIntensity=1.0f, OdInt32 nBaseOffset=0)
Definition: GiPalette.h:195
OdInt32 dimension() const
Definition: GiPalette.h:218
OdInt32 m_nGridDivs
Definition: GiPalette.h:191
OdInt32 gridDivisions() const
Definition: GiPalette.h:210
ODCOLORREF color(OdInt32 nColor) const
OdInt32 closestMatch(ODCOLORREF cref) const
OdInt32 baseOffset() const
Definition: GiPalette.h:206
void setColor(OdInt32 nColor, ODCOLORREF color)
void setColor(OdUInt32 nColor, ODCOLORREF color)
Definition: GiPalette.h:282
void resetGrayRamp(OdGiGrayRamp *pGrayRamp)
OdInt32 firstAvailableBlock(OdInt32 blockSize) const
bool remove(const OdGiPalette &pal2)
OdSharedPtr< OdGiGrayRamp > m_pGrayRamp
Definition: GiPalette.h:252
PalEntryArray m_palette
Definition: GiPalette.h:250
OdSharedPtr< OdGiColorCube > m_pColorCube
Definition: GiPalette.h:251
void clear()
OdInt32 entryHelper(OdUInt32 nColor) const
Definition: GiPalette.h:272
OdArray< PalEntry, OdMemoryAllocator< PalEntry > > PalEntryArray
Definition: GiPalette.h:248
void resetColorCube(OdGiColorCube *pColorCube)
void setGrayRamp(const OdGiGrayRamp &grayRamp)
Definition: GiPalette.h:328
void initPalette()
ODCOLORREF color(OdUInt32 nColor) const
Definition: GiPalette.h:264
bool install(const OdGiColorCube &cb)
void resetColorCube()
Definition: GiPalette.h:313
void setEntryHelper(OdUInt32 nColor, OdInt32 entryHelper)
Definition: GiPalette.h:291
const OdGiColorCube * colorCube() const
Definition: GiPalette.h:299
OdInt32 closestMatch(ODCOLORREF cref, bool bThroughPal=false) const
const OdGiGrayRamp * grayRamp() const
Definition: GiPalette.h:321
bool isEqualTo(const OdGiPalette &pal2) const
void resetGrayRamp()
Definition: GiPalette.h:335
bool install(const OdGiPalette &pal2)
bool install(const OdGiGrayRamp &gr)
void setColorCube(const OdGiColorCube &colorCube)
Definition: GiPalette.h:306
T * get()
Definition: SharedPtr.h:134
ODCOLORREF color() const
Definition: GiPalette.h:98
void setRed(OdInt32 _r)
Definition: GiPalette.h:68
OdGiIntRGB(OdInt32 _r, OdInt32 _g, OdInt32 _b)
Definition: GiPalette.h:42
OdInt32 b
Definition: GiPalette.h:40
void setColor(ODCOLORREF cref)
Definition: GiPalette.h:91
OdInt32 blue() const
Definition: GiPalette.h:62
void setGreen(OdInt32 _g)
Definition: GiPalette.h:73
OdGiIntRGB(ODCOLORREF cref)
Definition: GiPalette.h:46
OdInt32 r
Definition: GiPalette.h:40
OdInt32 green() const
Definition: GiPalette.h:58
void setBlue(OdInt32 _b)
Definition: GiPalette.h:78
OdGiIntRGB()
Definition: GiPalette.h:45
OdInt32 red() const
Definition: GiPalette.h:54
OdInt32 g
Definition: GiPalette.h:40
void setRGB(OdInt32 _r, OdInt32 _g, OdInt32 _b)
Definition: GiPalette.h:85
Definition: GiPalette.h:244
ODCOLORREF m_color
Definition: GiPalette.h:245
OdInt32 m_entryHelper
Definition: GiPalette.h:246