+extern struct color color_black, color_white;
+
+/* Conversion between various pixel formats */
+
+enum {
+ IMAGE_CONV_FILL_ALPHA = 1,
+ IMAGE_CONV_COPY_ALPHA = 2,
+ IMAGE_CONV_APPLY_ALPHA = 4,
+};
+
+struct image_conv_options {
+ uns flags;
+ struct color background;
+};
+
+extern struct image_conv_options image_conv_defaults;
+
+int image_conv(struct image_context *ctx, struct image *dest, struct image *src, struct image_conv_options *opt);
+
+/* Color spaces in the CIE 1931 chromacity diagram */
+
+struct color_space_chromacity_info {
+ double prim1[2];
+ double prim2[2];
+ double prim3[2];
+ double white[2];
+};
+
+struct color_space_gamma_info {
+ double simple_gamma;
+ double detailed_gamma;
+ double offset;
+ double transition;
+ double slope;
+};
+
+struct color_space_info {
+ byte *name;
+ struct color_space_chromacity_info chromacity;
+ struct color_space_gamma_info gamma;
+};
+
+extern const double
+ color_illuminant_d50[2],
+ color_illuminant_d65[2],
+ color_illuminant_e[2];
+
+extern const struct color_space_info
+ color_adobe_rgb_info, /* Adobe RGB (1998) */
+ color_apple_rgb_info, /* Apple RGB */
+ color_cie_rgb_info, /* CIE RGB */
+ color_color_match_rgb_info, /* ColorMatch RGB */
+ color_srgb_info; /* sRGB */
+
+/* These routines do not check numeric errors! */
+void color_compute_color_space_to_xyz_matrix(double matrix[9], const struct color_space_chromacity_info *space);
+void color_compute_bradford_matrix(double matrix[9], const double src[2], const double dest[2]);
+void color_compute_color_spaces_conversion_matrix(double matrix[9], const struct color_space_chromacity_info *src, const struct color_space_chromacity_info *dest);
+void color_invert_matrix(double dest[9], double matrix[9]);
+
+static inline uns
+rgb_to_gray_func(uns r, uns g, uns b)
+{
+ return (r * 19660 + g * 38666 + b * 7210) >> 16;
+}