forked from shadowfacts/Tusker
Convert wide-gamut images to sRGB before uploading
This commit is contained in:
parent
0413f326a0
commit
5c479e3bf0
|
@ -69,13 +69,22 @@ enum CompositionAttachmentData {
|
||||||
}
|
}
|
||||||
|
|
||||||
let utType: UTType
|
let utType: UTType
|
||||||
if dataUTI == "public.heic" {
|
let image = CIImage(data: data)!
|
||||||
// neither Mastodon nor Pleroma handles HEIC well, so convert to JPEG
|
let needsColorSpaceConversion = image.colorSpace?.name != CGColorSpace.sRGB
|
||||||
let image = CIImage(data: data)!
|
|
||||||
|
// neither Mastodon nor Pleroma handles HEIC well, so convert to JPEG
|
||||||
|
// they also do a bad job converting wide color gamut images (they seem to just drop the profile, letting the wide-gamut values be reinterprete as sRGB)
|
||||||
|
// if that changes in the future, we'll need to pass the InstanceFeatures in here somehow and gate the conversion
|
||||||
|
if needsColorSpaceConversion || dataUTI == "public.heic" {
|
||||||
let context = CIContext()
|
let context = CIContext()
|
||||||
let colorSpace = image.colorSpace ?? CGColorSpace(name: CGColorSpace.sRGB)!
|
let sRGB = CGColorSpace(name: CGColorSpace.sRGB)!
|
||||||
data = context.jpegRepresentation(of: image, colorSpace: colorSpace, options: [:])!
|
if dataUTI == "public.png" {
|
||||||
utType = .jpeg
|
data = context.pngRepresentation(of: image, format: .ARGB8, colorSpace: sRGB)!
|
||||||
|
utType = .png
|
||||||
|
} else {
|
||||||
|
data = context.jpegRepresentation(of: image, colorSpace: sRGB)!
|
||||||
|
utType = .jpeg
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
utType = UTType(dataUTI)!
|
utType = UTType(dataUTI)!
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue