Skip to content

Commit b8bdffc

Browse files
authored
feat: add more built-in highres upscalers (#1456)
1 parent c97702e commit b8bdffc

11 files changed

Lines changed: 625 additions & 210 deletions

File tree

examples/cli/README.md

Lines changed: 105 additions & 75 deletions
Large diffs are not rendered by default.

examples/cli/main.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -690,7 +690,10 @@ int main(int argc, const char* argv[]) {
690690
vae_decode_only = false;
691691
}
692692

693-
if (gen_params.hires_enabled && !gen_params.hires_upscaler_model_path.empty()) {
693+
if (gen_params.hires_enabled &&
694+
(gen_params.resolved_hires_upscaler == SD_HIRES_UPSCALER_MODEL ||
695+
gen_params.resolved_hires_upscaler == SD_HIRES_UPSCALER_LANCZOS ||
696+
gen_params.resolved_hires_upscaler == SD_HIRES_UPSCALER_NEAREST)) {
694697
vae_decode_only = false;
695698
}
696699

examples/common/common.cpp

Lines changed: 46 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -107,47 +107,60 @@ static bool is_absolute_path(const std::string& p) {
107107

108108
std::string ArgOptions::wrap_text(const std::string& text, size_t width, size_t indent) {
109109
std::ostringstream oss;
110-
size_t line_len = 0;
111110
size_t pos = 0;
111+
size_t line_len = 0;
112112

113113
while (pos < text.size()) {
114-
// Preserve manual newlines
115114
if (text[pos] == '\n') {
116115
oss << '\n'
117116
<< std::string(indent, ' ');
118-
line_len = indent;
117+
line_len = 0;
119118
++pos;
120119
continue;
121120
}
122121

123-
// Add the character
124-
oss << text[pos];
125-
++line_len;
126-
++pos;
127-
128-
// If the current line exceeds width, try to break at the last space
129-
if (line_len >= width) {
130-
std::string current = oss.str();
131-
size_t back = current.size();
132-
133-
// Find the last space (for a clean break)
134-
while (back > 0 && current[back - 1] != ' ' && current[back - 1] != '\n')
135-
--back;
136-
137-
// If found a space to break on
138-
if (back > 0 && current[back - 1] != '\n') {
139-
std::string before = current.substr(0, back - 1);
140-
std::string after = current.substr(back);
141-
oss.str("");
142-
oss.clear();
143-
oss << before << "\n"
144-
<< std::string(indent, ' ') << after;
145-
} else {
146-
// If no space found, just break at width
147-
oss << "\n"
122+
if (std::isspace(static_cast<unsigned char>(text[pos]))) {
123+
++pos;
124+
continue;
125+
}
126+
127+
size_t word_start = pos;
128+
while (pos < text.size() &&
129+
text[pos] != '\n' &&
130+
!std::isspace(static_cast<unsigned char>(text[pos]))) {
131+
++pos;
132+
}
133+
134+
std::string word = text.substr(word_start, pos - word_start);
135+
while (!word.empty()) {
136+
size_t separator_len = line_len == 0 ? 0 : 1;
137+
if (line_len + separator_len + word.size() <= width) {
138+
if (separator_len > 0) {
139+
oss << ' ';
140+
++line_len;
141+
}
142+
oss << word;
143+
line_len += word.size();
144+
word.clear();
145+
continue;
146+
}
147+
148+
if (line_len > 0) {
149+
oss << '\n'
150+
<< std::string(indent, ' ');
151+
line_len = 0;
152+
continue;
153+
}
154+
155+
size_t chunk_len = std::min(width, word.size());
156+
oss << word.substr(0, chunk_len);
157+
line_len = chunk_len;
158+
word.erase(0, chunk_len);
159+
if (!word.empty()) {
160+
oss << '\n'
148161
<< std::string(indent, ' ');
162+
line_len = 0;
149163
}
150-
line_len = indent;
151164
}
152165
}
153166

@@ -783,7 +796,9 @@ ArgOptions SDGenerationParams::get_options() {
783796
&pm_id_embed_path},
784797
{"",
785798
"--hires-upscaler",
786-
"highres fix upscaler, Latent (nearest) or a model name/path under --hires-upscalers-dir (default: Latent (nearest))",
799+
"highres fix upscaler, Lanczos, Nearest, Latent, Latent (nearest), Latent (nearest-exact), "
800+
"Latent (antialiased), Latent (bicubic), Latent (bicubic antialiased), or a model name "
801+
"under --hires-upscalers-dir (default: Latent)",
787802
&hires_upscaler},
788803
};
789804

@@ -1918,7 +1933,7 @@ bool SDGenerationParams::resolve(const std::string& lora_model_dir, const std::s
19181933
hires_upscaler_model_path.clear();
19191934
if (hires_enabled) {
19201935
if (hires_upscaler.empty()) {
1921-
hires_upscaler = "Latent (nearest)";
1936+
hires_upscaler = "Latent";
19221937
}
19231938
resolved_hires_upscaler = str_to_sd_hires_upscaler(hires_upscaler.c_str());
19241939
if (resolved_hires_upscaler == SD_HIRES_UPSCALER_NONE) {

examples/common/common.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ struct SDGenerationParams {
192192
int upscale_tile_size = 128;
193193

194194
bool hires_enabled = false;
195-
std::string hires_upscaler = "Latent (nearest)";
195+
std::string hires_upscaler = "Latent";
196196
std::string hires_upscaler_model_path;
197197
float hires_scale = 2.f;
198198
int hires_width = 0;

0 commit comments

Comments
 (0)