Fix image generation, tune rgb565 reconstruction

This commit is contained in:
mittorn 2024-11-02 07:22:28 +03:00
parent 875b55646d
commit b78f4dca2d
3 changed files with 96 additions and 30 deletions

View file

@ -56,26 +56,52 @@ vec4 sample4f(float x0, float y0)
}
const float cmul = 32;
const float off = 31.0/63;//7.0/15;//128.0/255;
const float cmul = 32.0;
const float off = 31.0/63.0;//7.0/15;//128.0/255;
const float off2 = 15.0/31.0;
float cmul2 = 64;
float conv(float x)
{
return log(cmul*x+1)/log(cmul+1);
//return x;
return log(cmul*x+1.0)/log(cmul+1.0);
}
float conv2(float x)
{
//return x;
return log(cmul2*x+1.0)/log(cmul2+1.0);
}
float aconv2(float x)
{
return conv2(abs(x))*sign(x)*15.75/31 + off2;
}
float aconv(float x)
{
return conv(abs(x))*sign(x)/2 + off;//float(abs(x) > 0.01);//conv(abs(x))*sign(x)/2 + off;
return conv(abs(x))*sign(x)*31.75/63 + off;
}
float invconv(float x)
{
return (exp(x*log(cmul+1))-1)/cmul;
return x;
return (exp(x*log(cmul+1.0))-1.0)/cmul;
}
float ainvconv(float x)
{
return invconv(x-off)*2;
return invconv(abs(x-off)*2.0)*sign(x-off);
}
float invconv2(float x)
{
return x;
return (exp(x*log(cmul2+1.0))-1.0)/cmul2;
}
float ainvconv2(float x)
{
return invconv2(abs(x-off2)*2.0)*sign(x-off2);
}
void main() {
@ -91,10 +117,10 @@ void main() {
for(int j = 0; j < 2; j++)
{
vec4 r1 = sample4f(gl_GlobalInvocationID.x * 4 + i, gl_GlobalInvocationID.y * 4 + j);
vec4 r2 = sample4f(gl_GlobalInvocationID.x * 4 + i + 1, gl_GlobalInvocationID.y * 4 + j);
vec4 r3 = sample4f(gl_GlobalInvocationID.x * 4 + i, gl_GlobalInvocationID.y * 4 + j + 1);
vec4 r4 = sample4f(gl_GlobalInvocationID.x * 4 + i + 1, gl_GlobalInvocationID.y * 4 + j + 1);
vec4 r1 = sample4f(gl_GlobalInvocationID.x * 4 + i*2, gl_GlobalInvocationID.y * 4 + j*2);
vec4 r2 = sample4f(gl_GlobalInvocationID.x * 4 + i*2 + 1, gl_GlobalInvocationID.y * 4 + j*2);
vec4 r3 = sample4f(gl_GlobalInvocationID.x * 4 + i*2, gl_GlobalInvocationID.y * 4 + j + 1*2);
vec4 r4 = sample4f(gl_GlobalInvocationID.x * 4 + i*2 + 1, gl_GlobalInvocationID.y * 4 + j*2 + 1);
float cy1 = r1.r * 0.2126 + r1.g * 0.7152 + r1.b * 0.0722;
float cy2 = r2.r * 0.2126 + r2.g * 0.7152 + r2.b * 0.0722;
@ -109,10 +135,14 @@ void main() {
float cb1 = ca - cc;
float cc1 = cb + cd;
float cd1 = cb - cd;
float val2 = float(gl_GlobalInvocationID.x * 4 + i*2)/1920*2.0-1.0;
//float val = abs(ainvconv(rn(aconv(val2))));
imageStore(resultImage, ivec2(gl_GlobalInvocationID.x * 2 + i, gl_GlobalInvocationID.y * 2 + j), vec4(ca1/4,0,0,0));
imageStore(reconstructionImage, ivec2(gl_GlobalInvocationID.x * 2 + i, gl_GlobalInvocationID.y * 2 + j), vec4(aconv(cb1),aconv(cc1),aconv(cd1),aconv(cd1)));//cd1/4 + 0.5));
//imageStore(resultImage, ivec2(gl_GlobalInvocationID.x * 2 + i, gl_GlobalInvocationID.y * 2 + j), vec4(r1.r,0,0,0));
// imageStore(reconstructionImage, ivec2(gl_GlobalInvocationID.x * 2 + i, gl_GlobalInvocationID.y * 2 + j), vec4(aconv(val2),aconv(val2),aconv2(val2),1));//vec4(aconv(cb1),aconv(cc1),aconv(cd1),aconv(cd1)));//cd1/4 + 0.5));
imageStore(reconstructionImage, ivec2(gl_GlobalInvocationID.x * 2 + i, gl_GlobalInvocationID.y * 2 + j), vec4(aconv2(cb1),aconv(cd1),aconv2(cc1),1));//cd1/4 + 0.5));
//imageStore(resultImage, ivec2(gl_GlobalInvocationID.x * 2 + i, gl_GlobalInvocationID.y * 2 + j), vec4(r1.r,0,0,0));
//imageStore(reconstructionImage, ivec2(gl_GlobalInvocationID.x * 2 + i, gl_GlobalInvocationID.y * 2 + j), vec4(r2.r,r3.r,r4.r,1));
//vec4(aconv(cb1/2),aconv(cc1/2),aconv(cd1/2),1));//cd1/4 + 0.5));
// if(i == 0 && j == 0)

View file

@ -17,33 +17,63 @@ layout (constant_id = 1) const float height = 1080;
const vec2 in_res = vec2(width,height);
vec4 convertYuv(float y, float u, float v)
{
//return vec4(y,y,y,1);//
// return vec4(y,y,y,1);//
return vec4(y + 1.403*v, y - 0.344*u - 0.714*v, y + 1.770*u,1);
}
const float cmul = 32;
const float off = 31.0/63;//7.0/15;//128.0/255;
float off2 = float(gl_GlobalInvocationID.x) / 960;//136.0/255;
const float cmul = 32.0;
const float off = 31.0/63.0;//7.0/15;//128.0/255;
const float off2 = 15.0/31.0;
float cmul2 = 64;
float conv2(float x)
{
return log(cmul2*x+1.0)/log(cmul2+1.0);
}
float aconv2(float x)
{
return x;
return conv2(abs(x))*sign(x)/2.0 + off2;
}
float conv(float x)
{
return log(cmul*x+1)/log(cmul+1);
return x;
return log(cmul*x+1.0)/log(cmul+1.0);
}
float aconv(float x)
{
return conv(abs(x))*sign(x)/2 + off;
return conv(abs(x))*sign(x)/2.0 + off;
}
float invconv(float x)
{
return (exp(x*log(cmul+1))-1)/cmul;
//return x;
return (exp(x*log(cmul+1.0))-1.0)/cmul;
}
float ainvconv(float x)
{
return invconv(abs(x-off)*2)*sign(x-off);
return invconv(abs(x-off)*63.0/31.75)*sign(x-off);
}
float invconv2(float x)
{
//return x;
return (exp(x*log(cmul2+1.0))-1.0)/cmul2;
}
float ainvconv2(float x)
{
return invconv2(abs(x-off2)*31.0/15.75)*sign(x-off2);
}
float rn(float x)
{
int x1 = int(x*63.0 + 1.0);
return float(x1)/64.0;
}
void main()
{
@ -53,13 +83,13 @@ void main()
#if USE_SAMPLER
vec3 rec = texture(inputImage, uv).rgb;
#else
vec3 rec = vec4(imageLoad(inputImage, gl_GlobalInvocationID.xy).rgb);
vec3 rec = imageLoad(inputImage, ivec2(gl_GlobalInvocationID.xy)).rgb;
#endif
float ca1 = yuv.y*4;
const float off = 128.0/255;
float cb1 = ainvconv(rec.x)*1.1;
float cc1 = ainvconv(rec.y)*1.0;
float cd1 = ainvconv(rec.z)*1.1;
float cb1 = ainvconv2(rec.r);
float cc1 = ainvconv2(rec.b);
float cd1 = ainvconv(rec.g);
float ca = ca1 + cb1;
float cb = cc1 + cd1;
float cc = ca1 - cb1;
@ -72,10 +102,16 @@ void main()
// y2 = 0;//abs(rec.x-off)*4;//float(abs(cb1) > 0.1);
// y3 = 0;//abs(rec.y-off)*4;//float(abs(cc1) > 0.6);
// y4 = abs(rec.z-off2)*4;//
// y1 = 0;//yuv.y;//ca1;
// y2 = abs(cb1)*4;//float(abs(cb1) > 0.6);
// y3 = abs(cc1)*4;//float(abs(cc1) > 0.6);
// y4 = abs(cd1)*4;//float(abs(cd1) > 0.6);
// y1 = abs(float(gl_GlobalInvocationID.x)*2/960.0-1);//yuv.y;//ca1;
// y2 = abs(cc1);//float(abs(cb1) > 0.6);
// y3 = abs(cb1);//abs(cc1)*4;//float(abs(cc1) > 0.6);
// y4 = abs(cd1);//abs(cd1)*4;//float(abs(cd1) > 0.6);
//imageStore(resultImage, ivec2(gl_GlobalInvocationID.x * 2, gl_GlobalInvocationID.y * 2), vec4(y1,y4,y1,1));
//imageStore(resultImage, ivec2(gl_GlobalInvocationID.x * 2 + 1, gl_GlobalInvocationID.y * 2), vec4(y1,y4,y1,1));
//imageStore(resultImage, ivec2(gl_GlobalInvocationID.x * 2, gl_GlobalInvocationID.y * 2 + 1), vec4(y1,y4,y1,1));
//imageStore(resultImage, ivec2(gl_GlobalInvocationID.x * 2 + 1 , gl_GlobalInvocationID.y * 2 + 1),vec4(y1,y4,y1,1));
imageStore(resultImage, ivec2(gl_GlobalInvocationID.x * 2, gl_GlobalInvocationID.y * 2), convertYuv(y1/4, yuv.z, yuv.x));
imageStore(resultImage, ivec2(gl_GlobalInvocationID.x * 2 + 1, gl_GlobalInvocationID.y * 2), convertYuv(y2/4, yuv.z, yuv.x));

View file

@ -407,7 +407,7 @@ struct ComputeApplicationPipeline: BaseVulkanPipeline
BasicBinding(2, VK_DESCRIPTOR_TYPE_STORAGE_IMAGE,1,VK_SHADER_STAGE_COMPUTE_BIT)
);
CreatePool((count1 + count3) * count2,
BasicPoolSize(VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, count2 * count3*2),
BasicPoolSize(VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, count2 * count3*3),
#if USE_SAMPLER
// BasicPoolSize(VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE, count3 * count2 * count1),
BasicPoolSize(VK_DESCRIPTOR_TYPE_STORAGE_IMAGE, count3 * count2 * count1)
@ -429,7 +429,7 @@ struct ComputeApplicationPipeline: BaseVulkanPipeline
{
WriteDescriptors(
ImageWrite(dstSet, 0, ImageDescriptor(imageView, VK_IMAGE_LAYOUT_GENERAL, sampler), VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER),
ImageWrite(dstSet, 1, ImageDescriptor(imageView1, VK_IMAGE_LAYOUT_GENERAL, sampler2), VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER),
ImageWrite(dstSet, 1, ImageDescriptor(imageView1, VK_IMAGE_LAYOUT_GENERAL, sampler2), USE_SAMPLER?VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER:VK_DESCRIPTOR_TYPE_STORAGE_IMAGE),
ImageWrite(dstSet, 2, ImageDescriptor(imageView2, VK_IMAGE_LAYOUT_GENERAL)));
}
};