misc sonarlint cleanups

Signed-off-by: Rosen Penev <rosenp@gmail.com>
This commit is contained in:
Rosen Penev 2022-08-04 17:30:27 -07:00
parent 1602afef0a
commit b8855fb3b5
20 changed files with 161 additions and 216 deletions

View File

@ -395,13 +395,11 @@ void FileIo::transfer(BasicIo& src) {
EXV_WARNING << Error(ErrorCode::kerCallFailed, pf, strError(), "::stat") << "\n";
#endif
}
if (statOk && origStMode != buf2.st_mode) {
// Set original file permissions
if (::chmod(pf, origStMode) == -1) {
// Set original file permissions
if (statOk && origStMode != buf2.st_mode && ::chmod(pf, origStMode) == -1) {
#ifndef SUPPRESS_WARNINGS
EXV_WARNING << Error(ErrorCode::kerCallFailed, pf, strError(), "::chmod") << "\n";
EXV_WARNING << Error(ErrorCode::kerCallFailed, pf, strError(), "::chmod") << "\n";
#endif
}
}
}
} // if (fileIo)
@ -1316,7 +1314,7 @@ byte* RemoteIo::mmap(bool /*isWriteable*/) {
size_t blocks = (p_->size_ + blockSize - 1) / blockSize;
bigBlock_ = new byte[blocks * blockSize];
for (size_t block = 0; block < blocks; block++) {
void* p = p_->blocksMap_[block].getData();
auto p = p_->blocksMap_[block].getData();
if (p) {
size_t nRead = block == (blocks - 1) ? p_->size_ - nRealData : blockSize;
memcpy(bigBlock_ + (block * blockSize), p, nRead);

View File

@ -145,11 +145,13 @@ std::string BmffImage::uuidName(Exiv2::DataBuf& uuid) {
const char* uuidCano = "\x85\xC0\xB6\x87\x82\xF\x11\xE0\x81\x11\xF4\xCE\x46\x2B\x6A\x48";
const char* uuidXmp = "\xBE\x7A\xCF\xCB\x97\xA9\x42\xE8\x9C\x71\x99\x94\x91\xE3\xAF\xAC";
const char* uuidCanp = "\xEA\xF4\x2B\x5E\x1C\x98\x4B\x88\xB9\xFB\xB7\xDC\x40\x6E\x4D\x16";
const char* result = uuid.cmpBytes(0, uuidCano, 16) == 0 ? "cano"
: uuid.cmpBytes(0, uuidXmp, 16) == 0 ? "xmp"
: uuid.cmpBytes(0, uuidCanp, 16) == 0 ? "canp"
: "";
return result;
if (uuid.cmpBytes(0, uuidCano, 16) == 0)
return "cano";
if (uuid.cmpBytes(0, uuidXmp, 16) == 0)
return "xmp";
if (uuid.cmpBytes(0, uuidCanp, 16) == 0)
return "canp";
return "";
}
uint64_t BmffImage::boxHandler(std::ostream& out /* = std::cout*/, Exiv2::PrintStructureOption option /* = kpsNone */,
@ -345,9 +347,13 @@ uint64_t BmffImage::boxHandler(std::ostream& out /* = std::cout*/, Exiv2::PrintS
enforce(data.size() - skip >= (version > 2u ? 4u : 2u), Exiv2::ErrorCode::kerCorruptedMetadata);
enforce(data.size() - skip >= step, Exiv2::ErrorCode::kerCorruptedMetadata);
uint32_t ID = version > 2 ? data.read_uint32(skip, endian_) : data.read_uint16(skip, endian_);
uint32_t offset = step == 14 || step == 16 ? data.read_uint32(skip + step - 8, endian_)
: step == 18 ? data.read_uint32(skip + 4, endian_)
: 0;
auto offset = [=] {
if (step == 14 || step == 16)
return data.read_uint32(skip + step - 8, endian_);
if (step == 18)
return data.read_uint32(skip + 4, endian_);
return 0u;
}();
uint32_t ldata = data.read_uint32(skip + step - 4, endian_);
if (bTrace) {
@ -388,7 +394,7 @@ uint64_t BmffImage::boxHandler(std::ostream& out /* = std::cout*/, Exiv2::PrintS
uint8_t meth = data.read_uint8(skip + 0);
uint8_t prec = data.read_uint8(skip + 1);
uint8_t approx = data.read_uint8(skip + 2);
std::string colour_type = std::string(data.c_str(), 4);
auto colour_type = std::string(data.c_str(), 4);
skip += 4;
if (colour_type == "rICC" || colour_type == "prof") {
DataBuf profile(data.c_data(skip), data.size() - skip);
@ -554,14 +560,11 @@ void BmffImage::parseCr3Preview(DataBuf& data, std::ostream& out, bool bTrace, u
nativePreview.height_ = data.read_uint16(height_offset, endian_);
nativePreview.size_ = data.read_uint32(size_offset, endian_);
nativePreview.filter_ = "";
switch (version) {
case 0:
nativePreview.mimeType_ = "image/jpeg";
break;
default:
nativePreview.mimeType_ = "application/octet-stream";
break;
}
nativePreview.mimeType_ = [version] {
if (version == 0)
return "image/jpeg";
return "application/octet-stream";
}();
nativePreviews_.push_back(nativePreview);
if (bTrace) {
@ -639,7 +642,7 @@ void BmffImage::printStructure(std::ostream& out, Exiv2::PrintStructureOption op
io_->seek(address, BasicIo::beg);
address = boxHandler(out, option, file_end, depth);
}
}; break;
} break;
}
}

View File

@ -2582,7 +2582,7 @@ std::ostream& printCsLensFFFF(std::ostream& os, const Value& value, const ExifDa
return os << "Canon EF-S 24mm f/2.8 STM";
}
} catch (const std::exception&) {
};
}
return EXV_PRINT_TAG(canonCsLensType)(os, value, metadata);
}

View File

@ -183,7 +183,7 @@ void findXmp(size_t& xmpPos, size_t& xmpSize, const byte* data, size_t startPos,
if (data[xmpPos] != '\x00' && data[xmpPos] != '<')
continue;
for (auto&& xmpTrailer : xmpTrailers) {
auto [trailer, readOnly] = xmpTrailer;
const auto& [trailer, readOnly] = xmpTrailer;
if (trailerPos + trailer.size() > size)
continue;
@ -524,14 +524,12 @@ void readWriteEpsMetadata(BasicIo& io, std::string& xmpPacket, NativePreviewList
#endif
}
}
if (line == "%%EOF" || line == "%%Trailer") {
if (posPageTrailer == posEndEps) {
posPageTrailer = startPos;
implicitPageTrailer = true;
if ((line == "%%EOF" || line == "%%Trailer") && posPageTrailer == posEndEps) {
posPageTrailer = startPos;
implicitPageTrailer = true;
#ifdef DEBUG
EXV_DEBUG << "readWriteEpsMetadata: Found implicit PageTrailer at position: " << startPos << "\n";
EXV_DEBUG << "readWriteEpsMetadata: Found implicit PageTrailer at position: " << startPos << "\n";
#endif
}
}
// remaining explicit comments
if (posEndComments == posEndEps && posLanguageLevel == posEndEps && startsWith(line, "%%LanguageLevel:")) {
@ -702,7 +700,7 @@ void readWriteEpsMetadata(BasicIo& io, std::string& xmpPacket, NativePreviewList
if (posOtherXmp >= posEndPageSetup)
break;
bool isRemovableEmbedding = false;
for (auto&& [r, s] : removableEmbeddings) {
for (const auto& [r, s] : removableEmbeddings) {
if (r <= posOtherXmp && posOtherXmp < s) {
isRemovableEmbedding = true;
break;
@ -871,23 +869,20 @@ void readWriteEpsMetadata(BasicIo& io, std::string& xmpPacket, NativePreviewList
#endif
}
// update and complement DSC comments
if (pos == posLanguageLevel && posLanguageLevel != posEndEps && !deleteXmp && !useFlexibleEmbedding) {
if (line == "%%LanguageLevel:1" || line == "%%LanguageLevel: 1") {
writeTemp(tempIo, "%%LanguageLevel: 2" + lineEnding);
skipPos = posLineEnd;
if (pos == posLanguageLevel && posLanguageLevel != posEndEps && !deleteXmp && !useFlexibleEmbedding &&
(line == "%%LanguageLevel:1" || line == "%%LanguageLevel: 1")) {
writeTemp(tempIo, "%%LanguageLevel: 2" + lineEnding);
skipPos = posLineEnd;
#ifdef DEBUG
EXV_DEBUG << "readWriteEpsMetadata: Skipping to " << skipPos << " at " << __FILE__ << ":" << __LINE__ << "\n";
EXV_DEBUG << "readWriteEpsMetadata: Skipping to " << skipPos << " at " << __FILE__ << ":" << __LINE__ << "\n";
#endif
}
}
if (pos == posContainsXmp && posContainsXmp != posEndEps) {
if (line != containsXmpLine) {
writeTemp(tempIo, containsXmpLine + lineEnding);
skipPos = posLineEnd;
if (pos == posContainsXmp && posContainsXmp != posEndEps && line != containsXmpLine) {
writeTemp(tempIo, containsXmpLine + lineEnding);
skipPos = posLineEnd;
#ifdef DEBUG
EXV_DEBUG << "readWriteEpsMetadata: Skipping to " << skipPos << " at " << __FILE__ << ":" << __LINE__ << "\n";
EXV_DEBUG << "readWriteEpsMetadata: Skipping to " << skipPos << " at " << __FILE__ << ":" << __LINE__ << "\n";
#endif
}
}
if (pos == posExiv2Version && posExiv2Version != posEndEps) {
writeTemp(tempIo, "%Exiv2Version: " + versionNumberHexString() + lineEnding);
@ -924,29 +919,23 @@ void readWriteEpsMetadata(BasicIo& io, std::string& xmpPacket, NativePreviewList
writeTemp(tempIo, "%%EndComments" + lineEnding);
}
}
if (pos == posPage) {
if (!startsWith(line, "%%Page:")) {
writeTemp(tempIo, "%%Page: 1 1" + lineEnding);
writeTemp(tempIo, "%%EndPageComments" + lineEnding);
}
if (pos == posPage && !startsWith(line, "%%Page:")) {
writeTemp(tempIo, "%%Page: 1 1" + lineEnding);
writeTemp(tempIo, "%%EndPageComments" + lineEnding);
}
if (pos == posBeginPageSetup) {
if (line != "%%BeginPageSetup") {
writeTemp(tempIo, "%%BeginPageSetup" + lineEnding);
}
if (pos == posBeginPageSetup && line != "%%BeginPageSetup") {
writeTemp(tempIo, "%%BeginPageSetup" + lineEnding);
}
if (useFlexibleEmbedding) {
// insert XMP metadata into existing flexible embedding
if (pos == xmpPos) {
if (fixBeginXmlPacket) {
writeTemp(tempIo, "%begin_xml_packet: " + toString(xmpPacket.size()) + lineEnding);
}
writeTemp(tempIo, xmpPacket);
skipPos += xmpSize;
// insert XMP metadata into existing flexible embedding
if (useFlexibleEmbedding && pos == xmpPos) {
if (fixBeginXmlPacket) {
writeTemp(tempIo, "%begin_xml_packet: " + toString(xmpPacket.size()) + lineEnding);
}
writeTemp(tempIo, xmpPacket);
skipPos += xmpSize;
#ifdef DEBUG
EXV_DEBUG << "readWriteEpsMetadata: Skipping to " << skipPos << " at " << __FILE__ << ":" << __LINE__ << "\n";
EXV_DEBUG << "readWriteEpsMetadata: Skipping to " << skipPos << " at " << __FILE__ << ":" << __LINE__ << "\n";
#endif
}
}
if (!useFlexibleEmbedding) {
// remove preceding embedding(s)
@ -1009,26 +998,21 @@ void readWriteEpsMetadata(BasicIo& io, std::string& xmpPacket, NativePreviewList
writeTemp(tempIo, "%Exiv2EndXMP" + lineEnding);
}
}
if (pos == posEndPageSetup) {
if (line != "%%EndPageSetup") {
writeTemp(tempIo, "%%EndPageSetup" + lineEnding);
}
if (pos == posEndPageSetup && line != "%%EndPageSetup") {
writeTemp(tempIo, "%%EndPageSetup" + lineEnding);
}
if (!useFlexibleEmbedding) {
if (pos == posPageTrailer && !deleteXmp) {
if (!implicitPageTrailer) {
skipPos = posLineEnd;
if (!useFlexibleEmbedding && pos == posPageTrailer && !deleteXmp) {
if (!implicitPageTrailer) {
skipPos = posLineEnd;
#ifdef DEBUG
EXV_DEBUG << "readWriteEpsMetadata: Skipping to " << skipPos << " at " << __FILE__ << ":" << __LINE__
<< "\n";
EXV_DEBUG << "readWriteEpsMetadata: Skipping to " << skipPos << " at " << __FILE__ << ":" << __LINE__ << "\n";
#endif
}
writeTemp(tempIo, "%%PageTrailer" + lineEnding);
writeTemp(tempIo, "%Exiv2BeginXMP: After %%PageTrailer" + lineEnding);
writeTemp(tempIo, "[/EMC Exiv2_pdfmark" + lineEnding);
writeTemp(tempIo, "[/NamespacePop Exiv2_pdfmark" + lineEnding);
writeTemp(tempIo, "%Exiv2EndXMP" + lineEnding);
}
writeTemp(tempIo, "%%PageTrailer" + lineEnding);
writeTemp(tempIo, "%Exiv2BeginXMP: After %%PageTrailer" + lineEnding);
writeTemp(tempIo, "[/EMC Exiv2_pdfmark" + lineEnding);
writeTemp(tempIo, "[/NamespacePop Exiv2_pdfmark" + lineEnding);
writeTemp(tempIo, "%Exiv2EndXMP" + lineEnding);
}
// add EOF comment if necessary
if (pos == posEndEps && posEof == posEndEps) {
@ -1080,18 +1064,16 @@ void readWriteEpsMetadata(BasicIo& io, std::string& xmpPacket, NativePreviewList
namespace Exiv2 {
EpsImage::EpsImage(BasicIo::UniquePtr io, bool create) : Image(ImageType::eps, mdXmp, std::move(io)) {
// LogMsg::setLevel(LogMsg::debug);
if (create) {
if (io_->open() == 0) {
if (create && io_->open() == 0) {
#ifdef DEBUG
EXV_DEBUG << "Exiv2::EpsImage:: Creating blank EPS image\n";
EXV_DEBUG << "Exiv2::EpsImage:: Creating blank EPS image\n";
#endif
IoCloser closer(*io_);
if (io_->write(reinterpret_cast<const byte*>(epsBlank.data()), epsBlank.size()) != epsBlank.size()) {
IoCloser closer(*io_);
if (io_->write(reinterpret_cast<const byte*>(epsBlank.data()), epsBlank.size()) != epsBlank.size()) {
#ifndef SUPPRESS_WARNINGS
EXV_WARNING << "Failed to write blank EPS image.\n";
EXV_WARNING << "Failed to write blank EPS image.\n";
#endif
throw Error(ErrorCode::kerImageWriteFailed);
}
throw Error(ErrorCode::kerImageWriteFailed);
}
}
}

View File

@ -188,7 +188,7 @@ std::ostream& Exifdatum::write(std::ostream& os, const ExifData* pMetadata) cons
// cause a std::out_of_range exception to be thrown.
try {
fct(os, value(), pMetadata);
} catch (std::out_of_range&) {
} catch (const std::out_of_range&) {
os << "Bad value";
#ifdef EXIV2_DEBUG_MESSAGES
std::cerr << "Caught std::out_of_range exception in Exifdatum::write().\n";

View File

@ -78,7 +78,7 @@ constexpr TagDetails fujiContrast[] = {{0, N_("Normal")}, {256, N_("High")}, {76
//! WhiteBalanceFineTune, tag 0x100a
std::ostream& printFujiWhiteBalanceFineTune(std::ostream& os, const Value& value, const ExifData*) {
if (value.typeId() == signedLong && value.size() == 8) {
auto longValue = static_cast<const LongValue&>(value);
auto longValue = dynamic_cast<const LongValue&>(value);
if (longValue.toInt64(0) % 20 == 0 && longValue.toInt64(1) % 20 == 0) {
auto redShift = longValue.toInt64(0) / 20;
auto blueShift = longValue.toInt64(1) / 20;

View File

@ -513,7 +513,7 @@ XmpData& Image::xmpData() {
std::string& Image::xmpPacket() {
// Serialize the current XMP
if (xmpData_.count() > 0 && !writeXmpFromPacket()) {
if (!xmpData_.empty() && !writeXmpFromPacket()) {
XmpParser::encode(xmpPacket_, xmpData_, XmpParser::useCompactFormat | XmpParser::omitAllFormatting);
}
return xmpPacket_;

View File

@ -306,11 +306,8 @@ const char* IptcData::detectCharset() const {
auto pos = findKey(IptcKey("Iptc.Envelope.CharacterSet"));
if (pos != end()) {
const std::string value = pos->toString();
if (pos->value().ok()) {
if (value == "\033%G")
return "UTF-8";
// other values are probably not practically relevant
}
if (pos->value().ok() && value == "\033%G")
return "UTF-8";
}
bool ascii = true;
@ -320,7 +317,7 @@ const char* IptcData::detectCharset() const {
std::string value = pos->toString();
if (pos->value().ok()) {
int seqCount = 0;
for (auto&& c : value) {
for (auto c : value) {
if (seqCount) {
if ((c & 0xc0) != 0x80) {
utf8 = false;

View File

@ -802,12 +802,10 @@ void Jp2Image::doWriteMetadata(BasicIo& outIo) {
}
}
if (!writeXmpFromPacket()) {
if (XmpParser::encode(xmpPacket_, xmpData_) > 1) {
if (!writeXmpFromPacket() && XmpParser::encode(xmpPacket_, xmpData_) > 1) {
#ifndef SUPPRESS_WARNINGS
EXV_ERROR << "Failed to encode XMP metadata." << std::endl;
EXV_ERROR << "Failed to encode XMP metadata." << std::endl;
#endif
}
}
if (!xmpPacket_.empty()) {
// Update Xmp data to a new UUID box

View File

@ -251,7 +251,7 @@ void JpegBase::readMetadata() {
// Read the beginning of the next segment
try {
marker = advanceToMarker(ErrorCode::kerFailedToReadImageData);
} catch (Error&) {
} catch (const Error&) {
rc = 5;
break;
}
@ -742,12 +742,11 @@ void JpegBase::doWriteMetadata(BasicIo& outIo) {
--search;
}
}
if (!writeXmpFromPacket()) {
if (XmpParser::encode(xmpPacket_, xmpData_, XmpParser::useCompactFormat | XmpParser::omitAllFormatting) > 1) {
if (!writeXmpFromPacket() &&
XmpParser::encode(xmpPacket_, xmpData_, XmpParser::useCompactFormat | XmpParser::omitAllFormatting) > 1) {
#ifndef SUPPRESS_WARNINGS
EXV_ERROR << "Failed to encode XMP metadata.\n";
EXV_ERROR << "Failed to encode XMP metadata.\n";
#endif
}
}
if (!xmpPacket_.empty()) {
std::array<byte, 33> tmpBuf;

View File

@ -71,7 +71,7 @@ std::string getExiv2ConfigPath() {
currentPath = buffer;
}
#else
struct passwd* pw = getpwuid(getuid());
auto pw = getpwuid(getuid());
currentPath = std::string(pw ? pw->pw_dir : "");
#endif
return (currentPath / inifile).string();
@ -815,9 +815,8 @@ TiffComponent* newSony2Mn2(uint16_t tag, IfdId group, IfdId mnGroup) {
TiffComponent* newCasioMn(uint16_t tag, IfdId group, IfdId /* mnGroup*/, const byte* pData, size_t size,
ByteOrder /* byteOrder */) {
if (size > 6 && std::string(reinterpret_cast<const char*>(pData), 6) == std::string("QVC\0\0\0", 6)) {
if (size > 6 && std::string(reinterpret_cast<const char*>(pData), 6) == std::string("QVC\0\0\0", 6))
return newCasio2Mn2(tag, group, IfdId::casio2Id);
};
// Require at least an IFD with 1 entry, but not necessarily a next pointer
if (size < 14)
return nullptr;

View File

@ -1188,14 +1188,10 @@ std::ostream& OlympusMakerNote::print0x1015(std::ostream& os, const Value& value
auto l0 = value.toInt64(0);
auto l1 = value.toInt64(1);
if (l0 == 1) {
switch (l1) {
case 0:
os << _("Auto");
break;
default:
os << _("Auto") << " (" << l1 << ")";
break;
}
if (l1 == 0)
os << _("Auto");
else
os << _("Auto") << " (" << l1 << ")";
} else if (l0 == 2) {
switch (l1) {
case 2:
@ -1224,17 +1220,12 @@ std::ostream& OlympusMakerNote::print0x1015(std::ostream& os, const Value& value
break;
}
} else if (l0 == 3) {
switch (l1) {
case 0:
os << _("One-touch");
break;
default:
os << value;
break;
}
} else {
if (l1 == 0)
os << _("One-touch");
else
os << value;
} else
return os << value;
}
} else {
return os << value;
}
@ -1380,7 +1371,7 @@ std::ostream& OlympusMakerNote::print0x0201(std::ostream& os, const Value& value
auto v2 = static_cast<byte>(value.toInt64(2));
auto v3 = static_cast<byte>(value.toInt64(3));
for (auto&& type : lensTypes) {
for (const auto& type : lensTypes) {
if (type.val[0] == v0 && type.val[1] == v2 && type.val[2] == v3) {
return os << type.label;
}
@ -1423,7 +1414,7 @@ std::ostream& OlympusMakerNote::printEq0x0301(std::ostream& os, const Value& val
auto v0 = static_cast<byte>(value.toInt64(0));
auto v2 = static_cast<byte>(value.toInt64(2));
for (auto&& model : extenderModels) {
for (const auto& model : extenderModels) {
if (model.val[0] == v0 && model.val[1] == v2) {
return os << model.label;
}

View File

@ -56,12 +56,11 @@ void OrfImage::printStructure(std::ostream& out, PrintStructureOption option, si
if (io_->open() != 0)
throw Error(ErrorCode::kerDataSourceOpenFailed, io_->path(), strError());
// Ensure that this is the correct image type
if (imageType() == ImageType::none)
if (!isOrfType(*io_, false)) {
if (io_->error() || io_->eof())
throw Error(ErrorCode::kerFailedToReadImageData);
throw Error(ErrorCode::kerNotAJpeg);
}
if (imageType() == ImageType::none && !isOrfType(*io_, false)) {
if (io_->error() || io_->eof())
throw Error(ErrorCode::kerFailedToReadImageData);
throw Error(ErrorCode::kerNotAJpeg);
}
io_->seek(0, BasicIo::beg);
@ -95,15 +94,13 @@ void OrfImage::writeMetadata() {
byte* pData = nullptr;
size_t size = 0;
IoCloser closer(*io_);
if (io_->open() == 0) {
// Ensure that this is the correct image type
if (isOrfType(*io_, false)) {
pData = io_->mmap(true);
size = io_->size();
OrfHeader orfHeader;
if (0 == orfHeader.read(pData, 8)) {
bo = orfHeader.byteOrder();
}
// Ensure that this is the correct image type
if (io_->open() == 0 && isOrfType(*io_, false)) {
pData = io_->mmap(true);
size = io_->size();
OrfHeader orfHeader;
if (0 == orfHeader.read(pData, 8)) {
bo = orfHeader.byteOrder();
}
}
if (bo == invalidByteOrder) {

View File

@ -550,17 +550,16 @@ std::ostream& PanasonicMakerNote::print0x0033(std::ostream& os, const Value& val
os << N_("not set");
} else {
os << value;
};
}
return os;
} // PanasonicMakerNote::print0x0033
// Travel days
std::ostream& PanasonicMakerNote::print0x0036(std::ostream& os, const Value& value, const ExifData*) {
if (value.toInt64() == 65535) {
if (value.toInt64() == 65535)
os << N_("not set");
} else {
else
os << value;
};
return os;
} // PanasonicMakerNote::print0x0036
@ -576,7 +575,7 @@ std::ostream& PanasonicMakerNote::print0x003c(std::ostream& os, const Value& val
default:
os << value;
break;
};
}
return os;
} // PanasonicMakerNote::print0x003c
@ -596,14 +595,10 @@ std::ostream& PanasonicMakerNote::printPanasonicText(std::ostream& os, const Val
// Manometer Pressure
std::ostream& PanasonicMakerNote::printPressure(std::ostream& os, const Value& value, const ExifData*) {
switch (value.toInt64()) {
case 65535:
os << N_("infinite");
break;
default:
os << value << N_(" hPa");
break;
};
if (value.toInt64() == 65535)
os << N_("infinite");
else
os << value << N_(" hPa");
return os;
} // PanasonicMakerNote::printPressure

View File

@ -51,17 +51,15 @@ static uint32_t byteSwap_(Exiv2::DataBuf& buf, size_t offset, bool bSwap) {
PgfImage::PgfImage(BasicIo::UniquePtr io, bool create) :
Image(ImageType::pgf, mdExif | mdIptc | mdXmp | mdComment, std::move(io)), bSwap_(isBigEndianPlatform()) {
if (create) {
if (io_->open() == 0) {
if (create && io_->open() == 0) {
#ifdef EXIV2_DEBUG_MESSAGES
std::cerr << "Exiv2::PgfImage:: Creating PGF image to memory\n";
std::cerr << "Exiv2::PgfImage:: Creating PGF image to memory\n";
#endif
IoCloser closer(*io_);
if (io_->write(pgfBlank, sizeof(pgfBlank)) != sizeof(pgfBlank)) {
IoCloser closer(*io_);
if (io_->write(pgfBlank, sizeof(pgfBlank)) != sizeof(pgfBlank)) {
#ifdef EXIV2_DEBUG_MESSAGES
std::cerr << "Exiv2::PgfImage:: Failed to create PGF image on memory\n";
std::cerr << "Exiv2::PgfImage:: Failed to create PGF image on memory\n";
#endif
}
}
}
} // PgfImage::PgfImage

View File

@ -288,23 +288,21 @@ void PngChunk::parseChunkContent(Image* pImage, const byte* key, size_t keySize,
// We look if an Adobe XMP string exist.
if (keySize >= 17 && memcmp("XML:com.adobe.xmp", key, 17) == 0 && pImage->xmpData().empty()) {
if (!arr.empty()) {
std::string& xmpPacket = pImage->xmpPacket();
xmpPacket.assign(arr.c_str(), arr.size());
std::string::size_type idx = xmpPacket.find_first_of('<');
if (idx != std::string::npos && idx > 0) {
if (keySize >= 17 && memcmp("XML:com.adobe.xmp", key, 17) == 0 && pImage->xmpData().empty() && !arr.empty()) {
std::string& xmpPacket = pImage->xmpPacket();
xmpPacket.assign(arr.c_str(), arr.size());
std::string::size_type idx = xmpPacket.find_first_of('<');
if (idx != std::string::npos && idx > 0) {
#ifndef SUPPRESS_WARNINGS
EXV_WARNING << "Removing " << idx << " characters "
<< "from the beginning of the XMP packet\n";
EXV_WARNING << "Removing " << idx << " characters "
<< "from the beginning of the XMP packet\n";
#endif
xmpPacket = xmpPacket.substr(idx);
}
if (XmpParser::decode(pImage->xmpData(), xmpPacket)) {
xmpPacket = xmpPacket.substr(idx);
}
if (XmpParser::decode(pImage->xmpData(), xmpPacket)) {
#ifndef SUPPRESS_WARNINGS
EXV_WARNING << "Failed to decode XMP metadata.\n";
EXV_WARNING << "Failed to decode XMP metadata.\n";
#endif
}
}
}
@ -593,8 +591,8 @@ std::string PngChunk::writeRawProfile(const std::string& profileData, const char
for (std::string::size_type i = 0; i < profileData.size(); ++i) {
if (i % 36 == 0)
oss << '\n';
oss << hex[((*sp >> 4) & 0x0fU)];
oss << hex[((*sp++) & 0x0fU)];
oss << hex[*sp >> 4 & 0x0fU];
oss << hex[*sp++ & 0x0fU];
}
oss << '\n';
return oss.str();

View File

@ -53,17 +53,15 @@ using namespace Internal;
PngImage::PngImage(BasicIo::UniquePtr io, bool create) :
Image(ImageType::png, mdExif | mdIptc | mdXmp | mdComment, std::move(io)) {
if (create) {
if (io_->open() == 0) {
if (create && io_->open() == 0) {
#ifdef EXIV2_DEBUG_MESSAGES
std::cerr << "Exiv2::PngImage:: Creating PNG image to memory\n";
std::cerr << "Exiv2::PngImage:: Creating PNG image to memory\n";
#endif
IoCloser closer(*io_);
if (io_->write(pngBlank, sizeof(pngBlank)) != sizeof(pngBlank)) {
IoCloser closer(*io_);
if (io_->write(pngBlank, sizeof(pngBlank)) != sizeof(pngBlank)) {
#ifdef EXIV2_DEBUG_MESSAGES
std::cerr << "Exiv2::PngImage:: Failed to create PNG image on memory\n";
std::cerr << "Exiv2::PngImage:: Failed to create PNG image on memory\n";
#endif
}
}
}
}
@ -572,7 +570,7 @@ void PngImage::doWriteMetadata(BasicIo& outIo) {
}
}
if (exifData_.count() > 0) {
if (!exifData_.empty()) {
// Update Exif data to a new PNG chunk
Blob blob;
ExifParser::encode(blob, littleEndian, exifData_);
@ -587,7 +585,7 @@ void PngImage::doWriteMetadata(BasicIo& outIo) {
}
}
if (iptcData_.count() > 0) {
if (!iptcData_.empty()) {
// Update IPTC data to a new PNG chunk
DataBuf newPsData = Photoshop::setIptcIrb(nullptr, 0, iptcData_);
if (!newPsData.empty()) {
@ -630,12 +628,10 @@ void PngImage::doWriteMetadata(BasicIo& outIo) {
}
}
if (!writeXmpFromPacket()) {
if (XmpParser::encode(xmpPacket_, xmpData_) > 1) {
if (!writeXmpFromPacket() && XmpParser::encode(xmpPacket_, xmpData_) > 1) {
#ifndef SUPPRESS_WARNINGS
EXV_ERROR << "Failed to encode XMP metadata.\n";
EXV_ERROR << "Failed to encode XMP metadata.\n";
#endif
}
}
if (!xmpPacket_.empty()) {
// Update XMP data to a new PNG chunk

View File

@ -4912,18 +4912,15 @@ XmpNsInfo::Prefix::Prefix(std::string prefix) : prefix_(std::move(prefix)) {
}
bool XmpNsInfo::operator==(const XmpNsInfo::Ns& ns) const {
std::string n(ns_);
return n == ns.ns_;
return ns_ == ns.ns_;
}
bool XmpNsInfo::operator==(const XmpNsInfo::Prefix& prefix) const {
std::string p(prefix_);
return p == prefix.prefix_;
return prefix_ == prefix.prefix_;
}
bool XmpPropertyInfo::operator==(const std::string& name) const {
std::string n(name_);
return n == name;
return name_ == name;
}
XmpProperties::NsRegistry XmpProperties::nsRegistry_;
@ -4931,20 +4928,20 @@ std::mutex XmpProperties::mutex_;
/// \todo not used internally. At least we should test it
const XmpNsInfo* XmpProperties::lookupNsRegistry(const XmpNsInfo::Prefix& prefix) {
auto scoped_read_lock = std::scoped_lock(mutex_);
auto scopedReadLock = std::scoped_lock(mutex_);
return lookupNsRegistryUnsafe(prefix);
}
const XmpNsInfo* XmpProperties::lookupNsRegistryUnsafe(const XmpNsInfo::Prefix& prefix) {
for (auto&& ns : nsRegistry_) {
if (ns.second == prefix)
return &(ns.second);
for (const auto& [_, p] : nsRegistry_) {
if (p == prefix)
return &p;
}
return nullptr;
}
void XmpProperties::registerNs(const std::string& ns, const std::string& prefix) {
auto scoped_write_lock = std::scoped_lock(mutex_);
auto scopedWriteLock = std::scoped_lock(mutex_);
std::string ns2 = ns;
if (ns2.substr(ns2.size() - 1, 1) != "/" && ns2.substr(ns2.size() - 1, 1) != "#")
ns2 += "/";

View File

@ -584,7 +584,7 @@ uint32_t PsdImage::writeExifData(const ExifData& exifData, BasicIo& out) {
uint32_t resLength = 0;
byte buf[8];
if (exifData.count() > 0) {
if (!exifData.empty()) {
Blob blob;
ByteOrder bo = byteOrder();
if (bo == invalidByteOrder) {
@ -634,12 +634,10 @@ uint32_t PsdImage::writeXmpData(const XmpData& xmpData, BasicIo& out) const {
std::cerr << "writeXmpFromPacket(): " << writeXmpFromPacket() << "\n";
#endif
// writeXmpFromPacket(true);
if (!writeXmpFromPacket()) {
if (XmpParser::encode(xmpPacket, xmpData) > 1) {
if (!writeXmpFromPacket() && XmpParser::encode(xmpPacket, xmpData) > 1) {
#ifndef SUPPRESS_WARNINGS
EXV_ERROR << "Failed to encode XMP metadata.\n";
EXV_ERROR << "Failed to encode XMP metadata.\n";
#endif
}
}
if (!xmpPacket.empty()) {

View File

@ -66,12 +66,11 @@ void Rw2Image::printStructure(std::ostream& out, PrintStructureOption option, si
if (io_->open() != 0)
throw Error(ErrorCode::kerDataSourceOpenFailed, io_->path(), strError());
// Ensure that this is the correct image type
if (imageType() == ImageType::none)
if (!isRw2Type(*io_, false)) {
if (io_->error() || io_->eof())
throw Error(ErrorCode::kerFailedToReadImageData);
throw Error(ErrorCode::kerNotAJpeg);
}
if (imageType() == ImageType::none && !isRw2Type(*io_, false)) {
if (io_->error() || io_->eof())
throw Error(ErrorCode::kerFailedToReadImageData);
throw Error(ErrorCode::kerNotAJpeg);
}
io_->seek(0, BasicIo::beg);
@ -121,7 +120,7 @@ void Rw2Image::readMetadata() {
ExifData& prevData = image->exifData();
if (!prevData.empty()) {
// Filter duplicate tags
for (auto&& pos : exifData_) {
for (const auto& pos : exifData_) {
if (pos.ifdId() == IfdId::panaRawId)
continue;
auto dup = prevData.findKey(ExifKey(pos.key()));
@ -176,7 +175,7 @@ void Rw2Image::readMetadata() {
}
// Add the remaining tags
for (auto&& pos : prevData) {
for (const auto& pos : prevData) {
exifData_.add(pos);
}