GameApi 28
Library used by GameApi Builder tool
Loading...
Searching...
No Matches
prediction_scheme_wrap_decoding_transform.h
Go to the documentation of this file.
1// Copyright 2016 The Draco Authors.
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14//
15#ifndef DRACO_COMPRESSION_ATTRIBUTES_PREDICTION_SCHEMES_PREDICTION_SCHEME_WRAP_DECODING_TRANSFORM_H_
16#define DRACO_COMPRESSION_ATTRIBUTES_PREDICTION_SCHEMES_PREDICTION_SCHEME_WRAP_DECODING_TRANSFORM_H_
17
20
21namespace draco {
22
23// PredictionSchemeWrapDecodingTransform unwraps values encoded with the
24// PredictionSchemeWrapEncodingTransform.
25// See prediction_scheme_wrap_transform_base.h for more details about the
26// method.
27template <typename DataTypeT, typename CorrTypeT = DataTypeT>
29 : public PredictionSchemeWrapTransformBase<DataTypeT> {
30 public:
31 typedef CorrTypeT CorrType;
33
34 // Computes the original value from the input predicted value and the decoded
35 // corrections. Values out of the bounds of the input values are unwrapped.
36 inline void ComputeOriginalValue(const DataTypeT *predicted_vals,
37 const CorrTypeT *corr_vals,
38 DataTypeT *out_original_vals) const {
39 // For now we assume both |DataTypeT| and |CorrTypeT| are equal.
40 static_assert(std::is_same<DataTypeT, CorrTypeT>::value,
41 "Predictions and corrections must have the same type.");
42
43 // The only valid implementation right now is for int32_t.
44 static_assert(std::is_same<DataTypeT, int32_t>::value,
45 "Only int32_t is supported for predicted values.");
46
47 predicted_vals = this->ClampPredictedValue(predicted_vals);
48
49 // Perform the wrapping using unsigned coordinates to avoid potential signed
50 // integer overflows caused by malformed input.
51 const uint32_t *const uint_predicted_vals =
52 reinterpret_cast<const uint32_t *>(predicted_vals);
53 const uint32_t *const uint_corr_vals =
54 reinterpret_cast<const uint32_t *>(corr_vals);
55 for (int i = 0; i < this->num_components(); ++i) {
56 out_original_vals[i] =
57 static_cast<DataTypeT>(uint_predicted_vals[i] + uint_corr_vals[i]);
58 if (out_original_vals[i] > this->max_value()) {
59 out_original_vals[i] -= this->max_dif();
60 } else if (out_original_vals[i] < this->min_value()) {
61 out_original_vals[i] += this->max_dif();
62 }
63 }
64 }
65
67 DataTypeT min_value, max_value;
68 if (!buffer->Decode(&min_value)) {
69 return false;
70 }
71 if (!buffer->Decode(&max_value)) {
72 return false;
73 }
74 if (min_value > max_value) {
75 return false;
76 }
77 this->set_min_value(min_value);
78 this->set_max_value(max_value);
79 if (!this->InitCorrectionBounds()) {
80 return false;
81 }
82 return true;
83 }
84};
85
86} // namespace draco
87
88#endif // DRACO_COMPRESSION_ATTRIBUTES_PREDICTION_SCHEMES_PREDICTION_SCHEME_WRAP_DECODING_TRANSFORM_H_
Definition decoder_buffer.h:30
bool Decode(T *out_val)
Definition decoder_buffer.h:68
bool DecodeTransformData(DecoderBuffer *buffer)
Definition prediction_scheme_wrap_decoding_transform.h:66
PredictionSchemeWrapDecodingTransform()
Definition prediction_scheme_wrap_decoding_transform.h:32
void ComputeOriginalValue(const DataTypeT *predicted_vals, const CorrTypeT *corr_vals, DataTypeT *out_original_vals) const
Definition prediction_scheme_wrap_decoding_transform.h:36
CorrTypeT CorrType
Definition prediction_scheme_wrap_decoding_transform.h:31
PredictionSchemeWrapTransformBase()
Definition prediction_scheme_wrap_transform_base.h:43
DataTypeT min_value() const
Definition prediction_scheme_wrap_transform_base.h:99
const DataTypeT * ClampPredictedValue(const DataTypeT *predicted_val) const
Definition prediction_scheme_wrap_transform_base.h:62
void set_max_value(const DataTypeT &v)
Definition prediction_scheme_wrap_transform_base.h:102
bool InitCorrectionBounds()
Definition prediction_scheme_wrap_transform_base.h:83
DataTypeT max_dif() const
Definition prediction_scheme_wrap_transform_base.h:103
int num_components() const
Definition prediction_scheme_wrap_transform_base.h:98
void set_min_value(const DataTypeT &v)
Definition prediction_scheme_wrap_transform_base.h:100
DataTypeT max_value() const
Definition prediction_scheme_wrap_transform_base.h:101
Definition attribute_octahedron_transform.cc:21