summaryrefslogtreecommitdiff
path: root/source/fitz
diff options
context:
space:
mode:
Diffstat (limited to 'source/fitz')
-rw-r--r--source/fitz/colorspace-impl.h16
-rw-r--r--source/fitz/colorspace.c59
-rw-r--r--source/fitz/draw-device.c12
-rw-r--r--source/fitz/draw-mesh.c10
-rw-r--r--source/fitz/image.c2
-rw-r--r--source/fitz/list-device.c28
-rw-r--r--source/fitz/load-jpx.c2
-rw-r--r--source/fitz/load-pnm.c15
-rw-r--r--source/fitz/pixmap.c10
-rw-r--r--source/fitz/shade.c9
-rw-r--r--source/fitz/stext-device.c2
-rw-r--r--source/fitz/trace-device.c7
12 files changed, 105 insertions, 67 deletions
diff --git a/source/fitz/colorspace-impl.h b/source/fitz/colorspace-impl.h
new file mode 100644
index 00000000..1ce2e167
--- /dev/null
+++ b/source/fitz/colorspace-impl.h
@@ -0,0 +1,16 @@
+#ifndef MUPDF_FITZ_COLORSPACE_IMPL_H
+#define MUPDF_FITZ_COLORSPACE_IMPL_H
+
+struct fz_colorspace_s
+{
+ fz_storable storable;
+ size_t size;
+ char name[16];
+ int n;
+ fz_colorspace_convert_fn *to_rgb;
+ fz_colorspace_convert_fn *from_rgb;
+ fz_colorspace_destruct_fn *free_data;
+ void *data;
+};
+
+#endif
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 : "";
+}
diff --git a/source/fitz/draw-device.c b/source/fitz/draw-device.c
index e337c482..e40b61db 100644
--- a/source/fitz/draw-device.c
+++ b/source/fitz/draw-device.c
@@ -439,7 +439,7 @@ fz_draw_fill_path(fz_context *ctx, fz_device *devp, const fz_path *path, int eve
if (state->blendmode & FZ_BLEND_KNOCKOUT)
state = fz_knockout_begin(ctx, dev);
- n = model ? model->n : 0;
+ n = fz_colorspace_n(ctx, model);
if (n > 0)
{
fz_convert_color(ctx, model, colorfv, colorspace, color);
@@ -507,7 +507,7 @@ fz_draw_stroke_path(fz_context *ctx, fz_device *devp, const fz_path *path, const
if (state->blendmode & FZ_BLEND_KNOCKOUT)
state = fz_knockout_begin(ctx, dev);
- n = model ? model->n : 0;
+ n = fz_colorspace_n(ctx, model);
if (n > 0)
{
fz_convert_color(ctx, model, colorfv, colorspace, color);
@@ -789,7 +789,7 @@ fz_draw_fill_text(fz_context *ctx, fz_device *devp, const fz_text *text, const f
if (state->blendmode & FZ_BLEND_KNOCKOUT)
state = fz_knockout_begin(ctx, dev);
- n = model ? model->n : 0;
+ n = fz_colorspace_n(ctx, model);
if (n > 0)
{
fz_convert_color(ctx, model, colorfv, colorspace, color);
@@ -880,7 +880,7 @@ fz_draw_stroke_text(fz_context *ctx, fz_device *devp, const fz_text *text, const
if (state->blendmode & FZ_BLEND_KNOCKOUT)
state = fz_knockout_begin(ctx, dev);
- n = model ? model->n : 0;
+ n = fz_colorspace_n(ctx, model);
if (n > 0)
{
fz_convert_color(ctx, model, colorfv, colorspace, color);
@@ -1238,7 +1238,7 @@ fz_draw_fill_shade(fz_context *ctx, fz_device *devp, fz_shade *shade, const fz_m
{
unsigned char *s;
int x, y, n, i;
- n = model ? model->n : 0;
+ n = fz_colorspace_n(ctx, model);
if (n > 0)
{
fz_convert_color(ctx, model, colorfv, shade->colorspace, shade->background);
@@ -1586,7 +1586,7 @@ fz_draw_fill_image_mask(fz_context *ctx, fz_device *devp, fz_image *image, const
pixmap = scaled;
}
- n = model ? model->n : 0;
+ n = fz_colorspace_n(ctx, model);
if (n > 0)
{
fz_convert_color(ctx, model, colorfv, colorspace, color);
diff --git a/source/fitz/draw-mesh.c b/source/fitz/draw-mesh.c
index d7606f1b..4f90c461 100644
--- a/source/fitz/draw-mesh.c
+++ b/source/fitz/draw-mesh.c
@@ -179,8 +179,9 @@ prepare_mesh_vertex(fz_context *ctx, void *arg, fz_vertex *v, const float *input
output[0] = input[0] * 255;
else
{
+ int n = fz_colorspace_n(ctx, dest->colorspace);
ptd->cc.convert(ctx, &ptd->cc, output, input);
- for (i = 0; i < dest->colorspace->n; i++)
+ for (i = 0; i < n; i++)
output[i] *= 255;
}
}
@@ -197,7 +198,7 @@ do_paint_tri(fz_context *ctx, void *arg, fz_vertex *av, fz_vertex *bv, fz_vertex
vertices[2] = (float *)cv;
dest = ptd->dest;
- fz_paint_triangle(dest, vertices, 2 + dest->colorspace->n, ptd->bbox);
+ fz_paint_triangle(dest, vertices, 2 + fz_colorspace_n(ctx, dest->colorspace), ptd->bbox);
}
void
@@ -221,14 +222,15 @@ fz_paint_shade(fz_context *ctx, fz_shade *shade, const fz_matrix *ctm, fz_pixmap
if (shade->use_function)
{
fz_color_converter cc;
- n = dest->colorspace ? dest->colorspace->n : 0;
+ int cn = fz_colorspace_n(ctx, shade->colorspace);
+ n = fz_colorspace_n(ctx, dest->colorspace);
fz_lookup_color_converter(ctx, &cc, dest->colorspace, shade->colorspace);
for (i = 0; i < 256; i++)
{
cc.convert(ctx, &cc, color, shade->function[i]);
for (k = 0; k < n; k++)
clut[i][k] = color[k] * 255;
- clut[i][k] = shade->function[i][shade->colorspace->n] * 255;
+ clut[i][k] = shade->function[i][cn] * 255;
}
/* We need to use alpha = 1 here, because the shade might not fill
* the bbox. */
diff --git a/source/fitz/image.c b/source/fitz/image.c
index 8d692fbd..77344a16 100644
--- a/source/fitz/image.c
+++ b/source/fitz/image.c
@@ -784,7 +784,7 @@ fz_new_image(fz_context *ctx, int w, int h, int bpc, fz_colorspace *colorspace,
image->xres = xres;
image->yres = yres;
image->bpc = bpc;
- image->n = (colorspace ? colorspace->n : 1);
+ image->n = (colorspace ? fz_colorspace_n(ctx, colorspace) : 1);
image->colorspace = fz_keep_colorspace(ctx, colorspace);
image->invert_cmyk_jpeg = 1;
image->interpolate = interpolate;
diff --git a/source/fitz/list-device.c b/source/fitz/list-device.c
index 3d17ee7d..bcc11230 100644
--- a/source/fitz/list-device.c
+++ b/source/fitz/list-device.c
@@ -302,7 +302,7 @@ fz_append_display_node(
else
{
int i;
- int n = colorspace ? colorspace->n : 0;
+ int n = fz_colorspace_n(ctx, colorspace);
colorspace_off = size;
size += SIZE_IN_NODES(sizeof(fz_colorspace *));
@@ -373,7 +373,7 @@ fz_append_display_node(
else
{
int i;
- int n = colorspace ? colorspace->n : 0;
+ int n = fz_colorspace_n(ctx, colorspace);
for (i=0; i < n; i++)
if (color[i] != 0.0f)
break;
@@ -393,7 +393,7 @@ fz_append_display_node(
const float *wc = &writer->color[0];
assert(colorspace != NULL);
- n = colorspace->n;
+ n = fz_colorspace_n(ctx, colorspace);
i = 0;
/* Only check colors if the colorspace is unchanged. If the
* colorspace *has* changed and the colors are implicit then
@@ -564,7 +564,7 @@ fz_append_display_node(
{
fz_colorspace **out_colorspace = (fz_colorspace **)(void *)(&node_ptr[colorspace_off]);
int i, n;
- n = colorspace ? colorspace->n : 0;
+ n = fz_colorspace_n(ctx, colorspace);
*out_colorspace = fz_keep_colorspace(ctx, colorspace);
writer->colorspace = fz_keep_colorspace(ctx, colorspace);
@@ -576,9 +576,10 @@ fz_append_display_node(
}
if (color_off)
{
+ int n = fz_colorspace_n(ctx, colorspace);
float *out_color = (float *)(void *)(&node_ptr[color_off]);
- memcpy(writer->color, color, colorspace->n * sizeof(float));
- memcpy(out_color, color, colorspace->n * sizeof(float));
+ memcpy(writer->color, color, n * sizeof(float));
+ memcpy(out_color, color, n * sizeof(float));
}
if (node.alpha)
{
@@ -1260,6 +1261,7 @@ fz_drop_display_list_imp(fz_context *ctx, fz_storable *list_)
fz_display_node *node = list->list;
fz_display_node *node_end = list->list + list->len;
int cs_n = 1;
+ fz_colorspace *cs;
if (list == NULL)
return;
@@ -1291,10 +1293,9 @@ fz_drop_display_list_imp(fz_context *ctx, fz_storable *list_)
cs_n = 4;
break;
case CS_OTHER_0:
- cs_n = 0;
- if (*(fz_colorspace **)node)
- cs_n = (*(fz_colorspace **)node)->n;
- fz_drop_colorspace(ctx, *(fz_colorspace **)node);
+ cs = *(fz_colorspace **)node;
+ cs_n = fz_colorspace_n(ctx, cs);
+ fz_drop_colorspace(ctx, cs);
node += SIZE_IN_NODES(sizeof(fz_colorspace *));
break;
}
@@ -1484,7 +1485,7 @@ fz_run_display_list(fz_context *ctx, fz_display_list *list, fz_device *dev, cons
case CS_OTHER_0:
colorspace = fz_keep_colorspace(ctx, *(fz_colorspace **)(node));
node += SIZE_IN_NODES(sizeof(fz_colorspace *));
- en = colorspace ? colorspace->n : 0;
+ en = fz_colorspace_n(ctx, colorspace);
for (i = 0; i < en; i++)
color[i] = 0.0f;
break;
@@ -1492,8 +1493,9 @@ fz_run_display_list(fz_context *ctx, fz_display_list *list, fz_device *dev, cons
}
if (n.color)
{
- memcpy(color, (float *)node, colorspace->n * sizeof(float));
- node += SIZE_IN_NODES(colorspace->n * sizeof(float));
+ int nc = fz_colorspace_n(ctx, colorspace);
+ memcpy(color, (float *)node, nc * sizeof(float));
+ node += SIZE_IN_NODES(nc * sizeof(float));
}
if (n.alpha)
{
diff --git a/source/fitz/load-jpx.c b/source/fitz/load-jpx.c
index a7775fc7..48b65217 100644
--- a/source/fitz/load-jpx.c
+++ b/source/fitz/load-jpx.c
@@ -777,7 +777,7 @@ jpx_read_image(fz_context *ctx, unsigned char *data, size_t size, fz_colorspace
if (defcs)
{
- if (defcs->n == n)
+ if (fz_colorspace_n(ctx, defcs) == n)
{
colorspace = defcs;
}
diff --git a/source/fitz/load-pnm.c b/source/fitz/load-pnm.c
index 6a330f98..c140938c 100644
--- a/source/fitz/load-pnm.c
+++ b/source/fitz/load-pnm.c
@@ -192,9 +192,10 @@ pnm_ascii_read_image(fz_context *ctx, struct info *pnm, unsigned char *p, unsign
}
else
{
+ int n = fz_colorspace_n(ctx, img->colorspace);
for (y = 0; y < pnm->height; y++)
for (x = 0; x < pnm->width; x++)
- for (k = 0; k < img->colorspace->n; k++)
+ for (k = 0; k < n; k++)
{
int v = 0;
p = pnm_read_number(ctx, p, e, &v);
@@ -262,25 +263,26 @@ pnm_binary_read_image(fz_context *ctx, struct info *pnm, unsigned char *p, unsig
}
else
{
+ int n = fz_colorspace_n(ctx, img->colorspace);
if (pnm->maxval == 255)
{
for (y = 0; y < pnm->height; y++)
for (x = 0; x < pnm->width; x++)
- for (k = 0; k < img->colorspace->n; k++)
+ for (k = 0; k < n; k++)
*dp++ = *p++;
}
else if (pnm->maxval < 256)
{
for (y = 0; y < pnm->height; y++)
for (x = 0; x < pnm->width; x++)
- for (k = 0; k < img->colorspace->n; k++)
+ for (k = 0; k < n; k++)
*dp++ = map_color(ctx, *p++, pnm->maxval, 255);
}
else
{
for (y = 0; y < pnm->height; y++)
for (x = 0; x < pnm->width; x++)
- for (k = 0; k < img->colorspace->n; k++)
+ for (k = 0; k < n; k++)
{
*dp++ = map_color(ctx, (p[0] << 8) | p[1], pnm->maxval, 255);
p += 2;
@@ -427,10 +429,11 @@ pam_binary_read_image(fz_context *ctx, struct info *pnm, unsigned char *p, unsig
if (!onlymeta)
{
unsigned char *dp;
- int x, y, k;
+ int x, y, k, n;
img = fz_new_pixmap(ctx, pnm->cs, pnm->width, pnm->height, pnm->alpha);
dp = img->samples;
+ n = fz_colorspace_n(ctx, img->colorspace);
if (bitmap)
{
@@ -439,7 +442,7 @@ pam_binary_read_image(fz_context *ctx, struct info *pnm, unsigned char *p, unsig
for (y = 0; y < pnm->height; y++)
for (x = 0; x < pnm->width; x++)
- for (k = 0; k < img->colorspace->n; k++)
+ for (k = 0; k < n; k++)
{
if (*p)
*dp = 0x00;
diff --git a/source/fitz/pixmap.c b/source/fitz/pixmap.c
index f888792d..1ced3b53 100644
--- a/source/fitz/pixmap.c
+++ b/source/fitz/pixmap.c
@@ -33,7 +33,7 @@ fz_new_pixmap_with_data(fz_context *ctx, fz_colorspace *colorspace, int w, int h
if (w < 0 || h < 0)
fz_throw(ctx, FZ_ERROR_GENERIC, "Illegal dimensions for pixmap %d %d", w, h);
- n = alpha + (colorspace ? colorspace->n : 0);
+ n = alpha + fz_colorspace_n(ctx, colorspace);
if (stride < n*w && stride > -n*w)
fz_throw(ctx, FZ_ERROR_GENERIC, "Illegal stride for pixmap (n=%d w=%d, stride=%d)", n, w, stride);
if (samples == NULL && stride < n*w)
@@ -91,7 +91,7 @@ fz_new_pixmap_with_data(fz_context *ctx, fz_colorspace *colorspace, int w, int h
fz_pixmap *
fz_new_pixmap(fz_context *ctx, fz_colorspace *colorspace, int w, int h, int alpha)
{
- int stride = ((colorspace ? colorspace->n : 0) + alpha) * w;
+ int stride = (fz_colorspace_n(ctx, colorspace) + alpha) * w;
return fz_new_pixmap_with_data(ctx, colorspace, w, h, alpha, stride, NULL);
}
@@ -109,7 +109,7 @@ fz_pixmap *
fz_new_pixmap_with_bbox_and_data(fz_context *ctx, fz_colorspace *colorspace, const fz_irect *r, int alpha, unsigned char *samples)
{
int w = r->x1 - r->x0;
- int stride = ((colorspace ? colorspace->n : 0) + alpha) * w;
+ int stride = (fz_colorspace_n(ctx, colorspace) + alpha) * w;
fz_pixmap *pixmap = fz_new_pixmap_with_data(ctx, colorspace, w, r->y1 - r->y0, alpha, stride, samples);
pixmap->x = r->x0;
pixmap->y = r->y0;
@@ -441,7 +441,7 @@ fz_clear_pixmap_with_value(fz_context *ctx, fz_pixmap *pix, int value)
return;
/* CMYK needs special handling (and potentially any other subtractive colorspaces) */
- if (pix->colorspace && pix->colorspace->n == 4)
+ if (fz_colorspace_n(ctx, pix->colorspace) == 4)
{
clear_cmyk_bitmap(pix->samples, w, h, pix->stride, 255-value, pix->alpha);
return;
@@ -611,7 +611,7 @@ fz_clear_pixmap_rect_with_value(fz_context *ctx, fz_pixmap *dest, int value, con
destp = dest->samples + (unsigned int)(destspan * (local_b.y0 - dest->y) + dest->n * (local_b.x0 - dest->x));
/* CMYK needs special handling (and potentially any other subtractive colorspaces) */
- if (dest->colorspace && dest->colorspace->n == 4)
+ if (fz_colorspace_n(ctx, dest->colorspace) == 4)
{
value = 255 - value;
do
diff --git a/source/fitz/shade.c b/source/fitz/shade.c
index 1b1f3371..8f82eb72 100644
--- a/source/fitz/shade.c
+++ b/source/fitz/shade.c
@@ -84,7 +84,7 @@ fz_process_mesh_type1(fz_context *ctx, fz_shade *shade, const fz_matrix *ctm, fz
fz_vertex vs[2][2];
fz_vertex *v = vs[0];
fz_vertex *vn = vs[1];
- int n = shade->colorspace->n;
+ int n = fz_colorspace_n(ctx, shade->colorspace);
fz_matrix local_ctm;
fz_concat(&local_ctm, &shade->u.f.matrix, ctm);
@@ -931,7 +931,7 @@ fz_process_mesh(fz_context *ctx, fz_shade *shade, const fz_matrix *ctm,
painter.prepare = prepare;
painter.process = process;
painter.process_arg = process_arg;
- painter.ncomp = (shade->use_function > 0 ? 1 : shade->colorspace->n);
+ painter.ncomp = (shade->use_function > 0 ? 1 : fz_colorspace_n(ctx, shade->colorspace));
if (shade->type == FZ_FUNCTION_BASED)
fz_process_mesh_type1(ctx, shade, ctm, &painter);
@@ -1105,7 +1105,7 @@ fz_print_shade(fz_context *ctx, fz_output *out, fz_shade *shade)
shade->bbox.x0, shade->bbox.y0,
shade->bbox.x1, shade->bbox.y1);
- fz_printf(ctx, out, "\tcolorspace %s\n", shade->colorspace->name);
+ fz_printf(ctx, out, "\tcolorspace %s\n", fz_colorspace_name(ctx, shade->colorspace));
fz_printf(ctx, out, "\tmatrix [%g %g %g %g %g %g]\n",
shade->matrix.a, shade->matrix.b, shade->matrix.c,
@@ -1113,8 +1113,9 @@ fz_print_shade(fz_context *ctx, fz_output *out, fz_shade *shade)
if (shade->use_background)
{
+ int n = fz_colorspace_n(ctx, shade->colorspace);
fz_printf(ctx, out, "\tbackground [");
- for (i = 0; i < shade->colorspace->n; i++)
+ for (i = 0; i < n; i++)
fz_printf(ctx, out, "%s%g", i == 0 ? "" : " ", shade->background[i]);
fz_printf(ctx, out, "]\n");
}
diff --git a/source/fitz/stext-device.c b/source/fitz/stext-device.c
index 88a9f669..007a6a2a 100644
--- a/source/fitz/stext-device.c
+++ b/source/fitz/stext-device.c
@@ -942,7 +942,7 @@ fz_stext_fill_image_mask(fz_context *ctx, fz_device *dev, fz_image *img, const f
block->image = fz_keep_image(ctx, img);
block->cspace = fz_keep_colorspace(ctx, cspace);
if (cspace)
- memcpy(block->colors, color, sizeof(block->colors[0])*cspace->n);
+ memcpy(block->colors, color, sizeof(block->colors[0])*fz_colorspace_n(ctx, cspace));
block->mat = *ctm;
block->bbox.x0 = 0;
block->bbox.y0 = 0;
diff --git a/source/fitz/trace-device.c b/source/fitz/trace-device.c
index 86e059b5..bcb68bf8 100644
--- a/source/fitz/trace-device.c
+++ b/source/fitz/trace-device.c
@@ -16,11 +16,12 @@ fz_trace_matrix(fz_context *ctx, fz_output *out, const fz_matrix *ctm)
static void
fz_trace_color(fz_context *ctx, fz_output *out, fz_colorspace *colorspace, const float *color, float alpha)
{
- int i;
+ int i, n;
if (colorspace)
{
- fz_printf(ctx, out, " colorspace=\"%s\" color=\"", colorspace->name);
- for (i = 0; i < colorspace->n; i++)
+ n = fz_colorspace_n(ctx, colorspace);
+ fz_printf(ctx, out, " colorspace=\"%s\" color=\"", fz_colorspace_name(ctx, colorspace));
+ for (i = 0; i < n; i++)
fz_printf(ctx, out, "%s%g", i == 0 ? "" : " ", color[i]);
fz_printf(ctx, out, "\"");
}