Rework/optimize gallery color calculation.
Use SparseIntArray for gallery's color