Qt handles editable images thanks to the QImage class.
However, this class does not provide advanced edition utilities.
XQImageTools offers some useful functions to help you work around this lack.

With XQImageTools, you can :

  • filter channels (red, green, blue or alpha) from a source image in order to keep only those you need,
  • combine channels between images,
  • converts an image to its grayscale equivalent,
  • rescale an image to its nearest power-of-2 equivalent (very useful for texture generation),
  • checks if two QImage objects contains different image data.


Filtering channels

Let’s considering you want to filter channels an image in order to keep only green and blue ones.

Combining channels

Let’s considering now you want to combine red and alpha channel from one source image and green and blue from one another.

Converting to grayscale

Building a texture

What if you need a texture from one of you images ?
Realtime engines requires that textures uses power-of-2 dimensions.
The toPower2() function helps you to build automatically this kind of images.

In this first example, the source image will be rescaled to have power-of-2 dimensions.
Those dimensions are found automatically by choosing the nearest power-of-2 values for each side.
For example, a 25 x 23 picture will be resized to a 32 x 16 picture.

The toPower2() function can also build square textures.
In this case, the square is generated using the biggest or the tinyest dimension from the power-of-2 texture at your own will.


Public enums

Thanks to the QFlags class you can use this enum with the standard binary operators to combine them.
Use this enum to select channels with filterChannels() and combineChannels() functions.

Use this enum to select squaring method when calling toPower2().

Static public members

Filters channels from a source image in order to keep only selected ones.

  • srcImage : Source image reference
  • kept : Selected filter flags

The function returns a new QImage object containing only selected channels from the source one.

Combines channels from two images in order to compose a third one.

  • srcImage1 : First source image
  • combine1 : Filter flags for the first source image
  • srcImage2 : Second source image
  • combine2 : Filter flags for the second source image

The function returns a QImage combining channels from the two source ones.

Converts an image to its grayscale equivalent.

  • srcImage : Source image
  • keepAlpha : If set, the alpha channel of the source image is kept untouched. If not, the alpha channel is not preserved.

The functions returns a new QImage containing only grayscale values, and eventually an alpha channel.

Rescales an image to make its dimensions fit the nearest power of 2. Useful for generating textures from random images.

  • srcImage : Source image
  • transformMode : Qt transformation mode flag. See Qt’s documentation for further information.
  • squaring : Squaring mode

The function returns a scaled, eventually square, image with power-of-2 dimensions.

Checks if two images contain different data.

  • refImage : reference image
  • othImage : other image to compare

The function returns true if the images are different, false either.


Zip archive (2,5 KB)


XQImageTools is released under the GNU GPL v2.
Permission to use, copy, modify, and distribute this software and its documentation under the terms of the GNU General Public License is hereby granted. No representations are made about the suitability of this software for any purpose. It is provided “as is” without express or implied warranty.


Comments are closed.