Skip to content

Commit 822b06f

Browse files
committed
Use cspan and snake case
Signed-off-by: Brecht Van Lommel <[email protected]>
1 parent b9ea1c9 commit 822b06f

File tree

11 files changed

+36
-35
lines changed

11 files changed

+36
-35
lines changed

src/ffmpeg.imageio/ffmpeginput.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -551,7 +551,7 @@ FFmpegInput::open(const std::string& name, ImageSpec& spec)
551551
m_codec_context->color_range == AVCOL_RANGE_MPEG ? 0 : 1 };
552552
m_spec.attribute("CICP", TypeDesc(TypeDesc::INT, 4), cicp);
553553
const ColorConfig& colorconfig(ColorConfig::default_colorconfig());
554-
string_view interop_id = colorconfig.getColorInteropID(cicp);
554+
string_view interop_id = colorconfig.get_color_interop_id(cicp);
555555
if (!interop_id.empty())
556556
m_spec.attribute("oiio:ColorSpace", interop_id);
557557

src/heif.imageio/heifinput.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -295,7 +295,7 @@ HeifInput::seek_subimage(int subimage, int miplevel)
295295
m_spec.attribute("CICP", TypeDesc(TypeDesc::INT, 4), cicp);
296296
const ColorConfig& colorconfig(
297297
ColorConfig::default_colorconfig());
298-
string_view interop_id = colorconfig.getColorInteropID(cicp);
298+
string_view interop_id = colorconfig.get_color_interop_id(cicp);
299299
if (!interop_id.empty())
300300
m_spec.attribute("oiio:ColorSpace", interop_id);
301301
}

