Add utility methods for zero-ing color channels

This commit is contained in:
Astrash
2022-11-24 13:55:36 +11:00
parent c491ac5b24
commit 4e225a6592
@@ -33,38 +33,93 @@ public class ColorUtil {
return (getRed(rgb) + getGreen(rgb) + getBlue(rgb)) / 3; return (getRed(rgb) + getGreen(rgb) + getBlue(rgb)) / 3;
} }
public static int getChannel(int rgb, Channel channel) {
return channel.from(rgb);
}
public static int zeroRed(int rgb) {
return rgb & ~0x00FF0000;
}
public static int zeroGreen(int rgb) {
return rgb & ~0x0000FF00;
}
public static int zeroBlue(int rgb) {
return rgb & ~0x000000FF;
}
public static int zeroAlpha(int rgb) {
return rgb & ~0xFF000000;
}
public static int zeroGrayscale(int rgb) {
return rgb & ~0x00FFFFFF;
}
public static int zeroChannel(int rgb, Channel channel) {
return channel.zero(rgb);
}
public enum Channel { public enum Channel {
RED { RED {
@Override @Override
public int from(int rgb) { public int from(int rgb) {
return getRed(rgb); return getRed(rgb);
} }
@Override
public int zero(int rgb) {
return zeroRed(rgb);
}
}, },
GREEN { GREEN {
@Override @Override
public int from(int rgb) { public int from(int rgb) {
return getGreen(rgb); return getGreen(rgb);
} }
@Override
public int zero(int rgb) {
return zeroGreen(rgb);
}
}, },
BLUE { BLUE {
@Override @Override
public int from(int rgb) { public int from(int rgb) {
return getBlue(rgb); return getBlue(rgb);
} }
@Override
public int zero(int rgb) {
return zeroBlue(rgb);
}
}, },
GRAYSCALE { GRAYSCALE {
@Override @Override
public int from(int rgb) { public int from(int rgb) {
return getGrayscale(rgb); return getGrayscale(rgb);
} }
@Override
public int zero(int rgb) {
return zeroGrayscale(rgb);
}
}, },
ALPHA { ALPHA {
@Override @Override
public int from(int rgb) { public int from(int rgb) {
return getAlpha(rgb); return getAlpha(rgb);
} }
@Override
public int zero(int rgb) {
return zeroAlpha(rgb);
}
}; };
public abstract int from(int rgb); public abstract int from(int rgb);
public abstract int zero(int rgb);
} }
} }