zoukankan      html  css  js  c++  java
  • sdl 画yuv

    #include <stdlib.h>
    #include <stdio.h>
    #include <math.h>
    
    #include "SDL.h"
    #include "CGSdlRender.h"
    using namespace ChunGen::Client::Player;
    int width = 1280;
    int height = 720;
    
    
    int frame_size_y = width * height;
    int frame_size_uv = ((width + 1) >> 1) * ((height + 1) >> 1);
    int frame_size = frame_size_y + 2 * frame_size_uv;
    char buf[1280 * 720 * 2] = { 0 };//实际用不了这么多
    
    int
    main(int argc, char* argv[]) {
    
        std::shared_ptr<CGSDLRender> sdlRender = std::make_shared<CGSDLRender>();
        sdlRender->InitVideo(0);
        sdlRender->CreateVideoSurface(width, height);
    
        int mSize = frame_size;
        BYTE* data[3] = { NULL };
        int linesize[5] = { 1280,640,640,0,0 };
        int color = 0;
    
        data[0] = (BYTE*)buf;
        data[1] = (BYTE*)(buf + frame_size_y);
        data[2] = (BYTE*)(buf + frame_size_y + frame_size_uv);
        memset(data[1], 128, frame_size_y);
        while (color <25 ) {
            //mSize = fread(buf, frame_size, 1, f);
            memset(buf,color*10, frame_size_y);
            color++;
    
            sdlRender->Display((uint8_t**)data, linesize);
            SDL_Delay(500);
            printf("myplay --%d\n",color);
        };
    
        return 0;
    }

    比如画正弦波形

        data[0] = (BYTE*)buf;
        data[1] = (BYTE*)(buf + frame_size_y);
        data[2] = (BYTE*)(buf + frame_size_y + frame_size_uv);
        memset(buf,0, frame_size_y);
        memset(data[1], 128, frame_size_y);
        
        for (int j = 0; j < 720; j++) {
            for (int i = 0; i < 1280; i++) {
              
                if (j < 240 - 240 * sin(3.14 * i / 180))
                    buf[j * 1280 + i] = 255;
                else
                    buf[j * 1280 + i] = 0;
            }
        }

    sdl  mac---

  • 相关阅读:
    取一定范围的随机数
    小菜学Chromium之OpenGL学习之二
    程序员健康之路
    解密硬件解码关键技术
    Android 图片开发内幕系列第一篇
    你所不知道的html5与html中的那些事第三篇
    如何加密android apk
    linux设备驱动第五篇:驱动中的并发与竟态
    快速调试chromium
    小菜鸟带着梦想学chromium
  • 原文地址:https://www.cnblogs.com/cnchengv/p/15799423.html
Copyright © 2011-2022 走看看