Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

1. 升级gradle和cmake版本 2. 优化部分代码 #6

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
66 changes: 0 additions & 66 deletions app/CMakeLists.txt

This file was deleted.

3 changes: 2 additions & 1 deletion app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ android {
}
externalNativeBuild {
cmake {
path file('CMakeLists.txt')
path "src/main/cpp/CMakeLists.txt"
version "3.10.2"
}
}
}
Expand Down
35 changes: 25 additions & 10 deletions app/src/main/assets/shaders/fshader_0.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,30 @@ varying vec2 v_texcoord;
uniform lowp sampler2D s_textureY;
uniform lowp sampler2D s_textureU;
uniform lowp sampler2D s_textureV;

vec4 YuvToRgb(vec2 uv) {
// YUV转RGB
// R = Y + 1.402 * (V - 128)
// G = Y - 0.34414 * (U - 128) - 0.71414 * (V - 128)
// B = Y + 1.772 * (U - 128)

vec3 yuv;
// 只赋值x 则会出现黑白照片效果
yuv.x = texture2D(s_textureY, uv).r;
// 因为YUV转RGB用的是Y、U-128和V-128,texture函数返回向量值的范围是0-1.0,128表示0.5, 所以要减去0.5
yuv.y = texture2D(s_textureU, uv).r - 0.5;
yuv.z = texture2D(s_textureV, uv).r - 0.5;

// YUV 和 RGB 的转换矩阵
highp vec3 rgb = mat3(
1.0, 1.0, 1.0, //第一列
0.0, -0.34414, 1.772, //第二列
1.403, -0.71414, 0.0 //第三列
) * yuv;
return vec4(rgb, 1.0);
}


void main() {
float y, u, v, r, g, b;
y = texture2D(s_textureY, v_texcoord).r;
u = texture2D(s_textureU, v_texcoord).r;
v = texture2D(s_textureV, v_texcoord).r;
u = u - 0.5;
v = v - 0.5;
r = y + 1.403 * v;
g = y - 0.344 * u - 0.714 * v;
b = y + 1.770 * u;
gl_FragColor = vec4(r, g, b, 1.0);
gl_FragColor = YuvToRgb(v_texcoord);
}
31 changes: 21 additions & 10 deletions app/src/main/assets/shaders/fshader_1.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,29 @@ varying vec2 v_texcoord;
uniform lowp sampler2D s_textureY;
uniform lowp sampler2D s_textureU;
uniform lowp sampler2D s_textureV;

vec4 YuvToRgb(vec2 uv) {
float y, u, v, r, g, b;
y = texture2D(s_textureY, uv).r;
u = texture2D(s_textureU, uv).r;
v = texture2D(s_textureV, uv).r;
u = u - 0.5;
v = v - 0.5;
r = y + 1.403 * v;
g = y - 0.344 * u - 0.714 * v;
b = y + 1.770 * u;
return vec4(r, g, b, 1.0);
// YUV转RGB
// R = Y + 1.402 * (V - 128)
// G = Y - 0.34414 * (U - 128) - 0.71414 * (V - 128)
// B = Y + 1.772 * (U - 128)

vec3 yuv;
// 只赋值x 则会出现黑白照片效果
yuv.x = texture2D(s_textureY, uv).r;
// 因为YUV转RGB用的是Y、U-128和V-128,texture函数返回向量值的范围是0-1.0,128表示0.5, 所以要减去0.5
yuv.y = texture2D(s_textureU, uv).r - 0.5;
yuv.z = texture2D(s_textureV, uv).r - 0.5;

// YUV 和 RGB 的转换矩阵
highp vec3 rgb = mat3(
1.0, 1.0, 1.0, //第一列
0.0, -0.34414, 1.772, //第二列
1.403, -0.71414, 0.0//第三列
) * yuv;
return vec4(rgb, 1.0);
}

void main() {
vec4 sample0, sample1, sample2, sample3;
float blurStep = 0.5;
Expand Down
69 changes: 43 additions & 26 deletions app/src/main/assets/shaders/fshader_10.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,29 @@ float satLevels[kSatLevCount];
float valLevels[kValLevCount];
float edge_thres = 0.2;
float edge_thres2 = 5.0;

vec4 YuvToRgb(vec2 uv) {
float y, u, v, r, g, b;
y = texture2D(s_textureY, uv).r;
u = texture2D(s_textureU, uv).r;
v = texture2D(s_textureV, uv).r;
u = u - 0.5;
v = v - 0.5;
r = y + 1.403 * v;
g = y - 0.344 * u - 0.714 * v;
b = y + 1.770 * u;
return vec4(r, g, b, 1.0);
// YUV转RGB
// R = Y + 1.402 * (V - 128)
// G = Y - 0.34414 * (U - 128) - 0.71414 * (V - 128)
// B = Y + 1.772 * (U - 128)

vec3 yuv;
// 只赋值x 则会出现黑白照片效果
yuv.x = texture2D(s_textureY, uv).r;
// 因为YUV转RGB用的是Y、U-128和V-128,texture函数返回向量值的范围是0-1.0,128表示0.5, 所以要减去0.5
yuv.y = texture2D(s_textureU, uv).r - 0.5;
yuv.z = texture2D(s_textureV, uv).r - 0.5;

// YUV 和 RGB 的转换矩阵
highp vec3 rgb = mat3(
1.0, 1.0, 1.0, //第一列
0.0, -0.34414, 1.772, //第二列
1.403, -0.71414, 0.0//第三列
) * yuv;
return vec4(rgb, 1.0);
}

vec3 RGBtoHSV(float r, float g, float b) {
float minv, maxv, delta;
vec3 res;
Expand All @@ -41,32 +52,33 @@ vec3 RGBtoHSV(float r, float g, float b) {
return res;
}
if (r == maxv)
res.x = ( g - b ) / delta;
res.x = (g - b) / delta;
else if (g == maxv)
res.x = 2.0 + ( b - r ) / delta;
res.x = 2.0 + (b - r) / delta;
else
res.x = 4.0 + ( r - g ) / delta;
res.x = 4.0 + (r - g) / delta;
res.x = res.x * 60.0;
if(res.x < 0.0)
if (res.x < 0.0)
res.x = res.x + 360.0;
return res;
}
vec3 HSVtoRGB(float h, float s, float v ) {

vec3 HSVtoRGB(float h, float s, float v) {
int i;
float f, p, q, t;
vec3 res;
if(s == 0.0) {
if (s == 0.0) {
res.x = v;
res.y = v;
res.z = v;
return res;
}
h /= 60.0;
i = int(floor( h ));
i = int(floor(h));
f = h - float(i);
p = v * ( 1.0 - s );
q = v * ( 1.0 - s * f );
t = v * ( 1.0 - s * ( 1.0 - f ) );
p = v * (1.0 - s);
q = v * (1.0 - s * f);
t = v * (1.0 - s * (1.0 - f));
if (i == 0) {
res.x = v;
res.y = t;
Expand Down Expand Up @@ -94,12 +106,13 @@ vec3 HSVtoRGB(float h, float s, float v ) {
}
return res;
}

float nearestLevel(float col, int mode) {
int levCount;
if (mode==0) levCount = kHueLevCount;
if (mode==1) levCount = kSatLevCount;
if (mode==2) levCount = kValLevCount;
for (int i=0; i<levCount-1; i++ ) {
for (int i=0; i<levCount-1; i++) {
if (mode==0) {
if (col >= hueLevels[i] && col <= hueLevels[i+1]) {
return hueLevels[i+1];
Expand All @@ -118,27 +131,31 @@ float nearestLevel(float col, int mode) {
}
return 0.0;
}

float avgIntensity(vec4 pix) {
return (pix.r + pix.g + pix.b)/3.;
}

vec4 getPixel(vec2 coords, float dx, float dy) {
return YuvToRgb(coords + vec2(dx, dy));
}

float IsEdge(in vec2 coords) {
float dxtex = 1.0 / float(texSize.x);
float dytex = 1.0 / float(texSize.y);
float pix[9];
int k = -1;
float delta;
for (int i=-1; i<2; i++) {
for(int j=-1; j<2; j++) {
for (int j=-1; j<2; j++) {
k++;
pix[k] = avgIntensity(getPixel(coords,float(i)*dxtex, float(j)*dytex));
pix[k] = avgIntensity(getPixel(coords, float(i)*dxtex, float(j)*dytex));
}
}
delta = (abs(pix[1]-pix[7]) + abs(pix[5]-pix[3]) + abs(pix[0]-pix[8])+ abs(pix[2]-pix[6]))/4.;
return clamp(edge_thres2*delta,0.0,1.0);
return clamp(edge_thres2*delta, 0.0, 1.0);
}

void main() {
hueLevels[0] = 0.0;
hueLevels[1] = 140.0;
Expand All @@ -159,11 +176,11 @@ void main() {
valLevels[3] = 1.0;
vec2 uv = v_texcoord;
vec3 color = YuvToRgb(uv).rgb;
vec3 vHSV = RGBtoHSV(color.r, color.g, color.b);
vec3 vHSV = RGBtoHSV(color.r, color.g, color.b);
vHSV.x = nearestLevel(vHSV.x, 0);
vHSV.y = nearestLevel(vHSV.y, 1);
vHSV.z = nearestLevel(vHSV.z, 2);
float edg = IsEdge(uv);
vec3 vRGB = (edg >= edge_thres) ? vec3(0.0,0.0,0.0) : HSVtoRGB(vHSV.x,vHSV.y,vHSV.z);
vec3 vRGB = (edg >= edge_thres) ? vec3(0.0, 0.0, 0.0) : HSVtoRGB(vHSV.x, vHSV.y, vHSV.z);
gl_FragColor = vec4(vRGB.x, vRGB.y, vRGB.z, 1.0);
}
36 changes: 25 additions & 11 deletions app/src/main/assets/shaders/fshader_11.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -5,24 +5,38 @@ varying vec2 v_texcoord;
uniform lowp sampler2D s_textureY;
uniform lowp sampler2D s_textureU;
uniform lowp sampler2D s_textureV;

vec4 YuvToRgb(vec2 uv) {
// YUV转RGB
// R = Y + 1.402 * (V - 128)
// G = Y - 0.34414 * (U - 128) - 0.71414 * (V - 128)
// B = Y + 1.772 * (U - 128)

vec3 yuv;
// 只赋值x 则会出现黑白照片效果
yuv.x = texture2D(s_textureY, uv).r;
// 因为YUV转RGB用的是Y、U-128和V-128,texture函数返回向量值的范围是0-1.0,128表示0.5, 所以要减去0.5
yuv.y = texture2D(s_textureU, uv).r - 0.5;
yuv.z = texture2D(s_textureV, uv).r - 0.5;

// YUV 和 RGB 的转换矩阵
highp vec3 rgb = mat3(
1.0, 1.0, 1.0, //第一列
0.0, -0.34414, 1.772, //第二列
1.403, -0.71414, 0.0//第三列
) * yuv;
return vec4(rgb, 1.0);
}

void main() {
float y, u, v, r, g, b;
y = texture2D(s_textureY, v_texcoord).r;
u = texture2D(s_textureU, v_texcoord).r;
v = texture2D(s_textureV, v_texcoord).r;
u = u - 0.5;
v = v - 0.5;
r = y + 1.403 * v;
g = y - 0.344 * u - 0.714 * v;
b = y + 1.770 * u;
vec3 color = vec3(r, g, b);
vec3 color = YuvToRgb(v_texcoord).rgb;
vec2 uv = v_texcoord.xy;
vec3 colors[3];
colors[0] = vec3(0.,0.,1.);
colors[1] = vec3(1.,1.,0.);
colors[2] = vec3(1.,0.,0.);
float lum = (color.r + color.g + color.b)/3.;
int idx = (lum < 0.5) ? 0 : 1;
vec3 rgb = mix(colors[idx],colors[idx+1],(lum-float(idx)*0.5)/0.5);
vec3 rgb = mix(colors[idx],colors[idx + 1],(lum - float(idx) * 0.5) / 0.5);
gl_FragColor = vec4(rgb, 1.0);
}
31 changes: 21 additions & 10 deletions app/src/main/assets/shaders/fshader_12.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,29 @@ uniform lowp sampler2D s_textureY;
uniform lowp sampler2D s_textureU;
uniform lowp sampler2D s_textureV;
uniform vec2 texSize;

vec4 YuvToRgb(vec2 uv) {
float y, u, v, r, g, b;
y = texture2D(s_textureY, uv).r;
u = texture2D(s_textureU, uv).r;
v = texture2D(s_textureV, uv).r;
u = u - 0.5;
v = v - 0.5;
r = y + 1.403 * v;
g = y - 0.344 * u - 0.714 * v;
b = y + 1.770 * u;
return vec4(r, g, b, 1.0);
// YUV转RGB
// R = Y + 1.402 * (V - 128)
// G = Y - 0.34414 * (U - 128) - 0.71414 * (V - 128)
// B = Y + 1.772 * (U - 128)

vec3 yuv;
// 只赋值x 则会出现黑白照片效果
yuv.x = texture2D(s_textureY, uv).r;
// 因为YUV转RGB用的是Y、U-128和V-128,texture函数返回向量值的范围是0-1.0,128表示0.5, 所以要减去0.5
yuv.y = texture2D(s_textureU, uv).r - 0.5;
yuv.z = texture2D(s_textureV, uv).r - 0.5;

// YUV 和 RGB 的转换矩阵
highp vec3 rgb = mat3(
1.0, 1.0, 1.0, //第一列
0.0, -0.34414, 1.772, //第二列
1.403, -0.71414, 0.0//第三列
) * yuv;
return vec4(rgb, 1.0);
}

void main() {
vec4 color;
color.rgb = vec3(0.5);
Expand Down
Loading