Re: Multi-Page TIFF routine
Re: Multi-Page TIFF routine
- Subject: Re: Multi-Page TIFF routine
- From: Scott Ribe <email@hidden>
- Date: Sun, 14 Nov 2004 19:14:49 -0700
> I am very sorry to ask you, but is there a routine to create and access
> multi-page TIFF file in Cocoa? I know that it does have for single TIFF, but I
> could not find a routine to access multi-page TIFF file format. Also, is there
> a way to load file faster? I have used initWithContentsOfFile, but it is too
> slow to load 60 image files, so I used initByReferencingFile, but this is slow
> when I try to display the image. Or is there a way to create thumbnails of
> images, and display them faster? Your reply will be greatly appreciated.
I don't think Cocoa supports multi-page TIFF. I'm pretty new to Cocoa, so
that's not a definite answer. I can give you a quick outline of how to do it
using QuickTime & QuickDraw. This code will get you a raw buffer of bytes
from a decoded 1-bit tiff, given an FSRef to the file and a 0-based index of
the page:
void * GetTifData( const FSRef & fsr, long pgidx )
{
FSSpec fss;
FSGetCatalogInfo( &fsr, kFSCatInfoNone, nil, nil, &fss, nil );
GraphicsImportComponent importer;
GetGraphicsImporterForFile( &fss, &importer );
unsigned long pagecnt;
GraphicsImportGetImageCount( importer, &pagecnt );
ImageDescriptionHandle desch = nil;
GraphicsImportSetImageIndex( importer, pgidx + 1 );
GraphicsImportGetImageDescription( importer, &desch );
long width = (**desch).width, height = (**desch).height;
long rowbytes = (width + 7) / 8;
void * data = malloc( rowbytes * height );
GWorldPtr gw = nil;
Rect r = { 0, 0, height, width };
NewGWorldFromPtr( &gw, 1, &r, NULL, NULL, 0, (Ptr) data, rowbytes );
GraphicsImportSetGWorld( importer, gw, nil );
GraphicsImportDraw( importer );
DisposeGWorld( gw );
return data;
}
Once you get the buffer, you can use it to build an image representation for
Core Graphics, Cocoa, or whatever.
Things the above code doesn't do that you would need to handle:
- check return values and handle erros
- check the "depth" attribute of the ImageDescriptionHandle and calculate
rowbytes (and buffer size) accordingly for bit depths other than 1
- pad rowbytes to an even multiple of 16
- return the width, height & rowbytes out to the calling procedure
- check that pgidx is < the actual page count of the file
For even more control, you can check the libtiff library at:
<http://libtiff.org/index2.html>
As for speed, watch out for scaling. Scaling of large image takes time, so
you only want to scale when necessary--once for display. If you try to copy
or draw into an intermediate buffer that's not the exact same size as the
source, that can kill performance.
--
Scott Ribe
email@hidden
http://www.killerbytes.com/
(303) 665-7007 voice
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden