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

Method copyImgToByteArray

YUViewLib/src/decoder/decoderLibde265.cpp:470–528  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

468void decoderLibde265::copyImgToByteArray(const de265_image *src, byteArrayAligned &dst)
469#else
470void decoderLibde265::copyImgToByteArray(const de265_image *src, QByteArray &dst)
471#endif
472{
473 // How many image planes are there?
474 auto cMode = this->lib.de265_get_chroma_format(src);
475 int nrPlanes = (cMode == de265_chroma_mono) ? 1 : 3;
476
477 // At first get how many bytes we are going to write
478 int nrBytes = 0;
479 int stride;
480 for (int c = 0; c < nrPlanes; c++)
481 {
482 int width = this->lib.de265_get_image_width(src, c);
483 int height = this->lib.de265_get_image_height(src, c);
484 int nrBytesPerSample = (this->lib.de265_get_bits_per_pixel(src, c) > 8) ? 2 : 1;
485
486 nrBytes += width * height * nrBytesPerSample;
487 }
488
489 DEBUG_LIBDE265("decoderLibde265::copyImgToByteArray nrBytes %d", nrBytes);
490
491 // Is the output big enough?
492 if (dst.capacity() < nrBytes)
493 dst.resize(nrBytes);
494
495 uint8_t *dst_c = (uint8_t *)dst.data();
496
497 // We can now copy from src to dst
498 for (int c = 0; c < nrPlanes; c++)
499 {
500 const int width = this->lib.de265_get_image_width(src, c);
501 const int height = this->lib.de265_get_image_height(src, c);
502 const int nrBytesPerSample = (this->lib.de265_get_bits_per_pixel(src, c) > 8) ? 2 : 1;
503 const size_t widthInBytes = width * nrBytesPerSample;
504
505 const uint8_t *img_c = nullptr;
506 if (decodeSignal == 0)
507 img_c = this->lib.de265_get_image_plane(src, c, &stride);
508 else if (decodeSignal == 1)
509 img_c = this->lib.de265_internals_get_image_plane(
510 src, DE265_INTERNALS_DECODER_PARAM_SAVE_PREDICTION, c, &stride);
511 else if (decodeSignal == 2)
512 img_c = this->lib.de265_internals_get_image_plane(
513 src, DE265_INTERNALS_DECODER_PARAM_SAVE_RESIDUAL, c, &stride);
514 else if (decodeSignal == 3)
515 img_c = this->lib.de265_internals_get_image_plane(
516 src, DE265_INTERNALS_DECODER_PARAM_SAVE_TR_COEFF, c, &stride);
517
518 if (img_c == nullptr)
519 return;
520
521 for (int y = 0; y < height; y++)
522 {
523 memcpy(dst_c, img_c, widthInBytes);
524 img_c += stride;
525 dst_c += widthInBytes;
526 }
527 }

Callers 1

getRawFrameDataMethod · 0.95

Calls 3

capacityMethod · 0.80
resizeMethod · 0.80
dataMethod · 0.45

Tested by

no test coverage detected