QCAD
Open Source 2D CAD
Loading...
Searching...
No Matches
opennurbs_bitmap.h
Go to the documentation of this file.
1/* $NoKeywords: $ */
2/*
3//
4// Copyright (c) 1993-2007 Robert McNeel & Associates. All rights reserved.
5// Rhinoceros is a registered trademark of Robert McNeel & Assoicates.
6//
7// THIS SOFTWARE IS PROVIDED "AS IS" WITHOUT EXPRESS OR IMPLIED WARRANTY.
8// ALL IMPLIED WARRANTIES OF FITNESS FOR ANY PARTICULAR PURPOSE AND OF
9// MERCHANTABILITY ARE HEREBY DISCLAIMED.
10//
11// For complete openNURBS copyright information see <http://www.opennurbs.org>.
12//
14*/
15
17//
18// Defines ON_WindowsBITMAPINFO class that is used to provide OS independent
19// serialization of Windows device independent bitmaps (BITMAPINFO) used
20// to store preview images.
21//
23
24#if !defined(OPENNURBS_BITMAP_INC_)
25#define OPENNURBS_BITMAP_INC_
26
28{
29 // virtual base class for bitmap objects
31public:
32 ON_Bitmap();
33 ~ON_Bitmap();
34
35 // C++ defaults work fine
36 //ON_Bitmap(const ON_Bitmap&);
37 //ON_Bitmap& operator=(const ON_Bitmap&);
38
39 // virtual
40 ON_UUID ModelObjectId() const;
41
42
43 void Dump( ON_TextLog& ) const; // for debugging
44
45 void EmergencyDestroy();
46 void Destroy();
47
48 void Defaults();
49
50 virtual
51 int Width() const = 0;
52 virtual
53 int Height() const = 0; // >0 means it's a bottom-up bitmap with origin at lower right
54 // <0 means it's a top-down bitmap with origin at upper left
55 virtual
56 int BitsPerPixel() const = 0; // bits per pixel
57 virtual
58 int SizeofScan() const = 0; // number of bytes per scan line
59 virtual
60 int SizeofImage() const = 0; // size of current map in bytes
61
62 virtual
63 unsigned char* Bits(
64 int // index of scan line
65 ) = 0;
66 virtual
67 const unsigned char* Bits(
68 int // index of scan line
69 ) const = 0;
70
73 ON_wString m_bitmap_name; // descriptive name
74 ON_wString m_bitmap_filename; // full path to file
75};
76
77
78#if !defined(ON_OS_WINDOWS_GDI)
79
80// These are the values of the Windows defines mentioned
81// in the comment below. If you're running on Windows,
82// they get defined by Windows system header files.
83// If you aren't running on Windows, then you don't
84// need them.
85//#define BI_RGB 0L
86//#define BI_RLE8 1L
87//#define BI_RLE4 2L
88//#define BI_BITFIELDS 3L
89
90// Mimics Windows BITMAPINFOHEADER structure.
91// For details searh for "BITMAPINFOHEADER" at http://msdn.microsoft.com/default.asp
93{
94 unsigned int biSize; // DWORD = sizeof(BITMAPINFOHEADER)
95 int biWidth; // LONG = width (in pixels) of (decompressed) bitmap
96 int biHeight; // LONG = height (in pixels) of (decompressed) bitmap
97 // >0 means it's a bottom-up bitmap with origin
98 // in the lower left corner.
99 // <0 means it's a top-down bitmap with origin
100 // in the upper left corner.
101 unsigned short biPlanes; // WORD = number of planes
102 // (always 1 in current Windows versions)
103 unsigned short biBitCount; // WORD = bits per pixel (0,1,4,8,16,24,32 are valid)
104 // 1 See http://msdn.microsoft.com/default.asp
105 // 4 See http://msdn.microsoft.com/default.asp
106 // 8 The bitmap has a maximum of 256 colors,
107 // and the bmiColors member contains up
108 // to 256 entries. In this case, each byte
109 // in the array represents a single pixel.
110 // 16 See http://msdn.microsoft.com/default.asp
111 // 24 If biClrUsed=0 and biCompression=BI_RGB(0),
112 // then each 3-byte triplet in the bitmap
113 // array represents the relative intensities
114 // of blue, green, and red, respectively, for
115 // a pixel. For other possibilities, see
116 // http://msdn.microsoft.com/default.asp
117 // 32 If biClrUsed=0 and biCompression=BI_RGB(0),
118 // then each 4-byte DWORD in the bitmap
119 // array represents the relative intensities
120 // of blue, green, and red, respectively, for
121 // a pixel. The high byte in each DWORD is not
122 // used.
123 // If biClrUsed=3, biCompression=BITFIELDS(3),
124 // biColors[0] = red mask (0x00FF0000),
125 // biColors[1] = green mask (0x0000FF00), and
126 // biColors[2] = blue mask (0x000000FF),
127 // then tese masks are used with each 4-byte
128 // DWORD in the bitmap array to determine
129 // the pixel's relative intensities. //
130 // For other possibilities, see
131 // http://msdn.microsoft.com/default.asp
132 unsigned int biCompression; // DWORD Currently, Windows defines the following
133 // types of compression.
134 // =0 BI_RGB (no compression)
135 // =1 BI_RLE8 (run length encoded used for 8 bpp)
136 // =2 BI_RLE4 (run length encoded used for 4 bpp)
137 // =3 BI_BITFIELDS Specifies that the bitmap is
138 // not compressed and that the color table
139 // consists of three DWORD color masks that
140 // specify the red, green, and blue components,
141 // respectively, of each pixel. This is valid
142 // when used with 16- and 32-bit-per-pixel
143 // bitmaps.
144 // =4 BI_JPEG (not supported in Win 95/NT4)
145 //
146 unsigned int biSizeImage; // DWORD = bytes in image
147 int biXPelsPerMeter; // LONG
148 int biYPelsPerMeter; // LONG
149 unsigned int biClrUsed; // DWORD = 0 or true length of bmiColors[] array. If 0,
150 // then the value of biBitCount determines the
151 // length of the bmiColors[] array.
152 unsigned int biClrImportant; // DWORD
153};
154
156 // Mimics Windows RGBQUAD structure.
157 // For details searh for "RGBQUAD" at http://msdn.microsoft.com/default.asp
158 unsigned char rgbBlue; // BYTE
159 unsigned char rgbGreen; // BYTE
160 unsigned char rgbRed; // BYTE
161 unsigned char rgbReserved; // BYTE
162};
163
165{
166 // Mimics Windows BITMAPINFO structure.
167 // For details searh for "BITMAPINFO" at http://msdn.microsoft.com/default.asp
169 ON_WindowsRGBQUAD bmiColors[1]; // The "[1]" is for the compiler. In
170 // practice this array commonly has
171 // length 0, 3, or 256 and a BITMAPINFO*
172 // points to a contiguous piece of memory
173 // that contains
174 //
175 // BITMAPINFOHEADER
176 // RGBQUAD[length determined by flags]
177 // unsigned char[biSizeImage]
178 //
179 // See the ON_WindowsBITMAPINFOHEADER comments
180 // and http://msdn.microsoft.com/default.asp
181 // for more details.
182};
183
184#endif
185
186// OBSOLETE // class ON_OpenGLBitmap;
187
189{
191 // Uncompressed 8 bpp, 24 bpp, or 32 bpp Windows device
192 // independent bitmaps (DIB)
193public:
194
198
200
201 void EmergencyDestroy();
202 void Destroy();
203
204 bool Create(
205 int, // width
206 int, // height
207 int // bits per pixel ( 1, 2, 4, 8, 16, 24, or 32 )
208 );
209
210 /*
211 Description:
212 Tests an object to see if its data members are correctly
213 initialized.
214 Parameters:
215 text_log - [in] if the object is not valid and text_log
216 is not NULL, then a brief englis description of the
217 reason the object is not valid is appened to the log.
218 The information appended to text_log is suitable for
219 low-level debugging purposes by programmers and is
220 not intended to be useful as a high level user
221 interface tool.
222 Returns:
223 @untitled table
224 true object is valid
225 false object is invalid, uninitialized, etc.
226 Remarks:
227 Overrides virtual ON_Object::IsValid
228 */
229 ON_BOOL32 IsValid( ON_TextLog* text_log = NULL ) const;
230
231 ON_BOOL32 Write( ON_BinaryArchive& ) const; // writes compressed image
232 ON_BOOL32 Read( ON_BinaryArchive& ); // reads compressed image
233 bool WriteCompressed( ON_BinaryArchive& ) const;
234 bool ReadCompressed( ON_BinaryArchive& );
235 bool WriteUncompressed( ON_BinaryArchive& ) const;
236 bool ReadUncompressed( ON_BinaryArchive& );
237
238 int Width() const;
239 int Height() const; // >0 means it's a bottom-up bitmap with origin at lower right
240 // <0 means it's a top-down bitmap with origin at upper left
241
242 int PaletteColorCount() const; // number of colors in palette
243 int SizeofPalette() const; // number of bytes in palette
244 int BitsPerPixel() const;
245 //int SizeofPixel() const; // number of bytes per pixel
246 int SizeofScan() const; // number of bytes per scan line
247 int SizeofImage() const; // number of bytes in image
248
249 unsigned char* Bits(
250 int // index of scan line
251 );
252 const unsigned char* Bits(
253 int // index of scan line
254 ) const;
255
256 //int PaletteIndex( ON_Color ) const; // for 8bpp bitmaps
257
258 ON_Color Pixel(
259 int, // 0 <= i < width
260 int // 0 <= j < height
261 ) const;
262 ON_Color Pixel(
263 int, // 0 <= i < width
264 const unsigned char* // value of Bits( j )
265 ) const;
266
267 //ON_BOOL32 SetColor( // sets entire map to specified color
268 // ON_Color
269 // );
270
271#if defined(ON_OS_WINDOWS_GDI)
272
273 /*
274 Description:
275 Create an ON_WindowsBitmap from a contiguous bitmap.
276 Copies src.
277 Parameters:
278 src - [in] contiguous Windows device independent bitmap.
279 Remarks:
280 If the current Windows BITMAPINFO is identical to ON_WindowsBITMAPINFO,
281 then the result of this call is identical to
282
283 int color_count = number of colors in bitmap's palette;
284 ON_WindowsBitmap::Create( &src, &src.bmiColors[color_count], true ).
285
286 See Also:
287 ON_WindowsBitmap::Create
288 */
289 ON_WindowsBitmap( const BITMAPINFO& src );
290
291 /*
292 Description:
293 Create an ON_WindowsBitmap from a contiguous bitmap.
294 Shares bitmap memory with src.
295 Parameters:
296 src - [in] contiguous Windows device independent bitmap.
297 See Also:
298 ON_WindowsBitmap::Create
299 Remarks:
300 ~ON_WindowsBitmap will not delete src.
301 */
302 ON_WindowsBitmap( const BITMAPINFO* src );
303
304 /*
305 Description:
306 Create an ON_WindowsBitmap from a contiguous bitmap.
307 Copies src.
308 Parameters:
309 src - [in] contiguous Windows device independent bitmap.
310 See Also:
311 ON_WindowsBitmap::Create
312 */
313 ON_WindowsBitmap& operator=( const BITMAPINFO& src );
314
315
316 // OBSOLETE - just use the m_bmi pointer
317 //__declspec(deprecated) BITMAPINFO* Convert();
318
319 /*
320 Description:
321 Create and ON_WindowsBitmap from a Windows BITMAPINFO pointer
322 and a pointer to the bits.
323
324 This is intended to make it easy to write compressed bimaps.
325 For ON_WindowsBitmap classes created with ON_WindowsBitmap::Share,
326 ON_WindowsBitmap::Destroy and ~ON_WindowsBitmap will
327 not free the bmi and bits memory.
328
329 Parameters:
330 bmi - [in] valid BITMAPINFO
331 bits - [in] bits for BITMAPINFO
332 bCopy - [in] If true, the bmi and bits are copied into a contiguous
333 bitmap that will be deleted by ~ON_WindowsBitmap.
334 If false, the m_bmi and m_bits pointers on this class
335 are simply set to bmi and bits. In this case,
336 ~ON_WindowsBitmap will not free the bmi or bits
337 memory.
338
339 Example:
340
341 ON_BinaryArchive archive = ...;
342 BITMAPINFO* bmi = 0;
343 unsigned char* bits = 0;
344 int color_count = ...; // number of colors in palette
345
346 int sizeof_palette = sizeof(bmi->bmiColors[0]) * color_count;
347
348 BITMAPINFO* bmi = (LPBITMAPINFO)calloc( 1, sizeof(*bmi) + sizeof_palette );
349
350 bmi->bmiHeader.biSize = sizeof(bmi->bmiHeader);
351 bmi->bmiHeader.biWidth = width;
352 bmi->bmiHeader.biHeight = height;
353 bmi->bmiHeader.biPlanes = 1;
354 bmi->bmiHeader.biBitCount = (USHORT)color_depth;
355 bmi->bmiHeader.biCompression = BI_RGB;
356 bmi->bmiHeader.biXPelsPerMeter = 0;
357 bmi->bmiHeader.biYPelsPerMeter = 0;
358 bmi->bmiHeader.biClrUsed = 0;
359 bmi->bmiHeader.biClrImportant = 0;
360 bmi->bmiHeader.biSizeImage = GetStorageSize();
361
362 // initialize palette
363 ...
364
365 HBITMAP hbm = ::CreateDIBSection( NULL, bmi, ..., (LPVOID*)&bits, NULL, 0);
366
367 {
368 // Use ON_WindowsBitmap to write a compressed bitmap to
369 // archive. Does not modify bmi or bits.
370 ON_WindowsBitmap onbm;
371 onbm.Create(bmi,bit,false);
372 onbm.Write( arcive );
373 }
374
375 */
376 bool Create( const BITMAPINFO* bmi,
377 const unsigned char* bits,
378 bool bCopy
379 );
380
381#endif
382
383 /*
384 Returns:
385 True if m_bmi and m_bits are in a single contiguous
386 block of memory.
387 False if m_bmi and m_bits are in two blocks of memory.
388 */
389 bool IsContiguous() const;
390
391#if defined(ON_OS_WINDOWS_GDI)
392 BITMAPINFO* m_bmi;
393#else
395#endif
396
397 unsigned char* m_bits;
398
399private:
400 int m_bFreeBMI; // 0 m_bmi and m_bits are not freed by ON_WindowsBitmap::Destroy
401 // 1 m_bmi memory is freed by ON_WindowsBitmap::Destroy
402 // 2 m_bits memory is freed by ON_WindowsBitmap::Destroy
403 // 3 m_bmi and m_bits memory is freed by ON_WindowsBitmap::Destroy
404};
405
406/*
407Description:
408 ON_WindowsBitmapEx is identical to ON_WindowsBitmap except that
409 it's Read/Write functions save bitmap names.
410*/
412{
414public:
417 ON_BOOL32 Write( ON_BinaryArchive& ) const; // writes compressed image
418 ON_BOOL32 Read( ON_BinaryArchive& ); // reads compressed image
419};
420
422{
424public:
427 void EmergencyDestroy();
428 void Destroy();
429 void Create( int sizeof_buffer );
430
431 ON_BOOL32 IsValid( ON_TextLog* text_log = NULL ) const;
432
435
436 int Width() const;
437 int Height() const;
438 int BitsPerPixel() const;
439 int SizeofScan() const;
440 int SizeofImage() const;
441 unsigned char* Bits(int);
442 const unsigned char* Bits(int) const;
443
444 void* m_buffer;
446 int m_free_buffer; // 1 = ~ON_EmbeddedBitmap will onfree m_buffer.
447 ON__UINT32 m_biffer_crc32; // 32 bit crc from ON_CRC32
448};
449
450// class ON_CLASS ON_OpenGLBitmap ...
451// OBSOLETE - See SourceSafe version 6 for old definition
452
453
454#endif
Definition opennurbs_archive.h:152
Definition opennurbs_bitmap.h:28
virtual const unsigned char * Bits(int) const =0
virtual int Width() const =0
virtual int SizeofScan() const =0
virtual unsigned char * Bits(int)=0
ON_wString m_bitmap_name
Definition opennurbs_bitmap.h:73
ON_UUID m_bitmap_id
Definition opennurbs_bitmap.h:71
ON_wString m_bitmap_filename
Definition opennurbs_bitmap.h:74
ON_OBJECT_DECLARE(ON_Bitmap)
virtual int Height() const =0
virtual int SizeofImage() const =0
virtual int BitsPerPixel() const =0
int m_bitmap_index
Definition opennurbs_bitmap.h:72
Definition opennurbs_color.h:24
Definition opennurbs_bitmap.h:422
ON_OBJECT_DECLARE(ON_EmbeddedBitmap)
void * m_buffer
Definition opennurbs_bitmap.h:444
size_t m_sizeof_buffer
Definition opennurbs_bitmap.h:445
ON__UINT32 m_biffer_crc32
Definition opennurbs_bitmap.h:447
int m_free_buffer
Definition opennurbs_bitmap.h:446
Definition opennurbs_object.h:393
virtual void Dump(ON_TextLog &) const
Definition opennurbs_object.cpp:1695
virtual ON_BOOL32 IsValid(ON_TextLog *text_log=NULL) const =0
virtual ON_BOOL32 Read(ON_BinaryArchive &binary_archive)
Definition opennurbs_object.cpp:1734
virtual ON_UUID ModelObjectId() const
Definition opennurbs_object.cpp:1622
ON_Object & operator=(const ON_Object &)
Definition opennurbs_object.cpp:1362
virtual ON_BOOL32 Write(ON_BinaryArchive &binary_archive) const
Definition opennurbs_object.cpp:1714
Definition opennurbs_textlog.h:20
Definition opennurbs_uuid.h:31
Definition opennurbs_bitmap.h:412
ON_OBJECT_DECLARE(ON_WindowsBitmapEx)
Definition opennurbs_bitmap.h:189
int m_bFreeBMI
Definition opennurbs_bitmap.h:400
unsigned char * m_bits
Definition opennurbs_bitmap.h:397
struct ON_WindowsBITMAPINFO * m_bmi
Definition opennurbs_bitmap.h:394
ON_OBJECT_DECLARE(ON_WindowsBitmap)
Definition opennurbs_string.h:392
#define ON_CLASS
Definition opennurbs_defines.h:91
#define NULL
Definition opennurbs_system.h:256
int ON_BOOL32
Definition opennurbs_system.h:362
unsigned int ON__UINT32
Definition opennurbs_system.h:326
Definition opennurbs_bitmap.h:93
unsigned int biCompression
Definition opennurbs_bitmap.h:132
int biYPelsPerMeter
Definition opennurbs_bitmap.h:148
unsigned int biSize
Definition opennurbs_bitmap.h:94
unsigned int biSizeImage
Definition opennurbs_bitmap.h:146
unsigned int biClrUsed
Definition opennurbs_bitmap.h:149
unsigned int biClrImportant
Definition opennurbs_bitmap.h:152
int biHeight
Definition opennurbs_bitmap.h:96
unsigned short biPlanes
Definition opennurbs_bitmap.h:101
int biXPelsPerMeter
Definition opennurbs_bitmap.h:147
unsigned short biBitCount
Definition opennurbs_bitmap.h:103
int biWidth
Definition opennurbs_bitmap.h:95
Definition opennurbs_bitmap.h:165
ON_WindowsBITMAPINFOHEADER bmiHeader
Definition opennurbs_bitmap.h:168
ON_WindowsRGBQUAD bmiColors[1]
Definition opennurbs_bitmap.h:169
Definition opennurbs_bitmap.h:155
unsigned char rgbGreen
Definition opennurbs_bitmap.h:159
unsigned char rgbReserved
Definition opennurbs_bitmap.h:161
unsigned char rgbRed
Definition opennurbs_bitmap.h:160
unsigned char rgbBlue
Definition opennurbs_bitmap.h:158