- 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
parent ed8f1ec8db
commit 7e4504f9d6
13 changed files with 158 additions and 102 deletions

View file

@ -1,3 +1,9 @@
September 30, 2009 (Changes by Graf Zahl)
- 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.
September 29, 2009 September 29, 2009
- Fixed: Alt+F4 no longer quit the program. - Fixed: Alt+F4 no longer quit the program.

View file

@ -49,7 +49,7 @@ public:
FWarpTexture (FTexture *source); FWarpTexture (FTexture *source);
~FWarpTexture (); ~FWarpTexture ();
virtual int CopyTrueColorPixels(FBitmap *bmp, int x, int y, int w=-1, int h=-1, int rotate=0, FCopyInfo *inf = NULL); virtual int CopyTrueColorPixels(FBitmap *bmp, int x, int y, int rotate=0, FCopyInfo *inf = NULL);
const BYTE *GetColumn (unsigned int column, const Span **spans_out); const BYTE *GetColumn (unsigned int column, const Span **spans_out);
const BYTE *GetPixels (); const BYTE *GetPixels ();
void Unload (); void Unload ();
@ -93,8 +93,6 @@ public:
void Unload (); void Unload ();
bool CheckModified (); bool CheckModified ();
void RenderView (AActor *viewpoint, int fov); void RenderView (AActor *viewpoint, int fov);
void RenderGLView(AActor *viewpoint, int fov);
void NeedUpdate() { bNeedsUpdate=true; }
protected: protected:
DSimpleCanvas *Canvas; DSimpleCanvas *Canvas;

View file

@ -280,7 +280,7 @@ static const CopyFunc copyfuncs[][9]={
// Clips the copy area for CopyPixelData functions // 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, const BYTE *&patch, int &srcwidth, int &srcheight,
int &pstep_x, int &pstep_y, int rotate) 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_x;
int step_y; int step_y;
assert(cr != NULL);
// First adjust the settings for the intended rotation // First adjust the settings for the intended rotation
switch (rotate) switch (rotate)
{ {
@ -362,35 +363,71 @@ bool ClipCopyPixelRect(int texwidth, int texheight, int &originx, int &originy,
pstep_y = step_y; pstep_y = step_y;
// clip source rectangle to destination // clip source rectangle to destination
if (originx<0) if (originx < cr->x)
{ {
srcwidth+=originx; int skip = cr->x - originx;
patch-=originx*step_x;
originx=0; srcwidth -= skip;
patch +=skip * step_x;
originx = cr->x;
if (srcwidth<=0) return false; 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 (srcwidth<=0) return false;
} }
if (originy<0) if (originy < cr->y)
{ {
srcheight+=originy; int skip = cr->y - originy;
patch-=originy*step_y;
originy=0; srcheight -= skip;
if (srcheight<=0) return false; 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; srcheight = cr->y + cr->height - originy;
if (srcheight<=0) return false; if (srcheight <= 0) return false;
} }
return true; 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 // 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, 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) 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; BYTE *buffer = data + 4 * originx + Pitch * originy;
int op = inf==NULL? OP_COPY : inf->op; 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, 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) 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; BYTE *buffer = data + 4*originx + Pitch*originy;
PalEntry penew[256]; PalEntry penew[256];
@ -485,9 +522,9 @@ void FBitmap::CopyPixelData(int originx, int originy, const BYTE * patch, int sr
void FBitmap::Zero() void FBitmap::Zero()
{ {
BYTE *buffer = data; 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; buffer += Pitch;
} }
} }

View file

@ -41,6 +41,13 @@
struct FCopyInfo; struct FCopyInfo;
struct FClipRect
{
int x, y, width, height;
bool Intersect(int ix, int iy, int iw, int ih);
};
class FBitmap class FBitmap
{ {
protected: protected:
@ -49,6 +56,8 @@ protected:
int Height; int Height;
int Pitch; int Pitch;
bool FreeBuffer; bool FreeBuffer;
FClipRect ClipRect;
public: public:
FBitmap() FBitmap()
@ -57,6 +66,7 @@ public:
Width = Height = 0; Width = Height = 0;
Pitch = 0; Pitch = 0;
FreeBuffer = false; FreeBuffer = false;
ClipRect.x = ClipRect.y = ClipRect.width = ClipRect.height = 0;
} }
FBitmap(BYTE *buffer, int pitch, int width, int height) FBitmap(BYTE *buffer, int pitch, int width, int height)
@ -67,6 +77,9 @@ public:
Width = width; Width = width;
Height = height; Height = height;
FreeBuffer = false; FreeBuffer = false;
ClipRect.x = ClipRect.y = 0;
ClipRect.width = width;
ClipRect.height = height;
} }
virtual ~FBitmap() virtual ~FBitmap()
@ -88,6 +101,9 @@ public:
Height = h; Height = h;
data = new BYTE[4*w*h]; data = new BYTE[4*w*h];
FreeBuffer = true; FreeBuffer = true;
ClipRect.x = ClipRect.y = 0;
ClipRect.width = w;
ClipRect.height = h;
return data != NULL; return data != NULL;
} }
@ -116,8 +132,29 @@ public:
return data; return data;
} }
void SetClipRect(FClipRect &clip)
{
ClipRect = clip;
}
void IntersectClipRect(FClipRect &clip)
{
ClipRect.Intersect(clip.x, clip.y, clip.width, clip.height);
}
void IntersectClipRect(int cx, int cy, int cw, int ch)
{
ClipRect.Intersect(cx, cy, cw, ch);
}
const FClipRect &GetClipRect() const
{
return ClipRect;
}
void Zero(); void Zero();
virtual void CopyPixelDataRGB(int originx, int originy, const BYTE *patch, int srcwidth, virtual void CopyPixelDataRGB(int originx, int originy, const BYTE *patch, int srcwidth,
int srcheight, int step_x, int step_y, int rotate, int ct, FCopyInfo *inf = NULL); int srcheight, int step_x, int step_y, int rotate, int ct, FCopyInfo *inf = NULL);
virtual void CopyPixelData(int originx, int originy, const BYTE * patch, int srcwidth, int srcheight, virtual void CopyPixelData(int originx, int originy, const BYTE * patch, int srcwidth, int srcheight,
@ -126,7 +163,7 @@ public:
}; };
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, const BYTE *&patch, int &srcwidth, int &srcheight,
int &step_x, int &step_y, int rotate); int &step_x, int &step_y, int rotate);

View file

@ -182,7 +182,7 @@ protected:
void DecompressDXT3 (FWadLump &lump, bool premultiplied, BYTE *tcbuf = NULL); void DecompressDXT3 (FWadLump &lump, bool premultiplied, BYTE *tcbuf = NULL);
void DecompressDXT5 (FWadLump &lump, bool premultiplied, BYTE *tcbuf = NULL); void DecompressDXT5 (FWadLump &lump, bool premultiplied, BYTE *tcbuf = NULL);
int CopyTrueColorPixels(FBitmap *bmp, int x, int y, int w, int h, int rotate, FCopyInfo *inf = NULL); int CopyTrueColorPixels(FBitmap *bmp, int x, int y, int rotate, FCopyInfo *inf = NULL);
bool UseBasePalette(); bool UseBasePalette();
friend class FTexture; friend class FTexture;
@ -874,7 +874,7 @@ void FDDSTexture::DecompressDXT5 (FWadLump &lump, bool premultiplied, BYTE *tcbu
// //
//=========================================================================== //===========================================================================
int FDDSTexture::CopyTrueColorPixels(FBitmap *bmp, int x, int y, int w, int h, int rotate, FCopyInfo *inf) int FDDSTexture::CopyTrueColorPixels(FBitmap *bmp, int x, int y, int rotate, FCopyInfo *inf)
{ {
FWadLump lump = Wads.OpenLumpNum (SourceLump); FWadLump lump = Wads.OpenLumpNum (SourceLump);
@ -899,11 +899,8 @@ int FDDSTexture::CopyTrueColorPixels(FBitmap *bmp, int x, int y, int w, int h, i
DecompressDXT5 (lump, Format == ID_DXT4, TexBuffer); DecompressDXT5 (lump, Format == ID_DXT4, TexBuffer);
} }
if (w < 0 || w > Width) w = Width;
if (h < 0 || h > Height) h = Height;
// All formats decompress to RGBA. // All formats decompress to RGBA.
bmp->CopyPixelDataRGB(x, y, TexBuffer, w, h, 4, Width*4, rotate, CF_RGBA, inf); bmp->CopyPixelDataRGB(x, y, TexBuffer, Width, Height, 4, Width*4, rotate, CF_RGBA, inf);
delete [] TexBuffer; delete [] TexBuffer;
return -1; return -1;
} }

