Skip to content

Commit

Permalink
fix: apply rotations and flips and drop alpha channel on data before …
Browse files Browse the repository at this point in the history
…storing it in `raw_data`
  • Loading branch information
sassanh committed Jul 5, 2024
1 parent 82dfafd commit bfee22f
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 3 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# Changelog

## Version 0.9.2

- fix: apply rotations and flips and drop alpha channel on data before storing it
in `raw_data`

## Version 0.9.1

- fix: consider alpha channel in the data stored in `raw_data` field of `HeadlessWidget`
Expand Down
9 changes: 8 additions & 1 deletion headless_kivy/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -244,9 +244,16 @@ def render_on_display(self: HeadlessWidget, *_: object) -> None:
except Empty:
last_thread = None

data = data.reshape(self.width, self.height, -1)[:, :, :3].astype(np.uint16)
data = np.rot90(data, config.rotation())
if config.flip_horizontal():
data = np.fliplr(data)
if config.flip_vertical():
data = np.flipud(data)

HeadlessWidget.raw_data[self.x : self.x + self.width][
self.y : self.y + self.height
] = data.reshape(self.width, self.height, -1)
] = data

thread = Thread(
target=config.callback(),
Expand Down
2 changes: 1 addition & 1 deletion headless_kivy/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ def setup_headless_kivy(config: SetupHeadlessConfig) -> None:
from headless_kivy import HeadlessWidget

HeadlessWidget.raw_data = np.zeros(
(int(dp(width())), int(dp(height())), 4),
(width(), height(), 3),
dtype=np.uint8,
)

Expand Down
1 change: 1 addition & 0 deletions headless_kivy_pytest/fixtures/snapshot.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ def write_image(image_path: Path, array: NDArray) -> None:
import png

png.Writer(
alpha=False,
width=array.shape[0],
height=array.shape[1],
greyscale=False, # pyright: ignore [reportArgumentType]
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 = "headless-kivy"
version = "0.9.1"
version = "0.9.2"
description = "Headless renderer for Kivy framework"
authors = ["Sassan Haradji <[email protected]>"]
license = "Apache-2.0"
Expand Down

0 comments on commit bfee22f

Please sign in to comment.