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);
84 baseColor(cg.baseColor) {
90 this->baseColor = cg.baseColor;
118 std::vector<BYTE> getRAWencoding()
const {
119 std::vector<BYTE> byte_buf(4 * gridSize[0] * gridSize[1]);
122 for (
int i = 0; i < gridSize[0]; i++) {
123 for (
int j = 0; j < gridSize[1]; j++) {
124 byte_buf[k++] = grid[i][j].getRed();
125 byte_buf[k++] = grid[i][j].getGreen();
126 byte_buf[k++] = grid[i][j].getBlue();
127 byte_buf[k++] = grid[i][j].getAlpha();
137 std::vector<BYTE> getRLEencoding()
const {
138 std::vector<BYTE> vec;
144 auto commit = [&]() {
153 std::cerr <<
"RLEencodingstream: " << (
int)repeat <<
" " << (int)r <<
" " << (
int)g <<
" " << (int)b <<
" " << (
int)a << std::endl;
155 vec.push_back(repeat);
165 while (pos < gridSize[0]*gridSize[1]) {
167 int posX = pos / gridSize[1];
168 int posY = pos % gridSize[1];
169 BYTE lr = grid[posX][posY].getRed();
170 BYTE lg = grid[posX][posY].getGreen();
171 BYTE lb = grid[posX][posY].getBlue();
172 BYTE la = grid[posX][posY].getAlpha();
207 if (totalcount != gridSize[0]*gridSize[1])
208 throw "what happened in RLE construction?";
211 std::cerr <<
"RLE length: " << vec.size()
212 <<
" raw length: " << gridSize[0]*gridSize[1] * 4
213 <<
" Compression rate:" << (float)(vec.size()) / (gridSize[0]*gridSize[1] * 4)
224 virtual const string getDataStructureRepresentation ()
const override {
228 std::vector<BYTE> byte_buf = getRLEencoding();
229 std::string encoding =
"RLE";
230 if ((
int)(byte_buf.size()) > gridSize[0]*gridSize[1] * 4) {
232 byte_buf = getRAWencoding();
234 std::cerr <<
"encoding ColorGrid as RAW" << std::endl;
238 std::cerr <<
"encoding ColorGrid as RLE" << std::endl;
int getHeight()
Definition: ColorGrid.h:100
string encode(BYTE const *buf, unsigned int bufLen)
Definition: base64.h:59
const string COLON
Definition: DataStructure.h:51
ColorGrid()
Definition: ColorGrid.h:51
int getWidth()
Definition: ColorGrid.h:109
const string OPEN_BOX
Definition: DataStructure.h:54
This is a class in BRIDGES for representing an image.
Definition: ColorGrid.h:22
const string CLOSE_CURLY
Definition: DataStructure.h:53
This is a class in BRIDGES for representing an (n x n) grid.
Definition: Grid.h:31
virtual const string getDStype() const override
Return the data structure type.
Definition: ColorGrid.h:43
This class represents Color, and supports rgba, hexadecimal and named color values.
Definition: Color.h:51
these methods convert byte arrays in to base64 codes and are used in BRIDGES to represent the color a...
Definition: alltypes.h:4
const string CLOSE_BOX
Definition: DataStructure.h:55
unsigned char BYTE
Definition: base64.h:44
ColorGrid(int rows, int cols, Color color)
Definition: ColorGrid.h:73
ColorGrid(int rows, int cols)
Definition: ColorGrid.h:61
ColorGrid(const ColorGrid &cg)
Definition: ColorGrid.h:82
const string COMMA
Definition: DataStructure.h:50
const string QUOTE
Definition: DataStructure.h:49
std::string JSONencode(const T &d)
Definition: JSONutil.h:37