Page 1 of 1

multipage tiff file to array of regular images using ImageMagick functions

Posted: 2019-06-09T14:19:01-07:00
by mehuldvgny
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

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

Posted: 2019-06-09T15:12:16-07:00
by fmw42
Please always provide your IM version when asking questions and platform/OS. What have you tried? Do you have any code?

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

Posted: 2019-06-10T00:22:02-07:00
by mehuldvgny
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

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

Posted: 2019-06-10T00:37:39-07:00
by mehuldvgny
_pData is the base64 decoded blob of Tiff image

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

Posted: 2019-06-17T05:00:34-07:00
by mehuldvgny
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;
}