Home | All Classes | Main Classes | Annotated | Grouped Classes | Functions |
The TQImage class provides a hardware-independent pixmap representation with direct access to the pixel data. More...
#include <tqimage.h>
It is one of the two classes TQt provides for dealing with images, the other being TQPixmap. TQImage is designed and optimized for I/O and for direct pixel access/manipulation. TQPixmap is designed and optimized for drawing. There are (slow) functions to convert between TQImage and TQPixmap: TQPixmap::convertToImage() and TQPixmap::convertFromImage().
An image has the parameters width, height and depth (bits per pixel, bpp), a color table and the actual pixels. TQImage supports 1-bpp, 8-bpp and 32-bpp image data. 1-bpp and 8-bpp images use a color lookup table; the pixel value is a color table index.
32-bpp images encode an RGB value in 24 bits and ignore the color table. The most significant byte is used for the alpha buffer.
An entry in the color table is an RGB triplet encoded as a uint. Use the tqRed(), tqGreen() and tqBlue() functions (tqcolor.h) to access the components, and tqRgb to make an RGB triplet (see the TQColor class documentation).
1-bpp (monochrome) images have a color table with a most two colors. There are two different formats: big endian (MSB first) or little endian (LSB first) bit order. To access a single bit you will must do some bit shifts:
TQImage image; // sets bit at (x,y) to 1 if ( image.bitOrder() == TQImage::LittleEndian ) *(image.scanLine(y) + (x >> 3)) |= 1 << (x & 7); else *(image.scanLine(y) + (x >> 3)) |= 1 << (7 - (x & 7));
If this looks complicated, it might be a good idea to convert the 1-bpp image to an 8-bpp image using convertDepth().
8-bpp images are much easier to work with than 1-bpp images because they have a single byte per pixel:
TQImage image; // set entry 19 in the color table to yellow image.setColor( 19, tqRgb(255,255,0) ); // set 8 bit pixel at (x,y) to value yellow (in color table) *(image.scanLine(y) + x) = 19;
32-bpp images ignore the color table; instead, each pixel contains the RGB triplet. 24 bits contain the RGB value; the most significant byte is reserved for the alpha buffer.
TQImage image; // sets 32 bit pixel at (x,y) to yellow. uint *p = (uint *)image.scanLine(y) + x; *p = tqRgb(255,255,0);
The scanlines are 32-bit aligned for all depths. The constructor taking a uchar* argument always expects 32-bit aligned data.
TQImage supports a variety of methods for getting information about the image, for example, colorTable(), allGray(), isGrayscale(), bitOrder(), bytesPerLine(), depth(), dotsPerMeterX() and dotsPerMeterY(), hasAlphaBuffer(), numBytes(), numColors(), and width() and height().
Pixel colors are retrieved with pixel() and set with setPixel().
TQImage also supports a number of functions for creating a new image that is a transformed version of the original. For example, copy(), convertBitOrder(), convertDepth(), createAlphaMask(), createHeuristicMask(), mirror(), scale(), smoothScale(), swapRGB() and xForm(). There are also functions for changing attributes of an image in-place, for example, setAlphaBuffer(), setColor(), setDotsPerMeterX() and setDotsPerMeterY() and setNumColors().
Images can be loaded and saved in the supported formats. Images are saved to a file with save(). Images are loaded from a file with load() (or in the constructor) or from an array of data with loadFromData(). The lists of supported formats are available from inputFormatList() and outputFormatList().
Strings of text may be added to images using setText().
The TQImage class uses explicit sharing, similar to that used by TQMemArray.
New image formats can be added as plugins.
See also TQImageIO, TQPixmap, Shared Classes, Graphics Classes, Image Processing Classes, and Implicitly and Explicitly Shared Classes.
This enum type is used to describe the endianness of the CPU and graphics hardware.
The functions scale() and smoothScale() use different modes for scaling the image. The purpose of these modes is to retain the ratio of the image if this is required.
See also isNull().
Using this constructor is the same as first constructing a null image and then calling the create() function.
See also create().
Using this constructor is the same as first constructing a null image and then calling the create() function.
See also create().
If format is specified, the loader attempts to read the image using the specified format. If format is not specified (which is the default), the loader reads a few bytes from the header to guess the file format.
If the loading of the image failed, this object is a null image.
The TQImageIO documentation lists the supported image formats and explains how to add extra formats.
See also load(), isNull(), and TQImageIO.
Errors are silently ignored.
Note that it's possible to squeeze the XPM variable a little bit by using an unusual declaration:
static const char * const start_xpm[]={ "16 15 8 1", "a c #cec6bd", ....
The extra const makes the entire definition read-only, which is slightly more efficient (e.g. when the code is in a shared library) and ROMable when the application is to be stored in ROM.
If the loading of the image failed, this object is a null image.
See also loadFromData(), isNull(), and imageFormat().
If colortable is 0, a color table sufficient for numColors will be allocated (and destructed later).
Note that yourdata must be 32-bit aligned.
The endianness is given in bitOrder.
This function is slow for large 32-bit images.
See also isGrayscale().
Returns the bit order for the image.
If it is a 1-bpp image, this function returns either TQImage::BigEndian or TQImage::LittleEndian.
If it is not a 1-bpp image, this function returns TQImage::IgnoreEndian.
See also depth().
Returns a pointer to the first pixel data. This is equivalent to scanLine(0).
See also numBytes(), scanLine(), and jumpTable().
Example: opengl/texture/gltexobj.cpp.
Returns the number of bytes per image scanline. This is equivalent to numBytes()/height().
See also numBytes() and scanLine().
Returns the color in the color table at index i. The first color is at index 0.
A color value is an RGB triplet. Use the tqRed(), tqGreen() and tqBlue() functions (defined in tqcolor.h) to get the color value components.
See also setColor(), numColors(), and TQColor.
Example: themes/wood.cpp.
Returns a pointer to the color table.
See also numColors().
Returns *this if the bitOrder is equal to the image bit order, or a null image if this image cannot be converted.
See also bitOrder(), systemBitOrder(), and isNull().
The depth argument must be 1, 8 or 32.
Returns *this if depth is equal to the image depth, or a null image if this image cannot be converted.
If the image needs to be modified to fit in a lower-resolution result (e.g. converting from 32-bit to 8-bit), use the conversion_flags to specify how you'd prefer this to happen.
See also TQt::ImageConversionFlags, depth(), and isNull().
If the image needs to be modified to fit in a lower-resolution result (e.g. converting from 32-bit to 8-bit), use the conversion_flags to specify how you'd prefer this to happen.
Note: currently no closest-color search is made. If colors are found that are not in the palette, the palette may not be used at all. This result should not be considered valid because it may change in future implementations.
Currently inefficient for non-32-bit images.
See also TQt::ImageConversionFlags.
See also detach().
Returns a deep copy of a sub-area of the image.
The returned image is always w by h pixels in size, and is copied from position x, y in this image. In areas beyond this image pixels are filled with pixel 0.
If the image needs to be modified to fit in a lower-resolution result (e.g. converting from 32-bit to 8-bit), use the conversion_flags to specify how you'd prefer this to happen.
See also bitBlt() and TQt::ImageConversionFlags.
Returns a deep copy of a sub-area of the image.
The returned image always has the size of the rectangle r. In areas beyond this image pixels are filled with pixel 0.
The width and height is limited to 32767. depth must be 1, 8, or 32. If depth is 1, bitOrder must be set to either TQImage::LittleEndian or TQImage::BigEndian. For other depths bitOrder must be TQImage::IgnoreEndian.
This function allocates a color table and a buffer for the image data. The image data is not initialized.
The image buffer is allocated as a single block that consists of a table of scanline pointers (jumpTable()) and the image data (bits()).
See also fill(), width(), height(), depth(), numColors(), bitOrder(), jumpTable(), scanLine(), bits(), bytesPerLine(), and numBytes().
See TQPixmap::convertFromImage() for a description of the conversion_flags argument.
The returned image has little-endian bit order, which you can convert to big-endianness using convertBitOrder().
See also createHeuristicMask(), hasAlphaBuffer(), and setAlphaBuffer().
The four corners vote for which color is to be masked away. In case of a draw (this generally means that this function is not applicable to the image), the result is arbitrary.
The returned image has little-endian bit order, which you can convert to big-endianness using convertBitOrder().
If clipTight is TRUE the mask is just large enough to cover the pixels; otherwise, the mask is larger than the data pixels.
This function disregards the alpha buffer.
See also createAlphaMask().
Returns the depth of the image.
The image depth is the number of bits used to encode a single pixel, also called bits per pixel (bpp) or bit planes of an image.
The supported depths are 1, 8 and 32.
See also convertDepth().
If multiple images share common data, this image makes a copy of the data and detaches itself from the sharing mechanism. Nothing is done if there is just a single reference.
See also copy().
Example: themes/wood.cpp.
Returns the number of pixels that fit horizontally in a physical meter. This and dotsPerMeterY() define the intended scale and aspect ratio of the image.
See also setDotsPerMeterX().
Returns the number of pixels that fit vertically in a physical meter. This and dotsPerMeterX() define the intended scale and aspect ratio of the image.
See also setDotsPerMeterY().
If the depth of this image is 1, only the lowest bit is used. If you say fill(0), fill(2), etc., the image is filled with 0s. If you say fill(1), fill(3), etc., the image is filled with 1s. If the depth is 8, the lowest 8 bits are used.
If the depth is 32 and the image has no alpha buffer, the pixel value is written to each pixel in the image. If the image has an alpha buffer, only the 24 RGB bits are set and the upper 8 bits (alpha value) are left unchanged.
Note: TQImage::pixel() returns the color of the pixel at the given coordinates; TQColor::pixel() returns the pixel value of the underlying window system (essentially an index value), so normally you will want to use TQImage::pixel() to use a color from an existing image or TQColor::rgb() to use a specific color.
See also invertPixels(), depth(), hasAlphaBuffer(), and create().
See also TQMimeSourceFactory, TQImage::fromMimeSource(), and TQImageDrag::decode().
Returns TRUE if alpha buffer mode is enabled; otherwise returns FALSE.
See also setAlphaBuffer().
Returns the height of the image.
See also width(), size(), and rect().
Examples: canvas/canvas.cpp and opengl/texture/gltexobj.cpp.
The TQImageIO documentation lists the guaranteed supported image formats, or use TQImage::inputFormats() and TQImage::outputFormats() to get lists that include the installed formats.
Note that if you want to iterate over the list, you should iterate over a copy, e.g.
TQStringList list = myImage.inputFormatList(); TQStringList::Iterator it = list.begin(); while( it != list.end() ) { myProcessing( *it ); ++it; }
See also outputFormatList(), inputFormats(), and TQImageIO.
Example: showimg/showimg.cpp.
See also outputFormats(), inputFormatList(), and TQImageIO.
If the depth is 32: if invertAlpha is TRUE, the alpha bits are also inverted, otherwise they are left unchanged.
If the depth is not 32, the argument invertAlpha has no meaning.
Note that inverting an 8-bit image means to replace all pixels using color index i with a pixel using color index 255 minus i. Similarly for a 1-bit image. The color table is not changed.
See also fill(), depth(), and hasAlphaBuffer().
For 8-bpp images, this function returns TRUE if color(i) is TQRgb(i,i,i) for all indices of the color table; otherwise returns FALSE.
See also allGray() and depth().
Returns TRUE if it is a null image; otherwise returns FALSE.
A null image has all parameters set to zero and no allocated data.
Example: showimg/showimg.cpp.
Returns a pointer to the scanline pointer table.
This is the beginning of the data block for the image.
See also bits() and scanLine().
If format is specified, the loader attempts to read the image using the specified format. If format is not specified (which is the default), the loader reads a few bytes from the header to guess the file format.
The TQImageIO documentation lists the supported image formats and explains how to add extra formats.
See also loadFromData(), save(), imageFormat(), TQPixmap::load(), and TQImageIO.
If format is specified, the loader attempts to read the image using the specified format. If format is not specified (which is the default), the loader reads a few bytes from the header to guess the file format.
The TQImageIO documentation lists the supported image formats and explains how to add extra formats.
See also load(), save(), imageFormat(), TQPixmap::loadFromData(), and TQImageIO.
Loads an image from the TQByteArray buf.
Returns a mirror of the image, mirrored in the horizontal and/or the vertical direction depending on whether horizontal and vertical are set to TRUE or FALSE. The original image is not changed.
See also smoothScale().
Returns the number of bytes occupied by the image data.
See also bytesPerLine() and bits().
Returns the size of the color table for the image.
Notice that numColors() returns 0 for 32-bpp images because these images do not use color tables, but instead encode pixel values as RGB triplets.
See also setNumColors() and colorTable().
Example: themes/wood.cpp.
Returns the number of pixels by which the image is intended to be offset by when positioning relative to other images.
See also operator=().
See also copy().
Sets the image bits to the pixmap contents and returns a reference to the image.
If the image shares data with other images, it will first dereference the shared data.
Makes a call to TQPixmap::convertToImage().
See also operator=().
Note that if you want to iterate over the list, you should iterate over a copy, e.g.
TQStringList list = myImage.outputFormatList(); TQStringList::Iterator it = list.begin(); while( it != list.end() ) { myProcessing( *it ); ++it; }
See also inputFormatList(), outputFormats(), and TQImageIO.
See also inputFormats(), outputFormatList(), and TQImageIO.
Example: showimg/showimg.cpp.
If (x, y) is not on the image, the results are undefined.
See also setPixel(), tqRed(), tqGreen(), tqBlue(), and valid().
Examples: canvas/canvas.cpp and qmag/qmag.cpp.
If (x, y) is not valid, or if the image is not a paletted image (depth() > 8), the results are undefined.
Returns the enclosing rectangle (0, 0, width(), height()) of the image.
See also width(), height(), and size().
Returns TRUE if the image was successfully saved; otherwise returns FALSE.
See also load(), loadFromData(), imageFormat(), TQPixmap::save(), and TQImageIO.
This function writes a TQImage to the TQIODevice, device. This can be used, for example, to save an image directly into a TQByteArray:
TQImage image; TQByteArray ba; TQBuffer buffer( ba ); buffer.open( IO_WriteOnly ); image.save( &buffer, "PNG" ); // writes image into ba in PNG format
If either the width w or the height h is 0 or negative, this function returns a null image.
This function uses a simple, fast algorithm. If you need better quality, use smoothScale() instead.
See also scaleWidth(), scaleHeight(), smoothScale(), and xForm().
The requested size of the image is s.
If h is 0 or negative a null image is returned.
See also scale(), scaleWidth(), smoothScale(), and xForm().
Example: table/small-table-demo/main.cpp.
If w is 0 or negative a null image is returned.
See also scale(), scaleHeight(), smoothScale(), and xForm().
Returns a pointer to the pixel data at the scanline with index i. The first scanline is at index 0.
The scanline data is aligned on a 32-bit boundary.
Warning: If you are accessing 32-bpp image data, cast the returned pointer to TQRgb* (TQRgb has a 32-bit size) and use it to read/write the pixel value. You cannot use the uchar* pointer directly, because the pixel format depends on the byte order on the underlying platform. Hint: use tqRed(), tqGreen() and tqBlue(), etc. (tqcolor.h) to access the pixels.
See also bytesPerLine(), bits(), and jumpTable().
Example: desktop/desktop.cpp.
An 8-bpp image has 8-bit pixels. A pixel is an index into the color table, which contains 32-bit color values. In a 32-bpp image, the 32-bit pixels are the color values.
This 32-bit value is encoded as follows: The lower 24 bits are used for the red, green, and blue components. The upper 8 bits contain the alpha component.
The alpha component specifies the transparency of a pixel. 0 means completely transparent and 255 means opaque. The alpha component is ignored if you do not enable alpha buffer mode.
The alpha buffer is used to set a mask when a TQImage is translated to a TQPixmap.
See also hasAlphaBuffer() and createAlphaMask().
Sets a color in the color table at index i to c.
A color value is an RGB triplet. Use the tqRgb() function (defined in tqcolor.h) to make RGB triplets.
See also color(), setNumColors(), and numColors().
Examples: desktop/desktop.cpp and themes/wood.cpp.
If the color table is expanded all the extra colors will be set to black (RGB 0,0,0).
See also numColors(), color(), setColor(), and colorTable().
If (x, y) is not valid, the result is undefined.
If the image is a paletted image (depth() <= 8) and index_or_rgb >= numColors(), the result is undefined.
See also pixelIndex(), pixel(), tqRgb(), tqRgba(), and valid().
Returns the size of the image, i.e. its width and height.
See also width(), height(), and rect().
For 32-bpp images and 1-bpp/8-bpp color images the result will be 32-bpp, whereas all-gray images (including black-and-white 1-bpp) will produce 8-bit grayscale images with the palette spanning 256 grays from black to white.
This function uses code based on pnmscale.c by Jef Poskanzer.
pnmscale.c - read a portable anymap and scale it
Copyright (C) 1989, 1991 by Jef Poskanzer.
Permission to use, copy, modify, and distribute this software and its documentation for any purpose and without fee is hereby granted, provided that the above copyright notice appear in all copies and that both that copyright notice and this permission notice appear in supporting documentation. This software is provided "as is" without express or implied warranty.
See also scale() and mirror().
The requested size of the image is s.
See also systemByteOrder().
See also systemBitOrder().
Returns the string recorded for the keyword and language kl.
Note that if you want to iterate over the list, you should iterate over a copy, e.g.
TQStringList list = myImage.textKeys(); TQStringList::Iterator it = list.begin(); while( it != list.end() ) { myProcessing( *it ); ++it; }
See also textList(), text(), setText(), and textLanguages().
Note that if you want to iterate over the list, you should iterate over a copy, e.g.
TQStringList list = myImage.textLanguages(); TQStringList::Iterator it = list.begin(); while( it != list.end() ) { myProcessing( *it ); ++it; }
See also textList(), text(), setText(), and textKeys().
Note that if you want to iterate over the list, you should iterate over a copy, e.g.
TQValueList<TQImageTextKeyLang> list = myImage.textList(); TQValueList<TQImageTextKeyLang>::Iterator it = list.begin(); while( it != list.end() ) { myProcessing( *it ); ++it; }
See also width(), height(), and pixelIndex().
Examples: canvas/canvas.cpp and qmag/qmag.cpp.
Returns the width of the image.
See also height(), size(), and rect().
Examples: canvas/canvas.cpp and opengl/texture/gltexobj.cpp.
The transformation matrix is internally adjusted to compensate for unwanted translation, i.e. xForm() returns the smallest image that contains all the transformed points of the original image.
See also scale(), TQPixmap::xForm(), TQPixmap::trueMatrix(), and TQWMatrix.
Copies a block of pixels from src to dst. The pixels copied from source (src) are converted according to conversion_flags if it is incompatible with the destination (dst).
sx, sy is the top-left pixel in src, dx, dy is the top-left position in dst and sw, \sh is the size of the copied block.
The copying is clipped if areas outside src or dst are specified.
If sw is -1, it is adjusted to src->width(). Similarly, if sh is -1, it is adjusted to src->height().
Currently inefficient for non 32-bit images.
Writes the image image to the stream s as a PNG image, or as a BMP image if the stream's version is 1.
Note that writing the stream to a file will not produce a valid image file.
See also TQImage::save() and Format of the TQDataStream operators.
Reads an image from the stream s and stores it in image.
See also TQImage::load() and Format of the TQDataStream operators.
This file is part of the TQt toolkit. Copyright © 1995-2007 Trolltech. All Rights Reserved.
Copyright © 2007 Trolltech | Trademarks | TQt 3.3.8
|