/epson-inkjet-printer-escpr/lib/epson-escpr-api.c

https://review.tizen.org/git/ · C · 5687 lines · 3128 code · 836 blank · 1723 comment · 990 complexity · c6c892ff60272920bdb72896e5f5842d MD5 · raw file

  1. /*_______________________________ epson-escpr-api.c ________________________________*/
  2. /* 1 2 3 4 5 6 7 8 */
  3. /*34567890123456789012345678901234567890123456789012345678901234567890123456789012345678*/
  4. /*******************************************|********************************************/
  5. /*
  6. * Copyright (c) 2009 Seiko Epson Corporation All rights reserved.
  7. *
  8. * Copyright protection claimed includes all forms and matters of
  9. * copyrightable material and information now allowed by statutory or judicial
  10. * law or hereinafter granted, including without limitation, material generated
  11. * from the software programs which are displayed on the screen such as icons,
  12. * screen display looks, etc.
  13. *
  14. */
  15. /*******************************************|********************************************/
  16. /* */
  17. /* Epson ESC/P-R Library APIs */
  18. /* */
  19. /* Core Function Calls */
  20. /* -------------------------- */
  21. /* API-0001 EPS_ERR_CODE epsInitDriver (commMode, usbFuncPtrs, */
  22. /* netFuncPtrs, cmnFuncPtrs); */
  23. /* API-0002 EPS_ERR_CODE epsReleaseDriver (); */
  24. /* API-0003 EPS_ERR_CODE epsFindPrinter (protocol, timeout); */
  25. /* API-0004 EPS_ERR_CODE epsProbePrinter (probeParam); */
  26. /* API-0005 EPS_ERR_CODE epsCancelFindPrinter (); */
  27. /* API-0006 EPS_ERR_CODE epsSetPrinter (printer); */
  28. /* API-0007 EPS_ERR_CODE epsStartJob (jobAttrib); */
  29. /* API-0008 EPS_ERR_CODE epsStartPage (pageAttrib); */
  30. /* API-0009 EPS_ERR_CODE epsPrintBand (imageData,width,,height); */
  31. /* API-0010 EPS_ERR_CODE epsSendData (prnData); */
  32. /* API-0011 EPS_ERR_CODE epsEndPage (); */
  33. /* API-0012 EPS_ERR_CODE epsEndJob (); */
  34. /* API-0013 EPS_ERR_CODE epsCancelJob (reserve); */
  35. /* API-0014 EPS_ERR_CODE epsContinueJob (); */
  36. /* API-0015 EPS_ERR_CODE epsGetStatus (status); */
  37. /* API-0016 EPS_ERR_CODE epsGetSupportedMedia (media); */
  38. /* API-0017 EPS_ERR_CODE epsGetPrintableArea (pageAttrib, */
  39. /* printableWidth, */
  40. /* printableHeight); */
  41. /* */
  42. /*******************************************|********************************************/
  43. /*------------------------------ Local Compiler Switch -------------------------------*/
  44. /*******************************************|********************************************/
  45. /*** 4KB Packet Data */
  46. /***--------------------------------------------------------------------------------*/
  47. #define LCOMSW_PACKET_4KB 0 /* 0: Make any size packet */
  48. /* 1: Make 4KB packet */
  49. #define LCOMSW_CANCEL_JOB 0
  50. #define LCOMSW_USE_720DPI 0 /* Not support 720dpi */
  51. #define ESCPR_DEBUG_IMAGE_LOG 0 /* 0: OFF 1: ON */
  52. #define LCOMSW_DUMMY_SEND 0 /* 1: Enable 0byte data sending */
  53. /*#define LCOMSW_JOBPARAM_CEHCK_OFF*/
  54. /* #define LCOMSW_CMDDMP */
  55. /*------------------------------------ Includes -------------------------------------*/
  56. /*******************************************|********************************************/
  57. #include "epson-escpr-pvt.h"
  58. #include "epson-escpr-services.h"
  59. #include "epson-escpr-mem.h"
  60. #include "epson-protocol.h"
  61. #include "epson-layout.h"
  62. #ifdef GCOMSW_CMD_ESCPAGE
  63. #include "epson-escpage.h"
  64. #ifdef GCOMSW_CMD_ESCPAGE_S
  65. #include "epson-escpage-s.h"
  66. #endif
  67. #endif
  68. #include "epson-escpr-api.h"
  69. /*---------------------------- ESC/P-R Lib Global Variables --------------------------*/
  70. /*******************************************|********************************************/
  71. DECRALE_DMP_FILE
  72. /*** Extern Function */
  73. /*** -------------------------------------------------------------------------------*/
  74. EPS_USB_FUNC epsUsbFnc;
  75. EPS_NET_FUNC epsNetFnc;
  76. EPS_CMN_FUNC epsCmnFnc;
  77. /*** Print Job Structure */
  78. /*** -------------------------------------------------------------------------------*/
  79. EPS_PRINT_JOB printJob;
  80. EPS_INT32 tonerSave;
  81. EPS_INT32 back_type;
  82. EPS_INT32 lWidth;
  83. EPS_INT32 lHeight;
  84. EPS_INT32 areaWidth;
  85. EPS_INT32 areaHeight;
  86. /*------------------------- Module "Local Global" Variables --------------------------*/
  87. /*******************************************|********************************************/
  88. /*** internal stock */
  89. /*** -------------------------------------------------------------------------------*/
  90. static EPS_SUPPORTED_MEDIA g_supportedMedia; /* Supported Media */
  91. /*** Job function */
  92. /*** -------------------------------------------------------------------------------*/
  93. EPS_JOB_FUNCS jobFnc;
  94. /*-------------------------------- Local Definition ---------------------------------*/
  95. /*******************************************|********************************************/
  96. #ifdef EPS_LOG_MODULE_API
  97. #define EPS_LOG_MODULE EPS_LOG_MODULE_API
  98. #else
  99. #define EPS_LOG_MODULE 0
  100. #endif
  101. /*** Roop Count */
  102. /*** -------------------------------------------------------------------------------*/
  103. #define EPS_ROOP_NUM 40 /* Send the data for "EPS_ROOP_NUM" */
  104. /* times and get printer status */
  105. #define EPS_TIMEOUT_NUM 20 /* retry Send the data "EPS_TIMEOUT_NUM"*/
  106. #define EPS_TIMEOUT_SEC 1000 /* retry Send the data 1 sec */
  107. /*** Packet Size (4KB) */
  108. /*** -------------------------------------------------------------------------------*/
  109. #if LCOMSW_PACKET_4KB
  110. #define ESCPR_PACKET_SIZE_4KB 4090
  111. #endif
  112. /*** ESC/PR Attributes not settable by developer */
  113. /*** -------------------------------------------------------------------------------*/
  114. #define EPS_COMP_NON 0 /* Non compression */
  115. #define EPS_COMP_RLE 1 /* Runlength compression */
  116. #define EPS_END_PAGE 0 /* There is no next page */
  117. #define EPS_NEXT_PAGE 1 /* There is a next page */
  118. /*** RLE Compression States */
  119. /*** -------------------------------------------------------------------------------*/
  120. #define EPS_RLE_COMPRESS_NOT_DONE 0
  121. #define EPS_RLE_COMPRESS_DONE 1
  122. /*** Borderless Mode */
  123. /*** -------------------------------------------------------------------------------*/
  124. #define EPS_BORDER_3MM_MARGINE 0
  125. #define EPS_BORDER_CUSTOM 1
  126. #define EPS_BORDERLESS_NORMAL 2
  127. #define EPS_BORDERLESS_ZERO_MARGINE 3
  128. /*--------------------------------- ESC/P-R Commands ---------------------------------*/
  129. /*******************************************|********************************************/
  130. /*** ESC/P-R Command Length */
  131. /*** -------------------------------------------------------------------------------*/
  132. #define REMOTE_HEADER_LENGTH 5
  133. #define ESCPR_CLASS_LENGTH 2 /* ESC + CLASS */
  134. #define ESCPR_HEADER_LENGTH 10 /* ESC + CLASS + ParamLen + CmdName */
  135. #define ESCPR_PRINT_QUALITY_LENGTH 9
  136. #define ESCPR_SEND_DATA_LENGTH 7
  137. #define ESCPR_SEND_JPGDATA_LENGTH 2
  138. #define ESCPR_JPGHEAD_LENGTH (ESCPR_HEADER_LENGTH + ESCPR_SEND_JPGDATA_LENGTH)
  139. /*** Escape Commands for Initialize/Colse Printer */
  140. /*** -------------------------------------------------------------------------------*/
  141. static const EPS_UINT8 ExitPacketMode[]= {
  142. 0x00, 0x00, 0x00, 0x1B, 0x01, 0x40, 0x45, 0x4A, 0x4C, 0x20,
  143. 0x31, 0x32, 0x38, 0x34, 0x2E, 0x34, 0x0A, 0x40, 0x45, 0x4A,
  144. 0x4C, 0x20, 0x20, 0x20, 0x20, 0x20, 0x0A };
  145. static const EPS_UINT8 ESCPRMode[] = {
  146. /* 0x1B, 0x28, 0x52, 0x06, 0x00, 0x00, 0x45, 0x53, 0x43, 0x50, 0x52, };*/
  147. 0x1B, '(', 'R', 0x06, 0x00, 0x00, 'E', 'S', 'C', 'P', 'R' };
  148. static const EPS_UINT8 ESCPRModeJpg[] = {
  149. 0x1B, '(', 'R', 0x07, 0x00, 0x00, 'E', 'S', 'C', 'P', 'R', 'J' };
  150. static const EPS_UINT8 InitPrinter[] = {
  151. 0x1B, 0x40, };
  152. static const EPS_UINT8 EnterRemoteMode[] = {
  153. 0x1B, 0x28, 0x52, 0x08, 0x00, 0x00, 'R', 'E', 'M', 'O', 'T', 'E', '1', };
  154. static const EPS_UINT8 RemoteJS[] = {
  155. 'J', 'S', 0x04, 0x00, 0x00,
  156. 0x00, 0x00, 0x00 };
  157. static const EPS_UINT8 RemoteTI[] = {
  158. 'T', 'I', 0x08, 0x00, 0x00,
  159. 0x00, 0x00, /* YYYY */
  160. 0x00, /* MM */
  161. 0x00, /* DD */
  162. 0x00, /* hh */
  163. 0x00, /* mm */
  164. 0x00, /* ss */ };
  165. static const EPS_UINT8 RemoteHD[] = {
  166. 'H', 'D', 0x03, 0x00, 0x00,
  167. 0x03, 0xFF };
  168. static const EPS_UINT8 RemoteJH[] = {
  169. 'J', 'H', 0x0e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  170. 0x45, 0x53, 0x43, 0x50, 0x52, 0x4c, 0x69, 0x62 };
  171. static const EPS_UINT8 RemotePP[] = {
  172. 'P', 'P', 0x03, 0x00, 0x00, 0x00, 0x00 };
  173. static const EPS_UINT8 RemoteDP[] = {
  174. 'D', 'P', 0x02, 0x00, 0x00, 0x02 };
  175. static const EPS_UINT8 RemoteLD[] = {
  176. 'L', 'D', 0x00, 0x00, };
  177. static const EPS_UINT8 RemoteJE[] = {
  178. 'J', 'E', 0x01, 0x00, 0x00, };
  179. static const EPS_UINT8 ExitRemoteMode[] = {
  180. 0x1B, 0x00, 0x00, 0x00, };
  181. #ifdef GCOMSW_EF_MAINTE
  182. static const EPS_UINT8 RemoteCH[] = {
  183. 'C', 'H', 0x02, 0x00, 0x00, 0x00 };
  184. static const EPS_UINT8 RemoteNC[] = {
  185. 'N', 'C', 0x02, 0x00, 0x00, 0x00 };
  186. static const EPS_UINT8 RemoteVI[] = {
  187. 'V', 'I', 0x02, 0x00, 0x00, 0x00 };
  188. static const EPS_UINT8 DataCR[] = {0x0D };
  189. static const EPS_UINT8 DataLF[] = {0x0A };
  190. static const EPS_UINT8 DataFF[] = {0x0C };
  191. #endif
  192. /*** ESC/P-R Commands (Print Quality) */
  193. /*** -------------------------------------------------------------------------------*/
  194. static const EPS_UINT8 PrintQualityCmd[] = {
  195. 0x1B, 'q', 0x09, 0x00, 0x00, 0x00,
  196. 's', 'e', 't', 'q',
  197. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
  198. /*** ESC/P-R Commands (APF setting) */
  199. /*** -------------------------------------------------------------------------------*/
  200. static const EPS_UINT8 APFSettingCmd[] = {
  201. 0x1B, 'a', 0x04, 0x00, 0x00, 0x00,
  202. 's', 'e', 't', 'a',
  203. 0x00, 0x00, 0x00, 0x00};
  204. /*** ESC/P-R Commands (Print Job) */
  205. /*** -------------------------------------------------------------------------------*/
  206. static const EPS_UINT8 JobCmd[] = {
  207. 0x1B, 'j', 0x16, 0x00, 0x00, 0x00,
  208. 's', 'e', 't', 'j',
  209. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  210. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  211. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
  212. static const EPS_UINT8 JobCmdJpg[] = {
  213. 0x1B, 'j', 0x05, 0x00, 0x00, 0x00,
  214. 's', 'e', 't', 's',
  215. 0x00, 0x00, 0x00, 0x00, 0x00 };
  216. /*** ESC/P-R Command (Start Page) */
  217. /*** -------------------------------------------------------------------------------*/
  218. static const EPS_UINT8 StartPage[] = {
  219. 0x1B, 'p', 0x00, 0x00, 0x00, 0x00,
  220. 's', 't', 't', 'p' };
  221. /*** ESC/P-R Commands (Send Data) */
  222. /*** -------------------------------------------------------------------------------*/
  223. static const EPS_UINT8 SendDataCmd[2] = {0x1B, 'd' };
  224. static const EPS_UINT8 SendDataName[4] = {'d', 's', 'n', 'd' };
  225. static const EPS_UINT8 SendJpegDataName[4] = {'j', 's', 'n', 'd' };
  226. /*** ESC/P-R Command (End Page) */
  227. /*** -------------------------------------------------------------------------------*/
  228. static const EPS_UINT8 EndPage[] = {
  229. 0x1B, 'p', 0x01, 0x00, 0x00, 0x00,
  230. 'e', 'n', 'd', 'p',
  231. 0x00};
  232. /*** ESC/P-R Command (End Job) */
  233. /*** -------------------------------------------------------------------------------*/
  234. static const EPS_UINT8 EndJob[] = {
  235. 0x1B, 'j', 0x00, 0x00, 0x00, 0x00,
  236. 'e', 'n', 'd', 'j' };
  237. /*------------------------------- Definition of Macro --------------------------------*/
  238. /*******************************************|********************************************/
  239. /*--------------------------- Data Structure Declarations ---------------------------*/
  240. /*******************************************|********************************************/
  241. /*** Generic Image Object */
  242. /*** -------------------------------------------------------------------------------*/
  243. typedef struct _tagEPS_IMAGE_ {
  244. const EPS_UINT8* data; /* Pointer to image/raster data */
  245. EPS_RECT rect; /* Rect define position of image */
  246. EPS_UINT32 bytesPerLine; /* Bytes-Per-Pixel for image/raster */
  247. } EPS_IMAGE;
  248. /*------------------------------ Local Global Variables ------------------------------*/
  249. /*******************************************|********************************************/
  250. /*** ESC/P-R LIB Status State */
  251. /*** -------------------------------------------------------------------------------*/
  252. EPS_INT32 libStatus; /* Library (epsInitDriver) status */
  253. /*** Status counter */
  254. /*** -------------------------------------------------------------------------------*/
  255. static EPS_INT32 gStatusCount; /* Variable for register the number of getting */
  256. /* printer status */
  257. /*** Buffer for Print Band */
  258. /*** -------------------------------------------------------------------------------*/
  259. EPS_UINT32 sendDataBufSize = 0;
  260. EPS_UINT8* sendDataBuf; /* buffer of SendCommand(save) input */
  261. EPS_UINT32 tmpLineBufSize;
  262. EPS_UINT8* tmpLineBuf;
  263. /*-------------------------------- Local Functions ----------------------------------*/
  264. /*******************************************|********************************************/
  265. static EPS_ERR_CODE MonitorStatus (EPS_STATUS_INFO * );
  266. static EPS_ERR_CODE SendLeftovers (void );
  267. static EPS_ERR_CODE SendBlankBand (void );
  268. EPS_ERR_CODE SetupJobAttrib (const EPS_JOB_ATTRIB* );
  269. static EPS_ERR_CODE SetupRGBAttrib (void );
  270. static EPS_ERR_CODE SetupJPGAttrib (void );
  271. EPS_ERR_CODE SendStartJob (EPS_BOOL );
  272. EPS_ERR_CODE SendEndJob (EPS_BOOL );
  273. EPS_ERR_CODE PrintBand (const EPS_UINT8*, EPS_UINT32, EPS_UINT32* );
  274. static EPS_ERR_CODE PrintChunk (const EPS_UINT8*, EPS_UINT32* );
  275. static void AdjustBasePoint (void );
  276. static EPS_ERR_CODE PrintLine (EPS_IMAGE* );
  277. static EPS_ERR_CODE SendLine (const EPS_BANDBMP*, EPS_RECT* );
  278. static EPS_UINT16 RunLengthEncode (const EPS_UINT8*, EPS_UINT8*, EPS_UINT16, EPS_UINT8, EPS_UINT8*);
  279. static void MakeRemoteTICmd (EPS_UINT8* );
  280. static void MakeQualityCmd (EPS_UINT8* );
  281. static void MakeAPFCmd (EPS_UINT8* );
  282. static void MakeJobCmd (EPS_UINT8* );
  283. static EPS_ERR_CODE AddCmdBuff (EPS_UINT8 **, EPS_UINT8 **, EPS_UINT32 *,
  284. const EPS_UINT8 *, EPS_UINT32 );
  285. static EPS_ERR_CODE CreateMediaInfo (EPS_PRINTER_INN*, EPS_UINT8*, EPS_INT32 );
  286. static EPS_ERR_CODE DuplSupportedMedia (EPS_PRINTER_INN*, EPS_SUPPORTED_MEDIA* );
  287. static EPS_ERR_CODE GetPaperSource (EPS_PRINTER_INN* );
  288. static EPS_ERR_CODE GetJpgMax (EPS_PRINTER_INN* );
  289. static void ClearSupportedMedia (void );
  290. /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%|%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
  291. /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%|%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
  292. /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%|%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
  293. /*%%%%%%%%%%%%%%%%%%%% %%%%%%%%%%%%%%%%%%%%%*/
  294. /*-------------------- ESC/P-R Library API ---------------------*/
  295. /*%%%%%%%%%%%%%%%%%%%% %%%%%%%%%%%%%%%%%%%%%*/
  296. /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%|%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
  297. /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%|%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
  298. /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%|%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
  299. /*******************************************|********************************************/
  300. /* */
  301. /* Function name: epsInitDriver() */
  302. /* */
  303. /* Arguments */
  304. /* --------- */
  305. /* Name: Type: Description: */
  306. /* commMode EPS_INT8 I: Communication Mode */
  307. /* (Bi-Directional or Uni-Directional) */
  308. /* usbFuncPtrs EPS_USB_FUNC* I: Data structure containing function pointers to */
  309. /* external USB I/O functions. */
  310. /* netFuncPtrs EPS_NET_FUNC* I: Data structure containing function pointers to */
  311. /* external network socket I/O functions. */
  312. /* cmnFuncPtrs EPS_CMN_FUNC* I: Data structure containing function pointers to */
  313. /* external memory management functions. */
  314. /* */
  315. /* Return value: */
  316. /* << Normal >> */
  317. /* EPS_ERR_NONE - Success */
  318. /* << Error >> */
  319. /* EPS_ERR_LIB_INTIALIZED - Lib already initialized */
  320. /* EPS_ERR_INV_ARG_COMMMODE - Invalid argument "commMode" */
  321. /* EPS_ERR_INV_FNCP_NULL - Invalid function pointer structure */
  322. /* EPS_ERR_INV_FNCP_FINDCALLBACK - Invalid function pointer "findCallback" */
  323. /* EPS_ERR_INV_FNCP_MEMALLOC - Invalid function pointer "memAlloc" */
  324. /* EPS_ERR_INV_FNCP_MEMFREE - Invalid function pointer "memFree" */
  325. /* EPS_ERR_INV_FNCP_SLEEP - Invalid function pointer "sleep" */
  326. /* EPS_ERR_INV_FNCP_OPENPORTAL - Invalid function pointer "openPortal" */
  327. /* EPS_ERR_INV_FNCP_CLOSEPORTAL - Invalid function pointer "closePortal" */
  328. /* EPS_ERR_INV_FNCP_READPORTAL - Invalid function pointer "readPortal" */
  329. /* EPS_ERR_INV_FNCP_WRITEPORTAL - Invalid function pointer "writePortal" */
  330. /* EPS_ERR_INV_FNCP_FINDFIRST - Invalid function pointer "findFirst" */
  331. /* EPS_ERR_INV_FNCP_FINDNEXT - Invalid function pointer "findNext" */
  332. /* EPS_ERR_INV_FNCP_FINDCLOSE - Invalid function pointer "findClose" */
  333. /* EPS_ERR_INV_FNCP_NETSOCKET - Invalid function pointer "socket" */
  334. /* EPS_ERR_INV_FNCP_NETCLOSE - Invalid function pointer "close" */
  335. /* EPS_ERR_INV_FNCP_NETCONNECT - Invalid function pointer "connect" */
  336. /* EPS_ERR_INV_FNCP_NETSHUTDOWN - Invalid function pointer "shutdown" */
  337. /* EPS_ERR_INV_FNCP_NETBIND - Invalid function pointer "bind" */
  338. /* EPS_ERR_INV_FNCP_NETLISTEN - Invalid function pointer "listen" */
  339. /* EPS_ERR_INV_FNCP_NETACCEPT - Invalid function pointer "accept" */
  340. /* EPS_ERR_INV_FNCP_NETSEND - Invalid function pointer "send" */
  341. /* EPS_ERR_INV_FNCP_NETSENDTO - Invalid function pointer "sendTo" */
  342. /* EPS_ERR_INV_FNCP_NETRECEIVE - Invalid function pointer "receive" */
  343. /* EPS_ERR_INV_FNCP_NETRECEIVEFROM - Invalid function pointer "receiveFrom" */
  344. /* EPS_ERR_INV_FNCP_NETGETSOCKNAME - Invalid function pointer "getsockname" */
  345. /* EPS_ERR_INV_FNCP_NETSETBROADCAST - Invalid function pointer "setBroadcast" */
  346. /* EPS_ERR_MEMORY_ALLOCATION - Failed to allocate memory */
  347. /* */
  348. /* Description: */
  349. /* Registers the external functions with the device driver. */
  350. /* */
  351. /*******************************************|********************************************/
  352. EPS_ERR_CODE epsInitDriver (
  353. EPS_INT32 commMode,
  354. const EPS_USB_FUNC* usbFuncPtrs,
  355. const EPS_NET_FUNC* netFuncPtrs,
  356. const EPS_CMN_FUNC* cmnFuncPtrs
  357. ){
  358. /*** Declare Variable Local to Routine */
  359. EPS_ERR_CODE retStatus = EPS_ERR_NONE; /* Return status of internal calls */
  360. EPS_LOG_FUNCIN
  361. #ifdef GCOMSW_EPSON_SLEEP
  362. EPS_INT32 idx, tdx; /* General loop/index varaible */
  363. EPS_INT32 sleepTime;
  364. struct timeb sleepS, sleepE;
  365. #endif /* GCOMSW_EPSON_SLEEP */
  366. /*** Has a Lib been initialized */
  367. if (libStatus != EPS_STATUS_NOT_INITIALIZED) {
  368. EPS_RETURN( EPS_ERR_LIB_INTIALIZED );
  369. }
  370. /*** Validate input parameters */
  371. if( EPS_ERR_NONE != (retStatus = prtFunctionCheck(commMode, usbFuncPtrs, netFuncPtrs, cmnFuncPtrs)) ){
  372. EPS_RETURN( retStatus );
  373. }
  374. /*** Register Functions */
  375. if( commMode & EPS_PROTOCOL_USB ){
  376. memcpy((void*)(&epsUsbFnc), (void*)usbFuncPtrs, sizeof(EPS_USB_FUNC));
  377. } else{
  378. memset((void*)(&epsUsbFnc), 0, sizeof(EPS_USB_FUNC));
  379. }
  380. if( commMode & EPS_PROTOCOL_NET ){
  381. memcpy((void*)(&epsNetFnc), (void*)netFuncPtrs, sizeof(EPS_NET_FUNC));
  382. } else{
  383. memset((void*)(&epsNetFnc), 0, sizeof(EPS_NET_FUNC));
  384. }
  385. memcpy((void*)(&epsCmnFnc), (void*)cmnFuncPtrs, sizeof(EPS_CMN_FUNC));
  386. #ifdef GCOMSW_EPSON_SLEEP
  387. if (epsCmnFnc.sleep == NULL)
  388. epsCmnFnc.sleep = serSleep;
  389. #endif /* GCOMSW_EPSON_SLEEP */
  390. /*** Initialize ESC/P-R Lib and Local Global Variables */
  391. gStatusCount = 0;
  392. memset(&printJob, 0, sizeof(EPS_PRINT_JOB));
  393. printJob.jobStatus = EPS_STATUS_NOT_INITIALIZED;
  394. printJob.pageStatus = EPS_STATUS_NOT_INITIALIZED;
  395. printJob.findStatus = EPS_STATUS_NOT_INITIALIZED;
  396. printJob.printer = NULL;
  397. printJob.bComm = TRUE;
  398. printJob.platform = 0x04; /* '0x04 = linux' is default */
  399. libStatus = EPS_STATUS_NOT_INITIALIZED;
  400. sendDataBufSize = 0;
  401. sendDataBuf = NULL;
  402. tmpLineBufSize = 0;
  403. tmpLineBuf = NULL;
  404. /*** Initialize continue buffer */
  405. printJob.contData.sendData = NULL;
  406. printJob.contData.sendDataSize = 0;
  407. /* DEL printJob.additional = EPS_ADDDATA_NONE;
  408. printJob.qrcode.bits = NULL;
  409. printJob.qrcode.cellNum = 0;
  410. printJob.qrcode.dpc = 0; */
  411. obsClear();
  412. /*** Set "Endian-ness" for the current cpu */
  413. memInspectEndian();
  414. /*** Set Communication Mode */
  415. printJob.commMode = commMode;
  416. /*** Change ESC/P-R Lib Status */
  417. libStatus = EPS_STATUS_INITIALIZED;
  418. /*** Return to Caller */
  419. EPS_RETURN( EPS_ERR_NONE );
  420. }
  421. /*******************************************|********************************************/
  422. /* */
  423. /* Function name: epsReleaseDriver() */
  424. /* */
  425. /* Arguments */
  426. /* --------- */
  427. /* Name: Type: Description: */
  428. /* N/A void */
  429. /* */
  430. /* Return value: */
  431. /* << Normal >> */
  432. /* EPS_ERR_NONE - Success */
  433. /* << Error >> */
  434. /* EPS_ERR_LIB_NOT_INITIALIZED - ESC/P-R Lib is NOT initialized */
  435. /* */
  436. /* Description: */
  437. /* Creanup Driver. */
  438. /* */
  439. /*******************************************|********************************************/
  440. EPS_ERR_CODE epsReleaseDriver (
  441. void
  442. ){
  443. EPS_LOG_FUNCIN;
  444. /*** Has a Lib been initialized */
  445. if (libStatus == EPS_STATUS_NOT_INITIALIZED) {
  446. EPS_RETURN( EPS_ERR_LIB_NOT_INITIALIZED );
  447. }
  448. epsEndJob();
  449. /*** Clear inside supported media list */
  450. ClearSupportedMedia();
  451. /*** Clear inside printer list */
  452. prtClearPrinterList();
  453. printJob.printer = NULL;
  454. obsClear();
  455. /*** Clear inside additional data buffer */
  456. /* DEL EPS_SAFE_RELEASE( printJob.qrcode.bits ) */
  457. /*** Change ESC/P-R Lib Status */
  458. libStatus = EPS_STATUS_NOT_INITIALIZED;
  459. EPS_RETURN( EPS_ERR_NONE );
  460. }
  461. /*******************************************|********************************************/
  462. /* */
  463. /* Function name: epsFindPrinter() */
  464. /* */
  465. /* Arguments */
  466. /* --------- */
  467. /* Name: Type: Description: */
  468. /* protocol EPS_INT32 I: Protocol to be retrieved */
  469. /* timeout EPS_UINT32 I: Network pirinter find timeout */
  470. /* */
  471. /* Return value: */
  472. /* EPS_ERR_NONE - Success (printer found) */
  473. /* EPS_ERR_LIB_NOT_INITIALIZED - not initialized */
  474. /* EPS_ERR_JOB_NOT_CLOSED - JOB is NOT finished */
  475. /* EPS_ERR_PRINTER_NOT_FOUND - printer not found */
  476. /* EPS_ERR_MEMORY_ALLOCATION - Fail to memory allocation */
  477. /* EPS_ERR_COMM_ERROR - Communication Error */
  478. /* */
  479. /* Description: */
  480. /* find USB and Network printer. */
  481. /* */
  482. /*******************************************|********************************************/
  483. EPS_ERR_CODE epsFindPrinter (
  484. EPS_INT32 protocol,
  485. EPS_UINT32 timeout
  486. ){
  487. /*** Declare Variable Local to Routine */
  488. EPS_ERR_CODE retStatus = EPS_ERR_NONE; /* Return status of internal calls */
  489. EPS_LOG_FUNCIN;
  490. /*** Has a Lib been initialized */
  491. if (libStatus != EPS_STATUS_INITIALIZED) {
  492. EPS_RETURN( EPS_ERR_LIB_NOT_INITIALIZED );
  493. }
  494. /*** Is a Job already open */
  495. if (printJob.jobStatus != EPS_STATUS_NOT_INITIALIZED) {
  496. EPS_RETURN( EPS_ERR_JOB_NOT_CLOSED );
  497. }
  498. /*** Clear inside printer list */
  499. prtClearPrinterList();
  500. printJob.printer = NULL;
  501. obsClear();
  502. /*** find */
  503. printJob.findStatus = EPS_STATUS_INITIALIZED;
  504. retStatus = prtFindPrinter( protocol, timeout );
  505. printJob.findStatus = EPS_STATUS_NOT_INITIALIZED;
  506. EPS_RETURN( retStatus );
  507. }
  508. /*******************************************|********************************************/
  509. /* */
  510. /* Function name: epsProbePrinter() */
  511. /* */
  512. /* Arguments */
  513. /* --------- */
  514. /* Name: Type: Description: */
  515. /* probeParam EPS_PROBE* I: prober parameter structure */
  516. /* */
  517. /* Return value: */
  518. /* EPS_ERR_NONE - Success (printer found) */
  519. /* EPS_ERR_LIB_NOT_INITIALIZED - not initialized */
  520. /* EPS_ERR_JOB_NOT_CLOSED - JOB is NOT finished */
  521. /* EPS_ERR_PRINTER_NOT_FOUND - printer not found */
  522. /* EPS_ERR_INV_ARG_PROBEINFO - Invalid argument probe infomation */
  523. /* EPS_ERR_INV_ARG_UNK_METHOD - Invalid value "method" */
  524. /* EPS_ERR_INV_ARG_PRINTER_ID - Invalid format "identify" */
  525. /* EPS_ERR_INV_ARG_PRINTER_ADDR - Invalid format "address" */
  526. /* EPS_ERR_PROTOCOL_NOT_SUPPORTED - Unsupported function Error */
  527. /* EPS_ERR_MEMORY_ALLOCATION - Fail to memory allocation */
  528. /* EPS_ERR_PRINTER_NOT_USEFUL - received but not usefl */
  529. /* */
  530. /* Description: */
  531. /* printer specified by printerID or IP Address is retrieved. */
  532. /* */
  533. /*******************************************|********************************************/
  534. EPS_ERR_CODE epsProbePrinter(
  535. const EPS_PROBE* probeParam
  536. ){
  537. /*** Declare Variable Local to Routine */
  538. EPS_ERR_CODE retStatus = EPS_ERR_NONE; /* Return status of internal calls */
  539. EPS_LOG_FUNCIN;
  540. /*** Validate input parameters */
  541. if (NULL == probeParam) {
  542. EPS_RETURN( EPS_ERR_INV_ARG_PROBEINFO );
  543. }
  544. /*** Has a Lib been initialized */
  545. if (libStatus != EPS_STATUS_INITIALIZED) {
  546. EPS_RETURN( EPS_ERR_LIB_NOT_INITIALIZED );
  547. }
  548. /*** Is a Job already open */
  549. if (printJob.jobStatus != EPS_STATUS_NOT_INITIALIZED) {
  550. EPS_RETURN( EPS_ERR_JOB_NOT_CLOSED );
  551. }
  552. /*** Clear inside printer list */
  553. prtClearPrinterList();
  554. printJob.printer = NULL;
  555. obsClear();
  556. /*** probe */
  557. printJob.findStatus = EPS_STATUS_INITIALIZED;
  558. switch( probeParam->method ){
  559. case EPS_PRB_BYID:
  560. retStatus = prtProbePrinterByID( probeParam );
  561. break;
  562. case EPS_PRB_BYADDR:
  563. retStatus = prtProbePrinterByAddr( probeParam );
  564. break;
  565. default:
  566. retStatus = EPS_ERR_INV_ARG_UNK_METHOD;
  567. }
  568. printJob.findStatus = EPS_STATUS_NOT_INITIALIZED;
  569. EPS_RETURN( retStatus );
  570. }
  571. /*******************************************|********************************************/
  572. /* */
  573. /* Function name: epsCancelFindPrinter() */
  574. /* */
  575. /* Arguments */
  576. /* --------- */
  577. /* Name: Type: Description: */
  578. /* N/A void */
  579. /* */
  580. /* Return value: */
  581. /* EPS_ERR_NONE - Success */
  582. /* EPS_ERR_LIB_NOT_INITIALIZED - not initialized */
  583. /* EPS_ERR_FIND_NOT_STARTED - find not started */
  584. /* EPS_ERR_INVALID_CALL - invalid called */
  585. /* */
  586. /* Description: */
  587. /* Cancel the epsFindPrinter(), epsProbePrinter() process. */
  588. /* */
  589. /*******************************************|********************************************/
  590. EPS_ERR_CODE epsCancelFindPrinter (
  591. void
  592. ){
  593. EPS_LOG_FUNCIN;
  594. /*** Has a Lib been initialized */
  595. if (libStatus != EPS_STATUS_INITIALIZED) {
  596. EPS_RETURN( EPS_ERR_LIB_NOT_INITIALIZED );
  597. }
  598. /*** Has a Find been started */
  599. if (printJob.findStatus != EPS_STATUS_INITIALIZED) {
  600. EPS_RETURN( EPS_ERR_FIND_NOT_STARTED );
  601. }
  602. EPS_RETURN( prtCancelFindPrinter() );
  603. }
  604. /*******************************************|********************************************/
  605. /* */
  606. /* Function name: epsSetPrinter() */
  607. /* */
  608. /* Arguments */
  609. /* --------- */
  610. /* Name: Type: Description: */
  611. /* printer EPS_PRINTER* O: Pointer to a target printer */
  612. /* */
  613. /* Return value: */
  614. /* EPS_ERR_NONE - Success */
  615. /* EPS_ERR_LIB_NOT_INITIALIZED - ESC/P-R Lib is NOT initialized */
  616. /* EPS_ERR_JOB_NOT_CLOSED - JOB is NOT finished */
  617. /* EPS_ERR_INV_ARG_PRINTER - Illegal printer was specified */
  618. /* EPS_ERR_INV_ARG_COMMMODE - Invalid argument "printer.protocol" */
  619. /* EPS_ERR_MEMORY_ALLOCATION - Fail to memory allocation */
  620. /* EPS_ERR_INV_ARG_PRINTER_ADDR - Invalid format " printer.location" */
  621. /* EPS_ERR_INV_PRINT_LANGUAGE - Invalid argument "printer.language" */
  622. /* */
  623. /* Description: */
  624. /* Selects a printer to use from detected printers. */
  625. /* Register a user specified printer. */
  626. /* */
  627. /*******************************************|********************************************/
  628. EPS_ERR_CODE epsSetPrinter (
  629. const EPS_PRINTER* printer
  630. ){
  631. /*** Declare Variable Local to Routine */
  632. EPS_ERR_CODE ret = EPS_ERR_NONE; /* Return status of internal calls */
  633. EPS_PRINTER_INN* innerPrinter = NULL;
  634. EPS_LOG_FUNCIN;
  635. /*** Has a Lib been initialized */
  636. if (libStatus != EPS_STATUS_INITIALIZED) {
  637. EPS_RETURN( EPS_ERR_LIB_NOT_INITIALIZED );
  638. }
  639. /*** Is a Job already open */
  640. if (printJob.jobStatus != EPS_STATUS_NOT_INITIALIZED) {
  641. EPS_RETURN( EPS_ERR_JOB_NOT_CLOSED );
  642. }
  643. /*** Validate input parameters */
  644. if (NULL == printer){
  645. EPS_RETURN( EPS_ERR_INV_ARG_PRINTER );
  646. }
  647. /*** convert internal structure */
  648. innerPrinter = prtGetInnerPrinter(printer);
  649. if( NULL == innerPrinter ){
  650. ret = prtAddUsrPrinter(printer, &innerPrinter);
  651. if( EPS_ERR_NONE != ret ){
  652. EPS_RETURN( ret );
  653. }
  654. }
  655. /*** Set Job target printer */
  656. printJob.printer = innerPrinter;
  657. printJob.bComm = TRUE;
  658. obsSetPrinter(innerPrinter);
  659. prtSetupJobFunctions(printJob.printer, &jobFnc); /* Set Job functions */
  660. EPS_RETURN( EPS_ERR_NONE );
  661. }
  662. /*******************************************|********************************************/
  663. /* */
  664. /* Function name: epsStartJob() */
  665. /* */
  666. /* Arguments */
  667. /* --------- */
  668. /* Name: Type: Description: */
  669. /* jobAttr const EPS_JOB_ATTRIB* I: Print Job Attribute */
  670. /* */
  671. /* Return value: */
  672. /* << Normal >> */
  673. /* EPS_ERR_NONE - Success */
  674. /* << Error >> */
  675. /* EPS_ERR_INV_ARG_JOB_ATTRIB - Invalid argument "jobAttr" */
  676. /* EPS_ERR_INV_COLOR_PLANE - Invalid Color Plane */
  677. /* EPS_ERR_INV_PALETTE_SIZE - Invalid Palette Size */
  678. /* EPS_ERR_INV_PALETTE_DATA - Invalid Palette Data */
  679. /* EPS_ERR_INV_MEDIA_SIZE - Invalid Media Size */
  680. /* EPS_ERR_INV_MEDIA_TYPE - Invalid Media Type */
  681. /* EPS_ERR_INV_BORDER_MODE - Invalid Border Mode */
  682. /* EPS_ERR_INV_PRINT_QUALITY - Invalid Print Quality */
  683. /* EPS_ERR_INV_COLOR_MODE - Invalid Color Mode */
  684. /* EPS_ERR_INV_INPUT_RESOLUTION - Invalid Input Resolution */
  685. /* EPS_ERR_INV_PRINT_DIRECTION - Invalid Print Direction */
  686. /* EPS_ERR_INV_BRIGHTNESS - Invalid Brightness */
  687. /* EPS_ERR_INV_CONTRAST - Invalid Contrast */
  688. /* EPS_ERR_INV_SATURATION - Invalid Saturation */
  689. /* EPS_ERR_INV_TOP_MARGIN - Invalid Top Magirn */
  690. /* EPS_ERR_INV_LEFT_MARGIN - Invalid Left Margin */
  691. /* EPS_ERR_INV_BOTTOM_MARGIN - Invalid Bottom Margin */
  692. /* EPS_ERR_INV_RIGHT_MARGIN - Invalid Right Margin */
  693. /* EPS_ERR_MARGIN_OVER_PRINTABLE_WIDTH - Invalid Magin Setting (Width) */
  694. /* EPS_ERR_MARGIN_OVER_PRINTABLE_HEIGHT - Invalid Magin Setting (Height) */
  695. /* EPS_ERR_INV_PAPER_SOURCE - Invalid Paper source */
  696. /* EPS_ERR_INV_DUPLEX - Invalid duplex */
  697. /* EPS_ERR_INV_FEED_DIRECTION - Invalid feed direction */
  698. /* EPS_ERR_LANGUAGE_NOT_SUPPORTED - Unsupported function Error (language) */
  699. /* */
  700. /* EPS_ERR_INV_APF_FLT - Invalid APF Filter */
  701. /* EPS_ERR_INV_APF_ACT - Invalid APF Scene */
  702. /* EPS_ERR_INV_APF_SHP - Invalid APF Sharpness */
  703. /* EPS_ERR_INV_APF_RDE - Invalid APF Red Eye */
  704. /* */
  705. /* (Uni/Bi-Directional) */
  706. /* EPS_ERR_LIB_NOT_INITIALIZED - ESC/P-R Lib is NOT initialized */
  707. /* EPS_ERR_JOB_NOT_CLOSED - JOB is NOT finished */
  708. /* EPS_ERR_PRINTER_NOT_SET - Target printer is not specified */
  709. /* EPS_ERR_OPR_FAIL - Internal Error */
  710. /* EPS_ERR_MEMORY_ALLOCATION - Fail to memory allocation */
  711. /* (Bi-Directional Only) */
  712. /* EPS_ERR_PRINTER_ERR_OCCUR - Printer Error happened */
  713. /* */
  714. /* Description: */
  715. /* Creates a new print job. */
  716. /* */
  717. /*******************************************|********************************************/
  718. EPS_ERR_CODE epsStartJob (
  719. const EPS_JOB_ATTRIB* jobAttr /* Print Attributes for this Job */
  720. ){
  721. /*** Declare Variable Local to Routine */
  722. EPS_ERR_CODE retStatus = EPS_ERR_NONE; /* Return status of internal calls */
  723. EPS_STATUS_INFO stInfo;
  724. EPS_LOG_FUNCIN;
  725. /*** Has a Lib been initialized */
  726. if (libStatus != EPS_STATUS_INITIALIZED) {
  727. EPS_RETURN( EPS_ERR_LIB_NOT_INITIALIZED );
  728. }
  729. /*** Is a Job already open */
  730. if (printJob.jobStatus != EPS_STATUS_NOT_INITIALIZED) {
  731. EPS_RETURN( EPS_ERR_JOB_NOT_CLOSED );
  732. }
  733. /*** Has a target printer specified */
  734. if(NULL == printJob.printer){
  735. EPS_RETURN( EPS_ERR_PRINTER_NOT_SET );
  736. }
  737. if(EPS_CP_JPEG == jobAttr->colorPlane ){
  738. if( !(EPS_SPF_JPGPRINT & printJob.printer->supportFunc) ){
  739. EPS_RETURN( EPS_ERR_INV_COLOR_PLANE );
  740. }
  741. }
  742. /*======================================================================================*/
  743. /*** Setup Page Attribute */
  744. /*======================================================================================*/
  745. if (jobAttr == NULL){
  746. EPS_RETURN( EPS_ERR_INV_ARG_JOB_ATTRIB )
  747. }
  748. if(EPS_LANG_ESCPR == printJob.printer->language ){
  749. /*** ESC/P-R ***/
  750. retStatus = SetupJobAttrib(jobAttr);
  751. } else{
  752. /*** ESC/Page ***/
  753. #ifdef GCOMSW_CMD_ESCPAGE
  754. retStatus = pageInitJob(jobAttr);
  755. #else
  756. retStatus = EPS_ERR_LANGUAGE_NOT_SUPPORTED;
  757. #endif
  758. }
  759. if (EPS_ERR_NONE != retStatus){
  760. EPS_RETURN( retStatus );
  761. }
  762. /*** Change Job Status */
  763. printJob.jobStatus = EPS_STATUS_INITIALIZED;
  764. obsSetColorPlane( printJob.attr.colorPlane );
  765. /*======================================================================================*/
  766. /*** Check the printer status. (before session open) */
  767. /*======================================================================================*/
  768. memset(&stInfo, 0, sizeof(stInfo));
  769. if( EPS_IS_BI_PROTOCOL(printJob.printer->protocol) ){
  770. retStatus = PRT_INVOKE_JOBFNC(jobFnc.GetStatus, (&stInfo, NULL, NULL));
  771. if( EPS_ERR_NONE != retStatus ){
  772. goto epsStartJob_END;
  773. } else if(EPS_ST_IDLE != stInfo.nState){
  774. retStatus = EPS_ERR_PRINTER_ERR_OCCUR;
  775. goto epsStartJob_END;
  776. } else if( EPS_PRNWARN_DISABLE_CLEAN & stInfo.nWarn &&
  777. EPS_MNT_CLEANING == printJob.attr.cmdType ){
  778. retStatus = EPS_ERR_PRINTER_ERR_OCCUR;
  779. goto epsStartJob_END;
  780. }
  781. /* ignore color-ink-end warning
  782. if color print done, will occuer EPS_PRNERR_INKOUT(0x47).
  783. else if( EPS_PRNWARN_COLOR_INKOUT & stInfo.nWarn ){
  784. if( !((EPS_CP_FULLCOLOR == printJob.attr.colorPlane || EPS_CP_256COLOR == printJob.attr.colorPlane)
  785. && EPS_CM_MONOCHROME == printJob.attr.colorMode
  786. && EPS_MTID_PLAIN == printJob.attr.mediaTypeIdx
  787. && (EPS_MLID_BORDERS == printJob.attr.printLayout || EPS_MLID_CUSTOM == printJob.attr.printLayout)) ){
  788. color printing is impossible. (Mono/Plain/Border is possible)
  789. retStatus = EPS_ERR_PRINTER_ERR_OCCUR;
  790. goto epsStartJob_END;
  791. }
  792. }*/
  793. }
  794. /*======================================================================================*/
  795. /*** Prepar RGB buffer */
  796. /*======================================================================================*/
  797. if(EPS_LANG_ESCPR == printJob.printer->language ){
  798. /*** ESC/P-R ***/
  799. if( EPS_CP_FULLCOLOR == printJob.attr.colorPlane ||
  800. EPS_CP_256COLOR == printJob.attr.colorPlane){
  801. /*** Allocate buffer for "Send Data" command */
  802. EPS_SAFE_RELEASE(sendDataBuf );
  803. EPS_SAFE_RELEASE(tmpLineBuf );
  804. sendDataBufSize = (EPS_INT32)(ESCPR_HEADER_LENGTH +
  805. ESCPR_SEND_DATA_LENGTH +
  806. (printJob.printableAreaWidth * printJob.bpp));
  807. sendDataBuf = (EPS_UINT8*)EPS_ALLOC(sendDataBufSize);
  808. if(sendDataBuf == NULL){
  809. sendDataBufSize = 0;
  810. EPS_RETURN( EPS_ERR_MEMORY_ALLOCATION );
  811. }
  812. memset(sendDataBuf, 0xFF, (EPS_UINT32)sendDataBufSize);
  813. /*** Allocate buffer for RLE complession */
  814. tmpLineBufSize = (EPS_INT32)(printJob.printableAreaWidth * printJob.bpp) + 256; /* 256 is temp buffer */
  815. tmpLineBuf = (EPS_UINT8*)EPS_ALLOC(tmpLineBufSize);
  816. if(tmpLineBuf == NULL){
  817. tmpLineBufSize = 0;
  818. EPS_RETURN( EPS_ERR_MEMORY_ALLOCATION );
  819. }
  820. memset(tmpLineBuf, 0xFF, (EPS_UINT32)tmpLineBufSize);
  821. } else if(EPS_CP_JPEG == printJob.attr.colorPlane){
  822. if(0 == printJob.printer->JpgMax){
  823. /*** get jpeg limit */
  824. retStatus = GetJpgMax(printJob.printer);
  825. if (retStatus != EPS_ERR_NONE) {
  826. goto epsStartJob_END;
  827. }
  828. }
  829. }
  830. } else{
  831. #ifdef GCOMSW_CMD_ESCPAGE
  832. /*** ESC/Page ***/
  833. retStatus = pageAllocBuffer();
  834. #else
  835. retStatus = EPS_ERR_LANGUAGE_NOT_SUPPORTED;
  836. #endif
  837. if (retStatus != EPS_ERR_NONE) {
  838. goto epsStartJob_END;
  839. }
  840. }
  841. /*======================================================================================*/
  842. /*** protocol depend StartJob */
  843. /*======================================================================================*/
  844. retStatus = jobFnc.StartJob();
  845. if (retStatus != EPS_ERR_NONE) {
  846. goto epsStartJob_END;
  847. }
  848. /*======================================================================================*/
  849. /*** Init flags */
  850. /*======================================================================================*/
  851. printJob.transmittable = TRUE;
  852. printJob.resetSent = EPS_RESET_NOT_SENT;
  853. printJob.resetReq = FALSE;
  854. printJob.bComm = TRUE;
  855. printJob.sendJS = FALSE;
  856. printJob.pageCount = 0;
  857. gStatusCount = 0;
  858. printJob.contData.savePoint = EPS_SAVEP_NONE;
  859. printJob.contData.saveStep = 0;
  860. printJob.contData.sendData = NULL;
  861. printJob.contData.sendDataSize = 0;
  862. /*======================================================================================*/
  863. /*** Send StartJob Commands */
  864. /*======================================================================================*/
  865. #ifdef LCOMSW_CMDDMP
  866. {
  867. EPS_INT8 fname[256];
  868. sprintf(fname, "%s-%s-%s.prn", (printJob.printer->language == EPS_LANG_ESCPR)?"escpr":"page",
  869. (printJob.attr.colorMode == EPS_CM_COLOR)?"color":"mono",
  870. (printJob.attr.colorPlane == EPS_CP_FULLCOLOR)?"24":"8");
  871. EPS_DF_OPEN(fname)
  872. }
  873. #endif
  874. if( EPS_CP_PRINTCMD != printJob.attr.colorPlane ){
  875. if(EPS_LANG_ESCPR == printJob.printer->language ){
  876. /*** ESC/P-R ***/
  877. if(EPS_PM_JOB != obsGetPageMode()){
  878. retStatus = SendStartJob(FALSE);
  879. }
  880. } else{
  881. /*** ESC/Page ***/
  882. #ifdef GCOMSW_CMD_ESCPAGE
  883. retStatus = pageStartJob();
  884. #else
  885. retStatus = EPS_ERR_LANGUAGE_NOT_SUPPORTED;
  886. #endif
  887. }
  888. if(EPS_ERR_NONE != retStatus){
  889. goto epsStartJob_END;
  890. }
  891. } else{
  892. printJob.pageStatus = EPS_STATUS_INITIALIZED;
  893. }
  894. printJob.jobStatus = EPS_STATUS_ESTABLISHED;
  895. epsStartJob_END:
  896. /*** Return to Caller */
  897. if (EPS_ERR_NOT_OPEN_IO == retStatus || EPS_ERR_COMM_ERROR == retStatus) {
  898. printJob.bComm = FALSE;
  899. retStatus = EPS_ERR_PRINTER_ERR_OCCUR;
  900. }
  901. EPS_RETURN( retStatus );
  902. }
  903. /*******************************************|********************************************/
  904. /* */
  905. /* Function name: epsStartPage() */
  906. /* */
  907. /* Arguments */
  908. /* --------- */
  909. /* Name: Type: Description: */
  910. /* pageAttr const EPS_JOB_ATTRIB* I: This Page Attribute */
  911. /* */
  912. /* Return value: */
  913. /* << Normal >> */
  914. /* EPS_ERR_NONE - Success */
  915. /* EPS_JOB_CANCELED - Cancelled operation by user */
  916. /* (Do not return when Uni-Directional) */
  917. /* << Error >> */
  918. /* EPS_ERR_JOB_NOT_INITIALIZED - JOB is NOT initialized */
  919. /* EPS_ERR_PAGE_NOT_CLOSED - PAGE is NOT closed */
  920. /* EPS_ERR_PRINTER_ERR_OCCUR - Printer Error happened */
  921. /* EPS_ERR_OPR_FAIL - Internal Error */
  922. /* EPS_ERR_MEMORY_ALLOCATION - Failed to allocate memory */
  923. /* */
  924. /* Description: */
  925. /* Starts the current page. */
  926. /* */
  927. /*******************************************|********************************************/
  928. EPS_ERR_CODE epsStartPage (
  929. const EPS_PAGE_ATTRIB* pageAttr
  930. ){
  931. /*** Declare Variable Local to Routine */
  932. EPS_ERR_CODE retStatus; /* Return status of internal calls */
  933. EPS_UINT32 retBufSize = 0;
  934. EPS_STATUS_INFO stInfo;
  935. EPS_LOG_FUNCIN;
  936. (void)pageAttr; /* unused now */
  937. /*** EPS_CP_PRINTCMD not necessary call epsStartPage() */
  938. if (EPS_CP_PRINTCMD == printJob.attr.colorPlane) {
  939. EPS_RETURN( EPS_ERR_NONE );
  940. }
  941. /*** Has a Job been initialized */
  942. if (printJob.jobStatus != EPS_STATUS_ESTABLISHED) {
  943. EPS_RETURN( EPS_ERR_JOB_NOT_INITIALIZED );
  944. }
  945. /*** Has the Page Status been un-initialized; indicating the last page was closed */
  946. if (printJob.pageStatus != EPS_STATUS_NOT_INITIALIZED) {
  947. EPS_RETURN( EPS_ERR_PAGE_NOT_CLOSED );
  948. }
  949. /*** Check the printer status and the stacker error. */
  950. if ( EPS_IS_BI_PROTOCOL(printJob.printer->protocol) ){
  951. retStatus = MonitorStatus(&stInfo);
  952. if( EPS_ERR_NONE == retStatus ){
  953. if( EPS_PREPARE_TRAYCLOSED == stInfo.nPrepare ){
  954. retStatus = EPS_ERR_PRINTER_ERR_OCCUR;
  955. } else if( EPS_PM_JOB == obsGetPageMode() &&
  956. EPS_ST_IDLE != stInfo.nState ){
  957. /* still printing */
  958. EPS_DBGPRINT(("*** StarPage Wait ***\n"))
  959. retStatus = EPS_ERR_PRINTER_ERR_OCCUR;
  960. }
  961. }
  962. if( EPS_ERR_NONE != retStatus ){
  963. if( EPS_ERR_COMM_ERROR != retStatus &&
  964. EPS_PROTOCOL_USB != EPS_PRT_PROTOCOL(printJob.printer->protocol) )
  965. { /* Ignore error, Make buffer full state. */
  966. EPS_DBGPRINT(("*** Ignore error on StartPage ***\n"))
  967. retStatus = EPS_ERR_NONE;
  968. } else{
  969. goto epsStartPage_END;
  970. }
  971. }
  972. }
  973. if( EPS_PM_JOB == obsGetPageMode() &&
  974. EPS_PROTOCOL_LPR == EPS_PRT_PROTOCOL(printJob.printer->protocol) ){
  975. retStatus = PRT_INVOKE_JOBFNC(jobFnc.StartPage, ());
  976. if (retStatus != EPS_ERR_NONE) {
  977. goto epsStartPage_END;
  978. }
  979. }
  980. if( EPS_RESET_SENT == printJob.resetSent ){
  981. /* If CancelPage is done, restart Job. */
  982. /*** protocol depend RestartJob */
  983. retStatus = PRT_INVOKE_JOBFNC(jobFnc.RestartJob, ());
  984. if (retStatus != EPS_ERR_NONE) {
  985. goto epsStartPage_END;
  986. }
  987. }
  988. if(0 == printJob.contData.saveStep){
  989. if(EPS_LANG_ESCPR == printJob.printer->language ){
  990. /*** ESC/P-R ***/
  991. if( EPS_RESET_SENT == printJob.resetSent ){
  992. /* If CancelPage is done, restart Job complete. */
  993. printJob.resetSent = EPS_RESET_NOT_SENT;
  994. /*** Send StartJob & StartPage Commands */
  995. retStatus = SendStartJob(TRUE);
  996. } else if( EPS_PM_JOB == obsGetPageMode() ){
  997. /*** Send StartJob & StartPage Commands */
  998. retStatus = SendStartJob(TRUE);
  999. } else{
  1000. /*** Send StartPage Commands */
  1001. EPS_MEM_GROW(EPS_UINT8*, sendDataBuf, &sendDataBufSize, sizeof(StartPage) )
  1002. if(NULL == sendDataBuf){
  1003. sendDataBufSize = 0;
  1004. retStatus = EPS_ERR_MEMORY_ALLOCATION;
  1005. goto epsStartPage_END;
  1006. }
  1007. memcpy(sendDataBuf, StartPage, sizeof(StartPage));
  1008. retStatus = SendCommand(sendDataBuf, sizeof(StartPage), &retBufSize, TRUE);
  1009. }
  1010. } else{
  1011. /*** ESC/Page ***/
  1012. #ifdef GCOMSW_CMD_ESCPAGE
  1013. retStatus = pageStartPage();
  1014. #else
  1015. retStatus = EPS_ERR_LANGUAGE_NOT_SUPPORTED;
  1016. #endif
  1017. }
  1018. } else{
  1019. /* send command retry */
  1020. retStatus = SendLeftovers();
  1021. if(EPS_ERR_INVALID_CALL == retStatus){
  1022. retStatus = EPS_ERR_NONE;
  1023. }
  1024. }
  1025. if(EPS_ERR_NONE == retStatus){
  1026. printJob.contData.saveStep = 0;
  1027. } else{
  1028. printJob.contData.saveStep = 1;
  1029. }
  1030. epsStartPage_END:
  1031. if(EPS_ERR_NONE == retStatus){
  1032. /*** Change Page Status */
  1033. printJob.pageStatus = EPS_STATUS_INITIALIZED;
  1034. printJob.contData.savePoint = EPS_SAVEP_NONE;
  1035. /*** Set Vertical Offset */
  1036. printJob.verticalOffset = 0;
  1037. printJob.contData.jpgSize = 0;
  1038. printJob.contData.epRetry = 0;
  1039. printJob.contData.skipLine = FALSE;
  1040. printJob.jpegSize = 0;
  1041. printJob.bJpgLimit = FALSE;
  1042. if( printJob.attr.duplex != EPS_DUPLEX_NONE ){
  1043. printJob.needBand = TRUE;
  1044. } else{
  1045. printJob.needBand = FALSE;
  1046. }
  1047. } else if(EPS_ERR_COMM_ERROR == retStatus){
  1048. printJob.bComm = FALSE;
  1049. retStatus = EPS_ERR_PRINTER_ERR_OCCUR;
  1050. } else{
  1051. printJob.contData.savePoint = EPS_SAVEP_START_PAGE;
  1052. }
  1053. /*** Return to Caller */
  1054. EPS_RETURN( retStatus );
  1055. }
  1056. /*******************************************|********************************************/
  1057. /* */
  1058. /* Function name: epsPrintBand() */
  1059. /* */
  1060. /* Arguments */
  1061. /* --------- */
  1062. /* Name: Type: Description: */
  1063. /* data EPS_UINT8* I: Pointer to image [RGB] data */
  1064. /* widthPixels EPS_UINT32 I: The width of the raster band (in pixels) */
  1065. /* heightPixels EPS_UINT32* I/O: In : Height of image (image lines) (in pixels)*/
  1066. /* : Out: Sent Height */
  1067. /* */
  1068. /* Return value: */
  1069. /* << Normal >> */
  1070. /* EPS_ERR_NONE - Success */
  1071. /* EPS_JOB_CANCELED - Cancelled operation by user */
  1072. /* (Do not return when Uni-Directional) */
  1073. /* EPS_OUT_OF_BOUNDS - Print band is in out of printable area */
  1074. /* << Error >> */
  1075. /* EPS_ERR_PAGE_NOT_INITIALIZED - Page is NOT initialized */
  1076. /* EPS_ERR_INV_ARG_DATA - Invalid argument "data" */
  1077. /* EPS_ERR_INV_ARG_WIDTH_PIXELS - Invalid argument "widthPixels" */
  1078. /* EPS_ERR_INV_ARG_HEIGHT_PIXELS - Invalid argument "heightPixels" */
  1079. /* EPS_ERR_INV_ARG_DATASIZE - data size limit */
  1080. /* EPS_ERR_PRINTER_ERR_OCCUR - Printer Error happened */
  1081. /* EPS_ERR_OPR_FAIL - Internal Error */
  1082. /* EPS_ERR_MEMORY_ALLOCATION - Failed to allocate memory */
  1083. /* */
  1084. /* Description: */
  1085. /* Prints a band of raster data or Jpeg file data. */
  1086. /* */
  1087. /*******************************************|********************************************/
  1088. EPS_ERR_CODE epsPrintBand (
  1089. const EPS_UINT8* data, /* Pointer to image [RGB] data */
  1090. EPS_UINT32 widthPixels, /* Width of image [ in pixels ] */
  1091. EPS_UINT32 *heightPixels /* Height of image (image lines) */
  1092. ) {
  1093. /*** Declare Variable Local to Routine */
  1094. EPS_ERR_CODE retStatus;
  1095. EPS_PRN_DATA prnData;
  1096. prnData.version = 1;
  1097. prnData.band.data = data;
  1098. prnData.band.widthPixels = widthPixels;
  1099. prnData.band.heightPixels = *heightPixels;
  1100. retStatus = epsSendData(&prnData);
  1101. *heightPixels = prnData.band.heightPixels;
  1102. return retStatus;
  1103. }
  1104. EPS_ERR_CODE epsSendData (
  1105. EPS_PRN_DATA* prnData /* Pointer to image [RGB, JPEG] data */
  1106. ) {
  1107. /*** Declare Variable Local to Routine */
  1108. EPS_ERR_CODE retStatus = EPS_ERR_NONE;
  1109. EPS_LOG_FUNCIN
  1110. /*** Has a Page (which also means Job) been initialized */
  1111. if (printJob.pageStatus == EPS_STATUS_NOT_INITIALIZED) {
  1112. retStatus = EPS_ERR_PAGE_NOT_INITIALIZED;
  1113. }
  1114. /* printJob.pageStatus = EPS_STATUS_PROCCESSING; */
  1115. if( FALSE == printJob.bComm ){
  1116. retStatus = EPS_ERR_PRINTER_ERR_OCCUR;
  1117. }
  1118. /*** Validate input parameters */
  1119. if( NULL == prnData ){
  1120. EPS_RETURN( EPS_ERR_INV_ARG_DATA );
  1121. }
  1122. switch(printJob.attr.colorPlane){
  1123. case EPS_CP_JPEG:
  1124. if(EPS_ERR_NONE == retStatus){
  1125. retStatus = PrintChunk(prnData->chunk.data, &prnData->chunk.dataSize);
  1126. } else{
  1127. prnData->chunk.dataSize = 0;
  1128. }
  1129. break;
  1130. case EPS_CP_FULLCOLOR:
  1131. case EPS_CP_256COLOR:
  1132. if(EPS_ERR_NONE == retStatus){
  1133. retStatus = PrintBand(prnData->band.data, prnData->band.widthPixels, &prnData->band.heightPixels);
  1134. } else{
  1135. prnData->band.heightPixels = 0;
  1136. }
  1137. break;
  1138. case EPS_CP_PRINTCMD:
  1139. default:
  1140. if(EPS_ERR_NONE == retStatus){
  1141. retStatus = SendCommand(prnData->chunk.data, prnData->chunk.dataSize,
  1142. &prnData->chunk.dataSize, FALSE);
  1143. } else{
  1144. prnData->chunk.dataSize = 0;
  1145. }
  1146. break;
  1147. }
  1148. if(EPS_ERR_COMM_ERROR == retStatus){
  1149. printJob.bComm = FALSE;
  1150. retStatus = EPS_ERR_PRINTER_ERR_OCCUR;
  1151. }
  1152. EPS_RETURN( retStatus );
  1153. }
  1154. /*******************************************|********************************************/
  1155. /* */
  1156. /* Function name: epsEndPage() */
  1157. /* */
  1158. /* Arguments */
  1159. /* --------- */
  1160. /* Name: Type: Description: */
  1161. /* nextPage EPS_BOOL Next page flag */
  1162. /* */
  1163. /* Return value: */
  1164. /* << Normal >> */
  1165. /* EPS_ERR_NONE - Success */
  1166. /* EPS_JOB_CANCELED - Cancelled operation by user */
  1167. /* (Do not return when Uni-Directional) */
  1168. /* << Error >> */
  1169. /* EPS_ERR_PAGE_NOT_INITIALIZED - PAGE is NOT initialized */
  1170. /* EPS_ERR_PRINTER_ERR_OCCUR - Printer Error happened */
  1171. /* EPS_ERR_OPR_FAIL - Internal Error */
  1172. /* */
  1173. /* Description: */
  1174. /* Ends the current page. */
  1175. /* */
  1176. /*******************************************|********************************************/
  1177. EPS_ERR_CODE epsEndPage (
  1178. EPS_BOOL nextPage
  1179. ){
  1180. /*** Declare Variable Local to Routine */
  1181. EPS_ERR_CODE retStatus= EPS_ERR_NONE; /* Return status of internal calls */
  1182. EPS_UINT32 retBufSize = 0;
  1183. EPS_UINT8* pCmd = NULL;
  1184. EPS_STATUS_INFO stInfo;
  1185. EPS_LOG_FUNCIN;
  1186. /*** EPS_CP_PRINTCMD not necessary call epsEndPage() */
  1187. if (EPS_CP_PRINTCMD == printJob.attr.colorPlane) {
  1188. EPS_RETURN( EPS_ERR_NONE );
  1189. }
  1190. /*** Has a Page (which also means Job) been initialized */
  1191. if (printJob.pageStatus == EPS_STATUS_NOT_INITIALIZED) {
  1192. EPS_RETURN( EPS_ERR_PAGE_NOT_INITIALIZED );
  1193. }
  1194. if( FALSE == printJob.bComm ){
  1195. /*** Change the page status */
  1196. printJob.pageStatus = EPS_STATUS_NOT_INITIALIZED;
  1197. /* Do not send "EndPage" commands */
  1198. EPS_RETURN( EPS_ERR_NONE );
  1199. }
  1200. /*======================================================================================*/
  1201. /*** Check the printer status */
  1202. /*======================================================================================*/
  1203. if ( EPS_IS_BI_PROTOCOL(printJob.printer->protocol) ){
  1204. /* Check the printer status */
  1205. retStatus = MonitorStatus(NULL);
  1206. if( EPS_JOB_CANCELED == retStatus ){
  1207. goto epsEndPage_END;
  1208. } else if(EPS_ERR_COMM_ERROR == retStatus ){
  1209. goto epsEndPage_END;
  1210. }
  1211. }
  1212. /* send command retry */
  1213. retStatus = SendLeftovers();
  1214. if(EPS_ERR_INVALID_CALL == retStatus){
  1215. retStatus = EPS_ERR_NONE;
  1216. }
  1217. /*** Send EndPage */
  1218. /* step 1 : send dummy band for duplex */
  1219. if( EPS_ERR_NONE == retStatus && 0 == printJob.contData.saveStep ){
  1220. printJob.contData.saveStep++;
  1221. if( TRUE == printJob.needBand ){
  1222. retStatus = SendBlankBand();
  1223. printJob.needBand = FALSE;
  1224. }
  1225. }
  1226. /* step 2 : send end page command */
  1227. if( EPS_ERR_NONE == retStatus && 1 == printJob.contData.saveStep ){
  1228. printJob.contData.saveStep++;
  1229. if(EPS_LANG_ESCPR == printJob.printer->language ){
  1230. /*** ESC/P-R ***/
  1231. if( EPS_PM_JOB == obsGetPageMode() ){
  1232. /* EndPage & EndJob */
  1233. retStatus = SendEndJob(TRUE);
  1234. } else{
  1235. /* EndPage */
  1236. EPS_MEM_GROW(EPS_UINT8*, sendDataBuf, &sendDataBufSize, sizeof(EndPage) )
  1237. if(NULL == sendDataBuf){
  1238. sendDataBufSize = 0;
  1239. retStatus = EPS_ERR_MEMORY_ALLOCATION;
  1240. goto epsEndPage_END;
  1241. }
  1242. pCmd = sendDataBuf;
  1243. memcpy(pCmd, EndPage, sizeof(EndPage));
  1244. if( FALSE == nextPage ){
  1245. if (EPS_DUPLEX_NONE != printJob.attr.duplex &&
  1246. 0 == (printJob.pageCount & 0x01)) {
  1247. nextPage = TRUE;
  1248. }
  1249. }
  1250. if(FALSE == nextPage
  1251. || EPS_IS_CDDVD( printJob.attr.mediaTypeIdx )){
  1252. pCmd[10] = EPS_END_PAGE;
  1253. } else{
  1254. pCmd[10] = EPS_NEXT_PAGE;
  1255. }
  1256. retStatus = SendCommand(sendDataBuf, sizeof(EndPage), &retBufSize, TRUE);
  1257. }
  1258. } else{
  1259. /*** ESC/Page ***/
  1260. #ifdef GCOMSW_CMD_ESCPAGE
  1261. retStatus = pageEndPage();
  1262. #else
  1263. retStatus = EPS_ERR_LANGUAGE_NOT_SUPPORTED;
  1264. #endif
  1265. }
  1266. }
  1267. epsEndPage_END:
  1268. /*** Return to Caller */
  1269. if(EPS_ERR_NONE == retStatus){
  1270. /*** Change the page status */
  1271. printJob.pageStatus = EPS_STATUS_NOT_INITIALIZED;
  1272. printJob.pageCount++;
  1273. printJob.contData.savePoint = EPS_SAVEP_NONE;
  1274. printJob.contData.saveStep = 0;
  1275. if( EPS_PM_JOB == obsGetPageMode() &&
  1276. EPS_PROTOCOL_LPR == EPS_PRT_PROTOCOL(printJob.printer->protocol) &&
  1277. printJob.contData.epRetry < 10){
  1278. /* LPR JOB mode */
  1279. retStatus = PRT_INVOKE_JOBFNC(jobFnc.EndPage, ());
  1280. if(EPS_ERR_NONE == retStatus){
  1281. if(EPS_IS_BI_PROTOCOL(printJob.printer->protocol)){
  1282. MonitorStatus(&stInfo);
  1283. if( EPS_ST_IDLE == stInfo.nState ){
  1284. /* retry this function still idle */
  1285. serDelayThread(2*_SECOND_, &epsCmnFnc);
  1286. printJob.contData.epRetry++;
  1287. printJob.contData.savePoint = EPS_SAVEP_END_PAGE;
  1288. printJob.contData.saveStep = 2;
  1289. printJob.pageStatus = EPS_STATUS_INITIALIZED;
  1290. retStatus = EPS_ERR_PRINTER_ERR_OCCUR;
  1291. EPS_DBGPRINT(("*** EndPage Wait ***\n"))
  1292. }
  1293. }
  1294. } else if(EPS_ERR_COMM_ERROR == retStatus){
  1295. printJob.bComm = FALSE;
  1296. retStatus = EPS_ERR_PRINTER_ERR_OCCUR;
  1297. }
  1298. }
  1299. } else if(EPS_ERR_COMM_ERROR == retStatus){
  1300. printJob.bComm = FALSE;
  1301. retStatus = EPS_ERR_PRINTER_ERR_OCCUR;
  1302. } else{
  1303. printJob.contData.savePoint = EPS_SAVEP_END_PAGE;
  1304. printJob.contData.nextPage = nextPage;
  1305. }
  1306. EPS_RETURN( retStatus );
  1307. }
  1308. /*******************************************|********************************************/
  1309. /* */
  1310. /* Function name: epsEndJob() */
  1311. /* */
  1312. /* Arguments */
  1313. /* --------- */
  1314. /* Name: Type: Description: */
  1315. /* N/A void N/A */
  1316. /* */
  1317. /* Return value: */
  1318. /* << Normal >> */
  1319. /* EPS_ERR_NONE - Success */
  1320. /* << Error >> */
  1321. /* EPS_ERR_JOB_NOT_INITIALIZED - JOB is NOT initialized */
  1322. /* */
  1323. /* Description: */
  1324. /* Ends the current print job. */
  1325. /* */
  1326. /*******************************************|********************************************/
  1327. EPS_ERR_CODE epsEndJob (
  1328. void
  1329. ){
  1330. /*** Declare Variable Local to Routine */
  1331. EPS_ERR_CODE retStatus; /* Return status of internal calls */
  1332. EPS_INT32 nRetry = 0;
  1333. EPS_PRINT_JOB tempPrintJob;
  1334. EPS_UINT32 retBufSize = 0;
  1335. EPS_BOOL sendEndpage = FALSE;
  1336. EPS_LOG_FUNCIN;
  1337. /*** Initialize Local Variables */
  1338. retStatus = EPS_ERR_NONE;
  1339. /*** Has a Job been initialized; indicate start job was called */
  1340. if (printJob.jobStatus == EPS_STATUS_NOT_INITIALIZED) {
  1341. retStatus = EPS_ERR_JOB_NOT_INITIALIZED;
  1342. goto JOBEND_END;
  1343. }
  1344. if (EPS_CP_PRINTCMD != printJob.attr.colorPlane) {
  1345. /*** If not invoked epsEndPage, invoke it */
  1346. if (printJob.pageStatus != EPS_STATUS_NOT_INITIALIZED) {
  1347. epsEndPage(FALSE);
  1348. }
  1349. /*** Send backside page for ESCPR duplex */
  1350. if(EPS_RESET_NOT_SENT == printJob.resetSent &&
  1351. EPS_DUPLEX_NONE != printJob.attr.duplex &&
  1352. EPS_LANG_ESCPR == printJob.printer->language &&
  1353. (printJob.pageCount & 0x01) )
  1354. {
  1355. memcpy(sendDataBuf, StartPage, sizeof(StartPage));
  1356. retStatus = SendCommand(sendDataBuf, sizeof(StartPage), &retBufSize, TRUE);
  1357. for(nRetry = 0; nRetry < 5 && printJob.bComm; nRetry++){
  1358. if(EPS_ERR_NONE == retStatus || EPS_JOB_CANCELED == retStatus){
  1359. break;
  1360. }
  1361. retStatus = SendLeftovers();
  1362. if(EPS_ERR_INVALID_CALL == retStatus){
  1363. retStatus = EPS_ERR_NONE;
  1364. }
  1365. }
  1366. retStatus = SendBlankBand();
  1367. for(nRetry = 0; nRetry < 5 && printJob.bComm; nRetry++){
  1368. if(EPS_ERR_NONE == retStatus || EPS_JOB_CANCELED == retStatus){
  1369. break;
  1370. }
  1371. retStatus = SendLeftovers();
  1372. if(EPS_ERR_INVALID_CALL == retStatus){
  1373. retStatus = EPS_ERR_NONE;
  1374. }
  1375. }
  1376. sendEndpage = TRUE;
  1377. }
  1378. /*** Send EndJob */
  1379. if (printJob.jobStatus == EPS_STATUS_ESTABLISHED &&
  1380. EPS_PM_JOB != obsGetPageMode() )
  1381. {
  1382. if(EPS_LANG_ESCPR == printJob.printer->language ){
  1383. /*** ESC/P-R ***/
  1384. retStatus = SendEndJob(sendEndpage);
  1385. } else{
  1386. /*** ESC/Page ***/
  1387. #ifdef GCOMSW_CMD_ESCPAGE
  1388. retStatus = pageEndJob();
  1389. #else
  1390. retStatus = EPS_ERR_LANGUAGE_NOT_SUPPORTED;
  1391. #endif
  1392. }
  1393. }
  1394. for(nRetry = 0; nRetry < 5 && printJob.bComm; nRetry++){
  1395. if(EPS_ERR_NONE == retStatus){
  1396. break;
  1397. }
  1398. EPS_DBGPRINT(("retry ENDJOB\n"))
  1399. retStatus = SendLeftovers();
  1400. if(EPS_ERR_INVALID_CALL == retStatus){
  1401. retStatus = EPS_ERR_NONE;
  1402. }
  1403. }
  1404. }
  1405. /*** protocol depend EndJob */
  1406. retStatus = jobFnc.EndJob();
  1407. JOBEND_END:
  1408. /*** Clear Memory */
  1409. #ifdef GCOMSW_CMD_ESCPAGE
  1410. pageRelaseBuffer();
  1411. #endif
  1412. EPS_SAFE_RELEASE(sendDataBuf );
  1413. EPS_SAFE_RELEASE(tmpLineBuf );
  1414. sendDataBufSize = 0;
  1415. tmpLineBufSize = 0;
  1416. /*** Reset continue buffer */
  1417. printJob.contData.sendData = NULL;
  1418. printJob.contData.sendDataSize = 0;
  1419. /*** Clear inside additional data buffer */
  1420. /* DEL EPS_SAFE_RELEASE( printJob.qrcode.bits );*/
  1421. /*** Clear and Copy Print_Job struct */
  1422. memcpy(&tempPrintJob, &printJob, sizeof(EPS_PRINT_JOB));
  1423. memset(&printJob, 0, sizeof(EPS_PRINT_JOB));
  1424. printJob.pageStatus = tempPrintJob.pageStatus;
  1425. printJob.commMode = tempPrintJob.commMode;
  1426. printJob.printer = tempPrintJob.printer;
  1427. printJob.platform = tempPrintJob.platform;
  1428. #ifdef GCOMSW_EPSON_SLEEP
  1429. printJob.sleepSteps = tempPrintJob.sleepSteps;
  1430. #endif
  1431. /*** Change the job status */
  1432. printJob.jobStatus = EPS_STATUS_NOT_INITIALIZED;
  1433. printJob.pageStatus = EPS_STATUS_NOT_INITIALIZED;
  1434. printJob.bComm = TRUE;
  1435. printJob.resetReq = FALSE;
  1436. #if 0
  1437. if(EPS_ERR_NOT_CLOSE_IO == retStatus || EPS_ERR_COMM_ERROR == retStatus){
  1438. retStatus = EPS_ERR_PRINTER_ERR_OCCUR;
  1439. }
  1440. #else
  1441. if (EPS_ERR_NONE != retStatus) {
  1442. EPS_DBGPRINT(("epsEndJob failed (%d)\r\n", retStatus));
  1443. retStatus = EPS_ERR_NONE;
  1444. }
  1445. #endif
  1446. #ifdef LCOMSW_CMDDMP
  1447. EPS_DF_CLOSE
  1448. #endif
  1449. EPS_RETURN( retStatus );
  1450. }
  1451. /*******************************************|********************************************/
  1452. /* */
  1453. /* Function name: epsCancelJob() */
  1454. /* */
  1455. /* Arguments */
  1456. /* --------- */
  1457. /* Name: Type: Description: */
  1458. /* reserve EPS_BOOL I:Call epsEndJob() */
  1459. /* */
  1460. /* Return value: */
  1461. /* EPS_ERR_NONE - Success */
  1462. /* EPS_ERR_NEED_BIDIRECT - Need Bi-Directional Communication */
  1463. /* EPS_ERR_CAN_NOT_RESET - Failed to reset printer */
  1464. /* */
  1465. /* Description: */
  1466. /* Reset printer. */
  1467. /* */
  1468. /*******************************************|********************************************/
  1469. EPS_ERR_CODE epsCancelJob (
  1470. EPS_INT32 reserve
  1471. ){
  1472. /*** Declare Variable Local to Routine */
  1473. EPS_ERR_CODE retStatus = EPS_ERR_NONE; /* Return status of internal calls */
  1474. EPS_ERR_CODE retTmp = EPS_ERR_NONE;
  1475. EPS_LOG_FUNCIN;
  1476. #if !LCOMSW_CANCEL_JOB
  1477. (void)reserve;
  1478. #endif
  1479. /*** Validate communication mode */
  1480. if(NULL == printJob.printer){
  1481. EPS_RETURN( EPS_ERR_NONE/*EPS_ERR_PRINTER_NOT_SET*/ );
  1482. }
  1483. if ( !EPS_IS_BI_PROTOCOL(printJob.printer->protocol) ){
  1484. EPS_RETURN( EPS_ERR_NEED_BIDIRECT );
  1485. }
  1486. if (printJob.jobStatus == EPS_STATUS_ESTABLISHED) {
  1487. /*** Send the reset command to printer */
  1488. retStatus = PRT_INVOKE_JOBFNC(jobFnc.ResetPrinter, ());
  1489. printJob.resetSent = EPS_RESET_SENT;
  1490. printJob.resetReq = FALSE;
  1491. if(EPS_ERR_NONE != retStatus){
  1492. EPS_DBGPRINT(("ResetPrinter() failed (%d)\r\n", retStatus));
  1493. retStatus = EPS_ERR_CAN_NOT_RESET;
  1494. /* return retStatus; Force continue */
  1495. }
  1496. /*** Change the page status */
  1497. printJob.pageStatus = EPS_STATUS_NOT_INITIALIZED;
  1498. }
  1499. #if LCOMSW_CANCEL_JOB
  1500. if(0 == reserve){
  1501. #endif
  1502. /*** Invoke epsEndJob() */
  1503. retTmp = epsEndJob();
  1504. if (retTmp != EPS_ERR_NONE) {
  1505. EPS_DBGPRINT(("epsEndJob() failed (%d)\r\n", retTmp));
  1506. /* return retStatus; Force continue */
  1507. }
  1508. #if LCOMSW_CANCEL_JOB
  1509. }
  1510. #endif
  1511. EPS_RETURN( retStatus );
  1512. }
  1513. /*******************************************|********************************************/
  1514. /* */
  1515. /* Function name: epsContinueJob() */
  1516. /* */
  1517. /* Arguments */
  1518. /* --------- */
  1519. /* Name: Type: Description: */
  1520. /* N/A void N/A */
  1521. /* */
  1522. /* Return value: */
  1523. /* << Normal >> */
  1524. /* EPS_ERR_NONE - Success */
  1525. /* EPS_JOB_CANCELED - Cancelled operation by user */
  1526. /* (Do not return when Uni-Directional) */
  1527. /* << Error >> */
  1528. /* EPS_ERR_NEED_BIDIRECT - Need Bi-Directional Communication */
  1529. /* EPS_ERR_JOB_NOT_INITIALIZED - JOB is NOT initialized */
  1530. /* EPS_ERR_PAGE_NOT_INITIALIZED - PAGR is NOT initialized */
  1531. /* EPS_ERR_PRINTER_ERR_OCCUR - Printer Error happened */
  1532. /* */
  1533. /* Description: */
  1534. /* Reset printer. */
  1535. /* */
  1536. /*******************************************|********************************************/
  1537. EPS_ERR_CODE epsContinueJob (
  1538. void
  1539. ){
  1540. /*** Declare Variable Local to Routine */
  1541. EPS_ERR_CODE retStatus = EPS_ERR_NONE; /* Return status of internal calls */
  1542. EPS_INT32 nCnt = 0;
  1543. EPS_LOG_FUNCIN;
  1544. /*** Has a target printer specified */
  1545. if(NULL == printJob.printer){
  1546. EPS_RETURN( EPS_ERR_JOB_NOT_INITIALIZED );
  1547. }
  1548. /*** Has a Job been initialized */
  1549. if (printJob.jobStatus == EPS_STATUS_NOT_INITIALIZED){
  1550. EPS_RETURN( EPS_ERR_JOB_NOT_INITIALIZED );
  1551. }
  1552. /*** Validate communication mode */
  1553. if( !EPS_IS_BI_PROTOCOL(printJob.printer->protocol) ){
  1554. EPS_RETURN( EPS_ERR_NEED_BIDIRECT );
  1555. }
  1556. /*** Recovery command */
  1557. switch( printJob.contData.lastError ){
  1558. case EPS_PRNERR_PAPEROUT:
  1559. case EPS_PRNERR_NOTRAY:
  1560. /*case EPS_PRNERR_CDDVDCONFIG:*/
  1561. if( EPS_ERR_PRINTER_ERR_OCCUR == MonitorStatus(NULL)){
  1562. if( EPS_ERR_NONE != (retStatus = prtRecoverPE()) ){
  1563. EPS_RETURN( EPS_ERR_PRINTER_ERR_OCCUR );
  1564. }
  1565. /*serDelayThread(2*_SECOND_, &epsCmnFnc);*/
  1566. /* Status change is delayed the condition of LPR ASSIST */
  1567. if( EPS_PROTOCOL_LPR == EPS_PRT_PROTOCOL(printJob.printer->protocol)
  1568. && EPS_IS_BI_PROTOCOL(printJob.printer->protocol) ){
  1569. for(nCnt = 0; nCnt < 3; nCnt++){
  1570. serDelayThread(2*_SECOND_, &epsCmnFnc);
  1571. if( EPS_ERR_NONE == MonitorStatus(NULL) ){
  1572. break;
  1573. }
  1574. EPS_DBGPRINT(("*** Recover Wait ***\n"))
  1575. }
  1576. }
  1577. }
  1578. break;
  1579. case EPS_PRNERR_INTERFACE:
  1580. /*serDelayThread(5*_SECOND_, &epsCmnFnc);*/
  1581. break;
  1582. default:
  1583. break;
  1584. }
  1585. /*** Check printer starus */
  1586. retStatus = MonitorStatus(NULL);
  1587. if(EPS_ERR_NONE != retStatus){
  1588. EPS_RETURN( retStatus );
  1589. }
  1590. /*** Send leftovers data */
  1591. switch(printJob.contData.savePoint){
  1592. case EPS_SAVEP_START_PAGE:
  1593. retStatus = epsStartPage(NULL);
  1594. break;
  1595. case EPS_SAVEP_END_PAGE:
  1596. retStatus = epsEndPage(printJob.contData.nextPage);
  1597. break;
  1598. default:
  1599. retStatus = SendLeftovers();
  1600. if(EPS_ERR_INVALID_CALL == retStatus){
  1601. retStatus = EPS_ERR_NONE;
  1602. } else if(EPS_ERR_NONE == retStatus){
  1603. printJob.contData.skipLine = TRUE;
  1604. } else {
  1605. EPS_RETURN( retStatus );
  1606. }
  1607. break;
  1608. }
  1609. /*** Return to Caller */
  1610. if(EPS_ERR_COMM_ERROR == retStatus){
  1611. printJob.bComm = FALSE;
  1612. retStatus = EPS_ERR_PRINTER_ERR_OCCUR;
  1613. }
  1614. EPS_RETURN( retStatus );
  1615. }
  1616. /*******************************************|********************************************/
  1617. /* */
  1618. /* Function name: epsSetAdditionalData() */
  1619. /* */
  1620. /* Arguments */
  1621. /* --------- */
  1622. /* Name: Type: Description: */
  1623. /* data EPS_ADD_DATA* I: pointer to Additional data */
  1624. /* */
  1625. /* Return value: */
  1626. /* << Normal >> */
  1627. /* EPS_ERR_NONE - Success */
  1628. /* << Error >> */
  1629. /* EPS_ERR_JOB_NOT_INITIALIZED - JOB is NOT initialized */
  1630. /* EPS_ERR_PAGE_NOT_CLOSED - PAGR is initialized */
  1631. /* EPS_ERR_INV_ARG_VALIDMEMBER - Invalid argument "validMember" */
  1632. /* EPS_ERR_INV_ARG_ADDDATA - Invalid argument "data" */
  1633. /* EPS_ERR_INV_ARG_QRSOURCE - Invalid argument "data.qrcode.source" */
  1634. /* EPS_ERR_INV_ARG_QRXPOS - Invalid argument "data.qrcode.xPos" */
  1635. /* EPS_ERR_INV_ARG_QRYPOS - Invalid argument "data.qrcode.position.y" */
  1636. /* EPS_ERR_QRSOURCE_TOO_LAGE - source is too lage to convert QR code */
  1637. /* */
  1638. /* Description: */
  1639. /* Set additional data print image. */
  1640. /* */
  1641. /*******************************************|********************************************/
  1642. EPS_ERR_CODE epsSetAdditionalData (
  1643. EPS_UINT32 dataType,
  1644. const void* data
  1645. ){
  1646. /*** Declare Variable Local to Routine */
  1647. EPS_LOG_FUNCIN;
  1648. /* This Func is ineffective in the current version. */
  1649. EPS_RETURN( EPS_ERR_INVALID_CALL );
  1650. }
  1651. /*******************************************|********************************************/
  1652. /* */
  1653. /* Function name: epsRemAdditionalData() */
  1654. /* */
  1655. /* Arguments */
  1656. /* --------- */
  1657. /* Name: Type: Description: */
  1658. /* member EPS_UINT32 I: pointer to Additional data */
  1659. /* */
  1660. /* Return value: */
  1661. /* << Normal >> */
  1662. /* EPS_ERR_NONE - Success */
  1663. /* << Error >> */
  1664. /* EPS_ERR_INV_ARG_VALIDMEMBER - Invalid argument "validMember" */
  1665. /* */
  1666. /* Description: */
  1667. /* Release additional data setting by epsRemAdditionalData(). */
  1668. /* */
  1669. /*******************************************|********************************************/
  1670. EPS_ERR_CODE epsRemAdditionalData (
  1671. EPS_UINT32 dataType
  1672. ){
  1673. EPS_LOG_FUNCIN;
  1674. /* This Func is ineffective in the current version. */
  1675. EPS_RETURN( EPS_ERR_INVALID_CALL );
  1676. }
  1677. /*******************************************|********************************************/
  1678. /* */
  1679. /* Function name: epsGetStatus() */
  1680. /* */
  1681. /* Arguments */
  1682. /* --------- */
  1683. /* Name: Type: Description: */
  1684. /* status EPS_STATUS* Pointer to the printer status. */
  1685. /* */
  1686. /* Return value: */
  1687. /* << Normal >> */
  1688. /* EPS_ERR_NONE - Success */
  1689. /* << Error >> */
  1690. /* EPS_ERR_NEED_BIDIRECT - Need Bi-Directional Communication */
  1691. /* EPS_ERR_PRINTER_NOT_SET - Target printer is not specified */
  1692. /* EPS_ERR_INV_ARG_STATUS - Invalid argument */
  1693. /* EPS_ERR_PROTOCOL_NOT_SUPPORTED - Unsupported function Error */
  1694. /* EPS_ERR_OPR_FAIL - Internal Error */
  1695. /* EPS_ERR_MEMORY_ALLOCATION - Failed to allocate memory */
  1696. /* */
  1697. /* Description: */
  1698. /* Gets the printer status. */
  1699. /* */
  1700. /*******************************************|********************************************/
  1701. EPS_ERR_CODE epsGetStatus (
  1702. EPS_STATUS *status
  1703. ){
  1704. /*** Declare Variable Local to Routine */
  1705. EPS_ERR_CODE ret = EPS_ERR_NONE; /* Return status of internal calls */
  1706. EPS_STATUS_INFO stInfo;
  1707. EPS_BOOL bIoStatus = FALSE;
  1708. EPS_BOOL bCanceling = FALSE;
  1709. EPS_LOG_FUNCIN;
  1710. /*** Validate communication mode */
  1711. if( !EPS_IS_BI_PROTOCOL(printJob.commMode) ){
  1712. EPS_RETURN( EPS_ERR_NEED_BIDIRECT );
  1713. }
  1714. /*** Has a target printer specified */
  1715. if(NULL == printJob.printer){
  1716. EPS_RETURN( EPS_ERR_PRINTER_NOT_SET );
  1717. }
  1718. /*** Validate input parameters */
  1719. if (status == NULL){
  1720. EPS_RETURN( EPS_ERR_INV_ARG_STATUS );
  1721. }
  1722. memset(status, 0, sizeof(EPS_STATUS));
  1723. /*** Jpeg size limitation */
  1724. if( TRUE == printJob.bJpgLimit ){
  1725. status->printerStatus = EPS_PRNST_ERROR;
  1726. status->errorCode = EPS_PRNERR_JPG_LIMIT;
  1727. status->jobContinue = FALSE;
  1728. EPS_RETURN( EPS_ERR_NONE );
  1729. }
  1730. /*** Get printer status */
  1731. memset(&stInfo, 0, sizeof(stInfo));
  1732. if( TRUE == printJob.bComm ){
  1733. ret = PRT_INVOKE_JOBFNC(jobFnc.GetStatus,
  1734. (&stInfo, &bIoStatus, &bCanceling));
  1735. if(EPS_ERR_COMM_ERROR == ret &&
  1736. EPS_STATUS_NOT_INITIALIZED != printJob.jobStatus){
  1737. printJob.bComm = FALSE;
  1738. }
  1739. } else{
  1740. ret = EPS_ERR_COMM_ERROR;
  1741. }
  1742. // EPS_DBGPRINT((" State\t: %d\n Error\t: %d\n IoStatus\t: %d\n Canceling\t: %d\n Prepare\t: %d\n",
  1743. // stInfo.nState, stInfo.nError, bIoStatus, bCanceling, stInfo.nPrepare))
  1744. if(EPS_ERR_COMM_ERROR == ret ||
  1745. EPS_ERR_NOT_OPEN_IO == ret ||
  1746. EPS_ERR_NOT_CLOSE_IO == ret ) {
  1747. status->printerStatus = EPS_PRNST_ERROR/*EPS_PRNST_OFFLINE*/;
  1748. status->errorCode = EPS_PRNERR_COMM;
  1749. status->jobContinue = FALSE;
  1750. EPS_RETURN( EPS_ERR_NONE );
  1751. } else if (EPS_ERR_NONE != ret){
  1752. EPS_RETURN( ret );
  1753. }
  1754. if(stInfo.nCancel == EPS_CAREQ_CANCEL) {
  1755. EPS_DBGPRINT(("EPS SER : CANCEL REQUEST by PRINTER\r\n"));
  1756. printJob.resetReq = TRUE;
  1757. }
  1758. #if 0
  1759. if(TRUE == printJob.resetReq){
  1760. status->printerStatus = EPS_PRNST_ERROR/*EPS_PRNST_OFFLINE*/;
  1761. status->errorCode = EPS_PRNERR_COMM;
  1762. status->jobContinue = FALSE;
  1763. }
  1764. #endif
  1765. /*** Copy status data to input buffer */
  1766. status->errorCode= stInfo.nError;
  1767. printJob.contData.lastError = stInfo.nError;
  1768. switch(stInfo.nState) {
  1769. case EPS_ST_ERROR:
  1770. status->printerStatus = EPS_PRNST_ERROR;
  1771. switch(stInfo.nError){
  1772. case EPS_PRNERR_INKOUT:
  1773. /* Convert Ink error */
  1774. serGetInkError(&stInfo, &status->errorCode);
  1775. break;
  1776. case EPS_PRNERR_INTERFACE:
  1777. case EPS_PRNERR_BUSY:
  1778. if(EPS_STATUS_ESTABLISHED == printJob.jobStatus){
  1779. /* between multi page(job of EPS_PM_JOB), it becomes busy. */
  1780. status->printerStatus = EPS_PRNST_PRINTING;
  1781. status->errorCode = EPS_PRNERR_NOERROR;
  1782. } else{
  1783. status->printerStatus = EPS_PRNST_BUSY;
  1784. }
  1785. break;
  1786. case EPS_PRNERR_PAPERJAM:
  1787. printJob.transmittable = FALSE;
  1788. break;
  1789. default:
  1790. break;
  1791. }
  1792. break;
  1793. case EPS_ST_WAITING:
  1794. status->printerStatus = EPS_PRNST_PRINTING;
  1795. break;
  1796. case EPS_ST_IDLE:
  1797. /* If printer doesn't move, it becomes idle. */
  1798. if(EPS_STATUS_ESTABLISHED == printJob.jobStatus){
  1799. status->printerStatus = EPS_PRNST_PRINTING;
  1800. } else{
  1801. status->printerStatus = EPS_PRNST_IDLE;
  1802. }
  1803. break;
  1804. case EPS_ST_FACTORY_SHIPMENT:
  1805. status->printerStatus = EPS_PRNST_ERROR;
  1806. status->errorCode = EPS_PRNERR_FACTORY;
  1807. break;
  1808. case EPS_ST_CLEANING:
  1809. case EPS_ST_BUSY:
  1810. if(EPS_STATUS_ESTABLISHED == printJob.jobStatus){
  1811. /* The cleaning under the print is made "printing". */
  1812. status->printerStatus = EPS_PRNST_PRINTING;
  1813. status->errorCode = EPS_PRNERR_NOERROR;
  1814. } else{
  1815. status->errorCode = EPS_PRNERR_BUSY;
  1816. status->printerStatus = EPS_PRNST_BUSY;
  1817. }
  1818. break;
  1819. default: /* The others. */
  1820. /* EPS_ST_SELF_PRINTING */
  1821. /* EPS_ST_SHUTDOWN */
  1822. status->errorCode = EPS_PRNERR_BUSY;
  1823. status->printerStatus = EPS_PRNST_BUSY;
  1824. break;
  1825. }
  1826. if(EPS_PRNERR_NOERROR == status->errorCode){
  1827. /* If other errors have not occurred */
  1828. if(EPS_PREPARE_TRAYCLOSED == stInfo.nPrepare
  1829. && EPS_STATUS_ESTABLISHED == printJob.jobStatus
  1830. && EPS_STATUS_NOT_INITIALIZED == printJob.pageStatus){
  1831. /* between epsStartJob to epsStartPage complete */
  1832. status->errorCode = EPS_PRNERR_TRAYCLOSE;
  1833. status->printerStatus = EPS_PRNST_ERROR;
  1834. } else if(EPS_PRNWARN_DISABLE_CLEAN & stInfo.nWarn
  1835. && EPS_MNT_CLEANING == printJob.attr.cmdType
  1836. && EPS_STATUS_INITIALIZED == printJob.jobStatus){
  1837. /* GetStatus failed in epsStartJob() */
  1838. status->errorCode = EPS_PRNERR_DISABEL_CLEANING;
  1839. status->printerStatus = EPS_PRNST_ERROR;
  1840. } else if( bCanceling ){
  1841. /* Printing has been canceled by the cancel request which had been triggered
  1842. * by either the epsonPrintCancelJob/Page() API
  1843. * or a user operation on the printer panel. */
  1844. status->printerStatus = EPS_PRNST_CANCELLING;
  1845. if(EPS_PRNERR_NOERROR == status->errorCode){
  1846. status->errorCode = EPS_PRNERR_BUSY;
  1847. }
  1848. } else if( !bIoStatus ) {
  1849. /* ESC/P-R Library had sent all that is needed to print
  1850. * to the printer but the printer has not been completed printing yet. */
  1851. status->printerStatus = EPS_PRNST_BUSY;
  1852. if(EPS_PRNERR_NOERROR == status->errorCode){
  1853. status->errorCode = EPS_PRNERR_BUSY;
  1854. }
  1855. }
  1856. /* ignore color-ink-end warning
  1857. else if( EPS_PRNWARN_COLOR_INKOUT & stInfo.nWarn
  1858. && EPS_STATUS_ESTABLISHED != printJob.jobStatus ){
  1859. color ink out is error, when besides job.
  1860. status->errorCode = EPS_PRNERR_INKOUT;
  1861. status->printerStatus = EPS_PRNST_ERROR;
  1862. }*/
  1863. }
  1864. /*** Set continue flag */
  1865. status->jobContinue = TRUE;
  1866. if( EPS_STATUS_ESTABLISHED != printJob.jobStatus ){
  1867. status->jobContinue = FALSE;
  1868. } else{
  1869. switch(status->errorCode){
  1870. /* The error that it can not continue the printing job */
  1871. case EPS_PRNERR_GENERAL:
  1872. case EPS_PRNERR_FATAL:
  1873. case EPS_PRNERR_PAPERJAM:
  1874. /*case EPS_PRNERR_SIZE_TYPE_PATH:*/
  1875. case EPS_PRNERR_SERVICEREQ:
  1876. case EPS_PRNERR_CARDLOADING:
  1877. case EPS_PRNERR_BATTERYVOLTAGE:
  1878. case EPS_PRNERR_BATTERYTEMPERATURE:
  1879. case EPS_PRNERR_BATTERYEMPTY:
  1880. case EPS_PRNERR_COMM:
  1881. status->jobContinue = FALSE;
  1882. break;
  1883. case EPS_PRNERR_BUSY:
  1884. if(EPS_PRNST_CANCELLING == status->printerStatus){
  1885. /* When last time page printing.
  1886. It's state EPS_PRNST_CANCELLING & EPS_PRNERR_BUSY.*/
  1887. status->jobContinue = TRUE;
  1888. } else{
  1889. status->jobContinue = FALSE;
  1890. }
  1891. break;
  1892. }
  1893. }
  1894. /*** Return to Caller */
  1895. EPS_RETURN( ret );
  1896. }
  1897. /*******************************************|********************************************/
  1898. /* */
  1899. /* Function name: epsGetInkInfo() */
  1900. /* */
  1901. /* Arguments */
  1902. /* --------- */
  1903. /* Name: Type: Description: */
  1904. /* status EPS_STATUS* Pointer to the printer status. */
  1905. /* */
  1906. /* Return value: */
  1907. /* << Normal >> */
  1908. /* EPS_ERR_NONE - Success */
  1909. /* << Error >> */
  1910. /* EPS_ERR_NEED_BIDIRECT - Need Bi-Directional Communication */
  1911. /* EPS_ERR_PRINTER_NOT_SET - Target printer is not specified */
  1912. /* EPS_ERR_INV_ARG_INKINFO - Invalid argument */
  1913. /* EPS_ERR_COMM_ERROR - Communication Error */
  1914. /* EPS_ERR_NOT_OPEN_IO - Cannot Open I/O Portal */
  1915. /* EPS_ERR_PROTOCOL_NOT_SUPPORTED - Unsupported function Error */
  1916. /* EPS_ERR_OPR_FAIL - Internal Error */
  1917. /* EPS_ERR_MEMORY_ALLOCATION - Failed to allocate memory */
  1918. /* */
  1919. /* Description: */
  1920. /* Gets the Ink Infomation. */
  1921. /* */
  1922. /*******************************************|********************************************/
  1923. EPS_ERR_CODE epsGetInkInfo (
  1924. EPS_INK_INFO *info
  1925. ){
  1926. /*** Declare Variable Local to Routine */
  1927. EPS_ERR_CODE ret = EPS_ERR_NONE; /* Return status of internal calls */
  1928. EPS_LOG_FUNCIN;
  1929. /*** Has a target printer specified */
  1930. if(NULL == printJob.printer){
  1931. EPS_RETURN( EPS_ERR_PRINTER_NOT_SET );
  1932. }
  1933. /*** Validate input parameters */
  1934. if (info == NULL){
  1935. EPS_RETURN( EPS_ERR_INV_ARG_INKINFO );
  1936. }
  1937. memset(info, 0, sizeof(EPS_INK_INFO));
  1938. /*** protocol GetStatus */
  1939. ret = prtGetInkInfo(printJob.printer, info);
  1940. /*** Return to Caller */
  1941. EPS_RETURN( ret );
  1942. }
  1943. /*******************************************|********************************************/
  1944. /* */
  1945. /* Function name: epsGetSupportedMedia() */
  1946. /* */
  1947. /* Arguments */
  1948. /* --------- */
  1949. /* Name: Type: Description: */
  1950. /* supportedMedia EPS_SUPPORTED_MEDIA* Pointer to Supported Media Structure */
  1951. /* */
  1952. /* Return value: */
  1953. /* << Normal >> */
  1954. /* EPS_ERR_NONE - Success */
  1955. /* << Error >> */
  1956. /* EPS_ERR_NEED_BIDIRECT - Need Bi-Directional Communication */
  1957. /* EPS_ERR_PRINTER_NOT_SET - Target printer is not specified */
  1958. /* EPS_ERR_INV_ARG_SUPPORTED_MEDIA - Invalid argument */
  1959. /* EPS_ERR_COMM_ERROR - Communication Error */
  1960. /* EPS_ERR_NOT_OPEN_IO - Cannot Open I/O Portal */
  1961. /* EPS_ERR_NOT_CLOSE_IO - Cannot Close I/O Portal */
  1962. /* EPS_ERR_PROTOCOL_NOT_SUPPORTED - Unsupported function Error */
  1963. /* EPS_ERR_OPR_FAIL - Internal Error */
  1964. /* EPS_ERR_MEMORY_ALLOCATION - Failed to allocate memory */
  1965. /* */
  1966. /* Description: */
  1967. /* Get supported media information from printer and save those data in */
  1968. /* "g_supportedMedia" structure. */
  1969. /* */
  1970. /*******************************************|********************************************/
  1971. EPS_ERR_CODE epsGetSupportedMedia (
  1972. EPS_SUPPORTED_MEDIA* supportedMedia
  1973. ){
  1974. /*** Declare Variable Local to Routine */
  1975. EPS_ERR_CODE retStatus, retGetPM; /* Return status of internal calls */
  1976. EPS_UINT8 pmString[EPS_PM_MAXSIZE]; /* Retrieved PM data from printer */
  1977. EPS_INT32 pmSize = EPS_PM_MAXSIZE;
  1978. EPS_PRINTER_INN* innerPrinter = NULL;
  1979. EPS_LOG_FUNCIN;
  1980. /*** Initialize Local Variables */
  1981. retStatus = retGetPM = EPS_ERR_NONE;
  1982. /*** Validate communication mode */
  1983. if( !EPS_IS_BI_PROTOCOL(printJob.commMode) ){
  1984. EPS_RETURN( EPS_ERR_NEED_BIDIRECT );
  1985. }
  1986. /*** Has a target printer specified */
  1987. if(NULL == printJob.printer){
  1988. EPS_RETURN( EPS_ERR_PRINTER_NOT_SET );
  1989. }
  1990. innerPrinter = printJob.printer;
  1991. if( !EPS_IS_BI_PROTOCOL(innerPrinter->protocol) ){
  1992. EPS_RETURN( EPS_ERR_NEED_BIDIRECT );
  1993. }
  1994. /*** Validate input parameters */
  1995. if (supportedMedia == NULL){
  1996. EPS_RETURN( EPS_ERR_INV_ARG_SUPPORTED_MEDIA );
  1997. }
  1998. #if !_VALIDATE_SUPPORTED_MEDIA_DATA_
  1999. /*** If already exist, return current value */
  2000. if(innerPrinter->supportedMedia.numSizes > 0
  2001. && NULL != innerPrinter->supportedMedia.sizeList){
  2002. EPS_RETURN( DuplSupportedMedia(innerPrinter, supportedMedia) );
  2003. }
  2004. #endif
  2005. /* Clear the prev value */
  2006. prtClearSupportedMedia(innerPrinter);
  2007. /* Clear the Printer Model Information (Media data or "PM" data) */
  2008. memset(pmString,0,EPS_PM_MAXSIZE);
  2009. /*** Get PM from Printer */
  2010. retStatus = prtGetPMString(innerPrinter, 1, pmString, &pmSize);
  2011. /*** ESC/Page divergence ***/
  2012. if(EPS_LANG_ESCPR != innerPrinter->language ){
  2013. #ifdef GCOMSW_CMD_ESCPAGE
  2014. if( EPS_ERR_NONE == retStatus ) {
  2015. /*** Create Media Infomation */
  2016. retStatus = pageCreateMediaInfo(innerPrinter, pmString, pmSize);
  2017. }
  2018. #else
  2019. retStatus = EPS_ERR_LANGUAGE_NOT_SUPPORTED;
  2020. #endif
  2021. } else {
  2022. if ( EPS_ERR_NONE == retStatus ){
  2023. /*** Create Media Infomation */
  2024. retStatus = CreateMediaInfo(innerPrinter, pmString, pmSize);
  2025. }
  2026. }
  2027. /*** Copy the supproted media information from "printer" structure to input buffer */
  2028. if ( EPS_ERR_NONE == retStatus ){
  2029. /* Copy to input buffer */
  2030. retStatus = DuplSupportedMedia(innerPrinter, supportedMedia);
  2031. }
  2032. /*** Return to Caller */
  2033. EPS_RETURN( retStatus );
  2034. }
  2035. /*******************************************|********************************************/
  2036. /* */
  2037. /* Function name: epsGetPrintableArea() */
  2038. /* */
  2039. /* Arguments */
  2040. /* --------- */
  2041. /* Name: Type: Description: */
  2042. /* jobAttr const EPS_JOB_ATTRIB* I: Print Job Attribute */
  2043. /* printableWidth EPS_INT32* O: Printable area width. */
  2044. /* printableHeight EPS_INT32* O: Printable area height. */
  2045. /* */
  2046. /* Return value: */
  2047. /* << Normal >> */
  2048. /* EPS_ERR_NONE - Success */
  2049. /* << Error >> */
  2050. /* EPS_ERR_LIB_NOT_INITIALIZED - ESC/P-R Lib is NOT initialized */
  2051. /* EPS_ERR_INV_ARG_JBO_ATTRIB - Invalid argument "jobAttr" */
  2052. /* EPS_ERR_INV_ARG_PRINTABLE_WIDTH - Invalid argument "printableWidth" */
  2053. /* EPS_ERR_INV_ARG_PRINTABLE_HEIGHT - Invalid argument "printableHeight" */
  2054. /* EPS_ERR_INV_MEDIA_SIZE - Invalid Media Size */
  2055. /* EPS_ERR_INV_BORDER_MODE - Invalid Border Mode */
  2056. /* EPS_ERR_INV_INPUT_RESOLUTION - Invalid Input Resolution */
  2057. /* EPS_ERR_INV_TOP_MARGIN - Invalid Top Magirn */
  2058. /* EPS_ERR_INV_LEFT_MARGIN - Invalid Left Margin */
  2059. /* EPS_ERR_INV_BOTTOM_MARGIN - Invalid Bottom Margin */
  2060. /* EPS_ERR_INV_RIGHT_MARGIN - Invalid Right Margin */
  2061. /* EPS_ERR_MARGIN_OVER_PRINTABLE_WIDTH - Invalid Magin Setting (Width) */
  2062. /* EPS_ERR_MARGIN_OVER_PRINTABLE_HEIGHT - Invalid Magin Setting (Height) */
  2063. /* EPS_ERR_OPR_FAIL - Internal Error */
  2064. /* */
  2065. /* Description: */
  2066. /* Gets the printable area of the image. */
  2067. /* */
  2068. /*******************************************|********************************************/
  2069. EPS_ERR_CODE epsGetPrintableArea (
  2070. EPS_JOB_ATTRIB* jobAttr,
  2071. EPS_UINT32* printableWidth,
  2072. EPS_UINT32* printableHeight
  2073. ){
  2074. /*** Declare Variable Local to Routine */
  2075. EPS_INT32 idx; /* General loop/index varaible */
  2076. EPS_ERR_CODE retStatus; /* Return status of internal calls */
  2077. EPS_INT32 factor; /* Scaling factor for dpi */
  2078. EPS_INT32 tempPrintableWidth;
  2079. EPS_INT32 tempPrintableHeight;
  2080. const EPS_MEDIA_INFO* pMI = NULL;
  2081. EPS_INT16 minCustomBorder;
  2082. EPS_LOG_FUNCIN;
  2083. /*** Has a Lib been initialized */
  2084. if (libStatus != EPS_STATUS_INITIALIZED) {
  2085. EPS_RETURN( EPS_ERR_LIB_NOT_INITIALIZED );
  2086. }
  2087. if(NULL == printJob.printer){
  2088. EPS_RETURN( EPS_ERR_PRINTER_NOT_SET );
  2089. }
  2090. /*** Validate input parameters */
  2091. if (jobAttr == NULL)
  2092. EPS_RETURN( EPS_ERR_INV_ARG_JOB_ATTRIB );
  2093. if (printableWidth == NULL)
  2094. EPS_RETURN( EPS_ERR_INV_ARG_PRINTABLE_WIDTH );
  2095. if (printableHeight == NULL)
  2096. EPS_RETURN( EPS_ERR_INV_ARG_PRINTABLE_HEIGHT );
  2097. /*** ESC/Page divergence ***/
  2098. if( EPS_LANG_ESCPR != printJob.printer->language ){
  2099. #ifdef GCOMSW_CMD_ESCPAGE
  2100. retStatus = pageGetPrintableArea(jobAttr, printableWidth, printableHeight);
  2101. #else
  2102. retStatus = EPS_ERR_LANGUAGE_NOT_SUPPORTED;
  2103. #endif
  2104. EPS_RETURN( retStatus );
  2105. }
  2106. /*** Initialize Local Variables */
  2107. retStatus = EPS_ERR_NONE;
  2108. /*** Validate/Confirm Page Attribute Data */
  2109. /*** Media Size */
  2110. if (! ( ( (jobAttr->mediaSizeIdx >= EPS_MSID_A4 ) &&
  2111. (jobAttr->mediaSizeIdx <= EPS_MSID_HIVISION ) ) ||
  2112. ( (jobAttr->mediaSizeIdx >= EPS_MSID_A3NOBI ) &&
  2113. (jobAttr->mediaSizeIdx <= EPS_MSID_12X12 ) ) ||
  2114. ( (jobAttr->mediaSizeIdx == EPS_MSID_USER ) ) ) )
  2115. EPS_RETURN( EPS_ERR_INV_MEDIA_SIZE );
  2116. #if 0 /* These parameter are not used in this function */
  2117. /*** Media Type */
  2118. if (! ( ( (jobAttr->mediaTypeIdx >= EPS_MTID_PLAIN ) &&
  2119. /* (jobAttr->mediaTypeIdx <= EPS_MTID_GLOSSYHAGAKI ) ) ||*/
  2120. (jobAttr->mediaTypeIdx <= EPS_MTID_BUSINESSCOAT ) ) ||
  2121. ( (jobAttr->mediaTypeIdx >= EPS_MTID_CDDVD ) &&
  2122. (jobAttr->mediaTypeIdx <= EPS_MTID_CDDVDGLOSSY ) ) ||
  2123. ( (jobAttr->mediaTypeIdx == EPS_MTID_CLEANING ) ) ) )
  2124. EPS_RETURN( EPS_ERR_INV_MEDIA_TYPE );
  2125. #endif
  2126. /*** Border Mode */
  2127. if (! ( (jobAttr->printLayout == EPS_MLID_BORDERLESS ) ||
  2128. (jobAttr->printLayout == EPS_MLID_BORDERS ) ||
  2129. (jobAttr->printLayout == EPS_MLID_CDLABEL ) ||
  2130. (jobAttr->printLayout == EPS_MLID_DIVIDE16 ) ||
  2131. (jobAttr->printLayout == EPS_MLID_CUSTOM ) ) )
  2132. EPS_RETURN( EPS_ERR_INV_BORDER_MODE );
  2133. #if 0 /* These parameter are not used in this function */
  2134. /*** Print Quality */
  2135. if (! ( (jobAttr->printQuality == EPS_MQID_DRAFT ) ||
  2136. (jobAttr->printQuality == EPS_MQID_NORMAL ) ||
  2137. (jobAttr->printQuality == EPS_MQID_HIGH ) ) )
  2138. EPS_RETURN( EPS_ERR_INV_PRINT_QUALITY );
  2139. /*** Color Mode */
  2140. if (! ( (jobAttr->colorMode == EPS_CM_COLOR ) ||
  2141. (jobAttr->colorMode == EPS_CM_MONOCHROME ) ) )
  2142. EPS_RETURN( EPS_ERR_INV_COLOR_MODE );
  2143. #endif
  2144. /*** Input Image Resolution */
  2145. /*** Select table and factor */
  2146. if(jobAttr->inputResolution == EPS_IR_360X360){
  2147. pMI = epsMediaSize;
  2148. factor = 1;
  2149. minCustomBorder = EPS_BORDERS_MARGIN_360;
  2150. } else if(jobAttr->inputResolution == EPS_IR_720X720){
  2151. pMI = epsMediaSize;
  2152. factor = 2;
  2153. minCustomBorder = EPS_BORDERS_MARGIN_360;
  2154. } else if(jobAttr->inputResolution == EPS_IR_300X300){
  2155. pMI = epsMediaSize300;
  2156. factor = 1;
  2157. minCustomBorder = EPS_BORDERS_MARGIN_300;
  2158. } else if(jobAttr->inputResolution == EPS_IR_600X600){
  2159. pMI = epsMediaSize300;
  2160. factor = 2;
  2161. minCustomBorder = EPS_BORDERS_MARGIN_300;
  2162. } else{
  2163. EPS_RETURN( EPS_ERR_INV_INPUT_RESOLUTION )
  2164. }
  2165. #if 0 /* These parameter are not used in this function */
  2166. /*** Printing Direction */
  2167. if (! ( (jobAttr->printDirection == EPS_PD_BIDIREC ) ||
  2168. (jobAttr->printDirection == EPS_PD_UNIDIREC ) ) )
  2169. EPS_RETURN( EPS_ERR_INV_PRINT_DIRECTION );
  2170. /*** Color Plane */
  2171. if (! ( (jobAttr->colorPlane == EPS_CP_FULLCOLOR ) ||
  2172. (jobAttr->colorPlane == EPS_CP_256COLOR ) ) )
  2173. EPS_RETURN( EPS_ERR_INV_COLOR_PLANE );
  2174. /*** Pallette Data */
  2175. if (jobAttr->colorPlane == EPS_CP_256COLOR) {
  2176. if (! ((jobAttr->paletteSize >= 3 ) &&
  2177. (jobAttr->paletteSize <= 768/*765*/ ) ) )
  2178. EPS_RETURN( EPS_ERR_INV_PALETTE_SIZE );
  2179. if ( jobAttr->paletteData == NULL )
  2180. EPS_RETURN( EPS_ERR_INV_PALETTE_DATA );
  2181. }
  2182. /*** Brightness */
  2183. if (! ( (jobAttr->brightness >= -50 ) &&
  2184. (jobAttr->brightness <= 50 ) ) )
  2185. EPS_RETURN( EPS_ERR_INV_BRIGHTNESS );
  2186. /*** Contrast */
  2187. if (! ( (jobAttr->contrast >= -50 ) &&
  2188. (jobAttr->contrast <= 50 ) ) )
  2189. EPS_RETURN( EPS_ERR_INV_CONTRAST );
  2190. /*** Saturation */
  2191. if (! ( (jobAttr->saturation >= -50 ) &&
  2192. (jobAttr->saturation <= 50 ) ) )
  2193. EPS_RETURN( EPS_ERR_INV_SATURATION );
  2194. #endif
  2195. /*** Margin */
  2196. if (jobAttr->printLayout == EPS_MLID_CUSTOM) {
  2197. if (jobAttr->topMargin < minCustomBorder*factor) EPS_RETURN( EPS_ERR_INV_TOP_MARGIN );
  2198. if (jobAttr->leftMargin < minCustomBorder*factor) EPS_RETURN( EPS_ERR_INV_LEFT_MARGIN );
  2199. if (jobAttr->bottomMargin < minCustomBorder*factor) EPS_RETURN( EPS_ERR_INV_BOTTOM_MARGIN );
  2200. if (jobAttr->rightMargin < minCustomBorder*factor) EPS_RETURN( EPS_ERR_INV_RIGHT_MARGIN );
  2201. }
  2202. #if 0 /* Don't need this logic */
  2203. /*** If full-color mode, nullify the 256-color parameters */
  2204. printJob.bpp = 1;
  2205. if (jobAttr->colorPlane == EPS_CP_FULLCOLOR) {
  2206. jobAttr->paletteSize = 0;
  2207. jobAttr->paletteData = NULL;
  2208. printJob.bpp = 3;
  2209. }
  2210. #endif
  2211. /*** Get Printable Area */
  2212. /*** Find the Media by ID */
  2213. for (idx = 0; pMI[idx].id != -1; idx++) {
  2214. if (pMI[idx].id == jobAttr->mediaSizeIdx)
  2215. break;
  2216. }
  2217. if (pMI[idx].id == -1) {
  2218. EPS_RETURN( EPS_ERR_INV_MEDIA_SIZE );
  2219. }
  2220. /*** Initialize Printable based on printLayout */
  2221. switch( jobAttr->printLayout ){
  2222. case EPS_MLID_BORDERLESS:
  2223. tempPrintableWidth = pMI[idx].print_area_x_borderless * factor;
  2224. tempPrintableHeight = pMI[idx].print_area_y_borderless * factor;
  2225. break;
  2226. case EPS_MLID_BORDERS:
  2227. case EPS_MLID_DIVIDE16: /* layout processing is not done. */
  2228. tempPrintableWidth = pMI[idx].print_area_x_border * factor;
  2229. tempPrintableHeight = pMI[idx].print_area_y_border * factor;
  2230. break;
  2231. case EPS_MLID_CDLABEL:
  2232. if( !( (jobAttr->cdDimOut >= EPS_CDDIM_IN_MIN )
  2233. && (jobAttr->cdDimOut <= EPS_CDDIM_OUT_MAX ) ) ){
  2234. EPS_RETURN( EPS_ERR_INV_CD_OUTDIM );
  2235. }
  2236. tempPrintableWidth =
  2237. tempPrintableHeight = elGetDots(jobAttr->inputResolution, jobAttr->cdDimOut);
  2238. break;
  2239. default: /* printLayout == EPS_MLID_CUSTOM */
  2240. tempPrintableWidth = pMI[idx].paper_x *factor -
  2241. jobAttr->leftMargin -
  2242. jobAttr->rightMargin;
  2243. tempPrintableHeight = pMI[idx].paper_y *factor -
  2244. jobAttr->topMargin -
  2245. jobAttr->bottomMargin;
  2246. }
  2247. /*** Validate/Confirm Magin Setting */
  2248. if (jobAttr->printLayout == EPS_MLID_CUSTOM) {
  2249. if (tempPrintableWidth <= 0) EPS_RETURN( EPS_ERR_MARGIN_OVER_PRINTABLE_WIDTH );
  2250. if (tempPrintableHeight <= 0) EPS_RETURN( EPS_ERR_MARGIN_OVER_PRINTABLE_HEIGHT );
  2251. }
  2252. /*** Set Printable Area to input parameter */
  2253. if ((tempPrintableWidth > 0) && (tempPrintableHeight > 0)) {
  2254. *printableWidth = (EPS_UINT32)tempPrintableWidth;
  2255. *printableHeight = (EPS_UINT32)tempPrintableHeight;
  2256. } else{
  2257. EPS_RETURN( EPS_ERR_OPR_FAIL );
  2258. }
  2259. /*** Return to Caller */
  2260. EPS_RETURN( EPS_ERR_NONE );
  2261. }
  2262. /*******************************************|********************************************/
  2263. /* */
  2264. /* Function name: epsMakeMainteCmd() */
  2265. /* */
  2266. /* Arguments */
  2267. /* --------- */
  2268. /* Name: Type: Description: */
  2269. /* cmd EPS_INT32 I:maintenance command type. */
  2270. /* buffer EPS_UINT8* I:pointer to command buffer. */
  2271. /* buffersize EPS_UINT32* I: buffer size. */
  2272. /* O: need size. */
  2273. /* */
  2274. /* Return value: */
  2275. /* << Normal >> */
  2276. /* EPS_ERR_NONE - Success */
  2277. /* << Error >> */
  2278. /* EPS_ERR_LIB_NOT_INITIALIZED - ESC/P-R Lib is NOT initialized */
  2279. /* EPS_ERR_INV_ARG_CMDTYPE - Invalid argument "cmd" */
  2280. /* EPS_ERR_OPR_FAIL - Internal Error */
  2281. /* EPS_ERR_MEMORY_ALLOCATION - Failed to allocate memory */
  2282. /* EPS_ERR_PRINTER_NOT_SET - Target printer is not specified */
  2283. /* EPS_ERR_LANGUAGE_NOT_SUPPORTED - Unsupported function Error (language) */
  2284. /* */
  2285. /* Description: */
  2286. /* Make maintenance command. */
  2287. /* Call this function as specifying NULL to buffer, so that the memory size */
  2288. /* necessary for executing the maintenance command is returned to buffersize. */
  2289. /* */
  2290. /*******************************************|********************************************/
  2291. EPS_ERR_CODE epsMakeMainteCmd (
  2292. EPS_INT32 cmd,
  2293. EPS_UINT8* buffer,
  2294. EPS_UINT32* buffersize
  2295. ){
  2296. #ifdef GCOMSW_EF_MAINTE
  2297. /*** Declare Variable Local to Routine */
  2298. EPS_ERR_CODE retStatus = EPS_ERR_NONE; /* Return status of internal calls */
  2299. EPS_UINT8 *pCmdBuf = NULL;
  2300. EPS_UINT8 *pCmdPos = NULL;
  2301. EPS_UINT32 cmdSize = 0;
  2302. EPS_UINT32 cmdBufSize = 0;
  2303. EPS_LOG_FUNCIN;
  2304. /*** Has a target printer specified */
  2305. if(NULL == printJob.printer){
  2306. EPS_RETURN( EPS_ERR_PRINTER_NOT_SET );
  2307. }
  2308. if(EPS_LANG_ESCPR != printJob.printer->language ){
  2309. EPS_RETURN( EPS_ERR_LANGUAGE_NOT_SUPPORTED );
  2310. }
  2311. if(buffer){
  2312. cmdBufSize = 256;
  2313. pCmdBuf = (EPS_UINT8*)EPS_ALLOC(cmdBufSize);
  2314. pCmdPos = pCmdBuf;
  2315. }
  2316. #define MakeMainteCmd_ADDCMD(CMD) { \
  2317. if(buffer){ \
  2318. retStatus = AddCmdBuff(&pCmdBuf, &pCmdPos, &cmdBufSize, CMD, sizeof(CMD)); \
  2319. if(EPS_ERR_NONE != retStatus){ \
  2320. goto epsMakeMainteCmd_END; \
  2321. } \
  2322. } \
  2323. cmdSize += sizeof(CMD); \
  2324. }
  2325. switch(cmd){
  2326. case EPS_MNT_NOZZLE: /* nozzle check */
  2327. MakeMainteCmd_ADDCMD(ExitPacketMode)
  2328. MakeMainteCmd_ADDCMD(InitPrinter)
  2329. MakeMainteCmd_ADDCMD(InitPrinter)
  2330. MakeMainteCmd_ADDCMD(EnterRemoteMode)
  2331. if(epsCmnFnc.getLocalTime){
  2332. MakeMainteCmd_ADDCMD(RemoteTI)
  2333. if( buffer ){
  2334. MakeRemoteTICmd(pCmdPos - sizeof(RemoteTI));
  2335. }
  2336. }
  2337. MakeMainteCmd_ADDCMD(RemoteJS)
  2338. MakeMainteCmd_ADDCMD(RemoteNC)
  2339. if(pCmdPos && obsIsA3Model(EPS_MDC_NOZZLE)){
  2340. *(pCmdPos - sizeof(RemoteNC) + 5) = 0x10;
  2341. }
  2342. MakeMainteCmd_ADDCMD(ExitRemoteMode)
  2343. MakeMainteCmd_ADDCMD(DataCR)
  2344. MakeMainteCmd_ADDCMD(DataLF)
  2345. MakeMainteCmd_ADDCMD(DataCR)
  2346. MakeMainteCmd_ADDCMD(DataLF)
  2347. MakeMainteCmd_ADDCMD(EnterRemoteMode)
  2348. MakeMainteCmd_ADDCMD(RemoteVI)
  2349. MakeMainteCmd_ADDCMD(RemoteLD)
  2350. MakeMainteCmd_ADDCMD(ExitRemoteMode)
  2351. MakeMainteCmd_ADDCMD(DataFF)
  2352. MakeMainteCmd_ADDCMD(InitPrinter)
  2353. MakeMainteCmd_ADDCMD(InitPrinter)
  2354. MakeMainteCmd_ADDCMD(EnterRemoteMode)
  2355. MakeMainteCmd_ADDCMD(RemoteJE)
  2356. MakeMainteCmd_ADDCMD(ExitRemoteMode)
  2357. break;
  2358. case EPS_MNT_CLEANING: /* head cleaning */
  2359. MakeMainteCmd_ADDCMD(ExitPacketMode)
  2360. MakeMainteCmd_ADDCMD(InitPrinter)
  2361. MakeMainteCmd_ADDCMD(InitPrinter)
  2362. MakeMainteCmd_ADDCMD(EnterRemoteMode)
  2363. if(epsCmnFnc.getLocalTime){
  2364. MakeMainteCmd_ADDCMD(RemoteTI)
  2365. if( buffer ){
  2366. MakeRemoteTICmd(pCmdPos - sizeof(RemoteTI));
  2367. }
  2368. }
  2369. MakeMainteCmd_ADDCMD(RemoteCH)
  2370. MakeMainteCmd_ADDCMD(ExitRemoteMode)
  2371. MakeMainteCmd_ADDCMD(InitPrinter)
  2372. MakeMainteCmd_ADDCMD(InitPrinter)
  2373. MakeMainteCmd_ADDCMD(EnterRemoteMode)
  2374. MakeMainteCmd_ADDCMD(RemoteJE)
  2375. MakeMainteCmd_ADDCMD(ExitRemoteMode)
  2376. break;
  2377. default:
  2378. retStatus = EPS_ERR_INV_CMDTYPE;
  2379. break;
  2380. }
  2381. epsMakeMainteCmd_END:
  2382. if(EPS_ERR_NONE == retStatus){
  2383. if( buffer ){
  2384. if(*buffersize > 0){
  2385. memcpy(buffer, pCmdBuf, Min(*buffersize, cmdSize));
  2386. }
  2387. }
  2388. *buffersize = cmdSize;
  2389. }
  2390. EPS_SAFE_RELEASE(pCmdBuf);
  2391. EPS_RETURN( retStatus );
  2392. #else
  2393. return EPS_ERR_INVALID_CALL;
  2394. #endif
  2395. }
  2396. /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%|%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
  2397. /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%|%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
  2398. /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%|%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
  2399. /*%%%%%%%%%%%%%%%%%%%% %%%%%%%%%%%%%%%%%%%%%*/
  2400. /*-------------------- Internal Processing ---------------------*/
  2401. /*-------------------- for ---------------------*/
  2402. /*-------------------- API ---------------------*/
  2403. /*%%%%%%%%%%%%%%%%%%%% %%%%%%%%%%%%%%%%%%%%%*/
  2404. /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%|%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
  2405. /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%|%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
  2406. /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%|%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
  2407. /*******************************************|********************************************/
  2408. /* */
  2409. /* Function name: MonitorStatus() */
  2410. /* */
  2411. /* Arguments */
  2412. /* --------- */
  2413. /* Name: Type: Description: */
  2414. /* pStInfo EPS_STATUS_INFO I: pointer to status info strucutre */
  2415. /* */
  2416. /* Return value: */
  2417. /* EPS_ERR_NONE - Printer settled into one of the requested state(s) */
  2418. /* EPS_JOB_CANCELED - Cancelled operation */
  2419. /* EPS_ERR_OPR_FAIL - Internal Error */
  2420. /* EPS_ERR_PRINTER_ERR_OCCUR - Printer Error happened */
  2421. /* */
  2422. /* Description: */
  2423. /* Monitor the status of the printer. */
  2424. /* */
  2425. /*******************************************|********************************************/
  2426. static EPS_ERR_CODE MonitorStatus (
  2427. EPS_STATUS_INFO *pStInfo
  2428. ){
  2429. /*** Declare Variable Local to Routine */
  2430. EPS_INT32 retStatus;
  2431. EPS_STATUS_INFO StatInfo;
  2432. EPS_LOG_FUNCIN;
  2433. /*** Initialize Local Variables */
  2434. retStatus = EPS_ERR_NONE;
  2435. memset(&StatInfo, -1, sizeof(EPS_STATUS_INFO));
  2436. retStatus = jobFnc.MonitorStatus(&StatInfo);
  2437. if ( retStatus != EPS_ERR_NONE) {
  2438. if(EPS_ERR_COMM_ERROR == retStatus &&
  2439. EPS_STATUS_NOT_INITIALIZED != printJob.jobStatus){
  2440. printJob.bComm = FALSE;
  2441. }
  2442. EPS_DBGPRINT(("EPS SER: STAT MON -> Status Retr Failed. [%d]\r\n", retStatus));
  2443. EPS_RETURN( retStatus );
  2444. }
  2445. if( pStInfo ){
  2446. memcpy(pStInfo, &StatInfo, sizeof(EPS_STATUS_INFO));
  2447. }
  2448. if(EPS_ST_ERROR == StatInfo.nState && EPS_PRNERR_PAPERJAM == StatInfo.nError){
  2449. printJob.transmittable = FALSE;
  2450. }
  2451. if(StatInfo.nCancel == EPS_CAREQ_CANCEL) {
  2452. EPS_DBGPRINT(("EPS SER : CANCEL REQUEST by PRINTER\r\n"));
  2453. printJob.resetReq = TRUE;
  2454. EPS_RETURN( EPS_JOB_CANCELED );
  2455. }
  2456. /* EPS_DBGPRINT(("M State\t: %d\n Error\t: %d\n Prepare\t: %d\n",
  2457. StatInfo.nState, StatInfo.nError, StatInfo.nPrepare))
  2458. */
  2459. /* The error occurs in printer. */
  2460. printJob.contData.lastError = StatInfo.nError;
  2461. /*EPS_DBGPRINT(("EPS SER: STAT MON -> Printer State [0x%x]\r\n",StatInfo.nState));*/
  2462. if( StatInfo.nState & ( EPS_ST_IDLE |
  2463. EPS_ST_WAITING |
  2464. EPS_ST_SELF_PRINTING |
  2465. EPS_ST_CLEANING ) ){
  2466. /*EPS_DBGPRINT(("EPS SER: STAT MON -> SETTLING\r\n"));*/
  2467. EPS_RETURN( EPS_ERR_NONE );
  2468. }else{
  2469. EPS_RETURN( EPS_ERR_PRINTER_ERR_OCCUR );
  2470. }
  2471. }
  2472. /*******************************************|********************************************/
  2473. /* */
  2474. /* Function name: PrintBand() */
  2475. /* */
  2476. /* Arguments */
  2477. /* --------- */
  2478. /* Name: Type: Description: */
  2479. /* data EPS_UINT8* I: Pointer to image [RGB] data */
  2480. /* widthPixels EPS_UINT32 I: The width of the raster band (in pixels) */
  2481. /* heightPixels EPS_UINT32* I/O: In : Height of image (image lines) (in pixels)*/
  2482. /* : Out: Sent Height */
  2483. /* */
  2484. /* Return value: */
  2485. /* << Normal >> */
  2486. /* EPS_ERR_NONE - Success */
  2487. /* EPS_JOB_CANCELED - Cancelled operation by user */
  2488. /* (Do not return when Uni-Directional) */
  2489. /* EPS_OUT_OF_BOUNDS - Print band is in out of printable area */
  2490. /* << Error >> */
  2491. /* EPS_ERR_PRINTER_ERR_OCCUR - Printer Error happened */
  2492. /* EPS_ERR_INV_ARG_WIDTH_PIXELS - Invalid argument "widthPixels" */
  2493. /* EPS_ERR_INV_ARG_HEIGHT_PIXELS - Invalid argument "heightPixels" */
  2494. /* EPS_ERR_OPR_FAIL - Internal Error */
  2495. /* EPS_ERR_MEMORY_ALLOCATION - Failed to allocate memory */
  2496. /* */
  2497. /* Description: */
  2498. /* Prints a band of raster data. */
  2499. /* It must be noted that this function automatically positions the raster bands; */
  2500. /* all subsequent raster bands after the first one are positioned directly */
  2501. /* underneath the preceding band. */
  2502. /* Horizontal orientation of the raster bands never changes. */
  2503. /* */
  2504. /*******************************************|********************************************/
  2505. EPS_ERR_CODE PrintBand (
  2506. const EPS_UINT8* data, /* Pointer to image [RGB] data */
  2507. EPS_UINT32 widthPixels, /* Width of image [ in pixels ] */
  2508. EPS_UINT32 *heightPixels /* Height of image (image lines) */
  2509. ) {
  2510. /*** Declare Variable Local to Routine */
  2511. EPS_ERR_CODE retStatus;
  2512. EPS_UINT32 idx = 0; /* Generl loop/index variable */
  2513. EPS_IMAGE line; /* Single line of image data */
  2514. const EPS_UINT8* tmpImageData; /* Temporary image pointer */
  2515. EPS_BOOL skipLine; /* Flag to skip or print current image line */
  2516. EPS_UINT32 linePixels;
  2517. EPS_UINT32 sendHeight;
  2518. EPS_LOG_FUNCIN;
  2519. if( NULL == data ){
  2520. EPS_RETURN( EPS_ERR_INV_ARG_DATA );
  2521. }
  2522. if(NULL == heightPixels){
  2523. EPS_RETURN( EPS_ERR_INV_ARG_HEIGHT_PIXELS );
  2524. }
  2525. if(*heightPixels == 0){
  2526. EPS_RETURN( EPS_ERR_INV_ARG_HEIGHT_PIXELS );
  2527. }
  2528. sendHeight = *heightPixels;
  2529. *heightPixels = 0;
  2530. if( widthPixels == 0 ){
  2531. EPS_RETURN( EPS_ERR_INV_ARG_WIDTH_PIXELS );
  2532. }
  2533. /*** Initialize Local Variables */
  2534. retStatus = EPS_ERR_NONE;
  2535. if( printJob.printableAreaHeight <= (EPS_UINT32)printJob.verticalOffset ){
  2536. /*** Return to Caller */
  2537. EPS_RETURN( EPS_OUT_OF_BOUNDS );
  2538. }
  2539. /*** Clip number is image lines if too many */
  2540. if (sendHeight > (printJob.printableAreaHeight - printJob.verticalOffset)){
  2541. sendHeight = printJob.printableAreaHeight - printJob.verticalOffset;
  2542. }
  2543. /*** Send leftovers of last time And Skip first line of input data */
  2544. idx = 0; /* Initialize line counter */
  2545. /*** Send leftovers data */
  2546. retStatus = SendLeftovers();
  2547. if(EPS_ERR_INVALID_CALL == retStatus){ /* It was unnecessary */
  2548. retStatus = EPS_ERR_NONE;
  2549. if(printJob.contData.skipLine == TRUE){
  2550. idx++; /* skip first line of input data */
  2551. printJob.contData.skipLine = FALSE;
  2552. }
  2553. } else if(EPS_ERR_NONE == retStatus){ /* Sent leftovers */
  2554. idx++; /* skip first line of input data */
  2555. } else{
  2556. EPS_RETURN( retStatus );
  2557. }
  2558. /*** The following section of code forces the core module to skip raster lines that are */
  2559. /*** completely white in order to minimize data size. This function is compatible with */
  2560. /*** 8-bit palettized and 24-bit RGB bitmaps. */
  2561. /*** ---------------------------------------------------------------------------------- */
  2562. /*** Initialize variable */
  2563. line.bytesPerLine = printJob.bpp * widthPixels;
  2564. linePixels = Min(line.bytesPerLine, printJob.bpp * printJob.printableAreaWidth);
  2565. for (; idx < sendHeight; idx++) {
  2566. /* Calculate position of image line */
  2567. //if(idx == 1){
  2568. //idx = sendHeight;
  2569. //break;
  2570. //}
  2571. line.data = data + idx * line.bytesPerLine;
  2572. /*** Make new LineRect */
  2573. line.rect.top = (EPS_INT32)(printJob.verticalOffset + idx);
  2574. line.rect.left = 0;
  2575. line.rect.bottom = line.rect.top + 1;
  2576. line.rect.right = (EPS_INT32)(widthPixels);
  2577. /*** Test if current image data is completely white */
  2578. if(EPS_LANG_ESCPR == printJob.printer->language ){
  2579. skipLine = TRUE;
  2580. } else{
  2581. skipLine = FALSE; /* esc/page need anything band */
  2582. }
  2583. /* skip blank band for ESC/P-R */
  2584. /* check blank page for duplex */
  2585. if( EPS_LANG_ESCPR == printJob.printer->language ||
  2586. (EPS_DUPLEX_NONE != printJob.attr.duplex && printJob.needBand) )
  2587. {
  2588. for (tmpImageData = line.data;
  2589. tmpImageData < (line.data + linePixels);
  2590. tmpImageData++ ) {
  2591. if(*tmpImageData != printJob.whiteColorValue) {
  2592. skipLine = FALSE;
  2593. printJob.needBand = FALSE;
  2594. break;
  2595. }
  2596. }
  2597. if (skipLine == TRUE)continue;
  2598. }
  2599. /*** Image Data not completely white - print image data */
  2600. //idx = sendHeight;
  2601. //break;
  2602. retStatus = PrintLine(&line);
  2603. if (retStatus != EPS_ERR_NONE) {
  2604. break;
  2605. }
  2606. }
  2607. /*** band positioning adds */
  2608. printJob.verticalOffset += idx;
  2609. /*** Return to Caller */
  2610. *heightPixels = idx;
  2611. EPS_RETURN( retStatus );
  2612. }
  2613. /*******************************************|********************************************/
  2614. /* */
  2615. /* Function name: PrintChunk() */
  2616. /* */
  2617. /* Arguments */
  2618. /* --------- */
  2619. /* Name: Type: Description: */
  2620. /* data EPS_UINT8* I: Pointer to image [RGB] data */
  2621. /* dataSize EPS_UINT32* I/O: In : size of image */
  2622. /* : Out: Sent size */
  2623. /* */
  2624. /* Return value: */
  2625. /* << Normal >> */
  2626. /* EPS_ERR_NONE - Success */
  2627. /* EPS_JOB_CANCELED - Cancelled operation by user */
  2628. /* (Do not return when Uni-Directional) */
  2629. /* EPS_OUT_OF_BOUNDS - Print band is in out of printable area */
  2630. /* << Error >> */
  2631. /* EPS_ERR_PRINTER_ERR_OCCUR - Printer Error happened */
  2632. /* EPS_ERR_INV_ARG_HEIGHT_PIXELS - Invalid argument "heightPixels" */
  2633. /* EPS_ERR_INV_ARG_DATASIZE - data size limit */
  2634. /* EPS_ERR_OPR_FAIL - Internal Error */
  2635. /* EPS_ERR_MEMORY_ALLOCATION - Failed to allocate memory */
  2636. /* */
  2637. /* Description: */
  2638. /* Prints Jpeg file data. */
  2639. /* */
  2640. /*******************************************|********************************************/
  2641. EPS_ERR_CODE PrintChunk (
  2642. const EPS_UINT8* data, /* Pointer to image [JPEG] data */
  2643. EPS_UINT32* dataSize /* size of image (chunked data) */
  2644. ) {
  2645. /*** Declare Variable Local to Routine */
  2646. EPS_ERR_CODE retStatus = EPS_ERR_NONE;
  2647. EPS_UINT32 sendSize = 0;
  2648. EPS_UINT32 retBufSize = 0;
  2649. EPS_INT32 cmdBuffSize = ESCPR_HEADER_LENGTH + ESCPR_SEND_JPGDATA_LENGTH;
  2650. EPS_UINT8* bufPtr = NULL; /* Temporary buffer pointer */
  2651. EPS_INT32 paramSize = 0; /* Size of command parameters only */
  2652. EPS_INT32 i = 0;
  2653. #define DUMMY_DATA_COUNT (1000)
  2654. EPS_LOG_FUNCIN;
  2655. /*** Validate input parameters */
  2656. if(NULL == dataSize){
  2657. EPS_RETURN( EPS_ERR_INV_ARG_HEIGHT_PIXELS );
  2658. }
  2659. #if LCOMSW_DUMMY_SEND
  2660. if( *dataSize == 0 &&
  2661. (EPS_PROTOCOL_USB & printJob.printer->protocol) ){
  2662. /* USB not peform */
  2663. EPS_RETURN( EPS_ERR_NONE );
  2664. }
  2665. #else
  2666. if( NULL == data ){
  2667. EPS_RETURN( EPS_ERR_INV_ARG_DATA );
  2668. }
  2669. if(*dataSize == 0){
  2670. EPS_RETURN( EPS_ERR_INV_ARG_HEIGHT_PIXELS );
  2671. }
  2672. #endif
  2673. sendSize = *dataSize;
  2674. *dataSize = 0;
  2675. #if !_VALIDATE_SUPPORTED_MEDIA_DATA_
  2676. if( EPS_JPEG_CHUNK_SIZE_MAX < sendSize){
  2677. *dataSize = 0;
  2678. EPS_RETURN( EPS_ERR_INV_ARG_DATASIZE );
  2679. }
  2680. if( (EPS_UINT32)printJob.printer->JpgMax < printJob.jpegSize + sendSize){
  2681. printJob.bJpgLimit = TRUE;
  2682. EPS_RETURN( EPS_ERR_INV_ARG_DATASIZE );
  2683. }
  2684. #endif
  2685. /************************************************************************************/
  2686. /*** Send last time leftovers data */
  2687. /*** Header */
  2688. retStatus = SendLeftovers();
  2689. if(EPS_ERR_INVALID_CALL == retStatus){ /* It was unnecessary */
  2690. retStatus = EPS_ERR_NONE;
  2691. } else if(EPS_ERR_NONE != retStatus){
  2692. *dataSize = 0;
  2693. EPS_RETURN( retStatus );
  2694. }
  2695. /*** Data */
  2696. if(0 < printJob.contData.jpgSize){
  2697. retBufSize = 0;
  2698. retStatus = SendCommand(data,
  2699. Min(printJob.contData.jpgSize, sendSize),
  2700. &retBufSize, FALSE); /* not save Leftovers */
  2701. printJob.contData.jpgSize -= retBufSize;
  2702. *dataSize = retBufSize;
  2703. printJob.jpegSize += retBufSize; /* add total size */
  2704. if( EPS_ERR_NONE != retStatus ){
  2705. EPS_RETURN( retStatus );
  2706. }
  2707. sendSize -= retBufSize;
  2708. if(0 >= sendSize ){
  2709. EPS_RETURN( EPS_ERR_NONE );
  2710. }
  2711. data += retBufSize;
  2712. }
  2713. /************************************************************************************/
  2714. /*** Send this time data */
  2715. /*** Header */
  2716. printJob.contData.jpgSize = sendSize;
  2717. #if !LCOMSW_DUMMY_SEND
  2718. EPS_MEM_GROW(EPS_UINT8*, sendDataBuf, &sendDataBufSize, ESCPR_JPGHEAD_LENGTH )
  2719. #else
  2720. if(0 < sendSize){
  2721. EPS_MEM_GROW(EPS_UINT8*, sendDataBuf, &sendDataBufSize, ESCPR_JPGHEAD_LENGTH )
  2722. } else{
  2723. EPS_MEM_GROW(EPS_UINT8*, sendDataBuf, &sendDataBufSize, ESCPR_JPGHEAD_LENGTH * DUMMY_DATA_COUNT )
  2724. }
  2725. #endif
  2726. if(NULL == sendDataBuf){
  2727. sendDataBufSize = 0;
  2728. EPS_RETURN( EPS_ERR_MEMORY_ALLOCATION )
  2729. }
  2730. bufPtr = sendDataBuf;
  2731. memcpy(bufPtr, SendDataCmd, sizeof(SendDataCmd));
  2732. bufPtr += sizeof(SendDataCmd);
  2733. paramSize = ESCPR_SEND_JPGDATA_LENGTH + sendSize;
  2734. memSetEndian(EPS_ENDIAN_LITTLE, EPS_4_BYTES, (EPS_UINT32)paramSize, bufPtr);
  2735. bufPtr += 4;
  2736. memcpy(bufPtr, SendJpegDataName, sizeof(SendJpegDataName));
  2737. bufPtr += sizeof(SendJpegDataName);
  2738. memSetEndian(EPS_ENDIAN_BIG, EPS_2_BYTES, sendSize, bufPtr);
  2739. if(0 < sendSize){
  2740. retBufSize = 0;
  2741. retStatus = SendCommand(sendDataBuf, cmdBuffSize, &retBufSize, TRUE);/* save Leftovers */
  2742. if( EPS_ERR_NONE != retStatus ){
  2743. EPS_RETURN( retStatus );
  2744. }
  2745. /*** Data */
  2746. retBufSize = 0;
  2747. retStatus = SendCommand(data, sendSize, &retBufSize, FALSE); /* NOT save Leftovers */
  2748. *dataSize += retBufSize;
  2749. printJob.contData.jpgSize -= retBufSize;
  2750. printJob.jpegSize += retBufSize; /* add total size */
  2751. } else {
  2752. /*** dummy data */
  2753. bufPtr = sendDataBuf + cmdBuffSize;
  2754. for(i=1; i < DUMMY_DATA_COUNT; i++){ /* 12x1000 byte */
  2755. memcpy(bufPtr, sendDataBuf, cmdBuffSize);
  2756. bufPtr += cmdBuffSize;
  2757. }
  2758. retStatus = SendCommand(sendDataBuf, ESCPR_JPGHEAD_LENGTH * DUMMY_DATA_COUNT, &retBufSize, TRUE);/* save Leftovers */
  2759. }
  2760. EPS_RETURN( retStatus );
  2761. }
  2762. /*******************************************|********************************************/
  2763. /* */
  2764. /* Function name: SendLeftovers() */
  2765. /* */
  2766. /* Arguments */
  2767. /* --------- */
  2768. /* Name: Type: Description: */
  2769. /* nStartStep EPS_INT32 I: Step of Start Page comannds */
  2770. /* */
  2771. /* Return value: */
  2772. /* << Normal >> */
  2773. /* EPS_ERR_NONE - Success */
  2774. /* EPS_ERR_INVALID_CALL - This call was unnecessary */
  2775. /* EPS_JOB_CANCELED - Cancelled operation by user */
  2776. /* (Do not return when Uni-Directional) */
  2777. /* << Error >> */
  2778. /* EPS_ERR_OPR_FAIL - Internal Error */
  2779. /* EPS_ERR_COMM_ERROR - Communication Error */
  2780. /* EPS_ERR_PRINTER_ERR_OCCUR - Printer Error happened */
  2781. /* */
  2782. /* Description: */
  2783. /* send leftovers data. */
  2784. /* */
  2785. /*******************************************|********************************************/
  2786. static EPS_ERR_CODE SendLeftovers (
  2787. void
  2788. ){
  2789. EPS_ERR_CODE retStatus = EPS_ERR_NONE; /* Return status of internal calls */
  2790. EPS_UINT32 retBufSize = 0;
  2791. EPS_LOG_FUNCIN;
  2792. /*** send leftovers */
  2793. #ifdef GCOMSW_CMD_ESCPAGE
  2794. if(EPS_LANG_ESCPR == printJob.printer->language ){
  2795. #endif
  2796. /*** ESC/P-R ***/
  2797. if( NULL != printJob.contData.sendData && 0 < printJob.contData.sendDataSize){
  2798. retStatus = SendCommand(printJob.contData.sendData,
  2799. printJob.contData.sendDataSize, &retBufSize, TRUE);
  2800. } else{
  2801. retStatus = EPS_ERR_INVALID_CALL;
  2802. }
  2803. #ifdef GCOMSW_CMD_ESCPAGE
  2804. } else{
  2805. /*** ESC/Page ***/
  2806. retStatus = pageSendLeftovers();
  2807. }
  2808. #endif
  2809. EPS_RETURN( retStatus );
  2810. }
  2811. /*******************************************|********************************************/
  2812. /* */
  2813. /* Function name: SendBlankBand() */
  2814. /* */
  2815. /* Arguments */
  2816. /* --------- */
  2817. /* Name: Type: Description: */
  2818. /* nStartStep EPS_INT32 I: Step of Start Page comannds */
  2819. /* */
  2820. /* Return value: */
  2821. /* << Normal >> */
  2822. /* EPS_ERR_NONE - Success */
  2823. /* EPS_JOB_CANCELED - Cancelled operation by user */
  2824. /* (Do not return when Uni-Directional) */
  2825. /* << Error >> */
  2826. /* EPS_ERR_OPR_FAIL - Internal Error */
  2827. /* EPS_ERR_COMM_ERROR - Communication Error */
  2828. /* EPS_ERR_PRINTER_ERR_OCCUR - Printer Error happened */
  2829. /* */
  2830. /* Description: */
  2831. /* send leftovers data. */
  2832. /* */
  2833. /*******************************************|********************************************/
  2834. static EPS_ERR_CODE SendBlankBand (
  2835. void
  2836. ){
  2837. EPS_ERR_CODE retStatus = EPS_ERR_NONE; /* Return status of internal calls */
  2838. EPS_UINT8 pix[3*16]; /* 16=ESC/Page24 minimum unit */
  2839. EPS_IMAGE line;
  2840. EPS_LOG_FUNCIN;
  2841. #ifdef GCOMSW_CMD_ESCPAGE_S
  2842. if(EPS_LANG_ESCPAGE_S == printJob.printer->language){
  2843. EPS_RETURN( EPS_ERR_NONE );
  2844. }
  2845. #endif
  2846. if(EPS_CP_FULLCOLOR == printJob.attr.colorPlane){
  2847. memset(pix, 0xFF, sizeof(pix)); /* white */
  2848. if(EPS_LANG_ESCPAGE == printJob.printer->language ||
  2849. EPS_LANG_ESCPAGE_COLOR == printJob.printer->language)
  2850. {
  2851. memset(pix, 0x00, 3); /* black dot */
  2852. }
  2853. } else{
  2854. memset(pix, printJob.whiteColorValue, sizeof(pix));
  2855. if(EPS_LANG_ESCPAGE == printJob.printer->language ||
  2856. EPS_LANG_ESCPAGE_COLOR == printJob.printer->language)
  2857. {
  2858. if(printJob.whiteColorValue != 0){
  2859. memset(pix, 0, sizeof(pix));
  2860. } else{
  2861. memset(pix, 1, sizeof(pix));
  2862. }
  2863. }
  2864. }
  2865. line.data = pix;
  2866. line.bytesPerLine = printJob.bpp;
  2867. line.rect.top = 0;
  2868. line.rect.left = 0;
  2869. line.rect.bottom = 1;
  2870. if(EPS_LANG_ESCPR == printJob.printer->language ||
  2871. EPS_CP_256COLOR == printJob.attr.colorPlane ){
  2872. line.rect.right= 1;
  2873. } else{
  2874. line.rect.right= 16;
  2875. }
  2876. retStatus = PrintLine(&line);
  2877. EPS_RETURN( retStatus );
  2878. }
  2879. /*******************************************|********************************************/
  2880. /* */
  2881. /* Function name: SetupJobAttrib() */
  2882. /* */
  2883. /* Arguments */
  2884. /* --------- */
  2885. /* Name: Type: Description: */
  2886. /* jobAttr EPS_JOB_ATTRIB* I: Data structure containing job attribut settings */
  2887. /* */
  2888. /* Return value: */
  2889. /* << Normal >> */
  2890. /* EPS_ERR_NONE - Success */
  2891. /* << Error >> */
  2892. /* EPS_ERR_INV_COLOR_PLANE - Invalid Color Plane */
  2893. /* EPS_ERR_INV_PALETTE_SIZE - Invalid Palette Size */
  2894. /* EPS_ERR_INV_PALETTE_DATA - Invalid Palette Data */
  2895. /* EPS_ERR_INV_MEDIA_SIZE - Invalid Media Size */
  2896. /* EPS_ERR_INV_MEDIA_TYPE - Invalid Media Type */
  2897. /* EPS_ERR_INV_BORDER_MODE - Invalid Border Mode */
  2898. /* EPS_ERR_INV_PRINT_QUALITY - Invalid Print Quality */
  2899. /* EPS_ERR_INV_PAPER_SOURCE - Invalid Paper source */
  2900. /* EPS_ERR_INV_COLOR_MODE - Invalid Color Mode */
  2901. /* EPS_ERR_INV_INPUT_RESOLUTION - Invalid Input Resolution */
  2902. /* EPS_ERR_INV_PRINT_DIRECTION - Invalid Print Direction */
  2903. /* EPS_ERR_INV_BRIGHTNESS - Invalid Brightness */
  2904. /* EPS_ERR_INV_CONTRAST - Invalid Contrast */
  2905. /* EPS_ERR_INV_SATURATION - Invalid Saturation */
  2906. /* EPS_ERR_INV_APF_FLT - Invalid APF Filter */
  2907. /* EPS_ERR_INV_APF_ACT - Invalid APF Scene */
  2908. /* EPS_ERR_INV_APF_SHP - Invalid APF Sharpness */
  2909. /* EPS_ERR_INV_APF_RDE - Invalid APF Redeye */
  2910. /* EPS_ERR_INV_TOP_MARGIN - Invalid Top Magirn */
  2911. /* EPS_ERR_INV_LEFT_MARGIN - Invalid Left Margin */
  2912. /* EPS_ERR_INV_BOTTOM_MARGIN - Invalid Bottom Margin */
  2913. /* EPS_ERR_INV_RIGHT_MARGIN - Invalid Right Margin */
  2914. /* EPS_ERR_MARGIN_OVER_PRINTABLE_WIDTH - Invalid Magin Setting (Width) */
  2915. /* EPS_ERR_MARGIN_OVER_PRINTABLE_HEIGHT - Invalid Magin Setting (Height) */
  2916. /* */
  2917. /* Description: */
  2918. /* Confirm ESC/P-R Job Attribute. */
  2919. /* */
  2920. /*******************************************|********************************************/
  2921. EPS_ERR_CODE SetupJobAttrib (
  2922. const EPS_JOB_ATTRIB* jobAttr /* Print Attributes for this Page */
  2923. ){
  2924. EPS_ERR_CODE retStatus = EPS_ERR_NONE; /* Return status of internal calls */
  2925. EPS_LOG_FUNCIN;
  2926. /*** Validate input parameters */
  2927. #ifndef LCOMSW_JOBPARAM_CEHCK_OFF
  2928. /*======================================================================================*/
  2929. /*** Validate/Confirm Page Attribute Data */
  2930. /*======================================================================================*/
  2931. /*** Color Plane */
  2932. if (! ( (jobAttr->colorPlane == EPS_CP_FULLCOLOR ) ||
  2933. (jobAttr->colorPlane == EPS_CP_256COLOR ) ||
  2934. (jobAttr->colorPlane == EPS_CP_JPEG ) ||
  2935. (jobAttr->colorPlane == EPS_CP_PRINTCMD ) ) ){
  2936. EPS_RETURN( EPS_ERR_INV_COLOR_PLANE )
  2937. }
  2938. if( EPS_CP_PRINTCMD == jobAttr->colorPlane ){ /* Print command */
  2939. /*** Structure version */
  2940. if(EPS_JOB_ATTRIB_VER_2 > jobAttr->version){
  2941. EPS_RETURN( EPS_ERR_INVALID_VERSION )
  2942. }
  2943. /*** Print command type */
  2944. if (! ( (jobAttr->cmdType == EPS_MNT_CUSTOM ) ||
  2945. (jobAttr->cmdType == EPS_MNT_CLEANING ) ||
  2946. (jobAttr->cmdType == EPS_MNT_NOZZLE ) ) ){
  2947. EPS_RETURN( EPS_ERR_INV_CMDTYPE )
  2948. }
  2949. } else{ /* Image(RGB, Jpeg) */
  2950. /*** Media Size */
  2951. if (! ( ( (jobAttr->mediaSizeIdx >= EPS_MSID_A4 ) &&
  2952. (jobAttr->mediaSizeIdx <= EPS_MSID_HIVISION ) ) ||
  2953. ( (jobAttr->mediaSizeIdx >= EPS_MSID_A3NOBI ) &&
  2954. (jobAttr->mediaSizeIdx <= EPS_MSID_12X12 ) ) ||
  2955. ( (jobAttr->mediaSizeIdx == EPS_MSID_USER ) ) ) ){
  2956. EPS_RETURN( EPS_ERR_INV_MEDIA_SIZE )
  2957. }
  2958. /*** Media Type */
  2959. if (! ( ( (jobAttr->mediaTypeIdx >= EPS_MTID_PLAIN ) &&
  2960. /* (jobAttr->mediaTypeIdx <= EPS_MTID_GLOSSYHAGAKI ) ) ||*/
  2961. (jobAttr->mediaTypeIdx <= EPS_MTID_BUSINESSCOAT ) ) ||
  2962. ( (jobAttr->mediaTypeIdx >= EPS_MTID_CDDVD ) &&
  2963. (jobAttr->mediaTypeIdx <= EPS_MTID_CDDVDGLOSSY ) ) ||
  2964. ( (jobAttr->mediaTypeIdx == EPS_MTID_CLEANING ) ) ) ){
  2965. EPS_RETURN( EPS_ERR_INV_MEDIA_TYPE )
  2966. }
  2967. /*** Print Quality */
  2968. if (! ( (jobAttr->printQuality == EPS_MQID_DRAFT ) ||
  2969. (jobAttr->printQuality == EPS_MQID_NORMAL ) ||
  2970. (jobAttr->printQuality == EPS_MQID_HIGH ) ) ){
  2971. EPS_RETURN( EPS_ERR_INV_PRINT_QUALITY )
  2972. }
  2973. /*** duplex */
  2974. if( !( (jobAttr->duplex == EPS_DUPLEX_NONE ) ||
  2975. (jobAttr->duplex == EPS_DUPLEX_LONG ) ||
  2976. (jobAttr->duplex == EPS_DUPLEX_SHORT ) ) ){
  2977. EPS_RETURN( EPS_ERR_INV_DUPLEX )
  2978. }
  2979. /*** Brightness */
  2980. if (! ( (jobAttr->brightness >= -50 ) &&
  2981. (jobAttr->brightness <= 50 ) ) ){
  2982. EPS_RETURN( EPS_ERR_INV_BRIGHTNESS )
  2983. }
  2984. /*** Contrast */
  2985. if (! ( (jobAttr->contrast >= -50 ) &&
  2986. (jobAttr->contrast <= 50 ) ) ){
  2987. EPS_RETURN( EPS_ERR_INV_CONTRAST )
  2988. }
  2989. /*** Saturation */
  2990. if (! ( (jobAttr->saturation >= -50 ) &&
  2991. (jobAttr->saturation <= 50 ) ) ){
  2992. EPS_RETURN( EPS_ERR_INV_SATURATION )
  2993. }
  2994. /*** Paper Source */
  2995. if (! ( (jobAttr->paperSource == EPS_MPID_AUTO ) ||
  2996. (jobAttr->paperSource == EPS_MPID_REAR ) ||
  2997. (jobAttr->paperSource == EPS_MPID_FRONT1 ) ||
  2998. (jobAttr->paperSource == EPS_MPID_FRONT2 ) ||
  2999. (jobAttr->paperSource == EPS_MPID_FRONT3 ) ||
  3000. (jobAttr->paperSource == EPS_MPID_FRONT4 ) ||
  3001. (jobAttr->paperSource == EPS_MPID_CDTRAY ) ||
  3002. (jobAttr->paperSource == EPS_MPID_PAGE_S_MP_TRAY ) ||
  3003. (jobAttr->paperSource == EPS_MPID_PAGE_S_CASSETTE1 ) ||
  3004. (jobAttr->paperSource == EPS_MPID_PAGE_S_CASSETTE2 ) ||
  3005. (jobAttr->paperSource == EPS_MPID_PAGE_S_CASSETTE3 ) ||
  3006. (jobAttr->paperSource == EPS_MPID_PAGE_S_CASSETTE4 ) ||
  3007. (jobAttr->paperSource == EPS_MPID_PAGE_S_PARAM_MANUALFEED ) ||
  3008. (jobAttr->paperSource == EPS_MPID_PAGE_S_AUTO_TRAY )
  3009. ) ){
  3010. EPS_RETURN( EPS_ERR_INV_PAPER_SOURCE )
  3011. }
  3012. if(jobAttr->printLayout == EPS_MLID_CDLABEL){
  3013. /*** CD Inside Diameter */
  3014. if( !( (jobAttr->cdDimIn >= EPS_CDDIM_IN_MIN )
  3015. && (jobAttr->cdDimIn <= EPS_CDDIM_IN_MAX ) ) ){
  3016. EPS_RETURN( EPS_ERR_INV_CD_INDIM )
  3017. }
  3018. /*** CD Outside Diameter */
  3019. if( !( (jobAttr->cdDimOut >= EPS_CDDIM_OUT_MIN )
  3020. && (jobAttr->cdDimOut <= EPS_CDDIM_OUT_MAX ) ) ){
  3021. EPS_RETURN( EPS_ERR_INV_CD_OUTDIM )
  3022. }
  3023. }
  3024. if( EPS_CP_JPEG == jobAttr->colorPlane ){
  3025. if( jobAttr->duplex != EPS_DUPLEX_NONE ){
  3026. EPS_RETURN( EPS_ERR_INV_DUPLEX )
  3027. }
  3028. }
  3029. }
  3030. #endif
  3031. /*======================================================================================*/
  3032. /*** Copy Input Page Attribute Data to Internal Variable */
  3033. /*======================================================================================*/
  3034. switch( jobAttr->colorPlane ){
  3035. case EPS_CP_FULLCOLOR: /* RGB */
  3036. case EPS_CP_256COLOR:
  3037. memcpy((void*)(&printJob.attr), (void*)jobAttr, sizeof(EPS_JOB_ATTRIB));
  3038. retStatus = SetupRGBAttrib();
  3039. if(EPS_ERR_NONE == retStatus){
  3040. _SP_ChangeSpec_DraftOnly(printJob.printer, &printJob.attr);
  3041. /* Ignore the return value of this func */
  3042. }
  3043. break;
  3044. case EPS_CP_JPEG: /* Jpeg */
  3045. memcpy((void*)(&printJob.attr), (void*)jobAttr, sizeof(EPS_JOB_ATTRIB));
  3046. retStatus = SetupJPGAttrib();
  3047. if(EPS_ERR_NONE == retStatus){
  3048. _SP_ChangeSpec_DraftOnly(printJob.printer, &printJob.attr);
  3049. /* Ignore the return value of this func */
  3050. }
  3051. break;
  3052. case EPS_CP_PRINTCMD: /* Print command */
  3053. default:
  3054. memset((void*)(&printJob.attr), 0, sizeof(EPS_JOB_ATTRIB));
  3055. printJob.attr.colorPlane = jobAttr->colorPlane;
  3056. printJob.attr.cmdType = jobAttr->cmdType;
  3057. break;
  3058. }
  3059. EPS_RETURN( retStatus )
  3060. }
  3061. /*******************************************|********************************************/
  3062. /* */
  3063. /* Function name: SetupRGBAttrib() */
  3064. /* */
  3065. /* Arguments */
  3066. /* --------- */
  3067. /* Name: Type: Description: */
  3068. /* jobAttr EPS_JOB_ATTRIB* I: Data structure containing page attribut settings */
  3069. /* */
  3070. /* Return value: */
  3071. /* << Normal >> */
  3072. /* EPS_ERR_NONE - Success */
  3073. /* << Error >> */
  3074. /* EPS_ERR_INV_COLOR_MODE - Invalid Color Mode */
  3075. /* EPS_ERR_INV_INPUT_RESOLUTION - Invalid Input Resolution */
  3076. /* EPS_ERR_INV_PRINT_DIRECTION - Invalid Print Direction */
  3077. /* EPS_ERR_INV_PALETTE_SIZE - Invalid Palette Size */
  3078. /* EPS_ERR_INV_PALETTE_DATA - Invalid Palette Data */
  3079. /* EPS_ERR_INV_TOP_MARGIN - Invalid Top Magirn */
  3080. /* EPS_ERR_INV_LEFT_MARGIN - Invalid Left Margin */
  3081. /* EPS_ERR_INV_BOTTOM_MARGIN - Invalid Bottom Margin */
  3082. /* EPS_ERR_INV_RIGHT_MARGIN - Invalid Right Margin */
  3083. /* EPS_ERR_MARGIN_OVER_PRINTABLE_WIDTH - Invalid Magin Setting (Width) */
  3084. /* EPS_ERR_MARGIN_OVER_PRINTABLE_HEIGHT - Invalid Magin Setting (Height) */
  3085. /* */
  3086. /* Description: */
  3087. /* Confirm RGB Attribute. */
  3088. /* */
  3089. /*******************************************|********************************************/
  3090. EPS_ERR_CODE SetupRGBAttrib (
  3091. void
  3092. ){
  3093. /*** Declare Variable Local to Routine */
  3094. EPS_INT32 factor; /* Scaling factor for dpi */
  3095. EPS_INT32 idx; /* Paper size index */
  3096. EPS_INT32 tempPrintableWidth; /* Temporary Variable */
  3097. EPS_INT32 tempPrintableHeight; /* Temporary Variable */
  3098. const EPS_MEDIA_INFO* pMI = NULL;
  3099. EPS_INT16 borderPixels;
  3100. EPS_LOG_FUNCIN;
  3101. /*** Initialize Global/Local Variables */
  3102. idx = -1;
  3103. tempPrintableWidth = 0;
  3104. tempPrintableHeight = 0;
  3105. #ifndef LCOMSW_JOBPARAM_CEHCK_OFF
  3106. /*** Validate input parameters */
  3107. /*** Border Mode */
  3108. if(! ((printJob.attr.printLayout == EPS_MLID_BORDERLESS ) ||
  3109. (printJob.attr.printLayout == EPS_MLID_BORDERS ) ||
  3110. (printJob.attr.printLayout == EPS_MLID_CDLABEL ) ||
  3111. (printJob.attr.printLayout == EPS_MLID_DIVIDE16 ) ||
  3112. (printJob.attr.printLayout == EPS_MLID_CUSTOM ) ) ){
  3113. EPS_RETURN( EPS_ERR_INV_BORDER_MODE )
  3114. }
  3115. /*** Color Mode */
  3116. if( !( (printJob.attr.colorMode == EPS_CM_COLOR ) ||
  3117. (printJob.attr.colorMode == EPS_CM_MONOCHROME ) /*||
  3118. (printJob.attr.colorMode == EPS_CM_SEPIA )*/ ) ){
  3119. EPS_RETURN( EPS_ERR_INV_COLOR_MODE )
  3120. }
  3121. /*** Input Image Resolution */
  3122. /*** Select table and factor */
  3123. if(printJob.attr.inputResolution == EPS_IR_360X360){
  3124. pMI = epsMediaSize;
  3125. factor = 1;
  3126. borderPixels = EPS_BORDERS_MARGIN_360;
  3127. } else if(printJob.attr.inputResolution == EPS_IR_720X720){
  3128. pMI = epsMediaSize;
  3129. factor = 2;
  3130. borderPixels = EPS_BORDERS_MARGIN_360;
  3131. } else if(printJob.attr.inputResolution == EPS_IR_300X300){
  3132. pMI = epsMediaSize300;
  3133. //pMI = epsMediaSize;
  3134. factor = 1;
  3135. borderPixels = EPS_BORDERS_MARGIN_300;
  3136. //borderPixels = EPS_BORDERS_MARGIN_360;
  3137. } else if(printJob.attr.inputResolution == EPS_IR_600X600){
  3138. pMI = epsMediaSize300;
  3139. factor = 2;
  3140. borderPixels = EPS_BORDERS_MARGIN_300;
  3141. } else{
  3142. EPS_RETURN( EPS_ERR_INV_INPUT_RESOLUTION )
  3143. }
  3144. /*** Printing Direction */
  3145. if (! ( (printJob.attr.printDirection == EPS_PD_BIDIREC ) ||
  3146. (printJob.attr.printDirection == EPS_PD_UNIDIREC ) ) ){
  3147. EPS_RETURN( EPS_ERR_INV_PRINT_DIRECTION )
  3148. }
  3149. /*** Pallette Data */
  3150. if (printJob.attr.colorPlane == EPS_CP_256COLOR) {
  3151. if (! ((printJob.attr.paletteSize >= 3 ) &&
  3152. (printJob.attr.paletteSize <= 768/*765*/ ) ) ){
  3153. EPS_RETURN( EPS_ERR_INV_PALETTE_SIZE )
  3154. }
  3155. if ( printJob.attr.paletteData == NULL ){
  3156. EPS_RETURN( EPS_ERR_INV_PALETTE_DATA )
  3157. }
  3158. }
  3159. /*** Margin */
  3160. if (printJob.attr.printLayout == EPS_MLID_CUSTOM) {
  3161. if (printJob.attr.topMargin < borderPixels*factor) EPS_RETURN( EPS_ERR_INV_TOP_MARGIN );
  3162. if (printJob.attr.leftMargin < borderPixels*factor) EPS_RETURN( EPS_ERR_INV_LEFT_MARGIN );
  3163. if (printJob.attr.bottomMargin < borderPixels*factor) EPS_RETURN( EPS_ERR_INV_BOTTOM_MARGIN );
  3164. if (printJob.attr.rightMargin < borderPixels*factor) EPS_RETURN( EPS_ERR_INV_RIGHT_MARGIN );
  3165. }
  3166. #endif
  3167. /*======================================================================================*/
  3168. /*** Set the following parameter */
  3169. /*** - printJob.topMargin */
  3170. /*** - printJob.leftMargin */
  3171. /*** - printJob.printableAreaWidth */
  3172. /*** - printJob.printableAreaHeight */
  3173. /*** - printJob.borderlessModeInternal */
  3174. /*** - printJob.verticalOffset */
  3175. /*======================================================================================*/
  3176. /*** Find the Media by ID */
  3177. for (idx = 0; pMI[idx].id != -1; idx++) {
  3178. if (pMI[idx].id == printJob.attr.mediaSizeIdx)
  3179. break;
  3180. }
  3181. if (pMI[idx].id == -1) {
  3182. EPS_RETURN( EPS_ERR_INV_MEDIA_SIZE );
  3183. }
  3184. /*** Media Attributes */
  3185. printJob.paperWidth = pMI[idx].paper_x * factor;
  3186. printJob.paperHeight = pMI[idx].paper_y * factor;
  3187. /*** Initialize Printable based on border mode */
  3188. switch( printJob.attr.printLayout ){
  3189. case EPS_MLID_BORDERLESS:
  3190. printJob.topMargin = pMI[idx].top_margin_borderless * factor;
  3191. printJob.leftMargin = pMI[idx].left_margin_borderless * factor;
  3192. tempPrintableWidth = pMI[idx].print_area_x_borderless * factor;
  3193. tempPrintableHeight = pMI[idx].print_area_y_borderless * factor;
  3194. printJob.borderlessMode = EPS_BORDERLESS_NORMAL;
  3195. break;
  3196. case EPS_MLID_BORDERS:
  3197. case EPS_MLID_DIVIDE16:
  3198. printJob.topMargin = borderPixels * factor;
  3199. printJob.leftMargin = borderPixels * factor;
  3200. tempPrintableWidth = pMI[idx].print_area_x_border * factor;
  3201. tempPrintableHeight = pMI[idx].print_area_y_border * factor;
  3202. printJob.borderlessMode = EPS_BORDER_3MM_MARGINE;
  3203. break;
  3204. case EPS_MLID_CDLABEL:
  3205. tempPrintableWidth =
  3206. tempPrintableHeight = elGetDots(printJob.attr.inputResolution, printJob.attr.cdDimOut);
  3207. printJob.topMargin = CDDVD_OFFSET_Y(printJob.attr.inputResolution, printJob.attr.cdDimOut);
  3208. printJob.leftMargin = CDDVD_OFFSET_X(printJob.attr.inputResolution, printJob.attr.cdDimOut);
  3209. printJob.borderlessMode = EPS_BORDER_3MM_MARGINE; /* It's no meaning & no effect */
  3210. EPS_DBGPRINT(("dim: %d / top: %d / left: %d\n", printJob.attr.cdDimOut,
  3211. printJob.topMargin, printJob.leftMargin));
  3212. break;
  3213. default: /* printJob.attr.printLayout == EPS_MLID_CUSTOM */
  3214. printJob.topMargin = printJob.attr.topMargin;
  3215. printJob.leftMargin = printJob.attr.leftMargin;
  3216. tempPrintableWidth = pMI[idx].paper_x * factor -
  3217. printJob.attr.leftMargin -
  3218. printJob.attr.rightMargin;
  3219. tempPrintableHeight = pMI[idx].paper_y * factor -
  3220. printJob.attr.topMargin -
  3221. printJob.attr.bottomMargin;
  3222. printJob.borderlessMode = EPS_BORDER_CUSTOM;
  3223. }
  3224. /*** Validate/Confirm Magin Setting */
  3225. if (printJob.attr.printLayout == EPS_MLID_CUSTOM) {
  3226. if (tempPrintableWidth <= 0) EPS_RETURN( EPS_ERR_MARGIN_OVER_PRINTABLE_WIDTH );
  3227. if (tempPrintableHeight <= 0) EPS_RETURN( EPS_ERR_MARGIN_OVER_PRINTABLE_HEIGHT );
  3228. }
  3229. /*** Set Printable Area */
  3230. EPS_INT32 lOffset = printJob.attr.inputResolution/30;
  3231. //printJob.printableAreaHeight = (EPS_UINT32)lWidth + lOffset*2;
  3232. //printJob.printableAreaWidth = (EPS_UINT32)lHeight + lOffset*2;
  3233. printJob.printableAreaWidth = (EPS_UINT32)tempPrintableWidth;
  3234. printJob.printableAreaHeight = (EPS_UINT32)tempPrintableHeight;
  3235. //printJob.printableAreaWidth = (EPS_UINT32)tempPrintableHeight;
  3236. //printJob.printableAreaHeight = (EPS_UINT32)tempPrintableWidth;
  3237. /*
  3238. areaWidth = tempPrintableHeight;
  3239. areaHeight = tempPrintableWidth;
  3240. EPS_INT32 lOffset = printJob.attr.inputResolution/30;
  3241. printJob.printableAreaHeight = (EPS_UINT32)lHeight + lOffset*2;
  3242. printJob.printableAreaWidth = (EPS_UINT32)lWidth + lOffset*2;
  3243. */
  3244. //printJob.printableAreaHeight = (EPS_UINT32)lHeight + lOffset*2;
  3245. //printJob.printableAreaWidth = (EPS_UINT32)lWidth + lOffset*2;
  3246. /*** Scan through palette for the index value of white and set the global white
  3247. value to this index for skipping white raster lines */
  3248. if( printJob.attr.colorPlane == EPS_CP_256COLOR ){
  3249. printJob.bpp = 1;
  3250. } else /* if(EPS_CP_FULLCOLOR) */{
  3251. printJob.bpp = 3;
  3252. printJob.attr.paletteSize = 0;
  3253. printJob.attr.paletteData = NULL;
  3254. }
  3255. printJob.whiteColorValue = memSearchWhiteColorVal(printJob.attr.colorPlane,
  3256. printJob.attr.paletteData,
  3257. printJob.attr.paletteSize);
  3258. /*** Set "Base Point" Data */
  3259. /*** BORDER */
  3260. printJob.border.top =
  3261. printJob.border.left =
  3262. printJob.border.bottom =
  3263. printJob.border.right = borderPixels * factor;
  3264. AdjustBasePoint();
  3265. EPS_RETURN( EPS_ERR_NONE );
  3266. }
  3267. /*******************************************|********************************************/
  3268. /* */
  3269. /* Function name: SetupJPGAttrib() */
  3270. /* */
  3271. /* Arguments */
  3272. /* --------- */
  3273. /* Name: Type: Description: */
  3274. /* N/A */
  3275. /* */
  3276. /* Return value: */
  3277. /* << Normal >> */
  3278. /* EPS_ERR_NONE - Success */
  3279. /* << Error >> */
  3280. /* EPS_ERR_INV_APF_FLT - Invalid APF Filter */
  3281. /* EPS_ERR_INV_APF_ACT - Invalid APF Scene */
  3282. /* EPS_ERR_INV_APF_SHP - Invalid APF Sharpness */
  3283. /* EPS_ERR_INV_APF_RDE - Invalid APF Redeye */
  3284. /* */
  3285. /* Description: */
  3286. /* Confirm APF Attribute. */
  3287. /* */
  3288. /*******************************************|********************************************/
  3289. EPS_ERR_CODE SetupJPGAttrib (
  3290. void
  3291. ){
  3292. EPS_LOG_FUNCIN;
  3293. #ifndef LCOMSW_JOBPARAM_CEHCK_OFF
  3294. /*** Validate input parameters */
  3295. /*** Border Mode */
  3296. if(! ((printJob.attr.printLayout == EPS_MLID_BORDERLESS ) ||
  3297. (printJob.attr.printLayout == EPS_MLID_BORDERS ) ||
  3298. (printJob.attr.printLayout == EPS_MLID_CDLABEL ) ||
  3299. (printJob.attr.printLayout == EPS_MLID_DIVIDE16 ) /*||
  3300. (printJob.attr.printLayout == EPS_MLID_CUSTOM ) */) ){
  3301. EPS_RETURN( EPS_ERR_INV_BORDER_MODE )
  3302. }
  3303. /*** Color Mode (APF Filter) */
  3304. if( !( (printJob.attr.colorMode == EPS_CM_COLOR ) ||
  3305. (printJob.attr.colorMode == EPS_CM_MONOCHROME ) ||
  3306. (printJob.attr.colorMode == EPS_CM_SEPIA ) ) ){
  3307. EPS_RETURN( EPS_ERR_INV_COLOR_MODE )
  3308. }
  3309. /*** APF Scene */
  3310. if( !( (printJob.attr.apfAutoCorrect == EPS_APF_ACT_NOTHING ) ||
  3311. (printJob.attr.apfAutoCorrect == EPS_APF_ACT_STANDARD ) ||
  3312. (printJob.attr.apfAutoCorrect == EPS_APF_ACT_PIM ) ||
  3313. (printJob.attr.apfAutoCorrect == EPS_APF_ACT_PORTRATE ) ||
  3314. (printJob.attr.apfAutoCorrect == EPS_APF_ACT_VIEW ) ||
  3315. (printJob.attr.apfAutoCorrect == EPS_APF_ACT_NIGHTVIEW) ) ){
  3316. EPS_RETURN( EPS_ERR_INV_APF_ACT );
  3317. }
  3318. /*** APF Sharpness */
  3319. if (! ((printJob.attr.sharpness >= -50 ) &&
  3320. (printJob.attr.sharpness <= 50 ) ) ){
  3321. EPS_RETURN( EPS_ERR_INV_APF_SHP );
  3322. }
  3323. /*** APF Redeye */
  3324. if( !( (printJob.attr.redeye == EPS_APF_RDE_NOTHING ) ||
  3325. (printJob.attr.redeye == EPS_APF_RDE_CORRECT ) ) ){
  3326. EPS_RETURN( EPS_ERR_INV_APF_RDE );
  3327. }
  3328. #endif
  3329. printJob.bpp = 0;
  3330. printJob.attr.paletteSize = 0;
  3331. printJob.attr.paletteData = NULL;
  3332. EPS_RETURN( EPS_ERR_NONE );
  3333. }
  3334. /*******************************************|********************************************/
  3335. /* */
  3336. /* Function name: AddCmdBuff() */
  3337. /* */
  3338. /* Arguments */
  3339. /* --------- */
  3340. /* Name: Type: Description: */
  3341. /* pBuff EPS_UINT8** IO: pointer to command buffer */
  3342. /* pPos EPS_UINT8** IO: pointer to append position */
  3343. /* bufSize EPS_UINT32* IO: pointer to size of command buffer(pBuff) */
  3344. /* cmd EPS_UINT8* I : pointer to command */
  3345. /* cmdSize EPS_UINT32 I : size of command(cmd) */
  3346. /* */
  3347. /* Return value: */
  3348. /* EPS_ERR_NONE - Success */
  3349. /* EPS_ERR_MEMORY_ALLOCATION - Failed to allocate memory */
  3350. /* */
  3351. /* Description: */
  3352. /* Append command to buffer. If the buffer is short, expand it. */
  3353. /* */
  3354. /*******************************************|********************************************/
  3355. EPS_ERR_CODE AddCmdBuff(
  3356. EPS_UINT8 **pBuff,
  3357. EPS_UINT8 **pPos,
  3358. EPS_UINT32 *bufSize,
  3359. const EPS_UINT8 *cmd,
  3360. EPS_UINT32 cmdSize
  3361. ){
  3362. EPS_UINT32 cmdPosDist = (EPS_UINT32)(*pPos - *pBuff); /* command offset distance */
  3363. EPS_LOG_FUNCIN;
  3364. EPS_MEM_GROW(EPS_UINT8*, *pBuff, bufSize, cmdPosDist + cmdSize )
  3365. if(*pBuff != NULL){
  3366. *pPos = *pBuff + cmdPosDist;
  3367. memcpy(*pPos, cmd, cmdSize);
  3368. *pPos += cmdSize;
  3369. EPS_RETURN( EPS_ERR_NONE );
  3370. } else{
  3371. EPS_RETURN( EPS_ERR_MEMORY_ALLOCATION );
  3372. }
  3373. }
  3374. /*******************************************|********************************************/
  3375. /* */
  3376. /* Function name: SendStartJob() */
  3377. /* */
  3378. /* Arguments */
  3379. /* --------- */
  3380. /* Name: Type: Description: */
  3381. /* bAddStartPage EPS_BOOL I: Append Start Page comannd */
  3382. /* */
  3383. /* Return value: */
  3384. /* << Normal >> */
  3385. /* EPS_ERR_NONE - Success */
  3386. /* EPS_JOB_CANCELED - Cancelled operation by user */
  3387. /* (Do not return when Uni-Directional) */
  3388. /* << Error >> */
  3389. /* EPS_ERR_OPR_FAIL - Internal Error */
  3390. /* EPS_ERR_COMM_ERROR - Communication Error */
  3391. /* EPS_ERR_MEMORY_ALLOCATION - Failed to allocate memory */
  3392. /* EPS_ERR_PRINTER_ERR_OCCUR - Printer Error happened */
  3393. /* */
  3394. /* Description: */
  3395. /* Send Start Job (&Page) commands. */
  3396. /* */
  3397. /*******************************************|********************************************/
  3398. EPS_ERR_CODE SendStartJob (
  3399. EPS_BOOL bAddStartPage
  3400. ){
  3401. /*** Declare Variable Local to Routine */
  3402. EPS_ERR_CODE retStatus = EPS_ERR_NONE; /* Return status of internal calls */
  3403. EPS_UINT8* pCmdPos = NULL; /* Temporary buffer pointer */
  3404. EPS_UINT32 retBufSize = 0; /* Size of buffer written */
  3405. EPS_LOG_FUNCIN;
  3406. pCmdPos = sendDataBuf;
  3407. /*======================================================================================*/
  3408. /*** Initialize Printer and Set Printer in ESC/PR mode */
  3409. /*======================================================================================*/
  3410. #define SendStartJob_ADDCMD_LEN(CMD, EXPLEN) { \
  3411. retStatus = AddCmdBuff(&sendDataBuf, &pCmdPos, &sendDataBufSize, CMD, sizeof(CMD)+EXPLEN); \
  3412. if(EPS_ERR_NONE != retStatus){ \
  3413. goto SendStartJob_END; \
  3414. } \
  3415. }
  3416. #define SendStartJob_ADDCMD(CMD) SendStartJob_ADDCMD_LEN(CMD, 0)
  3417. /*** Exit Packet Mode */
  3418. SendStartJob_ADDCMD(ExitPacketMode)
  3419. /*** Initialize Printer */
  3420. SendStartJob_ADDCMD(InitPrinter)
  3421. /*** Enter Remote Mode */
  3422. SendStartJob_ADDCMD(EnterRemoteMode)
  3423. /*** Remote Command - TI */
  3424. if(epsCmnFnc.getLocalTime){
  3425. SendStartJob_ADDCMD(RemoteTI)
  3426. MakeRemoteTICmd(pCmdPos - sizeof(RemoteTI));
  3427. }
  3428. /*** Remote Command - JS */
  3429. SendStartJob_ADDCMD(RemoteJS)
  3430. /*** Remote Command - JH */
  3431. SendStartJob_ADDCMD(RemoteJH)
  3432. /*** Remote Command - HD */
  3433. SendStartJob_ADDCMD(RemoteHD)
  3434. *(pCmdPos - sizeof(RemoteHD) + 6) = printJob.platform;
  3435. /*** Remote Command - PP */
  3436. SendStartJob_ADDCMD(RemotePP)
  3437. pCmdPos -= sizeof(RemotePP);
  3438. switch(printJob.attr.paperSource){
  3439. case EPS_MPID_REAR:
  3440. pCmdPos[5] = 0x01; pCmdPos[6] = 0x00;
  3441. break;
  3442. case EPS_MPID_FRONT1:
  3443. pCmdPos[5] = 0x01; pCmdPos[6] = 0x01;
  3444. break;
  3445. case EPS_MPID_FRONT2:
  3446. pCmdPos[5] = 0x01; pCmdPos[6] = 0x02;
  3447. break;
  3448. case EPS_MPID_CDTRAY:
  3449. pCmdPos[5] = 0x02; pCmdPos[6] = 0x01;
  3450. break;
  3451. case EPS_MPID_AUTO:
  3452. default:
  3453. if( EPS_CP_JPEG == printJob.attr.colorPlane &&
  3454. EPS_IS_CDDVD(printJob.attr.mediaTypeIdx) ){
  3455. /* Jpeg CD print need PP */
  3456. pCmdPos[5] = 0x02; pCmdPos[6] = 0x01;
  3457. } else{
  3458. EPS_DBGPRINT(("Paper Sourcr AutoSelect\n"));
  3459. pCmdPos[5] = 0x01; pCmdPos[6] = 0xFF; /* auto select */
  3460. }
  3461. break;
  3462. }
  3463. pCmdPos += sizeof(RemotePP);
  3464. /*** Remote Command - DP(duplex) */
  3465. if(EPS_DUPLEX_NONE != printJob.attr.duplex){
  3466. SendStartJob_ADDCMD(RemoteDP)
  3467. }
  3468. /*** Exit Remote Mode */
  3469. SendStartJob_ADDCMD(ExitRemoteMode)
  3470. /*** Enter ESC/P-R mode */
  3471. if( EPS_CP_JPEG != printJob.attr.colorPlane ){ /* RGB */
  3472. SendStartJob_ADDCMD(ESCPRMode)
  3473. } else{ /* JPEG */
  3474. SendStartJob_ADDCMD(ESCPRModeJpg)
  3475. }
  3476. /*** ESC/PR "Print Quality" Command (Internal called Page Attributes) */
  3477. SendStartJob_ADDCMD_LEN(PrintQualityCmd, printJob.attr.paletteSize)
  3478. MakeQualityCmd(pCmdPos - (sizeof(PrintQualityCmd) + printJob.attr.paletteSize) );
  3479. /*** ESC/PR "apf setting" Command */
  3480. if(EPS_CP_JPEG == printJob.attr.colorPlane){
  3481. SendStartJob_ADDCMD(APFSettingCmd)
  3482. MakeAPFCmd(pCmdPos-sizeof(APFSettingCmd));
  3483. }
  3484. /*** ESC/PR "Job" Command to Printer */
  3485. if( EPS_CP_JPEG != printJob.attr.colorPlane ){ /* RGB */
  3486. SendStartJob_ADDCMD(JobCmd)
  3487. MakeJobCmd(pCmdPos-sizeof(JobCmd));
  3488. } else{ /* JPEG */
  3489. SendStartJob_ADDCMD(JobCmdJpg)
  3490. MakeJobCmd(pCmdPos-sizeof(JobCmdJpg));
  3491. }
  3492. if(bAddStartPage){
  3493. SendStartJob_ADDCMD(StartPage)
  3494. }
  3495. retStatus = SendCommand(sendDataBuf, (EPS_UINT32)(pCmdPos - sendDataBuf), &retBufSize, TRUE);
  3496. SendStartJob_END:
  3497. if(EPS_ERR_NONE == retStatus){
  3498. printJob.sendJS = TRUE;
  3499. }
  3500. /*** Return to Caller */
  3501. EPS_RETURN( retStatus );
  3502. }
  3503. /*======================================================================================*/
  3504. /*** Set up Remote "TI" Command */
  3505. /*======================================================================================*/
  3506. static void MakeRemoteTICmd (
  3507. EPS_UINT8* pBuf
  3508. ){
  3509. /*** Declare Variable Local to Routine */
  3510. EPS_LOCAL_TIME locTime;
  3511. EPS_UINT8 array2[2] = {0, 0}; /* Temporary Buffer for 2 byte Big Endian */
  3512. EPS_LOG_FUNCIN;
  3513. /* Get platform local time */
  3514. epsCmnFnc.getLocalTime(&locTime);
  3515. /*** Skip Header */
  3516. pBuf += REMOTE_HEADER_LENGTH;
  3517. /*** Set Attributes/Values */
  3518. memSetEndian(EPS_ENDIAN_BIG, EPS_2_BYTES, locTime.year, array2);
  3519. memcpy(pBuf, array2, sizeof(array2));
  3520. pBuf += sizeof(array2);
  3521. *pBuf++ = locTime.mon;
  3522. *pBuf++ = locTime.day;
  3523. *pBuf++ = locTime.hour;
  3524. *pBuf++ = locTime.min;
  3525. *pBuf = locTime.sec;
  3526. EPS_RETURN_VOID;
  3527. }
  3528. /*======================================================================================*/
  3529. /*** Set up ESC/PR "Print Quality" Command */
  3530. /*======================================================================================*/
  3531. static void MakeQualityCmd (
  3532. EPS_UINT8* pBuf
  3533. ){
  3534. /*** Declare Variable Local to Routine */
  3535. EPS_UINT8* pCmdPosTmp = NULL;
  3536. EPS_UINT8 array2[2] = {0, 0}; /* Temporary Buffer for 2 byte Big Endian */
  3537. EPS_UINT8 array4[4] = {0, 0, 0, 0}; /* Temporary Buffer for 4 byte Big Endian */
  3538. EPS_LOG_FUNCIN;
  3539. /*** Parameter Length */
  3540. if(printJob.attr.paletteSize > 0){
  3541. pCmdPosTmp = pBuf + ESCPR_CLASS_LENGTH;
  3542. memSetEndian(EPS_ENDIAN_LITTLE, EPS_4_BYTES,
  3543. ESCPR_PRINT_QUALITY_LENGTH + printJob.attr.paletteSize, array4);
  3544. memcpy(pCmdPosTmp, array4, sizeof(array4));
  3545. }
  3546. pBuf += ESCPR_HEADER_LENGTH;
  3547. /*** Set Attributes/Values */
  3548. *pBuf++ = (EPS_UINT8)printJob.attr.mediaTypeIdx;
  3549. switch( printJob.attr.printQuality ){
  3550. case EPS_MQID_DRAFT:
  3551. *pBuf++ = 0;
  3552. break;
  3553. case EPS_MQID_HIGH:
  3554. *pBuf++ = 2;
  3555. break;
  3556. case EPS_MQID_NORMAL:
  3557. default:
  3558. *pBuf++ = 1;
  3559. break;
  3560. }
  3561. *pBuf++ = printJob.attr.colorMode;
  3562. *pBuf++ = (EPS_UINT8)printJob.attr.brightness;
  3563. *pBuf++ = (EPS_UINT8)printJob.attr.contrast;
  3564. *pBuf++ = (EPS_UINT8)printJob.attr.saturation;
  3565. *pBuf++ = printJob.attr.colorPlane;
  3566. memSetEndian(EPS_ENDIAN_BIG, EPS_2_BYTES, printJob.attr.paletteSize, array2);
  3567. memcpy(pBuf, array2, sizeof(array2));
  3568. if (printJob.attr.paletteSize > 0){
  3569. pBuf += sizeof(array2);
  3570. memcpy(pBuf, printJob.attr.paletteData, printJob.attr.paletteSize);
  3571. }
  3572. EPS_RETURN_VOID;
  3573. }
  3574. /*======================================================================================*/
  3575. /*** Set up ESC/PR "APF setting" Command */
  3576. /*======================================================================================*/
  3577. static void MakeAPFCmd (
  3578. EPS_UINT8* pBuf
  3579. ){
  3580. EPS_LOG_FUNCIN;
  3581. /*** Skip Header */
  3582. pBuf += ESCPR_HEADER_LENGTH;
  3583. /*** Set Attributes/Values */
  3584. *pBuf++ = printJob.attr.colorMode;
  3585. *pBuf++ = printJob.attr.apfAutoCorrect;
  3586. *pBuf++ = printJob.attr.sharpness;
  3587. *pBuf++ = printJob.attr.redeye;
  3588. EPS_RETURN_VOID;
  3589. }
  3590. /*======================================================================================*/
  3591. /*** Set up ESC/PR "Job" Command */
  3592. /*======================================================================================*/
  3593. static void MakeJobCmd (
  3594. EPS_UINT8* pBuf
  3595. ){
  3596. /*** Declare Variable Local to Routine */
  3597. EPS_UINT8 array2[2] = {0, 0}; /* Temporary Buffer for 2 byte Big Endian */
  3598. EPS_UINT8 array4[4] = {0, 0, 0, 0}; /* Temporary Buffer for 4 byte Big Endian */
  3599. EPS_LOG_FUNCIN;
  3600. /*** Skip Header */
  3601. pBuf += ESCPR_HEADER_LENGTH;
  3602. if( EPS_CP_JPEG != printJob.attr.colorPlane ){ /* RGB */
  3603. /*EPS_DBGPRINT(("(%d, %d) / (%d, %d) / (%d, %d)\n",
  3604. printJob.paperWidth, printJob.paperHeight,
  3605. printJob.topMargin, printJob.leftMargin,
  3606. printJob.printableAreaWidth, printJob.printableAreaHeight))*/
  3607. /*** Set Attributes/Values */
  3608. memSetEndian(EPS_ENDIAN_BIG, EPS_4_BYTES, (EPS_UINT32)printJob.paperWidth, array4);
  3609. memcpy(pBuf, array4, sizeof(array4));
  3610. pBuf += sizeof(array4);
  3611. memSetEndian(EPS_ENDIAN_BIG, EPS_4_BYTES, (EPS_UINT32)printJob.paperHeight, array4);
  3612. memcpy(pBuf, array4, sizeof(array4));
  3613. pBuf += sizeof(array4);
  3614. memSetEndian(EPS_ENDIAN_BIG, EPS_2_BYTES, (EPS_UINT32)printJob.topMargin, array2);
  3615. memcpy(pBuf, array2, sizeof(array2));
  3616. pBuf += sizeof(array2);
  3617. memSetEndian(EPS_ENDIAN_BIG, EPS_2_BYTES, (EPS_UINT32)printJob.leftMargin, array2);
  3618. memcpy(pBuf, array2, sizeof(array2));
  3619. pBuf += sizeof(array2);
  3620. memSetEndian(EPS_ENDIAN_BIG, EPS_4_BYTES, printJob.printableAreaWidth, array4);
  3621. memcpy(pBuf, array4, sizeof(array4));
  3622. pBuf += sizeof(array4);
  3623. memSetEndian(EPS_ENDIAN_BIG, EPS_4_BYTES, printJob.printableAreaHeight, array4);
  3624. memcpy(pBuf, array4, sizeof(array4));
  3625. pBuf += sizeof(array4);
  3626. switch( printJob.attr.inputResolution ){
  3627. case EPS_IR_720X720:
  3628. *pBuf++ = 0x01;
  3629. break;
  3630. case EPS_IR_300X300:
  3631. *pBuf++ = 0x02;
  3632. break;
  3633. case EPS_IR_600X600:
  3634. *pBuf++ = 0x03;
  3635. break;
  3636. case EPS_IR_360X360:
  3637. default:
  3638. *pBuf++ = 0x00;
  3639. break;
  3640. }
  3641. *pBuf = printJob.attr.printDirection;
  3642. } else{ /* JPEG */
  3643. /*** Set Attributes/Values */
  3644. *pBuf++ = (EPS_UINT8)printJob.attr.mediaSizeIdx;
  3645. if( EPS_IS_CDDVD( printJob.attr.mediaTypeIdx ) ){
  3646. *pBuf++ = 0x0A;
  3647. } else{
  3648. switch( printJob.attr.printLayout ){
  3649. case EPS_MLID_BORDERLESS:
  3650. *pBuf++ = 0x01;
  3651. break;
  3652. case EPS_MLID_CDLABEL:
  3653. *pBuf++ = 0x0A;
  3654. break;
  3655. case EPS_MLID_DIVIDE16:
  3656. *pBuf++ = 0x90;
  3657. break;
  3658. default: /* FIXED, CUSTOM */
  3659. *pBuf++ = 0x00;
  3660. }
  3661. }
  3662. *pBuf++ = printJob.attr.cdDimIn;
  3663. *pBuf++ = printJob.attr.cdDimOut;
  3664. *pBuf = printJob.attr.printDirection;
  3665. }
  3666. EPS_RETURN_VOID;
  3667. }
  3668. /*******************************************|********************************************/
  3669. /* */
  3670. /* Function name: SendEndJob() */
  3671. /* */
  3672. /* Arguments */
  3673. /* --------- */
  3674. /* Name: Type: Description: */
  3675. /* bAddEndPage EPS_BOOL I: Append End Page comannd */
  3676. /* */
  3677. /* Return value: */
  3678. /* << Normal >> */
  3679. /* EPS_ERR_NONE - Success */
  3680. /* EPS_JOB_CANCELED - Cancelled operation by user */
  3681. /* (Do not return when Uni-Directional) */
  3682. /* << Error >> */
  3683. /* EPS_ERR_OPR_FAIL - Internal Error */
  3684. /* EPS_ERR_COMM_ERROR - Communication Error */
  3685. /* EPS_ERR_PRINTER_ERR_OCCUR - Printer Error happened */
  3686. /* */
  3687. /* Description: */
  3688. /* Send End Page commands. */
  3689. /* */
  3690. /*******************************************|********************************************/
  3691. EPS_ERR_CODE SendEndJob (
  3692. EPS_BOOL bAddEndPage
  3693. ){
  3694. /*** Declare Variable Local to Routine */
  3695. EPS_ERR_CODE retStatus = EPS_ERR_NONE; /* Return status of internal calls */
  3696. EPS_UINT8* pCmdPos = NULL;
  3697. EPS_UINT32 retBufSize; /* Size of buffer written */
  3698. EPS_LOG_FUNCIN
  3699. EPS_MEM_GROW(EPS_UINT8*, sendDataBuf, &sendDataBufSize,
  3700. (sizeof(EndPage)+ sizeof(EndJob) + sizeof(InitPrinter)
  3701. + sizeof(EnterRemoteMode) + sizeof(RemoteLD) + sizeof(RemoteJE)+ sizeof(ExitRemoteMode)))
  3702. if(NULL == sendDataBuf){
  3703. EPS_RETURN( EPS_ERR_MEMORY_ALLOCATION )
  3704. }
  3705. pCmdPos = sendDataBuf;
  3706. if(bAddEndPage){
  3707. memcpy(pCmdPos, EndPage, sizeof(EndPage));
  3708. pCmdPos[10] = EPS_END_PAGE;
  3709. pCmdPos += sizeof(EndPage);
  3710. }
  3711. /*** End Job */
  3712. memcpy(pCmdPos, EndJob, sizeof(EndJob));
  3713. pCmdPos += sizeof(EndJob);
  3714. /*** Initialize */
  3715. memcpy(pCmdPos, InitPrinter, sizeof(InitPrinter));
  3716. pCmdPos += sizeof(InitPrinter);
  3717. memcpy(pCmdPos, EnterRemoteMode, sizeof(EnterRemoteMode));
  3718. pCmdPos += sizeof(EnterRemoteMode);
  3719. if(EPS_DUPLEX_NONE != printJob.attr.duplex){
  3720. memcpy(pCmdPos, RemoteLD, sizeof(RemoteLD));
  3721. pCmdPos += sizeof(RemoteLD);
  3722. }
  3723. /*** Remote Command - JE */
  3724. memcpy(pCmdPos, RemoteJE, sizeof(RemoteJE));
  3725. pCmdPos += sizeof(RemoteJE);
  3726. /*** Exit Remote Mode */
  3727. memcpy(pCmdPos, ExitRemoteMode, sizeof(ExitRemoteMode));
  3728. pCmdPos += sizeof(ExitRemoteMode);
  3729. retStatus = SendCommand(sendDataBuf, (EPS_UINT32)(pCmdPos - sendDataBuf), &retBufSize, TRUE);
  3730. if(EPS_JOB_CANCELED == retStatus){
  3731. retStatus = EPS_ERR_NONE;
  3732. }
  3733. /*printJob.sendJS = FALSE;*/
  3734. /*** Return to Caller */
  3735. EPS_RETURN( retStatus );
  3736. }
  3737. /*******************************************|********************************************/
  3738. /* */
  3739. /* Function name: SendCommand() */
  3740. /* */
  3741. /* Arguments */
  3742. /* --------- */
  3743. /* Name: Type: Description: */
  3744. /* Buffer EPS_INT8* I: Print Data Buffer */
  3745. /* BuffLen EPS_UINT32 I: Print Data Buffer Size */
  3746. /* pSize EPS_UINT32 O: Actual Length Transferred */
  3747. /* */
  3748. /* Return value: */
  3749. /* EPS_ERR_NONE - Sent the data successfully */
  3750. /* EPS_JOB_CANCELED - Cancelled operation by user */
  3751. /* (Do not return when Uni-Directional) */
  3752. /* EPS_ERR_OPR_FAIL - Internal Error */
  3753. /* EPS_ERR_COMM_ERROR - Communication Error */
  3754. /* EPS_ERR_PRINTER_ERR_OCCUR - Printer Error happened */
  3755. /* */
  3756. /* Description: */
  3757. /* Send print data to the active printer */
  3758. /* */
  3759. /*******************************************|********************************************/
  3760. EPS_ERR_CODE SendCommand (
  3761. const EPS_UINT8* Buffer,
  3762. EPS_UINT32 BuffLen,
  3763. EPS_UINT32* pSize,
  3764. EPS_BOOL bSave
  3765. ){
  3766. #ifdef EPS_FILTER
  3767. //long int i;
  3768. EPS_UINT32 i;
  3769. FILE* outfp = stdout;
  3770. for (i = 0; i < BuffLen; i++){
  3771. putc(*(Buffer + i), outfp);
  3772. }
  3773. *pSize = BuffLen;
  3774. return EPS_ERR_NONE;
  3775. #endif
  3776. /*** Declare Variable Local to Routine */
  3777. EPS_ERR_CODE Ret = EPS_ERR_NONE;
  3778. EPS_INT32 retStatus;
  3779. EPS_UINT32 sendSize;
  3780. EPS_UINT32 sentSize;
  3781. EPS_INT32 nRetry = 0;
  3782. EPS_UINT32 tmStart, tmNow, tmSpan;
  3783. EPS_INT32 nDlySpan = 10; /* first 10 ms */
  3784. EPS_INT32 nDlyTotal = EPS_TIMEOUT_SEC; /* total 1000 ms */
  3785. EPS_LOG_FUNCIN;
  3786. /*** Validate input parameters */
  3787. if ((Buffer == NULL) || (BuffLen == 0))
  3788. EPS_RETURN( EPS_ERR_OPR_FAIL );
  3789. /*** Initialize Global/Local Variables */
  3790. retStatus = EPS_ERR_NONE;
  3791. sentSize = 0;
  3792. sendSize = BuffLen;
  3793. *pSize = 0;
  3794. tmStart = tmNow = tmSpan = 0;
  3795. if( FALSE == printJob.bComm){
  3796. EPS_RETURN( EPS_ERR_PRINTER_ERR_OCCUR );
  3797. }
  3798. if( EPS_IS_BI_PROTOCOL(printJob.printer->protocol) ){
  3799. /***------------------------------------------------------------------------------------*/
  3800. /*** Bi-Directional Mode */
  3801. /***------------------------------------------------------------------------------------*/
  3802. /*** If printer reset command was already sent, don't send command any more. */
  3803. /*** When paper jam error happened, don't send command any more. */
  3804. /*** "transmittable == FLSE" means "paper jam error happened". */
  3805. if( printJob.resetSent == EPS_RESET_SENT || TRUE == printJob.resetReq ){
  3806. EPS_RETURN( EPS_JOB_CANCELED );
  3807. } else if(FALSE == printJob.transmittable){
  3808. EPS_RETURN( EPS_ERR_PRINTER_ERR_OCCUR );
  3809. }
  3810. /*** Send command */
  3811. if(epsCmnFnc.getTime){
  3812. tmStart = epsCmnFnc.getTime();
  3813. tmNow = tmSpan = 0;
  3814. }
  3815. while(nDlyTotal > 0){
  3816. if(gStatusCount == EPS_ROOP_NUM){
  3817. gStatusCount = 0;
  3818. if ((Ret = MonitorStatus(NULL) ) != EPS_ERR_NONE){
  3819. EPS_DBGPRINT(("MonitorStatus=%d\n", Ret));
  3820. if(Ret == EPS_JOB_CANCELED){
  3821. EPS_RETURN( Ret );
  3822. } else if(Ret == EPS_ERR_COMM_ERROR){
  3823. EPS_RETURN( EPS_ERR_PRINTER_ERR_OCCUR );
  3824. } else {
  3825. /*anoter error*/
  3826. if ( EPS_PROTOCOL_USB & printJob.printer->protocol ){
  3827. break;
  3828. } else{
  3829. /* Net continue to buffer full. */
  3830. }
  3831. }
  3832. }
  3833. }
  3834. gStatusCount++;
  3835. Ret = jobFnc.WriteData(Buffer, sendSize, &sentSize);
  3836. *pSize += sentSize;
  3837. #ifdef LCOMSW_CMDDMP
  3838. EPS_DF_WRITE(Buffer, sentSize)
  3839. #endif
  3840. if (Ret != EPS_ERR_NONE){
  3841. if (Ret == EPS_JOB_CANCELED) {
  3842. /* UPnP Job turned idle */
  3843. printJob.resetReq = TRUE;
  3844. EPS_RETURN( Ret );
  3845. } else if (Ret != EPS_COM_TINEOUT){
  3846. EPS_DBGPRINT(("PRINT--> Print Failed [%d]\r\n",Ret));
  3847. EPS_RETURN( EPS_ERR_COMM_ERROR );
  3848. } else if(sendSize > sentSize){
  3849. Buffer += sentSize;
  3850. sendSize -= sentSize;
  3851. }
  3852. } else if (sendSize > sentSize){ /* CBT returned OK, but size is less */
  3853. Ret = EPS_COM_TINEOUT;
  3854. Buffer += sentSize;
  3855. sendSize -= sentSize;
  3856. } else {
  3857. sendSize -= sentSize;
  3858. break;
  3859. }
  3860. if( !(EPS_PROTOCOL_USB & printJob.printer->protocol)
  3861. || NULL == epsCmnFnc.getTime ){
  3862. /* The count is made an upper bound. */
  3863. if(nRetry++ > EPS_TIMEOUT_NUM){
  3864. break;
  3865. }
  3866. } else{
  3867. /* The elapsed time is made an upper bound. */
  3868. tmNow = epsCmnFnc.getTime();
  3869. tmSpan = (EPS_UINT32)(tmNow - tmStart);
  3870. if( tmSpan >= EPS_TIMEOUT_SEC ){
  3871. break;
  3872. }
  3873. /* Wait */
  3874. nDlyTotal -= nDlySpan;
  3875. if(nDlySpan < 200){
  3876. nDlySpan += nDlySpan/2;
  3877. if(nDlySpan > 200){
  3878. nDlySpan = 200; /* max 200ms */
  3879. }
  3880. }
  3881. serDelayThread(nDlySpan, &epsCmnFnc);
  3882. }
  3883. }
  3884. if(0 < sendSize){
  3885. if(TRUE == bSave){
  3886. /* save the leftovers */
  3887. /*EPS_DBGPRINT(("%d / Save %d byte\r\n", Ret, sendSize));*/
  3888. printJob.contData.sendDataSize = sendSize;
  3889. printJob.contData.sendData = Buffer;
  3890. }
  3891. Ret = MonitorStatus(NULL);
  3892. if (Ret == EPS_JOB_CANCELED) {
  3893. EPS_RETURN( Ret );
  3894. } else{
  3895. EPS_RETURN( EPS_ERR_PRINTER_ERR_OCCUR );
  3896. }
  3897. } else{
  3898. printJob.contData.sendDataSize = 0;
  3899. }
  3900. if(Ret != EPS_ERR_NONE){
  3901. EPS_RETURN( EPS_ERR_PRINTER_ERR_OCCUR );
  3902. }
  3903. } else{
  3904. /***------------------------------------------------------------------------------------*/
  3905. /*** Uni-Directional Communication Mode */
  3906. /***------------------------------------------------------------------------------------*/
  3907. retStatus = jobFnc.WriteData(Buffer, BuffLen, &sentSize);
  3908. if ((retStatus == 0) && (sendSize == sentSize)) {
  3909. *pSize = sentSize;
  3910. } else {
  3911. EPS_RETURN( EPS_ERR_COMM_ERROR );
  3912. }
  3913. }
  3914. /*** Return to Caller */
  3915. EPS_RETURN( EPS_ERR_NONE );
  3916. }
  3917. /*******************************************|********************************************/
  3918. /* */
  3919. /* Function name: AdjustBasePoint() */
  3920. /* */
  3921. /* Arguments */
  3922. /* --------- */
  3923. /* Name: Type: Description: */
  3924. /* N/A void N/A */
  3925. /* */
  3926. /* Return value: N/A */
  3927. /* */
  3928. /* Description: Change the base point setting and the printable area value for */
  3929. /* the custum border mode. */
  3930. /* */
  3931. /*******************************************|********************************************/
  3932. static void AdjustBasePoint (
  3933. void
  3934. ){
  3935. /* temporary variables for max PAW/PAL */
  3936. EPS_UINT32 maxPAWidthBorder;
  3937. EPS_UINT32 maxPAHeightBorder;
  3938. EPS_UINT32 RightMargin;
  3939. EPS_UINT32 BottomMargin;
  3940. EPS_LOG_FUNCIN;
  3941. printJob.offset_x = 0;
  3942. printJob.offset_y = 0;
  3943. /*** Adjust the base point for custum border printing mode */
  3944. /*** (In case that left margin = 42 and top margin = 42 are NOT inputed) */
  3945. if (printJob.borderlessMode == EPS_BORDER_CUSTOM) {
  3946. if ( (printJob.attr.leftMargin > printJob.border.left) ||
  3947. (printJob.attr.topMargin > printJob.border.top ) ) {
  3948. printJob.offset_x = (EPS_INT16)(printJob.attr.leftMargin - printJob.border.left);
  3949. printJob.offset_y = (EPS_INT16)(printJob.attr.topMargin - printJob.border.top);
  3950. RightMargin = printJob.paperWidth
  3951. - printJob.attr.leftMargin - printJob.printableAreaWidth;
  3952. BottomMargin = printJob.paperHeight
  3953. - printJob.attr.topMargin - printJob.printableAreaHeight;
  3954. printJob.printableAreaWidth = printJob.paperWidth
  3955. - printJob.border.left - RightMargin;
  3956. printJob.printableAreaHeight = printJob.paperHeight
  3957. - printJob.border.top - BottomMargin;
  3958. printJob.leftMargin = (EPS_INT16)(printJob.border.left);
  3959. printJob.topMargin = (EPS_INT16)(printJob.border.top);
  3960. /* max PAW/PAL */
  3961. maxPAHeightBorder = (EPS_UINT32)(printJob.paperHeight
  3962. - printJob.border.top - printJob.border.bottom);
  3963. maxPAWidthBorder = (EPS_UINT32)(printJob.paperWidth
  3964. - printJob.border.left - printJob.border.right);
  3965. if (printJob.printableAreaHeight > maxPAHeightBorder) {
  3966. printJob.printableAreaHeight = maxPAHeightBorder;
  3967. }
  3968. if (printJob.printableAreaWidth > maxPAWidthBorder) {
  3969. printJob.printableAreaWidth = maxPAWidthBorder;
  3970. }
  3971. }
  3972. }
  3973. EPS_RETURN_VOID;
  3974. }
  3975. /*******************************************|********************************************/
  3976. /* */
  3977. /* Function name: PrintLine() */
  3978. /* */
  3979. /* Arguments */
  3980. /* --------- */
  3981. /* Name: Type: Description: */
  3982. /* line EPS_IMAGE* I: Image Data Structure */
  3983. /* */
  3984. /* Return value: */
  3985. /* EPS_ERR_NONE - Success */
  3986. /* EPS_ERR_MEMORY_ALLOCATION - Failed to allocate memory */
  3987. /* EPS_JOB_CANCELED - Cancelled operation by user */
  3988. /* (Do not return when Uni-Directional) */
  3989. /* EPS_ERR_OPR_FAIL - Internal Error */
  3990. /* EPS_ERR_COMM_ERROR - Communication Error */
  3991. /* */
  3992. /* Description: */
  3993. /* Filter Print Raster Data. */
  3994. /* */
  3995. /*******************************************|********************************************/
  3996. static EPS_ERR_CODE PrintLine (
  3997. EPS_IMAGE* line
  3998. ){
  3999. EPS_RECT AdjBandRec; /* Rectangle after BasePointAdjustment */
  4000. EPS_BANDBMP InBmp; /* Input band data */
  4001. EPS_LOG_FUNCIN;
  4002. /* Initialize input image structure */
  4003. InBmp.bits = line->data;
  4004. InBmp.widthBytes = line->bytesPerLine;
  4005. /* change rectangle due to base point adjustment */
  4006. AdjBandRec.top = line->rect.top + printJob.offset_y;
  4007. AdjBandRec.left = line->rect.left + printJob.offset_x;
  4008. AdjBandRec.bottom = line->rect.bottom + printJob.offset_y;
  4009. AdjBandRec.right = line->rect.right + printJob.offset_x;
  4010. /* band is not visible */
  4011. if ((EPS_UINT32)AdjBandRec.bottom > printJob.printableAreaHeight){
  4012. EPS_RETURN( EPS_ERR_NONE );
  4013. }
  4014. if ((EPS_UINT32)AdjBandRec.right > printJob.printableAreaWidth){
  4015. AdjBandRec.right = (EPS_INT32)printJob.printableAreaWidth;
  4016. }
  4017. #ifdef GCOMSW_CMD_ESCPAGE
  4018. if(EPS_LANG_ESCPR == printJob.printer->language ){
  4019. #endif
  4020. /*** ESC/P-R ***/
  4021. EPS_RETURN( SendLine(&InBmp, &AdjBandRec) );
  4022. #ifdef GCOMSW_CMD_ESCPAGE
  4023. } else{
  4024. /*** ESC/Page ***/
  4025. EPS_RETURN( pageColorRow(&InBmp, &AdjBandRec) );
  4026. }
  4027. #endif
  4028. }
  4029. /*******************************************|********************************************/
  4030. /* */
  4031. /* Function name: SendLine() */
  4032. /* */
  4033. /* Arguments */
  4034. /* --------- */
  4035. /* Name: Type: Description: */
  4036. /* pInBmp const EPS_BANDBMP I: [RGB] Image Data */
  4037. /* pBandRec EPS_RECT I: Band rectangle information */
  4038. /* */
  4039. /* Return value: */
  4040. /* EPS_ERR_NONE - Sent the data successfully */
  4041. /* EPS_JOB_CANCELED - Cancelled operation by user */
  4042. /* (Do not return when Uni-Directional) */
  4043. /* EPS_ERR_OPR_FAIL - Internal Error */
  4044. /* EPS_ERR_COMM_ERROR - Communication Error */
  4045. /* */
  4046. /* Description: */
  4047. /* Send a line data to printer. */
  4048. /* */
  4049. /*******************************************|********************************************/
  4050. static EPS_ERR_CODE SendLine (
  4051. const EPS_BANDBMP* pInBmp,
  4052. EPS_RECT* pBandRec
  4053. ){
  4054. /*** Declare Variable Local to Routine */
  4055. EPS_ERR_CODE retStatus; /* Return status of internal calls */
  4056. EPS_UINT32 retBufSize; /* Size of buffer written */
  4057. EPS_UINT32 cmdSize; /* All Size of Print Job Command */
  4058. EPS_UINT32 cpyCount; /* Counter for Set Command */
  4059. EPS_UINT16 compDataSize; /* Raster Data Size */
  4060. EPS_UINT16 linePixelSize; /* Raster Pixel Size */
  4061. EPS_UINT8 compFlag; /* Compression flg (1:done compression 0:undone compression) */
  4062. EPS_UINT32 paramSize; /* Parameter Length */
  4063. EPS_UINT8 array2[2] = {0, 0}; /* Temporary Buffer for 2 byte Big Endian */
  4064. EPS_UINT8 array4[4] = {0, 0, 0, 0}; /* Temporary Buffer for 4 byte Big Endian */
  4065. EPS_UINT8* compData; /* Compression Data Pointer */
  4066. EPS_UINT8* sdBuf; /* Send Data Buffer Pointer */
  4067. const EPS_UINT8* srcAddr;
  4068. #if LCOMSW_PACKET_4KB
  4069. EPS_INT32 rest_size;
  4070. EPS_INT32 idx;
  4071. #endif
  4072. EPS_LOG_FUNCIN;
  4073. /*** Initialize Local Variables */
  4074. compFlag = EPS_RLE_COMPRESS_DONE;
  4075. /*** Initialize global valiable */
  4076. memset(sendDataBuf, 0xFF, (EPS_UINT32)sendDataBufSize);
  4077. memset(tmpLineBuf, 0xFF, (EPS_UINT32)tmpLineBufSize );
  4078. /*** Initialize valiable */
  4079. sdBuf = sendDataBuf;
  4080. compData = tmpLineBuf;
  4081. /* EPS_DBGPRINT(("MakeOneRasterData: T,B,L,R [%d,%d,%d,%d]\r\n",
  4082. pBandRec->top, pBandRec->bottom, pBandRec->left, pBandRec->right));
  4083. */
  4084. if( (EPS_UINT32)(pBandRec->right - pBandRec->left) <= printJob.printableAreaWidth){
  4085. linePixelSize = (EPS_UINT16)(pBandRec->right - pBandRec->left);
  4086. } else{
  4087. linePixelSize = (EPS_UINT16) printJob.printableAreaWidth;
  4088. }
  4089. #if ESCPR_DEBUG_IMAGE_LOG
  4090. EPS_DBGPRINT(("ESCPRCMD : ImageData\r\n")
  4091. EPS_DUMP(pInBmp->bits, (pBandRec->right - pBandRec->left) * 3)
  4092. #endif
  4093. /*** Layout Filter */
  4094. if(EPS_MLID_CDLABEL == printJob.attr.printLayout){
  4095. #ifdef GCOMSW_EL_CDLABEL
  4096. elCDClipping(pInBmp->bits, sdBuf, printJob.bpp, pBandRec);
  4097. srcAddr = sdBuf;
  4098. #else
  4099. srcAddr = pInBmp->bits;
  4100. #endif
  4101. } else{
  4102. srcAddr = pInBmp->bits;
  4103. }
  4104. /*** RunLength Encode */
  4105. compDataSize = RunLengthEncode(srcAddr,
  4106. compData,
  4107. linePixelSize,
  4108. printJob.bpp,
  4109. &compFlag);
  4110. //compFlag = EPS_RLE_COMPRESS_NOT_DONE;
  4111. if(compDataSize < 0){
  4112. //return compDataSize;
  4113. }
  4114. /* Set Parameter Length */
  4115. paramSize = (EPS_UINT32)(ESCPR_SEND_DATA_LENGTH + compDataSize);
  4116. cmdSize = ESCPR_HEADER_LENGTH + paramSize;
  4117. /*** Set Parameter */
  4118. cpyCount = 0;
  4119. /* Header */
  4120. memcpy(sdBuf, SendDataCmd, sizeof(SendDataCmd));
  4121. cpyCount += sizeof(SendDataCmd);
  4122. /* Parameter Length */
  4123. memSetEndian(EPS_ENDIAN_LITTLE, EPS_4_BYTES, (EPS_UINT32)paramSize, array4);
  4124. memcpy(sdBuf + cpyCount, array4, sizeof(array4));
  4125. cpyCount += sizeof(array4);
  4126. /* Command Name */
  4127. memcpy(sdBuf + cpyCount, SendDataName, sizeof(SendDataName));
  4128. cpyCount += sizeof(SendDataName);
  4129. /* lXoffset */
  4130. memSetEndian(EPS_ENDIAN_BIG, EPS_2_BYTES, (EPS_UINT32)pBandRec->left, array2);
  4131. memcpy((sdBuf + cpyCount), array2, sizeof(array2));
  4132. cpyCount += sizeof(array2);
  4133. /* lYoffset */
  4134. memSetEndian(EPS_ENDIAN_BIG, EPS_2_BYTES, (EPS_UINT32)pBandRec->top, array2);
  4135. memcpy((sdBuf + cpyCount), array2, sizeof(array2));
  4136. cpyCount += sizeof(array2);
  4137. /* Compression Mode */
  4138. if(compFlag == EPS_RLE_COMPRESS_DONE){
  4139. *(sdBuf + cpyCount) = EPS_COMP_RLE;
  4140. } else{
  4141. *(sdBuf + cpyCount) = EPS_COMP_NON;
  4142. }
  4143. cpyCount += sizeof(EPS_UINT8);
  4144. /* Raster Data Size */
  4145. memSetEndian(EPS_ENDIAN_BIG, EPS_2_BYTES, (EPS_UINT32)compDataSize, array2);
  4146. memcpy((sdBuf + cpyCount), array2, sizeof(array2));
  4147. cpyCount += sizeof(array2);
  4148. /* RGB Raster Data */
  4149. memcpy((sdBuf + cpyCount), compData, compDataSize);
  4150. cpyCount += compDataSize;
  4151. if (cmdSize != cpyCount) {
  4152. EPS_RETURN( EPS_ERR_OPR_FAIL );
  4153. }
  4154. /* Send Print Quality Command to Printer */
  4155. /*** -----------------------------------------------------*/
  4156. #if LCOMSW_PACKET_4KB /* Set 1 packett size in 4096byte */
  4157. /*** -----------------------------------------------------*/
  4158. if(cmdSize > ESCPR_PACKET_SIZE_4KB) {
  4159. /* Send 4090 bytes Data */
  4160. for(idx = 0; idx < (EPS_INT32)(cmdSize / ESCPR_PACKET_SIZE_4KB); idx++){
  4161. #if ESCPR_DEBUG_IMAGE_LOG
  4162. EPS_DUMP(sdBuf, ESCPR_PACKET_SIZE_4KB)
  4163. #endif /* ESCPR_DEBUG_IMAGE_LOG */
  4164. retBufSize = 0;
  4165. retStatus = SendCommand(sdBuf, ESCPR_PACKET_SIZE_4KB, &retBufSize, TRUE);
  4166. if (!((retStatus == EPS_ERR_NONE) && (ESCPR_PACKET_SIZE_4KB == retBufSize))) {
  4167. EPS_RETURN( retStatus );
  4168. }
  4169. sdBuf += ESCPR_PACKET_SIZE_4KB;
  4170. }
  4171. /* Send Rest Data */
  4172. rest_size = cmdSize - ((EPS_INT32)(cmdSize / ESCPR_PACKET_SIZE_4KB)) * ESCPR_PACKET_SIZE_4KB;
  4173. retBufSize = 0;
  4174. retStatus = SendCommand(sdBuf, rest_size, &retBufSize, TRUE);
  4175. if (!((retStatus == EPS_ERR_NONE) && (rest_size == retBufSize))) {
  4176. EPS_RETURN( retStatus );
  4177. }
  4178. #if ESCPR_DEBUG_IMAGE_LOG
  4179. EPS_DUMP(sdBuf, rest_size)
  4180. #endif /* ESCPR_DEBUG_IMAGE_LOG */
  4181. } else /* if(cmdSize <= ESCPR_PACKET_SIZE_4KB) */{
  4182. #if ESCPR_DEBUG_IMAGE_LOG
  4183. EPS_DUMP(sdBuf, cmdSize)
  4184. #endif /* ESCPR_DEBUG_IMAGE_LOG */
  4185. retBufSize = 0;
  4186. retStatus = SendCommand(sdBuf, cmdSize, &retBufSize, TRUE);
  4187. if (!((retStatus == EPS_ERR_NONE) && (cmdSize == retBufSize))) {
  4188. EPS_RETURN( retStatus );
  4189. }
  4190. }
  4191. /*** -----------------------------------------------------*/
  4192. #else /* LCOMSW_PACKET_4KB */
  4193. /*** -----------------------------------------------------*/
  4194. #if ESCPR_DEBUG_IMAGE_LOG
  4195. EPS_DUMP(sdBuf, cpyCount)
  4196. #endif /* ESCPR_DEBUG_IMAGE_LOG */
  4197. retBufSize = 0;
  4198. retStatus = SendCommand(sdBuf, cmdSize, &retBufSize, TRUE);
  4199. if (!((retStatus == EPS_ERR_NONE) && (cmdSize == retBufSize))) {
  4200. EPS_RETURN( retStatus );
  4201. }
  4202. /*** -----------------------------------------------------*/
  4203. #endif /* LCOMSW_PACKET_4KB */
  4204. /*** -----------------------------------------------------*/
  4205. EPS_RETURN( EPS_ERR_NONE );
  4206. }
  4207. /*******************************************|********************************************/
  4208. /* */
  4209. /* Function name: RunLengthEncode() */
  4210. /* */
  4211. /* Arguments */
  4212. /* --------- */
  4213. /* Name: Type: Description: */
  4214. /* pSrcAddr const EPS_UINT8* I: An address of original raster */
  4215. /* pDstAddr EPS_UINT8* O: An address of compressed raster */
  4216. /* pixel EPS_INT16 I: Original Raster Size */
  4217. /* bpp EPS_UINT8 I: Bytes Per Pixel */
  4218. /* pCompress EPS_UINT8* O: Compression Flag */
  4219. /* */
  4220. /* Return value: */
  4221. /* Compressed Data Size (byte) */
  4222. /* */
  4223. /* Description: */
  4224. /* Runlength Compression for RGB Data. */
  4225. /* */
  4226. /*******************************************|********************************************/
  4227. static EPS_UINT16 RunLengthEncode (
  4228. const EPS_UINT8* pSrcAddr,
  4229. EPS_UINT8* pDstAddr,
  4230. EPS_UINT16 pixel,
  4231. EPS_UINT8 bpp,
  4232. EPS_UINT8* pCompress
  4233. ){
  4234. const EPS_UINT8* pSrcPos = pSrcAddr; /* pointer to srcBuffer */
  4235. EPS_UINT8* pDstPos = pDstAddr; /* pointer to destBuffer */
  4236. EPS_UINT16 srcCnt = 0; /* counter */
  4237. EPS_UINT16 repCnt = 0; /* replay conter */
  4238. EPS_UINT16 retCnt = 0; /* conpressed data size */
  4239. EPS_UINT32 copySize = 0;
  4240. EPS_UINT16 widthPixels = pixel * bpp;
  4241. EPS_BOOL bCompress = TRUE;
  4242. EPS_LOG_FUNCIN;
  4243. int i_index = 0;
  4244. while (srcCnt < pixel) {
  4245. /* In case of replay data */
  4246. if ((srcCnt + 1 < pixel) && (!memcmp(pSrcPos, pSrcPos + bpp, bpp))) {
  4247. repCnt = 2;
  4248. while ((srcCnt + repCnt < pixel) &&
  4249. (repCnt < 0x81) &&
  4250. (!memcmp(pSrcPos + (repCnt - 1) * bpp, pSrcPos + repCnt * bpp, bpp)) ) {
  4251. repCnt++;
  4252. }
  4253. /* Renewal compressed data size counter */
  4254. retCnt += 1 + bpp;
  4255. /* If compressed data size is bigger than original data size, */
  4256. /* stop compression process. */
  4257. if( retCnt > widthPixels ){
  4258. bCompress = FALSE;
  4259. retCnt -= 1 + bpp; /* rewind counter */
  4260. break;
  4261. }
  4262. /* Set replay count and data */
  4263. /* Set data counter */
  4264. if(pDstPos == NULL || (pDstPos+1) == NULL || (pDstPos + bpp) == NULL || pSrcPos == NULL ||( pSrcPos + bpp * repCnt) == NULL){
  4265. return i_index * (-1);
  4266. }
  4267. *pDstPos++ = (EPS_UINT8)(0xFF - repCnt + 2 );
  4268. /* Set data */
  4269. memcpy(pDstPos, pSrcPos, bpp);
  4270. /* Renewal data size counter */
  4271. srcCnt += repCnt;
  4272. i_index += bpp * repCnt;
  4273. /* Renewal original data address */
  4274. if((pSrcPos + bpp * repCnt) == NULL){
  4275. return i_index * (-1);
  4276. }
  4277. pSrcPos += bpp * repCnt;
  4278. /* Renewal compressed data address */
  4279. pDstPos += bpp;
  4280. }
  4281. /* In case of non replay data */
  4282. else {
  4283. copySize = 0;
  4284. repCnt = 1;
  4285. /* compare next data with next and next data */
  4286. while ((srcCnt + repCnt + 1< pixel) &&
  4287. (repCnt < 0x80) &&
  4288. (memcmp(pSrcPos + repCnt * bpp, pSrcPos + (repCnt + 1) * bpp, bpp)) ){
  4289. repCnt++;
  4290. }
  4291. /* Renewal compressed data size counter */
  4292. retCnt += 1 + repCnt * bpp;
  4293. /* If compressed data size is bigger than original data size, */
  4294. /* stop compression process. */
  4295. if( retCnt > widthPixels ){
  4296. bCompress = FALSE;
  4297. retCnt -= 1 + repCnt * bpp; /* rewind counter */
  4298. break;
  4299. }
  4300. /* Set data counter */
  4301. if(pDstPos == NULL || (pDstPos +1) == NULL){
  4302. return i_index *(-1);
  4303. }
  4304. *pDstPos++ = (EPS_UINT8)(repCnt - 1);
  4305. /* Renewal data size counter */
  4306. /* Size of non replay data (byte) */
  4307. srcCnt += repCnt;
  4308. copySize = (EPS_UINT32)(repCnt * bpp);
  4309. if(pDstPos == NULL || (pDstPos +1) == NULL || (pDstPos + copySize) == NULL || (pSrcPos + copySize) == NULL || pSrcPos == NULL){
  4310. return i_index * (-1);
  4311. }
  4312. /* Set data */
  4313. memcpy(pDstPos, pSrcPos, copySize);
  4314. /* Renewal original data address */
  4315. pSrcPos += copySize;
  4316. /* Renewal compressed data address */
  4317. pDstPos += copySize;
  4318. i_index += copySize;
  4319. }
  4320. }
  4321. if(TRUE == bCompress){
  4322. *pCompress = EPS_RLE_COMPRESS_DONE;
  4323. } else{
  4324. retCnt = widthPixels;
  4325. memcpy(pDstAddr, pSrcAddr, widthPixels);
  4326. *pCompress = EPS_RLE_COMPRESS_NOT_DONE;
  4327. }
  4328. EPS_RETURN( retCnt );
  4329. }
  4330. /*******************************************|********************************************/
  4331. /* */
  4332. /* Function name: CreateMediaInfo() */
  4333. /* */
  4334. /* Arguments */
  4335. /* --------- */
  4336. /* Name: Type: Description: */
  4337. /* innerPrinter EPS_PRINTER_INN* I: printer that it has original structure */
  4338. /* pmString EPS_INT8* I: PM reply string */
  4339. /* pmSize EPS_INT32 I: size of PM reply string */
  4340. /* */
  4341. /* Return value: */
  4342. /* EPS_ERR_NONE - Success */
  4343. /* EPS_ERR_OPR_FAIL - Internal Error */
  4344. /* EPS_ERR_MEMORY_ALLOCATION - Alloc memory failed */
  4345. /* */
  4346. /* Description: */
  4347. /* Marge paper source to EPS_SUPPORTED_MEDIA. */
  4348. /* */
  4349. /*******************************************|********************************************/
  4350. EPS_ERR_CODE CreateMediaInfo(
  4351. EPS_PRINTER_INN* innerPrinter,
  4352. EPS_UINT8* pmString,
  4353. EPS_INT32 pmSize
  4354. ){
  4355. EPS_ERR_CODE retStatus = EPS_ERR_NONE;
  4356. EPS_UINT8* cmdField; /* Pointer of pm command field */
  4357. EPS_INT32 pmIdx; /* pm string index */
  4358. EPS_UINT32 idx; /* Index */
  4359. EPS_INT32 sIdx = 0; /* Media size index */
  4360. EPS_INT32 tIdx = 0; /* Media type index */
  4361. EPS_INT32 num_mType = 0; /* Media type number */
  4362. EPS_INT32 num_mSize = 0; /* Media size number */
  4363. EPS_BOOL extPaper = FALSE; /* extend paper source is exist */
  4364. EPS_LOG_FUNCIN;
  4365. /*** Is this really "PM" data */
  4366. cmdField = (EPS_UINT8*)strstr((const char*)pmString,"PM");
  4367. if (cmdField == NULL ) {
  4368. EPS_DBGPRINT(("Get Model Info faild : ModelInfo = [%s]\r\n",pmString));
  4369. EPS_RETURN( EPS_ERR_OPR_FAIL );
  4370. }
  4371. EPS_DUMP(pmString, 256);
  4372. #if _VALIDATE_SUPPORTED_MEDIA_DATA_
  4373. if(innerPrinter->supportedMedia.numSizes != -1){
  4374. /*** "Filter" Raw "PM" data (Remake the correct pm stirng) */
  4375. retStatus = _SP_ChangeSpec_UpdatePMReply(innerPrinter, pmString, pmSize);
  4376. if (retStatus != EPS_ERR_NONE) {
  4377. EPS_RETURN( retStatus );
  4378. }
  4379. }
  4380. #else
  4381. /*** "Filter" Raw "PM" data (Remake the correct pm stirng) */
  4382. retStatus = _SP_ChangeSpec_UpdatePMReply(innerPrinter, pmString, pmSize);
  4383. if (retStatus != EPS_ERR_NONE) {
  4384. EPS_RETURN( EPS_ERR_OPR_FAIL ); /* Invalid format */
  4385. }
  4386. #endif
  4387. /*** Create the structure of the support media */
  4388. innerPrinter->supportedMedia.resolution = EPS_IR_360X360; /* default support */
  4389. /*** Count "Paper Size" field & check format */
  4390. pmIdx = EPS_PM_HEADER_LEN; /* skip the command header of pm string */
  4391. while( pmIdx < EPS_PM_MAXSIZE ) {
  4392. switch(pmString[pmIdx]) {
  4393. case 'R':
  4394. if( 720 == ((pmString[pmIdx+1] << 8) + pmString[pmIdx+2]) ){
  4395. innerPrinter->supportedMedia.resolution |= EPS_IR_720X720;
  4396. } else if( 600 == ((pmString[pmIdx+1] << 8) + pmString[pmIdx+2]) ){
  4397. innerPrinter->supportedMedia.resolution |= EPS_IR_300X300 | EPS_IR_600X600;
  4398. } else if( 300 == ((pmString[pmIdx+1] << 8) + pmString[pmIdx+2]) ){
  4399. innerPrinter->supportedMedia.resolution |= EPS_IR_300X300;
  4400. }
  4401. pmIdx += 6;
  4402. break;
  4403. case 'M':
  4404. innerPrinter->supportedMedia.JpegSizeLimit =
  4405. (pmString[pmIdx+1] << 24) + (pmString[pmIdx+2] << 16) + (pmString[pmIdx+3] << 8) + pmString[pmIdx+4];
  4406. innerPrinter->JpgMax = innerPrinter->supportedMedia.JpegSizeLimit;
  4407. pmIdx += 6;
  4408. break;
  4409. case 'S':
  4410. /* move T field */
  4411. if(pmIdx < EPS_PM_MAXSIZE-2){
  4412. pmIdx += 2;
  4413. } else{
  4414. EPS_RETURN( EPS_ERR_OPR_FAIL );
  4415. }
  4416. num_mSize++;
  4417. for(; pmIdx < EPS_PM_MAXSIZE-4; pmIdx += 4) { /* 4 = T x x / */
  4418. if(pmString[pmIdx] == '/'){
  4419. pmIdx += 1;
  4420. break;
  4421. } else if(pmString[pmIdx] != 'T') {
  4422. EPS_RETURN( EPS_ERR_OPR_FAIL );
  4423. }
  4424. }
  4425. if(pmIdx >= EPS_PM_MAXSIZE-4){
  4426. EPS_RETURN( EPS_ERR_OPR_FAIL );
  4427. }
  4428. break;
  4429. default:
  4430. EPS_RETURN( EPS_ERR_OPR_FAIL ); /* bad format */
  4431. }
  4432. /* If we run into an occurrence of carriage return followed by line feed,
  4433. * we have found the terminating characters of the string. */
  4434. if(pmString[pmIdx] == 0x0D && pmString[pmIdx+1] == 0x0A) {
  4435. break;
  4436. }
  4437. }
  4438. if(pmIdx >= EPS_PM_MAXSIZE){
  4439. EPS_RETURN( EPS_ERR_OPR_FAIL ); /* bad format */
  4440. }
  4441. /* Allocate memory for the media size list. */
  4442. innerPrinter->supportedMedia.sizeList =
  4443. (EPS_MEDIA_SIZE*)EPS_ALLOC( sizeof(EPS_MEDIA_SIZE) * num_mSize );
  4444. if( innerPrinter->supportedMedia.sizeList == NULL ){
  4445. EPS_RETURN( EPS_ERR_MEMORY_ALLOCATION );
  4446. }
  4447. memset(innerPrinter->supportedMedia.sizeList, 0, sizeof(EPS_MEDIA_SIZE) * num_mSize);
  4448. innerPrinter->supportedMedia.numSizes = num_mSize;
  4449. pmIdx = EPS_PM_HEADER_LEN; /* skip the command header of pm string */
  4450. for(sIdx = 0; sIdx < num_mSize; sIdx++) {
  4451. if(pmString[pmIdx] == 'M' || pmString[pmIdx] == 'R') {
  4452. pmIdx += 6;
  4453. sIdx--;
  4454. continue;
  4455. }
  4456. innerPrinter->supportedMedia.sizeList[sIdx].mediaSizeID = pmString[pmIdx+1];
  4457. /* EPS_DBGPRINT(("Size=%d\r\n", pmString[pmIdx+1]));*/
  4458. pmIdx += 2;
  4459. /* For the given paper type, iterate through the paper type to get the number
  4460. * of media types contained in it */
  4461. num_mType = 0;
  4462. for(idx = pmIdx; idx < EPS_PM_MAXSIZE-4; idx += 4) {
  4463. if(pmString[idx] == '/'){
  4464. idx += 1;
  4465. break;
  4466. }
  4467. num_mType++;
  4468. }
  4469. /* Allocate memory for the media type array. */
  4470. innerPrinter->supportedMedia.sizeList[sIdx].typeList =
  4471. (EPS_MEDIA_TYPE*)EPS_ALLOC( sizeof(EPS_MEDIA_TYPE) * num_mType );
  4472. if (innerPrinter->supportedMedia.sizeList[sIdx].typeList == NULL) {
  4473. EPS_RETURN( EPS_ERR_MEMORY_ALLOCATION );
  4474. }
  4475. memset(innerPrinter->supportedMedia.sizeList[sIdx].typeList, 0, sizeof(EPS_MEDIA_TYPE) * num_mType);
  4476. innerPrinter->supportedMedia.sizeList[sIdx].numTypes = num_mType;
  4477. for(tIdx = 0; tIdx < num_mType; tIdx++) {
  4478. innerPrinter->supportedMedia.sizeList[sIdx].typeList[tIdx].mediaTypeID = pmString[pmIdx+1];
  4479. /* EPS_DBGPRINT(("\tType=%d (%02X)\r\n", pmString[pmIdx+1], pmString[pmIdx+2]));*/
  4480. /* Bitwise OR with 10000000 - Check for borderless */
  4481. if( pmString[pmIdx+2] & 0x80 ){
  4482. innerPrinter->supportedMedia.sizeList[sIdx].typeList[tIdx].layout |= EPS_MLID_BORDERLESS;
  4483. }
  4484. /* Bitwise OR with 01000000 - Check for border "disable" mode */
  4485. if( !(pmString[pmIdx+2] & 0x40) ){
  4486. innerPrinter->supportedMedia.sizeList[sIdx].typeList[tIdx].layout |= EPS_MLID_BORDERS;
  4487. }
  4488. /* set quality */
  4489. innerPrinter->supportedMedia.sizeList[sIdx].typeList[tIdx].quality |= (pmString[pmIdx+2] & EPS_MQID_ALL);
  4490. /* set duplex */
  4491. if( pmString[pmIdx+2] & 0x10 &&
  4492. obsEnableDuplex(innerPrinter->supportedMedia.sizeList[sIdx].mediaSizeID) ){
  4493. innerPrinter->supportedMedia.sizeList[sIdx].typeList[tIdx].duplex = EPS_DUPLEX_ENABLE;/*EPS_DUPLEX_SHORT*/;
  4494. } else{
  4495. innerPrinter->supportedMedia.sizeList[sIdx].typeList[tIdx].duplex = EPS_DUPLEX_DISABLE;
  4496. }
  4497. /* Bitwise OR with 00001000 - Check for extend paper source */
  4498. #if _VALIDATE_SUPPORTED_MEDIA_DATA_
  4499. if( pmString[pmIdx+2] & 0x08 ){
  4500. extPaper = TRUE;
  4501. } else {
  4502. /* DEFAULT. All printer support rear paper source */
  4503. innerPrinter->supportedMedia.sizeList[sIdx].typeList[tIdx].paperSource = EPS_MPID_REAR;
  4504. }
  4505. /* param2 value check */
  4506. if( !(pmString[pmIdx+2] & (0x01 | 0x02 | 0x04)) ){
  4507. printf("\n\n!!!!!!!!! Quality is not described. !!!!!!!!!\n"
  4508. "SizeID=0x%02X / TypeID=0x%02X / param2=0x%02X\n",
  4509. innerPrinter->supportedMedia.sizeList[sIdx].mediaSizeID,
  4510. pmString[pmIdx+1], pmString[pmIdx+2]);
  4511. }
  4512. if( !(pmString[pmIdx+2] & 0x80) && (pmString[pmIdx+2] & 0x40) ){
  4513. printf("\n\n!!!!!!!!! Layout is not described. !!!!!!!!!\n"
  4514. "SizeID=0x%02X / TypeID=0x%02X / param2=0x%02X\n",
  4515. innerPrinter->supportedMedia.sizeList[sIdx].mediaSizeID,
  4516. pmString[pmIdx+1], pmString[pmIdx+2]);
  4517. }
  4518. #else
  4519. if( pmString[pmIdx+2] & 0x08 ){
  4520. extPaper = TRUE;
  4521. }
  4522. /* DEFAULT. All printer support rear paper source */
  4523. innerPrinter->supportedMedia.sizeList[sIdx].typeList[tIdx].paperSource = EPS_MPID_REAR;
  4524. #endif
  4525. pmIdx += 4; /* move next field */
  4526. }
  4527. pmIdx += 1; /* skip terminater */
  4528. }
  4529. /*** Add extend infomation */
  4530. if( EPS_ERR_NONE == retStatus && TRUE == extPaper ){
  4531. retStatus = GetPaperSource(innerPrinter);
  4532. if( EPS_ERR_NONE != retStatus){
  4533. prtClearSupportedMedia(innerPrinter);
  4534. }
  4535. }
  4536. serAppendMedia(&innerPrinter->supportedMedia);
  4537. EPS_RETURN( retStatus );
  4538. }
  4539. /*******************************************|********************************************/
  4540. /* */
  4541. /* Function name: GetPaperSource() */
  4542. /* */
  4543. /* Arguments */
  4544. /* --------- */
  4545. /* Name: Type: Description: */
  4546. /* innerPrinter EPS_PRINTER_INN* I: printer that it has original structure */
  4547. /* */
  4548. /* Return value: */
  4549. /* EPS_ERR_NONE - Success */
  4550. /* EPS_ERR_OPR_FAIL - Internal Error */
  4551. /* */
  4552. /* Description: */
  4553. /* Marge paper source to EPS_SUPPORTED_MEDIA. */
  4554. /* */
  4555. /*******************************************|********************************************/
  4556. EPS_ERR_CODE GetPaperSource(
  4557. EPS_PRINTER_INN* innerPrinter
  4558. ){
  4559. EPS_ERR_CODE ret = EPS_ERR_NONE;
  4560. EPS_UINT8 pmString[EPS_PM_MAXSIZE]; /* Retrieved PM data from printer */
  4561. EPS_INT32 pmSize = EPS_PM_MAXSIZE;
  4562. EPS_UINT32 pmIdx; /* pm string index */
  4563. EPS_INT32 sIdx = 0; /* Media size index */
  4564. EPS_INT32 tIdx = 0; /* Media type index */
  4565. EPS_MEDIA_SIZE *pMSize = NULL;
  4566. EPS_LOG_FUNCIN;
  4567. /* Clear the Printer Model Information (Media data or "PM" data) */
  4568. memset(pmString, 0, EPS_PM_MAXSIZE);
  4569. /*** Get PM2 from Printer */
  4570. ret = prtGetPMString(innerPrinter, 2, pmString, &pmSize);
  4571. if(ret == EPS_ERR_PROTOCOL_NOT_SUPPORTED){
  4572. EPS_RETURN( EPS_ERR_NONE );
  4573. } else if(ret != EPS_ERR_NONE){
  4574. EPS_RETURN( ret );
  4575. }
  4576. /*** Is this really "PM" data */
  4577. if( strstr((const char*)pmString, "PM") == NULL ) {
  4578. EPS_DBGPRINT(("Get Model Info faild : ModelInfo = [%s]\r\n", pmString));
  4579. EPS_RETURN( EPS_ERR_OPR_FAIL );
  4580. }
  4581. /* Delete the command header of pm string */
  4582. pmIdx = EPS_PM_HEADER_LEN; /* skip the command header of pm string */
  4583. /*** Check to make sure the PM reply has a valid beginning */
  4584. if(pmString[pmIdx] != 'S' && pmString[pmIdx+2] != 'T') {
  4585. EPS_RETURN( EPS_ERR_OPR_FAIL );
  4586. }
  4587. /*** Create the structure of the support media */
  4588. /*** Count "Paper Size" field & check format */
  4589. for(; pmIdx < EPS_PM_MAXSIZE-7; ) { /* 7 = S x T x x // */
  4590. if(pmString[pmIdx] != 'S') {
  4591. EPS_RETURN( EPS_ERR_OPR_FAIL ); /* bad format */
  4592. }
  4593. /* search size ID */
  4594. pmIdx++;
  4595. pMSize = NULL;
  4596. for(sIdx = 0; sIdx < innerPrinter->supportedMedia.numSizes; sIdx++){
  4597. if(pmString[pmIdx] == innerPrinter->supportedMedia.sizeList[sIdx].mediaSizeID){
  4598. pMSize = &innerPrinter->supportedMedia.sizeList[sIdx];
  4599. /* EPS_DBGPRINT(("Size = %d\n", innerPrinter->supportedMedia.sizeList[sIdx].mediaSizeID))*/
  4600. break;
  4601. }
  4602. }
  4603. pmIdx++; /* move next field */
  4604. while( pmIdx < EPS_PM_MAXSIZE-4 ){ /* 4 = T x x / */
  4605. if(pmString[pmIdx] == 'T'){
  4606. if(NULL != pMSize){
  4607. /* search type ID */
  4608. pmIdx++;
  4609. for(tIdx = 0; tIdx < pMSize->numTypes; tIdx++){
  4610. if(pmString[pmIdx] == pMSize->typeList[tIdx].mediaTypeID){
  4611. pMSize->typeList[tIdx].paperSource = pmString[pmIdx+1];
  4612. #if !_VALIDATE_SUPPORTED_MEDIA_DATA_
  4613. pMSize->typeList[tIdx].paperSource &= EPS_MPID_ALL_ESCPR;
  4614. #endif
  4615. pmIdx += 3;
  4616. break;
  4617. }
  4618. }
  4619. if(tIdx >= pMSize->numTypes){
  4620. /* Skip unknown T */
  4621. #if _VALIDATE_SUPPORTED_MEDIA_DATA_
  4622. printf("\n\n!!!!!!!!! pm2 contains TypeID(0x%02X) that doesn't exist in pm1. !!!!!!!!!\n", pmString[pmIdx]);
  4623. #endif
  4624. pmIdx += 3;
  4625. }
  4626. } else{
  4627. /* Skip unknown S */
  4628. #if _VALIDATE_SUPPORTED_MEDIA_DATA_
  4629. printf("\n\n!!!!!!!!! pm2 contains SizeID(0x%02X) that doesn't exist in pm1. !!!!!!!!!\n", pmString[pmIdx]);
  4630. #endif
  4631. pmIdx += 4;
  4632. }
  4633. } else if(pmString[pmIdx] == '/') {
  4634. pmIdx++;
  4635. break;
  4636. } else{
  4637. EPS_RETURN( EPS_ERR_OPR_FAIL ); /* bad format */
  4638. }
  4639. }
  4640. if(pmIdx >= EPS_PM_MAXSIZE-4){
  4641. EPS_RETURN( EPS_ERR_OPR_FAIL ); /* bad format */
  4642. }
  4643. /* If we run into an occurrence of carriage return followed by line feed,
  4644. * we have found the terminating characters of the string. */
  4645. if(pmString[pmIdx] == 0x0D && pmString[pmIdx+1] == 0x0A) {
  4646. break;
  4647. }
  4648. }
  4649. if(pmIdx >= EPS_PM_MAXSIZE){
  4650. EPS_RETURN( EPS_ERR_OPR_FAIL ); /* bad format */
  4651. }
  4652. EPS_RETURN( ret );
  4653. }
  4654. /*******************************************|********************************************/
  4655. /* */
  4656. /* Function name: GetJpgMax() */
  4657. /* */
  4658. /* Arguments */
  4659. /* --------- */
  4660. /* Name: Type: Description: */
  4661. /* innerPrinter EPS_PRINTER_INN* IO: printer that it has original structure */
  4662. /* */
  4663. /* Return value: */
  4664. /* EPS_ERR_NONE - Success */
  4665. /* EPS_ERR_OPR_FAIL - Internal Error */
  4666. /* */
  4667. /* Description: */
  4668. /* Marge paper source to EPS_SUPPORTED_MEDIA. */
  4669. /* */
  4670. /*******************************************|********************************************/
  4671. EPS_ERR_CODE GetJpgMax(
  4672. EPS_PRINTER_INN* printer
  4673. ){
  4674. EPS_ERR_CODE ret = EPS_ERR_NONE;
  4675. EPS_UINT8 pmString[EPS_PM_MAXSIZE]; /* Retrieved PM data from printer */
  4676. EPS_INT32 pmSize = EPS_PM_MAXSIZE;
  4677. EPS_UINT32 pmIdx; /* pm string index */
  4678. EPS_LOG_FUNCIN;
  4679. if( !EPS_IS_BI_PROTOCOL(printJob.printer->protocol) ){ /* Uni direction */
  4680. /* set unlimited(2GB) */
  4681. printer->JpgMax = EPS_JPEG_SIZE_UNLIMIT;
  4682. EPS_RETURN( EPS_ERR_NONE )
  4683. }
  4684. /* Clear the Printer Model Information (Media data or "PM" data) */
  4685. memset(pmString, 0, EPS_PM_MAXSIZE);
  4686. /*** Get PM1 from Printer */
  4687. ret = prtGetPMString(printer, 1, pmString, &pmSize);
  4688. if(ret == EPS_ERR_PROTOCOL_NOT_SUPPORTED){
  4689. /* set unlimited(2GB) */
  4690. printer->JpgMax = EPS_JPEG_SIZE_UNLIMIT;
  4691. EPS_RETURN( EPS_ERR_NONE )
  4692. } else if(ret != EPS_ERR_NONE){
  4693. EPS_RETURN( ret );
  4694. }
  4695. /*** "Filter" Raw "PM" data (Remake the correct pm stirng) */
  4696. ret = _SP_ChangeSpec_UpdatePMReply(printer, pmString, pmSize);
  4697. if (ret != EPS_ERR_NONE) {
  4698. EPS_RETURN( EPS_ERR_OPR_FAIL ); /* Invalid format */
  4699. }
  4700. /*** Is this really "PM" data */
  4701. if( strstr((const char*)pmString, "PM") == NULL ) {
  4702. EPS_DBGPRINT(("Get Model Info faild : ModelInfo = [%s]\r\n", pmString));
  4703. EPS_RETURN( EPS_ERR_OPR_FAIL );
  4704. }
  4705. /* Delete the command header of pm string */
  4706. pmIdx = EPS_PM_HEADER_LEN; /* skip the command header of pm string */
  4707. while( pmIdx < EPS_PM_MAXSIZE ) {
  4708. switch(pmString[pmIdx]) {
  4709. case 'M':
  4710. printer->JpgMax =
  4711. (pmString[pmIdx+1] << 24) + (pmString[pmIdx+2] << 16) + (pmString[pmIdx+3] << 8) + pmString[pmIdx+4];
  4712. pmIdx += 6;
  4713. break;
  4714. case 'R':
  4715. pmIdx += 6;
  4716. break;
  4717. case 'S':
  4718. /* move T field */
  4719. if(pmIdx < EPS_PM_MAXSIZE-2){
  4720. pmIdx += 2;
  4721. } else{
  4722. EPS_RETURN( EPS_ERR_OPR_FAIL );
  4723. }
  4724. for(; pmIdx < EPS_PM_MAXSIZE-4; pmIdx += 4) { /* 4 = T x x / */
  4725. if(pmString[pmIdx] == '/'){
  4726. pmIdx += 1;
  4727. break;
  4728. } else if(pmString[pmIdx] != 'T') {
  4729. EPS_RETURN( EPS_ERR_OPR_FAIL );
  4730. }
  4731. }
  4732. if(pmIdx >= EPS_PM_MAXSIZE-4){
  4733. EPS_RETURN( EPS_ERR_OPR_FAIL );
  4734. }
  4735. break;
  4736. default:
  4737. EPS_RETURN( EPS_ERR_OPR_FAIL ); /* bad format */
  4738. }
  4739. /* If we run into an occurrence of carriage return followed by line feed,
  4740. * we have found the terminating characters of the string. */
  4741. if(pmString[pmIdx] == 0x0D && pmString[pmIdx+1] == 0x0A) {
  4742. break;
  4743. }
  4744. }
  4745. if(pmIdx >= EPS_PM_MAXSIZE || 0 == printer->JpgMax){
  4746. EPS_RETURN( EPS_ERR_OPR_FAIL ); /* bad format */
  4747. }
  4748. EPS_RETURN( ret );
  4749. }
  4750. /*******************************************|********************************************/
  4751. /* */
  4752. /* Function name: DuplSupportedMedia() */
  4753. /* */
  4754. /* Arguments */
  4755. /* --------- */
  4756. /* Name: Type: Description: */
  4757. /* innerPrinter EPS_PRINTER_INN* I: printer that it has original structure */
  4758. /* pMedia EPS_SUPPORTED_MEDIA* O: pointer to a distination */
  4759. /* */
  4760. /* Return value: */
  4761. /* EPS_ERR_NONE - Success */
  4762. /* EPS_ERR_MEMORY_ALLOCATION - Alloc memory failed */
  4763. /* */
  4764. /* Description: */
  4765. /* Duplicate EPS_SUPPORTED_MEDIA to user buffer. */
  4766. /* */
  4767. /*******************************************|********************************************/
  4768. EPS_ERR_CODE DuplSupportedMedia(
  4769. EPS_PRINTER_INN* innerPrinter,
  4770. EPS_SUPPORTED_MEDIA* pMedia
  4771. ){
  4772. EPS_ERR_CODE ret = EPS_ERR_NONE;
  4773. EPS_INT32 idx;
  4774. EPS_LOG_FUNCIN;
  4775. ClearSupportedMedia();
  4776. g_supportedMedia.JpegSizeLimit = innerPrinter->supportedMedia.JpegSizeLimit;
  4777. g_supportedMedia.resolution = innerPrinter->supportedMedia.resolution;
  4778. g_supportedMedia.numSizes = innerPrinter->supportedMedia.numSizes;
  4779. g_supportedMedia.sizeList = (EPS_MEDIA_SIZE*)EPS_ALLOC( sizeof(EPS_MEDIA_SIZE) * innerPrinter->supportedMedia.numSizes );
  4780. if( g_supportedMedia.sizeList ){
  4781. for(idx = 0; idx < innerPrinter->supportedMedia.numSizes; idx++) {
  4782. g_supportedMedia.sizeList[idx].mediaSizeID = innerPrinter->supportedMedia.sizeList[idx].mediaSizeID;
  4783. g_supportedMedia.sizeList[idx].numTypes = innerPrinter->supportedMedia.sizeList[idx].numTypes;
  4784. g_supportedMedia.sizeList[idx].typeList =
  4785. (EPS_MEDIA_TYPE*)EPS_ALLOC( sizeof(EPS_MEDIA_TYPE) * innerPrinter->supportedMedia.sizeList[idx].numTypes );
  4786. if( g_supportedMedia.sizeList[idx].typeList ){
  4787. memcpy(g_supportedMedia.sizeList[idx].typeList,
  4788. innerPrinter->supportedMedia.sizeList[idx].typeList,
  4789. sizeof(EPS_MEDIA_TYPE) * innerPrinter->supportedMedia.sizeList[idx].numTypes);
  4790. } else{
  4791. ret = EPS_ERR_MEMORY_ALLOCATION;
  4792. break;
  4793. }
  4794. }
  4795. } else{
  4796. ret = EPS_ERR_MEMORY_ALLOCATION;
  4797. }
  4798. if(EPS_ERR_NONE == ret){
  4799. /* Copy to out param */
  4800. pMedia->JpegSizeLimit = g_supportedMedia.JpegSizeLimit;
  4801. pMedia->resolution = g_supportedMedia.resolution;
  4802. pMedia->numSizes = g_supportedMedia.numSizes;
  4803. pMedia->sizeList = g_supportedMedia.sizeList;
  4804. } else{
  4805. /* If error occur, unwind. */
  4806. for(idx = 0; idx < g_supportedMedia.numSizes; idx++) {
  4807. EPS_SAFE_RELEASE(g_supportedMedia.sizeList[idx].typeList);
  4808. }
  4809. EPS_SAFE_RELEASE(g_supportedMedia.sizeList);
  4810. g_supportedMedia.numSizes = 0;
  4811. }
  4812. EPS_RETURN( ret );
  4813. }
  4814. /*******************************************|********************************************/
  4815. /* */
  4816. /* Function name: ClearSupportedMedia() */
  4817. /* */
  4818. /* Arguments */
  4819. /* --------- */
  4820. /* Name: Type: Description: */
  4821. /* (none) */
  4822. /* */
  4823. /* Return value: */
  4824. /* void */
  4825. /* */
  4826. /* Description: */
  4827. /* Crean up inside list of supported media structure. */
  4828. /* */
  4829. /*******************************************|********************************************/
  4830. void ClearSupportedMedia(
  4831. void
  4832. ){
  4833. EPS_INT32 idx;
  4834. EPS_LOG_FUNCIN;
  4835. /* Clear "supportedMedia" */
  4836. if( NULL != g_supportedMedia.sizeList){
  4837. for(idx = 0; idx < g_supportedMedia.numSizes; idx++) {
  4838. EPS_SAFE_RELEASE(g_supportedMedia.sizeList[idx].typeList);
  4839. }
  4840. EPS_SAFE_RELEASE(g_supportedMedia.sizeList);
  4841. g_supportedMedia.numSizes = 0;
  4842. }
  4843. EPS_RETURN_VOID;
  4844. }
  4845. /*_______________________________ epson-escpr-api.c ________________________________*/
  4846. /*34567890123456789012345678901234567890123456789012345678901234567890123456789012345678*/
  4847. /* 1 2 3 4 5 6 7 8 */
  4848. /*******************************************|********************************************/
  4849. /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%|%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
  4850. /***** End of File *** End of File *** End of File *** End of File *** End of File ******/
  4851. /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%|%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/