From 93bd1ff05bf315ed11b305d32eb510bd9a9a7e92 Mon Sep 17 00:00:00 2001 From: Tor Andersson Date: Thu, 16 May 2013 22:29:27 +0200 Subject: Add colorspace context. To prepare for color management, we have to make the device colorspaces per-context and able to be overridden by users. --- apps/jstest_main.c | 2 +- apps/mudraw.c | 4 +- apps/pdfapp.c | 6 +- doc/example.c | 2 +- doc/multi-threaded.c | 2 +- draw/draw_device.c | 20 +++--- draw/draw_mesh.c | 2 +- fitz/base_context.c | 4 ++ fitz/dev_svg.c | 10 +-- fitz/fitz-internal.h | 5 +- fitz/fitz.h | 42 ++++++++---- fitz/image_jpeg.c | 6 +- fitz/image_jpx.c | 8 +-- fitz/image_png.c | 10 +-- fitz/image_save.c | 4 +- fitz/image_tiff.c | 14 ++-- fitz/res_colorspace.c | 177 ++++++++++++++++++++++++++++++++++++++------------ fitz/res_font.c | 2 +- fitz/res_pixmap.c | 4 +- pdf/pdf_annot.c | 16 ++--- pdf/pdf_colorspace.c | 40 ++++++------ pdf/pdf_device.c | 12 ++-- pdf/pdf_interpret.c | 24 +++---- xps/xps_common.c | 10 +-- xps/xps_gradient.c | 6 +- 25 files changed, 274 insertions(+), 158 deletions(-) diff --git a/apps/jstest_main.c b/apps/jstest_main.c index 7ef197b9..84d4dc9b 100644 --- a/apps/jstest_main.c +++ b/apps/jstest_main.c @@ -320,7 +320,7 @@ main(int argc, char *argv[]) pdfapp_init(ctx, &gapp); gapp.scrw = 640; gapp.scrh = 480; - gapp.colorspace = fz_device_rgb; + gapp.colorspace = fz_device_rgb(ctx); fz_try(ctx) { diff --git a/apps/mudraw.c b/apps/mudraw.c index dac5f42e..7efb9aae 100644 --- a/apps/mudraw.c +++ b/apps/mudraw.c @@ -815,9 +815,9 @@ int main(int argc, char **argv) } } - colorspace = fz_device_rgb; + colorspace = fz_device_rgb(ctx); if (grayscale || output_format == OUT_PGM || output_format == OUT_PBM) - colorspace = fz_device_gray; + colorspace = fz_device_gray(ctx); timing.count = 0; timing.total = 0; diff --git a/apps/pdfapp.c b/apps/pdfapp.c index 4320ba6a..78b00ed0 100644 --- a/apps/pdfapp.c +++ b/apps/pdfapp.c @@ -92,9 +92,9 @@ void pdfapp_init(fz_context *ctx, pdfapp_t *app) app->resolution = 72; app->ctx = ctx; #ifdef _WIN32 - app->colorspace = fz_device_bgr; + app->colorspace = fz_device_bgr(ctx); #else - app->colorspace = fz_device_rgb; + app->colorspace = fz_device_rgb(ctx); #endif } @@ -656,7 +656,7 @@ static void pdfapp_showpage(pdfapp_t *app, int loadpage, int drawpage, int repai if (app->image) fz_drop_pixmap(app->ctx, app->image); if (app->grayscale) - colorspace = fz_device_gray; + colorspace = fz_device_gray(app->ctx); else colorspace = app->colorspace; app->image = NULL; diff --git a/doc/example.c b/doc/example.c index d60c7cd6..45cca2ff 100644 --- a/doc/example.c +++ b/doc/example.c @@ -54,7 +54,7 @@ render(char *filename, int pagenumber, int zoom, int rotation) fz_irect bbox; fz_round_rect(&bbox, &bounds); - fz_pixmap *pix = fz_new_pixmap_with_bbox(ctx, fz_device_rgb, &bbox); + fz_pixmap *pix = fz_new_pixmap_with_bbox(ctx, fz_device_rgb(ctx), &bbox); fz_clear_pixmap_with_value(ctx, pix, 0xff); // A page consists of a series of objects (text, line art, images, diff --git a/doc/multi-threaded.c b/doc/multi-threaded.c index 7d6c34a4..ac250198 100644 --- a/doc/multi-threaded.c +++ b/doc/multi-threaded.c @@ -202,7 +202,7 @@ int main(int argc, char **argv) // Create a white pixmap using the correct dimensions. - fz_pixmap *pix = fz_new_pixmap_with_bbox(ctx, fz_device_rgb, fz_round_rect(&rbox, &bbox)); + fz_pixmap *pix = fz_new_pixmap_with_bbox(ctx, fz_device_rgb(ctx), fz_round_rect(&rbox, &bbox)); fz_clear_pixmap_with_value(ctx, pix, 0xff); // Populate the data structure to be sent to the diff --git a/draw/draw_device.c b/draw/draw_device.c index 0c95cbca..addd798c 100644 --- a/draw/draw_device.c +++ b/draw/draw_device.c @@ -253,7 +253,7 @@ fz_draw_fill_path(fz_device *devp, fz_path *path, int even_odd, const fz_matrix fz_colorspace *model = state->dest->colorspace; if (model == NULL) - model = fz_device_gray; + model = fz_device_gray(dev->ctx); fz_reset_gel(dev->gel, &state->scissor); fz_flatten_fill_path(dev->gel, path, ctm, flatness); @@ -303,7 +303,7 @@ fz_draw_stroke_path(fz_device *devp, fz_path *path, fz_stroke_state *stroke, con fz_colorspace *model = state->dest->colorspace; if (model == NULL) - model = fz_device_gray; + model = fz_device_gray(dev->ctx); if (linewidth * expansion < 0.1f) linewidth = 1 / expansion; @@ -766,7 +766,7 @@ fz_draw_clip_text(fz_device *devp, fz_text *text, const fz_matrix *ctm, int accu state[0].mask = NULL; fz_try(ctx) { - fz_draw_fill_path(devp, path, 0, &fz_identity, fz_device_gray, &white, 1); + fz_draw_fill_path(devp, path, 0, &fz_identity, fz_device_gray(ctx), &white, 1); } fz_always(ctx) { @@ -881,7 +881,7 @@ fz_draw_clip_stroke_text(fz_device *devp, fz_text *text, fz_stroke_state *stroke state[0].mask = NULL; fz_try(ctx) { - fz_draw_stroke_path(devp, path, stroke, &fz_identity, fz_device_gray, &white, 1); + fz_draw_stroke_path(devp, path, stroke, &fz_identity, fz_device_gray(ctx), &white, 1); } fz_always(ctx) { @@ -1107,7 +1107,7 @@ fz_draw_fill_image(fz_device *devp, fz_image *image, const fz_matrix *ctm, float state = fz_knockout_begin(dev); after = 0; - if (pixmap->colorspace == fz_device_gray) + if (pixmap->colorspace == fz_device_gray(ctx)) after = 1; if (pixmap->colorspace != model && !after) @@ -1137,8 +1137,8 @@ fz_draw_fill_image(fz_device *devp, fz_image *image, const fz_matrix *ctm, float if (pixmap->colorspace != model) { - if ((pixmap->colorspace == fz_device_gray && model == fz_device_rgb) || - (pixmap->colorspace == fz_device_gray && model == fz_device_bgr)) + if ((pixmap->colorspace == fz_device_gray(ctx) && model == fz_device_rgb(ctx)) || + (pixmap->colorspace == fz_device_gray(ctx) && model == fz_device_bgr(ctx))) { /* We have special case rendering code for gray -> rgb/bgr */ } @@ -1409,7 +1409,7 @@ fz_draw_begin_mask(fz_device *devp, const fz_rect *rect, int luminosity, fz_colo fz_try(ctx) { - state[1].dest = dest = fz_new_pixmap_with_bbox(dev->ctx, fz_device_gray, &bbox); + state[1].dest = dest = fz_new_pixmap_with_bbox(dev->ctx, fz_device_gray(ctx), &bbox); if (state->shape) { /* FIXME: If we ever want to support AIS true, then @@ -1425,8 +1425,8 @@ fz_draw_begin_mask(fz_device *devp, const fz_rect *rect, int luminosity, fz_colo { float bc; if (!colorspace) - colorspace = fz_device_gray; - fz_convert_color(dev->ctx, fz_device_gray, &bc, colorspace, colorfv); + colorspace = fz_device_gray(ctx); + fz_convert_color(dev->ctx, fz_device_gray(ctx), &bc, colorspace, colorfv); fz_clear_pixmap_with_value(dev->ctx, dest, bc * 255); if (shape) fz_clear_pixmap_with_value(dev->ctx, shape, 255); diff --git a/draw/draw_mesh.c b/draw/draw_mesh.c index 100a1686..8be48e02 100644 --- a/draw/draw_mesh.c +++ b/draw/draw_mesh.c @@ -230,7 +230,7 @@ fz_paint_shade(fz_context *ctx, fz_shade *shade, const fz_matrix *ctm, fz_pixmap clut[i][k] = shade->function[i][shade->colorspace->n] * 255; } conv = fz_new_pixmap_with_bbox(ctx, dest->colorspace, bbox); - temp = fz_new_pixmap_with_bbox(ctx, fz_device_gray, bbox); + temp = fz_new_pixmap_with_bbox(ctx, fz_device_gray(ctx), bbox); fz_clear_pixmap(ctx, temp); } else diff --git a/fitz/base_context.c b/fitz/base_context.c index 8189efb2..683ad7dd 100644 --- a/fitz/base_context.c +++ b/fitz/base_context.c @@ -52,6 +52,7 @@ fz_free_context(fz_context *ctx) fz_drop_glyph_cache_context(ctx); fz_drop_store_context(ctx); fz_free_aa_context(ctx); + fz_drop_colorspace_context(ctx); fz_drop_font_context(ctx); fz_drop_id_context(ctx); @@ -138,6 +139,7 @@ fz_new_context(fz_alloc_context *alloc, fz_locks_context *locks, unsigned int ma { fz_new_store_context(ctx, max_store); fz_new_glyph_cache_context(ctx); + fz_new_colorspace_context(ctx); fz_new_font_context(ctx); fz_new_id_context(ctx); } @@ -180,6 +182,8 @@ fz_clone_context_internal(fz_context *ctx) new_ctx->store = fz_keep_store_context(new_ctx); new_ctx->glyph_cache = ctx->glyph_cache; new_ctx->glyph_cache = fz_keep_glyph_cache(new_ctx); + new_ctx->colorspace = ctx->colorspace; + new_ctx->colorspace = fz_keep_colorspace_context(new_ctx); new_ctx->font = ctx->font; new_ctx->font = fz_keep_font_context(new_ctx); new_ctx->id = ctx->id; diff --git a/fitz/dev_svg.c b/fitz/dev_svg.c index 1b71e576..4353544d 100644 --- a/fitz/dev_svg.c +++ b/fitz/dev_svg.c @@ -112,7 +112,7 @@ svg_dev_fill_color(svg_device *sdev, fz_colorspace *colorspace, float *color, fl fz_output *out = sdev->out; float rgb[FZ_MAX_COLORS]; - if (colorspace != fz_device_rgb) + if (colorspace != fz_device_rgb(ctx)) { /* If it's not rgb, make it rgb */ colorspace->to_rgb(ctx, colorspace, color, rgb); @@ -136,7 +136,7 @@ svg_dev_stroke_color(svg_device *sdev, fz_colorspace *colorspace, float *color, fz_output *out = sdev->out; float rgb[FZ_MAX_COLORS]; - if (colorspace != fz_device_rgb) + if (colorspace != fz_device_rgb(ctx)) { /* If it's not rgb, make it rgb */ colorspace->to_rgb(ctx, colorspace, color, rgb); @@ -273,7 +273,7 @@ svg_dev_clip_stroke_path(fz_device *dev, fz_path *path, const fz_rect *rect, fz_ fz_printf(out, "\n\n\n", num); } @@ -319,7 +319,7 @@ svg_dev_clip_text(fz_device *dev, fz_text *text, const fz_matrix *ctm, int accum fz_printf(out, "\n", num, bounds.x0, bounds.y0, bounds.x1 - bounds.x0, bounds.y1 - bounds.y0); fz_printf(out, "\n\n", num); } @@ -340,7 +340,7 @@ svg_dev_clip_stroke_text(fz_device *dev, fz_text *text, fz_stroke_state *stroke, num, bounds.x0, bounds.y0, bounds.x1 - bounds.x0, bounds.y1 - bounds.y0); fz_printf(out, "\n\n", num); } diff --git a/fitz/fitz-internal.h b/fitz/fitz-internal.h index 24895591..25ab6860 100644 --- a/fitz/fitz-internal.h +++ b/fitz/fitz-internal.h @@ -1060,9 +1060,12 @@ fz_colorspace *fz_keep_colorspace(fz_context *ctx, fz_colorspace *colorspace); void fz_drop_colorspace(fz_context *ctx, fz_colorspace *colorspace); void fz_free_colorspace_imp(fz_context *ctx, fz_storable *colorspace); - void fz_convert_color(fz_context *ctx, fz_colorspace *dsts, float *dstv, fz_colorspace *srcs, float *srcv); +void fz_new_colorspace_context(fz_context *ctx); +fz_colorspace_context *fz_keep_colorspace_context(fz_context *ctx); +void fz_drop_colorspace_context(fz_context *ctx); + typedef struct fz_color_converter_s fz_color_converter; /* This structure is public because it allows us to avoid dynamic allocations. diff --git a/fitz/fitz.h b/fitz/fitz.h index f18efe6b..05bf85fb 100644 --- a/fitz/fitz.h +++ b/fitz/fitz.h @@ -204,6 +204,7 @@ typedef struct fz_error_context_s fz_error_context; typedef struct fz_id_context_s fz_id_context; typedef struct fz_warn_context_s fz_warn_context; typedef struct fz_font_context_s fz_font_context; +typedef struct fz_colorspace_context_s fz_colorspace_context; typedef struct fz_aa_context_s fz_aa_context; typedef struct fz_locks_context_s fz_locks_context; typedef struct fz_store_s fz_store; @@ -299,6 +300,7 @@ struct fz_context_s fz_error_context *error; fz_warn_context *warn; fz_font_context *font; + fz_colorspace_context *colorspace; fz_aa_context *aa; fz_store *store; fz_glyph_cache *glyph_cache; @@ -1428,28 +1430,44 @@ fz_colorspace *fz_find_device_colorspace(fz_context *ctx, char *name); int fz_colorspace_is_indexed(fz_colorspace *cs); /* - fz_device_gray: Abstract colorspace representing device specific - gray. + fz_device_gray: Get colorspace representing device specific gray. */ -extern fz_colorspace *fz_device_gray; +fz_colorspace *fz_device_gray(fz_context *ctx); /* - fz_device_rgb: Abstract colorspace representing device specific - rgb. + fz_device_rgb: Get colorspace representing device specific rgb. */ -extern fz_colorspace *fz_device_rgb; +fz_colorspace *fz_device_rgb(fz_context *ctx); /* - fz_device_bgr: Abstract colorspace representing device specific - bgr. + fz_device_bgr: Get colorspace representing device specific bgr. */ -extern fz_colorspace *fz_device_bgr; +fz_colorspace *fz_device_bgr(fz_context *ctx); /* - fz_device_cmyk: Abstract colorspace representing device specific - CMYK. + fz_device_cmyk: Get colorspace representing device specific CMYK. */ -extern fz_colorspace *fz_device_cmyk; +fz_colorspace *fz_device_cmyk(fz_context *ctx); + +/* + fz_set_device_gray: Set colorspace representing device specific gray. +*/ +void fz_set_device_gray(fz_context *ctx, fz_colorspace *cs); + +/* + fz_set_device_rgb: Set colorspace representing device specific rgb. +*/ +void fz_set_device_rgb(fz_context *ctx, fz_colorspace *cs); + +/* + fz_set_device_bgr: Set colorspace representing device specific bgr. +*/ +void fz_set_device_bgr(fz_context *ctx, fz_colorspace *cs); + +/* + fz_set_device_cmyk: Set colorspace representing device specific CMYK. +*/ +void fz_set_device_cmyk(fz_context *ctx, fz_colorspace *cs); /* Pixmaps represent a set of pixels for a 2 dimensional region of a diff --git a/fitz/image_jpeg.c b/fitz/image_jpeg.c index c6ff2033..bd7a6d5b 100644 --- a/fitz/image_jpeg.c +++ b/fitz/image_jpeg.c @@ -70,11 +70,11 @@ fz_load_jpeg_info(fz_context *ctx, unsigned char *rbuf, int rlen, int *xp, int * jpeg_read_header(&cinfo, 1); if (cinfo.num_components == 1) - *cspacep = fz_device_gray; + *cspacep = fz_device_gray(ctx); else if (cinfo.num_components == 3) - *cspacep = fz_device_rgb; + *cspacep = fz_device_rgb(ctx); else if (cinfo.num_components == 4) - *cspacep = fz_device_cmyk; + *cspacep = fz_device_cmyk(ctx); else fz_throw(ctx, "bad number of components in jpeg: %d", cinfo.num_components); diff --git a/fitz/image_jpx.c b/fitz/image_jpx.c index 0b3df098..ac232220 100644 --- a/fitz/image_jpx.c +++ b/fitz/image_jpx.c @@ -117,9 +117,9 @@ fz_load_jpx(fz_context *ctx, unsigned char *data, int size, fz_colorspace *defcs { switch (n) { - case 1: colorspace = fz_device_gray; break; - case 3: colorspace = fz_device_rgb; break; - case 4: colorspace = fz_device_cmyk; break; + case 1: colorspace = fz_device_gray(ctx); break; + case 3: colorspace = fz_device_rgb(ctx); break; + case 4: colorspace = fz_device_cmyk(ctx); break; } } @@ -158,7 +158,7 @@ fz_load_jpx(fz_context *ctx, unsigned char *data, int size, fz_colorspace *defcs { if (n == 4) { - fz_pixmap *tmp = fz_new_pixmap(ctx, fz_device_rgb, w, h); + fz_pixmap *tmp = fz_new_pixmap(ctx, fz_device_rgb(ctx), w, h); fz_convert_pixmap(ctx, tmp, img); fz_drop_pixmap(ctx, img); img = tmp; diff --git a/fitz/image_png.c b/fitz/image_png.c index 7eebdced..1adaaf7a 100644 --- a/fitz/image_png.c +++ b/fitz/image_png.c @@ -485,7 +485,7 @@ png_read_image(fz_context *ctx, struct info *info, unsigned char *p, unsigned in static fz_pixmap * png_expand_palette(fz_context *ctx, struct info *info, fz_pixmap *src) { - fz_pixmap *dst = fz_new_pixmap(ctx, fz_device_rgb, src->w, src->h); + fz_pixmap *dst = fz_new_pixmap(ctx, fz_device_rgb(ctx), src->w, src->h); unsigned char *sp = src->samples; unsigned char *dp = dst->samples; unsigned int x, y; @@ -545,9 +545,9 @@ fz_load_png(fz_context *ctx, unsigned char *p, int total) png_read_image(ctx, &png, p, total); if (png.n == 3 || png.n == 4) - colorspace = fz_device_rgb; + colorspace = fz_device_rgb(ctx); else - colorspace = fz_device_gray; + colorspace = fz_device_gray(ctx); stride = (png.width * png.n * png.depth + 7) / 8; @@ -587,9 +587,9 @@ fz_load_png_info(fz_context *ctx, unsigned char *p, int total, int *wp, int *hp, png_read_image(ctx, &png, p, total); if (png.n == 3 || png.n == 4) - *cspacep = fz_device_rgb; + *cspacep = fz_device_rgb(ctx); else - *cspacep = fz_device_gray; + *cspacep = fz_device_gray(ctx); *wp = png.width; *hp = png.height; diff --git a/fitz/image_save.c b/fitz/image_save.c index b0856507..8695002b 100644 --- a/fitz/image_save.c +++ b/fitz/image_save.c @@ -8,10 +8,10 @@ void fz_write_pixmap(fz_context *ctx, fz_pixmap *img, char *file, int rgb) if (!img) return; - if (rgb && img->colorspace && img->colorspace != fz_device_rgb) + if (rgb && img->colorspace && img->colorspace != fz_device_rgb(ctx)) { fz_irect bbox; - converted = fz_new_pixmap_with_bbox(ctx, fz_device_rgb, fz_pixmap_bbox(ctx, img, &bbox)); + converted = fz_new_pixmap_with_bbox(ctx, fz_device_rgb(ctx), fz_pixmap_bbox(ctx, img, &bbox)); fz_convert_pixmap(ctx, converted, img); img = converted; } diff --git a/fitz/image_tiff.c b/fitz/image_tiff.c index 0efcc622..7a372214 100644 --- a/fitz/image_tiff.c +++ b/fitz/image_tiff.c @@ -358,23 +358,23 @@ fz_decode_tiff_strips(struct tiff *tiff) switch (tiff->photometric) { case 0: /* WhiteIsZero -- inverted */ - tiff->colorspace = fz_device_gray; + tiff->colorspace = fz_device_gray(tiff->ctx); break; case 1: /* BlackIsZero */ - tiff->colorspace = fz_device_gray; + tiff->colorspace = fz_device_gray(tiff->ctx); break; case 2: /* RGB */ - tiff->colorspace = fz_device_rgb; + tiff->colorspace = fz_device_rgb(tiff->ctx); break; case 3: /* RGBPal */ - tiff->colorspace = fz_device_rgb; + tiff->colorspace = fz_device_rgb(tiff->ctx); break; case 5: /* CMYK */ - tiff->colorspace = fz_device_cmyk; + tiff->colorspace = fz_device_cmyk(tiff->ctx); break; case 6: /* YCbCr */ /* it's probably a jpeg ... we let jpeg convert to rgb */ - tiff->colorspace = fz_device_rgb; + tiff->colorspace = fz_device_rgb(tiff->ctx); break; default: fz_throw(tiff->ctx, "unknown photometric: %d", tiff->photometric); @@ -809,7 +809,7 @@ fz_load_tiff(fz_context *ctx, unsigned char *buf, int len) /* CMYK is a subtractive colorspace, we want additive for premul alpha */ if (image->n == 5) { - fz_pixmap *rgb = fz_new_pixmap(tiff.ctx, fz_device_rgb, image->w, image->h); + fz_pixmap *rgb = fz_new_pixmap(tiff.ctx, fz_device_rgb(ctx), image->w, image->h); fz_convert_pixmap(tiff.ctx, rgb, image); rgb->xres = image->xres; rgb->yres = image->yres; diff --git a/fitz/res_colorspace.c b/fitz/res_colorspace.c index 5d8c3b02..faa6c3c1 100644 --- a/fitz/res_colorspace.c +++ b/fitz/res_colorspace.c @@ -169,31 +169,122 @@ static void rgb_to_cmyk(fz_context *ctx, fz_colorspace *cs, float *rgb, float *c cmyk[3] = k; } -static fz_colorspace k_device_gray = { {-1, fz_free_colorspace_imp}, 0, "DeviceGray", 1, gray_to_rgb, rgb_to_gray }; -static fz_colorspace k_device_rgb = { {-1, fz_free_colorspace_imp}, 0, "DeviceRGB", 3, rgb_to_rgb, rgb_to_rgb }; -static fz_colorspace k_device_bgr = { {-1, fz_free_colorspace_imp}, 0, "DeviceRGB", 3, bgr_to_rgb, rgb_to_bgr }; -static fz_colorspace k_device_cmyk = { {-1, fz_free_colorspace_imp}, 0, "DeviceCMYK", 4, cmyk_to_rgb, rgb_to_cmyk }; +static fz_colorspace k_default_gray = { {-1, fz_free_colorspace_imp}, 0, "DeviceGray", 1, gray_to_rgb, rgb_to_gray }; +static fz_colorspace k_default_rgb = { {-1, fz_free_colorspace_imp}, 0, "DeviceRGB", 3, rgb_to_rgb, rgb_to_rgb }; +static fz_colorspace k_default_bgr = { {-1, fz_free_colorspace_imp}, 0, "DeviceRGB", 3, bgr_to_rgb, rgb_to_bgr }; +static fz_colorspace k_default_cmyk = { {-1, fz_free_colorspace_imp}, 0, "DeviceCMYK", 4, cmyk_to_rgb, rgb_to_cmyk }; -fz_colorspace *fz_device_gray = &k_device_gray; -fz_colorspace *fz_device_rgb = &k_device_rgb; -fz_colorspace *fz_device_bgr = &k_device_bgr; -fz_colorspace *fz_device_cmyk = &k_device_cmyk; +static fz_colorspace *fz_default_gray = &k_default_gray; +static fz_colorspace *fz_default_rgb = &k_default_rgb; +static fz_colorspace *fz_default_bgr = &k_default_bgr; +static fz_colorspace *fz_default_cmyk = &k_default_cmyk; + +struct fz_colorspace_context_s +{ + int ctx_refs; + fz_colorspace *gray, *rgb, *bgr, *cmyk; +}; + +void fz_new_colorspace_context(fz_context *ctx) +{ + ctx->colorspace = fz_malloc_struct(ctx, fz_colorspace_context); + ctx->colorspace->ctx_refs = 1; + ctx->colorspace->gray = fz_default_gray; + ctx->colorspace->rgb = fz_default_rgb; + ctx->colorspace->bgr = fz_default_bgr; + ctx->colorspace->cmyk = fz_default_cmyk; +} + +fz_colorspace_context * +fz_keep_colorspace_context(fz_context *ctx) +{ + if (!ctx || !ctx->colorspace) + return NULL; + fz_lock(ctx, FZ_LOCK_ALLOC); + ctx->colorspace->ctx_refs++; + fz_unlock(ctx, FZ_LOCK_ALLOC); + return ctx->colorspace; +} + +void fz_drop_colorspace_context(fz_context *ctx) +{ + int drop; + if (!ctx || !ctx->colorspace) + return; + fz_lock(ctx, FZ_LOCK_ALLOC); + drop = --ctx->colorspace->ctx_refs; + fz_unlock(ctx, FZ_LOCK_ALLOC); + if (drop == 0) + fz_free(ctx, ctx->colorspace); +} + +fz_colorspace * +fz_device_gray(fz_context *ctx) +{ + return ctx->colorspace->gray; +} + +fz_colorspace * +fz_device_rgb(fz_context *ctx) +{ + return ctx->colorspace->rgb; +} + +fz_colorspace * +fz_device_bgr(fz_context *ctx) +{ + return ctx->colorspace->bgr; +} + +fz_colorspace * +fz_device_cmyk(fz_context *ctx) +{ + return ctx->colorspace->cmyk; +} fz_colorspace * fz_find_device_colorspace(fz_context *ctx, char *name) { if (!strcmp(name, "DeviceGray")) - return fz_device_gray; + return fz_device_gray(ctx); if (!strcmp(name, "DeviceRGB")) - return fz_device_rgb; + return fz_device_rgb(ctx); if (!strcmp(name, "DeviceBGR")) - return fz_device_bgr; + return fz_device_bgr(ctx); if (!strcmp(name, "DeviceCMYK")) - return fz_device_cmyk; + return fz_device_cmyk(ctx); assert(!"unknown device colorspace"); return NULL; } +void +fz_set_device_gray(fz_context *ctx, fz_colorspace *cs) +{ + fz_drop_colorspace(ctx, ctx->colorspace->gray); + ctx->colorspace->gray = fz_keep_colorspace(ctx, cs); +} + +void +fz_set_device_rgb(fz_context *ctx, fz_colorspace *cs) +{ + fz_drop_colorspace(ctx, ctx->colorspace->rgb); + ctx->colorspace->rgb = fz_keep_colorspace(ctx, cs); +} + +void +fz_set_device_bgr(fz_context *ctx, fz_colorspace *cs) +{ + fz_drop_colorspace(ctx, ctx->colorspace->bgr); + ctx->colorspace->bgr = fz_keep_colorspace(ctx, cs); +} + +void +fz_set_device_cmyk(fz_context *ctx, fz_colorspace *cs) +{ + fz_drop_colorspace(ctx, ctx->colorspace->cmyk); + ctx->colorspace->cmyk = fz_keep_colorspace(ctx, cs); +} + int fz_colorspace_is_indexed(fz_colorspace *cs) { @@ -861,35 +952,35 @@ fz_convert_pixmap(fz_context *ctx, fz_pixmap *dp, fz_pixmap *sp) dp->interpolate = sp->interpolate; - if (ss == fz_device_gray) + if (ss == fz_default_gray) { - if (ds == fz_device_rgb) fast_gray_to_rgb(dp, sp); - else if (ds == fz_device_bgr) fast_gray_to_rgb(dp, sp); /* bgr == rgb here */ - else if (ds == fz_device_cmyk) fast_gray_to_cmyk(dp, sp); + 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); } - else if (ss == fz_device_rgb) + else if (ss == fz_default_rgb) { - if (ds == fz_device_gray) fast_rgb_to_gray(dp, sp); - else if (ds == fz_device_bgr) fast_rgb_to_bgr(dp, sp); - else if (ds == fz_device_cmyk) fast_rgb_to_cmyk(dp, sp); + 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); } - else if (ss == fz_device_bgr) + else if (ss == fz_default_bgr) { - if (ds == fz_device_gray) fast_bgr_to_gray(dp, sp); - else if (ds == fz_device_rgb) fast_rgb_to_bgr(dp, sp); /* bgr = rgb here */ - else if (ds == fz_device_cmyk) fast_bgr_to_cmyk(sp, dp); + 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); } - else if (ss == fz_device_cmyk) + else if (ss == fz_default_cmyk) { - if (ds == fz_device_gray) fast_cmyk_to_gray(dp, sp); - else if (ds == fz_device_bgr) fast_cmyk_to_bgr(ctx, dp, sp); - else if (ds == fz_device_rgb) fast_cmyk_to_rgb(ctx, dp, sp); + 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); } @@ -1027,47 +1118,47 @@ void fz_find_color_converter(fz_color_converter *cc, fz_context *ctx, fz_colorsp cc->ctx = ctx; cc->ds = ds; cc->ss = ss; - if (ss == fz_device_gray) + if (ss == fz_default_gray) { - if ((ds == fz_device_rgb) || (ds == fz_device_bgr)) + if ((ds == fz_default_rgb) || (ds == fz_default_bgr)) cc->convert = g2rgb; - else if (ds == fz_device_cmyk) + else if (ds == fz_default_cmyk) cc->convert = g2cmyk; else cc->convert = std_conv_color; } - else if (ss == fz_device_rgb) + else if (ss == fz_default_rgb) { - if (ds == fz_device_gray) + if (ds == fz_default_gray) cc->convert = rgb2g; - else if (ds == fz_device_bgr) + else if (ds == fz_default_bgr) cc->convert = rgb2bgr; - else if (ds == fz_device_cmyk) + else if (ds == fz_default_cmyk) cc->convert = rgb2cmyk; else cc->convert = std_conv_color; } - else if (ss == fz_device_bgr) + else if (ss == fz_default_bgr) { - if (ds == fz_device_gray) + if (ds == fz_default_gray) cc->convert = bgr2g; - else if (ds == fz_device_rgb) + else if (ds == fz_default_rgb) cc->convert = rgb2bgr; - else if (ds == fz_device_cmyk) + else if (ds == fz_default_cmyk) cc->convert = bgr2cmyk; else cc->convert = std_conv_color; } - else if (ss == fz_device_cmyk) + else if (ss == fz_default_cmyk) { - if (ds == fz_device_gray) + if (ds == fz_default_gray) cc->convert = cmyk2g; - else if (ds == fz_device_rgb) + else if (ds == fz_default_rgb) cc->convert = cmyk2rgb; - else if (ds == fz_device_bgr) + else if (ds == fz_default_bgr) cc->convert = cmyk2bgr; else cc->convert = std_conv_color; diff --git a/fitz/res_font.c b/fitz/res_font.c index edc8c054..8fb51377 100644 --- a/fitz/res_font.c +++ b/fitz/res_font.c @@ -954,7 +954,7 @@ fz_render_t3_glyph(fz_context *ctx, fz_font *font, int gid, const fz_matrix *trm fz_irect_from_rect(&bbox, &bounds); fz_intersect_irect(&bbox, &scissor); - glyph = fz_new_pixmap_with_bbox(ctx, model ? model : fz_device_gray, &bbox); + glyph = fz_new_pixmap_with_bbox(ctx, model ? model : fz_device_gray(ctx), &bbox); fz_clear_pixmap(ctx, glyph); fz_concat(&ctm, &font->t3matrix, trm); diff --git a/fitz/res_pixmap.c b/fitz/res_pixmap.c index 6a931486..18d05231 100644 --- a/fitz/res_pixmap.c +++ b/fitz/res_pixmap.c @@ -694,9 +694,9 @@ fz_image_as_png(fz_context *ctx, fz_image *image, int w, int h) fz_try(ctx) { - if (pix->colorspace != fz_device_gray || pix->colorspace != fz_device_rgb) + if (pix->colorspace != fz_device_gray(ctx) || pix->colorspace != fz_device_rgb(ctx)) { - fz_pixmap *pix2 = fz_new_pixmap(ctx, fz_device_rgb, pix->w, pix->h); + fz_pixmap *pix2 = fz_new_pixmap(ctx, fz_device_rgb(ctx), pix->w, pix->h); fz_convert_pixmap(ctx, pix2, pix); fz_drop_pixmap(ctx, pix); pix = pix2; diff --git a/pdf/pdf_annot.c b/pdf/pdf_annot.c index 0c2128a7..25ffd494 100644 --- a/pdf/pdf_annot.c +++ b/pdf/pdf_annot.c @@ -768,16 +768,16 @@ pdf_delete_annot(pdf_document *doc, pdf_page *page, pdf_annot *annot) doc->dirty = 1; } -static fz_colorspace *pdf_to_color(pdf_obj *col, float color[4]) +static fz_colorspace *pdf_to_color(pdf_document *doc, pdf_obj *col, float color[4]) { fz_colorspace *cs; int i, ncol = pdf_array_len(col); switch (ncol) { - case 1: cs = fz_device_gray; break; - case 3: cs = fz_device_rgb; break; - case 4: cs = fz_device_cmyk; break; + case 1: cs = fz_device_gray(doc->ctx); break; + case 3: cs = fz_device_rgb(doc->ctx); break; + case 4: cs = fz_device_cmyk(doc->ctx); break; default: return NULL; } @@ -1031,7 +1031,7 @@ pdf_set_markup_obj_appearance(pdf_document *doc, pdf_obj *annot, float color[3], if (stroke) { // assert(path) - fz_stroke_path(dev, path, stroke, &fz_identity, fz_device_rgb, color, alpha); + fz_stroke_path(dev, path, stroke, &fz_identity, fz_device_rgb(ctx), color, alpha); fz_drop_stroke_state(ctx, stroke); stroke = NULL; fz_free_path(ctx, path); @@ -1049,7 +1049,7 @@ pdf_set_markup_obj_appearance(pdf_document *doc, pdf_obj *annot, float color[3], if (stroke) { - fz_stroke_path(dev, path, stroke, &fz_identity, fz_device_rgb, color, alpha); + fz_stroke_path(dev, path, stroke, &fz_identity, fz_device_rgb(ctx), color, alpha); } pdf_set_annot_obj_appearance(doc, annot, &fz_identity, &rect, strike_list); @@ -1090,10 +1090,10 @@ pdf_set_ink_obj_appearance(pdf_document *doc, pdf_obj *annot) pdf_obj *list; int n, m, i, j; - cs = pdf_to_color(pdf_dict_gets(annot, "C"), color); + cs = pdf_to_color(doc, pdf_dict_gets(annot, "C"), color); if (!cs) { - cs = fz_device_rgb; + cs = fz_device_rgb(ctx); color[0] = 1.0f; color[1] = 0.0f; color[2] = 0.0f; diff --git a/pdf/pdf_colorspace.c b/pdf/pdf_colorspace.c index a398b44f..21d67eeb 100644 --- a/pdf/pdf_colorspace.c +++ b/pdf/pdf_colorspace.c @@ -12,9 +12,9 @@ load_icc_based(pdf_document *xref, pdf_obj *dict) switch (n) { - case 1: return fz_device_gray; - case 3: return fz_device_rgb; - case 4: return fz_device_cmyk; + case 1: return fz_device_gray(xref->ctx); + case 3: return fz_device_rgb(xref->ctx); + case 4: return fz_device_cmyk(xref->ctx); } fz_throw(xref->ctx, "syntaxerror: ICCBased must have 1, 3 or 4 components"); @@ -224,19 +224,19 @@ pdf_load_colorspace_imp(pdf_document *xref, pdf_obj *obj) { const char *str = pdf_to_name(obj); if (!strcmp(str, "Pattern")) - return fz_device_gray; + return fz_device_gray(ctx); else if (!strcmp(str, "G")) - return fz_device_gray; + return fz_device_gray(ctx); else if (!strcmp(str, "RGB")) - return fz_device_rgb; + return fz_device_rgb(ctx); else if (!strcmp(str, "CMYK")) - return fz_device_cmyk; + return fz_device_cmyk(ctx); else if (!strcmp(str, "DeviceGray")) - return fz_device_gray; + return fz_device_gray(ctx); else if (!strcmp(str, "DeviceRGB")) - return fz_device_rgb; + return fz_device_rgb(ctx); else if (!strcmp(str, "DeviceCMYK")) - return fz_device_cmyk; + return fz_device_cmyk(ctx); else fz_throw(ctx, "unknown colorspace: %s", pdf_to_name(obj)); } @@ -250,23 +250,23 @@ pdf_load_colorspace_imp(pdf_document *xref, pdf_obj *obj) { /* load base colorspace instead */ if (!strcmp(str, "G")) - return fz_device_gray; + return fz_device_gray(ctx); else if (!strcmp(str, "RGB")) - return fz_device_rgb; + return fz_device_rgb(ctx); else if (!strcmp(str, "CMYK")) - return fz_device_cmyk; + return fz_device_cmyk(ctx); else if (!strcmp(str, "DeviceGray")) - return fz_device_gray; + return fz_device_gray(ctx); else if (!strcmp(str, "DeviceRGB")) - return fz_device_rgb; + return fz_device_rgb(ctx); else if (!strcmp(str, "DeviceCMYK")) - return fz_device_cmyk; + return fz_device_cmyk(ctx); else if (!strcmp(str, "CalGray")) - return fz_device_gray; + return fz_device_gray(ctx); else if (!strcmp(str, "CalRGB")) - return fz_device_rgb; + return fz_device_rgb(ctx); else if (!strcmp(str, "CalCMYK")) - return fz_device_cmyk; + return fz_device_cmyk(ctx); else if (!strcmp(str, "Lab")) return fz_device_lab; else @@ -295,7 +295,7 @@ pdf_load_colorspace_imp(pdf_document *xref, pdf_obj *obj) pobj = pdf_array_get(obj, 1); if (!pobj) { - cs = fz_device_gray; + cs = fz_device_gray(ctx); break; } diff --git a/pdf/pdf_device.c b/pdf/pdf_device.c index dd21fb4b..37256316 100644 --- a/pdf/pdf_device.c +++ b/pdf/pdf_device.c @@ -420,11 +420,11 @@ pdf_dev_color(pdf_device *pdev, fz_colorspace *colorspace, float *color, int str float rgb[FZ_MAX_COLORS]; gstate *gs = CURRENT_GSTATE(pdev); - if (colorspace == fz_device_gray) + if (colorspace == fz_device_gray(ctx)) cspace = 1; - else if (colorspace == fz_device_rgb) + else if (colorspace == fz_device_rgb(ctx)) cspace = 3; - else if (colorspace == fz_device_cmyk) + else if (colorspace == fz_device_cmyk(ctx)) cspace = 4; if (cspace == 0) @@ -432,7 +432,7 @@ pdf_dev_color(pdf_device *pdev, fz_colorspace *colorspace, float *color, int str /* If it's an unknown colorspace, fallback to rgb */ colorspace->to_rgb(ctx, colorspace, color, rgb); color = rgb; - colorspace = fz_device_rgb; + colorspace = fz_device_rgb(ctx); } if (gs->colorspace[stroke] != colorspace) @@ -1208,8 +1208,8 @@ fz_device *pdf_new_pdf_device(pdf_document *doc, pdf_obj *contents, pdf_obj *res pdev->gstates = fz_malloc_struct(ctx, gstate); pdev->gstates[0].buf = fz_new_buffer(ctx, 256); pdev->gstates[0].ctm = *ctm; - pdev->gstates[0].colorspace[0] = fz_device_gray; - pdev->gstates[0].colorspace[1] = fz_device_gray; + pdev->gstates[0].colorspace[0] = fz_device_gray(ctx); + pdev->gstates[0].colorspace[1] = fz_device_gray(ctx); pdev->gstates[0].color[0][0] = 1; pdev->gstates[0].color[1][0] = 1; pdev->gstates[0].alpha[0] = 1.0; diff --git a/pdf/pdf_interpret.c b/pdf/pdf_interpret.c index 2a50116e..b6821d27 100644 --- a/pdf/pdf_interpret.c +++ b/pdf/pdf_interpret.c @@ -969,7 +969,7 @@ pdf_init_gstate(fz_context *ctx, pdf_gstate *gs, const fz_matrix *ctm) gs->stroke_state = fz_new_stroke_state(ctx); gs->stroke.kind = PDF_MAT_COLOR; - gs->stroke.colorspace = fz_device_gray; /* No fz_keep_colorspace as static */ + gs->stroke.colorspace = fz_device_gray(ctx); /* No fz_keep_colorspace as static */ gs->stroke.v[0] = 0; gs->stroke.pattern = NULL; gs->stroke.shade = NULL; @@ -977,7 +977,7 @@ pdf_init_gstate(fz_context *ctx, pdf_gstate *gs, const fz_matrix *ctm) gs->stroke.gstate_num = -1; gs->fill.kind = PDF_MAT_COLOR; - gs->fill.colorspace = fz_device_gray; /* No fz_keep_colorspace as static */ + gs->fill.colorspace = fz_device_gray(ctx); /* No fz_keep_colorspace as static */ gs->fill.v[0] = 0; gs->fill.pattern = NULL; gs->fill.shade = NULL; @@ -1697,7 +1697,7 @@ pdf_run_extgstate(pdf_csi *csi, pdf_obj *rdb, pdf_obj *extgstate) colorspace = xobj->colorspace; if (!colorspace) - colorspace = fz_device_gray; + colorspace = fz_device_gray(ctx); /* The softmask_ctm no longer has the softmask matrix rolled into it, as this * causes the softmask matrix to be applied twice. */ @@ -1869,11 +1869,11 @@ static void pdf_run_cs_imp(pdf_csi *csi, pdf_obj *rdb, int what) else { if (!strcmp(csi->name, "DeviceGray")) - colorspace = fz_device_gray; /* No fz_keep_colorspace as static */ + colorspace = fz_device_gray(ctx); /* No fz_keep_colorspace as static */ else if (!strcmp(csi->name, "DeviceRGB")) - colorspace = fz_device_rgb; /* No fz_keep_colorspace as static */ + colorspace = fz_device_rgb(ctx); /* No fz_keep_colorspace as static */ else if (!strcmp(csi->name, "DeviceCMYK")) - colorspace = fz_device_cmyk; /* No fz_keep_colorspace as static */ + colorspace = fz_device_cmyk(ctx); /* No fz_keep_colorspace as static */ else { dict = pdf_dict_gets(rdb, "ColorSpace"); @@ -2016,7 +2016,7 @@ static void pdf_run_F(pdf_csi *csi) static void pdf_run_G(pdf_csi *csi) { csi->dev->flags &= ~FZ_DEVFLAG_STROKECOLOR_UNDEFINED; - pdf_set_colorspace(csi, PDF_STROKE, fz_device_gray); + pdf_set_colorspace(csi, PDF_STROKE, fz_device_gray(csi->dev->ctx)); pdf_set_color(csi, PDF_STROKE, csi->stack); } @@ -2033,7 +2033,7 @@ static void pdf_run_J(pdf_csi *csi) static void pdf_run_K(pdf_csi *csi) { csi->dev->flags &= ~FZ_DEVFLAG_STROKECOLOR_UNDEFINED; - pdf_set_colorspace(csi, PDF_STROKE, fz_device_cmyk); + pdf_set_colorspace(csi, PDF_STROKE, fz_device_cmyk(csi->dev->ctx)); pdf_set_color(csi, PDF_STROKE, csi->stack); } @@ -2057,7 +2057,7 @@ static void pdf_run_Q(pdf_csi *csi) static void pdf_run_RG(pdf_csi *csi) { csi->dev->flags &= ~FZ_DEVFLAG_STROKECOLOR_UNDEFINED; - pdf_set_colorspace(csi, PDF_STROKE, fz_device_rgb); + pdf_set_colorspace(csi, PDF_STROKE, fz_device_rgb(csi->dev->ctx)); pdf_set_color(csi, PDF_STROKE, csi->stack); } @@ -2348,7 +2348,7 @@ static void pdf_run_fstar(pdf_csi *csi) static void pdf_run_g(pdf_csi *csi) { csi->dev->flags &= ~FZ_DEVFLAG_FILLCOLOR_UNDEFINED; - pdf_set_colorspace(csi, PDF_FILL, fz_device_gray); + pdf_set_colorspace(csi, PDF_FILL, fz_device_gray(csi->dev->ctx)); pdf_set_color(csi, PDF_FILL, csi->stack); } @@ -2389,7 +2389,7 @@ static void pdf_run_j(pdf_csi *csi) static void pdf_run_k(pdf_csi *csi) { csi->dev->flags &= ~FZ_DEVFLAG_FILLCOLOR_UNDEFINED; - pdf_set_colorspace(csi, PDF_FILL, fz_device_cmyk); + pdf_set_colorspace(csi, PDF_FILL, fz_device_cmyk(csi->dev->ctx)); pdf_set_color(csi, PDF_FILL, csi->stack); } @@ -2439,7 +2439,7 @@ static void pdf_run_re(pdf_csi *csi) static void pdf_run_rg(pdf_csi *csi) { csi->dev->flags &= ~FZ_DEVFLAG_FILLCOLOR_UNDEFINED; - pdf_set_colorspace(csi, PDF_FILL, fz_device_rgb); + pdf_set_colorspace(csi, PDF_FILL, fz_device_rgb(csi->dev->ctx)); pdf_set_color(csi, PDF_FILL, csi->stack); } diff --git a/xps/xps_common.c b/xps/xps_common.c index 640ea47a..f3a9ed54 100644 --- a/xps/xps_common.c +++ b/xps/xps_common.c @@ -213,7 +213,7 @@ xps_parse_color(xps_document *doc, char *base_uri, char *string, char buf[1024]; char *profile; - *csp = fz_device_rgb; + *csp = fz_device_rgb(doc->ctx); samples[0] = 1; samples[1] = 0; @@ -292,10 +292,10 @@ xps_parse_color(xps_document *doc, char *base_uri, char *string, /* TODO: load ICC profile */ switch (n) { - case 2: *csp = fz_device_gray; break; - case 4: *csp = fz_device_rgb; break; - case 5: *csp = fz_device_cmyk; break; - default: *csp = fz_device_gray; break; + case 2: *csp = fz_device_gray(doc->ctx); break; + case 4: *csp = fz_device_rgb(doc->ctx); break; + case 5: *csp = fz_device_cmyk(doc->ctx); break; + default: *csp = fz_device_gray(doc->ctx); break; } } } diff --git a/xps/xps_gradient.c b/xps/xps_gradient.c index 04438df8..3b4a2b88 100644 --- a/xps/xps_gradient.c +++ b/xps/xps_gradient.c @@ -60,7 +60,7 @@ xps_parse_gradient_stops(xps_document *doc, char *base_uri, fz_xml *node, xps_parse_color(doc, base_uri, color, &colorspace, sample); - fz_convert_color(doc->ctx, fz_device_rgb, rgb, colorspace, sample + 1); + fz_convert_color(doc->ctx, fz_device_rgb(doc->ctx), rgb, colorspace, sample + 1); stops[count].r = rgb[0]; stops[count].g = rgb[1]; @@ -213,7 +213,7 @@ xps_draw_one_radial_gradient(xps_document *doc, const fz_matrix *ctm, /* TODO: this (and the stuff in pdf_shade) should move to res_shade.c */ shade = fz_malloc_struct(doc->ctx, fz_shade); FZ_INIT_STORABLE(shade, 1, fz_free_shade_imp); - shade->colorspace = fz_device_rgb; + shade->colorspace = fz_device_rgb(doc->ctx); shade->bbox = fz_infinite_rect; shade->matrix = fz_identity; shade->use_background = 0; @@ -251,7 +251,7 @@ xps_draw_one_linear_gradient(xps_document *doc, const fz_matrix *ctm, /* TODO: this (and the stuff in pdf_shade) should move to res_shade.c */ shade = fz_malloc_struct(doc->ctx, fz_shade); FZ_INIT_STORABLE(shade, 1, fz_free_shade_imp); - shade->colorspace = fz_device_rgb; + shade->colorspace = fz_device_rgb(doc->ctx); shade->bbox = fz_infinite_rect; shade->matrix = fz_identity; shade->use_background = 0; -- cgit v1.2.3