Split off SDL-specific colormap bits into SDL domain; fixed minor SDL_Palette access bug; some colormap processing cleanups
git-svn-id: svn://svn.code.sf.net/p/sc2/code/trunk@3433 8092fc87-c524-0410-9efc-e669fe64eaf9
This commit is contained in:
@@ -1,4 +1,5 @@
|
|||||||
Changes towards version 0.7:
|
Changes towards version 0.7:
|
||||||
|
- Split off SDL-specific colormap bits into SDL domain - Alex
|
||||||
- Fixed planet blinking when exiting scan (bug #799) - Alex
|
- Fixed planet blinking when exiting scan (bug #799) - Alex
|
||||||
- Restore menu sounds after editing a control set name (bug #1066) - Alex
|
- Restore menu sounds after editing a control set name (bug #1066) - Alex
|
||||||
- Use an own 'UniChar' rather than 'wchar_t', which may not be large
|
- Use an own 'UniChar' rather than 'wchar_t', which may not be large
|
||||||
|
|||||||
@@ -16,7 +16,8 @@
|
|||||||
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "gfx_common.h"
|
#include "libs/graphics/cmap.h"
|
||||||
|
#include "libs/threadlib.h"
|
||||||
#include "libs/timelib.h"
|
#include "libs/timelib.h"
|
||||||
#include "libs/inplib.h"
|
#include "libs/inplib.h"
|
||||||
#include "libs/log.h"
|
#include "libs/log.h"
|
||||||
@@ -48,10 +49,11 @@ static TimeCount fadeStartTime;
|
|||||||
static sint32 fadeInterval;
|
static sint32 fadeInterval;
|
||||||
|
|
||||||
#define SPARE_COLORMAPS 20
|
#define SPARE_COLORMAPS 20
|
||||||
#define MAP_POOL_SIZE (MAX_COLORMAPS + SPARE_COLORMAPS)
|
|
||||||
|
|
||||||
static TFB_ColorMap mappool[MAP_POOL_SIZE];
|
// Colormaps are rapidly replaced in some parts of the game, so
|
||||||
|
// it pays to have some spares on hand
|
||||||
static TFB_ColorMap *poolhead;
|
static TFB_ColorMap *poolhead;
|
||||||
|
static int poolcount;
|
||||||
|
|
||||||
static TFB_ColorMap * colormaps[MAX_COLORMAPS];
|
static TFB_ColorMap * colormaps[MAX_COLORMAPS];
|
||||||
static int mapcount;
|
static int mapcount;
|
||||||
@@ -65,11 +67,6 @@ InitColorMaps (void)
|
|||||||
|
|
||||||
// init colormaps
|
// init colormaps
|
||||||
maplock = CreateMutex ("Colormaps Lock", SYNC_CLASS_TOPLEVEL | SYNC_CLASS_VIDEO);
|
maplock = CreateMutex ("Colormaps Lock", SYNC_CLASS_TOPLEVEL | SYNC_CLASS_VIDEO);
|
||||||
// init static pool
|
|
||||||
for (i = 0; i < MAP_POOL_SIZE - 1; ++i)
|
|
||||||
mappool[i].next = mappool + i + 1;
|
|
||||||
mappool[i].next = NULL;
|
|
||||||
poolhead = mappool;
|
|
||||||
|
|
||||||
// init xform control
|
// init xform control
|
||||||
XFormControl.Highest = -1;
|
XFormControl.Highest = -1;
|
||||||
@@ -81,6 +78,15 @@ InitColorMaps (void)
|
|||||||
void
|
void
|
||||||
UninitColorMaps (void)
|
UninitColorMaps (void)
|
||||||
{
|
{
|
||||||
|
TFB_ColorMap *next;
|
||||||
|
|
||||||
|
// free spares
|
||||||
|
for ( ; poolhead; poolhead = next)
|
||||||
|
{
|
||||||
|
next = poolhead->next;
|
||||||
|
HFree (poolhead);
|
||||||
|
}
|
||||||
|
|
||||||
// uninit xform control
|
// uninit xform control
|
||||||
DestroyMutex (XFormControl.Lock);
|
DestroyMutex (XFormControl.Lock);
|
||||||
|
|
||||||
@@ -94,12 +100,22 @@ alloc_colormap (void)
|
|||||||
{
|
{
|
||||||
TFB_ColorMap *map;
|
TFB_ColorMap *map;
|
||||||
|
|
||||||
if (!poolhead)
|
if (poolhead)
|
||||||
return NULL;
|
{ // have some spares
|
||||||
|
|
||||||
map = poolhead;
|
map = poolhead;
|
||||||
poolhead = map->next;
|
poolhead = map->next;
|
||||||
|
--poolcount;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{ // no spares, need a new one
|
||||||
|
map = HMalloc (sizeof (*map));
|
||||||
|
map->palette = AllocNativePalette ();
|
||||||
|
if (!map->palette)
|
||||||
|
{
|
||||||
|
HFree (map);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
}
|
||||||
map->next = NULL;
|
map->next = NULL;
|
||||||
map->index = -1;
|
map->index = -1;
|
||||||
map->refcount = 1;
|
map->refcount = 1;
|
||||||
@@ -116,28 +132,11 @@ clone_colormap (TFB_ColorMap *from, int index)
|
|||||||
|
|
||||||
map = alloc_colormap ();
|
map = alloc_colormap ();
|
||||||
if (!map)
|
if (!map)
|
||||||
{
|
|
||||||
static DWORD NextTime = 0;
|
|
||||||
DWORD Now;
|
|
||||||
|
|
||||||
if (!from)
|
|
||||||
{
|
{
|
||||||
log_add (log_Warning, "FATAL: clone_colormap(): "
|
log_add (log_Warning, "FATAL: clone_colormap(): "
|
||||||
"no maps available");
|
"could not allocate a map");
|
||||||
exit (EXIT_FAILURE);
|
exit (EXIT_FAILURE);
|
||||||
}
|
}
|
||||||
|
|
||||||
Now = GetTimeCounter ();
|
|
||||||
if (Now >= NextTime)
|
|
||||||
{
|
|
||||||
log_add (log_Warning, "clone_colormap(): static pool exhausted");
|
|
||||||
NextTime = Now + ONE_SECOND;
|
|
||||||
}
|
|
||||||
|
|
||||||
// just overwrite the current one -- better than aborting
|
|
||||||
map = from;
|
|
||||||
from->refcount++;
|
|
||||||
}
|
|
||||||
else
|
else
|
||||||
{ // fresh new map
|
{ // fresh new map
|
||||||
map->index = index;
|
map->index = index;
|
||||||
@@ -158,8 +157,17 @@ free_colormap (TFB_ColorMap *map)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (poolcount < SPARE_COLORMAPS)
|
||||||
|
{ // return to the spare pool
|
||||||
map->next = poolhead;
|
map->next = poolhead;
|
||||||
poolhead = map;
|
poolhead = map;
|
||||||
|
++poolcount;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{ // don't need any more spares
|
||||||
|
FreeNativePalette (map->palette);
|
||||||
|
HFree (map);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline TFB_ColorMap *
|
static inline TFB_ColorMap *
|
||||||
@@ -216,21 +224,15 @@ TFB_GetColorMap (int index)
|
|||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
TFB_ColorMapToRGB (Color *pal, int index)
|
GetColorMapColors (Color *colors, TFB_ColorMap *map)
|
||||||
{
|
{
|
||||||
TFB_ColorMap *map = NULL;
|
int i;
|
||||||
|
|
||||||
if (index < mapcount)
|
|
||||||
map = colormaps[index];
|
|
||||||
|
|
||||||
if (!map)
|
if (!map)
|
||||||
{
|
|
||||||
log_add (log_Warning, "TFB_ColorMapToRGB(): "
|
|
||||||
"requested non-present colormap %d", index);
|
|
||||||
return;
|
return;
|
||||||
}
|
|
||||||
|
|
||||||
memcpy (pal, map->colors, sizeof map->colors);
|
for (i = 0; i < NUMBER_OF_PLUTVALS; ++i)
|
||||||
|
colors[i] = GetNativePaletteColor (map->palette, i);
|
||||||
}
|
}
|
||||||
|
|
||||||
BOOLEAN
|
BOOLEAN
|
||||||
@@ -279,18 +281,21 @@ SetColorMap (COLORMAPPTR map)
|
|||||||
for (mpp = colormaps + start; start <= end; ++start, ++mpp)
|
for (mpp = colormaps + start; start <= end; ++start, ++mpp)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
Color *pal;
|
|
||||||
TFB_ColorMap *newmap;
|
TFB_ColorMap *newmap;
|
||||||
TFB_ColorMap *oldmap;
|
TFB_ColorMap *oldmap;
|
||||||
|
|
||||||
oldmap = *mpp;
|
oldmap = *mpp;
|
||||||
newmap = clone_colormap (oldmap, start);
|
newmap = clone_colormap (oldmap, start);
|
||||||
|
|
||||||
for (i = 0, pal = newmap->colors; i < NUMBER_OF_PLUTVALS; ++i, ++pal)
|
for (i = 0; i < NUMBER_OF_PLUTVALS; ++i, colors += PLUTVAL_BYTE_SIZE)
|
||||||
{
|
{
|
||||||
pal->r = *colors++;
|
Color color;
|
||||||
pal->g = *colors++;
|
|
||||||
pal->b = *colors++;
|
color.a = 0xff;
|
||||||
|
color.r = colors[PLUTVAL_RED];
|
||||||
|
color.g = colors[PLUTVAL_GREEN];
|
||||||
|
color.b = colors[PLUTVAL_BLUE];
|
||||||
|
SetNativePaletteColor (newmap->palette, i, color);
|
||||||
}
|
}
|
||||||
|
|
||||||
*mpp = newmap;
|
*mpp = newmap;
|
||||||
@@ -418,6 +423,11 @@ finish_colormap_xform (int which)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static inline BYTE
|
||||||
|
blendChan (BYTE c1, BYTE c2, int weight, int scale)
|
||||||
|
{
|
||||||
|
return c1 + ((int)c2 - c1) * weight / scale;
|
||||||
|
}
|
||||||
|
|
||||||
/* This gives the XFormColorMap task a timeslice to do its thing
|
/* This gives the XFormColorMap task a timeslice to do its thing
|
||||||
* Only one thread should ever be allowed to be calling this at any time
|
* Only one thread should ever be allowed to be calling this at any time
|
||||||
@@ -456,34 +466,32 @@ XFormColorMap_step (void)
|
|||||||
{
|
{
|
||||||
#define XFORM_SCALE 0x10000
|
#define XFORM_SCALE 0x10000
|
||||||
TFB_ColorMap *newmap = NULL;
|
TFB_ColorMap *newmap = NULL;
|
||||||
UBYTE *pNewCMap;
|
UBYTE *newClr;
|
||||||
Color *pCurCMap, *pOldCMap;
|
Color *oldClr;
|
||||||
int frac;
|
int frac;
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
newmap = clone_colormap (curmap, index);
|
newmap = clone_colormap (curmap, index);
|
||||||
|
|
||||||
pCurCMap = newmap->colors;
|
oldClr = control->OldCMap;
|
||||||
pOldCMap = control->OldCMap;
|
newClr = (UBYTE*)control->CMapPtr + 2;
|
||||||
pNewCMap = (UBYTE*)control->CMapPtr + 2;
|
|
||||||
|
|
||||||
frac = (int)(control->Ticks - TicksLeft) * XFORM_SCALE
|
frac = (int)(control->Ticks - TicksLeft) * XFORM_SCALE
|
||||||
/ control->Ticks;
|
/ control->Ticks;
|
||||||
|
|
||||||
for (i = 0; i < NUMBER_OF_PLUTVALS; i++, ++pCurCMap, ++pOldCMap)
|
for (i = 0; i < NUMBER_OF_PLUTVALS; ++i, ++oldClr,
|
||||||
|
newClr += PLUTVAL_BYTE_SIZE)
|
||||||
{
|
{
|
||||||
|
Color color;
|
||||||
|
|
||||||
pCurCMap->r = (UBYTE)(pOldCMap->r +
|
color.a = 0xff;
|
||||||
((int)*pNewCMap - pOldCMap->r) * frac / XFORM_SCALE);
|
color.r = blendChan (oldClr->r, newClr[PLUTVAL_RED],
|
||||||
pNewCMap++;
|
frac, XFORM_SCALE);
|
||||||
|
color.g = blendChan (oldClr->g, newClr[PLUTVAL_GREEN],
|
||||||
pCurCMap->g = (UBYTE)(pOldCMap->g +
|
frac, XFORM_SCALE);
|
||||||
((int)*pNewCMap - pOldCMap->g) * frac / XFORM_SCALE);
|
color.b = blendChan (oldClr->b, newClr[PLUTVAL_BLUE],
|
||||||
pNewCMap++;
|
frac, XFORM_SCALE);
|
||||||
|
SetNativePaletteColor (newmap->palette, i, color);
|
||||||
pCurCMap->b = (UBYTE)(pOldCMap->b +
|
|
||||||
((int)*pNewCMap - pOldCMap->b) * frac / XFORM_SCALE);
|
|
||||||
pNewCMap++;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
colormaps[index] = newmap;
|
colormaps[index] = newmap;
|
||||||
@@ -575,7 +583,7 @@ XFormPLUT (COLORMAPPTR ColorMapPtr, SIZE TimeInterval)
|
|||||||
log_add (log_Warning, "BUG: XFormPLUT(): no current map");
|
log_add (log_Warning, "BUG: XFormPLUT(): no current map");
|
||||||
return (0);
|
return (0);
|
||||||
}
|
}
|
||||||
memcpy (control->OldCMap, map->colors, sizeof (map->colors));
|
GetColorMapColors (control->OldCMap, map);
|
||||||
UnlockMutex (maplock);
|
UnlockMutex (maplock);
|
||||||
|
|
||||||
control->CMapIndex = index;
|
control->CMapIndex = index;
|
||||||
|
|||||||
@@ -16,27 +16,44 @@
|
|||||||
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "tfb_draw.h"
|
|
||||||
|
|
||||||
#ifndef CMAP_H
|
#ifndef CMAP_H
|
||||||
#define CMAP_H
|
#define CMAP_H
|
||||||
|
|
||||||
|
#include "libs/gfxlib.h"
|
||||||
|
|
||||||
#define MAX_COLORMAPS 250
|
#define MAX_COLORMAPS 250
|
||||||
|
|
||||||
|
// These are pertinent to colortable file format
|
||||||
|
// We load colormaps as binary and parse them when needed
|
||||||
#define PLUTVAL_BYTE_SIZE 3
|
#define PLUTVAL_BYTE_SIZE 3
|
||||||
|
// Channel order in colormap tables
|
||||||
|
#define PLUTVAL_RED 0
|
||||||
|
#define PLUTVAL_GREEN 1
|
||||||
|
#define PLUTVAL_BLUE 2
|
||||||
|
|
||||||
#define NUMBER_OF_PLUTVALS 256
|
#define NUMBER_OF_PLUTVALS 256
|
||||||
|
// Size of the colormap in a colortable file
|
||||||
#define PLUT_BYTE_SIZE (PLUTVAL_BYTE_SIZE * NUMBER_OF_PLUTVALS)
|
#define PLUT_BYTE_SIZE (PLUTVAL_BYTE_SIZE * NUMBER_OF_PLUTVALS)
|
||||||
|
|
||||||
#define FADE_NO_INTENSITY 0
|
#define FADE_NO_INTENSITY 0
|
||||||
#define FADE_NORMAL_INTENSITY 255
|
#define FADE_NORMAL_INTENSITY 255
|
||||||
#define FADE_FULL_INTENSITY 510
|
#define FADE_FULL_INTENSITY 510
|
||||||
|
|
||||||
|
typedef struct NativePalette NativePalette;
|
||||||
|
|
||||||
typedef struct tfb_colormap
|
typedef struct tfb_colormap
|
||||||
{
|
{
|
||||||
Color colors[NUMBER_OF_PLUTVALS];
|
|
||||||
int index;
|
int index;
|
||||||
|
// Colormap index as the game sees it
|
||||||
int version;
|
int version;
|
||||||
|
// Version goes up every time the colormap changes. This may
|
||||||
|
// be due to SetColorMap() or at every transformation step
|
||||||
|
// of XFormColorMap(). Paletted TFB_Images track the last
|
||||||
|
// colormap version they were drawn with for optimization.
|
||||||
int refcount;
|
int refcount;
|
||||||
struct tfb_colormap *next;
|
struct tfb_colormap *next;
|
||||||
|
// for spares linking
|
||||||
|
NativePalette *palette;
|
||||||
} TFB_ColorMap;
|
} TFB_ColorMap;
|
||||||
|
|
||||||
extern int GetFadeAmount (void);
|
extern int GetFadeAmount (void);
|
||||||
@@ -44,11 +61,17 @@ extern int GetFadeAmount (void);
|
|||||||
extern void InitColorMaps (void);
|
extern void InitColorMaps (void);
|
||||||
extern void UninitColorMaps (void);
|
extern void UninitColorMaps (void);
|
||||||
|
|
||||||
extern void TFB_ColorMapToRGB (Color *pal, int colormap_index);
|
extern void GetColorMapColors (Color *colors, TFB_ColorMap *);
|
||||||
|
|
||||||
extern TFB_ColorMap * TFB_GetColorMap (int index);
|
extern TFB_ColorMap * TFB_GetColorMap (int index);
|
||||||
extern void TFB_ReturnColorMap (TFB_ColorMap *map);
|
extern void TFB_ReturnColorMap (TFB_ColorMap *map);
|
||||||
|
|
||||||
extern BOOLEAN XFormColorMap_step (void);
|
extern BOOLEAN XFormColorMap_step (void);
|
||||||
|
|
||||||
|
// Native
|
||||||
|
NativePalette* AllocNativePalette (void);
|
||||||
|
void FreeNativePalette (NativePalette *);
|
||||||
|
void SetNativePaletteColor (NativePalette *, int index, Color);
|
||||||
|
Color GetNativePaletteColor (NativePalette *, int index);
|
||||||
|
|
||||||
#endif
|
#endif /* CMAP_H */
|
||||||
|
|||||||
@@ -99,6 +99,4 @@ extern int ScreenHeightActual;
|
|||||||
extern int ScreenColorDepth;
|
extern int ScreenColorDepth;
|
||||||
extern int GraphicsDriver;
|
extern int GraphicsDriver;
|
||||||
|
|
||||||
#include "cmap.h"
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
uqm_CFILES="3do_blt.c 3do_funcs.c 3do_getbody.c dcqueue.c opengl.c
|
uqm_CFILES="3do_blt.c 3do_funcs.c 3do_getbody.c dcqueue.c opengl.c
|
||||||
|
palette.c
|
||||||
primitives.c pure.c rndzoom.c sdl_common.c
|
primitives.c pure.c rndzoom.c sdl_common.c
|
||||||
scalers.c 2xscalers.c
|
scalers.c 2xscalers.c
|
||||||
2xscalers_mmx.c 2xscalers_sse.c 2xscalers_3dnow.c
|
2xscalers_mmx.c 2xscalers_sse.c 2xscalers_3dnow.c
|
||||||
|
|||||||
@@ -18,10 +18,12 @@
|
|||||||
#include SDL_INCLUDE(SDL.h)
|
#include SDL_INCLUDE(SDL.h)
|
||||||
#include "sdl_common.h"
|
#include "sdl_common.h"
|
||||||
#include "libs/graphics/gfx_common.h"
|
#include "libs/graphics/gfx_common.h"
|
||||||
#include "libs/graphics/sdl/primitives.h"
|
|
||||||
#include "libs/graphics/tfb_draw.h"
|
#include "libs/graphics/tfb_draw.h"
|
||||||
|
#include "libs/graphics/cmap.h"
|
||||||
#include "libs/log.h"
|
#include "libs/log.h"
|
||||||
#include "libs/memlib.h"
|
#include "libs/memlib.h"
|
||||||
|
#include "primitives.h"
|
||||||
|
#include "palette.h"
|
||||||
#include "rotozoom.h"
|
#include "rotozoom.h"
|
||||||
#include "options.h"
|
#include "options.h"
|
||||||
#include "types.h"
|
#include "types.h"
|
||||||
@@ -80,13 +82,15 @@ TFB_DrawCanvas_Rect (RECT *rect, Color color, TFB_Canvas target)
|
|||||||
SDL_FillRect (dst, &sr, sdlColor);
|
SDL_FillRect (dst, &sr, sdlColor);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// XXX: If a colormap is passed in, it has to have been acquired via
|
||||||
|
// TFB_GetColorMap(). We release the colormap at the end.
|
||||||
void
|
void
|
||||||
TFB_DrawCanvas_Image (TFB_Image *img, int x, int y, int scale,
|
TFB_DrawCanvas_Image (TFB_Image *img, int x, int y, int scale,
|
||||||
TFB_ColorMap *cmap, TFB_Canvas target)
|
TFB_ColorMap *cmap, TFB_Canvas target)
|
||||||
{
|
{
|
||||||
SDL_Rect srcRect, targetRect, *pSrcRect;
|
SDL_Rect srcRect, targetRect, *pSrcRect;
|
||||||
SDL_Surface *surf;
|
SDL_Surface *surf;
|
||||||
Color *palette;
|
SDL_Palette *NormalPal;
|
||||||
|
|
||||||
if (img == 0)
|
if (img == 0)
|
||||||
{
|
{
|
||||||
@@ -97,15 +101,10 @@ TFB_DrawCanvas_Image (TFB_Image *img, int x, int y, int scale,
|
|||||||
|
|
||||||
LockMutex (img->mutex);
|
LockMutex (img->mutex);
|
||||||
|
|
||||||
if (cmap)
|
NormalPal = ((SDL_Surface *)img->NormalImg)->format->palette;
|
||||||
palette = cmap->colors;
|
|
||||||
else
|
|
||||||
palette = img->Palette;
|
|
||||||
|
|
||||||
// only set the new palette if it changed
|
// only set the new palette if it changed
|
||||||
if (((SDL_Surface *)img->NormalImg)->format->palette
|
if (NormalPal && cmap && img->colormap_version != cmap->version)
|
||||||
&& cmap && img->colormap_version != cmap->version)
|
SDL_SetColors (img->NormalImg, cmap->palette->colors, 0, 256);
|
||||||
SDL_SetColors (img->NormalImg, (SDL_Color*)palette, 0, 256);
|
|
||||||
|
|
||||||
if (scale != 0 && scale != GSCALE_IDENTITY)
|
if (scale != 0 && scale != GSCALE_IDENTITY)
|
||||||
{
|
{
|
||||||
@@ -114,9 +113,9 @@ TFB_DrawCanvas_Image (TFB_Image *img, int x, int y, int scale,
|
|||||||
if (type == TFB_SCALE_TRILINEAR && img->MipmapImg)
|
if (type == TFB_SCALE_TRILINEAR && img->MipmapImg)
|
||||||
{
|
{
|
||||||
// only set the new palette if it changed
|
// only set the new palette if it changed
|
||||||
if (((SDL_Surface *)img->MipmapImg)->format->palette
|
if (TFB_DrawCanvas_IsPaletted (img->MipmapImg)
|
||||||
&& cmap && img->colormap_version != cmap->version)
|
&& cmap && img->colormap_version != cmap->version)
|
||||||
SDL_SetColors (img->MipmapImg, (SDL_Color*)palette, 0, 256);
|
SDL_SetColors (img->MipmapImg, cmap->palette->colors, 0, 256);
|
||||||
}
|
}
|
||||||
else if (type == TFB_SCALE_TRILINEAR && !img->MipmapImg)
|
else if (type == TFB_SCALE_TRILINEAR && !img->MipmapImg)
|
||||||
{
|
{
|
||||||
@@ -125,8 +124,13 @@ TFB_DrawCanvas_Image (TFB_Image *img, int x, int y, int scale,
|
|||||||
|
|
||||||
TFB_DrawImage_FixScaling (img, scale, type);
|
TFB_DrawImage_FixScaling (img, scale, type);
|
||||||
surf = img->ScaledImg;
|
surf = img->ScaledImg;
|
||||||
if (surf->format->palette)
|
if (TFB_DrawCanvas_IsPaletted (surf))
|
||||||
SDL_SetColors (surf, (SDL_Color*)palette, 0, 256);
|
{
|
||||||
|
// We may only get a paletted scaled image if the source is
|
||||||
|
// paletted. Currently, all scaling targets are truecolor.
|
||||||
|
assert (NormalPal && NormalPal->colors);
|
||||||
|
SDL_SetColors (surf, NormalPal->colors, 0, NormalPal->ncolors);
|
||||||
|
}
|
||||||
|
|
||||||
srcRect.x = 0;
|
srcRect.x = 0;
|
||||||
srcRect.y = 0;
|
srcRect.y = 0;
|
||||||
@@ -149,6 +153,9 @@ TFB_DrawCanvas_Image (TFB_Image *img, int x, int y, int scale,
|
|||||||
if (cmap)
|
if (cmap)
|
||||||
{
|
{
|
||||||
img->colormap_version = cmap->version;
|
img->colormap_version = cmap->version;
|
||||||
|
// TODO: Technically, this is not a proper place to release a
|
||||||
|
// colormap. As it stands now, the colormap must have been
|
||||||
|
// addrefed when passed to us.
|
||||||
TFB_ReturnColorMap (cmap);
|
TFB_ReturnColorMap (cmap);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -248,6 +255,7 @@ TFB_DrawCanvas_FilledImage (TFB_Image *img, int x, int y, int scale,
|
|||||||
{
|
{
|
||||||
SDL_Rect srcRect, targetRect, *pSrcRect;
|
SDL_Rect srcRect, targetRect, *pSrcRect;
|
||||||
SDL_Surface *surf;
|
SDL_Surface *surf;
|
||||||
|
SDL_Palette *palette;
|
||||||
int i;
|
int i;
|
||||||
bool force_fill = false;
|
bool force_fill = false;
|
||||||
|
|
||||||
@@ -299,7 +307,8 @@ TFB_DrawCanvas_FilledImage (TFB_Image *img, int x, int y, int scale,
|
|||||||
targetRect.y = y - img->NormalHs.y;
|
targetRect.y = y - img->NormalHs.y;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (surf->format->palette)
|
palette = surf->format->palette;
|
||||||
|
if (palette)
|
||||||
{ // set palette for fill-stamp
|
{ // set palette for fill-stamp
|
||||||
// Calling SDL_SetColors() results in an expensive src -> dst
|
// Calling SDL_SetColors() results in an expensive src -> dst
|
||||||
// color-mapping operation for an SDL blit, following the call.
|
// color-mapping operation for an SDL blit, following the call.
|
||||||
@@ -307,15 +316,13 @@ TFB_DrawCanvas_FilledImage (TFB_Image *img, int x, int y, int scale,
|
|||||||
|
|
||||||
// TODO: generate a 32bpp filled image?
|
// TODO: generate a 32bpp filled image?
|
||||||
|
|
||||||
SDL_Color pal[256];
|
SDL_Color colors[256];
|
||||||
|
|
||||||
for (i = 0; i < 256; i++)
|
colors[0] = ColorToNative (color);
|
||||||
{
|
for (i = 1; i < palette->ncolors; i++)
|
||||||
pal[i].r = color.r;
|
colors[i] = colors[0];
|
||||||
pal[i].g = color.g;
|
|
||||||
pal[i].b = color.b;
|
SDL_SetColors (surf, colors, 0, palette->ncolors);
|
||||||
}
|
|
||||||
SDL_SetColors (surf, pal, 0, 256);
|
|
||||||
// reflect the change in *actual* image palette
|
// reflect the change in *actual* image palette
|
||||||
img->colormap_version--;
|
img->colormap_version--;
|
||||||
}
|
}
|
||||||
@@ -488,7 +495,7 @@ TFB_DrawCanvas_New_ForScreen (int w, int h, BOOLEAN withalpha)
|
|||||||
}
|
}
|
||||||
|
|
||||||
TFB_Canvas
|
TFB_Canvas
|
||||||
TFB_DrawCanvas_New_Paletted (int w, int h, Color *palette,
|
TFB_DrawCanvas_New_Paletted (int w, int h, Color palette[256],
|
||||||
int transparent_index)
|
int transparent_index)
|
||||||
{
|
{
|
||||||
SDL_Surface *new_surf;
|
SDL_Surface *new_surf;
|
||||||
@@ -501,7 +508,7 @@ TFB_DrawCanvas_New_Paletted (int w, int h, Color *palette,
|
|||||||
}
|
}
|
||||||
if (palette != NULL)
|
if (palette != NULL)
|
||||||
{
|
{
|
||||||
SDL_SetColors(new_surf, (SDL_Color *)palette, 0, 256);
|
TFB_DrawCanvas_SetPalette (new_surf, palette);
|
||||||
}
|
}
|
||||||
if (transparent_index >= 0)
|
if (transparent_index >= 0)
|
||||||
{
|
{
|
||||||
@@ -608,21 +615,18 @@ TFB_DrawCanvas_ExtractPalette (TFB_Canvas canvas)
|
|||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
Color *result;
|
Color *result;
|
||||||
|
|
||||||
SDL_Surface *surf = (SDL_Surface *)canvas;
|
SDL_Surface *surf = (SDL_Surface *)canvas;
|
||||||
|
SDL_Palette *palette = surf->format->palette;
|
||||||
|
|
||||||
if (!surf->format->palette)
|
if (!palette)
|
||||||
{
|
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
|
||||||
|
|
||||||
result = (Color *) HMalloc (sizeof (Color) * 256);
|
// There may be less colors in the surface than 256. Init to 0 first.
|
||||||
for (i = 0; i < 256; ++i)
|
result = HCalloc (sizeof (Color) * 256);
|
||||||
{
|
assert (palette->ncolors <= 256);
|
||||||
result[i].r = surf->format->palette->colors[i].r;
|
for (i = 0; i < palette->ncolors; ++i)
|
||||||
result[i].g = surf->format->palette->colors[i].g;
|
result[i] = NativeToColor (palette->colors[i]);
|
||||||
result[i].b = surf->format->palette->colors[i].b;
|
|
||||||
}
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -656,9 +660,15 @@ TFB_DrawCanvas_IsPaletted (TFB_Canvas canvas)
|
|||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
TFB_DrawCanvas_SetPalette (TFB_Canvas target, Color *palette)
|
TFB_DrawCanvas_SetPalette (TFB_Canvas target, Color palette[256])
|
||||||
{
|
{
|
||||||
SDL_SetColors ((SDL_Surface *)target, (SDL_Color *)palette, 0, 256);
|
SDL_Color colors[256];
|
||||||
|
int i;
|
||||||
|
|
||||||
|
for (i = 0; i < 256; ++i)
|
||||||
|
colors[i] = ColorToNative (palette[i]);
|
||||||
|
|
||||||
|
SDL_SetColors ((SDL_Surface *)target, colors, 0, 256);
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
|
|||||||
@@ -0,0 +1,47 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2009 Alex Volkov <codepro@usa.net>
|
||||||
|
*
|
||||||
|
* 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
|
||||||
|
* the Free Software Foundation; either version 2 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program; if not, write to the Free Software
|
||||||
|
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "palette.h"
|
||||||
|
#include "libs/memlib.h"
|
||||||
|
#include "libs/log.h"
|
||||||
|
|
||||||
|
NativePalette *
|
||||||
|
AllocNativePalette (void)
|
||||||
|
{
|
||||||
|
return HCalloc (sizeof (NativePalette));
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
FreeNativePalette (NativePalette *palette)
|
||||||
|
{
|
||||||
|
HFree (palette);
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
SetNativePaletteColor (NativePalette *palette, int index, Color color)
|
||||||
|
{
|
||||||
|
assert (index < NUMBER_OF_PLUTVALS);
|
||||||
|
palette->colors[index] = ColorToNative (color);
|
||||||
|
}
|
||||||
|
|
||||||
|
Color
|
||||||
|
GetNativePaletteColor (NativePalette *palette, int index)
|
||||||
|
{
|
||||||
|
assert (index < NUMBER_OF_PLUTVALS);
|
||||||
|
return NativeToColor (palette->colors[index]);
|
||||||
|
}
|
||||||
@@ -0,0 +1,53 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2009 Alex Volkov <codepro@usa.net>
|
||||||
|
*
|
||||||
|
* 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
|
||||||
|
* the Free Software Foundation; either version 2 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program; if not, write to the Free Software
|
||||||
|
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef PALETTE_H_INCL__
|
||||||
|
#define PALETTE_H_INCL__
|
||||||
|
|
||||||
|
#include "port.h"
|
||||||
|
#include SDL_INCLUDE(SDL.h)
|
||||||
|
#include "libs/graphics/cmap.h"
|
||||||
|
|
||||||
|
struct NativePalette
|
||||||
|
{
|
||||||
|
SDL_Color colors[NUMBER_OF_PLUTVALS];
|
||||||
|
};
|
||||||
|
|
||||||
|
static inline Color
|
||||||
|
NativeToColor (SDL_Color native)
|
||||||
|
{
|
||||||
|
Color color;
|
||||||
|
color.r = native.r;
|
||||||
|
color.g = native.g;
|
||||||
|
color.b = native.b;
|
||||||
|
color.a = 0xff; // fully opaque
|
||||||
|
return color;
|
||||||
|
}
|
||||||
|
|
||||||
|
static inline SDL_Color
|
||||||
|
ColorToNative (Color color)
|
||||||
|
{
|
||||||
|
SDL_Color native;
|
||||||
|
native.r = color.r;
|
||||||
|
native.g = color.g;
|
||||||
|
native.b = color.b;
|
||||||
|
native.unused = 0;
|
||||||
|
return native;
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif /* PALETTE_H_INCL__ */
|
||||||
@@ -26,6 +26,7 @@
|
|||||||
#include "options.h"
|
#include "options.h"
|
||||||
#include "uqmversion.h"
|
#include "uqmversion.h"
|
||||||
#include "libs/graphics/drawcmd.h"
|
#include "libs/graphics/drawcmd.h"
|
||||||
|
#include "libs/graphics/cmap.h"
|
||||||
#include "libs/input/sdl/input.h"
|
#include "libs/input/sdl/input.h"
|
||||||
// for ProcessInputEvent()
|
// for ProcessInputEvent()
|
||||||
#include "bbox.h"
|
#include "bbox.h"
|
||||||
|
|||||||
@@ -38,8 +38,6 @@ typedef struct _tfb_graphics_backend {
|
|||||||
|
|
||||||
extern TFB_GRAPHICS_BACKEND *graphics_backend;
|
extern TFB_GRAPHICS_BACKEND *graphics_backend;
|
||||||
|
|
||||||
// constants for TFB_InitGraphics
|
|
||||||
|
|
||||||
extern SDL_Surface *SDL_Video;
|
extern SDL_Surface *SDL_Video;
|
||||||
extern SDL_Surface *SDL_Screen;
|
extern SDL_Surface *SDL_Screen;
|
||||||
extern SDL_Surface *TransitionScreen;
|
extern SDL_Surface *TransitionScreen;
|
||||||
|
|||||||
@@ -33,7 +33,7 @@ typedef enum {
|
|||||||
} SCREEN;
|
} SCREEN;
|
||||||
|
|
||||||
#include "libs/graphics/gfx_common.h"
|
#include "libs/graphics/gfx_common.h"
|
||||||
#include "cmap.h"
|
#include "libs/graphics/cmap.h"
|
||||||
|
|
||||||
typedef struct tfb_image
|
typedef struct tfb_image
|
||||||
{
|
{
|
||||||
@@ -119,7 +119,7 @@ void TFB_DrawImage_FontChar (TFB_Char *, TFB_Image *backing, int x, int y,
|
|||||||
|
|
||||||
TFB_Canvas TFB_DrawCanvas_New_TrueColor (int w, int h, BOOLEAN hasalpha);
|
TFB_Canvas TFB_DrawCanvas_New_TrueColor (int w, int h, BOOLEAN hasalpha);
|
||||||
TFB_Canvas TFB_DrawCanvas_New_ForScreen (int w, int h, BOOLEAN withalpha);
|
TFB_Canvas TFB_DrawCanvas_New_ForScreen (int w, int h, BOOLEAN withalpha);
|
||||||
TFB_Canvas TFB_DrawCanvas_New_Paletted (int w, int h, Color *palette,
|
TFB_Canvas TFB_DrawCanvas_New_Paletted (int w, int h, Color palette[256],
|
||||||
int transparent_index);
|
int transparent_index);
|
||||||
TFB_Canvas TFB_DrawCanvas_New_ScaleTarget (TFB_Canvas canvas,
|
TFB_Canvas TFB_DrawCanvas_New_ScaleTarget (TFB_Canvas canvas,
|
||||||
TFB_Canvas oldcanvas, int type, int last_type);
|
TFB_Canvas oldcanvas, int type, int last_type);
|
||||||
@@ -154,7 +154,7 @@ void TFB_DrawCanvas_FontChar (TFB_Char *, TFB_Image *backing, int x, int y,
|
|||||||
TFB_Canvas target);
|
TFB_Canvas target);
|
||||||
|
|
||||||
Color *TFB_DrawCanvas_ExtractPalette (TFB_Canvas canvas);
|
Color *TFB_DrawCanvas_ExtractPalette (TFB_Canvas canvas);
|
||||||
void TFB_DrawCanvas_SetPalette (TFB_Canvas target, Color *palette);
|
void TFB_DrawCanvas_SetPalette (TFB_Canvas target, Color palette[256]);
|
||||||
int TFB_DrawCanvas_GetTransparentIndex (TFB_Canvas canvas);
|
int TFB_DrawCanvas_GetTransparentIndex (TFB_Canvas canvas);
|
||||||
void TFB_DrawCanvas_SetTransparentIndex (TFB_Canvas canvas, int i,
|
void TFB_DrawCanvas_SetTransparentIndex (TFB_Canvas canvas, int i,
|
||||||
BOOLEAN rleaccel);
|
BOOLEAN rleaccel);
|
||||||
|
|||||||
@@ -28,6 +28,7 @@
|
|||||||
|
|
||||||
#include <stdarg.h>
|
#include <stdarg.h>
|
||||||
#include "libs/graphics/gfx_common.h"
|
#include "libs/graphics/gfx_common.h"
|
||||||
|
#include "libs/graphics/cmap.h"
|
||||||
#include "libs/sound/sound.h"
|
#include "libs/sound/sound.h"
|
||||||
#include "libs/input/input_common.h"
|
#include "libs/input/input_common.h"
|
||||||
#include "libs/inplib.h"
|
#include "libs/inplib.h"
|
||||||
|
|||||||
@@ -23,7 +23,7 @@
|
|||||||
#include "element.h"
|
#include "element.h"
|
||||||
#include "setup.h"
|
#include "setup.h"
|
||||||
#include "libs/compiler.h"
|
#include "libs/compiler.h"
|
||||||
#include "libs/graphics/gfx_common.h"
|
#include "libs/graphics/cmap.h"
|
||||||
#include "libs/mathlib.h"
|
#include "libs/mathlib.h"
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -41,6 +41,8 @@ InitOscilloscope (DWORD x, DWORD y, DWORD width, DWORD height, FRAME f)
|
|||||||
if (!scope_init)
|
if (!scope_init)
|
||||||
{
|
{
|
||||||
TFB_Canvas scope_bg_canvas, scope_surf_canvas;
|
TFB_Canvas scope_bg_canvas, scope_surf_canvas;
|
||||||
|
// TODO: this scope image copying does not properly account for
|
||||||
|
// the loaded colormaps. This should use regular primitives.
|
||||||
if (TFB_DrawCanvas_IsPaletted (scope_frame->image->NormalImg))
|
if (TFB_DrawCanvas_IsPaletted (scope_frame->image->NormalImg))
|
||||||
{
|
{
|
||||||
scope_bg_canvas = TFB_DrawCanvas_New_Paletted (width, height,
|
scope_bg_canvas = TFB_DrawCanvas_New_Paletted (width, height,
|
||||||
|
|||||||
@@ -43,6 +43,7 @@
|
|||||||
#include "libs/log.h"
|
#include "libs/log.h"
|
||||||
#include "libs/gfxlib.h"
|
#include "libs/gfxlib.h"
|
||||||
#include "libs/graphics/gfx_common.h"
|
#include "libs/graphics/gfx_common.h"
|
||||||
|
#include "libs/graphics/tfb_draw.h"
|
||||||
#include "libs/misc.h"
|
#include "libs/misc.h"
|
||||||
|
|
||||||
#include "uqmversion.h"
|
#include "uqmversion.h"
|
||||||
|
|||||||
Reference in New Issue
Block a user