stratagus-cvs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Stratagus-CVS] stratagus/src include/video.h video/font.c vide...


From: address@hidden
Subject: [Stratagus-CVS] stratagus/src include/video.h video/font.c vide...
Date: 10 Jan 2004 09:18:59 +1100

CVSROOT:        /home/strat
Module name:    stratagus
Changes by:      <address@hidden>       04/01/10 09:18:59

Modified files:
        src/include    : video.h 
        src/video      : font.c graphic.c video.c 

Log message:
        More cleaning

Patches:
Index: stratagus/src/include/video.h
diff -u stratagus/src/include/video.h:1.108 stratagus/src/include/video.h:1.109
--- stratagus/src/include/video.h:1.108 Sat Jan 10 08:57:18 2004
+++ stratagus/src/include/video.h       Sat Jan 10 09:18:57 2004
@@ -26,7 +26,7 @@
 //      Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
 //      02111-1307, USA.
 //
-//     $Id: video.h,v 1.108 2004/01/09 21:57:18 jsalmon3 Exp $
+//     $Id: video.h,v 1.109 2004/01/09 22:18:57 jsalmon3 Exp $
 
 #ifndef __VIDEO_H__
 #define __VIDEO_H__
@@ -872,24 +872,10 @@
        **              Special 8bpp functionality, only to be used in ../video
        **              @todo use CommonPalette names!
        */
-extern Palette   *commonpalette;
-       /// FIXME: docu
-extern unsigned long commonpalette_defined[8];
-       /// FIXME: docu
-extern VMemType8 *colorcube8;
        /// FIXME: docu
 extern VMemType8 *lookup25trans8;
        /// FIXME: docu
 extern VMemType8 *lookup50trans8;
-       /// FIXME: docu
-extern void (*VideoAllocPalette8)(Palette* palette, Palette* syspalette,
-       unsigned long syspalette_defined[8]);
-//FIXME: following function should be local in video.c, but this will also
-//        need VideoCreateNewPalette to be there (will all video still work?).
-       /// FIXME: docu
-extern global VMemType8* VideoFindNewPalette8(const VMemType8 *cube,
-       const Palette *palette);
-
 
        /**
        **              Video synchronization speed. Synchronization time in 
percent.
Index: stratagus/src/video/font.c
diff -u stratagus/src/video/font.c:1.71 stratagus/src/video/font.c:1.72
--- stratagus/src/video/font.c:1.71     Sat Jan 10 07:37:05 2004
+++ stratagus/src/video/font.c  Sat Jan 10 09:18:58 2004
@@ -26,7 +26,7 @@
 //      Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
 //      02111-1307, USA.
 //
-//      $Id: font.c,v 1.71 2004/01/09 20:37:05 jsalmon3 Exp $
+//      $Id: font.c,v 1.72 2004/01/09 22:18:58 jsalmon3 Exp $
 
 //@{
 
@@ -989,10 +989,8 @@
 global void LoadFonts(void)
 {
        unsigned i;
+#ifndef USE_SDL_SURFACE
        FontColorMapping* fcm;
-#ifdef USE_SDL_SURFACE
-       SDL_Color* color;
-#else
        void* pixels;
 #endif
 
Index: stratagus/src/video/graphic.c
diff -u stratagus/src/video/graphic.c:1.57 stratagus/src/video/graphic.c:1.58
--- stratagus/src/video/graphic.c:1.57  Sat Dec 20 16:33:48 2003
+++ stratagus/src/video/graphic.c       Sat Jan 10 09:18:58 2004
@@ -5,12 +5,12 @@
 //     /_______  /|__|  |__|  (____  /__| (____  /\___  /|____//____  >
 //             \/                  \/          \//_____/            \/
 //  ______________________                           ______________________
-//                       T H E   W A R   B E G I N S
-//        Stratagus - A free fantasy real time strategy game engine
+//                        T H E   W A R   B E G I N S
+//         Stratagus - A free fantasy real time strategy game engine
 //
-/address@hidden graphic.c      -       The general graphic functions. */
+/address@hidden graphic.c - The general graphic functions. */
 //
-//     (c) Copyright 1999-2002 by Lutz Sammer and Nehal Mistry
+//      (c) Copyright 1999-2004 by Lutz Sammer, Nehal Mistry, and Jimmy Salmon
 //
 //      This program is free software; you can redistribute it and/or modify
 //      it under the terms of the GNU General Public License as published by
@@ -26,7 +26,7 @@
 //      Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
 //      02111-1307, USA.
 //
-//     $Id: graphic.c,v 1.57 2003/12/20 05:33:48 jsalmon3 Exp $
+//      $Id: graphic.c,v 1.58 2004/01/09 22:18:58 jsalmon3 Exp $
 
 //@{
 
@@ -36,16 +36,13 @@
 
 #include <stdio.h>
 #include <stdlib.h>
+#include <string.h>
 
 #include "stratagus.h"
 #include "video.h"
 #include "iolib.h"
 #include "intern_video.h"
 
-#ifdef USE_SDL_SURFACE
-#include <string.h>
-#endif
-
 /*----------------------------------------------------------------------------
 --             Declarations
 ----------------------------------------------------------------------------*/
@@ -56,9 +53,7 @@
 --             Variables
 ----------------------------------------------------------------------------*/
 
-#ifdef USE_SDL_SURFACE
-local GraphicType GraphicImage;
-#else
+#ifndef USE_SDL_SURFACE
 local GraphicType GraphicImage8Type;           /// image type 8bit palette
 local GraphicType GraphicImage16Type;          /// image type 16bit palette
 #endif
@@ -344,16 +339,7 @@
 }
 #endif
 
-#ifdef USE_SDL_SURFACE
-/*
-local void VideoDrawSub(const Graphic* graphic, int gx, int gy,
-       int w, int h, int x, int y)
-{
-       CLIP_RECTANGLE(x, y, w, h);
-       VideoDrawSub(graphic, gx, gy, w, h, x, y);
-}
-*/
-#else
+#ifndef USE_SDL_SURFACE
 /**
 **             Video draw part of 8bit graphic clipped into 8 bit framebuffer.
 **
@@ -453,13 +439,10 @@
 local void FreeGraphic8(Graphic* graphic)
 {
 #ifdef DEBUG
-#ifdef USE_SDL_SURFACE
-       // FIXME: todo
-#else
-       AllocatedGraphicMemory -= graphic->Size;
+       AllocatedGraphicMemory -=
+               graphic->Width * graphic->Height * 
graphic->Surface->format->BytesPerPixel;
        AllocatedGraphicMemory -= sizeof(Graphic);
 #endif
-#endif
 
 #ifdef USE_OPENGL
        if (graphic->NumTextureNames) {
@@ -470,14 +453,21 @@
 
 #ifdef USE_SDL_SURFACE
        SDL_FreeSurface(graphic->Surface);
+       if (graphic->SurfaceFlip) {
+#ifdef DEBUG
+               AllocatedGraphicMemory -=
+                       graphic->Width * graphic->Height * 
graphic->SurfaceFlip->format->BytesPerPixel;
+#endif
+               SDL_FreeSurface(graphic->SurfaceFlip);
+       }
 #else
        VideoFreeSharedPalette(graphic->Pixels);
        if (graphic->Palette) {
                free(graphic->Palette);
        }
        free(graphic->Frames);
-       free(graphic);
 #endif
+       free(graphic);
 }
 
 // FIXME: need frame version
@@ -537,8 +527,7 @@
                fprintf(stderr, "Out of memory\n");
                ExitFatal(-1);
        }
-#ifdef USE_SDL_SURFACE
-#else
+#ifndef USE_SDL_SURFACE
        if (depth == 8) {
                graphic->Type = &GraphicImage8Type;
        } else if (depth == 16) {
@@ -556,9 +545,7 @@
 
        graphic->Surface = SDL_CreateRGBSurfaceFrom(data, width, height, depth, 
width * depth / 8,
                0, 0, 0, 0);
-
        graphic->SurfaceFlip = NULL;
-
        graphic->NumFrames = 0;
 #else
        graphic->Pixels = NULL;
@@ -578,9 +565,9 @@
 
 #ifdef USE_SDL_SURFACE
 /**
+**  Flip graphic and store in graphic->SurfaceFlip
 **
-**             Flip graphic and store in graphic->SurfaceFlip
-**
+**  @param graphic  Pointer to object
 */
 global void FlipGraphic(Graphic* graphic)
 {
@@ -590,16 +577,18 @@
 
        s = graphic->SurfaceFlip = SDL_ConvertSurface(graphic->Surface,
                graphic->Surface->format, SDL_SWSURFACE);
+#ifdef DEBUG
+       AllocatedGraphicMemory +=
+               graphic->Width * graphic->Height * 
graphic->Surface->format->BytesPerPixel;
+#endif
 
        SDL_LockSurface(s);
-
        for (i = 0; i < s->h; ++i) {
                for (j = 0; j < s->w; ++j) {
                        ((char*)s->pixels)[j + i * s->w] =
                                ((char*)graphic->Surface->pixels)[s->w - j + i 
* s->w];
                }
        }
-
        SDL_UnlockSurface(s);
 }
 #endif
@@ -816,7 +805,6 @@
        SDL_LockSurface(g->Surface);
 #else
        DebugCheck(g->Type != &GraphicImage8Type);
-
        if (g->Width == w && g->Height == h) {
                return;
        }
@@ -885,38 +873,26 @@
        }
 
 #ifdef USE_SDL_SURFACE
-//     Pixels = graphic->Surface->format->palette;
-//     graphic->Surface->format->palette =
-//             VideoCreateSharedPalette(graphic->Surface->format->palette);
        graphic->NumFrames = 1;
        VideoPaletteListAdd(graphic->Surface);
 #else
        graphic->Pixels = VideoCreateSharedPalette(graphic->Palette);
-       //free(graphic->Palette);
-       //graphic->Palette = NULL;                              // JOHNS: why 
should we free this?
 #endif
 
        return graphic;
 }
 
 /**
-**             Init graphic
+**  Init graphic
 */
 global void InitGraphic(void)
 {
-#ifdef USE_SDL_SURFACE
-//     GlobalPalletPixels->ncolors = 256;
-//     GlobalPalette.colors = (SDL_Color*)calloc(256, sizeof(SDL_Color));
-//     GlobalPalette.ncolors = 256;
-//     GlobalPalette.colors = (SDL_Color*)calloc(256, sizeof(SDL_Color));
-#else
-
+#ifndef USE_SDL_SURFACE
 #ifdef USE_OPENGL
        GraphicImage8Type.DrawSub = VideoDrawSubOpenGL;
        GraphicImage8Type.DrawSubClip = VideoDrawSubOpenGLClip;
 #else
-
-       switch( VideoBpp ) {
+       switch (VideoBpp) {
                case 8:
                        GraphicImage8Type.DrawSub = VideoDrawSub8to8;
                        GraphicImage8Type.DrawSubClip = VideoDrawSub8to8Clip;
Index: stratagus/src/video/video.c
diff -u stratagus/src/video/video.c:1.82 stratagus/src/video/video.c:1.83
--- stratagus/src/video/video.c:1.82    Fri Jan  9 16:44:47 2004
+++ stratagus/src/video/video.c Sat Jan 10 09:18:58 2004
@@ -26,7 +26,7 @@
 //      Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
 //      02111-1307, USA.
 //
-//     $Id: video.c,v 1.82 2004/01/09 05:44:47 jsalmon3 Exp $
+//     $Id: video.c,v 1.83 2004/01/09 22:18:58 jsalmon3 Exp $
 
 //@{
 
@@ -201,54 +201,23 @@
        **  following precalculated arrays deliver a shortcut.
        **  NOTE: all array pointers are NULL in a non 8bpp mode
        **
-       **  commonpalette:
-       **  The single main color palette denoting all possible colors on which 
all
-       **  other palettes (including above GlobalPalette) are based.
-       **  Note:this means other palettes probably doesn't contains unique 
colors.
-       **
-       **  commonpalette_defined:
-       **  Denotes the defined entries (as bit index) in above palette.
-       **  Needed as for X11 it is possible we can't get all 256 colors.
-       **
-       **  colorcube8:
-       **  Array of 32*32*32 system colors, to get from an unsigned int RGB
-       **  (5x5x5 bit) to a system color.
-       **
        **  lookup25trans8:
        **  Array to get from two system colors as unsigned int 
(color1<<8)|color2
        **  to a new system color which is aproximately 75% color1 and 25% 
color2.
        **  lookup50trans8:
        **  The same for 50% color1 and 50% color2.
-       **
-       **  VideoAllocPalette8:
-       **  Funcytion to let hardware independent palette be converted (when 
set).
        */
 #ifdef USE_SDL_SURFACE
-global SDL_Palette* commonpalette;
-       // FIXME: docu
-//global unsigned long commonpalette_defined[8];
-       // FIXME: docu
-global SDL_Color* colorcube8;
        // FIXME: docu
 global SDL_Color* lookup25trans8;
        // FIXME: docu
 global SDL_Color* lookup50trans8;
-       // FIXME: docu
-global void VideoAllocPalette(SDL_Palette* palette, SDL_Palette*
        syspalette);
 #else
-global Palette* commonpalette;
-       // FIXME: docu
-global unsigned long commonpalette_defined[8];
-       // FIXME: docu
-global VMemType8* colorcube8;
        // FIXME: docu
 global VMemType8* lookup25trans8;
        // FIXME: docu
 global VMemType8* lookup50trans8;
-       // FIXME: docu
-global void (*VideoAllocPalette8)(Palette* palette, Palette* syspalette,
-       unsigned long syspalette_defined[8]) = NULL;
 #endif
 
 global int ColorWaterCycleStart;
@@ -435,29 +404,12 @@
 
 /**
 **             Creates a checksum used to compare palettes.
-**             JOSH: change the method if you have better ideas.
-**             JOHNS: I say this also always :)
 **
 **             @param palette          Palette source.
 **
 **             @return                         Calculated hash/checksum.
 */
-#ifdef USE_SDL_SURFACE
-local long GetPaletteChecksum(const SDL_Palette* palette)
-{
-       long retVal;
-       int i;
-
-       for (retVal = i = 0; i < palette->ncolors; ++i){
-               //This is designed to return different values if
-               // the pixels are in a different order.
-               retVal = ((palette->colors[i].r + i) & 0xff) + retVal;
-               retVal = ((palette->colors[i].g + i) & 0xff) + retVal;
-               retVal = ((palette->colors[i].b + i) & 0xff) + retVal;
-       }
-       return retVal;
-}
-#else
+#ifndef USE_SDL_SURFACE
 local long GetPaletteChecksum(const Palette* palette)
 {
        long retVal;
@@ -927,375 +879,6 @@
 
        MapColorCycle();                                // FIXME: could be 
little more informative
        MustRedraw |= RedrawColorCycle;
-}
-#endif
-
-/*===========================================================================
-Following functions support a single common palette for 8bpp
-===========================================================================*/
-/**
-**       Fills a hardware independend palette with most common colors.
-**       (Only really needed in 8bpp, to get a good representation of all color
-**        possibilities.)
-**       NOTE: define BPP8_WINSAFE or BPP8_IRGB for a different version.
-**                     X11 supports BPP8_NORMAL to prevent using a common 
palette
-**                     (this will deliver "color allocation error" though!)
-**
-**       @param palette  256 color palette, to be filled with most common RGB.
-**
-**       FIXME: Use TheUI settings (brightness, contrast and saturation) and
-**       visual color range knowledge to reduce the ammount of colors needed.
-*/
-#ifdef USE_SDL_SURFACE
-       // FIXME: todo
-#else
-local void VideoFillCommonPalette8(Palette* palette)
-{
-#ifdef BPP8_WINSAFE
-       /*--------------------------------------------------------------------
-       This pallete generator is considered safe for Windows(tm), as static
-       colors used by the system are kept and at the original locations.
-       --------------------------------------------------------------------*/
-       const unsigned char win_top[] = {
-               0, 0, 0,
-               128, 0, 0,
-               0, 128, 0,
-               128, 128, 0,
-               0, 0, 128,
-               128, 0, 128,
-               0, 128, 128,
-               192, 192, 192,
-               192, 220, 192,
-               166, 202, 240,
-       };
-       const unsigned char win_bottom[] = {
-               255, 251, 240,
-               160, 160, 164,
-               128, 128, 128,
-               255, 0, 0,
-               0, 255, 0,
-               255, 255, 0,
-               0, 0, 255,
-               255, 0, 255,
-               0, 255, 255,
-               255, 255, 255,
-       };
-       const unsigned char colorlevel[] = { 0, 87, 138, 181, 220, 255 };
-       const unsigned char graylevel[]  = {
-       47,  67,  82,  95, 106, 116, 125, 134, 142, 150, 157, 164, 171, 177,
-       183, 189, 195, 201, 206, 212, 217, 222, 227, 232, 237, 241, 246, 251 };
-
-       int i;
-       int r;
-       int g;
-       int b;
-
-       /* Fill top of palette with static system colors */
-       for (i = 0; i <= 3 * 9; i += 3, ++palette) {
-               palette->r = win_top[i];
-               palette->g = win_top[i + 1];
-               palette->b = win_top[i + 2];
-       }
-
-       /* Fill 6*6*6 colorcube (without values already present in static 
parts) */
-       for (r = 0; r <= 5; ++r) {
-               for (g = 0; g <= 5; ++g) {
-                       for (b = 0; b <= 5; ++b) {
-                               if ((r && r != 5) || (g && g != 5) || (b && b 
!= 5)) {
-                                       palette->r = colorlevel[r];
-                                       palette->g = colorlevel[g];
-                                       palette->b = colorlevel[b];
-                                       ++palette;
-                               }
-                       }
-               }
-       }
-
-       /* Fill up remaining non-static part with grayshades */
-       for (i = 0; i <= 27; ++i, ++palette) {
-               palette->r = palette->g = palette->b = graylevel[i];
-       }
-
-       /* Fill bottom of palette with static system colors */
-       for (i = 0; i <= 3 * 9; i += 3, ++palette) {
-               palette->r = win_bottom[i];
-               palette->g = win_bottom[i + 1];
-               palette->b = win_bottom[i + 2];
-       }
-
-#else
-#ifdef BPP8_IRGB
-       
/*---------------------------------------------------------------------------
-       Palette generator using 8bit encoded as [IIRRGGBB], where I denotes the
-       intensity of the RGB values along a grayshade axis. Which delivers a 
better
-       spread out RGB range, but can not handle extreme values like 255:0:255
-       
---------------------------------------------------------------------------*/
-       int i;
-       int r;
-       int g;
-       int b;
-
-       for (i = 0; i <= 3 * 68; i += 68) {
-               for (r = 0; r <= 3 * 17; r += 17) {
-                       for (g = 0; g <= 3 * 17; g += 17) {
-                               for (b = 0; b <= 3 * 17; b += 17, ++palette) {
-                                       palette->r = i + r;
-                                       palette->g = i + g;
-                                       palette->b = i + b;
-                               }
-                       }
-               }
-       }
-
-#else
-       /* default 
------------------------------------------------------------------
-       Experimental palette, defining a colorcube in a hshorter (most common) 
range
-       and defining remaining as 40 grayshades over total range.
-       This delivered best quality in 8bpp gameplay:
-       - the large range for grayshades is valuable as many items need them
-       - the shortened colorcube seems just to fit any colors needed.
-       
---------------------------------------------------------------------------*/
-       int i;
-       int r;
-       int g;
-       int b;
-
-       /* Fill 6*6*6 colorcube (shortend and in lower RGB range) */
-       for (r = 0; r <= 5; ++r) {
-               for (g = 0; g <= 5; ++g) {
-                       for (b = 0; b <= 5; ++b, ++palette) {
-                               palette->r = 15 + (127 * r) / 5;
-                               palette->g = 15 + (127 * g) / 5;
-                               palette->b = 15 + (127 * b) / 5;
-                       }
-               }
-       }
-
-       /* Fill up remaining part with grayshades */
-       for (i = 0; i <= 39; ++i, ++palette) {
-               palette->r = palette->g = palette->b = ((i - 216) * 255) / 39;
-       }
-#endif
-#endif
-}
-#endif
-
-/**
-**       Fill a colorcube to get from a RGB (5x5x5 bit) to a system 8bpp color
-**
-**       @param palette  Array of 256 bytes with hardware dependent color as
-**                                       index, delivers RGB value (each in 
range 0..255).
-**
-**       @param pal_def  Denotes which entries (as bit index) in above palette
-**                                       are defined (and so may be used in 
colorcube).
-**                                       NOTE: atleast one defined entry 
should be available
-**
-**       @param cube    Array of 32768 (32*32*32) bytes with RGB value (each in
-**                                       range 0..31) as index, delivers color 
index.
-*/
-#ifdef USE_SDL_SURFACE
-       // FIXME: todo
-#else
-local void VideoFillColorcube8(const Palette* palette,
-       const unsigned long pal_def[8], VMemType8* cube)
-{
-       int r;
-       int g;
-       int b;
-       int i;
-
-       for (r = 0; r <= 255; r += 8) {
-               for (g = 0; g <= 255; g += 8) {
-                       for (b = 0; b <= 255; b += 8) {
-                               const Palette* pal;
-                               long int mindistance = 255 * 255 * 3 + 1;
-                               int colorfound = 0;
-
-                               // seek closest color in given palette
-                               for (pal = palette, i = 0; i <= 255; ++pal, 
++i) {
-                                       unsigned long bit;
-
-                                       bit = 1 << (i & 0x1F);
-                                       if (pal_def[i >> 5] & bit) {
-                                               long int distance;
-                                               long int xr;
-                                               long int xg;
-                                               long int xb;
-
-                                               xr = (long int)pal->r - r;
-                                               xb = (long int)pal->b - b;
-                                               xg = (long int)pal->g - g;
-                                               distance = xr * xr + xb * xb + 
xg * xg;
-                                               if (distance < mindistance) {
-                                                       mindistance = distance;
-                                                       colorfound = i;
-                                               }
-                                       }
-                               }
-
-                               // refer RGB to the system color (palette 
index) found
-                               *cube++ = colorfound;
-//                             fprintf(stderr, "%d %d %d = %d %d %d\n",
-//                                     r, g, b, palette[colorfound].r, 
palette[colorfound].g,
-//                                     palette[colorfound].b);
-                       }
-               }
-       }
-}
-#endif
-
-/**
-**       Find a new hardware dependend palette, re-using the colors as set in
-**       the colorcube.
-**
-**       @param cube    A 5x5x5 bit colorcube to get from RGB to system color.
-**
-**       @param palette  Hardware independend palette of 256 colors.
-**
-**       @return                A hardware dependend 8bpp pixel table.
-**
-*/
-#ifdef USE_SDL_SURFACE
-       // FIXME: todo2
-#else
-global VMemType8* VideoFindNewPalette8(const VMemType8* cube,
-       const Palette* palette)
-{
-       VMemType8* newpixels;
-       VMemType8* p;
-       int i;
-
-       newpixels = p = malloc(256 * sizeof(VMemType8));
-
-       i = 256;
-       do {
-               int r;
-               int g;
-               int b;
-
-               //FIXME: find a faster way, with rounding..
-//             r = palette->r >> 3;
-//             g = palette->g >> 3;
-//             b = palette->b >> 3;
-               r = (palette->r * 31 + 15) / 255;
-               g = (palette->g * 31 + 15) / 255;
-               b = (palette->b * 31 + 15) / 255;
-
-               ++palette;
-               *p++ = cube[(r << 10) | (g << 5) | b];
-       } while (--i > 0);
-
-       return newpixels;
-}
-
-/**
-**       Fill a lookup table to get from two system colors 8bpp as unsigned int
-**       (color1<<8)|color2 to a new system color which is alpha% color2 and
-**       (100-alpha)% color1.
-**
-**       @param palette                Already filled 256 color palette, to 
get from system
-**                                       color to RGB.
-**
-**       @param cube           Already filled 32*32*32 array of system colors, 
to get
-**                                       from RGB (as 5x5x5 bit) back to 
system color.
-**
-**       @param lookup         Allocated 256*256 array of system colors, to be 
filled
-**                                       as a lookup table for transparency 
alpha.
-**
-**       @param alpha          value in 0..255 denoting 0..100% transparency
-*/
-local void FillTransLookup8(const Palette* palette, const VMemType8* cube,
-       VMemType8* lookup, unsigned char alpha)
-{
-       const Palette* p1;
-       const Palette* p2;
-       unsigned int i;
-       unsigned int j;
-       unsigned int alpha1;
-       unsigned int alpha2;
-       unsigned int r1;
-       unsigned int g1;
-       unsigned int b1;
-       unsigned int r2;
-       unsigned int g2;
-       unsigned int b2;
-
-       alpha1 = 255 - alpha;
-       alpha2 = alpha;
-       for (p1 = palette, i = 256; i > 0; --i) {
-               r1 = alpha1 * (unsigned int)p1->r;
-               g1 = alpha1 * (unsigned int)p1->g;
-               b1 = alpha1 * (unsigned int)p1->b;
-               ++p1;
-               for (p2 = palette, j = 256; j > 0; --j) {
-                       r2 = (r1 + alpha2 * (unsigned int)p2->r + 255 * 4) / 
(255 * 8);
-                       g2 = (g1 + alpha2 * (unsigned int)p2->g + 255 * 4) / 
(255 * 8);
-                       b2 = (b1 + alpha2 * (unsigned int)p2->b + 255 * 4) / 
(255 * 8);
-                       ++p2;
-
-                       *lookup++ = cube[(r2 << 10) | (g2 << 5) | b2];
-               }
-       }
-}
-#endif
-/**
-**       Initialize globals based on a single common palette of 256 colors.
-**       Only needed for 8bpp, which hasn't RGB encoded in its system color.
-**       FIXME: should be called again when it gets dependent of TheUI settings
-**                      then call VideoFreePalette first to prevent "can not 
allocate"
-*/
-#ifdef USE_SDL_SURFACE
-local void InitSingleCommonPalette(void)
-{
-}
-#else
-local void InitSingleCommonPalette8(void)
-{
-       Palette* tmp;
-       int i;
-
-       if ((tmp = malloc(256 * sizeof(Palette))) &&
-                       (!VideoAllocPalette8 || (commonpalette = malloc(256 * 
sizeof(Palette)))) &&
-                       (colorcube8 = malloc(32 * 32 * 32 * sizeof(VMemType8))) 
&&
-                       (lookup25trans8 = malloc(256 * 256 * 
sizeof(VMemType8))) &&
-                       (lookup50trans8 = malloc(256 * 256 * 
sizeof(VMemType8)))) {
-               // Create one allocated pallette of 256 colors to be used by all
-               // palettes created later.
-               // This prevents "can not allocate color" errors, but the 
downside is
-               // that a fullscreen graphic can not use its own pallette to 
the fullest
-               // (not all colors might be present in the system pallete).
-               VideoFillCommonPalette8(tmp);
-               //for (i = 0; i <= 255; ++i) {
-               //  fprintf(stderr, "%d %d %d\n", tmp[i].r, tmp[i].g, tmp[i].b);
-               //}
-
-               if (VideoAllocPalette8) {
-                       // Palette needs to be converted to hardware dependent 
palette
-                       VideoAllocPalette8(tmp, commonpalette, 
commonpalette_defined);
-                       free(tmp);
-               } else {
-                       // Use palette AS-IS FIXME: unused at the moment..
-                       commonpalette = tmp;
-                       for (i = 0; i <= 7; ++i) {
-                               commonpalette_defined[i] = 0xFFFFFFFF;
-                       }
-               }
-
-               // Create a colorcube to easily get from RGB back to system 
color
-               VideoFillColorcube8(commonpalette, commonpalette_defined, 
colorcube8);
-
-               // Create lookup tables to get from one system color to another.
-               //FIXME: With max 256 unique colors in above colorcube, each 
RGB axis can
-               //         contain 3root(256)=6.3496.. variations. Currently 
only 5
-               //         supported (0,25,50,75,100% with/without use of 
lookup tables).
-               //         So extra levels 12.5% and 37.5% needed for better 
representation.
-               FillTransLookup8(commonpalette, colorcube8, lookup25trans8, 
(255 + 2) / 4);
-               FillTransLookup8(commonpalette, colorcube8, lookup50trans8, 
(255 + 1) / 2);
-       } else {
-               fprintf(stderr, "Out of memory for special 8bpp display mode\n"
-                       "Try another mode if you're low on memory\n");
-               exit(-1);
-       }
 }
 #endif
 




reply via email to

[Prev in Thread] Current Thread [Next in Thread]