-
I have a project which was using |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 1 reply
-
It looks like
Otherwise they looks the same and emscripten/src/library_legacy.js Lines 48 to 61 in bc2123f |
Beta Was this translation helpful? Give feedback.
-
Sorry for the delay, I hadn't time to replay; I will try to summarize the problem and how i solved: I developed a simple app Nft-Marker-Creator-App to create NFT (Natural Feature Tracking) markers to be used in projects like AR.js, jsartoolkit5, jsartoolkitNFT and ARnft to cite few of them. All about WebAR. The original code was by @Carnaux he did a great job, in the past he added the feature to compress the three single files(.fset, .iset and .fset3) into one only file called #include <emscripten.h>
#ifdef _WIN32
#include <Windows.h>
#else
#include <sys/stat.h>
#endif
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <AR/ar.h>
#include <zlib/zlib.h>
static const char *zipname = "/tempBinFile.bin";
extern "C"
{
uint compressZip(char *src, int srclen)
{
FILE *fp;
char *b = new char[srclen];
printf("Uncompressed size is: %lu", strlen(src));
printf("\n----------\n");
z_stream defstream;
defstream.zalloc = Z_NULL;
defstream.zfree = Z_NULL;
defstream.opaque = Z_NULL;
defstream.avail_in = (uInt)srclen;
defstream.next_in = (Bytef *)src;
defstream.avail_out = (uInt)srclen;
defstream.next_out = (Bytef *)b;
deflateInit(&defstream, Z_BEST_COMPRESSION);
deflate(&defstream, Z_FINISH);
deflateEnd(&defstream);
printf("Compressed size is: %lu\n", strlen(b));
fp = fopen(zipname, "wb");
fwrite(b, defstream.total_out, 1, fp);
fclose(fp);
delete[] b;
return 0;
} and used this flag
original code on github: This after upgrading to a newer emscripten version:
then with EMSCRIPTEN_BINDINGS: #include <emscripten/bind.h>
#include <emscripten/val.h>
#include <emscripten.h>
using namespace emscripten;
int createNftDataSet_em(emscripten::val imgData, float dpiIn, int xsizeIn,
int ysizeIn, int ncIn, std::string cmdStr) {
std::vector<uint8_t> idata =
emscripten::convertJSArrayToNumberVector<uint8_t>(imgData);
return createNftDataSet(idata.data(), dpiIn, xsizeIn, ysizeIn, ncIn,
&cmdStr[0]);
}
int compressZip_em(std::string srcStr, int srclen) {
return compressZip(&srcStr[0], srclen);
}
EMSCRIPTEN_BINDINGS(markerCreator_bindings) {
function("createNftDataSet", &createNftDataSet_em);
function("compressZip", &compressZip_em);
};
of course i added a |
Beta Was this translation helpful? Give feedback.
It looks like
writeStringToMemory
is almost the same asstringToUTF8
except for two things:writeStringToMemory
as a third argument calleddontAddNull
which means that string won't be null terminated.stringToUTF8
has a third argumentmaxBytesToWrite
which allows you the limit the number of bytes written to memory.Otherwise they looks the same and
writeStringToMemory
is implemented in terms ofstringToUTF8
:emscripten/src/library_legacy.js
Lines 48 to 61 in bc2123f