|
||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.kde.koala.KPixmapIO
public class KPixmapIO
KPixmapIO implements a fast path for QPixmap to/from QImage conversions. It uses the MIT-SHM shared memory extension for this. If this extension is not available, it will fall back to standard Qt methods.
KPixmapIO io; pixmap = io.convertToPixmap(image); image = io.convertToImage(pixmap);It also has functionality for partially updating/saving pixmaps, see putImage and getImage. KPixmapIO vs. Qt speed comparison\n Speed measurements were taken. These show that usage of KPixmapIO for images up to a certain threshold size, offers no speed advantage over the Qt routines. Below you can see a plot of these measurements. The threshold size, amongst other causes, is determined by the shared memory allocation policy. If the policy is
ShmDontKeep
, the
shared memory segment is discarded right after usage, and thus needs to
be allocated before each transfer. This introduces a a setup penalty not
present when the policy is ShmKeepAndGrow.
In this case the
shared memory segment is kept and resized when necessary, until the
KPixmapIO object is destroyed.
The default policy is ShmDontKeep.
This policy makes sense when
loading pixmaps once. The corresponding threshold is taken at 5.000
pixels as suggested by experiments. Below this threshold, KPixmapIO
will not use shared memory and fall back on the Qt routines.
When the policy is ShmKeepAndGrow
, the threshold is taken at
2.000 pixels. Using this policy, you might want to use preAllocShm
to pre-allocate a certain amount of shared memory, in order to avoid
resizes. This allocation policy makes sense in a multimedia type
application where you are constantly updating the screen.
Above a couple times the threshold size, KPixmapIO's and Qt's speed become
linear in the number of pixels, KPixmapIO being at least 2, and mostly around
4 times faster than Qt, depending on the screen and image depth.
Speed difference seems to be the most at 16 bpp, followed by 32 and 24
bpp respectively. This can be explained by the relatively poor
implementation of 16 bit RGB packing in Qt, while at 32 bpp we need to
transfer more data, and thus gain more, than at 24 bpp.
Field Summary | |
---|---|
static int |
ShmDontKeep
Shared memory allocation policies. |
static int |
ShmKeepAndGrow
|
Constructor Summary | |
---|---|
|
KPixmapIO()
|
protected |
KPixmapIO(java.lang.Class dummy)
|
Method Summary | |
---|---|
org.kde.qt.QImage |
convertToImage(org.kde.qt.QPixmap pixmap)
Convert a pixmap to an image. |
org.kde.qt.QPixmap |
convertToPixmap(org.kde.qt.QImage image)
Convert an image to a pixmap. |
void |
dispose()
Delete the wrapped C++ instance ahead of finalize() |
protected void |
finalize()
Deletes the wrapped C++ instance |
org.kde.qt.QImage |
getImage(org.kde.qt.QPixmap src,
int sx,
int sy,
int sw,
int sh)
Transfer (a part of) a pixmap to an image. |
org.kde.qt.QImage |
getImage(org.kde.qt.QPixmap src,
org.kde.qt.QRect rect)
This function is identical to the one above. |
boolean |
isDisposed()
Has the wrapped C++ instance been deleted? |
void |
preAllocShm(int size)
Pre-allocate shared memory. |
void |
putImage(org.kde.qt.QPixmap dst,
int dx,
int dy,
org.kde.qt.QImage src)
Bitblt an image onto a pixmap. |
void |
putImage(org.kde.qt.QPixmap dst,
org.kde.qt.QPoint offset,
org.kde.qt.QImage src)
This function is identical to the one above. |
void |
setShmPolicy(int policy)
Set the shared memory allocation policy. |
Methods inherited from class java.lang.Object |
---|
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
public static final int ShmDontKeep
public static final int ShmKeepAndGrow
Constructor Detail |
---|
protected KPixmapIO(java.lang.Class dummy)
public KPixmapIO()
Method Detail |
---|
public org.kde.qt.QPixmap convertToPixmap(org.kde.qt.QImage image)
image
- The image to convert.
public org.kde.qt.QImage convertToImage(org.kde.qt.QPixmap pixmap)
pixmap
- The pixmap to convert.
public void putImage(org.kde.qt.QPixmap dst, int dx, int dy, org.kde.qt.QImage src)
dst
- The destination pixmap.dx
- Destination x offset.dy
- Destination y offset.src
- The image to load.public void putImage(org.kde.qt.QPixmap dst, org.kde.qt.QPoint offset, org.kde.qt.QImage src)
public org.kde.qt.QImage getImage(org.kde.qt.QPixmap src, int sx, int sy, int sw, int sh)
src
- The source pixmap.sx
- Source x offset.sy
- Source y offset.sw
- Source width.sh
- Source height.
public org.kde.qt.QImage getImage(org.kde.qt.QPixmap src, org.kde.qt.QRect rect)
public void setShmPolicy(int policy)
policy
- The alloction policy.public void preAllocShm(int size)
size
- The size of the image in pixels.
protected void finalize() throws java.lang.InternalError
finalize
in class java.lang.Object
java.lang.InternalError
public void dispose()
public boolean isDisposed()
|
||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |