diff --git a/docs/rh-log.txt b/docs/rh-log.txt index c123fe4ef..8adf718f7 100644 --- a/docs/rh-log.txt +++ b/docs/rh-log.txt @@ -1,4 +1,7 @@ April 15, 2008 (Changes by Graf Zahl) +- Changed true color texture creation to use a newly defined Bitmap class + instead of having the copy functions in the frame buffer class. +- Fixed: The WolfSS didn't have its obituary defined. - Added submission for ACS CheckPlayerCamera ACS function. - Removed FRadiusThingsIterator after discovering that VC++ misoptimized it in P_CheckPosition. Now FBlockThingsIterator is used with the distance diff --git a/src/g_doom/doom_sbar.cpp b/src/g_doom/doom_sbar.cpp index 70f8f6c20..5f5b8a051 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(BYTE *buffer, int buf_pitch, int buf_height, int x, int y, int rotate); + int CopyTrueColorPixels(FBitmap *bmp, int x, int y, int rotate); FTextureFormat GetFormat() { @@ -1093,33 +1093,33 @@ void DDoomStatusBar::FDoomStatusBarTexture::MakeTexture () if (multiplayer) DrawToBar("STFBANY", 143, 1, STBFremap? STBFremap->Remap : NULL); } -int DDoomStatusBar::FDoomStatusBarTexture::CopyTrueColorPixels(BYTE *buffer, int buf_pitch, int buf_height, int x, int y, int rotate) +int DDoomStatusBar::FDoomStatusBarTexture::CopyTrueColorPixels(FBitmap *bmp, int x, int y, int rotate) { FTexture *tex; // rotate is never used here - BaseTexture->CopyTrueColorPixels(buffer, buf_pitch, buf_height, x, y); + BaseTexture->CopyTrueColorPixels(bmp, x, y); if (!deathmatch) { tex = TexMan["STARMS"]; if (tex != NULL) { - tex->CopyTrueColorPixels(buffer, buf_pitch, buf_height, x+104, y); + tex->CopyTrueColorPixels(bmp, x+104, y); } } tex = TexMan["STTPRCNT"]; if (tex != NULL) { - tex->CopyTrueColorPixels(buffer, buf_pitch, buf_height, x+90, y+3); - tex->CopyTrueColorPixels(buffer, buf_pitch, buf_height, x+221, y+3); + tex->CopyTrueColorPixels(bmp, x+90, y+3); + tex->CopyTrueColorPixels(bmp, x+221, y+3); } if (multiplayer) { tex = TexMan["STFBANY"]; if (tex != NULL) { - tex->CopyTrueColorTranslated(buffer, buf_pitch, buf_height, x+143, y+1, STBFremap); + tex->CopyTrueColorTranslated(bmp, x+143, y+1, STBFremap); } } return -1; diff --git a/src/r_data.h b/src/r_data.h index cbc984735..39223abb5 100644 --- a/src/r_data.h +++ b/src/r_data.h @@ -94,7 +94,7 @@ public: void Unload (); virtual void SetFrontSkyLayer (); - int CopyTrueColorPixels(BYTE *buffer, int buf_pitch, int buf_height, int x, int y, int rotate); + int CopyTrueColorPixels(FBitmap *bmp, int x, int y, int rotate); int GetSourceLump() { return DefinitionLump; } protected: @@ -261,7 +261,7 @@ public: const BYTE *GetPixels (); void Unload (); FTextureFormat GetFormat (); - int CopyTrueColorPixels(BYTE *buffer, int buf_pitch, int buf_height, int x, int y, int rotate); + int CopyTrueColorPixels(FBitmap *bmp, int x, int y, int rotate); bool UseBasePalette(); int GetSourceLump() { return SourceLump; } @@ -329,7 +329,7 @@ protected: void DecompressDXT3 (FWadLump &lump, bool premultiplied, BYTE *tcbuf = NULL); void DecompressDXT5 (FWadLump &lump, bool premultiplied, BYTE *tcbuf = NULL); - int CopyTrueColorPixels(BYTE *buffer, int buf_pitch, int buf_height, int x, int y, int rotate); + int CopyTrueColorPixels(FBitmap *bmp, int x, int y, int rotate); bool UseBasePalette(); friend class FTexture; @@ -345,7 +345,7 @@ public: const BYTE *GetPixels (); void Unload (); FTextureFormat GetFormat (); - int CopyTrueColorPixels(BYTE *buffer, int buf_pitch, int buf_height, int x, int y, int rotate); + int CopyTrueColorPixels(FBitmap *bmp, int x, int y, int rotate); bool UseBasePalette(); int GetSourceLump() { return SourceLump; } @@ -397,7 +397,7 @@ public: void Unload (); FTextureFormat GetFormat (); - int CopyTrueColorPixels(BYTE *buffer, int buf_pitch, int buf_height, int x, int y, int rotate); + int CopyTrueColorPixels(FBitmap *bmp, int x, int y, int rotate); bool UseBasePalette(); int GetSourceLump() { return SourceLump; } @@ -454,7 +454,7 @@ public: void Unload (); FTextureFormat GetFormat (); - int CopyTrueColorPixels(BYTE *buffer, int buf_pitch, int buf_height, int x, int y, int rotate); + int CopyTrueColorPixels(FBitmap *bmp, int x, int y, int rotate); bool UseBasePalette(); int GetSourceLump() { return SourceLump; } diff --git a/src/r_defs.h b/src/r_defs.h index d44d1b5ae..a9df07b35 100644 --- a/src/r_defs.h +++ b/src/r_defs.h @@ -86,6 +86,7 @@ struct line_t; class player_s; class FScanner; +class FBitmap; // // The SECTORS record, at runtime. @@ -794,8 +795,8 @@ public: // Returns the whole texture, stored in column-major order virtual const BYTE *GetPixels () = 0; - virtual int CopyTrueColorPixels(BYTE *buffer, int buf_pitch, int buf_height, int x, int y, int rotate=0); - int CopyTrueColorTranslated(BYTE *buffer, int buf_pitch, int buf_height, int x, int y, FRemapTable *remap); + virtual int CopyTrueColorPixels(FBitmap *bmp, int x, int y, int rotate=0); + int CopyTrueColorTranslated(FBitmap *bmp, int x, int y, FRemapTable *remap); virtual bool UseBasePalette(); virtual int GetSourceLump() { return -1; } diff --git a/src/textures/bitmap.cpp b/src/textures/bitmap.cpp new file mode 100644 index 000000000..eea69ed23 --- /dev/null +++ b/src/textures/bitmap.cpp @@ -0,0 +1,246 @@ +/* +** bitmap.cpp +** +**--------------------------------------------------------------------------- +** Copyright 2008 Christoph Oelckers +** All rights reserved. +** +** Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions +** are met: +** +** 1. Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** 2. Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in the +** documentation and/or other materials provided with the distribution. +** 3. The name of the author may not be used to endorse or promote products +** derived from this software without specific prior written permission. +** +** THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR +** IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES +** OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. +** IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, +** INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT +** NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF +** THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +**--------------------------------------------------------------------------- +** +** +*/ + +#include "bitmap.h" +#include "templates.h" + + +//=========================================================================== +// +// multi-format pixel copy with colormap application +// requires one of the previously defined conversion classes to work +// +//=========================================================================== +template +void iCopyColors(BYTE *pout, const BYTE *pin, int count, int step) +{ + for(int i=0;i, + iCopyColors, + iCopyColors, + iCopyColors, + iCopyColors, + iCopyColors, + iCopyColors, + iCopyColors, + iCopyColors +}; + +//=========================================================================== +// +// Clips the copy area for CopyPixelData functions +// +//=========================================================================== +bool ClipCopyPixelRect(int texwidth, int texheight, int &originx, int &originy, + const BYTE *&patch, int &srcwidth, int &srcheight, + int &pstep_x, int &pstep_y, int rotate) +{ + int pixxoffset; + int pixyoffset; + + int step_x; + int step_y; + + // First adjust the settings for the intended rotation + switch (rotate) + { + default: + case 0: // normal + pixxoffset = 0; + pixyoffset = 0; + step_x = pstep_x; + step_y = pstep_y; + break; + + case 1: // rotate 90° right + pixxoffset = 0; + pixyoffset = srcheight - 1; + step_x = -pstep_y; + step_y = pstep_x; + break; + + case 2: // rotate 180° + pixxoffset = srcwidth - 1; + pixyoffset = srcheight - 1; + step_x = -pstep_x; + step_y = -pstep_y; + break; + + case 3: // rotate 90° left + pixxoffset = srcwidth - 1; + pixyoffset = 0; + step_x = pstep_y; + step_y = -pstep_x; + break; + + case 4: // flip horizontally + pixxoffset = srcwidth - 1; + pixyoffset = 0; + step_x = -pstep_x; + step_y = pstep_y; + break; + + case 5: // flip horizontally and rotate 90° right + pixxoffset = srcwidth - 1; + pixyoffset = srcheight - 1; + step_x = -pstep_y; + step_y = -pstep_x; + break; + + case 6: // flip vertically + pixxoffset = 0; + pixyoffset = srcheight - 1; + step_x = pstep_x; + step_y = -pstep_y; + break; + + case 7: // flip horizontally and rotate 90° left + pixxoffset = 0; + pixyoffset = 0; + step_x = pstep_y; + step_y = pstep_x; + break; + } + if (rotate&1) + { + int v = srcwidth; + srcwidth = srcheight; + srcheight = v; + } + + patch += pixxoffset * pstep_x + pixyoffset * pstep_y; + pstep_x = step_x; + pstep_y = step_y; + + // clip source rectangle to destination + if (originx<0) + { + srcwidth+=originx; + patch-=originx*step_x; + originx=0; + if (srcwidth<=0) return false; + } + if (originx+srcwidth>texwidth) + { + srcwidth=texwidth-originx; + if (srcwidth<=0) return false; + } + + if (originy<0) + { + srcheight+=originy; + patch-=originy*step_y; + originy=0; + if (srcheight<=0) return false; + } + if (originy+srcheight>texheight) + { + srcheight=texheight-originy; + if (srcheight<=0) return false; + } + return true; +} + + +//=========================================================================== +// +// True Color texture copy function +// +//=========================================================================== +void FBitmap::CopyPixelDataRGB(int originx, int originy, const BYTE *patch, int srcwidth, + int srcheight, int step_x, int step_y, int rotate, int ct) +{ + 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;y(buffer[pos+3] + (( 255-buffer[pos+3]) * (255-palette[v].a))/255, 0, 255); + } + } + } + } +} + diff --git a/src/textures/bitmap.h b/src/textures/bitmap.h new file mode 100644 index 000000000..5010e3992 --- /dev/null +++ b/src/textures/bitmap.h @@ -0,0 +1,204 @@ +/* +** bitmap.h +** +**--------------------------------------------------------------------------- +** Copyright 2008 Christoph Oelckers +** All rights reserved. +** +** Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions +** are met: +** +** 1. Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** 2. Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in the +** documentation and/or other materials provided with the distribution. +** 3. The name of the author may not be used to endorse or promote products +** derived from this software without specific prior written permission. +** +** THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR +** IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES +** OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. +** IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, +** INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT +** NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF +** THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +**--------------------------------------------------------------------------- +** +** +*/ + + +#ifndef __BITMAP_H__ +#define __BITMAP_H__ + +#include "doomtype.h" + +class FBitmap +{ + BYTE *data; + int Width; + int Height; + int Pitch; + bool FreeBuffer; + +public: + FBitmap() + { + data = NULL; + Width = Height = 0; + Pitch = 0; + FreeBuffer = false; + } + + FBitmap(BYTE *buffer, int pitch, int width, int height) + { + data = buffer; + + Pitch = pitch; + Width = width; + Height = height; + FreeBuffer = false; + } + + ~FBitmap() + { + Destroy(); + } + + void Destroy() + { + if (data != NULL && FreeBuffer) delete [] data; + data = NULL; + FreeBuffer = false; + } + + bool Create (int w, int h) + { + Pitch = w*4; + Width = w; + Height = h; + data = new BYTE[4*w*h]; + FreeBuffer = true; + return data != NULL; + } + + + virtual void CopyPixelDataRGB(int originx, int originy, const BYTE *patch, int srcwidth, + int srcheight, int step_x, int step_y, int rotate, int ct); + virtual void CopyPixelData(int originx, int originy, const BYTE * patch, int srcwidth, int srcheight, + int step_x, int step_y, int rotate, PalEntry * palette); + + +}; + +bool ClipCopyPixelRect(int texwidth, int texheight, int &originx, int &originy, + const BYTE *&patch, int &srcwidth, int &srcheight, + int &step_x, int &step_y, int rotate); + +//=========================================================================== +// +// True color conversion classes for the different pixel formats +// used by the supported texture formats +// +//=========================================================================== +struct cRGB +{ + static unsigned char R(const unsigned char * p) { return p[0]; } + static unsigned char G(const unsigned char * p) { return p[1]; } + static unsigned char B(const unsigned char * p) { return p[2]; } + static unsigned char A(const unsigned char * p) { return 255; } + static int Gray(const unsigned char * p) { return (p[0]*77 + p[1]*143 + p[2]*36)>>8; } +}; + +struct cRGBA +{ + static unsigned char R(const unsigned char * p) { return p[0]; } + static unsigned char G(const unsigned char * p) { return p[1]; } + static unsigned char B(const unsigned char * p) { return p[2]; } + static unsigned char A(const unsigned char * p) { return p[3]; } + static int Gray(const unsigned char * p) { return (p[0]*77 + p[1]*143 + p[2]*36)>>8; } +}; + +struct cIA +{ + static unsigned char R(const unsigned char * p) { return p[0]; } + static unsigned char G(const unsigned char * p) { return p[0]; } + static unsigned char B(const unsigned char * p) { return p[0]; } + static unsigned char A(const unsigned char * p) { return p[1]; } + static int Gray(const unsigned char * p) { return p[0]; } +}; + +struct cCMYK +{ + static unsigned char R(const unsigned char * p) { return p[3] - (((256-p[0])*p[3]) >> 8); } + static unsigned char G(const unsigned char * p) { return p[3] - (((256-p[1])*p[3]) >> 8); } + static unsigned char B(const unsigned char * p) { return p[3] - (((256-p[2])*p[3]) >> 8); } + static unsigned char A(const unsigned char * p) { return 255; } + static int Gray(const unsigned char * p) { return (R(p)*77 + G(p)*143 + B(p)*36)>>8; } +}; + +struct cBGR +{ + static unsigned char R(const unsigned char * p) { return p[2]; } + static unsigned char G(const unsigned char * p) { return p[1]; } + static unsigned char B(const unsigned char * p) { return p[0]; } + static unsigned char A(const unsigned char * p) { return 255; } + static int Gray(const unsigned char * p) { return (p[2]*77 + p[1]*143 + p[0]*36)>>8; } +}; + +struct cBGRA +{ + static unsigned char R(const unsigned char * p) { return p[2]; } + static unsigned char G(const unsigned char * p) { return p[1]; } + static unsigned char B(const unsigned char * p) { return p[0]; } + static unsigned char A(const unsigned char * p) { return p[3]; } + static int Gray(const unsigned char * p) { return (p[2]*77 + p[1]*143 + p[0]*36)>>8; } +}; + +struct cI16 +{ + static unsigned char R(const unsigned char * p) { return p[1]; } + static unsigned char G(const unsigned char * p) { return p[1]; } + static unsigned char B(const unsigned char * p) { return p[1]; } + static unsigned char A(const unsigned char * p) { return 255; } + static int Gray(const unsigned char * p) { return p[1]; } +}; + +struct cRGB555 +{ + static unsigned char R(const unsigned char * p) { return (((*(WORD*)p)&0x1f)<<3); } + static unsigned char G(const unsigned char * p) { return (((*(WORD*)p)&0x3e0)>>2); } + static unsigned char B(const unsigned char * p) { return (((*(WORD*)p)&0x7c00)>>7); } + static unsigned char A(const unsigned char * p) { return p[1]; } + static int Gray(const unsigned char * p) { return (R(p)*77 + G(p)*143 + B(p)*36)>>8; } +}; + +struct cPalEntry +{ + static unsigned char R(const unsigned char * p) { return ((PalEntry*)p)->r; } + static unsigned char G(const unsigned char * p) { return ((PalEntry*)p)->g; } + static unsigned char B(const unsigned char * p) { return ((PalEntry*)p)->b; } + static unsigned char A(const unsigned char * p) { return ((PalEntry*)p)->a; } + static int Gray(const unsigned char * p) { return (R(p)*77 + G(p)*143 + B(p)*36)>>8; } +}; + +enum ColorType +{ + CF_RGB, + CF_RGBA, + CF_IA, + CF_CMYK, + CF_BGR, + CF_BGRA, + CF_I16, + CF_RGB555, + CF_PalEntry +}; + + +#endif \ No newline at end of file diff --git a/src/textures/ddstexture.cpp b/src/textures/ddstexture.cpp index c0053a658..f61fc90ed 100644 --- a/src/textures/ddstexture.cpp +++ b/src/textures/ddstexture.cpp @@ -53,6 +53,7 @@ #include "r_local.h" #include "w_wad.h" #include "templates.h" +#include "bitmap.h" // Since we want this to compile under Linux too, we need to define this // stuff ourselves instead of including a DirectX header. @@ -742,7 +743,7 @@ void FDDSTexture::DecompressDXT5 (FWadLump &lump, bool premultiplied, BYTE *tcbu // //=========================================================================== -int FDDSTexture::CopyTrueColorPixels(BYTE *buffer, int buf_pitch, int buf_height, int x, int y, int rotate) +int FDDSTexture::CopyTrueColorPixels(FBitmap *bmp, int x, int y, int rotate) { FWadLump lump = Wads.OpenLumpNum (SourceLump); @@ -768,7 +769,7 @@ int FDDSTexture::CopyTrueColorPixels(BYTE *buffer, int buf_pitch, int buf_height } // All formats decompress to RGBA. - screen->CopyPixelDataRGB(buffer, buf_pitch, buf_height, x, y, TexBuffer, Width, Height, 4, Width*4, rotate, CF_RGBA); + bmp->CopyPixelDataRGB(x, y, TexBuffer, Width, Height, 4, Width*4, rotate, CF_RGBA); delete [] TexBuffer; return -1; } diff --git a/src/textures/jpegtexture.cpp b/src/textures/jpegtexture.cpp index 74028f2d0..4d982caf0 100644 --- a/src/textures/jpegtexture.cpp +++ b/src/textures/jpegtexture.cpp @@ -39,6 +39,7 @@ #include "r_jpeg.h" #include "w_wad.h" #include "v_text.h" +#include "bitmap.h" void FLumpSourceMgr::InitSource (j_decompress_ptr cinfo) { @@ -332,7 +333,7 @@ void FJPEGTexture::MakeTexture () // //=========================================================================== -int FJPEGTexture::CopyTrueColorPixels(BYTE *buffer, int buf_pitch, int buf_height, int x, int y, int rotate) +int FJPEGTexture::CopyTrueColorPixels(FBitmap *bmp, int x, int y, int rotate) { PalEntry pe[256]; @@ -375,18 +376,18 @@ int FJPEGTexture::CopyTrueColorPixels(BYTE *buffer, int buf_pitch, int buf_heigh switch (cinfo.out_color_space) { case JCS_RGB: - screen->CopyPixelDataRGB(buffer, buf_pitch, buf_height, x, y, buff, cinfo.output_width, cinfo.output_height, + bmp->CopyPixelDataRGB(x, y, buff, cinfo.output_width, cinfo.output_height, 3, cinfo.output_width * cinfo.output_components, rotate, CF_RGB); break; case JCS_GRAYSCALE: for(int i=0;i<256;i++) pe[i]=PalEntry(0,i,i,i); // default to a gray map - screen->CopyPixelData(buffer, buf_pitch, buf_height, x, y, buff, cinfo.output_width, cinfo.output_height, + bmp->CopyPixelData(x, y, buff, cinfo.output_width, cinfo.output_height, 1, cinfo.output_width, rotate, pe); break; case JCS_CMYK: - screen->CopyPixelDataRGB(buffer, buf_pitch, buf_height, x, y, buff, cinfo.output_width, cinfo.output_height, + bmp->CopyPixelDataRGB(x, y, buff, cinfo.output_width, cinfo.output_height, 4, cinfo.output_width * cinfo.output_components, rotate, CF_CMYK); break; diff --git a/src/textures/multipatchtexture.cpp b/src/textures/multipatchtexture.cpp index fb7a1e4c8..9d2225ba6 100644 --- a/src/textures/multipatchtexture.cpp +++ b/src/textures/multipatchtexture.cpp @@ -304,14 +304,13 @@ void FMultiPatchTexture::MakeTexture () // //=========================================================================== -int FMultiPatchTexture::CopyTrueColorPixels(BYTE *buffer, int buf_pitch, int buf_height, int x, int y, int rotate) +int FMultiPatchTexture::CopyTrueColorPixels(FBitmap *bmp, int x, int y, int rotate) { int retv = -1; for(int i=0;iCopyTrueColorPixels(buffer, buf_pitch, buf_height, - x+Parts[i].OriginX, y+Parts[i].OriginY, Parts[i].Rotate); + int ret = Parts[i].Texture->CopyTrueColorPixels(bmp, x+Parts[i].OriginX, y+Parts[i].OriginY, Parts[i].Rotate); if (ret > retv) retv = ret; } diff --git a/src/textures/pcxtexture.cpp b/src/textures/pcxtexture.cpp index 3239966c2..a298ff425 100644 --- a/src/textures/pcxtexture.cpp +++ b/src/textures/pcxtexture.cpp @@ -39,6 +39,7 @@ #include "r_local.h" #include "w_wad.h" #include "templates.h" +#include "bitmap.h" bool FPCXTexture::Check(FileReader & file) @@ -418,7 +419,7 @@ void FPCXTexture::MakeTexture() // //=========================================================================== -int FPCXTexture::CopyTrueColorPixels(BYTE *buffer, int buf_pitch, int buf_height, int x, int y, int rotate) +int FPCXTexture::CopyTrueColorPixels(FBitmap *bmp, int x, int y, int rotate) { PalEntry pe[256]; PCXHeader header; @@ -472,14 +473,13 @@ int FPCXTexture::CopyTrueColorPixels(BYTE *buffer, int buf_pitch, int buf_height lump.Seek(sizeof(header), SEEK_SET); ReadPCX8bits (Pixels, lump, &header); } - screen->CopyPixelData(buffer, buf_pitch, buf_height, x, y, Pixels, Width, Height, 1, Width, rotate, pe); + bmp->CopyPixelData(x, y, Pixels, Width, Height, 1, Width, rotate, pe); } else { Pixels = new BYTE[Width*Height * 3]; - BYTE * row = buffer; ReadPCX24bits (Pixels, lump, &header, 3); - screen->CopyPixelDataRGB(buffer, buf_pitch, buf_height, x, y, Pixels, Width, Height, 3, Width*3, rotate, CF_RGB); + bmp->CopyPixelDataRGB(x, y, Pixels, Width, Height, 3, Width*3, rotate, CF_RGB); } delete [] Pixels; return 0; diff --git a/src/textures/pngtexture.cpp b/src/textures/pngtexture.cpp index 64550b690..c7af9ae9c 100644 --- a/src/textures/pngtexture.cpp +++ b/src/textures/pngtexture.cpp @@ -39,6 +39,7 @@ #include "w_wad.h" #include "templates.h" #include "m_png.h" +#include "bitmap.h" bool FPNGTexture::Check(FileReader & file) @@ -490,7 +491,7 @@ void FPNGTexture::MakeTexture () // //=========================================================================== -int FPNGTexture::CopyTrueColorPixels(BYTE *buffer, int buf_pitch, int buf_height, int x, int y, int rotate) +int FPNGTexture::CopyTrueColorPixels(FBitmap *bmp, int x, int y, int rotate) { // Parse pre-IDAT chunks. I skip the CRCs. Is that bad? PalEntry pe[256]; @@ -554,20 +555,20 @@ int FPNGTexture::CopyTrueColorPixels(BYTE *buffer, int buf_pitch, int buf_height { case 0: case 3: - screen->CopyPixelData(buffer, buf_pitch, buf_height, x, y, Pixels, Width, Height, 1, Width, rotate, pe); + bmp->CopyPixelData(x, y, Pixels, Width, Height, 1, Width, rotate, pe); break; case 2: - screen->CopyPixelDataRGB(buffer, buf_pitch, buf_height, x, y, Pixels, Width, Height, 3, pixwidth, rotate, CF_RGB); + bmp->CopyPixelDataRGB(x, y, Pixels, Width, Height, 3, pixwidth, rotate, CF_RGB); break; case 4: - screen->CopyPixelDataRGB(buffer, buf_pitch, buf_height, x, y, Pixels, Width, Height, 2, pixwidth, rotate, CF_IA); + bmp->CopyPixelDataRGB(x, y, Pixels, Width, Height, 2, pixwidth, rotate, CF_IA); transpal = -1; break; case 6: - screen->CopyPixelDataRGB(buffer, buf_pitch, buf_height, x, y, Pixels, Width, Height, 4, pixwidth, rotate, CF_RGBA); + bmp->CopyPixelDataRGB(x, y, Pixels, Width, Height, 4, pixwidth, rotate, CF_RGBA); transpal = -1; break; diff --git a/src/textures/texture.cpp b/src/textures/texture.cpp index 953a2a211..c2248d2f3 100644 --- a/src/textures/texture.cpp +++ b/src/textures/texture.cpp @@ -40,6 +40,7 @@ #include "templates.h" #include "i_system.h" #include "r_translate.h" +#include "bitmap.h" typedef bool (*CheckFunc)(FileReader & file); typedef FTexture * (*CreateFunc)(FileReader & file, int lumpnum); @@ -456,8 +457,11 @@ void FTexture::FillBuffer(BYTE *buff, int pitch, int height, FTextureFormat fmt) break; case TEX_RGB: - CopyTrueColorPixels(buff, pitch, height, 0, 0); + { + FBitmap bmp(buff, pitch, pitch, height); + CopyTrueColorPixels(&bmp, 0, 0); break; + } default: I_Error("FTexture::FillBuffer: Unsupported format %d", fmt); @@ -476,25 +480,21 @@ void FTexture::FillBuffer(BYTE *buff, int pitch, int height, FTextureFormat fmt) // //=========================================================================== -int FTexture::CopyTrueColorPixels(BYTE *buffer, int buf_pitch, int buf_height, int x, int y, int rotate) +int FTexture::CopyTrueColorPixels(FBitmap *bmp, int x, int y, int rotate) { PalEntry *palette = screen->GetPalette(); palette[0].a=255; // temporarily modify the first color's alpha - screen->CopyPixelData(buffer, buf_pitch, buf_height, x, y, - GetPixels(), Width, Height, Height, 1, - rotate, palette); + bmp->CopyPixelData(x, y, GetPixels(), Width, Height, Height, 1, rotate, palette); palette[0].a=0; return 0; } -int FTexture::CopyTrueColorTranslated(BYTE *buffer, int buf_pitch, int buf_height, int x, int y, FRemapTable *remap) +int FTexture::CopyTrueColorTranslated(FBitmap *bmp, int x, int y, FRemapTable *remap) { PalEntry *palette = remap->Palette; palette[0].a=255; // temporarily modify the first color's alpha - screen->CopyPixelData(buffer, buf_pitch, buf_height, x, y, - GetPixels(), Width, Height, Height, 1, - 0, palette); + bmp->CopyPixelData(x, y, GetPixels(), Width, Height, Height, 1, 0, palette); palette[0].a=0; return 0; diff --git a/src/textures/tgatexture.cpp b/src/textures/tgatexture.cpp index 09d0b53fe..3ece55557 100644 --- a/src/textures/tgatexture.cpp +++ b/src/textures/tgatexture.cpp @@ -38,6 +38,7 @@ #include "r_local.h" #include "w_wad.h" #include "templates.h" +#include "bitmap.h" bool FTGATexture::Check(FileReader & data) @@ -384,7 +385,7 @@ void FTGATexture::MakeTexture () // //=========================================================================== -int FTGATexture::CopyTrueColorPixels(BYTE *buffer, int buf_pitch, int buf_height, int x, int y, int rotate) +int FTGATexture::CopyTrueColorPixels(FBitmap *bmp, int x, int y, int rotate) { PalEntry pe[256]; FWadLump lump = Wads.OpenLumpNum (SourceLump); @@ -469,7 +470,7 @@ int FTGATexture::CopyTrueColorPixels(BYTE *buffer, int buf_pitch, int buf_height switch (hdr.img_type & 7) { case 1: // paletted - screen->CopyPixelData(buffer, buf_pitch, buf_height, x, y, ptr, Width, Height, step_x, Pitch, rotate, pe); + bmp->CopyPixelData(x, y, ptr, Width, Height, step_x, Pitch, rotate, pe); break; case 2: // RGB @@ -477,21 +478,21 @@ int FTGATexture::CopyTrueColorPixels(BYTE *buffer, int buf_pitch, int buf_height { case 15: case 16: - screen->CopyPixelDataRGB(buffer, buf_pitch, buf_height, x, y, ptr, Width, Height, step_x, Pitch, rotate, CF_RGB555); + bmp->CopyPixelDataRGB(x, y, ptr, Width, Height, step_x, Pitch, rotate, CF_RGB555); break; case 24: - screen->CopyPixelDataRGB(buffer, buf_pitch, buf_height, x, y, ptr, Width, Height, step_x, Pitch, rotate, CF_BGR); + bmp->CopyPixelDataRGB(x, y, ptr, Width, Height, step_x, Pitch, rotate, CF_BGR); break; case 32: if ((hdr.img_desc&15)!=8) // 32 bits without a valid alpha channel { - screen->CopyPixelDataRGB(buffer, buf_pitch, buf_height, x, y, ptr, Width, Height, step_x, Pitch, rotate, CF_BGR); + bmp->CopyPixelDataRGB(x, y, ptr, Width, Height, step_x, Pitch, rotate, CF_BGR); } else { - screen->CopyPixelDataRGB(buffer, buf_pitch, buf_height, x, y, ptr, Width, Height, step_x, Pitch, rotate, CF_BGRA); + bmp->CopyPixelDataRGB(x, y, ptr, Width, Height, step_x, Pitch, rotate, CF_BGRA); transval = -1; } break; @@ -506,11 +507,11 @@ int FTGATexture::CopyTrueColorPixels(BYTE *buffer, int buf_pitch, int buf_height { case 8: for(int i=0;i<256;i++) pe[i]=PalEntry(0,i,i,i); // gray map - screen->CopyPixelData(buffer, buf_pitch, buf_height, x, y, ptr, Width, Height, step_x, Pitch, rotate, pe); + bmp->CopyPixelData(x, y, ptr, Width, Height, step_x, Pitch, rotate, pe); break; case 16: - screen->CopyPixelDataRGB(buffer, buf_pitch, buf_height, x, y, ptr, Width, Height, step_x, Pitch, rotate, CF_I16); + bmp->CopyPixelDataRGB(x, y, ptr, Width, Height, step_x, Pitch, rotate, CF_I16); break; default: diff --git a/src/v_video.cpp b/src/v_video.cpp index 4aa7043ec..fdb351f83 100644 --- a/src/v_video.cpp +++ b/src/v_video.cpp @@ -1157,216 +1157,6 @@ void DFrameBuffer::WipeCleanup() wipe_Cleanup(); } -//=========================================================================== -// -// multi-format pixel copy with colormap application -// requires one of the previously defined conversion classes to work -// -//=========================================================================== -template -void iCopyColors(BYTE *pout, const BYTE *pin, int count, int step) -{ - for(int i=0;i, - iCopyColors, - iCopyColors, - iCopyColors, - iCopyColors, - iCopyColors, - iCopyColors, - iCopyColors, - iCopyColors -}; - -//=========================================================================== -// -// Clips the copy area for CopyPixelData functions -// -//=========================================================================== -bool ClipCopyPixelRect(int texwidth, int texheight, int &originx, int &originy, - const BYTE *&patch, int &srcwidth, int &srcheight, - int &pstep_x, int &pstep_y, int rotate) -{ - int pixxoffset; - int pixyoffset; - - int step_x; - int step_y; - - // First adjust the settings for the intended rotation - switch (rotate) - { - default: - case 0: // normal - pixxoffset = 0; - pixyoffset = 0; - step_x = pstep_x; - step_y = pstep_y; - break; - - case 1: // rotate 90° right - pixxoffset = 0; - pixyoffset = srcheight - 1; - step_x = -pstep_y; - step_y = pstep_x; - break; - - case 2: // rotate 180° - pixxoffset = srcwidth - 1; - pixyoffset = srcheight - 1; - step_x = -pstep_x; - step_y = -pstep_y; - break; - - case 3: // rotate 90° left - pixxoffset = srcwidth - 1; - pixyoffset = 0; - step_x = pstep_y; - step_y = -pstep_x; - break; - - case 4: // flip horizontally - pixxoffset = srcwidth - 1; - pixyoffset = 0; - step_x = -pstep_x; - step_y = pstep_y; - break; - - case 5: // flip horizontally and rotate 90° right - pixxoffset = srcwidth - 1; - pixyoffset = srcheight - 1; - step_x = -pstep_y; - step_y = -pstep_x; - break; - - case 6: // flip vertically - pixxoffset = 0; - pixyoffset = srcheight - 1; - step_x = pstep_x; - step_y = -pstep_y; - break; - - case 7: // flip horizontally and rotate 90° left - pixxoffset = 0; - pixyoffset = 0; - step_x = pstep_y; - step_y = pstep_x; - break; - } - if (rotate&1) - { - int v = srcwidth; - srcwidth = srcheight; - srcheight = v; - } - - patch += pixxoffset * pstep_x + pixyoffset * pstep_y; - pstep_x = step_x; - pstep_y = step_y; - - // clip source rectangle to destination - if (originx<0) - { - srcwidth+=originx; - patch-=originx*step_x; - originx=0; - if (srcwidth<=0) return false; - } - if (originx+srcwidth>texwidth) - { - srcwidth=texwidth-originx; - if (srcwidth<=0) return false; - } - - if (originy<0) - { - srcheight+=originy; - patch-=originy*step_y; - originy=0; - if (srcheight<=0) return false; - } - if (originy+srcheight>texheight) - { - srcheight=texheight-originy; - if (srcheight<=0) return false; - } - return true; -} - - -//=========================================================================== -// -// True Color texture copy function -// -//=========================================================================== -void DFrameBuffer::CopyPixelDataRGB(BYTE *buffer, int texpitch, int texheight, int originx, int originy, - const BYTE *patch, int srcwidth, int srcheight, int step_x, int step_y, - int rotate, int ct) -{ - if (ClipCopyPixelRect(texpitch/4, texheight, originx, originy, patch, srcwidth, srcheight, step_x, step_y, rotate)) - { - buffer+=4*originx + texpitch*originy; - for (int y=0;y(buffer[pos+3] + (( 255-buffer[pos+3]) * (255-palette[v].a))/255, 0, 255); - } - } - } - } -} - //=========================================================================== // // Texture precaching diff --git a/src/v_video.h b/src/v_video.h index 68758a5e8..8357a0a72 100644 --- a/src/v_video.h +++ b/src/v_video.h @@ -372,15 +372,6 @@ public: // Create a palette texture from a remap/palette table. virtual FNativePalette *CreatePalette(FRemapTable *remap); - // texture copy functions - virtual void CopyPixelDataRGB(BYTE *buffer, int texpitch, int texheight, int originx, int originy, - const BYTE *patch, int pix_width, int pix_height, int step_x, int step_y, - int rotate, int ct); - - virtual void CopyPixelData(BYTE *buffer, int texpitch, int texheight, int originx, int originy, - const BYTE *patch, int pix_width, int pix_height, - int step_x, int step_y, int rotate, PalEntry * palette); - // Precaches or unloads a texture virtual void PrecacheTexture(FTexture *tex, int cache); @@ -405,9 +396,6 @@ private: DWORD LastMS, LastSec, FrameCount, LastCount, LastTic; }; -bool ClipCopyPixelRect(int texwidth, int texheight, int &originx, int &originy, - const BYTE *&patch, int &srcwidth, int &srcheight, - int &step_x, int &step_y, int rotate); extern FColorMatcher ColorMatcher; @@ -478,106 +466,5 @@ int CheckRatio (int width, int height); extern const int BaseRatioSizes[5][4]; -//=========================================================================== -// -// True color conversion classes for the different pixel formats -// used by the supported texture formats -// -//=========================================================================== -struct cRGB -{ - static unsigned char R(const unsigned char * p) { return p[0]; } - static unsigned char G(const unsigned char * p) { return p[1]; } - static unsigned char B(const unsigned char * p) { return p[2]; } - static unsigned char A(const unsigned char * p) { return 255; } - static int Gray(const unsigned char * p) { return (p[0]*77 + p[1]*143 + p[2]*36)>>8; } -}; - -struct cRGBA -{ - static unsigned char R(const unsigned char * p) { return p[0]; } - static unsigned char G(const unsigned char * p) { return p[1]; } - static unsigned char B(const unsigned char * p) { return p[2]; } - static unsigned char A(const unsigned char * p) { return p[3]; } - static int Gray(const unsigned char * p) { return (p[0]*77 + p[1]*143 + p[2]*36)>>8; } -}; - -struct cIA -{ - static unsigned char R(const unsigned char * p) { return p[0]; } - static unsigned char G(const unsigned char * p) { return p[0]; } - static unsigned char B(const unsigned char * p) { return p[0]; } - static unsigned char A(const unsigned char * p) { return p[1]; } - static int Gray(const unsigned char * p) { return p[0]; } -}; - -struct cCMYK -{ - static unsigned char R(const unsigned char * p) { return p[3] - (((256-p[0])*p[3]) >> 8); } - static unsigned char G(const unsigned char * p) { return p[3] - (((256-p[1])*p[3]) >> 8); } - static unsigned char B(const unsigned char * p) { return p[3] - (((256-p[2])*p[3]) >> 8); } - static unsigned char A(const unsigned char * p) { return 255; } - static int Gray(const unsigned char * p) { return (R(p)*77 + G(p)*143 + B(p)*36)>>8; } -}; - -struct cBGR -{ - static unsigned char R(const unsigned char * p) { return p[2]; } - static unsigned char G(const unsigned char * p) { return p[1]; } - static unsigned char B(const unsigned char * p) { return p[0]; } - static unsigned char A(const unsigned char * p) { return 255; } - static int Gray(const unsigned char * p) { return (p[2]*77 + p[1]*143 + p[0]*36)>>8; } -}; - -struct cBGRA -{ - static unsigned char R(const unsigned char * p) { return p[2]; } - static unsigned char G(const unsigned char * p) { return p[1]; } - static unsigned char B(const unsigned char * p) { return p[0]; } - static unsigned char A(const unsigned char * p) { return p[3]; } - static int Gray(const unsigned char * p) { return (p[2]*77 + p[1]*143 + p[0]*36)>>8; } -}; - -struct cI16 -{ - static unsigned char R(const unsigned char * p) { return p[1]; } - static unsigned char G(const unsigned char * p) { return p[1]; } - static unsigned char B(const unsigned char * p) { return p[1]; } - static unsigned char A(const unsigned char * p) { return 255; } - static int Gray(const unsigned char * p) { return p[1]; } -}; - -struct cRGB555 -{ - static unsigned char R(const unsigned char * p) { return (((*(WORD*)p)&0x1f)<<3); } - static unsigned char G(const unsigned char * p) { return (((*(WORD*)p)&0x3e0)>>2); } - static unsigned char B(const unsigned char * p) { return (((*(WORD*)p)&0x7c00)>>7); } - static unsigned char A(const unsigned char * p) { return p[1]; } - static int Gray(const unsigned char * p) { return (R(p)*77 + G(p)*143 + B(p)*36)>>8; } -}; - -struct cPalEntry -{ - static unsigned char R(const unsigned char * p) { return ((PalEntry*)p)->r; } - static unsigned char G(const unsigned char * p) { return ((PalEntry*)p)->g; } - static unsigned char B(const unsigned char * p) { return ((PalEntry*)p)->b; } - static unsigned char A(const unsigned char * p) { return ((PalEntry*)p)->a; } - static int Gray(const unsigned char * p) { return (R(p)*77 + G(p)*143 + B(p)*36)>>8; } -}; - -enum ColorType -{ - CF_RGB, - CF_RGBA, - CF_IA, - CF_CMYK, - CF_BGR, - CF_BGRA, - CF_I16, - CF_RGB555, - CF_PalEntry -}; - - #endif // __V_VIDEO_H__ diff --git a/wadsrc/decorate/doom/possessed.txt b/wadsrc/decorate/doom/possessed.txt index b255cedef..62a41a80a 100644 --- a/wadsrc/decorate/doom/possessed.txt +++ b/wadsrc/decorate/doom/possessed.txt @@ -205,6 +205,7 @@ ACTOR WolfensteinSS 84 DeathSound "wolfss/death" ActiveSound "wolfss/active" AttackSound "wolfss/attack" + Obituary "$OB_WOLFSS" Dropitem "Clip" States { diff --git a/zdoom.vcproj b/zdoom.vcproj index 4a64484fc..c5c9e494f 100644 --- a/zdoom.vcproj +++ b/zdoom.vcproj @@ -1,7 +1,7 @@ + + + + + + + + + + + + + + + + + + + + - - - - - - - - - - - - - - - - - - - - - - - @@ -944,6 +934,16 @@ Outputs=""src/$(InputName).h"" /> + + + @@ -1538,16 +1538,6 @@ Outputs="$(IntDir)\$(InputName).obj" /> - - - @@ -1558,6 +1548,16 @@ Outputs="$(IntDir)\$(InputName).obj" /> + + + @@ -1582,16 +1582,6 @@ Outputs="$(IntDir)\$(InputName).obj" /> - - - @@ -1602,6 +1592,16 @@ Outputs="$(IntDir)\$(InputName).obj" /> + + + @@ -1626,16 +1626,6 @@ Outputs="$(IntDir)\$(InputName).obj" /> - - - @@ -1646,6 +1636,16 @@ Outputs="$(IntDir)\$(InputName).obj" /> + + + @@ -1670,16 +1670,6 @@ Outputs="$(IntDir)\$(InputName).obj" /> - - - @@ -1690,6 +1680,16 @@ Outputs="$(IntDir)\$(InputName).obj" /> + + + @@ -1714,16 +1714,6 @@ Outputs="$(IntDir)\$(InputName).obj" /> - - - @@ -1734,6 +1724,16 @@ Outputs="$(IntDir)\$(InputName).obj" /> + + + @@ -1898,14 +1898,6 @@ Outputs="$(IntDir)\$(InputName).obj" /> - - - @@ -1916,6 +1908,14 @@ Outputs="$(IntDir)\$(InputName).obj" /> + + + + + + + @@ -2765,14 +2773,6 @@ AdditionalIncludeDirectories="src\win32;$(NoInherit)" /> - - - @@ -2782,6 +2782,14 @@ AdditionalIncludeDirectories="src\win32;$(NoInherit)" /> + + + @@ -3024,7 +3032,7 @@ />