Revision: 25416
http://sourceforge.net/p/bibdesk/svn/25416
Author: hofman
Date: 2021-01-16 23:19:06 +0000 (Sat, 16 Jan 2021)
Log Message:
-----------
Use AVFoundation to get icon for movies
Modified Paths:
--------------
trunk/bibdesk_vendorsrc/amaxwell/FileView/FVImageIcon.m
trunk/bibdesk_vendorsrc/amaxwell/FileView/FVMovieIcon.m
trunk/bibdesk_vendorsrc/amaxwell/FileView/FileView.xcodeproj/project.pbxproj
Modified: trunk/bibdesk_vendorsrc/amaxwell/FileView/FVImageIcon.m
===================================================================
--- trunk/bibdesk_vendorsrc/amaxwell/FileView/FVImageIcon.m 2021-01-16
16:56:02 UTC (rev 25415)
+++ trunk/bibdesk_vendorsrc/amaxwell/FileView/FVImageIcon.m 2021-01-16
23:19:06 UTC (rev 25416)
@@ -140,6 +140,23 @@
return (CFDataRef)[[NSData allocWithZone:FVDefaultZone()]
initWithContentsOfURL:_fileURL options:NSUncachedRead error:NULL];
}
+- (CGImageRef)_copyImageWhileLocked {
+ CGImageRef image = NULL;
+ CFDataRef imageData = [self _copyDataForImageSourceWhileLocked];
+
+ if (imageData) {
+ CGImageSourceRef src = CGImageSourceCreateWithData(imageData,
_imsrcOptions);
+ CFRelease(imageData);
+ if (src) {
+ if (CGImageSourceGetCount(src) > 0)
+ image = CGImageSourceCreateImageAtIndex(src, 0, _imsrcOptions);
+ CFRelease(src);
+ }
+ }
+
+ return image;
+}
+
- (void)renderForSize:(NSSize)size
{
[[self class] _startRenderingForKey:_cacheKey];
@@ -191,28 +208,19 @@
// At this point, neither icon should be present, unless ImageIO failed
previously or caching failed. However, if multiple views are caching icons at
the same time, we can end up here with a thumbnail but no full image. Make
sure we don't leak in that case.
NSAssert1(NULL == _fullImage, @"unexpected full image for %@", [_fileURL
path]);
-
- CGImageSourceRef src = NULL;
- CFDataRef imageData = [self _copyDataForImageSourceWhileLocked];
- if (imageData) {
- src = CGImageSourceCreateWithData(imageData, _imsrcOptions);
- CFRelease(imageData);
- }
-
// local references for disk caching so we can unlock and draw earlier
CGImageRef fullImage = NULL, thumbnail = NULL;
- if (src && CGImageSourceGetCount(src) > 0) {
-
- // Now we have a thumbnail, create the full image so we have both of
them in the cache. Originally only the large image was cached to disk, and
then only if it was actually resampled. ImageIO is fast, in general, so
FVCGImageCache doesn't really benefit us significantly. The problem is
FVMovieIcon, which hits the main thread to get image data. To avoid hiccups in
the subclass, then, we'll just cache both images for consistency.
- CGImageRef sourceImage = CGImageSourceCreateImageAtIndex(src, 0,
_imsrcOptions);
- if (sourceImage) {
- // limit the size for better drawing/memory performance
- _fullImage = FVCreateResampledFullImage(sourceImage);
- fullImage = CGImageRetain(_fullImage);
- }
+ CGImageRef sourceImage = [self _copyImageWhileLocked];
+
+ // Now we have a thumbnail, create the full image so we have both of them
in the cache. Originally only the large image was cached to disk, and then
only if it was actually resampled. ImageIO is fast, in general, so
FVCGImageCache doesn't really benefit us significantly. The problem is
FVMovieIcon, which hits the main thread to get image data. To avoid hiccups in
the subclass, then, we'll just cache both images for consistency.
+ if (sourceImage) {
+ // limit the size for better drawing/memory performance
+ _fullImage = FVCreateResampledFullImage(sourceImage);
+ fullImage = CGImageRetain(_fullImage);
+
// resample the original image for better quality
if (NULL == _thumbnail) {
_thumbnail = FVCreateResampledThumbnail(sourceImage);
@@ -237,8 +245,6 @@
}
}
- if (src) CFRelease(src);
-
if (NULL == _thumbnail && NULL == _fullImage) {
_loadFailed = YES;
// _fallbackicon is created lazily in (fast)drawinRect:inContext: on
the main thread
Modified: trunk/bibdesk_vendorsrc/amaxwell/FileView/FVMovieIcon.m
===================================================================
--- trunk/bibdesk_vendorsrc/amaxwell/FileView/FVMovieIcon.m 2021-01-16
16:56:02 UTC (rev 25415)
+++ trunk/bibdesk_vendorsrc/amaxwell/FileView/FVMovieIcon.m 2021-01-16
23:19:06 UTC (rev 25416)
@@ -42,10 +42,19 @@
#import "FVOperationQueue.h"
#import "FVInvocationOperation.h"
+#if defined(MAC_OS_X_VERSION_10_7) && MAC_OS_X_VERSION_MAX_ALLOWED >=
MAC_OS_X_VERSION_10_7
+#import <AVFoundation/AVFoundation.h>
+#endif
+
/* @@ QTKit
#import <QTKit/QTKit.h>
*/
+@interface FVImageIcon (Private)
+- (CFDataRef)_copyDataForImageSourceWhileLocked;
+- (CGImageRef)_copyImageWhileLocked;
+@end
+
@implementation FVMovieIcon
/*
@@ -101,7 +110,13 @@
/* @@ QTKit
return [QTMovie canInitWithURL:url];
*/
+#if !defined(MAC_OS_X_VERSION_10_7) || MAC_OS_X_VERSION_MAX_ALLOWED <
MAC_OS_X_VERSION_10_7
return NO;
+#elif MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_7
+ return YES;
+#else
+ return floor(NSAppKitVersionNumber) >= NSAppKitVersionNumber10_7;
+#endif
}
- (BOOL)canReleaseResources;
@@ -129,4 +144,21 @@
return data;
}
+#if defined(MAC_OS_X_VERSION_10_7) && MAC_OS_X_VERSION_MAX_ALLOWED >=
MAC_OS_X_VERSION_10_7
+
+- (CGImageRef)_copyImageWhileLocked {
+ if ([AVAsset self] == Nil)
+ return [super _copyImageWhileLocked];
+ AVAsset *asset = [AVAsset assetWithURL:_fileURL];
+ AVAssetImageGenerator *imageGenerator = [[AVAssetImageGenerator alloc]
initWithAsset:asset];
+ CMTime time = [asset duration];
+ // 4% or 10 seconds, whichever is smaller
+ time = CMTimeMinimum(CMTimeMultiplyByRatio(time, 1, 25),
CMTimeMakeWithSeconds(10.0, time.timescale));
+ CGImageRef image = [imageGenerator copyCGImageAtTime:time actualTime:NULL
error:NULL];
+ [imageGenerator release];
+ return image;
+}
+
+#endif
+
@end
Modified:
trunk/bibdesk_vendorsrc/amaxwell/FileView/FileView.xcodeproj/project.pbxproj
===================================================================
---
trunk/bibdesk_vendorsrc/amaxwell/FileView/FileView.xcodeproj/project.pbxproj
2021-01-16 16:56:02 UTC (rev 25415)
+++
trunk/bibdesk_vendorsrc/amaxwell/FileView/FileView.xcodeproj/project.pbxproj
2021-01-16 23:19:06 UTC (rev 25416)
@@ -51,6 +51,8 @@
CE89233F0D7CBB1A006D514C /* FVOperation.m in Sources */ = {isa
= PBXBuildFile; fileRef = CE05D5E90D7C22550034C2A8 /* FVOperation.m */; };
CEA831140DC1FAB500B551D1 /* FVAccessibilityIconElement.h in
Headers */ = {isa = PBXBuildFile; fileRef = CEA831120DC1FAB500B551D1 /*
FVAccessibilityIconElement.h */; };
CEA831150DC1FAB500B551D1 /* FVAccessibilityIconElement.m in
Sources */ = {isa = PBXBuildFile; fileRef = CEA831130DC1FAB500B551D1 /*
FVAccessibilityIconElement.m */; };
+ CEAD5FAD25B3A418002281E0 /* AVFoundation.framework in
Frameworks */ = {isa = PBXBuildFile; fileRef = CEAD5FAC25B3A417002281E0 /*
AVFoundation.framework */; settings = {ATTRIBUTES = (Weak, ); }; };
+ CEAD5FB025B3A504002281E0 /* CoreMedia.framework in Frameworks
*/ = {isa = PBXBuildFile; fileRef = CEAD5FAF25B3A504002281E0 /*
CoreMedia.framework */; settings = {ATTRIBUTES = (Weak, ); }; };
CEC48F2325B090ED00A2B40A /* FVLockBadge.m in Sources */ = {isa
= PBXBuildFile; fileRef = CEC48F2125B090ED00A2B40A /* FVLockBadge.m */; };
CEC48F2425B090ED00A2B40A /* FVLockBadge.h in Headers */ = {isa
= PBXBuildFile; fileRef = CEC48F2225B090ED00A2B40A /* FVLockBadge.h */; };
CEC9932D1072B6C50089F20D /* FVPreviewer.xib in Resources */ =
{isa = PBXBuildFile; fileRef = CEC9932C1072B6C50089F20D /* FVPreviewer.xib */;
};
@@ -201,6 +203,8 @@
CE65FC5B0F72578D0089F9DC /* _FVSplitSet.m */ = {isa =
PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path
= _FVSplitSet.m; sourceTree = "<group>"; };
CEA831120DC1FAB500B551D1 /* FVAccessibilityIconElement.h */ =
{isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h;
path = FVAccessibilityIconElement.h; sourceTree = "<group>"; };
CEA831130DC1FAB500B551D1 /* FVAccessibilityIconElement.m */ =
{isa = PBXFileReference; fileEncoding = 4; lastKnownFileType =
sourcecode.c.objc; path = FVAccessibilityIconElement.m; sourceTree = "<group>";
};
+ CEAD5FAC25B3A417002281E0 /* AVFoundation.framework */ = {isa =
PBXFileReference; lastKnownFileType = wrapper.framework; name =
AVFoundation.framework; path =
System/Library/Frameworks/AVFoundation.framework; sourceTree = SDKROOT; };
+ CEAD5FAF25B3A504002281E0 /* CoreMedia.framework */ = {isa =
PBXFileReference; lastKnownFileType = wrapper.framework; name =
CoreMedia.framework; path = System/Library/Frameworks/CoreMedia.framework;
sourceTree = SDKROOT; };
CEC48F2125B090ED00A2B40A /* FVLockBadge.m */ = {isa =
PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path
= FVLockBadge.m; sourceTree = "<group>"; };
CEC48F2225B090ED00A2B40A /* FVLockBadge.h */ = {isa =
PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path =
FVLockBadge.h; sourceTree = "<group>"; };
CEC9932C1072B6C50089F20D /* FVPreviewer.xib */ = {isa =
PBXFileReference; lastKnownFileType = file.xib; path = FVPreviewer.xib;
sourceTree = "<group>"; };
@@ -282,7 +286,9 @@
files = (
F92C7C500D28250F004409D8 /*
SystemConfiguration.framework in Frameworks */,
8DC2EF570486A6940098B216 /* Cocoa.framework in
Frameworks */,
+ CEAD5FAD25B3A418002281E0 /*
AVFoundation.framework in Frameworks */,
F94692320CA5710500AC2772 /* Quartz.framework in
Frameworks */,
+ CEAD5FB025B3A504002281E0 /* CoreMedia.framework
in Frameworks */,
F94692340CA5710500AC2772 /* WebKit.framework in
Frameworks */,
CEFC1F410F6AD24600B2AEE6 /*
Accelerate.framework in Frameworks */,
F980F0930CCC3C2E0067C1DF /* libz.dylib in
Frameworks */,
@@ -325,6 +331,7 @@
034768DFFF38A50411DB9C8B /* Products */,
F946927B0CA5777300AC2772 /* FileView Program */,
CE4977F71E55B9EC000B1357 /* Configurations */,
+ CEAD5FAB25B3A417002281E0 /* Frameworks */,
);
name = FileView;
sourceTree = "<group>";
@@ -510,6 +517,15 @@
path = Configurations;
sourceTree = "<group>";
};
+ CEAD5FAB25B3A417002281E0 /* Frameworks */ = {
+ isa = PBXGroup;
+ children = (
+ CEAD5FAF25B3A504002281E0 /* CoreMedia.framework
*/,
+ CEAD5FAC25B3A417002281E0 /*
AVFoundation.framework */,
+ );
+ name = Frameworks;
+ sourceTree = "<group>";
+ };
CED643780F6F107B00283709 /* Previewer */ = {
isa = PBXGroup;
children = (
This was sent by the SourceForge.net collaborative development platform, the
world's largest Open Source development site.
_______________________________________________
Bibdesk-commit mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/bibdesk-commit