Line 0
Link Here
|
|
|
1 |
/* |
2 |
This file is part of GNU Ghostscript. |
3 |
|
4 |
GNU Ghostscript is distributed in the hope that it will be useful, but |
5 |
WITHOUT ANY WARRANTY. No author or distributor accepts responsibility to |
6 |
anyone for the consequences of using it or for whether it serves any |
7 |
particular purpose or works at all, unless he says so in writing. Refer to |
8 |
the GNU General Public License for full details. |
9 |
|
10 |
Everyone is granted permission to copy, modify and redistribute GNU |
11 |
Ghostscript, but only under the conditions described in the GNU General |
12 |
Public License. A copy of this license is supposed to have been given to |
13 |
you along with GNU Ghostscript so you can know your rights and |
14 |
responsibilities. It should be in a file named COPYING. Among other |
15 |
things, the copyright notice and this notice must be preserved on all |
16 |
copies. |
17 |
|
18 |
Aladdin Enterprises is not affiliated with the Free Software Foundation or |
19 |
the GNU Project. GNU Ghostscript, as distributed by Aladdin Enterprises, |
20 |
does not depend on any other GNU software. |
21 |
*/ |
22 |
|
23 |
/* gdevgdi.c */ |
24 |
/* SAMSUNG GDI driver for Ghostscript */ |
25 |
#include "gdevprn.h" |
26 |
#include "gdevpcl.h" |
27 |
|
28 |
|
29 |
/* |
30 |
* You may select a default resolution of 300 or 600 DPI |
31 |
* in the makefile, or an actual resolution |
32 |
* on the gs command line. |
33 |
* |
34 |
* If the preprocessor symbol A4 is defined, the default paper size is |
35 |
* the European A4 size; otherwise it is the U.S. letter size (8.5"x11"). |
36 |
* |
37 |
* To determine the proper "margin" settings for your printer, see the |
38 |
* file align.ps. |
39 |
*/ |
40 |
|
41 |
/* Define the default, maximum resolutions. */ |
42 |
#ifdef X_DPI |
43 |
# define X_DPI2 X_DPI |
44 |
#else |
45 |
# define X_DPI 300 |
46 |
# define X_DPI2 600 |
47 |
#endif |
48 |
#ifdef Y_DPI |
49 |
# define Y_DPI2 Y_DPI |
50 |
#else |
51 |
# define Y_DPI 300 |
52 |
# define Y_DPI2 600 |
53 |
#endif |
54 |
|
55 |
#define GDI_FALSE 0 |
56 |
#define GDI_TRUE 1 |
57 |
#define GDI_MAX_COUNT 31 |
58 |
#define GDI_NO_REPEAT_IDX 0x80000000L |
59 |
#define GDI_DATA_LENGTH 11 |
60 |
#define GDI_REPEAT_LENGTH 2 |
61 |
#define GDI_BAND_HEIGHT 128 |
62 |
#define GDI_MAX_BAND 66 |
63 |
//#define GDI_BAND_WIDTH 4928 |
64 |
//#define GDI_BAND_WIDTH_BYTES (((GDI_BAND_WIDTH + 31)/32)*4) |
65 |
|
66 |
#define GDI_PRE_COMP 2 |
67 |
#define GDI_REAL_COMP 0 |
68 |
|
69 |
#define GDI_COMP_NONE 0 |
70 |
#define GDI_COMP_TIFF 3 |
71 |
#define GDI_COMP_SCANLINE 4 |
72 |
#define GDI_COMP_MODITIFF 6 |
73 |
#define GDI_COMP_NOSEND 0x7f |
74 |
|
75 |
#define GDI_MARGINS_A4 0.167, 0.167, 0.167, 0.167 |
76 |
#define GDI_MARGINS_LETTER 0.167, 0.167, 0.167, 0.167 |
77 |
//#define GDI_MARGINS_A4 0.0, 0.0, 0.0, 0.0 |
78 |
//#define GDI_MARGINS_LETTER 0.0, 0.0, 0.0, 0.0 |
79 |
|
80 |
/* The number of blank lines that make it worthwhile to reposition */ |
81 |
/* the cursor. */ |
82 |
#define MIN_SKIP_LINES 7 |
83 |
|
84 |
/* We round up the LINE_SIZE to a multiple of a unsigned long for faster scanning. */ |
85 |
#define W sizeof(word) |
86 |
|
87 |
int GDI_BAND_WIDTH[] = {4768, 4928}; |
88 |
|
89 |
private int gdi_print_page(P2(gx_device_printer *pdev, FILE *prn_stream)); |
90 |
private int gdi_open(P1(gx_device *pdev)); |
91 |
private int gdi_close(P1(gx_device *pdev)); |
92 |
|
93 |
/* The device descriptors */ |
94 |
private dev_proc_open_device(gdi_open); |
95 |
private dev_proc_close_device(gdi_close); |
96 |
private dev_proc_print_page(gdi_print_page); |
97 |
|
98 |
private gx_device_procs prn_gdi_procs = |
99 |
prn_params_procs(gdi_open, gdev_prn_output_page, gdi_close, |
100 |
gdev_prn_get_params, gdev_prn_put_params); |
101 |
|
102 |
gx_device_printer far_data gs_gdi_device = |
103 |
prn_device(prn_gdi_procs, "gdi", |
104 |
DEFAULT_WIDTH_10THS, DEFAULT_HEIGHT_10THS, /* paper size (unit : 10/72 inch size) */ |
105 |
X_DPI2, Y_DPI2, |
106 |
0.20, 0.25, 0.25, 0.25, /* margins filled in by gdi_open */ |
107 |
1, /* color bit */ |
108 |
gdi_print_page); |
109 |
|
110 |
private FILE *WritePJLHeaderData(gx_device_printer *pdev, FILE *fp); |
111 |
private FILE *WriteBandHeader(FILE *fp, unsigned int usBandNo, |
112 |
unsigned char ubCompMode, unsigned int usBandWidth, |
113 |
unsigned int usBandHeight, unsigned long ulBandSize); |
114 |
private FILE *WriteTrailerData(FILE *fp); |
115 |
private unsigned long FrameTiffComp(unsigned char *pubDest, unsigned char *pubSrc, |
116 |
unsigned int usTotalLines, unsigned int usBytesPerLine, |
117 |
unsigned char ubMode); |
118 |
private unsigned int FrameTiff_Comp(unsigned char *lpSrcBuf, unsigned char *lpTgtBuf, |
119 |
unsigned int nSrcBytes); |
120 |
private unsigned int PreTiffComp(unsigned char *lpSrcBuf, unsigned int nSrcBytes); |
121 |
private long bmp2run(unsigned char *out_buf, unsigned char *in_buf, unsigned int sizeY, unsigned int sizeX, unsigned char ubMode); |
122 |
|
123 |
#define ppdev ((gx_device_printer *)pdev) |
124 |
|
125 |
/* Open the printer, adjusting the margins if necessary. */ |
126 |
private int |
127 |
gdi_open(gx_device *pdev) |
128 |
{ /* Change the margins if necessary. */ |
129 |
const float *m = 0; |
130 |
bool move_origin = true; |
131 |
|
132 |
static const float m_a4[4] = { GDI_MARGINS_A4 }; |
133 |
static const float m_letter[4] = { GDI_MARGINS_LETTER }; |
134 |
m = (gdev_pcl_paper_size(pdev) == PAPER_SIZE_A4 ? m_a4 : |
135 |
m_letter); |
136 |
move_origin = false; |
137 |
|
138 |
if ( m != 0 ) |
139 |
gx_device_set_margins(pdev, m, move_origin); |
140 |
|
141 |
return gdev_prn_open(pdev); |
142 |
} |
143 |
|
144 |
/* gdi_close is only here to eject odd numbered pages in duplex mode. */ |
145 |
private int |
146 |
gdi_close(gx_device *pdev) |
147 |
{ if ( ppdev->Duplex_set >= 0 && ppdev->Duplex ) |
148 |
{ gdev_prn_open_printer(pdev, 1); |
149 |
fputs("\033&l0H", ppdev->file) ; |
150 |
} |
151 |
return gdev_prn_close(pdev); |
152 |
} |
153 |
|
154 |
#undef ppdev |
155 |
|
156 |
/* ------ Internal routines ------ */ |
157 |
|
158 |
/* Samsung SmartGDI series compresses, and it needs a special sequence to */ |
159 |
/* allow it to specify coordinates at 600 dpi. */ |
160 |
/* It too needs its coordinate system translated slightly. */ |
161 |
|
162 |
private int |
163 |
gdi_print_page(gx_device_printer *pdev, FILE *prn_stream) |
164 |
{ |
165 |
int band_width_bytes; |
166 |
int band_height; |
167 |
int code=0, i, j, y, num_rows=0, band_num=0; |
168 |
int dots_per_inch = (int)pdev->y_pixels_per_inch; |
169 |
int raster = gx_device_raster((gx_device *)pdev, true); |
170 |
int real_line_width; |
171 |
long ul_band_size, ul_comp_size, ul_tiff_size, ul_min_size; |
172 |
byte *ibp=NULL, *obp=NULL, *tmp=NULL; |
173 |
byte paper_type=0, compression_type; |
174 |
|
175 |
switch (gdev_pcl_paper_size((gx_device*)pdev)) |
176 |
{ |
177 |
case PAPER_SIZE_A4 : paper_type = 0; |
178 |
break; |
179 |
case PAPER_SIZE_LETTER : paper_type = 1; |
180 |
break; |
181 |
case PAPER_SIZE_LEGAL : paper_type = 1; |
182 |
break; |
183 |
default: |
184 |
paper_type = 1; |
185 |
break; |
186 |
} |
187 |
if (dots_per_inch == 600) { /* 600dpi */ |
188 |
band_width_bytes = (GDI_BAND_WIDTH[paper_type]+31)/32*4; |
189 |
band_height = GDI_BAND_HEIGHT; |
190 |
} else { /* 300dpi */ |
191 |
band_width_bytes = (GDI_BAND_WIDTH[paper_type]+31)/32*4/2; |
192 |
band_height = GDI_BAND_HEIGHT*2; |
193 |
} |
194 |
|
195 |
ul_band_size = band_width_bytes * band_height; |
196 |
ibp = (byte *)gs_malloc(ul_band_size, 1, "gdi_print_page"); |
197 |
obp = (byte *)gs_malloc(ul_band_size*13/10, 1, "gdi_print_page"); |
198 |
tmp = (byte *)gs_malloc(raster, 1, "gdi_print_page"); |
199 |
|
200 |
if (!ibp) return_error(gs_error_VMerror); |
201 |
if (!obp) return_error(gs_error_VMerror); |
202 |
if (!tmp) return_error(gs_error_VMerror); |
203 |
|
204 |
if (ibp ==0 || obp == 0) return_error(gs_error_VMerror); |
205 |
|
206 |
/* Header Output */ |
207 |
prn_stream = WritePJLHeaderData(pdev, prn_stream); |
208 |
num_rows = dev_print_scan_lines(pdev); |
209 |
band_num = (num_rows + band_height -1)/band_height; |
210 |
|
211 |
if (raster > band_width_bytes) |
212 |
real_line_width = band_width_bytes; |
213 |
else |
214 |
real_line_width = raster; |
215 |
|
216 |
/* Real Data Output */ |
217 |
y = 0; |
218 |
for (i=0; i< band_num; i++) { |
219 |
memset(ibp, 0x00, ul_band_size); |
220 |
memset(obp, 0x00, ul_band_size*13/10); |
221 |
for (j=0; j<band_height; j++) { |
222 |
memset(tmp, 0x00, raster); |
223 |
//code = gdev_prn_copy_scan_lines(pdev, i*band_height+j, |
224 |
if (y == num_rows) break; |
225 |
code = gdev_prn_copy_scan_lines(pdev, y++, |
226 |
(byte*)tmp, raster); |
227 |
if (code < 0) break; |
228 |
memcpy(ibp+j*band_width_bytes, tmp, real_line_width); |
229 |
} |
230 |
|
231 |
if ( i>= GDI_MAX_BAND) continue; |
232 |
|
233 |
/* Write Band Data |
234 |
Because of Scanline compression, extract Scanline compression mode */ |
235 |
//ul_tiff_size = FrameTiffComp(obp, ibp, band_height, band_width_bytes, GDI_PRE_COMP); |
236 |
//ul_scan_size = (unsigned long)bmp2run(obp, ibp, band_height, band_width_bytes, GDI_PRE_COMP); |
237 |
//ul_min_size = (ul_scan_size > ul_tiff_size) ? ul_tiff_size : ul_scan_size; |
238 |
ul_min_size = ul_tiff_size; |
239 |
compression_type = GDI_COMP_MODITIFF; |
240 |
//compression_type = (ul_scan_size > ul_tiff_size) ? GDI_COMP_MODITIFF : GDI_COMP_SCANLINE; |
241 |
switch (compression_type) { |
242 |
case GDI_COMP_MODITIFF: |
243 |
ul_comp_size = FrameTiffComp(obp, ibp, band_height, band_width_bytes, GDI_REAL_COMP); |
244 |
break; |
245 |
case GDI_COMP_SCANLINE: |
246 |
ul_comp_size = bmp2run(obp, ibp, band_height, band_width_bytes, GDI_REAL_COMP); |
247 |
break; |
248 |
default: |
249 |
ul_comp_size = FrameTiffComp(obp, ibp, band_height, band_width_bytes, GDI_REAL_COMP); |
250 |
compression_type = GDI_COMP_MODITIFF; |
251 |
break; |
252 |
} |
253 |
|
254 |
prn_stream = WriteBandHeader(prn_stream, i, compression_type, (band_width_bytes * 8), |
255 |
band_height, ul_comp_size); |
256 |
//fprintf(prn_stream, "[%d] band, size : %d\n", i, ul_tiff_size); |
257 |
fwrite(obp, ul_comp_size, 1, prn_stream); |
258 |
} |
259 |
|
260 |
/* Trailer Output */ |
261 |
WriteTrailerData(prn_stream); |
262 |
gs_free(ibp, ul_band_size, 1, "gdi_line_buffer"); |
263 |
gs_free(obp, ul_band_size*13/10, 1, "gdi_line_buffer"); |
264 |
gs_free(tmp, raster, 1, "gdi_line_buffer"); |
265 |
return code; |
266 |
} |
267 |
|
268 |
FILE *WritePJLHeaderData(gx_device_printer *pdev, FILE *fp) |
269 |
{ |
270 |
unsigned long ulSize; |
271 |
unsigned char buffer[300]; |
272 |
int dots_per_inch = (int)pdev->y_pixels_per_inch; |
273 |
|
274 |
strcpy(buffer, "\x1b%-12345X"); |
275 |
|
276 |
// Paper Type |
277 |
strcat(buffer, "@PJL SET PAPERTYPE = NORMAL ON\x0d\x0a"); |
278 |
//Density |
279 |
strcat(buffer, "@PJL SET DENSITY = 1\x0d\x0a"); |
280 |
// Toner Save |
281 |
strcat(buffer, "@PJL SET TONERSAVE = OFF\x0d\x0a"); |
282 |
// Enter Language SMART |
283 |
strcat(buffer, "@PJL ENTER LANGUAGE = SMART\x0d\x0a"); |
284 |
// JobStart |
285 |
strcat(buffer, "$PJL JOB START\x0d\x0a"); |
286 |
|
287 |
// Resolution |
288 |
if (dots_per_inch == 600) |
289 |
strcat(buffer, "$PJL RESOLUTION = 600\x0d\x0a"); |
290 |
else |
291 |
strcat(buffer, "$PJL RESOLUTION = 300\x0d\x0a"); |
292 |
|
293 |
// Copies |
294 |
strcat(buffer, "$PJL COPIES = 1\x0d\x0a"); |
295 |
// Paper Size |
296 |
switch (gdev_pcl_paper_size((gx_device*)pdev)) |
297 |
{ |
298 |
case PAPER_SIZE_A4: |
299 |
strcat(buffer, "$PJL PAGE A4 AUTO\x0d\x0a"); |
300 |
break; |
301 |
case PAPER_SIZE_LETTER: |
302 |
strcat(buffer, "$PJL PAGE LETTER AUTO\x0d\x0a"); |
303 |
break; |
304 |
case PAPER_SIZE_LEGAL: |
305 |
strcat(buffer, "$PJL PAGE LEGAL AUTO\x0d\x0a"); |
306 |
break; |
307 |
default: |
308 |
strcat(buffer, "$PJL PAGE LETTER AUTO\x0d\x0a"); |
309 |
break; |
310 |
} |
311 |
// bitmap start |
312 |
strcat(buffer, "$PJL BITMAP START\x0d\x0a"); |
313 |
// write buffer to file. |
314 |
ulSize = strlen(buffer); |
315 |
fwrite(buffer, 1, ulSize, fp ); |
316 |
return(fp); |
317 |
} // WritePJLHeaderData() |
318 |
|
319 |
|
320 |
FILE *WriteBandHeader |
321 |
( |
322 |
FILE *fp, |
323 |
unsigned int usBandNo, |
324 |
unsigned char ubCompMode, |
325 |
unsigned int usBandWidth, |
326 |
unsigned int usBandHeight, |
327 |
unsigned long ulBandSize |
328 |
) |
329 |
{ |
330 |
unsigned char ubLeft=0; |
331 |
unsigned int i = 0; |
332 |
unsigned char buf[50]; |
333 |
|
334 |
memset(buf, 0x00, 50); |
335 |
|
336 |
ulBandSize += 8; |
337 |
|
338 |
// bandsize |
339 |
buf[i++] = (unsigned char)((ulBandSize >> 24) & 0xff); |
340 |
buf[i++] = (unsigned char)((ulBandSize >> 16) & 0xff); |
341 |
buf[i++] = (unsigned char)((ulBandSize >> 8) & 0xff); |
342 |
buf[i++] = (unsigned char)(ulBandSize & 0xff); |
343 |
|
344 |
// id |
345 |
buf[i++] = (unsigned char)((usBandNo >> 8) & 0xff); |
346 |
buf[i++] = (unsigned char)(usBandNo & 0xff); |
347 |
|
348 |
// compress mode |
349 |
buf[i++] = (unsigned char)(ubCompMode & 0xff); |
350 |
|
351 |
// ubLeft |
352 |
buf[i++] = (unsigned char)(ubLeft & 0xff); |
353 |
|
354 |
// height |
355 |
buf[i++] = (unsigned char)((usBandHeight >> 8) & 0xff); |
356 |
buf[i++] = (unsigned char)(usBandHeight & 0xff); |
357 |
|
358 |
// width |
359 |
buf[i++] = (unsigned char)((usBandWidth >> 8) & 0xff); |
360 |
buf[i++] = (unsigned char)(usBandWidth & 0xff); |
361 |
|
362 |
fwrite(buf, 1, i, fp); |
363 |
return(fp); |
364 |
} // end of WriteBandHeader() |
365 |
|
366 |
FILE *WriteTrailerData(FILE *fp) |
367 |
{ |
368 |
unsigned long ulSize; |
369 |
unsigned long buffer[200]; |
370 |
|
371 |
memset((char*)buffer, 0x00, 200); |
372 |
strcpy((char*)buffer, "$PJL PRINT 4\x0d\x0a"); |
373 |
strcat((char*)buffer, "$PJL EOJ\x0d\x0a"); |
374 |
strcat((char*)buffer, "$PJL SYNC\x0d\x0a"); |
375 |
strcat((char*)buffer, "$PJL RELEASE 0 2047\x0d\x0a"); |
376 |
strcat((char*)buffer, "$PJL GARBAGE\x0d\x0a"); |
377 |
strcat((char*)buffer, "\x1b%-12345X\x0d\x0a"); |
378 |
|
379 |
ulSize = strlen((char*)buffer); |
380 |
fwrite(buffer, 1, ulSize, fp); |
381 |
|
382 |
return(fp); |
383 |
} // WriteTrailerData() |
384 |
|
385 |
unsigned long FrameTiffComp(unsigned char *pubDest, |
386 |
unsigned char *pubSrc, |
387 |
unsigned int usTotalLines, |
388 |
unsigned int usBytesPerLine, |
389 |
unsigned char ubMode) |
390 |
{ |
391 |
unsigned char *TgtPtr, *SrcPtr; |
392 |
unsigned int usLineSize; |
393 |
unsigned long ulret; |
394 |
unsigned int i; |
395 |
|
396 |
SrcPtr = pubSrc; |
397 |
TgtPtr = pubDest; |
398 |
ulret = 0; |
399 |
|
400 |
for (i = 0; i < usTotalLines; i++) |
401 |
{ |
402 |
if (!(ubMode & 0x02)) // |
403 |
{ |
404 |
usLineSize = FrameTiff_Comp(SrcPtr, TgtPtr, usBytesPerLine); |
405 |
} |
406 |
else |
407 |
{ |
408 |
if(i == 0x253) |
409 |
{ |
410 |
i = i; |
411 |
} |
412 |
usLineSize = PreTiffComp(SrcPtr, usBytesPerLine); |
413 |
} |
414 |
SrcPtr += usBytesPerLine; |
415 |
TgtPtr += usLineSize; |
416 |
ulret += usLineSize; |
417 |
} |
418 |
|
419 |
if (!(ubMode & 0x02)) // |
420 |
{ |
421 |
switch (ulret%4) |
422 |
{ |
423 |
case 1: |
424 |
*TgtPtr++ = 0x00; |
425 |
ulret++; |
426 |
case 2: |
427 |
*TgtPtr++ = 0x00; |
428 |
ulret++; |
429 |
case 3: |
430 |
*TgtPtr++ = 0x00; |
431 |
ulret++; |
432 |
default: |
433 |
break; |
434 |
} |
435 |
} |
436 |
else |
437 |
{ |
438 |
switch (ulret%4) |
439 |
{ |
440 |
case 1: |
441 |
ulret++; |
442 |
case 2: |
443 |
ulret++; |
444 |
case 3: |
445 |
ulret++; |
446 |
default: |
447 |
break; |
448 |
} |
449 |
} |
450 |
return(ulret); |
451 |
} // FrameTiffComp() |
452 |
|
453 |
unsigned int FrameTiff_Comp(unsigned char *lpSrcBuf, unsigned char *lpTgtBuf, unsigned int nSrcBytes) |
454 |
{ |
455 |
unsigned int usret; |
456 |
unsigned int usCount, usEndCnt; |
457 |
unsigned int usControl; |
458 |
unsigned int usCnt; |
459 |
unsigned char ubFirst, ubSecond, ubMisCnt; |
460 |
unsigned char *pubDst, *pubSrc, *pubOrg; |
461 |
|
462 |
pubDst = lpTgtBuf; |
463 |
pubSrc = lpSrcBuf; |
464 |
usCount = nSrcBytes; |
465 |
while(1) |
466 |
{ |
467 |
if(!usCount) |
468 |
{ |
469 |
break; /* exit while(1) loop */ |
470 |
} |
471 |
else if (usCount == 1) |
472 |
{ |
473 |
*pubDst++ = 0x00; |
474 |
*pubDst++ = *pubSrc++; |
475 |
break; |
476 |
} |
477 |
|
478 |
pubOrg = pubSrc; |
479 |
ubFirst = *pubSrc++; |
480 |
ubSecond = *pubSrc++; |
481 |
|
482 |
if(ubFirst == ubSecond) /* case of data match */ |
483 |
{ |
484 |
usEndCnt = usCount; |
485 |
if (usCount > 16384) |
486 |
{ |
487 |
usEndCnt = 16384; |
488 |
} |
489 |
usEndCnt = usCount - 2; |
490 |
while (usEndCnt--) |
491 |
{ |
492 |
if (ubFirst != *pubSrc++) |
493 |
{ |
494 |
pubSrc--; |
495 |
break; |
496 |
} |
497 |
} /* of while */ |
498 |
|
499 |
/* Save compressed data */ |
500 |
usCnt = (unsigned int) (pubSrc - pubOrg); |
501 |
usCount -= usCnt; |
502 |
usCnt -=2; |
503 |
if (usCnt >= 64) |
504 |
{ |
505 |
/* save control code code 1100 0000 0000 0000 | usCnt */ |
506 |
usCnt = (~usCnt & 0x3fff) | 0xc000; |
507 |
*pubDst++ = (unsigned char)((usCnt & 0xff00) >> 8); |
508 |
*pubDst++ = (unsigned char)(usCnt & 0x00ff); |
509 |
*pubDst++ = ubFirst; |
510 |
} |
511 |
else |
512 |
{ |
513 |
/* save control code 0100 0000 | (unsigned char)(usCnt) */ |
514 |
usCnt = (~usCnt & 0x7f); |
515 |
*pubDst++ = (unsigned char)usCnt; |
516 |
*pubDst++ = ubFirst; |
517 |
} |
518 |
} /* of if (ubFirst == ubSecond) */ |
519 |
|
520 |
else /* case of data mismatch */ |
521 |
{ |
522 |
ubMisCnt = 0; |
523 |
if (usCount > 2) |
524 |
{ |
525 |
usEndCnt = usCount; |
526 |
if (usCount > 16384) |
527 |
{ |
528 |
usEndCnt = 16384; |
529 |
} |
530 |
usEndCnt = usCount - 2; |
531 |
// usEndCnt = usCount - 2; original |
532 |
// 19990824 by LSM : for end file while (usEndCnt--) |
533 |
while (usEndCnt--) |
534 |
{ |
535 |
/* read next data */ |
536 |
ubFirst = ubSecond; |
537 |
ubSecond = *pubSrc++; // read 3rd Data |
538 |
if (ubFirst == ubSecond) |
539 |
{ |
540 |
if (usEndCnt <= 1) |
541 |
{ |
542 |
ubMisCnt = 2; |
543 |
break; |
544 |
} |
545 |
else |
546 |
{ |
547 |
ubSecond = *pubSrc++; // read 4th Data |
548 |
usEndCnt--; |
549 |
if (ubFirst == ubSecond) |
550 |
{ |
551 |
ubMisCnt = 3; |
552 |
break; |
553 |
} |
554 |
} |
555 |
} |
556 |
} /* of while */ |
557 |
} /* of if (usCount > 2) */ |
558 |
/* save data */ |
559 |
usControl = (unsigned int) (pubSrc - pubOrg); |
560 |
usControl -= (unsigned int) ubMisCnt; |
561 |
if (usControl > usCount) |
562 |
{ |
563 |
usCount = usControl; |
564 |
} |
565 |
usCount -= usControl; |
566 |
usCnt = usControl - 1; |
567 |
if ( usCnt >= 64) |
568 |
{ |
569 |
/* save control code 1000 0000 0000 0000 | usCnt */ |
570 |
usCnt = ((usCnt & 0xbfff) | 0x8000); |
571 |
*pubDst++ = (unsigned char)((usCnt & 0xff00) >> 8); |
572 |
*pubDst++ = (unsigned char)(usCnt & 0x00ff); |
573 |
} |
574 |
else |
575 |
{ |
576 |
/* save control code 0000 0000 | (BYTE)usCnt */ |
577 |
/* and invert it */ |
578 |
*pubDst++ = (unsigned char)(usCnt & 0x003f); |
579 |
} |
580 |
pubSrc = pubOrg; |
581 |
while (usControl--) |
582 |
{ |
583 |
*pubDst++ = *pubSrc++; |
584 |
} /* of while */ |
585 |
} /* of else */ |
586 |
} /* of while(1) */ |
587 |
|
588 |
usret = (unsigned int) (pubDst - lpTgtBuf); |
589 |
return (usret); |
590 |
} |
591 |
|
592 |
unsigned int PreTiffComp(unsigned char *lpSrcBuf, unsigned int nSrcBytes) |
593 |
{ |
594 |
unsigned int usret =0; |
595 |
unsigned int usCount, usEndCnt; |
596 |
unsigned int usControl; |
597 |
unsigned int usCnt; |
598 |
unsigned char ubFirst, ubSecond, ubMisCnt; |
599 |
unsigned char *pubSrc, *pubOrg; |
600 |
|
601 |
pubSrc = lpSrcBuf; |
602 |
usCount = nSrcBytes; |
603 |
while(1) |
604 |
{ |
605 |
if(!usCount) |
606 |
{ |
607 |
break; /* exit while(1) loop */ |
608 |
} |
609 |
else if (usCount == 1) |
610 |
{ |
611 |
usret +=2; |
612 |
pubSrc++; |
613 |
break; |
614 |
} |
615 |
|
616 |
pubOrg = pubSrc; |
617 |
ubFirst = *pubSrc++; |
618 |
ubSecond = *pubSrc++; |
619 |
|
620 |
if(ubFirst == ubSecond) /* case of data match */ |
621 |
{ |
622 |
usEndCnt = usCount; |
623 |
if (usCount > 16384) |
624 |
{ |
625 |
usEndCnt = 16384; |
626 |
} |
627 |
usEndCnt = usCount - 2; |
628 |
while (usEndCnt--) |
629 |
{ |
630 |
if (ubFirst != *pubSrc++) |
631 |
{ |
632 |
pubSrc--; |
633 |
break; |
634 |
} |
635 |
} /* of while */ |
636 |
|
637 |
/* Save compressed data */ |
638 |
usCnt = (unsigned int) (pubSrc - pubOrg); |
639 |
usCount -= usCnt; |
640 |
usCnt -=2; |
641 |
if (usCnt >= 64) |
642 |
{ |
643 |
/* save control code code 1100 0000 0000 0000 | usCnt */ |
644 |
usret +=3; |
645 |
} |
646 |
else |
647 |
{ |
648 |
/* save control code 0100 0000 | (unsigned char)(usCnt) */ |
649 |
usret += 2; |
650 |
} |
651 |
} /* of if (ubFirst == ubSecond) */ |
652 |
|
653 |
else /* case of data mismatch */ |
654 |
{ |
655 |
ubMisCnt = 0; |
656 |
if (usCount > 2) |
657 |
{ |
658 |
usEndCnt = usCount; |
659 |
if (usCount > 16384) |
660 |
{ |
661 |
usEndCnt = 16384; |
662 |
} |
663 |
// usEndCnt = usCount - 2; |
664 |
usEndCnt = usCount - 2; |
665 |
// 19990824 by LSM : for Last file while (usEndCnt--) |
666 |
while (usEndCnt--) |
667 |
{ |
668 |
/* read next data */ |
669 |
ubFirst = ubSecond; |
670 |
ubSecond = *pubSrc++; // read 3rd Data |
671 |
if (ubFirst == ubSecond) |
672 |
{ |
673 |
if (usEndCnt <= 1) |
674 |
{ |
675 |
ubMisCnt = 2; |
676 |
break; |
677 |
} |
678 |
else |
679 |
{ |
680 |
ubSecond = *pubSrc++; // read 4th Data |
681 |
usEndCnt--; // 19990824 by LSM |
682 |
if (ubFirst == ubSecond) |
683 |
{ |
684 |
ubMisCnt = 3; |
685 |
break; |
686 |
} |
687 |
} |
688 |
} |
689 |
} /* of while */ |
690 |
} /* of if (usCount > 2) */ |
691 |
/* save data */ |
692 |
usControl = (unsigned int) (pubSrc - pubOrg); |
693 |
usControl -= ubMisCnt; |
694 |
// 19990824 by LSM : for fixing GPF on Photoshop |
695 |
if (usControl > usCount) |
696 |
{ |
697 |
usControl = usCount; |
698 |
} |
699 |
usCount -= usControl; |
700 |
usCnt = usControl - 1; |
701 |
if ( usCnt >= 64) |
702 |
{ |
703 |
/* save control code 1000 0000 0000 0000 | usCnt */ |
704 |
usret += 2; |
705 |
} |
706 |
else |
707 |
{ |
708 |
/* save control code 0000 0000 | (BYTE)usCnt */ |
709 |
/* and invert it */ |
710 |
usret++; |
711 |
} |
712 |
pubSrc = pubOrg; |
713 |
while (usControl--) |
714 |
{ |
715 |
usret++; |
716 |
pubSrc++; |
717 |
} /* of while */ |
718 |
} /* of else */ |
719 |
} /* of while(1) */ |
720 |
return (usret); |
721 |
} |
722 |
|
723 |
typedef struct |
724 |
{ |
725 |
unsigned char ubDx; |
726 |
unsigned char ubRl; |
727 |
unsigned char ubLastBit; |
728 |
} sc_tbl; |
729 |
|
730 |
static sc_tbl gdi_ScanTbl[256] = { |
731 |
{ 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 0, 1 }, { 0, 0, 0 }, { 0, 0, 1 }, |
786 |
{ 0, 0, 0 }, { 0, 0, 1 }, { 0, 0, 0 }, { 0, 0, 1 }, |
787 |
{ 0, 3, 0 }, { 0, 0, 1 }, { 0, 0, 0 }, { 0, 0, 1 }, // 0xe0 |
788 |
{ 0, 0, 0 }, { 0, 0, 1 }, { 0, 0, 0 }, { 0, 0, 1 }, |
789 |
{ 0, 0, 0 }, { 0, 0, 1 }, { 0, 0, 0 }, { 0, 0, 1 }, |
790 |
{ 0, 0, 0 }, { 0, 0, 1 }, { 0, 0, 0 }, { 0, 0, 1 }, |
791 |
{ 0, 4, 0 }, { 0, 0, 1 }, { 0, 0, 0 }, { 0, 0, 1 }, // 0xf0 |
792 |
{ 0, 0, 0 }, { 0, 0, 1 }, { 0, 0, 0 }, { 0, 0, 1 }, |
793 |
{ 0, 5, 0 }, { 0, 0, 1 }, { 0, 0, 0 }, { 0, 0, 1 }, |
794 |
{ 0, 6, 0 }, { 0, 0, 1 }, { 0, 7, 0 }, { 0, 8, 1 }, |
795 |
}; |
796 |
|
797 |
static sc_tbl gdi_ScanTbl4[16] = { |
798 |
{ 4, 0, 0 }, { 3, 1, 1 }, { 2, 1, 0 }, { 2, 2, 1 }, // 0x00 |
799 |
{ 1, 1, 0 }, { 0, 0, 1 }, { 1, 2, 0 }, { 1, 3, 1 }, // 0x04 |
800 |
{ 0, 1, 0 }, { 0, 0, 1 }, { 0, 0, 0 }, { 0, 0, 1 }, // 0x08 |
801 |
{ 0, 2, 0 }, { 0, 0, 1 }, { 0, 3, 0 }, { 0, 4, 1 } // 0x0c |
802 |
}; |
803 |
|
804 |
long SaveScanData( unsigned char *, unsigned short, unsigned short, unsigned short, unsigned short, unsigned short ); |
805 |
long UpdateScanSize( unsigned char *, unsigned short, unsigned short, unsigned short, unsigned short, unsigned short ); |
806 |
typedef long (*funcptr)( unsigned char *, unsigned short, unsigned short, unsigned short, unsigned short, unsigned short ); |
807 |
|
808 |
funcptr UpdateScanLine[2] = { SaveScanData, UpdateScanSize }; |
809 |
|
810 |
long Save6Bytes(unsigned char *out_buf, unsigned short usDy, unsigned short usRl, short sDx, unsigned short usWarp) |
811 |
{ |
812 |
unsigned long ultmp_dat; |
813 |
long lWarp, lDis; |
814 |
unsigned short ustmp_dat; |
815 |
|
816 |
lWarp = (long)(usWarp << 3); |
817 |
lDis = ((long)usDy * lWarp) + (long)sDx; |
818 |
|
819 |
// 1st, 2nd, 3rd & 4th byte |
820 |
ultmp_dat = 0xc0000000; |
821 |
if (lDis < 0) |
822 |
{ |
823 |
ultmp_dat |= 0x20000000; |
824 |
} |
825 |
ultmp_dat |= (lDis & 0x1fffffff); |
826 |
*out_buf++ = (unsigned char)((ultmp_dat & 0xff000000) >> 24); |
827 |
*out_buf++ = (unsigned char)((ultmp_dat & 0xff0000) >> 16); |
828 |
*out_buf++ = (unsigned char)((ultmp_dat & 0xff00) >> 8); |
829 |
*out_buf++ = (unsigned char)(ultmp_dat & 0xff); |
830 |
|
831 |
// 5th & 6th byte |
832 |
ustmp_dat = 0xc000; |
833 |
ustmp_dat |= (usRl & 0x3fff); |
834 |
*out_buf++ = (unsigned char)((ustmp_dat & 0xff00) >> 8); |
835 |
*out_buf++ = (unsigned char)(ustmp_dat & 0xff); |
836 |
|
837 |
return(6); |
838 |
} // Save6Bytes() |
839 |
|
840 |
long Save4Bytes(unsigned char *out_buf, unsigned short usDy, unsigned short usRl, short sDx) |
841 |
{ |
842 |
unsigned short ustmp_dat; |
843 |
|
844 |
// 1st & 2nd byte |
845 |
ustmp_dat = 0x8000; |
846 |
if (sDx < 0) |
847 |
{ |
848 |
ustmp_dat |= 0x2000; |
849 |
} |
850 |
ustmp_dat |= (sDx & 0x1fff); |
851 |
*out_buf++ = (unsigned char)((ustmp_dat & 0xff00) >> 8); |
852 |
*out_buf++ = (unsigned char)(ustmp_dat & 0xff); |
853 |
|
854 |
// 3rd & 4th byte |
855 |
ustmp_dat = 0x8000; |
856 |
ustmp_dat |= ((usDy & 0x03) << 12); |
857 |
ustmp_dat |= (usRl & 0xfff); |
858 |
*out_buf++ = (unsigned char)((ustmp_dat & 0xff00) >> 8); |
859 |
*out_buf++ = (unsigned char)(ustmp_dat & 0xff); |
860 |
|
861 |
return(4); |
862 |
} // end of Save4Bytes() |
863 |
|
864 |
long Save2Bytes(unsigned char *out_buf, unsigned short usDy, unsigned short usRl, short sDx) |
865 |
{ |
866 |
unsigned char ubtmp_dat; |
867 |
|
868 |
// 1st byte |
869 |
ubtmp_dat = 0x00; |
870 |
if (usDy == 1) |
871 |
{ |
872 |
ubtmp_dat |= 0x40; |
873 |
} |
874 |
ubtmp_dat |= (usRl & 0x3f); |
875 |
*out_buf++ = ubtmp_dat; |
876 |
|
877 |
// 2nd byte |
878 |
if (sDx < 0) |
879 |
{ |
880 |
ubtmp_dat = 0x80; |
881 |
} |
882 |
else |
883 |
{ |
884 |
ubtmp_dat = 0x00; |
885 |
} |
886 |
ubtmp_dat |= ((unsigned char)sDx & 0x7f); |
887 |
*out_buf++ = ubtmp_dat; |
888 |
return(2); |
889 |
} // end of Save2Bytes() |
890 |
|
891 |
long SaveScanData (unsigned char *out_buf, |
892 |
unsigned short us1Cnt, |
893 |
unsigned short usDy, |
894 |
unsigned short usPosX10, |
895 |
unsigned short usPosX01, |
896 |
unsigned short usWarp) |
897 |
{ |
898 |
short sDisX; |
899 |
long lRet; |
900 |
|
901 |
sDisX = (int)usPosX01 - (int)usPosX10; |
902 |
|
903 |
// 48 bit |
904 |
if ( (usDy > 3) || (us1Cnt > 4095) ) |
905 |
{ |
906 |
Save6Bytes(out_buf, usDy, us1Cnt, sDisX, usWarp); |
907 |
lRet = 6; |
908 |
} |
909 |
// 32 bit |
910 |
else if ( (usDy > 1) || (us1Cnt > 63) || (sDisX > 127) || (sDisX < -128) ) |
911 |
{ |
912 |
Save4Bytes(out_buf, usDy, us1Cnt, sDisX); |
913 |
lRet = 4; |
914 |
} |
915 |
// 16 bit |
916 |
else |
917 |
{ |
918 |
Save2Bytes(out_buf, usDy, us1Cnt, sDisX); |
919 |
lRet = 2; |
920 |
} |
921 |
return(lRet); |
922 |
} // end of SaveScanData() |
923 |
|
924 |
|
925 |
long UpdateScanSize (unsigned char *out_buf, |
926 |
unsigned short us1Cnt, |
927 |
unsigned short usDy, |
928 |
unsigned short usPosX10, |
929 |
unsigned short usPosX01, |
930 |
unsigned short usWarp) |
931 |
{ |
932 |
short sDisX; |
933 |
long lRet; |
934 |
|
935 |
sDisX = usPosX01 - usPosX10; |
936 |
|
937 |
// 48 bit |
938 |
if ( (usDy > 3) || (us1Cnt > 4095) ) |
939 |
{ |
940 |
lRet = 6; |
941 |
} |
942 |
// 32 bit |
943 |
else if ( (usDy > 1) || (us1Cnt > 63) || (sDisX > 127) || (sDisX < -128) ) |
944 |
{ |
945 |
lRet = 4; |
946 |
} |
947 |
// 16 bit |
948 |
else |
949 |
{ |
950 |
lRet = 2; |
951 |
} |
952 |
return(lRet); |
953 |
} // end of UpdateScanSize() by bglee 19981224 |
954 |
|
955 |
long GetSimpleScan(unsigned char *out_buf, |
956 |
unsigned char ubSizeMode, |
957 |
unsigned short *us1Count, |
958 |
unsigned short *usDy, |
959 |
unsigned short *usPosX10, |
960 |
unsigned short *usPosX01, |
961 |
unsigned short usBytePos, |
962 |
unsigned char ubCrtByte, |
963 |
unsigned char ubSize, |
964 |
unsigned char ubPreBit, |
965 |
unsigned short usWidth) |
966 |
{ |
967 |
long lScanSize; |
968 |
unsigned char ubDx, ubRl, ubLastBit; |
969 |
|
970 |
lScanSize = 0; |
971 |
if (ubSize == 8) |
972 |
{ |
973 |
ubDx = gdi_ScanTbl[ubCrtByte].ubDx; |
974 |
ubRl = gdi_ScanTbl[ubCrtByte].ubRl; |
975 |
ubLastBit = gdi_ScanTbl[ubCrtByte].ubLastBit; |
976 |
} |
977 |
else |
978 |
{ |
979 |
ubCrtByte &= 0x0f; |
980 |
ubDx = gdi_ScanTbl4[ubCrtByte].ubDx; |
981 |
ubRl = gdi_ScanTbl4[ubCrtByte].ubRl; |
982 |
ubLastBit = gdi_ScanTbl4[ubCrtByte].ubLastBit; |
983 |
} |
984 |
|
985 |
|
986 |
// 1 X 1 X |
987 |
if (ubPreBit) |
988 |
{ |
989 |
// 1 0 1 X |
990 |
if (ubDx) |
991 |
{ |
992 |
lScanSize += (*UpdateScanLine[ubSizeMode])(out_buf, *us1Count, *usDy, *usPosX10, *usPosX01, usWidth); |
993 |
*usPosX10 = usBytePos - *us1Count; |
994 |
*usPosX01 = usBytePos + ubDx; |
995 |
*us1Count = ubRl; |
996 |
*usDy = 0; |
997 |
// 1 0 1 0 |
998 |
if (!ubLastBit) |
999 |
{ |
1000 |
// 19990330 by bglee |
1001 |
out_buf = out_buf + lScanSize; |
1002 |
|
1003 |
lScanSize += (*UpdateScanLine[ubSizeMode])(out_buf, *us1Count, *usDy, *usPosX10, *usPosX01, usWidth); |
1004 |
*usPosX10 = *usPosX01 ; |
1005 |
*us1Count = 0; |
1006 |
} |
1007 |
// 1 0 1 1 |
1008 |
} |
1009 |
// 1 1 1 X |
1010 |
else |
1011 |
{ |
1012 |
*us1Count += ubRl; |
1013 |
// 1 1 1 0 |
1014 |
if (!ubLastBit) |
1015 |
{ |
1016 |
lScanSize += (*UpdateScanLine[ubSizeMode])(out_buf, *us1Count, *usDy, *usPosX10, *usPosX01, usWidth); |
1017 |
*usPosX10 = usBytePos + ubRl - *us1Count; |
1018 |
*us1Count = 0; |
1019 |
*usDy = 0; |
1020 |
} |
1021 |
// 1 1 1 1 |
1022 |
} |
1023 |
} |
1024 |
// 0 X 1 X |
1025 |
else |
1026 |
{ |
1027 |
// 0 X 1 X |
1028 |
*usPosX01 = usBytePos + ubDx; |
1029 |
*us1Count += ubRl; |
1030 |
// 0 X 1 0 |
1031 |
if (!ubLastBit) |
1032 |
{ |
1033 |
lScanSize += (*UpdateScanLine[ubSizeMode])(out_buf, *us1Count, *usDy, *usPosX10, *usPosX01, usWidth); |
1034 |
*usPosX10 = *usPosX01 + ubRl - *us1Count; |
1035 |
*us1Count = 0; |
1036 |
*usDy = 0; |
1037 |
} |
1038 |
// 0 X 1 1 |
1039 |
} |
1040 |
|
1041 |
return(lScanSize); |
1042 |
} // end of GetSimpleScan() |
1043 |
|
1044 |
|
1045 |
long scan_map (unsigned char *in_buf, |
1046 |
unsigned char *out_buf, |
1047 |
unsigned short usWidth, |
1048 |
unsigned short usHeight, |
1049 |
unsigned char ubMode) |
1050 |
{ |
1051 |
unsigned int i, j, k; |
1052 |
unsigned char ubPreBit, ubCrtByte;//, ubLastBit; |
1053 |
long lScanSize, lTmp; |
1054 |
long lCrtSize; |
1055 |
unsigned short us1Count; |
1056 |
unsigned short usPosX01, usPosX10; |
1057 |
unsigned short usDy, usBytePos; |
1058 |
unsigned char ubRevMode, ubSizeMode; |
1059 |
unsigned char ubTemp; |
1060 |
|
1061 |
usDy = 0; |
1062 |
usPosX01 = usPosX10 = 0; |
1063 |
lScanSize = 0; |
1064 |
ubRevMode = ubMode & 0x01; |
1065 |
ubSizeMode = (ubMode & 0x02) >> 1; |
1066 |
for (i = 0; i < usHeight; i++) |
1067 |
{ |
1068 |
ubPreBit = 0; |
1069 |
us1Count = 0; |
1070 |
for (j = 0; j < usWidth; j++) |
1071 |
{ |
1072 |
ubCrtByte = *in_buf++; |
1073 |
if (ubRevMode) |
1074 |
{ |
1075 |
ubCrtByte = ~ubCrtByte; |
1076 |
} |
1077 |
|
1078 |
switch (ubCrtByte) |
1079 |
{ |
1080 |
case 0x00: |
1081 |
// 1 0 |
1082 |
if (ubPreBit) |
1083 |
{ |
1084 |
lTmp = (*UpdateScanLine[ubSizeMode])(out_buf, us1Count, usDy, usPosX10, usPosX01, usWidth); |
1085 |
out_buf = out_buf + lTmp; |
1086 |
lScanSize += lTmp; |
1087 |
usPosX10 = (j << 3) - us1Count; /*by pkb*/ |
1088 |
us1Count = 0; |
1089 |
usDy = 0; |
1090 |
} |
1091 |
// 0 0 |
1092 |
break; |
1093 |
|
1094 |
case 0xff: |
1095 |
// 1 1 |
1096 |
if (ubPreBit) |
1097 |
{ |
1098 |
us1Count += 8; |
1099 |
} |
1100 |
// 0 1 |
1101 |
else |
1102 |
{ |
1103 |
us1Count = 8; |
1104 |
usPosX01 = (j << 3); |
1105 |
} |
1106 |
break; |
1107 |
|
1108 |
default: |
1109 |
// X X 1 X |
1110 |
if (gdi_ScanTbl[ubCrtByte].ubRl) |
1111 |
{ |
1112 |
usBytePos = (j << 3); |
1113 |
lTmp = GetSimpleScan(out_buf, ubSizeMode, &us1Count, &usDy, &usPosX10, &usPosX01, usBytePos, ubCrtByte, 8, ubPreBit, usWidth); |
1114 |
out_buf = out_buf + lTmp; |
1115 |
lScanSize += lTmp; |
1116 |
} |
1117 |
// complex pattern |
1118 |
else |
1119 |
{ |
1120 |
for (k = 0; k < 2; k++) |
1121 |
{ /*we calculate 4bit*/ |
1122 |
ubTemp = (ubCrtByte >> (4 - (k * 4)) ) & 0x0f; |
1123 |
usBytePos = (j << 3) + (k << 2); |
1124 |
switch (ubTemp) |
1125 |
{ |
1126 |
case 0x00: |
1127 |
// 1 0 |
1128 |
if (ubPreBit) |
1129 |
{ |
1130 |
lTmp = (*UpdateScanLine[ubSizeMode])(out_buf, us1Count, usDy, usPosX10, usPosX01, usWidth); |
1131 |
out_buf = out_buf + lTmp; |
1132 |
lScanSize += lTmp; |
1133 |
usPosX10 = usBytePos - us1Count; |
1134 |
us1Count = 0; |
1135 |
usDy = 0; |
1136 |
} |
1137 |
// 0 0 |
1138 |
break; |
1139 |
|
1140 |
case 0x0f: |
1141 |
// 1 1 |
1142 |
if (ubPreBit) |
1143 |
{ |
1144 |
us1Count += 4; |
1145 |
} |
1146 |
// 0 1 |
1147 |
else |
1148 |
{ |
1149 |
us1Count = 4; |
1150 |
usPosX01 = (j << 3) + (k << 2); |
1151 |
} |
1152 |
break; |
1153 |
|
1154 |
case 0x05: |
1155 |
// 1 0101 |
1156 |
if (ubPreBit) |
1157 |
{ |
1158 |
lTmp = (*UpdateScanLine[ubSizeMode])(out_buf, us1Count, usDy, usPosX10, usPosX01, usWidth); |
1159 |
out_buf = out_buf + lTmp; |
1160 |
lScanSize += lTmp; |
1161 |
|
1162 |
usPosX10 = usBytePos - us1Count; |
1163 |
usDy = 0; |
1164 |
} |
1165 |
// 0 0101 |
1166 |
usPosX01 = usBytePos + 1; |
1167 |
lTmp = (*UpdateScanLine[ubSizeMode])(out_buf, 1, usDy, usPosX10, usPosX01, usWidth); |
1168 |
out_buf = out_buf + lTmp; |
1169 |
lScanSize += lTmp; |
1170 |
|
1171 |
// next |
1172 |
usPosX10 = 0; |
1173 |
usPosX01 = 2; |
1174 |
usDy = 0; |
1175 |
us1Count = 1; |
1176 |
break; |
1177 |
|
1178 |
case 0x09: |
1179 |
// 1 1001 |
1180 |
if (ubPreBit) |
1181 |
{ |
1182 |
us1Count++; |
1183 |
} |
1184 |
// 0 1001 |
1185 |
else |
1186 |
{ |
1187 |
usPosX01 = usBytePos; |
1188 |
us1Count = 1; |
1189 |
} |
1190 |
lTmp = (*UpdateScanLine[ubSizeMode])(out_buf, us1Count, usDy, usPosX10, usPosX01, usWidth); |
1191 |
out_buf = out_buf + lTmp; |
1192 |
lScanSize += lTmp; |
1193 |
|
1194 |
// next |
1195 |
if (ubPreBit) |
1196 |
{ |
1197 |
usPosX10 = usBytePos - us1Count + 1; |
1198 |
usPosX01 = usBytePos + 3; |
1199 |
} |
1200 |
else |
1201 |
{ |
1202 |
usPosX10 = 0; |
1203 |
usPosX01 = 3; |
1204 |
} |
1205 |
usDy = 0; |
1206 |
us1Count = 1; |
1207 |
break; |
1208 |
|
1209 |
case 0x0a: |
1210 |
// 1 1010 |
1211 |
if (ubPreBit) |
1212 |
{ |
1213 |
us1Count++; |
1214 |
} |
1215 |
// 0 1010 |
1216 |
else |
1217 |
{ |
1218 |
us1Count = 1; |
1219 |
usPosX01 = usBytePos; |
1220 |
} |
1221 |
lTmp = (*UpdateScanLine[ubSizeMode])(out_buf, us1Count, usDy, usPosX10, usPosX01, usWidth); |
1222 |
out_buf = out_buf + lTmp; |
1223 |
lScanSize += lTmp; |
1224 |
|
1225 |
// next |
1226 |
usPosX10 = usBytePos - us1Count + 1; |
1227 |
usPosX01 = usBytePos + 2; |
1228 |
lTmp = (*UpdateScanLine[ubSizeMode])(out_buf, 1, 0, usPosX10, usPosX01, usWidth); |
1229 |
out_buf = out_buf + lTmp; |
1230 |
lScanSize += lTmp; |
1231 |
// next |
1232 |
usPosX10 = usBytePos + 2; |
1233 |
usDy = 0; |
1234 |
us1Count = 0; |
1235 |
break; |
1236 |
|
1237 |
case 0x0b: |
1238 |
// 1 1011 |
1239 |
if (ubPreBit) |
1240 |
{ |
1241 |
us1Count++; |
1242 |
} |
1243 |
// 0 1011 |
1244 |
else |
1245 |
{ |
1246 |
us1Count = 1; |
1247 |
usPosX01 = usBytePos; |
1248 |
} |
1249 |
lTmp = (*UpdateScanLine[ubSizeMode])(out_buf, us1Count, usDy, usPosX10, usPosX01, usWidth); |
1250 |
out_buf = out_buf + lTmp; |
1251 |
lScanSize += lTmp; |
1252 |
|
1253 |
// next |
1254 |
if (ubPreBit) |
1255 |
{ |
1256 |
usPosX10 = usBytePos - us1Count + 1; |
1257 |
usPosX01 = usBytePos + 2; |
1258 |
} |
1259 |
else |
1260 |
{ |
1261 |
usPosX10 = 0; |
1262 |
usPosX01 = 2; |
1263 |
} |
1264 |
|
1265 |
usDy = 0; |
1266 |
us1Count = 2; |
1267 |
break; |
1268 |
|
1269 |
case 0x0d: |
1270 |
// 1 1101 |
1271 |
if (ubPreBit) |
1272 |
{ |
1273 |
us1Count += 2; |
1274 |
} |
1275 |
// 0 1101 |
1276 |
else |
1277 |
{ |
1278 |
us1Count = 2; |
1279 |
usPosX01 = usBytePos; |
1280 |
} |
1281 |
lTmp = (*UpdateScanLine[ubSizeMode])(out_buf, us1Count, usDy, usPosX10, usPosX01, usWidth); |
1282 |
out_buf = out_buf + lTmp; |
1283 |
lScanSize += lTmp; |
1284 |
|
1285 |
// next |
1286 |
if (ubPreBit) |
1287 |
{ |
1288 |
usPosX10 = usBytePos - us1Count + 2; |
1289 |
usPosX01 = usBytePos + 3; |
1290 |
} |
1291 |
else |
1292 |
{ |
1293 |
usPosX10 = 0; |
1294 |
usPosX01 = 3; |
1295 |
} |
1296 |
usDy = 0; |
1297 |
us1Count = 1; |
1298 |
break; |
1299 |
|
1300 |
default: |
1301 |
// X X 1 X |
1302 |
lTmp = GetSimpleScan(out_buf, ubSizeMode, &us1Count, &usDy, &usPosX10, &usPosX01, usBytePos, ubTemp, 4, ubPreBit, usWidth); |
1303 |
out_buf = out_buf + lTmp; |
1304 |
lScanSize += lTmp; |
1305 |
break; |
1306 |
} // end of switch() |
1307 |
ubPreBit = ubTemp & 0x01; |
1308 |
} // end of k-loop |
1309 |
} |
1310 |
break; |
1311 |
} // end of switch() |
1312 |
|
1313 |
ubPreBit = ubCrtByte & 0x01; |
1314 |
} /*for usWidth */ |
1315 |
|
1316 |
if (us1Count) |
1317 |
{ |
1318 |
lTmp = (*UpdateScanLine[ubSizeMode])(out_buf, us1Count, usDy, usPosX10, usPosX01, usWidth); |
1319 |
out_buf = out_buf + lTmp; |
1320 |
lScanSize += lTmp; |
1321 |
usPosX10 = (j << 3) - us1Count; |
1322 |
|
1323 |
us1Count = 0; |
1324 |
usDy = 0; |
1325 |
usPosX01 = 0; |
1326 |
} |
1327 |
usDy++; |
1328 |
|
1329 |
// check size over |
1330 |
if ( (i % 5) == 4 ) |
1331 |
{ |
1332 |
lCrtSize = (long)((long)usWidth * (long)(i + 1)); |
1333 |
if ( lScanSize >= lCrtSize ) |
1334 |
{ |
1335 |
return(-1); |
1336 |
} |
1337 |
} |
1338 |
} /* for usHeight */ |
1339 |
lCrtSize = (long)((long)usWidth * (long)usHeight); |
1340 |
if ( (lScanSize + 4) >= lCrtSize ) |
1341 |
{ |
1342 |
lScanSize = -1; |
1343 |
} |
1344 |
return(lScanSize); |
1345 |
} // end of scan_map() |
1346 |
|
1347 |
/***************************************************************** |
1348 |
* H : bmp2run |
1349 |
* I : unsigned char *in_buf - input buffer pointer |
1350 |
* unsigned char *out_buf - output buffer pointer |
1351 |
* unsigned int sizeX - image width by byte |
1352 |
* unsigned int sizeY - image height by scanline |
1353 |
* unsigned char ubMode - bit 0 & 1 |
1354 |
* 0 0 - normal compression |
1355 |
* 0 1 - image reverse |
1356 |
* 1 X - you get scanline table size |
1357 |
* O : unsigned long lScanSize - scanline table size |
1358 |
* P : scanline table compression |
1359 |
****************************************************************/ |
1360 |
long bmp2run(unsigned char *out_buf, unsigned char *in_buf, unsigned int sizeY, unsigned int sizeX, unsigned char ubMode) |
1361 |
{ |
1362 |
unsigned char *tmp_buf1, *tmp_buf2; |
1363 |
long scan_size; |
1364 |
|
1365 |
//return(-1); // 19990323 by bglee - request from SM Lee |
1366 |
|
1367 |
tmp_buf1 = in_buf; |
1368 |
tmp_buf2 = out_buf; |
1369 |
scan_size = scan_map(tmp_buf1, tmp_buf2, sizeX, sizeY, ubMode); |
1370 |
if (scan_size == -1) |
1371 |
{ |
1372 |
return(-1); |
1373 |
} |
1374 |
|
1375 |
if ( !(ubMode & 0x02) ) // real compression //--- |
1376 |
{ |
1377 |
out_buf = tmp_buf2 + scan_size; |
1378 |
*out_buf++ = 0x00; |
1379 |
*out_buf++ = 0x00; |
1380 |
scan_size += 2; |
1381 |
if (scan_size % 4) |
1382 |
{ |
1383 |
*out_buf++ = 0x00; |
1384 |
*out_buf++ = 0x00; |
1385 |
scan_size += 2; |
1386 |
} |
1387 |
} |
1388 |
else // pre-compression |
1389 |
{ |
1390 |
scan_size += 2; |
1391 |
if (scan_size % 4) |
1392 |
{ |
1393 |
scan_size += 2; |
1394 |
} |
1395 |
} |
1396 |
return(scan_size); |
1397 |
} |
1398 |
|