Skip to content

Commit

Permalink
fix animation bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
awxkee committed Oct 27, 2023
1 parent 45c63a8 commit 2836959
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 10 deletions.
21 changes: 11 additions & 10 deletions Sources/avif/AVIFEncoder.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
1 change: 1 addition & 0 deletions Sources/avifc/AVIFAnimatedDecoder.mm
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
6 changes: 6 additions & 0 deletions Sources/avifc/half.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 2836959

Please sign in to comment.