[Nexus 4 Original Android Development] jazzboyrules:
Script to change colors and gamma using variables

Hey guys (especially the ones enjoying the color experiments on Paranoid Android),

I have been implementing various color/gamma values after Moles started posting his experiments. As he was constantly updated his gamma values, I got inspired to write this script that auto calculates the checksums :)

By default the gamma values for all 3 channels is the same. But you can tweak them by replacing the '0' with any constant of your choice in the tweak sections of this script. Of course you can replace the '+' with a '-' if you need to.

For most cases, you will need to change only the variables highlighted in orange.

As I said above, you can change all 27 gamma numbers too by messing around in the "#Tweak red/green/blue gamma values here if needed" sections of the script.

So here's the script:

#!/system/bin/sh

#Setting RGB
[COLOR="DarkOrange"]color_red=245
color_green=244
color_blue=240[/COLOR]
echo "$color_red $color_green $color_blue" > /sys/devices/platform/kcal_ctrl.0/kcal
echo 1 > /sys/devices/platform/kcal_ctrl.0/kcal_ctrl

#Setting gamma
[COLOR="DarkOrange"]g_white=64[/COLOR] #Whitepoint, LG=0x72, GOOG=0x40,40,20 Low values=extreme whites, risk of blown out highlights
[COLOR="DarkOrange"]g_mid=68[/COLOR]
[COLOR="DarkOrange"]g_black=118[/COLOR] #Blackpoint, LG=0x76, GOOG=0x76,76,74 Low values=cut out, banding in the shadows
[COLOR="DarkOrange"]g_unknown1=0[/COLOR]
[COLOR="DarkOrange"]g_contrast=26[/COLOR] #Contrast (AMP0), LG=0x00, GOOG=0x00,00,1F
[COLOR="DarkOrange"]g_brightness=0[/COLOR] #Brightness (AMP1), LG=0x00, GOOG=0x00,00,10
[COLOR="DarkOrange"]g_saturation=72[/COLOR] #Saturation, LG=0x50, GOOG=0x30,30,50
[COLOR="DarkOrange"]g_unknown2=48[/COLOR]
[COLOR="DarkOrange"]g_unknown3=2[/COLOR]

#Tweak red gamma values here if needed
gr_white=`expr $g_white + 0`
gr_mid=`expr $g_mid + 0`
gr_black=`expr $g_black + 0`
gr_unknown1=`expr $g_unknown1 + 0`
gr_contrast=`expr $g_contrast + 0`
gr_brightness=`expr $g_brightness + 0`
gr_saturation=`expr $g_saturation + 0`
gr_unknown2=`expr $g_unknown2 + 0`
gr_unknown3=`expr $g_unknown3 + 0`
gr_cksummotley=`expr $gr_white + $gr_mid + $gr_black + $gr_unknown1 + $gr_contrast + $gr_brightness + $gr_saturation + $gr_unknown2 + $gr_unknown3`

#Tweak green gamma values here if needed
gg_white=`expr $g_white + 0`
gg_mid=`expr $g_mid + 0`
gg_black=`expr $g_black + 0`
gg_unknown1=`expr $g_unknown1 + 0`
gg_contrast=`expr $g_contrast + 0`
gg_brightness=`expr $g_brightness + 0`
gg_saturation=`expr $g_saturation + 0`
gg_unknown2=`expr $g_unknown2 + 0`
gg_unknown3=`expr $g_unknown3 + 0`
gg_cksummotley=`expr $gg_white + $gg_mid + $gg_black + $gg_unknown1 + $gg_contrast + $gg_brightness + $gg_saturation + $gg_unknown2 + $gg_unknown3`

#Tweak blue gamma values here if needed
gb_white=`expr $g_white + 0`
gb_mid=`expr $g_mid + 0`
gb_black=`expr $g_black + 0`
gb_unknown1=`expr $g_unknown1 + 0`
gb_contrast=`expr $g_contrast + 0`
gb_brightness=`expr $g_brightness + 0`
gb_saturation=`expr $g_saturation + 0`
gb_unknown2=`expr $g_unknown2 + 0`
gb_unknown3=`expr $g_unknown3 + 0`
gb_cksummotley=`expr $gb_white + $gb_mid + $gb_black + $gb_unknown1 + $gb_contrast + $gb_brightness + $gb_saturation + $gb_unknown2 + $gb_unknown3`

echo "$gr_cksummotley $gr_white $gr_mid $gr_black $gr_unknown1 $gr_contrast $gr_brightness $gr_saturation $gr_unknown2 $gr_unknown3" > /sys/devices/platform/mipi_lgit.1537/kgamma_red
echo "$gg_cksummotley $gg_white $gg_mid $gg_black $gg_unknown1 $gg_contrast $gg_brightness $gg_saturation $gg_unknown2 $gg_unknown3" > /sys/devices/platform/mipi_lgit.1537/kgamma_green
echo "$gb_cksummotley $gb_white $gb_mid $gb_black $gb_unknown1 $gb_contrast $gb_brightness $gb_saturation $gb_unknown2 $gb_unknown3" > /sys/devices/platform/mipi_lgit.1537/kgamma_blue

# Show the current configuration and the checksum
echo "Verify that the values are written correctly..\n"
echo "RGB values:"
cat /sys/devices/platform/kcal_ctrl.0/kcal
echo "\nRed gamma values:"
cat /sys/devices/platform/mipi_lgit.1537/kgamma_red
echo "\nGreen gamma values:"
cat /sys/devices/platform/mipi_lgit.1537/kgamma_green
echo "\nBlue gamma values:"
cat /sys/devices/platform/mipi_lgit.1537/kgamma_blue
echo ""

#values tweaked by molesarecoming (Paranoid Android)
#script by jazzboyrules

UPDATE:

If copy-pasting the above script and running it in terminal in su mode does not work for you, I have attached the same script here in zipped format. ( DO NOT FLASH IT ).

Simply unzip it and execute in Terminal with su enabled. I am sure this script will work. Once you get the verification message showing the set rgb and gamma values after running it and those values ARE what you expected to be then go ahead and put it in init.d if you want to.

Q. How do I tweak this script to update it with Mole's latest rgb/gamma values?

A. All the variable names in this script match with the defines in Mole's post except one where I have g_mid and Mole has g_mids (but they are the same). Moles sets his variable values in hex. So you will have to do hex to decimal conversion and then assign that value in this script corresponding to the same variable.

So that's it. This script sets the values to get dark, contrasty screen. If you like the brighter screen settings, just set the variables in this script to the values Mole has suggested for brighter screen and you are good to go.

UPDATE Feb 8 2013:

Hey guys, for anyone interested, I have added the zipped script for holoblue ( DO NOT FLASH IT ). The contrasty version is still my fav :)

another UPDATE Feb 8 2013:

Added the zipped script for "halfbreed" ( DO NOT FLASH IT ). Loving it!!