141{
142 quint32
w = widthInput->value();
143 quint32
h = heightInput->value();
144
145 bool ok;
146 quint32 fileSize = fileSizeLabel->text().toUInt(&ok);
148
149 quint32
depth = bppLabel->text().toUInt(&ok);
151
152 quint32 bytesPerPixel =
depth / 8;
153
154 w = widthInput->text().toUInt(&ok);
156
157 h = heightInput->text().toUInt(&ok);
159
160 quint32 dimensions = fileSize / bytesPerPixel;
161
162 if (w > 0 && h > 0) {
163 if (w * h == dimensions) {
164
165 widthInput->setValue(h);
166 heightInput->setValue(w);
167 }
168 }
169 else if (w == 0 && h == 0) {
170 quint32
r = (quint32)(qFloor(qSqrt(dimensions) + 0.5));
171
172
173 if (r*r == dimensions) {
174 widthInput->setValue(r);
175 heightInput->setValue(r);
176 }
177 else {
178
180 h = dimensions /
w + (dimensions %
w);
181 if (w * h != dimensions) {
182 showErrorTooltip(i18n(
"Too many possible combinations. Input a width or height and try again."));
183 return;
184 }
185
186
187 widthInput->setValue(w > h ? w :
h);
188 heightInput->setValue(w > h ? h :
w);
189
190
191 }
192 }
193 else if (w > 0) {
194 if (w > dimensions) {
196 return;
197 }
198 h = dimensions /
w + (dimensions %
w);
199 if (w * h != dimensions) {
200 showErrorTooltip(i18n(
"Unable to calculate an appropriate height. File does not contain enough pixels to form a rectangle."));
201 return;
202 }
203 heightInput->setValue(h);
204 }
205 else {
206 if (h > dimensions) {
208 return;
209 }
210 w = dimensions /
h + (dimensions %
h);
211 if (w * h != dimensions) {
212 showErrorTooltip(i18n(
"Unable to calculate an appropriate width. File does not contain enough pixels to form a rectangle."));
213 return;
214 }
215 widthInput->setValue(w);
216 }
217}
#define KIS_ASSERT_RECOVER_RETURN(cond)
static void showErrorTooltip(const QString &msg)
static constexpr quint32 prevPow2(quint32 n)
int depth(typename Forest< T >::const_child_iterator beginIt, typename Forest< T >::const_child_iterator endIt)