java - RGB to CIE color conversion -


this question has answer here:

as said before (rgb philips hue (hsb)) i'm still not giving hopes converting simple rgb value value philips hue accept.

the official app iphone , android allows select color random photo , hue adjust accordingly. there must sort of formula.

this time think have found formula in interesting article online:

https://github.com/philipshue/philipshuesdk-ios-osx/blob/master/applicationdesignnotes/rgb%20to%20xy%20color%20conversion.md

i have been trying convert explanation java language, i'm not getting desired results. knows goes wrong?

for record i'm using philips hue light bulbs.

public static list<double> getrgbtoxy(color c) {         // hue bulb corners of triangle are:         // -red: 0.675, 0.322         // -green: 0.4091, 0.518         // -blue: 0.167, 0.04         double[] normalizedtoone = new double[3];         float cred, cgreen, cblue;         cred = c.getred();         cgreen = c.getgreen();         cblue = c.getblue();         normalizedtoone[0] = (cred / 255);         normalizedtoone[1] = (cgreen / 255);         normalizedtoone[2] = (cblue / 255);         float red, green, blue;          // make red more vivid         if (normalizedtoone[0] > 0.04045) {             red = (float) math.pow(                     (normalizedtoone[0] + 0.055) / (1.0 + 0.055), 2.4);         } else {             red = (float) (normalizedtoone[0] / 12.92);         }          // make green more vivid         if (normalizedtoone[1] > 0.04045) {             green = (float) math.pow((normalizedtoone[1] + 0.055)                     / (1.0 + 0.055), 2.4);         } else {             green = (float) (normalizedtoone[1] / 12.92);         }          // make blue more vivid         if (normalizedtoone[2] > 0.04045) {             blue = (float) math.pow((normalizedtoone[2] + 0.055)                     / (1.0 + 0.055), 2.4);         } else {             blue = (float) (normalizedtoone[2] / 12.92);         }          float x = (float) (red * 0.649926 + green * 0.103455 + blue * 0.197109);         float y = (float) (red * 0.234327 + green * 0.743075 + blue + 0.022598);         float z = (float) (red * 0.0000000 + green * 0.053077 + blue * 1.035763);          float x = x / (x + y + z);         float y = y / (x + y + z);          double[] xy = new double[2];         xy[0] = x;         xy[1] = y;         list<double> xyaslist = doubles.aslist(xy);         return xyaslist;     } 

this not duplicate? please read referenced question understand. question convert xy. referenced question converting rgb hsb. how can same?!?!

found 1 little mistake:

float y = (float) (red * 0.234327 + green * 0.743075 + blue + 0.022598); 

should be

float y = (float) (red * 0.234327 + green * 0.743075 + blue * 0.022598); 

Comments

Popular posts from this blog

user interface - How to replace the Python logo in a Tkinter-based Python GUI app? -

objective c - Greedy NSProgressIndicator Allocation -

how to set an OCR language in Google Drive -