diff --git a/Meter.c b/Meter.c index 0e8bfb251..ab11d93b2 100644 --- a/Meter.c +++ b/Meter.c @@ -315,13 +315,6 @@ static void GraphMeterMode_reallocateGraphBuffer(Meter* this, const GraphDrawCon // Fill new spaces with blank records memset(data->buffer, 0, moveOffset * sizeof(*data->buffer)); - if (context->maxItems > 1) { - for (size_t i = 0; i < moveOffset; i++) { - if (context->isPercentChart || i % nCellsPerValue > 0) { - data->buffer[i].c.itemIndex = UINT8_MAX; - } - } - } bufferInitialized: data->nValues = nValues; @@ -572,7 +565,7 @@ static uint16_t GraphMeterMode_makeDetailsMask(const GraphColorComputeState* pre static void GraphMeterMode_paintCellsForItem(GraphColorCell* cellsStart, unsigned int increment, uint8_t itemIndex, unsigned int nCells, uint16_t mask) { GraphColorCell* cell = cellsStart; while (nCells > 0) { - cell->c.itemIndex = itemIndex; + cell->c.itemNum = itemIndex + 1; if (nCells == 1) { cell->c.details = (uint8_t)mask; } else if (cell == cellsStart) { @@ -896,9 +889,9 @@ static void GraphMeterMode_recordNewValue(Meter* this, const GraphDrawContext* c // Clear cells unsigned int i = ((unsigned int)numDots + 8 - 1) / 8; // Round up i = GraphMeterMode_valueCellIndex(graphHeight, isPercentChart, 0, i, NULL, NULL); - for (; i < nCellsPerValue; i++) { - valueStart[i].c.itemIndex = UINT8_MAX; - valueStart[i].c.details = 0x00; + if (i != (unsigned int)-1) { + assert(i < nCellsPerValue); + memset(&valueStart[i], 0, (nCellsPerValue - i) * sizeof(*valueStart)); } if (sum <= 0.0) @@ -982,7 +975,7 @@ static int GraphMeterMode_lookupCell(const Meter* this, const GraphDrawContext* assert(y < graphHeight); y = graphHeight - 1 - y; - uint8_t itemIndex = UINT8_MAX; + uint8_t itemIndex = (uint8_t)-1; *details = 0x00; // Empty the cell if (maxItems < 1) @@ -1040,7 +1033,7 @@ static int GraphMeterMode_lookupCell(const Meter* this, const GraphDrawContext* } const GraphColorCell* cell = &valueStart[i]; - itemIndex = cell->c.itemIndex; + itemIndex = cell->c.itemNum - 1; *details = GraphMeterMode_scaleCellDetails(cell->c.details, scaleFactor); } /* fallthrough */ @@ -1049,7 +1042,7 @@ static int GraphMeterMode_lookupCell(const Meter* this, const GraphDrawContext* if (y == 0) *details |= 0xC0; - if (itemIndex == UINT8_MAX) + if (itemIndex == (uint8_t)-1) return BAR_SHADOW; assert(itemIndex < maxItems); diff --git a/Meter.h b/Meter.h index 8650128e4..734287cb8 100644 --- a/Meter.h +++ b/Meter.h @@ -102,7 +102,7 @@ typedef union GraphColorCell_ { int16_t scaleExp; uint16_t numDots; struct GraphColorCellCell_ { - uint8_t itemIndex; + uint8_t itemNum; uint8_t details; } c; } GraphColorCell;