TPDFlibModernImageDecodeCallback
Data types, image handling
Description
TPDFlibModernImageDecodeCallback is the pluggable decode backend for DecodeModernImageToPNG. Register one with RegisterModernImageDecoderBackend to bypass the external codec library; while a backend is registered it runs first and the native decode path is not used.
The library normalizes the streams before the call: InStream is positioned at 0 and OutPNG is reset to position 0 with size 0. A True result must leave a complete PNG in OutPNG, and the library then rewinds that stream to 0.
Syntax
Delphi
TPDFlibModernImageDecodeCallback = Function(InStream, OutPNG: TStream;
ImageFormat: TPDFlibModernImageFormat;
ApplyOrientation: Boolean): Boolean;Parameters
| InStream | Borrowed stream holding the complete image, positioned at its start; the library restores the stream position after the call returns |
|---|---|
| OutPNG | Destination stream, already emptied; write the PNG bytes here |
| ImageFormat | Format the caller detected, never mifUnknown |
| ApplyOrientation | True when the output should be upright, so the backend should honor the stored orientation |
Return values
| True | OutPNG holds a complete PNG and the decode call succeeds |
|---|---|
| False | The decode call fails and returns False; no fallback to the codec library runs afterwards |
Remarks
There is one backend per process. Registration and reading are protected by a critical section, registering again replaces the previous callback, and ClearModernImageDecoderBackend removes it.
The callback runs inside the caller's call to DecodeModernImageToPNG and must not keep references to either stream once it returns.
Without a backend the library loads the codec library and uses its decoder, so an installed backend always takes precedence while it stays registered.
The PNG contract is the whole output: alpha, color depth and ICC handling are the backend's responsibility, and the library does not post-process what it receives.
See also
RegisterModernImageDecoderBackend, ClearModernImageDecoderBackend, DecodeModernImageToPNG, DetermineModernImageFormat