-
Notifications
You must be signed in to change notification settings - Fork 0
/
ImageBase.hpp
80 lines (62 loc) · 3.17 KB
/
ImageBase.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
#ifndef IMAGEBASE_HPP
#define IMAGEBASE_HPP
#include <string>
#include <vector>
#include "BitStream.hpp"
#include "Block.hpp"
#include "MatrixReader.hpp"
namespace dc {
/**
* @brief The ImageBase class
* Provides a base with the image dimensions and the raw byte buffer
* read into an std::vector and accessible through a BitStreamReader instance.
*/
class ImageBase {
protected:
uint16_t width; ///< The width of the image.
uint16_t height; ///< The height of the image.
std::vector<uint8_t> *raw; ///< The raw input stream.
util::BitStreamReader *reader; ///< A BitStreamReader linked to the raw input stream.
public:
ImageBase(const std::string &source_file, const uint16_t &width, const uint16_t &height);
ImageBase(uint8_t * const raw, const uint16_t &width, const uint16_t &height);
~ImageBase(void);
};
////////////////////////////////////////////////////////////////////////////////////
/**
* @brief The ImageProcessor class
*/
class ImageProcessor : protected ImageBase {
protected:
bool use_rle; ///< Whether to use Run Length Encoding.
MatrixReader<> quant_m; ///< A quantization matrix instance.
const std::string &dest_file; ///< The path to the destination file.
std::vector<dc::MicroBlock*> *blocks; ///< A list of every Block for the image.
std::vector<dc::MacroBlock*> *macroblocks; ///< A list of every MacroBlock for the image.
util::BitStreamWriter *writer; ///< The output stream.
void saveResult(bool) const;
bool process(uint8_t * const);
bool processMacroBlocks(uint8_t * const);
void copyMacroblockToMatchingMicroblocks(MacroBlock&);
public:
ImageProcessor(const std::string &source_file, const std::string &dest_file,
const uint16_t &width, const uint16_t &height,
const bool &use_rle, MatrixReader<> &quant_m);
ImageProcessor(const std::string &source_file, const std::string &dest_file);
ImageProcessor(uint8_t * const raw,
const uint16_t &width, const uint16_t &height,
const bool &use_rle, MatrixReader<> &quant_m);
virtual ~ImageProcessor(void);
/**
* @brief Process the image, needs to be implemented in a child class.
* A child class can call ImageProcessor::process(buffer) to create
* block from the buffer.
*/
virtual bool process(void)=0;
virtual void saveResult(void) const {}
dc::MacroBlock* getBlockAtCoord(int16_t, int16_t) const;
static constexpr size_t RLE_BITS = 1u; ///< The amount of bits to use to represent zhether to use RLE or not.
static constexpr size_t DIM_BITS = 15u; ///< The amount of bits to use to represent the image dimensions (width or height).
};
}
#endif // IMAGEBASE_HPP