This is an automated email from the git hooks/post-receive script.
git pushed a commit to branch master
in repository legacy-imlib2.
View the commit online.
commit 73a7bb7e925b48c977900e40c515f4b854290395
Author: Chema Gonzalez <che...@meta.com>
AuthorDate: Sun May 18 18:40:48 2025 -0700
Y4M loader: add support for 10-bit mono
Tested:
```
$ src/bin/.libs/imlib2_view test/images/img-8x8.mono10.full_range.y4m
$ feh test/images/img-8x8.mono10.full_range.y4m
```
---
src/modules/loaders/loader_y4m.c | 40 ++++++++++++++++++++++++++++--
test/images/img-8x8.mono10.full_range.y4m | Bin 0 -> 195 bytes
2 files changed, 38 insertions(+), 2 deletions(-)
diff --git a/src/modules/loaders/loader_y4m.c b/src/modules/loaders/loader_y4m.c
index 0b7629b..8761c68 100644
--- a/src/modules/loaders/loader_y4m.c
+++ b/src/modules/loaders/loader_y4m.c
@@ -46,6 +46,7 @@ typedef struct {
Y4M_PARSE_CS_422,
Y4M_PARSE_CS_444,
Y4M_PARSE_CS_MONO,
+ Y4M_PARSE_CS_MONO10,
Y4M_PARSE_CS_420P10,
Y4M_PARSE_CS_422P10,
Y4M_PARSE_CS_444P10,
@@ -187,7 +188,12 @@ y4m__parse_params(Y4mParse *res, const uint8_t **start, const uint8_t *end)
break;
case 'C':
res->colour_space = Y4M_PARSE_CS_UNSUPPORTED;
- if (y4m__match("mono", 4, &p, end))
+ if (y4m__match("mono10", 6, &p, end))
+ {
+ res->colour_space = Y4M_PARSE_CS_MONO10;
+ res->depth = 10;
+ }
+ else if (y4m__match("mono", 4, &p, end))
{
res->colour_space = Y4M_PARSE_CS_MONO;
res->depth = 8;
@@ -367,6 +373,10 @@ y4m_parse_frame(Y4mParse *res)
sdiv = 1;
voff = npixels * 2;
break;
+ case Y4M_PARSE_CS_MONO10:
+ res->frame_data_len = npixels * 2;
+ sdiv = voff = 0; // silence bogus compiler warning
+ break;
case Y4M_PARSE_CS_MONO:
res->frame_data_len = npixels;
sdiv = voff = 0; // silence bogus compiler warning
@@ -382,7 +392,8 @@ y4m_parse_frame(Y4mParse *res)
res->y = p;
res->y_stride = res->w;
- if (res->colour_space == Y4M_PARSE_CS_MONO)
+ if (res->colour_space == Y4M_PARSE_CS_MONO ||
+ res->colour_space == Y4M_PARSE_CS_MONO10)
{
res->u = res->v = NULL;
res->u_stride = res->v_stride = 0;
@@ -482,6 +493,7 @@ _load(ImlibImage *im, int load_data)
switch (y4m.colour_space)
{
case Y4M_PARSE_CS_MONO:
+ case Y4M_PARSE_CS_MONO10:
conv = conv_mono;
break;
case Y4M_PARSE_CS_422:
@@ -545,6 +557,10 @@ _load(ImlibImage *im, int load_data)
{
buf_size = (y4m.w * y4m.h * 3);
}
+ else if (y4m.colour_space == Y4M_PARSE_CS_MONO10)
+ {
+ buf_size = y4m.w * y4m.h;
+ }
uint8_t *buf = calloc((buf_size), sizeof(uint8_t));
if (!buf)
return LOAD_OOM;
@@ -565,6 +581,10 @@ _load(ImlibImage *im, int load_data)
{
voff = npixels * 2;
}
+ else if (y4m.colour_space == Y4M_PARSE_CS_MONO10)
+ {
+ voff = 0;
+ }
uint8_t *buf_v = buf + voff;
int buf_stride_y = y4m.w;
ptrdiff_t buf_stride_u;
@@ -582,6 +602,10 @@ _load(ImlibImage *im, int load_data)
{
sdiv = 1;
}
+ else if (y4m.colour_space == Y4M_PARSE_CS_MONO10)
+ {
+ sdiv = 1;
+ }
buf_stride_u = buf_stride_v = y4m.w / sdiv;
/* 2. run the color conversion */
@@ -603,6 +627,18 @@ _load(ImlibImage *im, int load_data)
y4m.v, y4m.v_stride, buf_y, buf_stride_y,
buf_u, buf_stride_u, buf_v, buf_stride_v, y4m.w, y4m.h);
}
+ else if (y4m.colour_space == Y4M_PARSE_CS_MONO10)
+ {
+ /* libyuv does not support 10-bit grayscale (Y10-like) color.
+ * Let's downconvert to 8-bit before using the original mono
+ * conversion function. */
+ /* convert the 10-bit plane to an 8-bit plane */
+ for (int i = 0; i < y4m.w * y4m.h; ++i)
+ {
+ /* convert 10-bit to 8-bit */
+ buf_y[i] = (uint8_t) ((*((uint16_t *) (y4m.y) + i)) >> 2);
+ }
+ }
/* 3. convert 8-bit YUV (original subsampling) to 8-bit ARGB */
res = conv(buf_y, buf_stride_y, buf_u, buf_stride_u,
diff --git a/test/images/img-8x8.mono10.full_range.y4m b/test/images/img-8x8.mono10.full_range.y4m
new file mode 100644
index 0000000..31ef93d
Binary files /dev/null and b/test/images/img-8x8.mono10.full_range.y4m differ
--
To stop receiving notification emails like this one, please contact
the administrator of this repository.