Coder Social home page Coder Social logo

apngkit's Introduction

APNGKit

APNGKit is a high performance framework for loading and displaying APNG images in iOS and macOS. It's built with high-level abstractions and brings a delightful API. Since be that, you will feel at home and joy when using APNGKit to play with images in APNG format.

APNG, what and why?

The Animated Portable Network Graphics (APNG) is a file format extending the well-known PNG format. It allows for animated PNG files that work similarly to animated GIF files, while supporting 24-bit images and 8-bit transparency not available for GIFs. This means much better quality of animation. At the same time, the file size is comparable to or even less than, if created carefully, GIFs.

Talk is cheap; show me the image. You can click on the image to see how it looks like when animating.

APNGKit Demo

That's cool. APNG is much better! But wait...why haven't I heard about APNG before? It is not a popular format, so why should I use it in my next great iOS/macOS app?

Good question! APNG is an excellent extension for regular PNG, and it is also very simple to use and not conflicting with current PNG standard (It consists a standard PNG header, so if your platform does not support APNG, it will be recognized as a normal PNG with its first frame being displayed as a static image). But unfortunately, it is a rebel format so that it is not accepted by the PNG group. However, it is accepted by many vendors and is even mentioned in W3C Standards. There is another format called MNG (Multiple-image Network Graphics), which is created by the same team as PNG. It is a comprehensive format, but very very very (重要的事要说三遍) complex. It is so complex that despite being a "standard", it was almost universally rejected. There is only one "popular" browser called Konqueror(at least I have used it before when I was in high school) that supports MNG, which is really a sad but reasonable story.

Even though APNG is not accepted currently, we continue to see the widespread implementation of it. Apple recently supported APNG in both desktop and mobile Safari. Microsoft Edge and Chrome are also considering adding APNG support since it is already officially added in WebKit core.

APNG is such a nice format to bring users much better experience of animating images. The more APNG is used, the more recognition and support it will get. Not only in the browsers world, but also in the apps we always love. That's why I created this framework.

Installation

Requirement

iOS 9.0+ / macOS 10.11+ / tvOS 9.0+

Swift Package Manager

The recommended way to install APNGKit is to use Swift Package Manager. Adding it to your project with Xcode:

CocoaPods

CocoaPods is a dependency manager for Cocoa projects.

$ gem install cocoapods

To integrate APNGKit into your Xcode project using CocoaPods, specify it in your Podfile:

source 'https://github.com/CocoaPods/Specs.git'
platform :ios, '9.0'
use_frameworks!

target 'your_app' do
  pod 'APNGKit', '~> 2.0'
end

Then, run the following command:

$ pod install

You should open the {Project}.xcworkspace instead of the {Project}.xcodeproj after you installed anything from CocoaPods.

For more information about how to use CocoaPods, I suggest this tutorial.

Usage

Basic

Import APNGKit into your source files in which you want to use the framework.

import APNGKit

Load an APNG Image

// Load an APNG image from file in main bundle
var image = try APNGImage(named: "your_image")

// Or
// Load an APNG image from file at specified path
if let url = Bundle.main.url(forResource: "your_image", withExtension: "apng") {
    image = try APNGImage(fileURL: path)
}

// Or
// Load an APNG image from data
let data: Data = ... // From disk or network or anywhere else.
image = try APNGImage(data: data)

You may notice that all initializers are throwable. If anything is wrong during creating the image, it let you know the error explicitly and you have a chance to handle it. We will cover the error handling soon later.

Display an APNG Image

When you have an APNGImage object, you can use it to initialize an image view and display it on screen with an APNGImageView, which is a subclass of UIView or NSView:

let image: APNGImage = ... // You already have an APNG image object.

let imageView = APNGImageView(image: image)
view.addSubview(imageView)

Start animation

The animation will be played automatically as soon as the image view is created with a valid APNG image. If you do not want the animation to be played automatically, set the autoStartAnimationWhenSetImage property to false before you assign an image:

let imageView = APNGImageView(frame: .zero)
imageView.autoStartAnimationWhenSetImage = false
imageView.image = image

// Start the animation manually:
imageView.startAnimating()

XIB or Storyboard

If you are an Interface Builder lover, drag a UIView (or NSView) (Please note, not a UIImageView or NSImageView) to the canvas, and modify its class to APNGImageView. Then, you can drag an IBOutlet and play with it as usual, such as setting its image property.

