summaryrefslogtreecommitdiff
path: root/source/fitz/pixmap.c
diff options
context:
space:
mode:
Diffstat (limited to 'source/fitz/pixmap.c')
-rw-r--r--source/fitz/pixmap.c71
1 files changed, 44 insertions, 27 deletions
diff --git a/source/fitz/pixmap.c b/source/fitz/pixmap.c
index b568c842..2ac8bae5 100644
--- a/source/fitz/pixmap.c
+++ b/source/fitz/pixmap.c
@@ -23,21 +23,23 @@ fz_drop_pixmap_imp(fz_context *ctx, fz_storable *pix_)
fz_pixmap *pix = (fz_pixmap *)pix_;
fz_drop_colorspace(ctx, pix->colorspace);
- if (pix->free_samples)
+ fz_drop_separations(ctx, pix->seps);
+ if (pix->flags & FZ_PIXMAP_FLAG_FREE_SAMPLES)
fz_free(ctx, pix->samples);
fz_free(ctx, pix);
}
fz_pixmap *
-fz_new_pixmap_with_data(fz_context *ctx, fz_colorspace *colorspace, int w, int h, int alpha, int stride, unsigned char *samples)
+fz_new_pixmap_with_data(fz_context *ctx, fz_colorspace *colorspace, int w, int h, fz_separations *seps, int alpha, int stride, unsigned char *samples)
{
fz_pixmap *pix;
+ int s = fz_count_active_separations(ctx, seps);
int n;
if (w < 0 || h < 0)
fz_throw(ctx, FZ_ERROR_GENERIC, "Illegal dimensions for pixmap %d %d", w, h);
- n = alpha + fz_colorspace_n(ctx, colorspace);
+ n = alpha + s + 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)
@@ -50,11 +52,13 @@ fz_new_pixmap_with_data(fz_context *ctx, fz_colorspace *colorspace, int w, int h
pix->w = w;
pix->h = h;
pix->alpha = alpha = !!alpha;
- pix->interpolate = 1;
+ pix->flags = FZ_PIXMAP_FLAG_INTERPOLATE;
pix->xres = 96;
pix->yres = 96;
pix->colorspace = NULL;
pix->n = n;
+ pix->s = s;
+ pix->seps = fz_keep_separations(ctx, seps);
pix->stride = stride;
if (colorspace)
@@ -63,15 +67,11 @@ fz_new_pixmap_with_data(fz_context *ctx, fz_colorspace *colorspace, int w, int h
}
else
{
- assert(alpha);
+ assert(alpha || s);
}
pix->samples = samples;
- if (samples)
- {
- pix->free_samples = 0;
- }
- else
+ if (!samples)
{
fz_try(ctx)
{
@@ -85,40 +85,42 @@ fz_new_pixmap_with_data(fz_context *ctx, fz_colorspace *colorspace, int w, int h
fz_free(ctx, pix);
fz_rethrow(ctx);
}
- pix->free_samples = 1;
+ pix->flags |= FZ_PIXMAP_FLAG_FREE_SAMPLES;
}
return pix;
}
fz_pixmap *
-fz_new_pixmap(fz_context *ctx, fz_colorspace *colorspace, int w, int h, int alpha)
+fz_new_pixmap(fz_context *ctx, fz_colorspace *colorspace, int w, int h, fz_separations *seps, int alpha)
{
int stride;
- if (!colorspace) alpha = 1;
- stride = (fz_colorspace_n(ctx, colorspace) + alpha) * w;
- return fz_new_pixmap_with_data(ctx, colorspace, w, h, alpha, stride, NULL);
+ int s = fz_count_active_separations(ctx, seps);
+ if (!colorspace && s == 0) alpha = 1;
+ stride = (fz_colorspace_n(ctx, colorspace) + s + alpha) * w;
+ return fz_new_pixmap_with_data(ctx, colorspace, w, h, seps, alpha, stride, NULL);
}
fz_pixmap *
-fz_new_pixmap_with_bbox(fz_context *ctx, fz_colorspace *colorspace, const fz_irect *r, int alpha)
+fz_new_pixmap_with_bbox(fz_context *ctx, fz_colorspace *colorspace, const fz_irect *r, fz_separations *seps, int alpha)
{
fz_pixmap *pixmap;
- pixmap = fz_new_pixmap(ctx, colorspace, r->x1 - r->x0, r->y1 - r->y0, alpha);
+ pixmap = fz_new_pixmap(ctx, colorspace, r->x1 - r->x0, r->y1 - r->y0, seps, alpha);
pixmap->x = r->x0;
pixmap->y = r->y0;
return pixmap;
}
fz_pixmap *
-fz_new_pixmap_with_bbox_and_data(fz_context *ctx, fz_colorspace *colorspace, const fz_irect *r, int alpha, unsigned char *samples)
+fz_new_pixmap_with_bbox_and_data(fz_context *ctx, fz_colorspace *colorspace, const fz_irect *r, fz_separations *seps, int alpha, unsigned char *samples)
{
int w = r->x1 - r->x0;
int stride;
+ int s = fz_count_active_separations(ctx, seps);
fz_pixmap *pixmap;
- if (!colorspace) alpha = 1;
- stride = (fz_colorspace_n(ctx, colorspace) + alpha) * w;
- pixmap = fz_new_pixmap_with_data(ctx, colorspace, w, r->y1 - r->y0, alpha, stride, samples);
+ if (!colorspace && s == 0) alpha = 1;
+ stride = (fz_colorspace_n(ctx, colorspace) + s + alpha) * w;
+ pixmap = fz_new_pixmap_with_data(ctx, colorspace, w, r->y1 - r->y0, seps, alpha, stride, samples);
pixmap->x = r->x0;
pixmap->y = r->y0;
return pixmap;
@@ -185,7 +187,19 @@ fz_pixmap_components(fz_context *ctx, fz_pixmap *pix)
int
fz_pixmap_colorants(fz_context *ctx, fz_pixmap *pix)
{
- return pix->n - pix->alpha;
+ return pix->n - pix->alpha - pix->s;
+}
+
+int
+fz_pixmap_spots(fz_context *ctx, fz_pixmap *pix)
+{
+ return pix->s;
+}
+
+int
+fz_pixmap_alpha(fz_context *ctx, fz_pixmap *pix)
+{
+ return pix->alpha;
}
int
@@ -661,7 +675,7 @@ fz_alpha_from_gray(fz_context *ctx, fz_pixmap *gray)
assert(gray->n == 1);
- alpha = fz_new_pixmap_with_bbox(ctx, NULL, fz_pixmap_bbox(ctx, gray, &bbox), 1);
+ alpha = fz_new_pixmap_with_bbox(ctx, NULL, fz_pixmap_bbox(ctx, gray, &bbox), 0, 1);
dp = alpha->samples;
dstride = alpha->stride;
sp = gray->samples;
@@ -813,13 +827,16 @@ fz_convert_pixmap(fz_context *ctx, fz_pixmap *pix, fz_colorspace *ds, fz_colorsp
if (color_params == NULL)
color_params = fz_default_color_params(ctx);
- cvt = fz_new_pixmap(ctx, ds, pix->w, pix->h, keep_alpha && pix->alpha);
+ cvt = fz_new_pixmap(ctx, ds, pix->w, pix->h, pix->seps, keep_alpha && pix->alpha);
cvt->xres = pix->xres;
cvt->yres = pix->yres;
cvt->x = pix->x;
cvt->y = pix->y;
- cvt->interpolate = pix->interpolate;
+ if (pix->flags & FZ_PIXMAP_FLAG_INTERPOLATE)
+ cvt->flags |= FZ_PIXMAP_FLAG_INTERPOLATE;
+ else
+ cvt->flags &= ~FZ_PIXMAP_FLAG_INTERPOLATE;
fz_try(ctx)
{
@@ -838,7 +855,7 @@ fz_convert_pixmap(fz_context *ctx, fz_pixmap *pix, fz_colorspace *ds, fz_colorsp
fz_pixmap *
fz_new_pixmap_from_8bpp_data(fz_context *ctx, int x, int y, int w, int h, unsigned char *sp, int span)
{
- fz_pixmap *pixmap = fz_new_pixmap(ctx, NULL, w, h, 1);
+ fz_pixmap *pixmap = fz_new_pixmap(ctx, NULL, w, h, NULL, 1);
int stride = pixmap->stride;
unsigned char *s = pixmap->samples;
pixmap->x = x;
@@ -856,7 +873,7 @@ fz_new_pixmap_from_8bpp_data(fz_context *ctx, int x, int y, int w, int h, unsign
fz_pixmap *
fz_new_pixmap_from_1bpp_data(fz_context *ctx, int x, int y, int w, int h, unsigned char *sp, int span)
{
- fz_pixmap *pixmap = fz_new_pixmap(ctx, NULL, w, h, 1);
+ fz_pixmap *pixmap = fz_new_pixmap(ctx, NULL, w, h, NULL, 1);
int stride = pixmap->stride - pixmap->w;
pixmap->x = x;
pixmap->y = y;