• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 
2 /*
3  * Copyright 2008 The Android Open Source Project
4  *
5  * Use of this source code is governed by a BSD-style license that can be
6  * found in the LICENSE file.
7  */
8 
9 
10 #ifndef SkUnitMappers_DEFINED
11 #define SkUnitMappers_DEFINED
12 
13 #include "SkUnitMapper.h"
14 
15 /** This discretizes the range [0...1) into N discret values.
16 */
17 class SkDiscreteMapper : public SkUnitMapper {
18 public:
19     SkDiscreteMapper(int segments);
20     // override from SkUnitMapper
21     virtual uint16_t mapUnit16(uint16_t x);
22 
23 protected:
24     SkDiscreteMapper(SkFlattenableReadBuffer& );
25     // overrides from SkFlattenable
26     virtual void flatten(SkFlattenableWriteBuffer& );
27     virtual Factory getFactory();
28 private:
29     int     fSegments;
30     SkFract fScale;    // computed from fSegments
31 
32     static SkFlattenable* Create(SkFlattenableReadBuffer& buffer);
33 
34     typedef SkUnitMapper INHERITED;
35 };
36 
37 /** This returns cos(x), to simulate lighting a sphere, where 0 maps to the
38     center of the sphere, and 1 maps to the edge.
39 */
40 class SkCosineMapper : public SkUnitMapper {
41 public:
SkCosineMapper()42     SkCosineMapper() {}
43     // override from SkUnitMapper
44     virtual uint16_t mapUnit16(uint16_t x);
45 
46 protected:
47     SkCosineMapper(SkFlattenableReadBuffer&);
48     // overrides from SkFlattenable
49     virtual Factory getFactory();
50 
51 private:
52     static SkFlattenable* Create(SkFlattenableReadBuffer&);
53 
54     typedef SkUnitMapper INHERITED;
55 };
56 
57 #endif
58 
59