diff options
author | metamerism <70122622+metamerism@users.noreply.github.com> | 2020-09-18 13:31:01 +1200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-09-17 18:31:01 -0700 |
commit | 862bfa9604a9231420c223538c877d16ee70fcad (patch) | |
tree | 82bbbbc3e34180fab87341db1822b4e77c83aa5d /projects/openexr | |
parent | 6e713f2f5c760e2df8379a7a74ee6c3e71100428 (diff) | |
download | oss-fuzz-862bfa9604a9231420c223538c877d16ee70fcad.tar.gz |
[openexr] speed up scanline reading, read all channels in readMulti (#4457)
* [openexr] speed up scanline reading, read all channels in readMulti
Signed-off-by: Peter Hillman <peter@pedro.kiwi>
* [openexr] rearrange channel order in readMulti
Signed-off-by: Peter Hillman <peter@pedro.kiwi>
Diffstat (limited to 'projects/openexr')
-rw-r--r-- | projects/openexr/openexr_scanlines_fuzzer.cc | 30 |
1 files changed, 26 insertions, 4 deletions
diff --git a/projects/openexr/openexr_scanlines_fuzzer.cc b/projects/openexr/openexr_scanlines_fuzzer.cc index e41f1f2ad..c4986e826 100644 --- a/projects/openexr/openexr_scanlines_fuzzer.cc +++ b/projects/openexr/openexr_scanlines_fuzzer.cc @@ -17,16 +17,19 @@ #include <stdlib.h> #include <string.h> #include <unistd.h> +#include <vector> #include <ImfArray.h> #include <ImfInputPart.h> #include <ImfMultiPartInputFile.h> +#include <ImfChannelList.h> #include <ImfRgbaFile.h> #include <ImfStdIO.h> using namespace OPENEXR_IMF_INTERNAL_NAMESPACE; using IMATH_NAMESPACE::Box2i; - +using std::vector; +using std::max; namespace { static void readSingle(IStream& is) { @@ -44,7 +47,10 @@ static void readSingle(IStream& is) { Array<Rgba> pixels(w); in.setFrameBuffer(&pixels[-dx], 1, 0); - for (int y = dw.min.y; y <= dw.max.y; ++y) in.readPixels(y); + // read up to 10,000 scanlines from file + int step = max( 1 , (dw.max.y - dw.min.y + 1) / 10000); + for (int y = dw.min.y; y <= dw.max.y; y+=step) in.readPixels(y); + } catch (...) { } } @@ -75,15 +81,31 @@ static void readMulti(IStream& is) { { throw std::logic_error("ignoring - very wide datawindow\n"); } - Array<Rgba> pixels(w); + FrameBuffer i; + // + // read all channels present (later channels will overwrite earlier ones) + vector<half> otherChannels(w); + const ChannelList& channelList = in->header().channels(); + for (ChannelList::ConstIterator c = channelList.begin() ; c != channelList.end() ; ++c ) + { + i.insert(c.name(),Slice(HALF, (char*)&otherChannels[0] , sizeof(half) , 0 )); + } + + // always try to read RGBA even if not present in file + Array<Rgba> pixels(w); i.insert("R", Slice(HALF, (char *)&(pixels[-dx].r), sizeof(Rgba), 0)); i.insert("G", Slice(HALF, (char *)&(pixels[-dx].g), sizeof(Rgba), 0)); i.insert("B", Slice(HALF, (char *)&(pixels[-dx].b), sizeof(Rgba), 0)); i.insert("A", Slice(HALF, (char *)&(pixels[-dx].a), sizeof(Rgba), 0)); + + + in->setFrameBuffer(i); - for (int y = dw.min.y; y <= dw.max.y; ++y) in->readPixels(y); + // read up to 10,000 scanlines from file + int step = max( 1 , (dw.max.y - dw.min.y + 1) / 10000); + for (int y = dw.min.y; y <= dw.max.y; y+=step) in->readPixels(y); } catch (...) { } |