Skip to content

Commit fd5ac81

Browse files
authored
fix(webp): Allow out-of-order scanlines when writing webp (#4973)
Move write_complete_data() to close() for proper scanline order support The WebP output plugin incorrectly assumed that scanlines would be written in sequential order, triggering the final write when y == height - 1. This violated the write_scanline API contract which allows scanlines to be written in any order (the plugin even advertises 'random_access' support). Changes: - Remove premature write_complete_data() call from write_scanline() - Move final encoding/writing to close() where it belongs - Add m_image_complete flag to track write state - Move buffer cleanup to after write_complete_data() in close() Fixes the issue where writing scanlines out of order would result in incomplete or corrupted WebP files. Signed-off-by: pmady <[email protected]>
1 parent 2d5e442 commit fd5ac81

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

src/webp.imageio/webpoutput.cpp

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -238,11 +238,6 @@ WebpOutput::write_scanline(int y, int z, TypeDesc format, const void* data,
238238
std::vector<uint8_t> scratch;
239239
data = to_native_scanline(format, data, xstride, scratch, m_dither, y, z);
240240
memcpy(&m_uncompressed_image[y * m_scanline_size], data, m_scanline_size);
241-
242-
/* If this was the final scanline, we are done. */
243-
if (y == m_spec.height - 1) {
244-
return write_complete_data();
245-
}
246241
return true;
247242
}
248243

@@ -271,9 +266,15 @@ WebpOutput::close()
271266
OIIO_DASSERT(m_uncompressed_image.size());
272267
ok &= write_scanlines(m_spec.y, m_spec.y + m_spec.height, 0,
273268
m_spec.format, &m_uncompressed_image[0]);
274-
std::vector<uint8_t>().swap(m_uncompressed_image);
275269
}
276270

271+
// Write the complete image data on close, not during write_scanline.
272+
// This allows scanlines to be written in any order.
273+
if (ok && m_uncompressed_image.size()) {
274+
ok = write_complete_data();
275+
}
276+
277+
std::vector<uint8_t>().swap(m_uncompressed_image);
277278
WebPPictureFree(&m_webp_picture);
278279
init();
279280
return ok;

0 commit comments

Comments
 (0)