Magnum::Trade::StbImageConverter class

Image converter plugin using stb_image_write.

Creates files in one of the following formats:

  • Windows Bitmap (*.bmp) if the plugin was loaded as StbBmpImageConverter / BmpImageConverter or Format::Bmp was passed to the constructor
  • Radiance HDR (*.hdr) if the plugin was loaded as StbHdrImageConverter / HdrImageConverter or Format::Hdr was passed to the constructor
  • Portable Network Graphics (*.png) if the plugin was loaded as StbPngImageConverter / PngImageConverter or Format::Png was passed to the constructor
  • Truevision TGA (*.tga, *.vda, *.icb, *.vst) if the plugin was loaded as StbTgaImageConverter / TgaImageConverter or Format::Tga was passed to the constructor

The images must have format PixelFormat::Red, PixelFormat::RG, PixelFormat::RGB or PixelFormat::RGBA. For BMP, PNG and TGA the type must be PixelType::UnsignedByte, for HDR the type must be PixelType::Float. On OpenGL ES 2.0 and WebGL 1.0 accepts also PixelFormat::Luminance instead of PixelFormat::Red and PixelFormat::LuminanceAlpha instead of PixelFormat::RG. Does not support non-default PixelStorage::swapBytes() values, the image data must be tightly packed (except for PNG output, which is able to handle custom row strides).

This plugin depends on the Trade library and is built if WITH_STBIMAGECONVERTER is enabled when building Magnum Plugins. To use as a dynamic plugin, you need to load one of the "StbBmpImageConverter", "StbHdrImageConverter", "StbPngImageConverter", "StbTgaImageConverter" plugins from MAGNUM_PLUGINS_IMAGECONVERTER_DIR. If you would load the plugin as just "StbImageConverter", it won't be able to guess the desired output format. To use as a static plugin or as a dependency of another plugin with CMake, you need to request the StbImageConverter component of the MagnumPlugins package and link to the MagnumPlugins::StbImageConverter target.

Besides StbBmpImageConverter, StbHdrImageConverter, StbPngImageConverter and StbTgaImageConverter aliases this plugin provides also BmpImageConverter, HdrImageConverter, PngImageConverter and TgaImageConverter plugins, but note that this plugin may generate slightly larger files and the performance might be worse than when using plugins dedicated for given format.

See Downloading and building plugins, Plugin usage with CMake and Loading and using plugins for more information.

Base classes

class AbstractImageConverter
Base for image converter plugins.

Public types

enum class Format: Int { Bmp = 1, Hdr, Png, Tga }
Output file format.

Constructors, destructors, conversion operators

StbImageConverter(Format format) explicit
Default constructor.
StbImageConverter(PluginManager::AbstractManager& manager, const std::string& plugin) explicit
Plugin manager constructor.

Private functions

auto doFeatures() const override -> Features virtual
Implementation of features()
auto doExportToData(const ImageView2D& image) override -> Containers::Array<char> virtual
Implementation of exportToData(const ImageView2D&)

Enum documentation

enum class Magnum::Trade::StbImageConverter::Format: Int

Output file format.


Output BMP images


Output HDR images


Output PNG images


Output TGA images

Function documentation

Magnum::Trade::StbImageConverter::StbImageConverter(Format format) explicit

Default constructor.

The converter outputs files in format defined by Format.

Magnum::Trade::StbImageConverter::StbImageConverter(PluginManager::AbstractManager& manager, const std::string& plugin) explicit

Plugin manager constructor.

Outputs files in format based on which alias was used to load the plugin.