]> git.saurik.com Git - wxWidgets.git/blame - src/common/image.cpp
update digitalmars makefile
[wxWidgets.git] / src / common / image.cpp
CommitLineData
01111366
RR
1/////////////////////////////////////////////////////////////////////////////
2// Name: image.cpp
3// Purpose: wxImage
4// Author: Robert Roebling
5// RCS-ID: $Id$
6// Copyright: (c) Robert Roebling
7// Licence: wxWindows licence
8/////////////////////////////////////////////////////////////////////////////
9
10#ifdef __GNUG__
11#pragma implementation "image.h"
12#endif
13
0b4f9ee3
UU
14// For compilers that support precompilation, includes "wx.h".
15#include "wx/wxprec.h"
16
17#ifdef __BORLANDC__
edccf428 18 #pragma hdrstop
0b4f9ee3
UU
19#endif
20
c96ea657
VS
21#include "wx/defs.h"
22
23#if wxUSE_IMAGE
24
01111366 25#include "wx/image.h"
99c67c77 26#include "wx/bitmap.h"
01111366
RR
27#include "wx/debug.h"
28#include "wx/log.h"
f6fcbb63 29#include "wx/app.h"
dc86cb34 30#include "wx/filefn.h"
3d05544e 31#include "wx/wfstream.h"
b75867a6 32#include "wx/intl.h"
a91b47e8 33#include "wx/module.h"
ed39ff57 34#include "wx/hash.h"
01111366 35
58a8ab88
JS
36// For memcpy
37#include <string.h>
7a632f10 38#include <math.h>
58a8ab88 39
a3ef5bf5 40#ifdef __SALFORDC__
edccf428 41 #undef FAR
a3ef5bf5
JS
42#endif
43
2432b92d 44
01111366
RR
45//-----------------------------------------------------------------------------
46// wxImage
47//-----------------------------------------------------------------------------
48
49class wxImageRefData: public wxObjectRefData
50{
fd0eed64 51public:
edccf428 52 wxImageRefData();
487659e0 53 virtual ~wxImageRefData();
c7abc967 54
dbda9e86
JS
55 int m_width;
56 int m_height;
57 unsigned char *m_data;
487659e0 58
dbda9e86
JS
59 bool m_hasMask;
60 unsigned char m_maskRed,m_maskGreen,m_maskBlue;
487659e0
VZ
61
62 // alpha channel data, may be NULL for the formats without alpha support
63 unsigned char *m_alpha;
64
dbda9e86 65 bool m_ok;
f6bcfd97 66 bool m_static;
487659e0 67
d275c7eb 68#if wxUSE_PALETTE
5e5437e0 69 wxPalette m_palette;
d275c7eb 70#endif // wxUSE_PALETTE
487659e0 71
5e5437e0
JS
72 wxArrayString m_optionNames;
73 wxArrayString m_optionValues;
22f3361e
VZ
74
75 DECLARE_NO_COPY_CLASS(wxImageRefData)
01111366
RR
76};
77
edccf428 78wxImageRefData::wxImageRefData()
01111366 79{
fd0eed64
RR
80 m_width = 0;
81 m_height = 0;
487659e0
VZ
82 m_data =
83 m_alpha = (unsigned char *) NULL;
84
fd0eed64
RR
85 m_maskRed = 0;
86 m_maskGreen = 0;
87 m_maskBlue = 0;
88 m_hasMask = FALSE;
487659e0
VZ
89
90 m_ok = FALSE;
f6bcfd97 91 m_static = FALSE;
01111366
RR
92}
93
edccf428 94wxImageRefData::~wxImageRefData()
01111366 95{
487659e0 96 if ( !m_static )
58c837a4 97 free( m_data );
487659e0
VZ
98
99 free(m_alpha);
01111366
RR
100}
101
102wxList wxImage::sm_handlers;
103
fec19ea9
VS
104wxImage wxNullImage;
105
01111366
RR
106//-----------------------------------------------------------------------------
107
108#define M_IMGDATA ((wxImageRefData *)m_refData)
109
5e5437e0 110IMPLEMENT_DYNAMIC_CLASS(wxImage, wxObject)
01111366
RR
111
112wxImage::wxImage()
113{
114}
115
ff865c13 116wxImage::wxImage( int width, int height, bool clear )
01111366 117{
ff865c13 118 Create( width, height, clear );
01111366
RR
119}
120
f6bcfd97
BP
121wxImage::wxImage( int width, int height, unsigned char* data, bool static_data )
122{
123 Create( width, height, data, static_data );
124}
125
60d43ad8 126wxImage::wxImage( const wxString& name, long type, int index )
01111366 127{
60d43ad8 128 LoadFile( name, type, index );
01111366
RR
129}
130
60d43ad8 131wxImage::wxImage( const wxString& name, const wxString& mimetype, int index )
9e9ee68e 132{
60d43ad8 133 LoadFile( name, mimetype, index );
9e9ee68e
VS
134}
135
e02afc7a 136#if wxUSE_STREAMS
60d43ad8 137wxImage::wxImage( wxInputStream& stream, long type, int index )
3d05544e 138{
60d43ad8 139 LoadFile( stream, type, index );
3d05544e 140}
9e9ee68e 141
60d43ad8 142wxImage::wxImage( wxInputStream& stream, const wxString& mimetype, int index )
9e9ee68e 143{
60d43ad8 144 LoadFile( stream, mimetype, index );
9e9ee68e 145}
e02afc7a 146#endif // wxUSE_STREAMS
3d05544e 147
4698648f 148wxImage::wxImage( const wxImage& image )
1b0674f7 149 : wxObject()
4698648f
VZ
150{
151 Ref(image);
01111366
RR
152}
153
4698648f
VZ
154wxImage::wxImage( const wxImage* image )
155{
156 if (image) Ref(*image);
01111366
RR
157}
158
ff865c13 159void wxImage::Create( int width, int height, bool clear )
01111366 160{
aadaf841
GRG
161 UnRef();
162
fd0eed64 163 m_refData = new wxImageRefData();
c7abc967 164
fd0eed64
RR
165 M_IMGDATA->m_data = (unsigned char *) malloc( width*height*3 );
166 if (M_IMGDATA->m_data)
167 {
ff865c13 168 if (clear) memset(M_IMGDATA->m_data, 0, width*height*3);
c7abc967 169
fd0eed64
RR
170 M_IMGDATA->m_width = width;
171 M_IMGDATA->m_height = height;
172 M_IMGDATA->m_ok = TRUE;
173 }
174 else
175 {
176 UnRef();
177 }
01111366
RR
178}
179
f6bcfd97
BP
180void wxImage::Create( int width, int height, unsigned char* data, bool static_data )
181{
182 UnRef();
183
184 m_refData = new wxImageRefData();
185
186 M_IMGDATA->m_data = data;
187 if (M_IMGDATA->m_data)
188 {
189 M_IMGDATA->m_width = width;
190 M_IMGDATA->m_height = height;
191 M_IMGDATA->m_ok = TRUE;
192 M_IMGDATA->m_static = static_data;
193 }
194 else
195 {
196 UnRef();
197 }
198}
199
01111366
RR
200void wxImage::Destroy()
201{
fd0eed64 202 UnRef();
01111366
RR
203}
204
f6bcfd97
BP
205wxImage wxImage::Copy() const
206{
207 wxImage image;
208
209 wxCHECK_MSG( Ok(), image, wxT("invalid image") );
210
ff865c13 211 image.Create( M_IMGDATA->m_width, M_IMGDATA->m_height, false );
f6bcfd97 212
487659e0 213 unsigned char *data = image.GetData();
f6bcfd97
BP
214
215 wxCHECK_MSG( data, image, wxT("unable to create image") );
216
fdbb06ba
RR
217 image.SetMaskColour( M_IMGDATA->m_maskRed, M_IMGDATA->m_maskGreen, M_IMGDATA->m_maskBlue );
218 image.SetMask( M_IMGDATA->m_hasMask );
f6bcfd97
BP
219
220 memcpy( data, GetData(), M_IMGDATA->m_width*M_IMGDATA->m_height*3 );
221
222 return image;
223}
224
fd9655ad
SC
225wxImage wxImage::ShrinkBy( int xFactor , int yFactor ) const
226{
227 if( xFactor == 1 && yFactor == 1 )
228 return Copy() ;
229
230 wxImage image;
231
232 wxCHECK_MSG( Ok(), image, wxT("invalid image") );
233
234 // can't scale to/from 0 size
235 wxCHECK_MSG( (xFactor > 0) && (yFactor > 0), image,
236 wxT("invalid new image size") );
237
238 long old_height = M_IMGDATA->m_height,
239 old_width = M_IMGDATA->m_width;
240
241 wxCHECK_MSG( (old_height > 0) && (old_width > 0), image,
242 wxT("invalid old image size") );
243
244 long width = old_width / xFactor ;
245 long height = old_height / yFactor ;
246
ff865c13 247 image.Create( width, height, false );
fd9655ad
SC
248
249 char unsigned *data = image.GetData();
250
251 wxCHECK_MSG( data, image, wxT("unable to create image") );
252
253 bool hasMask = false ;
254 unsigned char maskRed = 0;
255 unsigned char maskGreen = 0;
256 unsigned char maskBlue =0 ;
257 if (M_IMGDATA->m_hasMask)
258 {
259 hasMask = true ;
260 maskRed = M_IMGDATA->m_maskRed;
261 maskGreen = M_IMGDATA->m_maskGreen;
262 maskBlue =M_IMGDATA->m_maskBlue ;
263
264 image.SetMaskColour( M_IMGDATA->m_maskRed,
265 M_IMGDATA->m_maskGreen,
266 M_IMGDATA->m_maskBlue );
267 }
268 char unsigned *source_data = M_IMGDATA->m_data;
269 char unsigned *target_data = data;
270
271 for (long y = 0; y < height; y++)
272 {
fd9655ad
SC
273 for (long x = 0; x < width; x++)
274 {
275 unsigned long avgRed = 0 ;
276 unsigned long avgGreen = 0;
277 unsigned long avgBlue = 0;
278 unsigned long counter = 0 ;
279 // determine average
280 for ( int y1 = 0 ; y1 < yFactor ; ++y1 )
281 {
282 long y_offset = (y * yFactor + y1) * old_width;
283 for ( int x1 = 0 ; x1 < xFactor ; ++x1 )
284 {
285 unsigned char *pixel = source_data + 3 * ( y_offset + x * xFactor + x1 ) ;
286 unsigned char red = pixel[0] ;
287 unsigned char green = pixel[1] ;
288 unsigned char blue = pixel[2] ;
289 if ( !hasMask || red != maskRed || green != maskGreen || blue != maskBlue )
290 {
291 avgRed += red ;
292 avgGreen += green ;
293 avgBlue += blue ;
294 counter++ ;
295 }
296 }
297 }
298 if ( counter == 0 )
299 {
300 *(target_data++) = M_IMGDATA->m_maskRed ;
301 *(target_data++) = M_IMGDATA->m_maskGreen ;
302 *(target_data++) = M_IMGDATA->m_maskBlue ;
303 }
304 else
305 {
306 *(target_data++) = avgRed / counter ;
307 *(target_data++) = avgGreen / counter ;
308 *(target_data++) = avgBlue / counter ;
309 }
310 }
311 }
312
313 // In case this is a cursor, make sure the hotspot is scalled accordingly:
314 if ( HasOption(wxIMAGE_OPTION_CUR_HOTSPOT_X) )
315 image.SetOption(wxIMAGE_OPTION_CUR_HOTSPOT_X,
316 (GetOptionInt(wxIMAGE_OPTION_CUR_HOTSPOT_X))/xFactor);
317 if ( HasOption(wxIMAGE_OPTION_CUR_HOTSPOT_Y) )
318 image.SetOption(wxIMAGE_OPTION_CUR_HOTSPOT_Y,
319 (GetOptionInt(wxIMAGE_OPTION_CUR_HOTSPOT_Y))/yFactor);
320
321 return image;
322}
323
ce9a75d2 324wxImage wxImage::Scale( int width, int height ) const
4bc67cc5
RR
325{
326 wxImage image;
c7abc967 327
223d09f6 328 wxCHECK_MSG( Ok(), image, wxT("invalid image") );
c7abc967 329
6721fc38
VZ
330 // can't scale to/from 0 size
331 wxCHECK_MSG( (width > 0) && (height > 0), image,
332 wxT("invalid new image size") );
333
334 long old_height = M_IMGDATA->m_height,
335 old_width = M_IMGDATA->m_width;
336 wxCHECK_MSG( (old_height > 0) && (old_width > 0), image,
337 wxT("invalid old image size") );
c7abc967 338
fd9655ad
SC
339 if ( old_width % width == 0 && old_width >= width &&
340 old_height % height == 0 && old_height >= height )
341 {
342 return ShrinkBy( old_width / width , old_height / height ) ;
343 }
ff865c13 344 image.Create( width, height, false );
c7abc967 345
487659e0 346 unsigned char *data = image.GetData();
c7abc967 347
223d09f6 348 wxCHECK_MSG( data, image, wxT("unable to create image") );
c7abc967 349
4bc67cc5 350 if (M_IMGDATA->m_hasMask)
6721fc38
VZ
351 {
352 image.SetMaskColour( M_IMGDATA->m_maskRed,
353 M_IMGDATA->m_maskGreen,
354 M_IMGDATA->m_maskBlue );
355 }
c7abc967 356
487659e0
VZ
357 unsigned char *source_data = M_IMGDATA->m_data;
358 unsigned char *target_data = data;
c7abc967 359
ff865c13
JS
360 long x_delta = (old_width<<16) / width;
361 long y_delta = (old_height<<16) / height;
c7abc967 362
ff865c13 363 unsigned char* dest_pixel = target_data;
6721fc38 364
ff865c13
JS
365 long y = 0;
366 for ( long j = 0; j < height; j++ )
367 {
368 unsigned char* src_line = &source_data[(y>>16)*old_width*3];
eeca3a46 369
ff865c13
JS
370 long x = 0;
371 for ( long i = 0; i < width; i++ )
eeca3a46 372 {
ff865c13
JS
373 unsigned char* src_pixel = &src_line[(x>>16)*3];
374 dest_pixel[0] = src_pixel[0];
375 dest_pixel[1] = src_pixel[1];
376 dest_pixel[2] = src_pixel[2];
377 dest_pixel += 3;
378 x += x_delta;
eeca3a46 379 }
ff865c13
JS
380
381 y += y_delta;
eeca3a46 382 }
36aac195 383
fd94e8aa
VS
384 // In case this is a cursor, make sure the hotspot is scalled accordingly:
385 if ( HasOption(wxIMAGE_OPTION_CUR_HOTSPOT_X) )
386 image.SetOption(wxIMAGE_OPTION_CUR_HOTSPOT_X,
387 (GetOptionInt(wxIMAGE_OPTION_CUR_HOTSPOT_X)*width)/old_width);
388 if ( HasOption(wxIMAGE_OPTION_CUR_HOTSPOT_Y) )
389 image.SetOption(wxIMAGE_OPTION_CUR_HOTSPOT_Y,
390 (GetOptionInt(wxIMAGE_OPTION_CUR_HOTSPOT_Y)*height)/old_height);
c7abc967 391
4bc67cc5
RR
392 return image;
393}
4698648f 394
f6bcfd97
BP
395wxImage wxImage::Rotate90( bool clockwise ) const
396{
397 wxImage image;
398
399 wxCHECK_MSG( Ok(), image, wxT("invalid image") );
400
ff865c13 401 image.Create( M_IMGDATA->m_height, M_IMGDATA->m_width, false );
f6bcfd97 402
487659e0 403 unsigned char *data = image.GetData();
f6bcfd97
BP
404
405 wxCHECK_MSG( data, image, wxT("unable to create image") );
406
407 if (M_IMGDATA->m_hasMask)
408 image.SetMaskColour( M_IMGDATA->m_maskRed, M_IMGDATA->m_maskGreen, M_IMGDATA->m_maskBlue );
409
410 long height = M_IMGDATA->m_height;
411 long width = M_IMGDATA->m_width;
412
487659e0
VZ
413 unsigned char *source_data = M_IMGDATA->m_data;
414 unsigned char *target_data;
f6bcfd97
BP
415
416 for (long j = 0; j < height; j++)
417 {
418 for (long i = 0; i < width; i++)
419 {
420 if (clockwise)
421 target_data = data + (((i+1)*height) - j - 1)*3;
422 else
423 target_data = data + ((height*(width-1)) + j - (i*height))*3;
424 memcpy( target_data, source_data, 3 );
425 source_data += 3;
426 }
427 }
428
429 return image;
430}
431
432wxImage wxImage::Mirror( bool horizontally ) const
433{
434 wxImage image;
435
436 wxCHECK_MSG( Ok(), image, wxT("invalid image") );
437
ff865c13 438 image.Create( M_IMGDATA->m_width, M_IMGDATA->m_height, false );
f6bcfd97 439
487659e0 440 unsigned char *data = image.GetData();
f6bcfd97
BP
441
442 wxCHECK_MSG( data, image, wxT("unable to create image") );
443
444 if (M_IMGDATA->m_hasMask)
445 image.SetMaskColour( M_IMGDATA->m_maskRed, M_IMGDATA->m_maskGreen, M_IMGDATA->m_maskBlue );
446
447 long height = M_IMGDATA->m_height;
448 long width = M_IMGDATA->m_width;
449
487659e0
VZ
450 unsigned char *source_data = M_IMGDATA->m_data;
451 unsigned char *target_data;
f6bcfd97
BP
452
453 if (horizontally)
454 {
455 for (long j = 0; j < height; j++)
456 {
457 data += width*3;
458 target_data = data-3;
459 for (long i = 0; i < width; i++)
460 {
461 memcpy( target_data, source_data, 3 );
462 source_data += 3;
463 target_data -= 3;
464 }
465 }
466 }
467 else
468 {
469 for (long i = 0; i < height; i++)
470 {
471 target_data = data + 3*width*(height-1-i);
3ca6a5f0 472 memcpy( target_data, source_data, (size_t)3*width );
f6bcfd97
BP
473 source_data += 3*width;
474 }
475 }
476
477 return image;
478}
479
7b2471a0
SB
480wxImage wxImage::GetSubImage( const wxRect &rect ) const
481{
482 wxImage image;
483
223d09f6 484 wxCHECK_MSG( Ok(), image, wxT("invalid image") );
7b2471a0 485
58c837a4
RR
486 wxCHECK_MSG( (rect.GetLeft()>=0) && (rect.GetTop()>=0) && (rect.GetRight()<=GetWidth()) && (rect.GetBottom()<=GetHeight()),
487 image, wxT("invalid subimage size") );
7b2471a0
SB
488
489 int subwidth=rect.GetWidth();
490 const int subheight=rect.GetHeight();
491
ff865c13 492 image.Create( subwidth, subheight, false );
7b2471a0 493
487659e0 494 unsigned char *subdata = image.GetData(), *data=GetData();
7b2471a0 495
223d09f6 496 wxCHECK_MSG( subdata, image, wxT("unable to create image") );
7b2471a0
SB
497
498 if (M_IMGDATA->m_hasMask)
499 image.SetMaskColour( M_IMGDATA->m_maskRed, M_IMGDATA->m_maskGreen, M_IMGDATA->m_maskBlue );
500
501 const int subleft=3*rect.GetLeft();
502 const int width=3*GetWidth();
503 subwidth*=3;
995612e2 504
7b2471a0
SB
505 data+=rect.GetTop()*width+subleft;
506
507 for (long j = 0; j < subheight; ++j)
508 {
509 memcpy( subdata, data, subwidth);
510 subdata+=subwidth;
995612e2 511 data+=width;
7b2471a0
SB
512 }
513
514 return image;
515}
516
f6bcfd97
BP
517void wxImage::Paste( const wxImage &image, int x, int y )
518{
519 wxCHECK_RET( Ok(), wxT("invalid image") );
520 wxCHECK_RET( image.Ok(), wxT("invalid image") );
521
522 int xx = 0;
523 int yy = 0;
524 int width = image.GetWidth();
525 int height = image.GetHeight();
526
527 if (x < 0)
528 {
529 xx = -x;
530 width += x;
531 }
532 if (y < 0)
533 {
534 yy = -y;
535 height += y;
536 }
537
538 if ((x+xx)+width > M_IMGDATA->m_width)
539 width = M_IMGDATA->m_width - (x+xx);
540 if ((y+yy)+height > M_IMGDATA->m_height)
541 height = M_IMGDATA->m_height - (y+yy);
542
543 if (width < 1) return;
544 if (height < 1) return;
545
546 if ((!HasMask() && !image.HasMask()) ||
547 ((HasMask() && image.HasMask() &&
548 (GetMaskRed()==image.GetMaskRed()) &&
549 (GetMaskGreen()==image.GetMaskGreen()) &&
550 (GetMaskBlue()==image.GetMaskBlue()))))
551 {
552 width *= 3;
553 unsigned char* source_data = image.GetData() + xx*3 + yy*3*image.GetWidth();
554 int source_step = image.GetWidth()*3;
555
556 unsigned char* target_data = GetData() + (x+xx)*3 + (y+yy)*3*M_IMGDATA->m_width;
557 int target_step = M_IMGDATA->m_width*3;
558 for (int j = 0; j < height; j++)
559 {
560 memcpy( target_data, source_data, width );
561 source_data += source_step;
562 target_data += target_step;
563 }
aa21b509 564 return;
f6bcfd97 565 }
33ac7e6f 566
aa21b509 567 if (!HasMask() && image.HasMask())
f6bcfd97 568 {
aa21b509
RR
569 unsigned char r = image.GetMaskRed();
570 unsigned char g = image.GetMaskGreen();
571 unsigned char b = image.GetMaskBlue();
33ac7e6f 572
aa21b509
RR
573 width *= 3;
574 unsigned char* source_data = image.GetData() + xx*3 + yy*3*image.GetWidth();
575 int source_step = image.GetWidth()*3;
576
577 unsigned char* target_data = GetData() + (x+xx)*3 + (y+yy)*3*M_IMGDATA->m_width;
578 int target_step = M_IMGDATA->m_width*3;
33ac7e6f 579
aa21b509
RR
580 for (int j = 0; j < height; j++)
581 {
582 for (int i = 0; i < width; i+=3)
583 {
33ac7e6f
KB
584 if ((source_data[i] != r) &&
585 (source_data[i+1] != g) &&
aa21b509
RR
586 (source_data[i+2] != b))
587 {
588 memcpy( target_data+i, source_data+i, 3 );
589 }
33ac7e6f 590 }
aa21b509
RR
591 source_data += source_step;
592 target_data += target_step;
593 }
f6bcfd97
BP
594 }
595}
596
be25e480
RR
597void wxImage::Replace( unsigned char r1, unsigned char g1, unsigned char b1,
598 unsigned char r2, unsigned char g2, unsigned char b2 )
599{
600 wxCHECK_RET( Ok(), wxT("invalid image") );
601
487659e0 602 unsigned char *data = GetData();
06b466c7 603
be25e480
RR
604 const int w = GetWidth();
605 const int h = GetHeight();
606
607 for (int j = 0; j < h; j++)
608 for (int i = 0; i < w; i++)
069d0f27
VZ
609 {
610 if ((data[0] == r1) && (data[1] == g1) && (data[2] == b1))
611 {
612 data[0] = r2;
613 data[1] = g2;
614 data[2] = b2;
615 }
616 data += 3;
617 }
be25e480
RR
618}
619
f515c25a 620wxImage wxImage::ConvertToMono( unsigned char r, unsigned char g, unsigned char b ) const
fec19ea9
VS
621{
622 wxImage image;
623
624 wxCHECK_MSG( Ok(), image, wxT("invalid image") );
625
ff865c13 626 image.Create( M_IMGDATA->m_width, M_IMGDATA->m_height, false );
fec19ea9 627
487659e0 628 unsigned char *data = image.GetData();
fec19ea9
VS
629
630 wxCHECK_MSG( data, image, wxT("unable to create image") );
631
632 if (M_IMGDATA->m_hasMask)
633 {
634 if (M_IMGDATA->m_maskRed == r && M_IMGDATA->m_maskGreen == g &&
635 M_IMGDATA->m_maskBlue == b)
636 image.SetMaskColour( 255, 255, 255 );
637 else
638 image.SetMaskColour( 0, 0, 0 );
639 }
640
641 long size = M_IMGDATA->m_height * M_IMGDATA->m_width;
642
487659e0
VZ
643 unsigned char *srcd = M_IMGDATA->m_data;
644 unsigned char *tard = image.GetData();
fec19ea9
VS
645
646 for ( long i = 0; i < size; i++, srcd += 3, tard += 3 )
647 {
648 if (srcd[0] == r && srcd[1] == g && srcd[2] == b)
649 tard[0] = tard[1] = tard[2] = 255;
650 else
651 tard[0] = tard[1] = tard[2] = 0;
652 }
653
654 return image;
655}
656
ef539066
RR
657void wxImage::SetRGB( int x, int y, unsigned char r, unsigned char g, unsigned char b )
658{
223d09f6 659 wxCHECK_RET( Ok(), wxT("invalid image") );
c7abc967 660
ef539066
RR
661 int w = M_IMGDATA->m_width;
662 int h = M_IMGDATA->m_height;
c7abc967 663
223d09f6 664 wxCHECK_RET( (x>=0) && (y>=0) && (x<w) && (y<h), wxT("invalid image index") );
c7abc967 665
ef539066 666 long pos = (y * w + x) * 3;
c7abc967 667
ef539066
RR
668 M_IMGDATA->m_data[ pos ] = r;
669 M_IMGDATA->m_data[ pos+1 ] = g;
670 M_IMGDATA->m_data[ pos+2 ] = b;
671}
672
f6bcfd97 673unsigned char wxImage::GetRed( int x, int y ) const
ef539066 674{
223d09f6 675 wxCHECK_MSG( Ok(), 0, wxT("invalid image") );
c7abc967 676
ef539066
RR
677 int w = M_IMGDATA->m_width;
678 int h = M_IMGDATA->m_height;
c7abc967 679
223d09f6 680 wxCHECK_MSG( (x>=0) && (y>=0) && (x<w) && (y<h), 0, wxT("invalid image index") );
c7abc967 681
ef539066 682 long pos = (y * w + x) * 3;
c7abc967 683
ef539066
RR
684 return M_IMGDATA->m_data[pos];
685}
686
f6bcfd97 687unsigned char wxImage::GetGreen( int x, int y ) const
ef539066 688{
223d09f6 689 wxCHECK_MSG( Ok(), 0, wxT("invalid image") );
c7abc967 690
ef539066
RR
691 int w = M_IMGDATA->m_width;
692 int h = M_IMGDATA->m_height;
c7abc967 693
223d09f6 694 wxCHECK_MSG( (x>=0) && (y>=0) && (x<w) && (y<h), 0, wxT("invalid image index") );
c7abc967 695
ef539066 696 long pos = (y * w + x) * 3;
c7abc967 697
ef539066
RR
698 return M_IMGDATA->m_data[pos+1];
699}
700
f6bcfd97 701unsigned char wxImage::GetBlue( int x, int y ) const
ef539066 702{
223d09f6 703 wxCHECK_MSG( Ok(), 0, wxT("invalid image") );
c7abc967 704
ef539066
RR
705 int w = M_IMGDATA->m_width;
706 int h = M_IMGDATA->m_height;
c7abc967 707
223d09f6 708 wxCHECK_MSG( (x>=0) && (y>=0) && (x<w) && (y<h), 0, wxT("invalid image index") );
c7abc967 709
ef539066 710 long pos = (y * w + x) * 3;
c7abc967 711
ef539066
RR
712 return M_IMGDATA->m_data[pos+2];
713}
4698648f
VZ
714
715bool wxImage::Ok() const
716{
de8c48cf
VZ
717 // image of 0 width or height can't be considered ok - at least because it
718 // causes crashes in ConvertToBitmap() if we don't catch it in time
719 wxImageRefData *data = M_IMGDATA;
720 return data && data->m_ok && data->m_width && data->m_height;
01111366
RR
721}
722
487659e0 723unsigned char *wxImage::GetData() const
01111366 724{
487659e0 725 wxCHECK_MSG( Ok(), (unsigned char *)NULL, wxT("invalid image") );
c7abc967 726
fd0eed64 727 return M_IMGDATA->m_data;
01111366
RR
728}
729
487659e0 730void wxImage::SetData( unsigned char *data )
01111366 731{
223d09f6 732 wxCHECK_RET( Ok(), wxT("invalid image") );
58a8ab88 733
ed58dbea
RR
734 wxImageRefData *newRefData = new wxImageRefData();
735
736 newRefData->m_width = M_IMGDATA->m_width;
737 newRefData->m_height = M_IMGDATA->m_height;
738 newRefData->m_data = data;
739 newRefData->m_ok = TRUE;
740 newRefData->m_maskRed = M_IMGDATA->m_maskRed;
741 newRefData->m_maskGreen = M_IMGDATA->m_maskGreen;
742 newRefData->m_maskBlue = M_IMGDATA->m_maskBlue;
743 newRefData->m_hasMask = M_IMGDATA->m_hasMask;
995612e2 744
ed58dbea 745 UnRef();
995612e2 746
ed58dbea 747 m_refData = newRefData;
01111366
RR
748}
749
487659e0 750void wxImage::SetData( unsigned char *data, int new_width, int new_height )
f6bcfd97
BP
751{
752 wxImageRefData *newRefData = new wxImageRefData();
753
754 if (m_refData)
755 {
756 newRefData->m_width = new_width;
757 newRefData->m_height = new_height;
758 newRefData->m_data = data;
759 newRefData->m_ok = TRUE;
760 newRefData->m_maskRed = M_IMGDATA->m_maskRed;
761 newRefData->m_maskGreen = M_IMGDATA->m_maskGreen;
762 newRefData->m_maskBlue = M_IMGDATA->m_maskBlue;
763 newRefData->m_hasMask = M_IMGDATA->m_hasMask;
764 }
765 else
766 {
767 newRefData->m_width = new_width;
768 newRefData->m_height = new_height;
769 newRefData->m_data = data;
770 newRefData->m_ok = TRUE;
771 }
772
773 UnRef();
774
775 m_refData = newRefData;
776}
777
487659e0
VZ
778// ----------------------------------------------------------------------------
779// alpha channel support
780// ----------------------------------------------------------------------------
781
782void wxImage::SetAlpha(int x, int y, unsigned char alpha)
783{
784 wxCHECK_RET( Ok() && HasAlpha(), wxT("invalid image or no alpha channel") );
785
786 int w = M_IMGDATA->m_width,
787 h = M_IMGDATA->m_height;
788
789 wxCHECK_RET( x >=0 && y >= 0 && x < w && y < h, wxT("invalid image index") );
790
791 M_IMGDATA->m_alpha[y*w + x] = alpha;
792}
793
794unsigned char wxImage::GetAlpha(int x, int y)
795{
796 wxCHECK_MSG( Ok() && HasAlpha(), 0, wxT("invalid image or no alpha channel") );
797
798 int w = M_IMGDATA->m_width,
799 h = M_IMGDATA->m_height;
800
801 wxCHECK_MSG( x >=0 && y >= 0 && x < w && y < h, 0, wxT("invalid image index") );
802
803 return M_IMGDATA->m_alpha[y*w + x];
804}
805
806void wxImage::SetAlpha( unsigned char *alpha )
807{
808 wxCHECK_RET( Ok(), wxT("invalid image") );
809
810 if ( !alpha )
811 {
812 alpha = (unsigned char *)
813 malloc(M_IMGDATA->m_width*M_IMGDATA->m_height*3);
814 }
815
816 delete [] M_IMGDATA->m_alpha;
817 M_IMGDATA->m_alpha = alpha;
818}
819
820unsigned char *wxImage::GetAlpha() const
821{
822 wxCHECK_MSG( Ok(), (unsigned char *)NULL, wxT("invalid image") );
823
824 return M_IMGDATA->m_alpha;
825}
826
827// ----------------------------------------------------------------------------
828// mask support
829// ----------------------------------------------------------------------------
830
01111366
RR
831void wxImage::SetMaskColour( unsigned char r, unsigned char g, unsigned char b )
832{
223d09f6 833 wxCHECK_RET( Ok(), wxT("invalid image") );
c7abc967 834
fd0eed64
RR
835 M_IMGDATA->m_maskRed = r;
836 M_IMGDATA->m_maskGreen = g;
837 M_IMGDATA->m_maskBlue = b;
838 M_IMGDATA->m_hasMask = TRUE;
01111366
RR
839}
840
841unsigned char wxImage::GetMaskRed() const
842{
223d09f6 843 wxCHECK_MSG( Ok(), 0, wxT("invalid image") );
c7abc967 844
fd0eed64 845 return M_IMGDATA->m_maskRed;
01111366
RR
846}
847
848unsigned char wxImage::GetMaskGreen() const
849{
223d09f6 850 wxCHECK_MSG( Ok(), 0, wxT("invalid image") );
c7abc967 851
fd0eed64 852 return M_IMGDATA->m_maskGreen;
01111366
RR
853}
854
855unsigned char wxImage::GetMaskBlue() const
856{
223d09f6 857 wxCHECK_MSG( Ok(), 0, wxT("invalid image") );
c7abc967 858
fd0eed64 859 return M_IMGDATA->m_maskBlue;
01111366 860}
4698648f 861
01111366
RR
862void wxImage::SetMask( bool mask )
863{
223d09f6 864 wxCHECK_RET( Ok(), wxT("invalid image") );
c7abc967 865
fd0eed64 866 M_IMGDATA->m_hasMask = mask;
01111366
RR
867}
868
869bool wxImage::HasMask() const
870{
223d09f6 871 wxCHECK_MSG( Ok(), FALSE, wxT("invalid image") );
c7abc967 872
fd0eed64 873 return M_IMGDATA->m_hasMask;
01111366
RR
874}
875
4698648f
VZ
876int wxImage::GetWidth() const
877{
223d09f6 878 wxCHECK_MSG( Ok(), 0, wxT("invalid image") );
c7abc967 879
4698648f 880 return M_IMGDATA->m_width;
01111366
RR
881}
882
4698648f
VZ
883int wxImage::GetHeight() const
884{
223d09f6 885 wxCHECK_MSG( Ok(), 0, wxT("invalid image") );
c7abc967 886
4698648f 887 return M_IMGDATA->m_height;
01111366
RR
888}
889
487659e0 890bool wxImage::SetMaskFromImage(const wxImage& mask,
1f5b2017 891 unsigned char mr, unsigned char mg, unsigned char mb)
52b64b0a 892{
52b64b0a
RR
893 // check that the images are the same size
894 if ( (M_IMGDATA->m_height != mask.GetHeight() ) || (M_IMGDATA->m_width != mask.GetWidth () ) )
895 {
487659e0 896 wxLogError( _("Image and Mask have different sizes") );
52b64b0a
RR
897 return FALSE;
898 }
487659e0 899
52b64b0a
RR
900 // find unused colour
901 unsigned char r,g,b ;
1f5b2017 902 if (!FindFirstUnusedColour(&r, &g, &b))
52b64b0a 903 {
487659e0 904 wxLogError( _("No Unused Color in image being masked") );
52b64b0a
RR
905 return FALSE ;
906 }
487659e0
VZ
907
908 unsigned char *imgdata = GetData();
909 unsigned char *maskdata = mask.GetData();
52b64b0a
RR
910
911 const int w = GetWidth();
912 const int h = GetHeight();
913
914 for (int j = 0; j < h; j++)
1f5b2017 915 {
52b64b0a
RR
916 for (int i = 0; i < w; i++)
917 {
1f5b2017 918 if ((maskdata[0] == mr) && (maskdata[1] == mg) && (maskdata[2] == mb))
52b64b0a
RR
919 {
920 imgdata[0] = r;
921 imgdata[1] = g;
922 imgdata[2] = b;
923 }
924 imgdata += 3;
925 maskdata += 3;
926 }
1f5b2017 927 }
52b64b0a 928
1f5b2017
VS
929 SetMaskColour(r, g, b);
930 SetMask(TRUE);
487659e0 931
52b64b0a
RR
932 return TRUE;
933}
934
d275c7eb
VZ
935#if wxUSE_PALETTE
936
5e5437e0
JS
937// Palette functions
938
939bool wxImage::HasPalette() const
940{
941 if (!Ok())
942 return FALSE;
943
944 return M_IMGDATA->m_palette.Ok();
945}
946
947const wxPalette& wxImage::GetPalette() const
948{
949 wxCHECK_MSG( Ok(), wxNullPalette, wxT("invalid image") );
950
951 return M_IMGDATA->m_palette;
952}
953
954void wxImage::SetPalette(const wxPalette& palette)
955{
956 wxCHECK_RET( Ok(), wxT("invalid image") );
957
958 M_IMGDATA->m_palette = palette;
959}
960
d275c7eb
VZ
961#endif // wxUSE_PALETTE
962
5e5437e0
JS
963// Option functions (arbitrary name/value mapping)
964void wxImage::SetOption(const wxString& name, const wxString& value)
965{
966 wxCHECK_RET( Ok(), wxT("invalid image") );
967
968 int idx = M_IMGDATA->m_optionNames.Index(name, FALSE);
969 if (idx == wxNOT_FOUND)
970 {
971 M_IMGDATA->m_optionNames.Add(name);
972 M_IMGDATA->m_optionValues.Add(value);
973 }
974 else
975 {
976 M_IMGDATA->m_optionNames[idx] = name;
977 M_IMGDATA->m_optionValues[idx] = value;
978 }
979}
980
981void wxImage::SetOption(const wxString& name, int value)
982{
983 wxString valStr;
984 valStr.Printf(wxT("%d"), value);
985 SetOption(name, valStr);
986}
987
988wxString wxImage::GetOption(const wxString& name) const
989{
990 wxCHECK_MSG( Ok(), wxEmptyString, wxT("invalid image") );
991
992 int idx = M_IMGDATA->m_optionNames.Index(name, FALSE);
993 if (idx == wxNOT_FOUND)
994 return wxEmptyString;
995 else
996 return M_IMGDATA->m_optionValues[idx];
997}
998
999int wxImage::GetOptionInt(const wxString& name) const
1000{
1001 wxCHECK_MSG( Ok(), 0, wxT("invalid image") );
1002
1003 return wxAtoi(GetOption(name));
1004}
1005
1006bool wxImage::HasOption(const wxString& name) const
1007{
1008 wxCHECK_MSG( Ok(), FALSE, wxT("invalid image") );
1009
1010 return (M_IMGDATA->m_optionNames.Index(name, FALSE) != wxNOT_FOUND);
1011}
1012
60d43ad8 1013bool wxImage::LoadFile( const wxString& filename, long type, int index )
01111366 1014{
e02afc7a 1015#if wxUSE_STREAMS
d80207c3 1016 if (wxFileExists(filename))
6c28fd33 1017 {
d80207c3
KB
1018 wxFileInputStream stream(filename);
1019 wxBufferedInputStream bstream( stream );
60d43ad8 1020 return LoadFile(bstream, type, index);
6c28fd33 1021 }
d80207c3 1022 else
6c28fd33 1023 {
d80207c3
KB
1024 wxLogError( _("Can't load image from file '%s': file does not exist."), filename.c_str() );
1025
716cd410 1026 return FALSE;
6c28fd33 1027 }
9e9ee68e
VS
1028#else // !wxUSE_STREAMS
1029 return FALSE;
1030#endif // wxUSE_STREAMS
1031}
1032
60d43ad8 1033bool wxImage::LoadFile( const wxString& filename, const wxString& mimetype, int index )
9e9ee68e
VS
1034{
1035#if wxUSE_STREAMS
d80207c3 1036 if (wxFileExists(filename))
6c28fd33 1037 {
d80207c3
KB
1038 wxFileInputStream stream(filename);
1039 wxBufferedInputStream bstream( stream );
60d43ad8 1040 return LoadFile(bstream, mimetype, index);
6c28fd33 1041 }
d80207c3 1042 else
6c28fd33 1043 {
d80207c3
KB
1044 wxLogError( _("Can't load image from file '%s': file does not exist."), filename.c_str() );
1045
716cd410 1046 return FALSE;
6c28fd33 1047 }
e02afc7a 1048#else // !wxUSE_STREAMS
dbda9e86 1049 return FALSE;
e02afc7a 1050#endif // wxUSE_STREAMS
1ccbb61a
VZ
1051}
1052
45647dcf
VS
1053
1054
1055bool wxImage::SaveFile( const wxString& filename ) const
1056{
1057 wxString ext = filename.AfterLast('.').Lower();
487659e0 1058
45647dcf
VS
1059 wxImageHandler * pHandler = FindHandler(ext, -1);
1060 if (pHandler)
1061 {
1062 SaveFile(filename, pHandler->GetType());
1063 return TRUE;
1064 }
1065
1066 wxLogError(_("Can't save image to file '%s': unknown extension."), filename.c_str());
1067
1068 return FALSE;
1069}
1070
e0a76d8d 1071bool wxImage::SaveFile( const wxString& filename, int type ) const
1ccbb61a 1072{
e02afc7a 1073#if wxUSE_STREAMS
36aac195 1074 ((wxImage*)this)->SetOption(wxIMAGE_OPTION_FILENAME, filename);
fd94e8aa 1075
1ccbb61a 1076 wxFileOutputStream stream(filename);
9e9ee68e 1077
2b5f62a0 1078 if ( stream.IsOk() )
1b055864 1079 {
069d0f27 1080 wxBufferedOutputStream bstream( stream );
1b055864
RR
1081 return SaveFile(bstream, type);
1082 }
e02afc7a 1083#endif // wxUSE_STREAMS
3ca6a5f0
BP
1084
1085 return FALSE;
3d05544e 1086}
01111366 1087
e0a76d8d 1088bool wxImage::SaveFile( const wxString& filename, const wxString& mimetype ) const
9e9ee68e
VS
1089{
1090#if wxUSE_STREAMS
36aac195 1091 ((wxImage*)this)->SetOption(wxIMAGE_OPTION_FILENAME, filename);
fd94e8aa 1092
9e9ee68e 1093 wxFileOutputStream stream(filename);
c7abc967 1094
2b5f62a0 1095 if ( stream.IsOk() )
1b055864 1096 {
069d0f27 1097 wxBufferedOutputStream bstream( stream );
1b055864
RR
1098 return SaveFile(bstream, mimetype);
1099 }
9e9ee68e 1100#endif // wxUSE_STREAMS
3ca6a5f0
BP
1101
1102 return FALSE;
9e9ee68e
VS
1103}
1104
87202f78
SB
1105bool wxImage::CanRead( const wxString &name )
1106{
1107#if wxUSE_STREAMS
1108 wxFileInputStream stream(name);
1109 return CanRead(stream);
1110#else
1111 return FALSE;
1112#endif
1113}
1114
649d13e8 1115int wxImage::GetImageCount( const wxString &name, long type )
60d43ad8
VS
1116{
1117#if wxUSE_STREAMS
1118 wxFileInputStream stream(name);
2c0a4e08 1119 if (stream.Ok())
08811762 1120 return GetImageCount(stream, type);
60d43ad8 1121#endif
2c0a4e08
VZ
1122
1123 return 0;
60d43ad8
VS
1124}
1125
e02afc7a 1126#if wxUSE_STREAMS
deb2fec0 1127
87202f78
SB
1128bool wxImage::CanRead( wxInputStream &stream )
1129{
79fa2374 1130 const wxList& list = GetHandlers();
004fd0c8 1131
60d43ad8 1132 for ( wxList::Node *node = list.GetFirst(); node; node = node->GetNext() )
004fd0c8 1133 {
60d43ad8
VS
1134 wxImageHandler *handler=(wxImageHandler*)node->GetData();
1135 if (handler->CanRead( stream ))
1136 return TRUE;
87202f78
SB
1137 }
1138
60d43ad8
VS
1139 return FALSE;
1140}
1141
649d13e8 1142int wxImage::GetImageCount( wxInputStream &stream, long type )
60d43ad8
VS
1143{
1144 wxImageHandler *handler;
1145
1146 if ( type == wxBITMAP_TYPE_ANY )
1147 {
1148 wxList &list=GetHandlers();
1149
1150 for (wxList::Node *node = list.GetFirst(); node; node = node->GetNext())
1151 {
1152 handler=(wxImageHandler*)node->GetData();
1153 if ( handler->CanRead(stream) )
649d13e8 1154 return handler->GetImageCount(stream);
60d43ad8
VS
1155
1156 }
1157
1158 wxLogWarning(_("No handler found for image type."));
1159 return 0;
1160 }
1161
1162 handler = FindHandler(type);
1163
1164 if ( !handler )
1165 {
1166 wxLogWarning(_("No image handler for type %d defined."), type);
1167 return FALSE;
1168 }
1169
1170 if ( handler->CanRead(stream) )
1171 {
649d13e8 1172 return handler->GetImageCount(stream);
60d43ad8
VS
1173 }
1174 else
1175 {
1176 wxLogError(_("Image file is not of type %d."), type);
1177 return 0;
1178 }
87202f78
SB
1179}
1180
60d43ad8 1181bool wxImage::LoadFile( wxInputStream& stream, long type, int index )
3d05544e
JS
1182{
1183 UnRef();
c7abc967 1184
fd0eed64 1185 m_refData = new wxImageRefData;
c7abc967 1186
deb2fec0
SB
1187 wxImageHandler *handler;
1188
60d43ad8 1189 if ( type == wxBITMAP_TYPE_ANY )
deb2fec0 1190 {
995612e2 1191 wxList &list=GetHandlers();
deb2fec0 1192
995612e2
VZ
1193 for ( wxList::Node *node = list.GetFirst(); node; node = node->GetNext() )
1194 {
1195 handler=(wxImageHandler*)node->GetData();
60d43ad8
VS
1196 if ( handler->CanRead(stream) )
1197 return handler->LoadFile(this, stream, TRUE/*verbose*/, index);
7b2471a0 1198
995612e2 1199 }
deb2fec0 1200
58c837a4 1201 wxLogWarning( _("No handler found for image type.") );
995612e2 1202 return FALSE;
deb2fec0
SB
1203 }
1204
1205 handler = FindHandler(type);
c7abc967 1206
2b5f62a0 1207 if (handler == 0)
fd0eed64 1208 {
58c837a4 1209 wxLogWarning( _("No image handler for type %d defined."), type );
c7abc967 1210
fd0eed64
RR
1211 return FALSE;
1212 }
c7abc967 1213
60d43ad8 1214 return handler->LoadFile(this, stream, TRUE/*verbose*/, index);
01111366
RR
1215}
1216
60d43ad8 1217bool wxImage::LoadFile( wxInputStream& stream, const wxString& mimetype, int index )
9e9ee68e
VS
1218{
1219 UnRef();
1220
1221 m_refData = new wxImageRefData;
1222
1223 wxImageHandler *handler = FindHandlerMime(mimetype);
1224
2b5f62a0 1225 if (handler == 0)
9e9ee68e 1226 {
58c837a4 1227 wxLogWarning( _("No image handler for type %s defined."), mimetype.GetData() );
9e9ee68e
VS
1228
1229 return FALSE;
1230 }
1231
649d13e8 1232 return handler->LoadFile( this, stream, TRUE/*verbose*/, index );
9e9ee68e
VS
1233}
1234
e0a76d8d 1235bool wxImage::SaveFile( wxOutputStream& stream, int type ) const
01111366 1236{
223d09f6 1237 wxCHECK_MSG( Ok(), FALSE, wxT("invalid image") );
c7abc967 1238
fd0eed64 1239 wxImageHandler *handler = FindHandler(type);
c7abc967 1240
2b5f62a0 1241 if (handler == 0)
fd0eed64 1242 {
58c837a4 1243 wxLogWarning( _("No image handler for type %d defined."), type );
9e9ee68e
VS
1244
1245 return FALSE;
1246 }
1247
e0a76d8d 1248 return handler->SaveFile( (wxImage*)this, stream );
9e9ee68e
VS
1249}
1250
e0a76d8d 1251bool wxImage::SaveFile( wxOutputStream& stream, const wxString& mimetype ) const
9e9ee68e 1252{
223d09f6 1253 wxCHECK_MSG( Ok(), FALSE, wxT("invalid image") );
c7abc967 1254
9e9ee68e 1255 wxImageHandler *handler = FindHandlerMime(mimetype);
c7abc967 1256
2b5f62a0 1257 if (handler == 0)
9e9ee68e 1258 {
58c837a4 1259 wxLogWarning( _("No image handler for type %s defined."), mimetype.GetData() );
c7abc967 1260
dbda9e86 1261 return FALSE;
fd0eed64 1262 }
c7abc967 1263
e0a76d8d 1264 return handler->SaveFile( (wxImage*)this, stream );
01111366 1265}
e02afc7a 1266#endif // wxUSE_STREAMS
01111366
RR
1267
1268void wxImage::AddHandler( wxImageHandler *handler )
1269{
4698648f
VZ
1270 // make sure that the memory will be freed at the program end
1271 sm_handlers.DeleteContents(TRUE);
c7abc967 1272
2b5f62a0
VZ
1273 // Check for an existing handler of the type being added.
1274 if (FindHandler( handler->GetType() ) == 0)
1275 {
1276 sm_handlers.Append( handler );
1277 }
1278 else
1279 {
1280 // This is not documented behaviour, merely the simplest 'fix'
1281 // for preventing duplicate additions. If someone ever has
1282 // a good reason to add and remove duplicate handlers (and they
1283 // may) we should probably refcount the duplicates.
1284 // also an issue in InsertHandler below.
1285
1286 wxLogDebug( _T("Adding duplicate image handler for '%s'"),
1287 handler->GetName().c_str() );
1288 delete handler;
1289 }
01111366
RR
1290}
1291
1292void wxImage::InsertHandler( wxImageHandler *handler )
1293{
4698648f
VZ
1294 // make sure that the memory will be freed at the program end
1295 sm_handlers.DeleteContents(TRUE);
c7abc967 1296
2b5f62a0
VZ
1297 // Check for an existing handler of the type being added.
1298 if (FindHandler( handler->GetType() ) == 0)
1299 {
1300 sm_handlers.Insert( handler );
1301 }
1302 else
1303 {
1304 // see AddHandler for additional comments.
1305 wxLogDebug( _T("Inserting duplicate image handler for '%s'"),
1306 handler->GetName().c_str() );
1307 delete handler;
1308 }
01111366
RR
1309}
1310
1311bool wxImage::RemoveHandler( const wxString& name )
1312{
fd0eed64
RR
1313 wxImageHandler *handler = FindHandler(name);
1314 if (handler)
1315 {
1316 sm_handlers.DeleteObject(handler);
1317 return TRUE;
1318 }
1319 else
1320 return FALSE;
01111366
RR
1321}
1322
1323wxImageHandler *wxImage::FindHandler( const wxString& name )
1324{
b1d4dd7a 1325 wxNode *node = sm_handlers.GetFirst();
fd0eed64
RR
1326 while (node)
1327 {
b1d4dd7a 1328 wxImageHandler *handler = (wxImageHandler*)node->GetData();
ce3ed50d 1329 if (handler->GetName().Cmp(name) == 0) return handler;
c7abc967 1330
b1d4dd7a 1331 node = node->GetNext();
fd0eed64 1332 }
2b5f62a0 1333 return 0;
01111366
RR
1334}
1335
1336wxImageHandler *wxImage::FindHandler( const wxString& extension, long bitmapType )
1337{
b1d4dd7a 1338 wxNode *node = sm_handlers.GetFirst();
fd0eed64
RR
1339 while (node)
1340 {
b1d4dd7a 1341 wxImageHandler *handler = (wxImageHandler*)node->GetData();
ce3ed50d 1342 if ( (handler->GetExtension().Cmp(extension) == 0) &&
fd0eed64 1343 (bitmapType == -1 || handler->GetType() == bitmapType) )
dbda9e86 1344 return handler;
b1d4dd7a 1345 node = node->GetNext();
fd0eed64 1346 }
2b5f62a0 1347 return 0;
01111366
RR
1348}
1349
1350wxImageHandler *wxImage::FindHandler( long bitmapType )
1351{
b1d4dd7a 1352 wxNode *node = sm_handlers.GetFirst();
fd0eed64
RR
1353 while (node)
1354 {
b1d4dd7a 1355 wxImageHandler *handler = (wxImageHandler *)node->GetData();
fd0eed64 1356 if (handler->GetType() == bitmapType) return handler;
b1d4dd7a 1357 node = node->GetNext();
fd0eed64 1358 }
2b5f62a0 1359 return 0;
fd0eed64
RR
1360}
1361
9e9ee68e
VS
1362wxImageHandler *wxImage::FindHandlerMime( const wxString& mimetype )
1363{
b1d4dd7a 1364 wxNode *node = sm_handlers.GetFirst();
9e9ee68e
VS
1365 while (node)
1366 {
b1d4dd7a 1367 wxImageHandler *handler = (wxImageHandler *)node->GetData();
9e9ee68e 1368 if (handler->GetMimeType().IsSameAs(mimetype, FALSE)) return handler;
b1d4dd7a 1369 node = node->GetNext();
9e9ee68e 1370 }
2b5f62a0 1371 return 0;
9e9ee68e
VS
1372}
1373
fd0eed64
RR
1374void wxImage::InitStandardHandlers()
1375{
77fac225 1376#if wxUSE_STREAMS
66e23ad2 1377 AddHandler(new wxBMPHandler);
77fac225 1378#endif // wxUSE_STREAMS
01111366
RR
1379}
1380
1381void wxImage::CleanUpHandlers()
1382{
b1d4dd7a 1383 wxNode *node = sm_handlers.GetFirst();
fd0eed64
RR
1384 while (node)
1385 {
b1d4dd7a
RL
1386 wxImageHandler *handler = (wxImageHandler *)node->GetData();
1387 wxNode *next = node->GetNext();
fd0eed64
RR
1388 delete handler;
1389 delete node;
1390 node = next;
1391 }
01111366
RR
1392}
1393
ff865c13 1394
01111366
RR
1395//-----------------------------------------------------------------------------
1396// wxImageHandler
1397//-----------------------------------------------------------------------------
1398
63d963a1 1399IMPLEMENT_ABSTRACT_CLASS(wxImageHandler,wxObject)
01111366 1400
e02afc7a 1401#if wxUSE_STREAMS
700ec454 1402bool wxImageHandler::LoadFile( wxImage *WXUNUSED(image), wxInputStream& WXUNUSED(stream), bool WXUNUSED(verbose), int WXUNUSED(index) )
01111366 1403{
fd0eed64 1404 return FALSE;
01111366
RR
1405}
1406
deb2fec0 1407bool wxImageHandler::SaveFile( wxImage *WXUNUSED(image), wxOutputStream& WXUNUSED(stream), bool WXUNUSED(verbose) )
01111366 1408{
fd0eed64 1409 return FALSE;
01111366 1410}
0828c087 1411
649d13e8 1412int wxImageHandler::GetImageCount( wxInputStream& WXUNUSED(stream) )
700ec454
RR
1413{
1414 return 1;
1415}
1416
0828c087
VS
1417bool wxImageHandler::CanRead( const wxString& name )
1418{
0828c087
VS
1419 if (wxFileExists(name))
1420 {
1421 wxFileInputStream stream(name);
1422 return CanRead(stream);
1423 }
1424
39d16996 1425 wxLogError( _("Can't check image format of file '%s': file does not exist."), name.c_str() );
0828c087 1426
39d16996
VZ
1427 return FALSE;
1428}
1429
1430bool wxImageHandler::CallDoCanRead(wxInputStream& stream)
1431{
1432 off_t posOld = stream.TellI();
1433 if ( posOld == wxInvalidOffset )
1434 {
1435 // can't test unseekable stream
1436 return FALSE;
1437 }
1438
1439 bool ok = DoCanRead(stream);
1440
1441 // restore the old position to be able to test other formats and so on
1442 if ( stream.SeekI(posOld) == wxInvalidOffset )
1443 {
1444 wxLogDebug(_T("Failed to rewind the stream in wxImageHandler!"));
1445
1446 // reading would fail anyhow as we're not at the right position
0828c087
VS
1447 return FALSE;
1448 }
39d16996
VZ
1449
1450 return ok;
0828c087
VS
1451}
1452
e02afc7a 1453#endif // wxUSE_STREAMS
01111366 1454
fec19ea9
VS
1455
1456
01111366 1457//-----------------------------------------------------------------------------
2b5f62a0 1458// Deprecated wxBitmap conversion routines
01111366
RR
1459//-----------------------------------------------------------------------------
1460
ef8f37e0 1461#if WXWIN_COMPATIBILITY_2_2 && wxUSE_GUI
e3554471 1462
fec19ea9 1463#ifdef __WXGTK__
f515c25a 1464wxBitmap wxImage::ConvertToMonoBitmap( unsigned char red, unsigned char green, unsigned char blue ) const
e3554471 1465{
fec19ea9
VS
1466 wxImage mono = this->ConvertToMono( red, green, blue );
1467 wxBitmap bitmap( mono, 1 );
bba6f3bd 1468 return bitmap;
e3554471 1469}
03e11df5 1470#endif
7c74e7fe 1471
7c74e7fe
SC
1472wxBitmap wxImage::ConvertToBitmap() const
1473{
fec19ea9 1474 wxBitmap bitmap( *this );
5fde6fcc 1475 return bitmap;
7c74e7fe
SC
1476}
1477
1478wxImage::wxImage( const wxBitmap &bitmap )
1479{
fec19ea9 1480 *this = bitmap.ConvertToImage();
82ea63e6
RR
1481}
1482
ef8f37e0 1483#endif // WXWIN_COMPATIBILITY_2_2 && wxUSE_GUI
c9d01afd
GRG
1484
1485
487659e0
VZ
1486// ----------------------------------------------------------------------------
1487// image histogram stuff
1488// ----------------------------------------------------------------------------
1489
1490bool
1491wxImageHistogram::FindFirstUnusedColour(unsigned char *r,
1492 unsigned char *g,
1493 unsigned char *b,
1494 unsigned char r2,
1495 unsigned char b2,
1496 unsigned char g2) const
1497{
1498 unsigned long key = MakeKey(r2, g2, b2);
1499
1500 while ( find(key) != end() )
1501 {
1502 // color already used
1503 r2++;
1504 if ( r2 >= 255 )
1505 {
1506 r2 = 0;
1507 g2++;
1508 if ( g2 >= 255 )
1509 {
1510 g2 = 0;
1511 b2++;
1512 if ( b2 >= 255 )
1513 {
1514 wxLogError(_("GetUnusedColour:: No Unused Color in image ") );
1515 return FALSE;
1516 }
1517 }
1518 }
1519
1520 key = MakeKey(r2, g2, b2);
1521 }
1522
1523 if ( r )
1524 *r = r2;
1525 if ( g )
1526 *g = g2;
1527 if ( b )
1528 *b = b2;
1529
1530 return TRUE;
1531}
1532
1533bool
1534wxImage::FindFirstUnusedColour(unsigned char *r,
1535 unsigned char *g,
1536 unsigned char *b,
1537 unsigned char r2,
1538 unsigned char b2,
1539 unsigned char g2) const
1540{
1541 wxImageHistogram histogram;
1542
1543 ComputeHistogram(histogram);
1544
1545 return histogram.FindFirstUnusedColour(r, g, b, r2, g2, b2);
1546}
1547
1548
c9d01afd 1549
89d00456
GRG
1550// GRG, Dic/99
1551// Counts and returns the number of different colours. Optionally stops
cc9f7d79
GRG
1552// when it exceeds 'stopafter' different colours. This is useful, for
1553// example, to see if the image can be saved as 8-bit (256 colour or
1554// less, in this case it would be invoked as CountColours(256)). Default
1555// value for stopafter is -1 (don't care).
89d00456 1556//
e0a76d8d 1557unsigned long wxImage::CountColours( unsigned long stopafter ) const
89d00456
GRG
1558{
1559 wxHashTable h;
ad30de59 1560 wxObject dummy;
33ac7e6f 1561 unsigned char r, g, b;
eeca3a46 1562 unsigned char *p;
89d00456
GRG
1563 unsigned long size, nentries, key;
1564
1565 p = GetData();
1566 size = GetWidth() * GetHeight();
1567 nentries = 0;
1568
cc9f7d79 1569 for (unsigned long j = 0; (j < size) && (nentries <= stopafter) ; j++)
89d00456
GRG
1570 {
1571 r = *(p++);
1572 g = *(p++);
1573 b = *(p++);
487659e0 1574 key = wxImageHistogram::MakeKey(r, g, b);
89d00456 1575
ad30de59 1576 if (h.Get(key) == NULL)
89d00456 1577 {
ad30de59 1578 h.Put(key, &dummy);
89d00456
GRG
1579 nentries++;
1580 }
1581 }
1582
89d00456
GRG
1583 return nentries;
1584}
1585
1586
e0a76d8d 1587unsigned long wxImage::ComputeHistogram( wxImageHistogram &h ) const
c9d01afd 1588{
487659e0
VZ
1589 unsigned char *p = GetData();
1590 unsigned long nentries = 0;
952ae1e8
VS
1591
1592 h.clear();
c9d01afd 1593
487659e0 1594 const unsigned long size = GetWidth() * GetHeight();
c9d01afd 1595
487659e0
VZ
1596 unsigned char r, g, b;
1597 for ( unsigned long n = 0; n < size; n++ )
c9d01afd 1598 {
487659e0
VZ
1599 r = *p++;
1600 g = *p++;
1601 b = *p++;
1602
1603 wxImageHistogramEntry& entry = h[wxImageHistogram::MakeKey(r, g, b)];
c9d01afd 1604
952ae1e8
VS
1605 if ( entry.value++ == 0 )
1606 entry.index = nentries++;
c9d01afd
GRG
1607 }
1608
1609 return nentries;
1610}
1611
7a632f10
JS
1612/*
1613 * Rotation code by Carlos Moreno
1614 */
1615
b5c91ac6
GRG
1616// GRG: I've removed wxRotationPoint - we already have wxRealPoint which
1617// does exactly the same thing. And I also got rid of wxRotationPixel
1618// bacause of potential problems in architectures where alignment
1619// is an issue, so I had to rewrite parts of the code.
7a632f10 1620
7a632f10
JS
1621static const double gs_Epsilon = 1e-10;
1622
1623static inline int wxCint (double x)
1624{
1625 return (x > 0) ? (int) (x + 0.5) : (int) (x - 0.5);
1626}
1627
1628
1629// Auxiliary function to rotate a point (x,y) with respect to point p0
1630// make it inline and use a straight return to facilitate optimization
1631// also, the function receives the sine and cosine of the angle to avoid
1632// repeating the time-consuming calls to these functions -- sin/cos can
1633// be computed and stored in the calling function.
1634
b5c91ac6 1635inline wxRealPoint rotated_point (const wxRealPoint & p, double cos_angle, double sin_angle, const wxRealPoint & p0)
7a632f10 1636{
b5c91ac6
GRG
1637 return wxRealPoint (p0.x + (p.x - p0.x) * cos_angle - (p.y - p0.y) * sin_angle,
1638 p0.y + (p.y - p0.y) * cos_angle + (p.x - p0.x) * sin_angle);
7a632f10
JS
1639}
1640
b5c91ac6 1641inline wxRealPoint rotated_point (double x, double y, double cos_angle, double sin_angle, const wxRealPoint & p0)
7a632f10 1642{
b5c91ac6 1643 return rotated_point (wxRealPoint(x,y), cos_angle, sin_angle, p0);
7a632f10
JS
1644}
1645
1646wxImage wxImage::Rotate(double angle, const wxPoint & centre_of_rotation, bool interpolating, wxPoint * offset_after_rotation) const
1647{
7a632f10
JS
1648 int i;
1649 angle = -angle; // screen coordinates are a mirror image of "real" coordinates
1650
ad30de59 1651 // Create pointer-based array to accelerate access to wxImage's data
b5c91ac6 1652 unsigned char ** data = new unsigned char * [GetHeight()];
7a632f10 1653
b5c91ac6 1654 data[0] = GetData();
7a632f10 1655
b5c91ac6
GRG
1656 for (i = 1; i < GetHeight(); i++)
1657 data[i] = data[i - 1] + (3 * GetWidth());
7a632f10 1658
b5c91ac6 1659 // precompute coefficients for rotation formula
ad30de59 1660 // (sine and cosine of the angle)
7a632f10
JS
1661 const double cos_angle = cos(angle);
1662 const double sin_angle = sin(angle);
1663
ad30de59
GRG
1664 // Create new Image to store the result
1665 // First, find rectangle that covers the rotated image; to do that,
1666 // rotate the four corners
7a632f10 1667
b5c91ac6 1668 const wxRealPoint p0(centre_of_rotation.x, centre_of_rotation.y);
7a632f10 1669
b5c91ac6
GRG
1670 wxRealPoint p1 = rotated_point (0, 0, cos_angle, sin_angle, p0);
1671 wxRealPoint p2 = rotated_point (0, GetHeight(), cos_angle, sin_angle, p0);
1672 wxRealPoint p3 = rotated_point (GetWidth(), 0, cos_angle, sin_angle, p0);
1673 wxRealPoint p4 = rotated_point (GetWidth(), GetHeight(), cos_angle, sin_angle, p0);
7a632f10 1674
57c1c6cb
BJ
1675 int x1 = (int) floor (wxMin (wxMin(p1.x, p2.x), wxMin(p3.x, p4.x)));
1676 int y1 = (int) floor (wxMin (wxMin(p1.y, p2.y), wxMin(p3.y, p4.y)));
57c1c6cb
BJ
1677 int x2 = (int) ceil (wxMax (wxMax(p1.x, p2.x), wxMax(p3.x, p4.x)));
1678 int y2 = (int) ceil (wxMax (wxMax(p1.y, p2.y), wxMax(p3.y, p4.y)));
7a632f10 1679
ff865c13 1680 wxImage rotated (x2 - x1 + 1, y2 - y1 + 1, false);
7a632f10
JS
1681
1682 if (offset_after_rotation != NULL)
1683 {
06b466c7 1684 *offset_after_rotation = wxPoint (x1, y1);
7a632f10
JS
1685 }
1686
b5c91ac6
GRG
1687 // GRG: The rotated (destination) image is always accessed
1688 // sequentially, so there is no need for a pointer-based
1689 // array here (and in fact it would be slower).
1690 //
1691 unsigned char * dst = rotated.GetData();
7a632f10 1692
ad30de59
GRG
1693 // GRG: if the original image has a mask, use its RGB values
1694 // as the blank pixel, else, fall back to default (black).
1695 //
b5c91ac6
GRG
1696 unsigned char blank_r = 0;
1697 unsigned char blank_g = 0;
1698 unsigned char blank_b = 0;
ad30de59
GRG
1699
1700 if (HasMask())
1701 {
b5c91ac6
GRG
1702 blank_r = GetMaskRed();
1703 blank_g = GetMaskGreen();
1704 blank_b = GetMaskBlue();
1705 rotated.SetMaskColour( blank_r, blank_g, blank_b );
ad30de59
GRG
1706 }
1707
1708 // Now, for each point of the rotated image, find where it came from, by
1709 // performing an inverse rotation (a rotation of -angle) and getting the
1710 // pixel at those coordinates
1711
b5c91ac6
GRG
1712 // GRG: I've taken the (interpolating) test out of the loops, so that
1713 // it is done only once, instead of repeating it for each pixel.
7a632f10
JS
1714
1715 int x;
b5c91ac6 1716 if (interpolating)
7a632f10
JS
1717 {
1718 for (int y = 0; y < rotated.GetHeight(); y++)
1719 {
b5c91ac6 1720 for (x = 0; x < rotated.GetWidth(); x++)
7a632f10 1721 {
b5c91ac6
GRG
1722 wxRealPoint src = rotated_point (x + x1, y + y1, cos_angle, -sin_angle, p0);
1723
f2506310
JS
1724 if (-0.25 < src.x && src.x < GetWidth() - 0.75 &&
1725 -0.25 < src.y && src.y < GetHeight() - 0.75)
7a632f10 1726 {
ad30de59
GRG
1727 // interpolate using the 4 enclosing grid-points. Those
1728 // points can be obtained using floor and ceiling of the
1729 // exact coordinates of the point
f2506310 1730 // C.M. 2000-02-17: when the point is near the border, special care is required.
7a632f10 1731
f2506310
JS
1732 int x1, y1, x2, y2;
1733
1734 if (0 < src.x && src.x < GetWidth() - 1)
1735 {
1736 x1 = wxCint(floor(src.x));
1737 x2 = wxCint(ceil(src.x));
1738 }
1739 else // else means that x is near one of the borders (0 or width-1)
1740 {
1741 x1 = x2 = wxCint (src.x);
1742 }
1743
1744 if (0 < src.y && src.y < GetHeight() - 1)
1745 {
1746 y1 = wxCint(floor(src.y));
1747 y2 = wxCint(ceil(src.y));
1748 }
1749 else
1750 {
1751 y1 = y2 = wxCint (src.y);
1752 }
7a632f10 1753
ad30de59
GRG
1754 // get four points and the distances (square of the distance,
1755 // for efficiency reasons) for the interpolation formula
b5c91ac6
GRG
1756
1757 // GRG: Do not calculate the points until they are
1758 // really needed -- this way we can calculate
1759 // just one, instead of four, if d1, d2, d3
1760 // or d4 are < gs_Epsilon
7a632f10
JS
1761
1762 const double d1 = (src.x - x1) * (src.x - x1) + (src.y - y1) * (src.y - y1);
1763 const double d2 = (src.x - x2) * (src.x - x2) + (src.y - y1) * (src.y - y1);
1764 const double d3 = (src.x - x2) * (src.x - x2) + (src.y - y2) * (src.y - y2);
1765 const double d4 = (src.x - x1) * (src.x - x1) + (src.y - y2) * (src.y - y2);
1766
ad30de59
GRG
1767 // Now interpolate as a weighted average of the four surrounding
1768 // points, where the weights are the distances to each of those points
7a632f10 1769
ad30de59
GRG
1770 // If the point is exactly at one point of the grid of the source
1771 // image, then don't interpolate -- just assign the pixel
7a632f10 1772
06b466c7 1773 if (d1 < gs_Epsilon) // d1,d2,d3,d4 are positive -- no need for abs()
7a632f10 1774 {
b5c91ac6
GRG
1775 unsigned char *p = data[y1] + (3 * x1);
1776 *(dst++) = *(p++);
1777 *(dst++) = *(p++);
1778 *(dst++) = *(p++);
7a632f10
JS
1779 }
1780 else if (d2 < gs_Epsilon)
1781 {
b5c91ac6
GRG
1782 unsigned char *p = data[y1] + (3 * x2);
1783 *(dst++) = *(p++);
1784 *(dst++) = *(p++);
1785 *(dst++) = *(p++);
7a632f10
JS
1786 }
1787 else if (d3 < gs_Epsilon)
1788 {
b5c91ac6
GRG
1789 unsigned char *p = data[y2] + (3 * x2);
1790 *(dst++) = *(p++);
1791 *(dst++) = *(p++);
1792 *(dst++) = *(p++);
7a632f10
JS
1793 }
1794 else if (d4 < gs_Epsilon)
1795 {
b5c91ac6
GRG
1796 unsigned char *p = data[y2] + (3 * x1);
1797 *(dst++) = *(p++);
1798 *(dst++) = *(p++);
1799 *(dst++) = *(p++);
7a632f10
JS
1800 }
1801 else
1802 {
06b466c7 1803 // weights for the weighted average are proportional to the inverse of the distance
b5c91ac6
GRG
1804 unsigned char *v1 = data[y1] + (3 * x1);
1805 unsigned char *v2 = data[y1] + (3 * x2);
1806 unsigned char *v3 = data[y2] + (3 * x2);
1807 unsigned char *v4 = data[y2] + (3 * x1);
1808
06b466c7
VZ
1809 const double w1 = 1/d1, w2 = 1/d2, w3 = 1/d3, w4 = 1/d4;
1810
b5c91ac6
GRG
1811 // GRG: Unrolled.
1812
1813 *(dst++) = (unsigned char)
1814 ( (w1 * *(v1++) + w2 * *(v2++) +
1815 w3 * *(v3++) + w4 * *(v4++)) /
1816 (w1 + w2 + w3 + w4) );
1817 *(dst++) = (unsigned char)
1818 ( (w1 * *(v1++) + w2 * *(v2++) +
1819 w3 * *(v3++) + w4 * *(v4++)) /
1820 (w1 + w2 + w3 + w4) );
1821 *(dst++) = (unsigned char)
1822 ( (w1 * *(v1++) + w2 * *(v2++) +
1823 w3 * *(v3++) + w4 * *(v4++)) /
1824 (w1 + w2 + w3 + w4) );
7a632f10
JS
1825 }
1826 }
1827 else
1828 {
b5c91ac6
GRG
1829 *(dst++) = blank_r;
1830 *(dst++) = blank_g;
1831 *(dst++) = blank_b;
7a632f10
JS
1832 }
1833 }
b5c91ac6
GRG
1834 }
1835 }
1836 else // not interpolating
1837 {
1838 for (int y = 0; y < rotated.GetHeight(); y++)
1839 {
1840 for (x = 0; x < rotated.GetWidth(); x++)
7a632f10 1841 {
b5c91ac6
GRG
1842 wxRealPoint src = rotated_point (x + x1, y + y1, cos_angle, -sin_angle, p0);
1843
1844 const int xs = wxCint (src.x); // wxCint rounds to the
457e6c54 1845 const int ys = wxCint (src.y); // closest integer
7a632f10 1846
b5c91ac6
GRG
1847 if (0 <= xs && xs < GetWidth() &&
1848 0 <= ys && ys < GetHeight())
7a632f10 1849 {
b5c91ac6
GRG
1850 unsigned char *p = data[ys] + (3 * xs);
1851 *(dst++) = *(p++);
1852 *(dst++) = *(p++);
1853 *(dst++) = *(p++);
7a632f10
JS
1854 }
1855 else
1856 {
b5c91ac6
GRG
1857 *(dst++) = blank_r;
1858 *(dst++) = blank_g;
1859 *(dst++) = blank_b;
7a632f10
JS
1860 }
1861 }
1862 }
1863 }
1864
4aff28fc 1865 delete [] data;
4aff28fc 1866
7a632f10
JS
1867 return rotated;
1868}
c9d01afd 1869
ef8f37e0
VS
1870
1871
1872
1873
1874// A module to allow wxImage initialization/cleanup
1875// without calling these functions from app.cpp or from
1876// the user's application.
1877
1878class wxImageModule: public wxModule
1879{
1880DECLARE_DYNAMIC_CLASS(wxImageModule)
1881public:
1882 wxImageModule() {}
1883 bool OnInit() { wxImage::InitStandardHandlers(); return TRUE; };
1884 void OnExit() { wxImage::CleanUpHandlers(); };
1885};
1886
1887IMPLEMENT_DYNAMIC_CLASS(wxImageModule, wxModule)
1888
1889
c96ea657 1890#endif // wxUSE_IMAGE