Skip to content
Open

Fixes #3413

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 27 additions & 10 deletions app/actions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -447,13 +447,21 @@ bool Print::printMetadatum(const Exiv2::Metadatum& md, const Exiv2::Image* pImag

bool const manyFiles = Params::instance().files_.size() > 1;
if (manyFiles) {
std::cout << std::setfill(' ') << std::left << std::setw(20) << path_ << " ";
std::ostringstream os;
std::ios::fmtflags f(os.flags());
os << std::setfill(' ') << std::left << std::setw(20) << path_ << " ";
binaryOutput(os);
os.flags(f);
}

bool first = true;
if (Params::instance().printItems_ & Params::prTag) {
first = false;
std::cout << "0x" << std::setw(4) << std::setfill('0') << std::right << std::hex << md.tag();
std::ostringstream os;
std::ios::fmtflags f(os.flags());
os << "0x" << std::setw(4) << std::setfill('0') << std::right << std::hex << md.tag();
binaryOutput(os);
os.flags(f);
}
if (Params::instance().printItems_ & Params::prSet) {
if (!first)
Expand Down Expand Up @@ -522,6 +530,7 @@ bool Print::printMetadatum(const Exiv2::Metadatum& md, const Exiv2::Image* pImag
std::cout << " ";
first = false;
std::ostringstream os;
std::ios::fmtflags f(os.flags());
// #1114 - show negative values for SByte
if (md.typeId() == Exiv2::signedByte) {
for (size_t c = 0; c < md.value().count(); c++) {
Expand All @@ -532,14 +541,17 @@ bool Print::printMetadatum(const Exiv2::Metadatum& md, const Exiv2::Image* pImag
os << std::dec << md.value();
}
binaryOutput(os);
os.flags(f);
}
if (Params::instance().printItems_ & Params::prTrans) {
if (!first)
std::cout << " ";
first = false;
std::ostringstream os;
std::ios::fmtflags f(os.flags());
os << std::dec << md.print(&pImage->exifData());
binaryOutput(os);
os.flags(f);
}
if (Params::instance().printItems_ & Params::prHex) {
if (!first)
Expand Down Expand Up @@ -580,17 +592,22 @@ int Print::printPreviewList() {
bool const manyFiles = Params::instance().files_.size() > 1;
int cnt = 0;
Exiv2::PreviewManager pm(*image);
std::ostringstream os;
std::ios::fmtflags f(os.flags());
Exiv2::PreviewPropertiesList list = pm.getPreviewProperties();
for (const auto& pos : list) {
if (manyFiles) {
std::cout << std::setfill(' ') << std::left << std::setw(20) << path_ << " ";
}
std::cout << _("Preview") << " " << ++cnt << ": " << pos.mimeType_ << ", ";
if (pos.width_ != 0 && pos.height_ != 0) {
std::cout << pos.width_ << "x" << pos.height_ << " " << _("pixels") << ", ";
}
std::cout << pos.size_ << " " << _("bytes") << "\n";
if (manyFiles)
os << std::setfill(' ') << std::left << std::setw(20) << path_ << " ";

os << _("Preview") << " " << ++cnt << ": " << pos.mimeType_ << ", ";

if (pos.width_ != 0 && pos.height_ != 0)
os << pos.width_ << "x" << pos.height_ << " " << _("pixels") << ", ";

os << pos.size_ << " " << _("bytes") << "\n";
}
binaryOutput(os);
os.flags(f);
return 0;
} // Print::printPreviewList

Expand Down
4 changes: 4 additions & 0 deletions include/exiv2/bmpimage.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,15 +48,19 @@ class EXIV2API BmpImage : public Image {
void readMetadata() override;

/// @throws Error(ErrorCode::kerWritingImageFormatUnsupported).
/// Always
void writeMetadata() override;

/// @throws Error(ErrorCode::kerInvalidSettingForImage)
/// Always
void setExifData(const ExifData& exifData) override;

/// @throws Error(ErrorCode::kerInvalidSettingForImage)
/// Always
void setIptcData(const IptcData& iptcData) override;

/// @throws Error(ErrorCode::kerInvalidSettingForImage)
/// Always
void setComment(const std::string&) override;
//@}

Expand Down
2 changes: 1 addition & 1 deletion include/exiv2/cr2image.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ class EXIV2API Cr2Parser {
See TiffParser::encode().
*/
static WriteMethod encode(BasicIo& io, const byte* pData, size_t size, ByteOrder byteOrder, ExifData& exifData,
IptcData& iptcData, XmpData& xmpData);
const IptcData& iptcData, const XmpData& xmpData);

}; // class Cr2Parser

Expand Down
2 changes: 1 addition & 1 deletion include/exiv2/image.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ class EXIV2API Image {
/*!
@brief Throw an exception if the size at the beginning of the iccProfile isn't correct.
*/
void checkIccProfile();
void checkIccProfile() const;
/*!
@brief Erase iccProfile. the profile is not removed from
the actual image until the writeMetadata() method is called.
Expand Down
2 changes: 1 addition & 1 deletion include/exiv2/jpgimage.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ class EXIV2API JpegImage : public JpegBase {
/*!
@brief Get the encoding process of the JPEG Image derived from the Start of Frame (SOF) markers
*/
[[nodiscard]] std::string encodingProcess() const {
[[nodiscard]] const std::string& encodingProcess() const {
return sof_encoding_process_;
}
//@}
Expand Down
2 changes: 1 addition & 1 deletion include/exiv2/matroskavideo.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -149,11 +149,11 @@ class EXIV2API MatroskaVideo : public Image {
@param size Size of \em buf.
*/

void decodeDateTags(const Internal::MatroskaTag* tag, const byte* buf, size_t size);
void decodeInternalTags(const Internal::MatroskaTag* tag, const byte* buf);
void decodeStringTags(const Internal::MatroskaTag* tag, const byte* buf);
void decodeIntegerTags(const Internal::MatroskaTag* tag, const byte* buf);
void decodeBooleanTags(const Internal::MatroskaTag* tag, const byte* buf);
void decodeDateTags(const Internal::MatroskaTag* tag, const byte* buf, size_t size);
void decodeFloatTags(const Internal::MatroskaTag* tag, const byte* buf);

private:
Expand Down
2 changes: 1 addition & 1 deletion include/exiv2/orfimage.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ class EXIV2API OrfParser {
See TiffParser::encode().
*/
static WriteMethod encode(BasicIo& io, const byte* pData, size_t size, ByteOrder byteOrder, ExifData& exifData,
IptcData& iptcData, XmpData& xmpData);
const IptcData& iptcData, const XmpData& xmpData);
}; // class OrfParser

// *****************************************************************************
Expand Down
4 changes: 2 additions & 2 deletions include/exiv2/preview.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -87,12 +87,12 @@ class EXIV2API PreviewImage {
@brief Return the MIME type of the preview image, usually either
\c "image/tiff" or \c "image/jpeg".
*/
[[nodiscard]] std::string mimeType() const;
[[nodiscard]] const std::string& mimeType() const;
/*!
@brief Return the file extension for the format of the preview image
(".tif" or ".jpg").
*/
[[nodiscard]] std::string extension() const;
[[nodiscard]] const std::string& extension() const;
/*!
@brief Return the width of the preview image in pixels.
*/
Expand Down
2 changes: 1 addition & 1 deletion include/exiv2/quicktimevideo.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ class EXIV2API QuickTimeVideo : public Image {
/*!
@brief Interpret User Data Tag, and save it
in the respective XMP container.
@param size Size of the data block used to store Tag Information.
@param outer_size Size of the data block used to store Tag Information.
*/
void userDataDecoder(size_t outer_size, size_t recursion_depth);
/*!
Expand Down
4 changes: 2 additions & 2 deletions include/exiv2/slice.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -326,7 +326,7 @@ struct PtrSliceStorage {
* Obtain a reference to the element with the given `index` in the
* array.
*
* @throw nothing
* @note Does not throw
*/
[[nodiscard]] auto& unsafeAt(size_t index) noexcept {
return data_[index];
Expand All @@ -340,7 +340,7 @@ struct PtrSliceStorage {
* Obtain an iterator (=pointer) at the position of the element with
* the given index in the container.
*
* @throw nothing
* @note Does not throw
*/
[[nodiscard]] auto unsafeGetIteratorAt(size_t index) noexcept {
return data_ + index;
Expand Down
2 changes: 1 addition & 1 deletion include/exiv2/tiffimage.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ class EXIV2API TiffParser {
@return Write method used.
*/
static WriteMethod encode(BasicIo& io, const byte* pData, size_t size, ByteOrder byteOrder, ExifData& exifData,
IptcData& iptcData, XmpData& xmpData);
const IptcData& iptcData, const XmpData& xmpData);

}; // class TiffParser

Expand Down
4 changes: 2 additions & 2 deletions src/cr2image.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ void Cr2Image::writeMetadata() {
std::cerr << "Writing CR2 file " << io_->path() << "\n";
#endif
ByteOrder bo = byteOrder();
byte* pData = nullptr;
const byte* pData = nullptr;
size_t size = 0;
IoCloser closer(*io_);
// Ensure that this is the correct image type
Expand All @@ -104,7 +104,7 @@ ByteOrder Cr2Parser::decode(ExifData& exifData, IptcData& iptcData, XmpData& xmp
}

WriteMethod Cr2Parser::encode(BasicIo& io, const byte* pData, size_t size, ByteOrder byteOrder, ExifData& exifData,
IptcData& iptcData, XmpData& xmpData) {
const IptcData& iptcData, const XmpData& xmpData) {
// Delete IFDs which do not occur in TIFF images
static constexpr auto filteredIfds = std::array{
IfdId::panaRawId,
Expand Down
2 changes: 1 addition & 1 deletion src/crwimage_int.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -837,7 +837,7 @@ void CrwMap::encodeBasic(const Image& image, const CrwMapping& pCrwMapping, Ciff
void CrwMap::encode0x0805(const Image& image, const CrwMapping& pCrwMapping, CiffHeader& pHead) {
std::string comment = image.comment();

CiffComponent* cc = pHead.findComponent(pCrwMapping.crwTagId_, pCrwMapping.crwDir_);
auto cc = pHead.findComponent(pCrwMapping.crwTagId_, pCrwMapping.crwDir_);
if (!comment.empty()) {
auto size = comment.size();
if (cc && cc->size() > size)
Expand Down
2 changes: 1 addition & 1 deletion src/datasets.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -481,7 +481,7 @@ uint16_t IptcDataSets::recordId(const std::string& recordName) {
}

void IptcDataSets::dataSetList(std::ostream& os) {
for (auto&& record : records_) {
for (const auto& record : records_) {
for (int j = 0; record && record[j].number_ != 0xffff; ++j) {
os << record[j] << "\n";
}
Expand Down
2 changes: 1 addition & 1 deletion src/image.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -650,7 +650,7 @@ void Image::appendIccProfile(const uint8_t* bytes, size_t size, bool bTestValid)
}
}

void Image::checkIccProfile() {
void Image::checkIccProfile() const {
if (iccProfile_.size() < sizeof(long)) {
throw Error(ErrorCode::kerInvalidIccProfile);
}
Expand Down
6 changes: 3 additions & 3 deletions src/image_int.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,10 @@ struct binaryToStringHelper;
* @brief Actual implementation of the output algorithm described in @ref
* binaryToString
*
* @throws nothing
* @note Does not throw
*/
template <typename T>
std::ostream& operator<<(std::ostream& stream, const binaryToStringHelper<T>& binToStr) {
std::ostream& operator<<(std::ostream& stream, const binaryToStringHelper<T>& binToStr) noexcept {
for (size_t i = 0; i < binToStr.buf_.size(); ++i) {
auto c = static_cast<unsigned char>(binToStr.buf_.at(i));
if (c != 0 || i != binToStr.buf_.size() - 1) {
Expand Down Expand Up @@ -95,7 +95,7 @@ struct binaryToStringHelper {
* the stream throws neither.
*/
template <typename T>
constexpr binaryToStringHelper<T> binaryToString(Slice<T>&& sl) noexcept {
constexpr auto binaryToString(Slice<T>&& sl) noexcept {
return binaryToStringHelper<T>(std::move(sl));
}

Expand Down
4 changes: 2 additions & 2 deletions src/orfimage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ void OrfImage::writeMetadata() {
std::cerr << "Writing ORF file " << io_->path() << "\n";
#endif
ByteOrder bo = byteOrder();
byte* pData = nullptr;
const byte* pData = nullptr;
size_t size = 0;
IoCloser closer(*io_);
// Ensure that this is the correct image type
Expand All @@ -116,7 +116,7 @@ ByteOrder OrfParser::decode(ExifData& exifData, IptcData& iptcData, XmpData& xmp
}

WriteMethod OrfParser::encode(BasicIo& io, const byte* pData, size_t size, ByteOrder byteOrder, ExifData& exifData,
IptcData& iptcData, XmpData& xmpData) {
const IptcData& iptcData, const XmpData& xmpData) {
// Delete IFDs which do not occur in TIFF images
static constexpr auto filteredIfds = {
IfdId::panaRawId,
Expand Down
2 changes: 2 additions & 0 deletions src/pentaxmn_int.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -996,6 +996,7 @@ std::ostream& PentaxMakerNote::printFlashCompensation(std::ostream& os, const Va
}

std::ostream& PentaxMakerNote::printBracketing(std::ostream& os, const Value& value, const ExifData*) {
std::ios::fmtflags f(os.flags());
if (auto l0 = value.toUint32(0); l0 < 10) {
os << std::setprecision(2) << static_cast<float>(l0) / 3 << " EV";
} else {
Expand Down Expand Up @@ -1034,6 +1035,7 @@ std::ostream& PentaxMakerNote::printBracketing(std::ostream& os, const Value& va
}
os << ")";
}
os.flags(f);
return os;
}

Expand Down
4 changes: 2 additions & 2 deletions src/preview.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -981,11 +981,11 @@ uint32_t PreviewImage::size() const {
return static_cast<uint32_t>(preview_.size());
}

std::string PreviewImage::mimeType() const {
const std::string& PreviewImage::mimeType() const {
return properties_.mimeType_;
}

std::string PreviewImage::extension() const {
const std::string& PreviewImage::extension() const {
return properties_.extension_;
}

Expand Down
2 changes: 1 addition & 1 deletion src/tiffcomposite_int.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1172,7 +1172,7 @@ size_t TiffComponent::writeImage(IoWrapper& ioWrapper, ByteOrder byteOrder) cons

size_t TiffDirectory::doWriteImage(IoWrapper& ioWrapper, ByteOrder byteOrder) const {
size_t len = 0;
TiffComponent* pSubIfd = nullptr;
const TiffComponent* pSubIfd = nullptr;
for (const auto& component : components_) {
if (component->tag() == 0x014a) {
// Hack: delay writing of sub-IFD image data to get the order correct
Expand Down
4 changes: 2 additions & 2 deletions src/tiffimage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ void TiffImage::writeMetadata() {
std::cerr << "Writing TIFF file " << io_->path() << "\n";
#endif
ByteOrder bo = byteOrder();
byte* pData = nullptr;
const byte* pData = nullptr;
size_t size = 0;
IoCloser closer(*io_);
// Ensure that this is the correct image type
Expand Down Expand Up @@ -217,7 +217,7 @@ ByteOrder TiffParser::decode(ExifData& exifData, IptcData& iptcData, XmpData& xm
} // TiffParser::decode

WriteMethod TiffParser::encode(BasicIo& io, const byte* pData, size_t size, ByteOrder byteOrder, ExifData& exifData,
IptcData& iptcData, XmpData& xmpData) {
const IptcData& iptcData, const XmpData& xmpData) {
// Delete IFDs which do not occur in TIFF images
static constexpr auto filteredIfds = std::array{
IfdId::panaRawId,
Expand Down
17 changes: 10 additions & 7 deletions src/utils.cpp
Original file line number Diff line number Diff line change
@@ -1,20 +1,23 @@
#include "utils.hpp"

#include <algorithm>
#include <cctype>
#include <string>

namespace Exiv2::Internal {

std::string upper(const std::string& str) {
std::string result = str;
std::transform(str.begin(), str.end(), result.begin(), [](int c) { return static_cast<char>(toupper(c)); });
std::string upper(std::string_view str) {
std::string result;
result.reserve(str.size());
for (auto c : str)
result.push_back(std::toupper(static_cast<unsigned char>(c)));
return result;
}

std::string lower(const std::string& a) {
std::string b = a;
std::transform(a.begin(), a.end(), b.begin(), [](int c) { return static_cast<char>(tolower(c)); });
std::string lower(std::string_view a) {
std::string b;
b.reserve(a.size());
for (auto c : a)
b.push_back(std::tolower(static_cast<unsigned char>(c)));
return b;
}

Expand Down
4 changes: 2 additions & 2 deletions src/utils.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@ constexpr bool contains(std::string_view s, T c) {
}

/// @brief Returns the uppercase version of \b str
std::string upper(const std::string& str);
std::string upper(std::string_view str);

/// @brief Returns the lowercase version of \b str
std::string lower(const std::string& a);
std::string lower(std::string_view a);

} // namespace Exiv2::Internal

Expand Down
Loading