More conversions to size_t while removing static_casts
This commit is contained in:
parent
7576a2757b
commit
4355d635d4
@ -22,10 +22,10 @@ namespace Exiv2 {
|
||||
|
||||
//! Native preview information. This is meant to be used only by the PreviewManager.
|
||||
struct NativePreview {
|
||||
long position_; //!< Position
|
||||
uint32_t size_; //!< Size
|
||||
uint32_t width_; //!< Width
|
||||
uint32_t height_; //!< Height
|
||||
size_t position_; //!< Position
|
||||
size_t size_; //!< Size
|
||||
size_t width_; //!< Width
|
||||
size_t height_; //!< Height
|
||||
std::string filter_; //!< Filter
|
||||
std::string mimeType_; //!< MIME type
|
||||
};
|
||||
|
||||
@ -82,21 +82,15 @@ namespace Exiv2 {
|
||||
with data in ORF format to the provided metadata containers.
|
||||
See TiffParser::decode().
|
||||
*/
|
||||
static ByteOrder decode(
|
||||
ExifData& exifData,
|
||||
IptcData& iptcData,
|
||||
XmpData& xmpData,
|
||||
const byte* pData,
|
||||
uint32_t size
|
||||
);
|
||||
static ByteOrder decode(ExifData& exifData, IptcData& iptcData, XmpData& xmpData, const byte* pData,
|
||||
size_t size);
|
||||
/*!
|
||||
@brief Encode metadata from the provided metadata to ORF format.
|
||||
See TiffParser::encode().
|
||||
*/
|
||||
static WriteMethod encode(
|
||||
BasicIo& io,
|
||||
static WriteMethod encode(BasicIo& io,
|
||||
const byte* pData,
|
||||
uint32_t size,
|
||||
size_t size,
|
||||
ByteOrder byteOrder,
|
||||
const ExifData& exifData,
|
||||
const IptcData& iptcData,
|
||||
|
||||
@ -77,7 +77,7 @@ namespace Exiv2
|
||||
//! Read Magick number. Only version >= 6 is supported.
|
||||
static byte readPgfMagicNumber(BasicIo& iIo);
|
||||
//! Read PGF Header size encoded in 32 bits integer.
|
||||
uint32_t readPgfHeaderSize(BasicIo& iIo) const;
|
||||
size_t readPgfHeaderSize(BasicIo& iIo) const;
|
||||
//! Read header structure.
|
||||
DataBuf readPgfHeaderStructure(BasicIo& iIo, uint32_t& width, uint32_t& height) const;
|
||||
//@}
|
||||
|
||||
@ -21,19 +21,14 @@ namespace Exiv2 {
|
||||
/*!
|
||||
@brief Preview image properties.
|
||||
*/
|
||||
struct EXIV2API PreviewProperties {
|
||||
//! Preview image mime type.
|
||||
std::string mimeType_;
|
||||
//! Preview image extension.
|
||||
std::string extension_;
|
||||
//! Preview image size in bytes.
|
||||
size_t size_;
|
||||
//! Preview image width in pixels or 0 for unknown width.
|
||||
uint32_t width_;
|
||||
//! Preview image height in pixels or 0 for unknown height.
|
||||
uint32_t height_;
|
||||
//! Identifies type of preview image.
|
||||
PreviewId id_;
|
||||
struct EXIV2API PreviewProperties
|
||||
{
|
||||
std::string mimeType_; //!< Preview image mime type.
|
||||
std::string extension_; //!< Preview image extension.
|
||||
size_t size_; //!< Preview image size in bytes.
|
||||
size_t width_; //!< Preview image width in pixels or 0 for unknown width.
|
||||
size_t height_; //!< Preview image height in pixels or 0 for unknown height.
|
||||
PreviewId id_; //!< Identifies type of preview image.
|
||||
};
|
||||
|
||||
//! Container type to hold all preview images metadata.
|
||||
@ -97,11 +92,11 @@ namespace Exiv2 {
|
||||
/*!
|
||||
@brief Return the width of the preview image in pixels.
|
||||
*/
|
||||
uint32_t width() const;
|
||||
size_t width() const;
|
||||
/*!
|
||||
@brief Return the height of the preview image in pixels.
|
||||
*/
|
||||
uint32_t height() const;
|
||||
size_t height() const;
|
||||
/*!
|
||||
@brief Return the preview image type identifier.
|
||||
*/
|
||||
|
||||
@ -95,12 +95,11 @@ namespace Exiv2 {
|
||||
with data in RW2 format to the provided metadata containers.
|
||||
See TiffParser::decode().
|
||||
*/
|
||||
static ByteOrder decode(
|
||||
ExifData& exifData,
|
||||
static ByteOrder decode(ExifData& exifData,
|
||||
IptcData& iptcData,
|
||||
XmpData& xmpData,
|
||||
const byte* pData,
|
||||
uint32_t size
|
||||
size_t size
|
||||
);
|
||||
|
||||
}; // class Rw2Parser
|
||||
|
||||
@ -152,10 +152,9 @@ namespace Exiv2 {
|
||||
|
||||
@return Write method used.
|
||||
*/
|
||||
static WriteMethod encode(
|
||||
BasicIo& io,
|
||||
static WriteMethod encode(BasicIo& io,
|
||||
const byte* pData,
|
||||
uint32_t size,
|
||||
size_t size,
|
||||
ByteOrder byteOrder,
|
||||
const ExifData& exifData,
|
||||
const IptcData& iptcData,
|
||||
|
||||
@ -221,9 +221,8 @@ namespace Exiv2::Internal {
|
||||
return false;
|
||||
header_.alloc(sizeOfSignature());
|
||||
header_.copyBytes(0, pData, header_.size());
|
||||
return !(static_cast<uint32_t>(header_.size()) < sizeOfSignature() ||
|
||||
0 != header_.cmpBytes(0, signature_, 6));
|
||||
} // OlympusMnHeader::read
|
||||
return !(header_.size() < sizeOfSignature() || 0 != header_.cmpBytes(0, signature_, 6));
|
||||
}
|
||||
|
||||
size_t OlympusMnHeader::write(IoWrapper& ioWrapper, ByteOrder /*byteOrder*/) const
|
||||
{
|
||||
@ -266,9 +265,8 @@ namespace Exiv2::Internal {
|
||||
return false;
|
||||
header_.alloc(sizeOfSignature());
|
||||
header_.copyBytes(0, pData, header_.size());
|
||||
return !(static_cast<uint32_t>(header_.size()) < sizeOfSignature() ||
|
||||
0 != header_.cmpBytes(0, signature_, 10));
|
||||
} // Olympus2MnHeader::read
|
||||
return !(header_.size() < sizeOfSignature() || 0 != header_.cmpBytes(0, signature_, 10));
|
||||
}
|
||||
|
||||
size_t Olympus2MnHeader::write(IoWrapper& ioWrapper,
|
||||
ByteOrder /*byteOrder*/) const
|
||||
@ -321,9 +319,8 @@ namespace Exiv2::Internal {
|
||||
// Read offset to the IFD relative to the start of the makernote
|
||||
// from the header. Note that we ignore the byteOrder argument
|
||||
start_ = header_.read_uint32(8, byteOrder_);
|
||||
return !(static_cast<uint32_t>(header_.size()) < sizeOfSignature() ||
|
||||
0 != header_.cmpBytes(0, signature_, 8));
|
||||
} // FujiMnHeader::read
|
||||
return !(header_.size() < sizeOfSignature() || 0 != header_.cmpBytes(0, signature_, 8));
|
||||
}
|
||||
|
||||
size_t FujiMnHeader::write(IoWrapper& ioWrapper,
|
||||
ByteOrder /*byteOrder*/) const
|
||||
@ -426,8 +423,7 @@ namespace Exiv2::Internal {
|
||||
return true;
|
||||
} // Nikon3MnHeader::read
|
||||
|
||||
size_t Nikon3MnHeader::write(IoWrapper& ioWrapper,
|
||||
ByteOrder byteOrder) const
|
||||
size_t Nikon3MnHeader::write(IoWrapper& ioWrapper, ByteOrder byteOrder) const
|
||||
{
|
||||
assert(buf_.size() >= 10);
|
||||
|
||||
@ -436,8 +432,8 @@ namespace Exiv2::Internal {
|
||||
TiffHeader th(byteOrder);
|
||||
DataBuf buf = th.write();
|
||||
ioWrapper.write(buf.c_data(), buf.size());
|
||||
return 10 + static_cast<uint32_t>(buf.size());
|
||||
} // Nikon3MnHeader::write
|
||||
return 10 + buf.size();
|
||||
}
|
||||
|
||||
void Nikon3MnHeader::setByteOrder(ByteOrder byteOrder)
|
||||
{
|
||||
@ -514,16 +510,14 @@ namespace Exiv2::Internal {
|
||||
return sizeOfSignature();
|
||||
}
|
||||
|
||||
bool PentaxDngMnHeader::read(const byte* pData,
|
||||
size_t size,
|
||||
ByteOrder /*byteOrder*/)
|
||||
bool PentaxDngMnHeader::read(const byte* pData, size_t size, ByteOrder /*byteOrder*/)
|
||||
{
|
||||
if (!pData || size < sizeOfSignature()) return false;
|
||||
if (!pData || size < sizeOfSignature())
|
||||
return false;
|
||||
header_.alloc(sizeOfSignature());
|
||||
header_.copyBytes(0, pData, header_.size());
|
||||
return !(static_cast<uint32_t>(header_.size()) < sizeOfSignature() ||
|
||||
0 != header_.cmpBytes(0, signature_, 7));
|
||||
} // PentaxDngMnHeader::read
|
||||
return !(header_.size() < sizeOfSignature() || 0 != header_.cmpBytes(0, signature_, 7));
|
||||
}
|
||||
|
||||
size_t PentaxDngMnHeader::write(IoWrapper& ioWrapper,
|
||||
ByteOrder /*byteOrder*/) const
|
||||
@ -556,23 +550,20 @@ namespace Exiv2::Internal {
|
||||
return sizeOfSignature();
|
||||
}
|
||||
|
||||
bool PentaxMnHeader::read(const byte* pData,
|
||||
size_t size,
|
||||
ByteOrder /*byteOrder*/)
|
||||
bool PentaxMnHeader::read(const byte* pData, size_t size, ByteOrder /*byteOrder*/)
|
||||
{
|
||||
if (!pData || size < sizeOfSignature()) return false;
|
||||
if (!pData || size < sizeOfSignature())
|
||||
return false;
|
||||
header_.alloc(sizeOfSignature());
|
||||
header_.copyBytes(0, pData, header_.size());
|
||||
return !(static_cast<uint32_t>(header_.size()) < sizeOfSignature() ||
|
||||
0 != header_.cmpBytes(0, signature_, 3));
|
||||
} // PentaxMnHeader::read
|
||||
return !(header_.size() < sizeOfSignature() || 0 != header_.cmpBytes(0, signature_, 3));
|
||||
}
|
||||
|
||||
size_t PentaxMnHeader::write(IoWrapper& ioWrapper,
|
||||
ByteOrder /*byteOrder*/) const
|
||||
size_t PentaxMnHeader::write(IoWrapper& ioWrapper, ByteOrder /*byteOrder*/) const
|
||||
{
|
||||
ioWrapper.write(signature_, sizeOfSignature());
|
||||
return sizeOfSignature();
|
||||
} // PentaxMnHeader::write
|
||||
}
|
||||
|
||||
SamsungMnHeader::SamsungMnHeader()
|
||||
{
|
||||
|
||||
@ -1173,7 +1173,7 @@ namespace Exiv2::Internal {
|
||||
return os << value;
|
||||
}
|
||||
if (value.count() == 1) {
|
||||
auto l0 = static_cast<short>(value.toInt64(0));
|
||||
auto l0 = value.toInt64(0);
|
||||
if (l0 == 1) {
|
||||
os << _("Auto");
|
||||
}
|
||||
@ -1182,8 +1182,8 @@ namespace Exiv2::Internal {
|
||||
}
|
||||
}
|
||||
else if (value.count() == 2) {
|
||||
auto l0 = static_cast<short>(value.toInt64(0));
|
||||
auto l1 = static_cast<short>(value.toInt64(1));
|
||||
auto l0 = value.toInt64(0);
|
||||
auto l1 = value.toInt64(1);
|
||||
if (l0 == 1) {
|
||||
switch (l1) {
|
||||
case 0: os << _("Auto"); break;
|
||||
|
||||
@ -86,10 +86,9 @@ namespace Exiv2 {
|
||||
throw Error(ErrorCode::kerNotAnImage, "ORF");
|
||||
}
|
||||
clearMetadata();
|
||||
ByteOrder bo =
|
||||
OrfParser::decode(exifData_, iptcData_, xmpData_, io_->mmap(), static_cast<uint32_t>(io_->size()));
|
||||
ByteOrder bo = OrfParser::decode(exifData_, iptcData_, xmpData_, io_->mmap(), io_->size());
|
||||
setByteOrder(bo);
|
||||
} // OrfImage::readMetadata
|
||||
}
|
||||
|
||||
void OrfImage::writeMetadata()
|
||||
{
|
||||
@ -98,13 +97,13 @@ namespace Exiv2 {
|
||||
#endif
|
||||
ByteOrder bo = byteOrder();
|
||||
byte* pData = nullptr;
|
||||
long size = 0;
|
||||
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 = static_cast<long>(io_->size());
|
||||
size = io_->size();
|
||||
OrfHeader orfHeader;
|
||||
if (0 == orfHeader.read(pData, 8)) {
|
||||
bo = orfHeader.byteOrder();
|
||||
@ -118,13 +117,8 @@ namespace Exiv2 {
|
||||
OrfParser::encode(*io_, pData, size, bo, exifData_, iptcData_, xmpData_); // may throw
|
||||
} // OrfImage::writeMetadata
|
||||
|
||||
ByteOrder OrfParser::decode(
|
||||
ExifData& exifData,
|
||||
IptcData& iptcData,
|
||||
XmpData& xmpData,
|
||||
const byte* pData,
|
||||
uint32_t size
|
||||
)
|
||||
ByteOrder OrfParser::decode(ExifData& exifData, IptcData& iptcData, XmpData& xmpData, const byte* pData,
|
||||
size_t size)
|
||||
{
|
||||
OrfHeader orfHeader;
|
||||
return TiffParserWorker::decode(exifData,
|
||||
@ -140,7 +134,7 @@ namespace Exiv2 {
|
||||
WriteMethod OrfParser::encode(
|
||||
BasicIo& io,
|
||||
const byte* pData,
|
||||
uint32_t size,
|
||||
size_t size,
|
||||
ByteOrder byteOrder,
|
||||
const ExifData& exifData,
|
||||
const IptcData& iptcData,
|
||||
|
||||
@ -94,16 +94,12 @@ namespace Exiv2 {
|
||||
|
||||
readPgfMagicNumber(*io_);
|
||||
|
||||
uint32_t headerSize = readPgfHeaderSize(*io_);
|
||||
size_t headerSize = readPgfHeaderSize(*io_);
|
||||
readPgfHeaderStructure(*io_, pixelWidth_, pixelHeight_);
|
||||
|
||||
// And now, the most interesting, the user data byte array where metadata are stored as small image.
|
||||
|
||||
enforce(headerSize <= std::numeric_limits<uint32_t>::max() - 8, ErrorCode::kerCorruptedMetadata);
|
||||
#if LONG_MAX < UINT_MAX
|
||||
enforce(headerSize + 8 <= static_cast<uint32_t>(std::numeric_limits<long>::max()),
|
||||
ErrorCode::kerCorruptedMetadata);
|
||||
#endif
|
||||
enforce(headerSize <= std::numeric_limits<size_t>::max() - 8, ErrorCode::kerCorruptedMetadata);
|
||||
long size = static_cast<long>(headerSize) + 8 - io_->tell();
|
||||
|
||||
#ifdef EXIV2_DEBUG_MESSAGES
|
||||
@ -175,7 +171,7 @@ namespace Exiv2 {
|
||||
img->setIptcData(iptcData_);
|
||||
img->setXmpData(xmpData_);
|
||||
img->writeMetadata();
|
||||
auto imgSize = static_cast<long>(img->io().size());
|
||||
size_t imgSize = img->io().size();
|
||||
DataBuf imgBuf = img->io().read(imgSize);
|
||||
|
||||
#ifdef EXIV2_DEBUG_MESSAGES
|
||||
@ -185,13 +181,15 @@ namespace Exiv2 {
|
||||
//---------------------------------------------------------------
|
||||
|
||||
// Write PGF Signature.
|
||||
if (outIo.write(pgfSignature, 3) != 3) throw Error(ErrorCode::kerImageWriteFailed);
|
||||
if (outIo.write(pgfSignature, 3) != 3)
|
||||
throw Error(ErrorCode::kerImageWriteFailed);
|
||||
|
||||
// Write Magic number.
|
||||
if (outIo.putb(mnb) == EOF) throw Error(ErrorCode::kerImageWriteFailed);
|
||||
if (outIo.putb(mnb) == EOF)
|
||||
throw Error(ErrorCode::kerImageWriteFailed);
|
||||
|
||||
// Write new Header size.
|
||||
uint32_t newHeaderSize = static_cast<uint32_t>(header.size()) + imgSize;
|
||||
uint32_t newHeaderSize = static_cast<uint32_t>(header.size() + imgSize);
|
||||
DataBuf buffer(4);
|
||||
buffer.copyBytes(0, &newHeaderSize, 4);
|
||||
byteSwap_(buffer,0,bSwap_);
|
||||
@ -242,7 +240,7 @@ namespace Exiv2 {
|
||||
return b;
|
||||
} // PgfImage::readPgfMagicNumber
|
||||
|
||||
uint32_t PgfImage::readPgfHeaderSize(BasicIo& iIo) const
|
||||
size_t PgfImage::readPgfHeaderSize(BasicIo& iIo) const
|
||||
{
|
||||
DataBuf buffer(4);
|
||||
const size_t bufRead = iIo.read(buffer.data(), buffer.size());
|
||||
@ -251,15 +249,16 @@ namespace Exiv2 {
|
||||
if (bufRead != buffer.size())
|
||||
throw Error(ErrorCode::kerInputDataReadFailed);
|
||||
|
||||
auto headerSize = static_cast<int>(byteSwap_(buffer, 0, bSwap_));
|
||||
if (headerSize <= 0 ) throw Error(ErrorCode::kerNoImageInInputData);
|
||||
auto headerSize = static_cast<size_t>(byteSwap_(buffer, 0, bSwap_));
|
||||
if (headerSize == 0 )
|
||||
throw Error(ErrorCode::kerNoImageInInputData);
|
||||
|
||||
#ifdef EXIV2_DEBUG_MESSAGES
|
||||
std::cout << "Exiv2::PgfImage: PGF header size : " << headerSize << " bytes\n";
|
||||
#endif
|
||||
|
||||
return headerSize;
|
||||
} // PgfImage::readPgfHeaderSize
|
||||
}
|
||||
|
||||
DataBuf PgfImage::readPgfHeaderStructure(BasicIo& iIo, uint32_t& width, uint32_t& height) const
|
||||
{
|
||||
|
||||
@ -224,7 +224,7 @@ namespace Exiv2::Internal {
|
||||
#endif
|
||||
pos = pos + sizeof(exifHeader);
|
||||
ByteOrder bo = TiffParser::decode(pImage->exifData(), pImage->iptcData(), pImage->xmpData(),
|
||||
exifData.c_data(pos), static_cast<uint32_t>(length - pos));
|
||||
exifData.c_data(pos), length - pos);
|
||||
pImage->setByteOrder(bo);
|
||||
} else {
|
||||
#ifndef SUPPRESS_WARNINGS
|
||||
@ -258,15 +258,14 @@ namespace Exiv2::Internal {
|
||||
pCur += (sizeIptc & 1);
|
||||
}
|
||||
if (!iptcBlob.empty() &&
|
||||
IptcParser::decode(pImage->iptcData(), &iptcBlob[0], static_cast<uint32_t>(iptcBlob.size()))) {
|
||||
IptcParser::decode(pImage->iptcData(), &iptcBlob[0], iptcBlob.size())) {
|
||||
#ifndef SUPPRESS_WARNINGS
|
||||
EXV_WARNING << "Failed to decode IPTC metadata.\n";
|
||||
#endif
|
||||
pImage->clearIptcData();
|
||||
}
|
||||
// If there is no IRB, try to decode the complete chunk data
|
||||
if (iptcBlob.empty() && IptcParser::decode(pImage->iptcData(), psData.c_data(),
|
||||
static_cast<uint32_t>(psData.size()))) {
|
||||
if (iptcBlob.empty() && IptcParser::decode(pImage->iptcData(), psData.c_data(), psData.size())) {
|
||||
#ifndef SUPPRESS_WARNINGS
|
||||
EXV_WARNING << "Failed to decode IPTC metadata.\n";
|
||||
#endif
|
||||
|
||||
@ -457,11 +457,8 @@ namespace Exiv2 {
|
||||
} else if (chunkType == "iTXt") {
|
||||
PngChunk::decodeTXTChunk(this, chunkData, PngChunk::iTXt_Chunk);
|
||||
} else if (chunkType == "eXIf") {
|
||||
ByteOrder bo = TiffParser::decode(exifData(),
|
||||
iptcData(),
|
||||
xmpData(),
|
||||
chunkData.c_data(),
|
||||
static_cast<uint32_t>(chunkData.size()));
|
||||
ByteOrder bo =
|
||||
TiffParser::decode(exifData(), iptcData(), xmpData(), chunkData.c_data(), chunkData.size());
|
||||
setByteOrder(bo);
|
||||
} else if (chunkType == "iCCP") {
|
||||
// The ICC profile name can vary from 1-79 characters.
|
||||
@ -559,7 +556,7 @@ namespace Exiv2 {
|
||||
bufRead = io_->read(chunkBuf.data(8), dataOffset + 4); // Extract chunk data + CRC
|
||||
if (io_->error())
|
||||
throw Error(ErrorCode::kerFailedToReadImageData);
|
||||
if (bufRead != static_cast<size_t>(dataOffset) + 4)
|
||||
if (bufRead != dataOffset + 4)
|
||||
throw Error(ErrorCode::kerInputDataReadFailed);
|
||||
|
||||
char szChunk[5];
|
||||
|
||||
@ -24,36 +24,24 @@ namespace {
|
||||
of both lhs and rhs are available or else by size.
|
||||
Return true if lhs is smaller than rhs.
|
||||
*/
|
||||
bool cmpPreviewProperties(
|
||||
const PreviewProperties& lhs,
|
||||
const PreviewProperties& rhs
|
||||
)
|
||||
bool cmpPreviewProperties(const PreviewProperties &lhs, const PreviewProperties &rhs)
|
||||
{
|
||||
uint32_t l = lhs.width_ * lhs.height_;
|
||||
uint32_t r = rhs.width_ * rhs.height_;
|
||||
|
||||
auto l = lhs.width_ * lhs.height_;
|
||||
auto r = rhs.width_ * rhs.height_;
|
||||
return l < r;
|
||||
}
|
||||
|
||||
/*!
|
||||
@brief Decode a Hex string.
|
||||
*/
|
||||
/// @brief Decode a Hex string.
|
||||
DataBuf decodeHex(const byte *src, long srcSize);
|
||||
|
||||
/*!
|
||||
@brief Decode a Base64 string.
|
||||
*/
|
||||
/// @brief Decode a Base64 string.
|
||||
DataBuf decodeBase64(const std::string &src);
|
||||
|
||||
/*!
|
||||
@brief Decode an Illustrator thumbnail that follows after %AI7_Thumbnail.
|
||||
*/
|
||||
/// @brief Decode an Illustrator thumbnail that follows after %AI7_Thumbnail.
|
||||
DataBuf decodeAi7Thumbnail(const DataBuf &src);
|
||||
|
||||
/*!
|
||||
@brief Create a PNM image from raw RGB data.
|
||||
*/
|
||||
DataBuf makePnm(uint32_t width, uint32_t height, const DataBuf &rgb);
|
||||
/// @brief Create a PNM image from raw RGB data.
|
||||
DataBuf makePnm(size_t width, size_t height, const DataBuf &rgb);
|
||||
|
||||
/*!
|
||||
Base class for image loaders. Provides virtual methods for reading properties
|
||||
@ -109,10 +97,10 @@ namespace {
|
||||
const Image &image_;
|
||||
|
||||
//! Preview image width
|
||||
uint32_t width_;
|
||||
size_t width_;
|
||||
|
||||
//! Preview image length
|
||||
uint32_t height_;
|
||||
size_t height_;
|
||||
|
||||
//! Preview image size in bytes
|
||||
size_t size_;
|
||||
@ -388,7 +376,8 @@ namespace {
|
||||
LoaderNative::LoaderNative(PreviewId id, const Image &image, int parIdx)
|
||||
: Loader(id, image)
|
||||
{
|
||||
if (!(0 <= parIdx && static_cast<size_t>(parIdx) < image.nativePreviews().size())) return;
|
||||
if (!(0 <= parIdx && static_cast<size_t>(parIdx) < image.nativePreviews().size()))
|
||||
return;
|
||||
nativePreview_ = image.nativePreviews()[parIdx];
|
||||
width_ = nativePreview_.width_;
|
||||
height_ = nativePreview_.height_;
|
||||
@ -396,7 +385,7 @@ namespace {
|
||||
if (nativePreview_.filter_.empty()) {
|
||||
size_ = nativePreview_.size_;
|
||||
} else {
|
||||
size_ = static_cast<uint32_t>(getData().size());
|
||||
size_ = getData().size();
|
||||
}
|
||||
}
|
||||
|
||||
@ -437,7 +426,7 @@ namespace {
|
||||
}
|
||||
IoCloser closer(io);
|
||||
const byte* data = io.mmap();
|
||||
if (static_cast<long>(io.size()) < nativePreview_.position_ + static_cast<long>(nativePreview_.size_)) {
|
||||
if (io.size() < nativePreview_.position_ + nativePreview_.size_) {
|
||||
#ifndef SUPPRESS_WARNINGS
|
||||
EXV_WARNING << "Invalid native preview position or size.\n";
|
||||
#endif
|
||||
@ -1000,7 +989,7 @@ namespace {
|
||||
return {reinterpret_cast<const byte *>(dest.data()), dest.size()};
|
||||
}
|
||||
|
||||
DataBuf makePnm(uint32_t width, uint32_t height, const DataBuf &rgb)
|
||||
DataBuf makePnm(size_t width, size_t height, const DataBuf &rgb)
|
||||
{
|
||||
const size_t expectedSize = width * height * 3UL;
|
||||
if (rgb.size() != expectedSize) {
|
||||
@ -1074,12 +1063,12 @@ namespace Exiv2 {
|
||||
return properties_.extension_;
|
||||
}
|
||||
|
||||
uint32_t PreviewImage::width() const
|
||||
size_t PreviewImage::width() const
|
||||
{
|
||||
return properties_.width_;
|
||||
}
|
||||
|
||||
uint32_t PreviewImage::height() const
|
||||
size_t PreviewImage::height() const
|
||||
{
|
||||
return properties_.height_;
|
||||
}
|
||||
|
||||
@ -299,7 +299,7 @@ namespace Exiv2 {
|
||||
nativePreview.height_ = getLong(buf + 8, bigEndian);
|
||||
const uint32_t format = getLong(buf + 0, bigEndian);
|
||||
|
||||
if (nativePreview.size_ > 0 && nativePreview.position_ >= 0) {
|
||||
if (nativePreview.size_ > 0 && nativePreview.position_ > 0) {
|
||||
io_->seek(static_cast<long>(nativePreview.size_), BasicIo::cur);
|
||||
if (io_->error() || io_->eof())
|
||||
throw Error(ErrorCode::kerFailedToReadImageData);
|
||||
|
||||
@ -291,10 +291,8 @@ namespace Exiv2 {
|
||||
enforce(Safe::add(jpg_img_off_u32, jpg_img_len_u32) <= io_->size(), ErrorCode::kerCorruptedMetadata);
|
||||
|
||||
#if LONG_MAX < UINT_MAX
|
||||
enforce(jpg_img_off_u32 <= static_cast<uint32_t>(std::numeric_limits<long>::max()),
|
||||
ErrorCode::kerCorruptedMetadata);
|
||||
enforce(jpg_img_len_u32 <= static_cast<uint32_t>(std::numeric_limits<long>::max()),
|
||||
ErrorCode::kerCorruptedMetadata);
|
||||
enforce(jpg_img_off_u32 <= std::numeric_limits<uint32_t>::max(), ErrorCode::kerCorruptedMetadata);
|
||||
enforce(jpg_img_len_u32 <= std::numeric_limits<uint32_t>::max(), ErrorCode::kerCorruptedMetadata);
|
||||
#endif
|
||||
|
||||
auto jpg_img_off = static_cast<long>(jpg_img_off_u32);
|
||||
@ -312,11 +310,8 @@ namespace Exiv2 {
|
||||
|
||||
io_->seek(0,BasicIo::beg); // rewind
|
||||
|
||||
ByteOrder bo = TiffParser::decode(exifData_,
|
||||
iptcData_,
|
||||
xmpData_,
|
||||
buf.c_data(),
|
||||
static_cast<uint32_t>(buf.size()));
|
||||
ByteOrder bo =
|
||||
TiffParser::decode(exifData_, iptcData_, xmpData_, buf.c_data(), buf.size());
|
||||
|
||||
exifData_["Exif.Image2.JPEGInterchangeFormat"] = getULong(jpg_img_offset, bigEndian);
|
||||
exifData_["Exif.Image2.JPEGInterchangeFormatLength"] = getULong(jpg_img_length, bigEndian);
|
||||
@ -355,14 +350,10 @@ namespace Exiv2 {
|
||||
|
||||
if (!io_->error() && !io_->eof())
|
||||
{
|
||||
TiffParser::decode(exifData_,
|
||||
iptcData_,
|
||||
xmpData_,
|
||||
tiff.c_data(),
|
||||
static_cast<uint32_t>(tiff.size()));
|
||||
TiffParser::decode(exifData_, iptcData_, xmpData_, tiff.c_data(), tiff.size());
|
||||
}
|
||||
}
|
||||
} // RafImage::readMetadata
|
||||
}
|
||||
|
||||
void RafImage::writeMetadata()
|
||||
{
|
||||
|
||||
@ -101,8 +101,7 @@ namespace Exiv2 {
|
||||
throw Error(ErrorCode::kerNotAnImage, "RW2");
|
||||
}
|
||||
clearMetadata();
|
||||
ByteOrder bo =
|
||||
Rw2Parser::decode(exifData_, iptcData_, xmpData_, io_->mmap(), static_cast<uint32_t>(io_->size()));
|
||||
ByteOrder bo = Rw2Parser::decode(exifData_, iptcData_, xmpData_, io_->mmap(), io_->size());
|
||||
setByteOrder(bo);
|
||||
|
||||
// A lot more metadata is hidden in the embedded preview image
|
||||
@ -197,13 +196,8 @@ namespace Exiv2 {
|
||||
throw(Error(ErrorCode::kerWritingImageFormatUnsupported, "RW2"));
|
||||
} // Rw2Image::writeMetadata
|
||||
|
||||
ByteOrder Rw2Parser::decode(
|
||||
ExifData& exifData,
|
||||
IptcData& iptcData,
|
||||
XmpData& xmpData,
|
||||
const byte* pData,
|
||||
uint32_t size
|
||||
)
|
||||
ByteOrder Rw2Parser::decode(ExifData& exifData, IptcData& iptcData, XmpData& xmpData, const byte* pData,
|
||||
size_t size)
|
||||
{
|
||||
Rw2Header rw2Header;
|
||||
return TiffParserWorker::decode(exifData,
|
||||
|
||||
@ -61,7 +61,8 @@ namespace Exiv2::Internal {
|
||||
if (target < 0 || target > std::numeric_limits<uint32_t>::max()) {
|
||||
throw Error(ErrorCode::kerOffsetOutOfRange);
|
||||
}
|
||||
if (pow_) pow_->setTarget(OffsetWriter::OffsetId(id), static_cast<uint32_t>(target));
|
||||
if (pow_)
|
||||
pow_->setTarget(OffsetWriter::OffsetId(id), static_cast<uint32_t>(target));
|
||||
}
|
||||
|
||||
TiffComponent::TiffComponent(uint16_t tag, IfdId group) : tag_(tag), group_(group) {}
|
||||
@ -259,7 +260,7 @@ namespace Exiv2::Internal {
|
||||
{
|
||||
storage_ = buf;
|
||||
pData_ = buf->data();
|
||||
size_ = static_cast<uint32_t>(buf->size());
|
||||
size_ = buf->size();
|
||||
}
|
||||
|
||||
void TiffEntryBase::setData(byte* pData, uint32_t size,
|
||||
@ -337,9 +338,7 @@ namespace Exiv2::Internal {
|
||||
auto offset = pValue()->toUint32(0);
|
||||
// Todo: Remove limitation of JPEG writer: strips must be contiguous
|
||||
// Until then we check: last offset + last size - first offset == size?
|
||||
if ( pValue()->toUint32(static_cast<long>(pValue()->count())-1)
|
||||
+ pSize->toUint32(static_cast<long>(pSize->count())-1)
|
||||
- offset != size) {
|
||||
if (pValue()->toUint32(pValue()->count()-1) + pSize->toUint32(pSize->count()-1) - offset != size) {
|
||||
#ifndef SUPPRESS_WARNINGS
|
||||
EXV_WARNING << "Directory " << groupName(group())
|
||||
<< ", entry 0x" << std::setw(4)
|
||||
@ -631,7 +630,7 @@ namespace Exiv2::Internal {
|
||||
auto atc = std::make_unique<TiffDirectory>(tpi1.tag(), tpi2.group());
|
||||
tc = addChild(std::move(atc));
|
||||
}
|
||||
setCount(static_cast<uint32_t>(ifds_.size()));
|
||||
setCount(ifds_.size());
|
||||
}
|
||||
return tc->addPath(tag, tiffPath, pRoot, std::move(object));
|
||||
} // TiffSubIfd::doAddPath
|
||||
@ -702,7 +701,7 @@ namespace Exiv2::Internal {
|
||||
assert(atc);
|
||||
assert(tpi.extendedTag() != Tag::next);
|
||||
tc = addChild(std::move(atc));
|
||||
setCount(static_cast<uint32_t>(elements_.size()));
|
||||
setCount(elements_.size());
|
||||
}
|
||||
return tc->addPath(tag, tiffPath, pRoot, std::move(object));
|
||||
} // TiffBinaryArray::doAddPath
|
||||
@ -923,12 +922,12 @@ namespace Exiv2::Internal {
|
||||
|
||||
size_t TiffDirectory::doCount() const
|
||||
{
|
||||
return static_cast<uint32_t>(components_.size());
|
||||
return components_.size();
|
||||
}
|
||||
|
||||
size_t TiffEntryBase::doCount() const
|
||||
{
|
||||
return static_cast<uint32_t>(count_);
|
||||
return count_;
|
||||
}
|
||||
|
||||
size_t TiffMnEntry::doCount() const
|
||||
@ -974,7 +973,7 @@ namespace Exiv2::Internal {
|
||||
typeSize = 1;
|
||||
}
|
||||
|
||||
return static_cast<uint32_t>(static_cast<double>(size()) / typeSize + 0.5);
|
||||
return static_cast<size_t>(static_cast<double>(size()) / typeSize + 0.5);
|
||||
}
|
||||
|
||||
size_t TiffBinaryElement::doCount() const
|
||||
@ -1168,7 +1167,8 @@ namespace Exiv2::Internal {
|
||||
uint32_t /*dataIdx*/,
|
||||
uint32_t& /*imageIdx*/)
|
||||
{
|
||||
if (!pValue_) return 0;
|
||||
if (!pValue_)
|
||||
return 0;
|
||||
|
||||
DataBuf buf(pValue_->size());
|
||||
pValue_->copy(buf.data(), byteOrder);
|
||||
@ -1216,14 +1216,11 @@ namespace Exiv2::Internal {
|
||||
for (uint32_t i = 0; i < count(); ++i) {
|
||||
const int64_t newDataIdx = pValue()->toInt64(i) - prevOffset
|
||||
+ static_cast<int64_t>(dataIdx);
|
||||
idx += writeOffset(buf.data(idx),
|
||||
offset + newDataIdx,
|
||||
tiffType(),
|
||||
byteOrder);
|
||||
idx += writeOffset(buf.data(idx), offset + newDataIdx, tiffType(), byteOrder);
|
||||
}
|
||||
ioWrapper.write(buf.c_data(), buf.size());
|
||||
return static_cast<uint32_t>(buf.size());
|
||||
} // TiffDataEntry::doWrite
|
||||
}
|
||||
|
||||
uint32_t TiffImageEntry::doWrite(IoWrapper& ioWrapper,
|
||||
ByteOrder byteOrder,
|
||||
|
||||
@ -482,7 +482,7 @@ namespace Exiv2 {
|
||||
//! Implements encode().
|
||||
virtual void doEncode(TiffEncoder& encoder, const Exifdatum* datum) =0;
|
||||
//! Set the number of components in this entry
|
||||
void setCount(uint32_t count) { count_ = count; }
|
||||
void setCount(size_t count) { count_ = count; }
|
||||
//! Set the unique id of the entry in the image
|
||||
void setIdx(int idx) { idx_ = idx; }
|
||||
/*!
|
||||
|
||||
@ -157,8 +157,7 @@ namespace Exiv2 {
|
||||
}
|
||||
clearMetadata();
|
||||
|
||||
ByteOrder bo =
|
||||
TiffParser::decode(exifData_, iptcData_, xmpData_, io_->mmap(), static_cast<uint32_t>(io_->size()));
|
||||
ByteOrder bo = TiffParser::decode(exifData_, iptcData_, xmpData_, io_->mmap(), io_->size());
|
||||
setByteOrder(bo);
|
||||
|
||||
// read profile from the metadata
|
||||
@ -182,13 +181,13 @@ namespace Exiv2 {
|
||||
#endif
|
||||
ByteOrder bo = byteOrder();
|
||||
byte* pData = nullptr;
|
||||
long size = 0;
|
||||
size_t size = 0;
|
||||
IoCloser closer(*io_);
|
||||
if (io_->open() == 0) {
|
||||
// Ensure that this is the correct image type
|
||||
if (isTiffType(*io_, false)) {
|
||||
pData = io_->mmap(true);
|
||||
size = static_cast<long>(io_->size());
|
||||
size = io_->size();
|
||||
TiffHeader tiffHeader;
|
||||
if (0 == tiffHeader.read(pData, 8)) {
|
||||
bo = tiffHeader.byteOrder();
|
||||
@ -205,7 +204,7 @@ namespace Exiv2 {
|
||||
auto pos = exifData_.findKey(key);
|
||||
bool found = pos != exifData_.end();
|
||||
if ( iccProfileDefined() ) {
|
||||
Exiv2::DataValue value(iccProfile_.c_data(), static_cast<long>(iccProfile_.size()));
|
||||
Exiv2::DataValue value(iccProfile_.c_data(), iccProfile_.size());
|
||||
if ( found ) pos->setValue(&value);
|
||||
else exifData_.add(key,&value);
|
||||
} else {
|
||||
@ -244,15 +243,8 @@ namespace Exiv2 {
|
||||
TiffMapping::findDecoder);
|
||||
} // TiffParser::decode
|
||||
|
||||
WriteMethod TiffParser::encode(
|
||||
BasicIo& io,
|
||||
const byte* pData,
|
||||
uint32_t size,
|
||||
ByteOrder byteOrder,
|
||||
const ExifData& exifData,
|
||||
const IptcData& iptcData,
|
||||
const XmpData& xmpData
|
||||
)
|
||||
WriteMethod TiffParser::encode(BasicIo& io, const byte* pData, size_t size, ByteOrder byteOrder,
|
||||
const ExifData& exifData, const IptcData& iptcData, const XmpData& xmpData)
|
||||
{
|
||||
// Copy to be able to modify the Exif data
|
||||
ExifData ed = exifData;
|
||||
|
||||
Loading…
Reference in New Issue
Block a user