OWLNext    7.0
Borland's Object Windows Library for the modern age
Loading...
Searching...
No Matches
owl::TPalette Class Reference

TPalette is the GDI Palette class derived from TGdiObject. More...

#include <owl/gdiobjec.h>

Inheritance diagram for owl::TPalette:
owl::TGdiObject owl::TGdiBase owl::THalftonePalette owl::TIdentityPalette

Public Types

typedef HPALETTE THandle
 TPalette encapsulates an HPALETTE.
 
- Public Types inherited from owl::TGdiObject
enum  TType { None , Pen , Brush , Font , Palette , Bitmap , TextBrush }
 This enumeration is used to store the object type in the struct TObjInfo. More...
 
typedef HGDIOBJ THandle
 TGdiObject encapsulates an HGDIOBJ.
 

Public Member Functions

 TPalette (HPALETTE handle, TAutoDelete autoDelete=NoAutoDelete)
 Alias an existing palette handle. Assume ownership if autoDelete says so.
 
 TPalette (const TClipboard &)
 Creates a TPalette object with values taken from the given clipboard.
 
 TPalette (const TPalette &src)
 Deep copy whole palette.
 
 TPalette (const LOGPALETTE &logPalette)
 Creates a TPalette object from the given LOGPALETTE.
 
 TPalette (const PALETTEENTRY *entries, int count)
 Creates a TPalette object with count entries from the given entries array.
 
 TPalette (const BITMAPINFO &info, uint flags=0)
 Win 3.0 DIB hdr.
 
 TPalette (const TDib &dib, uint flags=0)
 DIB object.
 
 TPalette (const tchar *fileName)
 read from file: *.dib,*.bmp,*.pal,*.aco,*.act
 
template<size_t N>
 TPalette (const PALETTEENTRY(&entries)[N])
 Creates a TPalette object with the entries from the given array.
 
HPALETTE GetHandle () const
 Returns the handle of the palette.
 
 operator HPALETTE () const
 Typecasting operator.
 
bool ResizePalette (uint numEntries)
 Changes the size of this logical palette to the number given by numEntries.
 
void AnimatePalette (uint start, uint count, const PALETTEENTRY *entries)
 Animate palette from entry 'start' for 'count' entries.
 
uint SetPaletteEntries (uint16 start, uint16 count, const PALETTEENTRY *entries)
 Sets the RGB color values in this palette from the entries array of PALETTEENTRY structures.
 
uint SetPaletteEntry (uint16 index, const PALETTEENTRY &entry)
 Sets the RGB color value at index in this palette from the entry argument.
 
uint GetPaletteEntries (uint16 start, uint16 count, PALETTEENTRY *entries) const
 Retrieves a range of entries in this logical palette and places them in the entries array.
 
uint GetPaletteEntry (uint16 index, PALETTEENTRY &entry) const
 Retrieves the entry in this logical palette at index and places it in the entries array.
 
uint GetNearestPaletteIndex (const TColor &color) const
 Returns the index of the color entry that represents the closest color in this palette to the given color.
 
bool GetObject (uint16 &numEntries) const
 Finds the number of entries in this logical palette and sets the value in the numEntries argument.
 
uint16 GetNumEntries () const
 Returns the number of entries in this palette, or 0 if the call fails.
 
void ToClipboard (TClipboard &Clipboard)
 Moves this palette to the target Clipboard argument.
 
bool UnrealizeObject ()
 Directs the GDI to completely remap the logical palette to the system palette on the next RealizePalette(HDC) or TDC::RealizePalette call.
 
bool Write (const tchar *fileName)
 Write this palette into file: *.dib,*.bmp,*.pal,*.aco,*.act.
 
- Public Member Functions inherited from owl::TGdiObject
 ~TGdiObject ()
 Decrement the reference count on this object.
 
HGDIOBJ GetGdiHandle () const
 Returns the handle of the GDI object.
 
 operator HGDIOBJ () const
 Typecasting operator that converts this GDI object handle to type HGDIOBJ.
 
int GetObject (int count, void *object) const
 Retrieve the object's attributes into a buffer.
 
