@@ -46,52 +46,21 @@ private enum Layout {
4646
4747 Determined empirically to match the original ImageMagick output.
4848 */
49- static let widthResizeFactor = 1.58
49+ static let widthResizeFactor = 1.92
5050
5151 /**
5252 Resize factor to fit app icon height inside disk icon.
5353
5454 Determined empirically to match the original ImageMagick output.
5555 */
56- static let heightResizeFactor = 1.82
56+ static let heightResizeFactor = 1.92
5757
5858 /**
5959 Vertical offset factor to position app icon correctly on disk icon.
6060
6161 Determined empirically to match the original ImageMagick output.
6262 */
63- static let verticalOffsetFactor = 0.063
64- }
65-
66- // MARK: - Image Operations
67-
68- extension CGImage {
69- func applyingPerspective( using context: CIContext ) throws ( ComposeIconError) -> CGImage {
70- let ciImage = CIImage ( cgImage: self )
71- let filter = CIFilter . perspectiveTransform ( )
72-
73- let w = Double ( width)
74- let h = Double ( height)
75-
76- filter. inputImage = ciImage
77- filter. topLeft = CGPoint ( x: w * Layout. perspectiveInset, y: h)
78- filter. topRight = CGPoint ( x: w * ( 1 - Layout. perspectiveInset) , y: h)
79- filter. bottomLeft = CGPoint ( x: 0 , y: 0 )
80- filter. bottomRight = CGPoint ( x: w, y: 0 )
81-
82- guard let outputImage = filter. outputImage else {
83- throw . perspectiveTransformFailed
84- }
85-
86- let inputExtent = ciImage. extent
87- let croppedImage = outputImage. cropped ( to: inputExtent)
88-
89- guard let result = context. createCGImage ( croppedImage, from: inputExtent) else {
90- throw . perspectiveTransformFailed
91- }
92-
93- return result
94- }
63+ static let verticalOffsetFactor = 0.043
9564}
9665
9766// MARK: - Main
@@ -113,19 +82,13 @@ func run() throws(ComposeIconError) {
11382 throw . loadFailed( diskIconURL)
11483 }
11584
116- // Reuse CIContext for efficiency
117- let ciContext = CIContext ( )
118-
119- // Apply perspective transformation
120- let transformedAppImage = try appImage. applyingPerspective ( using: ciContext)
121-
12285 // Resize app icon to fit inside disk icon
12386 let resizedSize = CGSize (
12487 width: ( Double ( diskImage. width) / Layout. widthResizeFactor) . rounded ( ) ,
12588 height: ( Double ( diskImage. height) / Layout. heightResizeFactor) . rounded ( )
12689 )
12790
128- guard let resizedAppImage = transformedAppImage . resized ( to: resizedSize) else {
91+ guard let resizedAppImage = appImage . resized ( to: resizedSize) else {
12992 throw . resizeFailed
13093 }
13194
0 commit comments