-
Notifications
You must be signed in to change notification settings - Fork 18
/
WebPImage.h
105 lines (82 loc) · 3.19 KB
/
WebPImage.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
//
// WebPImage.h
// ImageButter
//
// Created by Dalton Cherry on 8/27/15.
//
#import <Foundation/Foundation.h>
#import <CoreGraphics/CoreGraphics.h>
#import <UIKit/UIKit.h>
/**
This is used be WebPImageView for drawing and can be ignored in all most all cases.
*/
@interface WebPFrame : NSObject
- (instancetype)initWithFrame:(CGRect)frame image:(UIImage*)image dispose:(BOOL)dispose blend:(BOOL)blend duration:(NSInteger)duration;
//the frame of this image
@property(nonatomic, readonly)CGRect frame;
//should the we canvas be cleared before drawing this image?
//dispose == YES don't draw anything but this image. NO means to draw the previous frames.
@property(nonatomic, readonly)BOOL dispose;
//should only the last drawing rect have transparent pixels or solid background?
//Blend == YES means it should be transparent and NO means the background color.
@property(nonatomic, readonly)BOOL blend;
//how long should this image frame be display (in milliseconds)?
@property(nonatomic, readonly)NSInteger displayDuration;
//the image object to display for this frame
@property(nonatomic, readonly)UIImage *image;
@end
/**
Like a UIImage/NSImage but for WebP. Since the biggest weakness of WebP is the slow decoding times, they can be done async to not block the main thread while decoding images (especially animated ones).
*/
@interface WebPImage : NSObject
typedef void (^WebPDecodeFinished)(WebPImage*);
typedef void (^WebPDecodeProgress)(CGFloat);
/**
Create a new WebPImage object with the data. This is done on the *main* thread and not recommend to be used in almost all cases.
@param data is the webp data to decode.
*/
- (instancetype)initWithData:(NSData*)data;
/**
Create a new WebPImage object with the a UIImage. This is hack so you can use a UIImage in a WebPImageView.
@param image to "convert" to webp.
*/
- (instancetype)initWithImage:(UIImage*)img;
/**
Create a new WebPImage object with data. The decoding is done on a background thread with this decode.
@param data is the webp data to decode.
@param async is triggered once the image is done decoding. nil can be passed.
*/
- (instancetype)initWithData:(NSData*)data async:(WebPDecodeFinished)finished;
/**
the size of the image. This also accounts for scale on the device so the image isn't grainy.
*/
@property(nonatomic, readonly)CGSize size;
/**
the frames of image. This can be either one WPFrame or multiple if it is animated
*/
@property(nonatomic,readonly)NSArray *frames;
/**
the background color of the image.
*/
@property(nonatomic, readonly)UIColor *backgroundColor;
/**
Reports if the image is done decoding or not.
*/
@property(nonatomic,readonly)BOOL isDecoded;
/**
get the progress of the decode
*/
@property(nonatomic, strong)WebPDecodeProgress decodeProgress;
/**
this is a property is to be ignored. It is exposed so the WebPImageView can be notified when an async image is ready
*/
@property(nonatomic,strong)WebPDecodeFinished finishedDecode;
/**
this is a property can be ignored most of the time. It is exposed so the WebPImageView can use it as drawing optimzation for animated gifs
*/
@property(nonatomic, readonly)BOOL hasAlpha;
/**
Returns true if it is a valid image type.
*/
+ (BOOL)isValidImage:(NSData*)data;
@end