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

View File

@@ -33,38 +33,93 @@ public class ColorUtil {
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 {
RED {
@Override
public int from(int rgb) {
return getRed(rgb);
}
@Override
public int zero(int rgb) {
return zeroRed(rgb);
}
},
GREEN {
@Override
public int from(int rgb) {
return getGreen(rgb);
}
@Override
public int zero(int rgb) {
return zeroGreen(rgb);
}
},
BLUE {
@Override
public int from(int rgb) {
return getBlue(rgb);
}
@Override
public int zero(int rgb) {
return zeroBlue(rgb);
}
},
GRAYSCALE {
@Override
public int from(int rgb) {
return getGrayscale(rgb);
}
@Override
public int zero(int rgb) {
return zeroGrayscale(rgb);
}
},
ALPHA {
@Override
public int from(int rgb) {
return getAlpha(rgb);
}
@Override
public int zero(int rgb) {
return zeroAlpha(rgb);
}
};
public abstract int from(int rgb);
public abstract int zero(int rgb);
}
}