' ' Load a JPG/PNG picture into the XTerm canvas using STB. (c) PvE - MIT license ' PRAGMA INCLUDE stb-master/stb_image.h PRAGMA OPTIONS -DSTB_IMAGE_IMPLEMENTATION -DSTBI_FAILURE_USERMSG INCLUDE canvas-xterm DECLARE w, h, channels TYPE unsigned int DECLARE r, g, b, a TYPE unsigned char DECLARE data TYPE unsigned char* IF AMOUNT(ARGUMENT$) < 2 THEN EPRINT "Usage: picture [type 0=mono 1=color (default)]" END 1 ENDIF CHANGEDIR DIRNAME$(ME$) file$ = REALPATH$(TOKEN$(ARGUMENT$, 2)) IF NOT(FILEEXISTS(file$)) THEN EPRINT "File '" & file$ & "' not found!" END 1 ENDIF ' By default use 4 components (RGBA) comp = 4 ' Verify argument IF AMOUNT(ARGUMENT$) = 3 THEN IF VAL(TOKEN$(ARGUMENT$, 3)) = 0 THEN comp = 1 ENDIF ENDIF ' Load the picture data = stbi_load(file$, &w, &h, &channels, comp) IF data = NULL THEN PRINT stbi_failure_reason() FORMAT "ERROR: %s.\n" END 1 ENDIF ' Setup the XTerm canvas WINDOW(BASENAME$(file$), w, h) ' Render loop FOR y = 0 TO h-1 FOR x = 0 TO w-1 r = data[(x+y*w)*comp+0] g = data[(x+y*w)*comp+1] b = data[(x+y*w)*comp+2] a = data[(x+y*w)*comp+3] INK(r, g, b, a) PIXEL(x+1, y+1) NEXT NEXT SYNC INK(255,255,255,255) TEXT(STR$(TIMER), 10, 50) WAITKEY