GameApi 28
Library used by GameApi Builder tool
Loading...
Searching...
No Matches
prediction_scheme_normal_octahedron_canonicalized_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_NORMAL_OCTAHEDRON_CANONICALIZED_DECODING_TRANSFORM_H_
16#define DRACO_COMPRESSION_ATTRIBUTES_PREDICTION_SCHEMES_PREDICTION_SCHEME_NORMAL_OCTAHEDRON_CANONICALIZED_DECODING_TRANSFORM_H_
17
18#include <cmath>
19
23#include "draco/core/macros.h"
25#include "draco/core/vector_d.h"
26
27namespace draco {
28
29// Class for converting correction values transformed by the canonicalized
30// normal octahedron transform back to the original values. See the
31// corresponding encoder for more details.
32template <typename DataTypeT>
35 DataTypeT> {
36 public:
38 typedef DataTypeT CorrType;
39 typedef DataTypeT DataType;
40
42
43 // Dummy to fulfill concept.
44 void Init(int num_components) {}
45
48 if (!buffer->Decode(&max_quantized_value)) {
49 return false;
50 }
51 if (!buffer->Decode(&center_value)) {
52 return false;
53 }
54 (void)center_value;
55 if (!this->set_max_quantized_value(max_quantized_value)) {
56 return false;
57 }
58 // Account for reading wrong values, e.g., due to fuzzing.
59 if (this->quantization_bits() < 2) {
60 return false;
61 }
62 if (this->quantization_bits() > 30) {
63 return false;
64 }
65 return true;
66 }
67
68 inline void ComputeOriginalValue(const DataType *pred_vals,
69 const CorrType *corr_vals,
70 DataType *out_orig_vals) const {
71 DRACO_DCHECK_LE(pred_vals[0], 2 * this->center_value());
72 DRACO_DCHECK_LE(pred_vals[1], 2 * this->center_value());
73 DRACO_DCHECK_LE(corr_vals[0], 2 * this->center_value());
74 DRACO_DCHECK_LE(corr_vals[1], 2 * this->center_value());
75
76 DRACO_DCHECK_LE(0, pred_vals[0]);
77 DRACO_DCHECK_LE(0, pred_vals[1]);
78 DRACO_DCHECK_LE(0, corr_vals[0]);
79 DRACO_DCHECK_LE(0, corr_vals[1]);
80
81 const Point2 pred = Point2(pred_vals[0], pred_vals[1]);
82 const Point2 corr = Point2(corr_vals[0], corr_vals[1]);
83 const Point2 orig = ComputeOriginalValue(pred, corr);
84
85 out_orig_vals[0] = orig[0];
86 out_orig_vals[1] = orig[1];
87 }
88
89 private:
90 Point2 ComputeOriginalValue(Point2 pred, Point2 corr) const {
91 const Point2 t(this->center_value(), this->center_value());
92 pred = pred - t;
93 const bool pred_is_in_diamond = this->IsInDiamond(pred[0], pred[1]);
94 if (!pred_is_in_diamond) {
95 this->InvertDiamond(&pred[0], &pred[1]);
96 }
97 const bool pred_is_in_bottom_left = this->IsInBottomLeft(pred);
98 const int32_t rotation_count = this->GetRotationCount(pred);
99 if (!pred_is_in_bottom_left) {
100 pred = this->RotatePoint(pred, rotation_count);
101 }
102 Point2 orig(this->ModMax(AddAsUnsigned(pred[0], corr[0])),
103 this->ModMax(AddAsUnsigned(pred[1], corr[1])));
104 if (!pred_is_in_bottom_left) {
105 const int32_t reverse_rotation_count = (4 - rotation_count) % 4;
106 orig = this->RotatePoint(orig, reverse_rotation_count);
107 }
108 if (!pred_is_in_diamond) {
109 this->InvertDiamond(&orig[0], &orig[1]);
110 }
111 orig = orig + t;
112 return orig;
113 }
114};
115
116} // namespace draco
117
118#endif // DRACO_COMPRESSION_ATTRIBUTES_PREDICTION_SCHEMES_PREDICTION_SCHEME_NORMAL_OCTAHEDRON_CANONICALIZED_DECODING_TRANSFORM_H_
Definition decoder_buffer.h:30
bool Decode(T *out_val)
Definition decoder_buffer.h:68
void Init(int num_components)
Definition prediction_scheme_normal_octahedron_canonicalized_decoding_transform.h:44
DataTypeT CorrType
Definition prediction_scheme_normal_octahedron_canonicalized_decoding_transform.h:38
VectorD< DataTypeT, 2 > Point2
Definition prediction_scheme_normal_octahedron_canonicalized_decoding_transform.h:37
void ComputeOriginalValue(const DataType *pred_vals, const CorrType *corr_vals, DataType *out_orig_vals) const
Definition prediction_scheme_normal_octahedron_canonicalized_decoding_transform.h:68
PredictionSchemeNormalOctahedronCanonicalizedDecodingTransform()
Definition prediction_scheme_normal_octahedron_canonicalized_decoding_transform.h:41
bool DecodeTransformData(DecoderBuffer *buffer)
Definition prediction_scheme_normal_octahedron_canonicalized_decoding_transform.h:46
DataTypeT DataType
Definition prediction_scheme_normal_octahedron_canonicalized_decoding_transform.h:39
PredictionSchemeNormalOctahedronCanonicalizedTransformBase()
Definition prediction_scheme_normal_octahedron_canonicalized_transform_base.h:40
Point2 RotatePoint(Point2 p, int32_t rotation_count) const
Definition prediction_scheme_normal_octahedron_canonicalized_transform_base.h:79
int32_t GetRotationCount(Point2 pred) const
Definition prediction_scheme_normal_octahedron_canonicalized_transform_base.h:50
bool IsInBottomLeft(const Point2 &p) const
Definition prediction_scheme_normal_octahedron_canonicalized_transform_base.h:92
void InvertDiamond(DataTypeT *s, DataTypeT *t) const
Definition prediction_scheme_normal_octahedron_transform_base.h:73
DataTypeT max_quantized_value() const
Definition prediction_scheme_normal_octahedron_transform_base.h:51
DataTypeT center_value() const
Definition prediction_scheme_normal_octahedron_transform_base.h:54
bool set_max_quantized_value(DataTypeT max_quantized_value)
Definition prediction_scheme_normal_octahedron_transform_base.h:62
int32_t ModMax(int32_t x) const
Definition prediction_scheme_normal_octahedron_transform_base.h:77
int32_t quantization_bits() const
Definition prediction_scheme_normal_octahedron_transform_base.h:57
bool IsInDiamond(DataTypeT s, DataTypeT t) const
Definition prediction_scheme_normal_octahedron_transform_base.h:70
Definition vector_d.h:30
#define DRACO_DCHECK_LE(a, b)
Definition macros.h:85
Definition attribute_octahedron_transform.cc:21
DataTypeT AddAsUnsigned(DataTypeT a, DataTypeT b)
Definition math_utils.h:63