Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

random cleanups #3169

Merged
merged 15 commits into from
Feb 21, 2025
6 changes: 3 additions & 3 deletions include/exiv2/orfimage.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,9 @@ class EXIV2API OrfImage : public TiffImage {

//! @name Accessors
//@{
std::string mimeType() const override;
uint32_t pixelWidth() const override;
uint32_t pixelHeight() const override;
[[nodiscard]] std::string mimeType() const override;
[[nodiscard]] uint32_t pixelWidth() const override;
[[nodiscard]] uint32_t pixelHeight() const override;
//@}
}; // class OrfImage

Expand Down
8 changes: 4 additions & 4 deletions include/exiv2/tiffimage.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,16 +63,16 @@ class EXIV2API TiffImage : public Image {

//! @name Accessors
//@{
std::string mimeType() const override;
uint32_t pixelWidth() const override;
uint32_t pixelHeight() const override;
[[nodiscard]] std::string mimeType() const override;
[[nodiscard]] uint32_t pixelWidth() const override;
[[nodiscard]] uint32_t pixelHeight() const override;
//@}

private:
//! @name Accessors
//@{
//! Return the group name of the group with the primary image.
std::string primaryGroup() const;
[[nodiscard]] std::string primaryGroup() const;
//@}

// DATA
Expand Down
1 change: 0 additions & 1 deletion include/exiv2/value.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -1481,7 +1481,6 @@ template <typename T>
ValueType<T>& ValueType<T>::operator=(const ValueType<T>& rhs) {
if (this == &rhs)
return *this;
Value::operator=(rhs);
value_ = rhs.value_;

byte* tmp = nullptr;
Expand Down
28 changes: 16 additions & 12 deletions samples/geotag.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ namespace fs = std::filesystem;
#define _MAX_PATH 1024
#endif

namespace {
// prototypes
class Options;
int getFileType(const char* path, Options& options);
Expand Down Expand Up @@ -109,7 +110,9 @@ class Position final {
}

Position() = default;
virtual ~Position() = default;
~Position() = default;
Position(const Position&) = default;
Position& operator=(const Position&) = default;

// instance methods
[[nodiscard]] bool good() const {
Expand Down Expand Up @@ -260,7 +263,7 @@ struct UserData final {
};

// XML Parser Callbacks
static void startElement(void* userData, const char* name, const char** atts) {
void startElement(void* userData, const char* name, const char** atts) {
auto me = static_cast<UserData*>(userData);
// for ( int i = 0 ; i < me->indent ; i++ ) printf(" ");
// printf("begin %s\n",name);
Expand All @@ -283,7 +286,7 @@ static void startElement(void* userData, const char* name, const char** atts) {
me->indent++;
}

static void endElement(void* userData, const char* name) {
void endElement(void* userData, const char* name) {
auto me = static_cast<UserData*>(userData);
me->indent--;
if (strcmp(name, "trkpt") == 0) {
Expand Down Expand Up @@ -368,7 +371,7 @@ time_t parseTime(const char* arg, bool bAdjust) {
result = mktime(&T);
}
} catch (...) {
};
}
return result;
}

Expand All @@ -380,21 +383,21 @@ int timeZoneAdjust() {
#if defined(_WIN32)
TIME_ZONE_INFORMATION TimeZoneInfo;
GetTimeZoneInformation(&TimeZoneInfo);
offset = -(((int)TimeZoneInfo.Bias + (int)TimeZoneInfo.DaylightBias) * 60);
offset = -(TimeZoneInfo.Bias + TimeZoneInfo.DaylightBias * 60);
#elif defined(__CYGWIN__)
struct tm lcopy = *localtime(&now);
time_t gmt = timegm(&lcopy); // timegm modifies lcopy
offset = (int)(((long signed int)gmt) - ((long signed int)now));
#elif defined(OS_SOLARIS) || defined(__sun__)
struct tm local = *localtime(&now);
time_t local_tt = (int)mktime(&local);
time_t time_gmt = (int)mktime(gmtime(&now));
time_t local_tt = mktime(&local);
time_t time_gmt = mktime(gmtime(&now));
offset = time_gmt - local_tt;
#else
struct tm local = *localtime(&now);
offset = local.tm_gmtoff;

#if EXIV2_DEBUG_MESSAGES
#ifdef EXIV2_DEBUG_MESSAGES
struct tm utc = *gmtime(&now);
printf("utc : offset = %6d dst = %d time = %s", 0, utc.tm_isdst, asctime(&utc));
printf("local: offset = %6d dst = %d time = %s", offset, local.tm_isdst, asctime(&local));
Expand Down Expand Up @@ -534,7 +537,7 @@ bool readImage(const char* path, Options& /* options */) {
bResult = !exifData.empty();
}
} catch (...) {
};
}
return bResult;
}

Expand All @@ -558,7 +561,7 @@ time_t readImageTime(const std::string& path, std::string* pS = nullptr) {
*pS = exifData[dateString].toString();
}
} catch (...) {
};
}
}

return result;
Expand Down Expand Up @@ -676,7 +679,7 @@ int parseTZ(const char* adjust) {
try {
sscanf(adjust, "%d%c%d", &h, &c, &m);
} catch (...) {
};
}

return (3600 * h) + (60 * m);
}
Expand All @@ -686,6 +689,7 @@ bool mySort(const std::string& a, const std::string& b) {
time_t B = readImageTime(b);
return (A < B);
}
} // namespace

