13 namespace datastructure {
35 void initializeGrid (
const Color& col) {
37 for (
int i = 0; i < gridSize[0]; i++)
38 for (
int j = 0; j < gridSize[1]; j++)
52 initializeGrid(baseColor);
62 initializeGrid(baseColor);
75 initializeGrid(color);
83 baseColor(cg.baseColor) {
89 this->baseColor = cg.baseColor;
117 std::vector<BYTE> getRAWencoding()
const {
118 std::vector<BYTE> byte_buf(4 * gridSize[0] * gridSize[1]);
121 for (
int i = 0; i < gridSize[0]; i++) {
122 for (
int j = 0; j < gridSize[1]; j++) {
123 byte_buf[k++] = grid[i][j].getRed();
124 byte_buf[k++] = grid[i][j].getGreen();
125 byte_buf[k++] = grid[i][j].getBlue();
126 byte_buf[k++] = grid[i][j].getAlpha();
136 std::vector<BYTE> getRLEencoding()
const {
137 std::vector<BYTE> vec;
143 auto commit = [&]() {
152 std::cerr <<
"RLEencodingstream: " << (
int)repeat <<
" " << (int)r <<
" " << (
int)
g <<
" " << (int)b <<
" " << (
int)
a << std::endl;
154 vec.push_back(repeat);
164 while (pos < gridSize[0]*gridSize[1]) {
166 int posX = pos / gridSize[1];
167 int posY = pos % gridSize[1];
168 BYTE lr = grid[posX][posY].getRed();
169 BYTE lg = grid[posX][posY].getGreen();
170 BYTE lb = grid[posX][posY].getBlue();
171 BYTE la = grid[posX][posY].getAlpha();
206 if (totalcount != gridSize[0]*gridSize[1])
207 throw "what happened in RLE construction?";
210 std::cerr <<
"RLE length: " << vec.size()
211 <<
" raw length: " << gridSize[0]*gridSize[1] * 4
212 <<
" Compression rate:" << (float)(vec.size()) / (gridSize[0]*gridSize[1] * 4)
223 virtual const string getDataStructureRepresentation ()
const override {
227 std::vector<BYTE> byte_buf = getRLEencoding();
228 std::string encoding =
"RLE";
229 if ((
int)(byte_buf.size()) > gridSize[0]*gridSize[1] * 4) {
231 byte_buf = getRAWencoding();
233 std::cerr <<
"encoding ColorGrid as RAW" << std::endl;
237 std::cerr <<
"encoding ColorGrid as RLE" << std::endl;
This is a class in BRIDGES for representing an image.
Definition: ColorGrid.h:22
ColorGrid(int rows, int cols, Color color)
Definition: ColorGrid.h:73
int getWidth()
Definition: ColorGrid.h:108
ColorGrid(int rows, int cols)
Definition: ColorGrid.h:61
int getHeight()
Definition: ColorGrid.h:99
ColorGrid(const ColorGrid &cg)
Definition: ColorGrid.h:81
virtual const string getDStype() const override
Return the data structure type.
Definition: ColorGrid.h:43
ColorGrid()
Definition: ColorGrid.h:51
This class represents Color, and supports rgba, hexadecimal and named color values.
Definition: Color.h:50
This is a class in BRIDGES for representing an (n x n) grid.
Definition: Grid.h:30
std::string JSONencode(const T &d)
Definition: JSONutil.h:38
string encode(BYTE const *buf, unsigned int bufLen)
Definition: base64.h:56
Support for drawing Bar charts.
Definition: alltypes.h:4
const string COLON
Definition: DataStructure.h:52
unsigned char BYTE
Definition: base64.h:43
const string OPEN_BOX
Definition: DataStructure.h:55
const string COMMA
Definition: DataStructure.h:51
const string CLOSE_BOX
Definition: DataStructure.h:56
const string CLOSE_CURLY
Definition: DataStructure.h:54
const string QUOTE
Definition: DataStructure.h:50