multipage tiff file to array of regular images using ImageMagick functions

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
mehuldvgny
Posts: 4
Joined: 2019-06-09T13:28:50-07:00
Authentication code: 1152

multipage tiff file to array of regular images using ImageMagick functions

Post by mehuldvgny » 2019-06-09T14:19:01-07:00

Hi Guys, please help me to get the ImageMagick API functions(C/C++ code snippet and not command line) that converts multipage tiff Image file data to array of regular images(jpg/png)... Thanks

User avatar
fmw42
Posts: 25152
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: multipage tiff file to array of regular images using ImageMagick functions

Post by fmw42 » 2019-06-09T15:12:16-07:00

Please always provide your IM version when asking questions and platform/OS. What have you tried? Do you have any code?

mehuldvgny
Posts: 4
Joined: 2019-06-09T13:28:50-07:00
Authentication code: 1152

Re: multipage tiff file to array of regular images using ImageMagick functions

Post by mehuldvgny » 2019-06-10T00:22:02-07:00

I am using 64 bit windows 10 for development and my IM version details is as as follows
MagickppLibVersionText/MagickLibVersionText "7.0.0"
MagickppLibVersionNumber/MagickLibVersionNumber 1:0:0


JS Code Snippet:

Code: Select all

if (e.target.result.split(',')[0].indexOf('tiff') > 0) 
          var fileData = e.target.result.split(',')[1];
I am passing proper TIFF fileData in _pData and size of _pData in _nSize to C function doing following things:

C - Code Snippet:

Code: Select all

ExceptionInfo* 	exInfo = AcquireExceptionInfo();
ImageInfo* imInfo = CloneImageInfo(NULL);

//I now want _pData to decompress and convert into array of png/jpg image so that I can use each separate images and process that
Image* imImage = BlobToImage(imInfo, _pData, (size_t)_nSize, exInfo);
strcpy(imImage->magick, "bmp");
strcpy(imInfo->magick, "bmp");
unsigned char* ptr = (unsigned char*)::ImageToBlob(imInfo, imImage, (size_t*)&_imageDataSize, exInfo);
_imageData = new unsigned char[_imageDataSize];
memcpy(_imageData, ptr, _imageDataSize);
SO please suggest IM API methods to achieve the desired result

Thanks

mehuldvgny
Posts: 4
Joined: 2019-06-09T13:28:50-07:00
Authentication code: 1152

Re: multipage tiff file to array of regular images using ImageMagick functions

Post by mehuldvgny » 2019-06-10T00:37:39-07:00

_pData is the base64 decoded blob of Tiff image

mehuldvgny
Posts: 4
Joined: 2019-06-09T13:28:50-07:00
Authentication code: 1152

Re: multipage tiff file to array of regular images using ImageMagick functions

Post by mehuldvgny » 2019-06-17T05:00:34-07:00

Hi,
This can be done using BlobToImage() method present in blob.h of MagickCore and we can iterate through different images using the next pointer of Image* returned by BlobToImage() method as shown below

Code: Select all

//_pData is the base64 decoded blob of Tiff image
//_nSize is the sizeof _pData
//_imageData  is the actual data of the image

ExceptionInfo* exInfoX = AcquireExceptionInfo();
ImageInfo* imInfoX = CloneImageInfo(NULL);
Image* imImageX = BlobToImage(imInfoX, _pData, (size_t)_nSize, exInfoX);

int EMSCRIPTEN_KEEPALIVE ImageControlWebAssembly::showGivenPageTiffImage(int pageNumber)
{
	int count = 1;
	try
	{
		if (imImageX == NULL)
		{
			return -1; //Handle this error
		}
		if (_imageData) {
			delete[] _imageData;
		}
		_imageData = NULL;
		_imageDataSize = 0;

		ExceptionInfo* exInfo = AcquireExceptionInfo();
		
		Image* temp = imImageX;
		
		if (temp->next != NULL)
		{
			TRACE << _id << L"::imImage->next has info" << output();
			while (count != pageNumber)
			{
				temp = temp->next;
				count++;
			}
			//TRACE << _id << L":imImage->next has counts " << count << output();
		}

		strcpy(temp->magick, "bmp");
		strcpy(temp->image_info->magick, "bmp");
		unsigned char* ptr = (unsigned char*)::ImageToBlob(temp->image_info, temp, (size_t*)& _imageDataSize, exInfo);
		_imageData = new unsigned char[_imageDataSize];
		memcpy(_imageData, ptr, _imageDataSize);
		
		free(ptr);
		DestroyExceptionInfo(exInfo);
		
	}
	catch (std::exception& ex) {
		//TRACE << _id << L"::]Magick::Exception " << ex.what() << output();
	}

	return count;
}

Post Reply