Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: How to grab IconRef from a .tiff file.



On 22/08/2003 23:18, Laurence Harris wrote:

> Will do.

Thanks for the samples. Now I see it. Here is the version that
works much better. No double alpha blending, no banding.

No error checking as well :)

--- Cut Here ---
Handle GetThumbnailMaskHandle(PicHandle pict);
IconRef FileToIconRef(FSRef *fsRef);

#warning "Check for errors!!!"
IconRef FileToIconRef(FSRef *fsRef)
{
GraphicsImportComponent component;
OSStatus err;
FSSpec fsSpec;
PicHandle pict;
IconFamilyHandle iconFamily;
IconRef iconRef;
const OSType kFakeCreator = '#%$^', kFakeType = '#$&$';
Handle h;

err = FSGetCatalogInfo(fsRef, kFSCatInfoNone, NULL,
NULL, &fsSpec, NULL);

err = GetGraphicsImporterForFile(&fsSpec, &component);

err = GraphicsImportGetAsPicture(component, &pict);
iconFamily = (IconFamilyHandle)NewHandle(0);
err = SetIconFamilyData(iconFamily, 'PICT', (Handle)pict);
KillPicture(pict);

err = GraphicsImportSetGraphicsMode(component,
graphicsModeStraightAlpha, NULL);
err = GraphicsImportGetAsPicture(component, &pict);
CloseComponent(component);

h = GetThumbnailMaskHandle(pict);
KillPicture(pict);
err = SetIconFamilyData(iconFamily, kThumbnail8BitMask, h);
DisposeHandle(h);

err = RegisterIconRefFromIconFamily(kFakeCreator, kFakeType,
iconFamily, &iconRef);
DisposeHandle((Handle)iconFamily);
err = AcquireIconRef(iconRef);
err = UnregisterIconRef(kFakeCreator, kFakeType);
return iconRef;
}

#warning "Check for errors!!!"
Handle GetThumbnailMaskHandle(PicHandle pict)
{
GWorldPtr offscreen, offscreen2, offscreen3;
CGrafPtr savedPort;
GDHandle savedDevice;
Handle h;
CTabHandle cTab;
OSErr err;
Rect r;

SetRect(&r, 0, 0, 128, 128);

GetGWorld(&savedPort, &savedDevice);

err = NewGWorld(&offscreen, 32, &r, NULL, NULL, 0);
HLock((Handle)GetGWorldPixMap(offscreen));
SetGWorld(offscreen, NULL);
PaintRect(&r);
DrawPicture(pict, &r);

err = NewGWorld(&offscreen2, 32, &r, NULL, NULL, 0);
HLock((Handle)GetGWorldPixMap(offscreen2));
SetGWorld(offscreen2, NULL);
EraseRect(&r);
DrawPicture(pict, &r);

CopyBits(GetPortBitMapForCopyBits(offscreen),
GetPortBitMapForCopyBits(offscreen2), &r, &r, subOver, NULL);

h = NewHandle(128*128);
HLock(h);
cTab = GetCTable(8 + 32);
err = NewGWorldFromPtr(&offscreen3, 8, &r, cTab, NULL, 0,
*h, 128);
DisposeCTable(cTab);
HLock((Handle)GetGWorldPixMap(offscreen3));
SetGWorld(offscreen3, NULL);
CopyBits(GetPortBitMapForCopyBits(offscreen2),
GetPortBitMapForCopyBits(offscreen3), &r, &r, srcCopy, NULL);

SetGWorld(savedPort, savedDevice);

DisposeGWorld(offscreen);
DisposeGWorld(offscreen2);

return h;
}

--- Cut Here ---

Mike
_______________________________________________
carbon-development mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/carbon-development
Do not post admin requests to the list. They will be ignored.

References: 
 >Re: How to grab IconRef from a .tiff file. (From: Laurence Harris <email@hidden>)



Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.