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_NAMESPACEso 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 withONNX_APIcompile without modification.Namespace alias so that ONNX C++ code (and consumers such as onnxruntime) that refers to the literal
onnxnamespace — rather than theONNX_NAMESPACEmacro — resolves to the onnx-light namespace. The standard onnx package lives innamespace onnx; onnx-light usesonnx_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 fromonnx.-
namespace onnx_kernels
-
namespace kernel
-
class ImageDecoder : public onnx_light::onnx_kernels::kernel::KernelBase#
- #include <include_image_kernels.h>
Reference implementation of the
ImageDecoderoperator (ai.onnx, since opset 20).Validates the input
tensor(uint8)(must be 1-D, carrying the encoded bytestream) and thepixel_formatattribute (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 throughlibwebpand JPEG2000 (JP2 / raw J2K codestream) throughlibopenjp2(OpenJPEG) when available at runtime. The Netpbm family (P1-P6with 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 throwstd::invalid_argument.Public Functions
-
Tensor operator()(const Tensor &encoded_stream, const std::string &pixel_format = "RGB") const#
Allocating overload.
pixel_formatdefaults 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.
outputmust already be atensor(uint8)whose last dimension matches the channel count derived frompixel_format(output.shape == {H, W, C}withC == ChannelCount(pixel_format)). When the bytestream is a supported BMP the decoded pixels are written intooutput.dataand the shape must match the decoded image dimensions; when decoding falls back to the empty-matrix path,outputmust 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:1for"Grayscale",3for"RGB"/"BGR". Throwsstd::invalid_argumentfor 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.
-
Tensor operator()(const Tensor &encoded_stream, const std::string &pixel_format = "RGB") const#
-
class ImageDecoder : public onnx_light::onnx_kernels::kernel::KernelBase#
-
namespace kernel
-
namespace onnx_kernels