Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * === FUNCTION ======================================================================
- * Name: modBitmapColor
- * Description:
- * =====================================================================================
- */
- public int[] modBitmapColor( int[] colorarray , int width , int height , int amtR , int amtG, int amtB )
- {
- //THIS SECTION IS COMMENTED OUT FOR TESTING COLOR DATA.
- Random generator = new Random();
- amtR = generator.nextInt( 255 );
- amtG = generator.nextInt( 255 );
- amtB = generator.nextInt( 255 );
- /////Log.d(TAG, "public int modBitmapColor( int[] colorarray, int width , int height , int amtR , int amtG, int amtB )");
- // image.getPixels(scratch, 0, image.getWidth() , 0, 0, image.getWidth() , image.getHeight() );
- Log.d(TAG, "inside modBitmapColor amtR="+amtR+" amtG="+amtG+" amtB="+amtB );
- for (int y = 0; y < height; y++)
- {
- for (int x = 0; x < width; x++)
- {
- int index = y * width + x;
- int a = (colorarray[index] >> 24) & 0xff;
- int r = (colorarray[index] >> 16) & 0xff;
- int g = (colorarray[index] >> 8) & 0xff;
- int b = colorarray[index] & 0xff;
- //Log.d(TAG, "A:"+a+" R:"+r +" G:"+g +"B:"+b );
- if( r!=0) { r = amtR;}
- if( g!=0) { g = amtG;}
- if( b!=0) { b = amtB;}
- if( r>=256) { r=255; }
- if( g>=256) { g=255; }
- if( b>=256) { b=255; }
- if( r<=0) { r=0; }
- if( g<=0) { g=0; }
- if( b<=0) { b=0; }
- colorarray[index] = (a << 24) | (r << 16) | (g << 8) | b;
- }
- }
- // To copy the contents of the pixels array onto the Bitmap:
- //image.setPixels( colorarray, 0, image.getWidth(), 0, 0, image.getWidth(), image.getHeight() );
- ///Log.d(TAG, " return");
- return colorarray;
- }
- /*
- * === FUNCTION ======================================================================
- * Name: Text2PosTexture
- * Description: blit string to texture at specific X Y location with
- * specific color,spacing and size.
- *
- *
- *
- * =====================================================================================
- */
- public void Text2PosTexture( String texID, String text , int startx , int starty, int fontsize , int Rcol , int Gcol, int Bcol )
- {
- //Log.d(TAG, "public void Text2PosTexture( String texID ,String text , int startx , int starty, int fontsize , int Rcol , int Gcol, int Bcol )" );
- int[] letterpos = new int[1];
- int spaceing=0;
- //Log.d(TAG, "text.length="+text.length());
- int[] fontType = null;
- int[] blitletter = null;
- Bitmap fontTarget = font_table.immutable_thatfont.copy(Bitmap.Config.ARGB_4444, true);
- //choose font size
- switch( fontsize )
- {
- case 1:
- //normal 16
- //Log.d(TAG, "16pt");
- fontType = font_table.pixles_16pt;
- spaceing = font_table.MEDIUM_FONT_SPACEING;
- break;
- case 2:
- //large 32
- //Log.d(TAG, "32pt");
- fontType = font_table.pixles_32pt;
- spaceing = font_table.LARGE_FONT_SPACEING;
- break;
- default:
- //small 14
- //Log.d(TAG, "14pt");
- fontType = font_table.pixles_14pt;
- spaceing = font_table.SMALL_FONT_SPACEING;
- break;
- }
- Log.d(TAG, "modBitmapColor Rcol="+Rcol+" Gcol="+Gcol+" Bcol="+Bcol );
- //choose color to change to. H W RGB
- fontType = modBitmapColor( fontType, 512 , 512 , Rcol , Gcol , Bcol );
- //this will convert every leter of the string to a position on the font
- //table .
- for (int n=0;n<text.length();n++)
- {
- letterpos = Letter2TexturePos( text.substring(n,n+1) );
- //return a blitmap letter to post to blitarray
- blitletter = getBlitLetter( fontType, 512 , letterpos[1] , letterpos[0] );
- //all fonts are 32x32 chunks will copy to a 1024x1024(6) texture.
- font_table.blitmapZ = blitIntArray( font_table.blitmapZ , 6, blitletter , startx + (n * spaceing),starty, 32 , 32 );
- }
- // make texture
- fontTarget.setPixels( font_table.blitmapZ , 0, 1024 , 0, 0, 1024 , 1024 );
- //place font into texture.
- Texture allfonts = new Texture( fontTarget , true );
- TextureManager.getInstance().replaceTexture(texID, allfonts );
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement