Improved BMP decoding.
[wxWidgets.git] / tests / image / image.cpp
1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: tests/image/image.cpp
3 // Purpose: Test wxImage
4 // Author: Francesco Montorsi
5 // Created: 2009-05-31
6 // RCS-ID: $Id$
7 // Copyright: (c) 2009 Francesco Montorsi
8 // Licence: wxWindows licence
9 ///////////////////////////////////////////////////////////////////////////////
10
11 // ----------------------------------------------------------------------------
12 // headers
13 // ----------------------------------------------------------------------------
14
15 #include "testprec.h"
16
17 #if wxUSE_IMAGE
18
19 #ifdef __BORLANDC__
20 #pragma hdrstop
21 #endif
22
23 #ifndef WX_PRECOMP
24 #endif // WX_PRECOMP
25
26 #include "wx/anidecod.h" // wxImageArray
27 #include "wx/palette.h"
28 #include "wx/url.h"
29 #include "wx/log.h"
30 #include "wx/mstream.h"
31 #include "wx/zstream.h"
32 #include "wx/wfstream.h"
33
34 #include "testimage.h"
35
36 struct testData {
37 const char* file;
38 wxBitmapType type;
39 unsigned bitDepth;
40 } g_testfiles[] =
41 {
42 { "horse.ico", wxBITMAP_TYPE_ICO, 4 },
43 { "horse.xpm", wxBITMAP_TYPE_XPM, 8 },
44 { "horse.png", wxBITMAP_TYPE_PNG, 24 },
45 { "horse.ani", wxBITMAP_TYPE_ANI, 24 },
46 { "horse.bmp", wxBITMAP_TYPE_BMP, 8 },
47 { "horse.cur", wxBITMAP_TYPE_CUR, 1 },
48 { "horse.gif", wxBITMAP_TYPE_GIF, 8 },
49 { "horse.jpg", wxBITMAP_TYPE_JPEG, 24 },
50 { "horse.pcx", wxBITMAP_TYPE_PCX, 8 },
51 { "horse.pnm", wxBITMAP_TYPE_PNM, 24 },
52 { "horse.tga", wxBITMAP_TYPE_TGA, 8 },
53 { "horse.tif", wxBITMAP_TYPE_TIF, 8 }
54 };
55
56
57 // ----------------------------------------------------------------------------
58 // test class
59 // ----------------------------------------------------------------------------
60
61 class ImageTestCase : public CppUnit::TestCase
62 {
63 public:
64 ImageTestCase();
65 ~ImageTestCase();
66
67 private:
68 CPPUNIT_TEST_SUITE( ImageTestCase );
69 CPPUNIT_TEST( LoadFromSocketStream );
70 CPPUNIT_TEST( LoadFromZipStream );
71 CPPUNIT_TEST( LoadFromFile );
72 CPPUNIT_TEST( SizeImage );
73 CPPUNIT_TEST( CompareLoadedImage );
74 CPPUNIT_TEST( CompareSavedImage );
75 CPPUNIT_TEST( SavePNG );
76 CPPUNIT_TEST( SaveAnimatedGIF );
77 CPPUNIT_TEST( ReadCorruptedTGA );
78 CPPUNIT_TEST( GIFComment );
79 CPPUNIT_TEST( DibPadding );
80 CPPUNIT_TEST( BMPFlippingAndRLECompression );
81 CPPUNIT_TEST_SUITE_END();
82
83 void LoadFromSocketStream();
84 void LoadFromZipStream();
85 void LoadFromFile();
86 void SizeImage();
87 void CompareLoadedImage();
88 void CompareSavedImage();
89 void SavePNG();
90 void SaveAnimatedGIF();
91 void ReadCorruptedTGA();
92 void GIFComment();
93 void DibPadding();
94 void BMPFlippingAndRLECompression();
95
96 DECLARE_NO_COPY_CLASS(ImageTestCase)
97 };
98
99 CPPUNIT_TEST_SUITE_REGISTRATION( ImageTestCase );
100 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( ImageTestCase, "ImageTestCase" );
101
102 ImageTestCase::ImageTestCase()
103 {
104 wxSocketBase::Initialize();
105
106 // the formats we're going to test:
107 wxImage::AddHandler(new wxICOHandler);
108 wxImage::AddHandler(new wxXPMHandler);
109 wxImage::AddHandler(new wxPNGHandler);
110 wxImage::AddHandler(new wxANIHandler);
111 wxImage::AddHandler(new wxBMPHandler);
112 wxImage::AddHandler(new wxCURHandler);
113 wxImage::AddHandler(new wxGIFHandler);
114 wxImage::AddHandler(new wxJPEGHandler);
115 wxImage::AddHandler(new wxPCXHandler);
116 wxImage::AddHandler(new wxPNMHandler);
117 wxImage::AddHandler(new wxTGAHandler);
118 wxImage::AddHandler(new wxTIFFHandler);
119 }
120
121 ImageTestCase::~ImageTestCase()
122 {
123 wxSocketBase::Shutdown();
124 }
125
126 void ImageTestCase::LoadFromFile()
127 {
128 wxImage img;
129 for (unsigned int i=0; i<WXSIZEOF(g_testfiles); i++)
130 CPPUNIT_ASSERT(img.LoadFile(g_testfiles[i].file));
131 }
132
133 void ImageTestCase::LoadFromSocketStream()
134 {
135 if (!IsNetworkAvailable()) // implemented in test.cpp
136 {
137 wxLogWarning("No network connectivity; skipping the "
138 "ImageTestCase::LoadFromSocketStream test unit.");
139 return;
140 }
141
142 struct {
143 const char* url;
144 wxBitmapType type;
145 } testData[] =
146 {
147 { "http://www.wxwidgets.org/logo9.jpg", wxBITMAP_TYPE_JPEG },
148 { "http://www.wxwidgets.org/favicon.ico", wxBITMAP_TYPE_ICO }
149 };
150
151 for (unsigned int i=0; i<WXSIZEOF(testData); i++)
152 {
153 wxURL url(testData[i].url);
154 WX_ASSERT_EQUAL_MESSAGE
155 (
156 ("Constructing URL \"%s\" failed.", testData[i].url),
157 wxURL_NOERR,
158 url.GetError()
159 );
160
161 wxInputStream *in_stream = url.GetInputStream();
162 WX_ASSERT_MESSAGE
163 (
164 ("Opening URL \"%s\" failed.", testData[i].url),
165 in_stream && in_stream->IsOk()
166 );
167
168 wxImage img;
169
170 // NOTE: it's important to inform wxImage about the type of the image being
171 // loaded otherwise it will try to autodetect the format, but that
172 // requires a seekable stream!
173 WX_ASSERT_MESSAGE
174 (
175 ("Loading image from \"%s\" failed.", testData[i].url),
176 img.LoadFile(*in_stream, testData[i].type)
177 );
178
179 delete in_stream;
180 }
181 }
182
183 void ImageTestCase::LoadFromZipStream()
184 {
185 for (unsigned int i=0; i<WXSIZEOF(g_testfiles); i++)
186 {
187 switch (g_testfiles[i].type)
188 {
189 case wxBITMAP_TYPE_XPM:
190 case wxBITMAP_TYPE_GIF:
191 case wxBITMAP_TYPE_PCX:
192 case wxBITMAP_TYPE_TGA:
193 case wxBITMAP_TYPE_TIF:
194 continue; // skip testing those wxImageHandlers which cannot
195 // load data from non-seekable streams
196
197 default:
198 ; // proceed
199 }
200
201 // compress the test file on the fly:
202 wxMemoryOutputStream memOut;
203 {
204 wxFileInputStream file(g_testfiles[i].file);
205 CPPUNIT_ASSERT(file.IsOk());
206
207 wxZlibOutputStream compressFilter(memOut, 5, wxZLIB_GZIP);
208 CPPUNIT_ASSERT(compressFilter.IsOk());
209
210 file.Read(compressFilter);
211 CPPUNIT_ASSERT(file.GetLastError() == wxSTREAM_EOF);
212 }
213
214 // now fetch the compressed memory to wxImage, decompressing it on the fly; this
215 // allows us to test loading images from non-seekable streams other than socket streams
216 wxMemoryInputStream memIn(memOut);
217 CPPUNIT_ASSERT(memIn.IsOk());
218 wxZlibInputStream decompressFilter(memIn, wxZLIB_GZIP);
219 CPPUNIT_ASSERT(decompressFilter.IsOk());
220
221 wxImage img;
222
223 // NOTE: it's important to inform wxImage about the type of the image being
224 // loaded otherwise it will try to autodetect the format, but that
225 // requires a seekable stream!
226 WX_ASSERT_MESSAGE(("Could not load file type '%d' after it was zipped", g_testfiles[i].type),
227 img.LoadFile(decompressFilter, g_testfiles[i].type));
228 }
229 }
230
231 void ImageTestCase::SizeImage()
232 {
233 // Test the wxImage::Size() function which takes a rectangle from source and
234 // places it in a new image at a given position. This test checks, if the
235 // correct areas are chosen, and clipping is done correctly.
236
237 // our test image:
238 static const char * xpm_orig[] = {
239 "10 10 5 1", "B c Black", " c #00ff00", ". c #0000ff", "+ c #7f7f7f", "@ c #FF0000",
240 " .....",
241 " ++++@@@@.",
242 " +... @.",
243 " +.@@++ @.",
244 " +.@ .+ @.",
245 ".@ +. @.+ ",
246 ".@ ++@@.+ ",
247 ".@ ...+ ",
248 ".@@@@++++ ",
249 "..... "
250 };
251 // the expected results for all tests:
252 static const char * xpm_l_t[] = {
253 "10 10 5 1", "B c Black", " c #00ff00", ". c #0000ff", "+ c #7f7f7f", "@ c #FF0000",
254 "... @.BB",
255 ".@@++ @.BB",
256 ".@ .+ @.BB",
257 " +. @.+ BB",
258 " ++@@.+ BB",
259 " ...+ BB",
260 "@@@++++ BB",
261 "... BB",
262 "BBBBBBBBBB",
263 "BBBBBBBBBB"
264 };
265 static const char * xpm_t[] = {
266 "10 10 5 1", "B c Black", " c #00ff00", ". c #0000ff", "+ c #7f7f7f", "@ c #FF0000",
267 " +... @.",
268 " +.@@++ @.",
269 " +.@ .+ @.",
270 ".@ +. @.+ ",
271 ".@ ++@@.+ ",
272 ".@ ...+ ",
273 ".@@@@++++ ",
274 "..... ",
275 "BBBBBBBBBB",
276 "BBBBBBBBBB"
277 };
278 static const char * xpm_r_t[] = {
279 "10 10 5 1", "B c Black", " c #00ff00", ". c #0000ff", "+ c #7f7f7f", "@ c #FF0000",
280 "BB +... ",
281 "BB +.@@++ ",
282 "BB +.@ .+ ",
283 "BB.@ +. @.",
284 "BB.@ ++@@.",
285 "BB.@ ...",
286 "BB.@@@@+++",
287 "BB..... ",
288 "BBBBBBBBBB",
289 "BBBBBBBBBB"
290 };
291 static const char * xpm_l[] = {
292 "10 10 5 1", "B c Black", " c #00ff00", ". c #0000ff", "+ c #7f7f7f", "@ c #FF0000",
293 " .....BB",
294 "+++@@@@.BB",
295 "... @.BB",
296 ".@@++ @.BB",
297 ".@ .+ @.BB",
298 " +. @.+ BB",
299 " ++@@.+ BB",
300 " ...+ BB",
301 "@@@++++ BB",
302 "... BB"
303 };
304 static const char * xpm_r[] = {
305 "10 10 5 1", "B c Black", " c #00ff00", ". c #0000ff", "+ c #7f7f7f", "@ c #FF0000",
306 "BB ...",
307 "BB ++++@@@",
308 "BB +... ",
309 "BB +.@@++ ",
310 "BB +.@ .+ ",
311 "BB.@ +. @.",
312 "BB.@ ++@@.",
313 "BB.@ ...",
314 "BB.@@@@+++",
315 "BB..... "
316 };
317 static const char * xpm_l_b[] = {
318 "10 10 5 1", "B c Black", " c #00ff00", ". c #0000ff", "+ c #7f7f7f", "@ c #FF0000",
319 "BBBBBBBBBB",
320 "BBBBBBBBBB",
321 " .....BB",
322 "+++@@@@.BB",
323 "... @.BB",
324 ".@@++ @.BB",
325 ".@ .+ @.BB",
326 " +. @.+ BB",
327 " ++@@.+ BB",
328 " ...+ BB"
329 };
330 static const char * xpm_b[] = {
331 "10 10 5 1", "B c Black", " c #00ff00", ". c #0000ff", "+ c #7f7f7f", "@ c #FF0000",
332 "BBBBBBBBBB",
333 "BBBBBBBBBB",
334 " .....",
335 " ++++@@@@.",
336 " +... @.",
337 " +.@@++ @.",
338 " +.@ .+ @.",
339 ".@ +. @.+ ",
340 ".@ ++@@.+ ",
341 ".@ ...+ "
342 };
343 static const char * xpm_r_b[] = {
344 "10 10 5 1", "B c Black", " c #00ff00", ". c #0000ff", "+ c #7f7f7f", "@ c #FF0000",
345 "BBBBBBBBBB",
346 "BBBBBBBBBB",
347 "BB ...",
348 "BB ++++@@@",
349 "BB +... ",
350 "BB +.@@++ ",
351 "BB +.@ .+ ",
352 "BB.@ +. @.",
353 "BB.@ ++@@.",
354 "BB.@ ..."
355 };
356 static const char * xpm_sm[] = {
357 "8 8 5 1", "B c Black", " c #00ff00", ". c #0000ff", "+ c #7f7f7f", "@ c #FF0000",
358 " .....",
359 " ++++@@@",
360 " +... ",
361 " +.@@++ ",
362 " +.@ .+ ",
363 ".@ +. @.",
364 ".@ ++@@.",
365 ".@ ..."
366 };
367 static const char * xpm_gt[] = {
368 "12 12 5 1", "B c Black", " c #00ff00", ". c #0000ff", "+ c #7f7f7f", "@ c #FF0000",
369 " .....BB",
370 " ++++@@@@.BB",
371 " +... @.BB",
372 " +.@@++ @.BB",
373 " +.@ .+ @.BB",
374 ".@ +. @.+ BB",
375 ".@ ++@@.+ BB",
376 ".@ ...+ BB",
377 ".@@@@++++ BB",
378 "..... BB",
379 "BBBBBBBBBBBB",
380 "BBBBBBBBBBBB"
381 };
382 static const char * xpm_gt_l_t[] = {
383 "12 12 5 1", "B c Black", " c #00ff00", ". c #0000ff", "+ c #7f7f7f", "@ c #FF0000",
384 "... @.BBBB",
385 ".@@++ @.BBBB",
386 ".@ .+ @.BBBB",
387 " +. @.+ BBBB",
388 " ++@@.+ BBBB",
389 " ...+ BBBB",
390 "@@@++++ BBBB",
391 "... BBBB",
392 "BBBBBBBBBBBB",
393 "BBBBBBBBBBBB",
394 "BBBBBBBBBBBB",
395 "BBBBBBBBBBBB"
396 };
397 static const char * xpm_gt_l[] = {
398 "12 12 5 1", "B c Black", " c #00ff00", ". c #0000ff", "+ c #7f7f7f", "@ c #FF0000",
399 " .....BBBB",
400 "+++@@@@.BBBB",
401 "... @.BBBB",
402 ".@@++ @.BBBB",
403 ".@ .+ @.BBBB",
404 " +. @.+ BBBB",
405 " ++@@.+ BBBB",
406 " ...+ BBBB",
407 "@@@++++ BBBB",
408 "... BBBB",
409 "BBBBBBBBBBBB",
410 "BBBBBBBBBBBB"
411 };
412 static const char * xpm_gt_l_b[] = {
413 "12 12 5 1", "B c Black", " c #00ff00", ". c #0000ff", "+ c #7f7f7f", "@ c #FF0000",
414 "BBBBBBBBBBBB",
415 "BBBBBBBBBBBB",
416 " .....BBBB",
417 "+++@@@@.BBBB",
418 "... @.BBBB",
419 ".@@++ @.BBBB",
420 ".@ .+ @.BBBB",
421 " +. @.+ BBBB",
422 " ++@@.+ BBBB",
423 " ...+ BBBB",
424 "@@@++++ BBBB",
425 "... BBBB"
426 };
427 static const char * xpm_gt_l_bb[] = {
428 "12 12 5 1", "B c Black", " c #00ff00", ". c #0000ff", "+ c #7f7f7f", "@ c #FF0000",
429 "BBBBBBBBBBBB",
430 "BBBBBBBBBBBB",
431 "BBBBBBBBBBBB",
432 "BBBBBBBBBBBB",
433 " .....BBBB",
434 "+++@@@@.BBBB",
435 "... @.BBBB",
436 ".@@++ @.BBBB",
437 ".@ .+ @.BBBB",
438 " +. @.+ BBBB",
439 " ++@@.+ BBBB",
440 " ...+ BBBB"
441 };
442 static const char * xpm_gt_t[] = {
443 "12 12 5 1", "B c Black", " c #00ff00", ". c #0000ff", "+ c #7f7f7f", "@ c #FF0000",
444 " +... @.BB",
445 " +.@@++ @.BB",
446 " +.@ .+ @.BB",
447 ".@ +. @.+ BB",
448 ".@ ++@@.+ BB",
449 ".@ ...+ BB",
450 ".@@@@++++ BB",
451 "..... BB",
452 "BBBBBBBBBBBB",
453 "BBBBBBBBBBBB",
454 "BBBBBBBBBBBB",
455 "BBBBBBBBBBBB"
456 };
457 static const char * xpm_gt_b[] = {
458 "12 12 5 1", "B c Black", " c #00ff00", ". c #0000ff", "+ c #7f7f7f", "@ c #FF0000",
459 "BBBBBBBBBBBB",
460 "BBBBBBBBBBBB",
461 " .....BB",
462 " ++++@@@@.BB",
463 " +... @.BB",
464 " +.@@++ @.BB",
465 " +.@ .+ @.BB",
466 ".@ +. @.+ BB",
467 ".@ ++@@.+ BB",
468 ".@ ...+ BB",
469 ".@@@@++++ BB",
470 "..... BB"
471 };
472 static const char * xpm_gt_bb[] = {
473 "12 12 5 1", "B c Black", " c #00ff00", ". c #0000ff", "+ c #7f7f7f", "@ c #FF0000",
474 "BBBBBBBBBBBB",
475 "BBBBBBBBBBBB",
476 "BBBBBBBBBBBB",
477 "BBBBBBBBBBBB",
478 " .....BB",
479 " ++++@@@@.BB",
480 " +... @.BB",
481 " +.@@++ @.BB",
482 " +.@ .+ @.BB",
483 ".@ +. @.+ BB",
484 ".@ ++@@.+ BB",
485 ".@ ...+ BB"
486 };
487 static const char * xpm_gt_r_t[] = {
488 "12 12 5 1", "B c Black", " c #00ff00", ". c #0000ff", "+ c #7f7f7f", "@ c #FF0000",
489 "BB +... @.",
490 "BB +.@@++ @.",
491 "BB +.@ .+ @.",
492 "BB.@ +. @.+ ",
493 "BB.@ ++@@.+ ",
494 "BB.@ ...+ ",
495 "BB.@@@@++++ ",
496 "BB..... ",
497 "BBBBBBBBBBBB",
498 "BBBBBBBBBBBB",
499 "BBBBBBBBBBBB",
500 "BBBBBBBBBBBB"
501 };
502 static const char * xpm_gt_r[] = {
503 "12 12 5 1", "B c Black", " c #00ff00", ". c #0000ff", "+ c #7f7f7f", "@ c #FF0000",
504 "BB .....",
505 "BB ++++@@@@.",
506 "BB +... @.",
507 "BB +.@@++ @.",
508 "BB +.@ .+ @.",
509 "BB.@ +. @.+ ",
510 "BB.@ ++@@.+ ",
511 "BB.@ ...+ ",
512 "BB.@@@@++++ ",
513 "BB..... ",
514 "BBBBBBBBBBBB",
515 "BBBBBBBBBBBB"
516 };
517 static const char * xpm_gt_r_b[] = {
518 "12 12 5 1", "B c Black", " c #00ff00", ". c #0000ff", "+ c #7f7f7f", "@ c #FF0000",
519 "BBBBBBBBBBBB",
520 "BBBBBBBBBBBB",
521 "BB .....",
522 "BB ++++@@@@.",
523 "BB +... @.",
524 "BB +.@@++ @.",
525 "BB +.@ .+ @.",
526 "BB.@ +. @.+ ",
527 "BB.@ ++@@.+ ",
528 "BB.@ ...+ ",
529 "BB.@@@@++++ ",
530 "BB..... "
531 };
532 static const char * xpm_gt_r_bb[] = {
533 "12 12 5 1", "B c Black", " c #00ff00", ". c #0000ff", "+ c #7f7f7f", "@ c #FF0000",
534 "BBBBBBBBBBBB",
535 "BBBBBBBBBBBB",
536 "BBBBBBBBBBBB",
537 "BBBBBBBBBBBB",
538 "BB .....",
539 "BB ++++@@@@.",
540 "BB +... @.",
541 "BB +.@@++ @.",
542 "BB +.@ .+ @.",
543 "BB.@ +. @.+ ",
544 "BB.@ ++@@.+ ",
545 "BB.@ ...+ "
546 };
547 static const char * xpm_gt_rr_t[] = {
548 "12 12 5 1", "B c Black", " c #00ff00", ". c #0000ff", "+ c #7f7f7f", "@ c #FF0000",
549 "BBBB +... ",
550 "BBBB +.@@++ ",
551 "BBBB +.@ .+ ",
552 "BBBB.@ +. @.",
553 "BBBB.@ ++@@.",
554 "BBBB.@ ...",
555 "BBBB.@@@@+++",
556 "BBBB..... ",
557 "BBBBBBBBBBBB",
558 "BBBBBBBBBBBB",
559 "BBBBBBBBBBBB",
560 "BBBBBBBBBBBB"
561 };
562 static const char * xpm_gt_rr[] = {
563 "12 12 5 1", "B c Black", " c #00ff00", ". c #0000ff", "+ c #7f7f7f", "@ c #FF0000",
564 "BBBB ...",
565 "BBBB ++++@@@",
566 "BBBB +... ",
567 "BBBB +.@@++ ",
568 "BBBB +.@ .+ ",
569 "BBBB.@ +. @.",
570 "BBBB.@ ++@@.",
571 "BBBB.@ ...",
572 "BBBB.@@@@+++",
573 "BBBB..... ",
574 "BBBBBBBBBBBB",
575 "BBBBBBBBBBBB"
576 };
577 static const char * xpm_gt_rr_b[] = {
578 "12 12 5 1", "B c Black", " c #00ff00", ". c #0000ff", "+ c #7f7f7f", "@ c #FF0000",
579 "BBBBBBBBBBBB",
580 "BBBBBBBBBBBB",
581 "BBBB ...",
582 "BBBB ++++@@@",
583 "BBBB +... ",
584 "BBBB +.@@++ ",
585 "BBBB +.@ .+ ",
586 "BBBB.@ +. @.",
587 "BBBB.@ ++@@.",
588 "BBBB.@ ...",
589 "BBBB.@@@@+++",
590 "BBBB..... "
591 };
592 static const char * xpm_gt_rr_bb[] = {
593 "12 12 5 1", "B c Black", " c #00ff00", ". c #0000ff", "+ c #7f7f7f", "@ c #FF0000",
594 "BBBBBBBBBBBB",
595 "BBBBBBBBBBBB",
596 "BBBBBBBBBBBB",
597 "BBBBBBBBBBBB",
598 "BBBB ...",
599 "BBBB ++++@@@",
600 "BBBB +... ",
601 "BBBB +.@@++ ",
602 "BBBB +.@ .+ ",
603 "BBBB.@ +. @.",
604 "BBBB.@ ++@@.",
605 "BBBB.@ ..."
606 };
607 static const char * xpm_sm_ll_tt[] = {
608 "8 8 5 1", "B c Black", " c #00ff00", ". c #0000ff", "+ c #7f7f7f", "@ c #FF0000",
609 " .+ @.BB",
610 ". @.+ BB",
611 "+@@.+ BB",
612 " ...+ BB",
613 "@++++ BB",
614 ". BB",
615 "BBBBBBBB",
616 "BBBBBBBB"
617 };
618 static const char * xpm_sm_ll_t[] = {
619 "8 8 5 1", "B c Black", " c #00ff00", ". c #0000ff", "+ c #7f7f7f", "@ c #FF0000",
620 ". @.BB",
621 "@++ @.BB",
622 " .+ @.BB",
623 ". @.+ BB",
624 "+@@.+ BB",
625 " ...+ BB",
626 "@++++ BB",
627 ". BB"
628 };
629 static const char * xpm_sm_ll[] = {
630 "8 8 5 1", "B c Black", " c #00ff00", ". c #0000ff", "+ c #7f7f7f", "@ c #FF0000",
631 " .....BB",
632 "+@@@@.BB",
633 ". @.BB",
634 "@++ @.BB",
635 " .+ @.BB",
636 ". @.+ BB",
637 "+@@.+ BB",
638 " ...+ BB"
639 };
640 static const char * xpm_sm_ll_b[] = {
641 "8 8 5 1", "B c Black", " c #00ff00", ". c #0000ff", "+ c #7f7f7f", "@ c #FF0000",
642 "BBBBBBBB",
643 "BBBBBBBB",
644 " .....BB",
645 "+@@@@.BB",
646 ". @.BB",
647 "@++ @.BB",
648 " .+ @.BB",
649 ". @.+ BB"
650 };
651 static const char * xpm_sm_l_tt[] = {
652 "8 8 5 1", "B c Black", " c #00ff00", ". c #0000ff", "+ c #7f7f7f", "@ c #FF0000",
653 ".@ .+ @.",
654 " +. @.+ ",
655 " ++@@.+ ",
656 " ...+ ",
657 "@@@++++ ",
658 "... ",
659 "BBBBBBBB",
660 "BBBBBBBB"
661 };
662 static const char * xpm_sm_l_t[] = {
663 "8 8 5 1", "B c Black", " c #00ff00", ". c #0000ff", "+ c #7f7f7f", "@ c #FF0000",
664 "... @.",
665 ".@@++ @.",
666 ".@ .+ @.",
667 " +. @.+ ",
668 " ++@@.+ ",
669 " ...+ ",
670 "@@@++++ ",
671 "... "
672 };
673 static const char * xpm_sm_l[] = {
674 "8 8 5 1", "B c Black", " c #00ff00", ". c #0000ff", "+ c #7f7f7f", "@ c #FF0000",
675 " .....",
676 "+++@@@@.",
677 "... @.",
678 ".@@++ @.",
679 ".@ .+ @.",
680 " +. @.+ ",
681 " ++@@.+ ",
682 " ...+ "
683 };
684 static const char * xpm_sm_l_b[] = {
685 "8 8 5 1", "B c Black", " c #00ff00", ". c #0000ff", "+ c #7f7f7f", "@ c #FF0000",
686 "BBBBBBBB",
687 "BBBBBBBB",
688 " .....",
689 "+++@@@@.",
690 "... @.",
691 ".@@++ @.",
692 ".@ .+ @.",
693 " +. @.+ "
694 };
695 static const char * xpm_sm_tt[] = {
696 "8 8 5 1", "B c Black", " c #00ff00", ". c #0000ff", "+ c #7f7f7f", "@ c #FF0000",
697 " +.@ .+ ",
698 ".@ +. @.",
699 ".@ ++@@.",
700 ".@ ...",
701 ".@@@@+++",
702 "..... ",
703 "BBBBBBBB",
704 "BBBBBBBB"
705 };
706 static const char * xpm_sm_t[] = {
707 "8 8 5 1", "B c Black", " c #00ff00", ". c #0000ff", "+ c #7f7f7f", "@ c #FF0000",
708 " +... ",
709 " +.@@++ ",
710 " +.@ .+ ",
711 ".@ +. @.",
712 ".@ ++@@.",
713 ".@ ...",
714 ".@@@@+++",
715 "..... "
716 };
717 static const char * xpm_sm_b[] = {
718 "8 8 5 1", "B c Black", " c #00ff00", ". c #0000ff", "+ c #7f7f7f", "@ c #FF0000",
719 "BBBBBBBB",
720 "BBBBBBBB",
721 " ...",
722 " ++++@@@",
723 " +... ",
724 " +.@@++ ",
725 " +.@ .+ ",
726 ".@ +. @."
727 };
728 static const char * xpm_sm_r_tt[] = {
729 "8 8 5 1", "B c Black", " c #00ff00", ". c #0000ff", "+ c #7f7f7f", "@ c #FF0000",
730 "BB +.@ .",
731 "BB.@ +. ",
732 "BB.@ ++@",
733 "BB.@ .",
734 "BB.@@@@+",
735 "BB..... ",
736 "BBBBBBBB",
737 "BBBBBBBB"
738 };
739 static const char * xpm_sm_r_t[] = {
740 "8 8 5 1", "B c Black", " c #00ff00", ". c #0000ff", "+ c #7f7f7f", "@ c #FF0000",
741 "BB +... ",
742 "BB +.@@+",
743 "BB +.@ .",
744 "BB.@ +. ",
745 "BB.@ ++@",
746 "BB.@ .",
747 "BB.@@@@+",
748 "BB..... "
749 };
750 static const char * xpm_sm_r[] = {
751 "8 8 5 1", "B c Black", " c #00ff00", ". c #0000ff", "+ c #7f7f7f", "@ c #FF0000",
752 "BB .",
753 "BB ++++@",
754 "BB +... ",
755 "BB +.@@+",
756 "BB +.@ .",
757 "BB.@ +. ",
758 "BB.@ ++@",
759 "BB.@ ."
760 };
761 static const char * xpm_sm_r_b[] = {
762 "8 8 5 1", "B c Black", " c #00ff00", ". c #0000ff", "+ c #7f7f7f", "@ c #FF0000",
763 "BBBBBBBB",
764 "BBBBBBBB",
765 "BB .",
766 "BB ++++@",
767 "BB +... ",
768 "BB +.@@+",
769 "BB +.@ .",
770 "BB.@ +. "
771 };
772
773 // this table defines all tests
774 struct SizeTestData
775 {
776 int w, h, dx, dy; // first parameters for Size()
777 const char **ref_xpm; // expected result
778 } sizeTestData[] =
779 {
780 { 10, 10, 0, 0, xpm_orig}, // same size, same position
781 { 12, 12, 0, 0, xpm_gt}, // target larger, same position
782 { 8, 8, 0, 0, xpm_sm}, // target smaller, same position
783 { 10, 10, -2, -2, xpm_l_t}, // same size, move left up
784 { 10, 10, -2, 0, xpm_l}, // same size, move left
785 { 10, 10, -2, 2, xpm_l_b}, // same size, move left down
786 { 10, 10, 0, -2, xpm_t}, // same size, move up
787 { 10, 10, 0, 2, xpm_b}, // same size, move down
788 { 10, 10, 2, -2, xpm_r_t}, // same size, move right up
789 { 10, 10, 2, 0, xpm_r}, // same size, move right
790 { 10, 10, 2, 2, xpm_r_b}, // same size, move right down
791 { 12, 12, -2, -2, xpm_gt_l_t}, // target larger, move left up
792 { 12, 12, -2, 0, xpm_gt_l}, // target larger, move left
793 { 12, 12, -2, 2, xpm_gt_l_b}, // target larger, move left down
794 { 12, 12, -2, 4, xpm_gt_l_bb}, // target larger, move left down
795 { 12, 12, 0, -2, xpm_gt_t}, // target larger, move up
796 { 12, 12, 0, 2, xpm_gt_b}, // target larger, move down
797 { 12, 12, 0, 4, xpm_gt_bb}, // target larger, move down
798 { 12, 12, 2, -2, xpm_gt_r_t}, // target larger, move right up
799 { 12, 12, 2, 0, xpm_gt_r}, // target larger, move right
800 { 12, 12, 2, 2, xpm_gt_r_b}, // target larger, move right down
801 { 12, 12, 2, 4, xpm_gt_r_bb}, // target larger, move right down
802 { 12, 12, 4, -2, xpm_gt_rr_t}, // target larger, move right up
803 { 12, 12, 4, 0, xpm_gt_rr}, // target larger, move right
804 { 12, 12, 4, 2, xpm_gt_rr_b}, // target larger, move right down
805 { 12, 12, 4, 4, xpm_gt_rr_bb}, // target larger, move right down
806 { 8, 8, -4, -4, xpm_sm_ll_tt}, // target smaller, move left up
807 { 8, 8, -4, -2, xpm_sm_ll_t}, // target smaller, move left up
808 { 8, 8, -4, 0, xpm_sm_ll}, // target smaller, move left
809 { 8, 8, -4, 2, xpm_sm_ll_b}, // target smaller, move left down
810 { 8, 8, -2, -4, xpm_sm_l_tt}, // target smaller, move left up
811 { 8, 8, -2, -2, xpm_sm_l_t}, // target smaller, move left up
812 { 8, 8, -2, 0, xpm_sm_l}, // target smaller, move left
813 { 8, 8, -2, 2, xpm_sm_l_b}, // target smaller, move left down
814 { 8, 8, 0, -4, xpm_sm_tt}, // target smaller, move up
815 { 8, 8, 0, -2, xpm_sm_t}, // target smaller, move up
816 { 8, 8, 0, 2, xpm_sm_b}, // target smaller, move down
817 { 8, 8, 2, -4, xpm_sm_r_tt}, // target smaller, move right up
818 { 8, 8, 2, -2, xpm_sm_r_t}, // target smaller, move right up
819 { 8, 8, 2, 0, xpm_sm_r}, // target smaller, move right
820 { 8, 8, 2, 2, xpm_sm_r_b}, // target smaller, move right down
821 };
822
823 const wxImage src_img(xpm_orig);
824 for ( unsigned i = 0; i < WXSIZEOF(sizeTestData); i++ )
825 {
826 SizeTestData& st = sizeTestData[i];
827 wxImage
828 actual(src_img.Size(wxSize(st.w, st.h), wxPoint(st.dx, st.dy), 0, 0, 0)),
829 expected(st.ref_xpm);
830
831 // to check results with an image viewer uncomment this:
832 //actual.SaveFile(wxString::Format("imagetest-%02d-actual.png", i), wxBITMAP_TYPE_PNG);
833 //expected.SaveFile(wxString::Format("imagetest-%02d-exp.png", i), wxBITMAP_TYPE_PNG);
834
835 CPPUNIT_ASSERT_EQUAL( actual.GetSize().x, expected.GetSize().x );
836 CPPUNIT_ASSERT_EQUAL( actual.GetSize().y, expected.GetSize().y );
837
838 WX_ASSERT_EQUAL_MESSAGE
839 (
840 ("Resize test #%u: (%d, %d), (%d, %d)", i, st.w, st.h, st.dx, st.dy),
841 expected, actual
842 );
843 }
844 }
845
846 void ImageTestCase::CompareLoadedImage()
847 {
848 wxImage expected8("horse.xpm");
849 CPPUNIT_ASSERT( expected8.IsOk() );
850
851 wxImage expected24("horse.png");
852 CPPUNIT_ASSERT( expected24.IsOk() );
853
854 for (size_t i=0; i<WXSIZEOF(g_testfiles); i++)
855 {
856 if ( !(g_testfiles[i].bitDepth == 8 || g_testfiles[i].bitDepth == 24)
857 || g_testfiles[i].type == wxBITMAP_TYPE_JPEG /*skip lossy JPEG*/)
858 {
859 continue;
860 }
861
862 wxImage actual(g_testfiles[i].file);
863
864 if ( actual.GetSize() != expected8.GetSize() )
865 {
866 continue;
867 }
868
869
870 WX_ASSERT_EQUAL_MESSAGE
871 (
872 ("Compare test '%s' for loading failed", g_testfiles[i].file),
873 g_testfiles[i].bitDepth == 8 ? expected8 : expected24,
874 actual
875 );
876 }
877
878 }
879
880 enum
881 {
882 wxIMAGE_HAVE_ALPHA = (1 << 0),
883 wxIMAGE_HAVE_PALETTE = (1 << 1)
884 };
885
886 static
887 void CompareImage(const wxImageHandler& handler, const wxImage& image,
888 int properties = 0, const wxImage *compareTo = NULL)
889 {
890 wxBitmapType type = handler.GetType();
891
892 const bool testPalette = (properties & wxIMAGE_HAVE_PALETTE) != 0;
893 /*
894 This is getting messy and should probably be transformed into a table
895 with image format features before it gets hairier.
896 */
897 if ( testPalette
898 && ( !(type == wxBITMAP_TYPE_BMP
899 || type == wxBITMAP_TYPE_GIF
900 || type == wxBITMAP_TYPE_ICO
901 || type == wxBITMAP_TYPE_PNG)
902 || type == wxBITMAP_TYPE_XPM) )
903 {
904 return;
905 }
906
907 const bool testAlpha = (properties & wxIMAGE_HAVE_ALPHA) != 0;
908 if (testAlpha
909 && !(type == wxBITMAP_TYPE_PNG || type == wxBITMAP_TYPE_TGA) )
910 {
911 // don't test images with alpha if this handler doesn't support alpha
912 return;
913 }
914
915 if (type == wxBITMAP_TYPE_JPEG /* skip lossy JPEG */
916 || type == wxBITMAP_TYPE_TIF)
917 {
918 /*
919 TIFF is skipped because the memory stream can't be loaded. Libtiff
920 looks for a TIFF directory at offset 120008 while the memory
921 stream size is only 120008 bytes (when saving as a file
922 the file size is 120280 bytes).
923 */
924 return;
925 }
926
927 wxMemoryOutputStream memOut;
928 if ( !image.SaveFile(memOut, type) )
929 {
930 // Unfortunately we can't know if the handler just doesn't support
931 // saving images, or if it failed to save.
932 return;
933 }
934
935 wxMemoryInputStream memIn(memOut);
936 CPPUNIT_ASSERT(memIn.IsOk());
937
938 wxImage actual(memIn);
939 CPPUNIT_ASSERT(actual.IsOk());
940
941 const wxImage *expected = compareTo ? compareTo : &image;
942 CPPUNIT_ASSERT( actual.GetSize() == expected->GetSize() );
943
944 unsigned bitsPerPixel = testPalette ? 8 : (testAlpha ? 32 : 24);
945 WX_ASSERT_EQUAL_MESSAGE
946 (
947 ("Compare test '%s (%d-bit)' for saving failed",
948 handler.GetExtension(), bitsPerPixel),
949 *expected,
950 actual
951 );
952
953 #if wxUSE_PALETTE
954 CPPUNIT_ASSERT(actual.HasPalette()
955 == (testPalette || type == wxBITMAP_TYPE_XPM));
956 #endif
957
958 CPPUNIT_ASSERT( actual.HasAlpha() == testAlpha);
959
960 if (!testAlpha)
961 {
962 return;
963 }
964
965 WX_ASSERT_EQUAL_MESSAGE
966 (
967 ("Compare alpha test '%s' for saving failed", handler.GetExtension()),
968 *expected,
969 actual
970 );
971 }
972
973 void ImageTestCase::CompareSavedImage()
974 {
975 // FIXME-VC6: Pre-declare the loop variables for compatibility with
976 // pre-standard compilers such as MSVC6 that don't implement proper scope
977 // for the variables declared in the for loops.
978 int i, x, y;
979
980 wxImage expected24("horse.png");
981 CPPUNIT_ASSERT( expected24.IsOk() );
982 CPPUNIT_ASSERT( !expected24.HasAlpha() );
983
984 wxImage expected8 = expected24.ConvertToGreyscale();
985
986 #if wxUSE_PALETTE
987 unsigned char greys[256];
988 for (i = 0; i < 256; ++i)
989 {
990 greys[i] = i;
991 }
992 wxPalette palette(256, greys, greys, greys);
993 expected8.SetPalette(palette);
994 #endif // #if wxUSE_PALETTE
995
996 expected8.SetOption(wxIMAGE_OPTION_BMP_FORMAT, wxBMP_8BPP_PALETTE);
997
998 // Create an image with alpha based on the loaded image
999 wxImage expected32(expected24);
1000 expected32.SetAlpha();
1001
1002 int width = expected32.GetWidth();
1003 int height = expected32.GetHeight();
1004 for (y = 0; y < height; ++y)
1005 {
1006 for (x = 0; x < width; ++x)
1007 {
1008 expected32.SetAlpha(x, y, (x*y) & wxIMAGE_ALPHA_OPAQUE);
1009 }
1010 }
1011
1012 const wxList& list = wxImage::GetHandlers();
1013 for ( wxList::compatibility_iterator node = list.GetFirst();
1014 node; node = node->GetNext() )
1015 {
1016 wxImageHandler *handler = (wxImageHandler *) node->GetData();
1017
1018 #if wxUSE_PALETTE
1019 CompareImage(*handler, expected8, wxIMAGE_HAVE_PALETTE);
1020 #endif
1021 CompareImage(*handler, expected24);
1022 CompareImage(*handler, expected32, wxIMAGE_HAVE_ALPHA);
1023 }
1024 }
1025
1026 void ImageTestCase::SavePNG()
1027 {
1028 wxImage expected24("horse.png");
1029 CPPUNIT_ASSERT( expected24.IsOk() );
1030 #if wxUSE_PALETTE
1031 CPPUNIT_ASSERT( !expected24.HasPalette() );
1032 #endif // #if wxUSE_PALETTE
1033
1034 wxImage expected8 = expected24.ConvertToGreyscale();
1035
1036 /*
1037 horse.png converted to greyscale should be saved without a palette.
1038 */
1039 CompareImage(*wxImage::FindHandler(wxBITMAP_TYPE_PNG), expected8);
1040
1041 /*
1042 But if we explicitly ask for trying to save with a palette, it should work.
1043 */
1044 expected8.SetOption(wxIMAGE_OPTION_PNG_FORMAT, wxPNG_TYPE_PALETTE);
1045
1046 CompareImage(*wxImage::FindHandler(wxBITMAP_TYPE_PNG),
1047 expected8, wxIMAGE_HAVE_PALETTE);
1048
1049
1050 CPPUNIT_ASSERT( expected8.LoadFile("horse.gif") );
1051 #if wxUSE_PALETTE
1052 CPPUNIT_ASSERT( expected8.HasPalette() );
1053 #endif // #if wxUSE_PALETTE
1054
1055 CompareImage(*wxImage::FindHandler(wxBITMAP_TYPE_PNG),
1056 expected8, wxIMAGE_HAVE_PALETTE);
1057
1058 /*
1059 Add alpha to the image in such a way that there will still be a maximum
1060 of 256 unique RGBA combinations. This should result in a saved
1061 PNG image still being palettised and having alpha.
1062 */
1063 expected8.SetAlpha();
1064
1065 int x, y;
1066 const int width = expected8.GetWidth();
1067 const int height = expected8.GetHeight();
1068 for (y = 0; y < height; ++y)
1069 {
1070 for (x = 0; x < width; ++x)
1071 {
1072 expected8.SetAlpha(x, y, expected8.GetRed(x, y));
1073 }
1074 }
1075
1076 CompareImage(*wxImage::FindHandler(wxBITMAP_TYPE_PNG),
1077 expected8, wxIMAGE_HAVE_ALPHA|wxIMAGE_HAVE_PALETTE);
1078
1079 /*
1080 Now change the alpha of the first pixel so that we can't save palettised
1081 anymore because there will be 256+1 entries which is beyond PNGs limit
1082 of 256 entries.
1083 */
1084 expected8.SetAlpha(0, 0, 1);
1085
1086 CompareImage(*wxImage::FindHandler(wxBITMAP_TYPE_PNG),
1087 expected8, wxIMAGE_HAVE_ALPHA);
1088
1089 /*
1090 Even if we explicitly ask for saving palettised it should not be done.
1091 */
1092 expected8.SetOption(wxIMAGE_OPTION_PNG_FORMAT, wxPNG_TYPE_PALETTE);
1093 CompareImage(*wxImage::FindHandler(wxBITMAP_TYPE_PNG),
1094 expected8, wxIMAGE_HAVE_ALPHA);
1095
1096 }
1097
1098 void ImageTestCase::SaveAnimatedGIF()
1099 {
1100 #if wxUSE_PALETTE
1101 wxImage image("horse.gif");
1102 CPPUNIT_ASSERT( image.IsOk() );
1103
1104 wxImageArray images;
1105 images.Add(image);
1106 int i;
1107 for (i = 0; i < 4-1; ++i)
1108 {
1109 images.Add( images[i].Rotate90() );
1110
1111 images[i+1].SetPalette(images[0].GetPalette());
1112 }
1113
1114 wxMemoryOutputStream memOut;
1115 CPPUNIT_ASSERT( wxGIFHandler().SaveAnimation(images, &memOut) );
1116
1117 wxGIFHandler handler;
1118 wxMemoryInputStream memIn(memOut);
1119 CPPUNIT_ASSERT(memIn.IsOk());
1120 const int imageCount = handler.GetImageCount(memIn);
1121 CPPUNIT_ASSERT_EQUAL(4, imageCount);
1122
1123 for (i = 0; i < imageCount; ++i)
1124 {
1125 wxFileOffset pos = memIn.TellI();
1126 CPPUNIT_ASSERT( handler.LoadFile(&image, memIn, true, i) );
1127 memIn.SeekI(pos);
1128
1129 WX_ASSERT_EQUAL_MESSAGE
1130 (
1131 ("Compare test for GIF frame number %d failed", i),
1132 images[i],
1133 image
1134 );
1135 }
1136 #endif // #if wxUSE_PALETTE
1137 }
1138
1139 void ImageTestCase::ReadCorruptedTGA()
1140 {
1141 static unsigned char corruptTGA[18+1+3] =
1142 {
1143 0,
1144 0,
1145 10, // RLE compressed image.
1146 0, 0,
1147 0, 0,
1148 0,
1149 0, 0,
1150 0, 0,
1151 1, 0, // Width is 1.
1152 1, 0, // Height is 1.
1153 24, // Bits per pixel.
1154 0,
1155
1156 0xff, // Run length (repeat next pixel 127+1 times).
1157 0xff, 0xff, 0xff // One 24-bit pixel.
1158 };
1159
1160 wxMemoryInputStream memIn(corruptTGA, WXSIZEOF(corruptTGA));
1161 CPPUNIT_ASSERT(memIn.IsOk());
1162
1163 wxImage tgaImage;
1164 CPPUNIT_ASSERT( !tgaImage.LoadFile(memIn) );
1165
1166
1167 /*
1168 Instead of repeating a pixel 127+1 times, now tell it there will
1169 follow 127+1 uncompressed pixels (while we only should have 1 in total).
1170 */
1171 corruptTGA[18] = 0x7f;
1172 CPPUNIT_ASSERT( !tgaImage.LoadFile(memIn) );
1173 }
1174
1175 static void TestGIFComment(const wxString& comment)
1176 {
1177 wxImage image("horse.gif");
1178
1179 image.SetOption(wxIMAGE_OPTION_GIF_COMMENT, comment);
1180 wxMemoryOutputStream memOut;
1181 CPPUNIT_ASSERT(image.SaveFile(memOut, wxBITMAP_TYPE_GIF));
1182
1183 wxMemoryInputStream memIn(memOut);
1184 CPPUNIT_ASSERT( image.LoadFile(memIn) );
1185
1186 CPPUNIT_ASSERT_EQUAL(comment,
1187 image.GetOption(wxIMAGE_OPTION_GIF_COMMENT));
1188 }
1189
1190 void ImageTestCase::GIFComment()
1191 {
1192 // Test reading a comment.
1193 wxImage image("horse.gif");
1194 CPPUNIT_ASSERT_EQUAL(" Imported from GRADATION image: gray",
1195 image.GetOption(wxIMAGE_OPTION_GIF_COMMENT));
1196
1197
1198 // Test writing a comment and reading it back.
1199 TestGIFComment("Giving the GIF a gifted giraffe as a gift");
1200
1201
1202 // Test writing and reading a comment again but with a long comment.
1203 TestGIFComment(wxString(wxT('a'), 256)
1204 + wxString(wxT('b'), 256)
1205 + wxString(wxT('c'), 256));
1206
1207
1208 // Test writing comments in an animated GIF and reading them back.
1209 CPPUNIT_ASSERT( image.LoadFile("horse.gif") );
1210
1211 wxImageArray images;
1212 int i;
1213 for (i = 0; i < 4; ++i)
1214 {
1215 if (i)
1216 {
1217 images.Add( images[i-1].Rotate90() );
1218 images[i].SetPalette(images[0].GetPalette());
1219 }
1220 else
1221 {
1222 images.Add(image);
1223 }
1224
1225 images[i].SetOption(wxIMAGE_OPTION_GIF_COMMENT,
1226 wxString::Format("GIF comment for frame #%d", i+1));
1227
1228 }
1229
1230
1231 wxMemoryOutputStream memOut;
1232 CPPUNIT_ASSERT( wxGIFHandler().SaveAnimation(images, &memOut) );
1233
1234 wxGIFHandler handler;
1235 wxMemoryInputStream memIn(memOut);
1236 CPPUNIT_ASSERT(memIn.IsOk());
1237 const int imageCount = handler.GetImageCount(memIn);
1238 for (i = 0; i < imageCount; ++i)
1239 {
1240 wxFileOffset pos = memIn.TellI();
1241 CPPUNIT_ASSERT( handler.LoadFile(&image, memIn, true /*verbose?*/, i) );
1242
1243 CPPUNIT_ASSERT_EQUAL(
1244 wxString::Format("GIF comment for frame #%d", i+1),
1245 image.GetOption(wxIMAGE_OPTION_GIF_COMMENT));
1246 memIn.SeekI(pos);
1247 }
1248 }
1249
1250 void ImageTestCase::DibPadding()
1251 {
1252 /*
1253 There used to be an error with calculating the DWORD aligned scan line
1254 pitch for a BMP/ICO resulting in buffer overwrites (with at least MSVC9
1255 Debug this gave a heap corruption assertion when saving the mask of
1256 an ICO). Test for it here.
1257 */
1258 wxImage image("horse.gif");
1259 CPPUNIT_ASSERT( image.IsOk() );
1260
1261 image = image.Scale(99, 99);
1262
1263 wxMemoryOutputStream memOut;
1264 CPPUNIT_ASSERT( image.SaveFile(memOut, wxBITMAP_TYPE_ICO) );
1265 }
1266
1267 static void CompareBMPImage(const wxString& file1, const wxString& file2)
1268 {
1269 wxImage image1(file1);
1270 CPPUNIT_ASSERT( image1.IsOk() );
1271
1272 wxImage image2(file2);
1273 CPPUNIT_ASSERT( image2.IsOk() );
1274
1275 CompareImage(*wxImage::FindHandler(wxBITMAP_TYPE_BMP), image1, 0, &image2);
1276 }
1277
1278 void ImageTestCase::BMPFlippingAndRLECompression()
1279 {
1280 CompareBMPImage("image/horse_grey.bmp", "image/horse_grey_flipped.bmp");
1281
1282 CompareBMPImage("image/horse_rle8.bmp", "image/horse_grey.bmp");
1283 CompareBMPImage("image/horse_rle8.bmp", "image/horse_rle8_flipped.bmp");
1284
1285 CompareBMPImage("image/horse_rle4.bmp", "image/horse_rle4_flipped.bmp");
1286 }
1287 #endif //wxUSE_IMAGE
1288
1289
1290 /*
1291 TODO: add lots of more tests to wxImage functions
1292 */