CImageBasis.h 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  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 Negative(void);
  44. void Contrast(float _contrast);
  45. bool ImageOkay();
  46. bool CopyFromMemory(uint8_t* _source, int _size);
  47. void SetIndepended(){externalImage = false;};
  48. void CreateEmptyImage(int _width, int _height, int _channels);
  49. void EmptyImage();
  50. CImageBasis(std::string name);
  51. CImageBasis(std::string name, std::string _image);
  52. CImageBasis(std::string name, uint8_t* _rgb_image, int _channels, int _width, int _height, int _bpp);
  53. CImageBasis(std::string name, int _width, int _height, int _channels);
  54. CImageBasis(std::string name, CImageBasis *_copyfrom);
  55. void Resize(int _new_dx, int _new_dy);
  56. void Resize(int _new_dx, int _new_dy, CImageBasis *_target);
  57. void crop_image(unsigned short cropLeft, unsigned short cropRight, unsigned short cropTop, unsigned short cropBottom);
  58. void LoadFromMemory(stbi_uc *_buffer, int len);
  59. ImageData* writeToMemoryAsJPG(const int quality = 90);
  60. void writeToMemoryAsJPG(ImageData* ii, const int quality = 90);
  61. esp_err_t SendJPGtoHTTP(httpd_req_t *req, const int quality = 90);
  62. uint8_t GetPixelColor(int x, int y, int ch);
  63. ~CImageBasis();
  64. void SaveToFile(std::string _imageout);
  65. };
  66. #endif //CIMAGEBASIS_H