Skip to content

Commit

Permalink
Fix HDR Static Metadata Data Block
Browse files Browse the repository at this point in the history
  • Loading branch information
N-Nagorny committed Dec 18, 2023
1 parent 70cd2dc commit abcf2b2
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 12 deletions.
4 changes: 2 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ if (BUILD_TESTS)
if(RUN_TESTS)
add_custom_command(TARGET roundtrip-tester POST_BUILD
COMMAND ${CMAKE_SOURCE_DIR}/scripts/linuxhw_coverage.sh
ARGS ${CMAKE_BINARY_DIR}/roundtrip-tester 40697 ${LINUXHW_EDID_DIR}
ARGS ${CMAKE_BINARY_DIR}/roundtrip-tester 40697 ${LINUXHW_EDID_DIR} ${CMAKE_BINARY_DIR}/test_result
)
endif()

Expand All @@ -225,7 +225,7 @@ if (BUILD_TESTS)
if(RUN_TESTS)
add_custom_command(TARGET json-roundtrip-tester POST_BUILD
COMMAND ${CMAKE_SOURCE_DIR}/scripts/linuxhw_coverage.sh
ARGS ${CMAKE_BINARY_DIR}/json-roundtrip-tester 35643 ${LINUXHW_EDID_DIR}
ARGS ${CMAKE_BINARY_DIR}/json-roundtrip-tester 35643 ${LINUXHW_EDID_DIR} ${CMAKE_BINARY_DIR}/test_result_json
)
endif()

Expand Down
9 changes: 5 additions & 4 deletions scripts/linuxhw_download.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ function download_edid_db {

function decoded_to_binary {
local INDEX_PATH="${1}"
# IGNORE contains EDID read failures
local IGNORE=(
"Digital/Apple/APPAE22/F1F2AA8940D8"
"Digital/Apple/APPAE22/89635EDE05B1"
Expand All @@ -32,9 +33,6 @@ function decoded_to_binary {
"Digital/Others/MSF1003/03CA7D56B4D6"
"Digital/BOE/BOE9001/33E71EDD4E0D"
"Digital/Dell/DEL4284/317CAF62DB5C"
"Digital/Corsair/CRM1B1C/A22F34D527B5"
"Digital/Corsair/CRM1B1C/D8C47E01839A"
"Digital/Corsair/CRM1B1C/D6A169A461AA"
)
local BINARY_PATH="$(echo "${INDEX_PATH}" | sed 's/decoded/binary/')"

Expand All @@ -51,7 +49,10 @@ function decoded_to_binary {
done
if [ "$IS_IGNORED" = "false" ]; then
cat "$file" | grep -E '^([a-f0-9]{32}|[a-f0-9 ]{47})$' | tr -d '[:space:]' | xxd -r -p > "$file".bin
echo "${file}.bin" >> "${BINARY_PATH}"
# Also ignore EDIDs larger than 256 bytes
if [[ $(wc -c "${file}.bin" | cut -d' ' -f1) -lt 257 ]]; then
echo "${file}.bin" >> "${BINARY_PATH}"
fi
fi
done
}
Expand Down
3 changes: 3 additions & 0 deletions src/cta861_block.cc
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,9 @@ namespace Edid {
case CTA861_EXTENDED_COLORIMETRY_BLOCK_TAG:
data_block_ptr = std::make_unique<CtaDataBlock>(std::move(ColorimetryDataBlock::parse_byte_block(iter_read)));
break;
case CTA861_EXTENDED_HDR_STATIC_METADATA_BLOCK_TAG:
data_block_ptr = std::make_unique<CtaDataBlock>(std::move(HdrStaticMetadataDataBlock::parse_byte_block(iter_read)));
break;
default:
data_block_ptr = std::make_unique<CtaDataBlock>(std::move(UnknownDataBlock::parse_byte_block(iter_read)));
}
Expand Down
15 changes: 9 additions & 6 deletions src/cta_data_block.cc
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ namespace Edid {
std::to_string(data_block_tag)
);

int extended_tag = *iter++;
int extended_tag = *iter++; size_remainder--;
if (extended_tag != CTA861_EXTENDED_HDR_STATIC_METADATA_BLOCK_TAG)
throw EdidException(__FUNCTION__, "HDR Static Metadata Data Block has incorrect Extended Data Block Tag: " +
std::to_string(extended_tag)
Expand Down Expand Up @@ -234,11 +234,11 @@ namespace Edid {

void HdrStaticMetadataDataBlock::print(std::ostream& os, uint8_t tabs) const {
const auto get_luminance = [](uint8_t cv) -> float {
return 50 * std::pow(2.0, cv / 32);
return 50.0 * std::pow(2.0, cv / 32.0);
};

const auto get_min_luminance = [](uint8_t cv, float max_luminanace) -> float {
return max_luminanace * std::pow(cv / 255, 2.0) / 100;
return max_luminanace * std::pow(cv / 255.0, 2.0) / 100.0;
};

std::string indent(tabs, '\t');
Expand All @@ -257,15 +257,18 @@ namespace Edid {

if (max_luminance_code_value.has_value()) {
os << indent << "Desired Max luminance: " <<
get_luminance(*max_luminance_code_value) << " cd/m^2\n";
static_cast<uint16_t>(*max_luminance_code_value) << " (" <<
get_luminance(*max_luminance_code_value) << " cd/m^2)\n";
}
if (max_frame_average_luminance_code_value.has_value()) {
os << indent << "Desired Max frame-average luminance: " <<
get_luminance(*max_frame_average_luminance_code_value) << " cd/m^2\n";
static_cast<uint16_t>(*max_frame_average_luminance_code_value) << " (" <<
get_luminance(*max_frame_average_luminance_code_value) << " cd/m^2)\n";
}
if (min_luminance_code_value.has_value()) {
os << indent << "Desired Min luminance: " <<
get_min_luminance(*min_luminance_code_value, get_luminance(*max_luminance_code_value)) << " cd/m^2\n";
static_cast<uint16_t>(*min_luminance_code_value) << " (" <<
get_min_luminance(*min_luminance_code_value, get_luminance(*max_luminance_code_value)) << " cd/m^2)\n";
}
}
} // namespace Edid
5 changes: 5 additions & 0 deletions src/json.cc
Original file line number Diff line number Diff line change
Expand Up @@ -434,6 +434,11 @@ namespace Edid {
from_json(j, subresult);
descriptor = subresult;
}
else if (j.contains("static_metadata_types")) {
HdrStaticMetadataDataBlock subresult;
from_json(j, subresult);
descriptor = subresult;
}
else if (j.contains("hdmi_vsdb")) {
HdmiVendorDataBlock subresult;
from_json(j, subresult);
Expand Down

0 comments on commit abcf2b2

Please sign in to comment.