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---

  • 相关阅读:
    【项目】项目75
    【项目】项目74
    【项目】项目73
    【项目】项目72
    【项目】项目71
    【项目】项目70
    【项目】项目69
    【项目】项目68
    【项目】项目67
    .Net随笔:解决VS2008,重新生成解决方案,很慢
  • 原文地址:https://www.cnblogs.com/cnchengv/p/15799423.html
Copyright © 2011-2022 走看看