| 473 | void decoderDav1d::copyImgToByteArray(const Dav1dPictureWrapper &src, byteArrayAligned &dst) |
| 474 | #else |
| 475 | void decoderDav1d::copyImgToByteArray(const Dav1dPictureWrapper &src, QByteArray &dst) |
| 476 | #endif |
| 477 | { |
| 478 | // How many image planes are there? |
| 479 | int nrPlanes = (src.getSubsampling() == Subsampling::YUV_400) ? 1 : 3; |
| 480 | |
| 481 | // At first get how many bytes we are going to write |
| 482 | const auto nrBytesPerSample = (src.getBitDepth() > 8) ? 2 : 1; |
| 483 | const auto framSize = src.getFrameSize(); |
| 484 | auto nrBytes = frameSize.width * frameSize.height * nrBytesPerSample; |
| 485 | auto layout = src.getSubsampling(); |
| 486 | if (layout == Subsampling::YUV_420) |
| 487 | nrBytes += (frameSize.width / 2) * (frameSize.height / 2) * 2 * nrBytesPerSample; |
| 488 | else if (layout == Subsampling::YUV_422) |
| 489 | nrBytes += (frameSize.width / 2) * frameSize.height * 2 * nrBytesPerSample; |
| 490 | else if (layout == Subsampling::YUV_444) |
| 491 | nrBytes += frameSize.width * frameSize.height * 2 * nrBytesPerSample; |
| 492 | |
| 493 | DEBUG_DAV1D("decoderDav1d::copyImgToByteArray nrBytes %d", nrBytes); |
| 494 | |
| 495 | // Is the output big enough? |
| 496 | if (dst.capacity() < int(nrBytes)) |
| 497 | dst.resize(int(nrBytes)); |
| 498 | |
| 499 | uint8_t *dst_c = (uint8_t *)dst.data(); |
| 500 | |
| 501 | // We can now copy from src to dst |
| 502 | for (int c = 0; c < nrPlanes; c++) |
| 503 | { |
| 504 | auto width = framSize.width; |
| 505 | auto height = framSize.height; |
| 506 | if (c != 0) |
| 507 | { |
| 508 | if (layout == Subsampling::YUV_420 || layout == Subsampling::YUV_422) |
| 509 | width /= 2; |
| 510 | if (layout == Subsampling::YUV_420) |
| 511 | height /= 2; |
| 512 | } |
| 513 | const size_t widthInBytes = width * nrBytesPerSample; |
| 514 | |
| 515 | uint8_t *img_c = nullptr; |
| 516 | if (decodeSignal == 0) |
| 517 | img_c = curPicture.getData(c); |
| 518 | else if (decodeSignal == 1) |
| 519 | img_c = curPicture.getDataPrediction(c); |
| 520 | else if (decodeSignal == 2) |
| 521 | img_c = curPicture.getDataReconstructionPreFiltering(c); |
| 522 | |
| 523 | if (img_c == nullptr) |
| 524 | return; |
| 525 | |
| 526 | const int stride = (c == 0) ? curPicture.getStride(0) : curPicture.getStride(1); |
| 527 | for (size_t y = 0; y < height; y++) |
| 528 | { |
| 529 | memcpy(dst_c, img_c, widthInBytes); |
| 530 | img_c += stride; |
| 531 | dst_c += widthInBytes; |
| 532 | } |
nothing calls this directly
no test coverage detected