Skip to content
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
2 changes: 2 additions & 0 deletions Source/JTSAnimatedGIFUtility.h
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@

+ (BOOL)imageURLIsAGIF:(NSString *)imageURL;

+ (BOOL)imageDataIsAGIF:(NSData *)imageData;

/*
UIImage *animation = [UIImage animatedImageWithAnimatedGIFData:theData];

Expand Down
46 changes: 31 additions & 15 deletions Source/JTSAnimatedGIFUtility.m
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,33 @@ + (BOOL)imageURLIsAGIF:(NSString *)imageURL {
return [[imageURL substringFromIndex:[imageURL length] - 3] isEqualToString:@"gif"];
}

static NSString * contentTypeForImageData(NSData * data) {
uint8_t c;
[data getBytes:&c length:1];

switch (c) {
case 0xFF:
return @"image/jpeg";
case 0x89:
return @"image/png";
case 0x47:
return @"image/gif";
case 0x49:
case 0x4D:
return @"image/tiff";
}
return nil;
}

+ (BOOL)imageDataIsAGIF:(NSData *)imageData {
NSString *imageType = contentTypeForImageData(imageData);
if ([imageType isEqualToString:@"image/gif"]) {
return YES;
} else {
return NO;
}
}

static int delayCentisecondsForImageAtIndex(CGImageSourceRef const source, size_t const i) {
int delayCentiseconds = 1;
CFDictionaryRef const properties = CGImageSourceCopyPropertiesAtIndex(source, i, NULL);
Expand Down Expand Up @@ -104,21 +131,10 @@ static void releaseImages(size_t const count, CGImageRef const images[count]) {
int delayCentiseconds[count]; // in centiseconds
createImagesAndDelays(source, count, images, delayCentiseconds);
int const totalDurationCentiseconds = sum(count, delayCentiseconds);
UIImage *image = nil;
if (totalDurationCentiseconds == 0 || count == 1) {
// This can't be animated, so don't bother trying to create an animated image.
CGImageRef imageRef = CGImageSourceCreateImageAtIndex(source, 0, NULL);
if (imageRef) {
image = [UIImage imageWithCGImage:imageRef];
CGImageRelease(imageRef);
}
} else {
NSArray *const frames = frameArray(count, images, delayCentiseconds, totalDurationCentiseconds);
UIImage *const animation = [UIImage animatedImageWithImages:frames duration:(NSTimeInterval)totalDurationCentiseconds / 100.0];
releaseImages(count, images);
image = animation;
}
return image;
NSArray *const frames = frameArray(count, images, delayCentiseconds, totalDurationCentiseconds);
UIImage *const animation = [UIImage animatedImageWithImages:frames duration:(NSTimeInterval)totalDurationCentiseconds / 100.0];
releaseImages(count, images);
return animation;
}

static UIImage *animatedImageWithAnimatedGIFReleasingImageSource(CGImageSourceRef source CF_CONSUMED) {
Expand Down
19 changes: 14 additions & 5 deletions Source/JTSImageViewController.h
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

@import UIKit;

#import "JTSImageInfo.h"
#import "JTSMediaInfo.h"

///--------------------------------------------------------------------------------------------------------------------
/// Definitions
Expand Down Expand Up @@ -45,9 +45,9 @@ extern CGFloat const JTSImageViewController_DefaultBackgroundBlurRadius;

@interface JTSImageViewController : UIViewController

@property (strong, nonatomic, readonly) JTSImageInfo *imageInfo;
@property (strong, nonatomic, readonly) NSArray *imageInfoArray;//JTSMediaInfo *imageInfo;

@property (strong, nonatomic, readonly) UIImage *image;
@property (strong, nonatomic, readonly) NSMutableArray *imageArray;

@property (assign, nonatomic, readonly) JTSImageViewControllerMode mode;

Expand All @@ -73,10 +73,15 @@ extern CGFloat const JTSImageViewController_DefaultBackgroundBlurRadius;
@param backgroundStyle Currently, either scaled-and-dimmed, or scaled-dimmed-and-blurred.
The latter is like Tweetbot 3.0's background style.
*/
- (instancetype)initWithImageInfo:(JTSImageInfo *)imageInfo
- (instancetype)initWithImageInfo:(JTSMediaInfo *)imageInfo
mode:(JTSImageViewControllerMode)mode
backgroundStyle:(JTSImageViewControllerBackgroundOptions)backgroundOptions;

- (instancetype)initWIthImageInfoArray:(NSArray *)imageInfoArray
startingIndex:(int)startingIndex
mode:(JTSImageViewControllerMode)mode
backgroundStyle:(JTSImageViewControllerBackgroundOptions)backgroundOptions;

/**
JTSImageViewController is presented from viewController as a UIKit modal view controller.

Expand All @@ -86,13 +91,17 @@ extern CGFloat const JTSImageViewController_DefaultBackgroundBlurRadius;
Next, there is an animated transition to a full-screen image viewer.
*/
- (void)showFromViewController:(UIViewController *)viewController
transition:(JTSImageViewControllerTransition)transition;
transition:(JTSImageViewControllerTransition)transition
completion:(void (^)(void))completion;

/**
Dismisses the image viewer. Must not be called while previous presentation or dismissal is still in flight.
*/
- (void)dismiss:(BOOL)animated;

-(void)pauseVideoPlayback;
-(void)resumeVideoPlayback;

@end

///--------------------------------------------------------------------------------------------------------------------
Expand Down
Loading