Skip to content

Commit d3bfe09

Browse files
committed
DPX cont
Signed-off-by: Larry Gritz <[email protected]>
1 parent bfb75cb commit d3bfe09

File tree

5 files changed

+103
-9
lines changed

5 files changed

+103
-9
lines changed

src/doc/builtinplugins.rst

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -322,6 +322,18 @@ control aspects of the writing itself:
322322
- ptr
323323
- Pointer to a ``Filesystem::IOProxy`` that will handle the I/O, for
324324
example by writing to memory rather than the file system.
325+
* - ``dpx:ImageDescriptor``
326+
- string
327+
- Requests an encoding for the image data in the file. Possible values of the ImageDescriptor are:
328+
``"Red"``, ``"Green"``, ``"Blue"``, ``"Alpha"``, ``"Luma"``,
329+
``"ColorDifference"``, ``"Depth"``, ``"CompositeVideo"``, ``"RGB"``,
330+
``"RGBA"``, ``"ABGR"``, ``"CbYCrY"``, ``"CbYACrYA"``, ``"CbYCr"``,
331+
``"CbYCrA"``. Note that OpenImageIO does not support automatic
332+
conversion of regular RGB data to these exotic formats, therefore this
333+
request will only be conveyed into the output file if the
334+
``oiio:RawColor`` configuration hint is also set to nonzero, indicating
335+
that the caller has ensured that the data presented is already in the
336+
correct representation.
325337

326338
**Custom I/O Overrides**
327339

@@ -383,7 +395,15 @@ the `set_ioproxy()` methods.
383395
- Colorimetric specification
384396
* - ``dpx:ImageDescriptor``
385397
- string
386-
- ImageDescriptor
398+
- Describes the encoding of the image data in the file. Possible values of the ImageDescriptor are:
399+
``"Red"``, ``"Green"``, ``"Blue"``, ``"Alpha"``, ``"Luma"``,
400+
``"ColorDifference"``, ``"Depth"``, ``"CompositeVideo"``, ``"RGB"``,
401+
``"RGBA"``, ``"ABGR"``, ``"CbYCrY"``, ``"CbYACrYA"``, ``"CbYCr"``,
402+
``"CbYCrA"``, or custom descriptors. Only if the file was opened with
403+
the configuration hint ``oiio:RawColor``, the values will be preserved
404+
in this representation; otherwise, they will be converted to RGB color
405+
space (in which case this attribute only describes the state of the
406+
file, not the data in the buffer you read).
387407
* - ``dpx:Packing``
388408
- string
389409
- Image packing method

src/dpx.imageio/dpxoutput.cpp

Lines changed: 34 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -431,6 +431,11 @@ DPXOutput::prep_subimage(int s, bool allocate)
431431
{
432432
ImageSpec& spec_s(m_subimage_specs[s]); // reference the spec
433433

434+
// check if the client is giving us raw data to write
435+
m_rawcolor = spec_s.get_int_attribute("dpx:RawColor")
436+
|| spec_s.get_int_attribute("dpx:RawData") // deprecated
437+
|| spec_s.get_int_attribute("oiio:RawColor");
438+
434439
// determine descriptor
435440
m_desc = get_image_descriptor();
436441

@@ -517,13 +522,9 @@ DPXOutput::prep_subimage(int s, bool allocate)
517522
m_datasize = dpx::kWord;
518523
}
519524

520-
// check if the client is giving us raw data to write
521-
m_rawcolor = spec_s.get_int_attribute("dpx:RawColor")
522-
|| spec_s.get_int_attribute("dpx:RawData") // deprecated
523-
|| spec_s.get_int_attribute("oiio:RawColor");
524-
525525
// see if we'll need to convert color space or not
526-
if (m_desc == dpx::kRGB || m_desc == dpx::kRGBA || spec_s.nchannels == 1) {
526+
if (spec_s.nchannels == 1 || m_desc == dpx::kRGB || m_desc == dpx::kRGBA
527+
|| m_desc == dpx::kABGR) {
527528
// shortcut for RGB/RGBA, and for 1-channel images that don't
528529
// need to decode color representations.
529530
m_bytes = spec_s.scanline_bytes();
@@ -696,6 +697,7 @@ dpx::Descriptor
696697
DPXOutput::get_image_descriptor()
697698
{
698699
const ImageSpec& spec0(m_subimage_specs[0]);
700+
string_view request = spec0.get_string_attribute("dpx:ImageDescriptor");
699701
switch (spec0.nchannels) {
700702
case 1: {
701703
std::string name = spec0.channelnames.size() ? spec0.channelnames[0]
@@ -713,8 +715,32 @@ DPXOutput::get_image_descriptor()
713715
else
714716
return dpx::kLuma;
715717
}
716-
case 3: return dpx::kRGB;
717-
case 4: return dpx::kRGBA;
718+
case 3: {
719+
if (m_rawcolor) {
720+
// Only allow these if we're being given "raw color" data, assumed
721+
// to already be in the requested representation. We don't support
722+
// converting usual RGB/RGBA to these exotic dpx types.
723+
if (request == "CbYCrY")
724+
return dpx::kCbYCrY;
725+
else if (request == "CbYCr")
726+
return dpx::kCbYCr;
727+
}
728+
return dpx::kRGB;
729+
}
730+
case 4: {
731+
if (m_rawcolor) {
732+
// Only allow these if we're being given "raw color" data, assumed
733+
// to already be in the requested representation. We don't support
734+
// converting usual RGB/RGBA to these exotic dpx types.
735+
if (request == "ABGR")
736+
return dpx::kABGR;
737+
else if (request == "CbYACrYA")
738+
return dpx::kCbYACrYA;
739+
else if (request == "CbYCrA")
740+
return dpx::kCbYCrA;
741+
}
742+
return dpx::kRGBA;
743+
}
718744
default:
719745
if (spec0.nchannels <= 8)
720746
return (dpx::Descriptor)((int)dpx::kUserDefined2Comp

testsuite/dpx/ref/out.txt

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,3 +158,41 @@ grey.dpx : 512 x 512, 1 channel, uint10 dpx
158158
oiio:subimages: 1
159159
Comparing "grey.dpx" and "ref/grey.tif"
160160
PASS
161+
Reading gradient.dpx
162+
gradient.dpx : 64 x 64, 4 channel, uint16 dpx
163+
SHA-1: C379576BBA43B7937C6C9F6FBB3DA95206EA8AC1
164+
channel list: R, G, B, A
165+
Orientation: 1 (normal)
166+
PixelAspectRatio: 1
167+
dpx:Colorimetric: "User defined"
168+
dpx:DittoKey: 1
169+
dpx:EndOfImagePadding: 0
170+
dpx:EndOfLinePadding: 0
171+
dpx:ImageDescriptor: "RGBA"
172+
dpx:Packing: "Filled, method A"
173+
dpx:Signal: "Undefined"
174+
dpx:Transfer: "Undefined"
175+
dpx:Version: "V2.0"
176+
oiio:BitsPerSample: 16
177+
oiio:subimages: 1
178+
Comparing "gradient.dpx" and "src/gradient.tif"
179+
PASS
180+
Reading gradient-abgr.dpx
181+
gradient-abgr.dpx : 64 x 64, 4 channel, uint16 dpx
182+
SHA-1: C379576BBA43B7937C6C9F6FBB3DA95206EA8AC1
183+
channel list: R, G, B, A
184+
Orientation: 1 (normal)
185+
PixelAspectRatio: 1
186+
dpx:Colorimetric: "User defined"
187+
dpx:DittoKey: 1
188+
dpx:EndOfImagePadding: 0
189+
dpx:EndOfLinePadding: 0
190+
dpx:ImageDescriptor: "ABGR"
191+
dpx:Packing: "Filled, method A"
192+
dpx:Signal: "Undefined"
193+
dpx:Transfer: "Undefined"
194+
dpx:Version: "V2.0"
195+
oiio:BitsPerSample: 16
196+
oiio:subimages: 1
197+
Comparing "gradient-abgr.dpx" and "src/gradient.tif"
198+
PASS

testsuite/dpx/run.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,3 +31,13 @@
3131
" -chsum:weight=0.333,0.333,0.333 -chnames Y -ch Y -o grey.dpx")
3232
command += info_command("grey.dpx", safematch=True)
3333
command += diff_command("grey.dpx", "ref/grey.tif")
34+
35+
# Test some other combinations of encodings
36+
# Pre-made: oiiotool -d uint16 -pattern fill:topleft=1,0,0,1:topright=0,1,0,1:bottomleft=0,0,1,1:bottomright=1,1,1,1 64x64 4 -o src/gradient.tif
37+
command += oiiotool("src/gradient.tif -o gradient.dpx")
38+
command += info_command("gradient.dpx", safematch=True)
39+
command += diff_command("gradient.dpx", "src/gradient.tif")
40+
command += oiiotool("src/gradient.tif -ch A,B,G,R --chnames A,B,G,R -attrib oiio:RawColor 1 -attrib dpx:ImageDescriptor ABGR -o gradient-abgr.dpx")
41+
command += info_command("gradient-abgr.dpx", safematch=True)
42+
command += diff_command("gradient-abgr.dpx", "src/gradient.tif")
43+

testsuite/dpx/src/gradient.tif

2.55 KB
Binary file not shown.

0 commit comments

Comments
 (0)