Yunqa • The Delphi Inspiration

Delphi Components and Applications

User Tools

Site Tools



YuImage is a collection of image processing libraries and classes, such as Delphi ports of Little CMS, libpng, and libwebp, all statically linked, no DLLs needed.


YuImage is a collection of image processing libraries, classes and functions for Delphi. In particular, it contains Delphi ports of the following C libraries, all with complete API, statically linked, and no DLLs needed:

Little CMS / YuLcms2.pas: A small-footprint color management engine

Little CMS implements fast transformations between color profiels based on the International Color Consortium (ICC) 4.4 specification and support for all kinds of V2 and V4 profiles.

  • Read and write ICC profiles.
  • Create new or modify existing profiles.
  • Apply profiles to a wide range of pixel formats.

libpng / YuPng.pas: The official PNG reference library

libpng supports almost all features of the PNG image format, is extensible, and extensively tested.

  • Read and write PNG images, both interlaced and non-interlaced..
  • RGB, palette, and grayscale color types, with 1, 2, 4, 8, and 16-bit color depth with automatic conversion.
  • Full alpha transparency.

TYuPngImage is an image class which descends from TGraphic. It loads and draws PNG encoded images with transparency and automatically applies embedded ICC color profiles, gamma correction, and chromaticities.

libwebp / YuWebP.pas: The official WebP refernce library

WebP is a modern image format that provides superior lossless and lossy image compression. It can create smaller and richer images. WebP lossless images are 26% smaller in size compared to PNGs. WebP lossy images are 25-34% smaller than comparable JPEG images at equivalent perceived quality.

  • Decode and encode WebP images to RGB, BGR, and YUV.
  • Demuxer to extract image and external format data from WebP images.
  • Muxer to manipulate WebP containers with color profile, metadata and animation.
  • Animatied WebP decoder and encoder.
  • Multi-threading.
  • Full alpha transparency.

TYuWebPImage is a TGraphic descendent image class. It loads and draws WebP encoded images with alpha transparency and automatically applies embedded ICC profiles. TYuWebPImage renders animated WebP images.

Demo projects, including an Image Viewer with thumbnails preview, are included in the download.

Minimum TYuPngImage and TYuWebPImage Code Example

{ Add the YuPngImage and YuWebPImage units once to any uses clause to register 
  TYuPngImage as the PNG handler and TYuWebPImage as the WebP handler. }
  Graphics,    // For TPicture.
  YuPngImage,  // Register TYuPngImage.
  YuWebPImage; // Register TYuWebPImage.
procedure LoadImages;
  pic: TPicture;
  pic := TPicture.Create;
    pic.LoadFromFile('test.png'); // Load a PNG image.
    { Add code here to do something with the picture. }
  pic := TPicture.Create;
    pic.LoadFromFile('test.webp'); // Load a WebP image.
    { Add code here to do something with the picture. }

Why TYuPngImage, yet another Delphi PNG image class?

Because TPngImage, Delphi's own PNG image class, if faulty. TYuPngImage fixes some annoying bugs and deficiencies of TPngImage, as demonstrated below.

The examples were painted by Delphi 11.2 Alexandria, the most recent Delphi at the time of this writing. The left and right images are drawn on a checker board pattern to show their transparent pixels. The center image points out pixel differences with a red color overlay.

  • Embedded ICC color profiles go unnoticed in TPngImage. TYuPngImage reads the iCCP chunk and applies the proper color conversions. In this example, red and blue are swapped.
    TPngImage ignores iCCP chunk and displays wrong colors.
  • In this example, failure to apply ICC color profiles leads to negative rendering of grayscale images. The correct gradient is white on the left and black on the right.
    TPngImage ignores iCCP chunk in grayscale PNG.
  • Primary chromaticities and white point are not handled in TPngImage. TYuPngImage reads the cHRM chunk and applies the red, green, and blue chromaticities and the referenced white point. In this example, red and green are swapped.
    TPngImage fails to apply cHRM chromaticities.
  • 2-bit grayscale images show wrong colors in TPngImage. The differences are in stainted shades of gray, whereas the lightest color should be a clean white.
    TPngImage outputs wrong gray levels in 2-bit PNG.
  • 2-bit grayscale can have 7 colors in TPngImage, where only 4 colors are possible. The artistic diff-pattern hints at an algorithmic problem. TYuPngImage is less imaginative and sticks the correct 4 colors.
    TYuPngImage shows 4 correct colors in 2-bit grayscale. TPngImage shows 7 colors, 3 more than possible.
  • Transparency ignored for 16-bit grayscale in TPngImage so the checker board does not shine through.
    TYuPngImage shows correct transparncy where TPngImage prints wrong opacity.
  • Transparency ignored for 16-bit color as well in TPngImage.
    TYuPngImage shows correct transparncy where TPngImage shows wrong opaqe color.
  • Access Violation and memory leak on invalid IHDR data in TPngImage. Older Delphis are more prone to AV than newer ones, but even the current Delphi 11.2 Alexandria is affected. TYuPngImage issues a proper error message and does not leak memory, in all Delphi versions.
    TYuPngImage shows invalid IHDR error where TPngImage crashes with access violation.

3rd Party Problems Detected During YuImage Development

products/image/index.txt · Last modified: 2023/06/22 12:51 by