Quantcast
Channel: Intel® Software - Intel® Integrated Performance Primitives
Viewing all articles
Browse latest Browse all 1489

UIC Jpeg encoding color distortion

$
0
0

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()[i].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;
		

 


Viewing all articles
Browse latest Browse all 1489

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>