Difference between revisions of "Grey Scale Bitmaps"

From QB64 Wiki
Jump to navigation Jump to search
imported>Clippy
(Created page with '{{CodeStart}} '' '' {{Cl|SUB}} True{{Cl|COLOR}}12 'screen 12 ************************greyscale 24 bit {{Cl|IF}} ((Picture{{Cl|WIDTH}}& * 3) {{Cl|MOD}} 4) <> 0 {{Cl|THEN}} ZeroP…')
 
imported>Clippy
Line 1: Line 1:
 
{{CodeStart}}
 
{{CodeStart}}
 
'' ''
 
'' ''
{{Cl|SUB}} True{{Cl|COLOR}}12  'screen 12 ************************greyscale 24 bit
+
{{Cl|SUB}} True{{Cl|COLOR}}12  'Screen 12 greyscale 24 bit 'code by Bob Seguin
 
+
{{Cl|IF}} BMP.PWidth * 3) {{Cl|MOD}} 4) <> 0 {{Cl|THEN}}
{{Cl|IF}} ((Picture{{Cl|WIDTH}}& * 3) {{Cl|MOD}} 4) <> 0 {{Cl|THEN}}
+
ZeroPAD$ = {{Cl|SPACE$}}((4 - ((BMP.PWidth * 3) {{Cl|MOD}} 4)))
ZeroPAD$ = {{Cl|SPACE$}}((4 - ((Picture{{Cl|WIDTH}}& * 3) {{Cl|MOD}} 4)))
 
 
{{Cl|END IF}}
 
{{Cl|END IF}}
 
{{Cl|SCREEN (statement)|SCREEN}} 12
 
 
 
n = 3
 
n = 3
 
{{Cl|FOR...NEXT|FOR}} Colr = 0 {{Cl|TO}} 15
 
{{Cl|FOR...NEXT|FOR}} Colr = 0 {{Cl|TO}} 15
Line 17: Line 13:
 
         n = n + 4
 
         n = n + 4
 
{{Cl|NEXT}} Colr
 
{{Cl|NEXT}} Colr
 
+
y = PictureDEPTH& - 1: o$ = " "
y = PictureDEPTH& - 1
+
{{Cl|GET}} #1, BMP.Offset, o$
 
+
R$ = " ": G$ = " ": B$ = " "
o$ = " "
 
{{Cl|GET}} #1, OffsetBITS&, o$
 
 
 
a$ = " "
 
B$ = " "
 
c$ = " "
 
 
 
 
{{Cl|DO}}
 
{{Cl|DO}}
 
x = 0
 
x = 0
    
+
   {{Cl|DO}}
    {{Cl|DO}}
 
 
     {{Cl|GET}} #1, , a$
 
     {{Cl|GET}} #1, , a$
 
     {{Cl|GET}} #1, , B$
 
     {{Cl|GET}} #1, , B$
 
     {{Cl|GET}} #1, , c$
 
     {{Cl|GET}} #1, , c$
     a = {{Cl|ASC}}(a$)
+
     b = {{Cl|ASC}}(a$)           'intensities from 0 to 255
     B = {{Cl|ASC}}(B$)
+
     g = {{Cl|ASC}}(B$)
     c = {{Cl|ASC}}(c$)
+
     r = {{Cl|ASC}}(c$)
     d = (a + B + c) \ 48
+
     average = (r + g + b) \ 48   'divide by 16 colors and divide by 3 for average
 
+
     {{Cl|PSET}} (x, y), average
     {{Cl|PSET}} (x, y), d
 
 
     x = x + 1
 
     x = x + 1
 
 
     {{Cl|LOOP}} {{Cl|WHILE}} x < Picture{{Cl|WIDTH}}&
 
     {{Cl|LOOP}} {{Cl|WHILE}} x < Picture{{Cl|WIDTH}}&
  
Line 52: Line 38:
  
 
{{CodeEnd}}
 
{{CodeEnd}}
 +
  
 
{{CodeStart}}
 
{{CodeStart}}
 
'' ''
 
'' ''
{{Cl|SUB}} True{{Cl|COLOR}}13    'screen 13*****************greyscale 24 bit
+
{{Cl|SUB}} True{{Cl|COLOR}}13    'Screen 13 greyscale of 24 bit 'code by Bob Seguin
  
