亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频

? 歡迎來(lái)到蟲(chóng)蟲(chóng)下載站! | ?? 資源下載 ?? 資源專輯 ?? 關(guān)于我們
? 蟲(chóng)蟲(chóng)下載站

?? glimage.java

?? OPENGL animation timing tutorial using LWJGL engine.
?? JAVA
字號(hào):
import java.nio.*;
import java.io.*;
import java.awt.*;
import java.awt.image.*;
import java.net.URL;

/**
 * Loads an Image from file, stores pixels as ARGB int array, and RGBA ByteBuffer.
 * An alternate constructor creates a GLImage from a ByteBuffer containing
 * pixel data.
 * <P>
 * Static functions are included to load, flip and convert pixel arrays.
 * <P>
 * napier at potatoland dot org
 */

public class GLImage {
    public static final int SIZE_BYTE = 1;
    int h = 0;
    int w = 0;
    ByteBuffer pixelBuffer = null;   // to store bytes in GL_RGBA format
    int[] pixels = null;
    Image image = null;


    public GLImage() {
    }

    /**
     * Load pixels from an image file.
     * @param imgName
     */
    public GLImage(String imgName)
    {
        loadImage(imgName);
    }

    /**
     * Store pixels passed in a ByteBuffer.
     * @param pixels
     * @param w
     * @param h
     */
    public GLImage(ByteBuffer pixels, int w, int h) {
        this.pixelBuffer = pixels;
        this.pixels = null;
        this.image = null;  // image is not loaded from file
        this.h = h;
        this.w = w;
    }

    /**
     * return true if image has been loaded successfully
     * @return
     */
    public boolean isLoaded()
    {
        return (image != null);
    }

    /**
     * Flip the image pixels vertically
     */
    public void flipPixels()
    {
        pixels = GLImage.flipPixels(pixels, w, h);
    }

    /**
     * Load an image file and hold its width/height.
     * @param imgName
     */
    public void loadImage(String imgName) {
        Image tmpi = loadImageFromFile(imgName);
        if (tmpi != null) {
            w = tmpi.getWidth(null);
            h = tmpi.getHeight(null);
            image = tmpi;
            pixels = getImagePixels();  // pixels in default Java ARGB format
            pixelBuffer = convertImagePixels(pixels,w,h,true);  // convert to RGBA bytes
            System.out.println("GLImage: loaded " + imgName + ", width=" + w + " height=" + h);
        }
        else {
            System.out.println("GLImage: FAILED TO LOAD IMAGE " + imgName);
            image = null;
            pixels = null;
            pixelBuffer = null;
            h = w = 0;
        }
    }

    /**
     * Return the image pixels in default Java int ARGB format.
     * @return
     */
    public int[] getImagePixels()
    {
        if (pixels == null && image != null) {
            pixels = new int[w * h];
            PixelGrabber pg = new PixelGrabber(image, 0, 0, w, h, pixels, 0, w);
            try {
                pg.grabPixels();
            }
            catch (Exception e) {
                System.out.println("Pixel Grabbing interrupted!");
                return null;
            }
        }
        return pixels;
    }

    /**
     * return int array containing pixels in ARGB format (default Java byte order).
     */
    public int[] getPixelsARGB()
    {
        return pixels;
    }

    /**
     * return ByteBuffer containing pixels in RGBA format (commmonly used in OpenGL).
     */
    public ByteBuffer getPixelsRGBA()
    {
        return pixelBuffer;
    }

    //========================================================================
    //
    // Utility functions to prepare pixels for use in OpenGL
    //
    //========================================================================

    /**
     * Flip an array of pixels vertically
     * @param imgPixels
     * @param imgw
     * @param imgh
     * @return int[]
     */
    public static int[] flipPixels(int[] imgPixels, int imgw, int imgh)
    {
        int[] flippedPixels = null;
        if (imgPixels != null) {
            flippedPixels = new int[imgw * imgh];
            for (int y = 0; y < imgh; y++) {
                for (int x = 0; x < imgw; x++) {
                    flippedPixels[ ( (imgh - y - 1) * imgw) + x] = imgPixels[ (y * imgw) + x];
                }
            }
        }
        return flippedPixels;
    }

    /**
     * Convert ARGB pixels to a ByteBuffer containing RGBA pixels.<BR>
     * Can be drawn in ORTHO mode using:<BR>
     *         GL.glDrawPixels(imgW, imgH, GL.GL_RGBA, GL.GL_UNSIGNED_BYTE, byteBuffer); <BR>
     * If flipVertically is true, pixels will be flipped vertically (for OpenGL coord system).
     * @param imgFilename
     * @return ByteBuffer
     */
    public static ByteBuffer convertImagePixels(int[] jpixels, int imgw, int imgh, boolean flipVertically) {
        byte[] bytes;     // will hold pixels as RGBA bytes
        if (flipVertically) {
            jpixels = flipPixels(jpixels, imgw, imgh); // flip Y axis
        }
        bytes = convertARGBtoRGBA(jpixels);
        return allocBytes(bytes);  // convert to ByteBuffer and return
    }

    /**
     * Convert pixels from java default ARGB int format to byte array in RGBA format.
     * @param jpixels
     * @return
     */
    public static byte[] convertARGBtoRGBA(int[] jpixels)
    {
        byte[] bytes = new byte[jpixels.length*4];  // will hold pixels as RGBA bytes
        int p, r, g, b, a;
        int j=0;
        for (int i = 0; i < jpixels.length; i++) {
            int outPixel = 0x00000000; // AARRGGBB
            p = jpixels[i];
            a = (p >> 24) & 0xFF;  // get pixel bytes in ARGB order
            r = (p >> 16) & 0xFF;
            g = (p >> 8) & 0xFF;
            b = (p >> 0) & 0xFF;
            bytes[j+0] = (byte)r;  // fill in bytes in RGBA order
            bytes[j+1] = (byte)g;
            bytes[j+2] = (byte)b;
            bytes[j+3] = (byte)a;
            j += 4;
        }
        return bytes;
    }


    //========================================================================
    // Utility functions to load file into byte array
    // and create Image from bytes.
    //========================================================================

    /**
     * Same function as in GLApp.java.  Allocates a ByteBuffer to hold the given
     * array of bytes.
     *
     * @param bytearray
     * @return  ByteBuffer containing the contents of the byte array
     */
    public static ByteBuffer allocBytes(byte[] bytearray) {
        ByteBuffer bb = ByteBuffer.allocateDirect(bytearray.length * SIZE_BYTE).order(ByteOrder.nativeOrder());
        bb.put(bytearray).flip();
        return bb;
    }

    /**
     * Load an image from file.  Avoids the flaky MediaTracker/ImageObserver headache.
     * Assumes that the file can be loaded quickly from the local filesystem, so
     * does not need to wait in a thread.  If it can't find the file in the
     * filesystem, will try loading from jar file.  If not found will return
     * null.
     * <P>
     * @param imgName
     */
    public static Image loadImageFromFile(String imgName) {
        byte[] imageBytes = getBytesFromFile(imgName);
        Image tmpi = null;
        int numTries = 20;
        if (imageBytes == null) {
            // couldn't read image from file: try JAR file
            //URL url = getClass().getResource(filename);   // for non-static class
            URL url = GLImage.class.getResource(imgName);
            if (url != null) {
                // found image in jar: load it
                tmpi = Toolkit.getDefaultToolkit().createImage(url);
                // Wait up to two seconds to load image
                int wait = 200;
                while (tmpi.getHeight(null) < 0 && wait-- > 0) {
                    try {
                        Thread.sleep(10);
                    }
                    catch (Exception e) {}
                }
            }
        }
        else {
            tmpi = Toolkit.getDefaultToolkit().createImage(imageBytes, 0, imageBytes.length);
            while (tmpi.getWidth(null) < 0 && numTries-- > 0) {
                try { Thread.sleep(100); }
                catch( InterruptedException e ) {System.out.println(e);}
            }
            while (tmpi.getHeight(null) < 0 && numTries-- > 0) {
                try { Thread.sleep(100); }
                catch( InterruptedException e ) {System.out.println(e);}
            }
        }
        return tmpi;
    }

    public static Image loadImageFromFile_ORIG(String imgName) {
        byte[] imageBytes = getBytesFromFile(imgName);
        Image tmpi = null;
        int numTries = 20;
        if (imageBytes != null) {
            tmpi = Toolkit.getDefaultToolkit().createImage(imageBytes, 0, imageBytes.length);
            while (tmpi.getWidth(null) < 0 && numTries-- > 0) {
                try { Thread.sleep(100); }
                catch( InterruptedException e ) {System.out.println(e);}
            }
            while (tmpi.getHeight(null) < 0 && numTries-- > 0) {
                try { Thread.sleep(100); }
                catch( InterruptedException e ) {System.out.println(e);}
            }
        }
        return tmpi;
    }

    /**
     * Given name of file, return entire file as a byte array.
     * @param filename
     * @return
     */
    public static byte[] getBytesFromFile(String filename)
    {
        File f = new File(filename);
        byte[] bytes = null;
        if (f.exists()) {
            try {
                bytes = getBytesFromFile(f);
            }
            catch (Exception e) {
                System.out.println("getBytesFromFile() exception: " + e);
            }
        }
        return bytes;
    }

    /**
     * Given File object, returns the contents of the file as a byte array.
     */
    public static byte[] getBytesFromFile(File file) throws IOException {
        byte[] bytes = null;
        if (file != null) {
            InputStream is = new FileInputStream(file);
            long length = file.length();
            // Can't create an array using a long type.
            // Before converting to an int type, check
            // to ensure that file is not larger than Integer.MAX_VALUE.
            if (length > Integer.MAX_VALUE) {
                System.out.println("getBytesFromFile() error: File " + file.getName()+ " is too large");
            }
            else {
                // Create the byte array to hold the data
                bytes = new byte[ (int) length];
                int offset = 0;
                int numRead = 0;
                // Read in the bytes
                while (offset < bytes.length
                       && (numRead = is.read(bytes, offset, bytes.length - offset)) >= 0) {
                    offset += numRead;
                }
                // Ensure all the bytes have been read in
                if (offset < bytes.length) {
                    throw new IOException("getBytesFromFile() error: Could not completely read file " + file.getName());
                }
            }
            // Close the input stream and return bytes
            is.close();
        }
        return bytes;
    }

}

?? 快捷鍵說(shuō)明

復(fù)制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號(hào) Ctrl + =
減小字號(hào) Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
亚洲国产精品99久久久久久久久| 久久久精品免费免费| 精品伊人久久久久7777人| 中文字幕一区二区三区蜜月| 色婷婷综合五月| 国产精品一二三区在线| 日韩和欧美的一区| 国产精品久久久久久户外露出| 欧美顶级少妇做爰| 一本色道亚洲精品aⅴ| 国产一区久久久| 三级亚洲高清视频| 一区二区三区高清在线| 国产日韩欧美激情| 精品少妇一区二区三区在线播放| 欧美影院一区二区三区| 成人av网站免费观看| 激情六月婷婷综合| 麻豆成人综合网| 亚洲成人高清在线| 一区二区三区精品在线| 中文字幕制服丝袜成人av| 久久久久久久精| 日韩欧美精品三级| 欧美一区二区精品在线| 欧美午夜片在线看| 91九色最新地址| 97精品电影院| 成a人片亚洲日本久久| 国产电影一区在线| 国产在线播放一区三区四| 麻豆成人久久精品二区三区小说| 视频一区视频二区中文| 亚洲午夜在线观看视频在线| 一区二区三区在线视频播放 | 欧美怡红院视频| 91碰在线视频| 99久久99久久免费精品蜜臀| 成人福利视频在线| 成人h版在线观看| eeuss影院一区二区三区| 丁香激情综合国产| 丁香婷婷综合色啪| 99久久精品免费| 91麻豆精品视频| 欧美亚洲一区二区在线| 欧美色视频在线观看| 欧美日韩在线三区| 91精品在线免费| 日韩精品在线看片z| 日韩欧美一区二区视频| 日韩无一区二区| 久久久久免费观看| 中文字幕不卡的av| 亚洲欧美日韩国产一区二区三区| 一区二区三区中文字幕精品精品| 亚洲与欧洲av电影| 日韩av不卡一区二区| 另类小说欧美激情| 国产成人av一区二区| 成av人片一区二区| 欧美日韩五月天| 欧美videossexotv100| 国产欧美中文在线| 亚洲免费观看高清完整| 日韩极品在线观看| 国产成人综合网站| 91免费国产在线| 在线播放亚洲一区| 久久精品一区八戒影视| 亚洲日韩欧美一区二区在线| 性做久久久久久| 国产一区不卡精品| 在线视频亚洲一区| 精品久久久久久亚洲综合网| 国产精品天天摸av网| 亚洲一区二区四区蜜桃| 麻豆91精品91久久久的内涵| 波多野结衣欧美| 欧美精品日韩精品| 国产拍欧美日韩视频二区| 一个色综合网站| 国产美女av一区二区三区| 91麻豆福利精品推荐| 欧美一级电影网站| 亚洲少妇30p| 久久电影网站中文字幕| 91原创在线视频| 欧美va亚洲va国产综合| 中文字幕字幕中文在线中不卡视频| 日韩精品一二三区| 99久久精品一区| 精品人在线二区三区| 亚洲精品高清在线| 国产精品99久久久久久宅男| 欧美色视频在线| 国产精品精品国产色婷婷| 蜜臀av一区二区在线免费观看 | 9久草视频在线视频精品| 中文字幕亚洲一区二区va在线| 一区二区三区免费看视频| 国产精品一区二区三区乱码| 欧美日韩国产首页在线观看| 国产精品私人自拍| 久久成人麻豆午夜电影| 欧美午夜精品免费| 国产精品免费丝袜| 九九九久久久精品| 欧美精品丝袜久久久中文字幕| 成人欧美一区二区三区| 国产一区二区在线观看视频| 91精品国产综合久久久久久漫画| 日韩理论片中文av| 国产成人精品三级麻豆| 欧美精品一区二区三区一线天视频| 亚洲自拍另类综合| 91麻豆精品一区二区三区| 国产精品沙发午睡系列990531| 另类小说综合欧美亚洲| 欧美情侣在线播放| 亚洲综合激情网| 色又黄又爽网站www久久| 国产精品青草久久| 国产69精品久久99不卡| 久久人人爽爽爽人久久久| 久久99久久精品| 欧美一区二区三级| 奇米777欧美一区二区| 欧美日韩欧美一区二区| 一区二区三区精品在线| 91福利在线播放| 一区二区三区在线免费| 日本电影亚洲天堂一区| 亚洲欧美日韩一区二区| 色视频一区二区| 一区二区三区中文字幕| 91国偷自产一区二区开放时间 | 欧美酷刑日本凌虐凌虐| 亚洲成人免费在线观看| 欧美性色aⅴ视频一区日韩精品| 亚洲欧美另类图片小说| 91视频在线看| 亚洲午夜免费福利视频| 欧美日本精品一区二区三区| 同产精品九九九| 日韩欧美在线影院| 激情深爱一区二区| 国产精品视频第一区| 一本久道中文字幕精品亚洲嫩| 亚洲激情一二三区| 欧美美女喷水视频| 裸体在线国模精品偷拍| 国产网站一区二区| www..com久久爱| 亚洲国产视频直播| 日韩一区二区免费在线电影| 激情成人综合网| 国产精品久久久久一区二区三区| 94-欧美-setu| 亚瑟在线精品视频| 精品国产乱码久久| av电影在线不卡| 亚洲第一搞黄网站| 欧美成人aa大片| 白白色 亚洲乱淫| 亚洲一区欧美一区| 日韩精品一区二区在线观看| 国产成人精品1024| 亚洲一区二区精品3399| 日韩视频在线你懂得| 国产成人欧美日韩在线电影| 亚洲日本免费电影| 欧美一区二区三区四区在线观看 | 蜜桃一区二区三区在线观看| 久久麻豆一区二区| 日本乱人伦一区| 日韩电影在线一区二区三区| 久久久综合视频| 国产偷国产偷精品高清尤物| 欧美中文字幕不卡| 国产一二三精品| 亚洲一区二区三区四区五区中文| 欧美成人精品1314www| 黄网站免费久久| 成人午夜av影视| 国产精品99久| 欧美变态凌虐bdsm| 国产日产欧产精品推荐色 | 在线视频你懂得一区| 日韩一级免费观看| 中文字幕中文字幕在线一区| 亚洲国产综合人成综合网站| 极品少妇一区二区| 91久久人澡人人添人人爽欧美| 正在播放亚洲一区| 亚洲日本va午夜在线电影| 捆绑变态av一区二区三区| 色综合婷婷久久| 一区二区三区欧美在线观看| 久久成人av少妇免费|