Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Converting code-blocks to literalincludes in ReadingAndWritingImageFiles.rst #1583

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
406 changes: 171 additions & 235 deletions website/ReadingAndWritingImageFiles.rst

Large diffs are not rendered by default.

27 changes: 25 additions & 2 deletions website/src/all.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,6 @@ namespace XXX {
#include "C_IStream_read.cpp"
#include "C_IStream_seekg.cpp"
#include "C_IStream_tellg.cpp"
#include "gamma.cpp"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If gamma.cpp and makePreviewImage.cpp have been subsumed by previewImageExamples.cpp, they should be removed from the git repo, via
git rm gamma.cpp makePreviewImage.cpp

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One question before pushing new changes - does it make sense to use Imath::clamp() instead of std::clamp()? clamp is only available in std from c++17.

#include "makePreviewImage.cpp"
#ifndef _WIN32
#include "MemoryMappedIStream.cpp"
#include "MemoryMappedIStream_isMemoryMapped.cpp"
Expand All @@ -109,6 +107,31 @@ namespace XXX {
#include "writeGZ2.cpp"
#include "writeRgba1.cpp"
#include "writeRgba2.cpp"
#include "readChannelsAndLayers.cpp"
#include "tileDescription.cpp"
#include "validExrFile.cpp"
#include "previewImageExamples.cpp"


void structDefinitions()
{
#include "structDefinitions.cpp"
}

void multithreading()
{
#include "multithreading.cpp"
}

void envmap()
{
#include "envmap.cpp"
}

void compression()
{
#include "compression.cpp"
}

int
main(int argc, char* argv[])
Expand Down
14 changes: 14 additions & 0 deletions website/src/compression.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@

int width=1; int height=1;
// [begin setCompression]
Header header (width, height);
header.channels().insert ("G", Channel (HALF));
header.channels().insert ("Z", Channel (FLOAT));
header.compression() = ZIP_COMPRESSION;
header.zipCompressionLevel() = 6;
// [end setCompression]

// [begin setCompressionDefault]
setDefaultZipCompressionLevel (6);
setDefaultDwaCompressionLevel (45.0f);
// [end setCompressionDefault]
11 changes: 11 additions & 0 deletions website/src/envmap.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@

char fileName[] = "";
// [begin hasEnvmap]
RgbaInputFile file (fileName);

if (hasEnvmap (file.header()))
{
Envmap type = envmap (file.header());
// ...
}
// [end hasEnvmap]
7 changes: 0 additions & 7 deletions website/src/gamma.cpp

This file was deleted.

31 changes: 0 additions & 31 deletions website/src/makePreviewImage.cpp

This file was deleted.

22 changes: 22 additions & 0 deletions website/src/multithreading.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
char fileName[] = "";
// [begin main thread create]
// main, before application threads are created:

setGlobalThreadCount (4);
// [begin applications input thread]
// application's input thread

InputFile in (fileName);

// ...
// [end applications input thread]

Header header = in.header();
// [begin applications output thread]
// application's output thread

OutputFile out (fileName, header, 2);

// ...
// [end applications output thread]

67 changes: 67 additions & 0 deletions website/src/previewImageExamples.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
void
accessPreviewImage (const char fileName[])
{
// [begin accessPreviewImage]
RgbaInputFile file (fileName);

if (file.header().hasPreviewImage())
{
const PreviewImage &preview = file.header().previewImage();

for (int y = 0; y < preview.height(); ++y)
{
for (int x = 0; x < preview.width(); ++x)
{

const PreviewRgba &pixel = preview.pixel (x, y);

// ...

}
}
}
// [end accessPreviewImage]
}

// [begin gamma]
unsigned char
gamma (float x)
{
x = pow (5.5555f * max (0.f, x), 0.4545f) * 84.66f;
return (unsigned char) Imath::clamp (x, 0.f, 255.f);
}
// [end gamma]

// [begin makePreviewImage]
void
makePreviewImage (
const Array2D<Rgba>& pixels,
int width,
int height,
Array2D<PreviewRgba>& previewPixels,
int& previewWidth,
int& previewHeight)
{
const int N = 8;

previewWidth = width / N;
previewHeight = height / N;

previewPixels.resizeErase (previewHeight, previewWidth);

for (int y = 0; y < previewHeight; ++y)
{
for (int x = 0; x < previewWidth; ++x)
{

const Rgba& inPixel = pixels[y * N][x * N];
PreviewRgba& outPixel = previewPixels[y][x];

outPixel.r = gamma (inPixel.r);
outPixel.g = gamma (inPixel.g);
outPixel.b = gamma (inPixel.b);
outPixel.a = static_cast<int> (Imath::clamp (inPixel.a * 255.f, 0.f, 255.f) + 0.5f);
}
}
}
// [end makePreviewImage]
53 changes: 53 additions & 0 deletions website/src/readChannelsAndLayers.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
void
readChannels(const char fileName[])
{
InputFile file (fileName);

// [begin useIterator]
const ChannelList &channels = file.header().channels();

for (ChannelList::ConstIterator i = channels.begin(); i != channels.end(); ++i)
{
const Channel &channel = i.channel();
// ...
}
// [end useIterator]

// [begin directAccess]
// const ChannelList &channels = file.header().channels();

const Channel &channel = channels["G"];

const Channel *channelPtr = channels.findChannel("G");
// [end directAccess]

}

void
readLayers (const char fileName[])
{
InputFile file (fileName);

// [begin layers]
const ChannelList &channels = file.header().channels(); ;

std::set<string> layerNames;

channels.layers (layerNames);

for (std::set<std::string>::const_iterator i = layerNames.begin(); i != layerNames.end(); ++i)
{
cout << "layer " << *i << endl;

ChannelList::ConstIterator layerBegin, layerEnd;
channels.channelsInLayer (*i, layerBegin, layerEnd);
for (ChannelList::ConstIterator j = layerBegin; j != layerEnd; ++j)
{
cout << "tchannel " << j.name() << endl;
}
}
// [end layers]
}



2 changes: 1 addition & 1 deletion website/src/readGZ1.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,4 +51,4 @@ readGZ1 (

file.setFrameBuffer (frameBuffer);
file.readPixels (dw.min.y, dw.max.y);
}
}
24 changes: 24 additions & 0 deletions website/src/readHeader.cpp
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// [begin readHeader]
void
readHeader (const char fileName[])
{
Expand All @@ -14,3 +15,26 @@ readHeader (const char fileName[])
if (cameraTransform)
cout << "cameraTransformn" << cameraTransform->value () << flush;
}
// [end readHeader]

// [begin readComments]
void
readComments (const char fileName[], string &comments)
{
RgbaInputFile file (fileName);

comments = file.header().typedAttribute<StringAttribute>("comments").value();
}
// [end readComments]

// [begin readCommentsError]
void
readComments (const char fileName[], const StringAttribute *&comments)
{
// error: comments pointer is invalid after this function returns

RgbaInputFile file (fileName);

comments = file.header().findTypedAttribute <StringAttribute> ("comments");
}
// [end readCommentsError]
14 changes: 14 additions & 0 deletions website/src/readTiled1.cpp
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// [begin readTiled1]
void
readTiled1 (const char fileName[], Array2D<GZ>& pixels, int& width, int& height)
{
Expand Down Expand Up @@ -33,3 +34,16 @@ readTiled1 (const char fileName[], Array2D<GZ>& pixels, int& width, int& height)
in.setFrameBuffer (frameBuffer);
in.readTiles (0, in.numXTiles () - 1, 0, in.numYTiles () - 1);
}
// [end readTiled1]
void
readTiledOtherVersions (const char fileName[])
{
// read tile function versions
TiledInputFile in(fileName);
int tileX, tileY, levelX, levelY, tileXMin, tileXMax, tileYMin, tileYMax;
// [begin v1]
in.readTile (tileX, tileY, levelX, levelY);
// [end v1]
in.readTiles (tileXMin, tileXMax, tileYMin, tileYMax, levelX, levelY);
// [end v2]
}
17 changes: 17 additions & 0 deletions website/src/structDefinitions.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// [Rgba definition begin]
struct Rgba
{
half r; // red
half g; // green
half b; // blue
half a; // alpha (opacity)
};
// [Rgba definition end]

// [GZ definition begin]
struct GZ
{
half g;
float z;
};
// [GZ definition end]
23 changes: 23 additions & 0 deletions website/src/tileDescription.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
// Enums defined in ImfTileDescription.h
// enum LevelMode
// {
// ONE_LEVEL,
// MIPMAP_LEVELS,
// RIPMAP_LEVELS
// };

// enum LevelRoundingMode
// {
// ROUND_DOWN,
// ROUND_UP
// };

class TileDescription
{
public:
unsigned int xSize; // size of a tile in the x dimension
unsigned int ySize; // size of a tile in the y dimension
LevelMode mode;
LevelRoundingMode roundingMode;
// ... (methods omitted)
};
35 changes: 35 additions & 0 deletions website/src/validExrFile.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#include <fstream>
// [begin validFileCheck]
bool
isThisAnOpenExrFile (const char fileName[])
{
std::ifstream f (fileName, std::ios_base::binary);

char b[4];
f.read (b, sizeof (b));

return !!f && b[0] == 0x76 && b[1] == 0x2f && b[2] == 0x31 && b[3] == 0x01;
}
// [end validFileCheck]
// [begin completeFileCheck]
bool
isComplete (const char fileName[])
{
InputFile in (fileName);
return in.isComplete();
}
// [end completeFileCheck]

// [begin otherValidFileChecks]
bool isOpenExrFile (const char fileName[], bool &isTiled);

bool isOpenExrFile (const char fileName[]);

bool isTiledOpenExrFile (const char fileName[]);

bool isOpenExrFile (IStream &is, bool &isTiled);

bool isOpenExrFile (IStream &is);

bool isTiledOpenExrFile (IStream &is);
// [end otherValidFileChecks]
Loading