|
0 |
/***********************************************************************
|
|
1 |
cutswath.c - function to cut a swath of a PNM file for PPA printers
|
|
2 |
-------------------
|
|
3 |
begin : Thu Jan 13 2000
|
|
4 |
copyright : (C) 1998-2000 by the pnm2ppa project
|
|
5 |
email :
|
|
6 |
***************************************************************************/
|
|
7 |
|
|
8 |
/***************************************************************************
|
|
9 |
* *
|
|
10 |
* This program is free software; you can redistribute it and/or modify *
|
|
11 |
* it under the terms of the GNU General Public License as published by *
|
|
12 |
* the Free Software Foundation; either version 2 of the License, or *
|
|
13 |
* (at your option) any later version. *
|
|
14 |
* *
|
|
15 |
***************************************************************************/
|
|
16 |
|
|
17 |
#include <stdio.h>
|
|
18 |
#include <stdlib.h>
|
|
19 |
#include <string.h>
|
|
20 |
#include <assert.h>
|
|
21 |
|
|
22 |
#define __CUTSWATH_C__
|
|
23 |
|
|
24 |
#include "syslog.h"
|
|
25 |
#include "global.h"
|
|
26 |
#include "debug.h"
|
|
27 |
#include "defaults.h"
|
|
28 |
#include "ppa.h"
|
|
29 |
#include "image.h"
|
|
30 |
|
|
31 |
#include "lang.h"
|
|
32 |
|
|
33 |
int b_left, b_right, b_vpos , b_dir ;
|
|
34 |
int c_left, c_right, c_vpos , c_dir ;
|
|
35 |
|
|
36 |
/* sweep_data->direction must be set already */
|
|
37 |
|
|
38 |
/* Upon successful completion, sweep_data->image_data and
|
|
39 |
sweep_data->nozzle_data have been set to pointers which this routine
|
|
40 |
malloc()'d. */
|
|
41 |
|
|
42 |
/* Upon successful completion, all members of *sweep_data have been set
|
|
43 |
except direction, vertical_pos, and next. */
|
|
44 |
|
|
45 |
/* Returns: 0 if unsuccessful
|
|
46 |
1 if successful, but with non-printing result (end of page)
|
|
47 |
2 if successful, with printing result
|
|
48 |
3 if unsuccessful, exceeded buffer size */
|
|
49 |
|
|
50 |
int
|
|
51 |
cut_im_black_swath (image_t *image, ppaPrinter_t *printer,
|
|
52 |
int maxlines, ppaSweepData_t *sweep_data)
|
|
53 |
{
|
|
54 |
unsigned char *data[4], *ppa, *place, *maxplace;
|
|
55 |
int width8, p_width8;
|
|
56 |
int k, i, j, left, right, numlines;
|
|
57 |
int left_limit , right_limit , bottom_limit, top_limit;
|
|
58 |
int top_vpos , bottom_vpos, sweep_offset;
|
|
59 |
int non_blanklines, pre_blanklines, post_blanklines ;
|
|
60 |
int even_non_blanklines, even_pre_blanklines, even_post_blanklines ;
|
|
61 |
int odd_non_blanklines, odd_pre_blanklines, odd_post_blanklines ;
|
|
62 |
int start_even, start_odd;
|
|
63 |
int vpos_shift=600; /* "vertical position" = line number - vpos_shift */
|
|
64 |
BOOLEAN at_bottom ;
|
|
65 |
|
|
66 |
BOOLEAN got_nonblank;
|
|
67 |
int horzpos, hp2;
|
|
68 |
ppaNozzleData_t nozzles[2];
|
|
69 |
|
|
70 |
/* better have (black) maxlines a multiple of 4;
|
|
71 |
color uses half this number, and that must be even !*/
|
|
72 |
|
|
73 |
assert ( !(maxlines %4));
|
|
74 |
|
|
75 |
/* safeguard against the user freeing these */
|
|
76 |
for (k = 0; k < gMaxPass; k++)
|
|
77 |
{
|
|
78 |
sweep_data->image_data[k] = NULL;
|
|
79 |
}
|
|
80 |
sweep_data->nozzle_data = NULL;
|
|
81 |
|
|
82 |
/* read the data from the input file */
|
|
83 |
width8 = (image->width + 7) / 8;
|
|
84 |
for (k = 0; k < gMaxPass; k++)
|
|
85 |
{
|
|
86 |
if ((data[k] = malloc (width8 * maxlines)) == NULL)
|
|
87 |
{
|
|
88 |
snprintf(syslog_message,message_size,"cut_im_black_swath(): %s",
|
|
89 |
gMessages[E_CS_BADMALLOC]);
|
|
90 |
wrap_syslog (LOG_CRIT,"%s",syslog_message);
|
|
91 |
return 0;
|
|
92 |
}
|
|
93 |
}
|
|
94 |
|
|
95 |
/* prevent weird user settings of the margins
|
|
96 |
* from causing segfaults
|
|
97 |
*/
|
|
98 |
left_limit = printer->left_margin / 8;
|
|
99 |
if ( left_limit < 0 )
|
|
100 |
left_limit = 0;
|
|
101 |
right_limit = ( gWidth - printer->right_margin ) / 8;
|
|
102 |
if (right_limit > width8 )
|
|
103 |
right_limit = width8;
|
|
104 |
bottom_limit = gHeight - printer->bottom_margin ;
|
|
105 |
if (bottom_limit > gHeight )
|
|
106 |
bottom_limit = gHeight;
|
|
107 |
if ( bottom_limit < 0 )
|
|
108 |
bottom_limit = 0;
|
|
109 |
top_limit = printer->top_margin ;
|
|
110 |
if ( top_limit < 0 )
|
|
111 |
top_limit = 0 ;
|
|
112 |
if ( top_limit > bottom_limit )
|
|
113 |
top_limit = bottom_limit ;
|
|
114 |
|
|
115 |
/* ignore lines that are above the upper margin */
|
|
116 |
while (image->blackCurLine < top_limit)
|
|
117 |
{
|
|
118 |
if (!im_black_readline (image, data, 0))
|
|
119 |
{
|
|
120 |
snprintf(syslog_message,message_size,"cut_im_black_swath(): %s",
|
|
121 |
gMessages[E_CS_BADTOPMARG]);
|
|
122 |
wrap_syslog (LOG_CRIT,"%s",syslog_message);
|
|
123 |
|
|
124 |
for (k = 0; k < gMaxPass; k++)
|
|
125 |
{
|
|
126 |
free (data[k]);
|
|
127 |
}
|
|
128 |
return 0;
|
|
129 |
}
|
|
130 |
}
|
|
131 |
|
|
132 |
/* eat all lines that are below the lower margin */
|
|
133 |
if (image->blackCurLine >= bottom_limit )
|
|
134 |
{
|
|
135 |
while (image->blackCurLine < image->height)
|
|
136 |
if (!im_black_readline (image, data, 0))
|
|
137 |
{
|
|
138 |
snprintf(syslog_message,message_size,"cut_im_black_swath(): %s",
|
|
139 |
gMessages[E_CS_BADBOTMARG]);
|
|
140 |
wrap_syslog (LOG_CRIT,"%s",syslog_message);
|
|
141 |
|
|
142 |
for (k = 0; k < gMaxPass; k++)
|
|
143 |
{
|
|
144 |
free (data[k]);
|
|
145 |
}
|
|
146 |
return 0;
|
|
147 |
}
|
|
148 |
for (k = 0; k < gMaxPass; k++)
|
|
149 |
{
|
|
150 |
free (data[k]);
|
|
151 |
}
|
|
152 |
return 1;
|
|
153 |
}
|
|
154 |
|
|
155 |
left = right_limit - 1;
|
|
156 |
right = left_limit;
|
|
157 |
|
|
158 |
/* eat all beginning blank lines and then up to maxlines or lower margin */
|
|
159 |
got_nonblank = false;
|
|
160 |
numlines = 0;
|
|
161 |
pre_blanklines = 0;
|
|
162 |
post_blanklines = 0;
|
|
163 |
sweep_offset = 0;
|
|
164 |
at_bottom = false ;
|
|
165 |
while (( image->blackCurLine + pre_blanklines < bottom_limit)
|
|
166 |
&& ((numlines + pre_blanklines + post_blanklines ) < maxlines)
|
|
167 |
&& ((!gColorMode) || got_nonblank
|
|
168 |
|| ((image->buflines < MAXBUFFLINES)
|
|
169 |
|| (image->buftype == bitmap))))
|
|
170 |
{
|
|
171 |
if (!im_black_readline (image, data, width8 * numlines))
|
|
172 |
{
|
|
173 |
snprintf(syslog_message,message_size,"cut_im_black_swath(): %s",
|
|
174 |
gMessages[E_CS_BADNEXTLINE]);
|
|
175 |
wrap_syslog (LOG_CRIT,"%s",syslog_message);
|
|
176 |
for (k = 0; k < gMaxPass; k++)
|
|
177 |
{
|
|
178 |
free (data[k]);
|
|
179 |
}
|
|
180 |
return 0;
|
|
181 |
}
|
|
182 |
if (!got_nonblank)
|
|
183 |
{
|
|
184 |
for (i = left_limit ; i < right_limit; i++)
|
|
185 |
{
|
|
186 |
if (data[0][i])
|
|
187 |
{
|
|
188 |
left = i;
|
|
189 |
got_nonblank = true;
|
|
190 |
right = i;
|
|
191 |
for (j = right_limit - 1; j > left ; j--)
|
|
192 |
{
|
|
193 |
if (data[0][j])
|
|
194 |
{
|
|
195 |
right = j;
|
|
196 |
break;
|
|
197 |
}
|
|
198 |
}
|
|
199 |
/* begin a new swath;, nonblank pixels occur in
|
|
200 |
* bytes "left" through "right", inclusive,
|
|
201 |
* where
|
|
202 |
* left_limit <= left <= right < right_limit.
|
|
203 |
* This range will be expanded if necessary
|
|
204 |
* as the swath is constructed
|
|
205 |
*/
|
|
206 |
DPRINTF("cut_im_black_swath: begin swath, line %d\n",
|
|
207 |
image->blackCurLine ) ;
|
|
208 |
|
|
209 |
/* vertical position of top of swath */
|
|
210 |
top_vpos = image->blackCurLine - vpos_shift ;
|
|
211 |
|
|
212 |
/* predicted vertical position of bottom of swath */
|
|
213 |
bottom_vpos = top_vpos + maxlines - 1 ;
|
|
214 |
if ( bottom_vpos > bottom_limit - vpos_shift)
|
|
215 |
{
|
|
216 |
at_bottom = true;
|
|
217 |
bottom_vpos = bottom_limit - vpos_shift ;
|
|
218 |
/* make sure we are at least 12 dots below the previous
|
|
219 |
black swath vertical position (this is only
|
|
220 |
a possible problem if we are at the bottom limit)*/
|
|
221 |
if ( b_vpos + 12 - bottom_vpos > 0 )
|
|
222 |
{
|
|
223 |
post_blanklines += (b_vpos + 12 - bottom_vpos) ;
|
|
224 |
bottom_vpos += post_blanklines ;
|
|
225 |
}
|
|
226 |
}
|
|
227 |
|
|
228 |
DPRINTF("cut_im_black_swath: shifted bottom_limit=%d, bottom_vpos=%d\n",
|
|
229 |
bottom_limit - vpos_shift , bottom_vpos) ;
|
|
230 |
|
|
231 |
/* sweep_offset is the difference in vertical position
|
|
232 |
of consecutive color and black sweeps.
|
|
233 |
Flashing lights happen on the HP820 if this
|
|
234 |
is -3, -2, -1, 1 , 2 or 3! */
|
|
235 |
|
|
236 |
/* test previous color swath vertical positions */
|
|
237 |
sweep_offset = bottom_vpos - c_vpos ;
|
|
238 |
|
|
239 |
if ( ( sweep_offset >= -4 ) &&
|
|
240 |
( sweep_offset < 4 ) &&
|
|
241 |
( sweep_offset != 0 || at_bottom) )
|
|
242 |
{
|
|
243 |
if ( ( at_bottom ) &&
|
|
244 |
( c_vpos + 5 - sweep_offset < top_vpos + maxlines - 1 ))
|
|
245 |
{
|
|
246 |
/* we are at the bottom margin , and can add post_blanklines*/
|
|
247 |
post_blanklines += 4 - sweep_offset ;
|
|
248 |
}
|
|
249 |
else
|
|
250 |
{
|
|
251 |
/* we are in the middle of the page */
|
|
252 |
if ( ( sweep_offset > 0 ) && ( ! at_bottom ))
|
|
253 |
{
|
|
254 |
/* shift swath upward to have same vpos */
|
|
255 |
pre_blanklines = sweep_offset ;
|
|
256 |
}
|
|
257 |
else
|
|
258 |
{
|
|
259 |
/* shift swath up to have vertical position vpos - 5 */
|
|
260 |
pre_blanklines = 5 + sweep_offset ;
|
|
261 |
}
|
|
262 |
}
|
|
263 |
}
|
|
264 |
/* will add pre_blanklines blank lines at the top of the swath
|
|
265 |
and post_blanklines at the end of the swath. */
|
|
266 |
break;
|
|
267 |
}
|
|
268 |
}
|
|
269 |
}
|
|
270 |
if (got_nonblank)
|
|
271 |
{
|
|
272 |
int newleft = left, newright = right;
|
|
273 |
|
|
274 |
/* find left-most nonblank */
|
|
275 |
for (i = left_limit ; i < left; i++)
|
|
276 |
{
|
|
277 |
if (data[0][width8 * numlines + i])
|
|
278 |
{
|
|
279 |
newleft = i;
|
|
280 |
break;
|
|
281 |
}
|
|
282 |
}
|
|
283 |
/* find right-most nonblank */
|
|
284 |
for (j = right_limit - 1; j > right; j--)
|
|
285 |
{
|
|
286 |
if (data[0][width8 * numlines + j])
|
|
287 |
{
|
|
288 |
newright = j;
|
|
289 |
break;
|
|
290 |
}
|
|
291 |
}
|
|
292 |
numlines++;
|
|
293 |
|
|
294 |
if (newright < newleft)
|
|
295 |
{
|
|
296 |
DPRINTF ("Code error! newleft=%d, newright=%d, left=%d, right=%d\n",
|
|
297 |
newleft, newright, left, right);
|
|
298 |
for (k = 0; k < gMaxPass; k++)
|
|
299 |
{
|
|
300 |
free (data[k]);
|
|
301 |
}
|
|
302 |
return 0;
|
|
303 |
}
|
|
304 |
|
|
305 |
/* if the next line might push us over the buffer size, stop here! */
|
|
306 |
/* ignore this test for the 720 right now. Will add better */
|
|
307 |
/* size-guessing for compressed data in the near future! */
|
|
308 |
if (numlines % 2 == 1 && printer->version != HP7X0)
|
|
309 |
{
|
|
310 |
int l = newleft, r = newright, w;
|
|
311 |
|
|
312 |
l--;
|
|
313 |
r += 3;
|
|
314 |
w = r - l;
|
|
315 |
|
|
316 |
if ((w + 24) * numlines > printer->bufsize)
|
|
317 |
{
|
|
318 |
numlines--;
|
|
319 |
im_unreadline (image, data[0] + width8 * numlines);
|
|
320 |
break;
|
|
321 |
}
|
|
322 |
else
|
|
323 |
{
|
|
324 |
left = newleft;
|
|
325 |
right = newright;
|
|
326 |
}
|
|
327 |
}
|
|
328 |
else
|
|
329 |
{
|
|
330 |
left = newleft;
|
|
331 |
right = newright;
|
|
332 |
}
|
|
333 |
}
|
|
334 |
}
|
|
335 |
|
|
336 |
if ((gColorMode) && (image->buflines >= MAXBUFFLINES)
|
|
337 |
&& (image->buftype == color))
|
|
338 |
{
|
|
339 |
DPRINTF ("cut_im_black_swath: exceeding buffer size: buflines=%d, MAX=%d\n",
|
|
340 |
image->buflines, MAXBUFFLINES);
|
|
341 |
if ((!got_nonblank))
|
|
342 |
{
|
|
343 |
for (k = 0; k < gMaxPass; k++)
|
|
344 |
{
|
|
345 |
free (data[k]);
|
|
346 |
}
|
|
347 |
return 3;
|
|
348 |
}
|
|
349 |
}
|
|
350 |
|
|
351 |
if ((!got_nonblank))
|
|
352 |
{
|
|
353 |
/* eat all lines that are below the lower margin */
|
|
354 |
if (image->blackCurLine >= bottom_limit )
|
|
355 |
{
|
|
356 |
while (image->blackCurLine < image->height)
|
|
357 |
if (!im_black_readline (image, data, 0))
|
|
358 |
{
|
|
359 |
snprintf(syslog_message,message_size,"cut_im_black_swath(): %s",
|
|
360 |
gMessages[E_CS_BADBOTMARG]);
|
|
361 |
wrap_syslog (LOG_CRIT,"%s",syslog_message);
|
|
362 |
|
|
363 |
for (k = 0; k < gMaxPass; k++)
|
|
364 |
{
|
|
365 |
free (data[k]);
|
|
366 |
}
|
|
367 |
return 0;
|
|
368 |
}
|
|
369 |
for (k = 0; k < gMaxPass; k++)
|
|
370 |
{
|
|
371 |
free (data[k]);
|
|
372 |
}
|
|
373 |
return 1;
|
|
374 |
}
|
|
375 |
for (k = 0; k < gMaxPass; k++)
|
|
376 |
{
|
|
377 |
free (data[k]);
|
|
378 |
}
|
|
379 |
return 0;
|
|
380 |
/* error, since didn't get to lower margin, yet blank */
|
|
381 |
}
|
|
382 |
|
|
383 |
|
|
384 |
/* calculate vertical position */
|
|
385 |
sweep_data->vertical_pos = image->blackCurLine ;
|
|
386 |
|
|
387 |
/* subtract that 600 dot adjustment here */
|
|
388 |
sweep_data->vertical_pos -= vpos_shift;
|
|
389 |
|
|
390 |
DPRINTF("cut_im_black_swath: end swath, line %d numlines=%d left=%d right=%d\n",
|
|
391 |
image->blackCurLine, numlines, left, right) ;
|
|
392 |
/* width of the swath in bytes */
|
|
393 |
|
|
394 |
|
|
395 |
/* calculate number of blank lines added at top and bottom of swath */
|
|
396 |
|
|
397 |
non_blanklines = numlines ;
|
|
398 |
numlines += pre_blanklines ;
|
|
399 |
if ( (numlines + post_blanklines) % 2 )
|
|
400 |
post_blanklines++ ;
|
|
401 |
numlines += post_blanklines ;
|
|
402 |
assert (maxlines >= numlines );
|
|
403 |
sweep_data->vertical_pos += post_blanklines ;
|
|
404 |
|
|
405 |
even_pre_blanklines = odd_pre_blanklines = pre_blanklines / 2 ;
|
|
406 |
even_non_blanklines = odd_non_blanklines = non_blanklines / 2 ;
|
|
407 |
even_post_blanklines = odd_post_blanklines = post_blanklines / 2 ;
|
|
408 |
|
|
409 |
start_even= 0;
|
|
410 |
start_odd = 1;
|
|
411 |
|
|
412 |
if ( (pre_blanklines %2 == 0) &&
|
|
413 |
!(non_blanklines % 2 == 0) &&
|
|
414 |
!(post_blanklines % 2 == 0))
|
|
415 |
{
|
|
416 |
even_non_blanklines++ ;
|
|
417 |
odd_post_blanklines++;
|
|
418 |
start_even= 0;
|
|
419 |
start_odd = 1;
|
|
420 |
}
|
|
421 |
if ( !(pre_blanklines %2 == 0) &&
|
|
422 |
!(non_blanklines % 2 == 0) &&
|
|
423 |
(post_blanklines % 2 == 0))
|
|
424 |
{
|
|
425 |
even_pre_blanklines++;
|
|
426 |
odd_non_blanklines++;
|
|
427 |
start_even= 1;
|
|
428 |
start_odd = 0;
|
|
429 |
}
|
|
430 |
if ( !(pre_blanklines %2 == 0) &&
|
|
431 |
(non_blanklines % 2 == 0) &&
|
|
432 |
!(post_blanklines % 2 == 0))
|
|
433 |
{
|
|
434 |
even_pre_blanklines++;
|
|
435 |
odd_post_blanklines++;
|
|
436 |
start_even= 1;
|
|
437 |
start_odd = 0;
|
|
438 |
}
|
|
439 |
|
|
440 |
|
|
441 |
assert (( even_pre_blanklines + odd_pre_blanklines +
|
|
442 |
even_non_blanklines + odd_non_blanklines +
|
|
443 |
even_post_blanklines + odd_post_blanklines ) == numlines );
|
|
444 |
|
|
445 |
if (pre_blanklines)
|
|
446 |
{
|
|
447 |
DPRINTF("cut_im_black_swath: offset %d; add pre_blanklines=%d lines\n",
|
|
448 |
sweep_offset, pre_blanklines);
|
|
449 |
}
|
|
450 |
if (post_blanklines)
|
|
451 |
{
|
|
452 |
DPRINTF("cut_im_black_swath: offset %d; add post_blanklines=%d lines\n",
|
|
453 |
sweep_offset, post_blanklines);
|
|
454 |
}
|
|
455 |
|
|
456 |
|
|
457 |
/* change sweep params */
|
|
458 |
/* ensures at least 4 bytes sweep width */
|
|
459 |
right +=3;
|
|
460 |
left-- ;
|
|
461 |
p_width8 = right - left;
|
|
462 |
|
|
463 |
|
|
464 |
if ((ppa = malloc ((p_width8 + 24) * numlines)) == NULL)
|
|
465 |
{
|
|
466 |
snprintf(syslog_message,message_size,"cut_im_black_swath(): %s",
|
|
467 |
gMessages[E_CS_BADPPAMALLOC]);
|
|
468 |
wrap_syslog (LOG_CRIT,"%s",syslog_message);
|
|
469 |
|
|
470 |
for (k = 0; k < gMaxPass; k++)
|
|
471 |
{
|
|
472 |
free (data[k]);
|
|
473 |
}
|
|
474 |
return 0;
|
|
475 |
}
|
|
476 |
|
|
477 |
place = ppa;
|
|
478 |
|
|
479 |
|
|
480 |
/* always left-to-right if gUnimode is true */
|
|
481 |
if (gUnimode)
|
|
482 |
sweep_data->direction = left_to_right;
|
|
483 |
else if ((b_vpos > c_vpos) || (c_vpos > sweep_data->vertical_pos))
|
|
484 |
{
|
|
485 |
if (b_dir == left_to_right)
|
|
486 |
sweep_data->direction = right_to_left;
|
|
487 |
else
|
|
488 |
sweep_data->direction = left_to_right;
|
|
489 |
} else {
|
|
490 |
if (c_dir == left_to_right)
|
|
491 |
sweep_data->direction = right_to_left;
|
|
492 |
else
|
|
493 |
sweep_data->direction = left_to_right;
|
|
494 |
}
|
|
495 |
|
|
496 |
DPRINTF("cut_im_black_swath: prev b_left %d b_right %d b_vpos %d b_dir %d\n",
|
|
497 |
b_left, b_right, b_vpos, b_dir);
|
|
498 |
DPRINTF("cut_im_black_swath: cur left %d right %d vpos %d dir %d\n",
|
|
499 |
left, right, sweep_data->vertical_pos, sweep_data->direction);
|
|
500 |
b_left = left;
|
|
501 |
b_right = right;
|
|
502 |
b_vpos = sweep_data->vertical_pos;
|
|
503 |
b_dir = sweep_data->direction;
|
|
504 |
DPRINTF("cut_im_black_swath: c_left %d c_right %d c_vpos %d c_dir %d\n",
|
|
505 |
c_left, c_right, c_vpos, c_dir);
|
|
506 |
|
|
507 |
/* place 0's in the first 12 columns */
|
|
508 |
memset (place, 0, numlines / 2 * 12);
|
|
509 |
place += numlines / 2 * 12;
|
|
510 |
|
|
511 |
if (sweep_data->direction == left_to_right)
|
|
512 |
DPRINTF ("black: sweep_data->direction == left_to_right\n");
|
|
513 |
else if (sweep_data->direction == right_to_left)
|
|
514 |
DPRINTF ("black: sweep_data->direction == right_to_left\n");
|
|
515 |
else
|
|
516 |
DPRINTF ("black: sweep_data->direction == *** ERROR: NOT SET! \n");
|
|
517 |
|
|
518 |
if (sweep_data->direction == right_to_left) /* right-to-left */
|
|
519 |
{
|
|
520 |
for (i = p_width8 + 11; i >= 0; i--)
|
|
521 |
{
|
|
522 |
int x ;
|
|
523 |
if (i >= 12 )
|
|
524 |
{
|
|
525 |
x = i - 12;
|
|
526 |
if( left + x < left_limit || left + x >= right_limit )
|
|
527 |
{
|
|
528 |
/* never print data outside the limits */
|
|
529 |
memset (place, 0, numlines / 2);
|
|
530 |
place += numlines / 2;
|
|
531 |
}
|
|
532 |
else
|
|
533 |
{
|
|
534 |
if ( even_pre_blanklines > 0)
|
|
535 |
{
|
|
536 |
/* first pre_blanklines lines are blank */
|
|
537 |
memset (place, 0, even_pre_blanklines) ;
|
|
538 |
place += even_pre_blanklines ;
|
|
539 |
}
|
|
540 |
for (j = 0; j < even_non_blanklines; j++)
|
|
541 |
{
|
|
542 |
*place++ = data[0][((j * 2) + start_even ) * width8 + left + x];
|
|
543 |
}
|
|
544 |
if ( even_post_blanklines > 0 )
|
|
545 |
{
|
|
546 |
/* last post_blanklines lines are blank */
|
|
547 |
memset (place, 0, even_post_blanklines) ;
|
|
548 |
place += even_post_blanklines ;
|
|
549 |
}
|
|
550 |
}
|
|
551 |
}
|
|
552 |
else
|
|
553 |
{
|
|
554 |
memset (place, 0, numlines / 2);
|
|
555 |
place += numlines / 2;
|
|
556 |
}
|
|
557 |
|
|
558 |
if (i < p_width8)
|
|
559 |
{
|
|
560 |
x = i ;
|
|
561 |
if( left + x < left_limit || left + x >= right_limit )
|
|
562 |
{
|
|
563 |
/* never print data outside the limits */
|
|
564 |
memset (place, 0, numlines / 2);
|
|
565 |
place += numlines / 2;
|
|
566 |
}
|
|
567 |
else
|
|
568 |
{
|
|
569 |
if ( odd_pre_blanklines > 0)
|
|
570 |
{
|
|
571 |
/* first pre_blanklines lines are blank */
|
|
572 |
memset (place, 0, odd_pre_blanklines) ;
|
|
573 |
place += odd_pre_blanklines ;
|
|
574 |
}
|
|
575 |
for (j = 0; j < odd_non_blanklines; j++)
|
|
576 |
{
|
|
577 |
*place++ = data[0][((j * 2) + start_odd ) * width8 + left + x];
|
|
578 |
}
|
|
579 |
if ( odd_post_blanklines > 0 )
|
|
580 |
{
|
|
581 |
/* last post_blanklines lines are blank */
|
|
582 |
memset (place, 0, odd_post_blanklines) ;
|
|
583 |
place += odd_post_blanklines ;
|
|
584 |
}
|
|
585 |
}
|
|
586 |
}
|
|
587 |
else
|
|
588 |
{
|
|
589 |
memset (place, 0, numlines / 2);
|
|
590 |
place += numlines / 2;
|
|
591 |
}
|
|
592 |
}
|
|
593 |
}
|
|
594 |
else /* sweep_data->direction == left_to_right */
|
|
595 |
{
|
|
596 |
for (i = 0; i < p_width8 + 12; i++)
|
|
597 |
{
|
|
598 |
int x;
|
|
599 |
if (i < p_width8)
|
|
600 |
{
|
|
601 |
x = i;
|
|
602 |
if( left + x < left_limit || left + x >= right_limit )
|
|
603 |
{
|
|
604 |
/* never print data outside the limits */
|
|
605 |
memset (place, 0, numlines / 2);
|
|
606 |
place += numlines / 2;
|
|
607 |
}
|
|
608 |
else
|
|
609 |
{
|
|
610 |
if ( odd_pre_blanklines > 0)
|
|
611 |
{
|
|
612 |
/* first pre_blanklines lines are blank */
|
|
613 |
memset (place, 0, odd_pre_blanklines) ;
|
|
614 |
place += odd_pre_blanklines ;
|
|
615 |
}
|
|
616 |
for (j = 0; j < odd_non_blanklines; j++)
|
|
617 |
{
|
|
618 |
*place++ = data[0][((j * 2) + start_odd) * width8 + left + x];
|
|
619 |
}
|
|
620 |
if ( odd_post_blanklines > 0 )
|
|
621 |
{
|
|
622 |
/* last post_blanklines lines are blank */
|
|
623 |
memset (place, 0, odd_post_blanklines) ;
|
|
624 |
place += odd_post_blanklines ;
|
|
625 |
}
|
|
626 |
}
|
|
627 |
}
|
|
628 |
else
|
|
629 |
{
|
|
630 |
memset (place, 0, numlines / 2);
|
|
631 |
place += numlines / 2;
|
|
632 |
}
|
|
633 |
|
|
634 |
if (i >= 12)
|
|
635 |
{
|
|
636 |
x = i - 12;
|
|
637 |
if( left + x < left_limit || left + x >= right_limit )
|
|
638 |
{
|
|
639 |
/* never print data outside the limits */
|
|
640 |
memset (place, 0, numlines / 2);
|
|
641 |
place += numlines / 2;
|
|
642 |
}
|
|
643 |
else
|
|
644 |
{
|
|
645 |
if ( even_pre_blanklines > 0)
|
|
646 |
{
|
|
647 |
/* first pre_blanklines lines are blank */
|
|
648 |
memset (place, 0, even_pre_blanklines) ;
|
|
649 |
place += even_pre_blanklines ;
|
|
650 |
}
|
|
651 |
for (j = 0; j < even_non_blanklines; j++)
|
|
652 |
{
|
|
653 |
*place++ = data[0][((j * 2) + start_even) * width8 + left + x];
|
|
654 |
}
|
|
655 |
if ( even_post_blanklines > 0 )
|
|
656 |
{
|
|
657 |
/* last post_blanklines lines are blank */
|
|
658 |
memset (place, 0, even_post_blanklines) ;
|
|
659 |
place += even_post_blanklines ;
|
|
660 |
}
|
|
661 |
}
|
|
662 |
}
|
|
663 |
else
|
|
664 |
{
|
|
665 |
memset (place, 0, numlines / 2);
|
|
666 |
place += numlines / 2;
|
|
667 |
}
|
|
668 |
}
|
|
669 |
}
|
|
670 |
|
|
671 |
/* done with data */
|
|
672 |
for (k = 0; k < gMaxPass; k++)
|
|
673 |
{
|
|
674 |
if (data[k] != NULL)
|
|
675 |
{
|
|
676 |
free (data[k]);
|
|
677 |
}
|
|
678 |
}
|
|
679 |
|
|
680 |
/* place 0's in the last 12 columns */
|
|
681 |
memset (place, 0, numlines / 2 * 12);
|
|
682 |
place += numlines / 2 * 12;
|
|
683 |
maxplace = place;
|
|
684 |
|
|
685 |
/* create sweep data */
|
|
686 |
sweep_data->image_data[0] = ppa;
|
|
687 |
sweep_data->data_size = maxplace - ppa;
|
|
688 |
sweep_data->in_color = false;
|
|
689 |
|
|
690 |
horzpos = left * 8 ;
|
|
691 |
|
|
692 |
horzpos += (sweep_data->direction == left_to_right) ? 1 : 0;
|
|
693 |
|
|
694 |
if (sweep_data->direction == right_to_left )
|
|
695 |
horzpos += printer->r2l_bw_offset ;/* correct bidirectional shearing */
|
|
696 |
|
|
697 |
hp2 = horzpos + (p_width8 + 24) * 8;
|
|
698 |
|
|
699 |
|
|
700 |
sweep_data->left_margin = horzpos;
|
|
701 |
sweep_data->right_margin = hp2 + printer->marg_diff;
|
|
702 |
|
|
703 |
for (i = 0; i < 2; i++)
|
|
704 |
{
|
|
705 |
nozzles[i].DPI = 600;
|
|
706 |
nozzles[i].pins_used_d2 = numlines / 2;
|
|
707 |
nozzles[i].unused_pins_p1 = 301 - numlines;
|
|
708 |
nozzles[i].first_pin = 1;
|
|
709 |
if (i == 0)
|
|
710 |
{
|
|
711 |
nozzles[i].left_margin = horzpos + printer->marg_diff;
|
|
712 |
nozzles[i].right_margin = hp2 + printer->marg_diff;
|
|
713 |
if (sweep_data->direction == right_to_left)
|
|
714 |
nozzles[i].nozzle_delay = 0;
|
|
715 |
else
|
|
716 |
nozzles[i].nozzle_delay = 6; //6
|
|
717 |
}
|
|
718 |
else
|
|
719 |
{
|
|
720 |
nozzles[i].left_margin = horzpos;
|
|
721 |
nozzles[i].right_margin = hp2;
|
|
722 |
if (sweep_data->direction == right_to_left)
|
|
723 |
nozzles[i].nozzle_delay = 2;
|
|
724 |
else
|
|
725 |
nozzles[i].nozzle_delay = 0;
|
|
726 |
}
|
|
727 |
}
|
|
728 |
|
|
729 |
sweep_data->nozzle_data_size = 2;
|
|
730 |
sweep_data->nozzle_data = malloc (sizeof (nozzles));
|
|
731 |
if (sweep_data->nozzle_data == NULL)
|
|
732 |
return 0;
|
|
733 |
memcpy (sweep_data->nozzle_data, nozzles, sizeof (nozzles));
|
|
734 |
|
|
735 |
return 2;
|
|
736 |
}
|
|
737 |
|
|
738 |
#define UNUSABLE 1
|
|
739 |
#define CYAN (0<<1)
|
|
740 |
#define MAGENTA (1<<1)
|
|
741 |
#define YELLOW (2<<1)
|
|
742 |
#define ODD (1<<3)
|
|
743 |
#define EVEN (0<<3)
|
|
744 |
#define XSHIFT 4
|
|
745 |
#define XPOS(x) ((x)<<XSHIFT)
|
|
746 |
|
|
747 |
|
|
748 |
/* number of "special" columns at left of sweep */
|
|
749 |
/* different versions for left-to-right and right-to-left sweeps */
|
|
750 |
static int Right_size = 42;
|
|
751 |
static int Right_l2r[] = {
|
|
752 |
UNUSABLE,
|
|
753 |
UNUSABLE,
|
|
754 |
UNUSABLE,
|
|
755 |
UNUSABLE,
|
|
756 |
CYAN | EVEN | XPOS (0),
|
|
757 |
CYAN | ODD | XPOS (0),
|
|
758 |
CYAN | EVEN | XPOS (1),
|
|
759 |
UNUSABLE,
|
|
760 |
UNUSABLE,
|
|
761 |
CYAN | ODD | XPOS (1),
|
|
762 |
CYAN | EVEN | XPOS (2),
|
|
763 |
UNUSABLE,
|
|
764 |
UNUSABLE,
|
|
765 |
CYAN | ODD | XPOS (2),
|
|
766 |
CYAN | EVEN | XPOS (3),
|
|
767 |
UNUSABLE,
|
|
768 |
MAGENTA | EVEN | XPOS (0),
|
|
769 |
CYAN | ODD | XPOS (3),
|
|
770 |
CYAN | EVEN | XPOS (4),
|
|
771 |
UNUSABLE,
|
|
772 |
MAGENTA | ODD | XPOS (0),
|
|
773 |
MAGENTA | EVEN | XPOS (1),
|
|
774 |
CYAN | ODD | XPOS (4),
|
|
775 |
CYAN | EVEN | XPOS (5),
|
|
776 |
UNUSABLE,
|
|
777 |
UNUSABLE,
|
|
778 |
MAGENTA | ODD | XPOS (1),
|
|
779 |
MAGENTA | EVEN | XPOS (2),
|
|
780 |
CYAN | ODD | XPOS (5),
|
|
781 |
CYAN | EVEN | XPOS (6),
|
|
782 |
UNUSABLE,
|
|
783 |
UNUSABLE,
|
|
784 |
MAGENTA | ODD | XPOS (2),
|
|
785 |
MAGENTA | EVEN | XPOS (3),
|
|
786 |
CYAN | ODD | XPOS (6),
|
|
787 |
CYAN | EVEN | XPOS (7),
|
|
788 |
UNUSABLE,
|
|
789 |
YELLOW | EVEN | XPOS (0),
|
|
790 |
MAGENTA | ODD | XPOS (3),
|
|
791 |
MAGENTA | EVEN | XPOS (4),
|
|
792 |
CYAN | ODD | XPOS (7),
|
|
793 |
CYAN | EVEN | XPOS (8)
|
|
794 |
};
|
|
795 |
static int Right_r2l[] = {
|
|
796 |
UNUSABLE,
|
|
797 |
UNUSABLE,
|
|
798 |
UNUSABLE,
|
|
799 |
CYAN | EVEN | XPOS (0),
|
|
800 |
UNUSABLE,
|
|
801 |
CYAN | EVEN | XPOS (1),
|
|
802 |
CYAN | ODD | XPOS (0),
|
|
803 |
UNUSABLE,
|
|
804 |
UNUSABLE,
|
|
805 |
CYAN | EVEN | XPOS (2),
|
|
806 |
CYAN | ODD | XPOS (1),
|
|
807 |
UNUSABLE,
|
|
808 |
UNUSABLE,
|
|
809 |
CYAN | EVEN | XPOS (3),
|
|
810 |
CYAN | ODD | XPOS (2),
|
|
811 |
MAGENTA | EVEN | XPOS (0),
|
|
812 |
UNUSABLE,
|
|
813 |
CYAN | EVEN | XPOS (4),
|
|
814 |
CYAN | ODD | XPOS (3),
|
|
815 |
UNUSABLE,
|
|
816 |
MAGENTA | EVEN | XPOS (1),
|
|
817 |
MAGENTA | ODD | XPOS (0),
|
|
818 |
CYAN | EVEN | XPOS (5),
|
|
819 |
CYAN | ODD | XPOS (4),
|
|
820 |
UNUSABLE,
|
|
821 |
UNUSABLE,
|
|
822 |
MAGENTA | EVEN | XPOS (2),
|
|
823 |
MAGENTA | ODD | XPOS (1),
|
|
824 |
CYAN | EVEN | XPOS (6),
|
|
825 |
CYAN | ODD | XPOS (5),
|
|
826 |
UNUSABLE,
|
|
827 |
UNUSABLE,
|
|
828 |
MAGENTA | EVEN | XPOS (3),
|
|
829 |
MAGENTA | ODD | XPOS (2),
|
|
830 |
CYAN | EVEN | XPOS (7),
|
|
831 |
CYAN | ODD | XPOS (6),
|
|
832 |
YELLOW | EVEN | XPOS (0),
|
|
833 |
UNUSABLE,
|
|
834 |
MAGENTA | EVEN | XPOS (4),
|
|
835 |
MAGENTA | ODD | XPOS (3),
|
|
836 |
CYAN | EVEN | XPOS (8),
|
|
837 |
CYAN | ODD | XPOS (7)
|
|
838 |
};
|
|
839 |
|
|
840 |
/* number of "special" columns at left of sweep */
|
|
841 |
static int Left_size = 32;
|
|
842 |
static int Left_l2r[] = {
|
|
843 |
YELLOW | ODD | XPOS (0),
|
|
844 |
YELLOW | EVEN | XPOS (0),
|
|
845 |
YELLOW | ODD | XPOS (1),
|
|
846 |
YELLOW | EVEN | XPOS (1),
|
|
847 |
YELLOW | ODD | XPOS (2),
|
|
848 |
YELLOW | EVEN | XPOS (2),
|
|
849 |
YELLOW | ODD | XPOS (3),
|
|
850 |
UNUSABLE,
|
|
851 |
MAGENTA | ODD | XPOS (0),
|
|
852 |
YELLOW | EVEN | XPOS (3),
|
|
853 |
YELLOW | ODD | XPOS (4),
|
|
854 |
MAGENTA | EVEN | XPOS (0),
|
|
855 |
MAGENTA | ODD | XPOS (1),
|
|
856 |
YELLOW | EVEN | XPOS (4),
|
|
857 |
YELLOW | ODD | XPOS (5),
|
|
858 |
MAGENTA | EVEN | XPOS (1),
|
|
859 |
MAGENTA | ODD | XPOS (2),
|
|
860 |
YELLOW | EVEN | XPOS (5),
|
|
861 |
YELLOW | ODD | XPOS (6),
|
|
862 |
UNUSABLE,
|
|
863 |
MAGENTA | EVEN | XPOS (2),
|
|
864 |
MAGENTA | ODD | XPOS (3),
|
|
865 |
YELLOW | EVEN | XPOS (6),
|
|
866 |
YELLOW | ODD | XPOS (7),
|
|
867 |
UNUSABLE,
|
|
868 |
CYAN | ODD | XPOS (0),
|
|
869 |
MAGENTA | EVEN | XPOS (3),
|
|
870 |
MAGENTA | ODD | XPOS (4),
|
|
871 |
YELLOW | EVEN | XPOS (7),
|
|
872 |
YELLOW | ODD | XPOS (8),
|
|
873 |
CYAN | EVEN | XPOS (0),
|
|
874 |
CYAN | ODD | XPOS (1)
|
|
875 |
};
|
|
876 |
|
|
877 |
/* the final odd yellow swing buffer doesnt fit in right-to-left
|
|
878 |
* color sweeps. Instead of redesigning the structure of the Left of
|
|
879 |
* the sweep (If it works, dont fix it ...)
|
|
880 |
* I'll just arrange that no printable data ever uses
|
|
881 |
* this last position .. (the leftmost printed dot) (duncan)
|
|
882 |
*/
|
|
883 |
|
|
884 |
static int Left_r2l[] = {
|
|
885 |
UNUSABLE,//YELLOW | ODD | XPOS (0), //this data doesnt fit, what to do?
|
|
886 |
YELLOW | ODD | XPOS (1),
|
|
887 |
YELLOW | EVEN | XPOS (0),
|
|
888 |
YELLOW | ODD | XPOS (2),
|
|
889 |
YELLOW | EVEN | XPOS (1),
|
|
890 |
YELLOW | ODD | XPOS (3),
|
|
891 |
YELLOW | EVEN | XPOS (2),
|
|
892 |
MAGENTA | ODD | XPOS (0),
|
|
893 |
UNUSABLE,
|
|
894 |
YELLOW | ODD | XPOS (4),
|
|
895 |
YELLOW | EVEN | XPOS (3),
|
|
896 |
MAGENTA | ODD | XPOS (1),
|
|
897 |
MAGENTA | EVEN | XPOS (0),
|
|
898 |
YELLOW | ODD | XPOS (5),
|
|
899 |
YELLOW | EVEN | XPOS (4),
|
|
900 |
MAGENTA | ODD | XPOS (2),
|
|
901 |
MAGENTA | EVEN | XPOS (1),
|
|
902 |
YELLOW | ODD | XPOS (6),
|
|
903 |
YELLOW | EVEN | XPOS (5),
|
|
904 |
UNUSABLE,
|
|
905 |
MAGENTA | ODD | XPOS (3),
|
|
906 |
MAGENTA | EVEN | XPOS (2),
|
|
907 |
YELLOW | ODD | XPOS (7),
|
|
908 |
YELLOW | EVEN | XPOS (6),
|
|
909 |
CYAN | ODD | XPOS (0),
|
|
910 |
UNUSABLE,
|
|
911 |
MAGENTA | ODD | XPOS (4),
|
|
912 |
MAGENTA | EVEN | XPOS (3),
|
|
913 |
YELLOW | ODD | XPOS (8),
|
|
914 |
YELLOW | EVEN | XPOS (7),
|
|
915 |
CYAN | ODD | XPOS (1),
|
|
916 |
CYAN | EVEN | XPOS (0)
|
|
917 |
};
|
|
918 |
|
|
919 |
#define GET_USABLE(A,i) (!(A[i] & 0x1))
|
|
920 |
#define GET_COLOR(A,i) ((A[i] >> 1) & 0x3);
|
|
921 |
#define GET_ODD(A,i) ((A[i] >> 3) & 0x1);
|
|
922 |
#define GET_X(A,i) ((A[i] >> 4));
|
|
923 |
|
|
924 |
int
|
|
925 |
cut_im_color_swath (image_t *image, ppaPrinter_t *printer, int maxlines,
|
|
926 |
ppaSweepData_t *sweep_data)
|
|
927 |
{
|
|
928 |
unsigned char *data[4], *ppa, *place, *maxplace;
|
|
929 |
int width8, p_width8;
|
|
930 |
int k, i, j, left , right, numlines;
|
|
931 |
int left_limit, right_limit, bottom_limit, top_limit ;
|
|
932 |
int top_vpos , bottom_vpos, sweep_offset ;
|
|
933 |
int non_blanklines, pre_blanklines, post_blanklines ;
|
|
934 |
int even_non_blanklines, even_pre_blanklines, even_post_blanklines ;
|
|
935 |
int odd_non_blanklines, odd_pre_blanklines, odd_post_blanklines ;
|
|
936 |
BOOLEAN at_bottom ;
|
|
937 |
int start_even, start_odd;
|
|
938 |
int vpos_shift=600; /* "vertical position" = line number - vpos_shift */
|
|
939 |
|
|
940 |
BOOLEAN got_nonblank;
|
|
941 |
int horzpos, hp2;
|
|
942 |
ppaNozzleData_t nozzles[6];
|
|
943 |
|
|
944 |
/* maxlines needs to be even */
|
|
945 |
assert( !(maxlines % 2 ));
|
|
946 |
|
|
947 |
place = NULL;
|
|
948 |
ppa = NULL;
|
|
949 |
maxplace = NULL;
|
|
950 |
|
|
951 |
/* safeguard against the user freeing these */
|
|
952 |
for (k = 0; k < gMaxPass; k++) //mocho
|
|
953 |
{
|
|
954 |
sweep_data->image_data[k] = NULL;
|
|
955 |
}
|
|
956 |
sweep_data->nozzle_data = NULL;
|
|
957 |
|
|
958 |
/* read the data from the input file */
|
|
959 |
width8 = (image->width / 2 + 7) / 8;
|
|
960 |
DPRINTF ("width8 * 3 * maxlines = %d\n", width8 * 3 * maxlines);
|
|
961 |
for (k = 0; k < gMaxPass; k++) //mocho
|
|
962 |
{
|
|
963 |
if ((data[k] = malloc (width8 * 3 * maxlines + 8)) == NULL)
|
|
964 |
{
|
|
965 |
snprintf(syslog_message,message_size,"cut_im_color_swath(): %s",
|
|
966 |
gMessages[E_CS_BADMALLOC]);
|
|
967 |
wrap_syslog (LOG_CRIT,"%s",syslog_message);
|
|
968 |
return 0;
|
|
969 |
}
|
|
970 |
}
|
|
971 |
|
|
972 |
/* protect against weird margin settings */
|
|
973 |
|
|
974 |
left_limit = printer->left_margin / 2 / 8;
|
|
975 |
if ( left_limit < 0 )
|
|
976 |
left_limit = 0 ;
|
|
977 |
right_limit = (gWidth - printer->right_margin) / 2 / 8;
|
|
978 |
if ( right_limit > width8 )
|
|
979 |
right_limit = width8 ;
|
|
980 |
bottom_limit = gHeight - printer->bottom_margin ;
|
|
981 |
if ( bottom_limit > gHeight)
|
|
982 |
bottom_limit = gHeight ;
|
|
983 |
if ( bottom_limit < 0 )
|
|
984 |
bottom_limit = 0;
|
|
985 |
top_limit = printer->top_margin ;
|
|
986 |
if ( top_limit < 0 )
|
|
987 |
top_limit = 0 ;
|
|
988 |
if ( top_limit > bottom_limit )
|
|
989 |
top_limit = bottom_limit ;
|
|
990 |
|
|
991 |
|
|
992 |
/* ignore lines that are above the upper margin */
|
|
993 |
while (image->colorCurLine < top_limit )
|
|
994 |
if (!im_color_readline (image, data, 0))
|
|
995 |
{
|
|
996 |
snprintf(syslog_message,message_size,"cut_im_color_swath(): %s",
|
|
997 |
gMessages[E_CS_BADTOPMARG]);
|
|
998 |
wrap_syslog (LOG_CRIT,"%s",syslog_message);
|
|
999 |
|
|
1000 |
for (k = 0; k < gMaxPass; k++) // mocho
|
|
1001 |
{
|
|
1002 |
free (data[k]);
|
|
1003 |
}
|
|
1004 |
return 0;
|
|
1005 |
}
|
|
1006 |
|
|
1007 |
/* eat all lines that are below the lower margin */
|
|
1008 |
if (image->colorCurLine >= bottom_limit )
|
|
1009 |
{
|
|
1010 |
while (image->colorCurLine < image->height)
|
|
1011 |
if (!im_color_readline (image, data, 0))
|
|
1012 |
{
|
|
1013 |
snprintf(syslog_message,message_size,"cut_im_color_swath(): %s",
|
|
1014 |
gMessages[E_CS_BADBOTMARG]);
|
|
1015 |
wrap_syslog (LOG_CRIT,"%s",syslog_message);
|
|
1016 |
|
|
1017 |
for (k = 0; k < gMaxPass; k++)
|
|
1018 |
{
|
|
1019 |
free (data[k]); //mocho
|
|
1020 |
}
|
|
1021 |
return 0;
|
|
1022 |
}
|
|
1023 |
for (k = 0; k < gMaxPass; k++)
|
|
1024 |
{
|
|
1025 |
free (data[k]); //mocho
|
|
1026 |
}
|
|
1027 |
DPRINTF (" cut_im_color_swath: return 1 on line %d\n", __LINE__);
|
|
1028 |
return 1;
|
|
1029 |
}
|
|
1030 |
|
|
1031 |
|
|
1032 |
left = right_limit - 1;
|
|
1033 |
right = left_limit;
|
|
1034 |
|
|
1035 |
got_nonblank = false;
|
|
1036 |
numlines = 0;
|
|
1037 |
pre_blanklines = 0;
|
|
1038 |
post_blanklines = 0;
|
|
1039 |
at_bottom = false ;
|
|
1040 |
sweep_offset = 0;
|
|
1041 |
/* eat all beginning blank lines and then up to maxlines or lower margin */
|
|
1042 |
while (
|
|
1043 |
( image->colorCurLine + (2* pre_blanklines) < bottom_limit ) &&
|
|
1044 |
( (numlines + pre_blanklines + post_blanklines) < maxlines)
|
|
1045 |
&& (got_nonblank ||
|
|
1046 |
((image->buflines < MAXBUFFLINES) || (image->buftype == color))))
|
|
1047 |
{
|
|
1048 |
if (!im_color_readline (image, data, width8 * 3 * numlines)) //mocho
|
|
1049 |
{
|
|
1050 |
snprintf(syslog_message,message_size,"cut_im_color_swath(): %s",
|
|
1051 |
gMessages[E_CS_BADNEXTLINE]);
|
|
1052 |
wrap_syslog (LOG_CRIT,"%s",syslog_message);
|
|
1053 |
|
|
1054 |
for (k = 0; k < gMaxPass; k++)
|
|
1055 |
{
|
|
1056 |
free (data[k]); //mocho
|
|
1057 |
}
|
|
1058 |
return 0;
|
|
1059 |
}
|
|
1060 |
if (!got_nonblank)
|
|
1061 |
{
|
|
1062 |
for (i = left_limit * 3; i < right_limit * 3; i++)
|
|
1063 |
{
|
|
1064 |
if ((data[gMaxPass - 1][i]))
|
|
1065 |
{
|
|
1066 |
left = i / 3;
|
|
1067 |
got_nonblank = true;
|
|
1068 |
right = left;
|
|
1069 |
for (j = right_limit * 3 - 1; j > left * 3 + 2; j--)
|
|
1070 |
{
|
|
1071 |
if ((data[gMaxPass - 1][j]))
|
|
1072 |
{
|
|
1073 |
right = j / 3;
|
|
1074 |
break;
|
|
1075 |
}
|
|
1076 |
}
|
|
1077 |
/* begin a new swath;, nonblank pixels occur in
|
|
1078 |
* bytes "left" through "right", inclusive,
|
|
1079 |
* where
|
|
1080 |
* left_limit <= left <= right < right_limit.
|
|
1081 |
* This range will be expanded if necessary
|
|
1082 |
* as the swath is constructed
|
|
1083 |
*/
|
|
1084 |
DPRINTF("cut_im_color_swath: begin swath, line %d\n",
|
|
1085 |
image->colorCurLine ) ;
|
|
1086 |
|
|
1087 |
/* vertical position of top of swath */
|
|
1088 |
top_vpos = image->colorCurLine - vpos_shift + printer->ColBwOffsY ;
|
|
1089 |
|
|
1090 |
/* predicted vertical position of bottom of swath */
|
|
1091 |
bottom_vpos = top_vpos + 2* ( maxlines - 1);
|
|
1092 |
if ( bottom_vpos > bottom_limit - vpos_shift + printer->ColBwOffsY )
|
|
1093 |
{
|
|
1094 |
at_bottom = true;
|
|
1095 |
bottom_vpos = bottom_limit - vpos_shift + printer->ColBwOffsY ;
|
|
1096 |
/* make sure we are at least 20 dots below the previous
|
|
1097 |
color swath vertical position (this is only
|
|
1098 |
a possible problem if we are at the bottom limit)*/
|
|
1099 |
if ( ( c_vpos + 21 - bottom_vpos )/2 > 0)
|
|
1100 |
{
|
|
1101 |
post_blanklines += (c_vpos + 21 - bottom_vpos) /2 ;
|
|
1102 |
bottom_vpos += 2 * post_blanklines ;
|
|
1103 |
}
|
|
1104 |
}
|
|
1105 |
|
|
1106 |
DPRINTF("cut_im_color_swath: shifted bottom_limit=%d, bottom_vpos=%d\n",
|
|
1107 |
bottom_limit - vpos_shift, bottom_vpos) ;
|
|
1108 |
|
|
1109 |
/* sweep_offset is the difference in vertical position
|
|
1110 |
of consecutive color and black sweeps.
|
|
1111 |
Flashing lights happen on the HP820 if this
|
|
1112 |
is -3, -2, -1, 1 , 2 or 3! */
|
|
1113 |
|
|
1114 |
/* compare to last black vpos */
|
|
1115 |
sweep_offset = bottom_vpos - b_vpos ;
|
|
1116 |
|
|
1117 |
if ( ( sweep_offset >= -4 ) &&
|
|
1118 |
( sweep_offset < 4 ) &&
|
|
1119 |
( (sweep_offset !=0 ) || at_bottom ))
|
|
1120 |
{
|
|
1121 |
if ( (at_bottom) &&
|
|
1122 |
( b_vpos + 2 * ((5 - sweep_offset ) / 2) < top_vpos + 2 * ( maxlines - 1 ) ) )
|
|
1123 |
{
|
|
1124 |
/* we are at bottom of page, and can add post_blanklines */
|
|
1125 |
post_blanklines += ( 5 - sweep_offset ) /2 ;
|
|
1126 |
}
|
|
1127 |
else
|
|
1128 |
{
|
|
1129 |
/* we are in the middle of the page ;
|
|
1130 |
add pre_blanklines to shift swath end up */
|
|
1131 |
if ( sweep_offset == 3 )
|
|
1132 |
{
|
|
1133 |
/* shift swath upward to vpos - 7 */
|
|
1134 |
pre_blanklines = 5;
|
|
1135 |
}
|
|
1136 |
else if ( sweep_offset == 2 )
|
|
1137 |
{
|
|
1138 |
/* shift swath upward to vpos - 6 */
|
|
1139 |
pre_blanklines = 4;
|
|
1140 |
}
|
|
1141 |
else if ( sweep_offset == 1 )
|
|
1142 |
{
|
|
1143 |
/* shift swath upward to vpos - 7 */
|
|
1144 |
pre_blanklines = 4;
|
|
1145 |
}
|
|
1146 |
else if ( sweep_offset == -1 )
|
|
1147 |
{
|
|
1148 |
/* shift swath upward to vpos -7 */
|
|
1149 |
pre_blanklines = 3;
|
|
1150 |
}
|
|
1151 |
else if ( sweep_offset == -2 )
|
|
1152 |
{
|
|
1153 |
/* shift swath upward to vpos -6 */
|
|
1154 |
pre_blanklines = 2;
|
|
1155 |
}
|
|
1156 |
else if ( sweep_offset == -3 )
|
|
1157 |
{
|
|
1158 |
/* shift swath upward to vpos - 7 */
|
|
1159 |
pre_blanklines = 2;
|
|
1160 |
}
|
|
1161 |
else if ( sweep_offset == -4 )
|
|
1162 |
{
|
|
1163 |
/* shift swath upward to vpos - 6 */
|
|
1164 |
pre_blanklines = 1;
|
|
1165 |
}
|
|
1166 |
}
|
|
1167 |
}
|
|
1168 |
/*will add pre_blanklines blank lines at the top of the swath
|
|
1169 |
and post_blanklines at the end of the swath.
|
|
1170 |
Note that allowance has been made for a possible
|
|
1171 |
extra post_blankline to compensate for odd numlines */
|
|
1172 |
break;
|
|
1173 |
}
|
|
1174 |
}
|
|
1175 |
}
|
|
1176 |
|
|
1177 |
if (got_nonblank)
|
|
1178 |
{
|
|
1179 |
/* find left-most nonblank */
|
|
1180 |
for (i = left_limit * 3; i < left * 3; i++)
|
|
1181 |
{
|
|
1182 |
// fprintf(stderr, "left: %d ", i);
|
|
1183 |
if ((data[gMaxPass - 1][width8 * 3 * numlines + i]))
|
|
1184 |
{
|
|
1185 |
left = i / 3;
|
|
1186 |
break;
|
|
1187 |
}
|
|
1188 |
}
|
|
1189 |
/* find right-most nonblank */
|
|
1190 |
for (j = right_limit * 3 - 1 ; j > right * 3 + 2 ; j--)
|
|
1191 |
{
|
|
1192 |
// fprintf(stderr, "right: %d ", i);
|
|
1193 |
if ((data[gMaxPass - 1][width8 * 3 * numlines + j]))
|
|
1194 |
{
|
|
1195 |
right = j / 3;
|
|
1196 |
break;
|
|
1197 |
}
|
|
1198 |
}
|
|
1199 |
numlines++;
|
|
1200 |
}
|
|
1201 |
}
|
|
1202 |
|
|
1203 |
if ((image->buflines >= MAXBUFFLINES) && (image->buftype == bitmap))
|
|
1204 |
{
|
|
1205 |
DPRINTF
|
|
1206 |
("cut_im_color_swath: exceeding buffer size: image.buflines=%d, MAX=%d\n",
|
|
1207 |
image->buflines, MAXBUFFLINES);
|
|
1208 |
if ((!got_nonblank))
|
|
1209 |
{
|
|
1210 |
for (k = 0; k < gMaxPass; k++)
|
|
1211 |
free (data[k]);
|
|
1212 |
return 3;
|
|
1213 |
}
|
|
1214 |
}
|
|
1215 |
|
|
1216 |
|
|
1217 |
if ((!got_nonblank))
|
|
1218 |
{
|
|
1219 |
/* eat all lines that are below the lower margin */
|
|
1220 |
if (image->colorCurLine >= bottom_limit)
|
|
1221 |
{
|
|
1222 |
while (image->colorCurLine < image->height)
|
|
1223 |
if (!im_color_readline (image, data, 0))
|
|
1224 |
{
|
|
1225 |
snprintf(syslog_message,message_size,"cut_im_color_swath(): %s",
|
|
1226 |
gMessages[E_CS_BADBOTMARG]);
|
|
1227 |
wrap_syslog (LOG_CRIT,"%s",syslog_message);
|
|
1228 |
|
|
1229 |
for (k = 0; k < gMaxPass; k++)
|
|
1230 |
{
|
|
1231 |
free (data[k]); //mocho
|
|
1232 |
}
|
|
1233 |
return 0;
|
|
1234 |
}
|
|
1235 |
for (k = 0; k < gMaxPass; k++)
|
|
1236 |
{
|
|
1237 |
free (data[k]); //mocho
|
|
1238 |
}
|
|
1239 |
DPRINTF
|
|
1240 |
("cut_im_color_swath: return 1 on line %d; ccl: %d; height: %d\n",
|
|
1241 |
__LINE__, image->colorCurLine, bottom_limit );
|
|
1242 |
return 1;
|
|
1243 |
}
|
|
1244 |
for (k = 0; k < gMaxPass; k++)
|
|
1245 |
{
|
|
1246 |
free (data[k]); //mocho
|
|
1247 |
}
|
|
1248 |
return 0;
|
|
1249 |
/* error, since didn't get to lower margin, yet blank */
|
|
1250 |
}
|
|
1251 |
|
|
1252 |
sweep_data->vertical_pos = image->colorCurLine + printer->ColBwOffsY ;
|
|
1253 |
|
|
1254 |
/* subtract that 600 dot adjustment here */
|
|
1255 |
sweep_data->vertical_pos -= vpos_shift;
|
|
1256 |
|
|
1257 |
DPRINTF("cut_im_color_swath: end swath, line %d numlines=%d left=%d right=%d\n",
|
|
1258 |
image->colorCurLine, numlines, left, right ) ;
|
|
1259 |
|
|
1260 |
|
|
1261 |
|
|
1262 |
/* calculate number of blank lines added at top and bottom of swath */
|
|
1263 |
|
|
1264 |
non_blanklines = numlines ;
|
|
1265 |
numlines += pre_blanklines ;
|
|
1266 |
if ( (numlines + post_blanklines) % 2 )
|
|
1267 |
post_blanklines++ ;
|
|
1268 |
numlines += post_blanklines ;
|
|
1269 |
assert (maxlines >= numlines );
|
|
1270 |
sweep_data->vertical_pos += 2 * post_blanklines ;
|
|
1271 |
|
|
1272 |
|
|
1273 |
even_pre_blanklines = odd_pre_blanklines = pre_blanklines / 2 ;
|
|
1274 |
even_non_blanklines = odd_non_blanklines = non_blanklines / 2 ;
|
|
1275 |
even_post_blanklines = odd_post_blanklines = post_blanklines / 2 ;
|
|
1276 |
|
|
1277 |
start_even= 0;
|
|
1278 |
start_odd = 1;
|
|
1279 |
|
|
1280 |
if ( (pre_blanklines %2 == 0) &&
|
|
1281 |
!(non_blanklines % 2 == 0) &&
|
|
1282 |
!(post_blanklines % 2 == 0))
|
|
1283 |
{
|
|
1284 |
even_non_blanklines++ ;
|
|
1285 |
odd_post_blanklines++;
|
|
1286 |
start_even= 0;
|
|
1287 |
start_odd = 1;
|
|
1288 |
}
|
|
1289 |
if ( !(pre_blanklines %2 == 0) &&
|
|
1290 |
!(non_blanklines % 2 == 0) &&
|
|
1291 |
(post_blanklines % 2 == 0))
|
|
1292 |
{
|
|
1293 |
even_pre_blanklines++;
|
|
1294 |
odd_non_blanklines++;
|
|
1295 |
start_even= 1;
|
|
1296 |
start_odd = 0;
|
|
1297 |
}
|
|
1298 |
if ( !(pre_blanklines %2 == 0) &&
|
|
1299 |
(non_blanklines % 2 == 0) &&
|
|
1300 |
!(post_blanklines % 2 == 0))
|
|
1301 |
{
|
|
1302 |
even_pre_blanklines++;
|
|
1303 |
odd_post_blanklines++;
|
|
1304 |
start_even= 1;
|
|
1305 |
start_odd = 0;
|
|
1306 |
}
|
|
1307 |
|
|
1308 |
|
|
1309 |
assert ( numlines % 2 == 0);
|
|
1310 |
assert (( even_pre_blanklines +
|
|
1311 |
even_non_blanklines +
|
|
1312 |
even_post_blanklines ) == numlines/2 );
|
|
1313 |
assert (( odd_pre_blanklines +
|
|
1314 |
odd_non_blanklines +
|
|
1315 |
odd_post_blanklines ) == numlines/2 );
|
|
1316 |
|
|
1317 |
|
|
1318 |
if (pre_blanklines)
|
|
1319 |
{
|
|
1320 |
DPRINTF("cut_im_color_swath: offset %d; add pre_blanklines=%d lines\n",
|
|
1321 |
sweep_offset, pre_blanklines);
|
|
1322 |
}
|
|
1323 |
if (post_blanklines)
|
|
1324 |
{
|
|
1325 |
DPRINTF("cut_im_color_swath: offset %d; add post_blanklines=%d lines\n",
|
|
1326 |
sweep_offset, post_blanklines);
|
|
1327 |
}
|
|
1328 |
|
|
1329 |
|
|
1330 |
/* printing in the leftmost and rightmost bytes of the color
|
|
1331 |
* swath leads to problems, so expand the swath width to avoid
|
|
1332 |
* using these locations. Nothing will ever get printed in these
|
|
1333 |
* expanded ends of the swath. (They are either whitespace,
|
|
1334 |
* or outside the limits, where data is rejected below)
|
|
1335 |
*/
|
|
1336 |
left -= 2;
|
|
1337 |
right += 3;
|
|
1338 |
p_width8 = right - left ;
|
|
1339 |
|
|
1340 |
/* enforce a minimum swath width of 8 bytes */
|
|
1341 |
if ( p_width8 < 8 )
|
|
1342 |
{
|
|
1343 |
if (left > left_limit + 8 )
|
|
1344 |
left = left - 8 + p_width8 ;
|
|
1345 |
else
|
|
1346 |
right = right + 8 - p_width8 ;
|
|
1347 |
}
|
|
1348 |
p_width8 = right - left ;
|
|
1349 |
|
|
1350 |
/* always left-to-right if gUnimode is true */
|
|
1351 |
if (gUnimode)
|
|
1352 |
sweep_data->direction = left_to_right;
|
|
1353 |
else if ((b_vpos > c_vpos) && (b_vpos < sweep_data->vertical_pos))
|
|
1354 |
{
|
|
1355 |
if (b_dir == left_to_right)
|
|
1356 |
sweep_data->direction = right_to_left;
|
|
1357 |
else
|
|
1358 |
sweep_data->direction = left_to_right;
|
|
1359 |
} else
|
|
1360 |
{
|
|
1361 |
if (c_dir == left_to_right)
|
|
1362 |
sweep_data->direction = right_to_left;
|
|
1363 |
else
|
|
1364 |
sweep_data->direction = left_to_right;
|
|
1365 |
}
|
|
1366 |
|
|
1367 |
DPRINTF("cut_im_color_swath: b_left %d b_right %d b_vpos %d b_dir %d\n",
|
|
1368 |
b_left, b_right, b_vpos, b_dir);
|
|
1369 |
DPRINTF("cut_im_color_swath: prev c_left %d c_right %d c_vpos %d c_dir %d\n",
|
|
1370 |
c_left, c_right, c_vpos, c_dir);
|
|
1371 |
DPRINTF("cut_im_color_swath: cur left %d right %d vpos %d dir %d\n",
|
|
1372 |
left, right, sweep_data->vertical_pos, sweep_data->direction);
|
|
1373 |
c_left = left;
|
|
1374 |
c_right = right;
|
|
1375 |
c_vpos = sweep_data->vertical_pos;
|
|
1376 |
c_dir = sweep_data->direction;
|
|
1377 |
|
|
1378 |
|
|
1379 |
for (k = 0; k < gMaxPass; k++)
|
|
1380 |
{
|
|
1381 |
if ((ppa = malloc ( (p_width8 + 3 ) * numlines * 3)) == NULL)
|
|
1382 |
{
|
|
1383 |
snprintf(syslog_message,message_size,"cut_im_color_swath(): %s",
|
|
1384 |
gMessages[E_CS_BADPPAMALLOC]);
|
|
1385 |
wrap_syslog (LOG_CRIT,"%s",syslog_message);
|
|
1386 |
|
|
1387 |
for (k = 0; k < gMaxPass; k++)
|
|
1388 |
free (data[k]);
|
|
1389 |
return 0;
|
|
1390 |
}
|
|
1391 |
|
|
1392 |
place = ppa;
|
|
1393 |
|
|
1394 |
if (sweep_data->direction == right_to_left)
|
|
1395 |
{
|
|
1396 |
for (i = (p_width8 + 1) * 6 - 1 ; i >= 0; i--)
|
|
1397 |
{
|
|
1398 |
int color, x, odd, y ;
|
|
1399 |
j = (p_width8 + 1) * 6 - 1 - i ;
|
|
1400 |
if (i < Left_size )
|
|
1401 |
{
|
|
1402 |
if (!GET_USABLE (Left_r2l, i))
|
|
1403 |
{
|
|
1404 |
memset (place, 0x00, numlines / 2);
|
|
1405 |
place += numlines / 2;
|
|
1406 |
continue;
|
|
1407 |
}
|
|
1408 |
odd = GET_ODD (Left_r2l, i );
|
|
1409 |
color = GET_COLOR (Left_r2l, i);
|
|
1410 |
x = GET_X (Left_r2l, i );
|
|
1411 |
}
|
|
1412 |
else if (j < Right_size )
|
|
1413 |
{
|
|
1414 |
if (!GET_USABLE (Right_r2l,j))
|
|
1415 |
{
|
|
1416 |
memset (place, 0x00, numlines / 2);
|
|
1417 |
place += numlines / 2;
|
|
1418 |
continue;
|
|
1419 |
}
|
|
1420 |
color = GET_COLOR (Right_r2l, j);
|
|
1421 |
odd = GET_ODD (Right_r2l, j);
|
|
1422 |
x = p_width8 - 3 - GET_X (Right_r2l, j);
|
|
1423 |
}
|
|
1424 |
else
|
|
1425 |
{
|
|
1426 |
color = (i / 2 - 15) % 3;
|
|
1427 |
odd = (i + 1) % 2;
|
|
1428 |
x = (i - 24) / 6 - 1 + odd + (color == 0 ? 0 :/* cyan */
|
|
1429 |
color == 1 ? 4 :/* magenta */
|
|
1430 |
8); /* yellow */
|
|
1431 |
}
|
|
1432 |
if (x + left < left_limit || x + left >= right_limit)
|
|
1433 |
{
|
|
1434 |
/* never print data that is outside the limits */
|
|
1435 |
memset (place, 0x00, numlines / 2);
|
|
1436 |
place += numlines / 2;
|
|
1437 |
}
|
|
1438 |
else
|
|
1439 |
{
|
|
1440 |
int new_pre_blanklines , new_non_blanklines , new_post_blanklines;
|
|
1441 |
int new_start;
|
|
1442 |
if (odd)
|
|
1443 |
{
|
|
1444 |
/* odd lines */
|
|
1445 |
new_pre_blanklines = odd_pre_blanklines ;
|
|
1446 |
new_non_blanklines = odd_non_blanklines ;
|
|
1447 |
new_post_blanklines = odd_post_blanklines ;
|
|
1448 |
new_start = start_odd;
|
|
1449 |
}
|
|
1450 |
else
|
|
1451 |
{
|
|
1452 |
/* even lines */
|
|
1453 |
new_pre_blanklines = even_pre_blanklines ;
|
|
1454 |
new_non_blanklines = even_non_blanklines ;
|
|
1455 |
new_post_blanklines = even_post_blanklines ;
|
|
1456 |
new_start = start_even;
|
|
1457 |
}
|
|
1458 |
if ( new_pre_blanklines > 0 )
|
|
1459 |
{
|
|
1460 |
/* first pre_blanklines lines are blank */
|
|
1461 |
memset(place, 0x00, new_pre_blanklines ) ;
|
|
1462 |
place += new_pre_blanklines ;
|
|
1463 |
}
|
|
1464 |
for (y = 0; y < new_non_blanklines ; y++)
|
|
1465 |
{
|
|
1466 |
int index ;
|
|
1467 |
index = ( (y * 2 + new_start) * width8 * 3 +
|
|
1468 |
(x + left ) * 3 + color ) ;
|
|
1469 |
|
|
1470 |
if (index >= (width8 * 3 * maxlines ))
|
|
1471 |
{
|
|
1472 |
DPRINTF ("index out of range! index = %d\n", index);
|
|
1473 |
index = (width8 * 3 * maxlines ) - 1;
|
|
1474 |
}
|
|
1475 |
|
|
1476 |
assert ( index < width8 * 3 * maxlines && index >= 0 );
|
|
1477 |
*place++ = data[k][index];
|
|
1478 |
}
|
|
1479 |
if ( new_post_blanklines > 0 )
|
|
1480 |
{
|
|
1481 |
/* last post_blanklines lines are blank */
|
|
1482 |
memset(place, 0x00, new_post_blanklines ) ;
|
|
1483 |
place += new_post_blanklines ;
|
|
1484 |
}
|
|
1485 |
}
|
|
1486 |
}
|
|
1487 |
|
|
1488 |
}
|
|
1489 |
else /* sweep direction is left-to-right */
|
|
1490 |
{
|
|
1491 |
for (i = 0; i < (p_width8 + 1) * 6 ; i++)
|
|
1492 |
{
|
|
1493 |
int color, x, odd, y;
|
|
1494 |
j = (p_width8 + 1) * 6 - 1 - i ;
|
|
1495 |
if (i < Left_size)
|
|
1496 |
{
|
|
1497 |
if (!GET_USABLE (Left_l2r, i))
|
|
1498 |
{
|
|
1499 |
memset (place, 0x00, numlines / 2);
|
|
1500 |
place += numlines / 2;
|
|
1501 |
continue;
|
|
1502 |
}
|
|
1503 |
color = GET_COLOR (Left_l2r, i);
|
|
1504 |
odd = GET_ODD (Left_l2r, i);
|
|
1505 |
x = GET_X (Left_l2r, i);
|
|
1506 |
}
|
|
1507 |
else if ( j < Right_size )
|
|
1508 |
{
|
|
1509 |
if (!GET_USABLE (Right_l2r, j))
|
|
1510 |
{
|
|
1511 |
memset (place, 0x00, numlines / 2);
|
|
1512 |
place += numlines / 2;
|
|
1513 |
continue;
|
|
1514 |
}
|
|
1515 |
color = GET_COLOR (Right_l2r, j);
|
|
1516 |
odd = GET_ODD (Right_l2r, j);
|
|
1517 |
x = p_width8 -3 - GET_X (Right_l2r,j);
|
|
1518 |
}
|
|
1519 |
else
|
|
1520 |
{
|
|
1521 |
color = (i / 2 - 15) % 3;
|
|
1522 |
odd = i % 2;
|
|
1523 |
x = (i - 24) / 6 - 1 + odd + (color == 0 ? 0 :/* cyan */
|
|
1524 |
color == 1 ? 4 :/* magenta */
|
|
1525 |
8); /* yellow */
|
|
1526 |
}
|
|
1527 |
if (x + left < left_limit || x + left >= right_limit)
|
|
1528 |
{
|
|
1529 |
/* never print data that is outside the limits */
|
|
1530 |
memset (place, 0x00, numlines / 2);
|
|
1531 |
place += numlines / 2;
|
|
1532 |
}
|
|
1533 |
else
|
|
1534 |
{
|
|
1535 |
int new_pre_blanklines , new_non_blanklines , new_post_blanklines;
|
|
1536 |
int new_start;
|
|
1537 |
if (odd)
|
|
1538 |
{
|
|
1539 |
/* odd lines */
|
|
1540 |
new_pre_blanklines = odd_pre_blanklines ;
|
|
1541 |
new_non_blanklines = odd_non_blanklines ;
|
|
1542 |
new_post_blanklines = odd_post_blanklines ;
|
|
1543 |
new_start = start_odd;
|
|
1544 |
}
|
|
1545 |
else
|
|
1546 |
{
|
|
1547 |
/* even lines */
|
|
1548 |
new_pre_blanklines = even_pre_blanklines ;
|
|
1549 |
new_non_blanklines = even_non_blanklines ;
|
|
1550 |
new_post_blanklines = even_post_blanklines ;
|
|
1551 |
new_start = start_even;
|
|
1552 |
}
|
|
1553 |
if ( new_pre_blanklines > 0 )
|
|
1554 |
{
|
|
1555 |
/* first pre_blanklines lines are blank */
|
|
1556 |
memset (place, 0x00, new_pre_blanklines ) ;
|
|
1557 |
place += new_pre_blanklines ;
|
|
1558 |
}
|
|
1559 |
for (y = 0; y < new_non_blanklines; y++)
|
|
1560 |
{
|
|
1561 |
int index ;
|
|
1562 |
index = ((y * 2 + new_start) * width8 * 3 +
|
|
1563 |
(x + left ) * 3 + color);
|
|
1564 |
|
|
1565 |
if (index >= (width8 * 3 * maxlines + 8))
|
|
1566 |
{
|
|
1567 |
DPRINTF ("index out of range! index = %d\n",index);
|
|
1568 |
index = (width8 * 3 * maxlines + 8) - 1;
|
|
1569 |
}
|
|
1570 |
|
|
1571 |
assert ( index < width8 * 3 * maxlines + 8 && index >= 0 );
|
|
1572 |
*place++ = data[k][index];
|
|
1573 |
}
|
|
1574 |
if ( new_post_blanklines > 0 )
|
|
1575 |
{
|
|
1576 |
/* last post_blanklines lines are blank */
|
|
1577 |
memset(place, 0x00, new_post_blanklines) ;
|
|
1578 |
place += new_post_blanklines ;
|
|
1579 |
}
|
|
1580 |
}
|
|
1581 |
}
|
|
1582 |
}
|
|
1583 |
maxplace = place;
|
|
1584 |
|
|
1585 |
/* create sweep data */
|
|
1586 |
sweep_data->image_data[k] = ppa;
|
|
1587 |
}
|
|
1588 |
|
|
1589 |
sweep_data->data_size = maxplace - ppa;
|
|
1590 |
sweep_data->in_color = true;
|
|
1591 |
|
|
1592 |
horzpos = (left - 7) * 8 * 2 + printer->ColBwOffsX - 600 ;
|
|
1593 |
|
|
1594 |
horzpos += (sweep_data->direction == left_to_right) ? 2 : 12 ;
|
|
1595 |
|
|
1596 |
if (sweep_data->direction == right_to_left )
|
|
1597 |
horzpos += printer->r2l_col_offset ; /*correct bidirectional shearing*/
|
|
1598 |
|
|
1599 |
hp2 = 16 + horzpos + p_width8 * 2 * 8;
|
|
1600 |
sweep_data->left_margin = horzpos;
|
|
1601 |
sweep_data->right_margin = hp2 + 0x74; /* printer->color_marg_diff */
|
|
1602 |
|
|
1603 |
DPRINTF("sweep data: left_margin = %d, right margin = %d\n",
|
|
1604 |
sweep_data->left_margin, sweep_data->right_margin);
|
|
1605 |
|
|
1606 |
for (i = 0; i < 6; i++)
|
|
1607 |
{
|
|
1608 |
nozzles[i].DPI = 300;
|
|
1609 |
nozzles[i].pins_used_d2 = numlines / 2;
|
|
1610 |
nozzles[i].unused_pins_p1 = 65 - numlines;
|
|
1611 |
nozzles[i].first_pin = 1;
|
|
1612 |
if (i == 0)
|
|
1613 |
{
|
|
1614 |
nozzles[i].left_margin = horzpos + 0x74;
|
|
1615 |
nozzles[i].right_margin = hp2 + 0x74;
|
|
1616 |
if (sweep_data->direction == right_to_left)
|
|
1617 |
nozzles[i].nozzle_delay = 0;
|
|
1618 |
else
|
|
1619 |
nozzles[i].nozzle_delay = 0;
|
|
1620 |
}
|
|
1621 |
if (i == 1)
|
|
1622 |
{
|
|
1623 |
nozzles[i].left_margin = horzpos + 0x64;
|
|
1624 |
nozzles[i].right_margin = hp2 + 0x64;
|
|
1625 |
if (sweep_data->direction == right_to_left)
|
|
1626 |
nozzles[i].nozzle_delay = 0;
|
|
1627 |
else
|
|
1628 |
nozzles[i].nozzle_delay = 0;
|
|
1629 |
}
|
|
1630 |
if (i == 2)
|
|
1631 |
{
|
|
1632 |
nozzles[i].left_margin = horzpos + 0x3A;
|
|
1633 |
nozzles[i].right_margin = hp2 + 0x3A;
|
|
1634 |
if (sweep_data->direction == right_to_left)
|
|
1635 |
nozzles[i].nozzle_delay = 0x0A;
|
|
1636 |
else
|
|
1637 |
nozzles[i].nozzle_delay = 0x0A;
|
|
1638 |
}
|
|
1639 |
if (i == 3)
|
|
1640 |
{
|
|
1641 |
nozzles[i].left_margin = horzpos + 0x3A;
|
|
1642 |
nozzles[i].right_margin = hp2 + 0x3A;
|
|
1643 |
if (sweep_data->direction == right_to_left)
|
|
1644 |
nozzles[i].nozzle_delay = 0x0A;
|
|
1645 |
else
|
|
1646 |
nozzles[i].nozzle_delay = 0x0A;
|
|
1647 |
|
|
1648 |
}
|
|
1649 |
if (i == 4)
|
|
1650 |
{
|
|
1651 |
nozzles[i].left_margin = horzpos + 0x10;
|
|
1652 |
nozzles[i].right_margin = hp2 + 0x10;
|
|
1653 |
if (sweep_data->direction == right_to_left)
|
|
1654 |
nozzles[i].nozzle_delay = 0x04;
|
|
1655 |
else
|
|
1656 |
nozzles[i].nozzle_delay = 0x04;
|
|
1657 |
|
|
1658 |
}
|
|
1659 |
if (i == 5)
|
|
1660 |
{
|
|
1661 |
nozzles[i].left_margin = horzpos + 0x00;
|
|
1662 |
nozzles[i].right_margin = hp2 + 0x00;
|
|
1663 |
if (sweep_data->direction == right_to_left)
|
|
1664 |
nozzles[i].nozzle_delay = 0x04;
|
|
1665 |
else
|
|
1666 |
nozzles[i].nozzle_delay = 0x04;
|
|
1667 |
|
|
1668 |
}
|
|
1669 |
}
|
|
1670 |
|
|
1671 |
sweep_data->nozzle_data_size = 6;
|
|
1672 |
sweep_data->nozzle_data = malloc (sizeof (nozzles));
|
|
1673 |
if (sweep_data->nozzle_data == NULL)
|
|
1674 |
return 0;
|
|
1675 |
memcpy (sweep_data->nozzle_data, nozzles, sizeof (nozzles));
|
|
1676 |
|
|
1677 |
DPRINTF ("cut_im_color_swath: return 2 on line %d\n", __LINE__);
|
|
1678 |
|
|
1679 |
for (k = 0; k < gMaxPass; k++)
|
|
1680 |
free (data[k]);
|
|
1681 |
|
|
1682 |
return 2;
|
|
1683 |
|
|
1684 |
}
|
|
1685 |
|
|
1686 |
/*
|
|
1687 |
|
|
1688 |
Here, we should call cut_im_black_swath and cut_im_color_swath to begin.
|
|
1689 |
|
|
1690 |
Then, we need to determine which of these swaths comes earlier on the page
|