Transfer algorithm for RGB, CMY (K), YUV, YIQ, YCBCR color

xiaoxiao2021-03-06  99

/ ** * Color selector color conversion algorithm *

Copyright: langzisoft 13/10/2004 * Shandong University Computer system * @Author Shao Jian * @Version 1.0 ** /

Import java.lang.math; import java.awt. *;

Public class colorconverter {public color,} // RGB conversion CMYK public int [] RGB2CMYK (int R, int G, int b) {int CMYK [] = new int = (4]; cmyk [3] = (int) (Math.min (Math.min (255-R, 255-G), 255-B) / 2.55); // CMYKK INT MyR = (int) (R / 2.55); int Div = 100-CMYK [3] ; If (div == 0) DIV = 1; CMYK [0] = ((100-MyR-CMYK [3]) / div) * 100; // cmykc int myg = (int) (g / 2.55); CMYK [1] = ((100-MYG-CMYK [3]) / div) * 100; int myb = (int) (B / 2.55); CMYK [2] = ((100-myb-cmyk [3]) / Div) * 100; Return CMYK;} Public Color CMYK2RGB (INT C, INT M, INT Y, INT K) {float myc = c / 100; float mym = m / 100; float mym = y / 100; float myk = K / 100; int R = (int) ((1- (myc * (1-myk) myk) * 255); int g = (int) ((1- (MyM * (1-myk) myk )) * 255); int b = (int) ((1- (MYY * (1-myk) myk) * 255); if (r <0) r = 0; IF (g <0) g = 0; if (b <0) b = 0; if (r> 255) r = 255; if (g> 255) g = 255; if (b> 255) b = 255; color RGB = New color (R, G, b); return RGB;} public int [] RGB2YUV (int R, int G, int b) {int yuv [] = new int =; yuv [0] = (int) (0.299 * r 0.587 * G 0.114 * b); YUV [1] = (int) (- 0.147 * r-0.289 * g 0.437 * b); YUV [2] = (int) (0.615 * r-0.515 * g-0.1 * b); return yuv;} public color YUV2RGB (int y, int u, int v) {int R = (int) (Y 1.14 * V); int G = (int) (Y-0.394 * U-0.581 * v); int b = (int) (y 2.028 * u); if (r <0) r = 0; if (g <0) g = 0; if (b <0) b = 0; if (r> 255) r = 255; IF ( G> 255; if (b> 255) B = 255; color RGB = New Color (R, G, B); RETURN RGB;} public int [] RGB2YIQ (int R, Int g, int b) {Int yiq [] = new int [3]; yiq [0] = (int) (0.299 * r 0.587 * g 0.114 * b); yiq [1] =

转载请注明原文地址:https://www.9cbs.com/read-105090.html

New Post(0)