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

Manipulating colors and number types.

Root / Programming Questions / [.]

Alex_Created:
I'm trying to code a bilinear scaling algorithm but don't know how to extract the RGB data from a color so I can do the math on it. I load an image then use GSAVE to copy the part of it I want to scale onto an array while setting the flag to convert to 32 bit values, although I think in the array each number is saved as 64 bits. The image is grayscale and I want to pull one of the RGB values to do the algorithm on it and print it on screen using GPSET. How do number types work in an array and how do I get an RGB value from a number? Thanks, using sb3 (3DS).

Color codes on SB3 use the ARGB8888 format, so, each channel, ARGB, uses 8 bits. However, the graphics screens, the actual display elements, use uh ARGB1555 I believe, meaning each channel RGB uses 5 bits, and the alpha channel uses 1 (0=transparent, 1=opaque). When you draw a ARGB8888 color code to the graphics screen, it is converted to ARGB1555, and reading the color code data from the graphics screen yields the 16-bit ARGB1555 color code (it's lossy). You'd want to use an integer array to store your color code data, as each converted color code is 32-bit (in the ARGB8888 format). Keep in mind the RGB(A,R,G,B) function returns a 32-bit color code. Integers are suffixed by %, so, for example
DIM IMG%[WDTH*HGHT]
would produce an array, IMG%, filled with WDTH*HGHT number of 32-bit integer elements. FLT# (64-bit float), INT% (32-bit int), STR$ (16-bit char) I believe all unsuffixed variables are by default 64-bit floating point. I like to preface my programs with
OPTION STRICT
OPTION DEFINT
DEFINT forces all unsuffixed variables to be 32 bit integer type, (saves RAM if you say create an array meant to be integer however unsuffixed), and STRICT mandates that all variables be declared with either DIM or VAR. DEFINT removes the need to specify integer types, so, equivalent to the example before
DIM IMG[WDTH*HGHT]
stores WDTH*HGHT number of 32-bit integer elements.

You can use RGBREAD color OUT A,R,G,B and color=RGB(A,R,G,B) to convert between numbers and separate channels

@MZ952 Cool that's a pretty good explanation. So I had tried making an integer array with the percent symbol but the error came later in my code when I tried to use it. You actually have to call it like this for example in case anybody wants to know:
GSAVE 0,0,128,128,IMG%,0
@12Me21 Really, and here I was trying to do bit shifting. I'll try RGBREAD later when I have time.