I need to draw an image to the screen for an RPG I'm working on. The issue is, I have no clue how to do this efficiently. The image I am currently trying to draw to the screen is a PPM image file I simply transferred over to my 3DS using PetitModem.
I wrote some code that can do it, but there's two issues with it. (1) It requires time for the image to load, and (2) it doesn't draw it instantly. Both of these are not too big of deal on the n3DS, but on the old 3DS it draws really slowly and the loading time is pretty long. (12 seconds for one 400x240 image! As opposed to 3.5 seconds on the n3DS.)
This is currently how it runs on the n3DS:
It runs fast enough on the n3DS for the purpose I need it for, but nowhere near fast enough on the old 3DS. There's a 12 second loading time then the image draws onto the screen significantly slower.
This is the code I'm currently using:
It works by first I have the "@LOADPPM" subroutine that loads the PPM file into an RGB array. PPM is an image format like JPEG and PNG but a lot simpler. It reads the file byte-by-byte and builds up an array containing simply the RGB data, which "@DRAWIMAGE" can then draw to the screen.
As you can see, my code works, but is inefficient and I'm wondering if anyone has done something similar to this but came up with a much more efficient method.
Spoiler
GCLS CLS 'LOAD IMAGE PRINT "Loading..." DIM OUTDATA[400*240] FNAME$="DAT:PIC1" GOSUB @LOADPPM 'DRAW IMAGE CLS GOSUB @DRAWIMAGE 'WAIT FOR USER TO PRESS A WHILE BUTTON()!=#A:WEND GCLS END 'IN: FNAME$ 'OUT: OUTDATA[] @LOADPPM 'SIZE OF ANY GIVEN PPM OF 400x240 IN BYTES SIZE=288015 'LOAD IMAGE INTO INTEGER ARRAY 'EACH INTEGER CONTAINS 4 BYTES DIM INDATA[SIZE/4] LOAD FNAME$,INDATA,FALSE 'TEMPORARY STORAGE FOR INDIVIDUAL BYTES DIM TMPDATA[288015] 'BREAK THE INTEGER ARRAY UP INTO ITS RESPECTIVE BYTES FOR I=0 TO (SIZE/4)-1 'MOD IS NOT USED HERE ON PURPOSE! X0=INDATA[I] X1=X0 X1=((X1/256)-FLOOR(X1/256))*256 X2=((X0-X1)/POW(2,8)) X2=((X2/256)-FLOOR(X2/256))*256 X3=((X0-X1-X2*POW(2,8))/POW(2,16)) X3=((X3/256)-FLOOR(X3/256))*256 X4=((X0-X1-X2*POW(2,8)-X3*POW(2,16))/POW(2,24)) X4=((X4/256)-FLOOR(X4/256))*256 TMPDATA[I*4]=X1 TMPDATA[I*4+1]=X2 TMPDATA[I*4+2]=X3 TMPDATA[I*4+3]=X4 NEXT 'CALCULATE WHEN DATA SECTION STARTS NLC=0 START=0 WHILE NLC<3 IF TMPDATA[START]==10 THEN NLC=NLC+1 START=START+1 WEND 'COPY ALL RGB DATA FROM DATA SECTION INTO OUTDATA ARRAY FOR I=0 TO LEN(OUTDATA)-1 R=TMPDATA[START+I*3] G=TMPDATA[START+I*3+1] B=TMPDATA[START+I*3+2] OUTDATA[I]=RGB(R,G,B) NEXT RETURN 'IN: OUTDATA[SIZE] 'OUT: DRAWS IMAGE @DRAWIMAGE X=0 Y=0 FOR I=0 TO LEN(OUTDATA)-1 GCOLOR OUTDATA[I] GPSET X,Y X=X+1 IF X>=400 THEN X=0 Y=Y+1 ENDIF NEXT RETURN