src/video/x11/edid-parse.c
changeset 6796 424a12862805
child 6797 8a818a373436
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/src/video/x11/edid-parse.c	Mon Dec 31 18:32:30 2012 -0800
     1.3 @@ -0,0 +1,760 @@
     1.4 +/*
     1.5 + * Copyright 2007 Red Hat, Inc.
     1.6 + *
     1.7 + * Permission is hereby granted, free of charge, to any person obtaining a
     1.8 + * copy of this software and associated documentation files (the "Software"),
     1.9 + * to deal in the Software without restriction, including without limitation
    1.10 + * on the rights to use, copy, modify, merge, publish, distribute, sub
    1.11 + * license, and/or sell copies of the Software, and to permit persons to whom
    1.12 + * the Software is furnished to do so, subject to the following conditions:
    1.13 + *
    1.14 + * The above copyright notice and this permission notice (including the next
    1.15 + * paragraph) shall be included in all copies or substantial portions of the
    1.16 + * Software.
    1.17 + *
    1.18 + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
    1.19 + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
    1.20 + * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.  IN NO EVENT SHALL
    1.21 + * THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
    1.22 + * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
    1.23 + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
    1.24 + */
    1.25 +
    1.26 +/* Author: Soren Sandmann <sandmann@redhat.com> */
    1.27 +
    1.28 +#include "edid.h"
    1.29 +#include <stdlib.h>
    1.30 +#include <string.h>
    1.31 +#include <math.h>
    1.32 +
    1.33 +#define TRUE 1
    1.34 +#define FALSE 0
    1.35 +
    1.36 +static int
    1.37 +get_bit (int in, int bit)
    1.38 +{
    1.39 +    return (in & (1 << bit)) >> bit;
    1.40 +}
    1.41 +
    1.42 +static int
    1.43 +get_bits (int in, int begin, int end)
    1.44 +{
    1.45 +    int mask = (1 << (end - begin + 1)) - 1;
    1.46 +    
    1.47 +    return (in >> begin) & mask;
    1.48 +}
    1.49 +
    1.50 +static int
    1.51 +decode_header (const uchar *edid)
    1.52 +{
    1.53 +    if (memcmp (edid, "\x00\xff\xff\xff\xff\xff\xff\x00", 8) == 0)
    1.54 +	return TRUE;
    1.55 +    return FALSE;
    1.56 +}
    1.57 +
    1.58 +static int
    1.59 +decode_vendor_and_product_identification (const uchar *edid, MonitorInfo *info)
    1.60 +{
    1.61 +    int is_model_year;
    1.62 +    
    1.63 +    /* Manufacturer Code */
    1.64 +    info->manufacturer_code[0]  = get_bits (edid[0x08], 2, 6);
    1.65 +    info->manufacturer_code[1]  = get_bits (edid[0x08], 0, 1) << 3;
    1.66 +    info->manufacturer_code[1] |= get_bits (edid[0x09], 5, 7);
    1.67 +    info->manufacturer_code[2]  = get_bits (edid[0x09], 0, 4);
    1.68 +    info->manufacturer_code[3]  = '\0';
    1.69 +    
    1.70 +    info->manufacturer_code[0] += 'A' - 1;
    1.71 +    info->manufacturer_code[1] += 'A' - 1;
    1.72 +    info->manufacturer_code[2] += 'A' - 1;
    1.73 +
    1.74 +    /* Product Code */
    1.75 +    info->product_code = edid[0x0b] << 8 | edid[0x0a];
    1.76 +
    1.77 +    /* Serial Number */
    1.78 +    info->serial_number =
    1.79 +	edid[0x0c] | edid[0x0d] << 8 | edid[0x0e] << 16 | edid[0x0f] << 24;
    1.80 +
    1.81 +    /* Week and Year */
    1.82 +    is_model_year = FALSE;
    1.83 +    switch (edid[0x10])
    1.84 +    {
    1.85 +    case 0x00:
    1.86 +	info->production_week = -1;
    1.87 +	break;
    1.88 +
    1.89 +    case 0xff:
    1.90 +	info->production_week = -1;
    1.91 +	is_model_year = TRUE;
    1.92 +	break;
    1.93 +
    1.94 +    default:
    1.95 +	info->production_week = edid[0x10];
    1.96 +	break;
    1.97 +    }
    1.98 +
    1.99 +    if (is_model_year)
   1.100 +    {
   1.101 +	info->production_year = -1;
   1.102 +	info->model_year = 1990 + edid[0x11];
   1.103 +    }
   1.104 +    else
   1.105 +    {
   1.106 +	info->production_year = 1990 + edid[0x11];
   1.107 +	info->model_year = -1;
   1.108 +    }
   1.109 +
   1.110 +    return TRUE;
   1.111 +}
   1.112 +
   1.113 +static int
   1.114 +decode_edid_version (const uchar *edid, MonitorInfo *info)
   1.115 +{
   1.116 +    info->major_version = edid[0x12];
   1.117 +    info->minor_version = edid[0x13];
   1.118 +
   1.119 +    return TRUE;
   1.120 +}
   1.121 +
   1.122 +static int
   1.123 +decode_display_parameters (const uchar *edid, MonitorInfo *info)
   1.124 +{
   1.125 +    /* Digital vs Analog */
   1.126 +    info->is_digital = get_bit (edid[0x14], 7);
   1.127 +
   1.128 +    if (info->is_digital)
   1.129 +    {
   1.130 +	int bits;
   1.131 +	
   1.132 +	static const int bit_depth[8] =
   1.133 +	{
   1.134 +	    -1, 6, 8, 10, 12, 14, 16, -1
   1.135 +	};
   1.136 +
   1.137 +	static const Interface interfaces[6] =
   1.138 +	{
   1.139 +	    UNDEFINED, DVI, HDMI_A, HDMI_B, MDDI, DISPLAY_PORT
   1.140 +	};
   1.141 +
   1.142 +	bits = get_bits (edid[0x14], 4, 6);
   1.143 +	info->digital.bits_per_primary = bit_depth[bits];
   1.144 +
   1.145 +	bits = get_bits (edid[0x14], 0, 3);
   1.146 +	
   1.147 +	if (bits <= 5)
   1.148 +	    info->digital.interface = interfaces[bits];
   1.149 +	else
   1.150 +	    info->digital.interface = UNDEFINED;
   1.151 +    }
   1.152 +    else
   1.153 +    {
   1.154 +	int bits = get_bits (edid[0x14], 5, 6);
   1.155 +	
   1.156 +	static const double levels[][3] =
   1.157 +	{
   1.158 +	    { 0.7,   0.3,    1.0 },
   1.159 +	    { 0.714, 0.286,  1.0 },
   1.160 +	    { 1.0,   0.4,    1.4 },
   1.161 +	    { 0.7,   0.0,    0.7 },
   1.162 +	};
   1.163 +
   1.164 +	info->analog.video_signal_level = levels[bits][0];
   1.165 +	info->analog.sync_signal_level = levels[bits][1];
   1.166 +	info->analog.total_signal_level = levels[bits][2];
   1.167 +
   1.168 +	info->analog.blank_to_black = get_bit (edid[0x14], 4);
   1.169 +
   1.170 +	info->analog.separate_hv_sync = get_bit (edid[0x14], 3);
   1.171 +	info->analog.composite_sync_on_h = get_bit (edid[0x14], 2);
   1.172 +	info->analog.composite_sync_on_green = get_bit (edid[0x14], 1);
   1.173 +
   1.174 +	info->analog.serration_on_vsync = get_bit (edid[0x14], 0);
   1.175 +    }
   1.176 +
   1.177 +    /* Screen Size / Aspect Ratio */
   1.178 +    if (edid[0x15] == 0 && edid[0x16] == 0)
   1.179 +    {
   1.180 +	info->width_mm = -1;
   1.181 +	info->height_mm = -1;
   1.182 +	info->aspect_ratio = -1.0;
   1.183 +    }
   1.184 +    else if (edid[0x16] == 0)
   1.185 +    {
   1.186 +	info->width_mm = -1;
   1.187 +	info->height_mm = -1; 
   1.188 +	info->aspect_ratio = 100.0 / (edid[0x15] + 99);
   1.189 +    }
   1.190 +    else if (edid[0x15] == 0)
   1.191 +    {
   1.192 +	info->width_mm = -1;
   1.193 +	info->height_mm = -1;
   1.194 +	info->aspect_ratio = 100.0 / (edid[0x16] + 99);
   1.195 +	info->aspect_ratio = 1/info->aspect_ratio; /* portrait */
   1.196 +    }
   1.197 +    else
   1.198 +    {
   1.199 +	info->width_mm = 10 * edid[0x15];
   1.200 +	info->height_mm = 10 * edid[0x16];
   1.201 +    }
   1.202 +
   1.203 +    /* Gamma */
   1.204 +    if (edid[0x17] == 0xFF)
   1.205 +	info->gamma = -1.0;
   1.206 +    else
   1.207 +	info->gamma = (edid[0x17] + 100.0) / 100.0;
   1.208 +
   1.209 +    /* Features */
   1.210 +    info->standby = get_bit (edid[0x18], 7);
   1.211 +    info->suspend = get_bit (edid[0x18], 6);
   1.212 +    info->active_off = get_bit (edid[0x18], 5);
   1.213 +
   1.214 +    if (info->is_digital)
   1.215 +    {
   1.216 +	info->digital.rgb444 = TRUE;
   1.217 +	if (get_bit (edid[0x18], 3))
   1.218 +	    info->digital.ycrcb444 = 1;
   1.219 +	if (get_bit (edid[0x18], 4))
   1.220 +	    info->digital.ycrcb422 = 1;
   1.221 +    }
   1.222 +    else
   1.223 +    {
   1.224 +	int bits = get_bits (edid[0x18], 3, 4);
   1.225 +	ColorType color_type[4] =
   1.226 +	{
   1.227 +	    MONOCHROME, RGB, OTHER_COLOR, UNDEFINED_COLOR
   1.228 +	};
   1.229 +
   1.230 +	info->analog.color_type = color_type[bits];
   1.231 +    }
   1.232 +
   1.233 +    info->srgb_is_standard = get_bit (edid[0x18], 2);
   1.234 +
   1.235 +    /* In 1.3 this is called "has preferred timing" */
   1.236 +    info->preferred_timing_includes_native = get_bit (edid[0x18], 1);
   1.237 +
   1.238 +    /* FIXME: In 1.3 this indicates whether the monitor accepts GTF */
   1.239 +    info->continuous_frequency = get_bit (edid[0x18], 0);
   1.240 +    return TRUE;
   1.241 +}
   1.242 +
   1.243 +static double
   1.244 +decode_fraction (int high, int low)
   1.245 +{
   1.246 +    double result = 0.0;
   1.247 +    int i;
   1.248 +
   1.249 +    high = (high << 2) | low;
   1.250 +
   1.251 +    for (i = 0; i < 10; ++i)
   1.252 +	result += get_bit (high, i) * pow (2, i - 10);
   1.253 +
   1.254 +    return result;
   1.255 +}
   1.256 +
   1.257 +static int
   1.258 +decode_color_characteristics (const uchar *edid, MonitorInfo *info)
   1.259 +{
   1.260 +    info->red_x = decode_fraction (edid[0x1b], get_bits (edid[0x19], 6, 7));
   1.261 +    info->red_y = decode_fraction (edid[0x1c], get_bits (edid[0x19], 5, 4));
   1.262 +    info->green_x = decode_fraction (edid[0x1d], get_bits (edid[0x19], 2, 3));
   1.263 +    info->green_y = decode_fraction (edid[0x1e], get_bits (edid[0x19], 0, 1));
   1.264 +    info->blue_x = decode_fraction (edid[0x1f], get_bits (edid[0x1a], 6, 7));
   1.265 +    info->blue_y = decode_fraction (edid[0x20], get_bits (edid[0x1a], 4, 5));
   1.266 +    info->white_x = decode_fraction (edid[0x21], get_bits (edid[0x1a], 2, 3));
   1.267 +    info->white_y = decode_fraction (edid[0x22], get_bits (edid[0x1a], 0, 1));
   1.268 +
   1.269 +    return TRUE;
   1.270 +}
   1.271 +
   1.272 +static int
   1.273 +decode_established_timings (const uchar *edid, MonitorInfo *info)
   1.274 +{
   1.275 +    static const Timing established[][8] = 
   1.276 +    {
   1.277 +	{
   1.278 +	    { 800, 600, 60 },
   1.279 +	    { 800, 600, 56 },
   1.280 +	    { 640, 480, 75 },
   1.281 +	    { 640, 480, 72 },
   1.282 +	    { 640, 480, 67 },
   1.283 +	    { 640, 480, 60 },
   1.284 +	    { 720, 400, 88 },
   1.285 +	    { 720, 400, 70 }
   1.286 +	},
   1.287 +	{
   1.288 +	    { 1280, 1024, 75 },
   1.289 +	    { 1024, 768, 75 },
   1.290 +	    { 1024, 768, 70 },
   1.291 +	    { 1024, 768, 60 },
   1.292 +	    { 1024, 768, 87 },
   1.293 +	    { 832, 624, 75 },
   1.294 +	    { 800, 600, 75 },
   1.295 +	    { 800, 600, 72 }
   1.296 +	},
   1.297 +	{
   1.298 +	    { 0, 0, 0 },
   1.299 +	    { 0, 0, 0 },
   1.300 +	    { 0, 0, 0 },
   1.301 +	    { 0, 0, 0 },
   1.302 +	    { 0, 0, 0 },
   1.303 +	    { 0, 0, 0 },
   1.304 +	    { 0, 0, 0 },
   1.305 +	    { 1152, 870, 75 }
   1.306 +	},
   1.307 +    };
   1.308 +
   1.309 +    int i, j, idx;
   1.310 +
   1.311 +    idx = 0;
   1.312 +    for (i = 0; i < 3; ++i)
   1.313 +    {
   1.314 +	for (j = 0; j < 8; ++j)
   1.315 +	{
   1.316 +	    int byte = edid[0x23 + i];
   1.317 +
   1.318 +	    if (get_bit (byte, j) && established[i][j].frequency != 0)
   1.319 +		info->established[idx++] = established[i][j];
   1.320 +	}
   1.321 +    }
   1.322 +    return TRUE;
   1.323 +}
   1.324 +
   1.325 +static int
   1.326 +decode_standard_timings (const uchar *edid, MonitorInfo *info)
   1.327 +{
   1.328 +    int i;
   1.329 +    
   1.330 +    for (i = 0; i < 8; i++)
   1.331 +    {
   1.332 +	int first = edid[0x26 + 2 * i];
   1.333 +	int second = edid[0x27 + 2 * i];
   1.334 +
   1.335 +	if (first != 0x01 && second != 0x01)
   1.336 +	{
   1.337 +	    int w = 8 * (first + 31);
   1.338 +	    int h;
   1.339 +
   1.340 +	    switch (get_bits (second, 6, 7))
   1.341 +	    {
   1.342 +	    case 0x00: h = (w / 16) * 10; break;
   1.343 +	    case 0x01: h = (w / 4) * 3; break;
   1.344 +	    case 0x02: h = (w / 5) * 4; break;
   1.345 +	    case 0x03: h = (w / 16) * 9; break;
   1.346 +	    }
   1.347 +
   1.348 +	    info->standard[i].width = w;
   1.349 +	    info->standard[i].height = h;
   1.350 +	    info->standard[i].frequency = get_bits (second, 0, 5) + 60;
   1.351 +	}
   1.352 +    }
   1.353 +    
   1.354 +    return TRUE;
   1.355 +}
   1.356 +
   1.357 +static void
   1.358 +decode_lf_string (const uchar *s, int n_chars, char *result)
   1.359 +{
   1.360 +    int i;
   1.361 +    for (i = 0; i < n_chars; ++i)
   1.362 +    {
   1.363 +	if (s[i] == 0x0a)
   1.364 +	{
   1.365 +	    *result++ = '\0';
   1.366 +	    break;
   1.367 +	}
   1.368 +	else if (s[i] == 0x00)
   1.369 +	{
   1.370 +	    /* Convert embedded 0's to spaces */
   1.371 +	    *result++ = ' ';
   1.372 +	}
   1.373 +	else
   1.374 +	{
   1.375 +	    *result++ = s[i];
   1.376 +	}
   1.377 +    }
   1.378 +}
   1.379 +
   1.380 +static void
   1.381 +decode_display_descriptor (const uchar *desc,
   1.382 +			   MonitorInfo *info)
   1.383 +{
   1.384 +    switch (desc[0x03])
   1.385 +    {
   1.386 +    case 0xFC:
   1.387 +	decode_lf_string (desc + 5, 13, info->dsc_product_name);
   1.388 +	break;
   1.389 +    case 0xFF:
   1.390 +	decode_lf_string (desc + 5, 13, info->dsc_serial_number);
   1.391 +	break;
   1.392 +    case 0xFE:
   1.393 +	decode_lf_string (desc + 5, 13, info->dsc_string);
   1.394 +	break;
   1.395 +    case 0xFD:
   1.396 +	/* Range Limits */
   1.397 +	break;
   1.398 +    case 0xFB:
   1.399 +	/* Color Point */
   1.400 +	break;
   1.401 +    case 0xFA:
   1.402 +	/* Timing Identifications */
   1.403 +	break;
   1.404 +    case 0xF9:
   1.405 +	/* Color Management */
   1.406 +	break;
   1.407 +    case 0xF8:
   1.408 +	/* Timing Codes */
   1.409 +	break;
   1.410 +    case 0xF7:
   1.411 +	/* Established Timings */
   1.412 +	break;
   1.413 +    case 0x10:
   1.414 +	break;
   1.415 +    }
   1.416 +}
   1.417 +
   1.418 +static void
   1.419 +decode_detailed_timing (const uchar *timing,
   1.420 +			DetailedTiming *detailed)
   1.421 +{
   1.422 +    int bits;
   1.423 +    StereoType stereo[] =
   1.424 +    {
   1.425 +	NO_STEREO, NO_STEREO, FIELD_RIGHT, FIELD_LEFT,
   1.426 +	TWO_WAY_RIGHT_ON_EVEN, TWO_WAY_LEFT_ON_EVEN,
   1.427 +	FOUR_WAY_INTERLEAVED, SIDE_BY_SIDE
   1.428 +    };
   1.429 +    
   1.430 +    detailed->pixel_clock = (timing[0x00] | timing[0x01] << 8) * 10000;
   1.431 +    detailed->h_addr = timing[0x02] | ((timing[0x04] & 0xf0) << 4);
   1.432 +    detailed->h_blank = timing[0x03] | ((timing[0x04] & 0x0f) << 8);
   1.433 +    detailed->v_addr = timing[0x05] | ((timing[0x07] & 0xf0) << 4);
   1.434 +    detailed->v_blank = timing[0x06] | ((timing[0x07] & 0x0f) << 8);
   1.435 +    detailed->h_front_porch = timing[0x08] | get_bits (timing[0x0b], 6, 7) << 8;
   1.436 +    detailed->h_sync = timing[0x09] | get_bits (timing[0x0b], 4, 5) << 8;
   1.437 +    detailed->v_front_porch =
   1.438 +	get_bits (timing[0x0a], 4, 7) | get_bits (timing[0x0b], 2, 3) << 4;
   1.439 +    detailed->v_sync =
   1.440 +	get_bits (timing[0x0a], 0, 3) | get_bits (timing[0x0b], 0, 1) << 4;
   1.441 +    detailed->width_mm =  timing[0x0c] | get_bits (timing[0x0e], 4, 7) << 8;
   1.442 +    detailed->height_mm = timing[0x0d] | get_bits (timing[0x0e], 0, 3) << 8;
   1.443 +    detailed->right_border = timing[0x0f];
   1.444 +    detailed->top_border = timing[0x10];
   1.445 +
   1.446 +    detailed->interlaced = get_bit (timing[0x11], 7);
   1.447 +
   1.448 +    /* Stereo */
   1.449 +    bits = get_bits (timing[0x11], 5, 6) << 1 | get_bit (timing[0x11], 0);
   1.450 +    detailed->stereo = stereo[bits];
   1.451 +
   1.452 +    /* Sync */
   1.453 +    bits = timing[0x11];
   1.454 +
   1.455 +    detailed->digital_sync = get_bit (bits, 4);
   1.456 +    if (detailed->digital_sync)
   1.457 +    {
   1.458 +	detailed->digital.composite = !get_bit (bits, 3);
   1.459 +
   1.460 +	if (detailed->digital.composite)
   1.461 +	{
   1.462 +	    detailed->digital.serrations = get_bit (bits, 2);
   1.463 +	    detailed->digital.negative_vsync = FALSE;
   1.464 +	}
   1.465 +	else
   1.466 +	{
   1.467 +	    detailed->digital.serrations = FALSE;
   1.468 +	    detailed->digital.negative_vsync = !get_bit (bits, 2);
   1.469 +	}
   1.470 +
   1.471 +	detailed->digital.negative_hsync = !get_bit (bits, 0);
   1.472 +    }
   1.473 +    else
   1.474 +    {
   1.475 +	detailed->analog.bipolar = get_bit (bits, 3);
   1.476 +	detailed->analog.serrations = get_bit (bits, 2);
   1.477 +	detailed->analog.sync_on_green = !get_bit (bits, 1);
   1.478 +    }
   1.479 +}
   1.480 +
   1.481 +static int
   1.482 +decode_descriptors (const uchar *edid, MonitorInfo *info)
   1.483 +{
   1.484 +    int i;
   1.485 +    int timing_idx;
   1.486 +    
   1.487 +    timing_idx = 0;
   1.488 +    
   1.489 +    for (i = 0; i < 4; ++i)
   1.490 +    {
   1.491 +	int index = 0x36 + i * 18;
   1.492 +
   1.493 +	if (edid[index + 0] == 0x00 && edid[index + 1] == 0x00)
   1.494 +	{
   1.495 +	    decode_display_descriptor (edid + index, info);
   1.496 +	}
   1.497 +	else
   1.498 +	{
   1.499 +	    decode_detailed_timing (
   1.500 +		edid + index, &(info->detailed_timings[timing_idx++]));
   1.501 +	}
   1.502 +    }
   1.503 +
   1.504 +    info->n_detailed_timings = timing_idx;
   1.505 +
   1.506 +    return TRUE;
   1.507 +}
   1.508 +
   1.509 +static void
   1.510 +decode_check_sum (const uchar *edid,
   1.511 +		  MonitorInfo *info)
   1.512 +{
   1.513 +    int i;
   1.514 +    uchar check = 0;
   1.515 +
   1.516 +    for (i = 0; i < 128; ++i)
   1.517 +	check += edid[i];
   1.518 +
   1.519 +    info->checksum = check;
   1.520 +}
   1.521 +
   1.522 +MonitorInfo *
   1.523 +decode_edid (const uchar *edid)
   1.524 +{
   1.525 +    MonitorInfo *info = calloc (1, sizeof (MonitorInfo));
   1.526 +
   1.527 +    decode_check_sum (edid, info);
   1.528 +    
   1.529 +    if (!decode_header (edid))
   1.530 +	return NULL;
   1.531 +
   1.532 +    if (!decode_vendor_and_product_identification (edid, info))
   1.533 +	return NULL;
   1.534 +
   1.535 +    if (!decode_edid_version (edid, info))
   1.536 +	return NULL;
   1.537 +
   1.538 +    if (!decode_display_parameters (edid, info))
   1.539 +	return NULL;
   1.540 +
   1.541 +    if (!decode_color_characteristics (edid, info))
   1.542 +	return NULL;
   1.543 +
   1.544 +    if (!decode_established_timings (edid, info))
   1.545 +	return NULL;
   1.546 +
   1.547 +    if (!decode_standard_timings (edid, info))
   1.548 +	return NULL;
   1.549 +    
   1.550 +    if (!decode_descriptors (edid, info))
   1.551 +	return NULL;
   1.552 +    
   1.553 +    return info;
   1.554 +}
   1.555 +
   1.556 +static const char *
   1.557 +yesno (int v)
   1.558 +{
   1.559 +    return v? "yes" : "no";
   1.560 +}
   1.561 +
   1.562 +void
   1.563 +dump_monitor_info (MonitorInfo *info)
   1.564 +{
   1.565 +    char *s;
   1.566 +    int i;
   1.567 +    
   1.568 +    printf ("Checksum: %d (%s)\n",
   1.569 +	    info->checksum, info->checksum? "incorrect" : "correct");
   1.570 +    printf ("Manufacturer Code: %s\n", info->manufacturer_code);
   1.571 +    printf ("Product Code: 0x%x\n", info->product_code);
   1.572 +    printf ("Serial Number: %u\n", info->serial_number);
   1.573 +    
   1.574 +    if (info->production_week != -1)
   1.575 +	printf ("Production Week: %d\n", info->production_week);
   1.576 +    else
   1.577 +	printf ("Production Week: unspecified\n");
   1.578 +    
   1.579 +    if (info->production_year != -1)
   1.580 +	printf ("Production Year: %d\n", info->production_year);
   1.581 +    else
   1.582 +	printf ("Production Year: unspecified\n");
   1.583 +    
   1.584 +    if (info->model_year != -1)
   1.585 +	printf ("Model Year: %d\n", info->model_year);
   1.586 +    else
   1.587 +	printf ("Model Year: unspecified\n");
   1.588 +    
   1.589 +    printf ("EDID revision: %d.%d\n", info->major_version, info->minor_version);
   1.590 +    
   1.591 +    printf ("Display is %s\n", info->is_digital? "digital" : "analog");
   1.592 +    if (info->is_digital)
   1.593 +    {
   1.594 +	const char *interface;
   1.595 +	if (info->digital.bits_per_primary != -1)
   1.596 +	    printf ("Bits Per Primary: %d\n", info->digital.bits_per_primary);
   1.597 +	else
   1.598 +	    printf ("Bits Per Primary: undefined\n");
   1.599 +	
   1.600 +	switch (info->digital.interface)
   1.601 +	{
   1.602 +	case DVI: interface = "DVI"; break;
   1.603 +	case HDMI_A: interface = "HDMI-a"; break;
   1.604 +	case HDMI_B: interface = "HDMI-b"; break;
   1.605 +	case MDDI: interface = "MDDI"; break;
   1.606 +	case DISPLAY_PORT: interface = "DisplayPort"; break;
   1.607 +	case UNDEFINED: interface = "undefined"; break;
   1.608 +	}
   1.609 +	printf ("Interface: %s\n", interface);
   1.610 +	
   1.611 +	printf ("RGB 4:4:4: %s\n", yesno (info->digital.rgb444));
   1.612 +	printf ("YCrCb 4:4:4: %s\n", yesno (info->digital.ycrcb444));
   1.613 +	printf ("YCrCb 4:2:2: %s\n", yesno (info->digital.ycrcb422));
   1.614 +    }
   1.615 +    else
   1.616 +    {
   1.617 +	printf ("Video Signal Level: %f\n", info->analog.video_signal_level);
   1.618 +	printf ("Sync Signal Level: %f\n", info->analog.sync_signal_level);
   1.619 +	printf ("Total Signal Level: %f\n", info->analog.total_signal_level);
   1.620 +	
   1.621 +	printf ("Blank to Black: %s\n",
   1.622 +		yesno (info->analog.blank_to_black));
   1.623 +	printf ("Separate HV Sync: %s\n",
   1.624 +		yesno (info->analog.separate_hv_sync));
   1.625 +	printf ("Composite Sync on H: %s\n",
   1.626 +		yesno (info->analog.composite_sync_on_h));
   1.627 +	printf ("Serration on VSync: %s\n",
   1.628 +		yesno (info->analog.serration_on_vsync));
   1.629 +	
   1.630 +	switch (info->analog.color_type)
   1.631 +	{
   1.632 +	case UNDEFINED_COLOR: s = "undefined"; break;
   1.633 +	case MONOCHROME: s = "monochrome"; break;
   1.634 +	case RGB: s = "rgb"; break;
   1.635 +	case OTHER_COLOR: s = "other color"; break;
   1.636 +	};
   1.637 +	
   1.638 +	printf ("Color: %s\n", s);
   1.639 +    }
   1.640 +    
   1.641 +    if (info->width_mm == -1)
   1.642 +	printf ("Width: undefined\n");
   1.643 +    else
   1.644 +	printf ("Width: %d mm\n", info->width_mm);
   1.645 +    
   1.646 +    if (info->height_mm == -1)
   1.647 +	printf ("Height: undefined\n");
   1.648 +    else
   1.649 +	printf ("Height: %d mm\n", info->height_mm);
   1.650 +    
   1.651 +    if (info->aspect_ratio > 0)
   1.652 +	printf ("Aspect Ratio: %f\n", info->aspect_ratio);
   1.653 +    else
   1.654 +	printf ("Aspect Ratio: undefined\n");
   1.655 +    
   1.656 +    if (info->gamma >= 0)
   1.657 +	printf ("Gamma: %f\n", info->gamma);
   1.658 +    else
   1.659 +	printf ("Gamma: undefined\n");
   1.660 +    
   1.661 +    printf ("Standby: %s\n", yesno (info->standby));
   1.662 +    printf ("Suspend: %s\n", yesno (info->suspend));
   1.663 +    printf ("Active Off: %s\n", yesno (info->active_off));
   1.664 +    
   1.665 +    printf ("SRGB is Standard: %s\n", yesno (info->srgb_is_standard));
   1.666 +    printf ("Preferred Timing Includes Native: %s\n",
   1.667 +	    yesno (info->preferred_timing_includes_native));
   1.668 +    printf ("Continuous Frequency: %s\n", yesno (info->continuous_frequency));
   1.669 +    
   1.670 +    printf ("Red X: %f\n", info->red_x);
   1.671 +    printf ("Red Y: %f\n", info->red_y);
   1.672 +    printf ("Green X: %f\n", info->green_x);
   1.673 +    printf ("Green Y: %f\n", info->green_y);
   1.674 +    printf ("Blue X: %f\n", info->blue_x);
   1.675 +    printf ("Blue Y: %f\n", info->blue_y);
   1.676 +    printf ("White X: %f\n", info->white_x);
   1.677 +    printf ("White Y: %f\n", info->white_y);
   1.678 +    
   1.679 +    printf ("Established Timings:\n");
   1.680 +    
   1.681 +    for (i = 0; i < 24; ++i)
   1.682 +    {
   1.683 +	Timing *timing = &(info->established[i]);
   1.684 +	
   1.685 +	if (timing->frequency == 0)
   1.686 +	    break;
   1.687 +	
   1.688 +	printf ("  %d x %d @ %d Hz\n",
   1.689 +		timing->width, timing->height, timing->frequency);
   1.690 +	
   1.691 +    }
   1.692 +    
   1.693 +    printf ("Standard Timings:\n");
   1.694 +    for (i = 0; i < 8; ++i)
   1.695 +    {
   1.696 +	Timing *timing = &(info->standard[i]);
   1.697 +	
   1.698 +	if (timing->frequency == 0)
   1.699 +	    break;
   1.700 +	
   1.701 +	printf ("  %d x %d @ %d Hz\n",
   1.702 +		timing->width, timing->height, timing->frequency);
   1.703 +    }
   1.704 +    
   1.705 +    for (i = 0; i < info->n_detailed_timings; ++i)
   1.706 +    {
   1.707 +	DetailedTiming *timing = &(info->detailed_timings[i]);
   1.708 +	const char *s;
   1.709 +	
   1.710 +	printf ("Timing%s: \n",
   1.711 +		(i == 0 && info->preferred_timing_includes_native)?
   1.712 +		" (Preferred)" : "");
   1.713 +	printf ("  Pixel Clock: %d\n", timing->pixel_clock);
   1.714 +	printf ("  H Addressable: %d\n", timing->h_addr);
   1.715 +	printf ("  H Blank: %d\n", timing->h_blank);
   1.716 +	printf ("  H Front Porch: %d\n", timing->h_front_porch);
   1.717 +	printf ("  H Sync: %d\n", timing->h_sync);
   1.718 +	printf ("  V Addressable: %d\n", timing->v_addr);
   1.719 +	printf ("  V Blank: %d\n", timing->v_blank);
   1.720 +	printf ("  V Front Porch: %d\n", timing->v_front_porch);
   1.721 +	printf ("  V Sync: %d\n", timing->v_sync);
   1.722 +	printf ("  Width: %d mm\n", timing->width_mm);
   1.723 +	printf ("  Height: %d mm\n", timing->height_mm);
   1.724 +	printf ("  Right Border: %d\n", timing->right_border);
   1.725 +	printf ("  Top Border: %d\n", timing->top_border);
   1.726 +	switch (timing->stereo)
   1.727 +	{
   1.728 +	case NO_STEREO:   s = "No Stereo"; break;
   1.729 +	case FIELD_RIGHT: s = "Field Sequential, Right on Sync"; break;
   1.730 +	case FIELD_LEFT:  s = "Field Sequential, Left on Sync"; break;
   1.731 +	case TWO_WAY_RIGHT_ON_EVEN: s = "Two-way, Right on Even"; break;
   1.732 +	case TWO_WAY_LEFT_ON_EVEN:  s = "Two-way, Left on Even"; break;
   1.733 +	case FOUR_WAY_INTERLEAVED:  s = "Four-way Interleaved"; break;
   1.734 +	case SIDE_BY_SIDE:          s = "Side-by-Side"; break;
   1.735 +	}
   1.736 +	printf ("  Stereo: %s\n", s);
   1.737 +	
   1.738 +	if (timing->digital_sync)
   1.739 +	{
   1.740 +	    printf ("  Digital Sync:\n");
   1.741 +	    printf ("    composite: %s\n", yesno (timing->digital.composite));
   1.742 +	    printf ("    serrations: %s\n", yesno (timing->digital.serrations));
   1.743 +	    printf ("    negative vsync: %s\n",
   1.744 +		    yesno (timing->digital.negative_vsync));
   1.745 +	    printf ("    negative hsync: %s\n",
   1.746 +		    yesno (timing->digital.negative_hsync));
   1.747 +	}
   1.748 +	else
   1.749 +	{
   1.750 +	    printf ("  Analog Sync:\n");
   1.751 +	    printf ("    bipolar: %s\n", yesno (timing->analog.bipolar));
   1.752 +	    printf ("    serrations: %s\n", yesno (timing->analog.serrations));
   1.753 +	    printf ("    sync on green: %s\n", yesno (
   1.754 +			timing->analog.sync_on_green));
   1.755 +	}
   1.756 +    }
   1.757 +    
   1.758 +    printf ("Detailed Product information:\n");
   1.759 +    printf ("  Product Name: %s\n", info->dsc_product_name);
   1.760 +    printf ("  Serial Number: %s\n", info->dsc_serial_number);
   1.761 +    printf ("  Unspecified String: %s\n", info->dsc_string);
   1.762 +}
   1.763 +