Giter VIP home page Giter VIP logo

libyuv-for-android's Introduction

libyuv for Android

编译了libyuv

       @Override
            public void run() {
                while (!isInterrupted()) {
                    if (mBuffers.isEmpty()) {
                        SystemClock.sleep(1);
                        continue;
                    }

                    PixelBuffer buffer = mBuffers.remove(0);

    //                long millis = System.currentTimeMillis();
                    byte[] data = buffer.getData();

                    byte[] nv21 = new byte[buffer.getWidth() * buffer.getHeight() * 3 / 2];
                    if (mMediaEncoder != null) {
                        YuvUtil.BGRAToNV21(buffer.getData(),nv21,buffer.getWidth(),buffer.getHeight());
                        mMediaEncoder.encode(nv21);
                        mMediaEncoder.frameAvailableSoon();
                    }
    //                YuvUtil.RGBAToNV21(data,temp, nv21, buffer.getWidth(), buffer.getHeight());
    //                Log.i(TAG, "nv21.length : " + nv21.length + "\t\t time :" + String.valueOf(System.currentTimeMillis() - millis));
    //                YuvImage yuvImage = new YuvImage(nv21, ImageFormat.NV21, buffer.getWidth(), buffer.getHeight(), null);
    //                ByteArrayOutputStream stream = new ByteArrayOutputStream();
    //                yuvImage.compressToJpeg(new Rect(0, 0, buffer.getWidth(), buffer.getHeight()), 80, stream);
    //
    //                Bitmap bmp = BitmapFactory.decodeByteArray(stream.toByteArray(), 0, stream.size());
    //                try {
    //                    stream.close();
    //                } catch (IOException e) {
    //                    e.printStackTrace();
    //                }
    ////                int width = buffer.getWidth();
    ////                int height = buffer.getHeight();
    ////                int pixelStride = buffer.getPixelStride();
    ////                int rowStride = buffer.getRowStride();
    ////
    ////                int size = width * height;
    ////                if (mPixelData == null || size != mPixelData.length) {
    ////                    mPixelData = new int[width * height];
    ////                }
    ////
    ////                int offset = 0;
    ////                int index = 0;
    ////                for (int i = 0; i < height; ++i) {
    ////                    for (int j = 0; j < width; ++j) {
    ////                        int pixel = 0;
    ////                        pixel |= (data[offset] & 0xff) << 16;     // R
    ////                        pixel |= (data[offset + 1] & 0xff) << 8;  // G
    ////                        pixel |= (data[offset + 2] & 0xff);       // B
    ////                        pixel |= (data[offset + 3] & 0xff) << 24; // A
    ////                        mPixelData[index++] = pixel;
    ////                        offset += 4;
    ////                    }
    ////                    offset += rowStride - width * pixelStride;
    ////                }
    ////
    ////                Bitmap bitmap = Bitmap.createBitmap(mPixelData,
    ////                        width, height,
    ////                        Bitmap.Config.ARGB_8888);
    //                sendMessage(obtainMessage(PREVIEW_BITMAP, bmp));


                    mReusableBuffers.add(data);
                }
                mBuffers.clear();
            }


    /**
     * 将 ARGB 8888 格式的像素数据转换为 NV21 格式的数据
     *
     * @param rgbaArray rgbaArray.length =  width * height * 4
     * @param temp      临时存储空间 , 大小应跟 rgbaArray 保持一致
     * @param nv21Array nv21Array.length =  width * height * 3 / 2
     * @param width     width
     * @param height    height
     */
    public static void RGBAToNV21(byte[] rgbaArray, byte[] temp, byte[] nv21Array, int width, int height) {
        RGBAToBGRA(rgbaArray, temp, width, height);
        BGRAToNV21(temp, nv21Array, width, height);
    }

    private static native void RGBAToBGRA(byte[] rgba, byte[] bgra, int width, int height);

    /**
     * 将 BGRA 8888 格式的像素数据转换为 NV21 格式的数据,
     * 从glReadPixes获取的数据直接调用此方法即可
     *
     * @param bgra   bgra.length =  width * height * 4
     * @param yuv    yuv.length =  width * height * 3 / 2
     * @param width  width
     * @param height height
     */
    public static native void BGRAToNV21(byte[] bgra, byte[] yuv, int width, int height);

libyuv-for-android's People

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.