Android Open Source - FxCameraApp Default Config Chooser






From Project

Back to project page FxCameraApp.

License

The source code is released under:

MIT License

If you think the Android project FxCameraApp 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

package com.af.experiments.FxCameraApp.ogles;
//  w  w  w  .  j a va 2 s  .  c  o m
import android.opengl.GLSurfaceView;
import android.os.Build;

import javax.microedition.khronos.egl.EGL10;
import javax.microedition.khronos.egl.EGLConfig;
import javax.microedition.khronos.egl.EGLDisplay;

import static javax.microedition.khronos.egl.EGL10.*;
public class DefaultConfigChooser implements GLSurfaceView.EGLConfigChooser {

    private final int[] mConfigSpec;
    private final int mRedSize;
    private final int mGreenSize;
    private final int mBlueSize;
    private final int mAlphaSize;
    private final int mDepthSize;
    private final int mStencilSize;

        public DefaultConfigChooser(final int version) {
        this(true, version);
    }

    private static final int JELLY_BEAN_MR1 = 17;

    private static final boolean USE_RGB_888 = Integer.parseInt(Build.VERSION.SDK) >= JELLY_BEAN_MR1;

    public DefaultConfigChooser(final boolean withDepthBuffer, final int version) {
        this(
                USE_RGB_888 ? 8 : 5,
                USE_RGB_888 ? 8 : 6,
                USE_RGB_888 ? 8 : 5,
                0,
                withDepthBuffer ? 16 : 0,
                0,
                version
        );
    }

    public DefaultConfigChooser(
            final int redSize,
            final int greenSize,
            final int blueSize,
            final int alphaSize,
            final int depthSize,
            final int stencilSize,
            final int version) {
        mConfigSpec = filterConfigSpec(new int[]{
                EGL_RED_SIZE, redSize,
                EGL_GREEN_SIZE, greenSize,
                EGL_BLUE_SIZE, blueSize,
                EGL_ALPHA_SIZE, alphaSize,
                EGL_DEPTH_SIZE, depthSize,
                EGL_STENCIL_SIZE, stencilSize,
                EGL_NONE
        }, version);
        mRedSize = redSize;
        mGreenSize = greenSize;
        mBlueSize = blueSize;
        mAlphaSize = alphaSize;
        mDepthSize = depthSize;
        mStencilSize = stencilSize;
    }

    private static final int EGL_OPENGL_ES2_BIT = 4;

    private int[] filterConfigSpec(final int[] configSpec, final int version) {
        if (version != 2) {
            return configSpec;
        }
    /*
     * We know none of the subclasses define EGL_RENDERABLE_TYPE.
     * And we know the configSpec is well formed.
     */
        final int len = configSpec.length;
        final int[] newConfigSpec = new int[len + 2];
        System.arraycopy(configSpec, 0, newConfigSpec, 0, len - 1);
        newConfigSpec[len - 1] = EGL_RENDERABLE_TYPE;
        newConfigSpec[len] = EGL_OPENGL_ES2_BIT;
        newConfigSpec[len + 1] = EGL_NONE;
        return newConfigSpec;
    }

    //////////////////////////////////////////////////////////////////////////

    @Override
    public EGLConfig chooseConfig(final EGL10 egl, final EGLDisplay display) {
        // ?????????????????????????????????????????????????
        final int[] num_config = new int[1];
        if (!egl.eglChooseConfig(display, mConfigSpec, null, 0, num_config)) {
            throw new IllegalArgumentException("eglChooseConfig failed");
        }
        final int config_size = num_config[0];
        if (config_size <= 0) {
            throw new IllegalArgumentException("No configs match configSpec");
        }

        // ?????????????????????
        final EGLConfig[] configs = new EGLConfig[config_size];
        if (!egl.eglChooseConfig(display, mConfigSpec, configs, config_size, num_config)) {
            throw new IllegalArgumentException("eglChooseConfig#2 failed");
        }
        final EGLConfig config = chooseConfig(egl, display, configs);
        if (config == null) {
            throw new IllegalArgumentException("No config chosen");
        }
        return config;
    }

