Use Xephyr to run a second X window with 8bit color depth in Raspberry Pi
https://nims11.wordpress.com/2012/06/24/nested-x-servers-with-xephyr/
Xephyr -ac -screen 800x600x8 -reset :1 &
This will open a blank window
In the original window, type
DISPLAY=:1
Then run the C program. It show “Colomap_size: 256”.
It worked!