diff options
author | Arun Kumar K.R <akumarkr@codeaurora.org> | 2017-02-16 19:12:20 -0800 |
---|---|---|
committer | Sushil Chauhan <sushilchauhan@codeaurora.org> | 2017-05-07 12:10:23 -0700 |
commit | 1d1e57dc0e959f8c84be8913cf3d651ed3de49e0 (patch) | |
tree | c948bd85bea08e8d21163bf9b03bb535cf3cdca6 /gpu_tonemapper | |
parent | f0b7c337ecf7c567eb5c85fec249a7a65a846206 (diff) | |
download | display-1d1e57dc0e959f8c84be8913cf3d651ed3de49e0.tar.gz |
gpu_tonemapper: Adjust sample points to maintain linearity
Adjust texture sample points to maintain linearity throughout the
sample range
CRs-Fixed: 1110654
Change-Id: I2c198c9f330a0b6001d2eda28c0355f2c9ecbde4
Diffstat (limited to 'gpu_tonemapper')
-rw-r--r-- | gpu_tonemapper/Tonemapper.cpp | 21 | ||||
-rw-r--r-- | gpu_tonemapper/Tonemapper.h | 2 | ||||
-rw-r--r-- | gpu_tonemapper/engine.h | 1 | ||||
-rw-r--r-- | gpu_tonemapper/forward_tonemap.inl | 26 | ||||
-rw-r--r-- | gpu_tonemapper/glengine.cpp | 7 | ||||
-rw-r--r-- | gpu_tonemapper/rgba_inverse_tonemap.inl | 26 |
6 files changed, 67 insertions, 16 deletions
diff --git a/gpu_tonemapper/Tonemapper.cpp b/gpu_tonemapper/Tonemapper.cpp index ec74b801..38b4fe2a 100644 --- a/gpu_tonemapper/Tonemapper.cpp +++ b/gpu_tonemapper/Tonemapper.cpp @@ -33,6 +33,12 @@ Tonemapper::Tonemapper() lutXformTexture = 0; programID = 0; eglImageWrapper = new EGLImageWrapper(); + + lutXformScaleOffset[0] = 1.0f; + lutXformScaleOffset[1] = 0.0f; + + tonemapScaleOffset[0] = 1.0f; + tonemapScaleOffset[1] = 0.0f; } //----------------------------------------------------------------------------- @@ -72,9 +78,17 @@ Tonemapper *Tonemapper::build(int type, void *colorMap, int colorMapSize, void * // load the 3d lut tonemapper->tonemapTexture = engine_load3DTexture(colorMap, colorMapSize, 0); + tonemapper->tonemapScaleOffset[0] = ((float)(colorMapSize-1))/((float)(colorMapSize)); + tonemapper->tonemapScaleOffset[1] = 1.0f/(2.0f*colorMapSize); + // load the non-uniform xform tonemapper->lutXformTexture = engine_load1DTexture(lutXform, lutXformSize, 0); bool bUseXform = (tonemapper->lutXformTexture != 0) && (lutXformSize != 0); + if( bUseXform ) + { + tonemapper->lutXformScaleOffset[0] = ((float)(lutXformSize-1))/((float)(lutXformSize)); + tonemapper->lutXformScaleOffset[1] = 1.0f/(2.0f*lutXformSize); + } // create the program const char *fragmentShaders[3]; @@ -115,6 +129,13 @@ int Tonemapper::blit(const void *dst, const void *src, int srcFenceFd) // bind the program engine_setProgram(programID); + engine_setData2f(3, tonemapScaleOffset); + bool bUseXform = (lutXformTexture != 0); + if( bUseXform ) + { + engine_setData2f(4, lutXformScaleOffset); + } + // set destination engine_setDestination(dst_buffer->getFramebuffer(), 0, 0, dst_buffer->getWidth(), dst_buffer->getHeight()); diff --git a/gpu_tonemapper/Tonemapper.h b/gpu_tonemapper/Tonemapper.h index 1d6f8080..88866d5f 100644 --- a/gpu_tonemapper/Tonemapper.h +++ b/gpu_tonemapper/Tonemapper.h @@ -32,6 +32,8 @@ class Tonemapper { unsigned int tonemapTexture; unsigned int lutXformTexture; unsigned int programID; + float lutXformScaleOffset[2]; + float tonemapScaleOffset[2]; EGLImageWrapper* eglImageWrapper; Tonemapper(); diff --git a/gpu_tonemapper/engine.h b/gpu_tonemapper/engine.h index ca914b27..c07f13e7 100644 --- a/gpu_tonemapper/engine.h +++ b/gpu_tonemapper/engine.h @@ -36,6 +36,7 @@ void engine_set2DInputBuffer(int binding, unsigned int textureID); void engine_set3DInputBuffer(int binding, unsigned int textureID); void engine_setExternalInputBuffer(int binding, unsigned int textureID); void engine_setDestination(int id, int x, int y, int w, int h); +void engine_setData2f(int loc, float* data); int engine_blit(int); diff --git a/gpu_tonemapper/forward_tonemap.inl b/gpu_tonemapper/forward_tonemap.inl index db23cf1f..0d89a9ea 100644 --- a/gpu_tonemapper/forward_tonemap.inl +++ b/gpu_tonemapper/forward_tonemap.inl @@ -1,5 +1,5 @@ /* - * Copyright (c) 2016, The Linux Foundation. All rights reserved. + * Copyright (c) 2016-2017, The Linux Foundation. All rights reserved. * Not a Contribution. * * Copyright 2015 The Android Open Source Project @@ -24,22 +24,32 @@ const char* forward_tonemap_shader = "" "layout(binding = 0) uniform samplerExternalOES externalTexture; \n" "layout(binding = 1) uniform sampler3D tonemapper; \n" "layout(binding = 2) uniform sampler2D xform; \n" + "layout(location = 3) uniform vec2 tSO; \n" + "#ifdef USE_NONUNIFORM_SAMPLING \n" + "layout(location = 4) uniform vec2 xSO; \n" + "#endif \n" "in vec2 uv; \n" "out vec4 fs_color; \n" + " \n" + "vec3 ScaleOffset(in vec3 samplePt, in vec2 so) \n" + "{ \n" + " vec3 adjPt = so.x * samplePt + so.y; \n" + " return adjPt; \n" + "} \n" + " \n" "void main() \n" "{ \n" - "vec2 flipped = uv; \n" - "flipped.y = 1.0 - flipped.y; \n" - "flipped.x = flipped.x; \n" + "vec2 flipped = vec2(uv.x, 1.0f - uv.y); \n" "vec4 rgb = texture(externalTexture, flipped); \n" "#ifdef USE_NONUNIFORM_SAMPLING \n" - "float r = texture(xform, vec2(r, 0.0f)).r; \n" - "float g = texture(xform, vec2(g, 0.0f)).g; \n" - "float b = texture(xform, vec2(b, 0.0f)).b; \n" + "vec3 adj = ScaleOffset(rgb.xyz, xSO); \n" + "float r = texture(xform, vec2(adj.r, 0.5f)).r; \n" + "float g = texture(xform, vec2(adj.g, 0.5f)).g; \n" + "float b = texture(xform, vec2(adj.b, 0.5f)).b; \n" "#else \n" "float r = rgb.r; \n" "float g = rgb.g; \n" "float b = rgb.b; \n" "#endif \n" - "fs_color.rgb = texture(tonemapper, vec3(r, g, b)).rgb; \n" + "fs_color.rgb = texture(tonemapper, ScaleOffset(vec3(r, g, b), tSO)).rgb; \n" "} \n"; diff --git a/gpu_tonemapper/glengine.cpp b/gpu_tonemapper/glengine.cpp index eda4e6b6..7a970c5d 100644 --- a/gpu_tonemapper/glengine.cpp +++ b/gpu_tonemapper/glengine.cpp @@ -121,6 +121,13 @@ void engine_deleteProgram(unsigned int id) } //----------------------------------------------------------------------------- +void engine_setData2f(int location, float* data) +//----------------------------------------------------------------------------- +{ + GL(glUniform2f(location, data[0], data[1])); +} + +//----------------------------------------------------------------------------- unsigned int engine_load3DTexture(void *colorMapData, int sz, int format) //----------------------------------------------------------------------------- { diff --git a/gpu_tonemapper/rgba_inverse_tonemap.inl b/gpu_tonemapper/rgba_inverse_tonemap.inl index 399e2f8b..2865fbe0 100644 --- a/gpu_tonemapper/rgba_inverse_tonemap.inl +++ b/gpu_tonemapper/rgba_inverse_tonemap.inl @@ -1,5 +1,5 @@ /* - * Copyright (c) 2016, The Linux Foundation. All rights reserved. + * Copyright (c) 2016-2017, The Linux Foundation. All rights reserved. * Not a Contribution. * * Copyright 2015 The Android Open Source Project @@ -24,27 +24,37 @@ const char* rgba_inverse_tonemap_shader = "" "layout(binding = 0) uniform samplerExternalOES externalTexture; \n" "layout(binding = 1) uniform sampler3D tonemapper; \n" "layout(binding = 2) uniform sampler2D xform; \n" + "layout(location = 3) uniform vec2 tSO; \n" + "#if defined(USE_NONUNIFORM_SAMPLING) \n" + "layout(location = 4) uniform vec2 xSO; \n" + "#endif \n" "in vec2 uv; \n" "out vec4 fs_color; \n" + " \n" + "vec3 ScaleOffset(in vec3 samplePt, in vec2 so) \n" + "{ \n" + " vec3 adjPt = so.x * samplePt + so.y; \n" + " return adjPt; \n" + "} \n" + " \n" "void main() \n" "{ \n" - "vec2 flipped = uv; \n" - "flipped.y = 1.0 - flipped.y; \n" - "flipped.x = flipped.x; \n" + "vec2 flipped = vec2(uv.x, 1.0f - uv.y); \n" "vec4 rgb_premulalpha = texture(externalTexture, flipped); \n" "fs_color = rgb_premulalpha; \n" "if( rgb_premulalpha.a > 0.0 ) { \n" "vec3 rgb = rgb_premulalpha.rgb/rgb_premulalpha.a; \n" "#if defined(USE_NONUNIFORM_SAMPLING) \n" - "float r = texture(xform, vec2(rgb.r, 0.0f)).r; \n" - "float g = texture(xform, vec2(rgb.g, 0.0f)).g; \n" - "float b = texture(xform, vec2(rgb.b, 0.0f)).b; \n" + "vec3 adj = ScaleOffset(rgb.xyz, xSO); \n" + "float r = texture(xform, vec2(adj.r, 0.5f)).r; \n" + "float g = texture(xform, vec2(adj.g, 0.5f)).g; \n" + "float b = texture(xform, vec2(adj.b, 0.5f)).b; \n" "#else \n" "float r = rgb.r; \n" "float g = rgb.g; \n" "float b = rgb.b; \n" "#endif \n" - "fs_color.rgb = texture(tonemapper, vec3(r, g, b)).rgb * rgb_premulalpha.a; \n" + "fs_color.rgb = texture(tonemapper, ScaleOffset(vec3(r, g, b), tSO)).rgb * rgb_premulalpha.a; \n" "fs_color.a = rgb_premulalpha.a; \n" "} \n" "} \n"; |