Revision: 14299
          http://sourceforge.net/p/skim-app/code/14299
Author:   hofman
Date:     2024-06-04 16:35:46 +0000 (Tue, 04 Jun 2024)
Log Message:
-----------
create TIFF representations of thumbnails and snapshots from low and high 
resolution bitmaps

Modified Paths:
--------------
    trunk/PDFPage_SKExtensions.m
    trunk/SKMainWindowController.m
    trunk/SKSnapshotWindowController.m

Modified: trunk/PDFPage_SKExtensions.m
===================================================================
--- trunk/PDFPage_SKExtensions.m        2024-06-04 15:47:39 UTC (rev 14298)
+++ trunk/PDFPage_SKExtensions.m        2024-06-04 16:35:46 UTC (rev 14299)
@@ -61,7 +61,6 @@
 #import "NSURL_SKExtensions.h"
 #import "NSString_SKExtensions.h"
 #import "SKLine.h"
-#import "NSScreen_SKExtensions.h"
 
 NSString *SKPDFPageBoundsDidChangeNotification = 
@"SKPDFPageBoundsDidChangeNotification";
 
@@ -219,9 +218,10 @@
 }
 
 - (NSAttributedString *)thumbnailAttachmentWithSize:(CGFloat)aSize {
-    NSImage *image = [self thumbnailWithSize:aSize scale:[NSScreen 
maxBackingScaleFactor] forBox:kPDFDisplayBoxCropBox hasShadow:YES 
highlights:nil];
-    
-    NSFileWrapper *wrapper = [[NSFileWrapper alloc] 
initRegularFileWithContents:[image TIFFRepresentation]];
+    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];
+    NSData *data = [NSBitmapImageRep 
TIFFRepresentationOfImageRepsInArray:@[imageRep2, imageRep1]];
+    NSFileWrapper *wrapper = [[NSFileWrapper alloc] 
initRegularFileWithContents:data];
     NSString *filename = [NSString stringWithFormat:@"page_%lu.tiff", 
(unsigned long)([self pageIndex] + 1)];
     [wrapper setFilename:filename];
     [wrapper setPreferredFilename:filename];
@@ -264,24 +264,28 @@
 }
 
 - (NSData *)TIFFDataForRect:(NSRect)rect {
-    PDFDisplayBox box = NSEqualRects(rect, [self 
boundsForBox:kPDFDisplayBoxCropBox]) ? kPDFDisplayBoxCropBox : 
kPDFDisplayBoxMediaBox;
-    NSImage *pageImage = [self thumbnailWithSize:0.0 scale:[NSScreen 
maxBackingScaleFactor] forBox:box hasShadow:NO highlights:nil];
-    NSRect bounds = [self boundsForBox:box];
-    
-    if (NSEqualRects(rect, NSZeroRect) || NSEqualRects(rect, bounds))
-        return [pageImage TIFFRepresentation];
     if (NSIsEmptyRect(rect))
         return nil;
     
-    NSAffineTransform *transform = [self affineTransformForBox:box];
-    NSRect sourceRect = SKTransformRect(transform, rect);
-    CGFloat scale = round([[[pageImage representations] firstObject] 
pixelsHigh] / [pageImage size].height);
+    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];
     
-    NSImage *image = [NSImage bitmapImageWithSize:sourceRect.size scale:scale 
drawingHandler:^(NSRect dstRect){
-        [pageImage drawInRect:dstRect fromRect:sourceRect 
operation:NSCompositingOperationCopy fraction:1.0];
-    }];
+    NSRect bounds = [self boundsForBox:box];
     
