From 40a355a42d4a9444dc753c04c6608dade2f06a23 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Fri, 19 Apr 2024 03:13:27 +0200 Subject: Adding upstream version 125.0.1. Signed-off-by: Daniel Baumann --- third_party/jpeg-xl/lib/extras/enc/npy.cc | 35 ++++++++++++++++++------------- 1 file changed, 20 insertions(+), 15 deletions(-) (limited to 'third_party/jpeg-xl/lib/extras/enc/npy.cc') diff --git a/third_party/jpeg-xl/lib/extras/enc/npy.cc b/third_party/jpeg-xl/lib/extras/enc/npy.cc index ae8cf13cc4..8d9954ef31 100644 --- a/third_party/jpeg-xl/lib/extras/enc/npy.cc +++ b/third_party/jpeg-xl/lib/extras/enc/npy.cc @@ -7,11 +7,13 @@ #include +#include #include #include #include #include "lib/extras/packed_image.h" +#include "lib/jxl/base/common.h" namespace jxl { namespace extras { @@ -52,14 +54,17 @@ class JSONDict : public JSONField { static_assert(std::is_convertible::value, "T must be a JSONField"); T* ret = new T(); - values_.emplace_back( - key, std::unique_ptr(static_cast(ret))); + JSONField* field = static_cast(ret); + auto handle = std::unique_ptr(field); + values_.emplace_back(key, std::move(handle)); return ret; } template void Add(const std::string& key, const T& value) { - values_.emplace_back(key, std::unique_ptr(new JSONValue(value))); + JSONField* field = static_cast(new JSONValue(value)); + auto handle = std::unique_ptr(field); + values_.emplace_back(key, std::move(handle)); } void Write(std::ostream& o, uint32_t indent) const override { @@ -71,11 +76,11 @@ class JSONDict : public JSONField { o << ","; } is_first = false; - o << std::endl << indent_str << " \"" << key_value.first << "\": "; + o << "\n" << indent_str << " \"" << key_value.first << "\": "; key_value.second->Write(o, indent + 2); } if (!values_.empty()) { - o << std::endl << indent_str; + o << "\n" << indent_str; } o << "}"; } @@ -112,11 +117,11 @@ class JSONArray : public JSONField { o << ","; } is_first = false; - o << std::endl << indent_str << " "; + o << "\n" << indent_str << " "; value->Write(o, indent + 2); } if (!values_.empty()) { - o << std::endl << indent_str; + o << "\n" << indent_str; } o << "]"; } @@ -160,13 +165,13 @@ void GenerateMetadata(const PackedPixelFile& ppf, std::vector* out) { } { - auto ectype = meta.AddEmpty("extra_channel_type"); - auto bps = meta.AddEmpty("bits_per_sample"); - auto ebps = meta.AddEmpty("exp_bits_per_sample"); + auto* ectype = meta.AddEmpty("extra_channel_type"); + auto* bps = meta.AddEmpty("bits_per_sample"); + auto* ebps = meta.AddEmpty("exp_bits_per_sample"); bps->Add(ppf.info.bits_per_sample); ebps->Add(ppf.info.exponent_bits_per_sample); - for (size_t i = 0; i < ppf.extra_channels_info.size(); i++) { - switch (ppf.extra_channels_info[i].ec_info.type) { + for (const auto& eci : ppf.extra_channels_info) { + switch (eci.ec_info.type) { case JXL_CHANNEL_ALPHA: { ectype->Add(std::string("Alpha")); break; @@ -200,8 +205,8 @@ void GenerateMetadata(const PackedPixelFile& ppf, std::vector* out) { break; } } - bps->Add(ppf.extra_channels_info[i].ec_info.bits_per_sample); - ebps->Add(ppf.extra_channels_info[i].ec_info.exponent_bits_per_sample); + bps->Add(eci.ec_info.bits_per_sample); + ebps->Add(eci.ec_info.exponent_bits_per_sample); } } @@ -282,7 +287,7 @@ bool WriteNPYArray(const PackedPixelFile& ppf, std::vector* out) { class NumPyEncoder : public Encoder { public: Status Encode(const PackedPixelFile& ppf, EncodedImage* encoded_image, - ThreadPool* pool = nullptr) const override { + ThreadPool* pool) const override { JXL_RETURN_IF_ERROR(VerifyBasicInfo(ppf.info)); GenerateMetadata(ppf, &encoded_image->metadata); encoded_image->bitstreams.emplace_back(); -- cgit v1.2.3