Skip to content

Commit ec9d0a0

Browse files
committed
Revert "BGR(A) image format support (#7238)"
This reverts commit 1cd91ff.
1 parent 98696ba commit ec9d0a0

File tree

28 files changed

+107
-400
lines changed

28 files changed

+107
-400
lines changed

crates/store/re_types/definitions/rerun/datatypes/color_model.fbs

-6
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,4 @@ enum ColorModel: ubyte{
1515

1616
/// Red, Green, Blue, Alpha
1717
RGBA = 3,
18-
19-
/// Blue, Green, Red
20-
BGR,
21-
22-
/// Blue, Green, Red, Alpha
23-
BGRA,
2418
}

crates/store/re_types/src/archetypes/image_ext.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,10 @@ impl Image {
3939

4040
let is_shape_correct = match color_model {
4141
ColorModel::L => non_empty_dim_inds.len() == 2,
42-
ColorModel::RGB | ColorModel::BGR => {
42+
ColorModel::RGB => {
4343
non_empty_dim_inds.len() == 3 && shape[non_empty_dim_inds[2]].size == 3
4444
}
45-
ColorModel::RGBA | ColorModel::BGRA => {
45+
ColorModel::RGBA => {
4646
non_empty_dim_inds.len() == 3 && shape[non_empty_dim_inds[2]].size == 4
4747
}
4848
};

crates/store/re_types/src/datatypes/color_model.rs

+1-15
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/store/re_types/src/datatypes/color_model_ext.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -8,17 +8,17 @@ impl ColorModel {
88
pub fn num_channels(self) -> usize {
99
match self {
1010
Self::L => 1,
11-
Self::RGB | Self::BGR => 3,
12-
Self::RGBA | Self::BGRA => 4,
11+
Self::RGB => 3,
12+
Self::RGBA => 4,
1313
}
1414
}
1515

1616
/// Do we have an alpha channel?
1717
#[inline]
1818
pub fn has_alpha(&self) -> bool {
1919
match self {
20-
Self::L | Self::RGB | Self::BGR => false,
21-
Self::RGBA | Self::BGRA => true,
20+
Self::L | Self::RGB => false,
21+
Self::RGBA => true,
2222
}
2323
}
2424
}

crates/viewer/re_data_ui/src/image.rs

-46
Original file line numberDiff line numberDiff line change
@@ -421,52 +421,6 @@ fn image_pixel_value_ui(
421421
None
422422
}
423423
}
424-
425-
ColorModel::BGR => {
426-
if let Some([b, g, r]) = {
427-
if let [Some(b), Some(g), Some(r)] = [
428-
image.get_xyc(x, y, 0),
429-
image.get_xyc(x, y, 1),
430-
image.get_xyc(x, y, 2),
431-
] {
432-
Some([r, g, b])
433-
} else {
434-
None
435-
}
436-
} {
437-
match (b, g, r) {
438-
(TensorElement::U8(b), TensorElement::U8(g), TensorElement::U8(r)) => {
439-
Some(format!("B: {b}, G: {g}, R: {r}, #{b:02X}{g:02X}{r:02X}"))
440-
}
441-
_ => Some(format!("B: {b}, G: {g}, R: {r}")),
442-
}
443-
} else {
444-
None
445-
}
446-
}
447-
448-
ColorModel::BGRA => {
449-
if let (Some(b), Some(g), Some(r), Some(a)) = (
450-
image.get_xyc(x, y, 0),
451-
image.get_xyc(x, y, 1),
452-
image.get_xyc(x, y, 2),
453-
image.get_xyc(x, y, 3),
454-
) {
455-
match (b, g, r, a) {
456-
(
457-
TensorElement::U8(b),
458-
TensorElement::U8(g),
459-
TensorElement::U8(r),
460-
TensorElement::U8(a),
461-
) => Some(format!(
462-
"B: {b}, G: {g}, R: {r}, A: {a}, #{r:02X}{g:02X}{b:02X}{a:02X}"
463-
)),
464-
_ => Some(format!("B: {b}, G: {g}, R: {r}, A: {a}")),
465-
}
466-
} else {
467-
None
468-
}
469-
}
470424
},
471425
};
472426

crates/viewer/re_renderer/shader/rectangle.wgsl

-3
Original file line numberDiff line numberDiff line change
@@ -59,9 +59,6 @@ struct UniformBuffer {
5959

6060
/// Boolean: multiply RGB with alpha before filtering
6161
multiply_rgb_with_alpha: u32,
62-
63-
/// Boolean: swizzle RGBA to BGRA
64-
bgra_to_rgba: u32,
6562
};
6663

6764
@group(1) @binding(0)

crates/viewer/re_renderer/shader/rectangle_fs.wgsl

