Skip to content

Commit

Permalink
multipart code examples (#1502)
Browse files Browse the repository at this point in the history
Signed-off-by: Anton Dukhovnikov <antond@wetafx.co.nz>
  • Loading branch information
antond-weta authored Aug 6, 2023
1 parent ebeb567 commit 09f8aea
Show file tree
Hide file tree
Showing 7 changed files with 572 additions and 8 deletions.
4 changes: 4 additions & 0 deletions src/examples/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ add_executable(OpenEXRExamples
deepExamples.h
deepTiledExamples.cpp
deepTiledExamples.h
multipartExamples.cpp
multipartExamples.h
)

target_link_libraries(OpenEXRExamples OpenEXR::OpenEXR)
Expand Down Expand Up @@ -66,6 +68,8 @@ install(
deepExamples.h
deepTiledExamples.cpp
deepTiledExamples.h
multipartExamples.cpp
multipartExamples.h
DESTINATION
${CMAKE_INSTALL_DOCDIR}/examples
)
Expand Down
32 changes: 30 additions & 2 deletions src/examples/deepExamples.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,20 @@ readDeepScanlineFile (
Array2D<half*>& dataA,
Array2D<unsigned int>& sampleCount)
{
//
// Read a deep image using class DeepScanLineInputFile. Try to read one
// channel, A, of type HALF, and one channel, Z,
// of type FLOAT. Store the A, and Z pixels in two
// separate memory buffers.
//
// - open the file
// - allocate memory for the pixels
// - describe the layout of the A, and Z pixel buffers
// - read the sample counts from the file
// - allocate the memory requred to store the samples
// - read the pixels from the file
//

DeepScanLineInputFile file (filename);

const Header& header = file.header ();
Expand Down Expand Up @@ -106,6 +120,7 @@ readDeepScanlineFile (

unsigned int getPixelSampleCount (int i, int j)
{
// Dummy code creating deep data from a flat image
return 1;
}

Expand All @@ -118,6 +133,7 @@ void getPixelSampleData(
Array2D<float*>& dataZ,
Array2D<half*>& dataA)
{
// Dummy code creating deep data from a flat image
dataZ[i][j][0] = testDataZ[i][j];
dataA[i][j][0] = testDataA[i][j];
}
Expand All @@ -134,6 +150,17 @@ writeDeepScanlineFile (
Array2D<unsigned int>& sampleCount)

{
//
// Write a deep image with only a A (alpha) and a Z (depth) channel,
// using class DeepScanLineOutputFile.
//
// - create a file header
// - add A and Z channels to the header
// - open the file, and store the header in the file
// - describe the memory layout of the A and Z pixels
// - store the pixels in the file
//

int height = dataWindow.max.y - dataWindow.min.y + 1;
int width = dataWindow.max.x - dataWindow.min.x + 1;

Expand Down Expand Up @@ -207,8 +234,8 @@ void deepExamples()
int h = 600;

Box2i window;
window.min.setValue(1, 1);
window.max.setValue(w, h);
window.min.setValue(0, 0);
window.max.setValue(w - 1, h - 1);

Array2D<float *> dataZ;
dataZ.resizeErase(h, w);
Expand All @@ -219,6 +246,7 @@ void deepExamples()
Array2D<unsigned int> sampleCount;
sampleCount.resizeErase(h, w);

// Create an image to be used as a source for deep data
testDataA.resizeErase(h, w);
testDataZ.resizeErase(h, w);
drawImage2(testDataA, testDataZ, w, h);
Expand Down
30 changes: 28 additions & 2 deletions src/examples/deepTiledExamples.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,20 @@ readDeepTiledFile (
Array2D<half*>& dataA,
Array2D<unsigned int>& sampleCount)
{
//
// Read a deep image using class DeepTiledInputFile. Try to read one
// channel, A, of type HALF, and one channel, Z,
// of type FLOAT. Store the A, and Z pixels in two
// separate memory buffers.
//
// - open the file
// - allocate memory for the pixels
// - describe the layout of the A, and Z pixel buffers
// - read the sample counts from the file
// - allocate the memory requred to store the samples
// - read the pixels from the file
//

DeepTiledInputFile file (filename);

int width = dataWindow.max.x - dataWindow.min.x + 1;
Expand Down Expand Up @@ -151,6 +165,17 @@ writeDeepTiledFile (
int tileSizeX,
int tileSizeY)
{
//
// Write a deep image with only a A (alpha) and a Z (depth) channel,
// using class DeepTiledOutputFile.
//
// - create a file header
// - add A and Z channels to the header
// - open the file, and store the header in the file
// - describe the memory layout of the A and Z pixels
// - store the pixels in the file
//

int height = dataWindow.max.y - dataWindow.min.y + 1;
int width = dataWindow.max.x - dataWindow.min.x + 1;

Expand Down Expand Up @@ -231,8 +256,8 @@ void deepTiledExamples()
int tileSizeY = 64;

Box2i window;
window.min.setValue(1, 1);
window.max.setValue(w, h);
window.min.setValue(0, 0);
window.max.setValue(w - 1, h - 1);

Array2D<float *> dataZ;
dataZ.resizeErase(h, w);
Expand All @@ -243,6 +268,7 @@ void deepTiledExamples()
Array2D<unsigned int> sampleCount;
sampleCount.resizeErase(h, w);

// Create an image to be used as a source for deep data
testDataA.resizeErase(h, w);
testDataZ.resizeErase(h, w);
drawImage2(testDataA, testDataZ, w, h);
Expand Down
2 changes: 1 addition & 1 deletion src/examples/generalInterfaceExamples.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ writeGZ1 (
// - create a file header
// - add G and Z channels to the header
// - open the file, and store the header in the file
// - describe the memory layout of the G anx Z pixels
// - describe the memory layout of the G and Z pixels
// - store the pixels in the file
//

Expand Down
14 changes: 11 additions & 3 deletions src/examples/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include "rgbaInterfaceTiledExamples.h"
#include "deepExamples.h"
#include "deepTiledExamples.h"
#include "multipartExamples.h"

#include <iostream>
#include <stdexcept>
Expand All @@ -25,13 +26,20 @@ main (int argc, char* argv[])

rgbaInterfaceTiledExamples ();
generalInterfaceTiledExamples ();
deepExamples();
deepTiledExamples();

deepExamples ();
deepTiledExamples ();

lowLevelIoExamples ();

previewImageExamples ();

// This example uses the files created by
// generalInterfaceExamples,
// generalInterfaceTiledExamples,
// deepExamples,
// deepTiledExamples
multipartExamples ();
}
catch (const std::exception& exc)
{
Expand Down
Loading

0 comments on commit 09f8aea

Please sign in to comment.