Re: Problem with deep data

Peter Hillman <[email protected]> Fri, 20 Apr 2018 10:36:16 +1200
Newsgroups gmane.comp.video.openexr.devel
Message-ID <[email protected]>
This is a multi-part message in MIME format.
--===============9065854695674994365==
Content-Type: multipart/alternative;
 boundary="------------8B0D7CB890E86F3441F57763"
Content-Language: en-US

This is a multi-part message in MIME format.
--------------8B0D7CB890E86F3441F57763
Content-Type: text/plain; charset=utf-8; format=flowed
Content-Transfer-Encoding: 8bit

Hi Richard,

It may also be instructive to confirm the library built correctly by 
building and running the IlmImfTest suite. Running IlmImfTest with 
"deep" as an argument will run only the deep tests.

The source code of those tests should provide further examples of how to 
read/write deep data. The different tests intentionally use slightly 
different approaches to read/write data. You might modify one of those 
tests to disable the file cleanup, which would generate a deep file you 
can read with your own code, and compare to the known values written 
into the file.

Are you getting the correct sample counts but entirely incorrect data? 
That would suggest you have the pointer-to-arrays pointing to the wrong 
memory locations. If some of the values are correct (e.g. only the first 
pixel in the image, only the first pixel on each row, or only the first 
sample of each pixel) that would suggest the pointers are correct, but 
the yPixelStride,xPixelStride,sampleStride (respectively) values are wrong.

Try writing a small amount of 32 bit float data (e.g. a 2x2 pixel image 
with 1 channel) with compression set to NO_COMPRESSION and check the 
file contents in a hex editor: the last 4 bytes of the file should be 
the last sample of the last pixel of the last channel in the file. That 
might tell you whether you are writing the file correctly.



On 20/04/18 09:45, Michael Wolf wrote:
> Re: [Openexr-devel] Problem with deep data
>
> Hallo Richard,
>
> This is a snippet from my simple deep reader (half RGBA, float Z)- 
> minus all the cleanup.
> It was written some time ago as a simple test, but it works for the 
> purpose. Maybe it helps you find the issue.
>
> --- snip ---
>
> Imf::Array2D< unsigned int > sampleCount;
> Imf::Array2D< half* > dataR, dataG, dataB, dataA;
>
> void readDeepExr(const char *filename)
> {
>   Imf::DeepScanLineInputFile file(filename);
>   const Imf::Header &header = file.header();
>
>   dataWindow = header.dataWindow();
>   displayWindow = header.displayWindow();
>   width = dataWindow.max.x - dataWindow.min.x + 1;
>   height = dataWindow.max.y - dataWindow.min.y + 1;
>
>   sampleCount.resizeEraseUnsafe(height, width);
>   Imf::Array2D< float* >dataZ(height, width);
>   dataR.resizeEraseUnsafe(height, width); 
> dataG.resizeEraseUnsafe(height, width);
>   dataB.resizeEraseUnsafe(height, width); 
> dataA.resizeEraseUnsafe(height, width);
>
>   Imf::DeepFrameBuffer frameBuffer;
>   frameBuffer.insertSampleCountSlice (Imf::Slice (Imf::UINT,
>     (char *) (&sampleCount[0][0] - dataWindow.min.x - dataWindow.min.y 
> * width),
>     sizeof (unsigned int) * 1, // xStride
>     sizeof (unsigned int) * width)); // yStride
>   frameBuffer.insert ("Z",
>     Imf::DeepSlice (Imf::FLOAT, (char *) (&dataZ[0][0] - 
> dataWindow.min.x - dataWindow.min.y * width),
>     sizeof (float *) * 1, // xStride for pointer array
>     sizeof (float *) * width, // yStride for pointer array
>     sizeof (float) * 1)); // stride for Z data sample
>   frameBuffer.insert ("R",
>     Imf::DeepSlice (Imf::HALF, (char *) (&dataR[0][0] - 
> dataWindow.min.x - dataWindow.min.y * width),
>     sizeof (half *), // xStride for pointer array
>     sizeof (half *) * width, // yStride for pointer array
>     sizeof (half))); // stride for O data sample
>   frameBuffer.insert ("G",
>     Imf::DeepSlice (Imf::HALF, (char *) (&dataG[0][0] - 
> dataWindow.min.x - dataWindow.min.y * width),
>     sizeof (half *), sizeof (half *) * width, sizeof (half)));
>   frameBuffer.insert ("B",
>     Imf::DeepSlice (Imf::HALF, (char *) (&dataB[0][0] - 
> dataWindow.min.x - dataWindow.min.y * width),
>     sizeof (half *), sizeof (half *) * width, sizeof (half)));
>   frameBuffer.insert ("A",
>     Imf::DeepSlice (Imf::HALF, (char *) (&dataA[0][0] - 
> dataWindow.min.x - dataWindow.min.y * width),
>     sizeof (half *), sizeof (half *) * width, sizeof (half)));
>
>   file.setFrameBuffer(frameBuffer);
>   file.readPixelSampleCounts(dataWindow.min.y, dataWindow.max.y);
>
>   for (int y = 0; y < height; y++)
>   {
>     for (int x = 0; x < width; x++)
>     {
>       int s = sampleCount[y][x];
>       dataZ[y][x] = new float[s];
>       dataR[y][x] = new half[s];
>       dataG[y][x] = new half[s];
>       dataB[y][x] = new half[s];
>       dataA[y][x] = new half[s];
>     }
>   }
>   file.readPixels(dataWindow.min.y, dataWindow.max.y);
>   std::cout << "Done.\n";
>
>   // clean up etc...
> }
>
>
> --- snip ---
>
> Cheers,
> Mike
>
> /--
> db&w Bornemann und Wolf GbR
> Seyfferstr. 34
> 70197 Stuttgart
> Deutschland
>
> /[email protected] <mailto:[email protected]>
> /
> /http://www.db-w.com
> /
> tel: +49 (711) 664 525-3
> fax: +49 (711) 664 525-1
> mob: +49 (173) 66 37 652
>
> skype: lupus_lux
> msn: /[email protected] <mailto:[email protected]>
>
>
> _______________________________________________
> Openexr-devel mailing list
> [email protected]
> https://lists.nongnu.org/mailman/listinfo/openexr-devel