-5
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,6 @@ fn decode_color(sampled_value: vec4f) -> vec4f {
2828
// Normalize the value first, otherwise premultiplying alpha and linear space conversion won't make sense.
2929
var rgba = normalize_range(sampled_value);
3030

31-
// BGR(A) -> RGB(A)
32-
if rect_info.bgra_to_rgba != 0u {
33-
rgba = rgba.bgra;
34-
}
35-
3631
// Convert to linear space
3732
if rect_info.decode_srgb != 0u {
3833
if all(vec3f(0.0) <= rgba.rgb) && all(rgba.rgb <= vec3f(1.0)) {

crates/viewer/re_renderer/src/renderer/rectangles.rs

+2-9
Original file line numberDiff line numberDiff line change
@@ -51,10 +51,6 @@ pub enum TextureFilterMin {
5151
pub enum ShaderDecoding {
5252
Nv12,
5353
Yuy2,
54-
55-
/// BGR(A)->RGB(A) conversion is done in the shader.
56-
/// (as opposed to doing it via ``)
57-
Bgr,
5854
}
5955

6056
/// Describes a texture and how to map it to a color.
@@ -155,7 +151,7 @@ impl ColormappedTexture {
155151
let [width, height] = self.texture.width_height();
156152
[width / 2, height]
157153
}
158-
Some(ShaderDecoding::Bgr) | None => self.texture.width_height(),
154+
_ => self.texture.width_height(),
159155
}
160156
}
161157
}
@@ -279,8 +275,7 @@ mod gpu_data {
279275

280276
decode_srgb: u32,
281277
multiply_rgb_with_alpha: u32,
282-
bgra_to_rgba: u32,
283-
_row_padding: [u32; 1],
278+
_row_padding: [u32; 2],
284279

285280
_end_padding: [wgpu_buffer_types::PaddingRow; 16 - 7],
286281
}
@@ -367,7 +362,6 @@ mod gpu_data {
367362
super::TextureFilterMag::Linear => FILTER_BILINEAR,
368363
super::TextureFilterMag::Nearest => FILTER_NEAREST,
369364
};
370-
let bgra_to_rgba = shader_decoding == &Some(super::ShaderDecoding::Bgr);
371365

372366
Ok(Self {
373367
top_left_corner_position: (*top_left_corner_position).into(),
@@ -385,7 +379,6 @@ mod gpu_data {
385379
magnification_filter,
386380
decode_srgb: *decode_srgb as _,
387381
multiply_rgb_with_alpha: *multiply_rgb_with_alpha as _,
388-
bgra_to_rgba: bgra_to_rgba as _,
389382
_row_padding: Default::default(),
390383
_end_padding: Default::default(),
391384
})

crates/viewer/re_space_view_spatial/src/mesh_loader.rs

+16-50
Original file line numberDiff line numberDiff line change
@@ -150,19 +150,26 @@ impl LoadedMesh {
150150
re_math::BoundingBox::from_points(vertex_positions.iter().copied())
151151
};
152152

153-
let albedo = try_get_or_create_albedo_texture(
154-
albedo_texture_buffer,
155-
albedo_texture_format,
156-
render_ctx,
157-
texture_key,
158-
&name,
159-
)
160-
.unwrap_or_else(|| {
153+
let albedo = if let (Some(albedo_texture_buffer), Some(albedo_texture_format)) =
154+
(&albedo_texture_buffer, albedo_texture_format)
155+
{
156+
let image_info = ImageInfo {
157+
buffer_row_id: RowId::ZERO, // unused
158+
buffer: albedo_texture_buffer.0.clone(),
159+
format: albedo_texture_format.0,
160+
kind: re_types::image::ImageKind::Color,
161+
colormap: None,
162+
};
163+
re_viewer_context::gpu_bridge::get_or_create_texture(render_ctx, texture_key, || {
164+
let debug_name = "mesh albedo texture";
165+
texture_creation_desc_from_color_image(&image_info, debug_name)
166+
})?
167+
} else {
161168
render_ctx
162169
.texture_manager_2d
163170
.white_texture_unorm_handle()
164171
.clone()
165-
});
172+
};
166173

167174
let mesh = re_renderer::mesh::Mesh {
168175
label: name.clone().into(),
@@ -204,44 +211,3 @@ impl LoadedMesh {
204211
self.bbox
205212
}
206213
}
207-
208-
fn try_get_or_create_albedo_texture(
209-
albedo_texture_buffer: &Option<re_types::components::ImageBuffer>,
210-
albedo_texture_format: &Option<re_types::components::ImageFormat>,
211-
render_ctx: &RenderContext,
212-
texture_key: u64,
213-
name: &str,
214-
) -> Option<re_renderer::resource_managers::GpuTexture2D> {
215-
let (Some(albedo_texture_buffer), Some(albedo_texture_format)) =
216-
(&albedo_texture_buffer, albedo_texture_format)
217-
else {
218-
return None;
219-
};
220-
221-
let image_info = ImageInfo {
222-
buffer_row_id: RowId::ZERO, // unused
223-
buffer: albedo_texture_buffer.0.clone(),
224-
format: albedo_texture_format.0,
225-
kind: re_types::image::ImageKind::Color,
226-
colormap: None,
227-
};
228-
229-
if re_viewer_context::gpu_bridge::required_shader_decode(albedo_texture_format).is_some() {
230-
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:?}.");
231-
return None;
232-
}
233-
234-
let texture =
235-
re_viewer_context::gpu_bridge::get_or_create_texture(render_ctx, texture_key, || {
236-
let debug_name = "mesh albedo texture";
237-
texture_creation_desc_from_color_image(&image_info, debug_name)
238-
});
239-
240-
match texture {
241-
Ok(texture) => Some(texture),
242-
Err(err) => {
243-
re_log::warn_once!("Failed to create mesh albedo texture for {name:?}: {err}");
244-
None
245-
}
246-
}
247-
}

0 commit comments

Comments
 (0)