- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I am trying to encode raw bitmap pixel data to a jpeg encoded equivalent. I am able to compile the uic example given (uic_transcoder_con) and everything is working fine. When I try to implement the sample into my code however I am getting a color distorted version of my original image. I have the same encoding parameters as the example and have tried using other combinations but to no success. I have attached a sample image I am trying to encode and the resulting jpeg I get after the encoding. Here is a snippet of the code I am trying out.
.....
//BEGIN ENCODING PROCESS
ExcStatus excStatus = ExcStatusOk;
JPEGEncoder encoder;
Image imageCn;
ImageDataPtr dataPtr;
ImageDataOrder dataOrder;
Rect refgrid;
RectSize size;
Point origin;
ImageSamplingGeometry geometry;
CMemBuffOutput* out = new CMemBuffOutput();
BaseStream::TSize mosize;
Ipp8u* buf;
int nOfComponents = numSamples;
//int du = ((8&255)+7)/8 ;
int step = dstWidth * nOfComponents;
mosize = step*dstHeight*2;
buf = (Ipp8u*)ippMalloc((int)mosize);
if(0 == buf)
return 1;
//open the output stream
out->Open(buf, (int)mosize);
excStatus = encoder.SetNOfThreads(1);
if(UIC::ExcStatusOk != status)
return 1;
//initialize encoder
excStatus = encoder.Init();
if(UIC::ExcStatusOk != status)
return 1;
//attach output stream to encoder
excStatus = encoder.AttachStream(*out);
if(ExcStatusOk != excStatus)
return 1;
dataOrder.SetDataType(T8u);
origin.SetX(0);
origin.SetY(0);
size.SetWidth(dstWidth);
size.SetHeight(dstHeight);
refgrid.SetOrigin(origin);
refgrid.SetSize(size);
geometry.SetRefGridRect(refgrid);
geometry.ReAlloc(nOfComponents);
geometry.SetEnumSampling(S444);
dataOrder.ReAlloc(Interleaved, nOfComponents);
dataOrder.PixelStep()[0] = nOfComponents;
dataOrder.LineStep() [0] = step;
imageCn.ColorSpec().ReAlloc(nOfComponents);
imageCn.ColorSpec().SetColorSpecMethod(Enumerated);
imageCn.ColorSpec().SetComponentToColorMap(Direct);
for(int i = 0; i < nOfComponents; i++)
{
imageCn.ColorSpec().DataRange().SetAsRange8u(255);
}
imageCn.ColorSpec().SetEnumColorSpace(ImageEnumColorSpace::RGBA);
//set pointer equal to resized pixel data (NOTE: imgResizeBuf is an unsigned char* )
dataPtr.p8u = imgResizeBuf;
//set the buffer of the image
imageCn.Buffer().Attach(&dataPtr,dataOrder,geometry);
if(ExcStatusOk != encoder.AttachImage(imageCn))
return 1;
//initialize encoding params
JPEGEncoderParamsBAS je_params;
je_params.SetColor((JCOLOR)ImageEnumColorSpace::YCbCr);
je_params.SetSampling(JSS::JS_444);
je_params.SetRestartInterval(1);
je_params.SetHuffmanOption(0);
je_params.SetQuality(100);
je_params.SetThreading((JTMODE)1);
if(ExcStatusOk != encoder.SetParams(je_params))
return 1;
excStatus = encoder.WriteHeader();
if(ExcStatusOk != excStatus)
return 1;
//encode the data
excStatus = encoder.WriteData();
if(ExcStatusOk != excStatus)
return 1;
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
How did you read BMP file? In uic_transcoder I see the channel swapping for 32-bit BMPs:
case 4:
status = ippiSwapChannels_8u_C4IR((Ipp8u*)m_imageData,m_step, m_roi, order);
break;
with order= int order_c4[4] = { 2, 1, 0, 3};
Did you do that?
Link Copied
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi Matthew,
As far as uci_transcoder_con works OK with this image, could your check the difference in JPEG encoder initialization between your source code and uic_transcoder. Just in debugger, line by line. Especially, when it concerns pixel type, channel number and color space. May be you need to specify BGRA instead of RGBA ?
Regards,
Sergey
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi Sergey,
I have ran both uic_transcoder_con and my source code at the same time and compared the jpeg encoder properties. They are identical to one another, (noChannels = 4, RGBA color space, etc.). The one line in my source code I am a bit concerned about is how I am allocating the dataPtr.p8u to an unsigned char* (imgResizeBuf). Could this be a possible problem? The reason I mention this is that I saw my memory output stream length after writing was not the same size as the one in the uic_transcoder_con.
Thanks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
How did you read BMP file? In uic_transcoder I see the channel swapping for 32-bit BMPs:
case 4:
status = ippiSwapChannels_8u_C4IR((Ipp8u*)m_imageData,m_step, m_roi, order);
break;
with order= int order_c4[4] = { 2, 1, 0, 3};
Did you do that?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi Sergey,
That was exactly my problem! Thank you so much for the quick reply.
Cheers
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page