Пример #1
0
////////////////////////////////////////////////////////////////
//
// CPixelsManager::ChangePixelsFormat
//
// JPEG <-> PNG <-> PLAIN
//
////////////////////////////////////////////////////////////////
bool CPixelsManager::ChangePixelsFormat ( const CPixels& oldPixels, CPixels& newPixels, EPixelsFormatType newFormat, int uiQuality )
{
    EPixelsFormatType oldFormat = GetPixelsFormat ( oldPixels );
    if ( oldFormat == EPixelsFormat::UNKNOWN || newFormat == EPixelsFormat::UNKNOWN )
        return false;

    if ( oldFormat == newFormat )
    {
        // No change
        newPixels = oldPixels;
        return true;
    }

    if ( oldFormat == EPixelsFormat::PLAIN )
    {
        // Encode
        uint uiWidth, uiHeight;
        if ( !GetPixelsSize ( oldPixels, uiWidth, uiHeight ) )
            return false;

        if ( newFormat == EPixelsFormat::JPEG )
            return JpegEncode ( uiWidth, uiHeight, uiQuality, oldPixels.GetData (), oldPixels.GetSize () - 4, newPixels.buffer );
        else
        if ( newFormat == EPixelsFormat::PNG )
            return PngEncode ( uiWidth, uiHeight, oldPixels.GetData (), oldPixels.GetSize () - 4, newPixels.buffer );
    }
    else
    if ( newFormat == EPixelsFormat::PLAIN )
    {
        // Decode
        if ( oldFormat == EPixelsFormat::JPEG )
        {
            uint uiWidth, uiHeight;
            if ( JpegDecode ( oldPixels.GetData (), oldPixels.GetSize (), newPixels.buffer, uiWidth, uiHeight ) )
            {
                newPixels.buffer.SetSize ( uiWidth * uiHeight * 4 + SIZEOF_PLAIN_TAIL );
                return SetPlainDimensions ( newPixels, uiWidth, uiHeight );
            }
        }
        else
        if ( oldFormat == EPixelsFormat::PNG )
        {
            uint uiWidth, uiHeight;
            if ( PngDecode ( oldPixels.GetData (), oldPixels.GetSize (), newPixels.buffer, uiWidth, uiHeight ) )
            {
                newPixels.buffer.SetSize ( uiWidth * uiHeight * 4 + SIZEOF_PLAIN_TAIL );
                return SetPlainDimensions ( newPixels, uiWidth, uiHeight );
            }
        }
    }
    else
    {
        // Recode
        CPixels tempPixels;
        if ( ChangePixelsFormat ( oldPixels, tempPixels, EPixelsFormat::PLAIN ) )
            return ChangePixelsFormat ( tempPixels, newPixels, newFormat, uiQuality );
    }

    return false;
}
Пример #2
0
void main()
{
	FILE *fp;
	int file_len;

	fp = fopen("E:\\WORK\\JPEGSR6\\JPEG-6B\\DSC00115.JPG","rb");
	fseek(fp,0,SEEK_END);
	file_len = ftell(fp);
	fseek(fp,0,SEEK_SET);
	fread(in_buf,1,file_len,fp);
	fclose(fp);
	JpegDecode(in_buf,out_buf);
	fp = fopen("E:\\WORK\\JPEGSR6\\JPEG-6B\\out.raw","wb");
	fwrite(out_buf,1,640*480*3,fp);
	fclose(fp);
}
Пример #3
0
///////////////////////////////////////////////////////////////
//
// JpegGetDimensions
//
// This needs optimizing
//
///////////////////////////////////////////////////////////////
bool JpegGetDimensions ( const void* pData, uint uiDataSize, uint& uiOutWidth, uint& uiOutHeight )
{
    CBuffer temp;
    return JpegDecode ( pData, uiDataSize, temp, uiOutWidth, uiOutHeight );
}
Пример #4
0
///////////////////////////////////////////////////////////////
//
// JpegGetDimensions
//
//
//
///////////////////////////////////////////////////////////////
bool JpegGetDimensions(const void* pData, uint uiDataSize, uint& uiOutWidth, uint& uiOutHeight)
{
    return JpegDecode(pData, uiDataSize, nullptr, uiOutWidth, uiOutHeight);
}