[Nexus 5 Original Android Development] rajendra82:
You want me to reveal all my secret magic don't you? Just kidding. Here is how I came up with insanity, and then derived Sammy from it.

From the beginning the register array contents, size, and usage has bothered me. The following were the oddities:

1. There are 23 registers for each color. Why did they choose 23? That is such a weird number to use. It also seemed odd that the last register values did not go to zero. This made me believe that there is an implied 24th value that stays at 0, and is used when all colors are at full black.

2. This assumption was confirmed by how the registers were being used. The first 12 were being subtracted from 255 while the last 11 were being used as is. This imbalance is corrected if there is an implied 24th value set at zero. That gives us 12 and 12, which makes a lot of sense. This implied that the midpoint of the color curves is actually halfway between register 12 and register 13.

3. Each register corresponds to an initial intensity value, but what is it. This took some trial and error, but I think I have the values figured out now. The clue was in the test results by mag01 posted in the Gamma app thread. He indicated that the value of red was limited at the high end (which is why is starts at 0 for register 1, which corresponds to an intensity of 255, the maximum, and it probably can't go much lower at the low end either, and it implies the intensity of red of 20 at register 23, was close to a minimum. And at the midpoint of register 12 and 13 it should be 127.5 (halfway between 0 and 255). Based on this I played with various functions, and tried to figure out how the raw intensity at each register level is based on the distance it is from point 12.5, that gives me close to the stock values for red at each register. The function was simpler than I initially thought. It is is simply based on the distance a point is from value 12.5 divided by the maximum distance of 11.5. Basically Raw Intensity =127.5-(Register Number -12.5)/(11.5)*127.5. If there was a Register 12.5, the value would be 127.5, and if there was a register 24, the value would be 0. The results of this function are close to red starting intensity along most points on the curve except near the low point, where Google seemed to want to raise brightness. This gives you the following raw intensities at each register level:

1	255.0

2	243.9

3	232.8

4	221.7

5	210.7

6	199.6

7	188.5

8	177.4

9	166.3

10	155.2

11	144.1

12	133.0

13	122.0

14	110.9

15	99.8

16	88.7

17	77.6

18	66.5

19	55.4

20	44.3

21	33.3

22	22.2

23	11.1

Convert these raw intensities to an integer register array (same for each color, remember no color correction), add a line for white point of 32, and voila, you have insanity profile. This gives you the native gamut, gamma, and color temperature of our panel.

To get from insanity to Sammy is easy now. I applied insanity and measured the native gamma of 2.0. I targeted for a gamma of 2.2. Take the raw intensity numbers and divide them by 255 to convert to a 0 to 1 color space. Apply a gamma correction factor of 1.1 to go from 2.0 to 2.2, then back calculate register array to get the needed intensities at that register. Now you have Sammy. Still no color correction. Still using full gamut of 0 to 255 for each color, but now targeting a different gamma setting.