summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorClaude Heiland-Allen <claude@mathr.co.uk>2021-03-11 13:14:49 +0000
committerSimon Ser <contact@emersion.fr>2022-11-03 12:51:47 +0000
commit83ba0244838217714d387834cf2ea4eef04a3206 (patch)
treec7eb73efaa6ce7014daf22a3ea070c15fc2adb2e
parent37216a32839f59e8dcaa4c3951b3fcfc3f07852c (diff)
downloadpixman-83ba0244838217714d387834cf2ea4eef04a3206.tar.gz
implement r8g8b8 sRGB (without alpha)
Signed-off-by: Claude Heiland-Allen <claude@mathr.co.uk>
-rw-r--r--pixman/pixman-access.c156
-rw-r--r--pixman/pixman.c1
-rw-r--r--pixman/pixman.h1
3 files changed, 158 insertions, 0 deletions
diff --git a/pixman/pixman-access.c b/pixman/pixman-access.c
index 7c5ce78..54b0f31 100644
--- a/pixman/pixman-access.c
+++ b/pixman/pixman-access.c
@@ -610,6 +610,32 @@ fetch_scanline_a8r8g8b8_sRGB_float (bits_image_t * image,
}
}
+static void
+fetch_scanline_r8g8b8_sRGB_float (bits_image_t * image,
+ int x,
+ int y,
+ int width,
+ uint32_t * b,
+ const uint32_t *mask)
+{
+ const uint8_t *bits = (uint8_t *)(image->bits + y * image->rowstride);
+ argb_t *buffer = (argb_t *)b;
+ int i;
+ for (i = x; i < width; ++i)
+ {
+ uint32_t p = FETCH_24 (image, bits, i);
+ argb_t *argb = buffer;
+
+ argb->a = 1.0f;
+
+ argb->r = to_linear[(p >> 16) & 0xff];
+ argb->g = to_linear[(p >> 8) & 0xff];
+ argb->b = to_linear[(p >> 0) & 0xff];
+
+ buffer++;
+ }
+}
+
/* Expects a float buffer */
static void
fetch_scanline_a2r10g10b10_float (bits_image_t * image,
@@ -981,6 +1007,24 @@ fetch_pixel_a8r8g8b8_sRGB_float (bits_image_t *image,
return argb;
}
+static argb_t
+fetch_pixel_r8g8b8_sRGB_float (bits_image_t *image,
+ int offset,
+ int line)
+{
+ uint8_t *bits = (uint8_t *)(image->bits + line * image->rowstride);
+ uint32_t p = FETCH_24 (image, bits, offset);
+ argb_t argb;
+
+ argb.a = 1.0f;
+
+ argb.r = to_linear[(p >> 16) & 0xff];
+ argb.g = to_linear[(p >> 8) & 0xff];
+ argb.b = to_linear[(p >> 0) & 0xff];
+
+ return argb;
+}
+
static uint32_t
fetch_pixel_yuy2 (bits_image_t *image,
int offset,
@@ -1205,6 +1249,31 @@ store_scanline_a8r8g8b8_sRGB_float (bits_image_t * image,
}
}
+static void
+store_scanline_r8g8b8_sRGB_float (bits_image_t * image,
+ int x,
+ int y,
+ int width,
+ const uint32_t *v)
+{
+ uint8_t *bits = (uint8_t *)(image->bits + image->rowstride * y) + 3 * x;
+ argb_t *values = (argb_t *)v;
+ int i;
+
+ for (i = 0; i < width; ++i)
+ {
+ uint32_t r, g, b, rgb;
+
+ r = to_srgb (values[i].r);
+ g = to_srgb (values[i].g);
+ b = to_srgb (values[i].b);
+
+ rgb = (r << 16) | (g << 8) | b;
+
+ STORE_24 (image, bits, i, rgb);
+ }
+}
+
/*
* Contracts a floating point image to 32bpp and then stores it using a
* regular 32-bit store proc. Despite the type, this function expects an
@@ -1283,6 +1352,37 @@ fetch_scanline_a8r8g8b8_32_sRGB (bits_image_t *image,
}
}
+static void
+fetch_scanline_r8g8b8_32_sRGB (bits_image_t *image,
+ int x,
+ int y,
+ int width,
+ uint32_t *buffer,
+ const uint32_t *mask)
+{
+ const uint8_t *bits = (uint8_t *)(image->bits + y * image->rowstride) + 3 * x;
+ uint32_t tmp;
+ int i;
+
+ for (i = 0; i < width; ++i)
+ {
+ uint32_t a, r, g, b;
+
+ tmp = FETCH_24 (image, bits, i);
+
+ a = 0xff;
+ r = (tmp >> 16) & 0xff;
+ g = (tmp >> 8) & 0xff;
+ b = (tmp >> 0) & 0xff;
+
+ r = to_linear[r] * 255.0f + 0.5f;
+ g = to_linear[g] * 255.0f + 0.5f;
+ b = to_linear[b] * 255.0f + 0.5f;
+
+ *buffer++ = (a << 24) | (r << 16) | (g << 8) | (b << 0);
+ }
+}
+
static uint32_t
fetch_pixel_a8r8g8b8_32_sRGB (bits_image_t *image,
int offset,
@@ -1304,6 +1404,27 @@ fetch_pixel_a8r8g8b8_32_sRGB (bits_image_t *image,
return (a << 24) | (r << 16) | (g << 8) | (b << 0);
}
+static uint32_t
+fetch_pixel_r8g8b8_32_sRGB (bits_image_t *image,
+ int offset,
+ int line)
+{
+ uint8_t *bits = (uint8_t *)(image->bits + line * image->rowstride);
+ uint32_t tmp = FETCH_24 (image, bits, offset);
+ uint32_t a, r, g, b;
+
+ a = 0xff;
+ r = (tmp >> 16) & 0xff;
+ g = (tmp >> 8) & 0xff;
+ b = (tmp >> 0) & 0xff;
+
+ r = to_linear[r] * 255.0f + 0.5f;
+ g = to_linear[g] * 255.0f + 0.5f;
+ b = to_linear[b] * 255.0f + 0.5f;
+
+ return (a << 24) | (r << 16) | (g << 8) | (b << 0);
+}
+
static void
store_scanline_a8r8g8b8_32_sRGB (bits_image_t *image,
int x,
@@ -1336,6 +1457,36 @@ store_scanline_a8r8g8b8_32_sRGB (bits_image_t *image,
}
}
+static void
+store_scanline_r8g8b8_32_sRGB (bits_image_t *image,
+ int x,
+ int y,
+ int width,
+ const uint32_t *v)
+{
+ uint8_t *bits = (uint8_t *)(image->bits + image->rowstride * y) + 3 * x;
+ uint64_t *values = (uint64_t *)v;
+ uint64_t tmp;
+ int i;
+
+ for (i = 0; i < width; ++i)
+ {
+ uint32_t r, g, b;
+
+ tmp = values[i];
+
+ r = (tmp >> 16) & 0xff;
+ g = (tmp >> 8) & 0xff;
+ b = (tmp >> 0) & 0xff;
+
+ r = to_srgb (r * (1/255.0f));
+ g = to_srgb (g * (1/255.0f));
+ b = to_srgb (b * (1/255.0f));
+
+ STORE_24 (image, bits, i, (r << 16) | (g << 8) | (b << 0));
+ }
+}
+
static argb_t
fetch_pixel_generic_float (bits_image_t *image,
int offset,
@@ -1409,6 +1560,11 @@ static const format_info_t accessors[] =
fetch_pixel_a8r8g8b8_32_sRGB, fetch_pixel_a8r8g8b8_sRGB_float,
store_scanline_a8r8g8b8_32_sRGB, store_scanline_a8r8g8b8_sRGB_float,
},
+ { PIXMAN_r8g8b8_sRGB,
+ fetch_scanline_r8g8b8_32_sRGB, fetch_scanline_r8g8b8_sRGB_float,
+ fetch_pixel_r8g8b8_32_sRGB, fetch_pixel_r8g8b8_sRGB_float,
+ store_scanline_r8g8b8_32_sRGB, store_scanline_r8g8b8_sRGB_float,
+ },
/* 24bpp formats */
FORMAT_INFO (r8g8b8),
diff --git a/pixman/pixman.c b/pixman/pixman.c
index c09b528..1a3cba0 100644
--- a/pixman/pixman.c
+++ b/pixman/pixman.c
@@ -1020,6 +1020,7 @@ pixman_format_supported_source (pixman_format_code_t format)
case PIXMAN_x2r10g10b10:
case PIXMAN_a8r8g8b8:
case PIXMAN_a8r8g8b8_sRGB:
+ case PIXMAN_r8g8b8_sRGB:
case PIXMAN_x8r8g8b8:
case PIXMAN_a8b8g8r8:
case PIXMAN_x8b8g8r8:
diff --git a/pixman/pixman.h b/pixman/pixman.h
index 0070340..2cd875b 100644
--- a/pixman/pixman.h
+++ b/pixman/pixman.h
@@ -891,6 +891,7 @@ typedef enum {
/* sRGB formats */
PIXMAN_a8r8g8b8_sRGB = PIXMAN_FORMAT(32,PIXMAN_TYPE_ARGB_SRGB,8,8,8,8),
+ PIXMAN_r8g8b8_sRGB = PIXMAN_FORMAT(24,PIXMAN_TYPE_ARGB_SRGB,0,8,8,8),
/* 24bpp formats */
PIXMAN_r8g8b8 = PIXMAN_FORMAT(24,PIXMAN_TYPE_ARGB,0,8,8,8),