Skip to content

Commit

Permalink
do not convert RGB/BGR inplace on imencode/imwrite
Browse files Browse the repository at this point in the history
  • Loading branch information
nihui authored Aug 8, 2023
1 parent 49039eb commit 4327ab2
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions highgui/src/highgui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -201,12 +201,16 @@ bool imwrite(const String& filename, InputArray _img, const std::vector<int>& pa
else if (img.type() == CV_8UC3)
{
c = 3;
cvtColor(img, img, COLOR_BGR2RGB);
Mat img2
cvtColor(img, img2, COLOR_BGR2RGB);
img = img2;
}
else if (img.type() == CV_8UC4)
{
c = 4;
cvtColor(img, img, COLOR_BGRA2RGBA);
Mat img2
cvtColor(img, img2, COLOR_BGRA2RGBA);
img = img2;
}
else
{
Expand Down Expand Up @@ -368,12 +372,16 @@ bool imencode(const String& ext, InputArray _img, std::vector<uchar>& buf, const
else if (img.type() == CV_8UC3)
{
c = 3;
cvtColor(img, img, COLOR_BGR2RGB);
Mat img2;
cvtColor(img, img2, COLOR_BGR2RGB);
img = img2;
}
else if (img.type() == CV_8UC4)
{
c = 4;
cvtColor(img, img, COLOR_BGRA2RGBA);
Mat img2;
cvtColor(img, img2, COLOR_BGRA2RGBA);
img = img2;
}
else
{
Expand Down

0 comments on commit 4327ab2

Please sign in to comment.