📄 halutils.c
字号:
/******************************************************************************
<module>
* Name : halutils.c
* Title : Utility functions
* Author(s) : Imagination Technologies
* Created : 26 May 2004
*
* Copyright : 2004 by Imagination Technologies Limited.
* All rights reserved. No part of this software, either
* material or conceptual may be copied or distributed,
* transmitted, transcribed, stored in a retrieval system
* or translated into any human or computer language in any
* form by any means, electronic, mechanical, manual or
* other-wise, or disclosed to third parties without the
* express written permission of Imagination Technologies
* Limited, Unit 8, HomePark Industrial Estate,
* King's Langley, Hertfordshire, WD4 8LZ, U.K.
*
* Description : Utility functions
*
* Platform : Windows CE
*
$Log: halutils.c $
********************************************************************************/
#include "ddraw_headers.h"
/*****************************************************************************
FUNCTION : ConvertARGBColourToPFColour
PURPOSE : Convert a 32bpp ARGB value into a destination pixel format.
We're only interested in display surface formats.
The conversion method used
simulates the hardware conversion technique.
PARAMETERS : DWORD dwDestFormat - MBXDD_FORMAT of destination pixel
DWORD dwRGBColour - 32Bpp ARGB Colour
RETURNS : DWORD dwPFColour - Colour in destination pixel format
*****************************************************************************/
DWORD ConvertARGBColourToPFColour(DWORD dwDestFormat, DWORD dwRGBColour)
{
DWORD dwPFColour;
switch(dwDestFormat)
{
case MBXDD_FORMAT_RGB565:
{
/*
DITHERING must be disabled for this to work
*/
dwPFColour = (dwRGBColour >> 8) & 0xf800;
dwPFColour |= (dwRGBColour >> 5) & 0x07e0;
dwPFColour |= (dwRGBColour >> 3) & 0x001f;
break;
}
case MBXDD_FORMAT_RGB555:
{
/*
DITHERING must be disabled for this to work
*/
dwPFColour = (dwRGBColour >> 9) & 0x7c00;
dwPFColour |= (dwRGBColour >> 6) & 0x03e0;
dwPFColour |= (dwRGBColour >> 3) & 0x001f;
break;
}
case MBXDD_FORMAT_RGB888:
{
dwPFColour = dwRGBColour & 0x00ffffff;
break;
}
case MBXDD_FORMAT_BGR888:
{
dwPFColour = (dwRGBColour << 16) & 0x00ff0000;
dwPFColour |= (dwRGBColour ) & 0x0000ff00;
dwPFColour |= (dwRGBColour >> 16) & 0x000000ff;
break;
}
case MBXDD_FORMAT_ARGB1555:
{
dwPFColour = (dwRGBColour >> 16) & 0x8000;
dwPFColour |= (dwRGBColour >> 9) & 0x7c00;
dwPFColour |= (dwRGBColour >> 6) & 0x03e0;
dwPFColour |= (dwRGBColour >> 3) & 0x001f;
break;
}
case MBXDD_FORMAT_ARGB4444:
{
dwPFColour = (dwRGBColour >> 16) & 0xf000;
dwPFColour |= (dwRGBColour >> 12) & 0x0f00;
dwPFColour |= (dwRGBColour >> 8) & 0x00f0;
dwPFColour |= (dwRGBColour >> 4) & 0x000f;
break;
}
case MBXDD_FORMAT_ARGB8888:
{
dwPFColour = dwRGBColour;
break;
}
case MBXDD_FORMAT_ABGR8888:
{
dwPFColour = (dwRGBColour ) & 0xff000000;
dwPFColour |= (dwRGBColour << 16) & 0x00ff0000;
dwPFColour |= (dwRGBColour ) & 0x0000ff00;
dwPFColour |= (dwRGBColour >> 16) & 0x000000ff;
break;
}
default:
{
/*
Unknown format, return what we were given (stops compiler warning).
*/
DPFL2("ConvertRGBColourToPFColour: Warning, unknown format");
dwPFColour = dwRGBColour;
break;
}
}
return(dwPFColour);
}
/*****************************************************************************
FUNCTION : ConvertPFCKToMBX3DCK
PURPOSE : Converts Color Key colour value in a given pixel format to
24-bit RGB format, which is used by h/w CK registers.
PARAMETERS : dwColourKey - CK value in pixel format
sPixelFormat - pixel format.
dwTSPCtl - TSP control - containing MBX 3d texture format
pvDDPalette - ddraw palette for use with palettised textures
bReplicate - replicate each CK channel value into low order bits
(dont use for strided textures).
RETURNS : 24-bit RGB CK value.
*****************************************************************************/
DWORD ConvertPFCKToMBX3DCK( DWORD dwColourKey,
LPDDPIXELFORMAT psPixelFormat,
DWORD dwTSPCtl,
PVOID pvDDPalette,
BOOL bReplicate)
{
DWORD dw24BitColour;
DWORD dwSrc;
DWORD dwRYLMask, dwGUMask, dwBVMask;
/*
get local parameters.
*/
dwSrc = dwColourKey;
DPFL4("ConvertPFCKToMBX3DCK source CK low %8.8lX",dwSrc);
/*
Give colour an initial value to please the compiler
*/
dw24BitColour = 0;
/*
dwSrc is a colour is some 16 bit format - we have to examine the
surface to retrieve the precise format from the Texture Control
word and then convert it.
*/
dwRYLMask = psPixelFormat->dwRBitMask; /* Red, Y and luminance masks. */
dwGUMask = psPixelFormat->dwGBitMask; /* Green and U maskes. */
dwBVMask = psPixelFormat->dwBBitMask; /* Blue and V masks. */
switch (dwTSPCtl & (~MBX1_TSPPL1_TPIXFORMCLRMASK))
{
pvDDPalette;
case MBX1_TSPPL1_TPIXFORM1555:
{
dw24BitColour = (dwSrc & dwRYLMask) << 9;
dw24BitColour |= (dwSrc & dwGUMask) << 6;
dw24BitColour |= (dwSrc & dwBVMask) << 3;
if (bReplicate)
{
dw24BitColour |= (dwSrc & 0x00007000) << 4;
dw24BitColour |= (dwSrc & 0x00000380) << 1;
dw24BitColour |= (dwSrc & 0x0000001C) >> 2;
}
break;
}
case MBX1_TSPPL1_TPIXFORM565:
{
dw24BitColour = (dwSrc & dwRYLMask) << 8;
dw24BitColour |= (dwSrc & dwGUMask) << 5;
dw24BitColour |= (dwSrc & dwBVMask) << 3;
if (bReplicate)
{
dw24BitColour |= (dwSrc & 0x0000E000) << 3;
dw24BitColour |= (dwSrc & 0x00000600) >> 1;
dw24BitColour |= (dwSrc & 0x0000001F) >> 2;
}
break;
}
case MBX1_TSPPL1_TPIXFORM4444:
{
dw24BitColour = (dwSrc & 0x00000F00) << 12;
dw24BitColour |= (dwSrc & 0x000000F0) << 8;
dw24BitColour |= (dwSrc & 0x0000000F) << 4;
if (bReplicate)
{
dw24BitColour |= (dwSrc & 0x00000F00) << 8;
dw24BitColour |= (dwSrc & 0x000000F0) << 4;
dw24BitColour |= (dwSrc & 0x0000000F);
}
break;
}
case MBX1_TSPPL1_TPIXFORM8332:
{
dw24BitColour = (dwSrc & dwRYLMask) << 16; // Red
dw24BitColour |= (dwSrc & dwRYLMask) << 13; // Red
dw24BitColour |= (dwSrc & 0xC0) << 10; // Red
dw24BitColour |= (dwSrc & dwGUMask) << 11; // Green
dw24BitColour |= (dwSrc & dwGUMask) << 8; // Green
dw24BitColour |= (dwSrc & 0x18) << 5; // Green
dw24BitColour |= (dwSrc & dwBVMask) << 6; // Blue
dw24BitColour |= (dwSrc & dwBVMask) << 4; // Blue
dw24BitColour |= (dwSrc & dwBVMask) << 2; // Blue
dw24BitColour |= (dwSrc & dwBVMask) << 0; // Blue
break;
}
case MBX1_TSPPL1_TPIXFORMY1VY0U:
case MBX1_TSPPL1_TPIXFORMVY1UY0:
{
dw24BitColour = (dwSrc & (dwRYLMask | dwGUMask | dwBVMask));
break;
}
case MBX1_TSPPL1_TPIXFORM8:
{
dw24BitColour = (dwSrc & dwRYLMask);
dw24BitColour |= ((dwSrc & dwRYLMask) << 8);
dw24BitColour |= ((dwSrc & dwRYLMask) << 16);
break;
}
case MBX1_TSPPL1_TPIXFORM88:
{
dw24BitColour = (dwSrc & 0xff);
dw24BitColour |= ((dwSrc & 0xff) << 8);
dw24BitColour |= ((dwSrc & 0xff) << 16);
break;
}
case MBX1_TSPPL1_TPIXFORM8888:
{
dw24BitColour = (dwSrc & 0xffffff);
break;
}
#if DEBUG
case MBX1_TSPPL1_TPIXFORMPVRTC2:
case MBX1_TSPPL1_TPIXFORMPVRTC4:
case MBX1_TSPPL1_TPIXFORM1:
{
DPF("ConvertPFCKToMBX3DCK: texture format is PVRTC2/4 or 1-bit Alpha, doing nothing");
break;
}
default:
{
DPF("ConvertPFCKToMBX3DCK: Unknown pixel format in TextureCtl");
break;
}
#endif
}
DPFL4("ConvertPFCKToMBX3DCK dw24BitColour %8.8lX",dw24BitColour);
return (dw24BitColour);
}
/*****************************************************************************
FUNCTION : ConvertColour
PURPOSE : Convert colour to 32 (24) bit (A)RGB.
PARAMETERS : LPDDRAWI_DDRAWSURFACE_LCL psDDSurfLcl - DD surface local
DWORD dwSrc - colour in source format
DWORD dwTSPCtl - MBX1 TSPCtl word, only tex format is required
RETURNS : Converted colour
*****************************************************************************/
DWORD ConvertColour(LPDDRAWI_DDRAWSURFACE_LCL psDDSurfLcl, DWORD dwSrc, DWORD dwTSPCtl)
{
PSURFDATA psSurfData;
DWORD dw24BitColour;
BOOL bReplicate;
psSurfData = (PSURFDATA) psDDSurfLcl->lpGbl->dwReserved1;
/*
If the source texture is stride based, then the key colour doesn't
get the higher bits replicated into the lower. Previously we
Replicated if the source had the TWIDDLED or RESCAN_FOR_CK surface
flags bit set, but Speedbusters failed. Now try for it not being a
3D Device.
*/
bReplicate = FALSE;
if (!(psSurfData->dwDDSCaps & DDSCAPS_3DDEVICE))
{
bReplicate = TRUE;
}
/*
Windows 2000 doesn't know about palettes the same way as Win9x.
*/
dw24BitColour = ConvertPFCKToMBX3DCK(dwSrc,
&psSurfData->sPixelFormat,
dwTSPCtl,
psDDSurfLcl->lp16DDPalette,
bReplicate);
return (dw24BitColour);
}
/*****************************************************************************
FUNCTION : ConvertPixelFormatToMBX
PURPOSE : To create the dwMBXFormat value from DirectDraw's DDPIXELFORMAT
pixel format.
PARAMETERS : LPDDPIXELFORMAT lpPixelFormat
RETURNS : DDHAL return code.
*****************************************************************************/
DWORD ConvertPixelFormatToMBX(LPDDPIXELFORMAT lpPixelFormat)
{
DWORD dwMBXFormat;
dwMBXFormat = 0;
if (lpPixelFormat->dwFlags & DDPF_FOURCC)
{
/*
Read FourCC flag.
*/
switch (lpPixelFormat->dwFourCC)
{
case HALFOURCC_UYVY:
case HALFOURCC_UYNV:
{
dwMBXFormat = MBXDD_FORMAT_UYVY;
break;
}
case HALFOURCC_YUY2:
case HALFOURCC_YUYV:
case HALFOURCC_YUNV:
{
dwMBXFormat = MBXDD_FORMAT_YUYV;
break;
}
case HALFOURCC_YVYU:
{
dwMBXFormat = MBXDD_FORMAT_YVYU;
break;
}
case HALFOURCC_VYUY:
{
dwMBXFormat = MBXDD_FORMAT_VYUY;
break;
}
case HALFOURCC_YV12:
{
dwMBXFormat = MBXDD_FORMAT_YV12;
break;
}
case HALFOURCC_IMC2:
{
dwMBXFormat = MBXDD_FORMAT_IMC2;
break;
}
case HALFOURCC_PVRTC2:
{
dwMBXFormat = MBXDD_FORMAT_PVRTC2;
break;
}
case HALFOURCC_PVRTC4:
{
dwMBXFormat = MBXDD_FORMAT_PVRTC4;
break;
}
case HALFOURCC_0888:
{
/*
Dummy the format.
This is a valid texture surface but not a 2D surface.
*/
dwMBXFormat = MBXDD_FORMAT_YUYV;
break;
}
default:
{
DPF("ConvertPixelFormatToMBX: Unrecognised FourCC pixel format.");
break;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -