3 * Purpose: Declaration of the Platform Independent Image Base Class
4 * Author: Alejandro Aguilar Sierra
6 * Copyright: (c) 1995, Alejandro Aguilar Sierra <asierra(at)servidor(dot)unam(dot)mx>
8 * 07/08/2001 Davide Pizzolato - www.xdp.it
12 * Permission is given by the author to freely redistribute and include
13 * this code in any program as long as this credit is given where due.
15 * COVERED CODE IS PROVIDED UNDER THIS LICENSE ON AN "AS IS" BASIS, WITHOUT WARRANTY
16 * OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, WITHOUT LIMITATION, WARRANTIES
17 * THAT THE COVERED CODE IS FREE OF DEFECTS, MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE
18 * OR NON-INFRINGING. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE COVERED
19 * CODE IS WITH YOU. SHOULD ANY COVERED CODE PROVE DEFECTIVE IN ANY RESPECT, YOU (NOT
20 * THE INITIAL DEVELOPER OR ANY OTHER CONTRIBUTOR) ASSUME THE COST OF ANY NECESSARY
21 * SERVICING, REPAIR OR CORRECTION. THIS DISCLAIMER OF WARRANTY CONSTITUTES AN ESSENTIAL
22 * PART OF THIS LICENSE. NO USE OF ANY COVERED CODE IS AUTHORIZED HEREUNDER EXCEPT UNDER
25 * Use at your own risk!
26 * ==========================================================
29 #if !defined(__ImaIter_h)
39 int Itx, Ity; // Counters
41 BYTE* IterImage; // Image pointer
45 CImageIterator ( void );
46 CImageIterator ( CxImage *image );
53 void SetRow(BYTE *buf, int n);
54 void GetRow(BYTE *buf, int n);
55 BYTE GetByte( ) { return IterImage[Itx]; }
56 void SetByte(BYTE b) { IterImage[Itx] = b; }
64 void SetSteps(int x, int y=0) { Stepx = x; Stepy = y; }
65 void GetSteps(int *x, int *y) { *x = Stepx; *y = Stepy; }
69 void SetY(int y); /* AD - for interlace */
70 int GetY() {return Ity;}
71 BOOL GetCol(BYTE* pCol, DWORD x);
72 BOOL SetCol(BYTE* pCol, DWORD x);
75 /////////////////////////////////////////////////////////////////////
77 CImageIterator::CImageIterator(void)
84 /////////////////////////////////////////////////////////////////////
86 CImageIterator::CImageIterator(CxImage *imageImpl): ima(imageImpl)
88 if (ima) IterImage = ima->GetBits();
92 /////////////////////////////////////////////////////////////////////
94 CImageIterator::operator CxImage* ()
98 /////////////////////////////////////////////////////////////////////
99 inline BOOL CImageIterator::ItOK ()
101 if (ima) return ima->IsInside(Itx, Ity);
104 /////////////////////////////////////////////////////////////////////
105 inline void CImageIterator::Reset()
107 if (ima) IterImage = ima->GetBits();
111 /////////////////////////////////////////////////////////////////////
112 inline void CImageIterator::Upset()
115 Ity = ima->GetHeight()-1;
116 IterImage = ima->GetBits() + ima->GetEffWidth()*(ima->GetHeight()-1);
118 /////////////////////////////////////////////////////////////////////
119 inline BOOL CImageIterator::NextRow()
121 if (++Ity >= (int)ima->GetHeight()) return 0;
122 IterImage += ima->GetEffWidth();
125 /////////////////////////////////////////////////////////////////////
126 inline BOOL CImageIterator::PrevRow()
128 if (--Ity < 0) return 0;
129 IterImage -= ima->GetEffWidth();
132 /* AD - for interlace */
133 inline void CImageIterator::SetY(int y)
135 if ((y < 0) || (y > (int)ima->GetHeight())) return;
137 IterImage = ima->GetBits() + ima->GetEffWidth()*y;
139 /////////////////////////////////////////////////////////////////////
140 inline void CImageIterator::SetRow(BYTE *buf, int n)
142 if (n<0) n = (int)ima->GetEffWidth();
143 else n = min(n,(int)ima->GetEffWidth());
145 if ((IterImage!=NULL)&&(buf!=NULL)&&(n>0)) memcpy(IterImage,buf,n);
147 /////////////////////////////////////////////////////////////////////
148 inline void CImageIterator::GetRow(BYTE *buf, int n)
150 if ((IterImage!=NULL)&&(buf!=NULL)&&(n>0))
151 memcpy(buf,IterImage,min(n,(int)ima->GetEffWidth()));
153 /////////////////////////////////////////////////////////////////////
154 inline BYTE* CImageIterator::GetRow()
158 /////////////////////////////////////////////////////////////////////
159 inline BYTE* CImageIterator::GetRow(int n)
164 /////////////////////////////////////////////////////////////////////
165 inline BOOL CImageIterator::NextByte()
167 if (++Itx < (int)ima->GetEffWidth()) return 1;
169 if (++Ity < (int)ima->GetHeight()){
170 IterImage += ima->GetEffWidth();
176 /////////////////////////////////////////////////////////////////////
177 inline BOOL CImageIterator::PrevByte()
179 if (--Itx >= 0) return 1;
182 IterImage -= ima->GetEffWidth();
188 /////////////////////////////////////////////////////////////////////
189 inline BOOL CImageIterator::NextStep()
192 if (Itx < (int)ima->GetEffWidth()) return 1;
195 if (Ity < (int)ima->GetHeight()){
196 IterImage += ima->GetEffWidth();
203 /////////////////////////////////////////////////////////////////////
204 inline BOOL CImageIterator::PrevStep()
207 if (Itx >= 0) return 1;
210 if (Ity >= 0 && Ity < (int)ima->GetHeight()) {
211 IterImage -= ima->GetEffWidth();
218 /////////////////////////////////////////////////////////////////////
219 inline BOOL CImageIterator::GetCol(BYTE* pCol, DWORD x)
221 if ((pCol==0)||(ima->GetBpp()<8)||(x>=ima->GetWidth()))
223 DWORD h = ima->GetHeight();
224 //DWORD line = ima->GetEffWidth();
225 BYTE bytes = (BYTE)(ima->GetBpp()>>3);
227 for (DWORD y=0;y<h;y++){
228 pSrc = ima->GetBits(y) + x*bytes;
229 for (BYTE w=0;w<bytes;w++){
235 /////////////////////////////////////////////////////////////////////
236 inline BOOL CImageIterator::SetCol(BYTE* pCol, DWORD x)
238 if ((pCol==0)||(ima->GetBpp()<8)||(x>=ima->GetWidth()))
240 DWORD h = ima->GetHeight();
241 //DWORD line = ima->GetEffWidth();
242 BYTE bytes = (BYTE)(ima->GetBpp()>>3);
244 for (DWORD y=0;y<h;y++){
245 pSrc = ima->GetBits(y) + x*bytes;
246 for (BYTE w=0;w<bytes;w++){
252 /////////////////////////////////////////////////////////////////////