18#if defined(__BORLANDC__)
22#define BFT_BITMAP 0x4d42
34class TFileIO :
public TDib::IFileIn,
public TDib::IFileOut {
38 virtual long Read(
void *
buffer,
long size)
42 virtual void Skip(
long size)
46 virtual bool Write(
void *
buffer,
long size)
113 Mask =
reinterpret_cast<uint32 *
>(Info->bmiColors);
114 Colors =
reinterpret_cast<TRgbQuad *
>(
reinterpret_cast<char *
>(Info->bmiColors) + 3 *
sizeof(
uint32));
118 Colors =
static_cast<TRgbQuad *
>(Info->bmiColors);
124 NumClrs = Info->bmiHeader.biClrUsed
125 ? Info->bmiHeader.biClrUsed
126 :
NColors(Info->bmiHeader.biBitCount);
128 Bits =
reinterpret_cast<char *
>(Colors) +
static_cast<int>(NumClrs) *
sizeof(
RGBQUAD);
145 const char* begin =
reinterpret_cast<const char*
>(Info);
146 const char* end =
static_cast<const char*
>(Bits) + Info->bmiHeader.biSizeImage;
147 size_t size = end - begin;
213 Mask =
reinterpret_cast<uint32 *
>(
src.Mask ?
214 reinterpret_cast<char *
>(Info) + (
reinterpret_cast<char *
>(
src.Mask) -
reinterpret_cast<char *
>(
src.Info)) :
nullptr);
215 Bits =
reinterpret_cast<char *
>(Info) + (
reinterpret_cast<char *
>(
src.Bits) -
reinterpret_cast<char *
>(
src.Info));
217 NumClrs =
src.NumClrs;
224 Colors =
reinterpret_cast<TRgbQuad *
>(
reinterpret_cast<char *
>(Info) + (
reinterpret_cast<char *
>(
src.Colors) -
reinterpret_cast<char *
>(
src.Info)));
235 if (!
Handle || IsResHandle)
return;
257 for (
int c = 0;
c < NumClrs;
c++) {
261 pal.GetPaletteEntry(
i,
pe);
262 if (
pe.peRed == Colors[
c].rgbRed &&
263 pe.peGreen == Colors[
c].rgbGreen &&
264 pe.peBlue == Colors[
c].rgbBlue) {
269 (
reinterpret_cast<uint16*
>(Colors))[
c] = index;
287 static_cast<uint>(
reinterpret_cast<char*
>(Bits) -
reinterpret_cast<char*
>(Info)) < NumClrs*
sizeof(
RGBQUAD))
292 for (
int c =
static_cast<int>(NumClrs)-1;
c >= 0;
c--) {
297 pal.GetPaletteEntry(
i,
pe);
298 Colors[
c].rgbRed =
pe.peRed;
299 Colors[
c].rgbGreen =
pe.peGreen;
300 Colors[
c].rgbBlue =
pe.peBlue;
552 if (!
file.IsOpen()) {
587 TStreamIn(istream&
is) : Is(
is) {}
589 virtual long Read(
void*
buffer,
long size)
597 return static_cast<long>(
n);
600 virtual void Skip(
long size)
602 Is.seekg(size, ios::cur);
647 TRACEX(
OwlGDI, 0,
"Not a Windows 3.x or PM 1.x bitmap file");
664 TRACEX(
OwlGDI, 0,
"Not a Windows 3.x or PM 1.x bitmap file");
748 int size = 3*
sizeof(
uint32);
749 if (
in.Read(
reinterpret_cast<char *
>(Mask), size) != size) {
760 static_cast<int>(NumClrs) *
sizeof(
RGBTRIPLE) :
761 static_cast<int>(NumClrs) *
sizeof(
RGBQUAD);
769 for (
int i =
int(NumClrs-1);
i >= 0;
i--) {
770 Colors[
i].rgbRed = (
reinterpret_cast<RGBTRIPLE*
>(Colors))[
i].rgbtRed;
771 Colors[
i].rgbGreen = (
reinterpret_cast<RGBTRIPLE*
>(Colors))[
i].rgbtGreen;
772 Colors[
i].rgbBlue = (
reinterpret_cast<RGBTRIPLE*
>(Colors))[
i].rgbtBlue;
773 Colors[
i].rgbReserved = 0;
850 if (!
file.IsOpen()) {
887 TStreamOut( ostream&
os) : Os(
os) {}
889 virtual bool Write(
void *
buffer,
long size)
891 return Os.write(
reinterpret_cast<char*
>(
buffer), size).good();
924 const char* begin =
reinterpret_cast<const char*
>(Info);
925 const char* end =
static_cast<const char*
>(Bits) +
sizeof(
BITMAPFILEHEADER);
944 if (!
out.Write(Info,
static_cast<long>(size)))
995 Colors[
i].rgbReserved = 0;
1058 for (
int i = 0;
i < 256;
i++)
1074 pal.GetPaletteEntries(0, 256,
pe);
1076 for (
int j = 0;
j < 256;
j++) {
#define PRECONDITION(condition)
#define DIAG_DECLARE_GROUP(group)
#define TRACEX(group, level, message)
TBitmap is the GDI bitmap class derived from TGdiObject.
The clipboard class encapsulates the methods for the clipboard object of Windows.
HANDLE SetClipboardData(uint format, HANDLE handle)
Copy the data onto the clipboard in the format.
Class wrapper for management of color values.
static const TColor LtMagenta
Static TColor object with fixed Value set by RGB(255, 0, 255).
static const TColor SysBtnText
The symbolic system color value for the text on buttons.
static const TColor Sys3dHilight
The symbolic system color value for highlighted 3-dimensional display elements (for edges facing the ...
static const TColor SysWindowFrame
The symbolic system color value for the frame around each window.
static const TColor LtYellow
Static TColor object with fixed Value set by RGB(255, 255, 0).
static const TColor LtGray
Static TColor object with fixed Value set by RGB(192, 192, 192).
static const TColor Sys3dShadow
The symbolic system color value for the shadow regions of 3-dimensional display elements (for edges f...
static const TColor Sys3dFace
The symbolic system color value for the face color of 3-dimensional display elements.
static const TColor Gray
Static TColor object with fixed Value set by RGB(128, 128, 128).
static const TColor White
Static TColor object with fixed Value set by RGB(255, 255, 255).
static const TColor SysWindow
The symbolic system color value for the background of each window.
static const TColor Black
Static TColor object with fixed Value set by RGB(0, 0, 0).
virtual int GetDeviceCaps(int index) const
Used under WIN3.1 or later, GetDeviceCaps returns capability information about this DC.
void SelectObject(const TBrush &brush)
Selects the given GDI brush object into this DC.
int GetDIBits(const TBitmap &bitmap, uint startScan, uint numScans, void *bits, const BITMAPINFO &info, uint16 usage)
The first version retrieves some or all of the bits from the given bitmap on this DC and copies them ...
Internal DIB file Reda/Write functions talk to these interfaces.
Pseudo-GDI object Device Independent Bitmap (DIB) class.
uint NumScans() const
Returns the number of scans in this DIB.
TColor GetColor(int entry) const
Returns the color for the given palette entry.
uint16 Usage() const
Returns the Mode for this DIB.
const uint16 * GetIndices() const
Returns the bmiColors indexes of this DIB.
uint16 GetIndex(int entry) const
int FindIndex(uint16 index)
Returns the palette entry corresponding to the given index.
bool Write(TFile &file, bool writeFileHeader=false)
Write this DIB to a file object.
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 ...
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.
void ResToMemHandle()
Under Win32, resources are read-only.
int FindColor(const TColor &color)
Returns the palette entry for the given color.
bool WriteFile(const tstring &filename)
Writes the DIB into an external file.
void SetColor(int entry, const TColor &color)
Sets the given color for the given palette entry.
bool LoadResource(HINSTANCE, TResId)
Loads this DIB from the given resource and returns true if successful.
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.
int MapIndex(uint16 fromIndex, uint16 toIndex, bool doAll=false)
Maps the fromIndex to the toIndex in the current palette of this DIB.
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.
int Pitch() const
Size of scan in bytes = Pixel Width * bits per pixel rounded up to a uint32 boundary.
TDib()
Protected ctor- derived classes need to fill in handle & get info.
void MapToPalette(const TPalette &pal)
Modifies this DIB so that the pixels and color table coincide with a given palette.
void ToClipboard(TClipboard &clipboard)
Moves this dib to the clipboard.
static int ScanBytes(long w, int bpp)
Width+bpp to dword aligned bytes.
bool ChangeModeToRGB(const TPalette &pal)
Converts the existing color table in place to use absolute RGB values.
int Height() const
Returns the height of the DIB.
void InfoFromHeader(const BITMAPINFOHEADER &infoHeader)
Given a BITMAPINFOHEADER, allocate a global buffer for Handle & init Info.
void SetIndex(int entry, uint16 index)
Sets the given index for the given entry.
bool ShouldDelete
Should object delete GDI handle in dtor?
virtual ~TDib()
Destruct a TDib by unlocking & freeing its global memory handle as required.
uint StartScan() const
Returns the starting scan line.
HANDLE Handle
GDI handle of this object.
void InfoFromHandle()
Locks the global/res handle if needed and extracts the pointers and cached info maintained as member ...
bool ChangeModeToPal(const TPalette &pal)
Converts the existing color table in place to use palette relative values.
const void * GetBits() const
Returns the Bits data member for this DIB.
const TRgbQuad * GetColors() const
Returns the bmiColors value of this DIB.
The TFile class encapsulates standard file characteristics and operations.
virtual uint64 Seek(int64 offset, TSeekDir origin=beg)
Repositions the file pointer to offset bytes from the specified origin.
@ OpenExisting
Opens the file. The function fails if the file does not exist.
@ CreateAlways
Creates a new file. The function overwrites the file if it exists.
virtual uint32 Read(void *buffer, uint32 numBytes)
Reads numBytes from the file into buffer. The number of bytes read is returned.
virtual bool Write(const void *buffer, uint32 numBytes)
Writes numbytes of buffer to the file.
@ cur
Seek from the current position in the file.
Root and abstract class for Windows object wrappers.
TPalette is the GDI Palette class derived from TGdiObject.
Wrapper for Windows' RBGQUAD type.
Derived from TWindowDC, TScreenDC is a DC class that provides direct access to the screen bitmap.
static void Raise(uint resId=IDS_GDIFAILURE, HANDLE handle=0)
Throws the exception.
Definition of classes for clipboard Encapsulation.
Definition of abstract GDI object class and derived classes.
TAutoDelete
Flag for Handle ctors to control Handle deletion in dtor.
static void Raise()
Construct a TXOutOfMemory exception from scratch, and throw it.
Object Windows Library (OWLNext Core)
long NColors(uint16 bitCount)
Functions to convert number of bits to number of palette colors and back, and build an RGB COLORREF.
uint16 NBits(long colors)
Return the number of bits required to represent a given number of colors.
ObjectWindows exception class & function definitions.
Classes for window system structure and type encapsulation.