How to resolve the algorithm Bitmap/PPM conversion through a pipe step by step in the Wren programming language
Published on 12 May 2024 09:40 PM
How to resolve the algorithm Bitmap/PPM conversion through a pipe step by step in the Wren programming language
Table of Contents
Problem Statement
Using the data storage type defined on this page for raster images, delegate writing a JPEG file through a pipe using the output_ppm function defined on this other page. There are various utilities that can be used for this task, for example: cjpeg (package "jpeg-progs" on Linux, or "media-libs/libjpeg-turbo" on Gentoo), ppmtojpeg (package "netpbm" on Linux), convert (from ImageMagick, multi-platform).
Let's start with the solution:
Step by Step solution about How to resolve the algorithm Bitmap/PPM conversion through a pipe step by step in the Wren programming language
Source code in the wren programming language
/* gcc -O3 -std=c11 -shared -o pipeconv.so -fPIC -I./include pipeconv.c */
#include <stdlib.h>
#include <string.h>
#include "dome.h"
static DOME_API_v0* core;
static WREN_API_v0* wren;
static const char* source = ""
"class PipeConv {\n"
"foreign static convert(from, to) \n"
"} \n";
void C_convert(WrenVM* vm) {
const char *from = wren->getSlotString(vm, 1);
const char *to = wren->getSlotString(vm, 2);
char command[strlen(from) + strlen(to) + 10];
strcpy(command, "convert ");
strcat(command, from);
strcat(command, " ");
strcat(command, to);
int res = system(command);
}
DOME_EXPORT DOME_Result PLUGIN_onInit(DOME_getAPIFunction DOME_getAPI, DOME_Context ctx) {
core = DOME_getAPI(API_DOME, DOME_API_VERSION);
wren = DOME_getAPI(API_WREN, WREN_API_VERSION);
core->registerModule(ctx, "pipeconv", source);
core->registerClass(ctx, "pipeconv", "PipeConv", NULL, NULL);
core->registerFn(ctx, "pipeconv", "static PipeConv.convert(_,_)", C_convert);
return DOME_RESULT_SUCCESS;
}
DOME_EXPORT DOME_Result PLUGIN_preUpdate(DOME_Context ctx) {
return DOME_RESULT_SUCCESS;
}
DOME_EXPORT DOME_Result PLUGIN_postUpdate(DOME_Context ctx) {
return DOME_RESULT_SUCCESS;
}
DOME_EXPORT DOME_Result PLUGIN_preDraw(DOME_Context ctx) {
return DOME_RESULT_SUCCESS;
}
DOME_EXPORT DOME_Result PLUGIN_postDraw(DOME_Context ctx) {
return DOME_RESULT_SUCCESS;
}
DOME_EXPORT DOME_Result PLUGIN_onShutdown(DOME_Context ctx) {
return DOME_RESULT_SUCCESS;
}
import "graphics" for Canvas, ImageData
import "dome" for Window
import "plugin" for Plugin
Plugin.load("pipeconv")
import "pipeconv" for PipeConv
class ConvertPPM {
construct new(fileName, fileName2, width, height) {
Window.resize(width, height)
Canvas.resize(width, height)
Window.title = "Convert PPM file via pipe"
// convert .ppm file to .jpg via a pipe
PipeConv.convert(fileName, fileName2)
// load and display .jpg file
var image = ImageData.loadFromFile(fileName2)
image.draw(0, 0)
}
init() {}
update() {}
draw(alpha) {}
}
var Game = ConvertPPM.new("output.ppm", "output_piped.jpg", 350, 350)
You may also check:How to resolve the algorithm Metronome step by step in the Java programming language
You may also check:How to resolve the algorithm Sort using a custom comparator step by step in the jq programming language
You may also check:How to resolve the algorithm Sort disjoint sublist step by step in the Icon and Unicon programming language
You may also check:How to resolve the algorithm Set step by step in the BASIC programming language
You may also check:How to resolve the algorithm Modular arithmetic step by step in the C programming language