~ruther/CTU-FEE-B0B35APO-Semestral-project

a59007aef45d903bf17feda631d930c5bbebb862 — František Boháček 3 years ago e813054
feat: add image upscale using nearest-neighbor
1 files changed, 19 insertions(+), 0 deletions(-)

M image-viewer/src/image.c
M image-viewer/src/image.c => image-viewer/src/image.c +19 -0
@@ 125,6 125,25 @@ static void image_write_downscale(image_t *image, display_t *display,
    }
  }
}
static void image_write_upscale(image_t *image, display_t *display,
                                image_region_t region, double scale_factor) {
  float downscale_factor = 1 / scale_factor;
  uint16_t w = region.width, h = region.height;
  uint16_t sw = (uint16_t)(scale_factor * w), sh = (uint16_t)(scale_factor * h);

  uint16_t beg_x = (DISPLAY_WIDTH - sw) / 2;
  uint16_t beg_y = (DISPLAY_HEIGHT - sh) / 2;

  for (int y = 0; y < sh; y++) {
    for (int x = 0; x < sw; x++) {
      float px = (downscale_factor * (x + 0.5f)) + region.x;
      float py = (downscale_factor * (y + 0.5f)) + region.y;

      display_pixel_t result_display = image_get_pixel(image, px, py);
      display_set_pixel(display, x + beg_x, y + beg_y, result_display);
    }
  }
}
                            image_region_t region) {
  uint16_t w = region.width, h = region.height;
  uint16_t x = region.x, y = region.y;

Do not follow this link