Tiff Splitting Very Slow

We use another product called BitMiracle Read and write TIFF images in C# and VB.NET - LibTiff.Net for our current conversion needs. There are a few features we wanted to acquire from Aspose so my job is to try to compare the 2 products. So far everything was similar in function if not better on the Aspose side until I got to Tiff Splitting.


Using the code below I am trying to split a TIFF that is 270 pages. BitMiracles product can split the tiff in 3 seconds while the best time I have seen Aspose do it is 1 minute and 39 seconds. This is a major issue for us because we do thousands of tiff splits a day.

Can you tell me if I am doing something wrong or if there are any optimizations that can be done?

using (var multiImage = (TiffImage) Image.Load(@“Resources\Multi.tiff”))
{
foreach (var tiffFrame in multiImage.Frames)
{
multiImage.ActiveFrame = tiffFrame;
var pixels = multiImage.LoadPixels(tiffFrame.Bounds);

var createOptions = new TiffOptions
{
Compression = TiffCompressions.CcittFax4,
BitsPerSample = new ushort[] {1},
Photometric = TiffPhotometrics.MinIsWhite,
Source = new FileCreateSource(“output-” + multiImage.Frames.ToList().IndexOf(tiffFrame).ToString(“0000”) + “.tiff”, false)
};

using (var tiffImage = (TiffImage) Image.Create(createOptions, tiffFrame.Width, tiffFrame.Height))
{
tiffImage.SavePixels(tiffFrame.Bounds, pixels);
tiffImage.Save();
}
}
}

Hi Michael,


Thank you for contacting Aspose support.

Please provide us a sample image (multi-page TIFF) after benchmarking it on your end with both APIs along with your test environment details. We will do the same on our end to establish the said behavior as a performance lapse in Aspose.Imaging APIs, and then we can report it to the core development team for further investigation.

Thanks for your response.


I have created a test application that shows both BitMiracle and Aspose side by side. I was unable to upload it to your website due to a 404 error in the attach file button. But I did put it on my server for you to grab.

To use this application you will need to add a lic file to the Resources folder and then rebuild and execute the exe.

I ran the code 2 different ways. Once in a single thread and once muli-threaded and had the following results:

Aspose Single Thread 01:17.219
BitMiracle Single Thread 00:03.484
Aspose Multi Thread 01:04.990
BitMiracle Multi Thread 00:01.440

I couldn’t really come up with a good way to thread the Aspose library so what I did was somewhat of a hack.

Please let me know what you find.

Hi Michael,


Thank you for providing the sample application to test this case. We have evaluated the scenario using your provided application and are able to notice the difference in performance. We are currently trying to tweak the source code of splitting the TIFF frames to notice any performance improvements. We will shortly get back to you with updates in this regard.

Hi Michael,


Thank you for your patience with us.

We have optimized the TIFF frame splitting code (using Aspose.Imaging for .NET API) to reduce the execution time nearly to half. The execution time for your provided code was 3 mins & 20 secs on my machine (1st generation i7 CPU Q740 with 6GB of RAM). It has been reduced to 1 min & 40 secs using the following code snippet.

C#

var createOptions = new TiffOptions
{
Compression = TiffCompressions.CcittFax4,
BitsPerSample = new ushort[] { 1 },
Photometric = TiffPhotometrics.MinIsWhite,
};

using (var multiImage = (TiffImage)TiffImage.Load(@“Resources\MultiPageTest.tif”))
{
foreach (var tiffFrame in multiImage.Frames)
{
//Save the frame directly on disc
tiffFrame.Save(Path.Combine(outputDirectory.FullName, “page-” + multiImage.Frames.ToList().IndexOf(tiffFrame).ToString(“0000”) + “.tiff”), createOptions);
}
}

Please note, the above code is saving the TiffFrame directly on disc in spite of creating a new TiffImage first. This approach will save the memory as well as time for the overall operation due to the reason that previous approach cached the image data before saving it on the disc.

The optimized code is quicker but it still does not match the performance of other library. In case you are not satisfied with the performance of Aspose.Imaging for .NET API, we can log an investigative ticket to look further into this matter.

Hi,


The performance is much better. I am now looking at 40 seconds which is about 1/2 like you said. The problem is it is still about 40x slower than the other product. I think it would be a good idea to create a ticket. This seems like something that needs to be fixed.

Also while trying to improve performance I used the following code. I encounter a nondescript image saving error when I run this. Is there a reason why? It seems that threading each frame is going to be a key way to improve performance.

using (var multiImage = (TiffImage)Image.Load(@“Resources\MultiPageTest.tif”))
{
Parallel.ForEach(multiImage.Frames, f =>
{
var createOptions = new TiffOptions
{
Compression = TiffCompressions.CcittFax4,
BitsPerSample = new ushort[] { 1 },
Photometric = TiffPhotometrics.MinIsWhite,
};
f.Save(Path.Combine(outputDirectory.FullName, “page-” + multiImage.Frames.ToList().IndexOf(f).ToString(“0000”) + “.tiff”), createOptions);
});
}

Error: Image saving failed.

Thanks,
Mike Hohlios

Hi Mike,


Good to know there is some improvement. I have logged an investigative ticket (IMAGING-34459) for the product team to look further into this matter. Please spare us some time for the proper analysis. In the meanwhile we will keep you posted with updates in this regard.

Please always look for the InnerException to get more descriptive error messages in case you stumble upon any. your code is throwing ImageSaveException: "Cannot decode strip 0. Details: " while saving 9th frame. At the moment I am not sure what is causing this exception. Let me check and get back to you with details.

Hi Mike,


Thank you for your patience with us.

I was unable to bypass the ImageSaveException as discussed in your last post so I have logged the incident in our bug tracking system under the ticket IMAGING-34463 for further investigation. Please spare us little time to properly analyze the problem cause and to provide a fix at earliest possible. In the meanwhile, we will keep you posted with updates in this regard.

Hi Mike,


This is to inform you that we have completed the preliminary investigation of the issue logged earlier as IMAGING-34463. The problem is caused due to the reason that Aspose.Imaging for .NET API currently doesn’t fully support multi-threading execution. We already have this feature on our road map, and we hope to provide the implementation in the first quarter of 2015.

The issues you have found earlier (filed as ) have been fixed in this Aspose.Words for JasperReports 18.3 update.