ScreenshotObj.hpp 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. /******************************************************************************
  2. Copyright (C) 2023 by Lain Bailey <[email protected]>
  3. Copyright (C) 2025 by Taylor Giampaolo <[email protected]>
  4. This program is free software: you can redistribute it and/or modify
  5. it under the terms of the GNU General Public License as published by
  6. the Free Software Foundation, either version 2 of the License, or
  7. (at your option) any later version.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. GNU General Public License for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with this program. If not, see <http://www.gnu.org/licenses/>.
  14. ******************************************************************************/
  15. #pragma once
  16. #include <obs.hpp>
  17. #include <QImage>
  18. #include <QObject>
  19. #include <thread>
  20. class ScreenshotObj : public QObject {
  21. Q_OBJECT
  22. public:
  23. ScreenshotObj(obs_source_t *source);
  24. ~ScreenshotObj() override;
  25. enum class Stage { Render, Download, Output, Finished };
  26. void processStage();
  27. void renderScreenshot();
  28. void downloadData();
  29. void copyData();
  30. void saveToFile();
  31. void muxFile();
  32. void onFinished();
  33. Stage stage() { return stage_; }
  34. void setStage(Stage stage) { stage_ = stage; }
  35. void setSize(QSize size);
  36. void setSize(int width, int height);
  37. void setSaveToFile(bool save);
  38. private:
  39. Stage stage_ = Stage::Render;
  40. gs_texrender_t *texrender = nullptr;
  41. gs_stagesurf_t *stagesurf = nullptr;
  42. OBSWeakSource weakSource;
  43. std::string path;
  44. QImage image;
  45. std::vector<uint8_t> half_bytes;
  46. QSize customSize;
  47. uint32_t sourceWidth = 0;
  48. uint32_t sourceHeight = 0;
  49. uint32_t outputWidth = 0;
  50. uint32_t outputHeight = 0;
  51. std::thread th;
  52. std::shared_ptr<QImage> imagePtr;
  53. bool outputToFile = true;
  54. signals:
  55. void imageReady(QImage image);
  56. private slots:
  57. void handleSave();
  58. };