-    return [image TIFFRepresentation];
+    if (NSEqualRects(rect, NSZeroRect) == NO && NSEqualRects(rect, bounds) == 
NO) {
+        NSAffineTransform *transform = [self affineTransformForBox:box];
+        NSRect sourceRect = SKTransformRect(transform, rect);
+        
+        imageRep1 = [NSBitmapImageRep imageRepWithSize:sourceRect.size 
scale:1.0 drawingHandler:^(NSRect dstRect){
+            [imageRep1 drawInRect:dstRect fromRect:sourceRect 
operation:NSCompositingOperationCopy fraction:1.0 respectFlipped:YES hints:nil];
+        }];
+        imageRep2 = [NSBitmapImageRep imageRepWithSize:sourceRect.size 
scale:2.0 drawingHandler:^(NSRect dstRect){
+            [imageRep2 drawInRect:dstRect fromRect:sourceRect 
operation:NSCompositingOperationCopy fraction:1.0 respectFlipped:YES hints:nil];
+        }];
+    }
+    
+    return [NSBitmapImageRep TIFFRepresentationOfImageRepsInArray:@[imageRep2, 
imageRep1]];
 }
 
 - (NSData *)dataRepresentationForPageIndexes:(NSIndexSet *)pageIndexes {

Modified: trunk/SKMainWindowController.m
===================================================================
--- trunk/SKMainWindowController.m      2024-06-04 15:47:39 UTC (rev 14298)
+++ trunk/SKMainWindowController.m      2024-06-04 16:35:46 UTC (rev 14299)
@@ -93,7 +93,6 @@
 #import "SKColorCell.h"
 #import "PDFDocument_SKExtensions.h"
 #import "SKPDFPage.h"
-#import "NSScreen_SKExtensions.h"
 #import "PDFView_SKExtensions.h"
 #import "NSScanner_SKExtensions.h"
 #import "SKMainWindow.h"

Modified: trunk/SKSnapshotWindowController.m
===================================================================
--- trunk/SKSnapshotWindowController.m  2024-06-04 15:47:39 UTC (rev 14298)
+++ trunk/SKSnapshotWindowController.m  2024-06-04 16:35:46 UTC (rev 14299)
@@ -59,7 +59,6 @@
 #import "NSPasteboard_SKExtensions.h"
 #import "NSURL_SKExtensions.h"
 #import "NSWindow_SKExtensions.h"
-#import "NSScreen_SKExtensions.h"
 #import "SKApplication.h"
 #import "PDFDocument_SKExtensions.h"
 #import "NSString_SKExtensions.h"
@@ -66,7 +65,6 @@
 #import "NSScroller_SKExtensions.h"
 #import "NSGraphics_SKExtensions.h"
 #import "NSView_SKExtensions.h"
-#import "NSScreen_SKExtensions.h"
 
 #define SMALL_DELAY 0.1
 #define RESIZE_TIME_FACTOR 1.0
@@ -522,9 +520,11 @@
 }
 
 - (NSAttributedString *)thumbnailAttachmentWithSize:(CGFloat)size {
-    NSImage *image = [self thumbnailWithSize:size scale:[NSScreen 
maxBackingScaleFactor]];
+    NSBitmapImageRep *imageRep1 = (NSBitmapImageRep *)[[[self 
thumbnailWithSize:size scale:1.0] representations] firstObject];
+    NSBitmapImageRep *imageRep2 = (NSBitmapImageRep *)[[[self 
thumbnailWithSize:size scale:2.0] representations] firstObject];
+    NSData *data = [NSBitmapImageRep 
TIFFRepresentationOfImageRepsInArray:@[imageRep2, imageRep1]];
     
-    NSFileWrapper *wrapper = [[NSFileWrapper alloc] 
initRegularFileWithContents:[image TIFFRepresentation]];
+    NSFileWrapper *wrapper = [[NSFileWrapper alloc] 
initRegularFileWithContents:data];
     NSString *filename = [NSString 
stringWithFormat:@"snapshot_page_%lu.tiff",(unsigned long)( [self pageIndex] + 
1)];
     [wrapper setFilename:filename];
     [wrapper setPreferredFilename:filename];
@@ -721,8 +721,11 @@
 }
 
 - (void)filePromiseProvider:(NSFilePromiseProvider *)filePromiseProvider 
writePromiseToURL:(NSURL *)fileURL completionHandler:(void (^)(NSError 
*))completionHandler {
+    NSBitmapImageRep *imageRep1 = (NSBitmapImageRep *)[[[self 
thumbnailWithSize:0.0 scale:1.0] representations] firstObject];
+    NSBitmapImageRep *imageRep2 = (NSBitmapImageRep *)[[[self 
thumbnailWithSize:0.0 scale:2.0] representations] firstObject];
+    NSData *data = [NSBitmapImageRep 
TIFFRepresentationOfImageRepsInArray:@[imageRep2, imageRep1]];
     NSError *error = nil;
-    [[[self thumbnailWithSize:0.0 scale:[NSScreen maxBackingScaleFactor]] 
TIFFRepresentation] writeToURL:fileURL options:NSDataWritingAtomic 
error:&error];
+    [data writeToURL:fileURL options:NSDataWritingAtomic error:&error];
     completionHandler(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