Fixed several off-by-one errors and some compiler warnings

svn path=/trunk/; revision=4229
This commit is contained in:
Gé van Geldorp 2003-03-02 12:04:00 +00:00
parent 8690cad211
commit 1b1e741e1b
9 changed files with 113 additions and 115 deletions

View file

@ -17,87 +17,86 @@ DrvLineTo(SURFOBJ *Surface,
// FIXME: Use Mix to perform ROPs // FIXME: Use Mix to perform ROPs
{ {
ULONG x, y, d, i, length, xchange, ychange, error, ULONG x, y, d, i, xchange, ychange, error,
iSolidColor, hx, vy; iSolidColor, hx, vy;
LONG deltax, deltay; LONG deltax, deltay;
iSolidColor = Brush->iSolidColor; // FIXME: Brush Realization... iSolidColor = Brush->iSolidColor; // FIXME: Brush Realization...
// FIXME: Implement clipping // FIXME: Implement clipping
x=x1; x = x1;
y=y1; y = y1;
deltax=x2-x1; deltax = x2 - x1;
deltay=y2-y1; deltay = y2 - y1;
if(deltax<0) if (deltax < 0)
{ {
xchange=-1; xchange = -1;
deltax=-deltax; deltax = - deltax;
hx = x2; hx = x2;
} else x--;
{ }
xchange=1; else
hx = x1; {
} xchange = 1;
hx = x1;
}
if(deltay<0) if (deltay < 0)
{ {
ychange=-1; ychange = -1;
deltay=-deltay; deltay = - deltay;
vy = y2; vy = y2;
} else y--;
{ }
ychange=1; else
vy = y1; {
}; ychange = 1;
vy = y1;
};
if(y1==y2) if (y1 == y2)
{ {
return vgaHLine(hx, y1, deltax, iSolidColor); return vgaHLine(hx, y1, deltax, iSolidColor);
} }
if(x1==x2) if (x1 == x2)
{ {
return vgaVLine(x1, vy, deltay, iSolidColor); return vgaVLine(x1, vy, deltay, iSolidColor);
} }
// Using individual pixels to draw a line neither horizontal or vertical // Using individual pixels to draw a line neither horizontal or vertical
// Set up the VGA masking for individual pixels // Set up the VGA masking for individual pixels
error = 0;
error=0; if (deltax < deltay)
i=0;
if(deltax<deltay)
{
length=deltay+1;
while(i<length)
{
vgaPutPixel(x, y, iSolidColor);
y=y+ychange;
error=error+deltax;
if(error>deltay)
{
x=x+xchange;
error=error-deltay;
}
i=i+1;
}
} else
{
length=deltax+1;
while(i<length)
{ {
vgaPutPixel(x, y, iSolidColor); for (i = 0; i < deltay; i++)
x=x+xchange; {
error=error+deltay; vgaPutPixel(x, y, iSolidColor);
if(error>deltax) y = y + ychange;
{ error = error + deltax;
y=y+ychange;
error=error-deltax; if (deltay <= error)
} {
i=i+1; x = x + xchange;
error = error - deltay;
}
}
}
else
{
for (i = 0; i < deltax; i++)
{
vgaPutPixel(x, y, iSolidColor);
x = x + xchange;
error = error + deltay;
if (deltax <= error)
{
y = y + ychange;
error = error - deltax;
}
} }
} }

View file

@ -270,7 +270,7 @@ BOOL vgaHLine(INT x, INT y, INT len, UCHAR c)
// Calculate the left mask pixels, middle bytes and right mask pixel // Calculate the left mask pixels, middle bytes and right mask pixel
ileftpix = 8-mod(x, 8); ileftpix = 8-mod(x, 8);
irightpix = mod(x+len, 8); irightpix = mod(x+len-1, 8);
imidpix = (len-ileftpix-irightpix) / 8; imidpix = (len-ileftpix-irightpix) / 8;
pre1=xconv[x-(8-ileftpix)]+y80[y]; pre1=xconv[x-(8-ileftpix)]+y80[y];
@ -324,8 +324,6 @@ BOOL vgaVLine(INT x, INT y, INT len, UCHAR c)
WRITE_PORT_UCHAR((PUCHAR)0x3ce,0x08); // set the mask WRITE_PORT_UCHAR((PUCHAR)0x3ce,0x08); // set the mask
WRITE_PORT_UCHAR((PUCHAR)0x3cf,maskbit[x]); WRITE_PORT_UCHAR((PUCHAR)0x3cf,maskbit[x]);
len++;
for(i=y; i<y+len; i++) for(i=y; i<y+len; i++)
{ {
a = READ_REGISTER_UCHAR(vidmem + offset); a = READ_REGISTER_UCHAR(vidmem + offset);

View file

@ -0,0 +1,5 @@
/* Static data */
unsigned char notmask[2] = { 0x0f, 0xf0 };
unsigned char altnotmask[2] = { 0xf0, 0x0f };
unsigned char mask1Bpp[8] = { 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80 };

View file

@ -1,25 +1,25 @@
static unsigned char notmask[2] = { 0x0f, 0xf0 }; extern unsigned char notmask[2];
static unsigned char altnotmask[2] = { 0xf0, 0x0f }; extern unsigned char altnotmask[2];
static unsigned char mask1Bpp[8] = { 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80 }; extern unsigned char mask1Bpp[8];
typedef VOID (*PFN_DIB_PutPixel)(PSURFOBJ, LONG, LONG, ULONG); typedef VOID (*PFN_DIB_PutPixel)(PSURFOBJ, LONG, LONG, ULONG);
typedef ULONG (*PFN_DIB_GetPixel)(PSURFOBJ, LONG, LONG); typedef ULONG (*PFN_DIB_GetPixel)(PSURFOBJ, LONG, LONG);
typedef VOID (*PFN_DIB_HLine) (PSURFOBJ, LONG, LONG, LONG, ULONG); typedef VOID (*PFN_DIB_HLine) (PSURFOBJ, LONG, LONG, LONG, ULONG);
typedef VOID (*PFN_DIB_VLine) (PSURFOBJ, LONG, LONG, LONG, ULONG); typedef VOID (*PFN_DIB_VLine) (PSURFOBJ, LONG, LONG, LONG, ULONG);
PFN_DIB_PutPixel DIB_1BPP_PutPixel(PSURFOBJ SurfObj, LONG x, LONG y, ULONG c); VOID DIB_1BPP_PutPixel(PSURFOBJ SurfObj, LONG x, LONG y, ULONG c);
PFN_DIB_GetPixel DIB_1BPP_GetPixel(PSURFOBJ SurfObj, LONG x, LONG y); ULONG DIB_1BPP_GetPixel(PSURFOBJ SurfObj, LONG x, LONG y);
PFN_DIB_HLine DIB_1BPP_HLine(PSURFOBJ SurfObj, LONG x1, LONG x2, LONG y, ULONG c); VOID DIB_1BPP_HLine(PSURFOBJ SurfObj, LONG x1, LONG x2, LONG y, ULONG c);
PFN_DIB_VLine DIB_1BPP_VLine(PSURFOBJ SurfObj, LONG x, LONG y1, LONG y2, ULONG c); VOID DIB_1BPP_VLine(PSURFOBJ SurfObj, LONG x, LONG y1, LONG y2, ULONG c);
BOOLEAN DIB_To_1BPP_Bitblt( SURFOBJ *DestSurf, SURFOBJ *SourceSurf, BOOLEAN DIB_To_1BPP_Bitblt( SURFOBJ *DestSurf, SURFOBJ *SourceSurf,
SURFGDI *DestGDI, SURFGDI *SourceGDI, SURFGDI *DestGDI, SURFGDI *SourceGDI,
PRECTL DestRect, POINTL *SourcePoint, PRECTL DestRect, POINTL *SourcePoint,
LONG Delta, XLATEOBJ *ColorTranslation); LONG Delta, XLATEOBJ *ColorTranslation);
PFN_DIB_PutPixel DIB_4BPP_PutPixel(PSURFOBJ SurfObj, LONG x, LONG y, ULONG c); VOID DIB_4BPP_PutPixel(PSURFOBJ SurfObj, LONG x, LONG y, ULONG c);
PFN_DIB_GetPixel DIB_4BPP_GetPixel(PSURFOBJ SurfObj, LONG x, LONG y); ULONG DIB_4BPP_GetPixel(PSURFOBJ SurfObj, LONG x, LONG y);
PFN_DIB_HLine DIB_4BPP_HLine(PSURFOBJ SurfObj, LONG x1, LONG x2, LONG y, ULONG c); VOID DIB_4BPP_HLine(PSURFOBJ SurfObj, LONG x1, LONG x2, LONG y, ULONG c);
PFN_DIB_VLine DIB_4BPP_VLine(PSURFOBJ SurfObj, LONG x, LONG y1, LONG y2, ULONG c); VOID DIB_4BPP_VLine(PSURFOBJ SurfObj, LONG x, LONG y1, LONG y2, ULONG c);
BOOLEAN DIB_To_4BPP_Bitblt( SURFOBJ *DestSurf, SURFOBJ *SourceSurf, BOOLEAN DIB_To_4BPP_Bitblt( SURFOBJ *DestSurf, SURFOBJ *SourceSurf,
SURFGDI *DestGDI, SURFGDI *SourceGDI, SURFGDI *DestGDI, SURFGDI *SourceGDI,
PRECTL DestRect, POINTL *SourcePoint, PRECTL DestRect, POINTL *SourcePoint,
@ -34,10 +34,10 @@ BOOL DIB_To_16BPP_Bitblt( SURFOBJ *DestSurf, SURFOBJ *SourceSurf,
PRECTL DestRect, POINTL *SourcePoint, PRECTL DestRect, POINTL *SourcePoint,
LONG Delta, XLATEOBJ *ColorTranslation); LONG Delta, XLATEOBJ *ColorTranslation);
PFN_DIB_PutPixel DIB_24BPP_PutPixel(PSURFOBJ SurfObj, LONG x, LONG y, ULONG c); VOID DIB_24BPP_PutPixel(PSURFOBJ SurfObj, LONG x, LONG y, ULONG c);
PFN_DIB_GetPixel DIB_24BPP_GetPixel(PSURFOBJ SurfObj, LONG x, LONG y); ULONG DIB_24BPP_GetPixel(PSURFOBJ SurfObj, LONG x, LONG y);
PFN_DIB_HLine DIB_24BPP_HLine(PSURFOBJ SurfObj, LONG x1, LONG x2, LONG y, ULONG c); VOID DIB_24BPP_HLine(PSURFOBJ SurfObj, LONG x1, LONG x2, LONG y, ULONG c);
PFN_DIB_VLine DIB_24BPP_VLine(PSURFOBJ SurfObj, LONG x, LONG y1, LONG y2, ULONG c); VOID DIB_24BPP_VLine(PSURFOBJ SurfObj, LONG x, LONG y1, LONG y2, ULONG c);
BOOLEAN DIB_To_24BPP_Bitblt( SURFOBJ *DestSurf, SURFOBJ *SourceSurf, BOOLEAN DIB_To_24BPP_Bitblt( SURFOBJ *DestSurf, SURFOBJ *SourceSurf,
SURFGDI *DestGDI, SURFGDI *SourceGDI, SURFGDI *DestGDI, SURFGDI *SourceGDI,
PRECTL DestRect, POINTL *SourcePoint, PRECTL DestRect, POINTL *SourcePoint,

View file

@ -30,7 +30,7 @@ VOID DIB_16BPP_HLine(PSURFOBJ SurfObj, LONG x1, LONG x2, LONG y, ULONG c)
PWORD addr = (PWORD)byteaddr + x1; PWORD addr = (PWORD)byteaddr + x1;
LONG cx = x1; LONG cx = x1;
while(cx <= x2) { while(cx < x2) {
*addr = (WORD)c; *addr = (WORD)c;
++addr; ++addr;
++cx; ++cx;
@ -44,7 +44,7 @@ VOID DIB_16BPP_VLine(PSURFOBJ SurfObj, LONG x, LONG y1, LONG y2, ULONG c)
LONG lDelta = SurfObj->lDelta; LONG lDelta = SurfObj->lDelta;
byteaddr = (PBYTE)addr; byteaddr = (PBYTE)addr;
while(y1++ <= y2) { while(y1++ < y2) {
*addr = (WORD)c; *addr = (WORD)c;
byteaddr += lDelta; byteaddr += lDelta;

View file

@ -8,7 +8,7 @@
#include "../eng/objects.h" #include "../eng/objects.h"
#include "dib.h" #include "dib.h"
PFN_DIB_PutPixel DIB_24BPP_PutPixel(PSURFOBJ SurfObj, LONG x, LONG y, ULONG c) VOID DIB_24BPP_PutPixel(PSURFOBJ SurfObj, LONG x, LONG y, ULONG c)
{ {
PBYTE byteaddr = SurfObj->pvBits + y * SurfObj->lDelta; PBYTE byteaddr = SurfObj->pvBits + y * SurfObj->lDelta;
PRGBTRIPLE addr = (PRGBTRIPLE)byteaddr + x; PRGBTRIPLE addr = (PRGBTRIPLE)byteaddr + x;
@ -16,35 +16,35 @@ PFN_DIB_PutPixel DIB_24BPP_PutPixel(PSURFOBJ SurfObj, LONG x, LONG y, ULONG c)
*(PULONG)(addr) = c; *(PULONG)(addr) = c;
} }
PFN_DIB_GetPixel DIB_24BPP_GetPixel(PSURFOBJ SurfObj, LONG x, LONG y) ULONG DIB_24BPP_GetPixel(PSURFOBJ SurfObj, LONG x, LONG y)
{ {
PBYTE byteaddr = SurfObj->pvBits + y * SurfObj->lDelta; PBYTE byteaddr = SurfObj->pvBits + y * SurfObj->lDelta;
PRGBTRIPLE addr = (PRGBTRIPLE)byteaddr + x; PRGBTRIPLE addr = (PRGBTRIPLE)byteaddr + x;
return (PFN_DIB_GetPixel)(*(PULONG)(addr)); return *(PULONG)(addr) & 0x00ffffff;
} }
PFN_DIB_HLine DIB_24BPP_HLine(PSURFOBJ SurfObj, LONG x1, LONG x2, LONG y, ULONG c) VOID DIB_24BPP_HLine(PSURFOBJ SurfObj, LONG x1, LONG x2, LONG y, ULONG c)
{ {
PBYTE byteaddr = SurfObj->pvBits + y * SurfObj->lDelta; PBYTE byteaddr = SurfObj->pvBits + y * SurfObj->lDelta;
PRGBTRIPLE addr = (PRGBTRIPLE)byteaddr + x1; PRGBTRIPLE addr = (PRGBTRIPLE)byteaddr + x1;
LONG cx = x1; LONG cx = x1;
while(cx <= x2) { while(cx < x2) {
*(PULONG)(addr) = c; *(PULONG)(addr) = c;
++addr; ++addr;
++cx; ++cx;
} }
} }
PFN_DIB_VLine DIB_24BPP_VLine(PSURFOBJ SurfObj, LONG x, LONG y1, LONG y2, ULONG c) VOID DIB_24BPP_VLine(PSURFOBJ SurfObj, LONG x, LONG y1, LONG y2, ULONG c)
{ {
PBYTE byteaddr = SurfObj->pvBits + y1 * SurfObj->lDelta; PBYTE byteaddr = SurfObj->pvBits + y1 * SurfObj->lDelta;
PRGBTRIPLE addr = (PRGBTRIPLE)byteaddr + x; PRGBTRIPLE addr = (PRGBTRIPLE)byteaddr + x;
LONG lDelta = SurfObj->lDelta; LONG lDelta = SurfObj->lDelta;
byteaddr = (PBYTE)addr; byteaddr = (PBYTE)addr;
while(y1++ <= y2) { while(y1++ < y2) {
*(PULONG)(addr) = c; *(PULONG)(addr) = c;
byteaddr += lDelta; byteaddr += lDelta;
@ -89,11 +89,9 @@ BOOLEAN DIB_To_24BPP_Bitblt( SURFOBJ *DestSurf, SURFOBJ *SourceSurf,
LONG Delta, XLATEOBJ *ColorTranslation) LONG Delta, XLATEOBJ *ColorTranslation)
{ {
LONG i, j, sx, sy, xColor, f1; LONG i, j, sx, sy, xColor, f1;
PBYTE DestBits, SourceBits_24BPP, DestLine, SourceLine_24BPP; PBYTE DestBits, DestLine;
PRGBTRIPLE SPDestBits, SPSourceBits_24BPP, SPDestLine, SPSourceLine_24BPP; // specially for 24-to-24 blit PBYTE SourceBits_4BPP, SourceLine_4BPP;
PBYTE SourceBits_4BPP, SourceBits_8BPP, SourceLine_4BPP, SourceLine_8BPP;
PWORD SourceBits_16BPP, SourceLine_16BPP; PWORD SourceBits_16BPP, SourceLine_16BPP;
PDWORD SourceBits_32BPP, SourceLine_32BPP;
DestBits = DestSurf->pvBits + (DestRect->top * DestSurf->lDelta) + DestRect->left * 3; DestBits = DestSurf->pvBits + (DestRect->top * DestSurf->lDelta) + DestRect->left * 3;

View file

@ -8,24 +8,22 @@
#include "../eng/objects.h" #include "../eng/objects.h"
#include "dib.h" #include "dib.h"
PFN_DIB_PutPixel DIB_4BPP_PutPixel(PSURFOBJ SurfObj, LONG x, LONG y, ULONG c) VOID DIB_4BPP_PutPixel(PSURFOBJ SurfObj, LONG x, LONG y, ULONG c)
{ {
unsigned char *vp;
unsigned char mask;
PBYTE addr = SurfObj->pvBits; PBYTE addr = SurfObj->pvBits;
addr += (x>>1) + y * SurfObj->lDelta; addr += (x>>1) + y * SurfObj->lDelta;
*addr = (*addr & notmask[x&1]) | (c << ((1-(x&1))<<2)); *addr = (*addr & notmask[x&1]) | (c << ((1-(x&1))<<2));
} }
PFN_DIB_GetPixel DIB_4BPP_GetPixel(PSURFOBJ SurfObj, LONG x, LONG y) ULONG DIB_4BPP_GetPixel(PSURFOBJ SurfObj, LONG x, LONG y)
{ {
PBYTE addr = SurfObj->pvBits; PBYTE addr = SurfObj->pvBits;
return (PFN_DIB_GetPixel)((addr[(x>>1) + y * SurfObj->lDelta] >> ((1-(x&1))<<2) ) & 0x0f); return (addr[(x>>1) + y * SurfObj->lDelta] >> ((1-(x&1))<<2) ) & 0x0f;
} }
PFN_DIB_HLine DIB_4BPP_HLine(PSURFOBJ SurfObj, LONG x1, LONG x2, LONG y, ULONG c) VOID DIB_4BPP_HLine(PSURFOBJ SurfObj, LONG x1, LONG x2, LONG y, ULONG c)
{ {
PBYTE addr = SurfObj->pvBits + (x1>>1) + y * SurfObj->lDelta; PBYTE addr = SurfObj->pvBits + (x1>>1) + y * SurfObj->lDelta;
LONG cx = x1; LONG cx = x1;
@ -38,7 +36,7 @@ PFN_DIB_HLine DIB_4BPP_HLine(PSURFOBJ SurfObj, LONG x1, LONG x2, LONG y, ULONG c
} }
} }
PFN_DIB_VLine DIB_4BPP_VLine(PSURFOBJ SurfObj, LONG x, LONG y1, LONG y2, ULONG c) VOID DIB_4BPP_VLine(PSURFOBJ SurfObj, LONG x, LONG y1, LONG y2, ULONG c)
{ {
PBYTE addr = SurfObj->pvBits; PBYTE addr = SurfObj->pvBits;
int lDelta = SurfObj->lDelta; int lDelta = SurfObj->lDelta;
@ -57,9 +55,7 @@ BOOLEAN DIB_To_4BPP_Bitblt( SURFOBJ *DestSurf, SURFOBJ *SourceSurf,
{ {
LONG i, j, sx, sy, f1, f2, xColor; LONG i, j, sx, sy, f1, f2, xColor;
PBYTE SourceBits_24BPP, SourceLine_24BPP; PBYTE SourceBits_24BPP, SourceLine_24BPP;
PBYTE DestBits, DestLine, SourceBits_4BPP, SourceBits_8BPP, SourceLine_4BPP, SourceLine_8BPP; PBYTE DestBits, DestLine, SourceBits_8BPP, SourceLine_8BPP;
PWORD SourceBits_16BPP, SourceLine_16BPP;
PDWORD SourceBits_32BPP, SourceLine_32BPP;
DestBits = DestSurf->pvBits + (DestRect->left>>1) + DestRect->top * DestSurf->lDelta; DestBits = DestSurf->pvBits + (DestRect->left>>1) + DestRect->top * DestSurf->lDelta;

View file

@ -106,6 +106,7 @@ EngLineTo(SURFOBJ *DestObj,
xchange = -1; xchange = -1;
deltax = - deltax; deltax = - deltax;
hx = x2; hx = x2;
x--;
} }
else else
{ {
@ -118,6 +119,7 @@ EngLineTo(SURFOBJ *DestObj,
ychange = -1; ychange = -1;
deltay = - deltay; deltay = - deltay;
vy = y2; vy = y2;
y--;
} }
else else
{ {
@ -129,7 +131,7 @@ EngLineTo(SURFOBJ *DestObj,
{ {
DIB_HLine(OutputObj, hx, hx + deltax, y1, Pixel); DIB_HLine(OutputObj, hx, hx + deltax, y1, Pixel);
} }
else if(x1==x2) else if (x1 == x2)
{ {
DIB_VLine(OutputObj, x1, vy, vy + deltay, Pixel); DIB_VLine(OutputObj, x1, vy, vy + deltay, Pixel);
} }
@ -145,7 +147,7 @@ EngLineTo(SURFOBJ *DestObj,
y = y + ychange; y = y + ychange;
error = error + deltax; error = error + deltax;
if (deltay < error) if (deltay <= error)
{ {
x = x + xchange; x = x + xchange;
error = error - deltay; error = error - deltay;
@ -159,7 +161,7 @@ EngLineTo(SURFOBJ *DestObj,
DIB_PutPixel(OutputObj, x, y, Pixel); DIB_PutPixel(OutputObj, x, y, Pixel);
x = x + xchange; x = x + xchange;
error = error + deltay; error = error + deltay;
if (error > deltax) if (deltax <= error)
{ {
y = y + ychange; y = y + ychange;
error = error - deltax; error = error - deltax;

View file

@ -1,4 +1,4 @@
# $Id: makefile,v 1.56 2003/02/25 23:08:52 gvg Exp $ # $Id: makefile,v 1.57 2003/03/02 12:03:59 gvg Exp $
PATH_TO_TOP = ../.. PATH_TO_TOP = ../..
@ -41,7 +41,7 @@ OBJECTS_OBJECTS = objects/bitmaps.o objects/brush.o objects/cliprgn.o \
objects/region.o objects/text.o objects/wingl.o \ objects/region.o objects/text.o objects/wingl.o \
objects/bezier.o objects/objconv.o objects/dib.o \ objects/bezier.o objects/objconv.o objects/dib.o \
objects/palette.o objects/rect.o objects/palette.o objects/rect.o
DIB_OBJECTS = dib/dib1bpp.o dib/dib4bpp.o dib/dib16bpp.o dib/dib24bpp.o DIB_OBJECTS = dib/dib.o dib/dib1bpp.o dib/dib4bpp.o dib/dib16bpp.o dib/dib24bpp.o
FREETYPE_OBJECTS = freetype/ctype.o freetype/grfont.o \ FREETYPE_OBJECTS = freetype/ctype.o freetype/grfont.o \
freetype/src/base/ftsystem.o freetype/src/base/ftdebug.o \ freetype/src/base/ftsystem.o freetype/src/base/ftdebug.o \
freetype/src/base/ftinit.o freetype/src/base/ftbase.o \ freetype/src/base/ftinit.o freetype/src/base/ftbase.o \