PxCrypt v0.2.2
Encrypt data within an image
Loading...
Searching...
No Matches
canvas_traverser.h
1#ifndef CANVAS_TRAVERSER_H
2#define CANVAS_TRAVERSER_H
3
4// Project Includes
5#include "medium_io/sequence/px_sequence_generator.h"
6#include "medium_io/sequence/ch_sequence_generator.h"
7
8namespace PxCryptPrivate
9{
10
11class MetaAccess;
12
13class CanvasTraverser
14{
15//-Inner Struct-----------------------------------------------------------------------------------------------------------
16private:
17 struct Position
18 {
19 quint64 px;
20 int ch;
21 int bit;
22
23 static quint64 channelsBeteween(const Position& a, const Position& b);
24 static Position fromBits(quint64 bitPos, quint8 bpc);
25 quint64 toBits(quint8 bpc) const;
26 bool operator==(const Position& other) const = default;
27 auto operator<=>(const Position& other) const noexcept = default;
28 };
29
30 struct Selection
31 {
32 qint64 px;
33 Channel ch;
34 //int bit; Always the same as linear position bit so just share that
35
36 bool operator==(const Selection& other) const = default;
37 };
38
39 struct State
40 {
41 PxSequenceGenerator::State pxState;
42 ChSequenceGenerator::State chState;
43 Position linearPosition;
44 Selection currentSelection;
45 };
46
47//-Instance Variables------------------------------------------------------------------------------------------------------
48private:
49 // Meta
50 MetaAccess& mMeta;
51
52 // Generator
53 std::unique_ptr<PxSequenceGenerator> mPxSequence;
54 std::unique_ptr<ChSequenceGenerator> mChSequence;
55
56 // Location
57 Position mLinearPosition;
58 Selection mCurrentSelection;
59 Position mLinearEnd;
60
61 // State
62 std::unique_ptr<State> mInitialState;
63
64//-Constructor---------------------------------------------------------------------------------------------------------
65public:
66 CanvasTraverser(MetaAccess& meta);
67
68//-Instance Functions----------------------------------------------------------------------------------------------
69private:
70 void restoreState(const State& state);
71 void calculateEnd();
72 void advanceChannel();
73 void advancePixel();
74
75public:
76 void init();
77
78 // Stat
79 State state() const;
80 bool atEnd() const;
81
82 quint64 pixelIndex() const;
83 Channel channel() const;
84 int channelBitIndex() const;
85 int remainingChannelBits() const;
86
87 // Manipulation
88 void advanceBits(int bitCount);
89 bool bitAdvanceWillChangePixel(int bitCount);
90 qint64 skip(qint64 bytes);
91
92//-Operators----------------------------------------------------------------------------------------------------------------
93public:
94 bool operator==(const State& state) const;
95};
96
97}
98
99#endif // CANVAS_TRAVERSER_H