    EGLConfig chooseConfig(final EGL10 egl, final EGLDisplay display, final EGLConfig[] configs) {
        for (final EGLConfig config : configs) {
            final int d = findConfigAttrib(egl, display, config, EGL_DEPTH_SIZE, 0);
            final int s = findConfigAttrib(egl, display, config, EGL_STENCIL_SIZE, 0);
            if ((d >= mDepthSize) && (s >= mStencilSize)) {
                final int r = findConfigAttrib(egl, display, config, EGL_RED_SIZE, 0);
                final int g = findConfigAttrib(egl, display, config, EGL_GREEN_SIZE, 0);
                final int b = findConfigAttrib(egl, display, config, EGL_BLUE_SIZE, 0);
                final int a = findConfigAttrib(egl, display, config, EGL_ALPHA_SIZE, 0);
                if ((r == mRedSize) && (g == mGreenSize) && (b == mBlueSize) && (a == mAlphaSize)) {
                    return config;
                }
            }
        }
        return null;
    }

    private int findConfigAttrib(final EGL10 egl, final EGLDisplay display, final EGLConfig config, final int attribute, final int defaultValue) {
        final int[] value = new int[1];
        if (egl.eglGetConfigAttrib(display, config, attribute, value)) {
            return value[0];
        }
        return defaultValue;
    }
}




Java Source Code List

