/******************************************************************************
 * $Id: gfx_deprecated.hh,v 1.2 2006/10/31 01:54:37 devel Exp $
 * @file
 * @author	Jim E. Brooks  http://www.jimbrooks.org
 * @brief	Deprecated code.
 *//*
 * LEGAL:	COPYRIGHT (C) 2006 JIM E. BROOKS
 *          THIS SOURCE CODE IS RELEASED UNDER THE TERMS
 *          OF THE GNU GENERAL PUBLIC LICENSE (GPL).
 ******************************************************************************/

#if 0

////////////////////////////////////////////////////////////////////////////////
// gfx_texture.hh
////////////////////////////////////////////////////////////////////////////////

/*****************************************************************************
 * Blend pixels using the CPU.
 *****************************************************************************/
// [RGBA]s : src fragment     (incoming fragment)
// [RGBA]d : dst fragment     (pre-written fragment in color buffer)
// S[rgba] : src blend factor (arg to glBlendFunc)
// D[rgba] : dst blend factor (arg to glBlendFunc)

#define BLEND_EQUATION( Rs, Gs, Bs, As,  \
                        Rd, Gd, Bd, Ad,  \
                        Sr, Sg, Sb, Sa,	 \
                        Dr, Dg, Db, Da ) \
    ( (Min(0xffu,uint( ((Bs) * (Sb) + (Bd) * (Db)) * 255.0 ) ) << Texture::TEXEL32_BB_BIT_SHIFT) \
    | (Min(0xffu,uint( ((Gs) * (Sg) + (Gd) * (Dg)) * 255.0 ) ) << Texture::TEXEL32_GG_BIT_SHIFT) \
    | (Min(0xffu,uint( ((Rs) * (Sr) + (Rd) * (Dr)) * 255.0 ) ) << Texture::TEXEL32_RR_BIT_SHIFT) \
    | (Min(0xffu,uint( ((As) * (Sa) + (Ad) * (Da)) * 255.0 ) ) << Texture::TEXEL32_AA_BIT_SHIFT) \
    )

// For speed, the blend factor args are implied by the function name
// (a switch statement is way too slow for pixel processing).
static inline uint32
Blend_SRC_ALPHA_and_ONE_MINUS_SRC_ALPHA( const uint8 src[4], const uint8 dst[4] )
{
    const fp R256 = 1.0 / 256.0;
    fp srcR = src[RR] * R256; fp srcG = src[GG] * R256; fp srcB = src[BB] * R256; fp srcA = src[AA] * R256;
    fp dstR = dst[RR] * R256; fp dstG = dst[GG] * R256; fp dstB = dst[BB] * R256; fp dstA = dst[AA] * R256;
	fp src1MA = 1.0 - srcA;
    return BLEND_EQUATION( srcR,    srcG,    srcB,    srcA,
                           dstR,    dstG,    dstB,    dstA,
                           srcA,    srcA,    srcA,    srcA,     // srcBlend = GP_SRC_ALPHA
                           src1MA,  src1MA,  src1MA,  src1MA );  // dstBlend = GP_ONE_MINUS_SRC_ALPHA
}

/// --deprecated--
/// A safer string copy that ensures the destination string isn't overrun
/// and that it'll be terminated by a null char.
static inline void
STRNCPY( char* dest, const char* src, uint destLen /* length of dest (not src) */ )
{
	if ( dest != NULL && src != NULL && destLen >= 1 && destLen < GFX_MAX_STR_LEN )
	{
		strncpy( dest, src, destLen );
		dest[destLen - 1] = '\0';		// destLen must be >= 1
	}
#if DEBUG
	else { ASSERT(0); }
#endif
}

#endif // 0
