Skip to content

Commit e129fac

Browse files
authored
fix cpu mode with tilesize smaller than image size (#187)
It was only tested on Linux platform. So, please check if it works on Windows. :) Signed-off-by: ArchieMeng <[email protected]>
1 parent 8e88a19 commit e129fac

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

src/waifu2x.cpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -594,7 +594,7 @@ int Waifu2x::process_cpu(const ncnn::Mat& inimage, ncnn::Mat& outimage) const
594594
int in_tile_x1 = std::min((xi + 1) * TILE_SIZE_X + prepadding_right, w);
595595

596596
// crop tile
597-
ncnn::Mat in;
597+
ncnn::Mat in, in_nopad;
598598
{
599599
if (channels == 3)
600600
{
@@ -607,8 +607,10 @@ int Waifu2x::process_cpu(const ncnn::Mat& inimage, ncnn::Mat& outimage) const
607607
if (channels == 4)
608608
{
609609
#if _WIN32
610+
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);
610611
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);
611612
#else
613+
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);
612614
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);
613615
#endif
614616
}
@@ -639,7 +641,7 @@ int Waifu2x::process_cpu(const ncnn::Mat& inimage, ncnn::Mat& outimage) const
639641

640642
if (channels == 4)
641643
{
642-
in_alpha_tile = in.channel_range(3, 1).clone();
644+
in_alpha_tile = in_nopad.channel_range(3, 1).clone();
643645
}
644646
}
645647

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

791793
if (channels == 4)
792794
{
793-
in_alpha_tile = in.channel_range(3, 1).clone();
795+
in_alpha_tile = in_nopad.channel_range(3, 1).clone();
794796
}
795797
}
796798

0 commit comments

Comments
 (0)