Grey Scale Bitmaps: Difference between revisions
Jump to navigation
Jump to search
SCREEN 12 (4 BPP - 16 colors)
SCREEN 13 (4 or 8 BPP - 256 colors)
SCREEN _NEWIMAGE(BMP.PWidth, BMP.PDepth, 32) (24 BPP - 16 million colors)
Tinting Grey Scale Images
Navigation:
Main Page with Articles and Tutorials
Keyword Reference - Alphabetical
Keyword Reference - By usage
Report a broken link
(Created page with "Grey scale is necessary for compatibility with QBasic's legacy SCREEN modes when viewing 24/32 bit bitmaps! You may also desire grey scale images for aesthetic or artistic reasons. * Set each color '''attribute''''s RGB '''intensities''' to the same value while incrementing the attribute values and intensity levels. * Don't exceed 63 when using OUT in legacy screen modes 12 or 13. Screens 7 and 9 use DAC color settings. * If using a ''...") |
No edit summary |
||
Line 1: | Line 1: | ||
Grey scale is necessary for compatibility with QBasic's legacy [[SCREEN (statement)|SCREEN]] modes when viewing 24/32 bit bitmaps! You may also desire grey scale images for aesthetic or artistic reasons. | Grey scale is necessary for compatibility with QBasic's legacy [[SCREEN (statement)|SCREEN]] modes when viewing 24/32 bit bitmaps! You may also desire grey scale images for aesthetic or artistic reasons. | ||
* Set each color '''attribute''''s RGB '''intensities''' to the same value while incrementing the attribute values and intensity levels. | * Set each color '''attribute''''s RGB '''intensities''' to the same value while incrementing the attribute values and intensity levels. | ||
* Don't exceed 63 when using [[OUT]] in legacy screen modes 12 or 13. Screens 7 and 9 use [[DAC]] color settings. | * Don't exceed 63 when using [[OUT]] in legacy screen modes 12 or 13. Screens 7 and 9 use [[DAC]] color settings. | ||
* If using a '''QB64''' 32 bit [[_NEWIMAGE]] Screen, use [[_RGB]] or [[RGB32]] values no higher than 255. | * If using a '''QB64''' 32 bit [[_NEWIMAGE]] Screen, use [[_RGB]] or [[RGB32]] values no higher than 255. | ||
* Then set the color '''attributes''' to reflect the number of colors available in that legacy screen mode. | * Then set the color '''attributes''' to reflect the number of colors available in that legacy screen mode. | ||
* 24/32 bit do not use color attributes, so the '''intensity levels''' must be set to an average for all three. | * 24/32 bit do not use color attributes, so the '''intensity levels''' must be set to an average for all three. | ||
Line 14: | Line 14: | ||
<center>'''SCREEN 12 (4 BPP - 16 colors)'''</center> | <center>'''SCREEN 12 (4 BPP - 16 colors)'''</center> | ||
{{CodeStart}} | {{CodeStart}} | ||
{{Cl|SUB}} TrueColor12 'Screen 12 greyscale of 24 bit 'code by Bob Seguin | {{Cl|SUB}} TrueColor12 'Screen 12 greyscale of 24 bit 'code by Bob Seguin | ||
{{Cl|IF}} BMP.PWidth * 3) {{Cl|MOD}} 4) {{Cl|THEN}} | {{Cl|IF}} BMP.PWidth * 3) {{Cl|MOD}} 4) {{Cl|THEN}} | ||
Line 46: | Line 45: | ||
y = y - 1 | y = y - 1 | ||
{{Cl|LOOP}} {{Cl|UNTIL}} y = -1 | {{Cl|LOOP}} {{Cl|UNTIL}} y = -1 | ||
{{Cl|END SUB}} | {{Cl|END SUB}} | ||
{{CodeEnd}} | {{CodeEnd}} | ||
Line 53: | Line 51: | ||
<center>'''SCREEN 13 (4 or 8 BPP - 256 colors)'''</center> | <center>'''SCREEN 13 (4 or 8 BPP - 256 colors)'''</center> | ||
{{CodeStart}} | {{CodeStart}} | ||
{{Cl|SUB}} TrueColor13 'Screen 13 greyscale of 24 bit 'code by Bob Seguin | {{Cl|SUB}} TrueColor13 'Screen 13 greyscale of 24 bit 'code by Bob Seguin | ||
{{Cl|IF}} ((BMP.PWidth * 3) {{Cl|MOD}} 4) <> 0 {{Cl|THEN}} | {{Cl|IF}} ((BMP.PWidth * 3) {{Cl|MOD}} 4) <> 0 {{Cl|THEN}} | ||
Line 86: | Line 83: | ||
y = y - 1 'move up one row from bottom | y = y - 1 'move up one row from bottom | ||
{{Cl|LOOP}} {{Cl|UNTIL}} y = -1 | {{Cl|LOOP}} {{Cl|UNTIL}} y = -1 | ||
{{Cl|END SUB}} | {{Cl|END SUB}} | ||
{{CodeEnd}} | {{CodeEnd}} | ||
Line 117: | Line 113: | ||
y = y - 1 'move up one row from bottom | y = y - 1 'move up one row from bottom | ||
{{Cl|LOOP}} {{Cl|UNTIL}} y = -1 | {{Cl|LOOP}} {{Cl|UNTIL}} y = -1 | ||
{{Cl|END SUB}} | {{Cl|END SUB}} | ||
{{CodeEnd}} | {{CodeEnd}} | ||
Line 126: | Line 121: | ||
: To tint a SCREEN 12 or 13 greyscale image, keep the '''palette''' intensity settings of 1 or 2 colors less than the others. | : To tint a SCREEN 12 or 13 greyscale image, keep the '''palette''' intensity settings of 1 or 2 colors less than the others. | ||
{{CodeStart}} | {{CodeStart}} | ||
{{Cl|FOR...NEXT|FOR}} Colr = 0 {{Cl|TO}} 255 {{Cl|STEP}} 4 '63 different intensities | {{Cl|FOR...NEXT|FOR}} Colr = 0 {{Cl|TO}} 255 {{Cl|STEP}} 4 '63 different intensities | ||
{{Cl|FOR...NEXT|FOR}} Reps = 0 {{Cl|TO}} 3 'set 3 colors at a time | {{Cl|FOR...NEXT|FOR}} Reps = 0 {{Cl|TO}} 3 'set 3 colors at a time | ||
Line 136: | Line 130: | ||
n = n + 1 'increment intensities. maximum = 63 | n = n + 1 'increment intensities. maximum = 63 | ||
{{Cl|IF}} n > 5 {{Cl|THEN}} tint = 5 'keep red and green intensity values above 0! | {{Cl|IF}} n > 5 {{Cl|THEN}} tint = 5 'keep red and green intensity values above 0! | ||
{{Cl|NEXT}} Colr | {{Cl|NEXT}} Colr | ||
{{CodeEnd}} | {{CodeEnd}} | ||
: In 24/32 bit SCREENs, subtract some intensity from one or two of the 3 '''image pixel''' settings. | : In 24/32 bit SCREENs, subtract some intensity from one or two of the 3 '''image pixel''' settings. | ||
{{CodeStart}} | {{CodeStart}} | ||
{{Cl|DO}} | {{Cl|DO}} | ||
{{Cl|GET}} #1, , B$ | {{Cl|GET}} #1, , B$ | ||
{{Cl|GET}} #1, , G$ | {{Cl|GET}} #1, , G$ | ||
{{Cl|GET}} #1, , R$ | {{Cl|GET}} #1, , R$ | ||
red = {{Cl|ASC}}(R$) | red = {{Cl|ASC}}(R$) | ||
grn = {{Cl|ASC}}(G$) | grn = {{Cl|ASC}}(G$) | ||
blu = {{Cl|ASC}}(B$) | blu = {{Cl|ASC}}(B$) | ||
average = (red + grn + blu) \ 3 'divide by 3 for average as colors match intensities | average = (red + grn + blu) \ 3 'divide by 3 for average as colors match intensities | ||
IF average > 5 THEN tint = 5 ELSE tint = 0 | IF average > 5 THEN tint = 5 ELSE tint = 0 | ||
{{Cl|PSET}} (x, y), {{Cl|_RGB32}}(average - tint, average - tint, average) 'maximum color intensity = 255 | {{Cl|PSET}} (x, y), {{Cl|_RGB32}}(average - tint, average - tint, average) 'maximum color intensity = 255 | ||
x = x + 1 | x = x + 1 | ||
{{Cl|LOOP}} {{Cl|WHILE}} x < BMP.PWidth | {{Cl|LOOP}} {{Cl|WHILE}} x < BMP.PWidth | ||
{{CodeEnd}} | {{CodeEnd}} | ||
: You could keep the red and green intensity settings higher than blue to yellow, brown, or antique the image too. | : You could keep the red and green intensity settings higher than blue to yellow, brown, or antique the image too. | ||
Revision as of 01:45, 23 January 2023
Grey scale is necessary for compatibility with QBasic's legacy SCREEN modes when viewing 24/32 bit bitmaps! You may also desire grey scale images for aesthetic or artistic reasons.
- Set each color attribute's RGB intensities to the same value while incrementing the attribute values and intensity levels.
- Don't exceed 63 when using OUT in legacy screen modes 12 or 13. Screens 7 and 9 use DAC color settings.
- Then set the color attributes to reflect the number of colors available in that legacy screen mode.
- 24/32 bit do not use color attributes, so the intensity levels must be set to an average for all three.
SUB TrueColor12 'Screen 12 greyscale of 24 bit 'code by Bob Seguin IF BMP.PWidth * 3) MOD 4) THEN ZeroPAD$ = SPACE$((4 - ((BMP.PWidth * 3) MOD 4))) END IF n = 3 FOR Colr = 0 TO 15 '16 colors OUT &H3C8, Colr OUT &H3C9, n 'color intensities are each equal in grey scale OUT &H3C9, n OUT &H3C9, n n = n + 4 'increment intensities. maximum intensity = 63 NEXT Colr y = BMP.PDepth - 1: o$ = " " GET #1, BMP.Offset, o$ R$ = " ": G$ = " ": B$ = " " DO x = 0 'set image to left of screen DO GET #1, , B$ GET #1, , G$ GET #1, , R$ red = ASC(R$) 'intensities from 0 to 255 grn = ASC(G$) blu = ASC(B$) average = (red + grn + blu) \ 48 'divide by 16 colors and divide by 3 for average PSET (x, y), average '255 * 3 divided by 16 = maximum color of 15 x = x + 1 LOOP WHILE x < BMP.Pwidth GET #1, , ZeroPAD$ 'move up one row from bottom y = y - 1 LOOP UNTIL y = -1 END SUB |
SUB TrueColor13 'Screen 13 greyscale of 24 bit 'code by Bob Seguin IF ((BMP.PWidth * 3) MOD 4) <> 0 THEN ZeroPAD$ = SPACE$((4 - ((BMP.PWidth * 3) MOD 4))) END IF FOR Colr = 0 TO 255 STEP 4 '63 different intensities FOR Reps = 0 TO 3 'set 3 colors at a time OUT &H3C8, Colr + Reps OUT &H3C9, n 'color intensities are each equal in grey scale OUT &H3C9, n OUT &H3C9, n NEXT Reps n = n + 1 'increment intensities. maximum = 63 NEXT Colr y = BMP.PDepth - 1: o$ = " " GET #1, BMP.Offset, o$ 'offset + 1 immediately after header R$ = " ": G$ = " ": B$ = " " DO x = 0 'set image to left side of screen DO GET #1, , B$ GET #1, , G$ GET #1, , R$ red = ASC(R$) grn = ASC(G$) blu = ASC(B$) average = (red + grn + blu) \ 3 'divide by 3 for average as colors match intensities PSET (x, y), average '3 * 255 divided by 3 = maximum color attribute of 255 x = x + 1 LOOP WHILE x < BMP.PWidth GET #1, , ZeroPAD$ 'skip padder if used y = y - 1 'move up one row from bottom LOOP UNTIL y = -1 END SUB |
SUB TrueGreyScale 'convert a 24 bit bitmap image to grey scale IF ((BMP.PWidth * 3) MOD 4) <> 0 THEN ZeroPAD$ = SPACE$((4 - ((BMP.PWidth * 3) MOD 4))) END IF y = BMP.PDepth - 1: o$ = " " GET #1, BMP.Offset, o$ 'offset + 1 immediately after header R$ = " ": G$ = " ": B$ = " " DO x = 0 'set image to left side of screen DO GET #1, , B$ GET #1, , G$ GET #1, , R$ red = ASC(R$) grn = ASC(G$) blu = ASC(B$) average = (red + grn + blu) \ 3 'divide by 3 for average as colors match intensities PSET (x, y), _RGB32(average, average, average) 'maximum color intensity = 255 x = x + 1 LOOP WHILE x < BMP.PWidth GET #1, , ZeroPAD$ 'skip padder if used y = y - 1 'move up one row from bottom LOOP UNTIL y = -1 END SUB |
- To tint a SCREEN 12 or 13 greyscale image, keep the palette intensity settings of 1 or 2 colors less than the others.
FOR Colr = 0 TO 255 STEP 4 '63 different intensities FOR Reps = 0 TO 3 'set 3 colors at a time OUT &H3C8, Colr + Reps OUT &H3C9, n - tint 'decrease color intensities of red and green OUT &H3C9, n - tint OUT &H3C9, n 'higher blue intensity will blue the image NEXT Reps n = n + 1 'increment intensities. maximum = 63 IF n > 5 THEN tint = 5 'keep red and green intensity values above 0! NEXT Colr |
- In 24/32 bit SCREENs, subtract some intensity from one or two of the 3 image pixel settings.
DO GET #1, , B$ GET #1, , G$ GET #1, , R$ red = ASC(R$) grn = ASC(G$) blu = ASC(B$) average = (red + grn + blu) \ 3 'divide by 3 for average as colors match intensities IF average > 5 THEN tint = 5 ELSE tint = 0 PSET (x, y), _RGB32(average - tint, average - tint, average) 'maximum color intensity = 255 x = x + 1 LOOP WHILE x < BMP.PWidth |
- You could keep the red and green intensity settings higher than blue to yellow, brown, or antique the image too.
See also