Skip to content
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
28 changes: 18 additions & 10 deletions src/oiiotool/oiiotool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -819,20 +819,26 @@ get_value_override(string_view localoption, string_view defaultval)
static void
set_output_dataformat(ImageSpec& spec, TypeDesc format,
std::map<std::string, std::string>& channelformats,
int bitdepth)
int bitdepth, int subimage_index, int nsubimages)
{
if (format != TypeUnknown)
spec.format = format;
spec.channelformats.resize(spec.nchannels, spec.format);
if (!channelformats.empty()) {
std::string subimagename = spec["oiio:subimagename"];
// If this is one of several subimages and it doesn't have a name, let
// it be referred to be "subimage0N".
if (nsubimages > 1 && subimagename.size() == 0)
subimagename = Strutil::format("subimage{:02}", subimage_index);
auto subwildcard = Strutil::format("{}.*", subimagename);
for (int c = 0; c < spec.nchannels; ++c) {
std::string chname = spec.channel_name(c);
auto subchname = Strutil::fmt::format("{}.{}", subimagename,
chname);
auto subchname = Strutil::format("{}.{}", subimagename, chname);
TypeDesc chtype = spec.channelformat(c);
if (subimagename.size() && channelformats[subchname] != "")
chtype = TypeDesc(channelformats[subchname]);
else if (subimagename.size() && channelformats[subwildcard] != "")
chtype = TypeDesc(channelformats[subwildcard]);
else if (channelformats[chname] != "")
chtype = TypeDesc(channelformats[chname]);
if (chtype != TypeUnknown)
Expand Down Expand Up @@ -862,6 +868,7 @@ set_output_dataformat(ImageSpec& spec, TypeDesc format,
static void
adjust_output_options(string_view filename, ImageSpec& spec,
const ImageSpec* nativespec, const Oiiotool& ot,
int subimage_index, int nsubimages,
bool format_supports_tiles,
const ParamValueList& fileoptions,
bool was_direct_read = false)
Expand Down Expand Up @@ -944,7 +951,8 @@ adjust_output_options(string_view filename, ImageSpec& spec,

// Set the types in the spec
set_output_dataformat(spec, requested_output_dataformat,
requested_channelformats, requested_output_bits);
requested_channelformats, requested_output_bits,
subimage_index, nsubimages);


// Tiling strategy:
Expand Down Expand Up @@ -5850,8 +5858,8 @@ output_file(Oiiotool& ot, cspan<const char*> argv)
bool ok = true;
if (do_tex || do_latlong || do_bumpslopes) {
ImageSpec configspec;
adjust_output_options(filename, configspec, nullptr, ot, supports_tiles,
fileoptions);
adjust_output_options(filename, configspec, nullptr, ot, 0, 1,
supports_tiles, fileoptions);
prep_texture_config(ot, configspec, fileoptions);
ImageBufAlgo::MakeTextureMode mode = ImageBufAlgo::MakeTxTexture;
if (do_shad)
Expand All @@ -5878,10 +5886,10 @@ output_file(Oiiotool& ot, cspan<const char*> argv)
} else {
// Non-texture case
std::vector<ImageSpec> subimagespecs(ir->subimages());
for (int s = 0; s < ir->subimages(); ++s) {
for (int s = 0, send = ir->subimages(); s < send; ++s) {
ImageSpec spec = *ir->spec(s, 0);
adjust_output_options(filename, spec, ir->nativespec(s), ot,
supports_tiles, fileoptions,
adjust_output_options(filename, spec, ir->nativespec(s), ot, s,
send, supports_tiles, fileoptions,
(*ir)[s].was_direct_read());
// If it's not tiled and MIP-mapped, remove any "textureformat"
if (!spec.tile_pixels() || ir->miplevels(s) <= 1)
Expand Down Expand Up @@ -5923,7 +5931,7 @@ output_file(Oiiotool& ot, cspan<const char*> argv)
for (int m = 0, mend = ir->miplevels(s); m < mend && ok; ++m) {
ImageSpec spec = *ir->spec(s, m);
adjust_output_options(filename, spec, ir->nativespec(s, m), ot,
supports_tiles, fileoptions,
s, send, supports_tiles, fileoptions,
(*ir)[s].was_direct_read());
if (s > 0 || m > 0) { // already opened first subimage/level
if (!out->open(tmpfilename, spec, mode)) {
Expand Down
15 changes: 15 additions & 0 deletions testsuite/oiiotool-copy/ref/out.txt
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,21 @@ rgbahalf-zfloat.exr : 38 x 38, 5 channel, half/half/half/half/float openexr
screenWindowWidth: 1
oiio:subimages: 1
openexr:lineOrder: "increasingY"
Reading sub-formats.exr
3 subimages: 64x64 [h,h,h], 64x64 [h,f,h], 64x64 [h,h,h,h]
oiio:subimages: 3
oiio:subimages: 3
oiio:subimages: 3
Reading sub-formats2.exr
3 subimages: 64x64 [h,h,h], 64x64 [f,f,f], 64x64 [h,h,h,h]
oiio:subimages: 3
oiio:subimages: 3
oiio:subimages: 3
Reading sub-formats3.exr
3 subimages: 64x64 [h,h,h], 64x64 [f,f,f], 64x64 [h,h,h]
oiio:subimages: 3
oiio:subimages: 3
oiio:subimages: 3
explicit -d uint save result:
uint8.tif : 128 x 128, 3 channel, uint8 tiff
tile size: 16 x 16
Expand Down
19 changes: 19 additions & 0 deletions testsuite/oiiotool-copy/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,25 @@
command += oiiotool ("src/rgbaz.exr -d half -d Z=float -o rgbahalf-zfloat.exr")
command += info_command ("rgbahalf-zfloat.exr", safematch=1)

# test -d SUBIMAGE.NAME=fmt to change data format of one subimage
command += oiiotool ("--create 64x64 3 --attrib oiio:subimagename subimageA " +
"--create 64x64 3 --attrib oiio:subimagename subimageB " +
"--create 64x64 4 --attrib oiio:subimagename subimageC " +
"--siappendall -d half -d subimageB.G=float -o sub-formats.exr")
command += info_command ("sub-formats.exr", extraargs="--metamatch subimages")
# test -d SUBIMAGE.*=fmt to change data format of one channel of one subimage
command += oiiotool ("--create 64x64 3 --attrib oiio:subimagename subimageA " +
"--create 64x64 3 --attrib oiio:subimagename subimageB " +
"--create 64x64 4 --attrib oiio:subimagename subimageC " +
"--siappendall -d half -d subimageB.*=float -o sub-formats2.exr")
command += info_command ("sub-formats2.exr", extraargs="--metamatch subimages")
# test -d SUBIMAGE.*=fmt to change data format of one channel of one subimage,
# when no subimages are named (they wil be upon output) but it will still
# recognize "subimage{:02}".
command += oiiotool ("--create 64x64 3 --dup --dup " +
"--siappendall -d half -d subimage01.*=float -o sub-formats3.exr")
command += info_command ("sub-formats3.exr", extraargs="--metamatch subimages")


# Some tests to verify that we are transferring data formats properly.
#
Expand Down
Loading