Member-only story
Porting Third Party to WebAssembly
The idea of this article is to take a more complex application (as it could exist in a C++ library) and port it to WebAssembly. In this process, the application is first compiled into native machine code and executed directly on the operating system. Then, in a second step, the same application is compiled into WebAssembly and used in a web application.
Bitmap Application
The application uses the bitmap_image.hpp
by Arash Partow, which is used to work with bitmaps in C++.
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <string>
#include "bitmap_image.hpp"
void cartesian()
{
...
}
void fractal()
{
...
}
extern "C"
void build_bitmap(int choosen)
{
switch(choosen) {
case 1:
cartesian();
break;
case 2:
fractal();
break;
default:
break;
}
}
int main(int argc, char **argv)
{
int choosen = 0;
if(argc > 1)
{
choosen = std::atoi(argv[1]);
}
build_bitmap(choosen);
return 0;
}
The application consists of two functions, cartesian
and fractal
, which generate different bitmaps. You can choose the respective function using the 1
or 2
as a parameter in the main
function.
Before you can proceed, the program needs to be compiled. To do that, the following Makefile is used:
COMPILER = -c++
OPTIONS = -ansi -pedantic-errors -Wall -Wall -Werror -Wextra -o
LINKER_OPT =…