Delegates

APNG defines the play loop count as numberOfPlays in APNGImage, and APNGKit respects it by default. To inspect the end of each loop, register yourself as a delegate of APNGImageView.onOnePlayDone:

class ViewController: UIViewController {
    override func viewDidLoad() {
        super.viewDidLoad()

        let imageView = APNGImageView(image: image)
        imageView.onOnePlayDone.delegate(on: self) { (self, count) in
            print("Played: \(count)")
        }
    }
}

When numberOfPlays is nil, the animation will be played forever. If it is a limited non-zero value, the animation will be stopped at the final frame when the loop count reaches the limit. To inspect the whole animation is done, use onAllPlaysDone:

imageView.onAllPlaysDone.delegate(on: self) { (self, _) in
    print("All done.")
}

APNGKit loads the data in a streaming way by default, it reads the frame information while playing the animation. Since APNG encodes the duration in each frame, it is not possible to get the whole animation duration before loading all frames information. Before the first reading pass finishes, you can only get a partial duration for loaded frames. To get the full duration, use APNGImage.onFramesInformationPrepared:

let image = try APNGImage(named: "image")
image.onFramesInformationPrepared.delegate(on: self) { (self, _) in
    switch image.duration {
        case .full(let duration):
            print("Full duration: \(duration)")
        case .partial:
            print("This should not happen.")
    }
}

imageView.image = image

Or, you can specify the .fullFirstPass option while creating the APNGImage. It reads all frames before starting rendering and animating the image:

let image = try APNGImage(named: "image", options: [.fullFirstPass])
print(image.duration) // .full(duration)

APNGKit provides a few other reading options. Please let me skip it for now and you can check them in documentation.

Error handling

While creating image

Creating an APNGImage can throw an error if anything goes wrong. All possible errors while decoding are defined as an APNGKitError.decoderError. When an error happens while creating the image, you are expected to check if it should be treated as a normal static image. If so, try to set it as the static image:

do {
    let image = try APNGImage(named: data.imageName)
    imageView.image = image
} catch {
    if let normalImage = error.apngError?.normalImage {
        imageView.staticImage = normalImage
    } else {
        print("Error: \(error)")
    }
}

While playing animation

If some frames are broken, the default image defined in APNG should be displayed as a fallback. You can get this in APNGKit for free. To get notified when this happens, listen to APNGImageView.onFallBackToDefaultImage:

imageView.onDecodingFrameError.delegate(on: self) { (self, error) in
    print("A frame cannot be decoded. After this, either onFallBackToDefaultImage or onFallBackToDefaultImageFailed happens.")
}

imageView.onFallBackToDefaultImage.delegate(on: self) { (self, _) in
    print("Fall back to default image.")
}
imageView.onFallBackToDefaultImageFailed.delegate(on: self) { (self, error) in
    print("Tried to fall back to default image, but it fails: \(error)")
}

PNG compression

Xcode will compress all PNG files in your app bundle when you build the project. Since APNG is an extension format of PNG, Xcode will think there are redundancy data in that file and compress it into a single static image. When this happens, you may inspect a log message from APNGKit:

CgBI chunk found. It seems that the input image is compressed by Xcode and not supported by APNGKit. Consider to rename it to apng to prevent compressing.

Usually this is not what you want when working with APNG. You can disable the PNG compression by setting "COMPRESS_PNG_FILES" to NO in the build settings of your app target. However, it will also prevent Xcode to optimize your other regular PNGs.

A better approach would be renaming your APNG files with an extension besides of "png". If you do so, Xcode will stop recognizing your APNG files as PNG format, and will not apply compression on them. A suggested extension is "apng", which will be detected and handled by APNGKit seamlessly.

Acknowledgement

The demo elephant image in README file is stolen from ICS Lab, you can find the original post here.

Reference

If you are interested in APNG, you can know more about it from the links below (some of them are written in Chinese).

APNGKit can only load and display APNG image now. The creating feature will be developed later. If you need to create APNG file now, I suggest using iSparta or apngasm instead for now.

License

APNGKit is released under the MIT license. See LICENSE for details.

apngkit's People

Contributors

