refactored code for extracting image dimensions from metadata

(cherry picked from commit 0ece9c5bfad09bc9052238d83fa696ef39effaaa)
This commit is contained in:
Alberto Griggio 2020-12-02 02:03:00 -08:00 committed by Lawrence Lee
parent 0102fca563
commit 92befa7e81
No known key found for this signature in database
GPG Key ID: 048FF2B76A63895F
13 changed files with 146 additions and 21 deletions

View File

@ -81,7 +81,9 @@ FramesData::FramesData(const Glib::ustring &fname) :
lens("Unknown"),
sampleFormat(IIOSF_UNKNOWN),
isPixelShift(false),
isHDR(false)
isHDR(false),
w_(-1),
h_(-1)
{
make.clear();
model.clear();
@ -374,6 +376,8 @@ FramesData::FramesData(const Glib::ustring &fname) :
}
}
meta.getDimensions(w_, h_);
// -----------------------
// Special file type detection (HDR, PixelShift)
// ------------------------
@ -773,3 +777,17 @@ void FramesData::fillBasicTags(Exiv2::ExifData &exif) const
strftime(buf, 256, "%Y:%m:%d %H:%M:%S", &t);
set_exif(exif, "Exif.Photo.DateTimeOriginal", buf);
}
void FramesData::getDimensions(int &w, int &h) const
{
w = w_;
h = h_;
}
void FramesData::setDimensions(int w, int h)
{
w_ = w;
h_ = h;
}

View File

@ -57,6 +57,8 @@ private:
IIOSampleFormat sampleFormat;
bool isPixelShift;
bool isHDR;
int w_;
int h_;
public:
explicit FramesData(const Glib::ustring& fname);
@ -84,8 +86,11 @@ public:
std::string getOrientation() const override;
Glib::ustring getFileName() const override;
int getRating() const override;
void getDimensions(int &w, int &h) const override;
void fillBasicTags(Exiv2::ExifData &exif) const;
void setDimensions(int w, int h);
};
}

View File

