Skip to content

Commit

Permalink
Revert "BGR(A) image format support (#7238)"
Browse files Browse the repository at this point in the history
This reverts commit 1cd91ff.
  • Loading branch information
emilk committed Aug 28, 2024
1 parent 98696ba commit ec9d0a0
Show file tree
Hide file tree
Showing 28 changed files with 107 additions and 400 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,4 @@ enum ColorModel: ubyte{

/// Red, Green, Blue, Alpha
RGBA = 3,

/// Blue, Green, Red
BGR,

/// Blue, Green, Red, Alpha
BGRA,
}
4 changes: 2 additions & 2 deletions crates/store/re_types/src/archetypes/image_ext.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,10 @@ impl Image {

let is_shape_correct = match color_model {
ColorModel::L => non_empty_dim_inds.len() == 2,
ColorModel::RGB | ColorModel::BGR => {
ColorModel::RGB => {
non_empty_dim_inds.len() == 3 && shape[non_empty_dim_inds[2]].size == 3
}
ColorModel::RGBA | ColorModel::BGRA => {
ColorModel::RGBA => {
non_empty_dim_inds.len() == 3 && shape[non_empty_dim_inds[2]].size == 4
}
};
Expand Down
16 changes: 1 addition & 15 deletions crates/store/re_types/src/datatypes/color_model.rs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions crates/store/re_types/src/datatypes/color_model_ext.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,17 @@ impl ColorModel {
pub fn num_channels(self) -> usize {
match self {
Self::L => 1,
Self::RGB | Self::BGR => 3,
Self::RGBA | Self::BGRA => 4,
Self::RGB => 3,
Self::RGBA => 4,
}
}

/// Do we have an alpha channel?
#[inline]
pub fn has_alpha(&self) -> bool {
match self {
Self::L | Self::RGB | Self::BGR => false,
Self::RGBA | Self::BGRA => true,
Self::L | Self::RGB => false,
Self::RGBA => true,
}
}
}
46 changes: 0 additions & 46 deletions crates/viewer/re_data_ui/src/image.rs
Original file line number Diff line number Diff line change
Expand Up @@ -421,52 +421,6 @@ fn image_pixel_value_ui(
None
}
}

ColorModel::BGR => {
if let Some([b, g, r]) = {
if let [Some(b), Some(g), Some(r)] = [
image.get_xyc(x, y, 0),
image.get_xyc(x, y, 1),
image.get_xyc(x, y, 2),
] {
Some([r, g, b])
} else {
None
}
} {
match (b, g, r) {
(TensorElement::U8(b), TensorElement::U8(g), TensorElement::U8(r)) => {
Some(format!("B: {b}, G: {g}, R: {r}, #{b:02X}{g:02X}{r:02X}"))
}
_ => Some(format!("B: {b}, G: {g}, R: {r}")),
}
} else {
None
}
}

ColorModel::BGRA => {
if let (Some(b), Some(g), Some(r), Some(a)) = (
image.get_xyc(x, y, 0),
image.get_xyc(x, y, 1),
image.get_xyc(x, y, 2),
image.get_xyc(x, y, 3),
) {
match (b, g, r, a) {
(
TensorElement::U8(b),
TensorElement::U8(g),
TensorElement::U8(r),
TensorElement::U8(a),
) => Some(format!(
"B: {b}, G: {g}, R: {r}, A: {a}, #{r:02X}{g:02X}{b:02X}{a:02X}"
)),
_ => Some(format!("B: {b}, G: {g}, R: {r}, A: {a}")),
}
} else {
None
}
}
},
};

Expand Down
3 changes: 0 additions & 3 deletions crates/viewer/re_renderer/shader/rectangle.wgsl
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,6 @@ struct UniformBuffer {

/// Boolean: multiply RGB with alpha before filtering
multiply_rgb_with_alpha: u32,

/// Boolean: swizzle RGBA to BGRA
bgra_to_rgba: u32,
};