aodhol avatar buzzmusiq avatar carlosdigio avatar cetauri avatar christopherrogers avatar dorofiykolya avatar helloyako avatar jdmcd avatar lumenlunae avatar noppefoxwolf avatar onevcat avatar sidepelican avatar thii avatar tyljohnny avatar w4-hojin avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

apngkit's Issues

Repeatedly push an view controller whose view owned a apng animation view and pop it, app will crash.

This is the occasional problem. And we detected it by our apm system. And finally positioned to the APNGKit. I test the APNGKit's demo, it also has the same problem.

This is the error symbol stack log of APNGKitDemo proj.

Hardware Model:      iPhone7,2
Process:             APNGDemo-iOS [3710]
Path:                /private/var/containers/Bundle/Application/42CDB407-533D-4EA7-8F5D-77F199CBAC8B/APNGDemo-iOS.app/APNGDemo-iOS
Identifier:          com.onevcat.APNGDemo-iOS
Version:             1 (1.0)
Code Type:           ARM-64 (Native)
Role:                Foreground
Parent Process:      launchd [1]
Coalition:           com.onevcat.APNGDemo-iOS [3835]


Date/Time:           2017-11-07 10:28:59.6368 +0800
Launch Time:         2017-11-07 10:27:52.6125 +0800
OS Version:          iPhone OS 10.3.2 (14F89)
Report Version:      104

Exception Type:  EXC_BAD_ACCESS (SIGSEGV)
Exception Subtype: KERN_INVALID_ADDRESS at 0x0000000109e38000
Termination Signal: Segmentation fault: 11
Termination Reason: Namespace SIGNAL, Code 0xb
Terminating Process: exc handler [0]
Triggered by Thread:  0

Filtered syslog:
None found

Thread 0 name:  Dispatch queue: com.apple.main-thread
Thread 0 Crashed:
0   libsystem_platform.dylib      	0x000000018bd20e10 _platform_memmove + 176
1   CoreGraphics                  	0x000000018e0702c0 decode_data + 13144
2   CoreGraphics                  	0x000000018e239720 img_decode_read + 2024
3   CoreGraphics                  	0x000000018e23d490 img_alphamerge_read + 548
4   CoreGraphics                  	0x000000018e2408fc img_data_lock + 6124
5   CoreGraphics                  	0x000000018e23f0b8 CGSImageDataLock + 176
6   CoreGraphics                  	0x000000018e05f1c0 ripc_AcquireImage + 756
7   CoreGraphics                  	0x000000018e2539a4 ripc_DrawImage + 656
8   CoreGraphics                  	0x000000018e243b50 CGContextDrawImageWithOptions + 632
9   QuartzCore                    	0x000000018fe87a8c CA::Render::(anonymous namespace)::create_image_by_rendering+ 105100 (CGImage*, CGColorSpace*, unsigned int, double) + 1068
10  QuartzCore                    	0x000000018fe88960 CA::Render::(anonymous namespace)::create_image_from_rgb_image+ 108896 (CGImage*, CGColorSpace*, unsigned int, double) + 660
11  QuartzCore                    	0x000000018fe874b0 CA::Render::create_image+ 103600 (CGImage*, CGColorSpace*, unsigned int, double) + 876
12  QuartzCore                    	0x000000018fe89238 CA::Render::copy_image+ 111160 (CGImage*, CGColorSpace*, unsigned int, double, double) + 472
13  QuartzCore                    	0x000000018ff87434 -[CALayer+ 1152052 (CALayerPrivate) _copyRenderLayer:layerFlags:commitFlags:] + 480
14  QuartzCore                    	0x000000018fef4a74 CA::Context::commit_layer+ 551540 (CA::Layer*, unsigned int, unsigned int, void*) + 108
15  QuartzCore                    	0x000000018ff7a3a8 CA::Layer::commit_if_needed(CA::Transaction*, void (*)+ 1098664 (CA::Layer*, unsigned int, unsigned int, void*), void*) + 388
16  QuartzCore                    	0x000000018feb39ac x_hash_table_foreach + 72
17  QuartzCore                    	0x000000018ff1d4c0 CA::Transaction::foreach_root(void (*)+ 718016 (CA::Layer*, void*), void*) + 40
18  QuartzCore                    	0x000000018fef5778 CA::Context::commit_transaction+ 554872 (CA::Transaction*) + 1320
19  QuartzCore                    	0x000000018ff1c3ac CA::Transaction::commit+ 713644 () + 504
20  QuartzCore                    	0x000000018ff1ce78 CA::Transaction::observer_callback+ 716408 (__CFRunLoopObserver*, unsigned long, void*) + 120
21  CoreFoundation                	0x000000018cc149a8 __CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION__ + 32
22  CoreFoundation                	0x000000018cc12630 __CFRunLoopDoObservers + 372
23  CoreFoundation                	0x000000018cc12a7c __CFRunLoopRun + 956
24  CoreFoundation                	0x000000018cb42da4 CFRunLoopRunSpecific + 424
25  GraphicsServices              	0x000000018e5ac074 GSEventRunModal + 100
26  UIKit                         	0x0000000192dfd058 UIApplicationMain + 208
27  APNGDemo-iOS                  	0x0000000100097cfc 0x100090000 + 31996
28  libdyld.dylib                 	0x000000018bb5159c start + 4

