LoginLogin
Nintendo shutting down 3DS + Wii U online services, see our post

How do I use GLOAD with palette data?

Root / Programming Questions / [.]

raimondzCreated:
GLOAD [X,Y,Width,Height,] Image array,Palette array,Copy mode 
I've seen in the documentation that GLOAD can be used to load an image using a palette array. However, I couldn't find a way to use that feature. Does anyone know how to use that?

OPTION STRICT
VAR AR%[16 * 16], PAL%[4], I%, J%

FOR J% = 0 TO 15
 FOR I% = 0 to 15
  AR%[(J%*16) + I%] = RND(4)
 NEXT I%
NEXT J%
PAL%[0] = RGB(0, 255, 0, 0) 'Red is transparent and won't be copied (ARGB)
PAL%[1] = RGB(0, 255, 0)
PAL%[2] = RGB(0, 0, 255)
PAL%[3] = RGB(255, 255, 0)

'PUT AT 50,50
'ARRAY IS 16x16
'ARRAY = AR%
'PALLETTE = PAL%
'FALSE - Don't copy transparent color, don't know if the flag actually works or not.
GLOAD 50, 50, 16, 16, AR%, PAL%, FALSE

END
I hope that helps. You could also pass in 8,32 for the size or something similar if you want.

Thanks, that really helped me a lot. It would be useful if there were a way to transform a 16bit image to a palette map on smilebasic's functions. I made this to transform a 16bit image to one that use a palette array. Let me know if you find a faster way to do that.
DEF toPal PIC%[] OUT PICR%[],PAL%[]
 VAR P%[0]
 PICR%=PIC%
 PAL%=P%[0]
 VAR I,J,C%
  
 FOR I=0 TO LEN(PIC%)-1
  C%=PIC%[I] OR &HFF000000
  
  J=ARRAY_indexOF(PAL%,C%)
  IF J==-1 THEN
   PUSH PAL%,C%
   PICR%[I]=LEN(PAL%)-1
  ELSE
   PICR%[I]=J
  ENDIF
 NEXT
 
END