From what I could read (might be missing the ball completely) -
There shouldn't be a need for the extra seek operation, as you're already calculating the offset based on the pixel's position. It is possible that the issue might be related to the way your stream's internal state or buffer management is interacting with your sequential reads.
When you perform a read operation 'read_data' from the stream, it might consume a certain amount of data from your stream's internal buffer. This might cause the stream's internal position to become misaligned with your calculated offset 'ofs', leading to the out-of-order data.
By adding the extra seek operation, you are effectively resetting your stream's position to the expected offset, ensuring that the subsequent read operation starts from the correct position. While the extra seek might seem redundant, it could serve as a workaround for you to ensure proper alignment between your calculated offset and the stream's actual position. You can add a check if the calculated offset 'ofs' is different from your stream's current position. If the offset is the same as the current position, skip the seek operation and directly perform the read operation using 'read_data'. Not exactly what you wanted though but I hope it shed some light on your issue -
gfx_result vlw_font::draw(draw_callback draw_cb, const glyph& glyph, uint32_t bitmap_offset, void* state) const {
if (draw_cb == nullptr || bitmap_offset < 24 + (glyph_count * 28)) {
return gfx_result::invalid_argument;
}
if (m_stream == nullptr || !m_stream->caps().read || !m_stream->caps().seek) {
return gfx_result::invalid_state;
}
int y_adj = max_ascent - glyph.y_delta;
for (int y = 0; y < glyph.size.height; ++y) {
for (int x = 0; x < glyph.size.width; ++x) {
uint8_t tmp;
size_t s = 1;
uint32_t ofs = bitmap_offset + (x + y * glyph.size.width);
if (ofs != m_stream->current_position()) {
seek_data(m_stream, ofs);
}
read_data(m_stream, &tmp, &s);
if (s != 1) return gfx_result::io_error;
draw_cb(x + glyph.x_delta, y + y_adj, tmp, state);
}
}
return gfx_result::success;
}