mirror of
https://github.com/ddidderr/wuffs.git
synced 2026-11-18 08:32:11 +01:00
Rename color_u32argb; add YCoCg color
This commit is contained in:
1 parent
e3486eec17
commit
f06126c85a
5 files changed
+110
-97
No files matched your search
@@ -20,10 +20,10 @@ extern "C" {
|
||||
|
||||
// ---------------- Images
|
||||
|
||||
// wuffs_base__color_u32argb is an 8 bit per channel Alpha, Red, Green, Blue
|
||||
// color, as a uint32_t value. It is in word order, not byte order: its value
|
||||
// is always 0xAARRGGBB, regardless of endianness. It uses premultiplied alpha.
|
||||
typedef uint32_t wuffs_base__color_u32argb;
|
||||
// wuffs_base__color_u32_argb_premul is an 8 bit per channel premultiplied
|
||||
// Alpha, Red, Green, Blue color, as a uint32_t value. It is in word order, not
|
||||
// byte order: its value is always 0xAARRGGBB, regardless of endianness.
|
||||
typedef uint32_t wuffs_base__color_u32_argb_premul;
|
||||
|
||||
// --------
|
||||
|
||||
@@ -57,7 +57,7 @@ typedef uint32_t wuffs_base__color_u32argb;
|
||||
//
|
||||
// For direct formats with N > 1 channels, those channels can be laid out in
|
||||
// either 1 (packed) or N (planar) planes. For example, RGBA data is usually
|
||||
// packed, but YUV data is usually planar, due to chroma subsampling (for
|
||||
// packed, but YCbCr data is usually planar, due to chroma subsampling (for
|
||||
// details, see the wuffs_base__pixel_subsampling type).
|
||||
//
|
||||
// For indexed formats, the palette (always 256 × 4 bytes) holds 8 bits per
|
||||
@@ -66,12 +66,13 @@ typedef uint32_t wuffs_base__color_u32argb;
|
||||
// indices. Plane 3 is re-purposed to hold the per-index colors.
|
||||
//
|
||||
// The color field is encoded in 3 bits:
|
||||
// - 0 means A (Alpha).
|
||||
// - 1 means Y or YA (Gray, Alpha).
|
||||
// - 2 means BGR, BGRX or BGRA (Blue, Green, Red, X-padding or Alpha).
|
||||
// - 3 means RGB, RGBX or RGBA (Red, Green, Blue, X-padding or Alpha).
|
||||
// - 4 means YUV or YUVA (Luma, Chroma-blue, Chroma-red, Alpha).
|
||||
// - 5 means CMY or CMYK (Cyan, Magenta, Yellow, Black).
|
||||
// - 0 means A (Alpha).
|
||||
// - 1 means Y or YA (Gray, Alpha).
|
||||
// - 2 means YCbCr or YCbCrA (Luma, Chroma-blue, Chroma-red, Alpha).
|
||||
// - 3 means YCoCg or YCoCgA (Luma, Chroma-orange, Chroma-green, Alpha).
|
||||
// - 4 means BGR, BGRX or BGRA (Blue, Green, Red, X-padding or Alpha).
|
||||
// - 5 means RGB, RGBX or RGBA (Red, Green, Blue, X-padding or Alpha).
|
||||
// - 6 means CMY or CMYK (Cyan, Magenta, Yellow, Black).
|
||||
// - all other values are reserved.
|
||||
//
|
||||
// In Wuffs, channels are given in memory order (also known as byte order),
|
||||
@@ -102,7 +103,7 @@ typedef uint32_t wuffs_base__color_u32argb;
|
||||
// - 14 means a bit depth of 48.
|
||||
// - 15 means a bit depth of 64.
|
||||
//
|
||||
// For example, wuffs_base__pixel_format 0x3210BBBB is a natural format for
|
||||
// For example, wuffs_base__pixel_format 0x5210BBBB is a natural format for
|
||||
// decoding a PNG image - network byte order (also known as big-endian),
|
||||
// packed, non-premultiplied alpha - that happens to be 16-bit-depth truecolor
|
||||
// with alpha (RGBA). In memory order:
|
||||
@@ -110,7 +111,7 @@ typedef uint32_t wuffs_base__color_u32argb;
|
||||
// ptr+0 ptr+1 ptr+2 ptr+3 ptr+4 ptr+5 ptr+6 ptr+7
|
||||
// Rhi Rlo Ghi Glo Bhi Blo Ahi Alo
|
||||
//
|
||||
// For example, the value wuffs_base__pixel_format 0x20000565 means BGR with no
|
||||
// For example, the value wuffs_base__pixel_format 0x40000565 means BGR with no
|
||||
// alpha or padding, 5/6/5 bits for blue/green/red, packed 2 bytes per pixel,
|
||||
// laid out LSB-first in memory order:
|
||||
//
|
||||
@@ -119,12 +120,12 @@ typedef uint32_t wuffs_base__color_u32argb;
|
||||
// G₂G₁G₀B₄B₃B₂B₁B₀ R₄R₃R₂R₁R₀G₅G₄G₃
|
||||
//
|
||||
// On little-endian systems (but not big-endian), this Wuffs pixel format value
|
||||
// (0x20000565) corresponds to the Cairo library's CAIRO_FORMAT_RGB16_565, the
|
||||
// (0x40000565) corresponds to the Cairo library's CAIRO_FORMAT_RGB16_565, the
|
||||
// SDL2 (Simple DirectMedia Layer 2) library's SDL_PIXELFORMAT_RGB565 and the
|
||||
// Skia library's kRGB_565_SkColorType. Note BGR in Wuffs versus RGB in the
|
||||
// other libraries.
|
||||
//
|
||||
// Regardless of endianness, this Wuffs pixel format value (0x20000565)
|
||||
// Regardless of endianness, this Wuffs pixel format value (0x40000565)
|
||||
// corresponds to the V4L2 (Video For Linux 2) library's V4L2_PIX_FMT_RGB565
|
||||
// and the Wayland-DRM library's WL_DRM_FORMAT_RGB565.
|
||||
//
|
||||
@@ -152,30 +153,35 @@ typedef uint32_t wuffs_base__pixel_format;
|
||||
#define WUFFS_BASE__PIXEL_FORMAT__YA_PREMUL \
|
||||
((wuffs_base__pixel_format)0x13000008)
|
||||
|
||||
#define WUFFS_BASE__PIXEL_FORMAT__YCBCR ((wuffs_base__pixel_format)0x20020888)
|
||||
#define WUFFS_BASE__PIXEL_FORMAT__YCBCRK ((wuffs_base__pixel_format)0x21038888)
|
||||
#define WUFFS_BASE__PIXEL_FORMAT__YCBCRA_NONPREMUL \
|
||||
((wuffs_base__pixel_format)0x22038888)
|
||||
|
||||
#define WUFFS_BASE__PIXEL_FORMAT__YCOCG ((wuffs_base__pixel_format)0x30020888)
|
||||
#define WUFFS_BASE__PIXEL_FORMAT__YCOCGK ((wuffs_base__pixel_format)0x31038888)
|
||||
#define WUFFS_BASE__PIXEL_FORMAT__YCOCGA_NONPREMUL \
|
||||
((wuffs_base__pixel_format)0x32038888)
|
||||
|
||||
#define WUFFS_BASE__PIXEL_FORMAT__INDEXED__BGRA_NONPREMUL \
|
||||
((wuffs_base__pixel_format)0x22040008)
|
||||
((wuffs_base__pixel_format)0x42040008)
|
||||
|
||||
#define WUFFS_BASE__PIXEL_FORMAT__BGR ((wuffs_base__pixel_format)0x20000888)
|
||||
#define WUFFS_BASE__PIXEL_FORMAT__BGRX ((wuffs_base__pixel_format)0x21008888)
|
||||
#define WUFFS_BASE__PIXEL_FORMAT__BGR ((wuffs_base__pixel_format)0x40000888)
|
||||
#define WUFFS_BASE__PIXEL_FORMAT__BGRX ((wuffs_base__pixel_format)0x41008888)
|
||||
#define WUFFS_BASE__PIXEL_FORMAT__BGRA_NONPREMUL \
|
||||
((wuffs_base__pixel_format)0x22008888)
|
||||
((wuffs_base__pixel_format)0x42008888)
|
||||
#define WUFFS_BASE__PIXEL_FORMAT__BGRA_PREMUL \
|
||||
((wuffs_base__pixel_format)0x23008888)
|
||||
((wuffs_base__pixel_format)0x43008888)
|
||||
|
||||
#define WUFFS_BASE__PIXEL_FORMAT__RGB ((wuffs_base__pixel_format)0x30000888)
|
||||
#define WUFFS_BASE__PIXEL_FORMAT__RGBX ((wuffs_base__pixel_format)0x31008888)
|
||||
#define WUFFS_BASE__PIXEL_FORMAT__RGB ((wuffs_base__pixel_format)0x50000888)
|
||||
#define WUFFS_BASE__PIXEL_FORMAT__RGBX ((wuffs_base__pixel_format)0x51008888)
|
||||
#define WUFFS_BASE__PIXEL_FORMAT__RGBA_NONPREMUL \
|
||||
((wuffs_base__pixel_format)0x32008888)
|
||||
((wuffs_base__pixel_format)0x52008888)
|
||||
#define WUFFS_BASE__PIXEL_FORMAT__RGBA_PREMUL \
|
||||
((wuffs_base__pixel_format)0x33008888)
|
||||
((wuffs_base__pixel_format)0x53008888)
|
||||
|
||||
#define WUFFS_BASE__PIXEL_FORMAT__YUV ((wuffs_base__pixel_format)0x40020888)
|
||||
#define WUFFS_BASE__PIXEL_FORMAT__YUVK ((wuffs_base__pixel_format)0x41038888)
|
||||
#define WUFFS_BASE__PIXEL_FORMAT__YUVA_NONPREMUL \
|
||||
((wuffs_base__pixel_format)0x42038888)
|
||||
|
||||
#define WUFFS_BASE__PIXEL_FORMAT__CMY ((wuffs_base__pixel_format)0x50020888)
|
||||
#define WUFFS_BASE__PIXEL_FORMAT__CMYK ((wuffs_base__pixel_format)0x51038888)
|
||||
#define WUFFS_BASE__PIXEL_FORMAT__CMY ((wuffs_base__pixel_format)0x60020888)
|
||||
#define WUFFS_BASE__PIXEL_FORMAT__CMYK ((wuffs_base__pixel_format)0x61038888)
|
||||
|
||||
static inline bool //
|
||||
wuffs_base__pixel_format__is_valid(wuffs_base__pixel_format f) {
|
||||
@@ -206,9 +212,9 @@ wuffs_base__pixel_format__num_planes(wuffs_base__pixel_format f) {
|
||||
//
|
||||
// For packed pixel formats, the mapping is trivial: i = x and j = y. For
|
||||
// planar pixel formats, the mapping can differ due to chroma subsampling. For
|
||||
// example, consider a three plane YUV pixel format with 4:2:2 subsampling. For
|
||||
// the luma (Y) channel, there is one sample for every pixel, but for the
|
||||
// chroma (U, V) channels, there is one sample for every two pixels: pairs of
|
||||
// example, consider a three plane YCbCr pixel format with 4:2:2 subsampling.
|
||||
// For the luma (Y) channel, there is one sample for every pixel, but for the
|
||||
// chroma (Cb, Cr) channels, there is one sample for every two pixels: pairs of
|
||||
// horizontally adjacent pixels form one macropixel, i = x / 2 and j == y. In
|
||||
// general, for a given p:
|
||||
// - i = (x + bias_x) >> shift_x.
|
||||
|
||||
@@ -123,22 +123,22 @@ const baseBaseImplC = "" +
|
||||
const baseImagePublicH = "" +
|
||||
"// Copyright 2017 The Wuffs Authors.\n//\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// https://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\n#ifdef __cplusplus\nextern \"C\" {\n#endif\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" +
|
||||
"// ---------------- Images\n\n// wuffs_base__color_u32_argb_premul is an 8 bit per channel premultiplied\n// Alpha, Red, Green, Blue color, as a uint32_t value. It is in word order, not\n// byte order: its value is always 0xAARRGGBB, regardless of endianness.\ntypedef uint32_t wuffs_base__color_u32_argb_premul;\n\n" +
|
||||
"" +
|
||||
"// --------\n\n// wuffs_base__pixel_format encodes the format of the bytes that constitute an\n// image frame's pixel data. Its bits:\n// - bit 31 is reserved.\n// - bits 30 .. 28 encodes color (and channel order, in terms of memory).\n// - bits 27 .. 26 are reserved.\n// - bits 25 .. 24 encodes transparency.\n// - bits 23 .. 21 are reserved.\n// - bit 20 indicates big-endian/MSB-first (as opposed to little/LSB).\n// - bit 19 indicates floating point (as opposed to integer).\n// - bit 18 indicates palette-indexed. The number-of-planes (the next\n// field) will be zero, as the format is considered packed,\n// but the 8-bit N-BGRA color data is stored in plane 3.\n// - bits 17 .. 16 are the number of planes, minus 1. Zero means packed.\n// - bits 15 .. 12 encodes the number of bits (depth) in the 3rd channel.\n// - bits 11 .. 8 encodes the number of bits (depth) in the 2nd channel.\n// - bits 7 .. 4 encodes the number of bits (depth) in the 1st channe" +
|
||||
"l.\n// - bits 3 .. 0 encodes the number of bits (depth) in the 0th channel.\n//\n// The bit fields of a wuffs_base__pixel_format are not independent. For\n// example, the number of planes should not be greater than the number of\n// channels. Similarly, bits 15..4 are unused (and should be zero) if bits\n// 31..24 (color and transparency) together imply only 1 channel (gray, no\n// alpha) and floating point samples should mean a bit depth of 16, 32 or 64.\n//\n// Formats hold between 1 and 4 channels. For example: Y (1 channel: gray), YA\n// (2 channels: gray and alpha), BGR (3 channels: blue, green, red) or CMYK (4\n// channels: cyan, magenta, yellow, black).\n//\n// For direct formats with N > 1 channels, those channels can be laid out in\n// either 1 (packed) or N (planar) planes. For example, RGBA data is usually\n// packed, but YUV data is usually planar, due to chroma subsampling (for\n// details, see the wuffs_base__pixel_subsampling type).\n//\n// For indexed formats, the palette (always 256 × 4 bytes) holds 8 bits" +
|
||||
" per\n// channel non-alpha-premultiplied BGRA color data. There is only 1 plane (for\n// the index), as the format is considered packed. Plane 0 holds the per-pixel\n// indices. Plane 3 is re-purposed to hold the per-index colors.\n//\n// The color field is encoded in 3 bits:\n// - 0 means A (Alpha).\n// - 1 means Y or YA (Gray, Alpha).\n// - 2 means BGR, BGRX or BGRA (Blue, Green, Red, X-padding or Alpha).\n// - 3 means RGB, RGBX or RGBA (Red, Green, Blue, X-padding or Alpha).\n// - 4 means YUV or YUVA (Luma, Chroma-blue, Chroma-red, Alpha).\n// - 5 means CMY or CMYK (Cyan, Magenta, Yellow, Black).\n// - all other values are reserved.\n//\n// In Wuffs, channels are given in memory order (also known as byte order),\n// regardless of endianness, since the C type for the pixel data is an array of\n// bytes, not an array of uint32_t. For example, packed BGRA with 8 bits per\n// channel means that the bytes in memory are always Blue, Green, Red then\n// Alpha. On big-endian systems, tha" +
|
||||
"t is the uint32_t 0xBBGGRRAA. On\n// little-endian, 0xAARRGGBB.\n//\n// When the color field (3 bits) encodes multiple options, the transparency\n// field (2 bits) distinguishes them:\n// - 0 means fully opaque, no extra channels\n// - 1 means fully opaque, one extra channel (X or K, padding or black).\n// - 2 means one extra alpha channel, other channels are non-premultiplied.\n// - 3 means one extra alpha channel, other channels are premultiplied.\n//\n// The zero wuffs_base__pixel_format value is an invalid pixel format, as it is\n// invalid to combine the zero color (alpha only) with the zero transparency.\n//\n// Bit depth is encoded in 4 bits:\n// - 0 means the channel or index is unused.\n// - x means a bit depth of x, for x in the range 1..8.\n// - 9 means a bit depth of 10.\n// - 10 means a bit depth of 12.\n// - 11 means a bit depth of 16.\n// - 12 means a bit depth of 24.\n// - 13 means a bit depth of 32.\n// - 14 means a bit depth of 48.\n// - 15 means a bit depth of 64.\n//\n// For example, wuffs_ba" +
|
||||
"se__pixel_format 0x3210BBBB is a natural format for\n// decoding a PNG image - network byte order (also known as big-endian),\n// packed, non-premultiplied alpha - that happens to be 16-bit-depth truecolor\n// with alpha (RGBA). In memory order:\n//\n// ptr+0 ptr+1 ptr+2 ptr+3 ptr+4 ptr+5 ptr+6 ptr+7\n// Rhi Rlo Ghi Glo Bhi Blo Ahi Alo\n//\n// For example, the value wuffs_base__pixel_format 0x20000565 means BGR with no\n// alpha or padding, 5/6/5 bits for blue/green/red, packed 2 bytes per pixel,\n// laid out LSB-first in memory order:\n//\n// ptr+0........... ptr+1...........\n// MSB LSB MSB LSB\n// G₂G₁G₀B₄B₃B₂B₁B₀ R₄R₃R₂R₁R₀G₅G₄G₃\n//\n// On little-endian systems (but not big-endian), this Wuffs pixel format value\n// (0x20000565) corresponds to the Cairo library's CAIRO_FORMAT_RGB16_565, the\n// SDL2 (Simple DirectMedia Layer 2) library's SDL_PIXELFORMAT_RGB565 and the\n// Skia library's kRGB_565_SkColorType. Note BGR in Wuffs versus RGB i" +
|
||||
"n the\n// other libraries.\n//\n// Regardless of endianness, this Wuffs pixel format value (0x20000565)\n// corresponds to the V4L2 (Video For Linux 2) library's V4L2_PIX_FMT_RGB565\n// and the Wayland-DRM library's WL_DRM_FORMAT_RGB565.\n//\n// Different software libraries name their pixel formats (and especially their\n// channel order) either according to memory layout or as bits of a native\n// integer type like uint32_t. The two conventions differ because of a system's\n// endianness. As mentioned earlier, Wuffs pixel formats are always in memory\n// order. More detail of other software libraries' naming conventions is in the\n// Pixel Format Guide at https://afrantzis.github.io/pixel-format-guide/\n//\n// Do not manipulate these bits directly; they are private implementation\n// details. Use methods such as wuffs_base__pixel_format__num_planes instead.\ntypedef uint32_t wuffs_base__pixel_format;\n\n// Common 8-bit-depth pixel formats. This list is not exhaustive; not all valid\n// wuffs_base__pixel_format values are prese" +
|
||||
"nt.\n\n#define WUFFS_BASE__PIXEL_FORMAT__INVALID ((wuffs_base__pixel_format)0x00000000)\n\n#define WUFFS_BASE__PIXEL_FORMAT__A ((wuffs_base__pixel_format)0x02000008)\n\n#define WUFFS_BASE__PIXEL_FORMAT__Y ((wuffs_base__pixel_format)0x10000008)\n#define WUFFS_BASE__PIXEL_FORMAT__YA_NONPREMUL \\\n ((wuffs_base__pixel_format)0x12000008)\n#define WUFFS_BASE__PIXEL_FORMAT__YA_PREMUL \\\n ((wuffs_base__pixel_format)0x13000008)\n\n#define WUFFS_BASE__PIXEL_FORMAT__INDEXED__BGRA_NONPREMUL \\\n ((wuffs_base__pixel_format)0x22040008)\n\n#define WUFFS_BASE__PIXEL_FORMAT__BGR ((wuffs_base__pixel_format)0x20000888)\n#define WUFFS_BASE__PIXEL_FORMAT__BGRX ((wuffs_base__pixel_format)0x21008888)\n#define WUFFS_BASE__PIXEL_FORMAT__BGRA_NONPREMUL \\\n ((wuffs_base__pixel_format)0x22008888)\n#define WUFFS_BASE__PIXEL_FORMAT__BGRA_PREMUL \\\n ((wuffs_base__pixel_format)0x23008888)\n\n#define WUFFS_BASE__PIXEL_FORMAT__RGB ((wuffs_base__pixel_format)0x30000888)\n#define WUFFS_BASE__PIXEL_FORMAT__RGBX ((wuffs_base__pixel_format)0x31008888)\n#define WUFFS_" +
|
||||
"BASE__PIXEL_FORMAT__RGBA_NONPREMUL \\\n ((wuffs_base__pixel_format)0x32008888)\n#define WUFFS_BASE__PIXEL_FORMAT__RGBA_PREMUL \\\n ((wuffs_base__pixel_format)0x33008888)\n\n#define WUFFS_BASE__PIXEL_FORMAT__YUV ((wuffs_base__pixel_format)0x40020888)\n#define WUFFS_BASE__PIXEL_FORMAT__YUVK ((wuffs_base__pixel_format)0x41038888)\n#define WUFFS_BASE__PIXEL_FORMAT__YUVA_NONPREMUL \\\n ((wuffs_base__pixel_format)0x42038888)\n\n#define WUFFS_BASE__PIXEL_FORMAT__CMY ((wuffs_base__pixel_format)0x50020888)\n#define WUFFS_BASE__PIXEL_FORMAT__CMYK ((wuffs_base__pixel_format)0x51038888)\n\nstatic inline bool //\nwuffs_base__pixel_format__is_valid(wuffs_base__pixel_format f) {\n return f != 0;\n}\n\nstatic inline bool //\nwuffs_base__pixel_format__is_indexed(wuffs_base__pixel_format f) {\n return (f >> 18) & 0x01;\n}\n\nstatic inline uint32_t //\nwuffs_base__pixel_format__num_planes(wuffs_base__pixel_format f) {\n return f ? (((f >> 16) & 0x03) + 1) : 0;\n}\n\n#define WUFFS_BASE__PIXEL_FORMAT__NUM_PLANES_MAX 4\n\n#define WUFFS_BASE__PIXEL_FORMAT" +
|
||||
"__INDEXED__INDEX_PLANE 0\n#define WUFFS_BASE__PIXEL_FORMAT__INDEXED__COLOR_PLANE 3\n\n" +
|
||||
"l.\n// - bits 3 .. 0 encodes the number of bits (depth) in the 0th channel.\n//\n// The bit fields of a wuffs_base__pixel_format are not independent. For\n// example, the number of planes should not be greater than the number of\n// channels. Similarly, bits 15..4 are unused (and should be zero) if bits\n// 31..24 (color and transparency) together imply only 1 channel (gray, no\n// alpha) and floating point samples should mean a bit depth of 16, 32 or 64.\n//\n// Formats hold between 1 and 4 channels. For example: Y (1 channel: gray), YA\n// (2 channels: gray and alpha), BGR (3 channels: blue, green, red) or CMYK (4\n// channels: cyan, magenta, yellow, black).\n//\n// For direct formats with N > 1 channels, those channels can be laid out in\n// either 1 (packed) or N (planar) planes. For example, RGBA data is usually\n// packed, but YCbCr data is usually planar, due to chroma subsampling (for\n// details, see the wuffs_base__pixel_subsampling type).\n//\n// For indexed formats, the palette (always 256 × 4 bytes) holds 8 bi" +
|
||||
"ts per\n// channel non-alpha-premultiplied BGRA color data. There is only 1 plane (for\n// the index), as the format is considered packed. Plane 0 holds the per-pixel\n// indices. Plane 3 is re-purposed to hold the per-index colors.\n//\n// The color field is encoded in 3 bits:\n// - 0 means A (Alpha).\n// - 1 means Y or YA (Gray, Alpha).\n// - 2 means YCbCr or YCbCrA (Luma, Chroma-blue, Chroma-red, Alpha).\n// - 3 means YCoCg or YCoCgA (Luma, Chroma-orange, Chroma-green, Alpha).\n// - 4 means BGR, BGRX or BGRA (Blue, Green, Red, X-padding or Alpha).\n// - 5 means RGB, RGBX or RGBA (Red, Green, Blue, X-padding or Alpha).\n// - 6 means CMY or CMYK (Cyan, Magenta, Yellow, Black).\n// - all other values are reserved.\n//\n// In Wuffs, channels are given in memory order (also known as byte order),\n// regardless of endianness, since the C type for the pixel data is an array of\n// bytes, not an array of uint32_t. For example, packed BGRA with 8 bits per\n// channel means th" +
|
||||
"at the bytes in memory are always Blue, Green, Red then\n// Alpha. On big-endian systems, that is the uint32_t 0xBBGGRRAA. On\n// little-endian, 0xAARRGGBB.\n//\n// When the color field (3 bits) encodes multiple options, the transparency\n// field (2 bits) distinguishes them:\n// - 0 means fully opaque, no extra channels\n// - 1 means fully opaque, one extra channel (X or K, padding or black).\n// - 2 means one extra alpha channel, other channels are non-premultiplied.\n// - 3 means one extra alpha channel, other channels are premultiplied.\n//\n// The zero wuffs_base__pixel_format value is an invalid pixel format, as it is\n// invalid to combine the zero color (alpha only) with the zero transparency.\n//\n// Bit depth is encoded in 4 bits:\n// - 0 means the channel or index is unused.\n// - x means a bit depth of x, for x in the range 1..8.\n// - 9 means a bit depth of 10.\n// - 10 means a bit depth of 12.\n// - 11 means a bit depth of 16.\n// - 12 means a bit depth of 24.\n// - 13 means a bit depth of 32.\n// " +
|
||||
" - 14 means a bit depth of 48.\n// - 15 means a bit depth of 64.\n//\n// For example, wuffs_base__pixel_format 0x5210BBBB is a natural format for\n// decoding a PNG image - network byte order (also known as big-endian),\n// packed, non-premultiplied alpha - that happens to be 16-bit-depth truecolor\n// with alpha (RGBA). In memory order:\n//\n// ptr+0 ptr+1 ptr+2 ptr+3 ptr+4 ptr+5 ptr+6 ptr+7\n// Rhi Rlo Ghi Glo Bhi Blo Ahi Alo\n//\n// For example, the value wuffs_base__pixel_format 0x40000565 means BGR with no\n// alpha or padding, 5/6/5 bits for blue/green/red, packed 2 bytes per pixel,\n// laid out LSB-first in memory order:\n//\n// ptr+0........... ptr+1...........\n// MSB LSB MSB LSB\n// G₂G₁G₀B₄B₃B₂B₁B₀ R₄R₃R₂R₁R₀G₅G₄G₃\n//\n// On little-endian systems (but not big-endian), this Wuffs pixel format value\n// (0x40000565) corresponds to the Cairo library's CAIRO_FORMAT_RGB16_565, the\n// SDL2 (Simple DirectMedia Layer 2) library's SDL_PIXEL" +
|
||||
"FORMAT_RGB565 and the\n// Skia library's kRGB_565_SkColorType. Note BGR in Wuffs versus RGB in the\n// other libraries.\n//\n// Regardless of endianness, this Wuffs pixel format value (0x40000565)\n// corresponds to the V4L2 (Video For Linux 2) library's V4L2_PIX_FMT_RGB565\n// and the Wayland-DRM library's WL_DRM_FORMAT_RGB565.\n//\n// Different software libraries name their pixel formats (and especially their\n// channel order) either according to memory layout or as bits of a native\n// integer type like uint32_t. The two conventions differ because of a system's\n// endianness. As mentioned earlier, Wuffs pixel formats are always in memory\n// order. More detail of other software libraries' naming conventions is in the\n// Pixel Format Guide at https://afrantzis.github.io/pixel-format-guide/\n//\n// Do not manipulate these bits directly; they are private implementation\n// details. Use methods such as wuffs_base__pixel_format__num_planes instead.\ntypedef uint32_t wuffs_base__pixel_format;\n\n// Common 8-bit-depth pixel form" +
|
||||
"ats. This list is not exhaustive; not all valid\n// wuffs_base__pixel_format values are present.\n\n#define WUFFS_BASE__PIXEL_FORMAT__INVALID ((wuffs_base__pixel_format)0x00000000)\n\n#define WUFFS_BASE__PIXEL_FORMAT__A ((wuffs_base__pixel_format)0x02000008)\n\n#define WUFFS_BASE__PIXEL_FORMAT__Y ((wuffs_base__pixel_format)0x10000008)\n#define WUFFS_BASE__PIXEL_FORMAT__YA_NONPREMUL \\\n ((wuffs_base__pixel_format)0x12000008)\n#define WUFFS_BASE__PIXEL_FORMAT__YA_PREMUL \\\n ((wuffs_base__pixel_format)0x13000008)\n\n#define WUFFS_BASE__PIXEL_FORMAT__YCBCR ((wuffs_base__pixel_format)0x20020888)\n#define WUFFS_BASE__PIXEL_FORMAT__YCBCRK ((wuffs_base__pixel_format)0x21038888)\n#define WUFFS_BASE__PIXEL_FORMAT__YCBCRA_NONPREMUL \\\n ((wuffs_base__pixel_format)0x22038888)\n\n#define WUFFS_BASE__PIXEL_FORMAT__YCOCG ((wuffs_base__pixel_format)0x30020888)\n#define WUFFS_BASE__PIXEL_FORMAT__YCOCGK ((wuffs_base__pixel_format)0x31038888)\n#define WUFFS_BASE__PIXEL_FORMAT__YCOCGA_NONPREMUL \\\n ((wuffs_base__pixel_format)0x32038888)\n\n#define " +
|
||||
"WUFFS_BASE__PIXEL_FORMAT__INDEXED__BGRA_NONPREMUL \\\n ((wuffs_base__pixel_format)0x42040008)\n\n#define WUFFS_BASE__PIXEL_FORMAT__BGR ((wuffs_base__pixel_format)0x40000888)\n#define WUFFS_BASE__PIXEL_FORMAT__BGRX ((wuffs_base__pixel_format)0x41008888)\n#define WUFFS_BASE__PIXEL_FORMAT__BGRA_NONPREMUL \\\n ((wuffs_base__pixel_format)0x42008888)\n#define WUFFS_BASE__PIXEL_FORMAT__BGRA_PREMUL \\\n ((wuffs_base__pixel_format)0x43008888)\n\n#define WUFFS_BASE__PIXEL_FORMAT__RGB ((wuffs_base__pixel_format)0x50000888)\n#define WUFFS_BASE__PIXEL_FORMAT__RGBX ((wuffs_base__pixel_format)0x51008888)\n#define WUFFS_BASE__PIXEL_FORMAT__RGBA_NONPREMUL \\\n ((wuffs_base__pixel_format)0x52008888)\n#define WUFFS_BASE__PIXEL_FORMAT__RGBA_PREMUL \\\n ((wuffs_base__pixel_format)0x53008888)\n\n#define WUFFS_BASE__PIXEL_FORMAT__CMY ((wuffs_base__pixel_format)0x60020888)\n#define WUFFS_BASE__PIXEL_FORMAT__CMYK ((wuffs_base__pixel_format)0x61038888)\n\nstatic inline bool //\nwuffs_base__pixel_format__is_valid(wuffs_base__pixel_format f) {\n return f !" +
|
||||
"= 0;\n}\n\nstatic inline bool //\nwuffs_base__pixel_format__is_indexed(wuffs_base__pixel_format f) {\n return (f >> 18) & 0x01;\n}\n\nstatic inline uint32_t //\nwuffs_base__pixel_format__num_planes(wuffs_base__pixel_format f) {\n return f ? (((f >> 16) & 0x03) + 1) : 0;\n}\n\n#define WUFFS_BASE__PIXEL_FORMAT__NUM_PLANES_MAX 4\n\n#define WUFFS_BASE__PIXEL_FORMAT__INDEXED__INDEX_PLANE 0\n#define WUFFS_BASE__PIXEL_FORMAT__INDEXED__COLOR_PLANE 3\n\n" +
|
||||
"" +
|
||||
"// --------\n\n// wuffs_base__pixel_subsampling encodes the mapping of pixel space coordinates\n// (x, y) to pixel buffer indices (i, j). That mapping can differ for each\n// plane p. For a depth of 8 bits (1 byte), the p'th plane's sample starts at\n// (planes[p].ptr + (j * planes[p].stride) + i).\n//\n// For packed pixel formats, the mapping is trivial: i = x and j = y. For\n// planar pixel formats, the mapping can differ due to chroma subsampling. For\n// example, consider a three plane YUV pixel format with 4:2:2 subsampling. For\n// the luma (Y) channel, there is one sample for every pixel, but for the\n// chroma (U, V) channels, there is one sample for every two pixels: pairs of\n// horizontally adjacent pixels form one macropixel, i = x / 2 and j == y. In\n// general, for a given p:\n// - i = (x + bias_x) >> shift_x.\n// - j = (y + bias_y) >> shift_y.\n// where biases and shifts are in the range 0..3 and 0..2 respectively.\n//\n// In general, the biases will be zero after decoding an image. However, making\n// a sub-im" +
|
||||
"age may change the bias, since the (x, y) coordinates are relative\n// to the sub-image's top-left origin, but the backing pixel buffers were\n// created relative to the original image's origin.\n//\n// For each plane p, each of those four numbers (biases and shifts) are encoded\n// in two bits, which combine to form an 8 bit unsigned integer:\n//\n// e_p = (bias_x << 6) | (shift_x << 4) | (bias_y << 2) | (shift_y << 0)\n//\n// Those e_p values (e_0 for the first plane, e_1 for the second plane, etc)\n// combine to form a wuffs_base__pixel_subsampling value:\n//\n// pixsub = (e_3 << 24) | (e_2 << 16) | (e_1 << 8) | (e_0 << 0)\n//\n// Do not manipulate these bits directly; they are private implementation\n// details. Use methods such as wuffs_base__pixel_subsampling__bias_x instead.\ntypedef uint32_t wuffs_base__pixel_subsampling;\n\n#define WUFFS_BASE__PIXEL_SUBSAMPLING__NONE ((wuffs_base__pixel_subsampling)0)\n\n#define WUFFS_BASE__PIXEL_SUBSAMPLING__444 \\\n ((wuffs_base__pixel_subsampling)0x000000)\n#define WUFFS_BASE__PIXEL_" +
|
||||
"SUBSAMPLING__440 \\\n ((wuffs_base__pixel_subsampling)0x010100)\n#define WUFFS_BASE__PIXEL_SUBSAMPLING__422 \\\n ((wuffs_base__pixel_subsampling)0x101000)\n#define WUFFS_BASE__PIXEL_SUBSAMPLING__420 \\\n ((wuffs_base__pixel_subsampling)0x111100)\n#define WUFFS_BASE__PIXEL_SUBSAMPLING__411 \\\n ((wuffs_base__pixel_subsampling)0x202000)\n#define WUFFS_BASE__PIXEL_SUBSAMPLING__410 \\\n ((wuffs_base__pixel_subsampling)0x212100)\n\nstatic inline uint32_t //\nwuffs_base__pixel_subsampling__bias_x(wuffs_base__pixel_subsampling s,\n uint32_t plane) {\n uint32_t shift = ((plane & 0x03) * 8) + 6;\n return (s >> shift) & 0x03;\n}\n\nstatic inline uint32_t //\nwuffs_base__pixel_subsampling__shift_x(wuffs_base__pixel_subsampling s,\n uint32_t plane) {\n uint32_t shift = ((plane & 0x03) * 8) + 4;\n return (s >> shift) & 0x03;\n}\n\nstatic inline uint32_t //\nwuffs_base__pixel_subsampling__bias_y(wuffs_base__pixel_subsampling s,\n ui" +
|
||||
"nt32_t plane) {\n uint32_t shift = ((plane & 0x03) * 8) + 2;\n return (s >> shift) & 0x03;\n}\n\nstatic inline uint32_t //\nwuffs_base__pixel_subsampling__shift_y(wuffs_base__pixel_subsampling s,\n uint32_t plane) {\n uint32_t shift = ((plane & 0x03) * 8) + 0;\n return (s >> shift) & 0x03;\n}\n\n" +
|
||||
"// --------\n\n// wuffs_base__pixel_subsampling encodes the mapping of pixel space coordinates\n// (x, y) to pixel buffer indices (i, j). That mapping can differ for each\n// plane p. For a depth of 8 bits (1 byte), the p'th plane's sample starts at\n// (planes[p].ptr + (j * planes[p].stride) + i).\n//\n// For packed pixel formats, the mapping is trivial: i = x and j = y. For\n// planar pixel formats, the mapping can differ due to chroma subsampling. For\n// example, consider a three plane YCbCr pixel format with 4:2:2 subsampling.\n// For the luma (Y) channel, there is one sample for every pixel, but for the\n// chroma (Cb, Cr) channels, there is one sample for every two pixels: pairs of\n// horizontally adjacent pixels form one macropixel, i = x / 2 and j == y. In\n// general, for a given p:\n// - i = (x + bias_x) >> shift_x.\n// - j = (y + bias_y) >> shift_y.\n// where biases and shifts are in the range 0..3 and 0..2 respectively.\n//\n// In general, the biases will be zero after decoding an image. However, making\n// a su" +
|
||||
"b-image may change the bias, since the (x, y) coordinates are relative\n// to the sub-image's top-left origin, but the backing pixel buffers were\n// created relative to the original image's origin.\n//\n// For each plane p, each of those four numbers (biases and shifts) are encoded\n// in two bits, which combine to form an 8 bit unsigned integer:\n//\n// e_p = (bias_x << 6) | (shift_x << 4) | (bias_y << 2) | (shift_y << 0)\n//\n// Those e_p values (e_0 for the first plane, e_1 for the second plane, etc)\n// combine to form a wuffs_base__pixel_subsampling value:\n//\n// pixsub = (e_3 << 24) | (e_2 << 16) | (e_1 << 8) | (e_0 << 0)\n//\n// Do not manipulate these bits directly; they are private implementation\n// details. Use methods such as wuffs_base__pixel_subsampling__bias_x instead.\ntypedef uint32_t wuffs_base__pixel_subsampling;\n\n#define WUFFS_BASE__PIXEL_SUBSAMPLING__NONE ((wuffs_base__pixel_subsampling)0)\n\n#define WUFFS_BASE__PIXEL_SUBSAMPLING__444 \\\n ((wuffs_base__pixel_subsampling)0x000000)\n#define WUFFS_BASE__PI" +
|
||||
"XEL_SUBSAMPLING__440 \\\n ((wuffs_base__pixel_subsampling)0x010100)\n#define WUFFS_BASE__PIXEL_SUBSAMPLING__422 \\\n ((wuffs_base__pixel_subsampling)0x101000)\n#define WUFFS_BASE__PIXEL_SUBSAMPLING__420 \\\n ((wuffs_base__pixel_subsampling)0x111100)\n#define WUFFS_BASE__PIXEL_SUBSAMPLING__411 \\\n ((wuffs_base__pixel_subsampling)0x202000)\n#define WUFFS_BASE__PIXEL_SUBSAMPLING__410 \\\n ((wuffs_base__pixel_subsampling)0x212100)\n\nstatic inline uint32_t //\nwuffs_base__pixel_subsampling__bias_x(wuffs_base__pixel_subsampling s,\n uint32_t plane) {\n uint32_t shift = ((plane & 0x03) * 8) + 6;\n return (s >> shift) & 0x03;\n}\n\nstatic inline uint32_t //\nwuffs_base__pixel_subsampling__shift_x(wuffs_base__pixel_subsampling s,\n uint32_t plane) {\n uint32_t shift = ((plane & 0x03) * 8) + 4;\n return (s >> shift) & 0x03;\n}\n\nstatic inline uint32_t //\nwuffs_base__pixel_subsampling__bias_y(wuffs_base__pixel_subsampling s,\n " +
|
||||
" uint32_t plane) {\n uint32_t shift = ((plane & 0x03) * 8) + 2;\n return (s >> shift) & 0x03;\n}\n\nstatic inline uint32_t //\nwuffs_base__pixel_subsampling__shift_y(wuffs_base__pixel_subsampling s,\n uint32_t plane) {\n uint32_t shift = ((plane & 0x03) * 8) + 0;\n return (s >> shift) & 0x03;\n}\n\n" +
|
||||
"" +
|
||||
"// --------\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__pixel_format pixfmt;\n wuffs_base__pixel_subsampling pixsub;\n uint32_t width;\n uint32_t height;\n } private_impl;\n\n#ifdef __cplusplus\n inline void initialize(wuffs_base__pixel_format pixfmt,\n wuffs_base__pixel_subsampling pixsub,\n uint32_t width,\n uint32_t height);\n inline void invalidate();\n inline bool is_valid();\n inline wuffs_base__pixel_format pixel_format();\n inline wuffs_base__pixel_subsampling pixel_subsampling();\n inline wuffs_base__rect_ie_u32 bounds();\n inline uint32_t width();\n inline uint32_t height();\n inline uint64_t pixbuf_len();\n#endif // __cplusplus\n\n} wuffs_base__pixel_config;\n\n// TODO: Should this function return bool? An error type?\nstatic inline void //\nwuffs_base__pixel_config__initialize(wuffs_base__pixel_config* c" +
|
||||
",\n wuffs_base__pixel_format pixfmt,\n wuffs_base__pixel_subsampling pixsub,\n uint32_t width,\n uint32_t height) {\n if (!c) {\n return;\n }\n if (pixfmt) {\n uint64_t wh = ((uint64_t)width) * ((uint64_t)height);\n // TODO: handle things other than 1 byte per pixel.\n if (wh <= ((uint64_t)SIZE_MAX)) {\n c->private_impl.pixfmt = pixfmt;\n c->private_impl.pixsub = pixsub;\n c->private_impl.width = width;\n c->private_impl.height = height;\n return;\n }\n }\n *c = ((wuffs_base__pixel_config){});\n}\n\nstatic inline void //\nwuffs_base__pixel_config__invalidate(wuffs_base__pixel_config* c) {\n if (c) {\n *c = ((wuffs_base__pixel_config){});\n }\n}\n\nstatic inline bool //\nwuffs_base__pixel_config__is_valid(wuffs_base__pixel_config* c) {\n return c && c->private_impl.pixfmt;\n}\n\nstatic inline wuffs_base__pixel_format //\nwuffs_base__pixel_config__pix" +
|
||||
|
||||
@@ -78,8 +78,8 @@ uint64_t micros_since_start(struct timespec* now) {
|
||||
uint8_t src_buffer[SRC_BUFFER_SIZE] = {0};
|
||||
size_t src_len = 0;
|
||||
|
||||
wuffs_base__color_u32argb* curr_dst_buffer = NULL;
|
||||
wuffs_base__color_u32argb* prev_dst_buffer = NULL;
|
||||
wuffs_base__color_u32_argb_premul* curr_dst_buffer = NULL;
|
||||
wuffs_base__color_u32_argb_premul* prev_dst_buffer = NULL;
|
||||
size_t dst_len; // Length in bytes.
|
||||
|
||||
wuffs_base__slice_u8 pixbuf = ((wuffs_base__slice_u8){});
|
||||
@@ -136,7 +136,7 @@ void restore_background(wuffs_base__pixel_buffer* pb,
|
||||
size_t y;
|
||||
for (y = bounds.min_incl_y; y < bounds.max_excl_y; y++) {
|
||||
size_t x;
|
||||
wuffs_base__color_u32argb* d =
|
||||
wuffs_base__color_u32_argb_premul* d =
|
||||
curr_dst_buffer + (y * width) + bounds.min_incl_x;
|
||||
for (x = bounds.min_incl_x; x < bounds.max_excl_x; x++) {
|
||||
*d++ = 0;
|
||||
@@ -154,12 +154,13 @@ void compose(wuffs_base__pixel_buffer* pb, wuffs_base__rect_ie_u32 bounds) {
|
||||
size_t y;
|
||||
for (y = bounds.min_incl_y; y < bounds.max_excl_y; y++) {
|
||||
size_t x;
|
||||
wuffs_base__color_u32argb* d =
|
||||
wuffs_base__color_u32_argb_premul* d =
|
||||
curr_dst_buffer + (y * width) + bounds.min_incl_x;
|
||||
uint8_t* s = tab.ptr + (y * tab.stride) + bounds.min_incl_x;
|
||||
for (x = bounds.min_incl_x; x < bounds.max_excl_x; x++) {
|
||||
uint32_t index = *s++;
|
||||
wuffs_base__color_u32argb c = load_u32le(palette.ptr + (4 * index));
|
||||
wuffs_base__color_u32_argb_premul c =
|
||||
load_u32le(palette.ptr + (4 * index));
|
||||
if (c) {
|
||||
*d = c;
|
||||
}
|
||||
@@ -172,14 +173,14 @@ size_t print_ascii_art(wuffs_base__pixel_buffer* pb) {
|
||||
uint32_t width = wuffs_base__pixel_config__width(&pb->pixcfg);
|
||||
uint32_t height = wuffs_base__pixel_config__height(&pb->pixcfg);
|
||||
|
||||
wuffs_base__color_u32argb* d = curr_dst_buffer;
|
||||
wuffs_base__color_u32_argb_premul* d = curr_dst_buffer;
|
||||
uint8_t* p = printbuf.ptr;
|
||||
*p++ = '\n';
|
||||
uint32_t y;
|
||||
for (y = 0; y < height; y++) {
|
||||
uint32_t x;
|
||||
for (x = 0; x < width; x++) {
|
||||
wuffs_base__color_u32argb c = *d++;
|
||||
wuffs_base__color_u32_argb_premul c = *d++;
|
||||
// Convert to grayscale via the formula
|
||||
// Y = (0.299 * R) + (0.587 * G) + (0.114 * B)
|
||||
// translated into fixed point arithmetic.
|
||||
@@ -198,7 +199,7 @@ size_t print_color_art(wuffs_base__pixel_buffer* pb) {
|
||||
uint32_t width = wuffs_base__pixel_config__width(&pb->pixcfg);
|
||||
uint32_t height = wuffs_base__pixel_config__height(&pb->pixcfg);
|
||||
|
||||
wuffs_base__color_u32argb* d = curr_dst_buffer;
|
||||
wuffs_base__color_u32_argb_premul* d = curr_dst_buffer;
|
||||
uint8_t* p = printbuf.ptr;
|
||||
*p++ = '\n';
|
||||
p += sprintf((char*)p, "%s", reset_color);
|
||||
@@ -206,7 +207,7 @@ size_t print_color_art(wuffs_base__pixel_buffer* pb) {
|
||||
for (y = 0; y < height; y++) {
|
||||
uint32_t x;
|
||||
for (x = 0; x < width; x++) {
|
||||
wuffs_base__color_u32argb c = *d++;
|
||||
wuffs_base__color_u32_argb_premul c = *d++;
|
||||
int b = 0xFF & (c >> 0);
|
||||
int g = 0xFF & (c >> 8);
|
||||
int r = 0xFF & (c >> 16);
|
||||
@@ -226,17 +227,17 @@ const char* try_allocate(wuffs_base__image_config* ic) {
|
||||
uint32_t width = wuffs_base__pixel_config__width(&ic->pixcfg);
|
||||
uint32_t height = wuffs_base__pixel_config__height(&ic->pixcfg);
|
||||
uint64_t num_pixels = ((uint64_t)width) * ((uint64_t)height);
|
||||
if (num_pixels > (SIZE_MAX / sizeof(wuffs_base__color_u32argb))) {
|
||||
if (num_pixels > (SIZE_MAX / sizeof(wuffs_base__color_u32_argb_premul))) {
|
||||
return "could not allocate dst buffer";
|
||||
}
|
||||
|
||||
dst_len = num_pixels * sizeof(wuffs_base__color_u32argb);
|
||||
curr_dst_buffer = (wuffs_base__color_u32argb*)malloc(dst_len);
|
||||
dst_len = num_pixels * sizeof(wuffs_base__color_u32_argb_premul);
|
||||
curr_dst_buffer = (wuffs_base__color_u32_argb_premul*)malloc(dst_len);
|
||||
if (!curr_dst_buffer) {
|
||||
return "could not allocate curr-dst buffer";
|
||||
}
|
||||
|
||||
prev_dst_buffer = (wuffs_base__color_u32argb*)malloc(dst_len);
|
||||
prev_dst_buffer = (wuffs_base__color_u32_argb_premul*)malloc(dst_len);
|
||||
if (!prev_dst_buffer) {
|
||||
return "could not allocate prev-dst buffer";
|
||||
}
|
||||
@@ -368,7 +369,7 @@ const char* play() {
|
||||
break;
|
||||
}
|
||||
case WUFFS_BASE__ANIMATION_DISPOSAL__RESTORE_PREVIOUS: {
|
||||
wuffs_base__color_u32argb* swap = curr_dst_buffer;
|
||||
wuffs_base__color_u32_argb_premul* swap = curr_dst_buffer;
|
||||
curr_dst_buffer = prev_dst_buffer;
|
||||
prev_dst_buffer = swap;
|
||||
break;
|
||||
|
||||
@@ -1235,10 +1235,10 @@ extern "C" {
|
||||
|
||||
// ---------------- Images
|
||||
|
||||
// wuffs_base__color_u32argb is an 8 bit per channel Alpha, Red, Green, Blue
|
||||
// color, as a uint32_t value. It is in word order, not byte order: its value
|
||||
// is always 0xAARRGGBB, regardless of endianness. It uses premultiplied alpha.
|
||||
typedef uint32_t wuffs_base__color_u32argb;
|
||||
// wuffs_base__color_u32_argb_premul is an 8 bit per channel premultiplied
|
||||
// Alpha, Red, Green, Blue color, as a uint32_t value. It is in word order, not
|
||||
// byte order: its value is always 0xAARRGGBB, regardless of endianness.
|
||||
typedef uint32_t wuffs_base__color_u32_argb_premul;
|
||||
|
||||
// --------
|
||||
|
||||
@@ -1272,7 +1272,7 @@ typedef uint32_t wuffs_base__color_u32argb;
|
||||
//
|
||||
// For direct formats with N > 1 channels, those channels can be laid out in
|
||||
// either 1 (packed) or N (planar) planes. For example, RGBA data is usually
|
||||
// packed, but YUV data is usually planar, due to chroma subsampling (for
|
||||
// packed, but YCbCr data is usually planar, due to chroma subsampling (for
|
||||
// details, see the wuffs_base__pixel_subsampling type).
|
||||
//
|
||||
// For indexed formats, the palette (always 256 × 4 bytes) holds 8 bits per
|
||||
@@ -1281,12 +1281,13 @@ typedef uint32_t wuffs_base__color_u32argb;
|
||||
// indices. Plane 3 is re-purposed to hold the per-index colors.
|
||||
//
|
||||
// The color field is encoded in 3 bits:
|
||||
// - 0 means A (Alpha).
|
||||
// - 1 means Y or YA (Gray, Alpha).
|
||||
// - 2 means BGR, BGRX or BGRA (Blue, Green, Red, X-padding or Alpha).
|
||||
// - 3 means RGB, RGBX or RGBA (Red, Green, Blue, X-padding or Alpha).
|
||||
// - 4 means YUV or YUVA (Luma, Chroma-blue, Chroma-red, Alpha).
|
||||
// - 5 means CMY or CMYK (Cyan, Magenta, Yellow, Black).
|
||||
// - 0 means A (Alpha).
|
||||
// - 1 means Y or YA (Gray, Alpha).
|
||||
// - 2 means YCbCr or YCbCrA (Luma, Chroma-blue, Chroma-red, Alpha).
|
||||
// - 3 means YCoCg or YCoCgA (Luma, Chroma-orange, Chroma-green, Alpha).
|
||||
// - 4 means BGR, BGRX or BGRA (Blue, Green, Red, X-padding or Alpha).
|
||||
// - 5 means RGB, RGBX or RGBA (Red, Green, Blue, X-padding or Alpha).
|
||||
// - 6 means CMY or CMYK (Cyan, Magenta, Yellow, Black).
|
||||
// - all other values are reserved.
|
||||
//
|
||||
// In Wuffs, channels are given in memory order (also known as byte order),
|
||||
@@ -1317,7 +1318,7 @@ typedef uint32_t wuffs_base__color_u32argb;
|
||||
// - 14 means a bit depth of 48.
|
||||
// - 15 means a bit depth of 64.
|
||||
//
|
||||
// For example, wuffs_base__pixel_format 0x3210BBBB is a natural format for
|
||||
// For example, wuffs_base__pixel_format 0x5210BBBB is a natural format for
|
||||
// decoding a PNG image - network byte order (also known as big-endian),
|
||||
// packed, non-premultiplied alpha - that happens to be 16-bit-depth truecolor
|
||||
// with alpha (RGBA). In memory order:
|
||||
@@ -1325,7 +1326,7 @@ typedef uint32_t wuffs_base__color_u32argb;
|
||||
// ptr+0 ptr+1 ptr+2 ptr+3 ptr+4 ptr+5 ptr+6 ptr+7
|
||||
// Rhi Rlo Ghi Glo Bhi Blo Ahi Alo
|
||||
//
|
||||
// For example, the value wuffs_base__pixel_format 0x20000565 means BGR with no
|
||||
// For example, the value wuffs_base__pixel_format 0x40000565 means BGR with no
|
||||
// alpha or padding, 5/6/5 bits for blue/green/red, packed 2 bytes per pixel,
|
||||
// laid out LSB-first in memory order:
|
||||
//
|
||||
@@ -1334,12 +1335,12 @@ typedef uint32_t wuffs_base__color_u32argb;
|
||||
// G₂G₁G₀B₄B₃B₂B₁B₀ R₄R₃R₂R₁R₀G₅G₄G₃
|
||||
//
|
||||
// On little-endian systems (but not big-endian), this Wuffs pixel format value
|
||||
// (0x20000565) corresponds to the Cairo library's CAIRO_FORMAT_RGB16_565, the
|
||||
// (0x40000565) corresponds to the Cairo library's CAIRO_FORMAT_RGB16_565, the
|
||||
// SDL2 (Simple DirectMedia Layer 2) library's SDL_PIXELFORMAT_RGB565 and the
|
||||
// Skia library's kRGB_565_SkColorType. Note BGR in Wuffs versus RGB in the
|
||||
// other libraries.
|
||||
//
|
||||
// Regardless of endianness, this Wuffs pixel format value (0x20000565)
|
||||
// Regardless of endianness, this Wuffs pixel format value (0x40000565)
|
||||
// corresponds to the V4L2 (Video For Linux 2) library's V4L2_PIX_FMT_RGB565
|
||||
// and the Wayland-DRM library's WL_DRM_FORMAT_RGB565.
|
||||
//
|
||||
@@ -1367,30 +1368,35 @@ typedef uint32_t wuffs_base__pixel_format;
|
||||
#define WUFFS_BASE__PIXEL_FORMAT__YA_PREMUL \
|
||||
((wuffs_base__pixel_format)0x13000008)
|
||||
|
||||
#define WUFFS_BASE__PIXEL_FORMAT__YCBCR ((wuffs_base__pixel_format)0x20020888)
|
||||
#define WUFFS_BASE__PIXEL_FORMAT__YCBCRK ((wuffs_base__pixel_format)0x21038888)
|
||||
#define WUFFS_BASE__PIXEL_FORMAT__YCBCRA_NONPREMUL \
|
||||
((wuffs_base__pixel_format)0x22038888)
|
||||
|
||||
#define WUFFS_BASE__PIXEL_FORMAT__YCOCG ((wuffs_base__pixel_format)0x30020888)
|
||||
#define WUFFS_BASE__PIXEL_FORMAT__YCOCGK ((wuffs_base__pixel_format)0x31038888)
|
||||
#define WUFFS_BASE__PIXEL_FORMAT__YCOCGA_NONPREMUL \
|
||||
((wuffs_base__pixel_format)0x32038888)
|
||||
|
||||
#define WUFFS_BASE__PIXEL_FORMAT__INDEXED__BGRA_NONPREMUL \
|
||||
((wuffs_base__pixel_format)0x22040008)
|
||||
((wuffs_base__pixel_format)0x42040008)
|
||||
|
||||
#define WUFFS_BASE__PIXEL_FORMAT__BGR ((wuffs_base__pixel_format)0x20000888)
|
||||
#define WUFFS_BASE__PIXEL_FORMAT__BGRX ((wuffs_base__pixel_format)0x21008888)
|
||||
#define WUFFS_BASE__PIXEL_FORMAT__BGR ((wuffs_base__pixel_format)0x40000888)
|
||||
#define WUFFS_BASE__PIXEL_FORMAT__BGRX ((wuffs_base__pixel_format)0x41008888)
|
||||
#define WUFFS_BASE__PIXEL_FORMAT__BGRA_NONPREMUL \
|
||||
((wuffs_base__pixel_format)0x22008888)
|
||||
((wuffs_base__pixel_format)0x42008888)
|
||||
#define WUFFS_BASE__PIXEL_FORMAT__BGRA_PREMUL \
|
||||
((wuffs_base__pixel_format)0x23008888)
|
||||
((wuffs_base__pixel_format)0x43008888)
|
||||
|
||||
#define WUFFS_BASE__PIXEL_FORMAT__RGB ((wuffs_base__pixel_format)0x30000888)
|
||||
#define WUFFS_BASE__PIXEL_FORMAT__RGBX ((wuffs_base__pixel_format)0x31008888)
|
||||
#define WUFFS_BASE__PIXEL_FORMAT__RGB ((wuffs_base__pixel_format)0x50000888)
|
||||
#define WUFFS_BASE__PIXEL_FORMAT__RGBX ((wuffs_base__pixel_format)0x51008888)
|
||||
#define WUFFS_BASE__PIXEL_FORMAT__RGBA_NONPREMUL \
|
||||
((wuffs_base__pixel_format)0x32008888)
|
||||
((wuffs_base__pixel_format)0x52008888)
|
||||
#define WUFFS_BASE__PIXEL_FORMAT__RGBA_PREMUL \
|
||||
((wuffs_base__pixel_format)0x33008888)
|
||||
((wuffs_base__pixel_format)0x53008888)
|
||||
|
||||
#define WUFFS_BASE__PIXEL_FORMAT__YUV ((wuffs_base__pixel_format)0x40020888)
|
||||
#define WUFFS_BASE__PIXEL_FORMAT__YUVK ((wuffs_base__pixel_format)0x41038888)
|
||||
#define WUFFS_BASE__PIXEL_FORMAT__YUVA_NONPREMUL \
|
||||
((wuffs_base__pixel_format)0x42038888)
|
||||
|
||||
#define WUFFS_BASE__PIXEL_FORMAT__CMY ((wuffs_base__pixel_format)0x50020888)
|
||||
#define WUFFS_BASE__PIXEL_FORMAT__CMYK ((wuffs_base__pixel_format)0x51038888)
|
||||
#define WUFFS_BASE__PIXEL_FORMAT__CMY ((wuffs_base__pixel_format)0x60020888)
|
||||
#define WUFFS_BASE__PIXEL_FORMAT__CMYK ((wuffs_base__pixel_format)0x61038888)
|
||||
|
||||
static inline bool //
|
||||
wuffs_base__pixel_format__is_valid(wuffs_base__pixel_format f) {
|
||||
@@ -1421,9 +1427,9 @@ wuffs_base__pixel_format__num_planes(wuffs_base__pixel_format f) {
|
||||
//
|
||||
// For packed pixel formats, the mapping is trivial: i = x and j = y. For
|
||||
// planar pixel formats, the mapping can differ due to chroma subsampling. For
|
||||
// example, consider a three plane YUV pixel format with 4:2:2 subsampling. For
|
||||
// the luma (Y) channel, there is one sample for every pixel, but for the
|
||||
// chroma (U, V) channels, there is one sample for every two pixels: pairs of
|
||||
// example, consider a three plane YCbCr pixel format with 4:2:2 subsampling.
|
||||
// For the luma (Y) channel, there is one sample for every pixel, but for the
|
||||
// chroma (Cb, Cr) channels, there is one sample for every two pixels: pairs of
|
||||
// horizontally adjacent pixels form one macropixel, i = x / 2 and j == y. In
|
||||
// general, for a given p:
|
||||
// - i = (x + bias_x) >> shift_x.
|
||||
@@ -7352,7 +7358,7 @@ wuffs_gif__decoder__decode_image_config(wuffs_gif__decoder* self,
|
||||
(self->private_impl.f_frame_rect_y1 == self->private_impl.f_height));
|
||||
if (a_dst != NULL) {
|
||||
wuffs_base__image_config__initialize(
|
||||
a_dst, 570687496, 0, self->private_impl.f_width,
|
||||
a_dst, 1107558408, 0, self->private_impl.f_width,
|
||||
self->private_impl.f_height, ((uint64_t)(self->private_impl.f_width)),
|
||||
((uint64_t)(self->private_impl.f_width)),
|
||||
self->private_impl.f_frame_config_io_position, v_ffio);
|
||||
|
||||
@@ -139,7 +139,7 @@ pub func decoder.decode_image_config!??(dst nptr base.image_config, src base.io_
|
||||
// TODO: a Wuffs (not just C) name for the
|
||||
// WUFFS_BASE__PIXEL_FORMAT__INDEXED__BGRA_NONPREMUL magic pixfmt constant.
|
||||
args.dst.initialize!(
|
||||
pixfmt:0x22040008,
|
||||
pixfmt:0x42040008,
|
||||
pixsub:0,
|
||||
width:this.width,
|
||||
height:this.height,
|
||||
|
||||
Reference in new issue
Block a user