|
degate 0.1.1
|
The ScalingManager creates prescaled images for a master image. More...
#include <ScalingManager.h>
Public Types | |
| typedef std::pair< double, std::tr1::shared_ptr < ImageType > > | image_map_element |
| typedef std::map< double, std::tr1::shared_ptr < ImageType > > | image_map |
| typedef std::list< double > | zoom_step_list |
Public Member Functions | |
| ScalingManager (std::tr1::shared_ptr< ImageType > img, std::string const &base_directory, int min_size=1024) | |
| Create a new ScalingManager object for an image. | |
| ~ScalingManager () | |
| Destroy a scaling manager. | |
| const zoom_step_list | get_zoom_steps () const |
| Get a list of available zoom steps. | |
| void | create_scalings () |
| Create the scaled images. | |
| image_map_element | get_image (double request_scaling) |
| Get the image with the nearest scaling value to the requested scaling. | |
Private Member Functions | |
| unsigned long | get_nearest_power_of_two (unsigned int value) |
Private Attributes | |
| std::string | base_directory |
| image_map | images |
| unsigned int | min_size |
The ScalingManager creates prescaled images for a master image.
You can use the ScalingManager only for images of type TileImage. If you want to scale images for yourself, please check out method scale_down().
Definition at line 42 of file ScalingManager.h.
| typedef std::map<double, std::tr1::shared_ptr<ImageType> > degate::ScalingManager< ImageType >::image_map |
Definition at line 48 of file ScalingManager.h.
| typedef std::pair<double, std::tr1::shared_ptr<ImageType> > degate::ScalingManager< ImageType >::image_map_element |
Definition at line 46 of file ScalingManager.h.
| typedef std::list<double> degate::ScalingManager< ImageType >::zoom_step_list |
Definition at line 74 of file ScalingManager.h.
| degate::ScalingManager< ImageType >::ScalingManager | ( | std::tr1::shared_ptr< ImageType > | img, |
| std::string const & | base_directory, | ||
| int | min_size = 1024 |
||
| ) | [inline] |
Create a new ScalingManager object for an image.
| img | The background image. |
| base_directory | A directory where all files can be stored. You can use the directory of the master image for that. Make sure that the directory exist. if you compile libdegate with DEBUG=1 the existence is assert()ed. |
| min_size | Create down scalings until the edge length is becomes less than min_size. |
Definition at line 86 of file ScalingManager.h.
References degate::ScalingManager< ImageType >::base_directory, degate::file_exists(), degate::ScalingManager< ImageType >::images, and degate::ScalingManager< ImageType >::min_size.
{
assert(img != NULL);
this->base_directory = base_directory;
images[1] = img;
this->min_size = min_size;
assert(file_exists(base_directory));
}

| degate::ScalingManager< ImageType >::~ScalingManager | ( | ) | [inline] |
Destroy a scaling manager.
This will destroy images anf their files and directories if the imag is not persistent.
Definition at line 102 of file ScalingManager.h.
{}
| void degate::ScalingManager< ImageType >::create_scalings | ( | ) | [inline] |
Create the scaled images.
Created prescaled images that have the same peristence state as the master image. The files are written into the directory, where the master image is stored.
| InvalidPathException | This exception is thrown, if the directory (ctor param) doesn't exists. |
Definition at line 130 of file ScalingManager.h.
References degate::ScalingManager< ImageType >::base_directory, degate::create_directory(), debug(), degate::file_exists(), degate::ScalingManager< ImageType >::images, degate::is_directory(), degate::join_pathes(), degate::ScalingManager< ImageType >::min_size, and TM.
{
if(!(file_exists(base_directory) && is_directory(base_directory)))
throw InvalidPathException("The directory for prescaled images must exist. but it is not there.");
std::tr1::shared_ptr<ImageType> last_img = images[1];
unsigned int w = last_img->get_width();
unsigned int h = last_img->get_height();
for(int i = 2; ((h > min_size) || (w > min_size)) &&
(i < (1<<24)); // max 24 scaling levels
i*=2) {
w >>= 1;
h >>= 1;
// create a new image
char dir_name[PATH_MAX];
snprintf(dir_name, sizeof(dir_name), "scaling_%d.dimg", i);
std::string dir_path = join_pathes(images[1]->get_directory(), std::string(dir_name));
debug(TM, "create scaled image in %s for scaling factor %d?", dir_path.c_str(), i);
if(!file_exists(dir_path)) {
debug(TM, "yes");
create_directory(dir_path);
std::tr1::shared_ptr<ImageType> new_img(new ImageType(w, h, dir_path,
images[1]->is_persistent()));
scale_down_by_2<ImageType, ImageType>(new_img, last_img);
last_img = new_img;
}
else {
debug(TM, "no");
std::tr1::shared_ptr<ImageType> new_img(new ImageType(w, h, dir_path,
images[1]->is_persistent()));
last_img = new_img;
}
images[i] = last_img;
}
}

| image_map_element degate::ScalingManager< ImageType >::get_image | ( | double | request_scaling | ) | [inline] |
Get the image with the nearest scaling value to the requested scaling.
Definition at line 177 of file ScalingManager.h.
References degate::ScalingManager< ImageType >::get_nearest_power_of_two(), and degate::ScalingManager< ImageType >::images.
{
unsigned int factor;
if(request_scaling > 1) {
factor = std::min(get_nearest_power_of_two(lrint(request_scaling)),
(unsigned long)lrint(images.rbegin()->first));
typename image_map::iterator found = images.find(factor);
assert(found != images.end());
//debug(TM, "requested scaling is %f. nearest scaling is %d. found image with scaling %f", request_scaling, factor, found->first);
return *found;
}
//debug(TM, "return normal image");
return image_map_element(1, images[1]);
}

| unsigned long degate::ScalingManager< ImageType >::get_nearest_power_of_two | ( | unsigned int | value | ) | [inline, private] |
Definition at line 59 of file ScalingManager.h.
Referenced by degate::ScalingManager< ImageType >::get_image().
{
unsigned int i = 1;
if (value == 0) return 1;
for (;;) {
if (value == 1) return i;
else if (value == 3) return i*4;
value >>= 1;
i *= 2;
}
}

| const zoom_step_list degate::ScalingManager< ImageType >::get_zoom_steps | ( | ) | const [inline] |
Get a list of available zoom steps.
Definition at line 110 of file ScalingManager.h.
References degate::ScalingManager< ImageType >::images.
{
zoom_step_list steps;
for(typename image_map::const_iterator iter = images.begin();
iter != images.end(); ++iter)
steps.push_back((*iter).first);
steps.sort();
return steps;
}
std::string degate::ScalingManager< ImageType >::base_directory [private] |
Definition at line 51 of file ScalingManager.h.
Referenced by degate::ScalingManager< ImageType >::create_scalings(), and degate::ScalingManager< ImageType >::ScalingManager().
image_map degate::ScalingManager< ImageType >::images [private] |
unsigned int degate::ScalingManager< ImageType >::min_size [private] |
Definition at line 55 of file ScalingManager.h.
Referenced by degate::ScalingManager< ImageType >::create_scalings(), and degate::ScalingManager< ImageType >::ScalingManager().
1.7.4