/** * @fn void bitmap_t::resize(int width, int height, int xslop, int yslop) * * @brief ------------------------------------------------- * resize -- resize a bitmap, reusing existing memory if the new size is smaller than * the current size * -------------------------------------------------. * * @param width The width. * @param height The height. * @param xslop The xslop. * @param yslop The yslop. */ public void resize(int width, int height, int xslop = 0, int yslop = 0) { //assert(m_format != BITMAP_FORMAT_INVALID); //assert(m_bpp == 8 || m_bpp == 16 || m_bpp == 32 || m_bpp == 64); // handle empty requests cleanly if (width <= 0 || height <= 0) { width = height = 0; } // determine how much memory we need for the new bitmap int new_rowpixels = compute_rowpixels(width, xslop); uint32_t new_allocbytes = (uint32_t)(new_rowpixels * (height + 2 * yslop) * m_bpp / 8); if (new_allocbytes > m_allocbytes) { // if we need more memory, just realloc palette_t palette = m_palette; allocate(width, height, xslop, yslop); set_palette(palette); } else { // otherwise, reconfigure m_rowpixels = new_rowpixels; m_width = width; m_height = height; m_cliprect.set(0, width - 1, 0, height - 1); // re-compute the base compute_base(xslop, yslop); } }
// construction/destruction //------------------------------------------------- // device_palette_interface - constructor //------------------------------------------------- public device_palette_interface(machine_config mconfig, device_t device) : base(device, "palette") { m_palette = null; m_pens = null; m_format = bitmap_format.BITMAP_FORMAT_RGB32; m_shadow_table = null; m_shadow_group = 0; m_hilight_group = 0; m_white_pen = 0; m_black_pen = 0; }
rectangle m_cliprect; // a clipping rectangle covering the full bitmap // construction/destruction -- subclasses only to ensure type correctness //bitmap_t(const bitmap_t &) = delete; //bitmap_t(bitmap_t &&that); /** * @fn bitmap_t::bitmap_t(bitmap_format format, int bpp, int width, int height, int xslop, int yslop) * * @brief ------------------------------------------------- * bitmap_t - basic constructor * -------------------------------------------------. * * @param format Describes the format to use. * @param bpp The bits per pixel. * @param width The width. * @param height The height. * @param xslop The xslop. * @param yslop The yslop. */ public bitmap_t(bitmap_format format, uint8_t bpp, int width = 0, int height = 0, int xslop = 0, int yslop = 0) { m_alloc = null; m_allocbytes = 0; m_format = format; m_bpp = (byte)bpp; m_palette = null; assert(valid_format()); // allocate intializes all other fields allocate(width, height, xslop, yslop); }
// operations /** * @fn void bitmap_t::set_palette(palette_t *palette) * * @brief ------------------------------------------------- * set_palette -- associate a palette with a bitmap * -------------------------------------------------. * * @param [in,out] palette If non-null, the palette. */ public void set_palette(palette_t palette) { // first dereference any existing palette if (m_palette != null) { m_palette.deref(); m_palette = null; } // then reference any new palette if (palette != null) { palette.ref_(); m_palette = palette; } }
/** * @fn bitmap_t::bitmap_t(bitmap_format format, uint8_t bpp, void *base, int width, int height, int rowpixels) * * @brief Constructor. * * @param format Describes the format to use. * @param bpp The bits per pixel. * @param [in,out] base If non-null, the base. * @param width The width. * @param height The height. * @param rowpixels The rowpixels. */ public bitmap_t(bitmap_format format, uint8_t bpp, PointerU8 base_, int width, int height, int rowpixels) //bitmap_t::bitmap_t(bitmap_format format, uint8_t bpp, void *base, int width, int height, int rowpixels) { m_alloc = null; m_allocbytes = 0; m_base = base_; m_rowpixels = rowpixels; m_width = width; m_height = height; m_format = format; m_bpp = bpp; m_palette = null; m_cliprect = new rectangle(0, width - 1, 0, height - 1); assert(valid_format()); }
/** * @fn bitmap_t::bitmap_t(bitmap_format format, int bpp, bitmap_t &source, const rectangle &subrect) * * @brief Constructor. * * @param format Describes the format to use. * @param bpp The bits per pixel. * @param [in,out] source Source for the. * @param subrect The subrect. */ public bitmap_t(bitmap_format format, uint8_t bpp, bitmap_t source, rectangle subrect) { m_alloc = null; m_allocbytes = 0; m_base = source.raw_pixptr(subrect.top(), subrect.left()); //m_base(source.raw_pixptr(subrect.top(), subrect.left())) m_rowpixels = source.m_rowpixels; m_width = subrect.width(); m_height = subrect.height(); m_format = format; m_bpp = (uint8_t)bpp; m_palette = null; m_cliprect = new rectangle(0, subrect.width() - 1, 0, subrect.height() - 1); assert(format == source.m_format); assert(bpp == source.m_bpp); assert(source.cliprect().contains(subrect)); }
dirty_state [] m_dirty = new dirty_state[2]; // two dirty states // construction/destruction //------------------------------------------------- // palette_client - constructor //------------------------------------------------- public palette_client(palette_t palette) { m_palette = palette; m_next = null; m_liveIdx = 0; // m_live(&m_dirty[0]), m_previousIdx = 1; // m_previous(&m_dirty[1]) // add a reference to the palette palette.ref_(); // resize the dirty lists uint32_t total_colors = (uint32_t)(palette.num_colors() * palette.num_groups()); m_dirty[0] = new dirty_state(); m_dirty[1] = new dirty_state(); m_dirty[0].resize(total_colors); m_dirty[1].resize(total_colors); // now add us to the list of clients m_next = palette.m_client_list; palette.m_client_list = this; }
// internal helpers //------------------------------------------------- // allocate_palette - allocate and configure the // palette object itself //------------------------------------------------- void allocate_palette(u32 numentries) { assert(numentries > 0); // determine the number of groups we need int numgroups = 1; if (palette_shadows_enabled()) { m_shadow_group = (UInt32)numgroups++; } if (palette_hilights_enabled()) { m_hilight_group = (UInt32)numgroups++; } assert_always(numentries * numgroups <= 65536, "Palette has more than 65536 colors."); // allocate a palette object containing all the colors and groups m_palette = palette_t.alloc(numentries, (UInt32)numgroups); // configure the groups if (m_shadow_group != 0) { set_shadow_factor(PALETTE_DEFAULT_SHADOW_FACTOR); } if (m_hilight_group != 0) { set_highlight_factor(PALETTE_DEFAULT_HIGHLIGHT_FACTOR); } // set the initial colors to a standard rainbow for (int index = 0; index < numentries; index++) { set_pen_color((UInt32)index, rgbexpand(1, 1, 1, (UInt32)index, 0, 1, 2)); } // switch off the color mode switch (m_format) { // 16-bit paletteized case case bitmap_format.BITMAP_FORMAT_IND16: m_black_pen = m_palette.black_entry(); m_white_pen = m_palette.white_entry(); if (m_black_pen >= 65536) { m_black_pen = 0; } if (m_white_pen >= 65536) { m_white_pen = 65535; } break; // 32-bit direct case case bitmap_format.BITMAP_FORMAT_RGB32: m_black_pen = rgb_t.black(); m_white_pen = rgb_t.white(); break; // screenless case case bitmap_format.BITMAP_FORMAT_INVALID: default: break; } }