| 376 | void decoderHM::copyImgToByteArray(libHMDec_picture *src, byteArrayAligned &dst) |
| 377 | #else |
| 378 | void decoderHM::copyImgToByteArray(libHMDec_picture *src, QByteArray &dst) |
| 379 | #endif |
| 380 | { |
| 381 | // How many image planes are there? |
| 382 | auto fmt = this->lib.libHMDEC_get_chroma_format(src); |
| 383 | int nrPlanes = (fmt == LIBHMDEC_CHROMA_400) ? 1 : 3; |
| 384 | |
| 385 | // Is the output going to be 8 or 16 bit? |
| 386 | bool outputTwoByte = false; |
| 387 | for (int c = 0; c < nrPlanes; c++) |
| 388 | { |
| 389 | auto component = (c == 0) ? LIBHMDEC_LUMA : (c == 1) ? LIBHMDEC_CHROMA_U : LIBHMDEC_CHROMA_V; |
| 390 | if (this->lib.libHMDEC_get_internal_bit_depth(src, component) > 8) |
| 391 | outputTwoByte = true; |
| 392 | } |
| 393 | |
| 394 | // How many samples are in each component? |
| 395 | int outSizeY = this->lib.libHMDEC_get_picture_width(src, LIBHMDEC_LUMA) * |
| 396 | this->lib.libHMDEC_get_picture_height(src, LIBHMDEC_LUMA); |
| 397 | int outSizeCb = (nrPlanes == 1) ? 0 |
| 398 | : (this->lib.libHMDEC_get_picture_width(src, LIBHMDEC_CHROMA_U) * |
| 399 | this->lib.libHMDEC_get_picture_height(src, LIBHMDEC_CHROMA_U)); |
| 400 | int outSizeCr = (nrPlanes == 1) ? 0 |
| 401 | : (this->lib.libHMDEC_get_picture_width(src, LIBHMDEC_CHROMA_V) * |
| 402 | this->lib.libHMDEC_get_picture_height(src, LIBHMDEC_CHROMA_V)); |
| 403 | // How many bytes do we need in the output buffer? |
| 404 | int nrBytesOutput = (outSizeY + outSizeCb + outSizeCr) * (outputTwoByte ? 2 : 1); |
| 405 | DEBUG_DECHM("decoderHM::copyImgToByteArray nrBytesOutput %d", nrBytesOutput); |
| 406 | |
| 407 | // Is the output big enough? |
| 408 | if (dst.capacity() < nrBytesOutput) |
| 409 | dst.resize(nrBytesOutput); |
| 410 | |
| 411 | // The source (from HM) is always short (16bit). The destination is a QByteArray so |
| 412 | // we have to cast it right. |
| 413 | for (int c = 0; c < nrPlanes; c++) |
| 414 | { |
| 415 | auto component = (c == 0) ? LIBHMDEC_LUMA : (c == 1) ? LIBHMDEC_CHROMA_U : LIBHMDEC_CHROMA_V; |
| 416 | |
| 417 | const short *img_c = this->lib.libHMDEC_get_image_plane(src, component); |
| 418 | int stride = this->lib.libHMDEC_get_picture_stride(src, component); |
| 419 | |
| 420 | if (img_c == nullptr) |
| 421 | return; |
| 422 | |
| 423 | auto width = this->lib.libHMDEC_get_picture_width(src, component); |
| 424 | auto height = this->lib.libHMDEC_get_picture_height(src, component); |
| 425 | |
| 426 | if (outputTwoByte) |
| 427 | { |
| 428 | unsigned short *restrict d = (unsigned short *)dst.data(); |
| 429 | if (c > 0) |
| 430 | d += outSizeY; |
| 431 | if (c == 2) |
| 432 | d += outSizeCb; |
| 433 | |
| 434 | for (int y = 0; y < height; y++) |
| 435 | { |