Merge
This commit is contained in:
@@ -658,6 +658,7 @@ TP_RESIZE_FULLSIZE;Full Image Size:
|
||||
TP_RESIZE_H;H:
|
||||
TP_RESIZE_HEIGHT;Height
|
||||
TP_RESIZE_LABEL;Resize
|
||||
TP_RESIZE_LANCZOS;Lanczos
|
||||
TP_RESIZE_METHOD;Method:
|
||||
TP_RESIZE_NEAREST;Nearest
|
||||
TP_RESIZE_SCALE;Scale
|
||||
|
@@ -23,6 +23,8 @@
|
||||
#include <omp.h>
|
||||
#endif
|
||||
|
||||
#include <iostream>
|
||||
|
||||
namespace rtengine {
|
||||
|
||||
#undef CLIP
|
||||
@@ -33,9 +35,149 @@ namespace rtengine {
|
||||
#define CLIP(a) ((a)>0?((a)<CMAXVAL?(a):CMAXVAL):0)
|
||||
#define CLIPTO(a,b,c) ((a)>(b)?((a)<(c)?(a):(c)):(b))
|
||||
|
||||
inline double Lanc(double x, double a)
|
||||
{
|
||||
if (x * x < 1e-6)
|
||||
return 1.0;
|
||||
else if (x * x > a * a)
|
||||
return 0.0;
|
||||
else {
|
||||
x = M_PI * x;
|
||||
return sin(x) * sin(x / a) / (x * x / a);
|
||||
}
|
||||
}
|
||||
|
||||
void Lanczos(const Image16* src, Image16* dst, double scale)
|
||||
{
|
||||
const double delta = 1.0 / scale;
|
||||
const double a = 3.0;
|
||||
const double sc = std::min(scale, 1.0);
|
||||
const int support = (int)(2.0 * a / sc) + 1;
|
||||
|
||||
// storage for precomputed parameters for horisontal interpolation
|
||||
double * wwh = new double[support * dst->width];
|
||||
int * jj0 = new int[dst->width];
|
||||
int * jj1 = new int[dst->width];
|
||||
|
||||
// temporal storage for vertically-interpolated row of pixels
|
||||
double * lr = new double[src->width];
|
||||
double * lg = new double[src->width];
|
||||
double * lb = new double[src->width];
|
||||
|
||||
// Phase 1: precompute coefficients for horisontal interpolation
|
||||
|
||||
for (int j = 0; j < dst->width; j++) {
|
||||
|
||||
// x coord of the center of pixel on src image
|
||||
double x0 = (j + 0.5) * delta - 0.5;
|
||||
|
||||
// weights for interpolation in horisontal direction
|
||||
double * w = wwh + j * support;
|
||||
|
||||
// sum of weights used for normalization
|
||||
double ws = 0.0;
|
||||
|
||||
jj0[j] = std::max(0, (int)floor(x0 - a / sc) + 1);
|
||||
jj1[j] = std::min(src->width, (int)floor(x0 + a / sc) + 1);
|
||||
|
||||
// calculate weights
|
||||
for (int jj = jj0[j]; jj < jj1[j]; jj++) {
|
||||
int k = jj - jj0[j];
|
||||
double z = sc * (x0 - jj);
|
||||
w[k] = Lanc(z, a);
|
||||
ws += w[k];
|
||||
}
|
||||
|
||||
// normalize weights
|
||||
for (int k = 0; k < support; k++) {
|
||||
w[k] /= ws;
|
||||
}
|
||||
}
|
||||
|
||||
// Phase 2: do actual interpolation
|
||||
|
||||
for (int i = 0; i < dst->height; i++) {
|
||||
|
||||
// y coord of the center of pixel on src image
|
||||
double y0 = (i + 0.5) * delta - 0.5;
|
||||
|
||||
// weights for interpolation in y direction
|
||||
double w[support];
|
||||
|
||||
// sum of weights used for normalization
|
||||
double ws= 0.0;
|
||||
|
||||
int ii0 = std::max(0, (int)floor(y0 - a / sc) + 1);
|
||||
int ii1 = std::min(src->height, (int)floor(y0 + a / sc) + 1);
|
||||
|
||||
// calculate weights for vertical interpolation
|
||||
for (int ii = ii0; ii < ii1; ii++) {
|
||||
int k = ii - ii0;
|
||||
double z = sc * (y0 - ii);
|
||||
w[k] = Lanc(z, a);
|
||||
ws += w[k];
|
||||
}
|
||||
|
||||
// normalize weights
|
||||
for (int k = 0; k < support; k++) {
|
||||
w[k] /= ws;
|
||||
}
|
||||
|
||||
// Do vertical interpolation. Store results.
|
||||
for (int j = 0; j < src->width; j++) {
|
||||
|
||||
double r = 0.0, g = 0.0, b = 0.0;
|
||||
|
||||
for (int ii = ii0; ii < ii1; ii++) {
|
||||
int k = ii - ii0;
|
||||
|
||||
r += w[k] * src->r[ii][j];
|
||||
g += w[k] * src->g[ii][j];
|
||||
b += w[k] * src->b[ii][j];
|
||||
}
|
||||
|
||||
lr[j] = r;
|
||||
lg[j] = g;
|
||||
lb[j] = b;
|
||||
}
|
||||
|
||||
// Do horisontal interpolation
|
||||
for(int j = 0; j < dst->width; j++) {
|
||||
|
||||
double * wh = wwh + support * j;
|
||||
|
||||
double r = 0.0, g = 0.0, b = 0.0;
|
||||
|
||||
for (int jj = jj0[j]; jj < jj1[j]; jj++) {
|
||||
int k = jj - jj0[j];
|
||||
|
||||
r += wh[k] * lr[jj];
|
||||
g += wh[k] * lg[jj];
|
||||
b += wh[k] * lb[jj];
|
||||
}
|
||||
|
||||
dst->r[i][j] = CLIP((int)r);
|
||||
dst->g[i][j] = CLIP((int)g);
|
||||
dst->b[i][j] = CLIP((int)b);
|
||||
}
|
||||
}
|
||||
|
||||
delete[] wwh;
|
||||
delete[] jj0;
|
||||
delete[] jj1;
|
||||
delete[] lr;
|
||||
delete[] lg;
|
||||
delete[] lb;
|
||||
}
|
||||
|
||||
void ImProcFunctions::resize (Image16* src, Image16* dst) {
|
||||
|
||||
if(params->resize.method == "Downscale (Better)") {
|
||||
//time_t t1 = clock();
|
||||
|
||||
if(params->resize.method == "Lanczos") {
|
||||
Lanczos(src, dst, params->resize.scale);
|
||||
}
|
||||
else if(params->resize.method == "Downscale (Better)") {
|
||||
// small-scale algorithm by Ilia
|
||||
// provides much better quality on small scales
|
||||
// calculates mean value over source pixels which current destination pixel covers
|
||||
@@ -117,11 +259,8 @@ void ImProcFunctions::resize (Image16* src, Image16* dst) {
|
||||
dst->b[i][j] = CLIP((int)b);
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
if(params->resize.method == "Downscale (Faster)")
|
||||
{
|
||||
else if(params->resize.method == "Downscale (Faster)") {
|
||||
// faster version of algo above, does not take into account border pixels,
|
||||
// which are summed with non-unity weights in slow algo. So, no need
|
||||
// for weights at all
|
||||
@@ -190,9 +329,8 @@ void ImProcFunctions::resize (Image16* src, Image16* dst) {
|
||||
dst->b[i][j] = CLIP( b * k / divider);
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
if (params->resize.method.substr(0,7)=="Bicubic") {
|
||||
else if (params->resize.method.substr(0,7)=="Bicubic") {
|
||||
double Av = -0.5;
|
||||
if (params->resize.method=="Bicubic (Sharper)")
|
||||
Av = -0.75;
|
||||
@@ -290,6 +428,10 @@ void ImProcFunctions::resize (Image16* src, Image16* dst) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//time_t t2 = clock();
|
||||
//std::cout << "Resize: " << params->resize.method << ": "
|
||||
// << (double)(t2 - t1) / CLOCKS_PER_SEC << std::endl;
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -336,7 +336,7 @@ IImage8* Thumbnail::processImage (const procparams::ProcParams& params, int rhei
|
||||
baseImg->b[i][j] = CLIP(val);
|
||||
}
|
||||
|
||||
// appy highlight recovery, if needed
|
||||
// apply highlight recovery, if needed
|
||||
if (isRaw && params.hlrecovery.enabled) {
|
||||
int maxval = 65535 / defGain;
|
||||
if (params.hlrecovery.method=="Luminance" || params.hlrecovery.method=="Color")
|
||||
@@ -623,6 +623,7 @@ void Thumbnail::transformPixel (int x, int y, int tran, int& tx, int& ty) {
|
||||
ty/=scale;
|
||||
}
|
||||
|
||||
// format: 1=8bit direct, 2=16bit direct, 3=JPG
|
||||
bool Thumbnail::writeImage (const Glib::ustring& fname, int format) {
|
||||
|
||||
if (!thumbImg)
|
||||
@@ -689,6 +690,14 @@ bool Thumbnail::writeImage (const Glib::ustring& fname, int format) {
|
||||
cinfo.input_components = 3;
|
||||
jpeg_set_defaults (&cinfo);
|
||||
cinfo.write_JFIF_header = FALSE;
|
||||
|
||||
// compute optimal Huffman coding tables for the image. Bit slower to generate, but size of result image is a bit less (default was FALSE)
|
||||
cinfo.optimize_coding = TRUE;
|
||||
|
||||
// Since math coprocessors are common these days, FLOAT should be a bit more accurate AND fast (default is ISLOW)
|
||||
// (machine dependency is not really an issue, since we all run on x86 and having exactly the same file is not a requirement)
|
||||
cinfo.dct_method = JDCT_FLOAT;
|
||||
|
||||
jpeg_set_quality (&cinfo, 85, true);
|
||||
jpeg_start_compress(&cinfo, TRUE);
|
||||
int rowlen = thumbImg->width*3;
|
||||
|
@@ -195,7 +195,7 @@ rtengine::ProcessingJob* BatchQueue::imageReady (rtengine::IImage16* img) {
|
||||
fname = autoCompleteFileName (removeExtension(processing->outFileName), getExtension(processing->outFileName));
|
||||
saveFormat = processing->saveFormat;
|
||||
}
|
||||
printf ("fname=%s, %s\n", fname.c_str(), removeExtension(fname).c_str());
|
||||
//printf ("fname=%s, %s\n", fname.c_str(), removeExtension(fname).c_str());
|
||||
if (img && fname!="") {
|
||||
int err = 0;
|
||||
if (saveFormat.format=="tif")
|
||||
@@ -205,14 +205,16 @@ rtengine::ProcessingJob* BatchQueue::imageReady (rtengine::IImage16* img) {
|
||||
else if (saveFormat.format=="jpg")
|
||||
err = img->saveAsJPEG (fname, saveFormat.jpegQuality);
|
||||
img->free ();
|
||||
if (!err && saveFormat.saveParams)
|
||||
|
||||
if (err) throw "Unable to save output file";
|
||||
|
||||
if (saveFormat.saveParams) {
|
||||
// We keep the extension to avoid overwriting the profile when we have
|
||||
// the same output filename with different extension
|
||||
//processing->params.save (removeExtension(fname) + paramFileExtension);
|
||||
processing->params.save (fname + paramFileExtension);
|
||||
else {
|
||||
printf("Unable to process or save %s\n", fname.c_str());
|
||||
}
|
||||
|
||||
if (processing->thumbnail) {
|
||||
processing->thumbnail->imageDeveloped ();
|
||||
processing->thumbnail->imageRemovedFromQueue ();
|
||||
|
@@ -91,9 +91,7 @@ int CacheImageData::save (const Glib::ustring& fname) {
|
||||
|
||||
rtengine::SafeKeyFile keyFile;
|
||||
|
||||
try {
|
||||
keyFile.load_from_file (fname);
|
||||
} catch (...) {}
|
||||
if (::g_file_test(fname.c_str(),G_FILE_TEST_EXISTS)) keyFile.load_from_file (fname);
|
||||
|
||||
keyFile.set_string ("General", "MD5", md5);
|
||||
keyFile.set_integer ("General", "Version", options.version);
|
||||
|
@@ -98,9 +98,9 @@ Thumbnail* CacheManager::getEntry (const Glib::ustring& fname) {
|
||||
}
|
||||
delete cfs;
|
||||
}
|
||||
|
||||
// if not, create a new one
|
||||
if (!res) {
|
||||
|
||||
res = new Thumbnail (this, fname, md5);
|
||||
if (!res->isSupported ()) {
|
||||
delete res;
|
||||
@@ -241,15 +241,9 @@ void CacheManager::clearThumbImages () {
|
||||
deleteDir ("images");
|
||||
deleteDir ("aehistograms");
|
||||
deleteDir ("embprofiles");
|
||||
|
||||
// re-generate thumbnail images of open thumbnails
|
||||
//string_thumb_map::iterator i;
|
||||
//for (i=openEntries.begin(); i!=openEntries.end(); i++)
|
||||
// i->second->generateThumbnailImage ();
|
||||
}
|
||||
|
||||
void CacheManager::clearProfiles () {
|
||||
|
||||
Glib::Mutex::Lock lock(mutex_);
|
||||
|
||||
deleteDir ("profiles");
|
||||
|
@@ -39,6 +39,7 @@ Resize::Resize () : maxw(100000), maxh(100000) {
|
||||
method->append_text (M("TP_RESIZE_BICUBICSH"));
|
||||
method->append_text (M("TP_RESIZE_DOWNSCALEB"));
|
||||
method->append_text (M("TP_RESIZE_DOWNSCALEF"));
|
||||
method->append_text (M("TP_RESIZE_LANCZOS"));
|
||||
method->set_active (0);
|
||||
|
||||
combos->attach (*Gtk::manage (new Gtk::Label (M("TP_RESIZE_METHOD"))), 0, 1, 0, 1, Gtk::SHRINK, Gtk::SHRINK, 2, 2);
|
||||
@@ -130,6 +131,8 @@ void Resize::read (const ProcParams* pp, const ParamsEdited* pedited) {
|
||||
method->set_active (5);
|
||||
else if (pp->resize.method == "Downscale (Faster)")
|
||||
method->set_active (6);
|
||||
else if (pp->resize.method == "Lanczos")
|
||||
method->set_active (7);
|
||||
|
||||
wDirty = false;
|
||||
hDirty = false;
|
||||
@@ -170,6 +173,8 @@ void Resize::write (ProcParams* pp, ParamsEdited* pedited) {
|
||||
pp->resize.method = "Downscale (Better)";
|
||||
else if (method->get_active_row_number() == 6)
|
||||
pp->resize.method = "Downscale (Faster)";
|
||||
else if (method->get_active_row_number() == 7)
|
||||
pp->resize.method = "Lanczos";
|
||||
|
||||
pp->resize.dataspec = spec->get_active_row_number();
|
||||
pp->resize.width = round (w->get_value ());
|
||||
|
@@ -131,13 +131,7 @@ void Thumbnail::_generateThumbnailImage () {
|
||||
generateExifDateTimeStrings ();
|
||||
}
|
||||
|
||||
void Thumbnail::generateThumbnailImage () {
|
||||
Glib::Mutex::Lock lock(mutex);
|
||||
_generateThumbnailImage();
|
||||
}
|
||||
|
||||
bool Thumbnail::isSupported () {
|
||||
|
||||
return cfs.supported;
|
||||
}
|
||||
|
||||
|
@@ -98,8 +98,6 @@ class Thumbnail {
|
||||
void getThumbnailSize (int &w, int &h);
|
||||
void getFinalSize (const rtengine::procparams::ProcParams& pparams, int& w, int& h) { if (tpp) tpp->getFinalSize (pparams, w, h); }
|
||||
|
||||
void generateThumbnailImage ();
|
||||
|
||||
const Glib::ustring& getExifString ();
|
||||
const Glib::ustring& getDateTimeString ();
|
||||
void getCamWB (double& temp, double& green) { if (tpp) tpp->getCamWB (temp, green); }
|
||||
|
Reference in New Issue
Block a user