Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
oblivioncth committed Aug 11, 2024
1 parent fba3ca1 commit b622f81
Show file tree
Hide file tree
Showing 51 changed files with 2,033 additions and 1,226 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/standard/header.h
art_io/standard/header.cpp
art_io/artwork.h
art_io/artwork.cpp
art_io/standard.h
art_io/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
3 changes: 2 additions & 1 deletion lib/include/pxcrypt/decoder.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
namespace PxCrypt
{

// 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
3 changes: 3 additions & 0 deletions lib/include/pxcrypt/encoder.h
Original file line number Diff line number Diff line change
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
}

}
17 changes: 17 additions & 0 deletions lib/src/art_io/artwork.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// Unit Include
#include "artwork.h"

// Qt Includes
#include <QDataStream>

namespace PxCrypt
{
/*! @cond */

//===============================================================================================================
// BaseArtwork
//===============================================================================================================


/*! @endcond */
}
46 changes: 46 additions & 0 deletions lib/src/art_io/artwork.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
#ifndef ARTWORK_H
#define ARTWORK_H

// Qt Includes
#include <QByteArray>
#include <QString>

using namespace Qt::Literals::StringLiterals;

namespace PxCrypt
{
/*! @cond */

class IArtwork
{
//-Class Variables--------------------------------------------------------------------------------------------------------
private:
static inline const QByteArray MAGIC_NUM = "PXC"_ba;

//-Constructor---------------------------------------------------------------------------------------------------------
protected:
IArtwork() = default;

//-Class Functions----------------------------------------------------------------------------------------------
public:


//-Instance Functions----------------------------------------------------------------------------------------------
public:
bool isNull() const;
quint64 size() const;

};

template<quint8 CodecNum>
class Artwork : IArtwork
{
//-Class Variables----------------------------------------------------------------------------------------------------------
public:
static constexpr quint8 CODEC_NUMBER = CodecNum;
};

/*! @endcond */
}

#endif // ARTWORK_H
20 changes: 20 additions & 0 deletions lib/src/art_io/base.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// Unit Include
#include "base.h"

// Qt Includes
#include <QDataStream>

// Qx Includes
#include <qx/core/qx-integrity.h>

namespace PxCrypt
{
/*! @cond */

//===============================================================================================================
// BaseArtwork
//===============================================================================================================


/*! @endcond */
}
38 changes: 38 additions & 0 deletions lib/src/art_io/base.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
#ifndef BASE_H
#define BASE_H

// Qt Includes
#include <QByteArray>
#include <QString>

using namespace Qt::Literals::StringLiterals;

namespace PxCrypt
{
/*! @cond */

class BaseArtwork
{
//-Class Variables--------------------------------------------------------------------------------------------------------
private:
static inline const QByteArray MAGIC_NUM = "PXC"_ba;

//-Constructor---------------------------------------------------------------------------------------------------------
public:
BaseArtwork();

//-Class Functions----------------------------------------------------------------------------------------------
public:


//-Instance Functions----------------------------------------------------------------------------------------------
public:
bool isNull() const;
quint64 size() const;

};

/*! @endcond */
}

#endif // BASE_H
Empty file added lib/src/art_io/standard.cpp
Empty file.
Empty file added lib/src/art_io/standard.h
Empty file.
87 changes: 87 additions & 0 deletions lib/src/art_io/standard/header.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
// Unit Include
#include "header.h"

// Qt Includes
#include <QDataStream>

// Qx Includes
#include <qx/core/qx-integrity.h>

namespace PxCrypt
{
/*! @cond */

//===============================================================================================================
// Header
//===============================================================================================================

//-Constructor---------------------------------------------------------------------------------------------------------
//Public:
Header::Header() :
mChecksum(0),
mPayloadSize(0),
mTag()
{}

Header::Header(QByteArrayView payload, const QString& tag) :
mChecksum(Qx::Integrity::crc32(payload)),
mPayloadSize(payload.size()),
mTag(tag.toUtf8())
{
if(mTag.size() > std::numeric_limits<tag_length_t>::max())
mTag.resize(std::numeric_limits<tag_length_t>::max());
}

//-Class Functions----------------------------------------------------------------------------------------------
//Public:
quint64 Header::sizeOf(tag_length_t tagLength)
{
return MAGIC_NUM.size() +
sizeof(mChecksum) +
sizeof(tag_length_t) +
sizeof(mPayloadSize) +
tagLength;
}

//-Instance Functions--------------------------------------------------------------------------------------------
//Public:
bool Header::isNull() const { return mChecksum == 0 & mPayloadSize == 0 & mTag.isNull(); }
quint32 Header::checksum() const { return mChecksum; }
QByteArray Header::tag() const { return mTag; };
quint16 Header::tagSize() const { return mTag.size(); }
quint32 Header::payloadSize() const { return mPayloadSize; }
quint64 Header::size() const { return sizeOf(static_cast<tag_length_t>(mTag.size())); }

//-Non-member/Related Functions------------------------------------------------------------------------------------
QDataStream& operator<<(QDataStream& ds, const Header& h)
{
ds.writeRawData(Header::MAGIC_NUM, Header::MAGIC_NUM.size());
ds << h.mChecksum
<< static_cast<Header::tag_length_t>(h.mTag.size())
<< h.mPayloadSize;
ds.writeRawData(h.mTag, h.mTag.size());

return ds;
}

QDataStream& operator>>(QDataStream& ds, Header& h)
{
h = Header();

QByteArray magic(Header::MAGIC_NUM.size(), Qt::Uninitialized);
ds.readRawData(magic.data(), Header::MAGIC_NUM.size());
if(magic != Header::MAGIC_NUM)
return ds;

ds >> h.mChecksum;
Header::tag_length_t tl;
ds >> tl;
ds >> h.mPayloadSize;
h.mTag.resize(tl);
ds.readRawData(h.mTag.data(), tl);

return ds;
}

/*! @endcond */
}
60 changes: 60 additions & 0 deletions lib/src/art_io/standard/header.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
#ifndef HEADER_H
#define HEADER_H

// Qt Includes
#include <QByteArray>
#include <QString>

using namespace Qt::Literals::StringLiterals;

namespace PxCrypt
{
/*! @cond */

class Header
{
//-Class Types------------------------------------------------------------------------------------------------------------
using tag_length_t = quint16;

//-Class Variables--------------------------------------------------------------------------------------------------------
private:
static inline const QByteArray MAGIC_NUM = "PXC"_ba;

//-Instance Variables------------------------------------------------------------------------------------------------------
private:
quint32 mChecksum;
quint32 mPayloadSize;
QByteArray mTag;

//-Constructor---------------------------------------------------------------------------------------------------------
public:
Header();
Header(QByteArrayView payload, const QString& tag);

//-Class Functions----------------------------------------------------------------------------------------------
public:
static quint64 sizeOf(tag_length_t tagLength = 0); // Zero to see minimum without tag

//-Instance Functions----------------------------------------------------------------------------------------------
public:
bool isNull() const;
quint32 checksum() const;
QByteArray tag() const;
quint16 tagSize() const;
quint32 payloadSize() const;

quint64 size() const;

//-Friend Functions------------------------------------------------------------------------------------------------
friend QDataStream& operator<<(QDataStream& ds, const Header& h);
friend QDataStream& operator>>(QDataStream& ds, Header& h);
};

//-Non-member/Related Functions------------------------------------------------------------------------------------
QDataStream& operator<<(QDataStream& ds, const Header& h);
QDataStream& operator>>(QDataStream& ds, Header& h);

/*! @endcond */
}

#endif // HEADER_H
Loading

0 comments on commit b622f81

Please sign in to comment.