Having an image file buffer in memory, what is the fastest way to create its thumbnail?

拜拜、爱过 提交于 2019-12-23 08:44:30

问题


Trying to create a an image acquiring application optimized for a fast scanner (which can provide up to 6 compressed images [color+gray+binary][front+rear] for each paper at speed of 150 ppm) I have some speed issues. Using TWAIN technology and memory buffer transfer mode (TWSX_MEMORY) I receive image buffer (as JPEG or TIFF file loaded in memory) from scanner and save it to my application destination path. If I do not want to create thumbnails, my application causes no speed loss for the scanner, but if I want to, due the way I do it (saving buffer into a file in my C++ TWAIN handling dll, notifying my .NET host application with destination file path using a function pointer, opening the image file in C# and creating the thumbnail image), my application causes extreme speed loss to scanning speed. I tried some optimizations such as performing loading phase in a separate thread and sending unmanaged image file buffer to .NET host and trying to load it in an unsafe context (UnmanagedMemoryStream) and creating thumbnail. But it did not improve the speed significantly. So my question is :

Having an image file buffer in memory (e.g. 24 bit JPEG compressed without embeded thumbnail), is there a fast direct way to create a thumbnail image from it? What do you suggest as fastest method for creating thumbnails in this case?


回答1:


If it's a JPEG image, you can simply discard most of the DCT data, and create a thumbnail at a power of two size, using only the DCT coefficients.

If you can find the sources for it, take a look at EPEG from the Enlightenment project. It does exactly what you're looking for with JPEG files, entirely without decoding or decompressing the image. The source code would be very instructive.

For other image formats, it's not so simple - you'll need to decode and render the image to a memory buffer, then perform your own scaling. The CImg and boost::GIL libraries can assist with that.




回答2:


I take it that the problem is that it takes longer to convert an image to a thumbnail than to acquire the image in the first place, correct?

Although a faster thumbnail conversion program might fix the problem for you, it might not be sufficient for someone with a slower computer. Instead, I suggest creating a queue of images to be converted to thumbnails -- i.e. you have one thread (or process) which adds scanned images to the queue, and another thread/process that removes images from that queue and creates thumbnails from them. This way the relative speeds of the two operations don't matter.



来源:https://stackoverflow.com/questions/1316170/having-an-image-file-buffer-in-memory-what-is-the-fastest-way-to-create-its-thu

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!