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
2025
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
----- 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
[reactos] 01/01: [SHIMGVW] Fixes and enhancements (#7705)
by Whindmar Saksit
https://git.reactos.org/?p=reactos.git;a=commitdiff;h=dd34ad7037edbc90117db…
commit dd34ad7037edbc90117dbf24dcdca6135ac9c1b6 Author: Whindmar Saksit <whindsaks(a)proton.me> AuthorDate: Sat Feb 8 16:22:20 2025 +0100 Commit: GitHub <noreply(a)github.com> CommitDate: Sat Feb 8 16:22:20 2025 +0100 [SHIMGVW] Fixes and enhancements (#7705) Fixes: - Reduce flicker when resizing main window - Fixed slideshow starting with 1x1 pixel image zoom - Don't reset zoom levels > 100% when resizing main window - Always retain an active window on toggle slideshow (show/hide actions order) - Enable/disable real-size button as required - Correctly handle accelerators in main window after slideshow has been closed - Use same zoom shortcuts as NT6 New features (unique to ROS): - Fullscreen mode (slideshow mode but without timer) - Alt+Enter or double-click to toggle fullscreen mode - Shift +/- to change fullscreen slideshow next picture timer CORE-19358 --- dll/win32/shimgvw/resource.h | 5 ++ dll/win32/shimgvw/shimgvw.c | 132 +++++++++++++++++++++++++++++++++++++------ dll/win32/shimgvw/shimgvw.rc | 11 +++- 3 files changed, 131 insertions(+), 17 deletions(-) diff --git a/dll/win32/shimgvw/resource.h b/dll/win32/shimgvw/resource.h index ec2fbf116bd..17fce85b7fc 100644 --- a/dll/win32/shimgvw/resource.h +++ b/dll/win32/shimgvw/resource.h @@ -30,6 +30,11 @@ /* ToolBar buttons */ #define IDC_TOOL_BASE 500 +#define IDC_ACCEL_BASE (IDC_TOOL_BASE + 100) /* Accelerator commands not on the toolbar */ + +#define IDC_TOGGLEFULLSCREEN (IDC_ACCEL_BASE + 0) +#define IDC_INCTIMER (IDC_ACCEL_BASE + 1) +#define IDC_DECTIMER (IDC_ACCEL_BASE + 2) #define IDC_PREV_PIC (IDC_TOOL_BASE + 0) #define IDC_NEXT_PIC (IDC_TOOL_BASE + 1) diff --git a/dll/win32/shimgvw/shimgvw.c b/dll/win32/shimgvw/shimgvw.c index 693b499761f..c0ce4de2d39 100644 --- a/dll/win32/shimgvw/shimgvw.c +++ b/dll/win32/shimgvw/shimgvw.c @@ -20,6 +20,8 @@ /* Slide show timer */ #define SLIDESHOW_TIMER_ID 0xFACE #define SLIDESHOW_TIMER_INTERVAL 5000 /* 5 seconds */ +#define HIDECURSOR_TIMER_ID 0xBABE +#define HIDECURSOR_TIMER_TIMEOUT 3000 HINSTANCE g_hInstance = NULL; HWND g_hMainWnd = NULL; @@ -109,11 +111,15 @@ typedef struct tagPREVIEW_DATA INT m_xScrollOffset; INT m_yScrollOffset; UINT m_nMouseDownMsg; + UINT m_nTimerInterval; + BOOL m_bHideCursor; POINT m_ptOrigin; IStream *m_pMemStream; WCHAR m_szFile[MAX_PATH]; } PREVIEW_DATA, *PPREVIEW_DATA; +static VOID Preview_ToggleSlideShowEx(PPREVIEW_DATA pData, BOOL StartTimer); + static inline PPREVIEW_DATA Preview_GetData(HWND hwnd) { @@ -131,14 +137,34 @@ Preview_RestartTimer(HWND hwnd) { if (!Preview_IsMainWnd(hwnd)) { + PPREVIEW_DATA pData = Preview_GetData(hwnd); KillTimer(hwnd, SLIDESHOW_TIMER_ID); - SetTimer(hwnd, SLIDESHOW_TIMER_ID, SLIDESHOW_TIMER_INTERVAL, NULL); + if (pData->m_nTimerInterval) + SetTimer(hwnd, SLIDESHOW_TIMER_ID, pData->m_nTimerInterval, NULL); } } static VOID -ZoomWnd_UpdateScroll(PPREVIEW_DATA pData, HWND hwnd, BOOL bResetPos) +Preview_ChangeSlideShowTimer(PPREVIEW_DATA pData, BOOL bSlower) { + BOOL IsFullscreen = !Preview_IsMainWnd(pData->m_hwnd); + enum { mintime = 1000, maxtime = SLIDESHOW_TIMER_INTERVAL * 3, step = 1000 }; + UINT interval = pData->m_nTimerInterval ? pData->m_nTimerInterval : SLIDESHOW_TIMER_INTERVAL; + if (IsFullscreen) + { + interval = bSlower ? min(interval + step, maxtime) : max(interval - step, mintime); + if (pData->m_nTimerInterval != interval) + { + pData->m_nTimerInterval = interval; + Preview_RestartTimer(pData->m_hwnd); + } + } +} + +static VOID +ZoomWnd_UpdateScroll(PPREVIEW_DATA pData, BOOL bResetPos) +{ + HWND hwnd = pData->m_hwndZoom; RECT rcClient; UINT ImageWidth, ImageHeight, ZoomedWidth, ZoomedHeight; SCROLLINFO si; @@ -221,10 +247,10 @@ Preview_UpdateZoom(PPREVIEW_DATA pData, UINT NewZoom, BOOL bEnableBestFit, BOOL bEnableZoomOut = (NewZoom > MIN_ZOOM); /* Update toolbar buttons */ - PostMessageW(hToolBar, TB_ENABLEBUTTON, IDC_ZOOM_OUT, bEnableZoomOut); - PostMessageW(hToolBar, TB_ENABLEBUTTON, IDC_ZOOM_IN, bEnableZoomIn); - PostMessageW(hToolBar, TB_ENABLEBUTTON, IDC_BEST_FIT, bEnableBestFit); - PostMessageW(hToolBar, TB_ENABLEBUTTON, IDC_REAL_SIZE, bEnableRealSize); + SendMessageW(hToolBar, TB_ENABLEBUTTON, IDC_BEST_FIT, bEnableBestFit); + SendMessageW(hToolBar, TB_ENABLEBUTTON, IDC_REAL_SIZE, NewZoom != 100); + SendMessageW(hToolBar, TB_ENABLEBUTTON, IDC_ZOOM_IN, bEnableZoomIn); + SendMessageW(hToolBar, TB_ENABLEBUTTON, IDC_ZOOM_OUT, bEnableZoomOut); /* Redraw the display window */ InvalidateRect(pData->m_hwndZoom, NULL, TRUE); @@ -233,7 +259,7 @@ Preview_UpdateZoom(PPREVIEW_DATA pData, UINT NewZoom, BOOL bEnableBestFit, BOOL Preview_RestartTimer(pData->m_hwnd); /* Update scroll info */ - ZoomWnd_UpdateScroll(pData, pData->m_hwndZoom, FALSE); + ZoomWnd_UpdateScroll(pData, FALSE); } static VOID @@ -592,7 +618,7 @@ Preview_UpdateImage(PPREVIEW_DATA pData) if (!Preview_IsMainWnd(pData->m_hwnd)) Preview_ResetZoom(pData); - ZoomWnd_UpdateScroll(pData, pData->m_hwndZoom, TRUE); + ZoomWnd_UpdateScroll(pData, TRUE); } static SHIMGVW_FILENODE* @@ -985,11 +1011,24 @@ Preview_EndSlideShow(HWND hwnd) return; KillTimer(hwnd, SLIDESHOW_TIMER_ID); + ShowWindow(g_hMainWnd, SW_SHOW); ShowWindow(hwnd, SW_HIDE); - ShowWindow(g_hMainWnd, SW_SHOWNORMAL); Preview_ResetZoom(Preview_GetData(g_hMainWnd)); } +static VOID +GenerateSetCursor(HWND hwnd, UINT uMsg) +{ + SendMessage(hwnd, WM_SETCURSOR, (WPARAM)hwnd, MAKELONG(HTCLIENT, uMsg)); +} + +static VOID +ZoomWnd_StopHideCursor(PPREVIEW_DATA pData) +{ + pData->m_bHideCursor = FALSE; + KillTimer(pData->m_hwndZoom, HIDECURSOR_TIMER_ID); +} + static VOID ZoomWnd_OnButtonDown(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam) { @@ -1002,6 +1041,7 @@ ZoomWnd_OnButtonDown(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam) return; } + ZoomWnd_StopHideCursor(pData); pData->m_nMouseDownMsg = uMsg; pData->m_ptOrigin.x = GET_X_LPARAM(lParam); pData->m_ptOrigin.y = GET_Y_LPARAM(lParam); @@ -1015,6 +1055,13 @@ ZoomWnd_OnMouseMove(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam) PPREVIEW_DATA pData = Preview_GetData(hwnd); POINT pt = { GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam) }; + if (!Preview_IsMainWnd(pData->m_hwnd)) + { + ZoomWnd_StopHideCursor(pData); + if (!pData->m_nMouseDownMsg) + SetTimer(hwnd, HIDECURSOR_TIMER_ID, HIDECURSOR_TIMER_TIMEOUT, NULL); + } + if (pData->m_nMouseDownMsg == WM_MBUTTONDOWN) { INT x = GetScrollPos(hwnd, SB_HORZ) - (pt.x - pData->m_ptOrigin.x); @@ -1034,6 +1081,12 @@ ZoomWnd_OnSetCursor(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam) SetCursor(LoadCursorW(g_hInstance, MAKEINTRESOURCEW(IDC_HANDDRAG))); return TRUE; } + + if (pData->m_bHideCursor) + { + SetCursor(NULL); /* Hide cursor in fullscreen */ + return TRUE; + } return FALSE; } @@ -1041,8 +1094,15 @@ static VOID ZoomWnd_OnButtonUp(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam) { PPREVIEW_DATA pData = Preview_GetData(hwnd); + BOOL wasdrag = pData->m_nMouseDownMsg == WM_MBUTTONDOWN; + pData->m_nMouseDownMsg = 0; + if (wasdrag) + GenerateSetCursor(hwnd, uMsg); /* Reset to default cursor */ ReleaseCapture(); + + if (!Preview_IsMainWnd(pData->m_hwnd)) + SetTimer(hwnd, HIDECURSOR_TIMER_ID, HIDECURSOR_TIMER_TIMEOUT, NULL); } static VOID @@ -1167,6 +1227,12 @@ ZoomWndProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam) ZoomWnd_OnButtonUp(hwnd, uMsg, wParam, lParam); break; } + case WM_LBUTTONDBLCLK: + { + if (Preview_IsMainWnd(pData->m_hwnd)) + Preview_ToggleSlideShowEx(pData, FALSE); + break; + } case WM_PAINT: { ZoomWnd_OnPaint(pData, hwnd); @@ -1184,8 +1250,19 @@ ZoomWndProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam) break; case WM_TIMER: { + if (wParam == HIDECURSOR_TIMER_ID) + { + ZoomWnd_StopHideCursor(pData); + if (IsWindowVisible(hwnd)) + { + pData->m_bHideCursor = TRUE; + GenerateSetCursor(hwnd, uMsg); + } + } if (Anime_OnTimer(&pData->m_Anime, wParam)) + { InvalidateRect(hwnd, NULL, FALSE); + } break; } default: @@ -1298,7 +1375,9 @@ Preview_OnSize(HWND hwnd) MoveWindow(pData->m_hwndZoom, 0, 0, cx, cy - (rc.bottom - rc.top), TRUE); - if (!IsIconic(hwnd)) /* Is it not minimized? */ + if (pData->m_nZoomPercents > 100) + ZoomWnd_UpdateScroll(pData, FALSE); + else if (!IsIconic(hwnd)) /* Is it not minimized? */ Preview_ResetZoom(pData); Preview_OnMoveSize(hwnd); @@ -1372,7 +1451,7 @@ Preview_Edit(HWND hwnd) } static VOID -Preview_ToggleSlideShow(PPREVIEW_DATA pData) +Preview_ToggleSlideShowEx(PPREVIEW_DATA pData, BOOL StartTimer) { if (!IsWindow(g_hwndFullscreen)) { @@ -1385,18 +1464,28 @@ Preview_ToggleSlideShow(PPREVIEW_DATA pData) if (IsWindowVisible(g_hwndFullscreen)) { - ShowWindow(g_hwndFullscreen, SW_HIDE); - ShowWindow(g_hMainWnd, SW_SHOWNORMAL); KillTimer(g_hwndFullscreen, SLIDESHOW_TIMER_ID); + ShowWindow(g_hMainWnd, SW_SHOW); + ShowWindow(g_hwndFullscreen, SW_HIDE); } else { - ShowWindow(g_hMainWnd, SW_HIDE); + PPREVIEW_DATA pSlideData = Preview_GetData(g_hwndFullscreen); + pSlideData->m_nTimerInterval = StartTimer ? SLIDESHOW_TIMER_INTERVAL : 0; ShowWindow(g_hwndFullscreen, SW_SHOWMAXIMIZED); + ShowWindow(g_hMainWnd, SW_HIDE); + Preview_ResetZoom(pSlideData); Preview_RestartTimer(g_hwndFullscreen); + PostMessage(pSlideData->m_hwndZoom, WM_MOUSEMOVE, 0, 0); /* Start hide cursor */ } } +static inline VOID +Preview_ToggleSlideShow(PPREVIEW_DATA pData) +{ + Preview_ToggleSlideShowEx(pData, TRUE); +} + static VOID Preview_GoNextPic(PPREVIEW_DATA pData, BOOL bNext) { @@ -1452,6 +1541,15 @@ Preview_OnCommand(HWND hwnd, UINT nCommandID) Preview_EndSlideShow(hwnd); break; + case IDC_TOGGLEFULLSCREEN: + Preview_ToggleSlideShowEx(pData, FALSE); + break; + + case IDC_INCTIMER: + case IDC_DECTIMER: + Preview_ChangeSlideShowTimer(pData, nCommandID == IDC_INCTIMER); + break; + default: break; } @@ -1541,6 +1639,7 @@ Preview_OnDestroy(HWND hwnd) PPREVIEW_DATA pData = Preview_GetData(hwnd); KillTimer(hwnd, SLIDESHOW_TIMER_ID); + KillTimer(hwnd, HIDECURSOR_TIMER_ID); pFreeFileList(g_pCurrentFile); g_pCurrentFile = NULL; @@ -1683,7 +1782,7 @@ ImageView_Main(HWND hwnd, LPCWSTR szFileName) WndClass.style = CS_HREDRAW | CS_VREDRAW; WndClass.hIcon = LoadIconW(g_hInstance, MAKEINTRESOURCEW(IDI_APP_ICON)); WndClass.hCursor = LoadCursorW(NULL, (LPCWSTR)IDC_ARROW); - WndClass.hbrBackground = (HBRUSH)UlongToHandle(COLOR_3DFACE + 1); + WndClass.hbrBackground = GetStockBrush(NULL_BRUSH); /* less flicker */ if (!RegisterClassW(&WndClass)) return -1; WndClass.lpszClassName = WC_ZOOM; @@ -1714,7 +1813,8 @@ ImageView_Main(HWND hwnd, LPCWSTR szFileName) /* Message Loop */ while (GetMessageW(&msg, NULL, 0, 0) > 0) { - if (g_hwndFullscreen && TranslateAcceleratorW(g_hwndFullscreen, hAccel, &msg)) + const HWND hwndFull = g_hwndFullscreen; + if (IsWindowVisible(hwndFull) && TranslateAcceleratorW(hwndFull, hAccel, &msg)) continue; if (TranslateAcceleratorW(hMainWnd, hAccel, &msg)) continue; diff --git a/dll/win32/shimgvw/shimgvw.rc b/dll/win32/shimgvw/shimgvw.rc index bb46198ded1..bec550cb4c3 100644 --- a/dll/win32/shimgvw/shimgvw.rc +++ b/dll/win32/shimgvw/shimgvw.rc @@ -43,10 +43,19 @@ BEGIN "B", IDC_BEST_FIT, VIRTKEY, CONTROL "A", IDC_REAL_SIZE, VIRTKEY, CONTROL VK_F11, IDC_SLIDE_SHOW, VIRTKEY + VK_RETURN, IDC_TOGGLEFULLSCREEN, VIRTKEY, ALT + VK_ADD, IDC_INCTIMER, VIRTKEY, SHIFT + VK_OEM_PLUS, IDC_INCTIMER, VIRTKEY, SHIFT + VK_OEM_MINUS,IDC_DECTIMER, VIRTKEY, SHIFT + VK_SUBTRACT, IDC_DECTIMER, VIRTKEY, SHIFT VK_ADD, IDC_ZOOM_IN, VIRTKEY + VK_ADD, IDC_ZOOM_IN, VIRTKEY, CONTROL + VK_OEM_PLUS, IDC_ZOOM_IN, VIRTKEY + VK_OEM_PLUS, IDC_ZOOM_IN, VIRTKEY, CONTROL VK_SUBTRACT, IDC_ZOOM_OUT, VIRTKEY - VK_OEM_PLUS, IDC_ZOOM_IN, VIRTKEY, SHIFT + VK_SUBTRACT, IDC_ZOOM_OUT, VIRTKEY, CONTROL VK_OEM_MINUS,IDC_ZOOM_OUT, VIRTKEY + VK_OEM_MINUS,IDC_ZOOM_OUT, VIRTKEY, CONTROL "K", IDC_ROT_CLOCKW, VIRTKEY, CONTROL "L", IDC_ROT_COUNCW, VIRTKEY, CONTROL VK_DELETE, IDC_DELETE, VIRTKEY
4Â months, 3Â weeks
1
0
0
0
[reactos] 01/01: [PROPSYS] Sync to wine-10.0 (#7677)
by Mikhail Tyukin
https://git.reactos.org/?p=reactos.git;a=commitdiff;h=2d1144a5cd63ae1c4a0d2…
commit 2d1144a5cd63ae1c4a0d2c5b52f85a3e38115637 Author: Mikhail Tyukin <mishakeys20(a)gmail.com> AuthorDate: Fri Feb 7 16:00:48 2025 -0500 Commit: GitHub <noreply(a)github.com> CommitDate: Fri Feb 7 22:00:48 2025 +0100 [PROPSYS] Sync to wine-10.0 (#7677) [WINESYNC] propsys/tests: Merge test files. wine commit id d189b55d2ffb038474cb6656dc8743eb34c35a3d by Nikolay Sivov <nsivov(a)codeweavers.com> [WINESYNC] propsys: Add a semi-stub for PSCreatePropertyStoreFromObject(). Wine-Bug:
https://bugs.winehq.org/show_bug.cgi?id=47958
wine commit id acb2e4fc7a4242c74ac91657edb97bf1e402656a by Nikolay Sivov <nsivov(a)codeweavers.com> [WINESYNC] propsys: Allow only ASCII digits in PSPropertyKeyFromString. wine commit id 6e8c2d836e637e1fbd83c231cfd846ecb9333964 by Jacek Caban <jacek(a)codeweavers.com> [WINESYNC] propsys/tests: Get rid of strcmp_wa(). wine commit id 2340212ee9c48c731c85bbad8c81ed833458bf15 by Michael Stefaniuc <mstefani(a)winehq.org> [WINESYNC] propsys: Use wide-char string literals. wine commit id b72440fa2e1016681cbfcebcdc4792b6ced3eb53 by Michael Stefaniuc <mstefani(a)winehq.org> reduce wine diff and add stuff from previous commit [WINESYNC] propsys: Use --prefer_native instead of DLL_WINE_PREATTACH. wine commit id f99113192ffac37506a905827415d3d21d0ebbf8 by Alexandre Julliard <julliard(a)winehq.org> [WINESYNC] propsys: Use nameless unions. wine commit id 1d8e5079f0e53a767a783e5107f57f04c1897951 by Jacek Caban <jacek(a)codeweavers.com> [WINESYNC] propsys/tests: Use nameless unions. wine commit id 497de3cc19f971808ca4105f52038e61dc818db1 by Jacek Caban <jacek(a)codeweavers.com> [WINESYNC] winecrt0: Add a default implementation for DllCanUnloadNow(). wine commit id bd6b53740c28c6974300e15f965c12feb0252085 by Alexandre Julliard <julliard(a)winehq.org> [WINESYNC] winecrt0: Add a default implementation DllRegisterServer()/DllUnregisterServer(). wine commit id 5d82baf9747b7b133cad3be77c0cc9e24cc09582 by Alexandre Julliard <julliard(a)winehq.org> [WINESYNC] propsys: Add support for VT_VECTOR|VT_UI1 type in PropVariantCompareEx(). wine commit id e91b05bb5be6fd70a767bea9991e818a49cc5547 by Nikolay Sivov <nsivov(a)codeweavers.com> [WINESYNC] propsys: Fix VT_UI4 comparison, use ulVal instead of uiVal. wine commit id 58eeb1a86433db1104d3a9ccf9ad7435ec81443a by Rémi Bernon <rbernon(a)codeweavers.com> [WINESYNC] propsys/tests: Add a VT_UI4 test for PropVariantCompareEx(). A test for 58eeb1a86433db1104d3a9ccf9ad7435ec81443a. wine commit id 10359e17ce64f39461a7b7b54f73857e6458d1fb by Nikolay Sivov <nsivov(a)codeweavers.com> [WINESYNC] propsys/tests: Avoid "misleading indentation" warnings. wine commit id 7cd6681b3be35cf6c02f056cb5131c90c0674c16 by Fabian Maurer <dark.shadow4(a)web.de> [WINESYNC] propsys: Enable compilation with long types. wine commit id a9c797e4538a37716e62bb81c3fed3de39561b41 by Eric Pouech <eric.pouech(a)gmail.com> [WINESYNC] propsys/tests: Enable compilation with long types. wine commit id c1c393595d43bd95390d3ddf86dcbc46bc4f52ba by Eric Pouech <eric.pouech(a)gmail.com> [WINESYNC] propsys: Implement InitVariantFromFileTime. wine commit id f2b8ccb7b0b22b7b5d661d908f8f8ee02f22647d by Daniel Lehman <dlehman(a)esri.com> [WINESYNC] propsys/tests: Add some InitVariantFromFileTime tests. wine commit id 083dea7fce4372840ac18176496a7d05dadd5ad8 by Daniel Lehman <dlehman(a)esri.com> [WINESYNC] propsys: Implement VariantToStringWithDefault. wine commit id bf0f1fdcf80657a42116b79a0953181191cf9221 by Mohamad Al-Jaf <mohamadaljaf(a)gmail.com> [WINESYNC] propsys/tests: Add VariantToStringWithDefault tests. wine commit id 89aba13dc381dbbda62d1019e1af2af5a589b0cf by Mohamad Al-Jaf <mohamadaljaf(a)gmail.com> [WINESYNC] include: Add Stg functions declaration in propvarutil.h. wine commit id 0d294ad26544913414277daa164004d731ae6e33 by Biswapriyo Nath <nathbappai(a)gmail.com> [WINESYNC] propsys: Add InitPropVariantFromStringVector(). wine commit id 3a1146d8e63d7ceff38441fee08f7f7080527020 by Nikolay Sivov <nsivov(a)codeweavers.com> [WINESYNC] Remove unused NONAMELESS defines. wine commit id 20afe438320f77d103a96d1d8cd562d0899ebac7 by Alexandre Julliard <julliard(a)winehq.org> [WINESYNC] propsys: Partially implement VariantToString(). Wine-Bug:
https://bugs.winehq.org/show_bug.cgi?id=55708
wine commit id f7ef02bd8f74ea052d61e48cd84b226d8a5867a8 by Nikolay Sivov <nsivov(a)codeweavers.com> [WINESYNC] propsys: Handle VT_I4 type in VariantToString(). Wine-Bug:
https://bugs.winehq.org/show_bug.cgi?id=55708
wine commit id 001e0543bfd5aea060053af0c76233bb90fbb43b by Nikolay Sivov <nsivov(a)codeweavers.com> [WINESYNC] propsys: Implement PropVariantToUInt32WithDefault. Wine-Bug:
https://bugs.winehq.org/show_bug.cgi?id=55713
wine commit id d177709b10ce07ddd234b0e8e00764ae4b1d8488 by Fabian Maurer <dark.shadow4(a)web.de> [WINESYNC] include: Use proper dllimports for propsys functions. wine commit id f0b2e0d00c86fb04d47467f39e49c587250ffec5 by Alexandre Julliard <julliard(a)winehq.org> [WINESYNC] propsys: Remove DECLSPEC_HIDDEN usage. wine commit id e9ff53e098ef3871d692c7b907151cfbb2f0673f by Alistair Leslie-Hughes <leslie_alistair(a)hotmail.com> Update propsys_private.h [WINESYNC] propsys: Force debug info in critical sections. wine commit id 67bea281cc851eda6a08430c70f6c9e848d3fbe1 by Paul Gofman <pgofman(a)codeweavers.com> [WINESYNC] include: Fix typos in IID_IPropertyEnumType2 and CLSID_PropertySystem. wine commit id 66e6b61705a66459ed3a9e0cf9457d8b180e4564 by Alfred Agrell <floating(a)muncher.se> [WINESYNC] propsys: Add stubs for variant conversion functions. wine commit id c21f04f7adaa4a8d0ca2d2659bf9a6facdc168c3 by Ziqing Hui <zhui(a)codeweavers.com> [WINESYNC] propsys/tests: Add tests for VariantToPropVariant. wine commit id 8877889f2a8e36d22dcad061e6da84476efb3750 by Ziqing Hui <zhui(a)codeweavers.com> [WINESYNC] propsys: Initially implement VariantToPropVariant. wine commit id 6985637ed59e81e7d1716095a343cc5681082306 by Ziqing Hui <zhui(a)codeweavers.com> [WINESYNC] propsys/tests: Add tests for PropVariantToVariant. wine commit id 3277de5572b7f6c41ebeeb89f781e378a6a2c2d3 by Ziqing Hui <zhui(a)codeweavers.com> [WINESYNC] propsys/tests: Test converting clsid to string. wine commit id 7a4f9f83c51883f41ae1363e27700452472ec18f by Ziqing Hui <zhui(a)codeweavers.com> [WINESYNC] propsys: Support converting clsid to string for PropVariant. wine commit id 67b097ff46c65d525de6a7f560f019de6828320c by Ziqing Hui <zhui(a)codeweavers.com> [WINESYNC] propsys: Initially implement PropVariantToVariant. wine commit id 808b398549350fffc9fc023d637ef8de9e4bba37 by Ziqing Hui <zhui(a)codeweavers.com> [WINESYNC] propsys: Add PropVariantToBSTR stub. wine commit id 86558a4b83ebf9a0c6e76888a3d0f3fe3e36bf57 by Ziqing Hui <zhui(a)codeweavers.com> [WINESYNC] propsys/tests: Test PropVariantToBSTR. wine commit id b4ac03f1f622120906a8b6e691caa05f6539c2dd by Ziqing Hui <zhui(a)codeweavers.com> [WINESYNC] propsys/tests: Test truncating for PropVariantToString. wine commit id df16802582a56f8076ebbcf9cb6178f65bb8b9b6 by Ziqing Hui <zhui(a)codeweavers.com> [WINESYNC] propsys: Implement PropVariantToBSTR. wine commit id 66220be403ce5c3634c13da3546f0c19f04059cc by Ziqing Hui <zhui(a)codeweavers.com> [WINESYNC] propsys: Use debugstr_variant for the trace in VariantToPropVariant. wine commit id 3517aded4090229dbb11e413bde8349d1eca0be3 by Ziqing Hui <zhui(a)codeweavers.com> [WINESYNC] propsys: Support converting to BSTR for PropVariantToVariant. wine commit id c33fdc27650045a754a05a8f25e250e6e72c8072 by Ziqing Hui <zhui(a)codeweavers.com> [WINESYNC] propsys/tests: Fix a test that fails on some Windows versions. wine commit id c09f828f43101cf2dfe11d7e13f1fc6ef4b19853 by Alexandre Julliard <julliard(a)winehq.org> [WINESYNC]: propsys is now in sync with wine-staging wine-10.0 Co-authored-by: winesync <ros-dev(a)reactos.org> [PROPSYS] Remove duplicate uuid [PROPSYS] Fix headers/idl file --- dll/win32/propsys/CMakeLists.txt | 5 +- dll/win32/propsys/precomp.h | 3 +- dll/win32/propsys/propstore.c | 26 +- dll/win32/propsys/propsys.spec | 18 +- dll/win32/propsys/propsys_main.c | 60 +- dll/win32/propsys/propsys_private.h | 2 +- dll/win32/propsys/propvar.c | 502 +++++-- media/doc/WINESYNC.txt | 2 +- modules/rostests/winetests/propsys/CMakeLists.txt | 3 +- modules/rostests/winetests/propsys/propstore.c | 374 ----- modules/rostests/winetests/propsys/propsys.c | 1594 +++++++++++++++++---- modules/rostests/winetests/propsys/testlist.c | 2 - sdk/include/psdk/oaidl.idl | 11 + sdk/include/psdk/propsys.idl | 29 +- sdk/include/psdk/propvarutil.h | 144 +- sdk/tools/winesync/propsys.cfg | 9 + 16 files changed, 1939 insertions(+), 845 deletions(-) diff --git a/dll/win32/propsys/CMakeLists.txt b/dll/win32/propsys/CMakeLists.txt index 8d788ae20d4..41412950df7 100644 --- a/dll/win32/propsys/CMakeLists.txt +++ b/dll/win32/propsys/CMakeLists.txt @@ -1,6 +1,7 @@ include_directories(${REACTOS_SOURCE_DIR}/sdk/include/reactos/wine) -add_definitions(-D__WINESRC__) +remove_definitions(-D_CRT_NON_CONFORMING_SWPRINTFS -D__ROS_LONG64__) +add_definitions(-D__WINESRC__ -D_PROPSYS_) spec2def(propsys.dll propsys.spec ADD_IMPORTLIB) list(APPEND SOURCE @@ -16,7 +17,7 @@ add_library(propsys MODULE ${CMAKE_CURRENT_BINARY_DIR}/propsys.def) set_module_type(propsys win32dll) -target_link_libraries(propsys uuid wine) +target_link_libraries(propsys uuid wine wine_dll_register) add_importlibs(propsys ole32 oleaut32 msvcrt kernel32 ntdll) add_pch(propsys precomp.h SOURCE) add_cd_file(TARGET propsys DESTINATION reactos/system32 FOR all) diff --git a/dll/win32/propsys/precomp.h b/dll/win32/propsys/precomp.h index 1f432757e3a..a233f258ae0 100644 --- a/dll/win32/propsys/precomp.h +++ b/dll/win32/propsys/precomp.h @@ -9,13 +9,14 @@ #define COM_NO_WINDOWS_H #define COBJMACROS -#define NONAMELESSUNION #include <windef.h> #include <winbase.h> #include <winnls.h> #include <objbase.h> #include <propsys.h> +#include <oleauto.h> +#include <oaidl.h> #include <wine/debug.h> diff --git a/dll/win32/propsys/propstore.c b/dll/win32/propsys/propstore.c index 6212f293123..adef3b38916 100644 --- a/dll/win32/propsys/propstore.c +++ b/dll/win32/propsys/propstore.c @@ -92,7 +92,7 @@ static ULONG WINAPI PropertyStore_AddRef(IPropertyStoreCache *iface) PropertyStore *This = impl_from_IPropertyStoreCache(iface); ULONG ref = InterlockedIncrement(&This->ref); - TRACE("(%p) refcount=%u\n", iface, ref); + TRACE("(%p) refcount=%lu\n", iface, ref); return ref; } @@ -113,7 +113,7 @@ static ULONG WINAPI PropertyStore_Release(IPropertyStoreCache *iface) PropertyStore *This = impl_from_IPropertyStoreCache(iface); ULONG ref = InterlockedDecrement(&This->ref); - TRACE("(%p) refcount=%u\n", iface, ref); + TRACE("(%p) refcount=%lu\n", iface, ref); if (ref == 0) { @@ -159,7 +159,7 @@ static HRESULT WINAPI PropertyStore_GetAt(IPropertyStoreCache *iface, propstore_value *value; HRESULT hr; - TRACE("%p,%d,%p\n", iface, iProp, pkey); + TRACE("%p,%ld,%p\n", iface, iProp, pkey); if (!pkey) return E_POINTER; @@ -464,7 +464,11 @@ HRESULT PropertyStore_CreateInstance(IUnknown *pUnkOuter, REFIID iid, void** ppv This->IPropertyStoreCache_iface.lpVtbl = &PropertyStore_Vtbl; This->ref = 1; +#ifdef __REACTOS__ InitializeCriticalSection(&This->lock); +#else + InitializeCriticalSectionEx(&This->lock, 0, RTL_CRITICAL_SECTION_FLAG_FORCE_DEBUG_INFO); +#endif This->lock.DebugInfo->Spare[0] = (DWORD_PTR)(__FILE__ ": PropertyStore.lock"); list_init(&This->formats); @@ -473,3 +477,19 @@ HRESULT PropertyStore_CreateInstance(IUnknown *pUnkOuter, REFIID iid, void** ppv return ret; } + +HRESULT WINAPI PSCreatePropertyStoreFromObject(IUnknown *obj, DWORD access, REFIID riid, void **ret) +{ + HRESULT hr; + + TRACE("(%p, %ld, %s, %p)\n", obj, access, debugstr_guid(riid), ret); + + if (!obj || !ret) + return E_POINTER; + + if (IsEqualIID(riid, &IID_IPropertyStore) && SUCCEEDED(hr = IUnknown_QueryInterface(obj, riid, ret))) + return hr; + + FIXME("Unimplemented for %s.\n", debugstr_guid(riid)); + return E_NOTIMPL; +} diff --git a/dll/win32/propsys/propsys.spec b/dll/win32/propsys/propsys.spec index 19e16aedc1e..5771848917b 100644 --- a/dll/win32/propsys/propsys.spec +++ b/dll/win32/propsys/propsys.spec @@ -42,7 +42,7 @@ @ stub InitPropVariantFromResource @ stub InitPropVariantFromStrRet @ stub InitPropVariantFromStringAsVector -@ stub InitPropVariantFromStringVector +@ stdcall InitPropVariantFromStringVector(ptr long ptr) @ stub InitPropVariantFromUInt16Vector @ stub InitPropVariantFromUInt32Vector @ stub InitPropVariantFromUInt64Vector @@ -50,7 +50,7 @@ @ stub InitVariantFromBooleanArray @ stdcall InitVariantFromBuffer(ptr long ptr) @ stub InitVariantFromDoubleArray -@ stub InitVariantFromFileTime +@ stdcall InitVariantFromFileTime(ptr ptr) @ stub InitVariantFromFileTimeArray @ stdcall InitVariantFromGUIDAsString(ptr ptr) @ stub InitVariantFromInt16Array @@ -69,7 +69,7 @@ @ stdcall PSCreateMemoryPropertyStore(ptr ptr) @ stub PSCreateMultiplexPropertyStore @ stub PSCreatePropertyChangeArray -@ stub PSCreatePropertyStoreFromObject +@ stdcall PSCreatePropertyStoreFromObject(ptr long ptr ptr) @ stub PSCreatePropertyStoreFromPropertySetStorage @ stub PSCreateSimplePropertyChange @ stub PSEnumeratePropertyDescriptions @@ -107,7 +107,7 @@ @ stub PropVariantGetUInt16Elem @ stub PropVariantGetUInt32Elem @ stub PropVariantGetUInt64Elem -@ stub PropVariantToBSTR +@ stdcall PropVariantToBSTR(ptr ptr) @ stdcall PropVariantToBoolean(ptr ptr) @ stub PropVariantToBooleanVector @ stub PropVariantToBooleanVectorAlloc @@ -146,12 +146,12 @@ @ stdcall PropVariantToUInt32(ptr ptr) @ stub PropVariantToUInt32Vector @ stub PropVariantToUInt32VectorAlloc -@ stub PropVariantToUInt32WithDefault +@ stdcall PropVariantToUInt32WithDefault(ptr long) @ stdcall PropVariantToUInt64(ptr ptr) @ stub PropVariantToUInt64Vector @ stub PropVariantToUInt64VectorAlloc @ stub PropVariantToUInt64WithDefault -@ stub PropVariantToVariant +@ stdcall PropVariantToVariant(ptr ptr) @ stub StgDeserializePropVariant @ stub StgSerializePropVariant @ stub VariantCompare @@ -189,13 +189,13 @@ @ stub VariantToInt64Array @ stub VariantToInt64ArrayAlloc @ stub VariantToInt64WithDefault -@ stub VariantToPropVariant +@ stdcall VariantToPropVariant(ptr ptr) @ stub VariantToStrRet -@ stub VariantToString +@ stdcall VariantToString(ptr ptr long) @ stub VariantToStringAlloc @ stub VariantToStringArray @ stub VariantToStringArrayAlloc -@ stub VariantToStringWithDefault +@ stdcall VariantToStringWithDefault(ptr wstr) @ stub VariantToUInt16 @ stub VariantToUInt16Array @ stub VariantToUInt16ArrayAlloc diff --git a/dll/win32/propsys/propsys_main.c b/dll/win32/propsys/propsys_main.c index 6f7dc8a397c..5557131ed4b 100644 --- a/dll/win32/propsys/propsys_main.c +++ b/dll/win32/propsys/propsys_main.c @@ -22,9 +22,6 @@ #define COBJMACROS #include <stdarg.h> -#ifdef __REACTOS__ -#include <wchar.h> -#endif #include "windef.h" #include "winbase.h" @@ -37,35 +34,6 @@ WINE_DEFAULT_DEBUG_CHANNEL(propsys); -static HINSTANCE propsys_hInstance; - -BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved) -{ - TRACE("(0x%p, %d, %p)\n", hinstDLL, fdwReason, lpvReserved); - - switch (fdwReason) - { - case DLL_WINE_PREATTACH: - return FALSE; /* prefer native version */ - case DLL_PROCESS_ATTACH: - propsys_hInstance = hinstDLL; - DisableThreadLibraryCalls(hinstDLL); - break; - } - - return TRUE; -} - -HRESULT WINAPI DllRegisterServer(void) -{ - return __wine_register_resources( propsys_hInstance ); -} - -HRESULT WINAPI DllUnregisterServer(void) -{ - return __wine_unregister_resources( propsys_hInstance ); -} - static HRESULT WINAPI ClassFactory_QueryInterface(IClassFactory *iface, REFIID riid, void **ppv) { *ppv = NULL; @@ -135,11 +103,6 @@ HRESULT WINAPI DllGetClassObject(REFCLSID rclsid, REFIID riid, LPVOID *ppv) return CLASS_E_CLASSNOTAVAILABLE; } -HRESULT WINAPI DllCanUnloadNow(void) -{ - return S_FALSE; -} - static HRESULT WINAPI propsys_QueryInterface(IPropertySystem *iface, REFIID riid, void **obj) { *obj = NULL; @@ -194,7 +157,7 @@ static HRESULT WINAPI propsys_FormatForDisplay(IPropertySystem *iface, REFPROPERTYKEY key, REFPROPVARIANT propvar, PROPDESC_FORMAT_FLAGS flags, LPWSTR dest, DWORD destlen) { - FIXME("%p %p %x %p %d: stub\n", key, propvar, flags, dest, destlen); + FIXME("%p %p %x %p %ld: stub\n", key, propvar, flags, dest, destlen); return E_NOTIMPL; } @@ -283,12 +246,6 @@ HRESULT WINAPI PSRefreshPropertySchema(void) HRESULT WINAPI PSStringFromPropertyKey(REFPROPERTYKEY pkey, LPWSTR psz, UINT cch) { - static const WCHAR guid_fmtW[] = {'{','%','0','8','X','-','%','0','4','X','-', - '%','0','4','X','-','%','0','2','X','%','0','2','X','-', - '%','0','2','X','%','0','2','X','%','0','2','X', - '%','0','2','X','%','0','2','X','%','0','2','X','}',0}; - static const WCHAR pid_fmtW[] = {'%','u',0}; - WCHAR pidW[PKEY_PIDSTR_MAX + 1]; LPWSTR p = psz; int len; @@ -308,8 +265,8 @@ HRESULT WINAPI PSStringFromPropertyKey(REFPROPERTYKEY pkey, LPWSTR psz, UINT cch return E_NOT_SUFFICIENT_BUFFER; } - swprintf(psz, guid_fmtW, pkey->fmtid.Data1, pkey->fmtid.Data2, - pkey->fmtid.Data3, pkey->fmtid.Data4[0], pkey->fmtid.Data4[1], + swprintf(psz, cch, L"{%08X-%04X-%04X-%02X%02X-%02X%02X%02X%02X%02X%02X}", pkey->fmtid.Data1, + pkey->fmtid.Data2, pkey->fmtid.Data3, pkey->fmtid.Data4[0], pkey->fmtid.Data4[1], pkey->fmtid.Data4[2], pkey->fmtid.Data4[3], pkey->fmtid.Data4[4], pkey->fmtid.Data4[5], pkey->fmtid.Data4[6], pkey->fmtid.Data4[7]); @@ -318,7 +275,7 @@ HRESULT WINAPI PSStringFromPropertyKey(REFPROPERTYKEY pkey, LPWSTR psz, UINT cch *p++ = ' '; cch -= GUIDSTRING_MAX - 1 + 1; - len = swprintf(pidW, pid_fmtW, pkey->pid); + len = swprintf(pidW, ARRAY_SIZE(pidW), L"%u", pkey->pid); if (cch >= len + 1) { @@ -498,7 +455,7 @@ HRESULT WINAPI PSPropertyKeyFromString(LPCWSTR pszString, PROPERTYKEY *pkey) } /* Overflow is not checked. */ - while (iswdigit(*pszString)) + while ('0' <= *pszString && *pszString <= '9') { pkey->pid *= 10; pkey->pid += (*pszString - '0'); @@ -517,3 +474,10 @@ HRESULT WINAPI PSCreateMemoryPropertyStore(REFIID riid, void **ppv) return PropertyStore_CreateInstance(NULL, riid, ppv); } + +#ifdef __REACTOS__ +HRESULT WINAPI DllCanUnloadNow(void) +{ + return S_FALSE; +} +#endif diff --git a/dll/win32/propsys/propsys_private.h b/dll/win32/propsys/propsys_private.h index d43de7534d2..a91b5c5c289 100644 --- a/dll/win32/propsys/propsys_private.h +++ b/dll/win32/propsys/propsys_private.h @@ -20,4 +20,4 @@ #pragma once -HRESULT PropertyStore_CreateInstance(IUnknown *outer, REFIID riid, void **ppv) DECLSPEC_HIDDEN; +HRESULT PropertyStore_CreateInstance(IUnknown *outer, REFIID riid, void **ppv); diff --git a/dll/win32/propsys/propvar.c b/dll/win32/propsys/propvar.c index f03dc148435..e1375134f11 100644 --- a/dll/win32/propsys/propvar.c +++ b/dll/win32/propsys/propvar.c @@ -23,8 +23,6 @@ #include <stdio.h> #include <stdlib.h> -#define NONAMELESSUNION - #include "windef.h" #include "winbase.h" #include "winerror.h" @@ -33,11 +31,31 @@ #include "shlobj.h" #include "propvarutil.h" #include "strsafe.h" - #include "wine/debug.h" WINE_DEFAULT_DEBUG_CHANNEL(propsys); +#define GUID_STR_LEN 38 +static HRESULT VARIANT_ValidateType(VARTYPE vt) +{ + VARTYPE vtExtra = vt & (VT_VECTOR | VT_ARRAY | VT_BYREF | VT_RESERVED); + + vt &= VT_TYPEMASK; + + if (!(vtExtra & (VT_VECTOR | VT_RESERVED))) + { + if (vt < VT_VOID || vt == VT_RECORD || vt == VT_CLSID) + { + if ((vtExtra & (VT_BYREF | VT_ARRAY)) && vt <= VT_NULL) + return DISP_E_BADVARTYPE; + if (vt != (VARTYPE)15) + return S_OK; + } + } + + return DISP_E_BADVARTYPE; +} + static HRESULT PROPVAR_ConvertFILETIME(const FILETIME *ft, PROPVARIANT *ppropvarDest, VARTYPE vt) { SYSTEMTIME time; @@ -47,11 +65,11 @@ static HRESULT PROPVAR_ConvertFILETIME(const FILETIME *ft, PROPVARIANT *ppropvar switch (vt) { case VT_LPSTR: - ppropvarDest->u.pszVal = HeapAlloc(GetProcessHeap(), 0, 64); - if (!ppropvarDest->u.pszVal) + ppropvarDest->pszVal = HeapAlloc(GetProcessHeap(), 0, 64); + if (!ppropvarDest->pszVal) return E_OUTOFMEMORY; - sprintf( ppropvarDest->u.pszVal, "%04d/%02d/%02d:%02d:%02d:%02d.%03d", + sprintf( ppropvarDest->pszVal, "%04d/%02d/%02d:%02d:%02d:%02d.%03d", time.wYear, time.wMonth, time.wDay, time.wHour, time.wMinute, time.wSecond, time.wMilliseconds ); @@ -74,35 +92,35 @@ static HRESULT PROPVAR_ConvertNumber(REFPROPVARIANT pv, int dest_bits, { case VT_I1: src_signed = TRUE; - *res = pv->u.cVal; + *res = pv->cVal; break; case VT_UI1: src_signed = FALSE; - *res = pv->u.bVal; + *res = pv->bVal; break; case VT_I2: src_signed = TRUE; - *res = pv->u.iVal; + *res = pv->iVal; break; case VT_UI2: src_signed = FALSE; - *res = pv->u.uiVal; + *res = pv->uiVal; break; case VT_I4: src_signed = TRUE; - *res = pv->u.lVal; + *res = pv->lVal; break; case VT_UI4: src_signed = FALSE; - *res = pv->u.ulVal; + *res = pv->ulVal; break; case VT_I8: src_signed = TRUE; - *res = pv->u.hVal.QuadPart; + *res = pv->hVal.QuadPart; break; case VT_UI8: src_signed = FALSE; - *res = pv->u.uhVal.QuadPart; + *res = pv->uhVal.QuadPart; break; case VT_EMPTY: src_signed = FALSE; @@ -111,8 +129,12 @@ static HRESULT PROPVAR_ConvertNumber(REFPROPVARIANT pv, int dest_bits, case VT_LPSTR: { char *end; - *res = _strtoi64(pv->u.pszVal, &end, 0); - if (pv->u.pszVal == end) +#ifdef __REACTOS__ + *res = _strtoi64(pv->pszVal, &end, 0); +#else + *res = strtoll(pv->pszVal, &end, 0); +#endif + if (pv->pszVal == end) return DISP_E_TYPEMISMATCH; src_signed = *res < 0; break; @@ -121,8 +143,8 @@ static HRESULT PROPVAR_ConvertNumber(REFPROPVARIANT pv, int dest_bits, case VT_BSTR: { WCHAR *end; - *res = wcstol(pv->u.pwszVal, &end, 0); - if (pv->u.pwszVal == end) + *res = wcstol(pv->pwszVal, &end, 0); + if (pv->pwszVal == end) return DISP_E_TYPEMISMATCH; src_signed = *res < 0; break; @@ -130,7 +152,7 @@ static HRESULT PROPVAR_ConvertNumber(REFPROPVARIANT pv, int dest_bits, case VT_R8: { src_signed = TRUE; - *res = pv->u.dblVal; + *res = pv->dblVal; break; } default: @@ -231,6 +253,20 @@ HRESULT WINAPI PropVariantToUInt32(REFPROPVARIANT propvarIn, ULONG *ret) return hr; } +ULONG WINAPI PropVariantToUInt32WithDefault(REFPROPVARIANT propvarIn, ULONG ulDefault) +{ + LONGLONG res; + HRESULT hr; + + TRACE("%p,%lu\n", propvarIn, ulDefault); + + hr = PROPVAR_ConvertNumber(propvarIn, 32, FALSE, &res); + if (SUCCEEDED(hr)) + return (ULONG)res; + + return ulDefault; +} + HRESULT WINAPI PropVariantToUInt64(REFPROPVARIANT propvarIn, ULONGLONG *ret) { LONGLONG res; @@ -245,10 +281,6 @@ HRESULT WINAPI PropVariantToUInt64(REFPROPVARIANT propvarIn, ULONGLONG *ret) HRESULT WINAPI PropVariantToBoolean(REFPROPVARIANT propvarIn, BOOL *ret) { - static const WCHAR trueW[] = {'t','r','u','e',0}; - static const WCHAR falseW[] = {'f','a','l','s','e',0}; - static const WCHAR true2W[] = {'#','T','R','U','E','#',0}; - static const WCHAR false2W[] = {'#','F','A','L','S','E','#',0}; LONGLONG res; HRESULT hr; @@ -259,21 +291,21 @@ HRESULT WINAPI PropVariantToBoolean(REFPROPVARIANT propvarIn, BOOL *ret) switch (propvarIn->vt) { case VT_BOOL: - *ret = propvarIn->u.boolVal == VARIANT_TRUE; + *ret = propvarIn->boolVal == VARIANT_TRUE; return S_OK; case VT_LPWSTR: case VT_BSTR: - if (!propvarIn->u.pwszVal) + if (!propvarIn->pwszVal) return DISP_E_TYPEMISMATCH; - if (!lstrcmpiW(propvarIn->u.pwszVal, trueW) || !lstrcmpW(propvarIn->u.pwszVal, true2W)) + if (!lstrcmpiW(propvarIn->pwszVal, L"true") || !lstrcmpW(propvarIn->pwszVal, L"#TRUE#")) { *ret = TRUE; return S_OK; } - if (!lstrcmpiW(propvarIn->u.pwszVal, falseW) || !lstrcmpW(propvarIn->u.pwszVal, false2W)) + if (!lstrcmpiW(propvarIn->pwszVal, L"false") || !lstrcmpW(propvarIn->pwszVal, L"#FALSE#")) { *ret = FALSE; return S_OK; @@ -281,16 +313,16 @@ HRESULT WINAPI PropVariantToBoolean(REFPROPVARIANT propvarIn, BOOL *ret) break; case VT_LPSTR: - if (!propvarIn->u.pszVal) + if (!propvarIn->pszVal) return DISP_E_TYPEMISMATCH; - if (!lstrcmpiA(propvarIn->u.pszVal, "true") || !lstrcmpA(propvarIn->u.pszVal, "#TRUE#")) + if (!lstrcmpiA(propvarIn->pszVal, "true") || !lstrcmpA(propvarIn->pszVal, "#TRUE#")) { *ret = TRUE; return S_OK; } - if (!lstrcmpiA(propvarIn->u.pszVal, "false") || !lstrcmpA(propvarIn->u.pszVal, "#FALSE#")) + if (!lstrcmpiA(propvarIn->pszVal, "false") || !lstrcmpA(propvarIn->pszVal, "#FALSE#")) { *ret = FALSE; return S_OK; @@ -303,6 +335,26 @@ HRESULT WINAPI PropVariantToBoolean(REFPROPVARIANT propvarIn, BOOL *ret) return hr; } +HRESULT WINAPI PropVariantToBSTR(REFPROPVARIANT propvar, BSTR *bstr) +{ + WCHAR *str; + HRESULT hr; + + TRACE("propvar %p, propvar->vt %#x, bstr %p.\n", + propvar, propvar ? propvar->vt : 0, bstr); + + if (FAILED(hr = PropVariantToStringAlloc(propvar, &str))) + return hr; + + *bstr = SysAllocString(str); + CoTaskMemFree(str); + + if (!*bstr) + return E_OUTOFMEMORY; + + return S_OK; +} + HRESULT WINAPI PropVariantToBuffer(REFPROPVARIANT propvarIn, void *ret, UINT cb) { HRESULT hr = S_OK; @@ -312,9 +364,9 @@ HRESULT WINAPI PropVariantToBuffer(REFPROPVARIANT propvarIn, void *ret, UINT cb) switch(propvarIn->vt) { case VT_VECTOR|VT_UI1: - if(cb > propvarIn->u.caub.cElems) + if(cb > propvarIn->caub.cElems) return E_FAIL; - memcpy(ret, propvarIn->u.caub.pElems, cb); + memcpy(ret, propvarIn->caub.pElems, cb); break; case VT_ARRAY|VT_UI1: FIXME("Unsupported type: VT_ARRAY|VT_UI1\n"); @@ -328,7 +380,6 @@ HRESULT WINAPI PropVariantToBuffer(REFPROPVARIANT propvarIn, void *ret, UINT cb) return hr; } - HRESULT WINAPI PropVariantToString(REFPROPVARIANT propvarIn, PWSTR ret, UINT cch) { HRESULT hr; @@ -369,27 +420,36 @@ HRESULT WINAPI PropVariantToStringAlloc(REFPROPVARIANT propvarIn, WCHAR **ret) break; case VT_LPSTR: - if(propvarIn->u.pszVal) + if(propvarIn->pszVal) { DWORD len; - len = MultiByteToWideChar(CP_ACP, 0, propvarIn->u.pszVal, -1, NULL, 0); + len = MultiByteToWideChar(CP_ACP, 0, propvarIn->pszVal, -1, NULL, 0); res = CoTaskMemAlloc(len*sizeof(WCHAR)); if(!res) return E_OUTOFMEMORY; - MultiByteToWideChar(CP_ACP, 0, propvarIn->u.pszVal, -1, res, len); + MultiByteToWideChar(CP_ACP, 0, propvarIn->pszVal, -1, res, len); } break; case VT_LPWSTR: case VT_BSTR: - if (propvarIn->u.pwszVal) + if (propvarIn->pwszVal) { - DWORD size = (lstrlenW(propvarIn->u.pwszVal) + 1) * sizeof(WCHAR); + DWORD size = (lstrlenW(propvarIn->pwszVal) + 1) * sizeof(WCHAR); res = CoTaskMemAlloc(size); if(!res) return E_OUTOFMEMORY; - memcpy(res, propvarIn->u.pwszVal, size); + memcpy(res, propvarIn->pwszVal, size); + } + break; + + case VT_CLSID: + if (propvarIn->puuid) + { + if (!(res = CoTaskMemAlloc((GUID_STR_LEN + 1) * sizeof(WCHAR)))) + return E_OUTOFMEMORY; + StringFromGUID2(propvarIn->puuid, res, GUID_STR_LEN + 1); } break; @@ -406,21 +466,70 @@ HRESULT WINAPI PropVariantToStringAlloc(REFPROPVARIANT propvarIn, WCHAR **ret) PCWSTR WINAPI PropVariantToStringWithDefault(REFPROPVARIANT propvarIn, LPCWSTR pszDefault) { - static const WCHAR str_empty[] = {0}; if (propvarIn->vt == VT_BSTR) { - if (propvarIn->u.bstrVal == NULL) - return str_empty; + if (propvarIn->bstrVal == NULL) + return L""; - return propvarIn->u.bstrVal; + return propvarIn->bstrVal; } - if (propvarIn->vt == VT_LPWSTR && propvarIn->u.pwszVal != NULL) - return propvarIn->u.pwszVal; + if (propvarIn->vt == VT_LPWSTR && propvarIn->pwszVal != NULL) + return propvarIn->pwszVal; return pszDefault; } +/****************************************************************** + * VariantToStringWithDefault (PROPSYS.@) + */ +PCWSTR WINAPI VariantToStringWithDefault(const VARIANT *pvar, const WCHAR *default_value) +{ + TRACE("%s, %s.\n", debugstr_variant(pvar), debugstr_w(default_value)); + + if (V_VT(pvar) == (VT_BYREF | VT_VARIANT)) pvar = V_VARIANTREF(pvar); + if (V_VT(pvar) == (VT_BYREF | VT_BSTR) || V_VT(pvar) == VT_BSTR) + { + BSTR ret = V_ISBYREF(pvar) ? *V_BSTRREF(pvar) : V_BSTR(pvar); + return ret ? ret : L""; + } + + return default_value; +} + +/****************************************************************** + * VariantToString (PROPSYS.@) + */ +HRESULT WINAPI VariantToString(REFVARIANT var, PWSTR ret, UINT cch) +{ + WCHAR buffer[64], *str = buffer; + + TRACE("%p, %p, %u.\n", var, ret, cch); + + *ret = 0; + + if (!cch) + return E_INVALIDARG; + + switch (V_VT(var)) + { + case VT_BSTR: + str = V_BSTR(var); + break; + case VT_I4: + swprintf(buffer, ARRAY_SIZE(buffer), L"%d", V_I4(var)); + break; + default: + FIXME("Unsupported type %d.\n", V_VT(var)); + return E_NOTIMPL; + } + + if (wcslen(str) > cch - 1) + return STRSAFE_E_INSUFFICIENT_BUFFER; + wcscpy(ret, str); + + return S_OK; +} /****************************************************************** * PropVariantChangeType (PROPSYS.@) @@ -437,7 +546,7 @@ HRESULT WINAPI PropVariantChangeType(PROPVARIANT *ppropvarDest, REFPROPVARIANT p return PropVariantCopy(ppropvarDest, propvarSrc); if (propvarSrc->vt == VT_FILETIME) - return PROPVAR_ConvertFILETIME(&propvarSrc->u.filetime, ppropvarDest, vt); + return PROPVAR_ConvertFILETIME(&propvarSrc->filetime, ppropvarDest, vt); switch (vt) { @@ -449,7 +558,7 @@ HRESULT WINAPI PropVariantChangeType(PROPVARIANT *ppropvarDest, REFPROPVARIANT p if (SUCCEEDED(hr)) { ppropvarDest->vt = VT_I1; - ppropvarDest->u.cVal = (char)res; + ppropvarDest->cVal = (char)res; } return hr; } @@ -462,7 +571,7 @@ HRESULT WINAPI PropVariantChangeType(PROPVARIANT *ppropvarDest, REFPROPVARIANT p if (SUCCEEDED(hr)) { ppropvarDest->vt = VT_UI1; - ppropvarDest->u.bVal = (UCHAR)res; + ppropvarDest->bVal = (UCHAR)res; } return hr; } @@ -474,7 +583,7 @@ HRESULT WINAPI PropVariantChangeType(PROPVARIANT *ppropvarDest, REFPROPVARIANT p if (SUCCEEDED(hr)) { ppropvarDest->vt = VT_I2; - ppropvarDest->u.iVal = res; + ppropvarDest->iVal = res; } return hr; } @@ -485,7 +594,7 @@ HRESULT WINAPI PropVariantChangeType(PROPVARIANT *ppropvarDest, REFPROPVARIANT p if (SUCCEEDED(hr)) { ppropvarDest->vt = VT_UI2; - ppropvarDest->u.uiVal = res; + ppropvarDest->uiVal = res; } return hr; } @@ -496,7 +605,7 @@ HRESULT WINAPI PropVariantChangeType(PROPVARIANT *ppropvarDest, REFPROPVARIANT p if (SUCCEEDED(hr)) { ppropvarDest->vt = VT_I4; - ppropvarDest->u.lVal = res; + ppropvarDest->lVal = res; } return hr; } @@ -507,7 +616,7 @@ HRESULT WINAPI PropVariantChangeType(PROPVARIANT *ppropvarDest, REFPROPVARIANT p if (SUCCEEDED(hr)) { ppropvarDest->vt = VT_UI4; - ppropvarDest->u.ulVal = res; + ppropvarDest->ulVal = res; } return hr; } @@ -518,7 +627,7 @@ HRESULT WINAPI PropVariantChangeType(PROPVARIANT *ppropvarDest, REFPROPVARIANT p if (SUCCEEDED(hr)) { ppropvarDest->vt = VT_I8; - ppropvarDest->u.hVal.QuadPart = res; + ppropvarDest->hVal.QuadPart = res; } return hr; } @@ -529,7 +638,7 @@ HRESULT WINAPI PropVariantChangeType(PROPVARIANT *ppropvarDest, REFPROPVARIANT p if (SUCCEEDED(hr)) { ppropvarDest->vt = VT_UI8; - ppropvarDest->u.uhVal.QuadPart = res; + ppropvarDest->uhVal.QuadPart = res; } return hr; } @@ -542,7 +651,7 @@ HRESULT WINAPI PropVariantChangeType(PROPVARIANT *ppropvarDest, REFPROPVARIANT p if (SUCCEEDED(hr)) { ppropvarDest->vt = VT_LPWSTR; - ppropvarDest->u.pwszVal = res; + ppropvarDest->pwszVal = res; } return hr; } @@ -562,7 +671,7 @@ HRESULT WINAPI PropVariantChangeType(PROPVARIANT *ppropvarDest, REFPROPVARIANT p { WideCharToMultiByte(CP_ACP, 0, resW, -1, res, len, NULL, NULL); ppropvarDest->vt = VT_LPSTR; - ppropvarDest->u.pszVal = res; + ppropvarDest->pszVal = res; } else hr = E_OUTOFMEMORY; @@ -577,18 +686,6 @@ HRESULT WINAPI PropVariantChangeType(PROPVARIANT *ppropvarDest, REFPROPVARIANT p return E_FAIL; } } - -static void PROPVAR_GUIDToWSTR(REFGUID guid, WCHAR *str) -{ - static const WCHAR format[] = {'{','%','0','8','X','-','%','0','4','X','-','%','0','4','X', - '-','%','0','2','X','%','0','2','X','-','%','0','2','X','%','0','2','X','%','0','2','X', - '%','0','2','X','%','0','2','X','%','0','2','X','}',0}; - - swprintf(str, format, guid->Data1, guid->Data2, guid->Data3, - guid->Data4[0], guid->Data4[1], guid->Data4[2], guid->Data4[3], - guid->Data4[4], guid->Data4[5], guid->Data4[6], guid->Data4[7]); -} - HRESULT WINAPI InitPropVariantFromGUIDAsString(REFGUID guid, PROPVARIANT *ppropvar) { TRACE("(%p %p)\n", guid, ppropvar); @@ -597,11 +694,11 @@ HRESULT WINAPI InitPropVariantFromGUIDAsString(REFGUID guid, PROPVARIANT *ppropv return E_FAIL; ppropvar->vt = VT_LPWSTR; - ppropvar->u.pwszVal = CoTaskMemAlloc(39*sizeof(WCHAR)); - if(!ppropvar->u.pwszVal) + ppropvar->pwszVal = CoTaskMemAlloc((GUID_STR_LEN + 1) * sizeof(WCHAR)); + if(!ppropvar->pwszVal) return E_OUTOFMEMORY; - PROPVAR_GUIDToWSTR(guid, ppropvar->u.pwszVal); + StringFromGUID2(guid, ppropvar->pwszVal, GUID_STR_LEN + 1); return S_OK; } @@ -615,11 +712,11 @@ HRESULT WINAPI InitVariantFromGUIDAsString(REFGUID guid, VARIANT *pvar) } V_VT(pvar) = VT_BSTR; - V_BSTR(pvar) = SysAllocStringLen(NULL, 38); + V_BSTR(pvar) = SysAllocStringLen(NULL, GUID_STR_LEN); if(!V_BSTR(pvar)) return E_OUTOFMEMORY; - PROPVAR_GUIDToWSTR(guid, V_BSTR(pvar)); + StringFromGUID2(guid, V_BSTR(pvar), GUID_STR_LEN + 1); return S_OK; } @@ -627,13 +724,13 @@ HRESULT WINAPI InitPropVariantFromBuffer(const VOID *pv, UINT cb, PROPVARIANT *p { TRACE("(%p %u %p)\n", pv, cb, ppropvar); - ppropvar->u.caub.pElems = CoTaskMemAlloc(cb); - if(!ppropvar->u.caub.pElems) + ppropvar->caub.pElems = CoTaskMemAlloc(cb); + if(!ppropvar->caub.pElems) return E_OUTOFMEMORY; ppropvar->vt = VT_VECTOR|VT_UI1; - ppropvar->u.caub.cElems = cb; - memcpy(ppropvar->u.caub.pElems, pv, cb); + ppropvar->caub.cElems = cb; + memcpy(ppropvar->caub.pElems, pv, cb); return S_OK; } @@ -641,12 +738,44 @@ HRESULT WINAPI InitPropVariantFromCLSID(REFCLSID clsid, PROPVARIANT *ppropvar) { TRACE("(%s %p)\n", debugstr_guid(clsid), ppropvar); - ppropvar->u.puuid = CoTaskMemAlloc(sizeof(*ppropvar->u.puuid)); - if(!ppropvar->u.puuid) + ppropvar->puuid = CoTaskMemAlloc(sizeof(*ppropvar->puuid)); + if(!ppropvar->puuid) return E_OUTOFMEMORY; ppropvar->vt = VT_CLSID; - memcpy(ppropvar->u.puuid, clsid, sizeof(*ppropvar->u.puuid)); + memcpy(ppropvar->puuid, clsid, sizeof(*ppropvar->puuid)); + return S_OK; +} + +HRESULT WINAPI InitPropVariantFromStringVector(PCWSTR *strs, ULONG count, PROPVARIANT *ppropvar) +{ + unsigned int i; + + TRACE("(%p %lu %p)\n", strs, count, ppropvar); + + ppropvar->calpwstr.pElems = CoTaskMemAlloc(count * sizeof(*ppropvar->calpwstr.pElems)); + if(!ppropvar->calpwstr.pElems) + return E_OUTOFMEMORY; + + ppropvar->vt = VT_LPWSTR | VT_VECTOR; + ppropvar->calpwstr.cElems = 0; + if (count) + memset(ppropvar->calpwstr.pElems, 0, count * sizeof(*ppropvar->calpwstr.pElems)); + + for (i = 0; i < count; ++i) + { + if (strs[i]) + { + if (!(ppropvar->calpwstr.pElems[i] = CoTaskMemAlloc((wcslen(strs[i]) + 1)*sizeof(**strs)))) + { + PropVariantClear(ppropvar); + return E_OUTOFMEMORY; + } + } + wcscpy(ppropvar->calpwstr.pElems[i], strs[i]); + ppropvar->calpwstr.cElems++; + } + return S_OK; } @@ -681,6 +810,21 @@ HRESULT WINAPI InitVariantFromBuffer(const VOID *pv, UINT cb, VARIANT *pvar) return S_OK; } +HRESULT WINAPI InitVariantFromFileTime(const FILETIME *ft, VARIANT *var) +{ + SYSTEMTIME st; + + TRACE("%p, %p\n", ft, var); + + VariantInit(var); + if (!FileTimeToSystemTime(ft, &st)) + return E_INVALIDARG; + if (!SystemTimeToVariantTime(&st, &V_DATE(var))) + return E_INVALIDARG; + V_VT(var) = VT_DATE; + return S_OK; +} + static inline DWORD PROPVAR_HexToNum(const WCHAR *hex) { DWORD ret; @@ -759,11 +903,11 @@ HRESULT WINAPI PropVariantToGUID(const PROPVARIANT *ppropvar, GUID *guid) switch(ppropvar->vt) { case VT_BSTR: - return PROPVAR_WCHARToGUID(ppropvar->u.bstrVal, SysStringLen(ppropvar->u.bstrVal), guid); + return PROPVAR_WCHARToGUID(ppropvar->bstrVal, SysStringLen(ppropvar->bstrVal), guid); case VT_LPWSTR: - return PROPVAR_WCHARToGUID(ppropvar->u.pwszVal, lstrlenW(ppropvar->u.pwszVal), guid); + return PROPVAR_WCHARToGUID(ppropvar->pwszVal, lstrlenW(ppropvar->pwszVal), guid); case VT_CLSID: - memcpy(guid, ppropvar->u.puuid, sizeof(*ppropvar->u.puuid)); + memcpy(guid, ppropvar->puuid, sizeof(*ppropvar->puuid)); return S_OK; default: @@ -797,17 +941,20 @@ static BOOL isemptyornull(const PROPVARIANT *propvar) if ((propvar->vt & VT_ARRAY) == VT_ARRAY) { int i; - for (i=0; i<propvar->u.parray->cDims; i++) + for (i=0; i<propvar->parray->cDims; i++) { - if (propvar->u.parray->rgsabound[i].cElements != 0) + if (propvar->parray->rgsabound[i].cElements != 0) break; } - return i == propvar->u.parray->cDims; + return i == propvar->parray->cDims; } if (propvar->vt == VT_CLSID) - return !propvar->u.puuid; + return !propvar->puuid; + + if (propvar->vt & VT_VECTOR) + return !propvar->caub.cElems; - /* FIXME: vectors, byrefs, errors? */ + /* FIXME: byrefs, errors? */ return FALSE; } @@ -816,6 +963,7 @@ INT WINAPI PropVariantCompareEx(REFPROPVARIANT propvar1, REFPROPVARIANT propvar2 { const PROPVARIANT *propvar2_converted; PROPVARIANT propvar2_static; + unsigned int count; HRESULT hr; INT res=-1; @@ -844,9 +992,9 @@ INT WINAPI PropVariantCompareEx(REFPROPVARIANT propvar1, REFPROPVARIANT propvar2 propvar2_converted = propvar2; #define CMP_NUM_VALUE(var) do { \ - if (propvar1->u.var > propvar2_converted->u.var) \ + if (propvar1->var > propvar2_converted->var) \ res = 1; \ - else if (propvar1->u.var < propvar2_converted->u.var) \ + else if (propvar1->var < propvar2_converted->var) \ res = -1; \ else \ res = 0; \ @@ -870,7 +1018,7 @@ INT WINAPI PropVariantCompareEx(REFPROPVARIANT propvar1, REFPROPVARIANT propvar2 CMP_NUM_VALUE(lVal); break; case VT_UI4: - CMP_NUM_VALUE(uiVal); + CMP_NUM_VALUE(ulVal); break; case VT_I8: CMP_NUM_VALUE(hVal.QuadPart); @@ -888,20 +1036,27 @@ INT WINAPI PropVariantCompareEx(REFPROPVARIANT propvar1, REFPROPVARIANT propvar2 case VT_LPWSTR: /* FIXME: Use other string flags. */ if (flags & (PVCF_USESTRCMPI | PVCF_USESTRCMPIC)) - res = lstrcmpiW(propvar1->u.bstrVal, propvar2_converted->u.bstrVal); + res = lstrcmpiW(propvar1->bstrVal, propvar2_converted->bstrVal); else - res = lstrcmpW(propvar1->u.bstrVal, propvar2_converted->u.bstrVal); + res = lstrcmpW(propvar1->bstrVal, propvar2_converted->bstrVal); break; case VT_LPSTR: /* FIXME: Use other string flags. */ if (flags & (PVCF_USESTRCMPI | PVCF_USESTRCMPIC)) - res = lstrcmpiA(propvar1->u.pszVal, propvar2_converted->u.pszVal); + res = lstrcmpiA(propvar1->pszVal, propvar2_converted->pszVal); else - res = lstrcmpA(propvar1->u.pszVal, propvar2_converted->u.pszVal); + res = lstrcmpA(propvar1->pszVal, propvar2_converted->pszVal); break; case VT_CLSID: - res = memcmp(propvar1->u.puuid, propvar2->u.puuid, sizeof(*propvar1->u.puuid)); + res = memcmp(propvar1->puuid, propvar2->puuid, sizeof(*propvar1->puuid)); + if (res) res = res > 0 ? 1 : -1; + break; + case VT_VECTOR | VT_UI1: + count = min(propvar1->caub.cElems, propvar2->caub.cElems); + res = count ? memcmp(propvar1->caub.pElems, propvar2->caub.pElems, sizeof(*propvar1->caub.pElems) * count) : 0; if (res) res = res > 0 ? 1 : -1; + if (!res && propvar1->caub.cElems != propvar2->caub.cElems) + res = propvar1->caub.cElems > propvar2->caub.cElems ? 1 : -1; break; default: FIXME("vartype %#x not handled\n", propvar1->vt); @@ -914,3 +1069,158 @@ INT WINAPI PropVariantCompareEx(REFPROPVARIANT propvar1, REFPROPVARIANT propvar2 return res; } + +HRESULT WINAPI PropVariantToVariant(const PROPVARIANT *propvar, VARIANT *var) +{ + HRESULT hr = S_OK; + + TRACE("propvar %p, var %p, propvar->vt %#x.\n", propvar, var, propvar ? propvar->vt : 0); + + if (!var || !propvar) + return E_INVALIDARG; + + VariantInit(var); +#ifdef __REACTOS__ + V_VT(var) = propvar->vt; +#else + var->vt = propvar->vt; +#endif + + switch (propvar->vt) + { + case VT_EMPTY: + case VT_NULL: + break; + case VT_I1: + V_I1(var) = propvar->cVal; + break; + case VT_I2: + V_I2(var) = propvar->iVal; + break; + case VT_I4: + V_I4(var) = propvar->lVal; + break; + case VT_I8: + V_I8(var) = propvar->hVal.QuadPart; + break; + case VT_UI1: + V_UI1(var) = propvar->bVal; + break; + case VT_UI2: + V_UI2(var) = propvar->uiVal; + break; + case VT_UI4: + V_UI4(var) = propvar->ulVal; + break; + case VT_UI8: + V_UI8(var) = propvar->uhVal.QuadPart; + break; + case VT_BOOL: + V_BOOL(var) = propvar->boolVal; + break; + case VT_R4: + V_R4(var) = propvar->fltVal; + break; + case VT_R8: + V_R8(var) = propvar->dblVal; + break; + case VT_LPSTR: + case VT_LPWSTR: + case VT_BSTR: + case VT_CLSID: +#ifdef __REACTOS__ + V_VT(var) = VT_BSTR; +#else + var->vt = VT_BSTR; +#endif + hr = PropVariantToBSTR(propvar, &V_BSTR(var)); + break; + default: + FIXME("Unsupported type %d.\n", propvar->vt); + return E_INVALIDARG; + } + + return hr; +} + +HRESULT WINAPI VariantToPropVariant(const VARIANT *var, PROPVARIANT *propvar) +{ + HRESULT hr; + + TRACE("var %p, propvar %p.\n", debugstr_variant(var), propvar); + + if (!var || !propvar) + return E_INVALIDARG; + +#ifdef __REACTOS__ + if (FAILED(hr = VARIANT_ValidateType(V_VT(var)))) +#else + if (FAILED(hr = VARIANT_ValidateType(var->vt))) +#endif + return hr; + + PropVariantInit(propvar); + + +#ifdef __REACTOS__ + propvar->vt = V_VT(var); +#else + propvar->vt = var->vt; +#endif + +#ifdef __REACTOS__ + switch (V_VT(var)) +#else + switch (var->vt) +#endif + { + case VT_EMPTY: + case VT_NULL: + break; + case VT_I1: + propvar->cVal = V_I1(var); + break; + case VT_I2: + propvar->iVal = V_I2(var); + break; + case VT_I4: + propvar->lVal = V_I4(var); + break; + case VT_I8: + propvar->hVal.QuadPart = V_I8(var); + break; + case VT_UI1: + propvar->bVal = V_UI1(var); + break; + case VT_UI2: + propvar->uiVal = V_UI2(var); + break; + case VT_UI4: + propvar->ulVal = V_UI4(var); + break; + case VT_UI8: + propvar->uhVal.QuadPart = V_UI8(var); + break; + case VT_BOOL: + propvar->boolVal = V_BOOL(var); + break; + case VT_R4: + propvar->fltVal = V_R4(var); + break; + case VT_R8: + propvar->dblVal = V_R8(var); + break; + case VT_BSTR: + propvar->bstrVal = SysAllocString(V_BSTR(var)); + break; + default: +#ifdef __REACTOS__ + FIXME("Unsupported type %d.\n", V_VT(var)); +#else + FIXME("Unsupported type %d.\n", var->vt); +#endif + return E_INVALIDARG; + } + + return S_OK; +} diff --git a/media/doc/WINESYNC.txt b/media/doc/WINESYNC.txt index 203f7ae3333..2b000140713 100644 --- a/media/doc/WINESYNC.txt +++ b/media/doc/WINESYNC.txt @@ -160,7 +160,7 @@ dll/win32/pdh # Synced to WineStaging-4.18 dll/win32/pidgen # Synced to WineStaging-4.18 dll/win32/powrprof # Forked at Wine-1.0rc5 dll/win32/printui # Synced to WineStaging-4.18 -dll/win32/propsys # Synced to WineStaging-4.18 +dll/win32/propsys # Synced to Wine-10.0 dll/win32/pstorec # Synced to WineStaging-3.3 dll/win32/qmgr # Synced to WineStaging-4.18 dll/win32/qmgrprxy # Synced to WineStaging-2.9 diff --git a/modules/rostests/winetests/propsys/CMakeLists.txt b/modules/rostests/winetests/propsys/CMakeLists.txt index ac14259b769..a38b9654b9d 100644 --- a/modules/rostests/winetests/propsys/CMakeLists.txt +++ b/modules/rostests/winetests/propsys/CMakeLists.txt @@ -1,6 +1,7 @@ add_definitions(-DUSE_WINE_TODOS -DWINETEST_USE_DBGSTR_LONGLONG) -add_executable(propsys_winetest propstore.c propsys.c testlist.c) +remove_definitions(-D__ROS_LONG64__) +add_executable(propsys_winetest propsys.c testlist.c) set_module_type(propsys_winetest win32cui) add_importlibs(propsys_winetest propsys ole32 oleaut32 msvcrt kernel32) diff --git a/modules/rostests/winetests/propsys/propstore.c b/modules/rostests/winetests/propsys/propstore.c deleted file mode 100644 index 5aeb562cf27..00000000000 --- a/modules/rostests/winetests/propsys/propstore.c +++ /dev/null @@ -1,374 +0,0 @@ -/* - * Unit tests for IPropertyStore and related interfaces - * - * Copyright 2012 Vincent Povirk - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA - */ - -#define COBJMACROS - -#include <stdarg.h> -#include <stdio.h> - -#define NONAMELESSUNION - -#include "windef.h" -#include "winbase.h" -#include "objbase.h" -#include "propsys.h" -#include "wine/test.h" - -#include "initguid.h" - -DEFINE_GUID(PKEY_WineTest, 0x7b317433, 0xdfa3, 0x4c44, 0xad, 0x3e, 0x2f, 0x80, 0x4b, 0x90, 0xdb, 0xf4); -DEFINE_GUID(DUMMY_GUID1, 0x12345678, 0x1234,0x1234, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19); - -#define EXPECT_REF(obj,ref) _expect_ref((IUnknown *)obj, ref, __LINE__) -static void _expect_ref(IUnknown *obj, ULONG ref, int line) -{ - ULONG rc; - IUnknown_AddRef(obj); - rc = IUnknown_Release(obj); - ok_(__FILE__,line)(rc == ref, "expected refcount %d, got %d\n", ref, rc); -} - -static void test_inmemorystore(void) -{ - IPropertyStoreCache *propcache; - HRESULT hr; - PROPERTYKEY pkey; - PROPVARIANT propvar; - DWORD count; - PSC_STATE state; - - hr = CoCreateInstance(&CLSID_InMemoryPropertyStore, NULL, CLSCTX_INPROC_SERVER, - &IID_IPropertyStoreCache, (void**)&propcache); - ok(hr == S_OK, "CoCreateInstance failed, hr=%x\n", hr); - - if (FAILED(hr)) - { - skip("CLSID_InMemoryPropertyStore not supported\n"); - return; - } - - hr = IPropertyStoreCache_GetCount(propcache, NULL); - ok(hr == E_POINTER, "GetCount failed, hr=%x\n", hr); - - hr = IPropertyStoreCache_GetCount(propcache, &count); - ok(hr == S_OK, "GetCount failed, hr=%x\n", hr); - ok(count == 0, "GetCount returned %i, expected 0\n", count); - - hr = IPropertyStoreCache_Commit(propcache); - ok(hr == S_OK, "Commit failed, hr=%x\n", hr); - - hr = IPropertyStoreCache_Commit(propcache); - ok(hr == S_OK, "Commit failed, hr=%x\n", hr); - - hr = IPropertyStoreCache_GetAt(propcache, 0, &pkey); - ok(hr == E_INVALIDARG, "GetAt failed, hr=%x\n", hr); - - pkey.fmtid = PKEY_WineTest; - pkey.pid = 4; - - memset(&propvar, 0, sizeof(propvar)); - propvar.vt = VT_I4; - propvar.u.lVal = 12345; - - if (0) - { - /* Crashes on Windows 7 */ - hr = IPropertyStoreCache_SetValue(propcache, NULL, &propvar); - ok(hr == E_POINTER, "SetValue failed, hr=%x\n", hr); - - hr = IPropertyStoreCache_SetValue(propcache, &pkey, NULL); - ok(hr == E_POINTER, "SetValue failed, hr=%x\n", hr); - } - - hr = IPropertyStoreCache_SetValue(propcache, &pkey, &propvar); - ok(hr == S_OK, "SetValue failed, hr=%x\n", hr); - - hr = IPropertyStoreCache_GetCount(propcache, &count); - ok(hr == S_OK, "GetCount failed, hr=%x\n", hr); - ok(count == 1, "GetCount returned %i, expected 0\n", count); - - memset(&pkey, 0, sizeof(pkey)); - - hr = IPropertyStoreCache_GetAt(propcache, 0, &pkey); - ok(hr == S_OK, "GetAt failed, hr=%x\n", hr); - ok(IsEqualGUID(&pkey.fmtid, &PKEY_WineTest), "got wrong pkey\n"); - ok(pkey.pid == 4, "got pid of %i, expected 4\n", pkey.pid); - - pkey.fmtid = PKEY_WineTest; - pkey.pid = 4; - - memset(&propvar, 0, sizeof(propvar)); - - if (0) - { - /* Crashes on Windows 7 */ - hr = IPropertyStoreCache_GetValue(propcache, NULL, &propvar); - ok(hr == E_POINTER, "GetValue failed, hr=%x\n", hr); - } - - hr = IPropertyStoreCache_GetValue(propcache, &pkey, NULL); - ok(hr == E_POINTER, "GetValue failed, hr=%x\n", hr); - - hr = IPropertyStoreCache_GetValue(propcache, &pkey, &propvar); - ok(hr == S_OK, "GetValue failed, hr=%x\n", hr); - ok(propvar.vt == VT_I4, "expected VT_I4, got %d\n", propvar.vt); - ok(propvar.u.lVal == 12345, "expected 12345, got %d\n", propvar.u.lVal); - - pkey.fmtid = PKEY_WineTest; - pkey.pid = 10; - - /* Get information for field that isn't set yet */ - propvar.vt = VT_I2; - hr = IPropertyStoreCache_GetValue(propcache, &pkey, &propvar); - ok(hr == S_OK, "GetValue failed, hr=%x\n", hr); - ok(propvar.vt == VT_EMPTY, "expected VT_EMPTY, got %d\n", propvar.vt); - - state = 0xdeadbeef; - hr = IPropertyStoreCache_GetState(propcache, &pkey, &state); - ok(hr == TYPE_E_ELEMENTNOTFOUND, "GetState failed, hr=%x\n", hr); - ok(state == PSC_NORMAL, "expected PSC_NORMAL, got %d\n", state); - - propvar.vt = VT_I2; - state = 0xdeadbeef; - hr = IPropertyStoreCache_GetValueAndState(propcache, &pkey, &propvar, &state); - ok(hr == TYPE_E_ELEMENTNOTFOUND, "GetValueAndState failed, hr=%x\n", hr); - ok(propvar.vt == VT_EMPTY, "expected VT_EMPTY, got %d\n", propvar.vt); - ok(state == PSC_NORMAL, "expected PSC_NORMAL, got %d\n", state); - - /* Set state on an unset field */ - hr = IPropertyStoreCache_SetState(propcache, &pkey, PSC_NORMAL); - ok(hr == TYPE_E_ELEMENTNOTFOUND, "SetState failed, hr=%x\n", hr); - - /* Manipulate state on already set field */ - pkey.fmtid = PKEY_WineTest; - pkey.pid = 4; - - state = 0xdeadbeef; - hr = IPropertyStoreCache_GetState(propcache, &pkey, &state); - ok(hr == S_OK, "GetState failed, hr=%x\n", hr); - ok(state == PSC_NORMAL, "expected PSC_NORMAL, got %d\n", state); - - hr = IPropertyStoreCache_SetState(propcache, &pkey, 10); - ok(hr == S_OK, "SetState failed, hr=%x\n", hr); - - state = 0xdeadbeef; - hr = IPropertyStoreCache_GetState(propcache, &pkey, &state); - ok(hr == S_OK, "GetState failed, hr=%x\n", hr); - ok(state == 10, "expected 10, got %d\n", state); - - propvar.vt = VT_I4; - propvar.u.lVal = 12346; - hr = IPropertyStoreCache_SetValueAndState(propcache, &pkey, &propvar, 5); - ok(hr == S_OK, "SetValueAndState failed, hr=%x\n", hr); - - memset(&propvar, 0, sizeof(propvar)); - state = 0xdeadbeef; - hr = IPropertyStoreCache_GetValueAndState(propcache, &pkey, &propvar, &state); - ok(hr == S_OK, "GetValueAndState failed, hr=%x\n", hr); - ok(propvar.vt == VT_I4, "expected VT_I4, got %d\n", propvar.vt); - ok(propvar.u.lVal == 12346, "expected 12346, got %d\n", propvar.vt); - ok(state == 5, "expected 5, got %d\n", state); - - /* Set new field with state */ - pkey.fmtid = PKEY_WineTest; - pkey.pid = 8; - - propvar.vt = VT_I4; - propvar.u.lVal = 12347; - hr = IPropertyStoreCache_SetValueAndState(propcache, &pkey, &propvar, PSC_DIRTY); - ok(hr == S_OK, "SetValueAndState failed, hr=%x\n", hr); - - memset(&propvar, 0, sizeof(propvar)); - state = 0xdeadbeef; - hr = IPropertyStoreCache_GetValueAndState(propcache, &pkey, &propvar, &state); - ok(hr == S_OK, "GetValueAndState failed, hr=%x\n", hr); - ok(propvar.vt == VT_I4, "expected VT_I4, got %d\n", propvar.vt); - ok(propvar.u.lVal == 12347, "expected 12347, got %d\n", propvar.vt); - ok(state == PSC_DIRTY, "expected PSC_DIRTY, got %d\n", state); - - IPropertyStoreCache_Release(propcache); -} - -static void test_persistserialized(void) -{ - IPropertyStore *propstore; - IPersistSerializedPropStorage *serialized; - HRESULT hr; - SERIALIZEDPROPSTORAGE *result; - DWORD result_size; - - hr = CoCreateInstance(&CLSID_InMemoryPropertyStore, NULL, CLSCTX_INPROC_SERVER, - &IID_IPropertyStore, (void**)&propstore); - ok(hr == S_OK, "CoCreateInstance failed, hr=%x\n", hr); - - hr = IPropertyStore_QueryInterface(propstore, &IID_IPersistSerializedPropStorage, - (void**)&serialized); - todo_wine ok(hr == S_OK, "QueryInterface failed, hr=%x\n", hr); - - if (FAILED(hr)) - { - IPropertyStore_Release(propstore); - skip("IPersistSerializedPropStorage not supported\n"); - return; - } - - hr = IPersistSerializedPropStorage_GetPropertyStorage(serialized, NULL, &result_size); - ok(hr == E_POINTER, "GetPropertyStorage failed, hr=%x\n", hr); - - hr = IPersistSerializedPropStorage_GetPropertyStorage(serialized, &result, NULL); - ok(hr == E_POINTER, "GetPropertyStorage failed, hr=%x\n", hr); - - hr = IPersistSerializedPropStorage_GetPropertyStorage(serialized, &result, &result_size); - ok(hr == S_OK, "GetPropertyStorage failed, hr=%x\n", hr); - - if (SUCCEEDED(hr)) - { - ok(result_size == 0, "expected 0 bytes, got %i\n", result_size); - - CoTaskMemFree(result); - } - - hr = IPersistSerializedPropStorage_SetPropertyStorage(serialized, NULL, 4); - ok(hr == E_POINTER, "SetPropertyStorage failed, hr=%x\n", hr); - - hr = IPersistSerializedPropStorage_SetPropertyStorage(serialized, NULL, 0); - ok(hr == S_OK, "SetPropertyStorage failed, hr=%x\n", hr); - - hr = IPropertyStore_GetCount(propstore, &result_size); - ok(hr == S_OK, "GetCount failed, hr=%x\n", hr); - ok(result_size == 0, "expecting 0, got %d\n", result_size); - - IPropertyStore_Release(propstore); - IPersistSerializedPropStorage_Release(serialized); -} - -static void test_PSCreateMemoryPropertyStore(void) -{ - IPropertyStore *propstore, *propstore1; - IPersistSerializedPropStorage *serialized; - IPropertyStoreCache *propstorecache; - HRESULT hr; - - /* PSCreateMemoryPropertyStore(&IID_IPropertyStore, NULL); crashes */ - - hr = PSCreateMemoryPropertyStore(&IID_IPropertyStore, (void **)&propstore); - ok(hr == S_OK, "PSCreateMemoryPropertyStore failed: 0x%08x.\n", hr); - ok(propstore != NULL, "got %p.\n", propstore); - EXPECT_REF(propstore, 1); - - hr = PSCreateMemoryPropertyStore(&IID_IPersistSerializedPropStorage, (void **)&serialized); - todo_wine ok(hr == S_OK, "PSCreateMemoryPropertyStore failed: 0x%08x.\n", hr); - todo_wine ok(serialized != NULL, "got %p.\n", serialized); - EXPECT_REF(propstore, 1); - if(serialized) - { - EXPECT_REF(serialized, 1); - IPersistSerializedPropStorage_Release(serialized); - } - - hr = PSCreateMemoryPropertyStore(&IID_IPropertyStoreCache, (void **)&propstorecache); - ok(hr == S_OK, "PSCreateMemoryPropertyStore failed: 0x%08x.\n", hr); - ok(propstorecache != NULL, "got %p.\n", propstore); - ok(propstorecache != (IPropertyStoreCache *)propstore, "pointer are equal: %p, %p.\n", propstorecache, propstore); - EXPECT_REF(propstore, 1); - EXPECT_REF(propstorecache, 1); - - hr = PSCreateMemoryPropertyStore(&IID_IPropertyStore, (void **)&propstore1); - ok(hr == S_OK, "PSCreateMemoryPropertyStore failed: 0x%08x.\n", hr); - ok(propstore1 != NULL, "got %p.\n", propstore); - ok(propstore1 != propstore, "pointer are equal: %p, %p.\n", propstore1, propstore); - EXPECT_REF(propstore, 1); - EXPECT_REF(propstore1, 1); - EXPECT_REF(propstorecache, 1); - - IPropertyStore_Release(propstore1); - IPropertyStore_Release(propstore); - IPropertyStoreCache_Release(propstorecache); -} - -static void test_propertystore(void) -{ - IPropertyStore *propstore; - HRESULT hr; - PROPVARIANT propvar, ret_propvar; - PROPERTYKEY propkey; - DWORD count = 0; - - hr = PSCreateMemoryPropertyStore(&IID_IPropertyStore, (void **)&propstore); - ok(hr == S_OK, "PSCreateMemoryPropertyStore failed: 0x%08x.\n", hr); - ok(propstore != NULL, "got %p.\n", propstore); - - hr = IPropertyStore_GetCount(propstore, &count); - ok(hr == S_OK, "IPropertyStore_GetCount failed: 0x%08x.\n", hr); - ok(!count, "got wrong property count: %d, expected 0.\n", count); - - PropVariantInit(&propvar); - propvar.vt = VT_I4; - U(propvar).lVal = 123; - propkey.fmtid = DUMMY_GUID1; - propkey.pid = PID_FIRST_USABLE; - hr = IPropertyStore_SetValue(propstore, &propkey, &propvar); - ok(hr == S_OK, "IPropertyStore_SetValue failed: 0x%08x.\n", hr); - hr = IPropertyStore_Commit(propstore); - ok(hr == S_OK, "IPropertyStore_Commit failed: 0x%08x.\n", hr); - hr = IPropertyStore_GetCount(propstore, &count); - ok(hr == S_OK, "IPropertyStore_GetCount failed: 0x%08x.\n", hr); - ok(count == 1, "got wrong property count: %d, expected 1.\n", count); - PropVariantInit(&ret_propvar); - ret_propvar.vt = VT_I4; - hr = IPropertyStore_GetValue(propstore, &propkey, &ret_propvar); - ok(hr == S_OK, "IPropertyStore_GetValue failed: 0x%08x.\n", hr); - ok(ret_propvar.vt == VT_I4, "got wrong property type: %x.\n", ret_propvar.vt); - ok(U(ret_propvar).lVal == 123, "got wrong value: %d, expected 123.\n", U(ret_propvar).lVal); - PropVariantClear(&propvar); - PropVariantClear(&ret_propvar); - - PropVariantInit(&propvar); - propkey.fmtid = DUMMY_GUID1; - propkey.pid = PID_FIRST_USABLE; - hr = IPropertyStore_SetValue(propstore, &propkey, &propvar); - ok(hr == S_OK, "IPropertyStore_SetValue failed: 0x%08x.\n", hr); - hr = IPropertyStore_Commit(propstore); - ok(hr == S_OK, "IPropertyStore_Commit failed: 0x%08x.\n", hr); - hr = IPropertyStore_GetCount(propstore, &count); - ok(hr == S_OK, "IPropertyStore_GetCount failed: 0x%08x.\n", hr); - ok(count == 1, "got wrong property count: %d, expected 1.\n", count); - PropVariantInit(&ret_propvar); - hr = IPropertyStore_GetValue(propstore, &propkey, &ret_propvar); - ok(hr == S_OK, "IPropertyStore_GetValue failed: 0x%08x.\n", hr); - ok(ret_propvar.vt == VT_EMPTY, "got wrong property type: %x.\n", ret_propvar.vt); - ok(!U(ret_propvar).lVal, "got wrong value: %d, expected 0.\n", U(ret_propvar).lVal); - PropVariantClear(&propvar); - PropVariantClear(&ret_propvar); - - IPropertyStore_Release(propstore); -} - -START_TEST(propstore) -{ - CoInitialize(NULL); - - test_inmemorystore(); - test_persistserialized(); - test_PSCreateMemoryPropertyStore(); - test_propertystore(); - - CoUninitialize(); -} diff --git a/modules/rostests/winetests/propsys/propsys.c b/modules/rostests/winetests/propsys/propsys.c index 77ffe05f6d9..d63b9ddd3b2 100644 --- a/modules/rostests/winetests/propsys/propsys.c +++ b/modules/rostests/winetests/propsys/propsys.c @@ -3,6 +3,7 @@ * * Copyright 2006 Paul Vriens * Copyright 2010 Andrew Nguyen + * Copyright 2012 Vincent Povirk * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public @@ -24,12 +25,10 @@ #include <stdarg.h> #include <stdio.h> -#define NONAMELESSUNION - #include "windef.h" #include "winbase.h" -#include "objbase.h" #include "initguid.h" +#include "objbase.h" #include "propsys.h" #include "propvarutil.h" #include "strsafe.h" @@ -38,18 +37,23 @@ DEFINE_GUID(GUID_NULL,0,0,0,0,0,0,0,0,0,0,0); DEFINE_GUID(dummy_guid, 0xdeadbeef, 0xdead, 0xbeef, 0xde, 0xad, 0xbe, 0xef, 0xca, 0xfe, 0xba, 0xbe); DEFINE_GUID(expect_guid, 0x12345678, 0x1234, 0x1234, 0x12, 0x34, 0x12, 0x34, 0x56, 0x78, 0x90, 0x12); +DEFINE_GUID(PKEY_WineTest, 0x7b317433, 0xdfa3, 0x4c44, 0xad, 0x3e, 0x2f, 0x80, 0x4b, 0x90, 0xdb, 0xf4); +DEFINE_GUID(DUMMY_GUID1, 0x12345678, 0x1234,0x1234, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19); #define GUID_MEMBERS(g) {(g).Data1, (g).Data2, (g).Data3, {(g).Data4[0], (g).Data4[1], (g).Data4[2], (g).Data4[3], (g).Data4[4], (g).Data4[5], (g).Data4[6], (g).Data4[7]}} static const char topic[] = "wine topic"; static const WCHAR topicW[] = {'w','i','n','e',' ','t','o','p','i','c',0}; static const WCHAR emptyW[] = {0}; +static const WCHAR dummy_guid_str[] = L"{DEADBEEF-DEAD-BEEF-DEAD-BEEFCAFEBABE}"; -static int strcmp_wa(LPCWSTR strw, const char *stra) +#define EXPECT_REF(obj,ref) _expect_ref((IUnknown *)obj, ref, __LINE__) +static void _expect_ref(IUnknown *obj, ULONG ref, int line) { - CHAR buf[512]; - WideCharToMultiByte(CP_ACP, 0, strw, -1, buf, sizeof(buf), NULL, NULL); - return lstrcmpA(stra, buf); + ULONG rc; + IUnknown_AddRef(obj); + rc = IUnknown_Release(obj); + ok_(__FILE__,line)(rc == ref, "expected refcount %ld, got %ld\n", ref, rc); } static void test_PSStringFromPropertyKey(void) @@ -144,7 +148,7 @@ static void test_PSStringFromPropertyKey(void) testcases[i].cch); ok(ret == testcases[i].hr_expect || broken(testcases[i].hr_broken && ret == testcases[i].hr2), /* Vista/Win2k8 */ - "[%d] Expected PSStringFromPropertyKey to return 0x%08x, got 0x%08x\n", + "[%d] Expected PSStringFromPropertyKey to return 0x%08lx, got 0x%08lx\n", i, testcases[i].hr_expect, ret); if (testcases[i].psz) @@ -334,6 +338,9 @@ static void test_PSPropertyKeyFromString(void) static const WCHAR fmtid_normalpidW[] = {'{','1','2','3','4','5','6','7','8','-','1','2','3','4','-', '1','2','3','4','-','1','2','3','4','-', '1','2','3','4','5','6','7','8','9','0','1','2','}',' ','1','3','5','7','9',0}; + static const WCHAR fmtid_udigitW[] = {'{','1','2','3','4','5','6','7','8','-','1','2','3','4','-', + '1','2','3','4','-','1','2','3','4','-', + '1','2','3','4','5','6','7','8','9','0','1','2','}',' ','1','2','3',0x661,'5','7','9',0}; PROPERTYKEY out_init = {GUID_MEMBERS(dummy_guid), 0xdeadbeef}; PROPERTYKEY out; HRESULT ret; @@ -410,6 +417,7 @@ static void test_PSPropertyKeyFromString(void) {fmtid_commanegspcpidW, &out, S_OK, {GUID_MEMBERS(expect_guid), 0U}}, {fmtid_negcommapidW, &out, S_OK, {GUID_MEMBERS(expect_guid), 0}}, {fmtid_normalpidW, &out, S_OK, {GUID_MEMBERS(expect_guid), 13579}}, + {fmtid_udigitW, &out, S_OK, {GUID_MEMBERS(expect_guid), 123}}, }; int i; @@ -421,7 +429,7 @@ static void test_PSPropertyKeyFromString(void) ret = PSPropertyKeyFromString(testcases[i].pwzString, testcases[i].pkey); ok(ret == testcases[i].hr_expect, - "[%d] Expected PSPropertyKeyFromString to return 0x%08x, got 0x%08x\n", + "[%d] Expected PSPropertyKeyFromString to return 0x%08lx, got 0x%08lx\n", i, testcases[i].hr_expect, ret); if (testcases[i].pkey) @@ -430,7 +438,7 @@ static void test_PSPropertyKeyFromString(void) "[%d] Expected GUID %s, got %s\n", i, wine_dbgstr_guid(&testcases[i].pkey_expect.fmtid), wine_dbgstr_guid(&testcases[i].pkey->fmtid)); ok(testcases[i].pkey->pid == testcases[i].pkey_expect.pid, - "[%d] Expected property ID %u, got %u\n", + "[%d] Expected property ID %lu, got %lu\n", i, testcases[i].pkey_expect.pid, testcases[i].pkey->pid); } } @@ -443,13 +451,13 @@ static void test_PSRefreshPropertySchema(void) ret = PSRefreshPropertySchema(); todo_wine ok(ret == CO_E_NOTINITIALIZED, - "Expected PSRefreshPropertySchema to return CO_E_NOTINITIALIZED, got 0x%08x\n", ret); + "Expected PSRefreshPropertySchema to return CO_E_NOTINITIALIZED, got 0x%08lx\n", ret); CoInitialize(NULL); ret = PSRefreshPropertySchema(); ok(ret == S_OK, - "Expected PSRefreshPropertySchema to return S_OK, got 0x%08x\n", ret); + "Expected PSRefreshPropertySchema to return S_OK, got 0x%08lx\n", ret); CoUninitialize(); } @@ -463,14 +471,14 @@ static void test_InitPropVariantFromGUIDAsString(void) const struct { REFGUID guid; - const char *str; + const WCHAR *str; } testcases[] = { - {&IID_NULL, "{00000000-0000-0000-0000-000000000000}" }, - {&dummy_guid, "{DEADBEEF-DEAD-BEEF-DEAD-BEEFCAFEBABE}" }, + {&IID_NULL, L"{00000000-0000-0000-0000-000000000000}" }, + {&dummy_guid, dummy_guid_str }, }; hres = InitPropVariantFromGUIDAsString(NULL, &propvar); - ok(hres == E_FAIL, "InitPropVariantFromGUIDAsString returned %x\n", hres); + ok(hres == E_FAIL, "InitPropVariantFromGUIDAsString returned %lx\n", hres); if(0) { /* Returns strange data on Win7, crashes on older systems */ @@ -484,19 +492,19 @@ static void test_InitPropVariantFromGUIDAsString(void) for(i=0; i < ARRAY_SIZE(testcases); i++) { memset(&propvar, 0, sizeof(PROPVARIANT)); hres = InitPropVariantFromGUIDAsString(testcases[i].guid, &propvar); - ok(hres == S_OK, "%d) InitPropVariantFromGUIDAsString returned %x\n", i, hres); + ok(hres == S_OK, "%d) InitPropVariantFromGUIDAsString returned %lx\n", i, hres); ok(propvar.vt == VT_LPWSTR, "%d) propvar.vt = %d\n", i, propvar.vt); - ok(!strcmp_wa(propvar.u.pwszVal, testcases[i].str), "%d) propvar.u.pwszVal = %s\n", - i, wine_dbgstr_w(propvar.u.pwszVal)); - CoTaskMemFree(propvar.u.pwszVal); + ok(!lstrcmpW(propvar.pwszVal, testcases[i].str), "%d) propvar.pwszVal = %s\n", + i, wine_dbgstr_w(propvar.pwszVal)); + CoTaskMemFree(propvar.pwszVal); memset(&var, 0, sizeof(VARIANT)); hres = InitVariantFromGUIDAsString(testcases[i].guid, &var); - ok(hres == S_OK, "%d) InitVariantFromGUIDAsString returned %x\n", i, hres); + ok(hres == S_OK, "%d) InitVariantFromGUIDAsString returned %lx\n", i, hres); ok(V_VT(&var) == VT_BSTR, "%d) V_VT(&var) = %d\n", i, V_VT(&var)); ok(SysStringLen(V_BSTR(&var)) == 38, "SysStringLen returned %d\n", SysStringLen(V_BSTR(&var))); - ok(!strcmp_wa(V_BSTR(&var), testcases[i].str), "%d) V_BSTR(&var) = %s\n", + ok(!lstrcmpW(V_BSTR(&var), testcases[i].str), "%d) V_BSTR(&var) = %s\n", i, wine_dbgstr_w(V_BSTR(&var))); VariantClear(&var); } @@ -512,47 +520,47 @@ static void test_InitPropVariantFromBuffer(void) LONG size; hres = InitPropVariantFromBuffer(NULL, 0, &propvar); - ok(hres == S_OK, "InitPropVariantFromBuffer returned %x\n", hres); + ok(hres == S_OK, "InitPropVariantFromBuffer returned %lx\n", hres); ok(propvar.vt == (VT_VECTOR|VT_UI1), "propvar.vt = %d\n", propvar.vt); - ok(propvar.u.caub.cElems == 0, "cElems = %d\n", propvar.u.caub.cElems == 0); + ok(propvar.caub.cElems == 0, "cElems = %d\n", propvar.caub.cElems == 0); PropVariantClear(&propvar); hres = InitPropVariantFromBuffer(data_in, 4, &propvar); - ok(hres == S_OK, "InitPropVariantFromBuffer returned %x\n", hres); + ok(hres == S_OK, "InitPropVariantFromBuffer returned %lx\n", hres); ok(propvar.vt == (VT_VECTOR|VT_UI1), "propvar.vt = %d\n", propvar.vt); - ok(propvar.u.caub.cElems == 4, "cElems = %d\n", propvar.u.caub.cElems == 0); - ok(!memcmp(propvar.u.caub.pElems, data_in, 4), "Data inside array is incorrect\n"); + ok(propvar.caub.cElems == 4, "cElems = %d\n", propvar.caub.cElems == 0); + ok(!memcmp(propvar.caub.pElems, data_in, 4), "Data inside array is incorrect\n"); PropVariantClear(&propvar); hres = InitVariantFromBuffer(NULL, 0, &var); - ok(hres == S_OK, "InitVariantFromBuffer returned %x\n", hres); + ok(hres == S_OK, "InitVariantFromBuffer returned %lx\n", hres); ok(V_VT(&var) == (VT_ARRAY|VT_UI1), "V_VT(&var) = %d\n", V_VT(&var)); size = SafeArrayGetDim(V_ARRAY(&var)); - ok(size == 1, "SafeArrayGetDim returned %d\n", size); + ok(size == 1, "SafeArrayGetDim returned %ld\n", size); hres = SafeArrayGetLBound(V_ARRAY(&var), 1, &size); - ok(hres == S_OK, "SafeArrayGetLBound returned %x\n", hres); - ok(size == 0, "LBound = %d\n", size); + ok(hres == S_OK, "SafeArrayGetLBound returned %lx\n", hres); + ok(size == 0, "LBound = %ld\n", size); hres = SafeArrayGetUBound(V_ARRAY(&var), 1, &size); - ok(hres == S_OK, "SafeArrayGetUBound returned %x\n", hres); - ok(size == -1, "UBound = %d\n", size); + ok(hres == S_OK, "SafeArrayGetUBound returned %lx\n", hres); + ok(size == -1, "UBound = %ld\n", size); VariantClear(&var); hres = InitVariantFromBuffer(data_in, 4, &var); - ok(hres == S_OK, "InitVariantFromBuffer returned %x\n", hres); + ok(hres == S_OK, "InitVariantFromBuffer returned %lx\n", hres); ok(V_VT(&var) == (VT_ARRAY|VT_UI1), "V_VT(&var) = %d\n", V_VT(&var)); size = SafeArrayGetDim(V_ARRAY(&var)); - ok(size == 1, "SafeArrayGetDim returned %d\n", size); + ok(size == 1, "SafeArrayGetDim returned %ld\n", size); hres = SafeArrayGetLBound(V_ARRAY(&var), 1, &size); - ok(hres == S_OK, "SafeArrayGetLBound returned %x\n", hres); - ok(size == 0, "LBound = %d\n", size); + ok(hres == S_OK, "SafeArrayGetLBound returned %lx\n", hres); + ok(size == 0, "LBound = %ld\n", size); hres = SafeArrayGetUBound(V_ARRAY(&var), 1, &size); - ok(hres == S_OK, "SafeArrayGetUBound returned %x\n", hres); - ok(size == 3, "UBound = %d\n", size); + ok(hres == S_OK, "SafeArrayGetUBound returned %lx\n", hres); + ok(size == 3, "UBound = %ld\n", size); hres = SafeArrayAccessData(V_ARRAY(&var), &data_out); - ok(hres == S_OK, "SafeArrayAccessData failed %x\n", hres); + ok(hres == S_OK, "SafeArrayAccessData failed %lx\n", hres); ok(!memcmp(data_in, data_out, 4), "Data inside safe array is incorrect\n"); hres = SafeArrayUnaccessData(V_ARRAY(&var)); - ok(hres == S_OK, "SafeArrayUnaccessData failed %x\n", hres); + ok(hres == S_OK, "SafeArrayUnaccessData failed %lx\n", hres); VariantClear(&var); } @@ -564,67 +572,67 @@ static void test_PropVariantToGUID(void) HRESULT hres; hres = InitPropVariantFromGUIDAsString(&IID_NULL, &propvar); - ok(hres == S_OK, "InitPropVariantFromGUIDAsString failed %x\n", hres); + ok(hres == S_OK, "InitPropVariantFromGUIDAsString failed %lx\n", hres); hres = PropVariantToGUID(&propvar, &guid); - ok(hres == S_OK, "PropVariantToGUID failed %x\n", hres); + ok(hres == S_OK, "PropVariantToGUID failed %lx\n", hres); ok(IsEqualGUID(&IID_NULL, &guid), "incorrect GUID created: %s\n", wine_dbgstr_guid(&guid)); PropVariantClear(&propvar); hres = InitPropVariantFromGUIDAsString(&dummy_guid, &propvar); - ok(hres == S_OK, "InitPropVariantFromGUIDAsString failed %x\n", hres); + ok(hres == S_OK, "InitPropVariantFromGUIDAsString failed %lx\n", hres); hres = PropVariantToGUID(&propvar, &guid); - ok(hres == S_OK, "PropVariantToGUID failed %x\n", hres); + ok(hres == S_OK, "PropVariantToGUID failed %lx\n", hres); ok(IsEqualGUID(&dummy_guid, &guid), "incorrect GUID created: %s\n", wine_dbgstr_guid(&guid)); ok(propvar.vt == VT_LPWSTR, "incorrect PROPVARIANT type: %d\n", propvar.vt); - propvar.u.pwszVal[1] = 'd'; - propvar.u.pwszVal[2] = 'E'; - propvar.u.pwszVal[3] = 'a'; + propvar.pwszVal[1] = 'd'; + propvar.pwszVal[2] = 'E'; + propvar.pwszVal[3] = 'a'; hres = PropVariantToGUID(&propvar, &guid); - ok(hres == S_OK, "PropVariantToGUID failed %x\n", hres); + ok(hres == S_OK, "PropVariantToGUID failed %lx\n", hres); ok(IsEqualGUID(&dummy_guid, &guid), "incorrect GUID created: %s\n", wine_dbgstr_guid(&guid)); - propvar.u.pwszVal[1] = 'z'; + propvar.pwszVal[1] = 'z'; hres = PropVariantToGUID(&propvar, &guid); - ok(hres == E_INVALIDARG, "PropVariantToGUID returned %x\n", hres); + ok(hres == E_INVALIDARG, "PropVariantToGUID returned %lx\n", hres); PropVariantClear(&propvar); hres = InitVariantFromGUIDAsString(&IID_NULL, &var); - ok(hres == S_OK, "InitVariantFromGUIDAsString failed %x\n", hres); + ok(hres == S_OK, "InitVariantFromGUIDAsString failed %lx\n", hres); hres = VariantToGUID(&var, &guid); - ok(hres == S_OK, "VariantToGUID failed %x\n", hres); + ok(hres == S_OK, "VariantToGUID failed %lx\n", hres); ok(IsEqualGUID(&IID_NULL, &guid), "incorrect GUID created: %s\n", wine_dbgstr_guid(&guid)); VariantClear(&var); hres = InitVariantFromGUIDAsString(&dummy_guid, &var); - ok(hres == S_OK, "InitVariantFromGUIDAsString failed %x\n", hres); + ok(hres == S_OK, "InitVariantFromGUIDAsString failed %lx\n", hres); hres = VariantToGUID(&var, &guid); - ok(hres == S_OK, "VariantToGUID failed %x\n", hres); + ok(hres == S_OK, "VariantToGUID failed %lx\n", hres); ok(IsEqualGUID(&dummy_guid, &guid), "incorrect GUID created: %s\n", wine_dbgstr_guid(&guid)); ok(V_VT(&var) == VT_BSTR, "incorrect VARIANT type: %d\n", V_VT(&var)); V_BSTR(&var)[1] = 'z'; hres = VariantToGUID(&var, &guid); - ok(hres == E_FAIL, "VariantToGUID returned %x\n", hres); + ok(hres == E_FAIL, "VariantToGUID returned %lx\n", hres); V_BSTR(&var)[1] = 'd'; propvar.vt = V_VT(&var); - propvar.u.bstrVal = V_BSTR(&var); + propvar.bstrVal = V_BSTR(&var); V_VT(&var) = VT_EMPTY; hres = PropVariantToGUID(&propvar, &guid); - ok(hres == S_OK, "PropVariantToGUID failed %x\n", hres); + ok(hres == S_OK, "PropVariantToGUID failed %lx\n", hres); ok(IsEqualGUID(&dummy_guid, &guid), "incorrect GUID created: %s\n", wine_dbgstr_guid(&guid)); PropVariantClear(&propvar); memset(&guid, 0, sizeof(guid)); InitPropVariantFromCLSID(&dummy_guid, &propvar); hres = PropVariantToGUID(&propvar, &guid); - ok(hres == S_OK, "PropVariantToGUID failed %x\n", hres); + ok(hres == S_OK, "PropVariantToGUID failed %lx\n", hres); ok(IsEqualGUID(&dummy_guid, &guid), "incorrect GUID created: %s\n", wine_dbgstr_guid(&guid)); PropVariantClear(&propvar); } @@ -637,35 +645,46 @@ static void test_PropVariantToStringAlloc(void) prop.vt = VT_NULL; hres = PropVariantToStringAlloc(&prop, &str); - ok(hres == S_OK, "returned %x\n", hres); + ok(hres == S_OK, "returned %lx\n", hres); ok(!lstrcmpW(str, emptyW), "got %s\n", wine_dbgstr_w(str)); CoTaskMemFree(str); prop.vt = VT_LPSTR; - prop.u.pszVal = CoTaskMemAlloc(strlen(topic)+1); - strcpy(prop.u.pszVal, topic); + prop.pszVal = CoTaskMemAlloc(strlen(topic)+1); + strcpy(prop.pszVal, topic); hres = PropVariantToStringAlloc(&prop, &str); - ok(hres == S_OK, "returned %x\n", hres); + ok(hres == S_OK, "returned %lx\n", hres); ok(!lstrcmpW(str, topicW), "got %s\n", wine_dbgstr_w(str)); CoTaskMemFree(str); PropVariantClear(&prop); prop.vt = VT_EMPTY; hres = PropVariantToStringAlloc(&prop, &str); - ok(hres == S_OK, "returned %x\n", hres); + ok(hres == S_OK, "returned %lx\n", hres); ok(!lstrcmpW(str, emptyW), "got %s\n", wine_dbgstr_w(str)); CoTaskMemFree(str); + + prop.vt = VT_CLSID; + prop.puuid = (CLSID *)&dummy_guid; + hres = PropVariantToStringAlloc(&prop, &str); + ok(hres == S_OK, "PropVariantToStringAlloc returned %#lx.\n", hres); + ok(!wcscmp(str, dummy_guid_str), "Unexpected str %s.\n", debugstr_w(str)); + CoTaskMemFree(str); } -static void test_PropVariantCompare(void) +static void test_PropVariantCompareEx(void) { PROPVARIANT empty, null, emptyarray, i2_0, i2_2, i4_large, i4_largeneg, i4_2, str_2, str_02, str_b; PROPVARIANT clsid_null, clsid, clsid2, r4_0, r4_2, r8_0, r8_2; + PROPVARIANT ui4, ui4_large; + PROPVARIANT var1, var2; INT res; static const WCHAR str_2W[] = {'2', 0}; static const WCHAR str_02W[] = {'0', '2', 0}; static const WCHAR str_bW[] = {'b', 0}; SAFEARRAY emptysafearray; + unsigned char bytevector1[] = {1,2,3}; + unsigned char bytevector2[] = {4,5,6}; PropVariantInit(&empty); PropVariantInit(&null); @@ -681,7 +700,7 @@ static void test_PropVariantCompare(void) empty.vt = VT_EMPTY; null.vt = VT_NULL; emptyarray.vt = VT_ARRAY | VT_I4; - emptyarray.u.parray = &emptysafearray; + emptyarray.parray = &emptysafearray; emptysafearray.cDims = 1; emptysafearray.fFeatures = FADF_FIXEDSIZE; emptysafearray.cbElements = 4; @@ -690,35 +709,39 @@ static void test_PropVariantCompare(void) emptysafearray.rgsabound[0].cElements = 0; emptysafearray.rgsabound[0].lLbound = 0; i2_0.vt = VT_I2; - i2_0.u.iVal = 0; + i2_0.iVal = 0; i2_2.vt = VT_I2; - i2_2.u.iVal = 2; + i2_2.iVal = 2; i4_large.vt = VT_I4; - i4_large.u.lVal = 65536; + i4_large.lVal = 65536; i4_largeneg.vt = VT_I4; - i4_largeneg.u.lVal = -65536; + i4_largeneg.lVal = -65536; i4_2.vt = VT_I4; - i4_2.u.lVal = 2; + i4_2.lVal = 2; + ui4.vt = VT_UI4; + ui4.ulVal = 2; + ui4_large.vt = VT_UI4; + ui4_large.ulVal = 65536; str_2.vt = VT_BSTR; - str_2.u.bstrVal = SysAllocString(str_2W); + str_2.bstrVal = SysAllocString(str_2W); str_02.vt = VT_BSTR; - str_02.u.bstrVal = SysAllocString(str_02W); + str_02.bstrVal = SysAllocString(str_02W); str_b.vt = VT_BSTR; - str_b.u.bstrVal = SysAllocString(str_bW); + str_b.bstrVal = SysAllocString(str_bW); clsid_null.vt = VT_CLSID; - clsid_null.u.puuid = NULL; + clsid_null.puuid = NULL; clsid.vt = VT_CLSID; - clsid.u.puuid = (GUID *)&dummy_guid; + clsid.puuid = (GUID *)&dummy_guid; clsid2.vt = VT_CLSID; - clsid2.u.puuid = (GUID *)&GUID_NULL; + clsid2.puuid = (GUID *)&GUID_NULL; r4_0.vt = VT_R4; - r4_0.u.fltVal = 0.0f; + r4_0.fltVal = 0.0f; r4_2.vt = VT_R4; - r4_2.u.fltVal = 2.0f; + r4_2.fltVal = 2.0f; r8_0.vt = VT_R8; - r8_0.u.dblVal = 0.0; + r8_0.dblVal = 0.0; r8_2.vt = VT_R8; - r8_2.u.dblVal = 2.0; + r8_2.dblVal = 2.0; res = PropVariantCompareEx(&empty, &empty, 0, 0); ok(res == 0, "res=%i\n", res); @@ -747,6 +770,12 @@ static void test_PropVariantCompare(void) res = PropVariantCompareEx(&i2_0, &i2_2, 0, 0); ok(res == -1, "res=%i\n", res); + res = PropVariantCompareEx(&ui4, &ui4_large, 0, 0); + ok(res == -1, "res=%i\n", res); + + res = PropVariantCompareEx(&ui4_large, &ui4, 0, 0); + ok(res == 1, "res=%i\n", res); + /* Always return -1 if second value cannot be converted to first type */ res = PropVariantCompareEx(&i2_0, &i4_large, 0, 0); ok(res == -1, "res=%i\n", res); @@ -817,7 +846,7 @@ static void test_PropVariantCompare(void) /* VT_R4/VT_R8 */ res = PropVariantCompareEx(&r4_0, &r8_0, 0, 0); -todo_wine + todo_wine ok(res == 0, "res=%i\n", res); res = PropVariantCompareEx(&r4_0, &r4_0, 0, 0); @@ -838,9 +867,77 @@ todo_wine res = PropVariantCompareEx(&r8_2, &r8_0, 0, 0); ok(res == 1, "res=%i\n", res); - SysFreeString(str_2.u.bstrVal); - SysFreeString(str_02.u.bstrVal); - SysFreeString(str_b.u.bstrVal); + /* VT_VECTOR | VT_UI1 */ + var1.vt = VT_VECTOR | VT_UI1; + var1.caub.cElems = 1; + var1.caub.pElems = bytevector1; + var2.vt = VT_VECTOR | VT_UI1; + var2.caub.cElems = 1; + var2.caub.pElems = bytevector2; + + res = PropVariantCompareEx(&var1, &var2, 0, 0); + ok(res == -1, "res=%i\n", res); + + res = PropVariantCompareEx(&var2, &var1, 0, 0); + ok(res == 1, "res=%i\n", res); + + /* Vector length mismatch */ + var1.caub.cElems = 2; + res = PropVariantCompareEx(&var1, &var2, 0, 0); + ok(res == -1, "res=%i\n", res); + + res = PropVariantCompareEx(&var2, &var1, 0, 0); + ok(res == 1, "res=%i\n", res); + + var1.caub.pElems = bytevector2; + var2.caub.pElems = bytevector1; + res = PropVariantCompareEx(&var1, &var2, 0, 0); + ok(res == 1, "res=%i\n", res); + + var1.caub.pElems = bytevector1; + var2.caub.pElems = bytevector2; + + var1.caub.cElems = 1; + var2.caub.cElems = 2; + res = PropVariantCompareEx(&var1, &var2, 0, 0); + ok(res == -1, "res=%i\n", res); + + res = PropVariantCompareEx(&var2, &var1, 0, 0); + ok(res == 1, "res=%i\n", res); + + /* Length mismatch over same data */ + var1.caub.pElems = bytevector1; + var2.caub.pElems = bytevector1; + + res = PropVariantCompareEx(&var1, &var2, 0, 0); + ok(res == -1, "res=%i\n", res); + + res = PropVariantCompareEx(&var2, &var1, 0, 0); + ok(res == 1, "res=%i\n", res); + + var1.caub.cElems = 1; + var2.caub.cElems = 1; + res = PropVariantCompareEx(&var1, &var2, 0, 0); + ok(res == 0, "res=%i\n", res); + + var1.caub.cElems = 0; + res = PropVariantCompareEx(&var1, &var2, 0, PVCF_TREATEMPTYASGREATERTHAN); + ok(res == 1, "res=%i\n", res); + res = PropVariantCompareEx(&var2, &var1, 0, PVCF_TREATEMPTYASGREATERTHAN); + ok(res == -1, "res=%i\n", res); + + res = PropVariantCompareEx(&var1, &var2, 0, 0); + ok(res == -1, "res=%i\n", res); + res = PropVariantCompareEx(&var2, &var1, 0, 0); + ok(res == 1, "res=%i\n", res); + + var2.caub.cElems = 0; + res = PropVariantCompareEx(&var1, &var2, 0, 0); + ok(res == 0, "res=%i\n", res); + + SysFreeString(str_2.bstrVal); + SysFreeString(str_02.bstrVal); + SysFreeString(str_b.bstrVal); } static void test_intconversions(void) @@ -862,104 +959,113 @@ static void test_intconversions(void) PropVariantClear(&propvar); propvar.vt = VT_I8; - propvar.u.hVal.QuadPart = (ULONGLONG)1 << 63; + propvar.hVal.QuadPart = (ULONGLONG)1 << 63; hr = PropVariantToInt64(&propvar, &llval); - ok(hr == S_OK, "hr=%x\n", hr); + ok(hr == S_OK, "hr=%lx\n", hr); ok(llval == (ULONGLONG)1 << 63, "got wrong value %s\n", wine_dbgstr_longlong(llval)); hr = PropVariantToUInt64(&propvar, &ullval); - ok(hr == HRESULT_FROM_WIN32(ERROR_ARITHMETIC_OVERFLOW), "hr=%x\n", hr); + ok(hr == HRESULT_FROM_WIN32(ERROR_ARITHMETIC_OVERFLOW), "hr=%lx\n", hr); hr = PropVariantToInt32(&propvar, &lval); - ok(hr == HRESULT_FROM_WIN32(ERROR_ARITHMETIC_OVERFLOW), "hr=%x\n", hr); + ok(hr == HRESULT_FROM_WIN32(ERROR_ARITHMETIC_OVERFLOW), "hr=%lx\n", hr); hr = PropVariantToUInt32(&propvar, &ulval); - ok(hr == HRESULT_FROM_WIN32(ERROR_ARITHMETIC_OVERFLOW), "hr=%x\n", hr); + ok(hr == HRESULT_FROM_WIN32(ERROR_ARITHMETIC_OVERFLOW), "hr=%lx\n", hr); + + ulval = PropVariantToUInt32WithDefault(&propvar, 77); + ok(ulval == 77, "ulval=%lu\n", ulval); hr = PropVariantToInt16(&propvar, &sval); - ok(hr == HRESULT_FROM_WIN32(ERROR_ARITHMETIC_OVERFLOW), "hr=%x\n", hr); + ok(hr == HRESULT_FROM_WIN32(ERROR_ARITHMETIC_OVERFLOW), "hr=%lx\n", hr); hr = PropVariantToUInt16(&propvar, &usval); - ok(hr == HRESULT_FROM_WIN32(ERROR_ARITHMETIC_OVERFLOW), "hr=%x\n", hr); + ok(hr == HRESULT_FROM_WIN32(ERROR_ARITHMETIC_OVERFLOW), "hr=%lx\n", hr); propvar.vt = VT_UI8; - propvar.u.uhVal.QuadPart = 5; + propvar.uhVal.QuadPart = 5; hr = PropVariantToInt64(&propvar, &llval); - ok(hr == S_OK, "hr=%x\n", hr); + ok(hr == S_OK, "hr=%lx\n", hr); ok(llval == 5, "got wrong value %s\n", wine_dbgstr_longlong(llval)); hr = PropVariantToUInt64(&propvar, &ullval); - ok(hr == S_OK, "hr=%x\n", hr); + ok(hr == S_OK, "hr=%lx\n", hr); ok(ullval == 5, "got wrong value %s\n", wine_dbgstr_longlong(ullval)); hr = PropVariantToInt32(&propvar, &lval); - ok(hr == S_OK, "hr=%x\n", hr); - ok(lval == 5, "got wrong value %d\n", lval); + ok(hr == S_OK, "hr=%lx\n", hr); + ok(lval == 5, "got wrong value %ld\n", lval); hr = PropVariantToUInt32(&propvar, &ulval); - ok(hr == S_OK, "hr=%x\n", hr); - ok(ulval == 5, "got wrong value %d\n", ulval); + ok(hr == S_OK, "hr=%lx\n", hr); + ok(ulval == 5, "got wrong value %ld\n", ulval); + + ulval = PropVariantToUInt32WithDefault(&propvar, 77); + ok(ulval == 5, "got wrong value %lu\n", ulval); hr = PropVariantToInt16(&propvar, &sval); - ok(hr == S_OK, "hr=%x\n", hr); + ok(hr == S_OK, "hr=%lx\n", hr); ok(sval == 5, "got wrong value %d\n", sval); hr = PropVariantToUInt16(&propvar, &usval); - ok(hr == S_OK, "hr=%x\n", hr); + ok(hr == S_OK, "hr=%lx\n", hr); ok(usval == 5, "got wrong value %d\n", usval); propvar.vt = VT_I8; - propvar.u.hVal.QuadPart = -5; + propvar.hVal.QuadPart = -5; hr = PropVariantToInt64(&propvar, &llval); - ok(hr == S_OK, "hr=%x\n", hr); + ok(hr == S_OK, "hr=%lx\n", hr); ok(llval == -5, "got wrong value %s\n", wine_dbgstr_longlong(llval)); hr = PropVariantToUInt64(&propvar, &ullval); - ok(hr == HRESULT_FROM_WIN32(ERROR_ARITHMETIC_OVERFLOW), "hr=%x\n", hr); + ok(hr == HRESULT_FROM_WIN32(ERROR_ARITHMETIC_OVERFLOW), "hr=%lx\n", hr); hr = PropVariantToInt32(&propvar, &lval); - ok(hr == S_OK, "hr=%x\n", hr); - ok(lval == -5, "got wrong value %d\n", lval); + ok(hr == S_OK, "hr=%lx\n", hr); + ok(lval == -5, "got wrong value %ld\n", lval); hr = PropVariantToUInt32(&propvar, &ulval); - ok(hr == HRESULT_FROM_WIN32(ERROR_ARITHMETIC_OVERFLOW), "hr=%x\n", hr); + ok(hr == HRESULT_FROM_WIN32(ERROR_ARITHMETIC_OVERFLOW), "hr=%lx\n", hr); + + ulval = PropVariantToUInt32WithDefault(&propvar, 77); + ok(ulval == 77, "ulval=%lu\n", ulval); hr = PropVariantToInt16(&propvar, &sval); - ok(hr == S_OK, "hr=%x\n", hr); + ok(hr == S_OK, "hr=%lx\n", hr); ok(sval == -5, "got wrong value %d\n", sval); hr = PropVariantToUInt16(&propvar, &usval); - ok(hr == HRESULT_FROM_WIN32(ERROR_ARITHMETIC_OVERFLOW), "hr=%x\n", hr); + ok(hr == HRESULT_FROM_WIN32(ERROR_ARITHMETIC_OVERFLOW), "hr=%lx\n", hr); propvar.vt = VT_UI4; - propvar.u.ulVal = 6; + propvar.ulVal = 6; hr = PropVariantToInt64(&propvar, &llval); - ok(hr == S_OK, "hr=%x\n", hr); + ok(hr == S_OK, "hr=%lx\n", hr); ok(llval == 6, "got wrong value %s\n", wine_dbgstr_longlong(llval)); propvar.vt = VT_I4; - propvar.u.lVal = -6; + propvar.lVal = -6; hr = PropVariantToInt64(&propvar, &llval); - ok(hr == S_OK, "hr=%x\n", hr); + ok(hr == S_OK, "hr=%lx\n", hr); ok(llval == -6, "got wrong value %s\n", wine_dbgstr_longlong(llval)); propvar.vt = VT_UI2; - propvar.u.uiVal = 7; + propvar.uiVal = 7; hr = PropVariantToInt64(&propvar, &llval); - ok(hr == S_OK, "hr=%x\n", hr); + ok(hr == S_OK, "hr=%lx\n", hr); ok(llval == 7, "got wrong value %s\n", wine_dbgstr_longlong(llval)); propvar.vt = VT_I2; - propvar.u.iVal = -7; + propvar.iVal = -7; hr = PropVariantToInt64(&propvar, &llval); - ok(hr == S_OK, "hr=%x\n", hr); + ok(hr == S_OK, "hr=%lx\n", hr); ok(llval == -7, "got wrong value %s\n", wine_dbgstr_longlong(llval)); } @@ -982,195 +1088,195 @@ static void test_PropVariantToBoolean(void) /* VT_BOOL */ propvar.vt = VT_BOOL; - propvar.u.boolVal = VARIANT_FALSE; + propvar.boolVal = VARIANT_FALSE; val = TRUE; hr = PropVariantToBoolean(&propvar, &val); - ok(hr == S_OK, "Unexpected hr %#x.\n", hr); + ok(hr == S_OK, "Unexpected hr %#lx.\n", hr); ok(val == FALSE, "Unexpected value %d\n", val); propvar.vt = VT_BOOL; - propvar.u.boolVal = 1; + propvar.boolVal = 1; val = TRUE; hr = PropVariantToBoolean(&propvar, &val); - ok(hr == S_OK, "Unexpected hr %#x.\n", hr); + ok(hr == S_OK, "Unexpected hr %#lx.\n", hr); ok(val == FALSE, "Unexpected value %d\n", val); propvar.vt = VT_BOOL; - propvar.u.boolVal = VARIANT_TRUE; + propvar.boolVal = VARIANT_TRUE; val = FALSE; hr = PropVariantToBoolean(&propvar, &val); - ok(hr == S_OK, "Unexpected hr %#x.\n", hr); + ok(hr == S_OK, "Unexpected hr %#lx.\n", hr); ok(val == TRUE, "Unexpected value %d\n", val); /* VT_EMPTY */ propvar.vt = VT_EMPTY; - propvar.u.boolVal = VARIANT_TRUE; + propvar.boolVal = VARIANT_TRUE; val = TRUE; hr = PropVariantToBoolean(&propvar, &val); - ok(hr == S_OK, "Unexpected hr %#x.\n", hr); + ok(hr == S_OK, "Unexpected hr %#lx.\n", hr); ok(val == FALSE, "Unexpected value %d\n", val); /* test integer conversion */ propvar.vt = VT_I4; - propvar.u.lVal = 0; + propvar.lVal = 0; val = TRUE; hr = PropVariantToBoolean(&propvar, &val); - ok(hr == S_OK, "Unexpected hr %#x.\n", hr); + ok(hr == S_OK, "Unexpected hr %#lx.\n", hr); ok(val == FALSE, "Unexpected value %d\n", val); propvar.vt = VT_I4; - propvar.u.lVal = 1; + propvar.lVal = 1; val = FALSE; hr = PropVariantToBoolean(&propvar, &val); - ok(hr == S_OK, "Unexpected hr %#x.\n", hr); + ok(hr == S_OK, "Unexpected hr %#lx.\n", hr); ok(val == TRUE, "Unexpected value %d\n", val); propvar.vt = VT_I4; - propvar.u.lVal = 67; + propvar.lVal = 67; val = FALSE; hr = PropVariantToBoolean(&propvar, &val); - ok(hr == S_OK, "Unexpected hr %#x.\n", hr); + ok(hr == S_OK, "Unexpected hr %#lx.\n", hr); ok(val == TRUE, "Unexpected value %d\n", val); propvar.vt = VT_I4; - propvar.u.lVal = -67; + propvar.lVal = -67; val = FALSE; hr = PropVariantToBoolean(&propvar, &val); - ok(hr == S_OK, "Unexpected hr %#x.\n", hr); + ok(hr == S_OK, "Unexpected hr %#lx.\n", hr); ok(val == TRUE, "Unexpected value %d\n", val); /* test string conversion */ propvar.vt = VT_LPWSTR; - propvar.u.pwszVal = str_0; + propvar.pwszVal = str_0; val = TRUE; hr = PropVariantToBoolean(&propvar, &val); - ok(hr == S_OK, "Unexpected hr %#x.\n", hr); + ok(hr == S_OK, "Unexpected hr %#lx.\n", hr); ok(val == FALSE, "Unexpected value %d\n", val); propvar.vt = VT_LPWSTR; - propvar.u.pwszVal = str_1; + propvar.pwszVal = str_1; val = FALSE; hr = PropVariantToBoolean(&propvar, &val); - ok(hr == S_OK, "Unexpected hr %#x.\n", hr); + ok(hr == S_OK, "Unexpected hr %#lx.\n", hr); ok(val == TRUE, "Unexpected value %d\n", val); propvar.vt = VT_LPWSTR; - propvar.u.pwszVal = str_7; + propvar.pwszVal = str_7; val = FALSE; hr = PropVariantToBoolean(&propvar, &val); - ok(hr == S_OK, "Unexpected hr %#x.\n", hr); + ok(hr == S_OK, "Unexpected hr %#lx.\n", hr); ok(val == TRUE, "Unexpected value %d\n", val); propvar.vt = VT_LPWSTR; - propvar.u.pwszVal = str_n7; + propvar.pwszVal = str_n7; val = FALSE; hr = PropVariantToBoolean(&propvar, &val); - ok(hr == S_OK, "Unexpected hr %#x.\n", hr); + ok(hr == S_OK, "Unexpected hr %#lx.\n", hr); ok(val == TRUE, "Unexpected value %d\n", val); propvar.vt = VT_LPWSTR; - propvar.u.pwszVal = str_true; + propvar.pwszVal = str_true; val = FALSE; hr = PropVariantToBoolean(&propvar, &val); - ok(hr == S_OK, "Unexpected hr %#x.\n", hr); + ok(hr == S_OK, "Unexpected hr %#lx.\n", hr); ok(val == TRUE, "Unexpected value %d\n", val); propvar.vt = VT_LPWSTR; - propvar.u.pwszVal = str_true_case; + propvar.pwszVal = str_true_case; val = FALSE; hr = PropVariantToBoolean(&propvar, &val); - ok(hr == S_OK, "Unexpected hr %#x.\n", hr); + ok(hr == S_OK, "Unexpected hr %#lx.\n", hr); ok(val == TRUE, "Unexpected value %d\n", val); propvar.vt = VT_LPWSTR; - propvar.u.pwszVal = str_true2; + propvar.pwszVal = str_true2; val = FALSE; hr = PropVariantToBoolean(&propvar, &val); - ok(hr == S_OK, "Unexpected hr %#x.\n", hr); + ok(hr == S_OK, "Unexpected hr %#lx.\n", hr); ok(val == TRUE, "Unexpected value %d\n", val); propvar.vt = VT_LPWSTR; - propvar.u.pwszVal = str_false; + propvar.pwszVal = str_false; val = TRUE; hr = PropVariantToBoolean(&propvar, &val); - ok(hr == S_OK, "Unexpected hr %#x.\n", hr); + ok(hr == S_OK, "Unexpected hr %#lx.\n", hr); ok(val == FALSE, "Unexpected value %d\n", val); propvar.vt = VT_LPWSTR; - propvar.u.pwszVal = str_false2; + propvar.pwszVal = str_false2; val = TRUE; hr = PropVariantToBoolean(&propvar, &val); - ok(hr == S_OK, "Unexpected hr %#x.\n", hr); + ok(hr == S_OK, "Unexpected hr %#lx.\n", hr); ok(val == FALSE, "Unexpected value %d\n", val); propvar.vt = VT_LPWSTR; - propvar.u.pwszVal = str_true_space; + propvar.pwszVal = str_true_space; val = TRUE; hr = PropVariantToBoolean(&propvar, &val); - ok(hr == DISP_E_TYPEMISMATCH, "Unexpected hr %#x.\n", hr); + ok(hr == DISP_E_TYPEMISMATCH, "Unexpected hr %#lx.\n", hr); ok(val == FALSE, "Unexpected value %d\n", val); propvar.vt = VT_LPWSTR; - propvar.u.pwszVal = str_yes; + propvar.pwszVal = str_yes; val = TRUE; hr = PropVariantToBoolean(&propvar, &val); - ok(hr == DISP_E_TYPEMISMATCH, "Unexpected hr %#x.\n", hr); + ok(hr == DISP_E_TYPEMISMATCH, "Unexpected hr %#lx.\n", hr); ok(val == FALSE, "Unexpected value %d\n", val); propvar.vt = VT_LPWSTR; - propvar.u.pwszVal = NULL; + propvar.pwszVal = NULL; val = TRUE; hr = PropVariantToBoolean(&propvar, &val); - ok(hr == DISP_E_TYPEMISMATCH, "Unexpected hr %#x.\n", hr); + ok(hr == DISP_E_TYPEMISMATCH, "Unexpected hr %#lx.\n", hr); ok(val == FALSE, "Unexpected value %d\n", val); /* VT_LPSTR */ propvar.vt = VT_LPSTR; - propvar.u.pszVal = (char *)"#TruE#"; + propvar.pszVal = (char *)"#TruE#"; val = TRUE; hr = PropVariantToBoolean(&propvar, &val); - ok(hr == DISP_E_TYPEMISMATCH, "Unexpected hr %#x.\n", hr); + ok(hr == DISP_E_TYPEMISMATCH, "Unexpected hr %#lx.\n", hr); ok(val == FALSE, "Unexpected value %d\n", val); propvar.vt = VT_LPSTR; - propvar.u.pszVal = (char *)"#TRUE#"; + propvar.pszVal = (char *)"#TRUE#"; val = FALSE; hr = PropVariantToBoolean(&propvar, &val); - ok(hr == S_OK, "Unexpected hr %#x.\n", hr); + ok(hr == S_OK, "Unexpected hr %#lx.\n", hr); ok(val == TRUE, "Unexpected value %d\n", val); propvar.vt = VT_LPSTR; - propvar.u.pszVal = (char *)"tRUe"; + propvar.pszVal = (char *)"tRUe"; val = FALSE; hr = PropVariantToBoolean(&propvar, &val); - ok(hr == S_OK, "Unexpected hr %#x.\n", hr); + ok(hr == S_OK, "Unexpected hr %#lx.\n", hr); ok(val == TRUE, "Unexpected value %d\n", val); propvar.vt = VT_LPSTR; - propvar.u.pszVal = (char *)"#FALSE#"; + propvar.pszVal = (char *)"#FALSE#"; val = TRUE; hr = PropVariantToBoolean(&propvar, &val); - ok(hr == S_OK, "Unexpected hr %#x.\n", hr); + ok(hr == S_OK, "Unexpected hr %#lx.\n", hr); ok(val == FALSE, "Unexpected value %d\n", val); propvar.vt = VT_LPSTR; - propvar.u.pszVal = (char *)"fALSe"; + propvar.pszVal = (char *)"fALSe"; val = TRUE; hr = PropVariantToBoolean(&propvar, &val); - ok(hr == S_OK, "Unexpected hr %#x.\n", hr); + ok(hr == S_OK, "Unexpected hr %#lx.\n", hr); ok(val == FALSE, "Unexpected value %d\n", val); propvar.vt = VT_LPSTR; - propvar.u.pszVal = (char *)"1"; + propvar.pszVal = (char *)"1"; val = FALSE; hr = PropVariantToBoolean(&propvar, &val); - ok(hr == S_OK, "Unexpected hr %#x.\n", hr); + ok(hr == S_OK, "Unexpected hr %#lx.\n", hr); ok(val == TRUE, "Unexpected value %d\n", val); propvar.vt = VT_LPSTR; - propvar.u.pszVal = (char *)"-1"; + propvar.pszVal = (char *)"-1"; hr = PropVariantToBoolean(&propvar, &val); - ok(hr == S_OK, "Unexpected hr %#x.\n", hr); + ok(hr == S_OK, "Unexpected hr %#lx.\n", hr); ok(val == TRUE, "Unexpected value %d\n", val); } @@ -1195,83 +1301,88 @@ static void test_PropVariantToStringWithDefault(void) ok(result == default_value, "Unexpected value %s\n", wine_dbgstr_w(result)); propvar.vt = VT_BOOL; - propvar.u.boolVal = VARIANT_TRUE; + propvar.boolVal = VARIANT_TRUE; result = PropVariantToStringWithDefault(&propvar, default_value); ok(result == default_value, "Unexpected value %s\n", wine_dbgstr_w(result)); propvar.vt = VT_I4; - propvar.u.lVal = 15; + propvar.lVal = 15; result = PropVariantToStringWithDefault(&propvar, default_value); ok(result == default_value, "Unexpected value %s\n", wine_dbgstr_w(result)); + propvar.vt = VT_CLSID; + propvar.puuid = (CLSID *)&dummy_guid; + result = PropVariantToStringWithDefault(&propvar, default_value); + ok(result == default_value, "Unexpected value %s.\n", debugstr_w(result)); + /* VT_LPWSTR */ propvar.vt = VT_LPWSTR; - propvar.u.pwszVal = NULL; + propvar.pwszVal = NULL; result = PropVariantToStringWithDefault(&propvar, default_value); ok(result == default_value, "Unexpected value %s\n", wine_dbgstr_w(result)); propvar.vt = VT_LPWSTR; - propvar.u.pwszVal = wstr_empty; + propvar.pwszVal = wstr_empty; result = PropVariantToStringWithDefault(&propvar, default_value); ok(result == wstr_empty, "Unexpected value %s\n", wine_dbgstr_w(result)); propvar.vt = VT_LPWSTR; - propvar.u.pwszVal = wstr_space; + propvar.pwszVal = wstr_space; result = PropVariantToStringWithDefault(&propvar, default_value); ok(result == wstr_space, "Unexpected value %s\n", wine_dbgstr_w(result)); propvar.vt = VT_LPWSTR; - propvar.u.pwszVal = wstr_test2; + propvar.pwszVal = wstr_test2; result = PropVariantToStringWithDefault(&propvar, default_value); ok(result == wstr_test2, "Unexpected value %s\n", wine_dbgstr_w(result)); /* VT_LPSTR */ propvar.vt = VT_LPSTR; - propvar.u.pszVal = NULL; + propvar.pszVal = NULL; result = PropVariantToStringWithDefault(&propvar, default_value); ok(result == default_value, "Unexpected value %s\n", wine_dbgstr_w(result)); propvar.vt = VT_LPSTR; - propvar.u.pszVal = str_empty; + propvar.pszVal = str_empty; result = PropVariantToStringWithDefault(&propvar, default_value); ok(result == default_value, "Unexpected value %s\n", wine_dbgstr_w(result)); propvar.vt = VT_LPSTR; - propvar.u.pszVal = str_space; + propvar.pszVal = str_space; result = PropVariantToStringWithDefault(&propvar, default_value); ok(result == default_value, "Unexpected value %s\n", wine_dbgstr_w(result)); propvar.vt = VT_LPSTR; - propvar.u.pszVal = str_test2; + propvar.pszVal = str_test2; result = PropVariantToStringWithDefault(&propvar, default_value); ok(result == default_value, "Unexpected value %s\n", wine_dbgstr_w(result)); /* VT_BSTR */ propvar.vt = VT_BSTR; - propvar.u.bstrVal = NULL; + propvar.bstrVal = NULL; result = PropVariantToStringWithDefault(&propvar, default_value); ok(!lstrcmpW(result, wstr_empty), "Unexpected value %s\n", wine_dbgstr_w(result)); propvar.vt = VT_BSTR; - propvar.u.bstrVal = SysAllocString(wstr_empty); + propvar.bstrVal = SysAllocString(wstr_empty); result = PropVariantToStringWithDefault(&propvar, default_value); ok(!lstrcmpW(result, wstr_empty), "Unexpected value %s\n", wine_dbgstr_w(result)); - SysFreeString(propvar.u.bstrVal); + SysFreeString(propvar.bstrVal); propvar.vt = VT_BSTR; - propvar.u.bstrVal = SysAllocString(wstr_space); + propvar.bstrVal = SysAllocString(wstr_space); result = PropVariantToStringWithDefault(&propvar, default_value); ok(!lstrcmpW(result, wstr_space), "Unexpected value %s\n", wine_dbgstr_w(result)); - SysFreeString(propvar.u.bstrVal); + SysFreeString(propvar.bstrVal); propvar.vt = VT_BSTR; - propvar.u.bstrVal = SysAllocString(wstr_test2); + propvar.bstrVal = SysAllocString(wstr_test2); result = PropVariantToStringWithDefault(&propvar, default_value); ok(!lstrcmpW(result, wstr_test2), "Unexpected value %s\n", wine_dbgstr_w(result)); - SysFreeString(propvar.u.bstrVal); + SysFreeString(propvar.bstrVal); } static void test_PropVariantChangeType_LPWSTR(void) @@ -1283,29 +1394,29 @@ static void test_PropVariantChangeType_LPWSTR(void) src.vt = VT_NULL; hr = PropVariantChangeType(&dest, &src, 0, VT_LPWSTR); - ok(hr == S_OK, "hr=%x\n", hr); + ok(hr == S_OK, "hr=%lx\n", hr); ok(dest.vt == VT_LPWSTR, "got %d\n", dest.vt); - ok(!lstrcmpW(dest.u.pwszVal, emptyW), "got %s\n", wine_dbgstr_w(dest.u.pwszVal)); + ok(!lstrcmpW(dest.pwszVal, emptyW), "got %s\n", wine_dbgstr_w(dest.pwszVal)); PropVariantClear(&dest); PropVariantClear(&src); src.vt = VT_LPSTR; - src.u.pszVal = CoTaskMemAlloc(strlen(topic)+1); - strcpy(src.u.pszVal, topic); + src.pszVal = CoTaskMemAlloc(strlen(topic)+1); + strcpy(src.pszVal, topic); hr = PropVariantChangeType(&dest, &src, 0, VT_LPWSTR); - ok(hr == S_OK, "hr=%x\n", hr); + ok(hr == S_OK, "hr=%lx\n", hr); ok(dest.vt == VT_LPWSTR, "got %d\n", dest.vt); - ok(!lstrcmpW(dest.u.pwszVal, topicW), "got %s\n", wine_dbgstr_w(dest.u.pwszVal)); + ok(!lstrcmpW(dest.pwszVal, topicW), "got %s\n", wine_dbgstr_w(dest.pwszVal)); PropVariantClear(&dest); PropVariantClear(&src); src.vt = VT_LPWSTR; - src.u.pwszVal = CoTaskMemAlloc( (lstrlenW(topicW)+1) * sizeof(WCHAR)); - lstrcpyW(src.u.pwszVal, topicW); + src.pwszVal = CoTaskMemAlloc( (lstrlenW(topicW)+1) * sizeof(WCHAR)); + lstrcpyW(src.pwszVal, topicW); hr = PropVariantChangeType(&dest, &src, 0, VT_LPWSTR); - ok(hr == S_OK, "hr=%x\n", hr); + ok(hr == S_OK, "hr=%lx\n", hr); ok(dest.vt == VT_LPWSTR, "got %d\n", dest.vt); - ok(!lstrcmpW(dest.u.pwszVal, topicW), "got %s\n", wine_dbgstr_w(dest.u.pwszVal)); + ok(!lstrcmpW(dest.pwszVal, topicW), "got %s\n", wine_dbgstr_w(dest.pwszVal)); PropVariantClear(&dest); PropVariantClear(&src); } @@ -1318,13 +1429,42 @@ static void test_InitPropVariantFromCLSID(void) memset(&propvar, 0, sizeof(propvar)); propvar.vt = VT_I4; - propvar.u.lVal = 15; + propvar.lVal = 15; memset(&clsid, 0xcc, sizeof(clsid)); hr = InitPropVariantFromCLSID(&clsid, &propvar); - ok(hr == S_OK, "Unexpected hr %#x.\n", hr); + ok(hr == S_OK, "Unexpected hr %#lx.\n", hr); ok(propvar.vt == VT_CLSID, "Unexpected type %d.\n", propvar.vt); - ok(IsEqualGUID(propvar.u.puuid, &clsid), "Unexpected puuid value.\n"); + ok(IsEqualGUID(propvar.puuid, &clsid), "Unexpected puuid value.\n"); + PropVariantClear(&propvar); +} + +static void test_InitPropVariantFromStringVector(void) +{ + static const WCHAR *strs[2] = { L"abc", L"def" }; + PROPVARIANT propvar; + HRESULT hr; + + memset(&propvar, 0, sizeof(propvar)); + propvar.vt = VT_I4; + propvar.lVal = 15; + + hr = InitPropVariantFromStringVector(NULL, 0, &propvar); + ok(hr == S_OK, "Unexpected hr %#lx.\n", hr); + ok(propvar.vt == (VT_LPWSTR|VT_VECTOR), "Unexpected type %#x.\n", propvar.vt); + ok(!propvar.calpwstr.cElems, "Unexpected number of elements.\n"); + ok(!!propvar.calpwstr.pElems, "Unexpected vector pointer.\n"); + PropVariantClear(&propvar); + + hr = InitPropVariantFromStringVector(strs, 2, &propvar); + ok(hr == S_OK, "Unexpected hr %#lx.\n", hr); + ok(propvar.vt == (VT_LPWSTR|VT_VECTOR), "Unexpected type %#x.\n", propvar.vt); + ok(propvar.calpwstr.cElems == 2, "Unexpected number of elements.\n"); + ok(!!propvar.calpwstr.pElems, "Unexpected vector pointer.\n"); + ok(propvar.calpwstr.pElems[0] != strs[0], "Unexpected string pointer.\n"); + ok(!wcscmp(propvar.calpwstr.pElems[0], strs[0]), "Unexpected string %s.\n", debugstr_w(propvar.calpwstr.pElems[0])); + ok(propvar.calpwstr.pElems[1] != strs[1], "Unexpected string pointer.\n"); + ok(!wcscmp(propvar.calpwstr.pElems[1], strs[1]), "Unexpected string %s.\n", debugstr_w(propvar.calpwstr.pElems[1])); PropVariantClear(&propvar); } @@ -1336,141 +1476,262 @@ static void test_PropVariantToDouble(void) PropVariantInit(&propvar); propvar.vt = VT_R8; - propvar.u.dblVal = 15.0; + propvar.dblVal = 15.0; hr = PropVariantToDouble(&propvar, &value); - ok(hr == S_OK, "PropVariantToDouble failed: 0x%08x.\n", hr); + ok(hr == S_OK, "PropVariantToDouble failed: 0x%08lx.\n", hr); ok(value == 15.0, "Unexpected value: %f.\n", value); PropVariantClear(&propvar); propvar.vt = VT_I4; - propvar.u.lVal = 123; + propvar.lVal = 123; hr = PropVariantToDouble(&propvar, &value); - ok(hr == S_OK, "PropVariantToDouble failed: 0x%08x.\n", hr); + ok(hr == S_OK, "PropVariantToDouble failed: 0x%08lx.\n", hr); ok(value == 123.0, "Unexpected value: %f.\n", value); PropVariantClear(&propvar); propvar.vt = VT_I4; - propvar.u.lVal = -256; + propvar.lVal = -256; hr = PropVariantToDouble(&propvar, &value); - ok(hr == S_OK, "PropVariantToDouble failed: 0x%08x.\n", hr); + ok(hr == S_OK, "PropVariantToDouble failed: 0x%08lx.\n", hr); ok(value == -256, "Unexpected value: %f\n", value); PropVariantClear(&propvar); propvar.vt = VT_I8; - propvar.u.lVal = 65536; + propvar.lVal = 65536; hr = PropVariantToDouble(&propvar, &value); - ok(hr == S_OK, "PropVariantToDouble failed: 0x%08x.\n", hr); + ok(hr == S_OK, "PropVariantToDouble failed: 0x%08lx.\n", hr); ok(value == 65536.0, "Unexpected value: %f.\n", value); PropVariantClear(&propvar); propvar.vt = VT_I8; - propvar.u.lVal = -321; + propvar.lVal = -321; hr = PropVariantToDouble(&propvar, &value); - ok(hr == S_OK, "PropVariantToDouble failed: 0x%08x.\n", hr); + ok(hr == S_OK, "PropVariantToDouble failed: 0x%08lx.\n", hr); ok(value == 4294966975.0, "Unexpected value: %f.\n", value); PropVariantClear(&propvar); propvar.vt = VT_UI4; - propvar.u.ulVal = 6; + propvar.ulVal = 6; hr = PropVariantToDouble(&propvar, &value); - ok(hr == S_OK, "PropVariantToDouble failed: 0x%08x.\n", hr); + ok(hr == S_OK, "PropVariantToDouble failed: 0x%08lx.\n", hr); ok(value == 6.0, "Unexpected value: %f.\n", value); PropVariantClear(&propvar); propvar.vt = VT_UI8; - propvar.u.uhVal.QuadPart = 8; + propvar.uhVal.QuadPart = 8; hr = PropVariantToDouble(&propvar, &value); - ok(hr == S_OK, "PropVariantToDouble failed: 0x%08x.\n", hr); + ok(hr == S_OK, "PropVariantToDouble failed: 0x%08lx.\n", hr); ok(value == 8.0, "Unexpected value: %f.\n", value); } static void test_PropVariantToString(void) { - PROPVARIANT propvar; + static WCHAR stringW[] = L"Wine"; static CHAR string[] = "Wine"; - static WCHAR stringW[] = {'W','i','n','e',0}; WCHAR bufferW[256] = {0}; + PROPVARIANT propvar; HRESULT hr; PropVariantInit(&propvar); propvar.vt = VT_EMPTY; - U(propvar).pwszVal = stringW; + propvar.pwszVal = stringW; bufferW[0] = 65; hr = PropVariantToString(&propvar, bufferW, 0); - ok(hr == E_INVALIDARG, "PropVariantToString should fail: 0x%08x.\n", hr); + ok(hr == E_INVALIDARG, "PropVariantToString should fail: 0x%08lx.\n", hr); ok(!bufferW[0], "got wrong string: \"%s\".\n", wine_dbgstr_w(bufferW)); memset(bufferW, 0, sizeof(bufferW)); PropVariantClear(&propvar); PropVariantInit(&propvar); propvar.vt = VT_EMPTY; - U(propvar).pwszVal = stringW; + propvar.pwszVal = stringW; bufferW[0] = 65; hr = PropVariantToString(&propvar, bufferW, ARRAY_SIZE(bufferW)); - ok(hr == S_OK, "PropVariantToString failed: 0x%08x.\n", hr); + ok(hr == S_OK, "PropVariantToString failed: 0x%08lx.\n", hr); ok(!bufferW[0], "got wrong string: \"%s\".\n", wine_dbgstr_w(bufferW)); memset(bufferW, 0, sizeof(bufferW)); PropVariantClear(&propvar); PropVariantInit(&propvar); propvar.vt = VT_NULL; - U(propvar).pwszVal = stringW; + propvar.pwszVal = stringW; bufferW[0] = 65; hr = PropVariantToString(&propvar, bufferW, ARRAY_SIZE(bufferW)); - ok(hr == S_OK, "PropVariantToString failed: 0x%08x.\n", hr); + ok(hr == S_OK, "PropVariantToString failed: 0x%08lx.\n", hr); ok(!bufferW[0], "got wrong string: \"%s\".\n", wine_dbgstr_w(bufferW)); memset(bufferW, 0, sizeof(bufferW)); PropVariantClear(&propvar); PropVariantInit(&propvar); propvar.vt = VT_I4; - U(propvar).lVal = 22; + propvar.lVal = 22; hr = PropVariantToString(&propvar, bufferW, ARRAY_SIZE(bufferW)); - todo_wine ok(hr == S_OK, "PropVariantToString failed: 0x%08x.\n", hr); - todo_wine ok(!strcmp_wa(bufferW, "22"), "got wrong string: \"%s\".\n", wine_dbgstr_w(bufferW)); + todo_wine ok(hr == S_OK, "PropVariantToString failed: 0x%08lx.\n", hr); + todo_wine ok(!lstrcmpW(bufferW, L"22"), "got wrong string: \"%s\".\n", wine_dbgstr_w(bufferW)); memset(bufferW, 0, sizeof(bufferW)); PropVariantClear(&propvar); PropVariantInit(&propvar); propvar.vt = VT_LPWSTR; - U(propvar).pwszVal = stringW; + propvar.pwszVal = stringW; hr = PropVariantToString(&propvar, bufferW, ARRAY_SIZE(bufferW)); - ok(hr == S_OK, "PropVariantToString failed: 0x%08x.\n", hr); + ok(hr == S_OK, "PropVariantToString failed: 0x%08lx.\n", hr); ok(!lstrcmpW(bufferW, stringW), "got wrong string: \"%s\".\n", wine_dbgstr_w(bufferW)); memset(bufferW, 0, sizeof(bufferW)); PropVariantInit(&propvar); propvar.vt = VT_LPSTR; - U(propvar).pszVal = string; + propvar.pszVal = string; hr = PropVariantToString(&propvar, bufferW, ARRAY_SIZE(bufferW)); - ok(hr == S_OK, "PropVariantToString failed: 0x%08x.\n", hr); + ok(hr == S_OK, "PropVariantToString failed: 0x%08lx.\n", hr); ok(!lstrcmpW(bufferW, stringW), "got wrong string: \"%s\".\n", wine_dbgstr_w(bufferW)); memset(bufferW, 0, sizeof(bufferW)); + /* Result string will be truncated if output buffer is too small. */ + PropVariantInit(&propvar); + propvar.vt = VT_UI4; + propvar.lVal = 123456; + hr = PropVariantToString(&propvar, bufferW, 4); + todo_wine + ok(hr == STRSAFE_E_INSUFFICIENT_BUFFER, "PropVariantToString returned: %#lx.\n", hr); + todo_wine + ok(!wcscmp(bufferW, L"123"), "Unexpected string %s.\n", debugstr_w(bufferW)); + memset(bufferW, 0, sizeof(bufferW)); + PropVariantInit(&propvar); propvar.vt = VT_LPWSTR; - U(propvar).pwszVal = stringW; + propvar.pwszVal = stringW; hr = PropVariantToString(&propvar, bufferW, 4); - ok(hr == STRSAFE_E_INSUFFICIENT_BUFFER, "PropVariantToString returned: 0x%08x.\n", hr); - ok(!memcmp(bufferW, stringW, 4), "got wrong string.\n"); + ok(hr == STRSAFE_E_INSUFFICIENT_BUFFER, "PropVariantToString returned: 0x%08lx.\n", hr); + ok(!wcscmp(bufferW, L"Win"), "Unexpected string %s.\n", debugstr_w(bufferW)); memset(bufferW, 0, sizeof(bufferW)); PropVariantInit(&propvar); propvar.vt = VT_LPSTR; - U(propvar).pszVal = string; + propvar.pszVal = string; hr = PropVariantToString(&propvar, bufferW, 4); - ok(hr == STRSAFE_E_INSUFFICIENT_BUFFER, "PropVariantToString returned: 0x%08x.\n", hr); - ok(!memcmp(bufferW, stringW, 4), "got wrong string.\n"); + ok(hr == STRSAFE_E_INSUFFICIENT_BUFFER, "PropVariantToString returned: 0x%08lx.\n", hr); + ok(!wcscmp(bufferW, L"Win"), "Unexpected string %s.\n", debugstr_w(bufferW)); memset(bufferW, 0, sizeof(bufferW)); PropVariantInit(&propvar); propvar.vt = VT_BSTR; - propvar.u.bstrVal = SysAllocString(stringW); + propvar.bstrVal = SysAllocString(stringW); hr = PropVariantToString(&propvar, bufferW, ARRAY_SIZE(bufferW)); - ok(hr == S_OK, "PropVariantToString failed: 0x%08x.\n", hr); + ok(hr == S_OK, "PropVariantToString failed: 0x%08lx.\n", hr); ok(!lstrcmpW(bufferW, stringW), "got wrong string: \"%s\".\n", wine_dbgstr_w(bufferW)); memset(bufferW, 0, sizeof(bufferW)); - SysFreeString(propvar.u.bstrVal); + SysFreeString(propvar.bstrVal); + + PropVariantInit(&propvar); + propvar.vt = VT_CLSID; + propvar.puuid = (CLSID *)&dummy_guid; + hr = PropVariantToString(&propvar, bufferW, ARRAY_SIZE(bufferW)); + ok(hr == S_OK, "PropVariantToString returned %#lx.\n", hr); + ok(!wcscmp(bufferW, dummy_guid_str), "Unexpected string %s.\n", debugstr_w(bufferW)); + memset(bufferW, 0, sizeof(bufferW)); +} + +#define check_PropVariantToBSTR(type, member, value, expect_str) \ +do \ +{ \ + PROPVARIANT check_propvar_ = {.vt = (type), .member = (value)}; \ + HRESULT check_hr_; \ + BSTR check_bstr_; \ + \ + check_hr_ = PropVariantToBSTR(&check_propvar_, &check_bstr_); \ + ok_(__FILE__, __LINE__)(check_hr_ == S_OK, \ + "PropVariantToBSTR returned %#lx.\n", check_hr_); \ + \ + if (check_hr_ == S_OK) \ + { \ + ok_(__FILE__, __LINE__)(!wcscmp(check_bstr_, (expect_str)), \ + "Unexpected bstr %s.\n", debugstr_w(check_bstr_)); \ + SysFreeString(check_bstr_); \ + } \ +} while (0) + +static void test_PropVariantToBSTR(void) +{ + unsigned char test_bytes[] = {1, 20, 30, 4}; + WCHAR test_bstr[] = {'a', 0, 'b', 0, 'c'}; + PROPVARIANT propvar; + UINT length; + HRESULT hr; + BSTR bstr; + + if (0) /* Crashes. */ + { + hr = PropVariantToBSTR(&propvar, NULL); + hr = PropVariantToBSTR(NULL, &bstr); + } + + todo_wine + { + check_PropVariantToBSTR(VT_I1, cVal, -123, L"-123"); + check_PropVariantToBSTR(VT_I2, iVal, -456, L"-456"); + check_PropVariantToBSTR(VT_I4, lVal, -789, L"-789"); + check_PropVariantToBSTR(VT_I8, hVal.QuadPart, -101112, L"-101112"); + check_PropVariantToBSTR(VT_UI1, bVal, 0xcd, L"205"); + check_PropVariantToBSTR(VT_UI2, uiVal, 0xdead, L"57005"); + check_PropVariantToBSTR(VT_UI4, ulVal, 0xdeadbeef, L"3735928559"); + check_PropVariantToBSTR(VT_UI8, uhVal.QuadPart, 0xdeadbeefdeadbeef, L"16045690984833335023"); + check_PropVariantToBSTR(VT_BOOL, boolVal, TRUE, L"1"); + check_PropVariantToBSTR(VT_R4, fltVal, 0.125f, L"0.125"); + check_PropVariantToBSTR(VT_R8, dblVal, 0.456, L"0.456"); + } + check_PropVariantToBSTR(VT_CLSID, puuid, (CLSID *)&dummy_guid, dummy_guid_str); + check_PropVariantToBSTR(VT_LPSTR, pszVal, (char *)topic, topicW); + check_PropVariantToBSTR(VT_LPWSTR, pwszVal, (WCHAR *)topicW, topicW); + + PropVariantInit(&propvar); + propvar.vt = VT_FILETIME; + propvar.filetime.dwLowDateTime = 0xdead; + propvar.filetime.dwHighDateTime = 0xbeef; + hr = PropVariantToBSTR(&propvar, &bstr); + todo_wine + ok(hr == S_OK, "PropVariantToBSTR returned %#lx.\n", hr); + if (hr == S_OK) + { + ok(!wcscmp(bstr, L"1601/08/31:23:29:30.651"), "Unexpected bstr %s.\n", debugstr_w(bstr)); + SysFreeString(bstr); + } + + PropVariantInit(&propvar); + propvar.vt = VT_DATE; + propvar.date = 123.123f; + hr = PropVariantToBSTR(&propvar, &bstr); + todo_wine + ok(hr == S_OK, "PropVariantToBSTR returned %#lx.\n", hr); + if (hr == S_OK) + { + ok(!wcscmp(bstr, L"1900/05/02:02:57:07.000"), "Unexpected bstr %s.\n", debugstr_w(bstr)); + SysFreeString(bstr); + } + + PropVariantInit(&propvar); + propvar.vt = VT_VECTOR | VT_I1; + propvar.caub.cElems = ARRAY_SIZE(test_bytes); + propvar.caub.pElems = test_bytes; + hr = PropVariantToBSTR(&propvar, &bstr); + todo_wine + ok(hr == S_OK, "PropVariantToBSTR returned %#lx.\n", hr); + if (hr == S_OK) + { + ok(!wcscmp(bstr, L"1; 20; 30; 4"), "Unexpected bstr %s.\n", debugstr_w(bstr)); + SysFreeString(bstr); + } + + PropVariantInit(&propvar); + propvar.vt = VT_BSTR; + propvar.bstrVal = SysAllocStringLen(test_bstr, ARRAY_SIZE(test_bstr)); + hr = PropVariantToBSTR(&propvar, &bstr); + ok(hr == S_OK, "PropVariantToBSTR returned %#lx.\n", hr); + length = SysStringLen(bstr); + ok(length == wcslen(test_bstr), "Unexpected length %u.\n", length); + ok(!wcscmp(bstr, test_bstr), "Unexpected bstr %s.", debugstr_wn(bstr, ARRAY_SIZE(test_bstr))); + SysFreeString(bstr); + PropVariantClear(&propvar); } static void test_PropVariantToBuffer(void) @@ -1482,35 +1743,35 @@ static void test_PropVariantToBuffer(void) SAFEARRAY *sa; SAFEARRAYBOUND sabound; void *pdata; - UINT8 buffer[256]; + UINT8 buffer[256] = {0}; hr = InitPropVariantFromBuffer(data, 10, &propvar); - ok(hr == S_OK, "InitPropVariantFromBuffer failed 0x%08x.\n", hr); + ok(hr == S_OK, "InitPropVariantFromBuffer failed 0x%08lx.\n", hr); hr = PropVariantToBuffer(&propvar, NULL, 0); /* crash when cb isn't zero */ - ok(hr == S_OK, "PropVariantToBuffer failed: 0x%08x.\n", hr); + ok(hr == S_OK, "PropVariantToBuffer failed: 0x%08lx.\n", hr); PropVariantClear(&propvar); hr = InitPropVariantFromBuffer(data, 10, &propvar); - ok(hr == S_OK, "InitPropVariantFromBuffer failed 0x%08x.\n", hr); + ok(hr == S_OK, "InitPropVariantFromBuffer failed 0x%08lx.\n", hr); hr = PropVariantToBuffer(&propvar, buffer, 10); - ok(hr == S_OK, "PropVariantToBuffer failed: 0x%08x.\n", hr); + ok(hr == S_OK, "PropVariantToBuffer failed: 0x%08lx.\n", hr); ok(!memcmp(buffer, data, 10) && !buffer[10], "got wrong buffer.\n"); memset(buffer, 0, sizeof(buffer)); PropVariantClear(&propvar); hr = InitPropVariantFromBuffer(data, 10, &propvar); - ok(hr == S_OK, "InitPropVariantFromBuffer failed 0x%08x.\n", hr); + ok(hr == S_OK, "InitPropVariantFromBuffer failed 0x%08lx.\n", hr); buffer[0] = 99; hr = PropVariantToBuffer(&propvar, buffer, 11); - ok(hr == E_FAIL, "PropVariantToBuffer returned: 0x%08x.\n", hr); + ok(hr == E_FAIL, "PropVariantToBuffer returned: 0x%08lx.\n", hr); ok(buffer[0] == 99, "got wrong buffer.\n"); memset(buffer, 0, sizeof(buffer)); PropVariantClear(&propvar); hr = InitPropVariantFromBuffer(data, 10, &propvar); - ok(hr == S_OK, "InitPropVariantFromBuffer failed 0x%08x.\n", hr); + ok(hr == S_OK, "InitPropVariantFromBuffer failed 0x%08lx.\n", hr); hr = PropVariantToBuffer(&propvar, buffer, 9); - ok(hr == S_OK, "PropVariantToBuffer failed: 0x%08x.\n", hr); + ok(hr == S_OK, "PropVariantToBuffer failed: 0x%08lx.\n", hr); ok(!memcmp(buffer, data, 9) && !buffer[9], "got wrong buffer.\n"); memset(buffer, 0, sizeof(buffer)); PropVariantClear(&propvar); @@ -1523,14 +1784,14 @@ static void test_PropVariantToBuffer(void) sa = SafeArrayCreate(VT_UI1, 1, &sabound); ok(sa != NULL, "SafeArrayCreate failed.\n"); hr = SafeArrayAccessData(sa, &pdata); - ok(hr == S_OK, "SafeArrayAccessData failed: 0x%08x.\n", hr); + ok(hr == S_OK, "SafeArrayAccessData failed: 0x%08lx.\n", hr); memcpy(pdata, data, sizeof(data)); hr = SafeArrayUnaccessData(sa); - ok(hr == S_OK, "SafeArrayUnaccessData failed: 0x%08x.\n", hr); - U(propvar).parray = sa; + ok(hr == S_OK, "SafeArrayUnaccessData failed: 0x%08lx.\n", hr); + propvar.parray = sa; buffer[0] = 99; hr = PropVariantToBuffer(&propvar, buffer, 11); - todo_wine ok(hr == E_FAIL, "PropVariantToBuffer returned: 0x%08x.\n", hr); + todo_wine ok(hr == E_FAIL, "PropVariantToBuffer returned: 0x%08lx.\n", hr); ok(buffer[0] == 99, "got wrong buffer.\n"); memset(buffer, 0, sizeof(buffer)); PropVariantClear(&propvar); @@ -1543,24 +1804,24 @@ static void test_PropVariantToBuffer(void) sa = SafeArrayCreate(VT_UI1, 1, &sabound); ok(sa != NULL, "SafeArrayCreate failed.\n"); hr = SafeArrayAccessData(sa, &pdata); - ok(hr == S_OK, "SafeArrayAccessData failed: 0x%08x.\n", hr); + ok(hr == S_OK, "SafeArrayAccessData failed: 0x%08lx.\n", hr); memcpy(pdata, data, sizeof(data)); hr = SafeArrayUnaccessData(sa); - ok(hr == S_OK, "SafeArrayUnaccessData failed: 0x%08x.\n", hr); - U(propvar).parray = sa; + ok(hr == S_OK, "SafeArrayUnaccessData failed: 0x%08lx.\n", hr); + propvar.parray = sa; hr = PropVariantToBuffer(&propvar, buffer, sizeof(data)); - todo_wine ok(hr == S_OK, "PropVariantToBuffer failed: 0x%08x.\n", hr); + todo_wine ok(hr == S_OK, "PropVariantToBuffer failed: 0x%08lx.\n", hr); todo_wine ok(!memcmp(buffer, data, 10) && !buffer[10], "got wrong buffer.\n"); memset(buffer, 0, sizeof(buffer)); PropVariantClear(&propvar); PropVariantInit(&propvar); propvar.vt = VT_VECTOR|VT_I1; - U(propvar).caub.pElems = CoTaskMemAlloc(sizeof(data_int8)); - U(propvar).caub.cElems = sizeof(data_int8); - memcpy(U(propvar).caub.pElems, data_int8, sizeof(data_int8)); + propvar.caub.pElems = CoTaskMemAlloc(sizeof(data_int8)); + propvar.caub.cElems = sizeof(data_int8); + memcpy(propvar.caub.pElems, data_int8, sizeof(data_int8)); hr = PropVariantToBuffer(&propvar, buffer, sizeof(data_int8)); - ok(hr == E_INVALIDARG, "PropVariantToBuffer failed: 0x%08x.\n", hr); + ok(hr == E_INVALIDARG, "PropVariantToBuffer failed: 0x%08lx.\n", hr); PropVariantClear(&propvar); PropVariantInit(&propvar); @@ -1571,32 +1832,829 @@ static void test_PropVariantToBuffer(void) sa = SafeArrayCreate(VT_I1, 1, &sabound); ok(sa != NULL, "SafeArrayCreate failed.\n"); hr = SafeArrayAccessData(sa, &pdata); - ok(hr == S_OK, "SafeArrayAccessData failed: 0x%08x.\n", hr); + ok(hr == S_OK, "SafeArrayAccessData failed: 0x%08lx.\n", hr); memcpy(pdata, data_int8, sizeof(data_int8)); hr = SafeArrayUnaccessData(sa); - ok(hr == S_OK, "SafeArrayUnaccessData failed: 0x%08x.\n", hr); - U(propvar).parray = sa; + ok(hr == S_OK, "SafeArrayUnaccessData failed: 0x%08lx.\n", hr); + propvar.parray = sa; hr = PropVariantToBuffer(&propvar, buffer, sizeof(data_int8)); - ok(hr == E_INVALIDARG, "PropVariantToBuffer failed: 0x%08x.\n", hr); + ok(hr == E_INVALIDARG, "PropVariantToBuffer failed: 0x%08lx.\n", hr); + PropVariantClear(&propvar); +} + +static void test_inmemorystore(void) +{ + IPropertyStoreCache *propcache; + HRESULT hr; + PROPERTYKEY pkey; + PROPVARIANT propvar; + DWORD count; + PSC_STATE state; + + CoInitialize(NULL); + + hr = CoCreateInstance(&CLSID_InMemoryPropertyStore, NULL, CLSCTX_INPROC_SERVER, + &IID_IPropertyStoreCache, (void**)&propcache); + ok(hr == S_OK, "CoCreateInstance failed, hr=%lx\n", hr); + + if (FAILED(hr)) + { + win_skip("CLSID_InMemoryPropertyStore not supported\n"); + CoUninitialize(); + return; + } + + hr = IPropertyStoreCache_GetCount(propcache, NULL); + ok(hr == E_POINTER, "GetCount failed, hr=%lx\n", hr); + + hr = IPropertyStoreCache_GetCount(propcache, &count); + ok(hr == S_OK, "GetCount failed, hr=%lx\n", hr); + ok(count == 0, "GetCount returned %li, expected 0\n", count); + + hr = IPropertyStoreCache_Commit(propcache); + ok(hr == S_OK, "Commit failed, hr=%lx\n", hr); + + hr = IPropertyStoreCache_Commit(propcache); + ok(hr == S_OK, "Commit failed, hr=%lx\n", hr); + + hr = IPropertyStoreCache_GetAt(propcache, 0, &pkey); + ok(hr == E_INVALIDARG, "GetAt failed, hr=%lx\n", hr); + + pkey.fmtid = PKEY_WineTest; + pkey.pid = 4; + + memset(&propvar, 0, sizeof(propvar)); + propvar.vt = VT_I4; + propvar.lVal = 12345; + + if (0) + { + /* Crashes on Windows 7 */ + hr = IPropertyStoreCache_SetValue(propcache, NULL, &propvar); + ok(hr == E_POINTER, "SetValue failed, hr=%lx\n", hr); + + hr = IPropertyStoreCache_SetValue(propcache, &pkey, NULL); + ok(hr == E_POINTER, "SetValue failed, hr=%lx\n", hr); + } + + hr = IPropertyStoreCache_SetValue(propcache, &pkey, &propvar); + ok(hr == S_OK, "SetValue failed, hr=%lx\n", hr); + + hr = IPropertyStoreCache_GetCount(propcache, &count); + ok(hr == S_OK, "GetCount failed, hr=%lx\n", hr); + ok(count == 1, "GetCount returned %li, expected 0\n", count); + + memset(&pkey, 0, sizeof(pkey)); + + hr = IPropertyStoreCache_GetAt(propcache, 0, &pkey); + ok(hr == S_OK, "GetAt failed, hr=%lx\n", hr); + ok(IsEqualGUID(&pkey.fmtid, &PKEY_WineTest), "got wrong pkey\n"); + ok(pkey.pid == 4, "got pid of %li, expected 4\n", pkey.pid); + + pkey.fmtid = PKEY_WineTest; + pkey.pid = 4; + + memset(&propvar, 0, sizeof(propvar)); + + if (0) + { + /* Crashes on Windows 7 */ + hr = IPropertyStoreCache_GetValue(propcache, NULL, &propvar); + ok(hr == E_POINTER, "GetValue failed, hr=%lx\n", hr); + } + + hr = IPropertyStoreCache_GetValue(propcache, &pkey, NULL); + ok(hr == E_POINTER, "GetValue failed, hr=%lx\n", hr); + + hr = IPropertyStoreCache_GetValue(propcache, &pkey, &propvar); + ok(hr == S_OK, "GetValue failed, hr=%lx\n", hr); + ok(propvar.vt == VT_I4, "expected VT_I4, got %d\n", propvar.vt); + ok(propvar.lVal == 12345, "expected 12345, got %ld\n", propvar.lVal); + + pkey.fmtid = PKEY_WineTest; + pkey.pid = 10; + + /* Get information for field that isn't set yet */ + propvar.vt = VT_I2; + hr = IPropertyStoreCache_GetValue(propcache, &pkey, &propvar); + ok(hr == S_OK, "GetValue failed, hr=%lx\n", hr); + ok(propvar.vt == VT_EMPTY, "expected VT_EMPTY, got %d\n", propvar.vt); + + state = 0xdeadbeef; + hr = IPropertyStoreCache_GetState(propcache, &pkey, &state); + ok(hr == TYPE_E_ELEMENTNOTFOUND, "GetState failed, hr=%lx\n", hr); + ok(state == PSC_NORMAL, "expected PSC_NORMAL, got %d\n", state); + + propvar.vt = VT_I2; + state = 0xdeadbeef; + hr = IPropertyStoreCache_GetValueAndState(propcache, &pkey, &propvar, &state); + ok(hr == TYPE_E_ELEMENTNOTFOUND, "GetValueAndState failed, hr=%lx\n", hr); + ok(propvar.vt == VT_EMPTY, "expected VT_EMPTY, got %d\n", propvar.vt); + ok(state == PSC_NORMAL, "expected PSC_NORMAL, got %d\n", state); + + /* Set state on an unset field */ + hr = IPropertyStoreCache_SetState(propcache, &pkey, PSC_NORMAL); + ok(hr == TYPE_E_ELEMENTNOTFOUND, "SetState failed, hr=%lx\n", hr); + + /* Manipulate state on already set field */ + pkey.fmtid = PKEY_WineTest; + pkey.pid = 4; + + state = 0xdeadbeef; + hr = IPropertyStoreCache_GetState(propcache, &pkey, &state); + ok(hr == S_OK, "GetState failed, hr=%lx\n", hr); + ok(state == PSC_NORMAL, "expected PSC_NORMAL, got %d\n", state); + + hr = IPropertyStoreCache_SetState(propcache, &pkey, 10); + ok(hr == S_OK, "SetState failed, hr=%lx\n", hr); + + state = 0xdeadbeef; + hr = IPropertyStoreCache_GetState(propcache, &pkey, &state); + ok(hr == S_OK, "GetState failed, hr=%lx\n", hr); + ok(state == 10, "expected 10, got %d\n", state); + + propvar.vt = VT_I4; + propvar.lVal = 12346; + hr = IPropertyStoreCache_SetValueAndState(propcache, &pkey, &propvar, 5); + ok(hr == S_OK, "SetValueAndState failed, hr=%lx\n", hr); + + memset(&propvar, 0, sizeof(propvar)); + state = 0xdeadbeef; + hr = IPropertyStoreCache_GetValueAndState(propcache, &pkey, &propvar, &state); + ok(hr == S_OK, "GetValueAndState failed, hr=%lx\n", hr); + ok(propvar.vt == VT_I4, "expected VT_I4, got %d\n", propvar.vt); + ok(propvar.lVal == 12346, "expected 12346, got %d\n", propvar.vt); + ok(state == 5, "expected 5, got %d\n", state); + + /* Set new field with state */ + pkey.fmtid = PKEY_WineTest; + pkey.pid = 8; + + propvar.vt = VT_I4; + propvar.lVal = 12347; + hr = IPropertyStoreCache_SetValueAndState(propcache, &pkey, &propvar, PSC_DIRTY); + ok(hr == S_OK, "SetValueAndState failed, hr=%lx\n", hr); + + memset(&propvar, 0, sizeof(propvar)); + state = 0xdeadbeef; + hr = IPropertyStoreCache_GetValueAndState(propcache, &pkey, &propvar, &state); + ok(hr == S_OK, "GetValueAndState failed, hr=%lx\n", hr); + ok(propvar.vt == VT_I4, "expected VT_I4, got %d\n", propvar.vt); + ok(propvar.lVal == 12347, "expected 12347, got %d\n", propvar.vt); + ok(state == PSC_DIRTY, "expected PSC_DIRTY, got %d\n", state); + + IPropertyStoreCache_Release(propcache); + + CoUninitialize(); +} + +static void test_persistserialized(void) +{ + IPropertyStore *propstore; + IPersistSerializedPropStorage *serialized; + HRESULT hr; + SERIALIZEDPROPSTORAGE *result; + DWORD result_size; + + CoInitialize(NULL); + + hr = CoCreateInstance(&CLSID_InMemoryPropertyStore, NULL, CLSCTX_INPROC_SERVER, + &IID_IPropertyStore, (void**)&propstore); + ok(hr == S_OK, "CoCreateInstance failed, hr=%lx\n", hr); + + hr = IPropertyStore_QueryInterface(propstore, &IID_IPersistSerializedPropStorage, + (void**)&serialized); + todo_wine ok(hr == S_OK, "QueryInterface failed, hr=%lx\n", hr); + + if (FAILED(hr)) + { + IPropertyStore_Release(propstore); + skip("IPersistSerializedPropStorage not supported\n"); + CoUninitialize(); + return; + } + + hr = IPersistSerializedPropStorage_GetPropertyStorage(serialized, NULL, &result_size); + ok(hr == E_POINTER, "GetPropertyStorage failed, hr=%lx\n", hr); + + hr = IPersistSerializedPropStorage_GetPropertyStorage(serialized, &result, NULL); + ok(hr == E_POINTER, "GetPropertyStorage failed, hr=%lx\n", hr); + + hr = IPersistSerializedPropStorage_GetPropertyStorage(serialized, &result, &result_size); + ok(hr == S_OK, "GetPropertyStorage failed, hr=%lx\n", hr); + + if (SUCCEEDED(hr)) + { + ok(result_size == 0, "expected 0 bytes, got %li\n", result_size); + + CoTaskMemFree(result); + } + + hr = IPersistSerializedPropStorage_SetPropertyStorage(serialized, NULL, 4); + ok(hr == E_POINTER, "SetPropertyStorage failed, hr=%lx\n", hr); + + hr = IPersistSerializedPropStorage_SetPropertyStorage(serialized, NULL, 0); + ok(hr == S_OK, "SetPropertyStorage failed, hr=%lx\n", hr); + + hr = IPropertyStore_GetCount(propstore, &result_size); + ok(hr == S_OK, "GetCount failed, hr=%lx\n", hr); + ok(result_size == 0, "expecting 0, got %ld\n", result_size); + + IPropertyStore_Release(propstore); + IPersistSerializedPropStorage_Release(serialized); + + CoUninitialize(); +} + +static void test_PSCreateMemoryPropertyStore(void) +{ + IPropertyStore *propstore, *propstore1; + IPersistSerializedPropStorage *serialized; + IPropertyStoreCache *propstorecache; + HRESULT hr; + + /* PSCreateMemoryPropertyStore(&IID_IPropertyStore, NULL); crashes */ + + hr = PSCreateMemoryPropertyStore(&IID_IPropertyStore, (void **)&propstore); + ok(hr == S_OK, "PSCreateMemoryPropertyStore failed: 0x%08lx.\n", hr); + ok(propstore != NULL, "got %p.\n", propstore); + EXPECT_REF(propstore, 1); + + hr = PSCreateMemoryPropertyStore(&IID_IPersistSerializedPropStorage, (void **)&serialized); + todo_wine ok(hr == S_OK, "PSCreateMemoryPropertyStore failed: 0x%08lx.\n", hr); + todo_wine ok(serialized != NULL, "got %p.\n", serialized); + EXPECT_REF(propstore, 1); + if(serialized) + { + EXPECT_REF(serialized, 1); + IPersistSerializedPropStorage_Release(serialized); + } + + hr = PSCreateMemoryPropertyStore(&IID_IPropertyStoreCache, (void **)&propstorecache); + ok(hr == S_OK, "PSCreateMemoryPropertyStore failed: 0x%08lx.\n", hr); + ok(propstorecache != NULL, "got %p.\n", propstore); + ok(propstorecache != (IPropertyStoreCache *)propstore, "pointer are equal: %p, %p.\n", propstorecache, propstore); + EXPECT_REF(propstore, 1); + EXPECT_REF(propstorecache, 1); + + hr = PSCreateMemoryPropertyStore(&IID_IPropertyStore, (void **)&propstore1); + ok(hr == S_OK, "PSCreateMemoryPropertyStore failed: 0x%08lx.\n", hr); + ok(propstore1 != NULL, "got %p.\n", propstore); + ok(propstore1 != propstore, "pointer are equal: %p, %p.\n", propstore1, propstore); + EXPECT_REF(propstore, 1); + EXPECT_REF(propstore1, 1); + EXPECT_REF(propstorecache, 1); + + IPropertyStore_Release(propstore1); + IPropertyStore_Release(propstore); + IPropertyStoreCache_Release(propstorecache); +} + +static void test_propertystore(void) +{ + IPropertyStore *propstore; + HRESULT hr; + PROPVARIANT propvar, ret_propvar; + PROPERTYKEY propkey; + DWORD count = 0; + + hr = PSCreateMemoryPropertyStore(&IID_IPropertyStore, (void **)&propstore); + ok(hr == S_OK, "PSCreateMemoryPropertyStore failed: 0x%08lx.\n", hr); + ok(propstore != NULL, "got %p.\n", propstore); + + hr = IPropertyStore_GetCount(propstore, &count); + ok(hr == S_OK, "IPropertyStore_GetCount failed: 0x%08lx.\n", hr); + ok(!count, "got wrong property count: %ld, expected 0.\n", count); + + PropVariantInit(&propvar); + propvar.vt = VT_I4; + propvar.lVal = 123; + propkey.fmtid = DUMMY_GUID1; + propkey.pid = PID_FIRST_USABLE; + hr = IPropertyStore_SetValue(propstore, &propkey, &propvar); + ok(hr == S_OK, "IPropertyStore_SetValue failed: 0x%08lx.\n", hr); + hr = IPropertyStore_Commit(propstore); + ok(hr == S_OK, "IPropertyStore_Commit failed: 0x%08lx.\n", hr); + hr = IPropertyStore_GetCount(propstore, &count); + ok(hr == S_OK, "IPropertyStore_GetCount failed: 0x%08lx.\n", hr); + ok(count == 1, "got wrong property count: %ld, expected 1.\n", count); + PropVariantInit(&ret_propvar); + ret_propvar.vt = VT_I4; + hr = IPropertyStore_GetValue(propstore, &propkey, &ret_propvar); + ok(hr == S_OK, "IPropertyStore_GetValue failed: 0x%08lx.\n", hr); + ok(ret_propvar.vt == VT_I4, "got wrong property type: %x.\n", ret_propvar.vt); + ok(ret_propvar.lVal == 123, "got wrong value: %ld, expected 123.\n", ret_propvar.lVal); + PropVariantClear(&propvar); + PropVariantClear(&ret_propvar); + + PropVariantInit(&propvar); + propkey.fmtid = DUMMY_GUID1; + propkey.pid = PID_FIRST_USABLE; + hr = IPropertyStore_SetValue(propstore, &propkey, &propvar); + ok(hr == S_OK, "IPropertyStore_SetValue failed: 0x%08lx.\n", hr); + hr = IPropertyStore_Commit(propstore); + ok(hr == S_OK, "IPropertyStore_Commit failed: 0x%08lx.\n", hr); + hr = IPropertyStore_GetCount(propstore, &count); + ok(hr == S_OK, "IPropertyStore_GetCount failed: 0x%08lx.\n", hr); + ok(count == 1, "got wrong property count: %ld, expected 1.\n", count); + PropVariantInit(&ret_propvar); + hr = IPropertyStore_GetValue(propstore, &propkey, &ret_propvar); + ok(hr == S_OK, "IPropertyStore_GetValue failed: 0x%08lx.\n", hr); + ok(ret_propvar.vt == VT_EMPTY, "got wrong property type: %x.\n", ret_propvar.vt); + ok(!ret_propvar.lVal, "got wrong value: %ld, expected 0.\n", ret_propvar.lVal); PropVariantClear(&propvar); + PropVariantClear(&ret_propvar); + + IPropertyStore_Release(propstore); +} + +static void test_PSCreatePropertyStoreFromObject(void) +{ + IPropertyStore *propstore; + IUnknown *unk; + HRESULT hr; + + hr = PSCreateMemoryPropertyStore(&IID_IPropertyStore, (void **)&propstore); + ok(hr == S_OK, "Failed to create property store, hr %#lx.\n", hr); + + hr = PSCreatePropertyStoreFromObject(NULL, STGM_READWRITE, &IID_IUnknown, (void **)&unk); + ok(hr == E_POINTER, "Unexpected hr %#lx.\n", hr); + + hr = PSCreatePropertyStoreFromObject((IUnknown *)propstore, STGM_READWRITE, &IID_IUnknown, NULL); + ok(hr == E_POINTER, "Unexpected hr %#lx.\n", hr); + + hr = PSCreatePropertyStoreFromObject((IUnknown *)propstore, STGM_READWRITE, &IID_IUnknown, (void **)&unk); + todo_wine + ok(hr == S_OK, "Failed to create wrapper, hr %#lx.\n", hr); + if (SUCCEEDED(hr)) + { + ok(unk != (IUnknown *)propstore, "Unexpected object returned.\n"); + IUnknown_Release(unk); + } + + hr = PSCreatePropertyStoreFromObject((IUnknown *)propstore, STGM_READWRITE, &IID_IPropertyStore, (void **)&unk); + ok(hr == S_OK, "Failed to create wrapper, hr %#lx.\n", hr); + ok(unk == (IUnknown *)propstore, "Unexpected object returned.\n"); + IUnknown_Release(unk); + + IPropertyStore_Release(propstore); +} + +static void test_InitVariantFromFileTime(void) +{ + FILETIME ft = {0}; + SYSTEMTIME st; + VARIANT var; + HRESULT hr; + double d; + + VariantInit(&var); + if (0) /* crash on Windows */ + { + InitVariantFromFileTime(&ft, NULL); + InitVariantFromFileTime(NULL, &var); + } + + ft.dwHighDateTime = -1; + ft.dwLowDateTime = -1; + V_VT(&var) = 0xdead; + V_DATE(&var) = 42.0; + hr = InitVariantFromFileTime(&ft, &var); + ok(hr == E_INVALIDARG, "Unexpected hr %#lx.\n", hr); + ok(V_VT(&var) == VT_EMPTY, "Unexpected VT %d\n", V_VT(&var)); + ok(V_DATE(&var) == 0.0, "got wrong value: %f, expected 0.0\n", V_DATE(&var)); + + GetSystemTimeAsFileTime(&ft); + hr = InitVariantFromFileTime(&ft, &var); + ok(V_VT(&var) == VT_DATE, "Unexpected VT %d\n", V_VT(&var)); + ok(hr == S_OK, "Unexpected hr %#lx.\n", hr); + + FileTimeToSystemTime(&ft, &st); + SystemTimeToVariantTime(&st, &d); + ok(V_DATE(&var) == d, "got wrong value: %f, expected %f\n", V_DATE(&var), d); +} + +static void test_VariantToStringWithDefault(void) +{ + static WCHAR default_value[] = L"test"; + VARIANT var, var2; + PCWSTR result; + BSTR b; + + V_VT(&var) = VT_EMPTY; + result = VariantToStringWithDefault(&var, NULL); + ok(result == NULL, "Unexpected value %s\n", wine_dbgstr_w(result)); + result = VariantToStringWithDefault(&var, default_value); + ok(result == default_value, "Unexpected value %s\n", wine_dbgstr_w(result)); + + V_VT(&var) = VT_NULL; + result = VariantToStringWithDefault(&var, NULL); + ok(result == NULL, "Unexpected value %s\n", wine_dbgstr_w(result)); + result = VariantToStringWithDefault(&var, default_value); + ok(result == default_value, "Unexpected value %s\n", wine_dbgstr_w(result)); + + V_VT(&var) = VT_BOOL; + result = VariantToStringWithDefault(&var, NULL); + ok(result == NULL, "Unexpected value %s\n", wine_dbgstr_w(result)); + V_BOOL(&var) = VARIANT_TRUE; + result = VariantToStringWithDefault(&var, default_value); + ok(result == default_value, "Unexpected value %s\n", wine_dbgstr_w(result)); + + V_VT(&var) = VT_CY; + V_CY(&var).int64 = 100000; + result = VariantToStringWithDefault(&var, NULL); + ok(result == NULL, "Unexpected value %s\n", wine_dbgstr_w(result)); + result = VariantToStringWithDefault(&var, default_value); + ok(result == default_value, "Unexpected value %s\n", wine_dbgstr_w(result)); + + V_VT(&var) = VT_DATE; + V_DATE(&var) = 42.0; + result = VariantToStringWithDefault(&var, NULL); + ok(result == NULL, "Unexpected value %s\n", wine_dbgstr_w(result)); + result = VariantToStringWithDefault(&var, default_value); + ok(result == default_value, "Unexpected value %s\n", wine_dbgstr_w(result)); + + V_VT(&var) = VT_ERROR; + V_ERROR(&var) = DISP_E_PARAMNOTFOUND; + result = VariantToStringWithDefault(&var, NULL); + ok(result == NULL, "Unexpected value %s\n", wine_dbgstr_w(result)); + result = VariantToStringWithDefault(&var, default_value); + ok(result == default_value, "Unexpected value %s\n", wine_dbgstr_w(result)); + + V_VT(&var) = VT_I4; + V_I4(&var) = 15; + result = VariantToStringWithDefault(&var, NULL); + ok(result == NULL, "Unexpected value %s\n", wine_dbgstr_w(result)); + result = VariantToStringWithDefault(&var, default_value); + ok(result == default_value, "Unexpected value %s\n", wine_dbgstr_w(result)); + + V_VT(&var) = VT_I1; + V_I1(&var) = 1; + result = VariantToStringWithDefault(&var, NULL); + ok(result == NULL, "Unexpected value %s\n", wine_dbgstr_w(result)); + result = VariantToStringWithDefault(&var, default_value); + ok(result == default_value, "Unexpected value %s\n", wine_dbgstr_w(result)); + + /* V_BSTR */ + + V_VT(&var) = VT_BSTR; + V_BSTR(&var) = NULL; + result = VariantToStringWithDefault(&var, default_value); + ok(result[0] == '\0', "Unexpected value %s\n", wine_dbgstr_w(result)); + + V_VT(&var) = VT_BSTR; + V_BSTR(&var) = SysAllocString(L""); + result = VariantToStringWithDefault(&var, default_value); + ok(result == V_BSTR(&var), "Unexpected value %s\n", wine_dbgstr_w(result)); + VariantClear(&var); + + V_VT(&var) = VT_BSTR; + V_BSTR(&var) = SysAllocString(L" "); + result = VariantToStringWithDefault(&var, default_value); + ok(result == V_BSTR(&var), "Unexpected value %s\n", wine_dbgstr_w(result)); + VariantClear(&var); + + V_VT(&var) = VT_BSTR; + V_BSTR(&var) = SysAllocString(L"test1"); + result = VariantToStringWithDefault(&var, default_value); + ok(result == V_BSTR(&var), "Unexpected value %s\n", wine_dbgstr_w(result)); + VariantClear(&var); + + /* V_BSTRREF */ + + V_VT(&var) = VT_BYREF | VT_BSTR; + b = NULL; + V_BSTRREF(&var) = &b; + result = VariantToStringWithDefault(&var, default_value); + ok(result[0] == '\0', "Unexpected value %s\n", wine_dbgstr_w(result)); + + V_VT(&var) = VT_BYREF | VT_BSTR; + b = SysAllocString(L""); + V_BSTRREF(&var) = &b; + result = VariantToStringWithDefault(&var, default_value); + ok(result == b, "Unexpected value %s\n", wine_dbgstr_w(result)); + SysFreeString(b); + + V_VT(&var) = VT_BYREF | VT_BSTR; + b = SysAllocString(L" "); + V_BSTRREF(&var) = &b; + result = VariantToStringWithDefault(&var, default_value); + ok(result == b, "Unexpected value %s\n", wine_dbgstr_w(result)); + SysFreeString(b); + + V_VT(&var) = VT_BYREF | VT_BSTR; + b = SysAllocString(L"test1"); + V_BSTRREF(&var) = &b; + result = VariantToStringWithDefault(&var, default_value); + ok(result == b, "Unexpected value %s\n", wine_dbgstr_w(result)); + SysFreeString(b); + + /* Nested V_BSTR */ + + V_VT(&var) = VT_BYREF | VT_VARIANT; + V_VT(&var2) = VT_BSTR; + V_BSTR(&var2) = NULL; + V_VARIANTREF(&var) = &var2; + result = VariantToStringWithDefault(&var, default_value); + ok(result[0] == '\0', "Unexpected value %s\n", wine_dbgstr_w(result)); + + V_VT(&var) = VT_BYREF | VT_VARIANT; + V_VT(&var2) = VT_BSTR; + V_BSTR(&var2) = SysAllocString(L""); + V_VARIANTREF(&var) = &var2; + result = VariantToStringWithDefault(&var, default_value); + ok(result == V_BSTR(&var2), "Unexpected value %s\n", wine_dbgstr_w(result)); + VariantClear(&var2); + + V_VT(&var) = VT_BYREF | VT_VARIANT; + V_VT(&var2) = VT_BSTR; + V_BSTR(&var2) = SysAllocString(L" "); + V_VARIANTREF(&var) = &var2; + result = VariantToStringWithDefault(&var, default_value); + ok(result == V_BSTR(&var2), "Unexpected value %s\n", wine_dbgstr_w(result)); + VariantClear(&var2); + + V_VT(&var) = VT_BYREF | VT_VARIANT; + V_VT(&var2) = VT_BSTR; + V_BSTR(&var2) = SysAllocString(L"test1"); + V_VARIANTREF(&var) = &var2; + result = VariantToStringWithDefault(&var, default_value); + ok(result == V_BSTR(&var2), "Unexpected value %s\n", wine_dbgstr_w(result)); + VariantClear(&var2); + + /* Nested V_BSTRREF */ + + V_VT(&var) = VT_BYREF | VT_VARIANT; + V_VT(&var2) = VT_BYREF | VT_BSTR; + b = NULL; + V_BSTRREF(&var2) = &b; + V_VARIANTREF(&var) = &var2; + result = VariantToStringWithDefault(&var, default_value); + ok(result[0] == '\0', "Unexpected value %s\n", wine_dbgstr_w(result)); + + V_VT(&var) = VT_BYREF | VT_VARIANT; + V_VT(&var2) = VT_BYREF | VT_BSTR; + b = SysAllocString(L""); + V_BSTRREF(&var2) = &b; + V_VARIANTREF(&var) = &var2; + result = VariantToStringWithDefault(&var, default_value); + ok(result == b, "Unexpected value %s\n", wine_dbgstr_w(result)); + SysFreeString(b); + + V_VT(&var) = VT_BYREF | VT_VARIANT; + V_VT(&var2) = VT_BYREF | VT_BSTR; + b = SysAllocString(L" "); + V_BSTRREF(&var2) = &b; + V_VARIANTREF(&var) = &var2; + result = VariantToStringWithDefault(&var, default_value); + ok(result == b, "Unexpected value %s\n", wine_dbgstr_w(result)); + SysFreeString(b); + + V_VT(&var) = VT_BYREF | VT_VARIANT; + V_VT(&var2) = VT_BYREF | VT_BSTR; + b = SysAllocString(L"test1"); + V_BSTRREF(&var2) = &b; + V_VARIANTREF(&var) = &var2; + result = VariantToStringWithDefault(&var, default_value); + ok(result == b, "Unexpected value %s\n", wine_dbgstr_w(result)); + SysFreeString(b); +} + +static void test_VariantToString(void) +{ + HRESULT hr; + VARIANT v; + WCHAR buff[64]; + + buff[0] = 1; + V_VT(&v) = VT_EMPTY; + hr = VariantToString(&v, buff, 64); + todo_wine + ok(hr == S_OK, "Unexpected hr %#lx.\n", hr); + ok(!buff[0], "Unexpected buffer.\n"); + + buff[0] = 0; + V_VT(&v) = VT_I4; + V_I4(&v) = 567; + hr = VariantToString(&v, buff, 64); + ok(hr == S_OK, "Unexpected hr %#lx.\n", hr); + ok(!wcscmp(buff, L"567"), "Unexpected buffer %s.\n", wine_dbgstr_w(buff)); + + V_VT(&v) = VT_BSTR; + V_BSTR(&v) = SysAllocString(L"test1"); + + buff[0] = 1; + hr = VariantToString(&v, buff, 0); + ok(hr == E_INVALIDARG, "Unexpected hr %#lx.\n", hr); + ok(!buff[0], "Unexpected buffer.\n"); + + hr = VariantToString(&v, buff, 5); + ok(hr == STRSAFE_E_INSUFFICIENT_BUFFER, "Unexpected hr %#lx.\n", hr); + hr = VariantToString(&v, buff, 6); + ok(hr == S_OK, "Unexpected hr %#lx.\n", hr); + ok(!wcscmp(buff, L"test1"), "Unexpected string.\n"); + VariantClear(&v); +} + +#define check_VariantToPropVariant(var, propvar, type, member, value, format) do \ +{ \ + V_VT(&(var)) = VT_##type; \ + V_##type(&(var)) = (value); \ + hr = VariantToPropVariant(&(var), &(propvar)); \ + ok_(__FILE__, __LINE__)(hr == S_OK, "VariantToPropVariant returned %#lx.\n", hr); \ + ok_(__FILE__, __LINE__)((propvar).vt == VT_##type, "Unexpected propvar.vt %d.\n", (propvar).vt); \ + ok_(__FILE__, __LINE__)((propvar).member == (value), \ + "Unexpected propvar."#member" "format".\n", (propvar).member); \ +} while (0) + +#define check_PropVariantToVariant(propvar, var, type, member, value, format) do \ +{ \ + (propvar).vt = VT_##type; \ + (propvar).member = (value); \ + hr = PropVariantToVariant(&(propvar), &(var)); \ + ok_(__FILE__, __LINE__)(hr == S_OK, "PropVariantToVariant returned %#lx.\n", hr); \ + ok_(__FILE__, __LINE__)(V_VT(&(var)) == VT_##type, "Unexpected vt %d.\n", V_VT(&(var))); \ + ok_(__FILE__, __LINE__)(V_##type(&(var)) == (value), \ + "Unexpected V_"#type"(&var) "format".\n", (propvar).member); \ +} while (0) + +static void test_VariantToPropVariant(void) +{ + PROPVARIANT propvar; + VARIANT var; + HRESULT hr; + + VariantInit(&var); + PropVariantInit(&propvar); + + hr = VariantToPropVariant(NULL, &propvar); + ok(hr == E_INVALIDARG, "VariantToPropVariant returned %#lx.\n", hr); + hr = VariantToPropVariant(&var, NULL); + ok(hr == E_INVALIDARG, "VariantToPropVariant returned %#lx.\n", hr); + + V_VT(&var) = 0xdead; + hr = VariantToPropVariant(&var, &propvar); + ok(hr == DISP_E_BADVARTYPE, "VariantToPropVariant returned %#lx.\n", hr); + V_VT(&var) = VT_ILLEGAL; + hr = VariantToPropVariant(&var, &propvar); + todo_wine + ok(hr == TYPE_E_TYPEMISMATCH, "VariantToPropVariant returned %#lx.\n", hr); + V_VT(&var) = VT_CLSID; + hr = VariantToPropVariant(&var, &propvar); + todo_wine + ok(hr == DISP_E_BADVARTYPE, "VariantToPropVariant returned %#lx.\n", hr); + + V_VT(&var) = VT_EMPTY; + hr = VariantToPropVariant(&var, &propvar); + ok(hr == S_OK, "VariantToPropVariant returned %#lx.\n", hr); + ok(propvar.vt == VT_EMPTY, "Unexpected propvar.vt %d.\n", propvar.vt); + + V_VT(&var) = VT_NULL; + hr = VariantToPropVariant(&var, &propvar); + ok(hr == S_OK, "VariantToPropVariant returned %#lx.\n", hr); + ok(propvar.vt == VT_NULL, "Unexpected propvar.vt %d.\n", propvar.vt); + + check_VariantToPropVariant(var, propvar, I1, cVal, -123, "%c"); + check_VariantToPropVariant(var, propvar, I2, iVal, -456, "%d"); + check_VariantToPropVariant(var, propvar, I4, lVal, -789, "%ld"); + check_VariantToPropVariant(var, propvar, I8, hVal.QuadPart, -101112, "%I64d"); + + check_VariantToPropVariant(var, propvar, UI1, bVal, 0xcd, "%#x"); + check_VariantToPropVariant(var, propvar, UI2, uiVal, 0xdead, "%#x"); + check_VariantToPropVariant(var, propvar, UI4, ulVal, 0xdeadbeef, "%#lx"); + check_VariantToPropVariant(var, propvar, UI8, uhVal.QuadPart, 0xdeadbeefdeadbeef, "%I64x"); + + check_VariantToPropVariant(var, propvar, BOOL, boolVal, TRUE, "%d"); + + check_VariantToPropVariant(var, propvar, R4, fltVal, 0.123f, "%f"); + check_VariantToPropVariant(var, propvar, R8, dblVal, 0.456f, "%f"); + + V_VT(&var) = VT_BSTR; + V_BSTR(&var) = SysAllocString(L"test"); + hr = VariantToPropVariant(&var, &propvar); + ok(hr == S_OK, "VariantToPropVariant returned %#lx.\n", hr); + ok(propvar.vt == VT_BSTR, "Unexpected propvar.vt %d.\n", propvar.vt); + ok(propvar.bstrVal != V_BSTR(&var), "Got same string pointer.\n"); + ok(!wcscmp(propvar.bstrVal, V_BSTR(&var)), "Unexpected propvar.bstrVal %s.\n", debugstr_w(propvar.bstrVal)); + + PropVariantClear(&propvar); + VariantClear(&var); +} + +static void test_PropVariantToVariant(void) +{ + PROPVARIANT propvar; + VARIANT var; + HRESULT hr; + + VariantInit(&var); + PropVariantInit(&propvar); + + hr = PropVariantToVariant(NULL, &var); + ok(hr == E_INVALIDARG, "PropVariantToVariant returned %#lx.\n", hr); + hr = PropVariantToVariant(&propvar, NULL); + ok(hr == E_INVALIDARG, "PropVariantToVariant returned %#lx.\n", hr); + + propvar.vt = 0xdead; + hr = PropVariantToVariant(&propvar, &var); + todo_wine + ok(hr == E_OUTOFMEMORY, "PropVariantToVariant returned %#lx.\n", hr); + propvar.vt = VT_ILLEGAL; + hr = PropVariantToVariant(&propvar, &var); + todo_wine + ok(hr == E_OUTOFMEMORY, "PropVariantToVariant returned %#lx.\n", hr); + + propvar.vt = VT_EMPTY; + hr = PropVariantToVariant(&propvar, &var); + ok(hr == S_OK, "PropVariantToVariant returned %#lx.\n", hr); + ok(V_VT(&var) == VT_EMPTY, "Unexpected V_VT(&var) %d.\n", V_VT(&var)); + + propvar.vt = VT_NULL; + hr = PropVariantToVariant(&propvar, &var); + ok(hr == S_OK, "PropVariantToVariant returned %#lx.\n", hr); + ok(V_VT(&var) == VT_NULL, "Unexpected V_VT(&var) %d.\n", V_VT(&var)); + + check_PropVariantToVariant(propvar, var, I1, cVal, 'X', "%c"); + check_PropVariantToVariant(propvar, var, I2, iVal, -456, "%d"); + check_PropVariantToVariant(propvar, var, I4, lVal, -789, "%ld"); + check_PropVariantToVariant(propvar, var, I8, hVal.QuadPart, -101112, "%I64d"); + + check_PropVariantToVariant(propvar, var, UI1, bVal, 0xcd, "%#x"); + check_PropVariantToVariant(propvar, var, UI2, uiVal, 0xdead, "%#x"); + check_PropVariantToVariant(propvar, var, UI4, ulVal, 0xdeadbeef, "%#lx"); + check_PropVariantToVariant(propvar, var, UI8, uhVal.QuadPart, 0xdeadbeefdeadbeef, "%I64x"); + + check_PropVariantToVariant(propvar, var, BOOL, boolVal, TRUE, "%d"); + + check_PropVariantToVariant(propvar, var, R4, fltVal, 0.123f, "%f"); + check_PropVariantToVariant(propvar, var, R8, dblVal, 0.456f, "%f"); + + propvar.vt = VT_BSTR; + propvar.bstrVal = SysAllocString(L"test"); + hr = PropVariantToVariant(&propvar, &var); + ok(hr == S_OK, "PropVariantToVariant returned %#lx.\n", hr); + ok(V_VT(&var) == VT_BSTR, "Unexpected V_VT(&var) %d.\n", V_VT(&var)); + ok(V_BSTR(&var) != propvar.bstrVal, "Got same string pointer.\n"); + ok(!wcscmp(V_BSTR(&var), propvar.bstrVal), "Unexpected V_BSTR(&var) %s.\n", debugstr_w(V_BSTR(&var))); + PropVariantClear(&propvar); + VariantClear(&var); + + propvar.vt = VT_CLSID; + propvar.puuid = (GUID *)&dummy_guid; + hr = PropVariantToVariant(&propvar, &var); + todo_wine + ok(hr == 39, "PropVariantToVariant returned %#lx.\n", hr); + ok(V_VT(&var) == VT_BSTR, "Unexpected V_VT(&var) %d.\n", V_VT(&var)); + ok(!wcscmp(V_BSTR(&var), dummy_guid_str), "Unexpected V_BSTR(&var) %s.\n", debugstr_w(V_BSTR(&var))); + VariantClear(&var); + + propvar.vt = VT_LPSTR; + propvar.pszVal = (char *)topic; + hr = PropVariantToVariant(&propvar, &var); + ok(hr == S_OK, "PropVariantToVariant returned %#lx.\n", hr); + ok(V_VT(&var) == VT_BSTR, "Unexpected V_VT(&var) %d.\n", V_VT(&var)); + ok(!wcscmp(V_BSTR(&var), topicW), "Unexpected V_BSTR(&var) %s.\n", debugstr_w(V_BSTR(&var))); + VariantClear(&var); + + propvar.vt = VT_LPWSTR; + propvar.pwszVal = (WCHAR *)topicW; + hr = PropVariantToVariant(&propvar, &var); + ok(hr == S_OK, "PropVariantToVariant returned %#lx.\n", hr); + ok(V_VT(&var) == VT_BSTR, "Unexpected V_VT(&var) %d.\n", V_VT(&var)); + ok(V_BSTR(&var) != topicW, "Got same string pointer.\n"); + ok(!wcscmp(V_BSTR(&var), topicW), "Unexpected V_BSTR(&var) %s.\n", debugstr_w(V_BSTR(&var))); + VariantClear(&var); } START_TEST(propsys) { + test_InitPropVariantFromGUIDAsString(); + test_InitPropVariantFromBuffer(); + test_InitPropVariantFromCLSID(); + test_InitPropVariantFromStringVector(); + test_InitVariantFromFileTime(); + test_PSStringFromPropertyKey(); test_PSPropertyKeyFromString(); test_PSRefreshPropertySchema(); - test_InitPropVariantFromGUIDAsString(); - test_InitPropVariantFromBuffer(); test_PropVariantToGUID(); test_PropVariantToStringAlloc(); - test_PropVariantCompare(); + test_PropVariantCompareEx(); test_intconversions(); test_PropVariantChangeType_LPWSTR(); test_PropVariantToBoolean(); test_PropVariantToStringWithDefault(); - test_InitPropVariantFromCLSID(); test_PropVariantToDouble(); test_PropVariantToString(); + test_PropVariantToBSTR(); test_PropVariantToBuffer(); + test_inmemorystore(); + test_persistserialized(); + test_PSCreateMemoryPropertyStore(); + test_propertystore(); + test_PSCreatePropertyStoreFromObject(); + test_VariantToStringWithDefault(); + test_VariantToString(); + test_VariantToPropVariant(); + test_PropVariantToVariant(); } diff --git a/modules/rostests/winetests/propsys/testlist.c b/modules/rostests/winetests/propsys/testlist.c index 3773d6ad652..364dec7c1a9 100644 --- a/modules/rostests/winetests/propsys/testlist.c +++ b/modules/rostests/winetests/propsys/testlist.c @@ -3,12 +3,10 @@ #define STANDALONE #include <wine/test.h> -extern void func_propstore(void); extern void func_propsys(void); const struct test winetest_testlist[] = { - { "propstore", func_propstore }, { "propsys", func_propsys }, { 0, 0 } }; diff --git a/sdk/include/psdk/oaidl.idl b/sdk/include/psdk/oaidl.idl index 0dc4c057460..27e27a92125 100644 --- a/sdk/include/psdk/oaidl.idl +++ b/sdk/include/psdk/oaidl.idl @@ -230,6 +230,17 @@ typedef VARIANT *LPVARIANT; typedef VARIANT VARIANTARG; typedef VARIANTARG *LPVARIANTARG; +cpp_quote("#ifdef MIDL_PASS") +typedef const VARIANT *REFVARIANT; +cpp_quote("#elif !defined(_REFVARIANT_DEFINED)") +cpp_quote("#define _REFVARIANT_DEFINED") +cpp_quote("#ifdef __cplusplus") +cpp_quote("#define REFVARIANT const VARIANT &") +cpp_quote("#else") +cpp_quote("#define REFVARIANT const VARIANT *__MIDL_CONST") +cpp_quote("#endif") +cpp_quote("#endif") + struct _wireBRECORD { ULONG fFlags; ULONG clSize; diff --git a/sdk/include/psdk/propsys.idl b/sdk/include/psdk/propsys.idl index bdd67fa6a59..240bbfd86ca 100644 --- a/sdk/include/psdk/propsys.idl +++ b/sdk/include/psdk/propsys.idl @@ -27,7 +27,13 @@ import "shtypes.idl"; import "structuredquerycondition.idl"; cpp_quote("#ifndef PSSTDAPI") -cpp_quote("#define PSSTDAPI EXTERN_C DECLSPEC_IMPORT HRESULT STDAPICALLTYPE") +cpp_quote("#ifdef _PROPSYS_") +cpp_quote("#define PSSTDAPI STDAPI") +cpp_quote("#define PSSTDAPI_(type) STDAPI_(type)") +cpp_quote("#else") +cpp_quote("#define PSSTDAPI EXTERN_C DECLSPEC_IMPORT HRESULT STDAPICALLTYPE") +cpp_quote("#define PSSTDAPI_(type) EXTERN_C DECLSPEC_IMPORT type STDAPICALLTYPE") +cpp_quote("#endif") cpp_quote("#endif") cpp_quote("#if 0") @@ -272,7 +278,7 @@ interface IPropertyEnumType : IUnknown } [ - uuid(9b6e051c-5ddd-4321-9070-fe2acb55e974), + uuid(9b6e051c-5ddd-4321-9070-fe2acb55e794), object, pointer_default(unique) ] @@ -799,14 +805,15 @@ cpp_quote("#define PKEY_PIDSTR_MAX 10") cpp_quote("#define GUIDSTRING_MAX 39") cpp_quote("#define PKEYSTR_MAX (GUIDSTRING_MAX + 1 + PKEY_PIDSTR_MAX)") -cpp_quote("HRESULT WINAPI PSCreateMemoryPropertyStore(REFIID,void **);") -cpp_quote("HRESULT WINAPI PSStringFromPropertyKey(REFPROPERTYKEY,LPWSTR,UINT);") -cpp_quote("HRESULT WINAPI PSPropertyKeyFromString(LPCWSTR,PROPERTYKEY*);") -cpp_quote("HRESULT WINAPI PSGetPropertyDescription(REFPROPERTYKEY,REFIID,void **);") -cpp_quote("HRESULT WINAPI PSGetPropertyDescriptionListFromString(LPCWSTR,REFIID,void **);") -cpp_quote("HRESULT WINAPI PSRefreshPropertySchema(void);") -cpp_quote("HRESULT WINAPI PSRegisterPropertySchema(LPCWSTR);") -cpp_quote("HRESULT WINAPI PSUnregisterPropertySchema(LPCWSTR);") +cpp_quote("PSSTDAPI PSCreateMemoryPropertyStore(REFIID,void **);") +cpp_quote("PSSTDAPI PSCreatePropertyStoreFromObject(IUnknown*,DWORD,REFIID,void **);") +cpp_quote("PSSTDAPI PSStringFromPropertyKey(REFPROPERTYKEY,LPWSTR,UINT);") +cpp_quote("PSSTDAPI PSPropertyKeyFromString(LPCWSTR,PROPERTYKEY*);") +cpp_quote("PSSTDAPI PSGetPropertyDescription(REFPROPERTYKEY,REFIID,void **);") +cpp_quote("PSSTDAPI PSGetPropertyDescriptionListFromString(LPCWSTR,REFIID,void **);") +cpp_quote("PSSTDAPI PSRefreshPropertySchema(void);") +cpp_quote("PSSTDAPI PSRegisterPropertySchema(LPCWSTR);") +cpp_quote("PSSTDAPI PSUnregisterPropertySchema(LPCWSTR);") /* TODO: Add remainder of the C api here */ @@ -821,7 +828,7 @@ library PropSysObjects { interface IPropertyStore; } - [uuid(b8967f86-58ae-4f96-9fb2-5d7904798f4b)] coclass PropertySystem + [uuid(b8967f85-58ae-4f46-9fb2-5d7904798f4b)] coclass PropertySystem { interface IPropertySystem; } diff --git a/sdk/include/psdk/propvarutil.h b/sdk/include/psdk/propvarutil.h index e0a21faf8c7..9f689033548 100644 --- a/sdk/include/psdk/propvarutil.h +++ b/sdk/include/psdk/propvarutil.h @@ -22,6 +22,16 @@ #include <shtypes.h> #include <shlwapi.h> +#ifndef PSSTDAPI +#ifdef _PROPSYS_ +#define PSSTDAPI STDAPI +#define PSSTDAPI_(type) STDAPI_(type) +#else +#define PSSTDAPI DECLSPEC_IMPORT STDAPI +#define PSSTDAPI_(type) DECLSPEC_IMPORT STDAPI_(type) +#endif +#endif + #ifdef __cplusplus extern "C" { #endif @@ -63,37 +73,56 @@ enum tagPROPVAR_COMPARE_FLAGS typedef int PROPVAR_COMPARE_FLAGS; -HRESULT WINAPI PropVariantChangeType(PROPVARIANT *ppropvarDest, REFPROPVARIANT propvarSrc, +PSSTDAPI PropVariantChangeType(PROPVARIANT *ppropvarDest, REFPROPVARIANT propvarSrc, PROPVAR_CHANGE_FLAGS flags, VARTYPE vt); -HRESULT WINAPI InitPropVariantFromGUIDAsString(REFGUID guid, PROPVARIANT *ppropvar); -HRESULT WINAPI InitVariantFromGUIDAsString(REFGUID guid, VARIANT *pvar); -HRESULT WINAPI InitPropVariantFromBuffer(const VOID *pv, UINT cb, PROPVARIANT *ppropvar); -HRESULT WINAPI InitPropVariantFromCLSID(REFCLSID clsid, PROPVARIANT *ppropvar); -HRESULT WINAPI InitVariantFromBuffer(const VOID *pv, UINT cb, VARIANT *pvar); -HRESULT WINAPI PropVariantToGUID(const PROPVARIANT *ppropvar, GUID *guid); -HRESULT WINAPI VariantToGUID(const VARIANT *pvar, GUID *guid); -INT WINAPI PropVariantCompareEx(REFPROPVARIANT propvar1, REFPROPVARIANT propvar2, +PSSTDAPI InitPropVariantFromGUIDAsString(REFGUID guid, PROPVARIANT *ppropvar); +PSSTDAPI InitVariantFromFileTime(const FILETIME *ft, VARIANT *var); +PSSTDAPI InitVariantFromGUIDAsString(REFGUID guid, VARIANT *pvar); +PSSTDAPI InitPropVariantFromBuffer(const VOID *pv, UINT cb, PROPVARIANT *ppropvar); +PSSTDAPI InitPropVariantFromCLSID(REFCLSID clsid, PROPVARIANT *ppropvar); +PSSTDAPI InitVariantFromBuffer(const VOID *pv, UINT cb, VARIANT *pvar); +PSSTDAPI PropVariantToGUID(const PROPVARIANT *ppropvar, GUID *guid); +PSSTDAPI VariantToGUID(const VARIANT *pvar, GUID *guid); +PSSTDAPI_(INT) PropVariantCompareEx(REFPROPVARIANT propvar1, REFPROPVARIANT propvar2, PROPVAR_COMPARE_UNIT uint, PROPVAR_COMPARE_FLAGS flags); - -HRESULT WINAPI PropVariantToDouble(REFPROPVARIANT propvarIn, double *ret); -HRESULT WINAPI PropVariantToInt16(REFPROPVARIANT propvarIn, SHORT *ret); -HRESULT WINAPI PropVariantToInt32(REFPROPVARIANT propvarIn, LONG *ret); -HRESULT WINAPI PropVariantToInt64(REFPROPVARIANT propvarIn, LONGLONG *ret); -HRESULT WINAPI PropVariantToUInt16(REFPROPVARIANT propvarIn, USHORT *ret); -HRESULT WINAPI PropVariantToUInt32(REFPROPVARIANT propvarIn, ULONG *ret); -HRESULT WINAPI PropVariantToUInt64(REFPROPVARIANT propvarIn, ULONGLONG *ret); -HRESULT WINAPI PropVariantToBoolean(REFPROPVARIANT propvarIn, BOOL *ret); -HRESULT WINAPI PropVariantToBuffer(REFPROPVARIANT propvarIn, void *ret, UINT cb); -HRESULT WINAPI PropVariantToString(REFPROPVARIANT propvarIn, PWSTR ret, UINT cch); -PCWSTR WINAPI PropVariantToStringWithDefault(REFPROPVARIANT propvarIn, LPCWSTR pszDefault); - -HRESULT WINAPI PropVariantToStringAlloc(REFPROPVARIANT propvarIn, WCHAR **ret); +PSSTDAPI InitPropVariantFromFileTime(const FILETIME *pftIn, PROPVARIANT *ppropvar); +PSSTDAPI InitPropVariantFromStringVector(PCWSTR *strs, ULONG count, PROPVARIANT *ppropvar); + +PSSTDAPI PropVariantToDouble(REFPROPVARIANT propvarIn, double *ret); +PSSTDAPI PropVariantToInt16(REFPROPVARIANT propvarIn, SHORT *ret); +PSSTDAPI PropVariantToInt32(REFPROPVARIANT propvarIn, LONG *ret); +PSSTDAPI PropVariantToInt64(REFPROPVARIANT propvarIn, LONGLONG *ret); +PSSTDAPI PropVariantToUInt16(REFPROPVARIANT propvarIn, USHORT *ret); +PSSTDAPI PropVariantToUInt32(REFPROPVARIANT propvarIn, ULONG *ret); +PSSTDAPI_(ULONG) PropVariantToUInt32WithDefault(REFPROPVARIANT propvarIn, ULONG uLDefault); +PSSTDAPI PropVariantToUInt64(REFPROPVARIANT propvarIn, ULONGLONG *ret); +PSSTDAPI PropVariantToBoolean(REFPROPVARIANT propvarIn, BOOL *ret); +PSSTDAPI PropVariantToBSTR(REFPROPVARIANT propvar, BSTR *bstr); +PSSTDAPI PropVariantToBuffer(REFPROPVARIANT propvarIn, void *ret, UINT cb); +PSSTDAPI PropVariantToString(REFPROPVARIANT propvarIn, PWSTR ret, UINT cch); +PSSTDAPI_(PCWSTR) PropVariantToStringWithDefault(REFPROPVARIANT propvarIn, LPCWSTR pszDefault); +PSSTDAPI_(PCWSTR) VariantToStringWithDefault(const VARIANT *pvar, LPCWSTR pszDefault); +PSSTDAPI VariantToString(REFVARIANT var, PWSTR ret, UINT cch); + +PSSTDAPI PropVariantToStringAlloc(REFPROPVARIANT propvarIn, WCHAR **ret); + +PSSTDAPI PropVariantToVariant(const PROPVARIANT *propvar, VARIANT *var); +PSSTDAPI VariantToPropVariant(const VARIANT* var, PROPVARIANT* propvar); #ifdef __cplusplus HRESULT InitPropVariantFromBoolean(BOOL fVal, PROPVARIANT *ppropvar); -HRESULT InitPropVariantFromString(PCWSTR psz, PROPVARIANT *ppropvar); +HRESULT InitPropVariantFromInt16(SHORT nVal, PROPVARIANT *ppropvar); +HRESULT InitPropVariantFromUInt16(USHORT uiVal, PROPVARIANT *ppropvar); +HRESULT InitPropVariantFromInt32(LONG lVal, PROPVARIANT *ppropvar); +HRESULT InitPropVariantFromUInt32(ULONG ulVal, PROPVARIANT *ppropvar); HRESULT InitPropVariantFromInt64(LONGLONG llVal, PROPVARIANT *ppropvar); +HRESULT InitPropVariantFromUInt64(ULONGLONG ullVal, PROPVARIANT *ppropvar); +HRESULT InitPropVariantFromDouble(DOUBLE dblVal, PROPVARIANT *ppropvar); +HRESULT InitPropVariantFromString(PCWSTR psz, PROPVARIANT *ppropvar); +HRESULT InitPropVariantFromGUIDAsBuffer(REFGUID guid, PROPVARIANT *ppropvar); +BOOL IsPropVariantVector(REFPROPVARIANT propvar); +BOOL IsPropVariantString(REFPROPVARIANT propvar); #ifndef NO_PROPVAR_INLINES @@ -104,6 +133,55 @@ inline HRESULT InitPropVariantFromBoolean(BOOL fVal, PROPVARIANT *ppropvar) return S_OK; } +inline HRESULT InitPropVariantFromInt16(SHORT nVal, PROPVARIANT *ppropvar) +{ + ppropvar->vt = VT_I2; + ppropvar->iVal = nVal; + return S_OK; +} + +inline HRESULT InitPropVariantFromUInt16(USHORT uiVal, PROPVARIANT *ppropvar) +{ + ppropvar->vt = VT_UI2; + ppropvar->uiVal = uiVal; + return S_OK; +} + +inline HRESULT InitPropVariantFromInt32(LONG lVal, PROPVARIANT *ppropvar) +{ + ppropvar->vt = VT_I4; + ppropvar->lVal = lVal; + return S_OK; +} + +inline HRESULT InitPropVariantFromUInt32(ULONG ulVal, PROPVARIANT *ppropvar) +{ + ppropvar->vt = VT_UI4; + ppropvar->ulVal = ulVal; + return S_OK; +} + +inline HRESULT InitPropVariantFromInt64(LONGLONG llVal, PROPVARIANT *ppropvar) +{ + ppropvar->vt = VT_I8; + ppropvar->hVal.QuadPart = llVal; + return S_OK; +} + +inline HRESULT InitPropVariantFromUInt64(ULONGLONG ullVal, PROPVARIANT *ppropvar) +{ + ppropvar->vt = VT_UI8; + ppropvar->uhVal.QuadPart = ullVal; + return S_OK; +} + +inline HRESULT InitPropVariantFromDouble(DOUBLE dblVal, PROPVARIANT *ppropvar) +{ + ppropvar->vt = VT_R8; + ppropvar->dblVal = dblVal; + return S_OK; +} + inline HRESULT InitPropVariantFromString(PCWSTR psz, PROPVARIANT *ppropvar) { HRESULT hres; @@ -117,16 +195,26 @@ inline HRESULT InitPropVariantFromString(PCWSTR psz, PROPVARIANT *ppropvar) return hres; } -inline HRESULT InitPropVariantFromInt64(LONGLONG llVal, PROPVARIANT *ppropvar) +inline HRESULT InitPropVariantFromGUIDAsBuffer(REFGUID guid, PROPVARIANT *ppropvar) { - ppropvar->vt = VT_I8; - ppropvar->hVal.QuadPart = llVal; - return S_OK; + return InitPropVariantFromBuffer(&guid, sizeof(GUID), ppropvar); +} + +inline BOOL IsPropVariantVector(REFPROPVARIANT propvar) +{ + return (propvar.vt & (VT_ARRAY | VT_VECTOR)); +} + +inline BOOL IsPropVariantString(REFPROPVARIANT propvar) +{ + return (PropVariantToStringWithDefault(propvar, NULL) != NULL); } #endif /* NO_PROPVAR_INLINES */ #endif /* __cplusplus */ +PSSTDAPI StgSerializePropVariant(const PROPVARIANT *ppropvar, SERIALIZEDPROPERTYVALUE **ppprop, ULONG *pcb); +PSSTDAPI StgDeserializePropVariant(const SERIALIZEDPROPERTYVALUE *pprop, ULONG cbmax, PROPVARIANT *ppropvar); #ifdef __cplusplus } diff --git a/sdk/tools/winesync/propsys.cfg b/sdk/tools/winesync/propsys.cfg new file mode 100644 index 00000000000..1c8b99a3dfc --- /dev/null +++ b/sdk/tools/winesync/propsys.cfg @@ -0,0 +1,9 @@ +directories: + dlls/propsys: dll/win32/propsys + dlls/propsys/tests: modules/rostests/winetests/propsys +files: + include/oaidl.idl: sdk/include/psdk/oaidl.idl + include/propsys.idl: sdk/include/psdk/propsys.idl + include/propvarutil.h: sdk/include/psdk/propvarutil.h +tags: + wine: wine-10.0
4Â months, 3Â weeks
1
0
0
0
[reactos] 01/01: [RAPPS] Refresh item info after installer completes (#7697)
by Whindmar Saksit
https://git.reactos.org/?p=reactos.git;a=commitdiff;h=5bc6d5914288283606c33…
commit 5bc6d5914288283606c339534c65ceb81af663e5 Author: Whindmar Saksit <whindsaks(a)proton.me> AuthorDate: Fri Feb 7 21:33:19 2025 +0100 Commit: GitHub <noreply(a)github.com> CommitDate: Fri Feb 7 21:33:19 2025 +0100 [RAPPS] Refresh item info after installer completes (#7697) - Refresh the details view of the item that was just installed. - Hint update of uninstallers list is needed. - Restore focus correctly after installer process finishes. CORE-17677 --- base/applications/rapps/appinfo.cpp | 12 +++++++-- base/applications/rapps/appview.cpp | 45 ++++++++++++++++++++++++------- base/applications/rapps/gui.cpp | 41 +++++++++++++++++++++------- base/applications/rapps/include/appinfo.h | 9 +++++++ base/applications/rapps/include/appview.h | 7 ++++- base/applications/rapps/include/gui.h | 3 +++ base/applications/rapps/include/rapps.h | 2 ++ base/applications/rapps/loaddlg.cpp | 13 ++++++--- base/applications/rapps/misc.cpp | 2 ++ base/applications/rapps/unattended.cpp | 4 +-- 10 files changed, 109 insertions(+), 29 deletions(-) diff --git a/base/applications/rapps/appinfo.cpp b/base/applications/rapps/appinfo.cpp index 1970b9459d9..5442380fbad 100644 --- a/base/applications/rapps/appinfo.cpp +++ b/base/applications/rapps/appinfo.cpp @@ -10,6 +10,14 @@ #include "rapps.h" #include "appview.h" +static inline AppsCategories +ClampAvailableCategory(AppsCategories Category) +{ + if (Category <= ENUM_LASTCATEGORY) + return Category; + return ENUM_CAT_OTHER; // Treat future categories we don't know as Other +} + CAppInfo::CAppInfo(const CStringW &Identifier, AppsCategories Category) : szIdentifier(Identifier), iCategory(Category) { @@ -24,7 +32,7 @@ CAvailableApplicationInfo::CAvailableApplicationInfo( const CStringW &PkgName, AppsCategories Category, const CPathW &BasePath) - : CAppInfo(PkgName, Category), m_Parser(Parser), m_ScrnshotRetrieved(false), m_LanguagesLoaded(false) + : CAppInfo(PkgName, ClampAvailableCategory(Category)), m_Parser(Parser), m_ScrnshotRetrieved(false), m_LanguagesLoaded(false) { m_Parser->GetString(L"Name", szDisplayName); m_Parser->GetString(L"Version", szDisplayVersion); @@ -588,7 +596,7 @@ CInstalledApplicationInfo::GetInstallerType() const BOOL CInstalledApplicationInfo::UninstallApplication(UninstallCommandFlags Flags) { - if (GetInstallerType() == INSTALLER_GENERATE) + if (GetInstallerType() == INSTALLER_GENERATE && (Flags & UCF_SAMEPROCESS)) { return UninstallGenerated(*this, Flags); } diff --git a/base/applications/rapps/appview.cpp b/base/applications/rapps/appview.cpp index c0f18107c1e..248050ebb92 100644 --- a/base/applications/rapps/appview.cpp +++ b/base/applications/rapps/appview.cpp @@ -955,19 +955,22 @@ CAppInfoDisplay::Create(HWND hwndParent) } VOID -CAppInfoDisplay::ShowAppInfo(CAppInfo *Info) +CAppInfoDisplay::ShowAppInfo(CAppInfo &Info, bool OnlyUpdateText) { - CStringW ScrnshotLocation; - if (Info->RetrieveScreenshot(ScrnshotLocation)) + if (!OnlyUpdateText) { - ScrnshotPrev->DisplayImage(ScrnshotLocation); - } - else - { - ScrnshotPrev->DisplayEmpty(); + CStringW ScrnshotLocation; + if (Info.RetrieveScreenshot(ScrnshotLocation)) + { + ScrnshotPrev->DisplayImage(ScrnshotLocation); + } + else + { + ScrnshotPrev->DisplayEmpty(); + } } ResizeChildren(); - Info->ShowAppInfo(RichEdit); + Info.ShowAppInfo(RichEdit); } void @@ -1805,6 +1808,22 @@ CApplicationView::SetRedraw(BOOL bRedraw) m_ListView->SetRedraw(bRedraw); } +void +CApplicationView::RefreshAvailableItem(PCWSTR PackageName) +{ + if (ApplicationViewType != AppViewTypeAvailableApps || !PackageName) + return; + CAppInfo *pApp; + for (UINT i = 0; (pApp = (CAppInfo*)m_ListView->GetItemData(i)) != NULL; ++i) + { + if (pApp->szIdentifier.CompareNoCase(PackageName) == 0) + { + RefreshDetailsPane(*pApp, true); + break; + } + } +} + void CApplicationView::SetFocusOnSearchBar() { @@ -2134,6 +2153,12 @@ CApplicationView::RestoreListSelection(const RESTORELISTSELECTION &Restore) } } +VOID +CApplicationView::RefreshDetailsPane(CAppInfo &Info, bool OnlyUpdateText) +{ + m_AppsInfo->ShowAppInfo(Info, OnlyUpdateText); +} + // this function is called when a item of listview get focus. // CallbackParam is the param passed to listview when adding the item (the one getting focus now). VOID @@ -2142,7 +2167,7 @@ CApplicationView::ItemGetFocus(LPVOID CallbackParam) if (CallbackParam) { CAppInfo *Info = static_cast<CAppInfo *>(CallbackParam); - m_AppsInfo->ShowAppInfo(Info); + RefreshDetailsPane(*Info); if (ApplicationViewType == AppViewTypeInstalledApps) { diff --git a/base/applications/rapps/gui.cpp b/base/applications/rapps/gui.cpp index 6f2e1a1d3d8..8470ba092d1 100644 --- a/base/applications/rapps/gui.cpp +++ b/base/applications/rapps/gui.cpp @@ -81,6 +81,8 @@ CSideTreeView::~CSideTreeView() // **** CSideTreeView **** // **** CMainWindow **** +HWND CMainWindow::m_hLastFocus = NULL; +bool CMainWindow::m_PendingInstalledViewRefresh = false; CMainWindow::CMainWindow(CAppDB *db, BOOL bAppwiz) : m_ClientPanel(NULL), m_Db(db), m_bAppwizMode(bAppwiz), SelectedEnumType(ENUM_ALL_INSTALLED) { @@ -343,10 +345,32 @@ CMainWindow::ProcessWindowMessage(HWND hwnd, UINT Msg, WPARAM wParam, LPARAM lPa SendMessage(WM_CLOSE, 0, 0); break; + case WM_NOTIFY_INSTALLERFINISHED: + m_PendingInstalledViewRefresh = true; // Something just installed, our uninstall list is probably outdated + m_ApplicationView->RefreshAvailableItem((PCWSTR)lParam); + break; + case DM_REPOSITION: EmulateDialogReposition(hwnd); // We are not a real dialog, we need help from a real one break; + case WM_ACTIVATE: + if (LOWORD(wParam) == WA_INACTIVE) + m_hLastFocus = ::GetFocus(); + break; + + case WM_SETFOCUS: + if (m_hLastFocus) + ::SetFocus(m_hLastFocus); + break; + + case WM_NEXTDLGCTL: + if (!LOWORD(lParam)) + HandleTabOrder(wParam ? -1 : 1); + else if (wParam) + ::SetFocus((HWND)wParam); + break; + case WM_COMMAND: OnCommand(wParam, lParam); break; @@ -678,6 +702,12 @@ CMainWindow::UpdateApplicationsList(AppsCategories EnumType, BOOL bReload, BOOL if (bCheckAvailable) CheckAvailable(); + if (m_PendingInstalledViewRefresh && IsInstalledEnum(EnumType) && !IsInstalledEnum(SelectedEnumType)) + { + m_PendingInstalledViewRefresh = FALSE; + bReload = TRUE; // Reload because we are switching from Available to Installed after something installed + } + BOOL TryRestoreSelection = SelectedEnumType == EnumType; if (SelectedEnumType != EnumType) SelectedEnumType = EnumType; @@ -812,16 +842,7 @@ CMainWindow::ItemCheckStateChanged(BOOL bChecked, LPVOID CallbackParam) BOOL CMainWindow::InstallApplication(CAppInfo *Info) { - if (Info) - { - if (DownloadApplication(Info)) - { - //FIXME: Delay UpdateApplicationsList(SelectedEnumType); until install completes - return TRUE; - } - } - - return FALSE; + return Info && DownloadApplication(Info); } BOOL diff --git a/base/applications/rapps/include/appinfo.h b/base/applications/rapps/include/appinfo.h index 32cfc20b3dd..961ad0711bd 100644 --- a/base/applications/rapps/include/appinfo.h +++ b/base/applications/rapps/include/appinfo.h @@ -41,6 +41,7 @@ enum AppsCategories ENUM_CAT_THEMES, ENUM_CAT_OTHER, ENUM_CAT_SELECTED, + ENUM_LASTCATEGORY = ENUM_CAT_SELECTED - 1, ENUM_ALL_INSTALLED = 30, ENUM_INSTALLED_APPLICATIONS, ENUM_UPDATES, @@ -54,6 +55,12 @@ enum AppsCategories inline BOOL IsAvailableEnum(INT x) { + C_ASSERT(ENUM_CAT_AUDIO == 1 && ENUM_CAT_THEMES == 15 && ENUM_CAT_OTHER == 16); + C_ASSERT(ENUM_LASTCATEGORY >= ENUM_CAT_OTHER); + C_ASSERT(ENUM_LASTCATEGORY < ENUM_CAT_SELECTED); + C_ASSERT(ENUM_LASTCATEGORY < ENUM_INSTALLED_MIN); + C_ASSERT(ENUM_CAT_SELECTED < ENUM_INSTALLED_MIN); + return (x >= ENUM_AVAILABLE_MIN && x <= ENUM_AVAILABLE_MAX); } @@ -68,7 +75,9 @@ enum UninstallCommandFlags UCF_NONE = 0x00, UCF_MODIFY = 0x01, UCF_SILENT = 0x02, + UCF_SAMEPROCESS = 0x04, }; +DEFINE_ENUM_FLAG_OPERATORS(UninstallCommandFlags); enum InstallerType { diff --git a/base/applications/rapps/include/appview.h b/base/applications/rapps/include/appview.h index d457d45c799..169d0b23151 100644 --- a/base/applications/rapps/include/appview.h +++ b/base/applications/rapps/include/appview.h @@ -175,7 +175,7 @@ class CAppInfoDisplay : public CUiWindow<CWindowImpl<CAppInfoDisplay>> Create(HWND hwndParent); VOID - ShowAppInfo(CAppInfo *Info); + ShowAppInfo(CAppInfo &Info, bool OnlyUpdateText = false); void SetWelcomeText(bool bAppwiz); VOID @@ -388,6 +388,8 @@ class CApplicationView : public CUiWindow<CWindowImpl<CApplicationView>> void SetRedraw(BOOL bRedraw); void + RefreshAvailableItem(PCWSTR PackageName); + void SetFocusOnSearchBar(); BOOL SetDisplayAppType(APPLICATION_VIEW_TYPE AppType); @@ -415,6 +417,9 @@ class CApplicationView : public CUiWindow<CWindowImpl<CApplicationView>> VOID RestoreListSelection(const RESTORELISTSELECTION &Restore); + VOID + RefreshDetailsPane(CAppInfo &Info, bool OnlyUpdateText = false); + // this function is called when a item of listview get focus. // CallbackParam is the param passed to listview when adding the item (the one getting focus now). VOID diff --git a/base/applications/rapps/include/gui.h b/base/applications/rapps/include/gui.h index 36ff852dde3..fbe36a7fea1 100644 --- a/base/applications/rapps/include/gui.h +++ b/base/applications/rapps/include/gui.h @@ -65,6 +65,9 @@ class CMainWindow : public CWindowImpl<CMainWindow, CWindow, CFrameWinTraits> AppsCategories SelectedEnumType; public: + static HWND m_hLastFocus; + static bool m_PendingInstalledViewRefresh; + explicit CMainWindow(CAppDB *db, BOOL bAppwiz = FALSE); ~CMainWindow(); diff --git a/base/applications/rapps/include/rapps.h b/base/applications/rapps/include/rapps.h index c03a06d092d..f42c5919c2e 100644 --- a/base/applications/rapps/include/rapps.h +++ b/base/applications/rapps/include/rapps.h @@ -14,8 +14,10 @@ #include "configparser.h" extern LONG g_Busy; +extern bool g_PendingInstalledViewRefresh; #define WM_NOTIFY_OPERATIONCOMPLETED (WM_APP + 0) +#define WM_NOTIFY_INSTALLERFINISHED (WM_APP + 1) #define MAINWINDOWCLASSNAME L"ROSAPPMGR2" #define MAINWINDOWMUTEX szWindowClass diff --git a/base/applications/rapps/loaddlg.cpp b/base/applications/rapps/loaddlg.cpp index c863a5e2165..21b7b88d1fc 100644 --- a/base/applications/rapps/loaddlg.cpp +++ b/base/applications/rapps/loaddlg.cpp @@ -142,8 +142,7 @@ struct DownloadInfo AppInfo.GetDownloadInfo(szUrl, szSHA1, SizeInBytes); szName = AppInfo.szDisplayName; IType = AppInfo.GetInstallerType(); - if (IType == INSTALLER_GENERATE) - szPackageName = AppInfo.szIdentifier; + szPackageName = AppInfo.szIdentifier; CConfigParser *cfg = static_cast<const CAvailableApplicationInfo&>(AppInfo).GetConfigParser(); if (cfg) @@ -452,6 +451,8 @@ ShowLastError(HWND hWndOwner, BOOL bInetError, DWORD dwLastError) return FALSE; } + if (hWndOwner && !IsWindowVisible(hWndOwner)) + hWndOwner = NULL; MessageBoxW(hWndOwner, lpMsg, NULL, MB_OK | MB_ICONERROR); return TRUE; } @@ -1090,8 +1091,12 @@ run: SendMessageW(hDlg, WM_SETSTATUS, DLSTATUS_INSTALLING, 0); // TODO: issue an install operation separately so that the apps could be downloaded in the background - WaitForSingleObject(shExInfo.hProcess, INFINITE); - CloseHandle(shExInfo.hProcess); + if (shExInfo.hProcess) + { + WaitForSingleObject(shExInfo.hProcess, INFINITE); + CloseHandle(shExInfo.hProcess); + SendMessageW(hMainWnd, WM_NOTIFY_INSTALLERFINISHED, 0, (LPARAM)(PCWSTR)Info.szPackageName); + } } else { diff --git a/base/applications/rapps/misc.cpp b/base/applications/rapps/misc.cpp index c5fe6f0c4bc..baafe5309fd 100644 --- a/base/applications/rapps/misc.cpp +++ b/base/applications/rapps/misc.cpp @@ -160,6 +160,8 @@ StartProcess(const CStringW &Path, BOOL Wait) { EnableWindow(hMainWnd, TRUE); SetForegroundWindow(hMainWnd); + // We got the real activation message during MsgWaitForMultipleObjects while + // we were disabled, we need to set the focus again now. SetFocus(hMainWnd); } diff --git a/base/applications/rapps/unattended.cpp b/base/applications/rapps/unattended.cpp index 4967f259de3..06db5f0aba6 100644 --- a/base/applications/rapps/unattended.cpp +++ b/base/applications/rapps/unattended.cpp @@ -191,7 +191,7 @@ HandleUninstallCommand(CAppDB &db, UINT argcLeft, LPWSTR *argvLeft) if (pInfo) { - retval = pInfo->UninstallApplication(silent ? UCF_SILENT : UCF_NONE); + retval = pInfo->UninstallApplication((silent ? UCF_SILENT : UCF_NONE) | UCF_SAMEPROCESS); } delete pDelete; return retval; @@ -368,7 +368,7 @@ ParseCmdAndExecute(LPWSTR lpCmdLine, BOOL bIsFirstLaunch, int nCmdShow) if (hWindow) { /* Activate the window in the other instance */ - ShowWindow(hWindow, SW_SHOW); + ShowWindow(hWindow, SW_SHOWNA); SwitchToThisWindow(hWindow, TRUE); if (bAppwizMode) PostMessage(hWindow, WM_COMMAND, ID_ACTIVATE_APPWIZ, 0);
4Â months, 3Â weeks
1
0
0
0
[reactos] 01/01: [WINVER] Display compatibility information (#7661)
by Thamatip Chitpong
https://git.reactos.org/?p=reactos.git;a=commitdiff;h=a610016952841038e0c29…
commit a610016952841038e0c294ad4383a1a33ca6588b Author: Thamatip Chitpong <thamatip.chitpong(a)reactos.org> AuthorDate: Sat Feb 8 00:05:03 2025 +0700 Commit: GitHub <noreply(a)github.com> CommitDate: Sat Feb 8 00:05:03 2025 +0700 [WINVER] Display compatibility information (#7661) Also don't hardcode the OS name. This make it compatible with Windows. --- base/applications/winver/CMakeLists.txt | 10 ++- base/applications/winver/lang/en-US.rc | 14 ++++ base/applications/winver/osinfo.c | 126 ++++++++++++++++++++++++++++++++ base/applications/winver/resource.h | 11 +++ base/applications/winver/winver.c | 24 +++--- base/applications/winver/winver.rc | 9 +++ base/applications/winver/winver_p.h | 34 +++++++++ 7 files changed, 217 insertions(+), 11 deletions(-) diff --git a/base/applications/winver/CMakeLists.txt b/base/applications/winver/CMakeLists.txt index ac5b762b83d..9837665d4e5 100644 --- a/base/applications/winver/CMakeLists.txt +++ b/base/applications/winver/CMakeLists.txt @@ -1,5 +1,11 @@ -add_executable(winver winver.c winver.rc) +list(APPEND SOURCE + osinfo.c + winver.c + winver_p.h) + +add_executable(winver ${SOURCE} winver.rc) +add_pch(winver winver_p.h SOURCE) set_module_type(winver win32gui UNICODE) -add_importlibs(winver shell32 comctl32 msvcrt kernel32) +add_importlibs(winver advapi32 user32 shell32 comctl32 msvcrt kernel32) add_cd_file(TARGET winver DESTINATION reactos/system32 FOR all) diff --git a/base/applications/winver/lang/en-US.rc b/base/applications/winver/lang/en-US.rc new file mode 100644 index 00000000000..d4ec8dd84d9 --- /dev/null +++ b/base/applications/winver/lang/en-US.rc @@ -0,0 +1,14 @@ +/* + * PROJECT: ReactOS Version Program + * LICENSE: MIT (
https://spdx.org/licenses/MIT
) + * PURPOSE: English (United States) resource file + * TRANSLATOR: Copyright 2025 Thamatip Chitpong <thamatip.chitpong(a)reactos.org> + */ + +LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_US + +STRINGTABLE +BEGIN + IDS_OSINFO_COMPAT_FORMAT "Reporting NT %s (Build %s%s)" + IDS_OSINFO_SPK_FORMAT ": %s" +END diff --git a/base/applications/winver/osinfo.c b/base/applications/winver/osinfo.c new file mode 100644 index 00000000000..ff79baa3aab --- /dev/null +++ b/base/applications/winver/osinfo.c @@ -0,0 +1,126 @@ +/* + * PROJECT: ReactOS Version Program + * LICENSE: MIT (
https://spdx.org/licenses/MIT
) + * PURPOSE: Retrieve OS name and simple compatibility information + * COPYRIGHT: Copyright 2025 Thamatip Chitpong <thamatip.chitpong(a)reactos.org> + */ + +#include "winver_p.h" + +#define OSINFO_KEY L"SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion" + +static +VOID +Winver_GetRegValueString( + _In_ HKEY hKey, + _In_ LPCWSTR pValue, + _Out_ LPWSTR pBuffer, + _In_ DWORD cchSize) +{ + DWORD dwType, dwSize; + LSTATUS lError; + + /* NOTE: Reserved space for a NULL terminator */ + dwSize = (cchSize - 1) * sizeof(WCHAR); + lError = RegQueryValueExW(hKey, pValue, NULL, &dwType, (LPBYTE)pBuffer, &dwSize); + if (lError != ERROR_SUCCESS || dwType != REG_SZ) + { + /* Return empty string on failure */ + pBuffer[0] = UNICODE_NULL; + return; + } + + /* Ensure the returned string is NULL terminated */ + pBuffer[cchSize - 1] = UNICODE_NULL; +} + +static +VOID +Winver_GetFormattedSpkInfo( + _In_ HKEY hKey, + _Out_ LPWSTR pBuffer, + _In_ DWORD cchSize) +{ + WCHAR szRegValue[48]; + WCHAR szFormat[16] = L""; + + Winver_GetRegValueString(hKey, L"CSDVersion", szRegValue, _countof(szRegValue)); + if (!szRegValue[0]) + { + /* Return empty string on failure */ + pBuffer[0] = UNICODE_NULL; + return; + } + + LoadStringW(Winver_hInstance, + IDS_OSINFO_SPK_FORMAT, + szFormat, + _countof(szFormat)); + + StringCchPrintfW(pBuffer, cchSize, szFormat, szRegValue); +} + +static +VOID +Winver_FormatCompatInfo( + _In_ HKEY hKey, + _Out_ LPWSTR pBuffer, + _In_ DWORD cchSize) +{ + WCHAR szNtVersion[16]; + WCHAR szNtBuild[16]; + WCHAR szNtSpk[64]; + WCHAR szFormat[64] = L""; + + /* NOTE: Required info must be valid */ + Winver_GetRegValueString(hKey, L"CurrentVersion", szNtVersion, _countof(szNtVersion)); + Winver_GetRegValueString(hKey, L"CurrentBuildNumber", szNtBuild, _countof(szNtBuild)); + if (!szNtVersion[0] || !szNtBuild[0]) + { + /* Return empty string on failure */ + pBuffer[0] = UNICODE_NULL; + return; + } + + /* NOTE: Service pack info is optional */ + Winver_GetFormattedSpkInfo(hKey, szNtSpk, _countof(szNtSpk)); + + LoadStringW(Winver_hInstance, + IDS_OSINFO_COMPAT_FORMAT, + szFormat, + _countof(szFormat)); + + StringCchPrintfW(pBuffer, cchSize, szFormat, szNtVersion, szNtBuild, szNtSpk); +} + +BOOL +Winver_GetOSInfo( + _Out_ PWINVER_OS_INFO OSInfo) +{ + HKEY hKey; + LSTATUS lError; + + lError = RegOpenKeyExW(HKEY_LOCAL_MACHINE, + OSINFO_KEY, + 0, + KEY_QUERY_VALUE, + &hKey); + if (lError != ERROR_SUCCESS) + return FALSE; + + /* OS name */ + Winver_GetRegValueString(hKey, L"ProductName", OSInfo->szName, _countof(OSInfo->szName)); + if (!OSInfo->szName[0]) + { + /* This info must be valid */ + RegCloseKey(hKey); + return FALSE; + } + + /* Compatibility information */ + Winver_FormatCompatInfo(hKey, OSInfo->szCompatInfo, _countof(OSInfo->szCompatInfo)); + + RegCloseKey(hKey); + + return TRUE; +} diff --git a/base/applications/winver/resource.h b/base/applications/winver/resource.h new file mode 100644 index 00000000000..ca00ee82314 --- /dev/null +++ b/base/applications/winver/resource.h @@ -0,0 +1,11 @@ +/* + * PROJECT: ReactOS Version Program + * LICENSE: MIT (
https://spdx.org/licenses/MIT
) + * PURPOSE: Resource header file + * COPYRIGHT: Copyright 2025 Thamatip Chitpong <thamatip.chitpong(a)reactos.org> + */ + +#pragma once + +#define IDS_OSINFO_COMPAT_FORMAT 1 +#define IDS_OSINFO_SPK_FORMAT 2 diff --git a/base/applications/winver/winver.c b/base/applications/winver/winver.c index 1e22096c4ee..3eb2a9e3adf 100644 --- a/base/applications/winver/winver.c +++ b/base/applications/winver/winver.c @@ -4,26 +4,32 @@ * FILE: base/applications/winver/winver.c */ -#include <stdarg.h> -#include <windef.h> -#include <winbase.h> -#include <winuser.h> -#include <commctrl.h> -#include <shellapi.h> +#include "winver_p.h" + +HINSTANCE Winver_hInstance; int WINAPI wWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPWSTR lpCmdLine, int nCmdShow) { INITCOMMONCONTROLSEX iccx; + WINVER_OS_INFO OSInfo; - UNREFERENCED_PARAMETER(hInstance); UNREFERENCED_PARAMETER(hPrevInstance); UNREFERENCED_PARAMETER(lpCmdLine); UNREFERENCED_PARAMETER(nCmdShow); + Winver_hInstance = hInstance; + /* Initialize common controls */ - iccx.dwSize = sizeof(INITCOMMONCONTROLSEX); + iccx.dwSize = sizeof(iccx); iccx.dwICC = ICC_STANDARD_CLASSES | ICC_WIN95_CLASSES; InitCommonControlsEx(&iccx); - return ShellAboutW(NULL, L"ReactOS", NULL, NULL); + if (!Winver_GetOSInfo(&OSInfo)) + { + /* OS info is not available, display the default contents */ + StringCchCopyW(OSInfo.szName, _countof(OSInfo.szName), L"ReactOS"); + OSInfo.szCompatInfo[0] = UNICODE_NULL; + } + + return ShellAboutW(NULL, OSInfo.szName, OSInfo.szCompatInfo, NULL); } diff --git a/base/applications/winver/winver.rc b/base/applications/winver/winver.rc index 050ae694370..1d9dec6f9d9 100644 --- a/base/applications/winver/winver.rc +++ b/base/applications/winver/winver.rc @@ -2,9 +2,18 @@ #include <windef.h> #include <winuser.h> +#include "resource.h" + #define REACTOS_STR_FILE_DESCRIPTION "ReactOS Version Program" #define REACTOS_STR_INTERNAL_NAME "winver" #define REACTOS_STR_ORIGINAL_FILENAME "winver.exe" #include <reactos/version.rc> #include <reactos/manifest_exe.rc> + +/* UTF-8 */ +#pragma code_page(65001) + +#ifdef LANGUAGE_EN_US + #include "lang/en-US.rc" +#endif diff --git a/base/applications/winver/winver_p.h b/base/applications/winver/winver_p.h new file mode 100644 index 00000000000..b7b76ed5db9 --- /dev/null +++ b/base/applications/winver/winver_p.h @@ -0,0 +1,34 @@ +/* + * PROJECT: ReactOS Version Program + * LICENSE: MIT (
https://spdx.org/licenses/MIT
) + * PURPOSE: Main header file + * COPYRIGHT: Copyright 2025 Thamatip Chitpong <thamatip.chitpong(a)reactos.org> + */ + +#pragma once + +#include <stdarg.h> +#include <stdlib.h> + +#include <windef.h> +#include <winbase.h> +#include <winreg.h> +#include <winuser.h> +#include <commctrl.h> +#include <shellapi.h> + +#include <strsafe.h> + +#include "resource.h" + +typedef struct _WINVER_OS_INFO +{ + WCHAR szName[64]; + WCHAR szCompatInfo[256]; +} WINVER_OS_INFO, *PWINVER_OS_INFO; + +extern HINSTANCE Winver_hInstance; + +BOOL +Winver_GetOSInfo( + _Out_ PWINVER_OS_INFO OSInfo);
4Â months, 3Â weeks
1
0
0
0
[reactos] 02/02: [WINDOWSCODECS][WINDOWSCODECSEXT] Sync to wine-10.0 (#7665)
by Mikhail Tyukin
https://git.reactos.org/?p=reactos.git;a=commitdiff;h=197ed01e95f242af87a39…
commit 197ed01e95f242af87a3905d83c2cd22326a7668 Author: Mikhail Tyukin <mishakeys20(a)gmail.com> AuthorDate: Sun Jan 26 12:59:50 2025 -0500 Commit: Hermès Bélusca-Maïto <hermes.belusca-maito(a)reactos.org> CommitDate: Fri Feb 7 16:57:02 2025 +0100 [WINDOWSCODECS][WINDOWSCODECSEXT] Sync to wine-10.0 (#7665) --- dll/win32/windowscodecs/CMakeLists.txt | 19 +- dll/win32/windowscodecs/bitmap.c | 55 +- dll/win32/windowscodecs/bmpdecode.c | 82 +- dll/win32/windowscodecs/bmpencode.c | 44 +- dll/win32/windowscodecs/clipper.c | 12 +- dll/win32/windowscodecs/clsfactory.c | 24 +- dll/win32/windowscodecs/colorcontext.c | 24 +- dll/win32/windowscodecs/colortransform.c | 10 +- dll/win32/windowscodecs/converter.c | 276 +- dll/win32/windowscodecs/ddsformat.c | 2162 +++++++++++++ dll/win32/windowscodecs/decoder.c | 811 +++++ dll/win32/windowscodecs/encoder.c | 903 ++++++ dll/win32/windowscodecs/fliprotate.c | 14 +- dll/win32/windowscodecs/gifformat.c | 521 ++-- dll/win32/windowscodecs/icnsformat.c | 743 ----- dll/win32/windowscodecs/icoformat.c | 40 +- dll/win32/windowscodecs/imgfactory.c | 470 ++- dll/win32/windowscodecs/info.c | 309 +- dll/win32/windowscodecs/jpegformat.c | 1562 ---------- dll/win32/windowscodecs/libjpeg.c | 662 ++++ dll/win32/windowscodecs/libpng.c | 842 +++++ dll/win32/windowscodecs/libtiff.c | 1352 +++++++++ dll/win32/windowscodecs/main.c | 230 +- dll/win32/windowscodecs/metadatahandler.c | 295 +- dll/win32/windowscodecs/metadataquery.c | 580 ++-- dll/win32/windowscodecs/palette.c | 56 +- dll/win32/windowscodecs/pngformat.c | 2093 +------------ dll/win32/windowscodecs/precomp.h | 3 +- dll/win32/windowscodecs/propertybag.c | 33 +- dll/win32/windowscodecs/proxy.c | 2 - dll/win32/windowscodecs/regsvr.c | 207 +- dll/win32/windowscodecs/scaler.c | 28 +- dll/win32/windowscodecs/stream.c | 108 +- dll/win32/windowscodecs/tgaformat.c | 34 +- dll/win32/windowscodecs/tiffformat.c | 2385 --------------- dll/win32/windowscodecs/ungif.c | 93 +- dll/win32/windowscodecs/ungif.h | 7 +- dll/win32/windowscodecs/uuid.c | 36 + dll/win32/windowscodecs/wincodecs_common.c | 211 ++ dll/win32/windowscodecs/wincodecs_common.h | 214 ++ dll/win32/windowscodecs/wincodecs_private.h | 325 +- dll/win32/windowscodecs/windowscodecs_wincodec.idl | 32 +- dll/win32/windowscodecsext/main.c | 18 - media/doc/WINESYNC.txt | 4 +- .../winetests/windowscodecs/CMakeLists.txt | 8 +- modules/rostests/winetests/windowscodecs/bitmap.c | 460 +-- .../rostests/winetests/windowscodecs/bmpformat.c | 647 +++- .../rostests/winetests/windowscodecs/converter.c | 578 ++-- .../rostests/winetests/windowscodecs/ddsformat.c | 1579 ++++++++++ .../rostests/winetests/windowscodecs/gifformat.c | 198 +- .../rostests/winetests/windowscodecs/icoformat.c | 20 +- modules/rostests/winetests/windowscodecs/info.c | 263 +- .../rostests/winetests/windowscodecs/jpegformat.c | 38 +- .../rostests/winetests/windowscodecs/metadata.c | 3204 ++++++++++++++------ modules/rostests/winetests/windowscodecs/palette.c | 154 +- .../rostests/winetests/windowscodecs/pngformat.c | 203 +- .../rostests/winetests/windowscodecs/propertybag.c | 56 +- modules/rostests/winetests/windowscodecs/stream.c | 438 +-- .../rostests/winetests/windowscodecs/testlist.c | 4 + .../rostests/winetests/windowscodecs/tiffformat.c | 344 ++- .../rostests/winetests/windowscodecs/wmpformat.c | 182 ++ .../winetests/windowscodecsext/CMakeLists.txt | 1 + .../winetests/windowscodecsext/transform.c | 12 +- sdk/include/psdk/CMakeLists.txt | 1 + sdk/include/psdk/dxgiformat.idl | 145 + sdk/include/psdk/wincodec.idl | 137 + sdk/include/psdk/wincodecsdk.idl | 82 + sdk/tools/winesync/windowscodecs.cfg | 10 + 68 files changed, 16270 insertions(+), 10425 deletions(-) diff --git a/dll/win32/windowscodecs/CMakeLists.txt b/dll/win32/windowscodecs/CMakeLists.txt index ee7ff716e3b..c8e043b4979 100644 --- a/dll/win32/windowscodecs/CMakeLists.txt +++ b/dll/win32/windowscodecs/CMakeLists.txt @@ -1,12 +1,12 @@ add_definitions( -D__WINESRC__ - -D__ROS_LONG64__ -DENTRY_PREFIX=WIC_ -DPROXY_DELEGATION -DWINE_REGISTER_DLL) remove_definitions(-D_WIN32_WINNT=0x502) +remove_definitions(-D_CRT_NON_CONFORMING_SWPRINTFS) add_definitions(-D_WIN32_WINNT=0x600) include_directories( @@ -27,13 +27,17 @@ list(APPEND SOURCE colorcontext.c colortransform.c converter.c + ddsformat.c + decoder.c + encoder.c fliprotate.c gifformat.c - icnsformat.c icoformat.c imgfactory.c info.c - jpegformat.c + libjpeg.c + libpng.c + libtiff.c main.c metadatahandler.c metadataquery.c @@ -45,8 +49,9 @@ list(APPEND SOURCE scaler.c stream.c tgaformat.c - tiffformat.c - ungif.c) + ungif.c + uuid.c + wincodecs_common.c) if(MSVC) if(ARCH STREQUAL "i386") @@ -79,7 +84,7 @@ if(MSVC) endif() set_module_type(windowscodecs win32dll) -target_link_libraries(windowscodecs wine uuid ${PSEH_LIB}) -add_importlibs(windowscodecs ole32 oleaut32 rpcrt4 shlwapi user32 gdi32 advapi32 advapi32_vista propsys msvcrt kernel32 ntdll) +target_link_libraries(windowscodecs wine uuid ${PSEH_LIB} oldnames) +add_importlibs(windowscodecs libjpeg libpng libtiff ole32 oleaut32 rpcrt4 shlwapi user32 gdi32 advapi32 advapi32_vista propsys msvcrt kernel32 ntdll) add_pch(windowscodecs precomp.h "${PCH_SKIP_SOURCE}") add_cd_file(TARGET windowscodecs DESTINATION reactos/system32 FOR all) diff --git a/dll/win32/windowscodecs/bitmap.c b/dll/win32/windowscodecs/bitmap.c index 7959da6911d..dee3f28d5d7 100644 --- a/dll/win32/windowscodecs/bitmap.c +++ b/dll/win32/windowscodecs/bitmap.c @@ -17,10 +17,6 @@ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA */ -#ifndef __REACTOS__ -#include "config.h" -#endif - #include <stdarg.h> #define COBJMACROS @@ -34,6 +30,9 @@ #include "wine/asm.h" #include "wine/debug.h" +#include "initguid.h" +DEFINE_GUID(IID_CMetaBitmapRenderTarget, 0x0ccd7824,0xdc16,0x4d09,0xbc,0xa8,0x6b,0x09,0xc4,0xef,0x55,0x35); + WINE_DEFAULT_DEBUG_CHANNEL(wincodecs); /* WARNING: .NET Media Integration Layer (MIL) directly dereferences @@ -82,11 +81,6 @@ static inline BitmapImpl *impl_from_IMILUnknown1(IMILUnknown1 *iface) return CONTAINING_RECORD(iface, BitmapImpl, IMILUnknown1_iface); } -static inline BitmapImpl *impl_from_IMILUnknown2(IMILUnknown2 *iface) -{ - return CONTAINING_RECORD(iface, BitmapImpl, IMILUnknown2_iface); -} - static inline BitmapLockImpl *impl_from_IWICBitmapLock(IWICBitmapLock *iface) { return CONTAINING_RECORD(iface, BitmapLockImpl, IWICBitmapLock_iface); @@ -155,7 +149,7 @@ static ULONG WINAPI BitmapLockImpl_AddRef(IWICBitmapLock *iface) BitmapLockImpl *This = impl_from_IWICBitmapLock(iface); ULONG ref = InterlockedIncrement(&This->ref); - TRACE("(%p) refcount=%u\n", iface, ref); + TRACE("(%p) refcount=%lu\n", iface, ref); return ref; } @@ -165,13 +159,13 @@ static ULONG WINAPI BitmapLockImpl_Release(IWICBitmapLock *iface) BitmapLockImpl *This = impl_from_IWICBitmapLock(iface); ULONG ref = InterlockedDecrement(&This->ref); - TRACE("(%p) refcount=%u\n", iface, ref); + TRACE("(%p) refcount=%lu\n", iface, ref); if (ref == 0) { BitmapImpl_ReleaseLock(This->parent); IWICBitmap_Release(&This->parent->IWICBitmap_iface); - HeapFree(GetProcessHeap(), 0, This); + free(This); } return ref; @@ -262,7 +256,10 @@ static HRESULT WINAPI BitmapImpl_QueryInterface(IWICBitmap *iface, REFIID iid, } else { - FIXME("unknown interface %s\n", debugstr_guid(iid)); + if (IsEqualIID(&IID_CMetaBitmapRenderTarget, iid)) + WARN("Ignoring interface %s\n", debugstr_guid(iid)); + else + FIXME("unknown interface %s\n", debugstr_guid(iid)); *ppv = NULL; return E_NOINTERFACE; } @@ -276,7 +273,7 @@ static ULONG WINAPI BitmapImpl_AddRef(IWICBitmap *iface) BitmapImpl *This = impl_from_IWICBitmap(iface); ULONG ref = InterlockedIncrement(&This->ref); - TRACE("(%p) refcount=%u\n", iface, ref); + TRACE("(%p) refcount=%lu\n", iface, ref); return ref; } @@ -286,7 +283,7 @@ static ULONG WINAPI BitmapImpl_Release(IWICBitmap *iface) BitmapImpl *This = impl_from_IWICBitmap(iface); ULONG ref = InterlockedDecrement(&This->ref); - TRACE("(%p) refcount=%u\n", iface, ref); + TRACE("(%p) refcount=%lu\n", iface, ref); if (ref == 0) { @@ -296,8 +293,8 @@ static ULONG WINAPI BitmapImpl_Release(IWICBitmap *iface) if (This->view) UnmapViewOfFile(This->view); else - HeapFree(GetProcessHeap(), 0, This->data); - HeapFree(GetProcessHeap(), 0, This); + free(This->data); + free(This); } return ref; @@ -378,7 +375,7 @@ static HRESULT WINAPI BitmapImpl_Lock(IWICBitmap *iface, const WICRect *prcLock, BitmapLockImpl *result; WICRect rc; - TRACE("(%p,%s,%x,%p)\n", iface, debug_wic_rect(prcLock), flags, ppILock); + TRACE("(%p,%s,%lx,%p)\n", iface, debug_wic_rect(prcLock), flags, ppILock); if (!(flags & (WICBitmapLockRead|WICBitmapLockWrite)) || !ppILock) return E_INVALIDARG; @@ -401,13 +398,13 @@ static HRESULT WINAPI BitmapImpl_Lock(IWICBitmap *iface, const WICRect *prcLock, return E_FAIL; } - result = HeapAlloc(GetProcessHeap(), 0, sizeof(BitmapLockImpl)); + result = malloc(sizeof(BitmapLockImpl)); if (!result) return E_OUTOFMEMORY; if (!BitmapImpl_AcquireLock(This, flags & WICBitmapLockWrite)) { - HeapFree(GetProcessHeap(), 0, result); + free(result); return WINCODEC_ERR_ALREADYLOCKED; } @@ -605,7 +602,7 @@ static HRESULT WINAPI IMILBitmapImpl_unknown1(IMILBitmap *iface, void **ppv) static HRESULT WINAPI IMILBitmapImpl_Lock(IMILBitmap *iface, const WICRect *rc, DWORD flags, IWICBitmapLock **lock) { BitmapImpl *This = impl_from_IMILBitmap(iface); - TRACE("(%p,%p,%08x,%p)\n", iface, rc, flags, lock); + TRACE("(%p,%p,%08lx,%p)\n", iface, rc, flags, lock); return IWICBitmap_Lock(&This->IWICBitmap_iface, rc, flags, lock); } @@ -675,7 +672,7 @@ static ULONG WINAPI IMILUnknown1Impl_Release(IMILUnknown1 *iface) return IWICBitmap_Release(&This->IWICBitmap_iface); } -DECLSPEC_HIDDEN void WINAPI IMILUnknown1Impl_unknown1(IMILUnknown1 *iface, void *arg) +void WINAPI IMILUnknown1Impl_unknown1(IMILUnknown1 *iface, void *arg) { FIXME("(%p,%p): stub\n", iface, arg); } @@ -686,7 +683,7 @@ static HRESULT WINAPI IMILUnknown1Impl_unknown2(IMILUnknown1 *iface, void *arg1, return E_NOTIMPL; } -DECLSPEC_HIDDEN HRESULT WINAPI IMILUnknown1Impl_unknown3(IMILUnknown1 *iface, void *arg) +HRESULT WINAPI IMILUnknown1Impl_unknown3(IMILUnknown1 *iface, void *arg) { FIXME("(%p,%p): stub\n", iface, arg); return E_NOTIMPL; @@ -716,7 +713,7 @@ static HRESULT WINAPI IMILUnknown1Impl_unknown7(IMILUnknown1 *iface, void *arg) return E_NOTIMPL; } -DECLSPEC_HIDDEN HRESULT WINAPI IMILUnknown1Impl_unknown8(IMILUnknown1 *iface) +HRESULT WINAPI IMILUnknown1Impl_unknown8(IMILUnknown1 *iface) { FIXME("(%p): stub\n", iface); return E_NOTIMPL; @@ -808,13 +805,13 @@ HRESULT BitmapImpl_Create(UINT uiWidth, UINT uiHeight, UINT stride, UINT datasiz if (datasize < stride * uiHeight) return WINCODEC_ERR_INSUFFICIENTBUFFER; if (stride < ((bpp*uiWidth)+7)/8) return E_INVALIDARG; - This = HeapAlloc(GetProcessHeap(), 0, sizeof(BitmapImpl)); + This = malloc(sizeof(BitmapImpl)); if (!This) return E_OUTOFMEMORY; if (view) data = (BYTE *)view + offset; - else if (!(data = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, datasize))) + else if (!(data = calloc(1, datasize))) { - HeapFree(GetProcessHeap(), 0, This); + free(This); return E_OUTOFMEMORY; } @@ -835,7 +832,11 @@ HRESULT BitmapImpl_Create(UINT uiWidth, UINT uiHeight, UINT stride, UINT datasiz This->bpp = bpp; memcpy(&This->pixelformat, pixelFormat, sizeof(GUID)); This->dpix = This->dpiy = 0.0; +#ifdef __REACTOS__ InitializeCriticalSection(&This->cs); +#else + InitializeCriticalSectionEx(&This->cs, 0, RTL_CRITICAL_SECTION_FLAG_FORCE_DEBUG_INFO); +#endif This->cs.DebugInfo->Spare[0] = (DWORD_PTR)(__FILE__ ": BitmapImpl.lock"); *ppIBitmap = &This->IWICBitmap_iface; diff --git a/dll/win32/windowscodecs/bmpdecode.c b/dll/win32/windowscodecs/bmpdecode.c index 5ee4ac38ccb..9eb74b3d7cc 100644 --- a/dll/win32/windowscodecs/bmpdecode.c +++ b/dll/win32/windowscodecs/bmpdecode.c @@ -16,8 +16,6 @@ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA */ -#include "config.h" - #include <assert.h> #include <stdarg.h> @@ -226,9 +224,9 @@ static HRESULT WINAPI BmpFrameDecode_CopyPalette(IWICBitmapFrameDecode *iface, int i; count = 1 << bch->bcBitCount; - wiccolors = HeapAlloc(GetProcessHeap(), 0, sizeof(WICColor) * count); + wiccolors = malloc(sizeof(WICColor) * count); tablesize = sizeof(RGBTRIPLE) * count; - bgrcolors = HeapAlloc(GetProcessHeap(), 0, tablesize); + bgrcolors = malloc(tablesize); if (!wiccolors || !bgrcolors) { hr = E_OUTOFMEMORY; @@ -274,7 +272,7 @@ static HRESULT WINAPI BmpFrameDecode_CopyPalette(IWICBitmapFrameDecode *iface, count = min(This->bih.bV5ClrUsed, 1 << This->bih.bV5BitCount); tablesize = sizeof(WICColor) * count; - wiccolors = HeapAlloc(GetProcessHeap(), 0, tablesize); + wiccolors = malloc(tablesize); if (!wiccolors) { hr = E_OUTOFMEMORY; @@ -310,8 +308,8 @@ end: if (SUCCEEDED(hr)) hr = IWICPalette_InitializeCustom(pIPalette, wiccolors, count); - HeapFree(GetProcessHeap(), 0, wiccolors); - HeapFree(GetProcessHeap(), 0, bgrcolors); + free(wiccolors); + free(bgrcolors); return hr; } @@ -388,7 +386,7 @@ static HRESULT BmpFrameDecode_ReadUncompressed(BmpDecoder* This) bytesperrow = (((width * This->bitsperpixel)+31)/32)*4; datasize = bytesperrow * height; - This->imagedata = HeapAlloc(GetProcessHeap(), 0, datasize); + This->imagedata = malloc(datasize); if (!This->imagedata) return E_OUTOFMEMORY; offbits.QuadPart = This->image_offset; @@ -411,12 +409,45 @@ static HRESULT BmpFrameDecode_ReadUncompressed(BmpDecoder* This) return S_OK; fail: - HeapFree(GetProcessHeap(), 0, This->imagedata); + free(This->imagedata); This->imagedata = NULL; if (SUCCEEDED(hr)) hr = E_FAIL; return hr; } +static HRESULT BmpFrameDecode_ReadABGRasBGR(BmpDecoder* This) +{ + UINT x, y, width, height; + BYTE *pixel; + HRESULT hr; + + hr = IWICBitmapFrameDecode_GetSize(&This->IWICBitmapFrameDecode_iface, &width, &height); + + if (SUCCEEDED(hr)) + { + hr = BmpFrameDecode_ReadUncompressed(This); + } + + if (SUCCEEDED(hr)) + { + for (y = 0; y < height; y++) + { + pixel = This->imagedatastart + This->stride * (INT)y; + + for (x = 0; x < width; x++) + { + pixel[0] = pixel[1]; + pixel[1] = pixel[2]; + pixel[2] = pixel[3]; + pixel[3] = 0; + pixel += 4; + } + } + } + + return hr; +} + static HRESULT BmpFrameDecode_ReadRGB8(BmpDecoder* This) { HRESULT hr; @@ -482,7 +513,7 @@ static HRESULT BmpFrameDecode_ReadRLE8(BmpDecoder* This) else palettesize = 4 * 256; - This->imagedata = HeapAlloc(GetProcessHeap(), 0, datasize); + This->imagedata = malloc(datasize); if (!This->imagedata) { hr = E_OUTOFMEMORY; @@ -578,7 +609,7 @@ end: return S_OK; fail: - HeapFree(GetProcessHeap(), 0, This->imagedata); + free(This->imagedata); This->imagedata = NULL; if (SUCCEEDED(hr)) hr = E_FAIL; return hr; @@ -606,7 +637,7 @@ static HRESULT BmpFrameDecode_ReadRLE4(BmpDecoder* This) else palettesize = 4 * 16; - This->imagedata = HeapAlloc(GetProcessHeap(), 0, datasize); + This->imagedata = malloc(datasize); if (!This->imagedata) { hr = E_OUTOFMEMORY; @@ -718,7 +749,7 @@ end: return S_OK; fail: - HeapFree(GetProcessHeap(), 0, This->imagedata); + free(This->imagedata); This->imagedata = NULL; if (SUCCEEDED(hr)) hr = E_FAIL; return hr; @@ -744,7 +775,7 @@ static const struct bitfields_format bitfields_formats[] = { {16,0xf800,0x7e0,0x1f,0,&GUID_WICPixelFormat16bppBGR565,BmpFrameDecode_ReadUncompressed}, {32,0xff0000,0xff00,0xff,0,&GUID_WICPixelFormat32bppBGR,BmpFrameDecode_ReadUncompressed}, {32,0xff0000,0xff00,0xff,0xff000000,&GUID_WICPixelFormat32bppBGRA,BmpFrameDecode_ReadUncompressed}, - {32,0xff000000,0xff0000,0xff00,0xff,&GUID_WICPixelFormat32bppRGBA,BmpFrameDecode_ReadUncompressed}, + {32,0xff000000,0xff0000,0xff00,0xff,&GUID_WICPixelFormat32bppBGR,BmpFrameDecode_ReadABGRasBGR}, {32,0xff,0xff00,0xff0000,0,&GUID_WICPixelFormat32bppBGR,BmpFrameDecode_ReadRGB8}, {0} }; @@ -861,7 +892,7 @@ static HRESULT BmpDecoder_ReadHeaders(BmpDecoder* This, IStream *stream) } else /* struct is compatible with BITMAPINFOHEADER */ { - TRACE("bitmap header=%i compression=%i depth=%i\n", This->bih.bV5Size, This->bih.bV5Compression, This->bih.bV5BitCount); + TRACE("bitmap header=%li compression=%li depth=%i\n", This->bih.bV5Size, This->bih.bV5Compression, This->bih.bV5BitCount); switch(This->bih.bV5Compression) { case BI_RGB: @@ -935,7 +966,7 @@ static HRESULT BmpDecoder_ReadHeaders(BmpDecoder* This, IStream *stream) { This->read_data_func = BmpFrameDecode_ReadUncompressed; This->pixelformat = &GUID_WICPixelFormatUndefined; - FIXME("unsupported bitfields type depth=%i red=%x green=%x blue=%x alpha=%x\n", + FIXME("unsupported bitfields type depth=%i red=%lx green=%lx blue=%lx alpha=%lx\n", This->bih.bV5BitCount, This->bih.bV5RedMask, This->bih.bV5GreenMask, This->bih.bV5BlueMask, This->bih.bV5AlphaMask); } break; @@ -944,7 +975,7 @@ static HRESULT BmpDecoder_ReadHeaders(BmpDecoder* This, IStream *stream) This->bitsperpixel = 0; This->read_data_func = BmpFrameDecode_ReadUnsupported; This->pixelformat = &GUID_WICPixelFormatUndefined; - FIXME("unsupported bitmap type header=%i compression=%i depth=%i\n", This->bih.bV5Size, This->bih.bV5Compression, This->bih.bV5BitCount); + FIXME("unsupported bitmap type header=%li compression=%li depth=%i\n", This->bih.bV5Size, This->bih.bV5Compression, This->bih.bV5BitCount); break; } } @@ -999,7 +1030,7 @@ static ULONG WINAPI BmpDecoder_AddRef(IWICBitmapDecoder *iface) BmpDecoder *This = impl_from_IWICBitmapDecoder(iface); ULONG ref = InterlockedIncrement(&This->ref); - TRACE("(%p) refcount=%u\n", iface, ref); + TRACE("(%p) refcount=%lu\n", iface, ref); return ref; } @@ -1009,15 +1040,15 @@ static ULONG WINAPI BmpDecoder_Release(IWICBitmapDecoder *iface) BmpDecoder *This = impl_from_IWICBitmapDecoder(iface); ULONG ref = InterlockedDecrement(&This->ref); - TRACE("(%p) refcount=%u\n", iface, ref); + TRACE("(%p) refcount=%lu\n", iface, ref); if (ref == 0) { if (This->stream) IStream_Release(This->stream); - HeapFree(GetProcessHeap(), 0, This->imagedata); + free(This->imagedata); This->lock.DebugInfo->Spare[0] = 0; DeleteCriticalSection(&This->lock); - HeapFree(GetProcessHeap(), 0, This); + free(This); } return ref; @@ -1155,7 +1186,7 @@ static HRESULT BmpDecoder_Create(int packed, int icoframe, BmpDecoder **ppDecode { BmpDecoder *This; - This = HeapAlloc(GetProcessHeap(), 0, sizeof(BmpDecoder)); + This = malloc(sizeof(BmpDecoder)); if (!This) return E_OUTOFMEMORY; This->IWICBitmapDecoder_iface.lpVtbl = &BmpDecoder_Vtbl; @@ -1164,7 +1195,11 @@ static HRESULT BmpDecoder_Create(int packed, int icoframe, BmpDecoder **ppDecode This->initialized = FALSE; This->stream = NULL; This->imagedata = NULL; +#ifdef __REACTOS__ InitializeCriticalSection(&This->lock); +#else + InitializeCriticalSectionEx(&This->lock, 0, RTL_CRITICAL_SECTION_FLAG_FORCE_DEBUG_INFO); +#endif This->lock.DebugInfo->Spare[0] = (DWORD_PTR)(__FILE__ ": BmpDecoder.lock"); This->packed = packed; This->icoframe = icoframe; @@ -1220,7 +1255,8 @@ void BmpDecoder_FindIconMask(BmpDecoder *This, ULONG *mask_offset, int *topdown) if (This->read_data_func == BmpFrameDecode_ReadUncompressed) { /* RGB or BITFIELDS data */ - ULONG width, height, bytesperrow, datasize; + UINT width, height; + ULONG bytesperrow, datasize; IWICBitmapFrameDecode_GetSize(&This->IWICBitmapFrameDecode_iface, &width, &height); bytesperrow = (((width * This->bitsperpixel)+31)/32)*4; datasize = bytesperrow * height; diff --git a/dll/win32/windowscodecs/bmpencode.c b/dll/win32/windowscodecs/bmpencode.c index 3b77517a8d9..28da4a5e6d2 100644 --- a/dll/win32/windowscodecs/bmpencode.c +++ b/dll/win32/windowscodecs/bmpencode.c @@ -17,8 +17,6 @@ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA */ -#include "config.h" - #include <stdarg.h> #define COBJMACROS @@ -56,10 +54,7 @@ static const struct bmp_pixelformat formats[] = { {&GUID_WICPixelFormat16bppBGR555, 16, 0, BI_RGB}, {&GUID_WICPixelFormat16bppBGR565, 16, 0, BI_BITFIELDS, 0xf800, 0x7e0, 0x1f, 0}, {&GUID_WICPixelFormat32bppBGR, 32, 0, BI_RGB}, -#if 0 - /* Windows doesn't seem to support this one. */ {&GUID_WICPixelFormat32bppBGRA, 32, 0, BI_BITFIELDS, 0xff0000, 0xff00, 0xff, 0xff000000}, -#endif {NULL} }; @@ -79,8 +74,6 @@ typedef struct BmpFrameEncode { BOOL committed; } BmpFrameEncode; -static const WCHAR wszEnableV5Header32bppBGRA[] = {'E','n','a','b','l','e','V','5','H','e','a','d','e','r','3','2','b','p','p','B','G','R','A',0}; - static inline BmpFrameEncode *impl_from_IWICBitmapFrameEncode(IWICBitmapFrameEncode *iface) { return CONTAINING_RECORD(iface, BmpFrameEncode, IWICBitmapFrameEncode_iface); @@ -114,7 +107,7 @@ static ULONG WINAPI BmpFrameEncode_AddRef(IWICBitmapFrameEncode *iface) BmpFrameEncode *This = impl_from_IWICBitmapFrameEncode(iface); ULONG ref = InterlockedIncrement(&This->ref); - TRACE("(%p) refcount=%u\n", iface, ref); + TRACE("(%p) refcount=%lu\n", iface, ref); return ref; } @@ -124,13 +117,13 @@ static ULONG WINAPI BmpFrameEncode_Release(IWICBitmapFrameEncode *iface) BmpFrameEncode *This = impl_from_IWICBitmapFrameEncode(iface); ULONG ref = InterlockedDecrement(&This->ref); - TRACE("(%p) refcount=%u\n", iface, ref); + TRACE("(%p) refcount=%lu\n", iface, ref); if (ref == 0) { if (This->stream) IStream_Release(This->stream); - HeapFree(GetProcessHeap(), 0, This->bits); - HeapFree(GetProcessHeap(), 0, This); + free(This->bits); + free(This); } return ref; @@ -253,7 +246,7 @@ static HRESULT BmpFrameEncode_AllocateBits(BmpFrameEncode *This) return WINCODEC_ERR_WRONGSTATE; This->stride = (((This->width * This->format->bpp)+31)/32)*4; - This->bits = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, This->stride * This->height); + This->bits = calloc(This->stride, This->height); if (!This->bits) return E_OUTOFMEMORY; } @@ -316,7 +309,8 @@ static HRESULT WINAPI BmpFrameEncode_WriteSource(IWICBitmapFrameEncode *iface, if (SUCCEEDED(hr)) { hr = write_source(iface, pIBitmapSource, prc, - This->format->guid, This->format->bpp, This->width, This->height); + This->format->guid, This->format->bpp, !This->colors && This->format->colors, + This->width, This->height); } return hr; @@ -400,10 +394,16 @@ static HRESULT WINAPI BmpFrameEncode_Commit(IWICBitmapFrameEncode *iface) } static HRESULT WINAPI BmpFrameEncode_GetMetadataQueryWriter(IWICBitmapFrameEncode *iface, - IWICMetadataQueryWriter **ppIMetadataQueryWriter) + IWICMetadataQueryWriter **query_writer) { - FIXME("(%p, %p): stub\n", iface, ppIMetadataQueryWriter); - return E_NOTIMPL; + BmpFrameEncode *encoder = impl_from_IWICBitmapFrameEncode(iface); + + TRACE("iface %p, query_writer %p.\n", iface, query_writer); + + if (!encoder->initialized) + return WINCODEC_ERR_NOTINITIALIZED; + + return WINCODEC_ERR_UNSUPPORTEDOPERATION; } static const IWICBitmapFrameEncodeVtbl BmpFrameEncode_Vtbl = { @@ -463,7 +463,7 @@ static ULONG WINAPI BmpEncoder_AddRef(IWICBitmapEncoder *iface) BmpEncoder *This = impl_from_IWICBitmapEncoder(iface); ULONG ref = InterlockedIncrement(&This->ref); - TRACE("(%p) refcount=%u\n", iface, ref); + TRACE("(%p) refcount=%lu\n", iface, ref); return ref; } @@ -473,13 +473,13 @@ static ULONG WINAPI BmpEncoder_Release(IWICBitmapEncoder *iface) BmpEncoder *This = impl_from_IWICBitmapEncoder(iface); ULONG ref = InterlockedDecrement(&This->ref); - TRACE("(%p) refcount=%u\n", iface, ref); + TRACE("(%p) refcount=%lu\n", iface, ref); if (ref == 0) { if (This->stream) IStream_Release(This->stream); if (This->frame) IWICBitmapFrameEncode_Release(&This->frame->IWICBitmapFrameEncode_iface); - HeapFree(GetProcessHeap(), 0, This); + free(This); } return ref; @@ -563,7 +563,7 @@ static HRESULT WINAPI BmpEncoder_CreateNewFrame(IWICBitmapEncoder *iface, HRESULT hr; static const PROPBAG2 opts[1] = { - { PROPBAG2_TYPE_DATA, VT_BOOL, 0, 0, (LPOLESTR)wszEnableV5Header32bppBGRA }, + { PROPBAG2_TYPE_DATA, VT_BOOL, 0, 0, (LPOLESTR)L"EnableV5Header32bppBGRA" }, }; TRACE("(%p,%p,%p)\n", iface, ppIFrameEncode, ppIEncoderOptions); @@ -578,7 +578,7 @@ static HRESULT WINAPI BmpEncoder_CreateNewFrame(IWICBitmapEncoder *iface, if (FAILED(hr)) return hr; } - encode = HeapAlloc(GetProcessHeap(), 0, sizeof(BmpFrameEncode)); + encode = malloc(sizeof(BmpFrameEncode)); if (!encode) { IPropertyBag2_Release(*ppIEncoderOptions); @@ -648,7 +648,7 @@ HRESULT BmpEncoder_CreateInstance(REFIID iid, void** ppv) *ppv = NULL; - This = HeapAlloc(GetProcessHeap(), 0, sizeof(BmpEncoder)); + This = malloc(sizeof(BmpEncoder)); if (!This) return E_OUTOFMEMORY; This->IWICBitmapEncoder_iface.lpVtbl = &BmpEncoder_Vtbl; diff --git a/dll/win32/windowscodecs/clipper.c b/dll/win32/windowscodecs/clipper.c index 02e0d967f52..b4b2c23ee45 100644 --- a/dll/win32/windowscodecs/clipper.c +++ b/dll/win32/windowscodecs/clipper.c @@ -72,7 +72,7 @@ static ULONG WINAPI BitmapClipper_AddRef(IWICBitmapClipper *iface) BitmapClipper *This = impl_from_IWICBitmapClipper(iface); ULONG ref = InterlockedIncrement(&This->ref); - TRACE("(%p) refcount=%u\n", iface, ref); + TRACE("(%p) refcount=%lu\n", iface, ref); return ref; } @@ -82,14 +82,14 @@ static ULONG WINAPI BitmapClipper_Release(IWICBitmapClipper *iface) BitmapClipper *This = impl_from_IWICBitmapClipper(iface); ULONG ref = InterlockedDecrement(&This->ref); - TRACE("(%p) refcount=%u\n", iface, ref); + TRACE("(%p) refcount=%lu\n", iface, ref); if (ref == 0) { This->lock.DebugInfo->Spare[0] = 0; DeleteCriticalSection(&This->lock); if (This->source) IWICBitmapSource_Release(This->source); - HeapFree(GetProcessHeap(), 0, This); + free(This); } return ref; @@ -244,13 +244,17 @@ HRESULT BitmapClipper_Create(IWICBitmapClipper **clipper) { BitmapClipper *This; - This = HeapAlloc(GetProcessHeap(), 0, sizeof(BitmapClipper)); + This = malloc(sizeof(BitmapClipper)); if (!This) return E_OUTOFMEMORY; This->IWICBitmapClipper_iface.lpVtbl = &BitmapClipper_Vtbl; This->ref = 1; This->source = NULL; +#ifdef __REACTOS__ InitializeCriticalSection(&This->lock); +#else + InitializeCriticalSectionEx(&This->lock, 0, RTL_CRITICAL_SECTION_FLAG_FORCE_DEBUG_INFO); +#endif This->lock.DebugInfo->Spare[0] = (DWORD_PTR)(__FILE__ ": BitmapClipper.lock"); *clipper = &This->IWICBitmapClipper_iface; diff --git a/dll/win32/windowscodecs/clsfactory.c b/dll/win32/windowscodecs/clsfactory.c index 2de518a00c1..87b77c9c089 100644 --- a/dll/win32/windowscodecs/clsfactory.c +++ b/dll/win32/windowscodecs/clsfactory.c @@ -16,8 +16,6 @@ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA */ -#include "config.h" - #include <stdarg.h> #define COBJMACROS @@ -27,6 +25,8 @@ #include "winreg.h" #include "objbase.h" #include "ocidl.h" +#include "wincodec.h" +#include "wincodecsdk.h" #include "initguid.h" #include "wincodecs_private.h" @@ -35,7 +35,7 @@ WINE_DEFAULT_DEBUG_CHANNEL(wincodecs); -extern HRESULT WINAPI WIC_DllGetClassObject(REFCLSID, REFIID, LPVOID *) DECLSPEC_HIDDEN; +extern HRESULT WINAPI WIC_DllGetClassObject(REFCLSID, REFIID, LPVOID *); typedef struct { REFCLSID classid; @@ -47,6 +47,7 @@ static const classinfo wic_classes[] = { {&CLSID_WICImagingFactory2, ImagingFactory_CreateInstance}, {&CLSID_WICBmpDecoder, BmpDecoder_CreateInstance}, {&CLSID_WICPngDecoder, PngDecoder_CreateInstance}, + {&CLSID_WICPngDecoder2, PngDecoder_CreateInstance}, {&CLSID_WICPngEncoder, PngEncoder_CreateInstance}, {&CLSID_WICBmpEncoder, BmpEncoder_CreateInstance}, {&CLSID_WICGifDecoder, GifDecoder_CreateInstance}, @@ -56,14 +57,17 @@ static const classinfo wic_classes[] = { {&CLSID_WICJpegEncoder, JpegEncoder_CreateInstance}, {&CLSID_WICTiffDecoder, TiffDecoder_CreateInstance}, {&CLSID_WICTiffEncoder, TiffEncoder_CreateInstance}, - {&CLSID_WICIcnsEncoder, IcnsEncoder_CreateInstance}, + {&CLSID_WICDdsDecoder, DdsDecoder_CreateInstance}, + {&CLSID_WICDdsEncoder, DdsEncoder_CreateInstance}, {&CLSID_WICDefaultFormatConverter, FormatConverter_CreateInstance}, {&CLSID_WineTgaDecoder, TgaDecoder_CreateInstance}, {&CLSID_WICUnknownMetadataReader, UnknownMetadataReader_CreateInstance}, {&CLSID_WICIfdMetadataReader, IfdMetadataReader_CreateInstance}, {&CLSID_WICPngChrmMetadataReader, PngChrmReader_CreateInstance}, {&CLSID_WICPngGamaMetadataReader, PngGamaReader_CreateInstance}, + {&CLSID_WICPngHistMetadataReader, PngHistReader_CreateInstance}, {&CLSID_WICPngTextMetadataReader, PngTextReader_CreateInstance}, + {&CLSID_WICPngTimeMetadataReader, PngTimeReader_CreateInstance}, {&CLSID_WICLSDMetadataReader, LSDReader_CreateInstance}, {&CLSID_WICIMDMetadataReader, IMDReader_CreateInstance}, {&CLSID_WICGCEMetadataReader, GCEReader_CreateInstance}, @@ -110,7 +114,7 @@ static ULONG WINAPI ClassFactoryImpl_AddRef(IClassFactory *iface) ClassFactoryImpl *This = impl_from_IClassFactory(iface); ULONG ref = InterlockedIncrement(&This->ref); - TRACE("(%p) refcount=%u\n", iface, ref); + TRACE("(%p) refcount=%lu\n", iface, ref); return ref; } @@ -120,10 +124,10 @@ static ULONG WINAPI ClassFactoryImpl_Release(IClassFactory *iface) ClassFactoryImpl *This = impl_from_IClassFactory(iface); ULONG ref = InterlockedDecrement(&This->ref); - TRACE("(%p) refcount=%u\n", iface, ref); + TRACE("(%p) refcount=%lu\n", iface, ref); if (ref == 0) - HeapFree(GetProcessHeap(), 0, This); + free(This); return ref; } @@ -161,7 +165,7 @@ static HRESULT ClassFactoryImpl_Constructor(const classinfo *info, REFIID riid, *ppv = NULL; - This = HeapAlloc(GetProcessHeap(), 0, sizeof(ClassFactoryImpl)); + This = malloc(sizeof(ClassFactoryImpl)); if (!This) return E_OUTOFMEMORY; This->IClassFactory_iface.lpVtbl = &ClassFactoryImpl_Vtbl; @@ -201,11 +205,11 @@ HRESULT WINAPI DllGetClassObject(REFCLSID rclsid, REFIID iid, LPVOID *ppv) else ret = WIC_DllGetClassObject(rclsid, iid, ppv); - TRACE("<-- %08X\n", ret); + TRACE("<-- %08lX\n", ret); return ret; } -HRESULT create_instance(CLSID *clsid, const IID *iid, void **ppv) +HRESULT create_instance(const CLSID *clsid, const IID *iid, void **ppv) { int i; diff --git a/dll/win32/windowscodecs/colorcontext.c b/dll/win32/windowscodecs/colorcontext.c index eb13482cf43..a52e4e06eb7 100644 --- a/dll/win32/windowscodecs/colorcontext.c +++ b/dll/win32/windowscodecs/colorcontext.c @@ -16,8 +16,6 @@ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA */ -#include "config.h" - #include <stdarg.h> #define COBJMACROS @@ -74,7 +72,7 @@ static ULONG WINAPI ColorContext_AddRef(IWICColorContext *iface) ColorContext *This = impl_from_IWICColorContext(iface); ULONG ref = InterlockedIncrement(&This->ref); - TRACE("(%p) refcount=%u\n", iface, ref); + TRACE("(%p) refcount=%lu\n", iface, ref); return ref; } @@ -84,12 +82,12 @@ static ULONG WINAPI ColorContext_Release(IWICColorContext *iface) ColorContext *This = impl_from_IWICColorContext(iface); ULONG ref = InterlockedDecrement(&This->ref); - TRACE("(%p) refcount=%u\n", iface, ref); + TRACE("(%p) refcount=%lu\n", iface, ref); if (ref == 0) { - HeapFree(GetProcessHeap(), 0, This->profile); - HeapFree(GetProcessHeap(), 0, This); + free(This->profile); + free(This); } return ref; @@ -118,7 +116,7 @@ static HRESULT load_profile(const WCHAR *filename, BYTE **profile, UINT *len) CloseHandle(handle); return E_FAIL; } - if (!(*profile = HeapAlloc(GetProcessHeap(), 0, size.u.LowPart))) + if (!(*profile = malloc(size.u.LowPart))) { CloseHandle(handle); return E_OUTOFMEMORY; @@ -126,12 +124,12 @@ static HRESULT load_profile(const WCHAR *filename, BYTE **profile, UINT *len) ret = ReadFile(handle, *profile, size.u.LowPart, &count, NULL); CloseHandle(handle); if (!ret) { - HeapFree (GetProcessHeap(),0,*profile); + free(*profile); *profile = NULL; return HRESULT_FROM_WIN32(GetLastError()); } if (count != size.u.LowPart) { - HeapFree (GetProcessHeap(),0,*profile); + free(*profile); *profile = NULL; return E_FAIL; } @@ -156,7 +154,7 @@ static HRESULT WINAPI ColorContext_InitializeFromFilename(IWICColorContext *ifac hr = load_profile(wzFilename, &profile, &len); if (FAILED(hr)) return hr; - HeapFree(GetProcessHeap(), 0, This->profile); + free(This->profile); This->profile = profile; This->profile_len = len; This->type = WICColorContextProfile; @@ -174,10 +172,10 @@ static HRESULT WINAPI ColorContext_InitializeFromMemory(IWICColorContext *iface, if (This->type != WICColorContextUninitialized && This->type != WICColorContextProfile) return WINCODEC_ERR_WRONGSTATE; - if (!(profile = HeapAlloc(GetProcessHeap(), 0, cbBufferSize))) return E_OUTOFMEMORY; + if (!(profile = malloc(cbBufferSize))) return E_OUTOFMEMORY; memcpy(profile, pbBuffer, cbBufferSize); - HeapFree(GetProcessHeap(), 0, This->profile); + free(This->profile); This->profile = profile; This->profile_len = cbBufferSize; This->type = WICColorContextProfile; @@ -261,7 +259,7 @@ HRESULT ColorContext_Create(IWICColorContext **colorcontext) if (!colorcontext) return E_INVALIDARG; - This = HeapAlloc(GetProcessHeap(), 0, sizeof(ColorContext)); + This = malloc(sizeof(ColorContext)); if (!This) return E_OUTOFMEMORY; This->IWICColorContext_iface.lpVtbl = &ColorContext_Vtbl; diff --git a/dll/win32/windowscodecs/colortransform.c b/dll/win32/windowscodecs/colortransform.c index af66c67443d..9a392d6dc0c 100644 --- a/dll/win32/windowscodecs/colortransform.c +++ b/dll/win32/windowscodecs/colortransform.c @@ -16,8 +16,6 @@ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA */ -#include "config.h" - #include <stdarg.h> #define COBJMACROS @@ -72,7 +70,7 @@ static ULONG WINAPI ColorTransform_AddRef(IWICColorTransform *iface) ColorTransform *This = impl_from_IWICColorTransform(iface); ULONG ref = InterlockedIncrement(&This->ref); - TRACE("(%p) refcount=%u\n", iface, ref); + TRACE("(%p) refcount=%lu\n", iface, ref); return ref; } @@ -82,12 +80,12 @@ static ULONG WINAPI ColorTransform_Release(IWICColorTransform *iface) ColorTransform *This = impl_from_IWICColorTransform(iface); ULONG ref = InterlockedDecrement(&This->ref); - TRACE("(%p) refcount=%u\n", iface, ref); + TRACE("(%p) refcount=%lu\n", iface, ref); if (ref == 0) { if (This->dst) IWICBitmapSource_Release(This->dst); - HeapFree(GetProcessHeap(), 0, This); + free(This); } return ref; @@ -177,7 +175,7 @@ HRESULT ColorTransform_Create(IWICColorTransform **colortransform) if (!colortransform) return E_INVALIDARG; - This = HeapAlloc(GetProcessHeap(), 0, sizeof(ColorTransform)); + This = malloc(sizeof(ColorTransform)); if (!This) return E_OUTOFMEMORY; This->IWICColorTransform_iface.lpVtbl = &ColorTransform_Vtbl; diff --git a/dll/win32/windowscodecs/converter.c b/dll/win32/windowscodecs/converter.c index cac2ac1aa5a..2156e0aec8f 100644 --- a/dll/win32/windowscodecs/converter.c +++ b/dll/win32/windowscodecs/converter.c @@ -17,8 +17,6 @@ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA */ -#include "config.h" - #include <stdarg.h> #include <math.h> @@ -30,7 +28,6 @@ #include "wincodecs_private.h" -#include "wine/heap.h" #include "wine/debug.h" WINE_DEFAULT_DEBUG_CHANNEL(wincodecs); @@ -71,6 +68,7 @@ struct pixelformatinfo { enum pixelformat format; const WICPixelFormatGUID *guid; copyfunc copy_function; + BOOL is_indexed_format; }; typedef struct FormatConverter { @@ -176,7 +174,7 @@ static HRESULT copypixels_to_32bppBGRA(struct FormatConverter *This, const WICRe srcstride = (prc->Width+7)/8; srcdatasize = srcstride * prc->Height; - srcdata = HeapAlloc(GetProcessHeap(), 0, srcdatasize); + srcdata = malloc(srcdatasize); if (!srcdata) return E_OUTOFMEMORY; res = IWICBitmapSource_CopyPixels(This->source, prc, srcstride, srcdatasize, srcdata); @@ -205,7 +203,7 @@ static HRESULT copypixels_to_32bppBGRA(struct FormatConverter *This, const WICRe } } - HeapFree(GetProcessHeap(), 0, srcdata); + free(srcdata); return res; } @@ -243,7 +241,7 @@ static HRESULT copypixels_to_32bppBGRA(struct FormatConverter *This, const WICRe srcstride = (prc->Width+3)/4; srcdatasize = srcstride * prc->Height; - srcdata = HeapAlloc(GetProcessHeap(), 0, srcdatasize); + srcdata = malloc(srcdatasize); if (!srcdata) return E_OUTOFMEMORY; res = IWICBitmapSource_CopyPixels(This->source, prc, srcstride, srcdatasize, srcdata); @@ -268,7 +266,7 @@ static HRESULT copypixels_to_32bppBGRA(struct FormatConverter *This, const WICRe } } - HeapFree(GetProcessHeap(), 0, srcdata); + free(srcdata); return res; } @@ -306,7 +304,7 @@ static HRESULT copypixels_to_32bppBGRA(struct FormatConverter *This, const WICRe srcstride = (prc->Width+1)/2; srcdatasize = srcstride * prc->Height; - srcdata = HeapAlloc(GetProcessHeap(), 0, srcdatasize); + srcdata = malloc(srcdatasize); if (!srcdata) return E_OUTOFMEMORY; res = IWICBitmapSource_CopyPixels(This->source, prc, srcstride, srcdatasize, srcdata); @@ -329,7 +327,7 @@ static HRESULT copypixels_to_32bppBGRA(struct FormatConverter *This, const WICRe } } - HeapFree(GetProcessHeap(), 0, srcdata); + free(srcdata); return res; } @@ -349,7 +347,7 @@ static HRESULT copypixels_to_32bppBGRA(struct FormatConverter *This, const WICRe srcstride = prc->Width; srcdatasize = srcstride * prc->Height; - srcdata = HeapAlloc(GetProcessHeap(), 0, srcdatasize); + srcdata = malloc(srcdatasize); if (!srcdata) return E_OUTOFMEMORY; res = IWICBitmapSource_CopyPixels(This->source, prc, srcstride, srcdatasize, srcdata); @@ -371,7 +369,7 @@ static HRESULT copypixels_to_32bppBGRA(struct FormatConverter *This, const WICRe } } - HeapFree(GetProcessHeap(), 0, srcdata); + free(srcdata); return res; } @@ -405,7 +403,7 @@ static HRESULT copypixels_to_32bppBGRA(struct FormatConverter *This, const WICRe srcstride = prc->Width; srcdatasize = srcstride * prc->Height; - srcdata = HeapAlloc(GetProcessHeap(), 0, srcdatasize); + srcdata = malloc(srcdatasize); if (!srcdata) return E_OUTOFMEMORY; res = IWICBitmapSource_CopyPixels(This->source, prc, srcstride, srcdatasize, srcdata); @@ -424,7 +422,7 @@ static HRESULT copypixels_to_32bppBGRA(struct FormatConverter *This, const WICRe } } - HeapFree(GetProcessHeap(), 0, srcdata); + free(srcdata); return res; } @@ -444,7 +442,7 @@ static HRESULT copypixels_to_32bppBGRA(struct FormatConverter *This, const WICRe srcstride = prc->Width * 2; srcdatasize = srcstride * prc->Height; - srcdata = HeapAlloc(GetProcessHeap(), 0, srcdatasize); + srcdata = malloc(srcdatasize); if (!srcdata) return E_OUTOFMEMORY; res = IWICBitmapSource_CopyPixels(This->source, prc, srcstride, srcdatasize, srcdata); @@ -467,7 +465,7 @@ static HRESULT copypixels_to_32bppBGRA(struct FormatConverter *This, const WICRe } } - HeapFree(GetProcessHeap(), 0, srcdata); + free(srcdata); return res; } @@ -487,7 +485,7 @@ static HRESULT copypixels_to_32bppBGRA(struct FormatConverter *This, const WICRe srcstride = 2 * prc->Width; srcdatasize = srcstride * prc->Height; - srcdata = HeapAlloc(GetProcessHeap(), 0, srcdatasize); + srcdata = malloc(srcdatasize); if (!srcdata) return E_OUTOFMEMORY; res = IWICBitmapSource_CopyPixels(This->source, prc, srcstride, srcdatasize, srcdata); @@ -515,7 +513,7 @@ static HRESULT copypixels_to_32bppBGRA(struct FormatConverter *This, const WICRe } } - HeapFree(GetProcessHeap(), 0, srcdata); + free(srcdata); return res; } @@ -535,7 +533,7 @@ static HRESULT copypixels_to_32bppBGRA(struct FormatConverter *This, const WICRe srcstride = 2 * prc->Width; srcdatasize = srcstride * prc->Height; - srcdata = HeapAlloc(GetProcessHeap(), 0, srcdatasize); + srcdata = malloc(srcdatasize); if (!srcdata) return E_OUTOFMEMORY; res = IWICBitmapSource_CopyPixels(This->source, prc, srcstride, srcdatasize, srcdata); @@ -563,7 +561,7 @@ static HRESULT copypixels_to_32bppBGRA(struct FormatConverter *This, const WICRe } } - HeapFree(GetProcessHeap(), 0, srcdata); + free(srcdata); return res; } @@ -583,7 +581,7 @@ static HRESULT copypixels_to_32bppBGRA(struct FormatConverter *This, const WICRe srcstride = 2 * prc->Width; srcdatasize = srcstride * prc->Height; - srcdata = HeapAlloc(GetProcessHeap(), 0, srcdatasize); + srcdata = malloc(srcdatasize); if (!srcdata) return E_OUTOFMEMORY; res = IWICBitmapSource_CopyPixels(This->source, prc, srcstride, srcdatasize, srcdata); @@ -611,7 +609,7 @@ static HRESULT copypixels_to_32bppBGRA(struct FormatConverter *This, const WICRe } } - HeapFree(GetProcessHeap(), 0, srcdata); + free(srcdata); return res; } @@ -631,7 +629,7 @@ static HRESULT copypixels_to_32bppBGRA(struct FormatConverter *This, const WICRe srcstride = 3 * prc->Width; srcdatasize = srcstride * prc->Height; - srcdata = HeapAlloc(GetProcessHeap(), 0, srcdatasize); + srcdata = malloc(srcdatasize); if (!srcdata) return E_OUTOFMEMORY; res = IWICBitmapSource_CopyPixels(This->source, prc, srcstride, srcdatasize, srcdata); @@ -654,7 +652,7 @@ static HRESULT copypixels_to_32bppBGRA(struct FormatConverter *This, const WICRe } } - HeapFree(GetProcessHeap(), 0, srcdata); + free(srcdata); return res; } @@ -675,7 +673,7 @@ static HRESULT copypixels_to_32bppBGRA(struct FormatConverter *This, const WICRe srcstride = 3 * prc->Width; srcdatasize = srcstride * prc->Height; - srcdata = HeapAlloc(GetProcessHeap(), 0, srcdatasize); + srcdata = malloc(srcdatasize); if (!srcdata) return E_OUTOFMEMORY; res = IWICBitmapSource_CopyPixels(This->source, prc, srcstride, srcdatasize, srcdata); @@ -702,7 +700,7 @@ static HRESULT copypixels_to_32bppBGRA(struct FormatConverter *This, const WICRe } } - HeapFree(GetProcessHeap(), 0, srcdata); + free(srcdata); return res; } @@ -728,7 +726,7 @@ static HRESULT copypixels_to_32bppBGRA(struct FormatConverter *This, const WICRe HRESULT res; res = IWICBitmapSource_CopyPixels(This->source, prc, cbStride, cbBufferSize, pbBuffer); if (FAILED(res)) return res; - convert_rgba_to_bgra(4, pbBuffer, prc->Width, prc->Height, cbStride); + reverse_bgr8(4, pbBuffer, prc->Width, prc->Height, cbStride); } return S_OK; case format_32bppBGRA: @@ -772,7 +770,7 @@ static HRESULT copypixels_to_32bppBGRA(struct FormatConverter *This, const WICRe srcstride = 6 * prc->Width; srcdatasize = srcstride * prc->Height; - srcdata = HeapAlloc(GetProcessHeap(), 0, srcdatasize); + srcdata = malloc(srcdatasize); if (!srcdata) return E_OUTOFMEMORY; res = IWICBitmapSource_CopyPixels(This->source, prc, srcstride, srcdatasize, srcdata); @@ -796,7 +794,7 @@ static HRESULT copypixels_to_32bppBGRA(struct FormatConverter *This, const WICRe } } - HeapFree(GetProcessHeap(), 0, srcdata); + free(srcdata); return res; } @@ -816,7 +814,7 @@ static HRESULT copypixels_to_32bppBGRA(struct FormatConverter *This, const WICRe srcstride = 8 * prc->Width; srcdatasize = srcstride * prc->Height; - srcdata = HeapAlloc(GetProcessHeap(), 0, srcdatasize); + srcdata = malloc(srcdatasize); if (!srcdata) return E_OUTOFMEMORY; res = IWICBitmapSource_CopyPixels(This->source, prc, srcstride, srcdatasize, srcdata); @@ -841,7 +839,7 @@ static HRESULT copypixels_to_32bppBGRA(struct FormatConverter *This, const WICRe } } - HeapFree(GetProcessHeap(), 0, srcdata); + free(srcdata); return res; } @@ -985,9 +983,9 @@ static HRESULT copypixels_to_32bppPBGRA(struct FormatConverter *This, const WICR 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; + pbBuffer[cbStride*y+4*x] = (pbBuffer[cbStride*y+4*x] * alpha + 127) / 255; + pbBuffer[cbStride*y+4*x+1] = (pbBuffer[cbStride*y+4*x+1] * alpha + 127) / 255; + pbBuffer[cbStride*y+4*x+2] = (pbBuffer[cbStride*y+4*x+2] * alpha + 127) / 255; } } } @@ -1018,9 +1016,9 @@ static HRESULT copypixels_to_32bppPRGBA(struct FormatConverter *This, const WICR 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; + pbBuffer[cbStride*y+4*x] = (pbBuffer[cbStride*y+4*x] * alpha + 127) / 255; + pbBuffer[cbStride*y+4*x+1] = (pbBuffer[cbStride*y+4*x+1] * alpha + 127) / 255; + pbBuffer[cbStride*y+4*x+2] = (pbBuffer[cbStride*y+4*x+2] * alpha + 127) / 255; } } } @@ -1063,7 +1061,7 @@ static HRESULT copypixels_to_24bppBGR(struct FormatConverter *This, const WICRec srcstride = 4 * prc->Width; srcdatasize = srcstride * prc->Height; - srcdata = HeapAlloc(GetProcessHeap(), 0, srcdatasize); + srcdata = malloc(srcdatasize); if (!srcdata) return E_OUTOFMEMORY; res = IWICBitmapSource_CopyPixels(This->source, prc, srcstride, srcdatasize, srcdata); @@ -1107,7 +1105,7 @@ static HRESULT copypixels_to_24bppBGR(struct FormatConverter *This, const WICRec } } - HeapFree(GetProcessHeap(), 0, srcdata); + free(srcdata); return res; } @@ -1122,7 +1120,7 @@ static HRESULT copypixels_to_24bppBGR(struct FormatConverter *This, const WICRec srcstride = 4 * prc->Width; srcdatasize = srcstride * prc->Height; - srcdata = HeapAlloc(GetProcessHeap(), 0, srcdatasize); + srcdata = malloc(srcdatasize); if (!srcdata) return E_OUTOFMEMORY; hr = IWICBitmapSource_CopyPixels(This->source, prc, srcstride, srcdatasize, srcdata); @@ -1149,7 +1147,7 @@ static HRESULT copypixels_to_24bppBGR(struct FormatConverter *This, const WICRec } } - HeapFree(GetProcessHeap(), 0, srcdata); + free(srcdata); return hr; } @@ -1164,7 +1162,7 @@ static HRESULT copypixels_to_24bppBGR(struct FormatConverter *This, const WICRec srcstride = 4 * prc->Width; srcdatasize = srcstride * prc->Height; - srcdata = heap_alloc(srcdatasize); + srcdata = malloc(srcdatasize); if (!srcdata) return E_OUTOFMEMORY; hr = IWICBitmapSource_CopyPixels(This->source, prc, srcstride, srcdatasize, srcdata); @@ -1192,7 +1190,7 @@ static HRESULT copypixels_to_24bppBGR(struct FormatConverter *This, const WICRec } } - heap_free(srcdata); + free(srcdata); return hr; } return S_OK; @@ -1238,7 +1236,7 @@ static HRESULT copypixels_to_24bppRGB(struct FormatConverter *This, const WICRec srcstride = 4 * prc->Width; srcdatasize = srcstride * prc->Height; - srcdata = HeapAlloc(GetProcessHeap(), 0, srcdatasize); + srcdata = malloc(srcdatasize); if (!srcdata) return E_OUTOFMEMORY; res = IWICBitmapSource_CopyPixels(This->source, prc, srcstride, srcdatasize, srcdata); @@ -1265,7 +1263,7 @@ static HRESULT copypixels_to_24bppRGB(struct FormatConverter *This, const WICRec } } - HeapFree(GetProcessHeap(), 0, srcdata); + free(srcdata); return res; } @@ -1343,7 +1341,7 @@ static HRESULT copypixels_to_8bppGray(struct FormatConverter *This, const WICRec srcstride = 4 * prc->Width; srcdatasize = srcstride * prc->Height; - srcdata = HeapAlloc(GetProcessHeap(), 0, srcdatasize); + srcdata = malloc(srcdatasize); if (!srcdata) return E_OUTOFMEMORY; hr = IWICBitmapSource_CopyPixels(This->source, prc, srcstride, srcdatasize, srcdata); @@ -1365,7 +1363,7 @@ static HRESULT copypixels_to_8bppGray(struct FormatConverter *This, const WICRec } } - HeapFree(GetProcessHeap(), 0, srcdata); + free(srcdata); } return hr; @@ -1377,7 +1375,7 @@ static HRESULT copypixels_to_8bppGray(struct FormatConverter *This, const WICRec srcstride = 3 * prc->Width; srcdatasize = srcstride * prc->Height; - srcdata = HeapAlloc(GetProcessHeap(), 0, srcdatasize); + srcdata = malloc(srcdatasize); if (!srcdata) return E_OUTOFMEMORY; hr = copypixels_to_24bppBGR(This, prc, srcstride, srcdatasize, srcdata, source_format); @@ -1403,7 +1401,7 @@ static HRESULT copypixels_to_8bppGray(struct FormatConverter *This, const WICRec } } - HeapFree(GetProcessHeap(), 0, srcdata); + free(srcdata); return hr; } @@ -1467,7 +1465,7 @@ static HRESULT copypixels_to_8bppIndexed(struct FormatConverter *This, const WIC srcstride = 3 * prc->Width; srcdatasize = srcstride * prc->Height; - srcdata = HeapAlloc(GetProcessHeap(), 0, srcdatasize); + srcdata = malloc(srcdatasize); if (!srcdata) return E_OUTOFMEMORY; hr = copypixels_to_24bppBGR(This, prc, srcstride, srcdatasize, srcdata, source_format); @@ -1490,15 +1488,138 @@ static HRESULT copypixels_to_8bppIndexed(struct FormatConverter *This, const WIC } } - HeapFree(GetProcessHeap(), 0, srcdata); + free(srcdata); return hr; } +static HRESULT copypixels_to_16bppBGRA5551(struct FormatConverter *This, const WICRect *prc, + UINT cbStride, UINT cbBufferSize, BYTE *pbBuffer, enum pixelformat source_format) +{ + switch (source_format) + { + case format_16bppBGRA5551: + if (prc) + return IWICBitmapSource_CopyPixels(This->source, prc, cbStride, cbBufferSize, pbBuffer); + return S_OK; + case format_32bppBGRA: + if(prc) + { + HRESULT res; + INT x, y; + BYTE *srcdata; + UINT srcstride, srcdatasize; + const BYTE *srcrow; + const DWORD *srcpixel; + BYTE *dstrow; + DWORD srcval = 0; + WORD *dstpixel; + + int a, r, g, b; + + srcstride = 4 * prc->Width; + srcdatasize = srcstride * prc->Height; + + srcdata = malloc(srcdatasize); + if (!srcdata) return E_OUTOFMEMORY; + + res = IWICBitmapSource_CopyPixels(This->source, prc, srcstride, srcdatasize, srcdata); + if(SUCCEEDED(res)) + { + srcrow = srcdata; + dstrow = pbBuffer; + for(y=0; y< prc->Height; y++) { + srcpixel = (const DWORD*)srcrow; + dstpixel = (WORD *)dstrow; + for(x=0; x<prc->Width; x++) { + srcval=*srcpixel++; + a = (srcval & 0xff000000) >> 24; + r = (srcval & 0x00ff0000) >> 16; + g = (srcval & 0x0000ff00) >> 8; + b = (srcval & 0x000000ff); + a = (a >> 7) << 15; + r = (r >> 3) << 10; + g = (g >> 3) << 5; + b = (b >> 3); + *dstpixel++ = (a|r|g|b); + } + srcrow += srcstride; + dstrow += cbStride; + } + } + free(srcdata); + } + return S_OK; + default: + FIXME("Unimplemented conversion path! %d\n", source_format); + return WINCODEC_ERR_UNSUPPORTEDOPERATION; + } +} + +static HRESULT copypixels_to_64bppRGBA(struct FormatConverter *This, const WICRect *prc, + UINT cbStride, UINT cbBufferSize, BYTE *pbBuffer, enum pixelformat source_format) +{ + HRESULT hr; + + switch (source_format) + { + case format_64bppRGBA: + if (prc) + return IWICBitmapSource_CopyPixels(This->source, prc, cbStride, cbBufferSize, pbBuffer); + return S_OK; + + case format_48bppRGB: + { + UINT srcstride, srcdatasize; + const USHORT *srcpixel; + const BYTE *srcrow; + USHORT *dstpixel; + BYTE *srcdata; + BYTE *dstrow; + INT x, y; + + if (!prc) + return S_OK; + + srcstride = 6 * prc->Width; + srcdatasize = srcstride * prc->Height; + + srcdata = malloc(srcdatasize); + if (!srcdata) return E_OUTOFMEMORY; + + hr = IWICBitmapSource_CopyPixels(This->source, prc, srcstride, srcdatasize, srcdata); + if (SUCCEEDED(hr)) + { + srcrow = srcdata; + dstrow = pbBuffer; + for (y = 0; y < prc->Height; y++) + { + srcpixel = (USHORT *)srcrow; + dstpixel= (USHORT *)dstrow; + for (x = 0; x < prc->Width; x++) + { + *dstpixel++ = *srcpixel++; + *dstpixel++ = *srcpixel++; + *dstpixel++ = *srcpixel++; + *dstpixel++ = 65535; + } + srcrow += srcstride; + dstrow += cbStride; + } + } + free(srcdata); + return hr; + } + default: + FIXME("Unimplemented conversion path %d.\n", source_format); + return WINCODEC_ERR_UNSUPPORTEDOPERATION; + } +} + 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_1bppIndexed, &GUID_WICPixelFormat1bppIndexed, NULL, TRUE}, + {format_2bppIndexed, &GUID_WICPixelFormat2bppIndexed, NULL, TRUE}, + {format_4bppIndexed, &GUID_WICPixelFormat4bppIndexed, NULL, TRUE}, + {format_8bppIndexed, &GUID_WICPixelFormat8bppIndexed, copypixels_to_8bppIndexed, TRUE}, {format_BlackWhite, &GUID_WICPixelFormatBlackWhite, NULL}, {format_2bppGray, &GUID_WICPixelFormat2bppGray, NULL}, {format_4bppGray, &GUID_WICPixelFormat4bppGray, NULL}, @@ -1506,7 +1627,7 @@ static const struct pixelformatinfo supported_formats[] = { {format_16bppGray, &GUID_WICPixelFormat16bppGray, NULL}, {format_16bppBGR555, &GUID_WICPixelFormat16bppBGR555, NULL}, {format_16bppBGR565, &GUID_WICPixelFormat16bppBGR565, NULL}, - {format_16bppBGRA5551, &GUID_WICPixelFormat16bppBGRA5551, NULL}, + {format_16bppBGRA5551, &GUID_WICPixelFormat16bppBGRA5551, copypixels_to_16bppBGRA5551}, {format_24bppBGR, &GUID_WICPixelFormat24bppBGR, copypixels_to_24bppBGR}, {format_24bppRGB, &GUID_WICPixelFormat24bppRGB, copypixels_to_24bppRGB}, {format_32bppGrayFloat, &GUID_WICPixelFormat32bppGrayFloat, copypixels_to_32bppGrayFloat}, @@ -1517,7 +1638,7 @@ static const struct pixelformatinfo supported_formats[] = { {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_64bppRGBA, &GUID_WICPixelFormat64bppRGBA, copypixels_to_64bppRGBA}, {format_32bppCMYK, &GUID_WICPixelFormat32bppCMYK, NULL}, {0} }; @@ -1561,7 +1682,7 @@ static ULONG WINAPI FormatConverter_AddRef(IWICFormatConverter *iface) FormatConverter *This = impl_from_IWICFormatConverter(iface); ULONG ref = InterlockedIncrement(&This->ref); - TRACE("(%p) refcount=%u\n", iface, ref); + TRACE("(%p) refcount=%lu\n", iface, ref); return ref; } @@ -1571,7 +1692,7 @@ static ULONG WINAPI FormatConverter_Release(IWICFormatConverter *iface) FormatConverter *This = impl_from_IWICFormatConverter(iface); ULONG ref = InterlockedDecrement(&This->ref); - TRACE("(%p) refcount=%u\n", iface, ref); + TRACE("(%p) refcount=%lu\n", iface, ref); if (ref == 0) { @@ -1579,7 +1700,7 @@ static ULONG WINAPI FormatConverter_Release(IWICFormatConverter *iface) DeleteCriticalSection(&This->lock); if (This->source) IWICBitmapSource_Release(This->source); if (This->palette) IWICPalette_Release(This->palette); - HeapFree(GetProcessHeap(), 0, This); + free(This); } return ref; @@ -1638,12 +1759,7 @@ static HRESULT WINAPI FormatConverter_CopyPalette(IWICFormatConverter *iface, 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; + if (This->dst_format->is_indexed_format) return WINCODEC_ERR_WRONGSTATE; return IWICBitmapSource_CopyPalette(This->source, palette); } @@ -1691,6 +1807,13 @@ static HRESULT WINAPI FormatConverter_Initialize(IWICFormatConverter *iface, TRACE("(%p,%p,%s,%u,%p,%0.3f,%u)\n", iface, source, debugstr_guid(dstFormat), dither, palette, alpha_threshold, palette_type); + dstinfo = get_formatinfo(dstFormat); + if (!dstinfo) + { + FIXME("Unsupported destination format %s\n", debugstr_guid(dstFormat)); + return WINCODEC_ERR_UNSUPPORTEDPIXELFORMAT; + } + if (!palette) { UINT bpp; @@ -1705,18 +1828,21 @@ static HRESULT WINAPI FormatConverter_Initialize(IWICFormatConverter *iface, case WICBitmapPaletteTypeCustom: IWICPalette_Release(palette); palette = NULL; - if (bpp <= 8) return E_INVALIDARG; + + /* Indexed types require a palette */ + if (dstinfo->is_indexed_format) + return E_INVALIDARG; break; case WICBitmapPaletteTypeMedianCut: { - if (bpp <= 8) + if (dstinfo->is_indexed_format) res = IWICPalette_InitializeFromBitmap(palette, source, 1 << bpp, FALSE); break; } default: - if (bpp <= 8) + if (dstinfo->is_indexed_format) res = IWICPalette_InitializePredefined(palette, palette_type, FALSE); break; } @@ -1749,14 +1875,6 @@ static HRESULT WINAPI FormatConverter_Initialize(IWICFormatConverter *iface, goto end; } - dstinfo = get_formatinfo(dstFormat); - if (!dstinfo) - { - res = WINCODEC_ERR_UNSUPPORTEDPIXELFORMAT; - FIXME("Unsupported destination format %s\n", debugstr_guid(dstFormat)); - goto end; - } - if (dstinfo->copy_function) { IWICBitmapSource_AddRef(source); @@ -1841,14 +1959,18 @@ HRESULT FormatConverter_CreateInstance(REFIID iid, void** ppv) *ppv = NULL; - This = HeapAlloc(GetProcessHeap(), 0, sizeof(FormatConverter)); + This = malloc(sizeof(FormatConverter)); if (!This) return E_OUTOFMEMORY; This->IWICFormatConverter_iface.lpVtbl = &FormatConverter_Vtbl; This->ref = 1; This->source = NULL; This->palette = NULL; +#ifdef __REACTOS__ InitializeCriticalSection(&This->lock); +#else + InitializeCriticalSectionEx(&This->lock, 0, RTL_CRITICAL_SECTION_FLAG_FORCE_DEBUG_INFO); +#endif This->lock.DebugInfo->Spare[0] = (DWORD_PTR)(__FILE__ ": FormatConverter.lock"); ret = IWICFormatConverter_QueryInterface(&This->IWICFormatConverter_iface, iid, ppv); diff --git a/dll/win32/windowscodecs/ddsformat.c b/dll/win32/windowscodecs/ddsformat.c new file mode 100644 index 00000000000..680febb0d93 --- /dev/null +++ b/dll/win32/windowscodecs/ddsformat.c @@ -0,0 +1,2162 @@ +/* + * Copyright 2020 Ziqing Hui + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA + * + * + * Note: + * + * Uncompressed image: + * For uncompressed formats, a block is equivalent to a pixel. + * + * Cube map: + * A cube map is equivalent to a 2D texture array which has 6 textures. + * A cube map array is equivalent to a 2D texture array which has cubeCount*6 textures. + */ + +#include <stdarg.h> + +#define COBJMACROS + +#include "windef.h" +#include "winbase.h" +#include "objbase.h" + +#include "wincodecs_private.h" + +#include "wine/debug.h" + +WINE_DEFAULT_DEBUG_CHANNEL(wincodecs); + +#define DDS_MAGIC 0x20534444 +#ifndef MAKEFOURCC +#define MAKEFOURCC(ch0, ch1, ch2, ch3) \ + ((DWORD)(BYTE)(ch0) | ((DWORD)(BYTE)(ch1) << 8) | \ + ((DWORD)(BYTE)(ch2) << 16) | ((DWORD)(BYTE)(ch3) << 24 )) +#endif + +#define GET_RGB565_R(color) ((BYTE)(((color) >> 11) & 0x1F)) +#define GET_RGB565_G(color) ((BYTE)(((color) >> 5) & 0x3F)) +#define GET_RGB565_B(color) ((BYTE)(((color) >> 0) & 0x1F)) +#define MAKE_RGB565(r, g, b) ((WORD)(((BYTE)(r) << 11) | ((BYTE)(g) << 5) | (BYTE)(b))) +#define MAKE_ARGB(a, r, g, b) (((DWORD)(a) << 24) | ((DWORD)(r) << 16) | ((DWORD)(g) << 8) | (DWORD)(b)) + +#define DDPF_ALPHAPIXELS 0x00000001 +#define DDPF_ALPHA 0x00000002 +#define DDPF_FOURCC 0x00000004 +#define DDPF_PALETTEINDEXED8 0x00000020 +#define DDPF_RGB 0x00000040 +#define DDPF_LUMINANCE 0x00020000 +#define DDPF_BUMPDUDV 0x00080000 + +#define DDSCAPS2_CUBEMAP 0x00000200 +#define DDSCAPS2_VOLUME 0x00200000 + +#define DDS_DIMENSION_TEXTURE1D 2 +#define DDS_DIMENSION_TEXTURE2D 3 +#define DDS_DIMENSION_TEXTURE3D 4 + +#define DDS_RESOURCE_MISC_TEXTURECUBE 0x00000004 + +#define DDS_BLOCK_WIDTH 4 +#define DDS_BLOCK_HEIGHT 4 + +typedef struct { + DWORD size; + DWORD flags; + DWORD fourCC; + DWORD rgbBitCount; + DWORD rBitMask; + DWORD gBitMask; + DWORD bBitMask; + DWORD aBitMask; +} DDS_PIXELFORMAT; + +typedef struct { + DWORD size; + DWORD flags; + DWORD height; + DWORD width; + DWORD pitchOrLinearSize; + DWORD depth; + DWORD mipMapCount; + DWORD reserved1[11]; + DDS_PIXELFORMAT ddspf; + DWORD caps; + DWORD caps2; + DWORD caps3; + DWORD caps4; + DWORD reserved2; +} DDS_HEADER; + +typedef struct { + DWORD dxgiFormat; + DWORD resourceDimension; + DWORD miscFlag; + DWORD arraySize; + DWORD miscFlags2; +} DDS_HEADER_DXT10; + +typedef struct dds_info { + UINT width; + UINT height; + UINT depth; + UINT mip_levels; + UINT array_size; + UINT frame_count; + UINT data_offset; + UINT bytes_per_block; /* for uncompressed format, this means bytes per pixel*/ + DXGI_FORMAT format; + WICDdsDimension dimension; + WICDdsAlphaMode alpha_mode; + const GUID *pixel_format; + UINT pixel_format_bpp; +} dds_info; + +typedef struct dds_frame_info { + UINT width; + UINT height; + DXGI_FORMAT format; + UINT bytes_per_block; /* for uncompressed format, this means bytes per pixel*/ + UINT block_width; + UINT block_height; + UINT width_in_blocks; + UINT height_in_blocks; + const GUID *pixel_format; + UINT pixel_format_bpp; +} dds_frame_info; + +typedef struct DdsDecoder { + IWICBitmapDecoder IWICBitmapDecoder_iface; + IWICDdsDecoder IWICDdsDecoder_iface; + IWICWineDecoder IWICWineDecoder_iface; + LONG ref; + BOOL initialized; + IStream *stream; + CRITICAL_SECTION lock; + dds_info info; +} DdsDecoder; + +typedef struct DdsFrameDecode { + IWICBitmapFrameDecode IWICBitmapFrameDecode_iface; + IWICDdsFrameDecode IWICDdsFrameDecode_iface; + LONG ref; + BYTE *block_data; + BYTE *pixel_data; + CRITICAL_SECTION lock; + dds_frame_info info; +} DdsFrameDecode; + +typedef struct DdsEncoder { + IWICBitmapEncoder IWICBitmapEncoder_iface; + IWICDdsEncoder IWICDdsEncoder_iface; + LONG ref; + CRITICAL_SECTION lock; + IStream *stream; + UINT frame_count; + UINT frame_index; + BOOL uncommitted_frame; + BOOL committed; + dds_info info; +} DdsEncoder; + +typedef struct DdsFrameEncode { + IWICBitmapFrameEncode IWICBitmapFrameEncode_iface; + LONG ref; + DdsEncoder *parent; + BOOL initialized; + BOOL frame_created; + UINT width; + UINT height; + double dpi_x; + double dpi_y; +} DdsFrameEncode; + +static struct dds_format { + DDS_PIXELFORMAT pixel_format; + const GUID *wic_format; + UINT wic_format_bpp; + DXGI_FORMAT dxgi_format; +} dds_format_table[] = { + { { sizeof(DDS_PIXELFORMAT), DDPF_FOURCC, MAKEFOURCC('D', 'X', 'T', '1'), 0, 0, 0, 0, 0 }, + &GUID_WICPixelFormat32bppPBGRA, 32, DXGI_FORMAT_BC1_UNORM }, + { { sizeof(DDS_PIXELFORMAT), DDPF_FOURCC, MAKEFOURCC('D', 'X', 'T', '2'), 0, 0, 0, 0, 0 }, + &GUID_WICPixelFormat32bppPBGRA, 32, DXGI_FORMAT_BC2_UNORM }, + { { sizeof(DDS_PIXELFORMAT), DDPF_FOURCC, MAKEFOURCC('D', 'X', 'T', '3'), 0, 0, 0, 0, 0 }, + &GUID_WICPixelFormat32bppBGRA, 32, DXGI_FORMAT_BC2_UNORM }, + { { sizeof(DDS_PIXELFORMAT), DDPF_FOURCC, MAKEFOURCC('D', 'X', 'T', '4'), 0, 0, 0, 0, 0 }, + &GUID_WICPixelFormat32bppPBGRA, 32, DXGI_FORMAT_BC3_UNORM }, + { { sizeof(DDS_PIXELFORMAT), DDPF_FOURCC, MAKEFOURCC('D', 'X', 'T', '5'), 0, 0, 0, 0, 0 }, + &GUID_WICPixelFormat32bppBGRA, 32, DXGI_FORMAT_BC3_UNORM }, + { { sizeof(DDS_PIXELFORMAT), DDPF_FOURCC, MAKEFOURCC('B', 'C', '4', 'U'), 0, 0, 0, 0, 0 }, + &GUID_WICPixelFormat32bppBGRA, 32, DXGI_FORMAT_BC4_UNORM }, + { { sizeof(DDS_PIXELFORMAT), DDPF_FOURCC, MAKEFOURCC('B', 'C', '4', 'S'), 0, 0, 0, 0, 0 }, + &GUID_WICPixelFormat32bppBGRA, 32, DXGI_FORMAT_BC4_SNORM }, + { { sizeof(DDS_PIXELFORMAT), DDPF_FOURCC, MAKEFOURCC('B', 'C', '5', 'U'), 0, 0, 0, 0, 0 }, + &GUID_WICPixelFormat32bppBGRA, 32, DXGI_FORMAT_BC5_UNORM }, + { { sizeof(DDS_PIXELFORMAT), DDPF_FOURCC, MAKEFOURCC('B', 'C', '5', 'S'), 0, 0, 0, 0, 0 }, + &GUID_WICPixelFormat32bppBGRA, 32, DXGI_FORMAT_BC5_SNORM }, + { { sizeof(DDS_PIXELFORMAT), DDPF_FOURCC, MAKEFOURCC('A', 'T', 'I', '1'), 0, 0, 0, 0, 0 }, + &GUID_WICPixelFormat32bppBGRA, 32, DXGI_FORMAT_BC4_UNORM }, + { { sizeof(DDS_PIXELFORMAT), DDPF_FOURCC, MAKEFOURCC('A', 'T', 'I', '2'), 0, 0, 0, 0, 0 }, + &GUID_WICPixelFormat32bppBGRA, 32, DXGI_FORMAT_BC5_UNORM }, + { { sizeof(DDS_PIXELFORMAT), DDPF_FOURCC, MAKEFOURCC('R', 'G', 'B', 'G'), 0, 0, 0, 0, 0 }, + &GUID_WICPixelFormat32bpp4Channels, 32, DXGI_FORMAT_R8G8_B8G8_UNORM }, + { { sizeof(DDS_PIXELFORMAT), DDPF_FOURCC, MAKEFOURCC('G', 'R', 'G', 'B'), 0, 0, 0, 0, 0 }, + &GUID_WICPixelFormat32bpp4Channels, 32, DXGI_FORMAT_G8R8_G8B8_UNORM }, + { { sizeof(DDS_PIXELFORMAT), DDPF_FOURCC, MAKEFOURCC('D', 'X', '1', '0'), 0, 0, 0, 0, 0 }, + &GUID_WICPixelFormatUndefined, 0, DXGI_FORMAT_UNKNOWN }, + { { sizeof(DDS_PIXELFORMAT), DDPF_FOURCC, 0x24, 0, 0, 0, 0, 0 }, + &GUID_WICPixelFormat64bppRGBA, 64, DXGI_FORMAT_R16G16B16A16_UNORM }, + { { sizeof(DDS_PIXELFORMAT), DDPF_FOURCC, 0x6E, 0, 0, 0, 0, 0 }, + &GUID_WICPixelFormat64bppRGBA, 64, DXGI_FORMAT_R16G16B16A16_SNORM }, + { { sizeof(DDS_PIXELFORMAT), DDPF_FOURCC, 0x6F, 0, 0, 0, 0, 0 }, + &GUID_WICPixelFormat16bppGrayHalf, 16, DXGI_FORMAT_R16_FLOAT }, + { { sizeof(DDS_PIXELFORMAT), DDPF_FOURCC, 0x70, 0, 0, 0, 0, 0 }, + &GUID_WICPixelFormatUndefined, 0, DXGI_FORMAT_R16G16_FLOAT }, + { { sizeof(DDS_PIXELFORMAT), DDPF_FOURCC, 0x71, 0, 0, 0, 0, 0 }, + &GUID_WICPixelFormat64bppRGBAHalf, 64, DXGI_FORMAT_R16G16B16A16_FLOAT }, + { { sizeof(DDS_PIXELFORMAT), DDPF_FOURCC, 0x72, 0, 0, 0, 0, 0 }, + &GUID_WICPixelFormat32bppGrayFloat, 32, DXGI_FORMAT_R32_FLOAT }, + { { sizeof(DDS_PIXELFORMAT), DDPF_FOURCC, 0x73, 0, 0, 0, 0, 0 }, + &GUID_WICPixelFormatUndefined, 32, DXGI_FORMAT_R32G32_FLOAT }, + { { sizeof(DDS_PIXELFORMAT), DDPF_FOURCC, 0x74, 0, 0, 0, 0, 0 }, + &GUID_WICPixelFormat128bppRGBAFloat, 128, DXGI_FORMAT_R32G32B32A32_FLOAT }, + { { sizeof(DDS_PIXELFORMAT), DDPF_RGB, 0, 32, 0xFF,0xFF00,0xFF0000,0xFF000000 }, + &GUID_WICPixelFormat32bppRGBA, 32, DXGI_FORMAT_R8G8B8A8_UNORM }, + { { sizeof(DDS_PIXELFORMAT), DDPF_RGB, 0, 32, 0xFF,0xFF00,0xFF0000,0 }, + &GUID_WICPixelFormat32bppRGB, 32, DXGI_FORMAT_UNKNOWN }, + { { sizeof(DDS_PIXELFORMAT), DDPF_RGB, 0, 32, 0xFF0000,0xFF00,0xFF,0xFF000000 }, + &GUID_WICPixelFormat32bppBGRA, 32, DXGI_FORMAT_B8G8R8A8_UNORM }, + { { sizeof(DDS_PIXELFORMAT), DDPF_RGB, 0, 32, 0xFF0000,0xFF00,0xFF,0 }, + &GUID_WICPixelFormat32bppBGR, 32, DXGI_FORMAT_B8G8R8X8_UNORM }, + /* The red and blue masks are swapped for DXGI_FORMAT_R10G10B10A2_UNORM. + * For "correct" one, the RGB masks should be 0x3FF,0xFFC00,0x3FF00000. + * see:
https://walbourn.github.io/dds-update-and-1010102-problems
*/ + { { sizeof(DDS_PIXELFORMAT), DDPF_RGB, 0, 32, 0x3FF00000,0xFFC00,0x3FF,0xC0000000 }, + &GUID_WICPixelFormat32bppR10G10B10A2, 32, DXGI_FORMAT_R10G10B10A2_UNORM }, + { { sizeof(DDS_PIXELFORMAT), DDPF_RGB, 0, 32, 0x3FF,0xFFC00,0x3FF00000,0xC0000000 }, + &GUID_WICPixelFormat32bppRGBA1010102, 32, DXGI_FORMAT_R10G10B10A2_UNORM }, + { { sizeof(DDS_PIXELFORMAT), DDPF_RGB , 0, 32, 0xFFFF,0xFFFF0000,0,0 }, + &GUID_WICPixelFormatUndefined, 0, DXGI_FORMAT_R16G16_UNORM }, + { { sizeof(DDS_PIXELFORMAT), DDPF_RGB , 0, 32, 0xFFFFFFFF,0,0,0 }, + &GUID_WICPixelFormat32bppGrayFloat, 32, DXGI_FORMAT_R32_FLOAT }, + { { sizeof(DDS_PIXELFORMAT), DDPF_RGB , 0, 24, 0xFF0000,0x00FF00,0x0000FF,0 }, + &GUID_WICPixelFormat24bppBGR, 24, DXGI_FORMAT_UNKNOWN }, + { { sizeof(DDS_PIXELFORMAT), DDPF_RGB , 0, 24, 0x0000FF,0x00FF00,0xFF0000,0 }, + &GUID_WICPixelFormat24bppRGB, 24, DXGI_FORMAT_UNKNOWN }, + { { sizeof(DDS_PIXELFORMAT), DDPF_RGB, 0, 16, 0xF800,0x7E0,0x1F,0 }, + &GUID_WICPixelFormat16bppBGR565, 16, DXGI_FORMAT_B5G6R5_UNORM }, + { { sizeof(DDS_PIXELFORMAT), DDPF_RGB, 0, 16, 0x7C00,0x3E0,0x1F,0 }, + &GUID_WICPixelFormat16bppBGR555, 16, DXGI_FORMAT_UNKNOWN }, + { { sizeof(DDS_PIXELFORMAT), DDPF_RGB, 0, 16, 0x7C00,0x3E0,0x1F,0x8000 }, + &GUID_WICPixelFormat16bppBGRA5551, 16, DXGI_FORMAT_B5G5R5A1_UNORM }, + { { sizeof(DDS_PIXELFORMAT), DDPF_RGB, 0, 16, 0xF00,0xF0,0xF,0xF000 }, + &GUID_WICPixelFormatUndefined, 0, DXGI_FORMAT_B4G4R4A4_UNORM }, + { { sizeof(DDS_PIXELFORMAT), DDPF_ALPHA, 0, 8, 0,0,0,0xFF }, + &GUID_WICPixelFormat8bppAlpha, 8, DXGI_FORMAT_A8_UNORM }, + { { sizeof(DDS_PIXELFORMAT), DDPF_LUMINANCE, 0, 16, 0xFFFF,0,0,0 }, + &GUID_WICPixelFormat16bppGray, 16, DXGI_FORMAT_R16_UNORM }, + { { sizeof(DDS_PIXELFORMAT), DDPF_LUMINANCE, 0, 16, 0xFF,0,0,0xFF00 }, + &GUID_WICPixelFormatUndefined, 0, DXGI_FORMAT_R8G8_UNORM }, + { { sizeof(DDS_PIXELFORMAT), DDPF_LUMINANCE, 0, 8, 0xFF,0,0,0 }, + &GUID_WICPixelFormat8bppGray, 8, DXGI_FORMAT_R8_UNORM }, + { { 0 }, &GUID_WICPixelFormat8bppAlpha, 8, DXGI_FORMAT_A8_UNORM }, + { { 0 }, &GUID_WICPixelFormat8bppGray, 8, DXGI_FORMAT_R8_UNORM }, + { { 0 }, &GUID_WICPixelFormat16bppGray, 16, DXGI_FORMAT_R16_UNORM }, + { { 0 }, &GUID_WICPixelFormat16bppGrayHalf, 16, DXGI_FORMAT_R16_FLOAT }, + { { 0 }, &GUID_WICPixelFormat16bppBGR565, 16, DXGI_FORMAT_B5G6R5_UNORM }, + { { 0 }, &GUID_WICPixelFormat16bppBGRA5551, 16, DXGI_FORMAT_B5G5R5A1_UNORM }, + { { 0 }, &GUID_WICPixelFormat32bppGrayFloat, 32, DXGI_FORMAT_R32_FLOAT }, + { { 0 }, &GUID_WICPixelFormat32bppRGBA, 32, DXGI_FORMAT_R8G8B8A8_UNORM }, + { { 0 }, &GUID_WICPixelFormat32bppBGRA, 32, DXGI_FORMAT_B8G8R8A8_UNORM }, + { { 0 }, &GUID_WICPixelFormat32bppBGR, 32, DXGI_FORMAT_B8G8R8X8_UNORM }, + { { 0 }, &GUID_WICPixelFormat32bppR10G10B10A2, 32, DXGI_FORMAT_R10G10B10A2_UNORM }, + { { 0 }, &GUID_WICPixelFormat32bppRGBE, 32, DXGI_FORMAT_R9G9B9E5_SHAREDEXP }, + { { 0 }, &GUID_WICPixelFormat32bppRGBA1010102XR, 32, DXGI_FORMAT_R10G10B10_XR_BIAS_A2_UNORM }, + { { 0 }, &GUID_WICPixelFormat64bppRGBA, 64, DXGI_FORMAT_R16G16B16A16_UNORM }, + { { 0 }, &GUID_WICPixelFormat64bppRGBAHalf, 64, DXGI_FORMAT_R16G16B16A16_FLOAT }, + { { 0 }, &GUID_WICPixelFormat96bppRGBFloat, 96, DXGI_FORMAT_R32G32B32_FLOAT }, + { { 0 }, &GUID_WICPixelFormat128bppRGBAFloat, 128, DXGI_FORMAT_R32G32B32A32_FLOAT }, + { { 0 }, &GUID_WICPixelFormatUndefined, 0, DXGI_FORMAT_UNKNOWN } +}; + +static DXGI_FORMAT compressed_formats[] = { + DXGI_FORMAT_BC1_TYPELESS, DXGI_FORMAT_BC1_UNORM, DXGI_FORMAT_BC1_UNORM_SRGB, + DXGI_FORMAT_BC2_TYPELESS, DXGI_FORMAT_BC2_UNORM, DXGI_FORMAT_BC2_UNORM_SRGB, + DXGI_FORMAT_BC3_TYPELESS, DXGI_FORMAT_BC3_UNORM, DXGI_FORMAT_BC3_UNORM_SRGB, + DXGI_FORMAT_BC4_TYPELESS, DXGI_FORMAT_BC4_UNORM, DXGI_FORMAT_BC4_SNORM, + DXGI_FORMAT_BC5_TYPELESS, DXGI_FORMAT_BC5_UNORM, DXGI_FORMAT_BC5_SNORM, + DXGI_FORMAT_BC6H_TYPELESS, DXGI_FORMAT_BC6H_UF16, DXGI_FORMAT_BC6H_SF16, + DXGI_FORMAT_BC7_TYPELESS, DXGI_FORMAT_BC7_UNORM, DXGI_FORMAT_BC7_UNORM_SRGB +}; + +static HRESULT WINAPI DdsDecoder_Dds_GetFrame(IWICDdsDecoder *, UINT, UINT, UINT, IWICBitmapFrameDecode **); + +static DWORD rgb565_to_argb(WORD color, BYTE alpha) +{ + return MAKE_ARGB(alpha, (GET_RGB565_R(color) * 0xFF + 0x0F) / 0x1F, + (GET_RGB565_G(color) * 0xFF + 0x1F) / 0x3F, + (GET_RGB565_B(color) * 0xFF + 0x0F) / 0x1F); +} + +static inline BOOL has_extended_header(DDS_HEADER *header) +{ + return (header->ddspf.flags & DDPF_FOURCC) && + (header->ddspf.fourCC == MAKEFOURCC('D', 'X', '1', '0')); +} + +static WICDdsDimension get_dimension(DDS_HEADER *header, DDS_HEADER_DXT10 *header_dxt10) +{ + if (header_dxt10) { + if (header_dxt10->miscFlag & DDS_RESOURCE_MISC_TEXTURECUBE) return WICDdsTextureCube; + switch (header_dxt10->resourceDimension) + { + case DDS_DIMENSION_TEXTURE1D: return WICDdsTexture1D; + case DDS_DIMENSION_TEXTURE2D: return WICDdsTexture2D; + case DDS_DIMENSION_TEXTURE3D: return WICDdsTexture3D; + default: return WICDdsTexture2D; + } + } else { + if (header->caps2 & DDSCAPS2_CUBEMAP) { + return WICDdsTextureCube; + } else if (header->caps2 & DDSCAPS2_VOLUME) { + return WICDdsTexture3D; + } else { + return WICDdsTexture2D; + } + } +} + +static struct dds_format *get_dds_format(DDS_PIXELFORMAT *pixel_format) +{ + UINT i; + + for (i = 0; i < ARRAY_SIZE(dds_format_table); i++) + { + if ((pixel_format->flags & dds_format_table[i].pixel_format.flags) && + (pixel_format->fourCC == dds_format_table[i].pixel_format.fourCC) && + (pixel_format->rgbBitCount == dds_format_table[i].pixel_format.rgbBitCount) && + (pixel_format->rBitMask == dds_format_table[i].pixel_format.rBitMask) && + (pixel_format->gBitMask == dds_format_table[i].pixel_format.gBitMask) && + (pixel_format->bBitMask == dds_format_table[i].pixel_format.bBitMask) && + (pixel_format->aBitMask == dds_format_table[i].pixel_format.aBitMask)) + return dds_format_table + i; + } + + return dds_format_table + ARRAY_SIZE(dds_format_table) - 1; +} + +static WICDdsAlphaMode get_alpha_mode_from_fourcc(DWORD fourcc) +{ + switch (fourcc) + { + case MAKEFOURCC('D', 'X', 'T', '1'): + case MAKEFOURCC('D', 'X', 'T', '2'): + case MAKEFOURCC('D', 'X', 'T', '4'): + return WICDdsAlphaModePremultiplied; + default: + return WICDdsAlphaModeUnknown; + } +} + +static UINT get_bytes_per_block_from_format(DXGI_FORMAT format) +{ + /* for uncompressed format, return bytes per pixel*/ + switch (format) + { + case DXGI_FORMAT_R8_TYPELESS: + case DXGI_FORMAT_R8_UNORM: + case DXGI_FORMAT_R8_UINT: + case DXGI_FORMAT_R8_SNORM: + case DXGI_FORMAT_R8_SINT: + case DXGI_FORMAT_A8_UNORM: + return 1; + case DXGI_FORMAT_R8G8_TYPELESS: + case DXGI_FORMAT_R8G8_UNORM: + case DXGI_FORMAT_R8G8_UINT: + case DXGI_FORMAT_R8G8_SNORM: + case DXGI_FORMAT_R8G8_SINT: + case DXGI_FORMAT_R16_TYPELESS: + case DXGI_FORMAT_R16_FLOAT: + case DXGI_FORMAT_D16_UNORM: + case DXGI_FORMAT_R16_UNORM: + case DXGI_FORMAT_R16_UINT: + case DXGI_FORMAT_R16_SNORM: + case DXGI_FORMAT_R16_SINT: + case DXGI_FORMAT_B5G6R5_UNORM: + case DXGI_FORMAT_B5G5R5A1_UNORM: + case DXGI_FORMAT_B4G4R4A4_UNORM: + return 2; + case DXGI_FORMAT_R10G10B10A2_TYPELESS: + case DXGI_FORMAT_R10G10B10A2_UNORM: + case DXGI_FORMAT_R10G10B10A2_UINT: + case DXGI_FORMAT_R11G11B10_FLOAT: + case DXGI_FORMAT_R8G8B8A8_TYPELESS: + case DXGI_FORMAT_R8G8B8A8_UNORM: + case DXGI_FORMAT_R8G8B8A8_UNORM_SRGB: + case DXGI_FORMAT_R8G8B8A8_UINT: + case DXGI_FORMAT_R8G8B8A8_SNORM: + case DXGI_FORMAT_R8G8B8A8_SINT: + case DXGI_FORMAT_R16G16_TYPELESS: + case DXGI_FORMAT_R16G16_FLOAT: + case DXGI_FORMAT_R16G16_UNORM: + case DXGI_FORMAT_R16G16_UINT: + case DXGI_FORMAT_R16G16_SNORM: + case DXGI_FORMAT_R16G16_SINT: + case DXGI_FORMAT_R32_TYPELESS: + case DXGI_FORMAT_D32_FLOAT: + case DXGI_FORMAT_R32_FLOAT: + case DXGI_FORMAT_R32_UINT: + case DXGI_FORMAT_R32_SINT: + case DXGI_FORMAT_R24G8_TYPELESS: + case DXGI_FORMAT_D24_UNORM_S8_UINT: + case DXGI_FORMAT_R24_UNORM_X8_TYPELESS: + case DXGI_FORMAT_X24_TYPELESS_G8_UINT: + case DXGI_FORMAT_R9G9B9E5_SHAREDEXP: + case DXGI_FORMAT_R8G8_B8G8_UNORM: + case DXGI_FORMAT_G8R8_G8B8_UNORM: + case DXGI_FORMAT_B8G8R8A8_UNORM: + case DXGI_FORMAT_B8G8R8X8_UNORM: + case DXGI_FORMAT_R10G10B10_XR_BIAS_A2_UNORM: + case DXGI_FORMAT_B8G8R8A8_TYPELESS: + case DXGI_FORMAT_B8G8R8A8_UNORM_SRGB: + case DXGI_FORMAT_B8G8R8X8_TYPELESS: + case DXGI_FORMAT_B8G8R8X8_UNORM_SRGB: + return 4; + case DXGI_FORMAT_BC1_UNORM: + case DXGI_FORMAT_BC1_TYPELESS: + case DXGI_FORMAT_BC1_UNORM_SRGB: + case DXGI_FORMAT_BC4_TYPELESS: + case DXGI_FORMAT_BC4_UNORM: + case DXGI_FORMAT_BC4_SNORM: + case DXGI_FORMAT_R16G16B16A16_TYPELESS: + case DXGI_FORMAT_R16G16B16A16_FLOAT: + case DXGI_FORMAT_R16G16B16A16_UNORM: + case DXGI_FORMAT_R16G16B16A16_UINT: + case DXGI_FORMAT_R16G16B16A16_SNORM: + case DXGI_FORMAT_R16G16B16A16_SINT: + case DXGI_FORMAT_R32G32_TYPELESS: + case DXGI_FORMAT_R32G32_FLOAT: + case DXGI_FORMAT_R32G32_UINT: + case DXGI_FORMAT_R32G32_SINT: + case DXGI_FORMAT_R32G8X24_TYPELESS: + case DXGI_FORMAT_D32_FLOAT_S8X24_UINT: + case DXGI_FORMAT_R32_FLOAT_X8X24_TYPELESS: + case DXGI_FORMAT_X32_TYPELESS_G8X24_UINT: + return 8; + case DXGI_FORMAT_R32G32B32_TYPELESS: + case DXGI_FORMAT_R32G32B32_FLOAT: + case DXGI_FORMAT_R32G32B32_UINT: + case DXGI_FORMAT_R32G32B32_SINT: + return 12; + case DXGI_FORMAT_BC2_UNORM: + case DXGI_FORMAT_BC2_TYPELESS: + case DXGI_FORMAT_BC2_UNORM_SRGB: + case DXGI_FORMAT_BC3_UNORM: + case DXGI_FORMAT_BC3_TYPELESS: + case DXGI_FORMAT_BC3_UNORM_SRGB: + case DXGI_FORMAT_BC5_TYPELESS: + case DXGI_FORMAT_BC5_UNORM: + case DXGI_FORMAT_BC5_SNORM: + case DXGI_FORMAT_BC6H_TYPELESS: + case DXGI_FORMAT_BC6H_UF16: + case DXGI_FORMAT_BC6H_SF16: + case DXGI_FORMAT_BC7_TYPELESS: + case DXGI_FORMAT_BC7_UNORM: + case DXGI_FORMAT_BC7_UNORM_SRGB: + case DXGI_FORMAT_R32G32B32A32_TYPELESS: + case DXGI_FORMAT_R32G32B32A32_FLOAT: + case DXGI_FORMAT_R32G32B32A32_UINT: + case DXGI_FORMAT_R32G32B32A32_SINT: + return 16; + default: + WARN("DXGI format 0x%x is not supported in DDS decoder\n", format); + return 0; + } +} + +static UINT get_frame_count(UINT depth, UINT mip_levels, UINT array_size, WICDdsDimension dimension) +{ + UINT frame_count, i; + + if (depth == 1) + { + frame_count = mip_levels; + } + else + { + frame_count = 0; + for (i = 0; i < mip_levels; i++) + { + frame_count += depth; + if (depth > 1) depth /= 2; + } + } + + frame_count *= array_size; + if (dimension == WICDdsTextureCube) frame_count *= 6; + + return frame_count; +} + +static void get_frame_dds_index(UINT index, dds_info *info, UINT *array_index, UINT *mip_level, UINT *slice_index) +{ + UINT frame_per_texture, depth; + + if (info->dimension == WICDdsTextureCube) + frame_per_texture = info->mip_levels; + else + frame_per_texture = info->frame_count / info->array_size; + + *array_index = index / frame_per_texture; + *slice_index = index % frame_per_texture; + depth = info->depth; + *mip_level = 0; + while (*slice_index >= depth) + { + *slice_index -= depth; + (*mip_level)++; + if (depth > 1) depth /= 2; + } +} + +static const GUID *dxgi_format_to_wic_format(DXGI_FORMAT dxgi_format) +{ + UINT i; + for (i = 0; i < ARRAY_SIZE(dds_format_table); i++) + { + if (dds_format_table[i].pixel_format.size == 0 && + dds_format_table[i].dxgi_format == dxgi_format) + return dds_format_table[i].wic_format; + } + return &GUID_WICPixelFormatUndefined; +} + +static BOOL is_compressed(DXGI_FORMAT format) +{ + UINT i; + + for (i = 0; i < ARRAY_SIZE(compressed_formats); i++) + { + if (format == compressed_formats[i]) return TRUE; + } + return FALSE; +} + +static void get_dds_info(dds_info* info, DDS_HEADER *header, DDS_HEADER_DXT10 *header_dxt10) +{ + struct dds_format *format_info; + + info->width = header->width; + info->height = header->height; + info->depth = 1; + info->mip_levels = 1; + info->array_size = 1; + if (header->depth) info->depth = header->depth; + if (header->mipMapCount) info->mip_levels = header->mipMapCount; + + if (has_extended_header(header)) { + if (header_dxt10->arraySize) info->array_size = header_dxt10->arraySize; + info->format = header_dxt10->dxgiFormat; + info->dimension = get_dimension(NULL, header_dxt10); + info->alpha_mode = header_dxt10->miscFlags2 & 0x00000008; + info->data_offset = sizeof(DWORD) + sizeof(*header) + sizeof(*header_dxt10); + if (is_compressed(info->format)) { + info->pixel_format = (info->alpha_mode == WICDdsAlphaModePremultiplied) ? + &GUID_WICPixelFormat32bppPBGRA : &GUID_WICPixelFormat32bppBGRA; + info->pixel_format_bpp = 32; + } else { + info->pixel_format = dxgi_format_to_wic_format(info->format); + info->pixel_format_bpp = get_bytes_per_block_from_format(info->format) * 8; + } + } else { + format_info = get_dds_format(&header->ddspf); + info->format = format_info->dxgi_format; + info->dimension = get_dimension(header, NULL); + info->alpha_mode = get_alpha_mode_from_fourcc(header->ddspf.fourCC); + info->data_offset = sizeof(DWORD) + sizeof(*header); + info->pixel_format = format_info->wic_format; + info->pixel_format_bpp = format_info->wic_format_bpp; + } + + if (header->ddspf.flags & (DDPF_RGB | DDPF_ALPHA | DDPF_LUMINANCE)) { + info->bytes_per_block = header->ddspf.rgbBitCount / 8; + } else { + info->bytes_per_block = get_bytes_per_block_from_format(info->format); + } + + info->frame_count = get_frame_count(info->depth, info->mip_levels, info->array_size, info->dimension); +} + +static void decode_block(const BYTE *block_data, UINT block_count, DXGI_FORMAT format, + UINT width, UINT height, DWORD *buffer) +{ + const BYTE *block, *color_indices, *alpha_indices, *alpha_table; + int i, j, x, y, block_x, block_y, color_index, alpha_index; + int block_size, color_offset, color_indices_offset; + WORD color[4], color_value = 0; + BYTE alpha[8], alpha_value = 0; + + if (format == DXGI_FORMAT_BC1_UNORM) { + block_size = 8; + color_offset = 0; + color_indices_offset = 4; + } else { + block_size = 16; + color_offset = 8; + color_indices_offset = 12; + } + block_x = 0; + block_y = 0; + + for (i = 0; i < block_count; i++) + { + block = block_data + i * block_size; + + color[0] = *((WORD *)(block + color_offset)); + color[1] = *((WORD *)(block + color_offset + 2)); + color[2] = MAKE_RGB565(((GET_RGB565_R(color[0]) * 2 + GET_RGB565_R(color[1]) + 1) / 3), + ((GET_RGB565_G(color[0]) * 2 + GET_RGB565_G(color[1]) + 1) / 3), + ((GET_RGB565_B(color[0]) * 2 + GET_RGB565_B(color[1]) + 1) / 3)); + color[3] = MAKE_RGB565(((GET_RGB565_R(color[0]) + GET_RGB565_R(color[1]) * 2 + 1) / 3), + ((GET_RGB565_G(color[0]) + GET_RGB565_G(color[1]) * 2 + 1) / 3), + ((GET_RGB565_B(color[0]) + GET_RGB565_B(color[1]) * 2 + 1) / 3)); + + switch (format) + { + case DXGI_FORMAT_BC1_UNORM: + if (color[0] <= color[1]) { + color[2] = MAKE_RGB565(((GET_RGB565_R(color[0]) + GET_RGB565_R(color[1]) + 1) / 2), + ((GET_RGB565_G(color[0]) + GET_RGB565_G(color[1]) + 1) / 2), + ((GET_RGB565_B(color[0]) + GET_RGB565_B(color[1]) + 1) / 2)); + color[3] = 0; + } + break; + case DXGI_FORMAT_BC2_UNORM: + alpha_table = block; + break; + case DXGI_FORMAT_BC3_UNORM: + alpha[0] = *block; + alpha[1] = *(block + 1); + if (alpha[0] > alpha[1]) { + for (j = 2; j < 8; j++) + { + alpha[j] = (BYTE)((alpha[0] * (8 - j) + alpha[1] * (j - 1) + 3) / 7); + } + } else { + for (j = 2; j < 6; j++) + { + alpha[j] = (BYTE)((alpha[0] * (6 - j) + alpha[1] * (j - 1) + 2) / 5); + } + alpha[6] = 0; + alpha[7] = 0xFF; + } + alpha_indices = block + 2; + break; + default: + break; + } + + color_indices = block + color_indices_offset; + for (j = 0; j < 16; j++) + { + x = block_x + j % 4; + y = block_y + j / 4; + if (x >= width || y >= height) continue; + + color_index = (color_indices[j / 4] >> ((j % 4) * 2)) & 0x3; + color_value = color[color_index]; + + switch (format) + { + case DXGI_FORMAT_BC1_UNORM: + if ((color[0] <= color[1]) && !color_value) { + color_value = 0; + alpha_value = 0; + } else { + alpha_value = 0xFF; + } + break; + case DXGI_FORMAT_BC2_UNORM: + alpha_value = (alpha_table[j / 2] >> (j % 2) * 4) & 0xF; + alpha_value = (BYTE)((alpha_value * 0xFF + 0x7)/ 0xF); + break; + case DXGI_FORMAT_BC3_UNORM: + alpha_index = (*((DWORD *)(alpha_indices + (j / 8) * 3)) >> ((j % 8) * 3)) & 0x7; + alpha_value = alpha[alpha_index]; + break; + default: + break; + } + buffer[x + y * width] = rgb565_to_argb(color_value, alpha_value); + } + + block_x += DDS_BLOCK_WIDTH; + if (block_x >= width) { + block_x = 0; + block_y += DDS_BLOCK_HEIGHT; + } + } +} + +static inline DdsDecoder *impl_from_IWICBitmapDecoder(IWICBitmapDecoder *iface) +{ + return CONTAINING_RECORD(iface, DdsDecoder, IWICBitmapDecoder_iface); +} + +static inline DdsDecoder *impl_from_IWICDdsDecoder(IWICDdsDecoder *iface) +{ + return CONTAINING_RECORD(iface, DdsDecoder, IWICDdsDecoder_iface); +} + +static inline DdsDecoder *impl_from_IWICWineDecoder(IWICWineDecoder *iface) +{ + return CONTAINING_RECORD(iface, DdsDecoder, IWICWineDecoder_iface); +} + +static inline DdsFrameDecode *impl_from_IWICBitmapFrameDecode(IWICBitmapFrameDecode *iface) +{ + return CONTAINING_RECORD(iface, DdsFrameDecode, IWICBitmapFrameDecode_iface); +} + +static inline DdsFrameDecode *impl_from_IWICDdsFrameDecode(IWICDdsFrameDecode *iface) +{ + return CONTAINING_RECORD(iface, DdsFrameDecode, IWICDdsFrameDecode_iface); +} + +static inline DdsEncoder *impl_from_IWICBitmapEncoder(IWICBitmapEncoder *iface) +{ + return CONTAINING_RECORD(iface, DdsEncoder, IWICBitmapEncoder_iface); +} + +static inline DdsEncoder *impl_from_IWICDdsEncoder(IWICDdsEncoder *iface) +{ + return CONTAINING_RECORD(iface, DdsEncoder, IWICDdsEncoder_iface); +} + +static inline DdsFrameEncode *impl_from_IWICBitmapFrameEncode(IWICBitmapFrameEncode *iface) +{ + return CONTAINING_RECORD(iface, DdsFrameEncode, IWICBitmapFrameEncode_iface); +} + +static HRESULT WINAPI DdsFrameDecode_QueryInterface(IWICBitmapFrameDecode *iface, REFIID iid, + void **ppv) +{ + DdsFrameDecode *This = impl_from_IWICBitmapFrameDecode(iface); + TRACE("(%p,%s,%p)\n", iface, debugstr_guid(iid), ppv); + + if (!ppv) return E_INVALIDARG; + + if (IsEqualIID(&IID_IUnknown, iid) || + IsEqualIID(&IID_IWICBitmapSource, iid) || + IsEqualIID(&IID_IWICBitmapFrameDecode, iid)) { + *ppv = &This->IWICBitmapFrameDecode_iface; + } else if (IsEqualGUID(&IID_IWICDdsFrameDecode, iid)) { + *ppv = &This->IWICDdsFrameDecode_iface; + } else { + *ppv = NULL; + return E_NOINTERFACE; + } + + IUnknown_AddRef((IUnknown*)*ppv); + return S_OK; +} + +static ULONG WINAPI DdsFrameDecode_AddRef(IWICBitmapFrameDecode *iface) +{ + DdsFrameDecode *This = impl_from_IWICBitmapFrameDecode(iface); + ULONG ref = InterlockedIncrement(&This->ref); + + TRACE("(%p) refcount=%lu\n", iface, ref); + + return ref; +} + +static ULONG WINAPI DdsFrameDecode_Release(IWICBitmapFrameDecode *iface) +{ + DdsFrameDecode *This = impl_from_IWICBitmapFrameDecode(iface); + ULONG ref = InterlockedDecrement(&This->ref); + + TRACE("(%p) refcount=%lu\n", iface, ref); + + if (ref == 0) { + if (This->pixel_data != This->block_data) free(This->pixel_data); + free(This->block_data); + free(This); + } + + return ref; +} + +static HRESULT WINAPI DdsFrameDecode_GetSize(IWICBitmapFrameDecode *iface, + UINT *puiWidth, UINT *puiHeight) +{ + DdsFrameDecode *This = impl_from_IWICBitmapFrameDecode(iface); + + if (!puiWidth || !puiHeight) return E_INVALIDARG; + + *puiWidth = This->info.width; + *puiHeight = This->info.height; + + TRACE("(%p) -> (%d,%d)\n", iface, *puiWidth, *puiHeight); + + return S_OK; +} + +static HRESULT WINAPI DdsFrameDecode_GetPixelFormat(IWICBitmapFrameDecode *iface, + WICPixelFormatGUID *pPixelFormat) +{ + DdsFrameDecode *This = impl_from_IWICBitmapFrameDecode(iface); + + if (!pPixelFormat) return E_INVALIDARG; + + *pPixelFormat = *This->info.pixel_format; + + TRACE("(%p) -> %s\n", iface, debugstr_guid(pPixelFormat)); + + return S_OK; +} + +static HRESULT WINAPI DdsFrameDecode_GetResolution(IWICBitmapFrameDecode *iface, + double *pDpiX, double *pDpiY) +{ + FIXME("(%p,%p,%p): stub.\n", iface, pDpiX, pDpiY); + + return E_NOTIMPL; +} + +static HRESULT WINAPI DdsFrameDecode_CopyPalette(IWICBitmapFrameDecode *iface, + IWICPalette *pIPalette) +{ + FIXME("(%p,%p): stub.\n", iface, pIPalette); + + return E_NOTIMPL; +} + +static HRESULT WINAPI DdsFrameDecode_CopyPixels(IWICBitmapFrameDecode *iface, + const WICRect *prc, UINT cbStride, UINT cbBufferSize, BYTE *pbBuffer) +{ + DdsFrameDecode *This = impl_from_IWICBitmapFrameDecode(iface); + UINT bpp, frame_stride, frame_size; + INT x, y, width, height; + HRESULT hr; + + TRACE("(%p,%s,%u,%u,%p)\n", iface, debug_wic_rect(prc), cbStride, cbBufferSize, pbBuffer); + + if (!pbBuffer) return E_INVALIDARG; + + bpp = This->info.pixel_format_bpp; + if (!bpp) return WINCODEC_ERR_UNSUPPORTEDPIXELFORMAT; + + frame_stride = This->info.width * bpp / 8; + frame_size = frame_stride * This->info.height; + if (!prc) { + if (cbStride < frame_stride) return E_INVALIDARG; + if (cbBufferSize < frame_size) return WINCODEC_ERR_INSUFFICIENTBUFFER; + } else { + x = prc->X; + y = prc->Y; + width = prc->Width; + height = prc->Height; + if (x < 0 || y < 0 || width <= 0 || height <= 0 || + x + width > This->info.width || + y + height > This->info.height) { + return E_INVALIDARG; + } + if (cbStride < width * bpp / 8) return E_INVALIDARG; + if (cbBufferSize < cbStride * height) return WINCODEC_ERR_INSUFFICIENTBUFFER; + } + + EnterCriticalSection(&This->lock); + + if (!This->pixel_data) { + if (is_compressed(This->info.format)) { + This->pixel_data = malloc(frame_size); + if (!This->pixel_data) { + hr = E_OUTOFMEMORY; + goto end; + } + decode_block(This->block_data, This->info.width_in_blocks * This->info.height_in_blocks, This->info.format, + This->info.width, This->info.height, (DWORD *)This->pixel_data); + } else { + This->pixel_data = This->block_data; + } + } + + hr = copy_pixels(bpp, This->pixel_data, This->info.width, This->info.height, frame_stride, + prc, cbStride, cbBufferSize, pbBuffer); + +end: + LeaveCriticalSection(&This->lock); + + return hr; +} + +static HRESULT WINAPI DdsFrameDecode_GetMetadataQueryReader(IWICBitmapFrameDecode *iface, + IWICMetadataQueryReader **ppIMetadataQueryReader) +{ + FIXME("(%p,%p): stub.\n", iface, ppIMetadataQueryReader); + + return E_NOTIMPL; +} + +static HRESULT WINAPI DdsFrameDecode_GetColorContexts(IWICBitmapFrameDecode *iface, + UINT cCount, IWICColorContext **ppIColorContexts, UINT *pcActualCount) +{ + FIXME("(%p,%u,%p,%p): stub.\n", iface, cCount, ppIColorContexts, pcActualCount); + + return E_NOTIMPL; +} + +static HRESULT WINAPI DdsFrameDecode_GetThumbnail(IWICBitmapFrameDecode *iface, + IWICBitmapSource **ppIThumbnail) +{ + FIXME("(%p,%p): stub.\n", iface, ppIThumbnail); + + return E_NOTIMPL; +} + +static const IWICBitmapFrameDecodeVtbl DdsFrameDecode_Vtbl = { + DdsFrameDecode_QueryInterface, + DdsFrameDecode_AddRef, + DdsFrameDecode_Release, + DdsFrameDecode_GetSize, + DdsFrameDecode_GetPixelFormat, + DdsFrameDecode_GetResolution, + DdsFrameDecode_CopyPalette, + DdsFrameDecode_CopyPixels, + DdsFrameDecode_GetMetadataQueryReader, + DdsFrameDecode_GetColorContexts, + DdsFrameDecode_GetThumbnail +}; + +static HRESULT WINAPI DdsFrameDecode_Dds_QueryInterface(IWICDdsFrameDecode *iface, + REFIID iid, void **ppv) +{ + DdsFrameDecode *This = impl_from_IWICDdsFrameDecode(iface); + return DdsFrameDecode_QueryInterface(&This->IWICBitmapFrameDecode_iface, iid, ppv); +} + +static ULONG WINAPI DdsFrameDecode_Dds_AddRef(IWICDdsFrameDecode *iface) +{ + DdsFrameDecode *This = impl_from_IWICDdsFrameDecode(iface); + return DdsFrameDecode_AddRef(&This->IWICBitmapFrameDecode_iface); +} + +static ULONG WINAPI DdsFrameDecode_Dds_Release(IWICDdsFrameDecode *iface) +{ + DdsFrameDecode *This = impl_from_IWICDdsFrameDecode(iface); + return DdsFrameDecode_Release(&This->IWICBitmapFrameDecode_iface); +} + +static HRESULT WINAPI DdsFrameDecode_Dds_GetSizeInBlocks(IWICDdsFrameDecode *iface, + UINT *widthInBlocks, UINT *heightInBlocks) +{ + DdsFrameDecode *This = impl_from_IWICDdsFrameDecode(iface); + + if (!widthInBlocks || !heightInBlocks) return E_INVALIDARG; + + *widthInBlocks = This->info.width_in_blocks; + *heightInBlocks = This->info.height_in_blocks; + + TRACE("(%p,%p,%p) -> (%d,%d)\n", iface, widthInBlocks, heightInBlocks, *widthInBlocks, *heightInBlocks); + + return S_OK; +} + +static HRESULT WINAPI DdsFrameDecode_Dds_GetFormatInfo(IWICDdsFrameDecode *iface, + WICDdsFormatInfo *formatInfo) +{ + DdsFrameDecode *This = impl_from_IWICDdsFrameDecode(iface); + + if (!formatInfo) return E_INVALIDARG; + + formatInfo->DxgiFormat = This->info.format; + formatInfo->BytesPerBlock = This->info.bytes_per_block; + formatInfo->BlockWidth = This->info.block_width; + formatInfo->BlockHeight = This->info.block_height; + + TRACE("(%p,%p) -> (0x%x,%d,%d,%d)\n", iface, formatInfo, + formatInfo->DxgiFormat, formatInfo->BytesPerBlock, formatInfo->BlockWidth, formatInfo->BlockHeight); + + return S_OK; +} + +static HRESULT WINAPI DdsFrameDecode_Dds_CopyBlocks(IWICDdsFrameDecode *iface, + const WICRect *boundsInBlocks, UINT stride, UINT bufferSize, + BYTE *buffer) +{ + DdsFrameDecode *This = impl_from_IWICDdsFrameDecode(iface); + int x, y, width, height; + UINT bytes_per_block, frame_stride, frame_size; + + TRACE("(%p,%p,%u,%u,%p)\n", iface, boundsInBlocks, stride, bufferSize, buffer); + + if (!buffer) return E_INVALIDARG; + + bytes_per_block = This->info.bytes_per_block; + frame_stride = This->info.width_in_blocks * bytes_per_block; + frame_size = frame_stride * This->info.height_in_blocks; + + if (!boundsInBlocks) { + if (stride < frame_stride) return E_INVALIDARG; + if (bufferSize < frame_size) return E_INVALIDARG; + } else { + x = boundsInBlocks->X; + y = boundsInBlocks->Y; + width = boundsInBlocks->Width; + height = boundsInBlocks->Height; + if (x < 0 || y < 0 || width <= 0 || height <= 0 || + x + width > This->info.width_in_blocks || + y + height > This->info.height_in_blocks) { + return E_INVALIDARG; + } + if (stride < width * bytes_per_block) return E_INVALIDARG; + if (bufferSize < stride * height) return E_INVALIDARG; + } + + return copy_pixels(This->info.bytes_per_block * 8, This->block_data, This->info.width_in_blocks, + This->info.height_in_blocks, frame_stride, boundsInBlocks, stride, bufferSize, buffer); +} + +static const IWICDdsFrameDecodeVtbl DdsFrameDecode_Dds_Vtbl = { + DdsFrameDecode_Dds_QueryInterface, + DdsFrameDecode_Dds_AddRef, + DdsFrameDecode_Dds_Release, + DdsFrameDecode_Dds_GetSizeInBlocks, + DdsFrameDecode_Dds_GetFormatInfo, + DdsFrameDecode_Dds_CopyBlocks +}; + +static HRESULT DdsFrameDecode_CreateInstance(DdsFrameDecode **frame_decode) +{ + DdsFrameDecode *result; + + result = malloc(sizeof(*result)); + if (!result) return E_OUTOFMEMORY; + + result->IWICBitmapFrameDecode_iface.lpVtbl = &DdsFrameDecode_Vtbl; + result->IWICDdsFrameDecode_iface.lpVtbl = &DdsFrameDecode_Dds_Vtbl; + result->ref = 1; +#ifdef __REACTOS__ + InitializeCriticalSection(&result->lock); +#else + InitializeCriticalSectionEx(&result->lock, 0, RTL_CRITICAL_SECTION_FLAG_FORCE_DEBUG_INFO); +#endif + result->lock.DebugInfo->Spare[0] = (DWORD_PTR)(__FILE__ ": DdsFrameDecode.lock"); + + *frame_decode = result; + return S_OK; +} + +static HRESULT WINAPI DdsDecoder_QueryInterface(IWICBitmapDecoder *iface, REFIID iid, + void **ppv) +{ + DdsDecoder *This = impl_from_IWICBitmapDecoder(iface); + TRACE("(%p,%s,%p)\n", iface, debugstr_guid(iid), ppv); + + if (!ppv) return E_INVALIDARG; + + if (IsEqualIID(&IID_IUnknown, iid) || + IsEqualIID(&IID_IWICBitmapDecoder, iid)) { + *ppv = &This->IWICBitmapDecoder_iface; + } else if (IsEqualIID(&IID_IWICDdsDecoder, iid)) { + *ppv = &This->IWICDdsDecoder_iface; + } else if (IsEqualIID(&IID_IWICWineDecoder, iid)) { + *ppv = &This->IWICWineDecoder_iface; + } else { + *ppv = NULL; + return E_NOINTERFACE; + } + + IUnknown_AddRef((IUnknown*)*ppv); + return S_OK; +} + +static ULONG WINAPI DdsDecoder_AddRef(IWICBitmapDecoder *iface) +{ + DdsDecoder *This = impl_from_IWICBitmapDecoder(iface); + ULONG ref = InterlockedIncrement(&This->ref); + + TRACE("(%p) refcount=%lu\n", iface, ref); + + return ref; +} + +static ULONG WINAPI DdsDecoder_Release(IWICBitmapDecoder *iface) +{ + DdsDecoder *This = impl_from_IWICBitmapDecoder(iface); + ULONG ref = InterlockedDecrement(&This->ref); + + TRACE("(%p) refcount=%lu\n", iface, ref); + + if (ref == 0) + { + This->lock.DebugInfo->Spare[0] = 0; + DeleteCriticalSection(&This->lock); + if (This->stream) IStream_Release(This->stream); + free(This); + } + + return ref; +} + +static HRESULT WINAPI DdsDecoder_QueryCapability(IWICBitmapDecoder *iface, IStream *stream, + DWORD *capability) +{ + FIXME("(%p,%p,%p): stub.\n", iface, stream, capability); + + return E_NOTIMPL; +} + +static HRESULT WINAPI DdsDecoder_Initialize(IWICBitmapDecoder *iface, IStream *pIStream, + WICDecodeOptions cacheOptions) +{ + DdsDecoder *This = impl_from_IWICBitmapDecoder(iface); + HRESULT hr; + + TRACE("(%p,%p,%x)\n", iface, pIStream, cacheOptions); + + EnterCriticalSection(&This->lock); + + hr = IWICWineDecoder_Initialize(&This->IWICWineDecoder_iface, pIStream, cacheOptions); + if (FAILED(hr)) goto end; + + if (This->info.dimension == WICDdsTextureCube || + (This->info.format != DXGI_FORMAT_BC1_UNORM && + This->info.format != DXGI_FORMAT_BC2_UNORM && + This->info.format != DXGI_FORMAT_BC3_UNORM)) { + IStream_Release(pIStream); + This->stream = NULL; + This->initialized = FALSE; + hr = WINCODEC_ERR_BADHEADER; + } + +end: + LeaveCriticalSection(&This->lock); + + return hr; +} + +static HRESULT WINAPI DdsDecoder_GetContainerFormat(IWICBitmapDecoder *iface, + GUID *pguidContainerFormat) +{ + TRACE("(%p,%p)\n", iface, pguidContainerFormat); + + memcpy(pguidContainerFormat, &GUID_ContainerFormatDds, sizeof(GUID)); + + return S_OK; +} + +static HRESULT WINAPI DdsDecoder_GetDecoderInfo(IWICBitmapDecoder *iface, + IWICBitmapDecoderInfo **ppIDecoderInfo) +{ + TRACE("(%p,%p)\n", iface, ppIDecoderInfo); + + return get_decoder_info(&CLSID_WICDdsDecoder, ppIDecoderInfo); +} + +static HRESULT WINAPI DdsDecoder_CopyPalette(IWICBitmapDecoder *iface, + IWICPalette *pIPalette) +{ + TRACE("(%p,%p)\n", iface, pIPalette); + + return WINCODEC_ERR_PALETTEUNAVAILABLE; +} + +static HRESULT WINAPI DdsDecoder_GetMetadataQueryReader(IWICBitmapDecoder *iface, + IWICMetadataQueryReader **ppIMetadataQueryReader) +{ + if (!ppIMetadataQueryReader) return E_INVALIDARG; + + FIXME("(%p,%p)\n", iface, ppIMetadataQueryReader); + + return E_NOTIMPL; +} + +static HRESULT WINAPI DdsDecoder_GetPreview(IWICBitmapDecoder *iface, + IWICBitmapSource **ppIBitmapSource) +{ + TRACE("(%p,%p)\n", iface, ppIBitmapSource); + + return WINCODEC_ERR_UNSUPPORTEDOPERATION; +} + +static HRESULT WINAPI DdsDecoder_GetColorContexts(IWICBitmapDecoder *iface, + UINT cCount, IWICColorContext **ppDdslorContexts, UINT *pcActualCount) +{ + TRACE("(%p,%u,%p,%p)\n", iface, cCount, ppDdslorContexts, pcActualCount); + + return WINCODEC_ERR_UNSUPPORTEDOPERATION; +} + +static HRESULT WINAPI DdsDecoder_GetThumbnail(IWICBitmapDecoder *iface, + IWICBitmapSource **ppIThumbnail) +{ + TRACE("(%p,%p)\n", iface, ppIThumbnail); + + return WINCODEC_ERR_CODECNOTHUMBNAIL; +} + +static HRESULT WINAPI DdsDecoder_GetFrameCount(IWICBitmapDecoder *iface, + UINT *pCount) +{ + DdsDecoder *This = impl_from_IWICBitmapDecoder(iface); + + if (!pCount) return E_INVALIDARG; + if (!This->initialized) return WINCODEC_ERR_WRONGSTATE; + + EnterCriticalSection(&This->lock); + + *pCount = This->info.frame_count; + + LeaveCriticalSection(&This->lock); + + TRACE("(%p) -> %d\n", iface, *pCount); + + return S_OK; +} + +static HRESULT WINAPI DdsDecoder_GetFrame(IWICBitmapDecoder *iface, + UINT index, IWICBitmapFrameDecode **ppIBitmapFrame) +{ + DdsDecoder *This = impl_from_IWICBitmapDecoder(iface); + UINT array_index, mip_level, slice_index; + + TRACE("(%p,%u,%p)\n", iface, index, ppIBitmapFrame); + + if (!ppIBitmapFrame) return E_INVALIDARG; + + EnterCriticalSection(&This->lock); + + if (!This->initialized) { + LeaveCriticalSection(&This->lock); + return WINCODEC_ERR_WRONGSTATE; + } + + get_frame_dds_index(index, &This->info, &array_index, &mip_level, &slice_index); + + LeaveCriticalSection(&This->lock); + + return DdsDecoder_Dds_GetFrame(&This->IWICDdsDecoder_iface, array_index, mip_level, slice_index, ppIBitmapFrame); +} + +static const IWICBitmapDecoderVtbl DdsDecoder_Vtbl = { + DdsDecoder_QueryInterface, + DdsDecoder_AddRef, + DdsDecoder_Release, + DdsDecoder_QueryCapability, + DdsDecoder_Initialize, + DdsDecoder_GetContainerFormat, + DdsDecoder_GetDecoderInfo, + DdsDecoder_CopyPalette, + DdsDecoder_GetMetadataQueryReader, + DdsDecoder_GetPreview, + DdsDecoder_GetColorContexts, + DdsDecoder_GetThumbnail, + DdsDecoder_GetFrameCount, + DdsDecoder_GetFrame +}; + +static HRESULT WINAPI DdsDecoder_Dds_QueryInterface(IWICDdsDecoder *iface, + REFIID iid, void **ppv) +{ + DdsDecoder *This = impl_from_IWICDdsDecoder(iface); + return DdsDecoder_QueryInterface(&This->IWICBitmapDecoder_iface, iid, ppv); +} + +static ULONG WINAPI DdsDecoder_Dds_AddRef(IWICDdsDecoder *iface) +{ + DdsDecoder *This = impl_from_IWICDdsDecoder(iface); + return DdsDecoder_AddRef(&This->IWICBitmapDecoder_iface); +} + +static ULONG WINAPI DdsDecoder_Dds_Release(IWICDdsDecoder *iface) +{ + DdsDecoder *This = impl_from_IWICDdsDecoder(iface); + return DdsDecoder_Release(&This->IWICBitmapDecoder_iface); +} + +static HRESULT WINAPI DdsDecoder_Dds_GetParameters(IWICDdsDecoder *iface, + WICDdsParameters *parameters) +{ + DdsDecoder *This = impl_from_IWICDdsDecoder(iface); + HRESULT hr; + + if (!parameters) return E_INVALIDARG; + + EnterCriticalSection(&This->lock); + + if (!This->initialized) { + hr = WINCODEC_ERR_WRONGSTATE; + goto end; + } + + parameters->Width = This->info.width; + parameters->Height = This->info.height; + parameters->Depth = This->info.depth; + parameters->MipLevels = This->info.mip_levels; + parameters->ArraySize = This->info.array_size; + parameters->DxgiFormat = This->info.format; + parameters->Dimension = This->info.dimension; + parameters->AlphaMode = This->info.alpha_mode; + + TRACE("(%p) -> (%dx%d depth=%d mipLevels=%d arraySize=%d dxgiFormat=0x%x dimension=0x%x alphaMode=0x%x)\n", + iface, parameters->Width, parameters->Height, parameters->Depth, parameters->MipLevels, + parameters->ArraySize, parameters->DxgiFormat, parameters->Dimension, parameters->AlphaMode); + + hr = S_OK; + +end: + LeaveCriticalSection(&This->lock); + + return hr; +} + +static HRESULT WINAPI DdsDecoder_Dds_GetFrame(IWICDdsDecoder *iface, + UINT arrayIndex, UINT mipLevel, UINT sliceIndex, + IWICBitmapFrameDecode **bitmapFrame) +{ + DdsDecoder *This = impl_from_IWICDdsDecoder(iface); + HRESULT hr; + LARGE_INTEGER seek; + UINT width, height, depth, block_width, block_height, width_in_blocks, height_in_blocks, size; + UINT frame_width = 0, frame_height = 0, frame_width_in_blocks = 0, frame_height_in_blocks = 0, frame_size = 0; + UINT bytes_per_block, i; + DWORD bytesread; + DdsFrameDecode *frame_decode = NULL; + + TRACE("(%p,%u,%u,%u,%p)\n", iface, arrayIndex, mipLevel, sliceIndex, bitmapFrame); + + if (!bitmapFrame) return E_INVALIDARG; + + EnterCriticalSection(&This->lock); + + if (!This->initialized) { + hr = WINCODEC_ERR_WRONGSTATE; + goto end; + } + + if ((arrayIndex >= This->info.array_size && This->info.dimension != WICDdsTextureCube) || + (arrayIndex >= This->info.array_size * 6) || + (mipLevel >= This->info.mip_levels) || + (sliceIndex >= This->info.depth)) { + hr = E_INVALIDARG; + goto end; + } + + if (is_compressed(This->info.format)) { + block_width = DDS_BLOCK_WIDTH; + block_height = DDS_BLOCK_HEIGHT; + } else { + block_width = 1; + block_height = 1; + } + bytes_per_block = This->info.bytes_per_block; + seek.QuadPart = This->info.data_offset; + + width = This->info.width; + height = This->info.height; + depth = This->info.depth; + for (i = 0; i < This->info.mip_levels; i++) + { + width_in_blocks = (width + block_width - 1) / block_width; + height_in_blocks = (height + block_height - 1) / block_height; + size = width_in_blocks * height_in_blocks * bytes_per_block; + + if (i < mipLevel) { + seek.QuadPart += size * depth; + } else if (i == mipLevel){ + seek.QuadPart += size * sliceIndex; + frame_width = width; + frame_height = height; + frame_width_in_blocks = width_in_blocks; + frame_height_in_blocks = height_in_blocks; + frame_size = frame_width_in_blocks * frame_height_in_blocks * bytes_per_block; + if (arrayIndex == 0) break; + } + seek.QuadPart += arrayIndex * size * depth; + + if (width > 1) width /= 2; + if (height > 1) height /= 2; + if (depth > 1) depth /= 2; + } + + hr = DdsFrameDecode_CreateInstance(&frame_decode); + if (hr != S_OK) goto end; + frame_decode->info.width = frame_width; + frame_decode->info.height = frame_height; + frame_decode->info.format = This->info.format; + frame_decode->info.bytes_per_block = bytes_per_block; + frame_decode->info.block_width = block_width; + frame_decode->info.block_height = block_height; + frame_decode->info.width_in_blocks = frame_width_in_blocks; + frame_decode->info.height_in_blocks = frame_height_in_blocks; + frame_decode->info.pixel_format = This->info.pixel_format; + frame_decode->info.pixel_format_bpp = This->info.pixel_format_bpp; + frame_decode->block_data = malloc(frame_size); + frame_decode->pixel_data = NULL; + hr = IStream_Seek(This->stream, seek, SEEK_SET, NULL); + if (hr != S_OK) goto end; + hr = IStream_Read(This->stream, frame_decode->block_data, frame_size, &bytesread); + if (hr != S_OK || bytesread != frame_size) { + hr = WINCODEC_ERR_STREAMREAD; + goto end; + } + *bitmapFrame = &frame_decode->IWICBitmapFrameDecode_iface; + + hr = S_OK; + +end: + LeaveCriticalSection(&This->lock); + + if (hr != S_OK && frame_decode) DdsFrameDecode_Release(&frame_decode->IWICBitmapFrameDecode_iface); + + return hr; +} + +static const IWICDdsDecoderVtbl DdsDecoder_Dds_Vtbl = { + DdsDecoder_Dds_QueryInterface, + DdsDecoder_Dds_AddRef, + DdsDecoder_Dds_Release, + DdsDecoder_Dds_GetParameters, + DdsDecoder_Dds_GetFrame +}; + +static HRESULT WINAPI DdsDecoder_Wine_QueryInterface(IWICWineDecoder *iface, REFIID iid, void **ppv) +{ + DdsDecoder *This = impl_from_IWICWineDecoder(iface); + return DdsDecoder_QueryInterface(&This->IWICBitmapDecoder_iface, iid, ppv); +} + +static ULONG WINAPI DdsDecoder_Wine_AddRef(IWICWineDecoder *iface) +{ + DdsDecoder *This = impl_from_IWICWineDecoder(iface); + return DdsDecoder_AddRef(&This->IWICBitmapDecoder_iface); +} + +static ULONG WINAPI DdsDecoder_Wine_Release(IWICWineDecoder *iface) +{ + DdsDecoder *This = impl_from_IWICWineDecoder(iface); + return DdsDecoder_Release(&This->IWICBitmapDecoder_iface); +} + +static HRESULT WINAPI DdsDecoder_Wine_Initialize(IWICWineDecoder *iface, IStream *stream, WICDecodeOptions options) +{ + DdsDecoder *This = impl_from_IWICWineDecoder(iface); + DDS_HEADER_DXT10 header_dxt10; + LARGE_INTEGER seek; + DDS_HEADER header; + ULONG bytesread; + DWORD magic; + HRESULT hr; + + TRACE("(This %p, stream %p, options %#x)\n", iface, stream, options); + + EnterCriticalSection(&This->lock); + + if (This->initialized) { + hr = WINCODEC_ERR_WRONGSTATE; + goto end; + } + + seek.QuadPart = 0; + hr = IStream_Seek(stream, seek, SEEK_SET, NULL); + if (FAILED(hr)) goto end; + + hr = IStream_Read(stream, &magic, sizeof(magic), &bytesread); + if (FAILED(hr)) goto end; + if (bytesread != sizeof(magic)) { + hr = WINCODEC_ERR_STREAMREAD; + goto end; + } + if (magic != DDS_MAGIC) { + hr = WINCODEC_ERR_UNKNOWNIMAGEFORMAT; + goto end; + } + + hr = IStream_Read(stream, &header, sizeof(header), &bytesread); + if (FAILED(hr)) goto end; + if (bytesread != sizeof(header)) { + hr = WINCODEC_ERR_STREAMREAD; + goto end; + } + if (header.size != sizeof(header)) { + hr = WINCODEC_ERR_BADHEADER; + goto end; + } + + if (has_extended_header(&header)) { + hr = IStream_Read(stream, &header_dxt10, sizeof(header_dxt10), &bytesread); + if (FAILED(hr)) goto end; + if (bytesread != sizeof(header_dxt10)) { + hr = WINCODEC_ERR_STREAMREAD; + goto end; + } + } + + get_dds_info(&This->info, &header, &header_dxt10); + + This->initialized = TRUE; + This->stream = stream; + IStream_AddRef(stream); + +end: + LeaveCriticalSection(&This->lock); + + return hr; +} + +static const IWICWineDecoderVtbl DdsDecoder_Wine_Vtbl = { + DdsDecoder_Wine_QueryInterface, + DdsDecoder_Wine_AddRef, + DdsDecoder_Wine_Release, + DdsDecoder_Wine_Initialize +}; + +static HRESULT WINAPI DdsFrameEncode_QueryInterface(IWICBitmapFrameEncode *iface, REFIID iid, void **ppv) +{ + DdsFrameEncode *This = impl_from_IWICBitmapFrameEncode(iface); + TRACE("(%p,%s,%p)\n", iface, debugstr_guid(iid), ppv); + + if (!ppv) return E_INVALIDARG; + + if (IsEqualIID(&IID_IUnknown, iid) || + IsEqualIID(&IID_IWICBitmapFrameEncode, iid)) + { + *ppv = &This->IWICBitmapFrameEncode_iface; + } + else + { + *ppv = NULL; + return E_NOINTERFACE; + } + + IUnknown_AddRef((IUnknown*)*ppv); + return S_OK; +} + +static ULONG WINAPI DdsFrameEncode_AddRef(IWICBitmapFrameEncode *iface) +{ + DdsFrameEncode *This = impl_from_IWICBitmapFrameEncode(iface); + ULONG ref = InterlockedIncrement(&This->ref); + + TRACE("(%p) refcount=%lu\n", iface, ref); + + return ref; +} + +static ULONG WINAPI DdsFrameEncode_Release(IWICBitmapFrameEncode *iface) +{ + DdsFrameEncode *This = impl_from_IWICBitmapFrameEncode(iface); + ULONG ref = InterlockedDecrement(&This->ref); + + TRACE("(%p) refcount=%lu\n", iface, ref); + + if (ref == 0) + { + IWICBitmapEncoder_Release(&This->parent->IWICBitmapEncoder_iface); + free(This); + } + + return ref; +} + +static HRESULT WINAPI DdsFrameEncode_Initialize(IWICBitmapFrameEncode *iface, + IPropertyBag2 *encoderOptions) +{ + DdsFrameEncode *This = impl_from_IWICBitmapFrameEncode(iface); + HRESULT hr; + + TRACE("(%p,%p)\n", iface, encoderOptions); + if (encoderOptions) FIXME("encoder options are not supported for DDS.\n"); + + EnterCriticalSection(&This->parent->lock); + + if (This->initialized) + { + hr = WINCODEC_ERR_WRONGSTATE; + } + else + { + This->initialized = TRUE; + hr = S_OK; + } + + LeaveCriticalSection(&This->parent->lock); + + return hr; +} + +static HRESULT WINAPI DdsFrameEncode_SetSize(IWICBitmapFrameEncode *iface, + UINT width, UINT height) +{ + DdsFrameEncode *This = impl_from_IWICBitmapFrameEncode(iface); + HRESULT hr; + + TRACE("(%p,%u,%u)\n", iface, width, height); + + EnterCriticalSection(&This->parent->lock); + + if (!This->initialized || This->frame_created) + { + hr = WINCODEC_ERR_WRONGSTATE; + } + else + { + This->width = width; + This->height = height; + hr = S_OK; + } + + LeaveCriticalSection(&This->parent->lock); + + return hr; +} + +static HRESULT WINAPI DdsFrameEncode_SetResolution(IWICBitmapFrameEncode *iface, + double dpiX, double dpiY) +{ + DdsFrameEncode *This = impl_from_IWICBitmapFrameEncode(iface); + HRESULT hr; + + TRACE("(%p,%0.2f,%0.2f)\n", iface, dpiX, dpiY); + + EnterCriticalSection(&This->parent->lock); + + if (!This->initialized || This->frame_created) + { + hr = WINCODEC_ERR_WRONGSTATE; + } + else + { + This->dpi_x = dpiX; + This->dpi_y = dpiY; + hr = S_OK; + } + + LeaveCriticalSection(&This->parent->lock); + + return hr; +} + +static HRESULT WINAPI DdsFrameEncode_SetPixelFormat(IWICBitmapFrameEncode *iface, + WICPixelFormatGUID *pixelFormat) +{ + DdsFrameEncode *This = impl_from_IWICBitmapFrameEncode(iface); + HRESULT hr; + + TRACE("(%p,%s)\n", iface, debugstr_guid(pixelFormat)); + + EnterCriticalSection(&This->parent->lock); + + if (!This->initialized) + { + hr = WINCODEC_ERR_NOTINITIALIZED; + } + else if (This->frame_created) + { + hr = WINCODEC_ERR_WRONGSTATE; + } + else + { + *pixelFormat = GUID_WICPixelFormat32bppBGRA; + hr = S_OK; + } + + LeaveCriticalSection(&This->parent->lock); + + return hr; +} + +static HRESULT WINAPI DdsFrameEncode_SetColorContexts(IWICBitmapFrameEncode *iface, + UINT count, IWICColorContext **colorContext) +{ + FIXME("(%p,%u,%p): stub\n", iface, count, colorContext); + return E_NOTIMPL; +} + +static HRESULT WINAPI DdsFrameEncode_SetPalette(IWICBitmapFrameEncode *iface, + IWICPalette *palette) +{ + FIXME("(%p,%p): stub\n", iface, palette); + return E_NOTIMPL; +} + +static HRESULT WINAPI DdsFrameEncode_SetThumbnail(IWICBitmapFrameEncode *iface, + IWICBitmapSource *thumbnail) +{ + TRACE("(%p,%p)\n", iface, thumbnail); + return WINCODEC_ERR_UNSUPPORTEDOPERATION; +} + +static HRESULT WINAPI DdsFrameEncode_WritePixels(IWICBitmapFrameEncode *iface, + UINT lineCount, UINT stride, UINT bufferSize, BYTE *pixels) +{ + FIXME("(%p,%u,%u,%u,%p): stub\n", iface, lineCount, stride, bufferSize, pixels); + return E_NOTIMPL; +} + +static HRESULT WINAPI DdsFrameEncode_WriteSource(IWICBitmapFrameEncode *iface, + IWICBitmapSource *bitmapSource, WICRect *rc) +{ + FIXME("(%p,%p,%s): stub\n", iface, bitmapSource, debug_wic_rect(rc)); + return E_NOTIMPL; +} + +static HRESULT WINAPI DdsFrameEncode_Commit(IWICBitmapFrameEncode *iface) +{ + FIXME("(%p): stub\n", iface); + return E_NOTIMPL; +} + +static HRESULT WINAPI DdsFrameEncode_GetMetadataQueryWriter(IWICBitmapFrameEncode *iface, + IWICMetadataQueryWriter **metadataQueryWriter) +{ + FIXME("(%p,%p): stub\n", iface, metadataQueryWriter); + return E_NOTIMPL; +} + +static const IWICBitmapFrameEncodeVtbl DdsFrameEncode_Vtbl = { + DdsFrameEncode_QueryInterface, + DdsFrameEncode_AddRef, + DdsFrameEncode_Release, + DdsFrameEncode_Initialize, + DdsFrameEncode_SetSize, + DdsFrameEncode_SetResolution, + DdsFrameEncode_SetPixelFormat, + DdsFrameEncode_SetColorContexts, + DdsFrameEncode_SetPalette, + DdsFrameEncode_SetThumbnail, + DdsFrameEncode_WritePixels, + DdsFrameEncode_WriteSource, + DdsFrameEncode_Commit, + DdsFrameEncode_GetMetadataQueryWriter +}; + +HRESULT DdsDecoder_CreateInstance(REFIID iid, void** ppv) +{ + DdsDecoder *This; + HRESULT ret; + + TRACE("(%s,%p)\n", debugstr_guid(iid), ppv); + + *ppv = NULL; + + This = malloc(sizeof(DdsDecoder)); + if (!This) return E_OUTOFMEMORY; + + This->IWICBitmapDecoder_iface.lpVtbl = &DdsDecoder_Vtbl; + This->IWICDdsDecoder_iface.lpVtbl = &DdsDecoder_Dds_Vtbl; + This->IWICWineDecoder_iface.lpVtbl = &DdsDecoder_Wine_Vtbl; + This->ref = 1; + This->initialized = FALSE; + This->stream = NULL; +#ifdef __REACTOS__ + InitializeCriticalSection(&This->lock); +#else + InitializeCriticalSectionEx(&This->lock, 0, RTL_CRITICAL_SECTION_FLAG_FORCE_DEBUG_INFO); +#endif + This->lock.DebugInfo->Spare[0] = (DWORD_PTR)(__FILE__ ": DdsDecoder.lock"); + + ret = IWICBitmapDecoder_QueryInterface(&This->IWICBitmapDecoder_iface, iid, ppv); + IWICBitmapDecoder_Release(&This->IWICBitmapDecoder_iface); + + return ret; +} + +static HRESULT WINAPI DdsEncoder_Dds_QueryInterface(IWICDdsEncoder *iface, REFIID iid, + void **ppv) +{ + DdsEncoder *This = impl_from_IWICDdsEncoder(iface); + return IWICBitmapEncoder_QueryInterface(&This->IWICBitmapEncoder_iface, iid, ppv); +} + +static ULONG WINAPI DdsEncoder_Dds_AddRef(IWICDdsEncoder *iface) +{ + DdsEncoder *This = impl_from_IWICDdsEncoder(iface); + return IWICBitmapEncoder_AddRef(&This->IWICBitmapEncoder_iface); +} + +static ULONG WINAPI DdsEncoder_Dds_Release(IWICDdsEncoder *iface) +{ + DdsEncoder *This = impl_from_IWICDdsEncoder(iface); + return IWICBitmapEncoder_Release(&This->IWICBitmapEncoder_iface); +} + +static HRESULT WINAPI DdsEncoder_Dds_SetParameters(IWICDdsEncoder *iface, + WICDdsParameters *parameters) +{ + DdsEncoder *This = impl_from_IWICDdsEncoder(iface); + HRESULT hr; + + TRACE("(%p,%p)\n", iface, parameters); + + if (!parameters) return E_INVALIDARG; + + EnterCriticalSection(&This->lock); + + if (!This->stream) + { + hr = WINCODEC_ERR_WRONGSTATE; + goto end; + } + + This->info.width = parameters->Width; + This->info.height = parameters->Height; + This->info.depth = parameters->Depth; + This->info.mip_levels = parameters->MipLevels; + This->info.array_size = parameters->ArraySize; + This->info.format = parameters->DxgiFormat; + This->info.dimension = parameters->Dimension; + This->info.alpha_mode = parameters->AlphaMode; + + This->info.bytes_per_block = get_bytes_per_block_from_format(This->info.format); + This->info.frame_count = get_frame_count(This->info.depth, This->info.mip_levels, + This->info.array_size, This->info.dimension); + + hr = S_OK; + +end: + LeaveCriticalSection(&This->lock); + return hr; +} + +static HRESULT WINAPI DdsEncoder_Dds_GetParameters(IWICDdsEncoder *iface, + WICDdsParameters *parameters) +{ + DdsEncoder *This = impl_from_IWICDdsEncoder(iface); + HRESULT hr; + + TRACE("(%p,%p)\n", iface, parameters); + + if (!parameters) return E_INVALIDARG; + + EnterCriticalSection(&This->lock); + + if (!This->stream) + { + hr = WINCODEC_ERR_WRONGSTATE; + goto end; + } + + parameters->Width = This->info.width; + parameters->Height = This->info.height; + parameters->Depth = This->info.depth; + parameters->MipLevels = This->info.mip_levels; + parameters->ArraySize = This->info.array_size; + parameters->DxgiFormat = This->info.format; + parameters->Dimension = This->info.dimension; + parameters->AlphaMode = This->info.alpha_mode; + + TRACE("(%p,%p) -> (%dx%d depth=%u mipLevels=%u arraySize=%u dxgiFormat=%#x dimension=%#x alphaMode=%#x)\n", + iface, parameters, parameters->Width, parameters->Height, parameters->Depth, parameters->MipLevels, + parameters->ArraySize, parameters->DxgiFormat, parameters->Dimension, parameters->AlphaMode); + + hr = S_OK; + +end: + LeaveCriticalSection(&This->lock); + return hr; +} + +static HRESULT WINAPI DdsEncoder_Dds_CreateNewFrame(IWICDdsEncoder *iface, + IWICBitmapFrameEncode **frameEncode, + UINT *arrayIndex, UINT *mipLevel, UINT *sliceIndex) +{ + DdsEncoder *This = impl_from_IWICDdsEncoder(iface); + UINT array_index, mip_level, slice_index; + DdsFrameEncode *result; + HRESULT hr; + + TRACE("(%p,%p,%p,%p,%p)\n", iface, frameEncode, arrayIndex, mipLevel, sliceIndex); + + EnterCriticalSection(&This->lock); + + if (!This->stream || This->committed || This->uncommitted_frame) + { + hr = WINCODEC_ERR_WRONGSTATE; + goto end; + } + + result = malloc(sizeof(*result)); + if (!result) + { + hr = E_OUTOFMEMORY; + goto end; + } + + get_frame_dds_index(This->frame_index, &This->info, &array_index, &mip_level, &slice_index); + if (arrayIndex) *arrayIndex = array_index; + if (mipLevel) *mipLevel = mip_level; + if (sliceIndex) *sliceIndex = slice_index; + + This->frame_index++; + result->IWICBitmapFrameEncode_iface.lpVtbl = &DdsFrameEncode_Vtbl; + result->ref = 1; + result->parent = This; + result->parent->uncommitted_frame = TRUE; + result->initialized = FALSE; + result->frame_created = FALSE; + IWICDdsEncoder_AddRef(iface); + + *frameEncode = &result->IWICBitmapFrameEncode_iface; + hr = S_OK; + +end: + LeaveCriticalSection(&This->lock); + return hr; +} + +static const IWICDdsEncoderVtbl DdsEncoder_Dds_Vtbl = +{ + DdsEncoder_Dds_QueryInterface, + DdsEncoder_Dds_AddRef, + DdsEncoder_Dds_Release, + DdsEncoder_Dds_SetParameters, + DdsEncoder_Dds_GetParameters, + DdsEncoder_Dds_CreateNewFrame +}; + +static HRESULT WINAPI DdsEncoder_QueryInterface(IWICBitmapEncoder *iface, REFIID iid, + void **ppv) +{ + DdsEncoder *This = impl_from_IWICBitmapEncoder(iface); + FIXME("(%p,%s,%p)\n", iface, debugstr_guid(iid), ppv); + + if (!ppv) return E_INVALIDARG; + + if (IsEqualIID(&IID_IUnknown, iid) || + IsEqualIID(&IID_IWICBitmapEncoder, iid)) { + *ppv = &This->IWICBitmapEncoder_iface; + } else if (IsEqualIID(&IID_IWICDdsEncoder, iid)) { + *ppv = &This->IWICDdsEncoder_iface; + } else { + *ppv = NULL; + return E_NOINTERFACE; + } + + IUnknown_AddRef((IUnknown*)*ppv); + return S_OK; +} + +static ULONG WINAPI DdsEncoder_AddRef(IWICBitmapEncoder *iface) +{ + DdsEncoder *This = impl_from_IWICBitmapEncoder(iface); + ULONG ref = InterlockedIncrement(&This->ref); + + TRACE("(%p) refcount=%lu\n", iface, ref); + + return ref; +} + +static ULONG WINAPI DdsEncoder_Release(IWICBitmapEncoder *iface) +{ + DdsEncoder *This = impl_from_IWICBitmapEncoder(iface); + ULONG ref = InterlockedDecrement(&This->ref); + + TRACE("(%p) refcount=%lu\n", iface, ref); + + if (ref == 0) { + This->lock.DebugInfo->Spare[0] = 0; + DeleteCriticalSection(&This->lock); + if (This->stream) IStream_Release(This->stream); + free(This); + } + + return ref; +} + +static HRESULT WINAPI DdsEncoder_Initialize(IWICBitmapEncoder *iface, + IStream *stream, WICBitmapEncoderCacheOption cacheOption) +{ + DdsEncoder *This = impl_from_IWICBitmapEncoder(iface); + HRESULT hr; + + TRACE("(%p,%p,%u)\n", iface, stream, cacheOption); + + if (cacheOption != WICBitmapEncoderNoCache) + FIXME("Cache option %#x is not supported.\n", cacheOption); + + if (!stream) return E_INVALIDARG; + + EnterCriticalSection(&This->lock); + + if (This->stream) + { + hr = WINCODEC_ERR_WRONGSTATE; + goto end; + } + + This->stream = stream; + IStream_AddRef(stream); + + This->info.width = 1; + This->info.height = 1; + This->info.depth = 1; + This->info.mip_levels = 1; + This->info.array_size = 1; + This->info.frame_count = 1; + This->info.data_offset = 0; + This->info.bytes_per_block = get_bytes_per_block_from_format(DXGI_FORMAT_BC3_UNORM); + This->info.format = DXGI_FORMAT_BC3_UNORM; + This->info.dimension = WICDdsTexture2D; + This->info.alpha_mode = WICDdsAlphaModeUnknown; + This->info.pixel_format = &GUID_WICPixelFormatUndefined; + This->info.pixel_format_bpp = 0; + + hr = S_OK; + +end: + LeaveCriticalSection(&This->lock); + + return hr; +} + +static HRESULT WINAPI DdsEncoder_GetContainerFormat(IWICBitmapEncoder *iface, GUID *format) +{ + TRACE("(%p,%p)\n", iface, format); + + if (!format) + return E_INVALIDARG; + + memcpy(format, &GUID_ContainerFormatDds, sizeof(*format)); + return S_OK; +} + +static HRESULT WINAPI DdsEncoder_GetEncoderInfo(IWICBitmapEncoder *iface, IWICBitmapEncoderInfo **info) +{ + IWICComponentInfo *comp_info; + HRESULT hr; + + TRACE("%p,%p\n", iface, info); + + if (!info) return E_INVALIDARG; + + hr = CreateComponentInfo(&CLSID_WICDdsEncoder, &comp_info); + if (hr == S_OK) { + hr = IWICComponentInfo_QueryInterface(comp_info, &IID_IWICBitmapEncoderInfo, (void **)info); + IWICComponentInfo_Release(comp_info); + } + return hr; +} + +static HRESULT WINAPI DdsEncoder_SetColorContexts(IWICBitmapEncoder *iface, + UINT cCount, IWICColorContext **ppIColorContext) +{ + FIXME("(%p,%u,%p): stub\n", iface, cCount, ppIColorContext); + return E_NOTIMPL; +} + +static HRESULT WINAPI DdsEncoder_SetPalette(IWICBitmapEncoder *iface, IWICPalette *palette) +{ + DdsEncoder *This = impl_from_IWICBitmapEncoder(iface); + HRESULT hr; + + TRACE("(%p,%p)\n", iface, palette); + + EnterCriticalSection(&This->lock); + + hr = This->stream ? WINCODEC_ERR_UNSUPPORTEDOPERATION : WINCODEC_ERR_NOTINITIALIZED; + + LeaveCriticalSection(&This->lock); + + return hr; +} + +static HRESULT WINAPI DdsEncoder_SetThumbnail(IWICBitmapEncoder *iface, IWICBitmapSource *pIThumbnail) +{ + TRACE("(%p,%p)\n", iface, pIThumbnail); + return WINCODEC_ERR_UNSUPPORTEDOPERATION; +} + +static HRESULT WINAPI DdsEncoder_SetPreview(IWICBitmapEncoder *iface, IWICBitmapSource *pIPreview) +{ + TRACE("(%p,%p)\n", iface, pIPreview); + return WINCODEC_ERR_UNSUPPORTEDOPERATION; +} + +static HRESULT WINAPI DdsEncoder_CreateNewFrame(IWICBitmapEncoder *iface, + IWICBitmapFrameEncode **frameEncode, IPropertyBag2 **encoderOptions) +{ + DdsEncoder *This = impl_from_IWICBitmapEncoder(iface); + + TRACE("(%p,%p,%p)\n", iface, frameEncode, encoderOptions); + + return IWICDdsEncoder_CreateNewFrame(&This->IWICDdsEncoder_iface, frameEncode, NULL, NULL, NULL); +} + +static HRESULT WINAPI DdsEncoder_Commit(IWICBitmapEncoder *iface) +{ + FIXME("(%p): stub\n", iface); + return E_NOTIMPL; +} + +static HRESULT WINAPI DdsEncoder_GetMetadataQueryWriter(IWICBitmapEncoder *iface, + IWICMetadataQueryWriter **ppIMetadataQueryWriter) +{ + FIXME("(%p,%p): stub\n", iface, ppIMetadataQueryWriter); + return E_NOTIMPL; +} + +static const IWICBitmapEncoderVtbl DdsEncoder_Vtbl = { + DdsEncoder_QueryInterface, + DdsEncoder_AddRef, + DdsEncoder_Release, + DdsEncoder_Initialize, + DdsEncoder_GetContainerFormat, + DdsEncoder_GetEncoderInfo, + DdsEncoder_SetColorContexts, + DdsEncoder_SetPalette, + DdsEncoder_SetThumbnail, + DdsEncoder_SetPreview, + DdsEncoder_CreateNewFrame, + DdsEncoder_Commit, + DdsEncoder_GetMetadataQueryWriter +}; + +HRESULT DdsEncoder_CreateInstance( REFIID iid, void **ppv) +{ + DdsEncoder *This; + HRESULT ret; + + TRACE("(%s,%p)\n", debugstr_guid(iid), ppv); + + *ppv = NULL; + + This = malloc(sizeof(DdsEncoder)); + if (!This) return E_OUTOFMEMORY; + + This->IWICBitmapEncoder_iface.lpVtbl = &DdsEncoder_Vtbl; + This->IWICDdsEncoder_iface.lpVtbl = &DdsEncoder_Dds_Vtbl; + This->ref = 1; + This->stream = NULL; + This->frame_count = 0; + This->frame_index = 0; + This->uncommitted_frame = FALSE; + This->committed = FALSE; +#ifdef __REACTOS__ + InitializeCriticalSection(&This->lock); +#else + InitializeCriticalSectionEx(&This->lock, 0, RTL_CRITICAL_SECTION_FLAG_FORCE_DEBUG_INFO); +#endif + This->lock.DebugInfo->Spare[0] = (DWORD_PTR)(__FILE__ ": DdsEncoder.lock"); + + ret = IWICBitmapEncoder_QueryInterface(&This->IWICBitmapEncoder_iface, iid, ppv); + IWICBitmapEncoder_Release(&This->IWICBitmapEncoder_iface); + + return ret; +} diff --git a/dll/win32/windowscodecs/decoder.c b/dll/win32/windowscodecs/decoder.c new file mode 100644 index 00000000000..08fe23e1bf0 --- /dev/null +++ b/dll/win32/windowscodecs/decoder.c @@ -0,0 +1,811 @@ +/* + * Copyright 2020 Esme Povirk + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA + */ + +#include <stdarg.h> + +#define COBJMACROS + +#include "windef.h" +#include "winbase.h" +#include "objbase.h" + +#include "wincodecs_private.h" + +#include "wine/debug.h" + +WINE_DEFAULT_DEBUG_CHANNEL(wincodecs); + +typedef struct { + IWICBitmapDecoder IWICBitmapDecoder_iface; + LONG ref; + CRITICAL_SECTION lock; /* must be held when stream or decoder is accessed */ + IStream *stream; + struct decoder *decoder; + struct decoder_info decoder_info; + struct decoder_stat file_info; + WICDecodeOptions cache_options; +} CommonDecoder; + +static inline CommonDecoder *impl_from_IWICBitmapDecoder(IWICBitmapDecoder *iface) +{ + return CONTAINING_RECORD(iface, CommonDecoder, IWICBitmapDecoder_iface); +} + +static HRESULT WINAPI CommonDecoder_QueryInterface(IWICBitmapDecoder *iface, REFIID iid, + void **ppv) +{ + CommonDecoder *This = impl_from_IWICBitmapDecoder(iface); + TRACE("(%p,%s,%p)\n", iface, debugstr_guid(iid), ppv); + + if (!ppv) return E_INVALIDARG; + + if (IsEqualIID(&IID_IUnknown, iid) || IsEqualIID(&IID_IWICBitmapDecoder, iid)) + { + *ppv = &This->IWICBitmapDecoder_iface; + } + else + { + *ppv = NULL; + return E_NOINTERFACE; + } + + IUnknown_AddRef((IUnknown*)*ppv); + return S_OK; +} + +static ULONG WINAPI CommonDecoder_AddRef(IWICBitmapDecoder *iface) +{ + CommonDecoder *This = impl_from_IWICBitmapDecoder(iface); + ULONG ref = InterlockedIncrement(&This->ref); + + TRACE("(%p) refcount=%lu\n", iface, ref); + + return ref; +} + +static ULONG WINAPI CommonDecoder_Release(IWICBitmapDecoder *iface) +{ + CommonDecoder *This = impl_from_IWICBitmapDecoder(iface); + ULONG ref = InterlockedDecrement(&This->ref); + + TRACE("(%p) refcount=%lu\n", iface, ref); + + if (ref == 0) + { + if (This->stream) + IStream_Release(This->stream); + This->lock.DebugInfo->Spare[0] = 0; + DeleteCriticalSection(&This->lock); + decoder_destroy(This->decoder); + free(This); + } + + return ref; +} + +static HRESULT WINAPI CommonDecoder_QueryCapability(IWICBitmapDecoder *iface, IStream *stream, + DWORD *capability) +{ + CommonDecoder *This = impl_from_IWICBitmapDecoder(iface); + HRESULT hr; + + TRACE("(%p,%p,%p)\n", iface, stream, capability); + + if (!stream || !capability) return E_INVALIDARG; + + hr = IWICBitmapDecoder_Initialize(iface, stream, WICDecodeMetadataCacheOnDemand); + if (hr != S_OK) return hr; + + *capability = (This->file_info.flags & DECODER_FLAGS_CAPABILITY_MASK); + return S_OK; +} + +static HRESULT WINAPI CommonDecoder_Initialize(IWICBitmapDecoder *iface, IStream *pIStream, + WICDecodeOptions cacheOptions) +{ + CommonDecoder *This = impl_from_IWICBitmapDecoder(iface); + HRESULT hr=S_OK; + + TRACE("(%p,%p,%x)\n", iface, pIStream, cacheOptions); + + EnterCriticalSection(&This->lock); + + if (This->stream) + hr = WINCODEC_ERR_WRONGSTATE; + + if (SUCCEEDED(hr)) + hr = decoder_initialize(This->decoder, pIStream, &This->file_info); + + if (SUCCEEDED(hr)) + { + This->cache_options = cacheOptions; + This->stream = pIStream; + IStream_AddRef(This->stream); + } + + LeaveCriticalSection(&This->lock); + + return hr; +} + +static HRESULT WINAPI CommonDecoder_GetContainerFormat(IWICBitmapDecoder *iface, + GUID *pguidContainerFormat) +{ + CommonDecoder *This = impl_from_IWICBitmapDecoder(iface); + memcpy(pguidContainerFormat, &This->decoder_info.container_format, sizeof(GUID)); + return S_OK; +} + +static HRESULT WINAPI CommonDecoder_GetDecoderInfo(IWICBitmapDecoder *iface, + IWICBitmapDecoderInfo **ppIDecoderInfo) +{ + CommonDecoder *This = impl_from_IWICBitmapDecoder(iface); + TRACE("(%p,%p)\n", iface, ppIDecoderInfo); + + return get_decoder_info(&This->decoder_info.clsid, ppIDecoderInfo); +} + +static HRESULT WINAPI CommonDecoder_CopyPalette(IWICBitmapDecoder *iface, + IWICPalette *palette) +{ + TRACE("(%p,%p)\n", iface, palette); + return WINCODEC_ERR_PALETTEUNAVAILABLE; +} + +static HRESULT WINAPI CommonDecoder_GetMetadataQueryReader(IWICBitmapDecoder *iface, + IWICMetadataQueryReader **reader) +{ + TRACE("(%p,%p)\n", iface, reader); + + if (!reader) return E_INVALIDARG; + + *reader = NULL; + return WINCODEC_ERR_UNSUPPORTEDOPERATION; +} + +static HRESULT WINAPI CommonDecoder_GetPreview(IWICBitmapDecoder *iface, + IWICBitmapSource **ppIBitmapSource) +{ + TRACE("(%p,%p)\n", iface, ppIBitmapSource); + + if (!ppIBitmapSource) return E_INVALIDARG; + + *ppIBitmapSource = NULL; + return WINCODEC_ERR_UNSUPPORTEDOPERATION; +} + +static HRESULT WINAPI CommonDecoder_GetColorContexts(IWICBitmapDecoder *iface, + UINT cCount, IWICColorContext **ppIColorContexts, UINT *pcActualCount) +{ + TRACE("(%p,%u,%p,%p)\n", iface, cCount, ppIColorContexts, pcActualCount); + return WINCODEC_ERR_UNSUPPORTEDOPERATION; +} + +static HRESULT WINAPI CommonDecoder_GetThumbnail(IWICBitmapDecoder *iface, + IWICBitmapSource **ppIThumbnail) +{ + TRACE("(%p,%p)\n", iface, ppIThumbnail); + + if (!ppIThumbnail) return E_INVALIDARG; + + *ppIThumbnail = NULL; + return WINCODEC_ERR_CODECNOTHUMBNAIL; +} + +static HRESULT WINAPI CommonDecoder_GetFrameCount(IWICBitmapDecoder *iface, + UINT *pCount) +{ + CommonDecoder *This = impl_from_IWICBitmapDecoder(iface); + if (!pCount) return E_INVALIDARG; + + if (This->stream) + *pCount = This->file_info.frame_count; + else + *pCount = 0; + + return S_OK; +} + +static HRESULT WINAPI CommonDecoder_GetFrame(IWICBitmapDecoder *iface, + UINT index, IWICBitmapFrameDecode **ppIBitmapFrame); + +static const IWICBitmapDecoderVtbl CommonDecoder_Vtbl = { + CommonDecoder_QueryInterface, + CommonDecoder_AddRef, + CommonDecoder_Release, + CommonDecoder_QueryCapability, + CommonDecoder_Initialize, + CommonDecoder_GetContainerFormat, + CommonDecoder_GetDecoderInfo, + CommonDecoder_CopyPalette, + CommonDecoder_GetMetadataQueryReader, + CommonDecoder_GetPreview, + CommonDecoder_GetColorContexts, + CommonDecoder_GetThumbnail, + CommonDecoder_GetFrameCount, + CommonDecoder_GetFrame +}; + +typedef struct { + IWICBitmapFrameDecode IWICBitmapFrameDecode_iface; + IWICMetadataBlockReader IWICMetadataBlockReader_iface; + LONG ref; + CommonDecoder *parent; + DWORD frame; + struct decoder_frame decoder_frame; + BOOL metadata_initialized; + UINT metadata_count; + struct decoder_block* metadata_blocks; +} CommonDecoderFrame; + +static inline CommonDecoderFrame *impl_from_IWICBitmapFrameDecode(IWICBitmapFrameDecode *iface) +{ + return CONTAINING_RECORD(iface, CommonDecoderFrame, IWICBitmapFrameDecode_iface); +} + +static inline CommonDecoderFrame *impl_from_IWICMetadataBlockReader(IWICMetadataBlockReader *iface) +{ + return CONTAINING_RECORD(iface, CommonDecoderFrame, IWICMetadataBlockReader_iface); +} + +static HRESULT WINAPI CommonDecoderFrame_QueryInterface(IWICBitmapFrameDecode *iface, REFIID iid, + void **ppv) +{ + CommonDecoderFrame *This = impl_from_IWICBitmapFrameDecode(iface); + if (!ppv) return E_INVALIDARG; + + if (IsEqualIID(&IID_IUnknown, iid) || + IsEqualIID(&IID_IWICBitmapSource, iid) || + IsEqualIID(&IID_IWICBitmapFrameDecode, iid)) + { + *ppv = &This->IWICBitmapFrameDecode_iface; + } + else if (IsEqualIID(&IID_IWICMetadataBlockReader, iid) && + (This->parent->file_info.flags & WICBitmapDecoderCapabilityCanEnumerateMetadata)) + { + *ppv = &This->IWICMetadataBlockReader_iface; + } + else + { + *ppv = NULL; + return E_NOINTERFACE; + } + + IUnknown_AddRef((IUnknown*)*ppv); + return S_OK; +} + +static ULONG WINAPI CommonDecoderFrame_AddRef(IWICBitmapFrameDecode *iface) +{ + CommonDecoderFrame *This = impl_from_IWICBitmapFrameDecode(iface); + ULONG ref = InterlockedIncrement(&This->ref); + + TRACE("(%p) refcount=%lu\n", iface, ref); + + return ref; +} + +static ULONG WINAPI CommonDecoderFrame_Release(IWICBitmapFrameDecode *iface) +{ + CommonDecoderFrame *This = impl_from_IWICBitmapFrameDecode(iface); + ULONG ref = InterlockedDecrement(&This->ref); + + TRACE("(%p) refcount=%lu\n", iface, ref); + + if (ref == 0) + { + IWICBitmapDecoder_Release(&This->parent->IWICBitmapDecoder_iface); + free(This->metadata_blocks); + free(This); + } + + return ref; +} + +static HRESULT WINAPI CommonDecoderFrame_GetSize(IWICBitmapFrameDecode *iface, + UINT *puiWidth, UINT *puiHeight) +{ + CommonDecoderFrame *This = impl_from_IWICBitmapFrameDecode(iface); + + TRACE("(%p,%p,%p)\n", This, puiWidth, puiHeight); + + if (!puiWidth || !puiHeight) + return E_POINTER; + + *puiWidth = This->decoder_frame.width; + *puiHeight = This->decoder_frame.height; + return S_OK; +} + +static HRESULT WINAPI CommonDecoderFrame_GetPixelFormat(IWICBitmapFrameDecode *iface, + WICPixelFormatGUID *pPixelFormat) +{ + CommonDecoderFrame *This = impl_from_IWICBitmapFrameDecode(iface); + + TRACE("(%p,%p)\n", This, pPixelFormat); + + if (!pPixelFormat) + return E_POINTER; + + *pPixelFormat = This->decoder_frame.pixel_format; + return S_OK; +} + +static HRESULT WINAPI CommonDecoderFrame_GetResolution(IWICBitmapFrameDecode *iface, + double *pDpiX, double *pDpiY) +{ + CommonDecoderFrame *This = impl_from_IWICBitmapFrameDecode(iface); + + TRACE("(%p,%p,%p)\n", This, pDpiX, pDpiY); + + if (!pDpiX || !pDpiY) + return E_POINTER; + + *pDpiX = This->decoder_frame.dpix; + *pDpiY = This->decoder_frame.dpiy; + return S_OK; +} + +static HRESULT WINAPI CommonDecoderFrame_CopyPalette(IWICBitmapFrameDecode *iface, + IWICPalette *pIPalette) +{ + CommonDecoderFrame *This = impl_from_IWICBitmapFrameDecode(iface); + HRESULT hr=S_OK; + + TRACE("(%p,%p)\n", iface, pIPalette); + + if (This->decoder_frame.num_colors) + { + hr = IWICPalette_InitializeCustom(pIPalette, This->decoder_frame.palette, This->decoder_frame.num_colors); + } + else + { + hr = WINCODEC_ERR_PALETTEUNAVAILABLE; + } + + return hr; +} + +static HRESULT WINAPI CommonDecoderFrame_CopyPixels(IWICBitmapFrameDecode *iface, + const WICRect *prc, UINT cbStride, UINT cbBufferSize, BYTE *pbBuffer) +{ + CommonDecoderFrame *This = impl_from_IWICBitmapFrameDecode(iface); + HRESULT hr; + UINT bytesperrow; + WICRect rect; + + TRACE("(%p,%s,%u,%u,%p)\n", iface, debug_wic_rect(prc), cbStride, cbBufferSize, pbBuffer); + + if (!pbBuffer) + return E_POINTER; + + if (!prc) + { + rect.X = 0; + rect.Y = 0; + rect.Width = This->decoder_frame.width; + rect.Height = This->decoder_frame.height; + prc = ▭ + } + else + { + if (prc->X < 0 || prc->Y < 0 || + prc->X+prc->Width > This->decoder_frame.width || + prc->Y+prc->Height > This->decoder_frame.height) + return E_INVALIDARG; + } + + bytesperrow = ((This->decoder_frame.bpp * prc->Width)+7)/8; + + if (cbStride < bytesperrow) + return E_INVALIDARG; + + if ((cbStride * (prc->Height-1)) + bytesperrow > cbBufferSize) + return E_INVALIDARG; + + EnterCriticalSection(&This->parent->lock); + + hr = decoder_copy_pixels(This->parent->decoder, This->frame, + prc, cbStride, cbBufferSize, pbBuffer); + + LeaveCriticalSection(&This->parent->lock); + + return hr; +} + +static HRESULT WINAPI CommonDecoderFrame_GetMetadataQueryReader(IWICBitmapFrameDecode *iface, + IWICMetadataQueryReader **ppIMetadataQueryReader) +{ + CommonDecoderFrame *This = impl_from_IWICBitmapFrameDecode(iface); + IWICComponentFactory* factory; + HRESULT hr; + + TRACE("(%p,%p)\n", iface, ppIMetadataQueryReader); + + if (!ppIMetadataQueryReader) + return E_INVALIDARG; + + if (!(This->parent->file_info.flags & WICBitmapDecoderCapabilityCanEnumerateMetadata)) + return WINCODEC_ERR_UNSUPPORTEDOPERATION; + + hr = create_instance(&CLSID_WICImagingFactory, &IID_IWICComponentFactory, (void**)&factory); + + if (SUCCEEDED(hr)) + { + hr = IWICComponentFactory_CreateQueryReaderFromBlockReader(factory, &This->IWICMetadataBlockReader_iface, ppIMetadataQueryReader); + IWICComponentFactory_Release(factory); + } + + if (FAILED(hr)) + *ppIMetadataQueryReader = NULL; + + return hr; +} + +static HRESULT WINAPI CommonDecoderFrame_GetColorContexts(IWICBitmapFrameDecode *iface, + UINT cCount, IWICColorContext **ppIColorContexts, UINT *pcActualCount) +{ + CommonDecoderFrame *This = impl_from_IWICBitmapFrameDecode(iface); + HRESULT hr=S_OK; + UINT i; + BYTE *profile; + DWORD profile_len; + + TRACE("(%p,%u,%p,%p)\n", iface, cCount, ppIColorContexts, pcActualCount); + + if (!pcActualCount) return E_INVALIDARG; + + if (This->parent->file_info.flags & DECODER_FLAGS_UNSUPPORTED_COLOR_CONTEXT) + { + FIXME("not supported for %s\n", wine_dbgstr_guid(&This->parent->decoder_info.clsid)); + *pcActualCount = 0; + return WINCODEC_ERR_UNSUPPORTEDOPERATION; + } + + *pcActualCount = This->decoder_frame.num_color_contexts; + + if (This->decoder_frame.num_color_contexts && cCount && ppIColorContexts) + { + if (cCount >= This->decoder_frame.num_color_contexts) + { + EnterCriticalSection(&This->parent->lock); + + for (i=0; i<This->decoder_frame.num_color_contexts; i++) + { + hr = decoder_get_color_context(This->parent->decoder, This->frame, i, + &profile, &profile_len); + if (SUCCEEDED(hr)) + { + hr = IWICColorContext_InitializeFromMemory(ppIColorContexts[i], profile, profile_len); + + free(profile); + } + + if (FAILED(hr)) + break; + } + + LeaveCriticalSection(&This->parent->lock); + } + else + { + hr = E_INVALIDARG; + } + } + + return hr; +} + +static HRESULT WINAPI CommonDecoderFrame_GetThumbnail(IWICBitmapFrameDecode *iface, + IWICBitmapSource **ppIThumbnail) +{ + TRACE("(%p,%p)\n", iface, ppIThumbnail); + + if (!ppIThumbnail) return E_INVALIDARG; + + *ppIThumbnail = NULL; + return WINCODEC_ERR_CODECNOTHUMBNAIL; +} + +static const IWICBitmapFrameDecodeVtbl CommonDecoderFrameVtbl = { + CommonDecoderFrame_QueryInterface, + CommonDecoderFrame_AddRef, + CommonDecoderFrame_Release, + CommonDecoderFrame_GetSize, + CommonDecoderFrame_GetPixelFormat, + CommonDecoderFrame_GetResolution, + CommonDecoderFrame_CopyPalette, + CommonDecoderFrame_CopyPixels, + CommonDecoderFrame_GetMetadataQueryReader, + CommonDecoderFrame_GetColorContexts, + CommonDecoderFrame_GetThumbnail +}; + +static HRESULT WINAPI CommonDecoderFrame_Block_QueryInterface(IWICMetadataBlockReader *iface, REFIID iid, + void **ppv) +{ + CommonDecoderFrame *This = impl_from_IWICMetadataBlockReader(iface); + return IWICBitmapFrameDecode_QueryInterface(&This->IWICBitmapFrameDecode_iface, iid, ppv); +} + +static ULONG WINAPI CommonDecoderFrame_Block_AddRef(IWICMetadataBlockReader *iface) +{ + CommonDecoderFrame *This = impl_from_IWICMetadataBlockReader(iface); + return IWICBitmapFrameDecode_AddRef(&This->IWICBitmapFrameDecode_iface); +} + +static ULONG WINAPI CommonDecoderFrame_Block_Release(IWICMetadataBlockReader *iface) +{ + CommonDecoderFrame *This = impl_from_IWICMetadataBlockReader(iface); + return IWICBitmapFrameDecode_Release(&This->IWICBitmapFrameDecode_iface); +} + +static HRESULT WINAPI CommonDecoderFrame_Block_GetContainerFormat(IWICMetadataBlockReader *iface, + GUID *pguidContainerFormat) +{ + CommonDecoderFrame *This = impl_from_IWICMetadataBlockReader(iface); + if (!pguidContainerFormat) return E_INVALIDARG; + *pguidContainerFormat = This->parent->decoder_info.block_format; + return S_OK; +} + +static HRESULT CommonDecoderFrame_InitializeMetadata(CommonDecoderFrame *This) +{ + HRESULT hr=S_OK; + + if (This->metadata_initialized) + return S_OK; + + EnterCriticalSection(&This->parent->lock); + + if (!This->metadata_initialized) + { + hr = decoder_get_metadata_blocks(This->parent->decoder, This->frame, &This->metadata_count, &This->metadata_blocks); + if (SUCCEEDED(hr)) + This->metadata_initialized = TRUE; + } + + LeaveCriticalSection(&This->parent->lock); + + return hr; +} + +static HRESULT WINAPI CommonDecoderFrame_Block_GetCount(IWICMetadataBlockReader *iface, + UINT *pcCount) +{ + CommonDecoderFrame *This = impl_from_IWICMetadataBlockReader(iface); + HRESULT hr; + + TRACE("%p,%p\n", iface, pcCount); + + if (!pcCount) return E_INVALIDARG; + + hr = CommonDecoderFrame_InitializeMetadata(This); + if (SUCCEEDED(hr)) + *pcCount = This->metadata_count; + + return hr; +} + +static HRESULT WINAPI CommonDecoderFrame_Block_GetReaderByIndex(IWICMetadataBlockReader *iface, + UINT nIndex, IWICMetadataReader **ppIMetadataReader) +{ + CommonDecoderFrame *This = impl_from_IWICMetadataBlockReader(iface); + HRESULT hr; + IWICComponentFactory* factory = NULL; + IWICStream* stream; + + TRACE("%p,%d,%p\n", iface, nIndex, ppIMetadataReader); + + if (!ppIMetadataReader) + return E_INVALIDARG; + + hr = CommonDecoderFrame_InitializeMetadata(This); + + if (SUCCEEDED(hr) && nIndex >= This->metadata_count) + hr = E_INVALIDARG; + + if (SUCCEEDED(hr)) + hr = create_instance(&CLSID_WICImagingFactory, &IID_IWICComponentFactory, (void**)&factory); + + if (SUCCEEDED(hr)) + hr = IWICComponentFactory_CreateStream(factory, &stream); + + if (SUCCEEDED(hr)) + { + if (This->metadata_blocks[nIndex].options & DECODER_BLOCK_FULL_STREAM) + { + LARGE_INTEGER offset; + offset.QuadPart = This->metadata_blocks[nIndex].offset; + + hr = IWICStream_InitializeFromIStream(stream, This->parent->stream); + + if (SUCCEEDED(hr)) + hr = IWICStream_Seek(stream, offset, STREAM_SEEK_SET, NULL); + } + else + { + ULARGE_INTEGER offset, length; + + offset.QuadPart = This->metadata_blocks[nIndex].offset; + length.QuadPart = This->metadata_blocks[nIndex].length; + + hr = IWICStream_InitializeFromIStreamRegion(stream, This->parent->stream, + offset, length); + } + + if (This->metadata_blocks[nIndex].options & DECODER_BLOCK_READER_CLSID) + { + IWICMetadataReader *reader; + IWICPersistStream *persist; + if (SUCCEEDED(hr)) + { + hr = create_instance(&This->metadata_blocks[nIndex].reader_clsid, + &IID_IWICMetadataReader, (void**)&reader); + } + + if (SUCCEEDED(hr)) + { + hr = IWICMetadataReader_QueryInterface(reader, &IID_IWICPersistStream, (void**)&persist); + + if (SUCCEEDED(hr)) + { + hr = IWICPersistStream_LoadEx(persist, (IStream*)stream, NULL, + This->metadata_blocks[nIndex].options & DECODER_BLOCK_OPTION_MASK); + + IWICPersistStream_Release(persist); + } + + if (SUCCEEDED(hr)) + *ppIMetadataReader = reader; + else + IWICMetadataReader_Release(reader); + } + } + else + { + hr = IWICComponentFactory_CreateMetadataReaderFromContainer(factory, + &This->parent->decoder_info.block_format, NULL, + This->metadata_blocks[nIndex].options & DECODER_BLOCK_OPTION_MASK, + (IStream*)stream, ppIMetadataReader); + } + + IWICStream_Release(stream); + } + + if (factory) IWICComponentFactory_Release(factory); + + if (FAILED(hr)) + *ppIMetadataReader = NULL; + + return S_OK; +} + +static HRESULT WINAPI CommonDecoderFrame_Block_GetEnumerator(IWICMetadataBlockReader *iface, + IEnumUnknown **ppIEnumMetadata) +{ + FIXME("%p,%p\n", iface, ppIEnumMetadata); + return E_NOTIMPL; +} + +static const IWICMetadataBlockReaderVtbl CommonDecoderFrame_BlockVtbl = { + CommonDecoderFrame_Block_QueryInterface, + CommonDecoderFrame_Block_AddRef, + CommonDecoderFrame_Block_Release, + CommonDecoderFrame_Block_GetContainerFormat, + CommonDecoderFrame_Block_GetCount, + CommonDecoderFrame_Block_GetReaderByIndex, + CommonDecoderFrame_Block_GetEnumerator, +}; + +static HRESULT WINAPI CommonDecoder_GetFrame(IWICBitmapDecoder *iface, + UINT index, IWICBitmapFrameDecode **ppIBitmapFrame) +{ + CommonDecoder *This = impl_from_IWICBitmapDecoder(iface); + HRESULT hr=S_OK; + CommonDecoderFrame *result; + + TRACE("(%p,%u,%p)\n", iface, index, ppIBitmapFrame); + + if (!ppIBitmapFrame) + return E_INVALIDARG; + + EnterCriticalSection(&This->lock); + + if (!This->stream || index >= This->file_info.frame_count) + hr = WINCODEC_ERR_FRAMEMISSING; + + if (SUCCEEDED(hr)) + { + result = malloc(sizeof(*result)); + if (!result) + hr = E_OUTOFMEMORY; + } + + if (SUCCEEDED(hr)) + { + result->IWICBitmapFrameDecode_iface.lpVtbl = &CommonDecoderFrameVtbl; + result->IWICMetadataBlockReader_iface.lpVtbl = &CommonDecoderFrame_BlockVtbl; + result->ref = 1; + result->parent = This; + result->frame = index; + result->metadata_initialized = FALSE; + result->metadata_count = 0; + result->metadata_blocks = NULL; + + hr = decoder_get_frame_info(This->decoder, index, &result->decoder_frame); + + if (SUCCEEDED(hr) && This->cache_options == WICDecodeMetadataCacheOnLoad) + hr = CommonDecoderFrame_InitializeMetadata(result); + + if (FAILED(hr)) + free(result); + } + + LeaveCriticalSection(&This->lock); + + if (SUCCEEDED(hr)) + { + TRACE("-> %ux%u, %u-bit pixelformat=%s res=%f,%f colors=%lu contexts=%lu\n", + result->decoder_frame.width, result->decoder_frame.height, + result->decoder_frame.bpp, wine_dbgstr_guid(&result->decoder_frame.pixel_format), + result->decoder_frame.dpix, result->decoder_frame.dpiy, + result->decoder_frame.num_colors, result->decoder_frame.num_color_contexts); + IWICBitmapDecoder_AddRef(&This->IWICBitmapDecoder_iface); + *ppIBitmapFrame = &result->IWICBitmapFrameDecode_iface; + } + else + { + *ppIBitmapFrame = NULL; + } + + return hr; +} + +HRESULT CommonDecoder_CreateInstance(struct decoder *decoder, + const struct decoder_info *decoder_info, REFIID iid, void** ppv) +{ + CommonDecoder *This; + HRESULT hr; + + TRACE("(%s,%s,%p)\n", debugstr_guid(&decoder_info->clsid), debugstr_guid(iid), ppv); + + This = malloc(sizeof(*This)); + if (!This) + { + decoder_destroy(decoder); + return E_OUTOFMEMORY; + } + + This->IWICBitmapDecoder_iface.lpVtbl = &CommonDecoder_Vtbl; + This->ref = 1; + This->stream = NULL; + This->decoder = decoder; + This->decoder_info = *decoder_info; +#ifdef __REACTOS__ + InitializeCriticalSection(&This->lock); +#else + InitializeCriticalSectionEx(&This->lock, 0, RTL_CRITICAL_SECTION_FLAG_FORCE_DEBUG_INFO); +#endif + This->lock.DebugInfo->Spare[0] = (DWORD_PTR)(__FILE__ ": CommonDecoder.lock"); + + hr = IWICBitmapDecoder_QueryInterface(&This->IWICBitmapDecoder_iface, iid, ppv); + IWICBitmapDecoder_Release(&This->IWICBitmapDecoder_iface); + + return hr; +} diff --git a/dll/win32/windowscodecs/encoder.c b/dll/win32/windowscodecs/encoder.c new file mode 100644 index 00000000000..b2be1f12e1c --- /dev/null +++ b/dll/win32/windowscodecs/encoder.c @@ -0,0 +1,903 @@ +/* + * Copyright 2020 Esme Povirk + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA + */ + +#include <stdarg.h> + +#define COBJMACROS + +#include "windef.h" +#include "winbase.h" +#include "objbase.h" + +#include "wincodecs_private.h" + +#include "wine/debug.h" + +WINE_DEFAULT_DEBUG_CHANNEL(wincodecs); + +static const PROPBAG2 encoder_option_properties[ENCODER_OPTION_END] = { + { PROPBAG2_TYPE_DATA, VT_BOOL, 0, 0, (LPOLESTR)L"InterlaceOption" }, + { PROPBAG2_TYPE_DATA, VT_UI1, 0, 0, (LPOLESTR)L"FilterOption" }, + { PROPBAG2_TYPE_DATA, VT_UI1, 0, 0, (LPOLESTR)L"TiffCompressionMethod" }, + { PROPBAG2_TYPE_DATA, VT_R4, 0, 0, (LPOLESTR)L"CompressionQuality" }, + { PROPBAG2_TYPE_DATA, VT_R4, 0, 0, (LPOLESTR)L"ImageQuality" }, + { PROPBAG2_TYPE_DATA, VT_UI1, 0, 0, (LPOLESTR)L"BitmapTransform" }, + { PROPBAG2_TYPE_DATA, VT_I4 | VT_ARRAY, 0, 0, (LPOLESTR)L"Luminance" }, + { PROPBAG2_TYPE_DATA, VT_I4 | VT_ARRAY, 0, 0, (LPOLESTR)L"Chrominance" }, + { PROPBAG2_TYPE_DATA, VT_UI1, 0, 0, (LPOLESTR)L"JpegYCrCbSubsampling" }, + { PROPBAG2_TYPE_DATA, VT_BOOL, 0, 0, (LPOLESTR)L"SuppressApp0" } +}; + +typedef struct CommonEncoder { + IWICBitmapEncoder IWICBitmapEncoder_iface; + LONG ref; + CRITICAL_SECTION lock; /* must be held when stream or encoder is accessed */ + IStream *stream; + struct encoder *encoder; + struct encoder_info encoder_info; + UINT frame_count; + BOOL uncommitted_frame; + BOOL committed; +} CommonEncoder; + +typedef struct CommonEncoderFrame { + IWICBitmapFrameEncode IWICBitmapFrameEncode_iface; + IWICMetadataBlockWriter IWICMetadataBlockWriter_iface; + LONG ref; + CommonEncoder *parent; + struct encoder_frame encoder_frame; + BOOL initialized; + BOOL frame_created; + UINT lines_written; + BOOL committed; +} CommonEncoderFrame; + +static inline CommonEncoder *impl_from_IWICBitmapEncoder(IWICBitmapEncoder *iface) +{ + return CONTAINING_RECORD(iface, CommonEncoder, IWICBitmapEncoder_iface); +} + +static inline CommonEncoderFrame *impl_from_IWICBitmapFrameEncode(IWICBitmapFrameEncode *iface) +{ + return CONTAINING_RECORD(iface, CommonEncoderFrame, IWICBitmapFrameEncode_iface); +} + +static inline CommonEncoderFrame *impl_from_IWICMetadataBlockWriter(IWICMetadataBlockWriter *iface) +{ + return CONTAINING_RECORD(iface, CommonEncoderFrame, IWICMetadataBlockWriter_iface); +} + +static HRESULT WINAPI CommonEncoderFrame_QueryInterface(IWICBitmapFrameEncode *iface, REFIID iid, + void **ppv) +{ + CommonEncoderFrame *object = impl_from_IWICBitmapFrameEncode(iface); + TRACE("(%p,%s,%p)\n", iface, debugstr_guid(iid), ppv); + + if (!ppv) return E_INVALIDARG; + + if (IsEqualIID(&IID_IUnknown, iid) || + IsEqualIID(&IID_IWICBitmapFrameEncode, iid)) + { + *ppv = &object->IWICBitmapFrameEncode_iface; + } + else if (object->parent->encoder_info.flags & ENCODER_FLAGS_SUPPORTS_METADATA + && IsEqualIID(&IID_IWICMetadataBlockWriter, iid)) + { + *ppv = &object->IWICMetadataBlockWriter_iface; + } + else + { + *ppv = NULL; + return E_NOINTERFACE; + } + + IUnknown_AddRef((IUnknown*)*ppv); + return S_OK; +} + +static ULONG WINAPI CommonEncoderFrame_AddRef(IWICBitmapFrameEncode *iface) +{ + CommonEncoderFrame *This = impl_from_IWICBitmapFrameEncode(iface); + ULONG ref = InterlockedIncrement(&This->ref); + + TRACE("(%p) refcount=%lu\n", iface, ref); + + return ref; +} + +static ULONG WINAPI CommonEncoderFrame_Release(IWICBitmapFrameEncode *iface) +{ + CommonEncoderFrame *This = impl_from_IWICBitmapFrameEncode(iface); + ULONG ref = InterlockedDecrement(&This->ref); + + TRACE("(%p) refcount=%lu\n", iface, ref); + + if (ref == 0) + { + IWICBitmapEncoder_Release(&This->parent->IWICBitmapEncoder_iface); + free(This); + } + + return ref; +} + +static HRESULT WINAPI CommonEncoderFrame_Initialize(IWICBitmapFrameEncode *iface, + IPropertyBag2 *pIEncoderOptions) +{ + CommonEncoderFrame *This = impl_from_IWICBitmapFrameEncode(iface); + HRESULT hr=S_OK; + struct encoder_frame options = {{0}}; + PROPBAG2 opts[7]= {{0}}; + VARIANT opt_values[7]; + HRESULT opt_hres[7]; + DWORD num_opts, i; + + TRACE("(%p,%p)\n", iface, pIEncoderOptions); + + if (pIEncoderOptions) + { + for (i=0; This->parent->encoder_info.encoder_options[i] != ENCODER_OPTION_END; i++) + opts[i] = encoder_option_properties[This->parent->encoder_info.encoder_options[i]]; + num_opts = i; + + hr = IPropertyBag2_Read(pIEncoderOptions, num_opts, opts, NULL, opt_values, opt_hres); + + if (FAILED(hr)) + return hr; + + for (i=0; This->parent->encoder_info.encoder_options[i] != ENCODER_OPTION_END; i++) + { + VARIANT *val = &opt_values[i]; + + switch (This->parent->encoder_info.encoder_options[i]) + { + case ENCODER_OPTION_INTERLACE: + if (V_VT(val) == VT_EMPTY) + options.interlace = FALSE; + else + options.interlace = (V_BOOL(val) != 0); + break; + case ENCODER_OPTION_FILTER: + options.filter = V_UI1(val); + if (options.filter > WICPngFilterAdaptive) + { + WARN("Unrecognized filter option value %lu.\n", options.filter); + options.filter = WICPngFilterUnspecified; + } + break; + default: + break; + } + } + } + else + { + options.interlace = FALSE; + options.filter = WICPngFilterUnspecified; + } + + EnterCriticalSection(&This->parent->lock); + + if (This->initialized) + hr = WINCODEC_ERR_WRONGSTATE; + else + { + This->encoder_frame = options; + This->initialized = TRUE; + } + + LeaveCriticalSection(&This->parent->lock); + + return hr; +} + +static HRESULT WINAPI CommonEncoderFrame_SetSize(IWICBitmapFrameEncode *iface, + UINT uiWidth, UINT uiHeight) +{ + CommonEncoderFrame *This = impl_from_IWICBitmapFrameEncode(iface); + HRESULT hr; + + TRACE("(%p,%u,%u)\n", iface, uiWidth, uiHeight); + + EnterCriticalSection(&This->parent->lock); + + if (This->parent->encoder_info.flags & ENCODER_FLAGS_ICNS_SIZE) + { + if (uiWidth != uiHeight) + { + WARN("cannot generate ICNS icon from %dx%d image\n", uiWidth, uiHeight); + hr = E_INVALIDARG; + goto end; + } + + switch (uiWidth) + { + case 16: + case 32: + case 48: + case 128: + case 256: + case 512: + break; + default: + WARN("cannot generate ICNS icon from %dx%d image\n", uiWidth, uiHeight); + hr = E_INVALIDARG; + goto end; + } + } + + if (!This->initialized || This->frame_created) + { + hr = WINCODEC_ERR_WRONGSTATE; + } + else + { + This->encoder_frame.width = uiWidth; + This->encoder_frame.height = uiHeight; + hr = S_OK; + } + +end: + LeaveCriticalSection(&This->parent->lock); + + return hr; +} + +static HRESULT WINAPI CommonEncoderFrame_SetResolution(IWICBitmapFrameEncode *iface, + double dpiX, double dpiY) +{ + CommonEncoderFrame *This = impl_from_IWICBitmapFrameEncode(iface); + HRESULT hr; + + TRACE("(%p,%0.2f,%0.2f)\n", iface, dpiX, dpiY); + + EnterCriticalSection(&This->parent->lock); + + if (!This->initialized || This->frame_created) + { + hr = WINCODEC_ERR_WRONGSTATE; + } + else + { + This->encoder_frame.dpix = dpiX; + This->encoder_frame.dpiy = dpiY; + hr = S_OK; + } + + LeaveCriticalSection(&This->parent->lock); + + return hr; +} + +static HRESULT WINAPI CommonEncoderFrame_SetPixelFormat(IWICBitmapFrameEncode *iface, + WICPixelFormatGUID *pPixelFormat) +{ + CommonEncoderFrame *This = impl_from_IWICBitmapFrameEncode(iface); + HRESULT hr; + GUID pixel_format; + DWORD bpp; + BOOL indexed; + + TRACE("(%p,%s)\n", iface, debugstr_guid(pPixelFormat)); + + EnterCriticalSection(&This->parent->lock); + + if (!This->initialized || This->frame_created) + { + hr = WINCODEC_ERR_WRONGSTATE; + } + else + { + pixel_format = *pPixelFormat; + hr = encoder_get_supported_format(This->parent->encoder, &pixel_format, &bpp, &indexed); + } + + if (SUCCEEDED(hr)) + { + TRACE("<-- %s bpp=%li indexed=%i\n", wine_dbgstr_guid(&pixel_format), bpp, indexed); + *pPixelFormat = pixel_format; ... 33002 lines suppressed ...
4Â months, 3Â weeks
1
0
0
0
[reactos] 01/02: [LIBJPEG][LIBPNG][LIBTIFF] Add .spec files (#7665)
by Mikhail Tyukin
https://git.reactos.org/?p=reactos.git;a=commitdiff;h=41d1898fcd4ef53780e33…
commit 41d1898fcd4ef53780e33229e21dfee20a7d5de2 Author: Mikhail Tyukin <mishakeys20(a)gmail.com> AuthorDate: Sun Jan 26 12:57:27 2025 -0500 Commit: Hermès Bélusca-Maïto <hermes.belusca-maito(a)reactos.org> CommitDate: Fri Feb 7 16:57:01 2025 +0100 [LIBJPEG][LIBPNG][LIBTIFF] Add .spec files (#7665) --- dll/3rdparty/libjpeg/CMakeLists.txt | 4 +++- dll/3rdparty/libjpeg/libjpeg.spec | 14 +++++++++++++ dll/3rdparty/libpng/CMakeLists.txt | 4 +++- dll/3rdparty/libpng/libpng.spec | 40 +++++++++++++++++++++++++++++++++++++ dll/3rdparty/libtiff/CMakeLists.txt | 4 +++- dll/3rdparty/libtiff/libtiff.spec | 17 ++++++++++++++++ media/doc/3rd Party Files.txt | 3 +++ 7 files changed, 83 insertions(+), 3 deletions(-) diff --git a/dll/3rdparty/libjpeg/CMakeLists.txt b/dll/3rdparty/libjpeg/CMakeLists.txt index fefc3da850c..1b68ac71488 100644 --- a/dll/3rdparty/libjpeg/CMakeLists.txt +++ b/dll/3rdparty/libjpeg/CMakeLists.txt @@ -10,6 +10,8 @@ include_directories( ${REACTOS_SOURCE_DIR}/sdk/include/reactos/libs/libjpeg ${REACTOS_SOURCE_DIR}/sdk/include/reactos/libs/zlib) +spec2def(libjpeg.dll libjpeg.spec ADD_IMPORTLIB) + list(APPEND SOURCE jaricom.c jcapimin.c @@ -59,7 +61,7 @@ list(APPEND SOURCE jmemnobs.c precomp.h) -add_library(libjpeg MODULE ${SOURCE}) +add_library(libjpeg MODULE ${SOURCE} ${CMAKE_CURRENT_BINARY_DIR}/libjpeg.def) set_module_type(libjpeg win32dll) add_importlibs(libjpeg msvcrt kernel32) add_pch(libjpeg precomp.h SOURCE) diff --git a/dll/3rdparty/libjpeg/libjpeg.spec b/dll/3rdparty/libjpeg/libjpeg.spec new file mode 100644 index 00000000000..62eda3cbd0f --- /dev/null +++ b/dll/3rdparty/libjpeg/libjpeg.spec @@ -0,0 +1,14 @@ +@ cdecl jpeg_std_error(ptr) +@ cdecl jpeg_CreateCompress(ptr long) +@ cdecl jpeg_CreateDecompress(ptr long long) +@ cdecl jpeg_destroy_compress(ptr) +@ cdecl jpeg_destroy_decompress(ptr) +@ cdecl jpeg_set_defaults(ptr) +@ cdecl jpeg_start_compress(ptr long) +@ cdecl jpeg_write_scanlines(ptr ptr long) +@ cdecl jpeg_finish_compress(ptr) +@ cdecl jpeg_read_header(ptr long) +@ cdecl jpeg_start_decompress(ptr) +@ cdecl jpeg_read_scanlines(ptr ptr long) +@ cdecl jpeg_finish_decompress(ptr) +@ cdecl jpeg_resync_to_restart(ptr long) diff --git a/dll/3rdparty/libpng/CMakeLists.txt b/dll/3rdparty/libpng/CMakeLists.txt index e7599539562..a5b3849377f 100644 --- a/dll/3rdparty/libpng/CMakeLists.txt +++ b/dll/3rdparty/libpng/CMakeLists.txt @@ -9,6 +9,8 @@ include_directories( ${REACTOS_SOURCE_DIR}/sdk/include/reactos/libs/libpng ${REACTOS_SOURCE_DIR}/sdk/include/reactos/libs/zlib) +spec2def(libpng.dll libpng.spec ADD_IMPORTLIB) + list(APPEND SOURCE png.c pngerror.c @@ -27,7 +29,7 @@ list(APPEND SOURCE pngwutil.c pngpriv.h) -add_library(libpng MODULE ${SOURCE}) +add_library(libpng MODULE ${SOURCE} ${CMAKE_CURRENT_BINARY_DIR}/libpng.def) set_module_type(libpng win32dll) target_link_libraries(libpng zlib) add_importlibs(libpng msvcrt kernel32 ntdll) diff --git a/dll/3rdparty/libpng/libpng.spec b/dll/3rdparty/libpng/libpng.spec new file mode 100644 index 00000000000..b1b008b8ffc --- /dev/null +++ b/dll/3rdparty/libpng/libpng.spec @@ -0,0 +1,40 @@ +@ cdecl png_create_info_struct(ptr) +@ cdecl png_create_read_struct(ptr ptr ptr ptr) +@ cdecl png_create_write_struct(ptr ptr ptr ptr) +@ cdecl png_get_compression_buffer_size(ptr) +@ cdecl png_set_compression_buffer_size(ptr long) +@ cdecl png_set_longjmp_fn(ptr ptr long) +@ cdecl png_destroy_read_struct(ptr ptr ptr) +@ cdecl png_destroy_write_struct(ptr ptr) +@ cdecl png_error(ptr ptr) +@ cdecl png_get_bit_depth(ptr ptr) +@ cdecl png_get_color_type(ptr ptr) +@ cdecl png_get_error_ptr(ptr) +@ cdecl png_get_iCCP(ptr ptr ptr ptr ptr ptr) +@ cdecl png_get_image_height(ptr ptr) +@ cdecl png_get_image_width(ptr ptr) +@ cdecl png_get_io_ptr(ptr) +@ cdecl png_get_pHYs(ptr ptr ptr ptr) +@ cdecl png_get_PLTE(ptr ptr ptr ptr) +@ cdecl png_get_tRNS(ptr ptr ptr ptr ptr) +@ cdecl png_read_image(ptr ptr) +@ cdecl png_read_info(ptr ptr) +@ cdecl png_set_bgr(ptr) +@ cdecl png_set_crc_action(ptr long long) +@ cdecl png_set_filter(ptr long long) +@ cdecl png_set_error_fn(ptr ptr ptr ptr) +@ cdecl png_set_filler(ptr long long) +@ cdecl png_set_gray_to_rgb(ptr) +@ cdecl png_set_IHDR(ptr ptr long long long long long long long) +@ cdecl png_set_interlace_handling(ptr) +@ cdecl png_set_pHYs(ptr ptr ptr long long long) +@ cdecl png_set_PLTE(ptr ptr ptr long) +@ cdecl png_set_read_fn(ptr ptr ptr) +@ cdecl png_set_swap(ptr) +@ cdecl png_set_tRNS(ptr ptr ptr long ptr) +@ cdecl png_set_tRNS_to_alpha(ptr) +@ cdecl png_set_write_fn(ptr ptr ptr ptr) +@ cdecl png_set_chunk_malloc_max(ptr long) +@ cdecl png_write_end(ptr) +@ cdecl png_write_info(ptr ptr) +@ cdecl png_write_rows(ptr ptr long) diff --git a/dll/3rdparty/libtiff/CMakeLists.txt b/dll/3rdparty/libtiff/CMakeLists.txt index 2aff720a340..882d3b3971f 100644 --- a/dll/3rdparty/libtiff/CMakeLists.txt +++ b/dll/3rdparty/libtiff/CMakeLists.txt @@ -9,6 +9,8 @@ include_directories( ${REACTOS_SOURCE_DIR}/sdk/include/reactos/libs/libtiff ${REACTOS_SOURCE_DIR}/sdk/include/reactos/libs/zlib) +spec2def(libtiff.dll libtiff.spec ADD_IMPORTLIB) + list(APPEND SOURCE #mkg3states.c tif_aux.c @@ -54,7 +56,7 @@ list(APPEND SOURCE #tif_zstd.c precomp.h) -add_library(libtiff MODULE ${SOURCE} libtiff.def) +add_library(libtiff MODULE ${SOURCE} ${CMAKE_CURRENT_BINARY_DIR}/libtiff.def) set_module_type(libtiff win32dll) target_link_libraries(libtiff zlib getopt) diff --git a/dll/3rdparty/libtiff/libtiff.spec b/dll/3rdparty/libtiff/libtiff.spec new file mode 100644 index 00000000000..f774b2ac4a1 --- /dev/null +++ b/dll/3rdparty/libtiff/libtiff.spec @@ -0,0 +1,17 @@ +# TODO: add remaining exports +@ cdecl TIFFClose(ptr) +@ cdecl TIFFClientOpen(ptr ptr ptr ptr ptr ptr ptr ptr ptr ptr) +@ cdecl TIFFCurrentDirOffset(ptr) +@ cdecl TIFFGetField(ptr long long long) +@ cdecl TIFFIsByteSwapped(ptr) +@ cdecl TIFFNumberOfDirectories(ptr) +@ cdecl TIFFReadEncodedStrip(ptr) +@ cdecl TIFFReadEncodedTile(ptr long ptr long) +@ cdecl TIFFSetDirectory(ptr long) +@ cdecl TIFFSetErrorHandler(ptr) +@ cdecl TIFFSetErrorHandlerExt(ptr) +@ cdecl TIFFSetWarningHandler(ptr) +@ cdecl TIFFSetWarningHandlerExt(ptr) +@ cdecl TIFFSetField(ptr long long long) +@ cdecl TIFFWriteDirectory(ptr) +@ cdecl TIFFWriteScanline(ptr ptr long long) diff --git a/media/doc/3rd Party Files.txt b/media/doc/3rd Party Files.txt index e8ae9ad70ad..617aac1cc4d 100644 --- a/media/doc/3rd Party Files.txt +++ b/media/doc/3rd Party Files.txt @@ -31,18 +31,21 @@ Path: dll/3rdparty/libjpeg Used Version: 9d License: custom, BSD-like URL:
http://www.ijg.org/
+Modifications: added .spec file Title: libpng Path: dll/3rdparty/libpng Used Version: 1.6.39 License: PNG Reference Library version 2 URL:
http://libpng.sourceforge.net/
+Modifications: added .spec file Title: libtiff Path: dll/3rdparty/libtiff Used Version: 4.1.0 License: libtiff (
https://spdx.org/licenses/libtiff.html
) URL:
http://www.simplesystems.org/libtiff/
+Modifications: added .spec file Title: Libxslt Path: dll/3rdparty/libxslt
4Â months, 3Â weeks
1
0
0
0
[reactos] 01/01: Revert "[USER32][LIBPNG] Support PNG/Vista icons (#7704)"
by Hermès Bélusca-Maïto
https://git.reactos.org/?p=reactos.git;a=commitdiff;h=468a9787d1e39c2034189…
commit 468a9787d1e39c2034189f4fdc4ca9a9ec5aa7bd Author: Hermès Bélusca-Maïto <hermes.belusca-maito(a)reactos.org> AuthorDate: Fri Feb 7 15:20:05 2025 +0100 Commit: Hermès Bélusca-Maïto <hermes.belusca-maito(a)reactos.org> CommitDate: Fri Feb 7 15:20:05 2025 +0100 Revert "[USER32][LIBPNG] Support PNG/Vista icons (#7704)" This reverts commit 7f4708479dd73dad32838b2329bb7215ea897433. - PR was still in review; - Doug has commit access himself. --- dll/3rdparty/libpng/CMakeLists.txt | 5 +- dll/3rdparty/libpng/libpng.spec | 246 --------------------- win32ss/user/user32/CMakeLists.txt | 7 +- win32ss/user/user32/windows/cursoricon.c | 367 +++++-------------------------- 4 files changed, 60 insertions(+), 565 deletions(-) diff --git a/dll/3rdparty/libpng/CMakeLists.txt b/dll/3rdparty/libpng/CMakeLists.txt index 1c304b7b446..e7599539562 100644 --- a/dll/3rdparty/libpng/CMakeLists.txt +++ b/dll/3rdparty/libpng/CMakeLists.txt @@ -27,10 +27,7 @@ list(APPEND SOURCE pngwutil.c pngpriv.h) -spec2def(libpng.dll libpng.spec ADD_IMPORTLIB) - -add_library(libpng MODULE ${SOURCE} ${CMAKE_CURRENT_BINARY_DIR}/libpng.def) - +add_library(libpng MODULE ${SOURCE}) set_module_type(libpng win32dll) target_link_libraries(libpng zlib) add_importlibs(libpng msvcrt kernel32 ntdll) diff --git a/dll/3rdparty/libpng/libpng.spec b/dll/3rdparty/libpng/libpng.spec deleted file mode 100644 index f35705c3e9f..00000000000 --- a/dll/3rdparty/libpng/libpng.spec +++ /dev/null @@ -1,246 +0,0 @@ -@ cdecl png_access_version_number() -@ cdecl png_benign_error(ptr str) -@ cdecl png_build_grayscale_palette(ptr ptr) -@ cdecl png_calloc(ptr long) -@ cdecl png_chunk_benign_error(ptr str) -@ cdecl png_chunk_error(ptr str) -@ cdecl png_chunk_warning(ptr str) -@ cdecl png_convert_from_struct_tm(ptr ptr) -@ cdecl png_convert_from_time_t(ptr long) -@ cdecl png_convert_to_rfc1123(ptr ptr) -@ cdecl png_convert_to_rfc1123_buffer(ptr ptr) -@ cdecl png_create_info_struct(ptr) -@ cdecl png_create_read_struct(ptr ptr ptr ptr) -@ cdecl png_create_read_struct_2(ptr ptr ptr ptr ptr ptr ptr) -@ cdecl png_create_write_struct(ptr ptr ptr ptr) -@ cdecl png_create_write_struct_2(ptr ptr ptr ptr ptr ptr ptr) -@ cdecl png_data_freer(ptr ptr long long) -@ cdecl png_destroy_info_struct(ptr ptr) -@ cdecl png_destroy_read_struct(ptr ptr ptr) -@ cdecl png_destroy_write_struct(ptr ptr ptr) -@ cdecl png_error(ptr str) -@ cdecl png_free(ptr ptr) -@ cdecl png_free_data(ptr ptr long long) -@ cdecl png_free_default(ptr ptr) -@ cdecl png_get_IHDR(ptr ptr ptr ptr ptr ptr ptr ptr ptr) -@ cdecl png_get_PLTE(ptr ptr ptr ptr) -@ cdecl png_get_bKGD(ptr ptr ptr) -@ cdecl png_get_bit_depth(ptr ptr) -@ cdecl png_get_cHRM(ptr ptr ptr ptr ptr ptr ptr ptr ptr ptr) -@ cdecl png_get_cHRM_XYZ(ptr ptr ptr ptr ptr ptr ptr ptr ptr ptr ptr) -@ cdecl png_get_cHRM_XYZ_fixed(ptr ptr ptr ptr ptr ptr ptr ptr ptr ptr ptr) -@ cdecl png_get_cHRM_fixed(ptr ptr ptr ptr ptr ptr ptr ptr ptr ptr ptr) -@ cdecl png_get_channels(ptr ptr) -@ cdecl png_get_chunk_cache_max(ptr) -@ cdecl png_get_chunk_malloc_max(ptr) -@ cdecl png_get_color_type(ptr ptr) -@ cdecl png_get_compression_buffer_size(ptr) -@ cdecl png_get_compression_type(ptr ptr) -@ cdecl png_get_copyright(ptr) -@ cdecl png_get_current_pass_number(ptr) -@ cdecl png_get_current_row_number(ptr) -@ cdecl png_get_eXIf(ptr ptr ptr) -@ cdecl png_get_eXIf_1(ptr ptr ptr ptr) -@ cdecl png_get_error_ptr(ptr) -@ cdecl png_get_filter_type(ptr ptr) -@ cdecl png_get_gAMA(ptr ptr ptr) -@ cdecl png_get_gAMA_fixed(ptr ptr ptr) -@ cdecl png_get_hIST(ptr ptr ptr) -@ cdecl png_get_header_ver(ptr) -@ cdecl png_get_header_version(ptr) -@ cdecl png_get_iCCP(ptr ptr ptr ptr ptr ptr) -@ cdecl png_get_image_height(ptr ptr) -@ cdecl png_get_image_width(ptr ptr) -@ cdecl png_get_int_32(ptr) -@ cdecl png_get_interlace_type(ptr ptr) -@ cdecl png_get_io_chunk_type(ptr) -@ cdecl png_get_io_ptr(ptr) -@ cdecl png_get_io_state(ptr) -@ cdecl png_get_libpng_ver(ptr) -@ cdecl png_get_mem_ptr(ptr) -@ cdecl png_get_oFFs(ptr ptr ptr ptr ptr) -@ cdecl png_get_pCAL(ptr ptr ptr ptr ptr ptr ptr ptr ptr) -@ cdecl png_get_pHYs(ptr ptr ptr ptr ptr) -@ cdecl png_get_pHYs_dpi(ptr ptr ptr ptr ptr) -@ cdecl png_get_palette_max(ptr ptr) -@ cdecl png_get_pixel_aspect_ratio(ptr ptr) -@ cdecl png_get_pixel_aspect_ratio_fixed(ptr ptr) -@ cdecl png_get_pixels_per_inch(ptr ptr) -@ cdecl png_get_pixels_per_meter(ptr ptr) -@ cdecl png_get_progressive_ptr(ptr) -@ cdecl png_get_rgb_to_gray_status(ptr) -@ cdecl png_get_rowbytes(ptr ptr) -@ cdecl png_get_rows(ptr ptr) -@ cdecl png_get_sBIT(ptr ptr ptr) -@ cdecl png_get_sCAL(ptr ptr ptr ptr ptr) -@ cdecl png_get_sCAL_fixed(ptr ptr ptr ptr ptr) -@ cdecl png_get_sCAL_s(ptr ptr ptr ptr ptr) -@ cdecl png_get_sPLT(ptr ptr ptr) -@ cdecl png_get_sRGB(ptr ptr ptr) -@ cdecl png_get_signature(ptr ptr) -@ cdecl png_get_tIME(ptr ptr ptr) -@ cdecl png_get_tRNS(ptr ptr ptr ptr ptr) -@ cdecl png_get_text(ptr ptr ptr ptr) -@ cdecl png_get_uint_16(ptr) -@ cdecl png_get_uint_31(ptr ptr) -@ cdecl png_get_uint_32(ptr) -@ cdecl png_get_unknown_chunks(ptr ptr ptr) -@ cdecl png_get_user_chunk_ptr(ptr) -@ cdecl png_get_user_height_max(ptr) -@ cdecl png_get_user_transform_ptr(ptr) -@ cdecl png_get_user_width_max(ptr) -@ cdecl png_get_valid(ptr ptr long) -@ cdecl png_get_x_offset_inches(ptr ptr) -@ cdecl png_get_x_offset_inches_fixed(ptr ptr ptr ptr ptr) -@ cdecl png_get_x_offset_microns(ptr ptr) -@ cdecl png_get_x_offset_pixels(ptr ptr) -@ cdecl png_get_x_pixels_per_inch(ptr ptr) -@ cdecl png_get_x_pixels_per_meter(ptr ptr) -@ cdecl png_get_y_offset_inches(ptr ptr) -@ cdecl png_get_y_offset_inches_fixed(ptr ptr) -@ cdecl png_get_y_offset_microns(ptr ptr) -@ cdecl png_get_y_offset_pixels(ptr ptr) -@ cdecl png_get_y_pixels_per_inch(ptr ptr) -@ cdecl png_get_y_pixels_per_meter(ptr ptr) -@ cdecl png_handle_as_unknown(ptr str) -@ cdecl png_image_begin_read_from_file(ptr str) -@ cdecl png_image_begin_read_from_memory(ptr ptr long) -@ cdecl png_image_begin_read_from_stdio(ptr ptr) -@ cdecl png_image_finish_read(ptr ptr ptr long ptr) -@ cdecl png_image_free(ptr) -@ cdecl png_image_write_to_file(ptr str long ptr long ptr) -@ cdecl png_image_write_to_memory(ptr ptr ptr long ptr long ptr) -@ cdecl png_image_write_to_stdio(ptr ptr long ptr long ptr) -@ cdecl png_info_init_3(ptr long) -@ cdecl png_init_io(ptr ptr) -@ cdecl png_longjmp(ptr long) -@ cdecl png_malloc(ptr long) -@ cdecl png_malloc_default(ptr long) -@ cdecl png_malloc_warn(ptr long) -@ cdecl png_permit_mng_features(ptr long) -@ cdecl png_process_data(ptr ptr ptr long) -@ cdecl png_process_data_pause(ptr long) -@ cdecl png_process_data_skip(ptr) -@ cdecl png_progressive_combine_row(ptr ptr ptr) -@ cdecl png_read_end(ptr ptr) -@ cdecl png_read_image(ptr ptr) -@ cdecl png_read_info(ptr ptr) -@ cdecl png_read_png(ptr ptr ptr ptr) -@ cdecl png_read_row(ptr ptr ptr) -@ cdecl png_read_rows(ptr ptr ptr long) -@ cdecl png_read_update_info(ptr ptr) -@ cdecl png_reset_zstream(ptr) -@ cdecl png_save_int_32(ptr long) -@ cdecl png_save_uint_16(ptr long) -@ cdecl png_save_uint_32(ptr long) -@ cdecl png_set_IHDR(ptr ptr long long long long long long long) -@ cdecl png_set_PLTE(ptr ptr ptr long) -@ cdecl png_set_add_alpha(ptr long long) -@ cdecl png_set_alpha_mode(ptr long double) -@ cdecl png_set_alpha_mode_fixed(ptr long long) -@ cdecl png_set_bKGD(ptr ptr ptr) -@ cdecl png_set_background(ptr ptr long long double) -@ cdecl png_set_background_fixed(ptr ptr long long long) -@ cdecl png_set_benign_errors(ptr long) -@ cdecl png_set_bgr(ptr) -@ cdecl png_set_cHRM(ptr ptr double double double double double double double double) -@ cdecl png_set_cHRM_XYZ(ptr ptr double double double double double double double double double double) -@ cdecl png_set_cHRM_XYZ_fixed(ptr ptr long long long long long long long long long) -@ cdecl png_set_cHRM_fixed(ptr ptr long long long long long long long long) -@ cdecl png_set_check_for_invalid_index(ptr long) -@ cdecl png_set_chunk_cache_max(ptr long) -@ cdecl png_set_chunk_malloc_max(ptr long) -@ cdecl png_set_compression_buffer_size(ptr long) -@ cdecl png_set_compression_level(ptr long) -@ cdecl png_set_compression_mem_level(ptr long) -@ cdecl png_set_compression_method(ptr long) -@ cdecl png_set_compression_strategy(ptr long) -@ cdecl png_set_compression_window_bits(ptr long) -@ cdecl png_set_crc_action(ptr long long) -@ cdecl png_set_eXIf(ptr ptr ptr) -@ cdecl png_set_eXIf_1(ptr ptr long ptr) -@ cdecl png_set_error_fn(ptr ptr ptr ptr) -@ cdecl png_set_expand(ptr) -@ cdecl png_set_expand_16(ptr) -@ cdecl png_set_expand_gray_1_2_4_to_8(ptr) -@ cdecl png_set_filler(ptr long long) -@ cdecl png_set_filter(ptr long long) -@ cdecl png_set_filter_heuristics(ptr long long ptr ptr) -@ cdecl png_set_filter_heuristics_fixed(ptr long long ptr ptr) -@ cdecl png_set_flush(ptr long) -@ cdecl png_set_gAMA(ptr ptr double) -@ cdecl png_set_gAMA_fixed(ptr ptr long) -@ cdecl png_set_gamma(ptr long long) -@ cdecl png_set_gamma_fixed(ptr long long) -@ cdecl png_set_gray_to_rgb(ptr) -@ cdecl png_set_hIST(ptr ptr ptr) -@ cdecl png_set_iCCP(ptr ptr str long ptr long) -@ cdecl png_set_interlace_handling(ptr) -@ cdecl png_set_invalid(ptr ptr long) -@ cdecl png_set_invert_alpha(ptr) -@ cdecl png_set_invert_mono(ptr) -@ cdecl png_set_keep_unknown_chunks(ptr long str long) -@ cdecl png_set_longjmp_fn(ptr ptr long) -@ cdecl png_set_mem_fn(ptr ptr ptr ptr) -@ cdecl png_set_oFFs(ptr ptr long long long) -@ cdecl png_set_option(ptr long long) -@ cdecl png_set_pCAL(ptr ptr str long long long long str ptr) -@ cdecl png_set_pHYs(ptr ptr long long long) -@ cdecl png_set_packing(ptr) -@ cdecl png_set_packswap(ptr) -@ cdecl png_set_palette_to_rgb(ptr) -@ cdecl png_set_progressive_read_fn(ptr ptr ptr ptr ptr) -@ cdecl png_set_quantize(ptr ptr long long ptr long) -@ cdecl png_set_read_fn(ptr ptr ptr) -@ cdecl png_set_read_status_fn(ptr ptr) -@ cdecl png_set_read_user_chunk_fn(ptr ptr ptr) -@ cdecl png_set_read_user_transform_fn(ptr ptr) -@ cdecl png_set_rgb_to_gray(ptr long double double) -@ cdecl png_set_rgb_to_gray_fixed(ptr long long long) -@ cdecl png_set_rows(ptr ptr ptr) -@ cdecl png_set_sBIT(ptr ptr ptr) -@ cdecl png_set_sCAL(ptr ptr long double double) -@ cdecl png_set_sCAL_fixed(ptr ptr long long long) -@ cdecl png_set_sCAL_s(ptr ptr long str str) -@ cdecl png_set_sPLT(ptr ptr ptr long) -@ cdecl png_set_sRGB(ptr ptr long) -@ cdecl png_set_sRGB_gAMA_and_cHRM(ptr ptr long) -@ cdecl png_set_scale_16(ptr) -@ cdecl png_set_shift(ptr ptr) -@ cdecl png_set_sig_bytes(ptr long) -@ cdecl png_set_strip_16(ptr) -@ cdecl png_set_strip_alpha(ptr) -@ cdecl png_set_swap(ptr) -@ cdecl png_set_swap_alpha(ptr) -@ cdecl png_set_tIME(ptr ptr ptr) -@ cdecl png_set_tRNS(ptr ptr str long ptr) -@ cdecl png_set_tRNS_to_alpha(ptr) -@ cdecl png_set_text(ptr ptr ptr long) -@ cdecl png_set_text_compression_level(ptr long) -@ cdecl png_set_text_compression_mem_level(ptr long) -@ cdecl png_set_text_compression_method(ptr long) -@ cdecl png_set_text_compression_strategy(ptr long) -@ cdecl png_set_text_compression_window_bits(ptr long) -@ cdecl png_set_unknown_chunk_location(ptr ptr long long) -@ cdecl png_set_unknown_chunks(ptr ptr ptr long) -@ cdecl png_set_user_limits(ptr long long) -@ cdecl png_set_user_transform_info(ptr ptr long long) -@ cdecl png_set_write_fn(ptr ptr ptr ptr) -@ cdecl png_set_write_status_fn(ptr ptr) -@ cdecl png_set_write_user_transform_fn(ptr ptr) -@ cdecl png_sig_cmp(ptr long long) -@ cdecl png_start_read_image(ptr) -@ cdecl png_warning(ptr str) -@ cdecl png_write_chunk(ptr ptr ptr long) -@ cdecl png_write_chunk_data(ptr ptr long) -@ cdecl png_write_chunk_end(ptr) -@ cdecl png_write_chunk_start(ptr ptr long) -@ cdecl png_write_end(ptr ptr) -@ cdecl png_write_flush(ptr) -@ cdecl png_write_image(ptr ptr) -@ cdecl png_write_info(ptr ptr) -@ cdecl png_write_info_before_PLTE(ptr ptr) -@ cdecl png_write_png(ptr ptr ptr ptr) -@ cdecl png_write_row(ptr ptr) -@ cdecl png_write_rows(ptr ptr long) -@ cdecl png_write_sig(ptr) diff --git a/win32ss/user/user32/CMakeLists.txt b/win32ss/user/user32/CMakeLists.txt index b7cdfe3aa4d..ca2f2a143e2 100644 --- a/win32ss/user/user32/CMakeLists.txt +++ b/win32ss/user/user32/CMakeLists.txt @@ -5,8 +5,7 @@ include_directories( ${REACTOS_SOURCE_DIR}/sdk/include/reactos/subsys include ${REACTOS_SOURCE_DIR}/sdk/include/reactos/wine - ${REACTOS_SOURCE_DIR}/win32ss/include - ${REACTOS_SOURCE_DIR}/sdk/include/reactos/libs/libpng) + ${REACTOS_SOURCE_DIR}/win32ss/include) list(APPEND SOURCE controls/appswitch.c @@ -89,7 +88,7 @@ if(MSVC AND (ARCH STREQUAL "i386")) target_sources(user32 PRIVATE $<TARGET_OBJECTS:ftol2_sse>) endif() -add_delay_importlibs(user32 usp10 libpng) -add_importlibs(user32 gdi32 advapi32 msvcrt kernel32 ntdll) +add_delay_importlibs(user32 usp10) +add_importlibs(user32 gdi32 advapi32 kernel32 ntdll) add_pch(user32 include/user32.h SOURCE) add_cd_file(TARGET user32 DESTINATION reactos/system32 FOR all) diff --git a/win32ss/user/user32/windows/cursoricon.c b/win32ss/user/user32/windows/cursoricon.c index f06a1b9d540..b1d8bc7e69a 100644 --- a/win32ss/user/user32/windows/cursoricon.c +++ b/win32ss/user/user32/windows/cursoricon.c @@ -1,244 +1,17 @@ /* - * PROJECT: ReactOS user32.dll - * LICENSE: GPL-2.0-or-later (
https://spdx.org/licenses/GPL-2.0-or-later
) - * PURPOSE: cursor and icons implementation - * COPYRIGHT: Copyright Jérôme Gardou (jerome.gardou(a)reactos.org) - * Copyright 2022-2025 Doug Lyons (douglyons(a)douglyons.com) - * Copyright 2025 Katayama Hirofumi MZ (katayama.hirofumi.mz(a)gmail.com) + * PROJECT: ReactOS user32.dll + * COPYRIGHT: GPL - See COPYING in the top level directory + * FILE: win32ss/user/user32/windows/cursoricon.c + * PURPOSE: cursor and icons implementation + * PROGRAMMER: Jérôme Gardou (jerome.gardou(a)reactos.org) */ #include <user32.h> -#include "png.h" WINE_DEFAULT_DEBUG_CHANNEL(cursor); WINE_DECLARE_DEBUG_CHANNEL(icon); //WINE_DECLARE_DEBUG_CHANNEL(resource); -#include <pshpack1.h> -typedef struct { - BYTE bWidth; - BYTE bHeight; - BYTE bColorCount; - BYTE bReserved; - union - { - WORD wPlanes; /* For icons */ - WORD xHotspot; /* For cursors */ - }; - union - { - WORD wBitCount; /* For icons */ - WORD yHotspot; /* For cursors */ - }; - DWORD dwDIBSize; - DWORD dwDIBOffset; -} CURSORICONFILEDIRENTRY; - -typedef struct -{ - WORD idReserved; - WORD idType; - WORD idCount; - CURSORICONFILEDIRENTRY idEntries[1]; -} CURSORICONFILEDIR; -#include <poppack.h> - -#define PNG_CHECK_SIG_SIZE 8 /* Check signature size */ - -/* libpng helpers */ -typedef struct { - png_bytep buffer; - size_t bufSize; - size_t currentPos; -} PNG_READER_STATE; - -/* This function will be used for reading png data from memory */ -static VOID -ReadMemoryPng( - _Inout_ png_structp png_ptr, - _Out_ png_bytep data, - _In_ size_t length) -{ - PNG_READER_STATE *state = png_get_io_ptr(png_ptr); - if ((state->currentPos + length) > state->bufSize) - { - ERR("png read error\n"); - png_error(png_ptr, "read error in ReadMemoryPng"); - return; - } - RtlCopyMemory(data, state->buffer + state->currentPos, length); - state->currentPos += length; -} - -static int get_dib_image_size(int width, int height, int depth); - -/* Convert PNG raw data to BMP icon data */ -static LPBYTE -CURSORICON_ConvertPngToBmpIcon( - _In_ LPBYTE pngBits, - _In_ DWORD fileSize, - _Out_ PDWORD pBmpIconSize) -{ - if (!pngBits || fileSize < PNG_CHECK_SIG_SIZE || !png_check_sig(pngBits, PNG_CHECK_SIG_SIZE)) - return NULL; - - TRACE("pngBits %p fileSize %d\n", pngBits, fileSize); - - png_structp png_ptr = png_create_read_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL); - if (!png_ptr) - { - ERR("png_create_read_struct error\n"); - return NULL; - } - - png_infop info_ptr = png_create_info_struct(png_ptr); - if (!info_ptr) - { - ERR("png_create_info_struct error\n"); - png_destroy_read_struct(&png_ptr, NULL, NULL); - return NULL; - } - - /* Set our own read_function */ - PNG_READER_STATE readerState = { pngBits, fileSize, PNG_CHECK_SIG_SIZE }; - png_set_read_fn(png_ptr, &readerState, ReadMemoryPng); - png_set_sig_bytes(png_ptr, PNG_CHECK_SIG_SIZE); - - /* Read png info */ - png_read_info(png_ptr, info_ptr); - - /* Add translation of some PNG formats and update info */ - int colorType = png_get_color_type(png_ptr, info_ptr); - if (colorType == PNG_COLOR_TYPE_PALETTE) - png_set_palette_to_rgb(png_ptr); - else if (colorType == PNG_COLOR_TYPE_GRAY || colorType == PNG_COLOR_TYPE_GRAY_ALPHA) - png_set_gray_to_rgb(png_ptr); - png_set_scale_16(png_ptr); /* Convert 16-bit channels to 8-bit */ - png_read_update_info(png_ptr, info_ptr); - - /* Get updated png info */ - png_uint_32 width, height; - int bitDepth; - png_get_IHDR(png_ptr, info_ptr, &width, &height, &bitDepth, &colorType, NULL, NULL, NULL); - TRACE("width %d, height %d, bitDepth %d, colorType %d\n", - width, height, bitDepth, colorType); - - int channels = png_get_channels(png_ptr, info_ptr); - int rowbytes = png_get_rowbytes(png_ptr, info_ptr); - int imageSize = height * rowbytes; - TRACE("rowbytes %d, channels %d, imageSize %d\n", rowbytes, channels, imageSize); - - /* Allocate rows data */ - png_bytepp rows = png_malloc(png_ptr, sizeof(png_bytep) * height); - if (!rows) - { - ERR("png_malloc failed\n"); - png_destroy_read_struct(&png_ptr, &info_ptr, NULL); - return NULL; - } - - for (int i = 0; i < (int)height; i++) - { - rows[i] = png_malloc(png_ptr, rowbytes); - if (!rows[i]) - { - ERR("png_malloc failed\n"); - - /* Clean up */ - while (--i >= 0) - png_free(png_ptr, rows[i]); - png_free(png_ptr, rows); - png_destroy_read_struct(&png_ptr, &info_ptr, NULL); - - return NULL; - } - } - - /* Read png image data */ - png_set_rows(png_ptr, info_ptr, rows); - png_read_image(png_ptr, rows); - png_read_end(png_ptr, info_ptr); - - /* After reading the image, you can deal with row pointers */ - LPBYTE imageBytes = HeapAlloc(GetProcessHeap(), 0, imageSize); - if (imageBytes) - { - LPBYTE pb = imageBytes; - for (int i = height - 1; i >= 0; i--) - { - png_bytep row = rows[i]; - for (int j = 0; j < channels * width; j += channels) - { - *pb++ = row[j + 2]; /* Red */ - *pb++ = row[j + 1]; /* Green */ - *pb++ = row[j + 0]; /* Blue */ - if (channels == 4) - *pb++ = row[j + 3]; /* Alpha */ - } - pb += (channels * width) % 4; - } - } - - /* Clean up */ - for (int i = 0; i < (int)height; i++) - png_free(png_ptr, rows[i]); - png_free(png_ptr, rows); - png_destroy_read_struct(&png_ptr, &info_ptr, NULL); - - if (!imageBytes) - { - ERR("HeapAlloc failed\n"); - return NULL; - } - - /* BPP (Bits Per Pixel) */ - WORD bpp = (WORD)(bitDepth * channels); - - /* The byte size of mask bits */ - DWORD maskSize = get_dib_image_size(width, height, 1); - - /* Build BITMAPINFOHEADER */ - BITMAPINFOHEADER info = { sizeof(info) }; - info.biWidth = width; - info.biHeight = 2 * height; - info.biPlanes = 1; - info.biBitCount = bpp; - info.biCompression = BI_RGB; - - /* Build CURSORICONFILEDIR */ - CURSORICONFILEDIR cifd = { 0, 1, 1 }; - cifd.idEntries[0].bWidth = (BYTE)width; - cifd.idEntries[0].bHeight = (BYTE)height; - cifd.idEntries[0].bColorCount = 0; /* No color pallete */ - cifd.idEntries[0].wPlanes = 1; /* Must be 1 */ - cifd.idEntries[0].wBitCount = bpp; - cifd.idEntries[0].dwDIBSize = (DWORD)(sizeof(info) + imageSize + maskSize); - cifd.idEntries[0].dwDIBOffset = (DWORD)sizeof(cifd); - - /* Allocate BMP icon data */ - *pBmpIconSize = (DWORD)(sizeof(cifd) + sizeof(info) + imageSize + maskSize); - LPBYTE pbBmpIcon = HeapAlloc(GetProcessHeap(), 0, *pBmpIconSize); - if (!pbBmpIcon) - { - ERR("HeapAlloc failed\n"); - HeapFree(GetProcessHeap(), 0, imageBytes); - return NULL; - } - - /* Store data to pbBmpIcon */ - LPBYTE pb = pbBmpIcon; - RtlCopyMemory(pb, &cifd, sizeof(cifd)); - pb += sizeof(cifd); - RtlCopyMemory(pb, &info, sizeof(info)); - pb += sizeof(info); - RtlCopyMemory(pb, imageBytes, imageSize); - pb += imageSize; - RtlFillMemory(pb, maskSize, 0xFF); /* Mask bits for AND operation */ - - HeapFree(GetProcessHeap(), 0, imageBytes); - return pbBmpIcon; -} - /* We only use Wide string functions */ #undef MAKEINTRESOURCE #define MAKEINTRESOURCE MAKEINTRESOURCEW @@ -448,7 +221,7 @@ static int DIB_GetBitmapInfo( const BITMAPINFOHEADER *header, LONG *width, } if (memcmp(&header->biSize, png_sig_pattern, sizeof(png_sig_pattern)) == 0) { - TRACE("We have a PNG icon\n"); + ERR("Cannot yet display PNG icons\n"); /* for PNG format details see
https://en.wikipedia.org/wiki/PNG
*/ } else @@ -696,6 +469,29 @@ done: return alpha; } +#include "pshpack1.h" + +typedef struct { + BYTE bWidth; + BYTE bHeight; + BYTE bColorCount; + BYTE bReserved; + WORD xHotspot; + WORD yHotspot; + DWORD dwDIBSize; + DWORD dwDIBOffset; +} CURSORICONFILEDIRENTRY; + +typedef struct +{ + WORD idReserved; + WORD idType; + WORD idCount; + CURSORICONFILEDIRENTRY idEntries[1]; +} CURSORICONFILEDIR; + +#include "poppack.h" + const CURSORICONFILEDIRENTRY* get_best_icon_file_entry( _In_ const CURSORICONFILEDIR* dir, @@ -1359,14 +1155,6 @@ BITMAP_LoadImageW( ResSize = SizeofResource(hinst, hrsrc); } - if (pbmi->bmiHeader.biCompression == BI_BITFIELDS && pbmi->bmiHeader.biBitCount == 32) - { - SIZE_T totalSize = pbmi->bmiHeader.biSize + (3 * sizeof(DWORD)) + - pbmi->bmiHeader.biSizeImage; - if (pbmi->bmiHeader.biSizeImage != 0 && totalSize != ResSize) - WARN("Possibly bad resource size provided\n"); - } - /* Fix up values */ if(DIB_GetBitmapInfo(&pbmi->bmiHeader, &width, &height, &bpp, &compr) == -1) goto end; @@ -1597,8 +1385,8 @@ CURSORICON_LoadFromFileW( { const CURSORICONFILEDIRENTRY *entry; const CURSORICONFILEDIR *dir; - DWORD filesize = 0, BmpIconSize; - LPBYTE bits, pbBmpIcon = NULL; + DWORD filesize = 0; + LPBYTE bits; HANDLE hCurIcon = NULL; CURSORDATA cursorData; @@ -1630,37 +1418,15 @@ CURSORICON_LoadFromFileW( cursorData.xHotspot = entry->xHotspot; cursorData.yHotspot = entry->yHotspot; } - cursorData.rt = LOWORD(bIcon ? RT_ICON : RT_CURSOR); - - /* Try to load BMP icon */ - DWORD dwOffset = entry->dwDIBOffset; - if (!CURSORICON_GetCursorDataFromBMI(&cursorData, (BITMAPINFO *)(&bits[dwOffset]))) - { - /* Convert PNG raw data to BMP icon if the icon was PNG icon */ - LPBYTE pngBits = &bits[entry->dwDIBOffset]; - pbBmpIcon = CURSORICON_ConvertPngToBmpIcon(pngBits, filesize, &BmpIconSize); - if (!pbBmpIcon) - goto end; /* Not PNG icon or failed */ - - /* Find icon entry from BMP icon */ - dir = (CURSORICONFILEDIR *)pbBmpIcon; - entry = &dir->idEntries[0]; /* Only one entry */ - - /* A bit of preparation */ - RtlZeroMemory(&cursorData, sizeof(cursorData)); - cursorData.rt = LOWORD(bIcon ? RT_ICON : RT_CURSOR); + cursorData.rt = (USHORT)((ULONG_PTR)(bIcon ? RT_ICON : RT_CURSOR)); - /* Can we load this BMP icon? */ - dwOffset = entry->dwDIBOffset; - if (!CURSORICON_GetCursorDataFromBMI(&cursorData, (BITMAPINFO *)(&pbBmpIcon[dwOffset]))) + /* Do the dance */ + if(!CURSORICON_GetCursorDataFromBMI(&cursorData, (BITMAPINFO*)(&bits[entry->dwDIBOffset]))) { - ERR("Failing file: '%S'.\n", lpszName); + ERR("Failing File is \n '%S'.\n", lpszName); goto end; } - TRACE("Processing PNG/Vista icon: '%S'\n", lpszName); - } - hCurIcon = NtUserxCreateEmptyCurObject(FALSE); if(!hCurIcon) goto end; @@ -1669,16 +1435,21 @@ CURSORICON_LoadFromFileW( if(!NtUserSetCursorIconData(hCurIcon, NULL, NULL, &cursorData)) { NtUserDestroyCursor(hCurIcon, TRUE); - hCurIcon = NULL; - if (cursorData.hbmMask) DeleteObject(cursorData.hbmMask); - if (cursorData.hbmColor) DeleteObject(cursorData.hbmColor); - if (cursorData.hbmAlpha) DeleteObject(cursorData.hbmAlpha); + goto end_error; } end: UnmapViewOfFile(bits); - HeapFree(GetProcessHeap(), 0, pbBmpIcon); return hCurIcon; + + /* Clean up */ +end_error: + DeleteObject(cursorData.hbmMask); + if(cursorData.hbmColor) DeleteObject(cursorData.hbmColor); + if(cursorData.hbmAlpha) DeleteObject(cursorData.hbmAlpha); + UnmapViewOfFile(bits); + + return NULL; } static @@ -1743,7 +1514,7 @@ CURSORICON_LoadImageW( SetLastError(ERROR_NOT_ENOUGH_MEMORY); return NULL; } - ustrModule.Length = (USHORT)wsprintfW(ustrModule.Buffer, fakeNameFmt, hinst) * sizeof(WCHAR); + ustrModule.Length = wsprintfW(ustrModule.Buffer, fakeNameFmt, hinst) * sizeof(WCHAR); } else if(hinst) { @@ -1774,8 +1545,8 @@ CURSORICON_LoadImageW( } ustrModule.Buffer[ret] = UNICODE_NULL; - ustrModule.Length = (USHORT)(ret * sizeof(WCHAR)); - ustrModule.MaximumLength = (USHORT)(size * sizeof(WCHAR)); + ustrModule.Length = ret * sizeof(WCHAR); + ustrModule.MaximumLength = size * sizeof(WCHAR); break; } } @@ -2768,17 +2539,9 @@ HICON WINAPI CreateIconFromResourceEx( CURSORDATA cursorData; HICON hIcon; BOOL isAnimated; - LPBYTE pbBmpIcon = NULL; - DWORD BmpIconSize; TRACE("%p, %lu, %lu, %lu, %i, %i, %lu.\n", pbIconBits, cbIconBits, fIcon, dwVersion, cxDesired, cyDesired, uFlags); - if (!pbIconBits || cbIconBits < 2 * sizeof(DWORD)) - { - ERR("Sanity check failed\n"); - return NULL; - } - if(uFlags & LR_DEFAULTSIZE) { if(!cxDesired) cxDesired = GetSystemMetrics(fIcon ? SM_CXICON : SM_CXCURSOR); @@ -2788,7 +2551,7 @@ HICON WINAPI CreateIconFromResourceEx( ZeroMemory(&cursorData, sizeof(cursorData)); cursorData.cx = cxDesired; cursorData.cy = cyDesired; - cursorData.rt = LOWORD(fIcon ? RT_ICON : RT_CURSOR); + cursorData.rt = (USHORT)((ULONG_PTR)(fIcon ? RT_ICON : RT_CURSOR)); /* Convert to win32k-ready data */ if(!memcmp(pbIconBits, "RIFF", 4)) @@ -2859,30 +2622,15 @@ HICON WINAPI CreateIconFromResourceEx( pbIconBits = (PBYTE)pt; } - /* Try to load BMP icon */ - if (!CURSORICON_GetCursorDataFromBMI(&cursorData, (BITMAPINFO *)pbIconBits)) + if (!CURSORICON_GetCursorDataFromBMI(&cursorData, (BITMAPINFO*)pbIconBits)) { - /* Convert PNG raw data to BMP icon if the icon was PNG icon */ - pbBmpIcon = CURSORICON_ConvertPngToBmpIcon(pbIconBits, cbIconBits, &BmpIconSize); - if (!pbBmpIcon) - goto end; /* Not PNG icon or failed */ - - /* Find icon entry from BMP icon */ - CURSORICONFILEDIR *dir = (CURSORICONFILEDIR *)pbBmpIcon; - CURSORICONFILEDIRENTRY *entry = &dir->idEntries[0]; /* Only one entry */ - - /* A bit of preparation */ - RtlZeroMemory(&cursorData, sizeof(cursorData)); - cursorData.rt = LOWORD(fIcon ? RT_ICON : RT_CURSOR); - - /* Can we load this BMP icon? */ - DWORD dwOffset = entry->dwDIBOffset; - if (!CURSORICON_GetCursorDataFromBMI(&cursorData, (BITMAPINFO *)&pbBmpIcon[dwOffset])) - { - ERR("Couldn't get cursor/icon data\n"); - goto end; - } + ERR("Couldn't fill the CURSORDATA structure.\n"); + if (ResHandle) + FreeResource(ResHandle); + return NULL; } + if (ResHandle) + FreeResource(ResHandle); isAnimated = FALSE; } @@ -2903,13 +2651,10 @@ HICON WINAPI CreateIconFromResourceEx( if(isAnimated) HeapFree(GetProcessHeap(), 0, cursorData.aspcur); -end: - HeapFree(GetProcessHeap(), 0, pbBmpIcon); return hIcon; /* Clean up */ end_error: - HeapFree(GetProcessHeap(), 0, pbBmpIcon); if(isAnimated) HeapFree(GetProcessHeap(), 0, cursorData.aspcur); DeleteObject(cursorData.hbmMask);
4Â months, 3Â weeks
1
0
0
0
[reactos] 01/01: [USER32][LIBPNG] Support PNG/Vista icons (#7704)
by Doug Lyons
https://git.reactos.org/?p=reactos.git;a=commitdiff;h=7f4708479dd73dad32838…
commit 7f4708479dd73dad32838b2329bb7215ea897433 Author: Doug Lyons <douglyons(a)douglyons.com> AuthorDate: Fri Feb 7 08:12:32 2025 -0600 Commit: GitHub <noreply(a)github.com> CommitDate: Fri Feb 7 23:12:32 2025 +0900 [USER32][LIBPNG] Support PNG/Vista icons (#7704) Add PNG (NT6/Vista+) support. JIRA issue: CORE-18385 - Change libpng to add IMPORTLIB libpng.spec to allow linking to it in USER32. - Add code into mostly cursoricon.c to support PNG icons. --- dll/3rdparty/libpng/CMakeLists.txt | 5 +- dll/3rdparty/libpng/libpng.spec | 246 +++++++++++++++++++++ win32ss/user/user32/CMakeLists.txt | 7 +- win32ss/user/user32/windows/cursoricon.c | 367 ++++++++++++++++++++++++++----- 4 files changed, 565 insertions(+), 60 deletions(-) diff --git a/dll/3rdparty/libpng/CMakeLists.txt b/dll/3rdparty/libpng/CMakeLists.txt index e7599539562..1c304b7b446 100644 --- a/dll/3rdparty/libpng/CMakeLists.txt +++ b/dll/3rdparty/libpng/CMakeLists.txt @@ -27,7 +27,10 @@ list(APPEND SOURCE pngwutil.c pngpriv.h) -add_library(libpng MODULE ${SOURCE}) +spec2def(libpng.dll libpng.spec ADD_IMPORTLIB) + +add_library(libpng MODULE ${SOURCE} ${CMAKE_CURRENT_BINARY_DIR}/libpng.def) + set_module_type(libpng win32dll) target_link_libraries(libpng zlib) add_importlibs(libpng msvcrt kernel32 ntdll) diff --git a/dll/3rdparty/libpng/libpng.spec b/dll/3rdparty/libpng/libpng.spec new file mode 100644 index 00000000000..f35705c3e9f --- /dev/null +++ b/dll/3rdparty/libpng/libpng.spec @@ -0,0 +1,246 @@ +@ cdecl png_access_version_number() +@ cdecl png_benign_error(ptr str) +@ cdecl png_build_grayscale_palette(ptr ptr) +@ cdecl png_calloc(ptr long) +@ cdecl png_chunk_benign_error(ptr str) +@ cdecl png_chunk_error(ptr str) +@ cdecl png_chunk_warning(ptr str) +@ cdecl png_convert_from_struct_tm(ptr ptr) +@ cdecl png_convert_from_time_t(ptr long) +@ cdecl png_convert_to_rfc1123(ptr ptr) +@ cdecl png_convert_to_rfc1123_buffer(ptr ptr) +@ cdecl png_create_info_struct(ptr) +@ cdecl png_create_read_struct(ptr ptr ptr ptr) +@ cdecl png_create_read_struct_2(ptr ptr ptr ptr ptr ptr ptr) +@ cdecl png_create_write_struct(ptr ptr ptr ptr) +@ cdecl png_create_write_struct_2(ptr ptr ptr ptr ptr ptr ptr) +@ cdecl png_data_freer(ptr ptr long long) +@ cdecl png_destroy_info_struct(ptr ptr) +@ cdecl png_destroy_read_struct(ptr ptr ptr) +@ cdecl png_destroy_write_struct(ptr ptr ptr) +@ cdecl png_error(ptr str) +@ cdecl png_free(ptr ptr) +@ cdecl png_free_data(ptr ptr long long) +@ cdecl png_free_default(ptr ptr) +@ cdecl png_get_IHDR(ptr ptr ptr ptr ptr ptr ptr ptr ptr) +@ cdecl png_get_PLTE(ptr ptr ptr ptr) +@ cdecl png_get_bKGD(ptr ptr ptr) +@ cdecl png_get_bit_depth(ptr ptr) +@ cdecl png_get_cHRM(ptr ptr ptr ptr ptr ptr ptr ptr ptr ptr) +@ cdecl png_get_cHRM_XYZ(ptr ptr ptr ptr ptr ptr ptr ptr ptr ptr ptr) +@ cdecl png_get_cHRM_XYZ_fixed(ptr ptr ptr ptr ptr ptr ptr ptr ptr ptr ptr) +@ cdecl png_get_cHRM_fixed(ptr ptr ptr ptr ptr ptr ptr ptr ptr ptr ptr) +@ cdecl png_get_channels(ptr ptr) +@ cdecl png_get_chunk_cache_max(ptr) +@ cdecl png_get_chunk_malloc_max(ptr) +@ cdecl png_get_color_type(ptr ptr) +@ cdecl png_get_compression_buffer_size(ptr) +@ cdecl png_get_compression_type(ptr ptr) +@ cdecl png_get_copyright(ptr) +@ cdecl png_get_current_pass_number(ptr) +@ cdecl png_get_current_row_number(ptr) +@ cdecl png_get_eXIf(ptr ptr ptr) +@ cdecl png_get_eXIf_1(ptr ptr ptr ptr) +@ cdecl png_get_error_ptr(ptr) +@ cdecl png_get_filter_type(ptr ptr) +@ cdecl png_get_gAMA(ptr ptr ptr) +@ cdecl png_get_gAMA_fixed(ptr ptr ptr) +@ cdecl png_get_hIST(ptr ptr ptr) +@ cdecl png_get_header_ver(ptr) +@ cdecl png_get_header_version(ptr) +@ cdecl png_get_iCCP(ptr ptr ptr ptr ptr ptr) +@ cdecl png_get_image_height(ptr ptr) +@ cdecl png_get_image_width(ptr ptr) +@ cdecl png_get_int_32(ptr) +@ cdecl png_get_interlace_type(ptr ptr) +@ cdecl png_get_io_chunk_type(ptr) +@ cdecl png_get_io_ptr(ptr) +@ cdecl png_get_io_state(ptr) +@ cdecl png_get_libpng_ver(ptr) +@ cdecl png_get_mem_ptr(ptr) +@ cdecl png_get_oFFs(ptr ptr ptr ptr ptr) +@ cdecl png_get_pCAL(ptr ptr ptr ptr ptr ptr ptr ptr ptr) +@ cdecl png_get_pHYs(ptr ptr ptr ptr ptr) +@ cdecl png_get_pHYs_dpi(ptr ptr ptr ptr ptr) +@ cdecl png_get_palette_max(ptr ptr) +@ cdecl png_get_pixel_aspect_ratio(ptr ptr) +@ cdecl png_get_pixel_aspect_ratio_fixed(ptr ptr) +@ cdecl png_get_pixels_per_inch(ptr ptr) +@ cdecl png_get_pixels_per_meter(ptr ptr) +@ cdecl png_get_progressive_ptr(ptr) +@ cdecl png_get_rgb_to_gray_status(ptr) +@ cdecl png_get_rowbytes(ptr ptr) +@ cdecl png_get_rows(ptr ptr) +@ cdecl png_get_sBIT(ptr ptr ptr) +@ cdecl png_get_sCAL(ptr ptr ptr ptr ptr) +@ cdecl png_get_sCAL_fixed(ptr ptr ptr ptr ptr) +@ cdecl png_get_sCAL_s(ptr ptr ptr ptr ptr) +@ cdecl png_get_sPLT(ptr ptr ptr) +@ cdecl png_get_sRGB(ptr ptr ptr) +@ cdecl png_get_signature(ptr ptr) +@ cdecl png_get_tIME(ptr ptr ptr) +@ cdecl png_get_tRNS(ptr ptr ptr ptr ptr) +@ cdecl png_get_text(ptr ptr ptr ptr) +@ cdecl png_get_uint_16(ptr) +@ cdecl png_get_uint_31(ptr ptr) +@ cdecl png_get_uint_32(ptr) +@ cdecl png_get_unknown_chunks(ptr ptr ptr) +@ cdecl png_get_user_chunk_ptr(ptr) +@ cdecl png_get_user_height_max(ptr) +@ cdecl png_get_user_transform_ptr(ptr) +@ cdecl png_get_user_width_max(ptr) +@ cdecl png_get_valid(ptr ptr long) +@ cdecl png_get_x_offset_inches(ptr ptr) +@ cdecl png_get_x_offset_inches_fixed(ptr ptr ptr ptr ptr) +@ cdecl png_get_x_offset_microns(ptr ptr) +@ cdecl png_get_x_offset_pixels(ptr ptr) +@ cdecl png_get_x_pixels_per_inch(ptr ptr) +@ cdecl png_get_x_pixels_per_meter(ptr ptr) +@ cdecl png_get_y_offset_inches(ptr ptr) +@ cdecl png_get_y_offset_inches_fixed(ptr ptr) +@ cdecl png_get_y_offset_microns(ptr ptr) +@ cdecl png_get_y_offset_pixels(ptr ptr) +@ cdecl png_get_y_pixels_per_inch(ptr ptr) +@ cdecl png_get_y_pixels_per_meter(ptr ptr) +@ cdecl png_handle_as_unknown(ptr str) +@ cdecl png_image_begin_read_from_file(ptr str) +@ cdecl png_image_begin_read_from_memory(ptr ptr long) +@ cdecl png_image_begin_read_from_stdio(ptr ptr) +@ cdecl png_image_finish_read(ptr ptr ptr long ptr) +@ cdecl png_image_free(ptr) +@ cdecl png_image_write_to_file(ptr str long ptr long ptr) +@ cdecl png_image_write_to_memory(ptr ptr ptr long ptr long ptr) +@ cdecl png_image_write_to_stdio(ptr ptr long ptr long ptr) +@ cdecl png_info_init_3(ptr long) +@ cdecl png_init_io(ptr ptr) +@ cdecl png_longjmp(ptr long) +@ cdecl png_malloc(ptr long) +@ cdecl png_malloc_default(ptr long) +@ cdecl png_malloc_warn(ptr long) +@ cdecl png_permit_mng_features(ptr long) +@ cdecl png_process_data(ptr ptr ptr long) +@ cdecl png_process_data_pause(ptr long) +@ cdecl png_process_data_skip(ptr) +@ cdecl png_progressive_combine_row(ptr ptr ptr) +@ cdecl png_read_end(ptr ptr) +@ cdecl png_read_image(ptr ptr) +@ cdecl png_read_info(ptr ptr) +@ cdecl png_read_png(ptr ptr ptr ptr) +@ cdecl png_read_row(ptr ptr ptr) +@ cdecl png_read_rows(ptr ptr ptr long) +@ cdecl png_read_update_info(ptr ptr) +@ cdecl png_reset_zstream(ptr) +@ cdecl png_save_int_32(ptr long) +@ cdecl png_save_uint_16(ptr long) +@ cdecl png_save_uint_32(ptr long) +@ cdecl png_set_IHDR(ptr ptr long long long long long long long) +@ cdecl png_set_PLTE(ptr ptr ptr long) +@ cdecl png_set_add_alpha(ptr long long) +@ cdecl png_set_alpha_mode(ptr long double) +@ cdecl png_set_alpha_mode_fixed(ptr long long) +@ cdecl png_set_bKGD(ptr ptr ptr) +@ cdecl png_set_background(ptr ptr long long double) +@ cdecl png_set_background_fixed(ptr ptr long long long) +@ cdecl png_set_benign_errors(ptr long) +@ cdecl png_set_bgr(ptr) +@ cdecl png_set_cHRM(ptr ptr double double double double double double double double) +@ cdecl png_set_cHRM_XYZ(ptr ptr double double double double double double double double double double) +@ cdecl png_set_cHRM_XYZ_fixed(ptr ptr long long long long long long long long long) +@ cdecl png_set_cHRM_fixed(ptr ptr long long long long long long long long) +@ cdecl png_set_check_for_invalid_index(ptr long) +@ cdecl png_set_chunk_cache_max(ptr long) +@ cdecl png_set_chunk_malloc_max(ptr long) +@ cdecl png_set_compression_buffer_size(ptr long) +@ cdecl png_set_compression_level(ptr long) +@ cdecl png_set_compression_mem_level(ptr long) +@ cdecl png_set_compression_method(ptr long) +@ cdecl png_set_compression_strategy(ptr long) +@ cdecl png_set_compression_window_bits(ptr long) +@ cdecl png_set_crc_action(ptr long long) +@ cdecl png_set_eXIf(ptr ptr ptr) +@ cdecl png_set_eXIf_1(ptr ptr long ptr) +@ cdecl png_set_error_fn(ptr ptr ptr ptr) +@ cdecl png_set_expand(ptr) +@ cdecl png_set_expand_16(ptr) +@ cdecl png_set_expand_gray_1_2_4_to_8(ptr) +@ cdecl png_set_filler(ptr long long) +@ cdecl png_set_filter(ptr long long) +@ cdecl png_set_filter_heuristics(ptr long long ptr ptr) +@ cdecl png_set_filter_heuristics_fixed(ptr long long ptr ptr) +@ cdecl png_set_flush(ptr long) +@ cdecl png_set_gAMA(ptr ptr double) +@ cdecl png_set_gAMA_fixed(ptr ptr long) +@ cdecl png_set_gamma(ptr long long) +@ cdecl png_set_gamma_fixed(ptr long long) +@ cdecl png_set_gray_to_rgb(ptr) +@ cdecl png_set_hIST(ptr ptr ptr) +@ cdecl png_set_iCCP(ptr ptr str long ptr long) +@ cdecl png_set_interlace_handling(ptr) +@ cdecl png_set_invalid(ptr ptr long) +@ cdecl png_set_invert_alpha(ptr) +@ cdecl png_set_invert_mono(ptr) +@ cdecl png_set_keep_unknown_chunks(ptr long str long) +@ cdecl png_set_longjmp_fn(ptr ptr long) +@ cdecl png_set_mem_fn(ptr ptr ptr ptr) +@ cdecl png_set_oFFs(ptr ptr long long long) +@ cdecl png_set_option(ptr long long) +@ cdecl png_set_pCAL(ptr ptr str long long long long str ptr) +@ cdecl png_set_pHYs(ptr ptr long long long) +@ cdecl png_set_packing(ptr) +@ cdecl png_set_packswap(ptr) +@ cdecl png_set_palette_to_rgb(ptr) +@ cdecl png_set_progressive_read_fn(ptr ptr ptr ptr ptr) +@ cdecl png_set_quantize(ptr ptr long long ptr long) +@ cdecl png_set_read_fn(ptr ptr ptr) +@ cdecl png_set_read_status_fn(ptr ptr) +@ cdecl png_set_read_user_chunk_fn(ptr ptr ptr) +@ cdecl png_set_read_user_transform_fn(ptr ptr) +@ cdecl png_set_rgb_to_gray(ptr long double double) +@ cdecl png_set_rgb_to_gray_fixed(ptr long long long) +@ cdecl png_set_rows(ptr ptr ptr) +@ cdecl png_set_sBIT(ptr ptr ptr) +@ cdecl png_set_sCAL(ptr ptr long double double) +@ cdecl png_set_sCAL_fixed(ptr ptr long long long) +@ cdecl png_set_sCAL_s(ptr ptr long str str) +@ cdecl png_set_sPLT(ptr ptr ptr long) +@ cdecl png_set_sRGB(ptr ptr long) +@ cdecl png_set_sRGB_gAMA_and_cHRM(ptr ptr long) +@ cdecl png_set_scale_16(ptr) +@ cdecl png_set_shift(ptr ptr) +@ cdecl png_set_sig_bytes(ptr long) +@ cdecl png_set_strip_16(ptr) +@ cdecl png_set_strip_alpha(ptr) +@ cdecl png_set_swap(ptr) +@ cdecl png_set_swap_alpha(ptr) +@ cdecl png_set_tIME(ptr ptr ptr) +@ cdecl png_set_tRNS(ptr ptr str long ptr) +@ cdecl png_set_tRNS_to_alpha(ptr) +@ cdecl png_set_text(ptr ptr ptr long) +@ cdecl png_set_text_compression_level(ptr long) +@ cdecl png_set_text_compression_mem_level(ptr long) +@ cdecl png_set_text_compression_method(ptr long) +@ cdecl png_set_text_compression_strategy(ptr long) +@ cdecl png_set_text_compression_window_bits(ptr long) +@ cdecl png_set_unknown_chunk_location(ptr ptr long long) +@ cdecl png_set_unknown_chunks(ptr ptr ptr long) +@ cdecl png_set_user_limits(ptr long long) +@ cdecl png_set_user_transform_info(ptr ptr long long) +@ cdecl png_set_write_fn(ptr ptr ptr ptr) +@ cdecl png_set_write_status_fn(ptr ptr) +@ cdecl png_set_write_user_transform_fn(ptr ptr) +@ cdecl png_sig_cmp(ptr long long) +@ cdecl png_start_read_image(ptr) +@ cdecl png_warning(ptr str) +@ cdecl png_write_chunk(ptr ptr ptr long) +@ cdecl png_write_chunk_data(ptr ptr long) +@ cdecl png_write_chunk_end(ptr) +@ cdecl png_write_chunk_start(ptr ptr long) +@ cdecl png_write_end(ptr ptr) +@ cdecl png_write_flush(ptr) +@ cdecl png_write_image(ptr ptr) +@ cdecl png_write_info(ptr ptr) +@ cdecl png_write_info_before_PLTE(ptr ptr) +@ cdecl png_write_png(ptr ptr ptr ptr) +@ cdecl png_write_row(ptr ptr) +@ cdecl png_write_rows(ptr ptr long) +@ cdecl png_write_sig(ptr) diff --git a/win32ss/user/user32/CMakeLists.txt b/win32ss/user/user32/CMakeLists.txt index ca2f2a143e2..b7cdfe3aa4d 100644 --- a/win32ss/user/user32/CMakeLists.txt +++ b/win32ss/user/user32/CMakeLists.txt @@ -5,7 +5,8 @@ include_directories( ${REACTOS_SOURCE_DIR}/sdk/include/reactos/subsys include ${REACTOS_SOURCE_DIR}/sdk/include/reactos/wine - ${REACTOS_SOURCE_DIR}/win32ss/include) + ${REACTOS_SOURCE_DIR}/win32ss/include + ${REACTOS_SOURCE_DIR}/sdk/include/reactos/libs/libpng) list(APPEND SOURCE controls/appswitch.c @@ -88,7 +89,7 @@ if(MSVC AND (ARCH STREQUAL "i386")) target_sources(user32 PRIVATE $<TARGET_OBJECTS:ftol2_sse>) endif() -add_delay_importlibs(user32 usp10) -add_importlibs(user32 gdi32 advapi32 kernel32 ntdll) +add_delay_importlibs(user32 usp10 libpng) +add_importlibs(user32 gdi32 advapi32 msvcrt kernel32 ntdll) add_pch(user32 include/user32.h SOURCE) add_cd_file(TARGET user32 DESTINATION reactos/system32 FOR all) diff --git a/win32ss/user/user32/windows/cursoricon.c b/win32ss/user/user32/windows/cursoricon.c index b1d8bc7e69a..f06a1b9d540 100644 --- a/win32ss/user/user32/windows/cursoricon.c +++ b/win32ss/user/user32/windows/cursoricon.c @@ -1,17 +1,244 @@ /* - * PROJECT: ReactOS user32.dll - * COPYRIGHT: GPL - See COPYING in the top level directory - * FILE: win32ss/user/user32/windows/cursoricon.c - * PURPOSE: cursor and icons implementation - * PROGRAMMER: Jérôme Gardou (jerome.gardou(a)reactos.org) + * PROJECT: ReactOS user32.dll + * LICENSE: GPL-2.0-or-later (
https://spdx.org/licenses/GPL-2.0-or-later
) + * PURPOSE: cursor and icons implementation + * COPYRIGHT: Copyright Jérôme Gardou (jerome.gardou(a)reactos.org) + * Copyright 2022-2025 Doug Lyons (douglyons(a)douglyons.com) + * Copyright 2025 Katayama Hirofumi MZ (katayama.hirofumi.mz(a)gmail.com) */ #include <user32.h> +#include "png.h" WINE_DEFAULT_DEBUG_CHANNEL(cursor); WINE_DECLARE_DEBUG_CHANNEL(icon); //WINE_DECLARE_DEBUG_CHANNEL(resource); +#include <pshpack1.h> +typedef struct { + BYTE bWidth; + BYTE bHeight; + BYTE bColorCount; + BYTE bReserved; + union + { + WORD wPlanes; /* For icons */ + WORD xHotspot; /* For cursors */ + }; + union + { + WORD wBitCount; /* For icons */ + WORD yHotspot; /* For cursors */ + }; + DWORD dwDIBSize; + DWORD dwDIBOffset; +} CURSORICONFILEDIRENTRY; + +typedef struct +{ + WORD idReserved; + WORD idType; + WORD idCount; + CURSORICONFILEDIRENTRY idEntries[1]; +} CURSORICONFILEDIR; +#include <poppack.h> + +#define PNG_CHECK_SIG_SIZE 8 /* Check signature size */ + +/* libpng helpers */ +typedef struct { + png_bytep buffer; + size_t bufSize; + size_t currentPos; +} PNG_READER_STATE; + +/* This function will be used for reading png data from memory */ +static VOID +ReadMemoryPng( + _Inout_ png_structp png_ptr, + _Out_ png_bytep data, + _In_ size_t length) +{ + PNG_READER_STATE *state = png_get_io_ptr(png_ptr); + if ((state->currentPos + length) > state->bufSize) + { + ERR("png read error\n"); + png_error(png_ptr, "read error in ReadMemoryPng"); + return; + } + RtlCopyMemory(data, state->buffer + state->currentPos, length); + state->currentPos += length; +} + +static int get_dib_image_size(int width, int height, int depth); + +/* Convert PNG raw data to BMP icon data */ +static LPBYTE +CURSORICON_ConvertPngToBmpIcon( + _In_ LPBYTE pngBits, + _In_ DWORD fileSize, + _Out_ PDWORD pBmpIconSize) +{ + if (!pngBits || fileSize < PNG_CHECK_SIG_SIZE || !png_check_sig(pngBits, PNG_CHECK_SIG_SIZE)) + return NULL; + + TRACE("pngBits %p fileSize %d\n", pngBits, fileSize); + + png_structp png_ptr = png_create_read_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL); + if (!png_ptr) + { + ERR("png_create_read_struct error\n"); + return NULL; + } + + png_infop info_ptr = png_create_info_struct(png_ptr); + if (!info_ptr) + { + ERR("png_create_info_struct error\n"); + png_destroy_read_struct(&png_ptr, NULL, NULL); + return NULL; + } + + /* Set our own read_function */ + PNG_READER_STATE readerState = { pngBits, fileSize, PNG_CHECK_SIG_SIZE }; + png_set_read_fn(png_ptr, &readerState, ReadMemoryPng); + png_set_sig_bytes(png_ptr, PNG_CHECK_SIG_SIZE); + + /* Read png info */ + png_read_info(png_ptr, info_ptr); + + /* Add translation of some PNG formats and update info */ + int colorType = png_get_color_type(png_ptr, info_ptr); + if (colorType == PNG_COLOR_TYPE_PALETTE) + png_set_palette_to_rgb(png_ptr); + else if (colorType == PNG_COLOR_TYPE_GRAY || colorType == PNG_COLOR_TYPE_GRAY_ALPHA) + png_set_gray_to_rgb(png_ptr); + png_set_scale_16(png_ptr); /* Convert 16-bit channels to 8-bit */ + png_read_update_info(png_ptr, info_ptr); + + /* Get updated png info */ + png_uint_32 width, height; + int bitDepth; + png_get_IHDR(png_ptr, info_ptr, &width, &height, &bitDepth, &colorType, NULL, NULL, NULL); + TRACE("width %d, height %d, bitDepth %d, colorType %d\n", + width, height, bitDepth, colorType); + + int channels = png_get_channels(png_ptr, info_ptr); + int rowbytes = png_get_rowbytes(png_ptr, info_ptr); + int imageSize = height * rowbytes; + TRACE("rowbytes %d, channels %d, imageSize %d\n", rowbytes, channels, imageSize); + + /* Allocate rows data */ + png_bytepp rows = png_malloc(png_ptr, sizeof(png_bytep) * height); + if (!rows) + { + ERR("png_malloc failed\n"); + png_destroy_read_struct(&png_ptr, &info_ptr, NULL); + return NULL; + } + + for (int i = 0; i < (int)height; i++) + { + rows[i] = png_malloc(png_ptr, rowbytes); + if (!rows[i]) + { + ERR("png_malloc failed\n"); + + /* Clean up */ + while (--i >= 0) + png_free(png_ptr, rows[i]); + png_free(png_ptr, rows); + png_destroy_read_struct(&png_ptr, &info_ptr, NULL); + + return NULL; + } + } + + /* Read png image data */ + png_set_rows(png_ptr, info_ptr, rows); + png_read_image(png_ptr, rows); + png_read_end(png_ptr, info_ptr); + + /* After reading the image, you can deal with row pointers */ + LPBYTE imageBytes = HeapAlloc(GetProcessHeap(), 0, imageSize); + if (imageBytes) + { + LPBYTE pb = imageBytes; + for (int i = height - 1; i >= 0; i--) + { + png_bytep row = rows[i]; + for (int j = 0; j < channels * width; j += channels) + { + *pb++ = row[j + 2]; /* Red */ + *pb++ = row[j + 1]; /* Green */ + *pb++ = row[j + 0]; /* Blue */ + if (channels == 4) + *pb++ = row[j + 3]; /* Alpha */ + } + pb += (channels * width) % 4; + } + } + + /* Clean up */ + for (int i = 0; i < (int)height; i++) + png_free(png_ptr, rows[i]); + png_free(png_ptr, rows); + png_destroy_read_struct(&png_ptr, &info_ptr, NULL); + + if (!imageBytes) + { + ERR("HeapAlloc failed\n"); + return NULL; + } + + /* BPP (Bits Per Pixel) */ + WORD bpp = (WORD)(bitDepth * channels); + + /* The byte size of mask bits */ + DWORD maskSize = get_dib_image_size(width, height, 1); + + /* Build BITMAPINFOHEADER */ + BITMAPINFOHEADER info = { sizeof(info) }; + info.biWidth = width; + info.biHeight = 2 * height; + info.biPlanes = 1; + info.biBitCount = bpp; + info.biCompression = BI_RGB; + + /* Build CURSORICONFILEDIR */ + CURSORICONFILEDIR cifd = { 0, 1, 1 }; + cifd.idEntries[0].bWidth = (BYTE)width; + cifd.idEntries[0].bHeight = (BYTE)height; + cifd.idEntries[0].bColorCount = 0; /* No color pallete */ + cifd.idEntries[0].wPlanes = 1; /* Must be 1 */ + cifd.idEntries[0].wBitCount = bpp; + cifd.idEntries[0].dwDIBSize = (DWORD)(sizeof(info) + imageSize + maskSize); + cifd.idEntries[0].dwDIBOffset = (DWORD)sizeof(cifd); + + /* Allocate BMP icon data */ + *pBmpIconSize = (DWORD)(sizeof(cifd) + sizeof(info) + imageSize + maskSize); + LPBYTE pbBmpIcon = HeapAlloc(GetProcessHeap(), 0, *pBmpIconSize); + if (!pbBmpIcon) + { + ERR("HeapAlloc failed\n"); + HeapFree(GetProcessHeap(), 0, imageBytes); + return NULL; + } + + /* Store data to pbBmpIcon */ + LPBYTE pb = pbBmpIcon; + RtlCopyMemory(pb, &cifd, sizeof(cifd)); + pb += sizeof(cifd); + RtlCopyMemory(pb, &info, sizeof(info)); + pb += sizeof(info); + RtlCopyMemory(pb, imageBytes, imageSize); + pb += imageSize; + RtlFillMemory(pb, maskSize, 0xFF); /* Mask bits for AND operation */ + + HeapFree(GetProcessHeap(), 0, imageBytes); + return pbBmpIcon; +} + /* We only use Wide string functions */ #undef MAKEINTRESOURCE #define MAKEINTRESOURCE MAKEINTRESOURCEW @@ -221,7 +448,7 @@ static int DIB_GetBitmapInfo( const BITMAPINFOHEADER *header, LONG *width, } if (memcmp(&header->biSize, png_sig_pattern, sizeof(png_sig_pattern)) == 0) { - ERR("Cannot yet display PNG icons\n"); + TRACE("We have a PNG icon\n"); /* for PNG format details see
https://en.wikipedia.org/wiki/PNG
*/ } else @@ -469,29 +696,6 @@ done: return alpha; } -#include "pshpack1.h" - -typedef struct { - BYTE bWidth; - BYTE bHeight; - BYTE bColorCount; - BYTE bReserved; - WORD xHotspot; - WORD yHotspot; - DWORD dwDIBSize; - DWORD dwDIBOffset; -} CURSORICONFILEDIRENTRY; - -typedef struct -{ - WORD idReserved; - WORD idType; - WORD idCount; - CURSORICONFILEDIRENTRY idEntries[1]; -} CURSORICONFILEDIR; - -#include "poppack.h" - const CURSORICONFILEDIRENTRY* get_best_icon_file_entry( _In_ const CURSORICONFILEDIR* dir, @@ -1155,6 +1359,14 @@ BITMAP_LoadImageW( ResSize = SizeofResource(hinst, hrsrc); } + if (pbmi->bmiHeader.biCompression == BI_BITFIELDS && pbmi->bmiHeader.biBitCount == 32) + { + SIZE_T totalSize = pbmi->bmiHeader.biSize + (3 * sizeof(DWORD)) + + pbmi->bmiHeader.biSizeImage; + if (pbmi->bmiHeader.biSizeImage != 0 && totalSize != ResSize) + WARN("Possibly bad resource size provided\n"); + } + /* Fix up values */ if(DIB_GetBitmapInfo(&pbmi->bmiHeader, &width, &height, &bpp, &compr) == -1) goto end; @@ -1385,8 +1597,8 @@ CURSORICON_LoadFromFileW( { const CURSORICONFILEDIRENTRY *entry; const CURSORICONFILEDIR *dir; - DWORD filesize = 0; - LPBYTE bits; + DWORD filesize = 0, BmpIconSize; + LPBYTE bits, pbBmpIcon = NULL; HANDLE hCurIcon = NULL; CURSORDATA cursorData; @@ -1418,15 +1630,37 @@ CURSORICON_LoadFromFileW( cursorData.xHotspot = entry->xHotspot; cursorData.yHotspot = entry->yHotspot; } - cursorData.rt = (USHORT)((ULONG_PTR)(bIcon ? RT_ICON : RT_CURSOR)); + cursorData.rt = LOWORD(bIcon ? RT_ICON : RT_CURSOR); + + /* Try to load BMP icon */ + DWORD dwOffset = entry->dwDIBOffset; + if (!CURSORICON_GetCursorDataFromBMI(&cursorData, (BITMAPINFO *)(&bits[dwOffset]))) + { + /* Convert PNG raw data to BMP icon if the icon was PNG icon */ + LPBYTE pngBits = &bits[entry->dwDIBOffset]; + pbBmpIcon = CURSORICON_ConvertPngToBmpIcon(pngBits, filesize, &BmpIconSize); + if (!pbBmpIcon) + goto end; /* Not PNG icon or failed */ + + /* Find icon entry from BMP icon */ + dir = (CURSORICONFILEDIR *)pbBmpIcon; + entry = &dir->idEntries[0]; /* Only one entry */ + + /* A bit of preparation */ + RtlZeroMemory(&cursorData, sizeof(cursorData)); + cursorData.rt = LOWORD(bIcon ? RT_ICON : RT_CURSOR); - /* Do the dance */ - if(!CURSORICON_GetCursorDataFromBMI(&cursorData, (BITMAPINFO*)(&bits[entry->dwDIBOffset]))) + /* Can we load this BMP icon? */ + dwOffset = entry->dwDIBOffset; + if (!CURSORICON_GetCursorDataFromBMI(&cursorData, (BITMAPINFO *)(&pbBmpIcon[dwOffset]))) { - ERR("Failing File is \n '%S'.\n", lpszName); + ERR("Failing file: '%S'.\n", lpszName); goto end; } + TRACE("Processing PNG/Vista icon: '%S'\n", lpszName); + } + hCurIcon = NtUserxCreateEmptyCurObject(FALSE); if(!hCurIcon) goto end; @@ -1435,21 +1669,16 @@ CURSORICON_LoadFromFileW( if(!NtUserSetCursorIconData(hCurIcon, NULL, NULL, &cursorData)) { NtUserDestroyCursor(hCurIcon, TRUE); - goto end_error; + hCurIcon = NULL; + if (cursorData.hbmMask) DeleteObject(cursorData.hbmMask); + if (cursorData.hbmColor) DeleteObject(cursorData.hbmColor); + if (cursorData.hbmAlpha) DeleteObject(cursorData.hbmAlpha); } end: UnmapViewOfFile(bits); + HeapFree(GetProcessHeap(), 0, pbBmpIcon); return hCurIcon; - - /* Clean up */ -end_error: - DeleteObject(cursorData.hbmMask); - if(cursorData.hbmColor) DeleteObject(cursorData.hbmColor); - if(cursorData.hbmAlpha) DeleteObject(cursorData.hbmAlpha); - UnmapViewOfFile(bits); - - return NULL; } static @@ -1514,7 +1743,7 @@ CURSORICON_LoadImageW( SetLastError(ERROR_NOT_ENOUGH_MEMORY); return NULL; } - ustrModule.Length = wsprintfW(ustrModule.Buffer, fakeNameFmt, hinst) * sizeof(WCHAR); + ustrModule.Length = (USHORT)wsprintfW(ustrModule.Buffer, fakeNameFmt, hinst) * sizeof(WCHAR); } else if(hinst) { @@ -1545,8 +1774,8 @@ CURSORICON_LoadImageW( } ustrModule.Buffer[ret] = UNICODE_NULL; - ustrModule.Length = ret * sizeof(WCHAR); - ustrModule.MaximumLength = size * sizeof(WCHAR); + ustrModule.Length = (USHORT)(ret * sizeof(WCHAR)); + ustrModule.MaximumLength = (USHORT)(size * sizeof(WCHAR)); break; } } @@ -2539,9 +2768,17 @@ HICON WINAPI CreateIconFromResourceEx( CURSORDATA cursorData; HICON hIcon; BOOL isAnimated; + LPBYTE pbBmpIcon = NULL; + DWORD BmpIconSize; TRACE("%p, %lu, %lu, %lu, %i, %i, %lu.\n", pbIconBits, cbIconBits, fIcon, dwVersion, cxDesired, cyDesired, uFlags); + if (!pbIconBits || cbIconBits < 2 * sizeof(DWORD)) + { + ERR("Sanity check failed\n"); + return NULL; + } + if(uFlags & LR_DEFAULTSIZE) { if(!cxDesired) cxDesired = GetSystemMetrics(fIcon ? SM_CXICON : SM_CXCURSOR); @@ -2551,7 +2788,7 @@ HICON WINAPI CreateIconFromResourceEx( ZeroMemory(&cursorData, sizeof(cursorData)); cursorData.cx = cxDesired; cursorData.cy = cyDesired; - cursorData.rt = (USHORT)((ULONG_PTR)(fIcon ? RT_ICON : RT_CURSOR)); + cursorData.rt = LOWORD(fIcon ? RT_ICON : RT_CURSOR); /* Convert to win32k-ready data */ if(!memcmp(pbIconBits, "RIFF", 4)) @@ -2622,15 +2859,30 @@ HICON WINAPI CreateIconFromResourceEx( pbIconBits = (PBYTE)pt; } - if (!CURSORICON_GetCursorDataFromBMI(&cursorData, (BITMAPINFO*)pbIconBits)) + /* Try to load BMP icon */ + if (!CURSORICON_GetCursorDataFromBMI(&cursorData, (BITMAPINFO *)pbIconBits)) { - ERR("Couldn't fill the CURSORDATA structure.\n"); - if (ResHandle) - FreeResource(ResHandle); - return NULL; + /* Convert PNG raw data to BMP icon if the icon was PNG icon */ + pbBmpIcon = CURSORICON_ConvertPngToBmpIcon(pbIconBits, cbIconBits, &BmpIconSize); + if (!pbBmpIcon) + goto end; /* Not PNG icon or failed */ + + /* Find icon entry from BMP icon */ + CURSORICONFILEDIR *dir = (CURSORICONFILEDIR *)pbBmpIcon; + CURSORICONFILEDIRENTRY *entry = &dir->idEntries[0]; /* Only one entry */ + + /* A bit of preparation */ + RtlZeroMemory(&cursorData, sizeof(cursorData)); + cursorData.rt = LOWORD(fIcon ? RT_ICON : RT_CURSOR); + + /* Can we load this BMP icon? */ + DWORD dwOffset = entry->dwDIBOffset; + if (!CURSORICON_GetCursorDataFromBMI(&cursorData, (BITMAPINFO *)&pbBmpIcon[dwOffset])) + { + ERR("Couldn't get cursor/icon data\n"); + goto end; + } } - if (ResHandle) - FreeResource(ResHandle); isAnimated = FALSE; } @@ -2651,10 +2903,13 @@ HICON WINAPI CreateIconFromResourceEx( if(isAnimated) HeapFree(GetProcessHeap(), 0, cursorData.aspcur); +end: + HeapFree(GetProcessHeap(), 0, pbBmpIcon); return hIcon; /* Clean up */ end_error: + HeapFree(GetProcessHeap(), 0, pbBmpIcon); if(isAnimated) HeapFree(GetProcessHeap(), 0, cursorData.aspcur); DeleteObject(cursorData.hbmMask);
4Â months, 3Â weeks
1
0
0
0
[reactos] 01/01: [NTUSER][USER32] Support GetWindow.GW_ENABLEDPOPUP (#7700)
by Katayama Hirofumi MZ
https://git.reactos.org/?p=reactos.git;a=commitdiff;h=22577aed85f91b33a25c8…
commit 22577aed85f91b33a25c89ad857951ddb8e1a988 Author: Katayama Hirofumi MZ <katayama.hirofumi.mz(a)gmail.com> AuthorDate: Fri Feb 7 07:31:08 2025 +0900 Commit: GitHub <noreply(a)github.com> CommitDate: Fri Feb 7 07:31:08 2025 +0900 [NTUSER][USER32] Support GetWindow.GW_ENABLEDPOPUP (#7700) JIRA issue: CORE-6920 - Make the return value of NtUserCallHwnd a DWORD_PTR. - Add DWP_GetEnabledPopup helper function in win32ss/user/ntuser/defwnd.c. - Add code to NtUserCallHwnd for HWND_ROUTINE_DWP_GETENABLEDPOPUP. - Add code to GetWindow for GW_ENABLEDPOPUP. - Set last error in GetWindow and IntGetWindow. --- win32ss/include/ntuser.h | 2 +- win32ss/user/ntuser/defwnd.c | 52 +++++++++++++++++++++++++++++++++ win32ss/user/ntuser/simplecall.c | 13 ++++++++- win32ss/user/ntuser/userfuncs.h | 1 + win32ss/user/ntuser/window.c | 2 +- win32ss/user/user32/include/ntwrapper.h | 8 ++--- win32ss/user/user32/windows/window.c | 12 +++++++- 7 files changed, 82 insertions(+), 8 deletions(-) diff --git a/win32ss/include/ntuser.h b/win32ss/include/ntuser.h index 7e09af4896f..783d4e0c32a 100644 --- a/win32ss/include/ntuser.h +++ b/win32ss/include/ntuser.h @@ -1670,7 +1670,7 @@ enum SimpleCallRoutines TWOPARAM_ROUTINE_WOWCLEANUP }; -DWORD +DWORD_PTR NTAPI NtUserCallHwnd( HWND hWnd, diff --git a/win32ss/user/ntuser/defwnd.c b/win32ss/user/ntuser/defwnd.c index 368105afc42..dba5c7b567b 100644 --- a/win32ss/user/ntuser/defwnd.c +++ b/win32ss/user/ntuser/defwnd.c @@ -495,6 +495,58 @@ DefWndGetIcon(PWND pWnd, WPARAM wParam, LPARAM lParam) return (LRESULT)hIconRet; } +PWND FASTCALL +DWP_GetEnabledPopup(PWND pWnd) +{ + PWND pwndNode1; + PTHREADINFO pti = pWnd->head.pti, ptiNode; + BOOL bFoundNullNode = FALSE; + + for (pwndNode1 = pWnd->spwndNext; pwndNode1 != pWnd; ) + { + if (!pwndNode1) /* NULL detected? */ + { + if (bFoundNullNode) + return NULL; + bFoundNullNode = TRUE; + /* Retry with parent's first child (once only) */ + pwndNode1 = pWnd->spwndParent->spwndChild; + continue; + } + + /* + * 1. We want to detect the window that owns the same input target of pWnd. + * 2. For non-16-bit apps, we need to check the two threads' input queues to + * see whether they are the same, while for 16-bit apps it's sufficient to + * only check the thread info pointers themselves (ptiNode and pti). + * See also: + *
https://devblogs.microsoft.com/oldnewthing/20060221-09/?p=32203
+ *
https://github.com/reactos/reactos/pull/7700#discussion_r1939435931
+ */ + ptiNode = pwndNode1->head.pti; + if ((!(pti->TIF_flags & TIF_16BIT) && ptiNode->MessageQueue == pti->MessageQueue) || + ((pti->TIF_flags & TIF_16BIT) && ptiNode == pti)) + { + DWORD style = pwndNode1->style; + if ((style & WS_VISIBLE) && !(style & WS_DISABLED)) /* Visible and enabled? */ + { + /* Does pwndNode1 have a pWnd as an ancestor? */ + PWND pwndNode2; + for (pwndNode2 = pwndNode1->spwndOwner; pwndNode2; + pwndNode2 = pwndNode2->spwndOwner) + { + if (pwndNode2 == pWnd) + return pwndNode1; + } + } + } + + pwndNode1 = pwndNode1->spwndNext; + } + + return NULL; +} + VOID FASTCALL DefWndScreenshot(PWND pWnd) { diff --git a/win32ss/user/ntuser/simplecall.c b/win32ss/user/ntuser/simplecall.c index fa7ee28d857..6a433ed7120 100644 --- a/win32ss/user/ntuser/simplecall.c +++ b/win32ss/user/ntuser/simplecall.c @@ -706,7 +706,7 @@ NtUserCallHwndOpt( return hWnd; } -DWORD +DWORD_PTR APIENTRY NtUserCallHwnd( HWND hWnd, @@ -755,6 +755,17 @@ NtUserCallHwnd( UserLeave(); return FALSE; } + + case HWND_ROUTINE_DWP_GETENABLEDPOPUP: + { + PWND pWnd; + UserEnterShared(); + pWnd = UserGetWindowObject(hWnd); + if (pWnd) + pWnd = DWP_GetEnabledPopup(pWnd); + UserLeave(); + return (DWORD_PTR)pWnd; + } } STUB; diff --git a/win32ss/user/ntuser/userfuncs.h b/win32ss/user/ntuser/userfuncs.h index 740607530a4..f282344ab56 100644 --- a/win32ss/user/ntuser/userfuncs.h +++ b/win32ss/user/ntuser/userfuncs.h @@ -161,6 +161,7 @@ LRESULT NC_HandleNCRButtonDown( PWND wnd, WPARAM wParam, LPARAM lParam ); HBRUSH FASTCALL DefWndControlColor(HDC hDC,UINT ctlType); BOOL UserDrawSysMenuButton(PWND pWnd, HDC hDC, LPRECT Rect, BOOL Down); BOOL UserPaintCaption(PWND pWnd, INT Flags); +PWND FASTCALL DWP_GetEnabledPopup(PWND pWnd); /************** LAYERED **************/ diff --git a/win32ss/user/ntuser/window.c b/win32ss/user/ntuser/window.c index 55df7d52b4c..9f8d669e3e8 100644 --- a/win32ss/user/ntuser/window.c +++ b/win32ss/user/ntuser/window.c @@ -428,7 +428,7 @@ IntGetWindow(HWND hWnd, break; default: - Wnd = NULL; + EngSetLastError(ERROR_INVALID_GW_COMMAND); break; } diff --git a/win32ss/user/user32/include/ntwrapper.h b/win32ss/user/user32/include/ntwrapper.h index 67b67de6ed9..067077890ed 100644 --- a/win32ss/user/user32/include/ntwrapper.h +++ b/win32ss/user/user32/include/ntwrapper.h @@ -725,22 +725,22 @@ EXTINLINE VOID NtUserxNotifyWinEvent(HWND hWnd, PVOID ne) EXTINLINE DWORD NtUserxGetWindowContextHelpId(HWND hwnd) { - return NtUserCallHwnd(hwnd, HWND_ROUTINE_GETWNDCONTEXTHLPID); + return (DWORD)NtUserCallHwnd(hwnd, HWND_ROUTINE_GETWNDCONTEXTHLPID); } EXTINLINE BOOL NtUserxDeregisterShellHookWindow(HWND hWnd) { - return NtUserCallHwnd(hWnd, HWND_ROUTINE_DEREGISTERSHELLHOOKWINDOW); + return (BOOL)NtUserCallHwnd(hWnd, HWND_ROUTINE_DEREGISTERSHELLHOOKWINDOW); } EXTINLINE BOOL NtUserxRegisterShellHookWindow(HWND hWnd) { - return NtUserCallHwnd(hWnd, HWND_ROUTINE_REGISTERSHELLHOOKWINDOW); + return (BOOL)NtUserCallHwnd(hWnd, HWND_ROUTINE_REGISTERSHELLHOOKWINDOW); } EXTINLINE BOOL NtUserxSetMessageBox(HWND hWnd) { - return NtUserCallHwnd(hWnd, HWND_ROUTINE_SETMSGBOX); + return (BOOL)NtUserCallHwnd(hWnd, HWND_ROUTINE_SETMSGBOX); } EXTINLINE VOID NtUserxClearWindowState(PWND pWnd, UINT Flag) diff --git a/win32ss/user/user32/windows/window.c b/win32ss/user/user32/windows/window.c index dfe06a349c5..e7468f8a91c 100644 --- a/win32ss/user/user32/windows/window.c +++ b/win32ss/user/user32/windows/window.c @@ -1141,9 +1141,19 @@ GetWindow(HWND hWnd, FoundWnd = DesktopPtrToUser(FoundWnd->spwndNext); break; + case GW_ENABLEDPOPUP: + { + PWND pwndPopup = (PWND)NtUserCallHwnd(hWnd, HWND_ROUTINE_DWP_GETENABLEDPOPUP); + if (pwndPopup) + FoundWnd = DesktopPtrToUser(pwndPopup); + break; + } + default: - Wnd = NULL; + { + UserSetLastError(ERROR_INVALID_GW_COMMAND); break; + } } if (FoundWnd != NULL)
4Â months, 3Â weeks
1
0
0
0
[reactos] 01/01: [SYSSETUP] Add the type library registration to the Register Components task on the process page
by Eric Kohl
https://git.reactos.org/?p=reactos.git;a=commitdiff;h=2d8a2944baad1078aa980…
commit 2d8a2944baad1078aa98097b38d86fb3b72dee01 Author: Eric Kohl <eric.kohl(a)reactos.org> AuthorDate: Thu Feb 6 23:14:28 2025 +0100 Commit: Eric Kohl <eric.kohl(a)reactos.org> CommitDate: Thu Feb 6 23:14:28 2025 +0100 [SYSSETUP] Add the type library registration to the Register Components task on the process page --- dll/win32/syssetup/globals.h | 9 +++- dll/win32/syssetup/install.c | 25 +++++++++-- dll/win32/syssetup/wizard.c | 104 ++++++++++++++++++++++++++++++------------- 3 files changed, 102 insertions(+), 36 deletions(-) diff --git a/dll/win32/syssetup/globals.h b/dll/win32/syssetup/globals.h index 85b3f8dea3a..8112102a0b7 100644 --- a/dll/win32/syssetup/globals.h +++ b/dll/win32/syssetup/globals.h @@ -68,10 +68,15 @@ extern HINSTANCE hDllInstance; extern HINF hSysSetupInf; extern ADMIN_INFO AdminInfo; -BOOL RegisterTypeLibraries (HINF hinf, LPCWSTR szSection); - /* install */ +BOOL +RegisterTypeLibraries( + _In_ PITEMSDATA pItemsData, + _In_ PREGISTRATIONNOTIFY pNotify, + _In_ HINF hinf, + _In_ LPCWSTR szSection); + VOID InstallStartMenuItems( _In_ PITEMSDATA pItemsData); diff --git a/dll/win32/syssetup/install.c b/dll/win32/syssetup/install.c index 61d5da1bc33..4d964fab68c 100644 --- a/dll/win32/syssetup/install.c +++ b/dll/win32/syssetup/install.c @@ -336,11 +336,9 @@ InstallStartMenuItems( INF_STYLE_WIN4, NULL); -// Steps = SetupGetLineCountW(hShortcutsInf1, L"ShortcutFolders"); Steps = CountShortcuts(hShortcutsInf1, L"ShortcutFolders"); if (hShortcutsInf2 != INVALID_HANDLE_VALUE) Steps += CountShortcuts(hShortcutsInf2, L"ShortcutFolders"); -// Steps += SetupGetLineCountW(hShortcutsInf2, L"ShortcutFolders"); SendMessage(pItemsData->hwndDlg, PM_ITEM_START, 1, (LPARAM)Steps); @@ -538,7 +536,11 @@ InstallSysSetupInfComponents(VOID) BOOL -RegisterTypeLibraries(HINF hinf, LPCWSTR szSection) +RegisterTypeLibraries( + _In_ PITEMSDATA pItemsData, + _In_ PREGISTRATIONNOTIFY pNotify, + _In_ HINF hinf, + _In_ LPCWSTR szSection) { INFCONTEXT InfContext; BOOL res; @@ -575,6 +577,15 @@ RegisterTypeLibraries(HINF hinf, LPCWSTR szSection) p = PathAddBackslash(szPath); wcscpy(p, szName); + if (pItemsData && pNotify) + { + pNotify->Progress++; + pNotify->CurrentItem = szName; + + DPRINT("RegisterTypeLibraries: Start step %ld\n", pNotify->Progress); + SendMessage(pItemsData->hwndDlg, PM_STEP_START, 0, (LPARAM)pNotify); + } + hmod = LoadLibraryW(szPath); if (hmod == NULL) { @@ -584,6 +595,12 @@ RegisterTypeLibraries(HINF hinf, LPCWSTR szSection) __wine_register_resources(hmod); + if (pItemsData && pNotify) + { + DPRINT("RegisterTypeLibraries: End step %ld\n", pNotify->Progress); + SendMessage(pItemsData->hwndDlg, PM_STEP_END, 0, (LPARAM)pNotify); + } + } while (SetupFindNextLine(&InfContext, &InfContext)); return TRUE; @@ -1073,7 +1090,7 @@ InstallLiveCD(VOID) DPRINT1("SetupInstallFromInfSectionW failed!\n"); } - RegisterTypeLibraries(hSysSetupInf, L"TypeLibraries"); + RegisterTypeLibraries(NULL, NULL, hSysSetupInf, L"TypeLibraries"); } _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER) { diff --git a/dll/win32/syssetup/wizard.c b/dll/win32/syssetup/wizard.c index 4675ff904a9..0345ed14f40 100644 --- a/dll/win32/syssetup/wizard.c +++ b/dll/win32/syssetup/wizard.c @@ -33,6 +33,7 @@ typedef struct _REGISTRATIONDATA ULONG DllCount; ULONG Registered; PVOID DefaultContext; + PREGISTRATIONNOTIFY pNotify; } REGISTRATIONDATA, *PREGISTRATIONDATA; typedef struct _TIMEZONE_ENTRY @@ -1991,7 +1992,6 @@ RegistrationNotificationProc(PVOID Context, UINT_PTR Param2) { PREGISTRATIONDATA RegistrationData; - REGISTRATIONNOTIFY RegistrationNotify; PSP_REGISTER_CONTROL_STATUSW StatusInfo; UINT MessageID; @@ -2001,23 +2001,24 @@ RegistrationNotificationProc(PVOID Context, Notification == SPFILENOTIFY_ENDREGISTRATION) { StatusInfo = (PSP_REGISTER_CONTROL_STATUSW) Param1; - RegistrationNotify.CurrentItem = wcsrchr(StatusInfo->FileName, L'\\'); - if (RegistrationNotify.CurrentItem == NULL) + RegistrationData->pNotify->CurrentItem = wcsrchr(StatusInfo->FileName, L'\\'); + if (RegistrationData->pNotify->CurrentItem == NULL) { - RegistrationNotify.CurrentItem = StatusInfo->FileName; + RegistrationData->pNotify->CurrentItem = StatusInfo->FileName; } else { - RegistrationNotify.CurrentItem++; + RegistrationData->pNotify->CurrentItem++; } if (Notification == SPFILENOTIFY_STARTREGISTRATION) { DPRINT("Received SPFILENOTIFY_STARTREGISTRATION notification for %S\n", StatusInfo->FileName); -// RegistrationNotify.ErrorMessage = NULL; - RegistrationNotify.Progress = RegistrationData->Registered; - SendMessage(RegistrationData->hwndDlg, PM_STEP_START, 0, (LPARAM)&RegistrationNotify); + RegistrationData->pNotify->Progress = RegistrationData->Registered; + + DPRINT("RegisterDll: Start step %ld\n", RegistrationData->pNotify->Progress); + SendMessage(RegistrationData->hwndDlg, PM_STEP_START, 0, (LPARAM)RegistrationData->pNotify); } else { @@ -2049,13 +2050,13 @@ RegistrationNotificationProc(PVOID Context, break; } - RegistrationNotify.MessageID = MessageID; - RegistrationNotify.LastError = StatusInfo->Win32Error; + RegistrationData->pNotify->MessageID = MessageID; + RegistrationData->pNotify->LastError = StatusInfo->Win32Error; } else { - RegistrationNotify.MessageID = 0; - RegistrationNotify.LastError = ERROR_SUCCESS; + RegistrationData->pNotify->MessageID = 0; + RegistrationData->pNotify->LastError = ERROR_SUCCESS; } if (RegistrationData->Registered < RegistrationData->DllCount) @@ -2063,8 +2064,9 @@ RegistrationNotificationProc(PVOID Context, RegistrationData->Registered++; } - RegistrationNotify.Progress = RegistrationData->Registered; - SendMessage(RegistrationData->hwndDlg, PM_STEP_END, 0, (LPARAM)&RegistrationNotify); + RegistrationData->pNotify->Progress = RegistrationData->Registered; + DPRINT("RegisterDll: End step %ld\n", RegistrationData->pNotify->Progress); + SendMessage(RegistrationData->hwndDlg, PM_STEP_END, 0, (LPARAM)RegistrationData->pNotify); } return FILEOP_DOIT; @@ -2081,13 +2083,14 @@ RegistrationNotificationProc(PVOID Context, static DWORD RegisterDlls( - PITEMSDATA pItemsData) + _In_ PITEMSDATA pItemsData, + _In_ PREGISTRATIONNOTIFY pNotify) { REGISTRATIONDATA RegistrationData; WCHAR SectionName[512]; INFCONTEXT Context; LONG DllCount = 0; - DWORD LastError = NO_ERROR; + DWORD Error = NO_ERROR; ZeroMemory(&RegistrationData, sizeof(REGISTRATIONDATA)); RegistrationData.hwndDlg = pItemsData->hwndDlg; @@ -2097,7 +2100,7 @@ RegisterDlls( L"RegisterDlls", &Context)) { DPRINT1("No RegistrationPhase2 section found\n"); - return FALSE; + return GetLastError(); } if (!SetupGetStringFieldW(&Context, 1, SectionName, @@ -2105,21 +2108,19 @@ RegisterDlls( NULL)) { DPRINT1("Unable to retrieve section name\n"); - return FALSE; + return GetLastError(); } DllCount = SetupGetLineCountW(hSysSetupInf, SectionName); - DPRINT1("SectionName %S DllCount %ld\n", SectionName, DllCount); + DPRINT("SectionName %S DllCount %ld\n", SectionName, DllCount); if (DllCount < 0) { - SetLastError(STATUS_NOT_FOUND); - return FALSE; + return STATUS_NOT_FOUND; } RegistrationData.DllCount = (ULONG)DllCount; RegistrationData.DefaultContext = SetupInitDefaultQueueCallback(RegistrationData.hwndDlg); - - SendMessage(pItemsData->hwndDlg, PM_ITEM_START, 0, (LPARAM)RegistrationData.DllCount); + RegistrationData.pNotify = pNotify; _SEH2_TRY { @@ -2135,21 +2136,66 @@ RegisterDlls( NULL, NULL)) { - LastError = GetLastError(); + Error = GetLastError(); } } _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER) { DPRINT("Catching exception\n"); - LastError = RtlNtStatusToDosError(_SEH2_GetExceptionCode()); + Error = RtlNtStatusToDosError(_SEH2_GetExceptionCode()); } _SEH2_END; SetupTermDefaultQueueCallback(RegistrationData.DefaultContext); - SendMessage(pItemsData->hwndDlg, PM_ITEM_END, 0, LastError); + return Error; +} - return 0; +static +VOID +RegisterComponents( + PITEMSDATA pItemsData) +{ + WCHAR SectionName[512]; + INFCONTEXT Context; + LONG Steps = 0; + DWORD Error = NO_ERROR; + REGISTRATIONNOTIFY Notify; + + ZeroMemory(&Notify, sizeof(Notify)); + + /* Count the 'RegisterDlls' steps */ + if (!SetupFindFirstLineW(hSysSetupInf, L"RegistrationPhase2", + L"RegisterDlls", &Context)) + { + DPRINT1("No RegistrationPhase2 section found\n"); + return; + } + + if (!SetupGetStringFieldW(&Context, 1, SectionName, + ARRAYSIZE(SectionName), + NULL)) + { + DPRINT1("Unable to retrieve section name\n"); + return; + } + + Steps += SetupGetLineCountW(hSysSetupInf, SectionName); + + /* Count the 'TypeLibratries' steps */ + Steps += SetupGetLineCountW(hSysSetupInf, L"TypeLibraries"); + + /* Start the item */ + DPRINT("Register Components: %ld Steps\n", Steps); + SendMessage(pItemsData->hwndDlg, PM_ITEM_START, 0, (LPARAM)Steps); + + Error = RegisterDlls(pItemsData, &Notify); + if (Error == ERROR_SUCCESS) + RegisterTypeLibraries(pItemsData, &Notify, hSysSetupInf, L"TypeLibraries"); + + /* End the item */ + DPRINT("Register Components: done\n"); + SendMessage(pItemsData->hwndDlg, PM_ITEM_END, 0, Error); } @@ -2166,9 +2212,7 @@ ItemCompletionThread( hwndDlg = pItemsData->hwndDlg; /* Step 0 - Registering components */ - RegisterDlls(pItemsData); - - RegisterTypeLibraries(hSysSetupInf, L"TypeLibraries"); + RegisterComponents(pItemsData); /* Step 1 - Installing start menu items */ InstallStartMenuItems(pItemsData);
4Â months, 3Â weeks
1
0
0
0
← Newer
1
...
8
9
10
11
12
13
14
...
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