Skip to content

Commit

Permalink
Merge pull request #138 from onevcat/fix/true-color-alpha-info
Browse files Browse the repository at this point in the history
Use alpha bitmap for true color type
  • Loading branch information
onevcat committed Oct 9, 2023
2 parents ad198b9 + 0660e58 commit 77b5466
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 5 deletions.
6 changes: 6 additions & 0 deletions Demo/Demo.xcodeproj/project.pbxproj
Expand Up @@ -188,6 +188,8 @@
4BFF950B271C077D001645A7 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4BFF950A271C077D001645A7 /* AppDelegate.swift */; };
4BFF950F271C077D001645A7 /* TopViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4BFF950E271C077D001645A7 /* TopViewController.swift */; };
4BFF9514271C077F001645A7 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 4BFF9513271C077F001645A7 /* Assets.xcassets */; };
D1285CBD2AD309BE005EABFA /* tRNS_alpha.apng in Resources */ = {isa = PBXBuildFile; fileRef = D1285CBC2AD309BE005EABFA /* tRNS_alpha.apng */; };
D1285CBE2AD309BE005EABFA /* tRNS_alpha.apng in Resources */ = {isa = PBXBuildFile; fileRef = D1285CBC2AD309BE005EABFA /* tRNS_alpha.apng */; };
/* End PBXBuildFile section */

/* Begin PBXFileReference section */
Expand Down Expand Up @@ -296,6 +298,7 @@
4BFF9513271C077F001645A7 /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = "<group>"; };
4BFF9518271C077F001645A7 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
4BFF951F271C07AC001645A7 /* APNGKit */ = {isa = PBXFileReference; lastKnownFileType = folder; name = APNGKit; path = ..; sourceTree = "<group>"; };
D1285CBC2AD309BE005EABFA /* tRNS_alpha.apng */ = {isa = PBXFileReference; lastKnownFileType = file; path = tRNS_alpha.apng; sourceTree = "<group>"; };
/* End PBXFileReference section */

/* Begin PBXFrameworksBuildPhase section */
Expand Down Expand Up @@ -365,6 +368,7 @@
4BC3D8CD271C095D004DF785 /* General */ = {
isa = PBXGroup;
children = (
D1285CBC2AD309BE005EABFA /* tRNS_alpha.apng */,
4B5B97382744831600431356 /* maneki-neko.apng */,
4BC3D8CE271C095D004DF785 /* elephant_apng@2x.apng */,
4BC3D8CF271C095D004DF785 /* APNG-4D.apng */,
Expand Down Expand Up @@ -629,6 +633,7 @@
4B5B975D2744835400431356 /* 035.png in Resources */,
4B5B976A2744835400431356 /* 005.png in Resources */,
4B5B976F2744835400431356 /* 008.png in Resources */,
D1285CBE2AD309BE005EABFA /* tRNS_alpha.apng in Resources */,
4B5B977B2744835400431356 /* 043.png in Resources */,
4B5B977A2744835400431356 /* 042.png in Resources */,
4B5B97502744835400431356 /* 055.png in Resources */,
Expand Down Expand Up @@ -708,6 +713,7 @@
4BC3D91D271C095D004DF785 /* ball.apng in Resources */,
4BC3D94D271C095D004DF785 /* 050.png in Resources */,
4BC3D960271C095D004DF785 /* 032.png in Resources */,
D1285CBD2AD309BE005EABFA /* tRNS_alpha.apng in Resources */,
4BC3D942271C095D004DF785 /* 041.png in Resources */,
4BC3D91C271C095D004DF785 /* elephant_apng.apng in Resources */,
4BC3D92B271C095D004DF785 /* 015.png in Resources */,
Expand Down
1 change: 1 addition & 0 deletions Demo/Demo/SampleImageScene/SampleImages.swift
Expand Up @@ -16,6 +16,7 @@ let sampleImages = [
"maneki-neko",
"APNG-cube",
"pyani",
"tRNS_alpha",
"pia",
"over_none",
"over_background",
Expand Down
7 changes: 2 additions & 5 deletions Source/APNGKit/APNGImageRenderer.swift
Expand Up @@ -484,18 +484,15 @@ extension IHDR {
var colorSpace: CGColorSpace {
switch colorType {
case .greyscale, .greyscaleWithAlpha: return .deviceGray
case .trueColor, .trueColorWithAlpha: return .deviceRGB
case .indexedColor: return .deviceRGB
case .indexedColor, .trueColor, .trueColorWithAlpha: return .deviceRGB
}
}

var bitmapInfo: CGBitmapInfo {
switch colorType {
case .greyscale:
return CGBitmapInfo(rawValue: CGImageAlphaInfo.none.rawValue)
case .trueColor:
return CGBitmapInfo(rawValue: CGImageAlphaInfo.noneSkipLast.rawValue)
case .greyscaleWithAlpha, .trueColorWithAlpha, .indexedColor:
case .indexedColor, .trueColor, .greyscaleWithAlpha, .trueColorWithAlpha:
return CGBitmapInfo(rawValue: CGImageAlphaInfo.premultipliedLast.rawValue)
}
}
Expand Down
Binary file not shown.

0 comments on commit 77b5466

Please sign in to comment.