//-----------------------------------------------------------------------------
//
// This file contains the general span parsing code.
//
// Copyright (C) Microsoft Corporation, 1997.
//
//-----------------------------------------------------------------------------

#include "pch.cpp"
#pragma hdrstop
#include "rloop_mh.h"
#include "rmono.h"
#include "rtrd_mh.h"
include(`m4hdr.mh')
include(`rampbead.mh')

UINT16 g_uRampDitherTable[16] =
{
    0x00,   0x80,   0x20,   0xa0,
    0xc0,   0x40,   0xe0,   0x60,
    0x30,   0xb0,   0x10,   0x90,
    0xf0,   0x70,   0xd0,   0x50
};

//-----------------------------------------------------------------------------
//
// Ramp_*Tbl
//
// The individual bead tables
//
//-----------------------------------------------------------------------------
#define Ramp_NULL NULL
define(`d_MakeTable', `
static d_UpCase(`$1')`'BEADS Ramp_`'$1`'Beads =
{
d_Null(d_`'$1`'Beads(``    Ramp_XX,
'', `XX'))dnl
};')dnl
dnl
d_MakeTable(RampBegin)
d_MakeTable(RampMono)
d_MakeTable(RampTexRead)

// RenderSpans table is initially empty because it's very sparsely populated.
static RAMPRENDERSPANSBEADS Ramp_RampRenderSpansBeads;

// Actual RenderSpans table entries.
struct RAMP_RENDERSPANSBEAD_ENTRY
{
    INT iIndex;
    PFNRENDERSPANS pfn;
};
static RAMP_RENDERSPANSBEAD_ENTRY Ramp_SpecializedRampRenderSpansBeads[] =
{
d_Null(d_SpecializedRampRenderSpansBeads(``    d_RampRenderSpansBeadIndex(XX), Ramp_XX, '', `XX'))dnl
};

//-----------------------------------------------------------------------------
//
// Ramp_BeadTbl
//
// The root of all the bead table pointers.
//
//-----------------------------------------------------------------------------

RAMPBEADTABLE g_Ramp_BeadTbl =
{
    Ramp_RenderSpans_Any,
    &Ramp_RampRenderSpansBeads,
    &Ramp_RampBeginBeads,
    &Ramp_RampMonoBeads,
    &Ramp_RampTexReadBeads,
};

//----------------------------------------------------------------------------
//
// Ramp_InitBeadTbl
//
// Initializes the ramp bead table.
//
//----------------------------------------------------------------------------

void
Ramp_InitBeadTbl(void)
{
    INT i;
    PFNRENDERSPANS *ppfn;
    RAMP_RENDERSPANSBEAD_ENTRY *pEnt;

    // Initialize all RenderSpans bead entries to the generic routine.
    
    ppfn = (PFNRENDERSPANS *)g_Ramp_BeadTbl.pRenderSpansBeads;
    for (i = 0;
         i < sizeof(*g_Ramp_BeadTbl.pRenderSpansBeads)/sizeof(PFNRENDERSPANS);
         i++)
    {
        *ppfn++ = g_Ramp_BeadTbl.pfnRenderSpansAny;
    }

// #define NO_SPECIALIZED_LOOPS
#ifndef NO_SPECIALIZED_LOOPS
    // Insert specific implementations.
    pEnt = &Ramp_SpecializedRampRenderSpansBeads[0];
    ppfn = (PFNRENDERSPANS *)g_Ramp_BeadTbl.pRenderSpansBeads;
    for (i = 0;
         i < sizeof(Ramp_SpecializedRampRenderSpansBeads) / sizeof(*pEnt);
         i++)
    {
        *(ppfn + pEnt->iIndex) = pEnt->pfn;
        pEnt++;
    }
#endif
}