QImage/QPixmap 大小限制?

发布于 2024-11-30 03:21:27 字数 632 浏览 0 评论 0原文

是否有记录的 QPixmap 和/或 QImage 对象的任何已知大小/空间限制?我没有找到任何与此相关的有用信息。我目前在 OSX 和 Windows 上使用 Qt 4.7.3。我特别感兴趣的是:

  • 宽度/高度限制?
  • 限制取决于颜色格式?
  • 32/64位机的区别?
  • 关于操作系统的差异?

我天真地怀疑内存是唯一的限制,所以可以通过以下方式计算最大大小

宽度 x 高度 x 每个像素字节

我假设有一个更详细的经验法则;当您遇到 GB 尺寸时,32 位机器也可能会出现寻址问题。

最后,我想存储多个大小约为 16000x16000 像素的 RGBA 图像,并在 QGraphicsScene 中使用透明度将它们渲染到彼此上。可用的工作站可以有大量 RAM,比如说 16GB。

tl;dr:您知道 QImage/QPixmap 的大小限制是什么,或者我在哪里可以找到此类信息?

编辑: 我知道平铺方法,并且我我对此没意见。尽管如此,了解上述内容还是很高兴的。

谢谢!

Are there any known size/space limitation of QPixmap and/or QImage objects documented? I did not find any useful information regarding this. I'm currently using Qt 4.7.3 on OSX and Windows. Particulary I'm interested in:

  • Width/Height limits?
  • Limits depending on color format?
  • Difference between 32/64 bit machines?
  • Difference regarding OS?

I would naively suspect that memory is the only limitation, so one could calculate max size by

width x height x byte_per_pixel

I assume that there is a more elaborate rule of thumb; also 32 bit machines may have addressing problems when you run into GB dimensions.

In the end I want to store multiple RGBA images of about 16000x16000 pixel in size and render them using transparency onto each other within a QGraphicsScene. The workstation available can have a lot of RAM, let's say 16GB.

tl;dr: What size limits of QImage/QPixmap are you aware of, or where can I find such information?

Edit: I'm aware of the tiling approach and I'm fine with that. Still it would be great to know the things described above.

Thanks!

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

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

发布评论

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

