From: <ama...@us...> - 2007-12-17 00:23:14
|
Revision: 11937 http://bibdesk.svn.sourceforge.net/bibdesk/?rev=11937&view=rev Author: amaxwell Date: 2007-12-16 16:23:18 -0800 (Sun, 16 Dec 2007) Log Message: ----------- - Use ARGB for all bitmaps, now that text bitmaps are cached to disk. - Remove 8-bit grayscale context code. - Remove an unnecessary warning. Modified Paths: -------------- trunk/bibdesk_vendorsrc/amaxwell/FileView/FVBitmapContextCache.h trunk/bibdesk_vendorsrc/amaxwell/FileView/FVBitmapContextCache.m trunk/bibdesk_vendorsrc/amaxwell/FileView/FVIconCache.mm trunk/bibdesk_vendorsrc/amaxwell/FileView/FVTextIcon.m Modified: trunk/bibdesk_vendorsrc/amaxwell/FileView/FVBitmapContextCache.h =================================================================== --- trunk/bibdesk_vendorsrc/amaxwell/FileView/FVBitmapContextCache.h 2007-12-16 23:08:42 UTC (rev 11936) +++ trunk/bibdesk_vendorsrc/amaxwell/FileView/FVBitmapContextCache.h 2007-12-17 00:23:18 UTC (rev 11937) @@ -39,7 +39,6 @@ #import <Cocoa/Cocoa.h> FV_PRIVATE_EXTERN CGContextRef FVIconBitmapContextCreateWithSize(size_t width, size_t height); -FV_PRIVATE_EXTERN CGContextRef FVIconBitmapContextCreateGrayNoAlphaWithSize(size_t width, size_t height); FV_PRIVATE_EXTERN void FVIconBitmapContextDispose(CGContextRef ctxt); @interface FVBitmapContextCache : NSObject @@ -48,8 +47,4 @@ + (CGContextRef)newBitmapContextOfWidth:(CGFloat)w height:(CGFloat)h; + (void)disposeOfBitmapContext:(CGContextRef)ctxt; -// Grayscale cache -+ (void)disposeOf8BitGrayBitmapContext:(CGContextRef)ctxt; -+ (CGContextRef)new8BitGrayBitmapContextOfWidth:(CGFloat)w height:(CGFloat)h; - @end Modified: trunk/bibdesk_vendorsrc/amaxwell/FileView/FVBitmapContextCache.m =================================================================== --- trunk/bibdesk_vendorsrc/amaxwell/FileView/FVBitmapContextCache.m 2007-12-16 23:08:42 UTC (rev 11936) +++ trunk/bibdesk_vendorsrc/amaxwell/FileView/FVBitmapContextCache.m 2007-12-17 00:23:18 UTC (rev 11937) @@ -53,7 +53,7 @@ /* An underlying assumption here is that we'll be displaying many items of the same size. This is valid for pages of text (PDF/PS/RTF/etc), where we'll typically have a mix of letter/a4 pages with a few bastard ones thrown in. Update: journal pages are entirely bastard sizes, so we now create and destroy those contexts as needed. Scaling each page to paper size isn't right, but we could possibly check the aspect ratio and scale to a cached size. - This cache is also used for file icons. Since the FileView requests icons at widely varying sizes with floating point precision if the icon scale changes, the caller is responsible for ensuring a reasonable granularity of sizes (e.g. 16, 32, 64, 128, 256, 512) using bestIntegralSizeForIconSize(). + This cache was also used for file icons. Since the FileView requests icons at widely varying sizes with floating point precision if the icon scale changes, the caller is responsible for ensuring a reasonable granularity of sizes (e.g. 16, 32, 64, 128, 256, 512) using bestIntegralSizeForIconSize(). General image files are processed with ImageIO, since they can vary widely in pixel size. @@ -61,52 +61,18 @@ static NSLock *__cacheLock = nil; static NSMutableDictionary *__contextCache = nil; -static NSMutableDictionary *__gray8bitContextCache = nil; + (void)initialize { static BOOL didInit = NO; if (NO == didInit) { - // lock is shared between both caches; since this class is generally accessed from the rendering thread, there's no real contention to deal with + // Since this class is generally accessed from the rendering thread, there's no real contention to deal with. __cacheLock = [[NSLock alloc] init]; __contextCache = [[NSMutableDictionary alloc] init]; - __gray8bitContextCache = [[NSMutableDictionary alloc] init]; didInit = YES; } } -FV_PRIVATE_EXTERN CGContextRef FVIconBitmapContextCreateGrayNoAlphaWithSize(size_t width, size_t height) -{ - size_t bitsPerComponent = 8; - size_t nComponents = 1; - size_t bytesPerRow = bitsPerComponent * nComponents * width; - - //Widen bytesPerRow out to a integer multiple of 16 bytes - bytesPerRow = (bytesPerRow + 15) & ~15; - - //Make sure we are not an even power of 2 wide. - //Will loop a few times for bytesPerRow <= 16. - while( 0 == (bytesPerRow & (bytesPerRow - 1) ) ) - bytesPerRow += 16; //grow bytesPerRow - - size_t requiredDataSize = bytesPerRow * height; - - // see comments in FVIconBitmapContextCreateWithSize() - CGColorSpaceRef cspace = CGColorSpaceCreateDeviceGray(); - void *bitmapData = NSZoneMalloc(NSDefaultMallocZone(), requiredDataSize); - - CGContextRef ctxt; - // we're using kCGImageAlphaNone instead of kCGImageAlphaNoneSkipFirst since it lets us maintain a smaller memory footprint - ctxt = CGBitmapContextCreate(bitmapData, width, height, bitsPerComponent, bytesPerRow, cspace, kCGImageAlphaNone); - CGColorSpaceRelease(cspace); - - CGContextSetRenderingIntent(ctxt, kCGRenderingIntentAbsoluteColorimetric); - - // note that bitmapData and the context itself are allocated and not freed here - - return ctxt; -} - FV_PRIVATE_EXTERN CGContextRef FVIconBitmapContextCreateWithSize(size_t width, size_t height) { size_t bitsPerComponent = 8; @@ -145,47 +111,6 @@ CGContextRelease(ctxt); } -+ (CGContextRef)new8BitGrayBitmapContextOfWidth:(CGFloat)w height:(CGFloat)h; -{ - NSUInteger width = w, height = h; - FVBitmapSize *key = [FVBitmapSize newSizeWithWidth:width height:height]; - [__cacheLock lock]; - CGContextRef ctxt = (CGContextRef)[__gray8bitContextCache objectForKey:key]; - if (NULL == ctxt) { - // create a new context; the caller can then release it or push it into the cache - ctxt = FVIconBitmapContextCreateGrayNoAlphaWithSize(w, h); - } - else { - // remove from the cache so another thread/caller doesn't get it - CGContextRetain(ctxt); - [__gray8bitContextCache removeObjectForKey:key]; - } - [key release]; - [__cacheLock unlock]; - return ctxt; -} - -+ (void)disposeOf8BitGrayBitmapContext:(CGContextRef)ctxt; -{ - // This only allows us to cache a single context for any given size; however, - // we'll generally be using them from a single thread (serially), so I don't expect that to be a problem - FVBitmapSize *key = [FVBitmapSize newSizeWithWidth:CGBitmapContextGetWidth(ctxt) height:CGBitmapContextGetHeight(ctxt)]; - [__cacheLock lock]; - if ([__gray8bitContextCache objectForKey:key]) { - // we already have one of this size, so get rid of this instance - void *bitmapData = CGBitmapContextGetData(ctxt); - if (bitmapData) NSZoneFree(NSZoneFromPointer(bitmapData), bitmapData); - } - else { - // push it into the cache - [__gray8bitContextCache setObject:(id)ctxt forKey:key]; - } - [key release]; - // always decrement the retain count, since we either retained it in the cache or got rid of it - CGContextRelease(ctxt); - [__cacheLock unlock]; -} - + (CGContextRef)newBitmapContextOfWidth:(CGFloat)w height:(CGFloat)h; { NSUInteger width = w, height = h; Modified: trunk/bibdesk_vendorsrc/amaxwell/FileView/FVIconCache.mm =================================================================== --- trunk/bibdesk_vendorsrc/amaxwell/FileView/FVIconCache.mm 2007-12-16 23:08:42 UTC (rev 11936) +++ trunk/bibdesk_vendorsrc/amaxwell/FileView/FVIconCache.mm 2007-12-17 00:23:18 UTC (rev 11937) @@ -248,16 +248,10 @@ #undef USE_IMAGEIO #endif -#if 0 // MAC_OS_X_VERSION_10_5 -#define USE_IMAGEIO 1 -#warning FVIconCache is using ImageIO -#else -#warning FVIconCache is using raw bitmap data #define USE_IMAGEIO 0 #ifndef MAC_OS_X_VERSION_10_5 #warning Using private CG API #endif -#endif // PNG and JPEG2000 are too slow when drawing, and TIFF is too big (although we could compress it) #define IMAGEIO_TYPE kUTTypeTIFF Modified: trunk/bibdesk_vendorsrc/amaxwell/FileView/FVTextIcon.m =================================================================== --- trunk/bibdesk_vendorsrc/amaxwell/FileView/FVTextIcon.m 2007-12-16 23:08:42 UTC (rev 11936) +++ trunk/bibdesk_vendorsrc/amaxwell/FileView/FVTextIcon.m 2007-12-17 00:23:18 UTC (rev 11937) @@ -316,7 +316,7 @@ // repeat for the thumbnail image as needed, but this time just draw our bitmap again if (NULL == _thumbnailRef) { - ctxt = [FVBitmapContextCache new8BitGrayBitmapContextOfWidth:_thumbnailSize.width height:_thumbnailSize.height]; + ctxt = [FVBitmapContextCache newBitmapContextOfWidth:_thumbnailSize.width height:_thumbnailSize.height]; CGContextSaveGState(ctxt); // take a small hit here for good interpolation so we can draw smaller icons at larger sizes @@ -333,7 +333,7 @@ pthread_mutex_unlock(&_mutex); CGContextRestoreGState(ctxt); - [FVBitmapContextCache disposeOf8BitGrayBitmapContext:ctxt]; + [FVBitmapContextCache disposeOfBitmapContext:ctxt]; } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |