2 * EPSON ESC/P-R Printer Driver for Linux
3 * Copyright (C) 2002-2005 AVASYS CORPORATION.
4 * Copyright (C) Seiko Epson Corporation 2002-2005.
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.
20 * As a special exception, AVASYS CORPORATION gives permission to
21 * link the code of this program with libraries which are covered by
22 * the AVASYS Public License and distribute their linked
23 * combinations. You must obey the GNU General Public License in all
24 * respects for all of the code used other than the libraries which
25 * are covered by AVASYS Public License.
40 #include <cups/cups.h>
41 #include <cups/raster.h>
46 #include "epson-escpr-def.h"
47 #include "epson-escpr-media.h"
48 #include "epson-escpr-pvt.h"
49 #include "epson-escpr-api.h"
50 #include "epson-escpr-services.h"
51 #include "epson-escpr-mem.h"
52 #include "epson-escpage.h"
53 #include "linux_cmn.h"
58 #define EPS_PARAM_MP_TRAY 0x00
59 #define EPS_PARAM_CASSETTE1 0x01
60 #define EPS_PARAM_CASSETTE2 0x02
61 #define EPS_PARAM_CASSETTE3 0x03
62 #define EPS_PARAM_CASSETTE4 0x04
63 #define EPS_PARAM_MANUALFEED 0x0A
64 #define EPS_PARAM_AUTO_TRAY 0xFF
66 #define WIDTH_BYTES(bits) (((bits) + 31) / 32 * 4)
68 #define PIPSLITE_FILTER_VERSION "* epson-escpr is a part of " PACKAGE_STRING
70 #define PIPSLITE_FILTER_USAGE "Usage: $ epson-escpr model width_pixel height_pixel Ink PageSize Quality"
74 #define EPS_END_PAGE 0 /* There is no next page */
78 #define EPS_NEXT_PAGE 1 /* There is a next page */
81 #define PIPSLITE_WRAPPER_VERSION "* epson-escpr-wrapepr is a part of " PACKAGE_STRING
82 #define CUPS_FILTER_PATH "/opt/epson-abcdef/"
83 #define CUPS_FILTER_NAME "epson-escpage"
85 typedef struct rtp_filter_option {
87 char model_low[NAME_MAX];
90 char quality[NAME_MAX];
91 char duplex[NAME_MAX];
96 /* static functions */
97 static int getMediaTypeID(char *);
98 static int getMediaSizeID(char *);
99 const int band_line = 1;
101 extern EPS_INT32 libStatus; /* Library (epsInitDriver) status */
102 extern EPS_PRINT_JOB printJob;
103 extern EPS_UINT32 sendDataBufSize;
104 extern EPS_UINT8* sendDataBuf; /* buffer of SendCommand(save) input */
105 extern EPS_UINT32 tmpLineBufSize;
106 extern EPS_UINT8* tmpLineBuf;
108 extern EPS_CMN_FUNC epsCmnFnc;
110 extern EPS_INT32 back_type;
111 extern EPS_INT32 lWidth;
112 extern EPS_INT32 lHeight;
113 extern EPS_INT32 areaWidth;
114 extern EPS_INT32 areaHeight;
116 #ifndef ESCPR_HEADER_LENGTH
117 #define ESCPR_HEADER_LENGTH 10 /* ESC + CLASS + ParamLen + CmdName */
120 #ifndef ESCPR_SEND_DATA_LENGTH
121 #define ESCPR_SEND_DATA_LENGTH 7
125 EPS_ERR_CODE epsInitLib(){
126 EPS_CMN_FUNC cmnFuncPtrs;
127 memset(&cmnFuncPtrs, 0, sizeof(EPS_CMN_FUNC));
129 cmnFuncPtrs.version = EPS_CMNFUNC_VER_CUR;
130 cmnFuncPtrs.findCallback = NULL;
131 cmnFuncPtrs.memAlloc = &epsmpMemAlloc;
132 cmnFuncPtrs.memFree = &epsmpMemFree;
133 cmnFuncPtrs.sleep = &epsmpSleep;
134 cmnFuncPtrs.getTime = &epsmpGetTime;
135 cmnFuncPtrs.getLocalTime = &epsmpGetLocalTime;
136 cmnFuncPtrs.lockSync = &epsmpLockSync;
137 cmnFuncPtrs.unlockSync = &epsmpUnlockSync;
138 cmnFuncPtrs.stateCallback = NULL; /* current version unused */
140 memcpy((void*)(&epsCmnFnc), (void*)&cmnFuncPtrs, sizeof(EPS_CMN_FUNC));
143 EPS_ERR_CODE epsInitJob(){
145 memset(&printJob, 0, sizeof(EPS_PRINT_JOB));
146 printJob.printer = (EPS_PRINTER_INN*) malloc(sizeof(EPS_PRINTER_INN));
147 memset(printJob.printer, 0, sizeof(EPS_PRINTER_INN));
149 printJob.jobStatus = EPS_STATUS_NOT_INITIALIZED;
150 printJob.pageStatus = EPS_STATUS_NOT_INITIALIZED;
151 printJob.findStatus = EPS_STATUS_NOT_INITIALIZED;
152 printJob.bComm = TRUE;
153 printJob.platform = 0x04; /* '0x04 = linux' is default */
155 libStatus = EPS_STATUS_NOT_INITIALIZED;
161 /*** Initialize continue buffer */
162 printJob.contData.sendData = NULL;
163 printJob.contData.sendDataSize = 0;
165 /* DEL printJob.additional = EPS_ADDDATA_NONE;
166 printJob.qrcode.bits = NULL;
167 printJob.qrcode.cellNum = 0;
168 printJob.qrcode.dpc = 0; */
171 /*** Set "Endian-ness" for the current cpu */
174 /*** Set Communication Mode */
175 //printJob.commMode = commMode;
177 /*** Change ESC/P-R Lib Status */
178 libStatus = EPS_STATUS_INITIALIZED;
179 EPS_PRINTER_INN* printer = printJob.printer;
180 printer->pmData.state = EPS_PM_STATE_NOT_FILTERED;
181 printer->language = EPS_LANG_ESCPAGE;
186 EPS_ERR_CODE epsInitVariable(){
187 sendDataBufSize = (EPS_INT32)(ESCPR_HEADER_LENGTH +
188 ESCPR_SEND_DATA_LENGTH +
189 (printJob.printableAreaWidth * printJob.bpp));
190 sendDataBuf = (EPS_UINT8*)EPS_ALLOC(sendDataBufSize);
191 if(sendDataBuf == NULL){
193 EPS_RETURN( EPS_ERR_MEMORY_ALLOCATION );
196 memset(sendDataBuf, 0xFF, (EPS_UINT32)sendDataBufSize);
197 /*** Allocate buffer for RLE complession */
198 tmpLineBufSize = (EPS_INT32)(printJob.printableAreaWidth * printJob.bpp) + 256; /* 256 is temp buffer */
199 tmpLineBuf = (EPS_UINT8*)EPS_ALLOC(tmpLineBufSize);
200 if(tmpLineBuf == NULL){
202 EPS_RETURN( EPS_ERR_MEMORY_ALLOCATION );
204 memset(tmpLineBuf, 0xFF, (EPS_UINT32)tmpLineBufSize);
209 EPS_ERR_CODE epsFilterEndPage(EPS_BOOL bNextPage){
210 EPS_ERR_CODE retStatus= EPS_ERR_NONE;
212 #ifdef GCOMSW_CMD_ESCPAGE_S
213 retStatus = pageEndPage();
215 retStatus = EPS_ERR_LANGUAGE_NOT_SUPPORTED;
222 void eps_toupper(char *str){
225 if(str == NULL || strlen(str) == 0){
229 for(i = 0; i < len; i++){
230 str[i] = toupper(str[i]);
235 /* Get value for PPD */
236 static char *get_default_choice (ppd_file_t *ppd_p, const char *key)
238 ppd_option_t *option;
239 ppd_choice_t *choice;
241 option = ppdFindOption (ppd_p, key);
243 if( option == NULL && strcmp(key, "FaceUp") == 0 ) {
244 debug_msg("__ Face Down __\n");
250 debug_msg("option null\n");
254 choice = ppdFindChoice (option, option->defchoice);
257 debug_msg("choice null\n");
260 debug_msg("choice ok = [%s]\n", choice->choice);
261 return choice->choice;
265 int epsGetInputOption(char** in_argv,int in_argc, char *opt, char *dest)
269 char *str_tmp = NULL;
271 if(opt == NULL || strlen(opt) == 0 || dest == NULL ){
274 for(i = 0; i < in_argc; i++){
275 if(strcmp(opt, "RiTech") == 0)
277 str_tmp = strstr(in_argv[i], "noRiTech");
280 strcpy(dest, "False");
284 str_tmp = strstr(in_argv[i], "RiTech");
287 strcpy(dest, "True");
292 if(strcmp(opt, "TonerSave") == 0)
294 str_tmp = strstr(in_argv[i], "noTonerSaving");
297 strcpy(dest, "False");
300 str_tmp = strstr(in_argv[i], "TonerSaving");
303 strcpy(dest, "True");
308 if(strcmp(opt, "Duplex") == 0)
310 str_tmp = strstr(in_argv[i], "Duplex=DuplexNoTumble");
313 strcpy(dest, "DuplexNoTumble");
315 } else if(str_tmp = strstr(in_argv[i], "Duplex=DuplexTumble")){
318 strcpy(dest, "DuplexTumble");
322 strcpy(dest, "None");
326 if(strcmp(opt, "Orientation") == 0)
328 str_tmp = strstr(in_argv[i], "Orientation=Portrait");
331 strcpy(dest, "Portrait");
333 } else if(str_tmp = strstr(in_argv[i], "Orientation=Landscape")){
336 strcpy(dest, "Landscape");
341 str = strstr(in_argv[i], opt);
342 if(str != NULL && (str[strlen(opt)] == '=') && strncmp(str, opt, strlen(opt)) == 0){
343 strcpy(dest_t, str + strlen(opt) + 1);
345 while((dest_t[j] != ' ') && (j < 20))
356 debug_msg("return -1 \n");
361 static char *getOptionForJob(ppd_file_t *ppd_p, const char** argv, const int argc, char *key)
363 char *opt_tmp = NULL;
369 error = epsGetInputOption (argv, argc, key, opt_t);
375 opt_tmp = get_default_choice (ppd_p, key);
377 if(strcmp(key, "Duplex") == 0)
379 debug_msg("Duplex = %s \n", opt_tmp);
385 static int setupOptionforJob(const char** argv, const int argc, EPS_JOB_ATTRIB *jobAttr, const char *printer)
387 char *ppd_path; /* Path of PPD */
388 ppd_file_t *ppd_p; /* Struct of PPD */
389 char *opt = NULL; /* Temporary buffer (PPD option) */
393 jobAttr->colorPlane = EPS_CP_FULLCOLOR;
394 jobAttr->printDirection = EPS_PD_BIDIREC;
395 jobAttr->brightness = 0;
396 jobAttr->mediaSizeIdx = -1;
397 jobAttr->mediaTypeIdx = -1;
398 jobAttr->paperSource = 10000;
399 jobAttr->duplex = -1;
400 jobAttr->tonerSave = -1;
401 jobAttr->RiTech = -1;
402 jobAttr->colLate = -1;
403 jobAttr->contrast = 0;
404 jobAttr->orienTation = -1;
405 jobAttr->manualFeed = -1;
406 jobAttr->printQuality = 10000;
408 /* Get option from PPD. */
409 ppd_path = (char *) cupsGetPPD (printer);
410 ppd_p = ppdOpenFile (ppd_path);
414 /* get Color option */
415 opt = getOptionForJob(ppd_p, argv, argc, "Color");
417 debug_msg("opt check = %s \n", opt);
418 if(strcmp(opt, "MONO") == 0){
419 jobAttr->colorMode = EPS_CM_MONOCHROME;
421 jobAttr->colorMode = EPS_CM_COLOR;
424 jobAttr->colorMode = EPS_CM_MONOCHROME;
426 debug_msg("debug 1\n");
428 opt = getOptionForJob(ppd_p, argv, argc, "PageSize");
429 debug_msg("opt = %s\n", opt);
431 debug_msg("opt check = %s \n", opt);
432 jobAttr->mediaSizeIdx = getMediaSizeID(opt);
433 debug_msg("jobAttr->mediaSizeIdx = %d\n", jobAttr->mediaSizeIdx);
435 debug_msg("debug 2\n");
437 opt = getOptionForJob(ppd_p, argv, argc, "MediaType");
439 jobAttr->mediaTypeIdx = getMediaTypeID(opt);
441 debug_msg("debug 3\n");
444 opt = getOptionForJob(ppd_p, argv, argc, "InputSlot");
447 debug_msg("get option InputSlot \n");
450 if(strcmp(opt, "Auto") == 0){
451 jobAttr->paperSource = IPS_MPTID_AUTO;
452 }else if(strcmp(opt, "TRAY1") == 0){
453 jobAttr->paperSource = IPS_MPTID_TRAY1;
454 }else if(strcmp(opt, "TRAY2") == 0){
455 jobAttr->paperSource = IPS_MPTID_TRAY2;
456 }else if(strcmp(opt, "TRAY3") == 0){
457 jobAttr->paperSource = IPS_MPTID_TRAY3;
458 }else if(strcmp(opt, "TRAY4") == 0){
459 jobAttr->paperSource = IPS_MPTID_TRAY4;
460 }else if(strcmp(opt, "TRAY5") == 0){
461 jobAttr->paperSource = IPS_MPTID_TRAY5;
462 }else if(strcmp(opt, "TRAY6") == 0){
463 jobAttr->paperSource = IPS_MPTID_TRAY6;
464 }else if(strcmp(opt, "TRAY7") == 0){
465 jobAttr->paperSource = IPS_MPTID_TRAY7;
466 }else if(strcmp(opt, "TRAY8") == 0){
467 jobAttr->paperSource = IPS_MPTID_TRAY8;
468 }else if(strcmp(opt, "TRAY9") == 0){
469 jobAttr->paperSource = IPS_MPTID_TRAY9;
470 }else if(strcmp(opt, "TRAY10") == 0){
471 jobAttr->paperSource = IPS_MPTID_TRAY10;
472 }else if(strcmp(opt, "TRAY11") == 0){
473 jobAttr->paperSource = IPS_MPTID_TRAY11;
474 }else if(strcmp(opt, "TRAY12") == 0){
475 jobAttr->paperSource = IPS_MPTID_TRAY12;
476 }else if(strcmp(opt, "TRAY13") == 0){
477 jobAttr->paperSource = IPS_MPTID_TRAY13;
478 }else if(strcmp(opt, "TRAY14") == 0){
479 jobAttr->paperSource = IPS_MPTID_TRAY14;
480 }else if(strcmp(opt, "TRAY15") == 0){
481 jobAttr->paperSource = IPS_MPTID_TRAY15;
482 } else jobAttr->paperSource = IPS_MPTID_AUTO;
486 jobAttr->paperSource = IPS_MPTID_AUTO;
491 opt = getOptionForJob(ppd_p, argv, argc, "Duplex");
493 if(strcmp(opt, "DuplexTumble") == 0){
494 jobAttr->duplex = EPS_DUPLEX_SHORT;
495 }else if(strcmp(opt, "DuplexNoTumble") == 0){
496 jobAttr->duplex = EPS_DUPLEX_LONG;
498 jobAttr->duplex = EPS_DUPLEX_NONE;
500 debug_msg("jobAttr->duplex = %d\n", jobAttr->duplex);
502 debug_msg("debug 4\n");
504 opt = getOptionForJob(ppd_p, argv, argc, "Tonersave");
507 if(strcmp(opt, "TRUE") == 0){
508 jobAttr->tonerSave = 1; //ON
510 if(strcmp(opt, "FALSE") == 0){
511 jobAttr->tonerSave = 0; //OFF
515 /* get option RiTech */
516 opt = getOptionForJob(ppd_p, argv, argc, "RiTech");
519 if(strcmp(opt, "TRUE") == 0){
520 jobAttr->RiTech = 1; //ON
522 if(strcmp(opt, "FALSE") == 0){
523 jobAttr->RiTech = 0; //OFF
527 /*get option Quality*/
528 opt = getOptionForJob(ppd_p, argv, argc, "Quality");
529 debug_msg("Quality: = %s\n", opt);
531 if(strcmp(opt, "300x300dpi") == 0){
532 debug_msg("__ Nam 0 __\n");
533 jobAttr->printQuality = EPS_MQID_DRAFT;
534 jobAttr->inputResolution = EPS_IR_300X300;
535 jobAttr->topMargin = 300/6;
537 if(strcmp(opt, "600x600dpi") == 0){
538 debug_msg("__ Nam 1 __\n");
539 jobAttr->printQuality = EPS_MQID_NORMAL;
540 jobAttr->inputResolution = EPS_IR_600X600;
541 jobAttr->topMargin = 600/6;
543 if (strcmp(opt, "1200x1200dpi") == 0) {
544 debug_msg("__ Nam 2 __\n");
545 jobAttr->printQuality = EPS_MQID_HIGH;
546 jobAttr->inputResolution = EPS_IR_1200X1200;
547 jobAttr->topMargin = 1200/6;
551 /*get option Collate*/
552 opt = getOptionForJob(ppd_p, argv, argc, "Collate");
555 if((strcmp(opt, "TRUE") == 0) || (strcmp(opt, "ON") == 0)){
556 jobAttr->colLate = 1; //ON
557 } else jobAttr->colLate = 0; //OFF
560 /*get option Orientation*/
561 debug_msg("debug orientation \n");
562 opt = getOptionForJob(ppd_p, argv, argc, "Orientation");
565 if(strcmp(opt, "LANDSCAPE") == 0){
566 jobAttr->orienTation = 1; //Landscape
567 } else jobAttr->orienTation = 0; //Portrai
570 /*get option ManualFeed*/
571 debug_msg("debug manual feed \n");
572 opt = getOptionForJob(ppd_p, argv, argc, "ManualFeed");
575 if( strcmp(opt, "MANUAL") == 0 ){
576 debug_msg("check manual feed \n");
577 jobAttr->manualFeed = 1; //Manual
579 jobAttr->manualFeed = 0; //Automatic
583 opt = getOptionForJob(ppd_p, argv, argc, "FaceUp");
586 if(strcmp(opt, "True") == 0){
587 jobAttr->FacingPage = 1;
589 jobAttr->FacingPage = 0;
591 debug_msg("jobAttr->FacingPage = %d\n", jobAttr->FacingPage);
595 /*get option copies*/
596 opt = getOptionForJob(ppd_p, argv, argc, "nCopies");
598 jobAttr->copies = atoi(opt);
599 debug_msg("jobAttr->copies = %d", jobAttr->copies);
600 if(jobAttr->copies < 1 || jobAttr->copies > 999){
605 jobAttr->printLayout = EPS_MLID_BORDERS;
606 jobAttr->feedDirection = EPS_FEEDDIR_PORTRAIT; /* paper feed direction hardcode */
613 int main (int argc, char *argv[])
615 int fd; /* file descriptor */
619 cups_raster_t *ras; /* raster stream for printing */
620 cups_page_header_t header; /* page device dictionary header */
623 debug_msg("%s:%d \t<<%s>>: \t\tStart()\n", __FILE__, __LINE__, __FUNCTION__);
628 while (flag) sleep (3);
629 #endif /* USE_DEBUGGER */
631 for (i = 0; i < argc; i++)
632 debug_msg("%s:%d \t<<%s>>: \t\t argv[%d] = [%s]\n", __FILE__, __LINE__, __FUNCTION__, i, argv[i]);
634 debug_msg("%s:%d \t<<%s>>: \t\tStart get cups option\n", __FILE__, __LINE__, __FUNCTION__);
635 /*get_option_for_arg(argv, argc, &fopt);
636 get_cups_option(argv[0], &fopt); */
637 resul = setupOptionforJob(argv, argc, &fopt, argv[0]);
639 debug_msg("not setup option for job \n");
643 ras = cupsRasterOpen (fd, CUPS_RASTER_READ);
646 fprintf (stderr, "Can't open CUPS raster file.");
647 debug_msg("%s:%d \t<<%s>>: \t\tCan't open CUPS raster file\n", __FILE__, __LINE__, __FUNCTION__);
651 do_printJob(pfp, ras, fopt);
653 debug_msg("Check start call function close rsater file \n");
655 cupsRasterClose (ras);
657 debug_msg("Check end call function close rsater file");
661 static int getMediaTypeID(char *rsc_name)
663 debug_msg("%s:%d \t<<%s>>: \t\tTrace in()\n", __FILE__, __LINE__, __FUNCTION__);
665 for(j = 0; mediaTypeData[j].value != END_ARRAY; j++){
666 if(strncmp(mediaTypeData[j].rsc_name,rsc_name, strlen(mediaTypeData[j].rsc_name)) == 0){
667 debug_msg("%s:%d \t<<%s>>: \t\tmediaTypeData[%d].rsc_name = %s, value = %d\n", __FILE__, __LINE__, __FUNCTION__, j, mediaTypeData[j].rsc_name, mediaTypeData[j].value);
668 debug_msg("%s:%d \t<<%s>>: \t\tTrace out OK [%d]\n", __FILE__, __LINE__, __FUNCTION__, mediaTypeData[j].value);
669 return mediaTypeData[j].value;
671 debug_msg("%s:%d \t<<%s>>: \t\tTrace out Fail()\n", __FILE__, __LINE__, __FUNCTION__);
675 static int getMediaSizeID(char *media_name)
677 debug_msg("check media size \n");
678 debug_msg("%s:%d \t<<%s>>: \t\tTrace in()\n", __FILE__, __LINE__, __FUNCTION__);
681 for(j = 0; mediaSizeData[j].value != END_ARRAY; j++){
682 if(strncmp(mediaSizeData[j].rsc_name,media_name, strlen(mediaSizeData[j].rsc_name)) == 0){
683 eps_toupper(media_name);
684 debug_msg("media_name = %s \n", media_name);
685 if(strcmp(media_name, "USER")==0){
686 debug_msg("%s:%d \t<<%s>>: \t\tTrace out USER mode\n", __FILE__, __LINE__, __FUNCTION__);
689 debug_msg("%s:%d \t<<%s>>: \t\tTrace out OK [%d]()\n", __FILE__, __LINE__, __FUNCTION__, mediaSizeData[j].value);
690 return mediaSizeData[j].value;
696 int do_printJob(FILE* pfp,cups_raster_t *ras, EPS_JOB_ATTRIB jobAttr)
698 debug_msg("%s:%d \t<<%s>>: \tTrace in \n", __FILE__, __LINE__, __FUNCTION__);
699 cups_page_header_t header;
700 int width_pixel, height_pixel;
705 double print_area_x, print_area_y;
707 int leftMargin, topMargin;
713 EPS_INT32 heightPixels = 0;
717 char ppmfilename[30];
722 if (jobAttr.colorMode == EPS_CM_COLOR) {
728 while (cupsRasterReadHeader (ras, &header) > 0 && !cancel_flg)
730 debug_msg("%s:%d \t<<%s>>: \tStart Cupsraster read header \n", __FILE__, __LINE__, __FUNCTION__);
738 width_pixel = header.cupsWidth;
739 height_pixel = header.cupsHeight;
742 err = SetupJobAttrib(&jobAttr);
745 err_fatal ("Error occurred in \"SetupJobAttrib\"."); /* exit */
747 printJob.paperWidth = width_pixel;
748 printJob.paperHeight = height_pixel;
751 switch(printJob.attr.inputResolution)
754 printJob.topMargin = 50;
755 printJob.leftMargin = 50;
758 printJob.topMargin = 100;
759 printJob.leftMargin = 100;
762 printJob.topMargin = 200;
763 printJob.leftMargin = 200;
767 leftMargin = printJob.leftMargin;
768 topMargin = printJob.topMargin;
770 printJob.printableAreaHeight = (EPS_UINT32)height_pixel;// - (printJob.topMargin + printJob.leftMargin);
771 printJob.printableAreaWidth = (EPS_UINT32)width_pixel;// - (printJob.topMargin + printJob.leftMargin);
772 err = pageAllocBuffer();
775 debug_msg("%s:%d \t<<%s>>: \t\t Error occurred in \"pageAllocBuffer\".", __FILE__, __LINE__, __FUNCTION__); /* exit */
776 err_fatal ("Error occurred in \"pageAllocBuffer\"."); /* exit */
779 debug_msg("%s:%d \t<<%s>>: \t\t pageAllocBuffer() success\n", __FILE__, __LINE__, __FUNCTION__);
782 EPS_PRINTER_INN curPrinter;
783 memset(&curPrinter, 0, sizeof(curPrinter));
784 if(jobAttr.colorMode == EPS_CM_COLOR){
785 curPrinter.language = EPS_LANG_ESCPAGE_COLOR;
787 curPrinter.language = EPS_LANG_ESCPAGE;
790 printJob.printer = &curPrinter;
791 err = pageStartJob();
794 err_fatal ("Error occurred in \"pageStartJob\"."); /* exit */
797 debug_msg("%s:%d \t<<%s>>: \t\t pageStartJob() success", __FILE__, __LINE__, __FUNCTION__);
800 err = pageStartPage();
803 debug_msg("%s:%d \t<<%s>>: \t\t Error occurred in \"pageStartPage\": %d\n", __FILE__, __LINE__, __FUNCTION__, err);
804 err_fatal ("Error occurred in \"pageStartPage\"."); /* exit */
807 debug_msg("%s:%d \t<<%s>>: \t\t pageStartPage() success", __FILE__, __LINE__, __FUNCTION__);
809 printJob.verticalOffset = 0;
810 print_area_x = printJob.printableAreaWidth;
811 print_area_y = printJob.printableAreaHeight;
813 bytes_per_line = (width_pixel * byte_par_pixel);
815 int band_out_len = printJob.printableAreaWidth*byte_par_pixel;
816 //band_out_len += band_out_len % 2;
817 band_out_len = ((band_out_len +7)/8)*8;
818 char *bandPrint = mem_new0(char, band_out_len*band_line);
820 image_raw = mem_new0 (char, bytes_per_line);
823 if(byte_par_pixel == 1)
825 grayBuff = mem_new0 (char, band_out_len*band_line*3);
830 long int total_bytes = 0;
832 image_bytes = WIDTH_BYTES(header.cupsBytesPerLine)*8;
835 sprintf(ppmfilename, "/tmp/al-m2010-page%d.ppm", page_count);
836 fp = fopen(ppmfilename, "w");
837 if(jobAttr.colorMode == EPS_CM_COLOR){
842 fprintf(fp, "%u\n",(int)printJob.printableAreaWidth);
843 fprintf(fp, "%u\n",(int)header.cupsHeight);
844 fprintf(fp, "255\n");
849 debug_msg("%s:%d \t<<%s>>: \t\timage_bytes = %d\n", __FILE__, __LINE__, __FUNCTION__, image_bytes);
850 image_raw = (char *)calloc (sizeof (char), image_bytes);
853 debug_msg("duplex = %d, page_count = %d\n", jobAttr.duplex, page_count);
855 for (i = 0; i < header.cupsHeight && !cancel_flg; i ++)
857 debug_msg("%s:%d \t<<%s>>: \tStart print line [%d]\n", __FILE__, __LINE__, __FUNCTION__, i);
858 int numread = cupsRasterReadPixels (ras, (unsigned char*)image_raw, header.cupsBytesPerLine);
861 fprintf (stderr, "cupsRasterReadPixels");
862 debug_msg("%s:%d \t<<%s>>: \t\tcupsRasterReadPixels error\n", __FILE__, __LINE__, __FUNCTION__);
865 debug_msg("%s:%d \t<<%s>>: \t numread = %d\n", __FILE__, __LINE__, __FUNCTION__, numread);
866 memcpy (bandPrint + (heightPixels%band_line) * band_out_len, image_raw, band_out_len );
869 debug_msg("header.cupsBytesPerLine = %d\n", header.cupsBytesPerLine);
870 if (i < printJob.paperHeight)
872 if(byte_par_pixel == 1)
876 for(j = 0; j < band_out_len*band_line; j++)
878 grayBuff[j*3] = bandPrint[j];
879 grayBuff[j*3+1] = bandPrint[j];
880 grayBuff[j*3+2] = bandPrint[j];
882 debug_msg("byte_par_pixel = %d\n", byte_par_pixel);
883 err = PrintBand (grayBuff, band_out_len*band_line*3, &heightPixels);
886 fp = fopen(ppmfilename, "a+");
887 for(k=0; k<(int)header.cupsBytesPerLine; k++)
889 fprintf(fp, "%u ", (unsigned char)bandPrint[k]);
896 debug_msg("byte_par_pixel = %d\n", byte_par_pixel);
897 err = PrintBand (bandPrint, band_out_len, &heightPixels);
900 fp = fopen(ppmfilename, "a+");
901 for(k=0; k<(int)header.cupsBytesPerLine; k++)
903 fprintf(fp, "%u ", (unsigned char)bandPrint[k]);
910 //err = PrintBand (image_raw, band_out_len, &heightPixels);
913 if(err == EPS_OUT_OF_BOUNDS)
915 debug_msg("EPS_OUT_OF_BOUNDS\n");
918 debug_msg("PrintBand error: %d\n", err);
919 err_fatal ("Error occurred in \"OUT_FUNC\"."); /* exit */
922 debug_msg("PrintBand success\n");
924 debug_msg("%s:%d \t<<%s>>: \tCompleted print line [%d]\n", __FILE__, __LINE__, __FUNCTION__, i);
927 debug_msg("pageEndPage(%d) call\n", page_count);
931 debug_msg("pageEndPage() error: %d\n", err);
932 err_fatal ("Error occurred in \"PEND_FUNC\"."); /* exit */
935 debug_msg("pageEndPage() success\n");
944 err_fatal ("Error occurred in \"pageEndJob\"."); /* exit */
946 debug_msg("pageEndJob() success\n");