diff --git a/docs/rh-log.txt b/docs/rh-log.txt index 0e0e49d5a..5574dbfd5 100644 --- a/docs/rh-log.txt +++ b/docs/rh-log.txt @@ -1,3 +1,6 @@ +April 16, 2008 (Changes by Graf Zahl) +- Made translation support for multipatch textures operational. + April 15, 2008 - Added support for the GUS patch format's scale_frequency and scale_factor parameters. These seem to be used primarily to restrict percussion diff --git a/src/g_doom/doom_sbar.cpp b/src/g_doom/doom_sbar.cpp index 899de629f..a0e9e380a 100644 --- a/src/g_doom/doom_sbar.cpp +++ b/src/g_doom/doom_sbar.cpp @@ -211,7 +211,7 @@ private: void Unload (); ~FDoomStatusBarTexture (); void SetPlayerRemap(FRemapTable *remap); - int CopyTrueColorPixels(FBitmap *bmp, int x, int y, int rotate); + int CopyTrueColorPixels(FBitmap *bmp, int x, int y, int rotate, FCopyInfo *inf = NULL); FTextureFormat GetFormat() { @@ -1093,11 +1093,11 @@ void DDoomStatusBar::FDoomStatusBarTexture::MakeTexture () if (multiplayer) DrawToBar("STFBANY", 143, 1, STFBRemap? STFBRemap->Remap : NULL); } -int DDoomStatusBar::FDoomStatusBarTexture::CopyTrueColorPixels(FBitmap *bmp, int x, int y, int rotate) +int DDoomStatusBar::FDoomStatusBarTexture::CopyTrueColorPixels(FBitmap *bmp, int x, int y, int rotate, FCopyInfo *inf) { FTexture *tex; - // rotate is never used here + // rotate and inf are never used here BaseTexture->CopyTrueColorPixels(bmp, x, y); if (!deathmatch) { diff --git a/src/r_data.h b/src/r_data.h index 6771fae4e..94ae3ab46 100644 --- a/src/r_data.h +++ b/src/r_data.h @@ -94,7 +94,7 @@ public: void Unload (); virtual void SetFrontSkyLayer (); - int CopyTrueColorPixels(FBitmap *bmp, int x, int y, int rotate); + int CopyTrueColorPixels(FBitmap *bmp, int x, int y, int rotate, FCopyInfo *inf = NULL); int GetSourceLump() { return DefinitionLump; } protected: @@ -112,7 +112,6 @@ protected: FTexture *Texture; TexPart(); - ~TexPart(); }; int NumParts; @@ -263,7 +262,7 @@ public: const BYTE *GetPixels (); void Unload (); FTextureFormat GetFormat (); - int CopyTrueColorPixels(FBitmap *bmp, int x, int y, int rotate); + int CopyTrueColorPixels(FBitmap *bmp, int x, int y, int rotate, FCopyInfo *inf = NULL); bool UseBasePalette(); int GetSourceLump() { return SourceLump; } @@ -331,7 +330,7 @@ protected: void DecompressDXT3 (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 rotate); + int CopyTrueColorPixels(FBitmap *bmp, int x, int y, int rotate, FCopyInfo *inf = NULL); bool UseBasePalette(); friend class FTexture; @@ -347,7 +346,7 @@ public: const BYTE *GetPixels (); void Unload (); FTextureFormat GetFormat (); - int CopyTrueColorPixels(FBitmap *bmp, int x, int y, int rotate); + int CopyTrueColorPixels(FBitmap *bmp, int x, int y, int rotate, FCopyInfo *inf = NULL); bool UseBasePalette(); int GetSourceLump() { return SourceLump; } @@ -399,7 +398,7 @@ public: void Unload (); FTextureFormat GetFormat (); - int CopyTrueColorPixels(FBitmap *bmp, int x, int y, int rotate); + int CopyTrueColorPixels(FBitmap *bmp, int x, int y, int rotate, FCopyInfo *inf = NULL); bool UseBasePalette(); int GetSourceLump() { return SourceLump; } @@ -456,7 +455,7 @@ public: void Unload (); FTextureFormat GetFormat (); - int CopyTrueColorPixels(FBitmap *bmp, int x, int y, int rotate); + int CopyTrueColorPixels(FBitmap *bmp, int x, int y, int rotate, FCopyInfo *inf = NULL); bool UseBasePalette(); int GetSourceLump() { return SourceLump; } diff --git a/src/r_defs.h b/src/r_defs.h index 4da1ff2a1..3aa1319d0 100644 --- a/src/r_defs.h +++ b/src/r_defs.h @@ -87,6 +87,7 @@ struct line_t; class player_s; class FScanner; class FBitmap; +struct FCopyInfo; // // The SECTORS record, at runtime. @@ -795,7 +796,7 @@ public: // Returns the whole texture, stored in column-major order virtual const BYTE *GetPixels () = 0; - virtual int CopyTrueColorPixels(FBitmap *bmp, int x, int y, int rotate=0); + virtual int CopyTrueColorPixels(FBitmap *bmp, int x, int y, int rotate=0, FCopyInfo *inf = NULL); int CopyTrueColorTranslated(FBitmap *bmp, int x, int y, int rotate, FRemapTable *remap); virtual bool UseBasePalette(); virtual int GetSourceLump() { return -1; } diff --git a/src/textures/bitmap.cpp b/src/textures/bitmap.cpp index fb3657bf1..6fbc9824a 100644 --- a/src/textures/bitmap.cpp +++ b/src/textures/bitmap.cpp @@ -368,14 +368,14 @@ 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) + 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)) { BYTE *buffer = data + 4 * originx + Pitch * originy; for (int y=0;yblend) + { + // The palette's alpha is inverted so in order to use the + // True Color copy functions it has to be inverted temporarily. + memcpy(penew, palette, 4*256); + for(int i=0;i<256;i++) penew[i].a = 255-penew[i].a; + copyfuncs[CF_PalEntry]((BYTE*)penew, (BYTE*)penew, 256, 4, inf); + for(int i=0;i<256;i++) penew[i].a = 255-penew[i].a; + palette = penew; + } + for (y=0;yCopyPixelDataRGB(x, y, TexBuffer, Width, Height, 4, Width*4, rotate, CF_RGBA); + bmp->CopyPixelDataRGB(x, y, TexBuffer, Width, Height, 4, Width*4, rotate, CF_RGBA, inf); delete [] TexBuffer; return -1; } diff --git a/src/textures/jpegtexture.cpp b/src/textures/jpegtexture.cpp index 4d982caf0..9c6f9ba95 100644 --- a/src/textures/jpegtexture.cpp +++ b/src/textures/jpegtexture.cpp @@ -333,7 +333,7 @@ void FJPEGTexture::MakeTexture () // //=========================================================================== -int FJPEGTexture::CopyTrueColorPixels(FBitmap *bmp, int x, int y, int rotate) +int FJPEGTexture::CopyTrueColorPixels(FBitmap *bmp, int x, int y, int rotate, FCopyInfo *inf) { PalEntry pe[256]; @@ -377,18 +377,18 @@ int FJPEGTexture::CopyTrueColorPixels(FBitmap *bmp, int x, int y, int rotate) { case JCS_RGB: bmp->CopyPixelDataRGB(x, y, buff, cinfo.output_width, cinfo.output_height, - 3, cinfo.output_width * cinfo.output_components, rotate, CF_RGB); + 3, cinfo.output_width * cinfo.output_components, rotate, CF_RGB, inf); break; case JCS_GRAYSCALE: for(int i=0;i<256;i++) pe[i]=PalEntry(0,i,i,i); // default to a gray map bmp->CopyPixelData(x, y, buff, cinfo.output_width, cinfo.output_height, - 1, cinfo.output_width, rotate, pe); + 1, cinfo.output_width, rotate, pe, inf); break; case JCS_CMYK: bmp->CopyPixelDataRGB(x, y, buff, cinfo.output_width, cinfo.output_height, - 4, cinfo.output_width * cinfo.output_components, rotate, CF_CMYK); + 4, cinfo.output_width * cinfo.output_components, rotate, CF_CMYK, inf); break; default: diff --git a/src/textures/multipatchtexture.cpp b/src/textures/multipatchtexture.cpp index c9ef4edf8..0d4fd02a1 100644 --- a/src/textures/multipatchtexture.cpp +++ b/src/textures/multipatchtexture.cpp @@ -179,6 +179,11 @@ FMultiPatchTexture::~FMultiPatchTexture () Unload (); if (Parts != NULL) { + for(int i=0; iRemap; default: - if (blend >= BLEND_DESATURATE1 && blend <= BLEND_DESATURATE31) + if (blend.r >= BLEND_DESATURATE1 && blend.r <= BLEND_DESATURATE31) { return DesaturateColormap[blend - BLEND_DESATURATE1]; } @@ -376,16 +381,18 @@ void FMultiPatchTexture::MakeTexture () // //=========================================================================== -int FMultiPatchTexture::CopyTrueColorPixels(FBitmap *bmp, int x, int y, int rotate) +int FMultiPatchTexture::CopyTrueColorPixels(FBitmap *bmp, int x, int y, int rotate, FCopyInfo *inf) { int retv = -1; + FCopyInfo info; for(int i=0;ibComplex) + if (!Parts[i].Texture->bComplex || inf == NULL) { + memset (&info, 0, sizeof (info)); if (Parts[i].Translation != NULL) { // Using a translation forces downconversion to the base palette @@ -393,17 +400,49 @@ int FMultiPatchTexture::CopyTrueColorPixels(FBitmap *bmp, int x, int y, int rota } else { - if (Parts[i].Blend != BLEND_NONE) + PalEntry b = Parts[i].Blend; + if (b.a == 0 && b.r != BLEND_NONE) { + info.blend = EBlend(b.r); + inf = &info; } - ret = Parts[i].Texture->CopyTrueColorPixels(bmp, x+Parts[i].OriginX, y+Parts[i].OriginY, Parts[i].Rotate); + else if (b.a != 0) + { + if (b.a == 255) + { + info.blendcolor[0] = b.r * FRACUNIT / 255; + info.blendcolor[1] = b.g * FRACUNIT / 255; + info.blendcolor[2] = b.b * FRACUNIT / 255; + info.blend = BLEND_MODULATE; + inf = &info; + } + else + { + info.blendcolor[3] = b.a * FRACUNIT / 255; + info.blendcolor[0] = b.r * (FRACUNIT-info.blendcolor[3]); + info.blendcolor[1] = b.g * (FRACUNIT-info.blendcolor[3]); + info.blendcolor[2] = b.b * (FRACUNIT-info.blendcolor[3]); + + info.blend = BLEND_OVERLAY; + inf = &info; + } + } + ret = Parts[i].Texture->CopyTrueColorPixels(bmp, x+Parts[i].OriginX, y+Parts[i].OriginY, Parts[i].Rotate, inf); } } else { // If the patch is a texture with some kind of processing involved + // and being drawn with additional processing // the copying must be done in 2 steps: First create a complete image of the patch // including all processing and then copy from that intermediate image to the destination + FBitmap bmp1; + if (bmp1.Create(Parts[i].Texture->GetWidth(), Parts[i].Texture->GetHeight())) + { + Parts[i].Texture->CopyTrueColorPixels(&bmp1, 0, 0); + bmp->CopyPixelDataRGB(x+Parts[i].OriginX, y+Parts[i].OriginY, bmp1.GetPixels(), + bmp1.GetWidth(), bmp1.GetHeight(), 4, bmp1.GetPitch()*4, Parts[i].Rotate, CF_BGRA, inf); + } } if (ret > retv) retv = ret; @@ -589,19 +628,6 @@ FMultiPatchTexture::TexPart::TexPart() Blend = 0; } -//========================================================================== -// -// FMultiPatchTexture :: TexPart :: TexPart -// -//========================================================================== - -FMultiPatchTexture::TexPart::~TexPart() -{ - if (textureOwned && Texture != NULL) delete Texture; - Texture = NULL; - if (Translation != NULL) delete Translation; -} - //========================================================================== // // FTextureManager :: AddTexturesLump @@ -799,10 +825,20 @@ void FMultiPatchTexture::ParsePatch(FScanner &sc, TexPart & part) part.Texture = FTexture::CreateTexture(lumpnum, TEX_WallPatch); part.textureOwned = true; } + else if (strlen(sc.String) <= 8 && !strpbrk(sc.String, "./")) + { + int lumpnum = Wads.CheckNumForName(sc.String, ns_patches); + if (lumpnum >= 0) + { + part.Texture = FTexture::CreateTexture(lumpnum, TEX_WallPatch); + TexMan.AddTexture(part.Texture); + } + } } else { part.Texture = TexMan[texno]; + bComplex |= part.Texture->bComplex; } if (part.Texture == NULL) { @@ -844,6 +880,7 @@ void FMultiPatchTexture::ParsePatch(FScanner &sc, TexPart & part) part.Translation = NULL; part.Blend = 0; static const char *maps[] = { "inverse", "gold", "red", "green", "ice", "desaturate", NULL }; + sc.MustGetString(); int match = sc.MatchString(maps); if (match >= 0) { @@ -857,6 +894,7 @@ void FMultiPatchTexture::ParsePatch(FScanner &sc, TexPart & part) } else { + sc.UnGet(); part.Translation = new FRemapTable; part.Translation->MakeIdentity(); do @@ -916,6 +954,7 @@ void FMultiPatchTexture::ParsePatch(FScanner &sc, TexPart & part) if (!sc.CheckNumber()) { + sc.MustGetString(); part.Blend = V_GetColor(NULL, sc.String); } else @@ -1003,7 +1042,9 @@ FMultiPatchTexture::FMultiPatchTexture (FScanner &sc, int usetype) { TexPart part; ParsePatch(sc, part); - parts.Push(part); + if (part.Texture != NULL) parts.Push(part); + part.Texture = NULL; + part.Translation = NULL; } } diff --git a/src/textures/pcxtexture.cpp b/src/textures/pcxtexture.cpp index a298ff425..cd248deb8 100644 --- a/src/textures/pcxtexture.cpp +++ b/src/textures/pcxtexture.cpp @@ -419,7 +419,7 @@ void FPCXTexture::MakeTexture() // //=========================================================================== -int FPCXTexture::CopyTrueColorPixels(FBitmap *bmp, int x, int y, int rotate) +int FPCXTexture::CopyTrueColorPixels(FBitmap *bmp, int x, int y, int rotate, FCopyInfo *inf) { PalEntry pe[256]; PCXHeader header; @@ -473,13 +473,13 @@ int FPCXTexture::CopyTrueColorPixels(FBitmap *bmp, int x, int y, int rotate) lump.Seek(sizeof(header), SEEK_SET); ReadPCX8bits (Pixels, lump, &header); } - bmp->CopyPixelData(x, y, Pixels, Width, Height, 1, Width, rotate, pe); + bmp->CopyPixelData(x, y, Pixels, Width, Height, 1, Width, rotate, pe, inf); } else { Pixels = new BYTE[Width*Height * 3]; ReadPCX24bits (Pixels, lump, &header, 3); - bmp->CopyPixelDataRGB(x, y, Pixels, Width, Height, 3, Width*3, rotate, CF_RGB); + bmp->CopyPixelDataRGB(x, y, Pixels, Width, Height, 3, Width*3, rotate, CF_RGB, inf); } delete [] Pixels; return 0; diff --git a/src/textures/pngtexture.cpp b/src/textures/pngtexture.cpp index c7af9ae9c..8e36c89d1 100644 --- a/src/textures/pngtexture.cpp +++ b/src/textures/pngtexture.cpp @@ -491,7 +491,7 @@ void FPNGTexture::MakeTexture () // //=========================================================================== -int FPNGTexture::CopyTrueColorPixels(FBitmap *bmp, int x, int y, int rotate) +int FPNGTexture::CopyTrueColorPixels(FBitmap *bmp, int x, int y, int rotate, FCopyInfo *inf) { // Parse pre-IDAT chunks. I skip the CRCs. Is that bad? PalEntry pe[256]; @@ -555,20 +555,20 @@ int FPNGTexture::CopyTrueColorPixels(FBitmap *bmp, int x, int y, int rotate) { case 0: case 3: - bmp->CopyPixelData(x, y, Pixels, Width, Height, 1, Width, rotate, pe); + bmp->CopyPixelData(x, y, Pixels, Width, Height, 1, Width, rotate, pe, inf); break; case 2: - bmp->CopyPixelDataRGB(x, y, Pixels, Width, Height, 3, pixwidth, rotate, CF_RGB); + bmp->CopyPixelDataRGB(x, y, Pixels, Width, Height, 3, pixwidth, rotate, CF_RGB, inf); break; case 4: - bmp->CopyPixelDataRGB(x, y, Pixels, Width, Height, 2, pixwidth, rotate, CF_IA); + bmp->CopyPixelDataRGB(x, y, Pixels, Width, Height, 2, pixwidth, rotate, CF_IA, inf); transpal = -1; break; case 6: - bmp->CopyPixelDataRGB(x, y, Pixels, Width, Height, 4, pixwidth, rotate, CF_RGBA); + bmp->CopyPixelDataRGB(x, y, Pixels, Width, Height, 4, pixwidth, rotate, CF_RGBA, inf); transpal = -1; break; diff --git a/src/textures/texture.cpp b/src/textures/texture.cpp index 3f02f568f..4417e1b71 100644 --- a/src/textures/texture.cpp +++ b/src/textures/texture.cpp @@ -458,7 +458,7 @@ void FTexture::FillBuffer(BYTE *buff, int pitch, int height, FTextureFormat fmt) case TEX_RGB: { - FBitmap bmp(buff, pitch, pitch, height); + FBitmap bmp(buff, pitch, pitch/4, height); CopyTrueColorPixels(&bmp, 0, 0); break; } @@ -480,11 +480,11 @@ void FTexture::FillBuffer(BYTE *buff, int pitch, int height, FTextureFormat fmt) // //=========================================================================== -int FTexture::CopyTrueColorPixels(FBitmap *bmp, int x, int y, int rotate) +int FTexture::CopyTrueColorPixels(FBitmap *bmp, int x, int y, int rotate, FCopyInfo *inf) { PalEntry *palette = screen->GetPalette(); palette[0].a=255; // temporarily modify the first color's alpha - bmp->CopyPixelData(x, y, GetPixels(), Width, Height, Height, 1, rotate, palette); + bmp->CopyPixelData(x, y, GetPixels(), Width, Height, Height, 1, rotate, palette, inf); palette[0].a=0; return 0; diff --git a/src/textures/tgatexture.cpp b/src/textures/tgatexture.cpp index 3ece55557..cf5446293 100644 --- a/src/textures/tgatexture.cpp +++ b/src/textures/tgatexture.cpp @@ -385,7 +385,7 @@ void FTGATexture::MakeTexture () // //=========================================================================== -int FTGATexture::CopyTrueColorPixels(FBitmap *bmp, int x, int y, int rotate) +int FTGATexture::CopyTrueColorPixels(FBitmap *bmp, int x, int y, int rotate, FCopyInfo *inf) { PalEntry pe[256]; FWadLump lump = Wads.OpenLumpNum (SourceLump); @@ -470,7 +470,7 @@ int FTGATexture::CopyTrueColorPixels(FBitmap *bmp, int x, int y, int rotate) switch (hdr.img_type & 7) { case 1: // paletted - bmp->CopyPixelData(x, y, ptr, Width, Height, step_x, Pitch, rotate, pe); + bmp->CopyPixelData(x, y, ptr, Width, Height, step_x, Pitch, rotate, pe, inf); break; case 2: // RGB @@ -478,21 +478,21 @@ int FTGATexture::CopyTrueColorPixels(FBitmap *bmp, int x, int y, int rotate) { case 15: case 16: - bmp->CopyPixelDataRGB(x, y, ptr, Width, Height, step_x, Pitch, rotate, CF_RGB555); + bmp->CopyPixelDataRGB(x, y, ptr, Width, Height, step_x, Pitch, rotate, CF_RGB555, inf); break; case 24: - bmp->CopyPixelDataRGB(x, y, ptr, Width, Height, step_x, Pitch, rotate, CF_BGR); + bmp->CopyPixelDataRGB(x, y, ptr, Width, Height, step_x, Pitch, rotate, CF_BGR, inf); break; case 32: if ((hdr.img_desc&15)!=8) // 32 bits without a valid alpha channel { - bmp->CopyPixelDataRGB(x, y, ptr, Width, Height, step_x, Pitch, rotate, CF_BGR); + bmp->CopyPixelDataRGB(x, y, ptr, Width, Height, step_x, Pitch, rotate, CF_BGR, inf); } else { - bmp->CopyPixelDataRGB(x, y, ptr, Width, Height, step_x, Pitch, rotate, CF_BGRA); + bmp->CopyPixelDataRGB(x, y, ptr, Width, Height, step_x, Pitch, rotate, CF_BGRA, inf); transval = -1; } break; @@ -507,11 +507,11 @@ int FTGATexture::CopyTrueColorPixels(FBitmap *bmp, int x, int y, int rotate) { case 8: for(int i=0;i<256;i++) pe[i]=PalEntry(0,i,i,i); // gray map - bmp->CopyPixelData(x, y, ptr, Width, Height, step_x, Pitch, rotate, pe); + bmp->CopyPixelData(x, y, ptr, Width, Height, step_x, Pitch, rotate, pe, inf); break; case 16: - bmp->CopyPixelDataRGB(x, y, ptr, Width, Height, step_x, Pitch, rotate, CF_I16); + bmp->CopyPixelDataRGB(x, y, ptr, Width, Height, step_x, Pitch, rotate, CF_I16, inf); break; default: