- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hello,
I am using IPP 7.1 and figuring out from the uic_transcoder_con example, I have created my own wrapper of CJPEGDecoder to provide a limited number of decoding options. After finding some stumbling blocks, I stuck on one I cannot solve.
The returned image has a weird structure overlayed, so I guess the initialization has set some wrong step sizes or omits some of the needed conversions.
I made an small example which should run using the provided example image.
To have it run without exceptions I had to wrap the CJPEGDecoder and call the two fix_bug... functions.
[cpp]
int
bareboneExample( BYTE *pImageData, BYTE *pCompressedData, int nCompressedSize, int *resultRows, int *resultCols)
{
CMemBuffInput buffer;
MyCJPEGDecoder Decoder;
JERRCODE status;
JCOLOR color;
JSS sampling;
IppiSize size;
JDD m_DCT_SCALE=JDD::JD_1_2 ;
int nchannels,precision,expectedWidth,expectedHeight,step;
Decoder.Reset();//needed, otherwise there might be a System.AccessViolationException
if (!BaseStream::IsOk( buffer.Open ( pCompressedData, nCompressedSize)))
{
return -1;
}
status= Decoder.SetSource(&buffer);
if (status != JPEG_OK) return -2;
status = Decoder.ReadHeader(&size.width,&size.height,&nchannels,&color,&sampling,&precision);
if (status!=JPEG_OK) {
return -1;
}
if (precision!=8)
{
return -1;
}
JMODE mode=Decoder.Mode();
if( ( ! ((JMODE::JPEG_BASELINE == mode) || (JMODE::JPEG_PROGRESSIVE == mode))) && (m_DCT_SCALE > 0))
{
return -1;
}
Decoder.fixBug_needUpsampling (nchannels,sampling,1,m_DCT_SCALE);//needed, otherwise colored images will not be downscaled properly
expectedWidth = (size.width + 1) >> 1 ;
expectedHeight = (size.height + 1) >> 1 ;
step=expectedWidth* 1 * sizeof(Ipp8u) ;
size.width=expectedWidth ;
size.height=expectedHeight;
status=Decoder.SetDestination(pImageData ,step,size,1,JCOLOR::JC_GRAY ,JSS::JS_444 ,8,m_DCT_SCALE);
if (status != JPEG_OK)
{
return -1;
}
Decoder.fixBug_missingInitialization(max(nchannels,1));
status=Decoder.ReadData();
if (status != JPEG_OK)
{
return -1;
}
(*resultCols)=expectedWidth;
(*resultRows)=expectedHeight;
return 0;
}
[/cpp]
[cpp]
/// <summary>
/// Just wraps the CJPEGDecoder to give access to its protected members.
/// </summary>
class MyCJPEGDecoder: public CJPEGDecoder
{
public:
/// <summary>
/// Fixes the bug when a colored image is returned scaled down
/// </summary>
/// <param name="inpChannels">The inp channels.</param>
/// <param name="inpSampling">The inp sampling.</param>
/// <param name="outChannels">The out channels.</param>
/// <param name="outJDDScale">The out JDD scale.</param>
/// <returns></returns>
int fixBug_needUpsampling(int inpChannels , int inpSampling , int outChannels , int outJDDScale )
{
#ifdef noBugFixes
return 0;
#endif
int i ;
for (i=1;i<MAX_COMPS_PER_SCAN;i++)
{
if (inpSampling == JSS::JS_411 )
{
if (outJDDScale >= JDD::JD_1_2)//&&(outChannels>1))
m_ccomp.m_need_upsampling=0;
else
m_ccomp.m_need_upsampling=1;
}
}
return 0;
}
/// <summary>
/// Fixes the bug when a colored image is decoded to grayscale
/// missing initialization
/// </summary>
/// <param name="maxChannels">The max channels for input and output image</param>
/// <returns></returns>
JERRCODE fixBug_missingInitialization(int maxChannels)
{
#ifdef noBugFixes
return JERRCODE::JPEG_OK ;
#endif
if ((m_ccomp[maxChannels-1].m_v_factor == 0) || (m_ccomp[maxChannels-1].m_h_factor == 0))
return JERRCODE::JPEG_OK;
JERRCODE ret;
int old_m_dst_nChannels=m_dst.nChannels;
m_dst.nChannels=maxChannels;
ret = Init();
m_dst.nChannels = old_m_dst_nChannels ;
return ret;
}
};
[/cpp]
Any help is much appreciated.
Regards
David
PS Is there any other documentation on UIC other than the examples?
Link Copied

- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page