sonarlint cleanups

Signed-off-by: Rosen Penev <rosenp@gmail.com>
main
Rosen Penev 2 years ago
parent 25189ef1e6
commit 6fd143d6a4

@ -1794,10 +1794,8 @@ int metacopy(const std::string& source, const std::string& tgt, Exiv2::ImageType
// if we used a temporary target, copy it to stdout
if (rc == 0 && bStdout) {
FILE* f = ::fopen(target.c_str(), "rb");
_setmode(fileno(stdout), O_BINARY);
if (f) {
if (auto f = std::fopen(target.c_str(), "rb")) {
char buffer[8 * 1024];
size_t n = 1;
while (!feof(f) && n > 0) {

@ -1445,8 +1445,9 @@ bool parseLine(ModifyCmd& modifyCmd, const std::string& line, int num) {
} // parseLine
CmdId commandId(const std::string& cmdString) {
auto it = Exiv2::find(cmdIdAndString, cmdString);
return it ? it->cmdId_ : CmdId::invalid;
if (auto it = Exiv2::find(cmdIdAndString, cmdString))
return it->cmdId_;
return CmdId::invalid;
}
std::string parseEscapes(const std::string& input) {

@ -94,7 +94,7 @@ class EXIV2API AsfVideo : public Image {
uint64_t remaining_size_{};
public:
explicit HeaderReader(BasicIo::UniquePtr& io);
explicit HeaderReader(const BasicIo::UniquePtr& io);
[[nodiscard]] uint64_t getSize() const {
return size_;
@ -146,7 +146,7 @@ class EXIV2API AsfVideo : public Image {
@brief Interpret Header_Extension tag information, and save it in
the respective XMP container.
*/
void headerExtension();
void headerExtension() const;
/*!
@brief Interpret Metadata, Extended_Content_Description,
Metadata_Library tag information, and save it in the respective

@ -119,7 +119,7 @@ class EXIV2API BmffImage : public Image {
static constexpr Exiv2::ByteOrder endian_{Exiv2::bigEndian};
private:
void openOrThrow();
void openOrThrow() const;
/*!
@brief recursiveBoxHandler
@throw Error if we visit a box more than once

@ -129,7 +129,7 @@ class EXIV2API Exifdatum : public Metadatum {
@return Return -1 if the %Exifdatum does not have a value yet or the
value has no data area, else 0.
*/
int setDataArea(const byte* buf, size_t len);
int setDataArea(const byte* buf, size_t len) const;
//@}
//! @name Accessors

@ -88,13 +88,13 @@ class EXIV2API RiffVideo : public Image {
@brief Interpret Additional header data (strd), and save it in the respective XMP container.
@param size_ Size of the data block used to store Tag Information.
*/
void readStreamData(uint64_t size_);
void readStreamData(uint64_t size_) const;
/*!
@brief Interpret stream header list element (strn) , and save it in the respective XMP container.
@param size_ Size of the data block used to store Tag Information.
*/
void StreamName(uint64_t size_);
void StreamName(uint64_t size_) const;
/*!
@brief Interpret INFO List Chunk, and save it in the respective XMP container.
@param size_ Size of the data block used to store Tag Information.
@ -106,28 +106,28 @@ class EXIV2API RiffVideo : public Image {
The Movi - Lists contain Video, Audio, Subtitle and (secondary) index data. Those can be grouped into rec - Lists.
@param size_ Size of the data block used to store Tag Information.
*/
void readMoviList(uint64_t size_);
void readMoviList(uint64_t size_) const;
/*!
@brief Interpret Video Properties Header chunk, and save it in the respective XMP container.
The video properties header identifies video signal properties associated with a digital video stream in an AVI file
@param size_ Size of the data block used to store Tag Information.
*/
void readVPRPChunk(uint64_t size_);
void readVPRPChunk(uint64_t size_) const;
/*!
@brief Interpret Riff INdex Chunk, and save it in the respective XMP container.
@param size_ Size of the data block used to store Tag Information.
*/
void readIndexChunk(uint64_t size_);
void readIndexChunk(uint64_t size_) const;
/*!
@brief Interpret Riff Stream Chunk, and save it in the respective XMP container.
@param size_ Size of the data block used to store Tag Information.
*/
void readDataChunk(uint64_t size_);
void readDataChunk(uint64_t size_) const;
/*!
@brief Interpret Junk Chunk and save it in the respective XMP container.
@param size_ Size of the data block used to store Tag Information.
*/
void readJunk(uint64_t size_);
void readJunk(uint64_t size_) const;
static std::string getStreamType(uint32_t stream);
/*!

@ -315,7 +315,7 @@ class EXIV2API ExifKey : public Key {
*/
ExifKey& operator=(const ExifKey& rhs);
//! Set the index.
void setIdx(int idx);
void setIdx(int idx) const;
//@}
//! @name Accessors

@ -238,7 +238,7 @@ void AsfVideo::readMetadata() {
xmpData_["Xmp.video.AspectRatio"] = getAspectRatio(width_, height_);
} // AsfVideo::readMetadata
AsfVideo::HeaderReader::HeaderReader(BasicIo::UniquePtr& io) : IdBuf_(GUID) {
AsfVideo::HeaderReader::HeaderReader(const BasicIo::UniquePtr& io) : IdBuf_(GUID) {
if (io->size() >= io->tell() + GUID + QWORD) {
IdBuf_ = io->read(GUID);
@ -409,7 +409,7 @@ void AsfVideo::codecList() {
}
} // AsfVideo::codecList
void AsfVideo::headerExtension() {
void AsfVideo::headerExtension() const {
io_->seek(io_->tell() + GUID /*reserved1*/ + WORD /*Reserved2*/, BasicIo::beg);
auto header_ext_data_length = readDWORDTag(io_);
io_->seek(io_->tell() + header_ext_data_length, BasicIo::beg);

@ -184,10 +184,9 @@ int FileIo::Impl::switchMode(OpMode opMode) {
} // FileIo::Impl::switchMode
int FileIo::Impl::stat(StructStat& buf) const {
int ret = 0;
struct stat st;
ret = ::stat(path_.c_str(), &st);
if (0 == ret) {
auto ret = ::stat(path_.c_str(), &st);
if (ret == 0) {
buf.st_size = st.st_size;
buf.st_mode = st.st_mode;
}
@ -204,16 +203,16 @@ FileIo::~FileIo() {
int FileIo::munmap() {
int rc = 0;
if (p_->pMappedArea_) {
#if __has_include(<sys/mman.h>)
if (::munmap(p_->pMappedArea_, p_->mappedLength_) != 0) {
rc = 1;
}
#elif defined _WIN32
#if defined _WIN32
UnmapViewOfFile(p_->pMappedArea_);
CloseHandle(p_->hMap_);
p_->hMap_ = nullptr;
CloseHandle(p_->hFile_);
p_->hFile_ = nullptr;
#elif __has_include(<sys/mman.h>)
if (::munmap(p_->pMappedArea_, p_->mappedLength_) != 0) {
rc = 1;
}
#else
#error Platforms without mmap are not supported. See https://github.com/Exiv2/exiv2/issues/2380
if (p_->isWriteable_) {
@ -1221,7 +1220,7 @@ size_t RemoteIo::write(BasicIo& src) {
}
// submit to the remote machine.
if (auto dataSize = src.size() - left - right; dataSize > 0) {
if (auto dataSize = src.size() - left - right) {
std::vector<byte> data(dataSize);
src.seek(left, BasicIo::beg);
src.read(data.data(), dataSize);

@ -183,7 +183,7 @@ class BrotliDecoderWrapper {
BrotliDecoderWrapper(const BrotliDecoderWrapper&) = delete;
BrotliDecoderWrapper& operator=(const BrotliDecoderWrapper&) = delete;
BrotliDecoderState* get() const {
[[nodiscard]] BrotliDecoderState* get() const {
return decoder_;
}
};
@ -667,12 +667,11 @@ void BmffImage::parseCr3Preview(const DataBuf& data, std::ostream& out, bool bTr
return "image/jpeg";
return "application/octet-stream";
}();
nativePreviews_.push_back(std::move(nativePreview));
if (bTrace) {
out << Internal::stringFormat("width,height,size = %zu,%zu,%zu", nativePreview.width_, nativePreview.height_,
nativePreview.size_);
}
nativePreviews_.push_back(std::move(nativePreview));
}
void BmffImage::setExifData(const ExifData& /*exifData*/) {
@ -692,7 +691,7 @@ void BmffImage::setComment(const std::string&) {
throw(Error(ErrorCode::kerInvalidSettingForImage, "Image comment", "BMFF"));
}
void BmffImage::openOrThrow() {
void BmffImage::openOrThrow() const {
if (io_->open() != 0) {
throw Error(ErrorCode::kerDataSourceOpenFailed, io_->path(), strError());
}

@ -639,7 +639,6 @@ void Converter::cnvExifDate(const char* from, const char* to) {
return;
}
} else { // "Exif.GPSInfo.GPSTimeStamp"
bool ok = true;
if (pos->count() != 3)
ok = false;
@ -949,7 +948,6 @@ void Converter::cnvXmpDate(const char* from, const char* to) {
}
}
} else { // "Exif.GPSInfo.GPSTimeStamp"
// Ignore the time zone, assuming the time is in UTC as it should be
URational rhour(datetime.hour, 1);
@ -1391,17 +1389,16 @@ void moveXmpToIptc(XmpData& xmpData, IptcData& iptcData) {
bool convertStringCharset(std::string& str, const char* from, const char* to) {
if (0 == strcmp(from, to))
return true; // nothing to do
bool ret = false;
#if defined EXV_HAVE_ICONV
ret = convertStringCharsetIconv(str, from, to);
return convertStringCharsetIconv(str, from, to);
#elif defined _WIN32
ret = convertStringCharsetWindows(str, from, to);
return convertStringCharsetWindows(str, from, to);
#else
#ifndef SUPPRESS_WARNINGS
EXV_WARNING << "Charset conversion required but no character mapping functionality available.\n";
#endif
#endif
return ret;
return false;
}
} // namespace Exiv2
@ -1589,8 +1586,7 @@ const ConvFctList convFctList[] = {
[[maybe_unused]] bool convertStringCharsetWindows(std::string& str, const char* from, const char* to) {
bool ret = false;
std::string tmpstr = str;
auto p = Exiv2::find(convFctList, std::pair(from, to));
if (p)
if (auto p = Exiv2::find(convFctList, std::pair(from, to)))
ret = p->convFct_(tmpstr);
#ifndef SUPPRESS_WARNINGS
else {

@ -573,7 +573,7 @@ CiffComponent* CiffDirectory::doAdd(CrwDirs& crwDirs, uint16_t crwTagId) {
return cc_;
} // CiffDirectory::doAdd
void CiffHeader::remove(uint16_t crwTagId, uint16_t crwDir) {
void CiffHeader::remove(uint16_t crwTagId, uint16_t crwDir) const {
if (pRootDir_) {
CrwDirs crwDirs;
CrwMap::loadStack(crwDirs, crwDir);
@ -859,7 +859,7 @@ void CrwMap::encode0x0805(const Image& image, const CrwMapping* pCrwMapping, Cif
if (cc && cc->size() > size)
size = cc->size();
DataBuf buf(size);
std::copy(comment.begin(), comment.end(), buf.begin());
std::move(comment.begin(), comment.end(), buf.begin());
pHead->add(pCrwMapping->crwTagId_, pCrwMapping->crwDir_, std::move(buf));
} else {
if (cc) {
@ -900,21 +900,19 @@ void CrwMap::encode0x080a(const Image& image, const CrwMapping* pCrwMapping, Cif
}
void CrwMap::encodeArray(const Image& image, const CrwMapping* pCrwMapping, CiffHeader* pHead) {
IfdId ifdId = IfdId::ifdIdNotSet;
switch (pCrwMapping->tag_) {
case 0x0001:
ifdId = IfdId::canonCsId;
break;
case 0x0004:
ifdId = IfdId::canonSiId;
break;
case 0x000f:
ifdId = IfdId::canonCfId;
break;
case 0x0012:
ifdId = IfdId::canonPiId;
break;
}
auto ifdId = [=] {
switch (pCrwMapping->tag_) {
case 0x0001:
return IfdId::canonCsId;
case 0x0004:
return IfdId::canonSiId;
case 0x000f:
return IfdId::canonCfId;
case 0x0012:
return IfdId::canonPiId;
}
return IfdId::ifdIdNotSet;
}();
DataBuf buf = packIfdId(image.exifData(), ifdId, pHead->byteOrder());
if (buf.empty()) {
// Try the undecoded tag

@ -424,7 +424,7 @@ class CiffHeader {
@param crwTagId Tag id to be removed.
@param crwDir Parent directory of the tag.
*/
void remove(uint16_t crwTagId, uint16_t crwDir);
void remove(uint16_t crwTagId, uint16_t crwDir) const;
//@}
//! Return a pointer to the Canon CRW signature.

@ -265,7 +265,7 @@ int Exifdatum::setValue(const std::string& value) {
return value_->read(value);
}
int Exifdatum::setDataArea(const byte* buf, size_t len) {
int Exifdatum::setDataArea(const byte* buf, size_t len) const {
return value_ ? value_->setDataArea(buf, len) : -1;
}

@ -346,11 +346,10 @@ static std::ostream& printFujiFaceElementTypes(std::ostream& os, const Value& va
longValue -= '0';
}
auto td = Exiv2::find(fujiFaceElementType, longValue);
if (n != 0) {
os << " ";
}
if (td) {
if (auto td = Exiv2::find(fujiFaceElementType, longValue)) {
os << exvGettext(td->label_);
} else {
os << "(" << value.toInt64(n) << ")";

@ -139,7 +139,8 @@ int Exiv2::http(Exiv2::Dictionary& request, Exiv2::Dictionary& response, std::st
// Windows specific code
#if defined(_WIN32)
WSADATA wsaData;
WSAStartup(MAKEWORD(2, 2), &wsaData);
if (WSAStartup(MAKEWORD(2, 2), &wsaData) != 0)
return error(errors, "could not start WinSock");
#endif
const char* servername = request["server"].c_str();

@ -743,10 +743,9 @@ AccessMode ImageFactory::checkMode(ImageType type, MetadataId metadataId) {
}
bool ImageFactory::checkType(ImageType type, BasicIo& io, bool advance) {
auto r = Exiv2::find(registry, type);
if (!r)
return false;
return r->isThisType_(io, advance);
if (auto r = Exiv2::find(registry, type))
return r->isThisType_(io, advance);
return false;
}
ImageType ImageFactory::getType(const std::string& path) {
@ -844,10 +843,9 @@ Image::UniquePtr ImageFactory::create(ImageType type, BasicIo::UniquePtr io) {
// BasicIo instance does not need to be open
if (type == ImageType::none)
return {};
auto r = Exiv2::find(registry, type);
if (!r)
return {};
return r->newInstance_(std::move(io), true);
if (auto r = Exiv2::find(registry, type))
return r->newInstance_(std::move(io), true);
return {};
}
// *****************************************************************************

@ -142,11 +142,9 @@ bool TiffMnRegistry::operator==(IfdId key) const {
TiffComponent* TiffMnCreator::create(uint16_t tag, IfdId group, const std::string& make, const byte* pData, size_t size,
ByteOrder byteOrder) {
auto tmr = Exiv2::find(registry_, make);
if (!tmr) {
return nullptr;
}
return tmr->newMnFct_(tag, group, tmr->mnGroup_, pData, size, byteOrder);
if (auto tmr = Exiv2::find(registry_, make))
return tmr->newMnFct_(tag, group, tmr->mnGroup_, pData, size, byteOrder);
return nullptr;
} // TiffMnCreator::create
TiffComponent* TiffMnCreator::create(uint16_t tag, IfdId group, IfdId mnGroup) {
@ -914,11 +912,9 @@ int nikonSelector(uint16_t tag, const byte* pData, size_t size, TiffComponent* /
return -1;
auto ix = NikonArrayIdx::Key{tag, reinterpret_cast<const char*>(pData), size};
auto it = Exiv2::find(nikonArrayIdx, ix);
if (!it)
return -1;
return it->idx_;
if (auto it = Exiv2::find(nikonArrayIdx, ix))
return it->idx_;
return -1;
}
DataBuf nikonCrypt(uint16_t tag, const byte* pData, size_t size, TiffComponent* pRoot) {

@ -254,7 +254,7 @@ enum matroskaEnum : uint64_t {
Cluster = 0xf43b675
};
const MatroskaTag matroskaTags[] = {
const MatroskaTag matroskaTags[]{
{ChapterDisplay, "ChapterDisplay", Master, Composite},
{TrackType, "TrackType", Boolean, Process},
{ChapterString, "ChapterString", String, Skip},
@ -720,60 +720,46 @@ void MatroskaVideo::decodeBlock() {
} // MatroskaVideo::decodeBlock
void MatroskaVideo::decodeInternalTags(const MatroskaTag* tag, const byte* buf) {
const MatroskaTag* internalMt = nullptr;
uint64_t key = getULongLong(buf, bigEndian);
if (!key)
return;
switch (tag->_id) {
case Xmp_video_VideoScanTpye:
internalMt = Exiv2::find(videoScanType, key);
break;
case Xmp_audio_ChannelType:
internalMt = Exiv2::find(audioChannels, key);
break;
case Xmp_video_ContentCompressAlgo:
internalMt = Exiv2::find(compressionAlgorithm, key);
break;
case Xmp_video_ContentEncryptAlgo:
internalMt = Exiv2::find(encryptionAlgorithm, key);
break;
case Xmp_video_ContentSignAlgo_1:
case Xmp_video_ContentSignAlgo_2:
internalMt = Exiv2::find(contentSignatureAlgorithm, key);
break;
case Xmp_video_ContentSignHashAlgo_1:
case Xmp_video_ContentSignHashAlgo_2:
internalMt = Exiv2::find(contentSignatureHashAlgorithm, key);
break;
case Xmp_video_ContentEncodingType:
internalMt = Exiv2::find(encodingType, key);
break;
case Xmp_video_DisplayUnit:
internalMt = Exiv2::find(displayUnit, key);
break;
case Xmp_video_AspectRatioType:
internalMt = Exiv2::find(aspectRatioType, key);
break;
case Xmp_video_PhysicalEquivalent:
internalMt = Exiv2::find(chapterPhysicalEquivalent, key);
break;
case Xmp_video_TranslateCodec:
internalMt = Exiv2::find(chapterTranslateCodec, key);
break;
case Video_Audio_CodecID:
internalMt = Exiv2::find(trackCodec, key);
break;
case Video_Audio_CodecName:
internalMt = Exiv2::find(codecInfo, key);
break;
case CodecDownloadURL:
case CodecInfoURL:
internalMt = Exiv2::find(codecDownloadUrl, key);
break;
default:
break;
}
auto internalMt = [=]() -> const MatroskaTag* {
switch (tag->_id) {
case Xmp_video_VideoScanTpye:
return Exiv2::find(videoScanType, key);
case Xmp_audio_ChannelType:
return Exiv2::find(audioChannels, key);
case Xmp_video_ContentCompressAlgo:
return Exiv2::find(compressionAlgorithm, key);
case Xmp_video_ContentEncryptAlgo:
return Exiv2::find(encryptionAlgorithm, key);
case Xmp_video_ContentSignAlgo_1:
case Xmp_video_ContentSignAlgo_2:
return Exiv2::find(contentSignatureAlgorithm, key);
case Xmp_video_ContentSignHashAlgo_1:
case Xmp_video_ContentSignHashAlgo_2:
return Exiv2::find(contentSignatureHashAlgorithm, key);
case Xmp_video_ContentEncodingType:
return Exiv2::find(encodingType, key);
case Xmp_video_DisplayUnit:
return Exiv2::find(displayUnit, key);
case Xmp_video_AspectRatioType:
return Exiv2::find(aspectRatioType, key);
case Xmp_video_PhysicalEquivalent:
return Exiv2::find(chapterPhysicalEquivalent, key);
case Xmp_video_TranslateCodec:
return Exiv2::find(chapterTranslateCodec, key);
case Video_Audio_CodecID:
return Exiv2::find(trackCodec, key);
case Video_Audio_CodecName:
return Exiv2::find(codecInfo, key);
case CodecDownloadURL:
case CodecInfoURL:
return Exiv2::find(codecDownloadUrl, key);
}
return nullptr;
}();
if (internalMt) {
xmpData_[tag->_label] = internalMt->_label;
} else {
@ -803,7 +789,6 @@ void MatroskaVideo::decodeIntegerTags(const MatroskaTag* tag, const byte* buf) {
}
void MatroskaVideo::decodeBooleanTags(const MatroskaTag* tag, const byte* buf) {
std::string str("No");
const MatroskaTag* internalMt = nullptr;
uint64_t key = getULongLong(buf, bigEndian);
if (!key)
@ -841,8 +826,7 @@ void MatroskaVideo::decodeBooleanTags(const MatroskaTag* tag, const byte* buf) {
}
if (internalMt) {
str = "Yes";
xmpData_[internalMt->_label] = str;
xmpData_[internalMt->_label] = "Yes";
}
}
@ -893,8 +877,7 @@ void MatroskaVideo::decodeFloatTags(const MatroskaTag* tag, const byte* buf) {
uint64_t key = getULongLong(buf, bigEndian);
if (!key)
return;
const MatroskaTag* internalMt = Exiv2::find(streamRate, key);
if (internalMt) {
if (auto internalMt = Exiv2::find(streamRate, key)) {
switch (stream_) {
case 1: // video
frame_rate = static_cast<double>(1000000000) / static_cast<double>(key);

@ -1679,8 +1679,9 @@ std::ostream& printMinoltaSonyLensID(std::ostream& os, const Value& value, const
// #1145 - respect lenses with shared LensID
uint32_t index = value.toUint32();
if (auto f = Exiv2::find(lensIdFct, index); f && metadata)
return f->fct(os, value, metadata);
if (metadata)
if (auto f = Exiv2::find(lensIdFct, index))
return f->fct(os, value, metadata);
return EXV_PRINT_TAG(minoltaSonyLensID)(os, value, metadata);
}

@ -2007,7 +2007,7 @@ std::ostream& Nikon3MakerNote::printLensId(std::ostream& os, const Value& value,
// Nikkor lenses by their LensID
//------------------------------------------------------------------------------
static const struct FMntLens {
static constexpr struct FMntLens {
unsigned char lid, stps, focs, focl, aps, apl, lfw, ltype, tcinfo, dblid, mid;
const char *manuf, *lnumber, *lensname;
@ -3786,8 +3786,7 @@ std::ostream& Nikon3MakerNote::print0x009e(std::ostream& os, const Value& value,
if (l != 0)
trim = false;
std::string d = s.empty() ? "" : "; ";
auto td = Exiv2::find(nikonRetouchHistory, l);
if (td) {
if (auto td = Exiv2::find(nikonRetouchHistory, l)) {
s = std::string(exvGettext(td->label_)).append(d).append(s);
} else {
s = std::string(_("Unknown")).append(" (").append(std::to_string(l)).append(")").append(d).append(s);

@ -4993,13 +4993,10 @@ std::string XmpProperties::prefix(const std::string& ns) {
auto i = nsRegistry_.find(ns2);
std::string p;
if (i != nsRegistry_.end()) {
if (i != nsRegistry_.end())
p = i->second.prefix_;
} else {
auto xn = Exiv2::find(xmpNsInfo, XmpNsInfo::Ns{ns2});
if (xn)
p = std::string(xn->prefix_);
}
else if (auto xn = Exiv2::find(xmpNsInfo, XmpNsInfo::Ns{ns2}))
p = std::string(xn->prefix_);
return p;
}
@ -5087,8 +5084,7 @@ void XmpProperties::registeredNamespaces(Exiv2::Dictionary& nsDict) {
}
void XmpProperties::printProperties(std::ostream& os, const std::string& prefix) {
const XmpPropertyInfo* pl = propertyList(prefix);
if (pl) {
if (auto pl = propertyList(prefix)) {
for (int i = 0; pl[i].name_; ++i) {
os << pl[i];
}
@ -5099,8 +5095,7 @@ void XmpProperties::printProperties(std::ostream& os, const std::string& prefix)
std::ostream& XmpProperties::printProperty(std::ostream& os, const std::string& key, const Value& value) {
PrintFct fct = printValue;
if (value.count() != 0) {
auto info = Exiv2::find(xmpPrintInfo, key);
if (info)
if (auto info = Exiv2::find(xmpPrintInfo, key))
fct = info->printFct_;
}
return fct(os, value, nullptr);

@ -637,11 +637,11 @@ void RiffVideo::readStreamFormat(uint64_t size_) {
}
}
void RiffVideo::readStreamData(uint64_t size_) {
void RiffVideo::readStreamData(uint64_t size_) const {
io_->seekOrThrow(io_->tell() + size_, BasicIo::beg, ErrorCode::kerFailedToReadImageData);
}
void RiffVideo::StreamName(uint64_t size_) {
void RiffVideo::StreamName(uint64_t size_) const {
// This element contains a name for the stream. That stream name should only use plain ASCII, especially not UTF-8.
io_->seekOrThrow(io_->tell() + size_, BasicIo::beg, ErrorCode::kerFailedToReadImageData);
}
@ -658,11 +658,11 @@ void RiffVideo::readInfoListChunk(uint64_t size_) {
}
}
void RiffVideo::readMoviList(uint64_t size_) {
void RiffVideo::readMoviList(uint64_t size_) const {
io_->seekOrThrow(io_->tell() + size_ - DWORD, BasicIo::beg, ErrorCode::kerFailedToReadImageData);
}
void RiffVideo::readVPRPChunk(uint64_t size_) {
void RiffVideo::readVPRPChunk(uint64_t size_) const {
#ifdef EXIV2_DEBUG_MESSAGES
EXV_INFO << "--> VideoFormatToken = " << readDWORDTag(io_) << std::endl;
EXV_INFO << "--> VideoStandard = " << readDWORDTag(io_) << std::endl;
@ -688,7 +688,7 @@ void RiffVideo::readVPRPChunk(uint64_t size_) {
io_->seekOrThrow(io_->tell() + size_, BasicIo::beg, ErrorCode::kerFailedToReadImageData);
}
void RiffVideo::readIndexChunk(uint64_t size_) {
void RiffVideo::readIndexChunk(uint64_t size_) const {
#ifdef EXIV2_DEBUG_MESSAGES
uint64_t current_size = 0;
while (current_size < size_) {
@ -708,7 +708,7 @@ void RiffVideo::readIndexChunk(uint64_t size_) {
io_->seekOrThrow(io_->tell() + size_, BasicIo::beg, ErrorCode::kerFailedToReadImageData);
}
void RiffVideo::readDataChunk(uint64_t size_) {
void RiffVideo::readDataChunk(uint64_t size_) const {
#ifdef EXIV2_DEBUG_MESSAGES
EXV_INFO << "--> Data = " << readStringTag(io_, static_cast<size_t>(size_)) << std::endl;
uint64_t readed_size = size_;
@ -724,7 +724,7 @@ void RiffVideo::readDataChunk(uint64_t size_) {
io_->seekOrThrow(io_->tell() + 1, BasicIo::beg, ErrorCode::kerFailedToReadImageData);
}
void RiffVideo::readJunk(uint64_t size_) {
void RiffVideo::readJunk(uint64_t size_) const {
io_->seekOrThrow(io_->tell() + size_, BasicIo::beg, ErrorCode::kerFailedToReadImageData);
}

@ -1180,21 +1180,19 @@ static void findLensSpecFlags(const Value& value, std::string& flagsStart, std::
// https://github.com/exiftool/exiftool/blob/1e17485cbb372a502e5b9d052d01303db735e6fa/lib/Image/ExifTool/Sony.pm#L10545
const auto joinedV0V7 = ((value.toUint32(0) << 8) + value.toUint32(7));
auto temp = 0;
for (const auto& i : lSFArray) {
temp = i.mask & joinedV0V7;
if (temp) { // Check if a flag matches in the current LensSpecFlags
auto f = Exiv2::find(i.flags, temp);
if (!f) {
// Should never get in here. LensSpecFlags.mask should contain all the
// bits in all the LensSpecFlags.flags.val_ entries
throw Error(ErrorCode::kerErrorMessage,
std::string("LensSpecFlags mask doesn't match the bits in the flags array"));
if (auto temp = i.mask & joinedV0V7) { // Check if a flag matches in the current LensSpecFlags
if (auto f = Exiv2::find(i.flags, temp)) {
if (i.prepend)
flagsStart = (flagsStart.empty() ? f->label_ : f->label_ + std::string(" ") + flagsStart);
else
flagsEnd = (flagsEnd.empty() ? f->label_ : flagsEnd + std::string(" ") + f->label_);
continue;
}
if (i.prepend)
flagsStart = (flagsStart.empty() ? f->label_ : f->label_ + std::string(" ") + flagsStart);
else
flagsEnd = (flagsEnd.empty() ? f->label_ : flagsEnd + std::string(" ") + f->label_);
// Should never get in here. LensSpecFlags.mask should contain all the
// bits in all the LensSpecFlags.flags.val_ entries
throw Error(ErrorCode::kerErrorMessage,
std::string("LensSpecFlags mask doesn't match the bits in the flags array"));
}
}
}

@ -11,8 +11,6 @@
#include "tags_int.hpp"
#include "types.hpp"
#include <array>
// *****************************************************************************
// class member definitions
namespace Exiv2 {
@ -274,7 +272,7 @@ ExifKey& ExifKey::operator=(const ExifKey& rhs) {
return *this;
}
void ExifKey::setIdx(int idx) {
void ExifKey::setIdx(int idx) const {
p_->idx_ = idx;
}
@ -344,8 +342,7 @@ std::ostream& operator<<(std::ostream& os, const TagInfo& ti) {
// CSV encoded I am \"dead\" beat" => "I am ""dead"" beat"
char Q = '"';
os << Q;
for (size_t i = 0; i < exifKey.tagDesc().size(); i++) {
char c = exifKey.tagDesc()[i];
for (char c : exifKey.tagDesc()) {
if (c == Q)
os << Q;
os << c;

@ -2319,12 +2319,8 @@ const TagInfo* mnTagList() {
}
bool isMakerIfd(IfdId ifdId) {
bool rc = false;
auto ii = Exiv2::find(groupInfo, ifdId);
if (ii && 0 == strcmp(ii->ifdName_, "Makernote")) {
rc = true;
}
return rc;
return ii && strcmp(ii->ifdName_, "Makernote") == 0;
}
bool isExifIfd(IfdId ifdId) {
@ -2355,8 +2351,7 @@ bool isExifIfd(IfdId ifdId) {
}
void taglist(std::ostream& os, IfdId ifdId) {
const TagInfo* ti = Internal::tagList(ifdId);
if (ti) {
if (auto ti = tagList(ifdId)) {
for (int k = 0; ti[k].tag_ != 0xffff; ++k) {
os << ti[k] << "\n";
}
@ -2364,59 +2359,54 @@ void taglist(std::ostream& os, IfdId ifdId) {
} // taglist
const TagInfo* tagList(IfdId ifdId) {
auto ii = Exiv2::find(groupInfo, ifdId);
if (!ii || !ii->tagList_)
return nullptr;
return ii->tagList_();
if (auto ii = Exiv2::find(groupInfo, ifdId))
if (ii->tagList_)
return ii->tagList_();
return nullptr;
} // tagList
const TagInfo* tagInfo(uint16_t tag, IfdId ifdId) {
const TagInfo* ti = tagList(ifdId);
if (!ti)
return nullptr;
int idx = 0;
for (idx = 0; ti[idx].tag_ != 0xffff; ++idx) {
if (ti[idx].tag_ == tag)
break;
if (auto ti = tagList(ifdId)) {
int idx = 0;
for (idx = 0; ti[idx].tag_ != 0xffff; ++idx) {
if (ti[idx].tag_ == tag)
break;
}
return &ti[idx];
}
return &ti[idx];
return nullptr;
} // tagInfo
const TagInfo* tagInfo(const std::string& tagName, IfdId ifdId) {
const TagInfo* ti = tagList(ifdId);
if (!ti)
return nullptr;
if (tagName.empty())
return nullptr;
const char* tn = tagName.c_str();
for (int idx = 0; ti[idx].tag_ != 0xffff; ++idx) {
if (0 == strcmp(ti[idx].name_, tn)) {
return &ti[idx];
if (auto ti = tagList(ifdId)) {
const char* tn = tagName.c_str();
for (int idx = 0; ti[idx].tag_ != 0xffff; ++idx) {
if (0 == strcmp(ti[idx].name_, tn)) {
return &ti[idx];
}
}
}
return nullptr;
} // tagInfo
IfdId groupId(const std::string& groupName) {
IfdId ifdId = IfdId::ifdIdNotSet;
auto ii = Exiv2::find(groupInfo, groupName);
if (ii)
ifdId = static_cast<IfdId>(ii->ifdId_);
return ifdId;
if (auto ii = Exiv2::find(groupInfo, groupName))
return static_cast<IfdId>(ii->ifdId_);
return IfdId::ifdIdNotSet;
}
const char* ifdName(IfdId ifdId) {
auto ii = Exiv2::find(groupInfo, ifdId);
if (!ii)
return groupInfo[0].ifdName_;
return ii->ifdName_;
if (auto ii = Exiv2::find(groupInfo, ifdId))
return ii->ifdName_;
return groupInfo[0].ifdName_;
}
const char* groupName(IfdId ifdId) {
auto ii = Exiv2::find(groupInfo, ifdId);
if (!ii)
return groupInfo[0].groupName_;
return ii->groupName_;
if (auto ii = Exiv2::find(groupInfo, ifdId))
return ii->groupName_;
return groupInfo[0].groupName_;
}
std::ostream& printValue(std::ostream& os, const Value& value, const ExifData*) {
@ -2947,13 +2937,15 @@ std::ostream& print0xa001(std::ostream& os, const Value& value, const ExifData*
}
//! SensingMethod, tag 0xa217
constexpr TagDetails exifSensingMethod[] = {{1, N_("Not defined")},
{2, N_("One-chip color area")},
{3, N_("Two-chip color area")},
{4, N_("Three-chip color area")},
{5, N_("Color sequential area")},
{7, N_("Trilinear sensor")},
{8, N_("Color sequential linear")}};
constexpr TagDetails exifSensingMethod[] = {
{1, N_("Not defined")},
{2, N_("One-chip color area")},
{3, N_("Two-chip color area")},
{4, N_("Three-chip color area")},
{5, N_("Color sequential area")},
{7, N_("Trilinear sensor")},
{8, N_("Color sequential linear")},
};
std::ostream& print0xa217(std::ostream& os, const Value& value, const ExifData* metadata) {
return EXV_PRINT_TAG(exifSensingMethod)(os, value, metadata);
@ -2963,7 +2955,8 @@ std::ostream& print0xa217(std::ostream& os, const Value& value, const ExifData*
constexpr TagDetails exifFileSource[] = {
{1, N_("Film scanner")}, // Not defined to Exif 2.2 spec.
{2, N_("Reflexion print scanner")}, // but used by some scanner device softwares.
{3, N_("Digital still camera")}};
{3, N_("Digital still camera")},
};
std::ostream& print0xa300(std::ostream& os, const Value& value, const ExifData* metadata) {
return EXV_PRINT_TAG(exifFileSource)(os, value, metadata);

@ -2029,7 +2029,7 @@ ByteOrder TiffParserWorker::decode(ExifData& exifData, IptcData& iptcData, XmpDa
}
if (auto rootDir = parse(pData, size, root, pHeader)) {
TiffDecoder decoder(exifData, iptcData, xmpData, rootDir.get(), findDecoderFct);
auto decoder = TiffDecoder(exifData, iptcData, xmpData, rootDir.get(), findDecoderFct);
rootDir->accept(decoder);
}
return pHeader->byteOrder();

@ -39,13 +39,12 @@ class FindExifdatum2 {
}; // class FindExifdatum2
Exiv2::ByteOrder stringToByteOrder(const std::string& val) {
Exiv2::ByteOrder bo = Exiv2::invalidByteOrder;
if (val == "II")
bo = Exiv2::littleEndian;
else if (val == "MM")
bo = Exiv2::bigEndian;
return Exiv2::littleEndian;
if (val == "MM")
return Exiv2::bigEndian;
return bo;
return Exiv2::invalidByteOrder;
}
} // namespace
@ -500,7 +499,7 @@ void TiffEncoder::encodeIptc() {
if (rawIptc.size() % 4 != 0) {
// Pad the last unsignedLong value with 0s
buf.alloc((rawIptc.size() / 4) * 4 + 4);
std::copy(rawIptc.begin(), rawIptc.end(), buf.begin());
std::move(rawIptc.begin(), rawIptc.end(), buf.begin());
} else {
buf = std::move(rawIptc); // Note: This resets rawIptc
}
@ -1347,14 +1346,16 @@ void TiffReader::visitBinaryArray(TiffBinaryArray* object) {
// Check duplicates
TiffFinder finder(object->tag(), object->group());
pRoot_->accept(finder);
if (auto te = dynamic_cast<TiffEntryBase*>(finder.result()); te && te->idx() != object->idx()) {
if (auto te = dynamic_cast<TiffEntryBase*>(finder.result())) {
if (te->idx() != object->idx()) {
#ifndef SUPPRESS_WARNINGS
EXV_WARNING << "Not decoding duplicate binary array tag 0x" << std::setw(4) << std::setfill('0') << std::hex
<< object->tag() << std::dec << ", group " << groupName(object->group()) << ", idx " << object->idx()
<< "\n";
EXV_WARNING << "Not decoding duplicate binary array tag 0x" << std::setw(4) << std::setfill('0') << std::hex
<< object->tag() << std::dec << ", group " << groupName(object->group()) << ", idx " << object->idx()
<< "\n";
#endif
object->setDecoded(false);
return;
object->setDecoded(false);
return;
}
}
if (object->TiffEntryBase::doSize() == 0)

@ -69,24 +69,21 @@ constexpr struct TypeInfoTable {
// class member definitions
namespace Exiv2 {
const char* TypeInfo::typeName(TypeId typeId) {
auto tit = Exiv2::find(typeInfoTable, typeId);
if (!tit)
return nullptr;
return tit->name_;
if (auto tit = Exiv2::find(typeInfoTable, typeId))
return tit->name_;
return nullptr;
}
TypeId TypeInfo::typeId(const std::string& typeName) {
auto tit = Exiv2::find(typeInfoTable, typeName);
if (!tit)
return invalidTypeId;
return tit->typeId_;
if (auto tit = Exiv2::find(typeInfoTable, typeName))
return tit->typeId_;
return invalidTypeId;
}
size_t TypeInfo::typeSize(TypeId typeId) {
auto tit = Exiv2::find(typeInfoTable, typeId);
if (!tit)
return 0;
return tit->size_;
if (auto tit = Exiv2::find(typeInfoTable, typeId))
return tit->size_;
return 0;
}
DataBuf::DataBuf(size_t size) : pData_(size) {
@ -481,11 +478,7 @@ bool isHex(const std::string& str, size_t size, const std::string& prefix) {
if (size > 0 && str.size() != size + prefix.size())
return false;
for (size_t i = prefix.size(); i < str.size(); ++i) {
if (!isxdigit(str[i]))
return false;
}
return true;
return std::all_of(str.begin() + prefix.size(), str.end(), ::isxdigit);
} // isHex
int exifTime(const char* buf, tm* tm) {

Loading…
Cancel
Save