summaryrefslogtreecommitdiffstats
path: root/third_party
diff options
context:
space:
mode:
Diffstat (limited to 'third_party')
-rw-r--r--third_party/icon_family/IconFamily.h194
-rw-r--r--third_party/icon_family/IconFamily.m1764
-rw-r--r--third_party/icon_family/LICENSE10
-rw-r--r--third_party/icon_family/NSString+CarbonFSRefCreation.h25
-rw-r--r--third_party/icon_family/NSString+CarbonFSRefCreation.m58
-rw-r--r--third_party/icon_family/README.chromium15
-rw-r--r--third_party/icon_family/chromium_icon_family.patch222
-rw-r--r--third_party/icon_family/chromium_icon_family_2.patch189
-rw-r--r--third_party/icon_family/icon_family.gyp27
9 files changed, 0 insertions, 2504 deletions
diff --git a/third_party/icon_family/IconFamily.h b/third_party/icon_family/IconFamily.h
deleted file mode 100644
index 63f6bb7..0000000
--- a/third_party/icon_family/IconFamily.h
+++ /dev/null
@@ -1,194 +0,0 @@
-// IconFamily.h
-// IconFamily class interface
-// by Troy Stephens, Thomas Schnitzer, David Remahl, Nathan Day, Ben Haller, Sven Janssen, Peter Hosey, Conor Dearden, Elliot Glaysher, and Dave MacLachlan
-// version 0.9.4
-//
-// Project Home Page:
-// http://iconfamily.sourceforge.net/
-//
-// Problems, shortcomings, and uncertainties that I'm aware of are flagged with "NOTE:". Please address bug reports, bug fixes, suggestions, etc. to the project Forums and bug tracker at https://sourceforge.net/projects/iconfamily/
-
-/*
- Copyright (c) 2001-2010 Troy N. Stephens
- Portions Copyright (c) 2007 Google Inc.
-
- Use and distribution of this source code is governed by the MIT License, whose terms are as follows.
-
- Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
-
- The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
-
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
-*/
-
-#import <Cocoa/Cocoa.h>
-#import <Carbon/Carbon.h>
-
-// This class is a Cocoa/Objective-C wrapper for the Mac OS X Carbon API's
-// "icon family" data type. Its main purpose is to enable Cocoa applications
-// to easily create custom file icons from NSImage instances, and thus take
-// advantage of Mac OS X's new larger RGBA "thumbnail" icon format to provide
-// richly detailed thumbnail previews of the files' contents.
-//
-// Using IconFamily, this becomes as simple as:
-//
-// id iconFamily = [IconFamily iconFamilyWithThumbnailsOfImage:anImage];
-// [iconFamily setAsCustomIconForFile:anExistingFile];
-//
-// You can also write an icon family to an .icns file using the -writeToFile:
-// method.
-
-@interface IconFamily : NSObject
-{
- IconFamilyHandle hIconFamily;
-}
-
-// Convenience methods. These use the corresponding -init... methods to return
-// an autoreleased IconFamily instance.
-
-+ (IconFamily*) iconFamily;
-+ (IconFamily*) iconFamilyWithContentsOfFile:(NSString*)path;
-+ (IconFamily*) iconFamilyWithIconOfFile:(NSString*)path;
-+ (IconFamily*) iconFamilyWithIconFamilyHandle:(IconFamilyHandle)hNewIconFamily;
-+ (IconFamily*) iconFamilyWithSystemIcon:(int)fourByteCode;
-+ (IconFamily*) iconFamilyWithThumbnailsOfImage:(NSImage*)image;
-+ (IconFamily*) iconFamilyWithThumbnailsOfImage:(NSImage*)image usingImageInterpolation:(NSImageInterpolation)imageInterpolation;
-
-// Initializes as a new, empty IconFamily. This is IconFamily's designated
-// initializer method.
-
-- (id) init;
-
-// Initializes an IconFamily by loading the contents of an .icns file.
-
-- (id) initWithContentsOfFile:(NSString*)path;
-
-// Initializes an IconFamily from an existing Carbon IconFamilyHandle.
-
-- (id) initWithIconFamilyHandle:(IconFamilyHandle)hNewIconFamily;
-
-// Initializes an IconFamily by loading the Finder icon that's assigned to a
-// file.
-
-- (id) initWithIconOfFile:(NSString*)path;
-
-// Initializes an IconFamily by referencing a standard system icon.
-
-- (id) initWithSystemIcon:(int)fourByteCode;
-
-// Initializes an IconFamily by creating its elements from a resampled
-// NSImage. The second form of this method allows you to specify the degree
-// of antialiasing to be used in resampling the image, by passing in one of
-// the NSImageInterpolation... constants that are defined in
-// NSGraphicsContext.h. The first form of this initializer simply calls the
-// second form with imageInterpolation set to NSImageInterpolationHigh, which
-// produces highly smoothed thumbnails.
-
-- (id) initWithThumbnailsOfImage:(NSImage*)image;
-- (id) initWithThumbnailsOfImage:(NSImage*)image usingImageInterpolation:(NSImageInterpolation)imageInterpolation;
-
-// Writes the icon family to an .icns file.
-
-- (BOOL) writeToFile:(NSString*)path;
-
-// Sets the image data for one of the icon family's elements from an
-// NSBitmapImageRep. The "elementType" parameter must be one of the icon
-// family element types listed below, and the format of the "bitmapImageRep"
-// must match the corresponding requirements specified below. Regardless of
-// the elementType, the bitmapImageRep must also be non-planar and have 8 bits
-// per sample.
-//
-// elementType dimensions format
-// ------------------- ---------- ---------------------------------------
-// kIconServices512PixelDataARGB 512 x 512 32-bit RGBA, 32-bit RGB, or 24-bit RGB
-// kIconServices256PixelDataARGB 256 x 256 32-bit RGBA, 32-bit RGB, or 24-bit RGB
-// kThumbnail32BitData 128 x 128 32-bit RGBA, 32-bit RGB, or 24-bit RGB
-// kThumbnail8BitMask 128 x 128 32-bit RGBA or 8-bit intensity
-// kLarge32BitData 32 x 32 32-bit RGBA, 32-bit RGB, or 24-bit RGB
-// kLarge8BitMask 32 x 32 32-bit RGBA or 8-bit intensity
-// kLarge1BitMask 32 x 32 32-bit RGBA, 8-bit intensity, or 1-bit
-// kSmall32BitData 16 x 16 32-bit RGBA, 32-bit RGB, or 24-bit RGB
-// kSmall8BitMask 16 x 16 32-bit RGBA or 8-bit intensity
-// kSmall1BitMask 16 x 16 32-bit RGBA, 8-bit intensity, or 1-bit
-//
-// When an RGBA image is supplied to set a "Mask" element, the mask data is
-// taken from the image's alpha channel.
-//
-// NOTE: Setting an IconFamily's kLarge1BitMask seems to damage the IconFamily
-// for some as yet unknown reason. (If you then assign the icon family
-// as a file's custom icon using -setAsCustomIconForFile:, the custom
-// icon doesn't appear for the file in the Finder.) However, both
-// custom icon display and mouse-click hit-testing in the Finder seem to
-// work fine when we only set the other four elements (thus keeping the
-// existing kLarge1BitMask from the valid icon family from which we
-// initialized the IconFamily via -initWithContentsOfFile:, since
-// IconFamily's -init method is currently broken...), so it seems safe
-// to just leave the kLarge1BitMask alone.
-
-- (BOOL) setIconFamilyElement:(OSType)elementType
- fromBitmapImageRep:(NSBitmapImageRep*)bitmapImageRep;
-
-// Gets the image data for one of the icon family's elements as a new, 32-bit
-// RGBA NSBitmapImageRep. The specified elementType should be one of
-// kIconServices512PixelDataARGB, kIconServices256PixelDataARGB,
-// kThumbnail32BitData, kLarge32BitData, or kSmall32BitData.
-//
-// The returned NSBitmapImageRep will have the corresponding 8-bit mask data
-// in its alpha channel, or a fully opaque alpha channel if the icon family
-// has no 8-bit mask data for the specified alpha channel.
-//
-// Returns nil if the requested element cannot be retrieved (e.g. if the
-// icon family has no such 32BitData element).
-
-- (NSBitmapImageRep*) bitmapImageRepWithAlphaForIconFamilyElement:(OSType)elementType;
-
-// Creates and returns an NSImage that contains the icon family's various
-// elements as its NSImageReps.
-
-- (NSImage*) imageWithAllReps;
-
-#if !defined(DISABLE_CUSTOM_ICON)
-
-// NOTE: Planned method -- not yet implemented.
-//
-// Gets the image data for one of the icon family's elements as a new
-// NSBitmapImageRep. The specified elementType should be one of
-// kThumbnail32BitData, kThumbnail32BitMask, kLarge32BitData, kLarge8BitMask,
-// kLarge1BitMask, kSmall32BitData, kSmall8BitMask, or kSmall1BitMask.
-
-// - (NSBitmapImageRep*) bitmapImageRepForIconFamilyElement:(OSType)elementType;
-
-// Writes the icon family to the resource fork of the specified file as its
-// kCustomIconResource, and sets the necessary Finder bits so the icon will
-// be displayed for the file in Finder views.
-
-- (BOOL) setAsCustomIconForFile:(NSString*)path;
-- (BOOL) setAsCustomIconForFile:(NSString*)path withCompatibility:(BOOL)compat;
-
-// Same as the -setAsCustomIconForFile:... methods, but for folders (directories).
-
-- (BOOL) setAsCustomIconForDirectory:(NSString*)path;
-- (BOOL) setAsCustomIconForDirectory:(NSString*)path withCompatibility:(BOOL)compat;
-
-// Removes the custom icon (if any) from the specified file's resource fork,
-// and clears the necessary Finder bits for the file. (Note that this is a
-// class method, so you don't need an instance of IconFamily to invoke it.)
-
-+ (BOOL) removeCustomIconFromFile:(NSString*)path;
-
-//Same as the -removeCustomIconFromFile: method, but for folders (directories).
-
-+ (BOOL) removeCustomIconFromDirectory:(NSString*)path;
-
-#endif // !defined(DISABLE_CUSTOM_ICON)
-
-@end
-
-// Methods for interfacing with the Carbon Scrap Manager (analogous to and
-// interoperable with the Cocoa Pasteboard).
-@interface IconFamily (ScrapAdditions)
-+ (BOOL) canInitWithScrap;
-+ (IconFamily*) iconFamilyWithScrap;
-- (id) initWithScrap;
-- (BOOL) putOnScrap;
-@end
diff --git a/third_party/icon_family/IconFamily.m b/third_party/icon_family/IconFamily.m
deleted file mode 100644
index 911ea31..0000000
--- a/third_party/icon_family/IconFamily.m
+++ /dev/null
@@ -1,1764 +0,0 @@
-// IconFamily.m
-// IconFamily class implementation
-// by Troy Stephens, Thomas Schnitzer, David Remahl, Nathan Day, Ben Haller, Sven Janssen, Peter Hosey, Conor Dearden, Elliot Glaysher, and Dave MacLachlan
-// version 0.9.4
-//
-// Project Home Page:
-// http://iconfamily.sourceforge.net/
-//
-// Problems, shortcomings, and uncertainties that I'm aware of are flagged with "NOTE:". Please address bug reports, bug fixes, suggestions, etc. to the project Forums and bug tracker at https://sourceforge.net/projects/iconfamily/
-
-/*
- Copyright (c) 2001-2010 Troy N. Stephens
- Portions Copyright (c) 2007 Google Inc.
-
- Use and distribution of this source code is governed by the MIT License, whose terms are as follows.
-
- Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
-
- The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
-
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
-*/
-
-#import "IconFamily.h"
-#import "NSString+CarbonFSRefCreation.h"
-
-
-@interface NSFileManager (IconFamilyCompatibility)
-
-- (NSDictionary *) iconfamily_attributesAtPath:(NSString *)path;
-- (BOOL) iconfamily_setAttributes:(NSDictionary *)attributes atPath:(NSString *)path;
-- (BOOL) iconfamily_removeItemAtPath:(NSString *)path;
-
-@end
-
-
-@interface NSImage (IconFamilyCompatibility)
-
-- (NSImageRep *) iconfamily_bestRepresentation;
-
-@end
-
-
-#if MAC_OS_X_VERSION_MAX_ALLOWED <= 1050
-// Methods defined in 10.6 and beyond
-@interface NSImage (SnowLeopard)
-
-- (NSImageRep *)bestRepresentationForRect:(NSRect)rect context:(NSGraphicsContext *)referenceContext hints:(NSDictionary *)hints;
-
-@end
-#endif
-
-
-#if MAC_OS_X_VERSION_MAX_ALLOWED <= MAC_OS_X_VERSION_10_4
-// This is defined in 10.5 and beyond in IconStorage.h
-enum {
- kIconServices512PixelDataARGB = 'ic09' /* non-premultiplied 512x512 ARGB bitmap*/
-};
-
-// Methods defined in 10.5 and beyond
-@interface NSFileManager (Leopard)
-
-- (NSDictionary *)attributesOfItemAtPath:(NSString *)path error:(NSError **)error;
-- (BOOL)setAttributes:(NSDictionary *)attributes ofItemAtPath:(NSString *)path error:(NSError **)error;
-- (BOOL)removeItemAtPath:(NSString *)path error:(NSError **)error;
-
-@end
-#endif
-
-#if MAC_OS_X_VERSION_MAX_ALLOWED <= MAC_OS_X_VERSION_10_3
-// This is defined in 10.4 and beyond in IconStorage.h
-enum {
- kIconServices256PixelDataARGB = 'ic08' /* non-premultiplied 256x256 ARGB bitmap*/
-};
-#endif
-
-// Necessary on 10.5 for Preview's "New with Clipboard" menu item to see the IconFamily data.
-#define ICONFAMILY_UTI @"com.apple.icns"
-// Determined by using Pasteboard Manager to put com.apple.icns data on the clipboard. Alternatively, you can determine this by copying an application to the clipboard using the Finder (select an application and press cmd-C).
-#define ICONFAMILY_PBOARD_TYPE @"'icns' (CorePasteboardFlavorType 0x69636E73)"
-
-@interface IconFamily (Internals)
-
-+ (NSImage*) resampleImage:(NSImage*)image toIconWidth:(int)width usingImageInterpolation:(NSImageInterpolation)imageInterpolation;
-
-+ (Handle) get32BitDataFromBitmapImageRep:(NSBitmapImageRep*)bitmapImageRep requiredPixelSize:(int)requiredPixelSize;
-
-+ (Handle) get8BitDataFromBitmapImageRep:(NSBitmapImageRep*)bitmapImageRep requiredPixelSize:(int)requiredPixelSize;
-
-+ (Handle) get8BitMaskFromBitmapImageRep:(NSBitmapImageRep*)bitmapImageRep requiredPixelSize:(int)requiredPixelSize;
-
-+ (Handle) get1BitMaskFromBitmapImageRep:(NSBitmapImageRep*)bitmapImageRep requiredPixelSize:(int)requiredPixelSize;
-
-#if !defined(DISABLE_CUSTOM_ICON)
-- (BOOL) addResourceType:(OSType)type asResID:(int)resID;
-#endif
-
-@end
-
-@implementation IconFamily
-
-+ (IconFamily*) iconFamily
-{
- return [[[IconFamily alloc] init] autorelease];
-}
-
-+ (IconFamily*) iconFamilyWithContentsOfFile:(NSString*)path
-{
- return [[[IconFamily alloc] initWithContentsOfFile:path] autorelease];
-}
-
-+ (IconFamily*) iconFamilyWithIconOfFile:(NSString*)path
-{
- return [[[IconFamily alloc] initWithIconOfFile:path] autorelease];
-}
-
-+ (IconFamily*) iconFamilyWithIconFamilyHandle:(IconFamilyHandle)hNewIconFamily
-{
- return [[[IconFamily alloc] initWithIconFamilyHandle:hNewIconFamily] autorelease];
-}
-
-+ (IconFamily*) iconFamilyWithSystemIcon:(int)fourByteCode
-{
- return [[[IconFamily alloc] initWithSystemIcon:fourByteCode] autorelease];
-}
-
-+ (IconFamily*) iconFamilyWithThumbnailsOfImage:(NSImage*)image
-{
- return [[[IconFamily alloc] initWithThumbnailsOfImage:image] autorelease];
-}
-
-+ (IconFamily*) iconFamilyWithThumbnailsOfImage:(NSImage*)image usingImageInterpolation:(NSImageInterpolation)imageInterpolation
-{
- return [[[IconFamily alloc] initWithThumbnailsOfImage:image usingImageInterpolation:imageInterpolation] autorelease];
-}
-
-// This is IconFamily's designated initializer. It creates a new IconFamily that initially has no elements.
-//
-// The proper way to do this is to simply allocate a zero-sized handle (not to be confused with an empty handle) and assign it to hIconFamily. This technique works on Mac OS X 10.2 as well as on 10.0.x and 10.1.x. Our previous technique of allocating an IconFamily struct with a resourceSize of 0 no longer works as of Mac OS X 10.2.
-- (id) init
-{
- self = [super init];
- if (self) {
- hIconFamily = (IconFamilyHandle) NewHandle( 0 );
- if (hIconFamily == NULL) {
- [self autorelease];
- return nil;
- }
- }
- return self;
-}
-
-- (id) initWithData:(NSData *)data
-{
- self = [self init];
- if (self) {
- Handle storageMem = NULL;
-
- OSStatus err = PtrToHand([data bytes], &storageMem, (long)[data length]);
- if( err != noErr )
- {
- [self release];
- return nil;
- }
-
- hIconFamily = (IconFamilyHandle)storageMem;
- }
- return self;
-}
-
-- (id) initWithContentsOfFile:(NSString*)path
-{
- FSRef ref;
- OSStatus result;
-
- self = [self init];
- if (self) {
- if (hIconFamily) {
- DisposeHandle( (Handle)hIconFamily );
- hIconFamily = NULL;
- }
- if (![path getFSRef:&ref createFileIfNecessary:NO]) {
- [self autorelease];
- return nil;
- }
- result = ReadIconFromFSRef( &ref, &hIconFamily );
- if (result != noErr) {
- [self autorelease];
- return nil;
- }
- }
- return self;
-}
-
-- (id) initWithIconFamilyHandle:(IconFamilyHandle)hNewIconFamily
-{
- self = [self init];
- if (self) {
- if (hIconFamily) {
- DisposeHandle( (Handle)hIconFamily );
- hIconFamily = NULL;
- }
- hIconFamily = hNewIconFamily;
- }
- return self;
-}
-
-- (id) initWithIconOfFile:(NSString*)path
-{
- IconRef iconRef;
- OSStatus result;
- SInt16 label;
- FSRef ref;
-
- self = [self init];
- if (self)
- {
- if (hIconFamily)
- {
- DisposeHandle( (Handle)hIconFamily );
- hIconFamily = NULL;
- }
-
- if( ![path getFSRef:&ref createFileIfNecessary:NO] )
- {
- [self autorelease];
- return nil;
- }
-
- result = GetIconRefFromFileInfo(
- &ref,
- /*inFileNameLength*/ 0,
- /*inFileName*/ NULL,
- kFSCatInfoNone,
- /*inCatalogInfo*/ NULL,
- kIconServicesNormalUsageFlag,
- &iconRef,
- &label );
-
- if (result != noErr)
- {
- [self autorelease];
- return nil;
- }
-
- result = IconRefToIconFamily(
- iconRef,
- kSelectorAllAvailableData,
- &hIconFamily );
-
- ReleaseIconRef( iconRef );
-
- if (result != noErr || !hIconFamily)
- {
- [self autorelease];
- return nil;
- }
- }
- return self;
-}
-
-- (id) initWithSystemIcon:(int)fourByteCode
-{
- IconRef iconRef;
- OSErr result;
-
- self = [self init];
- if (self)
- {
- if (hIconFamily)
- {
- DisposeHandle( (Handle)hIconFamily );
- hIconFamily = NULL;
- }
-
- result = GetIconRef(kOnSystemDisk, kSystemIconsCreator, fourByteCode, &iconRef);
-
- if (result != noErr)
- {
- [self autorelease];
- return nil;
- }
-
- result = IconRefToIconFamily(
- iconRef,
- kSelectorAllAvailableData,
- &hIconFamily );
-
- if (result != noErr || !hIconFamily)
- {
- [self autorelease];
- return nil;
- }
-
- ReleaseIconRef( iconRef );
- }
- return self;
-}
-
-- (id) initWithThumbnailsOfImage:(NSImage*)image
-{
- // The default is to use a high degree of antialiasing, producing a smooth image.
- return [self initWithThumbnailsOfImage:image usingImageInterpolation:NSImageInterpolationHigh];
-}
-
-- (id) initWithThumbnailsOfImage:(NSImage*)image usingImageInterpolation:(NSImageInterpolation)imageInterpolation
-{
- NSImage* iconImage512x512;
- NSImage* iconImage256x256;
- NSImage* iconImage128x128;
- NSImage* iconImage32x32;
- NSImage* iconImage16x16;
- NSImage* bitmappedIconImage512x512;
- NSBitmapImageRep* iconBitmap512x512;
- NSBitmapImageRep* iconBitmap256x256;
- NSBitmapImageRep* iconBitmap128x128;
- NSBitmapImageRep* iconBitmap32x32;
- NSBitmapImageRep* iconBitmap16x16;
-
- // Start with a new, empty IconFamily.
- self = [self init];
- if (self == nil)
- return nil;
-
- // Resample the given image to create a 512x512 pixel, 32-bit RGBA
- // version, and use that as our "thumbnail" (512x512) icon and mask.
- //
- // Our +resampleImage:toIconWidth:... method, in its present form,
- // returns an NSImage that contains an NSCacheImageRep, rather than
- // an NSBitmapImageRep. We convert to an NSBitmapImageRep, so that
- // our methods can scan the image data, using initWithFocusedViewRect:.
- iconImage512x512 = [IconFamily resampleImage:image toIconWidth:512 usingImageInterpolation:imageInterpolation];
- if (!iconImage512x512) {
- [self autorelease];
- return nil;
- }
-
- [iconImage512x512 lockFocus];
- iconBitmap512x512 = [[[NSBitmapImageRep alloc] initWithFocusedViewRect:NSMakeRect(0, 0, 512, 512)] autorelease];
- [iconImage512x512 unlockFocus];
- if (!iconBitmap512x512) {
- [self release];
- return nil;
- }
- // Create an NSImage with the iconBitmap512x512 NSBitmapImageRep, that we
- // can resample to create the smaller icon family elements. (This is
- // most likely more efficient than resampling from the original image again,
- // particularly if it is large. It produces a slightly different result, but
- // the difference is minor and should not be objectionable...)
-
- bitmappedIconImage512x512 = [[NSImage alloc] initWithSize:NSMakeSize(512, 512)];
- [bitmappedIconImage512x512 addRepresentation:iconBitmap512x512];
-
- if (!bitmappedIconImage512x512) {
- [self autorelease];
- return nil;
- }
-
- [self setIconFamilyElement:kIconServices512PixelDataARGB fromBitmapImageRep:iconBitmap512x512];
-
- iconImage256x256 = [IconFamily resampleImage:bitmappedIconImage512x512 toIconWidth:256 usingImageInterpolation:imageInterpolation];
- if (iconImage256x256) {
- [iconImage256x256 lockFocus];
- iconBitmap256x256 = [[NSBitmapImageRep alloc] initWithFocusedViewRect:NSMakeRect(0, 0, 256, 256)];
- [iconImage256x256 unlockFocus];
- if (iconBitmap256x256) {
- [self setIconFamilyElement:kIconServices256PixelDataARGB fromBitmapImageRep:iconBitmap256x256];
- [iconBitmap256x256 release];
- }
- }
-
- iconImage128x128 = [IconFamily resampleImage:bitmappedIconImage512x512 toIconWidth:128 usingImageInterpolation:imageInterpolation];
- if (iconImage128x128) {
- [iconImage128x128 lockFocus];
- iconBitmap128x128 = [[NSBitmapImageRep alloc] initWithFocusedViewRect:NSMakeRect(0, 0, 128, 128)];
- [iconImage128x128 unlockFocus];
-
- if (iconBitmap128x128) {
- [self setIconFamilyElement:kThumbnail32BitData fromBitmapImageRep:iconBitmap128x128];
- [self setIconFamilyElement:kThumbnail8BitMask fromBitmapImageRep:iconBitmap128x128];
- [iconBitmap128x128 release];
- }
- }
-
- // Resample the 512x512 image to create a 32x32 pixel, 32-bit RGBA version,
- // and use that as our "large" (32x32) icon and 8-bit mask.
- iconImage32x32 = [IconFamily resampleImage:bitmappedIconImage512x512 toIconWidth:32 usingImageInterpolation:imageInterpolation];
- if (iconImage32x32) {
- [iconImage32x32 lockFocus];
- iconBitmap32x32 = [[NSBitmapImageRep alloc] initWithFocusedViewRect:NSMakeRect(0, 0, 32, 32)];
- [iconImage32x32 unlockFocus];
- if (iconBitmap32x32) {
- [self setIconFamilyElement:kLarge32BitData fromBitmapImageRep:iconBitmap32x32];
- [self setIconFamilyElement:kLarge8BitData fromBitmapImageRep:iconBitmap32x32];
- [self setIconFamilyElement:kLarge8BitMask fromBitmapImageRep:iconBitmap32x32];
- [self setIconFamilyElement:kLarge1BitMask fromBitmapImageRep:iconBitmap32x32];
- [iconBitmap32x32 release];
- }
- }
-
- // Resample the 512x512 image to create a 16x16 pixel, 32-bit RGBA version,
- // and use that as our "small" (16x16) icon and 8-bit mask.
- iconImage16x16 = [IconFamily resampleImage:bitmappedIconImage512x512 toIconWidth:16 usingImageInterpolation:imageInterpolation];
- if (iconImage16x16) {
- [iconImage16x16 lockFocus];
- iconBitmap16x16 = [[NSBitmapImageRep alloc] initWithFocusedViewRect:NSMakeRect(0, 0, 16, 16)];
- [iconImage16x16 unlockFocus];
- if (iconBitmap16x16) {
- [self setIconFamilyElement:kSmall32BitData fromBitmapImageRep:iconBitmap16x16];
- [self setIconFamilyElement:kSmall8BitData fromBitmapImageRep:iconBitmap16x16];
- [self setIconFamilyElement:kSmall8BitMask fromBitmapImageRep:iconBitmap16x16];
- [self setIconFamilyElement:kSmall1BitMask fromBitmapImageRep:iconBitmap16x16];
- [iconBitmap16x16 release];
- }
- }
-
- // Release the icon.
- [bitmappedIconImage512x512 release];
-
- // Return the new icon family!
- return self;
-}
-
-- (void) dealloc
-{
- DisposeHandle( (Handle)hIconFamily );
- [super dealloc];
-}
-
-- (void) finalize
-{
- /* "Starting with Mac OS X v10.3, Memory Manager is thread safe"
- -- Memory Manager Reference
- */
- DisposeHandle( (Handle)hIconFamily );
- hIconFamily = NULL;
-
- [super finalize];
-}
-
-- (NSBitmapImageRep*) bitmapImageRepWithAlphaForIconFamilyElement:(OSType)elementType
-{
- NSBitmapImageRep* bitmapImageRep;
- int pixelsWide;
- Handle hRawBitmapData;
- Handle hRawMaskData = NULL;
- OSType maskElementType;
-#if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_4
- NSBitmapFormat bitmapFormat = NSAlphaFirstBitmapFormat;
-#endif
- OSErr result;
- UInt32* pRawBitmapData;
- UInt32* pRawBitmapDataEnd;
- unsigned char* pRawMaskData;
- unsigned char* pBitmapImageRepBitmapData;
-
- // Make sure elementType is a valid type that we know how to handle, and
- // figure out the dimensions and bit depth of the bitmap for that type.
- switch (elementType) {
-#if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_5
- // 'ic09' 512x512 32-bit RGB image
- case kIconServices512PixelDataARGB:
- maskElementType = 0;
- pixelsWide = 512;
- break;
-#endif
-
-#if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_4
- // 'ic08' 256x256 32-bit ARGB image
- case kIconServices256PixelDataARGB:
- maskElementType = 0;
- pixelsWide = 256;
- break;
-#endif
-
- // 'it32' 128x128 32-bit RGB image
- case kThumbnail32BitData:
- maskElementType = kThumbnail8BitMask;
- pixelsWide = 128;
- break;
-
- // 'ih32' 48x48 32-bit RGB image
- case kHuge32BitData:
- maskElementType = kHuge8BitMask;
- pixelsWide = 48;
- break;
-
- // 'il32' 32x32 32-bit RGB image
- case kLarge32BitData:
- maskElementType = kLarge8BitMask;
- pixelsWide = 32;
- break;
-
- // 'is32' 16x16 32-bit RGB image
- case kSmall32BitData:
- maskElementType = kSmall8BitMask;
- pixelsWide = 16;
- break;
-
- default:
- return nil;
- }
-
- // Get the raw, uncompressed bitmap data for the requested element.
- hRawBitmapData = NewHandle( pixelsWide * pixelsWide * 4 );
- result = GetIconFamilyData( hIconFamily, elementType, hRawBitmapData );
- if (result != noErr) {
- DisposeHandle( hRawBitmapData );
- return nil;
- }
-
- if (maskElementType) {
- // Get the corresponding raw, uncompressed 8-bit mask data.
- hRawMaskData = NewHandle( pixelsWide * pixelsWide );
- result = GetIconFamilyData( hIconFamily, maskElementType, hRawMaskData );
- if (result != noErr) {
- DisposeHandle( hRawMaskData );
- hRawMaskData = NULL;
- }
- }
-
- // The retrieved raw bitmap data is stored in memory as 32 bit per pixel, 8 bit per sample xRGB data. (The sample order provided by IconServices is the same, regardless of whether we're running on a big-endian (PPC) or little-endian (Intel) architecture.)
-#if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_4
- // With proper attention to byte order, we can fold the mask data into the color data in-place, producing ARGB data suitable for handing off to NSBitmapImageRep.
-#else
- // With proper attention to byte order, we can fold the mask data into the color data in-place, producing RGBA data suitable for handing off to NSBitmapImageRep.
-#endif
-// HLock( hRawBitmapData ); // Handle-based memory isn't compacted anymore, so calling HLock()/HUnlock() is unnecessary.
- pRawBitmapData = (UInt32*) *hRawBitmapData;
- pRawBitmapDataEnd = pRawBitmapData + pixelsWide * pixelsWide;
- if (hRawMaskData) {
-// HLock( hRawMaskData ); // Handle-based memory isn't compacted anymore, so calling HLock()/HUnlock() is unnecessary.
- pRawMaskData = (UInt8*) *hRawMaskData;
- while (pRawBitmapData < pRawBitmapDataEnd) {
-#if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_4
- // Convert the xRGB pixel data to ARGB.
- // PowerPC Intel
- // ------- -----
- // Bytes in memory are x R G B x R G B
- // *pRawBitmapData loads as 32-bit word into register xRGB BGRx
- // CFSwapInt32HostToBig() swaps this to xRGB xRGB
- // Loading *pRawMaskData and shifting left 24 bits yields A000 A000
- // Bitwise ORing these two words together yields ARGB ARGB
- // CFSwapInt32BigToHost() swaps this to ARGB BGRA
- // Bytes in memory after they're stored as a 32-bit word A R G B A R G B
- *pRawBitmapData = CFSwapInt32BigToHost((*pRawMaskData++ << 24) | CFSwapInt32HostToBig(*pRawBitmapData));
-#else
- // Convert the xRGB pixel data to RGBA.
- // PowerPC Intel
- // ------- -----
- // Bytes in memory are x R G B x R G B
- // *pRawBitmapData loads as 32-bit word into register xRGB BGRx
- // CFSwapInt32HostToBig() swaps this to xRGB xRGB
- // Shifting left 8 bits yields ('0' denotes all zero bits) RGB0 RGB0
- // Bitwise ORing with *pRawMaskData byte yields RGBA RGBA
- // CFSwapInt32BigToHost() swaps this to RGBA ABGR
- // Bytes in memory after they're stored as a 32-bit word R G B A R G B A
- *pRawBitmapData = CFSwapInt32BigToHost((CFSwapInt32HostToBig(*pRawBitmapData) << 8) | *pRawMaskData++);
-#endif
- ++pRawBitmapData;
- }
-// HUnlock( hRawMaskData ); // Handle-based memory isn't compacted anymore, so calling HLock()/HUnlock() is unnecessary.
- } else {
- if(maskElementType) {
- // We SHOULD have a mask, but apparently not. Fake it with alpha=1.
- while (pRawBitmapData < pRawBitmapDataEnd) {
-#if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_4
- // Set alpha byte to 0xff.
- // PowerPC Intel
- // ------- -----
- // Bytes in memory are x R G B x R G B
- // Writing a single 0xff byte ('1') at pRawBitmapData yields 1 R G B 1 R G B
- *(unsigned char *)pRawBitmapData = 0xff;
-#else
- // Set alpha byte to 0xff.
- // PowerPC Intel
- // ------- -----
- // Bytes in memory are R G B x R G B x
- // Writing a single 0xff byte, 3 bytes past pRawBitmapData yields R G B 1 R G B 1
- *((unsigned char *)pRawBitmapData + 3) = 0xff;
-#endif
- ++pRawBitmapData;
- }
- }
- }
-
- // Create a new NSBitmapImageRep with the given bitmap data. Note that
- // when creating the NSBitmapImageRep we pass in NULL for the "planes"
- // parameter. This causes the new NSBitmapImageRep to allocate its own
- // buffer for the bitmap data (which it will own and release when the
- // NSBitmapImageRep is released), rather than referencing the bitmap
- // data we pass in (which will soon disappear when we call
- // DisposeHandle() below!). (See the NSBitmapImageRep documentation for
- // the -initWithBitmapDataPlanes:... method, where this is explained.)
- //
- // Once we have the new NSBitmapImageRep, we get a pointer to its
- // bitmapData and copy our bitmap data in.
- bitmapImageRep = [[[NSBitmapImageRep alloc]
- initWithBitmapDataPlanes:NULL
- pixelsWide:pixelsWide
- pixelsHigh:pixelsWide
- bitsPerSample:8
- samplesPerPixel:4
- hasAlpha:YES
- isPlanar:NO
- colorSpaceName:NSDeviceRGBColorSpace // NOTE: is this right?
-#if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_4
- bitmapFormat:bitmapFormat
-#endif
- bytesPerRow:0
- bitsPerPixel:0] autorelease];
- pBitmapImageRepBitmapData = [bitmapImageRep bitmapData];
- if (pBitmapImageRepBitmapData) {
- memcpy( pBitmapImageRepBitmapData, *hRawBitmapData,
- pixelsWide * pixelsWide * 4 );
- }
-// HUnlock( hRawBitmapData ); // Handle-based memory isn't compacted anymore, so calling HLock()/HUnlock() is unnecessary.
-
- // Free the retrieved raw data.
- DisposeHandle( hRawBitmapData );
- if (hRawMaskData)
- DisposeHandle( hRawMaskData );
-
- // Return nil if the NSBitmapImageRep didn't give us a buffer to copy into.
- if (pBitmapImageRepBitmapData == NULL)
- return nil;
-
- // Return the new NSBitmapImageRep.
- return bitmapImageRep;
-}
-
-- (NSImage*) imageWithAllReps
-{
- NSImage* image = NULL;
- image = [[[NSImage alloc] initWithData:[NSData dataWithBytes:*hIconFamily length:GetHandleSize((Handle)hIconFamily)]] autorelease];
- return image;
-}
-
-- (BOOL) setIconFamilyElement:(OSType)elementType fromBitmapImageRep:(NSBitmapImageRep*)bitmapImageRep
-{
- Handle hRawData = NULL;
- OSErr result;
-
- switch (elementType) {
- // 'ic08' 512x512 32-bit ARGB image
- case kIconServices512PixelDataARGB:
- hRawData = [IconFamily get32BitDataFromBitmapImageRep:bitmapImageRep requiredPixelSize:512];
- break;
-
- // 'ic08' 256x256 32-bit ARGB image
- case kIconServices256PixelDataARGB:
- hRawData = [IconFamily get32BitDataFromBitmapImageRep:bitmapImageRep requiredPixelSize:256];
- break;
-
- // 'it32' 128x128 32-bit RGB image
- case kThumbnail32BitData:
- hRawData = [IconFamily get32BitDataFromBitmapImageRep:bitmapImageRep requiredPixelSize:128];
- break;
-
- // 't8mk' 128x128 8-bit alpha mask
- case kThumbnail8BitMask:
- hRawData = [IconFamily get8BitMaskFromBitmapImageRep:bitmapImageRep requiredPixelSize:128];
- break;
-
- // 'il32' 32x32 32-bit RGB image
- case kLarge32BitData:
- hRawData = [IconFamily get32BitDataFromBitmapImageRep:bitmapImageRep requiredPixelSize:32];
- break;
-
- // 'l8mk' 32x32 8-bit alpha mask
- case kLarge8BitMask:
- hRawData = [IconFamily get8BitMaskFromBitmapImageRep:bitmapImageRep requiredPixelSize:32];
- break;
-
- // 'ICN#' 32x32 1-bit alpha mask
- case kLarge1BitMask:
- hRawData = [IconFamily get1BitMaskFromBitmapImageRep:bitmapImageRep requiredPixelSize:32];
- break;
-
- // 'icl8' 32x32 8-bit indexed image data
- case kLarge8BitData:
- hRawData = [IconFamily get8BitDataFromBitmapImageRep:bitmapImageRep requiredPixelSize:32];
- break;
-
- // 'is32' 16x16 32-bit RGB image
- case kSmall32BitData:
- hRawData = [IconFamily get32BitDataFromBitmapImageRep:bitmapImageRep requiredPixelSize:16];
- break;
-
- // 's8mk' 16x16 8-bit alpha mask
- case kSmall8BitMask:
- hRawData = [IconFamily get8BitMaskFromBitmapImageRep:bitmapImageRep requiredPixelSize:16];
- break;
-
- // 'ics#' 16x16 1-bit alpha mask
- case kSmall1BitMask:
- hRawData = [IconFamily get1BitMaskFromBitmapImageRep:bitmapImageRep requiredPixelSize:16];
- break;
-
- // 'ics8' 16x16 8-bit indexed image data
- case kSmall8BitData:
- hRawData = [IconFamily get8BitDataFromBitmapImageRep:bitmapImageRep requiredPixelSize:16];
- break;
-
- default:
- return NO;
- }
-
- // NSLog(@"setIconFamilyElement:%@ fromBitmapImageRep:%@ generated handle %p of size %d", NSFileTypeForHFSTypeCode(elementType), bitmapImageRep, hRawData, GetHandleSize(hRawData));
-
- if (hRawData == NULL)
- {
- NSLog(@"Null data returned to setIconFamilyElement:fromBitmapImageRep:");
- return NO;
- }
-
- result = SetIconFamilyData( hIconFamily, elementType, hRawData );
- DisposeHandle( hRawData );
-
- if (result != noErr)
- {
- NSLog(@"SetIconFamilyData() returned error %d", result);
- return NO;
- }
-
- return YES;
-}
-
-#if !defined(DISABLE_CUSTOM_ICON)
-
-- (BOOL) setAsCustomIconForFile:(NSString*)path
-{
- return( [self setAsCustomIconForFile:path withCompatibility:NO] );
-}
-
-- (BOOL) setAsCustomIconForFile:(NSString*)path withCompatibility:(BOOL)compat
-{
- FSRef targetFileFSRef;
- FSRef parentDirectoryFSRef;
- SInt16 file;
- OSStatus result;
- struct FSCatalogInfo catInfo;
- struct FileInfo *finderInfo = (struct FileInfo *)&catInfo.finderInfo;
- Handle hExistingCustomIcon;
- Handle hIconFamilyCopy;
- NSString *parentDirectory;
-
- // Before we do anything, get the original modification time for the target file.
- NSDate* modificationDate = [[[NSFileManager defaultManager] iconfamily_attributesAtPath:path] objectForKey:NSFileModificationDate];
-
- if ([path isAbsolutePath])
- parentDirectory = [path stringByDeletingLastPathComponent];
- else
- parentDirectory = [[[NSFileManager defaultManager] currentDirectoryPath] stringByAppendingPathComponent:[path stringByDeletingLastPathComponent]];
-
- // Get an FSRef for the target file's parent directory that we can use in
- // the FSCreateResFile() and FNNotify() calls below.
- if (![parentDirectory getFSRef:&parentDirectoryFSRef createFileIfNecessary:NO])
- return NO;
-
- // Get the name of the file, for FSCreateResFile.
- struct HFSUniStr255 filename;
- NSString *filenameString = [path lastPathComponent];
- filename.length = [filenameString length];
- [filenameString getCharacters:filename.unicode];
-
- // Make sure the file has a resource fork that we can open. (Although
- // this sounds like it would clobber an existing resource fork, the Carbon
- // Resource Manager docs for this function say that's not the case. If
- // the file already has a resource fork, we receive a result code of
- // dupFNErr, which is not really an error per se, but just a notification
- // to us that creating a new resource fork for the file was not necessary.)
- FSCreateResFile(
- &parentDirectoryFSRef,
- filename.length,
- filename.unicode,
- kFSCatInfoNone,
- /*catalogInfo/*/ NULL,
- &targetFileFSRef,
- /*newSpec*/ NULL);
- result = ResError();
- if (result == dupFNErr) {
- // If the call to FSCreateResFile() returned dupFNErr, targetFileFSRef will not have been set, so create it from the path.
- if (![path getFSRef:&targetFileFSRef createFileIfNecessary:NO])
- return NO;
- } else if (result != noErr) {
- return NO;
- }
-
- // Open the file's resource fork.
- file = FSOpenResFile( &targetFileFSRef, fsRdWrPerm );
- if (file == -1)
- return NO;
-
- // Make a copy of the icon family data to pass to AddResource().
- // (AddResource() takes ownership of the handle we pass in; after the
- // CloseResFile() call its master pointer will be set to 0xffffffff.
- // We want to keep the icon family data, so we make a copy.)
- // HandToHand() returns the handle of the copy in hIconFamily.
- hIconFamilyCopy = (Handle) hIconFamily;
- result = HandToHand( &hIconFamilyCopy );
- if (result != noErr) {
- CloseResFile( file );
- return NO;
- }
-
- // Remove the file's existing kCustomIconResource of type kIconFamilyType
- // (if any).
- hExistingCustomIcon = GetResource( kIconFamilyType, kCustomIconResource );
- if( hExistingCustomIcon )
- RemoveResource( hExistingCustomIcon );
-
- // Now add our icon family as the file's new custom icon.
- AddResource( (Handle)hIconFamilyCopy, kIconFamilyType,
- kCustomIconResource, "\p");
- if (ResError() != noErr) {
- CloseResFile( file );
- return NO;
- }
-
- if( compat )
- {
- [self addResourceType:kLarge8BitData asResID:kCustomIconResource];
- [self addResourceType:kLarge1BitMask asResID:kCustomIconResource];
- [self addResourceType:kSmall8BitData asResID:kCustomIconResource];
- [self addResourceType:kSmall1BitMask asResID:kCustomIconResource];
- }
-
- // Close the file's resource fork, flushing the resource map and new icon
- // data out to disk.
- CloseResFile( file );
- if (ResError() != noErr)
- return NO;
-
- // Prepare to get the Finder info.
-
- // Now we need to set the file's Finder info so the Finder will know that
- // it has a custom icon. Start by getting the file's current finder info:
- result = FSGetCatalogInfo(
- &targetFileFSRef,
- kFSCatInfoFinderInfo,
- &catInfo,
- /*outName*/ NULL,
- /*fsSpec*/ NULL,
- /*parentRef*/ NULL);
- if (result != noErr)
- return NO;
-
- // Set the kHasCustomIcon flag, and clear the kHasBeenInited flag.
- //
- // From Apple's "CustomIcon" code sample:
- // "set bit 10 (has custom icon) and unset the inited flag
- // kHasBeenInited is 0x0100 so the mask will be 0xFEFF:"
- // finderInfo.fdFlags = 0xFEFF & (finderInfo.fdFlags | kHasCustomIcon ) ;
- finderInfo->finderFlags = (finderInfo->finderFlags | kHasCustomIcon ) & ~kHasBeenInited;
-
- // Now write the Finder info back.
- result = FSSetCatalogInfo( &targetFileFSRef, kFSCatInfoFinderInfo, &catInfo );
- if (result != noErr)
- return NO;
-
- // Now set the modification time back to when the file was actually last modified.
- NSDictionary* attributes = [NSDictionary dictionaryWithObjectsAndKeys:modificationDate, NSFileModificationDate, nil];
- [[NSFileManager defaultManager] iconfamily_setAttributes:attributes atPath:path];
-
- // Notify the system that the directory containing the file has changed, to
- // give Finder the chance to find out about the file's new custom icon.
- result = FNNotify( &parentDirectoryFSRef, kFNDirectoryModifiedMessage, kNilOptions );
- if (result != noErr)
- return NO;
-
- return YES;
-}
-
-+ (BOOL) removeCustomIconFromFile:(NSString*)path
-{
- FSRef targetFileFSRef;
- FSRef parentDirectoryFSRef;
- SInt16 file;
- OSStatus result;
- struct FSCatalogInfo catInfo;
- struct FileInfo *finderInfo = (struct FileInfo *)&catInfo.finderInfo;
- Handle hExistingCustomIcon;
-
- // Get an FSRef for the target file.
- if (![path getFSRef:&targetFileFSRef createFileIfNecessary:NO])
- return NO;
-
- // Open the file's resource fork, if it has one.
- file = FSOpenResFile( &targetFileFSRef, fsRdWrPerm );
- if (file == -1)
- return NO;
-
- // Remove the file's existing kCustomIconResource of type kIconFamilyType
- // (if any).
- hExistingCustomIcon = GetResource( kIconFamilyType, kCustomIconResource );
- if( hExistingCustomIcon )
- RemoveResource( hExistingCustomIcon );
-
- // Close the file's resource fork, flushing the resource map out to disk.
- CloseResFile( file );
- if (ResError() != noErr)
- return NO;
-
- // Now we need to set the file's Finder info so the Finder will know that
- // it has no custom icon. Start by getting the file's current Finder info.
- // Also get an FSRef for its parent directory, that we can use in the
- // FNNotify() call below.
- result = FSGetCatalogInfo(
- &targetFileFSRef,
- kFSCatInfoFinderInfo,
- &catInfo,
- /*outName*/ NULL,
- /*fsSpec*/ NULL,
- &parentDirectoryFSRef );
- if (result != noErr)
- return NO;
-
- // Clear the kHasCustomIcon flag and the kHasBeenInited flag.
- finderInfo->finderFlags = finderInfo->finderFlags & ~(kHasCustomIcon | kHasBeenInited);
-
- // Now write the Finder info back.
- result = FSSetCatalogInfo( &targetFileFSRef, kFSCatInfoFinderInfo, &catInfo );
- if (result != noErr)
- return NO;
-
- // Notify the system that the directory containing the file has changed, to give Finder the chance to find out about the file's new custom icon.
- result = FNNotify( &parentDirectoryFSRef, kFNDirectoryModifiedMessage, kNilOptions );
- if (result != noErr)
- return NO;
-
- return YES;
-}
-
-- (BOOL) setAsCustomIconForDirectory:(NSString*)path
-{
- return [self setAsCustomIconForDirectory:path withCompatibility:NO];
-}
-
-- (BOOL) setAsCustomIconForDirectory:(NSString*)path withCompatibility:(BOOL)compat
-{
- NSFileManager *fm = [NSFileManager defaultManager];
- BOOL isDir;
- BOOL exists;
- NSString *iconrPath;
- FSRef targetFolderFSRef, iconrFSRef;
- SInt16 file;
- OSErr result;
- struct HFSUniStr255 filename;
- struct FSCatalogInfo catInfo;
- Handle hExistingCustomIcon;
- Handle hIconFamilyCopy;
-
- // Confirm that "path" exists and specifies a directory.
- exists = [fm fileExistsAtPath:path isDirectory:&isDir];
- if( !isDir || !exists )
- return NO;
-
- // Get an FSRef for the folder.
- if( ![path getFSRef:&targetFolderFSRef createFileIfNecessary:NO] )
- return NO;
-
- // Remove and re-create any existing "Icon\r" file in the directory, and get an FSRef for it.
- iconrPath = [path stringByAppendingPathComponent:@"Icon\r"];
- if( [fm fileExistsAtPath:iconrPath] )
- {
- if( ![fm iconfamily_removeItemAtPath:iconrPath] )
- return NO;
- }
- if( ![iconrPath getFSRef:&iconrFSRef createFileIfNecessary:YES] )
- return NO;
-
- // Get type and creator information for the Icon file.
- result = FSGetCatalogInfo(
- &iconrFSRef,
- kFSCatInfoFinderInfo,
- &catInfo,
- /*outName*/ NULL,
- /*fsSpec*/ NULL,
- /*parentRef*/ NULL );
- // This shouldn't fail because we just created the file above.
- if( result != noErr )
- return NO;
- else {
- // The file doesn't exist. Prepare to create it.
- struct FileInfo *finderInfo = (struct FileInfo *)catInfo.finderInfo;
-
- // These are the file type and creator given to Icon files created by
- // the Finder.
- finderInfo->fileType = 'icon';
- finderInfo->fileCreator = 'MACS';
-
- // Icon files should be invisible.
- finderInfo->finderFlags = kIsInvisible;
-
- // Because the inited flag is not set in finderFlags above, the Finder
- // will ignore the location, unless it's in the 'magic rectangle' of
- // { -24,000, -24,000, -16,000, -16,000 } (technote TB42).
- // So we need to make sure to set this to zero anyway, so that the
- // Finder will position it automatically. If the user makes the Icon
- // file visible for any reason, we don't want it to be positioned in an
- // exotic corner of the window.
- finderInfo->location.h = finderInfo->location.v = 0;
-
- // Standard reserved-field practice.
- finderInfo->reservedField = 0;
-
- // Update the catalog info:
- result = FSSetCatalogInfo(&iconrFSRef, kFSCatInfoFinderInfo, &catInfo);
-
- if (result != noErr)
- return NO;
- }
-
- // Get the filename, to be applied to the Icon file.
- filename.length = [@"Icon\r" length];
- [@"Icon\r" getCharacters:filename.unicode];
-
- // Make sure the file has a resource fork that we can open. (Although
- // this sounds like it would clobber an existing resource fork, the Carbon
- // Resource Manager docs for this function say that's not the case.)
- FSCreateResFile(
- &targetFolderFSRef,
- filename.length,
- filename.unicode,
- kFSCatInfoFinderInfo,
- &catInfo,
- &iconrFSRef,
- /*newSpec*/ NULL);
- result = ResError();
- if (!(result == noErr || result == dupFNErr))
- return NO;
-
- // Open the file's resource fork.
- file = FSOpenResFile( &iconrFSRef, fsRdWrPerm );
- if (file == -1)
- return NO;
-
- // Make a copy of the icon family data to pass to AddResource().
- // (AddResource() takes ownership of the handle we pass in; after the
- // CloseResFile() call its master pointer will be set to 0xffffffff.
- // We want to keep the icon family data, so we make a copy.)
- // HandToHand() returns the handle of the copy in hIconFamily.
- hIconFamilyCopy = (Handle) hIconFamily;
- result = HandToHand( &hIconFamilyCopy );
- if (result != noErr) {
- CloseResFile( file );
- return NO;
- }
-
- // Remove the file's existing kCustomIconResource of type kIconFamilyType
- // (if any).
- hExistingCustomIcon = GetResource( kIconFamilyType, kCustomIconResource );
- if( hExistingCustomIcon )
- RemoveResource( hExistingCustomIcon );
-
- // Now add our icon family as the file's new custom icon.
- AddResource( (Handle)hIconFamilyCopy, kIconFamilyType,
- kCustomIconResource, "\p");
-
- if (ResError() != noErr) {
- CloseResFile( file );
- return NO;
- }
-
- if( compat )
- {
- [self addResourceType:kLarge8BitData asResID:kCustomIconResource];
- [self addResourceType:kLarge1BitMask asResID:kCustomIconResource];
- [self addResourceType:kSmall8BitData asResID:kCustomIconResource];
- [self addResourceType:kSmall1BitMask asResID:kCustomIconResource];
- }
-
- // Close the file's resource fork, flushing the resource map and new icon
- // data out to disk.
- CloseResFile( file );
- if (ResError() != noErr)
- return NO;
-
- result = FSGetCatalogInfo( &targetFolderFSRef,
- kFSCatInfoFinderInfo,
- &catInfo,
- /*outName*/ NULL,
- /*fsSpec*/ NULL,
- /*parentRef*/ NULL);
- if( result != noErr )
- return NO;
-
- // Tell the Finder that the folder now has a custom icon.
- ((struct FolderInfo *)catInfo.finderInfo)->finderFlags = ( ((struct FolderInfo *)catInfo.finderInfo)->finderFlags | kHasCustomIcon ) & ~kHasBeenInited;
-
- result = FSSetCatalogInfo( &targetFolderFSRef,
- kFSCatInfoFinderInfo,
- &catInfo);
- if( result != noErr )
- return NO;
-
- // Notify the system that the target directory has changed, to give Finder
- // the chance to find out about its new custom icon.
- result = FNNotify( &targetFolderFSRef, kFNDirectoryModifiedMessage, kNilOptions );
- if (result != noErr)
- return NO;
-
- return YES;
-}
-
-+ (BOOL) removeCustomIconFromDirectory:(NSString*)path
-{
- FSRef targetFolderFSRef;
- if( [path getFSRef:&targetFolderFSRef createFileIfNecessary:NO] ) {
- OSStatus result;
- struct FSCatalogInfo catInfo;
- struct FileInfo *finderInfo = (struct FileInfo *)catInfo.finderInfo;
-
- result = FSGetCatalogInfo( &targetFolderFSRef,
- kFSCatInfoFinderInfo,
- &catInfo,
- /*outName*/ NULL,
- /*fsSpec*/ NULL,
- /*parentRef*/ NULL);
- if( result != noErr )
- return NO;
-
- // Tell the Finder that the folder no longer has a custom icon.
- finderInfo->finderFlags &= ~( kHasCustomIcon | kHasBeenInited );
-
- result = FSSetCatalogInfo( &targetFolderFSRef,
- kFSCatInfoFinderInfo,
- &catInfo);
- if( result != noErr )
- return NO;
-
- // Notify the system that the target directory has changed, to give Finder
- // the chance to find out about its new custom icon.
- result = FNNotify( &targetFolderFSRef, kFNDirectoryModifiedMessage, kNilOptions );
- if (result != noErr)
- return NO;
- }
-
- if( ! [[NSFileManager defaultManager] iconfamily_removeItemAtPath:[path stringByAppendingPathComponent:@"Icon\r"]] )
- return NO;
-
- return YES;
-}
-
-#endif // !defined(DISABLE_CUSTOM_ICON)
-
-- (NSData *) data
-{
- return [NSData dataWithBytes:*hIconFamily length:GetHandleSize((Handle)hIconFamily)];
-}
-
-- (BOOL) writeToFile:(NSString*)path
-{
- return [[self data] writeToFile:path atomically:NO];
-}
-
-@end
-
-@implementation IconFamily (Internals)
-
-+ (NSImage*) resampleImage:(NSImage*)image toIconWidth:(int)iconWidth usingImageInterpolation:(NSImageInterpolation)imageInterpolation
-{
- NSGraphicsContext* graphicsContext;
- BOOL wasAntialiasing;
- NSImageInterpolation previousImageInterpolation;
- NSImage* newImage;
- NSImage* workingImage;
- NSImageRep* workingImageRep;
- NSSize size, pixelSize, newSize;
- NSRect iconRect;
- NSRect targetRect;
-
- // Create a working copy of the image and scale its size down to fit in
- // the square area of the icon.
- //
- // It seems like there should be a more memory-efficient alternative to
- // first duplicating the entire original image, but I don't know what it
- // is. We need to change some properties ("size" and "scalesWhenResized")
- // of the original image, but we shouldn't change the original, so a copy
- // is necessary.
- workingImage = [image copyWithZone:[image zone]];
- [workingImage setScalesWhenResized:YES];
- size = [workingImage size];
- workingImageRep = [workingImage iconfamily_bestRepresentation];
- if ([workingImageRep isKindOfClass:[NSBitmapImageRep class]]) {
- pixelSize.width = [workingImageRep pixelsWide];
- pixelSize.height = [workingImageRep pixelsHigh];
- if (!NSEqualSizes( size, pixelSize )) {
- [workingImage setSize:pixelSize];
- [workingImageRep setSize:pixelSize];
- size = pixelSize;
- }
- }
- if (size.width >= size.height) {
- newSize.width = iconWidth;
- newSize.height = (float)floor( iconWidth * size.height / size.width + 0.5 );
- } else {
- newSize.height = iconWidth;
- newSize.width = (float)floor( iconWidth * size.width / size.height + 0.5 );
- }
- [workingImage setSize:newSize];
-
- // Create a new image the size of the icon, and clear it to transparent.
- newImage = [[NSImage alloc] initWithSize:NSMakeSize(iconWidth,iconWidth)];
- [newImage lockFocus];
- iconRect.origin.x = iconRect.origin.y = 0;
- iconRect.size.width = iconRect.size.height = iconWidth;
- [[NSColor clearColor] set];
- NSRectFill( iconRect );
-
- // Set current graphics context to use antialiasing and high-quality
- // image scaling.
- graphicsContext = [NSGraphicsContext currentContext];
- wasAntialiasing = [graphicsContext shouldAntialias];
- previousImageInterpolation = [graphicsContext imageInterpolation];
- [graphicsContext setShouldAntialias:YES];
- [graphicsContext setImageInterpolation:imageInterpolation];
-
- // Composite the working image into the icon bitmap, centered.
- targetRect.origin.x = ((float)iconWidth - newSize.width ) / 2.0f;
- targetRect.origin.y = ((float)iconWidth - newSize.height) / 2.0f;
- targetRect.size.width = newSize.width;
- targetRect.size.height = newSize.height;
- [workingImageRep drawInRect:targetRect];
-
- // Restore previous graphics context settings.
- [graphicsContext setShouldAntialias:wasAntialiasing];
- [graphicsContext setImageInterpolation:previousImageInterpolation];
-
- [newImage unlockFocus];
-
- [workingImage release];
-
- // Return the new image!
- return [newImage autorelease];
-}
-
-void GetRGBAFrom32BitSource(unsigned char src1, unsigned char src2, unsigned char src3, unsigned char src4,
- unsigned char* redOut, unsigned char* greenOut, unsigned char* blueOut, unsigned char* alphaOut,
- bool isAlphaFirst, bool isAlphaPremultiplied) {
- unsigned char r, g, b, a;
- if (isAlphaFirst) {
- a = src1;
- r = src2;
- g = src3;
- b = src4;
- } else {
- r = src1;
- g = src2;
- b = src3;
- a = src4;
- }
-
- if (isAlphaPremultiplied) {
- // The RGB values are premultiplied by the alpha (so that
- // Quartz can save time when compositing the bitmap to a
- // destination), and we undo this premultiplication (with some
- // lossiness unfortunately) when retrieving the bitmap data.
- float oneOverAlpha = 255.0f / (float)a;
- r = r * oneOverAlpha;
- g = g * oneOverAlpha;
- b = b * oneOverAlpha;
- }
-
- if (redOut)
- *redOut = r;
- if (greenOut)
- *greenOut = g;
- if (blueOut)
- *blueOut = b;
- if (alphaOut)
- *alphaOut = a;
-}
-
-+ (Handle) get32BitDataFromBitmapImageRep:(NSBitmapImageRep*)bitmapImageRep requiredPixelSize:(int)requiredPixelSize
-{
- Handle hRawData;
- unsigned char* pRawData;
- Size rawDataSize;
- unsigned char* pSrc;
- unsigned char* pDest;
- int x, y;
-
- // Get information about the bitmapImageRep.
- long pixelsWide = [bitmapImageRep pixelsWide];
- long pixelsHigh = [bitmapImageRep pixelsHigh];
- long bitsPerSample = [bitmapImageRep bitsPerSample];
- long samplesPerPixel = [bitmapImageRep samplesPerPixel];
- long bitsPerPixel = [bitmapImageRep bitsPerPixel];
- BOOL isPlanar = [bitmapImageRep isPlanar];
- long bytesPerRow = [bitmapImageRep bytesPerRow];
- unsigned char* bitmapData = [bitmapImageRep bitmapData];
- BOOL isAlphaFirst = [bitmapImageRep bitmapFormat] & NSAlphaFirstBitmapFormat;
- BOOL isAlphaPremultiplied = !([bitmapImageRep bitmapFormat] & NSAlphaNonpremultipliedBitmapFormat);
-
- // Make sure bitmap has the required dimensions.
- if (pixelsWide != requiredPixelSize || pixelsHigh != requiredPixelSize)
- return NULL;
-
- // So far, this code only handles non-planar 32-bit RGBA and 24-bit RGB source bitmaps.
- // This could be made more flexible with some additional programming to accommodate other possible
- // formats...
- if (isPlanar)
- {
- NSLog(@"get32BitDataFromBitmapImageRep:requiredPixelSize: returning NULL due to isPlanar == YES");
- return NULL;
- }
- if (bitsPerSample != 8)
- {
- NSLog(@"get32BitDataFromBitmapImageRep:requiredPixelSize: returning NULL due to bitsPerSample == %ld", bitsPerSample);
- return NULL;
- }
-
- if (((samplesPerPixel == 3) && (bitsPerPixel == 24)) || ((samplesPerPixel == 4) && (bitsPerPixel == 32)))
- {
- rawDataSize = pixelsWide * pixelsHigh * 4;
- hRawData = NewHandle( rawDataSize );
- if (hRawData == NULL)
- return NULL;
- pRawData = (unsigned char*) *hRawData;
-
- pDest = pRawData;
-
- if (bitsPerPixel == 32) {
- for (y = 0; y < pixelsHigh; y++) {
- pSrc = bitmapData + y * bytesPerRow;
- for (x = 0; x < pixelsWide; x++) {
- unsigned char r, g, b, a;
- GetRGBAFrom32BitSource(pSrc[0], pSrc[1], pSrc[2], pSrc[3],
- &r, &g, &b, &a, isAlphaFirst, isAlphaPremultiplied);
- *pDest++ = a;
- *pDest++ = r;
- *pDest++ = g;
- *pDest++ = b;
- pSrc += 4;
- }
- }
- } else if (bitsPerPixel == 24) {
- for (y = 0; y < pixelsHigh; y++) {
- pSrc = bitmapData + y * bytesPerRow;
- for (x = 0; x < pixelsWide; x++) {
- *pDest++ = 0xFF;
- *pDest++ = *pSrc++;
- *pDest++ = *pSrc++;
- *pDest++ = *pSrc++;
- }
- }
- }
- }
- else
- {
- NSLog(@"get32BitDataFromBitmapImageRep:requiredPixelSize: returning NULL due to samplesPerPixel == %ld, bitsPerPixel == %ld", samplesPerPixel, bitsPerPixel);
- return NULL;
- }
-
- return hRawData;
-}
-
-+ (Handle) get8BitDataFromBitmapImageRep:(NSBitmapImageRep*)bitmapImageRep requiredPixelSize:(int)requiredPixelSize
-{
- Handle hRawData;
- unsigned char* pRawData;
- Size rawDataSize;
- unsigned char* pSrc;
- unsigned char* pDest;
- int x, y;
-
- // Get information about the bitmapImageRep.
- long pixelsWide = [bitmapImageRep pixelsWide];
- long pixelsHigh = [bitmapImageRep pixelsHigh];
- long bitsPerSample = [bitmapImageRep bitsPerSample];
- long samplesPerPixel = [bitmapImageRep samplesPerPixel];
- long bitsPerPixel = [bitmapImageRep bitsPerPixel];
- BOOL isPlanar = [bitmapImageRep isPlanar];
- long bytesPerRow = [bitmapImageRep bytesPerRow];
- unsigned char* bitmapData = [bitmapImageRep bitmapData];
- BOOL isAlphaFirst = [bitmapImageRep bitmapFormat] & NSAlphaFirstBitmapFormat;
- BOOL isAlphaPremultiplied = !([bitmapImageRep bitmapFormat] & NSAlphaNonpremultipliedBitmapFormat);
-
- // Make sure bitmap has the required dimensions.
- if (pixelsWide != requiredPixelSize || pixelsHigh != requiredPixelSize)
- return NULL;
-
- // So far, this code only handles non-planar 32-bit RGBA and 24-bit RGB source bitmaps.
- // This could be made more flexible with some additional programming...
- if (isPlanar)
- {
- NSLog(@"get8BitDataFromBitmapImageRep:requiredPixelSize: returning NULL due to isPlanar == YES");
- return NULL;
- }
- if (bitsPerSample != 8)
- {
- NSLog(@"get8BitDataFromBitmapImageRep:requiredPixelSize: returning NULL due to bitsPerSample == %ld", bitsPerSample);
- return NULL;
- }
-
- if (((samplesPerPixel == 3) && (bitsPerPixel == 24)) || ((samplesPerPixel == 4) && (bitsPerPixel == 32)))
- {
- CGDirectPaletteRef cgPal;
- CGDeviceColor cgCol;
-
- rawDataSize = pixelsWide * pixelsHigh;
- hRawData = NewHandle( rawDataSize );
- if (hRawData == NULL)
- return NULL;
- pRawData = (unsigned char*) *hRawData;
-
- cgPal = CGPaletteCreateDefaultColorPalette();
-
- pDest = pRawData;
- if (bitsPerPixel == 32) {
- for (y = 0; y < pixelsHigh; y++) {
- pSrc = bitmapData + y * bytesPerRow;
- for (x = 0; x < pixelsWide; x++) {
- unsigned char r, g, b;
- GetRGBAFrom32BitSource(pSrc[0], pSrc[1], pSrc[2], pSrc[3],
- &r, &g, &b, NULL, isAlphaFirst, isAlphaPremultiplied);
- cgCol.red = (float)r / 255;
- cgCol.green = (float)g / 255;
- cgCol.blue = (float)b / 255;
-
- *pDest++ = CGPaletteGetIndexForColor(cgPal, cgCol);
-
- pSrc+=4;
- }
- }
- } else if (bitsPerPixel == 24) {
- for (y = 0; y < pixelsHigh; y++) {
- pSrc = bitmapData + y * bytesPerRow;
- for (x = 0; x < pixelsWide; x++) {
- cgCol.red = ((float)*(pSrc)) / 255;
- cgCol.green = ((float)*(pSrc+1)) / 255;
- cgCol.blue = ((float)*(pSrc+2)) / 255;
-
- *pDest++ = CGPaletteGetIndexForColor(cgPal, cgCol);
-
- pSrc+=3;
- }
- }
- }
-
- CGPaletteRelease(cgPal);
- }
- else
- {
- NSLog(@"get8BitDataFromBitmapImageRep:requiredPixelSize: returning NULL due to samplesPerPixel == %ld, bitsPerPixel == %ld", samplesPerPixel, bitsPerPixel);
- return NULL;
- }
-
- return hRawData;
-}
-
-+ (Handle) get8BitMaskFromBitmapImageRep:(NSBitmapImageRep*)bitmapImageRep requiredPixelSize:(int)requiredPixelSize
-{
- Handle hRawData;
- unsigned char* pRawData;
- Size rawDataSize;
- unsigned char* pSrc;
- unsigned char* pDest;
- int x, y;
-
- // Get information about the bitmapImageRep.
- long pixelsWide = [bitmapImageRep pixelsWide];
- long pixelsHigh = [bitmapImageRep pixelsHigh];
- long bitsPerSample = [bitmapImageRep bitsPerSample];
- long samplesPerPixel = [bitmapImageRep samplesPerPixel];
- long bitsPerPixel = [bitmapImageRep bitsPerPixel];
- BOOL isPlanar = [bitmapImageRep isPlanar];
- long bytesPerRow = [bitmapImageRep bytesPerRow];
- unsigned char* bitmapData = [bitmapImageRep bitmapData];
- BOOL isAlphaFirst = [bitmapImageRep bitmapFormat] & NSAlphaFirstBitmapFormat;
- BOOL isAlphaPremultiplied = !([bitmapImageRep bitmapFormat] & NSAlphaNonpremultipliedBitmapFormat);
-
- // Make sure bitmap has the required dimensions.
- if (pixelsWide != requiredPixelSize || pixelsHigh != requiredPixelSize)
- return NULL;
-
- // So far, this code only handles non-planar 32-bit RGBA, 24-bit RGB and 8-bit grayscale source bitmaps.
- // This could be made more flexible with some additional programming...
- if (isPlanar)
- {
- NSLog(@"get8BitMaskFromBitmapImageRep:requiredPixelSize: returning NULL due to isPlanar == YES");
- return NULL;
- }
- if (bitsPerSample != 8)
- {
- NSLog(@"get8BitMaskFromBitmapImageRep:requiredPixelSize: returning NULL due to bitsPerSample == %ld", bitsPerSample);
- return NULL;
- }
-
- if (((samplesPerPixel == 1) && (bitsPerPixel == 8)) || ((samplesPerPixel == 3) && (bitsPerPixel == 24)) || ((samplesPerPixel == 4) && (bitsPerPixel == 32)))
- {
- rawDataSize = pixelsWide * pixelsHigh;
- hRawData = NewHandle( rawDataSize );
- if (hRawData == NULL)
- return NULL;
- pRawData = (unsigned char*) *hRawData;
-
- pSrc = bitmapData;
- pDest = pRawData;
-
- if (bitsPerPixel == 32) {
- for (y = 0; y < pixelsHigh; y++) {
- pSrc = bitmapData + y * bytesPerRow;
- for (x = 0; x < pixelsWide; x++) {
- unsigned char a;
- GetRGBAFrom32BitSource(pSrc[0], pSrc[1], pSrc[2], pSrc[3],
- NULL, NULL, NULL, &a, isAlphaFirst, isAlphaPremultiplied);
- *pDest++ = a;
- pSrc += 4;
- }
- }
- }
- else if (bitsPerPixel == 24) {
- memset( pDest, 255, rawDataSize );
- }
- else if (bitsPerPixel == 8) {
- for (y = 0; y < pixelsHigh; y++) {
- memcpy( pDest, pSrc, pixelsWide );
- pSrc += bytesPerRow;
- pDest += pixelsWide;
- }
- }
- }
- else
- {
- NSLog(@"get8BitMaskFromBitmapImageRep:requiredPixelSize: returning NULL due to samplesPerPixel == %ld, bitsPerPixel == %ld", samplesPerPixel, bitsPerPixel);
- return NULL;
- }
-
- return hRawData;
-}
-
-// NOTE: This method hasn't been fully tested yet.
-+ (Handle) get1BitMaskFromBitmapImageRep:(NSBitmapImageRep*)bitmapImageRep requiredPixelSize:(int)requiredPixelSize
-{
- Handle hRawData;
- unsigned char* pRawData;
- Size rawDataSize;
- unsigned char* pSrc;
- unsigned char* pDest;
- int x, y;
- unsigned char maskByte;
-
- // Get information about the bitmapImageRep.
- long pixelsWide = [bitmapImageRep pixelsWide];
- long pixelsHigh = [bitmapImageRep pixelsHigh];
- long bitsPerSample = [bitmapImageRep bitsPerSample];
- long samplesPerPixel = [bitmapImageRep samplesPerPixel];
- long bitsPerPixel = [bitmapImageRep bitsPerPixel];
- BOOL isPlanar = [bitmapImageRep isPlanar];
- long bytesPerRow = [bitmapImageRep bytesPerRow];
- unsigned char* bitmapData = [bitmapImageRep bitmapData];
- BOOL isAlphaFirst = [bitmapImageRep bitmapFormat] & NSAlphaFirstBitmapFormat;
- BOOL isAlphaPremultiplied = !([bitmapImageRep bitmapFormat] & NSAlphaNonpremultipliedBitmapFormat);
-
- // Make sure bitmap has the required dimensions.
- if (pixelsWide != requiredPixelSize || pixelsHigh != requiredPixelSize)
- return NULL;
-
- // So far, this code only handles non-planar 32-bit RGBA, 24-bit RGB, 8-bit grayscale, and 1-bit source bitmaps.
- // This could be made more flexible with some additional programming...
- if (isPlanar)
- {
- NSLog(@"get1BitMaskFromBitmapImageRep:requiredPixelSize: returning NULL due to isPlanar == YES");
- return NULL;
- }
-
- if (((bitsPerPixel == 1) && (samplesPerPixel == 1) && (bitsPerSample == 1)) || ((bitsPerPixel == 8) && (samplesPerPixel == 1) && (bitsPerSample == 8)) ||
- ((bitsPerPixel == 24) && (samplesPerPixel == 3) && (bitsPerSample == 8)) || ((bitsPerPixel == 32) && (samplesPerPixel == 4) && (bitsPerSample == 8)))
- {
- rawDataSize = (pixelsWide * pixelsHigh)/4;
- hRawData = NewHandle( rawDataSize );
- if (hRawData == NULL)
- return NULL;
- pRawData = (unsigned char*) *hRawData;
-
- pSrc = bitmapData;
- pDest = pRawData;
-
- if (bitsPerPixel == 32) {
- for (y = 0; y < pixelsHigh; y++) {
- pSrc = bitmapData + y * bytesPerRow;
- for (x = 0; x < pixelsWide; x += 8) {
- maskByte = 0;
- for (int i = 7; i >= 0; i--) {
- unsigned char a;
- GetRGBAFrom32BitSource(pSrc[0], pSrc[1], pSrc[2], pSrc[3],
- NULL, NULL, NULL, &a, isAlphaFirst, isAlphaPremultiplied);
- if (a)
- maskByte |= 1 << i;
- pSrc += 4;
- }
- *pDest++ = maskByte;
- }
- }
- }
- else if (bitsPerPixel == 24) {
- memset( pDest, 255, rawDataSize );
- }
- else if (bitsPerPixel == 8) {
- for (y = 0; y < pixelsHigh; y++) {
- pSrc = bitmapData + y * bytesPerRow;
- for (x = 0; x < pixelsWide; x += 8) {
- maskByte = 0;
- maskByte |= *pSrc++ ? 0x80 : 0;
- maskByte |= *pSrc++ ? 0x40 : 0;
- maskByte |= *pSrc++ ? 0x20 : 0;
- maskByte |= *pSrc++ ? 0x10 : 0;
- maskByte |= *pSrc++ ? 0x08 : 0;
- maskByte |= *pSrc++ ? 0x04 : 0;
- maskByte |= *pSrc++ ? 0x02 : 0;
- maskByte |= *pSrc++ ? 0x01 : 0;
- *pDest++ = maskByte;
- }
- }
- }
- else if (bitsPerPixel == 1) {
- for (y = 0; y < pixelsHigh; y++) {
- memcpy( pDest, pSrc, pixelsWide / 8 );
- pDest += pixelsWide / 8;
- pSrc += bytesPerRow;
- }
- }
-
- memcpy( pRawData+(pixelsWide*pixelsHigh)/8, pRawData, (pixelsWide*pixelsHigh)/8 );
- }
- else
- {
- NSLog(@"get1BitMaskFromBitmapImageRep:requiredPixelSize: returning NULL due to bitsPerPixel == %ld, samplesPerPixel== %ld, bitsPerSample == %ld", bitsPerPixel, samplesPerPixel, bitsPerSample);
- return NULL;
- }
-
- return hRawData;
-}
-
-#if !defined(DISABLE_CUSTOM_ICON)
-
-- (BOOL) addResourceType:(OSType)type asResID:(int)resID
-{
- Handle hIconRes = NewHandle(0);
- OSErr err;
-
- err = GetIconFamilyData( hIconFamily, type, hIconRes );
-
- if( !GetHandleSize(hIconRes) || err != noErr )
- return NO;
-
- AddResource( hIconRes, type, resID, "\p" );
-
- return YES;
-}
-
-#endif // !defined(DISABLE_CUSTOM_ICON)
-
-@end
-
-// Methods for interfacing with the Cocoa Pasteboard.
-
-@implementation IconFamily (ScrapAdditions)
-
-+ (BOOL) canInitWithScrap
-{
- NSArray *types = [[NSPasteboard generalPasteboard] types];
- return [types containsObject:ICONFAMILY_UTI] || [types containsObject:ICONFAMILY_PBOARD_TYPE];
-}
-
-+ (IconFamily*) iconFamilyWithScrap
-{
- return [[[IconFamily alloc] initWithScrap] autorelease];
-}
-
-- (id) initWithScrap
-{
- NSPasteboard *pboard = [NSPasteboard generalPasteboard];
-
- NSData *data = [pboard dataForType:ICONFAMILY_UTI];
- if( !data )
- data = [pboard dataForType:ICONFAMILY_PBOARD_TYPE];
- if( !data )
- {
- [self release];
- return nil;
- }
-
- self = [self initWithData:data];
-
- return self;
-}
-
-- (BOOL) putOnScrap
-{
- NSPasteboard *pboard = [NSPasteboard generalPasteboard];
-
- [pboard declareTypes:[NSArray arrayWithObjects:ICONFAMILY_UTI, ICONFAMILY_PBOARD_TYPE, nil] owner:self];
- NSData *data = [self data];
- [pboard setData:data forType:ICONFAMILY_UTI];
- [pboard setData:data forType:ICONFAMILY_PBOARD_TYPE];
-
- return YES;
-}
-
-@end
-
-
-@implementation NSFileManager (IconFamilyCompatibility)
-
-- (NSDictionary *) iconfamily_attributesAtPath:(NSString *)path
-{
-#if MAC_OS_X_VERSION_MIN_REQUIRED < 1050
- if ([!self respondsToSelector:@selector(attributesOfItemAtPath:error:)])
- {
- return [self fileAttributesAtPath:path traverseLink:NO];
- }
-#endif
-
- return [self attributesOfItemAtPath:path error:NULL];
-}
-
-
-- (BOOL) iconfamily_setAttributes:(NSDictionary *)attributes atPath:(NSString *)path
-{
-#if MAC_OS_X_VERSION_MIN_REQUIRED < 1050
- if ([!self respondsToSelector:@selector(setAttributes:ofItemAtPath:error:)])
- {
- return [self changeFileAttributes:attributes atPath:path];
- }
-#endif
-
- return [self setAttributes:attributes ofItemAtPath:path error:NULL];
-}
-
-
-- (BOOL) iconfamily_removeItemAtPath:(NSString *)path
-{
-#if MAC_OS_X_VERSION_MIN_REQUIRED < 1050
- if ([!self respondsToSelector:@selector(removeItemAtPath:error:)])
- {
- return [self removeFileAtPath:path handler:nil];
- }
-#endif
-
- return [self removeItemAtPath:path error:NULL];
-}
-
-@end
-
-
-@implementation NSImage (IconFamilyCompatibility)
-
-- (NSImageRep *) iconfamily_bestRepresentation
-{
-#if MAC_OS_X_VERSION_MIN_REQUIRED < 1060
- if (![self respondsToSelector:@selector(bestRepresentationForRect:context:hints:)])
- {
- return [self bestRepresentationForDevice:nil];
- }
-#endif
-
- return [self bestRepresentationForRect:(NSRect){NSZeroPoint, [self size]} context:nil hints:nil];
-}
-
-@end
diff --git a/third_party/icon_family/LICENSE b/third_party/icon_family/LICENSE
deleted file mode 100644
index 236a4fa..0000000
--- a/third_party/icon_family/LICENSE
+++ /dev/null
@@ -1,10 +0,0 @@
-Copyright (c) 2001-2010 Troy N. Stephens
-Portions Copyright (c) 2007 Google Inc.
-
-Use and distribution of this source code is governed by the MIT License, whose terms are as follows.
-
-Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
-
-The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
-
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
diff --git a/third_party/icon_family/NSString+CarbonFSRefCreation.h b/third_party/icon_family/NSString+CarbonFSRefCreation.h
deleted file mode 100644
index fa96e69..0000000
--- a/third_party/icon_family/NSString+CarbonFSRefCreation.h
+++ /dev/null
@@ -1,25 +0,0 @@
-/*
- Copyright (c) 2001-2010 Troy N. Stephens
-
- Use and distribution of this source code is governed by the MIT License, whose terms are as follows.
-
- Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
-
- The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
-
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
-*/
-
-#import <Foundation/Foundation.h>
-#import <Carbon/Carbon.h>
-
-@interface NSString (CarbonFSRefCreation)
-
-// Fills in the given FSRef struct so it specifies the file whose path is in this string.
-// If the file doesn't exist, and "createFile" is YES, this method will attempt to create
-// an empty file with the specified path. (The caller should insure that the directory
-// the file is to be placed in already exists.)
-
-- (BOOL) getFSRef:(FSRef*)fsRef createFileIfNecessary:(BOOL)createFile;
-
-@end
diff --git a/third_party/icon_family/NSString+CarbonFSRefCreation.m b/third_party/icon_family/NSString+CarbonFSRefCreation.m
deleted file mode 100644
index fb86c52..0000000
--- a/third_party/icon_family/NSString+CarbonFSRefCreation.m
+++ /dev/null
@@ -1,58 +0,0 @@
-/*
- Copyright (c) 2001-2010 Troy N. Stephens
-
- Use and distribution of this source code is governed by the MIT License, whose terms are as follows.
-
- Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
-
- The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
-
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
-*/
-
-#import "NSString+CarbonFSRefCreation.h"
-
-@implementation NSString (CarbonFSRefCreation)
-
-- (BOOL) getFSRef:(FSRef*)fsRef createFileIfNecessary:(BOOL)createFile
-{
- NSFileManager* fileManager = [NSFileManager defaultManager];
- CFURLRef urlRef;
- Boolean gotFSRef;
-
- // Check whether the file exists already. If not, create an empty file if requested.
- if (![fileManager fileExistsAtPath:self]) {
- if (createFile) {
- if (![(NSData*)[NSData data] writeToFile:self atomically:YES]) {
- return NO;
- }
- } else {
- return NO;
- }
- }
-
- // Create a CFURL with the specified POSIX path.
- urlRef = CFURLCreateWithFileSystemPath( kCFAllocatorDefault,
- (CFStringRef) self,
- kCFURLPOSIXPathStyle,
- FALSE /* isDirectory */ );
- if (urlRef == NULL) {
-// printf( "** Couldn't make a CFURLRef for the file.\n" );
- return NO;
- }
-
- // Try to create an FSRef from the URL. (If the specified file doesn't exist, this
- // function will return false, but if we've reached this code we've already insured
- // that the file exists.)
- gotFSRef = CFURLGetFSRef( urlRef, fsRef );
- CFRelease( urlRef );
-
- if (!gotFSRef) {
-// printf( "** Couldn't get an FSRef for the file.\n" );
- return NO;
- }
-
- return YES;
-}
-
-@end
diff --git a/third_party/icon_family/README.chromium b/third_party/icon_family/README.chromium
deleted file mode 100644
index fe3473f..0000000
--- a/third_party/icon_family/README.chromium
+++ /dev/null
@@ -1,15 +0,0 @@
-Name: icon_family
-Short Name: IconFamily
-URL: http://iconfamily.sourceforge.net/
-Version: 0
-Date: 07/21/2010
-Revision: 46
-License: MIT
-Security Critical: Yes
-
-Description:
-This is an Objective-C wrapper around Mac OS X Icon Services' "IconFamily" data type. This is used to create .icns files for Web Apps installed from the browser.
-
-Local Modifications:
-chromium_icon_family.patch: Fix minor erors and warnings. Put code that the custom icon code behind a DISABLE_CUSTOM_ICON flag.
-chromium_icon_family_2.patch: Add support for alpha first and non-premultiplied image formats. Patch submitted to project page: https://sourceforge.net/tracker/?func=detail&aid=3491306&group_id=164783&atid=833111
diff --git a/third_party/icon_family/chromium_icon_family.patch b/third_party/icon_family/chromium_icon_family.patch
deleted file mode 100644
index 00dde8a..0000000
--- a/third_party/icon_family/chromium_icon_family.patch
+++ /dev/null
@@ -1,222 +0,0 @@
-diff --git a/third_party/icon_family/IconFamily.h b/third_party/icon_family/IconFamily.h
-index 6a6049f..63f6bb7 100644
---- a/third_party/icon_family/IconFamily.h
-+++ b/third_party/icon_family/IconFamily.h
-@@ -57,24 +57,24 @@
- // Initializes as a new, empty IconFamily. This is IconFamily's designated
- // initializer method.
-
--- init;
-+- (id) init;
-
- // Initializes an IconFamily by loading the contents of an .icns file.
-
--- initWithContentsOfFile:(NSString*)path;
-+- (id) initWithContentsOfFile:(NSString*)path;
-
- // Initializes an IconFamily from an existing Carbon IconFamilyHandle.
-
--- initWithIconFamilyHandle:(IconFamilyHandle)hNewIconFamily;
-+- (id) initWithIconFamilyHandle:(IconFamilyHandle)hNewIconFamily;
-
- // Initializes an IconFamily by loading the Finder icon that's assigned to a
- // file.
-
--- initWithIconOfFile:(NSString*)path;
-+- (id) initWithIconOfFile:(NSString*)path;
-
- // Initializes an IconFamily by referencing a standard system icon.
-
--- initWithSystemIcon:(int)fourByteCode;
-+- (id) initWithSystemIcon:(int)fourByteCode;
-
- // Initializes an IconFamily by creating its elements from a resampled
- // NSImage. The second form of this method allows you to specify the degree
-@@ -84,8 +84,8 @@
- // second form with imageInterpolation set to NSImageInterpolationHigh, which
- // produces highly smoothed thumbnails.
-
--- initWithThumbnailsOfImage:(NSImage*)image;
--- initWithThumbnailsOfImage:(NSImage*)image usingImageInterpolation:(NSImageInterpolation)imageInterpolation;
-+- (id) initWithThumbnailsOfImage:(NSImage*)image;
-+- (id) initWithThumbnailsOfImage:(NSImage*)image usingImageInterpolation:(NSImageInterpolation)imageInterpolation;
-
- // Writes the icon family to an .icns file.
-
-@@ -147,6 +147,8 @@
-
- - (NSImage*) imageWithAllReps;
-
-+#if !defined(DISABLE_CUSTOM_ICON)
-+
- // NOTE: Planned method -- not yet implemented.
- //
- // Gets the image data for one of the icon family's elements as a new
-@@ -178,6 +180,8 @@
-
- + (BOOL) removeCustomIconFromDirectory:(NSString*)path;
-
-+#endif // !defined(DISABLE_CUSTOM_ICON)
-+
- @end
-
- // Methods for interfacing with the Carbon Scrap Manager (analogous to and
-@@ -185,6 +189,6 @@
- @interface IconFamily (ScrapAdditions)
- + (BOOL) canInitWithScrap;
- + (IconFamily*) iconFamilyWithScrap;
--- initWithScrap;
-+- (id) initWithScrap;
- - (BOOL) putOnScrap;
- @end
-diff --git a/third_party/icon_family/IconFamily.m b/third_party/icon_family/IconFamily.m
-index b9571d0..439c2de 100644
---- a/third_party/icon_family/IconFamily.m
-+++ b/third_party/icon_family/IconFamily.m
-@@ -91,7 +91,9 @@ enum {
-
- + (Handle) get1BitMaskFromBitmapImageRep:(NSBitmapImageRep*)bitmapImageRep requiredPixelSize:(int)requiredPixelSize;
-
-+#if !defined(DISABLE_CUSTOM_ICON)
- - (BOOL) addResourceType:(OSType)type asResID:(int)resID;
-+#endif
-
- @end
-
-@@ -135,7 +137,7 @@ enum {
- // This is IconFamily's designated initializer. It creates a new IconFamily that initially has no elements.
- //
- // The proper way to do this is to simply allocate a zero-sized handle (not to be confused with an empty handle) and assign it to hIconFamily. This technique works on Mac OS X 10.2 as well as on 10.0.x and 10.1.x. Our previous technique of allocating an IconFamily struct with a resourceSize of 0 no longer works as of Mac OS X 10.2.
--- init
-+- (id) init
- {
- self = [super init];
- if (self) {
-@@ -148,7 +150,7 @@ enum {
- return self;
- }
-
--- initWithData:(NSData *)data
-+- (id) initWithData:(NSData *)data
- {
- self = [self init];
- if (self) {
-@@ -166,7 +168,7 @@ enum {
- return self;
- }
-
--- initWithContentsOfFile:(NSString*)path
-+- (id) initWithContentsOfFile:(NSString*)path
- {
- FSRef ref;
- OSStatus result;
-@@ -190,7 +192,7 @@ enum {
- return self;
- }
-
--- initWithIconFamilyHandle:(IconFamilyHandle)hNewIconFamily
-+- (id) initWithIconFamilyHandle:(IconFamilyHandle)hNewIconFamily
- {
- self = [self init];
- if (self) {
-@@ -203,7 +205,7 @@ enum {
- return self;
- }
-
--- initWithIconOfFile:(NSString*)path
-+- (id) initWithIconOfFile:(NSString*)path
- {
- IconRef iconRef;
- OSStatus result;
-@@ -257,7 +259,7 @@ enum {
- return self;
- }
-
--- initWithSystemIcon:(int)fourByteCode
-+- (id) initWithSystemIcon:(int)fourByteCode
- {
- IconRef iconRef;
- OSErr result;
-@@ -295,13 +297,13 @@ enum {
- return self;
- }
-
--- initWithThumbnailsOfImage:(NSImage*)image
-+- (id) initWithThumbnailsOfImage:(NSImage*)image
- {
- // The default is to use a high degree of antialiasing, producing a smooth image.
- return [self initWithThumbnailsOfImage:image usingImageInterpolation:NSImageInterpolationHigh];
- }
-
--- initWithThumbnailsOfImage:(NSImage*)image usingImageInterpolation:(NSImageInterpolation)imageInterpolation
-+- (id) initWithThumbnailsOfImage:(NSImage*)image usingImageInterpolation:(NSImageInterpolation)imageInterpolation
- {
- NSImage* iconImage512x512;
- NSImage* iconImage256x256;
-@@ -724,6 +726,8 @@ enum {
- return YES;
- }
-
-+#if !defined(DISABLE_CUSTOM_ICON)
-+
- - (BOOL) setAsCustomIconForFile:(NSString*)path
- {
- return( [self setAsCustomIconForFile:path withCompatibility:NO] );
-@@ -1139,6 +1143,8 @@ enum {
- return YES;
- }
-
-+#endif // !defined(DISABLE_CUSTOM_ICON)
-+
- - (NSData *) data
- {
- return [NSData dataWithBytes:*hIconFamily length:GetHandleSize((Handle)hIconFamily)];
-@@ -1589,6 +1595,8 @@ enum {
- return hRawData;
- }
-
-+#if !defined(DISABLE_CUSTOM_ICON)
-+
- - (BOOL) addResourceType:(OSType)type asResID:(int)resID
- {
- Handle hIconRes = NewHandle(0);
-@@ -1604,6 +1612,8 @@ enum {
- return YES;
- }
-
-+#endif // !defined(DISABLE_CUSTOM_ICON)
-+
- @end
-
- // Methods for interfacing with the Cocoa Pasteboard.
-@@ -1621,7 +1631,7 @@ enum {
- return [[[IconFamily alloc] initWithScrap] autorelease];
- }
-
--- initWithScrap
-+- (id) initWithScrap
- {
- NSPasteboard *pboard = [NSPasteboard generalPasteboard];
-
-@@ -1702,7 +1712,7 @@ enum {
- - (NSImageRep *) iconfamily_bestRepresentation
- {
- #if MAC_OS_X_VERSION_MIN_REQUIRED < 1060
-- if ([!self respondsToSelector:@selector(bestRepresentationForRect:context:hints:)])
-+ if (![self respondsToSelector:@selector(bestRepresentationForRect:context:hints:)])
- {
- return [self bestRepresentationForDevice:nil];
- }
-diff --git a/third_party/icon_family/NSString+CarbonFSRefCreation.m b/third_party/icon_family/NSString+CarbonFSRefCreation.m
-index 723de8b..fb86c52 100644
---- a/third_party/icon_family/NSString+CarbonFSRefCreation.m
-+++ b/third_party/icon_family/NSString+CarbonFSRefCreation.m
-@@ -23,7 +23,7 @@
- // Check whether the file exists already. If not, create an empty file if requested.
- if (![fileManager fileExistsAtPath:self]) {
- if (createFile) {
-- if (![[NSData data] writeToFile:self atomically:YES]) {
-+ if (![(NSData*)[NSData data] writeToFile:self atomically:YES]) {
- return NO;
- }
- } else {
diff --git a/third_party/icon_family/chromium_icon_family_2.patch b/third_party/icon_family/chromium_icon_family_2.patch
deleted file mode 100644
index 65e7096d..0000000
--- a/third_party/icon_family/chromium_icon_family_2.patch
+++ /dev/null
@@ -1,189 +0,0 @@
-diff --git a/third_party/icon_family/IconFamily.m b/third_party/icon_family/IconFamily.m
-index 439c2de..911ea31 100644
---- a/third_party/icon_family/IconFamily.m
-+++ b/third_party/icon_family/IconFamily.m
-@@ -1236,6 +1236,43 @@ enum {
- return [newImage autorelease];
- }
-
-+void GetRGBAFrom32BitSource(unsigned char src1, unsigned char src2, unsigned char src3, unsigned char src4,
-+ unsigned char* redOut, unsigned char* greenOut, unsigned char* blueOut, unsigned char* alphaOut,
-+ bool isAlphaFirst, bool isAlphaPremultiplied) {
-+ unsigned char r, g, b, a;
-+ if (isAlphaFirst) {
-+ a = src1;
-+ r = src2;
-+ g = src3;
-+ b = src4;
-+ } else {
-+ r = src1;
-+ g = src2;
-+ b = src3;
-+ a = src4;
-+ }
-+
-+ if (isAlphaPremultiplied) {
-+ // The RGB values are premultiplied by the alpha (so that
-+ // Quartz can save time when compositing the bitmap to a
-+ // destination), and we undo this premultiplication (with some
-+ // lossiness unfortunately) when retrieving the bitmap data.
-+ float oneOverAlpha = 255.0f / (float)a;
-+ r = r * oneOverAlpha;
-+ g = g * oneOverAlpha;
-+ b = b * oneOverAlpha;
-+ }
-+
-+ if (redOut)
-+ *redOut = r;
-+ if (greenOut)
-+ *greenOut = g;
-+ if (blueOut)
-+ *blueOut = b;
-+ if (alphaOut)
-+ *alphaOut = a;
-+}
-+
- + (Handle) get32BitDataFromBitmapImageRep:(NSBitmapImageRep*)bitmapImageRep requiredPixelSize:(int)requiredPixelSize
- {
- Handle hRawData;
-@@ -1244,9 +1281,7 @@ enum {
- unsigned char* pSrc;
- unsigned char* pDest;
- int x, y;
-- unsigned char alphaByte;
-- float oneOverAlpha;
--
-+
- // Get information about the bitmapImageRep.
- long pixelsWide = [bitmapImageRep pixelsWide];
- long pixelsHigh = [bitmapImageRep pixelsHigh];
-@@ -1256,6 +1291,8 @@ enum {
- BOOL isPlanar = [bitmapImageRep isPlanar];
- long bytesPerRow = [bitmapImageRep bytesPerRow];
- unsigned char* bitmapData = [bitmapImageRep bitmapData];
-+ BOOL isAlphaFirst = [bitmapImageRep bitmapFormat] & NSAlphaFirstBitmapFormat;
-+ BOOL isAlphaPremultiplied = !([bitmapImageRep bitmapFormat] & NSAlphaNonpremultipliedBitmapFormat);
-
- // Make sure bitmap has the required dimensions.
- if (pixelsWide != requiredPixelSize || pixelsHigh != requiredPixelSize)
-@@ -1289,23 +1326,14 @@ enum {
- for (y = 0; y < pixelsHigh; y++) {
- pSrc = bitmapData + y * bytesPerRow;
- for (x = 0; x < pixelsWide; x++) {
-- // Each pixel is 3 bytes of RGB data, followed by 1 byte of
-- // alpha. The RGB values are premultiplied by the alpha (so
-- // that Quartz can save time when compositing the bitmap to a
-- // destination), and we undo this premultiplication (with some
-- // lossiness unfortunately) when retrieving the bitmap data.
-- *pDest++ = alphaByte = *(pSrc+3);
-- if (alphaByte) {
-- oneOverAlpha = 255.0f / (float)alphaByte;
-- *pDest++ = *(pSrc+0) * oneOverAlpha;
-- *pDest++ = *(pSrc+1) * oneOverAlpha;
-- *pDest++ = *(pSrc+2) * oneOverAlpha;
-- } else {
-- *pDest++ = 0;
-- *pDest++ = 0;
-- *pDest++ = 0;
-- }
-- pSrc+=4;
-+ unsigned char r, g, b, a;
-+ GetRGBAFrom32BitSource(pSrc[0], pSrc[1], pSrc[2], pSrc[3],
-+ &r, &g, &b, &a, isAlphaFirst, isAlphaPremultiplied);
-+ *pDest++ = a;
-+ *pDest++ = r;
-+ *pDest++ = g;
-+ *pDest++ = b;
-+ pSrc += 4;
- }
- }
- } else if (bitsPerPixel == 24) {
-@@ -1347,6 +1375,8 @@ enum {
- BOOL isPlanar = [bitmapImageRep isPlanar];
- long bytesPerRow = [bitmapImageRep bytesPerRow];
- unsigned char* bitmapData = [bitmapImageRep bitmapData];
-+ BOOL isAlphaFirst = [bitmapImageRep bitmapFormat] & NSAlphaFirstBitmapFormat;
-+ BOOL isAlphaPremultiplied = !([bitmapImageRep bitmapFormat] & NSAlphaNonpremultipliedBitmapFormat);
-
- // Make sure bitmap has the required dimensions.
- if (pixelsWide != requiredPixelSize || pixelsHigh != requiredPixelSize)
-@@ -1383,9 +1413,12 @@ enum {
- for (y = 0; y < pixelsHigh; y++) {
- pSrc = bitmapData + y * bytesPerRow;
- for (x = 0; x < pixelsWide; x++) {
-- cgCol.red = ((float)*(pSrc)) / 255;
-- cgCol.green = ((float)*(pSrc+1)) / 255;
-- cgCol.blue = ((float)*(pSrc+2)) / 255;
-+ unsigned char r, g, b;
-+ GetRGBAFrom32BitSource(pSrc[0], pSrc[1], pSrc[2], pSrc[3],
-+ &r, &g, &b, NULL, isAlphaFirst, isAlphaPremultiplied);
-+ cgCol.red = (float)r / 255;
-+ cgCol.green = (float)g / 255;
-+ cgCol.blue = (float)b / 255;
-
- *pDest++ = CGPaletteGetIndexForColor(cgPal, cgCol);
-
-@@ -1436,6 +1469,8 @@ enum {
- BOOL isPlanar = [bitmapImageRep isPlanar];
- long bytesPerRow = [bitmapImageRep bytesPerRow];
- unsigned char* bitmapData = [bitmapImageRep bitmapData];
-+ BOOL isAlphaFirst = [bitmapImageRep bitmapFormat] & NSAlphaFirstBitmapFormat;
-+ BOOL isAlphaPremultiplied = !([bitmapImageRep bitmapFormat] & NSAlphaNonpremultipliedBitmapFormat);
-
- // Make sure bitmap has the required dimensions.
- if (pixelsWide != requiredPixelSize || pixelsHigh != requiredPixelSize)
-@@ -1469,8 +1504,11 @@ enum {
- for (y = 0; y < pixelsHigh; y++) {
- pSrc = bitmapData + y * bytesPerRow;
- for (x = 0; x < pixelsWide; x++) {
-- pSrc += 3;
-- *pDest++ = *pSrc++;
-+ unsigned char a;
-+ GetRGBAFrom32BitSource(pSrc[0], pSrc[1], pSrc[2], pSrc[3],
-+ NULL, NULL, NULL, &a, isAlphaFirst, isAlphaPremultiplied);
-+ *pDest++ = a;
-+ pSrc += 4;
- }
- }
- }
-@@ -1514,6 +1552,8 @@ enum {
- BOOL isPlanar = [bitmapImageRep isPlanar];
- long bytesPerRow = [bitmapImageRep bytesPerRow];
- unsigned char* bitmapData = [bitmapImageRep bitmapData];
-+ BOOL isAlphaFirst = [bitmapImageRep bitmapFormat] & NSAlphaFirstBitmapFormat;
-+ BOOL isAlphaPremultiplied = !([bitmapImageRep bitmapFormat] & NSAlphaNonpremultipliedBitmapFormat);
-
- // Make sure bitmap has the required dimensions.
- if (pixelsWide != requiredPixelSize || pixelsHigh != requiredPixelSize)
-@@ -1544,14 +1584,14 @@ enum {
- pSrc = bitmapData + y * bytesPerRow;
- for (x = 0; x < pixelsWide; x += 8) {
- maskByte = 0;
-- maskByte |= (*(unsigned*)pSrc & 0xff) ? 0x80 : 0; pSrc += 4;
-- maskByte |= (*(unsigned*)pSrc & 0xff) ? 0x40 : 0; pSrc += 4;
-- maskByte |= (*(unsigned*)pSrc & 0xff) ? 0x20 : 0; pSrc += 4;
-- maskByte |= (*(unsigned*)pSrc & 0xff) ? 0x10 : 0; pSrc += 4;
-- maskByte |= (*(unsigned*)pSrc & 0xff) ? 0x08 : 0; pSrc += 4;
-- maskByte |= (*(unsigned*)pSrc & 0xff) ? 0x04 : 0; pSrc += 4;
-- maskByte |= (*(unsigned*)pSrc & 0xff) ? 0x02 : 0; pSrc += 4;
-- maskByte |= (*(unsigned*)pSrc & 0xff) ? 0x01 : 0; pSrc += 4;
-+ for (int i = 7; i >= 0; i--) {
-+ unsigned char a;
-+ GetRGBAFrom32BitSource(pSrc[0], pSrc[1], pSrc[2], pSrc[3],
-+ NULL, NULL, NULL, &a, isAlphaFirst, isAlphaPremultiplied);
-+ if (a)
-+ maskByte |= 1 << i;
-+ pSrc += 4;
-+ }
- *pDest++ = maskByte;
- }
- }
-diff --git a/third_party/icon_family/README.chromium b/third_party/icon_family/README.chromium
-index 915d197..bbe5096 100644
---- a/third_party/icon_family/README.chromium
-+++ b/third_party/icon_family/README.chromium
-@@ -12,3 +12,4 @@ This is an Objective-C wrapper around Mac OS X Icon Services' "IconFamily" data
-
- Local Modifications:
- chromium_icon_family.patch: Fix minor erors and warnings. Put code that the custom icon code behind a DISABLE_CUSTOM_ICON flag.
-+chromium_icon_family_2.patch: Add support for alpha first and non-premultiplied image formats.
diff --git a/third_party/icon_family/icon_family.gyp b/third_party/icon_family/icon_family.gyp
deleted file mode 100644
index 13068e3..0000000
--- a/third_party/icon_family/icon_family.gyp
+++ /dev/null
@@ -1,27 +0,0 @@
-# Copyright (c) 2012 The Chromium Authors. All rights reserved.
-# Use of this source code is governed by a BSD-style license that can be
-# found in the LICENSE file.
-
-{
- 'targets': [
- ],
- 'conditions': [
- ['OS=="mac"', {
- 'targets' : [
- {
- 'target_name' : 'icon_family',
- 'type': 'static_library',
- 'sources': [
- 'IconFamily.h',
- 'IconFamily.m',
- 'NSString+CarbonFSRefCreation.h',
- 'NSString+CarbonFSRefCreation.m',
- ],
- 'defines': [
- 'DISABLE_CUSTOM_ICON'
- ],
- },
- ],
- }],
- ],
-}