diff options
author | Paul Gardiner <paul.gardiner@artifex.com> | 2013-10-14 11:22:41 +0100 |
---|---|---|
committer | Paul Gardiner <paul.gardiner@artifex.com> | 2013-10-16 09:59:35 +0100 |
commit | f9456a8ea13a63989b9c948fa93f474db3ca59b5 (patch) | |
tree | 820888aca59cda1145bcd7a3dd04a48d3684e257 /platform/ios/Classes | |
parent | a0029d70729f0cad0515b7e9fcb55a7527d199a1 (diff) | |
download | mupdf-f9456a8ea13a63989b9c948fa93f474db3ca59b5.tar.xz |
iOS: keep reference to the fz_pixmaps.
Diffstat (limited to 'platform/ios/Classes')
-rw-r--r-- | platform/ios/Classes/MuPageViewNormal.h | 4 | ||||
-rw-r--r-- | platform/ios/Classes/MuPageViewNormal.m | 31 |
2 files changed, 27 insertions, 8 deletions
diff --git a/platform/ios/Classes/MuPageViewNormal.h b/platform/ios/Classes/MuPageViewNormal.h index 9bbe459c..cc4a8e1d 100644 --- a/platform/ios/Classes/MuPageViewNormal.h +++ b/platform/ios/Classes/MuPageViewNormal.h @@ -27,7 +27,11 @@ fz_display_list *annot_list; int number; UIActivityIndicatorView *loadingView; + fz_pixmap *image_pix; + CGDataProviderRef imageData; UIImageView *imageView; + fz_pixmap *tile_pix; + CGDataProviderRef tileData; UIImageView *tileView; MuHitView *hitView; MuHitView *linkView; diff --git a/platform/ios/Classes/MuPageViewNormal.m b/platform/ios/Classes/MuPageViewNormal.m index 6f08424c..49df6c38 100644 --- a/platform/ios/Classes/MuPageViewNormal.m +++ b/platform/ios/Classes/MuPageViewNormal.m @@ -19,12 +19,18 @@ static void releasePixmap(void *info, const void *data, size_t size) fz_drop_pixmap(ctx, info); } -static UIImage *newImageWithPixmap(fz_pixmap *pix) +static CGDataProviderRef wrapPixmap(fz_pixmap *pix) { unsigned char *samples = fz_pixmap_samples(ctx, pix); int w = fz_pixmap_width(ctx, pix); int h = fz_pixmap_height(ctx, pix); - CGDataProviderRef cgdata = CGDataProviderCreateWithData(pix, samples, w * 4 * h, releasePixmap); + return CGDataProviderCreateWithData(pix, samples, w * 4 * h, releasePixmap); +} + +static UIImage *newImageWithPixmap(fz_pixmap *pix, CGDataProviderRef cgdata) +{ + int w = fz_pixmap_width(ctx, pix); + int h = fz_pixmap_height(ctx, pix); CGColorSpaceRef cgcolor = CGColorSpaceCreateDeviceRGB(); CGImageRef cgimage = CGImageCreate(w, h, 8, 32, 4 * w, cgcolor, kCGBitmapByteOrderDefault, @@ -33,7 +39,6 @@ static UIImage *newImageWithPixmap(fz_pixmap *pix) initWithCGImage: cgimage scale: screenScale orientation: UIImageOrientationUp]; - CGDataProviderRelease(cgdata); CGColorSpaceRelease(cgcolor); CGImageRelease(cgimage); return image; @@ -142,7 +147,7 @@ static fz_display_list *create_annot_list(fz_document *doc, fz_page *page) return list; } -static UIImage *renderPage(fz_document *doc, fz_display_list *page_list, fz_display_list *annot_list, CGSize pageSize, CGSize screenSize, CGRect tileRect, float zoom) +static fz_pixmap *renderPage(fz_document *doc, fz_display_list *page_list, fz_display_list *annot_list, CGSize pageSize, CGSize screenSize, CGRect tileRect, float zoom) { fz_irect bbox; fz_rect rect; @@ -185,10 +190,10 @@ static UIImage *renderPage(fz_document *doc, fz_display_list *page_list, fz_disp fz_catch(ctx) { fz_drop_pixmap(ctx, pix); - return nil; + return NULL; } - return newImageWithPixmap(pix); + return pix; } #import "MuPageViewNormal.h" @@ -271,6 +276,8 @@ static UIImage *renderPage(fz_document *doc, fz_display_list *page_list, fz_disp __block fz_display_list *block_annot_list = annot_list; __block fz_page *block_page = page; __block fz_document *block_doc = docRef->doc; + __block CGDataProviderRef block_tileData = tileData; + __block CGDataProviderRef block_imageData = imageData; dispatch_async(queue, ^{ if (block_page_list) fz_drop_display_list(ctx, block_page_list); @@ -279,6 +286,8 @@ static UIImage *renderPage(fz_document *doc, fz_display_list *page_list, fz_disp if (block_page) fz_free_page(block_doc, block_page); block_page = nil; + CGDataProviderRelease(block_tileData); + CGDataProviderRelease(block_imageData); }); [docRef release]; [widgetRects release]; @@ -380,7 +389,10 @@ static UIImage *renderPage(fz_document *doc, fz_display_list *page_list, fz_disp [self ensureDisplaylists]; CGSize scale = fitPageToScreen(pageSize, self.bounds.size); CGRect rect = (CGRect){{0.0, 0.0},{pageSize.width * scale.width, pageSize.height * scale.height}}; - UIImage *image = renderPage(doc, page_list, annot_list, pageSize, self.bounds.size, rect, 1.0); + image_pix = renderPage(doc, page_list, annot_list, pageSize, self.bounds.size, rect, 1.0); + CGDataProviderRelease(imageData); + imageData = wrapPixmap(image_pix); + UIImage *image = newImageWithPixmap(image_pix, imageData); widgetRects = enumerateWidgetRects(doc, page, pageSize, self.bounds.size); dispatch_async(dispatch_get_main_queue(), ^{ [self displayImage: image]; @@ -528,7 +540,10 @@ static UIImage *renderPage(fz_document *doc, fz_display_list *page_list, fz_disp [self ensureDisplaylists]; printf("render tile\n"); - UIImage *image = renderPage(doc, page_list, annot_list, pageSize, screenSize, viewFrame, scale); + tile_pix = renderPage(doc, page_list, annot_list, pageSize, screenSize, viewFrame, scale); + CGDataProviderRelease(tileData); + tileData = wrapPixmap(tile_pix); + UIImage *image = newImageWithPixmap(tile_pix, tileData); dispatch_async(dispatch_get_main_queue(), ^{ isValid = CGRectEqualToRect(frame, tileFrame) && scale == tileScale; |