📄 video.cpp
字号:
#include "video.h"#include <qpainter.h>#include <qimage.h>const int W = 256;const int H = 256;inline unsigned char sat(int c) { return( (c & ~255)? (c<0)?0:255 : c );}void video::fill_yuv() { int tu, tv; unsigned char *p = pRGB->bits(); for (int iv=0; iv<H; ++iv) { for (int iu=0; iu<W; ++iu) { tu = iu - 128; tv = iv - 128; *p = sat(y + ((454*tu)>>8)); // b ++p; *p = sat(y - ((183*tv + 88*tu)>>8)); // g ++p; *p = sat(y + ((359*tv)>>8)); // r p += 2; } }}video::video(): y(128) { setMinimumSize(W, H); setMaximumSize(W, H); setBackgroundMode(Qt::NoBackground); setMouseTracking(true); pRGB = new QImage(W, H, 32, 0); fill_yuv();}void video::paintEvent(QPaintEvent *) { QPainter p(this); p.drawImage(0, 0, *pRGB);}void video::mouseMoveEvent(QMouseEvent *e) { u = e->x(); v = e->y(); if (u < 0 || u >= W || v < 0 || v >= H) { return; } QString s; s.sprintf("%d %d %d", y, u, v); setCaption(s);}void video::keyPressEvent(QKeyEvent *e) { int key = e->ascii(); bool hit = false; switch (key) { case '1': if (y > 0) --y; hit = true; break; case '2': if (y < 255) ++y; hit = true; } if (hit) { fill_yuv(); QString s; s.sprintf("%d %d %d", y, u, v); setCaption(s); update(); }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -