summaryrefslogtreecommitdiff
path: root/gs/base/gshtx.c
diff options
context:
space:
mode:
Diffstat (limited to 'gs/base/gshtx.c')
-rw-r--r--gs/base/gshtx.c443
1 files changed, 220 insertions, 223 deletions
diff --git a/gs/base/gshtx.c b/gs/base/gshtx.c
index ae767c2cc..0199bb2e9 100644
--- a/gs/base/gshtx.c
+++ b/gs/base/gshtx.c
@@ -1,6 +1,6 @@
/* Copyright (C) 2001-2006 Artifex Software, Inc.
All Rights Reserved.
-
+
This software is provided AS-IS with no warranty, either express or
implied.
@@ -28,9 +28,9 @@
*/
static void
free_comps(
- gs_memory_t * pmem,
- void *pvht,
- client_name_t cname
+ gs_memory_t * pmem,
+ void *pvht,
+ client_name_t cname
)
{
gs_ht *pht = (gs_ht *) pvht;
@@ -45,23 +45,22 @@ free_comps(
*/
static float
null_closure_transfer(
- floatp val,
- const gx_transfer_map * pmap_dummy, /* NOTUSED */
- const void *dummy /* NOTUSED */
+ floatp val,
+ const gx_transfer_map * pmap_dummy, /* NOTUSED */
+ const void *dummy /* NOTUSED */
)
{
return val;
}
-
/*
* Build a gs_ht halftone structure.
*/
int
gs_ht_build(
- gs_ht ** ppht,
- uint num_comps,
- gs_memory_t * pmem
+ gs_ht ** ppht,
+ uint num_comps,
+ gs_memory_t * pmem
)
{
gs_ht *pht;
@@ -71,25 +70,25 @@ gs_ht_build(
/* must have at least one component */
*ppht = 0;
if (num_comps == 0)
- return_error(gs_error_rangecheck);
+ return_error(gs_error_rangecheck);
/* allocate the halftone and the array of components */
rc_alloc_struct_1(pht,
- gs_ht,
- &st_gs_ht,
- pmem,
- return_error(gs_error_VMerror),
- "gs_ht_build"
- );
+ gs_ht,
+ &st_gs_ht,
+ pmem,
+ return_error(gs_error_VMerror),
+ "gs_ht_build"
+ );
phtc = gs_alloc_struct_array(pmem,
- num_comps,
- gs_ht_component,
- &st_ht_comp_element,
- "gs_ht_build"
- );
+ num_comps,
+ gs_ht_component,
+ &st_ht_comp_element,
+ "gs_ht_build"
+ );
if (phtc == 0) {
- gs_free_object(pmem, pht, "gs_ht_build");
- return_error(gs_error_VMerror);
+ gs_free_object(pmem, pht, "gs_ht_build");
+ return_error(gs_error_VMerror);
}
/* initialize the halftone */
pht->type = ht_type_multiple;
@@ -99,8 +98,8 @@ gs_ht_build(
for (i = 0; i < num_comps; i++) {
phtc[i].comp_number = i;
- phtc[i].cname = 0;
- phtc[i].type = ht_type_none;
+ phtc[i].cname = 0;
+ phtc[i].type = ht_type_none;
}
*ppht = pht;
@@ -113,22 +112,22 @@ gs_ht_build(
*/
int
gs_ht_set_spot_comp(
- gs_ht * pht,
- int comp,
- floatp freq,
- floatp angle,
- float (*spot_func) (floatp, floatp),
- bool accurate,
- gs_ht_transfer_proc transfer,
- const void *client_data
+ gs_ht * pht,
+ int comp,
+ floatp freq,
+ floatp angle,
+ float (*spot_func) (floatp, floatp),
+ bool accurate,
+ gs_ht_transfer_proc transfer,
+ const void *client_data
)
{
gs_ht_component *phtc = &(pht->params.ht_multiple.components[comp]);
if (comp >= pht->params.ht_multiple.num_comp)
- return_error(gs_error_rangecheck);
+ return_error(gs_error_rangecheck);
if (phtc->type != ht_type_none)
- return_error(gs_error_invalidaccess);
+ return_error(gs_error_invalidaccess);
phtc->type = ht_type_spot;
phtc->params.ht_spot.screen.frequency = freq;
@@ -138,7 +137,7 @@ gs_ht_set_spot_comp(
phtc->params.ht_spot.transfer = gs_mapped_transfer;
phtc->params.ht_spot.transfer_closure.proc =
- (transfer == 0 ? null_closure_transfer : transfer);
+ (transfer == 0 ? null_closure_transfer : transfer);
phtc->params.ht_spot.transfer_closure.data = client_data;
return 0;
@@ -150,21 +149,21 @@ gs_ht_set_spot_comp(
*/
int
gs_ht_set_threshold_comp(
- gs_ht * pht,
- int comp,
- int width,
- int height,
- const gs_const_string * thresholds,
- gs_ht_transfer_proc transfer,
- const void *client_data
+ gs_ht * pht,
+ int comp,
+ int width,
+ int height,
+ const gs_const_string * thresholds,
+ gs_ht_transfer_proc transfer,
+ const void *client_data
)
{
gs_ht_component *phtc = &(pht->params.ht_multiple.components[comp]);
if (comp >= pht->params.ht_multiple.num_comp)
- return_error(gs_error_rangecheck);
+ return_error(gs_error_rangecheck);
if (phtc->type != ht_type_none)
- return_error(gs_error_invalidaccess);
+ return_error(gs_error_invalidaccess);
phtc->type = ht_type_threshold;
phtc->params.ht_threshold.width = width;
@@ -173,7 +172,7 @@ gs_ht_set_threshold_comp(
phtc->params.ht_threshold.transfer = gs_mapped_transfer;
phtc->params.ht_threshold.transfer_closure.proc =
- (transfer == 0 ? null_closure_transfer : transfer);
+ (transfer == 0 ? null_closure_transfer : transfer);
phtc->params.ht_threshold.transfer_closure.data = client_data;
return 0;
@@ -184,7 +183,7 @@ gs_ht_set_threshold_comp(
*/
void
gs_ht_reference(
- gs_ht * pht
+ gs_ht * pht
)
{
rc_increment(pht);
@@ -196,30 +195,29 @@ gs_ht_reference(
*/
void
gs_ht_release(
- gs_ht * pht
+ gs_ht * pht
)
{
rc_decrement_only(pht, "gs_ht_release");
}
-
/*
* Verify that a gs_ht halftone is legitimate.
*/
static int
check_ht(
- gs_ht * pht
+ gs_ht * pht
)
{
int i;
int num_comps = pht->params.ht_multiple.num_comp;
if (pht->type != ht_type_multiple)
- return_error(gs_error_unregistered);
+ return_error(gs_error_unregistered);
for (i = 0; i < num_comps; i++) {
- gs_ht_component *phtc = &(pht->params.ht_multiple.components[i]);
- if ((phtc->type != ht_type_spot) && (phtc->type != ht_type_threshold))
- return_error(gs_error_unregistered);
+ gs_ht_component *phtc = &(pht->params.ht_multiple.components[i]);
+ if ((phtc->type != ht_type_spot) && (phtc->type != ht_type_threshold))
+ return_error(gs_error_unregistered);
}
return 0;
}
@@ -229,8 +227,8 @@ check_ht(
*/
static void
build_transfer_map(
- gs_ht_component * phtc,
- gx_transfer_map * pmap
+ gs_ht_component * phtc,
+ gx_transfer_map * pmap
)
{
gs_ht_transfer_proc proc;
@@ -239,20 +237,20 @@ build_transfer_map(
frac *values = pmap->values;
if (phtc->type == ht_type_spot) {
- proc = phtc->params.ht_spot.transfer_closure.proc;
- client_info = phtc->params.ht_spot.transfer_closure.data;
+ proc = phtc->params.ht_spot.transfer_closure.proc;
+ client_info = phtc->params.ht_spot.transfer_closure.data;
} else {
- proc = phtc->params.ht_threshold.transfer_closure.proc;
- client_info = phtc->params.ht_threshold.transfer_closure.data;
+ proc = phtc->params.ht_threshold.transfer_closure.proc;
+ client_info = phtc->params.ht_threshold.transfer_closure.data;
}
for (i = 0; i < transfer_map_size; i++) {
- float fval =
- proc(i * (1 / (double)(transfer_map_size - 1)), pmap, client_info);
+ float fval =
+ proc(i * (1 / (double)(transfer_map_size - 1)), pmap, client_info);
- values[i] =
- (fval <= 0.0 ? frac_0 : fval >= 1.0 ? frac_1 :
- float2frac(fval));
+ values[i] =
+ (fval <= 0.0 ? frac_0 : fval >= 1.0 ? frac_1 :
+ float2frac(fval));
}
}
@@ -263,51 +261,51 @@ build_transfer_map(
*/
static gx_ht_order_component *
alloc_ht_order(
- const gs_ht * pht,
- gs_memory_t * pmem,
- byte * comp2order
+ const gs_ht * pht,
+ gs_memory_t * pmem,
+ byte * comp2order
)
{
int num_comps = pht->params.ht_multiple.num_comp;
gx_ht_order_component *pocs = gs_alloc_struct_array(
- pmem,
- pht->params.ht_multiple.num_comp,
- gx_ht_order_component,
- &st_ht_order_component_element,
- "alloc_ht_order"
+ pmem,
+ pht->params.ht_multiple.num_comp,
+ gx_ht_order_component,
+ &st_ht_order_component_element,
+ "alloc_ht_order"
);
int inext = 0;
int i;
if (pocs == 0)
- return 0;
+ return 0;
pocs->corder.transfer = 0;
for (i = 0; i < num_comps; i++) {
- gs_ht_component *phtc = &(pht->params.ht_multiple.components[i]);
- gx_transfer_map *pmap = gs_alloc_struct(pmem,
- gx_transfer_map,
- &st_transfer_map,
- "alloc_ht_order"
- );
-
- if (pmap == 0) {
- int j;
-
- for (j = 0; j < inext; j++)
- gs_free_object(pmem, pocs[j].corder.transfer, "alloc_ht_order");
- gs_free_object(pmem, pocs, "alloc_ht_order");
- return 0;
- }
- pmap->proc = gs_mapped_transfer;
- pmap->id = gs_next_ids(pmem, 1);
- pocs[inext].corder.levels = 0;
- pocs[inext].corder.bit_data = 0;
- pocs[inext].corder.cache = 0;
- pocs[inext].corder.transfer = pmap;
- pocs[inext].cname = phtc->cname;
+ gs_ht_component *phtc = &(pht->params.ht_multiple.components[i]);
+ gx_transfer_map *pmap = gs_alloc_struct(pmem,
+ gx_transfer_map,
+ &st_transfer_map,
+ "alloc_ht_order"
+ );
+
+ if (pmap == 0) {
+ int j;
+
+ for (j = 0; j < inext; j++)
+ gs_free_object(pmem, pocs[j].corder.transfer, "alloc_ht_order");
+ gs_free_object(pmem, pocs, "alloc_ht_order");
+ return 0;
+ }
+ pmap->proc = gs_mapped_transfer;
+ pmap->id = gs_next_ids(pmem, 1);
+ pocs[inext].corder.levels = 0;
+ pocs[inext].corder.bit_data = 0;
+ pocs[inext].corder.cache = 0;
+ pocs[inext].corder.transfer = pmap;
+ pocs[inext].cname = phtc->cname;
pocs[inext].comp_number = phtc->comp_number;
- comp2order[i] = inext++;
+ comp2order[i] = inext++;
}
return pocs;
@@ -318,56 +316,56 @@ alloc_ht_order(
*/
static int
build_component(
- gs_ht_component * phtc,
- gx_ht_order * porder,
- gs_state * pgs,
- gs_memory_t * pmem
+ gs_ht_component * phtc,
+ gx_ht_order * porder,
+ gs_state * pgs,
+ gs_memory_t * pmem
)
{
if (phtc->type == ht_type_spot) {
- gs_screen_enum senum;
- int code;
-
- code = gx_ht_process_screen_memory(&senum,
- pgs,
- &phtc->params.ht_spot.screen,
- phtc->params.ht_spot.accurate_screens,
- pmem
- );
- if (code < 0)
- return code;
-
- /* avoid wiping out the transfer structure pointer */
- senum.order.transfer = porder->transfer;
- *porder = senum.order;
+ gs_screen_enum senum;
+ int code;
+
+ code = gx_ht_process_screen_memory(&senum,
+ pgs,
+ &phtc->params.ht_spot.screen,
+ phtc->params.ht_spot.accurate_screens,
+ pmem
+ );
+ if (code < 0)
+ return code;
+
+ /* avoid wiping out the transfer structure pointer */
+ senum.order.transfer = porder->transfer;
+ *porder = senum.order;
} else { /* ht_type_threshold */
- int code;
- gx_transfer_map *transfer = porder->transfer;
-
- porder->params.M = phtc->params.ht_threshold.width;
- porder->params.N = 0;
- porder->params.R = 1;
- porder->params.M1 = phtc->params.ht_threshold.height;
- porder->params.N1 = 0;
- porder->params.R1 = 1;
- code = gx_ht_alloc_threshold_order(porder,
- phtc->params.ht_threshold.width,
- phtc->params.ht_threshold.height,
- 256,
- pmem
- );
- if (code < 0)
- return code;
- gx_ht_construct_threshold_order(
- porder,
- phtc->params.ht_threshold.thresholds.data
- );
- /*
- * gx_ht_construct_threshold_order wipes out transfer map pointer,
- * restore it here.
- */
- porder->transfer = transfer;
+ int code;
+ gx_transfer_map *transfer = porder->transfer;
+
+ porder->params.M = phtc->params.ht_threshold.width;
+ porder->params.N = 0;
+ porder->params.R = 1;
+ porder->params.M1 = phtc->params.ht_threshold.height;
+ porder->params.N1 = 0;
+ porder->params.R1 = 1;
+ code = gx_ht_alloc_threshold_order(porder,
+ phtc->params.ht_threshold.width,
+ phtc->params.ht_threshold.height,
+ 256,
+ pmem
+ );
+ if (code < 0)
+ return code;
+ gx_ht_construct_threshold_order(
+ porder,
+ phtc->params.ht_threshold.thresholds.data
+ );
+ /*
+ * gx_ht_construct_threshold_order wipes out transfer map pointer,
+ * restore it here.
+ */
+ porder->transfer = transfer;
}
build_transfer_map(phtc, porder->transfer);
@@ -379,26 +377,25 @@ build_component(
*/
static void
free_order_array(
- gx_ht_order_component * pocs,
- int num_comps,
- gs_memory_t * pmem
+ gx_ht_order_component * pocs,
+ int num_comps,
+ gs_memory_t * pmem
)
{
int i;
for (i = 0; i < num_comps; i++)
- gx_ht_order_release(&(pocs[i].corder), pmem, true);
+ gx_ht_order_release(&(pocs[i].corder), pmem, true);
gs_free_object(pmem, pocs, "gs_ht_install");
}
-
/*
* Install a gs_ht halftone as the current halftone in the graphic state.
*/
int
gs_ht_install(
- gs_state * pgs,
- gs_ht * pht
+ gs_state * pgs,
+ gs_ht * pht
)
{
int code = 0;
@@ -411,57 +408,57 @@ gs_ht_install(
/* perform so sanity checks (must have one default component) */
if ((code = check_ht(pht)) != 0)
- return code;
+ return code;
/* allocate the halftone order structure and transfer maps */
if ((pocs = alloc_ht_order(pht, pmem, comp2order)) == 0)
- return_error(gs_error_VMerror);
+ return_error(gs_error_VMerror);
/* build all of the order for each component */
for (i = 0; i < num_comps; i++) {
- int j = comp2order[i];
-
- code = build_component(&(pht->params.ht_multiple.components[i]),
- &(pocs[j].corder),
- pgs,
- pmem
- );
-
- if ((code >= 0) && (j != 0)) {
- gx_ht_cache *pcache;
-
- pcache = gx_ht_alloc_cache(pmem,
- 4,
- pocs[j].corder.raster *
- (pocs[j].corder.num_bits /
- pocs[j].corder.width) * 4
- );
-
- if (pcache == 0)
- code = gs_note_error(gs_error_VMerror);
- else {
- pocs[j].corder.cache = pcache;
- gx_ht_init_cache(pmem, pcache, &(pocs[j].corder));
- }
- }
- if (code < 0)
- break;
+ int j = comp2order[i];
+
+ code = build_component(&(pht->params.ht_multiple.components[i]),
+ &(pocs[j].corder),
+ pgs,
+ pmem
+ );
+
+ if ((code >= 0) && (j != 0)) {
+ gx_ht_cache *pcache;
+
+ pcache = gx_ht_alloc_cache(pmem,
+ 4,
+ pocs[j].corder.raster *
+ (pocs[j].corder.num_bits /
+ pocs[j].corder.width) * 4
+ );
+
+ if (pcache == 0)
+ code = gs_note_error(gs_error_VMerror);
+ else {
+ pocs[j].corder.cache = pcache;
+ gx_ht_init_cache(pmem, pcache, &(pocs[j].corder));
+ }
+ }
+ if (code < 0)
+ break;
}
if (code < 0) {
- free_order_array(pocs, num_comps, pmem);
- return code;
+ free_order_array(pocs, num_comps, pmem);
+ return code;
}
/* initialize the device halftone structure */
dev_ht.rc.memory = pmem;
dev_ht.order = pocs[0].corder; /* Default */
if (num_comps == 1) {
- /* we have only a Default; we don't need components. */
- gs_free_object(pmem, pocs, "gs_ht_install");
- dev_ht.components = 0;
+ /* we have only a Default; we don't need components. */
+ gs_free_object(pmem, pocs, "gs_ht_install");
+ dev_ht.components = 0;
} else {
- dev_ht.components = pocs;
- dev_ht.num_comp = num_comps;
+ dev_ht.components = pocs;
+ dev_ht.num_comp = num_comps;
}
/* at last, actually install the halftone in the graphic state */
@@ -479,7 +476,7 @@ gs_ht_install(
*/
static int
create_mask_bits(const byte * mask1, const byte * mask2,
- int width, int height, gx_ht_bit * bits)
+ int width, int height, gx_ht_bit * bits)
{
/*
* We do this with the slowest, simplest possible algorithm....
@@ -489,22 +486,22 @@ create_mask_bits(const byte * mask1, const byte * mask2,
int count = 0;
for (y = 0; y < height; ++y)
- for (x = 0; x < width; ++x) {
- int offset = y * width_bytes + (x >> 3);
- byte bit_mask = 0x80 >> (x & 7);
-
- if ((mask1[offset] ^ mask2[offset]) & bit_mask) {
- if (bits)
- gx_ht_construct_bit(&bits[count], width, y * width + x);
- ++count;
- }
- }
+ for (x = 0; x < width; ++x) {
+ int offset = y * width_bytes + (x >> 3);
+ byte bit_mask = 0x80 >> (x & 7);
+
+ if ((mask1[offset] ^ mask2[offset]) & bit_mask) {
+ if (bits)
+ gx_ht_construct_bit(&bits[count], width, y * width + x);
+ ++count;
+ }
+ }
return count;
}
static int
create_mask_order(gx_ht_order * porder, gs_state * pgs,
- const gs_client_order_halftone * phcop,
- gs_memory_t * mem)
+ const gs_client_order_halftone * phcop,
+ gs_memory_t * mem)
{
int width_bytes = (phcop->width + 7) >> 3;
const byte *masks = (const byte *)phcop->client_data;
@@ -517,25 +514,25 @@ create_mask_order(gx_ht_order * porder, gs_state * pgs,
/* Do a first pass to compute how many bits entries will be needed. */
for (prev_mask = masks, num_bits = 0, i = 0;
- i < num_levels - 1;
- ++i, prev_mask += bytes_per_mask
- )
- num_bits += create_mask_bits(prev_mask, prev_mask + bytes_per_mask,
- phcop->width, phcop->height, NULL);
+ i < num_levels - 1;
+ ++i, prev_mask += bytes_per_mask
+ )
+ num_bits += create_mask_bits(prev_mask, prev_mask + bytes_per_mask,
+ phcop->width, phcop->height, NULL);
code = gx_ht_alloc_client_order(porder, phcop->width, phcop->height,
- num_levels, num_bits, mem);
+ num_levels, num_bits, mem);
if (code < 0)
- return code;
+ return code;
/* Fill in the bits and levels entries. */
for (prev_mask = masks, num_bits = 0, i = 0;
- i < num_levels - 1;
- ++i, prev_mask += bytes_per_mask
- ) {
- porder->levels[i] = num_bits;
- num_bits += create_mask_bits(prev_mask, prev_mask + bytes_per_mask,
- phcop->width, phcop->height,
- ((gx_ht_bit *)porder->bit_data) +
- num_bits);
+ i < num_levels - 1;
+ ++i, prev_mask += bytes_per_mask
+ ) {
+ porder->levels[i] = num_bits;
+ num_bits += create_mask_bits(prev_mask, prev_mask + bytes_per_mask,
+ phcop->width, phcop->height,
+ ((gx_ht_bit *)porder->bit_data) +
+ num_bits);
}
porder->levels[num_levels - 1] = num_bits;
return 0;
@@ -554,19 +551,19 @@ static const gs_client_order_ht_procs_t mask_order_procs =
*/
int
gs_ht_set_mask_comp(gs_ht * pht,
- int component_index,
- int width, int height, int num_levels,
- const byte * masks, /* width x height x num_levels bits */
- gs_ht_transfer_proc transfer,
- const void *client_data)
+ int component_index,
+ int width, int height, int num_levels,
+ const byte * masks, /* width x height x num_levels bits */
+ gs_ht_transfer_proc transfer,
+ const void *client_data)
{
gs_ht_component *phtc =
&(pht->params.ht_multiple.components[component_index]);
if (component_index >= pht->params.ht_multiple.num_comp)
- return_error(gs_error_rangecheck);
+ return_error(gs_error_rangecheck);
if (phtc->type != ht_type_none)
- return_error(gs_error_invalidaccess);
+ return_error(gs_error_invalidaccess);
phtc->type = ht_type_client_order;
phtc->params.client_order.width = width;
@@ -575,7 +572,7 @@ gs_ht_set_mask_comp(gs_ht * pht,
phtc->params.client_order.procs = &mask_order_procs;
phtc->params.client_order.client_data = masks;
phtc->params.client_order.transfer_closure.proc =
- (transfer == 0 ? null_closure_transfer : transfer);
+ (transfer == 0 ? null_closure_transfer : transfer);
phtc->params.client_order.transfer_closure.data = client_data;
return 0;