2016-01-07 08:14:33 +00:00
|
|
|
#pragma once
|
2014-01-13 09:35:46 +00:00
|
|
|
|
|
|
|
namespace nall {
|
|
|
|
|
2015-06-18 10:48:53 +00:00
|
|
|
auto image::bitDepth(uint64_t color) -> unsigned {
|
2014-01-13 09:35:46 +00:00
|
|
|
unsigned depth = 0;
|
|
|
|
if(color) while((color & 1) == 0) color >>= 1;
|
|
|
|
while((color & 1) == 1) { color >>= 1; depth++; }
|
|
|
|
return depth;
|
|
|
|
}
|
|
|
|
|
2015-06-18 10:48:53 +00:00
|
|
|
auto image::bitShift(uint64_t color) -> unsigned {
|
2014-01-13 09:35:46 +00:00
|
|
|
unsigned shift = 0;
|
|
|
|
if(color) while((color & 1) == 0) { color >>= 1; shift++; }
|
|
|
|
return shift;
|
|
|
|
}
|
|
|
|
|
2015-06-18 10:48:53 +00:00
|
|
|
auto image::normalize(uint64_t color, unsigned sourceDepth, unsigned targetDepth) -> uint64_t {
|
2014-01-13 09:35:46 +00:00
|
|
|
if(sourceDepth == 0 || targetDepth == 0) return 0;
|
|
|
|
while(sourceDepth < targetDepth) {
|
|
|
|
color = (color << sourceDepth) | color;
|
|
|
|
sourceDepth += sourceDepth;
|
|
|
|
}
|
|
|
|
if(targetDepth < sourceDepth) color >>= (sourceDepth - targetDepth);
|
|
|
|
return color;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|