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
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
December 2017
----- 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
26 participants
355 discussions
Start a n
N
ew thread
[reactos] 01/01: [MSVCRT_WINETEST] Add a PCH.
by Amine Khaldi
https://git.reactos.org/?p=reactos.git;a=commitdiff;h=9cfa608dcffce7c319dc4…
commit 9cfa608dcffce7c319dc4371b8513bde727c538e Author: Amine Khaldi <amine.khaldi(a)reactos.org> AuthorDate: Wed Dec 20 12:57:58 2017 +0100 [MSVCRT_WINETEST] Add a PCH. --- modules/rostests/winetests/msvcrt/CMakeLists.txt | 7 ++--- modules/rostests/winetests/msvcrt/cpp.c | 5 ++-- modules/rostests/winetests/msvcrt/data.c | 14 ++-------- modules/rostests/winetests/msvcrt/dir.c | 14 ++-------- modules/rostests/winetests/msvcrt/environ.c | 3 +-- modules/rostests/winetests/msvcrt/file.c | 13 ++------- modules/rostests/winetests/msvcrt/headers.c | 34 +----------------------- modules/rostests/winetests/msvcrt/heap.c | 5 ++-- modules/rostests/winetests/msvcrt/locale.c | 5 +--- modules/rostests/winetests/msvcrt/misc.c | 6 ++--- modules/rostests/winetests/msvcrt/precomp.h | 16 +++++++++++ modules/rostests/winetests/msvcrt/printf.c | 11 +------- modules/rostests/winetests/msvcrt/scanf.c | 4 +-- modules/rostests/winetests/msvcrt/signal.c | 4 +-- modules/rostests/winetests/msvcrt/string.c | 14 ++-------- modules/rostests/winetests/msvcrt/time.c | 12 +++------ 16 files changed, 44 insertions(+), 123 deletions(-) diff --git a/modules/rostests/winetests/msvcrt/CMakeLists.txt b/modules/rostests/winetests/msvcrt/CMakeLists.txt index 5aba4c2f7f..f50ed55eae 100644 --- a/modules/rostests/winetests/msvcrt/CMakeLists.txt +++ b/modules/rostests/winetests/msvcrt/CMakeLists.txt @@ -18,10 +18,10 @@ list(APPEND SOURCE scanf.c signal.c string.c - testlist.c - time.c) + time.c + precomp.h) -add_executable(msvcrt_winetest ${SOURCE}) +add_executable(msvcrt_winetest ${SOURCE} testlist.c) if(USE_CLANG_CL OR (NOT MSVC)) add_target_compile_flags(msvcrt_winetest "-Wno-format") @@ -35,4 +35,5 @@ if(MSVC) add_importlibs(msvcrt_winetest ntdll) endif() +add_pch(msvcrt_winetest precomp.h SOURCE) add_rostests_file(TARGET msvcrt_winetest) diff --git a/modules/rostests/winetests/msvcrt/cpp.c b/modules/rostests/winetests/msvcrt/cpp.c index cf5e4c7d60..22f59124e3 100644 --- a/modules/rostests/winetests/msvcrt/cpp.c +++ b/modules/rostests/winetests/msvcrt/cpp.c @@ -16,9 +16,8 @@ * 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 "wine/test.h" -#include "winbase.h" -#include "winnt.h" + +#include "precomp.h" typedef void (*vtable_ptr)(void); diff --git a/modules/rostests/winetests/msvcrt/data.c b/modules/rostests/winetests/msvcrt/data.c index 9aacac7b50..724eb67c9b 100644 --- a/modules/rostests/winetests/msvcrt/data.c +++ b/modules/rostests/winetests/msvcrt/data.c @@ -18,18 +18,8 @@ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA */ -#include "wine/test.h" -#include <stdarg.h> -#include <stdlib.h> -#include <stdio.h> -#include <fcntl.h> -#include <sys/stat.h> -#include <io.h> -#include <windef.h> -#include <winbase.h> -#include <winnls.h> -#include <process.h> -#include <errno.h> +#include "precomp.h" + #include <direct.h> void __cdecl __getmainargs(int *, char ***, char ***, int, int *); diff --git a/modules/rostests/winetests/msvcrt/dir.c b/modules/rostests/winetests/msvcrt/dir.c index aa273ea85e..ad96ae70b9 100644 --- a/modules/rostests/winetests/msvcrt/dir.c +++ b/modules/rostests/winetests/msvcrt/dir.c @@ -18,19 +18,9 @@ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA */ -#include "wine/test.h" -#include <stdarg.h> -#include <stdlib.h> -#include <stdio.h> -#include <fcntl.h> -#include <sys/stat.h> -#include <io.h> +#include "precomp.h" + #include <mbctype.h> -#include <windef.h> -#include <winbase.h> -#include <winnls.h> -#include <process.h> -#include <errno.h> static int (__cdecl *p_makepath_s)(char *, size_t, const char *, const char *, const char *, const char *); static int (__cdecl *p_wmakepath_s)(wchar_t *, size_t, const wchar_t *,const wchar_t *, const wchar_t *, const wchar_t *); diff --git a/modules/rostests/winetests/msvcrt/environ.c b/modules/rostests/winetests/msvcrt/environ.c index fdfe81f5ee..d74922fbba 100644 --- a/modules/rostests/winetests/msvcrt/environ.c +++ b/modules/rostests/winetests/msvcrt/environ.c @@ -18,8 +18,7 @@ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA */ -#include "wine/test.h" -#include <stdlib.h> +#include "precomp.h" static const char *a_very_long_env_string = "LIBRARY_PATH=" diff --git a/modules/rostests/winetests/msvcrt/file.c b/modules/rostests/winetests/msvcrt/file.c index d92a6e459a..b2d32a7c1f 100644 --- a/modules/rostests/winetests/msvcrt/file.c +++ b/modules/rostests/winetests/msvcrt/file.c @@ -19,21 +19,12 @@ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA */ -#include "wine/test.h" -#include <stdarg.h> -#include <stdlib.h> -#include <stdio.h> +#include "precomp.h" + #include <fcntl.h> #include <share.h> #include <sys/stat.h> #include <io.h> -#include <direct.h> -#include <windef.h> -#include <winbase.h> -#include <winnls.h> -#include <process.h> -#include <errno.h> -#include <locale.h> #define MSVCRT_FD_BLOCK_SIZE 32 typedef struct { diff --git a/modules/rostests/winetests/msvcrt/headers.c b/modules/rostests/winetests/msvcrt/headers.c index 52d739e107..6a5660f7d8 100644 --- a/modules/rostests/winetests/msvcrt/headers.c +++ b/modules/rostests/winetests/msvcrt/headers.c @@ -20,39 +20,7 @@ * symbols defined in msvcrt.h (prefixed by MSVCRT_). */ -#include "dos.h" -#include "math.h" -#include "stdlib.h" -#include "io.h" -#include "errno.h" -#include "fcntl.h" -#include "malloc.h" -#include "limits.h" -#include "mbctype.h" -#include "stdio.h" -#include "wchar.h" -#include "ctype.h" -#include "crtdbg.h" -#include "share.h" -#include "search.h" -#include "wctype.h" -#include "float.h" -#include "stddef.h" -#include "mbstring.h" -#include "sys/locking.h" -#include "sys/utime.h" -#include "sys/types.h" -#include "sys/stat.h" -#include "sys/timeb.h" -#include "direct.h" -#include "conio.h" -#include "process.h" -#include "string.h" -#include "signal.h" -#include "time.h" -#include "locale.h" -#include "setjmp.h" -#include "wine/test.h" +#include "precomp.h" #ifdef __WINE_USE_MSVCRT /* Wine-specific msvcrt headers */ diff --git a/modules/rostests/winetests/msvcrt/heap.c b/modules/rostests/winetests/msvcrt/heap.c index 4a3c7a8170..e7fa3ecf13 100644 --- a/modules/rostests/winetests/msvcrt/heap.c +++ b/modules/rostests/winetests/msvcrt/heap.c @@ -18,10 +18,9 @@ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA */ -#include <stdlib.h> +#include "precomp.h" + #include <malloc.h> -#include <errno.h> -#include "wine/test.h" static void (__cdecl *p_aligned_free)(void*) = NULL; static void * (__cdecl *p_aligned_malloc)(size_t,size_t) = NULL; diff --git a/modules/rostests/winetests/msvcrt/locale.c b/modules/rostests/winetests/msvcrt/locale.c index 89761dd947..0554270f1d 100644 --- a/modules/rostests/winetests/msvcrt/locale.c +++ b/modules/rostests/winetests/msvcrt/locale.c @@ -18,10 +18,7 @@ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA */ -#include <locale.h> - -#include "wine/test.h" -#include "winnls.h" +#include "precomp.h" static BOOL (__cdecl *p__crtGetStringTypeW)(DWORD, DWORD, const wchar_t*, int, WORD*); static int (__cdecl *pmemcpy_s)(void *, size_t, void*, size_t); diff --git a/modules/rostests/winetests/msvcrt/misc.c b/modules/rostests/winetests/msvcrt/misc.c index 2aeff43daa..d64cfe86cc 100644 --- a/modules/rostests/winetests/msvcrt/misc.c +++ b/modules/rostests/winetests/msvcrt/misc.c @@ -18,11 +18,9 @@ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA */ -#include <wine/test.h> -#include <errno.h> -#include <stdio.h> +#include "precomp.h" + #include <msvcrt.h> -#include <process.h> static inline float __port_infinity(void) { diff --git a/modules/rostests/winetests/msvcrt/precomp.h b/modules/rostests/winetests/msvcrt/precomp.h new file mode 100644 index 0000000000..6cc0b62bc3 --- /dev/null +++ b/modules/rostests/winetests/msvcrt/precomp.h @@ -0,0 +1,16 @@ +#ifndef _MSVCRT_WINETEST_PRECOMP_H_ +#define _MSVCRT_WINETEST_PRECOMP_H_ + +#define WIN32_NO_STATUS +#define _INC_WINDOWS +#define COM_NO_WINDOWS_H +#define _CRT_NON_CONFORMING_SWPRINTFS + +#include <wine/test.h> + +#include <stdio.h> +#include <winnls.h> +#include <process.h> +#include <locale.h> + +#endif /* !_MSVCRT_WINETEST_PRECOMP_H_ */ diff --git a/modules/rostests/winetests/msvcrt/printf.c b/modules/rostests/winetests/msvcrt/printf.c index f9b3fc9ff0..372509088c 100644 --- a/modules/rostests/winetests/msvcrt/printf.c +++ b/modules/rostests/winetests/msvcrt/printf.c @@ -23,17 +23,8 @@ /* With Visual Studio >= 2005, swprintf() takes an extra parameter unless * the following macro is defined. */ -#define _CRT_NON_CONFORMING_SWPRINTFS - -#include <stdio.h> -#include <errno.h> -#include <locale.h> -#include "windef.h" -#include "winbase.h" -#include "winnls.h" - -#include "wine/test.h" +#include "precomp.h" static inline float __port_infinity(void) { diff --git a/modules/rostests/winetests/msvcrt/scanf.c b/modules/rostests/winetests/msvcrt/scanf.c index 1d1f28eaf4..a5c4d9da71 100644 --- a/modules/rostests/winetests/msvcrt/scanf.c +++ b/modules/rostests/winetests/msvcrt/scanf.c @@ -18,9 +18,7 @@ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA */ -#include <stdio.h> - -#include "wine/test.h" +#include "precomp.h" static void test_sscanf( void ) { diff --git a/modules/rostests/winetests/msvcrt/signal.c b/modules/rostests/winetests/msvcrt/signal.c index ad6ea6ecf9..5947889841 100644 --- a/modules/rostests/winetests/msvcrt/signal.c +++ b/modules/rostests/winetests/msvcrt/signal.c @@ -18,8 +18,8 @@ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA */ -#include "wine/test.h" -#include <winbase.h> +#include "precomp.h" + #include <signal.h> static int test_value = 0; diff --git a/modules/rostests/winetests/msvcrt/string.c b/modules/rostests/winetests/msvcrt/string.c index 1681001a86..10974e5ad4 100644 --- a/modules/rostests/winetests/msvcrt/string.c +++ b/modules/rostests/winetests/msvcrt/string.c @@ -18,23 +18,13 @@ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA */ -#include "wine/test.h" -#include <string.h> +#include "precomp.h" + #include <mbstring.h> #include <wchar.h> -#include <stdlib.h> -#include <stdio.h> #include <mbctype.h> -#include <locale.h> -#include <errno.h> -#include <limits.h> #include <math.h> -/* make it use a definition from string.h */ -#undef strncpy -#include "winbase.h" -#include "winnls.h" - static char *buf_to_string(const unsigned char *bin, int len, int nr) { static char buf[2][1024]; diff --git a/modules/rostests/winetests/msvcrt/time.c b/modules/rostests/winetests/msvcrt/time.c index 6865e3d269..6173cf4bc6 100644 --- a/modules/rostests/winetests/msvcrt/time.c +++ b/modules/rostests/winetests/msvcrt/time.c @@ -18,15 +18,9 @@ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA */ -#include "wine/test.h" -#include "winbase.h" -#include "winnls.h" -#include "time.h" - -#include <stdlib.h> /*setenv*/ -#include <stdio.h> /*printf*/ -#include <locale.h> -#include <errno.h> +#include "precomp.h" + +#include <time.h> #define _MAX__TIME64_T (((__time64_t)0x00000007 << 32) | 0x93406FFF)
7 years
1
0
0
0
[reactos] 01/01: Replace our dxtn.dll by a version based on the libtxc_dxtn source code (#203)
by Colin Finck
https://git.reactos.org/?p=reactos.git;a=commitdiff;h=12b78f182da5f1c21ef4d…
commit 12b78f182da5f1c21ef4d53b4c938a4bb346defa Author: Colin Finck <colin(a)reactos.org> AuthorDate: Wed Dec 20 11:15:13 2017 +0100 Replace our dxtn.dll by a version based on the libtxc_dxtn source code (#203) This is no official system DLL and WineD3D is its only user. But latest WineD3D prefers the libtxc_dxtn codebase instead of the alternative library we used. This is also what Mesa uses and Fedora ships now that the patents have expired, so we should stick to the same. I'm importing the libtxc_dxtn-1.0.1 codebase from
https://people.freedesktop.org/~cbrill/libtxc_dxtn/
It compiles warning-free in our tree without modifying a single line! I'm merging this Pull Request based on the positive response in CORE-12759. I lack a proper test case myself, but my version at least shouldn't make things worse. In my opinion, the previous one was broken anyway due to using stdcall imports when WineD3D called cdecl ones. This also removes the NSWPAT option from our buildsystem as dxtn was its latest user. --- dll/3rdparty/CMakeLists.txt | 5 +- dll/3rdparty/dxtn/CMakeLists.txt | 9 +- dll/3rdparty/dxtn/dxtn.c | 757 -------------- dll/3rdparty/dxtn/dxtn.h | 62 -- dll/3rdparty/dxtn/dxtn.spec | 18 +- dll/3rdparty/dxtn/fxt1.c | 1369 -------------------------- dll/3rdparty/dxtn/fxt1.h | 38 - dll/3rdparty/dxtn/internal.h | 138 --- dll/3rdparty/dxtn/txc_compress_dxtn.c | 843 ++++++++++++++++ dll/3rdparty/dxtn/{texstore.c => txc_dxtn.h} | 53 +- dll/3rdparty/dxtn/txc_fetch_dxtn.c | 243 +++++ dll/3rdparty/dxtn/types.h | 11 - dll/3rdparty/dxtn/wrapper.c | 110 --- sdk/cmake/config-amd64.cmake | 6 - sdk/cmake/config-arm.cmake | 6 - sdk/cmake/config.cmake | 6 - 16 files changed, 1118 insertions(+), 2556 deletions(-) diff --git a/dll/3rdparty/CMakeLists.txt b/dll/3rdparty/CMakeLists.txt index 936727c7b3..4ef9d7bce5 100644 --- a/dll/3rdparty/CMakeLists.txt +++ b/dll/3rdparty/CMakeLists.txt @@ -1,8 +1,5 @@ -if(NSWPAT) - add_subdirectory(dxtn) -endif() - +add_subdirectory(dxtn) add_subdirectory(libjpeg) add_subdirectory(libpng) add_subdirectory(libtiff) diff --git a/dll/3rdparty/dxtn/CMakeLists.txt b/dll/3rdparty/dxtn/CMakeLists.txt index b399df447b..e2e95fb08c 100644 --- a/dll/3rdparty/dxtn/CMakeLists.txt +++ b/dll/3rdparty/dxtn/CMakeLists.txt @@ -2,15 +2,10 @@ spec2def(dxtn.dll dxtn.spec) add_library(dxtn SHARED - fxt1.c - dxtn.c - wrapper.c - texstore.c + txc_compress_dxtn.c + txc_fetch_dxtn.c ${CMAKE_CURRENT_BINARY_DIR}/dxtn.def) set_entrypoint(dxtn 0) add_importlibs(dxtn msvcrt) -if(NOT MSVC) - add_target_compile_flags(dxtn "-Wno-unused-but-set-variable") -endif() add_cd_file(TARGET dxtn DESTINATION reactos/system32 FOR all) diff --git a/dll/3rdparty/dxtn/dxtn.c b/dll/3rdparty/dxtn/dxtn.c deleted file mode 100644 index e6e5988c00..0000000000 --- a/dll/3rdparty/dxtn/dxtn.c +++ /dev/null @@ -1,757 +0,0 @@ -/* - * DXTn codec - * Version: 1.1 - * - * Copyright (C) 2004 Daniel Borca All Rights Reserved. - * - * this is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2, or (at your option) - * any later version. - * - * this is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with GNU Make; see the file COPYING. If not, write to - * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. - */ - - -#include <stdlib.h> -#include <string.h> - -#include "types.h" -#include "internal.h" -#include "dxtn.h" - - -/***************************************************************************\ - * DXTn encoder - * - * The encoder was built by reversing the decoder, - * and is vaguely based on FXT1 codec. Note that this code - * is merely a proof of concept, since it is highly UNoptimized! -\***************************************************************************/ - - -#define MAX_COMP 4 /* ever needed maximum number of components in texel */ -#define MAX_VECT 4 /* ever needed maximum number of base vectors to find */ -#define N_TEXELS 16 /* number of texels in a block (always 16) */ -#define COLOR565(v) (word)((((v)[RCOMP] & 0xf8) << 8) | (((v)[GCOMP] & 0xfc) << 3) | ((v)[BCOMP] >> 3)) - - -static const int dxtn_color_tlat[2][4] = { - { 0, 2, 3, 1 }, - { 0, 2, 1, 3 } -}; - -static const int dxtn_alpha_tlat[2][8] = { - { 0, 2, 3, 4, 5, 6, 7, 1 }, - { 0, 2, 3, 4, 5, 1, 6, 7 } -}; - - -static void -dxt1_rgb_quantize (dword *cc, const byte *lines[], int comps) -{ - float b, iv[MAX_COMP]; /* interpolation vector */ - - dword hi; /* high doubleword */ - int color0, color1; - int n_vect; - const int n_comp = 3; - int black = 0; - - int minSum = 2000; /* big enough */ - int maxSum = -1; /* small enough */ - int minCol = 0; /* phoudoin: silent compiler! */ - int maxCol = 0; /* phoudoin: silent compiler! */ - - byte input[N_TEXELS][MAX_COMP]; - int i, k, l; - - /* make the whole block opaque */ - /* we will NEVER reference ACOMP of any pixel */ - - /* 4 texels each line */ - for (l = 0; l < 4; l++) { - for (k = 0; k < 4; k++) { - for (i = 0; i < comps; i++) { - input[k + l * 4][i] = *lines[l]++; - } - } - } - - /* Our solution here is to find the darkest and brightest colors in - * the 4x4 tile and use those as the two representative colors. - * There are probably better algorithms to use (histogram-based). - */ - for (k = 0; k < N_TEXELS; k++) { - int sum = 0; - for (i = 0; i < n_comp; i++) { - sum += input[k][i]; - } - if (minSum > sum) { - minSum = sum; - minCol = k; - } - if (maxSum < sum) { - maxSum = sum; - maxCol = k; - } - if (sum == 0) { - black = 1; - } - } - - color0 = COLOR565(input[minCol]); - color1 = COLOR565(input[maxCol]); - - if (color0 == color1) { - /* we'll use 3-vector */ - cc[0] = color0 | (color1 << 16); - hi = black ? -1 : 0; - } else { - if (black && ((color0 == 0) || (color1 == 0))) { - /* we still can use 4-vector */ - black = 0; - } - - if (black ^ (color0 <= color1)) { - int aux; - aux = color0; - color0 = color1; - color1 = aux; - aux = minCol; - minCol = maxCol; - maxCol = aux; - } - n_vect = (color0 <= color1) ? 2 : 3; - - MAKEIVEC(n_vect, n_comp, iv, b, input[minCol], input[maxCol]); - - /* add in texels */ - cc[0] = color0 | (color1 << 16); - hi = 0; - for (k = N_TEXELS - 1; k >= 0; k--) { - int texel = 3; - int sum = 0; - if (black) { - for (i = 0; i < n_comp; i++) { - sum += input[k][i]; - } - } - if (!black || sum) { - /* interpolate color */ - CALCCDOT(texel, n_vect, n_comp, iv, b, input[k]); - texel = dxtn_color_tlat[black][texel]; - } - /* add in texel */ - hi <<= 2; - hi |= texel; - } - } - cc[1] = hi; -} - - -static void -dxt1_rgba_quantize (dword *cc, const byte *lines[], int comps) -{ - float b, iv[MAX_COMP]; /* interpolation vector */ - - dword hi; /* high doubleword */ - int color0, color1; - int n_vect; - const int n_comp = 3; - int transparent = 0; - - int minSum = 2000; /* big enough */ - int maxSum = -1; /* small enough */ - int minCol = 0; /* phoudoin: silent compiler! */ - int maxCol = 0; /* phoudoin: silent compiler! */ - - byte input[N_TEXELS][MAX_COMP]; - int i, k, l; - - if (comps == 3) { - /* make the whole block opaque */ - memset(input, -1, sizeof(input)); - } - - /* 4 texels each line */ - for (l = 0; l < 4; l++) { - for (k = 0; k < 4; k++) { - for (i = 0; i < comps; i++) { - input[k + l * 4][i] = *lines[l]++; - } - } - } - - /* Our solution here is to find the darkest and brightest colors in - * the 4x4 tile and use those as the two representative colors. - * There are probably better algorithms to use (histogram-based). - */ - for (k = 0; k < N_TEXELS; k++) { - int sum = 0; - for (i = 0; i < n_comp; i++) { - sum += input[k][i]; - } - if (minSum > sum) { - minSum = sum; - minCol = k; - } - if (maxSum < sum) { - maxSum = sum; - maxCol = k; - } - if (input[k][ACOMP] < 128) { - transparent = 1; - } - } - - color0 = COLOR565(input[minCol]); - color1 = COLOR565(input[maxCol]); - - if (color0 == color1) { - /* we'll use 3-vector */ - cc[0] = color0 | (color1 << 16); - hi = transparent ? -1 : 0; - } else { - if (transparent ^ (color0 <= color1)) { - int aux; - aux = color0; - color0 = color1; - color1 = aux; - aux = minCol; - minCol = maxCol; - maxCol = aux; - } - n_vect = (color0 <= color1) ? 2 : 3; - - MAKEIVEC(n_vect, n_comp, iv, b, input[minCol], input[maxCol]); - - /* add in texels */ - cc[0] = color0 | (color1 << 16); - hi = 0; - for (k = N_TEXELS - 1; k >= 0; k--) { - int texel = 3; - if (input[k][ACOMP] >= 128) { - /* interpolate color */ - CALCCDOT(texel, n_vect, n_comp, iv, b, input[k]); - texel = dxtn_color_tlat[transparent][texel]; - } - /* add in texel */ - hi <<= 2; - hi |= texel; - } - } - cc[1] = hi; -} - - -static void -dxt3_rgba_quantize (dword *cc, const byte *lines[], int comps) -{ - float b, iv[MAX_COMP]; /* interpolation vector */ - - dword lolo, lohi; /* low quadword: lo dword, hi dword */ - dword hihi; /* high quadword: high dword */ - int color0, color1; - const int n_vect = 3; - const int n_comp = 3; - - int minSum = 2000; /* big enough */ - int maxSum = -1; /* small enough */ - int minCol = 0; /* phoudoin: silent compiler! */ - int maxCol = 0; /* phoudoin: silent compiler! */ - - byte input[N_TEXELS][MAX_COMP]; - int i, k, l; - - if (comps == 3) { - /* make the whole block opaque */ - memset(input, -1, sizeof(input)); - } - - /* 4 texels each line */ - for (l = 0; l < 4; l++) { - for (k = 0; k < 4; k++) { - for (i = 0; i < comps; i++) { - input[k + l * 4][i] = *lines[l]++; - } - } - } - - /* Our solution here is to find the darkest and brightest colors in - * the 4x4 tile and use those as the two representative colors. - * There are probably better algorithms to use (histogram-based). - */ - for (k = 0; k < N_TEXELS; k++) { - int sum = 0; - for (i = 0; i < n_comp; i++) { - sum += input[k][i]; - } - if (minSum > sum) { - minSum = sum; - minCol = k; - } - if (maxSum < sum) { - maxSum = sum; - maxCol = k; - } - } - - /* add in alphas */ - lolo = lohi = 0; - for (k = N_TEXELS - 1; k >= N_TEXELS / 2; k--) { - /* add in alpha */ - lohi <<= 4; - lohi |= input[k][ACOMP] >> 4; - } - cc[1] = lohi; - for (; k >= 0; k--) { - /* add in alpha */ - lolo <<= 4; - lolo |= input[k][ACOMP] >> 4; - } - cc[0] = lolo; - - color0 = COLOR565(input[minCol]); - color1 = COLOR565(input[maxCol]); - cc[2] = color0 | (color1 << 16); - - hihi = 0; - if (color0 != color1) { - MAKEIVEC(n_vect, n_comp, iv, b, input[minCol], input[maxCol]); - - /* add in texels */ - for (k = N_TEXELS - 1; k >= 0; k--) { - int texel; - /* interpolate color */ - CALCCDOT(texel, n_vect, n_comp, iv, b, input[k]); - texel = dxtn_color_tlat[0][texel]; - /* add in texel */ - hihi <<= 2; - hihi |= texel; - } - } - cc[3] = hihi; -} - - -static void -dxt5_rgba_quantize (dword *cc, const byte *lines[], int comps) -{ - float b, iv[MAX_COMP]; /* interpolation vector */ - - qword lo; /* low quadword */ - dword hihi; /* high quadword: high dword */ - int color0, color1; - const int n_vect = 3; - const int n_comp = 3; - - int minSum = 2000; /* big enough */ - int maxSum = -1; /* small enough */ - int minCol = 0; /* phoudoin: silent compiler! */ - int maxCol = 0; /* phoudoin: silent compiler! */ - int alpha0 = 2000; /* big enough */ - int alpha1 = -1; /* small enough */ - int anyZero = 0, anyOne = 0; - int a_vect; - - byte input[N_TEXELS][MAX_COMP]; - int i, k, l; - - if (comps == 3) { - /* make the whole block opaque */ - memset(input, -1, sizeof(input)); - } - - /* 4 texels each line */ - for (l = 0; l < 4; l++) { - for (k = 0; k < 4; k++) { - for (i = 0; i < comps; i++) { - input[k + l * 4][i] = *lines[l]++; - } - } - } - - /* Our solution here is to find the darkest and brightest colors in - * the 4x4 tile and use those as the two representative colors. - * There are probably better algorithms to use (histogram-based). - */ - for (k = 0; k < N_TEXELS; k++) { - int sum = 0; - for (i = 0; i < n_comp; i++) { - sum += input[k][i]; - } - if (minSum > sum) { - minSum = sum; - minCol = k; - } - if (maxSum < sum) { - maxSum = sum; - maxCol = k; - } - if (alpha0 > input[k][ACOMP]) { - alpha0 = input[k][ACOMP]; - } - if (alpha1 < input[k][ACOMP]) { - alpha1 = input[k][ACOMP]; - } - if (input[k][ACOMP] == 0) { - anyZero = 1; - } - if (input[k][ACOMP] == 255) { - anyOne = 1; - } - } - - /* add in alphas */ - if (alpha0 == alpha1) { - /* we'll use 6-vector */ - cc[0] = alpha0 | (alpha1 << 8); - cc[1] = 0; - } else { - if (anyZero && ((alpha0 == 0) || (alpha1 == 0))) { - /* we still might use 8-vector */ - anyZero = 0; - } - if (anyOne && ((alpha0 == 255) || (alpha1 == 255))) { - /* we still might use 8-vector */ - anyOne = 0; - } - if ((anyZero | anyOne) ^ (alpha0 <= alpha1)) { - int aux; - aux = alpha0; - alpha0 = alpha1; - alpha1 = aux; - } - a_vect = (alpha0 <= alpha1) ? 5 : 7; - - /* compute interpolation vector */ - iv[ACOMP] = (float)a_vect / (alpha1 - alpha0); - b = -iv[ACOMP] * alpha0 + 0.5F; - - /* add in alphas */ - Q_MOV32(lo, 0); - for (k = N_TEXELS - 1; k >= 0; k--) { - int texel = -1; - if (anyZero | anyOne) { - if (input[k][ACOMP] == 0) { - texel = 6; - } else if (input[k][ACOMP] == 255) { - texel = 7; - } - } - /* interpolate alpha */ - if (texel == -1) { - float dot = input[k][ACOMP] * iv[ACOMP]; - texel = (int)(dot + b); -#if SAFECDOT - if (texel < 0) { - texel = 0; - } else if (texel > a_vect) { - texel = a_vect; - } -#endif - texel = dxtn_alpha_tlat[anyZero | anyOne][texel]; - } - /* add in texel */ - Q_SHL(lo, 3); - Q_OR32(lo, texel); - } - Q_SHL(lo, 16); - Q_OR32(lo, alpha0 | (alpha1 << 8)); - ((qword *)cc)[0] = lo; - } - - color0 = COLOR565(input[minCol]); - color1 = COLOR565(input[maxCol]); - cc[2] = color0 | (color1 << 16); - - hihi = 0; - if (color0 != color1) { - MAKEIVEC(n_vect, n_comp, iv, b, input[minCol], input[maxCol]); - - /* add in texels */ - for (k = N_TEXELS - 1; k >= 0; k--) { - int texel; - /* interpolate color */ - CALCCDOT(texel, n_vect, n_comp, iv, b, input[k]); - texel = dxtn_color_tlat[0][texel]; - /* add in texel */ - hihi <<= 2; - hihi |= texel; - } - } - cc[3] = hihi; -} - - -#define ENCODER(dxtn, n) \ -int TAPIENTRY \ -dxtn##_encode (int width, int height, int comps, \ - const void *source, int srcRowStride, \ - void *dest, int destRowStride) \ -{ \ - int x, y; \ - const byte *data; \ - dword *encoded = (dword *)dest; \ - void *newSource = NULL; \ - \ - /* Replicate image if width is not M4 or height is not M4 */ \ - if ((width & 3) | (height & 3)) { \ - int newWidth = (width + 3) & ~3; \ - int newHeight = (height + 3) & ~3; \ - newSource = malloc(comps * newWidth * newHeight * sizeof(byte *));\ - _mesa_upscale_teximage2d(width, height, newWidth, newHeight, \ - comps, (const byte *)source, \ - srcRowStride, (byte *)newSource); \ - source = newSource; \ - width = newWidth; \ - height = newHeight; \ - srcRowStride = comps * newWidth; \ - } \ - \ - data = (const byte *)source; \ - destRowStride = (destRowStride - width * n) / 4; \ - for (y = 0; y < height; y += 4) { \ - unsigned int offs = 0 + (y + 0) * srcRowStride; \ - for (x = 0; x < width; x += 4) { \ - const byte *lines[4]; \ - lines[0] = &data[offs]; \ - lines[1] = lines[0] + srcRowStride; \ - lines[2] = lines[1] + srcRowStride; \ - lines[3] = lines[2] + srcRowStride; \ - offs += 4 * comps; \ - dxtn##_quantize(encoded, lines, comps); \ - /* 4x4 block */ \ - encoded += n; \ - } \ - encoded += destRowStride; \ - } \ - \ - if (newSource != NULL) { \ - free(newSource); \ - } \ - \ - return 0; \ -} - -ENCODER(dxt1_rgb, 2) -ENCODER(dxt1_rgba, 2) -ENCODER(dxt3_rgba, 4) -ENCODER(dxt5_rgba, 4) - - -/***************************************************************************\ - * DXTn decoder - * - * The decoder is based on GL_EXT_texture_compression_s3tc - * specification and serves as a concept for the encoder. -\***************************************************************************/ - - -/* lookup table for scaling 4 bit colors up to 8 bits */ -static const byte _rgb_scale_4[] = { - 0, 17, 34, 51, 68, 85, 102, 119, - 136, 153, 170, 187, 204, 221, 238, 255 -}; - -/* lookup table for scaling 5 bit colors up to 8 bits */ -static const byte _rgb_scale_5[] = { - 0, 8, 16, 25, 33, 41, 49, 58, - 66, 74, 82, 90, 99, 107, 115, 123, - 132, 140, 148, 156, 165, 173, 181, 189, - 197, 206, 214, 222, 230, 239, 247, 255 -}; - -/* lookup table for scaling 6 bit colors up to 8 bits */ -static const byte _rgb_scale_6[] = { - 0, 4, 8, 12, 16, 20, 24, 28, - 32, 36, 40, 45, 49, 53, 57, 61, - 65, 69, 73, 77, 81, 85, 89, 93, - 97, 101, 105, 109, 113, 117, 121, 125, - 130, 134, 138, 142, 146, 150, 154, 158, - 162, 166, 170, 174, 178, 182, 186, 190, - 194, 198, 202, 206, 210, 215, 219, 223, - 227, 231, 235, 239, 243, 247, 251, 255 -}; - - -#define CC_SEL(cc, which) (((dword *)(cc))[(which) / 32] >> ((which) & 31)) -#define UP4(c) _rgb_scale_4[(c) & 15] -#define UP5(c) _rgb_scale_5[(c) & 31] -#define UP6(c) _rgb_scale_6[(c) & 63] -#define ZERO_4UBV(v) *((dword *)(v)) = 0 - - -void TAPIENTRY -dxt1_rgb_decode_1 (const void *texture, int stride, - int i, int j, byte *rgba) -{ - const byte *src = (const byte *)texture - + ((j / 4) * ((stride + 3) / 4) + i / 4) * 8; - const int code = (src[4 + (j & 3)] >> ((i & 3) * 2)) & 0x3; - if (code == 0) { - rgba[RCOMP] = UP5(CC_SEL(src, 11)); - rgba[GCOMP] = UP6(CC_SEL(src, 5)); - rgba[BCOMP] = UP5(CC_SEL(src, 0)); - } else if (code == 1) { - rgba[RCOMP] = UP5(CC_SEL(src, 27)); - rgba[GCOMP] = UP6(CC_SEL(src, 21)); - rgba[BCOMP] = UP5(CC_SEL(src, 16)); - } else { - const word col0 = src[0] | (src[1] << 8); - const word col1 = src[2] | (src[3] << 8); - if (col0 > col1) { - if (code == 2) { - rgba[RCOMP] = (UP5(col0 >> 11) * 2 + UP5(col1 >> 11)) / 3; - rgba[GCOMP] = (UP6(col0 >> 5) * 2 + UP6(col1 >> 5)) / 3; - rgba[BCOMP] = (UP5(col0 ) * 2 + UP5(col1 )) / 3; - } else { - rgba[RCOMP] = (UP5(col0 >> 11) + 2 * UP5(col1 >> 11)) / 3; - rgba[GCOMP] = (UP6(col0 >> 5) + 2 * UP6(col1 >> 5)) / 3; - rgba[BCOMP] = (UP5(col0 ) + 2 * UP5(col1 )) / 3; - } - } else { - if (code == 2) { - rgba[RCOMP] = (UP5(col0 >> 11) + UP5(col1 >> 11)) / 2; - rgba[GCOMP] = (UP6(col0 >> 5) + UP6(col1 >> 5)) / 2; - rgba[BCOMP] = (UP5(col0 ) + UP5(col1 )) / 2; - } else { - ZERO_4UBV(rgba); - } - } - } - rgba[ACOMP] = 255; -} - - -void TAPIENTRY -dxt1_rgba_decode_1 (const void *texture, int stride, - int i, int j, byte *rgba) -{ - /* Same as rgb_dxt1 above, except alpha=0 if col0<=col1 and code=3. */ - const byte *src = (const byte *)texture - + ((j / 4) * ((stride + 3) / 4) + i / 4) * 8; - const int code = (src[4 + (j & 3)] >> ((i & 3) * 2)) & 0x3; - if (code == 0) { - rgba[RCOMP] = UP5(CC_SEL(src, 11)); - rgba[GCOMP] = UP6(CC_SEL(src, 5)); - rgba[BCOMP] = UP5(CC_SEL(src, 0)); - rgba[ACOMP] = 255; - } else if (code == 1) { - rgba[RCOMP] = UP5(CC_SEL(src, 27)); - rgba[GCOMP] = UP6(CC_SEL(src, 21)); - rgba[BCOMP] = UP5(CC_SEL(src, 16)); - rgba[ACOMP] = 255; - } else { - const word col0 = src[0] | (src[1] << 8); - const word col1 = src[2] | (src[3] << 8); - if (col0 > col1) { - if (code == 2) { - rgba[RCOMP] = (UP5(col0 >> 11) * 2 + UP5(col1 >> 11)) / 3; - rgba[GCOMP] = (UP6(col0 >> 5) * 2 + UP6(col1 >> 5)) / 3; - rgba[BCOMP] = (UP5(col0 ) * 2 + UP5(col1 )) / 3; - } else { - rgba[RCOMP] = (UP5(col0 >> 11) + 2 * UP5(col1 >> 11)) / 3; - rgba[GCOMP] = (UP6(col0 >> 5) + 2 * UP6(col1 >> 5)) / 3; - rgba[BCOMP] = (UP5(col0 ) + 2 * UP5(col1 )) / 3; - } - rgba[ACOMP] = 255; - } else { - if (code == 2) { - rgba[RCOMP] = (UP5(col0 >> 11) + UP5(col1 >> 11)) / 2; - rgba[GCOMP] = (UP6(col0 >> 5) + UP6(col1 >> 5)) / 2; - rgba[BCOMP] = (UP5(col0 ) + UP5(col1 )) / 2; - rgba[ACOMP] = 255; - } else { - ZERO_4UBV(rgba); - } - } - } -} - - -void TAPIENTRY -dxt3_rgba_decode_1 (const void *texture, int stride, - int i, int j, byte *rgba) -{ - const byte *src = (const byte *)texture - + ((j / 4) * ((stride + 3) / 4) + i / 4) * 16; - const int code = (src[12 + (j & 3)] >> ((i & 3) * 2)) & 0x3; - const dword *cc = (const dword *)(src + 8); - if (code == 0) { - rgba[RCOMP] = UP5(CC_SEL(cc, 11)); - rgba[GCOMP] = UP6(CC_SEL(cc, 5)); - rgba[BCOMP] = UP5(CC_SEL(cc, 0)); - } else if (code == 1) { - rgba[RCOMP] = UP5(CC_SEL(cc, 27)); - rgba[GCOMP] = UP6(CC_SEL(cc, 21)); - rgba[BCOMP] = UP5(CC_SEL(cc, 16)); - } else if (code == 2) { - /* (col0 * (4 - code) + col1 * (code - 1)) / 3 */ - rgba[RCOMP] = (UP5(CC_SEL(cc, 11)) * 2 + UP5(CC_SEL(cc, 27))) / 3; - rgba[GCOMP] = (UP6(CC_SEL(cc, 5)) * 2 + UP6(CC_SEL(cc, 21))) / 3; - rgba[BCOMP] = (UP5(CC_SEL(cc, 0)) * 2 + UP5(CC_SEL(cc, 16))) / 3; - } else { - rgba[RCOMP] = (UP5(CC_SEL(cc, 11)) + 2 * UP5(CC_SEL(cc, 27))) / 3; - rgba[GCOMP] = (UP6(CC_SEL(cc, 5)) + 2 * UP6(CC_SEL(cc, 21))) / 3; - rgba[BCOMP] = (UP5(CC_SEL(cc, 0)) + 2 * UP5(CC_SEL(cc, 16))) / 3; - } - rgba[ACOMP] = UP4(src[((j & 3) * 4 + (i & 3)) / 2] >> ((i & 1) * 4)); -} - - -void TAPIENTRY -dxt5_rgba_decode_1 (const void *texture, int stride, - int i, int j, byte *rgba) -{ - const byte *src = (const byte *)texture - + ((j / 4) * ((stride + 3) / 4) + i / 4) * 16; - const int code = (src[12 + (j & 3)] >> ((i & 3) * 2)) & 0x3; - const dword *cc = (const dword *)(src + 8); - const byte alpha0 = src[0]; - const byte alpha1 = src[1]; - const int alphaShift = (((j & 3) * 4) + (i & 3)) * 3 + 16; - const int acode = ((alphaShift == 31) - ? CC_SEL(src + 2, alphaShift - 16) - : CC_SEL(src, alphaShift)) & 0x7; - if (code == 0) { - rgba[RCOMP] = UP5(CC_SEL(cc, 11)); - rgba[GCOMP] = UP6(CC_SEL(cc, 5)); - rgba[BCOMP] = UP5(CC_SEL(cc, 0)); - } else if (code == 1) { - rgba[RCOMP] = UP5(CC_SEL(cc, 27)); - rgba[GCOMP] = UP6(CC_SEL(cc, 21)); - rgba[BCOMP] = UP5(CC_SEL(cc, 16)); - } else if (code == 2) { - /* (col0 * (4 - code) + col1 * (code - 1)) / 3 */ - rgba[RCOMP] = (UP5(CC_SEL(cc, 11)) * 2 + UP5(CC_SEL(cc, 27))) / 3; - rgba[GCOMP] = (UP6(CC_SEL(cc, 5)) * 2 + UP6(CC_SEL(cc, 21))) / 3; - rgba[BCOMP] = (UP5(CC_SEL(cc, 0)) * 2 + UP5(CC_SEL(cc, 16))) / 3; - } else { - rgba[RCOMP] = (UP5(CC_SEL(cc, 11)) + 2 * UP5(CC_SEL(cc, 27))) / 3; - rgba[GCOMP] = (UP6(CC_SEL(cc, 5)) + 2 * UP6(CC_SEL(cc, 21))) / 3; - rgba[BCOMP] = (UP5(CC_SEL(cc, 0)) + 2 * UP5(CC_SEL(cc, 16))) / 3; - } - if (acode == 0) { - rgba[ACOMP] = alpha0; - } else if (acode == 1) { - rgba[ACOMP] = alpha1; - } else if (alpha0 > alpha1) { - rgba[ACOMP] = ((8 - acode) * alpha0 + (acode - 1) * alpha1) / 7; - } else if (acode == 6) { - rgba[ACOMP] = 0; - } else if (acode == 7) { - rgba[ACOMP] = 255; - } else { - rgba[ACOMP] = ((6 - acode) * alpha0 + (acode - 1) * alpha1) / 5; - } -} diff --git a/dll/3rdparty/dxtn/dxtn.h b/dll/3rdparty/dxtn/dxtn.h deleted file mode 100644 index 4078fd9f92..0000000000 --- a/dll/3rdparty/dxtn/dxtn.h +++ /dev/null @@ -1,62 +0,0 @@ -/* - * DXTn codec - * Version: 1.1 - * - * Copyright (C) 2004 Daniel Borca All Rights Reserved. - * - * this is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2, or (at your option) - * any later version. - * - * this is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with GNU Make; see the file COPYING. If not, write to - * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. - */ - - -#ifndef DXTN_H_included -#define DXTN_H_included - -TAPI int TAPIENTRY -dxt1_rgb_encode (int width, int height, int comps, - const void *source, int srcRowStride, - void *dest, int destRowStride); - -TAPI int TAPIENTRY -dxt1_rgba_encode (int width, int height, int comps, - const void *source, int srcRowStride, - void *dest, int destRowStride); - -TAPI int TAPIENTRY -dxt3_rgba_encode (int width, int height, int comps, - const void *source, int srcRowStride, - void *dest, int destRowStride); - -TAPI int TAPIENTRY -dxt5_rgba_encode (int width, int height, int comps, - const void *source, int srcRowStride, - void *dest, int destRowStride); - -TAPI void TAPIENTRY -dxt1_rgb_decode_1 (const void *texture, int stride /* in pixels */, - int i, int j, byte *rgba); - -TAPI void TAPIENTRY -dxt1_rgba_decode_1 (const void *texture, int stride /* in pixels */, - int i, int j, byte *rgba); - -TAPI void TAPIENTRY -dxt3_rgba_decode_1 (const void *texture, int stride /* in pixels */, - int i, int j, byte *rgba); - -TAPI void TAPIENTRY -dxt5_rgba_decode_1 (const void *texture, int stride /* in pixels */, - int i, int j, byte *rgba); - -#endif diff --git a/dll/3rdparty/dxtn/dxtn.spec b/dll/3rdparty/dxtn/dxtn.spec index 103f96916e..d629b79edc 100644 --- a/dll/3rdparty/dxtn/dxtn.spec +++ b/dll/3rdparty/dxtn/dxtn.spec @@ -1,14 +1,4 @@ -@ stdcall dxt1_rgb_encode(long long long ptr long ptr long) -@ stdcall dxt1_rgba_encode(long long long ptr long ptr long) -@ stdcall dxt3_rgba_encode(long long long ptr long ptr long) -@ stdcall dxt5_rgba_encode(long long long ptr long ptr long) -@ stdcall dxt1_rgba_decode_1(ptr long long long long) -@ stdcall dxt3_rgba_decode_1(ptr long long long long) -@ stdcall dxt5_rgba_decode_1(ptr long long long long) -@ stdcall fxt1_encode(long long long ptr long ptr long) -@ stdcall fxt1_decode_1(ptr long long long long) -@ stdcall fetch_2d_texel_rgb_dxt1(long ptr long long long) -@ stdcall fetch_2d_texel_rgba_dxt1(long ptr long long long) -@ stdcall fetch_2d_texel_rgba_dxt3(long ptr long long long) -@ stdcall fetch_2d_texel_rgba_dxt5(long ptr long long long) -@ stdcall tx_compress_dxtn(long long long ptr long ptr long) +@ cdecl fetch_2d_texel_rgba_dxt1(long ptr long long ptr) +@ cdecl fetch_2d_texel_rgba_dxt3(long ptr long long ptr) +@ cdecl fetch_2d_texel_rgba_dxt5(long ptr long long ptr) +@ cdecl tx_compress_dxtn(long long long ptr long ptr long) diff --git a/dll/3rdparty/dxtn/fxt1.c b/dll/3rdparty/dxtn/fxt1.c deleted file mode 100644 index c528ee775f..0000000000 --- a/dll/3rdparty/dxtn/fxt1.c +++ /dev/null @@ -1,1369 +0,0 @@ -/* - * FXT1 codec - * Version: 1.1 - * - * Copyright (C) 2004 Daniel Borca All Rights Reserved. - * - * Permission is hereby granted, free of charge, to any person obtaining a - * copy of this software and associated documentation files (the "Software"), - * to deal in the Software without restriction, including without limitation - * the rights to use, copy, modify, merge, publish, distribute, sublicense, - * and/or sell copies of the Software, and to permit persons to whom the - * Software is furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included - * in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS - * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL - * DANIEL BORCA BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN - * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - */ - - -#include <stdlib.h> -#include <string.h> - -#include "types.h" -#include "internal.h" -#include "fxt1.h" - - -/***************************************************************************\ - * FXT1 encoder - * - * The encoder was built by reversing the decoder, - * and is vaguely based on Texus2 by 3dfx. Note that this code - * is merely a proof of concept, since it is highly UNoptimized; - * moreover, it is sub-optimal due to initial conditions passed - * to Lloyd's algorithm (the interpolation modes are even worse). -\***************************************************************************/ - - -#define MAX_COMP 4 /* ever needed maximum number of components in texel */ -#define MAX_VECT 4 /* ever needed maximum number of base vectors to find */ -#define N_TEXELS 32 /* number of texels in a block (always 32) */ -#define LL_N_REP 50 /* number of iterations in lloyd's vq */ -#define LL_RMS_D 10 /* fault tolerance (maximum delta) */ -#define LL_RMS_E 255 /* fault tolerance (maximum error) */ -#define ALPHA_TS 2 /* alpha threshold: (255 - ALPHA_TS) deemed opaque */ -#define ISTBLACK(v) (*((dword *)(v)) == 0) -#define COPY_4UBV(DST, SRC) *((dword *)(DST)) = *((dword *)(SRC)) - - -static int -fxt1_bestcol (float vec[][MAX_COMP], int nv, - byte input[MAX_COMP], int nc) -{ - int i, j, best = -1; - float err = 1e9; /* big enough */ - - for (j = 0; j < nv; j++) { - float e = 0.0F; - for (i = 0; i < nc; i++) { - e += (vec[j][i] - input[i]) * (vec[j][i] - input[i]); - } - if (e < err) { - err = e; - best = j; - } - } - - return best; -} - - -static int -fxt1_worst (float vec[MAX_COMP], - byte input[N_TEXELS][MAX_COMP], int nc, int n) -{ - int i, k, worst = -1; - float err = -1.0F; /* small enough */ - - for (k = 0; k < n; k++) { - float e = 0.0F; - for (i = 0; i < nc; i++) { - e += (vec[i] - input[k][i]) * (vec[i] - input[k][i]); - } - if (e > err) { - err = e; - worst = k; - } - } - - return worst; -} - - -static int -fxt1_variance (double variance[MAX_COMP], - byte input[N_TEXELS][MAX_COMP], int nc, int n) -{ - int i, k, best = 0; - dword sx, sx2; - double var, maxvar = -1; /* small enough */ - double teenth = 1.0 / n; - - for (i = 0; i < nc; i++) { - sx = sx2 = 0; - for (k = 0; k < n; k++) { - int t = input[k][i]; - sx += t; - sx2 += t * t; - } - var = sx2 * teenth - sx * sx * teenth * teenth; - if (maxvar < var) { - maxvar = var; - best = i; - } - if (variance) { - variance[i] = var; - } - } - - return best; -} - - -static int -fxt1_choose (float vec[][MAX_COMP], int nv, - byte input[N_TEXELS][MAX_COMP], int nc, int n) -{ -#if 0 - /* Choose colors from a grid. - */ - int i, j; - - for (j = 0; j < nv; j++) { - int m = j * (n - 1) / (nv - 1); - for (i = 0; i < nc; i++) { - vec[j][i] = input[m][i]; - } - } -#else - /* Our solution here is to find the darkest and brightest colors in - * the 8x4 tile and use those as the two representative colors. - * There are probably better algorithms to use (histogram-based). - */ - int i, j, k; - int minSum = 2000; /* big enough */ - int maxSum = -1; /* small enough */ - int minCol = 0; /* phoudoin: silent compiler! */ - int maxCol = 0; /* phoudoin: silent compiler! */ - - struct { - int flag; - dword key; - int freq; - int idx; - } hist[N_TEXELS]; - int lenh = 0; - - memset(hist, 0, sizeof(hist)); - - for (k = 0; k < n; k++) { - int l; - dword key = 0; - int sum = 0; - for (i = 0; i < nc; i++) { - key <<= 8; - key |= input[k][i]; - sum += input[k][i]; - } - for (l = 0; l < n; l++) { - if (!hist[l].flag) { - /* alloc new slot */ - hist[l].flag = !0; - hist[l].key = key; - hist[l].freq = 1; - hist[l].idx = k; - lenh = l + 1; - break; - } else if (hist[l].key == key) { - hist[l].freq++; - break; - } - } - if (minSum > sum) { - minSum = sum; - minCol = k; - } - if (maxSum < sum) { - maxSum = sum; - maxCol = k; - } - } - - if (lenh <= nv) { - for (j = 0; j < lenh; j++) { - for (i = 0; i < nc; i++) { - vec[j][i] = (float)input[hist[j].idx][i]; - } - } - for (; j < nv; j++) { - for (i = 0; i < nc; i++) { - vec[j][i] = vec[0][i]; - } - } - return 0; - } - - for (j = 0; j < nv; j++) { - for (i = 0; i < nc; i++) { - vec[j][i] = ((nv - 1 - j) * input[minCol][i] + j * input[maxCol][i] + (nv - 1) / 2) / (float)(nv - 1); - } - } -#endif - - return !0; -} - - -static int -fxt1_lloyd (float vec[][MAX_COMP], int nv, - byte input[N_TEXELS][MAX_COMP], int nc, int n) -{ - /* Use the generalized lloyd's algorithm for VQ: - * find 4 color vectors. - * - * for each sample color - * sort to nearest vector. - * - * replace each vector with the centroid of it's matching colors. - * - * repeat until RMS doesn't improve. - * - * if a color vector has no samples, or becomes the same as another - * vector, replace it with the color which is farthest from a sample. - * - * vec[][MAX_COMP] initial vectors and resulting colors - * nv number of resulting colors required - * input[N_TEXELS][MAX_COMP] input texels - * nc number of components in input / vec - * n number of input samples - */ - - int sum[MAX_VECT][MAX_COMP]; /* used to accumulate closest texels */ - int cnt[MAX_VECT]; /* how many times a certain vector was chosen */ - float error, lasterror = 1e9; - - int i, j, k, rep; - - /* the quantizer */ - for (rep = 0; rep < LL_N_REP; rep++) { - /* reset sums & counters */ - for (j = 0; j < nv; j++) { - for (i = 0; i < nc; i++) { - sum[j][i] = 0; - } - cnt[j] = 0; - } - error = 0; - - /* scan whole block */ - for (k = 0; k < n; k++) { -#if 1 - int best = -1; - float err = 1e9; /* big enough */ - /* determine best vector */ - for (j = 0; j < nv; j++) { - float e = (vec[j][0] - input[k][0]) * (vec[j][0] - input[k][0]) + - (vec[j][1] - input[k][1]) * (vec[j][1] - input[k][1]) + - (vec[j][2] - input[k][2]) * (vec[j][2] - input[k][2]); - if (nc == 4) { - e += (vec[j][3] - input[k][3]) * (vec[j][3] - input[k][3]); - } - if (e < err) { - err = e; - best = j; - } - } -#else - int best = fxt1_bestcol(vec, nv, input[k], nc, &err); -#endif - /* add in closest color */ - for (i = 0; i < nc; i++) { - sum[best][i] += input[k][i]; - } - /* mark this vector as used */ - cnt[best]++; - /* accumulate error */ - error += err; - } - - /* check RMS */ - if ((error < LL_RMS_E) || - ((error < lasterror) && ((lasterror - error) < LL_RMS_D))) { - return !0; /* good match */ - } - lasterror = error; - - /* move each vector to the barycenter of its closest colors */ - for (j = 0; j < nv; j++) { - if (cnt[j]) { - float div = 1.0F / cnt[j]; - for (i = 0; i < nc; i++) { - vec[j][i] = div * sum[j][i]; - } - } else { - /* this vec has no samples or is identical with a previous vec */ - int worst = fxt1_worst(vec[j], input, nc, n); - for (i = 0; i < nc; i++) { - vec[j][i] = input[worst][i]; - } - } - } - } - - return 0; /* could not converge fast enough */ -} - - -static void -fxt1_quantize_CHROMA (dword *cc, - byte input[N_TEXELS][MAX_COMP]) -{ - const int n_vect = 4; /* 4 base vectors to find */ - const int n_comp = 3; /* 3 components: R, G, B */ - float vec[MAX_VECT][MAX_COMP]; - int i, j, k; - qword hi; /* high quadword */ - dword lohi, lolo; /* low quadword: hi dword, lo dword */ - - if (fxt1_choose(vec, n_vect, input, n_comp, N_TEXELS) != 0) { - fxt1_lloyd(vec, n_vect, input, n_comp, N_TEXELS); - } - - Q_MOV32(hi, 4); /* cc-chroma = "010" + unused bit */ - for (j = n_vect - 1; j >= 0; j--) { - for (i = 0; i < n_comp; i++) { - /* add in colors */ - Q_SHL(hi, 5); - Q_OR32(hi, (dword)(vec[j][i] / 8.0F)); - } - } - ((qword *)cc)[1] = hi; - - lohi = lolo = 0; - /* right microtile */ - for (k = N_TEXELS - 1; k >= N_TEXELS / 2; k--) { - lohi <<= 2; - lohi |= fxt1_bestcol(vec, n_vect, input[k], n_comp); - } - /* left microtile */ - for (; k >= 0; k--) { - lolo <<= 2; - lolo |= fxt1_bestcol(vec, n_vect, input[k], n_comp); - } - cc[1] = lohi; - cc[0] = lolo; -} - - -static void -fxt1_quantize_ALPHA0 (dword *cc, - byte input[N_TEXELS][MAX_COMP], - byte reord[N_TEXELS][MAX_COMP], int n) -{ - const int n_vect = 3; /* 3 base vectors to find */ - const int n_comp = 4; /* 4 components: R, G, B, A */ - float vec[MAX_VECT][MAX_COMP]; - int i, j, k; - qword hi; /* high quadword */ - dword lohi, lolo; /* low quadword: hi dword, lo dword */ - - /* the last vector indicates zero */ - for (i = 0; i < n_comp; i++) { - vec[n_vect][i] = 0; - } - - /* the first n texels in reord are guaranteed to be non-zero */ - if (fxt1_choose(vec, n_vect, reord, n_comp, n) != 0) { - fxt1_lloyd(vec, n_vect, reord, n_comp, n); - } - - Q_MOV32(hi, 6); /* alpha = "011" + lerp = 0 */ - for (j = n_vect - 1; j >= 0; j--) { - /* add in alphas */ - Q_SHL(hi, 5); - Q_OR32(hi, (dword)(vec[j][ACOMP] / 8.0F)); - } - for (j = n_vect - 1; j >= 0; j--) { - for (i = 0; i < n_comp - 1; i++) { - /* add in colors */ - Q_SHL(hi, 5); - Q_OR32(hi, (dword)(vec[j][i] / 8.0F)); - } - } - ((qword *)cc)[1] = hi; - - lohi = lolo = 0; - /* right microtile */ - for (k = N_TEXELS - 1; k >= N_TEXELS / 2; k--) { - lohi <<= 2; - lohi |= fxt1_bestcol(vec, n_vect + 1, input[k], n_comp); - } - /* left microtile */ - for (; k >= 0; k--) { - lolo <<= 2; - lolo |= fxt1_bestcol(vec, n_vect + 1, input[k], n_comp); - } - cc[1] = lohi; - cc[0] = lolo; -} - - -static void -fxt1_quantize_ALPHA1 (dword *cc, - byte input[N_TEXELS][MAX_COMP]) -{ - const int n_vect = 3; /* highest vector number in each microtile */ - const int n_comp = 4; /* 4 components: R, G, B, A */ - float vec[1 + 1 + 1][MAX_COMP]; /* 1.5 extrema for each sub-block */ - float b, iv[MAX_COMP]; /* interpolation vector */ - int i, j, k; - qword hi; /* high quadword */ - dword lohi, lolo; /* low quadword: hi dword, lo dword */ - - int minSum; - int maxSum; - int minColL = 0, maxColL = 0; - int minColR = 0, maxColR = 0; - int sumL = 0, sumR = 0; - - /* Our solution here is to find the darkest and brightest colors in - * the 4x4 tile and use those as the two representative colors. - * There are probably better algorithms to use (histogram-based). - */ - minSum = 2000; /* big enough */ - maxSum = -1; /* small enough */ - for (k = 0; k < N_TEXELS / 2; k++) { - int sum = 0; - for (i = 0; i < n_comp; i++) { - sum += input[k][i]; - } - if (minSum > sum) { - minSum = sum; - minColL = k; - } - if (maxSum < sum) { - maxSum = sum; - maxColL = k; - } - sumL += sum; - } - minSum = 2000; /* big enough */ - maxSum = -1; /* small enough */ - for (; k < N_TEXELS; k++) { - int sum = 0; - for (i = 0; i < n_comp; i++) { - sum += input[k][i]; - } - if (minSum > sum) { - minSum = sum; - minColR = k; - } - if (maxSum < sum) { - maxSum = sum; - maxColR = k; - } - sumR += sum; - } - - /* choose the common vector (yuck!) */ - { - int j1, j2; - int v1 = 0, v2 = 0; - float err = 1e9; /* big enough */ - float tv[2 * 2][MAX_COMP]; /* 2 extrema for each sub-block */ - for (i = 0; i < n_comp; i++) { - tv[0][i] = input[minColL][i]; - tv[1][i] = input[maxColL][i]; - tv[2][i] = input[minColR][i]; - tv[3][i] = input[maxColR][i]; - } - for (j1 = 0; j1 < 2; j1++) { - for (j2 = 2; j2 < 4; j2++) { - float e = 0.0F; - for (i = 0; i < n_comp; i++) { - e += (tv[j1][i] - tv[j2][i]) * (tv[j1][i] - tv[j2][i]); - } - if (e < err) { - err = e; - v1 = j1; - v2 = j2; - } - } - } - for (i = 0; i < n_comp; i++) { - vec[0][i] = tv[1 - v1][i]; - vec[1][i] = (tv[v1][i] * sumL + tv[v2][i] * sumR) / (sumL + sumR); - vec[2][i] = tv[5 - v2][i]; - } - } - - /* left microtile */ - cc[0] = 0; - if (minColL != maxColL) { - /* compute interpolation vector */ - MAKEIVEC(n_vect, n_comp, iv, b, vec[0], vec[1]); - - /* add in texels */ - lolo = 0; - for (k = N_TEXELS / 2 - 1; k >= 0; k--) { - int texel; - /* interpolate color */ - CALCCDOT(texel, n_vect, n_comp, iv, b, input[k]); - /* add in texel */ - lolo <<= 2; - lolo |= texel; - } - - cc[0] = lolo; - } - - /* right microtile */ - cc[1] = 0; - if (minColR != maxColR) { - /* compute interpolation vector */ - MAKEIVEC(n_vect, n_comp, iv, b, vec[2], vec[1]); - - /* add in texels */ - lohi = 0; - for (k = N_TEXELS - 1; k >= N_TEXELS / 2; k--) { - int texel; - /* interpolate color */ - CALCCDOT(texel, n_vect, n_comp, iv, b, input[k]); - /* add in texel */ - lohi <<= 2; - lohi |= texel; - } - - cc[1] = lohi; - } - - Q_MOV32(hi, 7); /* alpha = "011" + lerp = 1 */ - for (j = n_vect - 1; j >= 0; j--) { - /* add in alphas */ - Q_SHL(hi, 5); - Q_OR32(hi, (dword)(vec[j][ACOMP] / 8.0F)); - } - for (j = n_vect - 1; j >= 0; j--) { - for (i = 0; i < n_comp - 1; i++) { - /* add in colors */ - Q_SHL(hi, 5); - Q_OR32(hi, (dword)(vec[j][i] / 8.0F)); - } - } - ((qword *)cc)[1] = hi; -} - - -static void -fxt1_quantize_HI (dword *cc, - byte input[N_TEXELS][MAX_COMP], - byte reord[N_TEXELS][MAX_COMP], int n) -{ - const int n_vect = 6; /* highest vector number */ - const int n_comp = 3; /* 3 components: R, G, B */ - float b = 0.0F; /* phoudoin: silent compiler! */ - float iv[MAX_COMP]; /* interpolation vector */ - int i, k; - dword hihi; /* high quadword: hi dword */ - - int minSum = 2000; /* big enough */ - int maxSum = -1; /* small enough */ - int minCol = 0; /* phoudoin: silent compiler! */ - int maxCol = 0; /* phoudoin: silent compiler! */ - - /* Our solution here is to find the darkest and brightest colors in - * the 8x4 tile and use those as the two representative colors. - * There are probably better algorithms to use (histogram-based). - */ - for (k = 0; k < n; k++) { - int sum = 0; - for (i = 0; i < n_comp; i++) { - sum += reord[k][i]; - } - if (minSum > sum) { - minSum = sum; - minCol = k; - } - if (maxSum < sum) { - maxSum = sum; - maxCol = k; - } - } - - hihi = 0; /* cc-hi = "00" */ - for (i = 0; i < n_comp; i++) { - /* add in colors */ - hihi <<= 5; - hihi |= reord[maxCol][i] >> 3; - } - for (i = 0; i < n_comp; i++) { - /* add in colors */ - hihi <<= 5; - hihi |= reord[minCol][i] >> 3; - } - cc[3] = hihi; - cc[0] = cc[1] = cc[2] = 0; - - /* compute interpolation vector */ - if (minCol != maxCol) { - MAKEIVEC(n_vect, n_comp, iv, b, reord[minCol], reord[maxCol]); - } - - /* add in texels */ - for (k = N_TEXELS - 1; k >= 0; k--) { - int t = k * 3; - dword *kk = (dword *)((byte *)cc + t / 8); - int texel = n_vect + 1; /* transparent black */ - - if (!ISTBLACK(input[k])) { - if (minCol != maxCol) { - /* interpolate color */ - CALCCDOT(texel, n_vect, n_comp, iv, b, input[k]); - /* add in texel */ - kk[0] |= texel << (t & 7); - } - } else { - /* add in texel */ - kk[0] |= texel << (t & 7); - } - } -} - - -static void -fxt1_quantize_MIXED1 (dword *cc, - byte input[N_TEXELS][MAX_COMP]) -{ - const int n_vect = 2; /* highest vector number in each microtile */ - const int n_comp = 3; /* 3 components: R, G, B */ - byte vec[2 * 2][MAX_COMP]; /* 2 extrema for each sub-block */ - float b, iv[MAX_COMP]; /* interpolation vector */ - int i, j, k; - qword hi; /* high quadword */ - dword lohi, lolo; /* low quadword: hi dword, lo dword */ - - int minSum; - int maxSum; - int minColL = 0, maxColL = -1; - int minColR = 0, maxColR = -1; - - /* Our solution here is to find the darkest and brightest colors in - * the 4x4 tile and use those as the two representative colors. - * There are probably better algorithms to use (histogram-based). - */ - minSum = 2000; /* big enough */ - maxSum = -1; /* small enough */ - for (k = 0; k < N_TEXELS / 2; k++) { - if (!ISTBLACK(input[k])) { - int sum = 0; - for (i = 0; i < n_comp; i++) { - sum += input[k][i]; - } - if (minSum > sum) { - minSum = sum; - minColL = k; - } - if (maxSum < sum) { - maxSum = sum; - maxColL = k; - } - } - } - minSum = 2000; /* big enough */ - maxSum = -1; /* small enough */ - for (; k < N_TEXELS; k++) { - if (!ISTBLACK(input[k])) { - int sum = 0; - for (i = 0; i < n_comp; i++) { - sum += input[k][i]; - } - if (minSum > sum) { - minSum = sum; - minColR = k; - } - if (maxSum < sum) { - maxSum = sum; - maxColR = k; - } - } - } - - /* left microtile */ - if (maxColL == -1) { - /* all transparent black */ - cc[0] = ~0UL; - for (i = 0; i < n_comp; i++) { - vec[0][i] = 0; - vec[1][i] = 0; - } - } else { - cc[0] = 0; - for (i = 0; i < n_comp; i++) { - vec[0][i] = input[minColL][i]; - vec[1][i] = input[maxColL][i]; - } - if (minColL != maxColL) { - /* compute interpolation vector */ - MAKEIVEC(n_vect, n_comp, iv, b, vec[0], vec[1]); - - /* add in texels */ - lolo = 0; - for (k = N_TEXELS / 2 - 1; k >= 0; k--) { - int texel = n_vect + 1; /* transparent black */ - if (!ISTBLACK(input[k])) { - /* interpolate color */ - CALCCDOT(texel, n_vect, n_comp, iv, b, input[k]); - } - /* add in texel */ - lolo <<= 2; - lolo |= texel; - } - cc[0] = lolo; - } - } - - /* right microtile */ - if (maxColR == -1) { - /* all transparent black */ - cc[1] = ~0UL; - for (i = 0; i < n_comp; i++) { - vec[2][i] = 0; - vec[3][i] = 0; - } - } else { - cc[1] = 0; - for (i = 0; i < n_comp; i++) { - vec[2][i] = input[minColR][i]; - vec[3][i] = input[maxColR][i]; - } - if (minColR != maxColR) { - /* compute interpolation vector */ - MAKEIVEC(n_vect, n_comp, iv, b, vec[2], vec[3]); - - /* add in texels */ - lohi = 0; - for (k = N_TEXELS - 1; k >= N_TEXELS / 2; k--) { - int texel = n_vect + 1; /* transparent black */ - if (!ISTBLACK(input[k])) { - /* interpolate color */ - CALCCDOT(texel, n_vect, n_comp, iv, b, input[k]); - } - /* add in texel */ - lohi <<= 2; - lohi |= texel; - } - cc[1] = lohi; - } - } - - Q_MOV32(hi, 9 | (vec[3][GCOMP] & 4) | ((vec[1][GCOMP] >> 1) & 2)); /* chroma = "1" */ - for (j = 2 * 2 - 1; j >= 0; j--) { - for (i = 0; i < n_comp; i++) { - /* add in colors */ - Q_SHL(hi, 5); - Q_OR32(hi, vec[j][i] >> 3); - } - } - ((qword *)cc)[1] = hi; -} - - -static void -fxt1_quantize_MIXED0 (dword *cc, - byte input[N_TEXELS][MAX_COMP]) -{ - const int n_vect = 3; /* highest vector number in each microtile */ - const int n_comp = 3; /* 3 components: R, G, B */ - byte vec[2 * 2][MAX_COMP]; /* 2 extrema for each sub-block */ - float b, iv[MAX_COMP]; /* interpolation vector */ - int i, j, k; - qword hi; /* high quadword */ - dword lohi, lolo; /* low quadword: hi dword, lo dword */ - - int minColL = 0, maxColL = 0; - int minColR = 0, maxColR = 0; -#if 0 - int minSum; - int maxSum; - - /* Our solution here is to find the darkest and brightest colors in - * the 4x4 tile and use those as the two representative colors. - * There are probably better algorithms to use (histogram-based). - */ - minSum = 2000; /* big enough */ - maxSum = -1; /* small enough */ - for (k = 0; k < N_TEXELS / 2; k++) { - int sum = 0; - for (i = 0; i < n_comp; i++) { - sum += input[k][i]; - } - if (minSum > sum) { - minSum = sum; - minColL = k; - } - if (maxSum < sum) { - maxSum = sum; - maxColL = k; - } - } - minSum = 2000; /* big enough */ - maxSum = -1; /* small enough */ - for (; k < N_TEXELS; k++) { - int sum = 0; - for (i = 0; i < n_comp; i++) { - sum += input[k][i]; - } - if (minSum > sum) { - minSum = sum; - minColR = k; - } - if (maxSum < sum) { - maxSum = sum; - maxColR = k; - } - } -#else - int minVal; - int maxVal; - int maxVarL = fxt1_variance(NULL, input, n_comp, N_TEXELS / 2); - int maxVarR = fxt1_variance(NULL, &input[N_TEXELS / 2], n_comp, N_TEXELS / 2); - - /* Scan the channel with max variance for lo & hi - * and use those as the two representative colors. - */ - minVal = 2000; /* big enough */ - maxVal = -1; /* small enough */ - for (k = 0; k < N_TEXELS / 2; k++) { - int t = input[k][maxVarL]; - if (minVal > t) { - minVal = t; - minColL = k; - } - if (maxVal < t) { - maxVal = t; - maxColL = k; - } - } - minVal = 2000; /* big enough */ - maxVal = -1; /* small enough */ - for (; k < N_TEXELS; k++) { - int t = input[k][maxVarR]; - if (minVal > t) { - minVal = t; - minColR = k; - } - if (maxVal < t) { - maxVal = t; - maxColR = k; - } - } -#endif - - /* left microtile */ - cc[0] = 0; - for (i = 0; i < n_comp; i++) { - vec[0][i] = input[minColL][i]; - vec[1][i] = input[maxColL][i]; - } - if (minColL != maxColL) { - /* compute interpolation vector */ - MAKEIVEC(n_vect, n_comp, iv, b, vec[0], vec[1]); - - /* add in texels */ - lolo = 0; - for (k = N_TEXELS / 2 - 1; k >= 0; k--) { - int texel; - /* interpolate color */ - CALCCDOT(texel, n_vect, n_comp, iv, b, input[k]); - /* add in texel */ - lolo <<= 2; - lolo |= texel; - } - - /* funky encoding for LSB of green */ - if ((int)((lolo >> 1) & 1) != (((vec[1][GCOMP] ^ vec[0][GCOMP]) >> 2) & 1)) { - for (i = 0; i < n_comp; i++) { - vec[1][i] = input[minColL][i]; - vec[0][i] = input[maxColL][i]; - } - lolo = ~lolo; - } - - cc[0] = lolo; - } - - /* right microtile */ - cc[1] = 0; - for (i = 0; i < n_comp; i++) { - vec[2][i] = input[minColR][i]; - vec[3][i] = input[maxColR][i]; - } - if (minColR != maxColR) { - /* compute interpolation vector */ - MAKEIVEC(n_vect, n_comp, iv, b, vec[2], vec[3]); - - /* add in texels */ - lohi = 0; - for (k = N_TEXELS - 1; k >= N_TEXELS / 2; k--) { - int texel; - /* interpolate color */ - CALCCDOT(texel, n_vect, n_comp, iv, b, input[k]); - /* add in texel */ - lohi <<= 2; - lohi |= texel; - } - - /* funky encoding for LSB of green */ - if ((int)((lohi >> 1) & 1) != (((vec[3][GCOMP] ^ vec[2][GCOMP]) >> 2) & 1)) { - for (i = 0; i < n_comp; i++) { - vec[3][i] = input[minColR][i]; - vec[2][i] = input[maxColR][i]; - } - lohi = ~lohi; - } - - cc[1] = lohi; - } - - Q_MOV32(hi, 8 | (vec[3][GCOMP] & 4) | ((vec[1][GCOMP] >> 1) & 2)); /* chroma = "1" */ - for (j = 2 * 2 - 1; j >= 0; j--) { - for (i = 0; i < n_comp; i++) { - /* add in colors */ - Q_SHL(hi, 5); - Q_OR32(hi, vec[j][i] >> 3); - } - } - ((qword *)cc)[1] = hi; -} - - -static void -fxt1_quantize (dword *cc, const byte *lines[], int comps) -{ - int trualpha; - byte reord[N_TEXELS][MAX_COMP]; - - byte input[N_TEXELS][MAX_COMP]; - int i, k, l; - - if (comps == 3) { - /* make the whole block opaque */ - memset(input, -1, sizeof(input)); - } - - /* 8 texels each line */ - for (l = 0; l < 4; l++) { - for (k = 0; k < 4; k++) { - for (i = 0; i < comps; i++) { - input[k + l * 4][i] = *lines[l]++; - } - } - for (; k < 8; k++) { - for (i = 0; i < comps; i++) { - input[k + l * 4 + 12][i] = *lines[l]++; - } - } - } - - /* block layout: - * 00, 01, 02, 03, 08, 09, 0a, 0b - * 10, 11, 12, 13, 18, 19, 1a, 1b - * 04, 05, 06, 07, 0c, 0d, 0e, 0f - * 14, 15, 16, 17, 1c, 1d, 1e, 1f - */ - - /* [dBorca] - * stupidity flows forth from this - */ - l = N_TEXELS; - trualpha = 0; - if (comps == 4) { - /* skip all transparent black texels */ - l = 0; - for (k = 0; k < N_TEXELS; k++) { - /* test all components against 0 */ - if (!ISTBLACK(input[k])) { - /* texel is not transparent black */ - COPY_4UBV(reord[l], input[k]); - if (reord[l][ACOMP] < (255 - ALPHA_TS)) { - /* non-opaque texel */ - trualpha = !0; - } - l++; - } - } - } - -#if 0 - if (trualpha) { - fxt1_quantize_ALPHA0(cc, input, reord, l); - } else if (l == 0) { - cc[0] = cc[1] = cc[2] = -1; - cc[3] = 0; - } else if (l < N_TEXELS) { - fxt1_quantize_HI(cc, input, reord, l); - } else { - fxt1_quantize_CHROMA(cc, input); - } - (void)fxt1_quantize_ALPHA1; - (void)fxt1_quantize_MIXED1; - (void)fxt1_quantize_MIXED0; -#else - if (trualpha) { - fxt1_quantize_ALPHA1(cc, input); - } else if (l == 0) { - cc[0] = cc[1] = cc[2] = ~0UL; - cc[3] = 0; - } else if (l < N_TEXELS) { - fxt1_quantize_MIXED1(cc, input); - } else { - fxt1_quantize_MIXED0(cc, input); - } - (void)fxt1_quantize_ALPHA0; - (void)fxt1_quantize_HI; - (void)fxt1_quantize_CHROMA; -#endif -} - - -TAPI int TAPIENTRY -fxt1_encode (int width, int height, int comps, - const void *source, int srcRowStride, - void *dest, int destRowStride) -{ - int x, y; - const byte *data; - dword *encoded = (dword *)dest; - void *newSource = NULL; - - /* Replicate image if width is not M8 or height is not M4 */ - if ((width & 7) | (height & 3)) { - int newWidth = (width + 7) & ~7; - int newHeight = (height + 3) & ~3; - newSource = malloc(comps * newWidth * newHeight * sizeof(byte *)); - _mesa_upscale_teximage2d(width, height, newWidth, newHeight, - comps, (const byte *)source, - srcRowStride, (byte *)newSource); - source = newSource; - width = newWidth; - height = newHeight; - srcRowStride = comps * newWidth; - } - - data = (const byte *)source; - destRowStride = (destRowStride - width * 2) / 4; - for (y = 0; y < height; y += 4) { - unsigned int offs = 0 + (y + 0) * srcRowStride; - for (x = 0; x < width; x += 8) { - const byte *lines[4]; - lines[0] = &data[offs]; - lines[1] = lines[0] + srcRowStride; - lines[2] = lines[1] + srcRowStride; - lines[3] = lines[2] + srcRowStride; - offs += 8 * comps; - fxt1_quantize(encoded, lines, comps); - /* 128 bits per 8x4 block */ - encoded += 4; - } - encoded += destRowStride; - } - - if (newSource != NULL) { - free(newSource); - } - - return 0; -} - - -/***************************************************************************\ - * FXT1 decoder - * - * The decoder is based on GL_3DFX_texture_compression_FXT1 - * specification and serves as a concept for the encoder. -\***************************************************************************/ - - -/* lookup table for scaling 5 bit colors up to 8 bits */ -static const byte _rgb_scale_5[] = { - 0, 8, 16, 25, 33, 41, 49, 58, - 66, 74, 82, 90, 99, 107, 115, 123, - 132, 140, 148, 156, 165, 173, 181, 189, - 197, 206, 214, 222, 230, 239, 247, 255 -}; - -/* lookup table for scaling 6 bit colors up to 8 bits */ -static const byte _rgb_scale_6[] = { - 0, 4, 8, 12, 16, 20, 24, 28, - 32, 36, 40, 45, 49, 53, 57, 61, - 65, 69, 73, 77, 81, 85, 89, 93, - 97, 101, 105, 109, 113, 117, 121, 125, - 130, 134, 138, 142, 146, 150, 154, 158, - 162, 166, 170, 174, 178, 182, 186, 190, - 194, 198, 202, 206, 210, 215, 219, 223, - 227, 231, 235, 239, 243, 247, 251, 255 -}; - - -#define CC_SEL(cc, which) (((dword *)(cc))[(which) / 32] >> ((which) & 31)) -#define UP5(c) _rgb_scale_5[(c) & 31] -#define UP6(c, b) _rgb_scale_6[(((c) & 31) << 1) | ((b) & 1)] -#define LERP(n, t, c0, c1) (((n) - (t)) * (c0) + (t) * (c1) + (n) / 2) / (n) -#define ZERO_4UBV(v) *((dword *)(v)) = 0 - - -static void -fxt1_decode_1HI (const byte *code, int t, byte *rgba) -{ - const dword *cc; - - t *= 3; - cc = (const dword *)(code + t / 8); - t = (cc[0] >> (t & 7)) & 7; - - if (t == 7) { - ZERO_4UBV(rgba); - } else { - cc = (const dword *)(code + 12); - if (t == 0) { - rgba[BCOMP] = UP5(CC_SEL(cc, 0)); - rgba[GCOMP] = UP5(CC_SEL(cc, 5)); - rgba[RCOMP] = UP5(CC_SEL(cc, 10)); - } else if (t == 6) { - rgba[BCOMP] = UP5(CC_SEL(cc, 15)); - rgba[GCOMP] = UP5(CC_SEL(cc, 20)); - rgba[RCOMP] = UP5(CC_SEL(cc, 25)); - } else { - rgba[BCOMP] = LERP(6, t, UP5(CC_SEL(cc, 0)), UP5(CC_SEL(cc, 15))); - rgba[GCOMP] = LERP(6, t, UP5(CC_SEL(cc, 5)), UP5(CC_SEL(cc, 20))); - rgba[RCOMP] = LERP(6, t, UP5(CC_SEL(cc, 10)), UP5(CC_SEL(cc, 25))); - } - rgba[ACOMP] = 255; - } -} - - -static void -fxt1_decode_1CHROMA (const byte *code, int t, byte *rgba) -{ - const dword *cc; - dword kk; - - cc = (const dword *)code; - if (t & 16) { - cc++; - t &= 15; - } - t = (cc[0] >> (t * 2)) & 3; - - t *= 15; - cc = (const dword *)(code + 8 + t / 8); - kk = cc[0] >> (t & 7); - rgba[BCOMP] = UP5(kk); - rgba[GCOMP] = UP5(kk >> 5); - rgba[RCOMP] = UP5(kk >> 10); - rgba[ACOMP] = 255; -} - - -static void -fxt1_decode_1MIXED (const byte *code, int t, byte *rgba) -{ - const dword *cc; - int col[2][3]; - int glsb, selb; - - cc = (const dword *)code; - if (t & 16) { - t &= 15; - t = (cc[1] >> (t * 2)) & 3; - /* col 2 */ - col[0][BCOMP] = (*(const dword *)(code + 11)) >> 6; - col[0][GCOMP] = CC_SEL(cc, 99); - col[0][RCOMP] = CC_SEL(cc, 104); - /* col 3 */ - col[1][BCOMP] = CC_SEL(cc, 109); - col[1][GCOMP] = CC_SEL(cc, 114); - col[1][RCOMP] = CC_SEL(cc, 119); - glsb = CC_SEL(cc, 126); - selb = CC_SEL(cc, 33); - } else { - t = (cc[0] >> (t * 2)) & 3; - /* col 0 */ - col[0][BCOMP] = CC_SEL(cc, 64); - col[0][GCOMP] = CC_SEL(cc, 69); - col[0][RCOMP] = CC_SEL(cc, 74); - /* col 1 */ - col[1][BCOMP] = CC_SEL(cc, 79); - col[1][GCOMP] = CC_SEL(cc, 84); - col[1][RCOMP] = CC_SEL(cc, 89); - glsb = CC_SEL(cc, 125); - selb = CC_SEL(cc, 1); - } - - if (CC_SEL(cc, 124) & 1) { - /* alpha[0] == 1 */ - - if (t == 3) { - ZERO_4UBV(rgba); - } else { - if (t == 0) { - rgba[BCOMP] = UP5(col[0][BCOMP]); - rgba[GCOMP] = UP5(col[0][GCOMP]); - rgba[RCOMP] = UP5(col[0][RCOMP]); - } else if (t == 2) { - rgba[BCOMP] = UP5(col[1][BCOMP]); - rgba[GCOMP] = UP6(col[1][GCOMP], glsb); - rgba[RCOMP] = UP5(col[1][RCOMP]); - } else { - rgba[BCOMP] = (UP5(col[0][BCOMP]) + UP5(col[1][BCOMP])) / 2; - rgba[GCOMP] = (UP5(col[0][GCOMP]) + UP6(col[1][GCOMP], glsb)) / 2; - rgba[RCOMP] = (UP5(col[0][RCOMP]) + UP5(col[1][RCOMP])) / 2; - } - rgba[ACOMP] = 255; - } - } else { - /* alpha[0] == 0 */ - - if (t == 0) { - rgba[BCOMP] = UP5(col[0][BCOMP]); - rgba[GCOMP] = UP6(col[0][GCOMP], glsb ^ selb); - rgba[RCOMP] = UP5(col[0][RCOMP]); - } else if (t == 3) { - rgba[BCOMP] = UP5(col[1][BCOMP]); - rgba[GCOMP] = UP6(col[1][GCOMP], glsb); - rgba[RCOMP] = UP5(col[1][RCOMP]); - } else { - rgba[BCOMP] = LERP(3, t, UP5(col[0][BCOMP]), UP5(col[1][BCOMP])); - rgba[GCOMP] = LERP(3, t, UP6(col[0][GCOMP], glsb ^ selb), - UP6(col[1][GCOMP], glsb)); - rgba[RCOMP] = LERP(3, t, UP5(col[0][RCOMP]), UP5(col[1][RCOMP])); - } - rgba[ACOMP] = 255; - } -} - - -static void -fxt1_decode_1ALPHA (const byte *code, int t, byte *rgba) -{ - const dword *cc; - - cc = (const dword *)code; - if (CC_SEL(cc, 124) & 1) { - /* lerp == 1 */ - int col0[4]; - - if (t & 16) { - t &= 15; - t = (cc[1] >> (t * 2)) & 3; - /* col 2 */ - col0[BCOMP] = (*(const dword *)(code + 11)) >> 6; - col0[GCOMP] = CC_SEL(cc, 99); - col0[RCOMP] = CC_SEL(cc, 104); - col0[ACOMP] = CC_SEL(cc, 119); - } else { - t = (cc[0] >> (t * 2)) & 3; - /* col 0 */ - col0[BCOMP] = CC_SEL(cc, 64); - col0[GCOMP] = CC_SEL(cc, 69); - col0[RCOMP] = CC_SEL(cc, 74); - col0[ACOMP] = CC_SEL(cc, 109); - } - - if (t == 0) { - rgba[BCOMP] = UP5(col0[BCOMP]); - rgba[GCOMP] = UP5(col0[GCOMP]); - rgba[RCOMP] = UP5(col0[RCOMP]); - rgba[ACOMP] = UP5(col0[ACOMP]); - } else if (t == 3) { - rgba[BCOMP] = UP5(CC_SEL(cc, 79)); - rgba[GCOMP] = UP5(CC_SEL(cc, 84)); - rgba[RCOMP] = UP5(CC_SEL(cc, 89)); - rgba[ACOMP] = UP5(CC_SEL(cc, 114)); - } else { - rgba[BCOMP] = LERP(3, t, UP5(col0[BCOMP]), UP5(CC_SEL(cc, 79))); - rgba[GCOMP] = LERP(3, t, UP5(col0[GCOMP]), UP5(CC_SEL(cc, 84))); - rgba[RCOMP] = LERP(3, t, UP5(col0[RCOMP]), UP5(CC_SEL(cc, 89))); - rgba[ACOMP] = LERP(3, t, UP5(col0[ACOMP]), UP5(CC_SEL(cc, 114))); - } - } else { - /* lerp == 0 */ - - if (t & 16) { - cc++; - t &= 15; - } - t = (cc[0] >> (t * 2)) & 3; - - if (t == 3) { - ZERO_4UBV(rgba); - } else { - dword kk; - cc = (const dword *)code; - rgba[ACOMP] = UP5(cc[3] >> (t * 5 + 13)); - t *= 15; - cc = (const dword *)(code + 8 + t / 8); - kk = cc[0] >> (t & 7); - rgba[BCOMP] = UP5(kk); - rgba[GCOMP] = UP5(kk >> 5); - rgba[RCOMP] = UP5(kk >> 10); - } - } -} - - -TAPI void TAPIENTRY -fxt1_decode_1 (const void *texture, int stride, - int i, int j, byte *rgba) -{ - static void (*decode_1[]) (const byte *, int, byte *) = { - fxt1_decode_1HI, /* cc-high = "00?" */ - fxt1_decode_1HI, /* cc-high = "00?" */ - fxt1_decode_1CHROMA, /* cc-chroma = "010" */ - fxt1_decode_1ALPHA, /* alpha = "011" */ - fxt1_decode_1MIXED, /* mixed = "1??" */ - fxt1_decode_1MIXED, /* mixed = "1??" */ - fxt1_decode_1MIXED, /* mixed = "1??" */ - fxt1_decode_1MIXED /* mixed = "1??" */ - }; - - const byte *code = (const byte *)texture + - ((j / 4) * (stride / 8) + (i / 8)) * 16; - int mode = CC_SEL(code, 125); - int t = i & 7; - - if (t & 4) { - t += 12; - } - t += (j & 3) * 4; - - decode_1[mode](code, t, rgba); - -#if VERBOSE - { - extern int cc_chroma; - extern int cc_alpha; - extern int cc_high; - extern int cc_mixed; - static int *cctype[] = { - &cc_high, - &cc_high, - &cc_chroma, - &cc_alpha, - &cc_mixed, - &cc_mixed, - &cc_mixed, - &cc_mixed - }; - (*cctype[mode])++; - } -#endif -} diff --git a/dll/3rdparty/dxtn/fxt1.h b/dll/3rdparty/dxtn/fxt1.h deleted file mode 100644 index c2919bbac0..0000000000 --- a/dll/3rdparty/dxtn/fxt1.h +++ /dev/null @@ -1,38 +0,0 @@ -/* - * FXT1 codec - * Version: 1.1 - * - * Copyright (C) 2004 Daniel Borca All Rights Reserved. - * - * Permission is hereby granted, free of charge, to any person obtaining a - * copy of this software and associated documentation files (the "Software"), - * to deal in the Software without restriction, including without limitation - * the rights to use, copy, modify, merge, publish, distribute, sublicense, - * and/or sell copies of the Software, and to permit persons to whom the - * Software is furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included - * in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS - * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL - * DANIEL BORCA BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN - * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - */ - - -#ifndef FXT1_H_included -#define FXT1_H_included - -TAPI int TAPIENTRY -fxt1_encode (int width, int height, int comps, - const void *source, int srcRowStride, - void *dest, int destRowStride); - -TAPI void TAPIENTRY -fxt1_decode_1 (const void *texture, int stride /* in pixels */, - int i, int j, byte *rgba); - -#endif diff --git a/dll/3rdparty/dxtn/internal.h b/dll/3rdparty/dxtn/internal.h deleted file mode 100644 index b7e01dbe93..0000000000 --- a/dll/3rdparty/dxtn/internal.h +++ /dev/null @@ -1,138 +0,0 @@ -/* - * Texture compression - * Version: 1.0 - * - * Copyright (C) 2004 Daniel Borca All Rights Reserved. - * - * this is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2, or (at your option) - * any later version. - * - * this is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with GNU Make; see the file COPYING. If not, write to - * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. - */ - - -#ifndef INTERNAL_H_included -#define INTERNAL_H_included - -/*****************************************************************************\ - * DLL stuff -\*****************************************************************************/ - -#ifdef __WIN32__ -#define TAPI __declspec(dllexport) -#define TAPIENTRY __stdcall -#else -#define TAPI -#define TAPIENTRY -#endif - - -/*****************************************************************************\ - * 64bit types on 32bit machine -\*****************************************************************************/ - -#if defined(__GNUC__) && !defined(__cplusplus) - -typedef unsigned long long qword; - -#define Q_MOV32(a, b) a = b -#define Q_OR32(a, b) a |= b -#define Q_SHL(a, c) a <<= c - -#else /* !__GNUC__ */ - -typedef struct { - dword lo, hi; -} qword; - -#define Q_MOV32(a, b) a.lo = b -#define Q_OR32(a, b) a.lo |= b -#define Q_SHL(a, c) \ - do { \ - if ((c) >= 32) { \ - a.hi = a.lo << ((c) - 32); \ - a.lo = 0; \ - } else { \ - a.hi = (a.hi << (c)) | (a.lo >> (32 - (c)));\ - a.lo <<= c; \ - } \ - } while (0) - -#endif /* !__GNUC__ */ - - -/*****************************************************************************\ - * Config -\*****************************************************************************/ - -#define RCOMP 0 -#define GCOMP 1 -#define BCOMP 2 -#define ACOMP 3 - - -/*****************************************************************************\ - * Metric -\*****************************************************************************/ - -#define F(i) (float)1 /* can be used to obtain an oblong metric: 0.30 / 0.59 / 0.11 */ -#define SAFECDOT 1 /* for paranoids */ - -#define MAKEIVEC(NV, NC, IV, B, V0, V1) \ - do { \ - /* compute interpolation vector */\ - float d2 = 0.0F; \ - float rd2; \ - \ - for (i = 0; i < NC; i++) { \ - IV[i] = (V1[i] - V0[i]) * F(i);\ - d2 += IV[i] * IV[i]; \ - } \ - rd2 = (float)NV / d2; \ - B = 0; \ - for (i = 0; i < NC; i++) { \ - IV[i] *= F(i); \ - B -= IV[i] * V0[i]; \ - IV[i] *= rd2; \ - } \ - B = B * rd2 + 0.5F; \ - } while (0) - -#define CALCCDOT(TEXEL, NV, NC, IV, B, V)\ - do { \ - float dot = 0.0F; \ - for (i = 0; i < NC; i++) { \ - dot += V[i] * IV[i]; \ - } \ - TEXEL = (int)(dot + B); \ - if (SAFECDOT) { \ - if (TEXEL < 0) { \ - TEXEL = 0; \ - } else if (TEXEL > NV) { \ - TEXEL = NV; \ - } \ - } \ - } while (0) - - -/*****************************************************************************\ - * Utility functions -\*****************************************************************************/ - -void -_mesa_upscale_teximage2d (unsigned int inWidth, unsigned int inHeight, - unsigned int outWidth, unsigned int outHeight, - unsigned int comps, - const byte *src, int srcRowStride, - unsigned char *dest); - -#endif diff --git a/dll/3rdparty/dxtn/txc_compress_dxtn.c b/dll/3rdparty/dxtn/txc_compress_dxtn.c new file mode 100644 index 0000000000..cf83d08eea --- /dev/null +++ b/dll/3rdparty/dxtn/txc_compress_dxtn.c @@ -0,0 +1,843 @@ +/* + * libtxc_dxtn + * Version: 1.0 + * + * Copyright (C) 2004 Roland Scheidegger All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN + * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ + +#include <stdio.h> +#include <stdlib.h> +#include "txc_dxtn.h" + +/* weights used for error function, basically weights (unsquared 2/4/1) according to rgb->luminance conversion + not sure if this really reflects visual perception */ +#define REDWEIGHT 4 +#define GREENWEIGHT 16 +#define BLUEWEIGHT 1 + +#define ALPHACUT 127 + +static void fancybasecolorsearch( GLubyte *blkaddr, GLubyte srccolors[4][4][4], GLubyte *bestcolor[2], + GLint numxpixels, GLint numypixels, GLint type, GLboolean haveAlpha) +{ + /* use same luminance-weighted distance metric to determine encoding as for finding the base colors */ + + /* TODO could also try to find a better encoding for the 3-color-encoding type, this really should be done + if it's rgba_dxt1 and we have alpha in the block, currently even values which will be mapped to black + due to their alpha value will influence the result */ + GLint i, j, colors, z; + GLuint pixerror, pixerrorred, pixerrorgreen, pixerrorblue, pixerrorbest; + GLint colordist, blockerrlin[2][3]; + GLubyte nrcolor[2]; + GLint pixerrorcolorbest[3]; + GLubyte enc = 0; + GLubyte cv[4][4]; + GLubyte testcolor[2][3]; + +/* fprintf(stderr, "color begin 0 r/g/b %d/%d/%d, 1 r/g/b %d/%d/%d\n", + bestcolor[0][0], bestcolor[0][1], bestcolor[0][2], bestcolor[1][0], bestcolor[1][1], bestcolor[1][2]);*/ + if (((bestcolor[0][0] & 0xf8) << 8 | (bestcolor[0][1] & 0xfc) << 3 | bestcolor[0][2] >> 3) < + ((bestcolor[1][0] & 0xf8) << 8 | (bestcolor[1][1] & 0xfc) << 3 | bestcolor[1][2] >> 3)) { + testcolor[0][0] = bestcolor[0][0]; + testcolor[0][1] = bestcolor[0][1]; + testcolor[0][2] = bestcolor[0][2]; + testcolor[1][0] = bestcolor[1][0]; + testcolor[1][1] = bestcolor[1][1]; + testcolor[1][2] = bestcolor[1][2]; + } + else { + testcolor[1][0] = bestcolor[0][0]; + testcolor[1][1] = bestcolor[0][1]; + testcolor[1][2] = bestcolor[0][2]; + testcolor[0][0] = bestcolor[1][0]; + testcolor[0][1] = bestcolor[1][1]; + testcolor[0][2] = bestcolor[1][2]; + } + + for (i = 0; i < 3; i ++) { + cv[0][i] = testcolor[0][i]; + cv[1][i] = testcolor[1][i]; + cv[2][i] = (testcolor[0][i] * 2 + testcolor[1][i]) / 3; + cv[3][i] = (testcolor[0][i] + testcolor[1][i] * 2) / 3; + } + + blockerrlin[0][0] = 0; + blockerrlin[0][1] = 0; + blockerrlin[0][2] = 0; + blockerrlin[1][0] = 0; + blockerrlin[1][1] = 0; + blockerrlin[1][2] = 0; + + nrcolor[0] = 0; + nrcolor[1] = 0; + + for (j = 0; j < numypixels; j++) { + for (i = 0; i < numxpixels; i++) { + pixerrorbest = 0xffffffff; + for (colors = 0; colors < 4; colors++) { + colordist = srccolors[j][i][0] - (cv[colors][0]); + pixerror = colordist * colordist * REDWEIGHT; + pixerrorred = colordist; + colordist = srccolors[j][i][1] - (cv[colors][1]); + pixerror += colordist * colordist * GREENWEIGHT; + pixerrorgreen = colordist; + colordist = srccolors[j][i][2] - (cv[colors][2]); + pixerror += colordist * colordist * BLUEWEIGHT; + pixerrorblue = colordist; + if (pixerror < pixerrorbest) { + enc = colors; + pixerrorbest = pixerror; + pixerrorcolorbest[0] = pixerrorred; + pixerrorcolorbest[1] = pixerrorgreen; + pixerrorcolorbest[2] = pixerrorblue; + } + } + if (enc == 0) { + for (z = 0; z < 3; z++) { + blockerrlin[0][z] += 3 * pixerrorcolorbest[z]; + } + nrcolor[0] += 3; + } + else if (enc == 2) { + for (z = 0; z < 3; z++) { + blockerrlin[0][z] += 2 * pixerrorcolorbest[z]; + } + nrcolor[0] += 2; + for (z = 0; z < 3; z++) { + blockerrlin[1][z] += 1 * pixerrorcolorbest[z]; + } + nrcolor[1] += 1; + } + else if (enc == 3) { + for (z = 0; z < 3; z++) { + blockerrlin[0][z] += 1 * pixerrorcolorbest[z]; + } + nrcolor[0] += 1; + for (z = 0; z < 3; z++) { + blockerrlin[1][z] += 2 * pixerrorcolorbest[z]; + } + nrcolor[1] += 2; + } + else if (enc == 1) { + for (z = 0; z < 3; z++) { + blockerrlin[1][z] += 3 * pixerrorcolorbest[z]; + } + nrcolor[1] += 3; + } + } + } + if (nrcolor[0] == 0) nrcolor[0] = 1; + if (nrcolor[1] == 0) nrcolor[1] = 1; + for (j = 0; j < 2; j++) { + for (i = 0; i < 3; i++) { + GLint newvalue = testcolor[j][i] + blockerrlin[j][i] / nrcolor[j]; + if (newvalue <= 0) + testcolor[j][i] = 0; + else if (newvalue >= 255) + testcolor[j][i] = 255; + else testcolor[j][i] = newvalue; + } + } + + if ((abs(testcolor[0][0] - testcolor[1][0]) < 8) && + (abs(testcolor[0][1] - testcolor[1][1]) < 4) && + (abs(testcolor[0][2] - testcolor[1][2]) < 8)) { + /* both colors are so close they might get encoded as the same 16bit values */ + GLubyte coldiffred, coldiffgreen, coldiffblue, coldiffmax, factor, ind0, ind1; + + coldiffred = abs(testcolor[0][0] - testcolor[1][0]); + coldiffgreen = 2 * abs(testcolor[0][1] - testcolor[1][1]); + coldiffblue = abs(testcolor[0][2] - testcolor[1][2]); + coldiffmax = coldiffred; + if (coldiffmax < coldiffgreen) coldiffmax = coldiffgreen; + if (coldiffmax < coldiffblue) coldiffmax = coldiffblue; + if (coldiffmax > 0) { + if (coldiffmax > 4) factor = 2; + else if (coldiffmax > 2) factor = 3; + else factor = 4; + /* Won't do much if the color value is near 255... */ + /* argh so many ifs */ + if (testcolor[1][1] >= testcolor[0][1]) { + ind1 = 1; ind0 = 0; + } + else { + ind1 = 0; ind0 = 1; + } + if ((testcolor[ind1][1] + factor * coldiffgreen) <= 255) + testcolor[ind1][1] += factor * coldiffgreen; + else testcolor[ind1][1] = 255; + if ((testcolor[ind1][0] - testcolor[ind0][1]) > 0) { + if ((testcolor[ind1][0] + factor * coldiffred) <= 255) + testcolor[ind1][0] += factor * coldiffred; + else testcolor[ind1][0] = 255; + } + else { + if ((testcolor[ind0][0] + factor * coldiffred) <= 255) + testcolor[ind0][0] += factor * coldiffred; + else testcolor[ind0][0] = 255; + } + if ((testcolor[ind1][2] - testcolor[ind0][2]) > 0) { + if ((testcolor[ind1][2] + factor * coldiffblue) <= 255) + testcolor[ind1][2] += factor * coldiffblue; + else testcolor[ind1][2] = 255; + } + else { + if ((testcolor[ind0][2] + factor * coldiffblue) <= 255) + testcolor[ind0][2] += factor * coldiffblue; + else testcolor[ind0][2] = 255; + } + } + } + + if (((testcolor[0][0] & 0xf8) << 8 | (testcolor[0][1] & 0xfc) << 3 | testcolor[0][2] >> 3) < + ((testcolor[1][0] & 0xf8) << 8 | (testcolor[1][1] & 0xfc) << 3 | testcolor[1][2]) >> 3) { + for (i = 0; i < 3; i++) { + bestcolor[0][i] = testcolor[0][i]; + bestcolor[1][i] = testcolor[1][i]; + } + } + else { + for (i = 0; i < 3; i++) { + bestcolor[0][i] = testcolor[1][i]; + bestcolor[1][i] = testcolor[0][i]; + } + } + +/* fprintf(stderr, "color end 0 r/g/b %d/%d/%d, 1 r/g/b %d/%d/%d\n", + bestcolor[0][0], bestcolor[0][1], bestcolor[0][2], bestcolor[1][0], bestcolor[1][1], bestcolor[1][2]);*/ +} + + + +static void storedxtencodedblock( GLubyte *blkaddr, GLubyte srccolors[4][4][4], GLubyte *bestcolor[2], + GLint numxpixels, GLint numypixels, GLuint type, GLboolean haveAlpha) +{ + /* use same luminance-weighted distance metric to determine encoding as for finding the base colors */ + + GLint i, j, colors; + GLuint testerror, testerror2, pixerror, pixerrorbest; + GLint colordist; + GLushort color0, color1, tempcolor; + GLuint bits = 0, bits2 = 0; + GLubyte *colorptr; + GLubyte enc = 0; + GLubyte cv[4][4]; + + bestcolor[0][0] = bestcolor[0][0] & 0xf8; + bestcolor[0][1] = bestcolor[0][1] & 0xfc; + bestcolor[0][2] = bestcolor[0][2] & 0xf8; + bestcolor[1][0] = bestcolor[1][0] & 0xf8; + bestcolor[1][1] = bestcolor[1][1] & 0xfc; + bestcolor[1][2] = bestcolor[1][2] & 0xf8; + + color0 = bestcolor[0][0] << 8 | bestcolor[0][1] << 3 | bestcolor[0][2] >> 3; + color1 = bestcolor[1][0] << 8 | bestcolor[1][1] << 3 | bestcolor[1][2] >> 3; + if (color0 < color1) { + tempcolor = color0; color0 = color1; color1 = tempcolor; + colorptr = bestcolor[0]; bestcolor[0] = bestcolor[1]; bestcolor[1] = colorptr; + } + + + for (i = 0; i < 3; i++) { + cv[0][i] = bestcolor[0][i]; + cv[1][i] = bestcolor[1][i]; + cv[2][i] = (bestcolor[0][i] * 2 + bestcolor[1][i]) / 3; + cv[3][i] = (bestcolor[0][i] + bestcolor[1][i] * 2) / 3; + } + + testerror = 0; + for (j = 0; j < numypixels; j++) { + for (i = 0; i < numxpixels; i++) { + pixerrorbest = 0xffffffff; + for (colors = 0; colors < 4; colors++) { + colordist = srccolors[j][i][0] - cv[colors][0]; + pixerror = colordist * colordist * REDWEIGHT; + colordist = srccolors[j][i][1] - cv[colors][1]; + pixerror += colordist * colordist * GREENWEIGHT; + colordist = srccolors[j][i][2] - cv[colors][2]; + pixerror += colordist * colordist * BLUEWEIGHT; + if (pixerror < pixerrorbest) { + pixerrorbest = pixerror; + enc = colors; + } + } + testerror += pixerrorbest; + bits |= enc << (2 * (j * 4 + i)); + } + } + /* some hw might disagree but actually decoding should always use 4-color encoding + for non-dxt1 formats */ + if (type == GL_COMPRESSED_RGB_S3TC_DXT1_EXT || type == GL_COMPRESSED_RGBA_S3TC_DXT1_EXT) { + for (i = 0; i < 3; i++) { + cv[2][i] = (bestcolor[0][i] + bestcolor[1][i]) / 2; + /* this isn't used. Looks like the black color constant can only be used + with RGB_DXT1 if I read the spec correctly (note though that the radeon gpu disagrees, + it will decode 3 to black even with DXT3/5), and due to how the color searching works + it won't get used even then */ + cv[3][i] = 0; + } + testerror2 = 0; + for (j = 0; j < numypixels; j++) { + for (i = 0; i < numxpixels; i++) { + pixerrorbest = 0xffffffff; + if ((type == GL_COMPRESSED_RGBA_S3TC_DXT1_EXT) && (srccolors[j][i][3] <= ALPHACUT)) { + enc = 3; + pixerrorbest = 0; /* don't calculate error */ + } + else { + /* we're calculating the same what we have done already for colors 0-1 above... */ + for (colors = 0; colors < 3; colors++) { + colordist = srccolors[j][i][0] - cv[colors][0]; + pixerror = colordist * colordist * REDWEIGHT; + colordist = srccolors[j][i][1] - cv[colors][1]; + pixerror += colordist * colordist * GREENWEIGHT; + colordist = srccolors[j][i][2] - cv[colors][2]; + pixerror += colordist * colordist * BLUEWEIGHT; + if (pixerror < pixerrorbest) { + pixerrorbest = pixerror; + /* need to exchange colors later */ + if (colors > 1) enc = colors; + else enc = colors ^ 1; + } + } + } + testerror2 += pixerrorbest; + bits2 |= enc << (2 * (j * 4 + i)); + } + } + } else { + testerror2 = 0xffffffff; + } + + /* finally we're finished, write back colors and bits */ + if ((testerror > testerror2) || (haveAlpha)) { + *blkaddr++ = color1 & 0xff; + *blkaddr++ = color1 >> 8; + *blkaddr++ = color0 & 0xff; + *blkaddr++ = color0 >> 8; + *blkaddr++ = bits2 & 0xff; + *blkaddr++ = ( bits2 >> 8) & 0xff; + *blkaddr++ = ( bits2 >> 16) & 0xff; + *blkaddr = bits2 >> 24; + } + else { + *blkaddr++ = color0 & 0xff; + *blkaddr++ = color0 >> 8; + *blkaddr++ = color1 & 0xff; + *blkaddr++ = color1 >> 8; + *blkaddr++ = bits & 0xff; + *blkaddr++ = ( bits >> 8) & 0xff; + *blkaddr++ = ( bits >> 16) & 0xff; + *blkaddr = bits >> 24; + } +} + +static void encodedxtcolorblockfaster( GLubyte *blkaddr, GLubyte srccolors[4][4][4], + GLint numxpixels, GLint numypixels, GLuint type ) +{ +/* simplistic approach. We need two base colors, simply use the "highest" and the "lowest" color + present in the picture as base colors */ + + /* define lowest and highest color as shortest and longest vector to 0/0/0, though the + vectors are weighted similar to their importance in rgb-luminance conversion + doesn't work too well though... + This seems to be a rather difficult problem */ + + GLubyte *bestcolor[2]; + GLubyte basecolors[2][3]; + GLubyte i, j; + GLuint lowcv, highcv, testcv; + GLboolean haveAlpha = GL_FALSE; + + lowcv = highcv = srccolors[0][0][0] * srccolors[0][0][0] * REDWEIGHT + + srccolors[0][0][1] * srccolors[0][0][1] * GREENWEIGHT + + srccolors[0][0][2] * srccolors[0][0][2] * BLUEWEIGHT; + bestcolor[0] = bestcolor[1] = srccolors[0][0]; + for (j = 0; j < numypixels; j++) { + for (i = 0; i < numxpixels; i++) { + /* don't use this as a base color if the pixel will get black/transparent anyway */ + if ((type != GL_COMPRESSED_RGBA_S3TC_DXT1_EXT) || (srccolors[j][i][3] > ALPHACUT)) { + testcv = srccolors[j][i][0] * srccolors[j][i][0] * REDWEIGHT + + srccolors[j][i][1] * srccolors[j][i][1] * GREENWEIGHT + + srccolors[j][i][2] * srccolors[j][i][2] * BLUEWEIGHT; + if (testcv > highcv) { + highcv = testcv; + bestcolor[1] = srccolors[j][i]; + } + else if (testcv < lowcv) { + lowcv = testcv; + bestcolor[0] = srccolors[j][i]; + } + } + else haveAlpha = GL_TRUE; + } + } + /* make sure the original color values won't get touched... */ + for (j = 0; j < 2; j++) { + for (i = 0; i < 3; i++) { + basecolors[j][i] = bestcolor[j][i]; + } + } + bestcolor[0] = basecolors[0]; + bestcolor[1] = basecolors[1]; + + /* try to find better base colors */ + fancybasecolorsearch(blkaddr, srccolors, bestcolor, numxpixels, numypixels, type, haveAlpha); + /* find the best encoding for these colors, and store the result */ + storedxtencodedblock(blkaddr, srccolors, bestcolor, numxpixels, numypixels, type, haveAlpha); +} + +static void writedxt5encodedalphablock( GLubyte *blkaddr, GLubyte alphabase1, GLubyte alphabase2, + GLubyte alphaenc[16]) +{ + *blkaddr++ = alphabase1; + *blkaddr++ = alphabase2; + *blkaddr++ = alphaenc[0] | (alphaenc[1] << 3) | ((alphaenc[2] & 3) << 6); + *blkaddr++ = (alphaenc[2] >> 2) | (alphaenc[3] << 1) | (alphaenc[4] << 4) | ((alphaenc[5] & 1) << 7); + *blkaddr++ = (alphaenc[5] >> 1) | (alphaenc[6] << 2) | (alphaenc[7] << 5); + *blkaddr++ = alphaenc[8] | (alphaenc[9] << 3) | ((alphaenc[10] & 3) << 6); + *blkaddr++ = (alphaenc[10] >> 2) | (alphaenc[11] << 1) | (alphaenc[12] << 4) | ((alphaenc[13] & 1) << 7); + *blkaddr++ = (alphaenc[13] >> 1) | (alphaenc[14] << 2) | (alphaenc[15] << 5); +} + +static void encodedxt5alpha(GLubyte *blkaddr, GLubyte srccolors[4][4][4], + GLint numxpixels, GLint numypixels) +{ + GLubyte alphabase[2], alphause[2]; + GLshort alphatest[2]; + GLuint alphablockerror1, alphablockerror2, alphablockerror3; + GLubyte i, j, aindex, acutValues[7]; + GLubyte alphaenc1[16], alphaenc2[16], alphaenc3[16]; + GLboolean alphaabsmin = GL_FALSE; + GLboolean alphaabsmax = GL_FALSE; + GLshort alphadist; + + /* find lowest and highest alpha value in block, alphabase[0] lowest, alphabase[1] highest */ + alphabase[0] = 0xff; alphabase[1] = 0x0; + for (j = 0; j < numypixels; j++) { + for (i = 0; i < numxpixels; i++) { + if (srccolors[j][i][3] == 0) + alphaabsmin = GL_TRUE; + else if (srccolors[j][i][3] == 255) + alphaabsmax = GL_TRUE; + else { + if (srccolors[j][i][3] > alphabase[1]) + alphabase[1] = srccolors[j][i][3]; + if (srccolors[j][i][3] < alphabase[0]) + alphabase[0] = srccolors[j][i][3]; + } + } + } + + + if ((alphabase[0] > alphabase[1]) && !(alphaabsmin && alphaabsmax)) { /* one color, either max or min */ + /* shortcut here since it is a very common case (and also avoids later problems) */ + /* || (alphabase[0] == alphabase[1] && !alphaabsmin && !alphaabsmax) */ + /* could also thest for alpha0 == alpha1 (and not min/max), but probably not common, so don't bother */ + + *blkaddr++ = srccolors[0][0][3]; + blkaddr++; + *blkaddr++ = 0; + *blkaddr++ = 0; + *blkaddr++ = 0; + *blkaddr++ = 0; + *blkaddr++ = 0; + *blkaddr++ = 0; +/* fprintf(stderr, "enc0 used\n");*/ + return; + } + + /* find best encoding for alpha0 > alpha1 */ + /* it's possible this encoding is better even if both alphaabsmin and alphaabsmax are true */ + alphablockerror1 = 0x0; + alphablockerror2 = 0xffffffff; + alphablockerror3 = 0xffffffff; + if (alphaabsmin) alphause[0] = 0; + else alphause[0] = alphabase[0]; + if (alphaabsmax) alphause[1] = 255; + else alphause[1] = alphabase[1]; + /* calculate the 7 cut values, just the middle between 2 of the computed alpha values */ + for (aindex = 0; aindex < 7; aindex++) { + /* don't forget here is always rounded down */ + acutValues[aindex] = (alphause[0] * (2*aindex + 1) + alphause[1] * (14 - (2*aindex + 1))) / 14; + } + + for (j = 0; j < numypixels; j++) { + for (i = 0; i < numxpixels; i++) { + /* maybe it's overkill to have the most complicated calculation just for the error + calculation which we only need to figure out if encoding1 or encoding2 is better... */ + if (srccolors[j][i][3] > acutValues[0]) { + alphaenc1[4*j + i] = 0; + alphadist = srccolors[j][i][3] - alphause[1]; + } + else if (srccolors[j][i][3] > acutValues[1]) { + alphaenc1[4*j + i] = 2; + alphadist = srccolors[j][i][3] - (alphause[1] * 6 + alphause[0] * 1) / 7; + } + else if (srccolors[j][i][3] > acutValues[2]) { + alphaenc1[4*j + i] = 3; + alphadist = srccolors[j][i][3] - (alphause[1] * 5 + alphause[0] * 2) / 7; + } + else if (srccolors[j][i][3] > acutValues[3]) { + alphaenc1[4*j + i] = 4; + alphadist = srccolors[j][i][3] - (alphause[1] * 4 + alphause[0] * 3) / 7; + } + else if (srccolors[j][i][3] > acutValues[4]) { + alphaenc1[4*j + i] = 5; + alphadist = srccolors[j][i][3] - (alphause[1] * 3 + alphause[0] * 4) / 7; + } + else if (srccolors[j][i][3] > acutValues[5]) { + alphaenc1[4*j + i] = 6; + alphadist = srccolors[j][i][3] - (alphause[1] * 2 + alphause[0] * 5) / 7; + } + else if (srccolors[j][i][3] > acutValues[6]) { + alphaenc1[4*j + i] = 7; + alphadist = srccolors[j][i][3] - (alphause[1] * 1 + alphause[0] * 6) / 7; + } + else { + alphaenc1[4*j + i] = 1; + alphadist = srccolors[j][i][3] - alphause[0]; + } + alphablockerror1 += alphadist * alphadist; + } + } +/* for (i = 0; i < 16; i++) { + fprintf(stderr, "%d ", alphaenc1[i]); + } + fprintf(stderr, "cutVals "); + for (i = 0; i < 8; i++) { + fprintf(stderr, "%d ", acutValues[i]); + } + fprintf(stderr, "srcVals "); + for (j = 0; j < numypixels; j++) + for (i = 0; i < numxpixels; i++) { + fprintf(stderr, "%d ", srccolors[j][i][3]); + } + + fprintf(stderr, "\n"); + }*/ + /* it's not very likely this encoding is better if both alphaabsmin and alphaabsmax + are false but try it anyway */ + if (alphablockerror1 >= 32) { + + /* don't bother if encoding is already very good, this condition should also imply + we have valid alphabase colors which we absolutely need (alphabase[0] <= alphabase[1]) */ + alphablockerror2 = 0; + for (aindex = 0; aindex < 5; aindex++) { + /* don't forget here is always rounded down */ + acutValues[aindex] = (alphabase[0] * (10 - (2*aindex + 1)) + alphabase[1] * (2*aindex + 1)) / 10; + } + for (j = 0; j < numypixels; j++) { + for (i = 0; i < numxpixels; i++) { + /* maybe it's overkill to have the most complicated calculation just for the error + calculation which we only need to figure out if encoding1 or encoding2 is better... */ + if (srccolors[j][i][3] == 0) { + alphaenc2[4*j + i] = 6; + alphadist = 0; + } + else if (srccolors[j][i][3] == 255) { + alphaenc2[4*j + i] = 7; + alphadist = 0; + } + else if (srccolors[j][i][3] <= acutValues[0]) { + alphaenc2[4*j + i] = 0; + alphadist = srccolors[j][i][3] - alphabase[0]; + } + else if (srccolors[j][i][3] <= acutValues[1]) { + alphaenc2[4*j + i] = 2; + alphadist = srccolors[j][i][3] - (alphabase[0] * 4 + alphabase[1] * 1) / 5; + } + else if (srccolors[j][i][3] <= acutValues[2]) { + alphaenc2[4*j + i] = 3; + alphadist = srccolors[j][i][3] - (alphabase[0] * 3 + alphabase[1] * 2) / 5; + } + else if (srccolors[j][i][3] <= acutValues[3]) { + alphaenc2[4*j + i] = 4; + alphadist = srccolors[j][i][3] - (alphabase[0] * 2 + alphabase[1] * 3) / 5; + } + else if (srccolors[j][i][3] <= acutValues[4]) { + alphaenc2[4*j + i] = 5; + alphadist = srccolors[j][i][3] - (alphabase[0] * 1 + alphabase[1] * 4) / 5; + } + else { + alphaenc2[4*j + i] = 1; + alphadist = srccolors[j][i][3] - alphabase[1]; + } + alphablockerror2 += alphadist * alphadist; + } + } + + + /* skip this if the error is already very small + this encoding is MUCH better on average than #2 though, but expensive! */ + if ((alphablockerror2 > 96) && (alphablockerror1 > 96)) { + GLshort blockerrlin1 = 0; + GLshort blockerrlin2 = 0; + GLubyte nralphainrangelow = 0; + GLubyte nralphainrangehigh = 0; + alphatest[0] = 0xff; + alphatest[1] = 0x0; + /* if we have large range it's likely there are values close to 0/255, try to map them to 0/255 */ + for (j = 0; j < numypixels; j++) { + for (i = 0; i < numxpixels; i++) { + if ((srccolors[j][i][3] > alphatest[1]) && (srccolors[j][i][3] < (255 -(alphabase[1] - alphabase[0]) / 28))) + alphatest[1] = srccolors[j][i][3]; + if ((srccolors[j][i][3] < alphatest[0]) && (srccolors[j][i][3] > (alphabase[1] - alphabase[0]) / 28)) + alphatest[0] = srccolors[j][i][3]; + } + } + /* shouldn't happen too often, don't really care about those degenerated cases */ + if (alphatest[1] <= alphatest[0]) { + alphatest[0] = 1; + alphatest[1] = 254; +/* fprintf(stderr, "only 1 or 0 colors for encoding!\n");*/ + } + for (aindex = 0; aindex < 5; aindex++) { + /* don't forget here is always rounded down */ + acutValues[aindex] = (alphatest[0] * (10 - (2*aindex + 1)) + alphatest[1] * (2*aindex + 1)) / 10; + } + + /* find the "average" difference between the alpha values and the next encoded value. + This is then used to calculate new base values. + Should there be some weighting, i.e. those values closer to alphatest[x] have more weight, + since they will see more improvement, and also because the values in the middle are somewhat + likely to get no improvement at all (because the base values might move in different directions)? + OTOH it would mean the values in the middle are even less likely to get an improvement + */ + for (j = 0; j < numypixels; j++) { + for (i = 0; i < numxpixels; i++) { + if (srccolors[j][i][3] <= alphatest[0] / 2) { + } + else if (srccolors[j][i][3] > ((255 + alphatest[1]) / 2)) { + } + else if (srccolors[j][i][3] <= acutValues[0]) { + blockerrlin1 += (srccolors[j][i][3] - alphatest[0]); + nralphainrangelow += 1; + } + else if (srccolors[j][i][3] <= acutValues[1]) { + blockerrlin1 += (srccolors[j][i][3] - (alphatest[0] * 4 + alphatest[1] * 1) / 5); + blockerrlin2 += (srccolors[j][i][3] - (alphatest[0] * 4 + alphatest[1] * 1) / 5); + nralphainrangelow += 1; + nralphainrangehigh += 1; + } + else if (srccolors[j][i][3] <= acutValues[2]) { + blockerrlin1 += (srccolors[j][i][3] - (alphatest[0] * 3 + alphatest[1] * 2) / 5); + blockerrlin2 += (srccolors[j][i][3] - (alphatest[0] * 3 + alphatest[1] * 2) / 5); + nralphainrangelow += 1; + nralphainrangehigh += 1; + } + else if (srccolors[j][i][3] <= acutValues[3]) { + blockerrlin1 += (srccolors[j][i][3] - (alphatest[0] * 2 + alphatest[1] * 3) / 5); + blockerrlin2 += (srccolors[j][i][3] - (alphatest[0] * 2 + alphatest[1] * 3) / 5); + nralphainrangelow += 1; + nralphainrangehigh += 1; + } + else if (srccolors[j][i][3] <= acutValues[4]) { + blockerrlin1 += (srccolors[j][i][3] - (alphatest[0] * 1 + alphatest[1] * 4) / 5); + blockerrlin2 += (srccolors[j][i][3] - (alphatest[0] * 1 + alphatest[1] * 4) / 5); + nralphainrangelow += 1; + nralphainrangehigh += 1; + } + else { + blockerrlin2 += (srccolors[j][i][3] - alphatest[1]); + nralphainrangehigh += 1; + } + } + } + /* shouldn't happen often, needed to avoid div by zero */ + if (nralphainrangelow == 0) nralphainrangelow = 1; + if (nralphainrangehigh == 0) nralphainrangehigh = 1; + alphatest[0] = alphatest[0] + (blockerrlin1 / nralphainrangelow); +/* fprintf(stderr, "block err lin low %d, nr %d\n", blockerrlin1, nralphainrangelow); + fprintf(stderr, "block err lin high %d, nr %d\n", blockerrlin2, nralphainrangehigh);*/ + /* again shouldn't really happen often... */ + if (alphatest[0] < 0) { + alphatest[0] = 0; +/* fprintf(stderr, "adj alpha base val to 0\n");*/ + } + alphatest[1] = alphatest[1] + (blockerrlin2 / nralphainrangehigh); + if (alphatest[1] > 255) { + alphatest[1] = 255; +/* fprintf(stderr, "adj alpha base val to 255\n");*/ + } + + alphablockerror3 = 0; + for (aindex = 0; aindex < 5; aindex++) { + /* don't forget here is always rounded down */ + acutValues[aindex] = (alphatest[0] * (10 - (2*aindex + 1)) + alphatest[1] * (2*aindex + 1)) / 10; + } + for (j = 0; j < numypixels; j++) { + for (i = 0; i < numxpixels; i++) { + /* maybe it's overkill to have the most complicated calculation just for the error + calculation which we only need to figure out if encoding1 or encoding2 is better... */ + if (srccolors[j][i][3] <= alphatest[0] / 2) { + alphaenc3[4*j + i] = 6; + alphadist = srccolors[j][i][3]; + } + else if (srccolors[j][i][3] > ((255 + alphatest[1]) / 2)) { + alphaenc3[4*j + i] = 7; + alphadist = 255 - srccolors[j][i][3]; + } + else if (srccolors[j][i][3] <= acutValues[0]) { + alphaenc3[4*j + i] = 0; + alphadist = srccolors[j][i][3] - alphatest[0]; + } + else if (srccolors[j][i][3] <= acutValues[1]) { + alphaenc3[4*j + i] = 2; + alphadist = srccolors[j][i][3] - (alphatest[0] * 4 + alphatest[1] * 1) / 5; + } + else if (srccolors[j][i][3] <= acutValues[2]) { + alphaenc3[4*j + i] = 3; + alphadist = srccolors[j][i][3] - (alphatest[0] * 3 + alphatest[1] * 2) / 5; + } + else if (srccolors[j][i][3] <= acutValues[3]) { + alphaenc3[4*j + i] = 4; + alphadist = srccolors[j][i][3] - (alphatest[0] * 2 + alphatest[1] * 3) / 5; + } + else if (srccolors[j][i][3] <= acutValues[4]) { + alphaenc3[4*j + i] = 5; + alphadist = srccolors[j][i][3] - (alphatest[0] * 1 + alphatest[1] * 4) / 5; + } + else { + alphaenc3[4*j + i] = 1; + alphadist = srccolors[j][i][3] - alphatest[1]; + } + alphablockerror3 += alphadist * alphadist; + } + } + } + } + /* write the alpha values and encoding back. */ + if ((alphablockerror1 <= alphablockerror2) && (alphablockerror1 <= alphablockerror3)) { +/* if (alphablockerror1 > 96) fprintf(stderr, "enc1 used, error %d\n", alphablockerror1);*/ + writedxt5encodedalphablock( blkaddr, alphause[1], alphause[0], alphaenc1 ); + } + else if (alphablockerror2 <= alphablockerror3) { +/* if (alphablockerror2 > 96) fprintf(stderr, "enc2 used, error %d\n", alphablockerror2);*/ + writedxt5encodedalphablock( blkaddr, alphabase[0], alphabase[1], alphaenc2 ); + } + else { +/* fprintf(stderr, "enc3 used, error %d\n", alphablockerror3);*/ + writedxt5encodedalphablock( blkaddr, (GLubyte)alphatest[0], (GLubyte)alphatest[1], alphaenc3 ); + } +} + +static void extractsrccolors( GLubyte srcpixels[4][4][4], const GLchan *srcaddr, + GLint srcRowStride, GLint numxpixels, GLint numypixels, GLint comps) +{ + GLubyte i, j, c; + const GLchan *curaddr; + for (j = 0; j < numypixels; j++) { + curaddr = srcaddr + j * srcRowStride * comps; + for (i = 0; i < numxpixels; i++) { + for (c = 0; c < comps; c++) { + srcpixels[j][i][c] = *curaddr++ / (CHAN_MAX / 255); + } + } + } +} + + +void tx_compress_dxtn(GLint srccomps, GLint width, GLint height, const GLubyte *srcPixData, + GLenum destFormat, GLubyte *dest, GLint dstRowStride) +{ + GLubyte *blkaddr = dest; + GLubyte srcpixels[4][4][4]; + const GLchan *srcaddr = srcPixData; + GLint numxpixels, numypixels; + GLint i, j; + GLint dstRowDiff; + + switch (destFormat) { + case GL_COMPRESSED_RGB_S3TC_DXT1_EXT: + case GL_COMPRESSED_RGBA_S3TC_DXT1_EXT: + /* hmm we used to get called without dstRowStride... */ + dstRowDiff = dstRowStride >= (width * 2) ? dstRowStride - (((width + 3) & ~3) * 2) : 0; +/* fprintf(stderr, "dxt1 tex width %d tex height %d dstRowStride %d\n", + width, height, dstRowStride); */ + for (j = 0; j < height; j += 4) { + if (height > j + 3) numypixels = 4; + else numypixels = height - j; + srcaddr = srcPixData + j * width * srccomps; + for (i = 0; i < width; i += 4) { + if (width > i + 3) numxpixels = 4; + else numxpixels = width - i; + extractsrccolors(srcpixels, srcaddr, width, numxpixels, numypixels, srccomps); + encodedxtcolorblockfaster(blkaddr, srcpixels, numxpixels, numypixels, destFormat); + srcaddr += srccomps * numxpixels; + blkaddr += 8; + } + blkaddr += dstRowDiff; + } + break; + case GL_COMPRESSED_RGBA_S3TC_DXT3_EXT: + dstRowDiff = dstRowStride >= (width * 4) ? dstRowStride - (((width + 3) & ~3) * 4) : 0; +/* fprintf(stderr, "dxt3 tex width %d tex height %d dstRowStride %d\n", + width, height, dstRowStride); */ + for (j = 0; j < height; j += 4) { + if (height > j + 3) numypixels = 4; + else numypixels = height - j; + srcaddr = srcPixData + j * width * srccomps; + for (i = 0; i < width; i += 4) { + if (width > i + 3) numxpixels = 4; + else numxpixels = width - i; + extractsrccolors(srcpixels, srcaddr, width, numxpixels, numypixels, srccomps); + *blkaddr++ = (srcpixels[0][0][3] >> 4) | (srcpixels[0][1][3] & 0xf0); + *blkaddr++ = (srcpixels[0][2][3] >> 4) | (srcpixels[0][3][3] & 0xf0); + *blkaddr++ = (srcpixels[1][0][3] >> 4) | (srcpixels[1][1][3] & 0xf0); + *blkaddr++ = (srcpixels[1][2][3] >> 4) | (srcpixels[1][3][3] & 0xf0); + *blkaddr++ = (srcpixels[2][0][3] >> 4) | (srcpixels[2][1][3] & 0xf0); + *blkaddr++ = (srcpixels[2][2][3] >> 4) | (srcpixels[2][3][3] & 0xf0); + *blkaddr++ = (srcpixels[3][0][3] >> 4) | (srcpixels[3][1][3] & 0xf0); + *blkaddr++ = (srcpixels[3][2][3] >> 4) | (srcpixels[3][3][3] & 0xf0); + encodedxtcolorblockfaster(blkaddr, srcpixels, numxpixels, numypixels, destFormat); + srcaddr += srccomps * numxpixels; + blkaddr += 8; + } + blkaddr += dstRowDiff; + } + break; + case GL_COMPRESSED_RGBA_S3TC_DXT5_EXT: + dstRowDiff = dstRowStride >= (width * 4) ? dstRowStride - (((width + 3) & ~3) * 4) : 0; +/* fprintf(stderr, "dxt5 tex width %d tex height %d dstRowStride %d\n", + width, height, dstRowStride); */ + for (j = 0; j < height; j += 4) { + if (height > j + 3) numypixels = 4; + else numypixels = height - j; + srcaddr = srcPixData + j * width * srccomps; + for (i = 0; i < width; i += 4) { + if (width > i + 3) numxpixels = 4; + else numxpixels = width - i; + extractsrccolors(srcpixels, srcaddr, width, numxpixels, numypixels, srccomps); + encodedxt5alpha(blkaddr, srcpixels, numxpixels, numypixels); + encodedxtcolorblockfaster(blkaddr + 8, srcpixels, numxpixels, numypixels, destFormat); + srcaddr += srccomps * numxpixels; + blkaddr += 16; + } + blkaddr += dstRowDiff; + } + break; + default: + fprintf(stderr, "libdxtn: Bad dstFormat %d in tx_compress_dxtn\n", destFormat); + return; + } +} + + diff --git a/dll/3rdparty/dxtn/texstore.c b/dll/3rdparty/dxtn/txc_dxtn.h similarity index 53% rename from dll/3rdparty/dxtn/texstore.c rename to dll/3rdparty/dxtn/txc_dxtn.h index 6349680745..cd1095bb70 100644 --- a/dll/3rdparty/dxtn/texstore.c +++ b/dll/3rdparty/dxtn/txc_dxtn.h @@ -1,8 +1,8 @@ /* - * Mesa 3-D graphics library - * Version: 6.3 + * libtxc_dxtn + * Version: 1.0 * - * Copyright (C) 1999-2004 Brian Paul All Rights Reserved. + * Copyright (C) 2004 Roland Scheidegger All Rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and associated documentation files (the "Software"), @@ -22,33 +22,30 @@ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ +#ifndef _TXC_DXTN_H +#define _TXC_DXTN_H -#include <assert.h> +#include <GL/gl.h> -#include "types.h" -#include "internal.h" +typedef GLubyte GLchan; +#define UBYTE_TO_CHAN(b) (b) +#define CHAN_MAX 255 +#define RCOMP 0 +#define GCOMP 1 +#define BCOMP 2 +#define ACOMP 3 +void fetch_2d_texel_rgb_dxt1(GLint srcRowStride, const GLubyte *pixdata, + GLint i, GLint j, GLvoid *texel); +void fetch_2d_texel_rgba_dxt1(GLint srcRowStride, const GLubyte *pixdata, + GLint i, GLint j, GLvoid *texel); +void fetch_2d_texel_rgba_dxt3(GLint srcRowStride, const GLubyte *pixdata, + GLint i, GLint j, GLvoid *texel); +void fetch_2d_texel_rgba_dxt5(GLint srcRowStride, const GLubyte *pixdata, + GLint i, GLint j, GLvoid *texel); -void -_mesa_upscale_teximage2d (unsigned int inWidth, unsigned int inHeight, - unsigned int outWidth, unsigned int outHeight, - unsigned int comps, - const byte *src, int srcRowStride, - byte *dest) -{ - unsigned int i, j, k; +void tx_compress_dxtn(GLint srccomps, GLint width, GLint height, + const GLubyte *srcPixData, GLenum destformat, + GLubyte *dest, GLint dstRowStride); - assert(outWidth >= inWidth); - assert(outHeight >= inHeight); - - for (i = 0; i < outHeight; i++) { - const int ii = i % inHeight; - for (j = 0; j < outWidth; j++) { - const int jj = j % inWidth; - for (k = 0; k < comps; k++) { - dest[(i * outWidth + j) * comps + k] - = src[ii * srcRowStride + jj * comps + k]; - } - } - } -} +#endif /* _TXC_DXTN_H */ diff --git a/dll/3rdparty/dxtn/txc_fetch_dxtn.c b/dll/3rdparty/dxtn/txc_fetch_dxtn.c new file mode 100644 index 0000000000..7f0db56a15 --- /dev/null +++ b/dll/3rdparty/dxtn/txc_fetch_dxtn.c @@ -0,0 +1,243 @@ +/* + * libtxc_dxtn + * Version: 1.0 + * + * Copyright (C) 2004 Roland Scheidegger All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN + * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ + +#include <stdio.h> +#include "txc_dxtn.h" + +#define EXP5TO8R(packedcol) \ + ((((packedcol) >> 8) & 0xf8) | (((packedcol) >> 13) & 0x7)) + +#define EXP6TO8G(packedcol) \ + ((((packedcol) >> 3) & 0xfc) | (((packedcol) >> 9) & 0x3)) + +#define EXP5TO8B(packedcol) \ + ((((packedcol) << 3) & 0xf8) | (((packedcol) >> 2) & 0x7)) + +#define EXP4TO8(col) \ + ((col) | ((col) << 4)) + +/* inefficient. To be efficient, it would be necessary to decode 16 pixels at once */ + +static void dxt135_decode_imageblock ( const GLubyte *img_block_src, + GLint i, GLint j, GLuint dxt_type, GLvoid *texel ) { + GLchan *rgba = (GLchan *) texel; + const GLushort color0 = img_block_src[0] | (img_block_src[1] << 8); + const GLushort color1 = img_block_src[2] | (img_block_src[3] << 8); + const GLuint bits = img_block_src[4] | (img_block_src[5] << 8) | + (img_block_src[6] << 16) | (img_block_src[7] << 24); + /* What about big/little endian? */ + GLubyte bit_pos = 2 * (j * 4 + i) ; + GLubyte code = (GLubyte) ((bits >> bit_pos) & 3); + + rgba[ACOMP] = CHAN_MAX; + switch (code) { + case 0: + rgba[RCOMP] = UBYTE_TO_CHAN( EXP5TO8R(color0) ); + rgba[GCOMP] = UBYTE_TO_CHAN( EXP6TO8G(color0) ); + rgba[BCOMP] = UBYTE_TO_CHAN( EXP5TO8B(color0) ); + break; + case 1: + rgba[RCOMP] = UBYTE_TO_CHAN( EXP5TO8R(color1) ); + rgba[GCOMP] = UBYTE_TO_CHAN( EXP6TO8G(color1) ); + rgba[BCOMP] = UBYTE_TO_CHAN( EXP5TO8B(color1) ); + break; + case 2: + if ((dxt_type > 1) || (color0 > color1)) { + rgba[RCOMP] = UBYTE_TO_CHAN( ((EXP5TO8R(color0) * 2 + EXP5TO8R(color1)) / 3) ); + rgba[GCOMP] = UBYTE_TO_CHAN( ((EXP6TO8G(color0) * 2 + EXP6TO8G(color1)) / 3) ); + rgba[BCOMP] = UBYTE_TO_CHAN( ((EXP5TO8B(color0) * 2 + EXP5TO8B(color1)) / 3) ); + } + else { + rgba[RCOMP] = UBYTE_TO_CHAN( ((EXP5TO8R(color0) + EXP5TO8R(color1)) / 2) ); + rgba[GCOMP] = UBYTE_TO_CHAN( ((EXP6TO8G(color0) + EXP6TO8G(color1)) / 2) ); + rgba[BCOMP] = UBYTE_TO_CHAN( ((EXP5TO8B(color0) + EXP5TO8B(color1)) / 2) ); + } + break; + case 3: + if ((dxt_type > 1) || (color0 > color1)) { + rgba[RCOMP] = UBYTE_TO_CHAN( ((EXP5TO8R(color0) + EXP5TO8R(color1) * 2) / 3) ); + rgba[GCOMP] = UBYTE_TO_CHAN( ((EXP6TO8G(color0) + EXP6TO8G(color1) * 2) / 3) ); + rgba[BCOMP] = UBYTE_TO_CHAN( ((EXP5TO8B(color0) + EXP5TO8B(color1) * 2) / 3) ); + } + else { + rgba[RCOMP] = 0; + rgba[GCOMP] = 0; + rgba[BCOMP] = 0; + if (dxt_type == 1) rgba[ACOMP] = UBYTE_TO_CHAN(0); + } + break; + default: + /* CANNOT happen (I hope) */ + break; + } +} + + +void fetch_2d_texel_rgb_dxt1(GLint srcRowStride, const GLubyte *pixdata, + GLint i, GLint j, GLvoid *texel) +{ + /* Extract the (i,j) pixel from pixdata and return it + * in texel[RCOMP], texel[GCOMP], texel[BCOMP], texel[ACOMP]. + */ + + const GLubyte *blksrc = (pixdata + ((srcRowStride + 3) / 4 * (j / 4) + (i / 4)) * 8); + dxt135_decode_imageblock(blksrc, (i&3), (j&3), 0, texel); +} + + +void fetch_2d_texel_rgba_dxt1(GLint srcRowStride, const GLubyte *pixdata, + GLint i, GLint j, GLvoid *texel) +{ + /* Extract the (i,j) pixel from pixdata and return it + * in texel[RCOMP], texel[GCOMP], texel[BCOMP], texel[ACOMP]. + */ + + const GLubyte *blksrc = (pixdata + ((srcRowStride + 3) / 4 * (j / 4) + (i / 4)) * 8); + dxt135_decode_imageblock(blksrc, (i&3), (j&3), 1, texel); +} + +void fetch_2d_texel_rgba_dxt3(GLint srcRowStride, const GLubyte *pixdata, + GLint i, GLint j, GLvoid *texel) { + + /* Extract the (i,j) pixel from pixdata and return it + * in texel[RCOMP], texel[GCOMP], texel[BCOMP], texel[ACOMP]. + */ + + GLchan *rgba = (GLchan *) texel; + const GLubyte *blksrc = (pixdata + ((srcRowStride + 3) / 4 * (j / 4) + (i / 4)) * 16); +#if 0 + /* Simple 32bit version. */ +/* that's pretty brain-dead for a single pixel, isn't it? */ + const GLubyte bit_pos = 4 * ((j&3) * 4 + (i&3)); + const GLuint alpha_low = blksrc[0] | (blksrc[1] << 8) | (blksrc[2] << 16) | (blksrc[3] << 24); + const GLuint alpha_high = blksrc[4] | (blksrc[5] << 8) | (blksrc[6] << 16) | (blksrc[7] << 24); + + dxt135_decode_imageblock(blksrc + 8, (i&3), (j&3), 2, texel); + if (bit_pos < 32) + rgba[ACOMP] = UBYTE_TO_CHAN( (GLubyte)(EXP4TO8((alpha_low >> bit_pos) & 15)) ); + else + rgba[ACOMP] = UBYTE_TO_CHAN( (GLubyte)(EXP4TO8((alpha_high >> (bit_pos - 32)) & 15)) ); +#endif +#if 1 +/* TODO test this! */ + const GLubyte anibble = (blksrc[((j&3) * 4 + (i&3)) / 2] >> (4 * (i&1))) & 0xf; + dxt135_decode_imageblock(blksrc + 8, (i&3), (j&3), 2, texel); + rgba[ACOMP] = UBYTE_TO_CHAN( (GLubyte)(EXP4TO8(anibble)) ); +#endif + +} + +void fetch_2d_texel_rgba_dxt5(GLint srcRowStride, const GLubyte *pixdata, + GLint i, GLint j, GLvoid *texel) { + + /* Extract the (i,j) pixel from pixdata and return it + * in texel[RCOMP], texel[GCOMP], texel[BCOMP], texel[ACOMP]. + */ + + GLchan *rgba = (GLchan *) texel; + const GLubyte *blksrc = (pixdata + ((srcRowStride + 3) / 4 * (j / 4) + (i / 4)) * 16); + const GLubyte alpha0 = blksrc[0]; + const GLubyte alpha1 = blksrc[1]; +#if 0 + const GLubyte bit_pos = 3 * ((j&3) * 4 + (i&3)); + /* simple 32bit version */ + const GLuint bits_low = blksrc[2] | (blksrc[3] << 8) | (blksrc[4] << 16) | (blksrc[5] << 24); + const GLuint bits_high = blksrc[6] | (blksrc[7] << 8); + GLubyte code; + + if (bit_pos < 30) + code = (GLubyte) ((bits_low >> bit_pos) & 7); + else if (bit_pos == 30) + code = (GLubyte) ((bits_low >> 30) & 3) | ((bits_high << 2) & 4); + else + code = (GLubyte) ((bits_high >> (bit_pos - 32)) & 7); +#endif +#if 1 +/* TODO test this! */ + const GLubyte bit_pos = ((j&3) * 4 + (i&3)) * 3; + const GLubyte acodelow = blksrc[2 + bit_pos / 8]; + const GLubyte acodehigh = blksrc[3 + bit_pos / 8]; + const GLubyte code = (acodelow >> (bit_pos & 0x7) | + (acodehigh << (8 - (bit_pos & 0x7)))) & 0x7; +#endif + dxt135_decode_imageblock(blksrc + 8, (i&3), (j&3), 2, texel); +#if 0 + if (alpha0 > alpha1) { + switch (code) { + case 0: + rgba[ACOMP] = UBYTE_TO_CHAN( alpha0 ); + break; + case 1: + rgba[ACOMP] = UBYTE_TO_CHAN( alpha1 ); + break; + case 2: + case 3: + case 4: + case 5: + case 6: + case 7: + rgba[ACOMP] = UBYTE_TO_CHAN( ((alpha0 * (8 - code) + (alpha1 * (code - 1))) / 7) ); + break; + } + } + else { + switch (code) { + case 0: + rgba[ACOMP] = UBYTE_TO_CHAN( alpha0 ); + break; + case 1: + rgba[ACOMP] = UBYTE_TO_CHAN( alpha1 ); + break; + case 2: + case 3: + case 4: + case 5: + rgba[ACOMP] = UBYTE_TO_CHAN( ((alpha0 * (6 - code) + (alpha1 * (code - 1))) / 5) ); + break; + case 6: + rgba[ACOMP] = 0; + break; + case 7: + rgba[ACOMP] = CHAN_MAX; + break; + } + } +#endif +/* not sure. Which version is faster? */ +#if 1 +/* TODO test this */ + if (code == 0) + rgba[ACOMP] = UBYTE_TO_CHAN( alpha0 ); + else if (code == 1) + rgba[ACOMP] = UBYTE_TO_CHAN( alpha1 ); + else if (alpha0 > alpha1) + rgba[ACOMP] = UBYTE_TO_CHAN( ((alpha0 * (8 - code) + (alpha1 * (code - 1))) / 7) ); + else if (code < 6) + rgba[ACOMP] = UBYTE_TO_CHAN( ((alpha0 * (6 - code) + (alpha1 * (code - 1))) / 5) ); + else if (code == 6) + rgba[ACOMP] = 0; + else + rgba[ACOMP] = CHAN_MAX; +#endif +} diff --git a/dll/3rdparty/dxtn/types.h b/dll/3rdparty/dxtn/types.h deleted file mode 100644 index 40e7153ab3..0000000000 --- a/dll/3rdparty/dxtn/types.h +++ /dev/null @@ -1,11 +0,0 @@ -#ifndef TYPES_H_included -#define TYPES_H_included - -/*****************************************************************************\ - * 32bit types -\*****************************************************************************/ -typedef unsigned char byte; /* 8-bit */ -typedef unsigned short word; /* 16-bit */ -typedef unsigned int dword; /* 32-bit */ - -#endif diff --git a/dll/3rdparty/dxtn/wrapper.c b/dll/3rdparty/dxtn/wrapper.c deleted file mode 100644 index 7bc8d610ad..0000000000 --- a/dll/3rdparty/dxtn/wrapper.c +++ /dev/null @@ -1,110 +0,0 @@ -/* - * Texture compression - * Version: 1.0 - * - * Copyright (C) 2004 Daniel Borca All Rights Reserved. - * - * this is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2, or (at your option) - * any later version. - * - * this is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with GNU Make; see the file COPYING. If not, write to - * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. - */ - - -#include <assert.h> - -#include "types.h" -#include "internal.h" -#include "dxtn.h" - - -#define GL_COMPRESSED_RGB_S3TC_DXT1_EXT 0x83F0 -#define GL_COMPRESSED_RGBA_S3TC_DXT1_EXT 0x83F1 -#define GL_COMPRESSED_RGBA_S3TC_DXT3_EXT 0x83F2 -#define GL_COMPRESSED_RGBA_S3TC_DXT5_EXT 0x83F3 - - -TAPI void TAPIENTRY -fetch_2d_texel_rgb_dxt1 (int texImage_RowStride, - const byte *texImage_Data, - int i, int j, - byte *texel) -{ - dxt1_rgb_decode_1(texImage_Data, texImage_RowStride, i, j, texel); -} - - -TAPI void TAPIENTRY -fetch_2d_texel_rgba_dxt1 (int texImage_RowStride, - const byte *texImage_Data, - int i, int j, - byte *texel) -{ - dxt1_rgba_decode_1(texImage_Data, texImage_RowStride, i, j, texel); -} - - -TAPI void TAPIENTRY -fetch_2d_texel_rgba_dxt3 (int texImage_RowStride, - const byte *texImage_Data, - int i, int j, - byte *texel) -{ - dxt3_rgba_decode_1(texImage_Data, texImage_RowStride, i, j, texel); -} - - -TAPI void TAPIENTRY -fetch_2d_texel_rgba_dxt5 (int texImage_RowStride, - const byte *texImage_Data, - int i, int j, - byte *texel) -{ - dxt5_rgba_decode_1(texImage_Data, texImage_RowStride, i, j, texel); -} - - -TAPI void TAPIENTRY -tx_compress_dxtn (int srccomps, int width, int height, - const byte *source, int destformat, byte *dest, - int destRowStride) -{ - int srcRowStride = width * srccomps; - int rv; - - switch (destformat) { - case GL_COMPRESSED_RGB_S3TC_DXT1_EXT: - rv = dxt1_rgb_encode(width, height, srccomps, - source, srcRowStride, - dest, destRowStride); - break; - case GL_COMPRESSED_RGBA_S3TC_DXT1_EXT: - rv = dxt1_rgba_encode(width, height, srccomps, - source, srcRowStride, - dest, destRowStride); - break; - case GL_COMPRESSED_RGBA_S3TC_DXT3_EXT: - rv = dxt3_rgba_encode(width, height, srccomps, - source, srcRowStride, - dest, destRowStride); - break; - case GL_COMPRESSED_RGBA_S3TC_DXT5_EXT: - rv = dxt5_rgba_encode(width, height, srccomps, - source, srcRowStride, - dest, destRowStride); - break; - default: - assert(0); - } - - /*return rv;*/ -} diff --git a/sdk/cmake/config-amd64.cmake b/sdk/cmake/config-amd64.cmake index e7516787f9..95d9fe2f93 100644 --- a/sdk/cmake/config-amd64.cmake +++ b/sdk/cmake/config-amd64.cmake @@ -37,12 +37,6 @@ set(_ELF_ FALSE CACHE BOOL "Whether to compile support for ELF files. Do not enable unless you know what you're doing.") -set(NSWPAT FALSE CACHE BOOL -"Whether to compile apps/libs with features covered software patents or not. -If you live in a country where software patents are valid/apply, don't -enable this (except they/you purchased a license from the patent owner). -This settings is disabled (0) by default.") - set(USERMODE TRUE CACHE BOOL "Whether to compile any usermode parts. This is while kernel mode is under heavy development and usermode part not relevant for bootcd.") diff --git a/sdk/cmake/config-arm.cmake b/sdk/cmake/config-arm.cmake index 05e532d57c..c260fc1900 100644 --- a/sdk/cmake/config-arm.cmake +++ b/sdk/cmake/config-arm.cmake @@ -38,12 +38,6 @@ set(_ELF_ FALSE CACHE BOOL "Whether to compile support for ELF files. Do not enable unless you know what you're doing.") -set(NSWPAT FALSE CACHE BOOL -"Whether to compile apps/libs with features covered software patents or not. -If you live in a country where software patents are valid/apply, don't -enable this (except they/you purchased a license from the patent owner). -This settings is disabled (0) by default.") - set(BUILD_MP TRUE CACHE BOOL "Whether to compile the multi processor versions for ntoskrnl and hal.") diff --git a/sdk/cmake/config.cmake b/sdk/cmake/config.cmake index 3fc9ce212e..7b296996ad 100644 --- a/sdk/cmake/config.cmake +++ b/sdk/cmake/config.cmake @@ -58,12 +58,6 @@ set(_ELF_ FALSE CACHE BOOL "Whether to compile support for ELF files. Do not enable unless you know what you're doing.") -set(NSWPAT FALSE CACHE BOOL -"Whether to build apps/libs with features covered by software patents. -If you live in a country where software patents are valid/apply, don't -enable this (except they/you purchased a license from the patent owner). -This setting is disabled by default.") - set(BUILD_MP TRUE CACHE BOOL "Whether to build the multiprocessor versions of NTOSKRNL and HAL.")
7 years
1
0
0
0
[reactos] 14/14: [BOOT] Add VBox debug to livecd.ini
by Timo Kreuzer
https://git.reactos.org/?p=reactos.git;a=commitdiff;h=84c26953e49ff0eda4c56…
commit 84c26953e49ff0eda4c5608295f23c164c914bab Author: Timo Kreuzer <timo.kreuzer(a)reactos.org> AuthorDate: Tue Dec 19 18:30:13 2017 +0100 [BOOT] Add VBox debug to livecd.ini --- boot/bootdata/livecd.ini | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/boot/bootdata/livecd.ini b/boot/bootdata/livecd.ini index 17a60e9253..914ebf66fc 100644 --- a/boot/bootdata/livecd.ini +++ b/boot/bootdata/livecd.ini @@ -27,6 +27,7 @@ TimeText=Seconds until highlighted choice will be started automatically: [Operating Systems] LiveCD="LiveCD" LiveCD_Debug="LiveCD (Debug)" +LiveCD_VBoxDebug="LiveCD (VBox Debug)" LiveCD_Screen="LiveCD (Screen)" LiveCD_LogFile="LiveCD (Log file)" @@ -40,6 +41,11 @@ BootType=Windows2003 SystemPath=\reactos Options=/DEBUG /DEBUGPORT=COM1 /BAUDRATE=115200 /SOS /MININT +[LiveCD_VBoxDebug] +BootType=Windows2003 +SystemPath=\reactos +Options=/DEBUG /DEBUGPORT=VBOX /SOS /MININT + [LiveCD_Screen] BootType=Windows2003 SystemPath=\reactos
7 years
1
0
0
0
[reactos] 13/14: [NTOS:MM] Fix a bug in MiBuildPfnDatabase MxPfnAllocation is in pages, not in bytes!
by Timo Kreuzer
https://git.reactos.org/?p=reactos.git;a=commitdiff;h=12e2c48a25240c05b73dc…
commit 12e2c48a25240c05b73dcec86ce8ae9370b59b1c Author: Timo Kreuzer <timo.kreuzer(a)reactos.org> AuthorDate: Tue Dec 19 15:17:35 2017 +0100 [NTOS:MM] Fix a bug in MiBuildPfnDatabase MxPfnAllocation is in pages, not in bytes! --- ntoskrnl/mm/amd64/init.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ntoskrnl/mm/amd64/init.c b/ntoskrnl/mm/amd64/init.c index 2acdf596e6..1f912623a2 100644 --- a/ntoskrnl/mm/amd64/init.c +++ b/ntoskrnl/mm/amd64/init.c @@ -610,9 +610,9 @@ MiBuildPfnDatabase(IN PLOADER_PARAMETER_BLOCK LoaderBlock) /* Map the PDEs and PPEs for the pfn database (ignore holes) */ #if (_MI_PAGING_LEVELS >= 3) - MiMapPPEs(MmPfnDatabase, (PUCHAR)MmPfnDatabase + MxPfnAllocation - 1); + MiMapPPEs(MmPfnDatabase, (PUCHAR)MmPfnDatabase + (MxPfnAllocation * PAGE_SIZE) - 1); #endif - MiMapPDEs(MmPfnDatabase, (PUCHAR)MmPfnDatabase + MxPfnAllocation - 1); + MiMapPDEs(MmPfnDatabase, (PUCHAR)MmPfnDatabase + (MxPfnAllocation * PAGE_SIZE) - 1); /* First initialize the color tables */ MiInitializeColorTables();
7 years
1
0
0
0
[reactos] 12/14: [NTOS:MM] Make debug code in MmArmInitSystem portable
by Timo Kreuzer
https://git.reactos.org/?p=reactos.git;a=commitdiff;h=18cd763160d92df9e70a7…
commit 18cd763160d92df9e70a7ed21a487e4839678372 Author: Timo Kreuzer <timo.kreuzer(a)reactos.org> AuthorDate: Tue Dec 19 15:16:54 2017 +0100 [NTOS:MM] Make debug code in MmArmInitSystem portable --- ntoskrnl/include/internal/arm/mm.h | 1 + ntoskrnl/include/internal/i386/mm.h | 1 + ntoskrnl/mm/ARM3/mminit.c | 6 ++---- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/ntoskrnl/include/internal/arm/mm.h b/ntoskrnl/include/internal/arm/mm.h index ade2bff25e..71468cce56 100644 --- a/ntoskrnl/include/internal/arm/mm.h +++ b/ntoskrnl/include/internal/arm/mm.h @@ -14,6 +14,7 @@ #define MI_PAGED_POOL_START (PVOID)0xE1000000 #define MI_NONPAGED_POOL_END (PVOID)0xFFBE0000 #define MI_DEBUG_MAPPING (PVOID)0xFFBFF000 +#define MI_HIGHEST_SYSTEM_ADDRESS (PVOID)0xFFFFFFFF #define PTE_PER_PAGE 256 #define PDE_PER_PAGE 4096 diff --git a/ntoskrnl/include/internal/i386/mm.h b/ntoskrnl/include/internal/i386/mm.h index aae223cf15..19ce1c82a6 100644 --- a/ntoskrnl/include/internal/i386/mm.h +++ b/ntoskrnl/include/internal/i386/mm.h @@ -23,6 +23,7 @@ #define MI_PAGED_POOL_START (PVOID)0xE1000000 #define MI_NONPAGED_POOL_END (PVOID)0xFFBE0000 #define MI_DEBUG_MAPPING (PVOID)0xFFBFF000 +#define MI_HIGHEST_SYSTEM_ADDRESS (PVOID)0xFFFFFFFF /* FIXME: These are different for PAE */ #define PTE_BASE 0xC0000000 diff --git a/ntoskrnl/mm/ARM3/mminit.c b/ntoskrnl/mm/ARM3/mminit.c index 0ed42eb14a..44f50b085b 100644 --- a/ntoskrnl/mm/ARM3/mminit.c +++ b/ntoskrnl/mm/ARM3/mminit.c @@ -2118,9 +2118,8 @@ MmArmInitSystem(IN ULONG Phase, TestPte = MiProtoPteToPte(&TempPte); ASSERT(PointerPte == TestPte); -#ifndef _M_AMD64 // Not working on x64 for obvoius reason /* Try a bunch of random addresses near the end of the address space */ - PointerPte = (PMMPTE)0xFFFC8000; + PointerPte = (PMMPTE)((ULONG_PTR)MI_HIGHEST_SYSTEM_ADDRESS - 0x37FFF); for (j = 0; j < 20; j += 1) { MI_MAKE_PROTOTYPE_PTE(&TempPte, PointerPte); @@ -2130,11 +2129,10 @@ MmArmInitSystem(IN ULONG Phase, } /* Subsection PTEs are always in nonpaged pool, pick a random address to try */ - PointerPte = (PMMPTE)0xFFAACBB8; + PointerPte = (PMMPTE)((ULONG_PTR)MmNonPagedPoolStart + (MmSizeOfNonPagedPoolInBytes / 2)); MI_MAKE_SUBSECTION_PTE(&TempPte, PointerPte); TestPte = MiSubsectionPteToSubsection(&TempPte); ASSERT(PointerPte == TestPte); -#endif #endif /* Loop all 8 standby lists */
7 years
1
0
0
0
[reactos] 11/14: [NTOS:MM] Implement x64 version of MI_MAKE_SUBSECTION_PTE
by Timo Kreuzer
https://git.reactos.org/?p=reactos.git;a=commitdiff;h=11c78f701dabaa098f80d…
commit 11c78f701dabaa098f80dfea2e259861b02c80e0 Author: Timo Kreuzer <timo.kreuzer(a)reactos.org> AuthorDate: Tue Dec 19 15:16:04 2017 +0100 [NTOS:MM] Implement x64 version of MI_MAKE_SUBSECTION_PTE --- ntoskrnl/include/internal/amd64/mm.h | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/ntoskrnl/include/internal/amd64/mm.h b/ntoskrnl/include/internal/amd64/mm.h index 0f5f3b7c03..2248ab490e 100644 --- a/ntoskrnl/include/internal/amd64/mm.h +++ b/ntoskrnl/include/internal/amd64/mm.h @@ -242,10 +242,18 @@ MiPxeToAddress(PMMPTE PointerPxe) FORCEINLINE VOID -MI_MAKE_SUBSECTION_PTE(IN PMMPTE NewPte, - IN PVOID Segment) +MI_MAKE_SUBSECTION_PTE( + _Out_ PMMPTE NewPte, + _In_ PVOID Segment) { - ASSERT(FALSE); + ULONG_PTR Offset; + + /* Mark this as a prototype */ + NewPte->u.Long = 0; + NewPte->u.Subsect.Prototype = 1; + + /* Store the lower 48 bits of the Segment address */ + NewPte->u.Subsect.SubsectionAddress = ((ULONG_PTR)Segment & 0x0000FFFFFFFFFFFF); } FORCEINLINE
7 years
1
0
0
0
[reactos] 10/14: [NTOS:PS] Skip backtrace on non-x86
by Ivan Labutin
https://git.reactos.org/?p=reactos.git;a=commitdiff;h=8723be733c9fdc865fbd7…
commit 8723be733c9fdc865fbd7ff4f7bac7a19ed301fa Author: Ivan Labutin <linuxrf(a)gmail.com> AuthorDate: Mon Dec 18 08:27:31 2017 +0100 [NTOS:PS] Skip backtrace on non-x86 --- ntoskrnl/ps/debug.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/ntoskrnl/ps/debug.c b/ntoskrnl/ps/debug.c index 6da8ea22e2..d87595a8d5 100644 --- a/ntoskrnl/ps/debug.c +++ b/ntoskrnl/ps/debug.c @@ -59,6 +59,7 @@ PspDumpThreads(BOOLEAN IncludeSystem) Thread->Tcb.State == Standby || Thread->Tcb.State == Waiting) { +#ifdef _M_IX86 ULONG i = 0; PULONG Esp = (PULONG)Thread->Tcb.KernelStack; PULONG Ebp = (PULONG)Esp[4]; @@ -77,6 +78,9 @@ PspDumpThreads(BOOLEAN IncludeSystem) /* Print a new line if there's nothing */ if((i % 8) != 0) DbgPrint("\n"); +#else + DbgPrint("FIXME: Backtrace skipped on non-x86\n"); +#endif } /* Move to the next Thread */
7 years
1
0
0
0
[reactos] 09/14: [SAC] Fix wrong sized variable in SAC driver
by Ivan Labutin
https://git.reactos.org/?p=reactos.git;a=commitdiff;h=925f1a67ea3db34be9693…
commit 925f1a67ea3db34be9693660b2182c4191233f44 Author: Ivan Labutin <linuxrf(a)gmail.com> AuthorDate: Mon Nov 13 18:26:37 2017 +0300 [SAC] Fix wrong sized variable in SAC driver --- drivers/sac/driver/init.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/sac/driver/init.c b/drivers/sac/driver/init.c index 974b67a80b..d11e6948a3 100644 --- a/drivers/sac/driver/init.c +++ b/drivers/sac/driver/init.c @@ -18,7 +18,7 @@ DriverEntry(IN PDRIVER_OBJECT DriverObject, IN PUNICODE_STRING RegistryPath) { HEADLESS_RSP_QUERY_INFO HeadlessInformation; - ULONG InfoSize = sizeof(HeadlessInformation); + SIZE_T InfoSize = sizeof(HeadlessInformation); NTSTATUS Status; UNICODE_STRING DriverName; PDEVICE_OBJECT DeviceObject;
7 years
1
0
0
0
[reactos] 08/14: [NTOS:FSRTL] Fixed incorrect comparison
by Ivan Labutin
https://git.reactos.org/?p=reactos.git;a=commitdiff;h=0d01b0087185cc6eeaef2…
commit 0d01b0087185cc6eeaef2f29f4038a86ac622ad0 Author: Ivan Labutin <linuxrf(a)gmail.com> AuthorDate: Mon Nov 13 15:08:27 2017 +0100 [NTOS:FSRTL] Fixed incorrect comparison --- ntoskrnl/fsrtl/unc.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ntoskrnl/fsrtl/unc.c b/ntoskrnl/fsrtl/unc.c index 2f8a1afeb0..6738915f72 100644 --- a/ntoskrnl/fsrtl/unc.c +++ b/ntoskrnl/fsrtl/unc.c @@ -71,7 +71,7 @@ FsRtlpIsDfsEnabled(VOID) return TRUE; } - return ((ULONG)KeyQueryOutput.KeyInfo.Data != 1); + return ((*(PULONG)KeyQueryOutput.KeyInfo.Data) != 1); } NTSTATUS
7 years
1
0
0
0
[reactos] 07/14: [NTOS][NDK][RTL] A bunch of 'wrong size' fixes
by Ivan Labutin
https://git.reactos.org/?p=reactos.git;a=commitdiff;h=d6792047f3e667017cf45…
commit d6792047f3e667017cf459e42c06d3ed9e5f78f9 Author: Ivan Labutin <linuxrf(a)gmail.com> AuthorDate: Mon Nov 13 15:06:29 2017 +0100 [NTOS][NDK][RTL] A bunch of 'wrong size' fixes --- dll/ntdll/ldr/ldrapi.c | 6 +++--- dll/win32/kernel32/client/loader.c | 4 ++-- ntoskrnl/fsrtl/stackovf.c | 4 ++-- ntoskrnl/io/pnpmgr/pnpreport.c | 4 ++-- ntoskrnl/ps/process.c | 4 ++-- sdk/include/ndk/ldrfuncs.h | 2 +- sdk/lib/rtl/memstream.c | 9 +++++++-- sdk/lib/rtl/rtlp.h | 4 ++-- 8 files changed, 21 insertions(+), 16 deletions(-) diff --git a/dll/ntdll/ldr/ldrapi.c b/dll/ntdll/ldr/ldrapi.c index c49be3dead..c33b21eff1 100644 --- a/dll/ntdll/ldr/ldrapi.c +++ b/dll/ntdll/ldr/ldrapi.c @@ -316,7 +316,7 @@ LdrLoadDll(IN PWSTR SearchPath OPTIONAL, UNICODE_STRING DllString1, DllString2; BOOLEAN RedirectedDll = FALSE; NTSTATUS Status; - ULONG Cookie; + ULONG_PTR Cookie; PUNICODE_STRING OldTldDll; PTEB Teb = NtCurrentTeb(); @@ -1117,7 +1117,7 @@ LdrEnumerateLoadedModules(IN BOOLEAN ReservedFlag, PLIST_ENTRY ListHead, ListEntry; PLDR_DATA_TABLE_ENTRY LdrEntry; NTSTATUS Status; - ULONG Cookie; + ULONG_PTR Cookie; BOOLEAN Stop = FALSE; /* Check parameters */ @@ -1232,7 +1232,7 @@ LdrAddRefDll(IN ULONG Flags, { PLDR_DATA_TABLE_ENTRY LdrEntry; NTSTATUS Status = STATUS_SUCCESS; - ULONG Cookie; + ULONG_PTR Cookie; BOOLEAN Locked = FALSE; /* Check for invalid flags */ diff --git a/dll/win32/kernel32/client/loader.c b/dll/win32/kernel32/client/loader.c index bed45c541f..82f8c7d988 100644 --- a/dll/win32/kernel32/client/loader.c +++ b/dll/win32/kernel32/client/loader.c @@ -610,7 +610,7 @@ GetModuleFileNameW(HINSTANCE hModule, PLIST_ENTRY ModuleListHead, Entry; PLDR_DATA_TABLE_ENTRY Module; ULONG Length = 0; - ULONG Cookie; + ULONG_PTR Cookie; PPEB Peb; hModule = BasepMapModuleHandle(hModule, FALSE); @@ -721,7 +721,7 @@ BOOLEAN WINAPI BasepGetModuleHandleExW(BOOLEAN NoLock, DWORD dwPublicFlags, LPCWSTR lpwModuleName, HMODULE *phModule) { - DWORD Cookie; + ULONG_PTR Cookie; NTSTATUS Status = STATUS_SUCCESS, Status2; HANDLE hModule = NULL; UNICODE_STRING ModuleNameU; diff --git a/ntoskrnl/fsrtl/stackovf.c b/ntoskrnl/fsrtl/stackovf.c index 076121f883..9016fce5da 100644 --- a/ntoskrnl/fsrtl/stackovf.c +++ b/ntoskrnl/fsrtl/stackovf.c @@ -115,7 +115,7 @@ FsRtlWorkerThread(IN PVOID StartContext) KIRQL Irql; PLIST_ENTRY Entry; PWORK_QUEUE_ITEM WorkItem; - ULONG QueueId = (ULONG)StartContext; + ULONG_PTR QueueId = (ULONG_PTR)StartContext; /* Set our priority according to the queue we're dealing with */ KeSetPriorityThread(&PsGetCurrentThread()->Tcb, LOW_REALTIME_PRIORITY + QueueId); @@ -149,7 +149,7 @@ NTAPI INIT_FUNCTION FsRtlInitializeWorkerThread(VOID) { - ULONG i; + ULONG_PTR i; NTSTATUS Status; HANDLE ThreadHandle; OBJECT_ATTRIBUTES ObjectAttributes; diff --git a/ntoskrnl/io/pnpmgr/pnpreport.c b/ntoskrnl/io/pnpmgr/pnpreport.c index 9449e2d01a..92523207c5 100644 --- a/ntoskrnl/io/pnpmgr/pnpreport.c +++ b/ntoskrnl/io/pnpmgr/pnpreport.c @@ -425,7 +425,7 @@ IoReportTargetDeviceChange(IN PDEVICE_OBJECT PhysicalDeviceObject, /* Check for valid PDO */ if (!IopIsValidPhysicalDeviceObject(PhysicalDeviceObject)) { - KeBugCheckEx(PNP_DETECTED_FATAL_ERROR, 0x2, (ULONG)PhysicalDeviceObject, 0, 0); + KeBugCheckEx(PNP_DETECTED_FATAL_ERROR, 0x2, (ULONG_PTR)PhysicalDeviceObject, 0, 0); } /* FileObject must be null. PnP will fill in it */ @@ -476,7 +476,7 @@ IoReportTargetDeviceChangeAsynchronous(IN PDEVICE_OBJECT PhysicalDeviceObject, /* Check for valid PDO */ if (!IopIsValidPhysicalDeviceObject(PhysicalDeviceObject)) { - KeBugCheckEx(PNP_DETECTED_FATAL_ERROR, 0x2, (ULONG)PhysicalDeviceObject, 0, 0); + KeBugCheckEx(PNP_DETECTED_FATAL_ERROR, 0x2, (ULONG_PTR)PhysicalDeviceObject, 0, 0); } /* FileObject must be null. PnP will fill in it */ diff --git a/ntoskrnl/ps/process.c b/ntoskrnl/ps/process.c index ab81ddca87..119997a753 100644 --- a/ntoskrnl/ps/process.c +++ b/ntoskrnl/ps/process.c @@ -1416,8 +1416,8 @@ NtCreateProcess(OUT PHANDLE ProcessHandle, "Parent: %p Attributes: %p\n", ParentProcess, ObjectAttributes); /* Set new-style flags */ - if ((ULONG)SectionHandle & 1) Flags |= PROCESS_CREATE_FLAGS_BREAKAWAY; - if ((ULONG)DebugPort & 1) Flags |= PROCESS_CREATE_FLAGS_NO_DEBUG_INHERIT; + if ((ULONG_PTR)SectionHandle & 1) Flags |= PROCESS_CREATE_FLAGS_BREAKAWAY; + if ((ULONG_PTR)DebugPort & 1) Flags |= PROCESS_CREATE_FLAGS_NO_DEBUG_INHERIT; if (InheritObjectTable) Flags |= PROCESS_CREATE_FLAGS_INHERIT_HANDLES; /* Call the new API */ diff --git a/sdk/include/ndk/ldrfuncs.h b/sdk/include/ndk/ldrfuncs.h index c134ecfb96..58859bcb35 100644 --- a/sdk/include/ndk/ldrfuncs.h +++ b/sdk/include/ndk/ldrfuncs.h @@ -109,7 +109,7 @@ NTAPI LdrLockLoaderLock( _In_ ULONG Flags, _Out_opt_ PULONG Disposition, - _Out_opt_ PULONG Cookie + _Out_opt_ PULONG_PTR Cookie ); NTSTATUS diff --git a/sdk/lib/rtl/memstream.c b/sdk/lib/rtl/memstream.c index 0549424ca4..51dc8e6653 100644 --- a/sdk/lib/rtl/memstream.c +++ b/sdk/lib/rtl/memstream.c @@ -205,6 +205,7 @@ RtlReadOutOfProcessMemoryStream( ULONG CopyLength; PRTL_MEMORY_STREAM Stream = IStream_To_RTL_MEMORY_STREAM(This); SIZE_T Available = (PUCHAR)Stream->End - (PUCHAR)Stream->Current; + SIZE_T LocalBytesRead = 0; if (BytesRead) *BytesRead = 0; @@ -218,10 +219,14 @@ RtlReadOutOfProcessMemoryStream( Stream->Current, Buffer, CopyLength, - BytesRead); + &LocalBytesRead); if (NT_SUCCESS(Status)) - Stream->Current = (PUCHAR)Stream->Current + *BytesRead; + { + Stream->Current = (PUCHAR)Stream->Current + LocalBytesRead; + if (BytesRead) + *BytesRead = (ULONG)LocalBytesRead; + } return HRESULT_FROM_WIN32(RtlNtStatusToDosError(Status)); } diff --git a/sdk/lib/rtl/rtlp.h b/sdk/lib/rtl/rtlp.h index 6942e18fde..d0d4a41033 100644 --- a/sdk/lib/rtl/rtlp.h +++ b/sdk/lib/rtl/rtlp.h @@ -27,10 +27,10 @@ extern VOID FASTCALL CHECK_PAGED_CODE_RTL(char *file, int line); #endif #define ROUND_DOWN(n, align) \ - (((ULONG)(n)) & ~((align) - 1l)) + (((ULONG_PTR)(n)) & ~((align) - 1l)) #define ROUND_UP(n, align) \ - ROUND_DOWN(((ULONG)(n)) + (align) - 1, (align)) + ROUND_DOWN(((ULONG_PTR)(n)) + (align) - 1, (align)) #define RVA(m, b) ((PVOID)((ULONG_PTR)(b) + (ULONG_PTR)(m)))
7 years
1
0
0
0
← Newer
1
...
10
11
12
13
14
15
16
...
36
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
Results per page:
10
25
50
100
200