MCPcopy Create free account
hub / github.com/IENT/YUView / copyImgToByteArray

Method copyImgToByteArray

YUViewLib/src/decoder/decoderVVDec.cpp:485–534  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

483}
484
485void decoderVVDec::copyImgToByteArray(QByteArray &dst)
486{
487 auto fmt = this->currentFrame->colorFormat;
488 if (fmt == VVDEC_CF_INVALID)
489 {
490 DEBUG_vvdec("decoderVVDec::copyImgToByteArray picture format is unknown");
491 return;
492 }
493 const auto nrPlanes = this->currentFrame->numPlanes;
494 const auto bytesPerSample = this->currentFrame->bitDepth > 8 ? 2 : 1;
495 const auto lumaSize = Size({this->currentFrame->width, this->currentFrame->height});
496 const auto chromaSize = calculateChromaSize(lumaSize, fmt);
497
498 auto outSizeLumaBytes = lumaSize.width * lumaSize.height * bytesPerSample;
499 auto outSizeChromaBytes = chromaSize.width * chromaSize.height * bytesPerSample;
500 // How many bytes do we need in the output buffer?
501 auto nrBytesOutput = (outSizeLumaBytes + outSizeChromaBytes * 2);
502 DEBUG_vvdec("decoderVVDec::copyImgToByteArray nrBytesOutput %d", nrBytesOutput);
503
504 // Is the output big enough?
505 if (dst.capacity() < int(nrBytesOutput))
506 dst.resize(int(nrBytesOutput));
507
508 for (unsigned c = 0; c < nrPlanes; c++)
509 {
510 auto &component = this->currentFrame->planes[c];
511
512 auto widthBytes = component.width * bytesPerSample;
513 auto plane = component.ptr;
514
515 if (component.ptr == nullptr)
516 {
517 DEBUG_vvdec("decoderVVDec::copyImgToByteArray unable to get plane for component %d", c);
518 return;
519 }
520
521 unsigned char *restrict d = (unsigned char *)dst.data();
522 if (c > 0)
523 d += outSizeLumaBytes;
524 if (c == 2)
525 d += outSizeChromaBytes;
526
527 for (unsigned y = 0; y < component.height; y++)
528 {
529 std::memcpy(d, plane, widthBytes);
530 plane += component.stride;
531 d += widthBytes;
532 }
533 }
534}
535
536QString decoderVVDec::getDecoderName() const
537{

Callers

nothing calls this directly

Calls 5

SizeClass · 0.85
calculateChromaSizeFunction · 0.85
capacityMethod · 0.80
resizeMethod · 0.80
dataMethod · 0.45

Tested by

no test coverage detected