summaryrefslogtreecommitdiff
path: root/source/fitz
diff options
context:
space:
mode:
Diffstat (limited to 'source/fitz')
-rw-r--r--source/fitz/colorspace.c136
1 files changed, 70 insertions, 66 deletions
diff --git a/source/fitz/colorspace.c b/source/fitz/colorspace.c
index 828054c0..2a356020 100644
--- a/source/fitz/colorspace.c
+++ b/source/fitz/colorspace.c
@@ -340,7 +340,7 @@ fz_set_device_lab(fz_context *ctx, fz_colorspace *cs)
/* Fast pixmap color conversions */
-static void fast_gray_to_rgb(fz_pixmap *dst, fz_pixmap *src)
+static void fast_gray_to_rgb(fz_context *ctx, fz_pixmap *dst, fz_pixmap *src)
{
unsigned char *s = src->samples;
unsigned char *d = dst->samples;
@@ -418,7 +418,7 @@ static void fast_gray_to_rgb(fz_pixmap *dst, fz_pixmap *src)
}
}
-static void fast_gray_to_cmyk(fz_pixmap *dst, fz_pixmap *src)
+static void fast_gray_to_cmyk(fz_context *ctx, fz_pixmap *dst, fz_pixmap *src)
{
unsigned char *s = src->samples;
unsigned char *d = dst->samples;
@@ -499,7 +499,7 @@ static void fast_gray_to_cmyk(fz_pixmap *dst, fz_pixmap *src)
}
}
-static void fast_rgb_to_gray(fz_pixmap *dst, fz_pixmap *src)
+static void fast_rgb_to_gray(fz_context *ctx, fz_pixmap *dst, fz_pixmap *src)
{
unsigned char *s = src->samples;
unsigned char *d = dst->samples;
@@ -571,7 +571,7 @@ static void fast_rgb_to_gray(fz_pixmap *dst, fz_pixmap *src)
}
}
-static void fast_bgr_to_gray(fz_pixmap *dst, fz_pixmap *src)
+static void fast_bgr_to_gray(fz_context *ctx, fz_pixmap *dst, fz_pixmap *src)
{
unsigned char *s = src->samples;
unsigned char *d = dst->samples;
@@ -643,7 +643,7 @@ static void fast_bgr_to_gray(fz_pixmap *dst, fz_pixmap *src)
}
}
-static void fast_rgb_to_cmyk(fz_pixmap *dst, fz_pixmap *src)
+static void fast_rgb_to_cmyk(fz_context *ctx, fz_pixmap *dst, fz_pixmap *src)
{
unsigned char *s = src->samples;
unsigned char *d = dst->samples;
@@ -736,7 +736,7 @@ static void fast_rgb_to_cmyk(fz_pixmap *dst, fz_pixmap *src)
}
}
-static void fast_bgr_to_cmyk(fz_pixmap *dst, fz_pixmap *src)
+static void fast_bgr_to_cmyk(fz_context *ctx, fz_pixmap *dst, fz_pixmap *src)
{
unsigned char *s = src->samples;
unsigned char *d = dst->samples;
@@ -829,7 +829,7 @@ static void fast_bgr_to_cmyk(fz_pixmap *dst, fz_pixmap *src)
}
}
-static void fast_cmyk_to_gray(fz_pixmap *dst, fz_pixmap *src)
+static void fast_cmyk_to_gray(fz_context *ctx, fz_pixmap *dst, fz_pixmap *src)
{
unsigned char *s = src->samples;
unsigned char *d = dst->samples;
@@ -1427,7 +1427,7 @@ static void fast_cmyk_to_bgr(fz_context *ctx, fz_pixmap *dst, fz_pixmap *src)
}
}
-static void fast_rgb_to_bgr(fz_pixmap *dst, fz_pixmap *src)
+static void fast_rgb_to_bgr(fz_context *ctx, fz_pixmap *dst, fz_pixmap *src)
{
unsigned char *s = src->samples;
unsigned char *d = dst->samples;
@@ -1689,93 +1689,97 @@ fz_std_conv_pixmap(fz_context *ctx, fz_pixmap *dst, fz_pixmap *src)
}
}
-static void fast_copy_alpha(fz_pixmap *dst, fz_pixmap *src)
+static void fast_any_to_alpha(fz_context *ctx, fz_pixmap *dst, fz_pixmap *src)
{
- unsigned char *s = src->samples;
- unsigned char *d = dst->samples;
- size_t w = src->w;
- int h = src->h;
- int n = src->n;
- ptrdiff_t d_line_inc = dst->stride - w * dst->n;
- ptrdiff_t s_line_inc = src->stride - w * src->n;
+ if (!src->alpha)
+ fz_clear_pixmap_with_value(ctx, dst, 255);
+ else
+ {
+ unsigned char *s = src->samples;
+ unsigned char *d = dst->samples;
+ size_t w = src->w;
+ int h = src->h;
+ int n = src->n;
+ ptrdiff_t d_line_inc = dst->stride - w * dst->n;
+ ptrdiff_t s_line_inc = src->stride - w * src->n;
- if ((int)w < 0 || h < 0)
- return;
+ if ((int)w < 0 || h < 0)
+ return;
- assert(dst->alpha && src->alpha && dst->n == 1);
+ assert(dst->alpha && src->alpha && dst->n == 1);
- if (d_line_inc == 0 && s_line_inc == 0)
- {
- w *= h;
- h = 1;
- }
+ if (d_line_inc == 0 && s_line_inc == 0)
+ {
+ w *= h;
+ h = 1;
+ }
- s += n-1;
- while (h--)
- {
- size_t ww = w;
- while (ww--)
+ s += n-1;
+ while (h--)
{
- *d++ = *s;
- s += n;
+ size_t ww = w;
+ while (ww--)
+ {
+ *d++ = *s;
+ s += n;
+ }
+ d += d_line_inc;
+ s += s_line_inc;
}
- d += d_line_inc;
- s += s_line_inc;
}
}
-void
-fz_convert_pixmap(fz_context *ctx, fz_pixmap *dp, fz_pixmap *sp)
+fz_pixmap_converter *fz_lookup_pixmap_converter(fz_context *ctx, fz_colorspace *ds, fz_colorspace *ss)
{
- fz_colorspace *ss = sp->colorspace;
- fz_colorspace *ds = dp->colorspace;
-
if (ds == NULL)
- {
- if (sp->alpha)
- fast_copy_alpha(dp, sp);
- else
- fz_clear_pixmap_with_value(ctx, dp, 255);
- return;
- }
-
- assert(ss && ds);
-
- dp->interpolate = sp->interpolate;
+ return fast_any_to_alpha;
if (ss == fz_default_gray)
{
- if (ds == fz_default_rgb) fast_gray_to_rgb(dp, sp);
- else if (ds == fz_default_bgr) fast_gray_to_rgb(dp, sp); /* bgr == rgb here */
- else if (ds == fz_default_cmyk) fast_gray_to_cmyk(dp, sp);
- else fz_std_conv_pixmap(ctx, dp, sp);
+ if (ds == fz_default_rgb) return fast_gray_to_rgb;
+ else if (ds == fz_default_bgr) return fast_gray_to_rgb; /* bgr == rgb here */
+ else if (ds == fz_default_cmyk) return fast_gray_to_cmyk;
+ else return fz_std_conv_pixmap;
}
else if (ss == fz_default_rgb)
{
- if (ds == fz_default_gray) fast_rgb_to_gray(dp, sp);
- else if (ds == fz_default_bgr) fast_rgb_to_bgr(dp, sp);
- else if (ds == fz_default_cmyk) fast_rgb_to_cmyk(dp, sp);
- else fz_std_conv_pixmap(ctx, dp, sp);
+ if (ds == fz_default_gray) return fast_rgb_to_gray;
+ else if (ds == fz_default_bgr) return fast_rgb_to_bgr;
+ else if (ds == fz_default_cmyk) return fast_rgb_to_cmyk;
+ else return fz_std_conv_pixmap;
}
else if (ss == fz_default_bgr)
{
- if (ds == fz_default_gray) fast_bgr_to_gray(dp, sp);
- else if (ds == fz_default_rgb) fast_rgb_to_bgr(dp, sp); /* bgr = rgb here */
- else if (ds == fz_default_cmyk) fast_bgr_to_cmyk(sp, dp);
- else fz_std_conv_pixmap(ctx, dp, sp);
+ if (ds == fz_default_gray) return fast_bgr_to_gray;
+ else if (ds == fz_default_rgb) return fast_rgb_to_bgr; /* bgr = rgb here */
+ else if (ds == fz_default_cmyk) return fast_bgr_to_cmyk;
+ else return fz_std_conv_pixmap;
}
else if (ss == fz_default_cmyk)
{
- if (ds == fz_default_gray) fast_cmyk_to_gray(dp, sp);
- else if (ds == fz_default_bgr) fast_cmyk_to_bgr(ctx, dp, sp);
- else if (ds == fz_default_rgb) fast_cmyk_to_rgb(ctx, dp, sp);
- else fz_std_conv_pixmap(ctx, dp, sp);
+ if (ds == fz_default_gray) return fast_cmyk_to_gray;
+ else if (ds == fz_default_bgr) return fast_cmyk_to_bgr;
+ else if (ds == fz_default_rgb) return fast_cmyk_to_rgb;
+ else return fz_std_conv_pixmap;
}
- else fz_std_conv_pixmap(ctx, dp, sp);
+ else return fz_std_conv_pixmap;
+}
+
+void
+fz_convert_pixmap(fz_context *ctx, fz_pixmap *dp, fz_pixmap *sp)
+{
+ fz_colorspace *ss = sp->colorspace;
+ fz_colorspace *ds = dp->colorspace;
+ fz_pixmap_converter *converter;
+
+ dp->interpolate = sp->interpolate;
+
+ converter = fz_lookup_pixmap_converter(ctx, ds, ss);
+ converter(ctx, dp, sp);
}
/* Convert a single color */