1 // -*- c-basic-offset: 4 -*-
2
3 /** @file wxImageCache.cpp
4 *
5 * @brief implementation of ImageCache Class
6 *
7 * @author Pablo d'Angelo <pablo.dangelo@web.de>
8 *
9 * $Id$
10 *
11 * This program is free software; you can redistribute it and/or
12 * modify it under the terms of the GNU General Public
13 * License as published by the Free Software Foundation; either
14 * version 2 of the License, or (at your option) any later version.
15 *
16 * This software is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 * General Public License for more details.
20 *
21 * You should have received a copy of the GNU General Public
22 * License along with this software. If not, see
23 * <http://www.gnu.org/licenses/>.
24 *
25 */
26
27 #include "wxImageCache.h"
28 #include "vigra_ext/utils.h"
29
imageCacheEntry2wxImage(ImageCache::EntryPtr e)30 wxImage imageCacheEntry2wxImage(ImageCache::EntryPtr e)
31 {
32 if (e->imageFloat->size().area() > 0)
33 {
34 // for float images we need to apply the mapping as selected by the user
35 // in the preferences
36 const int mapping = wxConfigBase::Get()->Read(wxT("/ImageCache/Mapping"), HUGIN_IMGCACHE_MAPPING_FLOAT);
37 // find min/max
38 vigra::RGBToGrayAccessor<vigra::RGBValue<float> > ga;
39 vigra::FindMinMax<float> minmax; // init functor
40 vigra::inspectImage(srcImageRange(*(e->imageFloat), ga), minmax);
41 // create temporary image with remapped tone scale
42 vigra::BRGBImage mappedImg(e->imageFloat->size());
43 vigra_ext::applyMapping(srcImageRange(*(e->imageFloat)), destImage(mappedImg), std::max(minmax.min, 1e-6f), minmax.max, mapping);
44 // convert to wxImage
45 wxImage mappedwxImg(mappedImg.width(), mappedImg.height(), (unsigned char *)mappedImg.data(), true);
46 return mappedwxImg.Copy();
47 }
48 else
49 {
50 ImageCacheRGB8Ptr img = e->get8BitImage();
51 if (img)
52 {
53 return wxImage(img->width(), img->height(), (unsigned char *)img->data(), true);
54 }
55 else
56 {
57 // invalid wxImage
58 return wxImage();
59 };
60 };
61 }
62
63