主题:[qbasic]发两个图象处理的SUB
设置调色板:
首先在主程序中定义数组:
dim shared redcol(255) as integer
dim shared grecol(255) as integer
dim shared blucol(255) as integer
SUB setpalette (r AS INTEGER)
FOR i = 1 TO 16
FOR j = 1 TO 16
x = ((i + 1) \ 2 - 1) * r
red = x \ r
IF red = 7 THEN red = 8
IF x = r * 7 THEN x = r * 8 - 1
y = ((j - 1) \ 4) * r
IF i MOD 2 = 0 THEN y = y + r * 4
gre = y \ r
IF gre = 7 THEN gre = 8
IF y = r * 7 THEN y = r * 8 - 1
z = ((j - 1) MOD 4) * r * 2
blu = z \ r
IF blu = 6 THEN blu = 8
IF z = r * 6 THEN z = r * 8 - 1
t = i * 16 + j - 17
redcol(t) = red
grecol(t) = gre
blucol(t) = blu
OUT &H3C8, t: OUT &H3C9, x: OUT &H3C9, y: OUT &H3C9, z
NEXT j
NEXT i
END SUB
参数r最小为1,最大为8,与对比度有关.
本调色板保证和BMP的256色一模一样.
向数组中放图片:
DEFLNG A-Z
SUB putimage (seg1 AS INTEGER, ptr1 AS INTEGER, seg2 AS INTEGER, ptr2 AS INTEGER, px AS INTEGER, py AS INTEGER)
DEF SEG = seg1
wid = (PEEK(ptr1) + PEEK(ptr1 + 1) * 256) \ 8
hei = PEEK(ptr1 + 2)
DEF SEG = seg2
targetwid = (PEEK(ptr2) + PEEK(ptr2 + 1) * 256) \ 8
FOR i = 0 TO hei - 1
ds = ptr1 + i * wid + 4
dt = ptr2 + (i + py) * targetwid + 4 + px
FOR j = 0 TO wid - 1
DEF SEG = seg1
x = PEEK(ds + j)
DEF SEG = seg2
POKE dt + j, x
NEXT j
NEXT i
END SUB
seg1 是源图片的SEG.
ptr1 是源图片的PTR.
seg2 是目标图片的SEG.
ptr2 是目标图片的PTR.
px 是源图片在目标图片中的X坐标.
py 是源图片在目标图片中的y坐标.
PS:调用此过程必须保证源图片不会露到目标图片外面. 否则......后果自负!!!
取得SEG和PTR的方法:
dim ss(6) as integer
seg = VARSEG(ss(0))
ptr = VARPTR(ss(0))
在这里顺便讲一下, 源图片和目标图片必须是可以PUT的.
例如:
dim ss(129) as integer
ss(0)=128 '此乃图片宽度*8是也.
ss(1)=16 '此乃图片高度是也.
for i=2 to 129
ss(i)=1028 '大家改一改就知道了.
next i
SCREEN 13
PUT (0,0),ss, PSET '除了PSET,还有PRESET, XOR, AND, OR.大家可以试试.
首先在主程序中定义数组:
dim shared redcol(255) as integer
dim shared grecol(255) as integer
dim shared blucol(255) as integer
SUB setpalette (r AS INTEGER)
FOR i = 1 TO 16
FOR j = 1 TO 16
x = ((i + 1) \ 2 - 1) * r
red = x \ r
IF red = 7 THEN red = 8
IF x = r * 7 THEN x = r * 8 - 1
y = ((j - 1) \ 4) * r
IF i MOD 2 = 0 THEN y = y + r * 4
gre = y \ r
IF gre = 7 THEN gre = 8
IF y = r * 7 THEN y = r * 8 - 1
z = ((j - 1) MOD 4) * r * 2
blu = z \ r
IF blu = 6 THEN blu = 8
IF z = r * 6 THEN z = r * 8 - 1
t = i * 16 + j - 17
redcol(t) = red
grecol(t) = gre
blucol(t) = blu
OUT &H3C8, t: OUT &H3C9, x: OUT &H3C9, y: OUT &H3C9, z
NEXT j
NEXT i
END SUB
参数r最小为1,最大为8,与对比度有关.
本调色板保证和BMP的256色一模一样.
向数组中放图片:
DEFLNG A-Z
SUB putimage (seg1 AS INTEGER, ptr1 AS INTEGER, seg2 AS INTEGER, ptr2 AS INTEGER, px AS INTEGER, py AS INTEGER)
DEF SEG = seg1
wid = (PEEK(ptr1) + PEEK(ptr1 + 1) * 256) \ 8
hei = PEEK(ptr1 + 2)
DEF SEG = seg2
targetwid = (PEEK(ptr2) + PEEK(ptr2 + 1) * 256) \ 8
FOR i = 0 TO hei - 1
ds = ptr1 + i * wid + 4
dt = ptr2 + (i + py) * targetwid + 4 + px
FOR j = 0 TO wid - 1
DEF SEG = seg1
x = PEEK(ds + j)
DEF SEG = seg2
POKE dt + j, x
NEXT j
NEXT i
END SUB
seg1 是源图片的SEG.
ptr1 是源图片的PTR.
seg2 是目标图片的SEG.
ptr2 是目标图片的PTR.
px 是源图片在目标图片中的X坐标.
py 是源图片在目标图片中的y坐标.
PS:调用此过程必须保证源图片不会露到目标图片外面. 否则......后果自负!!!
取得SEG和PTR的方法:
dim ss(6) as integer
seg = VARSEG(ss(0))
ptr = VARPTR(ss(0))
在这里顺便讲一下, 源图片和目标图片必须是可以PUT的.
例如:
dim ss(129) as integer
ss(0)=128 '此乃图片宽度*8是也.
ss(1)=16 '此乃图片高度是也.
for i=2 to 129
ss(i)=1028 '大家改一改就知道了.
next i
SCREEN 13
PUT (0,0),ss, PSET '除了PSET,还有PRESET, XOR, AND, OR.大家可以试试.