mirror of
https://github.com/WiVRn/WiVRn.git
synced 2026-11-28 04:46:55 -08:00
Fix colorspace on headset
This commit is contained in:
1 parent
9dce5e933b
commit
dc7f2cda21
6 files changed
+33
-18
No files matched your search
@@ -63,7 +63,7 @@ struct wivrn::android::decoder::pipeline_context
|
||||
vkDestroySamplerYcbcrConversion(device, ycbcr_conversion, nullptr);
|
||||
}
|
||||
|
||||
pipeline_context(VkDevice device, VkAndroidHardwareBufferFormatPropertiesANDROID & ahb_format, VkRenderPass renderpass) :
|
||||
pipeline_context(VkDevice device, VkAndroidHardwareBufferFormatPropertiesANDROID & ahb_format, VkRenderPass renderpass, const to_headset::video_stream_description::item& description) :
|
||||
device(device), ahb_format(ahb_format)
|
||||
{
|
||||
assert(ahb_format.externalFormat != 0);
|
||||
@@ -102,6 +102,11 @@ struct wivrn::android::decoder::pipeline_context
|
||||
.yChromaOffset = ahb_format.suggestedYChromaOffset,
|
||||
.chromaFilter = yuv_filter,
|
||||
};
|
||||
// suggested values from decoder don't actually read the metadata, so it's garbage
|
||||
if (description.range)
|
||||
ycbcr_create_info.ycbcrRange = VkSamplerYcbcrRange(*description.range);
|
||||
if (description.color_model)
|
||||
ycbcr_create_info.ycbcrModel = VkSamplerYcbcrModelConversion(*description.color_model);
|
||||
|
||||
CHECK_VK(vkCreateSamplerYcbcrConversion(device, &ycbcr_create_info, nullptr, &ycbcr_conversion));
|
||||
|
||||
@@ -615,7 +620,7 @@ std::shared_ptr<decoder::mapped_hardware_buffer> decoder::map_hardware_buffer(AI
|
||||
if (!pipeline || memcmp(&pipeline->ahb_format, &format_properties, sizeof(format_properties)))
|
||||
{
|
||||
pipeline.reset();
|
||||
pipeline = std::make_shared<pipeline_context>(device, format_properties, renderpass);
|
||||
pipeline = std::make_shared<pipeline_context>(device, format_properties, renderpass, description);
|
||||
hardware_buffer_map.clear();
|
||||
}
|
||||
|
||||
|
||||
@@ -46,8 +46,25 @@ layout(location = 0) in vec2 inUV;
|
||||
|
||||
layout(location = 0) out vec4 outColor;
|
||||
|
||||
float sRGB_to_linear(float x)
|
||||
{
|
||||
if (x <= 0.04045)
|
||||
return x / 12.92;
|
||||
return pow((x + 0.055) / 1.055, 2.4);
|
||||
}
|
||||
|
||||
vec4 sRGB_to_linear_rgba(vec4 x)
|
||||
{
|
||||
return vec4(
|
||||
sRGB_to_linear(x.r),
|
||||
sRGB_to_linear(x.g),
|
||||
sRGB_to_linear(x.b),
|
||||
x.a
|
||||
);
|
||||
}
|
||||
|
||||
void main()
|
||||
{
|
||||
outColor = texture(texSampler, inUV);
|
||||
outColor = sRGB_to_linear_rgba(texture(texSampler, inUV));
|
||||
}
|
||||
#endif
|
||||
@@ -181,6 +181,8 @@ struct video_stream_description
|
||||
uint16_t offset_x;
|
||||
uint16_t offset_y;
|
||||
video_codec codec;
|
||||
std::optional<uint32_t> range; // VkSamplerYcbcrRange
|
||||
std::optional<uint32_t> color_model; // VkSamplerYcbcrModelConversion
|
||||
};
|
||||
uint16_t width;
|
||||
uint16_t height;
|
||||
|
||||
@@ -38,14 +38,9 @@ vec4 gamma4(vec4 x)
|
||||
return vec4(gamma(x.r), gamma(x.g), gamma(x.b), gamma(x.a));
|
||||
}
|
||||
|
||||
float reduce_range(float x)
|
||||
{
|
||||
return (128 + x * 224) / 256;
|
||||
}
|
||||
|
||||
void main() {
|
||||
vec4 rgba = gamma4(texture(image, pos));
|
||||
uv.x = reduce_range(rgba.r * -0.1146 + rgba.g * -0.3854 + rgba.b * 0.5);
|
||||
uv.y = reduce_range(rgba.r * 0.5 + rgba.g * -0.4542 + rgba.b * -0.0458);
|
||||
uv.x = 0.5 + rgba.r * -0.1146 + rgba.g * -0.3854 + rgba.b * 0.5;
|
||||
uv.y = 0.5 + rgba.r * 0.5 + rgba.g * -0.4542 + rgba.b * -0.0458;
|
||||
}
|
||||
|
||||
@@ -38,12 +38,7 @@ vec4 gamma4(vec4 x)
|
||||
return vec4(gamma(x.r), gamma(x.g), gamma(x.b), gamma(x.a));
|
||||
}
|
||||
|
||||
float reduce_range(float x)
|
||||
{
|
||||
return (16 + x * 219) / 256;
|
||||
}
|
||||
|
||||
void main() {
|
||||
vec4 rgba = gamma4(texture(image, pos));
|
||||
y = reduce_range(rgba.r * 0.2126 + rgba.g * 0.7152 + rgba.b * 0.0722);
|
||||
y = rgba.r * 0.2126 + rgba.g * 0.7152 + rgba.b * 0.0722;
|
||||
}
|
||||
@@ -114,10 +114,11 @@ VideoEncoderX264::VideoEncoderX264(
|
||||
param.b_aud = 0;
|
||||
|
||||
// colour definitions, actually ignored by decoder
|
||||
using namespace to_headset;
|
||||
param.vui.b_fullrange = 0;
|
||||
param.vui.b_fullrange = 1;
|
||||
settings.range = VK_SAMPLER_YCBCR_RANGE_ITU_FULL;
|
||||
param.vui.i_colorprim = 1; // BT.709
|
||||
param.vui.i_colmatrix = 1; // BT.709
|
||||
settings.color_model = VK_SAMPLER_YCBCR_MODEL_CONVERSION_YCBCR_709;
|
||||
param.vui.i_transfer = 13; // sRGB
|
||||
|
||||
param.vui.i_sar_width = settings.width;
|
||||
|
||||
Reference in new issue
Block a user