Annotation of ntddk/src/print/dec3200/code.c, revision 1.1

1.1     ! root        1: #include        <windows.h>
        !             2: #include        <winuser.h>
        !             3: 
        !             4: #include        <ntmindrv.h>
        !             5: 
        !             6: 
        !             7: NTMD_INIT    ntmdInit;                 /* Function address in RasDD */
        !             8: 
        !             9: /*
        !            10:  *   Include the module initialisation function so that RasDD will
        !            11:  * recognise our module.
        !            12:  */
        !            13: 
        !            14: #define _GET_FUNC_ADDR    1
        !            15: 
        !            16: #include       "modinit.c"
        !            17: 
        !            18: 
        !            19: void CompressIt(PBYTE, PBYTE, int);
        !            20: 
        !            21: /***************************** Function Header *****************************
        !            22:  * CBFilterGraphics
        !            23:  *   Manipulate output data before calling RasDD's buffering function.
        !            24:  *       This function is called with the raw bit data that is to be
        !            25:  *       sent to the printer.
        !            26:  *
        !            27:  *
        !            28:  *   DEC Laser printers require raster graphics to be sent in byte column model 
        !            29:  *       similiar to dot matrix printers. However only six bits in every byte are 
        !            30:  *       used. Our function takes a 3 byte high column of data (24 scanlines) and 
        !            31:  *       converts it to 4 x 6 scanline high blocks.
        !            32:  *
        !            33:  *
        !            34:  *   Other massaging includes flipping the data. DEC's PPL3 expects the sixth 
        !            35:  *       scanline to be the low bit etc. 0x3F needs to be added to each byte.
        !            36:  *
        !            37:  *
        !            38:  *
        !            39:  *   CompressIt function then implements a run length encoding type compression 
        !            40:  *       before WriteSpoolBuf is called
        !            41:  *
        !            42:  *
        !            43:  *
        !            44:  ****************************************************************************/
        !            45: 
        !            46: int
        !            47: CBFilterGraphics( lpdv, lpBuf, len )
        !            48: void  *lpdv;
        !            49: BYTE  *lpBuf;
        !            50: int    len;
        !            51: {
        !            52:     BYTE  *lpSrc, *lpTgt;
        !            53:     static BYTE  localBuf[1300];
        !            54:     int  i,j, bytesRem,  nBytes;
        !            55:     static  BYTE  Blk1[256] = {0};
        !            56:     static  BYTE  Blk4[256] = {0};
        !            57:     static  BYTE  Blk2Byt1[256] = {0};
        !            58:     static  BYTE  Blk2Byt2[256] = {0};
        !            59:     static  BYTE  Blk3Byt1[256] = {0};
        !            60:     static  BYTE  Blk3Byt2[256] = {0};
        !            61:     static  BYTE  BindBlk2[4][16] = {0};
        !            62:     static  BYTE  BindBlk3[16][4] = {0};
        !            63: 
        !            64:     if (!Blk1[1])      //  need to initialize tables
        !            65:     {
        !            66:         for(i = 0 ; i < 256 ; i++)
        !            67:         {
        !            68:             BYTE  rot; 
        !            69: 
        !            70:             //First Block , one byte only 123456XX to  00654321
        !            71:             rot = i;  
        !            72:             Blk1[i]     = 0x10 & (rot <<=1);
        !            73:             Blk1[i]    |= 0x20 & (rot <<=2);
        !            74:             rot = i;                        
        !            75:             Blk1[i]    |= 0x08 & (rot >>=1);
        !            76:             Blk1[i]    |= 0x04 & (rot >>=2);
        !            77:             Blk1[i]    |= 0x02 & (rot >>=2);
        !            78:             Blk1[i]    |= 0x01 & (rot >>=2);
        !            79:             Blk1[i]     = Blk1[i]  + 0x3F;
        !            80:             
        !            81:             //Second Block first byte  XXXXXX12 to 00000021
        !            82:             Blk2Byt1[i]  = 0x01 & (i >>1);
        !            83:             Blk2Byt1[i] |= 0x02 & (i <<1);   // i byte
        !            84:             
        !            85:             //Second Block second byte  3456XXXX to 00006543
        !            86:             rot = i;                        
        !            87:             Blk2Byt2[i]  = 0x08 & (rot >>=1);
        !            88:             Blk2Byt2[i] |= 0x04 & (rot >>=2);
        !            89:             Blk2Byt2[i] |= 0x02 & (rot >>=2);
        !            90:             Blk2Byt2[i] |= 0x01 & (rot >>=2);   // j byte
        !            91: 
        !            92:             //Third Block First byte  XXXX1234 to 00004321
        !            93:             rot =i;
        !            94:             Blk3Byt1[i]  = 0x02 & (rot >>=1);
        !            95:             Blk3Byt1[i] |= 0x01 & (rot >>=2);
        !            96:             rot =i;                        
        !            97:             Blk3Byt1[i] |= 0x04 & (rot <<=1);
        !            98:             Blk3Byt1[i] |= 0x08 & (rot <<=2);   //j byte 
        !            99: 
        !           100:             //Third Block Second byte  56XXXXXX to 00000065
        !           101:             rot =i;
        !           102:             Blk3Byt2[i]  = 0x02 & (rot >>=5);
        !           103:             Blk3Byt2[i] |= 0x01 & (rot >>=2);   //i byte
        !           104:             
        !           105:             //Fourth Block, only byte  XX123456 to 00654321
        !           106:             rot=i;
        !           107:             Blk4[i]   = 0x08 & (rot <<=1); 
        !           108:             Blk4[i]  |= 0x10 & (rot <<=2);
        !           109:             Blk4[i]  |= 0x20 & (rot <<=2);
        !           110:             rot=i;
        !           111:             Blk4[i]  |= 0x04 & (rot >>=1); 
        !           112:             Blk4[i]  |= 0x02 & (rot >>=2);
        !           113:             Blk4[i]  |= 0x01 & (rot >>=2);
        !           114:             Blk4[i]   = Blk4[i]  + 0x3F;
        !           115: 
        !           116: 
        !           117:         }
        !           118:         for(i = 0 ; i < 4 ; i++)
        !           119:             for(j = 0 ; j < 16 ; j++)
        !           120:             {
        !           121:                 // Bind 00000021 & 00006543  & add 3F 
        !           122:                 BindBlk2[i][j] = ( (j<< 2 ) | i) + 0x3F;
        !           123:                 // Bind 00004321 & 00000065  & add 3F 
        !           124:                 BindBlk3[j][i] = ( (i<< 4 ) | j) + 0x3F;
        !           125:             }
        !           126:     }
        !           127: 
        !           128:     bytesRem = len;
        !           129:     lpSrc = lpBuf;
        !           130:     while(bytesRem > 0)
        !           131:     {   
        !           132:         nBytes = (bytesRem > 3072) ? 3072 : bytesRem;
        !           133:         bytesRem -= nBytes;
        !           134:         lpTgt = localBuf;
        !           135:         for(i = 0 ; i < nBytes / 3 ; i++)
        !           136:         {
        !           137:             *lpTgt++ = Blk1[*lpSrc];
        !           138:             lpSrc +=3;
        !           139:         }
        !           140:         CompressIt(lpdv, localBuf, lpTgt - localBuf);
        !           141:     }    
        !           142:     // End of block send graphics line feed & carriage return
        !           143:     ntmdInit.WriteSpoolBuf(lpdv, "\x2D\x24", 2); 
        !           144:     
        !           145:     bytesRem = len;
        !           146:     lpSrc = lpBuf;
        !           147:     while(bytesRem > 0)
        !           148:     {   
        !           149:         nBytes = (bytesRem > 3072) ? 3072 : bytesRem;
        !           150:         bytesRem -= nBytes;
        !           151:         lpTgt = localBuf;
        !           152:         for(i = 0 ; i < nBytes / 3 ; i++)
        !           153:         {
        !           154:             *lpTgt++ = BindBlk2[ Blk2Byt1[ *lpSrc] ][ Blk2Byt2[ *(lpSrc +1)] ]; 
        !           155:             lpSrc +=3;
        !           156:         }
        !           157:         CompressIt(lpdv, localBuf, lpTgt - localBuf);
        !           158:     }    
        !           159:     // End of block send graphics line feed & carriage return
        !           160:     
        !           161:     ntmdInit.WriteSpoolBuf(lpdv, "\x2D\x24", 2); 
        !           162:     bytesRem = len;
        !           163:     lpSrc = lpBuf;
        !           164:     while(bytesRem > 0)
        !           165:     {   
        !           166:         nBytes = (bytesRem > 3072) ? 3072 : bytesRem;
        !           167:         bytesRem -= nBytes;
        !           168:         lpTgt = localBuf;
        !           169:         for(i = 0 ; i < nBytes / 3 ; i++)
        !           170:         {   
        !           171:             *lpTgt++ = BindBlk3[ Blk3Byt1[ *(lpSrc+1) ] ][ Blk3Byt2[ *(lpSrc +2)] ]; 
        !           172:             lpSrc +=3;
        !           173:        }
        !           174:         CompressIt(lpdv, localBuf, lpTgt - localBuf);
        !           175:     }    
        !           176:     // End of block send graphics line feed & carriage return
        !           177:     ntmdInit.WriteSpoolBuf(lpdv, "\x2D\x24", 2); 
        !           178:     
        !           179:     bytesRem = len;
        !           180:     lpSrc = lpBuf;
        !           181:     while(bytesRem > 0)
        !           182:     {   
        !           183:         nBytes = (bytesRem > 3072) ? 3072 : bytesRem;
        !           184:         bytesRem -= nBytes;
        !           185:         lpTgt = localBuf;
        !           186:         for(i = 0 ; i < nBytes / 3 ; i++)
        !           187:         {
        !           188:             *lpTgt++ = Blk4[ *(lpSrc+2) ];
        !           189:             lpSrc += 3;
        !           190:         }
        !           191:         CompressIt(lpdv, localBuf, lpTgt - localBuf);
        !           192:     }    
        !           193: 
        !           194:     // End of final block send line feed  & End Block command
        !           195:     ntmdInit.WriteSpoolBuf(lpdv, "\x2D\x9C", 2); 
        !           196: 
        !           197:     return  100;                /* Value not used AT PRESENT! */
        !           198: }
        !           199: 
        !           200: void    
        !           201: CompressIt(lpdv, ExpBuf, ExpLen)
        !           202: BYTE  *lpdv;
        !           203: BYTE  *ExpBuf;
        !           204: int   ExpLen;
        !           205: {
        !           206:     static BYTE  CompBuf[1200]; //Max size before Compression is 1024
        !           207:     BYTE  *lpSrc, *lpTgt;
        !           208:     int InCompMode =0, count=0,i,FormatLen;
        !           209:     BYTE FormatBuf[10];
        !           210:     BYTE *pFormat;
        !           211:     lpSrc = ExpBuf;
        !           212:     lpTgt = CompBuf;
        !           213:     for (i=0; i < ExpLen; i++,lpSrc++)
        !           214:     {
        !           215:         if ( *lpSrc != *(lpSrc +1))
        !           216:         {
        !           217:             if (!InCompMode)
        !           218:                 *lpTgt++ = *lpSrc;
        !           219:             else
        !           220:             {
        !           221:                 InCompMode = 0;
        !           222:                 //Send the repeat char sequence - !#X
        !           223:                 pFormat = FormatBuf;
        !           224:                 FormatLen = wsprintf(pFormat,"!%d%c",count,*lpSrc);
        !           225:                 ntmdInit.WriteSpoolBuf(lpdv, FormatBuf,FormatLen);
        !           226:             }
        !           227:         }
        !           228:         else
        !           229:         {
        !           230:             if (!InCompMode)
        !           231:             {
        !           232:                  InCompMode =1;
        !           233:                  count =2;
        !           234:                  ntmdInit.WriteSpoolBuf(lpdv, CompBuf, (PBYTE)lpTgt - (PBYTE)CompBuf);
        !           235:                  lpTgt = CompBuf;
        !           236:             }
        !           237:             else
        !           238:                  count++;
        !           239:          }
        !           240:     }
        !           241:     if (!InCompMode)
        !           242:          ntmdInit.WriteSpoolBuf(lpdv, CompBuf, (PBYTE)lpTgt - (PBYTE)CompBuf);
        !           243:     else
        !           244:     {
        !           245:          //Send the repeat char sequence - !#X
        !           246:          pFormat = FormatBuf;
        !           247:          FormatLen  = wsprintf(pFormat,"!%d%c",count-1,*lpSrc);
        !           248:          ntmdInit.WriteSpoolBuf(lpdv, FormatBuf,FormatLen);
        !           249:     }
        !           250: }

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.