2011-04-27 11:58:34 +00:00
|
|
|
/*
|
|
|
|
* Copyright 2011, Blender Foundation.
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software Foundation,
|
|
|
|
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "tile.h"
|
|
|
|
|
|
|
|
#include "util_algorithm.h"
|
|
|
|
|
|
|
|
CCL_NAMESPACE_BEGIN
|
|
|
|
|
2011-09-16 13:14:02 +00:00
|
|
|
TileManager::TileManager(bool progressive_, int samples_, int tile_size_, int min_size_)
|
2011-04-27 11:58:34 +00:00
|
|
|
{
|
|
|
|
progressive = progressive_;
|
|
|
|
tile_size = tile_size_;
|
|
|
|
min_size = min_size_;
|
|
|
|
|
2011-12-20 12:25:37 +00:00
|
|
|
BufferParams buffer_params;
|
|
|
|
reset(buffer_params, 0);
|
2011-04-27 11:58:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
TileManager::~TileManager()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2011-12-20 12:25:37 +00:00
|
|
|
void TileManager::reset(BufferParams& params_, int samples_)
|
2011-04-27 11:58:34 +00:00
|
|
|
{
|
2011-12-20 12:25:37 +00:00
|
|
|
params = params_;
|
2011-04-27 11:58:34 +00:00
|
|
|
|
|
|
|
start_resolution = 1;
|
|
|
|
|
2011-12-20 12:25:37 +00:00
|
|
|
int w = params.width, h = params.height;
|
2011-04-27 11:58:34 +00:00
|
|
|
|
|
|
|
if(min_size != INT_MAX) {
|
|
|
|
while(w*h > min_size*min_size) {
|
|
|
|
w = max(1, w/2);
|
|
|
|
h = max(1, h/2);
|
|
|
|
|
|
|
|
start_resolution *= 2;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-09-16 13:14:02 +00:00
|
|
|
samples = samples_;
|
2011-08-28 13:55:59 +00:00
|
|
|
|
2011-12-21 13:48:35 +00:00
|
|
|
state.buffer = BufferParams();
|
2011-09-16 13:14:02 +00:00
|
|
|
state.sample = -1;
|
2011-04-27 11:58:34 +00:00
|
|
|
state.resolution = start_resolution;
|
|
|
|
state.tiles.clear();
|
|
|
|
}
|
|
|
|
|
2011-09-16 13:14:02 +00:00
|
|
|
void TileManager::set_samples(int samples_)
|
2011-08-28 13:55:59 +00:00
|
|
|
{
|
2011-09-16 13:14:02 +00:00
|
|
|
samples = samples_;
|
2011-08-28 13:55:59 +00:00
|
|
|
}
|
|
|
|
|
2011-04-27 11:58:34 +00:00
|
|
|
void TileManager::set_tiles()
|
|
|
|
{
|
|
|
|
int resolution = state.resolution;
|
2011-12-20 12:25:37 +00:00
|
|
|
int image_w = max(1, params.width/resolution);
|
|
|
|
int image_h = max(1, params.height/resolution);
|
2012-01-04 18:06:32 +00:00
|
|
|
int tile_w = (tile_size >= image_w)? 1: (image_w + tile_size - 1)/tile_size;
|
|
|
|
int tile_h = (tile_size >= image_h)? 1: (image_h + tile_size - 1)/tile_size;
|
2011-04-27 11:58:34 +00:00
|
|
|
int sub_w = image_w/tile_w;
|
|
|
|
int sub_h = image_h/tile_h;
|
|
|
|
|
|
|
|
state.tiles.clear();
|
|
|
|
|
|
|
|
for(int tile_y = 0; tile_y < tile_h; tile_y++) {
|
|
|
|
for(int tile_x = 0; tile_x < tile_w; tile_x++) {
|
|
|
|
int x = tile_x * sub_w;
|
|
|
|
int y = tile_y * sub_h;
|
|
|
|
int w = (tile_x == tile_w-1)? image_w - x: sub_w;
|
|
|
|
int h = (tile_y == tile_h-1)? image_h - y: sub_h;
|
|
|
|
|
|
|
|
state.tiles.push_back(Tile(x, y, w, h));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-12-21 13:48:35 +00:00
|
|
|
state.buffer.width = image_w;
|
|
|
|
state.buffer.height = image_h;
|
|
|
|
|
|
|
|
state.buffer.full_x = params.full_x/resolution;
|
|
|
|
state.buffer.full_y = params.full_y/resolution;
|
|
|
|
state.buffer.full_width = max(1, params.full_width/resolution);
|
|
|
|
state.buffer.full_height = max(1, params.full_height/resolution);
|
2011-04-27 11:58:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool TileManager::done()
|
|
|
|
{
|
2011-09-16 13:14:02 +00:00
|
|
|
return (state.sample+1 >= samples && state.resolution == 1);
|
2011-04-27 11:58:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool TileManager::next()
|
|
|
|
{
|
|
|
|
if(done())
|
|
|
|
return false;
|
|
|
|
|
|
|
|
if(progressive && state.resolution > 1) {
|
2011-09-16 13:14:02 +00:00
|
|
|
state.sample = 0;
|
2011-04-27 11:58:34 +00:00
|
|
|
state.resolution /= 2;
|
|
|
|
set_tiles();
|
|
|
|
}
|
|
|
|
else {
|
2011-09-16 13:14:02 +00:00
|
|
|
state.sample++;
|
2011-04-27 11:58:34 +00:00
|
|
|
state.resolution = 1;
|
|
|
|
set_tiles();
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
CCL_NAMESPACE_END
|
|
|
|
|