Merge pull request #3902 from apavlenko:doc_fix_imwrite_master

This commit is contained in:
Vadim Pisarevsky
2015-04-03 13:26:22 +00:00

View File

@@ -185,13 +185,14 @@ compression parameters :
void createAlphaMat(Mat &mat) void createAlphaMat(Mat &mat)
{ {
CV_Assert(mat.channels() == 4);
for (int i = 0; i < mat.rows; ++i) { for (int i = 0; i < mat.rows; ++i) {
for (int j = 0; j < mat.cols; ++j) { for (int j = 0; j < mat.cols; ++j) {
Vec4b& rgba = mat.at<Vec4b>(i, j); Vec4b& bgra = mat.at<Vec4b>(i, j);
rgba[0] = UCHAR_MAX; bgra[0] = UCHAR_MAX; // Blue
rgba[1] = saturate_cast<uchar>((float (mat.cols - j)) / ((float)mat.cols) * UCHAR_MAX); bgra[1] = saturate_cast<uchar>((float (mat.cols - j)) / ((float)mat.cols) * UCHAR_MAX); // Green
rgba[2] = saturate_cast<uchar>((float (mat.rows - i)) / ((float)mat.rows) * UCHAR_MAX); bgra[2] = saturate_cast<uchar>((float (mat.rows - i)) / ((float)mat.rows) * UCHAR_MAX); // Red
rgba[3] = saturate_cast<uchar>(0.5 * (rgba[1] + rgba[2])); bgra[3] = saturate_cast<uchar>(0.5 * (bgra[1] + bgra[2])); // Alpha
} }
} }
} }