mirror of
https://github.com/holub/mame
synced 2025-10-06 17:08:28 +03:00
digfx.c, drawgfx.c: don't do unneeded processing or allocate unneeded memory for RAW gfx layouts; add -valid check that extxoffs/extyoffs info are present when the layout size demands them [Alex Jackson]
This commit is contained in:
parent
66a929cfba
commit
f6229dd73e
@ -189,32 +189,6 @@ void device_gfx_interface::decode_gfx(const gfx_decode_entry *gfxdecodeinfo)
|
||||
// copy the layout into our temporary variable
|
||||
memcpy(&glcopy, gfx.gfxlayout, sizeof(gfx_layout));
|
||||
|
||||
// copy the X and Y offsets into our temporary arrays
|
||||
extxoffs.resize(glcopy.width * xscale);
|
||||
extyoffs.resize(glcopy.height * yscale);
|
||||
assert(glcopy.extxoffs != NULL || glcopy.width <= MAX_GFX_SIZE);
|
||||
memcpy(&extxoffs[0], (glcopy.extxoffs != NULL) ? glcopy.extxoffs : glcopy.xoffset, glcopy.width * sizeof(UINT32));
|
||||
assert(glcopy.extyoffs != NULL || glcopy.height <= MAX_GFX_SIZE);
|
||||
memcpy(&extyoffs[0], (glcopy.extyoffs != NULL) ? glcopy.extyoffs : glcopy.yoffset, glcopy.height * sizeof(UINT32));
|
||||
|
||||
// always use the extended offsets here
|
||||
glcopy.extxoffs = extxoffs;
|
||||
glcopy.extyoffs = extyoffs;
|
||||
|
||||
// expand X and Y by the scale factors
|
||||
if (xscale > 1)
|
||||
{
|
||||
glcopy.width *= xscale;
|
||||
for (int j = glcopy.width - 1; j >= 0; j--)
|
||||
extxoffs[j] = extxoffs[j / xscale];
|
||||
}
|
||||
if (yscale > 1)
|
||||
{
|
||||
glcopy.height *= yscale;
|
||||
for (int j = glcopy.height - 1; j >= 0; j--)
|
||||
extyoffs[j] = extyoffs[j / yscale];
|
||||
}
|
||||
|
||||
// if the character count is a region fraction, compute the effective total
|
||||
if (IS_FRAC(glcopy.total))
|
||||
{
|
||||
@ -225,6 +199,30 @@ void device_gfx_interface::decode_gfx(const gfx_decode_entry *gfxdecodeinfo)
|
||||
// for non-raw graphics, decode the X and Y offsets
|
||||
if (glcopy.planeoffset[0] != GFX_RAW)
|
||||
{
|
||||
// copy the X and Y offsets into our temporary arrays
|
||||
extxoffs.resize(glcopy.width * xscale);
|
||||
extyoffs.resize(glcopy.height * yscale);
|
||||
memcpy(&extxoffs[0], (glcopy.extxoffs != NULL) ? glcopy.extxoffs : glcopy.xoffset, glcopy.width * sizeof(UINT32));
|
||||
memcpy(&extyoffs[0], (glcopy.extyoffs != NULL) ? glcopy.extyoffs : glcopy.yoffset, glcopy.height * sizeof(UINT32));
|
||||
|
||||
// always use the extended offsets here
|
||||
glcopy.extxoffs = extxoffs;
|
||||
glcopy.extyoffs = extyoffs;
|
||||
|
||||
// expand X and Y by the scale factors
|
||||
if (xscale > 1)
|
||||
{
|
||||
glcopy.width *= xscale;
|
||||
for (int j = glcopy.width - 1; j >= 0; j--)
|
||||
extxoffs[j] = extxoffs[j / xscale];
|
||||
}
|
||||
if (yscale > 1)
|
||||
{
|
||||
glcopy.height *= yscale;
|
||||
for (int j = glcopy.height - 1; j >= 0; j--)
|
||||
extyoffs[j] = extyoffs[j / yscale];
|
||||
}
|
||||
|
||||
// loop over all the planes, converting fractions
|
||||
for (int j = 0; j < glcopy.planes; j++)
|
||||
{
|
||||
@ -360,16 +358,21 @@ void device_gfx_interface::interface_validity_check(validity_checker &valid) con
|
||||
if (layout.planeoffset[0] == GFX_RAW)
|
||||
{
|
||||
if (layout.total != RGN_FRAC(1,1))
|
||||
osd_printf_error("gfx[%d] with unsupported layout total\n", gfxnum);
|
||||
osd_printf_error("gfx[%d] RAW layouts can only be RGN_FRAC(1,1)\n", gfxnum);
|
||||
if (xscale != 1 || yscale != 1)
|
||||
osd_printf_error("gfx[%d] with unsupported xscale/yscale\n", gfxnum);
|
||||
osd_printf_error("gfx[%d] RAW layouts do not support xscale/yscale\n", gfxnum);
|
||||
}
|
||||
|
||||
// verify traditional decode doesn't have too many planes
|
||||
// verify traditional decode doesn't have too many planes,
|
||||
// and has extended offset arrays if its width and/or height demand them
|
||||
else
|
||||
{
|
||||
if (layout.planes > MAX_GFX_PLANES)
|
||||
osd_printf_error("gfx[%d] with invalid planes\n", gfxnum);
|
||||
osd_printf_error("gfx[%d] planes > %d\n", gfxnum, MAX_GFX_PLANES);
|
||||
if (layout.width > MAX_GFX_SIZE && layout.extxoffs == NULL)
|
||||
osd_printf_error("gfx[%d] width > %d but missing extended xoffset info\n", gfxnum, MAX_GFX_SIZE);
|
||||
if (layout.height > MAX_GFX_SIZE && layout.extyoffs == NULL)
|
||||
osd_printf_error("gfx[%d] width > %d but missing extended yoffset info\n", gfxnum, MAX_GFX_SIZE);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -40,7 +40,6 @@ const gfx_layout name = { width, height, RGN_FRAC(1,1), 8, { GFX_RAW }, { 0 }, {
|
||||
// When planeoffset[0] is set to GFX_RAW, the gfx data is left as-is, with no conversion.
|
||||
// No buffer is allocated for the decoded data, and gfxdata is set to point to the source
|
||||
// data.
|
||||
// xoffset[0] is an optional displacement (*8) from the beginning of the source data, while
|
||||
// yoffset[0] is the line modulo (*8) and charincrement the char modulo (*8). They are *8
|
||||
// for consistency with the usual behaviour, but the bottom 3 bits are not used.
|
||||
//
|
||||
|
@ -183,20 +183,22 @@ void gfx_element::set_layout(const gfx_layout &gl, const UINT8 *srcdata)
|
||||
m_layout_is_raw = (gl.planeoffset[0] == GFX_RAW);
|
||||
m_layout_planes = gl.planes;
|
||||
m_layout_charincrement = gl.charincrement;
|
||||
m_layout_planeoffset.resize(m_layout_planes);
|
||||
m_layout_xoffset.resize(m_width);
|
||||
m_layout_yoffset.resize(m_height);
|
||||
|
||||
// raw graphics case
|
||||
if (m_layout_is_raw)
|
||||
{
|
||||
// RAW layouts don't need these arrays
|
||||
m_layout_planeoffset.reset();
|
||||
m_layout_xoffset.reset();
|
||||
m_layout_yoffset.reset();
|
||||
m_gfxdata_allocated.reset();
|
||||
|
||||
// modulos are determined for us by the layout
|
||||
m_line_modulo = gl.yoffs(0) / 8;
|
||||
m_char_modulo = gl.charincrement / 8;
|
||||
|
||||
// RAW graphics must have a pointer up front
|
||||
assert(srcdata != NULL);
|
||||
m_gfxdata_allocated.reset();
|
||||
m_gfxdata = const_cast<UINT8 *>(m_srcdata);
|
||||
}
|
||||
|
||||
@ -204,6 +206,10 @@ void gfx_element::set_layout(const gfx_layout &gl, const UINT8 *srcdata)
|
||||
else
|
||||
{
|
||||
// copy offsets
|
||||
m_layout_planeoffset.resize(m_layout_planes);
|
||||
m_layout_xoffset.resize(m_width);
|
||||
m_layout_yoffset.resize(m_height);
|
||||
|
||||
for (int p = 0; p < m_layout_planes; p++)
|
||||
m_layout_planeoffset[p] = gl.planeoffset[p];
|
||||
for (int y = 0; y < m_height; y++)
|
||||
|
Loading…
Reference in New Issue
Block a user