// Copyright (c) the JPEG XL Project Authors. All rights reserved. // // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file.
// Struct to collect all the data needed to build a tree. struct TreeSamples { bool HasSamples() const { return !residuals.empty() && !residuals[0].empty();
}
size_t NumDistinctSamples() const { return sample_counts.size(); }
size_t NumSamples() const { return num_samples; } // Set the predictor to use. Must be called before adding any samples.
Status SetPredictor(Predictor predictor,
ModularOptions::TreeMode wp_tree_mode); // Set the properties to use. Must be called before adding any samples.
Status SetProperties(const std::vector<uint32_t> &properties,
ModularOptions::TreeMode wp_tree_mode);
// Preallocate data for a given number of samples. MUST be called before // adding any sample. void PrepareForSamples(size_t num_samples); // Add a sample. void AddSample(pixel_type_w pixel, const Properties &properties, const pixel_type_w *predictions); // Pre-cluster property values. void PreQuantizeProperties( const StaticPropRange &range, const std::vector<ModularMultiplierInfo> &multiplier_info, const std::vector<uint32_t> &group_pixel_count, const std::vector<uint32_t> &channel_pixel_count,
std::vector<pixel_type> &pixel_samples,
std::vector<pixel_type> &diff_samples, size_t max_property_values);
// Swaps samples in position a and b. Does nothing if a == b. void Swap(size_t a, size_t b);
// Cycles samples: a -> b -> c -> a. We assume a <= b <= c, so that we can // just call Swap(a, b) if b==c. void ThreeShuffle(size_t a, size_t b, size_t c);
private: // TODO(veluca): as the total number of properties and predictors are known // before adding any samples, it might be better to interleave predictors, // properties and counts in a single vector to improve locality. // A first attempt at doing this actually results in much slower encoding, // possibly because of the more complex addressing. struct ResidualToken {
uint8_t tok;
uint8_t nbits;
}; // Residual information: token and number of extra bits, per predictor.
std::vector<std::vector<ResidualToken>> residuals; // Number of occurrences of each sample.
std::vector<uint16_t> sample_counts; // Property values, quantized to at most 256 distinct values.
std::vector<std::vector<uint8_t>> props; // Decompactification info for `props`.
std::vector<std::vector<int32_t>> compact_properties; // List of properties to use.
std::vector<uint32_t> props_to_use; // List of predictors to use.
std::vector<Predictor> predictors; // Mapping property value -> quantized property value. static constexpr int32_t kPropertyRange = 511;
std::vector<std::vector<uint8_t>> property_mapping; // Number of samples seen.
size_t num_samples = 0; // Table for deduplication. static constexpr uint32_t kDedupEntryUnused{static_cast<uint32_t>(-1)};
std::vector<uint32_t> dedup_table_;
// Functions for sample deduplication. bool IsSameSample(size_t a, size_t b) const;
size_t Hash1(size_t a) const;
size_t Hash2(size_t a) const; void InitTable(size_t log_size); // Returns true if `a` was already present in the table. bool AddToTableAndMerge(size_t a); void AddToTable(size_t a);
};
Status TokenizeTree(const Tree &tree, std::vector<Token> *tokens,
Tree *decoder_tree);
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.