View file

@ -168,7 +168,7 @@ public:
const BYTE *GetPixels (); const BYTE *GetPixels ();
void Unload (); void Unload ();
FTextureFormat GetFormat (); FTextureFormat GetFormat ();
int CopyTrueColorPixels(FBitmap *bmp, int x, int y, int w, int h, int rotate, FCopyInfo *inf = NULL); int CopyTrueColorPixels(FBitmap *bmp, int x, int y, int rotate, FCopyInfo *inf = NULL);
bool UseBasePalette(); bool UseBasePalette();
protected: protected:
@ -445,7 +445,7 @@ void FJPEGTexture::MakeTexture ()
// //
//=========================================================================== //===========================================================================
int FJPEGTexture::CopyTrueColorPixels(FBitmap *bmp, int x, int y, int w, int h, int rotate, FCopyInfo *inf) int FJPEGTexture::CopyTrueColorPixels(FBitmap *bmp, int x, int y, int rotate, FCopyInfo *inf)
{ {
PalEntry pe[256]; PalEntry pe[256];
@ -460,9 +460,6 @@ int FJPEGTexture::CopyTrueColorPixels(FBitmap *bmp, int x, int y, int w, int h,
cinfo.err->error_exit = JPEG_ErrorExit; cinfo.err->error_exit = JPEG_ErrorExit;
jpeg_create_decompress(&cinfo); jpeg_create_decompress(&cinfo);
if (w < 0 || w > Width) w = Width;
if (h < 0 || h > Height) h = Height;
try try
{ {
FLumpSourceMgr sourcemgr(&lump, &cinfo); FLumpSourceMgr sourcemgr(&lump, &cinfo);
@ -491,18 +488,18 @@ int FJPEGTexture::CopyTrueColorPixels(FBitmap *bmp, int x, int y, int w, int h,
switch (cinfo.out_color_space) switch (cinfo.out_color_space)
{ {
case JCS_RGB: case JCS_RGB:
bmp->CopyPixelDataRGB(x, y, buff, w, h, bmp->CopyPixelDataRGB(x, y, buff, cinfo.output_width, cinfo.output_height,
3, cinfo.output_width * cinfo.output_components, rotate, CF_RGB, inf); 3, cinfo.output_width * cinfo.output_components, rotate, CF_RGB, inf);
break; break;
case JCS_GRAYSCALE: case JCS_GRAYSCALE:
for(int i=0;i<256;i++) pe[i]=PalEntry(255,i,i,i); // default to a gray map for(int i=0;i<256;i++) pe[i]=PalEntry(255,i,i,i); // default to a gray map
bmp->CopyPixelData(x, y, buff, w, h, bmp->CopyPixelData(x, y, buff, cinfo.output_width, cinfo.output_height,
1, cinfo.output_width, rotate, pe, inf); 1, cinfo.output_width, rotate, pe, inf);
break; break;
case JCS_CMYK: case JCS_CMYK:
bmp->CopyPixelDataRGB(x, y, buff, w, h, bmp->CopyPixelDataRGB(x, y, buff, cinfo.output_width, cinfo.output_height,
4, cinfo.output_width * cinfo.output_components, rotate, CF_CMYK, inf); 4, cinfo.output_width * cinfo.output_components, rotate, CF_CMYK, inf);
break; break;

View file

@ -158,7 +158,7 @@ public:
void Unload (); void Unload ();
virtual void SetFrontSkyLayer (); virtual void SetFrontSkyLayer ();
int CopyTrueColorPixels(FBitmap *bmp, int x, int y, int w, int h, int rotate, FCopyInfo *inf = NULL); int CopyTrueColorPixels(FBitmap *bmp, int x, int y, int rotate, FCopyInfo *inf = NULL);
int GetSourceLump() { return DefinitionLump; } int GetSourceLump() { return DefinitionLump; }
protected: protected:
@ -542,13 +542,15 @@ void FMultiPatchTexture::MakeTexture ()
// //
//=========================================================================== //===========================================================================
int FMultiPatchTexture::CopyTrueColorPixels(FBitmap *bmp, int x, int y, int w, int h, int rotate, FCopyInfo *inf) int FMultiPatchTexture::CopyTrueColorPixels(FBitmap *bmp, int x, int y, int rotate, FCopyInfo *inf)
{ {
int retv = -1; int retv = -1;
FCopyInfo info; FCopyInfo info;
if (w < 0 || w > Width) w = Width; // When compositing a multipatch texture with multipatch parts
if (h < 0 || h > Height) h = Height; // drawing must be restricted to the actual area which is covered by this texture.
FClipRect saved_cr = bmp->GetClipRect();
bmp->IntersectClipRect(x, y, Width, Height);
if (inf != NULL && inf->op == OP_OVERWRITE) if (inf != NULL && inf->op == OP_OVERWRITE)
{ {
@ -568,10 +570,7 @@ int FMultiPatchTexture::CopyTrueColorPixels(FBitmap *bmp, int x, int y, int w, i
if (Parts[i].Translation != NULL) if (Parts[i].Translation != NULL)
{ {
// Using a translation forces downconversion to the base palette // Using a translation forces downconversion to the base palette
ret = Parts[i].Texture->CopyTrueColorTranslated(bmp, ret = Parts[i].Texture->CopyTrueColorTranslated(bmp, x+Parts[i].OriginX, y+Parts[i].OriginY, Parts[i].Rotate, Parts[i].Translation, &info);
x+Parts[i].OriginX, y+Parts[i].OriginY,
Parts[i].Texture->GetWidth(), Parts[i].Texture->GetHeight(),
Parts[i].Rotate, Parts[i].Translation, &info);
} }
else else
{ {
@ -599,10 +598,7 @@ int FMultiPatchTexture::CopyTrueColorPixels(FBitmap *bmp, int x, int y, int w, i
info.blend = BLEND_OVERLAY; info.blend = BLEND_OVERLAY;
} }
} }
ret = Parts[i].Texture->CopyTrueColorPixels(bmp, ret = Parts[i].Texture->CopyTrueColorPixels(bmp, x+Parts[i].OriginX, y+Parts[i].OriginY, Parts[i].Rotate, &info);
x+Parts[i].OriginX, y+Parts[i].OriginY,
Parts[i].Texture->GetWidth(), Parts[i].Texture->GetHeight(),
Parts[i].Rotate, &info);
} }
} }
else else
@ -615,15 +611,15 @@ int FMultiPatchTexture::CopyTrueColorPixels(FBitmap *bmp, int x, int y, int w, i
if (bmp1.Create(Parts[i].Texture->GetWidth(), Parts[i].Texture->GetHeight())) if (bmp1.Create(Parts[i].Texture->GetWidth(), Parts[i].Texture->GetHeight()))
{ {
Parts[i].Texture->CopyTrueColorPixels(&bmp1, 0, 0); Parts[i].Texture->CopyTrueColorPixels(&bmp1, 0, 0);
bmp->CopyPixelDataRGB( bmp->CopyPixelDataRGB(x+Parts[i].OriginX, y+Parts[i].OriginY, bmp1.GetPixels(),
x+Parts[i].OriginX, y+Parts[i].OriginY, bmp1.GetPixels(), bmp1.GetWidth(), bmp1.GetHeight(), 4, bmp1.GetPitch()*4, Parts[i].Rotate, CF_BGRA, inf);
bmp1.GetWidth(), bmp1.GetHeight(),
4, bmp1.GetPitch()*4, Parts[i].Rotate, CF_BGRA, inf);
} }
} }
if (ret > retv) retv = ret; if (ret > retv) retv = ret;
} }
// Restore previous clipping rectangle.
bmp->SetClipRect(saved_cr);
return retv; return retv;
} }

View file

@ -91,7 +91,7 @@ public:
void Unload (); void Unload ();
FTextureFormat GetFormat (); FTextureFormat GetFormat ();
int CopyTrueColorPixels(FBitmap *bmp, int x, int y, int w, int h, int rotate, FCopyInfo *inf = NULL); int CopyTrueColorPixels(FBitmap *bmp, int x, int y, int rotate, FCopyInfo *inf = NULL);
bool UseBasePalette(); bool UseBasePalette();
protected: protected:
@ -543,7 +543,7 @@ void FPCXTexture::MakeTexture()
// //
//=========================================================================== //===========================================================================
int FPCXTexture::CopyTrueColorPixels(FBitmap *bmp, int x, int y, int w, int h, int rotate, FCopyInfo *inf) int FPCXTexture::CopyTrueColorPixels(FBitmap *bmp, int x, int y, int rotate, FCopyInfo *inf)
{ {
PalEntry pe[256]; PalEntry pe[256];
PCXHeader header; PCXHeader header;
@ -556,9 +556,6 @@ int FPCXTexture::CopyTrueColorPixels(FBitmap *bmp, int x, int y, int w, int h, i
bitcount = header.bitsPerPixel * header.numColorPlanes; bitcount = header.bitsPerPixel * header.numColorPlanes;
if (w < 0 || w > Width) w = Width;
if (h < 0 || h > Height) h = Height;
if (bitcount < 24) if (bitcount < 24)
{ {
Pixels = new BYTE[Width*Height]; Pixels = new BYTE[Width*Height];
@ -600,13 +597,13 @@ int FPCXTexture::CopyTrueColorPixels(FBitmap *bmp, int x, int y, int w, int h, i
lump.Seek(sizeof(header), SEEK_SET); lump.Seek(sizeof(header), SEEK_SET);
ReadPCX8bits (Pixels, lump, &header); ReadPCX8bits (Pixels, lump, &header);
} }
bmp->CopyPixelData(x, y, Pixels, w, h, 1, Width, rotate, pe, inf); bmp->CopyPixelData(x, y, Pixels, Width, Height, 1, Width, rotate, pe, inf);
} }
else else
{ {
Pixels = new BYTE[Width*Height * 3]; Pixels = new BYTE[Width*Height * 3];
ReadPCX24bits (Pixels, lump, &header, 3); ReadPCX24bits (Pixels, lump, &header, 3);
bmp->CopyPixelDataRGB(x, y, Pixels, w, h, 3, Width*3, rotate, CF_RGB, inf); bmp->CopyPixelDataRGB(x, y, Pixels, Width, Height, 3, Width*3, rotate, CF_RGB, inf);
} }
delete [] Pixels; delete [] Pixels;
return 0; return 0;

View file

@ -58,7 +58,7 @@ public:
const BYTE *GetPixels (); const BYTE *GetPixels ();
void Unload (); void Unload ();
FTextureFormat GetFormat (); FTextureFormat GetFormat ();
int CopyTrueColorPixels(FBitmap *bmp, int x, int y, int w, int h, int rotate, FCopyInfo *inf = NULL); int CopyTrueColorPixels(FBitmap *bmp, int x, int y, int rotate, FCopyInfo *inf = NULL);
bool UseBasePalette(); bool UseBasePalette();
protected: protected:
@ -583,7 +583,7 @@ void FPNGTexture::MakeTexture ()
// //
//=========================================================================== //===========================================================================
int FPNGTexture::CopyTrueColorPixels(FBitmap *bmp, int x, int y, int w, int h, int rotate, FCopyInfo *inf) int FPNGTexture::CopyTrueColorPixels(FBitmap *bmp, int x, int y, int rotate, FCopyInfo *inf)
{ {
// Parse pre-IDAT chunks. I skip the CRCs. Is that bad? // Parse pre-IDAT chunks. I skip the CRCs. Is that bad?
PalEntry pe[256]; PalEntry pe[256];
@ -593,9 +593,6 @@ int FPNGTexture::CopyTrueColorPixels(FBitmap *bmp, int x, int y, int w, int h, i
int pixwidth = Width * bpp[ColorType]; int pixwidth = Width * bpp[ColorType];
int transpal = false; int transpal = false;
if (w < 0 || w > Width) w = Width;
if (h < 0 || h > Height) h = Height;
if (SourceLump >= 0) if (SourceLump >= 0)
{ {
lump = new FWadLump(Wads.OpenLumpNum(SourceLump)); lump = new FWadLump(Wads.OpenLumpNum(SourceLump));
@ -654,20 +651,20 @@ int FPNGTexture::CopyTrueColorPixels(FBitmap *bmp, int x, int y, int w, int h, i
{ {
case 0: case 0:
case 3: case 3:
bmp->CopyPixelData(x, y, Pixels, w, h, 1, Width, rotate, pe, inf); bmp->CopyPixelData(x, y, Pixels, Width, Height, 1, Width, rotate, pe, inf);
break; break;
case 2: case 2:
bmp->CopyPixelDataRGB(x, y, Pixels, w, h, 3, pixwidth, rotate, CF_RGB, inf); bmp->CopyPixelDataRGB(x, y, Pixels, Width, Height, 3, pixwidth, rotate, CF_RGB, inf);
break; break;
case 4: case 4:
bmp->CopyPixelDataRGB(x, y, Pixels, w, h, 2, pixwidth, rotate, CF_IA, inf); bmp->CopyPixelDataRGB(x, y, Pixels, Width, Height, 2, pixwidth, rotate, CF_IA, inf);
transpal = -1; transpal = -1;
break; break;
case 6: case 6:
bmp->CopyPixelDataRGB(x, y, Pixels, w, h, 4, pixwidth, rotate, CF_RGBA, inf); bmp->CopyPixelDataRGB(x, y, Pixels, Width, Height, 4, pixwidth, rotate, CF_RGBA, inf);
transpal = -1; transpal = -1;
break; break;

View file

@ -316,8 +316,9 @@ void FTexture::CopyToBlock (BYTE *dest, int dwidth, int dheight, int xpos, int y
int srcheight = Height; int srcheight = Height;
int step_x = Height; int step_x = Height;
int step_y = 1; int step_y = 1;
FClipRect cr = {0, 0, dwidth, dheight};
if (ClipCopyPixelRect(dwidth, dheight, xpos, ypos, pixels, srcwidth, srcheight, step_x, step_y, rotate)) if (ClipCopyPixelRect(&cr, xpos, ypos, pixels, srcwidth, srcheight, step_x, step_y, rotate))
{ {
dest += ypos + dheight * xpos; dest += ypos + dheight * xpos;
if (translation == NULL) if (translation == NULL)
@ -498,7 +499,7 @@ void FTexture::FillBuffer(BYTE *buff, int pitch, int height, FTextureFormat fmt)
{ {
FCopyInfo inf = {OP_OVERWRITE, }; FCopyInfo inf = {OP_OVERWRITE, };
FBitmap bmp(buff, pitch, pitch/4, height); FBitmap bmp(buff, pitch, pitch/4, height);
CopyTrueColorPixels(&bmp, 0, 0, -1, -1, 0, &inf); CopyTrueColorPixels(&bmp, 0, 0, 0, &inf);
break; break;
} }
@ -519,23 +520,19 @@ void FTexture::FillBuffer(BYTE *buff, int pitch, int height, FTextureFormat fmt)
// //
//=========================================================================== //===========================================================================
int FTexture::CopyTrueColorPixels(FBitmap *bmp, int x, int y, int w, int h, int rotate, FCopyInfo *inf) int FTexture::CopyTrueColorPixels(FBitmap *bmp, int x, int y, int rotate, FCopyInfo *inf)
{ {
PalEntry *palette = screen->GetPalette(); PalEntry *palette = screen->GetPalette();
for(int i=1;i<256;i++) palette[i].a = 255; // set proper alpha values for(int i=1;i<256;i++) palette[i].a = 255; // set proper alpha values
if (w < 0 || w > Width) w = Width; bmp->CopyPixelData(x, y, GetPixels(), Width, Height, Height, 1, rotate, palette, inf);
if (h < 0 || h > Height) h = Height;
bmp->CopyPixelData(x, y, GetPixels(), w, h, Height, 1, rotate, palette, inf);
for(int i=1;i<256;i++) palette[i].a = 0; for(int i=1;i<256;i++) palette[i].a = 0;
return 0; return 0;
} }
int FTexture::CopyTrueColorTranslated(FBitmap *bmp, int x, int y, int w, int h, int rotate, FRemapTable *remap, FCopyInfo *inf) int FTexture::CopyTrueColorTranslated(FBitmap *bmp, int x, int y, int rotate, FRemapTable *remap, FCopyInfo *inf)
{ {
PalEntry *palette = remap->Palette; PalEntry *palette = remap->Palette;
if (w < 0 || w > Width) w = Width; bmp->CopyPixelData(x, y, GetPixels(), Width, Height, Height, 1, rotate, palette, inf);
if (h < 0 || h > Height) h = Height;
bmp->CopyPixelData(x, y, GetPixels(), w, h, Height, 1, rotate, palette, inf);
return 0; return 0;
} }

View file

@ -151,8 +151,8 @@ public:
// Returns the whole texture, stored in column-major order // Returns the whole texture, stored in column-major order
virtual const BYTE *GetPixels () = 0; virtual const BYTE *GetPixels () = 0;
virtual int CopyTrueColorPixels(FBitmap *bmp, int x, int y, int w=-1, int h=-1, int rotate=0, FCopyInfo *inf = NULL); virtual int CopyTrueColorPixels(FBitmap *bmp, int x, int y, int rotate=0, FCopyInfo *inf = NULL);
int CopyTrueColorTranslated(FBitmap *bmp, int x, int y,int w, int h, int rotate, FRemapTable *remap, FCopyInfo *inf = NULL); int CopyTrueColorTranslated(FBitmap *bmp, int x, int y, int rotate, FRemapTable *remap, FCopyInfo *inf = NULL);
virtual bool UseBasePalette(); virtual bool UseBasePalette();
virtual int GetSourceLump() { return SourceLump; } virtual int GetSourceLump() { return SourceLump; }
virtual FTexture *GetRedirect(bool wantwarped); virtual FTexture *GetRedirect(bool wantwarped);

View file

@ -86,7 +86,7 @@ public:
void Unload (); void Unload ();
FTextureFormat GetFormat (); FTextureFormat GetFormat ();
int CopyTrueColorPixels(FBitmap *bmp, int x, int y, int w, int h, int rotate, FCopyInfo *inf = NULL); int CopyTrueColorPixels(FBitmap *bmp, int x, int y, int rotate, FCopyInfo *inf = NULL);
bool UseBasePalette(); bool UseBasePalette();
protected: protected:
@ -487,12 +487,12 @@ void FTGATexture::MakeTexture ()
// //
//=========================================================================== //===========================================================================
int FTGATexture::CopyTrueColorPixels(FBitmap *bmp, int x, int y, int w, int h, int rotate, FCopyInfo *inf) int FTGATexture::CopyTrueColorPixels(FBitmap *bmp, int x, int y, int rotate, FCopyInfo *inf)
{ {
PalEntry pe[256]; PalEntry pe[256];
FWadLump lump = Wads.OpenLumpNum (SourceLump); FWadLump lump = Wads.OpenLumpNum (SourceLump);
TGAHeader hdr; TGAHeader hdr;
WORD wr; WORD w;
BYTE r,g,b,a; BYTE r,g,b,a;
BYTE * sbuffer; BYTE * sbuffer;
int transval = 0; int transval = 0;
@ -500,9 +500,6 @@ int FTGATexture::CopyTrueColorPixels(FBitmap *bmp, int x, int y, int w, int h, i
lump.Read(&hdr, sizeof(hdr)); lump.Read(&hdr, sizeof(hdr));
lump.Seek(hdr.id_len, SEEK_CUR); lump.Seek(hdr.id_len, SEEK_CUR);
if (w < 0 || w > Width) w = Width;
if (h < 0 || h > Height) h = Height;
hdr.width = LittleShort(hdr.width); hdr.width = LittleShort(hdr.width);
hdr.height = LittleShort(hdr.height); hdr.height = LittleShort(hdr.height);
hdr.cm_first = LittleShort(hdr.cm_first); hdr.cm_first = LittleShort(hdr.cm_first);
@ -517,10 +514,10 @@ int FTGATexture::CopyTrueColorPixels(FBitmap *bmp, int x, int y, int w, int h, i
{ {
case 15: case 15:
case 16: case 16:
lump >> wr; lump >> w;
r = (wr & 0x001F) << 3; r = (w & 0x001F) << 3;
g = (wr & 0x03E0) >> 2; g = (w & 0x03E0) >> 2;
b = (wr & 0x7C00) >> 7; b = (w & 0x7C00) >> 7;
a = 255; a = 255;
break; break;
@ -575,7 +572,7 @@ int FTGATexture::CopyTrueColorPixels(FBitmap *bmp, int x, int y, int w, int h, i
switch (hdr.img_type & 7) switch (hdr.img_type & 7)
{ {
case 1: // paletted case 1: // paletted
bmp->CopyPixelData(x, y, ptr, w, h, step_x, Pitch, rotate, pe, inf); bmp->CopyPixelData(x, y, ptr, Width, Height, step_x, Pitch, rotate, pe, inf);
break; break;
case 2: // RGB case 2: // RGB
@ -583,21 +580,21 @@ int FTGATexture::CopyTrueColorPixels(FBitmap *bmp, int x, int y, int w, int h, i
{ {
case 15: case 15:
case 16: case 16:
bmp->CopyPixelDataRGB(x, y, ptr, w, h, step_x, Pitch, rotate, CF_RGB555, inf); bmp->CopyPixelDataRGB(x, y, ptr, Width, Height, step_x, Pitch, rotate, CF_RGB555, inf);
break; break;
case 24: case 24:
bmp->CopyPixelDataRGB(x, y, ptr, w, h, step_x, Pitch, rotate, CF_BGR, inf); bmp->CopyPixelDataRGB(x, y, ptr, Width, Height, step_x, Pitch, rotate, CF_BGR, inf);
break; break;
case 32: case 32:
if ((hdr.img_desc&15)!=8) // 32 bits without a valid alpha channel if ((hdr.img_desc&15)!=8) // 32 bits without a valid alpha channel
{ {
bmp->CopyPixelDataRGB(x, y, ptr, w, h, step_x, Pitch, rotate, CF_BGR, inf); bmp->CopyPixelDataRGB(x, y, ptr, Width, Height, step_x, Pitch, rotate, CF_BGR, inf);
} }
else else
{ {
bmp->CopyPixelDataRGB(x, y, ptr, w, h, step_x, Pitch, rotate, CF_BGRA, inf); bmp->CopyPixelDataRGB(x, y, ptr, Width, Height, step_x, Pitch, rotate, CF_BGRA, inf);
transval = -1; transval = -1;
} }
break; break;
@ -612,11 +609,11 @@ int FTGATexture::CopyTrueColorPixels(FBitmap *bmp, int x, int y, int w, int h, i
{ {
case 8: case 8:
for(int i=0;i<256;i++) pe[i]=PalEntry(255,i,i,i); // gray map for(int i=0;i<256;i++) pe[i]=PalEntry(255,i,i,i); // gray map
bmp->CopyPixelData(x, y, ptr, w, h, step_x, Pitch, rotate, pe, inf); bmp->CopyPixelData(x, y, ptr, Width, Height, step_x, Pitch, rotate, pe, inf);
break; break;
case 16: case 16:
bmp->CopyPixelDataRGB(x, y, ptr, w, h, step_x, Pitch, rotate, CF_I16, inf); bmp->CopyPixelDataRGB(x, y, ptr, Width, Height, step_x, Pitch, rotate, CF_I16, inf);
break; break;
default: default:

View file

@ -242,8 +242,8 @@ FTexture *FWarpTexture::GetRedirect(bool wantwarped)
// //
//========================================================================== //==========================================================================
int FWarpTexture::CopyTrueColorPixels(FBitmap *bmp, int x, int y, int w, int h, int rotate, FCopyInfo *inf) int FWarpTexture::CopyTrueColorPixels(FBitmap *bmp, int x, int y, int rotate, FCopyInfo *inf)
{ {
return SourcePic->CopyTrueColorPixels(bmp, x, y, w, h, rotate, inf); return SourcePic->CopyTrueColorPixels(bmp, x, y, rotate, inf);
} }