camelCase, future support, minor cleanup

* use camelCase for local variables
* furure support: rename drawPixelCallback to draw2DPixelCallback
This commit is contained in:
Frank
2025-11-07 11:05:44 +01:00
parent 9564791640
commit f955df0488

View File

@@ -49,8 +49,9 @@ bool openGif(const char *filename) { // side-effect: updates "file"
static Segment* activeSeg; static Segment* activeSeg;
static uint16_t gifWidth, gifHeight; // these two must stay uint16_t, because they are passed by reference static uint16_t gifWidth, gifHeight; // these two must stay uint16_t, because they are passed by reference
static unsigned seg_cols = 1; static unsigned segCols = 1;
static unsigned seg_rows = 1; static unsigned segRows = 1;
//static unsigned segLen = 1; // for future 1D support
static int expandX = 1; static int expandX = 1;
static int expandY = 1; static int expandY = 1;
static int lastX = -1, lastY = -1; static int lastX = -1, lastY = -1;
@@ -69,12 +70,11 @@ void updateScreenCallback(void) {
} }
lastX = lastY = -1; // invalidate last position lastX = lastY = -1; // invalidate last position
} }
void drawPixelCallback(int16_t x, int16_t y, uint8_t red, uint8_t green, uint8_t blue) { void draw2DPixelCallback(int16_t x, int16_t y, uint8_t red, uint8_t green, uint8_t blue) {
// simple nearest-neighbor downscaling // simple nearest-neighbor downscaling
int outY = y * seg_rows / gifHeight; int outY = y * segRows / gifHeight;
int outX = x * seg_cols / gifWidth; int outX = x * segCols / gifWidth;
if ((unsigned(outX) >= segCols) || (unsigned(outY) >= segRows)) return; // out of range
if ((unsigned(outX) >= seg_cols) || (unsigned(outY) >= seg_rows)) return; // out of range
if ((lastX == outX) && (lastY == outY)) return; // downscaling optimization: skip re-painting same pixel if ((lastX == outX) && (lastY == outY)) return; // downscaling optimization: skip re-painting same pixel
lastX = outX; lastY = outY; lastX = outX; lastY = outY;
@@ -105,8 +105,9 @@ byte renderImageToSegment(Segment &seg) {
// TODO: if (seg.mode != seg.currentMode()) return IMAGE_ERROR_WAITING; // TODO: if (seg.mode != seg.currentMode()) return IMAGE_ERROR_WAITING;
if (activeSeg && activeSeg != &seg) return IMAGE_ERROR_SEG_LIMIT; // only one segment at a time if (activeSeg && activeSeg != &seg) return IMAGE_ERROR_SEG_LIMIT; // only one segment at a time
activeSeg = &seg; activeSeg = &seg;
seg_cols = activeSeg->virtualWidth(); segCols = activeSeg->virtualWidth();
seg_rows = activeSeg->virtualHeight(); segRows = activeSeg->virtualHeight();
// segLen = activeSeg->virtualLength(); // for future 1D and expand1D support
if (strncmp(lastFilename +1, seg.name, 32) != 0) { // segment name changed, load new image if (strncmp(lastFilename +1, seg.name, 32) != 0) { // segment name changed, load new image
strncpy(lastFilename +1, seg.name, 32); strncpy(lastFilename +1, seg.name, 32);
@@ -126,7 +127,7 @@ byte renderImageToSegment(Segment &seg) {
} }
decoder.setScreenClearCallback(screenClearCallback); decoder.setScreenClearCallback(screenClearCallback);
decoder.setUpdateScreenCallback(updateScreenCallback); decoder.setUpdateScreenCallback(updateScreenCallback);
decoder.setDrawPixelCallback(drawPixelCallback); decoder.setDrawPixelCallback(draw2DPixelCallback);
decoder.setFileSeekCallback(fileSeekCallback); decoder.setFileSeekCallback(fileSeekCallback);
decoder.setFilePositionCallback(filePositionCallback); decoder.setFilePositionCallback(filePositionCallback);
decoder.setFileReadCallback(fileReadCallback); decoder.setFileReadCallback(fileReadCallback);
@@ -177,8 +178,8 @@ byte renderImageToSegment(Segment &seg) {
return IMAGE_ERROR_GIF_DECODE; return IMAGE_ERROR_GIF_DECODE;
} }
// softhack007: pre-calculate upscaling for speedup // softhack007: pre-calculate upscaling for speedup
expandX = (seg_cols+(gifWidth-1)) / gifWidth; expandX = (segCols+(gifWidth-1)) / gifWidth;
expandY = (seg_rows+(gifHeight-1)) / gifHeight; expandY = (segRows+(gifHeight-1)) / gifHeight;
int result = decoder.decodeFrame(false); int result = decoder.decodeFrame(false);
if (result < 0) { if (result < 0) {