CImageBasis.h 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. #pragma once
  2. #ifndef CIMAGEBASIS_H
  3. #define CIMAGEBASIS_H
  4. #include "defines.h"
  5. #include <string>
  6. #include <math.h>
  7. #include <stdint.h>
  8. #include <esp_http_server.h>
  9. #include "../stb/stb_image.h"
  10. #include "../stb/stb_image_write.h"
  11. #include "../stb/deprecated/stb_image_resize.h"
  12. // #include "../stb/stb_image_resize2.h"
  13. #include "esp_heap_caps.h"
  14. struct ImageData
  15. {
  16. uint8_t data[MAX_JPG_SIZE];
  17. size_t size = 0;
  18. };
  19. class CImageBasis
  20. {
  21. protected:
  22. bool externalImage;
  23. std::string filename;
  24. std::string name; // Just used for diagnostics
  25. int memsize = 0;
  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 = NULL;
  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 Negative(void);
  45. void Contrast(float _contrast);
  46. bool ImageOkay();
  47. bool CopyFromMemory(uint8_t *_source, int _size);
  48. void SetIndepended() { externalImage = false; };
  49. void CreateEmptyImage(int _width, int _height, int _channels);
  50. void EmptyImage();
  51. CImageBasis(std::string name);
  52. CImageBasis(std::string name, std::string _image);
  53. CImageBasis(std::string name, uint8_t *_rgb_image, int _channels, int _width, int _height, int _bpp);
  54. CImageBasis(std::string name, int _width, int _height, int _channels);
  55. CImageBasis(std::string name, CImageBasis *_copyfrom);
  56. void Resize(int _new_dx, int _new_dy);
  57. void Resize(int _new_dx, int _new_dy, CImageBasis *_target);
  58. void crop_image(unsigned short cropLeft, unsigned short cropRight, unsigned short cropTop, unsigned short cropBottom);
  59. void LoadFromMemory(stbi_uc *_buffer, int len);
  60. ImageData *writeToMemoryAsJPG(const int quality = 90);
  61. void writeToMemoryAsJPG(ImageData *ii, const int quality = 90);
  62. esp_err_t SendJPGtoHTTP(httpd_req_t *req, const int quality = 90);
  63. uint8_t GetPixelColor(int x, int y, int ch);
  64. ~CImageBasis();
  65. void SaveToFile(std::string _imageout);
  66. };
  67. #endif // CIMAGEBASIS_H