10 #include "evoliserror.h"
\r
13 #define RgbToGray(r, g, b) (((long) (r)*74L + (long)(g)*155L +(long)(b)*27L) >> 8)
\r
16 int STATUS=0; //0 means succes, 1 means failure
\r
17 unsigned char *lpMem;
\r
18 unsigned char *lpRecto,*lpVerso;
\r
19 int Model; /* Model number */
\r
20 long dwSizeNeeded; // taille mmoire du lpMem en octets
\r
25 OverlayBackPannel[10],
\r
34 int Brightness, Contrast, SensibilityK, QualityK, SensibilityO;
\r
35 int TB,LB,BB,RB,TW,LW,BW,RW;
\r
36 int DetectAuto,StartDist;
\r
37 int colorspace,levelB;
\r
42 int DitherPattern1[8][8] = {
\r
43 {0, 112, 28, 140, 7, 119, 35, 147},
\r
44 {168, 56, 196, 84, 175, 63, 203, 78},
\r
45 {42, 154, 14, 126, 49, 161, 21, 114},
\r
46 {210, 98, 182, 70, 217, 105, 189, 77},
\r
47 {11, 123, 39, 151, 4, 116, 32, 143},
\r
48 {179, 67, 207, 95, 172, 59, 200, 88},
\r
49 {53, 165, 24, 137, 46, 158, 18, 111},
\r
50 {221, 109, 193, 81, 214, 102, 159, 74}
\r
55 // Compress and format data for the printer
\r
56 long ReduceBlack(unsigned char *lpMemIn, unsigned char *lpMemOut,int nbrline);
\r
57 long ReduceColor(unsigned char *lpMemIn, unsigned char *lpMemOut, int uiBitComp);//,int nbrline);
\r
58 //int CutPage(long *stop);
\r
60 // Download functions
\r
61 int DBNC(int col,int bl,int ov);//,int line);
\r
62 int DB32NC(long lPos, char color); //y,m,c pannels 5 bits per color
\r
63 int DB64NC(long lPos, char color); //y,m,c pannels 6 bits per color
\r
64 int DB128NC(long lPos, char color); //y,m,c pannels 7 bits per color
\r
65 /*int DB32NCS(long lPos, char color,int line); //y,m,c pannels 5 bits per color
\r
66 int DB64NCS(long lPos, char color,int line); //y,m,c pannels 6 bits per color
\r
67 int DB128NCS(long lPos, char color,int line); //y,m,c pannels 7 bits per color*/
\r
68 int DB2NC(long lPos, char pannel[10]); // k,o panel 2 levels
\r
69 int DB2MNC(long lPos); // k panel 2 levels
\r
71 // Convert RVB to k functions
\r
72 void RVBtoGray(unsigned char *lpMemIn, unsigned char *lpMemOut, long lNbrByte);
\r
73 void KinYMC(long Height, long Width);
\r
74 void GrayToFloyd(unsigned char *lpMemIn, unsigned char *lpMemOut, long Width, long Height);
\r
75 void GrayToDither(unsigned char *lpMemIn, unsigned char *lpMemOut, long Width, long Height);
\r
76 void GrayToThreshold(unsigned char *lpMemIn, unsigned char *lpMemOut, long lNbrByte);
\r
77 void ConvertRVBtoK(unsigned char *lpbRVB, long RVBSize, long Height, long Width, unsigned char *lpBlack);
\r
78 void GetFirstYMCDot(long Height, long Width , int *x, int *y);
\r
81 //===============================================================================//
\r
82 // Reduce color data from 8 bits to uiBitComp.
\r
84 // Entree : 1 color panel (1016 * 648 octets)
\r
85 // Sortie : 1 color panel with usable data ((1016*648)*uiBitComp)/8
\r
86 //===============================================================================//
\r
89 long ReduceColor(unsigned char *lpMemIn, unsigned char *lpMemOut, int uiBitComp)//,int nbrline)
\r
91 long lIndex = 0, lIndex1 = 0;
\r
92 unsigned char *lpbBuf, *lpbData, *lpbDataOut;
\r
94 long lNbrByte = (1016*648);
\r
96 //Reservation m�oire pour traitement d'une ligne
\r
103 //fprintf(stderr, "**************** EVOLIS ReduceColor manque de memoire pour lpBuf: taille demande 8 octets... \n");
\r
104 fatal("ReduceColor Fails memory lpBuf: requested size 8 bytes...");
\r
106 /// sortir de l'impression....
\r
110 //lpbData ppV mem bmp brute
\r
111 lpbData = &lpMemIn[0];
\r
113 lpbDataOut = &lpMemOut[0];
\r
114 // pour toutes les donnees
\r
115 while (lIndex < lNbrByte)
\r
117 //Traite byte par 8
\r
118 for (lIndex1 = 0; lIndex1 < 8; lIndex1++)
\r
120 if (lIndex < lNbrByte)
\r
122 //decalage donnees utiles
\r
123 lpbBuf[lIndex1] = *(lpbData++) >> (8 - uiBitComp);
\r
129 lpbBuf[lIndex1] = 0x00;
\r
136 *(lpbDataOut++) = (lpbBuf[0] << 2) | (lpbBuf[1] >> 4);
\r
137 *(lpbDataOut++) = (lpbBuf[1] << 4) | (lpbBuf[2] >> 2);
\r
138 *(lpbDataOut++) = (lpbBuf[2] << 6) | (lpbBuf[3]);
\r
139 *(lpbDataOut++) = (lpbBuf[4] << 2) | (lpbBuf[5] >> 4);
\r
140 *(lpbDataOut++) = (lpbBuf[5] << 4) | (lpbBuf[6] >> 2);
\r
141 *(lpbDataOut++) = (lpbBuf[6] << 6) | (lpbBuf[7]);
\r
144 *(lpbDataOut++) = (lpbBuf[0] << 1) | (lpbBuf[1] >> 6);
\r
145 *(lpbDataOut++) = (lpbBuf[1] << 2) | (lpbBuf[2] >> 5);
\r
146 *(lpbDataOut++) = (lpbBuf[2] << 3) | (lpbBuf[3] >> 4);
\r
147 *(lpbDataOut++) = (lpbBuf[3] << 4) | (lpbBuf[4] >> 3);
\r
149 *(lpbDataOut++) = (lpbBuf[4] << 5) | (lpbBuf[5] >> 2);
\r
150 *(lpbDataOut++) = (lpbBuf[5] << 6) | (lpbBuf[6] >> 1);
\r
151 *(lpbDataOut++) = (lpbBuf[6] << 7) | (lpbBuf[7]);
\r
155 *(lpbDataOut++) = (lpbBuf[0] << 3) | (lpbBuf[1] >> 2);
\r
156 *(lpbDataOut++) = (lpbBuf[1] << 6) | (lpbBuf[2] << 1) | (lpbBuf[3] >> 4);
\r
157 *(lpbDataOut++) = (lpbBuf[3] << 4) | (lpbBuf[4] >> 1);
\r
159 *(lpbDataOut++) = (lpbBuf[4] << 7) | (lpbBuf[5] << 2) | (lpbBuf[6] >> 3);
\r
160 *(lpbDataOut++) = (lpbBuf[6] << 5) | (lpbBuf[7]);
\r
165 lComp = (((lNbrByte * 10) / 8) * uiBitComp);
\r
174 //===================================================//
\r
175 // fonction pour le panneau noir & overlay uniquement
\r
176 // entree : 1 octect = 1 points
\r
177 // sortie : 1 octect = 8 points
\r
178 //===================================================//
\r
179 long ReduceBlack(unsigned char *lpMemIn, unsigned char *lpMemOut,int nbrline)
\r
181 long lIndex = 0, lIndex1 = 0;
\r
182 unsigned char *lpbData, *lpbDataOut;
\r
184 unsigned char bBuf = 0x00;
\r
186 unsigned char Mask[8] = { 0x80, 0x40, 0x20, 0x10, 0x08, 0x04, 0x02, 0x01 };
\r
187 long lNbrByte = nbrline * 648;
\r
190 //lpbData ppV mem bmp brute
\r
191 lpbData = &lpMemIn[0];
\r
192 lpbDataOut = &lpMemOut[0];
\r
193 // pour toutes les donnees
\r
195 while (lIndex < lNbrByte)
\r
199 //Traite byte par 8
\r
200 for (lIndex1 = 0; lIndex1 < 8; lIndex1++)
\r
203 if (lIndex < lNbrByte)
\r
205 if (*(lpbData++) == 0xFF)
\r
207 bBuf |= Mask[lIndex1];
\r
212 *(lpbDataOut++) = bBuf;
\r
219 //=====================================================================
\r
220 // Convert bitmap RVB data to evolis data format
\r
221 //=====================================================================
\r
224 int DBNC(int col,int bl,int ov)//,int line)
\r
226 //output("\033Ss\015"); // debut sequence + CR
\r
229 DB32NC(0 * (dwSizeNeeded / 5), 'y');
\r
230 DB32NC(1 * (dwSizeNeeded / 5), 'm');
\r
231 DB32NC(2 * (dwSizeNeeded / 5), 'c');
\r
233 else if (col == 2) {
\r
234 DB64NC(0 * (dwSizeNeeded / 5), 'y');
\r
235 DB64NC(1 * (dwSizeNeeded / 5), 'm');
\r
236 DB64NC(2 * (dwSizeNeeded / 5), 'c');
\r
238 else if (col == 3) {
\r
239 DB128NC(0 * (dwSizeNeeded / 5), 'y');
\r
240 DB128NC(1 * (dwSizeNeeded / 5), 'm');
\r
241 DB128NC(2 * (dwSizeNeeded / 5), 'c');
\r
245 DB2NC(3 * (dwSizeNeeded / 5), "ABP");
\r
249 if(ov == 1){//overlay at front
\r
250 DB2NC(0, OverlayPannel);
\r
253 DB2NC(0, OverlayBackPannel);
\r
258 //output("\033Se\015....................................."); // fin sequence + CR
\r
262 //===============================================================//
\r
263 // Telechargement d'un panneau non compresse 5 bits
\r
264 // Input : ucData / raw data
\r
265 // color /y,m or c
\r
267 // -1 si erreur ecriture
\r
268 //===============================================================//
\r
269 int DB32NC(long lPos, char color)
\r
271 unsigned char *ucCommand, *ucCol;
\r
272 long lCommandSize = ((1016 * 648) * 5) / 8;
\r
274 int numwritten = 0;
\r
276 //Reservation memoire pour une commande de telechargement
\r
277 ucCommand = malloc(lCommandSize + 12);
\r
279 fatal("DP32NC Error: Fails malloc... ");
\r
283 ucCol = &lpMem[lPos];
\r
284 strcpy(ucCommand, "\033Db;y;32;");
\r
285 strncpy(&ucCommand[4], &color, 1);
\r
287 lComp = ReduceColor(ucCol, &ucCommand[9], 5);//,1016);
\r
288 lCommandSize += 10;
\r
289 numwritten = fwrite(ucCommand, sizeof(unsigned char), lCommandSize, stdout);
\r
290 if (numwritten != lCommandSize) {
\r
291 fatal("DP32NC Error: Fails printf %d... \n", numwritten);
\r
296 while(lComp > 4096) {
\r
297 numwritten += fwrite(&ucCommand[numwritten], sizeof(unsigned char), 4096, stdout);
\r
300 debug("NuwWritten %d", numwritten);
\r
302 numwritten += fwrite(&ucCommand[numwritten], sizeof(unsigned char), lComp, stdout);
\r
304 debug("lComp %d numwritten %d lCommandSize %d", lComp,numwritten,lCommandSize);
\r
305 if (numwritten != lCommandSize) {
\r
306 fatal("DP32NC Error: Fails printf %d... \n", numwritten);
\r
316 //===============================================================//
\r
317 // Telechargement d'un panneau non compresse 6 bits
\r
318 // Input : ucData / raw data
\r
319 // color /y,m or c
\r
321 // -1 si erreur ecriture
\r
322 //===============================================================//
\r
324 int DB64NC(long lPos, char color)
\r
326 unsigned char *ucCommand, *ucCol;
\r
329 long lCommandSize = ((1016 * 648) * 6) / 8;
\r
331 int numwritten = 0;
\r
334 //Reservation memoire pour une commande de telechargement
\r
335 ucCommand = malloc(lCommandSize + 10);
\r
336 debug("DP64NC Size for one panel: %d... \n", (lCommandSize + 10));
\r
341 fatal("DP64NC Error: Fails malloc...");
\r
347 ucCol = &lpMem[lPos];
\r
348 strcpy(ucCommand, "\033Db;y;64;");
\r
349 strncpy(&ucCommand[4], &color, 1);
\r
352 lComp = ReduceColor(ucCol, &ucCommand[9], 6);//,1016);
\r
353 //fprintf(stderr, "**************** EVOLIS DP64NC taille apres compression %d... \n",lComp);
\r
354 strncpy(&ucCommand[lCommandSize + 9], "\015", 1);
\r
355 lCommandSize += 10;
\r
356 numwritten = fwrite(ucCommand, sizeof(unsigned char), lCommandSize, stdout);
\r
357 if (numwritten != lCommandSize)
\r
359 fatal("DP64NC Error: Fails fwrite %d... \n", numwritten);
\r
371 //===============================================================//
\r
372 // Telechargement d'un panneau non compresse 7 bits
\r
373 // Input : ucData / raw data
\r
374 // color /y,m or c
\r
376 // -1 si erreur ecriture
\r
377 //===============================================================//
\r
378 int DB128NC(long lPos, char color)
\r
381 unsigned char *ucCommand, *ucCol;
\r
382 long lCommandSize = ((1016 * 648) * 7) / 8;
\r
384 int numwritten = 0;
\r
386 //Reservation memoire pour une commande de telechargement
\r
387 ucCommand = malloc(lCommandSize + 11);
\r
388 debug("DP128NC Size for one panel: %d... ", (lCommandSize + 11));
\r
391 fatal("DP128NC Error: Fails malloc... ");
\r
396 ucCol = &lpMem[lPos];
\r
397 strcpy(ucCommand, "\033Db;y;128;");
\r
398 strncpy(&ucCommand[4], &color, 1);
\r
399 lComp = ReduceColor(ucCol, &ucCommand[10], 7);//,1016);
\r
400 strncpy(&ucCommand[lCommandSize + 10], "\015", 1);
\r
401 lCommandSize += 11;
\r
402 numwritten = fwrite(ucCommand, sizeof(unsigned char), lCommandSize, stdout);
\r
403 if (numwritten != lCommandSize)
\r
405 fatal("DP128NC Error: Fails fwrite %d... \n", numwritten);
\r
413 //===============================================================//
\r
414 // Telechargement d'un panneau non compresse 5 bits YMCKOS
\r
415 // Input : ucData / raw data
\r
418 // -1 si erreur ecriture
\r
419 //===============================================================//
\r
420 /*int DB32NCS(long lPos, char color,int line)
\r
422 unsigned char *ucCommand, *ucCol;
\r
423 long lCommandSize = ((1016 * 648) * 5) / 8;
\r
425 int numwritten = 0;
\r
427 //Reservation memoire pour une commande de telechargement
\r
428 ucCommand = malloc(lCommandSize + 20);
\r
429 //fprintf(stderr, "**************** EVOLIS DP32NC Size for one panel: %d... \n", (lCommandSize+10));
\r
432 //fprintf(stderr, "**************** EVOLIS DP32NC Error: Fails malloc... \n");
\r
433 fatal("DP32NC Error: Fails malloc... ");
\r
437 ucCol = &lpMem[lPos];
\r
438 //strcpy(ucCommand, "\033Dbc;y;32;");
\r
439 //nbroct = 540 * 648;
\r
440 lCommandSize = ((520 * 648) * 5) / 8;
\r
441 sprintf(ucCommand, "\033Dbc;y;32;%.4d;%.6d;",line,lCommandSize);
\r
442 strncpy(&ucCommand[5], &color, 1);
\r
444 info("%s",ucCommand);
\r
445 lComp = ReduceColor(ucCol, &ucCommand[22], 5, 520);
\r
446 strncpy(&ucCommand[lCommandSize + 22], "\015", 1);
\r
447 lCommandSize += 23;
\r
449 numwritten = fwrite(ucCommand, sizeof(unsigned char), lCommandSize, stdout);
\r
450 //info("%d %s", numwritten,ucCommand);
\r
451 if (numwritten != lCommandSize)
\r
453 //fprintf(stderr, "**************** EVOLIS DP32NC Error: Fails printf %d... \n",numwritten);
\r
454 fatal("DP32NC Error: Fails printf %d... \n", numwritten);
\r
462 //===============================================================//
\r
463 // Telechargement d'un panneau non compresse 6 bits YMCKOS
\r
464 // Input : ucData / raw data
\r
467 // -1 si erreur ecriture
\r
468 //===============================================================//
\r
470 int DB64NCS(long lPos, char color,int line)
\r
472 unsigned char *ucCommand, *ucCol;
\r
474 long lCommandSize = ((1016 * 648) * 6) / 8;
\r
476 int numwritten = 0;
\r
480 //Reservation memoire pour une commande de telechargement
\r
481 ucCommand = malloc(lCommandSize + 10);
\r
482 debug("DP64NC Size for one panel: %d... \n", (lCommandSize + 10));
\r
487 fatal("DP64NC Error: Fails malloc...");
\r
493 ucCol = &lpMem[lPos];
\r
494 strcpy(ucCommand, "\033Db;y;64;");
\r
495 strncpy(&ucCommand[4], &color, 1);
\r
498 lComp = ReduceColor(ucCol, &ucCommand[9], 6, 540);
\r
499 //fprintf(stderr, "**************** EVOLIS DP64NC taille apres compression %d... \n",lComp);
\r
500 strncpy(&ucCommand[lCommandSize + 9], "\015", 1);
\r
501 lCommandSize += 10;
\r
502 numwritten = fwrite(ucCommand, sizeof(unsigned char), lCommandSize, stdout);
\r
503 if (numwritten != lCommandSize)
\r
505 fatal("DP64NC Error: Fails fwrite %d... \n", numwritten);
\r
517 //===============================================================//
\r
518 // Telechargement d'un panneau non compresse 7 bits YMCKOS
\r
519 // Input : ucData / raw data
\r
522 // -1 si erreur ecriture
\r
523 //===============================================================//
\r
524 int DB128NCS(long lPos, char color,int line)
\r
527 unsigned char *ucCommand, *ucCol;
\r
528 long lCommandSize = ((1016 * 648) * 7) / 8;
\r
530 int numwritten = 0;
\r
532 //Reservation memoire pour une commande de telechargement
\r
533 ucCommand = malloc(lCommandSize + 11);
\r
534 //fprintf(stderr, "**************** EVOLIS DP128NC Size for one panel: %d... \n", (lCommandSize+11));
\r
535 debug("DP128NC Size for one panel: %d... ", (lCommandSize + 11));
\r
540 fatal("DP128NC Error: Fails malloc... ");
\r
545 ucCol = &lpMem[lPos];
\r
546 strcpy(ucCommand, "\033Db;y;128;");
\r
547 strncpy(&ucCommand[4], &color, 1);
\r
548 lComp = ReduceColor(ucCol, &ucCommand[10], 7, 540);
\r
549 //fprintf(stderr, "**************** EVOLIS DP128NC taille apres compression %d... \n",lComp);
\r
550 strncpy(&ucCommand[lCommandSize + 10], "\015", 1);
\r
551 lCommandSize += 11;
\r
552 numwritten = fwrite(ucCommand, sizeof(unsigned char), lCommandSize, stdout);
\r
553 if (numwritten != lCommandSize)
\r
555 fatal("DP128NC Error: Fails fwrite %d... \n", numwritten);
\r
563 //===============================================================//
\r
564 // Telechargement d'un panneau non compresse overlay noir
\r
565 // Input : ucData / raw datal978
\r
567 // f: full varnish
\r
569 // -1 si erreur ecriture
\r
570 //===============================================================//
\r
572 int DB2NC(long lPos, char pannel[10])
\r
574 unsigned char *ucCommand, *ucCol;
\r
577 long lCommandSize = ((1016 * 648)) / 8;
\r
578 int numwritten = 0;
\r
579 int B, T, L, R, i = 0, j = 0;
\r
580 int pB, pT, ModuloB, ModuloT;
\r
582 //unsigned char MaskB[8] = { 0x00,0x80,0xC0,0xE0,0xF0,0x7F,0x3F,0x1F};
\r
583 //unsigned char MaskT[8] = { 0x00,0x01,0x03,0x07,0x0F,0x1F,0x3F,0x7F};
\r
584 unsigned char MaskB[8] = { 0x00, 0x80, 0xC0, 0xE0, 0xF0, 0xF8, 0xFC, 0xFE };
\r
585 unsigned char MaskT[8] = { 0x00, 0x01, 0x03, 0x07, 0x0F, 0x1F, 0x3F, 0x7F };
\r
588 //Reservation memoire pour une commande de telechargement
\r
590 ucCommand = malloc(lCommandSize + 9);
\r
592 //debug("DP2NC Size for one panel: %d... ", (lCommandSize + 9));
\r
597 fatal("DP2NC Error: Fails malloc... ");
\r
602 if (!(strcmp(pannel, "ABP")))// == NULL)
\r
604 ucCol = &lpMem[lPos];
\r
605 strcpy(ucCommand, "\033Db;k;2;");
\r
606 lComp = ReduceBlack(ucCol, &ucCommand[8],1016);
\r
607 strncpy(&ucCommand[lCommandSize + 8], "\015", 1);
\r
609 numwritten = fwrite(ucCommand, sizeof(unsigned char), lCommandSize, stdout);
\r
610 if (numwritten != lCommandSize)
\r
612 fatal("DP2NC Error: Fails fprintf %d... ", numwritten);
\r
618 else if (!(strcmp(pannel, "NO")))// == NULL)
\r
620 memset(ucCommand, 0x00, lCommandSize);
\r
621 strcpy(ucCommand, "\033Db;o;2;");
\r
622 strncpy(&ucCommand[lCommandSize + 8], "\015", 1);
\r
624 numwritten = fwrite(ucCommand, sizeof(unsigned char), lCommandSize, stdout);
\r
625 if (numwritten != lCommandSize)
\r
627 fatal("DP2NC Error: Fails fwrite %d... ", numwritten);
\r
632 else if (!(strcmp(pannel, "FO")))// == NULL)
\r
634 memset(ucCommand, 0xFF, lCommandSize);
\r
635 strcpy(ucCommand, "\033Db;o;2;");
\r
636 strncpy(&ucCommand[lCommandSize + 8], "\015", 1);
\r
638 numwritten = fwrite(ucCommand, sizeof(unsigned char), lCommandSize, stdout);
\r
639 if (numwritten != lCommandSize)
\r
641 fatal("DP2NC Error: Fails fwrite %d... ", numwritten);
\r
649 if (!(strcmp(pannel, "OA")))// == NULL)
\r
656 debug("DP2NC OA... ");
\r
657 memset(ucCommand, 0x00, lCommandSize);
\r
660 for (j = L; j <= R; j++)
\r
663 pB = (j * 648) + (648 - B);
\r
668 ucCommand[pB + 7] = MaskB[ModuloB];
\r
670 pT = (j * 648) + (648 - T);
\r
675 ucCommand[pT + 7] = MaskT[ModuloT];
\r
677 for (i = (pB); i <= (pT); i++)
\r
679 ucCommand[i + 7] = 0xFF;
\r
687 else if (!(strcmp(pannel, "SCI")))// == NULL)
\r
694 memset(ucCommand, 0xFF, lCommandSize);
\r
695 debug("DP2NC SCI... ");
\r
697 else if (!(strcmp(pannel, "SCA")))// == NULL)
\r
704 memset(ucCommand, 0xFF, lCommandSize);
\r
705 debug("DP2NC SCA... ");
\r
707 else if (!(strcmp(pannel, "MS")))// == NULL)
\r
714 memset(ucCommand, 0xFF, lCommandSize);
\r
715 debug("DP2NC MS... ");
\r
718 for (j = L; j <= R; j++)
\r
720 pB = (j * 648) + (648 - B);
\r
725 ucCommand[pB + 7] = MaskB[ModuloB];
\r
727 pT = (j * 648) + (648 - T);
\r
732 ucCommand[pT + 7] = MaskT[ModuloT];
\r
734 for (i = (pB); i <= (pT); i++)
\r
736 ucCommand[i + 7] = 0x00;
\r
738 }//end of white part
\r
740 strcpy(ucCommand, "\033Db;o;2;");
\r
742 strncpy(&ucCommand[lCommandSize + 8], "\015", 1);
\r
744 numwritten = fwrite(ucCommand, sizeof(unsigned char), lCommandSize, stdout);
\r
745 if (numwritten != lCommandSize)
\r
747 fatal("DP2NC Error: Fails fwrite %d... ", numwritten);
\r
759 //=====================================================================
\r
760 // Convert color bitmap to monochrome bitmap
\r
761 //=====================================================================
\r
763 //////////////////////////////////////////////////////////////////////////////////////
\r
764 /////// RVB TO GRAY
\r
765 /////// Input parameters
\r
766 /////// lpMemIn : RVB data (3 byte by dot)
\r
767 /////// lNbrByte: number of byte to deal
\r
768 /////// Output parameter
\r
769 /////// lpMemOut: pointer on the gray data, result of the conversion
\r
772 //////////////////////////////////////////////////////////////////////////////////////
\r
774 void RVBtoGray(unsigned char *lpMemIn, unsigned char *lpMemOut, long lNbrByte)
\r
778 unsigned char *lpbData, *lpbDataOut;
\r
779 unsigned char red, green, blue;
\r
782 //lpbData ppV mem bmp brute
\r
783 lpbData = &lpMemIn[0];
\r
784 lpbDataOut = &lpMemOut[0];
\r
785 // pour toutes les donnees
\r
786 while (lIndex < lNbrByte)
\r
788 blue = lpbData[(lIndex * 3)];
\r
789 green = lpbData[(lIndex * 3) + 1];
\r
790 red = lpbData[(lIndex * 3) + 2];
\r
791 d = RgbToGray(red, green, blue);
\r
792 lpbDataOut[lIndex] = (unsigned char) d;
\r
799 //////////////////////////////////////////////////////////////////////////////////////
\r
800 /////// GRAY THRESHOLD
\r
801 /////// Input parameters
\r
802 /////// lpMemIn : gray data (1 byte by dot)
\r
803 /////// lNbrByte: number of byte to deal
\r
807 /////// Output parameter
\r
808 /////// lpMemOut: pointer on the monochrome data, result of the gray conversion
\r
810 //////////////////////////////////////////////////////////////////////////////////////
\r
812 void GrayToThreshold(unsigned char *lpMemIn, unsigned char *lpMemOut, long lNbrByte)
\r
815 unsigned char *lpbData, *lpbDataOut;
\r
818 //lpbData ppV mem bmp brute
\r
819 lpbData = &lpMemIn[0];
\r
820 lpbDataOut = &lpMemOut[0];
\r
821 // pour toutes les donnees
\r
822 while (lIndex < lNbrByte)
\r
826 gray = lpbData[lIndex];
\r
832 lpbDataOut[lIndex] = (unsigned char) gray;
\r
840 //////////////////////////////////////////////////////////////////////////////////////
\r
841 /////// GRAY DITHER
\r
842 /////// Input parameters
\r
843 /////// lpMemIn : gray data (1 byte by dot)
\r
844 /////// Height : height of the BMP image (648)
\r
845 /////// Width : width of the BMP image (1016)
\r
847 /////// Output parameter
\r
848 /////// lpMemOut: pointer on the monochrome data, result of the gray conversion
\r
849 //////////////////////////////////////////////////////////////////////////////////////
\r
851 void GrayToDither(unsigned char *lpMemIn, unsigned char *lpMemOut, long Width, long Height)
\r
853 long index_line = 0, index_dot = 0;
\r
854 unsigned char *lpbData, *lpbDataOut;
\r
858 //lpbData ppV mem bmp brute
\r
859 lpbData = &lpMemIn[0];
\r
861 lpbDataOut = &lpMemOut[0];
\r
862 // pour toutes les donnees
\r
863 if (Height < Width)
\r
865 index_line = Width;
\r
867 Height = index_line;
\r
871 for (index_line = 0; index_line < Height; index_line++)
\r
873 for (index_dot = 0; index_dot < Width; index_dot++)
\r
875 gray = lpbData[index_dot + (index_line * Width)];
\r
877 if (k > DitherPattern1[index_line % 8][index_dot % 8])
\r
881 lpbDataOut[index_dot + (index_line * Width)] = (unsigned char) gray;
\r
887 //////////////////////////////////////////////////////////////////////////////////////
\r
889 /////// Input parameters
\r
890 /////// lpMemIn : gray data (1 byte by dot)
\r
891 /////// Height : height of the BMP image (648)
\r
892 /////// Width : width of the BMP image (1016)
\r
893 /////// Output parameter
\r
894 /////// lpMemOut: pointer on the monochrome data, result of the gray conversion
\r
895 //////////////////////////////////////////////////////////////////////////////////////
\r
897 void GrayToFloyd(unsigned char *lpMemIn, unsigned char *lpMemOut, long Width, long Height)
\r
899 long index_line = 0, index_dot = 0;
\r
900 unsigned char *lpbData, *lpbDataOut;
\r
903 int NextError[1032];
\r
905 int CE3, CE5, CE7, CE1;
\r
907 if (Height < Width)
\r
909 index_line = Width;
\r
912 Height = index_line;
\r
916 for (index_line = 0; index_line < 1032; index_line++)
\r
918 Error[index_line] = NextError[index_line] = 0;
\r
920 //lpbData ppV mem bmp brute
\r
923 lpbData = &lpMemIn[0];
\r
924 lpbDataOut = &lpMemOut[0];
\r
925 // pour toutes les donnees
\r
926 for (index_line = 0; index_line < Height; index_line++)
\r
929 //for(index_dot = Width ; index_dot > 0; index_dot--)
\r
930 for (index_dot = 0; index_dot < Width; index_dot++)
\r
932 gray = lpbData[index_dot + (index_line * Width)];
\r
934 k = (gray + (int) Error[index_dot]);
\r
935 if (k > -128 && k < 128)
\r
942 lpbDataOut[index_dot + (index_line * Width)] = 0xFF - (unsigned char) l;
\r
947 CE3 = (Cerror * 3 / 16);
\r
948 CE5 = (Cerror * 5 / 16);
\r
949 CE7 = (Cerror * 7 / 16);
\r
950 CE1 = Cerror - CE3 - CE5 - CE7;
\r
952 NextError[index_dot] += CE5;
\r
953 if (index_dot < 1031)
\r
955 Error[index_dot + 1] += CE7;
\r
956 NextError[index_dot + 1] += CE1;
\r
959 NextError[index_dot - 1] += CE3;
\r
961 for (index_dot = 0; index_dot < 1032; index_dot++)
\r
963 Error[index_dot] = NextError[index_dot];
\r
964 NextError[index_dot] = 0;
\r
970 ////////////////////////////////////////////////////////////////////////////////////
\r
973 /////// Input parameters
\r
974 /////// lpbRVB : rvb color data from a 24 bits 1 panel BMP file
\r
975 /////// RVBSize : number of byte for the color data [(1016*648)]*3
\r
977 /////// Height : height of the BMP image (648)
\r
978 /////// Width : width of the BMP image (1016)
\r
979 /////// Type : type of monochrome dealing (threshold, floyd or dither)
\r
981 /////// Output parameter
\r
983 /////// lpBlack : pointer on the monochrome data, result of the color conversion
\r
984 //////////////////////////////////////////////////////////////////////////////////////
\r
985 void ConvertRVBtoK(unsigned char *lpbRVB, long RVBSize, long Height, long Width, unsigned char *lpBlack)
\r
987 //long y = 0,x = 0;
\r
988 //long index_line = 0 , index_dot = 0;
\r
990 if (!(strcmp(TreatementK, "GE")))// == NULL)
\r
992 GrayToFloyd(lpbRVB, lpBlack, Width, Height);
\r
994 else if (!(strcmp(TreatementK, "LM")))// == NULL)
\r
996 GrayToThreshold(lpbRVB, lpBlack, (RVBSize / 5));
\r
1002 //========================================================//
\r
1003 // OPTION : Not real black printed
\r
1004 // Insert sublimable black from K panel to Y,M & C panels
\r
1005 //========================================================//
\r
1006 void KinYMC(long Height, long Width)
\r
1009 unsigned char *lpYellow, *lpMagenta, *lpCyan, *lpBlack;
\r
1012 dwSize = Width * Height;
\r
1013 lpYellow = &lpMem[0];
\r
1014 lpMagenta = &lpMem[dwSize];
\r
1015 lpCyan = &lpMem[2 * dwSize];
\r
1016 lpBlack = &lpMem[3 * dwSize];
\r
1017 for (i = 0; i < dwSize; i++)
\r
1021 lpYellow[i] |= lpBlack[i];
\r
1022 lpMagenta[i] |= lpBlack[i];
\r
1023 lpCyan[i] |= lpBlack[i];
\r
1028 //========================================================//
\r
1029 // OPTION : Get the first YMC printed dots
\r
1030 //========================================================//
\r
1031 void GetFirstYMCDot(long Height, long Width , int *x, int *y)
\r
1034 unsigned char *lpYellow, *lpMagenta, *lpCyan, *lpBlack;
\r
1037 dwSize = Width * Height;
\r
1038 lpYellow = &lpMem[0];
\r
1039 lpMagenta = &lpMem[dwSize];
\r
1040 lpCyan = &lpMem[2 * dwSize];
\r
1041 //for (i = 0; i < dwSize; i++)
\r
1042 while(i < dwSize && !fi)
\r
1044 if(lpYellow[i] || lpMagenta[i] || lpCyan[i] )
\r
1052 // End of "evolis.c,v 1.0 ".
\r