@@ -67,8 +67,19 @@ class M5AtomDisplay : public lgfx::LGFX_Device
6767 }
6868
6969 {
70- static constexpr int X_SCALE_MAX = 16 ;
71- static constexpr int Y_SCALE_MAX = 16 ;
70+ static constexpr int SCALE_MAX = 16 ;
71+
72+ if (output_width)
73+ {
74+ if (output_width > 1920 ) { output_width = 1920 ; }
75+ if (logical_width > output_width) { logical_width = output_width; }
76+ }
77+ if (output_height)
78+ {
79+ if (output_height > 1920 ) { output_height = 1920 ; }
80+ if (logical_height > output_height) { logical_height = output_height; }
81+ }
82+
7283 if (logical_width == 0 )
7384 {
7485 if (logical_height == 0 )
@@ -91,62 +102,33 @@ class M5AtomDisplay : public lgfx::LGFX_Device
91102 {
92103 x_scale = 1 ;
93104 y_scale = 1 ;
94- uint32_t prev_total = 0 ;
95- float prev_aspect = INT_MAX;
96- for (int ys = 1 ; ys <= Y_SCALE_MAX; ++ys)
105+ for (int scale = 2 ; scale <= SCALE_MAX; ++scale)
97106 {
98- uint32_t scale_height = ys * logical_height;
99- if (scale_height > 1920 )
100- {
101- break ;
102- }
103- for (int xs = 1 ; xs <= X_SCALE_MAX; ++xs)
104- {
105- uint32_t scale_width = xs * logical_width;
106- if (scale_width > 1920 )
107- {
108- break ;
109- }
110- uint32_t total = scale_width * scale_height;
111- if (total <= 384000 || total > 1024000 ) continue ;
112- float aspect = fabsf (1 .67f - (float )scale_width / scale_height);
113- if (prev_total < total && prev_aspect >= aspect )
114- {
115- prev_total = total;
116- prev_aspect = aspect + 0 .001f ;
117- x_scale = xs;
118- y_scale = ys;
119- }
120- }
107+ uint32_t scale_height = scale * logical_height;
108+ uint32_t scale_width = scale * logical_width;
109+ uint32_t total = scale_width * scale_height;
110+ if (scale_width > 1920 || scale_height > 1920 || total >= 1024000 ) { break ; }
111+ x_scale = scale;
112+ y_scale = scale;
121113 }
122114 output_width = x_scale * logical_width;
123115 output_height = y_scale * logical_height;
124116 }
125117 else
126118 {
127- if (output_width)
128- {
129- if (output_width > 1920 ) { output_width = 1920 ; }
130- if (logical_width > output_width) { logical_width > output_width; }
131- }
132- if (output_height)
133- {
134- if (output_height > 1920 ) { output_height = 1920 ; }
135- if (logical_height > output_height) { logical_height > output_height; }
136- }
137-
138119 if (y_scale == 0 )
139120 {
140121 y_scale = output_height / logical_height;
141122 }
142- if (y_scale > Y_SCALE_MAX) { y_scale = Y_SCALE_MAX; }
123+ if (y_scale > SCALE_MAX) { y_scale = SCALE_MAX; }
124+ while (logical_height * y_scale > output_height) { --y_scale; }
143125
144126 if (x_scale == 0 )
145127 {
146128 x_scale = output_width / logical_width;
147129 }
148130 uint32_t w = output_width / x_scale;
149- while (x_scale > X_SCALE_MAX || w * x_scale != output_width)
131+ while (x_scale > SCALE_MAX || w * x_scale != output_width || logical_width * x_scale > output_width)
150132 {
151133 w = output_width / --x_scale;
152134 }
0 commit comments