Skip to content

Commit

Permalink
Update core
Browse files Browse the repository at this point in the history
Add RGB32 input support
  • Loading branch information
TianZerL committed Jun 29, 2020
1 parent 60bd6b9 commit 0d93227
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 5 deletions.
3 changes: 2 additions & 1 deletion Anime4KCore/include/Anime4K.h
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ class Anime4KCPP::Anime4K
void loadVideo(const std::string& srcFile);
void loadImage(const std::string& srcFile);
void loadImage(cv::InputArray srcImage);
void loadImage(int rows, int cols, unsigned char* data, size_t bytesPerLine = 0ULL, bool inputAsYUV444 = false);
void loadImage(int rows, int cols, unsigned char* data, size_t bytesPerLine = 0ULL, bool inputAsYUV444 = false, bool inputAsRGB32 = false);
void loadImage(int rows, int cols, unsigned char* r, unsigned char* g, unsigned char* b, bool inputAsYUV444 = false);
void loadImage(int rowsY, int colsY, unsigned char* y, int rowsU, int colsU, unsigned char* u, int rowsV, int colsV, unsigned char* v);
void setVideoSaveInfo(const std::string& dstFile, const CODEC codec = CODEC::MP4V, const double fps = 0.0);
Expand Down Expand Up @@ -176,6 +176,7 @@ class Anime4KCPP::Anime4K
cv::Mat orgY, orgU, orgV;
cv::Mat dstY, dstU, dstV;
bool inputYUV = false;
bool inputRGB32 = false;
VideoIO* videoIO = nullptr;

protected://arguments
Expand Down
19 changes: 17 additions & 2 deletions Anime4KCore/src/Anime4K.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -102,9 +102,18 @@ void Anime4KCPP::Anime4K::loadImage(cv::InputArray srcImage)
W = zf * orgW;
}

void Anime4KCPP::Anime4K::loadImage(int rows, int cols, unsigned char* data, size_t bytesPerLine, bool inputAsYUV444)
void Anime4KCPP::Anime4K::loadImage(int rows, int cols, unsigned char* data, size_t bytesPerLine, bool inputAsYUV444, bool inputAsRGB32)
{
orgImg = cv::Mat(rows, cols, CV_8UC3, data, bytesPerLine);
if (inputAsRGB32)
{
inputRGB32 = true;
cv::cvtColor(cv::Mat(rows, cols, CV_8UC4, data, bytesPerLine), orgImg, cv::COLOR_RGBA2RGB);
}
else
{
inputRGB32 = false;
orgImg = cv::Mat(rows, cols, CV_8UC3, data, bytesPerLine);
}
if (inputAsYUV444)
{
inputYUV = true;
Expand Down Expand Up @@ -190,6 +199,9 @@ void Anime4KCPP::Anime4K::saveImage(cv::Mat& dstImage)
else
throw "Only YUV444 can be saved to opencv Mat";
}
else if (inputRGB32)
cv::cvtColor(dstImg, dstImg, cv::COLOR_RGB2RGBA);

dstImage = dstImg;
}

Expand Down Expand Up @@ -222,6 +234,9 @@ void Anime4KCPP::Anime4K::saveImage(unsigned char*& data)
else
throw "Only YUV444 can be saved to data pointer";
}
else if (inputRGB32)
cv::cvtColor(dstImg, dstImg, cv::COLOR_RGB2RGBA);

size_t size = dstImg.step * H;
memcpy(data, dstImg.data, size);
}
Expand Down
2 changes: 0 additions & 2 deletions Anime4KCore/src/Anime4KGPUCNN.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,6 @@ bool Anime4KCPP::Anime4KGPUCNN::isInitializedGPU()
void Anime4KCPP::Anime4KGPUCNN::runKernelACNet(cv::InputArray orgImg, cv::OutputArray dstImg)
{
cl_int err;
int i;

cv::Mat orgImage = orgImg.getMat();
cv::Mat dstImage = dstImg.getMat();
Expand Down Expand Up @@ -528,7 +527,6 @@ void Anime4KCPP::Anime4KGPUCNN::runKernelACNet(cv::InputArray orgImg, cv::Output
void Anime4KCPP::Anime4KGPUCNN::runKernelACNetHDN(cv::InputArray orgImg, cv::OutputArray dstImg)
{
cl_int err;
int i;

cv::Mat orgImage = orgImg.getMat();
cv::Mat dstImage = dstImg.getMat();
Expand Down

0 comments on commit 0d93227

Please sign in to comment.