diff --git a/src/finish.cpp b/src/finish.cpp index b6d3244..fc4e81b 100644 --- a/src/finish.cpp +++ b/src/finish.cpp @@ -1,7 +1,208 @@ #include // all opencv header #include "hdrplus/finish.h" +#include + +// #include namespace hdrplus { + // void normalize(cv::Mat& A,int opencvType){ + // std::cout< it, end; + for( it = ans.begin(), end = ans.end(); it != end; ++it) + { + // std::cout<1){ + x = 1; + } + } + + x*=USHRT_MAX; + + return (uint16_t)x; + } + + uint16_t uGammaDecompress_1pix(float x, float threshold,float gainMin,float gainMax,float exponent){ + // Normalize pixel val + x/=65535.0; + // check the val against the threshold + if(x<=threshold){ + x = x/gainMin; + }else{ + x = pow((x+gainMax-1)/gainMax,exponent); + } + // clip + if(x<0){ + x=0; + }else{ + if(x>1){ + x = 1; + } + } + x*=65535; + + return (uint16_t)x; + } + + cv::Mat uGammaCompress_(cv::Mat m,float threshold,float gainMin,float gainMax,float exponent){ + cv::MatIterator_ it, end; + for( it = m.begin(), end = m.end(); it != end; ++it) + { + (*it)[0] =uGammaCompress_1pix((*it)[0],threshold,gainMin,gainMax,exponent); + (*it)[1] =uGammaCompress_1pix((*it)[1],threshold,gainMin,gainMax,exponent); + (*it)[2] =uGammaCompress_1pix((*it)[2],threshold,gainMin,gainMax,exponent); + } + return m; + } + + cv::Mat uGammaDecompress_(cv::Mat m,float threshold,float gainMin,float gainMax,float exponent){ + cv::MatIterator_ it, end; + for( it = m.begin(), end = m.end(); it != end; ++it) + { + (*it)[0] =uGammaDecompress_1pix((*it)[0],threshold,gainMin,gainMax,exponent); + (*it)[1] =uGammaDecompress_1pix((*it)[1],threshold,gainMin,gainMax,exponent); + (*it)[2] =uGammaDecompress_1pix((*it)[2],threshold,gainMin,gainMax,exponent); + } + return m; + } + + cv::Mat gammasRGB(cv::Mat img, bool mode){ + if(mode){// compress + return uGammaCompress_(img,0.0031308, 12.92, 1.055, 1. / 2.4); + }else{ // decompress + return uGammaDecompress_(img, 0.04045, 12.92, 1.055, 2.4); + } + } + + void Finish::pipeline_finish(){ + // copy mergedBayer to rawReference + std::cout<<"finish pipeline start ..."<libraw_processor,params.rawpyArgs); + +// write reference image + if(params.flags["writeReferenceImage"]){ + std::cout<<"writing reference img ..."<& libraw_ptr, cv::Mat B){ + u_int16_t* ptr_A = (u_int16_t*)libraw_ptr->imgdata.rawdata.raw_image; + u_int16_t* ptr_B = (u_int16_t*)B.data; + for(int r = 0; r < B.rows; r++) { + for(int c = 0; c < B.cols; c++) { + *(ptr_A+r*B.cols+c) = *(ptr_B+r*B.cols+c); + } + } + + } + + // cv::Mat Finish::postprocess(std::shared_ptr& libraw_ptr){ + // std::cout<<"postprocessing..."<dcraw_process(); + // int errorcode; + + // libraw_processed_image_t *ret_img = libraw_ptr->dcraw_make_mem_image(&errorcode); + + // // std::cout<<"ret_img height = "<height<libraw_processor,mergedBayer); + // // rawReference = cv::Mat( rawReference.rows, rawReference.cols, CV_16U, refBayer->libraw_processor->imgdata.rawdata.raw_image ); + // // showImg(rawReference); + // if(params.flags["writeReferenceImage"]){ + // std::cout<<"process reference img ..."<libraw_processor,params.rawpyArgs); + // //normalize(processedImage,CV_16UC1); + // std::cout<<"processedImage.rows = "<