Adding APNGKit project to workplace and build with Xcode 9 beta got error

As title, I build APNGKit project by self, and try to build my project with Xcode 9 beta, it got error like this:

The following binaries use incompatible versions of Swift:
...

Should I change any setting after I upgrade Xcode? My project is using objective-c.

EDIT:

I try to set my app target's setting to:

ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = NO

It can build success, but run time crash.

apng's with transparent alpha, appear blown out

Loading in an apng appears to just assign alpha values of 1 or 0. Any alpha values above 0 appear to be clamped to 1. When I look at the apng's in Finder/Preview on a mac, the alpha works fine.

The first frame is skipped (even when it's not set to skip) when calling startAnimating

The first frame is skipped (even when it's not set to skip) when calling startAnimating and when calling stopAnimating and then startAnimating again, the frame when stop was called is shown briefly.
Attached is a test image with frames red[1], yellow[2], green[3], blue[4].
test_sequence

I resolved this by changing startAnimating function by adding

    guard let image = image else {
        return
    }
    let frameIndex: Int = image.firstFrameHidden ? 1 : 0
    currentFrameIndex = frameIndex
    let frame = image.next(currentIndex: currentFrameIndex)
    currentFrameDuration = frame.duration
    updateContents(frame.image)

see https://github.com/imbrig/APNGKit/commit/0b003f19e77a9e51881dbc83ebfdb62fb3a478fb

APNGImage always returns nil

a line of code below always returns nil even though I passed apng image:

var image = APNGImage(named: "your_image")

Thanks

Issue in compiling with xcode 8 - for legacy support - swift 2.3

Hi!

I am trying to use the library. I get error for below:
/APNGKit/Frame.swift:75:73: Nil is not compatible with expected argument type 'CGDataProviderReleaseDataCallback' (aka '@convention(c) (UnsafeMutablePointer<()>, UnsafePointer<()>, Int) -> ()')

Tried this for most versions of library - 0.1.0 to 0.1.4.

Please suggest way to deal with this. My project is in Swift 2.3, so need library compiled with 2.3 to be used.

Thanks!

no functions visible in objective C

I can't see any init functions for either APNGImage or APNGImageView when trying to use in objective-c

I can see the Class name, but can't access any properties or functions
(using swift 4.2 in OBjective C project)

Won't build with xcode 10.0 beta 2

error: Cycle inside APNGKit; building could produce unreliable results.
Cycle details:
→ Target 'APNGKit' has link command with output '/Users/rob/Library/Developer/Xcode/DerivedData/ChillRemote-cdjhgicaxmoirdbnrfmvaaufhlfa/Build/Products/Debug-iphoneos/APNGKit/APNGKit.framework/APNGKit'

Showing All Messages
:-1: Cycle inside APNGKit; building could produce unreliable results.
Cycle details:
→ Target 'APNGKit' has link command with output '/Users/rob/Library/Developer/Xcode/DerivedData/ChillRemote-cdjhgicaxmoirdbnrfmvaaufhlfa/Build/Products/Debug-iphoneos/APNGKit/APNGKit.framework/APNGKit'

deinit crash for iOS

hi 猫神

我在 deinit 时手动 调用stopAnimating(), 偶现 crash , 概率比较高, 控制台可以明显的看到释放代码执行了, 我将 APNGImageView 用于 CollocationView 中

释放的代码:
deinit {
stopAPNG()
}

func stopAPNG() {
if let arFilterAPNGView = arFilterAPNGView {
GCDUtils.main({
print("(Thread.current) ---------------- arFilterAPNGView")
arFilterAPNGView.stopAnimating()
self.arFilterAPNGView = nil
})
}
}

crash时 控制台的 堆栈

  • thread #21, queue = 'gcdTimerQueue'
    frame #0: 0x00000001817958e8 libsystem_kernel.dylib__ulock_wait + 8 frame #1: 0x0000000104997300 libdispatch.dylib_dispatch_ulock_wait + 48
    frame #2: 0x0000000104997428 libdispatch.dylib_dispatch_thread_event_wait_slow + 36 frame #3: 0x000000010497e230 libdispatch.dylib_dispatch_barrier_sync_f_slow + 240
    frame #4: 0x0000000103f797ac APNGKitAPNGImageView.(startAnimating() -> ()).(closure #1) [inlined] function signature specialization <Arg[0] = Owned To Guaranteed> of APNGKit.APNGImageView.(startAnimating () -> ()).(closure #1) at APNGImageView.swift:185 [opt] frame #5: 0x0000000103f79704 APNGKitAPNGImageView.(startAnimating() -> ()).(closure #1) at APNGImageView.swift:184 [opt]
    frame #6: 0x0000000103f7f140 APNGKit`GCDTimer.(Event.setter).(closure #1) [inlined] function signature specialization <Arg[0] = Owned To Guaranteed> of APNGKit.GCDTimer.(self=) -> ()).(closure #1) at GCDTimer.swift:66 [opt]
    • frame #7: 0x0000000103f7f114 APNGKitGCDTimer.(Event.setter).(closure #1) at GCDTimer.swift:65 [opt] frame #8: 0x000000010496da10 libdispatch.dylib_dispatch_client_callout + 16
      frame #9: 0x0000000104979a84 libdispatch.dylib_dispatch_continuation_pop + 552 frame #10: 0x00000001049881f8 libdispatch.dylib_dispatch_source_latch_and_call + 204
      frame #11: 0x000000010496fa60 libdispatch.dylib_dispatch_source_invoke + 828 frame #12: 0x000000010497b128 libdispatch.dylib_dispatch_queue_serial_drain + 692
      frame #13: 0x0000000104971634 libdispatch.dylib_dispatch_queue_invoke + 852 frame #14: 0x000000010497d630 libdispatch.dylib_dispatch_root_queue_drain + 552
      frame #15: 0x000000010497d39c libdispatch.dylib_dispatch_worker_thread3 + 140 frame #16: 0x000000018185b100 libsystem_pthread.dylib_pthread_wqthread + 1096
      frame #17: 0x000000018185acac libsystem_pthread.dylib`start_wqthread + 4

短时间内重复销毁创建ApngImageView会导致crash

修改demo中的代码,执行下面的操作,必会crash

@IBAction func click(_ sender: Any) {
        var i = 0
        while i < 3 {
            i += 1
            DispatchQueue.main.async {
                self.test()
            }
            print("count: \(i) \(NSDate())")
//            Thread.sleep(forTimeInterval: 0.3)
        }
    }
    func test() {
        if let path = image?.path {
            imageView?.stopAnimating()
            imageView?.removeFromSuperview()
            imageView = nil
            let apngImage: APNGImage?
            if path.contains("@2x") {
                apngImage = APNGImage(named: (path as NSString).lastPathComponent, progressive: true)
            } else {
                apngImage = APNGImage(contentsOfFile: path, saveToCache: true, progressive: true)
            }
            imageView = APNGImageView.init(image: apngImage)
            imageView?.frame = CGRect(x: 100, y: 100, width: 200, height: 200)
            view.addSubview(imageView!)
            imageView?.startAnimating()
            print("start")
        }
    }
    

Crash when load a normal png

I'm trying to load a normal png and it crashes libpng error: CgBI: unhandled critical chunk

Is there any way to check if the image is an APNG or normal PNG?

Animation stops when scrolling

I have an APNGImageView in a collection view and whenever I start scrolling, the animation pauses. Once I stop scrolling, the animations speeds up and appears to catch up to where it would have been. How do I make it so the animation doesn't stop when scrolling?

returns image is nil

I have an apng image that has 200 frames and extension of pang image is .png
Whenever I do:

apngView = APNGImageView(image: image)

image is nil even though the image exists in assets

I am using Xcode9

Carthage in Objective-C context

Hey,

I'm trying to use APNGKit with Carthage in Objective-C context. I can't use Swift because its an Unity project. Is this combination possible? I imported <APNGKit/APNGKit-Swift.h> but the header file does only expose the default init and initWithDecoder methods. I tried [[APNGImage alloc] contentsOfFile:@""] wich throws No visible @interface for 'APNGImage' declares the selector 'contentsOfFile:'

App crash when showing apng image view on each collection view cell

I created a collection view, each collection cell contains apng image view, after scrolling the collection view from left to right the app crashes.

ERROR
#0. Crashed: com.apple.main-thread
0 libsystem_platform.dylib 0x1bbf06c6 _platform_memmove + 37
1 CoreGraphics 0x1d5639af decode_data + 10762
2 CoreGraphics 0x1d6e9471 img_decode_read + 226
3 CoreGraphics 0x1d6eca25 img_alphamerge_read + 382
4 CoreGraphics 0x1d6efc25 img_data_lock + 6540
5 CoreGraphics 0x1d6ee261 CGSImageDataLock + 116
6 CoreGraphics 0x1d555fa7 ripc_AcquireImage + 632
7 CoreGraphics 0x1d701975 ripc_DrawImage + 648
8 CoreGraphics 0x1d68075b CGContextDelegateDrawImage + 46
9 CoreGraphics 0x1d6f227d CGContextDrawImageWithOptions + 420
10 CoreGraphics 0x1d6f2499 CGContextDrawImage + 52
11 QuartzCore 0x1f11b0bb CA::Render::(anonymous namespace)::create_image_by_rendering(CGImage*, CGColorSpace*, unsigned int, float) + 716
12 QuartzCore 0x1f11be43 CA::Render::(anonymous namespace)::create_image_from_rgb_image(CGImage*, CGColorSpace*, unsigned int, float) + 558
13 QuartzCore 0x1f11ab69 CA::Render::create_image(CGImage*, CGColorSpace*, unsigned int, float) + 456
14 QuartzCore 0x1f11c63b CA::Render::copy_image(CGImage*, CGColorSpace*, unsigned int, double, float) + 446
15 QuartzCore 0x1f1fdd1f -[CALayer(CALayerPrivate) _copyRenderLayer:layerFlags:commitFlags:] + 574
16 QuartzCore 0x1f1ff4c9 CA::Layer::copy_render_layer(CA::Transaction*, unsigned int, unsigned int*) + 34
17 QuartzCore 0x1f17e1a7 CA::Context::commit_layer(CA::Layer*, unsigned int, unsigned int, void*) + 90
18 QuartzCore 0x1f1f036b CA::Layer::commit_if_needed(CA::Transaction*, void ()(CA::Layer, unsigned int, unsigned int, void*), void*) + 324
19 QuartzCore 0x1f1410ad x_hash_table_foreach + 46
20 QuartzCore 0x1f19e06d CA::Transaction::foreach_root(void ()(CA::Layer, void*), void*) + 28
21 QuartzCore 0x1f17ecff CA::Context::commit_transaction(CA::Transaction*) + 1542
22 QuartzCore 0x1f19cfdb CA::Transaction::commit() + 578
23 QuartzCore 0x1f19db2f CA::Transaction::observer_callback(__CFRunLoopObserver*, unsigned long, void*) + 162
24 CoreFoundation 0x1c32f803 CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION + 20
25 CoreFoundation 0x1c32da55 __CFRunLoopDoObservers + 282
26 CoreFoundation 0x1c32e017 __CFRunLoopRun + 1358
27 CoreFoundation 0x1c2811af CFRunLoopRunSpecific + 470
28 CoreFoundation 0x1c280fd1 CFRunLoopRunInMode + 104
29 GraphicsServices 0x1da2bb41 GSEventRunModal + 80
30 UIKit 0x21609a53 UIApplicationMain + 150
31 Andyou 0x81a04 main (AppDelegate.swift:17)
32 libdyld.dylib 0x1ba6e4eb start + 2

APNGImageView content mode

I don't see a "contentMode" for APNGImageView as UIImageView has. I know this is a UIViewSubclass, but how would I replicate this behavior so the image doesn't stretch?

Invalid transparency (compression off, APNG source is valid)

Can't understand the problem. I try to load simple APNG image, it is valid (I've checked it via several browsers). And when I look for it with debug mode enabled, I see normal image too. But on the Simulator and on a real device I see image without transparency, where all semi-transparent pixels are set to white. I can't understand what's the reason of this. Compression is OFF in Xcode, file source has "apng" extension (double checked this). When I tried to load this image via UIImage - I saw the normal picture. What's wrong with me?

P.S. Code is pretty simple.

override func viewDidAppear(_ animated: Bool) {
    let image = APNGImage(named: "scene1")
    let imageView = APNGImageView(image: image)
    view.addSubview(imageView)
}

Here you can see my application frozen with View Debug mode. Normal image in Debug area and broken inside the Simulator...

issue

Environment:
Xcode 8 GM Seed
iOS Simulator - iOS 9.3 / 10.0.1
iPhone 6S - iOS 10.0.1

Crash when Objective-C dealloc

Sometimes my app crashes when removing APNGImageView in Objective-C coded UIViewController .
In case of Swift, that's not happen.

I think this workaround is not enough for Objective-C.

// fix issue that `APNGImageView` may cause crash when deinit
layer.contents = nil

In Objective-C, sometimes deinit is not called when removing the APNGImageView from the parent view because of AutoreleasePool. So this workaround dose not affect, and crash it.

Podspec

Update podspec for Swift 4.2

Image isn't showing up

I tried both programmatically and storyboard ways, image simply not on screen. Although if I change APNGImage and APNGImageView to UIImage and UIImageView respectively, it works (w/o animation, of course). What could it be? (APNGKit v1.1.0)

Unexpected output result for specific apng files

Hello, I've been using the library for quite a long time, and it's great. Recently I found an issue with specific apng files which leads to and unexpected output when loading the file with the library. There is no different method when loading apng files, it just happen sometimes to specific files.

Here you have a video of the glitch (look at the vertical line created between the letter t and y):
actual-result

And here the expected result:
expected-result

Here you can download all the related files:
apng-bugreport.zip

Thanks

Project Bitcode issue

In out project, we setting the OTHER_CFLAGS to -fembed-bitcode but it show error:

Showing All Errors Only
ld: bitcode bundle could not be generated because '.../Build/Products/Debug-iphoneos/APNGKit/APNGKit.framework/APNGKit' was built without full bitcode. All frameworks and dylibs for bitcode must be generated from Xcode Archive or Install build for architecture arm64

Is any setting missing or APNGKit didn't support bitcode?

Swift 5 upgrade

Using Xcode 11 GM with Swift 5 tells me to convert APNGKit to support Swift 5.
I can see only one line of code needs to be changed, will we see an update for that?
Thanks!

image

animation time, no animation on iphone

could i set the total animation time? the total duration time of the apng is 1.5s and when i play the animation on iphone , there is not any animation . when run in simulator , have animation but seems weird, what is the reason? the duration of the apng is too short?

EXC_BAD_ACCESS on setting image

Hey,
many thanks for this project!

Can you give some instructions about how I can set my image for instantiating a APNGImage?

Usually I go with UIImage(named: "my-image-name") and it will go and get the correct resource from Images.xcassets.
Is APNGImage(named: String) looking for resources inside Images.xcassets, similiar to UIImage(named: String)?

I even tried to do work around and adding my image to "Build Phases -> Copy Bundle Resources".

let path = NSBundle.mainBundle().pathForResource("animated2", ofType: "apng")
if let path = path {
      let image2 = APNGImage(contentsOfFile: path)
      apngImageView.image = image2
}

Path seems to be correct: "/Users/[...]/Library/Developer/CoreSimulator/Devices/[...]/MyApp.app/animated2.apng"
Debugger says "image2" is not nil and shows me amount of frames and resolution.
But it always breaks with "EXC_BAD_ACCESS (code=2, ...)" when I'm setting image2 as the image of APNGImageView.

What am I doing wrong?

EDIT:
Okay, if I'm creating APNGItemView programmatically everything works fine.
Is the following right for make it working with interface builder?:

  • Adding UIView to Storyboard
  • Setting custom class to "APNGItemView"
  • Creating an IBOutlet named "apngImageView" (in my case above)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.