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

Color to Black and White Converter

Root / Submissions / [.]

DFrostCreated:
This program will convert color images to black and white in seconds!I will update it soon
DEF CONVERT X,Y,X2,Y2
FOR I=X TO X2
FOR I2=Y TO Y2
A=GSPOIT(I,I2)
RGBREAD A OUT R,G,B
B=(R+G+B)/3
GPSET I,I2,RGB(B,B,B)
NEXT
NEXT
END

This only supplements color with the blue color channel. Could it be better to—say—take the average of R,G,B and use that value instead?
DEF GRAYSCREEN X0,Y1,X1,Y1
VAR X,Y,R,G,B
FOR Y = Y0 TO Y1
 FOR X = X0 TO X1
  RGBREAD GSPOIT(X,Y) OUT R,G,B
  GPSET X,Y,GRAY((R+G+B)/3)
 NEXT
NEXT
END
DEF GRAY(V%)
 RETURN RGB(V%,V%,V%)
END

Replying to:MZ952
This only supplements color with the blue color channel. Could it be better to—say—take the average of R,G,B and use that value instead?
DEF GRAYSCREEN X0,Y1,X1,Y1
VAR X,Y,R,G,B
FOR Y = Y0 TO Y1
 FOR X = X0 TO X1
  RGBREAD GSPOIT(X,Y) OUT R,G,B
  GPSET X,Y,GRAY((R+G+B)/3)
 NEXT
NEXT
END
DEF GRAY(V%)
 RETURN RGB(V%,V%,V%)
END
I thought this as well, but Randomous pointed out that B is in fact reassigned to the average of the three channels before writing. Choosing a different name would have been better though, and it still doesn't take into account the alpha bit.

Replying to:MZ952
This only supplements color with the blue color channel. Could it be better to—say—take the average of R,G,B and use that value instead?
DEF GRAYSCREEN X0,Y1,X1,Y1
VAR X,Y,R,G,B
FOR Y = Y0 TO Y1
 FOR X = X0 TO X1
  RGBREAD GSPOIT(X,Y) OUT R,G,B
  GPSET X,Y,GRAY((R+G+B)/3)
 NEXT
NEXT
END
DEF GRAY(V%)
 RETURN RGB(V%,V%,V%)
END
Oh, you're right, I didn't follow the code through correctly. The alpha channel doesn't do anything for the graphics screen unless it's value is 255 (or zero?).

Replying to:MZ952
This only supplements color with the blue color channel. Could it be better to—say—take the average of R,G,B and use that value instead?
DEF GRAYSCREEN X0,Y1,X1,Y1
VAR X,Y,R,G,B
FOR Y = Y0 TO Y1
 FOR X = X0 TO X1
  RGBREAD GSPOIT(X,Y) OUT R,G,B
  GPSET X,Y,GRAY((R+G+B)/3)
 NEXT
NEXT
END
DEF GRAY(V%)
 RETURN RGB(V%,V%,V%)
END
If (for some reason) there is color data stored in the color channels and a value of 0-254 in the alpha channel, this function will set a nonblack pixel for a "transparent" pixel in the source. As suggested to me by 12Me21 in chat, this makes it an inaccurate transform even on the default resources:

I made a really fast version (takes about 1/3 second for the entire screen), but it requires the sound DLC because it uses ARYOP:
DEF GRAY X,Y,W,H
 DIM COL%[W*H],RED%[W*H],GRB%[W*H]
 
 'SAVE DATA
 GSAVE X,Y,W,H,COL%,TRUE 'save 16 bit colors
 
 'EXTRACT RED
 ARYOP #AOPDIV,RED%,COL%,&H800
 ARYOP #AOPMAD,COL%,RED%,-&H800,COL%
 
 'EXTRACT GREEN
 ARYOP #AOPDIV,GRB%,COL%,&H40
 ARYOP #AOPMAD,COL%,GRB%,-&H40,COL%
 ARYOP #AOPADD,RED%,RED%,GRB%
 
 'EXTRACT BLUE
 ARYOP #AOPDIV,GRB%,COL%,&H2
 ARYOP #AOPMAD,COL%,GRB%,-&H2,COL%
 ARYOP #AOPADD,RED%,RED%,GRB%
 
 'GET AVERAGE
 ARYOP #AOPDIV,RED%,RED%,3
 
 'MAKE GRAY
 ARYOP #AOPMAD,COL%,RED%,&H2,COL%
 ARYOP #AOPMAD,COL%,RED%,&H40,COL%
 ARYOP #AOPMAD,COL%,RED%,&H800,COL%
 
 'LOAD DATA
 GLOAD X,Y,W,H,COL%,TRUE,TRUE
END

Replying to:12Me21
I made a really fast version (takes about 1/3 second for the entire screen), but it requires the sound DLC because it uses ARYOP:
DEF GRAY X,Y,W,H
 DIM COL%[W*H],RED%[W*H],GRB%[W*H]
 
 'SAVE DATA
 GSAVE X,Y,W,H,COL%,TRUE 'save 16 bit colors
 
 'EXTRACT RED
 ARYOP #AOPDIV,RED%,COL%,&H800
 ARYOP #AOPMAD,COL%,RED%,-&H800,COL%
 
 'EXTRACT GREEN
 ARYOP #AOPDIV,GRB%,COL%,&H40
 ARYOP #AOPMAD,COL%,GRB%,-&H40,COL%
 ARYOP #AOPADD,RED%,RED%,GRB%
 
 'EXTRACT BLUE
 ARYOP #AOPDIV,GRB%,COL%,&H2
 ARYOP #AOPMAD,COL%,GRB%,-&H2,COL%
 ARYOP #AOPADD,RED%,RED%,GRB%
 
 'GET AVERAGE
 ARYOP #AOPDIV,RED%,RED%,3
 
 'MAKE GRAY
 ARYOP #AOPMAD,COL%,RED%,&H2,COL%
 ARYOP #AOPMAD,COL%,RED%,&H40,COL%
 ARYOP #AOPMAD,COL%,RED%,&H800,COL%
 
 'LOAD DATA
 GLOAD X,Y,W,H,COL%,TRUE,TRUE
END
Huh. I knew about the RINGCOPY thing, but it didn't quite register with me that the sound processing instructions could be used for anything other than sound processing.

Here is a slightly faster version(by my predictions)
DEF CONVERT X,Y,X2,Y2
'get width and height of area to convert----
VAR W=X2-X
VAR H=Y2-Y
'-------------------------------------------
VAR AREA=W*H'calculates area
WHILE COUNT<AREA
VAR X3=(AREA MOD W)+X'gets the single axis value into an x value
VAR Y3=(FLOOR(AREA/WIDTH))+Y'gets the single axis value into a y value
VAR COL=GSPOIT(X3, Y3)
VAR R, G, B
RGBREAD COL OUT R, G, B'convert a single
'value integer into three values
VAR GREY=(R+G+B)/3'or "gray" if you spell it
'that way
GPSET X3, Y3, RGB(GREY, GREY, GREY)'recolor
'that pixel in greyscale
WEND
END