Search code examples
image-processingpovray

Merge povray's partial images of arbitrary size


Starting situation:

Using povray I create 4 partial images of a scene.

povray +SR1 +ER200 +SC0 +EC200 +W400 +H400 +OPART1 povray.pov
povray +SR1 +ER200 +SC201 +EC400 +W400 +H400 +OPART11 povray.pov
povray +SR201 +ER400 +SC0 +EC200 +W400 +H400 +OPART2 povray.pov
povray +SR201 +ER400 +SC201 +EC400 +W400 +H400 +OPART22 povray.pov

Problem to solve:

  • Merge the 4 images programmatically.

Things to take in consideration:

  • Most of the partial images are NOT valid images and cannot be opened. For example, the first partial image can be opened, showing a rectangle with the image at the top left and everything else is black. But the rest of the images contain only the information regarding his zone. We could say that those images are broken.
  • The output format is set with the +F and could be PPM, PNG, Uncompressed and Compressed Targa. A valid solution could use any of those formats.
  • Focus on how to merge the images. You know the rectangle that each partial image have.

Things that have been tried:

  • Concatenating the images with Tail as described in http://povray.tashcorp.net/tutorials/qd_multicpu_render/ . It only works if the partial images are complete on the width axis, that is if PART1 is a set of lines, PART2 another set of lines...and no column division. But we have column division.
  • Use ImageMagick. It cannot open the partial images. It says they are broken.

Solution

  • I found how this could be achieved.

    You need to patch Povray so that it saves information about the offset of PNG files.

    This is the Patch. https://gist.github.com/721862

    You need to download the sources for povray and apply the patch. To apply the patch you save the patch file in povray-3.6.1/source/patch.patch and then:

    cp patch.patch povray-3.6.1/source/
    cd povray-3.6.1/source/
    patch png_pov.cpp patch.patch