Skip to content

Commit

Permalink
fix cpu mode with tilesize smaller than image size
Browse files Browse the repository at this point in the history
It was only tested on Linux platform. So, please check if it works on Windows. :)

Signed-off-by: ArchieMeng <archiemeng@protonmail.com>
  • Loading branch information
ArchieMeng committed Sep 17, 2022
1 parent 93ed2bc commit 97f5471
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions src/waifu2x.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -594,7 +594,7 @@ int Waifu2x::process_cpu(const ncnn::Mat& inimage, ncnn::Mat& outimage) const
int in_tile_x1 = std::min((xi + 1) * TILE_SIZE_X + prepadding_right, w);

// crop tile
ncnn::Mat in;
ncnn::Mat in, in_nopad;
{
if (channels == 3)
{
Expand All @@ -607,8 +607,10 @@ int Waifu2x::process_cpu(const ncnn::Mat& inimage, ncnn::Mat& outimage) const
if (channels == 4)
{
#if _WIN32
in_nopad = ncnn::Mat::from_pixels_roi(pixeldata, ncnn::Mat::PIXEL_BGRA2RGBA, w, h, xi * TILE_SIZE_X, yi * TILE_SIZE_Y, tile_w_nopad, tile_h_nopad);
in = ncnn::Mat::from_pixels_roi(pixeldata, ncnn::Mat::PIXEL_BGRA2RGBA, w, h, in_tile_x0, in_tile_y0, in_tile_x1 - in_tile_x0, in_tile_y1 - in_tile_y0);
#else
in_nopad = ncnn::Mat::from_pixels_roi(pixeldata, ncnn::Mat::PIXEL_RGBA, w, h, xi * TILE_SIZE_X, yi * TILE_SIZE_Y, tile_w_nopad, tile_h_nopad);
in = ncnn::Mat::from_pixels_roi(pixeldata, ncnn::Mat::PIXEL_RGBA, w, h, in_tile_x0, in_tile_y0, in_tile_x1 - in_tile_x0, in_tile_y1 - in_tile_y0);
#endif
}
Expand Down Expand Up @@ -639,7 +641,7 @@ int Waifu2x::process_cpu(const ncnn::Mat& inimage, ncnn::Mat& outimage) const

if (channels == 4)
{
in_alpha_tile = in.channel_range(3, 1).clone();
in_alpha_tile = in_nopad.channel_range(3, 1).clone();
}
}

Expand Down Expand Up @@ -790,7 +792,7 @@ int Waifu2x::process_cpu(const ncnn::Mat& inimage, ncnn::Mat& outimage) const

if (channels == 4)
{
in_alpha_tile = in.channel_range(3, 1).clone();
in_alpha_tile = in_nopad.channel_range(3, 1).clone();
}
}

Expand Down

0 comments on commit 97f5471

Please sign in to comment.