3 * Purpose: PNG file reader
4 * Author: Alejandro Aguilar Sierra/Julian Smart
6 * Copyright: (c) 1995, Alejandro Aguilar Sierra <asierra@servidor.unam.mx>
15 #pragma interface "pngread.h"
19 typedef unsigned char byte
;
22 #define WXIMA_COLORS DIB_PAL_COLORS
24 typedef byte
* ImagePointerType
;
34 #define COLORTYPE_PALETTE 1
35 #define COLORTYPE_COLOR 2
36 #define COLORTYPE_ALPHA 4
43 ImagePointerType RawImage
; // Image data
45 int Width
, Height
; // Dimensions
46 int Depth
; // (bits x pixel)
47 int ColorType
; // Bit 1 = Palette used
51 long EfeWidth
; // Efective Width
57 friend class wxPNGReaderIter
;
60 wxPNGReader (char* ImageFileName
); // Read an image file
61 virtual ~wxPNGReader ();
63 void Create(int width
, int height
, int deep
, int colortype
=-1);
65 bool ReadFile( char* ImageFileName
=0 );
66 bool SaveFile( char* ImageFileName
=0 );
67 bool SaveXPM(char *filename
, char *name
= 0);
68 int GetWidth( void ) const { return Width
; };
69 int GetHeight( void ) const { return Height
; };
70 int GetDepth( void ) const { return Depth
; };
71 int GetColorType( void ) const { return ColorType
; };
73 int GetIndex(int x
, int y
);
74 bool GetRGB(int x
, int y
, byte
* r
, byte
* g
, byte
* b
);
76 bool SetIndex(int x
, int y
, int index
);
77 bool SetRGB(int x
, int y
, byte r
, byte g
, byte b
);
80 bool SetPalette(wxPalette
* colourmap
);
81 bool SetPalette(int n
, rgb_color_struct
*rgb_struct
);
82 bool SetPalette(int n
, byte
*r
, byte
*g
=0, byte
*b
=0);
83 wxPalette
* GetPalette() const { return Palette
; }
86 inline int GetBGIndex(void) { return bgindex
; }
88 inline bool Inside(int x
, int y
)
89 { return (0<=y
&& y
<Height
&& 0<=x
&& x
<Width
); }
91 virtual wxBitmap
*GetBitmap(void);
92 virtual bool InstantiateBitmap(wxBitmap
*bitmap
);
93 wxMask
*CreateMask(void);
95 inline bool Ok(void) { return imageOK
; }
101 int Itx
, Ity
; // Counters
103 ImagePointerType IterImage
; // Image pointer
107 wxPNGReaderIter ( void );
108 wxPNGReaderIter ( wxPNGReader
*imax
);
109 operator wxPNGReader
* ();
115 void SetRow(byte
*buf
, int n
);
116 void GetRow(byte
*buf
, int n
);
117 byte
GetByte( ) { return IterImage
[Itx
]; }
118 void SetByte(byte b
) { IterImage
[Itx
] = b
; }
119 ImagePointerType
GetRow(void);
125 void SetSteps(int x
, int y
=0) { Stepx
= x
; Stepy
= y
; }
126 void GetSteps(int *x
, int *y
) { *x
= Stepx
; *y
= Stepy
; }
130 ////////////////////////// AD - for interlace ///////////////////////////////
132 /////////////////////////////////////////////////////////////////////////////
137 wxPNGReaderIter::wxPNGReaderIter(void)
146 wxPNGReaderIter::wxPNGReaderIter(wxPNGReader
*imax
): ima(imax
)
149 IterImage
= ima
->RawImage
;
155 wxPNGReaderIter::operator wxPNGReader
* ()
161 bool wxPNGReaderIter::ItOK ()
164 return ima
->Inside(Itx
, Ity
);
170 inline void wxPNGReaderIter::reset()
172 IterImage
= ima
->RawImage
;
176 inline void wxPNGReaderIter::upset()
180 IterImage
= ima
->RawImage
+ ima
->EfeWidth
*(ima
->Height
-1);
183 inline bool wxPNGReaderIter::NextRow()
185 if (++Ity
>= ima
->Height
) return 0;
186 IterImage
+= ima
->EfeWidth
;
190 inline bool wxPNGReaderIter::PrevRow()
192 if (--Ity
< 0) return 0;
193 IterImage
-= ima
->EfeWidth
;
197 ////////////////////////// AD - for interlace ///////////////////////////////
198 inline void wxPNGReaderIter::SetY(int y
)
200 if ((y
< 0) || (y
> ima
->Height
)) return;
202 IterImage
= ima
->RawImage
+ ima
->EfeWidth
*y
;
205 /////////////////////////////////////////////////////////////////////////////
207 inline void wxPNGReaderIter::SetRow(byte
*buf
, int n
)
209 // Here should be bcopy or memcpy
210 //_fmemcpy(IterImage, (void far *)buf, n);
214 for (int i
=0; i
<n
; i
++) IterImage
[i
] = buf
[i
];
217 inline void wxPNGReaderIter::GetRow(byte
*buf
, int n
)
219 for (int i
=0; i
<n
; i
++) buf
[i
] = IterImage
[i
];
222 inline ImagePointerType
wxPNGReaderIter::GetRow()
227 inline bool wxPNGReaderIter::NextByte()
229 if (++Itx
< ima
->EfeWidth
)
232 if (++Ity
< ima
->Height
)
234 IterImage
+= ima
->EfeWidth
;
241 inline bool wxPNGReaderIter::PrevByte()
248 IterImage
-= ima
->EfeWidth
;
255 inline bool wxPNGReaderIter::NextStep()
258 if (Itx
< ima
->EfeWidth
)
262 if (Ity
< ima
->Height
)
264 IterImage
+= ima
->EfeWidth
;
272 inline bool wxPNGReaderIter::PrevStep()
279 if (Ity
>= 0 && Ity
< ima
->Height
)
281 IterImage
-= ima
->EfeWidth
;