Compare commits
153 Commits
Author | SHA1 | Date | |
---|---|---|---|
de8f0153c0 | |||
820eb374d5 | |||
974cacda5f | |||
953a63d7b5 | |||
19477d60c0 | |||
8a48250bcb | |||
18d95584cc | |||
9b3075030e | |||
dd98ce6eab | |||
35ff0e5aa6 | |||
8529dcf755 | |||
56543e1a92 | |||
72543c9307 | |||
872c61e1d1 | |||
7f3cee4db9 | |||
3f036a11a6 | |||
3df9aff396 | |||
be12367910 | |||
c59a2e0a4b | |||
0abec17ab4 | |||
6b67f4a0d7 | |||
6e2565d1a4 | |||
3e3c8a4d18 | |||
8e836591ee | |||
50b8b67185 | |||
36850f6241 | |||
ed58bd90ff | |||
ab73c790e1 | |||
4a34c673a4 | |||
0ce578668f | |||
53e6c4c911 | |||
d99cf11e2e | |||
d9832ed22c | |||
a02649faa9 | |||
a28ebb4ccf | |||
0f5a5e5d24 | |||
8f0b129a52 | |||
098bc2f905 | |||
5943e8f42f | |||
ba72ebafcb | |||
a89735994c | |||
e7fd290af6 | |||
35b97e7a13 | |||
472c2d691f | |||
e48f56a15e | |||
25e32c8ff2 | |||
db63ba7fa4 | |||
3df66be089 | |||
3a52923697 | |||
9953883d26 | |||
5ed9090012 | |||
93e2fb46a9 | |||
03c9ec0f62 | |||
88fc5ca18e | |||
6fb29816a2 | |||
c67edca820 | |||
9d5242594b | |||
69c74d7a5e | |||
b7ea7a255b | |||
17790a34df | |||
7741a99b90 | |||
36dd7fb76b | |||
8fa870bf0c | |||
1afdf2da8a | |||
242aa4254e | |||
4f576d5539 | |||
2411f3f5db | |||
1c6b65ad52 | |||
f92a2191f2 | |||
7f9b10329b | |||
49409e9d92 | |||
f753cc9702 | |||
07a4daed7b | |||
2ad15489bb | |||
fa53ddcecd | |||
7a8b3aecc9 | |||
94357626f7 | |||
19342d8adf | |||
2ed4fee447 | |||
f03d702d84 | |||
10de10b9c2 | |||
508f9fbdc2 | |||
e965b0e4a9 | |||
1f4d313d0f | |||
dc0b78ad14 | |||
b8eb12afc1 | |||
1975883bed | |||
9bda107603 | |||
b4f17b968a | |||
e5ae0c0e20 | |||
a03411e451 | |||
931580edc5 | |||
fd2f5465f8 | |||
127052f404 | |||
a30490ab9b | |||
1ec115c7ec | |||
a4f56b65b8 | |||
bb69acec6c | |||
4bbf5e96f4 | |||
4a85f8e48d | |||
f34b7ce84f | |||
010905edd3 | |||
7bb2d55d35 | |||
e3a7cc19dd | |||
379605d30a | |||
c05c4e155b | |||
fd73484bfc | |||
f29d7dd938 | |||
3a5dc4783a | |||
d4a713451e | |||
a302475fa6 | |||
6e988ea4c8 | |||
7731181900 | |||
41f6e0ba73 | |||
11073171a1 | |||
0805832b44 | |||
a4dcd414ca | |||
4ff8a83f90 | |||
48da357385 | |||
e1916d43c8 | |||
321f320bfb | |||
df32fedc7c | |||
a7396b70ba | |||
d9ca49cc5e | |||
56849b78ad | |||
a769831fb5 | |||
7486201a7e | |||
1813624992 | |||
5fa27adfcd | |||
6d1891a7e9 | |||
8fb1d70d0b | |||
c26c52d59c | |||
c3329d4675 | |||
1cefc366f8 | |||
7df0885c4f | |||
1c5da0e341 | |||
36ba75b598 | |||
1628831878 | |||
12e774ea74 | |||
66b18f2dbd | |||
9ea1934097 | |||
9771e72702 | |||
7776bd5c17 | |||
6d8a75462a | |||
cf18077eda | |||
aa37e7a868 | |||
d01a5c1661 | |||
36ed6bebda | |||
5234060618 | |||
f402f28643 | |||
f047043eb2 | |||
7eac4195c4 | |||
0f5692d1ea |
@ -1,4 +1,4 @@
|
|||||||
CMAKE_MINIMUM_REQUIRED(VERSION 2.4.0)
|
CMAKE_MINIMUM_REQUIRED(VERSION 2.6.0)
|
||||||
PROJECT(NV)
|
PROJECT(NV)
|
||||||
ENABLE_TESTING()
|
ENABLE_TESTING()
|
||||||
|
|
||||||
@ -16,6 +16,13 @@ MESSAGE(STATUS "Setting optimal options")
|
|||||||
MESSAGE(STATUS " Processor: ${NV_SYSTEM_PROCESSOR}")
|
MESSAGE(STATUS " Processor: ${NV_SYSTEM_PROCESSOR}")
|
||||||
MESSAGE(STATUS " Compiler Flags: ${CMAKE_CXX_FLAGS}")
|
MESSAGE(STATUS " Compiler Flags: ${CMAKE_CXX_FLAGS}")
|
||||||
|
|
||||||
|
IF(NVTT_SHARED)
|
||||||
|
SET(NVCORE_SHARED TRUE)
|
||||||
|
SET(NVMATH_SHARED TRUE)
|
||||||
|
SET(NVIMAGE_SHARED TRUE)
|
||||||
|
ENDIF(NVTT_SHARED)
|
||||||
|
|
||||||
|
|
||||||
ADD_SUBDIRECTORY(src)
|
ADD_SUBDIRECTORY(src)
|
||||||
|
|
||||||
IF(WIN32)
|
IF(WIN32)
|
||||||
|
21
ChangeLog
21
ChangeLog
@ -1,3 +1,24 @@
|
|||||||
|
NVIDIA Texture Tools version 2.0.6
|
||||||
|
* Fix dll version checking.
|
||||||
|
* Detect CUDA 2.1 and future CUDA versions correctly.
|
||||||
|
* Print CUDA detection message in nvcompress.
|
||||||
|
* Select the fastest CUDA device.
|
||||||
|
* Compile squish with -fPIC. Fixes issue 74.
|
||||||
|
* Fix warnings under gcc 4.3.2.
|
||||||
|
* Fix nvzoom option typo by Frank Richter. Fixes issue 81.
|
||||||
|
* Do not use CUDA to compress small mipmaps. Fixes issue 76.
|
||||||
|
* Compute mipmaps of semi-transparent images correctly.
|
||||||
|
* Shutdown CUDA properly. Fixes issue 83.
|
||||||
|
* Fix pixel format converions. Fixes issue 87.
|
||||||
|
* Update single color compression tables. Fixes issue 85.
|
||||||
|
|
||||||
|
NVIDIA Texture Tools version 2.0.5
|
||||||
|
* Fix error in single color compressor. Fixes issue 66.
|
||||||
|
* Detect mismatch between CUDA runtime and driver, and disable CUDA in that case.
|
||||||
|
* Fix cmake files when compiling NVTT as a shared library.
|
||||||
|
* When linking nvtt dynamically on unix, link all libraries dynamically.
|
||||||
|
* Select fastest CUDA device.
|
||||||
|
|
||||||
NVIDIA Texture Tools version 2.0.4
|
NVIDIA Texture Tools version 2.0.4
|
||||||
* Fix error in RGB format output; reported by jonsoh. See issue 49.
|
* Fix error in RGB format output; reported by jonsoh. See issue 49.
|
||||||
* Added support RGB format dithering by jonsoh. Fixes issue 50 and 51.
|
* Added support RGB format dithering by jonsoh. Fixes issue 50 and 51.
|
||||||
|
@ -57,7 +57,7 @@ MARK_AS_ADVANCED (CUDA_FOUND CUDA_COMPILER CUDA_RUNTIME_LIBRARY)
|
|||||||
|
|
||||||
|
|
||||||
#SET(CUDA_OPTIONS "-ncfe")
|
#SET(CUDA_OPTIONS "-ncfe")
|
||||||
SET(CUDA_OPTIONS "")
|
SET(CUDA_OPTIONS "--host-compilation=C")
|
||||||
|
|
||||||
IF (CUDA_EMULATION)
|
IF (CUDA_EMULATION)
|
||||||
SET (CUDA_OPTIONS "${CUDA_OPTIONS} -deviceemu")
|
SET (CUDA_OPTIONS "${CUDA_OPTIONS} -deviceemu")
|
||||||
|
2
configure
vendored
2
configure
vendored
@ -53,7 +53,7 @@ echo "-- Configuring nvidia-texture-tools "`cat VERSION`
|
|||||||
|
|
||||||
mkdir -p ./build
|
mkdir -p ./build
|
||||||
cd ./build
|
cd ./build
|
||||||
$CMAKE .. -DCMAKE_BUILD_TYPE=$build -DCMAKE_INSTALL_PREFIX=$prefix -G "Unix Makefiles" || exit 1
|
$CMAKE .. -DNVTT_SHARED=1 -DCMAKE_BUILD_TYPE=$build -DCMAKE_INSTALL_PREFIX=$prefix -G "Unix Makefiles" || exit 1
|
||||||
cd ..
|
cd ..
|
||||||
|
|
||||||
echo ""
|
echo ""
|
||||||
|
@ -281,6 +281,10 @@
|
|||||||
RelativePath="..\..\..\src\nvcore\Debug.cpp"
|
RelativePath="..\..\..\src\nvcore\Debug.cpp"
|
||||||
>
|
>
|
||||||
</File>
|
</File>
|
||||||
|
<File
|
||||||
|
RelativePath="..\..\..\src\nvcore\Library.cpp"
|
||||||
|
>
|
||||||
|
</File>
|
||||||
<File
|
<File
|
||||||
RelativePath="..\..\..\src\nvcore\Memory.cpp"
|
RelativePath="..\..\..\src\nvcore\Memory.cpp"
|
||||||
>
|
>
|
||||||
@ -315,6 +319,10 @@
|
|||||||
RelativePath="..\..\..\src\nvcore\DefsVcWin32.h"
|
RelativePath="..\..\..\src\nvcore\DefsVcWin32.h"
|
||||||
>
|
>
|
||||||
</File>
|
</File>
|
||||||
|
<File
|
||||||
|
RelativePath="..\..\..\src\nvcore\Library.h"
|
||||||
|
>
|
||||||
|
</File>
|
||||||
<File
|
<File
|
||||||
RelativePath="..\..\..\src\nvcore\Memory.h"
|
RelativePath="..\..\..\src\nvcore\Memory.h"
|
||||||
>
|
>
|
||||||
|
@ -53,8 +53,8 @@ END
|
|||||||
//
|
//
|
||||||
|
|
||||||
VS_VERSION_INFO VERSIONINFO
|
VS_VERSION_INFO VERSIONINFO
|
||||||
FILEVERSION 2,0,4,0
|
FILEVERSION 2,0,6,0
|
||||||
PRODUCTVERSION 2,0,4,0
|
PRODUCTVERSION 2,0,6,0
|
||||||
FILEFLAGSMASK 0x17L
|
FILEFLAGSMASK 0x17L
|
||||||
#ifdef _DEBUG
|
#ifdef _DEBUG
|
||||||
FILEFLAGS 0x1L
|
FILEFLAGS 0x1L
|
||||||
@ -71,12 +71,12 @@ BEGIN
|
|||||||
BEGIN
|
BEGIN
|
||||||
VALUE "CompanyName", "NVIDIA Corporation"
|
VALUE "CompanyName", "NVIDIA Corporation"
|
||||||
VALUE "FileDescription", "NVIDIA Texture Tools Dynamic Link Library"
|
VALUE "FileDescription", "NVIDIA Texture Tools Dynamic Link Library"
|
||||||
VALUE "FileVersion", "2, 0, 4, 0"
|
VALUE "FileVersion", "2, 0, 6, 0"
|
||||||
VALUE "InternalName", "nvtt"
|
VALUE "InternalName", "nvtt"
|
||||||
VALUE "LegalCopyright", "Copyright (C) 2007"
|
VALUE "LegalCopyright", "Copyright (C) 2007"
|
||||||
VALUE "OriginalFilename", "nvtt.dll"
|
VALUE "OriginalFilename", "nvtt.dll"
|
||||||
VALUE "ProductName", "NVIDIA Texture Tools Dynamic Link Library"
|
VALUE "ProductName", "NVIDIA Texture Tools Dynamic Link Library"
|
||||||
VALUE "ProductVersion", "2, 0, 4, 0"
|
VALUE "ProductVersion", "2, 0, 6, 0"
|
||||||
END
|
END
|
||||||
END
|
END
|
||||||
BLOCK "VarFileInfo"
|
BLOCK "VarFileInfo"
|
||||||
|
@ -19,13 +19,19 @@ SET(CORE_SRCS
|
|||||||
TextWriter.h
|
TextWriter.h
|
||||||
TextWriter.cpp
|
TextWriter.cpp
|
||||||
Radix.h
|
Radix.h
|
||||||
Radix.cpp)
|
Radix.cpp
|
||||||
|
Library.h
|
||||||
|
Library.cpp)
|
||||||
|
|
||||||
INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR})
|
INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR})
|
||||||
|
|
||||||
# targets
|
# targets
|
||||||
ADD_DEFINITIONS(-DNVCORE_EXPORTS)
|
ADD_DEFINITIONS(-DNVCORE_EXPORTS)
|
||||||
|
|
||||||
|
IF(UNIX)
|
||||||
|
SET(LIBS ${LIBS} ${CMAKE_DL_LIBS})
|
||||||
|
ENDIF(UNIX)
|
||||||
|
|
||||||
IF(NVCORE_SHARED)
|
IF(NVCORE_SHARED)
|
||||||
ADD_LIBRARY(nvcore SHARED ${CORE_SRCS})
|
ADD_LIBRARY(nvcore SHARED ${CORE_SRCS})
|
||||||
ELSE(NVCORE_SHARED)
|
ELSE(NVCORE_SHARED)
|
||||||
|
@ -824,13 +824,13 @@ namespace nv
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Number of entries in the hash.
|
/// Number of entries in the hash.
|
||||||
int size()
|
int size() const
|
||||||
{
|
{
|
||||||
return entry_count;
|
return entry_count;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Number of entries in the hash.
|
/// Number of entries in the hash.
|
||||||
int count()
|
int count() const
|
||||||
{
|
{
|
||||||
return size();
|
return size();
|
||||||
}
|
}
|
||||||
|
@ -28,7 +28,7 @@
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if NV_OS_LINUX && defined(HAVE_EXECINFO_H)
|
#if NV_OS_LINUX && defined(HAVE_EXECINFO_H)
|
||||||
# include <execinfo.h>
|
# include <execinfo.h> // backtrace
|
||||||
# if NV_CC_GNUC // defined(HAVE_CXXABI_H)
|
# if NV_CC_GNUC // defined(HAVE_CXXABI_H)
|
||||||
# include <cxxabi.h>
|
# include <cxxabi.h>
|
||||||
# endif
|
# endif
|
||||||
@ -39,6 +39,13 @@
|
|||||||
# include <sys/types.h>
|
# include <sys/types.h>
|
||||||
# include <sys/sysctl.h> // sysctl
|
# include <sys/sysctl.h> // sysctl
|
||||||
# include <ucontext.h>
|
# include <ucontext.h>
|
||||||
|
# undef HAVE_EXECINFO_H
|
||||||
|
# if defined(HAVE_EXECINFO_H) // only after OSX 10.5
|
||||||
|
# include <execinfo.h> // backtrace
|
||||||
|
# if NV_CC_GNUC // defined(HAVE_CXXABI_H)
|
||||||
|
# include <cxxabi.h>
|
||||||
|
# endif
|
||||||
|
# endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include <stdexcept> // std::runtime_error
|
#include <stdexcept> // std::runtime_error
|
||||||
@ -128,6 +135,14 @@ namespace
|
|||||||
|
|
||||||
#if defined(HAVE_EXECINFO_H) // NV_OS_LINUX
|
#if defined(HAVE_EXECINFO_H) // NV_OS_LINUX
|
||||||
|
|
||||||
|
static bool nvHasStackTrace() {
|
||||||
|
#if NV_OS_DARWIN
|
||||||
|
return backtrace != NULL;
|
||||||
|
#else
|
||||||
|
return true;
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
static void nvPrintStackTrace(void * trace[], int size, int start=0) {
|
static void nvPrintStackTrace(void * trace[], int size, int start=0) {
|
||||||
char ** string_array = backtrace_symbols(trace, size);
|
char ** string_array = backtrace_symbols(trace, size);
|
||||||
|
|
||||||
@ -166,24 +181,36 @@ namespace
|
|||||||
|
|
||||||
static void * callerAddress(void * secret)
|
static void * callerAddress(void * secret)
|
||||||
{
|
{
|
||||||
# if NV_OS_DARWIN && NV_CPU_PPC
|
# if NV_OS_DARWIN
|
||||||
ucontext_t * ucp = (ucontext_t *)secret;
|
# if defined(_STRUCT_MCONTEXT)
|
||||||
return (void *) ucp->uc_mcontext->ss.srr0;
|
# if NV_CPU_PPC
|
||||||
# elif NV_OS_DARWIN && NV_CPU_X86
|
ucontext_t * ucp = (ucontext_t *)secret;
|
||||||
ucontext_t * ucp = (ucontext_t *)secret;
|
return (void *) ucp->uc_mcontext->__ss.__srr0;
|
||||||
return (void *) ucp->uc_mcontext->ss.eip;
|
# elif NV_CPU_X86
|
||||||
# elif NV_CPU_X86_64
|
ucontext_t * ucp = (ucontext_t *)secret;
|
||||||
// #define REG_RIP REG_INDEX(rip) // seems to be 16
|
return (void *) ucp->uc_mcontext->__ss.__eip;
|
||||||
ucontext_t * ucp = (ucontext_t *)secret;
|
# endif
|
||||||
return (void *)ucp->uc_mcontext.gregs[REG_RIP];
|
# else
|
||||||
# elif NV_CPU_X86
|
# if NV_CPU_PPC
|
||||||
ucontext_t * ucp = (ucontext_t *)secret;
|
ucontext_t * ucp = (ucontext_t *)secret;
|
||||||
return (void *)ucp->uc_mcontext.gregs[14/*REG_EIP*/];
|
return (void *) ucp->uc_mcontext->ss.srr0;
|
||||||
# elif NV_CPU_PPC
|
# elif NV_CPU_X86
|
||||||
ucontext_t * ucp = (ucontext_t *)secret;
|
ucontext_t * ucp = (ucontext_t *)secret;
|
||||||
return (void *) ucp->uc_mcontext.regs->nip;
|
return (void *) ucp->uc_mcontext->ss.eip;
|
||||||
|
# endif
|
||||||
|
# endif
|
||||||
# else
|
# else
|
||||||
return NULL;
|
# if NV_CPU_X86_64
|
||||||
|
// #define REG_RIP REG_INDEX(rip) // seems to be 16
|
||||||
|
ucontext_t * ucp = (ucontext_t *)secret;
|
||||||
|
return (void *)ucp->uc_mcontext.gregs[REG_RIP];
|
||||||
|
# elif NV_CPU_X86
|
||||||
|
ucontext_t * ucp = (ucontext_t *)secret;
|
||||||
|
return (void *)ucp->uc_mcontext.gregs[14/*REG_EIP*/];
|
||||||
|
# elif NV_CPU_PPC
|
||||||
|
ucontext_t * ucp = (ucontext_t *)secret;
|
||||||
|
return (void *) ucp->uc_mcontext.regs->nip;
|
||||||
|
# endif
|
||||||
# endif
|
# endif
|
||||||
|
|
||||||
// How to obtain the instruction pointers in different platforms, from mlton's source code.
|
// How to obtain the instruction pointers in different platforms, from mlton's source code.
|
||||||
@ -228,17 +255,18 @@ namespace
|
|||||||
}
|
}
|
||||||
|
|
||||||
# if defined(HAVE_EXECINFO_H)
|
# if defined(HAVE_EXECINFO_H)
|
||||||
|
if (nvHasStackTrace()) // in case of weak linking
|
||||||
|
{
|
||||||
|
void * trace[64];
|
||||||
|
int size = backtrace(trace, 64);
|
||||||
|
|
||||||
void * trace[64];
|
if (pnt != NULL) {
|
||||||
int size = backtrace(trace, 64);
|
// Overwrite sigaction with caller's address.
|
||||||
|
trace[1] = pnt;
|
||||||
|
}
|
||||||
|
|
||||||
if (pnt != NULL) {
|
nvPrintStackTrace(trace, size, 1);
|
||||||
// Overwrite sigaction with caller's address.
|
|
||||||
trace[1] = pnt;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
nvPrintStackTrace(trace, size, 1);
|
|
||||||
|
|
||||||
# endif // defined(HAVE_EXECINFO_H)
|
# endif // defined(HAVE_EXECINFO_H)
|
||||||
|
|
||||||
exit(0);
|
exit(0);
|
||||||
@ -373,9 +401,12 @@ namespace
|
|||||||
# endif
|
# endif
|
||||||
|
|
||||||
# if defined(HAVE_EXECINFO_H)
|
# if defined(HAVE_EXECINFO_H)
|
||||||
void * trace[64];
|
if (nvHasStackTrace())
|
||||||
int size = backtrace(trace, 64);
|
{
|
||||||
nvPrintStackTrace(trace, size, 3);
|
void * trace[64];
|
||||||
|
int size = backtrace(trace, 64);
|
||||||
|
nvPrintStackTrace(trace, size, 2);
|
||||||
|
}
|
||||||
# endif
|
# endif
|
||||||
|
|
||||||
// Exit cleanly.
|
// Exit cleanly.
|
||||||
@ -422,9 +453,12 @@ void NV_CDECL nvDebug(const char *msg, ...)
|
|||||||
void debug::dumpInfo()
|
void debug::dumpInfo()
|
||||||
{
|
{
|
||||||
#if !NV_OS_WIN32 && defined(HAVE_SIGNAL_H) && defined(HAVE_EXECINFO_H)
|
#if !NV_OS_WIN32 && defined(HAVE_SIGNAL_H) && defined(HAVE_EXECINFO_H)
|
||||||
void * trace[64];
|
if (nvHasStackTrace())
|
||||||
int size = backtrace(trace, 64);
|
{
|
||||||
nvPrintStackTrace(trace, size, 1);
|
void * trace[64];
|
||||||
|
int size = backtrace(trace, 64);
|
||||||
|
nvPrintStackTrace(trace, size, 1);
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2,8 +2,7 @@
|
|||||||
#error "Do not include this file directly."
|
#error "Do not include this file directly."
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include <stdlib.h> // uint8_t, int8_t, ...
|
#include <stdint.h> // uint8_t, int8_t, ...
|
||||||
|
|
||||||
|
|
||||||
// Function linkage
|
// Function linkage
|
||||||
#define DLL_IMPORT
|
#define DLL_IMPORT
|
||||||
|
@ -19,7 +19,9 @@
|
|||||||
|
|
||||||
// Set standard function names.
|
// Set standard function names.
|
||||||
#define snprintf _snprintf
|
#define snprintf _snprintf
|
||||||
#define vsnprintf _vsnprintf
|
#if _MSC_VER < 1500
|
||||||
|
# define vsnprintf _vsnprintf
|
||||||
|
#endif
|
||||||
#define vsscanf _vsscanf
|
#define vsscanf _vsscanf
|
||||||
#define chdir _chdir
|
#define chdir _chdir
|
||||||
#define getcwd _getcwd
|
#define getcwd _getcwd
|
||||||
@ -70,8 +72,6 @@ typedef uint32 uint;
|
|||||||
#pragma warning(disable : 4711) // function selected for automatic inlining
|
#pragma warning(disable : 4711) // function selected for automatic inlining
|
||||||
#pragma warning(disable : 4725) // Pentium fdiv bug
|
#pragma warning(disable : 4725) // Pentium fdiv bug
|
||||||
|
|
||||||
#pragma warning(disable : 4345) // behavior change: an object of POD type constructed with an initializer of the form () will be default-initialized
|
|
||||||
|
|
||||||
#pragma warning(disable : 4786) // Identifier was truncated and cannot be debugged.
|
#pragma warning(disable : 4786) // Identifier was truncated and cannot be debugged.
|
||||||
|
|
||||||
#pragma warning(disable : 4675) // resolved overload was found by argument-dependent lookup
|
#pragma warning(disable : 4675) // resolved overload was found by argument-dependent lookup
|
||||||
|
41
src/nvcore/Library.cpp
Normal file
41
src/nvcore/Library.cpp
Normal file
@ -0,0 +1,41 @@
|
|||||||
|
|
||||||
|
#include "Library.h"
|
||||||
|
#include "Debug.h"
|
||||||
|
|
||||||
|
#if NV_OS_WIN32
|
||||||
|
#define WIN32_LEAN_AND_MEAN
|
||||||
|
#define VC_EXTRALEAN
|
||||||
|
#include <windows.h>
|
||||||
|
#else
|
||||||
|
#include <dlfcn.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
void * nvLoadLibrary(const char * name)
|
||||||
|
{
|
||||||
|
#if NV_OS_WIN32
|
||||||
|
return (void *)LoadLibraryExA( name, NULL, 0 );
|
||||||
|
#else
|
||||||
|
return dlopen(name, RTLD_LAZY);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
void nvUnloadLibrary(void * handle)
|
||||||
|
{
|
||||||
|
nvDebugCheck(handle != NULL);
|
||||||
|
#if NV_OS_WIN32
|
||||||
|
FreeLibrary((HMODULE)handle);
|
||||||
|
#else
|
||||||
|
dlclose(handle);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
void * nvBindSymbol(void * handle, const char * symbol)
|
||||||
|
{
|
||||||
|
#if NV_OS_WIN32
|
||||||
|
return (void *)GetProcAddress((HMODULE)handle, symbol);
|
||||||
|
#else
|
||||||
|
return (void *)dlsym(handle, symbol);
|
||||||
|
#endif
|
||||||
|
}
|
50
src/nvcore/Library.h
Normal file
50
src/nvcore/Library.h
Normal file
@ -0,0 +1,50 @@
|
|||||||
|
// This code is in the public domain -- castano@gmail.com
|
||||||
|
|
||||||
|
#ifndef NV_CORE_LIBRARY_H
|
||||||
|
#define NV_CORE_LIBRARY_H
|
||||||
|
|
||||||
|
#include <nvcore/nvcore.h>
|
||||||
|
|
||||||
|
#if NV_OS_WIN32
|
||||||
|
#define LIBRARY_NAME(name) #name ".dll"
|
||||||
|
#elif NV_OS_DARWIN
|
||||||
|
#define NV_LIBRARY_NAME(name) "lib" #name ".dylib"
|
||||||
|
#else
|
||||||
|
#define NV_LIBRARY_NAME(name) "lib" #name ".so"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
NVCORE_API void * nvLoadLibrary(const char * name);
|
||||||
|
NVCORE_API void nvUnloadLibrary(void * lib);
|
||||||
|
NVCORE_API void * nvBindSymbol(void * lib, const char * symbol);
|
||||||
|
|
||||||
|
class NVCORE_CLASS Library
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
Library(const char * name)
|
||||||
|
{
|
||||||
|
handle = nvLoadLibrary(name);
|
||||||
|
}
|
||||||
|
~Library()
|
||||||
|
{
|
||||||
|
if (isValid())
|
||||||
|
{
|
||||||
|
nvUnloadLibrary(handle);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
bool isValid() const
|
||||||
|
{
|
||||||
|
return handle != NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
void * bindSymbol(const char * symbol)
|
||||||
|
{
|
||||||
|
return nvBindSymbol(handle, symbol);
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
void * handle;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
#endif // NV_CORE_LIBRARY_H
|
@ -24,7 +24,7 @@ __forceinline void nvPrefetch(const void * mem)
|
|||||||
#else // NV_CC_MSVC
|
#else // NV_CC_MSVC
|
||||||
|
|
||||||
// do nothing in other case.
|
// do nothing in other case.
|
||||||
#define piPrefetch(ptr)
|
#define nvPrefetch(ptr)
|
||||||
|
|
||||||
#endif // NV_CC_MSVC
|
#endif // NV_CC_MSVC
|
||||||
|
|
||||||
|
@ -43,8 +43,11 @@ public:
|
|||||||
|
|
||||||
/** Delete owned pointer and assign new one. */
|
/** Delete owned pointer and assign new one. */
|
||||||
void operator=( T * p ) {
|
void operator=( T * p ) {
|
||||||
delete m_ptr;
|
if (p != m_ptr)
|
||||||
m_ptr = p;
|
{
|
||||||
|
delete m_ptr;
|
||||||
|
m_ptr = p;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Member access. */
|
/** Member access. */
|
||||||
@ -249,14 +252,14 @@ public:
|
|||||||
/** -> operator. */
|
/** -> operator. */
|
||||||
BaseClass * operator -> () const
|
BaseClass * operator -> () const
|
||||||
{
|
{
|
||||||
piCheck( m_ptr != NULL );
|
nvCheck( m_ptr != NULL );
|
||||||
return m_ptr;
|
return m_ptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** * operator. */
|
/** * operator. */
|
||||||
BaseClass & operator*() const
|
BaseClass & operator*() const
|
||||||
{
|
{
|
||||||
piCheck( m_ptr != NULL );
|
nvCheck( m_ptr != NULL );
|
||||||
return *m_ptr;
|
return *m_ptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -47,25 +47,25 @@ public:
|
|||||||
|
|
||||||
/** @name Stream implementation. */
|
/** @name Stream implementation. */
|
||||||
//@{
|
//@{
|
||||||
virtual void seek( int pos )
|
virtual void seek( uint pos )
|
||||||
{
|
{
|
||||||
nvDebugCheck(m_fp != NULL);
|
nvDebugCheck(m_fp != NULL);
|
||||||
nvDebugCheck(pos >= 0 && pos < size());
|
nvDebugCheck(pos < size());
|
||||||
fseek(m_fp, pos, SEEK_SET);
|
fseek(m_fp, pos, SEEK_SET);
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual int tell() const
|
virtual uint tell() const
|
||||||
{
|
{
|
||||||
nvDebugCheck(m_fp != NULL);
|
nvDebugCheck(m_fp != NULL);
|
||||||
return ftell(m_fp);
|
return ftell(m_fp);
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual int size() const
|
virtual uint size() const
|
||||||
{
|
{
|
||||||
nvDebugCheck(m_fp != NULL);
|
nvDebugCheck(m_fp != NULL);
|
||||||
int pos = ftell(m_fp);
|
uint pos = ftell(m_fp);
|
||||||
fseek(m_fp, 0, SEEK_END);
|
fseek(m_fp, 0, SEEK_END);
|
||||||
int end = ftell(m_fp);
|
uint end = ftell(m_fp);
|
||||||
fseek(m_fp, pos, SEEK_SET);
|
fseek(m_fp, pos, SEEK_SET);
|
||||||
return end;
|
return end;
|
||||||
}
|
}
|
||||||
@ -117,11 +117,11 @@ public:
|
|||||||
/** @name Stream implementation. */
|
/** @name Stream implementation. */
|
||||||
//@{
|
//@{
|
||||||
/// Write data.
|
/// Write data.
|
||||||
virtual void serialize( void * data, int len )
|
virtual uint serialize( void * data, uint len )
|
||||||
{
|
{
|
||||||
nvDebugCheck(data != NULL);
|
nvDebugCheck(data != NULL);
|
||||||
nvDebugCheck(m_fp != NULL);
|
nvDebugCheck(m_fp != NULL);
|
||||||
fwrite(data, len, 1, m_fp);
|
return (uint)fwrite(data, 1, len, m_fp);
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual bool isLoading() const
|
virtual bool isLoading() const
|
||||||
@ -156,11 +156,11 @@ public:
|
|||||||
/** @name Stream implementation. */
|
/** @name Stream implementation. */
|
||||||
//@{
|
//@{
|
||||||
/// Read data.
|
/// Read data.
|
||||||
virtual void serialize( void * data, int len )
|
virtual uint serialize( void * data, uint len )
|
||||||
{
|
{
|
||||||
nvDebugCheck(data != NULL);
|
nvDebugCheck(data != NULL);
|
||||||
nvDebugCheck(m_fp != NULL);
|
nvDebugCheck(m_fp != NULL);
|
||||||
fread(data, len, 1, m_fp);
|
return (uint)fread(data, 1, len, m_fp);
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual bool isLoading() const
|
virtual bool isLoading() const
|
||||||
@ -184,33 +184,40 @@ class NVCORE_CLASS MemoryInputStream : public Stream
|
|||||||
public:
|
public:
|
||||||
|
|
||||||
/// Ctor.
|
/// Ctor.
|
||||||
MemoryInputStream( const uint8 * mem, int size ) :
|
MemoryInputStream( const uint8 * mem, uint size ) :
|
||||||
m_mem(mem), m_ptr(mem), m_size(size) { }
|
m_mem(mem), m_ptr(mem), m_size(size) { }
|
||||||
|
|
||||||
/** @name Stream implementation. */
|
/** @name Stream implementation. */
|
||||||
//@{
|
//@{
|
||||||
/// Read data.
|
/// Read data.
|
||||||
virtual void serialize( void * data, int len )
|
virtual uint serialize( void * data, uint len )
|
||||||
{
|
{
|
||||||
nvDebugCheck(data != NULL);
|
nvDebugCheck(data != NULL);
|
||||||
nvDebugCheck(!isError());
|
nvDebugCheck(!isError());
|
||||||
|
|
||||||
|
uint left = m_size - tell();
|
||||||
|
if (len > left) len = left;
|
||||||
|
|
||||||
memcpy( data, m_ptr, len );
|
memcpy( data, m_ptr, len );
|
||||||
m_ptr += len;
|
m_ptr += len;
|
||||||
|
|
||||||
|
return len;
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual void seek( int pos )
|
virtual void seek( uint pos )
|
||||||
{
|
{
|
||||||
nvDebugCheck(!isError());
|
nvDebugCheck(!isError());
|
||||||
m_ptr = m_mem + pos;
|
m_ptr = m_mem + pos;
|
||||||
nvDebugCheck(!isError());
|
nvDebugCheck(!isError());
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual int tell() const
|
virtual uint tell() const
|
||||||
{
|
{
|
||||||
return int(m_ptr - m_mem);
|
nvDebugCheck(m_ptr >= m_mem);
|
||||||
|
return uint(m_ptr - m_mem);
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual int size() const
|
virtual uint size() const
|
||||||
{
|
{
|
||||||
return m_size;
|
return m_size;
|
||||||
}
|
}
|
||||||
@ -252,7 +259,7 @@ private:
|
|||||||
|
|
||||||
const uint8 * m_mem;
|
const uint8 * m_mem;
|
||||||
const uint8 * m_ptr;
|
const uint8 * m_ptr;
|
||||||
int m_size;
|
uint m_size;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -286,17 +293,19 @@ public:
|
|||||||
/** @name Stream implementation. */
|
/** @name Stream implementation. */
|
||||||
//@{
|
//@{
|
||||||
/// Read data.
|
/// Read data.
|
||||||
virtual void serialize( void * data, int len )
|
virtual uint serialize( void * data, uint len )
|
||||||
{
|
{
|
||||||
nvDebugCheck(data != NULL);
|
nvDebugCheck(data != NULL);
|
||||||
m_s->serialize( data, len );
|
len = m_s->serialize( data, len );
|
||||||
|
|
||||||
if( m_s->isError() ) {
|
if( m_s->isError() ) {
|
||||||
throw std::exception();
|
throw std::exception();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return len;
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual void seek( int pos )
|
virtual void seek( uint pos )
|
||||||
{
|
{
|
||||||
m_s->seek( pos );
|
m_s->seek( pos );
|
||||||
|
|
||||||
@ -305,12 +314,12 @@ public:
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual int tell() const
|
virtual uint tell() const
|
||||||
{
|
{
|
||||||
return m_s->tell();
|
return m_s->tell();
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual int size() const
|
virtual uint size() const
|
||||||
{
|
{
|
||||||
return m_s->size();
|
return m_s->size();
|
||||||
}
|
}
|
||||||
|
@ -209,48 +209,11 @@ StringBuilder::StringBuilder( const StringBuilder & s ) : m_size(0), m_str(NULL)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/** Copy string. */
|
/** Copy string. */
|
||||||
StringBuilder::StringBuilder( const char * s )
|
StringBuilder::StringBuilder( const char * s ) : m_size(0), m_str(NULL)
|
||||||
{
|
{
|
||||||
copy(s);
|
copy(s);
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Allocate and copy string. */
|
|
||||||
StringBuilder::StringBuilder( int size_hint, const StringBuilder & s) : m_size(size_hint), m_str(NULL)
|
|
||||||
{
|
|
||||||
nvDebugCheck(m_size > 0);
|
|
||||||
m_str = strAlloc(m_size);
|
|
||||||
copy(s);
|
|
||||||
}
|
|
||||||
|
|
||||||
/** Allocate and format string. */
|
|
||||||
StringBuilder::StringBuilder( const char * fmt, ... ) : m_size(0), m_str(NULL)
|
|
||||||
{
|
|
||||||
nvDebugCheck(fmt != NULL);
|
|
||||||
va_list arg;
|
|
||||||
va_start( arg, fmt );
|
|
||||||
|
|
||||||
format( fmt, arg );
|
|
||||||
|
|
||||||
va_end( arg );
|
|
||||||
}
|
|
||||||
|
|
||||||
/** Allocate and format string. */
|
|
||||||
StringBuilder::StringBuilder( int size_hint, const char * fmt, ... ) : m_size(size_hint), m_str(NULL)
|
|
||||||
{
|
|
||||||
nvDebugCheck(m_size > 0);
|
|
||||||
nvDebugCheck(fmt != NULL);
|
|
||||||
|
|
||||||
m_str = strAlloc(m_size);
|
|
||||||
|
|
||||||
va_list arg;
|
|
||||||
va_start( arg, fmt );
|
|
||||||
|
|
||||||
format( fmt, arg );
|
|
||||||
|
|
||||||
va_end( arg );
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/** Delete the string. */
|
/** Delete the string. */
|
||||||
StringBuilder::~StringBuilder()
|
StringBuilder::~StringBuilder()
|
||||||
{
|
{
|
||||||
@ -278,8 +241,7 @@ StringBuilder & StringBuilder::format( const char * fmt, ... )
|
|||||||
/** Format a string safely. */
|
/** Format a string safely. */
|
||||||
StringBuilder & StringBuilder::format( const char * fmt, va_list arg )
|
StringBuilder & StringBuilder::format( const char * fmt, va_list arg )
|
||||||
{
|
{
|
||||||
nvCheck(fmt != NULL);
|
nvDebugCheck(fmt != NULL);
|
||||||
nvCheck(m_size >= 0);
|
|
||||||
|
|
||||||
if( m_size == 0 ) {
|
if( m_size == 0 ) {
|
||||||
m_size = 64;
|
m_size = 64;
|
||||||
@ -327,8 +289,7 @@ StringBuilder & StringBuilder::format( const char * fmt, va_list arg )
|
|||||||
/** Append a string. */
|
/** Append a string. */
|
||||||
StringBuilder & StringBuilder::append( const char * s )
|
StringBuilder & StringBuilder::append( const char * s )
|
||||||
{
|
{
|
||||||
nvCheck(s != NULL);
|
nvDebugCheck(s != NULL);
|
||||||
nvCheck(m_size >= 0);
|
|
||||||
|
|
||||||
const uint slen = uint(strlen( s ));
|
const uint slen = uint(strlen( s ));
|
||||||
|
|
||||||
@ -475,31 +436,6 @@ void StringBuilder::reset()
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
Path::Path(const char * fmt, ...)
|
|
||||||
{
|
|
||||||
nvDebugCheck( fmt != NULL );
|
|
||||||
|
|
||||||
va_list arg;
|
|
||||||
va_start( arg, fmt );
|
|
||||||
|
|
||||||
format( fmt, arg );
|
|
||||||
|
|
||||||
va_end( arg );
|
|
||||||
}
|
|
||||||
|
|
||||||
Path::Path(int size_hint, const char * fmt, ...) : StringBuilder(size_hint)
|
|
||||||
{
|
|
||||||
nvDebugCheck( fmt != NULL );
|
|
||||||
|
|
||||||
va_list arg;
|
|
||||||
va_start( arg, fmt );
|
|
||||||
|
|
||||||
format( fmt, arg );
|
|
||||||
|
|
||||||
va_end( arg );
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/// Get the file name from a path.
|
/// Get the file name from a path.
|
||||||
const char * Path::fileName() const
|
const char * Path::fileName() const
|
||||||
{
|
{
|
||||||
|
@ -14,7 +14,7 @@ namespace nv
|
|||||||
|
|
||||||
uint strHash(const char * str, uint h) NV_PURE;
|
uint strHash(const char * str, uint h) NV_PURE;
|
||||||
|
|
||||||
/// String hash vased on Bernstein's hash.
|
/// String hash based on Bernstein's hash.
|
||||||
inline uint strHash(const char * data, uint h = 5381)
|
inline uint strHash(const char * data, uint h = 5381)
|
||||||
{
|
{
|
||||||
uint i;
|
uint i;
|
||||||
@ -47,9 +47,6 @@ namespace nv
|
|||||||
explicit StringBuilder( int size_hint );
|
explicit StringBuilder( int size_hint );
|
||||||
StringBuilder( const char * str );
|
StringBuilder( const char * str );
|
||||||
StringBuilder( const StringBuilder & );
|
StringBuilder( const StringBuilder & );
|
||||||
StringBuilder( int size_hint, const StringBuilder & );
|
|
||||||
StringBuilder( const char * format, ... ) __attribute__((format (printf, 2, 3)));
|
|
||||||
StringBuilder( int size_hint, const char * format, ... ) __attribute__((format (printf, 3, 4)));
|
|
||||||
|
|
||||||
~StringBuilder();
|
~StringBuilder();
|
||||||
|
|
||||||
@ -122,16 +119,14 @@ namespace nv
|
|||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
/// Path string.
|
/// Path string. @@ This should be called PathBuilder.
|
||||||
class NVCORE_CLASS Path : public StringBuilder
|
class NVCORE_CLASS Path : public StringBuilder
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
Path() : StringBuilder() {}
|
Path() : StringBuilder() {}
|
||||||
explicit Path(int size_hint) : StringBuilder(size_hint) {}
|
explicit Path(int size_hint) : StringBuilder(size_hint) {}
|
||||||
Path(const StringBuilder & str) : StringBuilder(str) {}
|
Path(const char * str) : StringBuilder(str) {}
|
||||||
Path(int size_hint, const StringBuilder & str) : StringBuilder(size_hint, str) {}
|
Path(const Path & path) : StringBuilder(path) {}
|
||||||
Path(const char * format, ...) __attribute__((format (printf, 2, 3)));
|
|
||||||
Path(int size_hint, const char * format, ...) __attribute__((format (printf, 3, 4)));
|
|
||||||
|
|
||||||
const char * fileName() const;
|
const char * fileName() const;
|
||||||
const char * extension() const;
|
const char * extension() const;
|
||||||
@ -213,9 +208,12 @@ namespace nv
|
|||||||
/// Implement value semantics.
|
/// Implement value semantics.
|
||||||
String & operator=( const String & str )
|
String & operator=( const String & str )
|
||||||
{
|
{
|
||||||
release();
|
if (str.data != data)
|
||||||
data = str.data;
|
{
|
||||||
addRef();
|
release();
|
||||||
|
data = str.data;
|
||||||
|
addRef();
|
||||||
|
}
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -41,17 +41,17 @@ public:
|
|||||||
ByteOrder byteOrder() const { return m_byteOrder; }
|
ByteOrder byteOrder() const { return m_byteOrder; }
|
||||||
|
|
||||||
|
|
||||||
/// Serialize the given data. @@ Should return bytes serialized?
|
/// Serialize the given data.
|
||||||
virtual void serialize( void * data, int len ) = 0;
|
virtual uint serialize( void * data, uint len ) = 0;
|
||||||
|
|
||||||
/// Move to the given position in the archive.
|
/// Move to the given position in the archive.
|
||||||
virtual void seek( int pos ) = 0;
|
virtual void seek( uint pos ) = 0;
|
||||||
|
|
||||||
/// Return the current position in the archive.
|
/// Return the current position in the archive.
|
||||||
virtual int tell() const = 0;
|
virtual uint tell() const = 0;
|
||||||
|
|
||||||
/// Return the current size of the archive.
|
/// Return the current size of the archive.
|
||||||
virtual int size() const = 0;
|
virtual uint size() const = 0;
|
||||||
|
|
||||||
/// Determine if there has been any error.
|
/// Determine if there has been any error.
|
||||||
virtual bool isError() const = 0;
|
virtual bool isError() const = 0;
|
||||||
@ -136,13 +136,13 @@ public:
|
|||||||
protected:
|
protected:
|
||||||
|
|
||||||
/// Serialize in the stream byte order.
|
/// Serialize in the stream byte order.
|
||||||
Stream & byteOrderSerialize( void * v, int len ) {
|
Stream & byteOrderSerialize( void * v, uint len ) {
|
||||||
if( m_byteOrder == getSystemByteOrder() ) {
|
if( m_byteOrder == getSystemByteOrder() ) {
|
||||||
serialize( v, len );
|
serialize( v, len );
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
for( int i=len-1; i>=0; i-- ) {
|
for( uint i = len; i > 0; i-- ) {
|
||||||
serialize( (uint8 *)v + i, 1 );
|
serialize( (uint8 *)v + i - 1, 1 );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return *this;
|
return *this;
|
||||||
|
@ -532,7 +532,7 @@ DDSHeader::DDSHeader()
|
|||||||
|
|
||||||
// Store version information on the reserved header attributes.
|
// Store version information on the reserved header attributes.
|
||||||
this->reserved[9] = MAKEFOURCC('N', 'V', 'T', 'T');
|
this->reserved[9] = MAKEFOURCC('N', 'V', 'T', 'T');
|
||||||
this->reserved[10] = (2 << 16) | (0 << 8) | (4); // major.minor.revision
|
this->reserved[10] = (2 << 16) | (0 << 8) | (6); // major.minor.revision
|
||||||
|
|
||||||
this->pf.size = 32;
|
this->pf.size = 32;
|
||||||
this->pf.flags = 0;
|
this->pf.flags = 0;
|
||||||
@ -989,10 +989,10 @@ void DirectDrawSurface::readLinearImage(Image * img)
|
|||||||
stream->serialize(&c, byteCount);
|
stream->serialize(&c, byteCount);
|
||||||
|
|
||||||
Color32 pixel(0, 0, 0, 0xFF);
|
Color32 pixel(0, 0, 0, 0xFF);
|
||||||
pixel.r = PixelFormat::convert(c >> rshift, rsize, 8);
|
pixel.r = PixelFormat::convert((c & header.pf.rmask) >> rshift, rsize, 8);
|
||||||
pixel.g = PixelFormat::convert(c >> gshift, gsize, 8);
|
pixel.g = PixelFormat::convert((c & header.pf.gmask) >> gshift, gsize, 8);
|
||||||
pixel.b = PixelFormat::convert(c >> bshift, bsize, 8);
|
pixel.b = PixelFormat::convert((c & header.pf.bmask) >> bshift, bsize, 8);
|
||||||
pixel.a = PixelFormat::convert(c >> ashift, asize, 8);
|
pixel.a = PixelFormat::convert((c & header.pf.amask) >> ashift, asize, 8);
|
||||||
|
|
||||||
img->pixel(x, y) = pixel;
|
img->pixel(x, y) = pixel;
|
||||||
}
|
}
|
||||||
|
@ -33,11 +33,10 @@
|
|||||||
* http://www.dspguide.com/ch16.htm
|
* http://www.dspguide.com/ch16.htm
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include "Filter.h"
|
||||||
|
|
||||||
#include <nvcore/Containers.h> // swap
|
|
||||||
#include <nvmath/nvmath.h> // fabs
|
|
||||||
#include <nvmath/Vector.h> // Vector4
|
#include <nvmath/Vector.h> // Vector4
|
||||||
#include <nvimage/Filter.h>
|
#include <nvcore/Containers.h> // swap
|
||||||
|
|
||||||
using namespace nv;
|
using namespace nv;
|
||||||
|
|
||||||
@ -504,7 +503,7 @@ void Kernel2::initBlendedSobel(const Vector4 & scale)
|
|||||||
|
|
||||||
for (int i = 0; i < 7; i++) {
|
for (int i = 0; i < 7; i++) {
|
||||||
for (int e = 0; e < 7; e++) {
|
for (int e = 0; e < 7; e++) {
|
||||||
m_data[i * 9 + e + 1] += elements[i * 7 + e] * scale.z();
|
m_data[(i + 1) * 9 + e + 1] += elements[i * 7 + e] * scale.z();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -519,7 +518,7 @@ void Kernel2::initBlendedSobel(const Vector4 & scale)
|
|||||||
|
|
||||||
for (int i = 0; i < 5; i++) {
|
for (int i = 0; i < 5; i++) {
|
||||||
for (int e = 0; e < 5; e++) {
|
for (int e = 0; e < 5; e++) {
|
||||||
m_data[i * 9 + e + 2] += elements[i * 5 + e] * scale.y();
|
m_data[(i + 2) * 9 + e + 2] += elements[i * 5 + e] * scale.y();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -532,7 +531,7 @@ void Kernel2::initBlendedSobel(const Vector4 & scale)
|
|||||||
|
|
||||||
for (int i = 0; i < 3; i++) {
|
for (int i = 0; i < 3; i++) {
|
||||||
for (int e = 0; e < 3; e++) {
|
for (int e = 0; e < 3; e++) {
|
||||||
m_data[i * 9 + e + 3] += elements[i * 3 + e] * scale.x();
|
m_data[(i + 3) * 9 + e + 3] += elements[i * 3 + e] * scale.x();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -582,7 +581,6 @@ PolyphaseKernel::PolyphaseKernel(const Filter & f, uint srcLength, uint dstLengt
|
|||||||
m_data[i * m_windowSize + j] /= total;
|
m_data[i * m_windowSize + j] /= total;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
PolyphaseKernel::~PolyphaseKernel()
|
PolyphaseKernel::~PolyphaseKernel()
|
||||||
|
@ -11,16 +11,16 @@ namespace nv
|
|||||||
class Vector4;
|
class Vector4;
|
||||||
|
|
||||||
/// Base filter class.
|
/// Base filter class.
|
||||||
class Filter
|
class NVIMAGE_CLASS Filter
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
NVIMAGE_API Filter(float width);
|
Filter(float width);
|
||||||
NVIMAGE_API virtual ~Filter();
|
virtual ~Filter();
|
||||||
|
|
||||||
NVIMAGE_API float width() const { return m_width; }
|
float width() const { return m_width; }
|
||||||
NVIMAGE_API float sampleDelta(float x, float scale) const;
|
float sampleDelta(float x, float scale) const;
|
||||||
NVIMAGE_API float sampleBox(float x, float scale, int samples) const;
|
float sampleBox(float x, float scale, int samples) const;
|
||||||
NVIMAGE_API float sampleTriangle(float x, float scale, int samples) const;
|
float sampleTriangle(float x, float scale, int samples) const;
|
||||||
|
|
||||||
virtual float evaluate(float x) const = 0;
|
virtual float evaluate(float x) const = 0;
|
||||||
|
|
||||||
@ -29,56 +29,56 @@ namespace nv
|
|||||||
};
|
};
|
||||||
|
|
||||||
// Box filter.
|
// Box filter.
|
||||||
class BoxFilter : public Filter
|
class NVIMAGE_CLASS BoxFilter : public Filter
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
NVIMAGE_API BoxFilter();
|
BoxFilter();
|
||||||
NVIMAGE_API BoxFilter(float width);
|
BoxFilter(float width);
|
||||||
NVIMAGE_API virtual float evaluate(float x) const;
|
virtual float evaluate(float x) const;
|
||||||
};
|
};
|
||||||
|
|
||||||
// Triangle (bilinear/tent) filter.
|
// Triangle (bilinear/tent) filter.
|
||||||
class TriangleFilter : public Filter
|
class NVIMAGE_CLASS TriangleFilter : public Filter
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
NVIMAGE_API TriangleFilter();
|
TriangleFilter();
|
||||||
NVIMAGE_API TriangleFilter(float width);
|
TriangleFilter(float width);
|
||||||
NVIMAGE_API virtual float evaluate(float x) const;
|
virtual float evaluate(float x) const;
|
||||||
};
|
};
|
||||||
|
|
||||||
// Quadratic (bell) filter.
|
// Quadratic (bell) filter.
|
||||||
class QuadraticFilter : public Filter
|
class NVIMAGE_CLASS QuadraticFilter : public Filter
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
NVIMAGE_API QuadraticFilter();
|
QuadraticFilter();
|
||||||
NVIMAGE_API virtual float evaluate(float x) const;
|
virtual float evaluate(float x) const;
|
||||||
};
|
};
|
||||||
|
|
||||||
// Cubic filter from Thatcher Ulrich.
|
// Cubic filter from Thatcher Ulrich.
|
||||||
class CubicFilter : public Filter
|
class NVIMAGE_CLASS CubicFilter : public Filter
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
NVIMAGE_API CubicFilter();
|
CubicFilter();
|
||||||
NVIMAGE_API virtual float evaluate(float x) const;
|
virtual float evaluate(float x) const;
|
||||||
};
|
};
|
||||||
|
|
||||||
// Cubic b-spline filter from Paul Heckbert.
|
// Cubic b-spline filter from Paul Heckbert.
|
||||||
class BSplineFilter : public Filter
|
class NVIMAGE_CLASS BSplineFilter : public Filter
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
NVIMAGE_API BSplineFilter();
|
BSplineFilter();
|
||||||
NVIMAGE_API virtual float evaluate(float x) const;
|
virtual float evaluate(float x) const;
|
||||||
};
|
};
|
||||||
|
|
||||||
/// Mitchell & Netravali's two-param cubic
|
/// Mitchell & Netravali's two-param cubic
|
||||||
/// @see "Reconstruction Filters in Computer Graphics", SIGGRAPH 88
|
/// @see "Reconstruction Filters in Computer Graphics", SIGGRAPH 88
|
||||||
class MitchellFilter : public Filter
|
class NVIMAGE_CLASS MitchellFilter : public Filter
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
NVIMAGE_API MitchellFilter();
|
MitchellFilter();
|
||||||
NVIMAGE_API virtual float evaluate(float x) const;
|
virtual float evaluate(float x) const;
|
||||||
|
|
||||||
NVIMAGE_API void setParameters(float a, float b);
|
void setParameters(float b, float c);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
float p0, p2, p3;
|
float p0, p2, p3;
|
||||||
@ -86,29 +86,29 @@ namespace nv
|
|||||||
};
|
};
|
||||||
|
|
||||||
// Lanczos3 filter.
|
// Lanczos3 filter.
|
||||||
class LanczosFilter : public Filter
|
class NVIMAGE_CLASS LanczosFilter : public Filter
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
NVIMAGE_API LanczosFilter();
|
LanczosFilter();
|
||||||
NVIMAGE_API virtual float evaluate(float x) const;
|
virtual float evaluate(float x) const;
|
||||||
};
|
};
|
||||||
|
|
||||||
// Sinc filter.
|
// Sinc filter.
|
||||||
class SincFilter : public Filter
|
class NVIMAGE_CLASS SincFilter : public Filter
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
NVIMAGE_API SincFilter(float w);
|
SincFilter(float w);
|
||||||
NVIMAGE_API virtual float evaluate(float x) const;
|
virtual float evaluate(float x) const;
|
||||||
};
|
};
|
||||||
|
|
||||||
// Kaiser filter.
|
// Kaiser filter.
|
||||||
class KaiserFilter : public Filter
|
class NVIMAGE_CLASS KaiserFilter : public Filter
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
NVIMAGE_API KaiserFilter(float w);
|
KaiserFilter(float w);
|
||||||
NVIMAGE_API virtual float evaluate(float x) const;
|
virtual float evaluate(float x) const;
|
||||||
|
|
||||||
NVIMAGE_API void setParameters(float a, float stretch);
|
void setParameters(float a, float stretch);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
float alpha;
|
float alpha;
|
||||||
@ -118,12 +118,12 @@ namespace nv
|
|||||||
|
|
||||||
|
|
||||||
/// A 1D kernel. Used to precompute filter weights.
|
/// A 1D kernel. Used to precompute filter weights.
|
||||||
class Kernel1
|
class NVIMAGE_CLASS Kernel1
|
||||||
{
|
{
|
||||||
NV_FORBID_COPY(Kernel1);
|
NV_FORBID_COPY(Kernel1);
|
||||||
public:
|
public:
|
||||||
NVIMAGE_API Kernel1(const Filter & f, int iscale, int samples = 32);
|
Kernel1(const Filter & f, int iscale, int samples = 32);
|
||||||
NVIMAGE_API ~Kernel1();
|
~Kernel1();
|
||||||
|
|
||||||
float valueAt(uint x) const {
|
float valueAt(uint x) const {
|
||||||
nvDebugCheck(x < (uint)m_windowSize);
|
nvDebugCheck(x < (uint)m_windowSize);
|
||||||
@ -138,7 +138,7 @@ namespace nv
|
|||||||
return m_width;
|
return m_width;
|
||||||
}
|
}
|
||||||
|
|
||||||
NVIMAGE_API void debugPrint();
|
void debugPrint();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
int m_windowSize;
|
int m_windowSize;
|
||||||
@ -148,15 +148,15 @@ namespace nv
|
|||||||
|
|
||||||
|
|
||||||
/// A 2D kernel.
|
/// A 2D kernel.
|
||||||
class Kernel2
|
class NVIMAGE_CLASS Kernel2
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
NVIMAGE_API Kernel2(uint width);
|
Kernel2(uint width);
|
||||||
NVIMAGE_API Kernel2(const Kernel2 & k);
|
Kernel2(const Kernel2 & k);
|
||||||
NVIMAGE_API ~Kernel2();
|
~Kernel2();
|
||||||
|
|
||||||
NVIMAGE_API void normalize();
|
void normalize();
|
||||||
NVIMAGE_API void transpose();
|
void transpose();
|
||||||
|
|
||||||
float valueAt(uint x, uint y) const {
|
float valueAt(uint x, uint y) const {
|
||||||
return m_data[y * m_windowSize + x];
|
return m_data[y * m_windowSize + x];
|
||||||
@ -166,12 +166,12 @@ namespace nv
|
|||||||
return m_windowSize;
|
return m_windowSize;
|
||||||
}
|
}
|
||||||
|
|
||||||
NVIMAGE_API void initLaplacian();
|
void initLaplacian();
|
||||||
NVIMAGE_API void initEdgeDetection();
|
void initEdgeDetection();
|
||||||
NVIMAGE_API void initSobel();
|
void initSobel();
|
||||||
NVIMAGE_API void initPrewitt();
|
void initPrewitt();
|
||||||
|
|
||||||
NVIMAGE_API void initBlendedSobel(const Vector4 & scale);
|
void initBlendedSobel(const Vector4 & scale);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
const uint m_windowSize;
|
const uint m_windowSize;
|
||||||
@ -180,12 +180,12 @@ namespace nv
|
|||||||
|
|
||||||
|
|
||||||
/// A 1D polyphase kernel
|
/// A 1D polyphase kernel
|
||||||
class PolyphaseKernel
|
class NVIMAGE_CLASS PolyphaseKernel
|
||||||
{
|
{
|
||||||
NV_FORBID_COPY(PolyphaseKernel);
|
NV_FORBID_COPY(PolyphaseKernel);
|
||||||
public:
|
public:
|
||||||
NVIMAGE_API PolyphaseKernel(const Filter & f, uint srcLength, uint dstLength, int samples = 32);
|
PolyphaseKernel(const Filter & f, uint srcLength, uint dstLength, int samples = 32);
|
||||||
NVIMAGE_API ~PolyphaseKernel();
|
~PolyphaseKernel();
|
||||||
|
|
||||||
int windowSize() const {
|
int windowSize() const {
|
||||||
return m_windowSize;
|
return m_windowSize;
|
||||||
@ -205,7 +205,7 @@ namespace nv
|
|||||||
return m_data[column * m_windowSize + x];
|
return m_data[column * m_windowSize + x];
|
||||||
}
|
}
|
||||||
|
|
||||||
NVIMAGE_API void debugPrint() const;
|
void debugPrint() const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
int m_windowSize;
|
int m_windowSize;
|
||||||
|
@ -1,16 +1,18 @@
|
|||||||
// This code is in the public domain -- castanyo@yahoo.es
|
// This code is in the public domain -- castanyo@yahoo.es
|
||||||
|
|
||||||
#include <nvcore/Containers.h>
|
|
||||||
#include <nvcore/Ptr.h>
|
|
||||||
|
|
||||||
#include <nvmath/Color.h>
|
|
||||||
|
|
||||||
#include "FloatImage.h"
|
#include "FloatImage.h"
|
||||||
#include "Filter.h"
|
#include "Filter.h"
|
||||||
#include "Image.h"
|
#include "Image.h"
|
||||||
|
|
||||||
|
#include <nvmath/Color.h>
|
||||||
|
#include <nvmath/Matrix.h>
|
||||||
|
|
||||||
|
#include <nvcore/Containers.h>
|
||||||
|
#include <nvcore/Ptr.h>
|
||||||
|
|
||||||
#include <math.h>
|
#include <math.h>
|
||||||
|
|
||||||
|
|
||||||
using namespace nv;
|
using namespace nv;
|
||||||
|
|
||||||
namespace
|
namespace
|
||||||
@ -140,7 +142,8 @@ Image * FloatImage::createImageGammaCorrect(float gamma/*= 2.2f*/) const
|
|||||||
/// Allocate a 2d float image of the given format and the given extents.
|
/// Allocate a 2d float image of the given format and the given extents.
|
||||||
void FloatImage::allocate(uint c, uint w, uint h)
|
void FloatImage::allocate(uint c, uint w, uint h)
|
||||||
{
|
{
|
||||||
nvCheck(m_mem == NULL);
|
free();
|
||||||
|
|
||||||
m_width = w;
|
m_width = w;
|
||||||
m_height = h;
|
m_height = h;
|
||||||
m_componentNum = c;
|
m_componentNum = c;
|
||||||
@ -151,7 +154,6 @@ void FloatImage::allocate(uint c, uint w, uint h)
|
|||||||
/// Free the image, but don't clear the members.
|
/// Free the image, but don't clear the members.
|
||||||
void FloatImage::free()
|
void FloatImage::free()
|
||||||
{
|
{
|
||||||
nvCheck(m_mem != NULL);
|
|
||||||
nv::mem::free( reinterpret_cast<void *>(m_mem) );
|
nv::mem::free( reinterpret_cast<void *>(m_mem) );
|
||||||
m_mem = NULL;
|
m_mem = NULL;
|
||||||
}
|
}
|
||||||
@ -549,6 +551,15 @@ FloatImage * FloatImage::downSample(const Filter & filter, WrapMode wm) const
|
|||||||
return resize(filter, w, h, wm);
|
return resize(filter, w, h, wm);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Downsample applying a 1D kernel separately in each dimension.
|
||||||
|
FloatImage * FloatImage::downSample(const Filter & filter, WrapMode wm, uint alpha) const
|
||||||
|
{
|
||||||
|
const uint w = max(1, m_width / 2);
|
||||||
|
const uint h = max(1, m_height / 2);
|
||||||
|
|
||||||
|
return resize(filter, w, h, wm, alpha);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/// Downsample applying a 1D kernel separately in each dimension.
|
/// Downsample applying a 1D kernel separately in each dimension.
|
||||||
FloatImage * FloatImage::resize(const Filter & filter, uint w, uint h, WrapMode wm) const
|
FloatImage * FloatImage::resize(const Filter & filter, uint w, uint h, WrapMode wm) const
|
||||||
@ -620,10 +631,56 @@ FloatImage * FloatImage::resize(const Filter & filter, uint w, uint h, WrapMode
|
|||||||
return dst_image.release();
|
return dst_image.release();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Downsample applying a 1D kernel separately in each dimension.
|
||||||
|
FloatImage * FloatImage::resize(const Filter & filter, uint w, uint h, WrapMode wm, uint alpha) const
|
||||||
|
{
|
||||||
|
nvCheck(alpha < m_componentNum);
|
||||||
|
|
||||||
|
AutoPtr<FloatImage> tmp_image( new FloatImage() );
|
||||||
|
AutoPtr<FloatImage> dst_image( new FloatImage() );
|
||||||
|
|
||||||
|
PolyphaseKernel xkernel(filter, m_width, w, 32);
|
||||||
|
PolyphaseKernel ykernel(filter, m_height, h, 32);
|
||||||
|
|
||||||
|
{
|
||||||
|
tmp_image->allocate(m_componentNum, w, m_height);
|
||||||
|
dst_image->allocate(m_componentNum, w, h);
|
||||||
|
|
||||||
|
Array<float> tmp_column(h);
|
||||||
|
tmp_column.resize(h);
|
||||||
|
|
||||||
|
for (uint c = 0; c < m_componentNum; c++)
|
||||||
|
{
|
||||||
|
float * tmp_channel = tmp_image->channel(c);
|
||||||
|
|
||||||
|
for (uint y = 0; y < m_height; y++) {
|
||||||
|
this->applyKernelHorizontal(xkernel, y, c, alpha, wm, tmp_channel + y * w);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Process all channels before applying vertical kernel to make sure alpha has been computed.
|
||||||
|
|
||||||
|
for (uint c = 0; c < m_componentNum; c++)
|
||||||
|
{
|
||||||
|
float * dst_channel = dst_image->channel(c);
|
||||||
|
|
||||||
|
for (uint x = 0; x < w; x++) {
|
||||||
|
tmp_image->applyKernelVertical(ykernel, x, c, alpha, wm, tmp_column.unsecureBuffer());
|
||||||
|
|
||||||
|
for (uint y = 0; y < h; y++) {
|
||||||
|
dst_channel[y * w + x] = tmp_column[y];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return dst_image.release();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/// Apply 2D kernel at the given coordinates and return result.
|
/// Apply 2D kernel at the given coordinates and return result.
|
||||||
float FloatImage::applyKernel(const Kernel2 * k, int x, int y, int c, WrapMode wm) const
|
float FloatImage::applyKernel(const Kernel2 * k, int x, int y, uint c, WrapMode wm) const
|
||||||
{
|
{
|
||||||
nvDebugCheck(k != NULL);
|
nvDebugCheck(k != NULL);
|
||||||
|
|
||||||
@ -652,7 +709,7 @@ float FloatImage::applyKernel(const Kernel2 * k, int x, int y, int c, WrapMode w
|
|||||||
|
|
||||||
|
|
||||||
/// Apply 1D vertical kernel at the given coordinates and return result.
|
/// Apply 1D vertical kernel at the given coordinates and return result.
|
||||||
float FloatImage::applyKernelVertical(const Kernel1 * k, int x, int y, int c, WrapMode wm) const
|
float FloatImage::applyKernelVertical(const Kernel1 * k, int x, int y, uint c, WrapMode wm) const
|
||||||
{
|
{
|
||||||
nvDebugCheck(k != NULL);
|
nvDebugCheck(k != NULL);
|
||||||
|
|
||||||
@ -674,7 +731,7 @@ float FloatImage::applyKernelVertical(const Kernel1 * k, int x, int y, int c, Wr
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Apply 1D horizontal kernel at the given coordinates and return result.
|
/// Apply 1D horizontal kernel at the given coordinates and return result.
|
||||||
float FloatImage::applyKernelHorizontal(const Kernel1 * k, int x, int y, int c, WrapMode wm) const
|
float FloatImage::applyKernelHorizontal(const Kernel1 * k, int x, int y, uint c, WrapMode wm) const
|
||||||
{
|
{
|
||||||
nvDebugCheck(k != NULL);
|
nvDebugCheck(k != NULL);
|
||||||
|
|
||||||
@ -697,7 +754,7 @@ float FloatImage::applyKernelHorizontal(const Kernel1 * k, int x, int y, int c,
|
|||||||
|
|
||||||
|
|
||||||
/// Apply 1D vertical kernel at the given coordinates and return result.
|
/// Apply 1D vertical kernel at the given coordinates and return result.
|
||||||
void FloatImage::applyKernelVertical(const PolyphaseKernel & k, int x, int c, WrapMode wm, float * output) const
|
void FloatImage::applyKernelVertical(const PolyphaseKernel & k, int x, uint c, WrapMode wm, float * __restrict output) const
|
||||||
{
|
{
|
||||||
const uint length = k.length();
|
const uint length = k.length();
|
||||||
const float scale = float(length) / float(m_height);
|
const float scale = float(length) / float(m_height);
|
||||||
@ -729,7 +786,7 @@ void FloatImage::applyKernelVertical(const PolyphaseKernel & k, int x, int c, Wr
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Apply 1D horizontal kernel at the given coordinates and return result.
|
/// Apply 1D horizontal kernel at the given coordinates and return result.
|
||||||
void FloatImage::applyKernelHorizontal(const PolyphaseKernel & k, int y, int c, WrapMode wm, float * output) const
|
void FloatImage::applyKernelHorizontal(const PolyphaseKernel & k, int y, uint c, WrapMode wm, float * __restrict output) const
|
||||||
{
|
{
|
||||||
const uint length = k.length();
|
const uint length = k.length();
|
||||||
const float scale = float(length) / float(m_width);
|
const float scale = float(length) / float(m_width);
|
||||||
@ -760,3 +817,93 @@ void FloatImage::applyKernelHorizontal(const PolyphaseKernel & k, int y, int c,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/// Apply 1D vertical kernel at the given coordinates and return result.
|
||||||
|
void FloatImage::applyKernelVertical(const PolyphaseKernel & k, int x, uint c, uint a, WrapMode wm, float * __restrict output) const
|
||||||
|
{
|
||||||
|
const uint length = k.length();
|
||||||
|
const float scale = float(length) / float(m_height);
|
||||||
|
const float iscale = 1.0f / scale;
|
||||||
|
|
||||||
|
const float width = k.width();
|
||||||
|
const int windowSize = k.windowSize();
|
||||||
|
|
||||||
|
const float * channel = this->channel(c);
|
||||||
|
const float * alpha = this->channel(a);
|
||||||
|
|
||||||
|
for (uint i = 0; i < length; i++)
|
||||||
|
{
|
||||||
|
const float center = (0.5f + i) * iscale;
|
||||||
|
|
||||||
|
const int left = (int)floorf(center - width);
|
||||||
|
const int right = (int)ceilf(center + width);
|
||||||
|
nvCheck(right - left <= windowSize);
|
||||||
|
|
||||||
|
float norm = 0;
|
||||||
|
float sum = 0;
|
||||||
|
for (int j = 0; j < windowSize; ++j)
|
||||||
|
{
|
||||||
|
const int idx = this->index(x, j+left, wm);
|
||||||
|
|
||||||
|
float w = k.valueAt(i, j) * (alpha[idx] + (1.0f / 256.0f));
|
||||||
|
norm += w;
|
||||||
|
sum += w * channel[idx];
|
||||||
|
}
|
||||||
|
|
||||||
|
output[i] = sum / norm;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Apply 1D horizontal kernel at the given coordinates and return result.
|
||||||
|
void FloatImage::applyKernelHorizontal(const PolyphaseKernel & k, int y, uint c, uint a, WrapMode wm, float * __restrict output) const
|
||||||
|
{
|
||||||
|
const uint length = k.length();
|
||||||
|
const float scale = float(length) / float(m_width);
|
||||||
|
const float iscale = 1.0f / scale;
|
||||||
|
|
||||||
|
const float width = k.width();
|
||||||
|
const int windowSize = k.windowSize();
|
||||||
|
|
||||||
|
const float * channel = this->channel(c);
|
||||||
|
const float * alpha = this->channel(a);
|
||||||
|
|
||||||
|
for (uint i = 0; i < length; i++)
|
||||||
|
{
|
||||||
|
const float center = (0.5f + i) * iscale;
|
||||||
|
|
||||||
|
const int left = (int)floorf(center - width);
|
||||||
|
const int right = (int)ceilf(center + width);
|
||||||
|
nvDebugCheck(right - left <= windowSize);
|
||||||
|
|
||||||
|
float norm = 0.0f;
|
||||||
|
float sum = 0;
|
||||||
|
for (int j = 0; j < windowSize; ++j)
|
||||||
|
{
|
||||||
|
const int idx = this->index(left + j, y, wm);
|
||||||
|
|
||||||
|
float w = k.valueAt(i, j) * (alpha[idx] + (1.0f / 256.0f));
|
||||||
|
norm += w;
|
||||||
|
sum += w * channel[idx];
|
||||||
|
}
|
||||||
|
|
||||||
|
output[i] = sum / norm;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
FloatImage* FloatImage::clone() const
|
||||||
|
{
|
||||||
|
FloatImage* copy = new FloatImage();
|
||||||
|
copy->m_width = m_width;
|
||||||
|
copy->m_height = m_height;
|
||||||
|
copy->m_componentNum = m_componentNum;
|
||||||
|
copy->m_count = m_count;
|
||||||
|
|
||||||
|
if(m_mem)
|
||||||
|
{
|
||||||
|
copy->allocate(m_componentNum, m_width, m_height);
|
||||||
|
memcpy(copy->m_mem, m_mem, m_count * sizeof(float));
|
||||||
|
}
|
||||||
|
|
||||||
|
return copy;
|
||||||
|
}
|
||||||
|
|
||||||
|
@ -3,12 +3,20 @@
|
|||||||
#ifndef NV_IMAGE_FLOATIMAGE_H
|
#ifndef NV_IMAGE_FLOATIMAGE_H
|
||||||
#define NV_IMAGE_FLOATIMAGE_H
|
#define NV_IMAGE_FLOATIMAGE_H
|
||||||
|
|
||||||
|
#include <nvimage/nvimage.h>
|
||||||
|
|
||||||
|
#include <nvmath/Vector.h>
|
||||||
|
|
||||||
#include <nvcore/Debug.h>
|
#include <nvcore/Debug.h>
|
||||||
#include <nvcore/Containers.h> // clamp
|
#include <nvcore/Containers.h> // clamp
|
||||||
#include <nvimage/nvimage.h>
|
|
||||||
|
#include <stdlib.h> // abs
|
||||||
|
|
||||||
|
|
||||||
namespace nv
|
namespace nv
|
||||||
{
|
{
|
||||||
|
class Vector4;
|
||||||
|
class Matrix;
|
||||||
class Image;
|
class Image;
|
||||||
class Filter;
|
class Filter;
|
||||||
class Kernel1;
|
class Kernel1;
|
||||||
@ -63,17 +71,19 @@ public:
|
|||||||
|
|
||||||
NVIMAGE_API FloatImage * fastDownSample() const;
|
NVIMAGE_API FloatImage * fastDownSample() const;
|
||||||
NVIMAGE_API FloatImage * downSample(const Filter & filter, WrapMode wm) const;
|
NVIMAGE_API FloatImage * downSample(const Filter & filter, WrapMode wm) const;
|
||||||
|
NVIMAGE_API FloatImage * downSample(const Filter & filter, WrapMode wm, uint alpha) const;
|
||||||
NVIMAGE_API FloatImage * resize(const Filter & filter, uint w, uint h, WrapMode wm) const;
|
NVIMAGE_API FloatImage * resize(const Filter & filter, uint w, uint h, WrapMode wm) const;
|
||||||
|
|
||||||
//NVIMAGE_API FloatImage * downSample(const Kernel1 & filter, WrapMode wm) const;
|
NVIMAGE_API FloatImage * resize(const Filter & filter, uint w, uint h, WrapMode wm, uint alpha) const;
|
||||||
//NVIMAGE_API FloatImage * downSample(const Kernel1 & filter, uint w, uint h, WrapMode wm) const;
|
|
||||||
//@}
|
//@}
|
||||||
|
|
||||||
NVIMAGE_API float applyKernel(const Kernel2 * k, int x, int y, int c, WrapMode wm) const;
|
NVIMAGE_API float applyKernel(const Kernel2 * k, int x, int y, uint c, WrapMode wm) const;
|
||||||
NVIMAGE_API float applyKernelVertical(const Kernel1 * k, int x, int y, int c, WrapMode wm) const;
|
NVIMAGE_API float applyKernelVertical(const Kernel1 * k, int x, int y, uint c, WrapMode wm) const;
|
||||||
NVIMAGE_API float applyKernelHorizontal(const Kernel1 * k, int x, int y, int c, WrapMode wm) const;
|
NVIMAGE_API float applyKernelHorizontal(const Kernel1 * k, int x, int y, uint c, WrapMode wm) const;
|
||||||
NVIMAGE_API void applyKernelVertical(const PolyphaseKernel & k, int x, int c, WrapMode wm, float * output) const;
|
NVIMAGE_API void applyKernelVertical(const PolyphaseKernel & k, int x, uint c, WrapMode wm, float * output) const;
|
||||||
NVIMAGE_API void applyKernelHorizontal(const PolyphaseKernel & k, int y, int c, WrapMode wm, float * output) const;
|
NVIMAGE_API void applyKernelHorizontal(const PolyphaseKernel & k, int y, uint c, WrapMode wm, float * output) const;
|
||||||
|
NVIMAGE_API void applyKernelVertical(const PolyphaseKernel & k, int x, uint c, uint a, WrapMode wm, float * output) const;
|
||||||
|
NVIMAGE_API void applyKernelHorizontal(const PolyphaseKernel & k, int y, uint c, uint a, WrapMode wm, float * output) const;
|
||||||
|
|
||||||
|
|
||||||
uint width() const { return m_width; }
|
uint width() const { return m_width; }
|
||||||
@ -109,6 +119,9 @@ public:
|
|||||||
float sampleLinearMirror(float x, float y, int c) const;
|
float sampleLinearMirror(float x, float y, int c) const;
|
||||||
//@}
|
//@}
|
||||||
|
|
||||||
|
|
||||||
|
FloatImage* clone() const;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
uint index(uint x, uint y) const;
|
uint index(uint x, uint y) const;
|
||||||
|
@ -21,15 +21,16 @@
|
|||||||
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
||||||
// OTHER DEALINGS IN THE SOFTWARE.
|
// OTHER DEALINGS IN THE SOFTWARE.
|
||||||
|
|
||||||
#include <nvcore/Ptr.h>
|
|
||||||
|
|
||||||
#include <nvmath/Color.h>
|
|
||||||
|
|
||||||
#include <nvimage/NormalMap.h>
|
#include <nvimage/NormalMap.h>
|
||||||
#include <nvimage/Filter.h>
|
#include <nvimage/Filter.h>
|
||||||
#include <nvimage/FloatImage.h>
|
#include <nvimage/FloatImage.h>
|
||||||
#include <nvimage/Image.h>
|
#include <nvimage/Image.h>
|
||||||
|
|
||||||
|
#include <nvmath/Color.h>
|
||||||
|
|
||||||
|
#include <nvcore/Ptr.h>
|
||||||
|
|
||||||
|
|
||||||
using namespace nv;
|
using namespace nv;
|
||||||
|
|
||||||
// Create normal map using the given kernels.
|
// Create normal map using the given kernels.
|
||||||
|
@ -39,7 +39,7 @@ namespace nv
|
|||||||
bool isSupported() const
|
bool isSupported() const
|
||||||
{
|
{
|
||||||
if (version != 1) {
|
if (version != 1) {
|
||||||
printf("*** bad version number %u\n", version);
|
nvDebug("*** bad version number %u\n", version);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (channel_count > 4) {
|
if (channel_count > 4) {
|
||||||
|
@ -12,11 +12,14 @@ http://www.efg2.com/Lab/Library/ImageProcessing/DHALF.TXT
|
|||||||
@@ This code needs to be reviewed, I'm not sure it's correct.
|
@@ This code needs to be reviewed, I'm not sure it's correct.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include <nvimage/Quantize.h>
|
||||||
|
#include <nvimage/Image.h>
|
||||||
|
#include <nvimage/PixelFormat.h>
|
||||||
|
|
||||||
#include <nvmath/Color.h>
|
#include <nvmath/Color.h>
|
||||||
|
|
||||||
#include <nvimage/Image.h>
|
#include <nvcore/Containers.h> // swap
|
||||||
#include <nvimage/Quantize.h>
|
|
||||||
#include <nvimage/PixelFormat.h>
|
|
||||||
|
|
||||||
using namespace nv;
|
using namespace nv;
|
||||||
|
|
||||||
|
@ -3,6 +3,9 @@
|
|||||||
#ifndef NV_IMAGE_QUANTIZE_H
|
#ifndef NV_IMAGE_QUANTIZE_H
|
||||||
#define NV_IMAGE_QUANTIZE_H
|
#define NV_IMAGE_QUANTIZE_H
|
||||||
|
|
||||||
|
#include <nvimage/nvimage.h>
|
||||||
|
|
||||||
|
|
||||||
namespace nv
|
namespace nv
|
||||||
{
|
{
|
||||||
class Image;
|
class Image;
|
||||||
|
@ -108,7 +108,7 @@ public:
|
|||||||
float area() const
|
float area() const
|
||||||
{
|
{
|
||||||
const Vector3 d = extents();
|
const Vector3 d = extents();
|
||||||
return 4.0f * (d.x()*d.y() + d.x()*d.z() + d.y()*d.z());
|
return 8.0f * (d.x()*d.y() + d.x()*d.z() + d.y()*d.z());
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Get the volume of the box.
|
/// Get the volume of the box.
|
||||||
@ -118,6 +118,14 @@ public:
|
|||||||
return 8.0f * (d.x() * d.y() * d.z());
|
return 8.0f * (d.x() * d.y() * d.z());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Return true if the box contains the given point.
|
||||||
|
bool contains(Vector3::Arg p) const
|
||||||
|
{
|
||||||
|
return
|
||||||
|
m_mins.x() < p.x() && m_mins.y() < p.y() && m_mins.z() < p.z() &&
|
||||||
|
m_maxs.x() > p.x() && m_maxs.y() > p.y() && m_maxs.z() > p.z();
|
||||||
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
Vector3 m_mins;
|
Vector3 m_mins;
|
||||||
@ -125,15 +133,6 @@ private:
|
|||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
/*
|
|
||||||
/// Point inside box test.
|
|
||||||
inline bool pointInsideBox(const Box & b, Vector3::Arg p) const
|
|
||||||
{
|
|
||||||
return (m_mins.x() < p.x() && m_mins.y() < p.y() && m_mins.z() < p.z() &&
|
|
||||||
m_maxs.x() > p.x() && m_maxs.y() > p.y() && m_maxs.z() > p.z());
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
|
|
||||||
|
|
||||||
} // nv namespace
|
} // nv namespace
|
||||||
|
|
||||||
|
@ -48,19 +48,37 @@
|
|||||||
#define IS_NEGATIVE_FLOAT(x) (IR(x)&SIGN_BITMASK)
|
#define IS_NEGATIVE_FLOAT(x) (IR(x)&SIGN_BITMASK)
|
||||||
*/
|
*/
|
||||||
|
|
||||||
inline float sqrt_assert(const float f)
|
inline double sqrt_assert(const double f)
|
||||||
|
{
|
||||||
|
nvDebugCheck(f >= 0.0f);
|
||||||
|
return sqrt(f);
|
||||||
|
}
|
||||||
|
|
||||||
|
inline float sqrtf_assert(const float f)
|
||||||
{
|
{
|
||||||
nvDebugCheck(f >= 0.0f);
|
nvDebugCheck(f >= 0.0f);
|
||||||
return sqrtf(f);
|
return sqrtf(f);
|
||||||
}
|
}
|
||||||
|
|
||||||
inline float acos_assert(const float f)
|
inline double acos_assert(const double f)
|
||||||
|
{
|
||||||
|
nvDebugCheck(f >= -1.0f && f <= 1.0f);
|
||||||
|
return acos(f);
|
||||||
|
}
|
||||||
|
|
||||||
|
inline float acosf_assert(const float f)
|
||||||
{
|
{
|
||||||
nvDebugCheck(f >= -1.0f && f <= 1.0f);
|
nvDebugCheck(f >= -1.0f && f <= 1.0f);
|
||||||
return acosf(f);
|
return acosf(f);
|
||||||
}
|
}
|
||||||
|
|
||||||
inline float asin_assert(const float f)
|
inline double asin_assert(const double f)
|
||||||
|
{
|
||||||
|
nvDebugCheck(f >= -1.0f && f <= 1.0f);
|
||||||
|
return asin(f);
|
||||||
|
}
|
||||||
|
|
||||||
|
inline float asinf_assert(const float f)
|
||||||
{
|
{
|
||||||
nvDebugCheck(f >= -1.0f && f <= 1.0f);
|
nvDebugCheck(f >= -1.0f && f <= 1.0f);
|
||||||
return asinf(f);
|
return asinf(f);
|
||||||
@ -68,11 +86,11 @@ inline float asin_assert(const float f)
|
|||||||
|
|
||||||
// Replace default functions with asserting ones.
|
// Replace default functions with asserting ones.
|
||||||
#define sqrt sqrt_assert
|
#define sqrt sqrt_assert
|
||||||
#define sqrtf sqrt_assert
|
#define sqrtf sqrtf_assert
|
||||||
#define acos acos_assert
|
#define acos acos_assert
|
||||||
#define acosf acos_assert
|
#define acosf acosf_assert
|
||||||
#define asin asin_assert
|
#define asin asin_assert
|
||||||
#define asinf asin_assert
|
#define asinf asinf_assert
|
||||||
|
|
||||||
#if NV_OS_WIN32
|
#if NV_OS_WIN32
|
||||||
#include <float.h>
|
#include <float.h>
|
||||||
@ -136,6 +154,11 @@ inline float lerp(float f0, float f1, float t)
|
|||||||
return f0 * s + f1 * t;
|
return f0 * s + f1 * t;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
inline float square(float f)
|
||||||
|
{
|
||||||
|
return f * f;
|
||||||
|
}
|
||||||
|
|
||||||
} // nv
|
} // nv
|
||||||
|
|
||||||
#endif // NV_MATH_H
|
#endif // NV_MATH_H
|
||||||
|
@ -44,7 +44,8 @@ INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR})
|
|||||||
ADD_DEFINITIONS(-DNVTT_EXPORTS)
|
ADD_DEFINITIONS(-DNVTT_EXPORTS)
|
||||||
|
|
||||||
IF(NVTT_SHARED)
|
IF(NVTT_SHARED)
|
||||||
ADD_LIBRARY(nvtt SHARED ${DXT_SRCS})
|
ADD_DEFINITIONS(-DNVTT_SHARED=1)
|
||||||
|
ADD_LIBRARY(nvtt SHARED ${NVTT_SRCS})
|
||||||
ELSE(NVTT_SHARED)
|
ELSE(NVTT_SHARED)
|
||||||
ADD_LIBRARY(nvtt ${NVTT_SRCS})
|
ADD_LIBRARY(nvtt ${NVTT_SRCS})
|
||||||
ENDIF(NVTT_SHARED)
|
ENDIF(NVTT_SHARED)
|
||||||
|
@ -211,6 +211,10 @@ Compressor::Compressor() : m(*new Compressor::Private())
|
|||||||
|
|
||||||
if (m.cudaEnabled)
|
if (m.cudaEnabled)
|
||||||
{
|
{
|
||||||
|
// Select fastest CUDA device.
|
||||||
|
int device = cuda::getFastestDevice();
|
||||||
|
cuda::setDevice(device);
|
||||||
|
|
||||||
m.cuda = new CudaCompressor();
|
m.cuda = new CudaCompressor();
|
||||||
|
|
||||||
if (!m.cuda->isValid())
|
if (!m.cuda->isValid())
|
||||||
@ -224,6 +228,7 @@ Compressor::Compressor() : m(*new Compressor::Private())
|
|||||||
Compressor::~Compressor()
|
Compressor::~Compressor()
|
||||||
{
|
{
|
||||||
delete &m;
|
delete &m;
|
||||||
|
cuda::exit();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -237,6 +242,10 @@ void Compressor::enableCudaAcceleration(bool enable)
|
|||||||
|
|
||||||
if (m.cudaEnabled && m.cuda == NULL)
|
if (m.cudaEnabled && m.cuda == NULL)
|
||||||
{
|
{
|
||||||
|
// Select fastest CUDA device.
|
||||||
|
int device = cuda::getFastestDevice();
|
||||||
|
cuda::setDevice(device);
|
||||||
|
|
||||||
m.cuda = new CudaCompressor();
|
m.cuda = new CudaCompressor();
|
||||||
|
|
||||||
if (!m.cuda->isValid())
|
if (!m.cuda->isValid())
|
||||||
@ -689,6 +698,7 @@ bool Compressor::Private::compressMipmap(const Mipmap & mipmap, const InputOptio
|
|||||||
SlowCompressor slow;
|
SlowCompressor slow;
|
||||||
slow.setImage(image, inputOptions.alphaMode);
|
slow.setImage(image, inputOptions.alphaMode);
|
||||||
|
|
||||||
|
const bool useCuda = cudaEnabled && image->width() * image->height() >= 512;
|
||||||
|
|
||||||
if (compressionOptions.format == Format_RGBA || compressionOptions.format == Format_RGB)
|
if (compressionOptions.format == Format_RGBA || compressionOptions.format == Format_RGB)
|
||||||
{
|
{
|
||||||
@ -717,7 +727,7 @@ bool Compressor::Private::compressMipmap(const Mipmap & mipmap, const InputOptio
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if (cudaEnabled)
|
if (useCuda)
|
||||||
{
|
{
|
||||||
nvDebugCheck(cudaSupported);
|
nvDebugCheck(cudaSupported);
|
||||||
cuda->setImage(image, inputOptions.alphaMode);
|
cuda->setImage(image, inputOptions.alphaMode);
|
||||||
@ -737,7 +747,7 @@ bool Compressor::Private::compressMipmap(const Mipmap & mipmap, const InputOptio
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if (cudaEnabled)
|
if (useCuda)
|
||||||
{
|
{
|
||||||
nvDebugCheck(cudaSupported);
|
nvDebugCheck(cudaSupported);
|
||||||
/*cuda*/slow.compressDXT1a(compressionOptions, outputOptions);
|
/*cuda*/slow.compressDXT1a(compressionOptions, outputOptions);
|
||||||
@ -756,7 +766,7 @@ bool Compressor::Private::compressMipmap(const Mipmap & mipmap, const InputOptio
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if (cudaEnabled)
|
if (useCuda)
|
||||||
{
|
{
|
||||||
nvDebugCheck(cudaSupported);
|
nvDebugCheck(cudaSupported);
|
||||||
cuda->setImage(image, inputOptions.alphaMode);
|
cuda->setImage(image, inputOptions.alphaMode);
|
||||||
@ -776,7 +786,7 @@ bool Compressor::Private::compressMipmap(const Mipmap & mipmap, const InputOptio
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if (cudaEnabled)
|
if (useCuda)
|
||||||
{
|
{
|
||||||
nvDebugCheck(cudaSupported);
|
nvDebugCheck(cudaSupported);
|
||||||
cuda->setImage(image, inputOptions.alphaMode);
|
cuda->setImage(image, inputOptions.alphaMode);
|
||||||
|
File diff suppressed because it is too large
Load Diff
@ -191,6 +191,9 @@ __device__ void loadColorBlock(const uint * image, float3 colors[16], float3 sum
|
|||||||
|
|
||||||
*sameColor = (axis == make_float3(0, 0, 0));
|
*sameColor = (axis == make_float3(0, 0, 0));
|
||||||
|
|
||||||
|
// Single color compressor needs unweighted colors.
|
||||||
|
if (*sameColor) colors[idx] = rawColors[idx];
|
||||||
|
|
||||||
dps[idx] = dot(rawColors[idx], axis);
|
dps[idx] = dot(rawColors[idx], axis);
|
||||||
|
|
||||||
#if __DEVICE_EMULATION__
|
#if __DEVICE_EMULATION__
|
||||||
|
@ -37,7 +37,7 @@
|
|||||||
|
|
||||||
|
|
||||||
#if defined HAVE_CUDA
|
#if defined HAVE_CUDA
|
||||||
#include <cuda_runtime.h>
|
#include <cuda_runtime_api.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include <time.h>
|
#include <time.h>
|
||||||
|
@ -148,7 +148,7 @@ inline __device__ bool singleColor(const float3 * colors)
|
|||||||
bool sameColor = false;
|
bool sameColor = false;
|
||||||
for (int i = 0; i < 16; i++)
|
for (int i = 0; i < 16; i++)
|
||||||
{
|
{
|
||||||
sameColor &= (colors[idx] == colors[0]);
|
sameColor &= (colors[i] == colors[0]);
|
||||||
}
|
}
|
||||||
return sameColor;
|
return sameColor;
|
||||||
#else
|
#else
|
||||||
|
@ -22,15 +22,18 @@
|
|||||||
// OTHER DEALINGS IN THE SOFTWARE.
|
// OTHER DEALINGS IN THE SOFTWARE.
|
||||||
|
|
||||||
#include <nvcore/Debug.h>
|
#include <nvcore/Debug.h>
|
||||||
|
#include <nvcore/Library.h>
|
||||||
#include "CudaUtils.h"
|
#include "CudaUtils.h"
|
||||||
|
|
||||||
#if defined HAVE_CUDA
|
#if defined HAVE_CUDA
|
||||||
#include <cuda_runtime.h>
|
#include <cuda.h>
|
||||||
|
#include <cuda_runtime_api.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
using namespace nv;
|
using namespace nv;
|
||||||
using namespace cuda;
|
using namespace cuda;
|
||||||
|
|
||||||
|
/* @@ Move this to win32 utils or somewhere else.
|
||||||
#if NV_OS_WIN32
|
#if NV_OS_WIN32
|
||||||
|
|
||||||
#define WINDOWS_LEAN_AND_MEAN
|
#define WINDOWS_LEAN_AND_MEAN
|
||||||
@ -52,31 +55,93 @@ static bool isWow32()
|
|||||||
{
|
{
|
||||||
LPFN_ISWOW64PROCESS fnIsWow64Process = (LPFN_ISWOW64PROCESS)GetProcAddress(GetModuleHandle("kernel32"), "IsWow64Process");
|
LPFN_ISWOW64PROCESS fnIsWow64Process = (LPFN_ISWOW64PROCESS)GetProcAddress(GetModuleHandle("kernel32"), "IsWow64Process");
|
||||||
|
|
||||||
BOOL bIsWow64 = FALSE;
|
BOOL bIsWow64 = FALSE;
|
||||||
|
|
||||||
if (NULL != fnIsWow64Process)
|
if (NULL != fnIsWow64Process)
|
||||||
{
|
{
|
||||||
if (!fnIsWow64Process(GetCurrentProcess(), &bIsWow64))
|
if (!fnIsWow64Process(GetCurrentProcess(), &bIsWow64))
|
||||||
{
|
{
|
||||||
// Assume 32 bits.
|
// Assume 32 bits.
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return !bIsWow64;
|
return !bIsWow64;
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
static bool isCudaDriverAvailable(int version)
|
||||||
|
{
|
||||||
|
#if defined HAVE_CUDA
|
||||||
|
#if NV_OS_WIN32
|
||||||
|
Library nvcuda("nvcuda.dll");
|
||||||
|
#else
|
||||||
|
Library nvcuda(NV_LIBRARY_NAME(cuda));
|
||||||
|
#endif
|
||||||
|
|
||||||
|
if (!nvcuda.isValid())
|
||||||
|
{
|
||||||
|
nvDebug("*** CUDA driver not found.\n");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (version >= 2000)
|
||||||
|
{
|
||||||
|
void * address = nvcuda.bindSymbol("cuStreamCreate");
|
||||||
|
if (address == NULL) {
|
||||||
|
nvDebug("*** CUDA driver version < 2.0.\n");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (version >= 2010)
|
||||||
|
{
|
||||||
|
void * address = nvcuda.bindSymbol("cuModuleLoadDataEx");
|
||||||
|
if (address == NULL) {
|
||||||
|
nvDebug("*** CUDA driver version < 2.1.\n");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (version >= 2020)
|
||||||
|
{
|
||||||
|
typedef CUresult (CUDAAPI * PFCU_DRIVERGETVERSION)(int * version);
|
||||||
|
|
||||||
|
PFCU_DRIVERGETVERSION driverGetVersion = (PFCU_DRIVERGETVERSION)nvcuda.bindSymbol("cuDriverGetVersion");
|
||||||
|
if (driverGetVersion == NULL) {
|
||||||
|
nvDebug("*** CUDA driver version < 2.2.\n");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
int driverVersion;
|
||||||
|
CUresult err = driverGetVersion(&driverVersion);
|
||||||
|
if (err != CUDA_SUCCESS) {
|
||||||
|
nvDebug("*** Error querying driver version: '%s'.\n", cudaGetErrorString((cudaError_t)err));
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return driverVersion >= version;
|
||||||
|
}
|
||||||
|
#endif // HAVE_CUDA
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/// Determine if CUDA is available.
|
/// Determine if CUDA is available.
|
||||||
bool nv::cuda::isHardwarePresent()
|
bool nv::cuda::isHardwarePresent()
|
||||||
{
|
{
|
||||||
#if defined HAVE_CUDA
|
#if defined HAVE_CUDA
|
||||||
#if NV_OS_WIN32
|
// Make sure that CUDA driver matches CUDA runtime.
|
||||||
//if (isWindowsVista()) return false;
|
if (!isCudaDriverAvailable(CUDART_VERSION))
|
||||||
//if (isWindowsVista() || !isWow32()) return false;
|
{
|
||||||
#endif
|
nvDebug("CUDA driver not available for CUDA runtime %d\n", CUDART_VERSION);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
int count = deviceCount();
|
int count = deviceCount();
|
||||||
if (count == 1)
|
if (count == 1)
|
||||||
{
|
{
|
||||||
@ -89,10 +154,10 @@ bool nv::cuda::isHardwarePresent()
|
|||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// @@ Make sure that warp size == 32
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// @@ Make sure that warp size == 32
|
||||||
|
|
||||||
return count > 0;
|
return count > 0;
|
||||||
#else
|
#else
|
||||||
return false;
|
return false;
|
||||||
@ -115,14 +180,60 @@ int nv::cuda::deviceCount()
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int nv::cuda::getFastestDevice()
|
||||||
|
{
|
||||||
|
int max_gflops_device = 0;
|
||||||
|
#if defined HAVE_CUDA
|
||||||
|
int max_gflops = 0;
|
||||||
|
|
||||||
|
const int device_count = deviceCount();
|
||||||
|
int current_device = 0;
|
||||||
|
while (current_device < device_count)
|
||||||
|
{
|
||||||
|
cudaDeviceProp device_properties;
|
||||||
|
cudaGetDeviceProperties(&device_properties, current_device);
|
||||||
|
int gflops = device_properties.multiProcessorCount * device_properties.clockRate;
|
||||||
|
|
||||||
|
if (device_properties.major != -1 && device_properties.minor != -1)
|
||||||
|
{
|
||||||
|
if( gflops > max_gflops )
|
||||||
|
{
|
||||||
|
max_gflops = gflops;
|
||||||
|
max_gflops_device = current_device;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
current_device++;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
return max_gflops_device;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/// Activate the given devices.
|
/// Activate the given devices.
|
||||||
bool nv::cuda::setDevice(int i)
|
bool nv::cuda::setDevice(int i)
|
||||||
{
|
{
|
||||||
nvCheck(i < deviceCount());
|
nvCheck(i < deviceCount());
|
||||||
#if defined HAVE_CUDA
|
#if defined HAVE_CUDA
|
||||||
cudaError_t result = cudaSetDevice(i);
|
cudaError_t result = cudaSetDevice(i);
|
||||||
|
|
||||||
|
if (result != cudaSuccess) {
|
||||||
|
nvDebug("*** CUDA Error: %s\n", cudaGetErrorString(result));
|
||||||
|
}
|
||||||
|
|
||||||
return result == cudaSuccess;
|
return result == cudaSuccess;
|
||||||
#else
|
#else
|
||||||
return false;
|
return false;
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void nv::cuda::exit()
|
||||||
|
{
|
||||||
|
#if defined HAVE_CUDA
|
||||||
|
cudaError_t result = cudaThreadExit();
|
||||||
|
|
||||||
|
if (result != cudaSuccess) {
|
||||||
|
nvDebug("*** CUDA Error: %s\n", cudaGetErrorString(result));
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
@ -31,7 +31,9 @@ namespace nv
|
|||||||
{
|
{
|
||||||
bool isHardwarePresent();
|
bool isHardwarePresent();
|
||||||
int deviceCount();
|
int deviceCount();
|
||||||
|
int getFastestDevice();
|
||||||
bool setDevice(int i);
|
bool setDevice(int i);
|
||||||
|
void exit();
|
||||||
};
|
};
|
||||||
|
|
||||||
} // nv namespace
|
} // nv namespace
|
||||||
|
@ -1,13 +1,8 @@
|
|||||||
PROJECT(squish)
|
PROJECT(squish)
|
||||||
ENABLE_TESTING()
|
|
||||||
|
|
||||||
INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR})
|
INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR})
|
||||||
|
|
||||||
SET(SQUISH_SRCS
|
SET(SQUISH_SRCS
|
||||||
# alpha.cpp
|
|
||||||
# alpha.h
|
|
||||||
# clusterfit.cpp
|
|
||||||
# clusterfit.h
|
|
||||||
fastclusterfit.cpp
|
fastclusterfit.cpp
|
||||||
fastclusterfit.h
|
fastclusterfit.h
|
||||||
weightedclusterfit.cpp
|
weightedclusterfit.cpp
|
||||||
@ -21,32 +16,13 @@ SET(SQUISH_SRCS
|
|||||||
config.h
|
config.h
|
||||||
maths.cpp
|
maths.cpp
|
||||||
maths.h
|
maths.h
|
||||||
# rangefit.cpp
|
|
||||||
# rangefit.h
|
|
||||||
# singlecolourfit.cpp
|
|
||||||
# singlecolourfit.h
|
|
||||||
# singlecolourlookup.inl
|
|
||||||
# squish.cpp
|
|
||||||
# squish.h
|
|
||||||
simd.h
|
simd.h
|
||||||
simd_sse.h
|
simd_sse.h
|
||||||
simd_ve.h)
|
simd_ve.h)
|
||||||
|
|
||||||
ADD_LIBRARY(squish STATIC ${SQUISH_SRCS})
|
ADD_LIBRARY(squish STATIC ${SQUISH_SRCS})
|
||||||
|
|
||||||
# libpng
|
IF(CMAKE_COMPILER_IS_GNUCXX)
|
||||||
#FIND_PACKAGE(PNG)
|
SET_TARGET_PROPERTIES(squish PROPERTIES COMPILE_FLAGS -fPIC)
|
||||||
|
ENDIF(CMAKE_COMPILER_IS_GNUCXX)
|
||||||
#IF(PNG_FOUND)
|
|
||||||
# INCLUDE_DIRECTORIES(${PNG_INCLUDE_DIR})
|
|
||||||
# ADD_EXECUTABLE(squishpng extra/squishpng.cpp)
|
|
||||||
# TARGET_LINK_LIBRARIES(squishpng squish ${PNG_LIBRARY})
|
|
||||||
#ENDIF(PNG_FOUND)
|
|
||||||
|
|
||||||
##ADD_EXECUTABLE(squishgen extra/squishgen.cpp)
|
|
||||||
|
|
||||||
#ADD_EXECUTABLE(squishtest extra/squishtest.cpp)
|
|
||||||
#TARGET_LINK_LIBRARIES(squishtest squish)
|
|
||||||
|
|
||||||
#ADD_TEST(SQUISHTEST squishtest)
|
|
||||||
|
|
||||||
|
@ -396,21 +396,6 @@ int main(int argc, char *argv[])
|
|||||||
compressionOptions.setExternalCompressor(externalCompressor);
|
compressionOptions.setExternalCompressor(externalCompressor);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (format == nvtt::Format_RGB)
|
|
||||||
{
|
|
||||||
compressionOptions.setQuantization(true, false, false);
|
|
||||||
//compressionOptions.setPixelFormat(16, 0xF000, 0x0F00, 0x00F0, 0x000F);
|
|
||||||
compressionOptions.setPixelFormat(16,
|
|
||||||
0x0F00,
|
|
||||||
0x00F0,
|
|
||||||
0x000F,
|
|
||||||
0xF000);
|
|
||||||
// 0x003F0000,
|
|
||||||
// 0x00003F00,
|
|
||||||
// 0x0000003F,
|
|
||||||
// 0x3F000000);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
MyErrorHandler errorHandler;
|
MyErrorHandler errorHandler;
|
||||||
MyOutputHandler outputHandler(output);
|
MyOutputHandler outputHandler(output);
|
||||||
@ -423,6 +408,16 @@ int main(int argc, char *argv[])
|
|||||||
nvtt::Compressor compressor;
|
nvtt::Compressor compressor;
|
||||||
compressor.enableCudaAcceleration(!nocuda);
|
compressor.enableCudaAcceleration(!nocuda);
|
||||||
|
|
||||||
|
printf("CUDA acceleration ");
|
||||||
|
if (compressor.isCudaAccelerationEnabled())
|
||||||
|
{
|
||||||
|
printf("ENABLED\n\n");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
printf("DISABLED\n\n");
|
||||||
|
}
|
||||||
|
|
||||||
outputHandler.setTotal(compressor.estimateSize(inputOptions, compressionOptions));
|
outputHandler.setTotal(compressor.estimateSize(inputOptions, compressionOptions));
|
||||||
outputHandler.setDisplayProgress(!silent);
|
outputHandler.setDisplayProgress(!silent);
|
||||||
|
|
||||||
|
@ -84,7 +84,7 @@ struct Error
|
|||||||
{
|
{
|
||||||
mabse /= samples;
|
mabse /= samples;
|
||||||
mse /= samples;
|
mse /= samples;
|
||||||
rmse = sqrt(mse);
|
rmse = sqrtf(mse);
|
||||||
psnr = (rmse == 0) ? 999.0f : 20.0f * log10(255.0f / rmse);
|
psnr = (rmse == 0) ? 999.0f : 20.0f * log10(255.0f / rmse);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -134,7 +134,7 @@ struct NormalError
|
|||||||
{
|
{
|
||||||
ade /= samples;
|
ade /= samples;
|
||||||
mse /= samples * 3;
|
mse /= samples * 3;
|
||||||
rmse = sqrt(mse);
|
rmse = sqrtf(mse);
|
||||||
psnr = (rmse == 0) ? 999.0f : 20.0f * log10(255.0f / rmse);
|
psnr = (rmse == 0) ? 999.0f : 20.0f * log10(255.0f / rmse);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -113,7 +113,7 @@ int main(int argc, char *argv[])
|
|||||||
((nv::KaiserFilter *)filter.ptr())->setParameters(4.0f, 1.0f);
|
((nv::KaiserFilter *)filter.ptr())->setParameters(4.0f, 1.0f);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (strcmp("-f", argv[i]) == 0)
|
else if (strcmp("-w", argv[i]) == 0)
|
||||||
{
|
{
|
||||||
if (i+1 == argc) break;
|
if (i+1 == argc) break;
|
||||||
i++;
|
i++;
|
||||||
|
Reference in New Issue
Block a user