Android Open Source - android-imgpro-lib Contrast






From Project

Back to project page android-imgpro-lib.

License

The source code is released under:

MIT License

If you think the Android project android-imgpro-lib listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package net.akhyar.android.imgpro.actions;
/*from   w  w w  .j a  v a2 s  .  c  om*/
import net.akhyar.android.imgpro.Action;
import android.graphics.Color;

public class Contrast extends Action {

  private int value;
  private double contrast;

  public Contrast(int value) {
    this.value = value;
    this.contrast = Math.pow((100 + value) / 100, 2);
  }

  @Override
  protected void adjustPixels(int[] pixels) {

    int A, R, G, B;
    for (int i = 0; i < pixels.length; i++) {
      A = Color.alpha(pixels[i]);

      R = Color.red(pixels[i]);
      R = (int) (((((R / 255.0) - 0.5) * contrast) + 0.5) * 255.0);

      G = Color.green(pixels[i]);
      G = (int) (((((G / 255.0) - 0.5) * contrast) + 0.5) * 255.0);

      B = Color.blue(pixels[i]);
      B = (int) (((((B / 255.0) - 0.5) * contrast) + 0.5) * 255.0);
      
      R = clamp(R);
      G = clamp(G);
      B = clamp(B);
      
      pixels[i] = Color.argb(A, R, G, B);
    }
  }

  public float getAmount() {
    return value;
  }

  public void setAmount(int amount) {
    this.value = amount;
  }

}




Java Source Code List

net.akhyar.android.imgpro.Action.java
net.akhyar.android.imgpro.Channel.java
net.akhyar.android.imgpro.FilterListener.java
net.akhyar.android.imgpro.FilterTask.java
net.akhyar.android.imgpro.Filter.java
net.akhyar.android.imgpro.ImgPro.java
net.akhyar.android.imgpro.actions.Blend.java
net.akhyar.android.imgpro.actions.Blur.java
net.akhyar.android.imgpro.actions.Brightness.java
net.akhyar.android.imgpro.actions.ChannelMix.java
net.akhyar.android.imgpro.actions.Colorize.java
net.akhyar.android.imgpro.actions.Contrast.java
net.akhyar.android.imgpro.actions.Desaturate.java
net.akhyar.android.imgpro.actions.Invert.java
net.akhyar.android.imgpro.filters.Default.java
net.akhyar.android.imgpro.filters.Vintage.java
net.akhyar.android.imgpro.filters.XProcess.java
net.akhyar.android.perf.BitmapTask.java
net.akhyar.android.perf.SetBitmap.java
net.akhyar.android.perf.SetImageViewBitmapTask.java
net.akhyar.android.perf.Worker.java