2008-04-15 18:05:39 +00:00
|
|
|
/*
|
|
|
|
** 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"
|
2008-04-22 18:48:30 +00:00
|
|
|
#include "templates.h"
|
2008-04-15 18:05:39 +00:00
|
|
|
|
2008-04-16 18:17:20 +00:00
|
|
|
struct FCopyInfo;
|
|
|
|
|
2008-04-15 18:05:39 +00:00
|
|
|
class FBitmap
|
|
|
|
{
|
2008-04-17 20:34:58 +00:00
|
|
|
protected:
|
2008-04-15 18:05:39 +00:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2008-04-20 19:39:08 +00:00
|
|
|
virtual ~FBitmap()
|
2008-04-15 18:05:39 +00:00
|
|
|
{
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2008-04-16 18:17:20 +00:00
|
|
|
int GetHeight() const
|
|
|
|
{
|
|
|
|
return Height;
|
|
|
|
}
|
|
|
|
|
|
|
|
int GetWidth() const
|
|
|
|
{
|
|
|
|
return Width;
|
|
|
|
}
|
|
|
|
|
|
|
|
int GetPitch() const
|
|
|
|
{
|
|
|
|
return Pitch;
|
|
|
|
}
|
|
|
|
|
|
|
|
const BYTE *GetPixels() const
|
|
|
|
{
|
|
|
|
return data;
|
|
|
|
}
|
|
|
|
|
2008-04-17 20:34:58 +00:00
|
|
|
BYTE *GetPixels()
|
|
|
|
{
|
|
|
|
return data;
|
|
|
|
}
|
|
|
|
|
2009-09-25 02:27:48 +00:00
|
|
|
void Zero();
|
2008-04-15 18:05:39 +00:00
|
|
|
|
|
|
|
virtual void CopyPixelDataRGB(int originx, int originy, const BYTE *patch, int srcwidth,
|
2008-04-16 18:17:20 +00:00
|
|
|
int srcheight, int step_x, int step_y, int rotate, int ct, FCopyInfo *inf = NULL);
|
2008-04-15 18:05:39 +00:00
|
|
|
virtual void CopyPixelData(int originx, int originy, const BYTE * patch, int srcwidth, int srcheight,
|
2008-04-16 18:17:20 +00:00
|
|
|
int step_x, int step_y, int rotate, PalEntry * palette, FCopyInfo *inf = NULL);
|
2008-04-15 18:05:39 +00:00
|
|
|
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
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
|
|
|
|
{
|
2008-04-15 22:17:30 +00:00
|
|
|
static __forceinline unsigned char R(const unsigned char * p) { return p[0]; }
|
|
|
|
static __forceinline unsigned char G(const unsigned char * p) { return p[1]; }
|
|
|
|
static __forceinline unsigned char B(const unsigned char * p) { return p[2]; }
|
|
|
|
static __forceinline unsigned char A(const unsigned char * p) { return 255; }
|
|
|
|
static __forceinline int Gray(const unsigned char * p) { return (p[0]*77 + p[1]*143 + p[2]*36)>>8; }
|
2008-04-15 18:05:39 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
struct cRGBA
|
|
|
|
{
|
2008-04-15 22:17:30 +00:00
|
|
|
enum
|
|
|
|
{
|
|
|
|
RED = 0,
|
|
|
|
GREEN = 1,
|
|
|
|
BLUE = 1,
|
|
|
|
ALPHA = 3
|
|
|
|
};
|
|
|
|
static __forceinline unsigned char R(const unsigned char * p) { return p[0]; }
|
|
|
|
static __forceinline unsigned char G(const unsigned char * p) { return p[1]; }
|
|
|
|
static __forceinline unsigned char B(const unsigned char * p) { return p[2]; }
|
|
|
|
static __forceinline unsigned char A(const unsigned char * p) { return p[3]; }
|
|
|
|
static __forceinline int Gray(const unsigned char * p) { return (p[0]*77 + p[1]*143 + p[2]*36)>>8; }
|
2008-04-15 18:05:39 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
struct cIA
|
|
|
|
{
|
2008-04-15 22:17:30 +00:00
|
|
|
static __forceinline unsigned char R(const unsigned char * p) { return p[0]; }
|
|
|
|
static __forceinline unsigned char G(const unsigned char * p) { return p[0]; }
|
|
|
|
static __forceinline unsigned char B(const unsigned char * p) { return p[0]; }
|
|
|
|
static __forceinline unsigned char A(const unsigned char * p) { return p[1]; }
|
|
|
|
static __forceinline int Gray(const unsigned char * p) { return p[0]; }
|
2008-04-15 18:05:39 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
struct cCMYK
|
|
|
|
{
|
2008-04-15 22:17:30 +00:00
|
|
|
static __forceinline unsigned char R(const unsigned char * p) { return p[3] - (((256-p[0])*p[3]) >> 8); }
|
|
|
|
static __forceinline unsigned char G(const unsigned char * p) { return p[3] - (((256-p[1])*p[3]) >> 8); }
|
|
|
|
static __forceinline unsigned char B(const unsigned char * p) { return p[3] - (((256-p[2])*p[3]) >> 8); }
|
|
|
|
static __forceinline unsigned char A(const unsigned char * p) { return 255; }
|
|
|
|
static __forceinline int Gray(const unsigned char * p) { return (R(p)*77 + G(p)*143 + B(p)*36)>>8; }
|
2008-04-15 18:05:39 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
struct cBGR
|
|
|
|
{
|
2008-04-15 22:17:30 +00:00
|
|
|
static __forceinline unsigned char R(const unsigned char * p) { return p[2]; }
|
|
|
|
static __forceinline unsigned char G(const unsigned char * p) { return p[1]; }
|
|
|
|
static __forceinline unsigned char B(const unsigned char * p) { return p[0]; }
|
|
|
|
static __forceinline unsigned char A(const unsigned char * p) { return 255; }
|
|
|
|
static __forceinline int Gray(const unsigned char * p) { return (p[2]*77 + p[1]*143 + p[0]*36)>>8; }
|
2008-04-15 18:05:39 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
struct cBGRA
|
|
|
|
{
|
2008-04-15 22:17:30 +00:00
|
|
|
enum
|
|
|
|
{
|
|
|
|
RED = 2,
|
|
|
|
GREEN = 1,
|
|
|
|
BLUE = 0,
|
|
|
|
ALPHA = 3
|
|
|
|
};
|
|
|
|
static __forceinline unsigned char R(const unsigned char * p) { return p[2]; }
|
|
|
|
static __forceinline unsigned char G(const unsigned char * p) { return p[1]; }
|
|
|
|
static __forceinline unsigned char B(const unsigned char * p) { return p[0]; }
|
|
|
|
static __forceinline unsigned char A(const unsigned char * p) { return p[3]; }
|
|
|
|
static __forceinline int Gray(const unsigned char * p) { return (p[2]*77 + p[1]*143 + p[0]*36)>>8; }
|
|
|
|
};
|
|
|
|
|
|
|
|
struct cARGB
|
|
|
|
{
|
|
|
|
enum
|
|
|
|
{
|
|
|
|
RED = 1,
|
|
|
|
GREEN = 2,
|
|
|
|
BLUE = 3,
|
|
|
|
ALPHA = 0
|
|
|
|
};
|
|
|
|
static __forceinline unsigned char R(const unsigned char * p) { return p[1]; }
|
|
|
|
static __forceinline unsigned char G(const unsigned char * p) { return p[2]; }
|
|
|
|
static __forceinline unsigned char B(const unsigned char * p) { return p[3]; }
|
|
|
|
static __forceinline unsigned char A(const unsigned char * p) { return p[0]; }
|
|
|
|
static __forceinline int Gray(const unsigned char * p) { return (p[1]*77 + p[2]*143 + p[3]*36)>>8; }
|
2008-04-15 18:05:39 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
struct cI16
|
|
|
|
{
|
2008-04-15 22:17:30 +00:00
|
|
|
static __forceinline unsigned char R(const unsigned char * p) { return p[1]; }
|
|
|
|
static __forceinline unsigned char G(const unsigned char * p) { return p[1]; }
|
|
|
|
static __forceinline unsigned char B(const unsigned char * p) { return p[1]; }
|
|
|
|
static __forceinline unsigned char A(const unsigned char * p) { return 255; }
|
|
|
|
static __forceinline int Gray(const unsigned char * p) { return p[1]; }
|
2008-04-15 18:05:39 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
struct cRGB555
|
|
|
|
{
|
2008-04-15 22:17:30 +00:00
|
|
|
static __forceinline unsigned char R(const unsigned char * p) { return (((*(WORD*)p)&0x1f)<<3); }
|
|
|
|
static __forceinline unsigned char G(const unsigned char * p) { return (((*(WORD*)p)&0x3e0)>>2); }
|
|
|
|
static __forceinline unsigned char B(const unsigned char * p) { return (((*(WORD*)p)&0x7c00)>>7); }
|
|
|
|
static __forceinline unsigned char A(const unsigned char * p) { return 255; }
|
|
|
|
static __forceinline int Gray(const unsigned char * p) { return (R(p)*77 + G(p)*143 + B(p)*36)>>8; }
|
2008-04-15 18:05:39 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
struct cPalEntry
|
|
|
|
{
|
2008-04-15 22:17:30 +00:00
|
|
|
static __forceinline unsigned char R(const unsigned char * p) { return ((PalEntry*)p)->r; }
|
|
|
|
static __forceinline unsigned char G(const unsigned char * p) { return ((PalEntry*)p)->g; }
|
|
|
|
static __forceinline unsigned char B(const unsigned char * p) { return ((PalEntry*)p)->b; }
|
|
|
|
static __forceinline unsigned char A(const unsigned char * p) { return ((PalEntry*)p)->a; }
|
|
|
|
static __forceinline int Gray(const unsigned char * p) { return (R(p)*77 + G(p)*143 + B(p)*36)>>8; }
|
2008-04-15 18:05:39 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
enum ColorType
|
|
|
|
{
|
|
|
|
CF_RGB,
|
|
|
|
CF_RGBA,
|
|
|
|
CF_IA,
|
|
|
|
CF_CMYK,
|
|
|
|
CF_BGR,
|
|
|
|
CF_BGRA,
|
|
|
|
CF_I16,
|
|
|
|
CF_RGB555,
|
|
|
|
CF_PalEntry
|
|
|
|
};
|
|
|
|
|
2008-04-15 22:17:30 +00:00
|
|
|
enum EBlend
|
|
|
|
{
|
|
|
|
BLEND_NONE = 0,
|
2009-09-21 13:15:36 +00:00
|
|
|
BLEND_ICEMAP = 1,
|
|
|
|
BLEND_DESATURATE1 = 2,
|
|
|
|
BLEND_DESATURATE31 = 32,
|
|
|
|
BLEND_SPECIALCOLORMAP1 = 33,
|
2008-04-15 22:17:30 +00:00
|
|
|
BLEND_MODULATE = -1,
|
|
|
|
BLEND_OVERLAY = -2,
|
|
|
|
};
|
|
|
|
|
2008-04-22 18:48:30 +00:00
|
|
|
enum ECopyOp
|
|
|
|
{
|
|
|
|
OP_COPY,
|
|
|
|
OP_BLEND,
|
|
|
|
OP_ADD,
|
|
|
|
OP_SUBTRACT,
|
|
|
|
OP_REVERSESUBTRACT,
|
|
|
|
OP_MODULATE,
|
2008-05-16 23:36:47 +00:00
|
|
|
OP_COPYALPHA,
|
|
|
|
OP_OVERWRITE
|
2008-04-22 18:48:30 +00:00
|
|
|
};
|
|
|
|
|
2008-04-15 22:17:30 +00:00
|
|
|
struct FCopyInfo
|
|
|
|
{
|
2008-04-22 18:48:30 +00:00
|
|
|
ECopyOp op;
|
2008-04-15 22:17:30 +00:00
|
|
|
EBlend blend;
|
|
|
|
fixed_t blendcolor[4];
|
2008-04-22 18:48:30 +00:00
|
|
|
fixed_t alpha;
|
|
|
|
fixed_t invalpha;
|
2008-04-15 22:17:30 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
struct bCopy
|
|
|
|
{
|
|
|
|
static __forceinline void OpC(BYTE &d, BYTE s, BYTE a, FCopyInfo *i) { d = s; }
|
|
|
|
static __forceinline void OpA(BYTE &d, BYTE s, FCopyInfo *i) { d = s; }
|
2008-05-16 23:36:47 +00:00
|
|
|
static __forceinline bool ProcessAlpha0() { return false; }
|
|
|
|
};
|
|
|
|
|
|
|
|
struct bOverwrite
|
|
|
|
{
|
|
|
|
static __forceinline void OpC(BYTE &d, BYTE s, BYTE a, FCopyInfo *i) { d = s; }
|
|
|
|
static __forceinline void OpA(BYTE &d, BYTE s, FCopyInfo *i) { d = s; }
|
|
|
|
static __forceinline bool ProcessAlpha0() { return true; }
|
2008-04-15 22:17:30 +00:00
|
|
|
};
|
|
|
|
|
2008-04-22 18:48:30 +00:00
|
|
|
struct bBlend
|
|
|
|
{
|
|
|
|
static __forceinline void OpC(BYTE &d, BYTE s, BYTE a, FCopyInfo *i) { d = (d*i->invalpha + s*i->alpha) >> FRACBITS; }
|
|
|
|
static __forceinline void OpA(BYTE &d, BYTE s, FCopyInfo *i) { d = s; }
|
2008-05-17 08:18:31 +00:00
|
|
|
static __forceinline bool ProcessAlpha0() { return false; }
|
2008-04-22 18:48:30 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
struct bAdd
|
|
|
|
{
|
|
|
|
static __forceinline void OpC(BYTE &d, BYTE s, BYTE a, FCopyInfo *i) { d = MIN<int>((d*FRACUNIT + s*i->alpha) >> FRACBITS, 255); }
|
|
|
|
static __forceinline void OpA(BYTE &d, BYTE s, FCopyInfo *i) { d = s; }
|
2008-05-17 08:18:31 +00:00
|
|
|
static __forceinline bool ProcessAlpha0() { return false; }
|
2008-04-22 18:48:30 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
struct bSubtract
|
|
|
|
{
|
|
|
|
static __forceinline void OpC(BYTE &d, BYTE s, BYTE a, FCopyInfo *i) { d = MAX<int>((d*FRACUNIT - s*i->alpha) >> FRACBITS, 0); }
|
|
|
|
static __forceinline void OpA(BYTE &d, BYTE s, FCopyInfo *i) { d = s; }
|
2008-05-17 08:18:31 +00:00
|
|
|
static __forceinline bool ProcessAlpha0() { return false; }
|
2008-04-22 18:48:30 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
struct bReverseSubtract
|
|
|
|
{
|
|
|
|
static __forceinline void OpC(BYTE &d, BYTE s, BYTE a, FCopyInfo *i) { d = MAX<int>((-d*FRACUNIT + s*i->alpha) >> FRACBITS, 0); }
|
|
|
|
static __forceinline void OpA(BYTE &d, BYTE s, FCopyInfo *i) { d = s; }
|
2008-05-17 08:18:31 +00:00
|
|
|
static __forceinline bool ProcessAlpha0() { return false; }
|
2008-04-22 18:48:30 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
struct bModulate
|
|
|
|
{
|
|
|
|
static __forceinline void OpC(BYTE &d, BYTE s, BYTE a, FCopyInfo *i) { d = (s*d)/255; }
|
|
|
|
static __forceinline void OpA(BYTE &d, BYTE s, FCopyInfo *i) { d = s; }
|
2008-05-17 08:18:31 +00:00
|
|
|
static __forceinline bool ProcessAlpha0() { return false; }
|
2008-04-22 18:48:30 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
struct bCopyAlpha
|
|
|
|
{
|
|
|
|
static __forceinline void OpC(BYTE &d, BYTE s, BYTE a, FCopyInfo *i) { d = (s*a + d*(255-a))/255; }
|
|
|
|
static __forceinline void OpA(BYTE &d, BYTE s, FCopyInfo *i) { d = s; }
|
2008-05-17 08:18:31 +00:00
|
|
|
static __forceinline bool ProcessAlpha0() { return false; }
|
2008-04-22 18:48:30 +00:00
|
|
|
};
|
2008-04-15 22:17:30 +00:00
|
|
|
|
|
|
|
|
2008-04-15 18:05:39 +00:00
|
|
|
|
2008-04-16 20:02:16 +00:00
|
|
|
#endif
|