OWLNext    7.0
Borland's Object Windows Library for the modern age
Loading...
Searching...
No Matches
dibitmap.cpp
Go to the documentation of this file.
1//----------------------------------------------------------------------------
2// ObjectWindows
3// Copyright (c) 1995, 1996 by Borland International, All Rights Reserved
4//
5/// \file
6/// Implementation of TDiBitmap class, a combination of a GDI TBitmap object and
7/// a Device Independent Bitmap TDib object.
8//----------------------------------------------------------------------------
9#include <owl/pch.h>
10#include <owl/gdiobjec.h>
11#include <owl/dibitmap.h>
12#include <owl/pointer.h>
13#include <owl/wsyscls.h>
14
15using namespace std;
16
17namespace owl {
18
20
21//-------------------------------------------------------------------------
22
23//
24/// Initializes our bitmap side from the DIB side. TDib::Bits gets setup to point to
25/// the new DIBSection-managed DIB buffer.
26//
28{
29// PRECONDITION(Bits == 0);
30
31 // !CQ hacky!!! need to get a better dc...
32 TScreenDC dc;
34 if (NumColors() != 0)
35 p = new TPalette(*reinterpret_cast<TDib*>(this));
36 else
37 p = new TPalette(reinterpret_cast<HPALETTE>(::GetStockObject(DEFAULT_PALETTE)));
38
39 dc.SelectObject(*static_cast<TPalette*>(p));
40 dc.RealizePalette();
41 void *bits;
43 memcpy(bits, Bits, SizeImage());
44 Bits = bits;
45//JJH - maybe this is bad, but this->CheckValid wasn't defined!
48}
49
50
51// TWinGBitmap(TWinGIdentity&, TDibDC& dc, const TSize& size);
52// TWinGBitmap(TWinGIdentity&, TDibDC& dc, TDib& dib);
53// TWinGBitmap(TWinGIdentity&, TDibDC& dc, int width, int height);
54
55
56//
57/// Construct from existing bitmap handle.
58//
59TDiBitmap::TDiBitmap(HGLOBAL handle, TAutoDelete autoDelete)
60:
62{
63 InitBitmap();
64}
65
66
67//
68/// Construct from bitmap stored in clipboard.
69//
70TDiBitmap::TDiBitmap(const TClipboard& clipboard)
71:
72 TDib(clipboard)
73{
74 InitBitmap();
75}
76
77
78//
79/// Construct a copy from existing TDib.
80//
81TDiBitmap::TDiBitmap(const TDib& src)
82:
83 TDib(src)
84{
85 InitBitmap();
86}
87
88
89//
90/// Construct new bitmap with the passed-in parameters.
91//
92TDiBitmap::TDiBitmap(int width, int height, int nColors, uint16 mode)
93:
94 TDib(width, height, nColors, mode)
95{
96 InitBitmap();
97}
98
99
100//
101/// Construct a bitmap stored as resource.
102//
103TDiBitmap::TDiBitmap(HINSTANCE module, TResId resid)
104:
105 TDib(module, resid)
106{
107 InitBitmap();
108}
109
110
111//
112/// Construct from DIB stored as a file.
113//
114TDiBitmap::TDiBitmap(LPCTSTR filename)
115:
117{
118 InitBitmap();
119}
120
121//
122/// String-aware overload
123//
124TDiBitmap::TDiBitmap(const tstring& filename)
125:
127{
128 InitBitmap();
129}
130
131
132//
133/// Construct from a TFile.
134//
135TDiBitmap::TDiBitmap(TFile& file, bool readFileHeader)
136:
138{
139 InitBitmap();
140}
141
142//
143/// Construct from input stream.
144//
145TDiBitmap::TDiBitmap( istream& is, bool readFileHeader)
146:
148{
149 InitBitmap();
150}
151
152
153//
154/// Construct from a bitmap and palette information.
155//
156TDiBitmap::TDiBitmap(const TBitmap& bitmap, const TPalette* pal)
157:
158 TDib(bitmap, pal)
159{
160 InitBitmap();
161}
162
163
164//
165/// Restore Bits data member to 0.
166//
168{
169 Bits = nullptr; // Make sure that TDib doesn't mess with our unusual bits
170}
171
172
173/// Implementation of Identity Palette object, TIdentityPalette.
174/// Use of an identity palette allows objects to be blitted without having
175/// the color mapper come into play. The overall effect is faster graphics.
176//
177/// Return an identity palette to be used by bitmaps. This ensures
178/// speed and color accuracy.
179//
181:
183{
185
186 int nColors = palette.GetNumEntries();
187 int nSysColors = sdc.GetDeviceCaps(SIZEPALETTE);
188
189 LOGPALETTE* logPal = reinterpret_cast<LOGPALETTE*>(new uint8[
190 sizeof(LOGPALETTE)+(nColors-1)*sizeof(PALETTEENTRY) ]);
191 logPal->palVersion = 0x300;
192 logPal->palNumEntries = static_cast<uint16>(nColors);
193
194 if (sdc.GetSystemPaletteUse() == SYSPAL_NOSTATIC) {
195 int colorIndex;
196
197 // Set the entries to PC_NOCOLLAPSE
198 // !CQ First colors will get stomped. Need to offset & then fixup dib...
199 //
200 palette.GetPaletteEntries(0, uint16(nColors), logPal->palPalEntry);
202 logPal->palPalEntry[colorIndex].peFlags = PC_NOCOLLAPSE;
203
204 // Make the first entry black
205 //
206 logPal->palPalEntry[0].peRed = 0;
207 logPal->palPalEntry[0].peGreen = 0;
208 logPal->palPalEntry[0].peBlue = 0;
209 logPal->palPalEntry[0].peFlags = 0;
210
211 // Make the last entry white
212 //
213 logPal->palPalEntry[255].peRed = 255;
214 logPal->palPalEntry[255].peGreen = 255;
215 logPal->palPalEntry[255].peBlue = 255;
216 logPal->palPalEntry[255].peFlags = 0;
217 }
218 else {
219 // SystemPaletteUse == SYSPAL_STATIC
220 //
221 int staticColors = sdc.GetDeviceCaps(NUMCOLORS) / 2;
223
224 ///TH The passed color table should be indexed from the start not from
225 // the offset of the systems static palette use.
226 // !CQ is it really an identity palette then? More work needs to be done.
227 //
228 sdc.GetSystemPaletteEntries(0, staticColors, logPal->palPalEntry);
229 palette.GetPaletteEntries(0, uint16(usableColors), logPal->palPalEntry+staticColors);
230 sdc.GetSystemPaletteEntries(nSysColors - staticColors, staticColors,
231 logPal->palPalEntry + nSysColors - staticColors);
232
233 int colorIndex = 0;
235 logPal->palPalEntry[colorIndex].peFlags = 0;
236 for (; colorIndex < nColors; colorIndex++)
237 logPal->palPalEntry[colorIndex].peFlags = PC_NOCOLLAPSE;
238 for (; colorIndex < nSysColors; colorIndex++)
239 logPal->palPalEntry[colorIndex].peFlags = 0;
240 }
242 delete[] logPal;
243
244 ShouldDelete = true;
245 CheckValid();
247}
248
249
250//
251/// Default constructor. Retrieves the system's halftone palette.
252//
261
262
263} // OWL namespace
264
265/* ========================================================================== */
266
TBitmap is the GDI bitmap class derived from TGdiObject.
Definition gdiobjec.h:510
The clipboard class encapsulates the methods for the clipboard object of Windows.
Definition clipboar.h:32
HBITMAP CreateDIBSection(const BITMAPINFO &info, uint usage, void **bits, HANDLE section=0, uint32 offset=0)
Create a fast DIB under Win32.
Definition dc.h:2843
void SelectObject(const TBrush &brush)
Selects the given GDI brush object into this DC.
Definition dc.cpp:113
int RealizePalette()
Maps to the system palette the logical palette entries selected into this DC.
Definition dc.h:1054
void InitBitmap()
Initializes our bitmap side from the DIB side.
Definition dibitmap.cpp:27
~TDiBitmap()
Restore Bits data member to 0.
Definition dibitmap.cpp:167
Pseudo-GDI object Device Independent Bitmap (DIB) class.
Definition gdiobjec.h:795
uint16 Usage() const
Returns the Mode for this DIB.
Definition gdiobjec.h:1954
void CheckValid(uint resId=IDS_GDIFAILURE)
Definition gdibase.cpp:49
const BITMAPINFO * GetInfo() const
Returns this DIB's Info field.
Definition gdiobjec.h:1659
long NumColors() const
Returns NumClrs, the number of colors in this DIB's palette.
Definition gdiobjec.h:1906
uint32 SizeImage() const
Returns number of bytes used to store the image.
Definition gdiobjec.h:1898
The TFile class encapsulates standard file characteristics and operations.
Definition file.h:120
HANDLE Handle
GDI handle of this object.
Definition gdibase.h:81
void CheckValid(uint resId=IDS_GDIFAILURE)
Definition gdibase.cpp:49
bool ShouldDelete
Should object delete GDI handle in dtor?
Definition gdibase.h:82
static void RefAdd(HANDLE handle, TType type)
RefAdd adds a reference entry for the object with the given handle and type.
Definition gdiobjec.cpp:137
HANDLE Handle
GDI handle of this object.
Definition gdibase.h:81
THalftonePalette()
Default constructor. Retrieves the system's halftone palette.
Definition dibitmap.cpp:253
TIdentityPalette(const TPalette &palette)
Implementation of Identity Palette object, TIdentityPalette.
Definition dibitmap.cpp:180
TPalette is the GDI Palette class derived from TGdiObject.
Definition gdiobjec.h:413
Derived from TWindowDC, TScreenDC is a DC class that provides direct access to the screen bitmap.
Definition dc.h:610
Definition of DeviceIndependent Bitmap object class.
Definition of abstract GDI object class and derived classes.
TAutoDelete
Flag for Handle ctors to control Handle deletion in dtor.
Definition gdibase.h:70
@ NoAutoDelete
Definition gdibase.h:70
Object Windows Library (OWLNext Core)
Definition animctrl.h:22
OWL_DIAGINFO
Definition animctrl.cpp:14
unsigned short uint16
Definition number.h:33
std::string tstring
Definition defs.h:79
Various types of smart pointer templatized classes.
Classes for window system structure and type encapsulation.