OpenImageIO/oiio — pull request #470 by lgritz (2012-11-16 18:27:21+00:00)
Title: Improve speed of IC::get_pixels

I added a new test, imagespeed_test, to evaluate the penalty paid by ImageCache::get_pixels versus just a raw ImageInput::read_image. In other words, what's the extra cost of going through the ImageCache?

In my tests across a variety of file formats, data types, and scanline/tile, it turns out that reading an image through a call to IC::get_pixels was 40-80% more expensive (average around 45-50%) than just a direct read with ImageInput (presumably the fastest we can get).

This patch contains some changes to get_pixels to address this overhead. Basically speaking, it was pretty stupid before, treating each pixel it retrieves independently, both in terms of doing a separate find_tile as well as copying and converting it. With the patch, we only do a find_tile when we know we're crossing a tile boundary, and for contiguous data layouts we copy "spans" that can include many pixels (until the next tile boundary).

The result is that this reduces the overhead of using ImageCache (versus a raw ImageInput::read_image) down to 12-25%, depending on the file and data types involved, with an average of around 15%. This seems like a much more reasonable level of overhead for using all the features that ImageCache brings into the mix.

I expect this to significantly speed up file reads for oiiotool and maketx, both of which use ImageBuf's which are backed and/or populated by calls to ImageCache.