include/o3tl/float_int_conversion.hxx | 20 ++------ vcl/inc/graphic/AnimationContainer.hxx | 57 +++++++++++++++++++++++ vcl/inc/graphic/BitmapContainer.hxx | 56 +++++++++++++++++++++++ vcl/inc/impgraph.hxx | 79 --------------------------------- vcl/source/gdi/impgraph.cxx | 34 ++++++++++++-- 5 files changed, 151 insertions(+), 95 deletions(-)
New commits: commit 6686a02dbf43d1796b82a6f1135df2bbe31ece9c Author: Tomaž Vajngerl <tomaz.vajng...@collabora.co.uk> AuthorDate: Wed Apr 9 16:48:26 2025 +0900 Commit: Tomaž Vajngerl <qui...@gmail.com> CommitDate: Wed Apr 9 14:56:52 2025 +0200 vcl: move {Bitmap,Animation}Container to own files, createSwapInfo Move BitmapContainer and AnimationContainer into own files. Implement createSwapInfo for AnimationContiner and add needed functions for that. Change-Id: I723f4606a9a0cfa6627a5244de7f08c4d89387db Reviewed-on: https://gerrit.libreoffice.org/c/core/+/183866 Reviewed-by: Tomaž Vajngerl <qui...@gmail.com> Tested-by: Jenkins diff --git a/vcl/inc/graphic/AnimationContainer.hxx b/vcl/inc/graphic/AnimationContainer.hxx new file mode 100644 index 000000000000..25cfa26bd766 --- /dev/null +++ b/vcl/inc/graphic/AnimationContainer.hxx @@ -0,0 +1,57 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ + +#pragma once + +#include <vcl/dllapi.h> +#include <vcl/animate/Animation.hxx> + +class SAL_DLLPUBLIC_RTTI AnimationContainer final +{ +public: + Animation maAnimation; + + AnimationContainer() = default; + + AnimationContainer(Animation const& rAnimation) + : maAnimation(rAnimation) + { + } + + bool operator==(const AnimationContainer& rOther) const + { + return maAnimation == rOther.maAnimation; + } + + void createSwapInfo(ImpSwapInfo& rSwapInfo); + + bool isTransparent() const { return maAnimation.IsTransparent(); } + + sal_uInt64 getSizeBytes() { return maAnimation.GetSizeBytes(); } + + Size getPrefSize() const + { + Size aSize = maAnimation.GetBitmapEx().GetPrefSize(); + if (!aSize.Width() || !aSize.Height()) + aSize = maAnimation.GetBitmapEx().GetSizePixel(); + return aSize; + } + + MapMode getPrefMapMode() const + { + const Size aSize = maAnimation.GetBitmapEx().GetPrefSize(); + if (aSize.Width() && aSize.Height()) + return maAnimation.GetBitmapEx().GetPrefMapMode(); + return {}; + } + + sal_uInt32 getLoopCount() { return maAnimation.GetLoopCount(); } +}; + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/vcl/inc/graphic/BitmapContainer.hxx b/vcl/inc/graphic/BitmapContainer.hxx new file mode 100644 index 000000000000..010ac45c74bc --- /dev/null +++ b/vcl/inc/graphic/BitmapContainer.hxx @@ -0,0 +1,56 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ + +#pragma once + +#include <vcl/dllapi.h> +#include <vcl/bitmapex.hxx> + +struct ImpSwapInfo; + +class SAL_DLLPUBLIC_RTTI BitmapContainer final +{ +public: + BitmapEx maBitmapEx; + + BitmapContainer() = default; + + BitmapContainer(BitmapEx const& rBitmapEx) + : maBitmapEx(rBitmapEx) + { + } + + bool operator==(const BitmapContainer& rOther) const { return maBitmapEx == rOther.maBitmapEx; } + + void createSwapInfo(ImpSwapInfo& rSwapInfo); + + bool isAlpha() { return maBitmapEx.IsAlpha(); } + + const BitmapEx& getBitmapExRef() const { return maBitmapEx; } + + Size getPrefSize() const + { + Size aSize = maBitmapEx.GetPrefSize(); + if (!aSize.Width() || !aSize.Height()) + aSize = maBitmapEx.GetSizePixel(); + return aSize; + } + + MapMode getPrefMapMode() const + { + const Size aSize = maBitmapEx.GetPrefSize(); + if (aSize.Width() && aSize.Height()) + return maBitmapEx.GetPrefMapMode(); + return {}; + } + + sal_uInt64 getSizeBytes() { return maBitmapEx.GetSizeBytes(); } +}; + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/vcl/inc/impgraph.hxx b/vcl/inc/impgraph.hxx index 75a5e00f8a4f..52cfd768f511 100644 --- a/vcl/inc/impgraph.hxx +++ b/vcl/inc/impgraph.hxx @@ -26,6 +26,8 @@ #include "graphic/Manager.hxx" #include "graphic/MemoryManaged.hxx" #include "graphic/GraphicID.hxx" +#include "graphic/BitmapContainer.hxx" +#include "graphic/AnimationContainer.hxx" #include <optional> struct ImpSwapInfo @@ -57,83 +59,6 @@ enum class GraphicContentType : sal_Int32 Vector }; -class SAL_DLLPUBLIC_RTTI BitmapContainer final -{ -public: - BitmapEx maBitmapEx; - - BitmapContainer() = default; - - BitmapContainer(BitmapEx const& rBitmapEx) - : maBitmapEx(rBitmapEx) - {} - - bool operator==(const BitmapContainer& rOther) const - { - return maBitmapEx == rOther.maBitmapEx; - } - - void createSwapInfo(ImpSwapInfo& rSwapInfo); - - bool isAlpha() - { - return maBitmapEx.IsAlpha(); - } - - const BitmapEx& getBitmapExRef() const - { - return maBitmapEx; - } - - Size getPrefSize() const - { - Size aSize = maBitmapEx.GetPrefSize(); - if (!aSize.Width() || !aSize.Height()) - aSize = maBitmapEx.GetSizePixel(); - return aSize; - } - - MapMode getPrefMapMode() const - { - const Size aSize = maBitmapEx.GetPrefSize(); - if (aSize.Width() && aSize.Height()) - return maBitmapEx.GetPrefMapMode(); - return {}; - } - - sal_uInt64 getSizeBytes() - { - return maBitmapEx.GetSizeBytes(); - } -}; - -class SAL_DLLPUBLIC_RTTI AnimationContainer final -{ -public: - Animation maAnimation; - - AnimationContainer() = default; - - AnimationContainer(Animation const& rAnimation) - : maAnimation(rAnimation) - {} - - bool operator==(const AnimationContainer& rOther) const - { - return maAnimation == rOther.maAnimation; - } - - bool isTransparent() const - { - return maAnimation.IsTransparent(); - } - - sal_uInt64 getSizeBytes() - { - return maAnimation.GetSizeBytes(); - } -}; - class SAL_DLLPUBLIC_RTTI ImpGraphic final : public vcl::graphic::MemoryManaged { friend class Graphic; diff --git a/vcl/source/gdi/impgraph.cxx b/vcl/source/gdi/impgraph.cxx index c48c29b7d802..a7241eae8bc5 100644 --- a/vcl/source/gdi/impgraph.cxx +++ b/vcl/source/gdi/impgraph.cxx @@ -340,6 +340,20 @@ void BitmapContainer::createSwapInfo(ImpSwapInfo& rSwapInfo) rSwapInfo.mnPageIndex = -1; } +void AnimationContainer::createSwapInfo(ImpSwapInfo& rSwapInfo) +{ + rSwapInfo.maSizePixel = maAnimation.GetBitmapEx().GetSizePixel(); + + rSwapInfo.maPrefMapMode = getPrefMapMode(); + rSwapInfo.maPrefSize = getPrefSize(); + rSwapInfo.mbIsAnimated = true; + rSwapInfo.mbIsEPS = false; + rSwapInfo.mbIsTransparent = isTransparent(); + rSwapInfo.mbIsAlpha = false; + rSwapInfo.mnAnimationLoopCount = getLoopCount(); + rSwapInfo.mnPageIndex = -1; +} + void ImpGraphic::createSwapInfo() { if (isSwappedOut()) @@ -347,9 +361,13 @@ void ImpGraphic::createSwapInfo() if (mpBitmapContainer) { - mpBitmapContainer->createSwapInfo(maSwapInfo); - return; + return mpBitmapContainer->createSwapInfo(maSwapInfo); + } + else if (mpAnimationContainer) + { + return mpAnimationContainer->createSwapInfo(maSwapInfo); } + else if (!maCachedBitmap.IsEmpty()) maSwapInfo.maSizePixel = maCachedBitmap.GetSizePixel(); else @@ -804,7 +822,7 @@ Size ImpGraphic::getPrefSize() const aSize = maExPrefSize; } } - else if (mpAnimationContainer || maVectorGraphicData) + else if (maVectorGraphicData) { aSize = maCachedBitmap.GetPrefSize(); @@ -815,6 +833,10 @@ Size ImpGraphic::getPrefSize() const { aSize = mpBitmapContainer->getPrefSize(); } + else if (mpAnimationContainer) + { + aSize = mpAnimationContainer->getPrefSize(); + } } break; @@ -902,6 +924,10 @@ MapMode ImpGraphic::getPrefMapMode() const { aMapMode = mpBitmapContainer->getPrefMapMode(); } + else if (mpAnimationContainer) + { + aMapMode = mpAnimationContainer->getPrefMapMode(); + } else { const Size aSize = maCachedBitmap.GetPrefSize(); @@ -1106,7 +1132,7 @@ sal_uInt32 ImpGraphic::getAnimationLoopCount() const if (mbSwapOut) return maSwapInfo.mnAnimationLoopCount; - return mpAnimationContainer ? mpAnimationContainer->maAnimation.GetLoopCount() : 0; + return mpAnimationContainer ? mpAnimationContainer->getLoopCount() : 0; } bool ImpGraphic::swapInContent(SvStream& rStream) commit b5ac0a063101a5558d8421e26afd487b072e7a00 Author: Tomaž Vajngerl <tomaz.vajng...@collabora.co.uk> AuthorDate: Mon Mar 10 15:38:13 2025 +0900 Commit: Tomaž Vajngerl <qui...@gmail.com> CommitDate: Wed Apr 9 14:56:37 2025 +0200 o3tl: simplify by using concepts in float_int_conversion.hxx Change-Id: If4373d11c469d476f74087461499b7a425309bfe Reviewed-on: https://gerrit.libreoffice.org/c/core/+/182713 Reviewed-by: Tomaž Vajngerl <qui...@gmail.com> Tested-by: Jenkins diff --git a/include/o3tl/float_int_conversion.hxx b/include/o3tl/float_int_conversion.hxx index 403bed6221c3..76b8edabba0a 100644 --- a/include/o3tl/float_int_conversion.hxx +++ b/include/o3tl/float_int_conversion.hxx @@ -7,22 +7,20 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ -#ifndef INCLUDED_O3TL_FLOAT_INT_CONVERSION_HXX -#define INCLUDED_O3TL_FLOAT_INT_CONVERSION_HXX +#pragma once #include <sal/config.h> #include <cmath> #include <limits> #include <type_traits> +#include <o3tl/concepts.hxx> namespace o3tl { // Return true iff `value` of floating-point type `F` converts to a value of integral type `I` no // smaller than `min`: -template <typename F, typename I> -constexpr std::enable_if_t<std::is_floating_point_v<F> && std::is_integral_v<I>, bool> -convertsToAtLeast(F value, I min) +template <floating_point F, integral I> constexpr bool convertsToAtLeast(F value, I min) { // If `F(min)`, `F(min) - F(1)` are too large in magnitude for `F`'s precision, then they either // fall into the same bucket, in which case we should return false if `value` represents that @@ -33,9 +31,7 @@ convertsToAtLeast(F value, I min) // Return true iff `value` of floating-point type `F` converts to a value of integral type `I` no // larger than `max`: -template <typename F, typename I> -constexpr std::enable_if_t<std::is_floating_point_v<F> && std::is_integral_v<I>, bool> -convertsToAtMost(F value, I max) +template <floating_point F, integral I> constexpr bool convertsToAtMost(F value, I max) { // If `F(max)`, `F(max) + F(1)` are too large in magnitude for `F`'s precision, then they either // fall into the same bucket, in which case we should return false if `value` represents that @@ -46,9 +42,7 @@ convertsToAtMost(F value, I max) // Casts a floating-point to an integer, avoiding overflow. Used like: // sal_Int64 n = o3tl::saturating_cast<sal_Int64>(f); -template <typename I, typename F> -constexpr std::enable_if_t<std::is_floating_point_v<F> && std::is_integral_v<I>, I> -saturating_cast(F f) +template <integral I, floating_point F> constexpr I saturating_cast(F f) { if constexpr (std::is_signed_v<I>) if (!convertsToAtLeast(f, std::numeric_limits<I>::min())) @@ -61,12 +55,10 @@ saturating_cast(F f) // Return `value` of floating-point type `F` rounded to the nearest integer away from zero (which // can be useful in calls to convertsToAtLeast/Most(roundAway(x), n), to reject x that are // smaller/larger than n because they have a fractional part): -template <typename F> std::enable_if_t<std::is_floating_point_v<F>, F> roundAway(F value) +template <floating_point F> F roundAway(F value) { return value >= 0 ? std::ceil(value) : std::floor(value); } } -#endif - /* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */