Use color_t for color values

This commit is contained in:
Kp 2014-08-08 02:07:47 +00:00
parent fc979001cb
commit f47aa29cd9
13 changed files with 49 additions and 51 deletions

View file

@ -27,7 +27,7 @@ COPYRIGHT 1993-1998 PARALLAX SOFTWARE CORPORATION. ALL RIGHTS RESERVED.
#include "gr.h"
#include "grdef.h"
static void gr_linear_darken(ubyte * dest, int darkening_level, int count, ubyte * fade_table) {
static void gr_linear_darken(ubyte * dest, int darkening_level, int count, const std::array<color_t, 256*34> &fade_table) {
register int i;
for (i=0;i<count;i++)

View file

@ -171,7 +171,7 @@ void gr_set_super_transparent (grs_bitmap *pbm, int bTransparent)
}
}
void build_colormap_good( palette_array_t &palette, ubyte * colormap, int * freq )
void build_colormap_good( palette_array_t &palette, color_t * colormap, int * freq )
{
int i, r, g, b;

View file

@ -110,13 +110,13 @@ void gr_set_current_canvas( grs_canvas *canv )
grd_curcanv = canv;
}
void gr_clear_canvas(int color)
void gr_clear_canvas(color_t color)
{
gr_setcolor(color);
gr_rect(0,0,GWIDTH-1,GHEIGHT-1);
}
void gr_setcolor(int color)
void gr_setcolor(color_t color)
{
grd_curcanv->cv_color=color;
}

View file

@ -218,7 +218,7 @@ void gr_free_canvas(grs_canvas *canv);
void gr_free_sub_canvas(grs_canvas *canv);
// Clear the current canvas to the specified color
void gr_clear_canvas(int color);
void gr_clear_canvas(color_t color);
//=========================================================================
// Bitmap functions:
@ -285,7 +285,7 @@ void gr_use_palette_table(const char * filename );
// Drawing functions:
// Sets the color in the current canvas.
void gr_setcolor(int color);
void gr_setcolor(color_t color);
// Sets transparency and blending function
void gr_settransblend(int fade_level, ubyte blend_func);
@ -394,7 +394,7 @@ extern void gr_set_current_canvas( grs_canvas *canv );
#define FT_KERNED 4
extern palette_array_t gr_palette;
extern ubyte gr_fade_table[256*GR_FADE_LEVELS];
extern array<color_t, 256*GR_FADE_LEVELS> gr_fade_table;
extern ubyte gr_inverse_table[32*32*32];
extern ushort gr_palette_selector;
@ -426,7 +426,7 @@ extern void gr_bitmap_check_transparency( grs_bitmap * bmp );
// Given: r,g,b, each in range of 0-63, return the color index that
// best matches the input.
int gr_find_closest_color( int r, int g, int b );
color_t gr_find_closest_color( int r, int g, int b );
int gr_find_closest_color_15bpp( int rgb );
extern void gr_flip(void);

View file

@ -30,6 +30,7 @@ COPYRIGHT 1993-1998 PARALLAX SOFTWARE CORPORATION. ALL RIGHTS RESERVED.
#include "pstypes.h"
#ifdef __cplusplus
#include <cstdint>
#include "dxxsconf.h"
#include "compiler-array.h"
@ -37,6 +38,8 @@ struct rgb_t {
ubyte r,g,b;
};
typedef uint8_t color_t;
static inline bool operator==(const rgb_t &a, const rgb_t &b) { return a.r == b.r && a.g == b.g && a.b == b.b; }
struct palette_array_t : public array<rgb_t, 256> {};
@ -56,7 +59,7 @@ extern void gr_make_cthru_table(ubyte * table, ubyte r, ubyte g, ubyte b );
extern void gr_palette_clear();
extern void gr_make_blend_table(ubyte *blend_table, ubyte r, ubyte g, ubyte b);
#endif
extern int gr_find_closest_color_current( int r, int g, int b );
color_t gr_find_closest_color_current( int r, int g, int b );
extern void gr_palette_read(palette_array_t &palette);
extern void init_computed_colors(void);
extern ubyte gr_palette_gamma;

View file

@ -122,7 +122,7 @@ void c_tmap_scanline_lin()
if (!Transparency_on) {
ubyte* pixPtrLocalCopy = pixptr;
ubyte* fadeTableLocalCopy = gr_fade_table;
auto &fadeTableLocalCopy = gr_fade_table;
unsigned long destlong;
x = fx_xright-fx_xleft+1;
@ -834,7 +834,7 @@ void c_tmap_scanline_per()
if (!Transparency_on) {
ubyte* pixPtrLocalCopy = pixptr;
ubyte* fadeTableLocalCopy = gr_fade_table;
auto &fadeTableLocalCopy = gr_fade_table;
unsigned long destlong;
x = fx_xright-fx_xleft+1; // x = number of pixels in scanline

View file

@ -194,10 +194,7 @@ void draw_tmap_flat(grs_bitmap *bp,int nverts,g3s_point **vertbuf)
pnt2d points[MAX_TMAP_VERTS];
int i;
fix average_light;
int color;
Assert(nverts < MAX_TMAP_VERTS);
average_light = vertbuf[0]->p3_l;
for (i=1; i<nverts; i++)
average_light += vertbuf[i]->p3_l;
@ -212,7 +209,7 @@ void draw_tmap_flat(grs_bitmap *bp,int nverts,g3s_point **vertbuf)
else if (average_light > NUM_LIGHTING_LEVELS-1)
average_light = NUM_LIGHTING_LEVELS-1;
color = gr_fade_table[average_light*256 + bp->avg_color];
color_t color = gr_fade_table[average_light*256 + bp->avg_color];
gr_setcolor(color);
for (i=0;i<nverts;i++) {

View file

@ -60,15 +60,13 @@ void ui_get_button_size( const char * text, int * width, int * height )
void ui_draw_button(UI_DIALOG *dlg, UI_GADGET_BUTTON * button)
{
int color;
#if 0 //ndef OGL
if ((button->status==1) || (button->position != button->oldposition))
#endif
{
ui_button_any_drawn = 1;
gr_set_current_canvas( button->canvas );
color = button->canvas->cv_color;
color_t color = button->canvas->cv_color;
if (dlg->keyboard_focus_gadget == (UI_GADGET *)button)
gr_set_fontcolor( CRED, -1 );

View file

@ -47,14 +47,15 @@ COPYRIGHT 1993-1998 PARALLAX SOFTWARE CORPORATION. ALL RIGHTS RESERVED.
int Num_computed_colors=0;
struct color_record {
ubyte r,g,b,color_num;
ubyte r,g,b;
color_t color_num;
};
color_record Computed_colors[MAX_COMPUTED_COLORS];
palette_array_t gr_palette;
palette_array_t gr_current_pal;
ubyte gr_fade_table[256*34];
array<color_t, 256*34> gr_fade_table;
ubyte gr_palette_gamma = 0;
int gr_palette_gamma_param = 0;
@ -177,7 +178,7 @@ void gr_use_palette_table(const char * filename )
// Add a computed color (by gr_find_closest_color) to list of computed colors in Computed_colors.
// If list wasn't full already, increment Num_computed_colors.
// If was full, replace a random one.
static void add_computed_color(int r, int g, int b, int color_num)
static void add_computed_color(int r, int g, int b, color_t color_num)
{
int add_index;
@ -201,16 +202,16 @@ void init_computed_colors(void)
Computed_colors[i].r = 255; // Make impossible to match.
}
int gr_find_closest_color( int r, int g, int b )
color_t gr_find_closest_color( int r, int g, int b )
{
int i, j;
int best_value, best_index, value;
int j;
int best_value, value;
if (Num_computed_colors == 0)
init_computed_colors();
// If we've already computed this color, return it!
for (i=0; i<Num_computed_colors; i++)
for (unsigned i=0; i<Num_computed_colors; i++)
if (r == Computed_colors[i].r)
if (g == Computed_colors[i].g)
if (b == Computed_colors[i].b) {
@ -226,14 +227,14 @@ int gr_find_closest_color( int r, int g, int b )
// b &= 63;
best_value = SQUARE(r-gr_palette[0].r)+SQUARE(g-gr_palette[0].g)+SQUARE(b-gr_palette[0].b);
best_index = 0;
color_t best_index = 0;
if (best_value==0) {
add_computed_color(r, g, b, best_index);
return best_index;
}
j=0;
// only go to 255, 'cause we dont want to check the transparent color.
for (i=1; i < 254; i++ ) {
for (color_t i=1; i < 254; i++ ) {
++j;
value = SQUARE(r-gr_palette[j].r)+SQUARE(g-gr_palette[j].g)+SQUARE(b-gr_palette[j].b);
if ( value < best_value ) {
@ -255,23 +256,23 @@ int gr_find_closest_color_15bpp( int rgb )
}
int gr_find_closest_color_current( int r, int g, int b )
color_t gr_find_closest_color_current( int r, int g, int b )
{
int i, j;
int best_value, best_index, value;
int j;
int best_value, value;
// r &= 63;
// g &= 63;
// b &= 63;
best_value = SQUARE(r-gr_current_pal[0].r)+SQUARE(g-gr_current_pal[0].g)+SQUARE(b-gr_current_pal[0].b);
best_index = 0;
color_t best_index = 0;
if (best_value==0)
return best_index;
j=0;
// only go to 255, 'cause we dont want to check the transparent color.
for (i=1; i < 254; i++ ) {
for (color_t i=1; i < 254; i++ ) {
++j;
value = SQUARE(r-gr_current_pal[j].r)+SQUARE(g-gr_current_pal[j].g)+SQUARE(b-gr_current_pal[j].b);
if ( value < best_value ) {

View file

@ -227,8 +227,7 @@ static
#if defined(DXX_BUILD_DESCENT_I)
const
#endif
int edge_colors[] = { 54, 59, 64 };
array<color_t, 3> edge_colors = { 54, 59, 64 };
struct seg_edge
{

View file

@ -97,7 +97,7 @@ struct Edge_info
ubyte sides[4]; // 4 bytes
int segnum[4]; // 16 bytes // This might not need to be stored... If you can access the normals of a side.
ubyte flags; // 1 bytes // See the EF_??? defines above.
ubyte color; // 1 bytes
color_t color; // 1 bytes
ubyte num_faces; // 1 bytes // 31 bytes...
};
@ -132,18 +132,19 @@ struct automap
vms_matrix viewMatrix;
fix viewDist;
int wall_normal_color;
int wall_door_color;
int wall_door_blue;
int wall_door_gold;
int wall_door_red;
int wall_revealed_color;
int hostage_color;
int font_color_20;
int green_31;
int white_63;
int blue_48;
int red_48;
color_t wall_normal_color;
color_t wall_door_color;
color_t wall_door_blue;
color_t wall_door_gold;
color_t wall_door_red;
#if defined(DXX_BUILD_DESCENT_II)
color_t wall_revealed_color;
#endif
color_t hostage_color;
color_t green_31;
color_t white_63;
color_t blue_48;
color_t red_48;
control_info controls;
segment_depth_array_t depth_array;
};
@ -175,7 +176,6 @@ static void init_automap_colors(automap *am)
am->wall_revealed_color = K_WALL_REVEALED_COLOR;
#endif
am->hostage_color = K_HOSTAGE_COLOR;
am->font_color_20 = K_FONT_COLOR_20;
am->green_31 = K_GREEN_31;
am->white_63 = gr_find_closest_color_current(63,63,63);

View file

@ -932,7 +932,7 @@ static ubyte code_window_point(fix x,fix y,rect *w)
}
#ifndef NDEBUG
static void draw_window_box(int color,short left,short top,short right,short bot)
static void draw_window_box(color_t color,short left,short top,short right,short bot)
{
short l,t,r,b;

View file

@ -80,9 +80,9 @@ static int DefineBriefingBox (const char **buf);
#endif
#define DEFAULT_BRIEFING_BKG "brief03.pcx"
static int Briefing_text_colors[MAX_BRIEFING_COLORS];
static array<color_t, MAX_BRIEFING_COLORS> Briefing_text_colors;
static int Current_color = 0;
static int Erase_color;
static color_t Erase_color;
// added by Jan Bobrowski for variable-size menu screen
static int rescale_x(int x)