Skip to content
Permalink
Browse files

Use SDL_Color instead of PALETTEENTRY.

Also, various little cleanups.
  • Loading branch information...
pphaneuf committed Feb 26, 2014
1 parent e7b357e commit 26e9363a2b9509e7f803069e7157fde8cfd80247
@@ -132,7 +132,7 @@ void Video_Dumb::setpal(const Palette& p) {
newpal=true;
}

void Video_Dumb::dosetpal(const PALETTEENTRY pal[256], int size) {
void Video_Dumb::dosetpal(const SDL_Color pal[256], int size) {
}

void Video_Dumb::end_frame() {
@@ -21,57 +21,50 @@
#ifndef _HEADER_PALETTE
#define _HEADER_PALETTE

#ifdef HAVE_CONFIG_H
#include "autoconf.h"
#endif

#include <stdint.h>
#include <string.h>
#include <stdio.h>

#include "config.h"
#include "SDL.h"

#ifdef WIN32
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
#endif
#include <stdio.h>
#include "types.h"
#include "error.h"
#include "image.h"

#ifndef WIN32
typedef struct {
uint8_t peRed, peGreen, peBlue, peFlags;
} PALETTEENTRY;
#endif
#include "types.h"

class Palette {
private:
PALETTEENTRY pal[256];
SDL_Color pal[256];
public:
int size;
Palette() {
Palette()
: size(256) {
memset(pal, 0, sizeof(pal));
size=256;
}
Palette(const Image& raw) {
Palette(const Image& raw)
: size(256) {
memset(pal, 0, sizeof(pal));
load(raw);
}
void set_size(int s) {
size=s;
}
void load(const Image& raw);
void set() const;
uint8_t r(uint8_t c) const {
return pal[c].peRed;
return pal[c].r;
}
uint8_t g(uint8_t c) const {
return pal[c].peGreen;
return pal[c].g;
}
uint8_t b(uint8_t c) const {
return pal[c].peBlue;
return pal[c].b;
}
void setcolor(uint8_t c, uint8_t r, uint8_t g, uint8_t b) {
pal[c].peRed=r;
pal[c].peGreen=g;
pal[c].peBlue=b;
pal[c].r = r;
pal[c].g = g;
pal[c].b = b;
pal[c].a = SDL_ALPHA_OPAQUE;
}
};

@@ -23,6 +23,8 @@

#include <stdint.h>

#include "SDL.h"

#include "clipable.h"
#include "palette.h"

@@ -94,7 +96,7 @@ class Video {
}
virtual void end_frame() = 0;
virtual void setpal(const Palette& p) = 0;
virtual void dosetpal(const PALETTEENTRY pal[256], int size) = 0;
virtual void dosetpal(const SDL_Color pal[256], int size) = 0;
virtual void snap_shot(int x, int y, int w, int h) = 0;
virtual Video_bitmap* new_bitmap(int px, int py, int w, int h) = 0;
};
@@ -47,7 +47,7 @@ class Video_Dumb: public Video {
virtual ~Video_Dumb();
virtual void end_frame();
virtual void setpal(const Palette& p);
virtual void dosetpal(const PALETTEENTRY pal[256], int size);
virtual void dosetpal(const SDL_Color pal[256], int size);
virtual void snap_shot(int x, int y, int w, int h);
virtual Video_bitmap* new_bitmap(int px, int py, int w, int h);
};
@@ -37,12 +37,13 @@ void Palette::set() const {
}

void Palette::load(const Image& raw) {
size=raw.palettesize();
int j=0;
for(int i(0); i<size; i++) {
pal[i].peRed = raw.pal()[j++];
pal[i].peGreen = raw.pal()[j++];
pal[i].peBlue = raw.pal()[j++];
size = raw.palettesize();
int j(0);
for (int i = 0; i < size; ++i) {
pal[i].r = raw.pal()[j++];
pal[i].g = raw.pal()[j++];
pal[i].b = raw.pal()[j++];
pal[i].a = SDL_ALPHA_OPAQUE;
}
}

@@ -134,7 +135,6 @@ void Fade::set() {
if(currentframe==destframe-1) {
video->setpal(dest);
} else {
video->pal.set_size(256);
for(int i(0); i<256; i++)
video->pal.setcolor(i, current[i*3]>>7, current[i*3+1]>>7, current[i*3+2]>>7);
video->newpal = true;
@@ -91,17 +91,8 @@ class Video_SDL : public Video {
virtual void setpal(const Palette& p) {
p.set();
}
virtual void dosetpal(const PALETTEENTRY pal[256], int size) {
SDL_Color entries[256];

for (int i = 0; i < size; ++i) {
entries[i].r = pal[i].peRed;
entries[i].g = pal[i].peGreen;
entries[i].b = pal[i].peBlue;
entries[i].a = SDL_ALPHA_OPAQUE;
}

SDL_SetPaletteColors(surface_->format->palette, entries, 0, size);
virtual void dosetpal(const SDL_Color pal[256], int size) {
SDL_SetPaletteColors(surface_->format->palette, pal, 0, size);
}
virtual void snap_shot(int x, int y, int w, int h) {
SDL_assert_release(false);
@@ -948,7 +948,6 @@ Menu_single::Menu_single() {
pal.load(img);
}

pal.set_size(256); //Useless but whatever
set_fteam_color(pal);

inter->set_font(new Font(*fonts.normal, pal, 255,255,255));
@@ -988,7 +987,6 @@ Menu_multi::Menu_multi() {
pal.load(img);
}

pal.set_size(256); //Useless but whatever
set_fteam_color(pal);

inter->set_font(new Font(*fonts.normal, pal, 255,255,255));
@@ -1235,7 +1233,6 @@ Menu_help::Menu_help() {
bit = new Bitmap(img);
pal.load(img);
}
pal.set_size(256);
set_fteam_color(pal);

inter->set_font(new Font(*fonts.normal, pal, 255,255,255));
@@ -1302,7 +1299,6 @@ Menu_option::Menu_option() {
bit = new Bitmap(img);
pal.load(img);
}
pal.set_size(256);
set_fteam_color(pal);

Palette ptemp;
@@ -1637,7 +1633,6 @@ c_start(105), c_gap(4) {
Bitmap btemp(raw);
btemp.draw(*bit, 0, 0);
}
pal.set_size(256);
Palette temp;
{
Res_doze res(res_fond0_png);
@@ -82,7 +82,6 @@ Menu_demo_central::Menu_demo_central() {
bit = new Bitmap(img);
pal.load(img);
}
pal.set_size(256);
set_fteam_color(pal);

fcourrier[0] = new Font(*fonts.courrier, pal, 255,125,0);
@@ -56,7 +56,6 @@ Multi_player::Multi_player(int *got_high) {
Png img(res);
bit = new Bitmap(img);
}
pal.set_size(256);
for(i=0; i<9; i++)
color[i] = new Color(i, pal);
font2 = fteam[4];

0 comments on commit 26e9363

Please sign in to comment.
You can’t perform that action at this time.