📄 svgacc.txt
字号:
responsibility to be sure all pointers reference properly
allocated memory of the appropriate size.
Whenever a pixel is written on the screen, a mode is required.
Unless otherwise noted, there are five possible modes:
NO_ACTION, SET, XOR, OR and AND. These modes are represented by
the numbers zero through four respectively. NO_ACTION is self-
explanatory. Technically, SET is the fastest mode. However, XOR
maybe the most useful. XOR'ing a point twice with the same color
returns the original color. This can be used to cover and
uncover graphics. In addition when a reference to a color index
is made, only values between and including 0 and 255 are valid.
Any integer will work, but only the lowest eight bits are
recognized.
7
BLKGET
PROTOTYPE
extern int far blkget (int x1, int y1, int x2, int y2,
RasterBlock far *gfxblk)
INPUT
x1, y1 - top left corner of block
x2, y2 - bottom right corner of block
OUTPUT
BLKGET returns 1 if successful, 0 if failed.
gfxblk - retrieved bitmap
USAGE
BLKGET stores the pixel data contained within the block
defined by (x1, y1)-(x2, y2) in the variable referenced by
gfxblk. Memory for gfxblk must be allocated as a RasterBlock
structure with a data size in bytes equal to
[(x2-x1+1)*(y2-y1+1)]
plus four bytes for the width and height integers of the
RasterBlock structure.
Note, however, that gfxblk can be quite large. If the size of
gfxblk is insufficient, BLKGET will overwrite any data in
memory contained beyond gfxblk and may possibly cause the
system to crash. In addition the segmented nature of real
mode programming requires that gfxblk be smaller 65536 bytes.
For larger blocks, see XMSBLKGET. BLKGET enforces X2 X1 and
Y2 Y1. Also, the coordinates must be valid on the screen at
the current resolution.
SEE ALSO
BLKPUT, BLKRESIZE, BLKROTATE, GETLASTSTRING, SPRITEGAP,
SPRITEGET, SPRITEPUT, XMSBLKGET, XMSBLKPUT
EXAMPLE
/*
* Places 1/4 of a circle at the center of the screen
*/
#include <stdlib.h>
#include <conio.h>
#include "svgacc.h"
void main(void)
{
8
int vmode;
int a,b,c,d;
RasterBlock *blkdata;
vmode = videomodeget();
if ( !whichvga() || (whichmem() < 512))
exit(1);
res640();
drwcircle(1,10,30,30,20);
fillarea(30,30,10,7);
a = b = 0;
c = d = 30;
blkdata = (RasterBlock *)malloc((c-a+1)*(d-b+1)+4);
blkget(a,b,c,d,blkdata);
blkput(1,320,240,blkdata);
getch();
videomodeset(vmode);
exit(0);
}
9
BLKPUT
PROTOTYPE
extern void far blkput (PixelMode mode, int x, int y,
RasterBlock far *gfxblk)
INPUT
mode - pixel write mode
x, y - location for top left corner of block
gfxblk - RasterBlock pointer to bitmap
OUTPUT
no value returned
USAGE
BLKPUT places the pixel data contained in the variable
referenced by gfxblk on the screen. The top, left corner of
the block is specified by (X, Y). Any (X, Y) is acceptable
and any portion of the block that lies outside of the
currently defined viewport will not be drawn.
SEE ALSO
BLKGET, BLKRESIZE, BLKROTATE, GETLASTSTRING, SPRITEGAP,
SPRITEGET, SPRITEPUT, PCXPUT, SETVIEW, XMSBLKGET, XMSBLKPUT
EXAMPLE
See BLKGET
10
BLKRESIZE
PROTOTYPE
extern void far blkresize (unsigned newxsize, unsigned
newysize, RasterBlock far *sourcegfxblk, RasterBlock far
*destgfxblk)
INPUT
newxsize, newysize - size of resulting bitmap in destgfxblk
sourcegfxblk - RasterBlock pointer to source bitmap
OUTPUT
no value returned
destgfxblk - resized bitmap
USAGE
BLKRESIZE takes the bitmap in sourcegfxblk and scales it up or
down according the to values passed in newxsize and newysize.
The resulting bitmap is returned in destgfxblk which should
already be declared with a size calculated according to the
equation in BLKGET. Neither newxsize nor newysize should be
zero.
SEE ALSO
BLKGET, BLKPUT, BLKROTATE
EXAMPLE
/*
* Show blkresize
*/
#include <stdlib.h>
#include <math.h>
#include <conio.h>
#include "svgacc.h"
#define randnum(size) (rand() % (int)(size))
void main(void)
{
int vmode, i, j, colr, x1, y1, x2, y2;
RasterBlock *gfxblk1, *gfxblk2;
vmode = videomodeget();
if ( !whichvga() || (whichmem() < 512))
exit(1);
if ( !res640() )
exit(1);
i=20000;
gfxblk1 = (RasterBlock *)malloc(i);
11
if (!gfxblk1) {
restext();
printf("ERROR: Allocating memory for gfxblk1: %d
bytes\n",i);
exit(1);
}
gfxblk2 = (RasterBlock *)malloc(i);
if (!gfxblk2) {
restext();
printf("ERROR: Allocating memory for gfxblk2: %d
bytes\n",i);
exit(1);
}
for(i=0;i<=25;i++) {
x1 = randnum(50);
y1 = randnum(50);
x2 = randnum(50);
y2 = randnum(50);
colr = randnum(16);
drwline(1,colr,x1,y1,x2,y2);
}
x1 = 0;
y1 = 0;
x2 = 50;
y2 = 50;
drwbox(1,15,x1,y1,x2,y2);
blkget(x1,y1,x2,y2,gfxblk1);
x1 = maxx / 2;
y1 = maxy / 2;
blkresize(50,50,gfxblk1,gfxblk2);
blkput(2,x1-(gfxblk2->width)/2,y1-(gfxblk2-
>height)/2,gfxblk2);
for(i=x2;i<=x2+50;i++) {
blkput(2,x1-(gfxblk2->width)/2,y1-(gfxblk2-
>height)/2,gfxblk2);
blkresize(i,i,gfxblk1,gfxblk2);
blkput(2,x1-(gfxblk2->width)/2,y1-(gfxblk2-
>height)/2,gfxblk2);
sdelay(3);
}
for(i=x2+50;i>=x2-50;i--) {
blkput(2,x1-(gfxblk2->width)/2,y1-(gfxblk2-
>height)/2,gfxblk2);
blkresize(i,i,gfxblk1,gfxblk2);
blkput(2,x1-(gfxblk2->width)/2,y1-(gfxblk2-
>height)/2,gfxblk2);
sdelay(3);
}
for(i=x2-50;i<=x2+1;i++) {
blkput(2,x1-(gfxblk2->width)/2,y1-(gfxblk2-
>height)/2,gfxblk2);
blkresize(i,i,gfxblk1,gfxblk2);
blkput(2,x1-(gfxblk2->width)/2,y1-(gfxblk2-
>height)/2,gfxblk2);
12
sdelay(3);
}
getch();
videomodeset(vmode);
exit(0);
}
13
BLKROTATE
PROTOTYPE
extern int far blkrotate (int ang, int backfill, RasterBlock
far *sourcegfxblk, RasterBlock far *destgfxblk)
INPUT
ang - integer degree to rotate source bitmap
backfill - index to color in current palette to fill blank
space in destgfxblk
sourcegfxblk - RasterBlock pointer to source bitmap
OUTPUT
BLKROTATE returns 1 if successful, 0 if unsuccessful.
destgfxblk - rotated bitmap
USAGE
BLKROTATE takes the bitmap in sourcegfxblk and rotates by the
number of degrees specified in ang. The bitmap rotation
algorithm is a three-pass shear technique modified to make
efficient use of this library's internal buffers. Blank space
around the newly rotated block is filled with the color given
by backfill. The resulting bitmap is stored in destgfxblk.
The size of destgfxblk should be at least as big as given by
BLKROTATESIZE.
The function will fail if it calculates that the internal
buffers would be overflowed or if the destination array would
be larger than 65536 bytes. BLKROTATESIZE should be called
first to ensure that buffer integrity is maintained.
SEE ALSO
BLKGET, BLKPUT, BLKRESIZE, BLKROTATESIZE
EXAMPLE
/*
* Show blkrotate
*/
#include <stdlib.h>
#include <math.h>
#include <conio.h>
#include "svgacc.h"
void main(void)
{
int xinc, yinc, x1, y1, x2, y2, i, j, colr, vmode, cntx,
cnty, rot;
RasterBlock *gfxblk, *gfxblk2, *spritebkgnd;
14
vmode = videomodeget();
if ( !whichvga() || (whichmem() < 512))
exit(1);
if ( !res640() )
exit(1);
xinc = maxx/10;
yinc = maxy/20;
x1 = maxx/2-xinc;
y1 = maxy/2-yinc;
x2 = maxx/2+xinc;
y2 = maxy/2+yinc;
i = (x2-x1+1)*(y2-y1+1)+4;
gfxblk = (RasterBlock *)malloc(i);
if (!gfxblk) {
restext();
printf("ERROR: Allocating memory for gfxblk: %d
bytes\n",i);
exit(1);
}
colr = 1;
for(i=0;i<=maxx/2;i++) {
drwcircle(1,colr,maxx/4+i,maxy/2,maxy/5);
colr+=1;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -