openexr-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Openexr-devel] Writing an image upside down & negative yStride


From: Werner Benger
Subject: [Openexr-devel] Writing an image upside down & negative yStride
Date: Mon, 16 Mar 2009 16:04:40 -0500
User-agent: Opera Mail/9.64 (Win32)

Hello,

 I'm using a negate yStride value to write an image upside down into
an .exr file, giving it a buffer location that points to the last row,
and then telling the lib to traverse backwards to the first one, like
this:

TiledRgbaOutputFile*Outfile;
Rgba*Pixels;

Outfile->setFrameBuffer(Pixels+Outfile->tileXSize()*(Outfile->tileYSize()-1),
                        1,                    // xStride
                       -Outfile->tileXSize(), // yStride
true // the pixels buffer is relative (local modification)
                        );


Hereby I encountered the problem that the type of the yStride variable in
Imf::Slice is of type size_t, which is unsigned. As a consequence, the
computation of the readPtr in ImfTiledOutputFile.cpp, TileBufferTask::execute ()
results in a wrong pointer on a 64 bit machine. It works well for
Windows XP 32 bit and Linux 32 bit, where I tested it so far, but not
on an AMD64 bit machine under Linux (it crashes with segmentation fault).
A simple cure is to add a type conversion from the size_t value to an
integer (sizeof(size_t)=8, sizeof(int)=4 on this platform, thereby assuming
that the yStride will never be larger than what 31 bit can cover).
A patch would look like this:

Index: ImfTiledOutputFile.cpp
===================================================================
--- ImfTiledOutputFile.cpp      (revision 980)
+++ ImfTiledOutputFile.cpp      (working copy)
@@ -758,7 +758,7 @@
                     //

                     const char *readPtr = slice.base +
-                                          (y - yOffset) * slice.yStride +
+ (y - yOffset) * (int)slice.yStride +
                                           (tileRange.min.x - xOffset) *
                                           slice.xStride;


However, there might be quite similar locations, and better ways to
address the problem to allow writing .exr images upside down on a 64 bit
machine. So this is just to bring this problem to your attention, maybe
there can be some adjustment in a next version of the library?

Best regards,

        Werner


--
___________________________________________________________________________
Dr. Werner Benger <address@hidden>               Visualization Research
Laboratory for Creative Arts and Technology (LCAT)
Center for Computation & Technology at Louisiana State University (CCT/LSU)
239 Johnston Hall, Baton Rouge, Louisiana 70803
Tel.: +1 225 578 4809                        Fax.: +1 225 578-5362




reply via email to

[Prev in Thread] Current Thread [Next in Thread]