1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: wxImage BMP handler
4 // Author: Robert Roebling
6 // Copyright: (c) Robert Roebling
7 // Licence: wxWindows licence
8 /////////////////////////////////////////////////////////////////////////////
11 #pragma implementation "imagbmp.h"
14 // For compilers that support precompilation, includes "wx.h".
15 #include "wx/wxprec.h"
25 #include "wx/imagbmp.h"
26 #include "wx/bitmap.h"
30 #include "wx/filefn.h"
31 #include "wx/wfstream.h"
33 #include "wx/module.h"
34 #include "wx/quantize.h"
49 //-----------------------------------------------------------------------------
51 //-----------------------------------------------------------------------------
53 IMPLEMENT_DYNAMIC_CLASS(wxBMPHandler
,wxImageHandler
)
59 bool wxBMPHandler::SaveFile(wxImage
*image
,
60 wxOutputStream
& stream
,
63 wxCHECK_MSG( image
, FALSE
, _T("invalid pointer in wxBMPHandler::SaveFile") );
67 if (verbose
) wxLogError(_("BMP: Couldn't save invalid image."));
71 // get the format of the BMP file to save, else use 24bpp
72 unsigned format
= wxBMP_24BPP
;
73 if (image
->HasOption(wxBMP_FORMAT
))
74 format
= image
->GetOptionInt(wxBMP_FORMAT
);
76 unsigned bpp
; // # of bits per pixel
77 int palette_size
; // # of color map entries, ie. 2^bpp colors
79 // set the bpp and appropriate palette_size, and do additional checks
80 if ((format
== wxBMP_1BPP
) || (format
== wxBMP_1BPP_BW
))
85 else if (format
== wxBMP_4BPP
)
90 else if ((format
== wxBMP_8BPP
) || (format
== wxBMP_8BPP_GREY
) ||
91 (format
== wxBMP_8BPP_RED
) || (format
== wxBMP_8BPP_PALETTE
))
93 // need to set a wxPalette to use this, HOW TO CHECK IF VALID, SIZE?
94 if ((format
== wxBMP_8BPP_PALETTE
)
96 && !image
->HasPalette()
97 #endif // wxUSE_PALETTE
101 wxLogError(_("BMP: wImage doesn't have own wxPalette."));
107 else // you get 24bpp
109 format
= wxBMP_24BPP
;
114 unsigned width
= image
->GetWidth();
115 unsigned row_padding
= (4 - int(width
*bpp
/8.0) % 4) % 4; // # bytes to pad to dword
116 unsigned row_width
= int(width
* bpp
/8.0) + row_padding
; // # of bytes per row
121 wxUint16 magic
; // format magic, always 'BM'
122 wxUint32 filesize
; // total file size, inc. headers
123 wxUint32 reserved
; // for future use
124 wxUint32 data_offset
; // image data offset in the file
127 wxUint32 bih_size
; // 2nd part's size
128 wxUint32 width
, height
; // bitmap's dimensions
129 wxUint16 planes
; // num of planes
130 wxUint16 bpp
; // bits per pixel
131 wxUint32 compression
; // compression method
132 wxUint32 size_of_bmp
; // size of the bitmap
133 wxUint32 h_res
, v_res
; // image resolution in dpi
134 wxUint32 num_clrs
; // number of colors used
135 wxUint32 num_signif_clrs
;// number of significant colors
138 wxUint32 hdr_size
= 14/*BitmapHeader*/ + 40/*BitmapInfoHeader*/;
140 hdr
.magic
= wxUINT16_SWAP_ON_BE(0x4D42/*'BM'*/);
141 hdr
.filesize
= wxUINT32_SWAP_ON_BE( hdr_size
+ palette_size
*4 +
142 row_width
* image
->GetHeight() );
144 hdr
.data_offset
= wxUINT32_SWAP_ON_BE(hdr_size
+ palette_size
*4);
146 hdr
.bih_size
= wxUINT32_SWAP_ON_BE(hdr_size
- 14);
147 hdr
.width
= wxUINT32_SWAP_ON_BE(image
->GetWidth());
148 hdr
.height
= wxUINT32_SWAP_ON_BE(image
->GetHeight());
149 hdr
.planes
= wxUINT16_SWAP_ON_BE(1); // always 1 plane
150 hdr
.bpp
= wxUINT16_SWAP_ON_BE(bpp
);
151 hdr
.compression
= 0; // RGB uncompressed
152 hdr
.size_of_bmp
= wxUINT32_SWAP_ON_BE(row_width
* image
->GetHeight());
153 hdr
.h_res
= hdr
.v_res
= wxUINT32_SWAP_ON_BE(72); // 72dpi is standard
154 hdr
.num_clrs
= wxUINT32_SWAP_ON_BE(palette_size
); // # colors in colormap
155 hdr
.num_signif_clrs
= 0; // all colors are significant
157 if (// VS: looks ugly but compilers tend to do ugly things with structs,
158 // like aligning hdr.filesize's ofset to dword :(
159 // VZ: we should add padding then...
160 !stream
.Write(&hdr
.magic
, 2) ||
161 !stream
.Write(&hdr
.filesize
, 4) ||
162 !stream
.Write(&hdr
.reserved
, 4) ||
163 !stream
.Write(&hdr
.data_offset
, 4) ||
164 !stream
.Write(&hdr
.bih_size
, 4) ||
165 !stream
.Write(&hdr
.width
, 4) ||
166 !stream
.Write(&hdr
.height
, 4) ||
167 !stream
.Write(&hdr
.planes
, 2) ||
168 !stream
.Write(&hdr
.bpp
, 2) ||
169 !stream
.Write(&hdr
.compression
, 4) ||
170 !stream
.Write(&hdr
.size_of_bmp
, 4) ||
171 !stream
.Write(&hdr
.h_res
, 4) ||
172 !stream
.Write(&hdr
.v_res
, 4) ||
173 !stream
.Write(&hdr
.num_clrs
, 4) ||
174 !stream
.Write(&hdr
.num_signif_clrs
, 4)
178 wxLogError(_("BMP: Couldn't write the file header."));
182 wxPalette
*palette
= NULL
; // entries for quantized images
183 wxUint8
*rgbquad
= NULL
; // for the RGBQUAD bytes for the colormap
184 wxImage
*q_image
= NULL
; // destination for quantized image
186 // if <24bpp use quantization to reduce colors for *some* of the formats
187 if ( (format
== wxBMP_1BPP
) || (format
== wxBMP_4BPP
) ||
188 (format
== wxBMP_8BPP
) || (format
== wxBMP_8BPP_PALETTE
))
190 // make a new palette and quantize the image
191 if (format
!= wxBMP_8BPP_PALETTE
)
193 q_image
= new wxImage();
195 // I get a delete error using Quantize when desired colors > 236
196 int quantize
= ((palette_size
> 236) ? 236 : palette_size
);
197 // fill the destination too, it gives much nicer 4bpp images
198 wxQuantize::Quantize( *image
, *q_image
, &palette
, quantize
, 0,
199 wxQUANTIZE_FILL_DESTINATION_IMAGE
);
204 palette
= new wxPalette(image
->GetPalette());
205 #endif // wxUSE_PALETTE
209 unsigned char r
, g
, b
;
210 rgbquad
= new wxUint8
[palette_size
*4];
212 for (i
=0; i
<palette_size
; i
++)
215 if (!palette
->GetRGB( i
, &r
, &g
, &b
))
216 #endif // wxUSE_PALETTE
225 // make a 256 entry greyscale colormap or 2 entry black & white
226 else if ((format
== wxBMP_8BPP_GREY
) || (format
== wxBMP_8BPP_RED
) ||
227 (format
== wxBMP_1BPP_BW
))
230 rgbquad
= new wxUint8
[palette_size
*4];
232 for (i
=0; i
<palette_size
; i
++)
234 // if 1BPP_BW then just 0 and 255 then exit
235 if (( i
> 0) && (format
== wxBMP_1BPP_BW
)) i
= 255;
243 // if the colormap was made, then it needs to be written
246 if (!stream
.Write(rgbquad
, palette_size
*4))
249 wxLogError(_("BMP: Couldn't write RGB color map."));
253 #endif // wxUSE_PALETTE
260 // pointer to the image data, use quantized if available
261 wxUint8
*data
= (wxUint8
*) image
->GetData();
262 if (q_image
) if (q_image
->Ok()) data
= (wxUint8
*) q_image
->GetData();
264 wxUint8
*buffer
= new wxUint8
[row_width
];
265 memset(buffer
, 0, row_width
);
269 for (y
= image
->GetHeight() -1 ; y
>= 0; y
--)
271 if (format
== wxBMP_24BPP
) // 3 bytes per pixel red,green,blue
273 for (x
= 0; x
< width
; x
++)
275 pixel
= 3*(y
*width
+ x
);
277 buffer
[3*x
] = data
[pixel
+2];
278 buffer
[3*x
+ 1] = data
[pixel
+1];
279 buffer
[3*x
+ 2] = data
[pixel
];
282 else if ((format
== wxBMP_8BPP
) || // 1 byte per pixel in color
283 (format
== wxBMP_8BPP_PALETTE
))
285 for (x
= 0; x
< width
; x
++)
287 pixel
= 3*(y
*width
+ x
);
289 buffer
[x
] = palette
->GetPixel( data
[pixel
],
293 // FIXME: what should this be? use some std palette maybe?
295 #endif // wxUSE_PALETTE
298 else if (format
== wxBMP_8BPP_GREY
) // 1 byte per pix, rgb ave to grey
300 for (x
= 0; x
< width
; x
++)
302 pixel
= 3*(y
*width
+ x
);
303 buffer
[x
] = (wxUint8
)(.299*data
[pixel
] +
308 else if (format
== wxBMP_8BPP_RED
) // 1 byte per pixel, red as greys
310 for (x
= 0; x
< width
; x
++)
312 buffer
[x
] = (wxUint8
)data
[3*(y
*width
+ x
)];
315 else if (format
== wxBMP_4BPP
) // 4 bpp in color
317 for (x
= 0; x
< width
; x
+=2)
319 pixel
= 3*(y
*width
+ x
);
321 // fill buffer, ignore if > width
324 ((wxUint8
)palette
->GetPixel(data
[pixel
],
326 data
[pixel
+2]) << 4) |
329 : ((wxUint8
)palette
->GetPixel(data
[pixel
+3],
333 // FIXME: what should this be? use some std palette maybe?
335 #endif // wxUSE_PALETTE
338 else if (format
== wxBMP_1BPP
) // 1 bpp in "color"
340 for (x
= 0; x
< width
; x
+=8)
342 pixel
= 3*(y
*width
+ x
);
345 buffer
[x
/8] = ((wxUint8
)palette
->GetPixel(data
[pixel
], data
[pixel
+1], data
[pixel
+2]) << 7) |
346 (((x
+1) > width
) ? 0 : ((wxUint8
)palette
->GetPixel(data
[pixel
+3], data
[pixel
+4], data
[pixel
+5]) << 6)) |
347 (((x
+2) > width
) ? 0 : ((wxUint8
)palette
->GetPixel(data
[pixel
+6], data
[pixel
+7], data
[pixel
+8]) << 5)) |
348 (((x
+3) > width
) ? 0 : ((wxUint8
)palette
->GetPixel(data
[pixel
+9], data
[pixel
+10], data
[pixel
+11]) << 4)) |
349 (((x
+4) > width
) ? 0 : ((wxUint8
)palette
->GetPixel(data
[pixel
+12], data
[pixel
+13], data
[pixel
+14]) << 3)) |
350 (((x
+5) > width
) ? 0 : ((wxUint8
)palette
->GetPixel(data
[pixel
+15], data
[pixel
+16], data
[pixel
+17]) << 2)) |
351 (((x
+6) > width
) ? 0 : ((wxUint8
)palette
->GetPixel(data
[pixel
+18], data
[pixel
+19], data
[pixel
+20]) << 1)) |
352 (((x
+7) > width
) ? 0 : ((wxUint8
)palette
->GetPixel(data
[pixel
+21], data
[pixel
+22], data
[pixel
+23]) ));
354 // FIXME: what should this be? use some std palette maybe?
356 #endif // wxUSE_PALETTE
359 else if (format
== wxBMP_1BPP_BW
) // 1 bpp B&W colormap from red color ONLY
361 for (x
= 0; x
< width
; x
+=8)
363 pixel
= 3*(y
*width
+ x
);
366 (((wxUint8
)(data
[pixel
] /128.)) << 7) |
367 ( ((x
+1) > width
) ? 0 : (((wxUint8
)(data
[pixel
+3] /128.)) << 6)) |
368 ( ((x
+2) > width
) ? 0 : (((wxUint8
)(data
[pixel
+6] /128.)) << 5)) |
369 ( ((x
+3) > width
) ? 0 : (((wxUint8
)(data
[pixel
+9] /128.)) << 4)) |
370 ( ((x
+4) > width
) ? 0 : (((wxUint8
)(data
[pixel
+12]/128.)) << 3)) |
371 ( ((x
+5) > width
) ? 0 : (((wxUint8
)(data
[pixel
+15]/128.)) << 2)) |
372 ( ((x
+6) > width
) ? 0 : (((wxUint8
)(data
[pixel
+18]/128.)) << 1)) |
373 ( ((x
+7) > width
) ? 0 : (((wxUint8
)(data
[pixel
+21]/128.)) ));
377 if (!stream
.Write(buffer
, row_width
))
380 wxLogError(_("BMP: Couldn't write data."));
384 #endif // wxUSE_PALETTE
392 #endif // wxUSE_PALETTE
407 #define BI_BITFIELDS 3
410 #define poffset (line * width * 3 + column * 3)
416 wxUint8 bWidth
; // Width of the image
417 wxUint8 bHeight
; // Height of the image (times 2)
418 wxUint8 bColorCount
; // Number of colors in image (0 if >=8bpp)
419 wxUint8 bReserved
; // Reserved
420 wxUint16 wPlanes
; // Color Planes
421 wxUint16 wBitCount
; // Bits per pixel
422 wxUint32 dwBytesInRes
; // how many bytes in this resource?
423 wxUint32 dwImageOffset
; // where in the file is this image
429 wxUint16 idReserved
; // Reserved
430 wxUint16 idType
; // resource type (1 for icons)
431 wxUint16 idCount
; // how many images?
435 bool wxBMPHandler::DoLoadDib (wxImage
* image
, int width
, int height
, int bpp
, int ncolors
, int comp
,
436 off_t bmpOffset
, wxInputStream
& stream
,
437 bool verbose
, bool IsBmp
, bool hasPalette
)
440 wxInt32 aDword
, rmask
= 0, gmask
= 0, bmask
= 0;
441 int rshift
= 0, gshift
= 0, bshift
= 0;
448 // allocate space for palette if needed
451 unsigned char r
, g
, b
;
457 cmap
= (struct _cmap
*)malloc(sizeof(struct _cmap
) * ncolors
);
461 wxLogError( _("Loading DIB : Couldn't allocate memory.") );
468 // destroy existing here instead of
470 image
->Create( width
, height
);
471 unsigned char *ptr
= image
->GetData();
475 wxLogError( _("Loading DIB : Couldn't allocate memory.") );
481 * Reading the palette, if it exists.
483 if (bpp
< 16 && ncolors
!= 0)
485 unsigned char* r
= new unsigned char[ncolors
];
486 unsigned char* g
= new unsigned char[ncolors
];
487 unsigned char* b
= new unsigned char[ncolors
];
488 for (int j
= 0; j
< ncolors
; j
++)
492 stream
.Read( bbuf
, 4 );
503 //used in reading .ico file mask
504 r
[j
] = cmap
[j
].r
= j
* 255;
505 g
[j
] = cmap
[j
].g
= j
* 255;
506 b
[j
] = cmap
[j
].b
= j
* 255;
511 // Set the palette for the wxImage
512 image
->SetPalette(wxPalette(ncolors
, r
, g
, b
));
513 #endif // wxUSE_PALETTE
519 else if (bpp
== 16 || bpp
== 32)
521 if (comp
== BI_BITFIELDS
)
524 stream
.Read( dbuf
, 4 * 3 );
525 bmask
= wxINT32_SWAP_ON_BE( dbuf
[0] );
526 gmask
= wxINT32_SWAP_ON_BE( dbuf
[1] );
527 rmask
= wxINT32_SWAP_ON_BE( dbuf
[2] );
528 /* find shift amount.. ugly, but i can't think of a better way */
529 for (bit
= 0; bit
< bpp
; bit
++)
531 if (bmask
& (1 << bit
))
533 if (gmask
& (1 << bit
))
535 if (rmask
& (1 << bit
))
560 * Reading the image data
562 if ( IsBmp
) stream
.SeekI( bmpOffset
); // else icon, just carry on
564 unsigned char *data
= ptr
;
566 /* set the whole image to the background color */
567 if (bpp
< 16 && (comp
== BI_RLE4
|| comp
== BI_RLE8
))
569 for (int i
= 0; i
< width
* height
; i
++)
580 int linesize
= ((width
* bpp
+ 31) / 32) * 4;
582 /* BMPs are stored upside down */
583 for (line
= (height
- 1); line
>= 0; line
--)
586 for (column
= 0; column
< width
;)
592 aByte
= stream
.GetC();
596 for (bit
= 0; bit
< 8 && column
< width
; bit
++)
598 index
= ((aByte
& (0x80 >> bit
)) ? 1 : 0);
599 ptr
[poffset
] = cmap
[index
].r
;
600 ptr
[poffset
+ 1] = cmap
[index
].g
;
601 ptr
[poffset
+ 2] = cmap
[index
].b
;
610 wxLogError( _("DIB Header: Cannot deal with 4bit encoded yet.") );
618 for (nibble
= 0; nibble
< 2 && column
< width
; nibble
++)
620 index
= ((aByte
& (0xF0 >> nibble
* 4)) >> (!nibble
* 4));
623 ptr
[poffset
] = cmap
[index
].r
;
624 ptr
[poffset
+ 1] = cmap
[index
].g
;
625 ptr
[poffset
+ 2] = cmap
[index
].b
;
636 aByte
= stream
.GetC();
641 /* column = width; */
650 aByte
= stream
.GetC();
652 linepos
= column
* bpp
/ 8;
653 aByte
= stream
.GetC();
658 int absolute
= aByte
;
659 for (int k
= 0; k
< absolute
; k
++)
662 aByte
= stream
.GetC();
663 ptr
[poffset
] = cmap
[aByte
].r
;
664 ptr
[poffset
+ 1] = cmap
[aByte
].g
;
665 ptr
[poffset
+ 2] = cmap
[aByte
].b
;
669 aByte
= stream
.GetC();
674 for (int l
= 0; l
< first
&& column
< width
; l
++)
676 ptr
[poffset
] = cmap
[aByte
].r
;
677 ptr
[poffset
+ 1] = cmap
[aByte
].g
;
678 ptr
[poffset
+ 2] = cmap
[aByte
].b
;
686 ptr
[poffset
] = cmap
[aByte
].r
;
687 ptr
[poffset
+ 1] = cmap
[aByte
].g
;
688 ptr
[poffset
+ 2] = cmap
[aByte
].b
;
690 // linepos += size; seems to be wrong, RR
696 stream
.Read( bbuf
, 3 );
698 ptr
[poffset
] = (unsigned char)bbuf
[2];
699 ptr
[poffset
+ 1] = (unsigned char)bbuf
[1];
700 ptr
[poffset
+ 2] = (unsigned char)bbuf
[0];
706 stream
.Read( &aWord
, 2 );
707 aWord
= wxUINT16_SWAP_ON_BE( aWord
);
709 temp
= (aWord
& rmask
) >> rshift
;
711 temp
= (aWord
& gmask
) >> gshift
;
712 ptr
[poffset
+ 1] = temp
;
713 temp
= (aWord
& bmask
) >> bshift
;
714 ptr
[poffset
+ 2] = temp
;
720 stream
.Read( &aDword
, 4 );
721 aDword
= wxINT32_SWAP_ON_BE( aDword
);
723 temp
= (aDword
& rmask
) >> rshift
;
725 temp
= (aDword
& gmask
) >> gshift
;
726 ptr
[poffset
+ 1] = temp
;
727 temp
= (aDword
& bmask
) >> bshift
;
728 ptr
[poffset
+ 2] = temp
;
732 while ((linepos
< linesize
) && (comp
!= 1) && (comp
!= 2))
734 stream
.Read( &aByte
, 1 );
736 if (stream
.LastError() != wxStream_NOERROR
)
743 image
->SetMask( FALSE
);
745 return stream
.IsOk();
749 bool wxBMPHandler::LoadDib( wxImage
*image
, wxInputStream
& stream
, bool verbose
, bool IsBmp
)
756 offset
= 0; // keep gcc quiet
759 // read the header off the .BMP format file
761 offset
= stream
.TellI();
762 if (offset
== wxInvalidOffset
) offset
= 0;
764 stream
.Read( bbuf
, 2 );
766 stream
.Read( dbuf
, 16 );
770 stream
.Read( dbuf
, 4 );
773 wxInt32 size
= wxINT32_SWAP_ON_BE( dbuf
[0] );
775 offset
= offset
+ wxINT32_SWAP_ON_BE( dbuf
[2] );
777 stream
.Read(dbuf
, 4 * 2);
778 int width
= (int)wxINT32_SWAP_ON_BE( dbuf
[0] );
779 int height
= (int)wxINT32_SWAP_ON_BE( dbuf
[1] );
780 if ( !IsBmp
) height
= height
/ 2; // for icons divide by 2
785 wxLogError( _("DIB Header: Image width > 32767 pixels for file.") );
791 wxLogError( _("DIB Header: Image height > 32767 pixels for file.") );
795 stream
.Read( &aWord
, 2 );
798 int planes = (int)wxUINT16_SWAP_ON_BE( aWord );
800 stream
.Read( &aWord
, 2 );
801 int bpp
= (int)wxUINT16_SWAP_ON_BE( aWord
);
802 if (bpp
!= 1 && bpp
!= 4 && bpp
!= 8 && bpp
!= 16 && bpp
!= 24 && bpp
!= 32)
805 wxLogError( _("DIB Header: Unknown bitdepth in file.") );
809 stream
.Read( dbuf
, 4 * 4 );
810 int comp
= (int)wxINT32_SWAP_ON_BE( dbuf
[0] );
811 if (comp
!= BI_RGB
&& comp
!= BI_RLE4
&& comp
!= BI_RLE8
&& comp
!= BI_BITFIELDS
)
814 wxLogError( _("DIB Header: Unknown encoding in file.") );
818 stream
.Read( dbuf
, 4 * 2 );
819 int ncolors
= (int)wxINT32_SWAP_ON_BE( dbuf
[0] );
822 /* some more sanity checks */
823 if (((comp
== BI_RLE4
) && (bpp
!= 4)) ||
824 ((comp
== BI_RLE8
) && (bpp
!= 8)) ||
825 ((comp
== BI_BITFIELDS
) && (bpp
!= 16 && bpp
!= 32)))
828 wxLogError( _("DIB Header: Encoding doesn't match bitdepth.") );
832 //read DIB; this is the BMP image or the XOR part of an icon image
833 if (!DoLoadDib (image
, width
, height
, bpp
, ncolors
, comp
, offset
, stream
,
834 verbose
, IsBmp
, TRUE
) )
837 wxLogError( _("Error in reading image DIB .") );
843 //read Icon mask which is monochrome
844 //there is no palette, so we will create one
846 if (!DoLoadDib (&mask
, width
, height
, 1, 2, BI_RGB
, offset
, stream
,
847 verbose
, IsBmp
, FALSE
) )
850 wxLogError( _("ICO: Error in reading mask DIB.") );
853 image
->SetMaskFromImage(mask
, 255, 255, 255);
860 bool wxBMPHandler::LoadFile ( wxImage
*image
, wxInputStream
& stream
, bool verbose
, int WXUNUSED(index
) )
863 //Read a single DIB fom the file
864 return LoadDib ( image
, stream
, verbose
, IsBmp
) ;
869 bool wxICOHandler::LoadFile ( wxImage
*image
, wxInputStream
& stream
, bool verbose
, int WXUNUSED(index
) )
871 bool bResult
= FALSE
;
875 stream
.Read (&m_IconDir
, sizeof(m_IconDir
));
876 wxUint16 nIcons
= wxUINT16_SWAP_ON_BE ( m_IconDir
.idCount
) ;
878 //loop round the icons and choose the best one
879 ICONDIRENTRY
* pIconDirEntry
= new ICONDIRENTRY
[nIcons
];
880 ICONDIRENTRY
* pCurrentEntry
= pIconDirEntry
;
884 int iSel
= wxNOT_FOUND
;
885 for (i
=0; i
< nIcons
; i
++ )
887 stream
.Read(pCurrentEntry
, sizeof(ICONDIRENTRY
));
888 //bHeight and bColorCount are wxUint8
889 if (pCurrentEntry
->bWidth
>= wMax
)
891 // see if we have more colors, ==0 indicates > 8bpp
892 if (pCurrentEntry
->bColorCount
== 0 ) pCurrentEntry
->bColorCount
= 255 ;
893 if (pCurrentEntry
->bColorCount
>= colmax
)
896 wMax
= pCurrentEntry
->bWidth
;
897 colmax
= pCurrentEntry
->bColorCount
;
902 if (iSel
== wxNOT_FOUND
)
908 //seek to selected icon
909 pCurrentEntry
= pIconDirEntry
+ iSel
;
910 stream
.SeekI (wxUINT32_SWAP_ON_BE ( pCurrentEntry
-> dwImageOffset
), wxFromStart
) ;
911 bResult
= LoadDib ( image
, stream
, TRUE
, IsBmp
);
913 delete [] pIconDirEntry
;
918 bool wxICOHandler::SaveFile(wxImage
*image
,
919 wxOutputStream
& stream
,
925 bool wxBMPHandler::DoCanRead( wxInputStream
& stream
)
927 unsigned char hdr
[2];
930 stream
.SeekI(-2, wxFromCurrent
);
931 return (hdr
[0] == 'B' && hdr
[1] == 'M');
934 bool wxICOHandler::DoCanRead( wxInputStream
& stream
)
936 unsigned char hdr
[4];
939 stream
.SeekI(-4, wxFromCurrent
);
940 return (hdr
[0] == '\0' && hdr
[1] == '\0' && hdr
[2] == '\1' && hdr
[3] == '\0');
943 #endif // wxUSE_STREAMS
945 #endif // wxUSE_IMAGE