Skip to content

Instantly share code, notes, and snippets.

@andanteyk
Created November 2, 2014 03:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save andanteyk/6ccb888ef3ac7fedd328 to your computer and use it in GitHub Desktop.
Save andanteyk/6ccb888ef3ac7fedd328 to your computer and use it in GitHub Desktop.
メタデータに色を保存するサンプル
//メタデータ領域が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