Request for TIF support

Indeed, ImageMagick can do a lot of cool stuff with images, and it’s capabilities to convert images from/to everything are unparalled in my experience :slight_smile: I mostly use it as command-line tool, but they also feature a library that can be used from Pascal (and many other languages).

Note:

  1. Note that ImageMagick itself is not written in Pascal. It’s mostly in C, from what I know, GitHub - ImageMagick/ImageMagick: 🧙‍♂️ ImageMagick 7 confirms it. Debian’s build dependencies of ImageMagick also don’t include FPC, so it would be strange if ImageMagick was written in Pascal.

    The FPC includes Pascal units ImageMagick and Magick_Wand, documented on PascalMagick - Lazarus wiki . But these units are just “wrappers” – the functions they expose just call the underlying ImageMagick C library.

    There’s nothing wrong with that of course, ImageMagick is great. I’m using lots of software not written in Pascal, and CGE also doesn’t limit itself to only using libraries written in Pascal (as seen in Compiling from source | Manual | Castle Game Engine ). I absolutely recommend you to use ImageMagick, both as command-line tool, and as library, from any language including Pascal. It’s great open-source code. I just mention it to clarify – saying “ImageMagick is in Pascal” is not true :), only wrapper units are in Pascal.

  2. Note that CGE doesn’t preserve accuracy in 16-bit PNG now. Reading such PNG images goes under the hood through our regular 8-bit image classes (like TRGBAlphaImages, 32-bit per pixel, 8-bits per channel).

    We don’t even have a class internally in CGE to hold exactly 16-bit channel information. Though we have TRGBFloatImage, where every pixel is 3x Single (3x 32-bit floats) values. This is suitable for cases when you need higher precision than 8-bit per channel (and/or also higher range than 0…1, which makes sense for ray-tracers where output brightness is basically unbounded since in reality there’s no upper bound on how bright things can be). Of course it’s floating-point precision, not integer, but it’s still higher precision than 8-bit per channel in practical usage.

    Image formats like RGBE are read to TRGBFloatImage (right now this actually happens in Vampyre Imaging Library that we use in CGE; in the past we did RGBE read/write in CGE natively). KTX also can be read as TRGBFloatImage when the image format indicates floats. We also have OpenGL(ES) code to actually load such float-based data into OpenGL(ES), so it stays floats on GPU.

    It’s great to read / write float image data in our simple ray-tracer CastleRayTracer. It also makes sense to use in some rendering tricks that really require more precision / higher range (we use it in our “Variance Shadow Maps” implementation).

    However we don’t read PNG to TRGBFloatImage right now internally. (Forcing it, by MyImage := LoadImage('my16bit.png', [TRGBFloatImage]) will work but just mean we read it to 8-bit precision and then convert each Byte to Single. So it works, but you don’t preserve 16-bit precision.)

    If you have a need for 16-bit precision image format in CGE, let me know, and I can then advise how to proceed :slight_smile: