wlroots/render/gen_pixel_format.sh

88 lines
1.9 KiB
Bash
Raw Normal View History

#!/bin/sh -eu
#
# usage: gen_pixel_format.sh pixel_format_table.c
KDFS=${KDFS:-kdfs}
output_file="$1"
gen_info() {
"$KDFS" show --json 'DRM_FORMAT_*' | jq -r '
to_entries[]
| select((.value.bytes_plane | length) == 1)
|
" {\n" +
" .drm_format = \(.key),\n" +
" .bytes_per_block = \(.value.bytes_plane[0]),\n" +
" .block_width = \(.value.texel_block_dimension[0]),\n" +
" .block_height = \(.value.texel_block_dimension[1]),\n" +
" },"
'
}
gen_opaque() {
"$KDFS" show --json 'DRM_FORMAT_*' | jq -r '
to_entries[]
| select(any(.value.sample_info[]; .channel == "a") | not)
| " case \(.key):"
'
}
gen_opaque_substitute() {
"$KDFS" compat --json --with 'DRM_FORMAT_*' --filter-channel=a --strip-channel=a 'DRM_FORMAT_*' | jq -r '
to_entries[]
| select((.value | to_entries[] | select(.value.little_endian and .value.big_endian) | length) > 0)
| (.key as $format | .value | to_entries[] | { format: $format, opaque_substitute: .key })
|
" case \(.format):\n" +
" return \(.opaque_substitute);"
'
}
gen_ycbcr() {
"$KDFS" show --json 'DRM_FORMAT_*' | jq -r '
to_entries[]
| select(.value.color_model == "yuvsda")
| " case \(.key):"
'
}
cat >"$output_file" << EOF
// Generated by gen_pixel_formats.sh - DO NOT EDIT
#include <drm_fourcc.h>
#include "render/pixel_format.h"
const struct wlr_pixel_format_info pixel_format_info[] = {
$(gen_info)
};
const size_t pixel_format_info_len = sizeof(pixel_format_info) / sizeof(pixel_format_info[0]);
bool pixel_format_is_opaque(uint32_t format) {
switch (format) {
$(gen_opaque)
return true;
default:
return false;
}
}
uint32_t pixel_format_get_opaque_substitute(uint32_t format) {
switch (format) {
$(gen_opaque_substitute)
default:
return DRM_FORMAT_INVALID;
}
}
bool pixel_format_is_ycbcr(uint32_t format) {
switch (format) {
$(gen_ycbcr)
return true;
default:
return false;
}
}
EOF