static.hpp 737 B

1234567891011121314151617181920212223242526272829
  1. #pragma once
  2. namespace nall {
  3. auto image::bitDepth(uint64_t color) -> unsigned {
  4. unsigned depth = 0;
  5. if(color) while((color & 1) == 0) color >>= 1;
  6. while((color & 1) == 1) { color >>= 1; depth++; }
  7. return depth;
  8. }
  9. auto image::bitShift(uint64_t color) -> unsigned {
  10. unsigned shift = 0;
  11. if(color) while((color & 1) == 0) { color >>= 1; shift++; }
  12. return shift;
  13. }
  14. auto image::normalize(uint64_t color, unsigned sourceDepth, unsigned targetDepth) -> uint64_t {
  15. if(sourceDepth == 0 || targetDepth == 0) return 0;
  16. while(sourceDepth < targetDepth) {
  17. color = (color << sourceDepth) | color;
  18. sourceDepth += sourceDepth;
  19. }
  20. if(targetDepth < sourceDepth) color >>= (sourceDepth - targetDepth);
  21. return color;
  22. }
  23. }