'As a developer/C/C++'에 해당되는 글 37건
- 2012.09.14 NSIS INI파일 연동
- 2012.08.28 NSIS 샘플
- 2012.08.08 Open SSL
- 2012.07.26 HKEY로 레지스트리 키 얻기
- 2012.07.25 memory SPD read
- 2012.07.18 모니터 Enumerate
- 2012.07.16 EDID Parser - Detail
- 2012.07.16 EDID 파싱
- 2012.07.16 모니터 정보보기2 - EDID
- 2012.07.16 모니터 정보 얻기 - EDID
NSIS INI파일 연동
http://forums.winamp.com/showthread.php?t=346431&highlight=script
Function .onInit
ReadINIStr $v_major "\AA\my.ini" "Versiuni" "major"
ReadINIStr $v_minor "\AA\my.ini" "Versiuni" "minor"
ReadINIStr $v_build "\AA\my.ini" "Versiuni" "build"
ReadINIStr $v_revis "\AA\my.ini" "Versiuni" "revision"
FileOpen $R0 "version.nsh" w
FileWrite $R0 "!define v_major '$v_major'"
FileWrite $R0 "$\r$\n"
FileWrite $R0 "!define v_minor '$v_minor'"
FileWrite $R0 "$\r$\n"
FileWrite $R0 "!define v_build '$v_build'"
FileWrite $R0 "$\r$\n"
FileWrite $R0 "!define v_revis '$v_revis'"
FileClose $R0
FunctionEnd
Open SSL
HKEY로 레지스트리 키 얻기
http://stackoverflow.com/questions/937044/determine-path-to-registry-key-from-hkey-handle-in-c
#include <windows.h>
#include <string>
typedef LONG NTSTATUS;
#ifndef STATUS_SUCCESS
#define STATUS_SUCCESS ((NTSTATUS)0x00000000L)
#endif
#ifndef STATUS_BUFFER_TOO_SMALL
#define STATUS_BUFFER_TOO_SMALL ((NTSTATUS)0xC0000023L)
#endif
std::wstring GetKeyPathFromKKEY(HKEY key)
{
std::wstring keyPath;
if (key != NULL)
{
HMODULE dll = LoadLibrary(L"ntdll.dll");
if (dll != NULL) {
typedef DWORD (__stdcall *NtQueryKeyType)(
HANDLE KeyHandle,
int KeyInformationClass,
PVOID KeyInformation,
ULONG Length,
PULONG ResultLength);
NtQueryKeyType func = reinterpret_cast<NtQueryKeyType>(::GetProcAddress(dll, "NtQueryKey"));
if (func != NULL) {
DWORD size = 0;
DWORD result = 0;
result = func(key, 3, 0, 0, &size);
if (result == STATUS_BUFFER_TOO_SMALL)
{
size = size + 2;
wchar_t* buffer = new (std::nothrow) wchar_t[size/sizeof(wchar_t)]; // size is in bytes
if (buffer != NULL)
{
result = func(key, 3, buffer, size, &size);
if (result == STATUS_SUCCESS)
{
buffer[size / sizeof(wchar_t)] = L'\0';
keyPath = std::wstring(buffer + 2);
}
delete[] buffer;
}
}
}
FreeLibrary(dll);
}
}
return keyPath;
}
int _tmain(int argc, _TCHAR* argv[])
{
HKEY key = NULL;
LONG ret = ERROR_SUCCESS;
ret = RegOpenKey(HKEY_LOCAL_MACHINE, L"SOFTWARE\\Microsoft", &key);
if (ret == ERROR_SUCCESS)
{
wprintf_s(L"Key path for %p is '%s'.", key, GetKeyPathFromKKEY(key).c_str());
RegCloseKey(key);
}
return 0;
}
부모키 리턴
memory SPD read
모니터 Enumerate
#include <atlstr.h> |
002 |
#include <SetupApi.h> |
003 |
#pragma comment(lib, "setupapi.lib") |
004 |
|
005 |
#define NAME_SIZE 128 |
006 |
|
007 |
const GUID GUID_CLASS_MONITOR = {0x4d36e96e, 0xe325, 0x11ce, 0xbf, 0xc1, 0x08, 0x00, 0x2b, 0xe1, 0x03, 0x18}; |
008 |
|
009 |
// Assumes hDevRegKey is valid |
010 |
bool GetMonitorSizeFromEDID( const HKEY hDevRegKey, short & WidthMm, short & HeightMm) |
011 |
{ |
012 |
DWORD dwType, AcutalValueNameLength = NAME_SIZE; |
013 |
TCHAR valueName[NAME_SIZE]; |
014 |
|
015 |
BYTE EDIDdata[1024]; |
016 |
DWORD edidsize= sizeof (EDIDdata); |
017 |
|
018 |
for ( LONG i = 0, retValue = ERROR_SUCCESS; retValue != ERROR_NO_MORE_ITEMS; ++i) |
019 |
{ |
020 |
retValue = RegEnumValue ( hDevRegKey, i, &valueName[0], |
021 |
&AcutalValueNameLength, NULL, &dwType, |
022 |
EDIDdata, // buffer |
023 |
&edidsize); // buffer size |
024 |
|
025 |
if (retValue != ERROR_SUCCESS || 0 != _tcscmp(valueName,_T( "EDID" ))) |
026 |
continue ; |
027 |
|
028 |
WidthMm = ((EDIDdata[68] & 0xF0) << 4) + EDIDdata[66]; |
029 |
HeightMm = ((EDIDdata[68] & 0x0F) << 8) + EDIDdata[67]; |
030 |
|
031 |
return true ; // valid EDID found |
032 |
} |
033 |
|
034 |
return false ; // EDID not found |
035 |
} |
036 |
|
037 |
bool GetSizeForDevID( const CString& TargetDevID, short & WidthMm, short & HeightMm) |
038 |
{ |
039 |
HDEVINFO devInfo = SetupDiGetClassDevsEx( |
040 |
&GUID_CLASS_MONITOR, //class GUID |
041 |
NULL, //enumerator |
042 |
NULL, //HWND |
043 |
DIGCF_PRESENT, // Flags //DIGCF_ALLCLASSES| |
044 |
NULL, // device info, create a new one. |
045 |
NULL, // machine name, local machine |
046 |
NULL); // reserved |
047 |
|
048 |
if (NULL == devInfo) |
049 |
return false ; |
050 |
|
051 |
bool bRes = false ; |
052 |
|
053 |
for ( ULONG i=0; ERROR_NO_MORE_ITEMS != GetLastError(); ++i) |
054 |
{ |
055 |
SP_DEVINFO_DATA devInfoData; |
056 |
memset (&devInfoData,0, sizeof (devInfoData)); |
057 |
devInfoData.cbSize = sizeof (devInfoData); |
058 |
|
059 |
if (SetupDiEnumDeviceInfo(devInfo,i,&devInfoData)) |
060 |
{ |
061 |
HKEY hDevRegKey = SetupDiOpenDevRegKey(devInfo,&devInfoData, |
062 |
DICS_FLAG_GLOBAL, 0, DIREG_DEV, KEY_READ); |
063 |
|
064 |
if (!hDevRegKey || (hDevRegKey == INVALID_HANDLE_VALUE)) |
065 |
continue ; |
066 |
|
067 |
bRes = GetMonitorSizeFromEDID(hDevRegKey, WidthMm, HeightMm); |
068 |
|
069 |
RegCloseKey(hDevRegKey); |
070 |
} |
071 |
} |
072 |
SetupDiDestroyDeviceInfoList(devInfo); |
073 |
return bRes; |
074 |
} |
075 |
|
076 |
int _tmain( int argc, _TCHAR* argv[]) |
077 |
{ |
078 |
short WidthMm, HeightMm; |
079 |
|
080 |
DISPLAY_DEVICE dd; |
081 |
dd.cb = sizeof (dd); |
082 |
DWORD dev = 0; // device index |
083 |
int id = 1; // monitor number, as used by Display Properties > Settings |
084 |
|
085 |
CString DeviceID; |
086 |
bool bFoundDevice = false ; |
087 |
while (EnumDisplayDevices(0, dev, &dd, 0) && !bFoundDevice) |
088 |
{ |
089 |
DISPLAY_DEVICE ddMon; |
090 |
ZeroMemory(&ddMon, sizeof (ddMon)); |
091 |
ddMon.cb = sizeof (ddMon); |
092 |
DWORD devMon = 0; |
093 |
|
094 |
while (EnumDisplayDevices(dd.DeviceName, devMon, &ddMon, 0) && !bFoundDevice) |
095 |
{ |
096 |
if (ddMon.StateFlags & DISPLAY_DEVICE_ACTIVE && |
097 |
!(ddMon.StateFlags & DISPLAY_DEVICE_MIRRORING_DRIVER)) |
098 |
{ |
099 |
DeviceID.Format (L "%s" , ddMon.DeviceID); |
100 |
DeviceID = DeviceID.Mid (8, DeviceID.Find (L "\\" , 9) - 8); |
101 |
|
102 |
bFoundDevice = GetSizeForDevID(DeviceID, WidthMm, HeightMm); |
103 |
} |
104 |
devMon++; |
105 |
|
106 |
ZeroMemory(&ddMon, sizeof (ddMon)); |
107 |
ddMon.cb = sizeof (ddMon); |
108 |
} |
109 |
|
110 |
ZeroMemory(&dd, sizeof (dd)); |
111 |
dd.cb = sizeof (dd); |
112 |
dev++; |
113 |
} |
114 |
|
115 |
return 0; |
116 |
} |
EDID Parser - Detail
http://people.gnome.org/~ssp/randr/edid-parse.c
http://people.gnome.org/~ssp/randr/edid.h
-----------------------------------------------------------------------------------------------------------
// edid.h
typedef unsigned char uchar; typedef struct MonitorInfo MonitorInfo; typedef struct Timing Timing; typedef struct DetailedTiming DetailedTiming; typedef enum { UNDEFINED, DVI, HDMI_A, HDMI_B, MDDI, DISPLAY_PORT } Interface; typedef enum { UNDEFINED_COLOR, MONOCHROME, RGB, OTHER_COLOR } ColorType; typedef enum { NO_STEREO, FIELD_RIGHT, FIELD_LEFT, TWO_WAY_RIGHT_ON_EVEN, TWO_WAY_LEFT_ON_EVEN, FOUR_WAY_INTERLEAVED, SIDE_BY_SIDE } StereoType; struct Timing { int width; int height; int frequency; }; struct DisplayDescriptor { }; struct DetailedTiming { int pixel_clock; int h_addr; int h_blank; int h_sync; int h_front_porch; int v_addr; int v_blank; int v_sync; int v_front_porch; int width_mm; int height_mm; int right_border; int top_border; int interlaced; StereoType stereo; int digital_sync; union { struct { int bipolar; int serrations; int sync_on_green; } analog; struct { int composite; int serrations; int negative_vsync; int negative_hsync; } digital; }; }; struct MonitorInfo { int checksum; char manufacturer_code[4]; int product_code; unsigned int serial_number; int production_week; /* -1 if not specified */ int production_year; /* -1 if not specified */ int model_year; /* -1 if not specified */ int major_version; int minor_version; int is_digital; union { struct { int bits_per_primary; Interface interface; int rgb444; int ycrcb444; int ycrcb422; } digital; struct { double video_signal_level; double sync_signal_level; double total_signal_level; int blank_to_black; int separate_hv_sync; int composite_sync_on_h; int composite_sync_on_green; int serration_on_vsync; ColorType color_type; } analog; }; int width_mm; /* -1 if not specified */ int height_mm; /* -1 if not specified */ double aspect_ratio; /* -1.0 if not specififed */ double gamma; /* -1.0 if not specified */ int standby; int suspend; int active_off; int srgb_is_standard; int preferred_timing_includes_native; int continuous_frequency; double red_x; double red_y; double green_x; double green_y; double blue_x; double blue_y; double white_x; double white_y; Timing established[24]; /* Terminated by 0x0x0 */ Timing standard[8]; int n_detailed_timings; DetailedTiming detailed_timings[4]; /* If monitor has a preferred * mode, it is the first one * (whether it has, is * determined by the * preferred_timing_includes * bit. */ /* Optional product description */ char dsc_serial_number[14]; char dsc_product_name[14]; char dsc_string[14]; /* Unspecified ASCII data */ }; MonitorInfo *decode_edid (const uchar *data); char * make_display_name (const char *output_name, const MonitorInfo *info);
---------------------------------------------------------------------------------------------------
---------------------------------------------------------------------------------------------------
edid.c
/* * Copyright 2007 Red Hat, Inc. * * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and associated documentation files (the "Software"), * to deal in the Software without restriction, including without limitation * on the rights to use, copy, modify, merge, publish, distribute, sub * license, and/or sell copies of the Software, and to permit persons to whom * the Software is furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice (including the next * paragraph) shall be included in all copies or substantial portions of the * Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL * THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /* Author: Soren Sandmann <sandmann@redhat.com> */ #include "edid.h" #include <stdlib.h> #include <string.h> #include <math.h> #define TRUE 1 #define FALSE 0 static int get_bit (int in, int bit) { return (in & (1 << bit)) >> bit; } static int get_bits (int in, int begin, int end) { int mask = (1 << (end - begin + 1)) - 1; return (in >> begin) & mask; } static int decode_header (const uchar *edid) { if (memcmp (edid, "\x00\xff\xff\xff\xff\xff\xff\x00", 8) == 0) return TRUE; return FALSE; } static int decode_vendor_and_product_identification (const uchar *edid, MonitorInfo *info) { int is_model_year; /* Manufacturer Code */ info->manufacturer_code[0] = get_bits (edid[0x08], 2, 6); info->manufacturer_code[1] = get_bits (edid[0x08], 0, 1) << 3; info->manufacturer_code[1] |= get_bits (edid[0x09], 5, 7); info->manufacturer_code[2] = get_bits (edid[0x09], 0, 4); info->manufacturer_code[3] = '\0'; info->manufacturer_code[0] += 'A' - 1; info->manufacturer_code[1] += 'A' - 1; info->manufacturer_code[2] += 'A' - 1; /* Product Code */ info->product_code = edid[0x0b] << 8 | edid[0x0a]; /* Serial Number */ info->serial_number = edid[0x0c] | edid[0x0d] << 8 | edid[0x0e] << 16 | edid[0x0f] << 24; /* Week and Year */ is_model_year = FALSE; switch (edid[0x10]) { case 0x00: info->production_week = -1; break; case 0xff: info->production_week = -1; is_model_year = TRUE; break; default: info->production_week = edid[0x10]; break; } if (is_model_year) { info->production_year = -1; info->model_year = 1990 + edid[0x11]; } else { info->production_year = 1990 + edid[0x11]; info->model_year = -1; } return TRUE; } static int decode_edid_version (const uchar *edid, MonitorInfo *info) { info->major_version = edid[0x12]; info->minor_version = edid[0x13]; return TRUE; } static int decode_display_parameters (const uchar *edid, MonitorInfo *info) { /* Digital vs Analog */ info->is_digital = get_bit (edid[0x14], 7); if (info->is_digital) { int bits; static const int bit_depth[8] = { -1, 6, 8, 10, 12, 14, 16, -1 }; static const Interface interfaces[6] = { UNDEFINED, DVI, HDMI_A, HDMI_B, MDDI, DISPLAY_PORT }; bits = get_bits (edid[0x14], 4, 6); info->digital.bits_per_primary = bit_depth[bits]; bits = get_bits (edid[0x14], 0, 3); if (bits <= 5) info->digital.interface = interfaces[bits]; else info->digital.interface = UNDEFINED; } else { int bits = get_bits (edid[0x14], 5, 6); static const double levels[][3] = { { 0.7, 0.3, 1.0 }, { 0.714, 0.286, 1.0 }, { 1.0, 0.4, 1.4 }, { 0.7, 0.0, 0.7 }, }; info->analog.video_signal_level = levels[bits][0]; info->analog.sync_signal_level = levels[bits][1]; info->analog.total_signal_level = levels[bits][2]; info->analog.blank_to_black = get_bit (edid[0x14], 4); info->analog.separate_hv_sync = get_bit (edid[0x14], 3); info->analog.composite_sync_on_h = get_bit (edid[0x14], 2); info->analog.composite_sync_on_green = get_bit (edid[0x14], 1); info->analog.serration_on_vsync = get_bit (edid[0x14], 0); } /* Screen Size / Aspect Ratio */ if (edid[0x15] == 0 && edid[0x16] == 0) { info->width_mm = -1; info->height_mm = -1; info->aspect_ratio = -1.0; } else if (edid[0x16] == 0) { info->width_mm = -1; info->height_mm = -1; info->aspect_ratio = 100.0 / (edid[0x15] + 99); } else if (edid[0x15] == 0) { info->width_mm = -1; info->height_mm = -1; info->aspect_ratio = 100.0 / (edid[0x16] + 99); info->aspect_ratio = 1/info->aspect_ratio; /* portrait */ } else { info->width_mm = 10 * edid[0x15]; info->height_mm = 10 * edid[0x16]; } /* Gamma */ if (edid[0x17] == 0xFF) info->gamma = -1.0; else info->gamma = (edid[0x17] + 100.0) / 100.0; /* Features */ info->standby = get_bit (edid[0x18], 7); info->suspend = get_bit (edid[0x18], 6); info->active_off = get_bit (edid[0x18], 5); if (info->is_digital) { info->digital.rgb444 = TRUE; if (get_bit (edid[0x18], 3)) info->digital.ycrcb444 = 1; if (get_bit (edid[0x18], 4)) info->digital.ycrcb422 = 1; } else { int bits = get_bits (edid[0x18], 3, 4); ColorType color_type[4] = { MONOCHROME, RGB, OTHER_COLOR, UNDEFINED_COLOR }; info->analog.color_type = color_type[bits]; } info->srgb_is_standard = get_bit (edid[0x18], 2); /* In 1.3 this is called "has preferred timing" */ info->preferred_timing_includes_native = get_bit (edid[0x18], 1); /* FIXME: In 1.3 this indicates whether the monitor accepts GTF */ info->continuous_frequency = get_bit (edid[0x18], 0); return TRUE; } static double decode_fraction (int high, int low) { double result = 0.0; int i; high = (high << 2) | low; for (i = 0; i < 10; ++i) result += get_bit (high, i) * pow (2, i - 10); return result; } static int decode_color_characteristics (const uchar *edid, MonitorInfo *info) { info->red_x = decode_fraction (edid[0x1b], get_bits (edid[0x19], 6, 7)); info->red_y = decode_fraction (edid[0x1c], get_bits (edid[0x19], 5, 4)); info->green_x = decode_fraction (edid[0x1d], get_bits (edid[0x19], 2, 3)); info->green_y = decode_fraction (edid[0x1e], get_bits (edid[0x19], 0, 1)); info->blue_x = decode_fraction (edid[0x1f], get_bits (edid[0x1a], 6, 7)); info->blue_y = decode_fraction (edid[0x20], get_bits (edid[0x1a], 4, 5)); info->white_x = decode_fraction (edid[0x21], get_bits (edid[0x1a], 2, 3)); info->white_y = decode_fraction (edid[0x22], get_bits (edid[0x1a], 0, 1)); return TRUE; } static int decode_established_timings (const uchar *edid, MonitorInfo *info) { static const Timing established[][8] = { { { 800, 600, 60 }, { 800, 600, 56 }, { 640, 480, 75 }, { 640, 480, 72 }, { 640, 480, 67 }, { 640, 480, 60 }, { 720, 400, 88 }, { 720, 400, 70 } }, { { 1280, 1024, 75 }, { 1024, 768, 75 }, { 1024, 768, 70 }, { 1024, 768, 60 }, { 1024, 768, 87 }, { 832, 624, 75 }, { 800, 600, 75 }, { 800, 600, 72 } }, { { 0, 0, 0 }, { 0, 0, 0 }, { 0, 0, 0 }, { 0, 0, 0 }, { 0, 0, 0 }, { 0, 0, 0 }, { 0, 0, 0 }, { 1152, 870, 75 } }, }; int i, j, idx; idx = 0; for (i = 0; i < 3; ++i) { for (j = 0; j < 8; ++j) { int byte = edid[0x23 + i]; if (get_bit (byte, j) && established[i][j].frequency != 0) info->established[idx++] = established[i][j]; } } return TRUE; } static int decode_standard_timings (const uchar *edid, MonitorInfo *info) { int i; for (i = 0; i < 8; i++) { int first = edid[0x26 + 2 * i]; int second = edid[0x27 + 2 * i]; if (first != 0x01 && second != 0x01) { int w = 8 * (first + 31); int h; switch (get_bits (second, 6, 7)) { case 0x00: h = (w / 16) * 10; break; case 0x01: h = (w / 4) * 3; break; case 0x02: h = (w / 5) * 4; break; case 0x03: h = (w / 16) * 9; break; } info->standard[i].width = w; info->standard[i].height = h; info->standard[i].frequency = get_bits (second, 0, 5) + 60; } } return TRUE; } static void decode_lf_string (const uchar *s, int n_chars, char *result) { int i; for (i = 0; i < n_chars; ++i) { if (s[i] == 0x0a) { *result++ = '\0'; break; } else if (s[i] == 0x00) { /* Convert embedded 0's to spaces */ *result++ = ' '; } else { *result++ = s[i]; } } } static void decode_display_descriptor (const uchar *desc, MonitorInfo *info) { switch (desc[0x03]) { case 0xFC: decode_lf_string (desc + 5, 13, info->dsc_product_name); break; case 0xFF: decode_lf_string (desc + 5, 13, info->dsc_serial_number); break; case 0xFE: decode_lf_string (desc + 5, 13, info->dsc_string); break; case 0xFD: /* Range Limits */ break; case 0xFB: /* Color Point */ break; case 0xFA: /* Timing Identifications */ break; case 0xF9: /* Color Management */ break; case 0xF8: /* Timing Codes */ break; case 0xF7: /* Established Timings */ break; case 0x10: break; } } static void decode_detailed_timing (const uchar *timing, DetailedTiming *detailed) { int bits; StereoType stereo[] = { NO_STEREO, NO_STEREO, FIELD_RIGHT, FIELD_LEFT, TWO_WAY_RIGHT_ON_EVEN, TWO_WAY_LEFT_ON_EVEN, FOUR_WAY_INTERLEAVED, SIDE_BY_SIDE }; detailed->pixel_clock = (timing[0x00] | timing[0x01] << 8) * 10000; detailed->h_addr = timing[0x02] | ((timing[0x04] & 0xf0) << 4); detailed->h_blank = timing[0x03] | ((timing[0x04] & 0x0f) << 8); detailed->v_addr = timing[0x05] | ((timing[0x07] & 0xf0) << 4); detailed->v_blank = timing[0x06] | ((timing[0x07] & 0x0f) << 8); detailed->h_front_porch = timing[0x08] | get_bits (timing[0x0b], 6, 7) << 8; detailed->h_sync = timing[0x09] | get_bits (timing[0x0b], 4, 5) << 8; detailed->v_front_porch = get_bits (timing[0x0a], 4, 7) | get_bits (timing[0x0b], 2, 3) << 4; detailed->v_sync = get_bits (timing[0x0a], 0, 3) | get_bits (timing[0x0b], 0, 1) << 4; detailed->width_mm = timing[0x0c] | get_bits (timing[0x0e], 4, 7) << 8; detailed->height_mm = timing[0x0d] | get_bits (timing[0x0e], 0, 3) << 8; detailed->right_border = timing[0x0f]; detailed->top_border = timing[0x10]; detailed->interlaced = get_bit (timing[0x11], 7); /* Stereo */ bits = get_bits (timing[0x11], 5, 6) << 1 | get_bit (timing[0x11], 0); detailed->stereo = stereo[bits]; /* Sync */ bits = timing[0x11]; detailed->digital_sync = get_bit (bits, 4); if (detailed->digital_sync) { detailed->digital.composite = !get_bit (bits, 3); if (detailed->digital.composite) { detailed->digital.serrations = get_bit (bits, 2); detailed->digital.negative_vsync = FALSE; } else { detailed->digital.serrations = FALSE; detailed->digital.negative_vsync = !get_bit (bits, 2); } detailed->digital.negative_hsync = !get_bit (bits, 0); } else { detailed->analog.bipolar = get_bit (bits, 3); detailed->analog.serrations = get_bit (bits, 2); detailed->analog.sync_on_green = !get_bit (bits, 1); } } static int decode_descriptors (const uchar *edid, MonitorInfo *info) { int i; int timing_idx; timing_idx = 0; for (i = 0; i < 4; ++i) { int index = 0x36 + i * 18; if (edid[index + 0] == 0x00 && edid[index + 1] == 0x00) { decode_display_descriptor (edid + index, info); } else { decode_detailed_timing ( edid + index, &(info->detailed_timings[timing_idx++])); } } info->n_detailed_timings = timing_idx; return TRUE; } static void decode_check_sum (const uchar *edid, MonitorInfo *info) { int i; uchar check = 0; for (i = 0; i < 128; ++i) check += edid[i]; info->checksum = check; } MonitorInfo * decode_edid (const uchar *edid) { MonitorInfo *info = calloc (1, sizeof (MonitorInfo)); decode_check_sum (edid, info); if (!decode_header (edid)) return NULL; if (!decode_vendor_and_product_identification (edid, info)) return NULL; if (!decode_edid_version (edid, info)) return NULL; if (!decode_display_parameters (edid, info)) return NULL; if (!decode_color_characteristics (edid, info)) return NULL; if (!decode_established_timings (edid, info)) return NULL; if (!decode_standard_timings (edid, info)) return NULL; if (!decode_descriptors (edid, info)) return NULL; return info; } ---------------------------------------------------------------------------------------------------
EDID 파싱
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
// TODO: rewrite
// FIXME: cleanup 'static' variables
typedef unsigned char byte;
/* byte must be 8 bits */
/* int must be at least 16 bits */
/* long must be at least 32 bits */
#define DIE_MSG( x ) \
{ MSG( x ); exit( 1 ); }
#define UPPER_NIBBLE( x ) \
(((128|64|32|16) & (x)) >> 4)
#define LOWER_NIBBLE( x ) \
((1|2|4|8) & (x))
#define COMBINE_HI_8LO( hi, lo ) \
( (((unsigned)hi) << 8) | (unsigned)lo )
#define COMBINE_HI_4LO( hi, lo ) \
( (((unsigned)hi) << 4) | (unsigned)lo )
const byte edid_v1_header[] = { 0x00, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0x00 };
const byte edid_v1_descriptor_flag[] = { 0x00, 0x00 };
#define EDID_LENGTH 0x80
#define EDID_HEADER 0x00
#define EDID_HEADER_END 0x07
#define ID_MANUFACTURER_NAME 0x08
#define ID_MANUFACTURER_NAME_END 0x09
#define ID_MODEL 0x0a
#define ID_SERIAL_NUMBER 0x0c
#define MANUFACTURE_WEEK 0x10
#define MANUFACTURE_YEAR 0x11
#define EDID_STRUCT_VERSION 0x12
#define EDID_STRUCT_REVISION 0x13
#define DPMS_FLAGS 0x18
#define ESTABLISHED_TIMING_1 0x23
#define ESTABLISHED_TIMING_2 0x24
#define MANUFACTURERS_TIMINGS 0x25
#define DETAILED_TIMING_DESCRIPTIONS_START 0x36
#define DETAILED_TIMING_DESCRIPTION_SIZE 18
#define NO_DETAILED_TIMING_DESCRIPTIONS 4
#define DETAILED_TIMING_DESCRIPTION_1 0x36
#define DETAILED_TIMING_DESCRIPTION_2 0x48
#define DETAILED_TIMING_DESCRIPTION_3 0x5a
#define DETAILED_TIMING_DESCRIPTION_4 0x6c
#define PIXEL_CLOCK_LO (unsigned)dtd[ 0 ]
#define PIXEL_CLOCK_HI (unsigned)dtd[ 1 ]
#define PIXEL_CLOCK (COMBINE_HI_8LO( PIXEL_CLOCK_HI,PIXEL_CLOCK_LO )*10000)
#define H_ACTIVE_LO (unsigned)dtd[ 2 ]
#define H_BLANKING_LO (unsigned)dtd[ 3 ]
#define H_ACTIVE_HI UPPER_NIBBLE( (unsigned)dtd[ 4 ] )
#define H_ACTIVE COMBINE_HI_8LO( H_ACTIVE_HI, H_ACTIVE_LO )
#define H_BLANKING_HI LOWER_NIBBLE( (unsigned)dtd[ 4 ] )
#define H_BLANKING COMBINE_HI_8LO( H_BLANKING_HI, H_BLANKING_LO )
#define V_ACTIVE_LO (unsigned)dtd[ 5 ]
#define V_BLANKING_LO (unsigned)dtd[ 6 ]
#define V_ACTIVE_HI UPPER_NIBBLE( (unsigned)dtd[ 7 ] )
#define V_ACTIVE COMBINE_HI_8LO( V_ACTIVE_HI, V_ACTIVE_LO )
#define V_BLANKING_HI LOWER_NIBBLE( (unsigned)dtd[ 7 ] )
#define V_BLANKING COMBINE_HI_8LO( V_BLANKING_HI, V_BLANKING_LO )
#define H_SYNC_OFFSET_LO (unsigned)dtd[ 8 ]
#define H_SYNC_WIDTH_LO (unsigned)dtd[ 9 ]
#define V_SYNC_OFFSET_LO UPPER_NIBBLE( (unsigned)dtd[ 10 ] )
#define V_SYNC_WIDTH_LO LOWER_NIBBLE( (unsigned)dtd[ 10 ] )
#define V_SYNC_WIDTH_HI ((unsigned)dtd[ 11 ] & (1|2))
#define V_SYNC_OFFSET_HI (((unsigned)dtd[ 11 ] & (4|8)) >> 2)
#define H_SYNC_WIDTH_HI (((unsigned)dtd[ 11 ] & (16|32)) >> 4)
#define H_SYNC_OFFSET_HI (((unsigned)dtd[ 11 ] & (64|128)) >> 6)
#define V_SYNC_WIDTH COMBINE_HI_4LO( V_SYNC_WIDTH_HI, V_SYNC_WIDTH_LO )
#define V_SYNC_OFFSET COMBINE_HI_4LO( V_SYNC_OFFSET_HI, V_SYNC_OFFSET_LO )
#define H_SYNC_WIDTH COMBINE_HI_4LO( H_SYNC_WIDTH_HI, H_SYNC_WIDTH_LO )
#define H_SYNC_OFFSET COMBINE_HI_4LO( H_SYNC_OFFSET_HI, H_SYNC_OFFSET_LO )
#define H_SIZE_LO (unsigned)dtd[ 12 ]
#define V_SIZE_LO (unsigned)dtd[ 13 ]
#define H_SIZE_HI UPPER_NIBBLE( (unsigned)dtd[ 14 ] )
#define V_SIZE_HI LOWER_NIBBLE( (unsigned)dtd[ 14 ] )
#define H_SIZE COMBINE_HI_8LO( H_SIZE_HI, H_SIZE_LO )
#define V_SIZE COMBINE_HI_8LO( V_SIZE_HI, V_SIZE_LO )
#define H_BORDER (unsigned)dtd[ 15 ]
#define V_BORDER (unsigned)dtd[ 16 ]
#define FLAGS (unsigned)dtd[ 17 ]
#define INTERLACED (FLAGS&128)
#define SYNC_TYPE (FLAGS&3<<3) /* bits 4,3 */
#define SYNC_SEPARATE (3<<3)
#define HSYNC_POSITIVE (FLAGS & 4)
#define VSYNC_POSITIVE (FLAGS & 2)
#define MONITOR_NAME 0xfc
#define MONITOR_LIMITS 0xfd
#define UNKNOWN_DESCRIPTOR -1
#define DETAILED_TIMING_BLOCK -2
#define DESCRIPTOR_DATA 5
#define V_MIN_RATE block[ 5 ]
#define V_MAX_RATE block[ 6 ]
#define H_MIN_RATE block[ 7 ]
#define H_MAX_RATE block[ 8 ]
#define MAX_PIXEL_CLOCK (((int)block[ 9 ]) * 10)
#define GTF_SUPPORT block[10]
#define DPMS_ACTIVE_OFF (1 << 5)
#define DPMS_SUSPEND (1 << 6)
#define DPMS_STANDBY (1 << 7)
char* myname;
void MSG( const char* x )
{
fprintf( stderr, "%s: %s\n", myname, x );
}
int
parse_edid( byte* edid );
int
parse_timing_description( byte* dtd );
int
parse_monitor_limits( byte* block );
int
block_type( byte* block );
char*
get_monitor_name( byte const* block );
char*
get_vendor_sign( byte const* block );
int
parse_dpms_capabilities( byte flags );
int
main( int argc, char** argv )
{
byte edid[ EDID_LENGTH ];
FILE* edid_file;
myname = argv[ 0 ];
fprintf( stderr, "%s: parse-edid version %s\n", myname, VERSION );
if ( argc > 2 )
{
DIE_MSG( "syntax: [input EDID file]" );
}
else
{
if ( argc == 2 )
{
edid_file = fopen( argv[ 1 ], "rb" );
if ( !edid_file )
DIE_MSG( "unable to open file for input" );
}
else
edid_file = stdin;
}
if ( fread( edid, sizeof( byte ), EDID_LENGTH, edid_file )
!= EDID_LENGTH )
{
DIE_MSG( "IO error reading EDID" );
}
fclose( edid_file );
return parse_edid( edid );
}
int
parse_edid( byte* edid )
{
unsigned i;
byte* block;
char* monitor_name = NULL;
char monitor_alt_name[100];
byte checksum = 0;
char *vendor_sign;
int ret = 0;
for( i = 0; i < EDID_LENGTH; i++ )
checksum += edid[ i ];
if ( checksum != 0 ) {
MSG( "EDID checksum failed - data is corrupt. Continuing anyway." );
ret = 1;
} else
MSG( "EDID checksum passed." );
if ( strncmp( edid+EDID_HEADER, edid_v1_header, EDID_HEADER_END+1 ) )
{
MSG( "first bytes don't match EDID version 1 header" );
MSG( "do not trust output (if any)." );
ret = 1;
}
printf( "\n\t# EDID version %d revision %d\n", (int)edid[EDID_STRUCT_VERSION],(int)edid[EDID_STRUCT_REVISION] );
vendor_sign = get_vendor_sign( edid + ID_MANUFACTURER_NAME );
printf( "Section \"Monitor\"\n" );
block = edid + DETAILED_TIMING_DESCRIPTIONS_START;
for( i = 0; i < NO_DETAILED_TIMING_DESCRIPTIONS; i++,
block += DETAILED_TIMING_DESCRIPTION_SIZE )
{
if ( block_type( block ) == MONITOR_NAME )
{
monitor_name = get_monitor_name( block );
break;
}
}
if (!monitor_name) {
/* Stupid djgpp hasn't snprintf so we have to hack something together */
if(strlen(vendor_sign) + 10 > sizeof(monitor_alt_name))
vendor_sign[3] = 0;
sprintf(monitor_alt_name, "%s:%02x%02x",
vendor_sign, edid[ID_MODEL], edid[ID_MODEL+1]) ;
monitor_name = monitor_alt_name;
}
printf( "\tIdentifier \"%s\"\n", monitor_name );
printf( "\tVendorName \"%s\"\n", vendor_sign );
printf( "\tModelName \"%s\"\n", monitor_name );
block = edid + DETAILED_TIMING_DESCRIPTIONS_START;
for( i = 0; i < NO_DETAILED_TIMING_DESCRIPTIONS; i++,
block += DETAILED_TIMING_DESCRIPTION_SIZE )
{
if ( block_type( block ) == MONITOR_LIMITS )
parse_monitor_limits( block );
}
parse_dpms_capabilities(edid[DPMS_FLAGS]);
block = edid + DETAILED_TIMING_DESCRIPTIONS_START;
for( i = 0; i < NO_DETAILED_TIMING_DESCRIPTIONS; i++,
block += DETAILED_TIMING_DESCRIPTION_SIZE )
{
if ( block_type( block ) == DETAILED_TIMING_BLOCK )
parse_timing_description( block );
}
printf( "EndSection\n" );
return ret;
}
int
parse_timing_description( byte* dtd )
{
int htotal, vtotal;
htotal = H_ACTIVE + H_BLANKING;
vtotal = V_ACTIVE + V_BLANKING;
printf( "\tMode \t\"%dx%d\"", H_ACTIVE, V_ACTIVE );
printf( "\t# vfreq %3.3fHz, hfreq %6.3fkHz\n",
(double)PIXEL_CLOCK/((double)vtotal*(double)htotal),
(double)PIXEL_CLOCK/(double)(htotal*1000));
printf( "\t\tDotClock\t%f\n", (double)PIXEL_CLOCK/1000000.0 );
printf( "\t\tHTimings\t%u %u %u %u\n", H_ACTIVE,
H_ACTIVE+H_SYNC_OFFSET,
H_ACTIVE+H_SYNC_OFFSET+H_SYNC_WIDTH,
htotal );
printf( "\t\tVTimings\t%u %u %u %u\n", V_ACTIVE,
V_ACTIVE+V_SYNC_OFFSET,
V_ACTIVE+V_SYNC_OFFSET+V_SYNC_WIDTH,
vtotal );
if ( INTERLACED || (SYNC_TYPE == SYNC_SEPARATE)) {
printf( "\t\tFlags\t%s\"%sHSync\" \"%sVSync\"\n",
INTERLACED ? "\"Interlace\" ": "",
HSYNC_POSITIVE ? "+": "-",
VSYNC_POSITIVE ? "+": "-");
}
printf( "\tEndMode\n" );
return 0;
}
int
block_type( byte* block )
{
if ( !strncmp( edid_v1_descriptor_flag, block, 2 ) )
{
printf("\t# Block type: 2:%x 3:%x\n", block[2], block[3]);
/* descriptor */
if ( block[ 2 ] != 0 )
return UNKNOWN_DESCRIPTOR;
return block[ 3 ];
} else {
/* detailed timing block */
return DETAILED_TIMING_BLOCK;
}
}
char*
get_monitor_name( byte const* block )
{
static char name[ 13 ];
unsigned i;
byte const* ptr = block + DESCRIPTOR_DATA;
for( i = 0; i < 13; i++, ptr++ )
{
if ( *ptr == 0xa )
{
name[ i ] = 0;
return name;
}
name[ i ] = *ptr;
}
return name;
}
char* get_vendor_sign( byte const* block )
{
static char sign[4];
unsigned short h;
/*
08h WORD big-endian manufacturer ID (see #00136)
bits 14-10: first letter (01h='A', 02h='B', etc.)
bits 9-5: second letter
bits 4-0: third letter
*/
h = COMBINE_HI_8LO(block[0], block[1]);
sign[0] = ((h>>10) & 0x1f) + 'A' - 1;
sign[1] = ((h>>5) & 0x1f) + 'A' - 1;
sign[2] = (h & 0x1f) + 'A' - 1;
sign[3] = 0;
return sign;
}
int
parse_monitor_limits( byte* block )
{
printf( "\tHorizSync %u-%u\n", H_MIN_RATE, H_MAX_RATE );
printf( "\tVertRefresh %u-%u\n", V_MIN_RATE, V_MAX_RATE );
if ( MAX_PIXEL_CLOCK == 10*0xff )
printf( "\t# Max dot clock not given\n" );
else
printf( "\t# Max dot clock (video bandwidth) %u MHz\n", (int)MAX_PIXEL_CLOCK );
if ( GTF_SUPPORT )
{
printf( "\t# EDID version 3 GTF given: contact author\n" );
}
return 0;
}
int
parse_dpms_capabilities(byte flags)
{
printf("\t# DPMS capabilities: Active off:%s Suspend:%s Standby:%s\n\n",
(flags & DPMS_ACTIVE_OFF) ? "yes" : "no",
(flags & DPMS_SUSPEND) ? "yes" : "no",
(flags & DPMS_STANDBY) ? "yes" : "no");
return 0;
}
모니터 정보보기2 - EDID
#include "windows.h"
#include "setupapi.h"
#include "initguid.h"
#include "stdio.h"
#define NAME_SIZE 128
#define PRINT(_x_) printf _x_
DEFINE_GUID (GUID_CLASS_MONITOR,
0x4d36e96e, 0xe325, 0x11ce, 0xbf, 0xc1, 0x08, 0x00, 0x2b, 0xe1,
0x03, 0x18);
static void
PlayWithDeviceInfo(
IN HDEVINFO devInfo,
IN PSP_DEVINFO_DATA devInfoData
)
{
HKEY hDevRegKey;
DWORD uniID[123];
if (SetupDiGetDeviceRegistryProperty(
devInfo,
devInfoData,
SPDRP_DEVICEDESC,//SPDRP_UI_NUMBER,
NULL,
(PBYTE)(&uniID),
sizeof(uniID),
NULL))
{
printf("UID: %s\n",uniID);
}
else {
printf("ERROR: %d\n",GetLastError());
}
hDevRegKey = SetupDiOpenDevRegKey(
devInfo,
devInfoData,
DICS_FLAG_GLOBAL,
0,
DIREG_DEV,
KEY_ALL_ACCESS);
if (hDevRegKey) {
LONG retValue,i;
DWORD dwType, AcutalValueNameLength= NAME_SIZE;
CHAR valueName[NAME_SIZE];
for (i = 0, retValue = ERROR_SUCCESS; retValue !=
ERROR_NO_MORE_ITEMS; i++)
{
unsigned char EDIDdata[1024];
DWORD j,edidsize=sizeof(EDIDdata);
retValue = RegEnumValue (
hDevRegKey,
i,
&valueName[0],
&AcutalValueNameLength,
NULL,//reserved
&dwType,
EDIDdata, // buffer
&edidsize); // buffer size
if (retValue == ERROR_SUCCESS )
{
if (!strcmp(valueName,"EDID")) {
printf("Found value EDID\n");
{
for (j=0;j<edidsize;j++) {
if (j %16 == 0) printf("\n");
printf("%02x ",EDIDdata[j]);
}
printf("\n");
}
break;
}
}
}
RegCloseKey(hDevRegKey);
}
else {
printf("ERROR:%d\n",GetLastError());
}
}
int EnumDevices()
{
HDEVINFO devInfo = NULL;
SP_DEVINFO_DATA devInfoData;
SP_DEVINFO_LIST_DETAIL_DATA devInfoSetDetailData;
ULONG i;
do
{
devInfo = SetupDiGetClassDevsEx(
&GUID_CLASS_MONITOR, //class GUID
NULL, //enumerator
NULL, //HWND
DIGCF_PRESENT, // Flags //DIGCF_ALLCLASSES|
NULL, // device info, create a new one.
NULL, // machine name, local machine
NULL);// reserved
if (NULL == devInfo)
{
//PrintWin32Error("SetupDiGetClassDevsEx");
break;
}
for (i=0;ERROR_NO_MORE_ITEMS != GetLastError();i++)
{
memset(&devInfoData,0,sizeof(devInfoData));
devInfoData.cbSize = sizeof(devInfoData);
if (SetupDiEnumDeviceInfo(devInfo,i,&devInfoData))
{
PlayWithDeviceInfo(devInfo,&devInfoData);
}
}
} while (FALSE);
return i;
}
int __cdecl main()
{
EnumDevices();
return 0;
}
-
Calvin Guan Software Engineer
ATI Technologies Inc. www.ati.com