bool operator== (const TGdiObject &other) const
 Returns true if the handles are equal. This is a binary compare.
 
bool operator< (const TGdiObject &other) const
 not implemented just to make happy STL
 
bool IsGDIObject () const
 Returns true if this represents a real GDI object.
 
uint32 GetObjectType () const
 Returns the type of the GDI object.
 
auto IsHandleOwner () const -> bool
 Returns true if handle lifetime is managed.
 

Protected Member Functions

void Create (const BITMAPINFO *info, uint flags)
 Accept a pointer to a BITMAPINFO structure and create a GDI logical palette from the color table which follows it, for 2, 16 and 256 color bitmaps.
 
bool Read (const tchar *fileName)
 Read palette from file.
 
bool Read_PAL (TRiffFile &file)
 Read Microsoft palette from file.
 
bool Write_PAL (TRiffFile &file)
 Write Microsoft palette to file.
 
bool Read_ACO (TRiffFile &file)
 Read Adobe palette from file.
 
bool Write_ACO (TRiffFile &file)
 Write Adobe palette to file.
 
bool Read_ACT (TRiffFile &file)
 Read Adobe palette from file.
 
bool Write_ACT (TRiffFile &file)
 Write Adobe palette to file.
 
bool Read_BMP (TRiffFile &file)
 Read palette from BMP file.
 
bool Write_BMP (TRiffFile &file)
 Write palette to BMP 1x1 file.
 
- Protected Member Functions inherited from owl::TGdiObject
 TGdiObject ()
 This default constructor sets Handle to 0 and ShouldDelete to true.
 
 TGdiObject (HANDLE handle, TAutoDelete autoDelete=NoAutoDelete)
 Create a wrapper for a given GDI object.
 
void CheckValid (uint resId=IDS_GDIFAILURE)
 

Additional Inherited Members

- Static Public Member Functions inherited from owl::TGdiObject
static TObjInfo * RefFind (HANDLE object)
 Searches for the given object handle.
 
static void RefAdd (HANDLE handle, TType type)
 RefAdd adds a reference entry for the object with the given handle and type.
 
static void RefRemove (HANDLE handle)
 Removes the reference entry to the object with the given handle.
 
static void RefInc (HANDLE handle)
 Increments by 1 the reference count of the object associated with the given handle.
 
static void RefDec (HANDLE handle, bool wantDelete)
 Decrements this object's reference count by 1 and deletes the object when the reference count reaches zero.
 
static int RefCount (HANDLE handle)
 Returns this object's current reference count or -1 if the object is not found.
 
- Static Protected Member Functions inherited from owl::TGdiObject
static void _CheckValid (HANDLE handle, uint resId=IDS_GDIFAILURE)
 
- Protected Attributes inherited from owl::TGdiObject
HANDLE Handle
 GDI handle of this object.
 
bool ShouldDelete
 Should object delete GDI handle in dtor?
 

Detailed Description

TPalette is the GDI Palette class derived from TGdiObject.

The TPalette constructors can create palettes from explicit information or indirectly from various color table types that are used by DIBs.

Definition at line 413 of file gdiobjec.h.

Member Typedef Documentation

◆ THandle

TPalette encapsulates an HPALETTE.

Definition at line 417 of file gdiobjec.h.

Constructor & Destructor Documentation

◆ TPalette() [1/9]

owl::TPalette::TPalette ( HPALETTE handle,
TAutoDelete autoDelete = NoAutoDelete )

Alias an existing palette handle. Assume ownership if autoDelete says so.

Creates a TPalette object and sets the Handle data member to the given borrowed handle. The ShouldDelete data member defaults to false, ensuring that the borrowed handle will not be deleted when the C++ object is destroyed.

Definition at line 40 of file palette.cpp.

References owl::TGdiObject::Handle, owl::TGdiObject::Palette, owl::TGdiObject::RefAdd(), and owl::TGdiObject::ShouldDelete.

◆ TPalette() [2/9]

owl::TPalette::TPalette ( const TClipboard & clipboard)

Creates a TPalette object with values taken from the given clipboard.

