What's wrong with this RGB to XYZ color space conversion algorithm?

后端 未结 6 1238
无人及你
无人及你 2020-12-29 06:35

My goal is to convert an RGB pixel into CIELab color space for some special calculations only possible in CIELab. For this, I must convert RGB to XYZ first, which is the rea

6条回答
  •  無奈伤痛
    2020-12-29 07:30

    I believe here is your problem, this is truncating to an integer:

    CGFloat var_R = (*inR / 255); //R from 0 to 255
    CGFloat var_G = (*inG / 255); //G from 0 to 255
    CGFloat var_B = (*inB / 255); //B from 0 to 255
    

    Try this:

    CGFloat var_R = (*inR / 255.0f); //R from 0 to 255
    CGFloat var_G = (*inG / 255.0f); //G from 0 to 255
    CGFloat var_B = (*inB / 255.0f); //B from 0 to 255
    

    I haven't checked the rest of the code for other problems.

提交回复
热议问题