ImageProvider.cpp 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. #include "ImageProvider.h"
  2. #include <QDebug>
  3. ImageProvider::ImageProvider()
  4. : QQuickImageProvider(QQuickImageProvider::Image) {}
  5. QImage ImageProvider::requestImage(const QString&, QSize*,const QSize&)
  6. {
  7. return this->img;
  8. }
  9. QPixmap ImageProvider::requestPixmap(const QString&, QSize*,
  10. const QSize&) {
  11. return QPixmap::fromImage(this->img);
  12. }
  13. ShowImage::ShowImage(QObject* parent, RenderPosition _pos) : QObject(parent) {
  14. campos = _pos;
  15. m_pImgProvider = new ImageProvider();
  16. }
  17. void ShowImage::sendFrontImage() {
  18. emit callQmlRefeshFrontImg();
  19. }
  20. void ShowImage::sendBackImage() {
  21. emit callQmlRefeshBackImg();
  22. }
  23. void ShowImage::sendLeftImage() {
  24. // m_pImgProvider->img = image;// .mirrored(true, false);
  25. emit callQmlRefeshLeftImg();
  26. }
  27. void ShowImage::sendRightImage() {
  28. // m_pImgProvider->img = image;//.mirrored(true, false);
  29. emit callQmlRefeshRightImg();
  30. }
  31. void ShowImage::sendLeftAnchor() {
  32. // m_pImgProvider->img = image;
  33. emit callQmlRefeshLeftAnchor();
  34. }
  35. void ShowImage::sendRightAnchor()
  36. {
  37. // m_pImgProvider->img = image;
  38. emit callQmlRefeshRightAnchor();
  39. }
  40. // void ShowImage::sendPanelImage(QImage sendimage) {
  41. // m_pImgProvider->img = sendimage;
  42. // emit callQmlRefeshPanelImg();
  43. //}
  44. void ShowImage::OnRender(std::unique_ptr<uint8_t>& pBuffer, int32_t,
  45. int32_t) {
  46. //qDebug() <<&pBuffer;
  47. if (pBuffer == nullptr)
  48. {
  49. // m_image.fill(Qt::GlobalColor::transparent);
  50. return;
  51. }
  52. std::lock_guard<std::mutex> l(buffer_lock_);
  53. //m_pImgProvider->img = QImage(pBuffer.get(), 1920, 1080, QImage::Format_RGB32);
  54. //m_pImgProvider->img = QImage(pBuffer.get(), 1280, 720, QImage::Format_RGB32);
  55. m_pImgProvider->img = QImage(pBuffer.get(), 1080, 640, QImage::Format_RGB32);
  56. switch (campos)
  57. {
  58. case RenderPosition::FRONT:
  59. //m_CountF++;
  60. //if (m_CountF % 3 == 0)
  61. {
  62. sendFrontImage();
  63. //qDebug() << "====·¢ËÍ1/3ÊÓƵ" << "=======";
  64. }
  65. break;
  66. case RenderPosition::LEFT:
  67. sendLeftImage();
  68. break;
  69. case RenderPosition::RIGHT:
  70. sendRightImage();
  71. break;
  72. case RenderPosition::BACK:
  73. sendBackImage();
  74. break;
  75. case RenderPosition::LANCHOR:
  76. sendLeftAnchor();
  77. break;
  78. case RenderPosition::RANCHOR:
  79. sendRightAnchor();
  80. break;
  81. }
  82. }
  83. void ShowImage::Empty()
  84. {
  85. if (m_pImgProvider != nullptr)
  86. {
  87. //QColor bmpBackA(0, 0, 0, 0);
  88. //m_pImgProvider->img = QImage((uint8_t*)NULL, 1280, 720, QImage::Format_RGB32);
  89. //m_pImgProvider->img = QImage((uint8_t*)NULL, 1920, 1080, QImage::Format_RGB32);
  90. m_pImgProvider->img = QImage((uint8_t*)NULL, 1080, 640, QImage::Format_RGB32);
  91. switch (campos)
  92. {
  93. case RenderPosition::FRONT:
  94. sendFrontImage();
  95. break;
  96. case RenderPosition::LEFT:
  97. sendLeftImage();
  98. break;
  99. case RenderPosition::RIGHT:
  100. sendRightImage();
  101. break;
  102. case RenderPosition::BACK:
  103. sendBackImage();
  104. break;
  105. case RenderPosition::LANCHOR:
  106. sendLeftAnchor();
  107. break;
  108. case RenderPosition::RANCHOR:
  109. sendRightAnchor();
  110. break;
  111. }
  112. }
  113. }