Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 12 additions & 5 deletions ai_diffusion/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -296,11 +296,10 @@ def upscale_image(self):
return

self.clear_error()
self.upscale.set_in_progress(True)

eventloop.run(_report_errors(self, self._enqueue_job(job, inputs)))

self._doc.resize(job.params.bounds.extent)
self.upscale.set_in_progress(True)
self.upscale.target_extent_changed.emit(self.upscale.target_extent)

def estimate_cost(self, kind=JobKind.diffusion):
Expand Down Expand Up @@ -557,14 +556,22 @@ def hide_preview(self):
self._layer.hide()

def apply_result(self, image: Image, params: JobParams, behavior: ApplyBehavior, prefix=""):
if image.extent != params.bounds.extent:
image_width, image_height = image.extent.width, image.extent.height
bounds_width, bounds_height = params.bounds.extent.width, params.bounds.extent.height

is_upscaled = image_width > 1.25 * bounds_width and image_height > 1.25 * bounds_height

if not is_upscaled:
image = Image.crop(image, Bounds(0, 0, *params.bounds.extent))
if len(params.regions) == 0:
if behavior is ApplyBehavior.replace:
self.layers.update_layer_image(self.layers.active, image, params.bounds)
else:
name = f"{prefix}{trim_text(params.name, 200)} ({params.seed})"
self.layers.create(name, image, params.bounds)
if is_upscaled:
self.layers.create(name, image, Bounds(0, 0, *image.extent))
else:
self.layers.create(name, image, params.bounds)
else: # apply to regions
with RestoreActiveLayer(self.layers) as restore:
active_id = Region.link_target(self.layers.active).id_string
Expand Down Expand Up @@ -867,7 +874,7 @@ def _set_factor(self, value: float):
self._update_can_generate()

def _update_can_generate(self):
self.can_generate = not self._in_progress
self.can_generate = not self._in_progress and (self.factor > 1.0 or self.use_diffusion)

@property
def target_extent(self):
Expand Down