Skip to content

Commit 7141176

Browse files
authored
Merge pull request #592 from cchampet/fix_oiiowriterPremultiplied
oiiowriter: fix alpha premult when converting pixels
2 parents 28e4bb7 + 1200d3a commit 7141176

File tree

2 files changed

+8
-4
lines changed

2 files changed

+8
-4
lines changed

plugins/image/io/OpenImageIO/src/reader/OpenImageIOReaderProcess.tcc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ View& OpenImageIOReaderProcess<View>::readImage(View& dst, boost::scoped_ptr<Ope
167167
const stride_t zstride = ystride * tmpView.height();
168168

169169
img->read_image(TypeDesc::UNKNOWN, // it's to not convert into OpenImageIO, convert with GIL
170-
&((*tmpView.begin())[0]), // get the adress of the first channel value from the first pixel
170+
&((*tmpView.begin())[0]), // get the address of the first channel value from the first pixel
171171
xstride, ystride, zstride, &progressCallback, this);
172172

173173
copy_and_convert_pixels(tmpView, dst);

plugins/image/io/OpenImageIO/src/writer/OpenImageIOWriterProcess.tcc

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
#include <terry/globals.hpp>
55
#include <terry/openexr/half.hpp>
6+
#include <terry/color/components.hpp>
67

78
#include <tuttle/plugin/exceptions.hpp>
89

@@ -483,6 +484,7 @@ void OpenImageIOWriterProcess<View>::writeImage(View& src, const std::string& fi
483484
{
484485
using namespace boost;
485486
using namespace OpenImageIO;
487+
using namespace terry::color::components;
486488

487489
boost::scoped_ptr<ImageOutput> out(ImageOutput::create(filepath));
488490
if(out.get() == NULL)
@@ -491,8 +493,10 @@ void OpenImageIOWriterProcess<View>::writeImage(View& src, const std::string& fi
491493
}
492494
WImage img(src.width(), src.height());
493495

496+
ConvertionParameters parameters;
497+
parameters.premultiplied = params._premultiply;
494498
typename WImage::view_t vw(view(img));
495-
copy_and_convert_pixels(src, vw);
499+
convertComponentsView(src, vw, parameters);
496500

497501
OpenImageIO::TypeDesc oiioBitDepth;
498502
size_t sizeOfChannel = 0;
@@ -557,7 +561,7 @@ void OpenImageIOWriterProcess<View>::writeImage(View& src, const std::string& fi
557561
spec.attribute("Copyright", params._copyright);
558562

559563
spec.attribute("oiio:BitsPerSample", bitsPerSample);
560-
spec.attribute("oiio:UnassociatedAlpha", params._premultiply);
564+
spec.attribute("oiio:UnassociatedAlpha", ! params._premultiply);
561565
spec.attribute("CompressionQuality", params._quality);
562566
spec.attribute("Orientation", params._orientation + 1);
563567

@@ -612,7 +616,7 @@ void OpenImageIOWriterProcess<View>::writeImage(View& src, const std::string& fi
612616
typedef typename boost::gil::channel_type<WImage>::type channel_t;
613617

614618
out->write_image(oiioBitDepth,
615-
&((*vw.begin())[0]), // get the adress of the first channel value from the first pixel
619+
&((*vw.begin())[0]), // get the address of the first channel value from the first pixel
616620
xstride, ystride, zstride, &progressCallback, this);
617621

618622
out->close();

0 commit comments

Comments
 (0)