00001 #include <core_api/imagesplitter.h>
00002 #include <iostream>
00003
00004 #include <algorithm>
00005
00006 __BEGIN_YAFRAY
00007
00008
00009
00010
00011
00012 imageSpliter_t::imageSpliter_t(int w, int h, int x0,int y0, int bsize, tilesOrderType torder): blocksize(bsize), tilesorder(torder)
00013 {
00014 int nx, ny;
00015 nx = (w+blocksize-1)/blocksize;
00016 ny = (h+blocksize-1)/blocksize;
00017 for(int j=0; j<ny; ++j)
00018 {
00019 for(int i=0; i<nx; ++i)
00020 {
00021 region_t r;
00022 r.x = x0 + i*blocksize;
00023 r.y = y0 + j*blocksize;
00024 r.w = std::min(blocksize, x0+w-r.x);
00025 r.h = std::min(blocksize, y0+h-r.y);
00026 regions.push_back(r);
00027 }
00028 }
00029 switch(tilesorder)
00030 {
00031 case RANDOM: std::random_shuffle( regions.begin(), regions.end() );
00032 case LINEAR:
00033 default: break;
00034 }
00035 }
00036
00037 bool imageSpliter_t::getArea(int n, renderArea_t &area)
00038 {
00039 if(n<0 || n>=(int)regions.size()) return false;
00040 region_t &r = regions[n];
00041 area.X = r.x;
00042 area.Y = r.y;
00043 area.W = r.w;
00044 area.H = r.h;
00045 return true;
00046 }
00047
00048 __END_YAFRAY