From cc9552c7431c89879edce144c423595095868e8c Mon Sep 17 00:00:00 2001 From: Apex Liu Date: Wed, 4 Sep 2019 20:28:16 +0800 Subject: [PATCH] .temp. --- client/tp-player/mainwindow.cpp | 79 ++++++++++++++++++++++++++++----- client/tp-player/mainwindow.h | 3 +- client/tp-player/thr_play.cpp | 2 +- 3 files changed, 72 insertions(+), 12 deletions(-) diff --git a/client/tp-player/mainwindow.cpp b/client/tp-player/mainwindow.cpp index 1410c6f..e04bf28 100644 --- a/client/tp-player/mainwindow.cpp +++ b/client/tp-player/mainwindow.cpp @@ -6,6 +6,7 @@ #include #include #include +#include bool rdpimg2QImage(QImage& out, int w, int h, int bitsPerPixel, bool isCompressed, uint8_t* dat, uint32_t len) { switch(bitsPerPixel) { @@ -43,8 +44,24 @@ bool rdpimg2QImage(QImage& out, int w, int h, int bitsPerPixel, bool isCompresse // fflush(stdout); // } + //out = QImage(_dat, w, h, QImage::Format_RGB16); + + static bool bf = true; + if(bf) { + bf = false; + int total_bytes = w*h*2; + if(total_bytes == 32) { + uchar aaa[32] = {0x00, 0x00, 0x00, 0xff, 0x00, 0x00, 0x00, 0xff, 0x00, 0x00, 0x00, 0xff, 0x00, 0x00, 0x00, 0xff, 0x00, 0x00, 0x00, 0xff, 0x00, 0x00, 0x00, 0xff, 0x00, 0x00, 0x00, 0xff, 0x00, 0x00, 0x00, 0xff}; + memcpy(_dat, aaa, 32); + } + } + out = QImage(_dat, w, h, QImage::Format_RGB16); free(_dat); + +// QPixmap x(w, h); +// x.fill(QColor(0,0,0)); +// out = x.toImage(); } else { out = QImage(dat, w, h, QImage::Format_RGB16).transformed(QMatrix(1.0, 0.0, 0.0, -1.0, 0.0, 0.0)) ; @@ -71,6 +88,7 @@ MainWindow::MainWindow(QWidget *parent) : m_bg = QImage(":/tp-player/res/bg"); m_pt_normal = QImage(":/tp-player/res/cursor.png"); m_update_img = false; + memset(&m_pt, 0, sizeof(TS_RECORD_RDP_POINTER)); qDebug() << m_pt_normal.width() << "x" << m_pt_normal.height(); @@ -86,6 +104,9 @@ MainWindow::MainWindow(QWidget *parent) : // setWindowFlags(Qt::FramelessWindowHint | Qt::MSWindowsFixedSizeDialogHint | windowFlags()); //#endif //__APPLE__ + //m_canvas = QPixmap(m_bg.width(), m_bg.height()); + m_canvas.load(":/tp-player/res/bg"); + resize(m_bg.width(), m_bg.height()); setWindowFlags(windowFlags()&~Qt::WindowMaximizeButtonHint); // 禁止最大化按钮 @@ -101,26 +122,36 @@ MainWindow::~MainWindow() delete ui; } -void MainWindow::paintEvent(QPaintEvent *) +void MainWindow::paintEvent(QPaintEvent *pe) { QPainter painter(this); if(m_show_bg) { //qDebug() << "draw bg."; - painter.setBrush(Qt::black); - painter.drawRect(this->rect()); +// painter.setBrush(Qt::black); +// painter.drawRect(this->rect()); - int x = (rect().width() - m_bg.width()) / 2; - int y = (rect().height() - m_bg.height()) / 2; - painter.drawImage(x, y, m_bg); - //painter.drawPixmap(rect(), m_bg1); +// int x = (rect().width() - m_bg.width()) / 2; +// int y = (rect().height() - m_bg.height()) / 2; +// painter.drawImage(x, y, m_bg); + + painter.drawPixmap(rect(), m_canvas); } else { - if(m_update_img) - painter.drawImage(m_img_update_x, m_img_update_y, m_img_update, 0, 0, m_img_update_w, m_img_update_h, Qt::AutoColor); - else + painter.drawPixmap(rect(), m_canvas); + +// if(m_update_img) +// painter.drawImage(m_img_update_x, m_img_update_y, m_img_update, 0, 0, m_img_update_w, m_img_update_h, Qt::AutoColor); +// else //qDebug() << "draw pt (" << m_pt.x << "," << m_pt.y << ")"; +// painter.drawImage(m_pt.x, m_pt.y, m_pt_normal); + + QRect rcpt(m_pt_normal.rect()); + rcpt.moveTo(m_pt.x - m_pt_normal.width()/2, m_pt.y-m_pt_normal.height()/2); + QRect rcpe(pe->rect()); + + if(pe->rect().intersects(rcpt)) painter.drawImage(m_pt.x, m_pt.y, m_pt_normal); } @@ -171,6 +202,30 @@ void MainWindow::on_update_data(update_data* dat) { uint32_t img_len = dat->data_len() - sizeof(TS_RECORD_PKG) - sizeof(TS_RECORD_RDP_IMAGE_INFO); rdpimg2QImage(m_img_update, info->width, info->height, info->bitsPerPixel, (info->format == TS_RDP_IMG_BMP) ? true : false, img_dat, img_len); + + static bool need_save = true; + if(need_save) { + need_save = false; + m_img_update.save("E:\\work\\tp4a\\teleport\\server\\share\\replay\\rdp\\000000197\\test.bmp", "BMP"); + + uchar* xx = m_img_update.bits(); + int total_bytes = m_img_update.width()*m_img_update.height()*2; + for(int i = 0; i < total_bytes; i++) { + printf("%02x ", xx[i]); + if(i != 0 && i % 16 == 0) + printf("\n"); + } + fflush(stdout); + + } + + + + QPainter pp(&m_canvas); + pp.drawImage(m_img_update_x, m_img_update_y, m_img_update, 0, 0, m_img_update_w, m_img_update_h, Qt::AutoColor); + + + m_img_update_x = info->destLeft; m_img_update_y = info->destTop; m_img_update_w = info->destRight - info->destLeft + 1; @@ -200,6 +255,10 @@ void MainWindow::on_update_data(update_data* dat) { qDebug() << "resize (" << m_rec_hdr.basic.width << "," << m_rec_hdr.basic.height << ")"; if(m_rec_hdr.basic.width > 0 && m_rec_hdr.basic.height > 0) { + + m_canvas = QPixmap(m_rec_hdr.basic.width, m_rec_hdr.basic.height); + + m_win_board_w = frameGeometry().width() - geometry().width(); m_win_board_h = frameGeometry().height() - geometry().height(); diff --git a/client/tp-player/mainwindow.h b/client/tp-player/mainwindow.h index ffde816..d1bcc28 100644 --- a/client/tp-player/mainwindow.h +++ b/client/tp-player/mainwindow.h @@ -28,11 +28,12 @@ private slots: private: Ui::MainWindow *ui; QImage m_bg; - //QPixmap m_bg1; bool m_shown; ThreadPlay m_thr_play; + QPixmap m_canvas; + bool m_show_bg; TS_RECORD_HEADER m_rec_hdr; diff --git a/client/tp-player/thr_play.cpp b/client/tp-player/thr_play.cpp index 6f5b64f..4c0ce8c 100644 --- a/client/tp-player/thr_play.cpp +++ b/client/tp-player/thr_play.cpp @@ -82,6 +82,6 @@ void ThreadPlay::run() { } emit signal_update_data(dat); - msleep(5); + msleep(10); } }