2 * Epson Inkjet Printer Driver (ESC/P-R) for Linux
3 * Copyright (C) 2002-2005 AVASYS CORPORATION.
4 * Copyright (C) Seiko Epson Corporation 2002-2012.
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA.
36 #include "epson-escpr-def.h"
37 #include "epson-escpr-media.h"
38 #include "epson-protocol.h"
39 #include "epson-escpr-pvt.h"
40 #include "epson-escpr-api.h"
41 #include "epson-escpr-services.h"
42 #include "epson-escpr-mem.h"
51 #include "linux_cmn.h"
58 #define WIDTH_BYTES(bits) (((bits) + 31) / 32 * 4)
60 #define PIPSLITE_FILTER_VERSION "* epson-escpr is a part of " PACKAGE_STRING
62 #define PIPSLITE_FILTER_USAGE "Usage: $ epson-escpr model width_pixel height_pixel Ink PageSize Quality"
64 typedef struct rtp_filter_option {
66 char model_low[NAME_MAX];
69 char quality[NAME_MAX];
70 char duplex[NAME_MAX];
76 /* static functions */
77 static int set_pips_parameter (filter_option_t *, ESCPR_OPT *, ESCPR_PRINT_QUALITY *);
78 static int get_page_size (const char *, const char *);
79 static int getMediaTypeID(char *);
80 static ESCPR_BYTE4 print_spool_fnc(void* , const ESCPR_UBYTE1*, ESCPR_UBYTE4);
82 ///////////////////////////////////////////////////////////////////////////////////////////////////////////
83 const int band_line = 1;
84 extern EPS_INT32 libStatus; /* Library (epsInitDriver) status */
85 extern EPS_PRINT_JOB printJob;
86 extern EPS_UINT32 sendDataBufSize;
87 extern EPS_UINT8* sendDataBuf; /* buffer of SendCommand(save) input */
88 extern EPS_UINT32 tmpLineBufSize;
89 extern EPS_UINT8* tmpLineBuf;
91 extern EPS_CMN_FUNC epsCmnFnc;
94 extern EPS_INT32 tonerSave;
95 extern EPS_INT32 back_type;
96 extern EPS_INT32 lWidth;
97 extern EPS_INT32 lHeight;
98 extern EPS_INT32 areaWidth;
99 extern EPS_INT32 areaHeight;
101 #ifndef ESCPR_HEADER_LENGTH
102 #define ESCPR_HEADER_LENGTH 10 /* ESC + CLASS + ParamLen + CmdName */
105 #ifndef ESCPR_SEND_DATA_LENGTH
106 #define ESCPR_SEND_DATA_LENGTH 7
109 EPS_JOB_ATTRIB jobAttr;
111 ///////////////////////////////////////////////////////////////////////////////////////////////////////////
116 ///////////////////////////////////////////////////////////////////////////////////////////////////////////
117 EPS_ERR_CODE epsInitLib(){
118 EPS_CMN_FUNC cmnFuncPtrs;
119 memset(&cmnFuncPtrs, 0, sizeof(EPS_CMN_FUNC));
121 cmnFuncPtrs.version = EPS_CMNFUNC_VER_CUR;
122 cmnFuncPtrs.findCallback = NULL;
123 cmnFuncPtrs.memAlloc = &epsmpMemAlloc;
124 cmnFuncPtrs.memFree = &epsmpMemFree;
125 cmnFuncPtrs.sleep = &epsmpSleep;
126 cmnFuncPtrs.getTime = &epsmpGetTime;
127 cmnFuncPtrs.getLocalTime = &epsmpGetLocalTime;
128 cmnFuncPtrs.lockSync = &epsmpLockSync;
129 cmnFuncPtrs.unlockSync = &epsmpUnlockSync;
130 cmnFuncPtrs.stateCallback = NULL; /* current version unused */
132 memcpy((void*)(&epsCmnFnc), (void*)&cmnFuncPtrs, sizeof(EPS_CMN_FUNC));
135 EPS_ERR_CODE epsInitJob(){
137 memset(&printJob, 0, sizeof(EPS_PRINT_JOB));
138 printJob.printer = (EPS_PRINTER_INN*) malloc(sizeof(EPS_PRINTER_INN));
139 memset(printJob.printer, 0, sizeof(EPS_PRINTER_INN));
141 printJob.jobStatus = EPS_STATUS_NOT_INITIALIZED;
142 printJob.pageStatus = EPS_STATUS_NOT_INITIALIZED;
143 printJob.findStatus = EPS_STATUS_NOT_INITIALIZED;
144 printJob.bComm = TRUE;
145 printJob.platform = 0x04; /* '0x04 = linux' is default */
147 libStatus = EPS_STATUS_NOT_INITIALIZED;
153 /*** Initialize continue buffer */
154 printJob.contData.sendData = NULL;
155 printJob.contData.sendDataSize = 0;
157 /* DEL printJob.additional = EPS_ADDDATA_NONE;
158 printJob.qrcode.bits = NULL;
159 printJob.qrcode.cellNum = 0;
160 printJob.qrcode.dpc = 0; */
163 /*** Set "Endian-ness" for the current cpu */
166 /*** Set Communication Mode */
167 //printJob.commMode = commMode;
169 /*** Change ESC/P-R Lib Status */
170 libStatus = EPS_STATUS_INITIALIZED;
171 EPS_PRINTER_INN* printer = printJob.printer;
172 printer->pmData.state = EPS_PM_STATE_NOT_FILTERED;
173 printer->language = EPS_LANG_ESCPR;
178 EPS_ERR_CODE epsInitVariable(){
179 sendDataBufSize = (EPS_INT32)(ESCPR_HEADER_LENGTH +
180 ESCPR_SEND_DATA_LENGTH +
181 (printJob.printableAreaWidth * printJob.bpp));
182 sendDataBuf = (EPS_UINT8*)EPS_ALLOC(sendDataBufSize);
183 if(sendDataBuf == NULL){
185 EPS_RETURN( EPS_ERR_MEMORY_ALLOCATION );
188 memset(sendDataBuf, 0xFF, (EPS_UINT32)sendDataBufSize);
189 /*** Allocate buffer for RLE complession */
190 tmpLineBufSize = (EPS_INT32)(printJob.printableAreaWidth * printJob.bpp) + 256; /* 256 is temp buffer */
191 tmpLineBuf = (EPS_UINT8*)EPS_ALLOC(tmpLineBufSize);
192 if(tmpLineBuf == NULL){
194 EPS_RETURN( EPS_ERR_MEMORY_ALLOCATION );
196 memset(tmpLineBuf, 0xFF, (EPS_UINT32)tmpLineBufSize);
201 EPS_ERR_CODE epsFilterEndPage(EPS_BOOL bNextPage){
202 EPS_ERR_CODE retStatus= EPS_ERR_NONE;
204 #ifdef GCOMSW_CMD_ESCPAGE_S
205 debug_msg("GCOMSW_CMD_ESCPAGE defined\n");
206 retStatus = pageEndPage();
208 retStatus = EPS_ERR_LANGUAGE_NOT_SUPPORTED;
215 void eps_toupper(char *str){
218 if(str == NULL || strlen(str) == 0){
222 for(i = 0; i < len; i++){
223 str[i] = toupper(str[i]);
228 static int getMediaSizeID(char *media_name){
230 debug_msg("media name = %s\n", media_name);
231 for(j = 0; mediaSizeData[j].value != END_ARRAY; j++){
232 if((strlen(mediaSizeData[j].rsc_name) == strlen(media_name)) && strncmp(mediaSizeData[j].rsc_name,media_name, strlen(mediaSizeData[j].rsc_name)) == 0){
233 debug_msg("mediaSizeData[%d].rsc_name: %s, x_name = %s\n", j, mediaSizeData[j].rsc_name, mediaSizeData[j].x_name);
234 return mediaSizeData[j].value;
240 ///////////////////////////////////////////////////////////////////////////////////////////////////////////
243 /* Useage: epson-escpr model width_pixel height_pixel Ink PageSize Quality */
245 main (int argc, char *argv[])
247 filter_option_t fopt;
248 char libfile[PATH_MAX + 1];
250 long width_pixel, height_pixel;
255 double print_area_x, print_area_y;
265 /* 2004.04.15 added for 'cancel page' */
268 /* 2005.11.28 added */
273 /* library options */
275 ESCPR_PRINT_QUALITY printQuality;
276 //ESCPR_PRINT_JOB printJob;
277 ESCPR_BANDBMP bandBmp;
280 ///////////////////////////////////////////////////////////////////////////////////////////////////////////
281 memset (&jobAttr, 0, sizeof(jobAttr));
282 ///////////////////////////////////////////////////////////////////////////////////////////////////////////
287 while (flag) sleep (3);
288 #endif /* USE_DEBUGGER */
295 for ( i = 1; i < argc; i++ ) {
296 if ( (0 == strncmp(argv[i], "-v", (strlen("-v")+1)) )
297 || (0 == strncmp(argv[i], "--version", (strlen("--version")+1)) )
299 fprintf(stderr, "%s\n", PIPSLITE_FILTER_VERSION);
301 } else if ( (0 == strncmp(argv[i], "-u", (strlen("-u")+1)) )
302 || (0 == strncmp(argv[i], "--usage", (strlen("--usage")+1)) )
304 fprintf(stderr, "%s\n", PIPSLITE_FILTER_USAGE);
306 } else if ( (0 == strncmp(argv[i], "-h", (strlen("-h")+1)) )
307 || (0 == strncmp(argv[i], "--help", (strlen("--help")+1)) )
309 fprintf(stderr, "%s\n%s\n", PIPSLITE_FILTER_VERSION, PIPSLITE_FILTER_USAGE);
313 fprintf (stderr, "%s\n", PIPSLITE_FILTER_USAGE);
317 /* set filter options */
318 memset (&fopt, 0, sizeof (filter_option_t));
319 memset (&printOpt, 0, sizeof (ESCPR_OPT));
320 memset (&printQuality, 0, sizeof(ESCPR_PRINT_QUALITY));
321 //memset (&printJob, 0, sizeof(ESCPR_PRINT_JOB));
322 memset (&bandBmp, 0, sizeof(ESCPR_BANDBMP));
323 memset (&bandRect, 0, sizeof(ESCPR_RECT));
325 strncpy (fopt.model, argv[1], NAME_MAX);
326 for (i = 0; fopt.model[i] != '\0' && i < NAME_MAX - 1; i ++)
327 fopt.model_low[i] = tolower (fopt.model[i]);
328 fopt.model_low[i] = '\0';
330 width_pixel = atol (argv[2]);
331 height_pixel = atol (argv[3]);
332 HWResolution = atol (argv[4]);
334 strncpy (fopt.ink, argv[5], NAME_MAX);
335 strncpy (fopt.media, argv[6], NAME_MAX);
336 strncpy (fopt.quality, argv[7], NAME_MAX);
337 strncpy (fopt.duplex, argv[8], NAME_MAX);
339 debug_msg("all para\n");
340 for(i = 0; i< argc; i++){
341 debug_msg("argv[%d] = %s\n", i, argv[i]);
345 printOpt.fpspoolfunc = (ESCPR_FPSPOOLFUNC)print_spool_fnc;
347 if (set_pips_parameter (&fopt, &printOpt, &printQuality))
348 err_fatal ("Cannot get option of PIPS."); /* exit */
349 debug_msg("after setpip, duplex = %d\n", jobAttr.duplex);
353 paper=str_clone(++point,strlen(fopt.media)-1);
355 jobAttr.printLayout = EPS_MLID_BORDERLESS;
356 debug_msg("borderless\n");
360 paper=str_clone(point,strlen(fopt.media));
362 jobAttr.printLayout = EPS_MLID_BORDERS;
363 debug_msg("border\n");
366 eps_toupper(fopt.media);
367 //jobAttr.mediaSizeIdx = getMediaSizeID(fopt.media);
368 jobAttr.mediaSizeIdx = getMediaSizeID(paper);
370 switch(HWResolution){
372 //printJob.InResolution = ESCPR_IR_3636;
373 jobAttr.inputResolution = EPS_IR_360X360;
376 //printJob.InResolution = ESCPR_IR_7272;
377 jobAttr.inputResolution = EPS_IR_720X720;
380 //printJob.InResolution = ESCPR_IR_3030;
381 jobAttr.inputResolution = EPS_IR_300X300;
384 //printJob.InResolution = ESCPR_IR_6060;
385 jobAttr.inputResolution = EPS_IR_600X600;
390 //if (get_page_size (&printJob, paper, bin_id))
391 if (get_page_size (paper, bin_id))
392 err_fatal ("Cannot get page size of PIPS.");
396 if (strcmp (fopt.ink, "COLOR") == 0)
401 ///////////////////////////////////////////////////////////////////////////////////////////////////////////
404 debug_msg("before setupjobattr, duplex = %d\n", jobAttr.duplex);
405 debug_msg("mediasizeIDx = %d\n", jobAttr.mediaSizeIdx);
406 err = SetupJobAttrib(&jobAttr);
408 debug_msg("Error occurred in \"SetupJobAttrib\": %d\n", err);
409 err_fatal ("Error occurred in \"SetupJobAttrib\"."); /* exit */
411 //printJob.paperWidth = width_pixel;
412 //printJob.paperHeight = height_pixel;
416 debug_msg("begin pageAllocBuffer()\n");
417 err = pageAllocBuffer();
419 debug_msg ("Error occurred in \"pageAllocBuffer\"."); /* exit */
420 err_fatal ("Error occurred in \"pageAllocBuffer\"."); /* exit */
422 debug_msg ("pageAllocBuffer() success\n");
426 EPS_PRINTER_INN curPrinter;
427 memset(&curPrinter, 0, sizeof(curPrinter));
428 curPrinter.language = EPS_LANG_ESCPR;
429 curPrinter.protocol = EPS_PROTOCOL_LPR;
431 printJob.printer = &curPrinter;
433 prtSetupJobFunctions(printJob.printer, &jobFnc);
434 debug_msg("call SendStartJob function\n");
436 err = SendStartJob(FALSE);
438 debug_msg("Error occurred in \"pageStartJob\": %d\n", err);
439 err_fatal ("Error occurred in \"pageStartJob\"."); /* exit */
441 debug_msg("pageStartJob() success");
444 printJob.jobStatus = EPS_STATUS_ESTABLISHED;
446 ///////////////////////////////////////////////////////////////////////////////////////////////////////////
451 print_area_x = printJob.printableAreaWidth;
452 print_area_y = printJob.printableAreaHeight;
454 /* setup band struct */
455 bandBmp.WidthBytes = WIDTH_BYTES (print_area_x * 3 * 8 );
457 band = (unsigned char *)mem_new (char, bandBmp.WidthBytes * band_line);
458 memset (band, 0xff, bandBmp.WidthBytes * band_line);
462 bandRect.right = printJob.printableAreaWidth;
467 DEBUG_JOB_STRUCT (printJob);
468 DEBUG_QUALITY_STRUCT (printQuality);
470 err = escprInitJob (&printOpt, &printQuality, &printJob);
472 err_fatal ("Error occurred in \"INIT_FUNC\"."); /* exit */
475 x_mag = (double)print_area_x / width_pixel;
476 y_mag = (double)print_area_y / height_pixel;
478 bytes_per_line = WIDTH_BYTES(width_pixel * byte_par_pixel * 8 );
479 debug_msg("bytes_per_line = %d\n", bytes_per_line);
480 image_raw = mem_new0 (char, bytes_per_line);
481 //epsStartJob(&jobAttr);
483 while ((read_size = read (STDIN_FILENO, image_raw, bytes_per_line)) > 0)
485 debug_msg("step 100.0\n");
486 long x_count, y_count;
489 char ppmfilename[30];
496 //err = escprInitPage ();
497 err = epsStartPage(NULL);
499 sprintf(ppmfilename, "/tmp/px-b750f-page%d.ppm", page_count);
500 fp = fopen(ppmfilename, "w");
502 fprintf(fp, "%d\n",bytes_per_line/byte_par_pixel);
503 fprintf(fp, "%d\n",(int)print_area_y);
504 fprintf(fp, "255\n");
509 err_fatal ("Error occurred in \"PINIT_FUNC\"."); /* exit */
510 debug_msg("step 100.1\n");
511 debug_msg("ppm image width = %d; height = %d\n", bytes_per_line/3, (int)print_area_y);
512 printJob.verticalOffset = 0;
513 debug_msg("start page %d ======================\n", page_count);
514 if (jobAttr.duplex == EPS_DUPLEX_SHORT && ((page_count % 2) == 0))
516 char* pagebuf = malloc((int)(print_area_y) * (bandBmp.WidthBytes));
517 char* startpage = pagebuf;
519 //debug_msg("height pixel = %d\n", height_pixel);
520 //debug_msg("height pixel [%d]* byte_per_line [%d]=%d// Widthbyte = %d\n", (int)height_pixel, bytes_per_line, (int)(height_pixel)*(bytes_per_line), bandBmp.WidthBytes);
521 for (i = 0; i < print_area_y; i ++)
524 //debug_msg("step 10\n");
525 line = (char *)(band + (bandBmp.WidthBytes * band_line_count));
526 while ((0 == y_count) || ((i > (y_mag * y_count) - 1) && (y_count < height_pixel))) {
527 while ((0 == err) && (read_size < bytes_per_line)) {
529 rsize = read(STDIN_FILENO, image_raw + read_size, bytes_per_line - read_size);
530 //debug_msg("step 11\n");
532 if ((errno != EINTR) && (errno != EAGAIN) && (errno != EIO)) {
544 if( read_size == bytes_per_line ){
550 /* convert input raster data to output byte data. */
552 if ( 1 == byte_par_pixel )
556 //debug_msg("step 12\n");
557 if ( 1 == byte_par_pixel )
560 for ( j = 0; j < print_area_x; j++ )
562 for ( k = 0; k < copybyte ; k++ )
563 line[j * 3 + k] = image_raw[j];
567 memcpy (line, image_raw, bytes_per_line);
571 //debug_msg("step 13\n");
573 for (j = 0; j < print_area_x; j ++)
576 while ( x_count == 0 || j > x_mag * x_count)
578 for ( k = 0; k < copybyte ; k++ )
579 memcpy (line + (j * 3 ) + k,
580 image_raw + ((x_count - 1) * byte_par_pixel),
584 //debug_msg("step 14\n");
586 if (band_line_count >= band_line)
588 bandRect.bottom = bandRect.top + band_line_count;
589 printHeight = band_line_count;
591 memcpy(pagebuf, bandBmp.Bits, bandBmp.WidthBytes);
593 fp = fopen(ppmfilename, "a+");
595 for(i=0; i<bytes_per_line/byte_par_pixel*3; i++){
596 fprintf(fp, "%u ", (unsigned char)pagebuf[i]);
601 pagebuf+= bandBmp.WidthBytes;
602 posbuf+=bandBmp.WidthBytes;
603 //D_PrintBand (bandBmp.Bits, bandBmp.WidthBytes, &printHeight);
604 band_line_count -= printHeight;
605 bandBmp.Bits += band_line_count;
607 bandRect.top = bandRect.bottom;
610 //debug_msg("step 15\n");
611 if (band_line_count > 0)
613 bandRect.bottom = bandRect.top + band_line_count;
615 memcpy(pagebuf, bandBmp.Bits, bandBmp.WidthBytes);
617 fp = fopen(ppmfilename, "a+");
619 for(i=0; i<bytes_per_line/byte_par_pixel*3; i++){
620 fprintf(fp, "%u ", (unsigned char)pagebuf[i]);
625 pagebuf+= bandBmp.WidthBytes;
626 posbuf+= bandBmp.WidthBytes;
627 band_line_count -= printHeight;
628 bandBmp.Bits += band_line_count;
630 //debug_msg("band line count = %d\n", band_line_count);
631 //debug_msg("width byte = %d\n", bandBmp.WidthBytes);
632 //debug_msg("posbuf = %d\n", posbuf);
635 int pos = posbuf - bandBmp.WidthBytes ;
637 char *rever_buf = malloc(bandBmp.WidthBytes);
638 //debug_msg("byte_par_pixel = %d\n", byte_par_pixel);
639 for (revert = print_area_y; revert > 0; revert--)
641 if (3 != byte_par_pixel)
644 for (k = bandBmp.WidthBytes/3; k >= 0; k--)
646 memcpy(rever_buf + k*3, startpage + pos + (bandBmp.WidthBytes) - k*3, 3);
652 for (k = bandBmp.WidthBytes/3; k >= 0; k--)
654 memcpy(rever_buf + k*3, startpage + pos + (bandBmp.WidthBytes - 6) - k*3, 3);
657 // memcpy(rever_buf + k*3, startpage + pos + bandBmp.WidthBytes + 3, 3);
660 //debug_msg("k = %d\n", k);
662 //debug_msg("step 100\n");
663 PrintBand (rever_buf, bandBmp.WidthBytes, &printHeight);
664 pos -= bandBmp.WidthBytes;
665 //debug_msg("printHeight = %d\n", printHeight);
666 //debug_msg("WidthByte = %d\n", bandBmp.WidthBytes);
668 debug_msg("free rever\n");
669 if (rever_buf != NULL)
674 debug_msg("free page\n");
681 debug_msg("free page sucessfull\n");
682 err = epsEndPage(FALSE);
685 err_fatal ("Error occurred in \"PEND_FUNC\"."); /* exit */
689 for (i = 0; i < print_area_y; i ++)
693 line = (char *)(band + (bandBmp.WidthBytes * band_line_count));
694 while ((0 == y_count) || ((i > (y_mag * y_count) - 1) && (y_count < height_pixel))) {
695 while ((0 == err) && (read_size < bytes_per_line)) {
698 rsize = read(STDIN_FILENO, image_raw + read_size, bytes_per_line - read_size);
699 /* 2009.03.17 epson-escpr-1.0.0 */
700 /* if user cancels job from CUPS Web Admin, */
701 /* epson-escpr-wrapper exit normally, */
702 /* and read() return rsize = 0 */
704 if ((errno != EINTR) && (errno != EAGAIN) && (errno != EIO)) {
707 /* error then quit */
708 /* don't care err = -1 */
721 /* for "skip reading" */
722 /* modified y_count count up condition and clear read_size */
723 if( read_size == bytes_per_line ){
725 /* need to clear read_size */
726 /* not clear, data still remains on pipe */
732 /* convert input raster data to output byte data. */
736 if ( 1 == byte_par_pixel )
742 if ( 1 == byte_par_pixel )
746 for ( j = 0; j < print_area_x; j++ )
748 for ( k = 0; k < copybyte ; k++ )
749 line[j * 3 + k] = image_raw[j];
753 memcpy (line, image_raw, bytes_per_line);
760 for (j = 0; j < print_area_x; j ++)
764 while ( x_count == 0 || j > x_mag * x_count)
767 for ( k = 0; k < copybyte ; k++ )
768 memcpy (line + (j * 3 ) + k,
769 image_raw + ((x_count - 1) * byte_par_pixel),
777 if (band_line_count >= band_line)
779 bandRect.bottom = bandRect.top + band_line_count;
781 if (escprBandOut (&bandBmp, &bandRect))
782 err_fatal ("Error occurred in \"OUT_FUNC\"."); /* exit */
784 printHeight = band_line_count;
785 PrintBand (bandBmp.Bits, bandBmp.WidthBytes, &printHeight);
787 fp = fopen(ppmfilename, "a+");
789 for(i=0; i<bytes_per_line/byte_par_pixel*3; i++){
790 fprintf(fp, "%u ", (unsigned char)bandBmp.Bits[i]);
795 debug_msg("printHeight = %d\n", printHeight);
796 debug_msg("WidthByte = %d\n", bandBmp.WidthBytes);
797 band_line_count -= printHeight;
798 bandBmp.Bits += band_line_count;
799 bandRect.top = bandRect.bottom;
804 if (band_line_count > 0)
806 bandRect.bottom = bandRect.top + band_line_count;
808 //if (PrintBand (&bandBmp, bandBmp.WidthBytes))
809 err = PrintBand (bandBmp.Bits, bandBmp.WidthBytes, &printHeight);
810 debug_msg("printHeight = %d\n", printHeight);
812 err_fatal ("Error occurred in \"OUT_FUNC\"."); /* exit */
814 fp = fopen(ppmfilename, "a+");
816 for(i=0; i<bytes_per_line/byte_par_pixel*3; i++){
817 fprintf(fp, "%u ", (unsigned char)bandBmp.Bits[i]);
822 band_line_count -= printHeight;
823 bandBmp.Bits += band_line_count;
826 //if (escprTerminatePage (1ESCPR_END_PAGE))
827 err = epsEndPage(FALSE);
829 err_fatal ("Error occurred in \"PEND_FUNC\"."); /* exit */
835 /* 2004.04.15 for 'error' */
838 //escprTerminatePage (ESCPR_END_PAGE);
839 err = epsEndPage(FALSE);
842 //if (escprDestroyJob ())
845 err_fatal ("Error occurred in \"END_FUNC\"."); /* exit */
847 /* free alloced memory */
851 debug_msg("PRINT SUCCESS\n");
857 set_pips_parameter (filter_option_t *filter_opt_p, ESCPR_OPT *printOpt, ESCPR_PRINT_QUALITY *printQuality)
864 if (strlen (filter_opt_p->media) == 0
865 || strlen (filter_opt_p->ink) == 0
866 || strlen (filter_opt_p->quality) == 0)
869 /* pickup MediaType & Quality from input */
870 quality = strrchr(filter_opt_p->quality, '_');
872 if(strlen(quality) == 0)
875 mediaType = str_clone (filter_opt_p->quality, strlen(filter_opt_p->quality) - strlen(quality));
878 printQuality->MediaTypeID = getMediaTypeID(mediaType);
879 jobAttr.mediaTypeIdx = getMediaTypeID(mediaType);
880 debug_msg(" mediaType = %s\n", mediaType);
883 if(strcmp(quality, "_DRAFT") == 0){
884 printQuality->PrintQuality = ESCPR_PQ_DRAFT;
885 jobAttr.printQuality = EPS_MQID_DRAFT;
886 }else if(strcmp(quality, "_NORMAL") == 0){
887 printQuality->PrintQuality = ESCPR_PQ_NORMAL;
888 jobAttr.printQuality = EPS_MQID_NORMAL;
890 printQuality->PrintQuality = ESCPR_PQ_HIGH;
891 jobAttr.printQuality = EPS_MQID_DRAFT;
895 ink = str_clone (filter_opt_p->ink, strlen (filter_opt_p->ink));
896 if (strcmp (ink, "COLOR") == 0){
897 printQuality->ColorMono = ESCPR_CM_COLOR;
898 jobAttr.colorMode = EPS_CM_COLOR;
901 printQuality->ColorMono = ESCPR_CM_MONOCHROME;
902 jobAttr.colorMode = EPS_CM_MONOCHROME;
906 duplex = str_clone (filter_opt_p->duplex, strlen (filter_opt_p->duplex));
907 if (strcmp (duplex, "None") == 0){
908 debug_msg("DUPLEX NONE\n");
909 jobAttr.duplex = EPS_DUPLEX_NONE;
911 if (strcmp (duplex, "DuplexNoTumble") == 0){
912 debug_msg("DUPLEX LONG\n");
913 jobAttr.duplex = EPS_DUPLEX_LONG;
915 if (strcmp (duplex, "DuplexTumble") == 0){
916 debug_msg("DUPLEX SHORT\n");
917 jobAttr.duplex = EPS_DUPLEX_SHORT;
920 printQuality->Brightness = 0;
921 printQuality->Contrast = 0;
922 printQuality->Saturation = 0;
923 printQuality->ColorPlane = ESCPR_CP_FULLCOLOR; /* default for epson-escpr */
924 printQuality->PaletteSize = 0; /* cause ColorPlane is FULLCOLOR */
925 printQuality->PaletteData = NULL;
927 jobAttr.brightness = 0;
928 jobAttr.contrast = 0;
929 jobAttr.saturation = 0;
930 jobAttr.apfAutoCorrect = EPS_APF_ACT_STANDARD;
931 jobAttr.sharpness = 0;
932 jobAttr.colorPlane = ESCPR_CP_FULLCOLOR;
933 jobAttr.paletteSize = 0;
934 jobAttr.paletteData = NULL;
936 jobAttr.feedDirection = EPS_FEEDDIR_PORTRAIT; /* paper feed direction hardcode */
937 jobAttr.paperSource = EPS_MPID_AUTO;
938 jobAttr.printDirection = 0;
940 /* free alloced memory */
948 /* Get PageSize for PIPS */
950 get_page_size (const char *paper, const char *bin_id)
954 const char *path = PAPER_PATH;
957 long l_margin, r_margin, t_margin, b_margin;
959 csv_p = csvlist_open (path);
961 err_fatal ("%s : List file is broken.", path);
963 pos = csvlist_search_keyword (csv_p, 0, paper);
965 err_fatal ("%s : Unknown PageSize.", paper);
968 //if(printJob->InResolution == ESCPR_IR_3636 || printJob->InResolution == ESCPR_IR_7272){
969 if(jobAttr.inputResolution == EPS_IR_360X360 || jobAttr.inputResolution == EPS_IR_720X720){
970 printJob->PaperWidth = atol (csvlist_get_word (csv_p, pos + 2));
971 printJob->PaperLength = atol (csvlist_get_word (csv_p, pos + 3));
973 l_margin = atol (csvlist_get_word (csv_p, pos + 4));
974 r_margin = atol (csvlist_get_word (csv_p, pos + 5));
975 t_margin = atol (csvlist_get_word (csv_p, pos + 6));
976 b_margin = atol (csvlist_get_word (csv_p, pos + 7));
978 printJob->PaperWidth = atol (csvlist_get_word (csv_p, pos + 8));
979 printJob->PaperLength = atol (csvlist_get_word (csv_p, pos + 9));
981 l_margin = atol (csvlist_get_word (csv_p, pos + 10));
982 r_margin = atol (csvlist_get_word (csv_p, pos + 11));
983 t_margin = atol (csvlist_get_word (csv_p, pos + 12));
984 b_margin = atol (csvlist_get_word (csv_p, pos + 13));
989 if (!strcmp (bin_id, "BORDER"))
991 printJob->PrintableAreaWidth = printJob->PaperWidth - l_margin - r_margin;
992 printJob->PrintableAreaLength = printJob->PaperLength - t_margin - b_margin;
993 printJob->TopMargin = t_margin;
994 printJob->LeftMargin = l_margin;
997 else if (!strcmp (bin_id, "BORDERLESS"))
999 if(printJob->InResolution == ESCPR_IR_3636 || printJob->InResolution == ESCPR_IR_7272){
1000 printJob->PrintableAreaWidth = printJob->PaperWidth + 72;
1001 printJob->PrintableAreaLength = printJob->PaperLength + 112;
1002 printJob->TopMargin = -42;
1003 if ( printJob->PaperWidth < 4209 )
1004 printJob->LeftMargin = -36;
1006 printJob->LeftMargin = -48;
1008 printJob->PrintableAreaWidth = printJob->PaperWidth + 60;
1009 printJob->PrintableAreaLength = printJob->PaperLength + 93;
1010 printJob->TopMargin = -35;
1011 if ( printJob->PaperWidth < 3507 )
1012 printJob->LeftMargin = -30;
1014 printJob->LeftMargin = -40;
1022 err_fatal ("%s : This sheet feeder is not supported.");
1025 printJob->PrintDirection = 0;
1027 /* free alloced memory */
1028 csvlist_close(csv_p);
1033 static int getMediaTypeID(char *rsc_name)
1036 debug_msg("mediatype name = %s\n", rsc_name);
1037 for(j = 0; mediaTypeData[j].value != END_ARRAY; j++)
1038 if(strcmp(mediaTypeData[j].rsc_name,rsc_name) == 0)
1040 debug_msg("mediatype found, idx = %d\n", mediaTypeData[j].value);
1041 return mediaTypeData[j].value;
1046 ESCPR_BYTE4 print_spool_fnc(void* hParam, const ESCPR_UBYTE1* pBuf, ESCPR_UBYTE4 cbBuf)
1049 for (i = 0; i < cbBuf; i++)
1050 putc(*(pBuf + i), outfp);