@ -448,6 +448,29 @@ void Exiv2Metadata::setExifKeys(const std::vector<std::string> *keys)
}
void Exiv2Metadata::getDimensions(int &w, int &h) const
{
if (image_) {
if (dynamic_cast<const Exiv2::XmpSidecar *>(image_.get())) {
auto &exif = image_->exifData();
auto itw = exif.findKey(Exiv2::ExifKey("Exif.Image.ImageWidth"));
auto ith = exif.findKey(Exiv2::ExifKey("Exif.Image.ImageLength"));
if (itw != exif.end() && ith != exif.end()) {
w = itw->toLong();
h = ith->toLong();
} else {
w = h = -1;
}
} else {
w = image_->pixelWidth();
h = image_->pixelHeight();
}
} else {
w = h = -1;
}
}
Glib::ustring Exiv2Metadata::xmpSidecarPath(const Glib::ustring &path)
{
Glib::ustring fn = path;

View File

@ -58,6 +58,8 @@ public:
void setExifKeys(const std::vector<std::string> *keys);
void getDimensions(int &w, int &h) const;
static Glib::ustring xmpSidecarPath(const Glib::ustring& path);
static Exiv2::XmpData getXmpSidecar(const Glib::ustring& path);

View File

@ -690,7 +690,7 @@ void RawImageSource::getImage (const ColorTemp &ctemp, int tran, Imagefloat* ima
{
MyMutex::MyLock lock(getImageMutex);
tran = defTransform (tran);
tran = defTransform(ri, tran);
// compute channel multipliers
double r, g, b;
@ -1009,8 +1009,41 @@ void RawImageSource::convertColorSpace(Imagefloat* image, const ColorManagementP
void RawImageSource::getFullSize (int& w, int& h, int tr)
{
computeFullSize(ri, tr, w, h);
tr = defTransform (tr);
// tr = defTransform(ri, tr);
// if (fuji) {
// w = ri->get_FujiWidth() * 2 + 1;
// h = (H - ri->get_FujiWidth()) * 2 + 1;
// } else if (d1x) {
// w = W;
// h = 2 * H;
// } else {
// w = W;
// h = H;
// }
// if ((tr & TR_ROT) == TR_R90 || (tr & TR_ROT) == TR_R270) {
// int tmp = w;
// w = h;
// h = tmp;
// }
// w -= 2 * border;
// h -= 2 * border;
}
void RawImageSource::computeFullSize(const RawImage *ri, int tr, int &w, int &h)
{
tr = defTransform(ri, tr);
const int W = ri->get_width();
const int H = ri->get_height();
const bool fuji = ri->get_FujiWidth() != 0;
const bool d1x = !ri->get_model().compare("D1X");
const int border = (ri->getSensorType() == ST_BAYER ? 4 : (ri->getSensorType() == ST_FUJI_XTRANS ? 7 : 0));
if (fuji) {
w = ri->get_FujiWidth() * 2 + 1;
@ -1253,6 +1286,11 @@ int RawImageSource::load (const Glib::ustring &fname, bool firstFrameOnly)
// Load complete Exif information
idata = new FramesData(fname); // TODO: std::unique_ptr<>
idata->setDCRawFrameCount (numFrames);
{
int ww, hh;
getFullSize(ww, hh);
idata->setDimensions(ww, hh);
}
green(W, H);
red(W, H);
@ -2718,7 +2756,7 @@ void RawImageSource::scaleColors(int winx, int winy, int winw, int winh, const R
//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
int RawImageSource::defTransform (int tran)
int RawImageSource::defTransform(const RawImage *ri, int tran)
{
int deg = ri->get_rotateDegree();
@ -4466,7 +4504,7 @@ void RawImageSource::ItcWB(bool extra, double &tempref, double &greenref, double
Probably (sure) there are improvement to do...
I have create a table temperature with temp and white point with 118 values between 2000K and 12000K we can obviously change these values, more...with different steps
I have create a table for tint (green)with 134 values between 0.4 to 4.
I have create a table for tint (green)with 134 values between 0.4 to 4.
I have create or recuparate and transformed 201 spectral colors from Colorchecker24, others color and my 468 colors target, or from web flowers, etc. with a step of 5nm, I think it is large enough.
I think this value of 201 is now complete: I tested correlation with 60, 90, 100, 120, 155...better student increase with number of color, but now it seems stabilized
Of course we can increase this number :)
@ -4519,7 +4557,7 @@ void RawImageSource::ItcWB(bool extra, double &tempref, double &greenref, double
itcwb_precis : 5 by default - can be set to 3 or 9 - 3 best sampling but more time...9 "old" settings - but low differences in times with 3 instead of 9 about twice time 160ms instead of 80ms for a big raw file
*/
// BENCHFUN
TMatrix wprof = ICCStore::getInstance()->workingSpaceMatrix("sRGB");
const float wp[3][3] = {
{static_cast<float>(wprof[0][0]), static_cast<float>(wprof[0][1]), static_cast<float>(wprof[0][2])},
@ -5064,7 +5102,7 @@ void RawImageSource::ItcWB(bool extra, double &tempref, double &greenref, double
}
estimchrom /= sizcu4;
if (settings->verbose) {
if (settings->verbose) {
printf("estimchrom=%f\n", estimchrom);
}
if (settings->itcwb_sort) { //sort in ascending with chroma values
@ -5366,7 +5404,7 @@ void RawImageSource::getrgbloc(int begx, int begy, int yEn, int xEn, int cx, int
if (settings->itcwb_precis == 5) {
precision = 5;
} else if (settings->itcwb_precis < 5) {
precision = 3;
precision = 3;
} else if (settings->itcwb_precis > 5) {
precision = 9;
}
@ -5628,11 +5666,11 @@ void RawImageSource::getAutoWBMultipliersitc(double & tempref, double & greenref
if (settings->itcwb_precis == 5) {
precision = 5;
} else if (settings->itcwb_precis < 5) {
precision = 3;
precision = 3;
} else if (settings->itcwb_precis > 5) {
precision = 9;
}
const int bfw = W / precision + ((W % precision) > 0 ? 1 : 0);// 5 arbitrary value can be change to 3 or 9 ;
const int bfh = H / precision + ((H % precision) > 0 ? 1 : 0);
WBauto(tempref, greenref, redloc, greenloc, blueloc, bfw, bfh, avg_rm, avg_gm, avg_bm, tempitc, greenitc, studgood, twotimes, wbpar, begx, begy, yEn, xEn, cx, cy, cmp, raw);
@ -6093,7 +6131,7 @@ ColorTemp RawImageSource::getSpotWB (std::vector<Coord2D> &red, std::vector<Coor
void RawImageSource::transformPosition (int x, int y, int tran, int& ttx, int& tty)
{
tran = defTransform (tran);
tran = defTransform(ri, tran);
x += border;
y += border;

View File

@ -46,7 +46,7 @@ private:
static LUTf invGrad; // for fast_demosaic
static LUTf initInvGrad ();
static void colorSpaceConversion_ (Imagefloat* im, const procparams::ColorManagementParams& cmp, const ColorTemp &wb, double pre_mul[3], cmsHPROFILE embedded, cmsHPROFILE camprofile, double cam[3][3], const std::string &camName);
int defTransform (int tran);
static int defTransform (const RawImage *ri, int tran);
protected:
MyMutex getImageMutex; // locks getImage
@ -228,6 +228,8 @@ public:
virtual float operator()(int row) const { return 1.f; }
};
static void computeFullSize(const RawImage *ri, int tr, int &w, int &h);
protected:
typedef unsigned short ushort;
void processFalseColorCorrection(Imagefloat* i, const int steps);

View File

@ -157,6 +157,7 @@ public:
static FramesMetaData* fromFile(const Glib::ustring& fname);
virtual Glib::ustring getFileName() const = 0;
virtual void getDimensions(int &w, int &h) const = 0;
};
/** This listener interface is used to indicate the progress of time consuming operations */
@ -371,7 +372,7 @@ public :
virtual void adapCamChanged(double cadap) = 0;
virtual void ybCamChanged(int yb) = 0;
virtual void wbCamChanged(double tem, double tin) = 0;
};
class AutoChromaListener
@ -574,7 +575,7 @@ public:
virtual void getCamWB (double& temp, double& green) = 0;
virtual void getSpotWB (int x, int y, int rectSize, double& temp, double& green) = 0;
virtual bool getFilmNegativeSpot(int x, int y, int spotSize, procparams::FilmNegativeParams::RGB &refInput, procparams::FilmNegativeParams::RGB &refOutput) = 0;
virtual void getAutoCrop (double ratio, int &x, int &y, int &w, int &h) = 0;
virtual void saveInputICCReference (const Glib::ustring& fname, bool apply_wb) = 0;

View File

@ -968,6 +968,9 @@ Thumbnail* Thumbnail::loadFromRaw (const Glib::ustring& fname, eSensorType &sens
}
tpp->init();
RawImageSource::computeFullSize(ri, TR_NONE, tpp->full_width, tpp->full_height);
delete ri;
return tpp;
}
@ -1025,7 +1028,9 @@ Thumbnail::Thumbnail () :
gammaCorrected (false),
colorMatrix{},
scaleGain (1.0),
isRaw (true)
isRaw (true),
full_width(-1),
full_height(-1)
{
}
@ -1236,7 +1241,7 @@ IImage8* Thumbnail::processImage (const procparams::ProcParams& params, eSensorT
ipf.dehaze(baseImg, params.dehaze);
ipf.ToneMapFattal02(baseImg, params.fattal, 3, 0, nullptr, 0, 0, 0);
// perform transform
int origFW;
int origFH;
@ -2125,7 +2130,7 @@ bool Thumbnail::readData (const Glib::ustring& fname)
colorMatrix[i][j] = cm[ix++];
}
}
if (keyFile.has_key ("LiveThumbData", "ScaleGain")) {
scaleGain = keyFile.get_double ("LiveThumbData", "ScaleGain");
}

View File

@ -82,6 +82,8 @@ class Thumbnail
public:
bool isRaw;
int full_width;
int full_height;
~Thumbnail ();
Thumbnail ();
@ -94,7 +96,7 @@ public:
void getDimensions (int& w, int& h, double& scaleFac);
static Thumbnail* loadQuickFromRaw (const Glib::ustring& fname, eSensorType &sensorType, int &w, int &h, int fixwh, bool rotate, bool inspectorMode = false, bool forHistogramMatching = false);
static Thumbnail* loadFromRaw (const Glib::ustring& fname, eSensorType &sensorType, int &w, int &h, int fixwh, double wbEq, bool rotate, bool forHistogramMatching = false);
static Thumbnail* loadFromRaw (const Glib::ustring& fname, eSensorType &sensorType, int &w, int &h, int fixwh, double wbEq, bool rotate, bool forHistogramMatching=false);
static Thumbnail* loadFromImage (const Glib::ustring& fname, int &w, int &h, int fixwh, double wbEq, bool inspectorMode = false);
void getCamWB (double& temp, double& green);

View File

@ -56,7 +56,9 @@ CacheImageData::CacheImageData() :
greenAWBMul(-1.0),
blueAWBMul(-1.0),
rotate(0),
thumbImgType(0)
thumbImgType(0),
width(-1),
height(-1)
{
}
@ -208,6 +210,12 @@ int CacheImageData::load (const Glib::ustring& fname)
if (keyFile.has_key ("FileInfo", "SampleFormat")) {
sampleFormat = (rtengine::IIO_Sample_Format)keyFile.get_integer ("FileInfo", "SampleFormat");
}
if (keyFile.has_key("FileInfo", "Width")) {
width = keyFile.get_integer("FileInfo", "Width");
}
if (keyFile.has_key("FileInfo", "Height")) {
height = keyFile.get_integer("FileInfo", "Height");
}
}
if (format == FT_Raw && keyFile.has_group ("ExtraRawInfo")) {
@ -298,6 +306,8 @@ int CacheImageData::save (const Glib::ustring& fname)
keyFile.set_string ("FileInfo", "Filetype", filetype);
keyFile.set_integer ("FileInfo", "FrameCount", frameCount);
keyFile.set_integer ("FileInfo", "SampleFormat", sampleFormat);
keyFile.set_integer("FileInfo", "Width", width);
keyFile.set_integer("FileInfo", "Height", height);
if (format == FT_Raw) {
keyFile.set_integer ("ExtraRawInfo", "ThumbImageType", thumbImgType);

View File

@ -80,6 +80,9 @@ public:
QUICK_THUMBNAIL = 1 // was the thumbnail generated from embedded jpeg
};
int width;
int height;
CacheImageData ();
int load (const Glib::ustring& fname);
@ -110,4 +113,9 @@ public:
bool getHDR() const override { return isHDR; }
std::string getImageType() const override { return isPixelShift ? "PS" : isHDR ? "HDR" : "STD"; }
rtengine::IIOSampleFormat getSampleFormat() const override { return sampleFormat; }
void getDimensions(int &w, int &h) const override
{
w = width;
h = height;
}
};

View File

@ -1357,8 +1357,13 @@ void EditorPanel::info_toggled ()
escapeHtmlChars (Glib::path_get_dirname (openThm->getFileName())) + G_DIR_SEPARATOR_S,
escapeHtmlChars (Glib::path_get_basename (openThm->getFileName())) );
int ww = ipc->getFullWidth();
int hh = ipc->getFullHeight();
int ww = -1, hh = -1;
idata->getDimensions(ww, hh);
if (ww <= 0) {
ww = ipc->getFullWidth();
hh = ipc->getFullHeight();
}
//megapixels
infoString = Glib::ustring::compose ("%1\n<span size=\"small\">%2 MP (%3x%4)</span>",
infoString,

View File

@ -241,6 +241,10 @@ void Thumbnail::_generateThumbnailImage ()
cfs.format = FT_Raw;
cfs.thumbImgType = quick ? CacheImageData::QUICK_THUMBNAIL : CacheImageData::FULL_THUMBNAIL;
infoFromImage (fname);
if (!quick) {
cfs.width = tpp->full_width;
cfs.height = tpp->full_height;
}
}
}
@ -893,6 +897,8 @@ int Thumbnail::infoFromImage (const Glib::ustring& fname)
cfs.filetype = "";
}
idata->getDimensions(cfs.width, cfs.height);
delete idata;
return deg;
}