Created
November 2, 2014 03:49
-
-
Save andanteyk/6ccb888ef3ac7fedd328 to your computer and use it in GitHub Desktop.
メタデータに色を保存するサンプル
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//メタデータ領域が15bitだと rgb 各5bit | |
//ビット列は rrrrrgggggbbbbb とする | |
//rgbはそれぞれ 0-31 の値をとる | |
public int MetaToColor( int meta ) { | |
//各成分を抽出 | |
int r = ( meta >> 10 ) & 0x1F; | |
int g = ( meta >> 5 ) & 0x1F; | |
int b = meta & 0x1F; | |
return ( ( r << 3 ) << 16 ) | ( ( g << 3 ) << 8 ) | ( b << 3 ); | |
} | |
public int ColorToMeta( int r, int g, int b ) { | |
//各色下位3bitは切り捨てる | |
return ( ( r >> 3 ) << 16 ) | ( ( g >> 3 ) << 8 ) | ( b >> 3 ); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment