OWLNext 7.0
Borland's Object Windows Library for the modern age
|
Pseudo-GDI object Device Independent Bitmap (DIB) class. More...
#include <owl/gdiobjec.h>
Classes | |
class | IFileIn |
Internal DIB file Reda/Write functions talk to these interfaces. More... | |
class | IFileOut |
Public Types | |
enum | { MapFace = 0x01 , MapText = 0x02 , MapShadow = 0x04 , MapHighlight = 0x08 , MapFrame = 0x10 } |
Map colors in color table matching stock UI colors to current UI colors. More... | |
typedef HANDLE | THandle |
TDib encapsulates an memory HANDLE w/ a DIB. | |
Public Member Functions | |
TDib (HGLOBAL handle, TAutoDelete autoDelete=NoAutoDelete) | |
Creates a TDib object and sets the Handle data member to the given borrowed handle. | |
TDib (const TClipboard &clipboard) | |
Constructs a TDib object with a handle borrowed from the given Clipboard. | |
TDib (const TDib &src) | |
This public copy constructor creates a complete copy of the given src object as in: | |
TDib (int width, int height, uint32 nColors, uint16 mode=DIB_RGB_COLORS) | |
Creates a DIB object with the given width, height, number of colors, mode values. | |
TDib (HINSTANCE module, TResId resid) | |
Creates a TDib given a module instance and a resource name or int Id. | |
TDib (LPCTSTR filename) | |
Creates a DIB object from the given resource file (.bmp). | |
TDib (const tstring &filename) | |
String-aware overload. | |
TDib (TFile &file, bool readFileHeader=true) | |
Creates a DIB from the file. | |
TDib (std::istream &is, bool readFileHeader=false) | |
Creates a DIB from the file stream. | |
TDib (const TBitmap &bitmap, const TPalette *pal=nullptr) | |
Creates a DIB object from the given resource bitmap and palette. | |
virtual | ~TDib () |
Destruct a TDib by unlocking & freeing its global memory handle as required. | |
bool | operator== (const TDib &other) const |
Compares two handles and returns true if this DIB's handle equals the other (other) DIB's handle. | |
const BITMAPINFO * | GetInfo () const |
Returns this DIB's Info field. | |
BITMAPINFO * | GetInfo () |
Returns this DIB's Info field. | |
const BITMAPINFOHEADER * | GetInfoHeader () const |
Returns this DIB's bmiHeader field of the BITMAPINFO structure contains information about the color and dimensions of this DIB. | |
BITMAPINFOHEADER * | GetInfoHeader () |
Returns this DIB's bmiHeader field of the BITMAPINFO structure contains information about the color and dimensions of this DIB. | |
const TRgbQuad * | GetColors () const |
Returns the bmiColors value of this DIB. | |
TRgbQuad * | GetColors () |
Returns the bmiColors value of this DIB. | |
const uint16 * | GetIndices () const |
Returns the bmiColors indexes of this DIB. | |
uint16 * | GetIndices () |
Returns the bmiColors indexes of this DIB. | |
const void * | GetBits () const |
Returns the Bits data member for this DIB. | |
void * | GetBits () |
Returns the Bits data member for this DIB. | |
HANDLE | GetHandle () const |
Returns the handle of the DIB with type HANDLE. | |
operator HANDLE () const | |
Return the handle of the DIB with type HANDLE. | |
operator const BITMAPINFO * () const | |
Typecasts this DIB by returning a pointer to its bitmap information structure (BITMAPINFO) which contains information about this DIB's color format and dimensions (size, width, height, resolution, and so on). | |
operator BITMAPINFO * () | |
Typecasts this DIB by returning a pointer to its bitmap information structure (BITMAPINFO) which contains information about this DIB's color format and dimensions (size, width, height, resolution, and so on). | |
operator const BITMAPINFOHEADER * () const | |
Typecasts this DIB by returning a pointer to its bitmap info header. | |
operator BITMAPINFOHEADER * () | |
Typecasts this DIB by returning a pointer to its bitmap info header. | |
operator const TRgbQuad * () const | |
Typecasts this DIB by returning a pointer to its colors structure. | |
operator TRgbQuad * () | |
Typecasts this DIB by returning a pointer to its colors structure. | |
void | ToClipboard (TClipboard &clipboard) |
Moves this dib to the clipboard. | |
bool | IsOK () const |
Returns false if Info is 0, otherwise returns true. | |
bool | IsPM () const |
Returns true if IsCore is true; that is, if the DIB is an old-style PM DIB using core headers. | |
int | Width () const |
Returns the width of the DIB. | |
int | Height () const |
Returns the height of the DIB. | |
int | FlippedY (int y) const |
Returns the coordinate of y if the direction of the y-axis was reversed. | |
TSize | Size () const |
Returns TSize(W,H), the size of this DIB. | |
int | BitsPixel () const |
Return the number of bits (2, 4, 8, 16, 24, or 32) used to store a pixel for the DIB. | |
int | Pitch () const |
Size of scan in bytes = Pixel Width * bits per pixel rounded up to a uint32 boundary. | |
uint32 | Compression () const |
Returns type of compression and encoding for bottom-up DIBs. | |
uint32 | SizeImage () const |
Returns number of bytes used to store the image. | |
long | NumColors () const |
Returns NumClrs, the number of colors in this DIB's palette. | |
uint | StartScan () const |
Returns the starting scan line. | |
uint | NumScans () const |
Returns the number of scans in this DIB. | |
int32 | SizeColors () const |
Return number of colors times the size of each entry in the table, whether it is an RGB color table or palette index table. | |
uint32 | SizeDib () const |
Size of dib is measured as the end of the bits minus the start of the block. | |
uint16 | Usage () const |
Returns the Mode for this DIB. | |
int | XOffset (uint16 x) const |
Returns the byte offset from the start of the scan line to the xth pixel. | |
int | YOffset (uint16 y) const |
Returns the starting position of the scan line. | |
void * | PixelPtr (uint16 x, uint16 y) |
Returns the byte of where the pixel is located. | |
bool | WriteFile (const tstring &filename) |
Writes the DIB into an external file. | |
bool | Write (TFile &file, bool writeFileHeader=false) |
Write this DIB to a file object. | |
bool | Write (std::ostream &os, bool writeFileHeader=false) |
Writes this DIB to an ostream. | |
TColor | GetColor (int entry) const |
Returns the color for the given palette entry. | |
void | SetColor (int entry, const TColor &color) |
Sets the given color for the given palette entry. | |
int | FindColor (const TColor &color) |
Returns the palette entry for the given color. | |
int | MapColor (const TColor &fromColor, const TColor &toColor, bool doAll=false) |
Maps the first or all occurances of fromColor to the toColor in the current palette of this DIB. | |
uint16 | GetIndex (int entry) const |
void | SetIndex (int entry, uint16 index) |
Sets the given index for the given entry. | |
int | FindIndex (uint16 index) |
Returns the palette entry corresponding to the given index. | |
int | MapIndex (uint16 fromIndex, uint16 toIndex, bool doAll=false) |
Maps the fromIndex to the toIndex in the current palette of this DIB. | |
bool | ChangeModeToPal (const TPalette &pal) |
Converts the existing color table in place to use palette relative values. | |
bool | ChangeModeToRGB (const TPalette &pal) |
Converts the existing color table in place to use absolute RGB values. | |
void | MapUIColors (uint mapColors, const TColor *bkColor=nullptr) |
Maps the UI colors to the value specified in the parameter, mapColors, which is one of the values of the Map enum. | |
void | MapToPalette (const TPalette &pal) |
Modifies this DIB so that the pixels and color table coincide with a given palette. | |
Protected Member Functions | |
TDib () | |
Protected ctor- derived classes need to fill in handle & get info. | |
void | InfoFromHeader (const BITMAPINFOHEADER &infoHeader) |
Given a BITMAPINFOHEADER, allocate a global buffer for Handle & init Info. | |
void | InfoFromHandle () |
Locks the global/res handle if needed and extracts the pointers and cached info maintained as member variables from Info. | |
void | CopyOnWrite () |
Copies the DIB. | |
void | ResToMemHandle () |
Under Win32, resources are read-only. | |
bool | ReadFile (const tstring &name) |
Tests if the passed file is a Windows 3.x (or PM 1.x) DIB and if so read it. | |
bool | Read (TFile &file, bool readFileHeader=false) |
Read a Windows 3.x or PM 1.x device independent bitmap from a TFile Return true iff Dib was read OK. | |
bool | Read (std::istream &is, bool readFileHeader=false) |
Read a Windows 3.0 or PM 1.X device independent bitmap from an istream. | |
bool | LoadResource (HINSTANCE, TResId) |
Loads this DIB from the given resource and returns true if successful. | |
virtual bool | Read (IFileIn &in, bool readFileHeader=false) |
Reads a Windows 3.0 or PM 1.X device independent bitmap. | |
virtual bool | Write (IFileOut &out, bool writeFileHeader=false) |
Writes the DIB into a file stream. | |
void | CheckValid (uint resId=IDS_GDIFAILURE) |
Static Protected Member Functions | |
static int | ScanBytes (long w, int bpp) |
Width+bpp to dword aligned bytes. | |
Protected Attributes | |
HANDLE | Handle |
GDI handle of this object. | |
bool | ShouldDelete |
Should object delete GDI handle in dtor? | |
Pseudo-GDI object Device Independent Bitmap (DIB) class.
DIBs really have no Window's handle, they are just a structure containing format and palette information and a collection of bits (pixels). This class provides a very convenient way to work with DIBs like any other GDI object. The memory for the DIB is in one GlobalAlloc'd chunk so it can be passed to the Clipboard, OLE, etc. Overloads the destructor since it is not a real GDI object.
This is what is really inside a .BMP file, what is in bitmap resources, and what is put on the clipboard as a DIB.
Definition at line 795 of file gdiobjec.h.
TDib encapsulates an memory HANDLE w/ a DIB.
Definition at line 799 of file gdiobjec.h.
Map colors in color table matching stock UI colors to current UI colors.
Enumerates the values for the part of the window whose color is to be set. You can OR these together to control the colors used for face shading on push buttons, the color of a selected control button, the edge shading on push buttons, text on push buttons, the color of the window frame, and the background color of the various parts of a window. The function MapUIColors uses one of these values to map the colors of various parts of a window to a specified color.
Enumerator | |
---|---|
MapFace | |
MapText | |
MapShadow | |
MapHighlight | |
MapFrame |
Definition at line 909 of file gdiobjec.h.
|
explicit |
Creates a TDib 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 170 of file dib.cpp.
References InfoFromHandle().
|
explicit |
Constructs a TDib object with a handle borrowed from the given Clipboard.
Definition at line 182 of file dib.cpp.
References InfoFromHandle().
owl::TDib::TDib | ( | const TDib & | src | ) |
This public copy constructor creates a complete copy of the given src object as in:
Definition at line 198 of file dib.cpp.
References Handle, PRECONDITION, and owl::TXOutOfMemory::Raise().
owl::TDib::TDib | ( | int | width, |
int | height, | ||
uint32 | nColors, | ||
uint16 | mode = DIB_RGB_COLORS ) |
Creates a DIB object with the given width, height, number of colors, mode values.
Definition at line 955 of file dib.cpp.
References owl::TDC::GetDeviceCaps(), InfoFromHeader(), owl::NBits(), PRECONDITION, ScanBytes(), and Swap().
Creates a TDib given a module instance and a resource name or int Id.
Definition at line 796 of file dib.cpp.
References LoadResource(), and owl::TXGdi::Raise().
|
explicit |
Creates a DIB object from the given resource file (.bmp).
Definition at line 494 of file dib.cpp.
References owl::TXGdi::Raise(), and ReadFile().
|
explicit |
String-aware overload.
Definition at line 503 of file dib.cpp.
References owl::TXGdi::Raise(), and ReadFile().
Creates a DIB from the file.
Definition at line 513 of file dib.cpp.
References owl::TXGdi::Raise(), and Read().
Creates a DIB from the file stream.
Definition at line 522 of file dib.cpp.
References owl::TXGdi::Raise(), and Read().
Creates a DIB object from the given resource bitmap and palette.
If pal is 0 (the default), the default palette is used.
Definition at line 1006 of file dib.cpp.
References owl::TDC::GetDIBits(), InfoFromHeader(), owl::NBits(), owl::NColors(), NumScans(), ScanBytes(), owl::TDC::SelectObject(), StartScan(), and Usage().
|
virtual |
Destruct a TDib by unlocking & freeing its global memory handle as required.
Definition at line 233 of file dib.cpp.
References Handle, and ShouldDelete.
|
protected |
|
inline |
Return the number of bits (2, 4, 8, 16, 24, or 32) used to store a pixel for the DIB.
Definition at line 1873 of file gdiobjec.h.
|
protected |
Definition at line 86 of file gdibase.cpp.
|
inline |
Returns type of compression and encoding for bottom-up DIBs.
Definition at line 1890 of file gdiobjec.h.
|
inlineprotected |
Returns the palette entry for the given color.
Definition at line 340 of file dib.cpp.
References GetColors().
Returns the palette entry corresponding to the given index.
Definition at line 399 of file dib.cpp.
References GetIndices().
Returns the coordinate of y if the direction of the y-axis was reversed.
Definition at line 1848 of file gdiobjec.h.
|
inline |
Returns the Bits data member for this DIB.
Definition at line 1735 of file gdiobjec.h.
|
inline |
Returns the Bits data member for this DIB.
Definition at line 1727 of file gdiobjec.h.
Returns the color for the given palette entry.
Definition at line 314 of file dib.cpp.
References GetColors().
|
inline |
Returns the bmiColors value of this DIB.
Definition at line 1703 of file gdiobjec.h.
|
inline |
Returns the bmiColors value of this DIB.
Definition at line 1695 of file gdiobjec.h.
|
inline |
Returns the handle of the DIB with type HANDLE.
Definition at line 1743 of file gdiobjec.h.
References Handle.
Definition at line 373 of file dib.cpp.
References GetColors().
|
inline |
Returns the bmiColors indexes of this DIB.
Definition at line 1719 of file gdiobjec.h.
|
inline |
Returns the bmiColors indexes of this DIB.
Definition at line 1711 of file gdiobjec.h.
|
inline |
Returns this DIB's Info field.
A DIB's BITMAPINFO structure contains information about the dimensions and color of the DIB and specifies an array of data types that define the colors in the bitmap.
Definition at line 1669 of file gdiobjec.h.
|
inline |
Returns this DIB's Info field.
A DIB's BITMAPINFO structure contains information about the dimensions and color of the DIB and specifies an array of data types that define the colors in the bitmap.
Definition at line 1659 of file gdiobjec.h.
|
inline |
Returns this DIB's bmiHeader field of the BITMAPINFO structure contains information about the color and dimensions of this DIB.
Definition at line 1687 of file gdiobjec.h.
|
inline |
Returns this DIB's bmiHeader field of the BITMAPINFO structure contains information about the color and dimensions of this DIB.
Definition at line 1678 of file gdiobjec.h.
|
inline |
Returns the height of the DIB.
Definition at line 1840 of file gdiobjec.h.
|
protected |
Locks the global/res handle if needed and extracts the pointers and cached info maintained as member variables from Info.
Needs only Info setup, or if Info is 0 then Handle & IsResHandle setup
Definition at line 88 of file dib.cpp.
References Handle, owl::NColors(), and owl::TXGdi::Raise().
|
protected |
Given a BITMAPINFOHEADER, allocate a global buffer for Handle & init Info.
Definition at line 60 of file dib.cpp.
References Handle, InfoFromHandle(), and owl::TXOutOfMemory::Raise().
|
inline |
Returns false if Info is 0, otherwise returns true.
If there is a problem with the construction of the DIB, memory is freed and Info is set to 0. Therefore, using Info is a reliable way to determine if the DIB is constructed correctly.
Definition at line 1813 of file gdiobjec.h.
|
inline |
Returns true if IsCore is true; that is, if the DIB is an old-style PM DIB using core headers.
Otherwise returns false.
Definition at line 1824 of file gdiobjec.h.
Loads this DIB from the given resource and returns true if successful.
Definition at line 811 of file dib.cpp.
References Handle, InfoFromHandle(), LoadResource(), PRECONDITION, ResToMemHandle(), and TRACEX.
Maps the first or all occurances of fromColor to the toColor in the current palette of this DIB.
Returns the palette entry for the given color. Returns the palette entry for the toColor argument.
Definition at line 355 of file dib.cpp.
References GetColors().
Maps the fromIndex to the toIndex in the current palette of this DIB.
Returns the palette entry for the toIndex argument.
Definition at line 413 of file dib.cpp.
References GetIndices().
Modifies this DIB so that the pixels and color table coincide with a given palette.
!CQ 8bpp only!
Definition at line 1053 of file dib.cpp.
References GetBits(), GetColor(), GetColors(), Height(), and Pitch().
Maps the UI colors to the value specified in the parameter, mapColors, which is one of the values of the Map enum.
Use this function to get the colors for the face shading on push buttons, the highlighting for a selected control button, the text on push buttons, the shade of the window frame and the background color. Use MapColor to map selected standard UI colors in this DIB to their current system values. Also can map a background color. Used to update a UI DIB to current colors before rendering.
LtGray ->
3d FaceBlack ->
Button TextGray ->
3d ShadowWhite ->
3d HilightMagenta ->
Window FrameLtYellow ->
bkColor Definition at line 446 of file dib.cpp.
References owl::TColor::Black, owl::TColor::Gray, owl::TColor::LtGray, owl::TColor::LtMagenta, owl::TColor::LtYellow, MapColor(), MapFace, MapFrame, MapHighlight, MapShadow, MapText, owl::TColor::Sys3dFace, owl::TColor::Sys3dHilight, owl::TColor::Sys3dShadow, owl::TColor::SysBtnText, owl::TColor::SysWindow, owl::TColor::SysWindowFrame, and owl::TColor::White.
|
inline |
Returns NumClrs, the number of colors in this DIB's palette.
Definition at line 1906 of file gdiobjec.h.
|
inline |
Returns the number of scans in this DIB.
Always same as height of the DIB.
Definition at line 1926 of file gdiobjec.h.
References Height().
|
inline |
Typecasts this DIB by returning a pointer to its bitmap information structure (BITMAPINFO) which contains information about this DIB's color format and dimensions (size, width, height, resolution, and so on).
Definition at line 1771 of file gdiobjec.h.
|
inline |
Typecasts this DIB by returning a pointer to its bitmap info header.
Definition at line 1787 of file gdiobjec.h.
|
inline |
Typecasts this DIB by returning a pointer to its bitmap information structure (BITMAPINFO) which contains information about this DIB's color format and dimensions (size, width, height, resolution, and so on).
Definition at line 1761 of file gdiobjec.h.
|
inline |
Typecasts this DIB by returning a pointer to its bitmap info header.
Definition at line 1779 of file gdiobjec.h.
|
inline |
Typecasts this DIB by returning a pointer to its colors structure.
Definition at line 1795 of file gdiobjec.h.
|
inline |
Return the handle of the DIB with type HANDLE.
Definition at line 1751 of file gdiobjec.h.
|
inline |
Typecasts this DIB by returning a pointer to its colors structure.
Definition at line 1803 of file gdiobjec.h.
Compares two handles and returns true if this DIB's handle equals the other (other) DIB's handle.
Definition at line 1649 of file gdiobjec.h.
References Handle.
|
inline |
Size of scan in bytes = Pixel Width * bits per pixel rounded up to a uint32 boundary.
Definition at line 1882 of file gdiobjec.h.
References BitsPixel(), ScanBytes(), and Width().
Returns the byte of where the pixel is located.
Definition at line 1978 of file gdiobjec.h.
Reads a Windows 3.0 or PM 1.X device independent bitmap.
(.BMP) from an implementor of TDib's IFileIn interface
Checks header, read Info, palette and bitmap. PM Dibs are converted to Windows 3.x Dibs on the fly.
Returns true iff Dib was read OK
Definition at line 636 of file dib.cpp.
References BFT_BITMAP, Handle, InfoFromHeader(), owl::NColors(), owl::TXBadFormat::Raise(), ScanBytes(), and TRACEX.
Tests if the passed file is a Windows 3.x (or PM 1.x) DIB and if so read it.
Returns true if Dib was read OK.
Definition at line 549 of file dib.cpp.
References owl::TFile::OpenExisting, Read(), owl::TFile::ReadOnly, and TRACEX.
|
protected |
Under Win32, resources are read-only.
So, to allow for modification of the Dib, a copy must be made.
Definition at line 143 of file dib.cpp.
References Handle, InfoFromHandle(), and owl::TXOutOfMemory::Raise().
Width+bpp to dword aligned bytes.
Returns the number of bytes used to store a scanline for the DIB.
Rounded up to the nearest 32-bit boundary.
Definition at line 1865 of file gdiobjec.h.
Sets the given color for the given palette entry.
Definition at line 328 of file dib.cpp.
References GetColors().
Sets the given index for the given entry.
Definition at line 387 of file dib.cpp.
References GetColors().
|
inline |
Returns TSize(W,H), the size of this DIB.
Definition at line 1856 of file gdiobjec.h.
|
inline |
Return number of colors times the size of each entry in the table, whether it is an RGB color table or palette index table.
Definition at line 1935 of file gdiobjec.h.
References NumColors().
|
inline |
Size of dib is measured as the end of the bits minus the start of the block.
Definition at line 1945 of file gdiobjec.h.
References SizeImage().
|
inline |
Returns number of bytes used to store the image.
Definition at line 1898 of file gdiobjec.h.
|
inline |
Returns the starting scan line.
Always 0 because all DIBs are normalized.
Definition at line 1916 of file gdiobjec.h.
void owl::TDib::ToClipboard | ( | TClipboard & | clipboard | ) |
Moves this dib to the clipboard.
Ownership of the DIB handle is passed to the clipboard.
Definition at line 474 of file dib.cpp.
References Handle, owl::TClipboard::SetClipboardData(), and ShouldDelete.
|
inline |
Returns the Mode for this DIB.
This value tells GDI how to treat the color table - whether the DIB has palette color entries or RGB color entries.
Definition at line 1954 of file gdiobjec.h.
|
inline |
Returns the width of the DIB.
Definition at line 1832 of file gdiobjec.h.
Writes the DIB into a file stream.
Definition at line 912 of file dib.cpp.
References BFT_BITMAP, and Handle.
Writes the DIB into an external file.
Returns true if the call is successful; otherwise returns false.
Definition at line 846 of file dib.cpp.
References owl::TFile::CreateAlways, owl::TFile::PermExclusive, TRACEX, Write(), and owl::TFile::WriteOnly.
Returns the byte offset from the start of the scan line to the xth pixel.
Definition at line 1962 of file gdiobjec.h.
References BitsPixel().
Returns the starting position of the scan line.
Definition at line 1970 of file gdiobjec.h.
References Pitch().
|
protected |
|
protected |