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

add Write Texture Format #48

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
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
65 changes: 65 additions & 0 deletions OIIO/WriteOIIO.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,24 @@ enum EParamTileSize {
eParamTileSize512
};

#define kParamOutputTextureformat "textureformat"
#define kParamOutputTextureformatLabel "Texture Format"
#define kParamOutputTextureformatHint ""

#define kParamOutputTextureformatOptionNone "None", "", "0"
#define kParamOutputTextureformatOptionPlain "Plain Texture", "MIP-mapped OpenEXR files", "Plain Texture"
#define kParamOutputTextureformatOptionLatLong "LatLong Environment", "Latlong Environment OpenEXR environment maps.", "LatLong Environment"
#define kParamOutputTextureformatOptionCubeFace "CubeFace Environment", "CubeFace Environment OpenEXR environment maps.", "CubeFace Environment"
#define kParamOutputTextureformatOptionShadow "Shadow", "Force one level for shadow maps", "Shadow"

enum EParamTextureformat {
eParamTextureformatNone = 0,
eParamTextureformatPlain,
eParamTextureformatLatLong,
eParamTextureformatCubeFace,
eParamTextureformatShadow
}

#define kParamProcessAllLayers "processAllLayers"
#define kParamProcessAllLayersLabel "All Layers"
#define kParamProcessAllLayersHint "When checked, all layers will be written to the file"
Expand Down Expand Up @@ -372,6 +390,7 @@ class WriteOIIOPlugin
IntParam* _zipCompressionLevel;
ChoiceParam* _orientation;
ChoiceParam* _compression;
ChoiceParam* _textureformat;
ChoiceParam* _tileSize;
ChoiceParam* _outputLayers;
ChoiceParam* _parts;
Expand All @@ -389,6 +408,7 @@ WriteOIIOPlugin::WriteOIIOPlugin(OfxImageEffectHandle handle,
, _zipCompressionLevel(NULL)
, _orientation(NULL)
, _compression(NULL)
, _textureformat(NULL)
, _tileSize(NULL)
, _outputLayers(NULL)
, _parts(NULL)
Expand All @@ -403,6 +423,7 @@ WriteOIIOPlugin::WriteOIIOPlugin(OfxImageEffectHandle handle,
_zipCompressionLevel = fetchIntParam(kParamOutputZIPCompressionLevel);
_orientation = fetchChoiceParam(kParamOutputOrientation);
_compression = fetchChoiceParam(kParamOutputCompression);
_textureformat = fetchChoiceParam(kParamOutputTextureformat);
_tileSize = fetchChoiceParam(kParamTileSize);
if (gIsMultiplanarV2) {
_outputLayers = fetchChoiceParam(kParamOutputChannels);
Expand Down Expand Up @@ -843,6 +864,9 @@ WriteOIIOPlugin::refreshParamsVisibility(const string& filename)
if (_views) {
_views->setIsSecretAndDisabled(!isEXR);
}
if (_textureformat) {
_textureformat->setIsSecretAndDisabled(!isEXR);
}
if (_parts) {
_parts->setIsSecretAndDisabled(!output->supports("multiimage"));
}
Expand All @@ -855,6 +879,9 @@ WriteOIIOPlugin::refreshParamsVisibility(const string& filename)
if (_views) {
_views->setIsSecretAndDisabled(true);
}
if (_textureformat) {
_textureformat->setIsSecretAndDisabled(true);
}
if (_parts) {
_parts->setIsSecretAndDisabled(true);
}
Expand Down Expand Up @@ -1013,6 +1040,9 @@ WriteOIIOPlugin::beginEncodeParts(void* user_data,
int compression_i;
_compression->getValue(compression_i);
string compression;
int textureformat_i;
_textureformat->getValue(textureformat_i);
string textureformat;

switch ((EParamCompression)compression_i) {
case eParamCompressionAuto: {
Expand Down Expand Up @@ -1069,6 +1099,21 @@ WriteOIIOPlugin::beginEncodeParts(void* user_data,
break;
}

switch ((EParamTextureformat)textureformat_i) {
case eParamTextureformatPlain:
textureformat = "Plain Texture";
break;
case eParamTextureformatCubeFace:
textureformat = "CubeFace Environment";
break;
case eParamTextureformatLatLong:
textureformat = "LatLong Environment";
break;
case eParamTextureformatShadow:
textureformat = "Shadow";
break;
}

spec.attribute("oiio:BitsPerSample", bitsPerSample);
// oiio:UnassociatedAlpha should be set if the data buffer is unassociated/unpremultiplied.
// However, WriteOIIO::getExpectedInputPremultiplication() stated that input to the encode()
Expand Down Expand Up @@ -1150,6 +1195,7 @@ WriteOIIOPlugin::beginEncodeParts(void* user_data,
#endif
}
spec.attribute("Orientation", orientation + 1);
spec.attribute("textureformat", textureformat);
if (!compression.empty()) { // some formats have a good value for the default compression
spec.attribute("compression", compression);
}
Expand Down Expand Up @@ -1732,6 +1778,25 @@ WriteOIIOPluginFactory::describeInContext(ImageEffectDescriptor& desc,
page->addChild(*param);
}
}
{
ChoiceParamDescriptor* param = desc.defineChoiceParam(kParamOutputTextureformat);
param->setLabel(kParamOutputTextureformatLabel);
param->setHint(kParamOutputTextureformatHint);
assert(param->getNOptions() == eParamTextureformatNone);
param->appendOption(kParamOutputTextureformatOptionNone);
assert(param->getNOptions() == eParamTextureformatPlain);
param->appendOption(kParamOutputTextureformatOptionPlain);
assert(param->getNOptions() == eParamTextureformatLatLong);
param->appendOption(kParamOutputTextureformatOptionLatLong);
assert(param->getNOptions() == eParamTextureformatCubeFace);
param->appendOption(kParamOutputTextureformatOptionCubeFace);
assert(param->getNOptions() == eParamTextureformatShadow);
param->appendOption(kParamOutputTextureformatOptionShadow);
param->setDefault(eParamTextureformatNone);
if (page) {
page->addChild(*param);
}
}

if (gIsMultiplanarV2) {

Expand Down