I've been looking at the documentation and fiddling with ico files, but I can't quite seem to get a grasp on something...

I have an ico file stored as a base64 data uri in a web page. If i replace quad info using javascript I can dynamically change the color.
**Anyone already have an implementation of this I could look at?**

BUT, it seems I can't quite get all colors in the rgb scale predicdably. For example. If I save a 4x4 ico file that is a pure 0,0,255 blue you would expect each pixel to reflect a version of that info(a 255 and two 0's in some order). Instead, every third pixel becomes 240,15,0? I can find information about the header info ect, but no insights into this phenomenon. Any tips would be great.