[babl] cairo: add more little endian conversions
- From: Øyvind "pippin" Kolås <ok src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [babl] cairo: add more little endian conversions
- Date: Mon, 19 Aug 2019 15:40:26 +0000 (UTC)
commit cf41e05835ca0bb5291ae5bf3e816595647baa23
Author: Øyvind Kolås <pippin gimp org>
Date: Mon Aug 19 17:40:17 2019 +0200
cairo: add more little endian conversions
extensions/cairo.c | 79 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 79 insertions(+)
---
diff --git a/extensions/cairo.c b/extensions/cairo.c
index 53e8329a0..07a25ff1c 100644
--- a/extensions/cairo.c
+++ b/extensions/cairo.c
@@ -204,6 +204,76 @@ conv_cairo32_rgbAF_le (const Babl *conversion,
}
}
+
+static void
+conv_cairo32_rgbaF_le (const Babl *conversion,
+ unsigned char *src,
+ unsigned char *dst_char,
+ long samples)
+{
+ long n = samples;
+ float *dst = (void*)dst_char;
+ while (n--)
+ {
+ unsigned char blue = *src++;
+ unsigned char green = *src++;
+ unsigned char red = *src++;
+ unsigned char alpha = *src++;
+
+ float reciprocal_alpha = 0.0f;
+
+ if (alpha)
+ reciprocal_alpha = 1.0f/(alpha/255.0f) / 255.0f;
+
+
+ *dst++ = red * reciprocal_alpha;
+ *dst++ = green * reciprocal_alpha;
+ *dst++ = blue * reciprocal_alpha;
+ *dst++ = alpha / 255.0;
+ }
+}
+
+
+static void
+conv_cairo24_rgbF_le (const Babl *conversion,
+ unsigned char *src,
+ unsigned char *dst_char,
+ long samples)
+{
+ long n = samples;
+ float *dst = (void*)dst_char;
+ while (n--)
+ {
+ unsigned char blue = *src++;
+ unsigned char green = *src++;
+ unsigned char red = *src++;
+
+ *dst++ = red / 255.0;
+ *dst++ = green / 255.0;
+ *dst++ = blue / 255.0;
+ src++;
+ }
+}
+
+static void
+conv_cairo24_cairo32_le (const Babl *conversion,
+ unsigned char *src,
+ unsigned char *dst,
+ long samples)
+{
+ long n = samples;
+ while (n--)
+ {
+ unsigned char alpha = src[3];
+
+ *dst++ = (*src++);
+ *dst++ = (*src++);
+ *dst++ = (*src++);
+ *dst++ = 255; src++;
+ }
+}
+
+
static void
conv_rgba8_cairo32_le (const Babl *conversion,
unsigned char *src,
@@ -503,12 +573,21 @@ init (void)
babl_conversion_new (f32, babl_format ("R'aG'aB'aA float"), "linear",
conv_cairo32_rgbAF_le, NULL);
+ babl_conversion_new (f32, babl_format ("R'G'B'A float"), "linear",
+ conv_cairo32_rgbaF_le, NULL);
+
babl_conversion_new (f32, babl_format ("R'aG'aB'aA u8"), "linear",
conv_cairo32_rgbA8_le, NULL);
babl_conversion_new (f32, babl_format ("R'G'B'A u8"), "linear",
conv_cairo32_rgba8_le, NULL);
+ babl_conversion_new (f24, f32, "linear",
+ conv_cairo24_cairo32_le, NULL);
+
+ babl_conversion_new (f24, babl_format ("R'G'B' float"), "linear",
+ conv_cairo24_rgbF_le, NULL);
+
babl_conversion_new (babl_format ("R'aG'aB'aA u8"), f32, "linear",
conv_rgbA8_cairo32_le, NULL);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]