#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());
        m_list.AddString(str);
    }
    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 ) 
{
SDL_Quit();
return ;
break;
}
}
}
}

void CSdl_testDlg::OnButton2() 
{
// TODO: Add your control notification handler code here
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;
m_list.ResetContent();
    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);
    if ( screen == NULL ) {
        str.Format( "Couldn't set 720*576 video mode: %s",SDL_GetError());
        m_list.AddString(str);
    }

    SDL_Overlay* overlay = SDL_CreateYUVOverlay(w, h, SDL_YV12_OVERLAY, screen);
    if (overlay == NULL)
    {
        fprintf(stderr, "create overlay error!\n");
        exit(1);
    }

    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);
m_list.AddString(str);
    }
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() 
{
// TODO: Add your control notification handler code here
m_list.ResetContent();

// SDL_Event event;
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);
    if ( screen == NULL ) {
        str.Format( "Couldn't set 720*576 video mode: %s",SDL_GetError());
        m_list.AddString(str);
    }

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;
#else
    rmask = 0x000000ff;
    gmask = 0x0000ff00;
    bmask = 0x00ff0000;
    amask = 0xff000000;
#endif

    image = SDL_CreateRGBSurface(SDL_SWSURFACE, 720, 576, 0,
                                   rmask, gmask, bmask, amask);
    if(image == NULL) {
        fprintf(stderr, "CreateRGBSurface failed: %s\n", SDL_GetError());
        exit(1);
    }

// 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);

    SDL_UpdateRect(screen, 0, 0, image->w, image->h);
    
    /* Free the allocated BMP surface */
    SDL_FreeSurface(image);
}

void CSdl_testDlg::OnButton4() 
{
// TODO: Add your control notification handler code here
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;
m_list.ResetContent();
    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);
    if ( screen == NULL ) {
        str.Format( "Couldn't set 720*576 video mode: %s",SDL_GetError());
        m_list.AddString(str);
    }

    SDL_Overlay* overlay = SDL_CreateYUVOverlay(w, h, SDL_YUY2_OVERLAY, screen);
    if (overlay == NULL)
    {
        fprintf(stderr, "create overlay error!\n");
        exit(1);
    }

    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*2);
//    pU = (unsigned char*)malloc(w*h/4);
//    pV = (unsigned char*)malloc(w*h/4);

   
        SDL_LockSurface(screen);
        SDL_LockYUVOverlay(overlay);

 
        fp = fopen("d:\\TEMP\\6082.dat", "rb");
        if (fp == NULL)
        {
            fprintf(stderr, "open file error!\n");
            exit(1);
        }
while (!feof(fp))
{
        fread(pY, 1, w*h*2, fp);


        memcpy(overlay->pixels[0], pY, w*h*2);


       

        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);
m_list.AddString(str);
    }
fclose(fp);
    free(pY);
//    free(pU);
  //  free(pV);


    SDL_FreeYUVOverlay(overlay);
    SDL_FreeSurface(screen);
}

http://download.csdn.net/detail/mao0514/8202701

MFC下用sdl 显示bmp、rgb、yuv的更多相关文章

  1. 在c++MFC下用PCL显示操作点云文件 MFC对话框显示操作PCL点云

    原文作者:aircraft 原文地址:https://www.cnblogs.com/DOMLX/p/13115873.html 第一步 下载PCL库  我的版本是1.8.1的 你都要MFC下跑PCL ...

  2. 嵌入式linux------SDL移植(am335x下显示bmp图片)

    #include<stdio.h> #include "/usr/local/ffmpeg_arm/include/SDL/SDL.h" char *bmp_name[ ...

  3. 【秒懂音视频开发】21_显示BMP图片

    文本的主要内容是:使用SDL显示一张BMP图片,算是为后面的<播放YUV>做准备. 为什么是显示BMP图片?而不是显示JPG或PNG图片? 因为SDL内置了加载BMP的API,使用起来会更 ...

  4. MFC对话框显示BMP图片

    1.MFC对话框显示BMP图片我们先从简单的开始吧.先分一个类: (一) 非动态显示图片(即图片先通过资源管理器载入,有一个固定ID) (二) 动态载入图片(即只需要在程序中指定图片的路径即可载入) ...

  5. MFC对话框中显示BMP,JPG图片

    //************************************ // 方法说明:    显示JPG和GIF.BMP图片 // 参数说明:    CDC * pDC           设 ...

  6. 远程控制编写之屏幕传输 MFC实现 屏幕截图 发送bmp数据 显示bmp图像

    远程控制编写之屏幕传输  MFC实现  屏幕截图 发送bmp数据 显示bmp图像: 一 : 首先要了解bmp图像的结构 详情请看我转载的一篇文章http://blog.csdn.net/hnust_x ...

  7. MFC中显示 .bmp格式的位图

    最近在看VisualC++ 图像处理的书籍,表示一直在从基础做起,今天就记录一个简单功能的实现,显示.bmp格式的位图. 首先需要理解的是窗口创建的过程包括两个步骤:首先擦除窗口的背景,然后在对窗口进 ...

  8. Android下基于SDL的YUV渲染

    实战篇 本文主要参考我之前整理的文章windows下使用SDL进行YUV渲染. 相对于之前写的位图渲染部分(http://www.cnblogs.com/tocy/p/android-sdl-bitm ...

  9. MFC显示bmp图像

    有了bmp文件读写的基础,我们就能够開始用MFC显示BMP图片了. 在这里,事实上微软为我们提供了一个实现bmp文件显示的框架,名叫diblook,我们能够先下载下来看看. 以下上链接:DIBLOOK ...

随机推荐

  1. Eclipse运行Java简单实例

    运行eclipse前首先配置好JDK环境变量等  双击这句话可跳转配置环境变量详细步骤 运行eclipse软件 1.File菜单-New - project 2.Java Project - Next ...

  2. SQL Server中计算表达式的和

    项目使用的是SQL Server数据库,需要做一个审核规则,字段A中表达式的值和字段B中的值,做比较: 需求本身很简单,但是表达式中存在很多非法字符(非法全角,运算符,汉字--) eg:1.1.1*2 ...

  3. JAVA并发编程学习笔记------对象的可见性及发布逸出

    一.非原子的64位操作: 当线程在没有同步的情况下读取变量时,可能会得到一个失效值,但至少这个值是由之前某个线程设置的值,而不是一个随机值,这种安全性保证被称为最低安全性.最低安全性适用于绝大多数变量 ...

  4. spring boot + vue + element-ui全栈开发入门——开篇

    最近经常看到很多java程序员朋友还在使用Spring 3.x,Spring MVC(struts),JSP.jQuery等这样传统技术.其实,我并不认为这些传统技术不好,而我想表达的是,技术的新旧程 ...

  5. 制作 alipay-sdk-java包到本地仓库

    一.首先 搭建好maven 基础环境,本地可以运行maven 命令 从支付宝官网上下载sdk https://doc.open.alipay.com/doc2/detail?treeId=54& ...

  6. 编程岗位电话面试问答Top 50[转]

    原文链接:http://blog.jobbole.com/84618/ 1. 从哈希表,二叉树和链表中取元素的时间复杂度?如果你有数百万记录呢? 哈希表的时间复杂度为O(1),二叉树为O(logN) ...

  7. BZOJ 1935: [Shoi2007]Tree 园丁的烦恼 [树状数组 离线 离散化]

    传送门 刚才我还在郁闷网上怎么没人用$CDQ$分治做 突然发现根本没有时间序.... #include<iostream> #include<cstdio> #include& ...

  8. 【转】Android UI 五种布局

    在一个Android应用中,Layout是开发中的一个很重要环节,Layout是组成UI不可缺少的一部分. ## Android UI 核心类 在Android应用构建UI的方法有以下几种: 单纯使用 ...

  9. python学习1:程序元素和基本使用方法(跟随mooc学习)

    程序元素: 注释,缩进,变量,常量,表达式 输入,输出,分支,循环 示例程序,温度转换程序: #TempConvert.pyval=input("请输入带温度表示符号发温度值(例如:32C) ...

  10. 【南京邮电】maze 迷宫解法

    [南京邮电]maze 迷宫解法 题目来源:南京邮电大学网络攻防训练平台. 题目下载地址:https://pan.baidu.com/s/1i5gLzIt (密码rijss) 0x0 初步分析 题目中给 ...