summaryrefslogtreecommitdiff
path: root/source/fitz/colorspace.c
diff options
context:
space:
mode:
authorRobin Watts <Robin.Watts@artifex.com>2016-09-28 22:25:16 -0400
committerRobin Watts <robin.watts@artifex.com>2016-10-06 11:54:10 +0100
commit80d6490e6d54f822de6d36219ce08e6a8ad33137 (patch)
treeb3b5bf787b1454e82275be0b452c4edc8ce432de /source/fitz/colorspace.c
parent994770e2010e21cd8f90bacc34b9fae8a6350a40 (diff)
downloadmupdf-80d6490e6d54f822de6d36219ce08e6a8ad33137.tar.xz
Hide internals of fz_colorspace
The implementation does not need to be in the public API.
Diffstat (limited to 'source/fitz/colorspace.c')
-rw-r--r--source/fitz/colorspace.c59
1 files changed, 36 insertions, 23 deletions
diff --git a/source/fitz/colorspace.c b/source/fitz/colorspace.c
index 90539860..0e8ca594 100644
--- a/source/fitz/colorspace.c
+++ b/source/fitz/colorspace.c
@@ -1,5 +1,7 @@
#include "mupdf/fitz.h"
+#include "colorspace-impl.h"
+
#define SLOWCMYK
void
@@ -13,17 +15,17 @@ fz_drop_colorspace_imp(fz_context *ctx, fz_storable *cs_)
}
fz_colorspace *
-fz_new_colorspace(fz_context *ctx, char *name, int n)
+fz_new_colorspace(fz_context *ctx, char *name, int n, fz_colorspace_convert_fn *to_rgb, fz_colorspace_convert_fn *from_rgb, fz_colorspace_destruct_fn *destruct, void *data, size_t size)
{
fz_colorspace *cs = fz_malloc_struct(ctx, fz_colorspace);
FZ_INIT_STORABLE(cs, 1, fz_drop_colorspace_imp);
- cs->size = sizeof(fz_colorspace);
+ cs->size = sizeof(fz_colorspace) + size;
fz_strlcpy(cs->name, name, sizeof cs->name);
cs->n = n;
- cs->to_rgb = NULL;
- cs->from_rgb = NULL;
- cs->free_data = NULL;
- cs->data = NULL;
+ cs->to_rgb = to_rgb;
+ cs->from_rgb = from_rgb;
+ cs->free_data = destruct;
+ cs->data = data;
return cs;
}
@@ -207,6 +209,12 @@ rgb_to_lab(fz_context *ctx, fz_colorspace *cs, const float *rgb, float *lab)
lab[2] = rgb[2];
}
+int
+fz_colorspace_is_lab(fz_context *ctx, fz_colorspace *cs)
+{
+ return (cs && cs->to_rgb == lab_to_rgb);
+}
+
static fz_colorspace k_default_gray = { {-1, fz_drop_colorspace_imp}, 0, "DeviceGray", 1, gray_to_rgb, rgb_to_gray };
static fz_colorspace k_default_rgb = { {-1, fz_drop_colorspace_imp}, 0, "DeviceRGB", 3, rgb_to_rgb, rgb_to_rgb };
static fz_colorspace k_default_bgr = { {-1, fz_drop_colorspace_imp}, 0, "DeviceBGR", 3, bgr_to_rgb, rgb_to_bgr };
@@ -327,18 +335,6 @@ fz_set_device_lab(fz_context *ctx, fz_colorspace *cs)
fz_unlock(ctx, FZ_LOCK_ALLOC);
}
-int
-fz_colorspace_is_indexed(fz_context *ctx, fz_colorspace *cs)
-{
- return (cs && !strcmp(cs->name, "Indexed"));
-}
-
-int
-fz_colorspace_is_lab(fz_context *ctx, fz_colorspace *cs)
-{
- return (cs && !strcmp(cs->name, "Lab"));
-}
-
/* Fast pixmap color conversions */
static void fast_gray_to_rgb(fz_pixmap *dst, fz_pixmap *src)
@@ -2003,6 +1999,12 @@ free_indexed(fz_context *ctx, fz_colorspace *cs)
fz_free(ctx, idx);
}
+int
+fz_colorspace_is_indexed(fz_context *ctx, fz_colorspace *cs)
+{
+ return (cs && cs->to_rgb == indexed_to_rgb);
+}
+
fz_colorspace *
fz_new_indexed_colorspace(fz_context *ctx, fz_colorspace *base, int high, unsigned char *lookup)
{
@@ -2016,11 +2018,7 @@ fz_new_indexed_colorspace(fz_context *ctx, fz_colorspace *base, int high, unsign
fz_try(ctx)
{
- cs = fz_new_colorspace(ctx, "Indexed", 1);
- cs->to_rgb = indexed_to_rgb;
- cs->free_data = free_indexed;
- cs->data = idx;
- cs->size += sizeof(*idx) + (base->n * (idx->high + 1)) + base->size;
+ cs = fz_new_colorspace(ctx, "Indexed", 1, indexed_to_rgb, NULL, free_indexed, idx, sizeof(*idx) + (base->n * (idx->high + 1)) + base->size);
}
fz_catch(ctx)
{
@@ -2172,3 +2170,18 @@ void fz_fin_cached_color_converter(fz_context *ctx, fz_color_converter *cc_)
fz_drop_hash(ctx, cc->hash);
fz_free(ctx, cc);
}
+
+int fz_colorspace_is(fz_context *ctx, const fz_colorspace *cs, fz_colorspace_convert_fn *to_rgb)
+{
+ return cs && cs->to_rgb == to_rgb;
+}
+
+int fz_colorspace_n(fz_context *ctx, const fz_colorspace *cs)
+{
+ return cs ? cs->n : 0;
+}
+
+const char *fz_colorspace_name(fz_context *ctx, const fz_colorspace *cs)
+{
+ return cs ? cs->name : "";
+}