3 * Purpose: PNG file reader
4 * Author: Alejandro Aguilar Sierra/Julian Smart
6 * Copyright: (c) 1995, Alejandro Aguilar Sierra <asierra@servidor.unam.mx>
15 typedef unsigned char byte
;
18 #define WXIMA_COLORS DIB_PAL_COLORS
20 typedef byte
* ImagePointerType
;
30 #define COLORTYPE_PALETTE 1
31 #define COLORTYPE_COLOR 2
32 #define COLORTYPE_ALPHA 4
39 ImagePointerType RawImage
; // Image data
41 int Width
, Height
; // Dimensions
42 int Depth
; // (bits x pixel)
43 int ColorType
; // Bit 1 = Palette used
47 long EfeWidth
; // Efective Width
49 BITMAPINFOHEADER2
* lpbi
;
53 friend class wxPNGReaderIter
;
56 wxPNGReader (wxChar
* ImageFileName
); // Read an image file
59 void Create(int width
, int height
, int deep
, int colortype
=-1);
61 bool ReadFile( wxChar
* ImageFileName
=0 );
62 bool SaveFile( wxChar
* ImageFileName
=0 );
63 bool SaveXPM(wxChar
*filename
, wxChar
*name
= 0);
64 int GetWidth( void ) const { return Width
; };
65 int GetHeight( void ) const { return Height
; };
66 int GetDepth( void ) const { return Depth
; };
67 int GetColorType( void ) const { return ColorType
; };
69 int GetIndex(int x
, int y
);
70 bool GetRGB(int x
, int y
, byte
* r
, byte
* g
, byte
* b
);
72 bool SetIndex(int x
, int y
, int index
);
73 bool SetRGB(int x
, int y
, byte r
, byte g
, byte b
);
76 bool SetPalette(wxPalette
* colourmap
);
77 bool SetPalette(int n
, rgb_color_struct
*rgb_struct
);
78 bool SetPalette(int n
, byte
*r
, byte
*g
=0, byte
*b
=0);
79 wxPalette
* GetPalette() const { return Palette
; }
82 inline int GetBGIndex(void) { return bgindex
; }
84 inline bool Inside(int x
, int y
)
85 { return (0<=y
&& y
<Height
&& 0<=x
&& x
<Width
); }
87 virtual wxBitmap
*GetBitmap(void);
88 virtual bool InstantiateBitmap(wxBitmap
*bitmap
);
89 wxMask
*CreateMask(void);
91 inline bool Ok(void) { return imageOK
; }
97 int Itx
, Ity
; // Counters
99 ImagePointerType IterImage
; // Image pointer
103 wxPNGReaderIter ( void );
104 wxPNGReaderIter ( wxPNGReader
*imax
);
105 operator wxPNGReader
* ();
111 void SetRow(byte
*buf
, int n
);
112 void GetRow(byte
*buf
, int n
);
113 byte
GetByte( ) { return IterImage
[Itx
]; }
114 void SetByte(byte b
) { IterImage
[Itx
] = b
; }
115 ImagePointerType
GetRow(void);
121 void SetSteps(int x
, int y
=0) { Stepx
= x
; Stepy
= y
; }
122 void GetSteps(int *x
, int *y
) { *x
= Stepx
; *y
= Stepy
; }
126 ////////////////////////// AD - for interlace ///////////////////////////////
128 /////////////////////////////////////////////////////////////////////////////
133 wxPNGReaderIter::wxPNGReaderIter(void)
142 wxPNGReaderIter::wxPNGReaderIter(wxPNGReader
*imax
): ima(imax
)
145 IterImage
= ima
->RawImage
;
151 wxPNGReaderIter::operator wxPNGReader
* ()
157 bool wxPNGReaderIter::ItOK ()
160 return ima
->Inside(Itx
, Ity
);
166 inline void wxPNGReaderIter::reset()
168 IterImage
= ima
->RawImage
;
172 inline void wxPNGReaderIter::upset()
176 IterImage
= ima
->RawImage
+ ima
->EfeWidth
*(ima
->Height
-1);
179 inline bool wxPNGReaderIter::NextRow()
181 if (++Ity
>= ima
->Height
) return 0;
182 IterImage
+= ima
->EfeWidth
;
186 inline bool wxPNGReaderIter::PrevRow()
188 if (--Ity
< 0) return 0;
189 IterImage
-= ima
->EfeWidth
;
193 ////////////////////////// AD - for interlace ///////////////////////////////
194 inline void wxPNGReaderIter::SetY(int y
)
196 if ((y
< 0) || (y
> ima
->Height
)) return;
198 IterImage
= ima
->RawImage
+ ima
->EfeWidth
*y
;
201 /////////////////////////////////////////////////////////////////////////////
203 inline void wxPNGReaderIter::SetRow(byte
*buf
, int n
)
205 // Here should be bcopy or memcpy
206 //_fmemcpy(IterImage, (void far *)buf, n);
210 for (int i
=0; i
<n
; i
++) IterImage
[i
] = buf
[i
];
213 inline void wxPNGReaderIter::GetRow(byte
*buf
, int n
)
215 for (int i
=0; i
<n
; i
++) buf
[i
] = IterImage
[i
];
218 inline ImagePointerType
wxPNGReaderIter::GetRow()
223 inline bool wxPNGReaderIter::NextByte()
225 if (++Itx
< ima
->EfeWidth
)
228 if (++Ity
< ima
->Height
)
230 IterImage
+= ima
->EfeWidth
;
237 inline bool wxPNGReaderIter::PrevByte()
244 IterImage
-= ima
->EfeWidth
;
251 inline bool wxPNGReaderIter::NextStep()
254 if (Itx
< ima
->EfeWidth
)
258 if (Ity
< ima
->Height
)
260 IterImage
+= ima
->EfeWidth
;
268 inline bool wxPNGReaderIter::PrevStep()
275 if (Ity
>= 0 && Ity
< ima
->Height
)
277 IterImage
-= ima
->EfeWidth
;