--------------8B0D7CB890E86F3441F57763
Content-Type: text/html; charset=utf-8
Content-Transfer-Encoding: 8bit

<html>
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
  </head>
  <body text="#000000" bgcolor="#FFFFFF">
    <p>Hi Richard,<br>
    </p>
    <p>It may also be instructive to confirm the library built correctly
      by building and running the IlmImfTest suite. Running IlmImfTest
      with "deep" as an argument will run only the deep tests.<br>
    </p>
    <p>The source code of those tests should provide further examples of
      how to read/write deep data. The different tests intentionally use
      slightly different approaches to read/write data. You might modify
      one of those tests to disable the file cleanup, which would
      generate a deep file you can read with your own code, and compare
      to the known values written into the file.<br>
    </p>
    <p>Are you getting the correct sample counts but entirely incorrect
      data? That would suggest you have the pointer-to-arrays pointing
      to the wrong memory locations. If some of the values are correct
      (e.g. only the first pixel in the image, only the first pixel on
      each row, or only the first sample of each pixel) that would
      suggest the pointers are correct, but the
      yPixelStride,xPixelStride,sampleStride (respectively) values are
      wrong.<br>
    </p>
    <p>Try writing a small amount of 32 bit float data (e.g. a 2x2 pixel
      image with 1 channel) with compression set to NO_COMPRESSION and
      check the file contents in a hex editor: the last 4 bytes of the
      file should be the last sample of the last pixel of the last
      channel in the file. That might tell you whether you are writing
      the file correctly.<br>
    </p>
    <br>
    <br>
    <div class="moz-cite-prefix">On 20/04/18 09:45, Michael Wolf wrote:<br>
    </div>
    <blockquote type="cite" cite="mid:[email protected]">
      <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
      <title>Re: [Openexr-devel] Problem with deep data</title>
      <br>
      <br>
      <div><span style=" font-family:'Courier New'; font-size: 14pt;">Hallo
          Richard,<br>
          <br>
          This is a snippet from my simple deep reader (half RGBA, float
          Z)- minus all the cleanup.<br>
          It was written some time ago as a simple test, but it works
          for the purpose. Maybe it helps you find the issue.<br>
          <br>
          --- snip ---<br>
          <br>
          <span style=" font-family:'Tahoma'; font-size: 10pt; color:
            #000000;">Imf::Array2D&lt; unsigned int &gt; sampleCount;<br>
            Imf::Array2D&lt; half* &gt; dataR, dataG, dataB, dataA;<br>
            <br>
            void readDeepExr(const char *filename)<br>
            {<br>
              Imf::DeepScanLineInputFile file(filename);<br>
              const Imf::Header &amp;header = file.header();<br>
            <br>
              dataWindow = header.dataWindow();<br>
              displayWindow = header.displayWindow();<br>
              width = dataWindow.max.x - dataWindow.min.x + 1;<br>
              height = dataWindow.max.y - dataWindow.min.y + 1;<br>
            <br>
              sampleCount.resizeEraseUnsafe(height, width);<br>
              Imf::Array2D&lt; float* &gt;dataZ(height, width);<br>
              dataR.resizeEraseUnsafe(height, width);
            dataG.resizeEraseUnsafe(height, width);<br>
              dataB.resizeEraseUnsafe(height, width);
            dataA.resizeEraseUnsafe(height, width);        <br>
            <br>
              Imf::DeepFrameBuffer frameBuffer;<br>
              frameBuffer.insertSampleCountSlice (Imf::Slice (Imf::UINT,<br>
                (char *) (&amp;sampleCount[0][0] - dataWindow.min.x -
            dataWindow.min.y * width),<br>
                sizeof (unsigned int) * 1, // xStride<br>
                sizeof (unsigned int) * width)); // yStride<br>
              frameBuffer.insert ("Z",<br>
                Imf::DeepSlice (Imf::FLOAT, (char *) (&amp;dataZ[0][0] -
            dataWindow.min.x - dataWindow.min.y * width),<br>
                sizeof (float *) * 1, // xStride for pointer array<br>
                sizeof (float *) * width, // yStride for pointer array<br>
                sizeof (float) * 1)); // stride for Z data sample<br>
              frameBuffer.insert ("R",<br>
                Imf::DeepSlice (Imf::HALF, (char *) (&amp;dataR[0][0] -
            dataWindow.min.x - dataWindow.min.y * width),<br>
                sizeof (half *), // xStride for pointer array<br>
                sizeof (half *) * width, // yStride for pointer array<br>
                sizeof (half))); // stride for O data sample<br>
              frameBuffer.insert ("G",<br>
                Imf::DeepSlice (Imf::HALF, (char *) (&amp;dataG[0][0] -
            dataWindow.min.x - dataWindow.min.y * width),<br>
                sizeof (half *), sizeof (half *) * width, sizeof
            (half)));<br>
              frameBuffer.insert ("B",<br>
                Imf::DeepSlice (Imf::HALF, (char *) (&amp;dataB[0][0] -
            dataWindow.min.x - dataWindow.min.y * width),<br>
                sizeof (half *), sizeof (half *) * width, sizeof
            (half)));<br>
              frameBuffer.insert ("A",<br>
                Imf::DeepSlice (Imf::HALF, (char *) (&amp;dataA[0][0] -
            dataWindow.min.x - dataWindow.min.y * width),<br>
                sizeof (half *), sizeof (half *) * width, sizeof
            (half)));<br>
            <br>
              file.setFrameBuffer(frameBuffer);<br>
              file.readPixelSampleCounts(dataWindow.min.y,
            dataWindow.max.y);<br>
            <br>
              for (int y = 0; y &lt; height; y++)<br>
              {<br>
                for (int x = 0; x &lt; width; x++)<br>
                {<br>
                  int s = sampleCount[y][x];<br>
                  dataZ[y][x] = new float[s];<br>
                  dataR[y][x] = new half[s];<br>
                  dataG[y][x] = new half[s];<br>
                  dataB[y][x] = new half[s];<br>
                  dataA[y][x] = new half[s];      <br>
                }    <br>
              }<br>
              file.readPixels(dataWindow.min.y, dataWindow.max.y);<br>
              std::cout &lt;&lt; "Done.\n";<br>
             <br>
              // clean up etc...<br>
            }<br>
            <br>
            <br>
            <span style=" font-family:'Courier New'; font-size: 14pt;
              color: #000000;">--- snip ---<br>
              <br>
              Cheers,<br>
              Mike<br>
              <br>
              <span style=" font-family:'calibri'; color: #c0c0c0;"><i>--<br>
                  db&amp;w Bornemann und Wolf GbR<br>
                  Seyfferstr. 34<br>
                  70197 Stuttgart<br>
                  Deutschland<br>
                   <br>
                </i></span></span></span></span><a style="
          font-family:'calibri'; font-size: 14pt;"
          href="mailto:[email protected]" moz-do-not-send="true">[email protected]</a><br>
        <span style=" font-family:'calibri'; font-size: 14pt; color:
          #c0c0c0;"><i> <br>
          </i></span><a style=" font-family:'calibri'; font-size: 14pt;"
          href="http://www.db-w.com" moz-do-not-send="true">http://www.db-w.com</a><br>
        <span style=" font-family:'calibri'; font-size: 14pt; color:
          #c0c0c0;"><i> <br>
            tel: +49 (711) 664 525-3<br>
            fax: +49 (711) 664 525-1<br>
            mob: +49 (173) 66 37 652<br>
             <br>
            skype: lupus_lux<br>
            msn:   </i></span><a style=" font-family:'calibri';
          font-size: 14pt;" href="mailto:[email protected]"
          moz-do-not-send="true">[email protected]</a>
      </div>
      <br>
      <fieldset class="mimeAttachmentHeader"></fieldset>
      <br>
      <pre wrap="">_______________________________________________
Openexr-devel mailing list
<a class="moz-txt-link-abbreviated" href="mailto:[email protected]">[email protected]</a>
<a class="moz-txt-link-freetext" href="https://lists.nongnu.org/mailman/listinfo/openexr-devel">https://lists.nongnu.org/mailman/listinfo/openexr-devel</a>
</pre>
    </blockquote>
    <br>
  </body>
</html>

--------------8B0D7CB890E86F3441F57763--


--===============9065854695674994365==
Content-Type: text/plain; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Disposition: inline

_______________________________________________
Openexr-devel mailing list
[email protected]
https://lists.nongnu.org/mailman/listinfo/openexr-devel

--===============9065854695674994365==--