Skip to content

Commit

Permalink
Merge pull request #70 from m5stack/develop
Browse files Browse the repository at this point in the history
0.1.11
  • Loading branch information
lovyan03 authored Nov 1, 2023
2 parents b6e8eec + 1fd0dd7 commit 50821b3
Show file tree
Hide file tree
Showing 16 changed files with 487 additions and 449 deletions.
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ Supported device
- M5ATOMS3
- M5Dial
- M5DinMeter
- M5Capsule
- M5Cardputer
- UnitOLED
- UnitMiniOLED
Expand Down
2 changes: 1 addition & 1 deletion library.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"type": "git",
"url": "https://github.com/m5stack/M5GFX.git"
},
"version": "0.1.10",
"version": "0.1.11",
"frameworks": ["arduino", "espidf", "*"],
"platforms": ["espressif32", "native"],
"headers": "M5GFX.h"
Expand Down
2 changes: 1 addition & 1 deletion library.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name=M5GFX
version=0.1.10
version=0.1.11
author=M5Stack
maintainer=M5Stack
sentence=Library for M5Stack All Display
Expand Down
18 changes: 17 additions & 1 deletion src/M5GFX.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -675,7 +675,7 @@ namespace m5gfx
bus_spi->config(bus_cfg);
bus_spi->init();
id = _read_panel_id(bus_spi, GPIO_NUM_9, 0x70, 0);
if (id == 0x00F00000)
if ((id & 0xFFFFF0FFu) == 0x00F00000u)
{ // check panel (e-paper GDEW0154M09)
_pin_level(GPIO_NUM_12, true); // POWER_HOLD_PIN 12
board = board_t::board_M5StackCoreInk;
Expand Down Expand Up @@ -1432,6 +1432,9 @@ namespace m5gfx
case board_M5Tough: title = "M5Tough"; break;
case board_M5Station: title = "M5Station"; break;
case board_M5AtomS3: title = "M5AtomS3"; break;
case board_M5Dial: title = "M5Dial"; break;
case board_M5Cardputer: title = "M5Cardputer"; break;
case board_M5DinMeter: title = "M5DinMeter"; break;
default: title = "M5GFX"; break;
}
p->setWindowTitle(title);
Expand Down Expand Up @@ -1462,8 +1465,16 @@ namespace m5gfx
break;

case board_M5Station:
case board_M5Cardputer:
w = 240;
h = 135;
pnl_cfg.offset_rotation = 3;
r = 1;
break;

case board_M5StickCPlus:
case board_M5StickCPlus2:
case board_M5DinMeter:
w = 135;
h = 240;
break;
Expand All @@ -1475,6 +1486,11 @@ namespace m5gfx
r = 1;
break;

case board_M5Dial:
w = 240;
h = 240;
break;

default:
break;
}
Expand Down
12 changes: 6 additions & 6 deletions src/lgfx/utility/lgfx_tjpgd.c
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ static inline int32_t BYTECLIP (
/*---------------------------------------------*/

#if JD_BAYER
static const int_fast8_t Bayer[16] = { 0, 4, 1, 5,-2, 2,-1, 3, 1, 5, 0, 4,-1, 3,-2, 2};
static const int8_t Bayer[16] = { 0, 4, 1, 5,-2, 2,-1, 3, 1, 5, 0, 4,-1, 3,-2, 2};
#endif


Expand Down Expand Up @@ -299,7 +299,7 @@ static int32_t huffext ( /* >=0: decoded data, <0: error code */
{
const uint8_t* hb_end = hb + 16 + 1;
uint_fast8_t msk = jd->dbit;
uint_fast16_t w = *jd->dptr & ((1ul << msk) - 1);
uint32_t w = *jd->dptr & ((1ul << msk) - 1);
for (;;) {
if (!msk) { /* Next byte? */
uint8_t *dp = jd->dptr;
Expand Down Expand Up @@ -584,7 +584,7 @@ static JRESULT mcu_output (
iy = 0;
do {
#if JD_BAYER
const int_fast8_t* btbl = &Bayer[(iy & 3) << 2];
const int8_t* btbl = &Bayer[(iy & 3) << 2];
#endif
py = &jd->mcubuf[((iy & 8) + iy) << 3];
pc = &jd->mcubuf[((mx << iyshift) + (iy >> iyshift)) << 3];
Expand All @@ -596,10 +596,10 @@ static JRESULT mcu_output (
++pc;

/* Convert CbCr to RGB */
uint_fast16_t rr = ((int32_t)(1.402 * (1<<FP_SHIFT)) * cr) >> FP_SHIFT;
uint_fast16_t gg = ((int32_t)(0.34414 * (1<<FP_SHIFT)) * cb
int32_t rr = ((int32_t)(1.402 * (1<<FP_SHIFT)) * cr) >> FP_SHIFT;
int32_t gg = ((int32_t)(0.34414 * (1<<FP_SHIFT)) * cb
+ (int32_t)(0.71414 * (1<<FP_SHIFT)) * cr) >> FP_SHIFT;
uint_fast16_t bb = ((int32_t)(1.772 * (1<<FP_SHIFT)) * cb) >> FP_SHIFT;
int32_t bb = ((int32_t)(1.772 * (1<<FP_SHIFT)) * cb) >> FP_SHIFT;
do {
#if JD_BAYER
yy = *py + btbl[ix & 3]; /* Get Y component */
Expand Down
12 changes: 6 additions & 6 deletions src/lgfx/utility/lgfx_tjpgd.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,21 +63,21 @@ struct lgfxJdec {
uint8_t* dptr; /* Current data read ptr */
uint8_t* dpend; /* data end ptr */
uint8_t* inbuf; /* Bit stream input buffer */
uint_fast8_t dbit; /* Current bit in the current read byte */
uint_fast8_t scale; /* Output scaling ratio */
uint_fast8_t msx, msy; /* MCU size in unit of block (width, height) */
uint_fast8_t qtid[3]; /* Quantization table ID of each component */
uint8_t dbit; /* Current bit in the current read byte */
uint8_t scale; /* Output scaling ratio */
uint8_t msx, msy; /* MCU size in unit of block (width, height) */
uint8_t qtid[3]; /* Quantization table ID of each component */
int32_t dcv[3]; /* Previous DC element of each component */
uint16_t nrst; /* Restart inverval */
uint_fast16_t width, height;/* Size of the input image (pixel) */
uint16_t width, height;/* Size of the input image (pixel) */
uint8_t* huffbits[2][2]; /* Huffman bit distribution tables [id][dcac] */
uint16_t* huffcode[2][2]; /* Huffman code word tables [id][dcac] */
uint8_t* huffdata[2][2]; /* Huffman decoded data tables [id][dcac] */
int32_t* qttbl[4]; /* Dequantizer tables [id] */
void* workbuf; /* Working buffer for IDCT and RGB output */
int16_t* mcubuf; /* Working buffer for the MCU */
uint8_t* pool; /* Pointer to available memory pool */
uint_fast16_t sz_pool; /* Size of momory pool (bytes available) */
uint16_t sz_pool; /* Size of momory pool (bytes available) */
uint32_t (*infunc)(void*, uint8_t*, uint32_t);/* Pointer to jpeg stream input function */
void* device; /* Pointer to I/O device identifiler for the session */
uint8_t comps_in_frame; /* 1=Y(grayscale) 3=YCrCb */
Expand Down
34 changes: 33 additions & 1 deletion src/lgfx/v1/LGFXBase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2144,7 +2144,6 @@ namespace lgfx
//_decoderState = utf8_decode_state_t::utf8_state0;

font->getDefaultMetric(&_font_metrics);

}

/// load VLW font
Expand All @@ -2154,6 +2153,39 @@ namespace lgfx
return load_font(&_font_data);
}

bool LGFXBase::load_font_with_path(const char *path)
{
this->unloadFont();

if (this->_font_file.get() == nullptr) return false;

this->prepareTmpTransaction(this->_font_file.get());
this->_font_file->preRead();

bool result = this->_font_file->open(path);
if (!result)
{
size_t alloclen = strlen(path) + 8;
auto filename = (char*)alloca(alloclen);
memset(filename, 0, alloclen);
filename[0] = '/';

strcpy(&filename[1], &path[(path[0] == '/') ? 1 : 0]);
int len = strlen(filename);
if (memcmp(&filename[len - 4], ".vlw", 4))
{
strcpy(&filename[len], ".vlw");
}
result = this->_font_file->open(filename);
}

if (result) {
result = this->load_font(this->_font_file.get());
}
this->_font_file->postRead();
return result;
}

bool LGFXBase::load_font(lgfx::DataWrapper* data)
{
this->unloadFont();
Expand Down
68 changes: 66 additions & 2 deletions src/lgfx/v1/LGFXBase.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -742,6 +742,23 @@ namespace lgfx
/// load VLW font
bool loadFont(const uint8_t* array);

/// load vlw font from filesystem.
bool loadFont(const char *path)
{
this->unloadFont();
this->_font_file.reset(_create_data_wrapper());
return load_font_with_path(path);
}


template <typename T>
bool loadFont(T &fs, const char *path)
{
unloadFont();
_font_file.reset(new DataWrapperT<T>(&fs));
return load_font_with_path(path);
}

/// unload VLW font
void unloadFont(void);

Expand All @@ -754,6 +771,16 @@ namespace lgfx
uint8_t getAttribute(attribute_t attr_id);
uint8_t getAttribute(uint8_t attr_id) { return getAttribute((attribute_t)attr_id); }

template <typename T>
void setFileStorage(T& fs) {
_data_wrapper_factory.reset(new DataWrapperTFactoryT<T>(&fs));
}

template <typename T>
void setFileStorage(T* fs) { _data_wrapper_factory.reset(new DataWrapperTFactoryT<T>(fs)); }

void clearFileStorage(void) { _data_wrapper_factory.reset(new DataWrapperTFactoryT<void>(nullptr)); }

//----------------------------------------------------------------------------
// print & text support
//----------------------------------------------------------------------------
Expand Down Expand Up @@ -822,9 +849,9 @@ namespace lgfx
void qrcode(const char *string, int32_t x = -1, int32_t y = -1, int32_t width = -1, uint8_t version = 1);

#define LGFX_FUNCTION_GENERATOR(drawImg, draw_img) \
protected: \
protected: \
bool draw_img(DataWrapper* data, int32_t x, int32_t y, int32_t maxWidth, int32_t maxHeight, int32_t offX, int32_t offY, float scale_x, float scale_y, datum_t datum); \
public: \
public: \
bool drawImg(const uint8_t *data, uint32_t len, int32_t x=0, int32_t y=0, int32_t maxWidth=0, int32_t maxHeight=0, int32_t offX=0, int32_t offY=0, float scale_x = 1.0f, float scale_y = 0.0f, datum_t datum = datum_t::top_left) \
{ \
PointerWrapper data_wrapper; \
Expand All @@ -835,6 +862,34 @@ namespace lgfx
{ \
return this->draw_img(data, x, y, maxWidth, maxHeight, offX, offY, scale_x, scale_y, datum); \
} \
bool drawImg##File(DataWrapper* file, const char *path, int32_t x = 0, int32_t y = 0, int32_t maxWidth = 0, int32_t maxHeight = 0, int32_t offX = 0, int32_t offY = 0, float scale_x = 1.0f, float scale_y = 0.0f, datum_t datum = datum_t::top_left) \
{ \
bool res = false; \
this->prepareTmpTransaction(file); \
file->preRead(); \
if (file->open(path)) \
{ \
res = this->draw_img(file, x, y, maxWidth, maxHeight, offX, offY, scale_x, scale_y, datum); \
file->close(); \
} \
file->postRead(); \
return res; \
} \
inline bool drawImg##File(const char *path, int32_t x = 0, int32_t y = 0, int32_t maxWidth = 0, int32_t maxHeight = 0, int32_t offX = 0, int32_t offY = 0, float scale_x = 1.0f, float scale_y = 0.0f, datum_t datum = datum_t::top_left) \
{ \
auto data = _create_data_wrapper(); \
bool res = drawImg##File(data, path, x, y, maxWidth, maxHeight, offX, offY, scale_x, scale_y, datum); \
delete data; \
return res; \
} \
template <typename T> \
inline bool drawImg##File(T &fs, const char *path, int32_t x = 0, int32_t y = 0, int32_t maxWidth = 0, int32_t maxHeight = 0, int32_t offX = 0, int32_t offY = 0, float scale_x = 1.0f, float scale_y = 0.0f, datum_t datum = datum_t::top_left) \
{ \
DataWrapperT<T> file ( &fs ); \
bool res = this->drawImg##File(&file, path, x, y, maxWidth, maxHeight, offX, offY, scale_x, scale_y, datum); \
file.close(); \
return res; \
}

LGFX_FUNCTION_GENERATOR(drawBmp, draw_bmp)
LGFX_FUNCTION_GENERATOR(drawJpg, draw_jpg)
Expand All @@ -851,6 +906,11 @@ namespace lgfx
{
return drawJpg(data, x, y, maxWidth, maxHeight, offX, offY, 1.0f / (1 << scale));
}
[[deprecated("use float scale")]]
inline bool drawJpgFile(const char *path, int32_t x, int32_t y, int32_t maxWidth, int32_t maxHeight, int32_t offX, int32_t offY, jpeg_div::jpeg_div_t scale)
{
return drawJpgFile(path, x, y, maxWidth, maxHeight, offX, offY, 1.0f / (1 << scale));
}

void* createPng( size_t* datalen, int32_t x = 0, int32_t y = 0, int32_t width = 0, int32_t height = 0);

Expand Down Expand Up @@ -917,6 +977,9 @@ namespace lgfx
std::shared_ptr<DataWrapper> _font_file; // run-time font file
PointerWrapper _font_data;

std::shared_ptr<DataWrapperFactory> _data_wrapper_factory;
DataWrapper* _create_data_wrapper(void) { if (nullptr == _data_wrapper_factory.get()) { clearFileStorage(); } return _data_wrapper_factory->create(); }

bool _textwrap_x = true;
bool _textwrap_y = false;
bool _textscroll = false;
Expand Down Expand Up @@ -1220,6 +1283,7 @@ namespace lgfx
size_t draw_string(const char *string, int32_t x, int32_t y, textdatum_t datum, const IFont* font = nullptr);
int32_t text_width(const char *string, const IFont* font, FontMetrics* metrics);
bool load_font(lgfx::DataWrapper* data);
bool load_font_with_path(const char *path);

static void tmpBeginTransaction(LGFXBase* lgfx)
{
Expand Down
Loading

0 comments on commit 50821b3

Please sign in to comment.