98 || (h->offset <
sizeof(SharedImageHeader))
102 || (h->format <= QImage::Format_Invalid)
103 || (h->format >= QImage::NImageFormats)) {
107 const int depth = qt_depthForFormat(h->format);
108 if (h->bpl < (qint64(h->width) * depth + 7) / 8)
111 qint64 availSize = size - h->offset;
112 if (qint64(h->height) * h->bpl > availSize)
131#if QT_CONFIG(sharedmemory)
132 Q_Q(QSharedImageLoader);
138 auto shm = std::make_unique<QSharedMemory>(QSharedMemory::legacyNativeKey(q->key(path, params)));
141 if (!shm->attach(QSharedMemory::ReadOnly)) {
142 QImage img = q->loadFile(path, params);
145 size_t size =
sizeof(SharedImageHeader) + img.sizeInBytes();
146 if (size > size_t(std::numeric_limits<
int>::max())) {
147 qCDebug(lcSharedImage) <<
"Image" << path <<
"to large to load";
149 }
else if (shm->create(
int(size))) {
150 qCDebug(lcSharedImage) <<
"Created new shm segment of size" << size <<
"for image" << path;
152 qCDebug(lcSharedImage) <<
"Lock1 failed!?" << shm->errorString();
156 storeImageToMem(shm->data(), img);
157 }
else if (shm->error() == QSharedMemory::AlreadyExists) {
160 if (!shm->attach(QSharedMemory::ReadOnly)) {
161 qCDebug(lcSharedImage) <<
"Attach to existing failed?" << shm->errorString();
165 qCDebug(lcSharedImage) <<
"Create failed?" << shm->errorString();
170 Q_ASSERT(shm->isAttached());
174 qCDebug(lcSharedImage) <<
"Lock2 failed!?" << shm->errorString();
180 if (!verifyMem(shm->constData(), shm->size())) {
181 qCDebug(lcSharedImage) <<
"Verifymem failed!?";
186 QSharedMemory *shmp = shm.release();
187 SharedImageInfo *sii =
new SharedImageInfo;
190 QImage shImg = createImageFromMem(shmp->constData(), sii);
192 if (!shmp->unlock()) {
193 qCDebug(lcSharedImage) <<
"UnLock failed!?";