0
$\begingroup$

I am wondering about techniques for rendering a rotated and or scaled raster image. Currently I use the following algorithm

  1. Render everything at double resolution and store the result in A
  2. For each pixel in output image, assign it the value of the average of the four pixels in A
img(col, row) = 0.25f * (tmp(2 * col, 2 * row) + tmp(2 * col + 1, 2 * row) + tmp(2 * col, 2 * row + 1) + tmp(2 * col + 1, 2 * row + 1));

Current sampler looks like this:

            auto const loc_ret = vec2_t{static_cast<double>(col), static_cast<double>(row)};
            auto const src_pos =
                scale_factor * transform(loc_ret - loc_src_ret_coord, rot_x, rot_y) + origin_src;
            if(src_pos[0] >= 0 && src_pos[0] < src.width() && src_pos[1] >= 0
               && src_pos[1] < src.height())
            {
                auto const src_pixel =
                    src(static_cast<uint32_t>(src_pos[0]), static_cast<uint32_t>(src_pos[1]));
                auto& ret_pixel =
                    ret((col + ret.width()) % ret.width(), (row + ret.height()) % ret.height());
                ret_pixel = blend(ret_pixel, src_pixel, opacity);
            }

where

auto const scale_factor = 1.0 / (scale * layer.scaleFactor());

and scale is the scale used to down-sample the image once completed.

The algorithm works for rotated and down-scaled sources, however, it has no effect when the source is upscaled.

$\endgroup$
  • $\begingroup$ You just need better interpolation. Try bilinear, biquadratic, bicubic. $\endgroup$ – lightxbulb Nov 8 '20 at 10:03
  • $\begingroup$ @lightxbulb I guess interpolation only applies when upscaling. $\endgroup$ – user877329 Nov 8 '20 at 15:18
  • 1
    $\begingroup$ It applies always when you're sampling the signal at locations where the data was not defined. Even when you're downscaling it.It's just that you additionally apply some convolution filter on top when downscaling. $\endgroup$ – lightxbulb Nov 8 '20 at 16:22

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.