Enhance image editing tests and functionality

- Added parameterized tests for image edit replacement to ensure alpha mode preservation.
- Refactored existing tests to utilize new image editing methods and improve clarity.
- Introduced new tests for image target functionality, ensuring proper handling of shared textures and context.
- Updated various tests to validate alpha mode handling across different scenarios.
- Improved undo/redo functionality in image operators to maintain state consistency.
- Added support for texture node actions, enhancing integration with Blender's node system.
- Ensured that image properties are preserved during operations and that invalid contexts are handled gracefully.
This commit is contained in:
2026-09-10 00:00:13 +08:00
parent f48bbb3d05
commit 1622afa7a2
28 changed files with 1068 additions and 236 deletions

View File

@@ -1,6 +1,7 @@
import bpy
from .common.image import is_image_empty
from .common.image_target import active_texture_node, image_edit_owner, owner_image
from .operators.upscale import upscale_output_size
@@ -9,8 +10,6 @@ class AnyImageImageMenu(bpy.types.Menu):
bl_label = "AnyImage"
def draw(self, context):
from .properties import ai_setup_label, ai_status
layout = self.layout
layout.operator_context = "INVOKE_DEFAULT"
layout.operator(
@@ -29,37 +28,52 @@ class AnyImageImageMenu(bpy.types.Menu):
icon="MOD_DISPLACE",
)
layout.separator()
draw_image_actions(layout, context)
class AnyImageTextureNodeMenu(bpy.types.Menu):
bl_idname = "ANYIMAGE_MT_texture_node_context"
bl_label = "AnyImage"
def draw(self, context):
draw_image_actions(self.layout, context)
def draw_image_actions(layout, context):
from .properties import ai_setup_label, ai_status
layout.operator_context = "INVOKE_DEFAULT"
layout.operator(
"anyimage.remove_image_background",
text="Remove Background",
icon="IMAGE_ALPHA",
)
layout.operator(
"anyimage.upscale_image",
text=upscale_menu_label(context),
icon="FULLSCREEN_ENTER",
)
layout.separator()
status = ai_status()
if status["ready"]:
layout.operator(
"anyimage.remove_image_background",
text="Remove Background",
icon="IMAGE_ALPHA",
"anyimage.open_ai_environment_settings",
text="Settings",
icon="PREFERENCES",
)
else:
layout.operator(
"anyimage.upscale_image",
text=upscale_menu_label(context),
icon="FULLSCREEN_ENTER",
"anyimage.setup_ai_environment",
text=ai_setup_label(status),
icon="IMPORT",
)
layout.separator()
status = ai_status()
if status["ready"]:
layout.operator(
"anyimage.open_ai_environment_settings",
text="Settings",
icon="PREFERENCES",
)
else:
layout.operator(
"anyimage.setup_ai_environment",
text=ai_setup_label(status),
icon="IMPORT",
)
def upscale_menu_label(context):
source_object = getattr(context, "object", None)
if not is_image_empty(source_object):
owner = image_edit_owner(context)
if owner is None:
return "Upscale"
output_size = upscale_output_size(source_object.data)
output_size = upscale_output_size(owner_image(owner))
if output_size is None:
return "Upscale"
width, height = output_size
@@ -71,3 +85,10 @@ def draw_image_context_menu(self, context):
return
self.layout.menu(AnyImageImageMenu.bl_idname, text="AnyImage", icon="PLUGIN")
self.layout.separator()
def draw_texture_node_context_menu(self, context):
if active_texture_node(context) is None:
return
self.layout.menu(AnyImageTextureNodeMenu.bl_idname, text="AnyImage", icon="PLUGIN")
self.layout.separator()