Re: Getting image info without loading entire image
Re: Getting image info without loading entire image
- Subject: Re: Getting image info without loading entire image
- From: Kaelin Colclasure <email@hidden>
- Date: Fri, 19 Jan 2007 14:35:19 -0800
On Jan 19, 2007, at 12:55 PM, Ken Tozier wrote:
On Jan 19, 2007, at 2:55 PM, Kaelin Colclasure wrote:
If you are not seeing the full set of image attributes, then for
some reason or another the image you are trying to work with has
not been imported by Spotlight. (This could be because the
filesystem where the image is stored is not indexed, or because
it's in a filtered location... If you send a sample of the mdls
command and output I might be able to suggest why.)
I mentioned it in the initial post, but neglected to in the
followup, but what I need to do is get attributes from images on a
non-indexed Windows box. I have the folder scanning code working
nicely but wanted to get the image height/width as quickly and with
as little overhead as possible so I can store this info in a
database. Other parts of my application use this image info to
exactly size picture boxes in QuarkXPress before importing the
image, saves several steps.
Ahh, well that explains why you're seeing only the basic filesystem
attributes. Hmmm. I don't suppose it's practical to simply copy /
mirror the relevant folder onto a local HFS volume?
I can get this info by loading the image like this
NSImageRep *img = [NSImageRep imageRepWithContentsOfFile: inPath];
if (img != nil)
{
width = [NSNumber numberWithInt: [img pixelsWide]],
height = [NSNumber numberWithFloat: [img pixelsHigh]];
}
But I'm dealing with thousands of images and the folder scanner
really bogs down because it has to load every one into memory.
Gregory Weston's suggestion of directly loading and using the
"Image.mdimporter" plugin sounds like a promising possibility but
unfortunately, it's "GetMetadataForFile" function seems to have a
custom name as the following fails
typedef Boolean (*GET_METADATA_FOR_FILE)(void *thisInterface,
CFMutableDictionaryRef attributes,
CFStringRef contentTypeUTI,
CFStringRef pathToFile);
NSURL *bundleURL = [NSURL fileURLWithPath: @"/System/Library/
Spotlight/Image.mdimporter"];
CFBundleRef bundleRef = CFBundleCreate(kCFAllocatorDefault,
(CFURLRef) bundleURL);
GET_METADATA_FOR_FILE getter = CFBundleGetFunctionPointerForName
(bundleRef, CFSTR("GetMetadataForFile"));
if (getter == NULL)
NSLog(@"GetMetadataForFile failed");
Yes, while this would work for some (most?) importers, this is
bypassing much of the CFPlugIn "plumbing". The "correct" way requires
creating an instance of the plug in from its factory, which gets you
a pointer to an IUnknown interface struct. You then call the
QueryInterface member function from that struct with the UUID
kMDImporterInterfaceID, which gets you a pointer to an
MDImporterInterface struct, whose vtable layout can be seen in the
MDImporter.h header file.
Even after you figure all that out, there's still no guarantee that
the image importer will be any faster than your current solution. A
quick perusal of the plug in's symbols with nm suggests that it is
merely using the CGImage APIs to do its work... (See `nm /System/
Library/Spotlight/Image.mdimporter/Contents/MacOS/Image`.) I believe
this is the same plumbing used by NSImage in Tiger.
-- Kaelin
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden