MCPcopy Create free account
hub / github.com/RetroShare/RetroShare / decodeData

Method decodeData

plugins/VOIP/gui/VideoProcessor.cpp:327–369  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

325}
326
327bool JPEGVideo::decodeData(const RsVOIPDataChunk& chunk,QImage& image)
328{
329 // now see if the frame is a differential frame, or just a reference frame.
330
331 uint16_t codec = ((unsigned char *)chunk.data)[0] + (((unsigned char *)chunk.data)[1] << 8) ;
332 uint16_t flags = ((unsigned char *)chunk.data)[2] + (((unsigned char *)chunk.data)[3] << 8) ;
333
334 assert(codec == VideoProcessor::VIDEO_PROCESSOR_CODEC_ID_JPEG_VIDEO) ;
335
336 // un-compress image data
337
338 QByteArray qb((char*)&((uint8_t*)chunk.data)[HEADER_SIZE],(int)chunk.size - HEADER_SIZE) ;
339
340 if(!image.loadFromData(qb,"JPEG"))
341 {
342 std::cerr << "image.loadFromData(): returned an error.: " << std::endl;
343 return false ;
344 }
345
346 if(flags & JPEG_VIDEO_FLAGS_DIFFERENTIAL_FRAME)
347 {
348 if(_decoded_reference_frame.size() != image.size())
349 {
350 std::cerr << "Bad reference frame!" << std::endl;
351 return false ;
352 }
353
354 QImage res = _decoded_reference_frame ;
355
356 for(int i=0;i<image.byteCount();++i)
357 {
358 int new_val = (int)res.bits()[i] + ((int)image.bits()[i] - 128) ;
359
360 res.bits()[i] = std::max(0,std::min(255,new_val)) ;
361 }
362
363 image = res ;
364 }
365 else
366 _decoded_reference_frame = image ;
367
368 return true ;
369}
370
371bool JPEGVideo::encodeData(const QImage& image,uint32_t /* size_hint */,RsVOIPDataChunk& voip_chunk)
372{

Callers 1

receiveEncodedDataMethod · 0.80

Calls 1

sizeMethod · 0.45

Tested by

no test coverage detected