Skip to content

Commit

Permalink
jovian-updater-logo-helper: Add support for BGRT
Browse files Browse the repository at this point in the history
  • Loading branch information
samueldr committed Nov 1, 2024
1 parent 617d644 commit 38e4b8e
Showing 1 changed file with 78 additions and 8 deletions.
86 changes: 78 additions & 8 deletions pkgs/jovian-updater-logo-helper/jovian-updater-logo-helper.sh
Original file line number Diff line number Diff line change
Expand Up @@ -51,14 +51,84 @@ MAGICK_INVOCATION=(
"canvas:black[${image_width}x${image_height}!]"
)

MAGICK_INVOCATION+=(
# Add the logo
"$logo"
# Centered
-gravity center
# (This means 'add')
-composite
)
if [[ "$logo" == "--bgrt" ]]; then
# Status field described here:
# - https://uefi.org/htmlspecs/ACPI_Spec_6_4_html/05_ACPI_Software_Programming_Model/ACPI_Software_Programming_Model.html#boot-graphics-resource-table-bgrt
bgrt_rotation="$(( ($(cat /sys/firmware/acpi/bgrt/status) >> 1) & 2#11 ))"
bgrt_xoffset=$(cat /sys/firmware/acpi/bgrt/xoffset)
bgrt_yoffset=$(cat /sys/firmware/acpi/bgrt/yoffset)
bgrt_dimensions="$(magick identify /sys/firmware/acpi/bgrt/image | cut -d' ' -f3)"
bgrt_height=${bgrt_dimensions#*x}
bgrt_width=${bgrt_dimensions%x*}

case "$bgrt_rotation" in
"$(( 2#00 ))")
bgrt_offset="+$((
bgrt_xoffset
))+$((
bgrt_yoffset
))"
bgrt_rotation="0"
;;
"$(( 2#01 ))") # 90
bgrt_offset="+$((
image_height - bgrt_height - bgrt_yoffset
))+$((
bgrt_xoffset
))"
bgrt_rotation="90"
;;
"$(( 2#10 ))") # 180
bgrt_offset="+$((
image_width - bgrt_width - bgrt_xoffset
))+$((
image_height - bgrt_height - bgrt_yoffset
))"
bgrt_rotation="180"
;;
"$(( 2#11 ))") # -90
bgrt_offset="+$((
bgrt_yoffset
))+$((
image_width - bgrt_width - bgrt_xoffset
))"
bgrt_rotation="-90"
;;
esac

MAGICK_INVOCATION+=(
# Put the canvas back into the panel native orientation.
-rotate -$(( display_rotation ))

# Add the BGRT (bmp image)
# Group operation so we don't operate on the canvas.
'('
# Load the image
"/sys/firmware/acpi/bgrt/image"

# Rotate the BGRT to its expected rotation for composition
-rotate $(( bgrt_rotation ))

# At its defined offset, again considering pre-composed rotation
-geometry "$bgrt_offset"
')'

# (This means 'add' for the previous image)
-composite

# Undo the native orientation we added back.
-rotate $(( display_rotation ))
)
else
MAGICK_INVOCATION+=(
# Add the logo
"$logo"
# Centered
-gravity center
# (This means 'add')
-composite
)
fi

# Final fixups to the image
MAGICK_INVOCATION+=(
Expand Down

0 comments on commit 38e4b8e

Please sign in to comment.