From 0e69cddda20c495d4908c459c2f97c2861cd8ce8 Mon Sep 17 00:00:00 2001 From: okamotoR Date: Tue, 23 Jun 2020 21:36:47 +0900 Subject: [PATCH] add if block for indexed color images --- modules/imgcodecs/src/ios_conversions.mm | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/modules/imgcodecs/src/ios_conversions.mm b/modules/imgcodecs/src/ios_conversions.mm index e3363c28ae..53fb788d65 100644 --- a/modules/imgcodecs/src/ios_conversions.mm +++ b/modules/imgcodecs/src/ios_conversions.mm @@ -112,6 +112,21 @@ void UIImageToMat(const UIImage* image, m.step[0], colorSpace, bitmapInfo); } + else if (CGColorSpaceGetModel(colorSpace) == kCGColorSpaceModelIndexed) + { + // CGBitmapContextCreate() does not support indexed color spaces. + colorSpace = CGColorSpaceCreateDeviceRGB(); + m.create(rows, cols, CV_8UC4); // 8 bits per component, 4 channels + if (!alphaExist) + bitmapInfo = kCGImageAlphaNoneSkipLast | + kCGBitmapByteOrderDefault; + else + m = cv::Scalar(0); + contextRef = CGBitmapContextCreate(m.data, m.cols, m.rows, 8, + m.step[0], colorSpace, + bitmapInfo); + CGColorSpaceRelease(colorSpace); + } else { m.create(rows, cols, CV_8UC4); // 8 bits per component, 4 channels