From 5b455702a2ca597e83a87dcd2b0ba4e4f0751b25 Mon Sep 17 00:00:00 2001 From: heckflosse Date: Sun, 6 Nov 2016 16:42:20 +0100 Subject: [PATCH] pixelshift: Fixed a bug, cleaned code, parallel decode of frames --- rtengine/dfmanager.cc | 11 +++---- rtengine/ffmanager.cc | 12 +++----- rtengine/pixelshift.cc | 24 +++------------ rtengine/rawimage.cc | 4 +-- rtengine/rawimage.h | 3 +- rtengine/rawimagesource.cc | 62 +++++++++++++++++++++----------------- rtengine/rawimagesource.h | 1 - 7 files changed, 51 insertions(+), 66 deletions(-) diff --git a/rtengine/dfmanager.cc b/rtengine/dfmanager.cc index 1dedf661f..ab76ff854 100644 --- a/rtengine/dfmanager.cc +++ b/rtengine/dfmanager.cc @@ -138,8 +138,7 @@ void dfInfo::updateRawImage() std::list::iterator iName = pathNames.begin(); ri = new RawImage(*iName); // First file used also for extra pixels informations (width,height, shutter, filters etc.. ) - unsigned int imageNum = 0; - if( ri->loadRaw(true, imageNum)) { + if( ri->loadRaw(true)) { delete ri; ri = nullptr; } else { @@ -164,7 +163,7 @@ void dfInfo::updateRawImage() for( ++iName; iName != pathNames.end(); ++iName) { RawImage* temp = new RawImage(*iName); - if( !temp->loadRaw(true,imageNum)) { + if( !temp->loadRaw(true)) { temp->compress_image(); //\ TODO would be better working on original, because is temporary nFiles++; @@ -200,9 +199,8 @@ void dfInfo::updateRawImage() } } else { ri = new RawImage(pathname); - unsigned int imageNum = 0; - if( ri->loadRaw(true,imageNum)) { + if( ri->loadRaw(true)) { delete ri; ri = nullptr; } else { @@ -367,8 +365,7 @@ dfInfo* DFManager::addFileInfo (const Glib::ustring& filename, bool pool) } RawImage ri (filename); - unsigned int imageNum = 0; - int res = ri.loadRaw (false, imageNum); // Read informations about shot + int res = ri.loadRaw (false); // Read informations about shot if (res != 0) { return nullptr; diff --git a/rtengine/ffmanager.cc b/rtengine/ffmanager.cc index 42a46802b..7dd9140a1 100644 --- a/rtengine/ffmanager.cc +++ b/rtengine/ffmanager.cc @@ -130,8 +130,7 @@ void ffInfo::updateRawImage() if( !pathNames.empty() ) { std::list::iterator iName = pathNames.begin(); ri = new RawImage(*iName); // First file used also for extra pixels informations (width,height, shutter, filters etc.. ) - unsigned int imageNum = 0; - if( ri->loadRaw(true, imageNum)) { + if( ri->loadRaw(true)) { delete ri; ri = nullptr; } else { @@ -156,7 +155,7 @@ void ffInfo::updateRawImage() for( ++iName; iName != pathNames.end(); ++iName) { RawImage* temp = new RawImage(*iName); - if( !temp->loadRaw(true,imageNum)) { + if( !temp->loadRaw(true)) { temp->compress_image(); //\ TODO would be better working on original, because is temporary nFiles++; @@ -192,9 +191,7 @@ void ffInfo::updateRawImage() } } else { ri = new RawImage(pathname); - unsigned int imageNum = 0; - - if( ri->loadRaw(true, imageNum)) { + if( ri->loadRaw(true)) { delete ri; ri = nullptr; } else { @@ -327,8 +324,7 @@ ffInfo* FFManager::addFileInfo (const Glib::ustring& filename, bool pool) RawImage ri (filename); - unsigned int imageNum = 0; - int res = ri.loadRaw (false, imageNum); // Read informations about shot + int res = ri.loadRaw (false); // Read informations about shot if (res != 0) { return nullptr; diff --git a/rtengine/pixelshift.cc b/rtengine/pixelshift.cc index 944fc9790..20f27294a 100644 --- a/rtengine/pixelshift.cc +++ b/rtengine/pixelshift.cc @@ -1,6 +1,7 @@ //////////////////////////////////////////////////////////////// // -// pixelshift +// simple pentax pixelshift algorithm +// copyright (c) Ingo Weyrich 2016 // // // pixelshift.cc is free software: you can redistribute it and/or modify @@ -23,7 +24,7 @@ #include "../rtgui/multilangmgr.h" #include "procparams.h" #include "opthelper.h" -#define BENCHMARK +//#define BENCHMARK #include "StopWatch.h" using namespace std; using namespace rtengine; @@ -35,18 +36,16 @@ BENCHFUN double progress = 0.0; const bool plistenerActive = plistener; - //int winx=0, winy=0; - //int winw=W, winh=H; - if (plistener) { plistener->setProgressStr (Glib::ustring::compose(M("TP_RAW_DMETHOD_PROGRESSBAR"), RAWParams::BayerSensor::methodstring[RAWParams::BayerSensor::pixelshift_simple])); plistener->setProgress (progress); } - const int bord = 2; +#ifdef _OPENMP #pragma omp parallel for +#endif for(int i = bord; i < winh - bord; ++i) { for(int j = bord; j< winw - bord; ++j) { int c = FC(i,j); @@ -71,23 +70,10 @@ BENCHFUN } } -// if(plistenerActive && ((++progressCounter) % 16 == 0)) { -//#ifdef _OPENMP -// #pragma omp critical (updateprogress) -//#endif -// { -// progress += progressInc; -// progress = min(1.0, progress); -// plistener->setProgress (progress); -// } -// } - if(plistenerActive) { plistener->setProgress(1.00); } - - } #undef TS #undef CLF diff --git a/rtengine/rawimage.cc b/rtengine/rawimage.cc index 43b829148..f4a412ca5 100644 --- a/rtengine/rawimage.cc +++ b/rtengine/rawimage.cc @@ -398,7 +398,7 @@ skip_block: } } -int RawImage::loadRaw (bool loadData, unsigned int &imageNum, bool closeFile, ProgressListener *plistener, double progressRange) +int RawImage::loadRaw (bool loadData, unsigned int imageNum, bool closeFile, ProgressListener *plistener, double progressRange) { ifname = filename.c_str(); image = nullptr; @@ -426,10 +426,8 @@ int RawImage::loadRaw (bool loadData, unsigned int &imageNum, bool closeFile, Pr shot_select = imageNum; identify(); - std::cout << "israw : " << is_raw << std::endl; // in case dcraw didn't handle the above mentioned case... shot_select = std::min(shot_select, std::max(is_raw, 1u) - 1); - imageNum = shot_select; if (!is_raw) { fclose(ifp); diff --git a/rtengine/rawimage.h b/rtengine/rawimage.h index 4080702a6..cb9e9100e 100644 --- a/rtengine/rawimage.h +++ b/rtengine/rawimage.h @@ -106,7 +106,7 @@ public: explicit RawImage( const Glib::ustring &name ); ~RawImage(); - int loadRaw (bool loadData, unsigned int &imageNum, bool closeFile = true, ProgressListener *plistener = nullptr, double progressRange = 1.0); + int loadRaw (bool loadData, unsigned int imageNum = 0, bool closeFile = true, ProgressListener *plistener = nullptr, double progressRange = 1.0); void get_colorsCoeff( float* pre_mul_, float* scale_mul_, float* cblack_, bool forceAutoWB ); void set_prefilters() { @@ -122,6 +122,7 @@ public: float** compress_image(); // revert to compressed pixels format and release image data float** data; // holds pixel values, data[i][j] corresponds to the ith row and jth column unsigned prefilters; // original filters saved ( used for 4 color processing ) + unsigned int getFrameCount() const { return is_raw; } protected: Glib::ustring filename; // complete filename int rotate_deg; // 0,90,180,270 degree of rotation: info taken by dcraw from exif diff --git a/rtengine/rawimagesource.cc b/rtengine/rawimagesource.cc index 4ebbd5dc6..37cf2618e 100644 --- a/rtengine/rawimagesource.cc +++ b/rtengine/rawimagesource.cc @@ -1505,47 +1505,52 @@ int RawImageSource::load (const Glib::ustring &fname, int imageNum, bool batch) plistener->setProgressStr ("Decoding..."); plistener->setProgress (0.0); } - -StopWatch Stop1("loadraw"); - unsigned int tempImageNum = 256; - // requesting a subimage which is not available gives subimage 0. We use 256 to access a non existent frame resulting in frame 0 +StopWatch Stop1("decode"); ri = new RawImage(fname); - int errCode = ri->loadRaw (true, tempImageNum, true, plistener, 0.8); - // now tempImageNum is adjusted to the number of last frame + int errCode = ri->loadRaw (false, 0, false); if (errCode) { return errCode; } - ri->compress_image(); - ri->set_prefilters(); - riFrames[0] = ri; - numFrames ++; + numFrames = ri->getFrameCount(); - while (tempImageNum) { - numFrames ++; - ri = new RawImage(fname); - int errCode = ri->loadRaw (true, tempImageNum, true, plistener, 0.8); - std::cout << "imagenum : " << tempImageNum << " width : " << ri->get_width() << " height : " << ri->get_height() << std::endl; - - if (errCode) { - return errCode; + errCode = 0; +#ifdef _OPENMP +#pragma omp parallel if(numFrames > 1) +#endif +{ + int errCodeThr = 0; +#ifdef _OPENMP +#pragma omp for +#endif + for(unsigned int i = 0; i < numFrames; ++i) { + if(i == 0) { + riFrames[i] = ri; + errCodeThr = riFrames[i]->loadRaw (true, i, true, plistener, 0.8); + } else { + riFrames[i] = new RawImage(fname); + errCodeThr = riFrames[i]->loadRaw (true, i); } - riFrames[tempImageNum] = ri; - ri->compress_image(); - ri->set_prefilters(); - tempImageNum --; + riFrames[i]->compress_image(); } +#ifdef _OPENMP +#pragma omp critical +#endif +{ + errCode = errCodeThr ? errCodeThr : errCode; +} +} + if(errCode) { + return errCode; + } +Stop1.stop(); if(numFrames > 1 ) { // this disables multi frame support for Fuji S5 until I found a solution to handle different dimensions if(riFrames[0]->get_width() != riFrames[1]->get_width() || riFrames[0]->get_height() != riFrames[1]->get_height()) { numFrames = 1; } } -std::cout << "numframes : " << numFrames << std::endl; - - ri = riFrames[0]; -Stop1.stop(); if (plistener) { plistener->setProgress (0.9); } @@ -1657,6 +1662,9 @@ Stop1.stop(); initialGain = 1.0 / min(pre_mul[0], pre_mul[1], pre_mul[2]); }*/ + for(unsigned int i=0;i < numFrames; ++i) { + riFrames[i]->set_prefilters(); + } //Load complete Exif informations @@ -1953,7 +1961,7 @@ void RawImageSource::demosaic(const RAWParams &raw) if(numFrames == 4) { pixelshift_simple(0, 0, W, H); scaleColors_pixelshift( 0, 0, W, H, raw); - } else { + } else { // for non pixelshift files use amaze if pixelshift is selected amaze_demosaic_RT (0, 0, W, H); } } else if (raw.bayersensor.method == RAWParams::BayerSensor::methodstring[RAWParams::BayerSensor::dcb] ) { diff --git a/rtengine/rawimagesource.h b/rtengine/rawimagesource.h index abf1f6b97..560314802 100644 --- a/rtengine/rawimagesource.h +++ b/rtengine/rawimagesource.h @@ -203,7 +203,6 @@ public: void setCurrentFrame(unsigned int frameNum) { currFrame = std::min(numFrames - 1, frameNum); ri = riFrames[currFrame]; - std::cout << "currFrame : " << currFrame << std::endl; } protected: typedef unsigned short ushort;