From 97f5471e661569862e0a15cf49ec0f7ac724ea1a Mon Sep 17 00:00:00 2001 From: ArchieMeng Date: Fri, 16 Sep 2022 00:59:36 +0800 Subject: [PATCH] fix cpu mode with tilesize smaller than image size It was only tested on Linux platform. So, please check if it works on Windows. :) Signed-off-by: ArchieMeng --- src/waifu2x.cpp | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/waifu2x.cpp b/src/waifu2x.cpp index 518609f..c39f3b3 100644 --- a/src/waifu2x.cpp +++ b/src/waifu2x.cpp @@ -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) { @@ -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 } @@ -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(); } } @@ -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(); } }