00001 //////////////////////////////////////////////////////////////////////////////// 00002 // Scorched3D (c) 2000-2009 00003 // 00004 // This file is part of Scorched3D. 00005 // 00006 // Scorched3D is free software; you can redistribute it and/or modify 00007 // it under the terms of the GNU General Public License as published by 00008 // the Free Software Foundation; either version 2 of the License, or 00009 // (at your option) any later version. 00010 // 00011 // Scorched3D is distributed in the hope that it will be useful, 00012 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00013 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00014 // GNU General Public License for more details. 00015 // 00016 // You should have received a copy of the GNU General Public License 00017 // along with Scorched3D; if not, write to the Free Software 00018 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 00019 //////////////////////////////////////////////////////////////////////////////// 00020 00021 #if !defined(AFX_ImageITTERATOR_H__F83D9F30_02DF_44EC_B2E7_1F4D87D6FBC8__INCLUDED_) 00022 #define AFX_ImageITTERATOR_H__F83D9F30_02DF_44EC_B2E7_1F4D87D6FBC8__INCLUDED_ 00023 00024 #include <image/Image.h> 00025 00026 /** 00027 A helper class that simplifes the iteration (looping) through 00028 the components contained within bitmap files. 00029 00030 ImageItterator bitmapItor(myBitmap, 00031 myRequiredWidth, myRequiredHeight, myRequiredType); 00032 for (int by=0; by<myRequiredHeight; by++, bitmapItor.incY()) 00033 { 00034 for (int bx=0; bx<myRequiredWidth; bx++, bitmapItor.incX()) 00035 { 00036 // Get the bytes at bx, by position in the bitmap. 00037 // This will be an array of 3 or 4 bytes depending 00038 // on the bitmap type. 00039 unsigned char *sourceBits = bitmapItor.getPos(); 00040 } 00041 } 00042 */ 00043 class ImageItterator 00044 { 00045 public: 00046 /** 00047 Defines the type of the iteration. 00048 Wrap - The bitmap is tiled/repeated if it is smaller 00049 than the given destX/destY sizes. 00050 Stretch - The bitmap extents are stretched to 00051 match the destX and destY sizes. 00052 */ 00053 enum Type 00054 { 00055 wrap, 00056 stretch 00057 }; 00058 00059 /** 00060 DestX is the maximum width you will ask the iterator to return. 00061 DestY is the maximum height you will ask the iterator to return. 00062 Type defines how these width/height maps the bitmaps size. 00063 */ 00064 ImageItterator(Image &bitmap, 00065 int destX, 00066 int destY, 00067 Type type = stretch); 00068 virtual ~ImageItterator(); 00069 00070 /** 00071 Reset the iterator. 00072 */ 00073 void reset(); 00074 /** 00075 Position the iterator at the next bitmap bytes in the row. 00076 */ 00077 void incX(); 00078 /** 00079 Position the iterator at the next row. 00080 */ 00081 void incY(); 00082 /** 00083 Get the bytes at the current iterator's position. 00084 */ 00085 unsigned char *getPos(); 00086 00087 protected: 00088 Image &bitmap_; 00089 float dx_, dy_; 00090 int width_; 00091 Type type_; 00092 00093 unsigned char *pos_; 00094 float posX_, posY_; 00095 }; 00096 00097 #endif // !defined(AFX_ImageITTERATOR_H__F83D9F30_02DF_44EC_B2E7_1F4D87D6FBC8__INCLUDED_)
1.5.3