diff --git a/CheapRetouch/Services/InpaintEngine/PatchMatch.swift b/CheapRetouch/Services/InpaintEngine/PatchMatch.swift index 54e88d7..736bb90 100644 --- a/CheapRetouch/Services/InpaintEngine/PatchMatch.swift +++ b/CheapRetouch/Services/InpaintEngine/PatchMatch.swift @@ -294,8 +294,9 @@ final class PatchMatchInpainter { // MARK: - Texture Utilities private func loadCGImage(_ cgImage: CGImage, into texture: MTLTexture) throws { - let width = cgImage.width - let height = cgImage.height + // Use texture dimensions for consistency + let width = texture.width + let height = texture.height guard let context = CGContext( data: nil, @@ -309,6 +310,8 @@ final class PatchMatchInpainter { throw PatchMatchError.contextCreationFailed } + // Draw the image scaled to fit the texture dimensions + context.interpolationQuality = .high context.draw(cgImage, in: CGRect(x: 0, y: 0, width: width, height: height)) guard let data = context.data else { @@ -324,8 +327,9 @@ final class PatchMatchInpainter { } private func loadCGImageGrayscale(_ cgImage: CGImage, into texture: MTLTexture) throws { - let width = cgImage.width - let height = cgImage.height + // Use texture dimensions, scaling the mask if needed + let width = texture.width + let height = texture.height guard let context = CGContext( data: nil, @@ -339,6 +343,8 @@ final class PatchMatchInpainter { throw PatchMatchError.contextCreationFailed } + // Draw the mask scaled to fit the texture dimensions + context.interpolationQuality = .high context.draw(cgImage, in: CGRect(x: 0, y: 0, width: width, height: height)) guard let data = context.data else {