// given a paletted surface add it's colors in to the screen colormap // then return a surface with the color indexes remapped ready to // be displayed on the screen. insfc is either freed, or reused to // create the returned surface. SDL_Surface *palette_add(SDL_Surface *sfc) { SDL_Palette *pal = sfc->format->palette; int remap[MAX_COLORS]; int x, y, i; if (sfc->format->BitsPerPixel > 8) { staterr("palette_add: input surface is > 8bpp"); return NULL; } stat("palette_add: adding %d colors to screen palette...", pal->ncolors); for(i=0; i<pal->ncolors; i++) { remap[i] = palette_alloc(pal->colors[i].r, pal->colors[i].g, pal->colors[i].b); if (remap[i] == -1) return sfc; } SDL_SetColors(screen->GetSDLSurface(), screenpal, 0, ncolors); return sfc; /* // remap indexes in surface for(y=0;y<sfc->h;y++) { uint8_t *pixels = (uint8_t *)sfc->pixels + (y * sfc->pitch); for(x=0;x<sfc->w;x++) { *pixels = remap[*pixels]; pixels++; } } return sfc;*/ }
void laserdisc_device::init_video() { // register for VBLANK callbacks 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); 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)); // allocate video frames for (int index = 0; index < ARRAY_LENGTH(m_frame); index++) { // first allocate a YUY16 bitmap at 2x the height frame_data &frame = m_frame[index]; frame.m_bitmap.allocate(m_width, m_height * 2); frame.m_bitmap.set_palette(m_videopalette); fillbitmap_yuy16(frame.m_bitmap, 40, 109, 240); // make a copy of the bitmap that clips out the VBI and horizontal blanking areas frame.m_visbitmap.wrap(&frame.m_bitmap.pix16(44, frame.m_bitmap.width() * 8 / 720), frame.m_bitmap.width() - 2 * frame.m_bitmap.width() * 8 / 720, frame.m_bitmap.height() - 44, frame.m_bitmap.rowpixels()); frame.m_visbitmap.set_palette(m_videopalette); } // allocate an empty frame of the same size m_emptyframe.allocate(m_width, m_height * 2); m_emptyframe.set_palette(m_videopalette); fillbitmap_yuy16(m_emptyframe, 0, 128, 128); // allocate texture for rendering m_videoenable = true; m_videotex = machine().render().texture_alloc(); if (m_videotex == NULL) fatalerror("Out of memory allocating video texture\n"); // allocate overlay m_overenable = overlay_configured(); if (m_overenable) { // bind our handlers m_overupdate_ind16.bind_relative_to(*owner()); m_overupdate_rgb32.bind_relative_to(*owner()); // configure bitmap formats bitmap_format format = !m_overupdate_ind16.isnull() ? BITMAP_FORMAT_IND16 : BITMAP_FORMAT_RGB32; texture_format texformat = !m_overupdate_ind16.isnull() ? TEXFORMAT_PALETTEA16 : TEXFORMAT_ARGB32; // allocate overlay bitmaps for (int index = 0; index < ARRAY_LENGTH(m_overbitmap); index++) { m_overbitmap[index].set_format(format, texformat); m_overbitmap[index].set_palette(machine().palette); m_overbitmap[index].resize(m_overwidth, m_overheight); } // allocate overlay texture m_overtex = machine().render().texture_alloc(); if (m_overtex == NULL) fatalerror("Out of memory allocating overlay texture\n"); } }