评论(5

樱娆 2024-12-07 03:21:27

两者都限制为 32767x32767 像素。也就是说,您可以将它们视为对 X 和 Y 分辨率使用带符号的 16 位值。

任何轴都不能超过 32767 像素,即使另一个轴只有 1 像素。操作系统“位数”不影响该限制。
在创建如此巨大的图像之前,底层系统可能会遇到其他限制,例如您提到的内存。

您可以在以下源代码中看到此限制的示例:
http://git.zx2c4.com/qt/plain/src /gui/image/qpixmap_x11.cpp

if (uint(w) >= 32768 || uint(h) >= 32768) {
    w = h = 0;
    is_null = true;
    return;
}

Both are limited to 32767x32767 pixels. That is, you can think of them as using a signed 16-bit value for both the X and Y resolution.

No axis can ever exceed 32767 pixels, even if the other axis is only 1 pixel. Operating system "bitness" does not affect the limitation.
The underlying system may run into other limits, such as memory as you mentioned, before such a huge image can be created.

You can see an example of this limitation in the following source code:
http://git.zx2c4.com/qt/plain/src/gui/image/qpixmap_x11.cpp

if (uint(w) >= 32768 || uint(h) >= 32768) {
    w = h = 0;
    is_null = true;
    return;
}
Saygoodbye 2024-12-07 03:21:27

基于@charles-burns的答案,这里是QImage的相关源代码:

QImageData *d = 0;

if (format == QImage::Format_Invalid)
    return d;

const int depth = qt_depthForFormat(format);
const int calc_bytes_per_line = ((width * depth + 31)/32) * 4;
const int min_bytes_per_line = (width * depth + 7)/8;

if (bpl <= 0)
    bpl = calc_bytes_per_line;

if (width <= 0 || height <= 0 || !data
    || INT_MAX/sizeof(uchar *) < uint(height)
    || INT_MAX/uint(depth) < uint(width)
    || bpl <= 0
    || height <= 0
    || bpl < min_bytes_per_line
    || INT_MAX/uint(bpl) < uint(height))
    return d;                                        // invalid parameter(s)

所以这里,bpl是每行的字节数,实际上是宽度*深度字节数。在最终无效测试中使用代数:

  • INT_MAX/uint(bpl) INT_MAX/uint(bpl) INT_MAX/uint(bpl) uint(高度)
  • INT_MAX < uint(高度) * uint(bpl)
  • INT_MAX < height * width * height_in_bytes

因此,您的图像总大小必须小于 2147483647(对于 32 位整数)。

Building on the answer by @charles-burns, here is relevant source code for QImage:

QImageData *d = 0;

if (format == QImage::Format_Invalid)
    return d;

const int depth = qt_depthForFormat(format);
const int calc_bytes_per_line = ((width * depth + 31)/32) * 4;
const int min_bytes_per_line = (width * depth + 7)/8;

if (bpl <= 0)
    bpl = calc_bytes_per_line;

if (width <= 0 || height <= 0 || !data
    || INT_MAX/sizeof(uchar *) < uint(height)
    || INT_MAX/uint(depth) < uint(width)
    || bpl <= 0
    || height <= 0
    || bpl < min_bytes_per_line
    || INT_MAX/uint(bpl) < uint(height))
    return d;                                        // invalid parameter(s)

So here, bpl is the number of bytes per line, which is effectively width * depth_in_bytes. Using algebra on that final invalid test:

  • INT_MAX/uint(bpl) < uint(height)
  • INT_MAX < uint(height) * uint(bpl)
  • INT_MAX < height * width * depth_in_bytes

So, your image size in total must be less than 2147483647 (for 32-bit ints).

不再让梦枯萎 2024-12-07 03:21:27

我实际上曾经有机会研究过这个问题。在 qimage.cpp 的源代码中搜索“潜在溢出的健全性检查”,您可以看到 Qt 正在执行的检查。基本上,

  • 所需的字节数(宽度*高度*深度_for_format)必须小于INT_MAX
  • 它必须能够在您创建 QImage 实例时malloc 这些字节。

I actually had occasion to look into this at one time. Do a search in the source code of qimage.cpp for "sanity check for potential overflows" and you can see the checks that Qt is doing. Basically,

  • The number of bytes required (width * height * depth_for_format) must be less than INT_MAX.
  • It must be able to malloc those bytes at the point you are creating the QImage instance.
稀香 2024-12-07 03:21:27

您正在构建 64 位应用程序吗?如果没有,您很快就会遇到内存问题。在Windows上,即使机器有16GB RAM,32位进程也将被限制为2GB(除非是LARGEADDRESSAWARE则为3GB)。 16000x16000 图像的大小将略低于 1 GB,因此您只能为 1 个(如果您非常幸运的话,也许 2 个)分配足够的内存。

使用 64 位应用程序,您应该能够为多个图像分配足够的内存。

Are you building a 64 bit app? If not, you are going to run into memory issues very quickly. On Windows, even if the machine has 16GB ram, a 32 bit process will be limited to 2GB (Unless it is LARGEADDRESSAWARE then 3GB). A 16000x16000 image will be just under 1 GB, so you'll only be able to allocate enough memory for 1, maybe 2 if you are very lucky.

With a 64 bit app you should be able to allocate enough memory for several images.

没有你我更好 2024-12-07 03:21:27

当我尝试将大小为 6160x4120 的 JPEG 加载到 QPixmap 时,我收到此警告:“qt.gui.imageio:QImageIOHandler:拒绝图像,因为它超出了 128 兆字节的当前分配限制” 并返回空的QPixmap

这似乎是迄今为止我发现的最严格的限制。

不过,可以选择使用 void QImageReader::setAllocationLimit(int mbLimit) 来增加此限制。

When I try to load JPEG with size 6160x4120 to QPixmap I get this warning: "qt.gui.imageio: QImageIOHandler: Rejecting image as it exceeds the current allocation limit of 128 megabytes" and returns empty QPixmap.

This seems to be the most strict constraint I have found so far.

There is however an option to increase this limit with void QImageReader::setAllocationLimit(int mbLimit).

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