Thank you for your answer, A1ex, I was waiting for it first.
Concerning my results - you see, my transformation is simple - just shr by 2. I have made an assumption that if the original color space is linear than it is perfectly justified that in order to achieve 14 bps I should only make a simple linear transformation. Nonetheless, the result is unexpectedly green in the dark areas and the picture is much darker than the original (shadows transformed into deep shadows or even black), which proof one of the things: there is a transformation of original cr2-color space in cr2hdr and it is
not linear OR the original Canon color space is itself
not linear. The latter, however, should not be true if the cr2-values are raw levels - voltage, in fact (correct me if I am wrong with that assumption), which again bring us back to the idea that there is some color transformation in cr2hdr and it is not linear. It is difficult for me to check the code of cr2hdr that fast and that is why I started this topic.
you have simply ran out of bits.
Well, I would agree with you if it were not possible to have normal dynamic range using just 8 bps. The problem is deeper, and it does not matter whether it is 14 bps or as much as 20. If it were just shadows I would not say a word about it - I still have a lot to learn about appropriate ISO's in different scenes. This is the green tint which makes it all wrong. It means that the original and the resulting color spaces are not correspond to each other.
How did you replace the data in the original CR2? did you use libcraw2 or you wrote your own?
Well, that is quite a story and probably if I were acquainted with libcraw, I would not spend that much time. I did it using a result of comprehension of the dcraw.c, ITU-T.81, and ppmtoljpg example (which is based on the libjpeg). My tool is actually a mix of code excerpts from dcraw.c and ppmtoljpg.c and hard-coded values from 650d version of cr2-files (I have no idea whether the values are different in the other models cr2-files but I guess they could be). Actually, it was really a surprise for me that cr2-files (as well as dng) are not special files but just tiff-files with some private tags known only to Canon, and the raw data in such a file is just another lossless jpeg file inside tiff. Moreover, the ljpg-file is in the end of cr2-file and in order to replace the data you should only compress new data into ljpgf-file, replace the old one with it and modify the size of the "compressed data" in the "header" (tiff tag 279 of the corresponding ifd). The problem, however, is lossless jpeg compression, but I managed to find its free implementation, which suits good to the purpose.