Utility class for loading images from a URI. More...
#include "donner/svg/resources/ImageLoader.h"
Public Types | |
| using | Result = std::variant<ImageResource, SvgImageContent, UrlLoaderError> |
| Result type returned by fromUri. Contains either decoded raster pixels, raw SVG content, or an error. | |
| using | DecodedImageAdmission = std::function<bool(size_t)> |
| Callback that reserves exact decoded RGBA bytes after dimensions are known but before decode. Returning false fails the load with UrlLoaderError::ResourceTooLarge without exhausting the shared byte budget; decodedImageAdmissionRefused then returns true. | |
Public Member Functions | |
| ImageLoader (ResourceLoaderInterface &resourceLoader, size_t maximumResourceSize=UrlLoader::kDefaultMaximumResourceSize, size_t *remainingResourceBytes=nullptr, size_t maximumDecodedImageSize=kDefaultMaximumDecodedImageSize, DecodedImageAdmission decodedImageAdmission={}) | |
| Create a new image loader that uses the given resource loader to fetch external resources. | |
| ~ImageLoader ()=default | |
| Destructor. | |
| ImageLoader (const ImageLoader &)=delete | |
| ImageLoader (ImageLoader &&)=delete | |
| ImageLoader & | operator= (const ImageLoader &)=delete |
| ImageLoader & | operator= (ImageLoader &&)=delete |
| Result | fromUri (std::string_view uri) |
| Read an image from a URI, which can be a file path, a URL, or a data URL (e.g. | |
| bool | decodedImageAdmissionRefused () const |
| Whether the last load was refused specifically by the decoded-byte admission callback. | |
Static Public Attributes | |
| static constexpr size_t | kDefaultMaximumDecodedImageSize = 64 * 1024 * 1024 |
| Default maximum number of decoded RGBA bytes for one raster image. | |
| static constexpr size_t | kMaximumDecodedBytesPerInputByte = 4096 |
| Decode-amplification budget: output RGBA bytes may not exceed 4096 times the encoded input size, with a 1 MiB floor for small ordinary images. | |
| static constexpr size_t | kMinimumDecodedImageAllowance = 1 * 1024 * 1024 |
| Minimum decoded-byte allowance for small encoded image inputs. | |
Utility class for loading images from a URI.
Supports both raster images (PNG, JPEG, GIF) and SVG images. Raster images are decoded into pixel data (ImageResource), while SVG images are returned as raw bytes (SvgImageContent) for parsing by the caller.
|
inlineexplicit |
Create a new image loader that uses the given resource loader to fetch external resources.
| resourceLoader | Resource loader to use for fetching external resources. |
| maximumResourceSize | Maximum encoded bytes accepted from one resource. |
| remainingResourceBytes | Optional shared byte budget charged for encoded input and decoded raster output. |
| maximumDecodedImageSize | Maximum decoded RGBA bytes accepted for one image. |
| decodedImageAdmission | Optional exact decoded-byte admission callback. |
| Result donner::svg::ImageLoader::fromUri | ( | std::string_view | uri | ) |
Read an image from a URI, which can be a file path, a URL, or a data URL (e.g.
"data:image/png;base64,...").
If the resource is an SVG image (image/svg+xml), returns SvgImageContent with raw bytes. Otherwise, decodes the image into RGBA pixel data and returns ImageResource.
| uri | URI of the image, or data URL containing a base64 embedded image. |
|
staticconstexpr |
Decode-amplification budget: output RGBA bytes may not exceed 4096 times the encoded input size, with a 1 MiB floor for small ordinary images.
The configured per-image limit and shared document budget remain additional caps. This bounds synchronous work from tiny inputs.