|
1 | | -# Image loading helpers for Prefix |
2 | | -# Backed by ext/image.py (stdlib-only, prefers Windows GDI+). |
3 | | -# |
4 | | -# API (operators provided by the model/extension): |
5 | | -# LOAD_PNG(STR: path):TNS[width,height,[r,g,b,a]] |
6 | | -# LOAD_JPEG(STR: path):TNS[width,height,[r,g,b,a]] |
7 | | -# LOAD_BMP(STR: path):TNS[width,height,[r,g,b,a]] |
8 | | -# LOAD(STR: path):TNS[height,width,[r,g,b,a]] # auto-detects format by extension |
9 | | -# SAVE_PNG(TNS: img, STR: path, INT: compression_level) |
10 | | -# SAVE_JPEG(TNS: img, STR: path, INT: compression_level) |
11 | | -# SAVE_BMP(TNS: img, STR: path) |
12 | | -# POLYGON(TNS:img, TNS:points[[x,y]...], TNS:color[r,g,b,a], INT:fill=1, INT:thickness=1):TNS |
13 | | -# RECT(TNS: img, INT: x, INT: y, INT: width, INT: height, TNS: color[r,g,b,a], INT: fill = 1, INT: thickness = 1):TNS # wraps POLYGON |
14 | | -# ELLIPSE(TNS: img, TNS: center, INT: rx, INT: ry, TNS: color[r,g,b,a], INT: fill = 1, INT: thickness = 1):TNS |
15 | | -# SQUARE(TNS: img, INT: x, INT: y, INT: size, TNS: color, INT: fill, INT: thickness):TNS |
16 | | -# CIRCLE(TNS: img, TNS: center, INT: radius, TNS: color, INT: fill, INT: thickness):TNS |
17 | | -# WIDTH(TNS: img):INT |
18 | | -# HEIGHT(TNS: img):INT |
19 | | -# CHANNELS(TNS: img):INT |
20 | | -# R(TNS: img):TNS |
21 | | -# G(TNS: img):TNS |
22 | | -# B(TNS: img):TNS |
23 | | -# A(TNS: img):TNS |
24 | | -# PIXEL(TNS: img, INT: x, INT: y):TNS |
25 | | -# PIXEL_R(TNS: img, INT: x, INT: y):INT |
26 | | -# PIXEL_G(TNS: img, INT: x, INT: y):INT |
27 | | -# PIXEL_B(TNS: img, INT: x, INT: y):INT |
28 | | -# PIXEL_A(TNS: img, INT: x, INT: y):INT |
29 | | -# THRESHHOLD_A(TNS:img, INT:a, TNS:color=[0,0,0,0]):TNS |
30 | | -# THRESHHOLD_R(TNS:img, INT:r, TNS:color=[0,0,0,0]):TNS |
31 | | -# THRESHHOLD_G(TNS:img, INT:g, TNS:color=[0,0,0,0]):TNS |
32 | | -# THRESHHOLD_B(TNS:img, INT:b, TNS:color=[0,0,0,0]):TNS |
33 | | -# FLIP_V(TNS: img):TNS |
34 | | -# FLIP_H(TNS: img):TNS |
35 | | -# INVERT(TNS: img):TNS |
36 | | -# SCALE(TNS: src, FLT: scale_x, FLT: scale_y, INT: antialiasing = 1):TNS |
37 | | -# RESIZE(TNS: img, INT: new_width, INT: new_height, INT: antialiasing = 1):TNS |
38 | | -# CROP(TNS:img, TNS:corners[[tl_x,tl_y],[tr_x,tr_y],[bl_x,bl_y],[br_x,br_y]]):TNS |
39 | | -# ROTATE(TNS: img, FLT: degrees):TNS |
40 | | -# BLIT(TNS: src, TNS: dest, INT: x, INT: y, INT: mixalpha = 1):TNS |
41 | | -# GRAYSCALE(TNS: img):TNS # three-channel grayscale (rgb=luminance, alpha preserved) |
42 | | -# REPLACE_COLOR(TNS: img, TNS: target_color, TNS: replacement_color):TNS |
43 | | -# BLUR(TNS: img, INT: radius):TNS # gaussian blur with integer radius |
44 | | -# EDGE(TNS: img):TNS # difference-of-gaussians edge detector |
45 | | -# CELLSHADE(TNS: img, TNS: colors):TNS # map pixels to nearest palette color |
46 | | -# SHOW(TNS: img):INT # saves to temp file and opens with default viewer (Windows only) |
47 | | -# |
48 | | -# The returned tensor layout is [column][row][channel] (width, height, channel) |
49 | | -# in user code. Channels are ordered r,g,b,a and values are 0..255. |
| 1 | +! Image loading helpers for Prefix |
| 2 | +! Backed by ext/image.py (stdlib-only, prefers Windows GDI+). |
| 3 | +! |
| 4 | +! API (operators provided by the model/extension): |
| 5 | +! LOAD_PNG(STR: path):TNS[width,height,[r,g,b,a]] |
| 6 | +! LOAD_JPEG(STR: path):TNS[width,height,[r,g,b,a]] |
| 7 | +! LOAD_BMP(STR: path):TNS[width,height,[r,g,b,a]] |
| 8 | +! LOAD(STR: path):TNS[height,width,[r,g,b,a]] ! auto-detects format by extension |
| 9 | +! SAVE_PNG(TNS: img, STR: path, INT: compression_level) |
| 10 | +! SAVE_JPEG(TNS: img, STR: path, INT: compression_level) |
| 11 | +! SAVE_BMP(TNS: img, STR: path) |
| 12 | +! POLYGON(TNS:img, TNS:points[[x,y]...], TNS:color[r,g,b,a], INT:fill=1, INT:thickness=1):TNS |
| 13 | +! RECT(TNS: img, INT: x, INT: y, INT: width, INT: height, TNS: color[r,g,b,a], INT: fill = 1, INT: thickness = 1):TNS ! wraps POLYGON |
| 14 | +! ELLIPSE(TNS: img, TNS: center, INT: rx, INT: ry, TNS: color[r,g,b,a], INT: fill = 1, INT: thickness = 1):TNS |
| 15 | +! SQUARE(TNS: img, INT: x, INT: y, INT: size, TNS: color, INT: fill, INT: thickness):TNS |
| 16 | +! CIRCLE(TNS: img, TNS: center, INT: radius, TNS: color, INT: fill, INT: thickness):TNS |
| 17 | +! WIDTH(TNS: img):INT |
| 18 | +! HEIGHT(TNS: img):INT |
| 19 | +! CHANNELS(TNS: img):INT |
| 20 | +! R(TNS: img):TNS |
| 21 | +! G(TNS: img):TNS |
| 22 | +! B(TNS: img):TNS |
| 23 | +! A(TNS: img):TNS |
| 24 | +! PIXEL(TNS: img, INT: x, INT: y):TNS |
| 25 | +! PIXEL_R(TNS: img, INT: x, INT: y):INT |
| 26 | +! PIXEL_G(TNS: img, INT: x, INT: y):INT |
| 27 | +! PIXEL_B(TNS: img, INT: x, INT: y):INT |
| 28 | +! PIXEL_A(TNS: img, INT: x, INT: y):INT |
| 29 | +! THRESHHOLD_A(TNS:img, INT:a, TNS:color=[0,0,0,0]):TNS |
| 30 | +! THRESHHOLD_R(TNS:img, INT:r, TNS:color=[0,0,0,0]):TNS |
| 31 | +! THRESHHOLD_G(TNS:img, INT:g, TNS:color=[0,0,0,0]):TNS |
| 32 | +! THRESHHOLD_B(TNS:img, INT:b, TNS:color=[0,0,0,0]):TNS |
| 33 | +! FLIP_V(TNS: img):TNS |
| 34 | +! FLIP_H(TNS: img):TNS |
| 35 | +! INVERT(TNS: img):TNS |
| 36 | +! SCALE(TNS: src, FLT: scale_x, FLT: scale_y, INT: antialiasing = 1):TNS |
| 37 | +! RESIZE(TNS: img, INT: new_width, INT: new_height, INT: antialiasing = 1):TNS |
| 38 | +! CROP(TNS:img, TNS:corners[[tl_x,tl_y],[tr_x,tr_y],[bl_x,bl_y],[br_x,br_y]]):TNS |
| 39 | +! ROTATE(TNS: img, FLT: degrees):TNS |
| 40 | +! BLIT(TNS: src, TNS: dest, INT: x, INT: y, INT: mixalpha = 1):TNS |
| 41 | +! GRAYSCALE(TNS: img):TNS ! three-channel grayscale (rgb=luminance, alpha preserved) |
| 42 | +! REPLACE_COLOR(TNS: img, TNS: target_color, TNS: replacement_color):TNS |
| 43 | +! BLUR(TNS: img, INT: radius):TNS ! gaussian blur with integer radius |
| 44 | +! EDGE(TNS: img):TNS ! difference-of-gaussians edge detector |
| 45 | +! CELLSHADE(TNS: img, TNS: colors):TNS ! map pixels to nearest palette color |
| 46 | +! SHOW(TNS: img):INT ! saves to temp file and opens with default viewer (Windows only) |
| 47 | +! |
| 48 | +! The returned tensor layout is [column][row][channel] (width, height, channel) |
| 49 | +! in user code. Channels are ordered r,g,b,a and values are 0..255. |
50 | 50 |
|
51 | 51 | IMPORT(path) |
52 | 52 |
|
@@ -151,12 +151,12 @@ FUNC CIRCLE(TNS: img, TNS: center, INT: radius, TNS: color, INT: fill, INT: thic |
151 | 151 | } |
152 | 152 |
|
153 | 153 | FUNC SHOW(TNS: img):INT{ |
154 | | - # Save the image to the provided path and open it with the system default |
155 | | - # viewer on Windows. `img_path` is treated as the target file path. |
| 154 | + ! Save the image to the provided path and open it with the system default |
| 155 | + ! viewer on Windows. `img_path` is treated as the target file path. |
156 | 156 | STR: img_path = "C:/Windows/Temp/tmp_img.png" |
157 | 157 | image.SAVE_PNG(img, img_path, 0) |
158 | | - # ShellExecuteW(hwnd, operation, file, params, dir, showcmd) |
159 | | - # Use NULL hwnd (0), operation "open", empty params and dir, showcmd=1 |
| 158 | + ! ShellExecuteW(hwnd, operation, file, params, dir, showcmd) |
| 159 | + ! Use NULL hwnd (0), operation "open", empty params and dir, showcmd=1 |
160 | 160 | win32.WIN_CALL("shell32", "ShellExecuteW", "PSSSSI", "P", 0, "open", img_path, "", "", 1) |
161 | 161 | DEL(img_path) |
162 | 162 | RETURN(0) |
|
0 commit comments