summaryrefslogtreecommitdiff
path: root/source/pdf
diff options
context:
space:
mode:
Diffstat (limited to 'source/pdf')
-rw-r--r--source/pdf/pdf-colorspace.c11
-rw-r--r--source/pdf/pdf-device.c15
-rw-r--r--source/pdf/pdf-image.c10
-rw-r--r--source/pdf/pdf-interpret.c2
-rw-r--r--source/pdf/pdf-op-run.c13
-rw-r--r--source/pdf/pdf-shade.c29
6 files changed, 45 insertions, 35 deletions
diff --git a/source/pdf/pdf-colorspace.c b/source/pdf/pdf-colorspace.c
index b9cb26e9..05c54b31 100644
--- a/source/pdf/pdf-colorspace.c
+++ b/source/pdf/pdf-colorspace.c
@@ -1,5 +1,7 @@
#include "mupdf/pdf.h"
+#include "../fitz/colorspace-impl.h"
+
/* ICCBased */
static fz_colorspace *
@@ -106,11 +108,8 @@ load_separation(fz_context *ctx, pdf_document *doc, pdf_obj *array)
sep->base = base;
sep->tint = tint;
- cs = fz_new_colorspace(ctx, n == 1 ? "Separation" : "DeviceN", n);
- cs->to_rgb = separation_to_rgb;
- cs->free_data = free_separation;
- cs->data = sep;
- cs->size += sizeof(struct separation) + (base ? base->size : 0) + fz_function_size(ctx, tint);
+ cs = fz_new_colorspace(ctx, n == 1 ? "Separation" : "DeviceN", n, separation_to_rgb, NULL, free_separation, sep,
+ sizeof(struct separation) + (base ? base->size : 0) + fz_function_size(ctx, tint));
}
fz_catch(ctx)
{
@@ -126,7 +125,7 @@ load_separation(fz_context *ctx, pdf_document *doc, pdf_obj *array)
int
pdf_is_tint_colorspace(fz_context *ctx, fz_colorspace *cs)
{
- return cs && cs->to_rgb == separation_to_rgb;
+ return fz_colorspace_is(ctx, cs, separation_to_rgb);
}
/* Indexed */
diff --git a/source/pdf/pdf-device.c b/source/pdf/pdf-device.c
index 30ae76b5..ccf63e42 100644
--- a/source/pdf/pdf-device.c
+++ b/source/pdf/pdf-device.c
@@ -241,6 +241,7 @@ pdf_dev_color(fz_context *ctx, pdf_device *pdev, fz_colorspace *colorspace, cons
fz_convert_color(ctx, fz_device_rgb(ctx), rgb, colorspace, color);
color = rgb;
colorspace = fz_device_rgb(ctx);
+ cspace = 3;
}
if (gs->colorspace[stroke] != colorspace)
@@ -249,7 +250,7 @@ pdf_dev_color(fz_context *ctx, pdf_device *pdev, fz_colorspace *colorspace, cons
diff = 1;
}
- for (i=0; i < colorspace->n; i++)
+ for (i=0; i < cspace; i++)
if (gs->color[stroke][i] != color[i])
{
gs->color[stroke][i] = color[i];
@@ -564,15 +565,16 @@ pdf_dev_new_form(fz_context *ctx, pdf_obj **form_ref, pdf_device *pdev, const fz
group = pdf_new_dict(ctx, doc, 5);
fz_try(ctx)
{
+ int n = fz_colorspace_n(ctx, colorspace);
pdf_dict_put_drop(ctx, group, PDF_NAME_Type, PDF_NAME_Group);
pdf_dict_put_drop(ctx, group, PDF_NAME_S, PDF_NAME_Transparency);
pdf_dict_put_drop(ctx, group, PDF_NAME_K, pdf_new_bool(ctx, doc, knockout));
pdf_dict_put_drop(ctx, group, PDF_NAME_I, pdf_new_bool(ctx, doc, isolated));
- if (!colorspace)
+ if (n == 0)
{}
- else if (colorspace->n == 1)
+ if (n == 1)
pdf_dict_put_drop(ctx, group, PDF_NAME_CS, PDF_NAME_DeviceGray);
- else if (colorspace->n == 4)
+ else if (n == 4)
pdf_dict_put_drop(ctx, group, PDF_NAME_CS, PDF_NAME_DeviceCMYK);
else
pdf_dict_put_drop(ctx, group, PDF_NAME_CS, PDF_NAME_DeviceRGB);
@@ -907,12 +909,13 @@ pdf_dev_begin_mask(fz_context *ctx, fz_device *dev, const fz_rect *bbox, int lum
fz_try(ctx)
{
+ int n = fz_colorspace_n(ctx, colorspace);
smask = pdf_new_dict(ctx, doc, 4);
pdf_dict_put_drop(ctx, smask, PDF_NAME_Type, PDF_NAME_Mask);
pdf_dict_put_drop(ctx, smask, PDF_NAME_S, (luminosity ? PDF_NAME_Luminosity : PDF_NAME_Alpha));
pdf_dict_put(ctx, smask, PDF_NAME_G, form_ref);
- color_obj = pdf_new_array(ctx, doc, colorspace->n);
- for (i = 0; i < colorspace->n; i++)
+ color_obj = pdf_new_array(ctx, doc, n);
+ for (i = 0; i < n; i++)
pdf_array_push_drop(ctx, color_obj, pdf_new_real(ctx, doc, color[i]));
pdf_dict_put_drop(ctx, smask, PDF_NAME_BC, color_obj);
color_obj = NULL;
diff --git a/source/pdf/pdf-image.c b/source/pdf/pdf-image.c
index d54de34c..fa1d7675 100644
--- a/source/pdf/pdf-image.c
+++ b/source/pdf/pdf-image.c
@@ -99,7 +99,7 @@ pdf_load_image_imp(fz_context *ctx, pdf_document *doc, pdf_obj *rdb, pdf_obj *di
colorspace = pdf_load_colorspace(ctx, doc, obj);
indexed = fz_colorspace_is_indexed(ctx, colorspace);
- n = colorspace->n;
+ n = fz_colorspace_n(ctx, colorspace);
}
else
{
@@ -296,6 +296,7 @@ pdf_add_image(fz_context *ctx, pdf_document *doc, fz_image *image, int mask)
fz_buffer *buffer = NULL;
fz_colorspace *colorspace = image->colorspace;
unsigned char digest[16];
+ int n;
/* If we can maintain compression, do so */
cbuffer = fz_compressed_image_buffer(ctx, image);
@@ -370,14 +371,15 @@ pdf_add_image(fz_context *ctx, pdf_document *doc, fz_image *image, int mask)
pdf_dict_put_drop(ctx, imobj, PDF_NAME_Subtype, PDF_NAME_Image);
pdf_dict_put_drop(ctx, imobj, PDF_NAME_Width, pdf_new_int(ctx, doc, image->w));
pdf_dict_put_drop(ctx, imobj, PDF_NAME_Height, pdf_new_int(ctx, doc, image->h));
+ n = fz_colorspace_n(ctx, colorspace);
if (mask)
{
}
- else if (!colorspace || colorspace->n == 1)
+ else if (n <= 1)
pdf_dict_put_drop(ctx, imobj, PDF_NAME_ColorSpace, PDF_NAME_DeviceGray);
- else if (colorspace->n == 3)
+ else if (n == 3)
pdf_dict_put_drop(ctx, imobj, PDF_NAME_ColorSpace, PDF_NAME_DeviceRGB);
- else if (colorspace->n == 4)
+ else if (n == 4)
pdf_dict_put_drop(ctx, imobj, PDF_NAME_ColorSpace, PDF_NAME_DeviceCMYK);
if (!mask)
pdf_dict_put_drop(ctx, imobj, PDF_NAME_BitsPerComponent, pdf_new_int(ctx, doc, image->bpc));
diff --git a/source/pdf/pdf-interpret.c b/source/pdf/pdf-interpret.c
index 0ae4844a..28a02f13 100644
--- a/source/pdf/pdf-interpret.c
+++ b/source/pdf/pdf-interpret.c
@@ -461,7 +461,7 @@ pdf_process_extgstate(fz_context *ctx, pdf_processor *proc, pdf_csi *csi, pdf_ob
colorspace = pdf_xobject_colorspace(ctx, xobj);
if (colorspace)
{
- colorspace_n = colorspace->n;
+ colorspace_n = fz_colorspace_n(ctx, colorspace);
fz_drop_colorspace(ctx, colorspace);
}
diff --git a/source/pdf/pdf-op-run.c b/source/pdf/pdf-op-run.c
index dba3e086..ff3034fe 100644
--- a/source/pdf/pdf-op-run.c
+++ b/source/pdf/pdf-op-run.c
@@ -1108,6 +1108,7 @@ pdf_set_colorspace(fz_context *ctx, pdf_run_processor *pr, int what, fz_colorspa
{
pdf_gstate *gstate = pr->gstate + pr->gtop;
pdf_material *mat;
+ int n = fz_colorspace_n(ctx, colorspace);
gstate = pdf_flush_text(ctx, pr);
@@ -1126,7 +1127,7 @@ pdf_set_colorspace(fz_context *ctx, pdf_run_processor *pr, int what, fz_colorspa
if (pdf_is_tint_colorspace(ctx, colorspace))
{
int i;
- for (i = 0; i < colorspace->n; i++)
+ for (i = 0; i < n; i++)
mat->v[i] = 1.0f;
}
}
@@ -1136,7 +1137,7 @@ pdf_set_color(fz_context *ctx, pdf_run_processor *pr, int what, float *v)
{
pdf_gstate *gstate = pr->gstate + pr->gtop;
pdf_material *mat;
- int i;
+ int i, n;
gstate = pdf_flush_text(ctx, pr);
@@ -1154,13 +1155,15 @@ pdf_set_color(fz_context *ctx, pdf_run_processor *pr, int what, float *v)
}
else if (fz_colorspace_is_lab(ctx, mat->colorspace))
{
+ n = fz_colorspace_n(ctx, mat->colorspace);
/* input is in range (0..100, -128..127, -128..127) not (0..1, 0..1, 0..1) */
- for (i = 0; i < mat->colorspace->n; i++)
+ for (i = 0; i < n; i++)
mat->v[i] = fz_clamp(v[i], i ? -128 : 0, i ? 127 : 100);
}
else
{
- for (i = 0; i < mat->colorspace->n; i++)
+ n = fz_colorspace_n(ctx, mat->colorspace);
+ for (i = 0; i < n; i++)
mat->v[i] = fz_clamp(v[i], 0, 1);
}
break;
@@ -1486,7 +1489,7 @@ static void pdf_run_gs_SMask(fz_context *ctx, pdf_processor *proc, pdf_xobject *
int cs_n = 1;
if (cs)
{
- cs_n = cs->n;
+ cs_n = fz_colorspace_n(ctx, cs);
fz_drop_colorspace(ctx, cs);
}
gstate->softmask_ctm = gstate->ctm;
diff --git a/source/pdf/pdf-shade.c b/source/pdf/pdf-shade.c
index 6e25efa8..daa2363a 100644
--- a/source/pdf/pdf-shade.c
+++ b/source/pdf/pdf-shade.c
@@ -8,14 +8,15 @@
static void
pdf_sample_composite_shade_function(fz_context *ctx, fz_shade *shade, fz_function *func, float t0, float t1)
{
- int i;
+ int i, n;
float t;
+ n = fz_colorspace_n(ctx, shade->colorspace);
for (i = 0; i < 256; i++)
{
t = t0 + (i / 255.0f) * (t1 - t0);
- fz_eval_function(ctx, func, &t, 1, shade->function[i], shade->colorspace->n);
- shade->function[i][shade->colorspace->n] = 1;
+ fz_eval_function(ctx, func, &t, 1, shade->function[i], n);
+ shade->function[i][n] = 1;
}
}
@@ -55,6 +56,7 @@ pdf_load_function_based_shading(fz_context *ctx, pdf_document *doc, fz_shade *sh
fz_matrix matrix;
int xx, yy;
float *p;
+ int n = fz_colorspace_n(ctx, shade->colorspace);
x0 = y0 = 0;
x1 = y1 = 1;
@@ -75,7 +77,7 @@ pdf_load_function_based_shading(fz_context *ctx, pdf_document *doc, fz_shade *sh
shade->u.f.matrix = matrix;
shade->u.f.xdivs = FUNSEGS;
shade->u.f.ydivs = FUNSEGS;
- shade->u.f.fn_vals = fz_malloc(ctx, (FUNSEGS+1)*(FUNSEGS+1)*shade->colorspace->n*sizeof(float));
+ shade->u.f.fn_vals = fz_malloc(ctx, (FUNSEGS+1)*(FUNSEGS+1)*n*sizeof(float));
shade->u.f.domain[0][0] = x0;
shade->u.f.domain[0][1] = y0;
shade->u.f.domain[1][0] = x1;
@@ -90,8 +92,8 @@ pdf_load_function_based_shading(fz_context *ctx, pdf_document *doc, fz_shade *sh
{
fv[0] = x0 + (x1 - x0) * xx / FUNSEGS;
- fz_eval_function(ctx, func, fv, 2, p, shade->colorspace->n);
- p += shade->colorspace->n;
+ fz_eval_function(ctx, func, fv, 2, p, n);
+ p += n;
}
}
}
@@ -307,7 +309,7 @@ pdf_load_shading_dict(fz_context *ctx, pdf_document *doc, pdf_obj *dict, const f
pdf_obj *obj;
int funcs = 0;
int type = 0;
- int i, in, out;
+ int i, in, out, n;
fz_var(shade);
fz_var(func);
@@ -335,12 +337,13 @@ pdf_load_shading_dict(fz_context *ctx, pdf_document *doc, pdf_obj *dict, const f
if (!obj)
fz_throw(ctx, FZ_ERROR_GENERIC, "shading colorspace is missing");
shade->colorspace = pdf_load_colorspace(ctx, doc, obj);
+ n = fz_colorspace_n(ctx, shade->colorspace);
obj = pdf_dict_get(ctx, dict, PDF_NAME_Background);
if (obj)
{
shade->use_background = 1;
- for (i = 0; i < shade->colorspace->n; i++)
+ for (i = 0; i < n; i++)
shade->background[i] = pdf_to_real(ctx, pdf_array_get(ctx, obj, i));
}
@@ -357,7 +360,7 @@ pdf_load_shading_dict(fz_context *ctx, pdf_document *doc, pdf_obj *dict, const f
in = 2;
else
in = 1;
- out = shade->colorspace->n;
+ out = n;
func[0] = pdf_load_function(ctx, doc, obj, in, out);
if (!func[0])
@@ -366,7 +369,7 @@ pdf_load_shading_dict(fz_context *ctx, pdf_document *doc, pdf_obj *dict, const f
else if (pdf_is_array(ctx, obj))
{
funcs = pdf_array_len(ctx, obj);
- if (funcs != 1 && funcs != shade->colorspace->n)
+ if (funcs != 1 && funcs != n)
{
funcs = 0;
fz_throw(ctx, FZ_ERROR_GENERIC, "incorrect number of shading functions");
@@ -425,12 +428,12 @@ pdf_load_shading_dict(fz_context *ctx, pdf_document *doc, pdf_obj *dict, const f
}
static size_t
-fz_shade_size(fz_shade *s)
+fz_shade_size(fz_context *ctx, fz_shade *s)
{
if (s == NULL)
return 0;
if (s->type == FZ_FUNCTION_BASED)
- return sizeof(*s) + sizeof(float) * s->u.f.xdivs * s->u.f.ydivs * s->colorspace->n;
+ return sizeof(*s) + sizeof(float) * s->u.f.xdivs * s->u.f.ydivs * fz_colorspace_n(ctx, s->colorspace);
return sizeof(*s) + fz_compressed_buffer_size(s->buffer);
}
@@ -477,7 +480,7 @@ pdf_load_shading(fz_context *ctx, pdf_document *doc, pdf_obj *dict)
shade = pdf_load_shading_dict(ctx, doc, dict, &fz_identity);
}
- pdf_store_item(ctx, dict, shade, fz_shade_size(shade));
+ pdf_store_item(ctx, dict, shade, fz_shade_size(ctx, shade));
return shade;
}