PxCrypt v0.2.2
Encrypt data within an image
Loading...
Searching...
No Matches
PxCrypt::MultiEncoder Class Referencefinal

The MultiEncoder class encodes a payload and identifying tag into a single image.

#include <>>

Inheritance diagram for PxCrypt::MultiEncoder:
[legend]

Classes

class  Error
 The MultiEncoder::Error class is used to report errors during multi-image encoding. More...
 

Public Member Functions

 MultiEncoder ()
 
Error encode (QList< QImage > &encoded, QByteArrayView payload, const QList< QImage > &mediums)
 
void setTag (const QByteArray &tag)
 
QString tag () const
 
- Public Member Functions inherited from PxCrypt::Encoder
virtual ~Encoder ()
 
quint8 bpc () const
 
Encoding encoding () const
 
QByteArray presharedKey () const
 
void setBpc (quint8 bpc)
 
void setEncoding (Encoding enc)
 
void setPresharedKey (const QByteArray &key)
 

Static Public Member Functions

static quint64 calculateMaximumPayload (const QList< QSize > &dims, quint16 tagSize, quint8 bpc)
 
static quint8 calculateOptimalDensity (const QList< QSize > &dims, quint16 tagSize, quint32 payloadSize)
 

Additional Inherited Members

- Public Types inherited from PxCrypt::Encoder
enum  Encoding : quint8 {
  Relative ,
  Absolute
}
 

Constructor & Destructor Documentation

◆ MultiEncoder()

PxCrypt::MultiEncoder::MultiEncoder ( )

Constructs an encoder with default settings:

  • BPC of 1
  • Empty pre-shared key
  • Absolute encoding
  • Empty tag

Member Function Documentation

◆ calculateMaximumPayload()

quint64 PxCrypt::MultiEncoder::calculateMaximumPayload ( const QList< QSize > & dims,
quint16 tagSize,
quint8 bpc )
static

Returns the maximum number of payload bytes that can be stored within a images of dimensions dims and tag of size tagSize when using bpc bits per channel.

See also
calculateOptimalDensity().

◆ calculateOptimalDensity()

quint8 PxCrypt::MultiEncoder::calculateOptimalDensity ( const QList< QSize > & dims,
quint16 tagSize,
quint32 payloadSize )
static

Returns the minimum number of bits per channel required to store a payload of payloadSize along with a tag of tagSize within medium images of dims dimensions. 0 is returned if the payload/tag cannot fit within those dimensions.

Using the lowest BPC necessary is optimal as it will produce in the least distortion per pixel and the most even spread of the encoded data, overall resulting in the most minimal visual disturbance of the original image.

Note
With this encoder, the returned value is approximate and may differ by +/-1 given the fact that when actually encoding a payload with auto BPC, the BPC used can differ per image. Usually, it is the same for all images, but in some cases can vary +/-1 for some.
See also
calculateMaximumStorage().

◆ encode()

Error PxCrypt::MultiEncoder::encode ( QList< QImage > & encoded,
QByteArrayView payload,
const QList< QImage > & mediums )

NOTE: Note how the order of the parts wont necessarily be the same as mediums

See also
StandardDecoder::decode().

Encodes payload within the medium image medium and stores the result in encoded, then returns an error status.

Encodes payload within the images from mediums, distributed proportionally according to their dimmensions. That is, the bytes of the original payload are split into chunks and spread across all medium images.

The encoding is carried out in accordance with the current configuration of the encoder.

If the current BPC of the encoder is 0, the best BPC for each medium is determined independently based on the size of payload. Usually the ideal BPC is the same for all mediums, but there are some edge cases where some might differ from the rest by +/- 1. The encoders BPC will be set to the highest BPC used in this case.

The encoded images will always use the format QImage::Format_ARGB32 or QImage::Format_RGB32 (depending on if the original has an alpha channel) regardless of the format of the original medium.

Note
The encoded images are always returned in the same order as the input mediums, though this order is not necessarlly the same as the order in which payload was split up. This is a non-issue however as the multi-part decoder is able to determine the correct order of its input as long as all parts are present.
Warning

The images produced by this function must never undergo a reduction in fidelity in order to remain decodable. In other words, they must be stored in a format that uses 8 bits per color channel and holds at least the RGB channels, else the encoded data be corrupted. No data is encoded within alpha channels so they can safely be discarded.

Conversion to a format with a higher bit-depth can still result in data corruption due to aliasing sustained while resampling.

A 32-bit PNG is generally recommended as an ideal container.

See also
StandardDecoder::decode().

◆ setTag()

void PxCrypt::MultiEncoder::setTag ( const QByteArray & tag)

Sets the encoding tag to tag.

Payloads are coupled with the tag during encoding in order to aid in payload identification or allow for the storage of any other string-based metadata. The tag is stored as part of the encrypted stream, not in plain text.

The tag is optional and can be left empty.

See also
tag() and encode().

◆ tag()

QString PxCrypt::MultiEncoder::tag ( ) const

Returns the encoding tag.

See also
setTag().

The documentation for this class was generated from the following files: