restored original params for JPEG codec

This commit is contained in:
csoler 2015-08-14 22:44:39 -04:00
parent 5aac92fc97
commit 49c6c8a1fa

View File

@ -9,7 +9,7 @@
#include "QVideoDevice.h" #include "QVideoDevice.h"
VideoProcessor::VideoProcessor() VideoProcessor::VideoProcessor()
:_encoded_frame_size(256,256) :_encoded_frame_size(128,128)
{ {
_decoded_output_device = NULL ; _decoded_output_device = NULL ;
_encoding_current_codec = VIDEO_PROCESSOR_CODEC_ID_JPEG_VIDEO; _encoding_current_codec = VIDEO_PROCESSOR_CODEC_ID_JPEG_VIDEO;
@ -40,6 +40,8 @@ bool VideoProcessor::processImage(const QImage& img,uint32_t size_hint,uint32_t&
codec->encodeData(img.scaled(_encoded_frame_size,Qt::IgnoreAspectRatio,Qt::SmoothTransformation),size_hint,chunk) ; codec->encodeData(img.scaled(_encoded_frame_size,Qt::IgnoreAspectRatio,Qt::SmoothTransformation),size_hint,chunk) ;
encoded_size = chunk.size ;
if(chunk.size == 0) // the codec might be buffering the frame for compression reasons if(chunk.size == 0) // the codec might be buffering the frame for compression reasons
return true ; return true ;
@ -147,7 +149,6 @@ bool JPEGVideo::decodeData(const RsVOIPDataChunk& chunk,QImage& image)
return false ; return false ;
} }
if(flags & JPEG_VIDEO_FLAGS_DIFFERENTIAL_FRAME) if(flags & JPEG_VIDEO_FLAGS_DIFFERENTIAL_FRAME)
{ {
if(_decoded_reference_frame.size() != image.size()) if(_decoded_reference_frame.size() != image.size())
@ -187,6 +188,9 @@ bool JPEGVideo::encodeData(const QImage& image,uint32_t /* size_hint */,RsVOIPDa
for(uint32_t i=0;i<image.byteCount();++i) for(uint32_t i=0;i<image.byteCount();++i)
{ {
// We cannot use basic modulo 256 arithmetic, because the decompressed JPeg frames do not follow the same rules (values are clamped)
// and cause color blotches when perturbated by a differential frame.
int diff = ( (int)image.bits()[i] - (int)_encoded_reference_frame.bits()[i]) + 128; int diff = ( (int)image.bits()[i] - (int)_encoded_reference_frame.bits()[i]) + 128;
encoded_frame.bits()[i] = (unsigned char)std::max(0,std::min(255,diff)) ; encoded_frame.bits()[i] = (unsigned char)std::max(0,std::min(255,diff)) ;
} }
@ -199,7 +203,7 @@ bool JPEGVideo::encodeData(const QImage& image,uint32_t /* size_hint */,RsVOIPDa
_encoded_reference_frame = image ; _encoded_reference_frame = image ;
encoded_frame = image ; encoded_frame = image ;
differential_frame = false ; differential_frame = false ;
} }
QByteArray qb ; QByteArray qb ;