Add DecodeImageCallbacks::OnImageFormat def impl

This commit is contained in:
Nigel Tao committed 2021-03-11 12:04:00 +11:00
1 parent 54175156bd
commit 1daace6342
5 files changed
+115 -43

No files matched your search

+52 -7
View File
@@ -9458,19 +9458,27 @@ class DecodeImageCallbacks {
// OnImageFormat returns the image decoder for the input data's file format.
// Returning a nullptr means failure (DecodeImage_UnsupportedImageFormat).
//
// Common formats will have a non-zero FourCC value, such as
// WUFFS_BASE__FOURCC__JPEG. A zero FourCC code means that the caller is
// responsible for examining the opening bytes (a prefix) of the input data.
// OnImageFormat implementations should not modify those bytes.
// Common formats will have a FourCC value in the range [1 ..= 0x7FFF_FFFF],
// such as WUFFS_BASE__FOURCC__JPEG. A zero FourCC value means that the
// caller is responsible for examining the opening bytes (a prefix) of the
// input data. OnImageFormat implementations should not modify those bytes.
//
// OnImageFormat might be called more than once, since some image file
// formats can wrap others. For example, a nominal BMP file can actually
// contain a JPEG or a PNG.
//
// There is no default implementation, as modular Wuffs builds (those that
// define WUFFS_CONFIG__MODULES) may enable or disable particular codecs.
// The default OnImageFormat accepts the FOURCC codes listed below. For
// modular builds (i.e. when #define'ing WUFFS_CONFIG__MODULES), acceptance
// of the ETC file format is optional (for each value of ETC) and depends on
// the corresponding module to be enabled at compile time (i.e. #define'ing
// WUFFS_CONFIG__MODULE__ETC).
// - WUFFS_BASE__FOURCC__BMP
// - WUFFS_BASE__FOURCC__GIF
// - WUFFS_BASE__FOURCC__NIE
// - WUFFS_BASE__FOURCC__PNG
// - WUFFS_BASE__FOURCC__WBMP
virtual wuffs_base__image_decoder::unique_ptr //
OnImageFormat(uint32_t fourcc, wuffs_base__slice_u8 prefix) = 0;
OnImageFormat(uint32_t fourcc, wuffs_base__slice_u8 prefix);
// OnImageConfig allocates the pixel buffer.
//
@@ -36766,6 +36774,43 @@ DecodeImageCallbacks::AllocResult::AllocResult(std::string&& error_message0)
mem_slice(wuffs_base__empty_slice_u8()),
error_message(std::move(error_message0)) {}
wuffs_base__image_decoder::unique_ptr //
DecodeImageCallbacks::OnImageFormat(uint32_t fourcc,
wuffs_base__slice_u8 prefix) {
switch (fourcc) {
#if !defined(WUFFS_CONFIG__MODULES) || defined(WUFFS_CONFIG__MODULE__BMP)
case WUFFS_BASE__FOURCC__BMP:
return wuffs_bmp__decoder::alloc_as__wuffs_base__image_decoder();
#endif
#if !defined(WUFFS_CONFIG__MODULES) || defined(WUFFS_CONFIG__MODULE__GIF)
case WUFFS_BASE__FOURCC__GIF:
return wuffs_gif__decoder::alloc_as__wuffs_base__image_decoder();
#endif
#if !defined(WUFFS_CONFIG__MODULES) || defined(WUFFS_CONFIG__MODULE__NIE)
case WUFFS_BASE__FOURCC__NIE:
return wuffs_nie__decoder::alloc_as__wuffs_base__image_decoder();
#endif
#if !defined(WUFFS_CONFIG__MODULES) || defined(WUFFS_CONFIG__MODULE__PNG)
case WUFFS_BASE__FOURCC__PNG: {
auto dec = wuffs_png__decoder::alloc_as__wuffs_base__image_decoder();
// Favor faster decodes over rejecting invalid checksums.
dec->set_quirk_enabled(WUFFS_BASE__QUIRK_IGNORE_CHECKSUM, true);
return dec;
}
#endif
#if !defined(WUFFS_CONFIG__MODULES) || defined(WUFFS_CONFIG__MODULE__WBMP)
case WUFFS_BASE__FOURCC__WBMP:
return wuffs_wbmp__decoder::alloc_as__wuffs_base__image_decoder();
#endif
}
return wuffs_base__image_decoder::unique_ptr(nullptr, &free);
}
DecodeImageCallbacks::AllocResult //
DecodeImageCallbacks::OnImageConfig(
const wuffs_base__image_config& image_config) {