- Fixed: Coordinate handling for multipatch texture compositing was not correct

for true color. Instead of using a clipping rectangle on the destination it
  tried to alter the source offsets which produced incorrect results for
  mirrored or rotated patches.


SVN r1889 (trunk)
This commit is contained in:
Christoph Oelckers 2009-09-30 10:41:24 +00:00
commit 7e4504f9d6
13 changed files with 158 additions and 102 deletions

View file

@ -280,7 +280,7 @@ static const CopyFunc copyfuncs[][9]={
// Clips the copy area for CopyPixelData functions
//
//===========================================================================
bool ClipCopyPixelRect(int texwidth, int texheight, int &originx, int &originy,
bool ClipCopyPixelRect(const FClipRect *cr, int &originx, int &originy,
const BYTE *&patch, int &srcwidth, int &srcheight,
int &pstep_x, int &pstep_y, int rotate)
{
@ -290,6 +290,7 @@ bool ClipCopyPixelRect(int texwidth, int texheight, int &originx, int &originy,
int step_x;
int step_y;
assert(cr != NULL);
// First adjust the settings for the intended rotation
switch (rotate)
{
@ -362,35 +363,71 @@ bool ClipCopyPixelRect(int texwidth, int texheight, int &originx, int &originy,
pstep_y = step_y;
// clip source rectangle to destination
if (originx<0)
if (originx < cr->x)
{
srcwidth+=originx;
patch-=originx*step_x;
originx=0;
int skip = cr->x - originx;
srcwidth -= skip;
patch +=skip * step_x;
originx = cr->x;
if (srcwidth<=0) return false;
}
if (originx+srcwidth>texwidth)
if (originx + srcwidth > cr->x + cr->width)
{
srcwidth=texwidth-originx;
srcwidth = cr->x + cr->width - originx;
if (srcwidth<=0) return false;
}
if (originy<0)
if (originy < cr->y)
{
srcheight+=originy;
patch-=originy*step_y;
originy=0;
if (srcheight<=0) return false;
int skip = cr->y - originy;
srcheight -= skip;
patch += skip*step_y;
originy = cr->y;
if (srcheight <= 0) return false;
}
if (originy+srcheight>texheight)
if (originy + srcheight > cr->y + cr->height)
{
srcheight=texheight-originy;
if (srcheight<=0) return false;
srcheight = cr->y + cr->height - originy;
if (srcheight <= 0) return false;
}
return true;
}
//===========================================================================
//
//
//
//===========================================================================
bool FClipRect::Intersect(int ix, int iy, int iw, int ih)
{
if (ix > x)
{
width -= (ix-x);
x = ix;
}
else
{
iw -= (x-ix);
}
if (iy > y)
{
height -= (iy-y);
y = iy;
}
else
{
ih -= (x-ih);
}
if (iw < width) width = iw;
if (ih < height) height = ih;
return width > 0 && height > 0;
}
//===========================================================================
//
// True Color texture copy function
@ -399,7 +436,7 @@ bool ClipCopyPixelRect(int texwidth, int texheight, int &originx, int &originy,
void FBitmap::CopyPixelDataRGB(int originx, int originy, const BYTE *patch, int srcwidth,
int srcheight, int step_x, int step_y, int rotate, int ct, FCopyInfo *inf)
{
if (ClipCopyPixelRect(Width, Height, originx, originy, patch, srcwidth, srcheight, step_x, step_y, rotate))
if (ClipCopyPixelRect(&ClipRect, originx, originy, patch, srcwidth, srcheight, step_x, step_y, rotate))
{
BYTE *buffer = data + 4 * originx + Pitch * originy;
int op = inf==NULL? OP_COPY : inf->op;
@ -460,7 +497,7 @@ static const CopyPalettedFunc copypalettedfuncs[]=
void FBitmap::CopyPixelData(int originx, int originy, const BYTE * patch, int srcwidth, int srcheight,
int step_x, int step_y, int rotate, PalEntry * palette, FCopyInfo *inf)
{
if (ClipCopyPixelRect(Width, Height, originx, originy, patch, srcwidth, srcheight, step_x, step_y, rotate))
if (ClipCopyPixelRect(&ClipRect, originx, originy, patch, srcwidth, srcheight, step_x, step_y, rotate))
{
BYTE *buffer = data + 4*originx + Pitch*originy;
PalEntry penew[256];
@ -485,9 +522,9 @@ void FBitmap::CopyPixelData(int originx, int originy, const BYTE * patch, int sr
void FBitmap::Zero()
{
BYTE *buffer = data;
for (int y = 0; y < Height; ++y)
for (int y = ClipRect.y; y < ClipRect.height; ++y)
{
memset(buffer, 0, Width*4);
memset(buffer + ClipRect.x, 0, ClipRect.width*4);
buffer += Pitch;
}
}