Revision: 14323
          http://sourceforge.net/p/skim-app/code/14323
Author:   hofman
Date:     2024-06-11 09:22:34 +0000 (Tue, 11 Jun 2024)
Log Message:
-----------
separate methods to draw bitmap image reps for thumbnails so we don't need 
images fo TIFF representation

Modified Paths:
--------------
    trunk/PDFPage_SKExtensions.m
    trunk/SKSnapshotConfiguration.h
    trunk/SKSnapshotConfiguration.m
    trunk/SKSnapshotWindowController.m

Modified: trunk/PDFPage_SKExtensions.m
===================================================================
--- trunk/PDFPage_SKExtensions.m        2024-06-10 22:40:58 UTC (rev 14322)
+++ trunk/PDFPage_SKExtensions.m        2024-06-11 09:22:34 UTC (rev 14323)
@@ -148,7 +148,7 @@
     return NSIntersectionRect(NSInsetRect([self foregroundRect], -2.0, -2.0), 
[self boundsForBox:kPDFDisplayBoxCropBox]);
 }
 
-- (NSImage *)thumbnailWithSize:(CGFloat)aSize scale:(CGFloat)backingScale 
forBox:(PDFDisplayBox)box hasShadow:(BOOL)hasShadow highlights:(NSArray 
*)highlights {
+- (NSBitmapImageRep *)bitmapImageRepWithSize:(CGFloat)aSize 
scale:(CGFloat)backingScale forBox:(PDFDisplayBox)box hasShadow:(BOOL)hasShadow 
highlights:(NSArray *)highlights {
     NSSize pageSize = [self boundsForBox:box].size;
     CGFloat scale = 1.0;
     NSSize thumbnailSize;
@@ -155,7 +155,7 @@
     CGFloat shadowBlurRadius = 0.0;
     CGFloat shadowOffset = 0.0;
     NSRect pageRect = NSZeroRect;
-    NSImage *image;
+    NSBitmapImageRep *imageRep;
     
     if (hasShadow) {
         shadowBlurRadius = round(backingScale * aSize / 32.0) / backingScale;
@@ -181,7 +181,7 @@
         pageRect.origin.y -= shadowOffset;
     }
     
-    image = [NSImage bitmapImageWithSize:thumbnailSize scale:backingScale 
drawingHandler:^(NSRect dstRect){
+    imageRep = [NSBitmapImageRep imageRepWithSize:thumbnailSize 
scale:backingScale drawingHandler:^(NSRect dstRect){
         
         [[NSGraphicsContext currentContext] 
setImageInterpolation:[[NSUserDefaults standardUserDefaults] 
integerForKey:SKInterpolationQualityKey] + 1];
         
@@ -212,12 +212,19 @@
         
     }];
     
+    return imageRep;
+}
+
+- (NSImage *)thumbnailWithSize:(CGFloat)aSize scale:(CGFloat)backingScale 
forBox:(PDFDisplayBox)box hasShadow:(BOOL)hasShadow highlights:(NSArray 
*)highlights {
+    NSBitmapImageRep *imageRep;
+    NSImage *image = [[NSImage alloc] initWithSize:[imageRep size]];
+    [image addRepresentation:imageRep];
     return image;
 }
 
 - (NSAttributedString *)thumbnailAttachmentWithSize:(CGFloat)aSize {
-    NSBitmapImageRep *imageRep1 = (NSBitmapImageRep *)[[[self 
thumbnailWithSize:aSize scale:2.0 forBox:kPDFDisplayBoxCropBox hasShadow:YES 
highlights:nil] representations] firstObject];
-    NSBitmapImageRep *imageRep2 = (NSBitmapImageRep *)[[[self 
thumbnailWithSize:aSize scale:1.0 forBox:kPDFDisplayBoxCropBox hasShadow:YES 
highlights:nil] representations] firstObject];
+    NSBitmapImageRep *imageRep1 = [self bitmapImageRepWithSize:aSize scale:2.0 
forBox:kPDFDisplayBoxCropBox hasShadow:YES highlights:nil];
+    NSBitmapImageRep *imageRep2 = [self bitmapImageRepWithSize:aSize scale:1.0 
forBox:kPDFDisplayBoxCropBox hasShadow:YES highlights:nil];
     NSData *data = [NSBitmapImageRep 
TIFFRepresentationOfImageRepsInArray:@[imageRep1, imageRep2]];
     NSFileWrapper *wrapper = [[NSFileWrapper alloc] 
initRegularFileWithContents:data];
     NSString *filename = [NSString stringWithFormat:@"page_%lu.tiff", 
(unsigned long)([self pageIndex] + 1)];
@@ -266,8 +273,8 @@
         return nil;
     
     PDFDisplayBox box = NSEqualRects(rect, [self 
boundsForBox:kPDFDisplayBoxCropBox]) ? kPDFDisplayBoxCropBox : 
kPDFDisplayBoxMediaBox;
-    NSBitmapImageRep *imageRep1 = (NSBitmapImageRep *)[[[self 
thumbnailWithSize:0.0 scale:2.0 forBox:kPDFDisplayBoxCropBox hasShadow:NO 
highlights:nil] representations] firstObject];
-    NSBitmapImageRep *imageRep2 = (NSBitmapImageRep *)[[[self 
thumbnailWithSize:0.0 scale:1.0 forBox:kPDFDisplayBoxCropBox hasShadow:NO 
highlights:nil] representations] firstObject];
+    NSBitmapImageRep *imageRep1 = [self bitmapImageRepWithSize:0.0 scale:2.0 
forBox:kPDFDisplayBoxCropBox hasShadow:NO highlights:nil];
+    NSBitmapImageRep *imageRep2 = [self bitmapImageRepWithSize:0.0 scale:1.0 
forBox:kPDFDisplayBoxCropBox hasShadow:NO highlights:nil];
     
     NSRect bounds = [self boundsForBox:box];
     

Modified: trunk/SKSnapshotConfiguration.h
===================================================================
--- trunk/SKSnapshotConfiguration.h     2024-06-10 22:40:58 UTC (rev 14322)
+++ trunk/SKSnapshotConfiguration.h     2024-06-11 09:22:34 UTC (rev 14323)
@@ -52,6 +52,7 @@
 - (instancetype)initWithPDFView:(PDFView *)pdfView;
 
 - (NSImage *)thumbnailWithSize:(CGFloat)aSize scale:(CGFloat)scale;
+- (NSBitmapImageRep *)bitmapImageRepWithSize:(CGFloat)aSize 
scale:(CGFloat)scale;
 
 @end
 

Modified: trunk/SKSnapshotConfiguration.m
===================================================================
--- trunk/SKSnapshotConfiguration.m     2024-06-10 22:40:58 UTC (rev 14322)
+++ trunk/SKSnapshotConfiguration.m     2024-06-11 09:22:34 UTC (rev 14323)
@@ -38,6 +38,7 @@
 
 #import "SKSnapshotConfiguration.h"
 #import "NSImage_SKExtensions.h"
+#import "NSBitmapImageRep_SKExtensions.h"
 #import "NSShadow_SKExtensions.h"
 #import "NSGeometry_SKExtensions.h"
 #import "PDFView_SKExtensions.h"
@@ -64,13 +65,13 @@
     return self;
 }
 
-- (NSImage *)thumbnailWithSize:(CGFloat)aSize scale:(CGFloat)scale {
+- (NSBitmapImageRep *)bitmapImageRepWithSize:(CGFloat)aSize 
scale:(CGFloat)scale {
     NSRect bounds = (NSRect){NSZeroPoint, size};
     NSAffineTransform *transform = [NSAffineTransform transform];
     NSSize thumbnailSize = bounds.size;
     CGFloat shadowBlurRadius = 0.0;
     CGFloat shadowOffset = 0.0;
-    NSImage *image;
+    NSBitmapImageRep *imageRep;
     
     if (aSize > 0.0) {
         shadowBlurRadius = round(scale * aSize / 32.0) / scale;
@@ -86,7 +87,7 @@
     if (NSEqualPoints(bounds.origin, NSZeroPoint) == NO)
         [transform translateXBy:-NSMinX(bounds) yBy:-NSMinY(bounds)];
     
-    image = [NSImage bitmapImageWithSize:thumbnailSize scale:scale 
drawingHandler:^(NSRect dstRect){
+    imageRep = [NSBitmapImageRep imageRepWithSize:thumbnailSize scale:scale 
drawingHandler:^(NSRect dstRect){
         
         [[NSGraphicsContext currentContext] 
setImageInterpolation:NSImageInterpolationHigh];
         [transform concat];
@@ -113,6 +114,13 @@
         
     }];
     
+    return imageRep;
+}
+
+- (NSImage *)thumbnailWithSize:(CGFloat)aSize scale:(CGFloat)scale {
+    NSBitmapImageRep *imageRep = [self bitmapImageRepWithSize:aSize 
scale:scale];
+    NSImage *image = [[NSImage alloc] initWithSize:[imageRep size]];
+    [image addRepresentation:imageRep];
     return image;
 }
 

Modified: trunk/SKSnapshotWindowController.m
===================================================================
--- trunk/SKSnapshotWindowController.m  2024-06-10 22:40:58 UTC (rev 14322)
+++ trunk/SKSnapshotWindowController.m  2024-06-11 09:22:34 UTC (rev 14323)
@@ -485,8 +485,8 @@
 
 - (NSAttributedString *)thumbnailAttachmentWithSize:(CGFloat)size {
     SKSnapshotConfiguration *configuration = [self currentConfiguration];
-    NSBitmapImageRep *imageRep1 = (NSBitmapImageRep *)[[[configuration 
thumbnailWithSize:size scale:1.0] representations] firstObject];
-    NSBitmapImageRep *imageRep2 = (NSBitmapImageRep *)[[[configuration 
thumbnailWithSize:size scale:2.0] representations] firstObject];
+    NSBitmapImageRep *imageRep1 = [configuration bitmapImageRepWithSize:size 
scale:1.0];
+    NSBitmapImageRep *imageRep2 = [configuration bitmapImageRepWithSize:size 
scale:2.0];
     NSData *data = [NSBitmapImageRep 
TIFFRepresentationOfImageRepsInArray:@[imageRep1, imageRep2]];
     
     NSFileWrapper *wrapper = [[NSFileWrapper alloc] 
initRegularFileWithContents:data];
@@ -712,8 +712,8 @@
 
 - (void)filePromiseProvider:(NSFilePromiseProvider *)filePromiseProvider 
writePromiseToURL:(NSURL *)fileURL completionHandler:(void (^)(NSError 
*))completionHandler {
     SKSnapshotConfiguration *configuration = [self currentConfiguration];
-    NSBitmapImageRep *imageRep1 = (NSBitmapImageRep *)[[[configuration 
thumbnailWithSize:0.0 scale:1.0] representations] firstObject];
-    NSBitmapImageRep *imageRep2 = (NSBitmapImageRep *)[[[configuration 
thumbnailWithSize:0.0 scale:2.0] representations] firstObject];
+    NSBitmapImageRep *imageRep1 = [configuration bitmapImageRepWithSize:0.0 
scale:1.0];
+    NSBitmapImageRep *imageRep2 = [configuration bitmapImageRepWithSize:0.0 
scale:2.0];
     NSData *data = [NSBitmapImageRep 
TIFFRepresentationOfImageRepsInArray:@[imageRep1, imageRep2]];
     NSError *error = nil;
     [data writeToURL:fileURL options:NSDataWritingAtomic error:&error];

This was sent by the SourceForge.net collaborative development platform, the 
world's largest Open Source development site.



_______________________________________________
Skim-app-commit mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/skim-app-commit

Reply via email to