From 472030f8f0727f06746a40ded72bc414abf299f9 Mon Sep 17 00:00:00 2001 From: itsmattkc Date: Fri, 1 May 2020 01:38:31 +1000 Subject: [PATCH] oiiodecoder: implemented workaround for oiio stride bug in versions < 2.1.12 --- app/codec/oiio/oiiodecoder.cpp | 28 ++++++++++++++++++++++++---- app/codec/oiio/oiiodecoder.h | 3 +++ 2 files changed, 27 insertions(+), 4 deletions(-) diff --git a/app/codec/oiio/oiiodecoder.cpp b/app/codec/oiio/oiiodecoder.cpp index 813011f6a..ebd522c9e 100644 --- a/app/codec/oiio/oiiodecoder.cpp +++ b/app/codec/oiio/oiiodecoder.cpp @@ -192,8 +192,7 @@ FramePtr OIIODecoder::RetrieveVideo(const rational &timecode, const int& divider if (divider == 1) { - // Just a simple copy - buffer_->get_pixels(OIIO::ROI(), buffer_->spec().format, frame->data(), OIIO::AutoStride, frame->linesize_bytes()); + BufferToFrame(buffer_, frame); } else { @@ -204,8 +203,7 @@ FramePtr OIIODecoder::RetrieveVideo(const rational &timecode, const int& divider qWarning() << "OIIO resize failed"; } - // Just a simple copy - dst.get_pixels(OIIO::ROI(), dst.spec().format, frame->data(), OIIO::AutoStride, frame->linesize_bytes()); + BufferToFrame(&dst, frame); } @@ -233,6 +231,28 @@ QString OIIODecoder::GetIndexFilename() return QString(); } +void OIIODecoder::BufferToFrame(OIIO::ImageBuf *buf, FramePtr frame) +{ +#if OIIO_VERSION < 20112 + // + // Workaround for OIIO bug that ignores destination stride in versions OLDER than 2.1.12 + // + // See more: https://github.com/OpenImageIO/oiio/pull/2487 + // + for (int i=0;ispec().height;i++) { + memcpy(frame->data() + i * frame->linesize_bytes(), + reinterpret_cast(buf->localpixels()) + i * buf->scanline_stride(), + frame->width() * PixelFormat::BytesPerPixel(frame->format())); + } +#else + buf->get_pixels(OIIO::ROI(), + buf->spec().format, + frame->data(), + OIIO::AutoStride, + frame->linesize_bytes()); +#endif +} + bool OIIODecoder::FileTypeIsSupported(const QString& fn) { // We prioritize OIIO over FFmpeg to pick up still images more effectively, but some OIIO decoders (notably OpenJPEG) diff --git a/app/codec/oiio/oiiodecoder.h b/app/codec/oiio/oiiodecoder.h index 787596691..aaa8be388 100644 --- a/app/codec/oiio/oiiodecoder.h +++ b/app/codec/oiio/oiiodecoder.h @@ -54,6 +54,9 @@ private: #else std::unique_ptr image_; #endif + + static void BufferToFrame(OIIO::ImageBuf* buf, FramePtr frame); + static bool FileTypeIsSupported(const QString& fn); static int GetImageSequenceDigitCount(const QString& filename);