Skip to content

Commit

Permalink
fix: 加入图片成分色检查
Browse files Browse the repository at this point in the history
  • Loading branch information
filosfino committed Apr 29, 2021
1 parent fd7586f commit 8a08c0e
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 9 deletions.
13 changes: 5 additions & 8 deletions graphic_coloring_engine/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,23 +70,20 @@ class Layer:
order: int # 值越小越底层
bbox_coordinate: Coordinate
type: Literal["image", "text"]
polygon: MultiPolygon = field(default=None)
polygon: MultiPolygon = field(default=None) # 用于计算碰撞关系
dominant_colors: List[DominantColor] = field(default_factory=list) # 图片才有
color_mutable: bool = field(default=False) # 是否需要进行配色
color: Optional[Union[Color, ColorChoice]] = None

def __post_init__(self):
if self.type == "image":
self.color_mutable = False
if not self.dominant_colors:
logger.warn(f'image layer {self.order} has empty dominant colors')
if not self.color and self.dominant_color_with_highest_ratio:
self.color = self.dominant_color_with_highest_ratio
if not self.polygon:
self.polygon = MultiPolygon([self.bbox_coordinate.polygon])
if not self.color and self.dominant_color_with_highest_ratio:
self.color = self.dominant_color_with_highest_ratio

@staticmethod
def from_dict() -> "Layer":
# TODO
return

@cached_property
def dominant_color_with_highest_ratio(self) -> Optional[Color]:
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "graphic-coloring-engine"
version = "0.1.4"
version = "0.1.5"
description = "graphic coloring engine"
authors = ["filosfino <github@filosfino.com>"]
license = "MIT"
Expand Down

0 comments on commit 8a08c0e

Please sign in to comment.