CImageBasis.h 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  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. bool islocked;
  29. public:
  30. uint8_t* rgb_image;
  31. int channels;
  32. int width, height, bpp;
  33. uint8_t * RGBImageLock(int _waitmaxsec = 60);
  34. void RGBImageRelease();
  35. uint8_t * RGBImageGet();
  36. int getWidth(){return this->width;};
  37. int getHeight(){return this->height;};
  38. int getChannels(){return this->channels;};
  39. void drawRect(int x, int y, int dx, int dy, int r = 255, int g = 255, int b = 255, int thickness = 1);
  40. void drawLine(int x1, int y1, int x2, int y2, int r, int g, int b, int thickness = 1);
  41. void drawCircle(int x1, int y1, int rad, int r, int g, int b, int thickness = 1);
  42. void drawEllipse(int x1, int y1, int radx, int rady, int r, int g, int b, int thickness = 1);
  43. void setPixelColor(int x, int y, int r, int g, int b);
  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. CImageBasis();
  50. CImageBasis(std::string _image);
  51. CImageBasis(uint8_t* _rgb_image, int _channels, int _width, int _height, int _bpp);
  52. CImageBasis(int _width, int _height, int _channels);
  53. CImageBasis(CImageBasis *_copyfrom, int _anzrepeat = 0);
  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. esp_err_t SendJPGtoHTTP(httpd_req_t *req, const int quality = 90);
  59. uint8_t GetPixelColor(int x, int y, int ch);
  60. ~CImageBasis();
  61. void SaveToFile(std::string _imageout);
  62. };
  63. #endif