Exemplo n.º 1
0
  public static float getModifiedValue(float value, Shade shade) {

    if (shade.getValue() == 500) {
      return value;
    }

    float indexFloat = ((float) shade.getValue()) / 100.0f;

    int indexFloor = (int) Math.floor(indexFloat);
    int indexCeil = (int) Math.ceil(indexFloat);

    int max = mValuePercentConversion.length - 1;
    int lowerIndex = Math.min(Math.max(indexFloor, 0), max);
    int upperIndex = Math.min(Math.max(indexCeil, 0), max);

    float lowerPercent = mValuePercentConversion[lowerIndex];
    float valuePercent;
    if (lowerIndex != upperIndex) {
      float upperPercent = mValuePercentConversion[upperIndex];
      float deltaPercent = upperPercent - lowerPercent;
      float deltaIndex = upperIndex - lowerIndex;
      valuePercent = lowerPercent + (deltaPercent / deltaIndex) * (indexFloat - (float) lowerIndex);
    } else {
      valuePercent = lowerPercent;
    }

    if (shade.getValue() < 500) {
      return value + ((1.0f - value) * valuePercent);
    } else {
      return value + (value * valuePercent);
    }
  }
Exemplo n.º 2
0
 public static float getModifiedHue(float hue, Shade shade) {
   float s = (float) shade.getValue();
   if (s > 500) {
     // Initial calculations are based on hue being in the range [0.0-1.0]
     // java has the range [0.0-360.0] so we'll do a little conversion
     hue = hue / 360.0f;
     float hueAt900 = (1.003f * hue) - 0.016f;
     hue = ((hueAt900 - hue) / ((float) 900 - (float) 500)) * (s - (float) 500) + hue;
     return hue * 360.0f;
   } else {
     return hue;
   }
 }
Exemplo n.º 3
0
  public static float getModifiedSaturation(float saturation, Shade shade) {
    if (shade.getValue() == 500) {
      return saturation;
    }

    if (shade.getValue() < 500) {
      // get the saturation target @ 50:
      // clamp to 0.0
      float f = (0.136f * saturation) - 0.025f;
      float satAt50 = Math.max(f, 0.0f);
      // lerp shade 500->900
      return ((saturation - satAt50) / (500 - 50)) * (shade.getValue() - 50) + satAt50;
    } else {
      // get the saturation target @ 900:
      // quick inaccurate version:
      // 110% of the base saturation (clamped to 1.0)
      //            CGFloat satAt900 = MIN(baseSaturation * 1.10, 1.0);
      // expensive(?) accurate version
      float satAt900 =
          Math.min((-1.019f * saturation * saturation) + (2.283f * saturation) - 0.281f, 1.0f);
      // lerp shade 500->900
      return ((satAt900 - saturation) / (900 - 500)) * (shade.getValue() - 500) + saturation;
    }
  }