CImageBasis.h 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  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_image.h"
  10. #include "stb_image_write.h"
  11. #include "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. void memCopy(uint8_t* _source, uint8_t* _target, int _size);
  24. bool isInImage(int x, int y);
  25. bool islocked;
  26. public:
  27. uint8_t* rgb_image;
  28. int channels;
  29. int width, height, bpp;
  30. uint8_t * RGBImageLock(int _waitmaxsec = 60);
  31. void RGBImageRelease();
  32. uint8_t * RGBImageGet();
  33. int getWidth(){return this->width;};
  34. int getHeight(){return this->height;};
  35. int getChannels(){return this->channels;};
  36. void drawRect(int x, int y, int dx, int dy, int r = 255, int g = 255, int b = 255, int thickness = 1);
  37. void drawLine(int x1, int y1, int x2, int y2, int r, int g, int b, int thickness = 1);
  38. void drawCircle(int x1, int y1, int rad, int r, int g, int b, int thickness = 1);
  39. void drawEllipse(int x1, int y1, int radx, int rady, int r, int g, int b, int thickness = 1);
  40. void setPixelColor(int x, int y, int r, int g, int b);
  41. void Contrast(float _contrast);
  42. bool ImageOkay();
  43. bool CopyFromMemory(uint8_t* _source, int _size);
  44. void SetIndepended(){externalImage = false;};
  45. void CreateEmptyImage(int _width, int _height, int _channels);
  46. void EmptyImage();
  47. CImageBasis();
  48. CImageBasis(std::string _image);
  49. CImageBasis(uint8_t* _rgb_image, int _channels, int _width, int _height, int _bpp);
  50. CImageBasis(int _width, int _height, int _channels);
  51. CImageBasis(CImageBasis *_copyfrom);
  52. void Resize(int _new_dx, int _new_dy);
  53. void Resize(int _new_dx, int _new_dy, CImageBasis *_target);
  54. void LoadFromMemory(stbi_uc *_buffer, int len);
  55. ImageData* writeToMemoryAsJPG(const int quality = 90);
  56. void writeToMemoryAsJPG(ImageData* ii, const int quality = 90);
  57. esp_err_t SendJPGtoHTTP(httpd_req_t *req, const int quality = 90);
  58. uint8_t GetPixelColor(int x, int y, int ch);
  59. ~CImageBasis();
  60. void SaveToFile(std::string _imageout);
  61. };
  62. #endif //CIMAGEBASIS_H