[Qt-interest] Interested in Tiling large images
Cole, Derek
dcole at integrity-apps.com
Thu Jun 9 23:30:50 CEST 2011
I think I am kind of leaning toward doing the tiling within a QGraphicsItem subclass. The reason for this, is that zooming and such could get quite complicated if I have a bunch of QGraphicsItems, right? I have already implemented a QGraphicsItem subclass anyway, because I wanted to be able to mouse-over individual graphics items and zoom them. If I had a bunch of QGraphicsItems in the scene, I would have to loop over each one, and zoom it the appropriate amount, AND move it the right around to keep the edges touching to provide a contious image. That seems like a ton of work.
I think I basically am stuck using QGraphicsView for now at least. We do some of the vector overlays and a few other things that are nice.
If I am going to implement Tiling from within a QGraphicsItem subclass - how could that work? I would want to probably pre-load image tiles that are just outside the graphics view window, right? It seems like it would be inefficient to have to repaint the entire QGraphicsItem essentially if the view was zoomed out so far that the entire large image(or most of it) fit within the graphics view
-----Original Message-----
From: Ross Bencina [mailto:rossb-lists at audiomulch.com]
Sent: Thursday, June 09, 2011 3:03 PM
To: Cole, Derek
Subject: Re: [Qt-interest] Interested in Tiling large images
Derek Cole wrote:
> Presently, I have been putting my smaller sample images into
> QGraphicsPixmapItems.
> This generally requires generating a QImage from the raw byte data,
> pixmap from the QImage, and then sticking that pixmap into an item,
> and putting the item on the scene.
Another option would be to implement your own QGraphicsItem subclass that only renders the needed portions to screen. Probably keeping a cache of sub-tiles.
> Apparently one of these items has a limit on the size - could someone
> point me to the max constraints on these images?
Sorry not sure about that.
> I have had no problem with my smaller test images that were about
> 8192^2 pixels. These test image are about 35000^2.
I wonder if something has a 16 bit coordinate limit (>32768)
> It seems like I may have to go with some kind of tiling strategy..
> can anyone point me to how that generally works?
Googling for
"tiling algorithm"
"image tiling algorithm"
"bitmap tiling"
gives some results
> I want to be able to view pan the image, zoom in/out, etc etc.
> I already have code for doing this on those QGraphicsItems.
> How do I tell which tiles to load(on the edge of my qgraphicsview I
> guess?), which to discard(not visible in my qgraphicsview?),
I guess you have the option of either implementing one big QGraphicsItem and implementing the tiling inside it, or having one QGraphicsItem for each tile. Either way you'll need a cache of in-memory QImages and a way to keep the working set down (an LRU strategy with a cache size limit around twice the visible image area might be one way to handle it). If the files don't fit in RAM you'll also need to worry about asynchronous loading and re-painting once the block is loaded and decompressed -- QGraphicsItems for each block could help here, since you just paint background and then call
update() when the data has finished loading.
> how to translate what is on the screen to a position in the physical
> data file, etc?
If you have separate QGraphicsItems for each tile, they can know their position in the file.
Overall I think you have a trade-off between writing something direct like Boudewijn suggests or trying to shoehorn it into QGraphicsView. I think the answer will depend on whether you want to use GraphicsView for vector overlays etc etc, in which case it will solve some problems for you.
Ross.
More information about the Qt-interest-old
mailing list