可以在這裡下載:http://www.ferzkopp.net/joomla/content/view/19/14/
名為SDL_gfx、這裡是它的API文檔http://www.ferzkopp.net/Software/SDL_gfx-2.0/Docs/html/index.html
當然嗎如果邇僅僅是需要縮放的話而不需要其它功能也可以自己寫個簡單的縮放圖形的函數、這裡是
這裡提供完整的縮放代碼:
Uint32 ReadPixel(SDL_Surface *surface, int x, int y){ int bpp = surface->format->BytesPerPixel; /* Here p is the address to the pixel we want to retrieve */ Uint8 *p = (Uint8 *)surface->pixels + y * surface->pitch + x * bpp; switch(bpp) { case 1: return *p; break; case 2: return *(Uint16 *)p; break; case 3: if(SDL_BYTEORDER == SDL_BIG_ENDIAN) return p[0] << 16 | p[1] << 8 | p[2]; else return p[0] | p[1] << 8 | p[2] << 16; break; case 4: return *(Uint32 *)p; break; default: return 0; /* shouldn't happen, but avoids warnings */ }}void DrawPixel(SDL_Surface *surface, int x, int y, Uint32 pixel){ int bpp = surface->format->BytesPerPixel; /* Here p is the address to the pixel we want to set */ Uint8 *p = (Uint8 *)surface->pixels + y * surface->pitch + x * bpp; switch(bpp) { case 1: *p = pixel; break; case 2: *(Uint16 *)p = pixel; break; case 3: if(SDL_BYTEORDER == SDL_BIG_ENDIAN) { p[0] = (pixel >> 16) & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = pixel & 0xff; } else { p[0] = pixel & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = (pixel >> 16) & 0xff; } break; case 4: *(Uint32 *)p = pixel; break; }}SDL_Surface* SDL_ScaleSurface(SDL_Surface *Surface, Uint16 Width, Uint16 Height){ SDL_Surface *_ret = SDL_CreateRGBSurface(Surface->flags, Width, Height, Surface->format->BitsPerPixel, Surface->format->Rmask, Surface->format->Gmask, Surface->format->Bmask, Surface->format->Amask); double _stretch_factor_x = (static_cast<double>(Width) / static_cast<double>(Surface->w)), _stretch_factor_y = (static_cast<double>(Height) / static_cast<double>(Surface->h)); for(Sint32 y = 0; y < Surface->h; y++) //Run across all Y pixels. for(Sint32 x = 0; x < Surface->w; x++) //Run across all X pixels. for(Sint32 o_y = 0; o_y < _stretch_factor_y; ++o_y) //Draw _stretch_factor_y pixels for each Y pixel. for(Sint32 o_x = 0; o_x < _stretch_factor_x; ++o_x) //Draw _stretch_factor_x pixels for each X pixel. DrawPixel(_ret, static_cast<Sint32>(_stretch_factor_x * x) + o_x, static_cast<Sint32>(_stretch_factor_y * y) + o_y, ReadPixel(Surface, x, y)); return _ret;}
最後邇只需要簡單的調用SDL_ScaleSurface就可以了、這個代碼的實現非常的簡單、先輸入長寬、然後計算輸出的表面長寬比、如果是小於的話、就兩個像素變成一個像素、如果是大於原來的表面的話、就複製兩個像素代表原來的一個像素、總的來說就是這樣子吧其中返回的是計算後的產生的表面、如果原來的表面沒有用的話、趕緊使用SDL_FreeSurface釋放掉它吧、不然又要佔記憶體空間了、這裡還依賴了兩個函數寫像素和讀像素
原文連結:
http://www.sdltutorials.com/sdl-scale-surface
http://www.libsdl.org/cgi/docwiki.cgi/Pixel_Access