mirror of
https://github.com/ddidderr/wuffs.git
synced 2026-11-26 09:01:35 +01:00
Add wuffs_aux::FooArgBar types for optional args
Prior to this commit, with a "wuffs_aux::Foo(x, y, 0, 0, 4, 5)" call, with arguments after "y" optional, it was not a compile-time error to give the wrong number of "0"s or to transpose "4" and "5".
This commit is contained in:
1 parent
0460bfcd7a
commit
ca33506c01
10 files changed
+354
-51
No files matched your search
@@ -163,6 +163,46 @@ extern const char DecodeImage_UnsupportedPixelBlend[];
|
||||
extern const char DecodeImage_UnsupportedPixelConfiguration[];
|
||||
extern const char DecodeImage_UnsupportedPixelFormat[];
|
||||
|
||||
// The FooArgBar types add structure to Foo's optional arguments. They wrap
|
||||
// inner representations for several reasons:
|
||||
// - It provides a home for the DefaultValue static method, for Foo callers
|
||||
// that want to override some but not all optional arguments.
|
||||
// - It provides the "Bar" name at Foo call sites, which can help self-
|
||||
// document Foo calls with many arguemnts.
|
||||
// - It provides some type safety against accidentally transposing or omitting
|
||||
// adjacent fundamentally-numeric-typed optional arguments.
|
||||
|
||||
// DecodeImageArgPixelBlend wraps an optional argument to DecodeImage.
|
||||
struct DecodeImageArgPixelBlend {
|
||||
explicit DecodeImageArgPixelBlend(wuffs_base__pixel_blend repr0);
|
||||
|
||||
// DefaultValue returns WUFFS_BASE__PIXEL_BLEND__SRC.
|
||||
static DecodeImageArgPixelBlend DefaultValue();
|
||||
|
||||
wuffs_base__pixel_blend repr;
|
||||
};
|
||||
|
||||
// DecodeImageArgBackgroundColor wraps an optional argument to DecodeImage.
|
||||
struct DecodeImageArgBackgroundColor {
|
||||
explicit DecodeImageArgBackgroundColor(
|
||||
wuffs_base__color_u32_argb_premul repr0);
|
||||
|
||||
// DefaultValue returns 1, an invalid wuffs_base__color_u32_argb_premul.
|
||||
static DecodeImageArgBackgroundColor DefaultValue();
|
||||
|
||||
wuffs_base__color_u32_argb_premul repr;
|
||||
};
|
||||
|
||||
// DecodeImageArgMaxInclDimension wraps an optional argument to DecodeImage.
|
||||
struct DecodeImageArgMaxInclDimension {
|
||||
explicit DecodeImageArgMaxInclDimension(uint32_t repr0);
|
||||
|
||||
// DefaultValue returns 1048575 = 0x000F_FFFF.
|
||||
static DecodeImageArgMaxInclDimension DefaultValue();
|
||||
|
||||
uint32_t repr;
|
||||
};
|
||||
|
||||
// DecodeImage decodes the image data in input. A variety of image file formats
|
||||
// can be decoded, depending on what callbacks.SelectDecoder returns.
|
||||
//
|
||||
@@ -209,8 +249,11 @@ extern const char DecodeImage_UnsupportedPixelFormat[];
|
||||
DecodeImageResult //
|
||||
DecodeImage(DecodeImageCallbacks& callbacks,
|
||||
sync_io::Input& input,
|
||||
wuffs_base__pixel_blend pixel_blend = WUFFS_BASE__PIXEL_BLEND__SRC,
|
||||
wuffs_base__color_u32_argb_premul background_color = 1, // Invalid.
|
||||
uint32_t max_incl_dimension = 1048575); // 0x000F_FFFF
|
||||
DecodeImageArgPixelBlend pixel_blend =
|
||||
DecodeImageArgPixelBlend::DefaultValue(),
|
||||
DecodeImageArgBackgroundColor background_color =
|
||||
DecodeImageArgBackgroundColor::DefaultValue(),
|
||||
DecodeImageArgMaxInclDimension max_incl_dimension =
|
||||
DecodeImageArgMaxInclDimension::DefaultValue());
|
||||
|
||||
} // namespace wuffs_aux
|
||||
Reference in new issue
Block a user