135e2e62b55598210f6999fc2ea26ff8f41446ffeDerek Sollenberger/*
235e2e62b55598210f6999fc2ea26ff8f41446ffeDerek Sollenberger    Copyright 2011 Google Inc.
335e2e62b55598210f6999fc2ea26ff8f41446ffeDerek Sollenberger
435e2e62b55598210f6999fc2ea26ff8f41446ffeDerek Sollenberger    Licensed under the Apache License, Version 2.0 (the "License");
535e2e62b55598210f6999fc2ea26ff8f41446ffeDerek Sollenberger    you may not use this file except in compliance with the License.
635e2e62b55598210f6999fc2ea26ff8f41446ffeDerek Sollenberger    You may obtain a copy of the License at
735e2e62b55598210f6999fc2ea26ff8f41446ffeDerek Sollenberger
835e2e62b55598210f6999fc2ea26ff8f41446ffeDerek Sollenberger    http://www.apache.org/licenses/LICENSE-2.0
935e2e62b55598210f6999fc2ea26ff8f41446ffeDerek Sollenberger
1035e2e62b55598210f6999fc2ea26ff8f41446ffeDerek Sollenberger    Unless required by applicable law or agreed to in writing, software
1135e2e62b55598210f6999fc2ea26ff8f41446ffeDerek Sollenberger    distributed under the License is distributed on an "AS IS" BASIS,
1235e2e62b55598210f6999fc2ea26ff8f41446ffeDerek Sollenberger    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1335e2e62b55598210f6999fc2ea26ff8f41446ffeDerek Sollenberger    See the License for the specific language governing permissions and
1435e2e62b55598210f6999fc2ea26ff8f41446ffeDerek Sollenberger    limitations under the License.
1535e2e62b55598210f6999fc2ea26ff8f41446ffeDerek Sollenberger */
1635e2e62b55598210f6999fc2ea26ff8f41446ffeDerek Sollenberger
1735e2e62b55598210f6999fc2ea26ff8f41446ffeDerek Sollenberger#ifndef SkClampRange_DEFINED
1835e2e62b55598210f6999fc2ea26ff8f41446ffeDerek Sollenberger#define SkClampRange_DEFINED
1935e2e62b55598210f6999fc2ea26ff8f41446ffeDerek Sollenberger
2035e2e62b55598210f6999fc2ea26ff8f41446ffeDerek Sollenberger#include "SkFixed.h"
2135e2e62b55598210f6999fc2ea26ff8f41446ffeDerek Sollenberger
2235e2e62b55598210f6999fc2ea26ff8f41446ffeDerek Sollenberger/**
2335e2e62b55598210f6999fc2ea26ff8f41446ffeDerek Sollenberger *  Iteration fixed fx by dx, clamping as you go to [0..0xFFFF], this class
2435e2e62b55598210f6999fc2ea26ff8f41446ffeDerek Sollenberger *  computes the (up to) 3 spans there are:
2535e2e62b55598210f6999fc2ea26ff8f41446ffeDerek Sollenberger *
2635e2e62b55598210f6999fc2ea26ff8f41446ffeDerek Sollenberger *  range0: use constant value V0
2735e2e62b55598210f6999fc2ea26ff8f41446ffeDerek Sollenberger *  range1: iterate as usual fx += dx
2835e2e62b55598210f6999fc2ea26ff8f41446ffeDerek Sollenberger *  range2: use constant value V1
2935e2e62b55598210f6999fc2ea26ff8f41446ffeDerek Sollenberger */
3035e2e62b55598210f6999fc2ea26ff8f41446ffeDerek Sollenbergerstruct SkClampRange {
3135e2e62b55598210f6999fc2ea26ff8f41446ffeDerek Sollenberger    int fCount0;    // count for fV0
3235e2e62b55598210f6999fc2ea26ff8f41446ffeDerek Sollenberger    int fCount1;    // count for interpolating (fV0...fV1)
3335e2e62b55598210f6999fc2ea26ff8f41446ffeDerek Sollenberger    int fCount2;    // count for fV1
3435e2e62b55598210f6999fc2ea26ff8f41446ffeDerek Sollenberger    SkFixed fFx1;   // initial fx value for the fCount1 range.
3535e2e62b55598210f6999fc2ea26ff8f41446ffeDerek Sollenberger                    // only valid if fCount1 > 0
3635e2e62b55598210f6999fc2ea26ff8f41446ffeDerek Sollenberger    int fV0, fV1;
3735e2e62b55598210f6999fc2ea26ff8f41446ffeDerek Sollenberger    bool fOverflowed;   // true if we had to clamp due to numerical overflow
3835e2e62b55598210f6999fc2ea26ff8f41446ffeDerek Sollenberger
3935e2e62b55598210f6999fc2ea26ff8f41446ffeDerek Sollenberger    void init(SkFixed fx, SkFixed dx, int count, int v0, int v1);
4035e2e62b55598210f6999fc2ea26ff8f41446ffeDerek Sollenberger
4135e2e62b55598210f6999fc2ea26ff8f41446ffeDerek Sollenbergerprivate:
4235e2e62b55598210f6999fc2ea26ff8f41446ffeDerek Sollenberger    void initFor1(SkFixed fx);
4335e2e62b55598210f6999fc2ea26ff8f41446ffeDerek Sollenberger};
4435e2e62b55598210f6999fc2ea26ff8f41446ffeDerek Sollenberger
4535e2e62b55598210f6999fc2ea26ff8f41446ffeDerek Sollenberger#endif
4635e2e62b55598210f6999fc2ea26ff8f41446ffeDerek Sollenberger
47