Initial commit

This commit is contained in:
Ronak Gothi
2026-01-19 17:13:24 +05:30
commit e7a8646c25
8 changed files with 621 additions and 0 deletions
+2
View File
@@ -0,0 +1,2 @@
.idea
g5_imageconvert
+3
View File
@@ -0,0 +1,3 @@
[submodule "g5_imageconvert"]
path = g5_imageconvert
url = git@github.com:bitbank2/g5_imageconvert.git
+19
View File
@@ -0,0 +1,19 @@
#!/usr/bin/env bash
set -e
emcc g5_wasm.c \
-O3 \
-s WASM=1 \
-s MODULARIZE=1 \
-s ENVIRONMENT=web \
-s EXPORT_NAME=G5Wasm \
-s EXPORTED_FUNCTIONS="['_g5_encode_rgba_wasm','_malloc','_free']" \
-s EXPORTED_RUNTIME_METHODS="['cwrap', 'getValue', 'setValue', 'HEAPU8', 'HEAPU32']" \
-s ALLOW_MEMORY_GROWTH=1 \
-s INITIAL_MEMORY=16777216 \
-s MAXIMUM_MEMORY=268435456 \
-s TOTAL_STACK=8388608 \
-s FORCE_FILESYSTEM=1 \
-s ASSERTIONS=1 \
-s NO_EXIT_RUNTIME=1 \
-o web/g5_wasm.js
+16
View File
@@ -0,0 +1,16 @@
#include <stdint.h>
#include <emscripten/emscripten.h>
#include <stdio.h>
#include <string.h>
#include "g5_imageconvert/weblib/weblib.c"
EMSCRIPTEN_KEEPALIVE
int g5_encode_rgba_wasm(
const uint8_t *rgba,
int width,
int height,
uint8_t *out,
int outSize
) {
return g5_encode_rgba( rgba, width, height, out, outSize);
}
+68
View File
@@ -0,0 +1,68 @@
const wasm = await G5Wasm();
if (!wasm.HEAPU8) {
throw new Error("WASM not initialized correctly");
}
const encode = wasm.cwrap('g5_encode_rgba_wasm', 'number', ['number','number','number','number','number']);
window.encodePNG = async function (file) {
const img = await createImageBitmap(file);
const canvas = new OffscreenCanvas(img.width, img.height);
const ctx = canvas.getContext('2d');
ctx.drawImage(img, 0, 0);
const imageData = ctx.getImageData(0, 0, img.width, img.height);
const data = new Uint8Array(imageData.data.buffer);
const inPtr = wasm._malloc(data.length);
if (!inPtr) {
throw new Error(`Failed to allocate ${data.length} bytes for input`);
}
wasm.HEAPU8.set(data, inPtr);
const firstByte = wasm.HEAPU8[inPtr];
const outMax = Math.max(1024 * 1024, img.width * img.height); // Conservative estimate
const outPtr = wasm._malloc(outMax);
const size = encode(inPtr, img.width, img.height, outPtr, outMax);
const result = wasm.HEAPU8.slice(outPtr, outPtr + size);
wasm._free(inPtr);
wasm._free(outPtr);
return result;
};
function downloadBinaryFile(data, filename) {
const blob = new Blob([data], { type: 'application/octet-stream' });
const url = URL.createObjectURL(blob);
const a = document.createElement('a');
a.href = url;
a.download = filename;
document.body.appendChild(a);
a.click();
// Cleanup
setTimeout(() => {
document.body.removeChild(a);
URL.revokeObjectURL(url);
}, 100);
}
export async function combineLogoAndLoader() {
const logo = document.getElementById('logo-input');
const loader = document.getElementById('loader-input');
const logoBinary = await encodePNG(logo.files[0]);
downloadBinaryFile(logoBinary, 'logo.g')
const loaderBinary = await encodePNG(loader.files[0]);
downloadBinaryFile(loaderBinary, 'loader.g')
const totalLength = logoBinary.length + loaderBinary.length;
const combined = new Uint8Array(totalLength);
combined.set(logoBinary, 0);
combined.set(loaderBinary, logoBinary.length);
downloadBinaryFile(combined, 'browser.bin')
return new Blob([combined], { type: 'application/octet-stream' });
}
+2
View File
File diff suppressed because one or more lines are too long
BIN
View File
Binary file not shown.
+511
View File
File diff suppressed because it is too large Load Diff