| 60 | } |
| 61 | |
| 62 | void upscaleRectangularPowerOf2(const CRGB *input, CRGB *output, u8 inputWidth, |
| 63 | u8 inputHeight, u8 outputWidth, u8 outputHeight) { |
| 64 | for (u8 y = 0; y < outputHeight; y++) { |
| 65 | for (u8 x = 0; x < outputWidth; x++) { |
| 66 | // Use 8-bit fixed-point arithmetic with 8 fractional bits |
| 67 | // (scale factor of 256) |
| 68 | u16 fx = ((u16)x * (inputWidth - 1) * 256) / (outputWidth - 1); |
| 69 | u16 fy = ((u16)y * (inputHeight - 1) * 256) / (outputHeight - 1); |
| 70 | |
| 71 | u8 ix = fx >> 8; // Integer part |
| 72 | u8 iy = fy >> 8; |
| 73 | u8 dx = fx & 0xFF; // Fractional part |
| 74 | u8 dy = fy & 0xFF; |
| 75 | |
| 76 | u8 ix1 = (ix + 1 < inputWidth) ? ix + 1 : ix; |
| 77 | u8 iy1 = (iy + 1 < inputHeight) ? iy + 1 : iy; |
| 78 | |
| 79 | // Direct array access - no XY mapping overhead |
| 80 | u16 i00 = iy * inputWidth + ix; |
| 81 | u16 i10 = iy * inputWidth + ix1; |
| 82 | u16 i01 = iy1 * inputWidth + ix; |
| 83 | u16 i11 = iy1 * inputWidth + ix1; |
| 84 | |
| 85 | CRGB c00 = input[i00]; |
| 86 | CRGB c10 = input[i10]; |
| 87 | CRGB c01 = input[i01]; |
| 88 | CRGB c11 = input[i11]; |
| 89 | |
| 90 | CRGB result; |
| 91 | result.r = |
| 92 | bilinearInterpolatePowerOf2(c00.r, c10.r, c01.r, c11.r, dx, dy); |
| 93 | result.g = |
| 94 | bilinearInterpolatePowerOf2(c00.g, c10.g, c01.g, c11.g, dx, dy); |
| 95 | result.b = |
| 96 | bilinearInterpolatePowerOf2(c00.b, c10.b, c01.b, c11.b, dx, dy); |
| 97 | |
| 98 | // Direct array access - no XY mapping overhead |
| 99 | u16 idx = y * outputWidth + x; |
| 100 | output[idx] = result; |
| 101 | } |
| 102 | } |
| 103 | } |
| 104 | |
| 105 | void upscaleArbitrary(const CRGB *input, CRGB *output, u16 inputWidth, |
| 106 | u16 inputHeight, const XYMap& xyMap) { |
no test coverage detected