MCPcopy Create free account
hub / github.com/RavEngine/RavEngine / ConvertImageBufferFormat

Function ConvertImageBufferFormat

deps/LLGL/sources/Core/ImageFlags.cpp:460–542  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

458}
459
460static void ConvertImageBufferFormat(
461 const SrcImageDescriptor& srcImageDesc,
462 const DstImageDescriptor& dstImageDesc,
463 std::size_t threadCount)
464{
465 /* Get image parameters */
466 auto dataTypeSize = DataTypeSize(srcImageDesc.dataType);
467 auto srcFormatSize = ImageFormatSize(srcImageDesc.format);
468 auto dstFormatSize = ImageFormatSize(dstImageDesc.format);
469
470 /* Validate destination buffer size */
471 auto imageSize = srcImageDesc.dataSize / srcFormatSize;
472 auto requiredDstBufferSize = imageSize * dstFormatSize;
473
474 if (dstImageDesc.dataSize != requiredDstBufferSize)
475 throw std::invalid_argument("cannot convert image format with destination buffer size mismatch");
476
477 /* Allocate destination buffer */
478 imageSize /= dataTypeSize;
479
480 /* Get variant buffer for source and destination images */
481 VariantConstBuffer src { srcImageDesc.data };
482 VariantBuffer dst { dstImageDesc.data };
483
484 threadCount = std::min(threadCount, imageSize / g_threadMinWorkSize);
485
486 if (threadCount > 1)
487 {
488 /* Create worker threads */
489 std::vector<std::thread> workers(threadCount);
490
491 auto workSize = imageSize / threadCount;
492 auto workSizeRemain = imageSize % threadCount;
493
494 std::size_t offset = 0;
495
496 for (std::size_t i = 0; i < threadCount; ++i)
497 {
498 workers[i] = std::thread(
499 ConvertImageBufferFormatWorker,
500 srcImageDesc.format,
501 srcImageDesc.dataType,
502 std::ref(src),
503 dstImageDesc.format,
504 std::ref(dst),
505 offset,
506 offset + workSize
507 );
508 offset += workSize;
509 }
510
511 /* Execute conversion of remaining work on main thread */
512 if (workSizeRemain > 0)
513 {
514 ConvertImageBufferFormatWorker(
515 srcImageDesc.format,
516 srcImageDesc.dataType,
517 src,

Callers 2

ConvertImageBufferFunction · 0.85

Calls 1

Tested by

no test coverage detected