内存中有一个图像文件缓冲区,创建其缩略图的最快方法是什么?

发布于 2024-08-02 09:32:07 字数 553 浏览 6 评论 0原文

尝试创建一个针对快速扫描仪优化的图像采集应用程序(可以以 150 ppm 的速度为每张纸提供最多 6 张压缩图像 [彩色+灰度+二进制][正面+背面])我有一定的速度问题。 使用 TWAIN 技术和内存缓冲区传输模式 (TWSX_MEMORY),我从扫描仪接收图像缓冲区(作为加载到内存中的 JPEG 或 TIFF 文件)并将其保存到我的应用程序目标路径。 如果我不想创建缩略图,我的应用程序不会导致扫描仪速度损失,但如果我想,由于我这样做的方式(将缓冲区保存到我的 C++ TWAIN 处理 dll 中的文件中,通知我的 .NET 主机应用程序)使用函数指针的目标文件路径,在 C# 中打开图像文件并创建缩略图),我的应用程序会导致扫描速度急剧下降。 我尝试了一些优化,例如在单独的线程中执行加载阶段,将非托管图像文件缓冲区发送到 .NET 主机,并尝试在不安全的上下文 (UnmanagedMemoryStream) 中加载它并创建缩略图。但并没有显着提高速度。所以我的问题是:

内存中有一个图像文件缓冲区(例如,没有嵌入缩略图的 24 位 JPEG 压缩),是否有一种快速直接的方法来从中创建缩略图图像?在这种情况下,您建议创建缩略图的最快方法是什么?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

甜是你 2024-08-09 09:32:07

如果它是 JPEG 图像,您可以简单地丢弃大部分 DCT 数据,并仅使用 DCT 系数创建尺寸为 2 的幂的缩略图。

如果您能找到它的来源,请查看 Enlightenment 项目中的 EPEG。它完全可以满足您对 JPEG 文件的要求,完全无需解码或解压缩图像。源代码将非常有启发性。

对于其他图像格式,事情就没那么简单了 - 您需要解码图像并将其渲染到内存缓冲区,然后执行您自己的缩放。 CImg 和 boost::GIL 库可以为此提供帮助。

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.

脸赞 2024-08-09 09:32:07

我认为问题在于将图像转换为缩略图比首先获取图像需要更长的时间,对吗?

尽管更快的缩略图转换程序可能会为您解决问题,但对于计算机速度较慢的人来说可能还不够。相反,我建议创建一个要转换为缩略图的图像队列 - 即,您有一个线程(或进程)将扫描图像添加到队列中,另一个线程/进程从该队列中删除图像并从中创建缩略图。这样,两个操作的相对速度就无关紧要了。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文