bump product version to 4.1.6.2
[LibreOffice.git] / include / basebmp / greylevelformats.hxx
blob3fcd90fcda5f062b52f69f4c4e257deb24eee6dc
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #ifndef INCLUDED_BASEBMP_GREYLEVELFORMATS_HXX
21 #define INCLUDED_BASEBMP_GREYLEVELFORMATS_HXX
23 #include <basebmp/color.hxx>
24 #include <basebmp/colortraits.hxx>
25 #include <basebmp/accessor.hxx>
26 #include <basebmp/pixeliterator.hxx>
27 #include <basebmp/packedpixeliterator.hxx>
28 #include <basebmp/pixelformatadapters.hxx>
29 #include <basebmp/metafunctions.hxx>
31 #include <vigra/numerictraits.hxx>
32 #include <vigra/metaprogramming.hxx>
34 #include <functional>
36 namespace basebmp
39 template< typename PixelType,
40 typename ColorType,
41 int UsedRange > struct GreylevelGetter :
42 public std::unary_function<PixelType, ColorType>
44 ColorType operator()( PixelType const& c ) const
46 return ColorTraits<ColorType>::fromGreyscale(
47 vigra::NumericTraits<PixelType>::toPromote(c) *
48 vigra::NumericTraits<PixelType>::maxConst / UsedRange );
52 template< typename PixelType,
53 typename ColorType,
54 int UsedRange > struct GreylevelSetter :
55 public std::unary_function<ColorType, PixelType>
57 PixelType operator()( ColorType const& c ) const
59 return vigra::NumericTraits<PixelType>::toPromote(
60 ColorTraits<ColorType>::toGreyscale(c)) *
61 UsedRange /
62 vigra::NumericTraits<PixelType>::maxConst;
66 //-----------------------------------------------------------------------------
68 template< class Iterator,
69 class Accessor,
70 int UsedRange > struct PixelFormatTraitsTemplate_Greylevel
72 typedef typename Iterator::value_type pixel_type;
74 typedef GreylevelGetter<pixel_type,
75 Color,
76 UsedRange> getter_type;
77 typedef GreylevelSetter<pixel_type,
78 Color,
79 UsedRange> setter_type;
81 typedef Iterator iterator_type;
82 typedef Accessor raw_accessor_type;
83 typedef AccessorSelector<
84 getter_type,
85 setter_type > accessor_selector;
88 template< int BitsPerPixel,
89 bool MsbFirst > struct PixelFormatTraitsTemplate_PackedGreylevel :
90 public PixelFormatTraitsTemplate_Greylevel<
91 PackedPixelIterator< sal_uInt8,
92 BitsPerPixel,
93 true >,
94 NonStandardAccessor< sal_uInt8 >,
95 (1UL << BitsPerPixel)-1 >
96 {};
98 //-----------------------------------------------------------------------------
100 // 1bpp MSB
101 typedef PixelFormatTraitsTemplate_PackedGreylevel<1, true> PixelFormatTraits_GREY1_MSB;
103 // 1bpp LSB
104 typedef PixelFormatTraitsTemplate_PackedGreylevel<1, false> PixelFormatTraits_GREY1_LSB;
105 BASEBMP_SPECIALIZE_ACCESSORTRAITS(PixelFormatTraits_GREY1_MSB::getter_type,
106 PixelFormatTraits_GREY1_MSB::setter_type);
109 // 4bpp MSB
110 typedef PixelFormatTraitsTemplate_PackedGreylevel<4, true> PixelFormatTraits_GREY4_MSB;
112 // 4bpp LSB
113 typedef PixelFormatTraitsTemplate_PackedGreylevel<4, false> PixelFormatTraits_GREY4_LSB;
114 BASEBMP_SPECIALIZE_ACCESSORTRAITS(PixelFormatTraits_GREY4_MSB::getter_type,
115 PixelFormatTraits_GREY4_MSB::setter_type);
117 // 8bpp
118 typedef PixelFormatTraitsTemplate_Greylevel<
119 PixelIterator< sal_uInt8 >,
120 StandardAccessor< sal_uInt8 >,
121 255 > PixelFormatTraits_GREY8;
122 BASEBMP_SPECIALIZE_ACCESSORTRAITS(PixelFormatTraits_GREY8::getter_type,
123 PixelFormatTraits_GREY8::setter_type);
125 } // namespace basebmp
127 #endif /* INCLUDED_BASEBMP_GREYLEVELFORMATS_HXX */
129 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */