⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 colormap.c

📁 著名的 helix realplayer 基于手机 symbian 系统的 播放器全套源代码
💻 C
📖 第 1 页 / 共 2 页
字号:
/* ***** BEGIN LICENSE BLOCK ***** 
 * Version: RCSL 1.0/RPSL 1.0 
 *  
 * Portions Copyright (c) 1995-2002 RealNetworks, Inc. All Rights Reserved. 
 *      
 * The contents of this file, and the files included with this file, are 
 * subject to the current version of the RealNetworks Public Source License 
 * Version 1.0 (the "RPSL") available at 
 * http://www.helixcommunity.org/content/rpsl unless you have licensed 
 * the file under the RealNetworks Community Source License Version 1.0 
 * (the "RCSL") available at http://www.helixcommunity.org/content/rcsl, 
 * in which case the RCSL will apply. You may also obtain the license terms 
 * directly from RealNetworks.  You may not use this file except in 
 * compliance with the RPSL or, if you have a valid RCSL with RealNetworks 
 * applicable to this file, the RCSL.  Please see the applicable RPSL or 
 * RCSL for the rights, obligations and limitations governing use of the 
 * contents of the file.  
 *  
 * This file is part of the Helix DNA Technology. RealNetworks is the 
 * developer of the Original Code and owns the copyrights in the portions 
 * it created. 
 *  
 * This file, and the files included with this file, is distributed and made 
 * available on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER 
 * EXPRESS OR IMPLIED, AND REALNETWORKS HEREBY DISCLAIMS ALL SUCH WARRANTIES, 
 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, FITNESS 
 * FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. 
 * 
 * Technology Compatibility Kit Test Suite(s) Location: 
 *    http://www.helixcommunity.org/content/tck 
 * 
 * Contributor(s): 
 *  
 * ***** END LICENSE BLOCK ***** */ 

#include "hxtypes.h"
#if defined(_WIN32) && !defined(_WINCE)
/* Windows include files: */
#include <windows.h>
#include <vfw.h>
#include <ddraw.h>
#include "hxtypes.h"
#elif defined(_WINCE)
#include "hxwintyp.h"
#include <windows.h>
#include "hxcom.h"
//#undef _WIN32
#include "hxvsurf.h"
#endif

#include "hxcom.h"
#include "hlxclib/string.h"
#include "hxtypes.h"
#include "hxwintyp.h"
#include "hxvsurf.h"

/* Color IDs:*/
#include "colormap.h"

/*
 * FOURCC codes (in addition to what is defined in wingdi.h):
 */

/* standard YUV formats: */
#define BI_I420         MAKEFOURCC('I','4','2','0') /* planar YCrCb   */
#define BI_YUVA         MAKEFOURCC('Y','U','V','A') /* planar YVU 420 plus alpha plane */
#define BI_YV12         MAKEFOURCC('Y','V','1','2') /* planar YVU 420 */
#define BI_YVU9         MAKEFOURCC('Y','V','U','9') /* planar YVU 420 */
#define BI_YUY2         MAKEFOURCC('Y','U','Y','2') /* packed YVU 422 */
#define BI_UYVY         MAKEFOURCC('U','Y','V','Y') /* packed YVU 422 */
#define BI_DVPF         MAKEFOURCC('D','V','P','F') /* planar YCrCb in structure */

/* Xing decoder's YUV format */
#define BI_XING         MAKEFOURCC('X','I','N','G')

/* MPEG-2 pre-decoded formats: */
#define BI_MC12         MAKEFOURCC('M','C','1','2') /* ATI MPEG-2 M/C */
#define BI_MCAM         MAKEFOURCC('M','C','A','M') /* ATI MPEG-2 M/C */
#define BI_MCS3         MAKEFOURCC('M','C','S','3') /* S3 MPEG-2 M/C  */
#define BI_IGOR         MAKEFOURCC('I','G','O','R') /* Intel i810 M/C */

/* RMA proprietary formats: */
#ifndef HXCOLOR_RGB3_ID
#define HXCOLOR_RGB3_ID     MAKEFOURCC('3','B','G','R') /* RGB-32 ??      */
#define HXCOLOR_RGB24_ID    MAKEFOURCC('B','G','R',' ') /* top-down RGB-24*/
#define HXCOLOR_RGB565_ID   MAKEFOURCC('6','B','G','R') /* RGB-16 565     */
#define HXCOLOR_RGB555_ID   MAKEFOURCC('5','B','G','R') /* RGB-16 555     */
#define HXCOLOR_8BIT_ID     MAKEFOURCC('T','I','B','8') /* RGB-8 w. pal-e */
#define HXCOLOR_YUV420_ID   MAKEFOURCC('2','V','U','Y') /* planar YCrCb   */
#define HXCOLOR_YUV411_ID   MAKEFOURCC('1','V','U','Y') /* ???            */
#define HXCOLOR_YUVRAW_ID   MAKEFOURCC('R','V','U','Y') /* ???            */
#endif

/*
 * Color format tables:
 */

/* control flags: */
#define _FOURCC   0x01
#define _BITCOUNT 0x02
#define _BITMASK  0x04

/* color format descriptor: */

struct _greg
{
    ULONG32 dwFlags;              /* indicates valid fields       */
    ULONG32 dwFourCC;             /* FourCC code                  */
    ULONG32 dwBitCount;           /* number of bits/pixel         */
    ULONG32 dwBitMask [3];        /* RGB bit masks                */
};

typedef struct _greg  CIDD;
typedef struct _greg* LPCIDD;

/* color format descriptors to use with YUV bitmaps: */
static const CIDD ciddI420      = {_FOURCC,                    BI_I420,       12, {       0,        0,        0}};
static const CIDD ciddYUVA      = {_FOURCC,                    BI_YUVA,       20, {       0,        0,        0}};
static const CIDD ciddYV12      = {_FOURCC,                    BI_YV12,       12, {       0,        0,        0}};
static const CIDD ciddYVU9      = {_FOURCC,                    BI_YVU9,        9, {       0,        0,        0}};
static const CIDD ciddYUY2      = {_FOURCC,                    BI_YUY2,       16, {       0,        0,        0}};
static const CIDD ciddUYVY      = {_FOURCC,                    BI_UYVY,       16, {       0,        0,        0}};
static const CIDD ciddDVPF      = {_FOURCC,                    BI_DVPF,       12, {       0,        0,        0}};
static const CIDD ciddXING      = {_FOURCC,                    BI_XING,       16, {       0,        0,        0}};


/* color format descriptors to use with GDI RGB bitmaps: */
static const CIDD ciddBmpRGB32  = {_FOURCC+_BITCOUNT,          BI_RGB,        32, {       0,        0,        0}};
static const CIDD ciddBmpARGB32 = {_FOURCC+_BITCOUNT,          HX_ARGB,      32, {       0,        0,        0}};
static const CIDD ciddBmpRGB24  = {_FOURCC+_BITCOUNT,          BI_RGB,        24, {       0,        0,        0}};
static const CIDD ciddBmpRGB565 = {_FOURCC+_BITCOUNT+_BITMASK, BI_BITFIELDS,  16, {  0xF800,   0x07E0,   0x001F}};
static const CIDD ciddBmpRGB555 = {_FOURCC+_BITCOUNT+_BITMASK, BI_BITFIELDS,  16, {  0x7C00,   0x03E0,   0x001F}};
static const CIDD ciddBmpRGB8   = {_FOURCC+_BITCOUNT,          BI_RGB,         8, {       0,        0,        0}};

/* color format descriptors to use with DirectDraw RGB surfaces: */
static const CIDD ciddDDrRGB32  = {_FOURCC+_BITCOUNT+_BITMASK, BI_RGB,        32, {0xFF0000, 0x00FF00, 0x0000FF}};
static const CIDD ciddDDrARGB32 = {_FOURCC+_BITCOUNT+_BITMASK, HX_ARGB,      32, {0xFF0000, 0x00FF00, 0x0000FF}};
static const CIDD ciddDDrRGB24  = {_FOURCC+_BITCOUNT+_BITMASK, BI_RGB,        24, {0xFF0000, 0x00FF00, 0x0000FF}};
static const CIDD ciddDDrRGB565 = {_FOURCC+_BITCOUNT+_BITMASK, BI_RGB,        16, {  0xF800,   0x07E0,   0x001F}};
static const CIDD ciddDDrRGB555 = {_FOURCC+_BITCOUNT+_BITMASK, BI_RGB,        16, {  0x7C00,   0x03E0,   0x001F}};
static const CIDD ciddDDrRGB8   = {_FOURCC+_BITCOUNT,          BI_RGB,         8, {       0,        0,        0}};

/* color format descriptors to use with BRG bitmaps: */
static const CIDD ciddBGR32     = {_FOURCC+_BITCOUNT+_BITMASK, BI_BITFIELDS,  32, {0x0000FF, 0x00FF00, 0xFF0000}};
static const CIDD ciddBGR24     = {_FOURCC+_BITCOUNT+_BITMASK, BI_RGB,        24, {0x0000FF, 0x00FF00, 0xFF0000}};

/* color format descriptors to use with QuickTime byte swapped formats: */
static const CIDD ciddRGB32S    = {_FOURCC+_BITCOUNT+_BITMASK, BI_RGB,        32, {0x00FF00, 0xFF0000, 0xFF000000}};

/* color format descriptors to use with embedded device formats: */
static const CIDD ciddRGB444    = {_FOURCC+_BITCOUNT+_BITMASK, BI_BITFIELDS,  16, {  0x0F00,   0x00F0,   0x000F}};

/* color format descriptors to use with MPEG bitmaps: */
static const CIDD ciddMC12      = {_FOURCC,                    BI_MC12,       12, {       0,        0,        0}};
static const CIDD ciddMCAM      = {_FOURCC,                    BI_MCAM,       12, {       0,        0,        0}};
static const CIDD ciddMCS3      = {_FOURCC,                    BI_MCS3,       12, {       0,        0,        0}};
static const CIDD ciddIGOR      = {_FOURCC,                    BI_IGOR,       12, {       0,        0,        0}};

/* non-standard descriptors we should support: */
struct _stColors
{
    int cid;                    /* image format ID              */
    CIDD  cidd;                 /* color format descriptor      */
};

static const struct _stColors ciddlOtherColors [] = {
    {CID_I420, {_FOURCC,                    HXCOLOR_YUV420_ID, 12, {         0,          0,          0}}},
    {CID_YUVA,              {_FOURCC,                    HXCOLOR_YUVA_ID,   20, {         0,          0,          0}}},
    {CID_RGB32,             {_FOURCC+_BITCOUNT+_BITMASK, BI_BITFIELDS,      32, {0xFF000000, 0x00FF0000, 0x0000FF00}}}, 
    {CID_RGB565,            {_FOURCC+_BITCOUNT+_BITMASK, BI_BITFIELDS,      16, {0x0000f800, 0x000007c0, 0x0000003e}}}, 
    {CID_RGB32,             {_FOURCC+_BITCOUNT+_BITMASK, BI_BITFIELDS,      32, {  0xFF0000,   0x00FF00,   0x0000FF}}},
    {CID_RGB32,             {_FOURCC+_BITCOUNT,          HXCOLOR_RGB3_ID,   32, {         0,          0,          0}}},
    {CID_RGB24,             {_FOURCC+_BITCOUNT+_BITMASK, BI_BITFIELDS,      24, {  0xFF0000,   0x00FF00,   0x0000FF}}},
    {CID_RGB24,             {_FOURCC+_BITCOUNT,          HXCOLOR_RGB3_ID,   24, {         0,          0,          0}}},
    {CID_RGB24,             {_FOURCC,                    HXCOLOR_RGB24_ID,  24, {         0,          0,          0}}},
    {CID_RGB565,            {_FOURCC,                    HXCOLOR_RGB565_ID, 16, {         0,          0,          0}}},
    {CID_RGB555,            {_FOURCC+_BITCOUNT,          BI_RGB,            16, {         0,          0,          0}}},
    {CID_RGB555,            {_FOURCC,                    HXCOLOR_RGB555_ID, 16, {         0,          0,          0}}},
    {CID_RGB8,              {_FOURCC,                    HXCOLOR_8BIT_ID,    8, {         0,          0,          0}}},
    {CID_UNKNOWN,           {0      ,                    0,                  0, {         0,          0,          0}}}
};

/* color format attributes: */
#define _BITMAP         0x0001  /* has bitmap descriptor        */
#define _DIRECTDRAW     0x0002  /* has DirectDraw descriptor    */
#define _RGB            0x0100  /* normal RGB format            */
#define _BGR            0x0200  /* B/R flipped RGB format       */
#define _YUV            0x0400  /* YUV format                   */
#define _MPEG           0x0800  /* MPEG pre-decoded format      */
#define _RGBS           0x1000  /* Byte swapped RGB format      */

/* the main color descriptors' table: */
struct _stColorTable
{
    ULONG32 dwFlags;               /* general format properties    */
    const struct _greg * lpBitmapCIDD;     /* bitmap format descriptor     */
    const struct _greg * lpDirectDrawCIDD; /* DirectDraw format descriptor */
    int     nBPP;                  /* bytes per pixel              */
};

static const struct _stColorTable  ciddTbl[NFORMATS] = {
    {_BITMAP+_YUV,              &ciddI420,      (const struct _greg*)NULL,    1}, /* CID_I420   */
    {_BITMAP+_DIRECTDRAW+_YUV,  &ciddYV12,      &ciddYV12,      1}, /* CID_YV12   */
    {_BITMAP+_DIRECTDRAW+_YUV,  &ciddYVU9,      &ciddYVU9,      1}, /* CID_YVU9   */
    {_BITMAP+_DIRECTDRAW+_YUV,  &ciddYUY2,      &ciddYUY2,      2}, /* CID_YUY2   */
    {_BITMAP+_DIRECTDRAW+_YUV,  &ciddUYVY,      &ciddUYVY,      2}, /* CID_UYVY   */
    {_BITMAP+_DIRECTDRAW+_RGB,  &ciddBmpRGB32,  &ciddDDrRGB32,  4}, /* CID_RGB32  */
    {_BITMAP+_DIRECTDRAW+_RGB,  &ciddBmpRGB24,  &ciddDDrRGB24,  3}, /* CID_RGB24  */
    {_BITMAP+_DIRECTDRAW+_RGB,  &ciddBmpRGB565, &ciddDDrRGB565, 2}, /* CID_RGB565 */
    {_BITMAP+_DIRECTDRAW+_RGB,  &ciddBmpRGB555, &ciddDDrRGB555, 2}, /* CID_RGB555 */
    {_BITMAP+_DIRECTDRAW+_RGB,  &ciddBmpRGB8,   &ciddDDrRGB8,   1}, /* CID_RGB8   */
    {_BITMAP+_DIRECTDRAW+_YUV,  &ciddXING,      &ciddXING,      1}, /* CID_XING   */
    {_BITMAP+_DIRECTDRAW+_RGB,  &ciddBmpARGB32, &ciddDDrARGB32, 4}, /* CID_ARGB32 */
    {_BITMAP+_YUV,              &ciddYUVA,      NULL,           1}, /* CID_YUVA   */
    {_BITMAP+_YUV,              &ciddYUY2,      &ciddYUY2,      2}, /* CID_YUYU   */
    {0,                         NULL,           NULL,           0}, /* CID_UNKNOWN*/
    {_BITMAP+_BGR,              &ciddBGR32,     NULL,           4}, /* CID_BGR32  */
    {_BITMAP+_BGR,              &ciddBGR24,     NULL,           3}, /* CID_BGR24  */
    {_BITMAP+_RGBS,             &ciddRGB32S,    NULL,           4}, /* CID_RGB32S */
    {_BITMAP+_RGB,              &ciddRGB444,    NULL,           2}, /* CID_RGB444 */
    {_BITMAP+_DIRECTDRAW+_MPEG, &ciddMC12,      &ciddMC12,      1}, /* CID_MC12   */
    {_BITMAP+_DIRECTDRAW+_MPEG, &ciddMCAM,      &ciddMCAM,      1}, /* CID_MCAM   */
    {_BITMAP+_DIRECTDRAW+_MPEG, &ciddMCS3,      &ciddMCS3,      1}, /* CID_MCS3   */
    {_BITMAP+_DIRECTDRAW+_MPEG, &ciddIGOR,      &ciddIGOR,      1}, /* CID_IGOR   */
    {_BITMAP+_DIRECTDRAW+_YUV,  &ciddDVPF,      &ciddDVPF,      1}  /* CID_DVPF   */
};

                                                 
/*********************************
 *  _TEXT segment :-)
 *********************************/
int MapFourCCtoCID(ULONG32 dwFourCC)
{
    int i;

    //for (i=0; i<CID_UNKNOWN; i++)
    for (i=0; i<NFORMATS; i++)
    {
        if (ciddTbl[i].lpBitmapCIDD &&
            ciddTbl[i].lpBitmapCIDD->dwFourCC == dwFourCC)
	    {
	        return i;
	    }
    }

    return CID_UNKNOWN;
}

int MapCIDtoFourCC(ULONG32 CID)
{
    if (CID < NFORMATS)
        return ciddTbl[CID].lpBitmapCIDD->dwFourCC;
    else
        return 0;
}


/*
 * Check color format:
 */
static int ChkColor (const struct _greg* pcidd, ULONG32 dwFourCC, ULONG32 dwBitCount, ULONG32 *lpBitMask)
{
    /* clear match flags: */
    ULONG32 dwMatch = 0;

    /* check FourCC: */
    if ((pcidd->dwFlags & _FOURCC) && pcidd->dwFourCC == dwFourCC)
        dwMatch |= _FOURCC;

    /* check BitCount: */
    if ((pcidd->dwFlags & _BITCOUNT) && pcidd->dwBitCount == dwBitCount)
        dwMatch |= _BITCOUNT;

    /* check BitMasks: */
    if ((pcidd->dwFlags & _BITMASK) && lpBitMask &&
        pcidd->dwBitMask[0] == lpBitMask[0] &&
        pcidd->dwBitMask[1] == lpBitMask[1] &&
        pcidd->dwBitMask[2] == lpBitMask[2])
        dwMatch |= _BITMASK;

    /* combine results: */
    return dwMatch == pcidd->dwFlags;
}

/*
 * Get color format ID.
 * Use:
 *  int GetBitmapColor (LPBITMAPINFO lpbi);
 *  int GetDirectDrawColor (LPDDPIXELFORMAT lpddpf);
 * Input:
 *  lpbi - pointer to BITMAPINFO structure containing image format
 *  lpddpf - pointer to a DirectDraw DDPIXELFORMAT structure
 * Returns:
 *  ID of the specified format, if found;
 *  CID_UNKNOWN, if not supported.
 */
#ifdef _WIN32
int GetBitmapColor (LPBITMAPINFO lpbi)
#else
int GetBitmapColor (HXBitmapInfo* lpHXbi)
#endif
{
    ULONG32 dwFourCC, dwBitCount, *lpColors;
    register int i;

#ifdef _WIN32
    HXBitmapInfo* lpHXbi;

    if (!lpbi)
    {
	return CID_UNKNOWN;
    }
    lpHXbi = (HXBitmapInfo*) lpbi;
#endif

    /* check bitmap pointer/size... */
    if (lpHXbi == NULL)
        return CID_UNKNOWN;

    /* get bitmap parameters to compare: */
    dwFourCC = lpHXbi->bmiHeader.biCompression;
    dwBitCount = lpHXbi->bmiHeader.biBitCount;
    lpColors = (ULONG32*)&lpHXbi->un.dwBitMask[0];

    /* scan standard bitmap formats: */
    for (i=0; i<NFORMATS; i++)
        if ((ciddTbl[i].dwFlags & _BITMAP) && ciddTbl[i].lpBitmapCIDD &&
            ChkColor (ciddTbl[i].lpBitmapCIDD, dwFourCC, dwBitCount, lpColors))
            return i;
    
    /* scan our proprietary formats: */
    for (i=0; ; i++)
        if (ChkColor (&(ciddlOtherColors[i].cidd), dwFourCC, dwBitCount, lpColors))
            break;

    /* return color ID: */
    return ciddlOtherColors[i].cid;
}

#if defined(_WIN32) && !defined(WINCE)
int GetDirectDrawColor (LPDDPIXELFORMAT lpddpf)
{
    /* check bitmap pointer... */
    if (lpddpf != NULL && lpddpf->dwSize >= sizeof(DDPIXELFORMAT)) {

        /* scan DirectDraw formats: */
        register int i;
        for (i=0; i<NFORMATS; i++)
            if ((ciddTbl[i].dwFlags & _DIRECTDRAW) && ciddTbl[i].lpDirectDrawCIDD &&
                ChkColor (ciddTbl[i].lpDirectDrawCIDD, lpddpf->dwFourCC, lpddpf->dwRGBBitCount, &(lpddpf->dwRBitMask)))
                return i;
    }
    return CID_UNKNOWN;
}
#endif


/*
 * Set color format.
 * Use:
 *  void SetBitmapColor (LPBITMAPINFO lpbi, int cid);
 *  void SetDirectDrawColor (LPDDPIXELFORMAT lpddpf, int cid);
 * Input:
 *  lpbi - pointer to BITMAPINFO structure containing image format
 *  lpddpf - pointer to a DirectDraw DDPIXELFORMAT structure
 *  cid - color format to set
 * Returns:
 *  0, if success,
 *  !0 if wrong color format ID passed
 */
#ifdef _WIN32
int SetBitmapColor (LPBITMAPINFO lpbi, int cid)
#else
int SetBitmapColor (HXBitmapInfo* lpHXbi, int cid)
#endif
{
    const struct _greg* lpcidd;

#ifdef _WIN32
    HXBitmapInfo* lpHXbi;

    if (!lpbi)
    {
	return CID_UNKNOWN;
    }
    lpHXbi = (HXBitmapInfo*) lpbi;
#endif

    /* check input parameters: */
    if (lpHXbi == NULL ||
        cid < 0 || cid > NFORMATS || !(ciddTbl[cid].dwFlags & _BITMAP) ||
        (lpcidd = ciddTbl[cid].lpBitmapCIDD) == NULL)
        return -1;

    /* set color-format releated fields in BITMAPINFO: */
    lpHXbi->bmiHeader.biCompression = lpcidd->dwFourCC;
    lpHXbi->bmiHeader.biBitCount    = (UINT16)lpcidd->dwBitCount;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -