1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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>
39 template< typename PixelType
,
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
,
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
)) *
62 vigra::NumericTraits
<PixelType
>::maxConst
;
66 //-----------------------------------------------------------------------------
68 template< class Iterator
,
70 int UsedRange
> struct PixelFormatTraitsTemplate_Greylevel
72 typedef typename
Iterator::value_type pixel_type
;
74 typedef GreylevelGetter
<pixel_type
,
76 UsedRange
> getter_type
;
77 typedef GreylevelSetter
<pixel_type
,
79 UsedRange
> setter_type
;
81 typedef Iterator iterator_type
;
82 typedef Accessor raw_accessor_type
;
83 typedef AccessorSelector
<
85 setter_type
> accessor_selector
;
88 template< int BitsPerPixel
,
89 bool MsbFirst
> struct PixelFormatTraitsTemplate_PackedGreylevel
:
90 public PixelFormatTraitsTemplate_Greylevel
<
91 PackedPixelIterator
< sal_uInt8
,
94 NonStandardAccessor
< sal_uInt8
>,
95 (1UL << BitsPerPixel
)-1 >
98 //-----------------------------------------------------------------------------
101 typedef PixelFormatTraitsTemplate_PackedGreylevel
<1, true> PixelFormatTraits_GREY1_MSB
;
104 typedef PixelFormatTraitsTemplate_PackedGreylevel
<1, false> PixelFormatTraits_GREY1_LSB
;
105 BASEBMP_SPECIALIZE_ACCESSORTRAITS(PixelFormatTraits_GREY1_MSB::getter_type
,
106 PixelFormatTraits_GREY1_MSB::setter_type
);
110 typedef PixelFormatTraitsTemplate_PackedGreylevel
<4, true> PixelFormatTraits_GREY4_MSB
;
113 typedef PixelFormatTraitsTemplate_PackedGreylevel
<4, false> PixelFormatTraits_GREY4_LSB
;
114 BASEBMP_SPECIALIZE_ACCESSORTRAITS(PixelFormatTraits_GREY4_MSB::getter_type
,
115 PixelFormatTraits_GREY4_MSB::setter_type
);
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: */