mirror of
https://github.com/ddidderr/wuffs.git
synced 2026-11-25 16:55:11 +01:00
Add C++ convenience methods
This commit is contained in:
1 parent
60a7b48745
commit
30cfaa5db7
20 files changed
+1444
-229
No files matched your search
@@ -58,9 +58,9 @@ const basePublicH = "" +
|
||||
"& r.min_incl_y == s.min_incl_y &&\n r.max_excl_x == s.max_excl_x && r.max_excl_y == s.max_excl_y) ||\n (wuffs_base__rect_ie_u32__is_empty(r) &&\n wuffs_base__rect_ie_u32__is_empty(s));\n}\n\nstatic inline bool wuffs_base__rect_ie_u32__contains(wuffs_base__rect_ie_u32 r,\n uint32_t x,\n uint32_t y) {\n return (r.min_incl_x <= x) && (x < r.max_excl_x) && (r.min_incl_y <= y) &&\n (y < r.max_excl_y);\n}\n\nstatic inline wuffs_base__rect_ie_u32 wuffs_base__rect_ie_u32__intersection(\n wuffs_base__rect_ie_u32 r,\n wuffs_base__rect_ie_u32 s) {\n r.min_incl_x = wuffs_base__u32__max(r.min_incl_x, s.min_incl_x);\n r.min_incl_y = wuffs_base__u32__max(r.min_incl_y, s.min_incl_y);\n r.max_excl_x = wuffs_base__u32__min(r.max_excl_x, s.max_excl_x);\n r.max_excl_y = wuffs_base__u32__min(r.max_excl_y, s.max_excl_y);\n return r;\n}\n\nstatic inline wuffs_base__rect_ie_u32 wuffs_base__rect_ie_u32__union" +
|
||||
"(\n wuffs_base__rect_ie_u32 r,\n wuffs_base__rect_ie_u32 s) {\n if (wuffs_base__rect_ie_u32__is_empty(r)) {\n return s;\n }\n if (wuffs_base__rect_ie_u32__is_empty(s)) {\n return r;\n }\n r.min_incl_x = wuffs_base__u32__min(r.min_incl_x, s.min_incl_x);\n r.min_incl_y = wuffs_base__u32__min(r.min_incl_y, s.min_incl_y);\n r.max_excl_x = wuffs_base__u32__max(r.max_excl_x, s.max_excl_x);\n r.max_excl_y = wuffs_base__u32__max(r.max_excl_y, s.max_excl_y);\n return r;\n}\n\nstatic inline uint32_t wuffs_base__rect_ie_u32__width(\n wuffs_base__rect_ie_u32 r) {\n return wuffs_base__u32__sat_sub(r.max_excl_x, r.min_incl_x);\n}\n\nstatic inline uint32_t wuffs_base__rect_ie_u32__height(\n wuffs_base__rect_ie_u32 r) {\n return wuffs_base__u32__sat_sub(r.max_excl_y, r.min_incl_y);\n}\n\n" +
|
||||
"" +
|
||||
"// ---------------- I/O\n\n// wuffs_base__io_buffer is a 1-dimensional buffer (a pointer and length), plus\n// additional indexes into that buffer, plus an opened / closed flag.\n//\n// A value with all fields NULL or zero is a valid, empty buffer.\ntypedef struct {\n uint8_t* ptr; // Pointer.\n size_t len; // Length.\n size_t wi; // Write index. Invariant: wi <= len.\n size_t ri; // Read index. Invariant: ri <= wi.\n bool closed; // No further writes are expected.\n} wuffs_base__io_buffer;\n\ntypedef struct {\n // Do not access the private_impl's fields directly. There is no API/ABI\n // compatibility or safety guarantee if you do so.\n struct {\n wuffs_base__io_buffer* buf;\n // The bounds values are typically NULL, when created by the Wuffs public\n // API. NULL means that the callee substitutes the implicit bounds derived\n // from buf.\n uint8_t* bounds[2];\n } private_impl;\n} wuffs_base__io_reader;\n\ntypedef struct {\n // Do not access the private_impl's fields directly. There is no API/A" +
|
||||
"BI\n // compatibility or safety guarantee if you do so.\n struct {\n wuffs_base__io_buffer* buf;\n // The bounds values are typically NULL, when created by the Wuffs public\n // API. NULL means that the callee substitutes the implicit bounds derived\n // from buf.\n uint8_t* bounds[2];\n } private_impl;\n} wuffs_base__io_writer;\n\n// wuffs_base__io_buffer__compact moves any written but unread bytes to the\n// start of the buffer.\nstatic inline void wuffs_base__io_buffer__compact(wuffs_base__io_buffer* buf) {\n if (!buf || (buf->ri == 0)) {\n return;\n }\n size_t n = buf->wi - buf->ri;\n if (n != 0) {\n memmove(buf->ptr, buf->ptr + buf->ri, n);\n }\n buf->wi = n;\n buf->ri = 0;\n}\n\nstatic inline wuffs_base__io_reader wuffs_base__io_buffer__reader(\n wuffs_base__io_buffer* buf) {\n wuffs_base__io_reader ret = ((wuffs_base__io_reader){});\n ret.private_impl.buf = buf;\n return ret;\n}\n\nstatic inline wuffs_base__io_writer wuffs_base__io_buffer__writer(\n wuffs_base__io_buffer* buf) {\n wuffs_base__io" +
|
||||
"_writer ret = ((wuffs_base__io_writer){});\n ret.private_impl.buf = buf;\n return ret;\n}\n\n" +
|
||||
"// ---------------- I/O\n\nstruct wuffs_base__io_buffer__struct;\n\ntypedef struct {\n // Do not access the private_impl's fields directly. There is no API/ABI\n // compatibility or safety guarantee if you do so.\n struct {\n struct wuffs_base__io_buffer__struct* buf;\n // The bounds values are typically NULL, when created by the Wuffs public\n // API. NULL means that the callee substitutes the implicit bounds derived\n // from buf.\n uint8_t* bounds[2];\n } private_impl;\n} wuffs_base__io_reader;\n\ntypedef struct {\n // Do not access the private_impl's fields directly. There is no API/ABI\n // compatibility or safety guarantee if you do so.\n struct {\n struct wuffs_base__io_buffer__struct* buf;\n // The bounds values are typically NULL, when created by the Wuffs public\n // API. NULL means that the callee substitutes the implicit bounds derived\n // from buf.\n uint8_t* bounds[2];\n } private_impl;\n} wuffs_base__io_writer;\n\n// wuffs_base__io_buffer is a 1-dimensional buffer (a pointer and leng" +
|
||||
"th), plus\n// additional indexes into that buffer, plus an opened / closed flag.\n//\n// A value with all fields NULL or zero is a valid, empty buffer.\ntypedef struct wuffs_base__io_buffer__struct {\n uint8_t* ptr; // Pointer.\n size_t len; // Length.\n size_t wi; // Write index. Invariant: wi <= len.\n size_t ri; // Read index. Invariant: ri <= wi.\n bool closed; // No further writes are expected.\n\n#ifdef __cplusplus\n inline void compact();\n inline wuffs_base__io_reader reader();\n inline wuffs_base__io_writer writer();\n#endif // __cplusplus\n\n} wuffs_base__io_buffer;\n\n// wuffs_base__io_buffer__compact moves any written but unread bytes to the\n// start of the buffer.\nstatic inline void wuffs_base__io_buffer__compact(wuffs_base__io_buffer* buf) {\n if (!buf || (buf->ri == 0)) {\n return;\n }\n size_t n = buf->wi - buf->ri;\n if (n != 0) {\n memmove(buf->ptr, buf->ptr + buf->ri, n);\n }\n buf->wi = n;\n buf->ri = 0;\n}\n\nstatic inline wuffs_base__io_reader wuffs_base__io_buffer__reader(\n wuf" +
|
||||
"fs_base__io_buffer* buf) {\n wuffs_base__io_reader ret = ((wuffs_base__io_reader){});\n ret.private_impl.buf = buf;\n return ret;\n}\n\nstatic inline wuffs_base__io_writer wuffs_base__io_buffer__writer(\n wuffs_base__io_buffer* buf) {\n wuffs_base__io_writer ret = ((wuffs_base__io_writer){});\n ret.private_impl.buf = buf;\n return ret;\n}\n\n#ifdef __cplusplus\n\ninline void wuffs_base__io_buffer__struct::compact() {\n wuffs_base__io_buffer__compact(this);\n}\n\ninline wuffs_base__io_reader wuffs_base__io_buffer__struct::reader() {\n return wuffs_base__io_buffer__reader(this);\n}\n\ninline wuffs_base__io_writer wuffs_base__io_buffer__struct::writer() {\n return wuffs_base__io_buffer__writer(this);\n}\n\n#endif // __cplusplus\n\n" +
|
||||
"" +
|
||||
"// ---------------- Images\n\n// wuffs_base__color_u32argb is an 8 bit per channel Alpha, Red, Green, Blue\n// color, as a uint32_t value. It is in word order, not byte order: its value\n// is always 0xAARRGGBB, regardless of endianness. It uses premultiplied alpha.\ntypedef uint32_t wuffs_base__color_u32argb;\n\n" +
|
||||
"" +
|
||||
|
||||
Reference in new issue
Block a user