From 6d9dec96c2e909c14d15deb4b2367e87011f68ee Mon Sep 17 00:00:00 2001 From: Mattias Andrée Date: Fri, 23 May 2014 16:37:42 +0200 Subject: parse edid MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Mattias Andrée --- src/edid.c | 79 +++++++++++++++++++++++++++++++++++++++++++++++++++ src/edid.h | 39 +++++++++++++++++++++++++ src/gamma-linux-drm.c | 19 +++++++------ src/gamma-x-randr.c | 1 + src/libgamma-error.h | 33 +++++++++++++++++++++ 5 files changed, 163 insertions(+), 8 deletions(-) create mode 100644 src/edid.c create mode 100644 src/edid.h (limited to 'src') diff --git a/src/edid.c b/src/edid.c new file mode 100644 index 0000000..09b3ef5 --- /dev/null +++ b/src/edid.c @@ -0,0 +1,79 @@ +/** + * libgamma — Display server abstraction layer for gamma ramp adjustments + * Copyright © 2014 Mattias Andrée (maandree@member.fsf.org) + * + * This library is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this library. If not, see . + */ +#include "edid.h" + +#include "libgamma-method.h" +#include "libgamma-error.h" + +#include + + +/** + * Parse the EDID of a monitor + * + * @param this Instance of a data structure to fill with the information about the EDID. + * It must contain the EDID and its length. + * @param feilds OR:ed identifiers for the information about the EDID that should be parsed. + * Fields that do not have to do with EDID are ignored. + * @return Non-zero on error + */ +int libgamma_parse_edid(libgamma_crtc_information_t* restrict this, int32_t fields) +{ +#define __test_version(edid, major, minor) (((edid)[18] == major) && ((edid)[19] == minor)) + + int error = 0; + int checksum = 0; + size_t i; + + if (this->edid_length != 128) + error = LIBGAMMA_EDID_LENGTH_UNSUPPORTED; + else if ((this->edid[0] != 0x00) || (this->edid[1] != 0xFF) || (this->edid[2] != 0xFF) || (this->edid[3] != 0xFF) || + (this->edid[4] != 0xFF) || (this->edid[5] != 0xFF) || (this->edid[6] != 0xFF) || (this->edid[7] != 0x00)) + error = LIBGAMMA_EDID_WRONG_MAGIC_NUMBER; + else if (__test_version(this->edid, 1, 3) == 0) + error = LIBGAMMA_EDID_REVISION_UNSUPPORTED; + + this->width_mm_edid_error = this->height_mm_edid_error = this->gamma_error = error; + + this->width_mm_edid = (size_t)(this->edid[21]) * 10; + this->height_mm_edid = (size_t)(this->edid[22]) * 10; + + if ((fields & CRTC_INFO_GAMMA) && (error == 0)) + { + if (this->edid[23] == 0xFF) + this->gamma_error = LIBGAMMA_GAMMA_NOT_SPECIFIED; + else + this->gamma_red = this->gamma_green = this->gamma_blue = (float)((int)(this->edid[23]) + 100) / 100.f; + } + + if (error == 0) + for (i = 0; i < this->edid_length; i++) + checksum += (int)(this->edid[i]); + if ((checksum & 255)) + { + error = LIBGAMMA_EDID_CHECKSUM_ERROR; + this->edid_error = this->width_mm_edid_error = this->height_mm_edid_error = error; + this->gamma_error = this->gamma_error == LIBGAMMA_GAMMA_NOT_SPECIFIED + ? LIBGAMMA_GAMMA_NOT_SPECIFIED_AND_EDID_CHECKSUM_ERROR : 0; + } + + return error | this->gamma_error; + +#undef __test_version +} + diff --git a/src/edid.h b/src/edid.h new file mode 100644 index 0000000..321a7df --- /dev/null +++ b/src/edid.h @@ -0,0 +1,39 @@ +/** + * libgamma — Display server abstraction layer for gamma ramp adjustments + * Copyright © 2014 Mattias Andrée (maandree@member.fsf.org) + * + * This library is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this library. If not, see . + */ +#ifndef LIBGAMMA_EDID_H +#define LIBGAMMA_EDID_H + +#include "libgamma-method.h" + +#include + + +/** + * Parse the EDID of a monitor + * + * @param this Instance of a data structure to fill with the information about the EDID. + * It must contain the EDID and its length. + * @param feilds OR:ed identifiers for the information about the EDID that should be parsed. + * Fields that do not have to do with EDID are ignored. + * @return Non-zero on error + */ +int libgamma_parse_edid(libgamma_crtc_information_t* restrict out, int32_t fields); + + +#endif + diff --git a/src/gamma-linux-drm.c b/src/gamma-linux-drm.c index 9539700..4ac0022 100644 --- a/src/gamma-linux-drm.c +++ b/src/gamma-linux-drm.c @@ -24,6 +24,7 @@ #include "gamma-linux-drm.h" #include "libgamma-error.h" +#include "edid.h" #include #include @@ -660,10 +661,10 @@ int libgamma_linux_drm_get_crtc_information(libgamma_crtc_information_t* restric if ((connector = find_connector(crtc, &error)) == NULL) { e |= this->width_mm_error = this->height_mm_error - = this->connector_type = this->subpixel_order_error - = this->active_error = this->connector_name_error - = this->edid_error = this->gamma_error - = this->width_mm_edid_error = this->height_mm_edid_error = error; + = this->connector_type = this->subpixel_order_error + = this->active_error = this->connector_name_error + = this->edid_error = this->gamma_error + = this->width_mm_edid_error = this->height_mm_edid_error = error; goto cont; } if ((fields & (CRTC_INFO_WIDTH_MM | CRTC_INFO_HEIGHT_MM | CRTC_INFO_SUBPIXEL_ORDER | CRTC_INFO_CONNECTOR_TYPE))) @@ -672,10 +673,12 @@ int libgamma_linux_drm_get_crtc_information(libgamma_crtc_information_t* restric goto cont; e |= get_edid(crtc, this, connector); if (this->edid == NULL) - goto cont; - e |= this->width_mm_edid_error = _E(CRTC_INFO_WIDTH_MM_EDID); /* TODO */ - e |= this->height_mm_edid_error = _E(CRTC_INFO_HEIGHT_MM_EDID); /* TODO */ - e |= this->gamma_error = _E(CRTC_INFO_GAMMA); /* TODO */ + { + this->gamma_error = this->width_mm_edid_error = this->height_mm_edid_error = this->edid_error; + goto cont; + } + if ((fields & (CRTC_INFO_WIDTH_MM_EDID | CRTC_INFO_HEIGHT_MM_EDID | CRTC_INFO_GAMMA))) + e |= libgamma_parse_edid(this, fields); cont: e |= (fields & CRTC_INFO_GAMMA_SIZE) ? get_gamma_ramp_size(this, crtc) : 0; this->gamma_depth = 16; diff --git a/src/gamma-x-randr.c b/src/gamma-x-randr.c index 99a5a21..1d7b4bd 100644 --- a/src/gamma-x-randr.c +++ b/src/gamma-x-randr.c @@ -22,6 +22,7 @@ #include "gamma-x-randr.h" #include "libgamma-error.h" +#include "edid.h" #include #include diff --git a/src/libgamma-error.h b/src/libgamma-error.h index ba8ec86..c4da13c 100644 --- a/src/libgamma-error.h +++ b/src/libgamma-error.h @@ -179,6 +179,39 @@ extern const char* libgamma_group_name; */ #define LIBGAMMA_SUBPIXEL_ORDER_NOT_RECOGNISED (-27) +/** + * The length of the EDID does not match that of any supported EDID structure revision + */ +#define LIBGAMMA_EDID_LENGTH_UNSUPPORTED (-28) + +/** + * The magic number in the EDID does not match that of any supported EDID structure revision + */ +#define LIBGAMMA_EDID_WRONG_MAGIC_NUMBER (-29) + +/** + * The EDID structure revision used by the monitor is not supported + */ +#define LIBGAMMA_EDID_REVISION_UNSUPPORTED (-30) + +/** + * The gamma characteristics field in the EDID is left unspecified + * (This could be considered a non-error) + */ +#define LIBGAMMA_GAMMA_NOT_SPECIFIED (-31) + +/** + * The checksum in the EDID is incorrect, all request information has been provided + * by you cannot count on it. + */ +#define LIBGAMMA_EDID_CHECKSUM_ERROR (-32) + +/** + * Both of the errors `LIBGAMMA_GAMMA_NOT_SPECIFIED` and + * `LIBGAMMA_EDID_CHECKSUM_ERROR` have occurred + */ +#define LIBGAMMA_GAMMA_NOT_SPECIFIED_AND_EDID_CHECKSUM_ERROR (-33) + #endif -- cgit v1.2.3-70-g09d2