00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 #include "tilepx.h"
00024 #include "error.h"
00025
00026 using namespace lux;
00027
00028
00029 TilePixelSampler::TilePixelSampler(
00030 int xStart, int xEnd,
00031 int yStart, int yEnd) {
00032
00033
00034
00035
00036
00037
00038 int xSize = xEnd - xStart;
00039 int ySize = yEnd - yStart;
00040
00041 int tileXSize = xSize / TILEPX_SIZE + ((xSize % TILEPX_SIZE == 0) ? 0 : 1);
00042 int tileYSize = ySize / TILEPX_SIZE + ((ySize % TILEPX_SIZE == 0) ? 0 : 1);
00043
00044
00045
00046
00047
00048
00049 TotalPx = 0;
00050 for(int yg = 0; yg < tileYSize; yg++) {
00051 for(int xg = 0; xg < tileXSize; xg++) {
00052 for(int y = yStart + yg * TILEPX_SIZE; y < yStart + (yg + 1) * TILEPX_SIZE; y++) {
00053 for(int x = xStart + xg * TILEPX_SIZE; x < xStart + (xg + 1) * TILEPX_SIZE; x++) {
00054 if((x <= xEnd) && (y <= yEnd)) {
00055 PxLoc px;
00056 px.x = x; px.y = y;
00057 Pxa.push_back(px);
00058 TotalPx++;
00059 }
00060 }
00061 }
00062 }
00063 }
00064 }
00065
00066 u_int TilePixelSampler::GetTotalPixels() {
00067 return TotalPx;
00068 }
00069
00070 bool TilePixelSampler::GetNextPixel(int &xPos, int &yPos, u_int *use_pos) {
00071 u_int pos = (*use_pos);
00072 bool hasMorePixel = true;
00073 if(pos == TotalPx - 1)
00074 hasMorePixel = false;
00075
00076 xPos = Pxa[pos].x;
00077 yPos = Pxa[pos].y;
00078
00079 return hasMorePixel;
00080 }