Как повысить производительность чтения необработанных данных в объект QImage? - PullRequest
0 голосов
/ 25 мая 2020

Я читаю файлы TIFF и извлекаю данные каждого n-го пикселя для создания небольших эскизов. Все работает, но хотелось бы улучшить производительность. Создание миниатюры размером 256 пикселей занимает ~ 40 мсек на чтение файла tiff с SSD.

QByteArray ba;
QFile file;
QImage im;
quint32 offset;
// load file, get offset to strip offsets etc not included in example
// read nth pixels from a tiff file scanline
for (int x = 0; x < w; ++x) {
    file.seek(offset);
    ba += file.read(bytesPerPixel);
    offset += static_cast<uint>(nth * bytesPerPixel);
}
std::memcpy(im->scanLine(line), ba, static_cast<size_t>(newBytesPerLine));

Я также пробовал функцию Qt QFile :: map, которая была медленнее

for (int x = 0; x < w; x++) {
    std::memcpy(im->scanLine(line) + x * bytesPerPixel, 
                file.map(offset, bytesPerPixel), 
                static_cast<size_t>(newBytesPerLine));    
    offset += static_cast<uint>(nth * bytesPerPixel);
}
...