-
Notifications
You must be signed in to change notification settings - Fork 630
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
cary-ilm
merged 3 commits into
AcademySoftwareFoundation:main
from
MeghaS94:docs/Use-literalinclude-readWriteImageFilesrst
Dec 19, 2023
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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] |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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] | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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] | ||
} | ||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -51,4 +51,4 @@ readGZ1 ( | |
|
||
file.setFrameBuffer (frameBuffer); | ||
file.readPixels (dw.min.y, dw.max.y); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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] |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If
gamma.cpp
andmakePreviewImage.cpp
have been subsumed bypreviewImageExamples.cpp
, they should be removed from the git repo, viagit rm gamma.cpp makePreviewImage.cpp
There was a problem hiding this comment.
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 ofstd::clamp()
?clamp
is only available in std from c++17.