Definition at line 51 of file palette.cpp.

References owl::TGdiObject::CheckValid(), owl::TGdiObject::Handle, owl::TGdiObject::Palette, owl::TGdiObject::RefAdd(), owl::TGdiObject::RefInc(), and WARNX.

◆ TPalette() [3/9]

owl::TPalette::TPalette ( const TPalette & src)

Deep copy whole palette.

This public copy constructor creates a complete copy of the given palette object as in TPalette myPalette = yourPalette;.

Always performs full, deep object copy

Definition at line 67 of file palette.cpp.

References owl::TGdiObject::CheckValid(), owl::TGdiObject::Handle, owl::TGdiObject::Palette, owl::TGdiObject::RefAdd(), and WARNX.

◆ TPalette() [4/9]

owl::TPalette::TPalette ( const LOGPALETTE & logPalette)

Creates a TPalette object from the given LOGPALETTE.

Definition at line 92 of file palette.cpp.

References owl::TGdiObject::CheckValid(), owl::TGdiObject::Handle, owl::TGdiObject::Palette, owl::TGdiObject::RefAdd(), and WARNX.

◆ TPalette() [5/9]

owl::TPalette::TPalette ( const PALETTEENTRY * entries,
int count )

Creates a TPalette object with count entries from the given entries array.

Definition at line 120 of file palette.cpp.

◆ TPalette() [6/9]

owl::TPalette::TPalette ( const BITMAPINFO & info,
uint flags = 0 )

Win 3.0 DIB hdr.

Creates a TPalette object from the color table following the given BITMAPINFO structure.

This constructor works only for 2-color, 16-color, and 256-color bitmaps. A handle with value 0 (zero) is returned for other bitmaps, including 24-bit DIBs.

Definition at line 151 of file palette.cpp.

References Create().

◆ TPalette() [7/9]

owl::TPalette::TPalette ( const TDib & dib,
uint flags = 0 )

DIB object.

Creates a TPalette object from the given DIB object.

The flags argument represents the values of the LOGPALETTE data structure used to create the palette.

Definition at line 177 of file palette.cpp.

References Create().

◆ TPalette() [8/9]

owl::TPalette::TPalette ( const tchar * fileName)

read from file: *.dib,*.bmp,*.pal,*.aco,*.act

Read from file: *.dib,*.bmp,*.pal,*.aco,*.act.

Definition at line 185 of file palette.cpp.

References owl::TGdiObject::CheckValid(), owl::TGdiObject::Handle, owl::TGdiObject::Palette, PRECONDITION, Read(), owl::TGdiObject::RefAdd(), owl::TGdiObject::ShouldDelete, and WARNX.

◆ TPalette() [9/9]

template<size_t N>
owl::TPalette::TPalette ( const PALETTEENTRY(&) entries[N])
inline

Creates a TPalette object with the entries from the given array.

Definition at line 434 of file gdiobjec.h.

Member Function Documentation

◆ AnimatePalette()

void owl::TPalette::AnimatePalette ( uint start,
uint count,
const PALETTEENTRY * entries )
inline

Animate palette from entry 'start' for 'count' entries.

Replaces entries in this logical palette from the entries array of PALETTEENTRY structures. The parameter start specifies the first entry to be animated, and count gives the number of entries to be animated. The new entries are mapped into the system palette immediately.

Definition at line 1263 of file gdiobjec.h.

References AnimatePalette(), and GetHandle().

◆ Create()

void owl::TPalette::Create ( const BITMAPINFO * info,
uint flags )
protected

Accept a pointer to a BITMAPINFO structure and create a GDI logical palette from the color table which follows it, for 2, 16 and 256 color bitmaps.

Fail for all others, including 24-bit DIB's

!CQ Don't fail for other formats!?

Definition at line 207 of file palette.cpp.

References owl::TGdiObject::CheckValid(), owl::TGdiObject::Handle, owl::NColors(), owl::TGdiObject::Palette, PRECONDITION, owl::TGdiObject::RefAdd(), and WARNX.

◆ GetHandle()

