Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
oblivioncth committed Aug 13, 2024
1 parent fba3ca1 commit cfdd6ec
Show file tree
Hide file tree
Showing 52 changed files with 2,162 additions and 1,258 deletions.
4 changes: 2 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ set(PROJECT_NAME_FORMAL ${PROJECT_NAME})

# Get helper scripts
include(${CMAKE_CURRENT_SOURCE_DIR}/cmake/FetchOBCMake.cmake)
fetch_ob_cmake("v0.3.5")
fetch_ob_cmake("e78a1a7c8ebf4e4aa64c221e30b3be702524c4cc")

# Initialize project according to standard rules
include(OB/Project)
Expand Down Expand Up @@ -61,7 +61,7 @@ set(PXCRYPT_QX_COMPONENTS

include(OB/FetchQx)
ob_fetch_qx(
REF "v0.5.1"
REF "06c1ffe7a027c25b379973edfd117290aaa29035"
COMPONENTS
${PXCRYPT_QX_COMPONENTS}
)
Expand Down
43 changes: 25 additions & 18 deletions lib/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,6 @@ ob_add_standard_library(${LIB_TARGET_NAME}
ALIAS "${LIB_ALIAS_NAME}"
EXPORT_HEADER
PATH "${PROJECT_NAMESPACE_LC}/${PROJECT_NAMESPACE_LC}_${LIB_ALIAS_NAME_LC}_export.h"
HEADERS_PRIVATE
encdec.h
tools/bit_chunker.h
tools/byte_compositer.h
tools/ch_sequence_generator.h
tools/px_access_read.h
tools/px_access_write.h
tools/px_sequence_generator.h
tools/px_skimmer.h
tools/px_weaver.h
HEADERS_API
COMMON "${PROJECT_NAMESPACE_LC}"
FILES
Expand All @@ -29,15 +19,32 @@ ob_add_standard_library(${LIB_TARGET_NAME}
decode_error.cpp
encoder.cpp
encode_error.cpp
encdec.h
encdec.cpp
tools/bit_chunker.cpp
tools/byte_compositer.cpp
tools/ch_sequence_generator.cpp
tools/px_access_read.cpp
tools/px_access_write.cpp
tools/px_sequence_generator.cpp
tools/px_skimmer.cpp
tools/px_weaver.cpp
art_io/artwork.h
art_io/artwork.cpp
art_io/artwork_error.h
art_io/artwork_error.cpp
art_io/works/standard.h
art_io/works/standard.cpp
medium_io/canvas.h
medium_io/canvas.cpp
medium_io/frame.h
medium_io/frame.cpp
medium_io/operate/basic_px_access.h
medium_io/operate/basic_px_access.cpp
medium_io/operate/data_translator.h
medium_io/operate/data_translator.cpp
medium_io/operate/px_access.h
medium_io/operate/px_access.cpp
medium_io/sequence/ch_sequence_generator.h
medium_io/sequence/ch_sequence_generator.cpp
medium_io/sequence/px_sequence_generator.h
medium_io/sequence/px_sequence_generator.cpp
medium_io/traverse/canvas_traverser.h
medium_io/traverse/canvas_traverser.cpp
medium_io/traverse/frame_traverser.h
medium_io/traverse/frame_traverser.cpp
LINKS
PRIVATE
$<BUILD_INTERFACE:magic_enum::magic_enum>
Expand Down
2 changes: 1 addition & 1 deletion lib/include/pxcrypt/decode_error.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
// Qx Includes
#include <qx/core/qx-abstracterror.h>

namespace PxCrypt
namespace PxCryptPrivate
{

class PXCRYPT_CODEC_EXPORT QX_ERROR_TYPE(DecodeError, "PxCrypt::DecoderError", 6878)
Expand Down
5 changes: 3 additions & 2 deletions lib/include/pxcrypt/decoder.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,10 @@
// Project Includes
#include "pxcrypt/decode_error.h"

namespace PxCrypt
namespace PxCryptPrivate
{

// TODO: Check that all errors are actually popped, here and in encoder
class PXCRYPT_CODEC_EXPORT Decoder
{
//-Class Variables----------------------------------------------------------------------------------------------
Expand Down Expand Up @@ -54,7 +55,7 @@ class PXCRYPT_CODEC_EXPORT Decoder

//-Class Functions------------------------------------------------------------------------------------------------
private:
static bool canFitHeader(const QSize& dim, quint8 bpc);
static DecodeError errFromStream(QDataStream::Status s);

//-Instance Functions----------------------------------------------------------------------------------------------
public:
Expand Down
2 changes: 1 addition & 1 deletion lib/include/pxcrypt/encode_error.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
// Qx Includes
#include <qx/core/qx-abstracterror.h>

namespace PxCrypt
namespace PxCryptPrivate
{

class PXCRYPT_CODEC_EXPORT QX_ERROR_TYPE(EncodeError, "PxCrypt::EncoderError", 6978)
Expand Down
5 changes: 4 additions & 1 deletion lib/include/pxcrypt/encoder.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
// Project Includes
#include "pxcrypt/encode_error.h"

namespace PxCrypt
namespace PxCryptPrivate
{

class PXCRYPT_CODEC_EXPORT Encoder
Expand Down Expand Up @@ -53,6 +53,9 @@ class PXCRYPT_CODEC_EXPORT Encoder
Encoder();

//-Class Functions----------------------------------------------------------------------------------------------
private:
static EncodeError errFromStream(QDataStream::Status s);

public:
static quint64 calculateMaximumStorage(const QSize& dim, quint16 tagSize, quint8 bpc);
static quint8 calculateOptimalDensity(const QSize& dim, quint16 tagSize, quint32 payloadSize);
Expand Down
2 changes: 1 addition & 1 deletion lib/src/_internal.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ namespace _PxCrypt
*/
quint64 calculateMaximumPayloadBits(const QSize& dim, quint16 tagSize, quint8 bpc)
{
return PxCrypt::calcMaxPayloadBits(dim, tagSize, bpc);
return PxCrypt::calcMaxPayloadBits(dim, tagSize, bpc); //TODO: BODGE
}

}
24 changes: 24 additions & 0 deletions lib/src/art_io/artwork.cpp
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 */
}
124 changes: 124 additions & 0 deletions lib/src/art_io/artwork.h
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
26 changes: 26 additions & 0 deletions lib/src/art_io/artwork_error.cpp
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 */
}
60 changes: 60 additions & 0 deletions lib/src/art_io/artwork_error.h
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
Loading

0 comments on commit cfdd6ec

Please sign in to comment.