GameApi 28
Library used by GameApi Builder tool
Loading...
Searching...
No Matches
prediction_scheme_normal_octahedron_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#ifdef DRACO_BACKWARDS_COMPATIBILITY_SUPPORTED
16#ifndef DRACO_COMPRESSION_ATTRIBUTES_PREDICTION_SCHEMES_PREDICTION_SCHEME_NORMAL_OCTAHEDRON_DECODING_TRANSFORM_H_
17#define DRACO_COMPRESSION_ATTRIBUTES_PREDICTION_SCHEMES_PREDICTION_SCHEME_NORMAL_OCTAHEDRON_DECODING_TRANSFORM_H_
18
19#include <cmath>
20
24#include "draco/core/macros.h"
25#include "draco/core/vector_d.h"
27
28namespace draco {
29
30// Class for converting correction values transformed by the octahedral normal
31// transform back to the original values. See the corresponding encoder for more
32// details.
33template <typename DataTypeT>
34class PredictionSchemeNormalOctahedronDecodingTransform
36 public:
37 typedef VectorD<DataTypeT, 2> Point2;
38 typedef DataTypeT CorrType;
39 typedef DataTypeT DataType;
40
41 PredictionSchemeNormalOctahedronDecodingTransform() {}
42
43 // Dummy function to fulfill concept.
44 void Init(int num_components) {}
45 bool DecodeTransformData(DecoderBuffer *buffer) {
46 DataTypeT max_quantized_value, center_value;
47 if (!buffer->Decode(&max_quantized_value)) {
48 return false;
49 }
50 if (buffer->bitstream_version() < DRACO_BITSTREAM_VERSION(2, 2)) {
51 if (!buffer->Decode(&center_value)) {
52 return false;
53 }
54 }
55 (void)center_value;
56 return this->set_max_quantized_value(max_quantized_value);
57 }
58
59 inline void ComputeOriginalValue(const DataType *pred_vals,
60 const CorrType *corr_vals,
61 DataType *out_orig_vals) const {
62 DRACO_DCHECK_LE(pred_vals[0], 2 * this->center_value());
63 DRACO_DCHECK_LE(pred_vals[1], 2 * this->center_value());
64 DRACO_DCHECK_LE(corr_vals[0], 2 * this->center_value());
65 DRACO_DCHECK_LE(corr_vals[1], 2 * this->center_value());
66
67 DRACO_DCHECK_LE(0, pred_vals[0]);
68 DRACO_DCHECK_LE(0, pred_vals[1]);
69 DRACO_DCHECK_LE(0, corr_vals[0]);
70 DRACO_DCHECK_LE(0, corr_vals[1]);
71
72 const Point2 pred = Point2(pred_vals[0], pred_vals[1]);
73 const Point2 corr = Point2(corr_vals[0], corr_vals[1]);
74 const Point2 orig = ComputeOriginalValue(pred, corr);
75
76 out_orig_vals[0] = orig[0];
77 out_orig_vals[1] = orig[1];
78 }
79
80 private:
81 Point2 ComputeOriginalValue(Point2 pred, const Point2 &corr) const {
82 const Point2 t(this->center_value(), this->center_value());
83 typedef typename std::make_unsigned<DataTypeT>::type UnsignedDataTypeT;
84 typedef VectorD<UnsignedDataTypeT, 2> Point2u;
85
86 // Perform the addition in unsigned type to avoid signed integer overflow.
87 // Note that the result will be the same (for non-overflowing values).
88 pred = Point2(Point2u(pred) - Point2u(t));
89
90 const bool pred_is_in_diamond = this->IsInDiamond(pred[0], pred[1]);
91 if (!pred_is_in_diamond) {
92 this->InvertDiamond(&pred[0], &pred[1]);
93 }
94
95 // Perform the addition in unsigned type to avoid signed integer overflow.
96 // Note that the result will be the same (for non-overflowing values).
97 Point2 orig(Point2u(pred) + Point2u(corr));
98
99 orig[0] = this->ModMax(orig[0]);
100 orig[1] = this->ModMax(orig[1]);
101 if (!pred_is_in_diamond) {
102 this->InvertDiamond(&orig[0], &orig[1]);
103 }
104
105 // Perform the addition in unsigned type to avoid signed integer overflow.
106 // Note that the result will be the same (for non-overflowing values).
107 orig = Point2(Point2u(orig) + Point2u(t));
108 return orig;
109 }
110};
111
112} // namespace draco
113
114#endif // DRACO_COMPRESSION_ATTRIBUTES_PREDICTION_SCHEMES_PREDICTION_SCHEME_NORMAL_OCTAHEDRON_DECODING_TRANSFORM_H_
115#endif
Definition prediction_scheme_normal_octahedron_transform_base.h:32
#define DRACO_BITSTREAM_VERSION(MAJOR, MINOR)
Definition macros.h:114
#define DRACO_DCHECK_LE(a, b)
Definition macros.h:85
Definition attribute_octahedron_transform.cc:21
DataType
Definition draco_types.h:26