Skip to content

Commit

Permalink
changes to add decompressZFT feature for the NFT's markers
Browse files Browse the repository at this point in the history
- for now partially only for the old API
  • Loading branch information
kalwalt committed Nov 19, 2024
1 parent c5486f0 commit 2ad1a71
Show file tree
Hide file tree
Showing 29 changed files with 6,118 additions and 2,703 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
build/*.bc
build/*.o
build/*.a
node_modules
docs/*
emscripten/build
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
[submodule "emscripten/WebARKitLib"]
path = emscripten/WebARKitLib
url = https://github.com/webarkit/WebARKitLib
[submodule "emscripten/zlib"]
path = emscripten/zlib
url = https://github.com/madler/zlib
8,352 changes: 5,705 additions & 2,647 deletions build/artoolkitNFT.debug.js

Large diffs are not rendered by default.

20 changes: 10 additions & 10 deletions build/artoolkitNFT.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion build/artoolkitNFT_ES6_wasm.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion build/artoolkitNFT_ES6_wasm.simd.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion build/artoolkitNFT_ES6_wasm_td.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion build/artoolkitNFT_embed_ES6_wasm.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion build/artoolkitNFT_thread.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion build/artoolkitNFT_wasm.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion build/artoolkitNFT_wasm.simd.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/ARToolkitNFT.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/ARToolkitNFT_simd.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/ARToolkitNFT_td.js

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions emscripten/ARBindEM.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ EMSCRIPTEN_BINDINGS(constant_bindings) {

function("_addNFTMarkers", &addNFTMarkers);

function("_decompressZFT", &decompressZFT);

function("_loadCamera", &loadCamera);

function("detectNFTMarker", &detectNFTMarker);
Expand Down
9 changes: 9 additions & 0 deletions emscripten/ARToolKitJS.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
#include <string>
#include <unordered_map>
#include <vector>
#include "markerDecompress.h"


const int PAGES_MAX =
20; // Maximum number of pages expected. You can change this down (to save
Expand Down Expand Up @@ -504,6 +506,13 @@ extern "C"
return lens;
}

int decompressZFT(std::string datasetPathname, std::string tempPathname){
int response = decompressMarkers(datasetPathname.c_str(), tempPathname.c_str());

return 1;
}


/*****************
* Marker loading *
*****************/
Expand Down
7 changes: 7 additions & 0 deletions emscripten/ARToolKitJS_td.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
#include <string>
#include <unordered_map>
#include <vector>
#include "markerDecompress.h"

const int PAGES_MAX =
20; // Maximum number of pages expected. You can change this down (to save
Expand Down Expand Up @@ -465,6 +466,12 @@ emscripten::val getCameraLens(int id) {
return lens;
}

int decompressZFT(std::string datasetPathname, std::string tempPathname){
int response = decompressMarkers(datasetPathname.c_str(), tempPathname.c_str());

return 1;
}

/*****************
* Marker loading *
*****************/
Expand Down
6 changes: 6 additions & 0 deletions emscripten/ARToolKitNFT_js.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -308,6 +308,12 @@ emscripten::val ARToolKitNFT::getCameraLens() {
return lens;
}

int ARToolKitNFT::decompressZFT(std::string datasetPathname, std::string tempPathname){
int response = decompressMarkers(datasetPathname.c_str(), tempPathname.c_str());

return 1;
}

/*****************
* Marker loading *
*****************/
Expand Down
2 changes: 2 additions & 0 deletions emscripten/ARToolKitNFT_js.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#include <KPM/kpm.h>
#include <WebARKit/WebARKitLog.h>
#include "trackingMod.h"
#include "markerDecompress.h"

const int PAGES_MAX = 20; // Maximum number of pages expected. You can change this down (to save memory) or up (to accomodate more pages.)

Expand Down Expand Up @@ -50,6 +51,7 @@ class ARToolKitNFT
int loadCamera(std::string cparam_name);
int setCamera(int id, int cameraID);
emscripten::val getCameraLens();
int decompressZFT(std::string datasetPathname, std::string tempPathname);
std::vector<int> addNFTMarkers(std::vector<std::string> &datasetPathnames);

// setters and getters
Expand Down
1 change: 1 addition & 0 deletions emscripten/ARToolKitNFT_js_bindings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ EMSCRIPTEN_BINDINGS(constant_bindings) {
.function("setup", &ARToolKitNFT::setup)
.function("getCameraLens", &ARToolKitNFT::getCameraLens)
.function("passVideoData", &ARToolKitNFT::passVideoData)
.function("_decompressZFT", &ARToolKitNFT::decompressZFT)
.function("_addNFTMarkers", &ARToolKitNFT::addNFTMarkers)

.function("setLogLevel", &ARToolKitNFT::setLogLevel)
Expand Down
6 changes: 6 additions & 0 deletions emscripten/ARToolKitNFT_js_td.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -323,6 +323,12 @@ emscripten::val ARToolKitNFT::getCameraLens() {
return lens;
}

int ARToolKitNFT::decompressZFT(std::string datasetPathname, std::string tempPathname){
int response = decompressMarkers(datasetPathname.c_str(), tempPathname.c_str());

return 1;
}

/*****************
* Marker loading *
*****************/
Expand Down
2 changes: 2 additions & 0 deletions emscripten/ARToolKitNFT_js_td.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#include <AR/paramGL.h>
#include <KPM/kpm.h>
#include <WebARKit/WebARKitLog.h>
#include "markerDecompress.h"

const int PAGES_MAX = 20; // Maximum number of pages expected. You can change this down (to save memory) or up (to accomodate more pages.)

Expand Down Expand Up @@ -50,6 +51,7 @@ class ARToolKitNFT
int loadCamera(std::string cparam_name);
int setCamera(int id, int cameraID);
emscripten::val getCameraLens();
int decompressZFT(std::string datasetPathname, std::string tempPathname);
std::vector<int> addNFTMarkers(std::vector<std::string> &datasetPathnames);

// setters and getters
Expand Down
185 changes: 185 additions & 0 deletions emscripten/markerDecompress.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,185 @@
#include "markerDecompress.h"
#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>

const int mem_size_4mb = 4*1024*1024;

int decompressMarkers(const char* src, const char* outTemp){
// markerContentStruct *markerData;
FILE *fp;
char* in;
char* out;
int filesize, ret;
const char *ext = "zft";
char *c = malloc (mem_size_4mb);

fp = openZFT(src, ext);
if ( fp == NULL )
{
ARLOGe("Error opening .zft file\n");
exit(EXIT_FAILURE);
}

fseek (fp, 0, SEEK_END);
filesize = ftell (fp);
fseek (fp, 0, SEEK_SET);

in = malloc (filesize);

if (in == NULL)
{
ARLOGe("Error mallocing %i bytes for inflate\n", filesize);
exit(EXIT_FAILURE);
}
ret = fread (in, 1, filesize, fp);
fclose (fp);
char *tempName = nameConcat(src, ext);
remove(tempName);
free(tempName);

z_stream infstream;
infstream.zalloc = Z_NULL;
infstream.zfree = Z_NULL;
infstream.opaque = Z_NULL;
infstream.avail_in = filesize;
infstream.next_in = (Bytef *) in;
infstream.avail_out = (uInt)mem_size_4mb;
infstream.next_out = (Bytef *) c;

inflateInit(&infstream);
inflate(&infstream, Z_NO_FLUSH);
inflateEnd(&infstream);

free(in);

extractDataAndSave(c, outTemp);

free(c);
return 0;
// return markerData;
}

void extractDataAndSave(const char* str, const char* name){
// string and variable name structure
//
// iset_final_index
// V
// str = {"iset":"test","fset":"test2","fset3":"test3"}
// ∧
// Beginning of str or iset_initial_index
//
//
// iset_final_index fset_initial_index
// V V
// str = {"iset":"test","fset":"test2","fset3":"test3"}
// ---- <- iset_content
//

// markerContentStruct *tempMarkerData;

FILE *tempIset;
FILE *tempFset;
FILE *tempFset3;

int iset_final_index = 9;

char *fsetInitialIndex = strstr(str, "\",\"fset\":\"");
int fset_initial_index = (fsetInitialIndex - str);

int fset_final_index = (fset_initial_index + 10);

int iset_content_size = fset_initial_index - iset_final_index;

char *fset3InitialIndex = strstr(str, "\",\"fset3\":\"");
int fset3_initial_index = (fset3InitialIndex - str);
int fset3_final_index = (fset3_initial_index + 11);

int fset_content_size = fset3_initial_index - fset_final_index;

char *endOfStr = strstr(str, "\"}");
int endPos = endOfStr - str;

int fset3_content_size = endPos - fset3_final_index;

// ---ISET---
char *iset_contentHex = malloc(iset_content_size);
strncpy(iset_contentHex, str + iset_final_index, iset_content_size);

// tempMarkerData->iset_content = iset_contentHex;
char *isetName = nameConcat(name, ".iset");
tempIset = fopen(isetName, "w");
fwrite(iset_contentHex, iset_content_size, 1, tempIset);
// printf(iset_contentHex);
fclose(tempIset);
free(isetName);
free(iset_contentHex);

// ---FSET---
char *fset_contentHex = malloc(fset_content_size);
strncpy(fset_contentHex, str + fset_final_index, fset_content_size);

// tempMarkerData->fset_content = fset_contentHex;
char *fsetName = nameConcat(name, ".fset");
tempFset = fopen(fsetName, "w");
fwrite(fset_contentHex, fset_content_size, 1, tempFset);
fclose(tempFset);
free(fsetName);
free(fset_contentHex);

// ---FSET3---
char *fset3_contentHex = malloc(fset3_content_size);
strncpy(fset3_contentHex, str + fset3_final_index, fset3_content_size);

// tempMarkerData->fset3_content = fset3_contentHex;
char *fset3Name = nameConcat(name, ".fset3");
tempFset3 = fopen(fset3Name, "w");
fwrite(fset3_contentHex, fset3_content_size, 1, tempFset3);
fclose(tempFset3);
free(fset3Name);
free(fset3_contentHex);

// return tempMarkerData;
}

FILE *openZFT( const char *filename, const char *ext)
{
FILE *fp;
char *buf;
size_t len;

if (!filename) return (NULL);
if (ext) {
len = strlen(filename) + strlen(ext) + 2; // space for '.' and '\0'.
arMalloc(buf, char, len);
sprintf(buf, "%s.%s", filename, ext);
fp = fopen(buf,"rb");
free(buf);
} else {
fp = fopen(filename,"rb");
}

return fp;
}

char* nameConcat(const char *s1, const char *s2)
{
const size_t len1 = strlen(s1);
const size_t len2 = strlen(s2);
char *result = malloc(len1 + len2 + 1); // +1 for the null-terminator
// in real code you would check for errors in malloc here
memcpy(result, s1, len1);
memcpy(result + len1, s2, len2 + 1); // +1 to copy the null-terminator
return result;
}
21 changes: 21 additions & 0 deletions emscripten/markerDecompress.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#include <stdio.h>

#ifdef __cplusplus
extern "C" {
#endif

typedef struct
{
char *iset_content;
char *fset_content;
char *fset3_content;
} markerContentStruct;

char* nameConcat(const char *s1, const char *s2);
FILE *openZFT( const char *filename, const char *ext);
int decompressMarkers(const char* src, const char* outTemp);
void extractDataAndSave(const char* str, const char* name);

#ifdef __cplusplus
}
#endif
1 change: 1 addition & 0 deletions emscripten/zlib
Submodule zlib added at ef24c4
Loading

0 comments on commit 2ad1a71

Please sign in to comment.