CImageBasis.h 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. #pragma once
  2. #ifndef CIMAGEBASIS_H
  3. #define CIMAGEBASIS_H
  4. #include <stdint.h>
  5. #include <string>
  6. #include <esp_http_server.h>
  7. #include "../../include/defines.h"
  8. #include <math.h>
  9. #include "../stb/stb_image.h"
  10. #include "../stb/stb_image_write.h"
  11. #include "../stb/stb_image_resize.h"
  12. #include "esp_heap_caps.h"
  13. struct ImageData
  14. {
  15. uint8_t data[MAX_JPG_SIZE];
  16. size_t size = 0;
  17. };
  18. class CImageBasis
  19. {
  20. protected:
  21. bool externalImage;
  22. std::string filename;
  23. std::string name; // Just used for diagnostics
  24. int memsize = 0;
  25. void memCopy(uint8_t* _source, uint8_t* _target, int _size);
  26. bool isInImage(int x, int y);
  27. bool islocked;
  28. public:
  29. uint8_t* rgb_image = NULL;
  30. int channels;
  31. int width, height, bpp;
  32. uint8_t * RGBImageLock(int _waitmaxsec = 60);
  33. void RGBImageRelease();
  34. uint8_t * RGBImageGet();
  35. int getWidth(){return this->width;};
  36. int getHeight(){return this->height;};
  37. int getChannels(){return this->channels;};
  38. void drawRect(int x, int y, int dx, int dy, int r = 255, int g = 255, int b = 255, int thickness = 1);
  39. void drawLine(int x1, int y1, int x2, int y2, int r, int g, int b, int thickness = 1);
  40. void drawCircle(int x1, int y1, int rad, int r, int g, int b, int thickness = 1);
  41. void drawEllipse(int x1, int y1, int radx, int rady, int r, int g, int b, int thickness = 1);
  42. void setPixelColor(int x, int y, int r, int g, int b);
  43. void Contrast(float _contrast);
  44. bool ImageOkay();
  45. bool CopyFromMemory(uint8_t* _source, int _size);
  46. void SetIndepended(){externalImage = false;};
  47. void CreateEmptyImage(int _width, int _height, int _channels);
  48. void EmptyImage();
  49. CImageBasis(std::string name);
  50. CImageBasis(std::string name, std::string _image);
  51. CImageBasis(std::string name, uint8_t* _rgb_image, int _channels, int _width, int _height, int _bpp);
  52. CImageBasis(std::string name, int _width, int _height, int _channels);
  53. CImageBasis(std::string name, CImageBasis *_copyfrom);
  54. void Resize(int _new_dx, int _new_dy);
  55. void Resize(int _new_dx, int _new_dy, CImageBasis *_target);
  56. void LoadFromMemory(stbi_uc *_buffer, int len);
  57. ImageData* writeToMemoryAsJPG(const int quality = 90);
  58. void writeToMemoryAsJPG(ImageData* ii, const int quality = 90);
  59. esp_err_t SendJPGtoHTTP(httpd_req_t *req, const int quality = 90);
  60. uint8_t GetPixelColor(int x, int y, int ch);
  61. ~CImageBasis();
  62. void SaveToFile(std::string _imageout);
  63. };
  64. #endif //CIMAGEBASIS_H