Skip to content

Commit f7e9ef5

Browse files
author
Michael Shannon Potter
committed
Update README
- Add documentation for image format styles - Add documentation for image retrieval cancellation
1 parent 4c7560f commit f7e9ef5

File tree

1 file changed

+32
-3
lines changed

1 file changed

+32
-3
lines changed

README.md

Lines changed: 32 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ A significant burden on performance for graphics-rich applications like [Path](h
1818
- [Initial Configuration](#initial-configuration)
1919
- [Requesting Images from the Image Cache](#requesting-images-from-the-image-cache)
2020
- [Providing Source Images to the Image Cache](#providing-source-images-to-the-image-cache)
21+
- [Cancelling Source Image Requests](#cancelling-source-image-requests)
2122
- [Working with Image Format Families](#working-with-image-format-families)
2223
- [Documentation](#documentation)
2324
- [Demo Application](#demo-application)
@@ -167,22 +168,31 @@ Each image format corresponds to an image table that the image cache will use. I
167168
FICImageFormat *smallUserThumbnailImageFormat = [[FICImageFormat alloc] init];
168169
smallUserThumbnailImageFormat.name = XXImageFormatNameUserThumbnailSmall;
169170
smallUserThumbnailImageFormat.family = XXImageFormatFamilyUserThumbnails;
171+
smallUserThumbnailImageFormat.style = FICImageFormatStyle16BitBGR;
170172
smallUserThumbnailImageFormat.imageSize = CGSizeMake(50, 50);
171-
smallUserThumbnailImageFormat.opaque = YES;
172173
smallUserThumbnailImageFormat.maximumCount = 250;
173174
smallUserThumbnailImageFormat.devices = FICImageFormatDevicePhone;
174175

175176
FICImageFormat *mediumUserThumbnailImageFormat = [[FICImageFormat alloc] init];
176177
mediumUserThumbnailImageFormat.name = XXImageFormatNameUserThumbnailMedium;
177178
mediumUserThumbnailImageFormat.family = XXImageFormatFamilyUserThumbnails;
179+
mediumUserThumbnailImageFormat.style = FICImageFormatStyle32BitBGRA;
178180
mediumUserThumbnailImageFormat.imageSize = CGSizeMake(100, 100);
179-
mediumUserThumbnailImageFormat.opaque = YES;
180181
mediumUserThumbnailImageFormat.maximumCount = 250;
181182
mediumUserThumbnailImageFormat.devices = FICImageFormatDevicePhone;
182183

183184
NSArray *imageFormats = @[smallUserThumbnailImageFormat, mediumUserThumbnailImageFormat];
184185
```
185186

187+
An image format's style effectively determines the bit depth of the images stored in an image table. The following styles are currently available:
188+
189+
- 32-bit color plus an alpha component (default)
190+
- 32-bit color, no alpha component
191+
- 16-bit color, no alpha component
192+
- 8-bit grayscale, no alpha component
193+
194+
If the source images lack transparency (e.g., JPEG images), then better Core Animation performance can be achieved by using 32-bit color with no alpha component. If the source images have little color detail, or if the image format's image size is relatively small, it may be sufficient to use 16-bit color with little or no perceptible loss of quality. This results in smaller image table files stored on disk.
195+
186196
#### Configuring the Image Cache
187197

188198
Once one or more image formats have been defined, they need to be assigned to the image cache. Aside from assigning the image cache's delegate, there is nothing further that can be configured on the image cache itself.
@@ -332,7 +342,26 @@ There are two ways to provide source images to the image cache.
332342
```
333343
334344
> **Note**: Fast Image Cache does **not** persist source images. See [Source Image Persistence](#source-image-persistence) for more information.
335-
345+
346+
### Cancelling Source Image Requests
347+
348+
If an image request is already in progress, it can be cancelled:
349+
350+
```objective-c
351+
// We scrolled up far enough that the image we requested in no longer visible; cancel the request
352+
XXUser *user = [self _currentUser];
353+
NSString *formatName = XXImageFormatNameUserThumbnailSmall;
354+
[sharedImageCache cancelImageRetrievalForEntity:user withFormatName:formatName];
355+
```
356+
357+
When this happens, Fast Image Cache cleans up its internal bookkeeping, and any completion blocks from the corresponding image request will do nothing at this point. However, the image cache's delegate is still responsible for ensuring that any outstanding source image requests (e.g., network requests) are cancelled:
358+
359+
```objective-c
360+
- (void)imageCache:(FICImageCache *)imageCache cancelImageLoadingForEntity:(id <FICEntity>)entity withFormatName:(NSString *)formatName {
361+
[self _cancelNetworkRequestForSourceImageForEntity:entity withFormatName:formatName];
362+
}
363+
```
364+
336365
### Working with Image Format Families
337366

338367
The advantage of classifying image formats into families is that the image cache's delegate can tell the image cache to process entity source images for **all** image formats in a family when **any** image format in that family is processed.

0 commit comments

Comments
 (0)