diff --git a/Sources/avif/AVIFEncoder.swift b/Sources/avif/AVIFEncoder.swift index 10d3410..2c926fa 100644 --- a/Sources/avif/AVIFEncoder.swift +++ b/Sources/avif/AVIFEncoder.swift @@ -47,16 +47,17 @@ public class AVIFEncoder { assert(size.width > 0 && size.height > 0, "You cannot safely scale an image to a zero width or height") #if os(macOS) - let destSize = NSMakeSize(CGFloat(size.width), CGFloat(size.height)) - let newImage = NSImage(size: destSize) - newImage.lockFocus() - image.draw(in: NSMakeRect(0, 0, destSize.width, destSize.height), - from: NSMakeRect(0, 0, image.size.width, image.size.height), - operation: NSCompositingOperation.copy, - fraction: CGFloat(1)) - newImage.unlockFocus() - newImage.size = destSize - return NSImage(data: newImage.tiffRepresentation!)! + let newWidth = size.width * (scale ?? 1) + let newHeight = size.height * (scale ?? 1) + + // Create a new NSSize object with the newly calculated size + let newSize = NSSize(width: newWidth.rounded(.down), height: newHeight.rounded(.down)) + + // Cast the NSImage to a CGImage + var imageRect = CGRect(origin: .zero, size: size) + guard let imageRef = image.cgImage(forProposedRect: &imageRect, context: nil, hints: nil) else { return image } + + return NSImage(cgImage: imageRef, size: newSize) #else UIGraphicsBeginImageContextWithOptions(size, false, scale ?? image.scale) image.draw(in: CGRect(origin: .zero, size: size)) diff --git a/Sources/avifc/AVIFAnimatedDecoder.mm b/Sources/avifc/AVIFAnimatedDecoder.mm index ef75eb3..eba7998 100644 --- a/Sources/avifc/AVIFAnimatedDecoder.mm +++ b/Sources/avifc/AVIFAnimatedDecoder.mm @@ -48,6 +48,7 @@ -(nullable id)initWithData:(nonnull NSData*)data { avifResult decodeResult = avifDecoderParse(_idec); if (decodeResult != AVIF_RESULT_OK) { avifDecoderDestroy(_idec); + _idec = nullptr; return nil; } return self; diff --git a/Sources/avifc/half.hpp b/Sources/avifc/half.hpp index 841b9a8..2f2e97e 100644 --- a/Sources/avifc/half.hpp +++ b/Sources/avifc/half.hpp @@ -24,6 +24,12 @@ #ifndef HALF_HALF_HPP #define HALF_HALF_HPP +#pragma clang diagnostic push +#pragma clang diagnostic ignored "-Weverything" +#pragma clang diagnostic ignored "-Wunused-value" +#pragma clang diagnostic ignored "-Wunused-result" +#pragma clang diagnostic pop + #define HALF_GCC_VERSION (__GNUC__*100+__GNUC_MINOR__) #if defined(__INTEL_COMPILER)