| 63 | |
| 64 | template <typename T, size_t N> |
| 65 | void dequantizeAccessor(Model& model, Accessor& accessor) { |
| 66 | |
| 67 | BufferView* pBufferView = |
| 68 | Model::getSafe(&model.bufferViews, accessor.bufferView); |
| 69 | |
| 70 | if (!pBufferView) { |
| 71 | return; |
| 72 | } |
| 73 | |
| 74 | Buffer* pBuffer = Model::getSafe(&model.buffers, pBufferView->buffer); |
| 75 | if (!pBuffer) { |
| 76 | return; |
| 77 | } |
| 78 | |
| 79 | int64_t byteStride; |
| 80 | if (pBufferView->byteStride) { |
| 81 | byteStride = *pBufferView->byteStride; |
| 82 | } else { |
| 83 | byteStride = accessor.computeByteStride(model); |
| 84 | } |
| 85 | |
| 86 | if (static_cast<size_t>( |
| 87 | pBufferView->byteOffset + accessor.byteOffset + |
| 88 | accessor.count * byteStride) > pBuffer->cesium.data.size() || |
| 89 | static_cast<int64_t>(sizeof(T) * N) > byteStride) { |
| 90 | return; |
| 91 | } |
| 92 | |
| 93 | int64_t byteLength = accessor.count * static_cast<int64_t>(N * sizeof(float)); |
| 94 | if (byteLength < 0) { |
| 95 | return; |
| 96 | } |
| 97 | |
| 98 | std::vector<std::byte> data; |
| 99 | data.resize(static_cast<size_t>(byteLength)); |
| 100 | |
| 101 | const std::byte* bPtr = pBuffer->cesium.data.data() + |
| 102 | pBufferView->byteOffset + accessor.byteOffset; |
| 103 | |
| 104 | if (accessor.normalized) { |
| 105 | normalizeQuantized<T, N>( |
| 106 | reinterpret_cast<float*>(data.data()), |
| 107 | accessor.count, |
| 108 | bPtr, |
| 109 | byteStride); |
| 110 | for (double& d : accessor.min) { |
| 111 | d = intToFloat<T>(static_cast<T>(d)); |
| 112 | } |
| 113 | for (double& d : accessor.max) { |
| 114 | d = intToFloat<T>(static_cast<T>(d)); |
| 115 | } |
| 116 | } else { |
| 117 | castQuantizedToFloat<T, N>( |
| 118 | reinterpret_cast<float*>(data.data()), |
| 119 | accessor.count, |
| 120 | bPtr, |
| 121 | byteStride); |
| 122 | } |
no test coverage detected