Skip to content

Commit 0e69cdd

Browse files
committed
add if block for indexed color images
1 parent 7fae2e8 commit 0e69cdd

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

modules/imgcodecs/src/ios_conversions.mm

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,21 @@ void UIImageToMat(const UIImage* image,
112112
m.step[0], colorSpace,
113113
bitmapInfo);
114114
}
115+
else if (CGColorSpaceGetModel(colorSpace) == kCGColorSpaceModelIndexed)
116+
{
117+
// CGBitmapContextCreate() does not support indexed color spaces.
118+
colorSpace = CGColorSpaceCreateDeviceRGB();
119+
m.create(rows, cols, CV_8UC4); // 8 bits per component, 4 channels
120+
if (!alphaExist)
121+
bitmapInfo = kCGImageAlphaNoneSkipLast |
122+
kCGBitmapByteOrderDefault;
123+
else
124+
m = cv::Scalar(0);
125+
contextRef = CGBitmapContextCreate(m.data, m.cols, m.rows, 8,
126+
m.step[0], colorSpace,
127+
bitmapInfo);
128+
CGColorSpaceRelease(colorSpace);
129+
}
115130
else
116131
{
117132
m.create(rows, cols, CV_8UC4); // 8 bits per component, 4 channels

0 commit comments

Comments
 (0)