package com.aincc.libtest.activity.flip.internal; import java.nio.ByteBuffer; import java.nio.ByteOrder; import java.nio.FloatBuffer; import java.nio.ShortBuffer; import android.graphics.Bitmap; import android.graphics.Canvas; import android.view.View; /** * * <h3><b>Utils</b></h3></br> * * 플립 유틸리티 * * @author aincc@barusoft.com * @version 1.0.0 * @since 1.0.0 */ public class FlipUtils { /** * 텍스쳐 유효성 체크 * * @since 1.0.0 * @param t * @return boolean */ public static boolean isValidTexture(Texture t) { return t != null && !t.isDestroyed(); } /** * 뷰의 스크린샷 생성 * * @since 1.0.0 * @param view * @return bitmap */ public static Bitmap takeScreenShot(View view) { if (null == view) { return null; } assert view.getWidth() > 0 && view.getHeight() > 0; Bitmap.Config config = Bitmap.Config.ARGB_8888; Bitmap bitmap = null; try { bitmap = Bitmap.createBitmap(view.getWidth(), view.getHeight(), config); Canvas canvas = new Canvas(bitmap); view.draw(canvas); } catch (OutOfMemoryError e) { e.printStackTrace(); } return bitmap; } /** * degree to radian 변환 * * @since 1.0.0 * @param degree * @return the radian */ public static float d2r(float degree) { return degree * (float) Math.PI / 180f; } /** * * @since 1.0.0 * @param v * @return the FloatBuffer */ public static FloatBuffer toFloatBuffer(float[] v) { ByteBuffer buf = ByteBuffer.allocateDirect(v.length * 4); buf.order(ByteOrder.nativeOrder()); FloatBuffer buffer = buf.asFloatBuffer(); buffer.put(v); buffer.position(0); return buffer; } /** * * @since 1.0.0 * @param v * @return the ShortBuffer */ public static ShortBuffer toShortBuffer(short[] v) { ByteBuffer buf = ByteBuffer.allocateDirect(v.length * 2); buf.order(ByteOrder.nativeOrder()); ShortBuffer buffer = buf.asShortBuffer(); buffer.put(v); buffer.position(0); return buffer; } }