(New page: <source lang="java"> public static java.awt.Color twoColorFromYUV(byte y, byte u, byte v) { return new java.awt.Color(Ts.twoColorFromYUVInt(y, u, v)); } public static int twoColorFromYUV...) |
|||
Line 9: | Line 9: | ||
int blue = (298 * ((y & 0xFF) - 16) + 516 * ((u & 0xFF) - 128) + 128) >> 8; | int blue = (298 * ((y & 0xFF) - 16) + 516 * ((u & 0xFF) - 128) + 128) >> 8; | ||
red = red > 255 ? 255 : (red < 0 ? 0 : red); | red = red > 255 ? 255 : (red < 0 ? 0 : red); | ||
− | + | red = Ts.mathClip(red, 255, 0); | |
− | blue = | + | green = Ts.mathClip(green, 255, 0); |
+ | blue = Ts.mathClip(blue, 255, 0); | ||
return ((red << 16) | (green << 8) | blue); | return ((red << 16) | (green << 8) | blue); | ||
+ | } | ||
+ | |||
+ | /** | ||
+ | * Clip the value to limit it in the range from min to max (inclusive) | ||
+ | * @param original the value to be applied by clip | ||
+ | * @param max the max of the range (inclusive) | ||
+ | * @param min the min of the range (inclusive) | ||
+ | * @return the value that range from min to max | ||
+ | */ | ||
+ | public static int mathClip(int original, int max, int min) { | ||
+ | int result = Math.max(min, original); | ||
+ | return Math.min(max, result); | ||
} | } | ||
</source> | </source> |
Latest revision as of 09:21, 25 November 2010
public static java.awt.Color twoColorFromYUV(byte y, byte u, byte v) { return new java.awt.Color(Ts.twoColorFromYUVInt(y, u, v)); } public static int twoColorFromYUVInt(byte y, byte u, byte v) { int red = (298 * ((y & 0xFF) - 16) + 409 * ((v & 0xFF) - 128) + 128) >> 8; int green = (298 * ((y & 0xFF) - 16) - 100 * ((u & 0xFF) - 128) - 208 * ((v & 0xFF) - 128) + 128) >> 8; int blue = (298 * ((y & 0xFF) - 16) + 516 * ((u & 0xFF) - 128) + 128) >> 8; red = red > 255 ? 255 : (red < 0 ? 0 : red); red = Ts.mathClip(red, 255, 0); green = Ts.mathClip(green, 255, 0); blue = Ts.mathClip(blue, 255, 0); return ((red << 16) | (green << 8) | blue); } /** * Clip the value to limit it in the range from min to max (inclusive) * @param original the value to be applied by clip * @param max the max of the range (inclusive) * @param min the min of the range (inclusive) * @return the value that range from min to max */ public static int mathClip(int original, int max, int min) { int result = Math.max(min, original); return Math.min(max, result); }