1616 * @authors Soldered
1717 ***************************************************/
1818#include " Inkplate.h"
19+ #ifndef USE_COLOR_IMAGE
1920#include " Image.h"
2021#include " TJpeg/TJpg_Decoder.h"
2122#include " pgmspace.h"
2223
24+
2325Image *_imagePtrJpeg = nullptr ;
2426Image *_imagePtrPng = nullptr ;
2527
26- void Image::beginImage (Inkplate *inkplateptr)
28+ uint8_t (*Image::ditherBuffer)[E_INK_WIDTH + 20 ] = nullptr ;
29+ uint8_t (*Image::jpegDitherBuffer)[18 ] = nullptr ;
30+ uint8_t *Image::pixelBuffer = nullptr ;
31+ uint32_t *Image::ditherPalette = nullptr ;
32+ uint8_t *Image::palette = nullptr ;
33+
34+ void Image::begin (Inkplate *inkplateptr)
2735{
2836 _inkplate = inkplateptr;
2937 _imagePtrJpeg = this ;
3038 _imagePtrPng = this ;
39+
40+
41+ jpegDitherBuffer = (uint8_t (*)[18 ])heap_caps_calloc (18 , 18 , MALLOC_CAP_SPIRAM);
42+
43+
44+ ditherBuffer = (uint8_t (*)[E_INK_WIDTH + 20 ])heap_caps_calloc (2 , (E_INK_WIDTH + 20 ), MALLOC_CAP_INTERNAL | MALLOC_CAP_8BIT);
45+
46+
47+ pixelBuffer = (uint8_t *)heap_caps_calloc (1 , (E_INK_WIDTH * 4 + 5 ), MALLOC_CAP_SPIRAM);
48+
49+
50+ ditherPalette = (uint32_t *)heap_caps_calloc (256 , sizeof (uint32_t ), MALLOC_CAP_SPIRAM);
51+
52+
53+ palette = (uint8_t *)heap_caps_calloc (128 , sizeof (uint8_t ), MALLOC_CAP_SPIRAM);
54+
55+
56+ if (!jpegDitherBuffer || !ditherBuffer || !pixelBuffer || !ditherPalette || !palette)
57+ {
58+ Serial.println (" Failed to allocate one or more buffers (SRAM/PSRAM)" );
59+ }
60+ else
61+ {
62+ Serial.println (" Buffers allocated successfully in PSRAM" );
63+ }
64+
65+
66+
67+
3168}
3269
3370/* *
@@ -46,9 +83,9 @@ void Image::beginImage(Inkplate *inkplateptr)
4683 *
4784 * @return 1 if succesfuly drawn, 0 if not
4885 */
49- bool Image::drawImage (const String path, int x, int y, bool dither, bool invert)
86+ bool Image::draw (const String path, int x, int y, bool dither, bool invert)
5087{
51- return drawImage (path.c_str (), x, y, dither, invert);
88+ return draw (path.c_str (), x, y, dither, invert);
5289};
5390
5491/* *
@@ -67,7 +104,7 @@ bool Image::drawImage(const String path, int x, int y, bool dither, bool invert)
67104 *
68105 * @return 1 if succesfuly drawn, 0 if not
69106 */
70- bool Image::drawImage (const char *path, int x, int y, bool dither, bool invert)
107+ bool Image::draw (const char *path, int x, int y, bool dither, bool invert)
71108{
72109 // Try to get the file extension.
73110 char _fileExtension[5 ];
@@ -115,7 +152,7 @@ bool Image::drawImage(const char *path, int x, int y, bool dither, bool invert)
115152 *
116153 * @return 1 if succesfuly drawn, 0 if not
117154 */
118- bool Image::drawImage (const uint8_t *buf, int x, int y, int16_t w, int16_t h, uint8_t c, uint8_t bg)
155+ bool Image::draw (const uint8_t *buf, int x, int y, int16_t w, int16_t h, uint8_t c, uint8_t bg)
119156{
120157 if (_inkplate->getDisplayMode () == INKPLATE_1BIT && bg == 0xFF )
121158 _inkplate->drawBitmap (x, y, buf, w, h, c);
@@ -144,10 +181,10 @@ bool Image::drawImage(const uint8_t *buf, int x, int y, int16_t w, int16_t h, ui
144181 *
145182 * @return 1 if succesfuly drawn, 0 if not
146183 */
147- bool Image::drawImage (const String path, const Format &format, const int x, const int y, const bool dither,
184+ bool Image::draw (const String path, const Format &format, const int x, const int y, const bool dither,
148185 const bool invert)
149186{
150- return drawImage (path.c_str (), format, x, y, dither, invert);
187+ return draw (path.c_str (), format, x, y, dither, invert);
151188};
152189
153190/* *
@@ -168,7 +205,7 @@ bool Image::drawImage(const String path, const Format &format, const int x, cons
168205 *
169206 * @return 1 if succesfuly drawn, 0 if not
170207 */
171- bool Image::drawImage (const char *path, const Format &format, const int x, const int y, const bool dither,
208+ bool Image::draw (const char *path, const Format &format, const int x, const int y, const bool dither,
172209 const bool invert)
173210{
174211 if (strncmp (path, " http://" , 7 ) == 0 || strncmp (path, " https://" , 8 ) == 0 )
@@ -209,7 +246,7 @@ bool Image::drawImage(const char *path, const Format &format, const int x, const
209246 *
210247 * @return 1 if succesfuly drawn, 0 if not
211248 */
212- bool Image::drawImage (const char *path, const Format &format, const Position &position, const bool dither,
249+ bool Image::draw (const char *path, const Format &format, const Position &position, const bool dither,
213250 const bool invert)
214251{
215252 if (strncmp (path, " http://" , 7 ) == 0 || strncmp (path, " https://" , 8 ) == 0 )
@@ -374,3 +411,5 @@ void Image::getPointsForPosition(const Position &position, const uint16_t imageW
374411 break ;
375412 }
376413}
414+
415+ #endif
0 commit comments