/** ** Change current color set to new player. ** ** FIXME: use function pointer here. ** ** @param player Pointer to player. ** @param sprite The sprite in which the colors should be changed. */ void GraphicPlayerPixels(CPlayer *player, const CGraphic *sprite) { Assert(PlayerColorIndexCount); if (sprite->Surface->format->palette == NULL) { // Cannot set the player colors when there is no palette. return; } // Skip units whose color palette does not cover the indexes // for the player color. if (sprite->Surface->format->palette->ncolors < PlayerColorIndexStart + PlayerColorIndexCount) { return; } SDL_LockSurface(sprite->Surface); SDL_SetColors(sprite->Surface, player->UnitColors.Colors, PlayerColorIndexStart, PlayerColorIndexCount); if (sprite->SurfaceFlip) { // The flipped surface is supposed to have a similar palette. Assert(sprite->SurfaceFlip->format->palette->ncolors == sprite->Surface->format->palette->ncolors); SDL_SetColors(sprite->SurfaceFlip, player->UnitColors.Colors, PlayerColorIndexStart, PlayerColorIndexCount); } SDL_UnlockSurface(sprite->Surface); }
static void VID_SetIcon (void) { SDL_Surface *icon; SDL_Color color; Uint8 *ptr; int i, mask; # include "xbm_icon.h" icon = SDL_CreateRGBSurface(SDL_SWSURFACE, HOT_ICON_WIDTH, HOT_ICON_HEIGHT, 8, 0, 0, 0, 0); if (icon == NULL) return; SDL_SetColorKey(icon, SDL_SRCCOLORKEY, 0); color.r = 255; color.g = 255; color.b = 255; SDL_SetColors(icon, &color, 0, 1); /* just in case */ color.r = 128; color.g = 0; color.b = 0; SDL_SetColors(icon, &color, 1, 1); ptr = (Uint8 *)icon->pixels; for (i = 0; i < sizeof(HOT_ICON_bits); i++) { for (mask = 1; mask != 0x100; mask <<= 1) { *ptr = (HOT_ICON_bits[i] & mask) ? 1 : 0; ptr++; } } SDL_WM_SetIcon(icon, NULL); SDL_FreeSurface(icon); }
/** * Initialize the GUI. */ int SDLGui_Init(void) { SDL_Color blackWhiteColors[2] = {{255, 255, 255, 255}, {0, 0, 0, 255}}; if (pSmallFontGfx && pBigFontGfx) { /* already initialized */ return 0; } /* Initialize the font graphics: */ pSmallFontGfx = SDLGui_LoadXBM(font5x8_width, font5x8_height, font5x8_bits); pBigFontGfx = SDLGui_LoadXBM(font10x16_width, font10x16_height, font10x16_bits); if (pSmallFontGfx == NULL || pBigFontGfx == NULL) { fprintf(stderr, "Error: Can not init font graphics!\n"); return -1; } /* Set color palette of the font graphics: */ SDL_SetColors(pSmallFontGfx, blackWhiteColors, 0, 2); SDL_SetColors(pBigFontGfx, blackWhiteColors, 0, 2); /* Set font color 0 as transparent: */ SDL_SetColorKey(pSmallFontGfx, (SDL_SRCCOLORKEY|SDL_RLEACCEL), 0); SDL_SetColorKey(pBigFontGfx, (SDL_SRCCOLORKEY|SDL_RLEACCEL), 0); return 0; }
static void SetSDLIcon() { #include "q2icon.xbm" SDL_Surface *icon; SDL_Color color; Uint8 *ptr; int i, mask; icon = SDL_CreateRGBSurface(SDL_SWSURFACE, q2icon_width, q2icon_height, 8, 0, 0, 0, 0); if (icon == NULL) return; /* oh well... */ SDL_SetColorKey(icon, SDL_SRCCOLORKEY, 0); color.r = 255; color.g = 255; color.b = 255; SDL_SetColors(icon, &color, 0, 1); /* just in case */ color.r = 0; color.g = 16; color.b = 0; SDL_SetColors(icon, &color, 1, 1); ptr = (Uint8 *) icon->pixels; for (i = 0; i < sizeof(q2icon_bits); i++) { for (mask = 1; mask != 0x100; mask <<= 1) { *ptr = (q2icon_bits[i] & mask) ? 1 : 0; ptr++; } } SDL_WM_SetIcon(icon, NULL); SDL_FreeSurface(icon); }
void set_rgb_color(byte co, byte r, byte g, byte b) { SDL_Color col; col.r = (r << 2); col.g = (g << 2); col.b = (b << 2); SDL_SetColors(real_screen, &col, co, 1); SDL_SetColors(screen, &col, co, 1); }
int main() { SDL_Init(SDL_INIT_VIDEO); SDL_Surface *screen = SDL_SetVideoMode(600, 400, 8, SDL_HWSURFACE | SDL_HWPALETTE); //initialize sdl palette //with red green and blue //colors SDL_Color pal[3]; pal[0].r = 255; pal[0].g = 0; pal[0].b = 0; pal[0].unused = 0; pal[1].r = 0; pal[1].g = 255; pal[1].b = 0; pal[1].unused = 0; pal[2].r = 0; pal[2].g = 0; pal[2].b = 255; pal[2].unused = 0; SDL_SetColors(screen, pal, 0, 3); SDL_FillRect(screen, NULL, 0); { SDL_Rect rect = { 300, 0, 300, 200 }; SDL_FillRect(screen, &rect, 1); } { SDL_Rect rect = { 0, 200, 600, 200 }; SDL_FillRect(screen, &rect, 2); } //changing green color //to yellow pal[1].r = 255; SDL_SetColors(screen, &pal[1], 1, 1); { SDL_Rect rect = { 300, 200, 300, 200 }; SDL_FillRect(screen, &rect, 1); } printf("you should see red, blue and yellow rectangles\n"); SDL_Quit(); return 0; }
bool CSprite::createSurface(Uint32 flags, SDL_Color *Palette) { mpSurface = SDL_CreateRGBSurface( flags, m_xsize, m_ysize, 8, 0, 0, 0, 0); SDL_SetColors( mpSurface.get(), Palette, 0, 255); SDL_SetColorKey( mpSurface.get(), SDL_SRCCOLORKEY, COLORKEY ); // One black is the color key. There is another black, as normal color mpMasksurface = SDL_CreateRGBSurface( flags, m_xsize, m_ysize, 8, 0, 0, 0, 0); SDL_SetColors( mpMasksurface.get(), Palette, 0, 255); SDL_SetColorKey( mpMasksurface.get(), SDL_SRCCOLORKEY, COLORKEY ); // color key. return ( mpSurface.empty() && mpMasksurface.empty() ); }
/** ** Change current color set to new player. ** ** FIXME: use function pointer here. ** ** @param player Pointer to player. ** @param sprite The sprite in which the colors should be changed. */ void GraphicPlayerPixels(CPlayer &player, const CGraphic &sprite) { Assert(PlayerColorIndexCount); SDL_LockSurface(sprite.Surface); std::vector<SDL_Color> sdlColors(player.UnitColors.Colors.begin(), player.UnitColors.Colors.end()); SDL_SetColors(sprite.Surface, &sdlColors[0], PlayerColorIndexStart, PlayerColorIndexCount); if (sprite.SurfaceFlip) { SDL_SetColors(sprite.SurfaceFlip, &sdlColors[0], PlayerColorIndexStart, PlayerColorIndexCount); } SDL_UnlockSurface(sprite.Surface); }
static void UpdatePalette(bool init = false) { SDL_Color pal[256]; for (int i = 0; i != _local_palette.count_dirty; i++) { pal[i].r = _local_palette.palette[_local_palette.first_dirty + i].r; pal[i].g = _local_palette.palette[_local_palette.first_dirty + i].g; pal[i].b = _local_palette.palette[_local_palette.first_dirty + i].b; pal[i].unused = 0; } SDL_CALL SDL_SetColors(_sdl_screen, pal, _local_palette.first_dirty, _local_palette.count_dirty); if (_sdl_screen != _sdl_realscreen && init) { /* When using a shadow surface, also set our palette on the real screen. This lets SDL * allocate as much colors (or approximations) as * possible, instead of using only the default SDL * palette. This allows us to get more colors exactly * right and might allow using better approximations for * other colors. * * Note that colors allocations are tried in-order, so * this favors colors further up into the palette. Also * note that if two colors from the same animation * sequence are approximated using the same color, that * animation will stop working. * * Since changing the system palette causes the colours * to change right away, and allocations might * drastically change, we can't use this for animation, * since that could cause weird coloring between the * palette change and the blitting below, so we only set * the real palette during initialisation. */ SDL_CALL SDL_SetColors(_sdl_realscreen, pal, _local_palette.first_dirty, _local_palette.count_dirty); } if (_sdl_screen != _sdl_realscreen && !init) { /* We're not using real hardware palette, but are letting SDL * approximate the palette during shadow -> screen copy. To * change the palette, we need to recopy the entire screen. * * Note that this operation can slow down the rendering * considerably, especially since changing the shadow * palette will need the next blit to re-detect the * best mapping of shadow palette colors to real palette * colors from scratch. */ SDL_CALL SDL_BlitSurface(_sdl_screen, NULL, _sdl_realscreen, NULL); SDL_CALL SDL_UpdateRect(_sdl_realscreen, 0, 0, 0, 0); } }
static void Vid_SetMode() { int n; int w, h; int flags = 0; printf("CGA Screen Emulation\n"); printf("init screen: "); if (SDL_Init(SDL_INIT_VIDEO) < 0) { printf("failed\n"); fprintf(stderr, "Unable to initialise video subsystem: %s\n", SDL_GetError()); exit(-1); } srand(time(NULL)); set_icon(symbol_plane[rand() % 2][rand() % 16]); w = SCR_WDTH; h = SCR_HGHT; if (vid_double_size) { w *= 2; h *= 2; } flags = SDL_HWPALETTE; if (vid_fullscreen) flags |= SDL_FULLSCREEN; screen = SDL_SetVideoMode(w, h, 8, flags); if (screen) { printf("initialised\n"); } else { printf("failed to set mode\n"); fprintf(stderr, "cant init SDL\n"); exit(-1); } SDL_EnableUNICODE(1); for (n = 0; n < NUM_KEYS; ++n) keysdown[n] = 0; SDL_WM_SetCaption("SDL Sopwith", NULL); SDL_SetColors(screen, cga_pal, 0, sizeof(cga_pal)/sizeof(*cga_pal)); SDL_SetColors(screenbuf, cga_pal, 0, sizeof(cga_pal)/sizeof(*cga_pal)); SDL_ShowCursor(0); }
/** ** Change current color set to new player. ** ** FIXME: use function pointer here. ** ** @param player Pointer to player. ** @param sprite The sprite in which the colors should be changed. */ void GraphicPlayerPixels(CPlayer *player, const CGraphic *sprite) { Assert(PlayerColorIndexCount); SDL_LockSurface(sprite->Surface); SDL_SetColors(sprite->Surface, player->UnitColors.Colors, PlayerColorIndexStart, PlayerColorIndexCount); if (sprite->SurfaceFlip) { SDL_SetColors(sprite->SurfaceFlip, player->UnitColors.Colors, PlayerColorIndexStart, PlayerColorIndexCount); } SDL_UnlockSurface(sprite->Surface); }
void gr_refresh_palette() { int n ; if ( sys_pixel_format->depth > 8 ) { if ( sys_pixel_format->palette ) { for ( n = 0 ; n < 256 ; n++ ) { sys_pixel_format->palette->colorequiv[ n ] = gr_map_rgb ( sys_pixel_format, sys_pixel_format->palette->rgb[ n ].r, sys_pixel_format->palette->rgb[ n ].g, sys_pixel_format->palette->rgb[ n ].b ) ; } } } else if ( sys_pixel_format->depth == 8 ) { if ( sys_pixel_format->palette ) { for ( n = 0 ; n < 256 ; n++ ) { palette[ n ].r = sys_pixel_format->palette->rgb[ n ].r; palette[ n ].g = sys_pixel_format->palette->rgb[ n ].g; palette[ n ].b = sys_pixel_format->palette->rgb[ n ].b; } } else { uint8_t * pal = default_palette; for ( n = 0 ; n < 256 ; n++ ) { palette[ n ].r = *pal++; palette[ n ].g = *pal++; palette[ n ].b = *pal++; } } if ( scale_screen ) SDL_SetColors( scale_screen, palette, 0, 256 ) ; else SDL_SetColors( screen, palette, 0, 256 ) ; } palette_changed = 0; trans_table_updated = 0 ; }
/* change FG/BG colors and transparency */ void GUI_TermWin::SetColoring(Uint8 fr,Uint8 fg,Uint8 fb, int bg_opaque, Uint8 br, Uint8 bg, Uint8 bb) { SDL_Color colors[3]={{br,bg,bb,0},{fr,fg,fb,0}}; if (bg_opaque) { SDL_SetColors(font,colors,0,2); SDL_SetColorKey(font,0,0); } else { SDL_SetColors(font,&colors[1],1,1); SDL_SetColorKey(font,SDL_SRCCOLORKEY,0); } }
int fb_open() { int i; SDL_Init(SDL_INIT_VIDEO); screen = SDL_SetVideoMode(LCD_WIDTH, LCD_HEIGHT, 8, SDL_SWSURFACE); if (!screen) { SDL_Quit(); printf ("Could not set 160x128x8 video mode: %s\n", SDL_GetError()); return 1; } /* set palette */ for (i = 0; i < 256; i+= 4) { ipod_palette[i] = white; ipod_palette[i + 1] = ltgrey; ipod_palette[i + 2] = dkgrey; ipod_palette[i + 3] = black; } SDL_SetColors(screen, ipod_palette, 0, 256); SDL_ShowCursor(SDL_DISABLE); return 0; }
void gr_palette_load( ubyte *pal ) { int i, j; SDL_Palette *palette; SDL_Color colors[256]; for (i=0; i<768; i++ ) { gr_current_pal[i] = pal[i]; if (gr_current_pal[i] > 63) gr_current_pal[i] = 63; } palette = screen->format->palette; if (palette == NULL) { return; // Display is not palettised } for (i = 0, j = 0; j < 256; j++) { //changed on 980913 by adb to fix palette problems colors[j].r = (min(gr_current_pal[i++] + gr_palette_gamma, 63)) * 4; colors[j].g = (min(gr_current_pal[i++] + gr_palette_gamma, 63)) * 4; colors[j].b = (min(gr_current_pal[i++] + gr_palette_gamma, 63)) * 4; //end changes by adb } SDL_SetColors(screen, colors, 0, 256); gr_palette_faded_out = 0; init_computed_colors(); }
static int native_updaterect (SADisplay *display, VisRectangle *rect) { SDLNative *native = SDL_NATIVE (display->native); SDL_Surface *sdlscreen = native->screen; if (sdlscreen->format->BitsPerPixel == 8) { SDL_Color colors[256]; VisPalette *pal = display->screen->pal; visual_mem_set (colors, 0, sizeof (colors)); if (pal != NULL && pal->ncolors <= 256) { int i; for (i = 0; i < pal->ncolors; i++) { colors[i].r = pal->colors[i].r; colors[i].g = pal->colors[i].g; colors[i].b = pal->colors[i].b; } SDL_SetColors (sdlscreen, colors, 0, 256); } } if (native->requested_depth == VISUAL_VIDEO_DEPTH_GL) SDL_GL_SwapBuffers (); else SDL_UpdateRect (sdlscreen, rect->x, rect->y, rect->width, rect->height); return 0; }
void I_SetPalette (byte* palette) { register int i; register int c; static boolean firstcall = true; // TODO: add SDL mode check { // initialize the colormap if (firstcall) { firstcall = false; } // set the X colormap entries for (i=0 ; i<256 ; i++) { c = gammatable[usegamma][*palette++]; colors[i].r = (c<<8) + c; c = gammatable[usegamma][*palette++]; colors[i].g = (c<<8) + c; c = gammatable[usegamma][*palette++]; colors[i].b = (c<<8) + c; } // store the colors to the current colormap SDL_SetColors(screen, colors, 0, 256); } }
void render_player(SDL_Surface* surface) { SDL_Surface *image = IMG_Load("img/character1.png"); if(image == NULL) { fprintf(stderr, "Unable to load image - reason: %s\n", SDL_GetError()); return; } /* * Palettized screen modes will have a default palette (a standard * 8*8*4 colour cube), but if the image is palettized as well we can * use that palette for a nicer colour matching */ if (image->format->palette && surface->format->palette) { SDL_SetColors(surface, image->format->palette->colors, 0, image->format->palette->ncolors); } SDL_Rect dest; dest.x = get_player()->x; dest.y = get_player()->y; dest.w = image->w; dest.h = image->h; if(SDL_BlitSurface(image,NULL, surface, &dest) < 0) { fprintf(stderr, "%s\n", SDL_GetError()); } SDL_UpdateRect(surface, dest.x,dest.y,dest.w, dest.h); SDL_FreeSurface(image); }
SDL_Surface* CRlePack::CreateSurface( int a_iIndex, bool a_bFlipped ) { if ( (a_iIndex<0) || (a_iIndex>=p->m_iCount) ) return NULL; SRleSprite* poSprite = p->m_pSprites[a_iIndex]; if (!poSprite) return NULL; SDL_Surface* poSurface = SDL_CreateRGBSurface( SDL_SWSURFACE, poSprite->w, poSprite->h, gamescreen->format->BitsPerPixel, gamescreen->format->Rmask, gamescreen->format->Gmask, gamescreen->format->Bmask, gamescreen->format->Amask ); if ( NULL == poSurface ) { return NULL; } if ( gamescreen->format->BitsPerPixel <= 8 ) { SDL_SetColors( poSurface, gamescreen->format->palette->colors, 0, gamescreen->format->palette->ncolors ); } SDL_FillRect( poSurface, NULL, 0 );// C_LIGHTGREEN ); SDL_SetColorKey( poSurface, SDL_SRCCOLORKEY, 0 ); //C_LIGHTGREEN ); SDL_Surface* poTemp = gamescreen; gamescreen = poSurface; Draw( a_iIndex, 0, 0, a_bFlipped ); gamescreen = poTemp; return poSurface; }
/** * Shifts all the colors in the surface's palette by a set amount. * Optionally inverts the colors according to a middle point as well. * This is a common method in 8bpp games to simulate color * effects for cheap. * @param off Amount to shift. * @param mul Shift multiplier. * @param mid Optional middle point used to invert palette. If 0, palette is not inverted */ void Surface::paletteShift(int off, int mul, int mid) { int ncolors = _surface->format->palette->ncolors; // store the original palette _originalColors = (SDL_Color *)malloc(sizeof(SDL_Color) * ncolors); // create a temporary new palette SDL_Color *newColors = (SDL_Color *)malloc(sizeof(SDL_Color) * ncolors); // do the color shift - while storing the original colors too for (int i = 0; i < ncolors; i++) { int inverseOffset = mid ? 2 * (mid - i) : 0; int j = (i * mul + off + inverseOffset + ncolors) % ncolors; _originalColors[i].r = getPalette()[i].r; _originalColors[i].g = getPalette()[i].g; _originalColors[i].b = getPalette()[i].b; newColors[i].r = getPalette()[j].r; newColors[i].g = getPalette()[j].g; newColors[i].b = getPalette()[j].b; } // assign it and free it SDL_SetColors(_surface, newColors, 0, ncolors); free(newColors); return; }
void init() { SDL_Color palette[256]; int i; srand(time(NULL)); if( SDL_Init( SDL_INIT_VIDEO ) == -1) { fprintf(stderr, "could not init SDL\n"); exit(-1); } screen = SDL_SetVideoMode( 640, 480, 8, SDL_SWSURFACE | SDL_DOUBLEBUF ); if(!screen) { fprintf(stderr, "could not set video mode\n"); exit(-1); } SDL_WM_SetCaption( "teapot", NULL ); for(i = 0; i < 256; i++) { palette[i].r = i; palette[i].g = i; palette[i].b = i; } SDL_SetColors( screen, palette, 1, 255 ); }
/** * Renders the buffer's contents onto the screen, applying * any necessary filters or conversions in the process. * If the scaling factor is bigger than 1, the entire contents * of the buffer are resized by that factor (eg. 2 = doubled) * before being put on screen. */ void Screen::flip() { if (getWidth() != _baseWidth || getHeight() != _baseHeight || isOpenGLEnabled()) { Zoom::flipWithZoom(_surface->getSurface(), _screen, _topBlackBand, _bottomBlackBand, _leftBlackBand, _rightBlackBand, &glOutput); } else { SDL_BlitSurface(_surface->getSurface(), 0, _screen, 0); } // perform any requested palette update if (_pushPalette && _numColors && _screen->format->BitsPerPixel == 8) { if (_screen->format->BitsPerPixel == 8 && SDL_SetColors(_screen, &(deferredPalette[_firstColor]), _firstColor, _numColors) == 0) { Log(LOG_DEBUG) << "Display palette doesn't match requested palette"; } _numColors = 0; _pushPalette = false; } if (SDL_Flip(_screen) == -1) { throw Exception(SDL_GetError()); } }
void switchmode(void) { uint32_t saved; SDL_Surface *tmp = NULL; SDL_Surface *oldscreen; vgageti(0, 0, (uint8_t *)&tmp, 80, 200); oldscreen = screen; saved = addflag; if(addflag == 0) addflag = SDL_FULLSCREEN; else addflag = 0; if(setmode() == false) { addflag = saved; if(setmode() == false) { fprintf(stderr, "Fatal: failed to change videomode and"\ "fallback mode failed as well. Exitting.\n"); exit(1); } } SDL_SetColors(screen, tmp->format->palette->colors, 0, \ tmp->format->palette->ncolors); vgaputi(0, 0, (uint8_t *)&tmp, 80, 200); SDL_FreeSurface(tmp); SDL_FreeSurface(oldscreen); }
/* Draw a text string. */ void SDLGui_Text(int x, int y, const char *txt, int col) { int i; char c; SDL_Rect sr, dr; #if SDL_VERSION_ATLEAST(2, 0, 0) SDL_SetPaletteColors(fontgfx->format->palette, &gui_palette[col], 1, 1); #else SDL_SetColors(fontgfx, &gui_palette[col], 1, 1); #endif for (i = 0 ; txt[i] != 0 ; i++) { c = txt[i]; sr.x = fontwidth * (c % 16); sr.y = fontheight * (c / 16); sr.w = fontwidth; sr.h = fontheight; dr.x = x + (fontwidth * i); dr.y = y; dr.w = fontwidth; dr.h = fontheight; SDL_BlitSurface(fontgfx, &sr, sdlscrn, &dr); } }
/** * Recreates the surface with a new size. * Old contents will not be altered, and may be * cropped to fit the new size. * @param width Width in pixels. * @param height Height in pixels. */ void Surface::resize(int width, int height) { // Set up new surface Uint8 bpp = _surface->format->BitsPerPixel; int pitch = GetPitch(bpp, width); void *alignedBuffer = NewAligned(bpp, width, height); SDL_Surface *surface = SDL_CreateRGBSurfaceFrom(alignedBuffer, width, height, bpp, pitch, 0, 0, 0, 0); if (surface == 0) { throw Exception(SDL_GetError()); } // Copy old contents SDL_SetColorKey(surface, SDL_SRCCOLORKEY, 0); SDL_SetColors(surface, getPalette(), 0, 255); SDL_BlitSurface(_surface, 0, surface, 0); // Delete old surface DeleteAligned(_alignedBuffer); SDL_FreeSurface(_surface); _alignedBuffer = alignedBuffer; _surface = surface; _clear.w = getWidth(); _clear.h = getHeight(); }
SDL_Surface *CreateScreen(Uint16 w, Uint16 h, Uint8 bpp, Uint32 flags) { SDL_Surface *screen; int i; SDL_Color palette[NUM_COLORS]; /* Set the video mode */ screen = SDL_SetVideoMode(w, h, bpp, flags); if ( screen == NULL ) { fprintf(stderr, "Couldn't set display mode: %s\n", SDL_GetError()); return(NULL); } fprintf(stderr, "Screen is in %s mode\n", (screen->flags & SDL_FULLSCREEN) ? "fullscreen" : "windowed"); if (bpp==8) { /* Set a gray colormap, reverse order from white to black */ for ( i=0; i<NUM_COLORS; ++i ) { palette[i].r = (NUM_COLORS-1)-i * (256 / NUM_COLORS); palette[i].g = (NUM_COLORS-1)-i * (256 / NUM_COLORS); palette[i].b = (NUM_COLORS-1)-i * (256 / NUM_COLORS); } SDL_SetColors(screen, palette, 0, NUM_COLORS); } return(screen); }
void DECODE_COLOR() { Uint8 *pSrc; Uint16 NumColors, NumColorPackets; Uint8 NumColorsSkip; int i; pSrc=flc.pChunk+6; ReadU16(&NumColorPackets, pSrc); pSrc+=2; while(NumColorPackets--) { NumColorsSkip=*(pSrc++); if(!(NumColors=*(pSrc++))) { NumColors=256; } i=0; while(NumColors--) { flc.colors[i].r=*(pSrc++)<<2; flc.colors[i].g=*(pSrc++)<<2; flc.colors[i].b=*(pSrc++)<<2; i++; } flc.realscreen->setPalette(flc.colors, NumColorsSkip, i); SDL_SetColors(flc.mainscreen, flc.colors, NumColorsSkip, i); flc.realscreen->getSurface(); // force palette update to really happen } } /* DECODE_COLOR */
/* Create a fresh surface. If transparency is true, the surface is * created with 32-bit pixels, so as to ensure a complete alpha * channel. Otherwise, the surface is created with the same format as * the screen. */ static SDL_Surface *newsurface(int w, int h, int transparency) { SDL_Surface *s; if (transparency) { #if SDL_BYTEORDER == SDL_BIG_ENDIAN s = SDL_CreateRGBSurface(SDL_SWSURFACE | SDL_SRCALPHA | SDL_RLEACCEL, w, h, 32, 0xFF000000, 0x00FF0000, 0x0000FF00, 0x000000FF); #else s = SDL_CreateRGBSurface(SDL_SWSURFACE | SDL_SRCALPHA | SDL_RLEACCEL, w, h, 32, 0x000000FF, 0x0000FF00, 0x00FF0000, 0xFF000000); #endif } else { s = SDL_CreateRGBSurface(SDL_SWSURFACE, w, h, sdlg.screen->format->BitsPerPixel, sdlg.screen->format->Rmask, sdlg.screen->format->Gmask, sdlg.screen->format->Bmask, sdlg.screen->format->Amask); } if (!s) die("couldn't create surface: %s", SDL_GetError()); if (!transparency && sdlg.screen->format->palette) SDL_SetColors(s, sdlg.screen->format->palette->colors, 0, sdlg.screen->format->palette->ncolors); return s; }
void cUnit::drawBase() { byte angle = g_DuneEngine->resourcesGet()->angleAdjustGet( _angleBase._Current ); word *adjust = 0, *flag = 0; word frameAdd = 0, flags = 0; SDL_Surface *surface = 0; word destX, destY; destX = _X; destY = _Y; switch( _UnitData->frameAngleMode ) { case 0: break; case 1: case 2: { if( _UnitData->MovementType == 5) // Underground break; adjust = g_DuneEngine->resourcesGet()->unitAngleFrameAdjustGet( angle ); flag = g_DuneEngine->resourcesGet()->unitAngleFrameFlagsGet( angle ); frameAdd = *adjust; flags = *flag; break; } case 3: { adjust = g_DuneEngine->resourcesGet()->unitAngleFrame3AdjustGet( angle ); flag = g_DuneEngine->resourcesGet()->unitAngleFrame3FlagsGet( angle ); frameAdd = (*adjust) * 3; frameAdd += (*g_DuneEngine->resourcesGet()->unitFrameAdjustGet( _frame & 0x03 )); flags = *flag; break; } case 4: adjust = g_DuneEngine->resourcesGet()->unitAngleFrame3AdjustGet( angle ); flag = g_DuneEngine->resourcesGet()->unitAngleFrame3FlagsGet( angle ); frameAdd = (*adjust) << 2; frameAdd += (*g_DuneEngine->resourcesGet()->unitFrameAdjustGet( _frame & 0x03 )); flags = *flag; break; } surface = g_DuneEngine->resourcesGet()->shpGet( _UnitData->UnitGfxID + frameAdd, flags & 1 ); SDL_SetColors(surface, _house->paletteGet()->colors, 0, _house->paletteGet()->ncolors); if(surface->w == 8) { destX += 4; destY += 4; } _surface->surfacePut( surface, destX, destY); }
SDL_Surface *SDL_HorizontalInvert( SDL_Surface *image) { SDL_Surface *surface = SDL_CreateRGBSurface(SDL_SWSURFACE, image->w, image->h, 8, 0, 0, 0, 0); SDL_FillRect( surface, 0, 0xFF); SDL_SetColorKey( surface, SDL_SRCCOLORKEY, 0); SDL_SetColors(surface, image->format->palette->colors, 0, image->format->palette->ncolors); byte *src = (byte*) image->pixels; byte *dst; word gap = (image->pitch - image->w); for(int y = 0; y < surface->h; y++) { dst = ((byte*) surface->pixels) + surface->pitch + (( y * surface->pitch ) -gap) - 1; for(int x = 0; x < surface->w; x++) { *dst = *src; --dst; ++src; } src += gap; } return surface; }