CFx SDK Documentation 2026 SP0
Loading...
Searching...
No Matches
GiPalette.h
Go to the documentation of this file.
1
2// Copyright (C) 2002-2024, 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 Open Design Alliance software pursuant to a license
16// agreement with Open Design Alliance.
17// Open Design Alliance Copyright (C) 2002-2024 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 "StaticRxObject.h"
32
39{
46
55 : r(_r), g(_g), b(_b)
56 { }
57
62 : r(0), g(0), b(0)
63 { }
64
65
72 {
73 setColor(cref);
74 }
75
79 OdInt32 red() const { return r; }
83 OdInt32 green() const { return g; }
87 OdInt32 blue() const { return b; }
88
93 void setRed(OdInt32 _r) { r = _r; }
98 void setGreen(OdInt32 _g) { g = _g; }
103 void setBlue(OdInt32 _b) { b = _b; }
110 void setRGB(OdInt32 _r, OdInt32 _g, OdInt32 _b) { r = _r; g = _g; b = _b; }
111
117 {
118 setRGB((OdInt32)ODGETRED(cref), (OdInt32)ODGETGREEN(cref), (OdInt32)ODGETBLUE(cref));
119 }
120
124 {
125 return ODRGB(r, g, b);
126 }
127};
128
135{
136 protected:
143 protected:
144 virtual bool isDynamic() const { return false; }
145 public:
146 OdGiColorCube(OdGiIntRGB nGridDivs = OdGiIntRGB(2, 2, 2), float fIntensity = 1.0f, OdInt32 nBaseOffset = 0)
147 : m_nBaseOffset(nBaseOffset)
148 , m_nGridDivs(nGridDivs)
149 , m_fIntensity(fIntensity)
150 {
151 validate();
152 }
153 static OdSmartPtr<OdGiColorCube> createDynamic(OdGiIntRGB nGridDivs = OdGiIntRGB(2, 2, 2), float fIntensity = 1.0f, OdInt32 nBaseOffset = 0);
154
155 virtual OdRxObjectPtr clone() const;
156 OdSmartPtr<OdGiColorCube> cloneIfNeed() const { if (!isDynamic()) return clone(); return this; }
157
161 OdInt32 baseOffset() const { return m_nBaseOffset; }
165 const OdGiIntRGB &gridDivisions() const { return m_nGridDivs; }
169 float intensity() const { return m_fIntensity; }
173 OdInt32 gridSize() const { return m_nGridSize; }
177 const OdGiIntRGB &offsets() const { return m_nOffsets; }
181 const OdGiIntRGB &dimensions() const { return m_nDims; }
182
187 ODCOLORREF color(OdInt32 nColor) const;
188
194
200
209 protected:
210 void validate();
211};
212
217
223class ODGI_EXPORT OdGiGrayRamp : public OdStaticRxObject<OdRxObject>
224{
225 protected:
230 protected:
231 virtual bool isDynamic() const { return false; }
232 public:
233 OdGiGrayRamp(OdInt32 nGridDivs = 2, float fIntensity = 1.0f, OdInt32 nBaseOffset = 0)
234 : m_nBaseOffset(nBaseOffset)
235 , m_nGridDivs(nGridDivs)
236 , m_fIntensity(fIntensity)
237 {
238 validate();
239 }
240 static OdSmartPtr<OdGiGrayRamp> createDynamic(OdInt32 nGridDivs = 2, float fIntensity = 1.0f, OdInt32 nBaseOffset = 0);
241
242 virtual OdRxObjectPtr clone() const;
243 OdSmartPtr<OdGiGrayRamp> cloneIfNeed() const { if (!isDynamic()) return clone(); return this; }
244
248 OdInt32 baseOffset() const { return m_nBaseOffset; }
256 float intensity() const { return m_fIntensity; }
260 OdInt32 dimension() const { return m_nDim; }
261
266 ODCOLORREF color(OdInt32 nColor) const;
267
273 protected:
274 void validate();
275};
276
281
287class ODGI_EXPORT OdGiPalette : public OdStaticRxObject<OdRxObject>
288{
289 protected:
294 public:
296 {
300 Addressation(OdInt32 nFrom = 0, OdInt32 nTo = 0, OdInt32 nNum = 256)
301 : m_nSrcFrom(nFrom), m_nDstTo(nTo), m_nNumColors(nNum)
302 {}
303 bool validate() const { return ((m_nSrcFrom + m_nNumColors) <= 256) && ((m_nDstTo + m_nNumColors) <= 256); }
304 bool fullRange() const { return (m_nSrcFrom == 0) && (m_nDstTo == 0) && (m_nNumColors == 256); }
305 };
306 protected:
307 virtual bool isDynamic() const { return false; }
308 public:
313 {
314 initPalette();
315 }
316
324
325 OdGiPalette& operator= (const OdGiPalette & obj);
326
327 virtual OdRxObjectPtr clone() const;
328 OdSmartPtr<OdGiPalette> cloneIfNeed() const { if (!isDynamic()) return clone(); return this; }
329
335 {
336 return m_colors[nColor];
337 }
338
342 bool entryActivity(OdInt32 nColor) const
343 {
344 return GETBIT(m_activities[nColor >> 6], 1ULL << (OdUInt64(nColor) & 63));
345 }
346
353 {
354 m_colors[nColor] = color;
355 }
356
361 void setEntryActivity(OdInt32 nColor, bool bActivity)
362 {
363 SETBIT(m_activities[nColor >> 6], 1ULL << (OdUInt64(nColor) & 63), bActivity);
364 }
365
369 const ODCOLORREF *asArray() const
370 {
371 return m_colors;
372 }
373
378 {
379 return m_pColorCube.get();
380 }
381
384 void setColorCube(const OdGiColorCube *pColorCube)
385 {
386 resetColorCube(pColorCube);
387 }
388
392 {
393 resetColorCube(NULL);
394 }
395
399 const OdGiGrayRamp *grayRamp() const
400 {
401 return m_pGrayRamp.get();
402 }
403
406 void setGrayRamp(const OdGiGrayRamp *pGrayRamp)
407 {
408 resetGrayRamp(pGrayRamp);
409 }
410
414 {
415 resetGrayRamp(NULL);
416 }
417
423 bool install(const OdGiColorCube *pColorCube, bool bForceUpdate = false);
429 bool install(const OdGiGrayRamp *pGrayRamp, bool bForceUpdate = false);
435 bool install(const OdGiPalette *pPalette, bool bForceUpdate = false, const Addressation &address = Addressation());
442 bool install(ODCOLORREF const *const pColors, bool bForceUpdate = false, const Addressation &address = Addressation());
443
449 OdInt32 closestMatch(ODCOLORREF cref, bool bThroughPal = false) const;
450
456
462 bool isEqualTo(const OdGiPalette *pPalette, const Addressation &address = Addressation()) const;
468 bool remove(const OdGiPalette *pPalette, bool bForceUpdate = false, const Addressation &address = Addressation());
469
473 void clear();
474 protected:
476
477 void resetColorCube(const OdGiColorCube *pColorCube);
478 void resetGrayRamp(const OdGiGrayRamp *pGrayRamp);
479
481 {
482 m_colors[nColor] = color;
483 setEntryActivity(nColor, true);
484 }
485};
486
491
492// Forward declaration
494
528
529#include "TD_PackPop.h"
530
531#endif //#ifndef __ODGIPALETTE_H__
#define ODGI_EXPORT
Definition GiExport.h:35
OdSmartPtr< OdGiColorCube > OdGiColorCubePtr
Definition GiPalette.h:216
OdSmartPtr< OdGiPalette > OdGiPalettePtr
Definition GiPalette.h:490
OdSmartPtr< OdGiGrayRamp > OdGiGrayRampPtr
Definition GiPalette.h:280
#define ODGETBLUE(rgb)
#define ODRGB(r, g, b)
#define ODCOLORREF
#define ODGETGREEN(rgb)
#define ODGETRED(rgb)
int OdInt32
#define SETBIT(flags, bit, value)
Definition OdaDefs.h:516
#define GETBIT(flags, bit)
Definition OdaDefs.h:517
float intensity() const
Definition GiPalette.h:169
OdSmartPtr< OdGiColorCube > cloneIfNeed() const
Definition GiPalette.h:156
float m_fIntensity
Definition GiPalette.h:139
OdInt32 baseOffset() const
Definition GiPalette.h:161
OdInt32 m_nGridSize
Definition GiPalette.h:140
OdGiIntRGB m_nDims
Definition GiPalette.h:142
static OdSmartPtr< OdGiColorCube > createDynamic(OdGiIntRGB nGridDivs=OdGiIntRGB(2, 2, 2), float fIntensity=1.0f, OdInt32 nBaseOffset=0)
OdGiIntRGB m_nOffsets
Definition GiPalette.h:141
virtual bool isDynamic() const
Definition GiPalette.h:144
ODCOLORREF color(OdInt32 nColor) const
OdInt32 closestMatch(ODCOLORREF cref) const
const OdGiIntRGB & offsets() const
Definition GiPalette.h:177
OdGiColorCube(OdGiIntRGB nGridDivs=OdGiIntRGB(2, 2, 2), float fIntensity=1.0f, OdInt32 nBaseOffset=0)
Definition GiPalette.h:146
const OdGiIntRGB & dimensions() const
Definition GiPalette.h:181
virtual OdRxObjectPtr clone() const
OdGiIntRGB m_nGridDivs
Definition GiPalette.h:138
OdInt32 ditheredMatch(ODCOLORREF cref, DtMatchResult &results) const
const OdGiIntRGB & gridDivisions() const
Definition GiPalette.h:165
OdInt32 gridSize() const
Definition GiPalette.h:173
OdInt32 m_nBaseOffset
Definition GiPalette.h:137
float m_fIntensity
Definition GiPalette.h:228
float intensity() const
Definition GiPalette.h:256
OdInt32 m_nBaseOffset
Definition GiPalette.h:226
OdInt32 m_nDim
Definition GiPalette.h:229
void validate()
virtual OdRxObjectPtr clone() const
OdGiGrayRamp(OdInt32 nGridDivs=2, float fIntensity=1.0f, OdInt32 nBaseOffset=0)
Definition GiPalette.h:233
static OdSmartPtr< OdGiGrayRamp > createDynamic(OdInt32 nGridDivs=2, float fIntensity=1.0f, OdInt32 nBaseOffset=0)
OdInt32 dimension() const
Definition GiPalette.h:260
OdSmartPtr< OdGiGrayRamp > cloneIfNeed() const
Definition GiPalette.h:243
OdInt32 m_nGridDivs
Definition GiPalette.h:227
OdInt32 gridDivisions() const
Definition GiPalette.h:252
ODCOLORREF color(OdInt32 nColor) const
OdInt32 closestMatch(ODCOLORREF cref) const
virtual bool isDynamic() const
Definition GiPalette.h:231
OdInt32 baseOffset() const
Definition GiPalette.h:248
void setColorCube(const OdGiColorCube *pColorCube)
Definition GiPalette.h:384
bool install(ODCOLORREF const *const pColors, bool bForceUpdate=false, const Addressation &address=Addressation())
void setColor(OdInt32 nColor, ODCOLORREF color)
Definition GiPalette.h:352
OdUInt64 m_activities[4]
Definition GiPalette.h:291
void setColorImpl(OdInt32 nColor, ODCOLORREF color)
Definition GiPalette.h:480
void setGrayRamp(const OdGiGrayRamp *pGrayRamp)
Definition GiPalette.h:406
const OdGiGrayRamp * grayRamp() const
Definition GiPalette.h:399
OdInt32 firstAvailableBlock(OdInt32 blockSize) const
virtual bool isDynamic() const
Definition GiPalette.h:307
const OdGiColorCube * colorCube() const
Definition GiPalette.h:377
static OdSmartPtr< OdGiPalette > createDynamic()
bool entryActivity(OdInt32 nColor) const
Definition GiPalette.h:342
OdGiPalette(const OdGiPalette &obj)
void clear()
OdSmartPtr< OdGiPalette > cloneIfNeed() const
Definition GiPalette.h:328
void setEntryActivity(OdInt32 nColor, bool bActivity)
Definition GiPalette.h:361
bool install(const OdGiPalette *pPalette, bool bForceUpdate=false, const Addressation &address=Addressation())
void initPalette()
void resetGrayRamp(const OdGiGrayRamp *pGrayRamp)
ODCOLORREF m_colors[256]
Definition GiPalette.h:290
void resetColorCube()
Definition GiPalette.h:391
OdGiColorCubePtr m_pColorCube
Definition GiPalette.h:292
OdGiGrayRampPtr m_pGrayRamp
Definition GiPalette.h:293
OdInt32 closestMatch(ODCOLORREF cref, bool bThroughPal=false) const
ODCOLORREF color(OdInt32 nColor) const
Definition GiPalette.h:334
bool install(const OdGiColorCube *pColorCube, bool bForceUpdate=false)
bool remove(const OdGiPalette *pPalette, bool bForceUpdate=false, const Addressation &address=Addressation())
void resetGrayRamp()
Definition GiPalette.h:413
const ODCOLORREF * asArray() const
Definition GiPalette.h:369
void resetColorCube(const OdGiColorCube *pColorCube)
virtual OdRxObjectPtr clone() const
bool install(const OdGiGrayRamp *pGrayRamp, bool bForceUpdate=false)
bool isEqualTo(const OdGiPalette *pPalette, const Addressation &address=Addressation()) const
OdGiSubEntityTraits * m_pTraits
Definition GiPalette.h:506
OdGiPaletteOverrideHelper(OdGiSubEntityTraits &pTraits, const OdGiPalette &pOverride)
Definition GiPalette.h:519
void setPaletteOverride(OdGiSubEntityTraits &pTraits, const OdGiPalette &pOverride)
ODCOLORREF color() const
Definition GiPalette.h:123
void setRed(OdInt32 _r)
Definition GiPalette.h:93
OdGiIntRGB(OdInt32 _r, OdInt32 _g, OdInt32 _b)
Definition GiPalette.h:54
OdInt32 b
Definition GiPalette.h:45
void setColor(ODCOLORREF cref)
Definition GiPalette.h:116
OdInt32 blue() const
Definition GiPalette.h:87
void setGreen(OdInt32 _g)
Definition GiPalette.h:98
OdGiIntRGB(ODCOLORREF cref)
Definition GiPalette.h:71
OdInt32 r
Definition GiPalette.h:41
OdInt32 green() const
Definition GiPalette.h:83
void setBlue(OdInt32 _b)
Definition GiPalette.h:103
OdInt32 red() const
Definition GiPalette.h:79
OdInt32 g
Definition GiPalette.h:43
void setRGB(OdInt32 _r, OdInt32 _g, OdInt32 _b)
Definition GiPalette.h:110
Addressation(OdInt32 nFrom=0, OdInt32 nTo=0, OdInt32 nNum=256)
Definition GiPalette.h:300