Skip to content

Commit

Permalink
refactor: change name of CompressedRow class to RowCompressor
Browse files Browse the repository at this point in the history
Signed-off-by: Aditya Agarwal <[email protected]>
  • Loading branch information
Aditya-A-garwal committed Feb 13, 2024
1 parent db933d8 commit 37cc7d9
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 44 deletions.
48 changes: 5 additions & 43 deletions include/canvasClient.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

#include "stdint.h"

class CompressedRow {
class RowCompressor {

constexpr static unsigned NUM_SEGMENTS = 24;

Expand All @@ -27,49 +27,11 @@ class CompressedRow {

public:

CompressedRow() {}
bool compress(uint8_t *codes, uint16_t count);

bool compress(uint8_t *codes, uint16_t count) {

numSegments = 0;

for (unsigned l = 0, r; l < count; ) {
for (r = l; r < count; ++r) {
if (codes[r] == codes[l]) {
if (r < count-1) {
continue;
}
r = count;
}
break;
}

if (++numSegments >= NUM_SEGMENTS) {
numSegments = 0;
return false;
}

segment *curSegment = (segment *)(&segments[numSegments - 1]);
curSegment->code = codes[l];
curSegment->size = r - l;

l = r;
}

return true;
}

uint16_t getNumSegments() {
return numSegments;
}

uint16_t getSegment(uint16_t i) {
return segments[i];
}

uint16_t *getSegmentArray() {
return segments;
}
uint16_t getNumSegments();
uint16_t getSegment(uint16_t i);
uint16_t *getSegmentArray();

private:
};
Expand Down
46 changes: 45 additions & 1 deletion src/canvasClient.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,49 @@
#include "canvasClient.h"

CanvasClient::buffer CanvasClient::buf;

bool RowCompressor::compress(uint8_t *codes, uint16_t count) {

numSegments = 0;

for (unsigned l = 0, r; l < count; ) {
for (r = l; r < count; ++r) {
if (codes[r] == codes[l]) {
if (r < count-1) {
continue;
}
r = count;
}
break;
}

if (++numSegments >= NUM_SEGMENTS) {
numSegments = 0;
return false;
}

segment *curSegment = (segment *)(&segments[numSegments - 1]);
curSegment->code = codes[l];
curSegment->size = r - l;

l = r;
}

return true;
}

uint16_t RowCompressor::getNumSegments() {
return numSegments;
}

uint16_t RowCompressor::getSegment(uint16_t i) {
return segments[i];
}

uint16_t* RowCompressor::getSegmentArray() {
return segments;
}

CanvasClient::CanvasClient(Canvas *canvas)
: canvas {canvas}
{}
Expand Down Expand Up @@ -92,7 +136,7 @@ void CanvasClient::saveCanvas(uint8_t id) {
uint16_t imageHeight = canvas->height() - 2;
uint16_t imageWidth = canvas->width() - 2;

CompressedRow compressed;
RowCompressor compressed;

unsigned x = 0;

Expand Down

0 comments on commit 37cc7d9

Please sign in to comment.