- /* This is *so* not handling all the cases... */
- int gray = (image->depth > 16
- ? ((((rgba >> 24) & 0xFF) +
- ((rgba >> 16) & 0xFF) +
- ((rgba >> 8) & 0xFF) +
- ((rgba ) & 0xFF)) >> 2)
- : ((((rgba >> 12) & 0x0F) +
- ((rgba >> 8) & 0x0F) +
- ((rgba >> 4) & 0x0F) +
- ((rgba ) & 0x0F)) >> 1));
+ int gray;
+ if (cmap_p)
+ gray = ((200 - ((((colors[rgba].red >> 8) & 0xFF) +
+ ((colors[rgba].green >> 8) & 0xFF) +
+ ((colors[rgba].blue >> 8) & 0xFF))
+ >> 1))
+ & 0xFF);
+ else
+ /* This is *so* not handling all the cases... */
+ gray = (image->depth > 16
+ ? ((((rgba >> 24) & 0xFF) +
+ ((rgba >> 16) & 0xFF) +
+ ((rgba >> 8) & 0xFF) +
+ ((rgba ) & 0xFF)) >> 2)
+ : ((((rgba >> 12) & 0x0F) +
+ ((rgba >> 8) & 0x0F) +
+ ((rgba >> 4) & 0x0F) +
+ ((rgba ) & 0x0F)) >> 1));
+