refactored code for extracting image dimensions from metadata
(cherry picked from commit 0ece9c5bfad09bc9052238d83fa696ef39effaaa)
This commit is contained in:
parent
0102fca563
commit
92befa7e81
@ -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;
|
||||
}
|
||||
|
@ -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);
|
||||
};
|
||||
|
||||
}
|
||||
|
@ -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;
|
||||
|
@ -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);
|
||||
|
||||
|
@ -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();
|
||||
@ -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;
|
||||
|
@ -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);
|
||||
|
@ -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 */
|
||||
|
@ -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)
|
||||
{
|
||||
}
|
||||
|
||||
|
@ -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);
|
||||
|
@ -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);
|
||||
|
@ -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;
|
||||
}
|
||||
};
|
||||
|
@ -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,
|
||||
|
@ -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;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user