ReactOS.org
Sign In
Sign Up
Sign In
Sign Up
Manage this list
×
Keyboard Shortcuts
Thread View
j
: Next unread message
k
: Previous unread message
j a
: Jump to all threads
j l
: Jump to MailingList overview
2026
April
March
February
January
2025
December
November
October
September
August
July
June
May
April
March
February
January
2024
December
November
October
September
August
July
June
May
April
March
February
January
2023
December
November
October
September
August
July
June
May
April
March
February
January
2022
December
November
October
September
August
July
June
May
April
March
February
January
2021
December
November
October
September
August
July
June
May
April
March
February
January
2020
December
November
October
September
August
July
June
May
April
March
February
January
2019
December
November
October
September
August
July
June
May
April
March
February
January
2018
December
November
October
September
August
July
June
May
April
March
February
January
2017
December
November
October
September
August
July
June
May
April
March
February
January
2016
December
November
October
September
August
July
June
May
April
March
February
January
2015
December
November
October
September
August
July
June
May
April
March
February
January
2014
December
November
October
September
August
July
June
May
April
March
February
January
2013
December
November
October
September
August
July
June
May
April
March
February
January
2012
December
November
October
September
August
July
June
May
April
March
February
January
2011
December
November
October
September
August
July
June
May
April
March
February
January
2010
December
November
October
September
August
July
June
May
April
March
February
January
2009
December
November
October
September
August
July
June
May
April
March
February
January
2008
December
November
October
September
August
July
June
May
April
March
February
January
2007
December
November
October
September
August
July
June
May
April
March
February
January
2006
December
November
October
September
August
July
June
May
April
March
February
January
2005
December
November
October
September
August
July
June
May
April
March
February
January
2004
December
November
October
September
August
July
June
May
April
March
February
List overview
Download
Ros-diffs
----- 2026 -----
April 2026
March 2026
February 2026
January 2026
----- 2025 -----
December 2025
November 2025
October 2025
September 2025
August 2025
July 2025
June 2025
May 2025
April 2025
March 2025
February 2025
January 2025
----- 2024 -----
December 2024
November 2024
October 2024
September 2024
August 2024
July 2024
June 2024
May 2024
April 2024
March 2024
February 2024
January 2024
----- 2023 -----
December 2023
November 2023
October 2023
September 2023
August 2023
July 2023
June 2023
May 2023
April 2023
March 2023
February 2023
January 2023
----- 2022 -----
December 2022
November 2022
October 2022
September 2022
August 2022
July 2022
June 2022
May 2022
April 2022
March 2022
February 2022
January 2022
----- 2021 -----
December 2021
November 2021
October 2021
September 2021
August 2021
July 2021
June 2021
May 2021
April 2021
March 2021
February 2021
January 2021
----- 2020 -----
December 2020
November 2020
October 2020
September 2020
August 2020
July 2020
June 2020
May 2020
April 2020
March 2020
February 2020
January 2020
----- 2019 -----
December 2019
November 2019
October 2019
September 2019
August 2019
July 2019
June 2019
May 2019
April 2019
March 2019
February 2019
January 2019
----- 2018 -----
December 2018
November 2018
October 2018
September 2018
August 2018
July 2018
June 2018
May 2018
April 2018
March 2018
February 2018
January 2018
----- 2017 -----
December 2017
November 2017
October 2017
September 2017
August 2017
July 2017
June 2017
May 2017
April 2017
March 2017
February 2017
January 2017
----- 2016 -----
December 2016
November 2016
October 2016
September 2016
August 2016
July 2016
June 2016
May 2016
April 2016
March 2016
February 2016
January 2016
----- 2015 -----
December 2015
November 2015
October 2015
September 2015
August 2015
July 2015
June 2015
May 2015
April 2015
March 2015
February 2015
January 2015
----- 2014 -----
December 2014
November 2014
October 2014
September 2014
August 2014
July 2014
June 2014
May 2014
April 2014
March 2014
February 2014
January 2014
----- 2013 -----
December 2013
November 2013
October 2013
September 2013
August 2013
July 2013
June 2013
May 2013
April 2013
March 2013
February 2013
January 2013
----- 2012 -----
December 2012
November 2012
October 2012
September 2012
August 2012
July 2012
June 2012
May 2012
April 2012
March 2012
February 2012
January 2012
----- 2011 -----
December 2011
November 2011
October 2011
September 2011
August 2011
July 2011
June 2011
May 2011
April 2011
March 2011
February 2011
January 2011
----- 2010 -----
December 2010
November 2010
October 2010
September 2010
August 2010
July 2010
June 2010
May 2010
April 2010
March 2010
February 2010
January 2010
----- 2009 -----
December 2009
November 2009
October 2009
September 2009
August 2009
July 2009
June 2009
May 2009
April 2009
March 2009
February 2009
January 2009
----- 2008 -----
December 2008
November 2008
October 2008
September 2008
August 2008
July 2008
June 2008
May 2008
April 2008
March 2008
February 2008
January 2008
----- 2007 -----
December 2007
November 2007
October 2007
September 2007
August 2007
July 2007
June 2007
May 2007
April 2007
March 2007
February 2007
January 2007
----- 2006 -----
December 2006
November 2006
October 2006
September 2006
August 2006
July 2006
June 2006
May 2006
April 2006
March 2006
February 2006
January 2006
----- 2005 -----
December 2005
November 2005
October 2005
September 2005
August 2005
July 2005
June 2005
May 2005
April 2005
March 2005
February 2005
January 2005
----- 2004 -----
December 2004
November 2004
October 2004
September 2004
August 2004
July 2004
June 2004
May 2004
April 2004
March 2004
February 2004
ros-diffs@reactos.org
81390 discussions
Start a n
N
ew thread
01/01: [WINHTTP_WINETEST] Sync with Wine 3.0. CORE-14225
by Amine Khaldi
20 Jan '18
20 Jan '18
https://git.reactos.org/?p=reactos.git;a=commitdiff;h=69d123ae2547edb8b80d0…
commit 69d123ae2547edb8b80d013fe6e2ecd3bf3a8b47 Author: Amine Khaldi <amine.khaldi(a)reactos.org> AuthorDate: Sat Jan 20 13:56:09 2018 +0100 Commit: Amine Khaldi <amine.khaldi(a)reactos.org> CommitDate: Sat Jan 20 13:56:09 2018 +0100 [WINHTTP_WINETEST] Sync with Wine 3.0. CORE-14225 --- modules/rostests/winetests/winhttp/notification.c | 6 +- modules/rostests/winetests/winhttp/winhttp.c | 71 ++++++++++++++++++++++- 2 files changed, 72 insertions(+), 5 deletions(-) diff --git a/modules/rostests/winetests/winhttp/notification.c b/modules/rostests/winetests/winhttp/notification.c index 79f6b8c935..bcb7a0b318 100644 --- a/modules/rostests/winetests/winhttp/notification.c +++ b/modules/rostests/winetests/winhttp/notification.c @@ -944,7 +944,7 @@ static void _read_request_data(struct test_request *req, struct info *info, cons WaitForSingleObject( info->wait, INFINITE ); len = strlen(expected_data); - ok(!memcmp(buffer, expected_data, len), "unexpeceted data\n"); + ok(!memcmp(buffer, expected_data, len), "unexpected data\n"); } static void test_persistent_connection(int port) @@ -1033,14 +1033,16 @@ START_TEST (notification) ret = WaitForSingleObject( si.event, 10000 ); ok(ret == WAIT_OBJECT_0, "failed to start winhttp test server %u\n", GetLastError()); if (ret != WAIT_OBJECT_0) + { + CloseHandle(thread); return; + } #ifdef __REACTOS__ if (!winetest_interactive) { skip("Skipping test_persistent_connection due to hang. See ROSTESTS-295.\n"); } -else #endif test_persistent_connection( si.port ); diff --git a/modules/rostests/winetests/winhttp/winhttp.c b/modules/rostests/winetests/winhttp/winhttp.c index 8b2b601ba6..d9024dfb7d 100644 --- a/modules/rostests/winetests/winhttp/winhttp.c +++ b/modules/rostests/winetests/winhttp/winhttp.c @@ -326,7 +326,7 @@ static void test_SendRequest (void) static CHAR post_data[] = "mode=Test"; static const char test_post[] = "mode => Test\0\n"; HINTERNET session, request, connection; - DWORD header_len, optional_len, total_len, bytes_rw, size, err; + DWORD header_len, optional_len, total_len, bytes_rw, size, err, disable; DWORD_PTR context; BOOL ret; CHAR buffer[256]; @@ -357,6 +357,12 @@ static void test_SendRequest (void) ret = WinHttpSetOption(request, WINHTTP_OPTION_CONTEXT_VALUE, &context, sizeof(context)); ok(ret, "WinHttpSetOption failed: %u\n", GetLastError()); + /* writing more data than promised by the content-length header causes an error when the connection + is resued, so disable keep-alive */ + disable = WINHTTP_DISABLE_KEEP_ALIVE; + ret = WinHttpSetOption(request, WINHTTP_OPTION_DISABLE_FEATURE, &disable, sizeof(disable)); + ok(ret, "WinHttpSetOption failed: %u\n", GetLastError()); + context++; ret = WinHttpSendRequest(request, content_type, header_len, post_data, optional_len, total_len, context); err = GetLastError(); @@ -575,7 +581,7 @@ static void test_WinHttpAddHeaders(void) SetLastError(0xdeadbeef); ret = WinHttpAddRequestHeaders(request, test_headers[0], -1L, WINHTTP_ADDREQ_FLAG_ADD); err = GetLastError(); - ok(ret, "WinHttpAddRequestHeader failed to add new header, got %d with error %u.\n", ret, err); + ok(ret, "WinHttpAddRequestHeaders failed to add new header, got %d with error %u.\n", ret, err); ok(err == ERROR_SUCCESS || broken(err == 0xdeadbeef) /* < win7 */, "got %u\n", err); index = 0; @@ -981,7 +987,7 @@ static void test_secure_connection(void) { static const char data_start[] = "<!DOCTYPE html PUBLIC"; HINTERNET ses, con, req; - DWORD size, status, policy, bitness, read_size, err, available_size; + DWORD size, status, policy, bitness, read_size, err, available_size, protocols; BOOL ret; CERT_CONTEXT *cert; WINHTTP_CERTIFICATE_INFO info; @@ -994,6 +1000,11 @@ static void test_secure_connection(void) ret = WinHttpSetOption(ses, WINHTTP_OPTION_REDIRECT_POLICY, &policy, sizeof(policy)); ok(ret, "failed to set redirect policy %u\n", GetLastError()); + protocols = WINHTTP_FLAG_SECURE_PROTOCOL_TLS1_2; + ret = WinHttpSetOption(ses, WINHTTP_OPTION_SECURE_PROTOCOLS, &protocols, sizeof(protocols)); + err = GetLastError(); + ok(ret || err == ERROR_INVALID_PARAMETER /* < win7 */, "failed to set protocols %u\n", err); + con = WinHttpConnect(ses, test_winehq, 443, 0); ok(con != NULL, "failed to open a connection %u\n", GetLastError()); @@ -2077,6 +2088,7 @@ static const char largeauth[] = static const char unauthorized[] = "Unauthorized"; static const char hello_world[] = "Hello World"; +static const char auth_unseen[] = "Auth Unseen"; struct server_info { @@ -2136,6 +2148,15 @@ static DWORD CALLBACK server_thread(LPVOID param) send(c, okmsg, sizeof okmsg - 1, 0); send(c, page1, sizeof page1 - 1, 0); } + if (strstr(buffer, "/auth_with_creds")) + { + send(c, okauthmsg, sizeof okauthmsg - 1, 0); + if (strstr(buffer, "Authorization: Basic dXNlcjpwd2Q=")) + send(c, hello_world, sizeof hello_world - 1, 0); + else + send(c, auth_unseen, sizeof auth_unseen - 1, 0); + continue; + } if (strstr(buffer, "/auth")) { if (strstr(buffer, "Authorization: Basic dXNlcjpwd2Q=")) @@ -2316,6 +2337,7 @@ static void test_basic_request(int port, const WCHAR *verb, const WCHAR *path) static void test_basic_authentication(int port) { static const WCHAR authW[] = {'/','a','u','t','h',0}; + static const WCHAR auth_with_credsW[] = {'/','a','u','t','h','_','w','i','t','h','_','c','r','e','d','s',0}; static WCHAR userW[] = {'u','s','e','r',0}; static WCHAR passW[] = {'p','w','d',0}; static WCHAR pass2W[] = {'p','w','d','2',0}; @@ -2479,6 +2501,45 @@ static void test_basic_authentication(int port) WinHttpCloseHandle(con); WinHttpCloseHandle(ses); + /* now set the credentials first to show that they get sent with the first request */ + ses = WinHttpOpen(test_useragent, WINHTTP_ACCESS_TYPE_NO_PROXY, NULL, NULL, 0); + ok(ses != NULL, "failed to open session %u\n", GetLastError()); + + con = WinHttpConnect(ses, localhostW, port, 0); + ok(con != NULL, "failed to open a connection %u\n", GetLastError()); + + req = WinHttpOpenRequest(con, NULL, auth_with_credsW, NULL, NULL, NULL, 0); + ok(req != NULL, "failed to open a request %u\n", GetLastError()); + + ret = WinHttpSetCredentials(req, WINHTTP_AUTH_TARGET_SERVER, WINHTTP_AUTH_SCHEME_BASIC, userW, passW, NULL); + ok(ret, "failed to set credentials %u\n", GetLastError()); + + ret = WinHttpSendRequest(req, NULL, 0, NULL, 0, 0, 0); + ok(ret, "failed to send request %u\n", GetLastError()); + + ret = WinHttpReceiveResponse(req, NULL); + ok(ret, "failed to receive response %u\n", GetLastError()); + + status = 0xdeadbeef; + size = sizeof(status); + ret = WinHttpQueryHeaders(req, WINHTTP_QUERY_STATUS_CODE|WINHTTP_QUERY_FLAG_NUMBER, NULL, &status, &size, NULL); + ok(ret, "failed to query status code %u\n", GetLastError()); + ok(status == HTTP_STATUS_OK, "request failed unexpectedly %u\n", status); + + size = 0; + ret = WinHttpReadData(req, buffer, sizeof(buffer), &size); + error = GetLastError(); + ok(ret || broken(error == ERROR_WINHTTP_SHUTDOWN || error == ERROR_WINHTTP_TIMEOUT) /* XP */, "failed to read data %u\n", GetLastError()); + if (ret) + { + ok(size == 11, "expected 11, got %u\n", size); + ok(!memcmp(buffer, hello_world, 11), "got %s\n", buffer); + } + + WinHttpCloseHandle(req); + WinHttpCloseHandle(con); + WinHttpCloseHandle(ses); + /* credentials set with WinHttpSetCredentials take precedence over those set through options */ ses = WinHttpOpen(test_useragent, WINHTTP_ACCESS_TYPE_NO_PROXY, NULL, NULL, 0); @@ -4426,7 +4487,10 @@ START_TEST (winhttp) ret = WaitForSingleObject(si.event, 10000); ok(ret == WAIT_OBJECT_0, "failed to start winhttp test server %u\n", GetLastError()); if (ret != WAIT_OBJECT_0) + { + CloseHandle(thread); return; + } test_IWinHttpRequest(si.port); test_connection_info(si.port); @@ -4446,4 +4510,5 @@ START_TEST (winhttp) test_basic_request(si.port, NULL, quitW); WaitForSingleObject(thread, 3000); + CloseHandle(thread); }
1
0
0
0
01/01: [WINHTTP] Sync with Wine 3.0. CORE-14225
by Amine Khaldi
20 Jan '18
20 Jan '18
https://git.reactos.org/?p=reactos.git;a=commitdiff;h=9048bdf976df38c94e2ad…
commit 9048bdf976df38c94e2adb6faf976ccb83e952c2 Author: Amine Khaldi <amine.khaldi(a)reactos.org> AuthorDate: Sat Jan 20 13:55:24 2018 +0100 Commit: Amine Khaldi <amine.khaldi(a)reactos.org> CommitDate: Sat Jan 20 13:55:24 2018 +0100 [WINHTTP] Sync with Wine 3.0. CORE-14225 --- dll/win32/winhttp/cookie.c | 2 +- dll/win32/winhttp/net.c | 56 +- dll/win32/winhttp/request.c | 2091 ++++++++++++++++++----------------- dll/win32/winhttp/session.c | 38 +- dll/win32/winhttp/winhttp_private.h | 9 +- media/doc/README.WINE | 2 +- 6 files changed, 1116 insertions(+), 1082 deletions(-) diff --git a/dll/win32/winhttp/cookie.c b/dll/win32/winhttp/cookie.c index eb37d6f852..2d2dbf325e 100644 --- a/dll/win32/winhttp/cookie.c +++ b/dll/win32/winhttp/cookie.c @@ -140,7 +140,7 @@ static cookie_t *parse_cookie( const WCHAR *string ) if (*p++ == '=') { - while (*p && *p == ' ') p++; + while (*p == ' ') p++; len = strlenW( p ); while (len && p[len - 1] == ' ') len--; diff --git a/dll/win32/winhttp/net.c b/dll/win32/winhttp/net.c index 5c4ace898c..bf78b22647 100644 --- a/dll/win32/winhttp/net.c +++ b/dll/win32/winhttp/net.c @@ -131,7 +131,7 @@ static int sock_send(int fd, const void *msg, size_t len, int flags) int ret; do { - ret = send(fd, msg, len, flags); + if ((ret = send(fd, msg, len, flags)) == -1) WARN("send error %s\n", strerror(errno)); } while(ret == -1 && errno == EINTR); return ret; @@ -142,7 +142,7 @@ static int sock_recv(int fd, void *msg, size_t len, int flags) int ret; do { - ret = recv(fd, msg, len, flags); + if ((ret = recv(fd, msg, len, flags)) == -1) WARN("recv error %s\n", strerror(errno)); } while(ret == -1 && errno == EINTR); return ret; @@ -241,41 +241,6 @@ static DWORD netconn_verify_cert( PCCERT_CONTEXT cert, WCHAR *server, DWORD secu return err; } -static SecHandle cred_handle; -static BOOL cred_handle_initialized; - -static CRITICAL_SECTION init_sechandle_cs; -static CRITICAL_SECTION_DEBUG init_sechandle_cs_debug = { - 0, 0, &init_sechandle_cs, - { &init_sechandle_cs_debug.ProcessLocksList, - &init_sechandle_cs_debug.ProcessLocksList }, - 0, 0, { (DWORD_PTR)(__FILE__ ": init_sechandle_cs") } -}; -static CRITICAL_SECTION init_sechandle_cs = { &init_sechandle_cs_debug, -1, 0, 0, 0, 0 }; - -static BOOL ensure_cred_handle(void) -{ - BOOL ret = TRUE; - - EnterCriticalSection(&init_sechandle_cs); - - if(!cred_handle_initialized) { - SECURITY_STATUS res; - - res = AcquireCredentialsHandleW(NULL, (WCHAR*)UNISP_NAME_W, SECPKG_CRED_OUTBOUND, NULL, NULL, - NULL, NULL, &cred_handle, NULL); - if(res == SEC_E_OK) { - cred_handle_initialized = TRUE; - }else { - WARN("AcquireCredentialsHandleW failed: %u\n", res); - ret = FALSE; - } - } - - LeaveCriticalSection(&init_sechandle_cs); - return ret; -} - #ifdef __REACTOS__ static BOOL winsock_initialized = FALSE; BOOL netconn_init_winsock() @@ -300,9 +265,6 @@ BOOL netconn_init_winsock() void netconn_unload( void ) { - if(cred_handle_initialized) - FreeCredentialsHandle(&cred_handle); - DeleteCriticalSection(&init_sechandle_cs); #ifndef HAVE_GETADDRINFO DeleteCriticalSection(&cs_gethostbyname); #endif @@ -439,7 +401,7 @@ BOOL netconn_close( netconn_t *conn ) return TRUE; } -BOOL netconn_secure_connect( netconn_t *conn, WCHAR *hostname, DWORD security_flags ) +BOOL netconn_secure_connect( netconn_t *conn, WCHAR *hostname, DWORD security_flags, CredHandle *cred_handle ) { SecBuffer out_buf = {0, SECBUFFER_TOKEN, NULL}, in_bufs[2] = {{0, SECBUFFER_TOKEN}, {0, SECBUFFER_EMPTY}}; SecBufferDesc out_desc = {SECBUFFER_VERSION, 1, &out_buf}, in_desc = {SECBUFFER_VERSION, 2, in_bufs}; @@ -455,14 +417,11 @@ BOOL netconn_secure_connect( netconn_t *conn, WCHAR *hostname, DWORD security_fl const DWORD isc_req_flags = ISC_REQ_ALLOCATE_MEMORY|ISC_REQ_USE_SESSION_KEY|ISC_REQ_CONFIDENTIALITY |ISC_REQ_SEQUENCE_DETECT|ISC_REQ_REPLAY_DETECT|ISC_REQ_MANUAL_CRED_VALIDATION; - if(!ensure_cred_handle()) - return FALSE; - read_buf = heap_alloc(read_buf_size); if(!read_buf) return FALSE; - status = InitializeSecurityContextW(&cred_handle, NULL, hostname, isc_req_flags, 0, 0, NULL, 0, + status = InitializeSecurityContextW(cred_handle, NULL, hostname, isc_req_flags, 0, 0, NULL, 0, &ctx, &out_desc, &attrs, NULL); assert(status != SEC_E_OK); @@ -514,7 +473,6 @@ BOOL netconn_secure_connect( netconn_t *conn, WCHAR *hostname, DWORD security_fl size = sock_recv(conn->socket, read_buf+in_bufs[0].cbBuffer, read_buf_size-in_bufs[0].cbBuffer, 0); if(size < 1) { - WARN("recv error\n"); status = ERROR_WINHTTP_SECURE_CHANNEL_ERROR; break; } @@ -523,7 +481,7 @@ BOOL netconn_secure_connect( netconn_t *conn, WCHAR *hostname, DWORD security_fl in_bufs[0].cbBuffer += size; in_bufs[0].pvBuffer = read_buf; - status = InitializeSecurityContextW(&cred_handle, &ctx, hostname, isc_req_flags, 0, 0, &in_desc, + status = InitializeSecurityContextW(cred_handle, &ctx, hostname, isc_req_flags, 0, 0, &in_desc, 0, NULL, &out_desc, &attrs, NULL); TRACE("InitializeSecurityContext ret %08x\n", status); @@ -650,10 +608,8 @@ static BOOL read_ssl_chunk(netconn_t *conn, void *buf, SIZE_T buf_size, SIZE_T * conn->extra_buf = NULL; }else { buf_len = sock_recv(conn->socket, conn->ssl_buf+conn->extra_len, ssl_buf_size-conn->extra_len, 0); - if(buf_len < 0) { - WARN("recv failed\n"); + if(buf_len < 0) return FALSE; - } if(!buf_len) { *eof = TRUE; diff --git a/dll/win32/winhttp/request.c b/dll/win32/winhttp/request.c index 128d5cb14c..f3098e34d0 100644 --- a/dll/win32/winhttp/request.c +++ b/dll/win32/winhttp/request.c @@ -29,6 +29,7 @@ #include <winuser.h> #include <httprequest.h> #include <httprequestid.h> +#include <schannel.h> #include "inet_ntop.c" @@ -390,7 +391,7 @@ static BOOL delete_header( request_t *request, DWORD index ) return TRUE; } -BOOL process_header( request_t *request, LPCWSTR field, LPCWSTR value, DWORD flags, BOOL request_only ) +static BOOL process_header( request_t *request, LPCWSTR field, LPCWSTR value, DWORD flags, BOOL request_only ) { int index; header_t hdr; @@ -507,7 +508,7 @@ BOOL WINAPI WinHttpAddRequestHeaders( HINTERNET hrequest, LPCWSTR headers, DWORD BOOL ret; request_t *request; - TRACE("%p, %s, 0x%x, 0x%08x\n", hrequest, debugstr_w(headers), len, flags); + TRACE("%p, %s, %u, 0x%08x\n", hrequest, debugstr_wn(headers, len), len, flags); if (!headers || !len) { @@ -838,1325 +839,1367 @@ BOOL WINAPI WinHttpQueryHeaders( HINTERNET hrequest, DWORD level, LPCWSTR name, return ret; } -static LPWSTR concatenate_string_list( LPCWSTR *list, int len ) -{ - LPCWSTR *t; - LPWSTR str; - - for( t = list; *t ; t++ ) - len += strlenW( *t ); - len++; - - str = heap_alloc( len * sizeof(WCHAR) ); - if (!str) return NULL; - *str = 0; +#undef ARRAYSIZE +#define ARRAYSIZE(array) (sizeof(array) / sizeof((array)[0])) - for( t = list; *t ; t++ ) - strcatW( str, *t ); +static const WCHAR basicW[] = {'B','a','s','i','c',0}; +static const WCHAR ntlmW[] = {'N','T','L','M',0}; +static const WCHAR passportW[] = {'P','a','s','s','p','o','r','t',0}; +static const WCHAR digestW[] = {'D','i','g','e','s','t',0}; +static const WCHAR negotiateW[] = {'N','e','g','o','t','i','a','t','e',0}; - return str; +static const struct +{ + const WCHAR *str; + unsigned int len; + DWORD scheme; } +auth_schemes[] = +{ + { basicW, ARRAYSIZE(basicW) - 1, WINHTTP_AUTH_SCHEME_BASIC }, + { ntlmW, ARRAYSIZE(ntlmW) - 1, WINHTTP_AUTH_SCHEME_NTLM }, + { passportW, ARRAYSIZE(passportW) - 1, WINHTTP_AUTH_SCHEME_PASSPORT }, + { digestW, ARRAYSIZE(digestW) - 1, WINHTTP_AUTH_SCHEME_DIGEST }, + { negotiateW, ARRAYSIZE(negotiateW) - 1, WINHTTP_AUTH_SCHEME_NEGOTIATE } +}; +static const unsigned int num_auth_schemes = sizeof(auth_schemes)/sizeof(auth_schemes[0]); -static LPWSTR build_header_request_string( request_t *request, LPCWSTR verb, - LPCWSTR path, LPCWSTR version ) +static enum auth_scheme scheme_from_flag( DWORD flag ) { - static const WCHAR crlf[] = {'\r','\n',0}; - static const WCHAR space[] = { ' ',0 }; - static const WCHAR colon[] = { ':',' ',0 }; - static const WCHAR twocrlf[] = {'\r','\n','\r','\n', 0}; - LPWSTR requestString; - DWORD len, n; - LPCWSTR *req; - UINT i; - LPWSTR p; + int i; - /* allocate space for an array of all the string pointers to be added */ - len = (request->num_headers) * 4 + 10; - req = heap_alloc( len * sizeof(LPCWSTR) ); - if (!req) return NULL; + for (i = 0; i < num_auth_schemes; i++) if (flag == auth_schemes[i].scheme) return i; + return SCHEME_INVALID; +} - /* add the verb, path and HTTP version string */ - n = 0; - req[n++] = verb; - req[n++] = space; - req[n++] = path; - req[n++] = space; - req[n++] = version; +static DWORD auth_scheme_from_header( WCHAR *header ) +{ + unsigned int i; - /* Append custom request headers */ - for (i = 0; i < request->num_headers; i++) + for (i = 0; i < num_auth_schemes; i++) { - if (request->headers[i].is_request) - { - req[n++] = crlf; - req[n++] = request->headers[i].field; - req[n++] = colon; - req[n++] = request->headers[i].value; - - TRACE("Adding custom header %s (%s)\n", - debugstr_w(request->headers[i].field), - debugstr_w(request->headers[i].value)); - } + if (!strncmpiW( header, auth_schemes[i].str, auth_schemes[i].len ) && + (header[auth_schemes[i].len] == ' ' || !header[auth_schemes[i].len])) return auth_schemes[i].scheme; } - - if( n >= len ) - ERR("oops. buffer overrun\n"); - - req[n] = NULL; - requestString = concatenate_string_list( req, 4 ); - heap_free( req ); - if (!requestString) return NULL; - - /* - * Set (header) termination string for request - * Make sure there are exactly two new lines at the end of the request - */ - p = &requestString[strlenW(requestString)-1]; - while ( (*p == '\n') || (*p == '\r') ) - p--; - strcpyW( p+1, twocrlf ); - - return requestString; + return 0; } -static BOOL read_reply( request_t *request ); - -static BOOL secure_proxy_connect( request_t *request ) +static BOOL query_auth_schemes( request_t *request, DWORD level, LPDWORD supported, LPDWORD first ) { - static const WCHAR verbConnect[] = {'C','O','N','N','E','C','T',0}; - static const WCHAR fmt[] = {'%','s',':','%','u',0}; + DWORD index = 0, supported_schemes = 0, first_scheme = 0; BOOL ret = FALSE; - LPWSTR path; - connect_t *connect = request->connect; - path = heap_alloc( (strlenW( connect->hostname ) + 13) * sizeof(WCHAR) ); - if (path) + for (;;) { - LPWSTR requestString; - - sprintfW( path, fmt, connect->hostname, connect->hostport ); - requestString = build_header_request_string( request, verbConnect, - path, http1_1 ); - heap_free( path ); - if (requestString) - { - LPSTR req_ascii = strdupWA( requestString ); + WCHAR *buffer; + DWORD size, scheme; - heap_free( requestString ); - if (req_ascii) - { - int len = strlen( req_ascii ), bytes_sent; + size = 0; + query_headers( request, level, NULL, NULL, &size, &index ); + if (get_last_error() != ERROR_INSUFFICIENT_BUFFER) break; - ret = netconn_send( request->netconn, req_ascii, len, &bytes_sent ); - heap_free( req_ascii ); - if (ret) - ret = read_reply( request ); - } + index--; + if (!(buffer = heap_alloc( size ))) return FALSE; + if (!query_headers( request, level, NULL, buffer, &size, &index )) + { + heap_free( buffer ); + return FALSE; } - } - return ret; -} + scheme = auth_scheme_from_header( buffer ); + heap_free( buffer ); + if (!scheme) continue; -#ifndef INET6_ADDRSTRLEN -#define INET6_ADDRSTRLEN 46 -#endif + if (!first_scheme) first_scheme = scheme; + supported_schemes |= scheme; -static WCHAR *addr_to_str( struct sockaddr_storage *addr ) -{ - char buf[INET6_ADDRSTRLEN]; - void *src; + ret = TRUE; + } - switch (addr->ss_family) + if (ret) { - case AF_INET: - src = &((struct sockaddr_in *)addr)->sin_addr; - break; - case AF_INET6: - src = &((struct sockaddr_in6 *)addr)->sin6_addr; - break; - default: - WARN("unsupported address family %d\n", addr->ss_family); - return NULL; + *supported = supported_schemes; + *first = first_scheme; } - if (!inet_ntop( addr->ss_family, src, buf, sizeof(buf) )) return NULL; - return strdupAW( buf ); + return ret; } -static CRITICAL_SECTION connection_pool_cs; -static CRITICAL_SECTION_DEBUG connection_pool_debug = +/*********************************************************************** + * WinHttpQueryAuthSchemes (winhttp.@) + */ +BOOL WINAPI WinHttpQueryAuthSchemes( HINTERNET hrequest, LPDWORD supported, LPDWORD first, LPDWORD target ) { - 0, 0, &connection_pool_cs, - { &connection_pool_debug.ProcessLocksList, &connection_pool_debug.ProcessLocksList }, - 0, 0, { (DWORD_PTR)(__FILE__ ": connection_pool_cs") } -}; -static CRITICAL_SECTION connection_pool_cs = { &connection_pool_debug, -1, 0, 0, 0, 0 }; + BOOL ret = FALSE; + request_t *request; -static struct list connection_pool = LIST_INIT( connection_pool ); + TRACE("%p, %p, %p, %p\n", hrequest, supported, first, target); -void release_host( hostdata_t *host ) -{ - LONG ref; + if (!(request = (request_t *)grab_object( hrequest ))) + { + set_last_error( ERROR_INVALID_HANDLE ); + return FALSE; + } + if (request->hdr.type != WINHTTP_HANDLE_TYPE_REQUEST) + { + release_object( &request->hdr ); + set_last_error( ERROR_WINHTTP_INCORRECT_HANDLE_TYPE ); + return FALSE; + } + if (!supported || !first || !target) + { + release_object( &request->hdr ); + set_last_error( ERROR_INVALID_PARAMETER ); + return FALSE; - EnterCriticalSection( &connection_pool_cs ); - if (!(ref = --host->ref)) list_remove( &host->entry ); - LeaveCriticalSection( &connection_pool_cs ); - if (ref) return; + } - assert( list_empty( &host->connections ) ); - heap_free( host->hostname ); - heap_free( host ); -} + if (query_auth_schemes( request, WINHTTP_QUERY_WWW_AUTHENTICATE, supported, first )) + { + *target = WINHTTP_AUTH_TARGET_SERVER; + ret = TRUE; + } + else if (query_auth_schemes( request, WINHTTP_QUERY_PROXY_AUTHENTICATE, supported, first )) + { + *target = WINHTTP_AUTH_TARGET_PROXY; + ret = TRUE; + } -static BOOL connection_collector_running; + release_object( &request->hdr ); + if (ret) set_last_error( ERROR_SUCCESS ); + return ret; +} -static DWORD WINAPI connection_collector(void *arg) +static UINT encode_base64( const char *bin, unsigned int len, WCHAR *base64 ) { - unsigned int remaining_connections; - netconn_t *netconn, *next_netconn; - hostdata_t *host, *next_host; - ULONGLONG now; + UINT n = 0, x; + static const char base64enc[] = + "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"; - do + while (len > 0) { - /* FIXME: Use more sophisticated method */ - Sleep(5000); - remaining_connections = 0; - now = GetTickCount64(); - - EnterCriticalSection(&connection_pool_cs); + /* first 6 bits, all from bin[0] */ + base64[n++] = base64enc[(bin[0] & 0xfc) >> 2]; + x = (bin[0] & 3) << 4; - LIST_FOR_EACH_ENTRY_SAFE(host, next_host, &connection_pool, hostdata_t, entry) - { - LIST_FOR_EACH_ENTRY_SAFE(netconn, next_netconn, &host->connections, netconn_t, entry) - { - if (netconn->keep_until < now) - { - TRACE("freeing %p\n", netconn); - list_remove(&netconn->entry); - netconn_close(netconn); - } - else - { - remaining_connections++; - } - } + /* next 6 bits, 2 from bin[0] and 4 from bin[1] */ + if (len == 1) + { + base64[n++] = base64enc[x]; + base64[n++] = '='; + base64[n++] = '='; + break; } + base64[n++] = base64enc[x | ((bin[1] & 0xf0) >> 4)]; + x = (bin[1] & 0x0f) << 2; - if (!remaining_connections) connection_collector_running = FALSE; - - LeaveCriticalSection(&connection_pool_cs); - } while(remaining_connections); + /* next 6 bits 4 from bin[1] and 2 from bin[2] */ + if (len == 2) + { + base64[n++] = base64enc[x]; + base64[n++] = '='; + break; + } + base64[n++] = base64enc[x | ((bin[2] & 0xc0) >> 6)]; - FreeLibraryAndExitThread( winhttp_instance, 0 ); + /* last 6 bits, all from bin [2] */ + base64[n++] = base64enc[bin[2] & 0x3f]; + bin += 3; + len -= 3; + } + base64[n] = 0; + return n; } -static void cache_connection( netconn_t *netconn ) +static inline char decode_char( WCHAR c ) { - TRACE( "caching connection %p\n", netconn ); + if (c >= 'A' && c <= 'Z') return c - 'A'; + if (c >= 'a' && c <= 'z') return c - 'a' + 26; + if (c >= '0' && c <= '9') return c - '0' + 52; + if (c == '+') return 62; + if (c == '/') return 63; + return 64; +} - EnterCriticalSection( &connection_pool_cs ); +static unsigned int decode_base64( const WCHAR *base64, unsigned int len, char *buf ) +{ + unsigned int i = 0; + char c0, c1, c2, c3; + const WCHAR *p = base64; - netconn->keep_until = GetTickCount64() + DEFAULT_KEEP_ALIVE_TIMEOUT; - list_add_head( &netconn->host->connections, &netconn->entry ); + while (len > 4) + { + if ((c0 = decode_char( p[0] )) > 63) return 0; + if ((c1 = decode_char( p[1] )) > 63) return 0; + if ((c2 = decode_char( p[2] )) > 63) return 0; + if ((c3 = decode_char( p[3] )) > 63) return 0; - if (!connection_collector_running) + if (buf) + { + buf[i + 0] = (c0 << 2) | (c1 >> 4); + buf[i + 1] = (c1 << 4) | (c2 >> 2); + buf[i + 2] = (c2 << 6) | c3; + } + len -= 4; + i += 3; + p += 4; + } + if (p[2] == '=') { - HMODULE module; - HANDLE thread; + if ((c0 = decode_char( p[0] )) > 63) return 0; + if ((c1 = decode_char( p[1] )) > 63) return 0; - GetModuleHandleExW( GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS, (const WCHAR*)winhttp_instance, &module ); + if (buf) buf[i] = (c0 << 2) | (c1 >> 4); + i++; + } + else if (p[3] == '=') + { + if ((c0 = decode_char( p[0] )) > 63) return 0; + if ((c1 = decode_char( p[1] )) > 63) return 0; + if ((c2 = decode_char( p[2] )) > 63) return 0; - thread = CreateThread(NULL, 0, connection_collector, NULL, 0, NULL); - if (thread) + if (buf) { - CloseHandle( thread ); - connection_collector_running = TRUE; + buf[i + 0] = (c0 << 2) | (c1 >> 4); + buf[i + 1] = (c1 << 4) | (c2 >> 2); } - else + i += 2; + } + else + { + if ((c0 = decode_char( p[0] )) > 63) return 0; + if ((c1 = decode_char( p[1] )) > 63) return 0; + if ((c2 = decode_char( p[2] )) > 63) return 0; + if ((c3 = decode_char( p[3] )) > 63) return 0; + + if (buf) { - FreeLibrary( winhttp_instance ); + buf[i + 0] = (c0 << 2) | (c1 >> 4); + buf[i + 1] = (c1 << 4) | (c2 >> 2); + buf[i + 2] = (c2 << 6) | c3; } + i += 3; } - - LeaveCriticalSection( &connection_pool_cs ); + return i; } -static BOOL open_connection( request_t *request ) +static struct authinfo *alloc_authinfo(void) { - BOOL is_secure = request->hdr.flags & WINHTTP_FLAG_SECURE; - hostdata_t *host = NULL, *iter; - netconn_t *netconn = NULL; - connect_t *connect; - WCHAR *addressW = NULL; - INTERNET_PORT port; - DWORD len; + struct authinfo *ret; - if (request->netconn) goto done; + if (!(ret = heap_alloc( sizeof(*ret) ))) return NULL; - connect = request->connect; - port = connect->serverport ? connect->serverport : (request->hdr.flags & WINHTTP_FLAG_SECURE ? 443 : 80); + SecInvalidateHandle( &ret->cred ); + SecInvalidateHandle( &ret->ctx ); + memset( &ret->exp, 0, sizeof(ret->exp) ); + ret->scheme = 0; + ret->attr = 0; + ret->max_token = 0; + ret->data = NULL; + ret->data_len = 0; + ret->finished = FALSE; + return ret; +} - EnterCriticalSection( &connection_pool_cs ); +void destroy_authinfo( struct authinfo *authinfo ) +{ + if (!authinfo) return; - LIST_FOR_EACH_ENTRY( iter, &connection_pool, hostdata_t, entry ) - { - if (iter->port == port && !strcmpW( connect->servername, iter->hostname ) && !is_secure == !iter->secure) - { - host = iter; - host->ref++; - break; - } - } + if (SecIsValidHandle( &authinfo->ctx )) + DeleteSecurityContext( &authinfo->ctx ); + if (SecIsValidHandle( &authinfo->cred )) + FreeCredentialsHandle( &authinfo->cred ); - if (!host) + heap_free( authinfo->data ); + heap_free( authinfo ); +} + +static BOOL get_authvalue( request_t *request, DWORD level, DWORD scheme, WCHAR *buffer, DWORD len ) +{ + DWORD size, index = 0; + for (;;) { - if ((host = heap_alloc( sizeof(*host) ))) - { - host->ref = 1; - host->secure = is_secure; - host->port = port; - list_init( &host->connections ); - if ((host->hostname = strdupW( connect->servername ))) - { - list_add_head( &connection_pool, &host->entry ); - } - else - { - heap_free( host ); - host = NULL; - } - } + size = len; + if (!query_headers( request, level, NULL, buffer, &size, &index )) return FALSE; + if (auth_scheme_from_header( buffer ) == scheme) break; } + return TRUE; +} - LeaveCriticalSection( &connection_pool_cs ); +static BOOL do_authorization( request_t *request, DWORD target, DWORD scheme_flag ) +{ + struct authinfo *authinfo, **auth_ptr; + enum auth_scheme scheme = scheme_from_flag( scheme_flag ); + const WCHAR *auth_target, *username, *password; + WCHAR auth_value[2048], *auth_reply; + DWORD len = sizeof(auth_value), len_scheme, flags; + BOOL ret, has_auth_value; - if (!host) return FALSE; + if (scheme == SCHEME_INVALID) return FALSE; - for (;;) + switch (target) { - EnterCriticalSection( &connection_pool_cs ); - if (!list_empty( &host->connections )) + case WINHTTP_AUTH_TARGET_SERVER: + has_auth_value = get_authvalue( request, WINHTTP_QUERY_WWW_AUTHENTICATE, scheme_flag, auth_value, len ); + auth_ptr = &request->authinfo; + auth_target = attr_authorization; + if (request->creds[TARGET_SERVER][scheme].username) { - netconn = LIST_ENTRY( list_head( &host->connections ), netconn_t, entry ); - list_remove( &netconn->entry ); + if (scheme != SCHEME_BASIC && !has_auth_value) return FALSE; + username = request->creds[TARGET_SERVER][scheme].username; + password = request->creds[TARGET_SERVER][scheme].password; } - LeaveCriticalSection( &connection_pool_cs ); - if (!netconn) break; + else + { + if (!has_auth_value) return FALSE; + username = request->connect->username; + password = request->connect->password; + } + break; - if (netconn_is_alive( netconn )) break; - TRACE("connection %p no longer alive, closing\n", netconn); - netconn_close( netconn ); - netconn = NULL; - } + case WINHTTP_AUTH_TARGET_PROXY: + if (!get_authvalue( request, WINHTTP_QUERY_PROXY_AUTHENTICATE, scheme_flag, auth_value, len )) + return FALSE; + auth_ptr = &request->proxy_authinfo; + auth_target = attr_proxy_authorization; + if (request->creds[TARGET_PROXY][scheme].username) + { + username = request->creds[TARGET_PROXY][scheme].username; + password = request->creds[TARGET_PROXY][scheme].password; + } + else + { + username = request->connect->session->proxy_username; + password = request->connect->session->proxy_password; + } + break; - if (!connect->resolved && netconn) - { - connect->sockaddr = netconn->sockaddr; - connect->resolved = TRUE; + default: + WARN("unknown target %x\n", target); + return FALSE; } + authinfo = *auth_ptr; - if (!connect->resolved) + switch (scheme) { - len = strlenW( host->hostname ) + 1; - send_callback( &request->hdr, WINHTTP_CALLBACK_STATUS_RESOLVING_NAME, host->hostname, len ); + case SCHEME_BASIC: + { + int userlen, passlen; - if (!netconn_resolve( host->hostname, port, &connect->sockaddr, request->resolve_timeout )) - { - release_host( host ); - return FALSE; - } - connect->resolved = TRUE; + if (!username || !password) return FALSE; + if ((!authinfo && !(authinfo = alloc_authinfo())) || authinfo->finished) return FALSE; - if (!(addressW = addr_to_str( &connect->sockaddr ))) - { - release_host( host ); - return FALSE; - } - len = strlenW( addressW ) + 1; - send_callback( &request->hdr, WINHTTP_CALLBACK_STATUS_NAME_RESOLVED, addressW, len ); - } + userlen = WideCharToMultiByte( CP_UTF8, 0, username, strlenW( username ), NULL, 0, NULL, NULL ); + passlen = WideCharToMultiByte( CP_UTF8, 0, password, strlenW( password ), NULL, 0, NULL, NULL ); - if (!netconn) + authinfo->data_len = userlen + 1 + passlen; + if (!(authinfo->data = heap_alloc( authinfo->data_len ))) return FALSE; + + WideCharToMultiByte( CP_UTF8, 0, username, -1, authinfo->data, userlen, NULL, NULL ); + authinfo->data[userlen] = ':'; + WideCharToMultiByte( CP_UTF8, 0, password, -1, authinfo->data + userlen + 1, passlen, NULL, NULL ); + + authinfo->scheme = SCHEME_BASIC; + authinfo->finished = TRUE; + break; + } + case SCHEME_NTLM: + case SCHEME_NEGOTIATE: { - if (!addressW && !(addressW = addr_to_str( &connect->sockaddr ))) + SECURITY_STATUS status; + SecBufferDesc out_desc, in_desc; + SecBuffer out, in; + ULONG flags = ISC_REQ_CONNECTION|ISC_REQ_USE_DCE_STYLE|ISC_REQ_MUTUAL_AUTH|ISC_REQ_DELEGATE; + const WCHAR *p; + BOOL first = FALSE; + + if (!authinfo) { - release_host( host ); - return FALSE; - } + TimeStamp exp; + SEC_WINNT_AUTH_IDENTITY_W id; + WCHAR *domain, *user; - TRACE("connecting to %s:%u\n", debugstr_w(addressW), port); + if (!username || !password || !(authinfo = alloc_authinfo())) return FALSE; - send_callback( &request->hdr, WINHTTP_CALLBACK_STATUS_CONNECTING_TO_SERVER, addressW, 0 ); + first = TRUE; + domain = (WCHAR *)username; + user = strchrW( username, '\\' ); - if (!(netconn = netconn_create( host, &connect->sockaddr, request->connect_timeout ))) - { - heap_free( addressW ); - release_host( host ); - return FALSE; - } - netconn_set_timeout( netconn, TRUE, request->send_timeout ); - netconn_set_timeout( netconn, FALSE, request->recv_timeout ); - if (is_secure) - { - if (connect->session->proxy_server && - strcmpiW( connect->hostname, connect->servername )) + if (user) user++; + else { - if (!secure_proxy_connect( request )) + user = (WCHAR *)username; + domain = NULL; + } + id.Flags = SEC_WINNT_AUTH_IDENTITY_UNICODE; + id.User = user; + id.UserLength = strlenW( user ); + id.Domain = domain; + id.DomainLength = domain ? user - domain - 1 : 0; + id.Password = (WCHAR *)password; + id.PasswordLength = strlenW( password ); + + status = AcquireCredentialsHandleW( NULL, (SEC_WCHAR *)auth_schemes[scheme].str, + SECPKG_CRED_OUTBOUND, NULL, &id, NULL, NULL, + &authinfo->cred, &exp ); + if (status == SEC_E_OK) + { + PSecPkgInfoW info; + status = QuerySecurityPackageInfoW( (SEC_WCHAR *)auth_schemes[scheme].str, &info ); + if (status == SEC_E_OK) { - heap_free( addressW ); - netconn_close( netconn ); - return FALSE; + authinfo->max_token = info->cbMaxToken; + FreeContextBuffer( info ); } } - if (!netconn_secure_connect( netconn, connect->hostname, request->security_flags )) + if (status != SEC_E_OK) { - heap_free( addressW ); - netconn_close( netconn ); + WARN("AcquireCredentialsHandleW for scheme %s failed with error 0x%08x\n", + debugstr_w(auth_schemes[scheme].str), status); + heap_free( authinfo ); return FALSE; } + authinfo->scheme = scheme; } + else if (authinfo->finished) return FALSE; - request->netconn = netconn; - send_callback( &request->hdr, WINHTTP_CALLBACK_STATUS_CONNECTED_TO_SERVER, addressW, strlenW(addressW) + 1 ); - } - else - { - TRACE("using connection %p\n", netconn); + if ((strlenW( auth_value ) < auth_schemes[authinfo->scheme].len || + strncmpiW( auth_value, auth_schemes[authinfo->scheme].str, auth_schemes[authinfo->scheme].len ))) + { + ERR("authentication scheme changed from %s to %s\n", + debugstr_w(auth_schemes[authinfo->scheme].str), debugstr_w(auth_value)); + destroy_authinfo( authinfo ); + *auth_ptr = NULL; + return FALSE; + } + in.BufferType = SECBUFFER_TOKEN; + in.cbBuffer = 0; + in.pvBuffer = NULL; - netconn_set_timeout( netconn, TRUE, request->send_timeout ); - netconn_set_timeout( netconn, FALSE, request->recv_timeout ); - request->netconn = netconn; + in_desc.ulVersion = 0; + in_desc.cBuffers = 1; + in_desc.pBuffers = ∈ + + p = auth_value + auth_schemes[scheme].len; + if (*p == ' ') + { + int len = strlenW( ++p ); + in.cbBuffer = decode_base64( p, len, NULL ); + if (!(in.pvBuffer = heap_alloc( in.cbBuffer ))) { + destroy_authinfo( authinfo ); + *auth_ptr = NULL; + return FALSE; + } + decode_base64( p, len, in.pvBuffer ); + } + out.BufferType = SECBUFFER_TOKEN; + out.cbBuffer = authinfo->max_token; + if (!(out.pvBuffer = heap_alloc( authinfo->max_token ))) + { + heap_free( in.pvBuffer ); + destroy_authinfo( authinfo ); + *auth_ptr = NULL; + return FALSE; + } + out_desc.ulVersion = 0; + out_desc.cBuffers = 1; + out_desc.pBuffers = &out; + + status = InitializeSecurityContextW( first ? &authinfo->cred : NULL, first ? NULL : &authinfo->ctx, + first ? request->connect->servername : NULL, flags, 0, + SECURITY_NETWORK_DREP, in.pvBuffer ? &in_desc : NULL, 0, + &authinfo->ctx, &out_desc, &authinfo->attr, &authinfo->exp ); + heap_free( in.pvBuffer ); + if (status == SEC_E_OK) + { + heap_free( authinfo->data ); + authinfo->data = out.pvBuffer; + authinfo->data_len = out.cbBuffer; + authinfo->finished = TRUE; + TRACE("sending last auth packet\n"); + } + else if (status == SEC_I_CONTINUE_NEEDED) + { + heap_free( authinfo->data ); + authinfo->data = out.pvBuffer; + authinfo->data_len = out.cbBuffer; + TRACE("sending next auth packet\n"); + } + else + { + ERR("InitializeSecurityContextW failed with error 0x%08x\n", status); + heap_free( out.pvBuffer ); + destroy_authinfo( authinfo ); + *auth_ptr = NULL; + return FALSE; + } + break; + } + default: + ERR("invalid scheme %u\n", scheme); + return FALSE; } + *auth_ptr = authinfo; -done: - request->read_pos = request->read_size = 0; - request->read_chunked = FALSE; - request->read_chunked_size = ~0u; - request->read_chunked_eof = FALSE; - heap_free( addressW ); - return TRUE; -} + len_scheme = auth_schemes[authinfo->scheme].len; + len = len_scheme + 1 + ((authinfo->data_len + 2) * 4) / 3; + if (!(auth_reply = heap_alloc( (len + 1) * sizeof(WCHAR) ))) return FALSE; -void close_connection( request_t *request ) -{ - if (!request->netconn) return; + memcpy( auth_reply, auth_schemes[authinfo->scheme].str, len_scheme * sizeof(WCHAR) ); + auth_reply[len_scheme] = ' '; + encode_base64( authinfo->data, authinfo->data_len, auth_reply + len_scheme + 1 ); - send_callback( &request->hdr, WINHTTP_CALLBACK_STATUS_CLOSING_CONNECTION, 0, 0 ); - netconn_close( request->netconn ); - request->netconn = NULL; - send_callback( &request->hdr, WINHTTP_CALLBACK_STATUS_CONNECTION_CLOSED, 0, 0 ); + flags = WINHTTP_ADDREQ_FLAG_ADD | WINHTTP_ADDREQ_FLAG_REPLACE; + ret = process_header( request, auth_target, auth_reply, flags, TRUE ); + heap_free( auth_reply ); + return ret; } -static BOOL add_host_header( request_t *request, DWORD modifier ) +static LPWSTR concatenate_string_list( LPCWSTR *list, int len ) { - BOOL ret; - DWORD len; - WCHAR *host; - static const WCHAR fmt[] = {'%','s',':','%','u',0}; - connect_t *connect = request->connect; - INTERNET_PORT port; + LPCWSTR *t; + LPWSTR str; - port = connect->hostport ? connect->hostport : (request->hdr.flags & WINHTTP_FLAG_SECURE ? 443 : 80); + for( t = list; *t ; t++ ) + len += strlenW( *t ); + len++; - if (port == INTERNET_DEFAULT_HTTP_PORT || port == INTERNET_DEFAULT_HTTPS_PORT) - { - return process_header( request, attr_host, connect->hostname, modifier, TRUE ); - } - len = strlenW( connect->hostname ) + 7; /* sizeof(":65335") */ - if (!(host = heap_alloc( len * sizeof(WCHAR) ))) return FALSE; - sprintfW( host, fmt, connect->hostname, port ); - ret = process_header( request, attr_host, host, modifier, TRUE ); - heap_free( host ); - return ret; -} + str = heap_alloc( len * sizeof(WCHAR) ); + if (!str) return NULL; + *str = 0; -static void clear_response_headers( request_t *request ) -{ - unsigned int i; + for( t = list; *t ; t++ ) + strcatW( str, *t ); - for (i = 0; i < request->num_headers; i++) - { - if (!request->headers[i].field) continue; - if (!request->headers[i].value) continue; - if (request->headers[i].is_request) continue; - delete_header( request, i ); - i--; - } + return str; } -/* remove some amount of data from the read buffer */ -static void remove_data( request_t *request, int count ) +static LPWSTR build_header_request_string( request_t *request, LPCWSTR verb, + LPCWSTR path, LPCWSTR version ) { - if (!(request->read_size -= count)) request->read_pos = 0; - else request->read_pos += count; -} + static const WCHAR crlf[] = {'\r','\n',0}; + static const WCHAR space[] = { ' ',0 }; + static const WCHAR colon[] = { ':',' ',0 }; + static const WCHAR twocrlf[] = {'\r','\n','\r','\n', 0}; + LPWSTR requestString; + DWORD len, n; + LPCWSTR *req; + UINT i; + LPWSTR p; -/* read some more data into the read buffer */ -static BOOL read_more_data( request_t *request, int maxlen, BOOL notify ) -{ - int len; - BOOL ret; + /* allocate space for an array of all the string pointers to be added */ + len = (request->num_headers) * 4 + 10; + req = heap_alloc( len * sizeof(LPCWSTR) ); + if (!req) return NULL; - if (request->read_chunked_eof) return FALSE; + /* add the verb, path and HTTP version string */ + n = 0; + req[n++] = verb; + req[n++] = space; + req[n++] = path; + req[n++] = space; + req[n++] = version; - if (request->read_size && request->read_pos) + /* Append custom request headers */ + for (i = 0; i < request->num_headers; i++) { - /* move existing data to the start of the buffer */ - memmove( request->read_buf, request->read_buf + request->read_pos, request->read_size ); - request->read_pos = 0; + if (request->headers[i].is_request) + { + req[n++] = crlf; + req[n++] = request->headers[i].field; + req[n++] = colon; + req[n++] = request->headers[i].value; + + TRACE("Adding custom header %s (%s)\n", + debugstr_w(request->headers[i].field), + debugstr_w(request->headers[i].value)); + } } - if (maxlen == -1) maxlen = sizeof(request->read_buf); - if (notify) send_callback( &request->hdr, WINHTTP_CALLBACK_STATUS_RECEIVING_RESPONSE, NULL, 0 ); + if( n >= len ) + ERR("oops. buffer overrun\n"); - ret = netconn_recv( request->netconn, request->read_buf + request->read_size, - maxlen - request->read_size, 0, &len ); + req[n] = NULL; + requestString = concatenate_string_list( req, 4 ); + heap_free( req ); + if (!requestString) return NULL; - if (notify) send_callback( &request->hdr, WINHTTP_CALLBACK_STATUS_RESPONSE_RECEIVED, &len, sizeof(len) ); + /* + * Set (header) termination string for request + * Make sure there are exactly two new lines at the end of the request + */ + p = &requestString[strlenW(requestString)-1]; + while ( (*p == '\n') || (*p == '\r') ) + p--; + strcpyW( p+1, twocrlf ); - request->read_size += len; - return ret; + return requestString; } -/* discard data contents until we reach end of line */ -static BOOL discard_eol( request_t *request, BOOL notify ) -{ - do - { - char *eol = memchr( request->read_buf + request->read_pos, '\n', request->read_size ); - if (eol) - { - remove_data( request, (eol + 1) - (request->read_buf + request->read_pos) ); - break; - } - request->read_pos = request->read_size = 0; /* discard everything */ - if (!read_more_data( request, -1, notify )) return FALSE; - } while (request->read_size); - return TRUE; -} +static BOOL read_reply( request_t *request ); -/* read the size of the next chunk */ -static BOOL start_next_chunk( request_t *request, BOOL notify ) +static BOOL secure_proxy_connect( request_t *request ) { - DWORD chunk_size = 0; - - assert(!request->read_chunked_size || request->read_chunked_size == ~0u); - - if (request->read_chunked_eof) return FALSE; - - /* read terminator for the previous chunk */ - if (!request->read_chunked_size && !discard_eol( request, notify )) return FALSE; + static const WCHAR verbConnect[] = {'C','O','N','N','E','C','T',0}; + static const WCHAR fmt[] = {'%','s',':','%','u',0}; + BOOL ret = FALSE; + LPWSTR path; + connect_t *connect = request->connect; - for (;;) + path = heap_alloc( (strlenW( connect->hostname ) + 13) * sizeof(WCHAR) ); + if (path) { - while (request->read_size) - { - char ch = request->read_buf[request->read_pos]; - if (ch >= '0' && ch <= '9') chunk_size = chunk_size * 16 + ch - '0'; - else if (ch >= 'a' && ch <= 'f') chunk_size = chunk_size * 16 + ch - 'a' + 10; - else if (ch >= 'A' && ch <= 'F') chunk_size = chunk_size * 16 + ch - 'A' + 10; - else if (ch == ';' || ch == '\r' || ch == '\n') - { - TRACE("reading %u byte chunk\n", chunk_size); + LPWSTR requestString; - if (request->content_length == ~0u) request->content_length = chunk_size; - else request->content_length += chunk_size; + sprintfW( path, fmt, connect->hostname, connect->hostport ); + requestString = build_header_request_string( request, verbConnect, + path, http1_1 ); + heap_free( path ); + if (requestString) + { + LPSTR req_ascii = strdupWA( requestString ); - request->read_chunked_size = chunk_size; - if (!chunk_size) request->read_chunked_eof = TRUE; + heap_free( requestString ); + if (req_ascii) + { + int len = strlen( req_ascii ), bytes_sent; - return discard_eol( request, notify ); + ret = netconn_send( request->netconn, req_ascii, len, &bytes_sent ); + heap_free( req_ascii ); + if (ret) + ret = read_reply( request ); } - remove_data( request, 1 ); - } - if (!read_more_data( request, -1, notify )) return FALSE; - if (!request->read_size) - { - request->content_length = request->content_read = 0; - request->read_chunked_size = 0; - return TRUE; } } + return ret; } -static BOOL refill_buffer( request_t *request, BOOL notify ) +#ifndef INET6_ADDRSTRLEN +#define INET6_ADDRSTRLEN 46 +#endif + +static WCHAR *addr_to_str( struct sockaddr_storage *addr ) { - int len = sizeof(request->read_buf); + char buf[INET6_ADDRSTRLEN]; + void *src; - if (request->read_chunked) - { - if (request->read_chunked_eof) return FALSE; - if (request->read_chunked_size == ~0u || !request->read_chunked_size) - { - if (!start_next_chunk( request, notify )) return FALSE; - } - len = min( len, request->read_chunked_size ); - } - else if (request->content_length != ~0u) + switch (addr->ss_family) { - len = min( len, request->content_length - request->content_read ); + case AF_INET: + src = &((struct sockaddr_in *)addr)->sin_addr; + break; + case AF_INET6: + src = &((struct sockaddr_in6 *)addr)->sin6_addr; + break; + default: + WARN("unsupported address family %d\n", addr->ss_family); + return NULL; } - - if (len <= request->read_size) return TRUE; - if (!read_more_data( request, len, notify )) return FALSE; - if (!request->read_size) request->content_length = request->content_read = 0; - return TRUE; + if (!inet_ntop( addr->ss_family, src, buf, sizeof(buf) )) return NULL; + return strdupAW( buf ); } -static void finished_reading( request_t *request ) +static CRITICAL_SECTION connection_pool_cs; +static CRITICAL_SECTION_DEBUG connection_pool_debug = { - static const WCHAR closeW[] = {'c','l','o','s','e',0}; + 0, 0, &connection_pool_cs, + { &connection_pool_debug.ProcessLocksList, &connection_pool_debug.ProcessLocksList }, + 0, 0, { (DWORD_PTR)(__FILE__ ": connection_pool_cs") } +}; +static CRITICAL_SECTION connection_pool_cs = { &connection_pool_debug, -1, 0, 0, 0, 0 }; - BOOL close = FALSE; - WCHAR connection[20]; - DWORD size = sizeof(connection); +static struct list connection_pool = LIST_INIT( connection_pool ); - if (!request->netconn) return; +void release_host( hostdata_t *host ) +{ + LONG ref; - if (request->hdr.disable_flags & WINHTTP_DISABLE_KEEP_ALIVE) close = TRUE; - else if (query_headers( request, WINHTTP_QUERY_CONNECTION, NULL, connection, &size, NULL ) || - query_headers( request, WINHTTP_QUERY_PROXY_CONNECTION, NULL, connection, &size, NULL )) - { - if (!strcmpiW( connection, closeW )) close = TRUE; - } - else if (!strcmpW( request->version, http1_0 )) close = TRUE; - if (close) - { - close_connection( request ); - return; - } + EnterCriticalSection( &connection_pool_cs ); + if (!(ref = --host->ref)) list_remove( &host->entry ); + LeaveCriticalSection( &connection_pool_cs ); + if (ref) return; - cache_connection( request->netconn ); - request->netconn = NULL; + assert( list_empty( &host->connections ) ); + heap_free( host->hostname ); + heap_free( host ); } -/* return the size of data available to be read immediately */ -static DWORD get_available_data( request_t *request ) -{ - if (request->read_chunked) return min( request->read_chunked_size, request->read_size ); - return request->read_size; -} +static BOOL connection_collector_running; -/* check if we have reached the end of the data to read */ -static BOOL end_of_read_data( request_t *request ) +static DWORD WINAPI connection_collector(void *arg) { - if (!request->content_length) return TRUE; - if (request->read_chunked) return request->read_chunked_eof; - if (request->content_length == ~0u) return FALSE; - return (request->content_length == request->content_read); -} + unsigned int remaining_connections; + netconn_t *netconn, *next_netconn; + hostdata_t *host, *next_host; + ULONGLONG now; -static BOOL read_data( request_t *request, void *buffer, DWORD size, DWORD *read, BOOL async ) -{ - int count, bytes_read = 0; + do + { + /* FIXME: Use more sophisticated method */ + Sleep(5000); + remaining_connections = 0; + now = GetTickCount64(); - if (end_of_read_data( request )) goto done; + EnterCriticalSection(&connection_pool_cs); - while (size) - { - if (!(count = get_available_data( request ))) + LIST_FOR_EACH_ENTRY_SAFE(host, next_host, &connection_pool, hostdata_t, entry) { - if (!refill_buffer( request, async )) goto done; - if (!(count = get_available_data( request ))) goto done; - } - count = min( count, size ); - memcpy( (char *)buffer + bytes_read, request->read_buf + request->read_pos, count ); - remove_data( request, count ); - if (request->read_chunked) request->read_chunked_size -= count; - size -= count; - bytes_read += count; - request->content_read += count; - if (end_of_read_data( request )) goto done; - } - if (request->read_chunked && !request->read_chunked_size) refill_buffer( request, async ); + LIST_FOR_EACH_ENTRY_SAFE(netconn, next_netconn, &host->connections, netconn_t, entry) + { + if (netconn->keep_until < now) + { + TRACE("freeing %p\n", netconn); + list_remove(&netconn->entry); + netconn_close(netconn); + } + else + { + remaining_connections++; + } + } + } -done: - TRACE( "retrieved %u bytes (%u/%u)\n", bytes_read, request->content_read, request->content_length ); + if (!remaining_connections) connection_collector_running = FALSE; - if (async) send_callback( &request->hdr, WINHTTP_CALLBACK_STATUS_READ_COMPLETE, buffer, bytes_read ); - if (read) *read = bytes_read; - if (end_of_read_data( request )) finished_reading( request ); - return TRUE; + LeaveCriticalSection(&connection_pool_cs); + } while(remaining_connections); + + FreeLibraryAndExitThread( winhttp_instance, 0 ); } -/* read any content returned by the server so that the connection can be reused */ -static void drain_content( request_t *request ) +static void cache_connection( netconn_t *netconn ) { - DWORD size, bytes_read, bytes_total = 0, bytes_left = request->content_length - request->content_read; - char buffer[2048]; + TRACE( "caching connection %p\n", netconn ); - refill_buffer( request, FALSE ); - for (;;) + EnterCriticalSection( &connection_pool_cs ); + + netconn->keep_until = GetTickCount64() + DEFAULT_KEEP_ALIVE_TIMEOUT; + list_add_head( &netconn->host->connections, &netconn->entry ); + + if (!connection_collector_running) { - if (request->read_chunked) size = sizeof(buffer); + HMODULE module; + HANDLE thread; + + GetModuleHandleExW( GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS, (const WCHAR*)winhttp_instance, &module ); + + thread = CreateThread(NULL, 0, connection_collector, NULL, 0, NULL); + if (thread) + { + CloseHandle( thread ); + connection_collector_running = TRUE; + } else { - if (bytes_total >= bytes_left) return; - size = min( sizeof(buffer), bytes_left - bytes_total ); + FreeLibrary( winhttp_instance ); } - if (!read_data( request, buffer, size, &bytes_read, FALSE ) || !bytes_read) return; - bytes_total += bytes_read; } + + LeaveCriticalSection( &connection_pool_cs ); } -static BOOL send_request( request_t *request, LPCWSTR headers, DWORD headers_len, LPVOID optional, - DWORD optional_len, DWORD total_len, DWORD_PTR context, BOOL async ) +static DWORD map_secure_protocols( DWORD mask ) { - static const WCHAR keep_alive[] = {'K','e','e','p','-','A','l','i','v','e',0}; - static const WCHAR no_cache[] = {'n','o','-','c','a','c','h','e',0}; - static const WCHAR length_fmt[] = {'%','l','d',0}; - - BOOL ret = FALSE; - connect_t *connect = request->connect; - session_t *session = connect->session; - WCHAR *req = NULL; - char *req_ascii; - int bytes_sent; - DWORD len; - - clear_response_headers( request ); - drain_content( request ); + DWORD ret = 0; + if (mask & WINHTTP_FLAG_SECURE_PROTOCOL_SSL2) ret |= SP_PROT_SSL2_CLIENT; + if (mask & WINHTTP_FLAG_SECURE_PROTOCOL_SSL3) ret |= SP_PROT_SSL3_CLIENT; + if (mask & WINHTTP_FLAG_SECURE_PROTOCOL_TLS1) ret |= SP_PROT_TLS1_CLIENT; + if (mask & WINHTTP_FLAG_SECURE_PROTOCOL_TLS1_1) ret |= SP_PROT_TLS1_1_CLIENT; + if (mask & WINHTTP_FLAG_SECURE_PROTOCOL_TLS1_2) ret |= SP_PROT_TLS1_2_CLIENT; + return ret; +} - if (session->agent) - process_header( request, attr_user_agent, session->agent, WINHTTP_ADDREQ_FLAG_ADD_IF_NEW, TRUE ); +static BOOL ensure_cred_handle( session_t *session ) +{ + SCHANNEL_CRED cred; + SECURITY_STATUS status; - if (connect->hostname) - add_host_header( request, WINHTTP_ADDREQ_FLAG_ADD_IF_NEW ); + if (session->cred_handle_initialized) return TRUE; - if (total_len || (request->verb && !strcmpW( request->verb, postW ))) - { - WCHAR length[21]; /* decimal long int + null */ - sprintfW( length, length_fmt, total_len ); - process_header( request, attr_content_length, length, WINHTTP_ADDREQ_FLAG_ADD_IF_NEW, TRUE ); - } - if (!(request->hdr.disable_flags & WINHTTP_DISABLE_KEEP_ALIVE)) - { - process_header( request, attr_connection, keep_alive, WINHTTP_ADDREQ_FLAG_ADD_IF_NEW, TRUE ); - } - if (request->hdr.flags & WINHTTP_FLAG_REFRESH) - { - process_header( request, attr_pragma, no_cache, WINHTTP_ADDREQ_FLAG_ADD_IF_NEW, TRUE ); - process_header( request, attr_cache_control, no_cache, WINHTTP_ADDREQ_FLAG_ADD_IF_NEW, TRUE ); - } - if (headers && !add_request_headers( request, headers, headers_len, WINHTTP_ADDREQ_FLAG_ADD | WINHTTP_ADDREQ_FLAG_REPLACE )) + memset( &cred, 0, sizeof(cred) ); + cred.dwVersion = SCHANNEL_CRED_VERSION; + cred.grbitEnabledProtocols = map_secure_protocols( session->secure_protocols ); + if ((status = AcquireCredentialsHandleW( NULL, (WCHAR *)UNISP_NAME_W, SECPKG_CRED_OUTBOUND, NULL, &cred, + NULL, NULL, &session->cred_handle, NULL )) != SEC_E_OK) { - TRACE("failed to add request headers\n"); - return FALSE; - } - if (!(request->hdr.disable_flags & WINHTTP_DISABLE_COOKIES) && !add_cookie_headers( request )) - { - WARN("failed to add cookie headers\n"); + WARN( "AcquireCredentialsHandleW failed: 0x%08x\n", status ); return FALSE; } + session->cred_handle_initialized = TRUE; + return TRUE; +} - if (context) request->hdr.context = context; - - if (!(ret = open_connection( request ))) goto end; - if (!(req = build_request_string( request ))) goto end; +static BOOL open_connection( request_t *request ) +{ + BOOL is_secure = request->hdr.flags & WINHTTP_FLAG_SECURE; + hostdata_t *host = NULL, *iter; + netconn_t *netconn = NULL; + connect_t *connect; + WCHAR *addressW = NULL; + INTERNET_PORT port; + DWORD len; - if (!(req_ascii = strdupWA( req ))) goto end; - TRACE("full request: %s\n", debugstr_a(req_ascii)); - len = strlen(req_ascii); + if (request->netconn) goto done; - send_callback( &request->hdr, WINHTTP_CALLBACK_STATUS_SENDING_REQUEST, NULL, 0 ); + connect = request->connect; + port = connect->serverport ? connect->serverport : (request->hdr.flags & WINHTTP_FLAG_SECURE ? 443 : 80); - ret = netconn_send( request->netconn, req_ascii, len, &bytes_sent ); - heap_free( req_ascii ); - if (!ret) goto end; + EnterCriticalSection( &connection_pool_cs ); - if (optional_len) + LIST_FOR_EACH_ENTRY( iter, &connection_pool, hostdata_t, entry ) { - if (!netconn_send( request->netconn, optional, optional_len, &bytes_sent )) goto end; - request->optional = optional; - request->optional_len = optional_len; - len += optional_len; + if (iter->port == port && !strcmpW( connect->servername, iter->hostname ) && !is_secure == !iter->secure) + { + host = iter; + host->ref++; + break; + } } - send_callback( &request->hdr, WINHTTP_CALLBACK_STATUS_REQUEST_SENT, &len, sizeof(len) ); -end: - if (async) + if (!host) { - if (ret) send_callback( &request->hdr, WINHTTP_CALLBACK_STATUS_SENDREQUEST_COMPLETE, NULL, 0 ); - else + if ((host = heap_alloc( sizeof(*host) ))) { - WINHTTP_ASYNC_RESULT result; - result.dwResult = API_SEND_REQUEST; - result.dwError = get_last_error(); - send_callback( &request->hdr, WINHTTP_CALLBACK_STATUS_REQUEST_ERROR, &result, sizeof(result) ); + host->ref = 1; + host->secure = is_secure; + host->port = port; + list_init( &host->connections ); + if ((host->hostname = strdupW( connect->servername ))) + { + list_add_head( &connection_pool, &host->entry ); + } + else + { + heap_free( host ); + host = NULL; + } } } - heap_free( req ); - return ret; -} - -static void task_send_request( task_header_t *task ) -{ - send_request_t *s = (send_request_t *)task; - send_request( s->hdr.request, s->headers, s->headers_len, s->optional, s->optional_len, s->total_len, s->context, TRUE ); - heap_free( s->headers ); -} -/*********************************************************************** - * WinHttpSendRequest (winhttp.@) - */ -BOOL WINAPI WinHttpSendRequest( HINTERNET hrequest, LPCWSTR headers, DWORD headers_len, - LPVOID optional, DWORD optional_len, DWORD total_len, DWORD_PTR context ) -{ - BOOL ret; - request_t *request; + LeaveCriticalSection( &connection_pool_cs ); - TRACE("%p, %s, 0x%x, %u, %u, %lx\n", - hrequest, debugstr_w(headers), headers_len, optional_len, total_len, context); + if (!host) return FALSE; - if (!(request = (request_t *)grab_object( hrequest ))) + for (;;) { - set_last_error( ERROR_INVALID_HANDLE ); - return FALSE; + EnterCriticalSection( &connection_pool_cs ); + if (!list_empty( &host->connections )) + { + netconn = LIST_ENTRY( list_head( &host->connections ), netconn_t, entry ); + list_remove( &netconn->entry ); + } + LeaveCriticalSection( &connection_pool_cs ); + if (!netconn) break; + + if (netconn_is_alive( netconn )) break; + TRACE("connection %p no longer alive, closing\n", netconn); + netconn_close( netconn ); + netconn = NULL; } - if (request->hdr.type != WINHTTP_HANDLE_TYPE_REQUEST) + + if (!connect->resolved && netconn) { - release_object( &request->hdr ); - set_last_error( ERROR_WINHTTP_INCORRECT_HANDLE_TYPE ); - return FALSE; + connect->sockaddr = netconn->sockaddr; + connect->resolved = TRUE; } - if (headers && !headers_len) headers_len = strlenW( headers ); - - if (request->connect->hdr.flags & WINHTTP_FLAG_ASYNC) + if (!connect->resolved) { - send_request_t *s; + len = strlenW( host->hostname ) + 1; + send_callback( &request->hdr, WINHTTP_CALLBACK_STATUS_RESOLVING_NAME, host->hostname, len ); - if (!(s = heap_alloc( sizeof(send_request_t) ))) return FALSE; - s->hdr.request = request; - s->hdr.proc = task_send_request; - s->headers = strdupW( headers ); - s->headers_len = headers_len; - s->optional = optional; - s->optional_len = optional_len; - s->total_len = total_len; - s->context = context; + if (!netconn_resolve( host->hostname, port, &connect->sockaddr, request->resolve_timeout )) + { + release_host( host ); + return FALSE; + } + connect->resolved = TRUE; - addref_object( &request->hdr ); - ret = queue_task( (task_header_t *)s ); + if (!(addressW = addr_to_str( &connect->sockaddr ))) + { + release_host( host ); + return FALSE; + } + len = strlenW( addressW ) + 1; + send_callback( &request->hdr, WINHTTP_CALLBACK_STATUS_NAME_RESOLVED, addressW, len ); } - else - ret = send_request( request, headers, headers_len, optional, optional_len, total_len, context, FALSE ); - - release_object( &request->hdr ); - if (ret) set_last_error( ERROR_SUCCESS ); - return ret; -} -#undef ARRAYSIZE -#define ARRAYSIZE(array) (sizeof(array) / sizeof((array)[0])) + if (!netconn) + { + if (!addressW && !(addressW = addr_to_str( &connect->sockaddr ))) + { + release_host( host ); + return FALSE; + } -static const WCHAR basicW[] = {'B','a','s','i','c',0}; -static const WCHAR ntlmW[] = {'N','T','L','M',0}; -static const WCHAR passportW[] = {'P','a','s','s','p','o','r','t',0}; -static const WCHAR digestW[] = {'D','i','g','e','s','t',0}; -static const WCHAR negotiateW[] = {'N','e','g','o','t','i','a','t','e',0}; + TRACE("connecting to %s:%u\n", debugstr_w(addressW), port); -static const struct -{ - const WCHAR *str; - unsigned int len; - DWORD scheme; + send_callback( &request->hdr, WINHTTP_CALLBACK_STATUS_CONNECTING_TO_SERVER, addressW, 0 ); + + if (!(netconn = netconn_create( host, &connect->sockaddr, request->connect_timeout ))) + { + heap_free( addressW ); + release_host( host ); + return FALSE; + } + netconn_set_timeout( netconn, TRUE, request->send_timeout ); + netconn_set_timeout( netconn, FALSE, request->recv_timeout ); + if (is_secure) + { + if (connect->session->proxy_server && + strcmpiW( connect->hostname, connect->servername )) + { + if (!secure_proxy_connect( request )) + { + heap_free( addressW ); + netconn_close( netconn ); + return FALSE; + } + } + if (!ensure_cred_handle( connect->session ) || + !netconn_secure_connect( netconn, connect->hostname, request->security_flags, + &connect->session->cred_handle )) + { + heap_free( addressW ); + netconn_close( netconn ); + return FALSE; + } + } + + request->netconn = netconn; + send_callback( &request->hdr, WINHTTP_CALLBACK_STATUS_CONNECTED_TO_SERVER, addressW, strlenW(addressW) + 1 ); + } + else + { + TRACE("using connection %p\n", netconn); + + netconn_set_timeout( netconn, TRUE, request->send_timeout ); + netconn_set_timeout( netconn, FALSE, request->recv_timeout ); + request->netconn = netconn; + } + +done: + request->read_pos = request->read_size = 0; + request->read_chunked = FALSE; + request->read_chunked_size = ~0u; + request->read_chunked_eof = FALSE; + heap_free( addressW ); + return TRUE; } -auth_schemes[] = -{ - { basicW, ARRAYSIZE(basicW) - 1, WINHTTP_AUTH_SCHEME_BASIC }, - { ntlmW, ARRAYSIZE(ntlmW) - 1, WINHTTP_AUTH_SCHEME_NTLM }, - { passportW, ARRAYSIZE(passportW) - 1, WINHTTP_AUTH_SCHEME_PASSPORT }, - { digestW, ARRAYSIZE(digestW) - 1, WINHTTP_AUTH_SCHEME_DIGEST }, - { negotiateW, ARRAYSIZE(negotiateW) - 1, WINHTTP_AUTH_SCHEME_NEGOTIATE } -}; -static const unsigned int num_auth_schemes = sizeof(auth_schemes)/sizeof(auth_schemes[0]); -static enum auth_scheme scheme_from_flag( DWORD flag ) +void close_connection( request_t *request ) { - int i; + if (!request->netconn) return; - for (i = 0; i < num_auth_schemes; i++) if (flag == auth_schemes[i].scheme) return i; - return SCHEME_INVALID; + send_callback( &request->hdr, WINHTTP_CALLBACK_STATUS_CLOSING_CONNECTION, 0, 0 ); + netconn_close( request->netconn ); + request->netconn = NULL; + send_callback( &request->hdr, WINHTTP_CALLBACK_STATUS_CONNECTION_CLOSED, 0, 0 ); } -static DWORD auth_scheme_from_header( WCHAR *header ) +static BOOL add_host_header( request_t *request, DWORD modifier ) { - unsigned int i; + BOOL ret; + DWORD len; + WCHAR *host; + static const WCHAR fmt[] = {'%','s',':','%','u',0}; + connect_t *connect = request->connect; + INTERNET_PORT port; - for (i = 0; i < num_auth_schemes; i++) + port = connect->hostport ? connect->hostport : (request->hdr.flags & WINHTTP_FLAG_SECURE ? 443 : 80); + + if (port == INTERNET_DEFAULT_HTTP_PORT || port == INTERNET_DEFAULT_HTTPS_PORT) { - if (!strncmpiW( header, auth_schemes[i].str, auth_schemes[i].len ) && - (header[auth_schemes[i].len] == ' ' || !header[auth_schemes[i].len])) return auth_schemes[i].scheme; + return process_header( request, attr_host, connect->hostname, modifier, TRUE ); } - return 0; + len = strlenW( connect->hostname ) + 7; /* sizeof(":65335") */ + if (!(host = heap_alloc( len * sizeof(WCHAR) ))) return FALSE; + sprintfW( host, fmt, connect->hostname, port ); + ret = process_header( request, attr_host, host, modifier, TRUE ); + heap_free( host ); + return ret; } -static BOOL query_auth_schemes( request_t *request, DWORD level, LPDWORD supported, LPDWORD first ) +static void clear_response_headers( request_t *request ) { - DWORD index = 0, supported_schemes = 0, first_scheme = 0; - BOOL ret = FALSE; + unsigned int i; - for (;;) + for (i = 0; i < request->num_headers; i++) { - WCHAR *buffer; - DWORD size, scheme; - - size = 0; - query_headers( request, level, NULL, NULL, &size, &index ); - if (get_last_error() != ERROR_INSUFFICIENT_BUFFER) break; - - index--; - if (!(buffer = heap_alloc( size ))) return FALSE; - if (!query_headers( request, level, NULL, buffer, &size, &index )) - { - heap_free( buffer ); - return FALSE; - } - scheme = auth_scheme_from_header( buffer ); - heap_free( buffer ); - if (!scheme) continue; - - if (!first_scheme) first_scheme = scheme; - supported_schemes |= scheme; - - ret = TRUE; + if (!request->headers[i].field) continue; + if (!request->headers[i].value) continue; + if (request->headers[i].is_request) continue; + delete_header( request, i ); + i--; } +} - if (ret) - { - *supported = supported_schemes; - *first = first_scheme; - } - return ret; +/* remove some amount of data from the read buffer */ +static void remove_data( request_t *request, int count ) +{ + if (!(request->read_size -= count)) request->read_pos = 0; + else request->read_pos += count; } -/*********************************************************************** - * WinHttpQueryAuthSchemes (winhttp.@) - */ -BOOL WINAPI WinHttpQueryAuthSchemes( HINTERNET hrequest, LPDWORD supported, LPDWORD first, LPDWORD target ) +/* read some more data into the read buffer */ +static BOOL read_more_data( request_t *request, int maxlen, BOOL notify ) { - BOOL ret = FALSE; - request_t *request; + int len; + BOOL ret; - TRACE("%p, %p, %p, %p\n", hrequest, supported, first, target); + if (request->read_chunked_eof) return FALSE; - if (!(request = (request_t *)grab_object( hrequest ))) - { - set_last_error( ERROR_INVALID_HANDLE ); - return FALSE; - } - if (request->hdr.type != WINHTTP_HANDLE_TYPE_REQUEST) + if (request->read_size && request->read_pos) { - release_object( &request->hdr ); - set_last_error( ERROR_WINHTTP_INCORRECT_HANDLE_TYPE ); - return FALSE; + /* move existing data to the start of the buffer */ + memmove( request->read_buf, request->read_buf + request->read_pos, request->read_size ); + request->read_pos = 0; } - if (!supported || !first || !target) - { - release_object( &request->hdr ); - set_last_error( ERROR_INVALID_PARAMETER ); - return FALSE; + if (maxlen == -1) maxlen = sizeof(request->read_buf); - } + if (notify) send_callback( &request->hdr, WINHTTP_CALLBACK_STATUS_RECEIVING_RESPONSE, NULL, 0 ); - if (query_auth_schemes( request, WINHTTP_QUERY_WWW_AUTHENTICATE, supported, first )) - { - *target = WINHTTP_AUTH_TARGET_SERVER; - ret = TRUE; - } - else if (query_auth_schemes( request, WINHTTP_QUERY_PROXY_AUTHENTICATE, supported, first )) - { - *target = WINHTTP_AUTH_TARGET_PROXY; - ret = TRUE; - } + ret = netconn_recv( request->netconn, request->read_buf + request->read_size, + maxlen - request->read_size, 0, &len ); - release_object( &request->hdr ); - if (ret) set_last_error( ERROR_SUCCESS ); + if (notify) send_callback( &request->hdr, WINHTTP_CALLBACK_STATUS_RESPONSE_RECEIVED, &len, sizeof(len) ); + + request->read_size += len; return ret; } -static UINT encode_base64( const char *bin, unsigned int len, WCHAR *base64 ) +/* discard data contents until we reach end of line */ +static BOOL discard_eol( request_t *request, BOOL notify ) { - UINT n = 0, x; - static const char base64enc[] = - "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"; - - while (len > 0) + do { - /* first 6 bits, all from bin[0] */ - base64[n++] = base64enc[(bin[0] & 0xfc) >> 2]; - x = (bin[0] & 3) << 4; - - /* next 6 bits, 2 from bin[0] and 4 from bin[1] */ - if (len == 1) - { - base64[n++] = base64enc[x]; - base64[n++] = '='; - base64[n++] = '='; - break; - } - base64[n++] = base64enc[x | ((bin[1] & 0xf0) >> 4)]; - x = (bin[1] & 0x0f) << 2; - - /* next 6 bits 4 from bin[1] and 2 from bin[2] */ - if (len == 2) + char *eol = memchr( request->read_buf + request->read_pos, '\n', request->read_size ); + if (eol) { - base64[n++] = base64enc[x]; - base64[n++] = '='; + remove_data( request, (eol + 1) - (request->read_buf + request->read_pos) ); break; } - base64[n++] = base64enc[x | ((bin[2] & 0xc0) >> 6)]; - - /* last 6 bits, all from bin [2] */ - base64[n++] = base64enc[bin[2] & 0x3f]; - bin += 3; - len -= 3; - } - base64[n] = 0; - return n; + request->read_pos = request->read_size = 0; /* discard everything */ + if (!read_more_data( request, -1, notify )) return FALSE; + } while (request->read_size); + return TRUE; } -static inline char decode_char( WCHAR c ) +/* read the size of the next chunk */ +static BOOL start_next_chunk( request_t *request, BOOL notify ) { - if (c >= 'A' && c <= 'Z') return c - 'A'; - if (c >= 'a' && c <= 'z') return c - 'a' + 26; - if (c >= '0' && c <= '9') return c - '0' + 52; - if (c == '+') return 62; - if (c == '/') return 63; - return 64; -} + DWORD chunk_size = 0; -static unsigned int decode_base64( const WCHAR *base64, unsigned int len, char *buf ) -{ - unsigned int i = 0; - char c0, c1, c2, c3; - const WCHAR *p = base64; + assert(!request->read_chunked_size || request->read_chunked_size == ~0u); - while (len > 4) + if (request->read_chunked_eof) return FALSE; + + /* read terminator for the previous chunk */ + if (!request->read_chunked_size && !discard_eol( request, notify )) return FALSE; + + for (;;) { - if ((c0 = decode_char( p[0] )) > 63) return 0; - if ((c1 = decode_char( p[1] )) > 63) return 0; - if ((c2 = decode_char( p[2] )) > 63) return 0; - if ((c3 = decode_char( p[3] )) > 63) return 0; + while (request->read_size) + { + char ch = request->read_buf[request->read_pos]; + if (ch >= '0' && ch <= '9') chunk_size = chunk_size * 16 + ch - '0'; + else if (ch >= 'a' && ch <= 'f') chunk_size = chunk_size * 16 + ch - 'a' + 10; + else if (ch >= 'A' && ch <= 'F') chunk_size = chunk_size * 16 + ch - 'A' + 10; + else if (ch == ';' || ch == '\r' || ch == '\n') + { + TRACE("reading %u byte chunk\n", chunk_size); - if (buf) + if (request->content_length == ~0u) request->content_length = chunk_size; + else request->content_length += chunk_size; + + request->read_chunked_size = chunk_size; + if (!chunk_size) request->read_chunked_eof = TRUE; + + return discard_eol( request, notify ); + } + remove_data( request, 1 ); + } + if (!read_more_data( request, -1, notify )) return FALSE; + if (!request->read_size) { - buf[i + 0] = (c0 << 2) | (c1 >> 4); - buf[i + 1] = (c1 << 4) | (c2 >> 2); - buf[i + 2] = (c2 << 6) | c3; + request->content_length = request->content_read = 0; + request->read_chunked_size = 0; + return TRUE; } - len -= 4; - i += 3; - p += 4; } - if (p[2] == '=') - { - if ((c0 = decode_char( p[0] )) > 63) return 0; - if ((c1 = decode_char( p[1] )) > 63) return 0; +} - if (buf) buf[i] = (c0 << 2) | (c1 >> 4); - i++; - } - else if (p[3] == '=') - { - if ((c0 = decode_char( p[0] )) > 63) return 0; - if ((c1 = decode_char( p[1] )) > 63) return 0; - if ((c2 = decode_char( p[2] )) > 63) return 0; +static BOOL refill_buffer( request_t *request, BOOL notify ) +{ + int len = sizeof(request->read_buf); - if (buf) + if (request->read_chunked) + { + if (request->read_chunked_eof) return FALSE; + if (request->read_chunked_size == ~0u || !request->read_chunked_size) { - buf[i + 0] = (c0 << 2) | (c1 >> 4); - buf[i + 1] = (c1 << 4) | (c2 >> 2); + if (!start_next_chunk( request, notify )) return FALSE; } - i += 2; + len = min( len, request->read_chunked_size ); } - else + else if (request->content_length != ~0u) { - if ((c0 = decode_char( p[0] )) > 63) return 0; - if ((c1 = decode_char( p[1] )) > 63) return 0; - if ((c2 = decode_char( p[2] )) > 63) return 0; - if ((c3 = decode_char( p[3] )) > 63) return 0; - - if (buf) - { - buf[i + 0] = (c0 << 2) | (c1 >> 4); - buf[i + 1] = (c1 << 4) | (c2 >> 2); - buf[i + 2] = (c2 << 6) | c3; - } - i += 3; + len = min( len, request->content_length - request->content_read ); } - return i; + + if (len <= request->read_size) return TRUE; + if (!read_more_data( request, len, notify )) return FALSE; + if (!request->read_size) request->content_length = request->content_read = 0; + return TRUE; } -static struct authinfo *alloc_authinfo(void) +static void finished_reading( request_t *request ) { - struct authinfo *ret; + static const WCHAR closeW[] = {'c','l','o','s','e',0}; - if (!(ret = heap_alloc( sizeof(*ret) ))) return NULL; + BOOL close = FALSE; + WCHAR connection[20]; + DWORD size = sizeof(connection); - SecInvalidateHandle( &ret->cred ); - SecInvalidateHandle( &ret->ctx ); - memset( &ret->exp, 0, sizeof(ret->exp) ); - ret->scheme = 0; - ret->attr = 0; - ret->max_token = 0; - ret->data = NULL; - ret->data_len = 0; - ret->finished = FALSE; - return ret; -} + if (!request->netconn) return; -void destroy_authinfo( struct authinfo *authinfo ) -{ - if (!authinfo) return; + if (request->hdr.disable_flags & WINHTTP_DISABLE_KEEP_ALIVE) close = TRUE; + else if (query_headers( request, WINHTTP_QUERY_CONNECTION, NULL, connection, &size, NULL ) || + query_headers( request, WINHTTP_QUERY_PROXY_CONNECTION, NULL, connection, &size, NULL )) + { + if (!strcmpiW( connection, closeW )) close = TRUE; + } + else if (!strcmpW( request->version, http1_0 )) close = TRUE; + if (close) + { + close_connection( request ); + return; + } - if (SecIsValidHandle( &authinfo->ctx )) - DeleteSecurityContext( &authinfo->ctx ); - if (SecIsValidHandle( &authinfo->cred )) - FreeCredentialsHandle( &authinfo->cred ); + cache_connection( request->netconn ); + request->netconn = NULL; +} - heap_free( authinfo->data ); - heap_free( authinfo ); +/* return the size of data available to be read immediately */ +static DWORD get_available_data( request_t *request ) +{ + if (request->read_chunked) return min( request->read_chunked_size, request->read_size ); + return request->read_size; } -static BOOL get_authvalue( request_t *request, DWORD level, DWORD scheme, WCHAR *buffer, DWORD len ) +/* check if we have reached the end of the data to read */ +static BOOL end_of_read_data( request_t *request ) { - DWORD size, index = 0; - for (;;) - { - size = len; - if (!query_headers( request, level, NULL, buffer, &size, &index )) return FALSE; - if (auth_scheme_from_header( buffer ) == scheme) break; - } - return TRUE; + if (!request->content_length) return TRUE; + if (request->read_chunked) return request->read_chunked_eof; + if (request->content_length == ~0u) return FALSE; + return (request->content_length == request->content_read); } -static BOOL do_authorization( request_t *request, DWORD target, DWORD scheme_flag ) +static BOOL read_data( request_t *request, void *buffer, DWORD size, DWORD *read, BOOL async ) { - struct authinfo *authinfo, **auth_ptr; - enum auth_scheme scheme = scheme_from_flag( scheme_flag ); - const WCHAR *auth_target, *username, *password; - WCHAR auth_value[2048], *auth_reply; - DWORD len = sizeof(auth_value), len_scheme, flags; - BOOL ret; + int count, bytes_read = 0; - if (scheme == SCHEME_INVALID) return FALSE; + if (end_of_read_data( request )) goto done; - switch (target) + while (size) { - case WINHTTP_AUTH_TARGET_SERVER: - if (!get_authvalue( request, WINHTTP_QUERY_WWW_AUTHENTICATE, scheme_flag, auth_value, len )) - return FALSE; - auth_ptr = &request->authinfo; - auth_target = attr_authorization; - if (request->creds[TARGET_SERVER][scheme].username) - { - username = request->creds[TARGET_SERVER][scheme].username; - password = request->creds[TARGET_SERVER][scheme].password; - } - else + if (!(count = get_available_data( request ))) { - username = request->connect->username; - password = request->connect->password; + if (!refill_buffer( request, async )) goto done; + if (!(count = get_available_data( request ))) goto done; } - break; + count = min( count, size ); + memcpy( (char *)buffer + bytes_read, request->read_buf + request->read_pos, count ); + remove_data( request, count ); + if (request->read_chunked) request->read_chunked_size -= count; + size -= count; + bytes_read += count; + request->content_read += count; + if (end_of_read_data( request )) goto done; + } + if (request->read_chunked && !request->read_chunked_size) refill_buffer( request, async ); - case WINHTTP_AUTH_TARGET_PROXY: - if (!get_authvalue( request, WINHTTP_QUERY_PROXY_AUTHENTICATE, scheme_flag, auth_value, len )) - return FALSE; - auth_ptr = &request->proxy_authinfo; - auth_target = attr_proxy_authorization; - if (request->creds[TARGET_PROXY][scheme].username) - { - username = request->creds[TARGET_PROXY][scheme].username; - password = request->creds[TARGET_PROXY][scheme].password; - } +done: + TRACE( "retrieved %u bytes (%u/%u)\n", bytes_read, request->content_read, request->content_length ); + + if (async) send_callback( &request->hdr, WINHTTP_CALLBACK_STATUS_READ_COMPLETE, buffer, bytes_read ); + if (read) *read = bytes_read; + if (end_of_read_data( request )) finished_reading( request ); + return TRUE; +} + +/* read any content returned by the server so that the connection can be reused */ +static void drain_content( request_t *request ) +{ + DWORD size, bytes_read, bytes_total = 0, bytes_left = request->content_length - request->content_read; + char buffer[2048]; + + refill_buffer( request, FALSE ); + for (;;) + { + if (request->read_chunked) size = sizeof(buffer); else { - username = request->connect->session->proxy_username; - password = request->connect->session->proxy_password; + if (bytes_total >= bytes_left) return; + size = min( sizeof(buffer), bytes_left - bytes_total ); } - break; - - default: - WARN("unknown target %x\n", target); - return FALSE; + if (!read_data( request, buffer, size, &bytes_read, FALSE ) || !bytes_read) return; + bytes_total += bytes_read; } - authinfo = *auth_ptr; +} - switch (scheme) - { - case SCHEME_BASIC: - { - int userlen, passlen; +static BOOL send_request( request_t *request, LPCWSTR headers, DWORD headers_len, LPVOID optional, + DWORD optional_len, DWORD total_len, DWORD_PTR context, BOOL async ) +{ + static const WCHAR keep_alive[] = {'K','e','e','p','-','A','l','i','v','e',0}; + static const WCHAR no_cache[] = {'n','o','-','c','a','c','h','e',0}; + static const WCHAR length_fmt[] = {'%','l','d',0}; - if (!username || !password) return FALSE; - if ((!authinfo && !(authinfo = alloc_authinfo())) || authinfo->finished) return FALSE; + BOOL ret = FALSE; + connect_t *connect = request->connect; + session_t *session = connect->session; + WCHAR *req = NULL; + char *req_ascii; + int bytes_sent; + DWORD len, i, flags; - userlen = WideCharToMultiByte( CP_UTF8, 0, username, strlenW( username ), NULL, 0, NULL, NULL ); - passlen = WideCharToMultiByte( CP_UTF8, 0, password, strlenW( password ), NULL, 0, NULL, NULL ); + clear_response_headers( request ); + drain_content( request ); - authinfo->data_len = userlen + 1 + passlen; - if (!(authinfo->data = heap_alloc( authinfo->data_len ))) return FALSE; + flags = WINHTTP_ADDREQ_FLAG_ADD|WINHTTP_ADDREQ_FLAG_COALESCE_WITH_COMMA; + for (i = 0; i < request->num_accept_types; i++) + { + process_header( request, attr_accept, request->accept_types[i], flags, TRUE ); + } + if (session->agent) + process_header( request, attr_user_agent, session->agent, WINHTTP_ADDREQ_FLAG_ADD_IF_NEW, TRUE ); - WideCharToMultiByte( CP_UTF8, 0, username, -1, authinfo->data, userlen, NULL, NULL ); - authinfo->data[userlen] = ':'; - WideCharToMultiByte( CP_UTF8, 0, password, -1, authinfo->data + userlen + 1, passlen, NULL, NULL ); + if (connect->hostname) + add_host_header( request, WINHTTP_ADDREQ_FLAG_ADD_IF_NEW ); - authinfo->scheme = SCHEME_BASIC; - authinfo->finished = TRUE; - break; + if (request->creds[TARGET_SERVER][SCHEME_BASIC].username) + do_authorization( request, WINHTTP_AUTH_TARGET_SERVER, WINHTTP_AUTH_SCHEME_BASIC ); + + if (total_len || (request->verb && !strcmpW( request->verb, postW ))) + { + WCHAR length[21]; /* decimal long int + null */ + sprintfW( length, length_fmt, total_len ); + process_header( request, attr_content_length, length, WINHTTP_ADDREQ_FLAG_ADD_IF_NEW, TRUE ); } - case SCHEME_NTLM: - case SCHEME_NEGOTIATE: + if (!(request->hdr.disable_flags & WINHTTP_DISABLE_KEEP_ALIVE)) { - SECURITY_STATUS status; - SecBufferDesc out_desc, in_desc; - SecBuffer out, in; - ULONG flags = ISC_REQ_CONNECTION|ISC_REQ_USE_DCE_STYLE|ISC_REQ_MUTUAL_AUTH|ISC_REQ_DELEGATE; - const WCHAR *p; - BOOL first = FALSE; + process_header( request, attr_connection, keep_alive, WINHTTP_ADDREQ_FLAG_ADD_IF_NEW, TRUE ); + } + if (request->hdr.flags & WINHTTP_FLAG_REFRESH) + { + process_header( request, attr_pragma, no_cache, WINHTTP_ADDREQ_FLAG_ADD_IF_NEW, TRUE ); + process_header( request, attr_cache_control, no_cache, WINHTTP_ADDREQ_FLAG_ADD_IF_NEW, TRUE ); + } + if (headers && !add_request_headers( request, headers, headers_len, WINHTTP_ADDREQ_FLAG_ADD | WINHTTP_ADDREQ_FLAG_REPLACE )) + { + TRACE("failed to add request headers\n"); + return FALSE; + } + if (!(request->hdr.disable_flags & WINHTTP_DISABLE_COOKIES) && !add_cookie_headers( request )) + { + WARN("failed to add cookie headers\n"); + return FALSE; + } - if (!authinfo) - { - TimeStamp exp; - SEC_WINNT_AUTH_IDENTITY_W id; - WCHAR *domain, *user; + if (context) request->hdr.context = context; - if (!username || !password || !(authinfo = alloc_authinfo())) return FALSE; + if (!(ret = open_connection( request ))) goto end; + if (!(req = build_request_string( request ))) goto end; - first = TRUE; - domain = (WCHAR *)username; - user = strchrW( username, '\\' ); + if (!(req_ascii = strdupWA( req ))) goto end; + TRACE("full request: %s\n", debugstr_a(req_ascii)); + len = strlen(req_ascii); - if (user) user++; - else - { - user = (WCHAR *)username; - domain = NULL; - } - id.Flags = SEC_WINNT_AUTH_IDENTITY_UNICODE; - id.User = user; - id.UserLength = strlenW( user ); - id.Domain = domain; - id.DomainLength = domain ? user - domain - 1 : 0; - id.Password = (WCHAR *)password; - id.PasswordLength = strlenW( password ); + send_callback( &request->hdr, WINHTTP_CALLBACK_STATUS_SENDING_REQUEST, NULL, 0 ); - status = AcquireCredentialsHandleW( NULL, (SEC_WCHAR *)auth_schemes[scheme].str, - SECPKG_CRED_OUTBOUND, NULL, &id, NULL, NULL, - &authinfo->cred, &exp ); - if (status == SEC_E_OK) - { - PSecPkgInfoW info; - status = QuerySecurityPackageInfoW( (SEC_WCHAR *)auth_schemes[scheme].str, &info ); - if (status == SEC_E_OK) - { - authinfo->max_token = info->cbMaxToken; - FreeContextBuffer( info ); - } - } - if (status != SEC_E_OK) - { - WARN("AcquireCredentialsHandleW for scheme %s failed with error 0x%08x\n", - debugstr_w(auth_schemes[scheme].str), status); - heap_free( authinfo ); - return FALSE; - } - authinfo->scheme = scheme; - } - else if (authinfo->finished) return FALSE; + ret = netconn_send( request->netconn, req_ascii, len, &bytes_sent ); + heap_free( req_ascii ); + if (!ret) goto end; - if ((strlenW( auth_value ) < auth_schemes[authinfo->scheme].len || - strncmpiW( auth_value, auth_schemes[authinfo->scheme].str, auth_schemes[authinfo->scheme].len ))) + if (optional_len) + { + if (!netconn_send( request->netconn, optional, optional_len, &bytes_sent )) goto end; + request->optional = optional; + request->optional_len = optional_len; + len += optional_len; + } + send_callback( &request->hdr, WINHTTP_CALLBACK_STATUS_REQUEST_SENT, &len, sizeof(len) ); + +end: + if (async) + { + if (ret) send_callback( &request->hdr, WINHTTP_CALLBACK_STATUS_SENDREQUEST_COMPLETE, NULL, 0 ); + else { - ERR("authentication scheme changed from %s to %s\n", - debugstr_w(auth_schemes[authinfo->scheme].str), debugstr_w(auth_value)); - destroy_authinfo( authinfo ); - *auth_ptr = NULL; - return FALSE; + WINHTTP_ASYNC_RESULT result; + result.dwResult = API_SEND_REQUEST; + result.dwError = get_last_error(); + send_callback( &request->hdr, WINHTTP_CALLBACK_STATUS_REQUEST_ERROR, &result, sizeof(result) ); } - in.BufferType = SECBUFFER_TOKEN; - in.cbBuffer = 0; - in.pvBuffer = NULL; + } + heap_free( req ); + return ret; +} - in_desc.ulVersion = 0; - in_desc.cBuffers = 1; - in_desc.pBuffers = ∈ +static void task_send_request( task_header_t *task ) +{ + send_request_t *s = (send_request_t *)task; + send_request( s->hdr.request, s->headers, s->headers_len, s->optional, s->optional_len, s->total_len, s->context, TRUE ); + heap_free( s->headers ); +} - p = auth_value + auth_schemes[scheme].len; - if (*p == ' ') - { - int len = strlenW( ++p ); - in.cbBuffer = decode_base64( p, len, NULL ); - if (!(in.pvBuffer = heap_alloc( in.cbBuffer ))) { - destroy_authinfo( authinfo ); - *auth_ptr = NULL; - return FALSE; - } - decode_base64( p, len, in.pvBuffer ); - } - out.BufferType = SECBUFFER_TOKEN; - out.cbBuffer = authinfo->max_token; - if (!(out.pvBuffer = heap_alloc( authinfo->max_token ))) - { - heap_free( in.pvBuffer ); - destroy_authinfo( authinfo ); - *auth_ptr = NULL; - return FALSE; - } - out_desc.ulVersion = 0; - out_desc.cBuffers = 1; - out_desc.pBuffers = &out; +/*********************************************************************** + * WinHttpSendRequest (winhttp.@) + */ +BOOL WINAPI WinHttpSendRequest( HINTERNET hrequest, LPCWSTR headers, DWORD headers_len, + LPVOID optional, DWORD optional_len, DWORD total_len, DWORD_PTR context ) +{ + BOOL ret; + request_t *request; - status = InitializeSecurityContextW( first ? &authinfo->cred : NULL, first ? NULL : &authinfo->ctx, - first ? request->connect->servername : NULL, flags, 0, - SECURITY_NETWORK_DREP, in.pvBuffer ? &in_desc : NULL, 0, - &authinfo->ctx, &out_desc, &authinfo->attr, &authinfo->exp ); - heap_free( in.pvBuffer ); - if (status == SEC_E_OK) - { - heap_free( authinfo->data ); - authinfo->data = out.pvBuffer; - authinfo->data_len = out.cbBuffer; - authinfo->finished = TRUE; - TRACE("sending last auth packet\n"); - } - else if (status == SEC_I_CONTINUE_NEEDED) - { - heap_free( authinfo->data ); - authinfo->data = out.pvBuffer; - authinfo->data_len = out.cbBuffer; - TRACE("sending next auth packet\n"); - } - else - { - ERR("InitializeSecurityContextW failed with error 0x%08x\n", status); - heap_free( out.pvBuffer ); - destroy_authinfo( authinfo ); - *auth_ptr = NULL; - return FALSE; - } - break; + TRACE("%p, %s, %u, %u, %u, %lx\n", hrequest, debugstr_wn(headers, headers_len), headers_len, optional_len, + total_len, context); + + if (!(request = (request_t *)grab_object( hrequest ))) + { + set_last_error( ERROR_INVALID_HANDLE ); + return FALSE; } - default: - ERR("invalid scheme %u\n", scheme); + if (request->hdr.type != WINHTTP_HANDLE_TYPE_REQUEST) + { + release_object( &request->hdr ); + set_last_error( ERROR_WINHTTP_INCORRECT_HANDLE_TYPE ); return FALSE; } - *auth_ptr = authinfo; - len_scheme = auth_schemes[authinfo->scheme].len; - len = len_scheme + 1 + ((authinfo->data_len + 2) * 4) / 3; - if (!(auth_reply = heap_alloc( (len + 1) * sizeof(WCHAR) ))) return FALSE; + if (headers && !headers_len) headers_len = strlenW( headers ); - memcpy( auth_reply, auth_schemes[authinfo->scheme].str, len_scheme * sizeof(WCHAR) ); - auth_reply[len_scheme] = ' '; - encode_base64( authinfo->data, authinfo->data_len, auth_reply + len_scheme + 1 ); + if (request->connect->hdr.flags & WINHTTP_FLAG_ASYNC) + { + send_request_t *s; - flags = WINHTTP_ADDREQ_FLAG_ADD | WINHTTP_ADDREQ_FLAG_REPLACE; - ret = process_header( request, auth_target, auth_reply, flags, TRUE ); - heap_free( auth_reply ); + if (!(s = heap_alloc( sizeof(send_request_t) ))) return FALSE; + s->hdr.request = request; + s->hdr.proc = task_send_request; + s->headers = strdupW( headers ); + s->headers_len = headers_len; + s->optional = optional; + s->optional_len = optional_len; + s->total_len = total_len; + s->context = context; + + addref_object( &request->hdr ); + ret = queue_task( (task_header_t *)s ); + } + else + ret = send_request( request, headers, headers_len, optional, optional_len, total_len, context, FALSE ); + + release_object( &request->hdr ); + if (ret) set_last_error( ERROR_SUCCESS ); return ret; } diff --git a/dll/win32/winhttp/session.c b/dll/win32/winhttp/session.c index 429f505914..7ab10a66e4 100644 --- a/dll/win32/winhttp/session.c +++ b/dll/win32/winhttp/session.c @@ -71,6 +71,7 @@ static void session_destroy( object_header_t *hdr ) TRACE("%p\n", session); if (session->unload_event) SetEvent( session->unload_event ); + if (session->cred_handle_initialized) FreeCredentialsHandle( &session->cred_handle ); LIST_FOR_EACH_SAFE( item, next, &session->cookie_cache ) { @@ -155,6 +156,17 @@ static BOOL session_set_option( object_header_t *hdr, DWORD option, LPVOID buffe hdr->redirect_policy = policy; return TRUE; } + case WINHTTP_OPTION_SECURE_PROTOCOLS: + { + if (buflen != sizeof(session->secure_protocols)) + { + set_last_error( ERROR_INSUFFICIENT_BUFFER ); + return FALSE; + } + session->secure_protocols = *(DWORD *)buffer; + TRACE("0x%x\n", session->secure_protocols); + return TRUE; + } case WINHTTP_OPTION_DISABLE_FEATURE: set_last_error( ERROR_WINHTTP_INCORRECT_HANDLE_TYPE ); return FALSE; @@ -577,6 +589,8 @@ static void request_destroy( object_header_t *hdr ) heap_free( request->headers[i].value ); } heap_free( request->headers ); + for (i = 0; i < request->num_accept_types; i++) heap_free( request->accept_types[i] ); + heap_free( request->accept_types ); for (i = 0; i < TARGET_MAX; i++) { for (j = 0; j < SCHEME_MAX; j++) @@ -1002,14 +1016,32 @@ static const object_vtbl_t request_vtbl = static BOOL store_accept_types( request_t *request, const WCHAR **accept_types ) { - static const WCHAR attr_accept[] = {'A','c','c','e','p','t',0}; - static const DWORD flags = WINHTTP_ADDREQ_FLAG_ADD | WINHTTP_ADDREQ_FLAG_COALESCE_WITH_COMMA; const WCHAR **types = accept_types; + DWORD i; if (!types) return TRUE; while (*types) { - process_header( request, attr_accept, *types, flags, TRUE ); + request->num_accept_types++; + types++; + } + if (!request->num_accept_types) return TRUE; + if (!(request->accept_types = heap_alloc( request->num_accept_types * sizeof(WCHAR *)))) + { + request->num_accept_types = 0; + return FALSE; + } + types = accept_types; + for (i = 0; i < request->num_accept_types; i++) + { + if (!(request->accept_types[i] = strdupW( *types ))) + { + for ( ; i > 0; --i) heap_free( request->accept_types[i - 1] ); + heap_free( request->accept_types ); + request->accept_types = NULL; + request->num_accept_types = 0; + return FALSE; + } types++; } return TRUE; diff --git a/dll/win32/winhttp/winhttp_private.h b/dll/win32/winhttp/winhttp_private.h index 7e80dcab4e..1e6d16a238 100644 --- a/dll/win32/winhttp/winhttp_private.h +++ b/dll/win32/winhttp/winhttp_private.h @@ -135,6 +135,9 @@ typedef struct LPWSTR proxy_password; struct list cookie_cache; HANDLE unload_event; + CredHandle cred_handle; + BOOL cred_handle_initialized; + DWORD secure_protocols; } session_t; typedef struct @@ -235,6 +238,8 @@ typedef struct char read_buf[8192]; /* buffer for already read but not returned data */ header_t *headers; DWORD num_headers; + WCHAR **accept_types; + DWORD num_accept_types; struct authinfo *authinfo; struct authinfo *proxy_authinfo; HANDLE task_wait; @@ -313,7 +318,7 @@ void netconn_unload( void ) DECLSPEC_HIDDEN; ULONG netconn_query_data_available( netconn_t * ) DECLSPEC_HIDDEN; BOOL netconn_recv( netconn_t *, void *, size_t, int, int * ) DECLSPEC_HIDDEN; BOOL netconn_resolve( WCHAR *, INTERNET_PORT, struct sockaddr_storage *, int ) DECLSPEC_HIDDEN; -BOOL netconn_secure_connect( netconn_t *, WCHAR *, DWORD ) DECLSPEC_HIDDEN; +BOOL netconn_secure_connect( netconn_t *, WCHAR *, DWORD, CredHandle * ) DECLSPEC_HIDDEN; BOOL netconn_send( netconn_t *, const void *, size_t, int * ) DECLSPEC_HIDDEN; DWORD netconn_set_timeout( netconn_t *, BOOL, int ) DECLSPEC_HIDDEN; BOOL netconn_is_alive( netconn_t * ) DECLSPEC_HIDDEN; @@ -329,8 +334,6 @@ void destroy_authinfo( struct authinfo * ) DECLSPEC_HIDDEN; void release_host( hostdata_t *host ) DECLSPEC_HIDDEN; -BOOL process_header( request_t *request, LPCWSTR field, LPCWSTR value, DWORD flags, BOOL request_only ) DECLSPEC_HIDDEN; - extern HRESULT WinHttpRequest_create( void ** ) DECLSPEC_HIDDEN; void release_typelib( void ) DECLSPEC_HIDDEN; diff --git a/media/doc/README.WINE b/media/doc/README.WINE index 6905a44db6..5f30683e42 100644 --- a/media/doc/README.WINE +++ b/media/doc/README.WINE @@ -200,7 +200,7 @@ reactos/dll/win32/windowscodecs # Synced to Wine-3.0 reactos/dll/win32/windowscodecsext # Synced to WineStaging-2.9 reactos/dll/win32/winemp3.acm # Synced to Wine-3.0 reactos/dll/win32/wing32 # Synced to WineStaging-2.9 -reactos/dll/win32/winhttp # Synced to WineStaging-2.16 +reactos/dll/win32/winhttp # Synced to Wine-3.0 reactos/dll/win32/wininet # Synced to WineStaging-2.16 reactos/dll/win32/winmm # Forked at Wine-20050628 reactos/dll/win32/winmm/midimap # Forked at Wine-20050628
1
0
0
0
01/01: [PSDK] Update winhttp.h. CORE-14225
by Amine Khaldi
20 Jan '18
20 Jan '18
https://git.reactos.org/?p=reactos.git;a=commitdiff;h=4f825146c250485a02161…
commit 4f825146c250485a0216189a5657cf15eadf22ed Author: Amine Khaldi <amine.khaldi(a)reactos.org> AuthorDate: Sat Jan 20 13:54:50 2018 +0100 Commit: Amine Khaldi <amine.khaldi(a)reactos.org> CommitDate: Sat Jan 20 13:54:50 2018 +0100 [PSDK] Update winhttp.h. CORE-14225 --- sdk/include/psdk/winhttp.h | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/sdk/include/psdk/winhttp.h b/sdk/include/psdk/winhttp.h index 45be58a18e..3ef05ea0bd 100644 --- a/sdk/include/psdk/winhttp.h +++ b/sdk/include/psdk/winhttp.h @@ -440,10 +440,14 @@ typedef int INTERNET_SCHEME, *LPINTERNET_SCHEME; #define WINHTTP_CALLBACK_STATUS_FLAG_CERT_WRONG_USAGE 0x00000040 #define WINHTTP_CALLBACK_STATUS_FLAG_SECURITY_CHANNEL_ERROR 0x80000000 -#define WINHTTP_FLAG_SECURE_PROTOCOL_SSL2 0x00000008 -#define WINHTTP_FLAG_SECURE_PROTOCOL_SSL3 0x00000020 -#define WINHTTP_FLAG_SECURE_PROTOCOL_TLS1 0x00000080 -#define WINHTTP_FLAG_SECURE_PROTOCOL_ALL (WINHTTP_FLAG_SECURE_PROTOCOL_SSL2 | WINHTTP_FLAG_SECURE_PROTOCOL_SSL3 | WINHTTP_FLAG_SECURE_PROTOCOL_TLS1) +#define WINHTTP_FLAG_SECURE_PROTOCOL_SSL2 0x00000008 +#define WINHTTP_FLAG_SECURE_PROTOCOL_SSL3 0x00000020 +#define WINHTTP_FLAG_SECURE_PROTOCOL_TLS1 0x00000080 +#define WINHTTP_FLAG_SECURE_PROTOCOL_TLS1_1 0x00000200 +#define WINHTTP_FLAG_SECURE_PROTOCOL_TLS1_2 0x00000800 +#define WINHTTP_FLAG_SECURE_PROTOCOL_ALL (WINHTTP_FLAG_SECURE_PROTOCOL_SSL2 |\ + WINHTTP_FLAG_SECURE_PROTOCOL_SSL3 |\ + WINHTTP_FLAG_SECURE_PROTOCOL_TLS1) #define WINHTTP_AUTH_SCHEME_BASIC 0x00000001 #define WINHTTP_AUTH_SCHEME_NTLM 0x00000002
1
0
0
0
01/01: [WINEMP3.ACM] Sync with Wine 3.0. CORE-14225
by Amine Khaldi
20 Jan '18
20 Jan '18
https://git.reactos.org/?p=reactos.git;a=commitdiff;h=c8f158b700fb67cc12262…
commit c8f158b700fb67cc12262ecbf8a1a79f0765cb48 Author: Amine Khaldi <amine.khaldi(a)reactos.org> AuthorDate: Sat Jan 20 13:52:52 2018 +0100 Commit: Amine Khaldi <amine.khaldi(a)reactos.org> CommitDate: Sat Jan 20 13:52:52 2018 +0100 [WINEMP3.ACM] Sync with Wine 3.0. CORE-14225 --- dll/win32/winemp3.acm/mpegl3.c | 95 ++++++++---------------------------------- media/doc/README.WINE | 2 +- 2 files changed, 19 insertions(+), 78 deletions(-) diff --git a/dll/win32/winemp3.acm/mpegl3.c b/dll/win32/winemp3.acm/mpegl3.c index 9c875dca25..15acdeaad5 100644 --- a/dll/win32/winemp3.acm/mpegl3.c +++ b/dll/win32/winemp3.acm/mpegl3.c @@ -215,7 +215,6 @@ static void MPEG3_Reset(PACMDRVSTREAMINSTANCE adsi, AcmMpeg3Data* aad) */ static LRESULT MPEG3_StreamOpen(PACMDRVSTREAMINSTANCE adsi) { - LRESULT error = MMSYSERR_NOTSUPPORTED; AcmMpeg3Data* aad; int err; @@ -239,18 +238,6 @@ static LRESULT MPEG3_StreamOpen(PACMDRVSTREAMINSTANCE adsi) adsi->pwfxSrc->wFormatTag == WAVE_FORMAT_MPEG) && adsi->pwfxDst->wFormatTag == WAVE_FORMAT_PCM) { - if (adsi->pwfxSrc->wFormatTag == WAVE_FORMAT_MPEGLAYER3) - { - MPEGLAYER3WAVEFORMAT *formatmp3 = (MPEGLAYER3WAVEFORMAT *)adsi->pwfxSrc; - - if (adsi->pwfxSrc->cbSize < MPEGLAYER3_WFX_EXTRA_BYTES || - formatmp3->wID != MPEGLAYER3_ID_MPEG) - { - error = ACMERR_NOTPOSSIBLE; - goto theEnd; - } - } - /* resampling or mono <=> stereo not available * MPEG3 algo only define 16 bit per sample output */ @@ -271,10 +258,13 @@ static LRESULT MPEG3_StreamOpen(PACMDRVSTREAMINSTANCE adsi) mpg123_param(aad->mh, MPG123_ADD_FLAGS, MPG123_IGNORE_INFOFRAME, 0); #endif } - /* no encoding yet else if (adsi->pwfxSrc->wFormatTag == WAVE_FORMAT_PCM && - adsi->pwfxDst->wFormatTag == WAVE_FORMAT_MPEGLAYER3) - */ + (adsi->pwfxDst->wFormatTag == WAVE_FORMAT_MPEGLAYER3 || + adsi->pwfxDst->wFormatTag == WAVE_FORMAT_MPEG)) + { + WARN("Encoding to MPEG is not supported\n"); + goto theEnd; + } else goto theEnd; MPEG3_Reset(adsi, aad); @@ -283,7 +273,7 @@ static LRESULT MPEG3_StreamOpen(PACMDRVSTREAMINSTANCE adsi) theEnd: HeapFree(GetProcessHeap(), 0, aad); adsi->dwDriver = 0L; - return error; + return MMSYSERR_NOTSUPPORTED; } /*********************************************************************** @@ -749,54 +739,19 @@ static LRESULT MPEG3_FormatTagDetails(PACMFORMATTAGDETAILSW aftd, DWORD dwQuery) case 1: aftd->dwFormatTag = WAVE_FORMAT_MPEGLAYER3; aftd->cbFormatSize = sizeof(MPEGLAYER3WAVEFORMAT); - aftd->cStandardFormats = NUM_MPEG3_FORMATS; + aftd->cStandardFormats = 0; lstrcpyW(aftd->szFormatTag, szMpeg3); break; case 2: aftd->dwFormatTag = WAVE_FORMAT_MPEG; aftd->cbFormatSize = sizeof(MPEG1WAVEFORMAT); - aftd->cStandardFormats = NUM_MPEG3_FORMATS; + aftd->cStandardFormats = 0; lstrcpyW(aftd->szFormatTag, szMpeg); break; } return MMSYSERR_NOERROR; } -static void fill_in_mp3(unsigned cbwfx, WAVEFORMATEX* wfx, unsigned bit_rate) -{ - MPEGLAYER3WAVEFORMAT* mp3wfx = (MPEGLAYER3WAVEFORMAT*)wfx; - - wfx->nAvgBytesPerSec = bit_rate / 8; - if (cbwfx >= sizeof(WAVEFORMATEX)) - wfx->cbSize = sizeof(MPEGLAYER3WAVEFORMAT) - sizeof(WAVEFORMATEX); - if (cbwfx >= sizeof(MPEGLAYER3WAVEFORMAT)) - { - mp3wfx->wID = MPEGLAYER3_ID_MPEG; - mp3wfx->fdwFlags = MPEGLAYER3_FLAG_PADDING_OFF; - mp3wfx->nBlockSize = (bit_rate * 144) / wfx->nSamplesPerSec; - mp3wfx->nFramesPerBlock = 1; - mp3wfx->nCodecDelay = 0x0571; - } -} - -static void fill_in_mpeg(unsigned cbwfx, WAVEFORMATEX* wfx, unsigned bit_rate) -{ - MPEG1WAVEFORMAT* mp3wfx = (MPEG1WAVEFORMAT*)wfx; - - wfx->nAvgBytesPerSec = bit_rate / 8; - if (cbwfx >= sizeof(WAVEFORMATEX)) - wfx->cbSize = sizeof(MPEG1WAVEFORMAT) - sizeof(WAVEFORMATEX); - if (cbwfx >= sizeof(MPEG1WAVEFORMAT)) - { - mp3wfx->fwHeadLayer = ACM_MPEG_LAYER3; - mp3wfx->dwHeadBitrate = wfx->nAvgBytesPerSec * 8; - mp3wfx->fwHeadMode = ACM_MPEG_JOINTSTEREO; - mp3wfx->fwHeadModeExt = 0xf; - mp3wfx->wHeadEmphasis = 1; - mp3wfx->fwHeadFlags = ACM_MPEG_ID_MPEG1; - } -} - /*********************************************************************** * MPEG3_FormatDetails * @@ -827,16 +782,8 @@ static LRESULT MPEG3_FormatDetails(PACMFORMATDETAILSW afd, DWORD dwQuery) break; case WAVE_FORMAT_MPEGLAYER3: case WAVE_FORMAT_MPEG: - if (afd->dwFormatIndex >= NUM_MPEG3_FORMATS) return ACMERR_NOTPOSSIBLE; - afd->pwfx->nChannels = MPEG3_Formats[afd->dwFormatIndex].nChannels; - afd->pwfx->nSamplesPerSec = MPEG3_Formats[afd->dwFormatIndex].rate; - afd->pwfx->wBitsPerSample = MPEG3_Formats[afd->dwFormatIndex].nBits; - afd->pwfx->nBlockAlign = 1; - if (afd->dwFormatTag == WAVE_FORMAT_MPEGLAYER3) - fill_in_mp3(afd->cbwfx, afd->pwfx, 192000); - else - fill_in_mpeg(afd->cbwfx, afd->pwfx, 192000); - break; + WARN("Encoding to MPEG is not supported\n"); + return ACMERR_NOTPOSSIBLE; default: WARN("Unsupported tag %08x\n", afd->dwFormatTag); return MMSYSERR_INVALPARAM; @@ -869,18 +816,15 @@ static LRESULT MPEG3_FormatSuggest(PACMDRVFORMATSUGGEST adfs) adfs->pwfxDst->nChannels = adfs->pwfxSrc->nChannels; if (!(adfs->fdwSuggest & ACM_FORMATSUGGESTF_NSAMPLESPERSEC)) adfs->pwfxDst->nSamplesPerSec = adfs->pwfxSrc->nSamplesPerSec; - if (!(adfs->fdwSuggest & ACM_FORMATSUGGESTF_WBITSPERSAMPLE)) - { - if (adfs->pwfxSrc->wFormatTag == WAVE_FORMAT_PCM) - adfs->pwfxDst->wBitsPerSample = 4; - else - adfs->pwfxDst->wBitsPerSample = 16; - } + adfs->pwfxDst->wBitsPerSample = 16; if (!(adfs->fdwSuggest & ACM_FORMATSUGGESTF_WFORMATTAG)) { if (adfs->pwfxSrc->wFormatTag == WAVE_FORMAT_PCM) - adfs->pwfxDst->wFormatTag = WAVE_FORMAT_MPEGLAYER3; + { + WARN("Encoding to MPEG is not supported\n"); + return ACMERR_NOTPOSSIBLE; + } else adfs->pwfxDst->wFormatTag = WAVE_FORMAT_PCM; } @@ -896,12 +840,9 @@ static LRESULT MPEG3_FormatSuggest(PACMDRVFORMATSUGGEST adfs) adfs->pwfxDst->nAvgBytesPerSec = adfs->pwfxDst->nSamplesPerSec * adfs->pwfxDst->nBlockAlign; break; case WAVE_FORMAT_MPEG: - adfs->pwfxDst->nBlockAlign = 1; - fill_in_mpeg(adfs->cbwfxDst, adfs->pwfxDst, 192000); - break; case WAVE_FORMAT_MPEGLAYER3: - adfs->pwfxDst->nBlockAlign = 1; - fill_in_mp3(adfs->cbwfxDst, adfs->pwfxDst, 192000); + WARN("Encoding to MPEG is not supported\n"); + return ACMERR_NOTPOSSIBLE; break; default: FIXME("\n"); diff --git a/media/doc/README.WINE b/media/doc/README.WINE index d1c733260d..6905a44db6 100644 --- a/media/doc/README.WINE +++ b/media/doc/README.WINE @@ -198,7 +198,7 @@ reactos/dll/win32/wbemdisp # Synced to Wine-3.0 reactos/dll/win32/wbemprox # Synced to Wine-3.0 reactos/dll/win32/windowscodecs # Synced to Wine-3.0 reactos/dll/win32/windowscodecsext # Synced to WineStaging-2.9 -reactos/dll/win32/winemp3.acm # Synced to WineStaging-2.16 +reactos/dll/win32/winemp3.acm # Synced to Wine-3.0 reactos/dll/win32/wing32 # Synced to WineStaging-2.9 reactos/dll/win32/winhttp # Synced to WineStaging-2.16 reactos/dll/win32/wininet # Synced to WineStaging-2.16
1
0
0
0
01/01: [WINDOWSCODECS_WINETEST] Sync with Wine 3.0. CORE-14225
by Amine Khaldi
20 Jan '18
20 Jan '18
https://git.reactos.org/?p=reactos.git;a=commitdiff;h=a5cb9a0a8df9630613474…
commit a5cb9a0a8df9630613474b539dfe163945d71843 Author: Amine Khaldi <amine.khaldi(a)reactos.org> AuthorDate: Sat Jan 20 13:51:37 2018 +0100 Commit: Amine Khaldi <amine.khaldi(a)reactos.org> CommitDate: Sat Jan 20 13:51:37 2018 +0100 [WINDOWSCODECS_WINETEST] Sync with Wine 3.0. CORE-14225 --- .../rostests/winetests/windowscodecs/converter.c | 809 ++------------------- modules/rostests/winetests/windowscodecs/palette.c | 139 +--- .../rostests/winetests/windowscodecs/pngformat.c | 14 +- .../rostests/winetests/windowscodecs/tiffformat.c | 614 +--------------- 4 files changed, 111 insertions(+), 1465 deletions(-) diff --git a/modules/rostests/winetests/windowscodecs/converter.c b/modules/rostests/winetests/windowscodecs/converter.c index baa7a9d3c4..2a44ef50b0 100644 --- a/modules/rostests/winetests/windowscodecs/converter.c +++ b/modules/rostests/winetests/windowscodecs/converter.c @@ -107,30 +107,9 @@ static HRESULT WINAPI BitmapTestSrc_GetResolution(IWICBitmapSource *iface, } static HRESULT WINAPI BitmapTestSrc_CopyPalette(IWICBitmapSource *iface, - IWICPalette *palette) + IWICPalette *pIPalette) { - BitmapTestSrc *This = impl_from_IWICBitmapSource(iface); - - if (IsEqualGUID(This->data->format, &GUID_WICPixelFormat1bppIndexed) || - IsEqualGUID(This->data->format, &GUID_WICPixelFormat2bppIndexed) || - IsEqualGUID(This->data->format, &GUID_WICPixelFormat4bppIndexed) || - IsEqualGUID(This->data->format, &GUID_WICPixelFormat8bppIndexed)) - { - WICColor colors[8]; - - colors[0] = 0xff0000ff; - colors[1] = 0xff00ff00; - colors[2] = 0xffff0000; - colors[3] = 0xff000000; - colors[4] = 0xffffff00; - colors[5] = 0xffff00ff; - colors[6] = 0xff00ffff; - colors[7] = 0xffffffff; - return IWICPalette_InitializeCustom(palette, colors, 8); - } - - /* unique error marker */ - return 0xdeadbeef; + return E_NOTIMPL; } static HRESULT WINAPI BitmapTestSrc_CopyPixels(IWICBitmapSource *iface, @@ -262,58 +241,16 @@ static BOOL compare_bits(const struct bitmap_data *expect, UINT buffersize, cons break; } } - else if (IsEqualGUID(expect->format, &GUID_WICPixelFormat2bppIndexed) || - IsEqualGUID(expect->format, &GUID_WICPixelFormat4bppIndexed) || - IsEqualGUID(expect->format, &GUID_WICPixelFormat8bppIndexed)) - { - UINT i; - const BYTE *a=(const BYTE*)expect->bits, *b=(const BYTE*)converted_bits; - equal=TRUE; - - for (i=0; i<buffersize; i++) - if (a[i] != b[i]) - { - equal = FALSE; - break; - } - } else equal = (memcmp(expect->bits, converted_bits, buffersize) == 0); if (!equal && expect->alt_data) equal = compare_bits(expect->alt_data, buffersize, converted_bits); - if (!equal && winetest_debug > 1) - { - UINT i, bps; - bps = expect->bpp / 8; - if (!bps) bps = buffersize; - printf("converted_bits (%u bytes):\n ", buffersize); - for (i = 0; i < buffersize; i++) - { - printf("%u,", converted_bits[i]); - if (!((i + 1) % 32)) printf("\n "); - else if (!((i+1) % bps)) printf(" "); - } - printf("\n"); - } - return equal; } -static BOOL is_indexed_format(const GUID *format) -{ - if (IsEqualGUID(format, &GUID_WICPixelFormat1bppIndexed) || - IsEqualGUID(format, &GUID_WICPixelFormat2bppIndexed) || - IsEqualGUID(format, &GUID_WICPixelFormat4bppIndexed) || - IsEqualGUID(format, &GUID_WICPixelFormat8bppIndexed)) - return TRUE; - - return FALSE; -} - -static void compare_bitmap_data(const struct bitmap_data *src, const struct bitmap_data *expect, - IWICBitmapSource *source, const char *name) +static void compare_bitmap_data(const struct bitmap_data *expect, IWICBitmapSource *source, const char *name) { BYTE *converted_bits; UINT width, height; @@ -346,24 +283,15 @@ static void compare_bitmap_data(const struct bitmap_data *src, const struct bitm buffersize = stride * expect->height; converted_bits = HeapAlloc(GetProcessHeap(), 0, buffersize); - memset(converted_bits, 0xaa, buffersize); hr = IWICBitmapSource_CopyPixels(source, &prc, stride, buffersize, converted_bits); ok(SUCCEEDED(hr), "CopyPixels(%s) failed, hr=%x\n", name, hr); - - /* The result of conversion of color to indexed formats depends on - * optimized palette generation implementation. We either need to - * assign our own palette, or just skip the comparison. - */ - if (!(!is_indexed_format(src->format) && is_indexed_format(expect->format))) - ok(compare_bits(expect, buffersize, converted_bits), "unexpected pixel data (%s)\n", name); + ok(compare_bits(expect, buffersize, converted_bits), "unexpected pixel data (%s)\n", name); /* Test with NULL rectangle - should copy the whole bitmap */ memset(converted_bits, 0xaa, buffersize); hr = IWICBitmapSource_CopyPixels(source, NULL, stride, buffersize, converted_bits); ok(SUCCEEDED(hr), "CopyPixels(%s,rc=NULL) failed, hr=%x\n", name, hr); - /* see comment above */ - if (!(!is_indexed_format(src->format) && is_indexed_format(expect->format))) - ok(compare_bits(expect, buffersize, converted_bits), "unexpected pixel data (%s)\n", name); + ok(compare_bits(expect, buffersize, converted_bits), "unexpected pixel data (%s)\n", name); HeapFree(GetProcessHeap(), 0, converted_bits); } @@ -377,161 +305,66 @@ static const struct bitmap_data testdata_BlackWhite = { static const struct bitmap_data testdata_1bppIndexed = { &GUID_WICPixelFormat1bppIndexed, 1, bits_1bpp, 32, 2, 96.0, 96.0}; -/* some encoders (like BMP) require data to be 4-bytes aligned */ -static const BYTE bits_2bpp[] = { - 0xdb,0xdb,0xdb,0xdb,0xdb,0xdb,0xdb,0xdb, - 0x24,0x24,0x24,0x24,0x24,0x24,0x24,0x24}; -static const struct bitmap_data testdata_2bppIndexed = { - &GUID_WICPixelFormat2bppIndexed, 2, bits_2bpp, 32, 2, 96.0, 96.0}; - -/* some encoders (like BMP) require data to be 4-bytes aligned */ -static const BYTE bits_4bpp[] = { - 0x01,0x23,0x01,0x23,0x01,0x23,0x01,0x23,0x01,0x23,0x01,0x23,0x01,0x23,0x01,0x23, - 0x45,0x67,0x45,0x67,0x45,0x67,0x45,0x67,0x45,0x67,0x45,0x67,0x45,0x67,0x45,0x67}; - -static const struct bitmap_data testdata_4bppIndexed = { - &GUID_WICPixelFormat4bppIndexed, 4, bits_4bpp, 32, 2, 96.0, 96.0}; - -static const BYTE bits_8bpp_BW[] = { - 0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1, - 1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0}; -static const struct bitmap_data testdata_8bppIndexed_BW = { - &GUID_WICPixelFormat8bppIndexed, 8, bits_8bpp_BW, 32, 2, 96.0, 96.0}; - -static const BYTE bits_8bpp_4colors[] = { - 0,1,2,0,0,1,2,0,0,1,2,0,0,1,2,0,0,1,2,0,0,1,2,0,0,1,2,0,0,1,2,0, - 3,2,1,3,3,2,1,3,3,2,1,3,3,2,1,3,3,2,1,3,3,2,1,3,3,2,1,3,3,2,1,3}; -static const struct bitmap_data testdata_8bppIndexed_4colors = { - &GUID_WICPixelFormat8bppIndexed, 8, bits_8bpp_4colors, 32, 2, 96.0, 96.0}; - static const BYTE bits_8bpp[] = { - 0,1,2,3,0,1,2,3,0,1,2,3,0,1,2,3,0,1,2,3,0,1,2,3,0,1,2,3,0,1,2,3, - 4,5,6,7,4,5,6,7,4,5,6,7,4,5,6,7,4,5,6,7,4,5,6,7,4,5,6,7,4,5,6,7}; + 0,1,2,3, + 4,5,6,7}; static const struct bitmap_data testdata_8bppIndexed = { - &GUID_WICPixelFormat8bppIndexed, 8, bits_8bpp, 32, 2, 96.0, 96.0}; + &GUID_WICPixelFormat8bppIndexed, 8, bits_8bpp, 4, 2, 96.0, 96.0}; static const BYTE bits_24bppBGR[] = { - 255,0,0, 0,255,0, 0,0,255, 0,0,0, 255,0,0, 0,255,0, 0,0,255, 0,0,0, - 255,0,0, 0,255,0, 0,0,255, 0,0,0, 255,0,0, 0,255,0, 0,0,255, 0,0,0, - 255,0,0, 0,255,0, 0,0,255, 0,0,0, 255,0,0, 0,255,0, 0,0,255, 0,0,0, - 255,0,0, 0,255,0, 0,0,255, 0,0,0, 255,0,0, 0,255,0, 0,0,255, 0,0,0, - 0,255,255, 255,0,255, 255,255,0, 255,255,255, 0,255,255, 255,0,255, 255,255,0, 255,255,255, - 0,255,255, 255,0,255, 255,255,0, 255,255,255, 0,255,255, 255,0,255, 255,255,0, 255,255,255, - 0,255,255, 255,0,255, 255,255,0, 255,255,255, 0,255,255, 255,0,255, 255,255,0, 255,255,255, - 0,255,255, 255,0,255, 255,255,0, 255,255,255, 0,255,255, 255,0,255, 255,255,0, 255,255,255}; + 255,0,0, 0,255,0, 0,0,255, 0,0,0, + 0,255,255, 255,0,255, 255,255,0, 255,255,255}; static const struct bitmap_data testdata_24bppBGR = { - &GUID_WICPixelFormat24bppBGR, 24, bits_24bppBGR, 32, 2, 96.0, 96.0}; + &GUID_WICPixelFormat24bppBGR, 24, bits_24bppBGR, 4, 2, 96.0, 96.0}; static const BYTE bits_24bppRGB[] = { - 0,0,255, 0,255,0, 255,0,0, 0,0,0, 0,0,255, 0,255,0, 255,0,0, 0,0,0, - 0,0,255, 0,255,0, 255,0,0, 0,0,0, 0,0,255, 0,255,0, 255,0,0, 0,0,0, - 0,0,255, 0,255,0, 255,0,0, 0,0,0, 0,0,255, 0,255,0, 255,0,0, 0,0,0, - 0,0,255, 0,255,0, 255,0,0, 0,0,0, 0,0,255, 0,255,0, 255,0,0, 0,0,0, - 255,255,0, 255,0,255, 0,255,255, 255,255,255, 255,255,0, 255,0,255, 0,255,255, 255,255,255, - 255,255,0, 255,0,255, 0,255,255, 255,255,255, 255,255,0, 255,0,255, 0,255,255, 255,255,255, - 255,255,0, 255,0,255, 0,255,255, 255,255,255, 255,255,0, 255,0,255, 0,255,255, 255,255,255, - 255,255,0, 255,0,255, 0,255,255, 255,255,255, 255,255,0, 255,0,255, 0,255,255, 255,255,255 }; + 0,0,255, 0,255,0, 255,0,0, 0,0,0, + 255,255,0, 255,0,255, 0,255,255, 255,255,255}; static const struct bitmap_data testdata_24bppRGB = { - &GUID_WICPixelFormat24bppRGB, 24, bits_24bppRGB, 32, 2, 96.0, 96.0}; + &GUID_WICPixelFormat24bppRGB, 24, bits_24bppRGB, 4, 2, 96.0, 96.0}; static const BYTE bits_32bppBGR[] = { - 255,0,0,80, 0,255,0,80, 0,0,255,80, 0,0,0,80, 255,0,0,80, 0,255,0,80, 0,0,255,80, 0,0,0,80, - 255,0,0,80, 0,255,0,80, 0,0,255,80, 0,0,0,80, 255,0,0,80, 0,255,0,80, 0,0,255,80, 0,0,0,80, - 255,0,0,80, 0,255,0,80, 0,0,255,80, 0,0,0,80, 255,0,0,80, 0,255,0,80, 0,0,255,80, 0,0,0,80, - 255,0,0,80, 0,255,0,80, 0,0,255,80, 0,0,0,80, 255,0,0,80, 0,255,0,80, 0,0,255,80, 0,0,0,80, - 0,255,255,80, 255,0,255,80, 255,255,0,80, 255,255,255,80, 0,255,255,80, 255,0,255,80, 255,255,0,80, 255,255,255,80, - 0,255,255,80, 255,0,255,80, 255,255,0,80, 255,255,255,80, 0,255,255,80, 255,0,255,80, 255,255,0,80, 255,255,255,80, - 0,255,255,80, 255,0,255,80, 255,255,0,80, 255,255,255,80, 0,255,255,80, 255,0,255,80, 255,255,0,80, 255,255,255,80, - 0,255,255,80, 255,0,255,80, 255,255,0,80, 255,255,255,80, 0,255,255,80, 255,0,255,80, 255,255,0,80, 255,255,255,80}; + 255,0,0,80, 0,255,0,80, 0,0,255,80, 0,0,0,80, + 0,255,255,80, 255,0,255,80, 255,255,0,80, 255,255,255,80}; static const struct bitmap_data testdata_32bppBGR = { - &GUID_WICPixelFormat32bppBGR, 32, bits_32bppBGR, 32, 2, 96.0, 96.0}; -static const struct bitmap_data testdata_32bppBGRA80 = { - &GUID_WICPixelFormat32bppBGRA, 32, bits_32bppBGR, 32, 2, 96.0, 96.0}; -static const struct bitmap_data testdata_32bppRGBA80 = { - &GUID_WICPixelFormat32bppRGBA, 32, bits_32bppBGR, 32, 2, 96.0, 96.0}; + &GUID_WICPixelFormat32bppBGR, 32, bits_32bppBGR, 4, 2, 96.0, 96.0}; static const BYTE bits_32bppBGRA[] = { - 255,0,0,255, 0,255,0,255, 0,0,255,255, 0,0,0,255, 255,0,0,255, 0,255,0,255, 0,0,255,255, 0,0,0,255, - 255,0,0,255, 0,255,0,255, 0,0,255,255, 0,0,0,255, 255,0,0,255, 0,255,0,255, 0,0,255,255, 0,0,0,255, - 255,0,0,255, 0,255,0,255, 0,0,255,255, 0,0,0,255, 255,0,0,255, 0,255,0,255, 0,0,255,255, 0,0,0,255, - 255,0,0,255, 0,255,0,255, 0,0,255,255, 0,0,0,255, 255,0,0,255, 0,255,0,255, 0,0,255,255, 0,0,0,255, - 0,255,255,255, 255,0,255,255, 255,255,0,255, 255,255,255,255, 0,255,255,255, 255,0,255,255, 255,255,0,255, 255,255,255,255, - 0,255,255,255, 255,0,255,255, 255,255,0,255, 255,255,255,255, 0,255,255,255, 255,0,255,255, 255,255,0,255, 255,255,255,255, - 0,255,255,255, 255,0,255,255, 255,255,0,255, 255,255,255,255, 0,255,255,255, 255,0,255,255, 255,255,0,255, 255,255,255,255, - 0,255,255,255, 255,0,255,255, 255,255,0,255, 255,255,255,255, 0,255,255,255, 255,0,255,255, 255,255,0,255, 255,255,255,255}; + 255,0,0,255, 0,255,0,255, 0,0,255,255, 0,0,0,255, + 0,255,255,255, 255,0,255,255, 255,255,0,255, 255,255,255,255}; static const struct bitmap_data testdata_32bppBGRA = { - &GUID_WICPixelFormat32bppBGRA, 32, bits_32bppBGRA, 32, 2, 96.0, 96.0}; -static const struct bitmap_data testdata_32bppRGBA = { - &GUID_WICPixelFormat32bppRGBA, 32, bits_32bppBGRA, 32, 2, 96.0, 96.0}; -static const struct bitmap_data testdata_32bppRGB = { - &GUID_WICPixelFormat32bppRGB, 32, bits_32bppBGRA, 32, 2, 96.0, 96.0}; - -static const BYTE bits_32bppPBGRA[] = { - 80,0,0,80, 0,80,0,80, 0,0,80,80, 0,0,0,80, 80,0,0,80, 0,80,0,80, 0,0,80,80, 0,0,0,80, - 80,0,0,80, 0,80,0,80, 0,0,80,80, 0,0,0,80, 80,0,0,80, 0,80,0,80, 0,0,80,80, 0,0,0,80, - 80,0,0,80, 0,80,0,80, 0,0,80,80, 0,0,0,80, 80,0,0,80, 0,80,0,80, 0,0,80,80, 0,0,0,80, - 80,0,0,80, 0,80,0,80, 0,0,80,80, 0,0,0,80, 80,0,0,80, 0,80,0,80, 0,0,80,80, 0,0,0,80, - 0,80,80,80, 80,0,80,80, 80,80,0,80, 80,80,80,80, 0,80,80,80, 80,0,80,80, 80,80,0,80, 80,80,80,80, - 0,80,80,80, 80,0,80,80, 80,80,0,80, 80,80,80,80, 0,80,80,80, 80,0,80,80, 80,80,0,80, 80,80,80,80, - 0,80,80,80, 80,0,80,80, 80,80,0,80, 80,80,80,80, 0,80,80,80, 80,0,80,80, 80,80,0,80, 80,80,80,80, - 0,80,80,80, 80,0,80,80, 80,80,0,80, 80,80,80,80, 0,80,80,80, 80,0,80,80, 80,80,0,80, 80,80,80,80}; -static const struct bitmap_data testdata_32bppPBGRA = { - &GUID_WICPixelFormat32bppPBGRA, 32, bits_32bppPBGRA, 32, 2, 96.0, 96.0}; -static const struct bitmap_data testdata_32bppPRGBA = { - &GUID_WICPixelFormat32bppPRGBA, 32, bits_32bppPBGRA, 32, 2, 96.0, 96.0}; + &GUID_WICPixelFormat32bppBGRA, 32, bits_32bppBGRA, 4, 2, 96.0, 96.0}; /* XP and 2003 use linear color conversion, later versions use sRGB gamma */ static const float bits_32bppGrayFloat_xp[] = { - 0.114000f,0.587000f,0.299000f,0.000000f,0.114000f,0.587000f,0.299000f,0.000000f, - 0.114000f,0.587000f,0.299000f,0.000000f,0.114000f,0.587000f,0.299000f,0.000000f, - 0.114000f,0.587000f,0.299000f,0.000000f,0.114000f,0.587000f,0.299000f,0.000000f, - 0.114000f,0.587000f,0.299000f,0.000000f,0.114000f,0.587000f,0.299000f,0.000000f, - 0.886000f,0.413000f,0.701000f,1.000000f,0.886000f,0.413000f,0.701000f,1.000000f, - 0.886000f,0.413000f,0.701000f,1.000000f,0.886000f,0.413000f,0.701000f,1.000000f, - 0.886000f,0.413000f,0.701000f,1.000000f,0.886000f,0.413000f,0.701000f,1.000000f, - 0.886000f,0.413000f,0.701000f,1.000000f,0.886000f,0.413000f,0.701000f,1.000000f}; + 0.114000f,0.587000f,0.299000f,0.000000f, + 0.886000f,0.413000f,0.701000f,1.000000f}; static const struct bitmap_data testdata_32bppGrayFloat_xp = { - &GUID_WICPixelFormat32bppGrayFloat, 32, (const BYTE *)bits_32bppGrayFloat_xp, 32, 2, 96.0, 96.0}; + &GUID_WICPixelFormat32bppGrayFloat, 32, (const BYTE *)bits_32bppGrayFloat_xp, 4, 2, 96.0, 96.0}; static const float bits_32bppGrayFloat[] = { - 0.072200f,0.715200f,0.212600f,0.000000f,0.072200f,0.715200f,0.212600f,0.000000f, - 0.072200f,0.715200f,0.212600f,0.000000f,0.072200f,0.715200f,0.212600f,0.000000f, - 0.072200f,0.715200f,0.212600f,0.000000f,0.072200f,0.715200f,0.212600f,0.000000f, - 0.072200f,0.715200f,0.212600f,0.000000f,0.072200f,0.715200f,0.212600f,0.000000f, - 0.927800f,0.284800f,0.787400f,1.000000f,0.927800f,0.284800f,0.787400f,1.000000f, - 0.927800f,0.284800f,0.787400f,1.000000f,0.927800f,0.284800f,0.787400f,1.000000f, - 0.927800f,0.284800f,0.787400f,1.000000f,0.927800f,0.284800f,0.787400f,1.000000f, - 0.927800f,0.284800f,0.787400f,1.000000f,0.927800f,0.284800f,0.787400f,1.000000f}; + 0.072200f,0.715200f,0.212600f,0.000000f, + 0.927800f,0.284800f,0.787400f,1.000000f}; static const struct bitmap_data testdata_32bppGrayFloat = { - &GUID_WICPixelFormat32bppGrayFloat, 32, (const BYTE *)bits_32bppGrayFloat, 32, 2, 96.0, 96.0, &testdata_32bppGrayFloat_xp}; + &GUID_WICPixelFormat32bppGrayFloat, 32, (const BYTE *)bits_32bppGrayFloat, 4, 2, 96.0, 96.0, &testdata_32bppGrayFloat_xp}; static const BYTE bits_8bppGray_xp[] = { - 29,150,76,0,29,150,76,0,29,150,76,0,29,150,76,0, - 29,150,76,0,29,150,76,0,29,150,76,0,29,150,76,0, - 226,105,179,255,226,105,179,255,226,105,179,255,226,105,179,255, - 226,105,179,255,226,105,179,255,226,105,179,255,226,105,179,255}; + 29,150,76,0, + 226,105,179,255}; static const struct bitmap_data testdata_8bppGray_xp = { - &GUID_WICPixelFormat8bppGray, 8, bits_8bppGray_xp, 32, 2, 96.0, 96.0}; + &GUID_WICPixelFormat8bppGray, 8, bits_8bppGray_xp, 4, 2, 96.0, 96.0}; static const BYTE bits_8bppGray[] = { - 76,220,127,0,76,220,127,0,76,220,127,0,76,220,127,0, - 76,220,127,0,76,220,127,0,76,220,127,0,76,220,127,0, - 247,145,230,255,247,145,230,255,247,145,230,255,247,145,230,255, - 247,145,230,255,247,145,230,255,247,145,230,255,247,145,230,255}; + 76,220,127,0, + 247,145,230,255}; static const struct bitmap_data testdata_8bppGray = { - &GUID_WICPixelFormat8bppGray, 8, bits_8bppGray, 32, 2, 96.0, 96.0, &testdata_8bppGray_xp}; + &GUID_WICPixelFormat8bppGray, 8, bits_8bppGray, 4, 2, 96.0, 96.0, &testdata_8bppGray_xp}; static const BYTE bits_24bppBGR_gray[] = { - 76,76,76, 220,220,220, 127,127,127, 0,0,0, 76,76,76, 220,220,220, 127,127,127, 0,0,0, - 76,76,76, 220,220,220, 127,127,127, 0,0,0, 76,76,76, 220,220,220, 127,127,127, 0,0,0, - 76,76,76, 220,220,220, 127,127,127, 0,0,0, 76,76,76, 220,220,220, 127,127,127, 0,0,0, - 76,76,76, 220,220,220, 127,127,127, 0,0,0, 76,76,76, 220,220,220, 127,127,127, 0,0,0, - 247,247,247, 145,145,145, 230,230,230, 255,255,255, 247,247,247, 145,145,145, 230,230,230, 255,255,255, - 247,247,247, 145,145,145, 230,230,230, 255,255,255, 247,247,247, 145,145,145, 230,230,230, 255,255,255, - 247,247,247, 145,145,145, 230,230,230, 255,255,255, 247,247,247, 145,145,145, 230,230,230, 255,255,255, - 247,247,247, 145,145,145, 230,230,230, 255,255,255, 247,247,247, 145,145,145, 230,230,230, 255,255,255}; + 76,76,76, 220,220,220, 127,127,127, 0,0,0, + 247,247,247, 145,145,145, 230,230,230, 255,255,255}; static const struct bitmap_data testdata_24bppBGR_gray = { - &GUID_WICPixelFormat24bppBGR, 24, bits_24bppBGR_gray, 32, 2, 96.0, 96.0}; + &GUID_WICPixelFormat24bppBGR, 24, bits_24bppBGR_gray, 4, 2, 96.0, 96.0}; static void test_conversion(const struct bitmap_data *src, const struct bitmap_data *dst, const char *name, BOOL todo) { @@ -543,12 +376,11 @@ static void test_conversion(const struct bitmap_data *src, const struct bitmap_d hr = WICConvertBitmapSource(dst->format, &src_obj->IWICBitmapSource_iface, &dst_bitmap); todo_wine_if (todo) - ok(hr == S_OK || - broken(hr == E_INVALIDARG || hr == WINCODEC_ERR_COMPONENTNOTFOUND) /* XP */, "WICConvertBitmapSource(%s) failed, hr=%x\n", name, hr); + ok(SUCCEEDED(hr), "WICConvertBitmapSource(%s) failed, hr=%x\n", name, hr); - if (hr == S_OK) + if (SUCCEEDED(hr)) { - compare_bitmap_data(src, dst, dst_bitmap, name); + compare_bitmap_data(dst, dst_bitmap, name); IWICBitmapSource_Release(dst_bitmap); } @@ -596,7 +428,7 @@ static void test_default_converter(void) ok(SUCCEEDED(hr), "Initialize returned %x\n", hr); if (SUCCEEDED(hr)) - compare_bitmap_data(&testdata_32bppBGRA, &testdata_32bppBGR, (IWICBitmapSource*)converter, "default converter"); + compare_bitmap_data(&testdata_32bppBGR, (IWICBitmapSource*)converter, "default converter"); IWICFormatConverter_Release(converter); } @@ -781,232 +613,14 @@ static void test_encoder_properties(const CLSID* clsid_encoder, IPropertyBag2 *o } } -static void load_stream(IUnknown *reader, IStream *stream) +static void check_bmp_format(IStream *stream, const WICPixelFormatGUID *format) { - HRESULT hr; - IWICPersistStream *persist; -#ifdef WORDS_BIGENDIAN - DWORD persist_options = WICPersistOptionBigEndian; -#else - DWORD persist_options = WICPersistOptionLittleEndian; -#endif - - hr = IUnknown_QueryInterface(reader, &IID_IWICPersistStream, (void **)&persist); - ok(hr == S_OK, "QueryInterface failed, hr=%x\n", hr); - - hr = IWICPersistStream_LoadEx(persist, stream, NULL, persist_options); - ok(hr == S_OK, "LoadEx failed, hr=%x\n", hr); - - IWICPersistStream_Release(persist); + /* FIXME */ } static void check_tiff_format(IStream *stream, const WICPixelFormatGUID *format) { - HRESULT hr; - IWICMetadataReader *reader; - PROPVARIANT id, value; - struct - { - USHORT byte_order; - USHORT version; - ULONG dir_offset; - } tiff; - LARGE_INTEGER pos; - UINT count, i; - int width, height, bps, photo, samples, colormap; - struct - { - int id, *value; - } tag[] = - { - { 0x100, &width }, { 0x101, &height }, { 0x102, &bps }, - { 0x106, &photo }, { 0x115, &samples }, { 0x140, &colormap } - }; - - memset(&tiff, 0, sizeof(tiff)); - hr = IStream_Read(stream, &tiff, sizeof(tiff), NULL); - ok(hr == S_OK, "IStream_Read error %#x\n", hr); - ok(tiff.byte_order == MAKEWORD('I','I') || tiff.byte_order == MAKEWORD('M','M'), - "wrong TIFF byte order mark %02x\n", tiff.byte_order); - ok(tiff.version == 42, "wrong TIFF version %u\n", tiff.version); - - pos.QuadPart = tiff.dir_offset; - hr = IStream_Seek(stream, pos, SEEK_SET, NULL); - ok(hr == S_OK, "IStream_Seek error %#x\n", hr); - - hr = CoCreateInstance(&CLSID_WICIfdMetadataReader, NULL, CLSCTX_INPROC_SERVER, - &IID_IWICMetadataReader, (void **)&reader); - ok(hr == S_OK, "CoCreateInstance error %#x\n", hr); - - load_stream((IUnknown *)reader, stream); - - hr = IWICMetadataReader_GetCount(reader, &count); - ok(hr == S_OK, "GetCount error %#x\n", hr); - ok(count != 0, "wrong count %u\n", count); - - for (i = 0; i < sizeof(tag)/sizeof(tag[0]); i++) - { - PropVariantInit(&id); - PropVariantInit(&value); - - id.vt = VT_UI2; - U(id).uiVal = tag[i].id; - hr = IWICMetadataReader_GetValue(reader, NULL, &id, &value); - ok(hr == S_OK || (tag[i].id == 0x140 && hr == WINCODEC_ERR_PROPERTYNOTFOUND), - "GetValue(%04x) error %#x\n", tag[i].id, hr); - if (hr == S_OK) - { - ok(value.vt == VT_UI2 || value.vt == VT_UI4 || value.vt == (VT_UI2 | VT_VECTOR), "wrong vt: %d\n", value.vt); - tag[i].value[0] = U(value).uiVal; - } - else - tag[i].value[0] = -1; - } - - IWICMetadataReader_Release(reader); - - if (IsEqualGUID(format, &GUID_WICPixelFormatBlackWhite)) - { - ok(width == 32, "wrong width %u\n", width); - ok(height == 2, "wrong height %u\n", height); - - ok(bps == 1, "wrong bps %d\n", bps); - ok(photo == 1, "wrong photometric %d\n", photo); - ok(samples == 1, "wrong samples %d\n", samples); - ok(colormap == -1, "wrong colormap %d\n", colormap); - } - else if (IsEqualGUID(format, &GUID_WICPixelFormat1bppIndexed)) - { - ok(width == 32, "wrong width %u\n", width); - ok(height == 2, "wrong height %u\n", height); - - ok(bps == 1, "wrong bps %d\n", bps); - ok(photo == 3, "wrong photometric %d\n", photo); - ok(samples == 1, "wrong samples %d\n", samples); - ok(colormap == 6, "wrong colormap %d\n", colormap); - } - else if (IsEqualGUID(format, &GUID_WICPixelFormat2bppIndexed)) - { - ok(width == 32, "wrong width %u\n", width); - ok(height == 2, "wrong height %u\n", height); - - ok(bps == 2, "wrong bps %d\n", bps); - ok(photo == 3, "wrong photometric %d\n", photo); - ok(samples == 1, "wrong samples %d\n", samples); - ok(colormap == 12, "wrong colormap %d\n", colormap); - } - else if (IsEqualGUID(format, &GUID_WICPixelFormat4bppIndexed)) - { - ok(width == 32, "wrong width %u\n", width); - ok(height == 2, "wrong height %u\n", height); - - ok(bps == 4, "wrong bps %d\n", bps); - ok(photo == 3, "wrong photometric %d\n", photo); - ok(samples == 1, "wrong samples %d\n", samples); - ok(colormap == 48, "wrong colormap %d\n", colormap); - } - else if (IsEqualGUID(format, &GUID_WICPixelFormat8bppIndexed)) - { - ok(width == 32, "wrong width %u\n", width); - ok(height == 2, "wrong height %u\n", height); - - ok(bps == 8, "wrong bps %d\n", bps); - ok(photo == 3, "wrong photometric %d\n", photo); - ok(samples == 1, "wrong samples %d\n", samples); - ok(colormap == 768, "wrong colormap %d\n", colormap); - } - else if (IsEqualGUID(format, &GUID_WICPixelFormat24bppBGR)) - { - ok(width == 32, "wrong width %u\n", width); - ok(height == 2, "wrong height %u\n", height); - - ok(bps == 3, "wrong bps %d\n", bps); - ok(photo == 2, "wrong photometric %d\n", photo); - ok(samples == 3, "wrong samples %d\n", samples); - ok(colormap == -1, "wrong colormap %d\n", colormap); - } - else - ok(0, "unknown TIFF pixel format %s\n", wine_dbgstr_guid(format)); -} - -static void check_bmp_format(IStream *stream, const WICPixelFormatGUID *format) -{ - HRESULT hr; - BITMAPFILEHEADER bfh; - BITMAPV5HEADER bih; - - hr = IStream_Read(stream, &bfh, sizeof(bfh), NULL); - ok(hr == S_OK, "IStream_Read error %#x\n", hr); - - ok(bfh.bfType == 0x4d42, "wrong BMP signature %02x\n", bfh.bfType); - ok(bfh.bfReserved1 == 0, "wrong bfReserved1 %02x\n", bfh.bfReserved1); - ok(bfh.bfReserved2 == 0, "wrong bfReserved2 %02x\n", bfh.bfReserved2); - - hr = IStream_Read(stream, &bih, sizeof(bih), NULL); - ok(hr == S_OK, "IStream_Read error %#x\n", hr); - - if (IsEqualGUID(format, &GUID_WICPixelFormat1bppIndexed)) - { - ok(bfh.bfOffBits == 0x0436, "wrong bfOffBits %08x\n", bfh.bfOffBits); - - ok(bih.bV5Width == 32, "wrong width %u\n", bih.bV5Width); - ok(bih.bV5Height == 2, "wrong height %u\n", bih.bV5Height); - - ok(bih.bV5Planes == 1, "wrong Planes %d\n", bih.bV5Planes); - ok(bih.bV5BitCount == 1, "wrong BitCount %d\n", bih.bV5BitCount); - ok(bih.bV5ClrUsed == 256, "wrong ClrUsed %d\n", bih.bV5ClrUsed); - ok(bih.bV5ClrImportant == 256, "wrong ClrImportant %d\n", bih.bV5ClrImportant); - } - else if (IsEqualGUID(format, &GUID_WICPixelFormat2bppIndexed)) - { - ok(bfh.bfOffBits == 0x0436, "wrong bfOffBits %08x\n", bfh.bfOffBits); - - ok(bih.bV5Width == 32, "wrong width %u\n", bih.bV5Width); - ok(bih.bV5Height == 2, "wrong height %u\n", bih.bV5Height); - - ok(bih.bV5Planes == 1, "wrong Planes %d\n", bih.bV5Planes); - ok(bih.bV5BitCount == 2, "wrong BitCount %d\n", bih.bV5BitCount); - ok(bih.bV5ClrUsed == 256, "wrong ClrUsed %d\n", bih.bV5ClrUsed); - ok(bih.bV5ClrImportant == 256, "wrong ClrImportant %d\n", bih.bV5ClrImportant); - } - else if (IsEqualGUID(format, &GUID_WICPixelFormat4bppIndexed)) - { - ok(bfh.bfOffBits == 0x0436, "wrong bfOffBits %08x\n", bfh.bfOffBits); - - ok(bih.bV5Width == 32, "wrong width %u\n", bih.bV5Width); - ok(bih.bV5Height == 2, "wrong height %u\n", bih.bV5Height); - - ok(bih.bV5Planes == 1, "wrong Planes %d\n", bih.bV5Planes); - ok(bih.bV5BitCount == 4, "wrong BitCount %d\n", bih.bV5BitCount); - ok(bih.bV5ClrUsed == 256, "wrong ClrUsed %d\n", bih.bV5ClrUsed); - ok(bih.bV5ClrImportant == 256, "wrong ClrImportant %d\n", bih.bV5ClrImportant); - } - else if (IsEqualGUID(format, &GUID_WICPixelFormat8bppIndexed)) - { - ok(bfh.bfOffBits == 0x0436, "wrong bfOffBits %08x\n", bfh.bfOffBits); - - ok(bih.bV5Width == 32, "wrong width %u\n", bih.bV5Width); - ok(bih.bV5Height == 2, "wrong height %u\n", bih.bV5Height); - - ok(bih.bV5Planes == 1, "wrong Planes %d\n", bih.bV5Planes); - ok(bih.bV5BitCount == 8, "wrong BitCount %d\n", bih.bV5BitCount); - ok(bih.bV5ClrUsed == 256, "wrong ClrUsed %d\n", bih.bV5ClrUsed); - ok(bih.bV5ClrImportant == 256, "wrong ClrImportant %d\n", bih.bV5ClrImportant); - } - else if (IsEqualGUID(format, &GUID_WICPixelFormat32bppBGR)) - { - ok(bfh.bfOffBits == 0x0036, "wrong bfOffBits %08x\n", bfh.bfOffBits); - - ok(bih.bV5Width == 32, "wrong width %u\n", bih.bV5Width); - ok(bih.bV5Height == 2, "wrong height %u\n", bih.bV5Height); - - ok(bih.bV5Planes == 1, "wrong Planes %d\n", bih.bV5Planes); - ok(bih.bV5BitCount == 32, "wrong BitCount %d\n", bih.bV5BitCount); - ok(bih.bV5ClrUsed == 0, "wrong ClrUsed %d\n", bih.bV5ClrUsed); - ok(bih.bV5ClrImportant == 0, "wrong ClrImportant %d\n", bih.bV5ClrImportant); - } - else - ok(0, "unknown BMP pixel format %s\n", wine_dbgstr_guid(format)); + /* FIXME */ } static unsigned be_uint(unsigned val) @@ -1063,31 +677,9 @@ static void check_png_format(IStream *stream, const WICPixelFormatGUID *format) ok(png.filter == 0, "wrong filter %d\n", png.filter); ok(png.interlace == 0, "wrong interlace %d\n", png.interlace); } - else if (IsEqualGUID(format, &GUID_WICPixelFormat2bppIndexed)) - { - ok(be_uint(png.width) == 32, "wrong width %u\n", be_uint(png.width)); - ok(be_uint(png.height) == 2, "wrong height %u\n", be_uint(png.height)); - - ok(png.bit_depth == 2, "wrong bit_depth %d\n", png.bit_depth); - ok(png.color_type == 3, "wrong color_type %d\n", png.color_type); - ok(png.compression == 0, "wrong compression %d\n", png.compression); - ok(png.filter == 0, "wrong filter %d\n", png.filter); - ok(png.interlace == 0, "wrong interlace %d\n", png.interlace); - } - else if (IsEqualGUID(format, &GUID_WICPixelFormat4bppIndexed)) - { - ok(be_uint(png.width) == 32, "wrong width %u\n", be_uint(png.width)); - ok(be_uint(png.height) == 2, "wrong height %u\n", be_uint(png.height)); - - ok(png.bit_depth == 4, "wrong bit_depth %d\n", png.bit_depth); - ok(png.color_type == 3, "wrong color_type %d\n", png.color_type); - ok(png.compression == 0, "wrong compression %d\n", png.compression); - ok(png.filter == 0, "wrong filter %d\n", png.filter); - ok(png.interlace == 0, "wrong interlace %d\n", png.interlace); - } else if (IsEqualGUID(format, &GUID_WICPixelFormat8bppIndexed)) { - ok(be_uint(png.width) == 32, "wrong width %u\n", be_uint(png.width)); + ok(be_uint(png.width) == 4, "wrong width %u\n", be_uint(png.width)); ok(be_uint(png.height) == 2, "wrong height %u\n", be_uint(png.height)); ok(png.bit_depth == 8, "wrong bit_depth %d\n", png.bit_depth); @@ -1098,7 +690,7 @@ static void check_png_format(IStream *stream, const WICPixelFormatGUID *format) } else if (IsEqualGUID(format, &GUID_WICPixelFormat24bppBGR)) { - ok(be_uint(png.width) == 32, "wrong width %u\n", be_uint(png.width)); + ok(be_uint(png.width) == 4, "wrong width %u\n", be_uint(png.width)); ok(be_uint(png.height) == 2, "wrong height %u\n", be_uint(png.height)); ok(png.bit_depth == 8, "wrong bit_depth %d\n", png.bit_depth); @@ -1111,40 +703,6 @@ static void check_png_format(IStream *stream, const WICPixelFormatGUID *format) ok(0, "unknown PNG pixel format %s\n", wine_dbgstr_guid(format)); } -static void check_gif_format(IStream *stream, const WICPixelFormatGUID *format) -{ -#include "pshpack1.h" - struct logical_screen_descriptor - { - char signature[6]; - USHORT width; - USHORT height; - BYTE packed; - /* global_color_table_flag : 1; - * color_resolution : 3; - * sort_flag : 1; - * global_color_table_size : 3; - */ - BYTE background_color_index; - BYTE pixel_aspect_ratio; - } lsd; -#include "poppack.h" - UINT color_resolution; - HRESULT hr; - - memset(&lsd, 0, sizeof(lsd)); - hr = IStream_Read(stream, &lsd, sizeof(lsd), NULL); - ok(hr == S_OK, "IStream_Read error %#x\n", hr); - - ok(!memcmp(lsd.signature, "GIF89a", 6), "wrong GIF signature %.6s\n", lsd.signature); - - ok(lsd.width == 32, "wrong width %u\n", lsd.width); - ok(lsd.height == 2, "wrong height %u\n", lsd.height); - color_resolution = 1 << (((lsd.packed >> 4) & 0x07) + 1); - ok(color_resolution == 256, "wrong color resolution %u\n", color_resolution); - ok(lsd.pixel_aspect_ratio == 0, "wrong pixel_aspect_ratio %u\n", lsd.pixel_aspect_ratio); -} - static void check_bitmap_format(IStream *stream, const CLSID *encoder, const WICPixelFormatGUID *format) { HRESULT hr; @@ -1160,8 +718,6 @@ static void check_bitmap_format(IStream *stream, const CLSID *encoder, const WIC check_bmp_format(stream, format); else if (IsEqualGUID(encoder, &CLSID_WICTiffEncoder)) check_tiff_format(stream, format); - else if (IsEqualGUID(encoder, &CLSID_WICGifEncoder)) - check_gif_format(stream, format); else ok(0, "unknown encoder %s\n", wine_dbgstr_guid(encoder)); @@ -1238,7 +794,7 @@ static void test_multi_encoder(const struct bitmap_data **srcs, const CLSID* cls hr = CoCreateInstance(clsid_encoder, NULL, CLSCTX_INPROC_SERVER, &IID_IWICBitmapEncoder, (void**)&encoder); - ok(SUCCEEDED(hr), "CoCreateInstance(%s) failed, hr=%x\n", wine_dbgstr_guid(clsid_encoder), hr); + ok(SUCCEEDED(hr), "CoCreateInstance failed, hr=%x\n", hr); if (SUCCEEDED(hr)) { hglobal = GlobalAlloc(GMEM_MOVEABLE, 0); @@ -1263,10 +819,7 @@ static void test_multi_encoder(const struct bitmap_data **srcs, const CLSID* cls if (palette) { hr = IWICBitmapEncoder_SetPalette(encoder, palette); - if (IsEqualGUID(clsid_encoder, &CLSID_WICGifEncoder)) - ok(hr == S_OK, "SetPalette failed, hr=%#x\n", hr); - else - ok(hr == WINCODEC_ERR_UNSUPPORTEDOPERATION, "wrong error %#x\n", hr); + ok(hr == WINCODEC_ERR_UNSUPPORTEDOPERATION, "wrong error %#x\n", hr); hr = S_OK; } @@ -1315,10 +868,8 @@ static void test_multi_encoder(const struct bitmap_data **srcs, const CLSID* cls memcpy(&pixelformat, srcs[i]->format, sizeof(GUID)); hr = IWICBitmapFrameEncode_SetPixelFormat(frameencode, &pixelformat); ok(SUCCEEDED(hr), "SetPixelFormat failed, hr=%x\n", hr); - ok(IsEqualGUID(&pixelformat, dsts[i]->format) || - broken(IsEqualGUID(clsid_encoder, &CLSID_WICBmpEncoder) && srcs[i]->bpp == 2 && IsEqualGUID(&pixelformat, &GUID_WICPixelFormat4bppIndexed)) || - broken(IsEqualGUID(clsid_encoder, &CLSID_WICTiffEncoder) && srcs[i]->bpp == 2 && IsEqualGUID(&pixelformat, &GUID_WICPixelFormat4bppIndexed)), - "SetPixelFormat changed the format to %s (%s)\n", wine_dbgstr_guid(&pixelformat), name); + ok(IsEqualGUID(&pixelformat, dsts[i]->format), "SetPixelFormat changed the format to %s (%s)\n", + wine_dbgstr_guid(&pixelformat), name); hr = IWICBitmapFrameEncode_SetSize(frameencode, srcs[i]->width, srcs[i]->height); ok(SUCCEEDED(hr), "SetSize failed, hr=%x\n", hr); @@ -1353,8 +904,6 @@ static void test_multi_encoder(const struct bitmap_data **srcs, const CLSID* cls ok(SUCCEEDED(hr), "WriteSource(%dx%d) failed, hr=%x (%s)\n", rc->Width, rc->Height, hr, name); else ok(hr == S_OK || - broken(hr == E_INVALIDARG && IsEqualGUID(clsid_encoder, &CLSID_WICBmpEncoder) && srcs[i]->bpp == 2) /* XP */ || - broken(hr == E_INVALIDARG && IsEqualGUID(clsid_encoder, &CLSID_WICTiffEncoder) && srcs[i]->bpp == 2) /* XP */ || broken(hr == E_INVALIDARG && IsEqualGUID(clsid_encoder, &CLSID_WICBmpEncoder) && IsEqualGUID(srcs[i]->format, &GUID_WICPixelFormatBlackWhite)) /* XP */, "WriteSource(NULL) failed, hr=%x (%s)\n", hr, name); } @@ -1386,8 +935,7 @@ static void test_multi_encoder(const struct bitmap_data **srcs, const CLSID* cls hr = IWICBitmapEncoder_Commit(encoder); ok(SUCCEEDED(hr), "Commit failed, hr=%x\n", hr); - if (IsEqualGUID(&pixelformat, dsts[0]->format)) - check_bitmap_format(stream, clsid_encoder, dsts[0]->format); + check_bitmap_format(stream, clsid_encoder, dsts[0]->format); } if (SUCCEEDED(hr)) @@ -1405,19 +953,13 @@ static void test_multi_encoder(const struct bitmap_data **srcs, const CLSID* cls ok(hr == S_OK, "CreatePalette error %#x\n", hr); hr = IWICBitmapDecoder_CopyPalette(decoder, frame_palette); - if (IsEqualGUID(clsid_decoder, &CLSID_WICGifDecoder)) - ok(hr == WINCODEC_ERR_WRONGSTATE, "wrong error %#x\n", hr); - else - ok(hr == WINCODEC_ERR_PALETTEUNAVAILABLE, "wrong error %#x\n", hr); + ok(hr == WINCODEC_ERR_PALETTEUNAVAILABLE, "wrong error %#x\n", hr); hr = IWICBitmapDecoder_Initialize(decoder, stream, WICDecodeMetadataCacheOnDemand); ok(SUCCEEDED(hr), "Initialize failed, hr=%x\n", hr); hr = IWICBitmapDecoder_CopyPalette(decoder, frame_palette); - if (IsEqualGUID(clsid_decoder, &CLSID_WICGifDecoder)) - ok(hr == S_OK || broken(hr == WINCODEC_ERR_FRAMEMISSING) /* XP */, "CopyPalette failed, hr=%#x\n", hr); - else - ok(hr == WINCODEC_ERR_PALETTEUNAVAILABLE, "wrong error %#x\n", hr); + ok(hr == WINCODEC_ERR_PALETTEUNAVAILABLE, "wrong error %#x\n", hr); hr = S_OK; i=0; @@ -1428,10 +970,7 @@ static void test_multi_encoder(const struct bitmap_data **srcs, const CLSID* cls if (SUCCEEDED(hr)) { - hr = IWICBitmapFrameDecode_GetPixelFormat(framedecode, &pixelformat); - ok(hr == S_OK, "GetPixelFormat) failed, hr=%x (%s)\n", hr, name); - if (IsEqualGUID(&pixelformat, dsts[i]->format)) - compare_bitmap_data(srcs[i], dsts[i], (IWICBitmapSource*)framedecode, name); + compare_bitmap_data(dsts[i], (IWICBitmapSource*)framedecode, name); hr = IWICBitmapFrameDecode_CopyPalette(framedecode, frame_palette); if (winetest_debug > 1) @@ -1456,12 +995,7 @@ static void test_multi_encoder(const struct bitmap_data **srcs, const CLSID* cls ok(ret == count, "expected %u, got %u\n", count, ret); if (IsEqualGUID(clsid_decoder, &CLSID_WICPngDecoder)) { - /* Newer libpng versions don't accept larger palettes than the declared - * bit depth, so we need to generate the palette of the correct length. - */ - ok(count == 256 || (dsts[i]->bpp == 1 && count == 2) || - (dsts[i]->bpp == 2 && count == 4) || (dsts[i]->bpp == 4 && count == 16), - "expected 256, got %u (%s)\n", count, name); + ok(count == 256 || count == 2 /* newer libpng versions */, "expected 256, got %u (%s)\n", count, name); ok(colors[0] == 0x11111111, "got %08x (%s)\n", colors[0], name); ok(colors[1] == 0x22222222, "got %08x (%s)\n", colors[1], name); @@ -1469,19 +1003,15 @@ static void test_multi_encoder(const struct bitmap_data **srcs, const CLSID* cls { ok(colors[2] == 0x33333333, "got %08x (%s)\n", colors[2], name); ok(colors[3] == 0x44444444, "got %08x (%s)\n", colors[3], name); - if (count > 4) - { - ok(colors[4] == 0x55555555, "got %08x (%s)\n", colors[4], name); - ok(colors[5] == 0, "got %08x (%s)\n", colors[5], name); - } + ok(colors[4] == 0x55555555, "got %08x (%s)\n", colors[4], name); + ok(colors[5] == 0, "got %08x (%s)\n", colors[5], name); } } else if (IsEqualGUID(clsid_decoder, &CLSID_WICBmpDecoder) || - IsEqualGUID(clsid_decoder, &CLSID_WICTiffDecoder) || - IsEqualGUID(clsid_decoder, &CLSID_WICGifDecoder)) + IsEqualGUID(clsid_decoder, &CLSID_WICTiffDecoder)) { - if (IsEqualGUID(&pixelformat, &GUID_WICPixelFormatBlackWhite) || - IsEqualGUID(&pixelformat, &GUID_WICPixelFormat8bppIndexed)) + if (IsEqualGUID(dsts[i]->format, &GUID_WICPixelFormatBlackWhite) || + IsEqualGUID(dsts[i]->format, &GUID_WICPixelFormat8bppIndexed)) { ok(count == 256, "expected 256, got %u (%s)\n", count, name); @@ -1492,26 +1022,6 @@ static void test_multi_encoder(const struct bitmap_data **srcs, const CLSID* cls ok(colors[4] == 0xff555555, "got %08x (%s)\n", colors[4], name); ok(colors[5] == 0xff000000, "got %08x (%s)\n", colors[5], name); } - else if (IsEqualGUID(&pixelformat, &GUID_WICPixelFormat2bppIndexed)) - { - ok(count == 4, "expected 4, got %u (%s)\n", count, name); - - ok(colors[0] == 0xff111111, "got %08x (%s)\n", colors[0], name); - ok(colors[1] == 0xff222222, "got %08x (%s)\n", colors[1], name); - ok(colors[2] == 0xff333333, "got %08x (%s)\n", colors[2], name); - ok(colors[3] == 0xff444444, "got %08x (%s)\n", colors[3], name); - } - else if (IsEqualGUID(&pixelformat, &GUID_WICPixelFormat4bppIndexed)) - { - ok(count == 16, "expected 16, got %u (%s)\n", count, name); - - ok(colors[0] == 0xff111111, "got %08x (%s)\n", colors[0], name); - ok(colors[1] == 0xff222222, "got %08x (%s)\n", colors[1], name); - ok(colors[2] == 0xff333333, "got %08x (%s)\n", colors[2], name); - ok(colors[3] == 0xff444444, "got %08x (%s)\n", colors[3], name); - ok(colors[4] == 0xff555555, "got %08x (%s)\n", colors[4], name); - ok(colors[5] == 0xff000000, "got %08x (%s)\n", colors[5], name); - } else { ok(count == 2, "expected 2, got %u (%s)\n", count, name); @@ -1591,7 +1101,7 @@ static void test_encoder_rects(void) rc.X = 0; rc.Y = 0; - rc.Width = 32; + rc.Width = 4; rc.Height = 2; test_multi_encoder(srcs, &CLSID_WICTiffEncoder, dsts, &CLSID_WICTiffDecoder, &rc, NULL, "test_encoder_rects full", NULL); @@ -1602,7 +1112,7 @@ static void test_encoder_rects(void) rc.Width = -1; test_multi_encoder(srcs, &CLSID_WICTiffEncoder, dsts, &CLSID_WICTiffDecoder, &rc, NULL, "test_encoder_rects width=-1", NULL); - rc.Width = 32; + rc.Width = 4; rc.Height = 0; test_multi_encoder(srcs, &CLSID_WICTiffEncoder, dsts, &CLSID_WICTiffDecoder, &rc, NULL, "test_encoder_rects height=0", NULL); @@ -1624,163 +1134,6 @@ static const struct setting png_interlace_settings[] = { {NULL} }; -static void test_converter_8bppIndexed(void) -{ - HRESULT hr; - BitmapTestSrc *src_obj; - IWICFormatConverter *converter; - IWICPalette *palette; - UINT count, i; - BYTE buf[32 * 2 * 3]; /* enough to hold 32x2 24bppBGR data */ - - CreateTestBitmap(&testdata_24bppBGR, &src_obj); - - hr = IWICImagingFactory_CreatePalette(factory, &palette); - ok(hr == S_OK, "CreatePalette error %#x\n", hr); - count = 0xdeadbeef; - hr = IWICPalette_GetColorCount(palette, &count); - ok(hr == S_OK, "GetColorCount error %#x\n", hr); - ok(count == 0, "expected 0, got %u\n", count); - - /* NULL palette + Custom type*/ - hr = IWICImagingFactory_CreateFormatConverter(factory, &converter); - ok(hr == S_OK, "CreateFormatConverter error %#x\n", hr); - hr = IWICFormatConverter_Initialize(converter, &src_obj->IWICBitmapSource_iface, - &GUID_WICPixelFormat24bppBGR, WICBitmapDitherTypeNone, - NULL, 0.0, WICBitmapPaletteTypeCustom); - ok(hr == S_OK, "Initialize error %#x\n", hr); - hr = IWICFormatConverter_CopyPalette(converter, palette); - ok(hr == 0xdeadbeef, "unexpected error %#x\n", hr); - hr = IWICFormatConverter_CopyPixels(converter, NULL, 32 * 3, sizeof(buf), buf); - ok(hr == S_OK, "CopyPixels error %#x\n", hr); - IWICFormatConverter_Release(converter); - - /* NULL palette + Custom type*/ - hr = IWICImagingFactory_CreateFormatConverter(factory, &converter); - ok(hr == S_OK, "CreateFormatConverter error %#x\n", hr); - hr = IWICFormatConverter_Initialize(converter, &src_obj->IWICBitmapSource_iface, - &GUID_WICPixelFormat8bppIndexed, WICBitmapDitherTypeNone, - NULL, 0.0, WICBitmapPaletteTypeCustom); - ok(hr == E_INVALIDARG, "unexpected error %#x\n", hr); - hr = IWICFormatConverter_CopyPalette(converter, palette); - ok(hr == WINCODEC_ERR_WRONGSTATE, "unexpected error %#x\n", hr); - hr = IWICFormatConverter_CopyPixels(converter, NULL, 32, sizeof(buf), buf); - ok(hr == WINCODEC_ERR_WRONGSTATE, "unexpected error %#x\n", hr); - IWICFormatConverter_Release(converter); - - /* empty palette + Custom type*/ - hr = IWICImagingFactory_CreateFormatConverter(factory, &converter); - ok(hr == S_OK, "CreateFormatConverter error %#x\n", hr); - hr = IWICFormatConverter_Initialize(converter, &src_obj->IWICBitmapSource_iface, - &GUID_WICPixelFormat8bppIndexed, WICBitmapDitherTypeNone, - palette, 0.0, WICBitmapPaletteTypeCustom); - ok(hr == S_OK, "Initialize error %#x\n", hr); - hr = IWICFormatConverter_CopyPalette(converter, palette); - ok(hr == S_OK, "CopyPalette error %#x\n", hr); - count = 0xdeadbeef; - hr = IWICPalette_GetColorCount(palette, &count); - ok(hr == S_OK, "GetColorCount error %#x\n", hr); - ok(count == 0, "expected 0, got %u\n", count); - memset(buf, 0xaa, sizeof(buf)); - hr = IWICFormatConverter_CopyPixels(converter, NULL, 32, sizeof(buf), buf); - ok(hr == S_OK, "CopyPixels error %#x\n", hr); - count = 0; - for (i = 0; i < 32 * 2; i++) - if (buf[i] != 0) count++; - ok(count == 0, "expected 0\n"); - IWICFormatConverter_Release(converter); - - /* NULL palette + Predefined type*/ - hr = IWICImagingFactory_CreateFormatConverter(factory, &converter); - ok(hr == S_OK, "CreateFormatConverter error %#x\n", hr); - hr = IWICFormatConverter_Initialize(converter, &src_obj->IWICBitmapSource_iface, - &GUID_WICPixelFormat8bppIndexed, WICBitmapDitherTypeNone, - NULL, 0.0, WICBitmapPaletteTypeFixedGray16); - ok(hr == S_OK, "Initialize error %#x\n", hr); - hr = IWICFormatConverter_CopyPalette(converter, palette); - ok(hr == S_OK, "CopyPalette error %#x\n", hr); - count = 0xdeadbeef; - hr = IWICPalette_GetColorCount(palette, &count); - ok(hr == S_OK, "GetColorCount error %#x\n", hr); - ok(count == 16, "expected 16, got %u\n", count); - hr = IWICFormatConverter_CopyPixels(converter, NULL, 32, sizeof(buf), buf); - ok(hr == S_OK, "CopyPixels error %#x\n", hr); - count = 0; - for (i = 0; i < 32 * 2; i++) - if (buf[i] != 0) count++; - ok(count != 0, "expected != 0\n"); - IWICFormatConverter_Release(converter); - - /* not empty palette + Predefined type*/ - hr = IWICImagingFactory_CreateFormatConverter(factory, &converter); - ok(hr == S_OK, "CreateFormatConverter error %#x\n", hr); - hr = IWICFormatConverter_Initialize(converter, &src_obj->IWICBitmapSource_iface, - &GUID_WICPixelFormat8bppIndexed, WICBitmapDitherTypeNone, - palette, 0.0, WICBitmapPaletteTypeFixedHalftone64); - ok(hr == S_OK, "Initialize error %#x\n", hr); - hr = IWICFormatConverter_CopyPalette(converter, palette); - ok(hr == S_OK, "CopyPalette error %#x\n", hr); - count = 0xdeadbeef; - hr = IWICPalette_GetColorCount(palette, &count); - ok(hr == S_OK, "GetColorCount error %#x\n", hr); - ok(count == 16, "expected 16, got %u\n", count); - hr = IWICFormatConverter_CopyPixels(converter, NULL, 32, sizeof(buf), buf); - ok(hr == S_OK, "CopyPixels error %#x\n", hr); - count = 0; - for (i = 0; i < 32 * 2; i++) - if (buf[i] != 0) count++; - ok(count != 0, "expected != 0\n"); - IWICFormatConverter_Release(converter); - - /* not empty palette + MedianCut type*/ - hr = IWICImagingFactory_CreateFormatConverter(factory, &converter); - ok(hr == S_OK, "CreateFormatConverter error %#x\n", hr); - hr = IWICFormatConverter_Initialize(converter, &src_obj->IWICBitmapSource_iface, - &GUID_WICPixelFormat8bppIndexed, WICBitmapDitherTypeNone, - palette, 0.0, WICBitmapPaletteTypeMedianCut); - ok(hr == S_OK, "Initialize error %#x\n", hr); - hr = IWICFormatConverter_CopyPalette(converter, palette); - ok(hr == S_OK, "CopyPalette error %#x\n", hr); - count = 0xdeadbeef; - hr = IWICPalette_GetColorCount(palette, &count); - ok(hr == S_OK, "GetColorCount error %#x\n", hr); - ok(count == 16, "expected 16, got %u\n", count); - hr = IWICFormatConverter_CopyPixels(converter, NULL, 32, sizeof(buf), buf); - ok(hr == S_OK, "CopyPixels error %#x\n", hr); - count = 0; - for (i = 0; i < 32 * 2; i++) - if (buf[i] != 0) count++; - ok(count != 0, "expected != 0\n"); - IWICFormatConverter_Release(converter); - - /* NULL palette + MedianCut type*/ - hr = IWICImagingFactory_CreateFormatConverter(factory, &converter); - ok(hr == S_OK, "CreateFormatConverter error %#x\n", hr); - hr = IWICFormatConverter_Initialize(converter, &src_obj->IWICBitmapSource_iface, - &GUID_WICPixelFormat8bppIndexed, WICBitmapDitherTypeNone, - NULL, 0.0, WICBitmapPaletteTypeMedianCut); - ok(hr == S_OK || broken(hr == E_INVALIDARG) /* XP */, "Initialize error %#x\n", hr); - if (hr == S_OK) - { - hr = IWICFormatConverter_CopyPalette(converter, palette); - ok(hr == S_OK, "CopyPalette error %#x\n", hr); - count = 0xdeadbeef; - hr = IWICPalette_GetColorCount(palette, &count); - ok(hr == S_OK, "GetColorCount error %#x\n", hr); - ok(count == 8, "expected 8, got %u\n", count); - hr = IWICFormatConverter_CopyPixels(converter, NULL, 32, sizeof(buf), buf); - ok(hr == S_OK, "CopyPixels error %#x\n", hr); - count = 0; - for (i = 0; i < 32 * 2; i++) - if (buf[i] != 0) count++; - ok(count != 0, "expected != 0\n"); - } - IWICFormatConverter_Release(converter); - - IWICPalette_Release(palette); - DeleteTestBitmap(src_obj); -} - START_TEST(converter) { HRESULT hr; @@ -1791,27 +1144,9 @@ START_TEST(converter) &IID_IWICImagingFactory, (void **)&factory); ok(hr == S_OK, "failed to create factory: %#x\n", hr); - test_converter_8bppIndexed(); - - test_conversion(&testdata_24bppRGB, &testdata_1bppIndexed, "24bppRGB -> 1bppIndexed", TRUE); - test_conversion(&testdata_24bppRGB, &testdata_2bppIndexed, "24bppRGB -> 2bppIndexed", TRUE); - test_conversion(&testdata_24bppRGB, &testdata_4bppIndexed, "24bppRGB -> 4bppIndexed", TRUE); - test_conversion(&testdata_24bppRGB, &testdata_8bppIndexed, "24bppRGB -> 8bppIndexed", FALSE); - - test_conversion(&testdata_BlackWhite, &testdata_8bppIndexed_BW, "BlackWhite -> 8bppIndexed", TRUE); - test_conversion(&testdata_1bppIndexed, &testdata_8bppIndexed_BW, "1bppIndexed -> 8bppIndexed", TRUE); - test_conversion(&testdata_2bppIndexed, &testdata_8bppIndexed_4colors, "2bppIndexed -> 8bppIndexed", TRUE); - test_conversion(&testdata_4bppIndexed, &testdata_8bppIndexed, "4bppIndexed -> 8bppIndexed", TRUE); - test_conversion(&testdata_32bppBGRA, &testdata_32bppBGR, "BGRA -> BGR", FALSE); test_conversion(&testdata_32bppBGR, &testdata_32bppBGRA, "BGR -> BGRA", FALSE); test_conversion(&testdata_32bppBGRA, &testdata_32bppBGRA, "BGRA -> BGRA", FALSE); - test_conversion(&testdata_32bppBGRA80, &testdata_32bppPBGRA, "BGRA -> PBGRA", FALSE); - - test_conversion(&testdata_32bppRGBA, &testdata_32bppRGB, "RGBA -> RGB", FALSE); - test_conversion(&testdata_32bppRGB, &testdata_32bppRGBA, "RGB -> RGBA", FALSE); - test_conversion(&testdata_32bppRGBA, &testdata_32bppRGBA, "RGBA -> RGBA", FALSE); - test_conversion(&testdata_32bppRGBA80, &testdata_32bppPRGBA, "RGBA -> PRGBA", FALSE); test_conversion(&testdata_24bppBGR, &testdata_24bppBGR, "24bppBGR -> 24bppBGR", FALSE); test_conversion(&testdata_24bppBGR, &testdata_24bppRGB, "24bppBGR -> 24bppRGB", FALSE); @@ -1834,50 +1169,36 @@ START_TEST(converter) test_invalid_conversion(); test_default_converter(); - test_encoder(&testdata_8bppIndexed, &CLSID_WICGifEncoder, - &testdata_8bppIndexed, &CLSID_WICGifDecoder, "GIF encoder 8bppIndexed"); - test_encoder(&testdata_BlackWhite, &CLSID_WICPngEncoder, &testdata_BlackWhite, &CLSID_WICPngDecoder, "PNG encoder BlackWhite"); test_encoder(&testdata_1bppIndexed, &CLSID_WICPngEncoder, &testdata_1bppIndexed, &CLSID_WICPngDecoder, "PNG encoder 1bppIndexed"); - test_encoder(&testdata_2bppIndexed, &CLSID_WICPngEncoder, - &testdata_2bppIndexed, &CLSID_WICPngDecoder, "PNG encoder 2bppIndexed"); - test_encoder(&testdata_4bppIndexed, &CLSID_WICPngEncoder, - &testdata_4bppIndexed, &CLSID_WICPngDecoder, "PNG encoder 4bppIndexed"); test_encoder(&testdata_8bppIndexed, &CLSID_WICPngEncoder, &testdata_8bppIndexed, &CLSID_WICPngDecoder, "PNG encoder 8bppIndexed"); test_encoder(&testdata_24bppBGR, &CLSID_WICPngEncoder, &testdata_24bppBGR, &CLSID_WICPngDecoder, "PNG encoder 24bppBGR"); + if (!strcmp(winetest_platform, "windows")) /* FIXME: enable once implemented in Wine */ { - test_encoder(&testdata_32bppBGR, &CLSID_WICPngEncoder, - &testdata_24bppBGR, &CLSID_WICPngDecoder, "PNG encoder 32bppBGR"); -} - test_encoder(&testdata_BlackWhite, &CLSID_WICBmpEncoder, &testdata_1bppIndexed, &CLSID_WICBmpDecoder, "BMP encoder BlackWhite"); test_encoder(&testdata_1bppIndexed, &CLSID_WICBmpEncoder, &testdata_1bppIndexed, &CLSID_WICBmpDecoder, "BMP encoder 1bppIndexed"); - test_encoder(&testdata_2bppIndexed, &CLSID_WICBmpEncoder, - &testdata_2bppIndexed, &CLSID_WICBmpDecoder, "BMP encoder 2bppIndexed"); - test_encoder(&testdata_4bppIndexed, &CLSID_WICBmpEncoder, - &testdata_4bppIndexed, &CLSID_WICBmpDecoder, "BMP encoder 4bppIndexed"); test_encoder(&testdata_8bppIndexed, &CLSID_WICBmpEncoder, &testdata_8bppIndexed, &CLSID_WICBmpDecoder, "BMP encoder 8bppIndexed"); +} test_encoder(&testdata_32bppBGR, &CLSID_WICBmpEncoder, &testdata_32bppBGR, &CLSID_WICBmpDecoder, "BMP encoder 32bppBGR"); test_encoder(&testdata_BlackWhite, &CLSID_WICTiffEncoder, &testdata_BlackWhite, &CLSID_WICTiffDecoder, "TIFF encoder BlackWhite"); +if (!strcmp(winetest_platform, "windows")) /* FIXME: enable once implemented in Wine */ +{ test_encoder(&testdata_1bppIndexed, &CLSID_WICTiffEncoder, &testdata_1bppIndexed, &CLSID_WICTiffDecoder, "TIFF encoder 1bppIndexed"); - test_encoder(&testdata_2bppIndexed, &CLSID_WICTiffEncoder, - &testdata_2bppIndexed, &CLSID_WICTiffDecoder, "TIFF encoder 2bppIndexed"); - test_encoder(&testdata_4bppIndexed, &CLSID_WICTiffEncoder, - &testdata_4bppIndexed, &CLSID_WICTiffDecoder, "TIFF encoder 4bppIndexed"); test_encoder(&testdata_8bppIndexed, &CLSID_WICTiffEncoder, &testdata_8bppIndexed, &CLSID_WICTiffDecoder, "TIFF encoder 8bppIndexed"); +} test_encoder(&testdata_24bppBGR, &CLSID_WICTiffEncoder, &testdata_24bppBGR, &CLSID_WICTiffDecoder, "TIFF encoder 24bppBGR"); diff --git a/modules/rostests/winetests/windowscodecs/palette.c b/modules/rostests/winetests/windowscodecs/palette.c index 46d3bc8343..9031556f53 100644 --- a/modules/rostests/winetests/windowscodecs/palette.c +++ b/modules/rostests/winetests/windowscodecs/palette.c @@ -1,6 +1,6 @@ /* * Copyright 2009 Vincent Povirk for CodeWeavers - * Copyright 2012,2016 Dmitry Timoshkov + * Copyright 2012 Dmitry Timoshkov * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public @@ -19,10 +19,9 @@ #include "precomp.h" -static IWICImagingFactory *factory; - static void test_custom_palette(void) { + IWICImagingFactory *factory; IWICPalette *palette, *palette2; HRESULT hr; WICBitmapPaletteType type=0xffffffff; @@ -31,6 +30,11 @@ static void test_custom_palette(void) WICColor colors[4]; BOOL boolresult; + hr = CoCreateInstance(&CLSID_WICImagingFactory, NULL, CLSCTX_INPROC_SERVER, + &IID_IWICImagingFactory, (void**)&factory); + ok(SUCCEEDED(hr), "CoCreateInstance failed, hr=%x\n", hr); + if (FAILED(hr)) return; + hr = IWICImagingFactory_CreatePalette(factory, &palette); ok(SUCCEEDED(hr), "CreatePalette failed, hr=%x\n", hr); if (SUCCEEDED(hr)) @@ -195,6 +199,8 @@ static void test_custom_palette(void) IWICPalette_Release(palette2); IWICPalette_Release(palette); } + + IWICImagingFactory_Release(factory); } static void generate_gray16_palette(DWORD *entries, UINT count) @@ -437,6 +443,7 @@ static void test_predefined_palette(void) { WICBitmapPaletteTypeFixedHalftone256, 0, 0, 256, { 0 } }, { WICBitmapPaletteTypeFixedHalftone256, 0, 0, 256, { 0 }, 1 } }; + IWICImagingFactory *factory; IWICPalette *palette; HRESULT hr; WICBitmapPaletteType type; @@ -444,6 +451,10 @@ static void test_predefined_palette(void) BOOL bret; WICColor color[256]; + hr = CoCreateInstance(&CLSID_WICImagingFactory, NULL, CLSCTX_INPROC_SERVER, + &IID_IWICImagingFactory, (void **)&factory); + ok(hr == S_OK, "CoCreateInstance error %#x\n", hr); + hr = IWICImagingFactory_CreatePalette(factory, &palette); ok(hr == S_OK, "CreatePalette error %#x\n", hr); hr = IWICPalette_InitializePredefined(palette, WICBitmapPaletteTypeCustom, FALSE); @@ -519,136 +530,16 @@ static void test_predefined_palette(void) IWICPalette_Release(palette); } -} - -static BYTE *init_bitmap(UINT *width, UINT *height, UINT *stride) -{ - BYTE *src; - UINT i, j, scale; - - *width = 256; - *height = 256; - *stride = (*width * 3 + 3) & ~3; - trace("width %d, height %d, stride %d\n", *width, *height, *stride); - - src = HeapAlloc(GetProcessHeap(), 0, *stride * *height); - - scale = 256 / *width; - if (!scale) scale = 1; - - for (i = 0; i < *height; i++) - { - for (j = 0; j < *width; j++) - { - src[i * *stride + j*3 + 0] = scale * i; - src[i * *stride + j*3 + 1] = scale * (255 - (i+j)/2); - src[i * *stride + j*3 + 2] = scale * j; - } - } - - return src; -} - -static void test_palette_from_bitmap(void) -{ - HRESULT hr; - BYTE *data; - IWICBitmap *bitmap; - IWICPalette *palette; - WICBitmapPaletteType type; - UINT width, height, stride, count, ret; - WICColor color[257]; - - data = init_bitmap(&width, &height, &stride); - - hr = IWICImagingFactory_CreateBitmapFromMemory(factory, width, height, &GUID_WICPixelFormat24bppRGB, - stride, stride * height, data, &bitmap); - ok(hr == S_OK, "CreateBitmapFromMemory error %#x\n", hr); - - hr = IWICImagingFactory_CreatePalette(factory, &palette); - ok(hr == S_OK, "CreatePalette error %#x\n", hr); - - hr = IWICPalette_InitializeFromBitmap(palette, (IWICBitmapSource *)bitmap, 0, FALSE); - ok(hr == E_INVALIDARG, "expected E_INVALIDARG, got %#x\n", hr); - - hr = IWICPalette_InitializeFromBitmap(palette, (IWICBitmapSource *)bitmap, 1, FALSE); - ok(hr == E_INVALIDARG, "expected E_INVALIDARG, got %#x\n", hr); - - hr = IWICPalette_InitializeFromBitmap(palette, (IWICBitmapSource *)bitmap, 257, FALSE); - ok(hr == E_INVALIDARG, "expected E_INVALIDARG, got %#x\n", hr); - - hr = IWICPalette_InitializeFromBitmap(palette, NULL, 16, FALSE); - ok(hr == E_INVALIDARG, "expected E_INVALIDARG, got %#x\n", hr); - - hr = IWICPalette_InitializeFromBitmap(palette, (IWICBitmapSource *)bitmap, 2, FALSE); - ok(hr == S_OK, "InitializeFromBitmap error %#x\n", hr); - count = 0; - hr = IWICPalette_GetColorCount(palette, &count); - ok(hr == S_OK, "GetColorCount error %#x\n", hr); - ok(count == 2, "expected 2, got %u\n", count); - - hr = IWICPalette_InitializeFromBitmap(palette, (IWICBitmapSource *)bitmap, 2, TRUE); - ok(hr == S_OK, "InitializeFromBitmap error %#x\n", hr); - count = 0; - hr = IWICPalette_GetColorCount(palette, &count); - ok(hr == S_OK, "GetColorCount error %#x\n", hr); - ok(count == 2, "expected 2, got %u\n", count); - - /* without trasparent color */ - hr = IWICPalette_InitializeFromBitmap(palette, (IWICBitmapSource *)bitmap, 16, FALSE); - ok(hr == S_OK, "InitializeFromBitmap error %#x\n", hr); - type = -1; - hr = IWICPalette_GetType(palette, &type); - ok(hr == S_OK, "GetType error %#x\n", hr); - ok(type == WICBitmapPaletteTypeCustom, "expected WICBitmapPaletteTypeCustom, got %#x\n", type); - count = 0; - hr = IWICPalette_GetColorCount(palette, &count); - ok(hr == S_OK, "GetColorCount error %#x\n", hr); - ok(count == 16, "expected 16, got %u\n", count); - memset(color, 0, sizeof(color)); - hr = IWICPalette_GetColors(palette, count, color, &ret); - ok(hr == S_OK, "GetColors error %#x\n", hr); - ok(ret == count, "expected %u, got %u\n", count, ret); - ok(color[count - 1] != 0, "expected !0, got %08x\n", color[count - 1]); - - /* with trasparent color */ - hr = IWICPalette_InitializeFromBitmap(palette, (IWICBitmapSource *)bitmap, 16, TRUE); - ok(hr == S_OK, "InitializeFromBitmap error %#x\n", hr); - type = -1; - hr = IWICPalette_GetType(palette, &type); - ok(hr == S_OK, "GetType error %#x\n", hr); - ok(type == WICBitmapPaletteTypeCustom, "expected WICBitmapPaletteTypeCustom, got %#x\n", type); - count = 0; - hr = IWICPalette_GetColorCount(palette, &count); - ok(hr == S_OK, "GetColorCount error %#x\n", hr); - ok(count == 16, "expected 16, got %u\n", count); - memset(color, 0xff, sizeof(color)); - hr = IWICPalette_GetColors(palette, count, color, &ret); - ok(hr == S_OK, "GetColors error %#x\n", hr); - ok(ret == count, "expected %u, got %u\n", count, ret); - ok(color[count - 1] == 0, "expected 0, got %08x\n", color[count - 1]); - - IWICPalette_Release(palette); - IWICBitmap_Release(bitmap); - HeapFree(GetProcessHeap(), 0, data); + IWICImagingFactory_Release(factory); } START_TEST(palette) { - HRESULT hr; - CoInitializeEx(NULL, COINIT_APARTMENTTHREADED); - hr = CoCreateInstance(&CLSID_WICImagingFactory, NULL, CLSCTX_INPROC_SERVER, - &IID_IWICImagingFactory, (void **)&factory); - ok(hr == S_OK, "CoCreateInstance error %#x\n", hr); - test_custom_palette(); test_predefined_palette(); - test_palette_from_bitmap(); - - IWICImagingFactory_Release(factory); CoUninitialize(); } diff --git a/modules/rostests/winetests/windowscodecs/pngformat.c b/modules/rostests/winetests/windowscodecs/pngformat.c index 95ead41324..22f77936c7 100644 --- a/modules/rostests/winetests/windowscodecs/pngformat.c +++ b/modules/rostests/winetests/windowscodecs/pngformat.c @@ -668,11 +668,11 @@ static void test_color_formats(void) { 24, 2, NULL, NULL, NULL }, { 32, 2, NULL, NULL, NULL }, /* 0 - PNG_COLOR_TYPE_GRAY */ - { 1, 0, &GUID_WICPixelFormatBlackWhite, &GUID_WICPixelFormatBlackWhite, &GUID_WICPixelFormat1bppIndexed, TRUE }, - { 2, 0, &GUID_WICPixelFormat2bppGray, &GUID_WICPixelFormat2bppGray, &GUID_WICPixelFormat2bppIndexed, TRUE }, - { 4, 0, &GUID_WICPixelFormat4bppGray, &GUID_WICPixelFormat4bppGray, &GUID_WICPixelFormat4bppIndexed, TRUE }, - { 8, 0, &GUID_WICPixelFormat8bppGray, &GUID_WICPixelFormat8bppGray, &GUID_WICPixelFormat8bppIndexed, TRUE }, - { 16, 0, &GUID_WICPixelFormat16bppGray, &GUID_WICPixelFormat16bppGray, &GUID_WICPixelFormat64bppRGBA, TRUE }, + { 1, 0, &GUID_WICPixelFormatBlackWhite, &GUID_WICPixelFormatBlackWhite, &GUID_WICPixelFormat1bppIndexed }, + { 2, 0, &GUID_WICPixelFormat2bppGray, &GUID_WICPixelFormat2bppGray, &GUID_WICPixelFormat2bppIndexed }, + { 4, 0, &GUID_WICPixelFormat4bppGray, &GUID_WICPixelFormat4bppGray, &GUID_WICPixelFormat4bppIndexed }, + { 8, 0, &GUID_WICPixelFormat8bppGray, &GUID_WICPixelFormat8bppGray, &GUID_WICPixelFormat8bppIndexed }, + { 16, 0, &GUID_WICPixelFormat16bppGray, &GUID_WICPixelFormat16bppGray, &GUID_WICPixelFormat64bppRGBA }, { 24, 0, NULL, NULL, NULL }, { 32, 0, NULL, NULL, NULL }, /* 3 - PNG_COLOR_TYPE_PALETTE */ @@ -720,6 +720,7 @@ static void test_color_formats(void) hr = create_decoder(buf, sizeof(buf), &decoder); if (!is_valid_png_type_depth(td[i].color_type, td[i].bit_depth, TRUE)) +todo_wine ok(hr == WINCODEC_ERR_UNKNOWNIMAGEFORMAT, "%d: wrong error %#x\n", i, hr); else todo_wine_if(td[i].todo_load) @@ -748,6 +749,7 @@ next_1: hr = create_decoder(buf, sizeof(buf), &decoder); if (!is_valid_png_type_depth(td[i].color_type, td[i].bit_depth, TRUE)) +todo_wine ok(hr == WINCODEC_ERR_UNKNOWNIMAGEFORMAT, "%d: wrong error %#x\n", i, hr); else todo_wine_if(td[i].todo_load) @@ -776,6 +778,7 @@ next_2: hr = create_decoder(buf, sizeof(buf), &decoder); if (!is_valid_png_type_depth(td[i].color_type, td[i].bit_depth, FALSE)) +todo_wine ok(hr == WINCODEC_ERR_UNKNOWNIMAGEFORMAT, "%d: wrong error %#x\n", i, hr); else todo_wine_if(td[i].todo_load) @@ -803,6 +806,7 @@ next_3: hr = create_decoder(buf, sizeof(buf), &decoder); if (!is_valid_png_type_depth(td[i].color_type, td[i].bit_depth, FALSE)) +todo_wine ok(hr == WINCODEC_ERR_UNKNOWNIMAGEFORMAT, "%d: wrong error %#x\n", i, hr); else todo_wine_if(td[i].todo_load) diff --git a/modules/rostests/winetests/windowscodecs/tiffformat.c b/modules/rostests/winetests/windowscodecs/tiffformat.c index 81bd6409e0..e529a44a58 100644 --- a/modules/rostests/winetests/windowscodecs/tiffformat.c +++ b/modules/rostests/winetests/windowscodecs/tiffformat.c @@ -1,5 +1,5 @@ /* - * Copyright 2012,2016 Dmitry Timoshkov + * Copyright 2012 Dmitry Timoshkov * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public @@ -31,7 +31,7 @@ #define IFD_FLOAT 11 #define IFD_DOUBLE 12 -#include <pshpack2.h> +#include "pshpack2.h" struct IFD_entry { SHORT id; @@ -127,49 +127,6 @@ static const struct tiff_8bpp_alpha { 96, 1 }, { 0x11,0x22,0x33,0x44,0x55,0x66,0x77,0x88 } }; - -static const struct tiff_8bpp_data -{ - USHORT byte_order; - USHORT version; - ULONG dir_offset; - USHORT number_of_entries; - struct IFD_entry entry[14]; - ULONG next_IFD; - struct IFD_rational res; - short palette_data[3][256]; - BYTE pixel_data[4]; -} tiff_8bpp_data = -{ -#ifdef WORDS_BIGENDIAN - 'M' | 'M' << 8, -#else - 'I' | 'I' << 8, -#endif - 42, - FIELD_OFFSET(struct tiff_8bpp_data, number_of_entries), - 14, - { - { 0xff, IFD_SHORT, 1, 0 }, /* SUBFILETYPE */ - { 0x100, IFD_LONG, 1, 4 }, /* IMAGEWIDTH */ - { 0x101, IFD_LONG, 1, 1 }, /* IMAGELENGTH */ - { 0x102, IFD_SHORT, 1, 8 }, /* BITSPERSAMPLE: XP doesn't accept IFD_LONG here */ - { 0x103, IFD_SHORT, 1, 1 }, /* COMPRESSION: XP doesn't accept IFD_LONG here */ - { 0x106, IFD_SHORT, 1, 3 }, /* PHOTOMETRIC */ - { 0x111, IFD_LONG, 1, FIELD_OFFSET(struct tiff_8bpp_data, pixel_data) }, /* STRIPOFFSETS */ - { 0x115, IFD_SHORT, 1, 1 }, /* SAMPLESPERPIXEL */ - { 0x116, IFD_LONG, 1, 1 }, /* ROWSPERSTRIP */ - { 0x117, IFD_LONG, 1, 1 }, /* STRIPBYTECOUNT */ - { 0x11a, IFD_RATIONAL, 1, FIELD_OFFSET(struct tiff_8bpp_data, res) }, - { 0x11b, IFD_RATIONAL, 1, FIELD_OFFSET(struct tiff_8bpp_data, res) }, - { 0x128, IFD_SHORT, 1, 2 }, /* RESOLUTIONUNIT */ - { 0x140, IFD_SHORT, 256*3, FIELD_OFFSET(struct tiff_8bpp_data, palette_data) } /* COLORMAP */ - }, - 0, - { 96, 1 }, - { { 0 } }, - { 0,1,2,3 } -}; #include "poppack.h" static IWICImagingFactory *factory; @@ -195,96 +152,29 @@ static IStream *create_stream(const void *data, int data_size) return stream; } -static HRESULT create_decoder(const void *image_data, UINT image_size, IWICBitmapDecoder **decoder) +static IWICBitmapDecoder *create_decoder(const void *image_data, UINT image_size) { - HGLOBAL hmem; - BYTE *data; HRESULT hr; IStream *stream; - GUID format; - LONG refcount; - - *decoder = NULL; - - hmem = GlobalAlloc(0, image_size); - data = GlobalLock(hmem); - memcpy(data, image_data, image_size); - GlobalUnlock(hmem); + IWICBitmapDecoder *decoder = NULL; + GUID guid; - hr = CreateStreamOnHGlobal(hmem, TRUE, &stream); - ok(hr == S_OK, "CreateStreamOnHGlobal error %#x\n", hr); - - hr = IWICImagingFactory_CreateDecoderFromStream(factory, stream, NULL, 0, decoder); - if (hr == S_OK) - { - hr = IWICBitmapDecoder_GetContainerFormat(*decoder, &format); - ok(hr == S_OK, "GetContainerFormat error %#x\n", hr); - ok(IsEqualGUID(&format, &GUID_ContainerFormatTiff), - "wrong container format %s\n", wine_dbgstr_guid(&format)); + stream = create_stream(image_data, image_size); - refcount = IStream_Release(stream); - ok(refcount > 0, "expected stream refcount > 0\n"); - } - - return hr; -} - -static HRESULT get_pixelformat_info(const GUID *format, UINT *bpp, UINT *channels, BOOL *trasparency) -{ - HRESULT hr; - IWICComponentInfo *info; - IWICPixelFormatInfo2 *formatinfo; - - hr = IWICImagingFactory_CreateComponentInfo(factory, format, &info); - ok(hr == S_OK, "CreateComponentInfo(%s) error %#x\n", wine_dbgstr_guid(format), hr); - if (hr == S_OK) - { - hr = IWICComponentInfo_QueryInterface(info, &IID_IWICPixelFormatInfo2, (void **)&formatinfo); - if (hr == S_OK) - { - hr = IWICPixelFormatInfo2_SupportsTransparency(formatinfo, trasparency); - ok(hr == S_OK, "SupportsTransparency error %#x\n", hr); - IWICPixelFormatInfo2_Release(formatinfo); - } - hr = IWICComponentInfo_QueryInterface(info, &IID_IWICPixelFormatInfo, (void **)&formatinfo); - if (hr == S_OK) - { - hr = IWICPixelFormatInfo2_GetBitsPerPixel(formatinfo, bpp); - ok(hr == S_OK, "GetBitsPerPixel error %#x\n", hr); - hr = IWICPixelFormatInfo2_GetChannelCount(formatinfo, channels); - ok(hr == S_OK, "GetChannelCount error %#x\n", hr); - IWICPixelFormatInfo2_Release(formatinfo); - } - IWICComponentInfo_Release(info); - } - return hr; -} + hr = IWICImagingFactory_CreateDecoderFromStream(factory, stream, NULL, 0, &decoder); + ok(hr == S_OK, "CreateDecoderFromStream error %#x\n", hr); + if (FAILED(hr)) return NULL; -static void dump_tiff(void *buf) -{ - UINT count, i; - struct tiff_1bpp_data *tiff; - struct IFD_entry *tag; + hr = IWICBitmapDecoder_GetContainerFormat(decoder, &guid); + ok(hr == S_OK, "GetContainerFormat error %#x\n", hr); + ok(IsEqualGUID(&guid, &GUID_ContainerFormatTiff), "container format is not TIFF\n"); - tiff = buf; - count = *(short *)((char *)tiff + tiff->dir_offset); - tag = (struct IFD_entry *)((char *)tiff + tiff->dir_offset + sizeof(short)); + IStream_Release(stream); - for (i = 0; i < count; i++) - { - printf("tag %u: id %04x, type %04x, count %u, value %d", - i, tag[i].id, tag[i].type, tag[i].count, tag[i].value); - if (tag[i].id == 0x102 && tag[i].count > 2) - { - short *bps = (short *)((char *)tiff + tag[i].value); - printf(" (%d,%d,%d,%d)\n", bps[0], bps[1], bps[2], bps[3]); - } - else - printf("\n"); - } + return decoder; } -static void test_tiff_1bpp_palette(void) +static void test_tiff_palette(void) { HRESULT hr; IWICBitmapDecoder *decoder; @@ -292,9 +182,9 @@ static void test_tiff_1bpp_palette(void) IWICPalette *palette; GUID format; - hr = create_decoder(&tiff_1bpp_data, sizeof(tiff_1bpp_data), &decoder); - ok(hr == S_OK, "Failed to load TIFF image data %#x\n", hr); - if (hr != S_OK) return; + decoder = create_decoder(&tiff_1bpp_data, sizeof(tiff_1bpp_data)); + ok(decoder != 0, "Failed to load TIFF image data\n"); + if (!decoder) return; hr = IWICBitmapDecoder_GetFrame(decoder, 0, &frame); ok(hr == S_OK, "GetFrame error %#x\n", hr); @@ -426,9 +316,9 @@ static void test_tiff_8bpp_alpha(void) static const BYTE expected_data[16] = { 0x11,0x11,0x11,0x22,0x33,0x33,0x33,0x44, 0x55,0x55,0x55,0x66,0x77,0x77,0x77,0x88 }; - hr = create_decoder(&tiff_8bpp_alpha, sizeof(tiff_8bpp_alpha), &decoder); - ok(hr == S_OK, "Failed to load TIFF image data %#x\n", hr); - if (hr != S_OK) return; + decoder = create_decoder(&tiff_8bpp_alpha, sizeof(tiff_8bpp_alpha)); + ok(decoder != 0, "Failed to load TIFF image data\n"); + if (!decoder) return; hr = IWICBitmapDecoder_GetFrameCount(decoder, &frame_count); ok(hr == S_OK, "GetFrameCount error %#x\n", hr); @@ -473,464 +363,6 @@ static void test_tiff_8bpp_alpha(void) IWICBitmapDecoder_Release(decoder); } -static void generate_tiff_palette(void *buf, unsigned count) -{ - unsigned short *r, *g, *b; - unsigned i; - - r = buf; - g = r + count; - b = g + count; - - r[0] = 0x11 * 257; - g[0] = 0x22 * 257; - b[0] = 0x33 * 257; - r[1] = 0x44 * 257; - g[1] = 0x55 * 257; - b[1] = 0x66 * 257; - r[2] = 0x77 * 257; - g[2] = 0x88 * 257; - b[2] = 0x99 * 257; - r[3] = 0xa1 * 257; - g[3] = 0xb5 * 257; - b[3] = 0xff * 257; - - for (i = 4; i < count; i++) - { - r[i] = i * 257; - g[i] = (i | 0x40) * 257; - b[i] = (i | 0x80) * 257; - } -} - -static void test_tiff_8bpp_palette(void) -{ - char buf[sizeof(tiff_8bpp_data)]; - HRESULT hr; - IWICBitmapDecoder *decoder; - IWICBitmapFrameDecode *frame; - IWICPalette *palette; - GUID format; - UINT count, ret; - WICColor color[256]; - - memcpy(buf, &tiff_8bpp_data, sizeof(tiff_8bpp_data)); - generate_tiff_palette(buf + FIELD_OFFSET(struct tiff_8bpp_data, palette_data), 256); - - hr = create_decoder(buf, sizeof(buf), &decoder); - ok(hr == S_OK, "Failed to load TIFF image data %#x\n", hr); - if (hr != S_OK) return; - - hr = IWICBitmapDecoder_GetFrame(decoder, 0, &frame); - ok(hr == S_OK, "GetFrame error %#x\n", hr); - - hr = IWICBitmapFrameDecode_GetPixelFormat(frame, &format); - ok(hr == S_OK, "GetPixelFormat error %#x\n", hr); - ok(IsEqualGUID(&format, &GUID_WICPixelFormat8bppIndexed), - "expected GUID_WICPixelFormat8bppIndexed, got %s\n", wine_dbgstr_guid(&format)); - - hr = IWICImagingFactory_CreatePalette(factory, &palette); - ok(hr == S_OK, "CreatePalette error %#x\n", hr); - hr = IWICBitmapFrameDecode_CopyPalette(frame, palette); - ok(hr == S_OK, "CopyPalette error %#x\n", hr); - - hr = IWICPalette_GetColorCount(palette, &count); - ok(hr == S_OK, "GetColorCount error %#x\n", hr); - ok(count == 256, "expected 256, got %u\n", count); - - hr = IWICPalette_GetColors(palette, 256, color, &ret); - ok(hr == S_OK, "GetColors error %#x\n", hr); - ok(ret == count, "expected %u, got %u\n", count, ret); - ok(color[0] == 0xff112233, "got %#x\n", color[0]); - ok(color[1] == 0xff445566, "got %#x\n", color[1]); - ok(color[2] == 0xff778899, "got %#x\n", color[2]); - ok(color[3] == 0xffa1b5ff, "got %#x\n", color[3]); - - IWICPalette_Release(palette); - IWICBitmapFrameDecode_Release(frame); - IWICBitmapDecoder_Release(decoder); -} - -#include "pshpack2.h" -static const struct tiff_1x1_data -{ - USHORT byte_order; - USHORT version; - ULONG dir_offset; - USHORT number_of_entries; - struct IFD_entry entry[12]; - ULONG next_IFD; - struct IFD_rational res; - short palette_data[3][256]; - short bps_data[4]; - BYTE pixel_data[32]; -} tiff_1x1_data = -{ -#ifdef WORDS_BIGENDIAN - 'M' | 'M' << 8, -#else - 'I' | 'I' << 8, -#endif - 42, - FIELD_OFFSET(struct tiff_1x1_data, number_of_entries), - 12, - { - { 0xff, IFD_SHORT, 1, 0 }, /* SUBFILETYPE */ - { 0x100, IFD_LONG, 1, 1 }, /* IMAGEWIDTH */ - { 0x101, IFD_LONG, 1, 1 }, /* IMAGELENGTH */ - { 0x102, IFD_SHORT, 3, FIELD_OFFSET(struct tiff_1x1_data, bps_data) }, /* BITSPERSAMPLE */ - { 0x103, IFD_SHORT, 1, 1 }, /* COMPRESSION: XP doesn't accept IFD_LONG here */ - { 0x106, IFD_SHORT, 1, 2 }, /* PHOTOMETRIC */ - { 0x111, IFD_LONG, 1, FIELD_OFFSET(struct tiff_1x1_data, pixel_data) }, /* STRIPOFFSETS */ - { 0x115, IFD_SHORT, 1, 3 }, /* SAMPLESPERPIXEL */ - { 0x11a, IFD_RATIONAL, 1, FIELD_OFFSET(struct tiff_1x1_data, res) }, - { 0x11b, IFD_RATIONAL, 1, FIELD_OFFSET(struct tiff_1x1_data, res) }, - { 0x128, IFD_SHORT, 1, 2 }, /* RESOLUTIONUNIT */ - { 0x140, IFD_SHORT, 256*3, FIELD_OFFSET(struct tiff_1x1_data, palette_data) } /* COLORMAP */ - }, - 0, - { 96, 1 }, - { { 0 } }, - { 8,8,8,0 }, - { 1,0,2,3,4,5,6,7,8,9,0,1,2,3,4,5 } -}; -#include "poppack.h" - -static UINT width_bytes(UINT width, UINT bpp) -{ - return (width * bpp + 7) / 8; -} - -static void test_color_formats(void) -{ - struct bitmap_data - { - UINT bpp; - UINT width; - UINT height; - const WICPixelFormatGUID *format; - const BYTE *bits; - }; - static const BYTE bits_1bpsBGR[] = { 0,255,0,255,0,255,255,255,0,0,0,255,255,0,0,0,255,255,255,255,255,0,0,0,0,255,0,255,0,255 }; - static const struct bitmap_data data_1bpsBGR = - { - 24, 10, 2, &GUID_WICPixelFormat24bppBGR, bits_1bpsBGR - }; - static const BYTE bits_4bpsBGR[] = { 204,85,85,136,187,51,0,85,85,85,0,68,0,102,0,136,0,119,0,153,0 }; - static const struct bitmap_data data_4bpsBGR = - { - 24, 5, 2, &GUID_WICPixelFormat24bppBGR, bits_4bpsBGR - }; - static const BYTE bits_8bpsBGR[] = { 2,0,1,5,4,3,8,7,6 }; - static const struct bitmap_data data_8bpsBGR = - { - 24, 3, 1, &GUID_WICPixelFormat24bppBGR, bits_8bpsBGR - }; - static const BYTE bits_48bppRGB[] = { 1,0,2,3,4,5,6,7,8,9,0,1 }; - static const struct bitmap_data data_48bppRGB = - { - 48, 2, 1, &GUID_WICPixelFormat48bppRGB, bits_48bppRGB - }; - static const BYTE bits_1bpsBGRA[] = { 0,255,0,255,0,255,0,255,0,255,255,0,255,0,0,255,255,0,255,255,0,0,255,0,0,255,0,255,0,255,0,255,0,0,0,0,0,255,0,0 }; - static const struct bitmap_data data_1bpsBGRA = - { - 32, 5, 2, &GUID_WICPixelFormat32bppBGRA, bits_1bpsBGRA - }; - static const BYTE bits_4bpsBGRA[] = { 204,85,85,51,85,136,187,85,0,68,0,85,0,102,0,119,0,136,0,153,0,0,0,17,0,34,0,51 }; - static const struct bitmap_data data_4bpsBGRA = - { - 32, 5, 2, &GUID_WICPixelFormat32bppBGRA, bits_4bpsBGRA - }; - static const BYTE bits_8bpsBGRA[] = { 2,0,1,3,6,5,4,7,0,9,8,1,4,3,2,5 }; - static const struct bitmap_data data_8bpsBGRA = - { - 32, 4, 1, &GUID_WICPixelFormat32bppBGRA, bits_8bpsBGRA - }; - static const BYTE bits_64bppRGBA[] = { 1,0,2,3,4,5,6,7,8,9,0,1,2,3,4,5 }; - static const struct bitmap_data data_64bppRGBA = - { - 64, 2, 1, &GUID_WICPixelFormat64bppRGBA, bits_64bppRGBA - }; - static const BYTE bits_BlackWhite[] = { 85,195,184,85 }; - static const struct bitmap_data data_BlackWhite = - { - 1, 30, 1, &GUID_WICPixelFormatBlackWhite, bits_BlackWhite - }; - static const BYTE bits_BlackWhite_xp[] = { 85,195,184,84 }; - static const struct bitmap_data data_BlackWhite_xp = - { - 1, 30, 1, &GUID_WICPixelFormatBlackWhite, bits_BlackWhite_xp - }; - static const BYTE bits_4bppGray[] = { 85,195,184,85 }; - static const struct bitmap_data data_4bppGray = - { - 4, 7, 1, &GUID_WICPixelFormat4bppGray, bits_4bppGray - }; - static const BYTE bits_4bppGray_xp[] = { 85,195,184,80 }; - static const struct bitmap_data data_4bppGray_xp = - { - 4, 7, 1, &GUID_WICPixelFormat4bppGray, bits_4bppGray_xp - }; - static const BYTE bits_8bppGray[] = { 1,0,2,3,4,5,6,7,8,9 }; - static const struct bitmap_data data_8bppGray = - { - 8, 10, 1, &GUID_WICPixelFormat8bppGray, bits_8bppGray - }; - static const BYTE bits_16bppGray[] = { 1,0,2,3,4,5 }; - static const struct bitmap_data data_16bppGray = - { - 16, 3, 1, &GUID_WICPixelFormat16bppGray, bits_16bppGray - }; - static const BYTE bits_32bppGrayFloat[] = { 1,0,2,3,4,5,6,7,8,9,0,1 }; - static const struct bitmap_data data_32bppGrayFloat = - { - 32, 3, 1, &GUID_WICPixelFormat32bppGrayFloat, bits_32bppGrayFloat - }; -#if 0 /* FIXME */ - static const BYTE bits_96bpp3Channels[] = { 0 }; - static const struct bitmap_data data_96bpp3Channels = - { - 64, 1, 1, &GUID_WICPixelFormat96bpp3Channels, bits_96bpp3Channels - }; -#endif - static const BYTE bits_128bppRGBAFloat[] = { 1,0,2,3,4,5,6,7,8,9,0,1,2,3,4,5 }; - static const struct bitmap_data data_128bppRGBAFloat = - { - 128, 1, 1, &GUID_WICPixelFormat128bppRGBAFloat, bits_128bppRGBAFloat - }; - static const BYTE bits_1bppIndexed[] = { 85,195,184,85 }; - static const struct bitmap_data data_1bppIndexed = - { - 1, 32, 1, &GUID_WICPixelFormat1bppIndexed, bits_1bppIndexed - }; - static const BYTE bits_4bppIndexed[] = { 85,195,184,85 }; - static const struct bitmap_data data_4bppIndexed = - { - 4, 7, 1, &GUID_WICPixelFormat4bppIndexed, bits_4bppIndexed - }; - static const BYTE bits_4bppIndexed_xp[] = { 85,195,184,80 }; - static const struct bitmap_data data_4bppIndexed_xp = - { - 4, 7, 1, &GUID_WICPixelFormat4bppIndexed, bits_4bppIndexed_xp - }; - static const BYTE bits_8bppIndexed[] = { 1,0,2,3,4,5,6,7,8,9 }; - static const struct bitmap_data data_8bppIndexed = - { - 8, 3, 1, &GUID_WICPixelFormat8bppIndexed, bits_8bppIndexed - }; - static const BYTE bits_32bppCMYK[] = { 1,0,2,3,4,5,6,7,8,9,0,1 }; - static const struct bitmap_data data_32bppCMYK = - { - 32, 3, 1, &GUID_WICPixelFormat32bppCMYK, bits_32bppCMYK - }; - static const BYTE bits_64bppCMYK[] = { 1,0,2,3,4,5,6,7,8,9,0,1,2,3,4,5 }; - static const struct bitmap_data data_64bppCMYK = - { - 64, 2, 1, &GUID_WICPixelFormat64bppCMYK, bits_64bppCMYK - }; - static const struct - { - int photometric; /* PhotometricInterpretation */ - int samples; /* SamplesPerPixel */ - int bps; /* BitsPerSample */ - const struct bitmap_data *data; - const struct bitmap_data *alt_data; - } td[] = - { - /* 2 - RGB */ - { 2, 3, 1, &data_1bpsBGR }, - { 2, 3, 4, &data_4bpsBGR }, - { 2, 3, 8, &data_8bpsBGR }, - { 2, 3, 16, &data_48bppRGB }, - { 2, 3, 24, NULL }, -#if 0 /* FIXME */ - { 2, 3, 32, &data_96bpp3Channels }, -#endif - { 2, 4, 1, &data_1bpsBGRA }, - { 2, 4, 4, &data_4bpsBGRA }, - { 2, 4, 8, &data_8bpsBGRA }, - { 2, 4, 16, &data_64bppRGBA }, - { 2, 4, 24, NULL }, - { 2, 4, 32, &data_128bppRGBAFloat }, - /* 1 - BlackIsZero (Bilevel) */ - { 1, 1, 1, &data_BlackWhite, &data_BlackWhite_xp }, - { 1, 1, 4, &data_4bppGray, &data_4bppGray_xp }, - { 1, 1, 8, &data_8bppGray }, - { 1, 1, 16, &data_16bppGray }, - { 1, 1, 24, NULL }, - { 1, 1, 32, &data_32bppGrayFloat }, - /* 3 - Palette Color */ - { 3, 1, 1, &data_1bppIndexed }, - { 3, 1, 4, &data_4bppIndexed, &data_4bppIndexed_xp }, - { 3, 1, 8, &data_8bppIndexed }, -#if 0 /* FIXME: for some reason libtiff replaces photometric 3 by 1 for bps > 8 */ - { 3, 1, 16, &data_8bppIndexed }, - { 3, 1, 24, &data_8bppIndexed }, - { 3, 1, 32, &data_8bppIndexed }, -#endif - /* 5 - Separated */ - { 5, 4, 1, NULL }, - { 5, 4, 4, NULL }, - { 5, 4, 8, &data_32bppCMYK }, - { 5, 4, 16, &data_64bppCMYK }, - { 5, 4, 24, NULL }, - { 5, 4, 32, NULL }, - }; - BYTE buf[sizeof(tiff_1x1_data)]; - BYTE pixels[256]; - HRESULT hr; - IWICBitmapDecoder *decoder; - IWICBitmapFrameDecode *frame; - GUID format; - UINT count, i, bpp, channels, ret; - BOOL trasparency; - struct IFD_entry *tag, *tag_photo = NULL, *tag_bps = NULL, *tag_samples = NULL, *tag_colormap = NULL; - struct IFD_entry *tag_width = NULL, *tag_height = NULL; - short *bps; - - memcpy(buf, &tiff_1x1_data, sizeof(tiff_1x1_data)); - generate_tiff_palette(buf + FIELD_OFFSET(struct tiff_1x1_data, palette_data), 256); - - count = *(short *)(buf + tiff_1x1_data.dir_offset); - tag = (struct IFD_entry *)(buf + tiff_1x1_data.dir_offset + sizeof(short)); - - /* verify the TIFF structure */ - for (i = 0; i < count; i++) - { - if (tag[i].id == 0x100) /* ImageWidth */ - tag_width = &tag[i]; - else if (tag[i].id == 0x101) /* ImageLength */ - tag_height = &tag[i]; - else if (tag[i].id == 0x102) /* BitsPerSample */ - tag_bps = &tag[i]; - else if (tag[i].id == 0x106) /* PhotometricInterpretation */ - tag_photo = &tag[i]; - else if (tag[i].id == 0x115) /* SamplesPerPixel */ - tag_samples = &tag[i]; - else if (tag[i].id == 0x140) /* ColorMap */ - tag_colormap = &tag[i]; - } - - ok(tag_bps && tag_photo && tag_samples && tag_colormap, "tag 0x102,0x106,0x115 or 0x140 is missing\n"); - if (!tag_bps || !tag_photo || !tag_samples || !tag_colormap) return; - - ok(tag_bps->type == IFD_SHORT, "tag 0x102 should have type IFD_SHORT\n"); - bps = (short *)(buf + tag_bps->value); - ok(bps[0] == 8 && bps[1] == 8 && bps[2] == 8 && bps[3] == 0, - "expected bps 8,8,8,0 got %d,%d,%d,%d\n", bps[0], bps[1], bps[2], bps[3]); - - for (i = 0; i < sizeof(td)/sizeof(td[0]); i++) - { - if (td[i].data) - { - bpp = td[i].samples * td[i].bps; - if (winetest_debug > 1) - trace("samples %u, bps %u, bpp %u, width %u => width_bytes %u\n", td[i].samples, td[i].bps, bpp, - td[i].data->width, width_bytes(td[i].data->width, bpp)); - tag_width->value = td[i].data->width; - tag_height->value = td[i].data->height; - } - else - { - tag_width->value = 1; - tag_height->value = 1; - } - - tag_colormap->count = (1 << td[i].bps) * 3; - - if (td[i].bps < 8) - { - buf[FIELD_OFFSET(struct tiff_1x1_data, pixel_data)] = 0x55; - buf[FIELD_OFFSET(struct tiff_1x1_data, pixel_data) + 1] = 0xc3; - buf[FIELD_OFFSET(struct tiff_1x1_data, pixel_data) + 2] = 0xb8; - buf[FIELD_OFFSET(struct tiff_1x1_data, pixel_data) + 3] = 0x55; - } - else - { - buf[FIELD_OFFSET(struct tiff_1x1_data, pixel_data)] = 1; - buf[FIELD_OFFSET(struct tiff_1x1_data, pixel_data) + 1] = 0; - buf[FIELD_OFFSET(struct tiff_1x1_data, pixel_data) + 2] = 2; - buf[FIELD_OFFSET(struct tiff_1x1_data, pixel_data) + 3] = 3; - } - - tag_photo->value = td[i].photometric; - tag_bps->count = td[i].samples; - tag_samples->value = td[i].samples; - - if (td[i].samples == 1) - tag_bps->value = td[i].bps; - else if (td[i].samples == 2) - tag_bps->value = MAKELONG(td[i].bps, td[i].bps); - else if (td[i].samples == 3) - { - tag_bps->value = (BYTE *)bps - buf; - bps[0] = bps[1] = bps[2] = td[i].bps; - } - else if (td[i].samples == 4) - { - tag_bps->value = (BYTE *)bps - buf; - bps[0] = bps[1] = bps[2] = bps[3] = td[i].bps; - } - else - { - ok(0, "%u: unsupported samples count %d\n", i, td[i].samples); - continue; - } - - hr = create_decoder(buf, sizeof(buf), &decoder); - if (!td[i].data) - { - ok(hr == WINCODEC_ERR_UNSUPPORTEDPIXELFORMAT || hr == WINCODEC_ERR_COMPONENTNOTFOUND /* win8+ */ || WINCODEC_ERR_BADIMAGE /* XP */, - "%u: (%d,%d,%d) wrong error %#x\n", i, td[i].photometric, td[i].samples, td[i].bps, hr); - if (hr == S_OK) - { - IWICBitmapDecoder_Release(decoder); - dump_tiff(buf); - } - continue; - } - else - ok(hr == S_OK || broken(hr == WINCODEC_ERR_UNSUPPORTEDPIXELFORMAT || hr == WINCODEC_ERR_BADIMAGE) /* XP */, - "%u: failed to load TIFF image data (%d,%d,%d) %#x\n", - i, td[i].photometric, td[i].samples, td[i].bps, hr); - if (hr != S_OK) continue; - - hr = IWICBitmapDecoder_GetFrame(decoder, 0, &frame); - ok(hr == S_OK, "%u: GetFrame error %#x\n", i, hr); - - hr = IWICBitmapFrameDecode_GetPixelFormat(frame, &format); - ok(hr == S_OK, "%u: GetPixelFormat error %#x\n", i, hr); - ok(IsEqualGUID(&format, td[i].data->format), - "%u (%d,%d,%d): expected %s, got %s\n", - i, td[i].photometric, td[i].samples, td[i].bps, - wine_dbgstr_guid(td[i].data->format), wine_dbgstr_guid(&format)); - - trasparency = (td[i].photometric == 2 && td[i].samples == 4); /* for XP */ - hr = get_pixelformat_info(&format, &bpp, &channels, &trasparency); - ok(hr == S_OK, "%u: get_pixelformat_bpp error %#x\n", i, hr); - ok(bpp == td[i].data->bpp, "%u: expected %u, got %u\n", i, td[i].data->bpp, bpp); - ok(channels == td[i].samples, "%u: expected %u, got %u\n", i, td[i].samples, channels); - ok(trasparency == (td[i].photometric == 2 && td[i].samples == 4), "%u: got %u\n", i, trasparency); - - memset(pixels, 0, sizeof(pixels)); - hr = IWICBitmapFrameDecode_CopyPixels(frame, NULL, width_bytes(td[i].data->width, bpp), sizeof(pixels), pixels); - ok(hr == S_OK, "%u: CopyPixels error %#x\n", i, hr); - ret = memcmp(pixels, td[i].data->bits, width_bytes(td[i].data->width, bpp)); - if (ret && td[i].alt_data) - ret = memcmp(pixels, td[i].alt_data->bits, width_bytes(td[i].data->width, bpp)); - ok(ret == 0, "%u: (%d,%d,%d) wrong pixel data\n", i, td[i].photometric, td[i].samples, td[i].bps); - if (ret) - { - UINT j, n = width_bytes(td[i].data->width, bpp); - for (j = 0; j < n; j++) - printf("%u%s", pixels[j], (j + 1) < n ? "," : "\n"); - } - - IWICBitmapFrameDecode_Release(frame); - IWICBitmapDecoder_Release(decoder); - } -} - START_TEST(tiffformat) { HRESULT hr; @@ -942,9 +374,7 @@ START_TEST(tiffformat) ok(hr == S_OK, "CoCreateInstance error %#x\n", hr); if (FAILED(hr)) return; - test_color_formats(); - test_tiff_1bpp_palette(); - test_tiff_8bpp_palette(); + test_tiff_palette(); test_QueryCapability(); test_tiff_8bpp_alpha();
1
0
0
0
01/01: [WINDOWSCODECS] Sync with Wine 3.0. CORE-14225
by Amine Khaldi
20 Jan '18
20 Jan '18
https://git.reactos.org/?p=reactos.git;a=commitdiff;h=c3715ca58f21624199c9f…
commit c3715ca58f21624199c9f507840e73731887951c Author: Amine Khaldi <amine.khaldi(a)reactos.org> AuthorDate: Sat Jan 20 13:50:46 2018 +0100 Commit: Amine Khaldi <amine.khaldi(a)reactos.org> CommitDate: Sat Jan 20 13:50:46 2018 +0100 [WINDOWSCODECS] Sync with Wine 3.0. CORE-14225 --- dll/win32/windowscodecs/CMakeLists.txt | 11 +- dll/win32/windowscodecs/bitmap.c | 214 +---- dll/win32/windowscodecs/bmpdecode.c | 2 +- dll/win32/windowscodecs/bmpencode.c | 80 +- dll/win32/windowscodecs/clsfactory.c | 1 - dll/win32/windowscodecs/converter.c | 296 +----- dll/win32/windowscodecs/gifformat.c | 1015 +------------------- dll/win32/windowscodecs/imgfactory.c | 115 +-- dll/win32/windowscodecs/info.c | 20 +- dll/win32/windowscodecs/jpegformat.c | 185 ++-- dll/win32/windowscodecs/metadatahandler.c | 47 +- dll/win32/windowscodecs/palette.c | 279 +----- dll/win32/windowscodecs/pngformat.c | 182 ++-- dll/win32/windowscodecs/regsvr.c | 113 +-- dll/win32/windowscodecs/scaler.c | 169 ---- dll/win32/windowscodecs/tiffformat.c | 320 +----- dll/win32/windowscodecs/wincodecs_private.h | 78 +- dll/win32/windowscodecs/windowscodecs.spec | 3 +- dll/win32/windowscodecs/windowscodecs_wincodec.idl | 7 - media/doc/README.WINE | 2 +- 20 files changed, 417 insertions(+), 2722 deletions(-) diff --git a/dll/win32/windowscodecs/CMakeLists.txt b/dll/win32/windowscodecs/CMakeLists.txt index 227552a0b5..7ed058d112 100644 --- a/dll/win32/windowscodecs/CMakeLists.txt +++ b/dll/win32/windowscodecs/CMakeLists.txt @@ -23,6 +23,7 @@ spec2def(windowscodecs.dll windowscodecs.spec ADD_IMPORTLIB) add_rpcproxy_files(windowscodecs_wincodec.idl) list(APPEND SOURCE + bitmap.c bmpdecode.c bmpencode.c clipper.c @@ -52,16 +53,6 @@ list(APPEND SOURCE ungif.c wincodecs_private.h) -if(MSVC) - if(ARCH STREQUAL "i386") - list(APPEND SOURCE msvc-thiscall.c) - endif() - set_source_files_properties(bitmap.c PROPERTIES COMPILE_FLAGS "/FImsvc.h") - list(APPEND ADDITIONAL_SOURCE bitmap.c) -else() - list(APPEND SOURCE bitmap.c) -endif() - list(APPEND ADDITIONAL_SOURCE guid.c version.rc diff --git a/dll/win32/windowscodecs/bitmap.c b/dll/win32/windowscodecs/bitmap.c index 3d5a2bb496..dfd7dda89f 100644 --- a/dll/win32/windowscodecs/bitmap.c +++ b/dll/win32/windowscodecs/bitmap.c @@ -31,7 +31,6 @@ typedef struct BitmapImpl { int palette_set; LONG lock; /* 0 if not locked, -1 if locked for writing, count if locked for reading */ BYTE *data; - BOOL is_section; /* TRUE if data is a section created by an application */ UINT width, height; UINT stride; UINT bpp; @@ -63,13 +62,10 @@ static inline BitmapImpl *impl_from_IMILUnknown1(IMILUnknown1 *iface) return CONTAINING_RECORD(iface, BitmapImpl, IMILUnknown1_iface); } -#ifndef __REACTOS__ -/* This is currently unused */ static inline BitmapImpl *impl_from_IMILUnknown2(IMILUnknown2 *iface) { return CONTAINING_RECORD(iface, BitmapImpl, IMILUnknown2_iface); } -#endif static inline BitmapLockImpl *impl_from_IWICBitmapLock(IWICBitmapLock *iface) { @@ -125,7 +121,6 @@ static HRESULT WINAPI BitmapLockImpl_QueryInterface(IWICBitmapLock *iface, REFII } else { - FIXME("unknown interface %s\n", debugstr_guid(iid)); *ppv = NULL; return E_NOINTERFACE; } @@ -239,14 +234,12 @@ static HRESULT WINAPI BitmapImpl_QueryInterface(IWICBitmap *iface, REFIID iid, { *ppv = &This->IWICBitmap_iface; } - else if (IsEqualIID(&IID_IMILBitmap, iid) || - IsEqualIID(&IID_IMILBitmapSource, iid)) + else if (IsEqualIID(&IID_IMILBitmapSource, iid)) { *ppv = &This->IMILBitmapSource_iface; } else { - FIXME("unknown interface %s\n", debugstr_guid(iid)); *ppv = NULL; return E_NOINTERFACE; } @@ -277,10 +270,7 @@ static ULONG WINAPI BitmapImpl_Release(IWICBitmap *iface) if (This->palette) IWICPalette_Release(This->palette); This->cs.DebugInfo->Spare[0] = 0; DeleteCriticalSection(&This->cs); - if (This->is_section) - UnmapViewOfFile(This->data); - else - HeapFree(GetProcessHeap(), 0, This->data); + HeapFree(GetProcessHeap(), 0, This->data); HeapFree(GetProcessHeap(), 0, This); } @@ -475,22 +465,13 @@ static HRESULT WINAPI IMILBitmapImpl_QueryInterface(IMILBitmapSource *iface, REF if (!ppv) return E_INVALIDARG; if (IsEqualIID(&IID_IUnknown, iid) || - IsEqualIID(&IID_IMILBitmap, iid) || IsEqualIID(&IID_IMILBitmapSource, iid)) { IUnknown_AddRef(&This->IMILBitmapSource_iface); *ppv = &This->IMILBitmapSource_iface; return S_OK; } - else if (IsEqualIID(&IID_IWICBitmap, iid) || - IsEqualIID(&IID_IWICBitmapSource, iid)) - { - IUnknown_AddRef(&This->IWICBitmap_iface); - *ppv = &This->IWICBitmap_iface; - return S_OK; - } - FIXME("unknown interface %s\n", debugstr_guid(iid)); *ppv = NULL; return E_NOINTERFACE; } @@ -511,7 +492,6 @@ static HRESULT WINAPI IMILBitmapImpl_GetSize(IMILBitmapSource *iface, UINT *width, UINT *height) { BitmapImpl *This = impl_from_IMILBitmapSource(iface); - TRACE("(%p,%p,%p)\n", iface, width, height); return IWICBitmap_GetSize(&This->IWICBitmap_iface, width, height); } @@ -565,7 +545,6 @@ static HRESULT WINAPI IMILBitmapImpl_GetPixelFormat(IMILBitmapSource *iface, } } - TRACE("=> %u\n", *format); return S_OK; } @@ -573,7 +552,6 @@ static HRESULT WINAPI IMILBitmapImpl_GetResolution(IMILBitmapSource *iface, double *dpix, double *dpiy) { BitmapImpl *This = impl_from_IMILBitmapSource(iface); - TRACE("(%p,%p,%p)\n", iface, dpix, dpiy); return IWICBitmap_GetResolution(&This->IWICBitmap_iface, dpix, dpiy); } @@ -581,7 +559,6 @@ static HRESULT WINAPI IMILBitmapImpl_CopyPalette(IMILBitmapSource *iface, IWICPalette *palette) { BitmapImpl *This = impl_from_IMILBitmapSource(iface); - TRACE("(%p,%p)\n", iface, palette); return IWICBitmap_CopyPalette(&This->IWICBitmap_iface, palette); } @@ -589,11 +566,10 @@ static HRESULT WINAPI IMILBitmapImpl_CopyPixels(IMILBitmapSource *iface, const WICRect *rc, UINT stride, UINT size, BYTE *buffer) { BitmapImpl *This = impl_from_IMILBitmapSource(iface); - TRACE("(%p,%p,%u,%u,%p)\n", iface, rc, stride, size, buffer); return IWICBitmap_CopyPixels(&This->IWICBitmap_iface, rc, stride, size, buffer); } -static HRESULT WINAPI IMILBitmapImpl_unknown1(IMILBitmapSource *iface, void **ppv) +static HRESULT WINAPI IMILBitmapImpl_UnknownMethod1(IMILBitmapSource *iface, void **ppv) { BitmapImpl *This = impl_from_IMILBitmapSource(iface); @@ -601,46 +577,12 @@ static HRESULT WINAPI IMILBitmapImpl_unknown1(IMILBitmapSource *iface, void **pp if (!ppv) return E_INVALIDARG; - /* reference count is not incremented here */ + IUnknown_AddRef(&This->IMILUnknown1_iface); *ppv = &This->IMILUnknown1_iface; return S_OK; } -static HRESULT WINAPI IMILBitmapImpl_Lock(IMILBitmapSource *iface, const WICRect *rc, DWORD flags, IWICBitmapLock **lock) -{ - BitmapImpl *This = impl_from_IMILBitmapSource(iface); - TRACE("(%p,%p,%08x,%p)\n", iface, rc, flags, lock); - return IWICBitmap_Lock(&This->IWICBitmap_iface, rc, flags, lock); -} - -static HRESULT WINAPI IMILBitmapImpl_Unlock(IMILBitmapSource *iface, IWICBitmapLock *lock) -{ - TRACE("(%p,%p)\n", iface, lock); - IWICBitmapLock_Release(lock); - return S_OK; -} - -static HRESULT WINAPI IMILBitmapImpl_SetPalette(IMILBitmapSource *iface, IWICPalette *palette) -{ - BitmapImpl *This = impl_from_IMILBitmapSource(iface); - TRACE("(%p,%p)\n", iface, palette); - return IWICBitmap_SetPalette(&This->IWICBitmap_iface, palette); -} - -static HRESULT WINAPI IMILBitmapImpl_SetResolution(IMILBitmapSource *iface, double dpix, double dpiy) -{ - BitmapImpl *This = impl_from_IMILBitmapSource(iface); - TRACE("(%p,%f,%f)\n", iface, dpix, dpiy); - return IWICBitmap_SetResolution(&This->IWICBitmap_iface, dpix, dpiy); -} - -static HRESULT WINAPI IMILBitmapImpl_AddDirtyRect(IMILBitmapSource *iface, const WICRect *rc) -{ - FIXME("(%p,%p): stub\n", iface, rc); - return E_NOTIMPL; -} - static const IMILBitmapSourceVtbl IMILBitmapImpl_Vtbl = { IMILBitmapImpl_QueryInterface, @@ -651,20 +593,26 @@ static const IMILBitmapSourceVtbl IMILBitmapImpl_Vtbl = IMILBitmapImpl_GetResolution, IMILBitmapImpl_CopyPalette, IMILBitmapImpl_CopyPixels, - IMILBitmapImpl_unknown1, - IMILBitmapImpl_Lock, - IMILBitmapImpl_Unlock, - IMILBitmapImpl_SetPalette, - IMILBitmapImpl_SetResolution, - IMILBitmapImpl_AddDirtyRect + IMILBitmapImpl_UnknownMethod1, }; static HRESULT WINAPI IMILUnknown1Impl_QueryInterface(IMILUnknown1 *iface, REFIID iid, void **ppv) { - FIXME("(%p,%s,%p): stub\n", iface, debugstr_guid(iid), ppv); - *ppv = NULL; - return E_NOINTERFACE; + BitmapImpl *This = impl_from_IMILUnknown1(iface); + + TRACE("(%p,%s,%p)\n", iface, debugstr_guid(iid), ppv); + + if (!ppv) return E_INVALIDARG; + + if (IsEqualIID(&IID_IUnknown, iid)) + { + IUnknown_AddRef(&This->IMILUnknown1_iface); + *ppv = iface; + return S_OK; + } + + return IWICBitmap_QueryInterface(&This->IWICBitmap_iface, iid, ppv); } static ULONG WINAPI IMILUnknown1Impl_AddRef(IMILUnknown1 *iface) @@ -679,128 +627,66 @@ static ULONG WINAPI IMILUnknown1Impl_Release(IMILUnknown1 *iface) return IWICBitmap_Release(&This->IWICBitmap_iface); } -DECLSPEC_HIDDEN void WINAPI IMILUnknown1Impl_unknown1(IMILUnknown1 *iface, void *arg) -{ - FIXME("(%p,%p): stub\n", iface, arg); -} - -static HRESULT WINAPI IMILUnknown1Impl_unknown2(IMILUnknown1 *iface, void *arg1, void *arg2) -{ - FIXME("(%p,%p,%p): stub\n", iface, arg1, arg2); - return E_NOTIMPL; -} - -DECLSPEC_HIDDEN HRESULT WINAPI IMILUnknown1Impl_unknown3(IMILUnknown1 *iface, void *arg) -{ - FIXME("(%p,%p): stub\n", iface, arg); - return E_NOTIMPL; -} - -static HRESULT WINAPI IMILUnknown1Impl_unknown4(IMILUnknown1 *iface, void *arg) -{ - FIXME("(%p,%p): stub\n", iface, arg); - return E_NOTIMPL; -} - -static HRESULT WINAPI IMILUnknown1Impl_unknown5(IMILUnknown1 *iface, void *arg) -{ - FIXME("(%p,%p): stub\n", iface, arg); - return E_NOTIMPL; -} - -static HRESULT WINAPI IMILUnknown1Impl_unknown6(IMILUnknown1 *iface, DWORD64 arg) -{ - FIXME("(%p,%s): stub\n", iface, wine_dbgstr_longlong(arg)); - return E_NOTIMPL; -} - -static HRESULT WINAPI IMILUnknown1Impl_unknown7(IMILUnknown1 *iface, void *arg) -{ - FIXME("(%p,%p): stub\n", iface, arg); - return E_NOTIMPL; -} - -DECLSPEC_HIDDEN HRESULT WINAPI IMILUnknown1Impl_unknown8(IMILUnknown1 *iface) -{ - FIXME("(%p): stub\n", iface); - return E_NOTIMPL; -} - -DEFINE_THISCALL_WRAPPER(IMILUnknown1Impl_unknown1, 8) -DEFINE_THISCALL_WRAPPER(IMILUnknown1Impl_unknown3, 8) -DEFINE_THISCALL_WRAPPER(IMILUnknown1Impl_unknown8, 4) - static const IMILUnknown1Vtbl IMILUnknown1Impl_Vtbl = { IMILUnknown1Impl_QueryInterface, IMILUnknown1Impl_AddRef, IMILUnknown1Impl_Release, - THISCALL(IMILUnknown1Impl_unknown1), - IMILUnknown1Impl_unknown2, - THISCALL(IMILUnknown1Impl_unknown3), - IMILUnknown1Impl_unknown4, - IMILUnknown1Impl_unknown5, - IMILUnknown1Impl_unknown6, - IMILUnknown1Impl_unknown7, - THISCALL(IMILUnknown1Impl_unknown8) }; static HRESULT WINAPI IMILUnknown2Impl_QueryInterface(IMILUnknown2 *iface, REFIID iid, void **ppv) { - FIXME("(%p,%s,%p): stub\n", iface, debugstr_guid(iid), ppv); - *ppv = NULL; - return E_NOINTERFACE; + BitmapImpl *This = impl_from_IMILUnknown2(iface); + + TRACE("(%p,%s,%p)\n", iface, debugstr_guid(iid), ppv); + + if (!ppv) return E_INVALIDARG; + + if (IsEqualIID(&IID_IUnknown, iid)) + { + IUnknown_AddRef(&This->IMILUnknown2_iface); + *ppv = iface; + return S_OK; + } + + return IWICBitmap_QueryInterface(&This->IWICBitmap_iface, iid, ppv); } static ULONG WINAPI IMILUnknown2Impl_AddRef(IMILUnknown2 *iface) { - FIXME("(%p): stub\n", iface); - return 0; + BitmapImpl *This = impl_from_IMILUnknown2(iface); + return IWICBitmap_AddRef(&This->IWICBitmap_iface); } static ULONG WINAPI IMILUnknown2Impl_Release(IMILUnknown2 *iface) { - FIXME("(%p): stub\n", iface); - return 0; -} - -static HRESULT WINAPI IMILUnknown2Impl_unknown1(IMILUnknown2 *iface, void *arg1, void **arg2) -{ - FIXME("(%p,%p,%p): stub\n", iface, arg1, arg2); - if (arg2) *arg2 = NULL; - return E_NOTIMPL; + BitmapImpl *This = impl_from_IMILUnknown2(iface); + return IWICBitmap_Release(&This->IWICBitmap_iface); } -static HRESULT WINAPI IMILUnknown2Impl_unknown2(IMILUnknown2 *iface, void *arg1, void *arg2) +static HRESULT WINAPI IMILUnknown2Impl_UnknownMethod1(IMILUnknown2 *iface, void *arg1, void *arg2) { FIXME("(%p,%p,%p): stub\n", iface, arg1, arg2); return E_NOTIMPL; } -static HRESULT WINAPI IMILUnknown2Impl_unknown3(IMILUnknown2 *iface, void *arg1) -{ - FIXME("(%p,%p): stub\n", iface, arg1); - return E_NOTIMPL; -} - static const IMILUnknown2Vtbl IMILUnknown2Impl_Vtbl = { IMILUnknown2Impl_QueryInterface, IMILUnknown2Impl_AddRef, IMILUnknown2Impl_Release, - IMILUnknown2Impl_unknown1, - IMILUnknown2Impl_unknown2, - IMILUnknown2Impl_unknown3 + IMILUnknown2Impl_UnknownMethod1, }; HRESULT BitmapImpl_Create(UINT uiWidth, UINT uiHeight, - UINT stride, UINT datasize, BYTE *data, + UINT stride, UINT datasize, BYTE *bits, REFWICPixelFormatGUID pixelFormat, WICBitmapCreateCacheOption option, IWICBitmap **ppIBitmap) { HRESULT hr; BitmapImpl *This; + BYTE *data; UINT bpp; hr = get_pixelformat_bpp(pixelFormat, &bpp); @@ -813,20 +699,14 @@ HRESULT BitmapImpl_Create(UINT uiWidth, UINT uiHeight, if (stride < ((bpp*uiWidth)+7)/8) return E_INVALIDARG; This = HeapAlloc(GetProcessHeap(), 0, sizeof(BitmapImpl)); - if (!This) return E_OUTOFMEMORY; - - if (!data) + data = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, datasize); + if (!This || !data) { - data = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, datasize); - if (!data) - { - HeapFree(GetProcessHeap(), 0, This); - return E_OUTOFMEMORY; - } - This->is_section = FALSE; + HeapFree(GetProcessHeap(), 0, This); + HeapFree(GetProcessHeap(), 0, data); + return E_OUTOFMEMORY; } - else - This->is_section = TRUE; + if (bits) memcpy(data, bits, datasize); This->IWICBitmap_iface.lpVtbl = &BitmapImpl_Vtbl; This->IMILBitmapSource_iface.lpVtbl = &IMILBitmapImpl_Vtbl; diff --git a/dll/win32/windowscodecs/bmpdecode.c b/dll/win32/windowscodecs/bmpdecode.c index 395f71f1d8..5039694a76 100644 --- a/dll/win32/windowscodecs/bmpdecode.c +++ b/dll/win32/windowscodecs/bmpdecode.c @@ -256,7 +256,7 @@ static HRESULT WINAPI BmpFrameDecode_CopyPalette(IWICBitmapFrameDecode *iface, if (This->bih.bV5ClrUsed == 0) count = 1 << This->bih.bV5BitCount; else - count = min(This->bih.bV5ClrUsed, 1 << This->bih.bV5BitCount); + count = This->bih.bV5ClrUsed; tablesize = sizeof(WICColor) * count; wiccolors = HeapAlloc(GetProcessHeap(), 0, tablesize); diff --git a/dll/win32/windowscodecs/bmpencode.c b/dll/win32/windowscodecs/bmpencode.c index 5bc043a4db..e339324015 100644 --- a/dll/win32/windowscodecs/bmpencode.c +++ b/dll/win32/windowscodecs/bmpencode.c @@ -1,6 +1,5 @@ /* * Copyright 2009 Vincent Povirk for CodeWeavers - * Copyright 2016 Dmitry Timoshkov * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public @@ -24,7 +23,6 @@ struct bmp_pixelformat { const WICPixelFormatGUID *guid; UINT bpp; - UINT colors; /* palette size */ DWORD compression; DWORD redmask; DWORD greenmask; @@ -33,18 +31,13 @@ struct bmp_pixelformat { }; static const struct bmp_pixelformat formats[] = { - {&GUID_WICPixelFormat24bppBGR, 24, 0, BI_RGB}, - {&GUID_WICPixelFormatBlackWhite, 1, 2, BI_RGB}, - {&GUID_WICPixelFormat1bppIndexed, 1, 2, BI_RGB}, - {&GUID_WICPixelFormat2bppIndexed, 2, 4, BI_RGB}, - {&GUID_WICPixelFormat4bppIndexed, 4, 16, BI_RGB}, - {&GUID_WICPixelFormat8bppIndexed, 8, 256, BI_RGB}, - {&GUID_WICPixelFormat16bppBGR555, 16, 0, BI_RGB}, - {&GUID_WICPixelFormat16bppBGR565, 16, 0, BI_BITFIELDS, 0xf800, 0x7e0, 0x1f, 0}, - {&GUID_WICPixelFormat32bppBGR, 32, 0, BI_RGB}, + {&GUID_WICPixelFormat24bppBGR, 24, BI_RGB}, + {&GUID_WICPixelFormat16bppBGR555, 16, BI_RGB}, + {&GUID_WICPixelFormat16bppBGR565, 16, BI_BITFIELDS, 0xf800, 0x7e0, 0x1f, 0}, + {&GUID_WICPixelFormat32bppBGR, 32, BI_RGB}, #if 0 /* Windows doesn't seem to support this one. */ - {&GUID_WICPixelFormat32bppBGRA, 32, 0, BI_BITFIELDS, 0xff0000, 0xff00, 0xff, 0xff000000}, + {&GUID_WICPixelFormat32bppBGRA, 32, BI_BITFIELDS, 0xff0000, 0xff00, 0xff, 0xff000000}, #endif {NULL} }; @@ -172,13 +165,11 @@ static HRESULT WINAPI BmpFrameEncode_SetPixelFormat(IWICBitmapFrameEncode *iface for (i=0; formats[i].guid; i++) { - if (IsEqualGUID(formats[i].guid, pPixelFormat)) + if (memcmp(formats[i].guid, pPixelFormat, sizeof(GUID)) == 0) break; } if (!formats[i].guid) i = 0; - else if (IsEqualGUID(pPixelFormat, &GUID_WICPixelFormatBlackWhite)) - i = 2; /* GUID_WICPixelFormat1bppIndexed */ This->format = &formats[i]; memcpy(pPixelFormat, This->format->guid, sizeof(GUID)); @@ -197,7 +188,6 @@ static HRESULT WINAPI BmpFrameEncode_SetPalette(IWICBitmapFrameEncode *iface, IWICPalette *palette) { BmpFrameEncode *This = impl_from_IWICBitmapFrameEncode(iface); - HRESULT hr; TRACE("(%p,%p)\n", iface, palette); @@ -206,14 +196,7 @@ static HRESULT WINAPI BmpFrameEncode_SetPalette(IWICBitmapFrameEncode *iface, if (!This->initialized) return WINCODEC_ERR_NOTINITIALIZED; - hr = IWICPalette_GetColors(palette, 256, This->palette, &This->colors); - if (hr == S_OK) - { - UINT i; - for (i = 0; i < This->colors; i++) - This->palette[i] |= 0xff000000; /* BMP palette has no alpha */ - } - return hr; + return IWICPalette_GetColors(palette, 256, This->palette, &This->colors); } static HRESULT WINAPI BmpFrameEncode_SetThumbnail(IWICBitmapFrameEncode *iface, @@ -295,11 +278,10 @@ static HRESULT WINAPI BmpFrameEncode_Commit(IWICBitmapFrameEncode *iface) BmpFrameEncode *This = impl_from_IWICBitmapFrameEncode(iface); BITMAPFILEHEADER bfh; BITMAPV5HEADER bih; - UINT info_size, i; + UINT info_size; LARGE_INTEGER pos; ULONG byteswritten; HRESULT hr; - const BYTE *bits; TRACE("(%p)\n", iface); @@ -312,15 +294,15 @@ static HRESULT WINAPI BmpFrameEncode_Commit(IWICBitmapFrameEncode *iface) bih.bV5Size = info_size = sizeof(BITMAPINFOHEADER); bih.bV5Width = This->width; - bih.bV5Height = This->height; /* bottom-top bitmap */ + bih.bV5Height = -This->height; /* top-down bitmap */ bih.bV5Planes = 1; bih.bV5BitCount = This->format->bpp; bih.bV5Compression = This->format->compression; bih.bV5SizeImage = This->stride*This->height; bih.bV5XPelsPerMeter = (This->xres+0.0127) / 0.0254; bih.bV5YPelsPerMeter = (This->yres+0.0127) / 0.0254; - bih.bV5ClrUsed = (This->format->bpp <= 8) ? This->colors : 0; - bih.bV5ClrImportant = bih.bV5ClrUsed; + bih.bV5ClrUsed = 0; + bih.bV5ClrImportant = 0; if (This->format->compression == BI_BITFIELDS) { @@ -337,7 +319,6 @@ static HRESULT WINAPI BmpFrameEncode_Commit(IWICBitmapFrameEncode *iface) bfh.bfSize = sizeof(BITMAPFILEHEADER) + info_size + bih.bV5SizeImage; bfh.bfOffBits = sizeof(BITMAPFILEHEADER) + info_size; - bfh.bfOffBits += bih.bV5ClrUsed * sizeof(WICColor); pos.QuadPart = 0; hr = IStream_Seek(This->stream, pos, STREAM_SEEK_SET, NULL); @@ -351,23 +332,9 @@ static HRESULT WINAPI BmpFrameEncode_Commit(IWICBitmapFrameEncode *iface) if (FAILED(hr)) return hr; if (byteswritten != info_size) return E_FAIL; - /* write the palette */ - if (This->format->colors) - { - hr = IStream_Write(This->stream, This->palette, This->colors * sizeof(WICColor), &byteswritten); - if (FAILED(hr)) return hr; - if (byteswritten != This->colors * sizeof(WICColor)) return E_FAIL; - } - - /* write the image bits as a bottom-top array */ - bits = This->bits + bih.bV5SizeImage; - for (i = 0; i < This->height; i++) - { - bits -= This->stride; - hr = IStream_Write(This->stream, bits, This->stride, &byteswritten); - if (FAILED(hr)) return hr; - if (byteswritten != This->stride) return E_FAIL; - } + hr = IStream_Write(This->stream, This->bits, bih.bV5SizeImage, &byteswritten); + if (FAILED(hr)) return hr; + if (byteswritten != bih.bV5SizeImage) return E_FAIL; This->committed = TRUE; @@ -480,22 +447,11 @@ static HRESULT WINAPI BmpEncoder_GetContainerFormat(IWICBitmapEncoder *iface, return S_OK; } -static HRESULT WINAPI BmpEncoder_GetEncoderInfo(IWICBitmapEncoder *iface, IWICBitmapEncoderInfo **info) +static HRESULT WINAPI BmpEncoder_GetEncoderInfo(IWICBitmapEncoder *iface, + IWICBitmapEncoderInfo **ppIEncoderInfo) { - IWICComponentInfo *comp_info; - HRESULT hr; - - TRACE("%p,%p\n", iface, info); - - if (!info) return E_INVALIDARG; - - hr = CreateComponentInfo(&CLSID_WICBmpEncoder, &comp_info); - if (hr == S_OK) - { - hr = IWICComponentInfo_QueryInterface(comp_info, &IID_IWICBitmapEncoderInfo, (void **)info); - IWICComponentInfo_Release(comp_info); - } - return hr; + FIXME("(%p,%p): stub\n", iface, ppIEncoderInfo); + return E_NOTIMPL; } static HRESULT WINAPI BmpEncoder_SetColorContexts(IWICBitmapEncoder *iface, diff --git a/dll/win32/windowscodecs/clsfactory.c b/dll/win32/windowscodecs/clsfactory.c index 079ae762b8..2116ff9e8b 100644 --- a/dll/win32/windowscodecs/clsfactory.c +++ b/dll/win32/windowscodecs/clsfactory.c @@ -32,7 +32,6 @@ static const classinfo wic_classes[] = { {&CLSID_WICPngEncoder, PngEncoder_CreateInstance}, {&CLSID_WICBmpEncoder, BmpEncoder_CreateInstance}, {&CLSID_WICGifDecoder, GifDecoder_CreateInstance}, - {&CLSID_WICGifEncoder, GifEncoder_CreateInstance}, {&CLSID_WICIcoDecoder, IcoDecoder_CreateInstance}, {&CLSID_WICJpegDecoder, JpegDecoder_CreateInstance}, {&CLSID_WICJpegEncoder, JpegEncoder_CreateInstance}, diff --git a/dll/win32/windowscodecs/converter.c b/dll/win32/windowscodecs/converter.c index 3fca5b38f6..d6086b087a 100644 --- a/dll/win32/windowscodecs/converter.c +++ b/dll/win32/windowscodecs/converter.c @@ -40,11 +40,8 @@ enum pixelformat { format_24bppRGB, format_32bppGrayFloat, format_32bppBGR, - format_32bppRGB, format_32bppBGRA, - format_32bppRGBA, format_32bppPBGRA, - format_32bppPRGBA, format_48bppRGB, format_64bppRGBA, format_32bppCMYK, @@ -66,7 +63,7 @@ typedef struct FormatConverter { const struct pixelformatinfo *dst_format, *src_format; WICBitmapDitherType dither; double alpha_threshold; - IWICPalette *palette; + WICBitmapPaletteType palette_type; CRITICAL_SECTION lock; /* must be held when initialized */ } FormatConverter; @@ -850,27 +847,6 @@ static HRESULT copypixels_to_32bppBGRA(struct FormatConverter *This, const WICRe } } -static HRESULT copypixels_to_32bppRGBA(struct FormatConverter *This, const WICRect *prc, - UINT cbStride, UINT cbBufferSize, BYTE *pbBuffer, enum pixelformat source_format) -{ - HRESULT hr; - - switch (source_format) - { - case format_32bppRGB: - case format_32bppRGBA: - case format_32bppPRGBA: - if (prc) - return IWICBitmapSource_CopyPixels(This->source, prc, cbStride, cbBufferSize, pbBuffer); - return S_OK; - default: - hr = copypixels_to_32bppBGRA(This, prc, cbStride, cbBufferSize, pbBuffer, source_format); - if (SUCCEEDED(hr) && prc) - reverse_bgr8(4, pbBuffer, prc->Width, prc->Height, cbStride); - return hr; - } -} - static HRESULT copypixels_to_32bppBGR(struct FormatConverter *This, const WICRect *prc, UINT cbStride, UINT cbBufferSize, BYTE *pbBuffer, enum pixelformat source_format) { @@ -887,22 +863,6 @@ static HRESULT copypixels_to_32bppBGR(struct FormatConverter *This, const WICRec } } -static HRESULT copypixels_to_32bppRGB(struct FormatConverter *This, const WICRect *prc, - UINT cbStride, UINT cbBufferSize, BYTE *pbBuffer, enum pixelformat source_format) -{ - switch (source_format) - { - case format_32bppRGB: - case format_32bppRGBA: - case format_32bppPRGBA: - if (prc) - return IWICBitmapSource_CopyPixels(This->source, prc, cbStride, cbBufferSize, pbBuffer); - return S_OK; - default: - return copypixels_to_32bppRGBA(This, prc, cbStride, cbBufferSize, pbBuffer, source_format); - } -} - static HRESULT copypixels_to_32bppPBGRA(struct FormatConverter *This, const WICRect *prc, UINT cbStride, UINT cbBufferSize, BYTE *pbBuffer, enum pixelformat source_format) { @@ -936,39 +896,6 @@ static HRESULT copypixels_to_32bppPBGRA(struct FormatConverter *This, const WICR } } -static HRESULT copypixels_to_32bppPRGBA(struct FormatConverter *This, const WICRect *prc, - UINT cbStride, UINT cbBufferSize, BYTE *pbBuffer, enum pixelformat source_format) -{ - HRESULT hr; - - switch (source_format) - { - case format_32bppPRGBA: - if (prc) - return IWICBitmapSource_CopyPixels(This->source, prc, cbStride, cbBufferSize, pbBuffer); - return S_OK; - default: - hr = copypixels_to_32bppRGBA(This, prc, cbStride, cbBufferSize, pbBuffer, source_format); - if (SUCCEEDED(hr) && prc) - { - INT x, y; - - for (y=0; y<prc->Height; y++) - for (x=0; x<prc->Width; x++) - { - BYTE alpha = pbBuffer[cbStride*y+4*x+3]; - if (alpha != 255) - { - pbBuffer[cbStride*y+4*x] = pbBuffer[cbStride*y+4*x] * alpha / 255; - pbBuffer[cbStride*y+4*x+1] = pbBuffer[cbStride*y+4*x+1] * alpha / 255; - pbBuffer[cbStride*y+4*x+2] = pbBuffer[cbStride*y+4*x+2] * alpha / 255; - } - } - } - return hr; - } -} - static HRESULT copypixels_to_24bppBGR(struct FormatConverter *This, const WICRect *prc, UINT cbStride, UINT cbBufferSize, BYTE *pbBuffer, enum pixelformat source_format) { @@ -1074,48 +1001,6 @@ static HRESULT copypixels_to_24bppBGR(struct FormatConverter *This, const WICRec } return S_OK; - case format_32bppCMYK: - if (prc) - { - BYTE *srcdata; - UINT srcstride, srcdatasize; - - srcstride = 4 * prc->Width; - srcdatasize = srcstride * prc->Height; - - srcdata = HeapAlloc(GetProcessHeap(), 0, srcdatasize); - if (!srcdata) return E_OUTOFMEMORY; - - hr = IWICBitmapSource_CopyPixels(This->source, prc, srcstride, srcdatasize, srcdata); - if (SUCCEEDED(hr)) - { - INT x, y; - BYTE *src = srcdata, *dst = pbBuffer; - - for (y = 0; y < prc->Height; y++) - { - BYTE *cmyk = src; - BYTE *bgr = dst; - - for (x = 0; x < prc->Width; x++) - { - BYTE c = cmyk[0], m = cmyk[1], y = cmyk[2], k = cmyk[3]; - bgr[0] = (255 - y) * (255 - k) / 255; /* B */ - bgr[1] = (255 - m) * (255 - k) / 255; /* G */ - bgr[2] = (255 - c) * (255 - k) / 255; /* R */ - cmyk += 4; - bgr += 3; - } - src += srcstride; - dst += cbStride; - } - } - - HeapFree(GetProcessHeap(), 0, srcdata); - return hr; - } - return S_OK; - default: FIXME("Unimplemented conversion path!\n"); return WINCODEC_ERR_UNSUPPORTEDOPERATION; @@ -1323,95 +1208,11 @@ static HRESULT copypixels_to_8bppGray(struct FormatConverter *This, const WICRec return hr; } -static UINT rgb_to_palette_index(BYTE r, BYTE g, BYTE b, WICColor *colors, UINT count) -{ - UINT best_diff, best_index, i; - - best_diff = ~0; - best_index = 0; - - for (i = 0; i < count; i++) - { - BYTE pal_r, pal_g, pal_b; - DWORD diff_r, diff_g, diff_b, diff; - - pal_r = colors[i] >> 16; - pal_g = colors[i] >> 8; - pal_b = colors[i]; - - diff_r = r - pal_r; - diff_g = g - pal_g; - diff_b = b - pal_b; - - diff = diff_r * diff_r + diff_g * diff_g + diff_b * diff_b; - if (diff == 0) return i; - - if (diff < best_diff) - { - best_diff = diff; - best_index = i; - } - } - - return best_index; -} - -static HRESULT copypixels_to_8bppIndexed(struct FormatConverter *This, const WICRect *prc, - UINT cbStride, UINT cbBufferSize, BYTE *pbBuffer, enum pixelformat source_format) -{ - HRESULT hr; - BYTE *srcdata; - WICColor colors[256]; - UINT srcstride, srcdatasize, count; - - if (source_format == format_8bppIndexed) - { - if (prc) - return IWICBitmapSource_CopyPixels(This->source, prc, cbStride, cbBufferSize, pbBuffer); - - return S_OK; - } - - if (!This->palette) return WINCODEC_ERR_WRONGSTATE; - - hr = IWICPalette_GetColors(This->palette, 256, colors, &count); - if (hr != S_OK) return hr; - - srcstride = 3 * prc->Width; - srcdatasize = srcstride * prc->Height; - - srcdata = HeapAlloc(GetProcessHeap(), 0, srcdatasize); - if (!srcdata) return E_OUTOFMEMORY; - - hr = copypixels_to_24bppBGR(This, prc, srcstride, srcdatasize, srcdata, source_format); - if (SUCCEEDED(hr) && prc) - { - INT x, y; - BYTE *src = srcdata, *dst = pbBuffer; - - for (y = 0; y < prc->Height; y++) - { - BYTE *bgr = src; - - for (x = 0; x < prc->Width; x++) - { - dst[x] = rgb_to_palette_index(bgr[2], bgr[1], bgr[0], colors, count); - bgr += 3; - } - src += srcstride; - dst += cbStride; - } - } - - HeapFree(GetProcessHeap(), 0, srcdata); - return hr; -} - static const struct pixelformatinfo supported_formats[] = { {format_1bppIndexed, &GUID_WICPixelFormat1bppIndexed, NULL}, {format_2bppIndexed, &GUID_WICPixelFormat2bppIndexed, NULL}, {format_4bppIndexed, &GUID_WICPixelFormat4bppIndexed, NULL}, - {format_8bppIndexed, &GUID_WICPixelFormat8bppIndexed, copypixels_to_8bppIndexed}, + {format_8bppIndexed, &GUID_WICPixelFormat8bppIndexed, NULL}, {format_BlackWhite, &GUID_WICPixelFormatBlackWhite, NULL}, {format_2bppGray, &GUID_WICPixelFormat2bppGray, NULL}, {format_4bppGray, &GUID_WICPixelFormat4bppGray, NULL}, @@ -1424,11 +1225,8 @@ static const struct pixelformatinfo supported_formats[] = { {format_24bppRGB, &GUID_WICPixelFormat24bppRGB, copypixels_to_24bppRGB}, {format_32bppGrayFloat, &GUID_WICPixelFormat32bppGrayFloat, copypixels_to_32bppGrayFloat}, {format_32bppBGR, &GUID_WICPixelFormat32bppBGR, copypixels_to_32bppBGR}, - {format_32bppRGB, &GUID_WICPixelFormat32bppRGB, copypixels_to_32bppRGB}, {format_32bppBGRA, &GUID_WICPixelFormat32bppBGRA, copypixels_to_32bppBGRA}, - {format_32bppRGBA, &GUID_WICPixelFormat32bppRGBA, copypixels_to_32bppRGBA}, {format_32bppPBGRA, &GUID_WICPixelFormat32bppPBGRA, copypixels_to_32bppPBGRA}, - {format_32bppPRGBA, &GUID_WICPixelFormat32bppPRGBA, copypixels_to_32bppPRGBA}, {format_48bppRGB, &GUID_WICPixelFormat48bppRGB, NULL}, {format_64bppRGBA, &GUID_WICPixelFormat64bppRGBA, NULL}, {format_32bppCMYK, &GUID_WICPixelFormat32bppCMYK, NULL}, @@ -1491,7 +1289,6 @@ static ULONG WINAPI FormatConverter_Release(IWICFormatConverter *iface) This->lock.DebugInfo->Spare[0] = 0; DeleteCriticalSection(&This->lock); if (This->source) IWICBitmapSource_Release(This->source); - if (This->palette) IWICPalette_Release(This->palette); HeapFree(GetProcessHeap(), 0, This); } @@ -1540,27 +1337,10 @@ static HRESULT WINAPI FormatConverter_GetResolution(IWICFormatConverter *iface, } static HRESULT WINAPI FormatConverter_CopyPalette(IWICFormatConverter *iface, - IWICPalette *palette) + IWICPalette *pIPalette) { - FormatConverter *This = impl_from_IWICFormatConverter(iface); - - TRACE("(%p,%p)\n", iface, palette); - - if (!palette) return E_INVALIDARG; - if (!This->source) return WINCODEC_ERR_WRONGSTATE; - - if (!This->palette) - { - HRESULT hr; - UINT bpp; - - hr = get_pixelformat_bpp(This->dst_format->guid, &bpp); - if (hr != S_OK) return hr; - if (bpp <= 8) return WINCODEC_ERR_WRONGSTATE; - return IWICBitmapSource_CopyPalette(This->source, palette); - } - - return IWICPalette_InitializeFromPalette(palette, This->palette); + FIXME("(%p,%p): stub\n", iface, pIPalette); + return E_NOTIMPL; } static HRESULT WINAPI FormatConverter_CopyPixels(IWICFormatConverter *iface, @@ -1589,59 +1369,23 @@ static HRESULT WINAPI FormatConverter_CopyPixels(IWICFormatConverter *iface, pbBuffer, This->src_format->format); } else - return WINCODEC_ERR_WRONGSTATE; + return WINCODEC_ERR_NOTINITIALIZED; } static HRESULT WINAPI FormatConverter_Initialize(IWICFormatConverter *iface, - IWICBitmapSource *source, REFWICPixelFormatGUID dstFormat, WICBitmapDitherType dither, - IWICPalette *palette, double alpha_threshold, WICBitmapPaletteType palette_type) + IWICBitmapSource *pISource, REFWICPixelFormatGUID dstFormat, WICBitmapDitherType dither, + IWICPalette *pIPalette, double alphaThresholdPercent, WICBitmapPaletteType paletteTranslate) { FormatConverter *This = impl_from_IWICFormatConverter(iface); const struct pixelformatinfo *srcinfo, *dstinfo; + static INT fixme=0; GUID srcFormat; - HRESULT res; - - TRACE("(%p,%p,%s,%u,%p,%0.3f,%u)\n", iface, source, debugstr_guid(dstFormat), - dither, palette, alpha_threshold, palette_type); - - if (!palette) - { - UINT bpp; - res = get_pixelformat_bpp(dstFormat, &bpp); - if (res != S_OK) return res; - - res = PaletteImpl_Create(&palette); - if (res != S_OK) return res; - - switch (palette_type) - { - case WICBitmapPaletteTypeCustom: - IWICPalette_Release(palette); - palette = NULL; - if (bpp <= 8) return E_INVALIDARG; - break; - - case WICBitmapPaletteTypeMedianCut: - { - if (bpp <= 8) - res = IWICPalette_InitializeFromBitmap(palette, source, 1 << bpp, FALSE); - break; - } + HRESULT res=S_OK; - default: - if (bpp <= 8) - res = IWICPalette_InitializePredefined(palette, palette_type, FALSE); - break; - } + TRACE("(%p,%p,%s,%u,%p,%0.1f,%u)\n", iface, pISource, debugstr_guid(dstFormat), + dither, pIPalette, alphaThresholdPercent, paletteTranslate); - if (res != S_OK) - { - IWICPalette_Release(palette); - return res; - } - } - else - IWICPalette_AddRef(palette); + if (pIPalette && !fixme++) FIXME("ignoring palette\n"); EnterCriticalSection(&This->lock); @@ -1651,7 +1395,7 @@ static HRESULT WINAPI FormatConverter_Initialize(IWICFormatConverter *iface, goto end; } - res = IWICBitmapSource_GetPixelFormat(source, &srcFormat); + res = IWICBitmapSource_GetPixelFormat(pISource, &srcFormat); if (FAILED(res)) goto end; srcinfo = get_formatinfo(&srcFormat); @@ -1672,13 +1416,13 @@ static HRESULT WINAPI FormatConverter_Initialize(IWICFormatConverter *iface, if (dstinfo->copy_function) { - IWICBitmapSource_AddRef(source); + IWICBitmapSource_AddRef(pISource); This->src_format = srcinfo; This->dst_format = dstinfo; This->dither = dither; - This->alpha_threshold = alpha_threshold; - This->palette = palette; - This->source = source; + This->alpha_threshold = alphaThresholdPercent; + This->palette_type = paletteTranslate; + This->source = pISource; } else { @@ -1690,9 +1434,6 @@ end: LeaveCriticalSection(&This->lock); - if (res != S_OK && palette) - IWICPalette_Release(palette); - return res; } @@ -1760,7 +1501,6 @@ HRESULT FormatConverter_CreateInstance(REFIID iid, void** ppv) This->IWICFormatConverter_iface.lpVtbl = &FormatConverter_Vtbl; This->ref = 1; This->source = NULL; - This->palette = NULL; InitializeCriticalSection(&This->lock); This->lock.DebugInfo->Spare[0] = (DWORD_PTR)(__FILE__ ": FormatConverter.lock"); diff --git a/dll/win32/windowscodecs/gifformat.c b/dll/win32/windowscodecs/gifformat.c index 3a023d4963..3bc3bac409 100644 --- a/dll/win32/windowscodecs/gifformat.c +++ b/dll/win32/windowscodecs/gifformat.c @@ -1,6 +1,6 @@ /* * Copyright 2009 Vincent Povirk for CodeWeavers - * Copyright 2012,2016 Dmitry Timoshkov + * Copyright 2012 Dmitry Timoshkov * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public @@ -23,40 +23,6 @@ #include "ungif.h" -#include "pshpack1.h" - -struct logical_screen_descriptor -{ - char signature[6]; - USHORT width; - USHORT height; - BYTE packed; - /* global_color_table_flag : 1; - * color_resolution : 3; - * sort_flag : 1; - * global_color_table_size : 3; - */ - BYTE background_color_index; - BYTE pixel_aspect_ratio; -}; - -struct image_descriptor -{ - USHORT left; - USHORT top; - USHORT width; - USHORT height; - BYTE packed; - /* local_color_table_flag : 1; - * interlace_flag : 1; - * sort_flag : 1; - * reserved : 2; - * local_color_table_size : 3; - */ -}; - -#include "poppack.h" - static LPWSTR strdupAtoW(const char *src) { int len = MultiByteToWideChar(CP_ACP, 0, src, -1, NULL, 0); @@ -68,7 +34,22 @@ static LPWSTR strdupAtoW(const char *src) static HRESULT load_LSD_metadata(IStream *stream, const GUID *vendor, DWORD options, MetadataItem **items, DWORD *count) { - struct logical_screen_descriptor lsd_data; +#include "pshpack1.h" + struct logical_screen_descriptor + { + char signature[6]; + USHORT width; + USHORT height; + BYTE packed; + /* global_color_table_flag : 1; + * color_resolution : 3; + * sort_flag : 1; + * global_color_table_size : 3; + */ + BYTE background_color_index; + BYTE pixel_aspect_ratio; + } lsd_data; +#include "poppack.h" HRESULT hr; ULONG bytesread, i; MetadataItem *result; @@ -153,6 +134,23 @@ HRESULT LSDReader_CreateInstance(REFIID iid, void **ppv) return MetadataReader_Create(&LSDReader_Vtbl, iid, ppv); } +#include "pshpack1.h" +struct image_descriptor +{ + USHORT left; + USHORT top; + USHORT width; + USHORT height; + BYTE packed; + /* local_color_table_flag : 1; + * interlace_flag : 1; + * sort_flag : 1; + * reserved : 2; + * local_color_table_size : 3; + */ +}; +#include "poppack.h" + static HRESULT load_IMD_metadata(IStream *stream, const GUID *vendor, DWORD options, MetadataItem **items, DWORD *count) { @@ -1185,9 +1183,6 @@ static HRESULT WINAPI GifDecoder_CopyPalette(IWICBitmapDecoder *iface, IWICPalet TRACE("(%p,%p)\n", iface, palette); - if (!This->gif) - return WINCODEC_ERR_WRONGSTATE; - cm = This->gif->SColorMap; if (cm) { @@ -1452,945 +1447,3 @@ HRESULT GifDecoder_CreateInstance(REFIID iid, void** ppv) return ret; } - -typedef struct GifEncoder -{ - IWICBitmapEncoder IWICBitmapEncoder_iface; - LONG ref; - IStream *stream; - CRITICAL_SECTION lock; - BOOL initialized, info_written, committed; - UINT n_frames; - WICColor palette[256]; - UINT colors; -} GifEncoder; - -static inline GifEncoder *impl_from_IWICBitmapEncoder(IWICBitmapEncoder *iface) -{ - return CONTAINING_RECORD(iface, GifEncoder, IWICBitmapEncoder_iface); -} - -typedef struct GifFrameEncode -{ - IWICBitmapFrameEncode IWICBitmapFrameEncode_iface; - LONG ref; - GifEncoder *encoder; - BOOL initialized, interlace, committed; - UINT width, height, lines; - double xres, yres; - WICColor palette[256]; - UINT colors; - BYTE *image_data; -} GifFrameEncode; - -static inline GifFrameEncode *impl_from_IWICBitmapFrameEncode(IWICBitmapFrameEncode *iface) -{ - return CONTAINING_RECORD(iface, GifFrameEncode, IWICBitmapFrameEncode_iface); -} - -static HRESULT WINAPI GifFrameEncode_QueryInterface(IWICBitmapFrameEncode *iface, REFIID iid, void **ppv) -{ - TRACE("%p,%s,%p\n", iface, debugstr_guid(iid), ppv); - - if (!ppv) return E_INVALIDARG; - - if (IsEqualIID(&IID_IUnknown, iid) || - IsEqualIID(&IID_IWICBitmapFrameEncode, iid)) - { - IWICBitmapFrameEncode_AddRef(iface); - *ppv = iface; - return S_OK; - } - - *ppv = NULL; - return E_NOINTERFACE; -} - -static ULONG WINAPI GifFrameEncode_AddRef(IWICBitmapFrameEncode *iface) -{ - GifFrameEncode *This = impl_from_IWICBitmapFrameEncode(iface); - ULONG ref = InterlockedIncrement(&This->ref); - - TRACE("%p -> %u\n", iface, ref); - return ref; -} - -static ULONG WINAPI GifFrameEncode_Release(IWICBitmapFrameEncode *iface) -{ - GifFrameEncode *This = impl_from_IWICBitmapFrameEncode(iface); - ULONG ref = InterlockedDecrement(&This->ref); - - TRACE("%p -> %u\n", iface, ref); - - if (!ref) - { - IWICBitmapEncoder_Release(&This->encoder->IWICBitmapEncoder_iface); - HeapFree(GetProcessHeap(), 0, This->image_data); - HeapFree(GetProcessHeap(), 0, This); - } - - return ref; -} - -static HRESULT WINAPI GifFrameEncode_Initialize(IWICBitmapFrameEncode *iface, IPropertyBag2 *options) -{ - GifFrameEncode *This = impl_from_IWICBitmapFrameEncode(iface); - HRESULT hr; - - TRACE("%p,%p\n", iface, options); - - EnterCriticalSection(&This->encoder->lock); - - if (!This->initialized) - { - This->initialized = TRUE; - hr = S_OK; - } - else - hr = WINCODEC_ERR_WRONGSTATE; - - LeaveCriticalSection(&This->encoder->lock); - - return hr; -} - -static HRESULT WINAPI GifFrameEncode_SetSize(IWICBitmapFrameEncode *iface, UINT width, UINT height) -{ - GifFrameEncode *This = impl_from_IWICBitmapFrameEncode(iface); - HRESULT hr; - - TRACE("%p,%u,%u\n", iface, width, height); - - if (!width || !height) return E_INVALIDARG; - - EnterCriticalSection(&This->encoder->lock); - - if (This->initialized) - { - HeapFree(GetProcessHeap(), 0, This->image_data); - - This->image_data = HeapAlloc(GetProcessHeap(), 0, width * height); - if (This->image_data) - { - This->width = width; - This->height = height; - hr = S_OK; - } - else - hr = E_OUTOFMEMORY; - } - else - hr = WINCODEC_ERR_WRONGSTATE; - - LeaveCriticalSection(&This->encoder->lock); - - return hr; -} - -static HRESULT WINAPI GifFrameEncode_SetResolution(IWICBitmapFrameEncode *iface, double xres, double yres) -{ - GifFrameEncode *This = impl_from_IWICBitmapFrameEncode(iface); - HRESULT hr; - - TRACE("%p,%f,%f\n", iface, xres, yres); - - EnterCriticalSection(&This->encoder->lock); - - if (This->initialized) - { - This->xres = xres; - This->yres = yres; - hr = S_OK; - } - else - hr = WINCODEC_ERR_WRONGSTATE; - - LeaveCriticalSection(&This->encoder->lock); - - return hr; -} - -static HRESULT WINAPI GifFrameEncode_SetPixelFormat(IWICBitmapFrameEncode *iface, WICPixelFormatGUID *format) -{ - GifFrameEncode *This = impl_from_IWICBitmapFrameEncode(iface); - HRESULT hr; - - TRACE("%p,%s\n", iface, debugstr_guid(format)); - - if (!format) return E_INVALIDARG; - - EnterCriticalSection(&This->encoder->lock); - - if (This->initialized) - { - *format = GUID_WICPixelFormat8bppIndexed; - hr = S_OK; - } - else - hr = WINCODEC_ERR_WRONGSTATE; - - LeaveCriticalSection(&This->encoder->lock); - - return hr; -} - -static HRESULT WINAPI GifFrameEncode_SetColorContexts(IWICBitmapFrameEncode *iface, UINT count, IWICColorContext **context) -{ - FIXME("%p,%u,%p: stub\n", iface, count, context); - return E_NOTIMPL; -} - -static HRESULT WINAPI GifFrameEncode_SetPalette(IWICBitmapFrameEncode *iface, IWICPalette *palette) -{ - GifFrameEncode *This = impl_from_IWICBitmapFrameEncode(iface); - HRESULT hr; - - TRACE("%p,%p\n", iface, palette); - - if (!palette) return E_INVALIDARG; - - EnterCriticalSection(&This->encoder->lock); - - if (This->initialized) - hr = IWICPalette_GetColors(palette, 256, This->palette, &This->colors); - else - hr = WINCODEC_ERR_NOTINITIALIZED; - - LeaveCriticalSection(&This->encoder->lock); - return hr; -} - -static HRESULT WINAPI GifFrameEncode_SetThumbnail(IWICBitmapFrameEncode *iface, IWICBitmapSource *thumbnail) -{ - FIXME("%p,%p: stub\n", iface, thumbnail); - return E_NOTIMPL; -} - -static HRESULT WINAPI GifFrameEncode_WritePixels(IWICBitmapFrameEncode *iface, UINT lines, UINT stride, UINT size, BYTE *pixels) -{ - GifFrameEncode *This = impl_from_IWICBitmapFrameEncode(iface); - HRESULT hr; - - TRACE("%p,%u,%u,%u,%p\n", iface, lines, stride, size, pixels); - - if (!pixels) return E_INVALIDARG; - - EnterCriticalSection(&This->encoder->lock); - - if (This->initialized && This->image_data) - { - if (This->lines + lines <= This->height) - { - UINT i; - BYTE *src, *dst; - - src = pixels; - dst = This->image_data + This->lines * This->width; - - for (i = 0; i < lines; i++) - { - memcpy(dst, src, This->width); - src += stride; - dst += This->width; - } - - This->lines += lines; - hr = S_OK; - } - else - hr = E_INVALIDARG; - } - else - hr = WINCODEC_ERR_WRONGSTATE; - - LeaveCriticalSection(&This->encoder->lock); - return hr; -} - -static HRESULT WINAPI GifFrameEncode_WriteSource(IWICBitmapFrameEncode *iface, IWICBitmapSource *source, WICRect *rc) -{ - GifFrameEncode *This = impl_from_IWICBitmapFrameEncode(iface); - HRESULT hr; - - TRACE("%p,%p,%p\n", iface, source, rc); - - if (!source) return E_INVALIDARG; - - EnterCriticalSection(&This->encoder->lock); - - if (This->initialized) - { - const GUID *format = &GUID_WICPixelFormat8bppIndexed; - - hr = configure_write_source(iface, source, rc, format, - This->width, This->height, This->xres, This->yres); - if (hr == S_OK) - hr = write_source(iface, source, rc, format, 8, This->width, This->height); - } - else - hr = WINCODEC_ERR_WRONGSTATE; - - LeaveCriticalSection(&This->encoder->lock); - return hr; -} - -#define LZW_DICT_SIZE (1 << 12) - -struct lzw_dict -{ - short prefix[LZW_DICT_SIZE]; - unsigned char suffix[LZW_DICT_SIZE]; -}; - -struct lzw_state -{ - struct lzw_dict dict; - short init_code_bits, code_bits, next_code, clear_code, eof_code; - unsigned bits_buf; - int bits_count; - int (*user_write_data)(void *user_ptr, void *data, int length); - void *user_ptr; -}; - -struct input_stream -{ - unsigned len; - const BYTE *in; -}; - -struct output_stream -{ - struct - { - unsigned char len; - char data[255]; - } gif_block; - IStream *out; -}; - -static int lzw_output_code(struct lzw_state *state, short code) -{ - state->bits_buf |= code << state->bits_count; - state->bits_count += state->code_bits; - - while (state->bits_count >= 8) - { - unsigned char byte = (unsigned char)state->bits_buf; - if (state->user_write_data(state->user_ptr, &byte, 1) != 1) - return 0; - state->bits_buf >>= 8; - state->bits_count -= 8; - } - - return 1; -} - -static inline int lzw_output_clear_code(struct lzw_state *state) -{ - return lzw_output_code(state, state->clear_code); -} - -static inline int lzw_output_eof_code(struct lzw_state *state) -{ - return lzw_output_code(state, state->eof_code); -} - -static int lzw_flush_bits(struct lzw_state *state) -{ - unsigned char byte; - - while (state->bits_count >= 8) - { - byte = (unsigned char)state->bits_buf; - if (state->user_write_data(state->user_ptr, &byte, 1) != 1) - return 0; - state->bits_buf >>= 8; - state->bits_count -= 8; - } - - if (state->bits_count) - { - static const char mask[8] = { 0x00,0x01,0x03,0x07,0x0f,0x1f,0x3f,0x7f }; - - byte = (unsigned char)state->bits_buf & mask[state->bits_count]; - if (state->user_write_data(state->user_ptr, &byte, 1) != 1) - return 0; - } - - state->bits_buf = 0; - state->bits_count = 0; - - return 1; -} - -static void lzw_dict_reset(struct lzw_state *state) -{ - int i; - - state->code_bits = state->init_code_bits + 1; - state->next_code = (1 << state->init_code_bits) + 2; - - for(i = 0; i < LZW_DICT_SIZE; i++) - { - state->dict.prefix[i] = 1 << 12; /* impossible LZW code value */ - state->dict.suffix[i] = 0; - } -} - -static void lzw_state_init(struct lzw_state *state, short init_code_bits, void *user_write_data, void *user_ptr) -{ - state->init_code_bits = init_code_bits; - state->clear_code = 1 << init_code_bits; - state->eof_code = state->clear_code + 1; - state->bits_buf = 0; - state->bits_count = 0; - state->user_write_data = user_write_data; - state->user_ptr = user_ptr; - - lzw_dict_reset(state); -} - -static int lzw_dict_add(struct lzw_state *state, short prefix, unsigned char suffix) -{ - if (state->next_code < LZW_DICT_SIZE) - { - state->dict.prefix[state->next_code] = prefix; - state->dict.suffix[state->next_code] = suffix; - - if ((state->next_code & (state->next_code - 1)) == 0) - state->code_bits++; - - state->next_code++; - return state->next_code; - } - - return -1; -} - -static short lzw_dict_lookup(const struct lzw_state *state, short prefix, unsigned char suffix) -{ - short i; - - for (i = 0; i < state->next_code; i++) - { - if (state->dict.prefix[i] == prefix && state->dict.suffix[i] == suffix) - return i; - } - - return -1; -} - -static inline int write_byte(struct output_stream *out, char byte) -{ - if (out->gif_block.len == 255) - { - if (IStream_Write(out->out, &out->gif_block, sizeof(out->gif_block), NULL) != S_OK) - return 0; - - out->gif_block.len = 0; - } - - out->gif_block.data[out->gif_block.len++] = byte; - - return 1; -} - -static int write_data(void *user_ptr, void *user_data, int length) -{ - unsigned char *data = user_data; - struct output_stream *out = user_ptr; - int len = length; - - while (len-- > 0) - { - if (!write_byte(out, *data++)) return 0; - } - - return length; -} - -static int flush_output_data(void *user_ptr) -{ - struct output_stream *out = user_ptr; - - if (out->gif_block.len) - { - if (IStream_Write(out->out, &out->gif_block, out->gif_block.len + sizeof(out->gif_block.len), NULL) != S_OK) - return 0; - } - - /* write GIF block terminator */ - out->gif_block.len = 0; - return IStream_Write(out->out, &out->gif_block, sizeof(out->gif_block.len), NULL) == S_OK; -} - -static inline int read_byte(struct input_stream *in, unsigned char *byte) -{ - if (in->len) - { - in->len--; - *byte = *in->in++; - return 1; - } - - return 0; -} - -static HRESULT gif_compress(IStream *out_stream, const BYTE *in_data, ULONG in_size) -{ - struct input_stream in; - struct output_stream out; - struct lzw_state state; - short init_code_bits, prefix, code; - unsigned char suffix; - - in.in = in_data; - in.len = in_size; - - out.gif_block.len = 0; - out.out = out_stream; - - init_code_bits = suffix = 8; - if (IStream_Write(out.out, &suffix, sizeof(suffix), NULL) != S_OK) - return E_FAIL; - - lzw_state_init(&state, init_code_bits, write_data, &out); - - if (!lzw_output_clear_code(&state)) - return E_FAIL; - - if (read_byte(&in, &suffix)) - { - prefix = suffix; - - while (read_byte(&in, &suffix)) - { - code = lzw_dict_lookup(&state, prefix, suffix); - if (code == -1) - { - if (!lzw_output_code(&state, prefix)) - return E_FAIL; - - if (lzw_dict_add(&state, prefix, suffix) == -1) - { - if (!lzw_output_clear_code(&state)) - return E_FAIL; - lzw_dict_reset(&state); - } - - prefix = suffix; - } - else - prefix = code; - } - - if (!lzw_output_code(&state, prefix)) - return E_FAIL; - if (!lzw_output_eof_code(&state)) - return E_FAIL; - if (!lzw_flush_bits(&state)) - return E_FAIL; - } - - return flush_output_data(&out) ? S_OK : E_FAIL; -} - -static HRESULT WINAPI GifFrameEncode_Commit(IWICBitmapFrameEncode *iface) -{ - GifFrameEncode *This = impl_from_IWICBitmapFrameEncode(iface); - HRESULT hr; - - TRACE("%p\n", iface); - - EnterCriticalSection(&This->encoder->lock); - - if (This->image_data && This->lines == This->height && !This->committed) - { - BYTE gif_palette[256][3]; - - hr = S_OK; - - if (!This->encoder->info_written) - { - struct logical_screen_descriptor lsd; - - /* Logical Screen Descriptor */ - memcpy(lsd.signature, "GIF89a", 6); - lsd.width = This->width; - lsd.height = This->height; - lsd.packed = 0; - if (This->encoder->colors) - lsd.packed |= 0x80; /* global color table flag */ - lsd.packed |= 0x07 << 4; /* color resolution */ - lsd.packed |= 0x07; /* global color table size */ - lsd.background_color_index = 0; /* FIXME */ - lsd.pixel_aspect_ratio = 0; - hr = IStream_Write(This->encoder->stream, &lsd, sizeof(lsd), NULL); - if (hr == S_OK && This->encoder->colors) - { - UINT i; - - /* Global Color Table */ - memset(gif_palette, 0, sizeof(gif_palette)); - for (i = 0; i < This->encoder->colors; i++) - { - gif_palette[i][0] = (This->encoder->palette[i] >> 16) & 0xff; - gif_palette[i][1] = (This->encoder->palette[i] >> 8) & 0xff; - gif_palette[i][2] = This->encoder->palette[i] & 0xff; - } - hr = IStream_Write(This->encoder->stream, gif_palette, sizeof(gif_palette), NULL); - } - - /* FIXME: write GCE, APE, etc. GIF extensions */ - - if (hr == S_OK) - This->encoder->info_written = TRUE; - } - - if (hr == S_OK) - { - char image_separator = 0x2c; - - hr = IStream_Write(This->encoder->stream, &image_separator, sizeof(image_separator), NULL); - if (hr == S_OK) - { - struct image_descriptor imd; - - /* Image Descriptor */ - imd.left = 0; - imd.top = 0; - imd.width = This->width; - imd.height = This->height; - imd.packed = 0; - if (This->colors) - { - imd.packed |= 0x80; /* local color table flag */ - imd.packed |= 0x07; /* local color table size */ - } - /* FIXME: interlace flag */ - hr = IStream_Write(This->encoder->stream, &imd, sizeof(imd), NULL); - if (hr == S_OK && This->colors) - { - UINT i; - - /* Local Color Table */ - memset(gif_palette, 0, sizeof(gif_palette)); - for (i = 0; i < This->colors; i++) - { - gif_palette[i][0] = (This->palette[i] >> 16) & 0xff; - gif_palette[i][1] = (This->palette[i] >> 8) & 0xff; - gif_palette[i][2] = This->palette[i] & 0xff; - } - hr = IStream_Write(This->encoder->stream, gif_palette, sizeof(gif_palette), NULL); - if (hr == S_OK) - { - /* Image Data */ - hr = gif_compress(This->encoder->stream, This->image_data, This->width * This->height); - if (hr == S_OK) - This->committed = TRUE; - } - } - } - } - } - else - hr = WINCODEC_ERR_WRONGSTATE; - - LeaveCriticalSection(&This->encoder->lock); - return hr; -} - -static HRESULT WINAPI GifFrameEncode_GetMetadataQueryWriter(IWICBitmapFrameEncode *iface, IWICMetadataQueryWriter **writer) -{ - FIXME("%p, %p: stub\n", iface, writer); - return E_NOTIMPL; -} - -static const IWICBitmapFrameEncodeVtbl GifFrameEncode_Vtbl = -{ - GifFrameEncode_QueryInterface, - GifFrameEncode_AddRef, - GifFrameEncode_Release, - GifFrameEncode_Initialize, - GifFrameEncode_SetSize, - GifFrameEncode_SetResolution, - GifFrameEncode_SetPixelFormat, - GifFrameEncode_SetColorContexts, - GifFrameEncode_SetPalette, - GifFrameEncode_SetThumbnail, - GifFrameEncode_WritePixels, - GifFrameEncode_WriteSource, - GifFrameEncode_Commit, - GifFrameEncode_GetMetadataQueryWriter -}; - -static HRESULT WINAPI GifEncoder_QueryInterface(IWICBitmapEncoder *iface, REFIID iid, void **ppv) -{ - TRACE("%p,%s,%p\n", iface, debugstr_guid(iid), ppv); - - if (!ppv) return E_INVALIDARG; - - if (IsEqualIID(&IID_IUnknown, iid) || - IsEqualIID(&IID_IWICBitmapEncoder, iid)) - { - IWICBitmapEncoder_AddRef(iface); - *ppv = iface; - return S_OK; - } - - *ppv = NULL; - return E_NOINTERFACE; -} - -static ULONG WINAPI GifEncoder_AddRef(IWICBitmapEncoder *iface) -{ - GifEncoder *This = impl_from_IWICBitmapEncoder(iface); - ULONG ref = InterlockedIncrement(&This->ref); - - TRACE("%p -> %u\n", iface, ref); - return ref; -} - -static ULONG WINAPI GifEncoder_Release(IWICBitmapEncoder *iface) -{ - GifEncoder *This = impl_from_IWICBitmapEncoder(iface); - ULONG ref = InterlockedDecrement(&This->ref); - - TRACE("%p -> %u\n", iface, ref); - - if (!ref) - { - if (This->stream) IStream_Release(This->stream); - This->lock.DebugInfo->Spare[0] = 0; - DeleteCriticalSection(&This->lock); - HeapFree(GetProcessHeap(), 0, This); - } - - return ref; -} - -static HRESULT WINAPI GifEncoder_Initialize(IWICBitmapEncoder *iface, IStream *stream, WICBitmapEncoderCacheOption option) -{ - GifEncoder *This = impl_from_IWICBitmapEncoder(iface); - HRESULT hr; - - TRACE("%p,%p,%#x\n", iface, stream, option); - - if (!stream) return E_INVALIDARG; - - EnterCriticalSection(&This->lock); - - if (!This->initialized) - { - IStream_AddRef(stream); - This->stream = stream; - This->initialized = TRUE; - hr = S_OK; - } - else - hr = WINCODEC_ERR_WRONGSTATE; - - LeaveCriticalSection(&This->lock); - - return hr; -} - -static HRESULT WINAPI GifEncoder_GetContainerFormat(IWICBitmapEncoder *iface, GUID *format) -{ - if (!format) return E_INVALIDARG; - - *format = GUID_ContainerFormatGif; - return S_OK; -} - -static HRESULT WINAPI GifEncoder_GetEncoderInfo(IWICBitmapEncoder *iface, IWICBitmapEncoderInfo **info) -{ - IWICComponentInfo *comp_info; - HRESULT hr; - - TRACE("%p,%p\n", iface, info); - - if (!info) return E_INVALIDARG; - - hr = CreateComponentInfo(&CLSID_WICGifEncoder, &comp_info); - if (hr == S_OK) - { - hr = IWICComponentInfo_QueryInterface(comp_info, &IID_IWICBitmapEncoderInfo, (void **)info); - IWICComponentInfo_Release(comp_info); - } - return hr; -} - -static HRESULT WINAPI GifEncoder_SetColorContexts(IWICBitmapEncoder *iface, UINT count, IWICColorContext **context) -{ - FIXME("%p,%u,%p: stub\n", iface, count, context); - return E_NOTIMPL; -} - -static HRESULT WINAPI GifEncoder_SetPalette(IWICBitmapEncoder *iface, IWICPalette *palette) -{ - GifEncoder *This = impl_from_IWICBitmapEncoder(iface); - HRESULT hr; - - TRACE("%p,%p\n", iface, palette); - - if (!palette) return E_INVALIDARG; - - EnterCriticalSection(&This->lock); - - if (This->initialized) - hr = IWICPalette_GetColors(palette, 256, This->palette, &This->colors); - else - hr = WINCODEC_ERR_NOTINITIALIZED; - - LeaveCriticalSection(&This->lock); - return hr; -} - -static HRESULT WINAPI GifEncoder_SetThumbnail(IWICBitmapEncoder *iface, IWICBitmapSource *thumbnail) -{ - TRACE("%p,%p\n", iface, thumbnail); - return WINCODEC_ERR_UNSUPPORTEDOPERATION; -} - -static HRESULT WINAPI GifEncoder_SetPreview(IWICBitmapEncoder *iface, IWICBitmapSource *preview) -{ - TRACE("%p,%p\n", iface, preview); - return WINCODEC_ERR_UNSUPPORTEDOPERATION; -} - -static HRESULT WINAPI GifEncoder_CreateNewFrame(IWICBitmapEncoder *iface, IWICBitmapFrameEncode **frame, IPropertyBag2 **options) -{ - GifEncoder *This = impl_from_IWICBitmapEncoder(iface); - HRESULT hr; - - TRACE("%p,%p,%p\n", iface, frame, options); - - if (!frame) return E_INVALIDARG; - - EnterCriticalSection(&This->lock); - - if (This->initialized && !This->committed) - { - GifFrameEncode *ret = HeapAlloc(GetProcessHeap(), 0, sizeof(*ret)); - if (ret) - { - This->n_frames++; - - ret->IWICBitmapFrameEncode_iface.lpVtbl = &GifFrameEncode_Vtbl; - ret->ref = 1; - ret->encoder = This; - ret->initialized = FALSE; - ret->interlace = FALSE; /* FIXME: read from the properties */ - ret->committed = FALSE; - ret->width = 0; - ret->height = 0; - ret->lines = 0; - ret->xres = 0.0; - ret->yres = 0.0; - ret->colors = 0; - ret->image_data = NULL; - IWICBitmapEncoder_AddRef(iface); - *frame = &ret->IWICBitmapFrameEncode_iface; - - hr = S_OK; - - if (options) - { - hr = CreatePropertyBag2(NULL, 0, options); - if (hr != S_OK) - { - IWICBitmapFrameEncode_Release(*frame); - *frame = NULL; - } - } - } - else - hr = E_OUTOFMEMORY; - } - else - hr = WINCODEC_ERR_WRONGSTATE; - - LeaveCriticalSection(&This->lock); - - return hr; - -} - -static HRESULT WINAPI GifEncoder_Commit(IWICBitmapEncoder *iface) -{ - GifEncoder *This = impl_from_IWICBitmapEncoder(iface); - HRESULT hr; - - TRACE("%p\n", iface); - - EnterCriticalSection(&This->lock); - - if (This->initialized && !This->committed) - { - char gif_trailer = 0x3b; - - /* FIXME: write text, comment GIF extensions */ - - hr = IStream_Write(This->stream, &gif_trailer, sizeof(gif_trailer), NULL); - if (hr == S_OK) - This->committed = TRUE; - } - else - hr = WINCODEC_ERR_WRONGSTATE; - - LeaveCriticalSection(&This->lock); - return hr; -} - -static HRESULT WINAPI GifEncoder_GetMetadataQueryWriter(IWICBitmapEncoder *iface, IWICMetadataQueryWriter **writer) -{ - FIXME("%p,%p: stub\n", iface, writer); - return E_NOTIMPL; -} - -static const IWICBitmapEncoderVtbl GifEncoder_Vtbl = -{ - GifEncoder_QueryInterface, - GifEncoder_AddRef, - GifEncoder_Release, - GifEncoder_Initialize, - GifEncoder_GetContainerFormat, - GifEncoder_GetEncoderInfo, - GifEncoder_SetColorContexts, - GifEncoder_SetPalette, - GifEncoder_SetThumbnail, - GifEncoder_SetPreview, - GifEncoder_CreateNewFrame, - GifEncoder_Commit, - GifEncoder_GetMetadataQueryWriter -}; - -HRESULT GifEncoder_CreateInstance(REFIID iid, void **ppv) -{ - GifEncoder *This; - HRESULT ret; - - TRACE("%s,%p\n", debugstr_guid(iid), ppv); - - *ppv = NULL; - - This = HeapAlloc(GetProcessHeap(), 0, sizeof(*This)); - if (!This) return E_OUTOFMEMORY; - - This->IWICBitmapEncoder_iface.lpVtbl = &GifEncoder_Vtbl; - This->ref = 1; - This->stream = NULL; - InitializeCriticalSection(&This->lock); - This->lock.DebugInfo->Spare[0] = (DWORD_PTR)(__FILE__ ": GifEncoder.lock"); - This->initialized = FALSE; - This->info_written = FALSE; - This->committed = FALSE; - This->n_frames = 0; - This->colors = 0; - - ret = IWICBitmapEncoder_QueryInterface(&This->IWICBitmapEncoder_iface, iid, ppv); - IWICBitmapEncoder_Release(&This->IWICBitmapEncoder_iface); - - return ret; -} diff --git a/dll/win32/windowscodecs/imgfactory.c b/dll/win32/windowscodecs/imgfactory.c index cfb7fc1bf1..623265762a 100644 --- a/dll/win32/windowscodecs/imgfactory.c +++ b/dll/win32/windowscodecs/imgfactory.c @@ -104,23 +104,22 @@ static HRESULT WINAPI ComponentFactory_CreateDecoderFromFilename( return hr; } -static HRESULT find_decoder(IStream *pIStream, const GUID *pguidVendor, - WICDecodeOptions metadataOptions, IWICBitmapDecoder **decoder) +static IWICBitmapDecoder *find_decoder(IStream *pIStream, const GUID *pguidVendor, + WICDecodeOptions metadataOptions) { IEnumUnknown *enumdecoders; IUnknown *unkdecoderinfo; IWICBitmapDecoderInfo *decoderinfo; + IWICBitmapDecoder *decoder = NULL; GUID vendor; HRESULT res; ULONG num_fetched; BOOL matches; - *decoder = NULL; - res = CreateComponentEnumerator(WICDecoder, WICComponentEnumerateDefault, &enumdecoders); - if (FAILED(res)) return res; + if (FAILED(res)) return NULL; - while (!*decoder) + while (!decoder) { res = IEnumUnknown_Next(enumdecoders, 1, &unkdecoderinfo, &num_fetched); @@ -145,21 +144,18 @@ static HRESULT find_decoder(IStream *pIStream, const GUID *pguidVendor, if (SUCCEEDED(res) && matches) { - res = IWICBitmapDecoderInfo_CreateInstance(decoderinfo, decoder); + res = IWICBitmapDecoderInfo_CreateInstance(decoderinfo, &decoder); /* FIXME: should use QueryCapability to choose a decoder */ if (SUCCEEDED(res)) { - res = IWICBitmapDecoder_Initialize(*decoder, pIStream, metadataOptions); + res = IWICBitmapDecoder_Initialize(decoder, pIStream, metadataOptions); if (FAILED(res)) { - IWICBitmapDecoder_Release(*decoder); - IWICBitmapDecoderInfo_Release(decoderinfo); - IUnknown_Release(unkdecoderinfo); - *decoder = NULL; - return res; + IWICBitmapDecoder_Release(decoder); + decoder = NULL; } } } @@ -175,7 +171,7 @@ static HRESULT find_decoder(IStream *pIStream, const GUID *pguidVendor, IEnumUnknown_Release(enumdecoders); - return WINCODEC_ERR_COMPONENTNOTFOUND; + return decoder; } static HRESULT WINAPI ComponentFactory_CreateDecoderFromStream( @@ -189,9 +185,9 @@ static HRESULT WINAPI ComponentFactory_CreateDecoderFromStream( metadataOptions, ppIDecoder); if (pguidVendor) - res = find_decoder(pIStream, pguidVendor, metadataOptions, &decoder); + decoder = find_decoder(pIStream, pguidVendor, metadataOptions); if (!decoder) - res = find_decoder(pIStream, NULL, metadataOptions, &decoder); + decoder = find_decoder(pIStream, NULL, metadataOptions); if (decoder) { @@ -206,17 +202,17 @@ static HRESULT WINAPI ComponentFactory_CreateDecoderFromStream( BYTE data[4]; ULONG bytesread; - WARN("failed to load from a stream %#x\n", res); + WARN("failed to load from a stream\n"); seek.QuadPart = 0; - if (IStream_Seek(pIStream, seek, STREAM_SEEK_SET, NULL) == S_OK) - { - if (IStream_Read(pIStream, data, 4, &bytesread) == S_OK) - WARN("first %i bytes of stream=%x %x %x %x\n", bytesread, data[0], data[1], data[2], data[3]); - } + res = IStream_Seek(pIStream, seek, STREAM_SEEK_SET, NULL); + if (SUCCEEDED(res)) + res = IStream_Read(pIStream, data, 4, &bytesread); + if (SUCCEEDED(res)) + WARN("first %i bytes of stream=%x %x %x %x\n", bytesread, data[0], data[1], data[2], data[3]); } *ppIDecoder = NULL; - return res; + return WINCODEC_ERR_COMPONENTNOTFOUND; } } @@ -583,36 +579,12 @@ static HRESULT WINAPI ComponentFactory_CreateBitmapFromMemory(IWICComponentFacto UINT width, UINT height, REFWICPixelFormatGUID format, UINT stride, UINT size, BYTE *buffer, IWICBitmap **bitmap) { - HRESULT hr; - TRACE("(%p,%u,%u,%s,%u,%u,%p,%p\n", iface, width, height, debugstr_guid(format), stride, size, buffer, bitmap); if (!stride || !size || !buffer || !bitmap) return E_INVALIDARG; - hr = BitmapImpl_Create(width, height, stride, size, NULL, format, WICBitmapCacheOnLoad, bitmap); - if (SUCCEEDED(hr)) - { - IWICBitmapLock *lock; - - hr = IWICBitmap_Lock(*bitmap, NULL, WICBitmapLockWrite, &lock); - if (SUCCEEDED(hr)) - { - UINT buffersize; - BYTE *data; - - IWICBitmapLock_GetDataPointer(lock, &buffersize, &data); - memcpy(data, buffer, buffersize); - - IWICBitmapLock_Release(lock); - } - else - { - IWICBitmap_Release(*bitmap); - *bitmap = NULL; - } - } - return hr; + return BitmapImpl_Create(width, height, stride, size, buffer, format, WICBitmapCacheOnLoad, bitmap); } static BOOL get_16bpp_format(HBITMAP hbm, WICPixelFormatGUID *format) @@ -1188,50 +1160,3 @@ HRESULT ComponentFactory_CreateInstance(REFIID iid, void** ppv) return ret; } - -HRESULT WINAPI WICCreateBitmapFromSectionEx(UINT width, UINT height, - REFWICPixelFormatGUID format, HANDLE section, UINT stride, - UINT offset, WICSectionAccessLevel wicaccess, IWICBitmap **bitmap) -{ - DWORD access; - void *buffer; - HRESULT hr; - - TRACE("%u,%u,%s,%p,%u,%#x,%#x,%p\n", width, height, debugstr_guid(format), - section, stride, offset, wicaccess, bitmap); - - if (!width || !height || !section || !bitmap) return E_INVALIDARG; - - switch (wicaccess) - { - case WICSectionAccessLevelReadWrite: - access = FILE_MAP_READ | FILE_MAP_WRITE; - break; - - case WICSectionAccessLevelRead: - access = FILE_MAP_READ; - break; - - default: - FIXME("unsupported access %#x\n", wicaccess); - return E_INVALIDARG; - } - - buffer = MapViewOfFile(section, access, 0, offset, 0); - if (!buffer) return HRESULT_FROM_WIN32(GetLastError()); - - hr = BitmapImpl_Create(width, height, stride, 0, buffer, format, WICBitmapCacheOnLoad, bitmap); - if (FAILED(hr)) UnmapViewOfFile(buffer); - return hr; -} - -HRESULT WINAPI WICCreateBitmapFromSection(UINT width, UINT height, - REFWICPixelFormatGUID format, HANDLE section, - UINT stride, UINT offset, IWICBitmap **bitmap) -{ - TRACE("%u,%u,%s,%p,%u,%u,%p\n", width, height, debugstr_guid(format), - section, stride, offset, bitmap); - - return WICCreateBitmapFromSectionEx(width, height, format, section, - stride, offset, WICSectionAccessLevelRead, bitmap); -} diff --git a/dll/win32/windowscodecs/info.c b/dll/win32/windowscodecs/info.c index d3ea8754a2..63cdc07dbc 100644 --- a/dll/win32/windowscodecs/info.c +++ b/dll/win32/windowscodecs/info.c @@ -853,12 +853,8 @@ static HRESULT WINAPI BitmapEncoderInfo_GetMimeTypes(IWICBitmapEncoderInfo *ifac static HRESULT WINAPI BitmapEncoderInfo_GetFileExtensions(IWICBitmapEncoderInfo *iface, UINT cchFileExtensions, WCHAR *wzFileExtensions, UINT *pcchActual) { - BitmapEncoderInfo *This = impl_from_IWICBitmapEncoderInfo(iface); - - TRACE("(%p,%u,%p,%p)\n", iface, cchFileExtensions, wzFileExtensions, pcchActual); - - return ComponentInfo_GetStringValue(This->classkey, fileextensions_valuename, - cchFileExtensions, wzFileExtensions, pcchActual); + FIXME("(%p,%u,%p,%p): stub\n", iface, cchFileExtensions, wzFileExtensions, pcchActual); + return E_NOTIMPL; } static HRESULT WINAPI BitmapEncoderInfo_DoesSupportAnimation(IWICBitmapEncoderInfo *iface, @@ -2269,12 +2265,6 @@ HRESULT CreateComponentEnumerator(DWORD componentTypes, DWORD options, IEnumUnkn return hr; } -static BOOL is_1bpp_format(const WICPixelFormatGUID *format) -{ - return IsEqualGUID(format, &GUID_WICPixelFormatBlackWhite) || - IsEqualGUID(format, &GUID_WICPixelFormat1bppIndexed); -} - HRESULT WINAPI WICConvertBitmapSource(REFWICPixelFormatGUID dstFormat, IWICBitmapSource *pISrc, IWICBitmapSource **ppIDst) { HRESULT res; @@ -2287,12 +2277,10 @@ HRESULT WINAPI WICConvertBitmapSource(REFWICPixelFormatGUID dstFormat, IWICBitma BOOL canconvert; ULONG num_fetched; - TRACE("%s,%p,%p\n", debugstr_guid(dstFormat), pISrc, ppIDst); - res = IWICBitmapSource_GetPixelFormat(pISrc, &srcFormat); if (FAILED(res)) return res; - if (IsEqualGUID(&srcFormat, dstFormat) || (is_1bpp_format(&srcFormat) && is_1bpp_format(dstFormat))) + if (IsEqualGUID(&srcFormat, dstFormat)) { IWICBitmapSource_AddRef(pISrc); *ppIDst = pISrc; @@ -2329,7 +2317,7 @@ HRESULT WINAPI WICConvertBitmapSource(REFWICPixelFormatGUID dstFormat, IWICBitma if (SUCCEEDED(res) && canconvert) res = IWICFormatConverter_Initialize(converter, pISrc, dstFormat, WICBitmapDitherTypeNone, - NULL, 0.0, WICBitmapPaletteTypeMedianCut); + NULL, 0.0, WICBitmapPaletteTypeCustom); if (FAILED(res) || !canconvert) { diff --git a/dll/win32/windowscodecs/jpegformat.c b/dll/win32/windowscodecs/jpegformat.c index ecbfc01c3c..cfb84c36aa 100644 --- a/dll/win32/windowscodecs/jpegformat.c +++ b/dll/win32/windowscodecs/jpegformat.c @@ -137,7 +137,6 @@ typedef struct { struct jpeg_error_mgr jerr; struct jpeg_source_mgr source_mgr; BYTE source_buffer[1024]; - UINT bpp, stride; BYTE *image_data; CRITICAL_SECTION lock; } JpegDecoder; @@ -286,8 +285,6 @@ static HRESULT WINAPI JpegDecoder_Initialize(IWICBitmapDecoder *iface, IStream * int ret; LARGE_INTEGER seek; jmp_buf jmpbuf; - UINT data_size, i; - TRACE("(%p,%p,%u)\n", iface, pIStream, cacheOptions); EnterCriticalSection(&This->lock); @@ -366,55 +363,6 @@ static HRESULT WINAPI JpegDecoder_Initialize(IWICBitmapDecoder *iface, IStream * return E_FAIL; } - if (This->cinfo.out_color_space == JCS_GRAYSCALE) This->bpp = 8; - else if (This->cinfo.out_color_space == JCS_CMYK) This->bpp = 32; - else This->bpp = 24; - - This->stride = (This->bpp * This->cinfo.output_width + 7) / 8; - data_size = This->stride * This->cinfo.output_height; - - This->image_data = HeapAlloc(GetProcessHeap(), 0, data_size); - if (!This->image_data) - { - LeaveCriticalSection(&This->lock); - return E_OUTOFMEMORY; - } - - while (This->cinfo.output_scanline < This->cinfo.output_height) - { - UINT first_scanline = This->cinfo.output_scanline; - UINT max_rows; - JSAMPROW out_rows[4]; - JDIMENSION ret; - - max_rows = min(This->cinfo.output_height-first_scanline, 4); - for (i=0; i<max_rows; i++) - out_rows[i] = This->image_data + This->stride * (first_scanline+i); - - ret = pjpeg_read_scanlines(&This->cinfo, out_rows, max_rows); - if (ret == 0) - { - ERR("read_scanlines failed\n"); - LeaveCriticalSection(&This->lock); - return E_FAIL; - } - } - - if (This->bpp == 24) - { - /* libjpeg gives us RGB data and we want BGR, so byteswap the data */ - reverse_bgr8(3, This->image_data, - This->cinfo.output_width, This->cinfo.output_height, - This->stride); - } - - if (This->cinfo.out_color_space == JCS_CMYK && This->cinfo.saw_Adobe_marker) - { - /* Adobe JPEG's have inverted CMYK data. */ - for (i=0; i<data_size; i++) - This->image_data[i] ^= 0xff; - } - This->initialized = TRUE; LeaveCriticalSection(&This->lock); @@ -457,14 +405,10 @@ static HRESULT WINAPI JpegDecoder_CopyPalette(IWICBitmapDecoder *iface, } static HRESULT WINAPI JpegDecoder_GetMetadataQueryReader(IWICBitmapDecoder *iface, - IWICMetadataQueryReader **reader) + IWICMetadataQueryReader **ppIMetadataQueryReader) { - FIXME("(%p,%p): stub\n", iface, reader); - - if (!reader) return E_INVALIDARG; - - *reader = NULL; - return WINCODEC_ERR_UNSUPPORTEDOPERATION; + FIXME("(%p,%p): stub\n", iface, ppIMetadataQueryReader); + return E_NOTIMPL; } static HRESULT WINAPI JpegDecoder_GetPreview(IWICBitmapDecoder *iface, @@ -635,11 +579,98 @@ static HRESULT WINAPI JpegDecoder_Frame_CopyPixels(IWICBitmapFrameDecode *iface, const WICRect *prc, UINT cbStride, UINT cbBufferSize, BYTE *pbBuffer) { JpegDecoder *This = impl_from_IWICBitmapFrameDecode(iface); - + UINT bpp; + UINT stride; + UINT data_size; + UINT max_row_needed; + jmp_buf jmpbuf; + WICRect rect; TRACE("(%p,%p,%u,%u,%p)\n", iface, prc, cbStride, cbBufferSize, pbBuffer); - return copy_pixels(This->bpp, This->image_data, - This->cinfo.output_width, This->cinfo.output_height, This->stride, + if (!prc) + { + rect.X = 0; + rect.Y = 0; + rect.Width = This->cinfo.output_width; + rect.Height = This->cinfo.output_height; + prc = ▭ + } + else + { + if (prc->X < 0 || prc->Y < 0 || prc->X+prc->Width > This->cinfo.output_width || + prc->Y+prc->Height > This->cinfo.output_height) + return E_INVALIDARG; + } + + if (This->cinfo.out_color_space == JCS_GRAYSCALE) bpp = 8; + else if (This->cinfo.out_color_space == JCS_CMYK) bpp = 32; + else bpp = 24; + + stride = bpp * This->cinfo.output_width; + data_size = stride * This->cinfo.output_height; + + max_row_needed = prc->Y + prc->Height; + if (max_row_needed > This->cinfo.output_height) return E_INVALIDARG; + + EnterCriticalSection(&This->lock); + + if (!This->image_data) + { + This->image_data = HeapAlloc(GetProcessHeap(), 0, data_size); + if (!This->image_data) + { + LeaveCriticalSection(&This->lock); + return E_OUTOFMEMORY; + } + } + + This->cinfo.client_data = jmpbuf; + + if (setjmp(jmpbuf)) + { + LeaveCriticalSection(&This->lock); + return E_FAIL; + } + + while (max_row_needed > This->cinfo.output_scanline) + { + UINT first_scanline = This->cinfo.output_scanline; + UINT max_rows; + JSAMPROW out_rows[4]; + UINT i; + JDIMENSION ret; + + max_rows = min(This->cinfo.output_height-first_scanline, 4); + for (i=0; i<max_rows; i++) + out_rows[i] = This->image_data + stride * (first_scanline+i); + + ret = pjpeg_read_scanlines(&This->cinfo, out_rows, max_rows); + + if (ret == 0) + { + ERR("read_scanlines failed\n"); + LeaveCriticalSection(&This->lock); + return E_FAIL; + } + + if (bpp == 24) + { + /* libjpeg gives us RGB data and we want BGR, so byteswap the data */ + reverse_bgr8(3, This->image_data + stride * first_scanline, + This->cinfo.output_width, This->cinfo.output_scanline - first_scanline, + stride); + } + + if (This->cinfo.out_color_space == JCS_CMYK && This->cinfo.saw_Adobe_marker) + /* Adobe JPEG's have inverted CMYK data. */ + for (i=0; i<data_size; i++) + This->image_data[i] ^= 0xff; + } + + LeaveCriticalSection(&This->lock); + + return copy_pixels(bpp, This->image_data, + This->cinfo.output_width, This->cinfo.output_height, stride, prc, cbStride, cbBufferSize, pbBuffer); } @@ -1344,22 +1375,11 @@ static HRESULT WINAPI JpegEncoder_GetContainerFormat(IWICBitmapEncoder *iface, return E_NOTIMPL; } -static HRESULT WINAPI JpegEncoder_GetEncoderInfo(IWICBitmapEncoder *iface, IWICBitmapEncoderInfo **info) +static HRESULT WINAPI JpegEncoder_GetEncoderInfo(IWICBitmapEncoder *iface, + IWICBitmapEncoderInfo **ppIEncoderInfo) { - IWICComponentInfo *comp_info; - HRESULT hr; - - TRACE("%p,%p\n", iface, info); - - if (!info) return E_INVALIDARG; - - hr = CreateComponentInfo(&CLSID_WICJpegEncoder, &comp_info); - if (hr == S_OK) - { - hr = IWICComponentInfo_QueryInterface(comp_info, &IID_IWICBitmapEncoderInfo, (void **)info); - IWICComponentInfo_Release(comp_info); - } - return hr; + FIXME("(%p,%p): stub\n", iface, ppIEncoderInfo); + return E_NOTIMPL; } static HRESULT WINAPI JpegEncoder_SetColorContexts(IWICBitmapEncoder *iface, @@ -1439,14 +1459,11 @@ static HRESULT WINAPI JpegEncoder_CreateNewFrame(IWICBitmapEncoder *iface, opts[5].vt = VT_BOOL; opts[5].dwType = PROPBAG2_TYPE_DATA; - if (ppIEncoderOptions) + hr = CreatePropertyBag2(opts, 6, ppIEncoderOptions); + if (FAILED(hr)) { - hr = CreatePropertyBag2(opts, 6, ppIEncoderOptions); - if (FAILED(hr)) - { - LeaveCriticalSection(&This->lock); - return hr; - } + LeaveCriticalSection(&This->lock); + return hr; } This->frame_count = 1; diff --git a/dll/win32/windowscodecs/metadatahandler.c b/dll/win32/windowscodecs/metadatahandler.c index 25f4314720..dff5ed3c7f 100644 --- a/dll/win32/windowscodecs/metadatahandler.c +++ b/dll/win32/windowscodecs/metadatahandler.c @@ -704,7 +704,7 @@ static int tag_to_vt(SHORT tag) static HRESULT load_IFD_entry(IStream *input, const struct IFD_entry *entry, MetadataItem *item, BOOL native_byte_order) { - ULONG count, value, i; + ULONG count, value, i, bytesread; SHORT type; LARGE_INTEGER pos; HRESULT hr; @@ -746,7 +746,7 @@ static HRESULT load_IFD_entry(IStream *input, const struct IFD_entry *entry, item->value.vt |= VT_VECTOR; item->value.u.caub.cElems = count; - item->value.u.caub.pElems = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, count); + item->value.u.caub.pElems = HeapAlloc(GetProcessHeap(), 0, count); if (!item->value.u.caub.pElems) return E_OUTOFMEMORY; pos.QuadPart = value; @@ -756,8 +756,9 @@ static HRESULT load_IFD_entry(IStream *input, const struct IFD_entry *entry, HeapFree(GetProcessHeap(), 0, item->value.u.caub.pElems); return hr; } - hr = IStream_Read(input, item->value.u.caub.pElems, count, NULL); - if (FAILED(hr)) + hr = IStream_Read(input, item->value.u.caub.pElems, count, &bytesread); + if (bytesread != count) hr = E_FAIL; + if (hr != S_OK) { HeapFree(GetProcessHeap(), 0, item->value.u.caub.pElems); return hr; @@ -790,7 +791,7 @@ static HRESULT load_IFD_entry(IStream *input, const struct IFD_entry *entry, item->value.vt |= VT_VECTOR; item->value.u.caui.cElems = count; - item->value.u.caui.pElems = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, count * 2); + item->value.u.caui.pElems = HeapAlloc(GetProcessHeap(), 0, count * 2); if (!item->value.u.caui.pElems) return E_OUTOFMEMORY; pos.QuadPart = value; @@ -800,8 +801,9 @@ static HRESULT load_IFD_entry(IStream *input, const struct IFD_entry *entry, HeapFree(GetProcessHeap(), 0, item->value.u.caui.pElems); return hr; } - hr = IStream_Read(input, item->value.u.caui.pElems, count * 2, NULL); - if (FAILED(hr)) + hr = IStream_Read(input, item->value.u.caui.pElems, count * 2, &bytesread); + if (bytesread != count * 2) hr = E_FAIL; + if (hr != S_OK) { HeapFree(GetProcessHeap(), 0, item->value.u.caui.pElems); return hr; @@ -822,7 +824,7 @@ static HRESULT load_IFD_entry(IStream *input, const struct IFD_entry *entry, item->value.vt |= VT_VECTOR; item->value.u.caul.cElems = count; - item->value.u.caul.pElems = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, count * 4); + item->value.u.caul.pElems = HeapAlloc(GetProcessHeap(), 0, count * 4); if (!item->value.u.caul.pElems) return E_OUTOFMEMORY; pos.QuadPart = value; @@ -832,8 +834,9 @@ static HRESULT load_IFD_entry(IStream *input, const struct IFD_entry *entry, HeapFree(GetProcessHeap(), 0, item->value.u.caul.pElems); return hr; } - hr = IStream_Read(input, item->value.u.caul.pElems, count * 4, NULL); - if (FAILED(hr)) + hr = IStream_Read(input, item->value.u.caul.pElems, count * 4, &bytesread); + if (bytesread != count * 4) hr = E_FAIL; + if (hr != S_OK) { HeapFree(GetProcessHeap(), 0, item->value.u.caul.pElems); return hr; @@ -859,7 +862,8 @@ static HRESULT load_IFD_entry(IStream *input, const struct IFD_entry *entry, hr = IStream_Seek(input, pos, SEEK_SET, NULL); if (FAILED(hr)) return hr; - hr = IStream_Read(input, &ull, sizeof(ull), NULL); + hr = IStream_Read(input, &ull, sizeof(ull), &bytesread); + if (bytesread != sizeof(ull)) hr = E_FAIL; if (hr != S_OK) return hr; item->value.u.uhVal.QuadPart = ull; @@ -877,7 +881,7 @@ static HRESULT load_IFD_entry(IStream *input, const struct IFD_entry *entry, { item->value.vt |= VT_VECTOR; item->value.u.cauh.cElems = count; - item->value.u.cauh.pElems = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, count * 8); + item->value.u.cauh.pElems = HeapAlloc(GetProcessHeap(), 0, count * 8); if (!item->value.u.cauh.pElems) return E_OUTOFMEMORY; pos.QuadPart = value; @@ -887,8 +891,9 @@ static HRESULT load_IFD_entry(IStream *input, const struct IFD_entry *entry, HeapFree(GetProcessHeap(), 0, item->value.u.cauh.pElems); return hr; } - hr = IStream_Read(input, item->value.u.cauh.pElems, count * 8, NULL); - if (FAILED(hr)) + hr = IStream_Read(input, item->value.u.cauh.pElems, count * 8, &bytesread); + if (bytesread != count * 8) hr = E_FAIL; + if (hr != S_OK) { HeapFree(GetProcessHeap(), 0, item->value.u.cauh.pElems); return hr; @@ -906,7 +911,7 @@ static HRESULT load_IFD_entry(IStream *input, const struct IFD_entry *entry, } break; case IFD_ASCII: - item->value.u.pszVal = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, count + 1); + item->value.u.pszVal = HeapAlloc(GetProcessHeap(), 0, count + 1); if (!item->value.u.pszVal) return E_OUTOFMEMORY; if (count <= 4) @@ -924,8 +929,9 @@ static HRESULT load_IFD_entry(IStream *input, const struct IFD_entry *entry, HeapFree(GetProcessHeap(), 0, item->value.u.pszVal); return hr; } - hr = IStream_Read(input, item->value.u.pszVal, count, NULL); - if (FAILED(hr)) + hr = IStream_Read(input, item->value.u.pszVal, count, &bytesread); + if (bytesread != count) hr = E_FAIL; + if (hr != S_OK) { HeapFree(GetProcessHeap(), 0, item->value.u.pszVal); return hr; @@ -940,7 +946,7 @@ static HRESULT load_IFD_entry(IStream *input, const struct IFD_entry *entry, break; } - item->value.u.blob.pBlobData = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, count); + item->value.u.blob.pBlobData = HeapAlloc(GetProcessHeap(), 0, count); if (!item->value.u.blob.pBlobData) return E_OUTOFMEMORY; item->value.u.blob.cbSize = count; @@ -959,8 +965,9 @@ static HRESULT load_IFD_entry(IStream *input, const struct IFD_entry *entry, HeapFree(GetProcessHeap(), 0, item->value.u.blob.pBlobData); return hr; } - hr = IStream_Read(input, item->value.u.blob.pBlobData, count, NULL); - if (FAILED(hr)) + hr = IStream_Read(input, item->value.u.blob.pBlobData, count, &bytesread); + if (bytesread != count) hr = E_FAIL; + if (hr != S_OK) { HeapFree(GetProcessHeap(), 0, item->value.u.blob.pBlobData); return hr; diff --git a/dll/win32/windowscodecs/palette.c b/dll/win32/windowscodecs/palette.c index d31cb554d8..89b10b7ba9 100644 --- a/dll/win32/windowscodecs/palette.c +++ b/dll/win32/windowscodecs/palette.c @@ -1,7 +1,6 @@ /* * Copyright 2009 Vincent Povirk for CodeWeavers - * Copyright 2012,2016 Dmitry Timoshkov - * Copyright 2016 Sebastian Lackner + * Copyright 2012 Dmitry Timoshkov * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public @@ -432,279 +431,11 @@ static HRESULT WINAPI PaletteImpl_InitializeCustom(IWICPalette *iface, return S_OK; } -#define R_COUNT (1 << 5) -#define R_SHIFT (8 - 5) -#define R_SCALE 2 - -#define G_COUNT (1 << 6) -#define G_SHIFT (8 - 6) -#define G_SCALE 3 - -#define B_COUNT (1 << 5) -#define B_SHIFT (8 - 5) -#define B_SCALE 1 - -struct histogram -{ - unsigned int data[R_COUNT][G_COUNT][B_COUNT]; -}; - -struct box -{ - int r_min, r_max; - int g_min, g_max; - int b_min, b_max; - unsigned int count; - unsigned int score; -}; - -/* count nonzero elements in the histogram range [r_min, r_max] x [g_min, g_max] x [b_min, b_max] */ -static inline unsigned int histogram_count(struct histogram *h, int r_min, int r_max, - int g_min, int g_max, int b_min, int b_max) -{ - unsigned int count = 0; - int r, g, b; - for (r = r_min; r <= r_max; r++) - for (g = g_min; g <= g_max; g++) - for (b = b_min; b <= b_max; b++) - if (h->data[r][g][b] != 0) count++; - return count; -} - -/* compute weighted average color in the range [r_min, r_max] x [g_min, g_max] x [b_min, b_max] */ -static unsigned int histogram_color(struct histogram *h, int r_min, int r_max, - int g_min, int g_max, int b_min, int b_max) -{ - unsigned long long r_sum = 0, g_sum = 0, b_sum = 0; - unsigned int tmp, count = 0; - int r, g, b; - - for (r = r_min; r <= r_max; r++) - for (g = g_min; g <= g_max; g++) - for (b = b_min; b <= b_max; b++) - { - if (!(tmp = h->data[r][g][b])) continue; - r_sum += ((r << R_SHIFT) + ((1 << R_SHIFT) / 2)) * tmp; - g_sum += ((g << G_SHIFT) + ((1 << G_SHIFT) / 2)) * tmp; - b_sum += ((b << B_SHIFT) + ((1 << B_SHIFT) / 2)) * tmp; - count += tmp; - } - - return ((b_sum + (count / 2)) / count) | - ((g_sum + (count / 2)) / count) << 8 | - ((r_sum + (count / 2)) / count) << 16 | 0xff000000; -} - -/* same as histogram_count */ -static inline unsigned int box_count(struct histogram *h, struct box *b) -{ - return histogram_count(h, b->r_min, b->r_max, b->g_min, b->g_max, b->b_min, b->b_max); -} - -/* same as histogram_color */ -static inline unsigned int box_color(struct histogram *h, struct box *b) -{ - return histogram_color(h, b->r_min, b->r_max, b->g_min, b->g_max, b->b_min, b->b_max); -} - -/* compute score used to determine best split (also called "volume") */ -static inline unsigned int box_score(struct box *b) -{ - unsigned int tmp, sum = 0; - tmp = ((b->r_max - b->r_min) << R_SHIFT) * R_SCALE; sum += tmp * tmp; - tmp = ((b->g_max - b->g_min) << G_SHIFT) * G_SCALE; sum += tmp * tmp; - tmp = ((b->b_max - b->b_min) << B_SHIFT) * B_SCALE; sum += tmp * tmp; - return sum; -} - -/* attempt to shrink a box */ -static void shrink_box(struct histogram *h, struct box *b) -{ - int i; - for (i = b->r_min; i <= b->r_max; i++) - if (histogram_count(h, i, i, b->g_min, b->g_max, b->b_min, b->b_max)) { b->r_min = i; break; } - for (i = b->r_max; i >= b->r_min; i--) - if (histogram_count(h, i, i, b->g_min, b->g_max, b->b_min, b->b_max)) { b->r_max = i; break; } - for (i = b->g_min; i <= b->g_max; i++) - if (histogram_count(h, b->r_min, b->r_max, i, i, b->b_min, b->b_max)) { b->g_min = i; break; } - for (i = b->g_max; i >= b->g_min; i--) - if (histogram_count(h, b->r_min, b->r_max, i, i, b->b_min, b->b_max)) { b->g_max = i; break; } - for (i = b->b_min; i <= b->b_max; i++) - if (histogram_count(h, b->r_min, b->r_max, b->g_min, b->g_max, i, i)) { b->b_min = i; break; } - for (i = b->b_max; i >= b->b_min; i--) - if (histogram_count(h, b->r_min, b->r_max, b->g_min, b->g_max, i, i)) { b->b_max = i; break; } - b->count = box_count(h, b); - b->score = box_score(b); -} - -/* helper for split_box */ -static inline void set_avg(int *min, int *max) -{ - int avg = (*min + *max) / 2; - *min = avg + 1; - *max = avg; -} - -/* split a box based on the best axis */ -static void split_box(struct histogram *h, struct box *b1, struct box *b2) -{ - int r = ((b1->r_max - b1->r_min) << R_SHIFT) * R_SCALE; - int g = ((b1->g_max - b1->g_min) << G_SHIFT) * G_SCALE; - int b = ((b1->b_max - b1->b_min) << B_SHIFT) * B_SCALE; - - *b2 = *b1; - - if (r > g) - { - if (b > r) set_avg(&b1->b_min, &b2->b_max); - else set_avg(&b1->r_min, &b2->r_max); - } - else - { - if (b > g) set_avg(&b1->b_min, &b2->b_max); - else set_avg(&b1->g_min, &b2->g_max); - } - - shrink_box(h, b1); - shrink_box(h, b2); -} - -/* find box suitable for split based on count */ -static struct box *find_box_max_count(struct box *b, int count) -{ - struct box *best = NULL; - for (; count--; b++) - if (b->score && (!best || b->count > best->count)) best = b; - return best; -} - -/* find box suitable for split based on score */ -static struct box *find_box_max_score(struct box *b, int count) -{ - struct box *best = NULL; - for (; count--; b++) - if (b->score && (!best || b->score > best->score)) best = b; - return best; -} - -/* compute color map with at most 'desired' colors - * image must be in 24bpp BGR format and colors are returned in 0xAARRGGBB format */ -static int median_cut(unsigned char *image, unsigned int width, unsigned int height, - unsigned int stride, int desired, unsigned int *colors) -{ - struct box boxes[256]; - struct histogram *h; - unsigned int x, y; - unsigned char *p; - struct box *b1, *b2; - int numboxes, i; - - if (!(h = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*h)))) - return 0; - - for (y = 0; y < height; y++) - for (x = 0, p = image + y * stride; x < width; x++, p += 3) - h->data[p[2] >> R_SHIFT][p[1] >> G_SHIFT][p[0] >> B_SHIFT]++; - - numboxes = 1; - boxes[0].r_min = 0; boxes[0].r_max = R_COUNT - 1; - boxes[0].g_min = 0; boxes[0].g_max = G_COUNT - 1; - boxes[0].b_min = 0; boxes[0].b_max = B_COUNT - 1; - shrink_box(h, &boxes[0]); - - while (numboxes <= desired / 2) - { - if (!(b1 = find_box_max_count(boxes, numboxes))) break; - b2 = &boxes[numboxes++]; - split_box(h, b1, b2); - } - while (numboxes < desired) - { - if (!(b1 = find_box_max_score(boxes, numboxes))) break; - b2 = &boxes[numboxes++]; - split_box(h, b1, b2); - } - - for (i = 0; i < numboxes; i++) - colors[i] = box_color(h, &boxes[i]); - - HeapFree(GetProcessHeap(), 0, h); - return numboxes; -} - - -static HRESULT WINAPI PaletteImpl_InitializeFromBitmap(IWICPalette *palette, - IWICBitmapSource *source, UINT desired, BOOL add_transparent) +static HRESULT WINAPI PaletteImpl_InitializeFromBitmap(IWICPalette *iface, + IWICBitmapSource *pISurface, UINT colorCount, BOOL fAddTransparentColor) { - IWICImagingFactory *factory = NULL; - IWICBitmap *rgb24_bitmap = NULL; - IWICBitmapSource *rgb24_source; - IWICBitmapLock *lock = NULL; - WICPixelFormatGUID format; - HRESULT hr; - UINT width, height, stride, size, actual_number_of_colors; - BYTE *src; - WICColor colors[256]; - - TRACE("(%p,%p,%u,%d)\n", palette, source, desired, add_transparent); - - if (!source || desired < 2 || desired > 256) - return E_INVALIDARG; - - hr = IWICBitmapSource_GetPixelFormat(source, &format); - if (hr != S_OK) return hr; - - /* For interoperability with gdiplus where PixelFormat24bppRGB actully stored - * as BGR (and there is no a corresponding RGB format) we have to use 24bppBGR - * to avoid format conversions. - */ - if (!IsEqualGUID(&format, &GUID_WICPixelFormat24bppBGR)) - { - hr = WICConvertBitmapSource(&GUID_WICPixelFormat24bppBGR, source, &rgb24_source); - if (hr != S_OK) return hr; - } - else - rgb24_source = source; - - hr = ComponentFactory_CreateInstance(&IID_IWICImagingFactory, (void **)&factory); - if (hr != S_OK) goto fail; - - hr = IWICImagingFactory_CreateBitmapFromSource(factory, rgb24_source, WICBitmapCacheOnLoad, &rgb24_bitmap); - if (hr != S_OK) goto fail; - - hr = IWICBitmap_Lock(rgb24_bitmap, NULL, WICBitmapLockRead, &lock); - if (hr != S_OK) goto fail; - - IWICBitmapLock_GetSize(lock, &width, &height); - IWICBitmapLock_GetStride(lock, &stride); - IWICBitmapLock_GetDataPointer(lock, &size, &src); - - actual_number_of_colors = median_cut(src, width, height, stride, add_transparent ? desired - 1 : desired, colors); - TRACE("actual number of colors: %u\n", actual_number_of_colors); - - if (actual_number_of_colors) - { - if (add_transparent) colors[actual_number_of_colors++] = 0; - - hr = IWICPalette_InitializeCustom(palette, colors, actual_number_of_colors); - } - else - hr = E_OUTOFMEMORY; - -fail: - if (lock) - IWICBitmapLock_Release(lock); - - if (rgb24_bitmap) - IWICBitmap_Release(rgb24_bitmap); - - if (factory) - IWICImagingFactory_Release(factory); - - if (rgb24_source != source) - IWICBitmapSource_Release(rgb24_source); - - return hr; + FIXME("(%p,%p,%u,%i): stub\n", iface, pISurface, colorCount, fAddTransparentColor); + return E_NOTIMPL; } static HRESULT WINAPI PaletteImpl_InitializeFromPalette(IWICPalette *iface, diff --git a/dll/win32/windowscodecs/pngformat.c b/dll/win32/windowscodecs/pngformat.c index 175642b295..6946721b77 100644 --- a/dll/win32/windowscodecs/pngformat.c +++ b/dll/win32/windowscodecs/pngformat.c @@ -19,8 +19,6 @@ #include "wincodecs_private.h" -#include <winerror.h> - #ifdef HAVE_PNG_H #include <png.h> #endif @@ -565,8 +563,6 @@ static HRESULT WINAPI PngDecoder_Initialize(IWICBitmapDecoder *iface, IStream *p int num_trans; png_uint_32 transparency; png_color_16p trans_values; - png_colorp png_palette; - int num_palette; jmp_buf jmpbuf; BYTE chunk_type[4]; ULONG chunk_size; @@ -609,7 +605,7 @@ static HRESULT WINAPI PngDecoder_Initialize(IWICBitmapDecoder *iface, IStream *p ppng_destroy_read_struct(&This->png_ptr, &This->info_ptr, &This->end_info); HeapFree(GetProcessHeap(), 0, row_pointers); This->png_ptr = NULL; - hr = WINCODEC_ERR_UNKNOWNIMAGEFORMAT; + hr = E_FAIL; goto end; } ppng_set_error_fn(This->png_ptr, jmpbuf, user_error_fn, user_warning_fn); @@ -633,37 +629,18 @@ static HRESULT WINAPI PngDecoder_Initialize(IWICBitmapDecoder *iface, IStream *p /* check for color-keyed alpha */ transparency = ppng_get_tRNS(This->png_ptr, This->info_ptr, &trans, &num_trans, &trans_values); - if (!ppng_get_PLTE(This->png_ptr, This->info_ptr, &png_palette, &num_palette)) - num_palette = 0; - - TRACE("color_type %d, bit_depth %d, transparency %d, num_palette %d\n", - color_type, bit_depth, transparency, num_palette); + if (transparency && (color_type == PNG_COLOR_TYPE_RGB || + (color_type == PNG_COLOR_TYPE_GRAY && bit_depth == 16))) + { + /* expand to RGBA */ + if (color_type == PNG_COLOR_TYPE_GRAY) + ppng_set_gray_to_rgb(This->png_ptr); + ppng_set_tRNS_to_alpha(This->png_ptr); + color_type = PNG_COLOR_TYPE_RGB_ALPHA; + } switch (color_type) { - case PNG_COLOR_TYPE_GRAY: - This->bpp = bit_depth; - switch (bit_depth) - { - case 1: - This->format = num_palette ? &GUID_WICPixelFormat1bppIndexed : &GUID_WICPixelFormatBlackWhite; - break; - case 2: - This->format = num_palette ? &GUID_WICPixelFormat2bppIndexed : &GUID_WICPixelFormat2bppGray; - break; - case 4: - This->format = num_palette ? &GUID_WICPixelFormat4bppIndexed : &GUID_WICPixelFormat4bppGray; - break; - case 8: - This->format = num_palette ? &GUID_WICPixelFormat8bppIndexed : &GUID_WICPixelFormat8bppGray; - break; - case 16: This->format = &GUID_WICPixelFormat16bppGray; break; - default: - ERR("invalid grayscale bit depth: %i\n", bit_depth); - hr = WINCODEC_ERR_UNKNOWNIMAGEFORMAT; - goto end; - } - break; case PNG_COLOR_TYPE_GRAY_ALPHA: /* WIC does not support grayscale alpha formats so use RGBA */ ppng_set_gray_to_rgb(This->png_ptr); @@ -683,6 +660,25 @@ static HRESULT WINAPI PngDecoder_Initialize(IWICBitmapDecoder *iface, IStream *p goto end; } break; + case PNG_COLOR_TYPE_GRAY: + This->bpp = bit_depth; + if (!transparency) + { + switch (bit_depth) + { + case 1: This->format = &GUID_WICPixelFormatBlackWhite; break; + case 2: This->format = &GUID_WICPixelFormat2bppGray; break; + case 4: This->format = &GUID_WICPixelFormat4bppGray; break; + case 8: This->format = &GUID_WICPixelFormat8bppGray; break; + case 16: This->format = &GUID_WICPixelFormat16bppGray; break; + default: + ERR("invalid grayscale bit depth: %i\n", bit_depth); + hr = E_FAIL; + goto end; + } + break; + } + /* else fall through */ case PNG_COLOR_TYPE_PALETTE: This->bpp = bit_depth; switch (bit_depth) @@ -840,14 +836,10 @@ static HRESULT WINAPI PngDecoder_CopyPalette(IWICBitmapDecoder *iface, } static HRESULT WINAPI PngDecoder_GetMetadataQueryReader(IWICBitmapDecoder *iface, - IWICMetadataQueryReader **reader) + IWICMetadataQueryReader **ppIMetadataQueryReader) { - FIXME("(%p,%p): stub\n", iface, reader); - - if (!reader) return E_INVALIDARG; - - *reader = NULL; - return WINCODEC_ERR_UNSUPPORTEDOPERATION; + FIXME("(%p,%p): stub\n", iface, ppIMetadataQueryReader); + return E_NOTIMPL; } static HRESULT WINAPI PngDecoder_GetPreview(IWICBitmapDecoder *iface, @@ -1014,7 +1006,7 @@ static HRESULT WINAPI PngDecoder_Frame_CopyPalette(IWICBitmapFrameDecode *iface, IWICPalette *pIPalette) { PngDecoder *This = impl_from_IWICBitmapFrameDecode(iface); - png_uint_32 ret; + png_uint_32 ret, color_type, bit_depth; png_colorp png_palette; int num_palette; WICColor palette[256]; @@ -1028,30 +1020,58 @@ static HRESULT WINAPI PngDecoder_Frame_CopyPalette(IWICBitmapFrameDecode *iface, EnterCriticalSection(&This->lock); - ret = ppng_get_PLTE(This->png_ptr, This->info_ptr, &png_palette, &num_palette); - if (!ret) - { - hr = WINCODEC_ERR_PALETTEUNAVAILABLE; - goto end; - } + color_type = ppng_get_color_type(This->png_ptr, This->info_ptr); + bit_depth = ppng_get_bit_depth(This->png_ptr, This->info_ptr); - if (num_palette > 256) + if (color_type == PNG_COLOR_TYPE_PALETTE) { - ERR("palette has %i colors?!\n", num_palette); - hr = E_FAIL; - goto end; + ret = ppng_get_PLTE(This->png_ptr, This->info_ptr, &png_palette, &num_palette); + if (!ret) + { + hr = WINCODEC_ERR_PALETTEUNAVAILABLE; + goto end; + } + + if (num_palette > 256) + { + ERR("palette has %i colors?!\n", num_palette); + hr = E_FAIL; + goto end; + } + + ret = ppng_get_tRNS(This->png_ptr, This->info_ptr, &trans_alpha, &num_trans, &trans_values); + if (!ret) num_trans = 0; + + for (i=0; i<num_palette; i++) + { + BYTE alpha = (i < num_trans) ? trans_alpha[i] : 0xff; + palette[i] = (alpha << 24 | + png_palette[i].red << 16| + png_palette[i].green << 8| + png_palette[i].blue); + } } + else if (color_type == PNG_COLOR_TYPE_GRAY) { + ret = ppng_get_tRNS(This->png_ptr, This->info_ptr, &trans_alpha, &num_trans, &trans_values); - ret = ppng_get_tRNS(This->png_ptr, This->info_ptr, &trans_alpha, &num_trans, &trans_values); - if (!ret) num_trans = 0; + if (!ret) + { + hr = WINCODEC_ERR_PALETTEUNAVAILABLE; + goto end; + } - for (i=0; i<num_palette; i++) + num_palette = 1 << bit_depth; + + for (i=0; i<num_palette; i++) + { + BYTE alpha = (i == trans_values[0].gray) ? 0 : 0xff; + BYTE val = i * 255 / (num_palette - 1); + palette[i] = (alpha << 24 | val << 16 | val << 8 | val); + } + } + else { - BYTE alpha = (i < num_trans) ? trans_alpha[i] : 0xff; - palette[i] = (alpha << 24 | - png_palette[i].red << 16| - png_palette[i].green << 8| - png_palette[i].blue); + hr = WINCODEC_ERR_PALETTEUNAVAILABLE; } end: @@ -1632,31 +1652,22 @@ static HRESULT WINAPI PngFrameEncode_WritePixels(IWICBitmapFrameEncode *iface, /* Newer libpng versions don't accept larger palettes than the declared * bit depth, so we need to generate the palette of the correct length. */ - colors = 1 << This->format->bit_depth; + colors = min(This->colors, 1 << This->format->bit_depth); for (i = 0; i < colors; i++) { - if (i < This->colors) - { - png_palette[i].red = (This->palette[i] >> 16) & 0xff; - png_palette[i].green = (This->palette[i] >> 8) & 0xff; - png_palette[i].blue = This->palette[i] & 0xff; - trans[i] = (This->palette[i] >> 24) & 0xff; - if (trans[i] != 0xff) - num_trans++; - } - else - { - png_palette[i].red = 0; - png_palette[i].green = 0; - png_palette[i].blue = 0; - } + png_palette[i].red = (This->palette[i] >> 16) & 0xff; + png_palette[i].green = (This->palette[i] >> 8) & 0xff; + png_palette[i].blue = This->palette[i] & 0xff; + trans[i] = (This->palette[i] >> 24) & 0xff; + if (trans[i] != 0xff) + num_trans = i+1; } ppng_set_PLTE(This->png_ptr, This->info_ptr, png_palette, colors); if (num_trans) - ppng_set_tRNS(This->png_ptr, This->info_ptr, trans, colors, NULL); + ppng_set_tRNS(This->png_ptr, This->info_ptr, trans, num_trans, NULL); } ppng_write_info(This->png_ptr, This->info_ptr); @@ -1958,22 +1969,11 @@ static HRESULT WINAPI PngEncoder_GetContainerFormat(IWICBitmapEncoder *iface, return E_NOTIMPL; } -static HRESULT WINAPI PngEncoder_GetEncoderInfo(IWICBitmapEncoder *iface, IWICBitmapEncoderInfo **info) +static HRESULT WINAPI PngEncoder_GetEncoderInfo(IWICBitmapEncoder *iface, + IWICBitmapEncoderInfo **ppIEncoderInfo) { - IWICComponentInfo *comp_info; - HRESULT hr; - - TRACE("%p,%p\n", iface, info); - - if (!info) return E_INVALIDARG; - - hr = CreateComponentInfo(&CLSID_WICPngEncoder, &comp_info); - if (hr == S_OK) - { - hr = IWICComponentInfo_QueryInterface(comp_info, &IID_IWICBitmapEncoderInfo, (void **)info); - IWICComponentInfo_Release(comp_info); - } - return hr; + FIXME("(%p,%p): stub\n", iface, ppIEncoderInfo); + return E_NOTIMPL; } static HRESULT WINAPI PngEncoder_SetColorContexts(IWICBitmapEncoder *iface, diff --git a/dll/win32/windowscodecs/regsvr.c b/dll/win32/windowscodecs/regsvr.c index aba6c0a0ee..756fb19651 100644 --- a/dll/win32/windowscodecs/regsvr.c +++ b/dll/win32/windowscodecs/regsvr.c @@ -1194,10 +1194,6 @@ static GUID const * const tiff_decode_formats[] = { &GUID_WICPixelFormatBlackWhite, &GUID_WICPixelFormat4bppGray, &GUID_WICPixelFormat8bppGray, - &GUID_WICPixelFormat16bppGray, - &GUID_WICPixelFormat32bppGrayFloat, - &GUID_WICPixelFormat1bppIndexed, - &GUID_WICPixelFormat2bppIndexed, &GUID_WICPixelFormat4bppIndexed, &GUID_WICPixelFormat8bppIndexed, &GUID_WICPixelFormat24bppBGR, @@ -1207,9 +1203,6 @@ static GUID const * const tiff_decode_formats[] = { &GUID_WICPixelFormat48bppRGB, &GUID_WICPixelFormat64bppRGBA, &GUID_WICPixelFormat64bppPRGBA, - &GUID_WICPixelFormat32bppCMYK, - &GUID_WICPixelFormat64bppCMYK, - &GUID_WICPixelFormat128bppRGBAFloat, NULL }; @@ -1335,11 +1328,6 @@ static GUID const * const bmp_encode_formats[] = { &GUID_WICPixelFormat16bppBGR565, &GUID_WICPixelFormat24bppBGR, &GUID_WICPixelFormat32bppBGR, - &GUID_WICPixelFormatBlackWhite, - &GUID_WICPixelFormat1bppIndexed, - &GUID_WICPixelFormat2bppIndexed, - &GUID_WICPixelFormat4bppIndexed, - &GUID_WICPixelFormat8bppIndexed, NULL }; @@ -1365,10 +1353,6 @@ static GUID const * const tiff_encode_formats[] = { &GUID_WICPixelFormatBlackWhite, &GUID_WICPixelFormat4bppGray, &GUID_WICPixelFormat8bppGray, - &GUID_WICPixelFormat1bppIndexed, - &GUID_WICPixelFormat2bppIndexed, - &GUID_WICPixelFormat4bppIndexed, - &GUID_WICPixelFormat8bppIndexed, &GUID_WICPixelFormat24bppBGR, &GUID_WICPixelFormat32bppBGRA, &GUID_WICPixelFormat32bppPBGRA, @@ -1394,16 +1378,6 @@ static struct regsvr_encoder const encoder_list[] = { ".bmp,.dib,.rle", bmp_encode_formats }, - { &CLSID_WICGifEncoder, - "The Wine Project", - "GIF Encoder", - "1.0.0.0", - &GUID_VendorMicrosoft, - &GUID_ContainerFormatGif, - "image/gif", - ".gif", - gif_formats - }, { &CLSID_WICJpegEncoder, "The Wine Project", "JPEG Encoder", @@ -1463,11 +1437,8 @@ static GUID const * const converter_formats[] = { &GUID_WICPixelFormat24bppBGR, &GUID_WICPixelFormat24bppRGB, &GUID_WICPixelFormat32bppBGR, - &GUID_WICPixelFormat32bppRGB, &GUID_WICPixelFormat32bppBGRA, - &GUID_WICPixelFormat32bppRGBA, &GUID_WICPixelFormat32bppPBGRA, - &GUID_WICPixelFormat32bppPRGBA, &GUID_WICPixelFormat32bppGrayFloat, &GUID_WICPixelFormat48bppRGB, &GUID_WICPixelFormat64bppRGBA, @@ -1739,13 +1710,6 @@ static BYTE const channel_mask_16bit2[] = { 0x00, 0x00, 0xff, 0xff, 0x00, 0x00, static BYTE const channel_mask_16bit3[] = { 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0x00, 0x00 }; static BYTE const channel_mask_16bit4[] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff }; -static BYTE const channel_mask_32bit[] = { 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00 }; - -static BYTE const channel_mask_128bit1[] = { 0xff,0xff,0xff,0xff,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 }; -static BYTE const channel_mask_128bit2[] = { 0x00,0x00,0x00,0x00,0xff,0xff,0xff,0xff,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 }; -static BYTE const channel_mask_128bit3[] = { 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xff,0xff,0xff,0xff,0x00,0x00,0x00,0x00 }; -static BYTE const channel_mask_128bit4[] = { 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xff,0xff,0xff,0xff }; - static BYTE const channel_mask_5bit[] = { 0x1f, 0x00 }; static BYTE const channel_mask_5bit2[] = { 0xe0, 0x03 }; static BYTE const channel_mask_5bit3[] = { 0x00, 0x7c }; @@ -1762,9 +1726,6 @@ static BYTE const * const channel_masks_8bit[] = { channel_mask_8bit, static BYTE const * const channel_masks_16bit[] = { channel_mask_16bit, channel_mask_16bit2, channel_mask_16bit3, channel_mask_16bit4}; -static BYTE const * const channel_masks_32bit[] = { channel_mask_32bit }; -static BYTE const * const channel_masks_128bit[] = { channel_mask_128bit1, channel_mask_128bit2, channel_mask_128bit3, channel_mask_128bit4 }; - static BYTE const * const channel_masks_BGRA5551[] = { channel_mask_5bit, channel_mask_5bit2, channel_mask_5bit3, channel_mask_5bit4 }; @@ -1781,7 +1742,7 @@ static struct regsvr_pixelformat const pixelformat_list[] = { 1, /* channel count */ channel_masks_1bit, WICPixelFormatNumericRepresentationIndexed, - 0 + 1 }, { &GUID_WICPixelFormat2bppIndexed, "The Wine Project", @@ -1792,7 +1753,7 @@ static struct regsvr_pixelformat const pixelformat_list[] = { 1, /* channel count */ channel_masks_2bit, WICPixelFormatNumericRepresentationIndexed, - 0 + 1 }, { &GUID_WICPixelFormat4bppIndexed, "The Wine Project", @@ -1803,7 +1764,7 @@ static struct regsvr_pixelformat const pixelformat_list[] = { 1, /* channel count */ channel_masks_4bit, WICPixelFormatNumericRepresentationIndexed, - 0 + 1 }, { &GUID_WICPixelFormat8bppIndexed, "The Wine Project", @@ -1814,7 +1775,7 @@ static struct regsvr_pixelformat const pixelformat_list[] = { 1, /* channel count */ channel_masks_8bit, WICPixelFormatNumericRepresentationIndexed, - 0 + 1 }, { &GUID_WICPixelFormatBlackWhite, "The Wine Project", @@ -1937,17 +1898,6 @@ static struct regsvr_pixelformat const pixelformat_list[] = { WICPixelFormatNumericRepresentationUnsignedInteger, 0 }, - { &GUID_WICPixelFormat32bppRGB, - "The Wine Project", - "32bpp RGB", - NULL, /* no version */ - &GUID_VendorMicrosoft, - 32, /* bitsperpixel */ - 3, /* channel count */ - channel_masks_8bit, - WICPixelFormatNumericRepresentationUnsignedInteger, - 0 - }, { &GUID_WICPixelFormat32bppBGRA, "The Wine Project", "32bpp BGRA", @@ -1959,17 +1909,6 @@ static struct regsvr_pixelformat const pixelformat_list[] = { WICPixelFormatNumericRepresentationUnsignedInteger, 1 }, - { &GUID_WICPixelFormat32bppRGBA, - "The Wine Project", - "32bpp RGBA", - NULL, /* no version */ - &GUID_VendorMicrosoft, - 32, /* bitsperpixel */ - 4, /* channel count */ - channel_masks_8bit, - WICPixelFormatNumericRepresentationUnsignedInteger, - 1 - }, { &GUID_WICPixelFormat32bppPBGRA, "The Wine Project", "32bpp PBGRA", @@ -1981,28 +1920,6 @@ static struct regsvr_pixelformat const pixelformat_list[] = { WICPixelFormatNumericRepresentationUnsignedInteger, 1 }, - { &GUID_WICPixelFormat32bppPRGBA, - "The Wine Project", - "32bpp PRGBA", - NULL, /* no version */ - &GUID_VendorMicrosoft, - 32, /* bitsperpixel */ - 4, /* channel count */ - channel_masks_8bit, - WICPixelFormatNumericRepresentationUnsignedInteger, - 1 - }, - { &GUID_WICPixelFormat32bppGrayFloat, - "The Wine Project", - "32bpp GrayFloat", - NULL, /* no version */ - &GUID_VendorMicrosoft, - 32, /* bitsperpixel */ - 1, /* channel count */ - channel_masks_32bit, - WICPixelFormatNumericRepresentationFloat, - 0 - }, { &GUID_WICPixelFormat48bppRGB, "The Wine Project", "48bpp RGB", @@ -2047,28 +1964,6 @@ static struct regsvr_pixelformat const pixelformat_list[] = { WICPixelFormatNumericRepresentationUnsignedInteger, 0 }, - { &GUID_WICPixelFormat64bppCMYK, - "The Wine Project", - "64bpp CMYK", - NULL, /* no version */ - &GUID_VendorMicrosoft, - 64, /* bitsperpixel */ - 4, /* channel count */ - channel_masks_16bit, - WICPixelFormatNumericRepresentationUnsignedInteger, - 0 - }, - { &GUID_WICPixelFormat128bppRGBAFloat, - "The Wine Project", - "128bpp RGBAFloat", - NULL, /* no version */ - &GUID_VendorMicrosoft, - 128, /* bitsperpixel */ - 4, /* channel count */ - channel_masks_128bit, - WICPixelFormatNumericRepresentationFloat, - 1 - }, { NULL } /* list terminator */ }; diff --git a/dll/win32/windowscodecs/scaler.c b/dll/win32/windowscodecs/scaler.c index a7c2447f53..8e267e314a 100644 --- a/dll/win32/windowscodecs/scaler.c +++ b/dll/win32/windowscodecs/scaler.c @@ -21,7 +21,6 @@ typedef struct BitmapScaler { IWICBitmapScaler IWICBitmapScaler_iface; LONG ref; - IMILBitmapScaler IMILBitmapScaler_iface; IWICBitmapSource *source; UINT width, height; UINT src_width, src_height; @@ -37,11 +36,6 @@ static inline BitmapScaler *impl_from_IWICBitmapScaler(IWICBitmapScaler *iface) return CONTAINING_RECORD(iface, BitmapScaler, IWICBitmapScaler_iface); } -static inline BitmapScaler *impl_from_IMILBitmapScaler(IMILBitmapScaler *iface) -{ - return CONTAINING_RECORD(iface, BitmapScaler, IMILBitmapScaler_iface); -} - static HRESULT WINAPI BitmapScaler_QueryInterface(IWICBitmapScaler *iface, REFIID iid, void **ppv) { @@ -56,13 +50,8 @@ static HRESULT WINAPI BitmapScaler_QueryInterface(IWICBitmapScaler *iface, REFII { *ppv = &This->IWICBitmapScaler_iface; } - else if (IsEqualIID(&IID_IMILBitmapScaler, iid)) - { - *ppv = &This->IMILBitmapScaler_iface; - } else { - FIXME("unknown interface %s\n", debugstr_guid(iid)); *ppv = NULL; return E_NOINTERFACE; } @@ -371,163 +360,6 @@ static const IWICBitmapScalerVtbl BitmapScaler_Vtbl = { BitmapScaler_Initialize }; -static HRESULT WINAPI IMILBitmapScaler_QueryInterface(IMILBitmapScaler *iface, REFIID iid, - void **ppv) -{ - BitmapScaler *This = impl_from_IMILBitmapScaler(iface); - - TRACE("(%p,%s,%p)\n", iface, debugstr_guid(iid), ppv); - - if (!ppv) return E_INVALIDARG; - - if (IsEqualIID(&IID_IUnknown, iid) || - IsEqualIID(&IID_IMILBitmapScaler, iid) || - IsEqualIID(&IID_IMILBitmapSource, iid)) - { - IUnknown_AddRef(&This->IMILBitmapScaler_iface); - *ppv = &This->IMILBitmapScaler_iface; - return S_OK; - } - else if (IsEqualIID(&IID_IWICBitmapScaler, iid) || - IsEqualIID(&IID_IWICBitmapSource, iid)) - { - IUnknown_AddRef(&This->IWICBitmapScaler_iface); - *ppv = &This->IWICBitmapScaler_iface; - return S_OK; - } - - FIXME("unknown interface %s\n", debugstr_guid(iid)); - *ppv = NULL; - return E_NOINTERFACE; -} - -static ULONG WINAPI IMILBitmapScaler_AddRef(IMILBitmapScaler *iface) -{ - BitmapScaler *This = impl_from_IMILBitmapScaler(iface); - return IWICBitmapScaler_AddRef(&This->IWICBitmapScaler_iface); -} - -static ULONG WINAPI IMILBitmapScaler_Release(IMILBitmapScaler *iface) -{ - BitmapScaler *This = impl_from_IMILBitmapScaler(iface); - return IWICBitmapScaler_Release(&This->IWICBitmapScaler_iface); -} - -static HRESULT WINAPI IMILBitmapScaler_GetSize(IMILBitmapScaler *iface, - UINT *width, UINT *height) -{ - BitmapScaler *This = impl_from_IMILBitmapScaler(iface); - - TRACE("(%p,%p,%p)\n", iface, width, height); - - if (!This->source) - return WINCODEC_ERR_NOTINITIALIZED; - - return IWICBitmapScaler_GetSize(&This->IWICBitmapScaler_iface, width, height); -} - -static HRESULT WINAPI IMILBitmapScaler_GetPixelFormat(IMILBitmapScaler *iface, - int *format) -{ - BitmapScaler *This = impl_from_IMILBitmapScaler(iface); - IMILBitmapSource *source; - HRESULT hr; - - TRACE("(%p,%p)\n", iface, format); - - if (!format) return E_INVALIDARG; - - if (!This->source) - return WINCODEC_ERR_NOTINITIALIZED; - - hr = IWICBitmapSource_QueryInterface(This->source, &IID_IMILBitmapSource, (void **)&source); - if (hr == S_OK) - { - hr = source->lpVtbl->GetPixelFormat(source, format); - source->lpVtbl->Release(source); - } - return hr; -} - -static HRESULT WINAPI IMILBitmapScaler_GetResolution(IMILBitmapScaler *iface, - double *dpix, double *dpiy) -{ - BitmapScaler *This = impl_from_IMILBitmapScaler(iface); - - TRACE("(%p,%p,%p)\n", iface, dpix, dpiy); - - if (!This->source) - return WINCODEC_ERR_NOTINITIALIZED; - - return IWICBitmapScaler_GetResolution(&This->IWICBitmapScaler_iface, dpix, dpiy); -} - -static HRESULT WINAPI IMILBitmapScaler_CopyPalette(IMILBitmapScaler *iface, - IWICPalette *palette) -{ - BitmapScaler *This = impl_from_IMILBitmapScaler(iface); - - TRACE("(%p,%p)\n", iface, palette); - - if (!This->source) - return WINCODEC_ERR_NOTINITIALIZED; - - return IWICBitmapScaler_CopyPalette(&This->IWICBitmapScaler_iface, palette); -} - -static HRESULT WINAPI IMILBitmapScaler_CopyPixels(IMILBitmapScaler *iface, - const WICRect *rc, UINT stride, UINT size, BYTE *buffer) -{ - BitmapScaler *This = impl_from_IMILBitmapScaler(iface); - - TRACE("(%p,%p,%u,%u,%p)\n", iface, rc, stride, size, buffer); - - if (!This->source) - return WINCODEC_ERR_NOTINITIALIZED; - - return IWICBitmapScaler_CopyPixels(&This->IWICBitmapScaler_iface, rc, stride, size, buffer); -} - -static HRESULT WINAPI IMILBitmapScaler_unknown1(IMILBitmapScaler *iface, void **ppv) -{ - TRACE("(%p,%p)\n", iface, ppv); - return E_NOINTERFACE; -} - -static HRESULT WINAPI IMILBitmapScaler_Initialize(IMILBitmapScaler *iface, - IMILBitmapSource *mil_source, UINT width, UINT height, - WICBitmapInterpolationMode mode) -{ - BitmapScaler *This = impl_from_IMILBitmapScaler(iface); - IWICBitmapSource *wic_source; - HRESULT hr; - - TRACE("(%p,%p,%u,%u,%u)\n", iface, mil_source, width, height, mode); - - if (!mil_source) return E_INVALIDARG; - - hr = mil_source->lpVtbl->QueryInterface(mil_source, &IID_IWICBitmapSource, (void **)&wic_source); - if (hr == S_OK) - { - hr = IWICBitmapScaler_Initialize(&This->IWICBitmapScaler_iface, wic_source, width, height, mode); - IWICBitmapSource_Release(wic_source); - } - return hr; -} - -static const IMILBitmapScalerVtbl IMILBitmapScaler_Vtbl = { - IMILBitmapScaler_QueryInterface, - IMILBitmapScaler_AddRef, - IMILBitmapScaler_Release, - IMILBitmapScaler_GetSize, - IMILBitmapScaler_GetPixelFormat, - IMILBitmapScaler_GetResolution, - IMILBitmapScaler_CopyPalette, - IMILBitmapScaler_CopyPixels, - IMILBitmapScaler_unknown1, - IMILBitmapScaler_Initialize -}; - HRESULT BitmapScaler_Create(IWICBitmapScaler **scaler) { BitmapScaler *This; @@ -536,7 +368,6 @@ HRESULT BitmapScaler_Create(IWICBitmapScaler **scaler) if (!This) return E_OUTOFMEMORY; This->IWICBitmapScaler_iface.lpVtbl = &BitmapScaler_Vtbl; - This->IMILBitmapScaler_iface.lpVtbl = &IMILBitmapScaler_Vtbl; This->ref = 1; This->source = NULL; This->width = 0; diff --git a/dll/win32/windowscodecs/tiffformat.c b/dll/win32/windowscodecs/tiffformat.c index 740de4955b..55423028a4 100644 --- a/dll/win32/windowscodecs/tiffformat.c +++ b/dll/win32/windowscodecs/tiffformat.c @@ -1,6 +1,5 @@ /* * Copyright 2010 Vincent Povirk for CodeWeavers - * Copyright 2016 Dmitry Timoshkov * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public @@ -304,8 +303,6 @@ static HRESULT tiff_get_decode_info(TIFF *tiff, tiff_decode_info *decode_info) } decode_info->planar = planar; - TRACE("planar %u, photometric %u, samples %u, bps %u\n", planar, photometric, samples, bps); - switch(photometric) { case 0: /* WhiteIsZero */ @@ -370,28 +367,14 @@ static HRESULT tiff_get_decode_info(TIFF *tiff, tiff_decode_info *decode_info) } } break; - case 16: - if (samples != 1) - { - FIXME("unhandled 16bpp grayscale sample count %u\n", samples); - return WINCODEC_ERR_UNSUPPORTEDPIXELFORMAT; - } - decode_info->format = &GUID_WICPixelFormat16bppGray; - break; - case 32: - if (samples != 1) - { - FIXME("unhandled 32bpp grayscale sample count %u\n", samples); - return WINCODEC_ERR_UNSUPPORTEDPIXELFORMAT; - } - decode_info->format = &GUID_WICPixelFormat32bppGrayFloat; - break; default: - WARN("unhandled greyscale bit count %u\n", bps); - return WINCODEC_ERR_UNSUPPORTEDPIXELFORMAT; + FIXME("unhandled greyscale bit count %u\n", bps); + return E_FAIL; } break; case 2: /* RGB */ + decode_info->bpp = bps * samples; + if (samples == 4) { ret = pTIFFGetField(tiff, TIFFTAG_EXTRASAMPLES, &extra_sample_count, &extra_samples); @@ -408,12 +391,8 @@ static HRESULT tiff_get_decode_info(TIFF *tiff, tiff_decode_info *decode_info) return E_FAIL; } - decode_info->bpp = max(bps, 8) * samples; - decode_info->source_bpp = bps * samples; switch(bps) { - case 1: - case 4: case 8: decode_info->reverse_bgr = 1; if (samples == 3) @@ -451,17 +430,9 @@ static HRESULT tiff_get_decode_info(TIFF *tiff, tiff_decode_info *decode_info) return E_FAIL; } break; - case 32: - if (samples != 4) - { - FIXME("unhandled 32bpp RGB sample count %u\n", samples); - return WINCODEC_ERR_UNSUPPORTEDPIXELFORMAT; - } - decode_info->format = &GUID_WICPixelFormat128bppRGBAFloat; - break; default: - WARN("unhandled RGB bit count %u\n", bps); - return WINCODEC_ERR_UNSUPPORTEDPIXELFORMAT; + FIXME("unhandled RGB bit count %u\n", bps); + return E_FAIL; } break; case 3: /* RGB Palette */ @@ -475,12 +446,6 @@ static HRESULT tiff_get_decode_info(TIFF *tiff, tiff_decode_info *decode_info) decode_info->bpp = bps; switch (bps) { - case 1: - decode_info->format = &GUID_WICPixelFormat1bppIndexed; - break; - case 2: - decode_info->format = &GUID_WICPixelFormat2bppIndexed; - break; case 4: decode_info->format = &GUID_WICPixelFormat4bppIndexed; break; @@ -492,31 +457,8 @@ static HRESULT tiff_get_decode_info(TIFF *tiff, tiff_decode_info *decode_info) return E_FAIL; } break; - - case 5: /* Separated */ - if (samples != 4) - { - FIXME("unhandled Separated sample count %u\n", samples); - return E_FAIL; - } - - decode_info->bpp = bps * samples; - switch(bps) - { - case 8: - decode_info->format = &GUID_WICPixelFormat32bppCMYK; - break; - case 16: - decode_info->format = &GUID_WICPixelFormat64bppCMYK; - break; - - default: - WARN("unhandled Separated bit count %u\n", bps); - return WINCODEC_ERR_UNSUPPORTEDPIXELFORMAT; - } - break; - case 4: /* Transparency mask */ + case 5: /* CMYK */ case 6: /* YCbCr */ case 8: /* CIELab */ default: @@ -667,7 +609,6 @@ static HRESULT WINAPI TiffDecoder_Initialize(IWICBitmapDecoder *iface, IStream * { TiffDecoder *This = impl_from_IWICBitmapDecoder(iface); TIFF *tiff; - tiff_decode_info decode_info; HRESULT hr=S_OK; TRACE("(%p,%p,%x)\n", iface, pIStream, cacheOptions); @@ -681,20 +622,13 @@ static HRESULT WINAPI TiffDecoder_Initialize(IWICBitmapDecoder *iface, IStream * } tiff = tiff_open_stream(pIStream, "r"); + if (!tiff) { hr = E_FAIL; goto exit; } - /* make sure that TIFF format is supported */ - hr = tiff_get_decode_info(tiff, &decode_info); - if (hr != S_OK) - { - pTIFFClose(tiff); - goto exit; - } - This->tiff = tiff; This->stream = pIStream; IStream_AddRef(pIStream); @@ -743,12 +677,8 @@ static HRESULT WINAPI TiffDecoder_CopyPalette(IWICBitmapDecoder *iface, static HRESULT WINAPI TiffDecoder_GetMetadataQueryReader(IWICBitmapDecoder *iface, IWICMetadataQueryReader **ppIMetadataQueryReader) { - TRACE("(%p,%p)\n", iface, ppIMetadataQueryReader); - - if (!ppIMetadataQueryReader) return E_INVALIDARG; - - *ppIMetadataQueryReader = NULL; - return WINCODEC_ERR_UNSUPPORTEDOPERATION; + FIXME("(%p,%p): stub\n", iface, ppIMetadataQueryReader); + return E_NOTIMPL; } static HRESULT WINAPI TiffDecoder_GetPreview(IWICBitmapDecoder *iface, @@ -1010,183 +940,34 @@ static HRESULT WINAPI TiffFrameDecode_CopyPalette(IWICBitmapFrameDecode *iface, static HRESULT TiffFrameDecode_ReadTile(TiffFrameDecode *This, UINT tile_x, UINT tile_y) { + HRESULT hr=S_OK; tsize_t ret; int swap_bytes; swap_bytes = pTIFFIsByteSwapped(This->parent->tiff); ret = pTIFFSetDirectory(This->parent->tiff, This->index); - if (ret == -1) - return E_FAIL; - - if (This->decode_info.tiled) - ret = pTIFFReadEncodedTile(This->parent->tiff, tile_x + tile_y * This->decode_info.tiles_across, This->cached_tile, This->decode_info.tile_size); - else - ret = pTIFFReadEncodedStrip(This->parent->tiff, tile_y, This->cached_tile, This->decode_info.tile_size); if (ret == -1) - return E_FAIL; + hr = E_FAIL; - /* 3bpp RGB */ - if (This->decode_info.source_bpp == 3 && This->decode_info.samples == 3 && This->decode_info.bpp == 24) + if (hr == S_OK) { - BYTE *srcdata, *src, *dst; - DWORD x, y, count, width_bytes = (This->decode_info.tile_width * 3 + 7) / 8; - - count = width_bytes * This->decode_info.tile_height; - - srcdata = HeapAlloc(GetProcessHeap(), 0, count); - if (!srcdata) return E_OUTOFMEMORY; - memcpy(srcdata, This->cached_tile, count); - - for (y = 0; y < This->decode_info.tile_height; y++) + if (This->decode_info.tiled) { - src = srcdata + y * width_bytes; - dst = This->cached_tile + y * This->decode_info.tile_width * 3; - - for (x = 0; x < This->decode_info.tile_width; x += 8) - { - dst[2] = (src[0] & 0x80) ? 0xff : 0; /* R */ - dst[1] = (src[0] & 0x40) ? 0xff : 0; /* G */ - dst[0] = (src[0] & 0x20) ? 0xff : 0; /* B */ - if (x + 1 < This->decode_info.tile_width) - { - dst[5] = (src[0] & 0x10) ? 0xff : 0; /* R */ - dst[4] = (src[0] & 0x08) ? 0xff : 0; /* G */ - dst[3] = (src[0] & 0x04) ? 0xff : 0; /* B */ - } - if (x + 2 < This->decode_info.tile_width) - { - dst[8] = (src[0] & 0x02) ? 0xff : 0; /* R */ - dst[7] = (src[0] & 0x01) ? 0xff : 0; /* G */ - dst[6] = (src[1] & 0x80) ? 0xff : 0; /* B */ - } - if (x + 3 < This->decode_info.tile_width) - { - dst[11] = (src[1] & 0x40) ? 0xff : 0; /* R */ - dst[10] = (src[1] & 0x20) ? 0xff : 0; /* G */ - dst[9] = (src[1] & 0x10) ? 0xff : 0; /* B */ - } - if (x + 4 < This->decode_info.tile_width) - { - dst[14] = (src[1] & 0x08) ? 0xff : 0; /* R */ - dst[13] = (src[1] & 0x04) ? 0xff : 0; /* G */ - dst[12] = (src[1] & 0x02) ? 0xff : 0; /* B */ - } - if (x + 5 < This->decode_info.tile_width) - { - dst[17] = (src[1] & 0x01) ? 0xff : 0; /* R */ - dst[16] = (src[2] & 0x80) ? 0xff : 0; /* G */ - dst[15] = (src[2] & 0x40) ? 0xff : 0; /* B */ - } - if (x + 6 < This->decode_info.tile_width) - { - dst[20] = (src[2] & 0x20) ? 0xff : 0; /* R */ - dst[19] = (src[2] & 0x10) ? 0xff : 0; /* G */ - dst[18] = (src[2] & 0x08) ? 0xff : 0; /* B */ - } - if (x + 7 < This->decode_info.tile_width) - { - dst[23] = (src[2] & 0x04) ? 0xff : 0; /* R */ - dst[22] = (src[2] & 0x02) ? 0xff : 0; /* G */ - dst[21] = (src[2] & 0x01) ? 0xff : 0; /* B */ - } - src += 3; - dst += 24; - } + ret = pTIFFReadEncodedTile(This->parent->tiff, tile_x + tile_y * This->decode_info.tiles_across, This->cached_tile, This->decode_info.tile_size); } - - HeapFree(GetProcessHeap(), 0, srcdata); - } - /* 12bpp RGB */ - else if (This->decode_info.source_bpp == 12 && This->decode_info.samples == 3 && This->decode_info.bpp == 24) - { - BYTE *srcdata, *src, *dst; - DWORD x, y, count, width_bytes = (This->decode_info.tile_width * 12 + 7) / 8; - - count = width_bytes * This->decode_info.tile_height; - - srcdata = HeapAlloc(GetProcessHeap(), 0, count); - if (!srcdata) return E_OUTOFMEMORY; - memcpy(srcdata, This->cached_tile, count); - - for (y = 0; y < This->decode_info.tile_height; y++) + else { - src = srcdata + y * width_bytes; - dst = This->cached_tile + y * This->decode_info.tile_width * 3; - - for (x = 0; x < This->decode_info.tile_width; x += 2) - { - dst[0] = ((src[1] & 0xf0) >> 4) * 17; /* B */ - dst[1] = (src[0] & 0x0f) * 17; /* G */ - dst[2] = ((src[0] & 0xf0) >> 4) * 17; /* R */ - if (x + 1 < This->decode_info.tile_width) - { - dst[5] = (src[1] & 0x0f) * 17; /* B */ - dst[4] = ((src[2] & 0xf0) >> 4) * 17; /* G */ - dst[3] = (src[2] & 0x0f) * 17; /* R */ - } - src += 3; - dst += 6; - } + ret = pTIFFReadEncodedStrip(This->parent->tiff, tile_y, This->cached_tile, This->decode_info.tile_size); } - HeapFree(GetProcessHeap(), 0, srcdata); - } - /* 4bpp RGBA */ - else if (This->decode_info.source_bpp == 4 && This->decode_info.samples == 4 && This->decode_info.bpp == 32) - { - BYTE *src, *dst; - DWORD count; - - /* 1 source byte expands to 2 BGRA samples */ - count = (This->decode_info.tile_width * This->decode_info.tile_height + 1) / 2; - - src = This->cached_tile + count - 1; - dst = This->cached_tile + This->decode_info.tile_size; - - while (count--) - { - BYTE b = *src--; - - dst -= 8; - dst[2] = (b & 0x80) ? 0xff : 0; /* R */ - dst[1] = (b & 0x40) ? 0xff : 0; /* G */ - dst[0] = (b & 0x20) ? 0xff : 0; /* B */ - dst[3] = (b & 0x10) ? 0xff : 0; /* A */ - dst[6] = (b & 0x08) ? 0xff : 0; /* R */ - dst[5] = (b & 0x04) ? 0xff : 0; /* G */ - dst[4] = (b & 0x02) ? 0xff : 0; /* B */ - dst[7] = (b & 0x01) ? 0xff : 0; /* A */ - } + if (ret == -1) + hr = E_FAIL; } - /* 16bpp RGBA */ - else if (This->decode_info.source_bpp == 16 && This->decode_info.samples == 4 && This->decode_info.bpp == 32) - { - BYTE *src, *dst; - DWORD count = This->decode_info.tile_width * This->decode_info.tile_height; - src = This->cached_tile + count * 2; - dst = This->cached_tile + This->decode_info.tile_size; - - while (count--) - { - BYTE b[2]; - - src -= 2; - dst -= 4; - - b[0] = src[0]; - b[1] = src[1]; - - dst[0] = ((b[1] & 0xf0) >> 4) * 17; /* B */ - dst[1] = (b[0] & 0x0f) * 17; /* G */ - dst[2] = ((b[0] & 0xf0) >> 4) * 17; /* R */ - dst[3] = (b[1] & 0x0f) * 17; /* A */ - } - } /* 8bpp grayscale with extra alpha */ - else if (This->decode_info.source_bpp == 16 && This->decode_info.samples == 2 && This->decode_info.bpp == 32) + if (hr == S_OK && This->decode_info.source_bpp == 16 && This->decode_info.samples == 2 && This->decode_info.bpp == 32) { BYTE *src; DWORD *dst, count = This->decode_info.tile_width * This->decode_info.tile_height; @@ -1201,7 +982,7 @@ static HRESULT TiffFrameDecode_ReadTile(TiffFrameDecode *This, UINT tile_x, UINT } } - if (This->decode_info.reverse_bgr) + if (hr == S_OK && This->decode_info.reverse_bgr) { if (This->decode_info.bps == 8) { @@ -1212,7 +993,7 @@ static HRESULT TiffFrameDecode_ReadTile(TiffFrameDecode *This, UINT tile_x, UINT } } - if (swap_bytes && This->decode_info.bps > 8) + if (hr == S_OK && swap_bytes && This->decode_info.bps > 8) { UINT row, i, samples_per_row; BYTE *sample, temp; @@ -1240,7 +1021,7 @@ static HRESULT TiffFrameDecode_ReadTile(TiffFrameDecode *This, UINT tile_x, UINT } } - if (This->decode_info.invert_grayscale) + if (hr == S_OK && This->decode_info.invert_grayscale) { BYTE *byte, *end; @@ -1256,10 +1037,13 @@ static HRESULT TiffFrameDecode_ReadTile(TiffFrameDecode *This, UINT tile_x, UINT *byte = ~(*byte); } - This->cached_tile_x = tile_x; - This->cached_tile_y = tile_y; + if (hr == S_OK) + { + This->cached_tile_x = tile_x; + This->cached_tile_y = tile_y; + } - return S_OK; + return hr; } static HRESULT WINAPI TiffFrameDecode_CopyPixels(IWICBitmapFrameDecode *iface, @@ -1296,7 +1080,7 @@ static HRESULT WINAPI TiffFrameDecode_CopyPixels(IWICBitmapFrameDecode *iface, if (cbStride < bytesperrow) return E_INVALIDARG; - if ((cbStride * (prc->Height-1)) + ((prc->Width * This->decode_info.bpp) + 7)/8 > cbBufferSize) + if ((cbStride * prc->Height) > cbBufferSize) return E_INVALIDARG; min_tile_x = prc->X / This->decode_info.tile_width; @@ -1610,10 +1394,6 @@ static const struct tiff_encode_format formats[] = { {&GUID_WICPixelFormat48bppRGB, 2, 16, 3, 48, 0, 0, 0}, {&GUID_WICPixelFormat64bppRGBA, 2, 16, 4, 64, 1, 2, 0}, {&GUID_WICPixelFormat64bppPRGBA, 2, 16, 4, 64, 1, 1, 0}, - {&GUID_WICPixelFormat1bppIndexed, 3, 1, 1, 1, 0, 0, 0}, - {&GUID_WICPixelFormat2bppIndexed, 3, 2, 1, 2, 0, 0, 0}, - {&GUID_WICPixelFormat4bppIndexed, 3, 4, 1, 4, 0, 0, 0}, - {&GUID_WICPixelFormat8bppIndexed, 3, 8, 1, 8, 0, 0, 0}, {0} }; @@ -1896,21 +1676,6 @@ static HRESULT WINAPI TiffFrameEncode_WritePixels(IWICBitmapFrameEncode *iface, pTIFFSetField(This->parent->tiff, TIFFTAG_YRESOLUTION, (float)This->yres); } - if (This->format->bpp <= 8 && This->colors && !IsEqualGUID(This->format->guid, &GUID_WICPixelFormatBlackWhite)) - { - uint16 red[256], green[256], blue[256]; - UINT i; - - for (i = 0; i < This->colors; i++) - { - red[i] = (This->palette[i] >> 8) & 0xff00; - green[i] = This->palette[i] & 0xff00; - blue[i] = (This->palette[i] << 8) & 0xff00; - } - - pTIFFSetField(This->parent->tiff, TIFFTAG_COLORMAP, red, green, blue); - } - This->info_written = TRUE; } @@ -2109,22 +1874,11 @@ static HRESULT WINAPI TiffEncoder_GetContainerFormat(IWICBitmapEncoder *iface, return S_OK; } -static HRESULT WINAPI TiffEncoder_GetEncoderInfo(IWICBitmapEncoder *iface, IWICBitmapEncoderInfo **info) +static HRESULT WINAPI TiffEncoder_GetEncoderInfo(IWICBitmapEncoder *iface, + IWICBitmapEncoderInfo **ppIEncoderInfo) { - IWICComponentInfo *comp_info; - HRESULT hr; - - TRACE("%p,%p\n", iface, info); - - if (!info) return E_INVALIDARG; - - hr = CreateComponentInfo(&CLSID_WICTiffEncoder, &comp_info); - if (hr == S_OK) - { - hr = IWICComponentInfo_QueryInterface(comp_info, &IID_IWICBitmapEncoderInfo, (void **)info); - IWICComponentInfo_Release(comp_info); - } - return hr; + FIXME("(%p,%p): stub\n", iface, ppIEncoderInfo); + return E_NOTIMPL; } static HRESULT WINAPI TiffEncoder_SetColorContexts(IWICBitmapEncoder *iface, @@ -2184,7 +1938,7 @@ static HRESULT WINAPI TiffEncoder_CreateNewFrame(IWICBitmapEncoder *iface, hr = E_FAIL; } - if (SUCCEEDED(hr) && ppIEncoderOptions) + if (SUCCEEDED(hr)) { PROPBAG2 opts[2]= {{0}}; opts[0].pstrName = (LPOLESTR)wszTiffCompressionMethod; @@ -2202,7 +1956,7 @@ static HRESULT WINAPI TiffEncoder_CreateNewFrame(IWICBitmapEncoder *iface, VARIANT v; VariantInit(&v); V_VT(&v) = VT_UI1; - V_UI1(&v) = WICTiffCompressionDontCare; + V_UNION(&v, bVal) = WICTiffCompressionDontCare; hr = IPropertyBag2_Write(*ppIEncoderOptions, 1, opts, &v); VariantClear(&v); if (FAILED(hr)) @@ -2244,7 +1998,7 @@ static HRESULT WINAPI TiffEncoder_CreateNewFrame(IWICBitmapEncoder *iface, else hr = E_OUTOFMEMORY; - if (FAILED(hr) && ppIEncoderOptions) + if (FAILED(hr)) { IPropertyBag2_Release(*ppIEncoderOptions); *ppIEncoderOptions = NULL; diff --git a/dll/win32/windowscodecs/wincodecs_private.h b/dll/win32/windowscodecs/wincodecs_private.h index 96ee8fd069..99daf093ad 100644 --- a/dll/win32/windowscodecs/wincodecs_private.h +++ b/dll/win32/windowscodecs/wincodecs_private.h @@ -55,13 +55,7 @@ DEFINE_GUID(GUID_WineContainerFormatTga, 0x0c44fda1,0xa5c5,0x4298,0x96,0x85,0x47 DEFINE_GUID(GUID_VendorWine, 0xddf46da1,0x7dc1,0x404e,0x98,0xf2,0xef,0xa4,0x8d,0xfc,0x95,0x0a); -DEFINE_GUID(IID_IMILBitmap,0xb1784d3f,0x8115,0x4763,0x13,0xaa,0x32,0xed,0xdb,0x68,0x29,0x4a); DEFINE_GUID(IID_IMILBitmapSource,0x7543696a,0xbc8d,0x46b0,0x5f,0x81,0x8d,0x95,0x72,0x89,0x72,0xbe); -DEFINE_GUID(IID_IMILBitmapLock,0xa67b2b53,0x8fa1,0x4155,0x8f,0x64,0x0c,0x24,0x7a,0x8f,0x84,0xcd); -DEFINE_GUID(IID_IMILBitmapScaler,0xa767b0f0,0x1c8c,0x4aef,0x56,0x8f,0xad,0xf9,0x6d,0xcf,0xd5,0xcb); -DEFINE_GUID(IID_IMILFormatConverter,0x7e2a746f,0x25c5,0x4851,0xb3,0xaf,0x44,0x3b,0x79,0x63,0x9e,0xc0); -DEFINE_GUID(IID_IMILPalette,0xca8e206f,0xf22c,0x4af7,0x6f,0xba,0x7b,0xed,0x5e,0xb1,0xc9,0x2f); - #define INTERFACE IMILBitmapSource DECLARE_INTERFACE_(IMILBitmapSource,IUnknown) { @@ -69,58 +63,16 @@ DECLARE_INTERFACE_(IMILBitmapSource,IUnknown) STDMETHOD_(HRESULT,QueryInterface)(THIS_ REFIID,void **) PURE; STDMETHOD_(ULONG,AddRef)(THIS) PURE; STDMETHOD_(ULONG,Release)(THIS) PURE; - /*** IWICBitmapSource methods ***/ - STDMETHOD_(HRESULT,GetSize)(THIS_ UINT *,UINT *) PURE; - STDMETHOD_(HRESULT,GetPixelFormat)(THIS_ int *) PURE; - STDMETHOD_(HRESULT,GetResolution)(THIS_ double *,double *) PURE; - STDMETHOD_(HRESULT,CopyPalette)(THIS_ IWICPalette *) PURE; - STDMETHOD_(HRESULT,CopyPixels)(THIS_ const WICRect *,UINT,UINT,BYTE *) PURE; /*** IMILBitmapSource methods ***/ - STDMETHOD_(HRESULT,unknown1)(THIS_ void **) PURE; - STDMETHOD_(HRESULT,Lock)(THIS_ const WICRect *,DWORD,IWICBitmapLock **) PURE; - STDMETHOD_(HRESULT,Unlock)(THIS_ IWICBitmapLock *) PURE; - STDMETHOD_(HRESULT,SetPalette)(THIS_ IWICPalette *) PURE; - STDMETHOD_(HRESULT,SetResolution)(THIS_ double,double) PURE; - STDMETHOD_(HRESULT,AddDirtyRect)(THIS_ const WICRect *) PURE; + STDMETHOD_(HRESULT,GetSize)(THIS_ UINT *,UINT *); + STDMETHOD_(HRESULT,GetPixelFormat)(THIS_ int *); + STDMETHOD_(HRESULT,GetResolution)(THIS_ double *,double *); + STDMETHOD_(HRESULT,CopyPalette)(THIS_ IWICPalette *); + STDMETHOD_(HRESULT,CopyPixels)(THIS_ const WICRect *,UINT,UINT,BYTE *); + STDMETHOD_(HRESULT,UnknownMethod1)(THIS_ void **); }; #undef INTERFACE -#define INTERFACE IMILBitmapScaler -DECLARE_INTERFACE_(IMILBitmapScaler,IUnknown) -{ - /*** IUnknown methods ***/ - STDMETHOD_(HRESULT,QueryInterface)(THIS_ REFIID,void **) PURE; - STDMETHOD_(ULONG,AddRef)(THIS) PURE; - STDMETHOD_(ULONG,Release)(THIS) PURE; - /*** IWICBitmapSource methods ***/ - STDMETHOD_(HRESULT,GetSize)(THIS_ UINT *,UINT *) PURE; - STDMETHOD_(HRESULT,GetPixelFormat)(THIS_ int *) PURE; - STDMETHOD_(HRESULT,GetResolution)(THIS_ double *,double *) PURE; - STDMETHOD_(HRESULT,CopyPalette)(THIS_ IWICPalette *) PURE; - STDMETHOD_(HRESULT,CopyPixels)(THIS_ const WICRect *,UINT,UINT,BYTE *) PURE; - /*** IMILBitmapScaler methods ***/ - STDMETHOD_(HRESULT,unknown1)(THIS_ void **) PURE; - STDMETHOD_(HRESULT,Initialize)(THIS_ IMILBitmapSource *,UINT,UINT,WICBitmapInterpolationMode); -}; -#undef INTERFACE - -#ifdef __i386__ /* thiscall functions are i386-specific */ - -#define THISCALL(func) __thiscall_ ## func -#define DEFINE_THISCALL_WRAPPER(func,args) \ - extern typeof(func) THISCALL(func); \ - __ASM_STDCALL_FUNC(__thiscall_ ## func, args, \ - "popl %eax\n\t" \ - "pushl %ecx\n\t" \ - "pushl %eax\n\t" \ - "jmp " __ASM_NAME(#func) __ASM_STDCALL(args) ) -#else /* __i386__ */ - -#define THISCALL(func) func -#define DEFINE_THISCALL_WRAPPER(func,args) /* nothing */ - -#endif /* __i386__ */ - #define INTERFACE IMILUnknown1 DECLARE_INTERFACE_(IMILUnknown1,IUnknown) { @@ -128,19 +80,6 @@ DECLARE_INTERFACE_(IMILUnknown1,IUnknown) STDMETHOD_(HRESULT,QueryInterface)(THIS_ REFIID,void **) PURE; STDMETHOD_(ULONG,AddRef)(THIS) PURE; STDMETHOD_(ULONG,Release)(THIS) PURE; - /*** thiscall method ***/ - STDMETHOD_(void,unknown1)(THIS_ void*) PURE; - /*** stdcall ***/ - STDMETHOD_(HRESULT,unknown2)(THIS_ void*, void*) PURE; - /*** thiscall method ***/ - STDMETHOD_(HRESULT,unknown3)(THIS_ void*) PURE; - /*** stdcall ***/ - STDMETHOD_(HRESULT,unknown4)(THIS_ void*) PURE; - STDMETHOD_(HRESULT,unknown5)(THIS_ void*) PURE; - STDMETHOD_(HRESULT,unknown6)(THIS_ DWORD64) PURE; - STDMETHOD_(HRESULT,unknown7)(THIS_ void*) PURE; - /*** thiscall method ***/ - STDMETHOD_(HRESULT,unknown8)(THIS) PURE; }; #undef INTERFACE @@ -152,9 +91,7 @@ DECLARE_INTERFACE_(IMILUnknown2,IUnknown) STDMETHOD_(ULONG,AddRef)(THIS) PURE; STDMETHOD_(ULONG,Release)(THIS) PURE; /*** unknown methods ***/ - STDMETHOD_(HRESULT,unknown1)(THIS_ void *,void **) PURE; - STDMETHOD_(HRESULT,unknown2)(THIS_ void *,void *) PURE; - STDMETHOD_(HRESULT,unknown3)(THIS_ void *) PURE; + STDMETHOD_(HRESULT,UnknownMethod1)(THIS_ void *, void *) PURE; }; #undef INTERFACE @@ -169,7 +106,6 @@ extern HRESULT PngEncoder_CreateInstance(REFIID iid, void** ppv) DECLSPEC_HIDDEN extern HRESULT BmpEncoder_CreateInstance(REFIID iid, void** ppv) DECLSPEC_HIDDEN; extern HRESULT DibDecoder_CreateInstance(REFIID iid, void** ppv) DECLSPEC_HIDDEN; extern HRESULT GifDecoder_CreateInstance(REFIID riid, void** ppv) DECLSPEC_HIDDEN; -extern HRESULT GifEncoder_CreateInstance(REFIID iid, void** ppv) DECLSPEC_HIDDEN; extern HRESULT IcoDecoder_CreateInstance(REFIID iid, void** ppv) DECLSPEC_HIDDEN; extern HRESULT JpegDecoder_CreateInstance(REFIID iid, void** ppv) DECLSPEC_HIDDEN; extern HRESULT JpegEncoder_CreateInstance(REFIID iid, void** ppv) DECLSPEC_HIDDEN; diff --git a/dll/win32/windowscodecs/windowscodecs.spec b/dll/win32/windowscodecs/windowscodecs.spec index 424b3075ce..8fd2470f11 100644 --- a/dll/win32/windowscodecs/windowscodecs.spec +++ b/dll/win32/windowscodecs/windowscodecs.spec @@ -105,8 +105,7 @@ @ stdcall IWICStream_InitializeFromIStream_Proxy(ptr ptr) IWICStream_InitializeFromIStream_Proxy_W @ stdcall IWICStream_InitializeFromMemory_Proxy(ptr ptr long) IWICStream_InitializeFromMemory_Proxy_W @ stdcall WICConvertBitmapSource(ptr ptr ptr) -@ stdcall WICCreateBitmapFromSection(long long ptr long long long ptr) -@ stdcall WICCreateBitmapFromSectionEx(long long ptr long long long long ptr) +@ stdcall -stub WICCreateBitmapFromSection(long long ptr long long long ptr) @ stdcall WICCreateColorContext_Proxy(ptr ptr) @ stdcall WICCreateImagingFactory_Proxy(long ptr) @ stub WICGetMetadataContentSize diff --git a/dll/win32/windowscodecs/windowscodecs_wincodec.idl b/dll/win32/windowscodecs/windowscodecs_wincodec.idl index fec63d04e1..33c0d4a580 100644 --- a/dll/win32/windowscodecs/windowscodecs_wincodec.idl +++ b/dll/win32/windowscodecs/windowscodecs_wincodec.idl @@ -76,13 +76,6 @@ coclass WICBmpEncoder { interface IWICBitmapEncoder; } ] coclass WICGifDecoder { interface IWICBitmapDecoder; } -[ - helpstring("WIC GIF Encoder"), - threading(both), - uuid(114f5598-0b22-40a0-86a1-c83ea495adbd) -] -coclass WICGifEncoder { interface IWICBitmapEncoder; } - [ helpstring("WIC ICO Decoder"), threading(both), diff --git a/media/doc/README.WINE b/media/doc/README.WINE index b94e76dc58..d1c733260d 100644 --- a/media/doc/README.WINE +++ b/media/doc/README.WINE @@ -196,7 +196,7 @@ reactos/dll/win32/version # Synced to Wine-3.0 reactos/dll/win32/vssapi # Synced to WineStaging-2.9 reactos/dll/win32/wbemdisp # Synced to Wine-3.0 reactos/dll/win32/wbemprox # Synced to Wine-3.0 -reactos/dll/win32/windowscodecs # Synced to WineStaging-2.16 +reactos/dll/win32/windowscodecs # Synced to Wine-3.0 reactos/dll/win32/windowscodecsext # Synced to WineStaging-2.9 reactos/dll/win32/winemp3.acm # Synced to WineStaging-2.16 reactos/dll/win32/wing32 # Synced to WineStaging-2.9
1
0
0
0
01/01: [WBEMPROX_WINETEST] Sync with Wine 3.0. CORE-14225
by Amine Khaldi
20 Jan '18
20 Jan '18
https://git.reactos.org/?p=reactos.git;a=commitdiff;h=71b8c8c1e26b05ce6e9b4…
commit 71b8c8c1e26b05ce6e9b48e2c83bd7816ce8d434 Author: Amine Khaldi <amine.khaldi(a)reactos.org> AuthorDate: Sat Jan 20 13:48:13 2018 +0100 Commit: Amine Khaldi <amine.khaldi(a)reactos.org> CommitDate: Sat Jan 20 13:48:13 2018 +0100 [WBEMPROX_WINETEST] Sync with Wine 3.0. CORE-14225 --- modules/rostests/winetests/wbemprox/query.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/modules/rostests/winetests/wbemprox/query.c b/modules/rostests/winetests/wbemprox/query.c index 8ff98036bd..79b09c0966 100644 --- a/modules/rostests/winetests/wbemprox/query.c +++ b/modules/rostests/winetests/wbemprox/query.c @@ -106,8 +106,14 @@ static void test_select( IWbemServices *services ) {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ', 'W','i','n','3','2','_','V','i','d','e','o','C','o','n','t','r','o','l','l','e','r',' ','w','h','e','r','e',' ', 'a','v','a','i','l','a','b','i','l','i','t','y',' ','=',' ','\'','3','\'',0}; + static const WCHAR query12[] = + {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ','W','i','n','3','2','_','B','I','O','S', + ' ','W','H','E','R','E',' ','N','A','M','E',' ','<','>',' ','N','U','L','L', 0}; + static const WCHAR query13[] = + {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ','W','i','n','3','2','_','B','I','O','S', + ' ','W','H','E','R','E',' ','N','U','L','L',' ','=',' ','N','A','M','E', 0}; static const WCHAR *test[] = { query1, query2, query3, query4, query5, query6, query7, query8, query9, query10, - query11 }; + query11, query12, query13 }; HRESULT hr; IEnumWbemClassObject *result; BSTR wql = SysAllocString( wqlW ); @@ -1012,6 +1018,7 @@ static void test_SystemSecurity( IWbemServices *services ) win_skip( "__SystemSecurity not available\n" ); return; } + IWbemClassObject_Release( reg ); sid_size = sizeof(sid_admin_buffer); ret = CreateWellKnownSid( WinBuiltinAdministratorsSid, NULL, sid_admin, &sid_size ); @@ -1297,6 +1304,7 @@ static void test_PhysicalMemory( IWbemServices *services ) VariantClear( &val ); IWbemClassObject_Release( obj ); + IEnumWbemClassObject_Release( result ); SysFreeString( query ); SysFreeString( wql ); }
1
0
0
0
01/01: [WBEMPROX] Sync with Wine 3.0. CORE-14225
by Amine Khaldi
20 Jan '18
20 Jan '18
https://git.reactos.org/?p=reactos.git;a=commitdiff;h=7e99651d65d8c33404119…
commit 7e99651d65d8c33404119d0916d5072813449a8f Author: Amine Khaldi <amine.khaldi(a)reactos.org> AuthorDate: Sat Jan 20 13:47:34 2018 +0100 Commit: Amine Khaldi <amine.khaldi(a)reactos.org> CommitDate: Sat Jan 20 13:47:34 2018 +0100 [WBEMPROX] Sync with Wine 3.0. CORE-14225 --- dll/win32/wbemprox/builtin.c | 134 +++------------- dll/win32/wbemprox/wql.tab.c | 356 ++++++++++++++++++++++++------------------- dll/win32/wbemprox/wql.y | 36 +++-- media/doc/README.WINE | 2 +- 4 files changed, 241 insertions(+), 287 deletions(-) diff --git a/dll/win32/wbemprox/builtin.c b/dll/win32/wbemprox/builtin.c index bf92d3c35e..d32b72f9fb 100644 --- a/dll/win32/wbemprox/builtin.c +++ b/dll/win32/wbemprox/builtin.c @@ -136,10 +136,6 @@ static const WCHAR prop_codesetW[] = {'C','o','d','e','S','e','t',0}; static const WCHAR prop_commandlineW[] = {'C','o','m','m','a','n','d','L','i','n','e',0}; -#ifndef __REACTOS__ -static const WCHAR prop_configmanagererrorcodeW[] = - {'C','o','n','f','i','g','M','a','n','a','g','e','r','E','r','r','o','r','C','o','d','e',0}; -#endif static const WCHAR prop_countrycodeW[] = {'C','o','u','n','t','r','y','C','o','d','e',0}; static const WCHAR prop_cpustatusW[] = @@ -192,10 +188,6 @@ static const WCHAR prop_domainroleW[] = {'D','o','m','a','i','n','R','o','l','e',0}; static const WCHAR prop_driveW[] = {'D','r','i','v','e',0}; -#ifndef __REACTOS__ -static const WCHAR prop_driverdateW[] = - {'D','r','i','v','e','r','D','a','t','e',0}; -#endif static const WCHAR prop_drivernameW[] = {'D','r','i','v','e','r','N','a','m','e',0}; #ifndef __REACTOS__ @@ -212,8 +204,6 @@ static const WCHAR prop_flavorW[] = {'F','l','a','v','o','r',0}; static const WCHAR prop_freespaceW[] = {'F','r','e','e','S','p','a','c','e',0}; -static const WCHAR prop_freephysicalmemoryW[] = - {'F','r','e','e','P','h','y','s','i','c','a','l','M','e','m','o','r','y',0}; static const WCHAR prop_handleW[] = {'H','a','n','d','l','e',0}; static const WCHAR prop_horizontalresolutionW[] = @@ -228,10 +218,6 @@ static const WCHAR prop_indexW[] = {'I','n','d','e','x',0}; static const WCHAR prop_installdateW[] = {'I','n','s','t','a','l','l','D','a','t','e',0}; -#ifndef __REACTOS__ -static const WCHAR prop_installeddisplaydriversW[]= - {'I','n','s','t','a','l','l','e','d','D','i','s','p','l','a','y','D','r','i','v','e','r','s',0}; -#endif static const WCHAR prop_interfaceindexW[] = {'I','n','t','e','r','f','a','c','e','I','n','d','e','x',0}; static const WCHAR prop_interfacetypeW[] = @@ -250,8 +236,6 @@ static const WCHAR prop_localdatetimeW[] = {'L','o','c','a','l','D','a','t','e','T','i','m','e',0}; static const WCHAR prop_localeW[] = {'L','o','c','a','l','e',0}; -static const WCHAR prop_locationW[] = - {'L','o','c','a','t','i','o','n',0}; static const WCHAR prop_lockpresentW[] = {'L','o','c','k','P','r','e','s','e','n','t',0}; static const WCHAR prop_macaddressW[] = @@ -298,8 +282,6 @@ static const WCHAR prop_pixelsperxlogicalinchW[] = {'P','i','x','e','l','s','P','e','r','X','L','o','g','i','c','a','l','I','n','c','h',0}; static const WCHAR prop_pnpdeviceidW[] = {'P','N','P','D','e','v','i','c','e','I','D',0}; -static const WCHAR prop_portnameW[] = - {'P','o','r','t','N','a','m','e',0}; static const WCHAR prop_pprocessidW[] = {'P','a','r','e','n','t','P','r','o','c','e','s','s','I','D',0}; static const WCHAR prop_primaryW[] = @@ -344,10 +326,6 @@ static const WCHAR prop_startingoffsetW[] = {'S','t','a','r','t','i','n','g','O','f','f','s','e','t',0}; static const WCHAR prop_stateW[] = {'S','t','a','t','e',0}; -#ifndef __REACTOS__ -static const WCHAR prop_statusW[] = - {'S','t','a','t','u','s',0}; -#endif static const WCHAR prop_statusinfoW[] = {'S','t','a','t','u','s','I','n','f','o',0}; static const WCHAR prop_strvalueW[] = @@ -380,8 +358,6 @@ static const WCHAR prop_varianttypeW[] = {'V','a','r','i','a','n','t','T','y','p','e',0}; static const WCHAR prop_versionW[] = {'V','e','r','s','i','o','n',0}; -static const WCHAR prop_vendorW[] = - {'V','e','n','d','o','r',0}; #ifndef __REACTOS__ static const WCHAR prop_videoarchitectureW[] = {'V','i','d','e','o','A','r','c','h','i','t','e','c','t','u','r','e',0}; @@ -445,8 +421,7 @@ static const struct column col_compsys[] = static const struct column col_compsysproduct[] = { { prop_identifyingnumberW, CIM_STRING|COL_FLAG_KEY }, - { prop_uuidW, CIM_STRING|COL_FLAG_DYNAMIC }, - { prop_vendorW, CIM_STRING }, + { prop_uuidW, CIM_STRING|COL_FLAG_DYNAMIC } }; static const struct column col_datafile[] = { @@ -554,7 +529,6 @@ static const struct column col_os[] = { prop_systemdirectoryW, CIM_STRING|COL_FLAG_DYNAMIC }, { prop_totalvirtualmemorysizeW, CIM_UINT64 }, { prop_totalvisiblememorysizeW, CIM_UINT64 }, - { prop_freephysicalmemoryW, CIM_UINT64 }, { prop_versionW, CIM_STRING|COL_FLAG_DYNAMIC } }; static const struct column col_param[] = @@ -584,10 +558,7 @@ static const struct column col_printer[] = { prop_horizontalresolutionW, CIM_UINT32 }, { prop_localW, CIM_BOOLEAN }, { prop_nameW, CIM_STRING|COL_FLAG_DYNAMIC }, - { prop_networkW, CIM_BOOLEAN }, - { prop_deviceidW, CIM_STRING|COL_FLAG_DYNAMIC|COL_FLAG_KEY }, - { prop_portnameW, CIM_STRING|COL_FLAG_DYNAMIC }, - { prop_locationW, CIM_STRING|COL_FLAG_DYNAMIC }, + { prop_networkW, CIM_BOOLEAN } }; static const struct column col_process[] = { @@ -689,28 +660,24 @@ static const struct column col_systemsecurity[] = #ifndef __REACTOS__ static const struct column col_videocontroller[] = { - { prop_adapterdactypeW, CIM_STRING }, - { prop_adapterramW, CIM_UINT32, VT_I4 }, - { prop_availabilityW, CIM_UINT16 }, - { prop_captionW, CIM_STRING|COL_FLAG_DYNAMIC }, - { prop_configmanagererrorcodeW, CIM_UINT32, VT_I4 }, - { prop_currentbitsperpixelW, CIM_UINT32, VT_I4 }, - { prop_currenthorizontalresW, CIM_UINT32, VT_I4 }, - { prop_currentrefreshrateW, CIM_UINT32, VT_I4 }, - { prop_currentscanmodeW, CIM_UINT16, VT_I4 }, - { prop_currentverticalresW, CIM_UINT32, VT_I4 }, - { prop_descriptionW, CIM_STRING|COL_FLAG_DYNAMIC }, - { prop_deviceidW, CIM_STRING|COL_FLAG_KEY }, - { prop_driverdateW, CIM_DATETIME }, - { prop_driverversionW, CIM_STRING }, - { prop_installeddisplaydriversW,CIM_STRING }, - { prop_nameW, CIM_STRING|COL_FLAG_DYNAMIC }, - { prop_pnpdeviceidW, CIM_STRING|COL_FLAG_DYNAMIC }, - { prop_statusW, CIM_STRING }, - { prop_videoarchitectureW, CIM_UINT16, VT_I4 }, - { prop_videomemorytypeW, CIM_UINT16, VT_I4 }, - { prop_videomodedescriptionW, CIM_STRING|COL_FLAG_DYNAMIC }, - { prop_videoprocessorW, CIM_STRING|COL_FLAG_DYNAMIC }, + { prop_adapterdactypeW, CIM_STRING }, + { prop_adapterramW, CIM_UINT32, VT_I4 }, + { prop_availabilityW, CIM_UINT16 }, + { prop_captionW, CIM_STRING|COL_FLAG_DYNAMIC }, + { prop_currentbitsperpixelW, CIM_UINT32, VT_I4 }, + { prop_currenthorizontalresW, CIM_UINT32, VT_I4 }, + { prop_currentrefreshrateW, CIM_UINT32, VT_I4 }, + { prop_currentscanmodeW, CIM_UINT16, VT_I4 }, + { prop_currentverticalresW, CIM_UINT32, VT_I4 }, + { prop_descriptionW, CIM_STRING|COL_FLAG_DYNAMIC }, + { prop_deviceidW, CIM_STRING|COL_FLAG_KEY }, + { prop_driverversionW, CIM_STRING }, + { prop_nameW, CIM_STRING|COL_FLAG_DYNAMIC }, + { prop_pnpdeviceidW, CIM_STRING|COL_FLAG_DYNAMIC }, + { prop_videoarchitectureW, CIM_UINT16, VT_I4 }, + { prop_videomemorytypeW, CIM_UINT16, VT_I4 }, + { prop_videomodedescriptionW, CIM_STRING|COL_FLAG_DYNAMIC }, + { prop_videoprocessorW, CIM_STRING|COL_FLAG_DYNAMIC } }; #endif @@ -758,8 +725,6 @@ static const WCHAR compsysproduct_identifyingnumberW[] = static const WCHAR compsysproduct_uuidW[] = {'d','e','a','d','d','e','a','d','-','d','e','a','d','-','d','e','a','d','-','d','e','a','d','-', 'd','e','a','d','d','e','a','d','d','e','a','d',0}; -static const WCHAR compsysproduct_vendorW[] = - {'W','i','n','e',0}; static const WCHAR diskdrive_interfacetypeW[] = {'I','D','E',0}; static const WCHAR diskdrive_manufacturerW[] = @@ -801,12 +766,8 @@ static const WCHAR videocontroller_dactypeW[] = {'I','n','t','e','g','r','a','t','e','d',' ','R','A','M','D','A','C',0}; static const WCHAR videocontroller_deviceidW[] = {'V','i','d','e','o','C','o','n','t','r','o','l','l','e','r','1',0}; -static const WCHAR videocontroller_driverDateW[] = - {'2','0','1','7','0','1','0','1','0','0','0','0','0','0','.','0','0','0','0','0','0','+','0','0','0',0}; static const WCHAR videocontroller_driverversionW[] = {'1','.','0',0}; -static const WCHAR videocontroller_statusW[] = - {'O','K',0}; #endif #include "pshpack1.h" @@ -856,7 +817,6 @@ struct record_computersystemproduct { const WCHAR *identifyingnumber; const WCHAR *uuid; - const WCHAR *vendor; }; struct record_datafile { @@ -964,7 +924,6 @@ struct record_operatingsystem const WCHAR *systemdirectory; UINT64 totalvirtualmemorysize; UINT64 totalvisiblememorysize; - UINT64 freephysicalmemory; const WCHAR *version; }; struct record_param @@ -995,9 +954,6 @@ struct record_printer int local; const WCHAR *name; int network; - const WCHAR *device_id; - const WCHAR *portname; - const WCHAR *location; }; struct record_process { @@ -1101,7 +1057,6 @@ struct record_videocontroller UINT32 adapter_ram; UINT16 availability; const WCHAR *caption; - UINT32 config_errorcode; UINT32 current_bitsperpixel; UINT32 current_horizontalres; UINT32 current_refreshrate; @@ -1109,12 +1064,9 @@ struct record_videocontroller UINT32 current_verticalres; const WCHAR *description; const WCHAR *device_id; - const WCHAR *driverdate; const WCHAR *driverversion; - const WCHAR *installeddriver; const WCHAR *name; const WCHAR *pnpdevice_id; - const WCHAR *status; UINT16 videoarchitecture; UINT16 videomemorytype; const WCHAR *videomodedescription; @@ -1338,15 +1290,6 @@ static UINT64 get_total_physical_memory(void) return status.ullTotalPhys; } -static UINT64 get_available_physical_memory(void) -{ - MEMORYSTATUSEX status; - - status.dwLength = sizeof(status); - if (!GlobalMemoryStatusEx( &status )) return 1024 * 1024 * 1024; - return status.ullAvailPhys; -} - static WCHAR *get_computername(void) { WCHAR *ret; @@ -1461,7 +1404,6 @@ static enum fill_status fill_compsysproduct( struct table *table, const struct e rec = (struct record_computersystemproduct *)table->data; rec->identifyingnumber = compsysproduct_identifyingnumberW; rec->uuid = get_compsysproduct_uuid(); - rec->vendor = compsysproduct_vendorW; if (!match_row( table, row, cond, &status )) free_row_values( table, row ); else row++; @@ -2114,7 +2056,7 @@ static enum fill_status fill_ip4routetable( struct table *table, const struct ex heap_free( forwards ); return FILL_STATUS_FAILED; } - if (!resize_table( table, forwards->dwNumEntries, sizeof(*rec) )) + if (!resize_table( table, max(forwards->dwNumEntries, 1), sizeof(*rec) )) { heap_free( forwards ); return FILL_STATUS_FAILED; @@ -2474,12 +2416,10 @@ static enum fill_status fill_physicalmemory( struct table *table, const struct e static enum fill_status fill_printer( struct table *table, const struct expr *cond ) { - static const WCHAR fmtW[] = {'P','r','i','n','t','e','r','%','d',0}; struct record_printer *rec; enum fill_status status = FILL_STATUS_UNFILTERED; PRINTER_INFO_2W *info; DWORD i, offset = 0, count = 0, size = 0, num_rows = 0; - WCHAR id[20]; EnumPrintersW( PRINTER_ENUM_LOCAL, NULL, 2, NULL, 0, &size, &count ); if (GetLastError() != ERROR_INSUFFICIENT_BUFFER) return FILL_STATUS_FAILED; @@ -2505,10 +2445,6 @@ static enum fill_status fill_printer( struct table *table, const struct expr *co rec->local = -1; rec->name = heap_strdupW( info[i].pPrinterName ); rec->network = 0; - sprintfW( id, fmtW, i ); - rec->device_id = heap_strdupW( id ); - rec->portname = heap_strdupW( info[i].pPortName ); - rec->location = heap_strdupW( info[i].pLocation ); if (!match_row( table, i, cond, &status )) { free_row_values( table, i ); @@ -2937,7 +2873,6 @@ static enum fill_status fill_os( struct table *table, const struct expr *cond ) rec->systemdirectory = get_systemdirectory(); rec->totalvirtualmemorysize = get_total_physical_memory() / 1024; rec->totalvisiblememorysize = rec->totalvirtualmemorysize; - rec->freephysicalmemory = get_available_physical_memory() / 1024; rec->version = get_osversion( &ver ); if (!match_row( table, row, cond, &status )) free_row_values( table, row ); else row++; @@ -3225,29 +3160,6 @@ static WCHAR *get_pnpdeviceid( DXGI_ADAPTER_DESC *desc ) return ret; } -#define HW_VENDOR_AMD 0x1002 -#define HW_VENDOR_NVIDIA 0x10de -#define HW_VENDOR_VMWARE 0x15ad -#define HW_VENDOR_INTEL 0x8086 - -static const WCHAR* get_video_driver(UINT vendorid) -{ - static const WCHAR driver_amdW[] = {'a','t','i','c','f','x','3','2','.','d','l','l',0}; - static const WCHAR driver_intelW[] = {'i','g','d','u','m','d','i','m','3','2','.','d','l','l',0}; - static const WCHAR driver_nvidiaW[] = {'n','v','d','3','d','u','m','.','d','l','l',0}; - static const WCHAR driver_wineW[] = {'w','i','n','e','.','d','l','l',0}; - - /* FIXME: wined3d has a better table, but we can not access this information through dxgi */ - - if (vendorid == HW_VENDOR_AMD) - return driver_amdW; - else if (vendorid == HW_VENDOR_NVIDIA) - return driver_nvidiaW; - else if (vendorid == HW_VENDOR_INTEL) - return driver_intelW; - return driver_wineW; -} - static enum fill_status fill_videocontroller( struct table *table, const struct expr *cond ) { static const WCHAR fmtW[] = {'%','u',' ','x',' ','%','u',' ','x',' ','%','I','6','4','u',' ','c','o','l','o','r','s',0}; @@ -3282,7 +3194,6 @@ done: rec->adapter_dactype = videocontroller_dactypeW; rec->adapter_ram = vidmem; rec->availability = 3; /* Running or Full Power */ - rec->config_errorcode = 0; /* no error */ rec->caption = heap_strdupW( name ); rec->current_bitsperpixel = get_bits_per_pixel( &hres, &vres ); rec->current_horizontalres = hres; @@ -3291,12 +3202,9 @@ done: rec->current_verticalres = vres; rec->description = heap_strdupW( name ); rec->device_id = videocontroller_deviceidW; - rec->driverdate = videocontroller_driverDateW; rec->driverversion = videocontroller_driverversionW; - rec->installeddriver = get_video_driver( desc.VendorId ); rec->name = heap_strdupW( name ); rec->pnpdevice_id = get_pnpdeviceid( &desc ); - rec->status = videocontroller_statusW; rec->videoarchitecture = 2; /* Unknown */ rec->videomemorytype = 2; /* Unknown */ wsprintfW( mode, fmtW, hres, vres, (UINT64)1 << rec->current_bitsperpixel ); diff --git a/dll/win32/wbemprox/wql.tab.c b/dll/win32/wbemprox/wql.tab.c index 91b7ac46bf..4eaadd0818 100644 --- a/dll/win32/wbemprox/wql.tab.c +++ b/dll/win32/wbemprox/wql.tab.c @@ -1,4 +1,4 @@ -/* A Bison parser, made by GNU Bison 3.0.2. */ +/* A Bison parser, made by GNU Bison 3.0. */ /* Bison implementation for Yacc-like parsers in C @@ -44,7 +44,7 @@ #define YYBISON 1 /* Bison version. */ -#define YYBISON_VERSION "3.0.2" +#define YYBISON_VERSION "3.0" /* Skeleton name. */ #define YYSKELETON_NAME "yacc.c" @@ -243,13 +243,13 @@ static int wql_lex( void *val, struct parser *parser ); result = current_view -#line 259 "wql.tab.c" /* yacc.c:339 */ +#line 247 "wql.tab.c" /* yacc.c:339 */ -# ifndef YY_NULLPTR +# ifndef YY_NULL # if defined __cplusplus && 201103L <= __cplusplus -# define YY_NULLPTR nullptr +# define YY_NULL nullptr # else -# define YY_NULLPTR 0 +# define YY_NULL 0 # endif # endif @@ -261,7 +261,10 @@ static int wql_lex( void *val, struct parser *parser ); # define YYERROR_VERBOSE 1 #endif - +/* In a future release of Bison, this section will be replaced + by #include "wql.tab.h". */ +#ifndef YY_WQL_E_REACTOSSYNC3_0_GCC_DLL_WIN32_WBEMPROX_WQL_TAB_H_INCLUDED +# define YY_WQL_E_REACTOSSYNC3_0_GCC_DLL_WIN32_WBEMPROX_WQL_TAB_H_INCLUDED /* Debug traces. */ #ifndef YYDEBUG # define YYDEBUG 0 @@ -312,7 +315,7 @@ extern int wql_debug; typedef union YYSTYPE YYSTYPE; union YYSTYPE { -#line 194 "wql.y" /* yacc.c:355 */ +#line 182 "e:/reactosSync3.0/dll/win32/wbemprox/wql.y" /* yacc.c:355 */ struct string str; WCHAR *string; @@ -321,7 +324,7 @@ union YYSTYPE struct expr *expr; int integer; -#line 337 "wql.tab.c" /* yacc.c:355 */ +#line 328 "wql.tab.c" /* yacc.c:355 */ }; # define YYSTYPE_IS_TRIVIAL 1 # define YYSTYPE_IS_DECLARED 1 @@ -331,11 +334,11 @@ union YYSTYPE int wql_parse (struct parser *ctx); - +#endif /* !YY_WQL_E_REACTOSSYNC3_0_GCC_DLL_WIN32_WBEMPROX_WQL_TAB_H_INCLUDED */ /* Copy the second part of user declarations. */ -#line 351 "wql.tab.c" /* yacc.c:358 */ +#line 342 "wql.tab.c" /* yacc.c:358 */ #ifdef short # undef short @@ -392,30 +395,11 @@ typedef short int yytype_int16; # endif #endif -#ifndef YY_ATTRIBUTE -# if (defined __GNUC__ \ - && (2 < __GNUC__ || (__GNUC__ == 2 && 96 <= __GNUC_MINOR__))) \ - || defined __SUNPRO_C && 0x5110 <= __SUNPRO_C -# define YY_ATTRIBUTE(Spec) __attribute__(Spec) -# else -# define YY_ATTRIBUTE(Spec) /* empty */ -# endif -#endif - -#ifndef YY_ATTRIBUTE_PURE -# define YY_ATTRIBUTE_PURE YY_ATTRIBUTE ((__pure__)) -#endif - -#ifndef YY_ATTRIBUTE_UNUSED -# define YY_ATTRIBUTE_UNUSED YY_ATTRIBUTE ((__unused__)) -#endif - -#if !defined _Noreturn \ - && (!defined __STDC_VERSION__ || __STDC_VERSION__ < 201112) -# if defined _MSC_VER && 1200 <= _MSC_VER -# define _Noreturn __declspec (noreturn) -# else -# define _Noreturn YY_ATTRIBUTE ((__noreturn__)) +#ifndef __attribute__ +/* This feature is available in gcc versions 2.5 and later. */ +# if (! defined __GNUC__ || __GNUC__ < 2 \ + || (__GNUC__ == 2 && __GNUC_MINOR__ < 5)) +# define __attribute__(Spec) /* empty */ # endif #endif @@ -577,16 +561,16 @@ union yyalloc /* YYFINAL -- State number of the termination state. */ #define YYFINAL 9 /* YYLAST -- Last index in YYTABLE. */ -#define YYLAST 68 +#define YYLAST 85 /* YYNTOKENS -- Number of terminals. */ #define YYNTOKENS 32 /* YYNNTS -- Number of nonterminals. */ #define YYNNTS 10 /* YYNRULES -- Number of rules. */ -#define YYNRULES 36 +#define YYNRULES 40 /* YYNSTATES -- Number of states. */ -#define YYNSTATES 67 +#define YYNSTATES 74 /* YYTRANSLATE[YYX] -- Symbol number corresponding to YYX as returned by yylex, with out-of-bounds checking. */ @@ -635,10 +619,11 @@ static const yytype_uint8 yytranslate[] = /* YYRLINE[YYN] -- Source line where rule number YYN was defined. */ static const yytype_uint16 yyrline[] = { - 0, 221, 221, 233, 245, 260, 261, 265, 272, 278, - 287, 296, 303, 309, 315, 321, 327, 333, 339, 345, - 351, 357, 363, 369, 375, 381, 387, 393, 399, 405, - 411, 420, 429, 438, 444, 450, 456 + 0, 209, 209, 221, 233, 248, 249, 253, 260, 266, + 275, 284, 291, 297, 303, 309, 315, 321, 327, 333, + 339, 345, 351, 357, 363, 369, 375, 381, 387, 393, + 399, 405, 411, 417, 423, 432, 441, 450, 456, 462, + 468 }; #endif @@ -653,7 +638,7 @@ static const char *const yytname[] = "TK_ILLEGAL", "TK_BY", "TK_STRING", "TK_ID", "TK_OR", "TK_AND", "TK_NOT", "TK_EQ", "TK_NE", "TK_LT", "TK_GT", "TK_LE", "TK_GE", "TK_LIKE", "$accept", "select", "proplist", "prop", "id", "number", "expr", - "string_val", "prop_val", "const_val", YY_NULLPTR + "string_val", "prop_val", "const_val", YY_NULL }; #endif @@ -669,10 +654,10 @@ static const yytype_uint16 yytoknum[] = }; # endif -#define YYPACT_NINF -18 +#define YYPACT_NINF -23 #define yypact_value_is_default(Yystate) \ - (!!((Yystate) == (-18))) + (!!((Yystate) == (-23))) #define YYTABLE_NINF -1 @@ -683,13 +668,14 @@ static const yytype_uint16 yytoknum[] = STATE-NUM. */ static const yytype_int8 yypact[] = { - 7, 3, 12, -5, -18, -18, 24, 29, 35, -18, - -18, -5, 4, -5, 21, -18, -18, 17, 17, -18, - -18, -18, -18, 17, -18, -18, 11, -8, 25, 22, - -18, 17, 17, 16, -9, -9, -9, -9, -9, -9, - 23, -5, -5, -5, -5, -5, -5, -18, 45, -18, - -18, 37, -18, -18, -18, -18, -18, -18, -18, -18, - -18, -18, -18, -18, -18, -18, -18 + -2, 10, 34, 14, -23, -23, 29, 48, 46, -23, + -23, 14, 11, 14, 42, -23, -23, 28, 28, -16, + -23, -23, -23, -23, 28, -23, -23, 22, -8, -22, + 33, 14, 14, -23, 28, 28, 27, 50, 54, 59, + 59, 59, 59, 39, 14, 14, 14, 14, 14, 14, + -23, -23, -23, 52, -23, -23, 58, -23, -23, -23, + -23, -23, -23, -23, -23, -23, -23, -23, -23, -23, + -23, -23, -23, -23 }; /* YYDEFACT[STATE-NUM] -- Default reduction number in state STATE-NUM. @@ -698,24 +684,25 @@ static const yytype_int8 yypact[] = static const yytype_uint8 yydefact[] = { 0, 0, 0, 0, 7, 10, 0, 5, 9, 1, - 2, 0, 0, 0, 3, 6, 8, 0, 0, 36, - 35, 11, 34, 0, 32, 33, 4, 0, 0, 0, - 15, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 12, 14, 13, - 29, 0, 16, 21, 18, 17, 19, 20, 31, 28, - 22, 27, 24, 23, 25, 26, 30 + 2, 0, 0, 0, 3, 6, 8, 0, 0, 0, + 40, 39, 11, 38, 0, 36, 37, 4, 0, 0, + 0, 0, 0, 15, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 12, 32, 34, 14, 13, 29, 0, 31, 16, 33, + 21, 18, 17, 19, 20, 35, 28, 22, 27, 24, + 23, 25, 26, 30 }; /* YYPGOTO[NTERM-NUM]. */ static const yytype_int8 yypgoto[] = { - -18, -18, 34, 1, 36, -18, -17, -18, 15, 28 + -23, -23, 64, 1, 47, -23, 12, -23, -20, 43 }; /* YYDEFGOTO[NTERM-NUM]. */ static const yytype_int8 yydefgoto[] = { - -1, 2, 6, 24, 8, 25, 26, 59, 27, 28 + -1, 2, 6, 25, 8, 26, 27, 66, 28, 29 }; /* YYTABLE[YYPACT[STATE-NUM]] -- What to do in state STATE-NUM. If @@ -723,24 +710,28 @@ static const yytype_int8 yydefgoto[] = number is the opposite. If YYTABLE_NINF, syntax error. */ static const yytype_uint8 yytable[] = { - 33, 29, 7, 19, 20, 21, 30, 3, 4, 4, - 1, 22, 9, 7, 48, 49, 5, 34, 35, 36, - 37, 38, 39, 40, 5, 5, 18, 50, 11, 19, - 20, 21, 47, 31, 32, 12, 17, 22, 5, 10, - 51, 23, 13, 58, 31, 32, 15, 14, 66, 16, - 41, 42, 43, 44, 45, 46, 60, 61, 62, 63, - 64, 65, 52, 53, 54, 55, 56, 57, 32 + 36, 1, 7, 44, 45, 46, 47, 48, 49, 31, + 32, 51, 52, 7, 3, 4, 4, 37, 38, 39, + 40, 41, 42, 43, 67, 68, 69, 70, 71, 72, + 30, 5, 5, 11, 9, 5, 33, 18, 55, 19, + 20, 21, 22, 50, 34, 35, 53, 54, 23, 5, + 10, 56, 24, 13, 12, 34, 35, 17, 14, 65, + 16, 57, 20, 21, 22, 59, 20, 21, 22, 73, + 23, 20, 21, 22, 23, 35, 15, 0, 0, 23, + 58, 60, 61, 62, 63, 64 }; -static const yytype_uint8 yycheck[] = +static const yytype_int8 yycheck[] = { - 8, 18, 1, 12, 13, 14, 23, 4, 5, 5, - 3, 20, 0, 12, 31, 32, 21, 25, 26, 27, - 28, 29, 30, 31, 21, 21, 9, 11, 4, 12, - 13, 14, 10, 22, 23, 6, 15, 20, 21, 3, - 24, 24, 7, 20, 22, 23, 12, 11, 11, 13, - 25, 26, 27, 28, 29, 30, 41, 42, 43, 44, - 45, 46, 34, 35, 36, 37, 38, 39, 23 + 8, 3, 1, 25, 26, 27, 28, 29, 30, 25, + 26, 31, 32, 12, 4, 5, 5, 25, 26, 27, + 28, 29, 30, 31, 44, 45, 46, 47, 48, 49, + 18, 21, 21, 4, 0, 21, 24, 9, 11, 11, + 12, 13, 14, 10, 22, 23, 34, 35, 20, 21, + 3, 24, 24, 7, 6, 22, 23, 15, 11, 20, + 13, 11, 12, 13, 14, 11, 12, 13, 14, 11, + 20, 12, 13, 14, 20, 23, 12, -1, -1, 20, + 37, 38, 39, 40, 41, 42 }; /* YYSTOS[STATE-NUM] -- The (internal number of the) accessing @@ -748,12 +739,13 @@ static const yytype_uint8 yycheck[] = static const yytype_uint8 yystos[] = { 0, 3, 33, 4, 5, 21, 34, 35, 36, 0, - 36, 4, 6, 7, 36, 34, 36, 15, 9, 12, - 13, 14, 20, 24, 35, 37, 38, 40, 41, 38, - 38, 22, 23, 8, 25, 26, 27, 28, 29, 30, - 31, 25, 26, 27, 28, 29, 30, 10, 38, 38, - 11, 24, 41, 41, 41, 41, 41, 41, 20, 39, - 40, 40, 40, 40, 40, 40, 11 + 36, 4, 6, 7, 36, 34, 36, 15, 9, 11, + 12, 13, 14, 20, 24, 35, 37, 38, 40, 41, + 38, 25, 26, 38, 22, 23, 8, 25, 26, 27, + 28, 29, 30, 31, 25, 26, 27, 28, 29, 30, + 10, 40, 40, 38, 38, 11, 24, 11, 41, 11, + 41, 41, 41, 41, 41, 20, 39, 40, 40, 40, + 40, 40, 40, 11 }; /* YYR1[YYN] -- Symbol number of symbol that rule YYN derives. */ @@ -762,7 +754,8 @@ static const yytype_uint8 yyr1[] = 0, 32, 33, 33, 33, 34, 34, 34, 35, 35, 36, 37, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, - 38, 39, 40, 41, 41, 41, 41 + 38, 38, 38, 38, 38, 39, 40, 41, 41, 41, + 41 }; /* YYR2[YYN] -- Number of symbols on the right hand side of rule YYN. */ @@ -771,7 +764,8 @@ static const yytype_uint8 yyr2[] = 0, 2, 3, 4, 6, 1, 3, 1, 3, 1, 1, 1, 3, 3, 3, 2, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, - 4, 1, 1, 1, 1, 1, 1 + 4, 3, 3, 3, 3, 1, 1, 1, 1, 1, + 1 }; @@ -1056,11 +1050,11 @@ static int yysyntax_error (YYSIZE_T *yymsg_alloc, char **yymsg, yytype_int16 *yyssp, int yytoken) { - YYSIZE_T yysize0 = yytnamerr (YY_NULLPTR, yytname[yytoken]); + YYSIZE_T yysize0 = yytnamerr (YY_NULL, yytname[yytoken]); YYSIZE_T yysize = yysize0; enum { YYERROR_VERBOSE_ARGS_MAXIMUM = 5 }; /* Internationalized format string. */ - const char *yyformat = YY_NULLPTR; + const char *yyformat = YY_NULL; /* Arguments of yyformat. */ char const *yyarg[YYERROR_VERBOSE_ARGS_MAXIMUM]; /* Number of reported tokens (one for the "unexpected", one per @@ -1117,7 +1111,7 @@ yysyntax_error (YYSIZE_T *yymsg_alloc, char **yymsg, } yyarg[yycount++] = yytname[yyx]; { - YYSIZE_T yysize1 = yysize + yytnamerr (YY_NULLPTR, yytname[yyx]); + YYSIZE_T yysize1 = yysize + yytnamerr (YY_NULL, yytname[yyx]); if (! (yysize <= yysize1 && yysize1 <= YYSTACK_ALLOC_MAXIMUM)) return 2; @@ -1454,7 +1448,7 @@ yyreduce: switch (yyn) { case 2: -#line 222 "wql.y" /* yacc.c:1646 */ +#line 210 "e:/reactosSync3.0/dll/win32/wbemprox/wql.y" /* yacc.c:1646 */ { HRESULT hr; struct parser *parser = ctx; @@ -1466,11 +1460,11 @@ yyreduce: PARSER_BUBBLE_UP_VIEW( parser, (yyval.view), view ); } -#line 1482 "wql.tab.c" /* yacc.c:1646 */ +#line 1464 "wql.tab.c" /* yacc.c:1646 */ break; case 3: -#line 234 "wql.y" /* yacc.c:1646 */ +#line 222 "e:/reactosSync3.0/dll/win32/wbemprox/wql.y" /* yacc.c:1646 */ { HRESULT hr; struct parser *parser = ctx; @@ -1482,11 +1476,11 @@ yyreduce: PARSER_BUBBLE_UP_VIEW( parser, (yyval.view), view ); } -#line 1498 "wql.tab.c" /* yacc.c:1646 */ +#line 1480 "wql.tab.c" /* yacc.c:1646 */ break; case 4: -#line 246 "wql.y" /* yacc.c:1646 */ +#line 234 "e:/reactosSync3.0/dll/win32/wbemprox/wql.y" /* yacc.c:1646 */ { HRESULT hr; struct parser *parser = ctx; @@ -1498,315 +1492,355 @@ yyreduce: PARSER_BUBBLE_UP_VIEW( parser, (yyval.view), view ); } -#line 1514 "wql.tab.c" /* yacc.c:1646 */ +#line 1496 "wql.tab.c" /* yacc.c:1646 */ break; case 6: -#line 262 "wql.y" /* yacc.c:1646 */ +#line 250 "e:/reactosSync3.0/dll/win32/wbemprox/wql.y" /* yacc.c:1646 */ { (yyvsp[-2].proplist)->next = (yyvsp[0].proplist); } -#line 1522 "wql.tab.c" /* yacc.c:1646 */ +#line 1504 "wql.tab.c" /* yacc.c:1646 */ break; case 7: -#line 266 "wql.y" /* yacc.c:1646 */ +#line 254 "e:/reactosSync3.0/dll/win32/wbemprox/wql.y" /* yacc.c:1646 */ { (yyval.proplist) = NULL; } -#line 1530 "wql.tab.c" /* yacc.c:1646 */ +#line 1512 "wql.tab.c" /* yacc.c:1646 */ break; case 8: -#line 273 "wql.y" /* yacc.c:1646 */ +#line 261 "e:/reactosSync3.0/dll/win32/wbemprox/wql.y" /* yacc.c:1646 */ { (yyval.proplist) = alloc_property( ctx, (yyvsp[-2].string), (yyvsp[0].string) ); if (!(yyval.proplist)) YYABORT; } -#line 1540 "wql.tab.c" /* yacc.c:1646 */ +#line 1522 "wql.tab.c" /* yacc.c:1646 */ break; case 9: -#line 279 "wql.y" /* yacc.c:1646 */ +#line 267 "e:/reactosSync3.0/dll/win32/wbemprox/wql.y" /* yacc.c:1646 */ { (yyval.proplist) = alloc_property( ctx, NULL, (yyvsp[0].string) ); if (!(yyval.proplist)) YYABORT; } -#line 1550 "wql.tab.c" /* yacc.c:1646 */ +#line 1532 "wql.tab.c" /* yacc.c:1646 */ break; case 10: -#line 288 "wql.y" /* yacc.c:1646 */ +#line 276 "e:/reactosSync3.0/dll/win32/wbemprox/wql.y" /* yacc.c:1646 */ { (yyval.string) = get_string( ctx, &(yyvsp[0].str) ); if (!(yyval.string)) YYABORT; } -#line 1560 "wql.tab.c" /* yacc.c:1646 */ +#line 1542 "wql.tab.c" /* yacc.c:1646 */ break; case 11: -#line 297 "wql.y" /* yacc.c:1646 */ +#line 285 "e:/reactosSync3.0/dll/win32/wbemprox/wql.y" /* yacc.c:1646 */ { (yyval.integer) = get_int( ctx ); } -#line 1568 "wql.tab.c" /* yacc.c:1646 */ +#line 1550 "wql.tab.c" /* yacc.c:1646 */ break; case 12: -#line 304 "wql.y" /* yacc.c:1646 */ +#line 292 "e:/reactosSync3.0/dll/win32/wbemprox/wql.y" /* yacc.c:1646 */ { (yyval.expr) = (yyvsp[-1].expr); if (!(yyval.expr)) YYABORT; } -#line 1578 "wql.tab.c" /* yacc.c:1646 */ +#line 1560 "wql.tab.c" /* yacc.c:1646 */ break; case 13: -#line 310 "wql.y" /* yacc.c:1646 */ +#line 298 "e:/reactosSync3.0/dll/win32/wbemprox/wql.y" /* yacc.c:1646 */ { (yyval.expr) = expr_complex( ctx, (yyvsp[-2].expr), OP_AND, (yyvsp[0].expr) ); if (!(yyval.expr)) YYABORT; } -#line 1588 "wql.tab.c" /* yacc.c:1646 */ +#line 1570 "wql.tab.c" /* yacc.c:1646 */ break; case 14: -#line 316 "wql.y" /* yacc.c:1646 */ +#line 304 "e:/reactosSync3.0/dll/win32/wbemprox/wql.y" /* yacc.c:1646 */ { (yyval.expr) = expr_complex( ctx, (yyvsp[-2].expr), OP_OR, (yyvsp[0].expr) ); if (!(yyval.expr)) YYABORT; } -#line 1598 "wql.tab.c" /* yacc.c:1646 */ +#line 1580 "wql.tab.c" /* yacc.c:1646 */ break; case 15: -#line 322 "wql.y" /* yacc.c:1646 */ +#line 310 "e:/reactosSync3.0/dll/win32/wbemprox/wql.y" /* yacc.c:1646 */ { (yyval.expr) = expr_unary( ctx, (yyvsp[0].expr), OP_NOT ); if (!(yyval.expr)) YYABORT; } -#line 1608 "wql.tab.c" /* yacc.c:1646 */ +#line 1590 "wql.tab.c" /* yacc.c:1646 */ break; case 16: -#line 328 "wql.y" /* yacc.c:1646 */ +#line 316 "e:/reactosSync3.0/dll/win32/wbemprox/wql.y" /* yacc.c:1646 */ { (yyval.expr) = expr_complex( ctx, (yyvsp[-2].expr), OP_EQ, (yyvsp[0].expr) ); if (!(yyval.expr)) YYABORT; } -#line 1618 "wql.tab.c" /* yacc.c:1646 */ +#line 1600 "wql.tab.c" /* yacc.c:1646 */ break; case 17: -#line 334 "wql.y" /* yacc.c:1646 */ +#line 322 "e:/reactosSync3.0/dll/win32/wbemprox/wql.y" /* yacc.c:1646 */ { (yyval.expr) = expr_complex( ctx, (yyvsp[-2].expr), OP_GT, (yyvsp[0].expr) ); if (!(yyval.expr)) YYABORT; } -#line 1628 "wql.tab.c" /* yacc.c:1646 */ +#line 1610 "wql.tab.c" /* yacc.c:1646 */ break; case 18: -#line 340 "wql.y" /* yacc.c:1646 */ +#line 328 "e:/reactosSync3.0/dll/win32/wbemprox/wql.y" /* yacc.c:1646 */ { (yyval.expr) = expr_complex( ctx, (yyvsp[-2].expr), OP_LT, (yyvsp[0].expr) ); if (!(yyval.expr)) YYABORT; } -#line 1638 "wql.tab.c" /* yacc.c:1646 */ +#line 1620 "wql.tab.c" /* yacc.c:1646 */ break; case 19: -#line 346 "wql.y" /* yacc.c:1646 */ +#line 334 "e:/reactosSync3.0/dll/win32/wbemprox/wql.y" /* yacc.c:1646 */ { (yyval.expr) = expr_complex( ctx, (yyvsp[-2].expr), OP_LE, (yyvsp[0].expr) ); if (!(yyval.expr)) YYABORT; } -#line 1648 "wql.tab.c" /* yacc.c:1646 */ +#line 1630 "wql.tab.c" /* yacc.c:1646 */ break; case 20: -#line 352 "wql.y" /* yacc.c:1646 */ +#line 340 "e:/reactosSync3.0/dll/win32/wbemprox/wql.y" /* yacc.c:1646 */ { (yyval.expr) = expr_complex( ctx, (yyvsp[-2].expr), OP_GE, (yyvsp[0].expr) ); if (!(yyval.expr)) YYABORT; } -#line 1658 "wql.tab.c" /* yacc.c:1646 */ +#line 1640 "wql.tab.c" /* yacc.c:1646 */ break; case 21: -#line 358 "wql.y" /* yacc.c:1646 */ +#line 346 "e:/reactosSync3.0/dll/win32/wbemprox/wql.y" /* yacc.c:1646 */ { (yyval.expr) = expr_complex( ctx, (yyvsp[-2].expr), OP_NE, (yyvsp[0].expr) ); if (!(yyval.expr)) YYABORT; } -#line 1668 "wql.tab.c" /* yacc.c:1646 */ +#line 1650 "wql.tab.c" /* yacc.c:1646 */ break; case 22: -#line 364 "wql.y" /* yacc.c:1646 */ +#line 352 "e:/reactosSync3.0/dll/win32/wbemprox/wql.y" /* yacc.c:1646 */ { (yyval.expr) = expr_complex( ctx, (yyvsp[-2].expr), OP_EQ, (yyvsp[0].expr) ); if (!(yyval.expr)) YYABORT; } -#line 1678 "wql.tab.c" /* yacc.c:1646 */ +#line 1660 "wql.tab.c" /* yacc.c:1646 */ break; case 23: -#line 370 "wql.y" /* yacc.c:1646 */ +#line 358 "e:/reactosSync3.0/dll/win32/wbemprox/wql.y" /* yacc.c:1646 */ { (yyval.expr) = expr_complex( ctx, (yyvsp[-2].expr), OP_GT, (yyvsp[0].expr) ); if (!(yyval.expr)) YYABORT; } -#line 1688 "wql.tab.c" /* yacc.c:1646 */ +#line 1670 "wql.tab.c" /* yacc.c:1646 */ break; case 24: -#line 376 "wql.y" /* yacc.c:1646 */ +#line 364 "e:/reactosSync3.0/dll/win32/wbemprox/wql.y" /* yacc.c:1646 */ { (yyval.expr) = expr_complex( ctx, (yyvsp[-2].expr), OP_LT, (yyvsp[0].expr) ); if (!(yyval.expr)) YYABORT; } -#line 1698 "wql.tab.c" /* yacc.c:1646 */ +#line 1680 "wql.tab.c" /* yacc.c:1646 */ break; case 25: -#line 382 "wql.y" /* yacc.c:1646 */ +#line 370 "e:/reactosSync3.0/dll/win32/wbemprox/wql.y" /* yacc.c:1646 */ { (yyval.expr) = expr_complex( ctx, (yyvsp[-2].expr), OP_LE, (yyvsp[0].expr) ); if (!(yyval.expr)) YYABORT; } -#line 1708 "wql.tab.c" /* yacc.c:1646 */ +#line 1690 "wql.tab.c" /* yacc.c:1646 */ break; case 26: -#line 388 "wql.y" /* yacc.c:1646 */ +#line 376 "e:/reactosSync3.0/dll/win32/wbemprox/wql.y" /* yacc.c:1646 */ { (yyval.expr) = expr_complex( ctx, (yyvsp[-2].expr), OP_GE, (yyvsp[0].expr) ); if (!(yyval.expr)) YYABORT; } -#line 1718 "wql.tab.c" /* yacc.c:1646 */ +#line 1700 "wql.tab.c" /* yacc.c:1646 */ break; case 27: -#line 394 "wql.y" /* yacc.c:1646 */ +#line 382 "e:/reactosSync3.0/dll/win32/wbemprox/wql.y" /* yacc.c:1646 */ { (yyval.expr) = expr_complex( ctx, (yyvsp[-2].expr), OP_NE, (yyvsp[0].expr) ); if (!(yyval.expr)) YYABORT; } -#line 1728 "wql.tab.c" /* yacc.c:1646 */ +#line 1710 "wql.tab.c" /* yacc.c:1646 */ break; case 28: -#line 400 "wql.y" /* yacc.c:1646 */ +#line 388 "e:/reactosSync3.0/dll/win32/wbemprox/wql.y" /* yacc.c:1646 */ { (yyval.expr) = expr_complex( ctx, (yyvsp[-2].expr), OP_LIKE, (yyvsp[0].expr) ); if (!(yyval.expr)) YYABORT; } -#line 1738 "wql.tab.c" /* yacc.c:1646 */ +#line 1720 "wql.tab.c" /* yacc.c:1646 */ break; case 29: -#line 406 "wql.y" /* yacc.c:1646 */ +#line 394 "e:/reactosSync3.0/dll/win32/wbemprox/wql.y" /* yacc.c:1646 */ { (yyval.expr) = expr_unary( ctx, (yyvsp[-2].expr), OP_ISNULL ); if (!(yyval.expr)) YYABORT; } -#line 1748 "wql.tab.c" /* yacc.c:1646 */ +#line 1730 "wql.tab.c" /* yacc.c:1646 */ break; case 30: -#line 412 "wql.y" /* yacc.c:1646 */ +#line 400 "e:/reactosSync3.0/dll/win32/wbemprox/wql.y" /* yacc.c:1646 */ { (yyval.expr) = expr_unary( ctx, (yyvsp[-3].expr), OP_NOTNULL ); if (!(yyval.expr)) YYABORT; } -#line 1758 "wql.tab.c" /* yacc.c:1646 */ +#line 1740 "wql.tab.c" /* yacc.c:1646 */ break; case 31: -#line 421 "wql.y" /* yacc.c:1646 */ +#line 406 "e:/reactosSync3.0/dll/win32/wbemprox/wql.y" /* yacc.c:1646 */ { - (yyval.expr) = expr_sval( ctx, &(yyvsp[0].str) ); + (yyval.expr) = expr_unary( ctx, (yyvsp[-2].expr), OP_ISNULL ); if (!(yyval.expr)) YYABORT; } -#line 1768 "wql.tab.c" /* yacc.c:1646 */ +#line 1750 "wql.tab.c" /* yacc.c:1646 */ break; case 32: -#line 430 "wql.y" /* yacc.c:1646 */ +#line 412 "e:/reactosSync3.0/dll/win32/wbemprox/wql.y" /* yacc.c:1646 */ { - (yyval.expr) = expr_propval( ctx, (yyvsp[0].proplist) ); + (yyval.expr) = expr_unary( ctx, (yyvsp[0].expr), OP_ISNULL ); if (!(yyval.expr)) YYABORT; } -#line 1778 "wql.tab.c" /* yacc.c:1646 */ +#line 1760 "wql.tab.c" /* yacc.c:1646 */ break; case 33: -#line 439 "wql.y" /* yacc.c:1646 */ +#line 418 "e:/reactosSync3.0/dll/win32/wbemprox/wql.y" /* yacc.c:1646 */ { - (yyval.expr) = expr_ival( ctx, (yyvsp[0].integer) ); + (yyval.expr) = expr_unary( ctx, (yyvsp[-2].expr), OP_NOTNULL ); if (!(yyval.expr)) YYABORT; } -#line 1788 "wql.tab.c" /* yacc.c:1646 */ +#line 1770 "wql.tab.c" /* yacc.c:1646 */ break; case 34: -#line 445 "wql.y" /* yacc.c:1646 */ +#line 424 "e:/reactosSync3.0/dll/win32/wbemprox/wql.y" /* yacc.c:1646 */ { - (yyval.expr) = expr_sval( ctx, &(yyvsp[0].str) ); + (yyval.expr) = expr_unary( ctx, (yyvsp[0].expr), OP_NOTNULL ); if (!(yyval.expr)) YYABORT; } -#line 1798 "wql.tab.c" /* yacc.c:1646 */ +#line 1780 "wql.tab.c" /* yacc.c:1646 */ break; case 35: -#line 451 "wql.y" /* yacc.c:1646 */ +#line 433 "e:/reactosSync3.0/dll/win32/wbemprox/wql.y" /* yacc.c:1646 */ { - (yyval.expr) = expr_bval( ctx, -1 ); + (yyval.expr) = expr_sval( ctx, &(yyvsp[0].str) ); if (!(yyval.expr)) YYABORT; } -#line 1808 "wql.tab.c" /* yacc.c:1646 */ +#line 1790 "wql.tab.c" /* yacc.c:1646 */ break; case 36: -#line 457 "wql.y" /* yacc.c:1646 */ +#line 442 "e:/reactosSync3.0/dll/win32/wbemprox/wql.y" /* yacc.c:1646 */ + { + (yyval.expr) = expr_propval( ctx, (yyvsp[0].proplist) ); + if (!(yyval.expr)) + YYABORT; + } +#line 1800 "wql.tab.c" /* yacc.c:1646 */ + break; + + case 37: +#line 451 "e:/reactosSync3.0/dll/win32/wbemprox/wql.y" /* yacc.c:1646 */ + { + (yyval.expr) = expr_ival( ctx, (yyvsp[0].integer) ); + if (!(yyval.expr)) + YYABORT; + } +#line 1810 "wql.tab.c" /* yacc.c:1646 */ + break; + + case 38: +#line 457 "e:/reactosSync3.0/dll/win32/wbemprox/wql.y" /* yacc.c:1646 */ + { + (yyval.expr) = expr_sval( ctx, &(yyvsp[0].str) ); + if (!(yyval.expr)) + YYABORT; + } +#line 1820 "wql.tab.c" /* yacc.c:1646 */ + break; + + case 39: +#line 463 "e:/reactosSync3.0/dll/win32/wbemprox/wql.y" /* yacc.c:1646 */ + { + (yyval.expr) = expr_bval( ctx, -1 ); + if (!(yyval.expr)) + YYABORT; + } +#line 1830 "wql.tab.c" /* yacc.c:1646 */ + break; + + case 40: +#line 469 "e:/reactosSync3.0/dll/win32/wbemprox/wql.y" /* yacc.c:1646 */ { (yyval.expr) = expr_bval( ctx, 0 ); if (!(yyval.expr)) YYABORT; } -#line 1818 "wql.tab.c" /* yacc.c:1646 */ +#line 1840 "wql.tab.c" /* yacc.c:1646 */ break; -#line 1822 "wql.tab.c" /* yacc.c:1646 */ +#line 1844 "wql.tab.c" /* yacc.c:1646 */ default: break; } /* User semantic actions sometimes alter yychar, and that requires @@ -2034,7 +2068,7 @@ yyreturn: #endif return yyresult; } -#line 464 "wql.y" /* yacc.c:1906 */ +#line 476 "e:/reactosSync3.0/dll/win32/wbemprox/wql.y" /* yacc.c:1906 */ HRESULT parse_query( const WCHAR *str, struct view **view, struct list *mem ) diff --git a/dll/win32/wbemprox/wql.y b/dll/win32/wbemprox/wql.y index 98b0378677..beba2de08a 100644 --- a/dll/win32/wbemprox/wql.y +++ b/dll/win32/wbemprox/wql.y @@ -18,20 +18,8 @@ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA */ -#include "config.h" -#include <stdarg.h> - -#include "windef.h" -#include "winbase.h" -#include "wbemcli.h" #include "wbemprox_private.h" -#include "wine/list.h" -#include "wine/debug.h" -#include "wine/unicode.h" - -WINE_DEFAULT_DEBUG_CHANNEL(wbemprox); - struct parser { const WCHAR *cmd; @@ -414,6 +402,30 @@ expr: if (!$$) YYABORT; } + | prop_val TK_EQ TK_NULL + { + $$ = expr_unary( ctx, $1, OP_ISNULL ); + if (!$$) + YYABORT; + } + | TK_NULL TK_EQ prop_val + { + $$ = expr_unary( ctx, $3, OP_ISNULL ); + if (!$$) + YYABORT; + } + | prop_val TK_NE TK_NULL + { + $$ = expr_unary( ctx, $1, OP_NOTNULL ); + if (!$$) + YYABORT; + } + | TK_NULL TK_NE prop_val + { + $$ = expr_unary( ctx, $3, OP_NOTNULL ); + if (!$$) + YYABORT; + } ; string_val: diff --git a/media/doc/README.WINE b/media/doc/README.WINE index 84c078affb..b94e76dc58 100644 --- a/media/doc/README.WINE +++ b/media/doc/README.WINE @@ -195,7 +195,7 @@ reactos/dll/win32/vbscript # Synced to Wine-3.0 reactos/dll/win32/version # Synced to Wine-3.0 reactos/dll/win32/vssapi # Synced to WineStaging-2.9 reactos/dll/win32/wbemdisp # Synced to Wine-3.0 -reactos/dll/win32/wbemprox # Synced to WineStaging-2.16 +reactos/dll/win32/wbemprox # Synced to Wine-3.0 reactos/dll/win32/windowscodecs # Synced to WineStaging-2.16 reactos/dll/win32/windowscodecsext # Synced to WineStaging-2.9 reactos/dll/win32/winemp3.acm # Synced to WineStaging-2.16
1
0
0
0
01/01: [WBEMDISP] Sync with Wine 3.0. CORE-14225
by Amine Khaldi
20 Jan '18
20 Jan '18
https://git.reactos.org/?p=reactos.git;a=commitdiff;h=b99f0b4922a455db7f535…
commit b99f0b4922a455db7f535dc658150383d48d33a0 Author: Amine Khaldi <amine.khaldi(a)reactos.org> AuthorDate: Sat Jan 20 13:45:23 2018 +0100 Commit: Amine Khaldi <amine.khaldi(a)reactos.org> CommitDate: Sat Jan 20 13:45:23 2018 +0100 [WBEMDISP] Sync with Wine 3.0. CORE-14225 --- dll/win32/wbemdisp/locator.c | 249 +------------------------------------------ media/doc/README.WINE | 2 +- 2 files changed, 6 insertions(+), 245 deletions(-) diff --git a/dll/win32/wbemdisp/locator.c b/dll/win32/wbemdisp/locator.c index 1fb5ee44dc..951e4648d0 100644 --- a/dll/win32/wbemdisp/locator.c +++ b/dll/win32/wbemdisp/locator.c @@ -21,7 +21,6 @@ #include <wbemcli.h> static HRESULT EnumVARIANT_create( IEnumWbemClassObject *, IEnumVARIANT ** ); -static HRESULT ISWbemSecurity_create( ISWbemSecurity ** ); enum type_id { @@ -31,7 +30,6 @@ enum type_id ISWbemProperty_tid, ISWbemPropertySet_tid, ISWbemServices_tid, - ISWbemSecurity_tid, last_tid }; @@ -45,8 +43,7 @@ static REFIID wbemdisp_tid_id[] = &IID_ISWbemObjectSet, &IID_ISWbemProperty, &IID_ISWbemPropertySet, - &IID_ISWbemServices, - &IID_ISWbemSecurity + &IID_ISWbemServices }; static HRESULT get_typeinfo( enum type_id tid, ITypeInfo **ret ) @@ -1859,12 +1856,8 @@ static HRESULT WINAPI services_get_Security_( ISWbemServices *iface, ISWbemSecurity **objWbemSecurity ) { - TRACE( "%p, %p\n", iface, objWbemSecurity ); - - if (!objWbemSecurity) - return E_INVALIDARG; - - return ISWbemSecurity_create( objWbemSecurity ); + FIXME( "\n" ); + return E_NOTIMPL; } static const ISWbemServicesVtbl services_vtbl = @@ -2118,12 +2111,8 @@ static HRESULT WINAPI locator_get_Security_( ISWbemLocator *iface, ISWbemSecurity **objWbemSecurity ) { - TRACE( "%p, %p\n", iface, objWbemSecurity ); - - if (!objWbemSecurity) - return E_INVALIDARG; - - return ISWbemSecurity_create( objWbemSecurity ); + FIXME( "%p, %p\n", iface, objWbemSecurity ); + return E_NOTIMPL; } static const ISWbemLocatorVtbl locator_vtbl = @@ -2154,231 +2143,3 @@ HRESULT SWbemLocator_create( void **obj ) TRACE( "returning iface %p\n", *obj ); return S_OK; } - -struct security -{ - ISWbemSecurity ISWbemSecurity_iface; - LONG refs; - WbemImpersonationLevelEnum implevel; - WbemAuthenticationLevelEnum authlevel; -}; - -static inline struct security *impl_from_ISWbemSecurity( ISWbemSecurity *iface ) -{ - return CONTAINING_RECORD( iface, struct security, ISWbemSecurity_iface ); -} - -static ULONG WINAPI security_AddRef( - ISWbemSecurity *iface ) -{ - struct security *security = impl_from_ISWbemSecurity( iface ); - return InterlockedIncrement( &security->refs ); -} - -static ULONG WINAPI security_Release( - ISWbemSecurity *iface ) -{ - struct security *security = impl_from_ISWbemSecurity( iface ); - LONG refs = InterlockedDecrement( &security->refs ); - if (!refs) - { - TRACE( "destroying %p\n", security ); - heap_free( security ); - } - return refs; -} - -static HRESULT WINAPI security_QueryInterface( - ISWbemSecurity *iface, - REFIID riid, - void **ppvObject ) -{ - struct security *security = impl_from_ISWbemSecurity( iface ); - TRACE( "%p, %s, %p\n", security, debugstr_guid( riid ), ppvObject ); - - if (IsEqualGUID( riid, &IID_ISWbemSecurity ) || - IsEqualGUID( riid, &IID_IDispatch ) || - IsEqualGUID( riid, &IID_IUnknown )) - { - *ppvObject = iface; - } - else - { - FIXME( "interface %s not implemented\n", debugstr_guid(riid) ); - return E_NOINTERFACE; - } - ISWbemSecurity_AddRef( iface ); - return S_OK; -} - -static HRESULT WINAPI security_GetTypeInfoCount( - ISWbemSecurity *iface, - UINT *count ) -{ - struct security *security = impl_from_ISWbemSecurity( iface ); - TRACE( "%p, %p\n", security, count ); - - *count = 1; - return S_OK; -} - -static HRESULT WINAPI security_GetTypeInfo( - ISWbemSecurity *iface, - UINT index, - LCID lcid, - ITypeInfo **info ) -{ - struct security *security = impl_from_ISWbemSecurity( iface ); - TRACE( "%p, %u, %u, %p\n", security, index, lcid, info ); - - return get_typeinfo( ISWbemSecurity_tid, info ); -} - -static HRESULT WINAPI security_GetIDsOfNames( - ISWbemSecurity *iface, - REFIID riid, - LPOLESTR *names, - UINT count, - LCID lcid, - DISPID *dispid ) -{ - struct security *security = impl_from_ISWbemSecurity( iface ); - ITypeInfo *typeinfo; - HRESULT hr; - - TRACE( "%p, %s, %p, %u, %u, %p\n", security, debugstr_guid(riid), names, count, lcid, dispid ); - - if (!names || !count || !dispid) return E_INVALIDARG; - - hr = get_typeinfo( ISWbemSecurity_tid, &typeinfo ); - if (SUCCEEDED(hr)) - { - hr = ITypeInfo_GetIDsOfNames( typeinfo, names, count, dispid ); - ITypeInfo_Release( typeinfo ); - } - return hr; -} - -static HRESULT WINAPI security_Invoke( - ISWbemSecurity *iface, - DISPID member, - REFIID riid, - LCID lcid, - WORD flags, - DISPPARAMS *params, - VARIANT *result, - EXCEPINFO *excep_info, - UINT *arg_err ) -{ - struct security *security = impl_from_ISWbemSecurity( iface ); - ITypeInfo *typeinfo; - HRESULT hr; - - TRACE( "%p, %d, %s, %d, %d, %p, %p, %p, %p\n", security, member, debugstr_guid(riid), - lcid, flags, params, result, excep_info, arg_err ); - - hr = get_typeinfo( ISWbemSecurity_tid, &typeinfo ); - if (SUCCEEDED(hr)) - { - hr = ITypeInfo_Invoke( typeinfo, &security->ISWbemSecurity_iface, member, flags, - params, result, excep_info, arg_err ); - ITypeInfo_Release( typeinfo ); - } - return hr; -} - -static HRESULT WINAPI security_get_ImpersonationLevel_( - ISWbemSecurity *iface, - WbemImpersonationLevelEnum *impersonation_level ) -{ - struct security *security = impl_from_ISWbemSecurity( iface ); - FIXME( "%p, %p: stub\n", security, impersonation_level ); - - if (!impersonation_level) - return E_INVALIDARG; - - *impersonation_level = security->implevel; - return S_OK; -} - -static HRESULT WINAPI security_put_ImpersonationLevel_( - ISWbemSecurity *iface, - WbemImpersonationLevelEnum impersonation_level ) -{ - struct security *security = impl_from_ISWbemSecurity( iface ); - FIXME( "%p, %d: stub\n", security, impersonation_level ); - - security->implevel = impersonation_level; - return S_OK; -} - -static HRESULT WINAPI security_get_AuthenticationLevel_( - ISWbemSecurity *iface, - WbemAuthenticationLevelEnum *authentication_level ) -{ - struct security *security = impl_from_ISWbemSecurity( iface ); - FIXME( "%p, %p: stub\n", security, authentication_level ); - - if (!authentication_level) - return E_INVALIDARG; - - *authentication_level = security->authlevel; - return S_OK; -} - -static HRESULT WINAPI security_put_AuthenticationLevel_( - ISWbemSecurity *iface, - WbemAuthenticationLevelEnum authentication_level ) -{ - struct security *security = impl_from_ISWbemSecurity( iface ); - FIXME( "%p, %d: stub\n", security, authentication_level ); - - security->authlevel = authentication_level; - return S_OK; -} - -static HRESULT WINAPI security_get_Privileges_( - ISWbemSecurity *iface, - ISWbemPrivilegeSet **privilege_set ) -{ - struct security *security = impl_from_ISWbemSecurity( iface ); - FIXME( "%p, %p: stub\n", security, privilege_set ); - - if (!privilege_set) - return E_INVALIDARG; - - return E_NOTIMPL; -} - -static const ISWbemSecurityVtbl security_vtbl = -{ - security_QueryInterface, - security_AddRef, - security_Release, - security_GetTypeInfoCount, - security_GetTypeInfo, - security_GetIDsOfNames, - security_Invoke, - security_get_ImpersonationLevel_, - security_put_ImpersonationLevel_, - security_get_AuthenticationLevel_, - security_put_AuthenticationLevel_, - security_get_Privileges_ -}; - -static HRESULT ISWbemSecurity_create( ISWbemSecurity **obj ) -{ - struct security *security; - - TRACE( "%p\n", obj ); - - if (!(security = heap_alloc( sizeof(*security) ))) return E_OUTOFMEMORY; - security->ISWbemSecurity_iface.lpVtbl = &security_vtbl; - security->refs = 1; - security->implevel = wbemImpersonationLevelAnonymous; - security->authlevel = wbemAuthenticationLevelDefault; - - *obj = &security->ISWbemSecurity_iface; - TRACE( "returning iface %p\n", *obj ); - return S_OK; -} diff --git a/media/doc/README.WINE b/media/doc/README.WINE index 0652176980..84c078affb 100644 --- a/media/doc/README.WINE +++ b/media/doc/README.WINE @@ -194,7 +194,7 @@ reactos/dll/win32/uxtheme # Forked reactos/dll/win32/vbscript # Synced to Wine-3.0 reactos/dll/win32/version # Synced to Wine-3.0 reactos/dll/win32/vssapi # Synced to WineStaging-2.9 -reactos/dll/win32/wbemdisp # Synced to WineStaging-2.16 +reactos/dll/win32/wbemdisp # Synced to Wine-3.0 reactos/dll/win32/wbemprox # Synced to WineStaging-2.16 reactos/dll/win32/windowscodecs # Synced to WineStaging-2.16 reactos/dll/win32/windowscodecsext # Synced to WineStaging-2.9
1
0
0
0
01/01: [VERSION_WINETEST] Sync with Wine 3.0. CORE-14225
by Amine Khaldi
20 Jan '18
20 Jan '18
https://git.reactos.org/?p=reactos.git;a=commitdiff;h=41c4d894f3ead50892928…
commit 41c4d894f3ead50892928fe98b35756937370a30 Author: Amine Khaldi <amine.khaldi(a)reactos.org> AuthorDate: Sat Jan 20 13:43:01 2018 +0100 Commit: Amine Khaldi <amine.khaldi(a)reactos.org> CommitDate: Sat Jan 20 13:43:01 2018 +0100 [VERSION_WINETEST] Sync with Wine 3.0. CORE-14225 --- modules/rostests/winetests/version/info.c | 127 ---------------------- modules/rostests/winetests/version/install.c | 151 ++------------------------- 2 files changed, 6 insertions(+), 272 deletions(-) diff --git a/modules/rostests/winetests/version/info.c b/modules/rostests/winetests/version/info.c index 2b5ba42e68..b99a335d81 100644 --- a/modules/rostests/winetests/version/info.c +++ b/modules/rostests/winetests/version/info.c @@ -578,132 +578,6 @@ static void test_VerQueryValueA(void) HeapFree(GetProcessHeap(), 0, ver); } -static void test_VerQueryValue_InvalidLength(void) -{ - /* this buffer is created with the reactos resource compiler from this resource: -#include "winver.h" - -VS_VERSION_INFO VERSIONINFO -FILEVERSION 1,0,0,0 -PRODUCTVERSION 1,0,0,0 -FILEFLAGSMASK 63 -FILEFLAGS 0 -FILEOS VOS_UNKNOWN -FILETYPE VFT_APP -FILESUBTYPE VFT2_UNKNOWN -{ - BLOCK "StringFileInfo" - { - } -} -*/ - char preparedbuffer[] = { - /* VS_VERSION_INFO_STRUCT32 */ - 0x80, 0x00, /* wLength */ - 0x34, 0x00, /* wValueLength */ - 0x00, 0x00, /* wType */ - /* L"VS_VERSION_INFO" + DWORD alignment */ - 0x56, 0x00, 0x53, 0x00, 0x5f, 0x00, 0x56, 0x00, 0x45, 0x00, 0x52, 0x00, 0x53, 0x00, 0x49, 0x00, 0x4f, - 0x00, 0x4e, 0x00, 0x5f, 0x00, 0x49, 0x00, 0x4e, 0x00, 0x46, 0x00, 0x4f, 0x00, 0x00, 0x00, 0x00, 0x00, - - /* VS_FIXEDFILEINFO */ - 0xbd, 0x04, 0xef, 0xfe, /* dwSignature */ - 0x00, 0x00, 0x01, 0x00, /* dwStrucVersion */ - 0x00, 0x00, 0x01, 0x00, /* dwFileVersionMS */ - 0x00, 0x00, 0x00, 0x00, /* dwFileVersionLS */ - 0x00, 0x00, 0x01, 0x00, /* dwProductVersionMS */ - 0x00, 0x00, 0x00, 0x00, /* dwProductVersionLS */ - 0x3f, 0x00, 0x00, 0x00, /* dwFileFlagsMask */ - 0x00, 0x00, 0x00, 0x00, /* dwFileFlags */ - 0x00, 0x00, 0x00, 0x00, /* dwFileOS */ - 0x01, 0x00, 0x00, 0x00, /* dwFileType */ - 0x00, 0x00, 0x00, 0x00, /* dwFileSubtype */ - 0x00, 0x00, 0x00, 0x00, /* dwFileDateMS */ - 0x00, 0x00, 0x00, 0x00, /* dwFileDateLS */ - - /* first child: */ - 0x24, 0x00, /* wLength */ - 0x00, 0x00, /* wValueLength */ - 0x01, 0x00, /* wType */ - /* L"StringFileInfo" + DWORD alignment */ - 0x53, 0x00, 0x74, 0x00, 0x72, 0x00, 0x69, 0x00, 0x6e, 0x00, 0x67, 0x00, 0x46, 0x00, 0x69, 0x00, - 0x6c, 0x00, 0x65, 0x00, 0x49, 0x00, 0x6e, 0x00, 0x66, 0x00, 0x6f, 0x00, 0x00, 0x00, - /* "FE2X" */ - 0x46, 0x45, 0x32, 0x58, - - /* Extra bytes allocated for W->A conversions. */ - 0x0d, 0xf0, 0xad, 0xba, 0x0d, 0xf0, 0xad, 0xba, 0x0d, 0xf0, 0xad, 0xba, 0x0d, 0xf0, 0xad, 0xba, - 0x0d, 0xf0, 0xad, 0xba, 0x0d, 0xf0, 0xad, 0xba, 0x0d, 0xf0, 0xad, 0xba, 0x0d, 0xf0, 0xad, 0xba, - 0x0d, 0xf0, 0xad, 0xba, 0x0d, 0xf0, 0xad, 0xba, 0x0d, 0xf0, 0xad, 0xba, 0x0d, 0xf0, 0xad, 0xba, - 0x0d, 0xf0, 0xad, 0xba, 0x0d, 0xf0, 0xad, 0xba, 0x0d, 0xf0, 0xad, 0xba, 0x0d, 0xf0, 0xad, 0xba, - 0x0d, 0xf0, 0xad, 0xba, 0x0d, 0xf0, 0xad, 0xba, 0x0d, 0xf0, 0xad, 0xba, 0x0d, 0xf0, 0xad, 0xba, - 0x0d, 0xf0, 0xad, 0xba, 0x0d, 0xf0, 0xad, 0xba, 0x0d, 0xf0, 0xad, 0xba, 0x0d, 0xf0, 0xad, 0xba, - 0x0d, 0xf0, 0xad, 0xba, 0x0d, 0xf0, 0xad, 0xba, 0x0d, 0xf0, 0xad, 0xba, 0x0d, 0xf0, 0xad, 0xba, - 0x0d, 0xf0, 0xad, 0xba, 0x0d, 0xf0, 0xad, 0xba, 0x0d, 0xf0, 0xad, 0xba, 0x0d, 0xf0, 0xad, 0xba, - }; - char *p; - UINT len, ret; - WCHAR FileDescriptionW[] = { '\\', '\\', 'S', 't', 'r', 'i', 'n', 'g', 'F', 'i', 'l', 'e', 'I', 'n', 'f', 'o', 0 }; - - p = (char *)0xdeadbeef; - len = 0xdeadbeef; - SetLastError(0xdeadbeef); - ret = VerQueryValueA(preparedbuffer, "StringFileInfo", (LPVOID *)&p, &len); - ok(ret, "VerQueryValueA error %u\n", GetLastError()); - todo_wine - ok(len == 0, "VerQueryValueA returned %u, expected 0\n", len); - todo_wine - ok(p == preparedbuffer + 0x7e, "p was %p, expected %p\n", p, preparedbuffer + 0x7e); - - p = (char *)0xdeadbeef; - len = 0xdeadbeef; - SetLastError(0xdeadbeef); - ret = VerQueryValueA(preparedbuffer, "\\StringFileInfo", (LPVOID *)&p, &len); - ok(ret, "VerQueryValueA error %u\n", GetLastError()); - todo_wine - ok(len == 0, "VerQueryValueA returned %u, expected 0\n", len); - todo_wine - ok(p == preparedbuffer + 0x7e, "p was %p, expected %p\n", p, preparedbuffer + 0x7e); - - p = (char *)0xdeadbeef; - len = 0xdeadbeef; - SetLastError(0xdeadbeef); - ret = VerQueryValueA(preparedbuffer, "\\\\StringFileInfo", (LPVOID *)&p, &len); - ok(ret, "VerQueryValueA error %u\n", GetLastError()); - todo_wine - ok(len == 0, "VerQueryValueA returned %u, expected 0\n", len); - todo_wine - ok(p == preparedbuffer + 0x7e, "p was %p, expected %p\n", p, preparedbuffer + 0x7e); - - /* also test the W versions. */ - p = (char *)0xdeadbeef; - len = 0xdeadbeef; - SetLastError(0xdeadbeef); - ret = VerQueryValueW(preparedbuffer, FileDescriptionW + 2, (LPVOID *)&p, &len); - ok(ret, "VerQueryValueW error %u\n", GetLastError()); - ok(len == 0, "VerQueryValueW returned %u, expected 0\n", len); - todo_wine - ok(p == preparedbuffer + 0x7e, "p was %p, expected %p\n", p, preparedbuffer + 0x7e); - - p = (char *)0xdeadbeef; - len = 0xdeadbeef; - SetLastError(0xdeadbeef); - ret = VerQueryValueW(preparedbuffer, FileDescriptionW + 1, (LPVOID *)&p, &len); - ok(ret, "VerQueryValueW error %u\n", GetLastError()); - ok(len == 0, "VerQueryValueW returned %u, expected 0\n", len); - todo_wine - ok(p == preparedbuffer + 0x7e, "p was %p, expected %p\n", p, preparedbuffer + 0x7e); - - p = (char *)0xdeadbeef; - len = 0xdeadbeef; - SetLastError(0xdeadbeef); - ret = VerQueryValueW(preparedbuffer, FileDescriptionW, (LPVOID *)&p, &len); - ok(ret, "VerQueryValueW error %u\n", GetLastError()); - ok(len == 0, "VerQueryValueW returned %u, expected 0\n", len); - todo_wine - ok(p == preparedbuffer + 0x7e, "p was %p, expected %p\n", p, preparedbuffer + 0x7e); -} - static void test_extra_block(void) { WORD extra_block[] = { @@ -864,7 +738,6 @@ START_TEST(info) test_info(); test_32bit_win(); test_VerQueryValueA(); - test_VerQueryValue_InvalidLength(); test_extra_block(); test_GetFileVersionInfoEx(); } diff --git a/modules/rostests/winetests/version/install.c b/modules/rostests/winetests/version/install.c index b06125ff50..9b84dce492 100644 --- a/modules/rostests/winetests/version/install.c +++ b/modules/rostests/winetests/version/install.c @@ -24,13 +24,11 @@ #include "winbase.h" #include "winerror.h" #include "winver.h" -#include "shlobj.h" static void test_find_file(void) { DWORD ret; UINT dwCur, dwOut ; - char tmp[MAX_PATH]; char appdir[MAX_PATH]; char curdir[MAX_PATH]; char filename[MAX_PATH]; @@ -117,11 +115,10 @@ static void test_find_file(void) } } } - if(!GetSystemDirectoryA(windir, MAX_PATH) || - !SHGetSpecialFolderPathA(0, appdir, CSIDL_PROGRAM_FILES, FALSE) || - !GetTempPathA(MAX_PATH, tmp) || - !GetTempFileNameA(tmp, "tes", 0, filename)) - ok(0, "GetSystemDirectoryA, SHGetSpecialFolderPathA, GetTempPathA or GetTempFileNameA failed\n"); + if(!GetModuleFileNameA(NULL, filename, MAX_PATH) || + !GetSystemDirectoryA(windir, MAX_PATH) || + !GetTempPathA(MAX_PATH, appdir)) + trace("GetModuleFileNameA, GetSystemDirectoryA or GetTempPathA failed\n"); else { char *p = strrchr(filename, '\\'); if(p) { @@ -153,7 +150,7 @@ static void test_find_file(void) memset(outBuf, 0, MAX_PATH); memset(curdir, 0, MAX_PATH); ret = VerFindFileA(VFFF_ISSHAREDFILE, filename, NULL, appdir, curdir, &dwCur, outBuf, &dwOut); - ok(VFF_CURNEDEST == ret, "Wrong return value got %x expected VFF_CURNEDEST\n", ret); + todo_wine ok(VFF_CURNEDEST == ret, "Wrong return value got %x expected VFF_CURNEDEST\n", ret); ok(dwOut == 1 + strlen(windir), "Wrong length of buffer for current location: " "got %d(%s) expected %d\n", dwOut, outBuf, lstrlenA(windir)+1); @@ -162,145 +159,9 @@ static void test_find_file(void) memset(outBuf, 0, MAX_PATH); memset(curdir, 0, MAX_PATH); ret = VerFindFileA(0, filename, NULL, appdir, curdir, &dwCur, outBuf, &dwOut); - ok(VFF_CURNEDEST == ret, "Wrong return value got %x expected VFF_CURNEDEST\n", ret); + todo_wine ok(VFF_CURNEDEST == ret, "Wrong return value got %x expected VFF_CURNEDEST\n", ret); ok(dwOut == 1 + strlen(appdir), "Wrong length of buffer for current location: " "got %d(%s) expected %d\n", dwOut, outBuf, lstrlenA(appdir)+1); - - /* search for filename */ - dwCur=MAX_PATH; - dwOut=MAX_PATH; - ret = VerFindFileA(0, filename, NULL, NULL, curdir, &dwCur, outBuf, &dwOut); - ok(ret & VFF_CURNEDEST, "Wrong return value got %x expected VFF_CURNEDEST set\n", ret); - - dwCur=MAX_PATH; - dwOut=MAX_PATH; - ret = VerFindFileA(0, filename, NULL, empty, curdir, &dwCur, outBuf, &dwOut); - ok(ret & VFF_CURNEDEST, "Wrong return value got %x expected VFF_CURNEDEST set\n", ret); - - dwCur=MAX_PATH; - dwOut=MAX_PATH; - ret = VerFindFileA(0, filename, NULL, appdir, curdir, &dwCur, outBuf, &dwOut); - ok(ret & VFF_CURNEDEST, "Wrong return value got %x expected VFF_CURNEDEST set\n", ret); - - dwCur=MAX_PATH; - dwOut=MAX_PATH; - ret = VerFindFileA(VFFF_ISSHAREDFILE, filename, NULL, NULL, curdir, &dwCur, outBuf, &dwOut); - ok(ret & VFF_CURNEDEST, "Wrong return value got %x expected VFF_CURNEDEST set\n", ret); - - dwCur=MAX_PATH; - dwOut=MAX_PATH; - ret = VerFindFileA(VFFF_ISSHAREDFILE, filename, NULL, empty, curdir, &dwCur, outBuf, &dwOut); - ok(ret & VFF_CURNEDEST, "Wrong return value got %x expected VFF_CURNEDEST set\n", ret); - - dwCur=MAX_PATH; - dwOut=MAX_PATH; - ret = VerFindFileA(VFFF_ISSHAREDFILE, filename, NULL, appdir, curdir, &dwCur, outBuf, &dwOut); - ok(ret & VFF_CURNEDEST, "Wrong return value got %x expected VFF_CURNEDEST set\n", ret); - - /* search for regedit */ - dwCur=MAX_PATH; - dwOut=MAX_PATH; - ret = VerFindFileA(0, "regedit", NULL, NULL, curdir, &dwCur, outBuf, &dwOut); - ok(!ret, "Wrong return value got %x expected 0\n", ret); - - dwCur=MAX_PATH; - dwOut=MAX_PATH; - ret = VerFindFileA(0, "regedit", NULL, empty, curdir, &dwCur, outBuf, &dwOut); - ok(!ret, "Wrong return value got %x expected 0\n", ret); - - dwCur=MAX_PATH; - dwOut=MAX_PATH; - ret = VerFindFileA(0, "regedit", NULL, appdir, curdir, &dwCur, outBuf, &dwOut); - ok(ret & VFF_CURNEDEST, "Wrong return value got %x expected VFF_CURNEDEST set\n", ret); - - dwCur=MAX_PATH; - dwOut=MAX_PATH; - ret = VerFindFileA(VFFF_ISSHAREDFILE, "regedit", NULL, NULL, curdir, &dwCur, outBuf, &dwOut); - ok(ret & VFF_CURNEDEST, "Wrong return value got %x expected VFF_CURNEDEST set\n", ret); - - dwCur=MAX_PATH; - dwOut=MAX_PATH; - ret = VerFindFileA(VFFF_ISSHAREDFILE, "regedit", NULL, empty, curdir, &dwCur, outBuf, &dwOut); - ok(ret & VFF_CURNEDEST, "Wrong return value got %x expected VFF_CURNEDEST set\n", ret); - - dwCur=MAX_PATH; - dwOut=MAX_PATH; - ret = VerFindFileA(VFFF_ISSHAREDFILE, "regedit", NULL, appdir, curdir, &dwCur, outBuf, &dwOut); - ok(ret & VFF_CURNEDEST, "Wrong return value got %x expected VFF_CURNEDEST set\n", ret); - - /* search for regedit.exe */ - dwCur=MAX_PATH; - dwOut=MAX_PATH; - ret = VerFindFileA(0, "regedit.exe", NULL, NULL, curdir, &dwCur, outBuf, &dwOut); - ok(ret & VFF_CURNEDEST, "Wrong return value got %x expected VFF_CURNEDEST set\n", ret); - - dwCur=MAX_PATH; - dwOut=MAX_PATH; - ret = VerFindFileA(0, "regedit.exe", NULL, empty, curdir, &dwCur, outBuf, &dwOut); - ok(ret & VFF_CURNEDEST, "Wrong return value got %x expected VFF_CURNEDEST set\n", ret); - - dwCur=MAX_PATH; - dwOut=MAX_PATH; - ret = VerFindFileA(0, "regedit.exe", NULL, appdir, curdir, &dwCur, outBuf, &dwOut); - ok(ret & VFF_CURNEDEST, "Wrong return value got %x expected VFF_CURNEDEST set\n", ret); - - dwCur=MAX_PATH; - dwOut=MAX_PATH; - ret = VerFindFileA(VFFF_ISSHAREDFILE, "regedit.exe", NULL, NULL, curdir, &dwCur, outBuf, &dwOut); - ok(ret & VFF_CURNEDEST, "Wrong return value got %x expected VFF_CURNEDEST set\n", ret); - - dwCur=MAX_PATH; - dwOut=MAX_PATH; - ret = VerFindFileA(VFFF_ISSHAREDFILE, "regedit.exe", NULL, empty, curdir, &dwCur, outBuf, &dwOut); - ok(ret & VFF_CURNEDEST, "Wrong return value got %x expected VFF_CURNEDEST set\n", ret); - - dwCur=MAX_PATH; - dwOut=MAX_PATH; - ret = VerFindFileA(VFFF_ISSHAREDFILE, "regedit.exe", NULL, appdir, curdir, &dwCur, outBuf, &dwOut); - ok(ret & VFF_CURNEDEST, "Wrong return value got %x expected VFF_CURNEDEST set\n", ret); - - /* nonexistent filename */ - dwCur=MAX_PATH; - dwOut=MAX_PATH; - ret = VerFindFileA(0, "doesnotexist.exe", NULL, NULL, curdir, &dwCur, outBuf, &dwOut); - ok(!ret, "Wrong return value got %x expected 0\n", ret); - - dwCur=MAX_PATH; - dwOut=MAX_PATH; - ret = VerFindFileA(0, "doesnotexist.exe", NULL, empty, curdir, &dwCur, outBuf, &dwOut); - ok(!ret, "Wrong return value got %x expected 0\n", ret); - - dwCur=MAX_PATH; - dwOut=MAX_PATH; - ret = VerFindFileA(0, "doesnotexist.exe", NULL, appdir, curdir, &dwCur, outBuf, &dwOut); - ok(ret & VFF_CURNEDEST, "Wrong return value got %x expected VFF_CURNEDEST set\n", ret); - - dwCur=MAX_PATH; - dwOut=MAX_PATH; - ret = VerFindFileA(0, "doesnotexist.exe", NULL, "C:\\random_path_does_not_exist", curdir, &dwCur, outBuf, &dwOut); - ok(ret & VFF_CURNEDEST, "Wrong return value got %x expected VFF_CURNEDEST set\n", ret); - - dwCur=MAX_PATH; - dwOut=MAX_PATH; - ret = VerFindFileA(VFFF_ISSHAREDFILE, "doesnotexist.exe", NULL, NULL, curdir, &dwCur, outBuf, &dwOut); - ok(ret & VFF_CURNEDEST, "Wrong return value got %x expected VFF_CURNEDEST set\n", ret); - - dwCur=MAX_PATH; - dwOut=MAX_PATH; - ret = VerFindFileA(VFFF_ISSHAREDFILE, "doesnotexist.exe", NULL, empty, curdir, &dwCur, outBuf, &dwOut); - ok(ret & VFF_CURNEDEST, "Wrong return value got %x expected VFF_CURNEDEST set\n", ret); - - dwCur=MAX_PATH; - dwOut=MAX_PATH; - ret = VerFindFileA(VFFF_ISSHAREDFILE, "doesnotexist.exe", NULL, appdir, curdir, &dwCur, outBuf, &dwOut); - ok(ret & VFF_CURNEDEST, "Wrong return value got %x expected VFF_CURNEDEST set\n", ret); - - dwCur=MAX_PATH; - dwOut=MAX_PATH; - ret = VerFindFileA(VFFF_ISSHAREDFILE, "doesnotexist.exe", NULL, "C:\\random_path_does_not_exist", curdir, &dwCur, outBuf, &dwOut); - ok(ret & VFF_CURNEDEST, "Wrong return value got %x expected VFF_CURNEDEST set\n", ret); - - DeleteFileA(filename); } }
1
0
0
0
← Newer
1
...
1516
1517
1518
1519
1520
1521
1522
...
8139
Older →
Jump to page:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344
2345
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
2375
2376
2377
2378
2379
2380
2381
2382
2383
2384
2385
2386
2387
2388
2389
2390
2391
2392
2393
2394
2395
2396
2397
2398
2399
2400
2401
2402
2403
2404
2405
2406
2407
2408
2409
2410
2411
2412
2413
2414
2415
2416
2417
2418
2419
2420
2421
2422
2423
2424
2425
2426
2427
2428
2429
2430
2431
2432
2433
2434
2435
2436
2437
2438
2439
2440
2441
2442
2443
2444
2445
2446
2447
2448
2449
2450
2451
2452
2453
2454
2455
2456
2457
2458
2459
2460
2461
2462
2463
2464
2465
2466
2467
2468
2469
2470
2471
2472
2473
2474
2475
2476
2477
2478
2479
2480
2481
2482
2483
2484
2485
2486
2487
2488
2489
2490
2491
2492
2493
2494
2495
2496
2497
2498
2499
2500
2501
2502
2503
2504
2505
2506
2507
2508
2509
2510
2511
2512
2513
2514
2515
2516
2517
2518
2519
2520
2521
2522
2523
2524
2525
2526
2527
2528
2529
2530
2531
2532
2533
2534
2535
2536
2537
2538
2539
2540
2541
2542
2543
2544
2545
2546
2547
2548
2549
2550
2551
2552
2553
2554
2555
2556
2557
2558
2559
2560
2561
2562
2563
2564
2565
2566
2567
2568
2569
2570
2571
2572
2573
2574
2575
2576
2577
2578
2579
2580
2581
2582
2583
2584
2585
2586
2587
2588
2589
2590
2591
2592
2593
2594
2595
2596
2597
2598
2599
2600
2601
2602
2603
2604
2605
2606
2607
2608
2609
2610
2611
2612
2613
2614
2615
2616
2617
2618
2619
2620
2621
2622
2623
2624
2625
2626
2627
2628
2629
2630
2631
2632
2633
2634
2635
2636
2637
2638
2639
2640
2641
2642
2643
2644
2645
2646
2647
2648
2649
2650
2651
2652
2653
2654
2655
2656
2657
2658
2659
2660
2661
2662
2663
2664
2665
2666
2667
2668
2669
2670
2671
2672
2673
2674
2675
2676
2677
2678
2679
2680
2681
2682
2683
2684
2685
2686
2687
2688
2689
2690
2691
2692
2693
2694
2695
2696
2697
2698
2699
2700
2701
2702
2703
2704
2705
2706
2707
2708
2709
2710
2711
2712
2713
2714
2715
2716
2717
2718
2719
2720
2721
2722
2723
2724
2725
2726
2727
2728
2729
2730
2731
2732
2733
2734
2735
2736
2737
2738
2739
2740
2741
2742
2743
2744
2745
2746
2747
2748
2749
2750
2751
2752
2753
2754
2755
2756
2757
2758
2759
2760
2761
2762
2763
2764
2765
2766
2767
2768
2769
2770
2771
2772
2773
2774
2775
2776
2777
2778
2779
2780
2781
2782
2783
2784
2785
2786
2787
2788
2789
2790
2791
2792
2793
2794
2795
2796
2797
2798
2799
2800
2801
2802
2803
2804
2805
2806
2807
2808
2809
2810
2811
2812
2813
2814
2815
2816
2817
2818
2819
2820
2821
2822
2823
2824
2825
2826
2827
2828
2829
2830
2831
2832
2833
2834
2835
2836
2837
2838
2839
2840
2841
2842
2843
2844
2845
2846
2847
2848
2849
2850
2851
2852
2853
2854
2855
2856
2857
2858
2859
2860
2861
2862
2863
2864
2865
2866
2867
2868
2869
2870
2871
2872
2873
2874
2875
2876
2877
2878
2879
2880
2881
2882
2883
2884
2885
2886
2887
2888
2889
2890
2891
2892
2893
2894
2895
2896
2897
2898
2899
2900
2901
2902
2903
2904
2905
2906
2907
2908
2909
2910
2911
2912
2913
2914
2915
2916
2917
2918
2919
2920
2921
2922
2923
2924
2925
2926
2927
2928
2929
2930
2931
2932
2933
2934
2935
2936
2937
2938
2939
2940
2941
2942
2943
2944
2945
2946
2947
2948
2949
2950
2951
2952
2953
2954
2955
2956
2957
2958
2959
2960
2961
2962
2963
2964
2965
2966
2967
2968
2969
2970
2971
2972
2973
2974
2975
2976
2977
2978
2979
2980
2981
2982
2983
2984
2985
2986
2987
2988
2989
2990
2991
2992
2993
2994
2995
2996
2997
2998
2999
3000
3001
3002
3003
3004
3005
3006
3007
3008
3009
3010
3011
3012
3013
3014
3015
3016
3017
3018
3019
3020
3021
3022
3023
3024
3025
3026
3027
3028
3029
3030
3031
3032
3033
3034
3035
3036
3037
3038
3039
3040
3041
3042
3043
3044
3045
3046
3047
3048
3049
3050
3051
3052
3053
3054
3055
3056
3057
3058
3059
3060
3061
3062
3063
3064
3065
3066
3067
3068
3069
3070
3071
3072
3073
3074
3075
3076
3077
3078
3079
3080
3081
3082
3083
3084
3085
3086
3087
3088
3089
3090
3091
3092
3093
3094
3095
3096
3097
3098
3099
3100
3101
3102
3103
3104
3105
3106
3107
3108
3109
3110
3111
3112
3113
3114
3115
3116
3117
3118
3119
3120
3121
3122
3123
3124
3125
3126
3127
3128
3129
3130
3131
3132
3133
3134
3135
3136
3137
3138
3139
3140
3141
3142
3143
3144
3145
3146
3147
3148
3149
3150
3151
3152
3153
3154
3155
3156
3157
3158
3159
3160
3161
3162
3163
3164
3165
3166
3167
3168
3169
3170
3171
3172
3173
3174
3175
3176
3177
3178
3179
3180
3181
3182
3183
3184
3185
3186
3187
3188
3189
3190
3191
3192
3193
3194
3195
3196
3197
3198
3199
3200
3201
3202
3203
3204
3205
3206
3207
3208
3209
3210
3211
3212
3213
3214
3215
3216
3217
3218
3219
3220
3221
3222
3223
3224
3225
3226
3227
3228
3229
3230
3231
3232
3233
3234
3235
3236
3237
3238
3239
3240
3241
3242
3243
3244
3245
3246
3247
3248
3249
3250
3251
3252
3253
3254
3255
3256
3257
3258
3259
3260
3261
3262
3263
3264
3265
3266
3267
3268
3269
3270
3271
3272
3273
3274
3275
3276
3277
3278
3279
3280
3281
3282
3283
3284
3285
3286
3287
3288
3289
3290
3291
3292
3293
3294
3295
3296
3297
3298
3299
3300
3301
3302
3303
3304
3305
3306
3307
3308
3309
3310
3311
3312
3313
3314
3315
3316
3317
3318
3319
3320
3321
3322
3323
3324
3325
3326
3327
3328
3329
3330
3331
3332
3333
3334
3335
3336
3337
3338
3339
3340
3341
3342
3343
3344
3345
3346
3347
3348
3349
3350
3351
3352
3353
3354
3355
3356
3357
3358
3359
3360
3361
3362
3363
3364
3365
3366
3367
3368
3369
3370
3371
3372
3373
3374
3375
3376
3377
3378
3379
3380
3381
3382
3383
3384
3385
3386
3387
3388
3389
3390
3391
3392
3393
3394
3395
3396
3397
3398
3399
3400
3401
3402
3403
3404
3405
3406
3407
3408
3409
3410
3411
3412
3413
3414
3415
3416
3417
3418
3419
3420
3421
3422
3423
3424
3425
3426
3427
3428
3429
3430
3431
3432
3433
3434
3435
3436
3437
3438
3439
3440
3441
3442
3443
3444
3445
3446
3447
3448
3449
3450
3451
3452
3453
3454
3455
3456
3457
3458
3459
3460
3461
3462
3463
3464
3465
3466
3467
3468
3469
3470
3471
3472
3473
3474
3475
3476
3477
3478
3479
3480
3481
3482
3483
3484
3485
3486
3487
3488
3489
3490
3491
3492
3493
3494
3495
3496
3497
3498
3499
3500
3501
3502
3503
3504
3505
3506
3507
3508
3509
3510
3511
3512
3513
3514
3515
3516
3517
3518
3519
3520
3521
3522
3523
3524
3525
3526
3527
3528
3529
3530
3531
3532
3533
3534
3535
3536
3537
3538
3539
3540
3541
3542
3543
3544
3545
3546
3547
3548
3549
3550
3551
3552
3553
3554
3555
3556
3557
3558
3559
3560
3561
3562
3563
3564
3565
3566
3567
3568
3569
3570
3571
3572
3573
3574
3575
3576
3577
3578
3579
3580
3581
3582
3583
3584
3585
3586
3587
3588
3589
3590
3591
3592
3593
3594
3595
3596
3597
3598
3599
3600
3601
3602
3603
3604
3605
3606
3607
3608
3609
3610
3611
3612
3613
3614
3615
3616
3617
3618
3619
3620
3621
3622
3623
3624
3625
3626
3627
3628
3629
3630
3631
3632
3633
3634
3635
3636
3637
3638
3639
3640
3641
3642
3643
3644
3645
3646
3647
3648
3649
3650
3651
3652
3653
3654
3655
3656
3657
3658
3659
3660
3661
3662
3663
3664
3665
3666
3667
3668
3669
3670
3671
3672
3673
3674
3675
3676
3677
3678
3679
3680
3681
3682
3683
3684
3685
3686
3687
3688
3689
3690
3691
3692
3693
3694
3695
3696
3697
3698
3699
3700
3701
3702
3703
3704
3705
3706
3707
3708
3709
3710
3711
3712
3713
3714
3715
3716
3717
3718
3719
3720
3721
3722
3723
3724
3725
3726
3727
3728
3729
3730
3731
3732
3733
3734
3735
3736
3737
3738
3739
3740
3741
3742
3743
3744
3745
3746
3747
3748
3749
3750
3751
3752
3753
3754
3755
3756
3757
3758
3759
3760
3761
3762
3763
3764
3765
3766
3767
3768
3769
3770
3771
3772
3773
3774
3775
3776
3777
3778
3779
3780
3781
3782
3783
3784
3785
3786
3787
3788
3789
3790
3791
3792
3793
3794
3795
3796
3797
3798
3799
3800
3801
3802
3803
3804
3805
3806
3807
3808
3809
3810
3811
3812
3813
3814
3815
3816
3817
3818
3819
3820
3821
3822
3823
3824
3825
3826
3827
3828
3829
3830
3831
3832
3833
3834
3835
3836
3837
3838
3839
3840
3841
3842
3843
3844
3845
3846
3847
3848
3849
3850
3851
3852
3853
3854
3855
3856
3857
3858
3859
3860
3861
3862
3863
3864
3865
3866
3867
3868
3869
3870
3871
3872
3873
3874
3875
3876
3877
3878
3879
3880
3881
3882
3883
3884
3885
3886
3887
3888
3889
3890
3891
3892
3893
3894
3895
3896
3897
3898
3899
3900
3901
3902
3903
3904
3905
3906
3907
3908
3909
3910
3911
3912
3913
3914
3915
3916
3917
3918
3919
3920
3921
3922
3923
3924
3925
3926
3927
3928
3929
3930
3931
3932
3933
3934
3935
3936
3937
3938
3939
3940
3941
3942
3943
3944
3945
3946
3947
3948
3949
3950
3951
3952
3953
3954
3955
3956
3957
3958
3959
3960
3961
3962
3963
3964
3965
3966
3967
3968
3969
3970
3971
3972
3973
3974
3975
3976
3977
3978
3979
3980
3981
3982
3983
3984
3985
3986
3987
3988
3989
3990
3991
3992
3993
3994
3995
3996
3997
3998
3999
4000
4001
4002
4003
4004
4005
4006
4007
4008
4009
4010
4011
4012
4013
4014
4015
4016
4017
4018
4019
4020
4021
4022
4023
4024
4025
4026
4027
4028
4029
4030
4031
4032
4033
4034
4035
4036
4037
4038
4039
4040
4041
4042
4043
4044
4045
4046
4047
4048
4049
4050
4051
4052
4053
4054
4055
4056
4057
4058
4059
4060
4061
4062
4063
4064
4065
4066
4067
4068
4069
4070
4071
4072
4073
4074
4075
4076
4077
4078
4079
4080
4081
4082
4083
4084
4085
4086
4087
4088
4089
4090
4091
4092
4093
4094
4095
4096
4097
4098
4099
4100
4101
4102
4103
4104
4105
4106
4107
4108
4109
4110
4111
4112
4113
4114
4115
4116
4117
4118
4119
4120
4121
4122
4123
4124
4125
4126
4127
4128
4129
4130
4131
4132
4133
4134
4135
4136
4137
4138
4139
4140
4141
4142
4143
4144
4145
4146
4147
4148
4149
4150
4151
4152
4153
4154
4155
4156
4157
4158
4159
4160
4161
4162
4163
4164
4165
4166
4167
4168
4169
4170
4171
4172
4173
4174
4175
4176
4177
4178
4179
4180
4181
4182
4183
4184
4185
4186
4187
4188
4189
4190
4191
4192
4193
4194
4195
4196
4197
4198
4199
4200
4201
4202
4203
4204
4205
4206
4207
4208
4209
4210
4211
4212
4213
4214
4215
4216
4217
4218
4219
4220
4221
4222
4223
4224
4225
4226
4227
4228
4229
4230
4231
4232
4233
4234
4235
4236
4237
4238
4239
4240
4241
4242
4243
4244
4245
4246
4247
4248
4249
4250
4251
4252
4253
4254
4255
4256
4257
4258
4259
4260
4261
4262
4263
4264
4265
4266
4267
4268
4269
4270
4271
4272
4273
4274
4275
4276
4277
4278
4279
4280
4281
4282
4283
4284
4285
4286
4287
4288
4289
4290
4291
4292
4293
4294
4295
4296
4297
4298
4299
4300
4301
4302
4303
4304
4305
4306
4307
4308
4309
4310
4311
4312
4313
4314
4315
4316
4317
4318
4319
4320
4321
4322
4323
4324
4325
4326
4327
4328
4329
4330
4331
4332
4333
4334
4335
4336
4337
4338
4339
4340
4341
4342
4343
4344
4345
4346
4347
4348
4349
4350
4351
4352
4353
4354
4355
4356
4357
4358
4359
4360
4361
4362
4363
4364
4365
4366
4367
4368
4369
4370
4371
4372
4373
4374
4375
4376
4377
4378
4379
4380
4381
4382
4383
4384
4385
4386
4387
4388
4389
4390
4391
4392
4393
4394
4395
4396
4397
4398
4399
4400
4401
4402
4403
4404
4405
4406
4407
4408
4409
4410
4411
4412
4413
4414
4415
4416
4417
4418
4419
4420
4421
4422
4423
4424
4425
4426
4427
4428
4429
4430
4431
4432
4433
4434
4435
4436
4437
4438
4439
4440
4441
4442
4443
4444
4445
4446
4447
4448
4449
4450
4451
4452
4453
4454
4455
4456
4457
4458
4459
4460
4461
4462
4463
4464
4465
4466
4467
4468
4469
4470
4471
4472
4473
4474
4475
4476
4477
4478
4479
4480
4481
4482
4483
4484
4485
4486
4487
4488
4489
4490
4491
4492
4493
4494
4495
4496
4497
4498
4499
4500
4501
4502
4503
4504
4505
4506
4507
4508
4509
4510
4511
4512
4513
4514
4515
4516
4517
4518
4519
4520
4521
4522
4523
4524
4525
4526
4527
4528
4529
4530
4531
4532
4533
4534
4535
4536
4537
4538
4539
4540
4541
4542
4543
4544
4545
4546
4547
4548
4549
4550
4551
4552
4553
4554
4555
4556
4557
4558
4559
4560
4561
4562
4563
4564
4565
4566
4567
4568
4569
4570
4571
4572
4573
4574
4575
4576
4577
4578
4579
4580
4581
4582
4583
4584
4585
4586
4587
4588
4589
4590
4591
4592
4593
4594
4595
4596
4597
4598
4599
4600
4601
4602
4603
4604
4605
4606
4607
4608
4609
4610
4611
4612
4613
4614
4615
4616
4617
4618
4619
4620
4621
4622
4623
4624
4625
4626
4627
4628
4629
4630
4631
4632
4633
4634
4635
4636
4637
4638
4639
4640
4641
4642
4643
4644
4645
4646
4647
4648
4649
4650
4651
4652
4653
4654
4655
4656
4657
4658
4659
4660
4661
4662
4663
4664
4665
4666
4667
4668
4669
4670
4671
4672
4673
4674
4675
4676
4677
4678
4679
4680
4681
4682
4683
4684
4685
4686
4687
4688
4689
4690
4691
4692
4693
4694
4695
4696
4697
4698
4699
4700
4701
4702
4703
4704
4705
4706
4707
4708
4709
4710
4711
4712
4713
4714
4715
4716
4717
4718
4719
4720
4721
4722
4723
4724
4725
4726
4727
4728
4729
4730
4731
4732
4733
4734
4735
4736
4737
4738
4739
4740
4741
4742
4743
4744
4745
4746
4747
4748
4749
4750
4751
4752
4753
4754
4755
4756
4757
4758
4759
4760
4761
4762
4763
4764
4765
4766
4767
4768
4769
4770
4771
4772
4773
4774
4775
4776
4777
4778
4779
4780
4781
4782
4783
4784
4785
4786
4787
4788
4789
4790
4791
4792
4793
4794
4795
4796
4797
4798
4799
4800
4801
4802
4803
4804
4805
4806
4807
4808
4809
4810
4811
4812
4813
4814
4815
4816
4817
4818
4819
4820
4821
4822
4823
4824
4825
4826
4827
4828
4829
4830
4831
4832
4833
4834
4835
4836
4837
4838
4839
4840
4841
4842
4843
4844
4845
4846
4847
4848
4849
4850
4851
4852
4853
4854
4855
4856
4857
4858
4859
4860
4861
4862
4863
4864
4865
4866
4867
4868
4869
4870
4871
4872
4873
4874
4875
4876
4877
4878
4879
4880
4881
4882
4883
4884
4885
4886
4887
4888
4889
4890
4891
4892
4893
4894
4895
4896
4897
4898
4899
4900
4901
4902
4903
4904
4905
4906
4907
4908
4909
4910
4911
4912
4913
4914
4915
4916
4917
4918
4919
4920
4921
4922
4923
4924
4925
4926
4927
4928
4929
4930
4931
4932
4933
4934
4935
4936
4937
4938
4939
4940
4941
4942
4943
4944
4945
4946
4947
4948
4949
4950
4951
4952
4953
4954
4955
4956
4957
4958
4959
4960
4961
4962
4963
4964
4965
4966
4967
4968
4969
4970
4971
4972
4973
4974
4975
4976
4977
4978
4979
4980
4981
4982
4983
4984
4985
4986
4987
4988
4989
4990
4991
4992
4993
4994
4995
4996
4997
4998
4999
5000
5001
5002
5003
5004
5005
5006
5007
5008
5009
5010
5011
5012
5013
5014
5015
5016
5017
5018
5019
5020
5021
5022
5023
5024
5025
5026
5027
5028
5029
5030
5031
5032
5033
5034
5035
5036
5037
5038
5039
5040
5041
5042
5043
5044
5045
5046
5047
5048
5049
5050
5051
5052
5053
5054
5055
5056
5057
5058
5059
5060
5061
5062
5063
5064
5065
5066
5067
5068
5069
5070
5071
5072
5073
5074
5075
5076
5077
5078
5079
5080
5081
5082
5083
5084
5085
5086
5087
5088
5089
5090
5091
5092
5093
5094
5095
5096
5097
5098
5099
5100
5101
5102
5103
5104
5105
5106
5107
5108
5109
5110
5111
5112
5113
5114
5115
5116
5117
5118
5119
5120
5121
5122
5123
5124
5125
5126
5127
5128
5129
5130
5131
5132
5133
5134
5135
5136
5137
5138
5139
5140
5141
5142
5143
5144
5145
5146
5147
5148
5149
5150
5151
5152
5153
5154
5155
5156
5157
5158
5159
5160
5161
5162
5163
5164
5165
5166
5167
5168
5169
5170
5171
5172
5173
5174
5175
5176
5177
5178
5179
5180
5181
5182
5183
5184
5185
5186
5187
5188
5189
5190
5191
5192
5193
5194
5195
5196
5197
5198
5199
5200
5201
5202
5203
5204
5205
5206
5207
5208
5209
5210
5211
5212
5213
5214
5215
5216
5217
5218
5219
5220
5221
5222
5223
5224
5225
5226
5227
5228
5229
5230
5231
5232
5233
5234
5235
5236
5237
5238
5239
5240
5241
5242
5243
5244
5245
5246
5247
5248
5249
5250
5251
5252
5253
5254
5255
5256
5257
5258
5259
5260
5261
5262
5263
5264
5265
5266
5267
5268
5269
5270
5271
5272
5273
5274
5275
5276
5277
5278
5279
5280
5281
5282
5283
5284
5285
5286
5287
5288
5289
5290
5291
5292
5293
5294
5295
5296
5297
5298
5299
5300
5301
5302
5303
5304
5305
5306
5307
5308
5309
5310
5311
5312
5313
5314
5315
5316
5317
5318
5319
5320
5321
5322
5323
5324
5325
5326
5327
5328
5329
5330
5331
5332
5333
5334
5335
5336
5337
5338
5339
5340
5341
5342
5343
5344
5345
5346
5347
5348
5349
5350
5351
5352
5353
5354
5355
5356
5357
5358
5359
5360
5361
5362
5363
5364
5365
5366
5367
5368
5369
5370
5371
5372
5373
5374
5375
5376
5377
5378
5379
5380
5381
5382
5383
5384
5385
5386
5387
5388
5389
5390
5391
5392
5393
5394
5395
5396
5397
5398
5399
5400
5401
5402
5403
5404
5405
5406
5407
5408
5409
5410
5411
5412
5413
5414
5415
5416
5417
5418
5419
5420
5421
5422
5423
5424
5425
5426
5427
5428
5429
5430
5431
5432
5433
5434
5435
5436
5437
5438
5439
5440
5441
5442
5443
5444
5445
5446
5447
5448
5449
5450
5451
5452
5453
5454
5455
5456
5457
5458
5459
5460
5461
5462
5463
5464
5465
5466
5467
5468
5469
5470
5471
5472
5473
5474
5475
5476
5477
5478
5479
5480
5481
5482
5483
5484
5485
5486
5487
5488
5489
5490
5491
5492
5493
5494
5495
5496
5497
5498
5499
5500
5501
5502
5503
5504
5505
5506
5507
5508
5509
5510
5511
5512
5513
5514
5515
5516
5517
5518
5519
5520
5521
5522
5523
5524
5525
5526
5527
5528
5529
5530
5531
5532
5533
5534
5535
5536
5537
5538
5539
5540
5541
5542
5543
5544
5545
5546
5547
5548
5549
5550
5551
5552
5553
5554
5555
5556
5557
5558
5559
5560
5561
5562
5563
5564
5565
5566
5567
5568
5569
5570
5571
5572
5573
5574
5575
5576
5577
5578
5579
5580
5581
5582
5583
5584
5585
5586
5587
5588
5589
5590
5591
5592
5593
5594
5595
5596
5597
5598
5599
5600
5601
5602
5603
5604
5605
5606
5607
5608
5609
5610
5611
5612
5613
5614
5615
5616
5617
5618
5619
5620
5621
5622
5623
5624
5625
5626
5627
5628
5629
5630
5631
5632
5633
5634
5635
5636
5637
5638
5639
5640
5641
5642
5643
5644
5645
5646
5647
5648
5649
5650
5651
5652
5653
5654
5655
5656
5657
5658
5659
5660
5661
5662
5663
5664
5665
5666
5667
5668
5669
5670
5671
5672
5673
5674
5675
5676
5677
5678
5679
5680
5681
5682
5683
5684
5685
5686
5687
5688
5689
5690
5691
5692
5693
5694
5695
5696
5697
5698
5699
5700
5701
5702
5703
5704
5705
5706
5707
5708
5709
5710
5711
5712
5713
5714
5715
5716
5717
5718
5719
5720
5721
5722
5723
5724
5725
5726
5727
5728
5729
5730
5731
5732
5733
5734
5735
5736
5737
5738
5739
5740
5741
5742
5743
5744
5745
5746
5747
5748
5749
5750
5751
5752
5753
5754
5755
5756
5757
5758
5759
5760
5761
5762
5763
5764
5765
5766
5767
5768
5769
5770
5771
5772
5773
5774
5775
5776
5777
5778
5779
5780
5781
5782
5783
5784
5785
5786
5787
5788
5789
5790
5791
5792
5793
5794
5795
5796
5797
5798
5799
5800
5801
5802
5803
5804
5805
5806
5807
5808
5809
5810
5811
5812
5813
5814
5815
5816
5817
5818
5819
5820
5821
5822
5823
5824
5825
5826
5827
5828
5829
5830
5831
5832
5833
5834
5835
5836
5837
5838
5839
5840
5841
5842
5843
5844
5845
5846
5847
5848
5849
5850
5851
5852
5853
5854
5855
5856
5857
5858
5859
5860
5861
5862
5863
5864
5865
5866
5867
5868
5869
5870
5871
5872
5873
5874
5875
5876
5877
5878
5879
5880
5881
5882
5883
5884
5885
5886
5887
5888
5889
5890
5891
5892
5893
5894
5895
5896
5897
5898
5899
5900
5901
5902
5903
5904
5905
5906
5907
5908
5909
5910
5911
5912
5913
5914
5915
5916
5917
5918
5919
5920
5921
5922
5923
5924
5925
5926
5927
5928
5929
5930
5931
5932
5933
5934
5935
5936
5937
5938
5939
5940
5941
5942
5943
5944
5945
5946
5947
5948
5949
5950
5951
5952
5953
5954
5955
5956
5957
5958
5959
5960
5961
5962
5963
5964
5965
5966
5967
5968
5969
5970
5971
5972
5973
5974
5975
5976
5977
5978
5979
5980
5981
5982
5983
5984
5985
5986
5987
5988
5989
5990
5991
5992
5993
5994
5995
5996
5997
5998
5999
6000
6001
6002
6003
6004
6005
6006
6007
6008
6009
6010
6011
6012
6013
6014
6015
6016
6017
6018
6019
6020
6021
6022
6023
6024
6025
6026
6027
6028
6029
6030
6031
6032
6033
6034
6035
6036
6037
6038
6039
6040
6041
6042
6043
6044
6045
6046
6047
6048
6049
6050
6051
6052
6053
6054
6055
6056
6057
6058
6059
6060
6061
6062
6063
6064
6065
6066
6067
6068
6069
6070
6071
6072
6073
6074
6075
6076
6077
6078
6079
6080
6081
6082
6083
6084
6085
6086
6087
6088
6089
6090
6091
6092
6093
6094
6095
6096
6097
6098
6099
6100
6101
6102
6103
6104
6105
6106
6107
6108
6109
6110
6111
6112
6113
6114
6115
6116
6117
6118
6119
6120
6121
6122
6123
6124
6125
6126
6127
6128
6129
6130
6131
6132
6133
6134
6135
6136
6137
6138
6139
6140
6141
6142
6143
6144
6145
6146
6147
6148
6149
6150
6151
6152
6153
6154
6155
6156
6157
6158
6159
6160
6161
6162
6163
6164
6165
6166
6167
6168
6169
6170
6171
6172
6173
6174
6175
6176
6177
6178
6179
6180
6181
6182
6183
6184
6185
6186
6187
6188
6189
6190
6191
6192
6193
6194
6195
6196
6197
6198
6199
6200
6201
6202
6203
6204
6205
6206
6207
6208
6209
6210
6211
6212
6213
6214
6215
6216
6217
6218
6219
6220
6221
6222
6223
6224
6225
6226
6227
6228
6229
6230
6231
6232
6233
6234
6235
6236
6237
6238
6239
6240
6241
6242
6243
6244
6245
6246
6247
6248
6249
6250
6251
6252
6253
6254
6255
6256
6257
6258
6259
6260
6261
6262
6263
6264
6265
6266
6267
6268
6269
6270
6271
6272
6273
6274
6275
6276
6277
6278
6279
6280
6281
6282
6283
6284
6285
6286
6287
6288
6289
6290
6291
6292
6293
6294
6295
6296
6297
6298
6299
6300
6301
6302
6303
6304
6305
6306
6307
6308
6309
6310
6311
6312
6313
6314
6315
6316
6317
6318
6319
6320
6321
6322
6323
6324
6325
6326
6327
6328
6329
6330
6331
6332
6333
6334
6335
6336
6337
6338
6339
6340
6341
6342
6343
6344
6345
6346
6347
6348
6349
6350
6351
6352
6353
6354
6355
6356
6357
6358
6359
6360
6361
6362
6363
6364
6365
6366
6367
6368
6369
6370
6371
6372
6373
6374
6375
6376
6377
6378
6379
6380
6381
6382
6383
6384
6385
6386
6387
6388
6389
6390
6391
6392
6393
6394
6395
6396
6397
6398
6399
6400
6401
6402
6403
6404
6405
6406
6407
6408
6409
6410
6411
6412
6413
6414
6415
6416
6417
6418
6419
6420
6421
6422
6423
6424
6425
6426
6427
6428
6429
6430
6431
6432
6433
6434
6435
6436
6437
6438
6439
6440
6441
6442
6443
6444
6445
6446
6447
6448
6449
6450
6451
6452
6453
6454
6455
6456
6457
6458
6459
6460
6461
6462
6463
6464
6465
6466
6467
6468
6469
6470
6471
6472
6473
6474
6475
6476
6477
6478
6479
6480
6481
6482
6483
6484
6485
6486
6487
6488
6489
6490
6491
6492
6493
6494
6495
6496
6497
6498
6499
6500
6501
6502
6503
6504
6505
6506
6507
6508
6509
6510
6511
6512
6513
6514
6515
6516
6517
6518
6519
6520
6521
6522
6523
6524
6525
6526
6527
6528
6529
6530
6531
6532
6533
6534
6535
6536
6537
6538
6539
6540
6541
6542
6543
6544
6545
6546
6547
6548
6549
6550
6551
6552
6553
6554
6555
6556
6557
6558
6559
6560
6561
6562
6563
6564
6565
6566
6567
6568
6569
6570
6571
6572
6573
6574
6575
6576
6577
6578
6579
6580
6581
6582
6583
6584
6585
6586
6587
6588
6589
6590
6591
6592
6593
6594
6595
6596
6597
6598
6599
6600
6601
6602
6603
6604
6605
6606
6607
6608
6609
6610
6611
6612
6613
6614
6615
6616
6617
6618
6619
6620
6621
6622
6623
6624
6625
6626
6627
6628
6629
6630
6631
6632
6633
6634
6635
6636
6637
6638
6639
6640
6641
6642
6643
6644
6645
6646
6647
6648
6649
6650
6651
6652
6653
6654
6655
6656
6657
6658
6659
6660
6661
6662
6663
6664
6665
6666
6667
6668
6669
6670
6671
6672
6673
6674
6675
6676
6677
6678
6679
6680
6681
6682
6683
6684
6685
6686
6687
6688
6689
6690
6691
6692
6693
6694
6695
6696
6697
6698
6699
6700
6701
6702
6703
6704
6705
6706
6707
6708
6709
6710
6711
6712
6713
6714
6715
6716
6717
6718
6719
6720
6721
6722
6723
6724
6725
6726
6727
6728
6729
6730
6731
6732
6733
6734
6735
6736
6737
6738
6739
6740
6741
6742
6743
6744
6745
6746
6747
6748
6749
6750
6751
6752
6753
6754
6755
6756
6757
6758
6759
6760
6761
6762
6763
6764
6765
6766
6767
6768
6769
6770
6771
6772
6773
6774
6775
6776
6777
6778
6779
6780
6781
6782
6783
6784
6785
6786
6787
6788
6789
6790
6791
6792
6793
6794
6795
6796
6797
6798
6799
6800
6801
6802
6803
6804
6805
6806
6807
6808
6809
6810
6811
6812
6813
6814
6815
6816
6817
6818
6819
6820
6821
6822
6823
6824
6825
6826
6827
6828
6829
6830
6831
6832
6833
6834
6835
6836
6837
6838
6839
6840
6841
6842
6843
6844
6845
6846
6847
6848
6849
6850
6851
6852
6853
6854
6855
6856
6857
6858
6859
6860
6861
6862
6863
6864
6865
6866
6867
6868
6869
6870
6871
6872
6873
6874
6875
6876
6877
6878
6879
6880
6881
6882
6883
6884
6885
6886
6887
6888
6889
6890
6891
6892
6893
6894
6895
6896
6897
6898
6899
6900
6901
6902
6903
6904
6905
6906
6907
6908
6909
6910
6911
6912
6913
6914
6915
6916
6917
6918
6919
6920
6921
6922
6923
6924
6925
6926
6927
6928
6929
6930
6931
6932
6933
6934
6935
6936
6937
6938
6939
6940
6941
6942
6943
6944
6945
6946
6947
6948
6949
6950
6951
6952
6953
6954
6955
6956
6957
6958
6959
6960
6961
6962
6963
6964
6965
6966
6967
6968
6969
6970
6971
6972
6973
6974
6975
6976
6977
6978
6979
6980
6981
6982
6983
6984
6985
6986
6987
6988
6989
6990
6991
6992
6993
6994
6995
6996
6997
6998
6999
7000
7001
7002
7003
7004
7005
7006
7007
7008
7009
7010
7011
7012
7013
7014
7015
7016
7017
7018
7019
7020
7021
7022
7023
7024
7025
7026
7027
7028
7029
7030
7031
7032
7033
7034
7035
7036
7037
7038
7039
7040
7041
7042
7043
7044
7045
7046
7047
7048
7049
7050
7051
7052
7053
7054
7055
7056
7057
7058
7059
7060
7061
7062
7063
7064
7065
7066
7067
7068
7069
7070
7071
7072
7073
7074
7075
7076
7077
7078
7079
7080
7081
7082
7083
7084
7085
7086
7087
7088
7089
7090
7091
7092
7093
7094
7095
7096
7097
7098
7099
7100
7101
7102
7103
7104
7105
7106
7107
7108
7109
7110
7111
7112
7113
7114
7115
7116
7117
7118
7119
7120
7121
7122
7123
7124
7125
7126
7127
7128
7129
7130
7131
7132
7133
7134
7135
7136
7137
7138
7139
7140
7141
7142
7143
7144
7145
7146
7147
7148
7149
7150
7151
7152
7153
7154
7155
7156
7157
7158
7159
7160
7161
7162
7163
7164
7165
7166
7167
7168
7169
7170
7171
7172
7173
7174
7175
7176
7177
7178
7179
7180
7181
7182
7183
7184
7185
7186
7187
7188
7189
7190
7191
7192
7193
7194
7195
7196
7197
7198
7199
7200
7201
7202
7203
7204
7205
7206
7207
7208
7209
7210
7211
7212
7213
7214
7215
7216
7217
7218
7219
7220
7221
7222
7223
7224
7225
7226
7227
7228
7229
7230
7231
7232
7233
7234
7235
7236
7237
7238
7239
7240
7241
7242
7243
7244
7245
7246
7247
7248
7249
7250
7251
7252
7253
7254
7255
7256
7257
7258
7259
7260
7261
7262
7263
7264
7265
7266
7267
7268
7269
7270
7271
7272
7273
7274
7275
7276
7277
7278
7279
7280
7281
7282
7283
7284
7285
7286
7287
7288
7289
7290
7291
7292
7293
7294
7295
7296
7297
7298
7299
7300
7301
7302
7303
7304
7305
7306
7307
7308
7309
7310
7311
7312
7313
7314
7315
7316
7317
7318
7319
7320
7321
7322
7323
7324
7325
7326
7327
7328
7329
7330
7331
7332
7333
7334
7335
7336
7337
7338
7339
7340
7341
7342
7343
7344
7345
7346
7347
7348
7349
7350
7351
7352
7353
7354
7355
7356
7357
7358
7359
7360
7361
7362
7363
7364
7365
7366
7367
7368
7369
7370
7371
7372
7373
7374
7375
7376
7377
7378
7379
7380
7381
7382
7383
7384
7385
7386
7387
7388
7389
7390
7391
7392
7393
7394
7395
7396
7397
7398
7399
7400
7401
7402
7403
7404
7405
7406
7407
7408
7409
7410
7411
7412
7413
7414
7415
7416
7417
7418
7419
7420
7421
7422
7423
7424
7425
7426
7427
7428
7429
7430
7431
7432
7433
7434
7435
7436
7437
7438
7439
7440
7441
7442
7443
7444
7445
7446
7447
7448
7449
7450
7451
7452
7453
7454
7455
7456
7457
7458
7459
7460
7461
7462
7463
7464
7465
7466
7467
7468
7469
7470
7471
7472
7473
7474
7475
7476
7477
7478
7479
7480
7481
7482
7483
7484
7485
7486
7487
7488
7489
7490
7491
7492
7493
7494
7495
7496
7497
7498
7499
7500
7501
7502
7503
7504
7505
7506
7507
7508
7509
7510
7511
7512
7513
7514
7515
7516
7517
7518
7519
7520
7521
7522
7523
7524
7525
7526
7527
7528
7529
7530
7531
7532
7533
7534
7535
7536
7537
7538
7539
7540
7541
7542
7543
7544
7545
7546
7547
7548
7549
7550
7551
7552
7553
7554
7555
7556
7557
7558
7559
7560
7561
7562
7563
7564
7565
7566
7567
7568
7569
7570
7571
7572
7573
7574
7575
7576
7577
7578
7579
7580
7581
7582
7583
7584
7585
7586
7587
7588
7589
7590
7591
7592
7593
7594
7595
7596
7597
7598
7599
7600
7601
7602
7603
7604
7605
7606
7607
7608
7609
7610
7611
7612
7613
7614
7615
7616
7617
7618
7619
7620
7621
7622
7623
7624
7625
7626
7627
7628
7629
7630
7631
7632
7633
7634
7635
7636
7637
7638
7639
7640
7641
7642
7643
7644
7645
7646
7647
7648
7649
7650
7651
7652
7653
7654
7655
7656
7657
7658
7659
7660
7661
7662
7663
7664
7665
7666
7667
7668
7669
7670
7671
7672
7673
7674
7675
7676
7677
7678
7679
7680
7681
7682
7683
7684
7685
7686
7687
7688
7689
7690
7691
7692
7693
7694
7695
7696
7697
7698
7699
7700
7701
7702
7703
7704
7705
7706
7707
7708
7709
7710
7711
7712
7713
7714
7715
7716
7717
7718
7719
7720
7721
7722
7723
7724
7725
7726
7727
7728
7729
7730
7731
7732
7733
7734
7735
7736
7737
7738
7739
7740
7741
7742
7743
7744
7745
7746
7747
7748
7749
7750
7751
7752
7753
7754
7755
7756
7757
7758
7759
7760
7761
7762
7763
7764
7765
7766
7767
7768
7769
7770
7771
7772
7773
7774
7775
7776
7777
7778
7779
7780
7781
7782
7783
7784
7785
7786
7787
7788
7789
7790
7791
7792
7793
7794
7795
7796
7797
7798
7799
7800
7801
7802
7803
7804
7805
7806
7807
7808
7809
7810
7811
7812
7813
7814
7815
7816
7817
7818
7819
7820
7821
7822
7823
7824
7825
7826
7827
7828
7829
7830
7831
7832
7833
7834
7835
7836
7837
7838
7839
7840
7841
7842
7843
7844
7845
7846
7847
7848
7849
7850
7851
7852
7853
7854
7855
7856
7857
7858
7859
7860
7861
7862
7863
7864
7865
7866
7867
7868
7869
7870
7871
7872
7873
7874
7875
7876
7877
7878
7879
7880
7881
7882
7883
7884
7885
7886
7887
7888
7889
7890
7891
7892
7893
7894
7895
7896
7897
7898
7899
7900
7901
7902
7903
7904
7905
7906
7907
7908
7909
7910
7911
7912
7913
7914
7915
7916
7917
7918
7919
7920
7921
7922
7923
7924
7925
7926
7927
7928
7929
7930
7931
7932
7933
7934
7935
7936
7937
7938
7939
7940
7941
7942
7943
7944
7945
7946
7947
7948
7949
7950
7951
7952
7953
7954
7955
7956
7957
7958
7959
7960
7961
7962
7963
7964
7965
7966
7967
7968
7969
7970
7971
7972
7973
7974
7975
7976
7977
7978
7979
7980
7981
7982
7983
7984
7985
7986
7987
7988
7989
7990
7991
7992
7993
7994
7995
7996
7997
7998
7999
8000
8001
8002
8003
8004
8005
8006
8007
8008
8009
8010
8011
8012
8013
8014
8015
8016
8017
8018
8019
8020
8021
8022
8023
8024
8025
8026
8027
8028
8029
8030
8031
8032
8033
8034
8035
8036
8037
8038
8039
8040
8041
8042
8043
8044
8045
8046
8047
8048
8049
8050
8051
8052
8053
8054
8055
8056
8057
8058
8059
8060
8061
8062
8063
8064
8065
8066
8067
8068
8069
8070
8071
8072
8073
8074
8075
8076
8077
8078
8079
8080
8081
8082
8083
8084
8085
8086
8087
8088
8089
8090
8091
8092
8093
8094
8095
8096
8097
8098
8099
8100
8101
8102
8103
8104
8105
8106
8107
8108
8109
8110
8111
8112
8113
8114
8115
8116
8117
8118
8119
8120
8121
8122
8123
8124
8125
8126
8127
8128
8129
8130
8131
8132
8133
8134
8135
8136
8137
8138
8139
Results per page:
10
25
50
100
200