⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 convideo.cpp

📁 英特尔&#174 线程构建模块(英特尔&#174 TBB)是一个屡获殊荣的 C++ 运行时库
💻 CPP
字号:
/*    Copyright 2005-2007 Intel Corporation.  All Rights Reserved.    This file is part of Threading Building Blocks.    Threading Building Blocks is free software; you can redistribute it    and/or modify it under the terms of the GNU General Public License    version 2 as published by the Free Software Foundation.    Threading Building Blocks is distributed in the hope that it will be    useful, but WITHOUT ANY WARRANTY; without even the implied warranty    of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the    GNU General Public License for more details.    You should have received a copy of the GNU General Public License    along with Threading Building Blocks; if not, write to the Free Software    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA    As a special exception, you may use this file as part of a free software    library without restriction.  Specifically, if other files instantiate    templates or use macros or inline functions from this file, or you compile    this file and link it with other files to produce an executable, this    file does not by itself cause the resulting executable to be covered by    the GNU General Public License.  This exception does not however    invalidate any other reasons why the executable file might be covered by    the GNU General Public License.*/#include "video.h"#include <cassert>#include <stdio.h>unsigned int *              g_pImg = 0;int                         g_sizex, g_sizey;static video *g_video = 0;static int g_fps = 0;#if _WIN32 || _WIN64static DWORD g_msec = 0;#ifdef _WINDOWSHINSTANCE video::win_hInstance = 0;int video::win_iCmdShow = 0;void video::win_set_class(WNDCLASSEX &wcex){}void video::win_load_accelerators(int idc){}#endif#elif __linux__ || __APPLE__#include <sched.h>#include <sys/time.h>struct timeval g_time;#endifvideo::video()    : red_mask(0xff0000), red_shift(16), green_mask(0xff00),      green_shift(8), blue_mask(0xff), blue_shift(0), depth(24){    assert(g_video == 0);    g_video = this; title = "Video"; updating = calc_fps = false;}bool video::init_window(int x, int y){    g_sizex = x; g_sizey = y;    g_pImg = new unsigned int[x*y];    running = true;    return false;}bool video::init_console(){    running = true;    return true;}void video::terminate(){    if(calc_fps) {        double fps = g_fps;#if _WIN32 || _WIN64        fps /= (GetTickCount()-g_msec)/1000.0;#else        struct timezone tz; struct timeval end_time; gettimeofday(&end_time, &tz);        fps /= (end_time.tv_sec+1.0*end_time.tv_usec/1000000.0) - (g_time.tv_sec+1.0*g_time.tv_usec/1000000.0);#endif        printf("%s: %.1f fps\n", title, fps);  	}    g_video = 0; running = false;    if(g_pImg) { delete[] g_pImg; g_pImg = 0; }}video::~video(){    if(g_video) terminate();}//! Count and display FPS count in titlebarbool video::next_frame(){	if(!g_fps) {#if _WIN32 || _WIN64        g_msec = GetTickCount();#else        struct timezone tz; gettimeofday(&g_time, &tz);#endif	}    g_fps++;    return running;}//! Do standart loopvoid video::main_loop(){    on_process();}//! Change window titlevoid video::show_title(){}///////////////////////////////////////////// public methods of video class ///////////////////////drawing_area::drawing_area(int x, int y, int sizex, int sizey)    : start_x(x), start_y(y), size_x(sizex), size_y(sizey), pixel_depth(24),    base_index(y*g_sizex + x), max_index(g_sizex*g_sizey), index_stride(g_sizex), ptr32(g_pImg){    assert(x < g_sizex); assert(y < g_sizey);    assert(x+sizex <= g_sizex); assert(y+sizey <= g_sizey);    index = base_index; // current index}drawing_area::~drawing_area() {}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -