├── .gitignore
├── .idea
├── gradle.xml
├── misc.xml
├── modules.xml
└── runConfigurations.xml
├── app
├── .gitignore
├── build.gradle
├── proguard-rules.pro
└── src
│ ├── androidTest
│ └── java
│ │ └── com
│ │ └── hyq
│ │ └── hm
│ │ └── videotoimage
│ │ └── ExampleInstrumentedTest.java
│ ├── main
│ ├── AndroidManifest.xml
│ ├── java
│ │ └── com
│ │ │ └── hyq
│ │ │ └── hm
│ │ │ └── videotoimage
│ │ │ ├── EGLUtils.java
│ │ │ ├── GLBitmap.java
│ │ │ ├── GLRenderer.java
│ │ │ ├── MainActivity.java
│ │ │ └── ShaderUtils.java
│ └── res
│ │ ├── drawable-v24
│ │ └── ic_launcher_foreground.xml
│ │ ├── drawable
│ │ ├── ic_jn.jpg
│ │ └── ic_launcher_background.xml
│ │ ├── layout
│ │ └── activity_main.xml
│ │ ├── mipmap-anydpi-v26
│ │ ├── ic_launcher.xml
│ │ └── ic_launcher_round.xml
│ │ ├── mipmap-hdpi
│ │ ├── ic_launcher.png
│ │ └── ic_launcher_round.png
│ │ ├── mipmap-mdpi
│ │ ├── ic_launcher.png
│ │ └── ic_launcher_round.png
│ │ ├── mipmap-xhdpi
│ │ ├── ic_launcher.png
│ │ └── ic_launcher_round.png
│ │ ├── mipmap-xxhdpi
│ │ ├── ic_launcher.png
│ │ └── ic_launcher_round.png
│ │ ├── mipmap-xxxhdpi
│ │ ├── ic_launcher.png
│ │ └── ic_launcher_round.png
│ │ └── values
│ │ ├── colors.xml
│ │ ├── strings.xml
│ │ └── styles.xml
│ └── test
│ └── java
│ └── com
│ └── hyq
│ └── hm
│ └── videotoimage
│ └── ExampleUnitTest.java
├── build.gradle
├── gradle.properties
├── gradle
└── wrapper
│ ├── gradle-wrapper.jar
│ └── gradle-wrapper.properties
├── gradlew
├── gradlew.bat
└── settings.gradle
/.gitignore:
--------------------------------------------------------------------------------
1 | *.iml
2 | .gradle
3 | /local.properties
4 | /.idea/workspace.xml
5 | /.idea/libraries
6 | .DS_Store
7 | /build
8 | /captures
9 | .externalNativeBuild
10 |
--------------------------------------------------------------------------------
/.idea/gradle.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
17 |
18 |
--------------------------------------------------------------------------------
/.idea/misc.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
--------------------------------------------------------------------------------
/.idea/modules.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/.idea/runConfigurations.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/app/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/app/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.application'
2 |
3 | android {
4 | compileSdkVersion 26
5 | defaultConfig {
6 | applicationId "com.hyq.hm.videotoimage"
7 | minSdkVersion 21
8 | targetSdkVersion 26
9 | versionCode 1
10 | versionName "1.0"
11 | testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
12 | }
13 | buildTypes {
14 | release {
15 | minifyEnabled false
16 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
17 | }
18 | }
19 | }
20 |
21 | dependencies {
22 | implementation fileTree(dir: 'libs', include: ['*.jar'])
23 | implementation 'com.android.support:appcompat-v7:26.1.0'
24 | implementation 'com.android.support.constraint:constraint-layout:1.1.3'
25 | testImplementation 'junit:junit:4.12'
26 | androidTestImplementation 'com.android.support.test:runner:1.0.2'
27 | androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
28 | }
29 |
--------------------------------------------------------------------------------
/app/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # You can control the set of applied configuration files using the
3 | # proguardFiles setting in build.gradle.
4 | #
5 | # For more details, see
6 | # http://developer.android.com/guide/developing/tools/proguard.html
7 |
8 | # If your project uses WebView with JS, uncomment the following
9 | # and specify the fully qualified class name to the JavaScript interface
10 | # class:
11 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
12 | # public *;
13 | #}
14 |
15 | # Uncomment this to preserve the line number information for
16 | # debugging stack traces.
17 | #-keepattributes SourceFile,LineNumberTable
18 |
19 | # If you keep the line number information, uncomment this to
20 | # hide the original source file name.
21 | #-renamesourcefileattribute SourceFile
22 |
--------------------------------------------------------------------------------
/app/src/androidTest/java/com/hyq/hm/videotoimage/ExampleInstrumentedTest.java:
--------------------------------------------------------------------------------
1 | package com.hyq.hm.videotoimage;
2 |
3 | import android.content.Context;
4 | import android.support.test.InstrumentationRegistry;
5 | import android.support.test.runner.AndroidJUnit4;
6 |
7 | import org.junit.Test;
8 | import org.junit.runner.RunWith;
9 |
10 | import static org.junit.Assert.*;
11 |
12 | /**
13 | * Instrumented test, which will execute on an Android device.
14 | *
15 | * @see Testing documentation
16 | */
17 | @RunWith(AndroidJUnit4.class)
18 | public class ExampleInstrumentedTest {
19 | @Test
20 | public void useAppContext() throws Exception {
21 | // Context of the app under test.
22 | Context appContext = InstrumentationRegistry.getTargetContext();
23 |
24 | assertEquals("com.hyq.hm.videotoimage", appContext.getPackageName());
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/app/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
--------------------------------------------------------------------------------
/app/src/main/java/com/hyq/hm/videotoimage/EGLUtils.java:
--------------------------------------------------------------------------------
1 | package com.hyq.hm.videotoimage;
2 |
3 | import android.opengl.EGL14;
4 | import android.opengl.EGLConfig;
5 | import android.opengl.EGLContext;
6 | import android.opengl.EGLDisplay;
7 | import android.opengl.EGLSurface;
8 | import android.view.Surface;
9 |
10 |
11 | /**
12 | * Created by 海米 on 2017/8/15.
13 | */
14 |
15 | public class EGLUtils {
16 |
17 | private static final int EGL_RECORDABLE_ANDROID = 0x3142;
18 |
19 | private EGLSurface eglSurface = EGL14.EGL_NO_SURFACE;
20 | private EGLContext eglCtx = EGL14.EGL_NO_CONTEXT;
21 | private EGLDisplay eglDis = EGL14.EGL_NO_DISPLAY;
22 |
23 |
24 | public void initEGL(Surface surface,EGLContext eglContext) {
25 | eglDis = EGL14.eglGetDisplay(EGL14.EGL_DEFAULT_DISPLAY);
26 | int[] version = new int[2];
27 | EGL14.eglInitialize(eglDis, version, 0, version, 1);
28 | int confAttr[] = {
29 | EGL14.EGL_RED_SIZE, 8,
30 | EGL14.EGL_GREEN_SIZE, 8,
31 | EGL14.EGL_BLUE_SIZE, 8,
32 | EGL14.EGL_ALPHA_SIZE, 8,
33 | EGL14.EGL_RENDERABLE_TYPE, EGL14.EGL_OPENGL_ES2_BIT,
34 | EGL14.EGL_SURFACE_TYPE, EGL14.EGL_WINDOW_BIT,
35 | EGL_RECORDABLE_ANDROID, 1,
36 | EGL14.EGL_NONE
37 | };
38 | EGLConfig[] configs = new EGLConfig[1];
39 | int[] numConfigs = new int[1];
40 | EGL14.eglChooseConfig(eglDis, confAttr, 0, configs, 0, 1, numConfigs, 0);
41 | int ctxAttr[] = {
42 | EGL14.EGL_CONTEXT_CLIENT_VERSION, 2,// 0x3098
43 | EGL14.EGL_NONE
44 | };
45 | eglCtx = EGL14.eglCreateContext(eglDis, configs[0], eglContext, ctxAttr, 0);
46 | int[] surfaceAttr = {
47 | EGL14.EGL_NONE
48 | };
49 | eglSurface = EGL14.eglCreateWindowSurface(eglDis, configs[0], surface, surfaceAttr, 0);
50 |
51 | EGL14.eglMakeCurrent(eglDis, eglSurface, eglSurface, eglCtx);
52 |
53 | }
54 |
55 | public EGLContext getContext() {
56 | return eglCtx;
57 | }
58 |
59 | public void swap() {
60 | EGL14.eglSwapBuffers(eglDis, eglSurface);
61 | }
62 |
63 | public void release() {
64 | if (eglSurface != EGL14.EGL_NO_SURFACE) {
65 | EGL14.eglMakeCurrent(eglDis, EGL14.EGL_NO_SURFACE, EGL14.EGL_NO_SURFACE, EGL14.EGL_NO_CONTEXT);
66 | EGL14.eglDestroySurface(eglDis, eglSurface);
67 | eglSurface = EGL14.EGL_NO_SURFACE;
68 | }
69 | if (eglCtx != EGL14.EGL_NO_CONTEXT) {
70 | EGL14.eglDestroyContext(eglDis, eglCtx);
71 | eglCtx = EGL14.EGL_NO_CONTEXT;
72 | }
73 | if (eglDis != EGL14.EGL_NO_DISPLAY) {
74 | EGL14.eglTerminate(eglDis);
75 | eglDis = EGL14.EGL_NO_DISPLAY;
76 | }
77 | }
78 | }
79 |
--------------------------------------------------------------------------------
/app/src/main/java/com/hyq/hm/videotoimage/GLBitmap.java:
--------------------------------------------------------------------------------
1 | package com.hyq.hm.videotoimage;
2 |
3 | import android.content.Context;
4 | import android.graphics.Bitmap;
5 | import android.graphics.BitmapFactory;
6 | import android.graphics.Rect;
7 | import android.opengl.GLES30;
8 | import android.opengl.GLES30;
9 | import android.opengl.GLUtils;
10 | import android.opengl.Matrix;
11 |
12 | import java.nio.ByteBuffer;
13 | import java.nio.ByteOrder;
14 | import java.nio.FloatBuffer;
15 |
16 | /**
17 | * Created by 海米 on 2018/10/25.
18 | */
19 |
20 | public class GLBitmap {
21 |
22 | private int aPositionHandle;
23 | private int uMatrixHandle;
24 | private int uTextureSamplerHandle;
25 | private int aTextureCoordHandle;
26 | private int programId;
27 | private int[] textures = new int[2];
28 |
29 | private int[] frameBuffers = new int[2];
30 | private int[] frameColors = new int[1];
31 |
32 | private FloatBuffer vertexBuffer;
33 | private FloatBuffer textureVertexBuffer;
34 | private final float[] modelMatrix=new float[16];
35 | private final float[] projectionMatrix= new float[16];
36 | private final float[] viewMatrix = new float[16];
37 | private Bitmap bitmap;
38 |
39 | private int frameWidth,frameHeight;
40 |
41 | public GLBitmap(Context context, int id){
42 | scale = context.getResources().getDisplayMetrics().density;
43 | float[] vertexData = {
44 | 1f, -1f,0,
45 | -1f, -1f,0,
46 | 1f, 1f,0,
47 | -1f, 1f,0
48 | };
49 | vertexBuffer = ByteBuffer.allocateDirect(vertexData.length * 4)
50 | .order(ByteOrder.nativeOrder())
51 | .asFloatBuffer()
52 | .put(vertexData);
53 | vertexBuffer.position(0);
54 | float[] textureVertexData = {
55 | 1f, 0f,//右下
56 | 0f, 0f,//左下
57 | 1f, 1f,//右上
58 | 0f, 1f//左上
59 | };
60 | textureVertexBuffer = ByteBuffer.allocateDirect(textureVertexData.length * 4)
61 | .order(ByteOrder.nativeOrder())
62 | .asFloatBuffer()
63 | .put(textureVertexData);
64 | textureVertexBuffer.position(0);
65 | bitmap = BitmapFactory.decodeResource(context.getResources(),id);
66 | frameWidth = bitmap.getWidth();
67 | frameHeight = bitmap.getHeight();
68 | }
69 |
70 | public void surfaceCreated(){
71 | String vertexShader = "attribute vec4 aPosition;\n" +
72 | "attribute vec2 aTexCoord;\n" +
73 | "varying vec2 vTexCoord;\n" +
74 | "uniform mat4 uMatrix;\n" +
75 | "void main() {\n" +
76 | " vTexCoord=aTexCoord;\n" +
77 | " gl_Position = uMatrix*aPosition;\n" +
78 | "}";
79 | String fragmentShader = "precision mediump float;\n" +
80 | "varying vec2 vTexCoord;\n" +
81 | "uniform sampler2D sTexture;\n" +
82 | "void main() {\n" +
83 | " gl_FragColor = texture2D(sTexture,vTexCoord);\n" +
84 | "}";
85 | programId = ShaderUtils.createProgram(vertexShader, fragmentShader);
86 | aPositionHandle = GLES30.glGetAttribLocation(programId, "aPosition");
87 | uMatrixHandle=GLES30.glGetUniformLocation(programId,"uMatrix");
88 | uTextureSamplerHandle=GLES30.glGetUniformLocation(programId,"sTexture");
89 | aTextureCoordHandle=GLES30.glGetAttribLocation(programId,"aTexCoord");
90 |
91 |
92 |
93 | GLES30.glGenTextures(2,textures,0);
94 | GLES30.glBindTexture(GLES30.GL_TEXTURE_2D,textures[0]);
95 | GLES30.glTexParameteri(GLES30.GL_TEXTURE_2D,GLES30.GL_TEXTURE_MIN_FILTER,GLES30.GL_LINEAR);
96 | GLES30.glTexParameteri(GLES30.GL_TEXTURE_2D,GLES30.GL_TEXTURE_MAG_FILTER, GLES30.GL_LINEAR);
97 | GLES30.glTexParameteri(GLES30.GL_TEXTURE_2D, GLES30.GL_TEXTURE_WRAP_S, GLES30.GL_CLAMP_TO_EDGE);
98 | GLES30.glTexParameteri(GLES30.GL_TEXTURE_2D, GLES30.GL_TEXTURE_WRAP_T, GLES30.GL_CLAMP_TO_EDGE);
99 | GLUtils.texImage2D(GLES30.GL_TEXTURE_2D,0,GLES30.GL_RGBA,bitmap,0);
100 |
101 | GLES30.glBindTexture(GLES30.GL_TEXTURE_2D,textures[1]);
102 | GLES30.glTexParameteri(GLES30.GL_TEXTURE_2D,GLES30.GL_TEXTURE_MIN_FILTER,GLES30.GL_LINEAR);
103 | GLES30.glTexParameteri(GLES30.GL_TEXTURE_2D,GLES30.GL_TEXTURE_MAG_FILTER, GLES30.GL_LINEAR);
104 | GLES30.glTexParameteri(GLES30.GL_TEXTURE_2D, GLES30.GL_TEXTURE_WRAP_S, GLES30.GL_CLAMP_TO_EDGE);
105 | GLES30.glTexParameteri(GLES30.GL_TEXTURE_2D, GLES30.GL_TEXTURE_WRAP_T, GLES30.GL_CLAMP_TO_EDGE);
106 | GLES30.glTexImage2D(GLES30.GL_TEXTURE_2D, 0, GLES30.GL_RGBA, frameWidth, frameHeight, 0, GLES30.GL_RGBA, GLES30.GL_UNSIGNED_BYTE, null);
107 | GLES30.glBindTexture(GLES30.GL_TEXTURE_2D,0);
108 |
109 |
110 | GLES30.glGenRenderbuffers(1, frameColors, 0);
111 | GLES30.glBindRenderbuffer(GLES30.GL_RENDERBUFFER, frameColors[0]);
112 | GLES30.glRenderbufferStorageMultisample(GLES30.GL_RENDERBUFFER,4,GLES30.GL_RGBA8, frameWidth, frameHeight);
113 | GLES30.glBindRenderbuffer(GLES30.GL_RENDERBUFFER, 0);
114 |
115 | GLES30.glGenFramebuffers(2, frameBuffers,0);
116 | GLES30.glBindFramebuffer(GLES30.GL_FRAMEBUFFER, frameBuffers[0]);
117 | GLES30.glFramebufferRenderbuffer(GLES30.GL_FRAMEBUFFER, GLES30.GL_COLOR_ATTACHMENT0,GLES30.GL_RENDERBUFFER, frameColors[0]);
118 | GLES30.glBindFramebuffer(GLES30.GL_FRAMEBUFFER, frameBuffers[1]);
119 | GLES30.glFramebufferTexture2D(GLES30.GL_FRAMEBUFFER, GLES30.GL_COLOR_ATTACHMENT0, GLES30.GL_TEXTURE_2D, textures[1], 0);
120 | GLES30.glBindFramebuffer(GLES30.GL_FRAMEBUFFER, 0);
121 |
122 | GLES30.glUseProgram(programId);
123 | GLES30.glEnableVertexAttribArray(aPositionHandle);
124 | GLES30.glVertexAttribPointer(aPositionHandle, 2, GLES30.GL_FLOAT, false,
125 | 12, vertexBuffer);
126 | GLES30.glEnableVertexAttribArray(aTextureCoordHandle);
127 | GLES30.glVertexAttribPointer(aTextureCoordHandle,2,GLES30.GL_FLOAT,false,8,textureVertexBuffer);
128 | GLES30.glUseProgram(0);
129 |
130 | Matrix.perspectiveM(projectionMatrix, 0, 90f, 1, 1, 50);
131 | Matrix.setLookAtM(viewMatrix, 0,
132 | 0.0f, 0.0f, 2.0f,
133 | 0.0f, 0.0f,0.0f,
134 | 0.0f, -1.0f, 0.0f);
135 |
136 | int w = (int) (frameWidth*s);
137 | int f = (w - frameWidth)/2;
138 | rect.set(-f,0,w,frameHeight);
139 | }
140 |
141 | public void surfaceDestroyed(){
142 | GLES30.glDeleteProgram(programId);
143 | GLES30.glDeleteTextures(2,textures,0);
144 | GLES30.glDeleteRenderbuffers(1, frameColors, 0);
145 | GLES30.glDeleteFramebuffers(2,frameBuffers,0);
146 | }
147 |
148 | public int getTextureId() {
149 | return textures[1];
150 | }
151 |
152 | private int radian = 0;
153 |
154 | public void setRadian(int radian) {
155 | this.radian = radian;
156 | }
157 |
158 | private Rect rect = new Rect();
159 | private float scale = 1;
160 | private float s = 1.7f;
161 |
162 | public int getWidth(){
163 | return bitmap.getWidth();
164 | }
165 | public int getHeight(){
166 | return bitmap.getHeight();
167 | }
168 |
169 | void surfaceDraw(){
170 |
171 | Matrix.multiplyMM(modelMatrix, 0, projectionMatrix, 0, viewMatrix, 0);
172 | if(radian > 90){
173 | Matrix.rotateM(modelMatrix,0,radian - 180,0,-1,0);
174 | }else{
175 | Matrix.rotateM(modelMatrix,0,radian,0,-1,0);
176 | }
177 | Matrix.scaleM(modelMatrix,0,1.0f,s,1f);
178 |
179 | modelMatrix[3] = modelMatrix[3]/scale;
180 | modelMatrix[7] = modelMatrix[7]/scale;
181 | GLES30.glBindFramebuffer(GLES30.GL_FRAMEBUFFER, frameBuffers[0]);
182 | GLES30.glClearColor(1.0f,0.0f,0.0f,1.0f);
183 | GLES30.glClear(GLES30.GL_DEPTH_BUFFER_BIT | GLES30.GL_COLOR_BUFFER_BIT);
184 | GLES30.glViewport(rect.left, rect.top, rect.right, rect.bottom);
185 | GLES30.glUseProgram(programId);
186 | GLES30.glUniformMatrix4fv(uMatrixHandle,1,false,modelMatrix,0);
187 | GLES30.glActiveTexture(GLES30.GL_TEXTURE0);
188 | GLES30.glBindTexture(GLES30.GL_TEXTURE_2D,textures[0]);
189 | GLES30.glUniform1i(uTextureSamplerHandle,0);
190 | GLES30.glDrawArrays(GLES30.GL_TRIANGLE_STRIP, 0, 4);
191 |
192 | GLES30.glBindFramebuffer(GLES30.GL_DRAW_FRAMEBUFFER, frameBuffers[1]);
193 | GLES30.glBindFramebuffer(GLES30.GL_READ_FRAMEBUFFER, frameBuffers[0]);
194 | GLES30.glBlitFramebuffer(0, 0, frameWidth, frameHeight,
195 | 0, 0,frameWidth, frameHeight,
196 | GLES30.GL_COLOR_BUFFER_BIT, GLES30.GL_LINEAR);
197 | GLES30.glBindFramebuffer(GLES30.GL_FRAMEBUFFER, 0);
198 | GLES30.glBindTexture(GLES30.GL_TEXTURE_2D,0);
199 | GLES30.glUseProgram(0);
200 | }
201 | }
202 |
--------------------------------------------------------------------------------
/app/src/main/java/com/hyq/hm/videotoimage/GLRenderer.java:
--------------------------------------------------------------------------------
1 | package com.hyq.hm.videotoimage;
2 |
3 | import android.graphics.Bitmap;
4 | import android.graphics.Rect;
5 | import android.graphics.SurfaceTexture;
6 | import android.opengl.GLES11Ext;
7 | import android.opengl.GLES30;
8 | import android.opengl.GLUtils;
9 |
10 | import java.nio.ByteBuffer;
11 | import java.nio.ByteOrder;
12 | import java.nio.FloatBuffer;
13 |
14 | /**
15 | * Created by 海米 on 2018/10/26.
16 | */
17 |
18 | public class GLRenderer {
19 | private int programId;
20 | private int uTextureSamplerHandle;
21 |
22 |
23 | private FloatBuffer vertexBuffer;
24 | private FloatBuffer textureVertexBuffer;
25 | private int textureWidth;
26 | private int textureHeight;
27 |
28 | public GLRenderer(int width,int height){
29 | float[] vertexData = {
30 | 1.0f, -1.0f,0,
31 | -1.0f, -1.0f,0,
32 | 1.0f, 1.0f,0,
33 | -1.0f, 1.0f,0
34 | };
35 | vertexBuffer = ByteBuffer.allocateDirect(vertexData.length * 4)
36 | .order(ByteOrder.nativeOrder())
37 | .asFloatBuffer()
38 | .put(vertexData);
39 | vertexBuffer.position(0);
40 | float[] textureVertexData = {
41 | 1f, 0f,//右下
42 | 0f, 0f,//左下
43 | 1f, 1f,//右上
44 | 0f, 1f//左上
45 | };
46 | textureVertexBuffer = ByteBuffer.allocateDirect(textureVertexData.length * 4)
47 | .order(ByteOrder.nativeOrder())
48 | .asFloatBuffer()
49 | .put(textureVertexData);
50 | textureVertexBuffer.position(0);
51 | textureWidth = width;
52 | textureHeight = height;
53 | }
54 |
55 |
56 | public void onSurfaceCreated(){
57 | String fragmentShader =
58 | "varying highp vec2 vTexCoord;\n" +
59 | "uniform sampler2D sTexture;\n" +
60 | "void main() {\n" +
61 | " gl_FragColor = texture2D(sTexture,vTexCoord);\n" +
62 | "}";
63 | String vertexShader = "attribute vec4 aPosition;\n" +
64 | "attribute vec2 aTexCoord;\n" +
65 | "varying vec2 vTexCoord;\n" +
66 | "void main() {\n" +
67 | " vTexCoord = aTexCoord;\n" +
68 | " gl_Position = aPosition;\n" +
69 | "}";
70 | programId= ShaderUtils.createProgram(vertexShader, fragmentShader);
71 | int aPositionHandle = GLES30.glGetAttribLocation(programId, "aPosition");
72 | uTextureSamplerHandle = GLES30.glGetUniformLocation(programId, "sTexture");
73 | int aTextureCoordHandle = GLES30.glGetAttribLocation(programId, "aTexCoord");
74 |
75 |
76 | GLES30.glUseProgram(programId);
77 | GLES30.glEnableVertexAttribArray(aPositionHandle);
78 | GLES30.glVertexAttribPointer(aPositionHandle, 3, GLES30.GL_FLOAT, false,
79 | 0, vertexBuffer);
80 | GLES30.glEnableVertexAttribArray(aTextureCoordHandle);
81 | GLES30.glVertexAttribPointer(aTextureCoordHandle,2,GLES30.GL_FLOAT,false,0,textureVertexBuffer);
82 | GLES30.glUseProgram(0);
83 |
84 | }
85 | public void onSurfaceDestroyed(){
86 | GLES30.glDeleteProgram(programId);
87 | }
88 | private Rect rect = new Rect();
89 | public void onSurfaceChanged(int screenWidth, int screenHeight) {
90 | int left,top,viewWidth,viewHeight;
91 | float sh = screenWidth*1.0f/screenHeight;
92 | float vh = textureWidth*1.0f/textureHeight;
93 | if(sh < vh){
94 | left = 0;
95 | viewWidth = screenWidth;
96 | viewHeight = (int)(textureHeight*1.0f/textureWidth*viewWidth);
97 | top = (screenHeight - viewHeight)/2;
98 | }else{
99 | top = 0;
100 | viewHeight = screenHeight;
101 | viewWidth = (int)(textureWidth*1.0f/textureHeight*viewHeight);
102 | left = (screenWidth - viewWidth)/2;
103 | }
104 | rect.set(left,top,viewWidth,viewHeight);
105 | }
106 |
107 | public void onDrawFrame(int textureId){
108 | GLES30.glClearColor(0.0f,0.0f,0.0f,0.0f);
109 | GLES30.glClear(GLES30.GL_DEPTH_BUFFER_BIT | GLES30.GL_COLOR_BUFFER_BIT);
110 | GLES30.glViewport(rect.left,rect.top,rect.right,rect.bottom);
111 | GLES30.glUseProgram(programId);
112 | GLES30.glActiveTexture(GLES30.GL_TEXTURE0);
113 | GLES30.glBindTexture(GLES30.GL_TEXTURE_2D,textureId);
114 | GLES30.glUniform1i(uTextureSamplerHandle,0);
115 | GLES30.glDrawArrays(GLES30.GL_TRIANGLE_STRIP, 0, 4);
116 | GLES30.glUseProgram(0);
117 | GLES30.glBindTexture(GLES30.GL_TEXTURE_2D,0);
118 | }
119 | }
120 |
--------------------------------------------------------------------------------
/app/src/main/java/com/hyq/hm/videotoimage/MainActivity.java:
--------------------------------------------------------------------------------
1 | package com.hyq.hm.videotoimage;
2 |
3 | import android.graphics.Bitmap;
4 | import android.graphics.Canvas;
5 | import android.graphics.PixelFormat;
6 | import android.graphics.Rect;
7 | import android.graphics.RectF;
8 | import android.media.Image;
9 | import android.media.ImageReader;
10 | import android.opengl.EGL14;
11 | import android.opengl.EGLContext;
12 | import android.opengl.GLES20;
13 | import android.os.Handler;
14 | import android.os.HandlerThread;
15 | import android.support.v7.app.AppCompatActivity;
16 | import android.os.Bundle;
17 | import android.util.Log;
18 | import android.view.SurfaceHolder;
19 | import android.view.SurfaceView;
20 | import android.widget.ImageView;
21 | import android.widget.SeekBar;
22 |
23 | import java.nio.ByteBuffer;
24 |
25 | public class MainActivity extends AppCompatActivity {
26 |
27 | private Handler bitmapHandler;
28 | private HandlerThread bitmapThread;
29 | private EGLUtils eglUtils;
30 | private GLBitmap glBitmap;
31 | private GLRenderer renderer;
32 |
33 |
34 | private Handler imageHandler;
35 | private HandlerThread imageThread;
36 | private ImageReader imageReader;
37 |
38 | private Handler glHandler;
39 | private HandlerThread glThread;
40 | private EGLUtils glEglUtils;
41 | private GLRenderer glRenderer;
42 |
43 | private int imageWidth,imageHeight;
44 |
45 | @Override
46 | protected void onCreate(Bundle savedInstanceState) {
47 | super.onCreate(savedInstanceState);
48 | setContentView(R.layout.activity_main);
49 |
50 | bitmapThread = new HandlerThread("BitmapThread");
51 | bitmapThread.start();
52 | bitmapHandler = new Handler(bitmapThread.getLooper());
53 |
54 | glBitmap = new GLBitmap(this,R.drawable.ic_jn);
55 | renderer = new GLRenderer(glBitmap.getWidth(),glBitmap.getHeight());
56 |
57 | glThread = new HandlerThread("GLThread");
58 | glThread.start();
59 | glHandler = new Handler(glThread.getLooper());
60 | glRenderer = new GLRenderer(glBitmap.getWidth(),glBitmap.getHeight());
61 |
62 | imageWidth = glBitmap.getWidth()/10;
63 | imageHeight = glBitmap.getHeight()/10;
64 |
65 | imageThread = new HandlerThread("ImageThread");
66 | imageThread.start();
67 | imageHandler = new Handler(imageThread.getLooper());
68 | final Rect src = new Rect(0,0,imageWidth,imageHeight);
69 | final RectF dst = new RectF(0,0,imageWidth,imageHeight);
70 | final ImageView imageView = findViewById(R.id.image_view);
71 | imageReader = ImageReader.newInstance(imageWidth,imageHeight, PixelFormat.RGBA_8888,1);
72 | imageReader.setOnImageAvailableListener(new ImageReader.OnImageAvailableListener() {
73 | @Override
74 | public void onImageAvailable(ImageReader reader) {
75 | Image image = reader.acquireNextImage();
76 | if(image != null) {
77 | int width = image.getWidth();
78 | int height = image.getHeight();
79 | final Image.Plane[] planes = image.getPlanes();
80 | final ByteBuffer buffer = planes[0].getBuffer();
81 | int pixelStride = planes[0].getPixelStride();
82 | int rowStride = planes[0].getRowStride();
83 | int rowPadding = rowStride - pixelStride * width;
84 | Bitmap bitmap = Bitmap.createBitmap(width + rowPadding / pixelStride, height, Bitmap.Config.ARGB_8888);
85 | bitmap.copyPixelsFromBuffer(buffer);
86 | final Bitmap bmp = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
87 | Canvas canvas = new Canvas(bmp);
88 | canvas.drawBitmap(bitmap, src, dst, null);
89 | imageView.post(new Runnable() {
90 | @Override
91 | public void run() {
92 | imageView.setImageBitmap(bmp);
93 | }
94 | });
95 | image.close();
96 | }
97 | }
98 | },imageHandler);
99 |
100 |
101 | SurfaceView surfaceView = findViewById(R.id.surface_view);
102 | surfaceView.getHolder().addCallback(new SurfaceHolder.Callback() {
103 | @Override
104 | public void surfaceCreated(final SurfaceHolder holder) {
105 | bitmapHandler.post(new Runnable() {
106 | @Override
107 | public void run() {
108 | eglUtils = new EGLUtils();
109 | eglUtils.initEGL(holder.getSurface(), EGL14.EGL_NO_CONTEXT);
110 | glBitmap.surfaceCreated();
111 | renderer.onSurfaceCreated();
112 | }
113 | });
114 | }
115 |
116 | @Override
117 | public void surfaceChanged(SurfaceHolder holder, int format, final int width, final int height) {
118 | glHandler.post(new Runnable() {
119 | @Override
120 | public void run() {
121 | while (true){
122 | if(eglUtils != null){
123 | EGLContext eglContext = eglUtils.getContext();
124 | if(eglContext != EGL14.EGL_NO_CONTEXT){
125 | if(glEglUtils != null){
126 | glEglUtils.release();
127 | }else{
128 | glEglUtils = new EGLUtils();
129 | }
130 | glEglUtils.initEGL(imageReader.getSurface(),eglContext);
131 | glRenderer.onSurfaceCreated();
132 | glRenderer.onSurfaceChanged(imageWidth,imageHeight);
133 | break;
134 | }
135 | }
136 | try {
137 | Thread.sleep(10);
138 | } catch (InterruptedException e) {
139 | e.printStackTrace();
140 | }
141 | }
142 | }
143 | });
144 | bitmapHandler.post(new Runnable() {
145 | @Override
146 | public void run() {
147 | renderer.onSurfaceChanged(width,height);
148 | glBitmap.surfaceDraw();
149 | renderer.onDrawFrame(glBitmap.getTextureId());
150 | eglUtils.swap();
151 | glHandler.post(new Runnable() {
152 | @Override
153 | public void run() {
154 | glRenderer.onDrawFrame(glBitmap.getTextureId());
155 | glEglUtils.swap();
156 | }
157 | });
158 | }
159 | });
160 |
161 | }
162 |
163 | @Override
164 | public void surfaceDestroyed(SurfaceHolder holder) {
165 | bitmapHandler.post(new Runnable() {
166 | @Override
167 | public void run() {
168 | renderer.onSurfaceDestroyed();
169 | glBitmap.surfaceDestroyed();
170 | eglUtils.release();
171 | }
172 | });
173 | }
174 | });
175 | SeekBar seekBar = findViewById(R.id.seek_bar);
176 | seekBar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
177 | @Override
178 | public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
179 | rotate(progress);
180 | }
181 |
182 | @Override
183 | public void onStartTrackingTouch(SeekBar seekBar) {
184 |
185 | }
186 |
187 | @Override
188 | public void onStopTrackingTouch(SeekBar seekBar) {
189 |
190 | }
191 | });
192 | }
193 |
194 | private void rotate(final int rotate){
195 | bitmapHandler.post(new Runnable() {
196 | @Override
197 | public void run() {
198 | glBitmap.setRadian(rotate);
199 | glBitmap.surfaceDraw();
200 | renderer.onDrawFrame(glBitmap.getTextureId());
201 | eglUtils.swap();
202 | glHandler.post(new Runnable() {
203 | @Override
204 | public void run() {
205 | glRenderer.onDrawFrame(glBitmap.getTextureId());
206 | glEglUtils.swap();
207 | }
208 | });
209 | }
210 | });
211 | }
212 |
213 | @Override
214 | protected void onDestroy() {
215 | super.onDestroy();
216 | bitmapThread.quit();
217 | imageThread.quit();
218 | glHandler.post(new Runnable() {
219 | @Override
220 | public void run() {
221 | glRenderer.onSurfaceDestroyed();
222 | glEglUtils.release();
223 | glThread.quit();
224 | }
225 | });
226 | imageReader.close();
227 | }
228 | }
229 |
--------------------------------------------------------------------------------
/app/src/main/java/com/hyq/hm/videotoimage/ShaderUtils.java:
--------------------------------------------------------------------------------
1 | package com.hyq.hm.videotoimage;
2 |
3 | import android.content.Context;
4 | import android.opengl.GLES30;
5 | import android.util.Log;
6 |
7 | import java.io.BufferedReader;
8 | import java.io.IOException;
9 | import java.io.InputStream;
10 | import java.io.InputStreamReader;
11 |
12 | /**
13 | * Created by 海米 on 2017/7/7.
14 | */
15 |
16 | public class ShaderUtils {
17 | private static final String TAG = "ShaderUtils";
18 |
19 | public static void checkGlError(String label) {
20 | int error;
21 | while ((error = GLES30.glGetError()) != GLES30.GL_NO_ERROR) {
22 | Log.e(TAG, label + ": glError " + error);
23 | throw new RuntimeException(label + ": glError " + error);
24 | }
25 | }
26 |
27 | public static int createProgram(String vertexSource, String fragmentSource) {
28 | int vertexShader = loadShader(GLES30.GL_VERTEX_SHADER, vertexSource);
29 | if (vertexShader == 0) {
30 | return 0;
31 | }
32 | int pixelShader = loadShader(GLES30.GL_FRAGMENT_SHADER, fragmentSource);
33 | if (pixelShader == 0) {
34 | return 0;
35 | }
36 |
37 | int program = GLES30.glCreateProgram();
38 | if (program != 0) {
39 | GLES30.glAttachShader(program, vertexShader);
40 | checkGlError("glAttachShader");
41 | GLES30.glAttachShader(program, pixelShader);
42 | checkGlError("glAttachShader");
43 | GLES30.glLinkProgram(program);
44 | int[] linkStatus = new int[1];
45 | GLES30.glGetProgramiv(program, GLES30.GL_LINK_STATUS, linkStatus, 0);
46 | if (linkStatus[0] != GLES30.GL_TRUE) {
47 | Log.e(TAG, "Could not link program: ");
48 | Log.e(TAG, GLES30.glGetProgramInfoLog(program));
49 | GLES30.glDeleteProgram(program);
50 | program = 0;
51 | }
52 | }
53 | return program;
54 | }
55 |
56 |
57 | public static int loadShader(int shaderType, String source) {
58 | int shader = GLES30.glCreateShader(shaderType);
59 | if (shader != 0) {
60 | GLES30.glShaderSource(shader, source);
61 | GLES30.glCompileShader(shader);
62 | int[] compiled = new int[1];
63 | GLES30.glGetShaderiv(shader, GLES30.GL_COMPILE_STATUS, compiled, 0);
64 | if (compiled[0] == 0) {
65 | Log.e(TAG, "Could not compile shader " + shaderType + ":");
66 | Log.e(TAG, GLES30.glGetShaderInfoLog(shader));
67 | GLES30.glDeleteShader(shader);
68 | shader = 0;
69 | }
70 | }
71 | return shader;
72 | }
73 |
74 | public static String readRawTextFile(Context context, int resId) {
75 | InputStream inputStream = context.getResources().openRawResource(resId);
76 | try {
77 | BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream));
78 | StringBuilder sb = new StringBuilder();
79 | String line;
80 | while ((line = reader.readLine()) != null) {
81 | sb.append(line).append("\n");
82 | }
83 | reader.close();
84 | return sb.toString();
85 | } catch (IOException e) {
86 | e.printStackTrace();
87 | }
88 | return null;
89 | }
90 |
91 | }
92 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable-v24/ic_launcher_foreground.xml:
--------------------------------------------------------------------------------
1 |
7 |
12 |
13 |
19 |
22 |
25 |
26 |
27 |
28 |
34 |
35 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/ic_jn.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/a422070876/OpenGLESToBitmap/c1dc7dfc23d74ad1806b32c673716072ef50567d/app/src/main/res/drawable/ic_jn.jpg
--------------------------------------------------------------------------------
/app/src/main/res/drawable/ic_launcher_background.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
10 |
15 |
20 |
25 |
30 |
35 |
40 |
45 |
50 |
55 |
60 |
65 |
70 |
75 |
80 |
85 |
90 |
95 |
100 |
105 |
110 |
115 |
120 |
125 |
130 |
135 |
140 |
145 |
150 |
155 |
160 |
165 |
170 |
171 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_main.xml:
--------------------------------------------------------------------------------
1 |
2 |
8 |
9 |
10 |
14 |
20 |
25 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/a422070876/OpenGLESToBitmap/c1dc7dfc23d74ad1806b32c673716072ef50567d/app/src/main/res/mipmap-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/a422070876/OpenGLESToBitmap/c1dc7dfc23d74ad1806b32c673716072ef50567d/app/src/main/res/mipmap-hdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/a422070876/OpenGLESToBitmap/c1dc7dfc23d74ad1806b32c673716072ef50567d/app/src/main/res/mipmap-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/a422070876/OpenGLESToBitmap/c1dc7dfc23d74ad1806b32c673716072ef50567d/app/src/main/res/mipmap-mdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/a422070876/OpenGLESToBitmap/c1dc7dfc23d74ad1806b32c673716072ef50567d/app/src/main/res/mipmap-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/a422070876/OpenGLESToBitmap/c1dc7dfc23d74ad1806b32c673716072ef50567d/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/a422070876/OpenGLESToBitmap/c1dc7dfc23d74ad1806b32c673716072ef50567d/app/src/main/res/mipmap-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/a422070876/OpenGLESToBitmap/c1dc7dfc23d74ad1806b32c673716072ef50567d/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/a422070876/OpenGLESToBitmap/c1dc7dfc23d74ad1806b32c673716072ef50567d/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/a422070876/OpenGLESToBitmap/c1dc7dfc23d74ad1806b32c673716072ef50567d/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | #3F51B5
4 | #303F9F
5 | #FF4081
6 |
7 |
--------------------------------------------------------------------------------
/app/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | VideoToImage
3 |
4 |
--------------------------------------------------------------------------------
/app/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/app/src/test/java/com/hyq/hm/videotoimage/ExampleUnitTest.java:
--------------------------------------------------------------------------------
1 | package com.hyq.hm.videotoimage;
2 |
3 | import org.junit.Test;
4 |
5 | import static org.junit.Assert.*;
6 |
7 | /**
8 | * Example local unit test, which will execute on the development machine (host).
9 | *
10 | * @see Testing documentation
11 | */
12 | public class ExampleUnitTest {
13 | @Test
14 | public void addition_isCorrect() throws Exception {
15 | assertEquals(4, 2 + 2);
16 | }
17 | }
--------------------------------------------------------------------------------
/build.gradle:
--------------------------------------------------------------------------------
1 | // Top-level build file where you can add configuration options common to all sub-projects/modules.
2 |
3 | buildscript {
4 |
5 | repositories {
6 | google()
7 | jcenter()
8 | }
9 | dependencies {
10 | classpath 'com.android.tools.build:gradle:3.0.1'
11 |
12 |
13 | // NOTE: Do not place your application dependencies here; they belong
14 | // in the individual module build.gradle files
15 | }
16 | }
17 |
18 | allprojects {
19 | repositories {
20 | google()
21 | jcenter()
22 | }
23 | }
24 |
25 | task clean(type: Delete) {
26 | delete rootProject.buildDir
27 | }
28 |
--------------------------------------------------------------------------------
/gradle.properties:
--------------------------------------------------------------------------------
1 | # Project-wide Gradle settings.
2 |
3 | # IDE (e.g. Android Studio) users:
4 | # Gradle settings configured through the IDE *will override*
5 | # any settings specified in this file.
6 |
7 | # For more details on how to configure your build environment visit
8 | # http://www.gradle.org/docs/current/userguide/build_environment.html
9 |
10 | # Specifies the JVM arguments used for the daemon process.
11 | # The setting is particularly useful for tweaking memory settings.
12 | org.gradle.jvmargs=-Xmx1536m
13 |
14 | # When configured, Gradle will run in incubating parallel mode.
15 | # This option should only be used with decoupled projects. More details, visit
16 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
17 | # org.gradle.parallel=true
18 |
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/a422070876/OpenGLESToBitmap/c1dc7dfc23d74ad1806b32c673716072ef50567d/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #Thu Nov 08 18:07:55 CST 2018
2 | distributionBase=GRADLE_USER_HOME
3 | distributionPath=wrapper/dists
4 | zipStoreBase=GRADLE_USER_HOME
5 | zipStorePath=wrapper/dists
6 | distributionUrl=https\://services.gradle.org/distributions/gradle-4.1-all.zip
7 |
--------------------------------------------------------------------------------
/gradlew:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env bash
2 |
3 | ##############################################################################
4 | ##
5 | ## Gradle start up script for UN*X
6 | ##
7 | ##############################################################################
8 |
9 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
10 | DEFAULT_JVM_OPTS=""
11 |
12 | APP_NAME="Gradle"
13 | APP_BASE_NAME=`basename "$0"`
14 |
15 | # Use the maximum available, or set MAX_FD != -1 to use that value.
16 | MAX_FD="maximum"
17 |
18 | warn ( ) {
19 | echo "$*"
20 | }
21 |
22 | die ( ) {
23 | echo
24 | echo "$*"
25 | echo
26 | exit 1
27 | }
28 |
29 | # OS specific support (must be 'true' or 'false').
30 | cygwin=false
31 | msys=false
32 | darwin=false
33 | case "`uname`" in
34 | CYGWIN* )
35 | cygwin=true
36 | ;;
37 | Darwin* )
38 | darwin=true
39 | ;;
40 | MINGW* )
41 | msys=true
42 | ;;
43 | esac
44 |
45 | # Attempt to set APP_HOME
46 | # Resolve links: $0 may be a link
47 | PRG="$0"
48 | # Need this for relative symlinks.
49 | while [ -h "$PRG" ] ; do
50 | ls=`ls -ld "$PRG"`
51 | link=`expr "$ls" : '.*-> \(.*\)$'`
52 | if expr "$link" : '/.*' > /dev/null; then
53 | PRG="$link"
54 | else
55 | PRG=`dirname "$PRG"`"/$link"
56 | fi
57 | done
58 | SAVED="`pwd`"
59 | cd "`dirname \"$PRG\"`/" >/dev/null
60 | APP_HOME="`pwd -P`"
61 | cd "$SAVED" >/dev/null
62 |
63 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
64 |
65 | # Determine the Java command to use to start the JVM.
66 | if [ -n "$JAVA_HOME" ] ; then
67 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
68 | # IBM's JDK on AIX uses strange locations for the executables
69 | JAVACMD="$JAVA_HOME/jre/sh/java"
70 | else
71 | JAVACMD="$JAVA_HOME/bin/java"
72 | fi
73 | if [ ! -x "$JAVACMD" ] ; then
74 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
75 |
76 | Please set the JAVA_HOME variable in your environment to match the
77 | location of your Java installation."
78 | fi
79 | else
80 | JAVACMD="java"
81 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
82 |
83 | Please set the JAVA_HOME variable in your environment to match the
84 | location of your Java installation."
85 | fi
86 |
87 | # Increase the maximum file descriptors if we can.
88 | if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then
89 | MAX_FD_LIMIT=`ulimit -H -n`
90 | if [ $? -eq 0 ] ; then
91 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
92 | MAX_FD="$MAX_FD_LIMIT"
93 | fi
94 | ulimit -n $MAX_FD
95 | if [ $? -ne 0 ] ; then
96 | warn "Could not set maximum file descriptor limit: $MAX_FD"
97 | fi
98 | else
99 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
100 | fi
101 | fi
102 |
103 | # For Darwin, add options to specify how the application appears in the dock
104 | if $darwin; then
105 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
106 | fi
107 |
108 | # For Cygwin, switch paths to Windows format before running java
109 | if $cygwin ; then
110 | APP_HOME=`cygpath --path --mixed "$APP_HOME"`
111 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
112 | JAVACMD=`cygpath --unix "$JAVACMD"`
113 |
114 | # We build the pattern for arguments to be converted via cygpath
115 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
116 | SEP=""
117 | for dir in $ROOTDIRSRAW ; do
118 | ROOTDIRS="$ROOTDIRS$SEP$dir"
119 | SEP="|"
120 | done
121 | OURCYGPATTERN="(^($ROOTDIRS))"
122 | # Add a user-defined pattern to the cygpath arguments
123 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then
124 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
125 | fi
126 | # Now convert the arguments - kludge to limit ourselves to /bin/sh
127 | i=0
128 | for arg in "$@" ; do
129 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
130 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
131 |
132 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
133 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
134 | else
135 | eval `echo args$i`="\"$arg\""
136 | fi
137 | i=$((i+1))
138 | done
139 | case $i in
140 | (0) set -- ;;
141 | (1) set -- "$args0" ;;
142 | (2) set -- "$args0" "$args1" ;;
143 | (3) set -- "$args0" "$args1" "$args2" ;;
144 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;;
145 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
146 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
147 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
148 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
149 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
150 | esac
151 | fi
152 |
153 | # Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules
154 | function splitJvmOpts() {
155 | JVM_OPTS=("$@")
156 | }
157 | eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS
158 | JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME"
159 |
160 | exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@"
161 |
--------------------------------------------------------------------------------
/gradlew.bat:
--------------------------------------------------------------------------------
1 | @if "%DEBUG%" == "" @echo off
2 | @rem ##########################################################################
3 | @rem
4 | @rem Gradle startup script for Windows
5 | @rem
6 | @rem ##########################################################################
7 |
8 | @rem Set local scope for the variables with windows NT shell
9 | if "%OS%"=="Windows_NT" setlocal
10 |
11 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
12 | set DEFAULT_JVM_OPTS=
13 |
14 | set DIRNAME=%~dp0
15 | if "%DIRNAME%" == "" set DIRNAME=.
16 | set APP_BASE_NAME=%~n0
17 | set APP_HOME=%DIRNAME%
18 |
19 | @rem Find java.exe
20 | if defined JAVA_HOME goto findJavaFromJavaHome
21 |
22 | set JAVA_EXE=java.exe
23 | %JAVA_EXE% -version >NUL 2>&1
24 | if "%ERRORLEVEL%" == "0" goto init
25 |
26 | echo.
27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
28 | echo.
29 | echo Please set the JAVA_HOME variable in your environment to match the
30 | echo location of your Java installation.
31 |
32 | goto fail
33 |
34 | :findJavaFromJavaHome
35 | set JAVA_HOME=%JAVA_HOME:"=%
36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe
37 |
38 | if exist "%JAVA_EXE%" goto init
39 |
40 | echo.
41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
42 | echo.
43 | echo Please set the JAVA_HOME variable in your environment to match the
44 | echo location of your Java installation.
45 |
46 | goto fail
47 |
48 | :init
49 | @rem Get command-line arguments, handling Windowz variants
50 |
51 | if not "%OS%" == "Windows_NT" goto win9xME_args
52 | if "%@eval[2+2]" == "4" goto 4NT_args
53 |
54 | :win9xME_args
55 | @rem Slurp the command line arguments.
56 | set CMD_LINE_ARGS=
57 | set _SKIP=2
58 |
59 | :win9xME_args_slurp
60 | if "x%~1" == "x" goto execute
61 |
62 | set CMD_LINE_ARGS=%*
63 | goto execute
64 |
65 | :4NT_args
66 | @rem Get arguments from the 4NT Shell from JP Software
67 | set CMD_LINE_ARGS=%$
68 |
69 | :execute
70 | @rem Setup the command line
71 |
72 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
73 |
74 | @rem Execute Gradle
75 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
76 |
77 | :end
78 | @rem End local scope for the variables with windows NT shell
79 | if "%ERRORLEVEL%"=="0" goto mainEnd
80 |
81 | :fail
82 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
83 | rem the _cmd.exe /c_ return code!
84 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
85 | exit /b 1
86 |
87 | :mainEnd
88 | if "%OS%"=="Windows_NT" endlocal
89 |
90 | :omega
91 |
--------------------------------------------------------------------------------
/settings.gradle:
--------------------------------------------------------------------------------
1 | include ':app'
2 |
--------------------------------------------------------------------------------