2019-09-11 15:00:39 +00:00
|
|
|
/*
|
|
|
|
Open Asset Import Library (assimp)
|
|
|
|
----------------------------------------------------------------------
|
|
|
|
|
2024-02-23 21:30:05 +00:00
|
|
|
Copyright (c) 2006-2024, assimp team
|
2019-09-11 15:00:39 +00:00
|
|
|
|
|
|
|
All rights reserved.
|
|
|
|
|
|
|
|
Redistribution and use of this software in source and binary forms,
|
|
|
|
with or without modification, are permitted provided that the
|
|
|
|
following conditions are met:
|
|
|
|
|
|
|
|
* Redistributions of source code must retain the above
|
|
|
|
copyright notice, this list of conditions and the
|
|
|
|
following disclaimer.
|
|
|
|
|
|
|
|
* Redistributions in binary form must reproduce the above
|
|
|
|
copyright notice, this list of conditions and the
|
|
|
|
following disclaimer in the documentation and/or other
|
|
|
|
materials provided with the distribution.
|
|
|
|
|
|
|
|
* Neither the name of the assimp team, nor the names of its
|
|
|
|
contributors may be used to endorse or promote products
|
|
|
|
derived from this software without specific prior
|
|
|
|
written permission of the assimp team.
|
|
|
|
|
|
|
|
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
|
|
|
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
|
|
|
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
|
|
|
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
|
|
|
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
|
|
|
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
|
|
|
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
|
|
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
|
|
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
|
|
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
|
|
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
|
|
|
|
----------------------------------------------------------------------
|
|
|
|
*/
|
2020-09-02 14:28:12 +00:00
|
|
|
#ifndef ASSIMP_BUILD_NO_GLTF_IMPORTER
|
|
|
|
|
2020-05-02 13:14:38 +00:00
|
|
|
#include "AssetLib/glTF/glTFCommon.h"
|
2019-09-11 15:00:39 +00:00
|
|
|
|
|
|
|
namespace glTFCommon {
|
|
|
|
|
|
|
|
using namespace glTFCommon::Util;
|
|
|
|
|
|
|
|
namespace Util {
|
|
|
|
|
2020-03-15 09:17:54 +00:00
|
|
|
bool ParseDataURI(const char *const_uri, size_t uriLen, DataURI &out) {
|
2019-09-11 15:00:39 +00:00
|
|
|
if (nullptr == const_uri) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (const_uri[0] != 0x10) { // we already parsed this uri?
|
|
|
|
if (strncmp(const_uri, "data:", 5) != 0) // not a data uri?
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// set defaults
|
|
|
|
out.mediaType = "text/plain";
|
|
|
|
out.charset = "US-ASCII";
|
|
|
|
out.base64 = false;
|
|
|
|
|
2020-03-15 09:17:54 +00:00
|
|
|
char *uri = const_cast<char *>(const_uri);
|
2019-09-11 15:00:39 +00:00
|
|
|
if (uri[0] != 0x10) {
|
|
|
|
uri[0] = 0x10;
|
|
|
|
uri[1] = uri[2] = uri[3] = uri[4] = 0;
|
|
|
|
|
|
|
|
size_t i = 5, j;
|
|
|
|
if (uri[i] != ';' && uri[i] != ',') { // has media type?
|
|
|
|
uri[1] = char(i);
|
2020-04-28 18:31:59 +00:00
|
|
|
for (;i < uriLen && uri[i] != ';' && uri[i] != ','; ++i) {
|
2019-09-11 15:00:39 +00:00
|
|
|
// nothing to do!
|
|
|
|
}
|
|
|
|
}
|
2020-04-28 18:31:59 +00:00
|
|
|
while (i < uriLen && uri[i] == ';') {
|
2019-09-11 15:00:39 +00:00
|
|
|
uri[i++] = '\0';
|
2020-04-28 18:31:59 +00:00
|
|
|
for (j = i; i < uriLen && uri[i] != ';' && uri[i] != ','; ++i) {
|
2019-09-11 15:00:39 +00:00
|
|
|
// nothing to do!
|
|
|
|
}
|
|
|
|
|
|
|
|
if (strncmp(uri + j, "charset=", 8) == 0) {
|
|
|
|
uri[2] = char(j + 8);
|
2020-03-15 09:17:54 +00:00
|
|
|
} else if (strncmp(uri + j, "base64", 6) == 0) {
|
2019-09-11 15:00:39 +00:00
|
|
|
uri[3] = char(j);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (i < uriLen) {
|
|
|
|
uri[i++] = '\0';
|
|
|
|
uri[4] = char(i);
|
2020-03-15 09:17:54 +00:00
|
|
|
} else {
|
2019-09-11 15:00:39 +00:00
|
|
|
uri[1] = uri[2] = uri[3] = 0;
|
|
|
|
uri[4] = 5;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (uri[1] != 0) {
|
|
|
|
out.mediaType = uri + uri[1];
|
|
|
|
}
|
|
|
|
if (uri[2] != 0) {
|
|
|
|
out.charset = uri + uri[2];
|
|
|
|
}
|
|
|
|
if (uri[3] != 0) {
|
|
|
|
out.base64 = true;
|
|
|
|
}
|
|
|
|
out.data = uri + uri[4];
|
|
|
|
out.dataLength = (uri + uriLen) - out.data;
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2020-03-15 09:17:54 +00:00
|
|
|
} // namespace Util
|
|
|
|
} // namespace glTFCommon
|
2020-09-02 14:28:12 +00:00
|
|
|
|
|
|
|
#endif
|