com.af.experiments.FxCameraApp.FilterAdapter.java
com.af.experiments.FxCameraApp.MyActivity.java
com.af.experiments.FxCameraApp.Utils.BitmapFactoryUtils.java
com.af.experiments.FxCameraApp.Utils.ExifUtils.java
com.af.experiments.FxCameraApp.Utils.Fps.java
com.af.experiments.FxCameraApp.Utils.LogWriter.java
com.af.experiments.FxCameraApp.Utils.OpenGlUtils.java
com.af.experiments.FxCameraApp.View.CameraView.java
com.af.experiments.FxCameraApp.View.DefaultPreview.java
com.af.experiments.FxCameraApp.View.GlPreview.java
com.af.experiments.FxCameraApp.View.PreviewTexture.java
com.af.experiments.FxCameraApp.camera.CameraHelperBase.java
com.af.experiments.FxCameraApp.camera.CameraHelperCupcake.java
com.af.experiments.FxCameraApp.camera.CameraHelperDonut.java
com.af.experiments.FxCameraApp.camera.CameraHelperEclair.java
com.af.experiments.FxCameraApp.camera.CameraHelperFactory.java
com.af.experiments.FxCameraApp.camera.CameraHelperFroyo.java
com.af.experiments.FxCameraApp.camera.CameraHelperGingerbread.java
com.af.experiments.FxCameraApp.camera.CameraHelperHonycomb.java
com.af.experiments.FxCameraApp.camera.CameraHelperICS.java
com.af.experiments.FxCameraApp.camera.CameraHelper.java
com.af.experiments.FxCameraApp.display.DisplayHelperBase.java
com.af.experiments.FxCameraApp.display.DisplayHelperFactory.java
com.af.experiments.FxCameraApp.display.DisplayHelperFroyo.java
com.af.experiments.FxCameraApp.display.DisplayHelperHoneycombMR2.java
com.af.experiments.FxCameraApp.display.DisplayHelperHoneycomb.java
com.af.experiments.FxCameraApp.display.DisplayHelper.java
com.af.experiments.FxCameraApp.ogles.DefaultConfigChooser.java
com.af.experiments.FxCameraApp.ogles.DefaultContextFactory.java
com.af.experiments.FxCameraApp.ogles.DefaultWindowSurfaceFactory.java
com.af.experiments.FxCameraApp.ogles.EGLLogWrapper.java
com.af.experiments.FxCameraApp.ogles.GLES20ConfigChooser.java
com.af.experiments.FxCameraApp.ogles.GLES20ContextFactory.java
com.af.experiments.FxCameraApp.ogles.GlImageBitmapTexture.java
com.af.experiments.FxCameraApp.ogles.GlImageResourceTexture.java
com.af.experiments.FxCameraApp.ogles.GlImageTexture.java
com.af.experiments.FxCameraApp.ogles.GlPreviewTextureFactory.java
com.af.experiments.FxCameraApp.ogles.GlSurfaceTexture.java
com.af.experiments.FxCameraApp.ogles.GlTextureView.java
com.af.experiments.FxCameraApp.ogles.PixelBuffer.java
com.af.experiments.FxCameraApp.ogles.PreviewSurfaceHelperBase.java
com.af.experiments.FxCameraApp.ogles.PreviewSurfaceHelperFactory.java
com.af.experiments.FxCameraApp.ogles.PreviewSurfaceHelper.java
com.af.experiments.FxCameraApp.ogles.Texture.java
com.af.experiments.FxCameraApp.renderer.GLES20FramebufferObject.java
com.af.experiments.FxCameraApp.renderer.GlFrameBufferObjectRenderer.java
com.af.experiments.FxCameraApp.renderer.MainRenderer.java
com.af.experiments.FxCameraApp.shaders.GlBilateralShader.java
com.af.experiments.FxCameraApp.shaders.GlBoxBlurShader.java
com.af.experiments.FxCameraApp.shaders.GlBulgeDistortionShader.java
com.af.experiments.FxCameraApp.shaders.GlCGAColorspaceShader.java
com.af.experiments.FxCameraApp.shaders.GlColorInvertShader.java
com.af.experiments.FxCameraApp.shaders.GlColorMatrixShader.java
com.af.experiments.FxCameraApp.shaders.GlColorPackingShader.java
com.af.experiments.FxCameraApp.shaders.GlConvolutionShader.java
com.af.experiments.FxCameraApp.shaders.GlEmbossShader.java
com.af.experiments.FxCameraApp.shaders.GlFalseColorShader.java
com.af.experiments.FxCameraApp.shaders.GlFastBlurShader.java
com.af.experiments.FxCameraApp.shaders.GlGaussianBlurShader.java
com.af.experiments.FxCameraApp.shaders.GlGlassSphereShader.java
com.af.experiments.FxCameraApp.shaders.GlGrayScaleShader.java
com.af.experiments.FxCameraApp.shaders.GlHarrisCornerDetectionShader.java
com.af.experiments.FxCameraApp.shaders.GlHazeShader.java
com.af.experiments.FxCameraApp.shaders.GlMonochromeShader.java
com.af.experiments.FxCameraApp.shaders.GlNobleCornerDetectionShader.java
com.af.experiments.FxCameraApp.shaders.GlPerlinNoiseShader.java
com.af.experiments.FxCameraApp.shaders.GlPinchDistortionShader.java
com.af.experiments.FxCameraApp.shaders.GlPixellateShader.java
com.af.experiments.FxCameraApp.shaders.GlPolarPixellateShader.java
com.af.experiments.FxCameraApp.shaders.GlPolkaDotShader.java
com.af.experiments.FxCameraApp.shaders.GlPosterizeShader.java
com.af.experiments.FxCameraApp.shaders.GlPreviewShader.java
com.af.experiments.FxCameraApp.shaders.GlSepiaShader.java
com.af.experiments.FxCameraApp.shaders.GlShaderGroup.java
com.af.experiments.FxCameraApp.shaders.GlShader.java
com.af.experiments.FxCameraApp.shaders.GlSharpenShader.java
com.af.experiments.FxCameraApp.shaders.GlShiTomasiFeatureDetectionShader.java
com.af.experiments.FxCameraApp.shaders.GlSobelEdgeDetectionShader.java
com.af.experiments.FxCameraApp.shaders.GlSphereRefractionShader.java
com.af.experiments.FxCameraApp.shaders.GlStretchDistortionShader.java
com.af.experiments.FxCameraApp.shaders.GlThreex3ConvolutionShader.java
com.af.experiments.FxCameraApp.shaders.GlThreex3TextureSamplingShader.java
com.af.experiments.FxCameraApp.shaders.GlToneShader.java
com.af.experiments.FxCameraApp.shaders.GlTwoInputShader.java
com.af.experiments.FxCameraApp.shaders.GlVignetteShader.java
com.af.experiments.FxCameraApp.shaders.GlWeakPixelInclusionShader.java
com.af.experiments.FxCameraApp.shaders.GlWhiteBalanceShader.java
com.af.experiments.FxCameraApp.shaders.GlXRayShader.java
com.af.experiments.FxCameraApp.shaders.GlXYDerivativeShader.java
com.af.experiments.FxCameraApp.shaders.fx.GlLutShader.java