diff options
Diffstat (limited to 'third_party/jpeg-xl/lib/jxl/jpeg/enc_jpeg_data_reader.cc')
-rw-r--r-- | third_party/jpeg-xl/lib/jxl/jpeg/enc_jpeg_data_reader.cc | 37 |
1 files changed, 17 insertions, 20 deletions
diff --git a/third_party/jpeg-xl/lib/jxl/jpeg/enc_jpeg_data_reader.cc b/third_party/jpeg-xl/lib/jxl/jpeg/enc_jpeg_data_reader.cc index d1e8476db6..8208bba675 100644 --- a/third_party/jpeg-xl/lib/jxl/jpeg/enc_jpeg_data_reader.cc +++ b/third_party/jpeg-xl/lib/jxl/jpeg/enc_jpeg_data_reader.cc @@ -92,21 +92,21 @@ bool ProcessSOF(const uint8_t* data, const size_t len, JpegReadMode mode, std::vector<bool> ids_seen(256, false); int max_h_samp_factor = 1; int max_v_samp_factor = 1; - for (size_t i = 0; i < jpg->components.size(); ++i) { + for (auto& component : jpg->components) { const int id = ReadUint8(data, pos); if (ids_seen[id]) { // (cf. section B.2.2, syntax of Ci) return JXL_FAILURE("Duplicate ID %d in SOF.", id); } ids_seen[id] = true; - jpg->components[i].id = id; + component.id = id; int factor = ReadUint8(data, pos); int h_samp_factor = factor >> 4; int v_samp_factor = factor & 0xf; JXL_JPEG_VERIFY_INPUT(h_samp_factor, 1, kBrunsliMaxSampling, SAMP_FACTOR); JXL_JPEG_VERIFY_INPUT(v_samp_factor, 1, kBrunsliMaxSampling, SAMP_FACTOR); - jpg->components[i].h_samp_factor = h_samp_factor; - jpg->components[i].v_samp_factor = v_samp_factor; - jpg->components[i].quant_idx = ReadUint8(data, pos); + component.h_samp_factor = h_samp_factor; + component.v_samp_factor = v_samp_factor; + component.quant_idx = ReadUint8(data, pos); max_h_samp_factor = std::max(max_h_samp_factor, h_samp_factor); max_v_samp_factor = std::max(max_v_samp_factor, v_samp_factor); } @@ -116,18 +116,17 @@ bool ProcessSOF(const uint8_t* data, const size_t len, JpegReadMode mode, int MCU_rows = DivCeil(jpg->height, max_v_samp_factor * 8); int MCU_cols = DivCeil(jpg->width, max_h_samp_factor * 8); // Compute the block dimensions for each component. - for (size_t i = 0; i < jpg->components.size(); ++i) { - JPEGComponent* c = &jpg->components[i]; - if (max_h_samp_factor % c->h_samp_factor != 0 || - max_v_samp_factor % c->v_samp_factor != 0) { + for (JPEGComponent& c : jpg->components) { + if (max_h_samp_factor % c.h_samp_factor != 0 || + max_v_samp_factor % c.v_samp_factor != 0) { return JXL_FAILURE("Non-integral subsampling ratios."); } - c->width_in_blocks = MCU_cols * c->h_samp_factor; - c->height_in_blocks = MCU_rows * c->v_samp_factor; + c.width_in_blocks = MCU_cols * c.h_samp_factor; + c.height_in_blocks = MCU_rows * c.v_samp_factor; const uint64_t num_blocks = - static_cast<uint64_t>(c->width_in_blocks) * c->height_in_blocks; + static_cast<uint64_t>(c.width_in_blocks) * c.height_in_blocks; if (mode == JpegReadMode::kReadAll) { - c->coeffs.resize(num_blocks * kDCTBlockSize); + c.coeffs.resize(num_blocks * kDCTBlockSize); } } JXL_JPEG_VERIFY_MARKER_END(); @@ -192,8 +191,8 @@ bool ProcessSOS(const uint8_t* data, const size_t len, size_t* pos, for (size_t i = 0; i < comps_in_scan; ++i) { bool found_dc_table = false; bool found_ac_table = false; - for (size_t j = 0; j < jpg->huffman_code.size(); ++j) { - uint32_t slot_id = jpg->huffman_code[j].slot_id; + for (const auto& code : jpg->huffman_code) { + uint32_t slot_id = code.slot_id; if (slot_id == scan_info.components[i].dc_tbl_idx) { found_dc_table = true; } else if (slot_id == scan_info.components[i].ac_tbl_idx + 16) { @@ -757,11 +756,9 @@ bool ProcessScan(const uint8_t* data, const size_t len, bool is_interleaved = (scan_info->num_components > 1); int max_h_samp_factor = 1; int max_v_samp_factor = 1; - for (size_t i = 0; i < jpg->components.size(); ++i) { - max_h_samp_factor = - std::max(max_h_samp_factor, jpg->components[i].h_samp_factor); - max_v_samp_factor = - std::max(max_v_samp_factor, jpg->components[i].v_samp_factor); + for (const auto& component : jpg->components) { + max_h_samp_factor = std::max(max_h_samp_factor, component.h_samp_factor); + max_v_samp_factor = std::max(max_v_samp_factor, component.v_samp_factor); } int MCU_rows = DivCeil(jpg->height, max_v_samp_factor * 8); |