CImageBasis.h 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. #pragma once
  2. #ifndef __CIMAGEBASIS
  3. #define __CIMAGEBASIS
  4. #include <stdint.h>
  5. #include <string>
  6. #include <esp_http_server.h>
  7. #define _USE_MATH_DEFINES
  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. //#define GET_MEMORY malloc
  14. #define GET_MEMORY(X) heap_caps_malloc(X, MALLOC_CAP_SPIRAM)
  15. #define MAX_JPG_SIZE 128000
  16. struct ImageData
  17. {
  18. uint8_t data[MAX_JPG_SIZE];
  19. size_t size = 0;
  20. };
  21. class CImageBasis
  22. {
  23. protected:
  24. bool externalImage;
  25. std::string filename;
  26. void memCopy(uint8_t* _source, uint8_t* _target, int _size);
  27. bool isInImage(int x, int y);
  28. public:
  29. uint8_t* rgb_image;
  30. int channels;
  31. int width, height, bpp;
  32. int getWidth(){return this->width;};
  33. int getHeight(){return this->height;};
  34. int getChannels(){return this->channels;};
  35. void drawRect(int x, int y, int dx, int dy, int r = 255, int g = 255, int b = 255, int thickness = 1);
  36. void drawLine(int x1, int y1, int x2, int y2, int r, int g, int b, int thickness = 1);
  37. void drawCircle(int x1, int y1, int rad, int r, int g, int b, int thickness = 1);
  38. void setPixelColor(int x, int y, int r, int g, int b);
  39. void Contrast(float _contrast);
  40. bool ImageOkay();
  41. bool CopyFromMemory(uint8_t* _source, int _size);
  42. void SetIndepended(){externalImage = false;};
  43. void CreateEmptyImage(int _width, int _height, int _channels);
  44. CImageBasis();
  45. CImageBasis(std::string _image);
  46. CImageBasis(uint8_t* _rgb_image, int _channels, int _width, int _height, int _bpp);
  47. CImageBasis(int _width, int _height, int _channels);
  48. CImageBasis(CImageBasis *_copyfrom);
  49. void Resize(int _new_dx, int _new_dy);
  50. void Resize(int _new_dx, int _new_dy, CImageBasis *_target);
  51. void LoadFromMemory(stbi_uc *_buffer, int len);
  52. ImageData* writeToMemoryAsJPG(const int quality = 90);
  53. esp_err_t SendJPGtoHTTP(httpd_req_t *req, const int quality = 90);
  54. uint8_t GetPixelColor(int x, int y, int ch);
  55. ~CImageBasis();
  56. void SaveToFile(std::string _imageout);
  57. };
  58. #endif