comparison OrthancFramework/Sources/Images/ImageProcessing.cpp @ 4780:ebb801d44e06

optimization in ImageProcessing::ShiftScale()
author Sebastien Jodogne <s.jodogne@gmail.com>
date Mon, 30 Aug 2021 12:13:05 +0200
parents f9eda86f9045
children 7053502fbf97
comparison
equal deleted inserted replaced
4779:4f368230f32b 4780:ebb801d44e06
1403 throw OrthancException(ErrorCode_NotImplemented); 1403 throw OrthancException(ErrorCode_NotImplemented);
1404 } 1404 }
1405 } 1405 }
1406 1406
1407 1407
1408 static bool IsIdentityRescaling(float offset,
1409 float scaling)
1410 {
1411 return (std::abs(offset) <= 10.0f * std::numeric_limits<float>::epsilon() &&
1412 std::abs(scaling - 1.0f) <= 10.0f * std::numeric_limits<float>::epsilon());
1413 }
1414
1415
1408 void ImageProcessing::ShiftScale2(ImageAccessor& image, 1416 void ImageProcessing::ShiftScale2(ImageAccessor& image,
1409 float offset, 1417 float offset,
1410 float scaling, 1418 float scaling,
1411 bool useRound) 1419 bool useRound)
1412 { 1420 {
1413 // We compute "a * x + b" 1421 // We compute "a * x + b"
1414 const float a = scaling; 1422 const float a = scaling;
1415 const float b = offset; 1423 const float b = offset;
1424
1425 if (IsIdentityRescaling(offset, scaling))
1426 {
1427 return;
1428 }
1416 1429
1417 switch (image.GetFormat()) 1430 switch (image.GetFormat())
1418 { 1431 {
1419 case PixelFormat_Grayscale8: 1432 case PixelFormat_Grayscale8:
1420 if (useRound) 1433 if (useRound)
1474 bool useRound) 1487 bool useRound)
1475 { 1488 {
1476 // We compute "a * x + b" 1489 // We compute "a * x + b"
1477 const float a = scaling; 1490 const float a = scaling;
1478 const float b = offset; 1491 const float b = offset;
1492
1493 if (target.GetFormat() == source.GetFormat() &&
1494 IsIdentityRescaling(offset, scaling))
1495 {
1496 Copy(target, source);
1497 return;
1498 }
1479 1499
1480 switch (target.GetFormat()) 1500 switch (target.GetFormat())
1481 { 1501 {
1482 case PixelFormat_Grayscale8: 1502 case PixelFormat_Grayscale8:
1483 1503