MCPcopy Create free account
hub / github.com/GPUOpen-Tools/compressonator / QuantizeToInt

Function QuantizeToInt

cmp_framework/common/hdr_encode.cpp:87–115  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

85}
86
87int QuantizeToInt(short value, int prec, bool signedfloat16, float exposure) {
88 (exposure);
89
90 if (prec <= 1) return 0;
91 bool negvalue = false;
92
93 if (signedfloat16) {
94 if (value < 0) {
95 negvalue = true;
96 value = -value;
97 }
98 prec--;
99 } else {
100 // clamp -ve
101 if (value < 0)
102 value = 0;
103 }
104
105 // move data to use extra bits for processing
106 int ivalue = value;
107
108 int iQuantized;
109 int bias = (prec > 10 && prec != 16) ? ((1 << (prec - 11)) - 1) : 0;
110 bias = (prec == 16) ? 15 : bias;
111
112 iQuantized = ((ivalue << prec) + bias) / (F16HMAX + 1);
113
114 return (negvalue ? -iQuantized : iQuantized);
115}
116
117int Unquantize(int comp, unsigned char uBitsPerComp, bool bSigned) {
118 int unq = 0, s = 0;

Callers 1

Calls

no outgoing calls

Tested by

no test coverage detected