Home | History | Annotate | Download | only in utils
      1 /*
      2  * Copyright (C) 2008 The Android Open Source Project
      3  *
      4  * Licensed under the Apache License, Version 2.0 (the "License");
      5  * you may not use this file except in compliance with the License.
      6  * You may obtain a copy of the License at
      7  *
      8  *      http://www.apache.org/licenses/LICENSE-2.0
      9  *
     10  * Unless required by applicable law or agreed to in writing, software
     11  * distributed under the License is distributed on an "AS IS" BASIS,
     12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     13  * See the License for the specific language governing permissions and
     14  * limitations under the License.
     15  */
     16 
     17 #ifndef SkUnitMappers_DEFINED
     18 #define SkUnitMappers_DEFINED
     19 
     20 #include "SkUnitMapper.h"
     21 
     22 /** This discretizes the range [0...1) into N discret values.
     23 */
     24 class SkDiscreteMapper : public SkUnitMapper {
     25 public:
     26     SkDiscreteMapper(int segments);
     27     // override from SkUnitMapper
     28     virtual uint16_t mapUnit16(uint16_t x);
     29 
     30 protected:
     31     SkDiscreteMapper(SkFlattenableReadBuffer& );
     32     // overrides from SkFlattenable
     33     virtual void flatten(SkFlattenableWriteBuffer& );
     34     virtual Factory getFactory();
     35 private:
     36     int     fSegments;
     37     SkFract fScale;    // computed from fSegments
     38 
     39     static SkFlattenable* Create(SkFlattenableReadBuffer& buffer);
     40 
     41     typedef SkUnitMapper INHERITED;
     42 };
     43 
     44 /** This returns cos(x), to simulate lighting a sphere, where 0 maps to the
     45     center of the sphere, and 1 maps to the edge.
     46 */
     47 class SkCosineMapper : public SkUnitMapper {
     48 public:
     49     SkCosineMapper() {}
     50     // override from SkUnitMapper
     51     virtual uint16_t mapUnit16(uint16_t x);
     52 
     53 protected:
     54     SkCosineMapper(SkFlattenableReadBuffer&);
     55     // overrides from SkFlattenable
     56     virtual Factory getFactory();
     57 
     58 private:
     59     static SkFlattenable* Create(SkFlattenableReadBuffer&);
     60 
     61     typedef SkUnitMapper INHERITED;
     62 };
     63 
     64 #endif
     65 
     66