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
53 friend class wxPNGReaderIter
;
56 wxPNGReader (char* ImageFileName
); // Read an image file
57 virtual ~wxPNGReader ();
59 void Create(int width
, int height
, int deep
, int colortype
=-1);
61 bool ReadFile( char* ImageFileName
=0 );
62 bool SaveFile( char* ImageFileName
=0 );
63 bool SaveXPM(char *filename
, char *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 m_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() const { return IsOk(); }
92 inline bool IsOk(void) { return imageOK
; }
98 int Itx
, Ity
; // Counters
100 ImagePointerType IterImage
; // Image pointer
104 wxPNGReaderIter ( void );
105 wxPNGReaderIter ( wxPNGReader
*imax
);
106 operator wxPNGReader
* ();
112 void SetRow(byte
*buf
, int n
);
113 void GetRow(byte
*buf
, int n
);
114 byte
GetByte( ) { return IterImage
[Itx
]; }
115 void SetByte(byte b
) { IterImage
[Itx
] = b
; }
116 ImagePointerType
GetRow(void);
122 void SetSteps(int x
, int y
=0) { Stepx
= x
; Stepy
= y
; }
123 void GetSteps(int *x
, int *y
) { *x
= Stepx
; *y
= Stepy
; }
127 ////////////////////////// AD - for interlace ///////////////////////////////
129 /////////////////////////////////////////////////////////////////////////////
134 wxPNGReaderIter::wxPNGReaderIter(void)
143 wxPNGReaderIter::wxPNGReaderIter(wxPNGReader
*imax
): ima(imax
)
146 IterImage
= ima
->RawImage
;
152 wxPNGReaderIter::operator wxPNGReader
* ()
158 bool wxPNGReaderIter::ItOK ()
161 return ima
->Inside(Itx
, Ity
);
167 inline void wxPNGReaderIter::reset()
169 IterImage
= ima
->RawImage
;
173 inline void wxPNGReaderIter::upset()
177 IterImage
= ima
->RawImage
+ ima
->EfeWidth
*(ima
->Height
-1);
180 inline bool wxPNGReaderIter::NextRow()
182 if (++Ity
>= ima
->Height
) return 0;
183 IterImage
+= ima
->EfeWidth
;
187 inline bool wxPNGReaderIter::PrevRow()
189 if (--Ity
< 0) return 0;
190 IterImage
-= ima
->EfeWidth
;
194 ////////////////////////// AD - for interlace ///////////////////////////////
195 inline void wxPNGReaderIter::SetY(int y
)
197 if ((y
< 0) || (y
> ima
->Height
)) return;
199 IterImage
= ima
->RawImage
+ ima
->EfeWidth
*y
;
202 /////////////////////////////////////////////////////////////////////////////
204 inline void wxPNGReaderIter::SetRow(byte
*buf
, int n
)
206 // Here should be bcopy or memcpy
207 //_fmemcpy(IterImage, (void far *)buf, n);
211 for (int i
=0; i
<n
; i
++) IterImage
[i
] = buf
[i
];
214 inline void wxPNGReaderIter::GetRow(byte
*buf
, int n
)
216 for (int i
=0; i
<n
; i
++) buf
[i
] = IterImage
[i
];
219 inline ImagePointerType
wxPNGReaderIter::GetRow()
224 inline bool wxPNGReaderIter::NextByte()
226 if (++Itx
< ima
->EfeWidth
)
229 if (++Ity
< ima
->Height
)
231 IterImage
+= ima
->EfeWidth
;
238 inline bool wxPNGReaderIter::PrevByte()
245 IterImage
-= ima
->EfeWidth
;
252 inline bool wxPNGReaderIter::NextStep()
255 if (Itx
< ima
->EfeWidth
)
259 if (Ity
< ima
->Height
)
261 IterImage
+= ima
->EfeWidth
;
269 inline bool wxPNGReaderIter::PrevStep()
276 if (Ity
>= 0 && Ity
< ima
->Height
)
278 IterImage
-= ima
->EfeWidth
;