@@ -44,7 +44,7 @@ const uint8_t _pluto_dinis[4][2] = {
44
44
45
45
void pluto_transform_ucp (uchar * ret , uint16_t unichr )
46
46
{
47
- ret [0 ] = ( uchar )((( unichr >> 12 ) & 0x0F ) | 0xE0 ) ;
47
+ ret [0 ] = 0xE2 ;
48
48
ret [1 ] = (uchar )(((unichr >> 6 ) & 0x3F ) | 0x80 );
49
49
ret [2 ] = (uchar )(((unichr )& 0x3F ) | 0x80 );
50
50
}
@@ -56,6 +56,7 @@ void _pluto_lock_term()
56
56
{
57
57
if (_pluto_term_locked )
58
58
return ;
59
+
59
60
tcgetattr (0 , & _pluto_term );
60
61
tcgetattr (0 , & _pluto_old_term );
61
62
_pluto_term .c_lflag &= ~(ICANON | ECHO );
@@ -67,15 +68,18 @@ void _pluto_unlock_term()
67
68
{
68
69
if (!_pluto_term_locked )
69
70
return ;
71
+
70
72
tcsetattr (0 , TCSANOW , & _pluto_old_term );
71
73
_pluto_term_locked = false;
72
74
}
73
75
74
76
void pluto_write_out ()
75
77
{
76
78
_pluto_canvas .busy = true;
79
+
77
80
char buf [20 ];
78
81
uchar * cbuf = (uchar * )& _pluto_canvas .buffer [3 ];
82
+
79
83
for (int32_t i = 0 ; i < _pluto_canvas .bmsize ; i ++ )
80
84
{
81
85
int bx = (i % _pluto_canvas .width ) * 2 ;
@@ -86,15 +90,15 @@ void pluto_write_out()
86
90
87
91
for (int y = 0 ; y < 4 ; y ++ )
88
92
{
89
- int yp = y + by ;
93
+ int yp = ( y + by ) * ( _pluto_canvas . width << 1 ) ;
90
94
91
95
for (int x = 0 ; x < 2 ; x ++ )
92
96
{
93
97
int xp = x + bx ;
94
98
95
99
if (_pluto_canvas .bitmap [i ] & (1 << _pluto_dinis [y ][x ]))
96
100
{
97
- pci = yp * ( _pluto_canvas . width << 1 ) + xp ;
101
+ pci = yp + xp ;
98
102
bl ++ ;
99
103
tr += _pluto_canvas .pix_colour [pci ].r ;
100
104
tg += _pluto_canvas .pix_colour [pci ].g ;
@@ -105,23 +109,24 @@ void pluto_write_out()
105
109
106
110
if (bl )
107
111
{
108
- tr /= bl ;
109
- tg /= bl ;
110
- tb /= bl ;
112
+ tr /= bl , tg /= bl , tb /= bl ;
111
113
}
112
114
else
113
115
{
114
116
tr = 255 , tg = 255 , tb = 255 ;
115
117
}
116
118
117
119
sprintf (buf , "\e[38;2;%03u;%03u;%03um" , (uint8_t )tr , (uint8_t )tg , (uint8_t )tb );
118
- strcpy ((char * )& cbuf [i * 22 + (i / _pluto_canvas .width )], buf );
119
- pluto_transform_ucp (& cbuf [i * 22 + 19 + (i / _pluto_canvas .width )], PLUTO_CHAR_OFF + _pluto_canvas .bitmap [i ]);
120
+ int iw = i / _pluto_canvas .width ;
121
+ strcpy ((char * )& cbuf [i * 22 + iw ], buf );
122
+ pluto_transform_ucp (& cbuf [i * 22 + 19 + iw ], PLUTO_CHAR_OFF + _pluto_canvas .bitmap [i ]);
120
123
}
124
+
121
125
for (int i = 1 ; i < _pluto_canvas .height ; i ++ )
122
126
{
123
- cbuf [_pluto_canvas .width * 22 * i + i - 1 ] = '\n' ;
127
+ cbuf [( _pluto_canvas .width * 22 + 1 ) * i - 1 ] = '\n' ;
124
128
}
129
+
125
130
_pluto_canvas .buffer [_pluto_canvas .bufsize - 1 ] = 0 ;
126
131
_pluto_canvas .busy = false;
127
132
}
@@ -136,14 +141,15 @@ void pluto_render()
136
141
putchar ('\n' );
137
142
138
143
_pluto_first_out = false;
144
+
139
145
if (_pluto_canvas .use_write )
140
146
fflush (stdout );
141
147
}
142
148
if (_pluto_canvas .use_write )
143
149
{
144
150
#if defined(__unix__ ) || defined(__linux__ ) || defined(BSD ) || defined(__APPLE__ )
145
151
int wr = write (STDOUT_FILENO , _pluto_canvas .buffer , _pluto_canvas .bufsize );
146
- (void )wr ; /* Debian fix */
152
+ (void )wr ; /* Debian fix */
147
153
#else
148
154
fputs ((char * )_pluto_canvas .buffer , stdout );
149
155
fflush (stdout );
@@ -154,6 +160,7 @@ void pluto_render()
154
160
fputs ((char * )_pluto_canvas .buffer , stdout );
155
161
fflush (stdout );
156
162
}
163
+
157
164
_pluto_unlock_term ();
158
165
_pluto_canvas .busy = false;
159
166
}
0 commit comments