Home

Resume

Blog

Teikitu


/* =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-==-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= */
/*  »Project«   Teikitu Gaming System (TgS) (∂)
    »File«      TgS Common - Base - Type [Structs].inl
    »Author«    Andrew Aye (EMail: mailto:andrew.aye@gmail.com, Web: http://www.andrewaye.com)
    »Version«   4.51 / »GUID« A9981407-3EC9-42AF-8B6F-8BE6DD919615                                                                                                        */
/*   -------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
/*  Copyright: © 2002-2017, Andrew Aye.  All Rights Reserved.
    This software is free for non-commercial use.  Redistribution and use in source and binary forms, with or without modification, are permitted provided that the
      following conditions are met:
        Redistribution of source code must retain this copyright notice, this list of conditions and the following disclaimers.
        Redistribution in binary form must reproduce this copyright notice, this list of conditions and the following disclaimers in the documentation and other materials
          provided with the distribution.
    The name of the author may not be used to endorse or promote products derived from this software without specific prior written permission.
    The intellectual property rights of the algorithms used reside with Andrew Aye.
    You may not use this software, in whole or in part, in support of any commercial product without the express written consent of the author.
    There is no warranty or other guarantee of fitness of this software for any purpose. It is provided solely "as is".                                                   */
/* =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-==-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= */
#if !defined(TGS_COMMON_BASE_TYPES_STRUCTS_INL)
#define TGS_COMMON_BASE_TYPES_STRUCTS_INL
#pragma once


/* == Common ============================================================================================================================================================ */

/* -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-. */
/*  Public Functions                                                                                                                                                      */
/* -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-. */

/* ---- STg1_Codec -------------------------------------------------------------------------------------------------------------------------------------------------------- */

/* ---- tgCM_CD_Init ---------------------------------------------------------------------------------------------------------------------------------------------------- */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
TgINLINE TgVOID tgCM_CD_Init( PCU_STg1_Codec psCoA, TsCM_CD_FCN_ENCODE pfnEncode, TsCM_CD_FCN_DECODE pfnDecode )
{
    TgERROR(nullptr != psCoA);
    psCoA->m_pfnDecode = pfnDecode;
    psCoA->m_pfnEncode = pfnEncode;
}


/* ---- tgCM_CD_EQ ------------------------------------------------------------------------------------------------------------------------------------------------------ */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
TgINLINE TgBOOL tgCM_CD_EQ( CPCU_STg1_Codec psCoA, CPCU_STg1_Codec psCoB )
{
    TgERROR(nullptr != psCoA && nullptr != psCoB);
    return ((psCoA->m_pfnDecode == psCoB->m_pfnDecode) && (psCoA->m_pfnEncode == psCoB->m_pfnEncode));
}


/* ---- tgCM_CD_NE ------------------------------------------------------------------------------------------------------------------------------------------------------ */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
TgINLINE TgBOOL tgCM_CD_NE( CPCU_STg1_Codec psCoA, CPCU_STg1_Codec psCoB )
{
    TgERROR(nullptr != psCoA && nullptr != psCoB);
    return ((psCoA->m_pfnDecode != psCoB->m_pfnDecode) && (psCoA->m_pfnEncode != psCoB->m_pfnEncode));
}


/* ---- tgCM_CD_Clear --------------------------------------------------------------------------------------------------------------------------------------------------- */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
TgINLINE TgVOID tgCM_CD_Clear( PCU_STg1_Codec psCoA )
{
    TgERROR(nullptr != psCoA);
    psCoA->m_pfnDecode = nullptr;
    psCoA->m_pfnEncode = nullptr;
}


/* ---- tgCM_CD_Is_Empty ------------------------------------------------------------------------------------------------------------------------------------------------ */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
TgINLINE TgBOOL tgCM_CD_Is_Empty( CPCU_STg1_Codec psCoA )
{
    TgERROR(nullptr != psCoA);
    return ((psCoA->m_pfnDecode == nullptr) && (psCoA->m_pfnEncode == nullptr));
}


/* ---- tgCM_CD_NULL_ENCODE --------------------------------------------------------------------------------------------------------------------------------------------- */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
TgINLINE TgBOOL tgCM_CD_NULL_ENCODE( PC_TgVOID pDest, PC_TgSIZE puiDest, CPC_TgVOID pSrc, C_TgSIZE nuiSrc )
{
    TgERROR(nullptr != pDest && nullptr != puiDest && nullptr != pSrc);
    TgMEMCPY( pDest, (TgSIZE)*puiDest, pSrc, (TgSIZE)nuiSrc );
    *puiDest = nuiSrc;
    return (TgTRUE);
}


/* ---- tgCM_CD_NULL_DECODE --------------------------------------------------------------------------------------------------------------------------------------------- */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
TgINLINE TgBOOL tgCM_CD_NULL_DECODE( PC_TgVOID pDest, PC_TgSIZE puiDest, CPC_TgVOID pSrc, C_TgSIZE nuiSrc )
{
    TgERROR(nullptr != pDest && nullptr != puiDest && nullptr != pSrc);
    TgMEMCPY( pDest, (TgSIZE)*puiDest, pSrc, (TgSIZE)nuiSrc );
    *puiDest = nuiSrc;
    return (TgTRUE);
}


/* ---- tgCM_CD_TEXT_ENCODE --------------------------------------------------------------------------------------------------------------------------------------------- */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
TgINLINE TgBOOL tgCM_CD_TEXT_ENCODE( PC_TgVOID pDest, PC_TgSIZE puiDest, CPC_TgVOID pSrc, C_TgSIZE nuiSrc )
{
    TgERROR(nullptr != puiDest && nullptr != pSrc);

    if (nullptr != pDest)
    {
        ((P_TgUINT08)pDest)[0] = 0;
        TgMEMCPY( pDest, (TgSIZE)*puiDest, pSrc, (TgSIZE)nuiSrc );
        *puiDest = nuiSrc;
    }
    else
    {
        *puiDest = nuiSrc;
    };
    return (TgTRUE);
}


/* ---- tgCM_CD_TEXT_DECODE --------------------------------------------------------------------------------------------------------------------------------------------- */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
TgINLINE TgBOOL tgCM_CD_TEXT_DECODE( PC_TgVOID pDest, PC_TgSIZE puiDest, CPC_TgVOID pSrc, C_TgSIZE nuiSrc )
{
    TgERROR(nullptr != pDest && nullptr != puiDest && nullptr != pSrc);
    ((P_TgUINT08)pDest)[0] = 0;
    TgMEMCPY( pDest, (TgSIZE)*puiDest, pSrc, (TgSIZE)nuiSrc );
    *puiDest = nuiSrc;
    return (TgTRUE);
}


/* ---- TgFCOLOUR --------------------------------------------------------------------------------------------------------------------------------------------------------- */

/* ---- tgCM_CL_F32_Init_F32 -------------------------------------------------------------------------------------------------------------------------------------------- */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
TgINLINE TgVOID tgCM_CL_F32_Init_F32( PCU_TgVEC_F32_04 psFC, C_TgFLOAT32 fR, C_TgFLOAT32 fG, C_TgFLOAT32 fB, C_TgFLOAT32 fA )
{
    TgERROR(nullptr != psFC);
    psFC->c.r = fR;
    psFC->c.g = fG;
    psFC->c.b = fB;
    psFC->c.a = fA;
}


/* ---- tgCM_CL_F32_Init_U32 -------------------------------------------------------------------------------------------------------------------------------------------- */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
TgINLINE TgVOID tgCM_CL_F32_Init_U32( PCU_TgVEC_F32_04 psFC, C_TgUINT32 uiColour )
{
    TgERROR(nullptr != psFC);
    psFC->c.r = TgCOLOUR_R( uiColour ) / 255.0F;
    psFC->c.g = TgCOLOUR_G(uiColour) / 255.0F;
    psFC->c.b = TgCOLOUR_B( uiColour ) / 255.0F;
    psFC->c.a = TgCOLOUR_A( uiColour ) / 255.0F;
}


/* ---- tgCM_CL_F32_Brightness_U16 -------------------------------------------------------------------------------------------------------------------------------------- */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
TgINLINE TgUINT16 tgCM_CL_F32_Brightness_U16( CPCU_TgVEC_F32_04 psFC )
{
    TgERROR(nullptr != psFC);
    return ((TgUINT16)(tgCM_CLP_F32( tgCM_CL_F32_Brightness_F32( psFC ), 0.0F, 1.0F )* (TgFLOAT32)KTgMAX_U16));
}


/* ---- tgCM_CL_F32_Brightness_F32 -------------------------------------------------------------------------------------------------------------------------------------- */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
TgINLINE TgFLOAT32 tgCM_CL_F32_Brightness_F32( CPCU_TgVEC_F32_04 psFC )
{
    TgERROR(nullptr != psFC);
    return ((tgCM_CL_F32_Query_R_F32( psFC ) + tgCM_CL_F32_Query_G_F32( psFC ) + tgCM_CL_F32_Query_B_F32( psFC )) / 3.0F);
}


/* ---- tgCM_CL_F32_Lightness ------------------------------------------------------------------------------------------------------------------------------------------- */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
TgINLINE TgFLOAT32 tgCM_CL_F32_Lightness( CPCU_TgVEC_F32_04 psFC )
{
    TgERROR(nullptr != psFC);
    return (0.5F*(
        tgCM_MAX_F32( tgCM_CL_F32_Query_R_F32( psFC ), tgCM_MAX_F32( tgCM_CL_F32_Query_G_F32( psFC ), tgCM_CL_F32_Query_B_F32( psFC ) ) )
        + tgCM_MIN_F32( tgCM_CL_F32_Query_R_F32( psFC ), tgCM_MIN_F32( tgCM_CL_F32_Query_G_F32( psFC ), tgCM_CL_F32_Query_B_F32( psFC ) ) )
        ));
}


/* ---- tgCM_CL_F32_Luminance ------------------------------------------------------------------------------------------------------------------------------------------- */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
TgINLINE TgFLOAT32 tgCM_CL_F32_Luminance( CPCU_TgVEC_F32_04 psFC )
{
    TgERROR(nullptr != psFC);
    return (0.3f*tgCM_CL_F32_Query_R_F32( psFC ) + 0.59f*tgCM_CL_F32_Query_G_F32( psFC ) + 0.11f*tgCM_CL_F32_Query_B_F32( psFC ));
}


/* ---- tgCM_CL_F32_Query_R_F32 ----------------------------------------------------------------------------------------------------------------------------------------- */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
TgINLINE TgFLOAT32 tgCM_CL_F32_Query_R_F32( CPCU_TgVEC_F32_04 psFC )
{
    return (psFC->c.r);
}


/* ---- tgCM_CL_F32_Query_G_F32 ----------------------------------------------------------------------------------------------------------------------------------------- */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
TgINLINE TgFLOAT32 tgCM_CL_F32_Query_G_F32( CPCU_TgVEC_F32_04 psFC )
{
    return (psFC->c.g);
}


/* ---- tgCM_CL_F32_Query_B_F32 ----------------------------------------------------------------------------------------------------------------------------------------- */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
TgINLINE TgFLOAT32 tgCM_CL_F32_Query_B_F32( CPCU_TgVEC_F32_04 psFC )
{
    return (psFC->c.b);
}


/* ---- tgCM_CL_F32_Query_A_F32 ----------------------------------------------------------------------------------------------------------------------------------------- */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
TgINLINE TgFLOAT32 tgCM_CL_F32_Query_A_F32( CPCU_TgVEC_F32_04 psFC )
{
    return (psFC->c.a);
}


/* ---- TgCOLOUR32 -------------------------------------------------------------------------------------------------------------------------------------------------------- */

/* ---- tgCM_CL_U32_Init_U08 -------------------------------------------------------------------------------------------------------------------------------------------- */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
TgINLINE TgVOID tgCM_CL_U32_Init_U08( PCU_TgCOLOUR32 psCL, C_TgUINT08 uiRed, C_TgUINT08 uiGreen, C_TgUINT08 uiBlue, C_TgUINT08 uiAlpha )
{
    TgERROR(nullptr != psCL);
    psCL->m.uiRed = uiRed;
    psCL->m.uiGreen = uiGreen;
    psCL->m.uiBlue = uiBlue;
    psCL->m.uiAlpha = uiAlpha;
}


/* ---- tgCM_CL_U32_Init_U32 -------------------------------------------------------------------------------------------------------------------------------------------- */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
TgINLINE TgVOID tgCM_CL_U32_Init_U32( PCU_TgCOLOUR32 psCL, C_TgUINT32 uiColour )
{
    TgERROR(nullptr != psCL);
    psCL->m.uiRed = TgCOLOUR_R( uiColour );
    psCL->m.uiGreen = TgCOLOUR_G(uiColour);
    psCL->m.uiBlue = TgCOLOUR_B( uiColour );
    psCL->m.uiAlpha = TgCOLOUR_A( uiColour );
}


/* ---- tgCM_CL_U32_Init_F32 -------------------------------------------------------------------------------------------------------------------------------------------- */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
TgINLINE TgVOID tgCM_CL_U32_Init_F32( PCU_TgCOLOUR32 psCL, CPCU_TgVEC_F32_04 psFCL )
{
    TgERROR(nullptr != psCL);
    psCL->m.uiRed = (TgUINT08)(tgCM_CLP_F32( tgCM_CL_F32_Query_R_F32( psFCL ), 0.0F, 1.0F )* 255.0F);
    psCL->m.uiGreen = (TgUINT08)(tgCM_CLP_F32( tgCM_CL_F32_Query_G_F32( psFCL ), 0.0F, 1.0F )* 255.0F);
    psCL->m.uiBlue = (TgUINT08)(tgCM_CLP_F32( tgCM_CL_F32_Query_B_F32( psFCL ), 0.0F, 1.0F )* 255.0F);
    psCL->m.uiAlpha = (TgUINT08)(tgCM_CLP_F32( tgCM_CL_F32_Query_A_F32( psFCL ), 0.0F, 1.0F )* 255.0F);
}


/* ---- tgCM_CL_U32_Brightness_U16 -------------------------------------------------------------------------------------------------------------------------------------- */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
TgINLINE TgUINT16 tgCM_CL_U32_Brightness_U16( CPCU_TgCOLOUR32 psCL )
{
    TgERROR(nullptr != psCL);
    return ((TgUINT16)(tgCM_CLP_F32( tgCM_CL_U32_Brightness_F32( psCL ), 0.0F, 1.0F )* (TgFLOAT32)KTgMAX_U16));
}


/* ---- tgCM_CL_U32_Brightness_F32 -------------------------------------------------------------------------------------------------------------------------------------- */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
TgINLINE TgFLOAT32 tgCM_CL_U32_Brightness_F32( CPCU_TgCOLOUR32 psCL )
{
    TgERROR(nullptr != psCL);
    return ((tgCM_CL_U32_Query_R_F32( psCL ) + tgCM_CL_U32_Query_B_F32( psCL ) + tgCM_CL_U32_Query_G_F32( psCL )) / 3.0F);
}


/* ---- tgCM_CL_U32_Lightness ------------------------------------------------------------------------------------------------------------------------------------------- */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
TgINLINE TgFLOAT32 tgCM_CL_U32_Lightness( CPCU_TgCOLOUR32 psCL )
{
    TgERROR(nullptr != psCL);
    return (0.5F*(
        tgCM_MAX_F32( tgCM_CL_U32_Query_R_F32( psCL ),
                      tgCM_MAX_F32( tgCM_CL_U32_Query_G_F32( psCL ), tgCM_CL_U32_Query_B_F32( psCL ) ) )
        + tgCM_MIN_F32( tgCM_CL_U32_Query_R_F32( psCL ),
                        tgCM_MIN_F32( tgCM_CL_U32_Query_G_F32( psCL ), tgCM_CL_U32_Query_B_F32( psCL ) ) )
        ));
}


/* ---- tgCM_CL_U32_Luminance ------------------------------------------------------------------------------------------------------------------------------------------- */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
TgINLINE TgFLOAT32 tgCM_CL_U32_Luminance( CPCU_TgCOLOUR32 psCL )
{
    TgERROR(nullptr != psCL);
    return (0.3f*tgCM_CL_U32_Query_R_F32( psCL ) + 0.59f*tgCM_CL_U32_Query_G_F32( psCL ) + 0.11f*tgCM_CL_U32_Query_B_F32( psCL ));
}


/* ---- tgCM_CL_U32_Query_R_U32 ----------------------------------------------------------------------------------------------------------------------------------------- */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
TgINLINE TgUINT08 tgCM_CL_U32_Query_R_U32( CPCU_TgCOLOUR32 psCL )
{
    return (psCL->m.uiRed);
}


/* ---- tgCM_CL_U32_Query_G_U32 ----------------------------------------------------------------------------------------------------------------------------------------- */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
TgINLINE TgUINT08 tgCM_CL_U32_Query_G_U32( CPCU_TgCOLOUR32 psCL )
{
    return (psCL->m.uiGreen);
}


/* ---- tgCM_CL_U32_Query_B_U32 ----------------------------------------------------------------------------------------------------------------------------------------- */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
TgINLINE TgUINT08 tgCM_CL_U32_Query_B_U32( CPCU_TgCOLOUR32 psCL )
{
    return (psCL->m.uiBlue);
}


/* ---- tgCM_CL_U32_Query_A_U32 ----------------------------------------------------------------------------------------------------------------------------------------- */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
TgINLINE TgUINT08 tgCM_CL_U32_Query_A_U32( CPCU_TgCOLOUR32 psCL )
{
    return (psCL->m.uiAlpha);
}


/* ---- tgCM_CL_U32_Query_R_F32 ----------------------------------------------------------------------------------------------------------------------------------------- */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
TgINLINE TgFLOAT32 tgCM_CL_U32_Query_R_F32( CPCU_TgCOLOUR32 psCL )
{
    return (tgCM_CL_U32_Query_R_U32( psCL ) / 255.0F);
}


/* ---- tgCM_CL_U32_Query_G_F32 ----------------------------------------------------------------------------------------------------------------------------------------- */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
TgINLINE TgFLOAT32 tgCM_CL_U32_Query_G_F32( CPCU_TgCOLOUR32 psCL )
{
    return (tgCM_CL_U32_Query_G_U32( psCL ) / 255.0F);
}


/* ---- tgCM_CL_U32_Query_B_F32 ----------------------------------------------------------------------------------------------------------------------------------------- */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
TgINLINE TgFLOAT32 tgCM_CL_U32_Query_B_F32( CPCU_TgCOLOUR32 psCL )
{
    return (tgCM_CL_U32_Query_B_U32( psCL ) / 255.0F);
}


/* ---- tgCM_CL_U32_Query_A_F32 ----------------------------------------------------------------------------------------------------------------------------------------- */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
TgINLINE TgFLOAT32 tgCM_CL_U32_Query_A_F32( CPCU_TgCOLOUR32 psCL )
{
    return (tgCM_CL_U32_Query_A_U32( psCL ) / 255.0F);
}


/* ====================================================================================================================================================================== */
#endif