include_image_kernels.h#

namespace onnx_light

Alias that makes onnx-light headers compatible with code that references ONNX_LIGHT_NAMESPACE (the macro used in the standard onnx package).

Set to ONNX_LIGHT_NAMESPACE so both names resolve to the same namespace.

Symbol-visibility attribute for the public onnx-light C++ API.

Defined as empty because onnx-light does not require explicit __declspec(dllexport) or __attribute__((visibility("default"))) annotations — visibility is controlled at the shared-library level. The macro is provided so that vendored ONNX headers that decorate their declarations with ONNX_API compile without modification.

Namespace alias so that ONNX C++ code (and consumers such as onnxruntime) that refers to the literal onnx namespace — rather than the ONNX_NAMESPACE macro — resolves to the onnx-light namespace. The standard onnx package lives in namespace onnx; onnx-light uses onnx_light (via ONNX_LIGHT_NAMESPACE), so this alias keeps onnx-light a true drop-in. It is only introduced when the onnx-light namespace differs from onnx.

namespace onnx_kernels
namespace kernel
class ImageDecoder : public onnx_light::onnx_kernels::kernel::KernelBase#
#include <include_image_kernels.h>

Reference implementation of the ImageDecoder operator (ai.onnx, since opset 20).

Validates the input tensor(uint8) (must be 1-D, carrying the encoded bytestream) and the pixel_format attribute (must be one of "RGB", "BGR" or "Grayscale"). The decoded image is returned as a (H, W, C) tensor(uint8) in channel-last layout.

BMP (24-bit uncompressed, BI_RGB) and baseline-sequential JPEG (JFIF, SOF0, 8-bit precision, 1 or 3 components, sampling factors in {1, 2}, optional restart intervals) images, as well as 8-bit non-interlaced grayscale/truecolor PNG (color types 0 and 2), are decoded natively without any external library dependency. WebP is decoded through libwebp and JPEG2000 (JP2 / raw J2K codestream) through libopenjp2 (OpenJPEG) when available at runtime. The Netpbm family (P1-P6 with 8-bit samples) is also decoded natively. Bytestreams that cannot be decoded fall back to returning an empty matrix ((0, 0, C) tensor(uint8)). Invalid inputs or attribute values throw std::invalid_argument.

Public Functions

Tensor operator()(const Tensor &encoded_stream, const std::string &pixel_format = "RGB") const#

Allocating overload. pixel_format defaults to "RGB" (the schema default). Decodes BMP (24-bit uncompressed) to (H, W, C) uint8. Falls back to (0, 0, C) for unsupported/unrecognised formats.

void operator()(const Tensor &encoded_stream, const std::string &pixel_format, Tensor &output) const#

In-place overload. output must already be a tensor(uint8) whose last dimension matches the channel count derived from pixel_format (output.shape == {H, W, C} with C == ChannelCount(pixel_format)). When the bytestream is a supported BMP the decoded pixels are written into output.data and the shape must match the decoded image dimensions; when decoding falls back to the empty-matrix path, output must have shape (0, 0, C).

inline explicit KernelBase(const KernelContext &ctx)#

Public Static Functions

static int64_t ChannelCount(const std::string &pixel_format)#

Returns the channel count implied by pixel_format: 1 for "Grayscale", 3 for "RGB" / "BGR". Throws std::invalid_argument for any other value.

static inline constexpr bool CanRunInPlace() noexcept#

Output bytes are produced from the encoded bytestream and have a different shape than the input; the output buffer cannot safely alias the input buffer.