mirror of
https://github.com/ddidderr/wuffs.git
synced 2026-11-22 00:47:28 +01:00
base: add pixel_format.coloration
This commit is contained in:
1 parent
85af5a4bed
commit
affff51fbf
4 files changed
+62
-29
No files matched your search
@@ -26,7 +26,8 @@ no alpha) and floating point samples should mean a bit depth of 16, 32 or 64.
|
|||||||
|
|
||||||
Formats hold between 1 and 4 channels. For example: Y (1 channel: gray), YA (2
|
Formats hold between 1 and 4 channels. For example: Y (1 channel: gray), YA (2
|
||||||
channels: gray and alpha), BGR (3 channels: blue, green, red) or CMYK (4
|
channels: gray and alpha), BGR (3 channels: blue, green, red) or CMYK (4
|
||||||
channels: cyan, magenta, yellow, black).
|
channels: cyan, magenta, yellow, black). BGRX holds 4 channels even though the
|
||||||
|
X-padding channel's values are ignored.
|
||||||
|
|
||||||
For direct formats with N > 1 channels, those channels can be laid out in
|
For direct formats with N > 1 channels, those channels can be laid out in
|
||||||
either 1 (interleaved) or N (planar) planes. For example, RGBA data is usually
|
either 1 (interleaved) or N (planar) planes. For example, RGBA data is usually
|
||||||
|
|||||||
@@ -321,6 +321,20 @@ typedef uint32_t wuffs_base__pixel_alpha_transparency;
|
|||||||
|
|
||||||
// --------
|
// --------
|
||||||
|
|
||||||
|
// wuffs_base__pixel_coloration is whether a pixel format's color model has no
|
||||||
|
// color (alpha only), gray color or rich (non-gray) color. Rich color includes
|
||||||
|
// RGB, BGR, YCC, YCCK, CMY and CMYK.
|
||||||
|
//
|
||||||
|
// Coloration does not capture the alpha aspect of the color model. It does not
|
||||||
|
// distinguish RGB from RGBA.
|
||||||
|
typedef uint32_t wuffs_base__pixel_coloration;
|
||||||
|
|
||||||
|
#define WUFFS_BASE__PIXEL_COLORATION__NONE 0
|
||||||
|
#define WUFFS_BASE__PIXEL_COLORATION__GRAY 1
|
||||||
|
#define WUFFS_BASE__PIXEL_COLORATION__RICH 3
|
||||||
|
|
||||||
|
// --------
|
||||||
|
|
||||||
// Deprecated: use WUFFS_BASE__PIXEL_FORMAT__NUM_PLANES_MAX_INCL.
|
// Deprecated: use WUFFS_BASE__PIXEL_FORMAT__NUM_PLANES_MAX_INCL.
|
||||||
#define WUFFS_BASE__PIXEL_FORMAT__NUM_PLANES_MAX 4
|
#define WUFFS_BASE__PIXEL_FORMAT__NUM_PLANES_MAX 4
|
||||||
|
|
||||||
@@ -349,6 +363,7 @@ typedef struct wuffs_base__pixel_format__struct {
|
|||||||
inline bool is_indexed() const;
|
inline bool is_indexed() const;
|
||||||
inline bool is_interleaved() const;
|
inline bool is_interleaved() const;
|
||||||
inline bool is_planar() const;
|
inline bool is_planar() const;
|
||||||
|
inline uint32_t coloration() const;
|
||||||
inline uint32_t num_planes() const;
|
inline uint32_t num_planes() const;
|
||||||
inline wuffs_base__pixel_alpha_transparency transparency() const;
|
inline wuffs_base__pixel_alpha_transparency transparency() const;
|
||||||
#endif // __cplusplus
|
#endif // __cplusplus
|
||||||
@@ -455,6 +470,12 @@ wuffs_base__pixel_format__is_planar(const wuffs_base__pixel_format* f) {
|
|||||||
return ((f->repr >> 16) & 0x03) != 0;
|
return ((f->repr >> 16) & 0x03) != 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static inline uint32_t //
|
||||||
|
wuffs_base__pixel_format__coloration(const wuffs_base__pixel_format* f) {
|
||||||
|
uint32_t n = (f->repr) >> 29;
|
||||||
|
return (n <= 1) ? n : 3;
|
||||||
|
}
|
||||||
|
|
||||||
static inline uint32_t //
|
static inline uint32_t //
|
||||||
wuffs_base__pixel_format__num_planes(const wuffs_base__pixel_format* f) {
|
wuffs_base__pixel_format__num_planes(const wuffs_base__pixel_format* f) {
|
||||||
return ((f->repr >> 16) & 0x03) + 1;
|
return ((f->repr >> 16) & 0x03) + 1;
|
||||||
@@ -497,6 +518,11 @@ wuffs_base__pixel_format::is_planar() const {
|
|||||||
return wuffs_base__pixel_format__is_planar(this);
|
return wuffs_base__pixel_format__is_planar(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
inline uint32_t //
|
||||||
|
wuffs_base__pixel_format::coloration() const {
|
||||||
|
return wuffs_base__pixel_format__coloration(this);
|
||||||
|
}
|
||||||
|
|
||||||
inline uint32_t //
|
inline uint32_t //
|
||||||
wuffs_base__pixel_format::num_planes() const {
|
wuffs_base__pixel_format::num_planes() const {
|
||||||
return wuffs_base__pixel_format__num_planes(this);
|
return wuffs_base__pixel_format__num_planes(this);
|
||||||
|
|||||||
@@ -306,20 +306,10 @@ wuffs_drop_in__stb__load0( //
|
|||||||
if (channels_in_file) {
|
if (channels_in_file) {
|
||||||
wuffs_base__pixel_format src_pixfmt =
|
wuffs_base__pixel_format src_pixfmt =
|
||||||
wuffs_base__pixel_config__pixel_format(&ic.pixcfg);
|
wuffs_base__pixel_config__pixel_format(&ic.pixcfg);
|
||||||
switch (src_pixfmt.repr) {
|
uint32_t n_color = wuffs_base__pixel_format__coloration(&src_pixfmt);
|
||||||
case WUFFS_BASE__PIXEL_FORMAT__Y:
|
uint32_t n_alpha = wuffs_base__pixel_format__transparency(&src_pixfmt) !=
|
||||||
case WUFFS_BASE__PIXEL_FORMAT__Y_16LE:
|
WUFFS_BASE__PIXEL_ALPHA_TRANSPARENCY__OPAQUE;
|
||||||
case WUFFS_BASE__PIXEL_FORMAT__Y_16BE:
|
*channels_in_file = (int)(n_color + n_alpha);
|
||||||
*channels_in_file = 1;
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
*channels_in_file =
|
|
||||||
(wuffs_base__pixel_format__transparency(&src_pixfmt) ==
|
|
||||||
WUFFS_BASE__PIXEL_ALPHA_TRANSPARENCY__OPAQUE)
|
|
||||||
? 3
|
|
||||||
: 4;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
|
|||||||
@@ -4360,6 +4360,20 @@ typedef uint32_t wuffs_base__pixel_alpha_transparency;
|
|||||||
|
|
||||||
// --------
|
// --------
|
||||||
|
|
||||||
|
// wuffs_base__pixel_coloration is whether a pixel format's color model has no
|
||||||
|
// color (alpha only), gray color or rich (non-gray) color. Rich color includes
|
||||||
|
// RGB, BGR, YCC, YCCK, CMY and CMYK.
|
||||||
|
//
|
||||||
|
// Coloration does not capture the alpha aspect of the color model. It does not
|
||||||
|
// distinguish RGB from RGBA.
|
||||||
|
typedef uint32_t wuffs_base__pixel_coloration;
|
||||||
|
|
||||||
|
#define WUFFS_BASE__PIXEL_COLORATION__NONE 0
|
||||||
|
#define WUFFS_BASE__PIXEL_COLORATION__GRAY 1
|
||||||
|
#define WUFFS_BASE__PIXEL_COLORATION__RICH 3
|
||||||
|
|
||||||
|
// --------
|
||||||
|
|
||||||
// Deprecated: use WUFFS_BASE__PIXEL_FORMAT__NUM_PLANES_MAX_INCL.
|
// Deprecated: use WUFFS_BASE__PIXEL_FORMAT__NUM_PLANES_MAX_INCL.
|
||||||
#define WUFFS_BASE__PIXEL_FORMAT__NUM_PLANES_MAX 4
|
#define WUFFS_BASE__PIXEL_FORMAT__NUM_PLANES_MAX 4
|
||||||
|
|
||||||
@@ -4388,6 +4402,7 @@ typedef struct wuffs_base__pixel_format__struct {
|
|||||||
inline bool is_indexed() const;
|
inline bool is_indexed() const;
|
||||||
inline bool is_interleaved() const;
|
inline bool is_interleaved() const;
|
||||||
inline bool is_planar() const;
|
inline bool is_planar() const;
|
||||||
|
inline uint32_t coloration() const;
|
||||||
inline uint32_t num_planes() const;
|
inline uint32_t num_planes() const;
|
||||||
inline wuffs_base__pixel_alpha_transparency transparency() const;
|
inline wuffs_base__pixel_alpha_transparency transparency() const;
|
||||||
#endif // __cplusplus
|
#endif // __cplusplus
|
||||||
@@ -4494,6 +4509,12 @@ wuffs_base__pixel_format__is_planar(const wuffs_base__pixel_format* f) {
|
|||||||
return ((f->repr >> 16) & 0x03) != 0;
|
return ((f->repr >> 16) & 0x03) != 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static inline uint32_t //
|
||||||
|
wuffs_base__pixel_format__coloration(const wuffs_base__pixel_format* f) {
|
||||||
|
uint32_t n = (f->repr) >> 29;
|
||||||
|
return (n <= 1) ? n : 3;
|
||||||
|
}
|
||||||
|
|
||||||
static inline uint32_t //
|
static inline uint32_t //
|
||||||
wuffs_base__pixel_format__num_planes(const wuffs_base__pixel_format* f) {
|
wuffs_base__pixel_format__num_planes(const wuffs_base__pixel_format* f) {
|
||||||
return ((f->repr >> 16) & 0x03) + 1;
|
return ((f->repr >> 16) & 0x03) + 1;
|
||||||
@@ -4536,6 +4557,11 @@ wuffs_base__pixel_format::is_planar() const {
|
|||||||
return wuffs_base__pixel_format__is_planar(this);
|
return wuffs_base__pixel_format__is_planar(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
inline uint32_t //
|
||||||
|
wuffs_base__pixel_format::coloration() const {
|
||||||
|
return wuffs_base__pixel_format__coloration(this);
|
||||||
|
}
|
||||||
|
|
||||||
inline uint32_t //
|
inline uint32_t //
|
||||||
wuffs_base__pixel_format::num_planes() const {
|
wuffs_base__pixel_format::num_planes() const {
|
||||||
return wuffs_base__pixel_format__num_planes(this);
|
return wuffs_base__pixel_format__num_planes(this);
|
||||||
@@ -85704,20 +85730,10 @@ wuffs_drop_in__stb__load0( //
|
|||||||
if (channels_in_file) {
|
if (channels_in_file) {
|
||||||
wuffs_base__pixel_format src_pixfmt =
|
wuffs_base__pixel_format src_pixfmt =
|
||||||
wuffs_base__pixel_config__pixel_format(&ic.pixcfg);
|
wuffs_base__pixel_config__pixel_format(&ic.pixcfg);
|
||||||
switch (src_pixfmt.repr) {
|
uint32_t n_color = wuffs_base__pixel_format__coloration(&src_pixfmt);
|
||||||
case WUFFS_BASE__PIXEL_FORMAT__Y:
|
uint32_t n_alpha = wuffs_base__pixel_format__transparency(&src_pixfmt) !=
|
||||||
case WUFFS_BASE__PIXEL_FORMAT__Y_16LE:
|
WUFFS_BASE__PIXEL_ALPHA_TRANSPARENCY__OPAQUE;
|
||||||
case WUFFS_BASE__PIXEL_FORMAT__Y_16BE:
|
*channels_in_file = (int)(n_color + n_alpha);
|
||||||
*channels_in_file = 1;
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
*channels_in_file =
|
|
||||||
(wuffs_base__pixel_format__transparency(&src_pixfmt) ==
|
|
||||||
WUFFS_BASE__PIXEL_ALPHA_TRANSPARENCY__OPAQUE)
|
|
||||||
? 3
|
|
||||||
: 4;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
|
|||||||
Reference in new issue
Block a user