? Color to Black and White Converter ● SmileBASIC Source

Sign In

Register
*Usernames are case-sensitive
Forgot my password

Color to Black and White Converter

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
Author
dfrost2
Updated
Rating
4 votes
Categories
Keywords
  • grayscale
7 Comment(s) dfrost2 dfrost2 Expert Programmer Programming no longer gives me any trouble. Come to me for help, if you like! Programming Strength Minecraft Is Awesome! I love Minecraft! Express Yourself 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 12Me21 12Me21 Admin Syntax Highlighter Received for creating the code syntax highlighter on SBS Night Person I like the quiet night and sleep late. Express Yourself Second Year My account is over 2 years old Website 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 MZ952 MZ952 Intermediate Programmer I can make programs, but I still have trouble here and there. Programming Strength Drawing I like to draw! Hobbies Reading I like to read books! Hobbies 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. MZ952 MZ952 Intermediate Programmer I can make programs, but I still have trouble here and there. Programming Strength Drawing I like to draw! Hobbies Reading I like to read books! Hobbies 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 Lumage Lumage Head Admin 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. MZ952 MZ952 Intermediate Programmer I can make programs, but I still have trouble here and there. Programming Strength Drawing I like to draw! Hobbies Reading I like to read books! Hobbies 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?). Lumage Lumage Head Admin 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: