Skip to content

Commit

Permalink
Converted palette_t and palette_client to classes. General palette.c
Browse files Browse the repository at this point in the history
cleanup.
  • Loading branch information
aaronsgiles committed Feb 18, 2014
1 parent 847cecb commit 3e2995c
Show file tree
Hide file tree
Showing 74 changed files with 665 additions and 928 deletions.
2 changes: 1 addition & 1 deletion src/emu/bus/a2bus/a2videoterm.c
Expand Up @@ -349,7 +349,7 @@ void a2bus_videx80_device::write_c800(address_space &space, UINT16 offset, UINT8
static MC6845_UPDATE_ROW( videoterm_update_row )
{
a2bus_videx80_device *vterm = downcast<a2bus_videx80_device *>(device->owner());
const rgb_t *palette = palette_entry_list_raw(bitmap.palette());
const rgb_t *palette = bitmap.palette()->entry_list_raw();
UINT32 *p = &bitmap.pix32(y);
UINT16 chr_base = ra; //( ra & 0x08 ) ? 0x800 | ( ra & 0x07 ) : ra;
int i;
Expand Down
2 changes: 1 addition & 1 deletion src/emu/bus/ecbbus/grip.c
Expand Up @@ -253,7 +253,7 @@ static MC6845_UPDATE_ROW( grip_update_row )
static MC6845_UPDATE_ROW( grip5_update_row )
{
grip5_state *state = device->machine().driver_data<grip5_state>();
const rgb_t *palette = palette_entry_list_raw(bitmap.palette());
const rgb_t *palette = bitmap.palette()->entry_list_raw();
int column, bit;
for (column = 0; column < x_count; column++)
Expand Down
37 changes: 18 additions & 19 deletions src/emu/emupal.c
Expand Up @@ -144,7 +144,7 @@ void palette_init(running_machine &machine)
allocate_shadow_tables(machine, palette);

/* set up save/restore of the palette */
numcolors = palette_get_num_colors(machine.palette);
numcolors = machine.palette->num_colors();
palette->save_pen = auto_alloc_array(machine, pen_t, numcolors);
palette->save_bright = auto_alloc_array(machine, float, numcolors);
machine.save().save_pointer(NAME(palette->save_pen), numcolors);
Expand All @@ -170,7 +170,7 @@ void palette_set_shadow_factor(running_machine &machine, double factor)
palette_private *palette = machine.palette_data;

assert(palette->shadow_group != 0);
palette_group_set_contrast(machine.palette, palette->shadow_group, factor);
machine.palette->group_set_contrast(palette->shadow_group, factor);
}


Expand All @@ -184,7 +184,7 @@ void palette_set_highlight_factor(running_machine &machine, double factor)
palette_private *palette = machine.palette_data;

assert(palette->hilight_group != 0);
palette_group_set_contrast(machine.palette, palette->hilight_group, factor);
machine.palette->group_set_contrast(palette->hilight_group, factor);
}


Expand Down Expand Up @@ -530,15 +530,15 @@ pen_t get_white_pen(running_machine &machine)

static void palette_presave(running_machine &machine)
{
int numcolors = palette_get_num_colors(machine.palette);
int numcolors = machine.palette->num_colors();
palette_private *palette = machine.palette_data;
int index;

/* fill the save arrays with updated pen and brightness information */
for (index = 0; index < numcolors; index++)
{
palette->save_pen[index] = palette_entry_get_color(machine.palette, index);
palette->save_bright[index] = palette_entry_get_contrast(machine.palette, index);
palette->save_pen[index] = machine.palette->entry_color(index);
palette->save_bright[index] = machine.palette->entry_contrast(index);
}
}

Expand All @@ -550,15 +550,15 @@ static void palette_presave(running_machine &machine)

static void palette_postload(running_machine &machine)
{
int numcolors = palette_get_num_colors(machine.palette);
int numcolors = machine.palette->num_colors();
palette_private *palette = machine.palette_data;
int index;

/* reset the pen and brightness for each entry */
for (index = 0; index < numcolors; index++)
{
palette_entry_set_color(machine.palette, index, palette->save_pen[index]);
palette_entry_set_contrast(machine.palette, index, palette->save_bright[index]);
machine.palette->entry_set_color(index, palette->save_pen[index]);
machine.palette->entry_set_contrast(index, palette->save_bright[index]);
}
}

Expand All @@ -571,7 +571,7 @@ static void palette_exit(running_machine &machine)
{
/* dereference the palette */
if (machine.palette != NULL)
palette_deref(machine.palette);
machine.palette->deref();
}


Expand All @@ -593,26 +593,25 @@ static void allocate_palette(running_machine &machine, palette_private *palette)
assert_always(machine.total_colors() * numgroups <= 65536, "Error: palette has more than 65536 colors.");

/* allocate a palette object containing all the colors and groups */
machine.palette = palette_alloc(machine.total_colors(), numgroups);
assert_always(machine.palette != NULL, "Failed to allocate system palette");
machine.palette = new palette_t(machine.total_colors(), numgroups);

/* configure the groups */
if (palette->shadow_group != 0)
palette_group_set_contrast(machine.palette, palette->shadow_group, (float)PALETTE_DEFAULT_SHADOW_FACTOR);
machine.palette->group_set_contrast(palette->shadow_group, (float)PALETTE_DEFAULT_SHADOW_FACTOR);
if (palette->hilight_group != 0)
palette_group_set_contrast(machine.palette, palette->hilight_group, (float)PALETTE_DEFAULT_HIGHLIGHT_FACTOR);
machine.palette->group_set_contrast(palette->hilight_group, (float)PALETTE_DEFAULT_HIGHLIGHT_FACTOR);

/* set the initial colors to a standard rainbow */
for (index = 0; index < machine.total_colors(); index++)
palette_entry_set_color(machine.palette, index, MAKE_RGB(pal1bit(index >> 0), pal1bit(index >> 1), pal1bit(index >> 2)));
machine.palette->entry_set_color(index, MAKE_RGB(pal1bit(index >> 0), pal1bit(index >> 1), pal1bit(index >> 2)));

/* switch off the color mode */
switch (palette->format)
{
/* 16-bit paletteized case */
case BITMAP_FORMAT_IND16:
palette->black_pen = palette_get_black_entry(machine.palette);
palette->white_pen = palette_get_white_entry(machine.palette);
palette->black_pen = machine.palette->black_entry();
palette->white_pen = machine.palette->white_entry();
if (palette->black_pen >= 65536)
palette->black_pen = 0;
if (palette->white_pen >= 65536)
Expand Down Expand Up @@ -640,7 +639,7 @@ static void allocate_palette(running_machine &machine, palette_private *palette)

static void allocate_color_tables(running_machine &machine, palette_private *palette)
{
int total_colors = palette_get_num_colors(machine.palette) * palette_get_num_groups(machine.palette);
int total_colors = machine.palette->num_colors() * machine.palette->num_groups();
pen_t *pentable;
int i;

Expand All @@ -655,7 +654,7 @@ static void allocate_color_tables(running_machine &machine, palette_private *pal
break;

case BITMAP_FORMAT_RGB32:
machine.pens = palette_entry_list_adjusted(machine.palette);
machine.pens = machine.palette->entry_list_adjusted();
break;

default:
Expand Down
10 changes: 5 additions & 5 deletions src/emu/emupal.h
Expand Up @@ -198,7 +198,7 @@ pen_t get_white_pen(running_machine &machine);

INLINE void palette_set_color(running_machine &machine, pen_t pen, rgb_t rgb)
{
palette_entry_set_color(machine.palette, pen, rgb);
machine.palette->entry_set_color(pen, rgb);
}


Expand All @@ -209,7 +209,7 @@ INLINE void palette_set_color(running_machine &machine, pen_t pen, rgb_t rgb)

INLINE void palette_set_color_rgb(running_machine &machine, pen_t pen, UINT8 r, UINT8 g, UINT8 b)
{
palette_entry_set_color(machine.palette, pen, MAKE_RGB(r, g, b));
machine.palette->entry_set_color(pen, MAKE_RGB(r, g, b));
}


Expand All @@ -220,7 +220,7 @@ INLINE void palette_set_color_rgb(running_machine &machine, pen_t pen, UINT8 r,

INLINE rgb_t palette_get_color(running_machine &machine, pen_t pen)
{
return palette_entry_get_color(machine.palette, pen);
return machine.palette->entry_color(pen);
}


Expand All @@ -231,7 +231,7 @@ INLINE rgb_t palette_get_color(running_machine &machine, pen_t pen)

INLINE void palette_set_pen_contrast(running_machine &machine, pen_t pen, double bright)
{
palette_entry_set_contrast(machine.palette, pen, bright);
machine.palette->entry_set_contrast(pen, bright);
}


Expand All @@ -243,7 +243,7 @@ INLINE void palette_set_pen_contrast(running_machine &machine, pen_t pen, double
INLINE void palette_set_colors(running_machine &machine, pen_t color_base, const rgb_t *colors, int color_count)
{
while (color_count--)
palette_entry_set_color(machine.palette, color_base++, *colors++);
machine.palette->entry_set_color(color_base++, *colors++);
}


Expand Down
6 changes: 3 additions & 3 deletions src/emu/machine/laserdsc.c
Expand Up @@ -325,7 +325,7 @@ void laserdisc_device::device_stop()
if (m_videotex != NULL)
machine().render().texture_free(m_videotex);
if (m_videopalette != NULL)
palette_deref(m_videopalette);
m_videopalette->deref();
if (m_overtex != NULL)
machine().render().texture_free(m_overtex);
}
Expand Down Expand Up @@ -769,11 +769,11 @@ void laserdisc_device::init_video()
m_screen->register_vblank_callback(vblank_state_delegate(FUNC(laserdisc_device::vblank_state_changed), this));

// allocate palette for applying brightness/contrast/gamma
m_videopalette = palette_alloc(256, 1);
m_videopalette = new palette_t(256);
if (m_videopalette == NULL)
throw emu_fatalerror("Out of memory allocating video palette");
for (int index = 0; index < 256; index++)
palette_entry_set_color(m_videopalette, index, MAKE_RGB(index, index, index));
m_videopalette->entry_set_color(index, MAKE_RGB(index, index, index));

// allocate video frames
for (int index = 0; index < ARRAY_LENGTH(m_frame); index++)
Expand Down
25 changes: 12 additions & 13 deletions src/emu/render.c
Expand Up @@ -467,7 +467,7 @@ bool render_texture::get_scaled(UINT32 dwidth, UINT32 dheight, render_texinfo &t
texinfo.osddata = m_osddata;

// are we scaler-free? if so, just return the source bitmap
const rgb_t *palbase = (m_format == TEXFORMAT_PALETTE16 || m_format == TEXFORMAT_PALETTEA16) ? palette_entry_list_adjusted(m_bitmap->palette()) : NULL;
const rgb_t *palbase = (m_format == TEXFORMAT_PALETTE16 || m_format == TEXFORMAT_PALETTEA16) ? m_bitmap->palette()->entry_list_adjusted() : NULL;
if (m_scaler == NULL || (m_bitmap != NULL && swidth == dwidth && sheight == dheight))
{
// add a reference and set up the source bitmap
Expand Down Expand Up @@ -554,7 +554,7 @@ const rgb_t *render_texture::get_adjusted_palette(render_container &container)

// if no adjustment necessary, return the raw palette
assert(m_bitmap->palette() != NULL);
adjusted = palette_entry_list_adjusted(m_bitmap->palette());
adjusted = m_bitmap->palette()->entry_list_adjusted();
if (!container.has_brightness_contrast_gamma_changes())
return adjusted;

Expand All @@ -564,7 +564,7 @@ const rgb_t *render_texture::get_adjusted_palette(render_container &container)
return adjusted;

// otherwise, ensure we have memory allocated and compute the adjusted result ourself
numentries = palette_get_num_colors(m_bitmap->palette()) * palette_get_num_groups(m_bitmap->palette());
numentries = m_bitmap->palette()->num_colors() * m_bitmap->palette()->num_groups();
if (m_bcglookup == NULL || m_bcglookup_entries < numentries)
{
rgb_t *newlookup = auto_alloc_array(m_manager->machine(), rgb_t, numentries);
Expand Down Expand Up @@ -637,7 +637,7 @@ render_container::render_container(render_manager &manager, screen_device *scree

// allocate a client to the main palette
if (manager.machine().palette != NULL)
m_palclient = palette_client_alloc(manager.machine().palette);
m_palclient = global_alloc(palette_client(*manager.machine().palette));
recompute_lookups();
}

Expand All @@ -655,8 +655,7 @@ render_container::~render_container()
m_manager.texture_free(m_overlaytexture);

// release our palette client
if (m_palclient != NULL)
palette_client_free(m_palclient);
global_free(m_palclient);
}


Expand Down Expand Up @@ -772,7 +771,7 @@ const rgb_t *render_container::bcg_lookup_table(int texformat, palette_t *palett
{
case TEXFORMAT_PALETTE16:
case TEXFORMAT_PALETTEA16:
return (palette != NULL && palette == palette_client_get_palette(m_palclient)) ? m_bcglookup : NULL;
return (palette != NULL && palette == &m_palclient->palette()) ? m_bcglookup : NULL;

case TEXFORMAT_RGB32:
case TEXFORMAT_ARGB32:
Expand Down Expand Up @@ -858,9 +857,9 @@ void render_container::recompute_lookups()
// recompute the palette entries
if (m_palclient != NULL)
{
palette_t *palette = palette_client_get_palette(m_palclient);
const pen_t *adjusted_palette = palette_entry_list_adjusted(palette);
int colors = palette_get_num_colors(palette) * palette_get_num_groups(palette);
palette_t &palette = m_palclient->palette();
const pen_t *adjusted_palette = palette.entry_list_adjusted();
int colors = palette.num_colors() * palette.num_groups();

for (int i = 0; i < colors; i++)
{
Expand All @@ -887,13 +886,13 @@ void render_container::update_palette()

// get the dirty list
UINT32 mindirty, maxdirty;
const UINT32 *dirty = palette_client_get_dirty_list(m_palclient, &mindirty, &maxdirty);
const UINT32 *dirty = m_palclient->dirty_list(mindirty, maxdirty);

// iterate over dirty items and update them
if (dirty != NULL)
{
palette_t *palette = palette_client_get_palette(m_palclient);
const pen_t *adjusted_palette = palette_entry_list_adjusted(palette);
palette_t &palette = m_palclient->palette();
const pen_t *adjusted_palette = palette.entry_list_adjusted();

// loop over chunks of 32 entries, since we can quickly examine 32 at a time
for (UINT32 entry32 = mindirty / 32; entry32 <= maxdirty / 32; entry32++)
Expand Down
2 changes: 1 addition & 1 deletion src/emu/screen.c
Expand Up @@ -880,7 +880,7 @@ void screen_device::update_burnin()
{
UINT64 *dst = &m_burnin.pix64(y);
const UINT16 *src = &srcbitmap.pix16(srcy >> 16);
const rgb_t *palette = palette_entry_list_adjusted(machine().palette);
const rgb_t *palette = machine().palette->entry_list_adjusted();
for (x = 0, srcx = xstart; x < dstwidth; x++, srcx += xstep)
{
rgb_t pixel = palette[src[srcx >> 16]];
Expand Down
4 changes: 2 additions & 2 deletions src/emu/tilemap.c
Expand Up @@ -1183,7 +1183,7 @@ void tilemap_t::draw_instance(_BitmapClass &dest, const blit_parameters &blit, i
x_end = MIN(x_end, x2);

// if we're rendering something, compute the pointers
const rgb_t *clut = (dest.palette() != NULL) ? palette_entry_list_raw(dest.palette()) : machine().pens;
const rgb_t *clut = (dest.palette() != NULL) ? dest.palette()->entry_list_raw() : machine().pens;
if (prev_trans != WHOLLY_TRANSPARENT)
{
const UINT16 *source0 = source_baseaddr + x_start;
Expand Down Expand Up @@ -1277,7 +1277,7 @@ void tilemap_t::draw_roz_core(_BitmapClass &destbitmap, const blit_parameters &b
UINT32 startx, UINT32 starty, int incxx, int incxy, int incyx, int incyy, bool wraparound)
{
// pre-cache all the inner loop values
const rgb_t *clut = ((destbitmap.palette() != NULL) ? palette_entry_list_raw(destbitmap.palette()) : machine().pens) + (blit.tilemap_priority_code >> 16);
const rgb_t *clut = ((destbitmap.palette() != NULL) ? destbitmap.palette()->entry_list_raw() : machine().pens) + (blit.tilemap_priority_code >> 16);
bitmap_ind8 &priority_bitmap = *blit.priority;
const int xmask = m_pixmap.width() - 1;
const int ymask = m_pixmap.height() - 1;
Expand Down
4 changes: 2 additions & 2 deletions src/emu/ui/viewgfx.c
Expand Up @@ -257,7 +257,7 @@ static void palette_handler(running_machine &machine, render_container *containe
{
int total = state->palette.which ? colortable_palette_get_size(machine.colortable) : machine.total_colors();
const char *title = state->palette.which ? "COLORTABLE" : "PALETTE";
const rgb_t *raw_color = palette_entry_list_raw(machine.palette);
const rgb_t *raw_color = machine.palette->entry_list_raw();
render_font *ui_font = machine.ui().get_font();
float cellwidth, cellheight;
float chwidth, chheight;
Expand Down Expand Up @@ -787,7 +787,7 @@ static void gfxset_draw_item(running_machine &machine, gfx_element *gfx, int ind
};
int width = (rotate & ORIENTATION_SWAP_XY) ? gfx->height() : gfx->width();
int height = (rotate & ORIENTATION_SWAP_XY) ? gfx->width() : gfx->height();
const rgb_t *palette = (machine.total_colors() != 0) ? palette_entry_list_raw(machine.palette) : NULL;
const rgb_t *palette = (machine.total_colors() != 0) ? machine.palette->entry_list_raw() : NULL;
UINT32 palette_mask = ~0;
int x, y;

Expand Down
6 changes: 3 additions & 3 deletions src/emu/video.c
Expand Up @@ -310,7 +310,7 @@ void video_manager::save_snapshot(screen_device *screen, emu_file &file)
png_add_text(&pnginfo, "System", text2);

// now do the actual work
const rgb_t *palette = (machine().palette != NULL) ? palette_entry_list_adjusted(machine().palette) : NULL;
const rgb_t *palette = (machine().palette != NULL) ? machine().palette->entry_list_adjusted() : NULL;
png_error error = png_write_bitmap(file, &pnginfo, m_snap_bitmap, machine().total_colors(), palette);
if (error != PNGERR_NONE)
mame_printf_error("Error generating PNG for snapshot: png_error = %d\n", error);
Expand Down Expand Up @@ -1230,7 +1230,7 @@ void video_manager::record_frame()
}

// write the next frame
const rgb_t *palette = (machine().palette != NULL) ? palette_entry_list_adjusted(machine().palette) : NULL;
const rgb_t *palette = (machine().palette != NULL) ? machine().palette->entry_list_adjusted() : NULL;
png_error error = mng_capture_frame(*m_mngfile, &pnginfo, m_snap_bitmap, machine().total_colors(), palette);
png_free(&pnginfo);
if (error != PNGERR_NONE)
Expand Down Expand Up @@ -1258,7 +1258,7 @@ bool video_assert_out_of_range_pixels(running_machine &machine, bitmap_ind16 &bi
{
#ifdef MAME_DEBUG
// iterate over rows
int maxindex = palette_get_max_index(machine.palette);
int maxindex = machine.palette->max_index();
for (int y = 0; y < bitmap.height(); y++)
{
UINT16 *rowbase = &bitmap.pix16(y);
Expand Down

0 comments on commit 3e2995c

Please sign in to comment.