HPALETTE owl::TPalette::GetHandle ( ) const
inline

Returns the handle of the palette.

Definition at line 1222 of file gdiobjec.h.

References owl::TGdiObject::GetGdiHandle().

◆ GetNearestPaletteIndex()

uint owl::TPalette::GetNearestPaletteIndex ( const TColor & color) const
inline

Returns the index of the color entry that represents the closest color in this palette to the given color.

Definition at line 1325 of file gdiobjec.h.

References GetHandle().

◆ GetNumEntries()

uint16 owl::TPalette::GetNumEntries ( ) const
inline

Returns the number of entries in this palette, or 0 if the call fails.

Definition at line 1344 of file gdiobjec.h.

References owl::TGdiObject::GetObject().

◆ GetObject()

bool owl::TPalette::GetObject ( uint16 & numEntries) const
inline

Finds the number of entries in this logical palette and sets the value in the numEntries argument.

To find the entire LOGPALETTE structure, use GetPaletteEntries. Returns true if the call is successful; otherwise returns false.

Definition at line 1336 of file gdiobjec.h.

References owl::TGdiObject::GetObject().

◆ GetPaletteEntries()

uint owl::TPalette::GetPaletteEntries ( uint16 start,
uint16 count,
PALETTEENTRY * entries ) const
inline

Retrieves a range of entries in this logical palette and places them in the entries array.

The start parameter specifies the first entry to be retrieved, and count gives the number of entries to be retrieved. Returns the number of entries actually retrieved, or 0 if the call fails.

Definition at line 1306 of file gdiobjec.h.

References GetHandle().

◆ GetPaletteEntry()

uint owl::TPalette::GetPaletteEntry ( uint16 index,
PALETTEENTRY & entry ) const
inline

Retrieves the entry in this logical palette at index and places it in the entries array.

Returns the number of entries actually retrieved: 1 if successful or 0 if the call fails.

Definition at line 1316 of file gdiobjec.h.

References GetHandle().

◆ operator HPALETTE()

owl::TPalette::operator HPALETTE ( ) const
inline

Typecasting operator.

Converts this palette's Handle to type HPALETTE, which is the data type representing the handle to a logical palette.

Definition at line 1231 of file gdiobjec.h.

◆ Read()

bool owl::TPalette::Read ( const tchar * fileName)
protected

Read palette from file.

Definition at line 263 of file palette.cpp.

References _T, _tcsicmp, _tcsrchr, Read_ACO(), Read_ACT(), Read_BMP(), and Read_PAL().

◆ Read_ACO()

bool owl::TPalette::Read_ACO ( TRiffFile & file)
protected

Read Adobe palette from file.

Read Adobe Photoshop *.ACO color table.

return true if success

Definition at line 505 of file palette.cpp.

References owl::boBig_Endian, CMYK, owl::TGdiObject::Handle, owl::HSL_to_RGB(), owl::TXBadFormat::Raise(), TRACEX, and WARNX.

◆ Read_ACT()

bool owl::TPalette::Read_ACT ( TRiffFile & file)
protected

Read Adobe palette from file.

Read Adobe Photoshop *.ACT color table.

return true if success

Definition at line 674 of file palette.cpp.

References owl::TGdiObject::Handle, TFILE_ERROR, and WARNX.

◆ Read_BMP()

bool owl::TPalette::Read_BMP ( TRiffFile & file)
protected

Read palette from BMP file.

Read color table from *.DIB.

return true if success

Definition at line 737 of file palette.cpp.

References owl::TGdiObject::Handle, owl::NColors(), owl::TXBadFormat::Raise(), TFILE_ERROR, and WARNX.

◆ Read_PAL()

bool owl::TPalette::Read_PAL ( TRiffFile & file)
protected

Read Microsoft palette from file.

read Microsoft *.pal format, return true if success

Definition at line 325 of file palette.cpp.

References owl::boLittle_Endian, owl::TRiffFile::ffFindChunk, owl::TRiffFile::ffFindRiff, owl::TGdiObject::Handle, owlFCC, owl::TXBadFormat::Raise(), TFILE_ERROR, and WARNX.

