blob: 64aab5ddee7728dcf040d298b158798f07ceb779 [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& );
djsollen@google.com54924242012-03-29 15:18:04 +000027 virtual void flatten(SkFlattenableWriteBuffer&) const SK_OVERRIDE;
djsollen@google.comba28d032012-03-26 17:57:35 +000028
reed@android.com8a1c16f2008-12-17 15:59:43 +000029private:
30 int fSegments;
31 SkFract fScale; // computed from fSegments
32
reed@android.com8a1c16f2008-12-17 15:59:43 +000033 typedef SkUnitMapper INHERITED;
34};
35
36/** This returns cos(x), to simulate lighting a sphere, where 0 maps to the
37 center of the sphere, and 1 maps to the edge.
38*/
39class SkCosineMapper : public SkUnitMapper {
40public:
41 SkCosineMapper() {}
42 // override from SkUnitMapper
43 virtual uint16_t mapUnit16(uint16_t x);
44
djsollen@google.comba28d032012-03-26 17:57:35 +000045 SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkCosineMapper)
46
reed@android.com8a1c16f2008-12-17 15:59:43 +000047protected:
48 SkCosineMapper(SkFlattenableReadBuffer&);
reed@android.com8a1c16f2008-12-17 15:59:43 +000049
50private:
reed@android.com8a1c16f2008-12-17 15:59:43 +000051
52 typedef SkUnitMapper INHERITED;
53};
54
55#endif