comparison OrthancFramework/Sources/Images/ImageProcessing.cpp @ 4083:26efd0404d97 framework

integration mainline->framework
author Sebastien Jodogne <s.jodogne@gmail.com>
date Tue, 23 Jun 2020 07:39:42 +0200
parents Core/Images/ImageProcessing.cpp@2e1564f57542 Core/Images/ImageProcessing.cpp@259c33759937
children bf7b9edf6b81
comparison
equal deleted inserted replaced
4081:259c33759937 4083:26efd0404d97
2523 { 2523 {
2524 std::unique_ptr<ImageAccessor> target(new Image(source.GetFormat(), width, height, false)); 2524 std::unique_ptr<ImageAccessor> target(new Image(source.GetFormat(), width, height, false));
2525 FitSize(*target, source); 2525 FitSize(*target, source);
2526 return target.release(); 2526 return target.release();
2527 } 2527 }
2528
2529
2530 ImageAccessor* ImageProcessing::FitSizeKeepAspectRatio(const ImageAccessor& source,
2531 unsigned int width,
2532 unsigned int height)
2533 {
2534 std::unique_ptr<ImageAccessor> target(new Image(source.GetFormat(), width, height, false));
2535 Set(*target, 0);
2536
2537 if (width != 0 &&
2538 height != 0 &&
2539 source.GetWidth() != 0 &&
2540 source.GetHeight() != 0)
2541 {
2542 float ratio = std::min(static_cast<float>(width) / static_cast<float>(source.GetWidth()),
2543 static_cast<float>(height) / static_cast<float>(source.GetHeight()));
2544
2545 unsigned int resizedWidth = static_cast<unsigned int>(
2546 boost::math::iround(ratio * static_cast<float>(source.GetWidth())));
2547
2548 unsigned int resizedHeight = static_cast<unsigned int>(
2549 boost::math::iround(ratio * static_cast<float>(source.GetHeight())));
2550
2551 std::unique_ptr<ImageAccessor> resized(FitSize(source, resizedWidth, resizedHeight));
2552
2553 ImageAccessor region;
2554 target->GetRegion(region, (width - resizedWidth) / 2,
2555 (height - resizedHeight) / 2, resizedWidth, resizedHeight);
2556 Copy(region, *resized);
2557 }
2558
2559 return target.release();
2560 }
2528 } 2561 }