ffmpeg and SDL tutorial : 這個就是有名的 "How to write a video player in 1000 lines".
順便寫一下,這個也有說明 ffmpeg 的 source code architecture
www.wiki.multimedia.cx
其實這些link 在 ffmpeg 的主站就有link
ubuntu 在 R40e 上 還有 Debian 在 Sempron 2600 上
2009年9月4日 星期五
SDL programming - draw pixel
SDL library 裝完後,就可以試試SDL。
先從 SDL 手動繪圖 (描點) 來看 :
參考的是 Linux Journal : a crash course in SDL
還有 SDL Wiki
看起來 SDL 的用發跟 DirectDraw 類似。
也是以 Surface 為操作主體。
在使用之前,要 作 initialize:
完整code:
SDL_Init(SDL_INIT_VIDEO);然後create 一個你要的 surface,可以任意指定這個 video surface 的 format (color depth, color space(?), dimension):
SDL_Surface *screen;
screen = SDL_SetVideoMode(640,480,16,SDL_FULL_SCREEN);
接下來就跟 DirectDraw 很像..
surface 的 structure 中包含 surface 的 raw data arrary (就像是 framebuffer一樣),可以直接作read/write pixel 的動作。
但是在操作之前,要lock surface,操作完後 unlock:
Uint16 *raw_pixels;
SDL_LockSurface(screen);
raw_pixels = (Uint16 *)screen->pixels;
要"填寫" raw pixel value,可以利用 screen structure 中另一個資訊:format。
format 包涵 color bit 的 有效bit和 bit 位置的資料:
在 example program 可以看出來:
Uint value;
value = ((red >>fmt->Rloss) <<fmt->Rshift) +
....
R.G.B 三色分別有對應的無效 bit 數 (Xloss) 和位置(Xshift)
還有 raw_pixels[] array 的 x, y 對應,可以依照 screen structure 的 pitch 的資料。
pitch 代表 一條 y line 的 byte 數。
example code 中,填寫 (x,y) 點的 offset 是:
screen->pitch/2 * y + 1-- 因為 raw_pixels 是 Uint16,所以要/2。 畫完圖後SDL_Unlock(screen)。 再call SDL_UpdateRect(screen,0,0,0,0) 把 surface update 到真正的螢幕上。
完整code:
#include "SDL.h"
Uint16 CreateHicolorPixel(SDL_PixelFormat *fmt, Uint8 red, Uint8 green, Uint8 blue)
{
Uint16 value;
value = ((red >>fmt->Rloss) << fmt->Rshift) +
((green>>fmt->Gloss) << fmt->Gshift) +
((blue >>fmt->Bloss) << fmt->Bshift);
return value;
}
int main(int argc,char* argv[])
{
SDL_Surface *screen;
Uint16 *raw_pixels;
int x,y;
SDL_Init(SDL_INIT_VIDEO);
atexit(SDL_Quit);
screen = SDL_SetVideoMode(640,480,16,SDL_FULLSCREEN);
SDL_LockSurface(screen);
raw_pixels = (Uint16*)screen->pixels;
for(x=0;x<256;x++){
for(y=0;y<256;y++){
Uint16 pixel_color;
int offset;
pixel_color=CreateHicolorPixel(screen->format,x,0,y);
offset=(screen->pitch/2 *y+x);
raw_pixels[offset]=pixel_color;
}
}
SDL_UnlockSurface(screen);
SDL_UpdateRect(screen,0,0,0,0);
SDL_Delay(3000);
return 0;
}
build command 可以利用 sdl-config 吐出 build optin:
gcc sdl1.c -o sdl1 `sdl-config --cflags --libs`
標籤
- 3g (19)
- 工作的備worklog (93)
- 自言自語 (36)
- 草稿 (1)
- 亂亂寫 (8)
- 翻譯 (3)
- administration (76)
- alsa (7)
- android (299)
- apple (5)
- application (42)
- archlinux (1)
- audio (3)
- avr (6)
- backup_restore (2)
- bluetooth (5)
- bookmark (38)
- bootloader (21)
- browser (5)
- cellphone (28)
- command (8)
- Configuration (27)
- debug (7)
- django (1)
- driver (15)
- earphone (1)
- editor (1)
- EFL (1)
- ffmpeg (18)
- Filesystem (4)
- GCC (8)
- Gentoo (1)
- google (1)
- Graphic (3)
- hardware (40)
- hero (7)
- hibernation (9)
- iMX51 (38)
- Info (3)
- Install (30)
- java (4)
- Kernel (102)
- language (2)
- life (2)
- make (11)
- MantainLog (38)
- MCU_P (9)
- memo (8)
- microcontroller (3)
- MINGW (7)
- network (19)
- OpenCL (1)
- OS (11)
- package (3)
- pad (1)
- ProblemAndSolve (15)
- programming (8)
- Python (7)
- raspberry_pi (23)
- SDL (2)
- sensation (13)
- setup (3)
- software_package (36)
- SQL (1)
- suspend (2)
- ToDo (5)
- tool (3)
- ubuntu (1)
- VersionControl (45)
- Virtualization (15)
- VLC (5)
- wheezy (1)
- wifi (3)
- Windows (16)
- xiaomi (1)
- xperia (1)