📄 compression.cpp
字号:
*dptr++ = 0; } else { while( offset ) { *dptr++ = MIN ( offset, 255 ); if ( offset == 255 ) *dptr++ = 0; offset -= MIN ( offset, 255 ); } } } if (byte_count > (MAX_COUNT0+COUNT_START0)) { rem_count = byte_count - (MAX_COUNT0+COUNT_START0+1); if (rem_count == 0) *dptr++ = 0; else { while( rem_count ) { *dptr++ = MIN ( rem_count, 255 ); if ( rem_count == 255 ) *dptr++ = 0; rem_count -= MIN ( rem_count, 255 ); } } } /* Now output the run of bytes. First set up a pointer to the first source byte. */ tempPtr = nptr - byte_count; for(;byte_count;byte_count--) { *dptr++ = *tempPtr++; } } else /************ If doing a mode 1 *************/ { /* mode 1, next two bytes are equal */ command.bitf1.type = 1; nptr++; last_byte = *nptr++; byte_count = 2; while ((last_byte == *nptr++) && (byte_count < size)) { byte_count++; } nptr--; sptr += byte_count; size -= byte_count; if (offset > (MAX_OFFSET1+OFFSET_START1)) command.bitf1.roff = MAX_OFFSET1+1; else command.bitf1.roff = offset-OFFSET_START1; if (byte_count > (MAX_COUNT1+COUNT_START1)) command.bitf1.replace_count = MAX_COUNT1+1; else command.bitf1.replace_count = byte_count-COUNT_START1; *dptr++ = command.comchar; if (offset > (MAX_OFFSET1+OFFSET_START1)) { offset -= (MAX_OFFSET1+OFFSET_START1+1); if (offset == 0) { *dptr++ = 0; } else { while( offset ) { *dptr++ = MIN ( offset, 255 ); if ( offset == 255 ) *dptr++ = 0; offset -= MIN ( offset, 255 ); } } } /* if (offset > MAX... */ if (byte_count > (MAX_COUNT1+COUNT_START1)) { rem_count = byte_count - (MAX_COUNT1+COUNT_START1+1); if (rem_count == 0) *dptr++ = 0; else { while( rem_count ) { *dptr++ = MIN ( rem_count, 255 ); if ( rem_count == 255 ) *dptr++ = 0; rem_count -= MIN ( rem_count, 255 ); } } } /* if (byte_count > ... */ *dptr++ = last_byte; /* Now output the repeated byte. */ } } /* while (size > 0) */bail: size = ( dptr - dest ); compressedsize = size; if (myplane == COLORTYPE_BLACK) { memcpy(&(SeedRow[layer*originalsize]), originalKData, originalsize); } else { memcpy(&(SeedRow[layer*originalsize]), input->rasterdata[myplane], originalsize); } seeded = TRUE; iRastersReady=1; return TRUE;}/* * Only 8xx, 8x5, 9xx, ljmono and ljcolor use Mode2 */#if defined(APDK_DJ8xx)|| defined(APDK_DJ9xx) || defined(APDK_LJMONO) || defined(APDK_LJCOLOR)Mode2::Mode2 (SystemServices* pSys, unsigned int RasterSize) : Compressor (pSys, RasterSize, FALSE){ compressBuf = (BYTE*)pSS->AllocMem(RasterSize ); if (compressBuf == NULL) constructor_error=ALLOCMEM_ERROR;}Mode2::~Mode2(){ }BOOL Mode2::Process (RASTERDATA* input)// mode 2 compression code from Kevin Hudson{ BYTE* pDst = compressBuf; int ndstcount = 0; if (input==NULL || (myplane == COLORTYPE_COLOR && input->rasterdata[COLORTYPE_COLOR] == NULL) || (myplane == COLORTYPE_BLACK && input->rasterdata[COLORTYPE_BLACK] == NULL)) // flushing pipeline { compressedsize=0; iRastersReady=0; return FALSE; } unsigned int size = input->rastersize[myplane]; for (unsigned int ni = 0; ni < size;) { if ( ni + 1 < size && input->rasterdata[myplane][ ni ] == input->rasterdata[myplane][ ni + 1 ] ) { unsigned int nrepeatcount; for ( ni += 2, nrepeatcount = 1; ni < size && nrepeatcount < 127; ++ni, ++nrepeatcount ) { if ( input->rasterdata[myplane][ ni ] != input->rasterdata[myplane][ ni - 1 ] ) { break; } } int tmprepeat = 0 - nrepeatcount; BYTE trunc = (BYTE) tmprepeat; pDst[ ndstcount++ ] = trunc; pDst[ ndstcount++ ] = input->rasterdata[myplane][ ni - 1 ]; } else { int nliteralcount; int nfirst = ni; for ( ++ni, nliteralcount = 0; ni < size && nliteralcount < 127; ++ni, ++nliteralcount ) { if ( input->rasterdata[myplane][ ni ] == input->rasterdata[myplane][ ni - 1 ] ) { --ni; --nliteralcount; break; } } pDst[ ndstcount++ ] = (BYTE) nliteralcount; for ( int nj = 0; nj <= nliteralcount; ++nj ) { pDst[ ndstcount++ ] = input->rasterdata[myplane][ nfirst++ ]; } } } size = ndstcount; compressedsize = size; iRastersReady = 1; return TRUE;}#endif // if 8xx, 9xx, ljmono, ljcolor#ifdef APDK_LJCOLOR/* * Mode 3 (Delta Row Compression) * Raghu Cauligi */Mode3::Mode3 (SystemServices* pSys, Printer *pPrinter, unsigned int RasterSize) : Compressor (pSys, RasterSize, TRUE){ // Worst case is when two rows are completely different // In that case, one command byte is added for every 8 bytes // In the worst case, compression expands data by 50% compressBuf = (BYTE*)pSS->AllocMem(RasterSize + RasterSize/2); if (compressBuf == NULL) constructor_error=ALLOCMEM_ERROR; memset (SeedRow, 0x0, inputsize); m_pPrinter = pPrinter;}Mode3::~Mode3 (){}void Mode3::Flush (){ if (!seeded) return; compressedsize=0; iRastersReady = 0; seeded = FALSE; memset (SeedRow, 0x0, inputsize); m_pPrinter->Send ((const BYTE *) "\033*b0Y", 5);}BOOL Mode3::Process (RASTERDATA *input){ if (input==NULL || (myplane == COLORTYPE_COLOR && input->rasterdata[COLORTYPE_COLOR] == NULL) || (myplane == COLORTYPE_BLACK && input->rasterdata[COLORTYPE_BLACK] == NULL)) // flushing pipeline { Flush(); return FALSE; } else { seeded = TRUE; } unsigned int uOrgSize = input->rastersize[myplane]; unsigned int size = input->rastersize[myplane]; unsigned int uOffset; BYTE *pszSptr = SeedRow; BYTE *pszInPtr = input->rasterdata[myplane]; BYTE *pszCurPtr; BYTE ucByteCount; BYTE *pszOutPtr = compressBuf; while (size > 0) { uOffset = 0; if (seeded) { while ((*pszSptr == *pszInPtr) && (uOffset < size)) { pszSptr++; pszInPtr++; uOffset++; } } if (uOffset >= size) { break; } size -= uOffset; pszCurPtr = pszInPtr; ucByteCount = 1; pszSptr++; pszInPtr++; while ((*pszSptr != *pszInPtr) && ucByteCount < size && ucByteCount < 8) { pszSptr++; pszInPtr++; ucByteCount++; } ucByteCount--; if (uOffset < 31) { *pszOutPtr++ = ((ucByteCount << 5) | uOffset); } else { uOffset -= 31; *pszOutPtr++ = ((ucByteCount << 5) | 31); while (uOffset >= 255) { *pszOutPtr++ = 255; uOffset -= 255; } *pszOutPtr++ = uOffset; } ucByteCount++; size -= (ucByteCount); memcpy (pszOutPtr, pszCurPtr, ucByteCount); pszOutPtr += ucByteCount; } compressedsize = pszOutPtr - compressBuf; memcpy (SeedRow, input->rasterdata[myplane], uOrgSize); seeded = TRUE; iRastersReady = 1; return TRUE;// Mode 3}#endif // APDK_LJCOLORAPDK_END_NAMESPACE////////////////////////////////////////////////////////////////////
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -