@@ -1093,9 +1093,9 @@ namespace lgfx
10931093 auto scanline = (rgb888_t *)alloca (w * sizeof (rgb888_t ));
10941094
10951095 startWrite ();
1096- for ( int _y=0 ;_y<h;_y++ ) {
1096+ for ( int _y=0 ;_y<( int ) h;_y++ ) {
10971097 // only half of the scan line needs to be calculated, the other half is mirrored
1098- for ( int _x=0 ;_x<=w/2 ;_x++ ) {
1098+ for ( int _x=0 ;_x<=( int ) w/2 ;_x++ ) {
10991099 auto distance = pixelDistance ( fmidx, fmidy, _x*vratio, _y*hratio );
11001100 scanline[_x] = map_gradient ( distance, 0 , hyp0, gradient );
11011101 scanline[(w-1 )-_x] = scanline[_x];
@@ -1118,11 +1118,11 @@ namespace lgfx
11181118 bool is_vertical = style==VLINEAR;
11191119 const uint32_t gradient_len = is_vertical ? h : w;
11201120 auto scanline = (rgb888_t *)alloca (gradient_len * sizeof (rgb888_t ));
1121- for (int i=0 ;i<gradient_len;i++) { // memoize one gradient scanline
1121+ for (int i=0 ;i<( int ) gradient_len;i++) { // memoize one gradient scanline
11221122 scanline[i] = map_gradient ( i, 0 , gradient_len, gradient );
11231123 }
11241124 startWrite ();
1125- for ( int ys=0 ;ys<h;ys++ ) {
1125+ for ( int ys=0 ;ys<( int ) h;ys++ ) {
11261126 if ( is_vertical ) { // scanline is used as an colors index
11271127 setColor (color888 (scanline[ys].r , scanline[ys].g , scanline[ys].b ));
11281128 drawFastHLine ( x, y+ys, w );
@@ -2059,47 +2059,48 @@ namespace lgfx
20592059 uint16_t LGFXBase::decodeUTF8 (uint8_t c)
20602060 {
20612061 // 7 bit Unicode Code Point
2062- if (!(c & 0x80 )) {
2063- _decoderState = utf8_decode_state_t ::utf8_state0;
2064- return c;
2065- }
2066-
2067- if (_decoderState == utf8_decode_state_t ::utf8_state0)
2068- {
2069- // 11 bit Unicode Code Point
2070- if ((c & 0xE0 ) == 0xC0 )
2062+ if ((c & 0x80 )) {
2063+ // multibyte start or continue byte
2064+ switch (_decoderState)
20712065 {
2072- _unicode_buffer = ((c & 0x1F )<<6 );
2073- _decoderState = utf8_decode_state_t ::utf8_state1;
2074- return 0 ;
2075- }
2066+ case utf8_decode_state_t ::utf8_state3:
2067+ case utf8_decode_state_t ::utf8_state2:
2068+ case utf8_decode_state_t ::utf8_state1:
2069+ _decoderState=(utf8_decode_state_t )((uint8_t )_decoderState-1 );
2070+ _unicode_buffer |= ((c & 0x3F ) << (6 * (uint8_t )_decoderState));
2071+ return _decoderState ? 0 : _unicode_buffer;
2072+
2073+ case utf8_decode_state_t ::utf8_state0:
2074+ default :
2075+ // 11 bit Unicode Code Point
2076+ if ((c & 0xE0 ) == 0xC0 )
2077+ {
2078+ _unicode_buffer = ((c & 0x1F ) << (6 * 1 ));
2079+ _decoderState = utf8_decode_state_t ::utf8_state1;
2080+ return 0 ;
2081+ }
20762082
2077- // 16 bit Unicode Code Point
2078- if ((c & 0xF0 ) == 0xE0 )
2079- {
2080- _unicode_buffer = ((c & 0x0F )<<12 );
2081- _decoderState = utf8_decode_state_t ::utf8_state2;
2082- return 0 ;
2083- }
2084- // 21 bit Unicode Code Point not supported so fall-back to extended ASCII
2085- // if ((c & 0xF8) == 0xF0) return (uint16_t)c;
2086- }
2087- else
2088- {
2089- if (_decoderState == utf8_decode_state_t ::utf8_state2)
2090- {
2091- _unicode_buffer |= ((c & 0x3F )<<6 );
2092- _decoderState = utf8_decode_state_t ::utf8_state1;
2093- return 0 ;
2083+ // 16 bit Unicode Code Point
2084+ if ((c & 0xF0 ) == 0xE0 )
2085+ {
2086+ _unicode_buffer = ((c & 0x0F ) << (6 * 2 ));
2087+ _decoderState = utf8_decode_state_t ::utf8_state2;
2088+ return 0 ;
2089+ }
2090+ // 21 bit Unicode Code Point not supported so fall-back to extended ASCII
2091+ if ((c & 0xF8 ) == 0xF0 )
2092+ {
2093+ _unicode_buffer = (c & 0x07 )<<(6 * 3 ); // 6 bits for each of the 3 bytes
2094+ _decoderState = utf8_decode_state_t ::utf8_state3;
2095+ return 0 ;
2096+ }
2097+ // fallback to extended ASCII
2098+ break ;
20942099 }
2095- _unicode_buffer |= (c & 0x3F );
2096- _decoderState = utf8_decode_state_t ::utf8_state0;
2097- return _unicode_buffer;
20982100 }
2099-
2101+ // single byte ASCII
21002102 _decoderState = utf8_decode_state_t ::utf8_state0;
2101-
2102- return c; // fall-back to extended ASCII
2103+ return c;
21032104 }
21042105
21052106 int32_t LGFXBase::fontHeight (const IFont* font) const
0 commit comments