SDL視窗拉伸時顯示YUV

2021-09-27 06:39:08 字數 3287 閱讀 9203

(本部落格旨在個人總結回顧)

本例子是在雷神的sdl例子基礎上改的,發現雷神的例子上實現yuv資料顯示時進行視窗拉伸,發現顯示異常。

效果:

關鍵原始碼:

// testsdl.cpp : 定義控制台應用程式的入口點。

//#include "stdafx.h"

#ifdef __cplusplus

extern "c"

;#endif

#pragma comment(lib, "sdl2.lib")

#pragma comment(lib, "sdl2main.lib")

//refresh event

#define refresh_event (sdl_userevent + 1)

//break

#define break_event (sdl_userevent + 2)

int g_ntheadexit = 0;

bool g_bresize = false;

sdl_mutex* g_psdlmutex = sdl_createmutex();

sdl_window* g_pscreen = null;

struct threaddata

;int refreshvideo(void* popaque)

while (0 == g_ntheadexit)

if (fread(buffer, 1, npixelwidth*npixelheight*nbpp / 8, pfile) != npixelwidth*npixelheight*nbpp / 8)

sdl_getwindowsize(psdlthreaddate->psdlwindow, &nscreenwidth, &nscreenheight);

//sdl_setwindowsize(psdlthreaddate->psdlwindow, nscreenwidth, nscreenheight);

//設定紋理資料

int ret = sdl_updatetexture(psdlthreaddate->psdltexture, null, buffer, npixelwidth);

ret = sdl_renderclear(psdlthreaddate->psdlrenderer);

sdl_rect sdlrect;

sdlrect.x = 0;

sdlrect.y = 0;

sdlrect.w = 640;

sdlrect.h = 360;

cout << nscreenwidth << "x" << nscreenheight << endl;

//將紋理拷貝給渲染器

ret = sdl_rendercopy(psdlthreaddate->psdlrenderer, psdlthreaddate->psdltexture, null, &sdlrect);

//cout << __line__ << endl;

//顯示

sdl_renderpresent(psdlthreaddate->psdlrenderer);

sdl_unlockmutex(psdlthreaddate->psdlmutex);

cout << "refresh video!" << endl;

sdl_event sdlevent;

sdlevent.type = refresh_event;

sdl_pushevent(&sdlevent);

}g_ntheadexit = 0;

sdl_event tmpsdlevent;

tmpsdlevent.type = break_event;

sdl_pushevent(&tmpsdlevent);

return 0;

}int mysdleventfilter(void *userdata, sdl_event * event)

}return 1;

}int _tmain(int argc, _tchar* ar**)

sdl_seteventfilter(mysdleventfilter, null);

//建立視窗

g_pscreen = sdl_createwindow("******st video play sdl2", sdl_windowpos_undefined, sdl_windowpos_undefined,

nscreenwidth, nscreenheight, sdl_window_resizable);

if (!g_pscreen)

//建立渲染器

sdl_renderer* psdlrenderer = sdl_createrenderer(g_pscreen, -1, 0);

uint32 unpixformat = 0;

//iyuv: y + u + v (3 planes)

//yv12: y + v + u (3 planes)

unpixformat = sdl_pixelformat_iyuv;

//建立紋理

sdl_texture* psdltexture = sdl_createtexture(psdlrenderer, unpixformat, sdl_textureaccess_streaming, npixelwidth, npixelheight);

threaddata threaddate;

threaddate.psdlwindow = g_pscreen;

threaddate.psdltexture = psdltexture;

threaddate.psdlrenderer = psdlrenderer;

threaddate.psdlmutex = g_psdlmutex;

sdl_thread* prefreshthread = sdl_createthread(refreshvideo, null, &threaddate);

sdl_event sdlevent;

while (true)

}sdl_destroywindow(g_pscreen);

sdl_destroyrenderer(psdlrenderer);

sdl_destroytexture(psdltexture);

sdl_destroymutex(g_psdlmutex);

sdl_quit();

return 0;

}

上傳檔案時顯示選擇視窗

上載檔案時 需要選擇視窗 兩種實現方式 parameter p file type ibipparms path default c users pc desktop 上傳模板.xlsx 第一種 at selection screen on value request for p file.call...

SDL附著window視窗的方法

網上很多 介紹sdl的用法,主要需要注意的情況有3種 char sdl var 128 sprintf sdl var,sdl windowid 0x lx m hwnd 主視窗控制代碼 sdl putenv sdl var char myvalue sdl getenv sdl windowid ...

視窗顯示時讓字段獲得焦點

這是ext群裡一位大蝦提供的解決方案。通常情況下,在視窗顯示時,也就是在視窗的show事件中,直接使用focus方法讓字段獲得焦點,會因為瀏覽器內部處理而丟失焦點。解決辦法就是延遲執行focus,在api中,ext.form.field.base的focus方法的說明如下 focus boolean...