From 0620cb60dfd245d98137150b8a42a6ca48bee3b7 Mon Sep 17 00:00:00 2001 From: Matthew Chen Date: Thu, 17 May 2018 16:31:04 -0400 Subject: [PATCH] Normalize image colorspace. --- .../attachments/SignalAttachment.swift | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/SignalMessaging/attachments/SignalAttachment.swift b/SignalMessaging/attachments/SignalAttachment.swift index bfd45e298..8e007ac23 100644 --- a/SignalMessaging/attachments/SignalAttachment.swift +++ b/SignalMessaging/attachments/SignalAttachment.swift @@ -772,19 +772,15 @@ public class SignalAttachment: NSObject { assert(newSize.width <= maxSize) assert(newSize.height <= maxSize) - let bitsPerComponent = cgImage.bitsPerComponent - let bytesPerRow = cgImage.bytesPerRow - guard let colorSpace = cgImage.colorSpace else { - owsFail("\(logTag) cgImage missing colorSpace.") - return nil - } - let bitmapInfo = cgImage.bitmapInfo - + let colorSpace = CGColorSpaceCreateDeviceRGB() + let bitmapInfo: CGBitmapInfo = [ + CGBitmapInfo(rawValue: CGImageByteOrderInfo.orderDefault.rawValue), + CGBitmapInfo(rawValue: CGImageAlphaInfo.premultipliedLast.rawValue)] guard let context = CGContext.init(data: nil, width: Int(newSize.width), height: Int(newSize.height), - bitsPerComponent: bitsPerComponent, - bytesPerRow: bytesPerRow, + bitsPerComponent: 8, + bytesPerRow: 0, space: colorSpace, bitmapInfo: bitmapInfo.rawValue) else { owsFail("\(logTag) could not create CGContext.")