Texture::from_path uses confusing/misleading byte conversion #673

Open
opened 2026-07-05 03:23:28 +02:00 by Hermes · 0 comments
Collaborator

Severity: 🟡 Medium

File: Crates/orbital_resources/src/texture/mod.rs:210-215

Bug:
The from_path method converts image pixel data using a roundabout approach:

let data = img
    .to_rgba8()
    .iter()                        // iterates over INDIVIDUAL BYTES (not pixels)
    .map(|x| x.to_le_bytes())      // wraps each byte in a [u8;1]
    .collect::<Vec<_>>()
    .concat();                     // flattens back to Vec<u8>

This is equivalent to img.to_rgba8().into_raw() (or .to_vec()), but the to_le_bytes() call suggests the author thought they were iterating over pixel values, not individual bytes. The code works correctly but is misleading and suggests potential confusion about the image crate API.

This also pairs with the manual bytes_per_pixel table on lines 342-383 that duplicates target_pixel_byte_cost() from wgpu — together they signal fragility in the texture loading pipeline.

Fix: Replace with img.to_rgba8().into_raw() for clarity.

@SakulFlee

**Severity:** 🟡 Medium **File:** `Crates/orbital_resources/src/texture/mod.rs:210-215` **Bug:** The `from_path` method converts image pixel data using a roundabout approach: ```rust let data = img .to_rgba8() .iter() // iterates over INDIVIDUAL BYTES (not pixels) .map(|x| x.to_le_bytes()) // wraps each byte in a [u8;1] .collect::<Vec<_>>() .concat(); // flattens back to Vec<u8> ``` This is equivalent to `img.to_rgba8().into_raw()` (or `.to_vec()`), but the `to_le_bytes()` call suggests the author thought they were iterating over pixel values, not individual bytes. The code works correctly but is misleading and suggests potential confusion about the `image` crate API. This also pairs with the manual `bytes_per_pixel` table on lines 342-383 that duplicates `target_pixel_byte_cost()` from wgpu — together they signal fragility in the texture loading pipeline. **Fix:** Replace with `img.to_rgba8().into_raw()` for clarity. @SakulFlee
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
SakulFlee/Orbital#673
No description provided.