ImageProvider.cpp 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  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. break;
  58. case RenderPosition::LEFT:
  59. sendLeftImage();
  60. break;
  61. case RenderPosition::RIGHT:
  62. sendRightImage();
  63. break;
  64. case RenderPosition::BACK:
  65. sendBackImage();
  66. break;
  67. case RenderPosition::LANCHOR:
  68. sendLeftAnchor();
  69. break;
  70. case RenderPosition::RANCHOR:
  71. sendRightAnchor();
  72. break;
  73. }
  74. }
  75. void ShowImage::Empty()
  76. {
  77. if (m_pImgProvider != nullptr)
  78. {
  79. //QColor bmpBackA(0, 0, 0, 0);
  80. m_pImgProvider->img = QImage((uint8_t*)NULL, 1280, 720, QImage::Format_RGB32);
  81. switch (campos)
  82. {
  83. case RenderPosition::FRONT:
  84. sendFrontImage();
  85. break;
  86. case RenderPosition::LEFT:
  87. sendLeftImage();
  88. break;
  89. case RenderPosition::RIGHT:
  90. sendRightImage();
  91. break;
  92. case RenderPosition::BACK:
  93. sendBackImage();
  94. break;
  95. case RenderPosition::LANCHOR:
  96. sendLeftAnchor();
  97. break;
  98. case RenderPosition::RANCHOR:
  99. sendRightAnchor();
  100. break;
  101. }
  102. }
  103. }