- 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.


SVN r915 (trunk)
This commit is contained in:
Christoph Oelckers 2008-04-15 18:05:39 +00:00
commit ce5d4dba02
17 changed files with 648 additions and 505 deletions

View file

@ -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;

View file

@ -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; }

View file

@ -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; }

246
src/textures/bitmap.cpp Normal file
View file

@ -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<class T>
void iCopyColors(BYTE *pout, const BYTE *pin, int count, int step)
{
for(int i=0;i<count;i++)
{
pout[0]=T::B(pin);
pout[1]=T::G(pin);
pout[2]=T::R(pin);
pout[3]=T::A(pin);
pout+=4;
pin+=step;
}
}
typedef void (*CopyFunc)(BYTE *pout, const BYTE *pin, int count, int step);
static CopyFunc copyfuncs[]={
iCopyColors<cRGB>,
iCopyColors<cRGBA>,
iCopyColors<cIA>,
iCopyColors<cCMYK>,
iCopyColors<cBGR>,
iCopyColors<cBGRA>,
iCopyColors<cI16>,
iCopyColors<cRGB555>,
iCopyColors<cPalEntry>
};
//===========================================================================
//
// 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<srcheight;y++)
{
copyfuncs[ct](&buffer[y*Pitch], &patch[y*step_y], srcwidth, step_x);
}
}
}
//===========================================================================
//
// Paletted to True Color texture copy function
//
//===========================================================================
void FBitmap::CopyPixelData(int originx, int originy, const BYTE * patch, int srcwidth, int srcheight,
int step_x, int step_y, int rotate, PalEntry * palette)
{
int x,y,pos;
if (ClipCopyPixelRect(Width, Height, originx, originy, patch, srcwidth, srcheight, step_x, step_y, rotate))
{
BYTE *buffer = data + 4*originx + Pitch*originy;
for (y=0;y<srcheight;y++)
{
pos = y*Pitch;
for (x=0;x<srcwidth;x++,pos+=4)
{
int v=(unsigned char)patch[y*step_y+x*step_x];
if (palette[v].a==0)
{
buffer[pos]=palette[v].b;
buffer[pos+1]=palette[v].g;
buffer[pos+2]=palette[v].r;
buffer[pos+3]=255;
}
else if (palette[v].a!=255)
{
// [RH] Err... This can't be right, can it?
buffer[pos ] = (buffer[pos ] * palette[v].a + palette[v].b * (1-palette[v].a)) / 255;
buffer[pos+1] = (buffer[pos+1] * palette[v].a + palette[v].g * (1-palette[v].a)) / 255;
buffer[pos+2] = (buffer[pos+2] * palette[v].a + palette[v].r * (1-palette[v].a)) / 255;
buffer[pos+3] = clamp<int>(buffer[pos+3] + (( 255-buffer[pos+3]) * (255-palette[v].a))/255, 0, 255);
}
}
}
}
}

204
src/textures/bitmap.h Normal file
View file

@ -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

View file

@ -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;
}

View file

@ -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;

View file

@ -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;i<NumParts;i++)
{
int ret = Parts[i].Texture->CopyTrueColorPixels(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;
}

View file

@ -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;

View file

@ -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;

View file

@ -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;

View file

@ -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:

View file

@ -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<class T>
void iCopyColors(BYTE *pout, const BYTE *pin, int count, int step)
{
for(int i=0;i<count;i++)
{
pout[0]=T::B(pin);
pout[1]=T::G(pin);
pout[2]=T::R(pin);
pout[3]=T::A(pin);
pout+=4;
pin+=step;
}
}
typedef void (*CopyFunc)(BYTE *pout, const BYTE *pin, int count, int step);
static CopyFunc copyfuncs[]={
iCopyColors<cRGB>,
iCopyColors<cRGBA>,
iCopyColors<cIA>,
iCopyColors<cCMYK>,
iCopyColors<cBGR>,
iCopyColors<cBGRA>,
iCopyColors<cI16>,
iCopyColors<cRGB555>,
iCopyColors<cPalEntry>
};
//===========================================================================
//
// 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<srcheight;y++)
{
copyfuncs[ct](&buffer[y*texpitch], &patch[y*step_y], srcwidth, step_x);
}
}
}
//===========================================================================
//
// Paletted to True Color texture copy function
//
//===========================================================================
void DFrameBuffer::CopyPixelData(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, PalEntry * palette)
{
int x,y,pos;
if (ClipCopyPixelRect(texpitch/4, texheight, originx, originy, patch, srcwidth, srcheight, step_x, step_y, rotate))
{
buffer+=4*originx + texpitch*originy;
for (y=0;y<srcheight;y++)
{
pos=y*texpitch;
for (x=0;x<srcwidth;x++,pos+=4)
{
int v=(unsigned char)patch[y*step_y+x*step_x];
if (palette[v].a==0)
{
buffer[pos]=palette[v].b;
buffer[pos+1]=palette[v].g;
buffer[pos+2]=palette[v].r;
buffer[pos+3]=255;
}
else if (palette[v].a!=255)
{
// [RH] Err... This can't be right, can it?
buffer[pos ] = (buffer[pos ] * palette[v].a + palette[v].b * (1-palette[v].a)) / 255;
buffer[pos+1] = (buffer[pos+1] * palette[v].a + palette[v].g * (1-palette[v].a)) / 255;
buffer[pos+2] = (buffer[pos+2] * palette[v].a + palette[v].r * (1-palette[v].a)) / 255;
buffer[pos+3] = clamp<int>(buffer[pos+3] + (( 255-buffer[pos+3]) * (255-palette[v].a))/255, 0, 255);
}
}
}
}
}
//===========================================================================
//
// Texture precaching

View file

@ -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__