src/heif.imageio/heifoutput.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -254,9 +254,9 @@ HeifOutput::close()
254254
const ParamValue* p = m_spec.find_attribute("CICP",
255255
TypeDesc(TypeDesc::INT, 4));
256256
string_view colorspace = m_spec.get_string_attribute("oiio:ColorSpace");
257-
const int* cicp = (p) ? static_cast<const int*>(p->data())
258-
: colorconfig.getCICP(colorspace);
259-
if (cicp) {
257+
cspan<int> cicp = (p) ? p->as_cspan<int>()
258+
: colorconfig.get_cicp(colorspace);
259+
if (!cicp.empty()) {
260260
nclx->color_primaries = heif_color_primaries(cicp[0]);
261261
nclx->transfer_characteristics = heif_transfer_characteristics(
262262
cicp[1]);

src/include/OpenImageIO/color.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -403,16 +403,16 @@ class OIIO_API ColorConfig {
403403
string_view other_color_space) const;
404404

405405
/// Find CICP code corresponding to the colorspace.
406-
/// Returns pointer to int[4], and nullptr if not found.
406+
/// Return a cspan of 4 ints, or an empty span if not found.
407407
///
408408
/// @version 3.1
409-
const int* getCICP(string_view colorspace) const;
409+
cspan<int> get_cicp(string_view colorspace) const;
410410

411411
/// Find color interop ID corresponding to the CICP code.
412412
/// Returns empty string if not found.
413413
///
414414
/// @version 3.1
415-
string_view getColorInteropID(const int cicp[4]) const;
415+
string_view get_color_interop_id(const int cicp[4]) const;
416416

417417
/// Return a filename or other identifier for the config we're using.
418418
std::string configname() const;

src/libOpenImageIO/color_ocio.cpp

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2095,7 +2095,7 @@ constexpr ColorInteropID color_interop_ids[] = {
20952095
} // namespace
20962096

20972097
string_view
2098-
ColorConfig::getColorInteropID(const int cicp[4]) const
2098+
ColorConfig::get_color_interop_id(const int cicp[4]) const
20992099
{
21002100
for (const ColorInteropID& interop : color_interop_ids) {
21012101
if (interop.cicp[0] == cicp[0] && interop.cicp[1] == cicp[1]) {
@@ -2105,17 +2105,17 @@ ColorConfig::getColorInteropID(const int cicp[4]) const
21052105
return "";
21062106
}
21072107

2108-
const int*
2109-
ColorConfig::getCICP(string_view colorspace) const
2108+
cspan<int>
2109+
ColorConfig::get_cicp(string_view colorspace) const
21102110
{
21112111
if (!colorspace.empty()) {
21122112
for (const ColorInteropID& interop : color_interop_ids) {
21132113
if (equivalent(colorspace, interop.interop_id)) {
2114-
return interop.cicp.data();
2114+
return interop.cicp;
21152115
}
21162116
}
21172117
}
2118-
return nullptr;
2118+
return cspan<int>();
21192119
}
21202120

21212121

@@ -2776,6 +2776,7 @@ ColorConfig::set_colorspace_rec709_gamma(ImageSpec& spec, float gamma) const
27762776
}
27772777
}
27782778

2779+
27792780
void
27802781
set_colorspace(ImageSpec& spec, string_view colorspace)
27812782
{

src/png.imageio/png_pvt.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -333,7 +333,7 @@ read_info(png_structp& sp, png_infop& ip, int& bit_depth, int& color_type,
333333
const int cicp[4] = { pri, trc, mtx, vfr };
334334
spec.attribute(CICP_ATTR, TypeDesc(TypeDesc::INT, 4), cicp);
335335
const ColorConfig& colorconfig(ColorConfig::default_colorconfig());
336-
string_view interop_id = colorconfig.getColorInteropID(cicp);
336+
string_view interop_id = colorconfig.get_color_interop_id(cicp);
337337
if (!interop_id.empty())
338338
spec.attribute("oiio:ColorSpace", interop_id);
339339
}
@@ -740,10 +740,10 @@ write_info(png_structp& sp, png_infop& ip, int& color_type, ImageSpec& spec,
740740
// write colorspace metadata yet.
741741
const ParamValue* p = spec.find_attribute(CICP_ATTR,
742742
TypeDesc(TypeDesc::INT, 4));
743-
const int* cicp = (p) ? static_cast<const int*>(p->data())
744-
: (!wrote_colorspace) ? colorconfig.getCICP(colorspace)
745-
: nullptr;
746-
if (cicp) {
743+
cspan<int> cicp = (p) ? p->as_cspan<int>()
744+
: (!wrote_colorspace) ? colorconfig.get_cicp(colorspace)
745+
: cspan<int>();
746+
if (!cicp.empty()) {
747747
png_byte vals[4];
748748
for (int i = 0; i < 4; ++i)
749749
vals[i] = static_cast<png_byte>(cicp[i]);

src/python/py_colorconfig.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -161,15 +161,15 @@ declare_colorconfig(py::module& m)
161161
return self.equivalent(color_space, other_color_space);
162162
},
163163
"color_space"_a, "other_color_space"_a)
164-
.def("getColorInteropID",
164+
.def("get_color_interop_id",
165165
[](const ColorConfig& self, const std::array<int, 4> cicp) {
166-
return std::string(self.getColorInteropID(cicp.data()));
166+
return std::string(self.get_color_interop_id(cicp.data()));
167167
})
168-
.def("getCICP",
168+
.def("get_cicp",
169169
[](const ColorConfig& self, const std::string& colorspace)
170170
-> std::optional<std::array<int, 4>> {
171-
const int* cicp = self.getCICP(colorspace);
172-
if (cicp) {
171+
cspan<int> cicp = self.get_cicp(colorspace);
172+
if (!cicp.empty()) {
173173
return std::array<int, 4>(
174174
{ cicp[0], cicp[1], cicp[2], cicp[3] });
175175
}

testsuite/python-colorconfig/ref/out-ocio23.txt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,9 @@ equivalent('linear', 'lin_srgb'): False
2626
equivalent('scene_linear', 'lin_srgb'): False
2727
equivalent('ACEScg', 'scene_linear'): True
2828
equivalent('lnf', 'scene_linear'): False
29-
getColorInteropID([1, 13, 1, 1]) = srgb_rec709_scene
30-
getCICP('pq_rec2020_display') = [9, 16, 9, 1]
31-
getCICP('unknown_interop_id') = None
29+
get_color_interop_id([1, 13, 1, 1]) = srgb_rec709_scene
30+
get_cicp('pq_rec2020_display') = [9, 16, 9, 1]
31+
get_cicp('unknown_interop_id') = None
3232

3333
Loaded test OCIO config: oiio_test_v0.9.2.ocio
3434
Parsed color space for filepath 'foo_lin_ap1.exr': ACEScg

testsuite/python-colorconfig/ref/out-ocio24.txt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,9 @@ equivalent('linear', 'lin_srgb'): False
2626
equivalent('scene_linear', 'lin_srgb'): False
2727
equivalent('ACEScg', 'scene_linear'): True
2828
equivalent('lnf', 'scene_linear'): False
29-
getColorInteropID([1, 13, 1, 1]) = srgb_rec709_scene
30-
getCICP('pq_rec2020_display') = [9, 16, 9, 1]
31-
getCICP('unknown_interop_id') = None
29+
get_color_interop_id([1, 13, 1, 1]) = srgb_rec709_scene
30+
get_cicp('pq_rec2020_display') = [9, 16, 9, 1]
31+
get_cicp('unknown_interop_id') = None
3232

3333
Loaded test OCIO config: oiio_test_v0.9.2.ocio
3434
Parsed color space for filepath 'foo_lin_ap1.exr': ACEScg

testsuite/python-colorconfig/ref/out-ocio25.txt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,9 @@ equivalent('linear', 'lin_srgb'): False
2626
equivalent('scene_linear', 'lin_srgb'): False
2727
equivalent('ACEScg', 'scene_linear'): True
2828
equivalent('lnf', 'scene_linear'): False
29-
getColorInteropID([1, 13, 1, 1]) = srgb_rec709_scene
30-
getCICP('pq_rec2020_display') = [9, 16, 9, 1]
31-
getCICP('unknown_interop_id') = None
29+
get_color_interop_id([1, 13, 1, 1]) = srgb_rec709_scene
30+
get_cicp('pq_rec2020_display') = [9, 16, 9, 1]
31+
get_cicp('unknown_interop_id') = None
3232

3333
Loaded test OCIO config: oiio_test_v0.9.2.ocio
3434
Parsed color space for filepath 'foo_lin_ap1.exr': ACEScg

0 commit comments

Comments
 (0)