2 * File: wx/os2/pngread.h
3 * Purpose: PNG file reader
4 * Author: Alejandro Aguilar Sierra/Julian Smart
7 * Copyright: (c) 1995, Alejandro Aguilar Sierra <asierra@servidor.unam.mx>
16 typedef unsigned char byte
;
19 #define WXIMA_COLORS DIB_PAL_COLORS
21 typedef byte
* ImagePointerType
;
31 #define COLORTYPE_PALETTE 1
32 #define COLORTYPE_COLOR 2
33 #define COLORTYPE_ALPHA 4
40 ImagePointerType RawImage
; // Image data
42 int Width
, Height
; // Dimensions
43 int Depth
; // (bits x pixel)
44 int ColorType
; // Bit 1 = Palette used
48 long EfeWidth
; // Efective Width
50 BITMAPINFOHEADER2
* lpbi
;
54 friend class wxPNGReaderIter
;
57 wxPNGReader (wxChar
* ImageFileName
); // Read an image file
60 void Create(int width
, int height
, int deep
, int colortype
=-1);
62 bool ReadFile( wxChar
* ImageFileName
=0 );
63 bool SaveFile( wxChar
* ImageFileName
=0 );
64 bool SaveXPM(wxChar
*filename
, wxChar
*name
= 0);
65 int GetWidth( void ) const { return Width
; }
66 int GetHeight( void ) const { return Height
; }
67 int GetDepth( void ) const { return Depth
; }
68 int GetColorType( void ) const { return ColorType
; }
70 int GetIndex(int x
, int y
);
71 bool GetRGB(int x
, int y
, byte
* r
, byte
* g
, byte
* b
);
73 bool SetIndex(int x
, int y
, int index
);
74 bool SetRGB(int x
, int y
, byte r
, byte g
, byte b
);
77 bool SetPalette(wxPalette
* colourmap
);
78 bool SetPalette(int n
, rgb_color_struct
*rgb_struct
);
79 bool SetPalette(int n
, byte
*r
, byte
*g
=0, byte
*b
=0);
80 wxPalette
* GetPalette() const { return Palette
; }
83 inline int GetBGIndex(void) { return bgindex
; }
85 inline bool Inside(int x
, int y
)
86 { return (0<=y
&& y
<Height
&& 0<=x
&& x
<Width
); }
88 virtual wxBitmap
*GetBitmap(void);
89 virtual bool InstantiateBitmap(wxBitmap
*bitmap
);
90 wxMask
*CreateMask(void);
92 inline bool Ok() const { return IsOk(); }
93 inline bool IsOk(void) { return imageOK
; }
99 int Itx
, Ity
; // Counters
101 ImagePointerType IterImage
; // Image pointer
105 wxPNGReaderIter ( void );
106 wxPNGReaderIter ( wxPNGReader
*imax
);
107 operator wxPNGReader
* ();
113 void SetRow(byte
*buf
, int n
);
114 void GetRow(byte
*buf
, int n
);
115 byte
GetByte( ) { return IterImage
[Itx
]; }
116 void SetByte(byte b
) { IterImage
[Itx
] = b
; }
117 ImagePointerType
GetRow(void);
123 void SetSteps(int x
, int y
=0) { Stepx
= x
; Stepy
= y
; }
124 void GetSteps(int *x
, int *y
) { *x
= Stepx
; *y
= Stepy
; }
128 ////////////////////////// AD - for interlace ///////////////////////////////
130 /////////////////////////////////////////////////////////////////////////////
135 wxPNGReaderIter::wxPNGReaderIter(void)
144 wxPNGReaderIter::wxPNGReaderIter(wxPNGReader
*imax
): ima(imax
)
147 IterImage
= ima
->RawImage
;
153 wxPNGReaderIter::operator wxPNGReader
* ()
159 bool wxPNGReaderIter::ItOK ()
162 return ima
->Inside(Itx
, Ity
);
168 inline void wxPNGReaderIter::reset()
170 IterImage
= ima
->RawImage
;
174 inline void wxPNGReaderIter::upset()
178 IterImage
= ima
->RawImage
+ ima
->EfeWidth
*(ima
->Height
-1);
181 inline bool wxPNGReaderIter::NextRow()
183 if (++Ity
>= ima
->Height
) return 0;
184 IterImage
+= ima
->EfeWidth
;
188 inline bool wxPNGReaderIter::PrevRow()
190 if (--Ity
< 0) return 0;
191 IterImage
-= ima
->EfeWidth
;
195 ////////////////////////// AD - for interlace ///////////////////////////////
196 inline void wxPNGReaderIter::SetY(int y
)
198 if ((y
< 0) || (y
> ima
->Height
)) return;
200 IterImage
= ima
->RawImage
+ ima
->EfeWidth
*y
;
203 /////////////////////////////////////////////////////////////////////////////
205 inline void wxPNGReaderIter::SetRow(byte
*buf
, int n
)
207 // Here should be bcopy or memcpy
208 //_fmemcpy(IterImage, (void far *)buf, n);
212 for (int i
=0; i
<n
; i
++) IterImage
[i
] = buf
[i
];
215 inline void wxPNGReaderIter::GetRow(byte
*buf
, int n
)
217 for (int i
=0; i
<n
; i
++) buf
[i
] = IterImage
[i
];
220 inline ImagePointerType
wxPNGReaderIter::GetRow()
225 inline bool wxPNGReaderIter::NextByte()
227 if (++Itx
< ima
->EfeWidth
)
230 if (++Ity
< ima
->Height
)
232 IterImage
+= ima
->EfeWidth
;
239 inline bool wxPNGReaderIter::PrevByte()
246 IterImage
-= ima
->EfeWidth
;
253 inline bool wxPNGReaderIter::NextStep()
256 if (Itx
< ima
->EfeWidth
)
260 if (Ity
< ima
->Height
)
262 IterImage
+= ima
->EfeWidth
;
270 inline bool wxPNGReaderIter::PrevStep()
277 if (Ity
>= 0 && Ity
< ima
->Height
)
279 IterImage
-= ima
->EfeWidth
;