◆ ResizePalette()

bool owl::TPalette::ResizePalette ( uint numEntries)
inline

Changes the size of this logical palette to the number given by numEntries.

Returns true if the call is successful; otherwise returns false.

Definition at line 1250 of file gdiobjec.h.

References GetHandle().

◆ SetPaletteEntries()

uint owl::TPalette::SetPaletteEntries ( uint16 start,
uint16 count,
const PALETTEENTRY * entries )
inline

Sets the RGB color values in this palette from the entries array of PALETTEENTRY structures.

The start parameter specifies the first entry to be animated, and count gives the number of entries to be animated. Returns the number of entries actually set, or 0 if the call fails.

Definition at line 1274 of file gdiobjec.h.

References GetHandle().

◆ SetPaletteEntry()

uint owl::TPalette::SetPaletteEntry ( uint16 index,
const PALETTEENTRY & entry )
inline

Sets the RGB color value at index in this palette from the entry argument.

The start parameter specifies the first entry to be animated, and count gives the number of entries to be animated. Returns 1, the number of entries actually set if successful, or 0 if the call fails.

Definition at line 1290 of file gdiobjec.h.

References GetHandle().

◆ ToClipboard()

void owl::TPalette::ToClipboard ( TClipboard & clipboard)

Moves this palette to the target Clipboard argument.

If a copy is to be put on the Clipboard, use TPalette(myPalette).ToClipboard; to make a copy first. The handle in the temporary copy of the object is moved to the clipboard. ToClipboard sets ShouldDelete to false so that the object on the clipboard is not deleted. The handle will still be available for examination.

Definition at line 250 of file palette.cpp.

References owl::TGdiObject::Handle, owl::TGdiObject::RefRemove(), owl::TClipboard::SetClipboardData(), and owl::TGdiObject::ShouldDelete.

◆ UnrealizeObject()

bool owl::TPalette::UnrealizeObject ( )
inline

Directs the GDI to completely remap the logical palette to the system palette on the next RealizePalette(HDC) or TDC::RealizePalette call.

Returns true if the call is successful; otherwise false.

Definition at line 1241 of file gdiobjec.h.

References owl::TGdiObject::Handle.

◆ Write()

bool owl::TPalette::Write ( const tchar * fileName)

Write this palette into file: *.dib,*.bmp,*.pal,*.aco,*.act.

Definition at line 289 of file palette.cpp.

References _T, _tcsicmp, _tcsrchr, owl::TFile::CreateAlways, owl::TFile::PermExclusive, owl::TFileName::Remove(), Write_ACO(), Write_ACT(), Write_BMP(), Write_PAL(), and owl::TFile::WriteOnly.

◆ Write_ACO()

bool owl::TPalette::Write_ACO ( TRiffFile & file)
protected

Write Adobe palette to file.

Write Adobe Photoshop *.ACO color table.

return true if success

Definition at line 622 of file palette.cpp.

References owl::boBig_Endian, GetObject(), GetPaletteEntries(), owl::TXBadFormat::Raise(), and WARNX.

◆ Write_ACT()

bool owl::TPalette::Write_ACT ( TRiffFile & file)
protected

Write Adobe palette to file.

Read Adobe Photoshop *.ACT color table.

return true if success

Definition at line 701 of file palette.cpp.

References GetObject(), GetPaletteEntries(), and WARNX.

◆ Write_BMP()

bool owl::TPalette::Write_BMP ( TRiffFile & file)
protected

Write palette to BMP 1x1 file.

Write Color table to *.DIB with dimensions 1x1 pixel.

return true if success

Definition at line 851 of file palette.cpp.

References GetObject(), GetPaletteEntries(), and WARNX.

◆ Write_PAL()

bool owl::TPalette::Write_PAL ( TRiffFile & file)
protected

Write Microsoft palette to file.

write Microsoft *.pal format

return true if success

Definition at line 378 of file palette.cpp.

References owl::TRiffFile::cfCreateRiff, GetObject(), GetPaletteEntries(), owlFCC, and WARNX.


The documentation for this class was generated from the following files: