Esempio n. 1
0
static void SetPaletteColors(void)
{
    assert(This.m_PalEntries      != NULL);
    assert(This.m_AdjustedPalette != NULL);

    if (This.m_nDepth == 8)
    {
        assert(This.m_hPalette != NULL);
        SetPaletteEntries(This.m_hPalette, 0, This.m_nTotalColors, This.m_AdjustedPalette);
    }
    else
    if (This.m_bModifiablePalette == TRUE)
    {
        UINT i;

        for (i = 0; i < This.m_nTotalColors; i++)
        {
	        This.m_p16BitLookup[i] = MAKECOL(This.m_AdjustedPalette[i].peRed,
                                             This.m_AdjustedPalette[i].peGreen,
                                             This.m_AdjustedPalette[i].peBlue) * 0x10001;
        }
    }
}
Esempio n. 2
0
void do_bumpmapping(BITMAP *dest, BITMAP *bumpmap, BITMAP *colormap, int light_x, int light_y)
{
 int x, y, nx, ny, lx, ly, c;
 float k;

 for(y = 1; y < bumpmap->h - 1; y++)
  for(x = 1; x < bumpmap->w - 1; x++)
   {
    nx = PIXEL(bumpmap, x + 1, y) - PIXEL(bumpmap, x - 1, y);
    ny = PIXEL(bumpmap, x, y + 1) - PIXEL(bumpmap, x, y - 1);
    lx = x - light_x - 128;
    ly = y - light_y - 128;
    nx -= lx;
    ny -= ly;
    clamp(&nx, 0, 255);
    clamp(&ny, 0, 255);

    c = PIXEL(colormap, x, y);
    k = envmap[nx][ny] * 0.00390625;

    PIXEL(dest, x, y) = MAKECOL(GETR(c) * k, GETG(c) * k, GETB(c) * k);
  }
}
Esempio n. 3
0
/*
    palette is an array of 'totalcolors' R,G,B triplets. The function returns
    in *pens the pen values corresponding to the requested colors.
    If 'totalcolors' is 32768, 'palette' is ignored and the *pens array is filled
    with pen values corresponding to a 5-5-5 15-bit palette
*/
static int GDI_allocate_colors(unsigned int         totalcolors,
                               const unsigned char* palette,
                               unsigned short*      pens,
                               int                  modifiable)
{
    unsigned int i;

    This.m_bModifiablePalette = modifiable ? TRUE : FALSE;

    This.m_nTotalColors = totalcolors;
    if (This.m_nDepth != 8)
        This.m_nTotalColors += 2;
    else
        This.m_nTotalColors = OSD_NUMPENS;

    This.m_p16BitLookup    = (UINT32*) malloc(This.m_nTotalColors * sizeof(UINT32));
    This.m_PalEntries      = (PALETTEENTRY*) malloc(This.m_nTotalColors * sizeof(PALETTEENTRY));
    This.m_AdjustedPalette = (PALETTEENTRY*) malloc(This.m_nTotalColors * sizeof(PALETTEENTRY));
    if (This.m_p16BitLookup == NULL || This.m_PalEntries == NULL || This.m_AdjustedPalette == NULL)
        return 1;

    if (This.m_nDepth != 8 && This.m_bModifiablePalette == FALSE)
    {
        /* 16 bit static palette. */
        int r, g, b;

        for (i = 0; i < totalcolors; i++)
        {
            r = 255.0 * Display_get_brightness() * pow(palette[3 * i + 0] / 255.0, 1.0 / Display_get_gamma()) / 100.0;
            g = 255.0 * Display_get_brightness() * pow(palette[3 * i + 1] / 255.0, 1.0 / Display_get_gamma()) / 100.0;
            b = 255.0 * Display_get_brightness() * pow(palette[3 * i + 2] / 255.0, 1.0 / Display_get_gamma()) / 100.0;
            *pens++ = MAKECOL(r, g, b);
        }

        Machine->uifont->colortable[0] = 0;
        Machine->uifont->colortable[1] = MAKECOL(0xFF, 0xFF, 0xFF);
        Machine->uifont->colortable[2] = MAKECOL(0xFF, 0xFF, 0xFF);
        Machine->uifont->colortable[3] = 0;
    }
    else
    {
		if (This.m_nDepth == 8 && 255 <= totalcolors)
        {
            int bestblack;
            int bestwhite;
            int bestblackscore;
            int bestwhitescore;

            bestblack = bestwhite = 0;
            bestblackscore = 3 * 255 * 255;
            bestwhitescore = 0;
            for (i = 0; i < totalcolors; i++)
            {
                int r, g, b, score;

                r = palette[3 * i + 0];
                g = palette[3 * i + 1];
                b = palette[3 * i + 2];
                score = r * r + g * g + b * b;

                if (score < bestblackscore)
                {
                    bestblack      = i;
                    bestblackscore = score;
                }
                if (score > bestwhitescore)
                {
                    bestwhite      = i;
                    bestwhitescore = score;
                }
            }

            for (i = 0; i < totalcolors; i++)
                pens[i] = i;

            /* map black to pen 0, otherwise the screen border will not be black */
            pens[bestblack] = 0;
            pens[0] = bestblack;

            Machine->uifont->colortable[0] = pens[bestblack];
            Machine->uifont->colortable[1] = pens[bestwhite];
            Machine->uifont->colortable[2] = pens[bestwhite];
            Machine->uifont->colortable[3] = pens[bestblack];

            This.m_nUIPen = pens[bestwhite];
        }
        else
        {
            /* 8 or 16 bit palette with extra palette space left over. */

            /*
                If we have free places, fill the palette starting from the end,
                so we don't touch color 0, which is better left black.
            */
            for (i = 0; i < totalcolors; i++)
                pens[i] = (This.m_nTotalColors - 1) - i;

            /* As long as there are free pens, set 0 as black for GetBlackPen. */
            SetPen(0, 0, 0, 0);

            /* reserve color 1 for the user interface text */
            This.m_nUIPen = 1;
            SetPen(This.m_nUIPen, 0xFF, 0xFF, 0xFF);

            Machine->uifont->colortable[0] = 0;
            Machine->uifont->colortable[1] = This.m_nUIPen;
            Machine->uifont->colortable[2] = This.m_nUIPen;
            Machine->uifont->colortable[3] = 0;
        }

        for (i = 0; i < totalcolors; i++)
        {
            SetPen(pens[i],
                   palette[3 * i + 0],
                   palette[3 * i + 1],
                   palette[3 * i + 2]);
        }

        SetPaletteColors();
    }

    return 0;
}