@group(1) @binding(0)
Expand Down
5 changes: 0 additions & 5 deletions crates/viewer/re_renderer/shader/rectangle_fs.wgsl
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,6 @@ fn decode_color(sampled_value: vec4f) -> vec4f {
// Normalize the value first, otherwise premultiplying alpha and linear space conversion won't make sense.
var rgba = normalize_range(sampled_value);

// BGR(A) -> RGB(A)
if rect_info.bgra_to_rgba != 0u {
rgba = rgba.bgra;
}

// Convert to linear space
if rect_info.decode_srgb != 0u {
if all(vec3f(0.0) <= rgba.rgb) && all(rgba.rgb <= vec3f(1.0)) {
Expand Down
11 changes: 2 additions & 9 deletions crates/viewer/re_renderer/src/renderer/rectangles.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,6 @@ pub enum TextureFilterMin {
pub enum ShaderDecoding {
Nv12,
Yuy2,

/// BGR(A)->RGB(A) conversion is done in the shader.
/// (as opposed to doing it via ``)
Bgr,
}

/// Describes a texture and how to map it to a color.
Expand Down Expand Up @@ -155,7 +151,7 @@ impl ColormappedTexture {
let [width, height] = self.texture.width_height();
[width / 2, height]
}
Some(ShaderDecoding::Bgr) | None => self.texture.width_height(),
_ => self.texture.width_height(),
}
}
}
Expand Down Expand Up @@ -279,8 +275,7 @@ mod gpu_data {

decode_srgb: u32,
multiply_rgb_with_alpha: u32,
bgra_to_rgba: u32,
_row_padding: [u32; 1],
_row_padding: [u32; 2],

_end_padding: [wgpu_buffer_types::PaddingRow; 16 - 7],
}
Expand Down Expand Up @@ -367,7 +362,6 @@ mod gpu_data {
super::TextureFilterMag::Linear => FILTER_BILINEAR,
super::TextureFilterMag::Nearest => FILTER_NEAREST,
};
let bgra_to_rgba = shader_decoding == &Some(super::ShaderDecoding::Bgr);

Ok(Self {
top_left_corner_position: (*top_left_corner_position).into(),
Expand All @@ -385,7 +379,6 @@ mod gpu_data {
magnification_filter,
decode_srgb: *decode_srgb as _,
multiply_rgb_with_alpha: *multiply_rgb_with_alpha as _,
bgra_to_rgba: bgra_to_rgba as _,
_row_padding: Default::default(),
_end_padding: Default::default(),
})
Expand Down
66 changes: 16 additions & 50 deletions crates/viewer/re_space_view_spatial/src/mesh_loader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -150,19 +150,26 @@ impl LoadedMesh {
re_math::BoundingBox::from_points(vertex_positions.iter().copied())
};

let albedo = try_get_or_create_albedo_texture(
albedo_texture_buffer,
albedo_texture_format,
render_ctx,
texture_key,
&name,
)
.unwrap_or_else(|| {
let albedo = if let (Some(albedo_texture_buffer), Some(albedo_texture_format)) =
(&albedo_texture_buffer, albedo_texture_format)
{
let image_info = ImageInfo {
buffer_row_id: RowId::ZERO, // unused
buffer: albedo_texture_buffer.0.clone(),
format: albedo_texture_format.0,
kind: re_types::image::ImageKind::Color,
colormap: None,
};
re_viewer_context::gpu_bridge::get_or_create_texture(render_ctx, texture_key, || {
let debug_name = "mesh albedo texture";
texture_creation_desc_from_color_image(&image_info, debug_name)
})?
} else {
render_ctx
.texture_manager_2d
.white_texture_unorm_handle()
.clone()
});
};

let mesh = re_renderer::mesh::Mesh {
label: name.clone().into(),
Expand Down Expand Up @@ -204,44 +211,3 @@ impl LoadedMesh {
self.bbox
}
}

fn try_get_or_create_albedo_texture(
albedo_texture_buffer: &Option<re_types::components::ImageBuffer>,
albedo_texture_format: &Option<re_types::components::ImageFormat>,
render_ctx: &RenderContext,
texture_key: u64,
name: &str,
) -> Option<re_renderer::resource_managers::GpuTexture2D> {
let (Some(albedo_texture_buffer), Some(albedo_texture_format)) =
(&albedo_texture_buffer, albedo_texture_format)
else {
return None;
};

let image_info = ImageInfo {
buffer_row_id: RowId::ZERO, // unused
buffer: albedo_texture_buffer.0.clone(),
format: albedo_texture_format.0,
kind: re_types::image::ImageKind::Color,
colormap: None,
};

if re_viewer_context::gpu_bridge::required_shader_decode(albedo_texture_format).is_some() {
re_log::warn_once!("Mesh can't yet handle encoded image formats like NV12 & YUY2 or BGR(A) formats without a channel type other than U8. Ignoring the texture at {name:?}.");
return None;
}

let texture =
re_viewer_context::gpu_bridge::get_or_create_texture(render_ctx, texture_key, || {
let debug_name = "mesh albedo texture";
texture_creation_desc_from_color_image(&image_info, debug_name)
});

match texture {
Ok(texture) => Some(texture),
Err(err) => {
re_log::warn_once!("Failed to create mesh albedo texture for {name:?}: {err}");
None
}
}
}
Loading

0 comments on commit ec9d0a0

Please sign in to comment.