-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
fba3ca1
commit cfdd6ec
Showing
52 changed files
with
2,162 additions
and
1,258 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
// Unit Include | ||
#include "artwork.h" | ||
|
||
// Qt Includes | ||
#include <QDataStream> | ||
|
||
namespace PxCryptPrivate | ||
{ | ||
/*! @cond */ | ||
|
||
//=============================================================================================================== | ||
// IArtwork | ||
//=============================================================================================================== | ||
|
||
//-Constructor--------------------------------------------------------------------------------------------------------- | ||
//Protected: | ||
IArtwork::IArtwork() {} | ||
|
||
//-Instance Functions---------------------------------------------------------------------------------------------- | ||
//Public: | ||
quint64 IArtwork::size() const { return MAGIC_NUM.size() + renditionSize(); } | ||
|
||
/*! @endcond */ | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,124 @@ | ||
#ifndef ARTWORK_H | ||
#define ARTWORK_H | ||
|
||
// Qt Includes | ||
#include <QByteArray> | ||
|
||
// Qx Includes | ||
#include <qx/core/qx-error.h> | ||
|
||
// Project Includes | ||
#include "medium_io/canvas.h" | ||
#include "art_io/artwork_error.h" | ||
|
||
using namespace Qt::Literals::StringLiterals; | ||
|
||
namespace PxCryptPrivate | ||
{ | ||
/*! @cond */ | ||
|
||
class IArtwork | ||
{ | ||
//-Class Variables-------------------------------------------------------------------------------------------------------- | ||
protected: | ||
static constexpr QDataStream::Version STREAM_VER = QDataStream::Qt_6_0; // Shouldn't matter for this, but just in case | ||
static inline const QByteArray MAGIC_NUM = "PXC"_ba; | ||
|
||
//-Constructor--------------------------------------------------------------------------------------------------------- | ||
protected: | ||
IArtwork(); | ||
|
||
//-Instance Functions---------------------------------------------------------------------------------------------- | ||
protected: | ||
virtual quint64 renditionSize() const = 0; | ||
|
||
public: | ||
quint64 size() const; | ||
}; | ||
|
||
template<typename DerivedT, quint16 RenditionId> | ||
class Artwork : IArtwork | ||
{ | ||
//-Class Variables---------------------------------------------------------------------------------------------------------- | ||
public: | ||
static constexpr quint16 RENDITION_ID = RenditionId; | ||
|
||
//-Constructor------------------------------------------------------------------------------------------------------------- | ||
protected: | ||
Artwork() = default; | ||
|
||
//-Class Functions---------------------------------------------------------------------------------------------- | ||
public: | ||
static ArtworkError readFromCanvas(DerivedT& art, Canvas& canvas) | ||
{ | ||
// Null out return buffer | ||
art = DerivedT(); | ||
|
||
// Setup stream | ||
QDataStream canvasStream(&canvas); | ||
canvasStream.setVersion(STREAM_VER); | ||
|
||
// Read magic | ||
QByteArray magic(MAGIC_NUM.size(), Qt::Uninitialized); | ||
canvasStream.readRawData(magic.data(), MAGIC_NUM.size()); | ||
if(magic != MAGIC_NUM) | ||
return ArtworkError(ArtworkError::NotMagic); | ||
|
||
// Read rendition ID | ||
quint16 renditionId; canvasStream >> renditionId; | ||
if(renditionId != RENDITION_ID) | ||
return ArtworkError(ArtworkError::WrongCodec, u"0x%1 instead of 0x%2."_s.arg(renditionId, 2, 16, QChar(u'0')) | ||
.arg(RENDITION_ID, 2, 16, QChar(u'0'))); | ||
|
||
// Setup new artwork | ||
DerivedT readArt; | ||
|
||
// Read rendition portion | ||
ArtworkError renditionError = readArt.renditionRead(canvasStream); | ||
|
||
// Check stream | ||
QDataStream::Status ss = canvasStream.status(); | ||
if(ss != QDataStream::Ok) | ||
return ArtworkError(ArtworkError::DataStreamError, ENUM_NAME(ss)); | ||
|
||
// Check for rendition error | ||
if(renditionError) | ||
return renditionError; | ||
|
||
// Return art | ||
art = readArt; | ||
return ArtworkError(); | ||
} | ||
|
||
//-Instance Functions---------------------------------------------------------------------------------------------- | ||
protected: | ||
virtual ArtworkError renditionRead(QDataStream& stream) = 0; | ||
virtual ArtworkError renditionWrite(QDataStream& stream) const = 0; | ||
|
||
public: | ||
ArtworkError writeToCanvas(Canvas& canvas) | ||
{ | ||
// Setup stream | ||
QDataStream canvasStream(&canvas); | ||
canvasStream.setVersion(STREAM_VER); | ||
|
||
// Write magic and rendition ID | ||
canvasStream.writeRawData(MAGIC_NUM.constData(), MAGIC_NUM.size()); | ||
canvasStream << RENDITION_ID; | ||
|
||
// Write rendition portion | ||
ArtworkError renditionError = renditionWrite(canvasStream); | ||
|
||
// Check stream | ||
QDataStream::Status ss = canvasStream.status(); | ||
if(ss != QDataStream::Ok) | ||
return ArtworkError(ArtworkError::DataStreamError, ENUM_NAME(ss)); | ||
|
||
return renditionError; | ||
} | ||
}; | ||
|
||
/*! @endcond */ | ||
} | ||
|
||
#endif // ARTWORK_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
// Unit Include | ||
#include "artwork_error.h" | ||
|
||
namespace PxCryptPrivate | ||
{ | ||
/*! @cond */ | ||
|
||
//=============================================================================================================== | ||
// ArtworkError | ||
//=============================================================================================================== | ||
|
||
//-Constructor--------------------------------------------------------------------------------------------------------- | ||
//Public: | ||
ArtworkError::ArtworkError(Type t, const QString& d) : | ||
mType(t), | ||
mDetails(d) | ||
{} | ||
|
||
//-Instance Functions-------------------------------------------------------------------------------------------- | ||
//Public: | ||
bool ArtworkError::isValid() const { return mType > NoError; } | ||
ArtworkError::Type ArtworkError::type() const { return mType; }; | ||
QString ArtworkError::details() const { return mDetails; } | ||
|
||
/*! @endcond */ | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
#ifndef ARTWORK_ERROR_H | ||
#define ARTWORK_ERROR_H | ||
|
||
// Qt Includes | ||
#include <QString> | ||
#include <QHash> | ||
|
||
using namespace Qt::Literals::StringLiterals; | ||
|
||
namespace PxCryptPrivate | ||
{ | ||
/*! @cond */ | ||
|
||
class ArtworkError | ||
{ | ||
//-Class Enums------------------------------------------------------------- | ||
public: | ||
enum Type | ||
{ | ||
NoError, | ||
NotMagic, | ||
WrongCodec, | ||
DataStreamError, | ||
IntegrityError | ||
}; | ||
|
||
//-Class Variables------------------------------------------------------------- | ||
private: | ||
static inline const QHash<Type, QString> ERR_STRINGS{ | ||
{NoError, u""_s}, | ||
{NotMagic, u"Image is not a magic image (missing magic number)."_s}, | ||
{WrongCodec, u"Image created with a different codec than specified (mismatched rendition)."_s}, | ||
{DataStreamError, u"An error occurred while streaming data from/to the canvas."_s}, | ||
{IntegrityError, u"A data integrity check failed while reading data."_s} | ||
}; | ||
|
||
//-Instance Variables------------------------------------------------------------- | ||
private: | ||
Type mType; | ||
QString mDetails; | ||
|
||
//-Constructor------------------------------------------------------------- | ||
public: | ||
ArtworkError(Type t = NoError, const QString& d = {}); | ||
|
||
//-Instance Functions------------------------------------------------------------- | ||
public: | ||
bool isValid() const; | ||
Type type() const; | ||
QString details() const; | ||
|
||
//-Operators------------------------------------------------------------- | ||
public: | ||
operator bool() const { return isValid(); } | ||
}; | ||
|
||
/*! @endcond */ | ||
} | ||
|
||
#endif // ARTWORK_ERROR_H |
Oops, something went wrong.