Skip to content

Commit

Permalink
Converting code-blocks to literalincludes in ReadingAndWritingImageFi…
Browse files Browse the repository at this point in the history
…les.rst
  • Loading branch information
MeghaS94 committed Oct 17, 2023
1 parent fca936a commit 9e9b137
Show file tree
Hide file tree
Showing 16 changed files with 531 additions and 240 deletions.
405 changes: 168 additions & 237 deletions website/ReadingAndWritingImageFiles.rst

Large diffs are not rendered by default.

32 changes: 30 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"
#include "makePreviewImage.cpp"
#ifndef _WIN32
#include "MemoryMappedIStream.cpp"
#include "MemoryMappedIStream_isMemoryMapped.cpp"
Expand All @@ -109,6 +107,36 @@ 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 tryCatchWriteRgba1()
{
#include "tryCatchExample.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, height;
// [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[100];
// [begin hasEnvmap]
RgbaInputFile file (fileName);

if (hasEnvmap (file.header()))
{
Envmap type = envmap (file.header());
// ...
}
// [end hasEnvmap]
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[100];
// [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) 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> (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)
};
14 changes: 14 additions & 0 deletions website/src/tryCatchExample.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
char fileName[100];
const Rgba* pixels;
int width;
int height;
// [begin]
try
{
writeRgba1 (fileName, pixels, width, height);
}
catch (const std::exception &exc)
{
std::cerr << exc.what() << std::endl;
}
// [end]
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

0 comments on commit 9e9b137

Please sign in to comment.