summaryrefslogtreecommitdiff
path: root/src/main/print-weave.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/print-weave.c')
-rw-r--r--src/main/print-weave.c316
1 files changed, 183 insertions, 133 deletions
diff --git a/src/main/print-weave.c b/src/main/print-weave.c
index b7e058d..8b0213f 100644
--- a/src/main/print-weave.c
+++ b/src/main/print-weave.c
@@ -1,5 +1,5 @@
/*
- * "$Id: print-weave.c,v 1.36 2001/09/08 17:13:48 rleigh Exp $"
+ * "$Id: print-weave.c,v 1.36.4.3 2003/12/02 01:51:00 rlk Exp $"
*
* Softweave calculator for gimp-print.
*
@@ -103,8 +103,7 @@ typedef struct raw {
/*
* Strategy types currently defined:
*
- * 0: microweave (intercepted at the escp2 driver level so we never
- * see it here)
+ * 0: printer firmware weave
* 1: zig-zag type pass block filling
* 2: ascending pass block filling
* 3: descending pass block filling
@@ -952,37 +951,53 @@ stp_unpack_2_1(int length,
unsigned char *out0,
unsigned char *out1)
{
- unsigned char ti0, ti1;
- unsigned char to0, to1;
+ unsigned char tempin, bit, temp0, temp1;
if (length <= 0)
return;
+ for (bit = 128, temp0 = 0, temp1 = 0;
+ length > 0;
+ length --)
+ {
+ tempin = *in++;
+
+ if (tempin & 128)
+ temp0 |= bit;
+ if (tempin & 64)
+ temp1 |= bit;
+ bit >>= 1;
+ if (tempin & 32)
+ temp0 |= bit;
+ if (tempin & 16)
+ temp1 |= bit;
+ bit >>= 1;
+ if (tempin & 8)
+ temp0 |= bit;
+ if (tempin & 4)
+ temp1 |= bit;
+ bit >>= 1;
+ if (tempin & 2)
+ temp0 |= bit;
+ if (tempin & 1)
+ temp1 |= bit;
- length = (length + 1) / 2;
+ if (bit > 1)
+ bit >>= 1;
+ else
+ {
+ bit = 128;
+ *out0++ = temp0;
+ *out1++ = temp1;
+
+ temp0 = 0;
+ temp1 = 0;
+ }
+ }
- for (;length; length --)
+ if (bit < 128)
{
- ti0 = *in++;
- ti1 = *in++;
-
- to0 = (ti0 & 0x80) << 0;
- to1 = (ti0 & 0x40) << 1;
- to0 |= (ti0 & 0x20) << 1;
- to1 |= (ti0 & 0x10) << 2;
- to0 |= (ti0 & 0x08) << 2;
- to1 |= (ti0 & 0x04) << 3;
- to0 |= (ti0 & 0x02) << 3;
- to1 |= (ti0 & 0x01) << 4;
- to0 |= (ti1 & 0x80) >> 4;
- to1 |= (ti1 & 0x40) >> 3;
- to0 |= (ti1 & 0x20) >> 3;
- to1 |= (ti1 & 0x10) >> 2;
- to0 |= (ti1 & 0x08) >> 2;
- to1 |= (ti1 & 0x04) >> 1;
- to0 |= (ti1 & 0x02) >> 1;
- to1 |= (ti1 & 0x01) >> 0;
- *out0++ = to0;
- *out1++ = to1;
+ *out0++ = temp0;
+ *out1++ = temp1;
}
}
@@ -1046,61 +1061,57 @@ stp_unpack_4_1(int length,
unsigned char *out2,
unsigned char *out3)
{
- unsigned char ti0, ti1, ti2, ti3;
- unsigned char to0, to1, to2, to3;
+ unsigned char tempin, bit, temp0, temp1, temp2, temp3;
if (length <= 0)
return;
+ for (bit = 128, temp0 = 0, temp1 = 0, temp2 = 0, temp3 = 0;
+ length > 0;
+ length --)
+ {
+ tempin = *in++;
+
+ if (tempin & 128)
+ temp0 |= bit;
+ if (tempin & 64)
+ temp1 |= bit;
+ if (tempin & 32)
+ temp2 |= bit;
+ if (tempin & 16)
+ temp3 |= bit;
+ bit >>= 1;
+ if (tempin & 8)
+ temp0 |= bit;
+ if (tempin & 4)
+ temp1 |= bit;
+ if (tempin & 2)
+ temp2 |= bit;
+ if (tempin & 1)
+ temp3 |= bit;
- length = (length + 3) / 4;
+ if (bit > 1)
+ bit >>= 1;
+ else
+ {
+ bit = 128;
+ *out0++ = temp0;
+ *out1++ = temp1;
+ *out2++ = temp2;
+ *out3++ = temp3;
+
+ temp0 = 0;
+ temp1 = 0;
+ temp2 = 0;
+ temp3 = 0;
+ }
+ }
- for (;length; length --)
+ if (bit < 128)
{
- ti0 = *in++;
- ti1 = *in++;
- ti2 = *in++;
- ti3 = *in++;
-
- to0 = (ti0 & 0x80) << 0;
- to1 = (ti0 & 0x40) << 1;
- to2 = (ti0 & 0x20) << 2;
- to3 = (ti0 & 0x10) << 3;
- to0 |= (ti0 & 0x08) << 3;
- to1 |= (ti0 & 0x04) << 4;
- to2 |= (ti0 & 0x02) << 5;
- to3 |= (ti0 & 0x01) << 6;
-
- to0 |= (ti1 & 0x80) >> 2;
- to1 |= (ti1 & 0x40) >> 1;
- to2 |= (ti1 & 0x20) >> 0;
- to3 |= (ti1 & 0x10) << 1;
- to0 |= (ti1 & 0x08) << 1;
- to1 |= (ti1 & 0x04) << 2;
- to2 |= (ti1 & 0x02) << 3;
- to3 |= (ti1 & 0x01) << 4;
-
- to0 |= (ti2 & 0x80) >> 4;
- to1 |= (ti2 & 0x40) >> 3;
- to2 |= (ti2 & 0x20) >> 2;
- to3 |= (ti2 & 0x10) >> 1;
- to0 |= (ti2 & 0x08) >> 1;
- to1 |= (ti2 & 0x04) >> 0;
- to2 |= (ti2 & 0x02) << 1;
- to3 |= (ti2 & 0x01) << 2;
-
- to0 |= (ti3 & 0x80) >> 6;
- to1 |= (ti3 & 0x40) >> 5;
- to2 |= (ti3 & 0x20) >> 4;
- to3 |= (ti3 & 0x10) >> 3;
- to0 |= (ti3 & 0x08) >> 3;
- to1 |= (ti3 & 0x04) >> 2;
- to2 |= (ti3 & 0x02) >> 1;
- to3 |= (ti3 & 0x01) >> 0;
-
- *out0++ = to0;
- *out1++ = to1;
- *out2++ = to2;
- *out3++ = to3;
+ *out0++ = temp0;
+ *out1++ = temp1;
+ *out2++ = temp2;
+ *out3++ = temp3;
}
}
@@ -1197,6 +1208,8 @@ stp_unpack_8_1(int length,
unsigned char tempin, bit, temp0, temp1, temp2, temp3, temp4, temp5, temp6,
temp7;
+ if (length <= 0)
+ return;
for (bit = 128, temp0 = 0, temp1 = 0, temp2 = 0,
temp3 = 0, temp4 = 0, temp5 = 0, temp6 = 0, temp7 = 0;
@@ -1698,6 +1711,58 @@ stp_pack_tiff(const unsigned char *line,
* -- Robert Krawitz <rlk@alum.mit.edu) November 3, 1999
*/
+static stp_lineoff_t *
+allocate_lineoff(int count, int ncolors)
+{
+ int i;
+ stp_lineoff_t *retval = stp_malloc(count * sizeof(stp_lineoff_t));
+ for (i = 0; i < count; i++)
+ {
+ retval[i].ncolors = ncolors;
+ retval[i].v = stp_zalloc(ncolors * sizeof(unsigned long));
+ }
+ return (retval);
+}
+
+static stp_lineactive_t *
+allocate_lineactive(int count, int ncolors)
+{
+ int i;
+ stp_lineactive_t *retval = stp_malloc(count * sizeof(stp_lineactive_t));
+ for (i = 0; i < count; i++)
+ {
+ retval[i].ncolors = ncolors;
+ retval[i].v = stp_zalloc(ncolors * sizeof(char));
+ }
+ return (retval);
+}
+
+static stp_linecount_t *
+allocate_linecount(int count, int ncolors)
+{
+ int i;
+ stp_linecount_t *retval = stp_malloc(count * sizeof(stp_linecount_t));
+ for (i = 0; i < count; i++)
+ {
+ retval[i].ncolors = ncolors;
+ retval[i].v = stp_zalloc(ncolors * sizeof(int));
+ }
+ return (retval);
+}
+
+static stp_linebufs_t *
+allocate_linebuf(int count, int ncolors)
+{
+ int i;
+ stp_linebufs_t *retval = stp_malloc(count * sizeof(stp_linebufs_t));
+ for (i = 0; i < count; i++)
+ {
+ retval[i].ncolors = ncolors;
+ retval[i].v = stp_zalloc(ncolors * sizeof(unsigned char *));
+ }
+ return (retval);
+}
+
/*
* Initialize the weave parameters
*
@@ -1722,10 +1787,6 @@ stp_initialize_weave(int jets, /* Width of print head */
int width, /* bits/pixel */
int linewidth, /* Width of a line, in pixels */
int lineheight, /* Number of lines that will be printed */
- int separation_rows, /* Vertical spacing adjustment */
- /* for weird printers (1520/3000, */
- /* although they don't seem to do softweave */
- /* anyway) */
int first_line, /* First line that will be printed on page */
int phys_lines, /* Total height of the page in rows */
int weave_strategy, /* Which weaving pattern to use */
@@ -1746,9 +1807,8 @@ stp_initialize_weave(int jets, /* Width of print head */
{
int i;
int last_line, maxHeadOffset;
- stp_softweave_t *sw = stp_malloc(sizeof (stp_softweave_t));
+ stp_softweave_t *sw = stp_zalloc(sizeof (stp_softweave_t));
- (void) memset(sw, 0, sizeof(stp_softweave_t));
if (jets < 1)
jets = 1;
if (jets == 1 || sep < 1)
@@ -1765,23 +1825,27 @@ stp_initialize_weave(int jets, /* Width of print head */
sw->oversample = osample * v_subpasses * v_subsample;
if (sw->oversample > jets)
{
+ int found = 0;
for (i = 2; i <= osample; i++)
{
if ((osample % i == 0) && (sw->oversample / i <= jets))
{
sw->repeat_count = i;
osample /= i;
- goto found;
+ found = 1;
+ break;
}
}
- stp_eprintf(v, "Weave error: oversample (%d) > jets (%d)\n",
- sw->oversample, jets);
- stp_free(sw);
- return 0;
+ if (!found)
+ {
+ stp_eprintf(v, "Weave error: oversample (%d) > jets (%d)\n",
+ sw->oversample, jets);
+ stp_free(sw);
+ return 0;
+ }
}
else
sw->repeat_count = 1;
- found:
sw->vertical_oversample = v_subsample;
sw->vertical_subpasses = v_subpasses;
@@ -1802,16 +1866,14 @@ stp_initialize_weave(int jets, /* Width of print head */
* setup printhead offsets.
* for monochrome (bw) printing, the offsets are 0.
*/
- if(ncolors > 1)
- for(i=0; i<NCHANNELS; i++)
+ sw->head_offset = stp_zalloc(ncolors * sizeof(int));
+ if (ncolors > 1)
+ for(i = 0; i < ncolors; i++)
sw->head_offset[i] = head_offset[i];
- else
- for(i=0; i<NCHANNELS; i++)
- sw->head_offset[i] = 0;
maxHeadOffset = 0;
- for(i=0; i<NCHANNELS; i++)
- if(sw->head_offset[i] > maxHeadOffset)
+ for (i = 0; i < ncolors; i++)
+ if (sw->head_offset[i] > maxHeadOffset)
maxHeadOffset = sw->head_offset[i];
sw->virtual_jets = sw->jets;
@@ -1832,31 +1894,19 @@ stp_initialize_weave(int jets, /* Width of print head */
sw->vmod = 2 * sw->separation * sw->oversample * sw->repeat_count;
if (sw->virtual_jets > sw->jets)
sw->vmod *= (sw->virtual_jets + sw->jets - 1) / sw->jets;
- sw->separation_rows = separation_rows;
sw->bitwidth = width;
sw->last_pass_offset = 0;
sw->last_pass = -1;
sw->current_vertical_subpass = 0;
- sw->last_color = -1;
sw->ncolors = ncolors;
-
- /*
- * It's possible for the "compression" to actually expand the line by
- * one part in 128.
- */
-
sw->linewidth = linewidth;
sw->vertical_height = lineheight;
- sw->lineoffsets = stp_malloc(sw->vmod * sizeof(stp_lineoff_t));
- memset(sw->lineoffsets, 0, sw->vmod * sizeof(stp_lineoff_t));
- sw->lineactive = stp_malloc(sw->vmod * sizeof(stp_lineactive_t));
- memset(sw->lineactive, 0, sw->vmod * sizeof(stp_lineactive_t));
- sw->linebases = stp_malloc(sw->vmod * sizeof(stp_linebufs_t));
- sw->passes = stp_malloc(sw->vmod * sizeof(stp_pass_t));
- memset(sw->passes, 0, sw->vmod * sizeof(stp_pass_t));
- sw->linecounts = stp_malloc(sw->vmod * sizeof(stp_linecount_t));
- memset(sw->linecounts, 0, sw->vmod * sizeof(stp_linecount_t));
+ sw->lineoffsets = allocate_lineoff(sw->vmod, ncolors);
+ sw->lineactive = allocate_lineactive(sw->vmod, ncolors);
+ sw->linebases = allocate_linebuf(sw->vmod, ncolors);
+ sw->passes = stp_zalloc(sw->vmod * sizeof(stp_pass_t));
+ sw->linecounts = allocate_linecount(sw->vmod, ncolors);
sw->rcache = -2;
sw->vcache = -2;
sw->fill_start = fill_start;
@@ -1884,15 +1934,12 @@ stp_destroy_weave(void *vsw)
{
int i, j;
stp_softweave_t *sw = (stp_softweave_t *) vsw;
- stp_free(sw->linecounts);
stp_free(sw->passes);
- stp_free(sw->lineactive);
- stp_free(sw->lineoffsets);
if (sw->fold_buf)
stp_free(sw->fold_buf);
if (sw->comp_buf)
stp_free(sw->comp_buf);
- for (i = 0; i < 8; i++)
+ for (i = 0; i < MAX_WEAVE; i++)
if (sw->s[i])
stp_free(sw->s[i]);
for (i = 0; i < sw->vmod; i++)
@@ -1902,8 +1949,16 @@ stp_destroy_weave(void *vsw)
if (sw->linebases[i].v[j])
stp_free(sw->linebases[i].v[j]);
}
+ stp_free(sw->linecounts[i].v);
+ stp_free(sw->linebases[i].v);
+ stp_free(sw->lineactive[i].v);
+ stp_free(sw->lineoffsets[i].v);
}
+ stp_free(sw->linecounts);
+ stp_free(sw->lineactive);
+ stp_free(sw->lineoffsets);
stp_free(sw->linebases);
+ stp_free(sw->head_offset);
stp_destroy_weave_params(sw->weaveparm);
stp_free(vsw);
}
@@ -2029,10 +2084,10 @@ check_linebases(stp_softweave_t *sw, int row, int cpass, int head_offset,
int color)
{
stp_linebufs_t *bufs =
- (stp_linebufs_t *)stp_get_linebases(sw, row, cpass, head_offset);
+ (stp_linebufs_t *) stp_get_linebases(sw, row, cpass, head_offset);
if (!(bufs[0].v[color]))
bufs[0].v[color] =
- stp_malloc(sw->virtual_jets * sw->bitwidth * sw->horizontal_width);
+ stp_zalloc (sw->virtual_jets * sw->bitwidth * sw->horizontal_width);
}
/*
@@ -2111,6 +2166,10 @@ stp_fill_uncompressed(stp_softweave_t *sw, int row, int subpass,
int
stp_compute_tiff_linewidth(const stp_softweave_t *sw, int n)
{
+ /*
+ * It's possible for the "compression" to actually expand the line by
+ * roughly one part in 128.
+ */
return ((n + 128 + 7) * 129 / 128);
}
@@ -2122,7 +2181,7 @@ stp_compute_uncompressed_linewidth(const stp_softweave_t *sw, int n)
static void
initialize_row(stp_softweave_t *sw, int row, int width,
- const unsigned char *cols[])
+ unsigned char *const cols[])
{
stp_weave_t w;
int i, j, jj;
@@ -2268,15 +2327,6 @@ finalize_row(stp_softweave_t *sw, int row, int model, int width,
}
}
-static void *
-xzmalloc(size_t bytes)
-{
- void *retval = stp_malloc(bytes);
- if (retval)
- memset(retval, 0, bytes);
- return (retval);
-}
-
void
stp_write_weave(void * vsw,
int length, /* I - Length of bitmap data */
@@ -2286,7 +2336,7 @@ stp_write_weave(void * vsw,
int offset, /* I - Offset from left side of page */
int xdpi,
int physical_xdpi,
- const unsigned char *cols[])
+ unsigned char *const cols[])
{
stp_softweave_t *sw = (stp_softweave_t *) vsw;
stp_lineoff_t *lineoffs[8];
@@ -2302,9 +2352,9 @@ stp_write_weave(void * vsw,
int cpass = sw->current_vertical_subpass * h_passes;
if (!sw->fold_buf)
- sw->fold_buf = xzmalloc(sw->bitwidth * ylength);
+ sw->fold_buf = stp_zalloc(sw->bitwidth * ylength);
if (!sw->comp_buf)
- sw->comp_buf = xzmalloc(sw->bitwidth *(sw->compute_linewidth)(sw,ylength));
+ sw->comp_buf = stp_zalloc(sw->bitwidth *(sw->compute_linewidth)(sw,ylength));
if (sw->current_vertical_subpass == 0)
initialize_row(sw, sw->lineno, xlength, cols);
@@ -2317,7 +2367,7 @@ stp_write_weave(void * vsw,
for (i = 0; i < h_passes; i++)
{
if (!sw->s[i])
- sw->s[i] = xzmalloc(sw->bitwidth *
+ sw->s[i] = stp_zalloc(sw->bitwidth *
(sw->compute_linewidth)(sw, ylength));
lineoffs[i] = stp_get_lineoffsets(sw, sw->lineno, cpass + i,
sw->head_offset[j]);