Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update to Swift 5.5, libturbojpeg 2.1.2 #25

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Code/CCBufferedImageDecoder.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,15 +41,15 @@ typedef NS_ENUM(NSInteger, CCDecodingStatus){
*
* @return An initialized decoder instance.
*/
-(instancetype _Nullable)initWithData:(NSData* _Nullable)data;
-(instancetype)initWithData:(NSData*)data;

/**
* Convert the result RGB data to an image instance.
*
* @return An image instance for use in Cocoa.
*/
#if TARGET_OS_IPHONE
-(UIImage* _Nullable)toImage;
-(UIImage*)toImage;
#else
-(NSImage*)toImage;
#endif
Expand Down
49 changes: 26 additions & 23 deletions Code/CCBufferedImageView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@
import UIKit

/// A subclass of UIImageView which displays a JPEG progressively while it is downloaded
open class CCBufferedImageView : UIImageView, NSURLConnectionDataDelegate {
fileprivate weak var connection: NSURLConnection?
fileprivate let defaultContentLength = 5 * 1024 * 1024
fileprivate var data: Data?
fileprivate let queue = DispatchQueue(label: "com.contentful.Concorde", attributes: [])
public class CCBufferedImageView : UIImageView, NSURLConnectionDataDelegate {
private weak var connection: NSURLConnection?
private let defaultContentLength = 5 * 1024 * 1024
private var data: NSMutableData?
private let queue = DispatchQueue(label: "com.contentful.Concorde")

/// Optional handler which is called after an image has been successfully downloaded
open var loadedHandler: (() -> ())?
public var loadedHandler: (() -> ())?

deinit {
connection?.cancel()
Expand All @@ -30,48 +30,51 @@ open class CCBufferedImageView : UIImageView, NSURLConnectionDataDelegate {
}

/// Initialize a new image view and start loading a JPEG from the given URL
public init(URL: Foundation.URL) {
public init(URL: URL) {
super.init(image: nil)

backgroundColor = UIColor.gray
load(URL)
backgroundColor = .gray
load(URL: URL)
}

/// Required initializer, not implemented
required public init?(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)

backgroundColor = UIColor.gray
backgroundColor = .gray
}

/// Load a JPEG from the given URL
open func load(_ URL: Foundation.URL) {
public func load(URL: URL) {
connection?.cancel()
connection = NSURLConnection(request: URLRequest(url: URL), delegate: self)
connection = NSURLConnection(request: NSURLRequest(url: URL as URL) as URLRequest, delegate: self)
}

// MARK: NSURLConnectionDataDelegate

/// see NSURLConnectionDataDelegate
open func connection(_ connection: NSURLConnection, didFailWithError error: Error) {
NSLog("Error: \(error)")
public func connection(connection: NSURLConnection, didFailWithError error: NSError) {
NSLog("Error: %@", error)
}

/// see NSURLConnectionDataDelegate
open func connection(_ connection: NSURLConnection, didReceive data: Data) {
self.data?.append(data)
public func connection(connection: NSURLConnection, didReceiveData data: NSData) {
self.data?.append(data as Data)

queue.sync {
let decoder = CCBufferedImageDecoder(data: self.data! as Data)
queue.sync() {
let decoder = CCBufferedImageDecoder(data: self.data as Data?)
decoder?.decompress()

guard let decodedImage = decoder?.toImage() else {
return
}

UIGraphicsBeginImageContext(CGSize(width: 1,height: 1))
UIGraphicsBeginImageContext(CGSize(width: 1, height: 1))
let context = UIGraphicsGetCurrentContext()
context?.draw(decodedImage.cgImage!, in: CGRect(x: 0, y: 0, width: 1, height: 1))

context?.draw(decodedImage.cgImage!,
in: CGRect(x: 0, y: 0, width: 1, height: 1))

UIGraphicsEndImageContext()

DispatchQueue.main.async {
Expand All @@ -81,17 +84,17 @@ open class CCBufferedImageView : UIImageView, NSURLConnectionDataDelegate {
}

/// see NSURLConnectionDataDelegate
open func connection(_ connection: NSURLConnection, didReceive response: URLResponse) {
public func connection(connection: NSURLConnection, didReceiveResponse response: URLResponse) {
var contentLength = Int(response.expectedContentLength)
if contentLength < 0 {
contentLength = defaultContentLength
}

data = Data(capacity: contentLength)
data = NSMutableData(capacity: contentLength)
}

/// see NSURLConnectionDataDelegate
open func connectionDidFinishLoading(_ connection: NSURLConnection) {
public func connectionDidFinishLoading(connection: NSURLConnection) {
data = nil

if let loadedHandler = loadedHandler {
Expand Down
Binary file removed vendor/libjpeg-turbo/lib/libturbojpeg.a
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -1,18 +1,26 @@
/* jconfig.h. Generated from jconfig.h.in by configure. */
/* Version ID for the JPEG library.
* Might be useful for tests like "#if JPEG_LIB_VERSION >= 60".
*/
#define JPEG_LIB_VERSION 62
#define JPEG_LIB_VERSION 62

/* libjpeg-turbo version */
#define LIBJPEG_TURBO_VERSION 1.4.0
#define LIBJPEG_TURBO_VERSION 2.1.2

/* libjpeg-turbo version in integer form */
#define LIBJPEG_TURBO_VERSION_NUMBER 2001002

/* Support arithmetic encoding */
#define C_ARITH_CODING_SUPPORTED 1

/* Support arithmetic decoding */
#define D_ARITH_CODING_SUPPORTED 1

/* Support in-memory source/destination managers */
#define MEM_SRCDST_SUPPORTED 1

/* Use accelerated SIMD routines. */
#define WITH_SIMD 1

/*
* Define BITS_IN_JSAMPLE as either
* 8 for 8-bit sample values (the usual setting)
Expand All @@ -33,6 +41,13 @@
/* Define to 1 if you have the <stdlib.h> header file. */
#define HAVE_STDLIB_H 1

/* Define if you need to include <sys/types.h> to get size_t. */
#define NEED_SYS_TYPES_H 1

/* Define if you have BSD-like bzero and bcopy in <strings.h> rather than
memset/memcpy in <string.h>. */
/* #undef NEED_BSD_STRINGS */

/* Define to 1 if the system has the type `unsigned char'. */
#define HAVE_UNSIGNED_CHAR 1

Expand All @@ -42,28 +57,10 @@
/* Compiler does not support pointers to undefined structures. */
/* #undef INCOMPLETE_TYPES_BROKEN */

/* Support in-memory source/destination managers */
#define MEM_SRCDST_SUPPORTED 1

/* Define if you have BSD-like bzero and bcopy in <strings.h> rather than
memset/memcpy in <string.h>. */
/* #undef NEED_BSD_STRINGS */

/* Define if you need to include <sys/types.h> to get size_t. */
#define NEED_SYS_TYPES_H 1

/* Define if your (broken) compiler shifts signed values as if they were
unsigned. */
/* #undef RIGHT_SHIFT_IS_UNSIGNED */

/* Use accelerated SIMD routines. */
#define WITH_SIMD 1

/* Define to 1 if type `char' is unsigned and you are not using gcc. */
#ifndef __CHAR_UNSIGNED__
/* # undef __CHAR_UNSIGNED__ */
#endif

/* Define to empty if `const' does not conform to ANSI C. */
/* #undef const */

Expand Down
Loading