Skip to content
Open
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
138 changes: 73 additions & 65 deletions src/asfvideo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,67 +10,17 @@
#include "helper_functions.hpp"
#include "image_int.hpp"

// *****************************************************************************
// class member definitions
namespace Exiv2 {

/*!
Look-up list for ASF Type Video Files
Associates the GUID with its Name(i.e. Human Readable Form)
Tags have been differentiated into Various Categories.
The categories have been listed above Groups
see :
- https://fr.wikipedia.org/wiki/Advanced_Systems_Format
- https://exse.eyewated.com/fls/54b3ed95bbfb1a92.pdf
*/
/*
* @class GUID_struct
*
* @brief A class to represent a globally unique identifier (GUID) structure
*
* This class represents a globally unique identifier (GUID) structure which is used to identify objects in a
* distributed environment. A GUID is a unique identifier that is generated on a computer and can be used to
* identify an object across different systems. The GUID structure is comprised of four 32-bit values and an
* array of 8 bytes.
*
* @note The byte order of the GUID structure is in little endian.
*
* @see https://en.wikipedia.org/wiki/Globally_unique_identifier
*
*/

bool AsfVideo::GUIDTag::operator==(const AsfVideo::GUIDTag& other) const {
return data1_ == other.data1_ && data2_ == other.data2_ && data3_ == other.data3_ && data4_ == other.data4_;
}
namespace {
constexpr Exiv2::AsfVideo::GUIDTag Header(0x75B22630, 0x668E, 0x11CF, {0xA6, 0xD9, 0x00, 0xAA, 0x00, 0x62, 0xCE, 0x6C});

AsfVideo::GUIDTag::GUIDTag(const uint8_t* bytes) {
data1_ = Exiv2::getULong(bytes, ByteOrder::littleEndian);
data2_ = Exiv2::getUShort(bytes + DWORD, ByteOrder::littleEndian);
data3_ = Exiv2::getUShort(bytes + DWORD + WORD, ByteOrder::littleEndian);
std::copy(bytes + QWORD, bytes + (2 * QWORD), data4_.begin());
}
constexpr struct tags {
Exiv2::AsfVideo::GUIDTag first;
std::string_view second;

std::string AsfVideo::GUIDTag::to_string() const {
// Concatenate all strings into a single string
// Convert the string to uppercase
// Example of output 399595EC-8667-4E2D-8FDB-98814CE76C1E
return stringFormat("{:08X}-{:04X}-{:04X}-{:02X}{:02X}-{:02X}{:02X}{:02X}{:02X}{:02X}{:02X}", data1_, data2_, data3_,
data4_[0], data4_[1], data4_[2], data4_[3], data4_[4], data4_[5], data4_[6], data4_[7]);
}

bool AsfVideo::GUIDTag::operator<(const GUIDTag& other) const {
if (data1_ != other.data1_)
return data1_ < other.data1_;
if (data2_ != other.data2_)
return data2_ < other.data2_;
if (data3_ != other.data3_)
return data3_ < other.data3_;
return std::lexicographical_compare(data4_.begin(), data4_.end(), other.data4_.begin(), other.data4_.end());
}

constexpr AsfVideo::GUIDTag Header(0x75B22630, 0x668E, 0x11CF, {0xA6, 0xD9, 0x00, 0xAA, 0x00, 0x62, 0xCE, 0x6C});

const std::map<AsfVideo::GUIDTag, std::string> GUIDReferenceTags = {
bool operator==(const Exiv2::DataBuf& tag) const {
return Exiv2::AsfVideo::GUIDTag(tag.c_data()) == first;
};
} GUIDReferenceTags[] = {
//!< Top-level ASF object GUIDS
{Header, "Header"},
{{0x75B22636, 0x668E, 0x11CF, {0xA6, 0xD9, 0x00, 0xAA, 0x00, 0x62, 0xCE, 0x6C}}, "Data"},
Expand Down Expand Up @@ -175,8 +125,68 @@ const std::map<AsfVideo::GUIDTag, std::string> GUIDReferenceTags = {
@param buf Exiv2 byte buffer
@return Returns true if the buffer data is equivalent to Header GUID.
*/
static bool isASFType(const byte buf[]) {
return Header == AsfVideo::GUIDTag(buf);
bool isASFType(const Exiv2::byte buf[]) {
return Header == Exiv2::AsfVideo::GUIDTag(buf);
}

} // namespace

// *****************************************************************************
// class member definitions
namespace Exiv2 {

/*!
Look-up list for ASF Type Video Files
Associates the GUID with its Name(i.e. Human Readable Form)
Tags have been differentiated into Various Categories.
The categories have been listed above Groups
see :
- https://fr.wikipedia.org/wiki/Advanced_Systems_Format
- https://exse.eyewated.com/fls/54b3ed95bbfb1a92.pdf
*/
/*
* @class GUID_struct
*
* @brief A class to represent a globally unique identifier (GUID) structure
*
* This class represents a globally unique identifier (GUID) structure which is used to identify objects in a
* distributed environment. A GUID is a unique identifier that is generated on a computer and can be used to
* identify an object across different systems. The GUID structure is comprised of four 32-bit values and an
* array of 8 bytes.
*
* @note The byte order of the GUID structure is in little endian.
*
* @see https://en.wikipedia.org/wiki/Globally_unique_identifier
*
*/

bool AsfVideo::GUIDTag::operator==(const AsfVideo::GUIDTag& other) const {
return data1_ == other.data1_ && data2_ == other.data2_ && data3_ == other.data3_ && data4_ == other.data4_;
}

AsfVideo::GUIDTag::GUIDTag(const uint8_t* bytes) {
data1_ = Exiv2::getULong(bytes, ByteOrder::littleEndian);
data2_ = Exiv2::getUShort(bytes + DWORD, ByteOrder::littleEndian);
data3_ = Exiv2::getUShort(bytes + DWORD + WORD, ByteOrder::littleEndian);
std::copy(bytes + QWORD, bytes + (2 * QWORD), data4_.begin());
}

std::string AsfVideo::GUIDTag::to_string() const {
// Concatenate all strings into a single string
// Convert the string to uppercase
// Example of output 399595EC-8667-4E2D-8FDB-98814CE76C1E
return stringFormat("{:08X}-{:04X}-{:04X}-{:02X}{:02X}-{:02X}{:02X}{:02X}{:02X}{:02X}{:02X}", data1_, data2_, data3_,
data4_[0], data4_[1], data4_[2], data4_[3], data4_[4], data4_[5], data4_[6], data4_[7]);
}

bool AsfVideo::GUIDTag::operator<(const GUIDTag& other) const {
if (data1_ != other.data1_)
return data1_ < other.data1_;
if (data2_ != other.data2_)
return data2_ < other.data2_;
if (data3_ != other.data3_)
return data3_ < other.data3_;
return std::lexicographical_compare(data4_.begin(), data4_.end(), other.data4_.begin(), other.data4_.end());
}

AsfVideo::AsfVideo(BasicIo::UniquePtr io) : Image(ImageType::asf, mdNone, std::move(io)) {
Expand Down Expand Up @@ -231,9 +241,8 @@ void AsfVideo::decodeBlock() {
<< "\tsize= " << objectHeader.getSize() << "\t " << io_->tell() << "/" << io_->size() << '\n';
#endif
Internal::enforce(objectHeader.getSize() <= io_->size() - io_->tell(), Exiv2::ErrorCode::kerCorruptedMetadata);
auto tag = GUIDReferenceTags.find(GUIDTag(objectHeader.getId().data()));

if (tag != GUIDReferenceTags.end()) {
if (auto tag = Exiv2::find(GUIDReferenceTags, objectHeader.getId())) {
if (tag->second == "Header")
decodeHeader();
else if (tag->second == "File_Properties")
Expand Down Expand Up @@ -339,8 +348,7 @@ void AsfVideo::streamProperties() {
enum class streamTypeInfo { Audio = 1, Video = 2 };
auto stream = streamTypeInfo{0};

auto tag_stream_type = GUIDReferenceTags.find(GUIDTag(streamTypedBuf.data()));
if (tag_stream_type != GUIDReferenceTags.end()) {
if (auto tag_stream_type = Exiv2::find(GUIDReferenceTags, streamTypedBuf)) {
if (tag_stream_type->second == "Audio_Media")
stream = streamTypeInfo::Audio;
else if (tag_stream_type->second == "Video_Media")
Expand Down
4 changes: 2 additions & 2 deletions src/convert.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ bool convertStringCharsetWindows(std::string& str, std::string_view from, std::s
exactly one entry, \em value is set to this entry, without the qualifier.
The return code indicates if the operation was successful.
*/
bool getTextValue(std::string& value, const Exiv2::XmpData::iterator& pos);
bool getTextValue(std::string& value, Exiv2::XmpData::iterator pos);
} // namespace

// *****************************************************************************
Expand Down Expand Up @@ -1586,7 +1586,7 @@ bool convertStringCharsetWindows(std::string& str, std::string_view from, std::s
}

#endif // EXV_HAVE_ICONV
bool getTextValue(std::string& value, const XmpData::iterator& pos) {
bool getTextValue(std::string& value, XmpData::iterator pos) {
if (pos->typeId() == langAlt) {
// get the default language entry without x-default qualifier
value = pos->toString(0);
Expand Down
2 changes: 2 additions & 0 deletions src/crwimage_int.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,8 @@ class CiffComponent {
CiffComponent(uint16_t tag, uint16_t dir);
//! Virtual destructor.
virtual ~CiffComponent() = default;
CiffComponent(const CiffComponent&) = delete;
CiffComponent& operator=(const CiffComponent&) = delete;
//@}

//! @name Manipulators
Expand Down
3 changes: 3 additions & 0 deletions src/exif.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,11 @@ class Thumbnail {

//! @name Creators
//@{
Thumbnail() = default;
//! Virtual destructor
virtual ~Thumbnail() = default;
Thumbnail(const Thumbnail&) = delete;
Thumbnail& operator=(const Thumbnail&) = delete;
//@}

//! Factory function to create a thumbnail for the Exif metadata provided.
Expand Down
12 changes: 6 additions & 6 deletions src/image.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,12 @@ std::string pathOfFileUrl(const std::string& url) {
}
#endif

bool typeValid(uint16_t type) {
return type >= 1 && type <= 13;
}

std::set<size_t> visits; // #547

} // namespace

// *****************************************************************************
Expand Down Expand Up @@ -305,12 +311,6 @@ const char* Image::typeName(uint16_t tag) {
return result;
}

static bool typeValid(uint16_t type) {
return type >= 1 && type <= 13;
}

static std::set<size_t> visits; // #547

void Image::printIFDStructure(BasicIo& io, std::ostream& out, Exiv2::PrintStructureOption option, size_t start,
bool bSwap, char c, size_t depth) {
if (depth == 1)
Expand Down
5 changes: 2 additions & 3 deletions src/makernote_int.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ namespace fs = std::filesystem;
namespace {
// Todo: Can be generalized further - get any tag as a string/long/...
//! Get the Value for a tag within a particular group
const Exiv2::Value* getExifValue(Exiv2::Internal::TiffComponent* pRoot, const uint16_t& tag, const Exiv2::IfdId& group);
const Exiv2::Value* getExifValue(Exiv2::Internal::TiffComponent* pRoot, uint16_t tag, Exiv2::IfdId group);
//! Get the model name from tag Exif.Image.Model
std::string getExifModel(Exiv2::Internal::TiffComponent* pRoot);

Expand Down Expand Up @@ -1034,8 +1034,7 @@ int sonyMisc3cSelector(uint16_t /*tag*/, const byte* /*pData*/, size_t /*size*/,
// *****************************************************************************
// local definitions
namespace {
const Exiv2::Value* getExifValue(Exiv2::Internal::TiffComponent* pRoot, const uint16_t& tag,
const Exiv2::IfdId& group) {
const Exiv2::Value* getExifValue(Exiv2::Internal::TiffComponent* pRoot, uint16_t tag, Exiv2::IfdId group) {
Exiv2::Internal::TiffFinder finder(tag, group);
if (!pRoot)
return nullptr;
Expand Down
3 changes: 3 additions & 0 deletions src/makernote_int.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,11 @@ class MnHeader {
public:
//! @name Creators
//@{
MnHeader() = default;
//! Virtual destructor.
virtual ~MnHeader() = default;
MnHeader(const MnHeader&) = delete;
MnHeader& operator=(const MnHeader&) = delete;
//@}
//! @name Manipulators
//@{
Expand Down
26 changes: 20 additions & 6 deletions src/riffvideo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,16 @@

#include <array>

namespace Exiv2::Internal {
namespace {

const std::map<std::string, std::string> infoTags = {
constexpr struct tags {
std::string_view first;
const char* second;

bool operator==(std::string_view tag) const {
return tag == first;
};
} infoTags[] = {
{"AGES", "Xmp.video.Rated"},
{"CMNT", "Xmp.video.Comment"},
{"CODE", "Xmp.video.EncodedBy"},
Expand Down Expand Up @@ -105,7 +112,14 @@ const std::map<std::string, std::string> infoTags = {
{"YEAR", "Xmp.video.Year"},
};

const std::map<uint16_t, std::string> audioEncodingValues = {
constexpr struct encoding {
uint16_t first;
std::string_view second;

bool operator==(uint16_t tag) const {
return tag == first;
};
} audioEncodingValues[] = {
{0x1, "Microsoft PCM"},
{0x2, "Microsoft ADPCM"},
{0x3, "Microsoft IEEE float"},
Expand Down Expand Up @@ -351,7 +365,7 @@ const std::map<uint16_t, std::string> audioEncodingValues = {
{0xffff, "Development"},
};

} // namespace Exiv2::Internal
} // namespace
// *****************************************************************************
// class member definitions

Expand Down Expand Up @@ -625,7 +639,7 @@ void RiffVideo::readStreamFormat(uint64_t size_) {
xmpData_["Xmp.video.NumIfImpColours"] = "All";
} else if (streamType_ == Audio) {
uint16_t format_tag = readWORDTag(io_);
if (auto it = Internal::audioEncodingValues.find(format_tag); it != Internal::audioEncodingValues.end())
if (auto it = Exiv2::find(audioEncodingValues, format_tag))
xmpData_["Xmp.audio.Compressor"] = it->second;
else
xmpData_["Xmp.audio.Compressor"] = format_tag;
Expand Down Expand Up @@ -657,7 +671,7 @@ void RiffVideo::readInfoListChunk(uint64_t size_) {
std::string type = readStringTag(io_);
size_t size = readDWORDTag(io_);
std::string content = readStringTag(io_, size);
if (auto it = Internal::infoTags.find(type); it != Internal::infoTags.end())
if (auto it = Exiv2::find(infoTags, type))
xmpData_[it->second] = content;
current_size += DWORD * 2;
current_size += size;
Expand Down
4 changes: 3 additions & 1 deletion src/tiffimage_int.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ class TiffHeaderBase {
TiffHeaderBase(uint16_t tag, uint32_t size, ByteOrder byteOrder, uint32_t offset);
//! Virtual destructor.
virtual ~TiffHeaderBase() = default;
TiffHeaderBase(const TiffHeaderBase&) = delete;
TiffHeaderBase& operator=(const TiffHeaderBase&) = delete;
//@}

//! @name Manipulators
Expand Down Expand Up @@ -138,7 +140,7 @@ class TiffHeader : public TiffHeaderBase {
using TiffGroupKey = std::pair<uint32_t, IfdId>;

struct TiffGroupKey_hash {
std::size_t operator()(const TiffGroupKey& pair) const noexcept {
std::size_t operator()(TiffGroupKey pair) const noexcept {
return std::hash<uint64_t>{}(static_cast<uint64_t>(pair.first) << 32 | static_cast<uint64_t>(pair.second));
}
};
Expand Down
3 changes: 3 additions & 0 deletions src/tiffvisitor_int.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,11 @@ class TiffVisitor {
public:
//! @name Creators
//@{
TiffVisitor() = default;
//! Virtual destructor
virtual ~TiffVisitor() = default;
TiffVisitor(const TiffVisitor&) = delete;
TiffVisitor& operator=(const TiffVisitor&) = delete;
//@}

//! @name Manipulators
Expand Down
Loading
Loading