# Cannot figure out correct color conversion

I trying to get correct color after iProcessor.unpack(), but was puzzled by contents of libraw_colordata_t structure. Suppose that I have already done demosaicing but still have color in camera color space. What formulas do I need to use to convert (R,G,B) -> (X,Y,Z)? I tried these without success:

```X = (R - Black) * cam_xyz + (G - Black) * cam_xyz + (B - Black) * cam_xyz;
Y = (R - Black) * cam_xyz + (G - Black) * cam_xyz + (B - Black) * cam_xyz;
Z = (R - Black) * cam_xyz + (G - Black) * cam_xyz + (B - Black) * cam_xyz;```

I also noticed cam_mul, pre_mul, cmatrix and rgb_cam member, but not sure how to use them.

## Forums:

### 1) Black should be subtracted

1) Black should be subtracted before demosaic
2) Look into convert_to_rgb code:
to get output matrix, the rgb_cam matrix is multiplied to color space matrix. The rgb_cam is produced by cam_xyz_coeff() call

-- Alex Tutubalin @LibRaw LLC
{"ft_lang_label":"__label__en","ft_lang_prob":0.84906584,"math_prob":0.87102777,"size":935,"snap":"2021-43-2021-49","text_gpt3_token_len":287,"char_repetition_ratio":0.20300752,"word_repetition_ratio":0.06918239,"special_character_ratio":0.342246,"punctuation_ratio":0.11299435,"nsfw_num_words":0,"has_unicode_error":false,"math_prob_llama3":0.9537935,"pos_list":[0],"im_url_duplicate_count":[null],"WARC_HEADER":"{\"WARC-Type\":\"response\",\"WARC-Date\":\"2021-10-25T08:22:44Z\",\"WARC-Record-ID\":\"<urn:uuid:673e171a-d661-4745-be35-3353c17ee7a0>\",\"Content-Length\":\"30861\",\"Content-Type\":\"application/http; msgtype=response\",\"WARC-Warcinfo-ID\":\"<urn:uuid:aaddcdfc-c283-4e86-b515-22289d05cb8b>\",\"WARC-Concurrent-To\":\"<urn:uuid:83b0e36d-b15c-40bf-a7d4-f217853488d2>\",\"WARC-IP-Address\":\"192.95.29.165\",\"WARC-Target-URI\":\"https://www.libraw.org/node/1814\",\"WARC-Payload-Digest\":\"sha1:U225ZEBCR22CJJ7SQP7ALSBZ2ENTYCNR\",\"WARC-Block-Digest\":\"sha1:WLUFAEUYQ5D4MCABNSJ2QMWNNGTTDRUU\",\"WARC-Identified-Payload-Type\":\"text/html\",\"warc_filename\":\"/cc_download/warc_2021/CC-MAIN-2021-43/CC-MAIN-2021-43_segments_1634323587655.10_warc_CC-MAIN-20211025061300-20211025091300-00696.warc.gz\"}"}