2023-04-11 02:15:57 +00:00
|
|
|
from logging import getLogger
|
2023-11-19 00:13:13 +00:00
|
|
|
from typing import Optional
|
2023-04-11 02:15:57 +00:00
|
|
|
|
|
|
|
from PIL import Image
|
|
|
|
|
|
|
|
from ..params import ImageParams, StageParams
|
|
|
|
from ..server import ServerContext
|
|
|
|
from ..worker import ProgressCallback, WorkerContext
|
2023-11-18 23:18:23 +00:00
|
|
|
from .base import BaseStage
|
2023-11-19 00:08:38 +00:00
|
|
|
from .result import StageResult
|
2023-04-11 02:15:57 +00:00
|
|
|
|
|
|
|
logger = getLogger(__name__)
|
|
|
|
|
|
|
|
|
2023-07-02 23:21:21 +00:00
|
|
|
class BlendLinearStage(BaseStage):
|
2023-07-01 12:10:53 +00:00
|
|
|
def run(
|
|
|
|
self,
|
2023-07-15 23:54:54 +00:00
|
|
|
_worker: WorkerContext,
|
2023-07-01 12:10:53 +00:00
|
|
|
_server: ServerContext,
|
|
|
|
_stage: StageParams,
|
|
|
|
_params: ImageParams,
|
2023-11-19 00:08:38 +00:00
|
|
|
sources: StageResult,
|
2023-07-01 12:10:53 +00:00
|
|
|
*,
|
|
|
|
alpha: float,
|
2023-07-04 18:29:58 +00:00
|
|
|
stage_source: Optional[Image.Image] = None,
|
2023-07-01 12:10:53 +00:00
|
|
|
_callback: Optional[ProgressCallback] = None,
|
|
|
|
**kwargs,
|
2023-11-19 00:08:38 +00:00
|
|
|
) -> StageResult:
|
2023-07-04 18:29:58 +00:00
|
|
|
logger.info("blending source images using linear interpolation")
|
2023-04-11 02:15:57 +00:00
|
|
|
|
2023-11-19 00:13:13 +00:00
|
|
|
return StageResult(
|
2023-11-20 00:39:39 +00:00
|
|
|
images=[
|
|
|
|
Image.blend(source, stage_source, alpha)
|
|
|
|
for source in sources.as_image()
|
|
|
|
]
|
2023-11-19 00:13:13 +00:00
|
|
|
)
|