Last active
November 12, 2018 16:35
-
-
Save turbulem/c819774cc3e05946caa895ec25fa0c92 to your computer and use it in GitHub Desktop.
GifFile.swift
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import Foundation | |
| import GifSwift.CLibgif | |
| public class GifFile { | |
| private let path: URL | |
| private let fileHandlePtr: UnsafeMutablePointer<GifFileType> | |
| private var fileHandle: GifFileType { | |
| return self.fileHandlePtr.pointee | |
| } | |
| deinit { | |
| DGifCloseFile(self.fileHandlePtr, nil) | |
| } | |
| // MARK: - API | |
| public init?(path: URL) { | |
| self.path = path | |
| let errorCode = UnsafeMutablePointer<Int32>.allocate(capacity: 1) | |
| if let handle = path.path.withCString({ DGifOpenFileName($0, errorCode) }) { | |
| self.fileHandlePtr = handle | |
| DGifSlurp(handle) | |
| } else { | |
| debugPrint("Error opening file \(errorCode.pointee)") | |
| return nil | |
| } | |
| } | |
| public var size: CGSize { | |
| return CGSize(width: Double(fileHandle.SWidth), height: Double(fileHandle.SHeight)) | |
| } | |
| public var imagesCount: Int { | |
| return Int(fileHandle.ImageCount) | |
| } | |
| } | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment