Skip to content

Commit

Permalink
Merge branch 'master' into add_session_complete_delegate
Browse files Browse the repository at this point in the history
  • Loading branch information
ernestmama authored Nov 7, 2019
2 parents dbb8c98 + ebe69fb commit c946515
Show file tree
Hide file tree
Showing 7 changed files with 83 additions and 23 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@
- [fixed] Fixes blending in animated WebP images. [#507](https://github.com/pinterest/PINRemoteImage/pull/507) [garrettmoon](https://github.com/garrettmoon)
- [fixed] Fixes support in PINAnimatedImageView for WebP animated images. [#507](https://github.com/pinterest/PINRemoteImage/pull/507) [garrettmoon](https://github.com/garrettmoon)
- [new] Exposure didCompleteTask:withError: delegate method of protocol PINURLSessionManagerDelegate. [#519](https://github.com/pinterest/PINRemoteImage/pull/519) [zhongwuzw](https://github.com/zhongwuzw)
- [fixed] Fixes AnimatedImageView designated initializer not work. [#512](https://github.com/pinterest/PINRemoteImage/pull/512) [zhongwuzw](https://github.com/zhongwuzw)
- [fixed] Set bpp(bits per pixel) to 32 bit for GIF. [#511](https://github.com/pinterest/PINRemoteImage/pull/511) [zhongwuzw](https://github.com/zhongwuzw)
- [new] Add cancel method for PINRemoteImageManager. [#509](https://github.com/pinterest/PINRemoteImage/pull/509) [zhongwuzw](https://github.com/zhongwuzw)
- [fixed] Fixes build error when using Xcode 10.2.1. [#524](https://github.com/pinterest/PINRemoteImage/pull/524) [ANNotunzdY](https://github.com/ANNotunzdY)

## 3.0.0 Beta 14
- [fixed] Re-enable warnings check [#506](https://github.com/pinterest/PINRemoteImage/pull/506) [garrettmoon](https://github.com/garrettmoon)
Expand Down
2 changes: 1 addition & 1 deletion Examples/Example-Mac/Podfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
platform :macos, 10.9
platform :macos, 10.11

target 'PINRemoteImage' do
pod "PINRemoteImage/OSX", :path => "../../"
Expand Down
2 changes: 1 addition & 1 deletion PINRemoteImage.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ Pod::Spec.new do |s|
s.license = 'Apache 2.0'
s.author = { "Garrett Moon" => "[email protected]" }
s.source = { :git => "https://github.com/pinterest/PINRemoteImage.git", :tag => s.version.to_s }
s.social_media_url = 'https://twitter.com/garrettmoon'
# s.social_media_url = 'https://twitter.com/garrettmoon'

ios_deployment = "8.0"
tvos_deployment = "9.0"
Expand Down
47 changes: 28 additions & 19 deletions Source/Classes/AnimatedImages/PINAnimatedImageView.m
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,33 @@ - (void)commonInit:(PINCachedAnimatedImage *)animatedImage
{
_animatedImage = animatedImage;
_animatedImageRunLoopMode = NSRunLoopCommonModes;

if (animatedImage) {
[self initializeAnimatedImage:animatedImage];
}
}

- (void)initializeAnimatedImage:(nonnull PINCachedAnimatedImage *)animatedImage
{
PINWeakify(self);
animatedImage.coverImageReadyCallback = ^(PINImage *coverImage) {
dispatch_async(dispatch_get_main_queue(), ^{
PINStrongify(self);
// In this case the lock is already gone we have to call the unlocked version therefore
[self coverImageCompleted:coverImage];
});
};

animatedImage.playbackReadyCallback = ^{
dispatch_async(dispatch_get_main_queue(), ^{
// In this case the lock is already gone we have to call the unlocked version therefore
PINStrongify(self);
[self checkIfShouldAnimate];
});
};
if (animatedImage.playbackReady) {
[self checkIfShouldAnimate];
}
}

- (void)dealloc
Expand All @@ -84,25 +111,7 @@ - (void)setAnimatedImage:(PINCachedAnimatedImage *)animatedImage
_animatedImage = animatedImage;

if (animatedImage != nil) {
PINWeakify(self);
animatedImage.coverImageReadyCallback = ^(PINImage *coverImage) {
dispatch_async(dispatch_get_main_queue(), ^{
PINStrongify(self);
// In this case the lock is already gone we have to call the unlocked version therefore
[self coverImageCompleted:coverImage];
});
};

animatedImage.playbackReadyCallback = ^{
dispatch_async(dispatch_get_main_queue(), ^{
// In this case the lock is already gone we have to call the unlocked version therefore
PINStrongify(self);
[self checkIfShouldAnimate];
});
};
if (animatedImage.playbackReady) {
[self checkIfShouldAnimate];
}
[self initializeAnimatedImage:animatedImage];
} else {
// Clean up after ourselves.
self.layer.contents = nil;
Expand Down
2 changes: 1 addition & 1 deletion Source/Classes/AnimatedImages/PINGIFAnimatedImage.m
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ - (uint32_t)height

- (uint32_t)bytesPerFrame
{
return _width * _height * 3;
return _width * _height * 4;
}

- (NSError *)error
Expand Down
2 changes: 1 addition & 1 deletion Source/Classes/PINRemoteImageManager+Private.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

typedef void (^PINRemoteImageManagerDataCompletion)(NSData *data, NSURLResponse *response, NSError *error);

@interface PINRemoteImageManager (private)
@interface PINRemoteImageManager (PrivateExtension)

@property (nonatomic, strong, readonly) dispatch_queue_t callbackQueue;
@property (nonatomic, strong, readonly) PINOperationQueue *concurrentOperationQueue;
Expand Down
48 changes: 48 additions & 0 deletions Tests/PINAnimatedImageTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,55 @@ class PINAnimatedImageTests: XCTestCase, PINRemoteImageManagerAlternateRepresent
}
self.waitForExpectations(timeout: self.timeoutInterval(), handler: nil)
}

func testAnimatedImageViewInitializer() {
let animatedExpectation = self.expectation(description: "Animated image should be downloaded")
let imageManager = PINRemoteImageManager.init(sessionConfiguration: nil, alternativeRepresentationProvider: self)
imageManager.downloadImage(with: self.slowAnimatedGIFURL()!) { (result : PINRemoteImageManagerResult) in
XCTAssert(result.image == nil)
guard let animatedData = result.alternativeRepresentation as? NSData else {
XCTAssert(false, "alternativeRepresentation should be able to be coerced into data")
return
}

XCTAssert(animatedData.pin_isGIF() && animatedData.pin_isAnimatedGIF())

DispatchQueue.main.async {
let pinCachedAnimatedImage = PINCachedAnimatedImage(animatedImageData: animatedData as Data)

let gifImageView = PINAnimatedImageView(animatedImage: pinCachedAnimatedImage!)
XCTAssert(gifImageView.animatedImage?.coverImageReadyCallback != nil)

animatedExpectation.fulfill()
}
}

self.waitForExpectations(timeout: self.timeoutInterval(), handler: nil)
}

func testGIFBytes() {
let animatedExpectation = self.expectation(description: "Animated image should be downloaded")
let imageManager = PINRemoteImageManager.init(sessionConfiguration: nil, alternativeRepresentationProvider: self)
imageManager.downloadImage(with: self.slowAnimatedGIFURL()!) { (result : PINRemoteImageManagerResult) in
XCTAssert(result.image == nil)
guard let animatedData = result.alternativeRepresentation as? NSData else {
XCTAssert(false, "alternativeRepresentation should be able to be coerced into data")
return
}

XCTAssert(animatedData.pin_isGIF() && animatedData.pin_isAnimatedGIF())

let pinCachedAnimatedImage = PINGIFAnimatedImage(animatedImageData: animatedData as Data)!
let bytesSize = UInt32((pinCachedAnimatedImage.image(at: 0, cacheProvider: nil)!.takeUnretainedValue() as CGImage).bytesPerRow) * pinCachedAnimatedImage.height

XCTAssert(pinCachedAnimatedImage.bytesPerFrame == bytesSize)

animatedExpectation.fulfill()
}

self.waitForExpectations(timeout: self.timeoutInterval(), handler: nil)
}

func testInvalidAnimatedData() {
let data = "AA".data(using: .ascii)
let gifAnimatedImage = PINGIFAnimatedImage(animatedImageData: data)
Expand Down

0 comments on commit c946515

Please sign in to comment.