| 219 | } |
| 220 | |
| 221 | u8 bilinearInterpolatePowerOf2(u8 v00, u8 v10, u8 v01, |
| 222 | u8 v11, u8 dx, u8 dy) { |
| 223 | u16 dx_inv = 256 - dx; // 0 to 256 |
| 224 | u16 dy_inv = 256 - dy; // 0 to 256 |
| 225 | |
| 226 | // Scale down weights to fit into u16 |
| 227 | u16 w00 = (dx_inv * dy_inv) >> 8; // Max value 256 |
| 228 | u16 w10 = (dx * dy_inv) >> 8; |
| 229 | u16 w01 = (dx_inv * dy) >> 8; |
| 230 | u16 w11 = (dx * dy) >> 8; |
| 231 | |
| 232 | // Sum of weights should be approximately 256 |
| 233 | u16 weight_sum = w00 + w10 + w01 + w11; |
| 234 | |
| 235 | // Compute the weighted sum of pixel values |
| 236 | u16 sum = v00 * w00 + v10 * w10 + v01 * w01 + v11 * w11; |
| 237 | |
| 238 | // Normalize the result |
| 239 | u8 result = (sum + (weight_sum >> 1)) / weight_sum; |
| 240 | |
| 241 | return result; |
| 242 | } |
| 243 | |
| 244 | // Floating-point version of bilinear interpolation |
| 245 | u8 upscaleFloat(u8 v00, u8 v10, u8 v01, |
no outgoing calls
no test coverage detected