예제 #1
0
CodecError CCodec_DXT5::Compress_SuperFast(CCodecBuffer& bufferIn, CCodecBuffer& bufferOut, Codec_Feedback_Proc pFeedbackProc, CMP_DWORD_PTR pUser1, CMP_DWORD_PTR pUser2)
{
    assert(bufferIn.GetWidth() == bufferOut.GetWidth());
    assert(bufferIn.GetHeight() == bufferOut.GetHeight());

    if(bufferIn.GetWidth() != bufferOut.GetWidth() || bufferIn.GetHeight() != bufferOut.GetHeight())
        return CE_Unknown;

    const CMP_DWORD dwBlocksX = ((bufferIn.GetWidth() + 3) >> 2);
    const CMP_DWORD dwBlocksY = ((bufferIn.GetHeight() + 3) >> 2);

    CMP_DWORD compressedBlock[4];
    CMP_BYTE srcBlock[BLOCK_SIZE_4X4X4];
    for(CMP_DWORD j = 0; j < dwBlocksY; j++)
    {
        for(CMP_DWORD i = 0; i < dwBlocksX; i++)
        {
            bufferIn.ReadBlockRGBA(i*4, j*4, 4, 4, srcBlock);
            CompressRGBABlock_SuperFast(srcBlock, compressedBlock);
            bufferOut.WriteBlock(i*4, j*4, compressedBlock, 4);
        }
        if(pFeedbackProc)
        {
            float fProgress = 100.f * (j * dwBlocksX) / (dwBlocksX * dwBlocksY);
            if(pFeedbackProc(fProgress, pUser1, pUser2))
                return CE_Aborted;
        }
    }

    return CE_OK;
}
void CCodec_DXT5_xRBG::ReadBlock(CCodecBuffer& buffer, CMP_DWORD x, CMP_DWORD y, CMP_BYTE block[BLOCK_SIZE_4X4X4])
{
    CMP_BYTE dwTempBlock[BLOCK_SIZE_4X4X4];
    buffer.ReadBlockRGBA(x, y, 4, 4, dwTempBlock);
    for(CMP_DWORD i = 0; i < BLOCK_SIZE_4X4; i++)
        ((DWORD*)block)[i] = SWIZZLE_RGBA_xRBG(((DWORD*)dwTempBlock)[i]);
}
void CCodec_DXT5_xRBG::ReadBlock(CCodecBuffer& buffer, CMP_DWORD x, CMP_DWORD y, CODECFLOAT block[BLOCK_SIZE_4X4X4])
{
    CODECFLOAT fTempBlock[BLOCK_SIZE_4X4X4];
    buffer.ReadBlockRGBA(x, y, 4, 4, fTempBlock);
    for(CMP_DWORD i = 0; i < BLOCK_SIZE_4X4; i++)
    {
        block[(i* 4) + RGBA32F_OFFSET_R] = 0.0;
        block[(i* 4) + RGBA32F_OFFSET_G] = fTempBlock[(i* 4) + RGBA32F_OFFSET_R];
        block[(i* 4) + RGBA32F_OFFSET_B] = fTempBlock[(i* 4) + RGBA32F_OFFSET_B];
        block[(i* 4) + RGBA32F_OFFSET_A] = fTempBlock[(i* 4) + RGBA32F_OFFSET_G];
    }
}
void CCodecBuffer_R8::Copy(CCodecBuffer& srcBuffer)
{
    if(GetWidth() != srcBuffer.GetWidth() || GetHeight() != srcBuffer.GetHeight())
        return;

    const CMP_DWORD dwBlocksX = ((GetWidth() + 3) >> 2);
    const CMP_DWORD dwBlocksY = ((GetHeight() + 3) >> 2);

    for(CMP_DWORD j = 0; j < dwBlocksY; j++)
    {
        for(CMP_DWORD i = 0; i < dwBlocksX; i++)
        {
            CMP_BYTE block[BLOCK_SIZE_4X4X4];
            srcBuffer.ReadBlockRGBA(i*4, j*4, 4, 4, block);
            WriteBlockRGBA(i*4, j*4, 4, 4, block);
        }
    }
}
예제 #5
0
CodecError CCodec_DXT5::Compress(CCodecBuffer& bufferIn, CCodecBuffer& bufferOut, Codec_Feedback_Proc pFeedbackProc, CMP_DWORD_PTR pUser1, CMP_DWORD_PTR pUser2)
{
#ifndef _WIN64  //todo: add sse2 feature for win64
    if(m_nCompressionSpeed == CMP_Speed_SuperFast && m_bUseSSE2)
        return Compress_SuperFast(bufferIn, bufferOut, pFeedbackProc, pUser1, pUser2);
    else if((m_nCompressionSpeed == CMP_Speed_Fast || m_nCompressionSpeed == CMP_Speed_SuperFast) && m_bUseSSE)
        return Compress_Fast(bufferIn, bufferOut, pFeedbackProc, pUser1, pUser2);
#endif
    assert(bufferIn.GetWidth() == bufferOut.GetWidth());
    assert(bufferIn.GetHeight() == bufferOut.GetHeight());

    if(bufferIn.GetWidth() != bufferOut.GetWidth() || bufferIn.GetHeight() != bufferOut.GetHeight())
        return CE_Unknown;


    #ifdef DXT5_COMPDEBUGGER
    CompViewerClient    g_CompClient;
    if (g_CompClient.connect())
    {
        DbgTrace(("-------> Remote Server Connected"));
    }
    #endif
    
    const CMP_DWORD dwBlocksX = ((bufferIn.GetWidth() + 3) >> 2);
    const CMP_DWORD dwBlocksY = ((bufferIn.GetHeight() + 3) >> 2);


    #ifdef DXT5_COMPDEBUGGER
    DbgTrace(("IN : BufferType %d ChannelCount %d ChannelDepth %d",bufferIn.GetBufferType(),bufferIn.GetChannelCount(),bufferIn.GetChannelDepth()));
    DbgTrace(("   : Height %d Width %d Pitch %d isFloat %d",bufferIn.GetHeight(),bufferIn.GetWidth(),bufferIn.GetWidth(),bufferIn.IsFloat()));

    DbgTrace(("OUT: BufferType %d ChannelCount %d ChannelDepth %d",bufferOut.GetBufferType(),bufferOut.GetChannelCount(),bufferOut.GetChannelDepth()));
    DbgTrace(("   : Height %d Width %d Pitch %d isFloat %d",bufferOut.GetHeight(),bufferOut.GetWidth(),bufferOut.GetWidth(),bufferOut.IsFloat()));
    #endif;


    bool bUseFixed = (!bufferIn.IsFloat() && bufferIn.GetChannelDepth() == 8 && !m_bUseFloat);

    for(CMP_DWORD j = 0; j < dwBlocksY; j++)
    {
        for(CMP_DWORD i = 0; i < dwBlocksX; i++)
        {
            CMP_DWORD compressedBlock[4];
            memset(compressedBlock,0,sizeof(compressedBlock));
            if(bUseFixed)
            {
                CMP_BYTE srcBlock[BLOCK_SIZE_4X4X4];
                memset(srcBlock,0,sizeof(srcBlock));
                bufferIn.ReadBlockRGBA(i*4, j*4, 4, 4, srcBlock);

                #ifdef DXT5_COMPDEBUGGER
                g_CompClient.SendData(1,sizeof(srcBlock),srcBlock);
                #endif

                CompressRGBABlock(srcBlock, compressedBlock, CalculateColourWeightings(srcBlock));
            }
            else
            {
                float srcBlock[BLOCK_SIZE_4X4X4];
                bufferIn.ReadBlockRGBA(i*4, j*4, 4, 4, srcBlock);
                CompressRGBABlock(srcBlock, compressedBlock, CalculateColourWeightings(srcBlock));
            }

            bufferOut.WriteBlock(i*4, j*4, compressedBlock, 4);
    
            #ifdef DXT5_COMPDEBUGGER 
                //g_CompClient.SendData(2,sizeof(compressedBlock),(byte *)&compressedBlock[0]);
            #endif

            #ifdef DXT5_COMPDEBUGGER // Checks decompression it should match or be close to source
                CMP_BYTE destBlock[BLOCK_SIZE_4X4X4];
                DecompressRGBABlock(destBlock, compressedBlock);
                g_CompClient.SendData(3,sizeof(destBlock),destBlock);
            #endif

        }
        if(pFeedbackProc)
        {
            float fProgress = 100.f * (j * dwBlocksX) / (dwBlocksX * dwBlocksY);
            if(pFeedbackProc(fProgress, pUser1, pUser2))
            {
                #ifdef DXT5_COMPDEBUGGER
                    g_CompClient.disconnect();
                #endif
                return CE_Aborted;
            }
        }
    }

    #ifdef DXT5_COMPDEBUGGER
        g_CompClient.disconnect();
    #endif
    return CE_OK;
}
예제 #6
0
CodecError CCodec_GT::Compress(CCodecBuffer& bufferIn, CCodecBuffer& bufferOut, Codec_Feedback_Proc pFeedbackProc, DWORD_PTR pUser1, DWORD_PTR pUser2)
{
    assert(bufferIn.GetWidth()    == bufferOut.GetWidth());
    assert(bufferIn.GetHeight() == bufferOut.GetHeight());

    if(bufferIn.GetWidth() != bufferOut.GetWidth() || bufferIn.GetHeight() != bufferOut.GetHeight())
        return CE_Unknown;

    CodecError err = InitializeGTLibrary();
    if (err != CE_OK) return err;

#ifdef GT_COMPDEBUGGER
    CompViewerClient    g_CompClient;
    if (g_CompClient.connect())
    {
        #ifdef USE_DBGTRACE
        DbgTrace(("-------> Remote Server Connected"));
        #endif
    }
#endif

    const CMP_DWORD dwBlocksX = ((bufferIn.GetWidth() + 3) >> 2);
    const CMP_DWORD dwBlocksY = ((bufferIn.GetHeight() + 3) >> 2);
    const CMP_DWORD dwBlocksXY = dwBlocksX*dwBlocksY;


    #ifdef USE_DBGTRACE
    DbgTrace(("IN : BufferType %d ChannelCount %d ChannelDepth %d",bufferIn.GetBufferType(),bufferIn.GetChannelCount(),bufferIn.GetChannelDepth()));
    DbgTrace(("   : Height %d Width %d Pitch %d isFloat %d",bufferIn.GetHeight(),bufferIn.GetWidth(),bufferIn.GetWidth(),bufferIn.IsFloat()));

    DbgTrace(("OUT: BufferType %d ChannelCount %d ChannelDepth %d",bufferOut.GetBufferType(),bufferOut.GetChannelCount(),bufferOut.GetChannelDepth()));
    DbgTrace(("   : Height %d Width %d Pitch %d isFloat %d",bufferOut.GetHeight(),bufferOut.GetWidth(),bufferOut.GetWidth(),bufferOut.IsFloat()));
    #endif;

    char            row,col,srcIndex;

    CMP_BYTE    *pOutBuffer;
    pOutBuffer    = bufferOut.GetData();

    CMP_BYTE*    pInBuffer;
    pInBuffer    =  bufferIn.GetData();

    DWORD block = 0;

    for(CMP_DWORD j = 0; j < dwBlocksY; j++)
    {

        for(CMP_DWORD i = 0; i < dwBlocksX; i++)
        {
            BYTE blockToEncode[BLOCK_SIZE_4X4][CHANNEL_SIZE_ARGB];
            CMP_BYTE srcBlock[BLOCK_SIZE_4X4X4];

            memset(srcBlock,0,sizeof(srcBlock));
            bufferIn.ReadBlockRGBA(i*4, j*4, 4, 4, srcBlock);

            #ifdef GT_COMPDEBUGGER
            g_CompClient.SendData(1,sizeof(srcBlock),srcBlock);
            #endif

            // Create the block for encoding
            srcIndex = 0;
            for(row=0; row < BLOCK_SIZE_4; row++)
            {
                for(col=0; col < BLOCK_SIZE_4; col++)
                {
                    blockToEncode[row*BLOCK_SIZE_4+col][BC_COMP_RED]        = srcBlock[srcIndex];
                    blockToEncode[row*BLOCK_SIZE_4+col][BC_COMP_GREEN]      = srcBlock[srcIndex+1];
                    blockToEncode[row*BLOCK_SIZE_4+col][BC_COMP_BLUE]       = srcBlock[srcIndex+2];
                    blockToEncode[row*BLOCK_SIZE_4+col][BC_COMP_ALPHA]      = srcBlock[srcIndex+3];
                    srcIndex+=4;
                }
            }

            EncodeGTBlock(blockToEncode,pOutBuffer+block);
            block += 16;

            #ifdef GT_COMPDEBUGGER // Checks decompression it should match or be close to source
            union BBLOCKS
            {
                CMP_DWORD    compressedBlock[4];
                BYTE            out[16];
                BYTE            in[16];
            } data;
            
            memset(data.in,0,sizeof(data));
            
            union DBLOCKS
            {
                double            blockToSave[16][4];
                double            block[64];
            } savedata;
        
            CMP_BYTE destBlock[BLOCK_SIZE_4X4X4];
            memset(savedata.block,0,sizeof(savedata));
            m_decoder->DecompressBlock(savedata.blockToSave,data.in);

            for (row=0; row<64; row++)
            {
                destBlock[row] = (BYTE)savedata.block[row];
            }
            g_CompClient.SendData(3,sizeof(destBlock),destBlock);
            #endif

        }

        if(pFeedbackProc)
        {
            float fProgress = 100.f * (j * dwBlocksX) / dwBlocksXY;
            if(pFeedbackProc(fProgress, pUser1, pUser2))
            {
                #ifdef GT_COMPDEBUGGER
                    g_CompClient.disconnect();
                #endif
                FinishGTEncoding();
                return CE_Aborted;
            }
        }

    }


    #ifdef GT_COMPDEBUGGER
    g_CompClient.disconnect();
    #endif

    return FinishGTEncoding();
}
예제 #7
0
CodecError CCodec_BC6H::Compress(CCodecBuffer& bufferIn, CCodecBuffer& bufferOut, Codec_Feedback_Proc pFeedbackProc, DWORD_PTR pUser1, DWORD_PTR pUser2)
{
    assert(bufferIn.GetWidth()    == bufferOut.GetWidth());
    assert(bufferIn.GetHeight() == bufferOut.GetHeight());

    if(bufferIn.GetWidth() != bufferOut.GetWidth() || bufferIn.GetHeight() != bufferOut.GetHeight())
        return CE_Unknown;

    CodecError err = CInitializeBC6HLibrary();
    if (err != CE_OK)
        return err;

#ifdef BC6H_COMPDEBUGGER
    CompViewerClient    g_CompClient;
    if (g_CompClient.connect())
    {
    #ifdef USE_DBGTRACE
        DbgTrace(("-------> Remote Server Connected"));
    #endif
    }
#endif

#ifdef BC6H_DEBUG_TO_RESULTS_TXT
    g_fp = fopen("AMD_Results.txt","w");
    g_block = 0;
#endif

    const CMP_DWORD dwBlocksX = ((bufferIn.GetWidth() + 3) >> 2);
    const CMP_DWORD dwBlocksY = ((bufferIn.GetHeight() + 3) >> 2);


#ifdef _REMOTE_DEBUG
    DbgTrace(("IN : BufferType %d ChannelCount %d ChannelDepth %d",bufferIn.GetBufferType(),bufferIn.GetChannelCount(),bufferIn.GetChannelDepth()));
    DbgTrace(("   : Height %d Width %d Pitch %d isFloat %d",bufferIn.GetHeight(),bufferIn.GetWidth(),bufferIn.GetWidth(),bufferIn.IsFloat()));

    DbgTrace(("OUT: BufferType %d ChannelCount %d ChannelDepth %d",bufferOut.GetBufferType(),bufferOut.GetChannelCount(),bufferOut.GetChannelDepth()));
    DbgTrace(("   : Height %d Width %d Pitch %d isFloat %d",bufferOut.GetHeight(),bufferOut.GetWidth(),bufferOut.GetWidth(),bufferOut.IsFloat()));
#endif;

    char            row,col,srcIndex;

    CMP_BYTE    *pOutBuffer;
    pOutBuffer    = bufferOut.GetData();

    CMP_BYTE*    pInBuffer;
    pInBuffer    =  bufferIn.GetData();

    DWORD block = 0;

#ifdef _SAVE_AS_BC6
    FILE *bc6file = fopen("Test.bc6", "wb");
#endif

    for(CMP_DWORD j = 0; j < dwBlocksY; j++)
    {

        for(CMP_DWORD i = 0; i < dwBlocksX; i++)
        {
            float blockToEncode[BLOCK_SIZE_4X4][CHANNEL_SIZE_ARGB];
            CMP_FLOAT srcBlock[BLOCK_SIZE_4X4X4];

            memset(srcBlock,0,sizeof(srcBlock));
            bufferIn.ReadBlockRGBA(i*4, j*4, 4, 4, srcBlock);

            #ifdef _BC6H_COMPDEBUGGER
            g_CompClient.SendData(1,sizeof(srcBlock),srcBlock);
            #endif

            // Create the block for encoding
            srcIndex = 0;
            for(row=0; row < BLOCK_SIZE_4; row++)
            {
                for(col=0; col < BLOCK_SIZE_4; col++)
                {
                    blockToEncode[row*BLOCK_SIZE_4+col][BC6H_COMP_RED]        = (float)srcBlock[srcIndex];
                    blockToEncode[row*BLOCK_SIZE_4+col][BC6H_COMP_GREEN]    = (float)srcBlock[srcIndex+1];
                    blockToEncode[row*BLOCK_SIZE_4+col][BC6H_COMP_BLUE]        = (float)srcBlock[srcIndex+2];
                    blockToEncode[row*BLOCK_SIZE_4+col][BC6H_COMP_ALPHA]    = (float)srcBlock[srcIndex+3];
                    srcIndex+=4;
                }
            }

            union BBLOCKS
            {
                CMP_DWORD    compressedBlock[4];
                BYTE            out[16];
                BYTE            in[16];
            } data;

            memset(data.in,0,sizeof(data));
            CEncodeBC6HBlock(blockToEncode,pOutBuffer+block);
            
#ifdef _SAVE_AS_BC6
            if (fwrite(pOutBuffer+block, sizeof(char), 16, bc6file) != 16)
                throw "File error on write";
#endif

            block += 16;


                #ifdef _BC6H_COMPDEBUGGER // Checks decompression it should match or be close to source
                union DBLOCKS
                {
                    float            blockToSave[16][4];
                    float            block[64];
                } savedata;
        
                CMP_BYTE destBlock[BLOCK_SIZE_4X4X4];
                memset(savedata.block,0,sizeof(savedata));
                m_decoder->DecompressBlock(savedata.blockToSave,data.in);

                for (row=0; row<64; row++)
                {
                    destBlock[row] = (BYTE)savedata.block[row];
                }
                g_CompClient.SendData(3,sizeof(destBlock),destBlock);
                #endif


                if(pFeedbackProc)
                {
                    float fProgress = 100.f * (j * dwBlocksX) / (dwBlocksX * dwBlocksY);
                    if(pFeedbackProc(fProgress, pUser1, pUser2))
                    {
                        #ifdef _BC6H_COMPDEBUGGER
                            g_CompClient.disconnect();
                        #endif
                        CFinishBC6HEncoding();
                        return CE_Aborted;
                    }
                }
        }
    }


    #ifdef _SAVE_AS_BC6
    if (fclose(bc6file)) throw "Close failed on .bc6 file";
    #endif

    #ifdef BC6H_COMPDEBUGGER
    g_CompClient.disconnect();
    #endif

    #ifdef BC6H_DEBUG_TO_RESULTS_TXT
        if (g_fp)
        fclose(g_fp);
    #endif

    if(pFeedbackProc)
    {
        float fProgress = 100.f;
        pFeedbackProc(fProgress, pUser1, pUser2);
    }
        
    return CFinishBC6HEncoding();
}