Intel® Integrated Performance Primitives
Deliberate problems developing high-performance vision, signal, security, and storage applications.

blank image for JPEG XR Encoding

danielwang1971
Beginner
815 Views

Hello,

II try to use UIC::JpegExEncoder to compress a Mono 640x480  8bit image.Encodiong seems OK no error.

But the result image is blank. Quality is 75.   Do you have any idea?

Thanks

The Bmp and wdp file attached(Rename Camera 1-1.wdp.jpg to Camera 1-1.wdp). And followed is my code:

bool EncodeJPEGXRImage(CIppImage& image,BaseStreamOutput& out,CJPEGXRIppImageInitParam* param,int thread)

{

  Image                 imageCn;

  Rect                  refgrid;

  Point                 origin;

  RectSize              size;

  ImageDataPtr          dataPtr;

  ImageColorSpec        colorSpec;

  ImageDataOrder        dataOrder;

  ImageSamplingGeometry geometry;

  Ipp32u iChannels;

  Ipp32u iPrecision;

  Ipp32u iFormat;

  Ipp32u iDU;

  Ipp32u bAlphaPresent = 0;

  Ipp16u iTilesUniform[4] = {0};

  Ipp32u iWidth = image.Width();

  Ipp32u iHeight = image.Height();

  InputParams inParams;

  Ipp32u i;

 

intalpha_mode = 0;

 

int   aquality = 1;

  JPEGXREncoder encoder;

  iTilesUniform[0] =  0;

  iTilesUniform[1] =  0;

  iTilesUniform[2] =  (iWidth < 16)?0:iWidth/16;

  iTilesUniform[3] =  (iHeight < 16)?0:iHeight/16;

  inParams.iQuality      = (param->Quality* 255)/100;

 

if(inParams.iQuality < 0) inParams.iQuality = 1;

  aquality = inParams.iQuality;

  inParams.iOverlap      = 0;

  inParams.iBands        = 0;

  inParams.iSampling     = 0;

  inParams.iTrim         = 0;

  inParams.bFrequency    = 0;

  inParams.bCMYKD        = 0;

  inParams.iShift        = -1;

  inParams.bAlphaPlane   = 0;

  inParams.pTilesUniform = iTilesUniform;

 

if(ExcStatusOk != encoder.Init())

   

returnfalse;

 

if(ExcStatusOk != encoder.SetParams(inParams))

   

returnfalse;

 

if(ExcStatusOk != encoder.AttachStream(out))

   

returnfalse;

  iChannels  = image.NChannels();

  iPrecision = image.Precision();

  iFormat    = image.Format();

  iDU        = iPrecision/8;

  size.SetWidth(image.Width());

  size.SetHeight(image.Height());

  origin.SetX(0);

  origin.SetY(0);

  refgrid.SetOrigin(origin);

  refgrid.SetSize(size);

  geometry.SetRefGridRect(refgrid);

  geometry.ReAlloc(iChannels);

  geometry.SetEnumSampling(UIC::S444);

  dataOrder.ReAlloc(Interleaved, iChannels);

  dataOrder.PixelStep()[0] = iChannels * iDU;

  dataOrder.LineStep() [0] = image.Step();

  imageCn.ColorSpec().ReAlloc(iChannels);

  imageCn.ColorSpec().SetEnumColorSpace((ImageEnumColorSpace)image.Color());

  imageCn.ColorSpec().SetColorSpecMethod(Enumerated);

  imageCn.ColorSpec().SetComponentToColorMap(Direct);

 

for(i = 0; i < iChannels; i++)

  {

   

if(iPrecision <= 8)

      imageCn.ColorSpec().DataRange().SetAsRange8u(IPP_MAX_8U);

   

elseif(iPrecision <= 16)

    {

     

if(iFormat == IF_UNSIGNED)

        imageCn.ColorSpec().DataRange().SetAsRange16u(IPP_MAX_16U);

     

elseif(iFormat == IF_FIXED)

        imageCn.ColorSpec().DataRange().SetAsRange16s(IPP_MIN_16S, IPP_MAX_16S);

     

else

        imageCn.ColorSpec().DataRange().SetAsRange16f(IPP_MAX_16U);

    }

   

else

    {

     

if(iFormat == IF_UNSIGNED)

        imageCn.ColorSpec().DataRange().SetAsRange32u(IPP_MAX_32U);

     

elseif(iFormat == IF_FIXED)

        imageCn.ColorSpec().DataRange().SetAsRange32s(IPP_MIN_32S, IPP_MAX_32S);

     

else

        imageCn.ColorSpec().DataRange().SetAsRange32f((Ipp32f)IPP_MIN_32S, (Ipp32f)IPP_MAX_32S);

    }

  }

  dataPtr.p8u = image;

  imageCn.Buffer().Attach(&dataPtr, dataOrder, geometry);

 

if(ExcStatusOk != encoder.AttachImage(imageCn))

   

returnfalse;

 

if(ExcStatusOk != encoder.WriteFileHeader(alpha_mode))

   

returnfalse;

 

// Planar alpha support

 

switch(image.Color())

  {

 

caseRGBA:

 

caseBGRA:

 

caseRGBAP:

 

caseBGRAP:

 

caseCMYKA:

    bAlphaPresent = 1;

   

break;

  }

 

if(bAlphaPresent && alpha_mode == 1)

  {

    CIppImage imagePrimary;

    CIppImage imageAlpha;

    IppiSize  iROI = {image.Width(), image.Height()};

    Ipp8u*    pData = image;

    Ipp8u*    pDataPr;

    Ipp8u*    pDataAl;

    Ipp32u    iStep = image.Step();

    Ipp32u    iPStep, iAStep;

    Ipp32u    i, j;

   

if(0 != imagePrimary.Alloc(image.Width(), image.Height(), iChannels - 1, iPrecision, 1))

     

returnfalse;

   

if(0 != imageAlpha.Alloc(image.Width(), image.Height(), 1, iPrecision, 1))

     

returnfalse;

    pDataPr = imagePrimary;

    iPStep  = imagePrimary.Step();

    pDataAl = imageAlpha;

    iAStep  = imageAlpha.Step();

   

if(iPrecision == 8)

    {

     

if(image.Color() == IC_CMYKA)

      {

       

for(i = 0; i < iHeight; i++)

        {

          Ipp8u* pSrc = pData + iStep * i;

          Ipp8u* pDstPr = pDataPr + iPStep * i;

          Ipp8u* pDstAl = pDataAl + iAStep * i;

         

for(j = 0; j < iWidth; j++, pSrc += 5, pDstPr += 4, pDstAl++)

          {

            pDstPr[0] = pSrc[0];

            pDstPr[1] = pSrc[1];

            pDstPr[2] = pSrc[2];

            pDstPr[3] = pSrc[3];

            pDstAl[0] = pSrc[4];

          }

        }

      }

     

else

      {

        ippiCopy_8u_AC4C3R(pData, iStep, pDataPr, iPStep, iROI);

        ippiCopy_8u_C4C1R(pData + 3, iStep, pDataAl, iAStep, iROI);

      }

    }

   

elseif(iPrecision == 16)

    {

     

if(image.Color() == IC_CMYKA)

      {

       

for(i = 0; i < iHeight; i++)

        {

          Ipp16u* pSrc = (Ipp16u*)(pData + iStep * i);

          Ipp16u* pDstPr = (Ipp16u*)(pDataPr + iPStep * i);

          Ipp16u* pDstAl = (Ipp16u*)(pDataAl + iAStep * i);

         

for(j = 0; j < iWidth; j++, pSrc += 5, pDstPr += 4, pDstAl++)

          {

            pDstPr[0] = pSrc[0];

            pDstPr[1] = pSrc[1];

            pDstPr[2] = pSrc[2];

            pDstPr[3] = pSrc[3];

            pDstAl[0] = pSrc[4];

          }

        }

      }

     

else

      {

        ippiCopy_16s_AC4C3R((Ipp16s*)pData, iStep, (Ipp16s*)pDataPr, iPStep, iROI);

        ippiCopy_16s_C4C1R((Ipp16s*)pData + 3, iStep, (Ipp16s*)pDataAl, iAStep, iROI);

      }

    }

   

else

    {

      ippiCopy_32s_AC4C3R((Ipp32s*)pData, iStep, (Ipp32s*)pDataPr, iPStep, iROI);

      ippiCopy_32s_C4C1R((Ipp32s*)pData + 3, iStep, (Ipp32s*)pDataAl, iAStep, iROI);

    }

    geometry.SetRefGridRect(refgrid);

    geometry.ReAlloc(iChannels - 1);

    geometry.SetEnumSampling(UIC::S444);

    dataOrder.ReAlloc(Interleaved, iChannels - 1);

    dataOrder.PixelStep()[0] = (iChannels - 1) * iDU;

    dataOrder.LineStep() [0] = iPStep;

   

switch(imageCn.ColorSpec().EnumColorSpace())

    {

   

caseBGRA:  imageCn.ColorSpec().SetEnumColorSpace(BGR); break;

   

caseRGBA:  imageCn.ColorSpec().SetEnumColorSpace(RGB); break;

   

caseBGRAP: imageCn.ColorSpec().SetEnumColorSpace(BGR); break;

   

caseRGBAP: imageCn.ColorSpec().SetEnumColorSpace(RGB); break;

   

caseCMYKA: imageCn.ColorSpec().SetEnumColorSpace(CMYK);break;

   

default:

     

returnfalse;

    }

    dataPtr.p8u = pDataPr;

    imageCn.Buffer().Attach(&dataPtr, dataOrder, geometry);

   

if(ExcStatusOk != encoder.AttachImage(imageCn))

     

returnfalse;

   

if(ExcStatusOk != encoder.WriteHeader())

     

returnfalse;

   

if(ExcStatusOk != encoder.WriteData())

     

returnfalse;

   

if(ExcStatusOk != encoder.FreeData())

     

returnfalse;

    geometry.SetRefGridRect(refgrid);

    geometry.ReAlloc(1);

    geometry.SetEnumSampling(UIC::S444);

    dataOrder.ReAlloc(Interleaved, 1);

    dataOrder.PixelStep()[0] = iDU;

    dataOrder.LineStep() [0] = iAStep;

    imageCn.ColorSpec().SetEnumColorSpace(Grayscale);

    dataPtr.p8u = pDataAl;

    imageCn.Buffer().Attach(&dataPtr, dataOrder, geometry);

    inParams.iQuality    = aquality;

    inParams.bAlphaPlane = 1;

   

if(ExcStatusOk != encoder.SetParams(inParams))

     

returnfalse;

   

if(ExcStatusOk != encoder.AttachImage(imageCn))

     

returnfalse;

   

if(ExcStatusOk != encoder.WriteHeader())

     

returnfalse;

   

if(ExcStatusOk != encoder.WriteData())

     

returnfalse;

   

if(ExcStatusOk != encoder.FreeData())

     

returnfalse;

  }

 

else

  {

   

if(ExcStatusOk != encoder.WriteHeader())

     

returnfalse;

   

if(ExcStatusOk != encoder.WriteData())

     

returnfalse;

   

if(ExcStatusOk != encoder.FreeData())

     

returnfalse;

  }

 

returntrue;

}

0 Kudos
3 Replies
Chao_Y_Intel
Moderator
815 Views
Hello, The attached input bmp file looks corrupted, and cannot open from here. Could you have a check? Thanks, Chao
0 Kudos
danielwang1971
Beginner
815 Views
OK,Please try again. Thanks
0 Kudos
danielwang1971
Beginner
815 Views
Hi, I found problem:amount of tiles per rows and columns can't be 0. So the fix is: iTilesUniform[0] = 1; iTilesUniform[1] = 1; Thanks.
0 Kudos
Reply