MCPcopy Create free account
hub / github.com/Bzi-Han/AndroidSurfaceImgui / CalcMirrorLayerTransform

Function CalcMirrorLayerTransform

modules/ANativeWindowCreator.h:1387–1412  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1385 }
1386
1387 inline MirrorLayerTransform CalcMirrorLayerTransform(float targetWidth, float targetHeight, float sourceWidth, float sourceHeight, float epsilon = 0.002)
1388 {
1389 if (0.f == targetHeight || 0.f == sourceHeight)
1390 throw std::runtime_error("[-] Invalid height");
1391
1392 MirrorLayerTransform result{
1393 .isAspectRatioSimilar = std::abs(targetWidth / targetHeight - sourceWidth / sourceHeight) < epsilon,
1394 .widthScale = sourceWidth / targetWidth,
1395 .heightScale = sourceHeight / targetHeight,
1396 };
1397 if (result.isAspectRatioSimilar)
1398 return result;
1399
1400 if (result.widthScale > result.heightScale)
1401 {
1402 result.offsetX = (sourceWidth - targetWidth * result.heightScale) / 2;
1403 result.widthScale = result.heightScale;
1404 }
1405 else
1406 {
1407 result.offsetY = (sourceHeight - targetHeight * result.widthScale) / 2;
1408 result.heightScale = result.widthScale;
1409 }
1410
1411 return result;
1412 }
1413} // namespace android::anative_window_creator::detail
1414
1415namespace android

Callers 1

ProcessMirrorDisplayMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected