summaryrefslogtreecommitdiffstats
path: root/virtual-programs
diff options
context:
space:
mode:
authorOmar Rizwan <omar@omar.website>2023-09-11 21:41:43 +0000
committerOmar Rizwan <omar@omar.website>2023-09-11 21:41:43 +0000
commitb9e5187c1bbf267f0ec4fc899ce926cb2167247f (patch)
tree58e487b6239ed9b6ffe06b1fa4adbcddb0c3b6bb /virtual-programs
parentWIP: Images starting to work! Need to fix RGBA and coords (diff)
downloadfolk-b9e5187c1bbf267f0ec4fc899ce926cb2167247f.tar.gz
folk-b9e5187c1bbf267f0ec4fc899ce926cb2167247f.zip
WIP: Images starting to work
Diffstat (limited to 'virtual-programs')
-rw-r--r--virtual-programs/images.folk21
1 files changed, 21 insertions, 0 deletions
diff --git a/virtual-programs/images.folk b/virtual-programs/images.folk
index e9807b85..8af24aee 100644
--- a/virtual-programs/images.folk
+++ b/virtual-programs/images.folk
@@ -160,6 +160,27 @@ namespace eval ::image {
// TODO: Free the JPEG.
// ckfree(im.data);
}
+ $cc proc rechannel {image_t im int components} image_t {
+ if (im.components == components) return im;
+ if (components != 4 || im.components != 3) exit(2);
+
+ image_t ret = im;
+ ret.components = components;
+ ret.bytesPerRow = ret.width * ret.components;
+ ret.data = folkHeapAlloc(ret.bytesPerRow * ret.height);
+
+ for(int i = 0; i < ret.width*ret.height; i++) {
+ int r = im.data[i*im.components+0],
+ g = im.data[i*im.components+1],
+ b = im.data[i*im.components+2];
+
+ ret.data[i*ret.components+0] = r;
+ ret.data[i*ret.components+1] = g;
+ ret.data[i*ret.components+2] = b;
+ ret.data[i*ret.components+3] = 255;
+ }
+ return ret;
+ }
$cc compile
variable imagesCache [dict create]