Merge branch 'krishty-new-file-detection' of https://github.com/assimp/assimp into krishty-new-file-detection
This commit is contained in:
@@ -45,6 +45,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
// Header files, Assimp
|
||||
#include <assimp/DefaultLogger.hpp>
|
||||
#include <assimp/Base64.hpp>
|
||||
|
||||
#ifdef ASSIMP_IMPORTER_GLTF_USE_OPEN3DGC
|
||||
// Header files, Open3DGC.
|
||||
@@ -194,7 +195,7 @@ inline void Buffer::Read(Value &obj, Asset &r) {
|
||||
if (ParseDataURI(uri, it->GetStringLength(), dataURI)) {
|
||||
if (dataURI.base64) {
|
||||
uint8_t *data = 0;
|
||||
this->byteLength = Util::DecodeBase64(dataURI.data, dataURI.dataLength, data);
|
||||
this->byteLength = Base64::Decode(dataURI.data, dataURI.dataLength, data);
|
||||
this->mData.reset(data, std::default_delete<uint8_t[]>());
|
||||
|
||||
if (statedLength > 0 && this->byteLength != statedLength) {
|
||||
@@ -513,7 +514,7 @@ inline void Image::Read(Value &obj, Asset &r) {
|
||||
mimeType = dataURI.mediaType;
|
||||
if (dataURI.base64) {
|
||||
uint8_t *ptr = nullptr;
|
||||
mDataLength = glTFCommon::Util::DecodeBase64(dataURI.data, dataURI.dataLength, ptr);
|
||||
mDataLength = Base64::Decode(dataURI.data, dataURI.dataLength, ptr);
|
||||
mData.reset(ptr);
|
||||
}
|
||||
} else {
|
||||
|
||||
@@ -39,6 +39,8 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
----------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
#include <assimp/Base64.hpp>
|
||||
|
||||
#include <rapidjson/stringbuffer.h>
|
||||
#include <rapidjson/writer.h>
|
||||
#include <rapidjson/prettywriter.h>
|
||||
@@ -237,7 +239,7 @@ namespace glTF {
|
||||
else if (img.HasData()) {
|
||||
uri = "data:" + (img.mimeType.empty() ? "application/octet-stream" : img.mimeType);
|
||||
uri += ";base64,";
|
||||
glTFCommon::Util::EncodeBase64(img.GetData(), img.GetDataLength(), uri);
|
||||
Base64::Encode(img.GetData(), img.GetDataLength(), uri);
|
||||
}
|
||||
else {
|
||||
uri = img.uri;
|
||||
|
||||
@@ -48,84 +48,6 @@ using namespace glTFCommon::Util;
|
||||
|
||||
namespace Util {
|
||||
|
||||
size_t DecodeBase64(const char *in, size_t inLength, uint8_t *&out) {
|
||||
if (inLength % 4 != 0) {
|
||||
throw DeadlyImportError("Invalid base64 encoded data: \"", std::string(in, std::min(size_t(32), inLength)), "\", length:", inLength);
|
||||
}
|
||||
|
||||
if (inLength < 4) {
|
||||
out = nullptr;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int nEquals = int(in[inLength - 1] == '=') +
|
||||
int(in[inLength - 2] == '=');
|
||||
|
||||
size_t outLength = (inLength * 3) / 4 - nEquals;
|
||||
out = new uint8_t[outLength];
|
||||
memset(out, 0, outLength);
|
||||
|
||||
size_t i, j = 0;
|
||||
|
||||
for (i = 0; i + 4 < inLength; i += 4) {
|
||||
uint8_t b0 = DecodeCharBase64(in[i]);
|
||||
uint8_t b1 = DecodeCharBase64(in[i + 1]);
|
||||
uint8_t b2 = DecodeCharBase64(in[i + 2]);
|
||||
uint8_t b3 = DecodeCharBase64(in[i + 3]);
|
||||
|
||||
out[j++] = (uint8_t)((b0 << 2) | (b1 >> 4));
|
||||
out[j++] = (uint8_t)((b1 << 4) | (b2 >> 2));
|
||||
out[j++] = (uint8_t)((b2 << 6) | b3);
|
||||
}
|
||||
|
||||
{
|
||||
uint8_t b0 = DecodeCharBase64(in[i]);
|
||||
uint8_t b1 = DecodeCharBase64(in[i + 1]);
|
||||
uint8_t b2 = DecodeCharBase64(in[i + 2]);
|
||||
uint8_t b3 = DecodeCharBase64(in[i + 3]);
|
||||
|
||||
out[j++] = (uint8_t)((b0 << 2) | (b1 >> 4));
|
||||
if (b2 < 64) out[j++] = (uint8_t)((b1 << 4) | (b2 >> 2));
|
||||
if (b3 < 64) out[j++] = (uint8_t)((b2 << 6) | b3);
|
||||
}
|
||||
|
||||
return outLength;
|
||||
}
|
||||
|
||||
void EncodeBase64(const uint8_t *in, size_t inLength, std::string &out) {
|
||||
size_t outLength = ((inLength + 2) / 3) * 4;
|
||||
|
||||
size_t j = out.size();
|
||||
out.resize(j + outLength);
|
||||
|
||||
for (size_t i = 0; i < inLength; i += 3) {
|
||||
uint8_t b = (in[i] & 0xFC) >> 2;
|
||||
out[j++] = EncodeCharBase64(b);
|
||||
|
||||
b = (in[i] & 0x03) << 4;
|
||||
if (i + 1 < inLength) {
|
||||
b |= (in[i + 1] & 0xF0) >> 4;
|
||||
out[j++] = EncodeCharBase64(b);
|
||||
|
||||
b = (in[i + 1] & 0x0F) << 2;
|
||||
if (i + 2 < inLength) {
|
||||
b |= (in[i + 2] & 0xC0) >> 6;
|
||||
out[j++] = EncodeCharBase64(b);
|
||||
|
||||
b = in[i + 2] & 0x3F;
|
||||
out[j++] = EncodeCharBase64(b);
|
||||
} else {
|
||||
out[j++] = EncodeCharBase64(b);
|
||||
out[j++] = '=';
|
||||
}
|
||||
} else {
|
||||
out[j++] = EncodeCharBase64(b);
|
||||
out[j++] = '=';
|
||||
out[j++] = '=';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bool ParseDataURI(const char *const_uri, size_t uriLen, DataURI &out) {
|
||||
if (nullptr == const_uri) {
|
||||
return false;
|
||||
|
||||
@@ -232,37 +232,6 @@ struct DataURI {
|
||||
//! Check if a uri is a data URI
|
||||
bool ParseDataURI(const char *const_uri, size_t uriLen, DataURI &out);
|
||||
|
||||
template <bool B>
|
||||
struct DATA {
|
||||
static const uint8_t tableDecodeBase64[128];
|
||||
};
|
||||
|
||||
template <bool B>
|
||||
const uint8_t DATA<B>::tableDecodeBase64[128] = {
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 62, 0, 0, 0, 63,
|
||||
52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 0, 0, 0, 64, 0, 0,
|
||||
0, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14,
|
||||
15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 0, 0, 0, 0, 0,
|
||||
0, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40,
|
||||
41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 0, 0, 0, 0, 0
|
||||
};
|
||||
|
||||
inline char EncodeCharBase64(uint8_t b) {
|
||||
return "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/="[size_t(b)];
|
||||
}
|
||||
|
||||
inline uint8_t DecodeCharBase64(char c) {
|
||||
if (c & 0x80) {
|
||||
throw DeadlyImportError("Invalid base64 char value: ", size_t(c));
|
||||
}
|
||||
return DATA<true>::tableDecodeBase64[size_t(c & 0x7F)]; // TODO faster with lookup table or ifs?
|
||||
}
|
||||
|
||||
size_t DecodeBase64(const char *in, size_t inLength, uint8_t *&out);
|
||||
|
||||
void EncodeBase64(const uint8_t *in, size_t inLength, std::string &out);
|
||||
} // namespace Util
|
||||
|
||||
#define CHECK_EXT(EXT) \
|
||||
|
||||
@@ -44,6 +44,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
#include <assimp/MemoryIOWrapper.h>
|
||||
#include <assimp/StringUtils.h>
|
||||
#include <assimp/DefaultLogger.hpp>
|
||||
#include <assimp/Base64.hpp>
|
||||
|
||||
// clang-format off
|
||||
#ifdef ASSIMP_ENABLE_DRACO
|
||||
@@ -563,7 +564,7 @@ inline void Buffer::Read(Value &obj, Asset &r) {
|
||||
if (ParseDataURI(uri, it->GetStringLength(), dataURI)) {
|
||||
if (dataURI.base64) {
|
||||
uint8_t *data = nullptr;
|
||||
this->byteLength = glTFCommon::Util::DecodeBase64(dataURI.data, dataURI.dataLength, data);
|
||||
this->byteLength = Base64::Decode(dataURI.data, dataURI.dataLength, data);
|
||||
this->mData.reset(data, std::default_delete<uint8_t[]>());
|
||||
|
||||
if (statedLength > 0 && this->byteLength != statedLength) {
|
||||
@@ -1062,7 +1063,7 @@ inline void Image::Read(Value &obj, Asset &r) {
|
||||
mimeType = dataURI.mediaType;
|
||||
if (dataURI.base64) {
|
||||
uint8_t *ptr = nullptr;
|
||||
mDataLength = glTFCommon::Util::DecodeBase64(dataURI.data, dataURI.dataLength, ptr);
|
||||
mDataLength = Base64::Decode(dataURI.data, dataURI.dataLength, ptr);
|
||||
mData.reset(ptr);
|
||||
}
|
||||
} else {
|
||||
|
||||
@@ -39,6 +39,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
----------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
#include <assimp/Base64.hpp>
|
||||
#include <rapidjson/stringbuffer.h>
|
||||
#include <rapidjson/writer.h>
|
||||
#include <rapidjson/prettywriter.h>
|
||||
@@ -260,7 +261,7 @@ namespace glTF2 {
|
||||
if (img.HasData()) {
|
||||
uri = "data:" + (img.mimeType.empty() ? "application/octet-stream" : img.mimeType);
|
||||
uri += ";base64,";
|
||||
glTFCommon::Util::EncodeBase64(img.GetData(), img.GetDataLength(), uri);
|
||||
Base64::Encode(img.GetData(), img.GetDataLength(), uri);
|
||||
}
|
||||
else {
|
||||
uri = img.uri;
|
||||
|
||||
Reference in New Issue
Block a user