int main(int argc, const char* argv[]) {
Exiv2::XmpParser::initialize();
Expand Down Expand Up @@ -875,7 +879,7 @@ int main(int argc, const char* argv[]) {
image->writeMetadata();
}
} catch (...) {
};
}
}
}

Expand Down
8 changes: 1 addition & 7 deletions samples/metacopy.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

class Params : public Util::Getopt {
private:
std::string optstring_;
std::string optstring_{":iecxaph"};
bool first_{true};

public:
Expand All @@ -22,12 +22,6 @@ class Params : public Util::Getopt {
std::string read_; //!< Source file
std::string write_; //!< Destination file

/*!
@brief Default constructor. Note that optstring_ is initialized here.
*/
Params() : optstring_(":iecxaph") {
}

/*!
@brief Call Getopt::getopt() with optstring, to initiate command line
argument parsing, perform consistency checks after all command line
Expand Down
9 changes: 5 additions & 4 deletions src/canonmn_int.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ static std::ostream& printCsLensTypeByMetadata(std::ostream& os, const Value& va
//! Special treatment pretty-print function for non-unique lens ids.
static std::ostream& printCsLensFFFF(std::ostream& os, const Value& value, const ExifData* metadata);

static float string_to_float(const std::string& str);
static float string_to_float(std::string_view str);

//! ModelId, tag 0x0010
constexpr TagDetails canonModelId[] = {
Expand Down Expand Up @@ -2877,7 +2877,7 @@ std::ostream& printCsLensFFFF(std::ostream& os, const Value& value, const ExifDa
* @param str string to convert
* @return float value of string
*/
float string_to_float(std::string const& str) {
float string_to_float(std::string_view str) {
float val{};
std::stringstream ss;
std::locale c_locale("C");
Expand Down Expand Up @@ -3140,10 +3140,11 @@ std::ostream& CanonMakerNote::printFiFocusDistance(std::ostream& os, const Value
if (value.typeId() != signedShort || value.count() == 0)
return os << value;

if (auto l = value.toInt64(); l == -1) {
auto l = value.toInt64();
if (l == -1) {
return os << "Infinite";
}
return os << stringFormat("{:.2f} m", value.toInt64() / 100.0);
return os << stringFormat("{:.2f} m", l / 100.0);
}

// *****************************************************************************
Expand Down
2 changes: 1 addition & 1 deletion src/cr2header_int.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ class Cr2Header : public TiffHeaderBase {
//! @name Accessors
//@{
[[nodiscard]] DataBuf write() const override;
bool isImageTag(uint16_t tag, IfdId group, const PrimaryGroups& pPrimaryGroups) const override;
[[nodiscard]] bool isImageTag(uint16_t tag, IfdId group, const PrimaryGroups& pPrimaryGroups) const override;
//@}

//! Return the address of offset2 from the start of the header
Expand Down
2 changes: 1 addition & 1 deletion src/exif.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ Exifdatum::Exifdatum(const ExifKey& key, const Value* pValue) : key_(key.clone()
value_ = pValue->clone();
}

Exifdatum::Exifdatum(const Exifdatum& rhs) : Metadatum(rhs) {
Exifdatum::Exifdatum(const Exifdatum& rhs) {
if (rhs.key_)
key_ = rhs.key_->clone(); // deep copy
if (rhs.value_)
Expand Down
4 changes: 2 additions & 2 deletions src/futils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -207,8 +207,8 @@ size_t base64decode(const char* in, char* out, size_t out_size) {

Protocol fileProtocol(const std::string& path) {
Protocol result = pFile;
const struct {
std::string name;
constexpr struct {
std::string_view name;
Protocol prot;
bool isUrl; // path.size() > name.size()
} prots[] = {
Expand Down
2 changes: 1 addition & 1 deletion src/iptc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ Iptcdatum::Iptcdatum(const IptcKey& key, const Value* pValue) : key_(key.clone()
value_ = pValue->clone();
}

Iptcdatum::Iptcdatum(const Iptcdatum& rhs) : Metadatum(rhs) {
Iptcdatum::Iptcdatum(const Iptcdatum& rhs) {
if (rhs.key_)
key_ = rhs.key_->clone(); // deep copy
if (rhs.value_)
Expand Down
4 changes: 2 additions & 2 deletions src/makernote_int.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ const TiffMnRegistry TiffMnCreator::registry_[] = {
{"-", IfdId::casio2Id, nullptr, newCasio2Mn2},
};

bool TiffMnRegistry::operator==(const std::string& key) const {
bool TiffMnRegistry::operator==(std::string_view key) const {
if (!key.empty() && key.front() == '-')
return false;
return key.starts_with(make_);
Expand All @@ -139,7 +139,7 @@ bool TiffMnRegistry::operator==(IfdId key) const {
return mnGroup_ == key;
}

std::unique_ptr<TiffComponent> TiffMnCreator::create(uint16_t tag, IfdId group, const std::string& make,
std::unique_ptr<TiffComponent> TiffMnCreator::create(uint16_t tag, IfdId group, std::string_view make,
const byte* pData, size_t size, ByteOrder byteOrder) {
if (auto tmr = Exiv2::find(registry_, make))
return tmr->newMnFct_(tag, group, tmr->mnGroup_, pData, size, byteOrder);
Expand Down
4 changes: 2 additions & 2 deletions src/makernote_int.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ struct TiffMnRegistry {
same size. E.g., registry = "OLYMPUS",
key = "OLYMPUS OPTICAL CO.,LTD" (found in the image) match.
*/
bool operator==(const std::string& key) const;
bool operator==(std::string_view key) const;

//! Compare a TiffMnRegistry structure with a makernote group
bool operator==(IfdId key) const;
Expand Down Expand Up @@ -71,7 +71,7 @@ class TiffMnCreator {
is used to indicate this transfer here in order to reduce
file dependencies.
*/
static std::unique_ptr<TiffComponent> create(uint16_t tag, IfdId group, const std::string& make, const byte* pData,
static std::unique_ptr<TiffComponent> create(uint16_t tag, IfdId group, std::string_view make, const byte* pData,
size_t size, ByteOrder byteOrder);
/*!
@brief Create the Makernote for a given group. This method is used
Expand Down
45 changes: 6 additions & 39 deletions src/nikonmn_int.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3331,56 +3331,37 @@ std::ostream& Nikon3MakerNote::printExitPupilPosition(std::ostream& os, const Va
}

std::ostream& Nikon3MakerNote::printFlashFocalLength(std::ostream& os, const Value& value, const ExifData*) {
std::ios::fmtflags f(os.flags());
if (value.count() != 1 || value.typeId() != unsignedByte) {
os << "(" << value << ")";
os.flags(f);
return os;
}
auto temp = value.toInt64();
if (temp == 0 || temp == 255)
return os << _("n/a");

std::ostringstream oss;
oss.copyfmt(os);
os << std::fixed << std::setprecision(1) << temp << " mm";
os.copyfmt(oss);
os.flags(f);
return os;
return os << stringFormat("{:1} mm", temp);
}

std::ostream& Nikon3MakerNote::printRepeatingFlashRate(std::ostream& os, const Value& value, const ExifData*) {
std::ios::fmtflags f(os.flags());
if (value.count() != 1 || value.typeId() != unsignedByte) {
return os << "(" << value << ")";
}
auto temp = value.toInt64();
if (temp == 0 || temp == 255)
return os << _("n/a");

std::ostringstream oss;
oss.copyfmt(os);
os << std::fixed << std::setprecision(2) << temp << " Hz";
os.copyfmt(oss);
os.flags(f);
return os;
return os << stringFormat("{:2} Hz", temp);
}

std::ostream& Nikon3MakerNote::printRepeatingFlashCount(std::ostream& os, const Value& value, const ExifData*) {
std::ios::fmtflags f(os.flags());
if (value.count() != 1 || value.typeId() != unsignedByte) {
return os << "(" << value << ")";
}
auto temp = value.toInt64();
if (temp == 0 || temp == 255)
return os << _("n/a");

std::ostringstream oss;
oss.copyfmt(os);
os << std::fixed << std::setprecision(2) << temp;
os.copyfmt(oss);
os.flags(f);
return os;
return os << stringFormat("{:1}", temp);
}

std::ostream& Nikon3MakerNote::printExternalFlashData1Fl6(std::ostream& os, const Value& value,
Expand Down Expand Up @@ -3938,12 +3919,7 @@ std::ostream& Nikon3MakerNote::printApertureLd4(std::ostream& os, const Value& v
if (temp == 0)
return os << _("n/a");

double aperture = pow(2.0, (value.toInt64() / 384.0) - 1.0);
std::ostringstream oss;
oss.copyfmt(os);
os << std::fixed << std::setprecision(1) << "F" << aperture;
os.copyfmt(oss);
return os;
return os << stringFormat("F{:.1f}", std::pow(2.0, (temp / 384.0) - 1.0));
}
std::ostream& Nikon3MakerNote::printFocalLd4(std::ostream& os, const Value& value, const ExifData*) {
if (value.count() != 1 || value.typeId() != unsignedShort) {
Expand All @@ -3953,11 +3929,7 @@ std::ostream& Nikon3MakerNote::printFocalLd4(std::ostream& os, const Value& valu
if (temp == 0)
return os << _("n/a");

std::ostringstream oss;
oss.copyfmt(os);
os << std::fixed << std::setprecision(1) << value.toInt64() << " mm";
os.copyfmt(oss);
return os;
return os << stringFormat("{} mm", temp);
}

std::ostream& Nikon3MakerNote::printFocusDistanceLd4(std::ostream& os, const Value& value, const ExifData*) {
Expand All @@ -3968,12 +3940,7 @@ std::ostream& Nikon3MakerNote::printFocusDistanceLd4(std::ostream& os, const Val
if (temp == 0)
return os << _("n/a");

double dist = 0.01 * pow(10.0, (value.toInt64() / 256.0) / 40.0);
std::ostringstream oss;
oss.copyfmt(os);
os << std::fixed << std::setprecision(2) << dist << " m";
os.copyfmt(oss);
return os;
return os << stringFormat("{:.2f} m", std::pow(10.0, (temp / 256.0) / 40.0 - 2.0));
}

} // namespace Exiv2::Internal
Loading