⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 filterhpa.cpp

📁 HP喷墨打印机驱动代码 HP内部资料! 珍贵 珍贵 珍贵
💻 CPP
📖 第 1 页 / 共 5 页
字号:
                    currPixel = (R1<<16) + (G1<<8) + B1;                else if(bigEndian)                    currPixel = (R1<<24) + (G1<<16) + (B1<<8);                // Note we write this block out now and do not delay the writes for the postprocessing step since we do not track this block.                put4Pixel(row2Ptr, 0, currPixel);                put4Pixel(row2Ptr, 1, currPixel);                put4Pixel(row2Ptr, 2, currPixel);                put4Pixel(row2Ptr, 3, currPixel);                put4Pixel(row3Ptr, 0, currPixel);                put4Pixel(row3Ptr, 1, currPixel);                put4Pixel(row3Ptr, 2, currPixel);                put4Pixel(row3Ptr, 3, currPixel);                fPixelFilteredFlags[0][pixelNum] = fPixelFilteredFlags[0][pixelNum] & ~e41si;                fPixelFilteredFlags[0][pixelNum+1] = fPixelFilteredFlags[0][pixelNum+1] & ~e41s;                fPixelFilteredFlags[0][pixelNum+2] = fPixelFilteredFlags[0][pixelNum+1] & ~e41s;                fPixelFilteredFlags[0][pixelNum+3] = fPixelFilteredFlags[0][pixelNum+1] & ~e41s;                fPixelFilteredFlags[1][pixelNum] = fPixelFilteredFlags[1][pixelNum] & ~e41ni;  // Note that we just formed a 2x2 in the middle of the filtered sets of rows (and do not remember it). We then remove the 2x1s that the 2x2 eliminated.                fPixelFilteredFlags[1][pixelNum+1] = fPixelFilteredFlags[1][pixelNum+1] & ~e41n;                fPixelFilteredFlags[1][pixelNum+2] = fPixelFilteredFlags[1][pixelNum+1] & ~e41n;                fPixelFilteredFlags[1][pixelNum+3] = fPixelFilteredFlags[1][pixelNum+1] & ~e41n;            }            pixelNum += 4;            row1Ptr += 4*eBufferedPixelWidthInBytes;            row2Ptr += 4*eBufferedPixelWidthInBytes;            row3Ptr += 4*eBufferedPixelWidthInBytes;        }        else if ((fPixelFilteredFlags[0][pixelNum] & e21sw)                && (fPixelFilteredFlags[1][pixelNum] & e21nw))        {            /*    - -                 |   |                  - -  We have two 2x1s.                  - -                 |   |                  - -            */            ASSERT(!((fPixelFilteredFlags[0][pixelNum] & e11s) | (fPixelFilteredFlags[0][pixelNum+1] & e11s)));            ASSERT(!((fPixelFilteredFlags[1][pixelNum] & e11n) | (fPixelFilteredFlags[1][pixelNum+1] & e11n)));            upPixel = get4Pixel(row2Ptr);            currPixel = get4Pixel(row3Ptr);            R1 = GetRed(currPixel);            G1 = GetGreen(currPixel);            B1 = GetBlue(currPixel);            R0 = GetRed(upPixel);            G0 = GetGreen(upPixel);            B0 = GetBlue(upPixel);            if ((maxErrorForFourPixels >= 3) && (NewDeltaE(R1, R0, G1, G0, B1, B0, maxErrorForFourPixels)))            {                /*    - -                     |   |  build 2x2.                     |   |                      - -                */#if kGatherStats == 1                blockStats[es22w]++;#endif                AverageNRound((pixelNum & 0x02) == 0x02, R1, R1, R0, G1, G1, G0, B1, B1, B0);                if(littleEndian)                    currPixel = (R1<<16) + (G1<<8) + B1;                else if(bigEndian)                    currPixel = (R1<<24) + (G1<<16) + (B1<<8);                // Note we write this block out now and do not delay the writes for the postprocessing step since we do not track this block.                put4Pixel(row2Ptr, 0, currPixel);                put4Pixel(row2Ptr, 1, currPixel);                put4Pixel(row3Ptr, 0, currPixel);                put4Pixel(row3Ptr, 1, currPixel);                fPixelFilteredFlags[0][pixelNum] = fPixelFilteredFlags[0][pixelNum] & ~e21sw;                fPixelFilteredFlags[0][pixelNum+1] = fPixelFilteredFlags[0][pixelNum+1] & ~e21se;                fPixelFilteredFlags[1][pixelNum] = fPixelFilteredFlags[1][pixelNum] & ~e21nw;  // Note that we just formed a 2x2 in the middle of the filtered sets of rows (and do not remember it). We then remove the 2x1s that the 2x2 eliminated.                fPixelFilteredFlags[1][pixelNum+1] = fPixelFilteredFlags[1][pixelNum+1] & ~e21ne;            }            pixelNum += 2;            row1Ptr += 2*eBufferedPixelWidthInBytes;            row2Ptr += 2*eBufferedPixelWidthInBytes;            row3Ptr += 2*eBufferedPixelWidthInBytes;        }        else if ((fPixelFilteredFlags[0][pixelNum] & e11s)                && (fPixelFilteredFlags[1][pixelNum] & e11n))        {            /*    -                 | |                  -   We have two 1x1s.                  -                 | |                  -            */            upPixel = get4Pixel(row2Ptr);            currPixel = get4Pixel(row3Ptr);            R1 = GetRed(currPixel);            G1 = GetGreen(currPixel);            B1 = GetBlue(currPixel);            R0 = GetRed(upPixel);            G0 = GetGreen(upPixel);            B0 = GetBlue(upPixel);            if ((fMaxErrorForTwoPixels >= 3) && (NewDeltaE(R1, R0, G1, G0, B1, B0, fMaxErrorForTwoPixels)))            {                /*    -                     | |  build 1x2.                     | |                      -                */#if kGatherStats == 1                blockStats[es12w]++;#endif                AverageNRound(isOdd(pixelNum), R1, R1, R0, G1, G1, G0, B1, B1, B0);                if(littleEndian)                    currPixel = (R1<<16) + (G1<<8) + B1;                else if(bigEndian)                    currPixel = (R1<<24) + (G1<<16) + (B1<<8);                // Note we write this block out now and do not delay the writes for the postprocessing step since we do not track this block.                put4Pixel(row2Ptr, 0, currPixel);                put4Pixel(row3Ptr, 0, currPixel);                fPixelFilteredFlags[0][pixelNum] = fPixelFilteredFlags[0][pixelNum] & ~e11s;                fPixelFilteredFlags[1][pixelNum] = fPixelFilteredFlags[1][pixelNum] & ~e11n;  // Note that we just formed a 2x2 in the middle of the filtered sets of rows (and do not remember it). We then remove the 2x1s that the 2x2 eliminated.            }            pixelNum += 1;            row1Ptr += eBufferedPixelWidthInBytes;            row2Ptr += eBufferedPixelWidthInBytes;            row3Ptr += eBufferedPixelWidthInBytes;        }        else // Do no vertical filtering here.        {            pixelNum += 1;            row1Ptr += eBufferedPixelWidthInBytes;            row2Ptr += eBufferedPixelWidthInBytes;            row3Ptr += eBufferedPixelWidthInBytes;        }    }}#define NEWTEST trueinline bool TErnieFilter::NewDeltaE(int dr0, int dr1, int dg0, int dg1, int db0, int db1, int tolerance){    int Y0, Y1, dY, Cr0, Cr1, Cb0, Cb1, dCr, dCb;    // new Delta E stuff from Jay    Y0 = 5*dr0 + 9*dg0 + 2*db0;    Y1 = 5*dr1 + 9*dg1 + 2*db1;    dY = ABS(Y0 - Y1) >> 4;    if(dY > tolerance) {        return false;    }    else    {        Cr0 = (dr0 << 4) - Y0;        Cr1 = (dr1 << 4) - Y1;        dCr = ABS(Cr0 - Cr1) >> 5;        if(dCr > tolerance)        {            return false;        }        else        {            Cb0 = (db0 << 4) - Y0;            Cb1 = (db1 << 4) - Y1;            dCb = ABS(Cb0 - Cb1) >> 6;            if(dCb > tolerance)            {                return false;            }        }    }    return true;}TErnieFilter::TErnieFilter(int rowWidthInPixels, pixelTypes pixelType, unsigned int maxErrorForTwoPixels, int bytesPerPixel): fOriginalPixelSize(bytesPerPixel){    int index;    ASSERT((fOriginalPixelSize == 3) || (fOriginalPixelSize == 4));    ASSERT(rowWidthInPixels > 0);    ASSERT(pixelType == eBGRPixelData);    fInternalBufferPixelSize = 4;    fPixelOffsetIndex = 0;    fRowWidthInPixels = rowWidthInPixels;    fRowWidthInBytes = fRowWidthInPixels*fInternalBufferPixelSize;    fMaxErrorForTwoPixels = maxErrorForTwoPixels;    for (index = 0; index < 4; index++)    {        fRowBuf[index] = new uint32_t[rowWidthInPixels];        ASSERT(fRowBuf[index]);        fRowPtr[index] = new unsigned char[rowWidthInPixels*fOriginalPixelSize];		ASSERT(fRowPtr[index]);		fBlackRowPtr[index] = new BYTE[rowWidthInPixels*fOriginalPixelSize];		ASSERT(fBlackRowPtr[index]);		BlackRasterSize[index] = 0;    }    for (index = 0; index < 2; index++)    {        fPixelFilteredFlags[index] = new unsigned int[rowWidthInPixels];        ASSERT(fPixelFilteredFlags[index]);    }    // The least compressible image will be all raw pixels. Maximum compressed size is:    // full size + a bloat of Cmd byte + 1 VLI byte per 255 pixels rounded up to nearest integer.    int maxCompressionBufSize = fRowWidthInBytes + 1 + ((int)ceil(MAX((rowWidthInPixels-2)/255, 0)));    fCompressionOutBuf = new unsigned char[maxCompressionBufSize];    ASSERT(fCompressionOutBuf);    fNumberOfBufferedRows = 0;    fPixelOffset[0] = 0;    fPixelOffset[1] = 5;    fPixelOffset[2] = 2;    fPixelOffset[3] = 7;    fPixelOffset[4] = 1;    fPixelOffset[5] = 4;    fPixelOffset[6] = 6;    fPixelOffset[7] = 3;	RowIndex = 0;}TErnieFilter::~TErnieFilter(){    // Deallocate memory next.    int index;    for (index = 0; index < 4; index++)    {        delete [] fRowBuf[index];        delete [] fRowPtr[index];		delete [] fBlackRowPtr[index];    }    for (index = 0; index < 2; index++)    {        delete [] fPixelFilteredFlags[index];    }    delete [] fCompressionOutBuf;}void TErnieFilter::writeBufferedRows(){    int pixelIndex = 0;    // We just have one lonely raster left.  Nothing    // we can do but filter it horizontally.    if( 1 == fNumberOfBufferedRows)    {        int offset2 = fPixelOffset[fPixelOffsetIndex];        Filter1RawRow( (unsigned char*)(fRowBuf[0] + offset2),                       fRowWidthInPixels - fPixelOffset[fPixelOffsetIndex],                       fPixelFilteredFlags[0] + fPixelOffset[fPixelOffsetIndex]);        unsigned char *rowPtr = fRowPtr[0];        ASSERT(rowPtr);        pixelIndex = 0;        do        {            memcpy(rowPtr, &fRowBuf[0][pixelIndex], 3);            rowPtr += 3;        } while (++pixelIndex < fRowWidthInPixels);    }    // If we've got a pair of rasters in the buffer, that pair    // has already been filtered somewhat.  So lets just write them    // out, some filtering is better than none.    else if (2 == fNumberOfBufferedRows)    {        // Write the two rows back out.        int k;        for (k = 0; k < 2; k++)        {            unsigned char *rowPtr = fRowPtr[k];            ASSERT(rowPtr);            pixelIndex = 0;            do            {                memcpy(rowPtr, &fRowBuf[k][pixelIndex], 3);                rowPtr += 3;            } while (++pixelIndex < fRowWidt

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -