Well, it was leftover sort of. I had originally created one QImageReader, passed that pointer to all tiles, and used it to keep multiple threads for reading from the same file at once because I was getting some errors from libjpeg, libpng, etc. This made me think that was the issue.
Presently I get no errors, the image just doesnt load and look correct.
Well, it was leftover sort of. I had originally created one QImageReader, passed that pointer to all tiles, and used it to keep multiple threads for reading from the same file at once because I was getting some errors from libjpeg, libpng, etc. This made me think that was the issue.
Presently I get no errors, the image just doesnt load and look correct.
Here is the full code from my first try - passing a pointer to the reader into each tile:
Header:
class RasterTile : public Tile
{
public:
RasterTile
(QImageReader *reader,
int nBlocksX,
int nBlocksY,
int xoffset,
int yoffset,
int nXBlockSize,
int nYBlockSize
);
protected:
private:
};
class RasterTile : public Tile
{
public:
RasterTile (QImageReader *reader, int nBlocksX, int nBlocksY, int xoffset, int yoffset, int nXBlockSize, int nYBlockSize);
protected:
QImageReader *reader;
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option,QWidget *widget);
QImage LoadTilePixmap();
private:
mutable QMutex mutex;
};
To copy to clipboard, switch view to plain text mode
Cpp:
#include "rastertile.h"
RasterTile
::RasterTile(QImageReader *reader,
int nBlocksX,
int nBlocksY,
int xoffset,
int yoffset,
int nXBlockSize,
int nYBlockSize
) : Tile(nBlocksX, nBlocksY, xoffset, yoffset, nXBlockSize, nYBlockSize)
{
this->reader = reader;
connect(&watcher,SIGNAL(finished()),this,SLOT(updateSceneSlot()));
}
{
if(image.isNull())
{
TilePainter=painter;
TileOption=option;
TileWidget=widget;
future = QtConcurrent::run(this, &RasterTile::LoadTilePixmap);
watcher.setFuture(future);
}else
{
QRectF imageRect
= image.
rect();
painter->drawImage(imageRect, image);
}
}
QImage RasterTile
::LoadTilePixmap() {
QRect rect
(tilePosX
*nBlockXSize, tilePosY
*nBlockYSize, nBlockXSize, nBlockYSize
);
reader->setClipRect(rect);
reader->read(&img);
return img;
}
#include "rastertile.h"
RasterTile::RasterTile(QImageReader *reader, int nBlocksX, int nBlocksY, int xoffset, int yoffset, int nXBlockSize, int nYBlockSize)
: Tile(nBlocksX, nBlocksY, xoffset, yoffset, nXBlockSize, nYBlockSize)
{
this->reader = reader;
connect(&watcher,SIGNAL(finished()),this,SLOT(updateSceneSlot()));
}
void RasterTile::paint(QPainter *painter, const QStyleOptionGraphicsItem *option,QWidget *widget)
{
if(image.isNull())
{
TilePainter=painter;
TileOption=option;
TileWidget=widget;
future = QtConcurrent::run(this, &RasterTile::LoadTilePixmap);
watcher.setFuture(future);
}else
{
QRectF imageRect = image.rect();
painter->drawImage(imageRect, image);
}
}
QImage RasterTile::LoadTilePixmap()
{
QMutexLocker locker(&mutex);
QImage img(nBlockXSize, nBlockYSize, QImage::Format_RGB32);
QRect rect(tilePosX*nBlockXSize, tilePosY*nBlockYSize, nBlockXSize, nBlockYSize);
reader->setClipRect(rect);
reader->read(&img);
return img;
}
To copy to clipboard, switch view to plain text mode
How I am instantiating the classes:
for(int i =0; i < nXBlocks; i++)
{
for(int j = 0; j < nYBlocks; j++)
{
RasterTile *ipi = new RasterTile(reader,nXBlocks, nYBlocks, i, j, nXBlockSize, nYBlockSize);
}
}
for(int i =0; i < nXBlocks; i++)
{
for(int j = 0; j < nYBlocks; j++)
{
RasterTile *ipi = new RasterTile(reader,nXBlocks, nYBlocks, i, j, nXBlockSize, nYBlockSize);
}
}
To copy to clipboard, switch view to plain text mode
After this try, is when i started trying to make the mutex private, and then also passing in just the file name so each Tile could create it's own reader.
"image" is a QImage that gets set to the img from "LoadTilePixmap()" and is set in the Tile::updateSceneSlot()
Bookmarks