#include <libsdl/sdl.h>
//#include "sdl.h"
#ifdef test_vga16 /* define this if you want to test vga 16-color video modes */
#define num_colors 16
#else
#define num_colors 256
#endif
sdl_surface *screen;
void display_bmp()
{
sdl_surface *image;
char *file_name = "d:\\temp\\bao.bmp";
/* load the bmp file into a surface */
image = sdl_loadbmp(file_name);
if (image == null) {
// fprintf(stderr, "couldn't load %s: %s\n", file_name, 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 && screen->format->palette)
sdl_setcolors(screen, image->format->palette->colors, 0,
image->format->palette->ncolors);
/* blit onto the screen surface */
if(sdl_blitsurface(image, null, screen, null) < 0)
fprintf(stderr, "blitsurface error: %s\n", sdl_geterror());
sdl_updaterect(screen, 0, 0, image->w, image->h);
/* free the allocated bmp surface */
sdl_freesurface(image);
}
cstring str;
void csdl_testdlg::onbutton1()
// todo: add your control notification handler code here
m_list.resetcontent();
sdl_event event;
if((sdl_init(sdl_init_video|sdl_init_audio)==-1)) {
str.format("could not initialize sdl: %s.\n", sdl_geterror());
m_list.addstring(str);
m_list.addstring("sdl initialized.");
/* have a preference for 8-bit, but accept any depth */
screen = sdl_setvideomode(720, 576, 16, sdl_swsurface|sdl_anyformat);
if ( screen == null ) {
str.format( "couldn't set 720*576 video mode: %s",sdl_geterror());
str.format("set 720*576 at %d bits-per-pixel mode",
screen->format->bitsperpixel);
m_list.addstring(str);
display_bmp();
/* shutdown all subsystems */
//
m_list.addstring("quiting.... press image!");
while (sdl_waitevent(&event) )
switch (event.type)
case sdl_mousebuttondown:
sdl_quit();
return ;
break;
case sdl_keydown:
if ( event.key.keysym.sym == sdlk_space )
void csdl_testdlg::onbutton2()
int i = 1;
int x, y;
int w = 720;
int h = 576;
char c = 'n';
file* fp;
char filename[64];
unsigned char* py;
unsigned char* pu;
unsigned char* pv;
sdl_rect rect;
if (sdl_init(sdl_init_video) < 0)
{
fprintf(stderr, "can not initialize sdl:%s\n", sdl_geterror());
exit(1);
atexit(sdl_quit);
screen = sdl_setvideomode(720, 576, 32, sdl_swsurface|sdl_anyformat);
sdl_overlay* overlay = sdl_createyuvoverlay(w, h, sdl_yv12_overlay, screen);
if (overlay == null)
fprintf(stderr, "create overlay error!\n");
printf("w:%d, h:%d, planes:%d\n", overlay->w, overlay->h, overlay->planes);
printf("pitches:%d, %d, %d\n", overlay->pitches[0], overlay->pitches[1], overlay->pitches[2]);
py = (unsigned char*)malloc(w*h);
pu = (unsigned char*)malloc(w*h/4);
pv = (unsigned char*)malloc(w*h/4);
sdl_locksurface(screen);
sdl_lockyuvoverlay(overlay);
fp = fopen("d:\\temp\\1.yuv", "rb");
if (fp == null)
{
fprintf(stderr, "open file error!\n");
exit(1);
}
while (!feof(fp))
fread(py, 1, w*h, fp);
fread(pu, 1, w*h/4, fp);
fread(pv, 1, w*h/4, fp);
memcpy(overlay->pixels[0], py, w*h);
memcpy(overlay->pixels[1], pv, w*h/4);
memcpy(overlay->pixels[2], pu, w*h/4);
sdl_unlockyuvoverlay(overlay);
sdl_unlocksurface(screen);
rect.w = w;
rect.h = h;
rect.x = rect.y = 0;
sdl_displayyuvoverlay(overlay, &rect);
sdl_delay(40);
i += 1;
str.format("current frmcnt:%d",i);
fclose(fp);
free(py);
free(pu);
free(pv);
sdl_freeyuvoverlay(overlay);
sdl_freesurface(screen);
//unsigned char buff[720*576*3];
unsigned int rgb[720*576];
void csdl_testdlg::onbutton3()
// sdl_event event;
if (sdl_init(sdl_init_video) < 0)
sdl_surface *image;
uint32 rmask, gmask, bmask, amask;
/* sdl interprets each pixel as a 32-bit number, so our masks must depend
on the endianness (byte order) of the machine */
#if sdl_byteorder == sdl_big_endian
rmask = 0xff000000;
gmask = 0x00ff0000;
bmask = 0x0000ff00;
amask = 0x000000ff;
rmask = 0x000000ff;
gmask = 0x0000ff00;
bmask = 0x00ff0000;
amask = 0xff000000;
image = sdl_creatergbsurface(sdl_swsurface, 720, 576, 0,
rmask, gmask, bmask, amask);
if(image == null) {
fprintf(stderr, "creatergbsurface failed: %s\n", sdl_geterror());
// sdl_locksurface(screen);
// sdl_locksurface(image);
cbitmap m_bitmap;
hbitmap m_hbitmap;
bitmap bm;//存放位圖資訊的結構
m_hbitmap = (hbitmap)::loadimage(null,"d:\\temp\\bao.bmp",image_bitmap,0,0,lr_loadfromfile); //裝載位圖
if(m_bitmap.m_hobject)
m_bitmap.deleteobject();
m_bitmap.attach(m_hbitmap);//将句柄與cbitmap關聯起來
m_bitmap.getbitmap(&bm);
m_bitmap.getbitmapbits(bm.bmheight*bm.bmwidthbytes,rgb);
//
memcpy(screen->pixels,rgb,720*576*4);
// sdl_unlocksurface(image);
// sdl_unlocksurface(screen);
void csdl_testdlg::onbutton4()
// unsigned char* pu;
// unsigned char* pv;
sdl_overlay* overlay = sdl_createyuvoverlay(w, h, sdl_yuy2_overlay, screen);
py = (unsigned char*)malloc(w*h*2);
// pu = (unsigned char*)malloc(w*h/4);
// pv = (unsigned char*)malloc(w*h/4);
fp = fopen("d:\\temp\\6082.dat", "rb");
fread(py, 1, w*h*2, fp);
memcpy(overlay->pixels[0], py, w*h*2);
// free(pu);
// free(pv);
http://download.csdn.net/detail/mao0514/8202701