@@ -55,7 +55,6 @@ void BitmapTransform(FIBITMAP* dst, FIBITMAP* src, UnaryOperation_ unary_op)
5555 }
5656}
5757
58-
5958template <typename Ty_>
6059using IsIntPixelType = std::integral_constant<bool ,
6160 std::is_same_v<Ty_, FIRGB8 > ||
@@ -102,46 +101,6 @@ namespace details
102101template <typename PixelType_>
103102using ToValueType = typename details::ToValueTypeImpl<PixelType_>::type;
104103
105-
106- namespace details
107- {
108- template <typename Ty_>
109- struct ToWiderTypeImpl {};
110-
111- template <> struct ToWiderTypeImpl <uint64_t > { using type = uint64_t ; };
112- template <> struct ToWiderTypeImpl <int64_t > { using type = int64_t ; };
113- template <> struct ToWiderTypeImpl <uint32_t > { using type = uint64_t ; };
114- template <> struct ToWiderTypeImpl <int32_t > { using type = int64_t ; };
115- template <> struct ToWiderTypeImpl <uint16_t > { using type = uint32_t ; };
116- template <> struct ToWiderTypeImpl <int16_t > { using type = int32_t ; };
117- template <> struct ToWiderTypeImpl <uint8_t > { using type = uint32_t ; };
118- template <> struct ToWiderTypeImpl <int8_t > { using type = int32_t ; };
119- }
120-
121- template <typename Ty_>
122- using ToWiderType = typename details::ToWiderTypeImpl<Ty_>::type;
123-
124-
125- namespace details
126- {
127- template <typename Ty_>
128- struct ToUnsignedTypeImpl {};
129-
130- template <> struct ToUnsignedTypeImpl <uint64_t > { using type = uint64_t ; };
131- template <> struct ToUnsignedTypeImpl <int64_t > { using type = uint64_t ; };
132- template <> struct ToUnsignedTypeImpl <uint32_t > { using type = uint32_t ; };
133- template <> struct ToUnsignedTypeImpl <int32_t > { using type = uint32_t ; };
134- template <> struct ToUnsignedTypeImpl <uint16_t > { using type = uint16_t ; };
135- template <> struct ToUnsignedTypeImpl <int16_t > { using type = uint16_t ; };
136- template <> struct ToUnsignedTypeImpl <uint8_t > { using type = uint8_t ; };
137- template <> struct ToUnsignedTypeImpl <int8_t > { using type = uint8_t ; };
138- }
139-
140- template <typename Ty_>
141- using ToUnsignedType = typename details::ToUnsignedTypeImpl<Ty_>::type;
142-
143-
144-
145104template <uint32_t Value_>
146105using uint32_constant = std::integral_constant<uint32_t , Value_>;
147106
@@ -159,26 +118,6 @@ template <> struct PixelChannelsNumber<FIRGB8> : public uint32_constant<3> {};
159118template <> struct PixelChannelsNumber <FICOMPLEX > : public uint32_constant<2 > {};
160119template <> struct PixelChannelsNumber <FICOMPLEXF > : public uint32_constant<2 > {};
161120
162- namespace details
163- {
164- template <typename PixelType_>
165- struct ToNoAlphaTypeImpl
166- {
167- using type = PixelType_;
168- };
169-
170- template <> struct ToNoAlphaTypeImpl <FIRGBAF > { using type = FIRGBF ; };
171- template <> struct ToNoAlphaTypeImpl <FIRGBA32 > { using type = FIRGB32 ; };
172- template <> struct ToNoAlphaTypeImpl <FIRGBA16 > { using type = FIRGB16 ; };
173- template <> struct ToNoAlphaTypeImpl <FIRGBA8 > { using type = FIRGB8 ; };
174-
175- }
176-
177- template <typename PixelType_>
178- using ToNoAlphaType = typename details::ToNoAlphaTypeImpl<PixelType_>::type;
179-
180-
181-
182121template <uint32_t ChannelIndex_, typename PixelType_>
183122inline constexpr
184123void SetChannel (PixelType_& p, ToValueType<PixelType_> v)
@@ -200,61 +139,6 @@ ToValueType<PixelType_> GetChannel(const PixelType_& p, ToValueType<PixelType_>
200139 }
201140}
202141
203- template <typename PixelType_>
204- inline constexpr
205- void PixelFill (PixelType_& p, const ToValueType<PixelType_>& v)
206- {
207- SetChannel<0 >(p, v);
208- SetChannel<1 >(p, v);
209- SetChannel<2 >(p, v);
210- SetChannel<3 >(p, v);
211- }
212-
213- template <typename PixelType_, typename BinaryOperation_>
214- inline constexpr
215- auto PixelReduce (const PixelType_& p, ToValueType<PixelType_> init, BinaryOperation_&& op)
216- {
217- constexpr uint32_t channelsNumber = PixelChannelsNumber<PixelType_>::value;
218- if constexpr (channelsNumber > 0 ) {
219- init = op (std::move (init), GetChannel<0 >(p));
220- }
221- if constexpr (channelsNumber > 1 ) {
222- init = op (std::move (init), GetChannel<1 >(p));
223- }
224- if constexpr (channelsNumber > 2 ) {
225- init = op (std::move (init), GetChannel<2 >(p));
226- }
227- if constexpr (channelsNumber > 3 ) {
228- init = op (std::move (init), GetChannel<3 >(p));
229- }
230- return init;
231- }
232-
233- template <typename PixelType_>
234- inline constexpr
235- auto PixelMin (const PixelType_& p, ToValueType<PixelType_> init = std::numeric_limits<ToValueType<PixelType_>>::max())
236- {
237- return PixelReduce (p, init, [](const auto & lhs, const auto & rhs) { return std::min (lhs, rhs); });
238- }
239-
240- template <typename PixelType_>
241- inline constexpr
242- auto PixelMax (const PixelType_& p, ToValueType<PixelType_> init = std::numeric_limits<ToValueType<PixelType_>>::lowest())
243- {
244- return PixelReduce (p, init, [](const auto & lhs, const auto & rhs) { return std::max (lhs, rhs); });
245- }
246-
247- template <typename PixelType_>
248- inline constexpr
249- auto StripAlpha (PixelType_&& p)
250- {
251- return ToNoAlphaType<PixelType_>(std::forward<PixelType_>(p));
252- }
253-
254-
255-
256-
257-
258142inline
259143bool IsNan (float p) {
260144 return std::isnan (p);
@@ -283,8 +167,6 @@ std::enable_if_t<std::is_integral_v<Ty_> || IsIntPixelType<Ty_>::value, bool> Is
283167 return false ;
284168}
285169
286-
287-
288170struct Brightness
289171{
290172 template <typename Ty_>
@@ -302,54 +184,4 @@ struct Brightness
302184 }
303185};
304186
305- struct YuvBrightness
306- {
307- template <typename Ty_>
308- inline
309- auto operator ()(const Ty_& p, std::enable_if_t <IsPixelType<Ty_>::value, void *> = nullptr )
310- {
311- return p.red ;
312- }
313- };
314-
315-
316- template <typename PixelTy_, typename BrightnessOp_ = Brightness>
317- std::tuple<PixelTy_*, PixelTy_*, double , double > FindMinMax (FIBITMAP * src, BrightnessOp_ brightnessOp = BrightnessOp_{})
318- {
319- PixelTy_* minIt{}, * maxIt{};
320- double minVal = 0.0 , maxVal = 0.0 ;
321- if (src) {
322- const unsigned h = FreeImage_GetHeight (src);
323- const unsigned w = FreeImage_GetWidth (src);
324- const unsigned pitch = FreeImage_GetPitch (src);
325- auto srcLine = static_cast <uint8_t *>(static_cast <void *>(FreeImage_GetBits (src)));
326- for (unsigned j = 0 ; j < h; ++j, srcLine += pitch) {
327- auto pixIt = static_cast <PixelTy_*>(static_cast <void *>(srcLine));
328- for (unsigned i = 0 ; i < w; ++i, ++pixIt) {
329- if (IsNan (*pixIt)) {
330- continue ;
331- }
332- const auto b = static_cast <double >(brightnessOp (*pixIt));
333- if (!minIt || !maxIt) {
334- minIt = maxIt = pixIt;
335- minVal = maxVal = b;
336- }
337- else {
338- if (b < minVal) {
339- minIt = pixIt;
340- minVal = b;
341- }
342- if (maxVal < b) {
343- maxIt = pixIt;
344- maxVal = b;
345- }
346- }
347- }
348- }
349- }
350- return std::make_tuple (minIt, maxIt, minVal, maxVal);
351- }
352-
353-
354-
355187#endif // FREEIMAGE_SIMPLE_TOOLS_H_
0 commit comments