You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
229 lines
6.7 KiB
229 lines
6.7 KiB
//-----------------------------------------------------------------------------
|
|
//
|
|
// This file contains texture read functions.
|
|
//
|
|
// Copyright (C) Microsoft Corporation, 1997.
|
|
//
|
|
//-----------------------------------------------------------------------------
|
|
include(`m4hdr.mh')dnl
|
|
#include "rgb_pch.h"
|
|
#pragma hdrstop
|
|
#include "ctxrd_mh.h"
|
|
|
|
// Names are read LSB to MSB, so B5G6R5 means five bits of blue starting
|
|
// at the LSB, then six bits of green, then five bits of red.
|
|
dnl
|
|
dnl d_DoTex
|
|
dnl
|
|
dnl Calls the macro in $1 with all options to generate differentiated texture
|
|
dnl read functions
|
|
dnl
|
|
define(`d_DoTex', `d_Null($1(NoBorder, NoColorKey))
|
|
d_Null($1(NoBorder, ColorKey))
|
|
d_Null($1(Border, NoColorKey))
|
|
d_Null($1(Border, ColorKey))')dnl
|
|
dnl
|
|
dnl d_DoBorder
|
|
dnl
|
|
dnl Inserts conditional border code
|
|
dnl
|
|
define(`d_DoBorder', `ifelse(`$1', `NoBorder', `', `
|
|
if ((iU < 0) || (iV < 0))
|
|
{
|
|
return pTex->BorderColor;
|
|
}')')dnl
|
|
dnl
|
|
dnl d_DoColorKey
|
|
dnl
|
|
dnl Inserts conditional color key code
|
|
dnl $1 the function type, $2 is the thing to test against the Transparent color,
|
|
dnl and $3 is its type.
|
|
dnl
|
|
define(`d_DoColorKey', `ifelse(`$1', `NoColorKey', `', `
|
|
if ($2 == $3pTex->TransparentColor)
|
|
{
|
|
Color &= 0xffffff;
|
|
}')')dnl
|
|
dnl
|
|
define(`d_B8G8R8', `
|
|
D3DCOLOR C_TexRead_B8G8R8_$1_$2(INT32 iU, INT32 iV, INT32 iShiftU, PUINT8 pBits, PD3DI_SPANTEX pTex)
|
|
{
|
|
d_DoBorder(`$1')
|
|
UINT32 uTexel = ((UINT32*)pBits)[iU | (iV << iShiftU)];
|
|
D3DCOLOR Color = uTexel | 0xff000000;
|
|
d_DoColorKey(`$2', uTexel)
|
|
return Color;
|
|
}')dnl
|
|
d_DoTex(`d_B8G8R8')
|
|
dnl
|
|
define(`d_B8G8R8A8', `
|
|
D3DCOLOR C_TexRead_B8G8R8A8_$1_$2(INT32 iU, INT32 iV, INT32 iShiftU, PUINT8 pBits, PD3DI_SPANTEX pTex)
|
|
{
|
|
d_DoBorder(`$1')
|
|
D3DCOLOR Color = ((D3DCOLOR*)pBits)[iU | (iV << iShiftU)];
|
|
d_DoColorKey(`$2', Color)
|
|
return Color;
|
|
}')dnl
|
|
d_DoTex(`d_B8G8R8A8')
|
|
dnl
|
|
define(`d_B5G6R5', `
|
|
D3DCOLOR C_TexRead_B5G6R5_$1_$2(INT32 iU, INT32 iV, INT32 iShiftU, PUINT8 pBits, PD3DI_SPANTEX pTex)
|
|
{
|
|
d_DoBorder(`$1')
|
|
UINT16 uTexel = ((UINT16*)pBits)[iU | (iV << iShiftU)];
|
|
D3DCOLOR Color = RGBA_MAKE(( uTexel >> 8 ) & 0xf8,
|
|
(( uTexel >> 3) & 0xfc ),
|
|
(( uTexel << 3) & 0xf8 ),
|
|
0xff);
|
|
d_DoColorKey(`$2', uTexel, `(UINT16)')
|
|
return Color;
|
|
}')dnl
|
|
d_DoTex(`d_B5G6R5')
|
|
dnl
|
|
define(`d_B5G5R5', `
|
|
D3DCOLOR C_TexRead_B5G5R5_$1_$2(INT32 iU, INT32 iV, INT32 iShiftU, PUINT8 pBits, PD3DI_SPANTEX pTex)
|
|
{
|
|
d_DoBorder(`$1')
|
|
UINT16 uTexel = ((UINT16*)pBits)[iU | (iV << iShiftU)];
|
|
D3DCOLOR Color = RGBA_MAKE(( uTexel >> 7 ) & 0xf8,
|
|
(( uTexel >> 2) & 0xf8 ),
|
|
(( uTexel << 3) & 0xf8 ),
|
|
0xff);
|
|
d_DoColorKey(`$2', uTexel, `(UINT16)')
|
|
return Color;
|
|
}')dnl
|
|
d_DoTex(`d_B5G5R5')
|
|
dnl
|
|
define(`d_B5G5R5A1', `
|
|
D3DCOLOR C_TexRead_B5G5R5A1_$1_$2(INT32 iU, INT32 iV, INT32 iShiftU, PUINT8 pBits, PD3DI_SPANTEX pTex)
|
|
{
|
|
d_DoBorder(`$1')
|
|
INT16 iTexel = ((INT16*)pBits)[iU | (iV << iShiftU)];
|
|
D3DCOLOR Color = RGBA_MAKE(( iTexel >> 7 ) & 0xf8,
|
|
(( iTexel >> 2) & 0xf8 ),
|
|
(( iTexel << 3) & 0xf8 ),
|
|
(iTexel >> 15) & 0xff);
|
|
d_DoColorKey(`$2', iTexel, `(INT16)')
|
|
return Color;
|
|
}')dnl
|
|
d_DoTex(`d_B5G5R5A1')
|
|
dnl
|
|
define(`d_B4G4R4A4', `
|
|
D3DCOLOR C_TexRead_B4G4R4A4_$1_$2(INT32 iU, INT32 iV, INT32 iShiftU, PUINT8 pBits, PD3DI_SPANTEX pTex)
|
|
{
|
|
d_DoBorder(`$1')
|
|
INT16 iTexel = ((INT16*)pBits)[iU | (iV << iShiftU)];
|
|
INT16 iAlpha = ( iTexel >> 12 ) & 0xf;
|
|
D3DCOLOR Color = RGBA_MAKE((( iTexel >> 4 ) & 0xf0),
|
|
(( iTexel >> 0) & 0xf0 ),
|
|
(( iTexel << 4) & 0xf0 ),
|
|
(iAlpha << 4) | iAlpha );
|
|
d_DoColorKey(`$2', iTexel, `(INT16)')
|
|
return Color;
|
|
}')dnl
|
|
d_DoTex(`d_B4G4R4A4')
|
|
dnl
|
|
|
|
define(`d_L8', `
|
|
D3DCOLOR C_TexRead_L8_$1_$2(INT32 iU, INT32 iV, INT32 iShiftU, PUINT8 pBits, PD3DI_SPANTEX pTex)
|
|
{
|
|
d_DoBorder(`$1')
|
|
UINT8 uTexel = ((UINT8*)pBits)[iU | (iV << iShiftU)];
|
|
D3DCOLOR Color = RGBA_MAKE(uTexel,
|
|
uTexel,
|
|
uTexel,
|
|
0xff );
|
|
d_DoColorKey(`$2', uTexel, `(UINT8)')
|
|
return Color;
|
|
}')dnl
|
|
d_DoTex(`d_L8')
|
|
dnl
|
|
define(`d_L8A8', `
|
|
D3DCOLOR C_TexRead_L8A8_$1_$2(INT32 iU, INT32 iV, INT32 iShiftU, PUINT8 pBits, PD3DI_SPANTEX pTex)
|
|
{
|
|
d_DoBorder(`$1')
|
|
UINT16 uTexel = ((UINT16*)pBits)[iU | (iV << iShiftU)];
|
|
UINT16 uAlpha = ( uTexel >> 8 ) & 0xff;
|
|
UINT16 uTexel8 = uTexel & 0xff;
|
|
D3DCOLOR Color = RGBA_MAKE(uTexel8,
|
|
uTexel8,
|
|
uTexel8,
|
|
uAlpha );
|
|
d_DoColorKey(`$2', uTexel, `(UINT16)')
|
|
return Color;
|
|
}')dnl
|
|
d_DoTex(`d_L8A8')
|
|
dnl
|
|
dnl
|
|
dnl
|
|
dnl d_CheckPalette4
|
|
dnl
|
|
dnl Index computation for palette4, otherwise just retrieve iTexel for palette8
|
|
dnl $1 the function type,
|
|
dnl
|
|
define(`d_CheckPalette4', `ifelse(eval(d_index(`$1', `Palette4') >= 0), `1', `
|
|
INT32 iTexel = pBits[iIndex>>1];
|
|
if ((iIndex & 1) == 0)
|
|
{
|
|
iTexel &= 0xf;
|
|
}
|
|
else
|
|
{
|
|
iTexel >>= 4;
|
|
}', `
|
|
INT32 iTexel = pBits[iIndex];')')dnl
|
|
dnl
|
|
dnl
|
|
dnl
|
|
dnl d_DoPaletteAlpha
|
|
dnl
|
|
dnl Check if palette has alpha
|
|
dnl $1 the function type,
|
|
dnl
|
|
define(`d_DoPaletteAlpha', `ifelse(eval(d_index(`$1', `A') >= 0), `1', `
|
|
Color = RGBA_MAKE((Color & 0xff),
|
|
(Color >> 8) & 0xff,
|
|
(Color >> 16) & 0xff,
|
|
(Color >> 24) & 0xff);', `
|
|
Color = RGBA_MAKE((Color & 0xff),
|
|
(Color >> 8) & 0xff,
|
|
(Color >> 16) & 0xff,
|
|
0xff);')')dnl
|
|
dnl
|
|
define(`d_Palette', `
|
|
d_DoBorder(`$1')
|
|
INT32 iIndex = iU | (iV << iShiftU);
|
|
d_CheckPalette4(`$3')
|
|
D3DCOLOR Color = pTex->pPalette[iTexel];
|
|
|
|
// RL palette is BGR - flip the channels into RGB
|
|
d_DoPaletteAlpha(`$3')
|
|
d_DoColorKey(`$2', iTexel, `(INT32)')
|
|
return Color;
|
|
')dnl
|
|
dnl
|
|
define(`d_Palette8', `
|
|
D3DCOLOR C_TexRead_Palette8_$1_$2(INT32 iU, INT32 iV, INT32 iShiftU, PUINT8 pBits, PD3DI_SPANTEX pTex)
|
|
{
|
|
d_Palette($1, $2, Palette8)
|
|
}')dnl
|
|
d_DoTex(`d_Palette8')
|
|
define(`d_Palette4', `
|
|
D3DCOLOR C_TexRead_Palette4_$1_$2(INT32 iU, INT32 iV, INT32 iShiftU, PUINT8 pBits, PD3DI_SPANTEX pTex)
|
|
{
|
|
d_Palette($1, $2, Palette4)
|
|
}')dnl
|
|
d_DoTex(`d_Palette4')
|
|
dnl
|
|
define(`d_Palette8A', `
|
|
D3DCOLOR C_TexRead_Palette8A_$1_$2(INT32 iU, INT32 iV, INT32 iShiftU, PUINT8 pBits, PD3DI_SPANTEX pTex)
|
|
{
|
|
d_Palette($1, $2, Palette8A)
|
|
}')dnl
|
|
d_DoTex(`d_Palette8A')
|
|
define(`d_Palette4A', `
|
|
D3DCOLOR C_TexRead_Palette4A_$1_$2(INT32 iU, INT32 iV, INT32 iShiftU, PUINT8 pBits, PD3DI_SPANTEX pTex)
|
|
{
|
|
d_Palette($1, $2, Palette4A)
|
|
}')dnl
|
|
d_DoTex(`d_Palette4A')
|