From 3e57cdac1d412be81d875193953b6d6d2c497b43 Mon Sep 17 00:00:00 2001 From: itsmattkc Date: Sat, 2 May 2020 22:51:29 +1000 Subject: [PATCH] use linesize workaround for setting OIIO pixels as well as getting --- app/codec/oiio/oiiodecoder.cpp | 33 +++++++++++++++++++++++++++++++-- app/codec/oiio/oiiodecoder.h | 2 ++ app/render/pixelformat.cpp | 6 +----- 3 files changed, 34 insertions(+), 7 deletions(-) diff --git a/app/codec/oiio/oiiodecoder.cpp b/app/codec/oiio/oiiodecoder.cpp index 52653df05..590c23706 100644 --- a/app/codec/oiio/oiiodecoder.cpp +++ b/app/codec/oiio/oiiodecoder.cpp @@ -231,6 +231,35 @@ QString OIIODecoder::GetIndexFilename() return QString(); } +void OIIODecoder::FrameToBuffer(FramePtr frame, OpenImageIO_v2_1::ImageBuf *buf) +{ +#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 + // + int width_in_bytes = frame->width() * PixelFormat::BytesPerPixel(frame->format()); + + for (int i=0;ispec().height;i++) { + memcpy( +#if OIIO_VERSION < 10903 + reinterpret_cast(buf->localpixels()) + i * width_in_bytes, +#else + reinterpret_cast(buf->localpixels()) + i * buf->scanline_stride(), +#endif + frame->data() + i * frame->linesize_bytes(), + width_in_bytes); + } +#else + buf->set_pixels(OIIO::ROI(), + buf->spec().format, + frame->data(), + OIIO::AutoStride, + frame->linesize_bytes()); +#endif +} + void OIIODecoder::BufferToFrame(OIIO::ImageBuf *buf, FramePtr frame) { #if OIIO_VERSION < 20112 @@ -239,9 +268,9 @@ void OIIODecoder::BufferToFrame(OIIO::ImageBuf *buf, FramePtr frame) // // See more: https://github.com/OpenImageIO/oiio/pull/2487 // - for (int i=0;ispec().height;i++) { - int width_in_bytes = frame->width() * PixelFormat::BytesPerPixel(frame->format()); + int width_in_bytes = frame->width() * PixelFormat::BytesPerPixel(frame->format()); + for (int i=0;ispec().height;i++) { memcpy(frame->data() + i * frame->linesize_bytes(), #if OIIO_VERSION < 10903 reinterpret_cast(buf->localpixels()) + i * width_in_bytes, diff --git a/app/codec/oiio/oiiodecoder.h b/app/codec/oiio/oiiodecoder.h index 249a1a346..b56a49b46 100644 --- a/app/codec/oiio/oiiodecoder.h +++ b/app/codec/oiio/oiiodecoder.h @@ -48,6 +48,8 @@ public: virtual QString GetIndexFilename() override; + static void FrameToBuffer(FramePtr frame, OIIO::ImageBuf* buf); + static void BufferToFrame(OIIO::ImageBuf* buf, FramePtr frame); private: diff --git a/app/render/pixelformat.cpp b/app/render/pixelformat.cpp index 2ddd251c1..7c55e0c13 100644 --- a/app/render/pixelformat.cpp +++ b/app/render/pixelformat.cpp @@ -230,11 +230,7 @@ FramePtr PixelFormat::ConvertPixelFormat(FramePtr frame, const PixelFormat::Form // Set the pixels (this is necessary as opposed to an OIIO buffer wrapper since Frame has // linesizes) - src.set_pixels(OIIO::ROI(), - GetOIIOTypeDesc(frame->format()), - frame->const_data(), - OIIO::AutoStride, - frame->linesize_bytes()); + OIIODecoder::FrameToBuffer(frame, &src); // Create a destination OIIO buffer with our destination format OIIO::ImageBuf dst(OIIO::ImageSpec(converted->width(),