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