ImageProvider.cpp 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. #include "ImageProvider.h"
  2. #include <QDebug>
  3. ImageProvider::ImageProvider()
  4. : QQuickImageProvider(QQuickImageProvider::Image) {}
  5. QImage ImageProvider::requestImage(const QString &, QSize *,
  6. const QSize &) {
  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. if (pBuffer == nullptr)
  47. {
  48. // m_image.fill(Qt::GlobalColor::transparent);
  49. return;
  50. }
  51. std::lock_guard<std::mutex> l(buffer_lock_);
  52. m_pImgProvider->img = QImage(pBuffer.get(), 1280, 720, QImage::Format_RGB32);
  53. switch (campos)
  54. {
  55. case RenderPosition::FRONT:
  56. sendFrontImage();
  57. //qDebug() << "11111111111111111";
  58. break;
  59. case RenderPosition::LEFT:
  60. sendLeftImage();
  61. //qDebug() << "222222222222222222222222";
  62. break;
  63. case RenderPosition::RIGHT:
  64. sendRightImage();
  65. //qDebug() << "33333333333333333333333333333333";
  66. break;
  67. case RenderPosition::BACK:
  68. sendBackImage();
  69. //qDebug() << "44444444444444444444444444444444444444";
  70. break;
  71. case RenderPosition::LANCHOR:
  72. sendLeftAnchor();
  73. //qDebug() << "5555555555555555555555555555555555555555555555555";
  74. break;
  75. case RenderPosition::RANCHOR:
  76. sendRightAnchor();
  77. //qDebug() << "666666666666666666666666666666666666666666666666666666666666666666666666666";
  78. break;
  79. }
  80. }
  81. void ShowImage::Empty()
  82. {
  83. if (m_pImgProvider != nullptr)
  84. {
  85. //QColor bmpBackA(0, 0, 0, 0);
  86. m_pImgProvider->img = QImage((uint8_t*)NULL, 1280, 720, QImage::Format_RGB32);
  87. switch (campos)
  88. {
  89. case RenderPosition::FRONT:
  90. sendFrontImage();
  91. break;
  92. case RenderPosition::LEFT:
  93. sendLeftImage();
  94. break;
  95. case RenderPosition::RIGHT:
  96. sendRightImage();
  97. break;
  98. case RenderPosition::BACK:
  99. sendBackImage();
  100. break;
  101. case RenderPosition::LANCHOR:
  102. sendLeftAnchor();
  103. break;
  104. case RenderPosition::RANCHOR:
  105. sendRightAnchor();
  106. break;
  107. }
  108. }
  109. }