Fix colorspace on headset
This commit is contained in:
@@ -63,7 +63,7 @@ struct wivrn::android::decoder::pipeline_context
|
|||||||
vkDestroySamplerYcbcrConversion(device, ycbcr_conversion, nullptr);
|
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)
|
device(device), ahb_format(ahb_format)
|
||||||
{
|
{
|
||||||
assert(ahb_format.externalFormat != 0);
|
assert(ahb_format.externalFormat != 0);
|
||||||
@@ -102,6 +102,11 @@ struct wivrn::android::decoder::pipeline_context
|
|||||||
.yChromaOffset = ahb_format.suggestedYChromaOffset,
|
.yChromaOffset = ahb_format.suggestedYChromaOffset,
|
||||||
.chromaFilter = yuv_filter,
|
.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));
|
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)))
|
if (!pipeline || memcmp(&pipeline->ahb_format, &format_properties, sizeof(format_properties)))
|
||||||
{
|
{
|
||||||
pipeline.reset();
|
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();
|
hardware_buffer_map.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -46,8 +46,25 @@ layout(location = 0) in vec2 inUV;
|
|||||||
|
|
||||||
layout(location = 0) out vec4 outColor;
|
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()
|
void main()
|
||||||
{
|
{
|
||||||
outColor = texture(texSampler, inUV);
|
outColor = sRGB_to_linear_rgba(texture(texSampler, inUV));
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -181,6 +181,8 @@ struct video_stream_description
|
|||||||
uint16_t offset_x;
|
uint16_t offset_x;
|
||||||
uint16_t offset_y;
|
uint16_t offset_y;
|
||||||
video_codec codec;
|
video_codec codec;
|
||||||
|
std::optional<uint32_t> range; // VkSamplerYcbcrRange
|
||||||
|
std::optional<uint32_t> color_model; // VkSamplerYcbcrModelConversion
|
||||||
};
|
};
|
||||||
uint16_t width;
|
uint16_t width;
|
||||||
uint16_t height;
|
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));
|
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() {
|
void main() {
|
||||||
vec4 rgba = gamma4(texture(image, pos));
|
vec4 rgba = gamma4(texture(image, pos));
|
||||||
uv.x = reduce_range(rgba.r * -0.1146 + rgba.g * -0.3854 + rgba.b * 0.5);
|
uv.x = 0.5 + 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.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));
|
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() {
|
void main() {
|
||||||
vec4 rgba = gamma4(texture(image, pos));
|
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;
|
param.b_aud = 0;
|
||||||
|
|
||||||
// colour definitions, actually ignored by decoder
|
// colour definitions, actually ignored by decoder
|
||||||
using namespace to_headset;
|
param.vui.b_fullrange = 1;
|
||||||
param.vui.b_fullrange = 0;
|
settings.range = VK_SAMPLER_YCBCR_RANGE_ITU_FULL;
|
||||||
param.vui.i_colorprim = 1; // BT.709
|
param.vui.i_colorprim = 1; // BT.709
|
||||||
param.vui.i_colmatrix = 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_transfer = 13; // sRGB
|
||||||
|
|
||||||
param.vui.i_sar_width = settings.width;
|
param.vui.i_sar_width = settings.width;
|
||||||
|
|||||||
Reference in New Issue
Block a user