Advertisement
Guest User

Untitled

a guest
Jul 26th, 2017
111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 4.55 KB | None | 0 0
  1.     /*
  2.      * ===  FUNCTION  ======================================================================
  3.      *         Name:  modBitmapColor
  4.      *  Description:  
  5.      * =====================================================================================
  6.     */
  7.         public int[] modBitmapColor( int[] colorarray , int width , int height , int amtR , int amtG, int amtB )
  8.     {
  9.  
  10. //THIS SECTION IS COMMENTED OUT FOR TESTING COLOR DATA.
  11.          Random generator = new Random();
  12.       amtR = generator.nextInt( 255 );
  13.       amtG = generator.nextInt( 255 );
  14.       amtB = generator.nextInt( 255 );
  15.  
  16.  
  17.  
  18.    /////Log.d(TAG, "public int modBitmapColor( int[] colorarray, int width , int height , int amtR , int amtG, int amtB )");
  19.      // image.getPixels(scratch, 0,  image.getWidth() , 0, 0, image.getWidth() , image.getHeight() );
  20.             Log.d(TAG, "inside modBitmapColor amtR="+amtR+" amtG="+amtG+" amtB="+amtB );
  21.  
  22.         for (int y = 0; y < height; y++)
  23.          {     
  24.              for (int x = 0; x < width; x++)
  25.               {
  26.                int index = y * width + x;
  27.                int a = (colorarray[index] >> 24) & 0xff;
  28.                int r = (colorarray[index] >> 16) & 0xff;
  29.                int g = (colorarray[index] >> 8) & 0xff;
  30.                int b = colorarray[index] & 0xff;
  31.                //Log.d(TAG, "A:"+a+" R:"+r +" G:"+g +"B:"+b );
  32.          if( r!=0) { r = amtR;}
  33.          if( g!=0) { g = amtG;}
  34.          if( b!=0) { b = amtB;}
  35.                                
  36.          if( r>=256) { r=255; }
  37.          if( g>=256) { g=255; }
  38.          if( b>=256) { b=255; }
  39.          if( r<=0) { r=0; }
  40.          if( g<=0) { g=0; }
  41.          if( b<=0) { b=0; }
  42.  
  43.                  colorarray[index] = (a << 24) | (r << 16) | (g << 8) | b;
  44.                 }
  45.            }
  46.  
  47.           // To copy the contents of the pixels array onto the Bitmap:
  48.           //image.setPixels( colorarray, 0, image.getWidth(), 0, 0, image.getWidth(), image.getHeight() );
  49.          ///Log.d(TAG, " return");
  50.      return colorarray;
  51.     }
  52.  
  53.  
  54.  
  55.  
  56.  
  57.  
  58. /*
  59.  * ===  FUNCTION  ======================================================================
  60.  *         Name:  Text2PosTexture
  61.  *  Description:  blit string to texture at specific X Y location with
  62.  *  specific color,spacing and size.
  63.  *              
  64.  *
  65.  *
  66.  * =====================================================================================
  67. */
  68.   public void Text2PosTexture( String texID, String text , int startx , int starty, int fontsize , int Rcol , int Gcol, int Bcol )
  69.     {
  70.      //Log.d(TAG, "public void Text2PosTexture( String texID ,String text , int startx , int starty, int fontsize , int Rcol , int Gcol, int Bcol )" );
  71.            int[] letterpos = new int[1];
  72.          int spaceing=0;
  73.          //Log.d(TAG, "text.length="+text.length());
  74.          int[] fontType = null;
  75.          int[] blitletter = null;
  76.      Bitmap fontTarget = font_table.immutable_thatfont.copy(Bitmap.Config.ARGB_4444, true);
  77.    
  78.          //choose font size  
  79.      switch( fontsize )
  80.        {
  81.                 case 1:
  82.         //normal 16
  83.                 //Log.d(TAG, "16pt");
  84.                 fontType = font_table.pixles_16pt;
  85.                 spaceing = font_table.MEDIUM_FONT_SPACEING;
  86.         break;
  87.         case 2:
  88.         //large 32 
  89.                 //Log.d(TAG, "32pt");
  90.                 fontType = font_table.pixles_32pt;
  91.                 spaceing = font_table.LARGE_FONT_SPACEING;
  92.         break;            
  93.         default:
  94.         //small 14
  95.                 //Log.d(TAG, "14pt");
  96.                 fontType = font_table.pixles_14pt;
  97.                 spaceing = font_table.SMALL_FONT_SPACEING;
  98.  
  99.         break;
  100.      }
  101.  
  102.    Log.d(TAG, "modBitmapColor Rcol="+Rcol+" Gcol="+Gcol+" Bcol="+Bcol );
  103.  
  104.  
  105.    //choose color to change to. H W  RGB
  106.    fontType = modBitmapColor( fontType, 512 , 512 , Rcol , Gcol , Bcol );
  107.  
  108.  
  109.  
  110.  
  111.  
  112.          //this will convert every leter of the string to a position on the font
  113.          //table .
  114.            for (int n=0;n<text.length();n++)
  115.             {
  116.              letterpos =  Letter2TexturePos( text.substring(n,n+1) );
  117.            //return a blitmap letter to post to blitarray
  118.            blitletter = getBlitLetter( fontType, 512 , letterpos[1] , letterpos[0]  );
  119.            //all fonts are 32x32 chunks will copy to a 1024x1024(6) texture.
  120.            font_table.blitmapZ =  blitIntArray( font_table.blitmapZ , 6, blitletter , startx + (n * spaceing),starty, 32 , 32 );
  121.             }
  122.  
  123.          // make texture
  124.          fontTarget.setPixels( font_table.blitmapZ , 0, 1024 , 0, 0, 1024 , 1024 );
  125.            //place font into texture.
  126.          Texture allfonts = new Texture( fontTarget  , true  );
  127.          TextureManager.getInstance().replaceTexture(texID, allfonts );
  128.  
  129.  
  130.  
  131.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement