]> git.saurik.com Git - wxWidgets.git/blob - src/os2/pngread.cpp
no message
[wxWidgets.git] / src / os2 / pngread.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: pnghand.cpp
3 // Purpose: Implements a PNG reader class + handler
4 // Author: David Webster
5 // Modified by:
6 // Created: 10/10/99
7 // RCS-ID: $Id$
8 // Copyright: (c) David Webster
9 // Licence: wxWindows license
10 /////////////////////////////////////////////////////////////////////////////
11
12 // For compilers that support precompilation, includes "wx.h".
13 #include "wx/wxprec.h"
14
15 #include <stdlib.h>
16 #include <stdio.h>
17 #include <string.h>
18
19 #if wxUSE_IOSTREAMH
20 # include <fstream.h>
21 #else
22 # include <fstream>
23 #endif
24
25 #define INCL_DOS
26 #define INCL_PM
27 #define INCL_GPI
28 #include <os2.h>
29 #include "wx/palette.h"
30 #include "wx/bitmap.h"
31 #include "wx/utils.h"
32 #include "wx/msw/pngread.h"
33 #include "wx/msw/dibutils.h"
34
35 extern "C" {
36 #include "../png/png.h"
37 }
38
39 extern "C" void png_read_init PNGARG((png_structp png_ptr));
40 extern "C" void png_write_init PNGARG((png_structp png_ptr));
41
42 #ifndef GlobalAllocPtr
43 #define GlobalPtrHandle(lp) \
44 ((HGLOBAL)GlobalHandle(lp))
45
46 #define GlobalLockPtr(lp) \
47 ((BOOL)GlobalLock(GlobalPtrHandle(lp)))
48 #define GlobalUnlockPtr(lp) \
49 GlobalUnlock(GlobalPtrHandle(lp))
50
51 #define GlobalAllocPtr(flags, cb) \
52 (GlobalLock(GlobalAlloc((flags), (cb))))
53 #define GlobalReAllocPtr(lp, cbNew, flags) \
54 (GlobalUnlockPtr(lp), GlobalLock(GlobalReAlloc(GlobalPtrHandle(lp) , (cbNew), (flags))))
55 #define GlobalFreePtr(lp) \
56 (GlobalUnlockPtr(lp), (BOOL)GlobalFree(GlobalPtrHandle(lp)))
57 #endif
58
59
60 void
61 ima_png_error(png_struct *png_ptr, char *message)
62 {
63 // wxMessageBox(message, "PNG error");
64
65 longjmp(png_ptr->jmpbuf, 1);
66 }
67
68
69 // static wxGifReaderIter* iter;
70 wxPalette *wxCopyPalette(const wxPalette *cmap);
71
72 wxPNGReader::wxPNGReader()
73 {
74 filetype = 0;
75 RawImage = NULL; // Image data
76
77 Width = 0; Height = 0; // Dimensions
78 Depth = 0; // (bits x pixel)
79 ColorType = 0; // Bit 1 = Palette used
80 // Bit 2 = Color used
81 // Bit 3 = Alpha used
82
83 EfeWidth = 0; // Efective Width
84
85 lpbi = NULL;
86 bgindex = -1;
87 Palette = 0;
88 imageOK = FALSE;
89 }
90
91 wxPNGReader::wxPNGReader ( wxChar* ImageFileName )
92 {
93 imageOK = FALSE;
94 filetype = 0;
95 RawImage = NULL; // Image data
96
97 Width = 0; Height = 0; // Dimensions
98 Depth = 0; // (bits x pixel)
99 ColorType = 0; // Bit 1 = Palette used
100 // Bit 2 = Color used
101 // Bit 3 = Alpha used
102
103 EfeWidth = 0; // Efective Width
104
105 lpbi = NULL;
106 bgindex = -1;
107 Palette = 0;
108
109 imageOK = ReadFile (ImageFileName);
110 }
111
112 void
113 wxPNGReader::Create(int width, int height, int depth, int colortype)
114 {
115 Width = width; Height = height; Depth = depth;
116 ColorType = (colortype>=0) ? colortype: ((Depth>8) ? COLORTYPE_COLOR: 0);
117
118 if (lpbi) {
119 #ifdef __WIN16__
120 GlobalFreePtr((unsigned int) lpbi);
121 #else
122 GlobalFreePtr(lpbi);
123 #endif
124 // delete Palette;
125 }
126 RawImage = 0;
127 Palette = 0;
128 lpbi = wxDibCreate(Depth, Width, Height);
129 if (lpbi) {
130 RawImage = (ImagePointerType)wxDibPtr(lpbi);
131 EfeWidth = (long)(((long)Width*Depth + 31) / 32) * 4;
132 imageOK = TRUE;
133 }
134 }
135
136 wxPNGReader::~wxPNGReader ( )
137 {
138 if (lpbi) {
139 #ifdef __WIN16__
140 GlobalFreePtr((unsigned int) lpbi);
141 #else
142 GlobalFreePtr(lpbi);
143 #endif
144 delete Palette;
145 }
146 }
147
148
149 int wxPNGReader::GetIndex(int x, int y)
150 {
151 if (!Inside(x, y) || (Depth>8)) return -1;
152
153 ImagePointerType ImagePointer = RawImage + EfeWidth*y + (x*Depth >> 3);
154 int index = (int)(*ImagePointer);
155 return index;
156 }
157
158 bool wxPNGReader::GetRGB(int x, int y, byte* r, byte* g, byte* b)
159 {
160 if (!Inside(x, y)) return FALSE;
161
162 if (Palette) {
163 return Palette->GetRGB(GetIndex(x, y), r, g, b);
164 /* PALETTEENTRY entry;
165 ::GetPaletteEntries((HPALETTE) Palette->GetHPALETTE(), GetIndex(x, y), 1, &entry);
166 *r = entry.peRed;
167 *g = entry.peGreen;
168 *b = entry.peBlue; */
169 } else {
170 ImagePointerType ImagePointer = RawImage + EfeWidth*y + (x*Depth >> 3);
171 *b = ImagePointer[0];
172 *g = ImagePointer[1];
173 *r = ImagePointer[2];
174 }
175 return TRUE;
176 }
177
178
179 bool wxPNGReader::SetIndex(int x, int y, int index)
180 {
181 if (!Inside(x, y) || (Depth>8)) return FALSE;
182
183 ImagePointerType ImagePointer = RawImage + EfeWidth*y + (x*Depth >> 3);
184 *ImagePointer = index;
185
186 return TRUE;
187 }
188
189 bool wxPNGReader::SetRGB(int x, int y, byte r, byte g, byte b)
190 {
191 if (!Inside(x, y)) return FALSE;
192
193 if (ColorType & COLORTYPE_PALETTE)
194 {
195 if (!Palette) return FALSE;
196 SetIndex(x, y, Palette->GetPixel(r, g, b));
197
198 } else {
199 ImagePointerType ImagePointer = RawImage + EfeWidth*y + (x*Depth >> 3);
200 ImagePointer[0] = b;
201 ImagePointer[1] = g;
202 ImagePointer[2] = r;
203 }
204
205 return TRUE;
206 }
207
208 bool wxPNGReader::SetPalette(wxPalette* colourmap)
209 {
210 if (!colourmap)
211 return FALSE;
212 ColorType |= (COLORTYPE_PALETTE | COLORTYPE_COLOR);
213 Palette = colourmap;
214 return (wxDibSetUsage(lpbi, (HPALETTE) Palette->GetHPALETTE(), WXIMA_COLORS ) != 0);
215 }
216
217 bool
218 wxPNGReader::SetPalette(int n, byte *r, byte *g, byte *b)
219 {
220 Palette = new wxPalette();
221 if (!Palette)
222 return FALSE;
223
224 if (!g) g = r;
225 if (!b) b = g;
226 Palette->Create(n, r, g, b);
227 ColorType |= (COLORTYPE_PALETTE | COLORTYPE_COLOR);
228 return (wxDibSetUsage(lpbi, (HPALETTE) Palette->GetHPALETTE(), WXIMA_COLORS ) != 0);
229 }
230
231 bool
232 wxPNGReader::SetPalette(int n, rgb_color_struct *rgb_struct)
233 {
234 Palette = new wxPalette();
235 if (!Palette)
236 return FALSE;
237
238 byte r[256], g[256], b[256];
239
240 for(int i=0; i<n; i++)
241 {
242 r[i] = rgb_struct[i].red;
243 g[i] = rgb_struct[i].green;
244 b[i] = rgb_struct[i].blue;
245 }
246 // Added by JACS copying from Andrew Davison's additions
247 // to GIF-reading code
248 // Make transparency colour black...
249 if (bgindex != -1)
250 r[bgindex] = g[bgindex] = b[bgindex] = 0;
251
252 Palette->Create(n, r, g, b);
253 ColorType |= (COLORTYPE_PALETTE | COLORTYPE_COLOR);
254 return (wxDibSetUsage(lpbi, (HPALETTE) Palette->GetHPALETTE(), WXIMA_COLORS ) != 0);
255 }
256
257 void wxPNGReader::NullData()
258 {
259 lpbi = NULL;
260 Palette = NULL;
261 }
262
263 wxBitmap* wxPNGReader::GetBitmap()
264 {
265 wxBitmap *bitmap = new wxBitmap;
266 if ( InstantiateBitmap(bitmap) )
267 return bitmap;
268 else
269 {
270 delete bitmap;
271 return NULL;
272 }
273 }
274
275 bool wxPNGReader::InstantiateBitmap(wxBitmap *bitmap)
276 {
277 HDC dc = ::CreateCompatibleDC(NULL);
278
279 if (dc)
280 {
281 // tmpBitmap is a dummy, to satisfy ::CreateCompatibleDC (it
282 // is a memory dc that must have a bitmap selected into it)
283 HDC dc2 = GetDC(NULL);
284 HBITMAP tmpBitmap = ::CreateCompatibleBitmap(dc2, GetWidth(), GetHeight());
285 ReleaseDC(NULL, dc2);
286 HBITMAP oldBitmap = (HBITMAP) ::SelectObject(dc, tmpBitmap);
287
288 if ( Palette )
289 {
290 ::SelectPalette(dc, (HPALETTE) Palette->GetHPALETTE(), FALSE);
291 ::RealizePalette(dc);
292 }
293
294 HBITMAP hBitmap = ::CreateDIBitmap(dc, lpbi,
295 CBM_INIT, RawImage, (LPBITMAPINFO) lpbi, DIB_PAL_COLORS);
296
297 ::SelectPalette(dc, NULL, TRUE);
298 ::SelectObject(dc, oldBitmap);
299 ::DeleteObject(tmpBitmap);
300 ::DeleteDC(dc);
301
302 if ( hBitmap )
303 {
304 bitmap->SetHBITMAP((WXHBITMAP) hBitmap);
305 bitmap->SetWidth(GetWidth());
306 bitmap->SetHeight(GetHeight());
307 bitmap->SetDepth(GetDepth());
308 if ( GetDepth() > 1 && Palette )
309 bitmap->SetPalette(*Palette);
310 bitmap->SetOk(TRUE);
311
312
313 // Make a mask if appropriate
314 if ( bgindex > -1 )
315 {
316 wxMask *mask = CreateMask();
317 bitmap->SetMask(mask);
318 }
319 return TRUE;
320 }
321 else
322 {
323 return FALSE;
324 }
325 }
326 else
327 {
328 return FALSE;
329 }
330 }
331
332 wxPalette *wxCopyPalette(const wxPalette *cmap)
333 {
334 // To get number of entries...
335 WORD count = 0;
336 ::GetObject((HPALETTE) cmap->GetHPALETTE(), sizeof(WORD), &count);
337
338 LOGPALETTE* logPal = (LOGPALETTE*)
339 new BYTE[sizeof(LOGPALETTE) + count*sizeof(PALETTEENTRY)];
340 logPal->palVersion = 0x300;
341 logPal->palNumEntries = count;
342 ::GetPaletteEntries((HPALETTE) cmap->GetHPALETTE(), 0, count, logPal->palPalEntry);
343
344 HPALETTE hPalette = ::CreatePalette(logPal);
345 delete[] logPal;
346
347 wxPalette *newCmap = new wxPalette;
348 newCmap->SetHPALETTE((WXHPALETTE) hPalette);
349 return newCmap;
350 }
351
352 wxMask *wxPNGReader::CreateMask()
353 {
354 HBITMAP hBitmap = ::CreateBitmap(GetWidth(), GetHeight(), 1, 1, NULL);
355
356 HDC dc = ::CreateCompatibleDC(NULL);
357 HBITMAP oldBitmap = (HBITMAP) ::SelectObject(dc, hBitmap);
358
359 int bgIndex = GetBGIndex();
360
361 int x,y;
362
363 for (x=0; x<GetWidth(); x++)
364 {
365 for (y=0; y<GetHeight(); y++)
366 {
367 int index = GetIndex(x, y);
368 if ( index == bgIndex )
369 ::SetPixel(dc, x, GetHeight() - y - 1, RGB(0, 0, 0));
370 else
371 ::SetPixel(dc, x, GetHeight() - y - 1, RGB(255, 255, 255));
372
373 }
374 }
375 ::SelectObject(dc, oldBitmap);
376 wxMask *mask = new wxMask;
377 mask->SetMaskBitmap((WXHBITMAP) hBitmap);
378 return mask;
379 }
380
381 bool wxPNGReader::ReadFile(wxChar * ImageFileName)
382 {
383 if (ImageFileName)
384 wxStrcpy(filename, ImageFileName);
385
386 /* open the file */
387 FILE *fp = fopen(wxConvFile.cWX2MB(filename), "rb");
388 if (!fp)
389 return FALSE;
390
391 /* allocate the necessary structures */
392 png_struct *png_ptr = new (png_struct);
393 if (!png_ptr)
394 {
395 fclose(fp);
396 return FALSE;
397 }
398
399 png_info *info_ptr = new (png_info);
400 if (!info_ptr)
401 {
402 fclose(fp);
403 delete(png_ptr);
404 return FALSE;
405 }
406
407 /* set error handling */
408 if (setjmp(png_ptr->jmpbuf))
409 {
410 png_read_destroy(png_ptr, info_ptr, (png_info *)0);
411 fclose(fp);
412 delete(png_ptr);
413 delete(info_ptr);
414
415 /* If we get here, we had a problem reading the file */
416 return FALSE;
417 }
418 //png_set_error(ima_png_error, NULL);
419
420 /* initialize the structures, info first for error handling */
421 png_info_init(info_ptr);
422 png_read_init(png_ptr);
423
424 /* set up the input control */
425 png_init_io(png_ptr, fp);
426
427 /* read the file information */
428 png_read_info(png_ptr, info_ptr);
429
430 /* allocate the memory to hold the image using the fields
431 of png_info. */
432 png_color_16 my_background={ 0, 31, 127, 255, 0 };
433
434 if (info_ptr->valid & PNG_INFO_bKGD)
435 {
436 png_set_background(png_ptr, &(info_ptr->background),
437 PNG_BACKGROUND_GAMMA_FILE, 1, 1.0);
438 if ( info_ptr->num_palette > 0 )
439 bgindex = info_ptr->background.index;
440 }
441 else {
442 png_set_background(png_ptr, &my_background,
443 PNG_BACKGROUND_GAMMA_SCREEN, 0, 1.0);
444
445 // Added by JACS: guesswork!
446 if ( info_ptr->num_trans != 0 )
447 bgindex = info_ptr->num_trans - 1 ;
448 }
449
450 /* tell libpng to strip 16 bit depth files down to 8 bits */
451 if (info_ptr->bit_depth == 16)
452 png_set_strip_16(png_ptr);
453
454 int pixel_depth=(info_ptr->pixel_depth<24) ? info_ptr->pixel_depth: 24;
455 Create(info_ptr->width, info_ptr->height, pixel_depth,
456 info_ptr->color_type);
457
458 if (info_ptr->num_palette>0)
459 {
460 SetPalette((int)info_ptr->num_palette, (rgb_color_struct*)info_ptr->palette);
461 }
462
463 int row_stride = info_ptr->width * ((pixel_depth+7)>>3);
464 // printf("P = %d D = %d RS= %d ", info_ptr->num_palette, info_ptr->pixel_depth,row_stride);
465 // printf("CT = %d TRS = %d BD= %d ", info_ptr->color_type, info_ptr->valid & PNG_INFO_tRNS,info_ptr->bit_depth);
466
467 byte *row_pointers = new byte[row_stride];
468
469 /* turn on interlace handling */
470 int number_passes;
471 if (info_ptr->interlace_type)
472 number_passes = png_set_interlace_handling(png_ptr);
473 else
474 number_passes = 1;
475 // printf("NP = %d ", number_passes);
476
477 // don't use the object to prevent warnings from VC++ about "unportable
478 // interaction between setjmp and C++ object destruction" (this is a correct
479 // warning, of course!)
480 wxPNGReaderIter *iter = new wxPNGReaderIter(this);
481 for (int pass=0; pass< number_passes; pass++)
482 {
483 iter->upset();
484 int y=0;
485 do {
486 //(unsigned char *)iter.GetRow();
487 if (info_ptr->interlace_type) {
488 if (pass>0)
489 iter->GetRow(row_pointers, row_stride);
490 png_read_row(png_ptr, row_pointers, NULL);
491 }
492 else
493 png_read_row(png_ptr, row_pointers, NULL);
494
495 iter->SetRow(row_pointers, row_stride);
496 y++;
497 } while(iter->PrevRow());
498 // printf("Y=%d ",y);
499 }
500
501 delete iter;
502 delete[] row_pointers;
503
504 /* read the rest of the file, getting any additional chunks
505 in info_ptr */
506 png_read_end(png_ptr, info_ptr);
507
508 /* clean up after the read, and free any memory allocated */
509 png_read_destroy(png_ptr, info_ptr, (png_info *)0);
510
511 /* free the structures */
512 delete(png_ptr);
513 delete(info_ptr);
514
515 /* close the file */
516 fclose(fp);
517
518 /* that's it */
519 return TRUE;
520 }
521
522
523 /* write a png file */
524
525 bool wxPNGReader::SaveFile(wxChar * ImageFileName)
526 {
527 if (ImageFileName)
528 wxStrcpy(filename, ImageFileName);
529
530 wxPNGReaderIter iter(this);
531 FILE *fp;
532 png_struct *png_ptr;
533 png_info *info_ptr;
534
535 /* open the file */
536 fp = fopen(wxConvFile.cWX2MB(filename), "wb");
537 if (!fp)
538 return FALSE;
539
540 /* allocate the necessary structures */
541 png_ptr = new (png_struct);
542 if (!png_ptr)
543 {
544 fclose(fp);
545 return FALSE;
546 }
547
548 info_ptr = new (png_info);
549 if (!info_ptr)
550 {
551 fclose(fp);
552 delete(png_ptr);
553 return FALSE;
554 }
555
556 /* set error handling */
557 if (setjmp(png_ptr->jmpbuf))
558 {
559 png_write_destroy(png_ptr);
560 fclose(fp);
561 delete(png_ptr);
562 delete(info_ptr);
563
564 /* If we get here, we had a problem reading the file */
565 return FALSE;
566 }
567 //png_set_error(ima_png_error, NULL);
568
569 // printf("writig pg %s ", filename);
570 /* initialize the structures */
571 png_info_init(info_ptr);
572 png_write_init(png_ptr);
573
574 int row_stride = GetWidth() * ((GetDepth()+7)>>3);
575 /* set up the output control */
576 png_init_io(png_ptr, fp);
577
578 /* set the file information here */
579 info_ptr->width = GetWidth();
580 info_ptr->height = GetHeight();
581 info_ptr->pixel_depth = GetDepth();
582 info_ptr->channels = (GetDepth()>8) ? 3: 1;
583 info_ptr->bit_depth = GetDepth()/info_ptr->channels;
584 info_ptr->color_type = GetColorType();
585 info_ptr->compression_type = info_ptr->filter_type = info_ptr->interlace_type=0;
586 info_ptr->valid = 0;
587 info_ptr->rowbytes = row_stride;
588
589
590 // printf("P = %d D = %d RS= %d GD= %d CH= %d ", info_ptr->pixel_depth, info_ptr->bit_depth, row_stride, GetDepth(), info_ptr->channels);
591 /* set the palette if there is one */
592 if ((GetColorType() & COLORTYPE_PALETTE) && GetPalette())
593 {
594 // printf("writing paleta[%d %d %x]",GetColorType() ,COLORTYPE_PALETTE, GetPalette());
595 info_ptr->valid |= PNG_INFO_PLTE;
596 info_ptr->palette = new png_color[256];
597 info_ptr->num_palette = 256;
598 for (int i=0; i<256; i++)
599 GetPalette()->GetRGB(i, &info_ptr->palette[i].red, &info_ptr->palette[i].green, &info_ptr->palette[i].blue);
600 }
601 // printf("Paleta [%d %d %x]",GetColorType() ,COLORTYPE_PALETTE, GetPalette());
602
603
604 /* optional significant bit chunk */
605 // info_ptr->valid |= PNG_INFO_sBIT;
606 // info_ptr->sig_bit = true_bit_depth;
607
608 /* optional gamma chunk */
609 // info_ptr->valid |= PNG_INFO_gAMA;
610 // info_ptr->gamma = gamma;
611
612 /* other optional chunks */
613
614 /* write the file information */
615 png_write_info(png_ptr, info_ptr);
616
617 /* set up the transformations you want. Note that these are
618 all optional. Only call them if you want them */
619
620 /* shift the pixels up to a legal bit depth and fill in
621 as appropriate to correctly scale the image */
622 // png_set_shift(png_ptr, &(info_ptr->sig_bit));
623
624 /* pack pixels into bytes */
625 // png_set_packing(png_ptr);
626
627 /* flip bgr pixels to rgb */
628 // png_set_bgr(png_ptr);
629
630 /* swap bytes of 16 bit files to most significant bit first */
631 // png_set_swap(png_ptr);
632
633 /* get rid of filler bytes, pack rgb into 3 bytes */
634 // png_set_rgbx(png_ptr);
635
636 /* If you are only writing one row at a time, this works */
637
638 byte *row_pointers = new byte[row_stride];
639 iter.upset();
640 do {
641 // (unsigned char *)iter.GetRow();
642 iter.GetRow(row_pointers, row_stride);
643 png_write_row(png_ptr, row_pointers);
644 } while(iter.PrevRow());
645
646 delete[] row_pointers;
647
648 /* write the rest of the file */
649 png_write_end(png_ptr, info_ptr);
650
651 /* clean up after the write, and free any memory allocated */
652 png_write_destroy(png_ptr);
653
654 /* if you malloced the palette, free it here */
655 if (info_ptr->palette)
656 delete[] (info_ptr->palette);
657
658 /* free the structures */
659 delete(png_ptr);
660 delete(info_ptr);
661
662 /* close the file */
663 fclose(fp);
664
665 /* that's it */
666 return TRUE;
667 }
668
669 static int Power(int x, int y)
670 {
671 int z = 1;
672 int i;
673 for ( i = 0; i < y; i++)
674 {
675 z *= x;
676 }
677 return z;
678 }
679
680 static char hexArray[] = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B',
681 'C', 'D', 'E', 'F' };
682
683 static void DecToHex(int dec, char *buf)
684 {
685 int firstDigit = (int)(dec/16.0);
686 int secondDigit = (int)(dec - (firstDigit*16.0));
687 buf[0] = hexArray[firstDigit];
688 buf[1] = hexArray[secondDigit];
689 buf[2] = 0;
690 }
691
692
693 bool wxPNGReader::SaveXPM(wxChar *filename, wxChar *name)
694 {
695 wxChar nameStr[256];
696 if ( name )
697 wxStrcpy(nameStr, name);
698 else
699 {
700 wxStrcpy(nameStr, filename);
701 wxStripExtension(nameStr);
702 }
703
704 if ( GetDepth() > 4 )
705 {
706 // Only a depth of 4 and below allowed
707 return FALSE;
708 }
709
710 if ( !GetPalette() )
711 return FALSE;
712
713 ofstream str(wxConvFile.cWX2MB(filename));
714 if ( str.bad() )
715 return FALSE;
716
717 int noColours = Power(2, GetDepth());
718
719 // Output header
720 str << "/* XPM */\n";
721 str << "static char * " << nameStr << "_xpm[] = {\n";
722 str << "\"" << GetWidth() << " " << GetHeight() << " " << noColours << " 1\",\n";
723
724 // Output colourmap
725 int base = 97 ; // start from 'a'
726
727 unsigned char red, green, blue;
728 char hexBuf[4];
729 int i;
730 for ( i = 0; i < noColours; i ++)
731 {
732 str << "\"" << (char)(base + i) << " c #";
733 GetPalette()->GetRGB(i, &red, &green, &blue);
734 DecToHex(red, hexBuf);
735 str << hexBuf;
736 DecToHex(green, hexBuf);
737 str << hexBuf;
738 DecToHex(blue, hexBuf);
739 str << hexBuf;
740 str << "\",\n";
741 }
742
743 // Output the data
744 int x, y;
745 for ( y = 0; y < GetHeight(); y++)
746 {
747 str << "\"";
748 for ( x = 0; x < GetWidth(); x++)
749 {
750 int index = GetIndex(x, y);
751 str << (char)(base + index) ;
752 }
753 str << "\",\n";
754 }
755
756 str << "};\n";
757 str.flush();
758
759 return TRUE;
760 }
761
762 #include <wx/os2/pnghand.h>
763
764 IMPLEMENT_DYNAMIC_CLASS(wxPNGFileHandler, wxBitmapHandler)
765
766 bool wxPNGFileHandler::LoadFile(wxBitmap *bitmap, const wxString& name, long flags,
767 int desiredWidth, int desiredHeight)
768 {
769 wxPNGReader reader;
770 if (reader.ReadFile(WXSTRINGCAST name))
771 {
772 return reader.InstantiateBitmap(bitmap);
773 }
774 else
775 return FALSE;
776 }
777
778 bool wxPNGFileHandler::SaveFile(wxBitmap *bitmap, const wxString& name, int type, const wxPalette *pal)
779 {
780 return FALSE;
781 }
782
783