Skip to content

Instantly share code, notes, and snippets.

@aras-p
Created September 7, 2011 04:50
Show Gist options
  • Save aras-p/1199797 to your computer and use it in GitHub Desktop.
Save aras-p/1199797 to your computer and use it in GitHub Desktop.
Encoding to RGBM
// in our case,
const float kRGBMMaxRange = 8.0f;
const float kOneOverRGBMMaxRange = 1.0f / kRGBMMaxRange;
// encode to RGBM, c = ARGB colors in 0..1 floats
float r = c[1] * kOneOverRGBMMaxRange;
float g = c[2] * kOneOverRGBMMaxRange;
float b = c[3] * kOneOverRGBMMaxRange;
float a = max(max(r, g), max(b, 1e-6f));
a = ceilf(a * 255.0f) / 255.0f;
c[0] = min(a, 1.0f);
c[1] = min(r / a, 1.0f);
c[2] = min(g / a, 1.0f);
c[3] = min(b / a, 1.0f);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment