mirror of
https://github.com/akatrevorjay/edid-generator.git
synced 2026-01-15 23:50:28 +01:00
Detect ratio of given mode to ensure it is supported
This commit is contained in:
@@ -12,7 +12,7 @@
|
|||||||
#define REVISION 3
|
#define REVISION 3
|
||||||
#define XOFFSET 48
|
#define XOFFSET 48
|
||||||
#define YOFFSET (63+3)
|
#define YOFFSET (63+3)
|
||||||
#define XY_RATIO XY_RATIO_16_9
|
#define XY_RATIO XY_RATIO_16_10
|
||||||
#define YBLANK 52
|
#define YBLANK 52
|
||||||
#define XBLANK 160
|
#define XBLANK 160
|
||||||
#define TIMING_NAME "2880x1800"
|
#define TIMING_NAME "2880x1800"
|
||||||
|
|||||||
BIN
2880x1800.bin
BIN
2880x1800.bin
Binary file not shown.
@@ -1,12 +1,33 @@
|
|||||||
#!/bin/zsh
|
#!/bin/zsh
|
||||||
emulate -L zsh
|
emulate -L zsh
|
||||||
|
zmodload zsh/mathfunc
|
||||||
|
|
||||||
setopt errexit errreturn
|
setopt errexit errreturn
|
||||||
#setopt xtrace
|
#setopt xtrace
|
||||||
|
|
||||||
|
|
||||||
|
find-supported-ratio() {
|
||||||
|
local x=$1 y=$2 default=$3; shift 3
|
||||||
|
[ $# -gt 0 ] || set -- 16:10 16:9 4:3 5:4 # supported already in edid.S
|
||||||
|
|
||||||
|
local -A vals=()
|
||||||
|
local r
|
||||||
|
for r in "$@"; do
|
||||||
|
local -i rx=${r%%:*} ry=${r#*:}
|
||||||
|
local v=$(( abs( $x / $rx - $y / $ry ) ))
|
||||||
|
vals[$v]=$r
|
||||||
|
done
|
||||||
|
|
||||||
|
local best=${vals[0]}
|
||||||
|
[[ -n $best ]] || best=$default
|
||||||
|
|
||||||
|
echo $best
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
template-S() {
|
template-S() {
|
||||||
[[ ${(L)1} = mode(|line) ]] || return 1
|
[[ ${(L)1} = mode(|line) ]] || return 1
|
||||||
echo "-- Found naughty unicorn: $@"
|
echo "-- Found modeline: $@"
|
||||||
shift 1
|
shift 1
|
||||||
|
|
||||||
local name="${1//\"}"
|
local name="${1//\"}"
|
||||||
@@ -21,7 +42,7 @@ template-S() {
|
|||||||
local -i vdisp="$1" vsyncstart="$2" vsyncend="$3" vtotal="$4"; shift 4
|
local -i vdisp="$1" vsyncstart="$2" vsyncend="$3" vtotal="$4"; shift 4
|
||||||
|
|
||||||
local -i hsync_polarity=0 vsync_polarity=0 dpi=96 vfreq_hz=60
|
local -i hsync_polarity=0 vsync_polarity=0 dpi=96 vfreq_hz=60
|
||||||
local edid_version="1.3" ratio="16:9" # TODO calc ratio
|
local edid_version="1.3" ratio="compute"
|
||||||
|
|
||||||
local arg
|
local arg
|
||||||
for arg in "$@"; do
|
for arg in "$@"; do
|
||||||
@@ -36,32 +57,44 @@ template-S() {
|
|||||||
esac
|
esac
|
||||||
done
|
done
|
||||||
|
|
||||||
|
case $ratio in
|
||||||
|
compute)
|
||||||
|
# 16:9 is the default here if it can't find one that matches nicely.
|
||||||
|
ratio=$(find-supported-ratio $hdisp $vdisp 'ERROR')
|
||||||
|
printf 'Computed ratio: %s' $ratio
|
||||||
|
[[ $ratio != 'ERROR' ]] || return 1
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
|
||||||
local -A defines
|
local -A defines
|
||||||
defines=(
|
defines=(
|
||||||
VERSION "${edid_version%%.*}"
|
TIMING_NAME "${(qqq)name}"
|
||||||
REVISION "${edid_version#*.}"
|
|
||||||
CLOCK "$pixel_clock_khz"
|
CLOCK "$pixel_clock_khz"
|
||||||
XPIX "$hdisp"
|
XPIX "$hdisp"
|
||||||
YPIX "$vdisp"
|
|
||||||
XY_RATIO "XY_RATIO_${(U)ratio//:/_}"
|
|
||||||
XBLANK "$((htotal - hdisp))"
|
XBLANK "$((htotal - hdisp))"
|
||||||
YBLANK "$((vtotal - vdisp))"
|
|
||||||
XOFFSET "$((hsyncstart - hdisp))"
|
XOFFSET "$((hsyncstart - hdisp))"
|
||||||
XPULSE "$((hsyncend - hsyncstart))"
|
XPULSE "$((hsyncend - hsyncstart))"
|
||||||
|
|
||||||
|
YPIX "$vdisp"
|
||||||
|
YBLANK "$((vtotal - vdisp))"
|
||||||
YOFFSET "(63+$((vsyncstart - vdisp)))"
|
YOFFSET "(63+$((vsyncstart - vdisp)))"
|
||||||
YPULSE "(63+$((vsyncend - vsyncstart)))"
|
YPULSE "(63+$((vsyncend - vsyncstart)))"
|
||||||
|
|
||||||
|
VERSION "${edid_version%%.*}"
|
||||||
|
REVISION "${edid_version#*.}"
|
||||||
|
|
||||||
|
XY_RATIO "XY_RATIO_${(U)ratio//:/_}"
|
||||||
DPI "$dpi"
|
DPI "$dpi"
|
||||||
VFREQ "$vfreq_hz"
|
VFREQ "$vfreq_hz"
|
||||||
TIMING_NAME "${(qqq)name}"
|
|
||||||
HSYNC_POL "$hsync_polarity"
|
HSYNC_POL "$hsync_polarity"
|
||||||
VSYNC_POL "$vsync_polarity"
|
VSYNC_POL "$vsync_polarity"
|
||||||
)
|
)
|
||||||
|
|
||||||
local lines=('/* '"$name: $REPLY"' */') # removed -a option
|
local -a lines=('/* '"$name: $REPLY"' */')
|
||||||
local k
|
local k
|
||||||
for k in "${(@k)defines}"; do
|
for k in ${(k)defines}; do
|
||||||
lines+=("#define $k ${defines[$k]}")
|
lines+=("#define $k ${defines[$k]}")
|
||||||
|
|
||||||
done
|
done
|
||||||
lines+=('#include "edid.S"')
|
lines+=('#include "edid.S"')
|
||||||
|
|
||||||
@@ -75,7 +108,7 @@ local f=${1:-'-'}
|
|||||||
if [[ -z "$f" || "$f" == "-h" ]]; then
|
if [[ -z "$f" || "$f" == "-h" ]]; then
|
||||||
self=${0:t}
|
self=${0:t}
|
||||||
cat >&2 <<-EOF
|
cat >&2 <<-EOF
|
||||||
Modeline2EDID, version forever 0.0.1
|
${0:t}, version forever 0.0.1
|
||||||
Help:
|
Help:
|
||||||
$self -h
|
$self -h
|
||||||
Parse modelines from stdin:
|
Parse modelines from stdin:
|
||||||
@@ -87,7 +120,7 @@ if [[ -z "$f" || "$f" == "-h" ]]; then
|
|||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
echo "Searching for runaway unicorns in '$f'"
|
echo "Searching for modelines in '$f'"
|
||||||
while read; do
|
while read; do
|
||||||
# trim
|
# trim
|
||||||
REPLY=($=REPLY)
|
REPLY=($=REPLY)
|
||||||
|
|||||||
Reference in New Issue
Block a user