{{Cl|IF}} ((Picture{{Cl|WIDTH}}& * 3) {{Cl|MOD}} 4) <> 0 {{Cl|THEN}}
+
{{Cl|IF}} ((BMP.PWidth * 3) {{Cl|MOD}} 4) <> 0 {{Cl|THEN}}
ZeroPAD$ = {{Cl|SPACE$}}((4 - ((Picture{{Cl|WIDTH}}& * 3) {{Cl|MOD}} 4)))
+
ZeroPAD$ = {{Cl|SPACE$}}((4 - ((BMP.PWidth * 3) {{Cl|MOD}} 4)))
 
{{Cl|END IF}}
 
{{Cl|END IF}}
  
Line 72: Line 59:
 
     n = n + 1
 
     n = n + 1
 
{{Cl|NEXT}} Colr
 
{{Cl|NEXT}} Colr
 
+
y = BMP.PDepth - 1: o$ = " "
y = PictureDEPTH& - 1
+
{{Cl|GET}} #1, BMP.Offset, o$   'offset + 1 immediately after header
 
+
R$ = " ": G$ = " ": B$ = " "
o$ = " "
 
{{Cl|GET}} #1, OffsetBITS&, o$
 
 
 
a$ = " "
 
B$ = " "
 
c$ = " "
 
 
 
 
{{Cl|DO}}
 
{{Cl|DO}}
x = 0
+
x = 0                       'set image to left side of screen
 
 
 
     {{Cl|DO}}
 
     {{Cl|DO}}
    {{Cl|GET}} #1, , a$
 
 
     {{Cl|GET}} #1, , B$
 
     {{Cl|GET}} #1, , B$
     {{Cl|GET}} #1, , c$
+
     {{Cl|GET}} #1, , G$
     a = {{Cl|ASC}}(a$)
+
     {{Cl|GET}} #1, , R$
     B = {{Cl|ASC}}(B$)
+
    red = {{Cl|ASC}}(R$)
     c = {{Cl|ASC}}(c$)
+
     grn = {{Cl|ASC}}(G$)
     d = (a + B + c) / 3
+
     blu = {{Cl|ASC}}(B$)
 
+
     average = (red + grn + blu) \ 3
     {{Cl|PSET}} (x, y), d
+
     {{Cl|PSET}} (x, y), average
 
     x = x + 1
 
     x = x + 1
 
+
     {{Cl|LOOP}} {{Cl|WHILE}} x < BMP.PWidth
     {{Cl|LOOP}} {{Cl|WHILE}} x < Picture{{Cl|WIDTH}}&
+
     {{Cl|GET}} #1, , ZeroPAD$                 'skip padder if used
 
+
     y = y - 1                             'move up one row from bottom
     {{Cl|GET}} #1, , ZeroPAD$
 
     y = y - 1
 
 
 
 
{{Cl|LOOP}} {{Cl|UNTIL}} y = -1
 
{{Cl|LOOP}} {{Cl|UNTIL}} y = -1
 
 
{{Cl|END}} {{Cl|SUB}} '' ''
 
{{Cl|END}} {{Cl|SUB}} '' ''
  

Revision as of 00:22, 6 September 2010

SUB TrueCOLOR12 'Screen 12 greyscale 24 bit 'code by Bob Seguin IF BMP.PWidth * 3) MOD 4) <> 0 THEN ZeroPAD$ = SPACE$((4 - ((BMP.PWidth * 3) MOD 4))) END IF n = 3 FOR Colr = 0 TO 15 OUT &H3C8, Colr OUT &H3C9, n OUT &H3C9, n OUT &H3C9, n n = n + 4 NEXT Colr y = PictureDEPTH& - 1: o$ = " " GET #1, BMP.Offset, o$ R$ = " ": G$ = " ": B$ = " " DO x = 0 DO GET #1, , a$ GET #1, , B$ GET #1, , c$ b = ASC(a$) 'intensities from 0 to 255 g = ASC(B$) r = ASC(c$) average = (r + g + b) \ 48 'divide by 16 colors and divide by 3 for average PSET (x, y), average x = x + 1 LOOP WHILE x < PictureWIDTH& GET #1, , ZeroPAD$ 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 SCREEN 13 FOR Colr = 0 TO 255 STEP 4 FOR Reps = 0 TO 3 OUT &H3C8, Colr + Reps OUT &H3C9, n OUT &H3C9, n OUT &H3C9, n NEXT Reps n = n + 1 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 PSET (x, y), average 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


See also:




Navigation:
Keyword Reference - Alphabetical
Keyword Reference - By Usage
Main Wiki Page