From 26cd687a65f7c4f6d2d8d40b6c646292e950d816 Mon Sep 17 00:00:00 2001 From: lltcggie Date: Fri, 8 Jul 2016 00:42:44 +0900 Subject: [PATCH] =?UTF-8?q?Bitmap=E3=81=AE=E8=AA=AD=E3=81=BF=E8=BE=BC?= =?UTF-8?q?=E3=81=BF=E3=81=AFSTBI=E3=82=92=E5=84=AA=E5=85=88=E3=81=95?= =?UTF-8?q?=E3=81=9B=E3=82=8B=E3=82=88=E3=81=86=E3=81=AB=E3=81=97=E3=81=9F?= =?UTF-8?q?(32=E3=83=93=E3=83=83=E3=83=88Bitmap=E3=82=92OpenCV=E3=81=A7?= =?UTF-8?q?=E8=AA=AD=E3=81=BF=E8=BE=BC=E3=82=80=E3=81=A8=E7=94=BB=E5=83=8F?= =?UTF-8?q?=E3=81=8C=E3=81=8A=E3=81=8B=E3=81=97=E3=81=8F=E3=81=AA=E3=82=8B?= =?UTF-8?q?=E3=81=8B=E3=82=89)=20#35?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- common/stImage.cpp | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/common/stImage.cpp b/common/stImage.cpp index a6b4702..530b301 100644 --- a/common/stImage.cpp +++ b/common/stImage.cpp @@ -228,14 +228,29 @@ Waifu2x::eWaifu2xError stImage::LoadMat(cv::Mat &im, const boost::filesystem::pa if (!readFile(input_file, img_data)) return Waifu2x::eWaifu2xError_FailedOpenInputFile; - cv::Mat im(img_data.size(), 1, CV_8U, img_data.data()); - original_image = cv::imdecode(im, cv::IMREAD_UNCHANGED); + const boost::filesystem::path ipext(input_file.extension()); + if (!boost::iequals(ipext.string(), ".bmp")) // 特定のファイル形式の場合OpenCVで読むとバグることがあるのでSTBIを優先させる + { + cv::Mat im(img_data.size(), 1, CV_8U, img_data.data()); + original_image = cv::imdecode(im, cv::IMREAD_UNCHANGED); - if (original_image.empty()) + if (original_image.empty()) + { + const Waifu2x::eWaifu2xError ret = LoadMatBySTBI(original_image, img_data); + if (ret != Waifu2x::eWaifu2xError_OK) + return ret; + } + } + else { const Waifu2x::eWaifu2xError ret = LoadMatBySTBI(original_image, img_data); if (ret != Waifu2x::eWaifu2xError_OK) - return ret; + { + cv::Mat im(img_data.size(), 1, CV_8U, img_data.data()); + original_image = cv::imdecode(im, cv::IMREAD_UNCHANGED); + if (original_image.empty()) + return ret; + } } }