multi-page tiff 2 pdf on iphone

Questions and postings pertaining to the development of ImageMagick, feature enhancements, and ImageMagick internals. ImageMagick source code and algorithms are discussed here. Usage questions which are too arcane for the normal user list should also be posted here.
Post Reply
elfenlaid
Posts: 2
Joined: 2011-05-02T07:03:48-07:00
Authentication code: 8675308

multi-page tiff 2 pdf on iphone

Post by elfenlaid »

Hello,
I'm trying to convert multi-paged tif to pdf with following code: //took it from iphone magick sample

Code: Select all

- (void)posterizeImageWithoutCompression {
	// WITHOUT JPEG COMPRESSION, work done by Karl: karl@xk72.com
	NSLog(@"we're not using JPEG compression");
	
	MagickWandGenesis();
	magick_wand = NewMagickWand();
    
	UIImage * src = [UIImage imageNamed:"ololo.tif"];
	CGImageRef srcCGImage = [src CGImage];
	NSData * srcData = (NSData *) CGDataProviderCopyData(CGImageGetDataProvider(srcCGImage));
	unsigned long width = src.size.width;
	unsigned long height = src.size.height;
	const void *bytes = [srcData bytes];
	const char *map;
	CGBitmapInfo bitmapInfo = CGImageGetBitmapInfo(srcCGImage);
	CGImageAlphaInfo alphaInfo = CGImageGetAlphaInfo(srcCGImage);
	if ((bitmapInfo & kCGBitmapByteOrder32Little) != 0)
		switch (alphaInfo) {
			case kCGImageAlphaLast:
			case kCGImageAlphaPremultipliedLast:
				map = "ABGR";
				break;
			case kCGImageAlphaFirst:
			case kCGImageAlphaPremultipliedFirst:
				map = "BGRA";
				break;
			case kCGImageAlphaNoneSkipLast:
				map = "PBGR";
				break;
			case kCGImageAlphaNoneSkipFirst:
				map = "BGRP";
				break;
			case kCGImageAlphaNone:
				map = "BGR";
				break;
		}
	else {
		switch (alphaInfo) {
			case kCGImageAlphaLast:
			case kCGImageAlphaPremultipliedLast:
				map = "RGBA";
				break;
			case kCGImageAlphaFirst:
			case kCGImageAlphaPremultipliedFirst:
				map = "ARGB";
				break;
			case kCGImageAlphaNoneSkipLast:
				map = "RGBP";
				break;
			case kCGImageAlphaNoneSkipFirst:
				map = "PRGB";
				break;
			case kCGImageAlphaNone:
				map = "RGB";
				break;
		}
	}

       // ==================
       // Here code fail in EXC_BAD_ACCESS when using something differente from UndefinedPixel

	MagickBooleanType status = MagickConstituteImage(magick_wand, width, height, map, UndefinedPixel, bytes);

       // ===================

	if (status == MagickFalse) {
		ThrowWandException(magick_wand);
	}
	
	MagickSetFormat(magick_wand, "pdf");
	MagickSetImageDepth(magick_wand, 8);

        NSString *root = 
        [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask , YES)
        objectAtIndex:0];
  
	const char * filename= [[root stringByAppendingFormat:@"text.pdf"] cStringUsingEncoding:NSUTF8StringEncoding];
	status = MagickWriteImage(magick_wand, filename);
	if (status == MagickFalse) {
		ThrowWandException(magick_wand);
	}
After exec. app lefts only empty pdf file.
Trouble shooting:
- UIImage * src = [UIImage imageNamed:"ololo.tif"]; // reads only first page of tiff file @_@ Is exist other methods to get data without using uiimage class? Will [NSData dataWithContentOfFile] helps? If yes then from where i can get width/height of image and other properties?
- In my app i can receive a quite blob files(50-60 pages). Is imagemagick able to convert that kind of files in restricted memory size (near 25-30 mb)?

P.S. sorry for english
User avatar
magick
Site Admin
Posts: 11064
Joined: 2003-05-31T11:32:55-07:00

Re: multi-page tiff 2 pdf on iphone

Post by magick »

Most likely you are running out of memory. Use http://www.imagemagick.org/api/magick-p ... ourceLimit to force pixels to disk rather than memory. However, some TIFF images are processed by the TIFF delegate library which allocates its memory from the heap. Under those circumstances you should get an exception (e.g. out of memory condition).
elfenlaid
Posts: 2
Joined: 2011-05-02T07:03:48-07:00
Authentication code: 8675308

Re: multi-page tiff 2 pdf on iphone

Post by elfenlaid »

thanks for quick reply.
hm, in this circumstances it would be better to ban tiff format.
Post Reply