PDA

View Full Version : Filling QPixmap from an unsigned short array? QPixmap size limitations?



hickscorp
8th April 2007, 23:43
Hello,

My questions are fast and simple ^^

1a) Is there any way to fill a QPixmap from 3 unsigned shorts arrays (Each pixel has 16 bits per channel)? Of course i'm not talking of iterating on each pixel with a QPainter, doing a setPen with my 3 channels colors, and then a drawPoint on the QPixmap, since it's way too slow...

1b) Each of my channel can have a value between 0 and 65535 (16 bits). So i'm talking about a very "fast conversion copy", changing from 16 bits in original to 8 in the QPixmap.

1c) If the answer is clearly no, does the same question but with shorts instead of unsigned shorts have another answer? ^^

Telling me to "change to 8 bits per channel because the human eye only perceive N colors" is not an answer for me, since it's not related to human eye but to medical images processment... 16 bits per channel i have no choice ^^

2) Also, i have read somewhere that a QPixmap is limited in size to 2000x2000 pixels... Is it true? If yes, is there a workaround for this, knowing i'm using the QPixmap in a QGraphicsView linked to a QGraphicsScene?

Thanks for your answers.
Pierre.

jacek
9th April 2007, 00:21
It looks like such format isn't supported by QImage and you can create pixmaps only for data in the format for which a plugin exists.

Maybe you can try CreateBitmap() and QPixmap::fromWinHBITMAP()?

Another way is OpenGL.

marcel
9th April 2007, 06:02
2) Also, i have read somewhere that a QPixmap is limited in size to 2000x2000 pixels... Is it true? If yes, is there a workaround for this, knowing i'm using the QPixmap in a QGraphicsView linked to a QGraphicsScene?


Yes, it happened to me. But the limitation is not strictly 2000x2000. On some computers was smaller.

The workaround depends on what you are doing. I was drawing a very long raster on a widget ( sometimes 5-6000 pixels ). I solved it by splitting this one pixmap into an array of pixmaps, each 500 pixels wide ( could have been bigger, but just to be sure ). The, I painted all the pixmaps in the array next to each other, to obtain the same efect as if there was only one pixmap.

hickscorp
9th April 2007, 13:42
Hello and thanks for replying ^^

Jacek:
i can't use the QPixmap::fromWinHBITMAP() method, since the application is not windows only (Photoshop runs on Mac too, and there will probably be a non-plugin version of the application in the nearby future).
Now i see you suggest me to use OpenGL. I have a few questions about this:
The application is aimed to be deployed on computers which have reasonable RAM and CPU... However, we can't be sure of the video card. So if i use OpenGL and the user has a "crappy" video card, what will happend?
About using OpenGL, what do you suggest? Using two OpenGL viewports (2D), and drawing on a "texture" (My knowledge of OpenGL is very low... If you have any suggestions i will appreciate you go further in details ^^)?

Marcel:
Your suggestion sounds very nice, so here is a question relative to your answer:
Let's suppose i have a 1600*1200 picture. i will split it onto 500x500 blocks as you say "to be sure". Then i'll draw those blocks on my graphic scene, but what will happend if the user zoom to the "glued" parts of the blocks? Did you try successfully this? Did some "white lines glitch" appear?

Thanks again!
Pierre.

marcel
9th April 2007, 13:52
As I said, I was drawing on a widget( a QAbstractButton ), so no zooming occurred in my case.

However, using a QGraphicsView, if the integer distance between the blocks is 0 or the floating point distance is as close as possible to 0 then I tend to believe no background will show through. All I am trying to say is to make the distance between the blocks
as small as possible ( 0 if you can ).

I used the (500, 500) size because I had no way of knowing exactly the limitation, so this size seemed reasonable enough. BTW, the effect of large pixmaps is that they are not painted or if you try to paint inside the pixmap something Qt will crash( somewhere in QPaintEngine ).

Regards

jacek
9th April 2007, 14:26
i can't use the QPixmap::fromWinHBITMAP() method, since the application is not windows only
There's also QPixmap::fromMacCGImageRef(), so you could use both. Maybe the Trolls know how to create a QPixmap with arbitrary depth?


So if i use OpenGL and the user has a "crappy" video card, what will happend?
You are not going to use any 3D stuff, so the only problem might be the maximum texture size.

Although OpenGL can store textures in RGB16 and RGBA16 formats, it seems that there is no direct way to feed it with such data. Take a look at glDrawPixels() and glTexImage2D(), you might be able to draw one 16bit component at a time and with help of blending you should get original image.