Android Open Source - HexNanoController_Android Texture Utils






From Project

Back to project page HexNanoController_Android.

License

The source code is released under:

Code license GNU GPL v2 http://www.gnu.org/licenses/gpl.html Content license CC BY-NC-SA 4.0 http://creativecommons.org/licenses/by-nc-sa/4.0/

If you think the Android project HexNanoController_Android listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

/*
 * TextureUtils/*from w  w w  .  j av a  2 s.  c  om*/
 *
 *  Created on: May 24, 2011
 *      Author: Dmytro Baryskyy
 */


package com.hexairbot.hexmini.util;

import android.content.res.Resources;
import android.graphics.Bitmap;
import android.graphics.Canvas;

public class TextureUtils 
{
  /**
   * Finds greater nearest number that is power of 2
   * @return long
   */
  public static long roundPower2(final long x)
  {
    int rval=256;

    while(rval < x)
      rval <<= 1;

    return rval;
  }
  
  
  /**
   * Makes a texture from any bitmap. 
   * (Texture should have size that is power of 2) 
   * @param bmp bitmap
   * @return BitmapDrawable that has size that is power of 2. Bitmap is not stretched, free space 
   * is filled with default color.
   */
  public static Bitmap makeTexture(Resources res, Bitmap bmp) 
  {
    if (bmp == null) {
      throw new IllegalArgumentException("Bitmap can't be null");
    }
    
    int height = (int) roundPower2(bmp.getHeight());
    int width = (int) roundPower2(bmp.getWidth());
    
    Bitmap result = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
    
    Canvas canvas = new Canvas(result);
    canvas.drawBitmap(bmp, 0, 0, null);
    
    return result;
  }
  
  public static Bitmap makeTexture(Resources res, Bitmap srcBitmap, int destWidth, int destHeight, boolean xRepeated, boolean yRepeated) 
  {
    int xCnt = (destWidth + srcBitmap.getWidth() - 1) / srcBitmap.getWidth();
    int yCnt = (destHeight + srcBitmap.getHeight() - 1) / srcBitmap.getHeight();
    

    int width = destWidth;
    int height = destHeight;
    
    if (!xRepeated) {
      width = srcBitmap.getWidth();
    }

    if (!yRepeated) {
      height = srcBitmap.getHeight();
    }
    
    Bitmap bitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
    
    Canvas canvas = new Canvas(bitmap);
    
    if (xRepeated && yRepeated) {
      for(int xIdx = 0; xIdx < xCnt; ++xIdx){
        for(int yIdx = 0; yIdx < yCnt; ++yIdx){
          canvas.drawBitmap(srcBitmap, xIdx * srcBitmap.getWidth(), yIdx * srcBitmap.getHeight(), null);
        }
      }
    }
    else if(xRepeated && !yRepeated){
      for(int xIdx = 0; xIdx < xCnt; ++xIdx){
        canvas.drawBitmap(srcBitmap, xIdx * srcBitmap.getWidth(), 0, null);
      }
    }
    else if(!xRepeated && yRepeated){
      for(int yIdx = 0; yIdx < yCnt; ++yIdx){
        canvas.drawBitmap(srcBitmap, 0, yIdx * srcBitmap.getHeight(), null);
      }
    }
    else{
      canvas.drawBitmap(srcBitmap, 0, 0, null);
    }

    return bitmap;
  }
}




Java Source Code List

.FileHelper.java
.Input.java
.Output.java
.Serializable.java
com.hexairbot.hexmini.HelpActivity.java
com.hexairbot.hexmini.HexMiniApplication.java
com.hexairbot.hexmini.HudActivity.java
com.hexairbot.hexmini.HudViewControllerDelegate.java
com.hexairbot.hexmini.HudViewController.java
com.hexairbot.hexmini.SettingsDialogDelegate.java
com.hexairbot.hexmini.SettingsDialog.java
com.hexairbot.hexmini.SettingsViewControllerDelegate.java
com.hexairbot.hexmini.SettingsViewController.java
com.hexairbot.hexmini.ViewController.java
com.hexairbot.hexmini.adapter.SettingsViewAdapter.java
com.hexairbot.hexmini.ble.BleConnectinManagerDelegate.java
com.hexairbot.hexmini.ble.BleConnectinManager.java
com.hexairbot.hexmini.ble.BluetoothLeService.java
com.hexairbot.hexmini.gestures.EnhancedGestureDetector.java
com.hexairbot.hexmini.modal.ApplicationSettings.java
com.hexairbot.hexmini.modal.Channel.java
com.hexairbot.hexmini.modal.OSDCommon.java
com.hexairbot.hexmini.modal.Transmitter.java
com.hexairbot.hexmini.sensors.DeviceOrientationChangeDelegate.java
com.hexairbot.hexmini.sensors.DeviceOrientationManager.java
com.hexairbot.hexmini.sensors.DeviceSensorManagerWrapper.java
com.hexairbot.hexmini.sensors.SensorManagerWrapper.java
com.hexairbot.hexmini.services.ConnectStateManager.java
com.hexairbot.hexmini.services.IpcControlService.java
com.hexairbot.hexmini.services.IpcProxy.java
com.hexairbot.hexmini.services.NavData.java
com.hexairbot.hexmini.services.OnIpcConnectChangedListener.java
com.hexairbot.hexmini.services.VIConfig.java
com.hexairbot.hexmini.ui.Button.java
com.hexairbot.hexmini.ui.Image.java
com.hexairbot.hexmini.ui.Indicator.java
com.hexairbot.hexmini.ui.Sprite.java
com.hexairbot.hexmini.ui.Text.java
com.hexairbot.hexmini.ui.ToggleButton.java
com.hexairbot.hexmini.ui.UIRenderer.java
com.hexairbot.hexmini.ui.control.CustomSeekBar.java
com.hexairbot.hexmini.ui.control.ViewPagerIndicator.java
com.hexairbot.hexmini.ui.gl.GLSprite.java
com.hexairbot.hexmini.ui.joystick.AcceleratorJoystick.java
com.hexairbot.hexmini.ui.joystick.AnalogueJoystick.java
com.hexairbot.hexmini.ui.joystick.JoystickBase.java
com.hexairbot.hexmini.ui.joystick.JoystickFactory.java
com.hexairbot.hexmini.ui.joystick.JoystickListener.java
com.hexairbot.hexmini.util.DebugHandler.java
com.hexairbot.hexmini.util.FontUtils.java
com.hexairbot.hexmini.util.SystemUiHiderBase.java
com.hexairbot.hexmini.util.SystemUiHiderHoneycomb.java
com.hexairbot.hexmini.util.SystemUiHider.java
com.hexairbot.hexmini.util.SystemUtil.java
com.hexairbot.hexmini.util.TextureUtils.java
fix.android.opengl.GLES20.java