2

I have a very big image (31000X26000 pixels). I need to create tiles of a given size from this image and store them. I'm trying to use Qt's QImagereader but I've notice that after setClipRect for the second time, it can't read from the image. The code I have so far works, but is very slow (this first row takes 7 seconds, the second 14, the third 21 and so on...)

for (int i = 0; i < tilesPerRow; i++){

    for (int j = 0; j < tilesPerCol; j++){
        QImageReader reader(curImage);
        reader.setClipRect(QRect(j*(tileSize-OVERLAP),i*(tileSize-OVERLAP),tileSize,tileSize));
        QImage img = reader.read();
        if (img.isNull())
            qDebug() << reader.errorString();
        else{
            retImg.setTile(img,i,j);
        }
    }
}

What am I doing wrong? Is it reasonable that I have to create a new reader each time? Does the location of the tile I'm trying to access affects speed and performance? If you have any suggestions on a better practice, I would appreciate it

eyllanesc
  • 235,170
  • 19
  • 170
  • 241
JLev
  • 705
  • 1
  • 9
  • 30
  • You say "after setClipRect for the second time, it can't read from the image" -- what [error](http://doc.qt.io/qt-5/qimagereader.html#error) do you get? – G.M. Aug 10 '17 at 10:22
  • What format is the image? – dtech Aug 10 '17 at 10:37
  • I get "Unable to read image data", error number 4 – JLev Aug 10 '17 at 10:37
  • the image is jpg – JLev Aug 10 '17 at 10:37
  • Well, it will be slow, because that's an encoded format, it will probably have to decode the whole thing every time you read a tile. If it was a raw image it would be trivial. – dtech Aug 10 '17 at 10:38
  • The first time probably works because you are starting from the beginning, but after that it has to do more decoding before it gets the region of interest specified, so you are most likely running out of ram and it fails. – dtech Aug 10 '17 at 10:52
  • After a painful conversion to bmp, it doesn't slow over time. But still I have the issue with reading the image every time. I still can't create one imagereader and use it. any help? – JLev Aug 10 '17 at 12:19

0 Answers0