1
/* Copyright (C) 2001-2006 Artifex Software, Inc.
4
This software is provided AS-IS with no warranty, either express or
7
This software is distributed under license and may not be copied, modified
8
or distributed except as expressly authorized under the terms of that
9
license. Refer to licensing information at http://www.artifex.com/
10
or contact Artifex Software, Inc., 7 Mt. Lassen Drive - Suite A-134,
11
San Rafael, CA 94903, U.S.A., +1(415)492-9861, for further information.
14
/* $Id: zimage3.c 8250 2007-09-25 13:31:24Z giles $ */
15
/* LanguageLevel 3 ImageTypes (3 & 4 - masked images) */
19
#include "gscspace.h" /* for gscolor2.h */
23
#include "gxiparam.h" /* for image enumerator */
30
/* <dict> .image3 - */
32
zimage3(i_ctx_t *i_ctx_p)
39
image_params ip_data, ip_mask;
43
check_type(*op, t_dictionary);
45
if ((code = dict_int_param(op, "InterleaveType", 1, 3, -1,
46
&interleave_type)) < 0
49
gs_image3_t_init(&image, NULL, interleave_type);
50
if (dict_find_string(op, "DataDict", &pDataDict) <= 0 ||
51
dict_find_string(op, "MaskDict", &pMaskDict) <= 0
53
return_error(e_rangecheck);
54
if ((code = pixel_image_params(i_ctx_p, pDataDict,
55
(gs_pixel_image_t *)&image, &ip_data,
56
12, false, gs_currentcolorspace(igs))) < 0 ||
57
(mcode = code = data_image_params(imemory, pMaskDict, &image.MaskDict,
58
&ip_mask, false, 1, 12, false)) < 0 ||
59
(code = dict_int_param(pDataDict, "ImageType", 1, 1, 0, &ignored)) < 0 ||
60
(code = dict_int_param(pMaskDict, "ImageType", 1, 1, 0, &ignored)) < 0
64
* MaskDict must have a DataSource iff InterleaveType == 3.
66
if ((ip_data.MultipleDataSources && interleave_type != 3) ||
67
ip_mask.MultipleDataSources ||
68
mcode != (image.InterleaveType != 3)
70
return_error(e_rangecheck);
71
if (image.InterleaveType == 3) {
72
/* Insert the mask DataSource before the data DataSources. */
73
memmove(&ip_data.DataSource[1], &ip_data.DataSource[0],
74
(countof(ip_data.DataSource) - 1) *
75
sizeof(ip_data.DataSource[0]));
76
ip_data.DataSource[0] = ip_mask.DataSource[0];
78
return zimage_setup(i_ctx_p, (gs_pixel_image_t *)&image,
79
&ip_data.DataSource[0],
80
image.CombineWithColor, 1);
83
/* <dict> .image4 - */
85
zimage4(i_ctx_t *i_ctx_p)
91
gs_color_space_num_components(gs_currentcolorspace(igs));
92
int colors[countof(image.MaskColor)];
96
gs_image4_t_init(&image, NULL);
97
code = pixel_image_params(i_ctx_p, op, (gs_pixel_image_t *)&image, &ip,
98
12, false, gs_currentcolorspace(igs));
101
code = dict_int_array_check_param(imemory, op, "MaskColor",
102
num_components * 2, colors, 0, e_rangecheck);
103
/* Clamp the color values to the unsigned range. */
104
if (code == num_components) {
105
image.MaskColor_is_range = false;
106
for (i = 0; i < code; ++i)
107
image.MaskColor[i] = (colors[i] < 0 ? ~(uint)0 : colors[i]);
109
else if (code == num_components * 2) {
110
image.MaskColor_is_range = true;
111
for (i = 0; i < code; i += 2) {
112
if (colors[i+1] < 0) /* no match possible */
113
image.MaskColor[i] = 1, image.MaskColor[i+1] = 0;
115
image.MaskColor[i+1] = colors[i+1];
116
image.MaskColor[i] = max(colors[i], 0);
120
return_error(code < 0 ? code : gs_note_error(e_rangecheck));
121
return zimage_setup(i_ctx_p, (gs_pixel_image_t *)&image, &ip.DataSource[0],
122
image.CombineWithColor, 1);
125
/* ------ Initialization procedure ------ */
127
const op_def zimage3_op_defs[] =
130
{"1.image3", zimage3},
131
{"1.image4", zimage4},