]> git.saurik.com Git - wxWidgets.git/blame - include/wx/mac/carbon/pngread.h
added RequestUserAttention
[wxWidgets.git] / include / wx / mac / carbon / pngread.h
CommitLineData
8cf73271
SC
1/*
2 * File: pngread.h
3 * Purpose: PNG file reader
4 * Author: Alejandro Aguilar Sierra/Julian Smart
5 * Created: 1995
6 * Copyright: (c) 1995, Alejandro Aguilar Sierra <asierra@servidor.unam.mx>
7 *
8 *
9 */
10
11#ifndef _WX_PNGREAD__
12#define _WX_PNGREAD__
13
14#if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
15#pragma interface "pngread.h"
16#endif
17
18#ifndef byte
19typedef unsigned char byte;
20#endif
21
22#define WXIMA_COLORS DIB_PAL_COLORS
23
24typedef byte * ImagePointerType;
25
26typedef struct
27{
28 byte red;
29 byte green;
30 byte blue;
31} rgb_color_struct;
32
33
34#define COLORTYPE_PALETTE 1
35#define COLORTYPE_COLOR 2
36#define COLORTYPE_ALPHA 4
37
38class wxPNGReader
39{
40protected:
41 int filetype;
42 char filename[255];
43 ImagePointerType RawImage; // Image data
44
45 int Width, Height; // Dimensions
46 int Depth; // (bits x pixel)
47 int ColorType; // Bit 1 = Palette used
48 // Bit 2 = Color used
49 // Bit 3 = Alpha used
50
51 long EfeWidth; // Efective Width
52
53 void *lpbi;
54 int bgindex;
55 wxPalette* m_palette;
56 bool imageOK;
57friend class wxPNGReaderIter;
58public:
59 wxPNGReader(void);
60 wxPNGReader (char* ImageFileName); // Read an image file
61 virtual ~wxPNGReader ();
62
63 void Create(int width, int height, int deep, int colortype=-1);
64
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; };
72
73 int GetIndex(int x, int y);
74 bool GetRGB(int x, int y, byte* r, byte* g, byte* b);
75
76 bool SetIndex(int x, int y, int index);
77 bool SetRGB(int x, int y, byte r, byte g, byte b);
78
79 // ColorMap settings
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 m_palette; }
84
85 void NullData();
86 inline int GetBGIndex(void) { return bgindex; }
87
88 inline bool Inside(int x, int y)
89 { return (0<=y && y<Height && 0<=x && x<Width); }
90
91 virtual wxBitmap *GetBitmap(void);
92 virtual bool InstantiateBitmap(wxBitmap *bitmap);
93 wxMask *CreateMask(void);
94
95 inline bool Ok(void) { return imageOK; }
96};
97
98class wxPNGReaderIter
99{
100protected:
101 int Itx, Ity; // Counters
102 int Stepx, Stepy;
103 ImagePointerType IterImage; // Image pointer
104 wxPNGReader *ima;
105public:
106// Constructors
107 wxPNGReaderIter ( void );
108 wxPNGReaderIter ( wxPNGReader *imax );
109 operator wxPNGReader* ();
110
111// Iterators
112 bool ItOK ();
113 void reset ();
114 void upset ();
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);
120 bool NextRow();
121 bool PrevRow();
122 bool NextByte();
123 bool PrevByte();
124
125 void SetSteps(int x, int y=0) { Stepx = x; Stepy = y; }
126 void GetSteps(int *x, int *y) { *x = Stepx; *y = Stepy; }
127 bool NextStep();
128 bool PrevStep();
129
130////////////////////////// AD - for interlace ///////////////////////////////
131 void SetY(int y);
132/////////////////////////////////////////////////////////////////////////////
133};
134
135
136inline
137wxPNGReaderIter::wxPNGReaderIter(void)
138{
139 ima = 0;
140 IterImage = 0;
141 Itx = Ity = 0;
142 Stepx = Stepy = 0;
143}
144
145inline
146wxPNGReaderIter::wxPNGReaderIter(wxPNGReader *imax): ima(imax)
147{
148 if (ima)
149 IterImage = ima->RawImage;
150 Itx = Ity = 0;
151 Stepx = Stepy = 0;
152}
153
154inline
155wxPNGReaderIter::operator wxPNGReader* ()
156{
157 return ima;
158}
159
160inline
161bool wxPNGReaderIter::ItOK ()
162{
163 if (ima)
164 return ima->Inside(Itx, Ity);
165 else
166 return FALSE;
167}
168
169
170inline void wxPNGReaderIter::reset()
171{
172 IterImage = ima->RawImage;
173 Itx = Ity = 0;
174}
175
176inline void wxPNGReaderIter::upset()
177{
178 Itx = 0;
179 Ity = ima->Height-1;
180 IterImage = ima->RawImage + ima->EfeWidth*(ima->Height-1);
181}
182
183inline bool wxPNGReaderIter::NextRow()
184{
185 if (++Ity >= ima->Height) return 0;
186 IterImage += ima->EfeWidth;
187 return 1;
188}
189
190inline bool wxPNGReaderIter::PrevRow()
191{
192 if (--Ity < 0) return 0;
193 IterImage -= ima->EfeWidth;
194 return 1;
195}
196
197////////////////////////// AD - for interlace ///////////////////////////////
198inline void wxPNGReaderIter::SetY(int y)
199{
200 if ((y < 0) || (y > ima->Height)) return;
201 Ity = y;
202 IterImage = ima->RawImage + ima->EfeWidth*y;
203}
204
205/////////////////////////////////////////////////////////////////////////////
206
207inline void wxPNGReaderIter::SetRow(byte *buf, int n)
208{
209// Here should be bcopy or memcpy
210 //_fmemcpy(IterImage, (void far *)buf, n);
211 if (n<0)
212 n = ima->GetWidth();
213
214 for (int i=0; i<n; i++) IterImage[i] = buf[i];
215}
216
217inline void wxPNGReaderIter::GetRow(byte *buf, int n)
218{
219 for (int i=0; i<n; i++) buf[i] = IterImage[i];
220}
221
222inline ImagePointerType wxPNGReaderIter::GetRow()
223{
224 return IterImage;
225}
226
227inline bool wxPNGReaderIter::NextByte()
228{
229 if (++Itx < ima->EfeWidth)
230 return 1;
231 else
232 if (++Ity < ima->Height)
233 {
234 IterImage += ima->EfeWidth;
235 Itx = 0;
236 return 1;
237 } else
238 return 0;
239}
240
241inline bool wxPNGReaderIter::PrevByte()
242{
243 if (--Itx >= 0)
244 return 1;
245 else
246 if (--Ity >= 0)
247 {
248 IterImage -= ima->EfeWidth;
249 Itx = 0;
250 return 1;
251 } else
252 return 0;
253}
254
255inline bool wxPNGReaderIter::NextStep()
256{
257 Itx += Stepx;
258 if (Itx < ima->EfeWidth)
259 return 1;
260 else {
261 Ity += Stepy;
262 if (Ity < ima->Height)
263 {
264 IterImage += ima->EfeWidth;
265 Itx = 0;
266 return 1;
267 } else
268 return 0;
269 }
270}
271
272inline bool wxPNGReaderIter::PrevStep()
273{
274 Itx -= Stepx;
275 if (Itx >= 0)
276 return 1;
277 else {
278 Ity -= Stepy;
279 if (Ity >= 0 && Ity < ima->Height)
280 {
281 IterImage -= ima->EfeWidth;
282 Itx = 0;
283 return 1;
284 } else
285 return 0;
286 }
287}
288
289#endif
290