blob: d8856aed419b007f7be38cfef3031942b163fa07 [file] [log] [blame]
epoger@google.comec3ed6a2011-07-28 14:26:00 +00001
reed@android.com8a1c16f2008-12-17 15:59:43 +00002/*
epoger@google.comec3ed6a2011-07-28 14:26:00 +00003 * Copyright 2008 The Android Open Source Project
reed@android.com8a1c16f2008-12-17 15:59:43 +00004 *
epoger@google.comec3ed6a2011-07-28 14:26:00 +00005 * Use of this source code is governed by a BSD-style license that can be
6 * found in the LICENSE file.
reed@android.com8a1c16f2008-12-17 15:59:43 +00007 */
8
epoger@google.comec3ed6a2011-07-28 14:26:00 +00009
reed@android.com8a1c16f2008-12-17 15:59:43 +000010#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*/
17class SkDiscreteMapper : public SkUnitMapper {
18public:
19 SkDiscreteMapper(int segments);
20 // override from SkUnitMapper
21 virtual uint16_t mapUnit16(uint16_t x);
22
djsollen@google.comba28d032012-03-26 17:57:35 +000023 SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkDiscreteMapper)
24
reed@android.com8a1c16f2008-12-17 15:59:43 +000025protected:
26 SkDiscreteMapper(SkFlattenableReadBuffer& );
27 // overrides from SkFlattenable
28 virtual void flatten(SkFlattenableWriteBuffer& );
djsollen@google.comba28d032012-03-26 17:57:35 +000029
reed@android.com8a1c16f2008-12-17 15:59:43 +000030private:
31 int fSegments;
32 SkFract fScale; // computed from fSegments
33
reed@android.com8a1c16f2008-12-17 15:59:43 +000034 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*/
40class SkCosineMapper : public SkUnitMapper {
41public:
42 SkCosineMapper() {}
43 // override from SkUnitMapper
44 virtual uint16_t mapUnit16(uint16_t x);
45
djsollen@google.comba28d032012-03-26 17:57:35 +000046 SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkCosineMapper)
47
reed@android.com8a1c16f2008-12-17 15:59:43 +000048protected:
49 SkCosineMapper(SkFlattenableReadBuffer&);
reed@android.com8a1c16f2008-12-17 15:59:43 +000050
51private:
reed@android.com8a1c16f2008-12-17 15:59:43 +000052
53 typedef SkUnitMapper INHERITED;
54};
55
56#endif
57