264 Commits
2.0.4 ... 2.0.8

Author SHA1 Message Date
2587e2cf79 Update version number in resource file. Fixes issue 124. 2010-05-15 09:12:05 +00:00
eb01ca604f Tag 2.0.8 for release. 2010-05-14 18:01:41 +00:00
f6a39d6eab Remove duplicate code. 2010-05-14 04:58:08 +00:00
4fa93f8676 Update vc9 project. 2010-05-11 18:20:06 +00:00
639f11d0b9 Use the same defaults as nvtt 2.0 2010-05-11 17:18:08 +00:00
6e32d1e010 Update latest stb_dxt. 2010-05-09 08:21:34 +00:00
85db14f213 Add vertical flip. 2010-05-05 00:24:31 +00:00
ac5f849e91 Better estimation of principle component. Fixes issue 120. 2010-04-19 18:41:42 +00:00
4783d5621e Add missing files to cmake build as reported by amorilia. 2010-03-21 18:38:26 +00:00
85b9c2b0c5 Fix FindOpenEXR cmake script. Fixes issue 97. 2010-03-18 00:21:13 +00:00
447634d263 Fix cmake build in msvc. Fixes issue 111. 2010-03-18 00:13:31 +00:00
f436a71479 Add support for RGBE. 2010-03-17 07:55:03 +00:00
e848645e88 Add a few utils. Start converting tabs to spaces. 2010-03-17 07:54:07 +00:00
78b55e1e37 Finish pixel format converter. 2010-03-17 02:25:06 +00:00
3b0e0c3402 Fix errors after merge. Update cmake files. 2010-03-16 22:46:09 +00:00
a19e25228f reorg. 2010-03-16 22:37:25 +00:00
d8ed531e4c minor optimization. 2010-03-16 22:36:14 +00:00
73851ab86f misc 2010-03-16 22:35:38 +00:00
0cabfb6cfa misc. 2010-03-16 22:35:20 +00:00
1fafffd8af Detect OpenMP properly. 2010-03-16 22:31:27 +00:00
96f22f8cd4 Fix isColorNoAlpha, but leave it commented out. 2010-03-10 08:49:40 +00:00
558f7970b1 Fix issue 112. 2010-03-02 01:29:48 +00:00
d2fbcc5259 Add external libs. 2009-11-05 09:43:54 +00:00
0e5a1877a8 Some progress on the CUDA compressors. 2009-11-05 09:27:03 +00:00
8e436b1d30 Add post build commands to 64 bit targets. 2009-11-05 00:31:16 +00:00
2f0fe5149f Patch posh to support freebsd. 2009-11-03 23:58:10 +00:00
f744e700ae Add doc folder. 2009-11-03 23:57:36 +00:00
48f5dd4603 Update cmake scripts. 2009-11-03 23:56:25 +00:00
78bb864c14 cmake build system update. 2009-11-03 23:55:38 +00:00
7bc1eb6a29 Add ignore lists. 2009-11-03 23:53:44 +00:00
f63abb3ef6 Add properties. 2009-11-03 23:51:41 +00:00
e8500dead4 Add ignore list. 2009-11-03 23:50:14 +00:00
2e1d1e70ae Add ignore properties. 2009-11-03 23:44:05 +00:00
bc3299b78b Add ignore properties. 2009-11-03 23:43:35 +00:00
d01bdaf370 Add ignore properties. 2009-11-03 23:42:52 +00:00
d90b3d927b Update ignore file. 2009-11-03 23:40:10 +00:00
3e5c47d9fb Add ignore properties. 2009-11-03 23:39:03 +00:00
6a667fff50 Do not use external dependencies. 2009-11-03 23:28:18 +00:00
dfe081d32a Update messages. 2009-11-03 23:27:24 +00:00
acc02abaf1 Fix messages. 2009-11-03 23:17:11 +00:00
8871fefe89 Update project uuid. 2009-11-03 23:08:11 +00:00
2543f4c9ed rename stress->testsuite 2009-11-03 18:48:25 +00:00
ac46c40b3e Rename stress->testsuite 2009-11-03 18:48:03 +00:00
bcf0df2b49 use default pixel format, add comment to indicate where to change default 2009-10-30 01:05:31 +00:00
8c7f54056c Add more todo items.
Delete images more efficiently?
2009-10-21 19:20:30 +00:00
34cd266d8c Add todo item to perform color transforms before compression. 2009-10-21 19:19:09 +00:00
9a9366cf4c Who knows what msvc decided to change. 2009-10-21 18:29:46 +00:00
8820c43175 Large refactoring of compressor codes:
- Define compressor interface.
- Implement compressor interface for different compressors.
- Add parallel compressor using OpenMP. Experimental.
- Add generic GPU compressor, so far only DXT1 enabled.
2009-10-21 07:48:27 +00:00
18a3abf794 Enable alpha dithering when using DXT3.
Update timing message.
2009-10-21 07:43:24 +00:00
384f74ba39 Use minimal set by default. 2009-10-21 07:42:33 +00:00
7d75840398 Add todo messages.
Use DXT3 nvidia decoder if requested.
2009-10-21 07:42:08 +00:00
8ea52efbf4 Add DXT3 nvidia decoder. 2009-10-21 07:40:49 +00:00
d86a89742e Update info message. 2009-10-21 07:40:23 +00:00
fd11f5e7ef Implement generic swizzle, remove specialized ones. 2009-10-21 07:39:59 +00:00
dcfdabaee3 Fix timer. 2009-10-21 07:39:08 +00:00
2d97ee9c03 Update project files. Many minor changes. Enable OpenMP. 2009-10-21 07:38:11 +00:00
14f49b6003 Define new macro to point to extern dir. 2009-10-21 07:37:21 +00:00
ea7dabc6b1 Add comment. 2009-10-19 05:42:27 +00:00
0878c0e967 Add expand and pack normal methods.
Set normal map flag.
2009-10-18 20:04:39 +00:00
a088ae5789 Implement normal map generation for floating point images. 2009-10-18 20:03:21 +00:00
a52d3b7cdc Tweak implementation of scaleBias. 2009-10-18 20:02:43 +00:00
307c418acc Update FindCUDA script to latest. 2009-10-18 08:11:51 +00:00
d0218cb18b Merge changes from 2.0 2009-10-18 08:10:28 +00:00
c1f9c4df42 Create default output handle on setFileName to avoid modifying const argument.
Fix ref counting errors in TexImage.
Format TODO messages.
2009-10-18 08:09:20 +00:00
78d65e8368 When compiling with gcc, define NV_FILE_LINE using gcc convention. 2009-10-18 08:04:25 +00:00
18474cdb33 Some more progress towards 2.1:
- Add raw input methods in context.
- Implement some of the TexImage input methods in context.
- Add output header context method for TexImage.
2009-10-12 07:56:02 +00:00
b7fbd1fc9b Fix error in Snow Leopard. 2009-10-12 00:44:03 +00:00
9de3298d6b Fix cmake build. 2009-10-11 23:51:22 +00:00
568f34d838 Fix color weighted compression for single color blocks. Fixes issue 96. 2009-09-21 18:46:48 +00:00
e38e584db2 Rename texture to teximage. 2009-09-14 22:43:53 +00:00
8655259379 Fix comment. 2009-08-26 01:27:50 +00:00
7d65633f63 Add files to repro bugs/request. 2009-07-28 08:07:48 +00:00
cb62c3c461 Add support for R16 in DDS headers.
Cleanup DDS header output code.
Temporary testing code added to nvcompress.
2009-07-28 08:05:23 +00:00
573cc1b371 Add support for UINT16 images when using freetype. 2009-07-28 08:03:36 +00:00
9c6f6e143e Use tabs not spaces. 2009-07-28 08:03:08 +00:00
126816ef72 Experimental quality improvements and speed optimizations. 2009-07-06 09:08:09 +00:00
2ca6e4a1bd Add support function for stb compressor. 2009-07-06 09:06:40 +00:00
b839b873e1 Remove commented out code. 2009-07-06 09:06:17 +00:00
ab473f4ec5 Add DXT5 tests.
Use timer class.
2009-07-06 09:05:54 +00:00
f1ebbd4da6 Add more third-party compressors. 2009-07-06 09:04:29 +00:00
ac79935c88 Init default values. 2009-07-06 09:03:12 +00:00
2aca4673ab Some progress implementing new api. 2009-07-06 09:02:20 +00:00
43893d5d0f Add NV5x DXT5 decompressor. 2009-07-06 09:00:30 +00:00
009eaf2aa6 Fix msvc warnings. 2009-07-06 08:59:48 +00:00
fd2492670e Add a QPF timer. 2009-07-06 08:57:36 +00:00
7d88f4fa32 Merge changes from 2.0 branch. 2009-07-06 08:56:55 +00:00
60022acaa7 Add dxt5 tests to testsuite. 2009-07-04 19:34:42 +00:00
a5faf51738 Add simd power solver. 2009-07-04 19:33:55 +00:00
8365df0adf Add example textures with alpha. 2009-07-04 19:32:09 +00:00
2d38f4fb2c Update cmake scripts to use new FindCUDA package. 2009-06-26 06:34:19 +00:00
3adf00b4b9 Use official FindCUDA cmake script. 2009-06-26 06:33:34 +00:00
63897f3fe6 Mark threads as required. 2009-06-13 14:27:53 +00:00
71f29a27f3 Fix error in zero padding. 2009-06-13 14:18:31 +00:00
720be412fa Return correct error codes. Fix issue 92. 2009-06-13 14:17:46 +00:00
8d361eee22 Use memory allocator correctly. 2009-06-13 14:17:10 +00:00
8d54d22cb2 Update vc9 project files. 2009-04-21 09:31:59 +00:00
782a127071 Add alpha flag to DXT1a files. 2009-04-16 20:06:08 +00:00
154e117e13 Update nvmath project file. 2009-04-16 08:43:16 +00:00
603d8ad1a2 Update vc9 project. 2009-04-16 08:38:39 +00:00
bed4d78f6b Remove static member that was not thread safe! 2009-04-12 03:13:13 +00:00
d7f8fba7a7 Add comment about thread safety. 2009-04-12 03:10:40 +00:00
e0a7e103c1 Add include to all configurations. 2009-04-11 16:10:31 +00:00
319ed6bac0 Required include added 2009-04-11 16:07:12 +00:00
9e959d0191 Update wrapper, disable error handler temporarily. 2009-04-03 21:39:44 +00:00
53265596a3 Update nvtt wrapper. 2009-04-03 21:37:50 +00:00
ae24cb163d Remove msvc warnings. 2009-04-01 07:17:25 +00:00
fb75d6065d Update projects. 2009-04-01 07:13:47 +00:00
ae744f88e6 Add constructor that takes a stream. 2009-04-01 07:13:13 +00:00
5ac76b68c9 Add option to select decompression algorithm to test suite. 2009-03-24 17:35:40 +00:00
f2090df7a5 Add support for FreeBSD. Patch by AMDmi3. 2009-03-21 07:44:26 +00:00
0a8de141a6 Fix errors on win32. Define function pointers properly. 2009-03-21 07:43:15 +00:00
9aaee3ae16 Add proper todo message. 2009-03-21 07:42:36 +00:00
820eb374d5 Add single color table generation code. 2009-03-19 10:06:42 +00:00
974cacda5f Update single color compression tables. 2009-03-19 10:00:43 +00:00
953a63d7b5 Add farbrausch images to testsuite. 2009-03-19 10:00:26 +00:00
19477d60c0 Fix errors in the pixel format conversion code. 2009-03-19 08:57:49 +00:00
8a48250bcb Fix win32 errors and errors in the png saving code. 2009-03-19 08:57:28 +00:00
18d95584cc Add farbrausch textures. 2009-03-19 06:28:32 +00:00
9b3075030e Add data to repro bug reports. 2009-03-19 06:18:31 +00:00
dd98ce6eab Add one more exclude rule to pkg builder script. 2009-03-18 06:55:54 +00:00
35ff0e5aa6 Remove verbose error checking. 2009-03-18 05:51:15 +00:00
8529dcf755 Fix memory leaks.
Shutdown CUDA properly when nvtt context is destroyed.
Fixes issue 83.
2009-03-18 05:46:53 +00:00
56543e1a92 Merge changes from 2.0 2009-03-18 04:05:39 +00:00
72543c9307 Add todo message. 2009-03-17 08:16:00 +00:00
872c61e1d1 Add image saving code. 2009-03-17 08:14:28 +00:00
7f3cee4db9 Remove commented out code. 2009-03-17 06:33:31 +00:00
3f036a11a6 Avoid msvc8 warnings. 2009-03-16 21:08:09 +00:00
3df9aff396 rename gnuwin back to gnuwin32 2009-03-16 19:42:25 +00:00
be12367910 fix blend, add setborder and fill methods. 2009-03-16 09:05:32 +00:00
c59a2e0a4b Implement alpha premultiplication and color blending. 2009-03-16 08:54:43 +00:00
0abec17ab4 Implement toGreyScale.
Skip undefined images.
2009-03-16 08:47:20 +00:00
6b67f4a0d7 More progress with imperative api.
Rename Texture to TexImage.
Implement image initialization.
Add stubs for all methods.
2009-03-16 08:37:07 +00:00
6e2565d1a4 Install doc files in doc folder. 2009-03-16 06:05:51 +00:00
3e3c8a4d18 Generate debs on linux only. 2009-03-15 18:35:00 +00:00
8e836591ee Fix warning. 2009-03-15 18:34:46 +00:00
50b8b67185 Hide file format especific savers. Add generic image saver.
Misc fixes under OSX.
2009-03-15 10:18:54 +00:00
36850f6241 Include readme in the installer. 2009-03-14 08:02:47 +00:00
ed58bd90ff Update readme. 2009-03-14 08:02:33 +00:00
ab73c790e1 Testsuite cleanups and improvements.
Add ctest support.
Add FileSystem::changeDirectory method.
2009-03-14 07:27:25 +00:00
4a34c673a4 Add testsuite images. 2009-03-14 07:09:26 +00:00
0ce578668f Compile libraries as dynamic libs.
Excluse qtproject folder in source packages.
Add support for package generation using cpack.
2009-03-14 06:04:33 +00:00
53e6c4c911 Update project files with recently added files. 2009-03-14 03:31:12 +00:00
d99cf11e2e Update version checking code. 2009-03-14 03:30:20 +00:00
d9832ed22c Eliminate some warnings with MSVC. 2009-03-14 03:29:43 +00:00
a02649faa9 Fallback to CPU compressor only on smaller images. 2009-03-14 03:29:14 +00:00
a28ebb4ccf Some more progress in the imperative API. 2009-03-07 07:14:00 +00:00
0f5a5e5d24 Some more progress in the imperative API. 2009-03-05 05:34:28 +00:00
8f0b129a52 Add RefCounted base class back to the reposotory. 2009-03-05 05:33:53 +00:00
098bc2f905 Fix some endiannes errors. 2009-03-04 09:36:40 +00:00
5943e8f42f Fix errors on ibook G4. 2009-03-04 07:04:32 +00:00
ba72ebafcb Delete win64 dlls, not very useful without the corresponding lib files. 2009-03-02 09:50:47 +00:00
a89735994c Update vc9 project files. 2009-03-02 09:45:17 +00:00
e7fd290af6 Update changelog. 2009-03-02 09:28:11 +00:00
35b97e7a13 Add property file. 2009-03-02 09:27:51 +00:00
472c2d691f Update vc8 project files. 2009-03-02 09:27:07 +00:00
e48f56a15e Includer project headers first. 2009-03-02 09:21:48 +00:00
25e32c8ff2 Fix msvc warnings. 2009-03-02 09:21:30 +00:00
db63ba7fa4 Fix build in win64. 2009-03-02 09:21:07 +00:00
3df66be089 Do not use CUDA to compress small mipmaps. 2009-03-02 09:09:05 +00:00
3a52923697 Add alpha command line option. 2009-03-02 09:07:07 +00:00
9953883d26 Cleanup cmake files. 2009-03-02 07:32:00 +00:00
5ed9090012 Move poshlib to extern. 2009-03-02 07:30:38 +00:00
93e2fb46a9 Update changelog and buildpkg script. 2009-03-02 07:01:06 +00:00
03c9ec0f62 More cleanup. Remove files that are not strictly required. 2009-03-01 02:38:24 +00:00
88fc5ca18e Merge changes from private tree.
Eliminate files that are not needed for NVTT.
2009-03-01 00:18:47 +00:00
6fb29816a2 Gnome thumbnailer. Fixes issue 82. 2009-02-03 09:32:54 +00:00
c67edca820 Update changelog. 2009-02-03 09:30:54 +00:00
9d5242594b Add gnome thumbnailer by Frank Richter. Fixes issue 82. 2009-02-03 09:29:25 +00:00
69c74d7a5e Add support for comments. 2009-02-03 09:23:58 +00:00
b7ea7a255b Fix const-correctness. 2009-02-03 09:22:30 +00:00
17790a34df Add support for PNG in nvdecompress. Patch by Frank Richter. Fixes issue 80. 2009-02-03 09:08:39 +00:00
7741a99b90 Add support for saving PNG files. Patch by Frank Richter. Fixes issue 79. 2009-02-03 09:06:21 +00:00
36dd7fb76b Merge changes from p4. 2009-02-03 08:22:35 +00:00
8fa870bf0c Fix typo. Fixes issue 82. 2009-02-03 08:02:20 +00:00
1afdf2da8a Fix alpha-weighted filtering. 2009-01-28 12:10:04 +00:00
242aa4254e Use alpha-aware resize when alpha is used for transparency and it's not premultiplied. 2009-01-28 10:58:57 +00:00
4f576d5539 Add support for alpha weighting to float image. 2009-01-28 10:55:23 +00:00
2411f3f5db Fix generation of blended sobel filter. Fixes issue 77. 2009-01-28 00:56:27 +00:00
1c6b65ad52 Do not use custom FindGLUT cmake script. 2009-01-27 23:39:33 +00:00
f92a2191f2 Print message when cuda acceleration enabled. 2009-01-20 10:43:56 +00:00
7f9b10329b Add squish.h to project. 2009-01-19 10:43:53 +00:00
49409e9d92 Cleanup color rounding and expansion. 2009-01-19 10:42:31 +00:00
f753cc9702 Implement FileSystem::exists correctly on win32. 2009-01-19 10:41:51 +00:00
07a4daed7b Add FileSystem.{h,cpp} to project. 2009-01-19 10:41:09 +00:00
2ad15489bb Try to optimize color rounding and expansion.
Detect CUDA 2.1 properly.
2009-01-19 09:54:43 +00:00
fa53ddcecd Add NV5x/G8x DXT decompression code.
Clean things up a bit, remove old code.
2009-01-13 08:25:04 +00:00
7a8b3aecc9 Fix name of libpng dll. 2009-01-10 04:40:46 +00:00
94357626f7 Merge fixes from 2.0 branch. 2009-01-10 01:31:02 +00:00
19342d8adf Use timer class instead of clock.
Check that file exists before opening.
2009-01-09 05:46:24 +00:00
2ed4fee447 Fix error sin string builder and path. 2009-01-09 05:45:36 +00:00
f03d702d84 Implement exists with access instead of stat. 2009-01-09 05:45:02 +00:00
10de10b9c2 Implement FileSystem::exists(). 2009-01-09 02:24:32 +00:00
508f9fbdc2 Start implementing experimental interface. 2009-01-05 10:17:06 +00:00
e965b0e4a9 Include correct headers. 2009-01-04 07:29:35 +00:00
1f4d313d0f Merge changes from internal branch. Whitespace changes only. 2008-12-29 11:34:39 +00:00
dc0b78ad14 Do not enable testing. 2008-12-29 11:33:48 +00:00
b8eb12afc1 Merge changes from internal branch.
- Better support for win64.
2008-12-29 11:33:20 +00:00
1975883bed Update after changes in nvcore. 2008-12-29 11:29:45 +00:00
9bda107603 Add pull push filter with bilinear filtering. 2008-12-29 11:28:29 +00:00
b4f17b968a Merge changes from internal branch.
- Add frustum class and bezier evaluation functions.
- Add component accessors to vector.
- Add matrix constructors.
- Fix errors in sparse solvers.
- Better robust orthogonalization.
- Fix montecarlo distribution.
2008-12-29 11:27:13 +00:00
e5ae0c0e20 Merge internal branch.
- Remove old/unused code.
- Remove format string constructors.
- Better win64 support (vsscanf, prefetch, etc).
- Fix radix sort to sort -0 correctly.
- Add misc utilities (constraints, timer, cpuinfo, introsort).
2008-12-29 11:20:06 +00:00
a03411e451 Check version properly. 2008-12-16 20:25:12 +00:00
931580edc5 Include cuda runtime properly. 2008-12-09 11:26:08 +00:00
fd2f5465f8 Do not use kahansum, that was stupid.
Include cuda runtime properly.
2008-12-09 11:25:46 +00:00
127052f404 Use KahanSum to compute RMSE.
Fix typos.
2008-12-07 23:15:06 +00:00
a30490ab9b Preserve cluster location for empty partitions. 2008-11-24 10:35:42 +00:00
1ec115c7ec Cleanup 4 means compressor. 2008-11-24 10:35:07 +00:00
a4f56b65b8 Add support for alpha modes in the CPU compressors. Fixes issue 30. 2008-11-24 10:34:16 +00:00
bb69acec6c Add FileSystem to build. 2008-11-23 22:25:47 +00:00
4bbf5e96f4 Add squish external compressor.
Rename our squish version to nvsquish.
2008-11-23 08:59:56 +00:00
4a85f8e48d Remove executable flag. 2008-11-22 22:12:05 +00:00
f34b7ce84f Merge optimizations from squish. 2008-11-22 22:10:51 +00:00
010905edd3 Fix tabs. 2008-11-22 22:10:11 +00:00
7bb2d55d35 Create output directory. 2008-11-22 22:08:31 +00:00
e3a7cc19dd Add file system helper. 2008-11-22 22:07:07 +00:00
379605d30a Use metric to measure distance to clusters. 2008-11-22 21:32:27 +00:00
c05c4e155b Merge optimizations from official squish release. 2008-11-22 11:36:06 +00:00
fd73484bfc Merge optimizations from official squish relese. 2008-11-22 11:35:13 +00:00
f29d7dd938 Try using 4 means clustering. 2008-11-22 11:34:29 +00:00
3a5dc4783a Add support for regressions. 2008-11-22 11:33:31 +00:00
d4a713451e Fix 4 means clustering. 2008-11-22 11:32:51 +00:00
a302475fa6 Add fitting implementation to project. 2008-11-22 11:30:46 +00:00
6e988ea4c8 Add stream to the vc8 project. 2008-11-22 11:28:18 +00:00
7731181900 Update changelog. 2008-11-22 08:37:56 +00:00
41f6e0ba73 Try 4-means. 2008-11-22 08:37:14 +00:00
11073171a1 Rename stress to testsuite. Install target. 2008-11-22 08:36:55 +00:00
0805832b44 Remove squish build and project files. 2008-11-22 08:36:17 +00:00
a4dcd414ca Fix errors. 2008-11-22 08:35:04 +00:00
4ff8a83f90 Add fitting code to build. 2008-11-22 08:30:55 +00:00
48da357385 Add PCA, and 4-means implementation. 2008-11-22 08:30:20 +00:00
e1916d43c8 Do not mix tabs and spaces. 2008-11-22 00:14:05 +00:00
321f320bfb Do not print stupid messages. 2008-11-22 00:13:14 +00:00
df32fedc7c Add command line options.
Reformat output for easier parsing.
2008-11-21 09:09:57 +00:00
a7396b70ba Fix segfault on linux. Merged from 2.0 branch. 2008-11-21 09:08:00 +00:00
d9ca49cc5e Fix bug in dxt decompression.
Output files as TGA.
2008-11-21 08:06:25 +00:00
56849b78ad Output compressed files. 2008-11-21 07:58:49 +00:00
a769831fb5 Add const keyword to const arguments. 2008-11-21 07:57:28 +00:00
7486201a7e Fix bug in testsuite. 2008-11-21 07:45:09 +00:00
1813624992 Modify stress test to compress a list of real images. 2008-11-21 07:38:12 +00:00
5fa27adfcd Add custom error code and message for the case when container format does not support a certain output format. 2008-11-19 08:10:54 +00:00
6d1891a7e9 Remove gcc-4.3 warning. 2008-11-14 02:19:39 +00:00
8fb1d70d0b Fix bug detected by gcc-4.3. 2008-11-14 02:19:07 +00:00
c26c52d59c Fix gcc-4.3 warnings. 2008-11-14 02:18:35 +00:00
c3329d4675 Fix gcc-4.3 warning. 2008-11-14 02:16:36 +00:00
1cefc366f8 Remove unused function. 2008-11-14 02:15:35 +00:00
7df0885c4f Fix CUDA detection code on linux. 2008-11-14 01:15:36 +00:00
1c5da0e341 Do not use cuda API when CUDA not found.
Fix end of lines.
2008-11-10 21:54:03 +00:00
36ba75b598 Select fastest device. 2008-10-30 04:50:41 +00:00
1628831878 Fix comment. 2008-10-27 08:00:46 +00:00
12e774ea74 Fix cmake file. 2008-10-26 05:56:32 +00:00
66b18f2dbd Fix build under VC7 2008-10-22 03:48:06 +00:00
9ea1934097 Update vc8 projects. 2008-10-17 18:40:16 +00:00
9771e72702 Update vc9 projects. 2008-10-17 18:38:55 +00:00
7776bd5c17 Win32 fixes. 2008-10-17 18:37:17 +00:00
6d8a75462a Build nvtt as a shared library. 2008-10-16 22:22:45 +00:00
cf18077eda Prevent missmatches between incompatible versions of the CUDA runtime and the CUDA driver. 2008-10-16 22:21:21 +00:00
aa37e7a868 Add library loading helpers. 2008-10-16 22:20:31 +00:00
d01a5c1661 Workaround bug in CUDA runtime. When using CUDA 2.0, it's required to use a driver that supports CUDA 2.0. 2008-10-16 08:39:58 +00:00
36ed6bebda Update changelog with branch 2.0 fixes. 2008-10-15 07:17:20 +00:00
5234060618 Integrate branch 2.0 to trunk. 2008-10-15 07:16:57 +00:00
f402f28643 Use unsigned ints for stream sizes and positions. 2008-10-15 07:15:50 +00:00
f047043eb2 Fix compiler errors under gcc-4.3 2008-10-15 07:15:00 +00:00
7eac4195c4 Fix compiler errors under gcc-4.3 2008-10-15 07:14:25 +00:00
0f5692d1ea Compile CUDA files as C++. 2008-10-11 06:43:57 +00:00
58 changed files with 2251 additions and 1673 deletions

View File

@ -1,4 +1,4 @@
CMAKE_MINIMUM_REQUIRED(VERSION 2.4.0)
CMAKE_MINIMUM_REQUIRED(VERSION 2.6.0)
PROJECT(NV)
ENABLE_TESTING()
@ -16,6 +16,13 @@ MESSAGE(STATUS "Setting optimal options")
MESSAGE(STATUS " Processor: ${NV_SYSTEM_PROCESSOR}")
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)
IF(WIN32)

View File

@ -1,3 +1,37 @@
NVIDIA Texture Tools version 2.0.8
* Fix float to fixed image conversion. Patch provided by Alex Pfaffe. Fixes issue 121.
* ColorBlock::isSingleColor compares only RGB channels. Fixes issue 115.
* Fix cmake build in msvc. Fixes issue 111.
* Better estimate principal component. Fixes issue 120.
NVIDIA Texture Tools version 2.0.7
* Output correct exit codes. Fixes issue 92.
* Fix thread-safety errors. Fixes issue 90.
* Add SIMD power method. Fixes issue 94.
* Interact better with applications that already use CUDA.
* Faster CPU compression.
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
* Fix error in RGB format output; reported by jonsoh. See issue 49.
* Added support RGB format dithering by jonsoh. Fixes issue 50 and 51.

View File

@ -1 +1 @@
2.0.4
2.0.8

View File

@ -57,7 +57,7 @@ MARK_AS_ADVANCED (CUDA_FOUND CUDA_COMPILER CUDA_RUNTIME_LIBRARY)
#SET(CUDA_OPTIONS "-ncfe")
SET(CUDA_OPTIONS "")
SET(CUDA_OPTIONS "--host-compilation=C")
IF (CUDA_EMULATION)
SET (CUDA_OPTIONS "${CUDA_OPTIONS} -deviceemu")

View File

@ -53,11 +53,7 @@ ENDIF(ZLIB_FOUND)
IF (OPENEXR_INCLUDE_PATH AND OPENEXR_IMATH_LIBRARY AND OPENEXR_ILMIMF_LIBRARY AND OPENEXR_IEX_LIBRARY AND OPENEXR_HALF_LIBRARY)
SET(OPENEXR_FOUND TRUE)
SET(OPENEXR_INCLUDE_PATHS ${OPENEXR_INCLUDE_PATH} CACHE STRING "The include paths needed to use OpenEXR")
SET(OPENEXR_LIBRARIES ${OPENEXR_IMATH_LIBRARY} ${OPENEXR_ILMIMF_LIBRARY} ${OPENEXR_IEX_LIBRARY} ${OPENEXR_HALF_LIBRARY} ${ZLIB_LIBRARY} CACHE STRING "The libraries needed to use OpenEXR")
IF(OPENEXR_ILMTHREAD_LIBRARY)
SET(OPENEXR_LIBRARIES ${OPENEXR_LIBRARIES} ${OPENEXR_ILMTHREAD_LIBRARY})
ENDIF(OPENEXR_ILMTHREAD_LIBRARY)
SET(OPENEXR_LIBRARIES ${OPENEXR_IMATH_LIBRARY} ${OPENEXR_ILMIMF_LIBRARY} ${OPENEXR_IEX_LIBRARY} ${OPENEXR_HALF_LIBRARY} ${OPENEXR_ILMTHREAD_LIBRARY} ${ZLIB_LIBRARY} CACHE STRING "The libraries needed to use OpenEXR")
ENDIF (OPENEXR_INCLUDE_PATH AND OPENEXR_IMATH_LIBRARY AND OPENEXR_ILMIMF_LIBRARY AND OPENEXR_IEX_LIBRARY AND OPENEXR_HALF_LIBRARY)
IF(OPENEXR_FOUND)

2
configure vendored
View File

@ -53,7 +53,7 @@ echo "-- Configuring nvidia-texture-tools "`cat VERSION`
mkdir -p ./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 ..
echo ""

View File

@ -281,6 +281,10 @@
RelativePath="..\..\..\src\nvcore\Debug.cpp"
>
</File>
<File
RelativePath="..\..\..\src\nvcore\Library.cpp"
>
</File>
<File
RelativePath="..\..\..\src\nvcore\Memory.cpp"
>
@ -315,6 +319,10 @@
RelativePath="..\..\..\src\nvcore\DefsVcWin32.h"
>
</File>
<File
RelativePath="..\..\..\src\nvcore\Library.h"
>
</File>
<File
RelativePath="..\..\..\src\nvcore\Memory.h"
>

View File

@ -53,8 +53,8 @@ END
//
VS_VERSION_INFO VERSIONINFO
FILEVERSION 2,0,4,0
PRODUCTVERSION 2,0,4,0
FILEVERSION 2,0,6,0
PRODUCTVERSION 2,0,6,0
FILEFLAGSMASK 0x17L
#ifdef _DEBUG
FILEFLAGS 0x1L
@ -71,12 +71,12 @@ BEGIN
BEGIN
VALUE "CompanyName", "NVIDIA Corporation"
VALUE "FileDescription", "NVIDIA Texture Tools Dynamic Link Library"
VALUE "FileVersion", "2, 0, 4, 0"
VALUE "FileVersion", "2, 0, 8, 0"
VALUE "InternalName", "nvtt"
VALUE "LegalCopyright", "Copyright (C) 2007"
VALUE "LegalCopyright", "Copyright (C) 2007-2010"
VALUE "OriginalFilename", "nvtt.dll"
VALUE "ProductName", "NVIDIA Texture Tools Dynamic Link Library"
VALUE "ProductVersion", "2, 0, 4, 0"
VALUE "ProductVersion", "2, 0, 8, 0"
END
END
BLOCK "VarFileInfo"

View File

@ -179,6 +179,8 @@
/>
<Tool
Name="VCPostBuildEventTool"
Description="Copying header files..."
CommandLine="xcopy /y /f /i &quot;$(SolutionDir)\..\..\src\nvtt\nvtt*.h&quot; &quot;$(SolutionDir)\$(ConfigurationName).$(PlatformName)\include\nvtt\&quot;"
/>
</Configuration>
<Configuration
@ -344,6 +346,8 @@
/>
<Tool
Name="VCPostBuildEventTool"
Description="Copying header files..."
CommandLine="xcopy /y /f /i &quot;$(SolutionDir)\..\..\src\nvtt\nvtt*.h&quot; &quot;$(SolutionDir)\$(ConfigurationName).$(PlatformName)\include\nvtt\&quot;"
/>
</Configuration>
<Configuration
@ -503,6 +507,8 @@
/>
<Tool
Name="VCPostBuildEventTool"
Description="Copying header files..."
CommandLine="xcopy /y /f /i &quot;$(SolutionDir)\..\..\src\nvtt\nvtt*.h&quot; &quot;$(SolutionDir)\$(ConfigurationName).$(PlatformName)\include\nvtt\&quot;"
/>
</Configuration>
<Configuration
@ -664,6 +670,8 @@
/>
<Tool
Name="VCPostBuildEventTool"
Description="Copying header files..."
CommandLine="xcopy /y /f /i &quot;$(SolutionDir)\..\..\src\nvtt\nvtt*.h&quot; &quot;$(SolutionDir)\$(ConfigurationName).$(PlatformName)\include\nvtt\&quot;"
/>
</Configuration>
</Configurations>

View File

@ -105,7 +105,8 @@ ENDIF(OPENEXR_FOUND)
FIND_PACKAGE(Qt4)
# Threads
FIND_PACKAGE(Threads)
FIND_PACKAGE(Threads REQUIRED)
MESSAGE(STATUS "Use thread library: ${CMAKE_THREAD_LIBS_INIT}")
# configuration file
INCLUDE(CheckIncludeFiles)

View File

@ -19,14 +19,21 @@ SET(CORE_SRCS
TextWriter.h
TextWriter.cpp
Radix.h
Radix.cpp)
Radix.cpp
Library.h
Library.cpp)
INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR})
# targets
ADD_DEFINITIONS(-DNVCORE_EXPORTS)
IF(UNIX)
SET(LIBS ${LIBS} ${CMAKE_DL_LIBS})
ENDIF(UNIX)
IF(NVCORE_SHARED)
ADD_DEFINITIONS(-DNVCORE_SHARED=1)
ADD_LIBRARY(nvcore SHARED ${CORE_SRCS})
ELSE(NVCORE_SHARED)
ADD_LIBRARY(nvcore ${CORE_SRCS})

View File

@ -824,13 +824,13 @@ namespace nv
}
/// Number of entries in the hash.
int size()
int size() const
{
return entry_count;
}
/// Number of entries in the hash.
int count()
int count() const
{
return size();
}

View File

@ -28,7 +28,7 @@
#endif
#if NV_OS_LINUX && defined(HAVE_EXECINFO_H)
# include <execinfo.h>
# include <execinfo.h> // backtrace
# if NV_CC_GNUC // defined(HAVE_CXXABI_H)
# include <cxxabi.h>
# endif
@ -38,7 +38,14 @@
# include <unistd.h> // getpid
# include <sys/types.h>
# include <sys/sysctl.h> // sysctl
# include <ucontext.h>
# include <sys/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
#include <stdexcept> // std::runtime_error
@ -128,6 +135,14 @@ namespace
#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) {
char ** string_array = backtrace_symbols(trace, size);
@ -166,24 +181,36 @@ namespace
static void * callerAddress(void * secret)
{
# if NV_OS_DARWIN && NV_CPU_PPC
ucontext_t * ucp = (ucontext_t *)secret;
return (void *) ucp->uc_mcontext->ss.srr0;
# elif NV_OS_DARWIN && NV_CPU_X86
ucontext_t * ucp = (ucontext_t *)secret;
return (void *) ucp->uc_mcontext->ss.eip;
# elif 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;
# if NV_OS_DARWIN
# if defined(_STRUCT_MCONTEXT)
# if NV_CPU_PPC
ucontext_t * ucp = (ucontext_t *)secret;
return (void *) ucp->uc_mcontext->__ss.__srr0;
# elif NV_CPU_X86
ucontext_t * ucp = (ucontext_t *)secret;
return (void *) ucp->uc_mcontext->__ss.__eip;
# endif
# else
# if NV_CPU_PPC
ucontext_t * ucp = (ucontext_t *)secret;
return (void *) ucp->uc_mcontext->ss.srr0;
# elif NV_CPU_X86
ucontext_t * ucp = (ucontext_t *)secret;
return (void *) ucp->uc_mcontext->ss.eip;
# endif
# endif
# 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
// 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 (nvHasStackTrace()) // in case of weak linking
{
void * trace[64];
int size = backtrace(trace, 64);
void * trace[64];
int size = backtrace(trace, 64);
if (pnt != NULL) {
// Overwrite sigaction with caller's address.
trace[1] = pnt;
if (pnt != NULL) {
// Overwrite sigaction with caller's address.
trace[1] = pnt;
}
nvPrintStackTrace(trace, size, 1);
}
nvPrintStackTrace(trace, size, 1);
# endif // defined(HAVE_EXECINFO_H)
exit(0);
@ -373,9 +401,12 @@ namespace
# endif
# if defined(HAVE_EXECINFO_H)
void * trace[64];
int size = backtrace(trace, 64);
nvPrintStackTrace(trace, size, 3);
if (nvHasStackTrace())
{
void * trace[64];
int size = backtrace(trace, 64);
nvPrintStackTrace(trace, size, 2);
}
# endif
// Exit cleanly.
@ -422,9 +453,12 @@ void NV_CDECL nvDebug(const char *msg, ...)
void debug::dumpInfo()
{
#if !NV_OS_WIN32 && defined(HAVE_SIGNAL_H) && defined(HAVE_EXECINFO_H)
void * trace[64];
int size = backtrace(trace, 64);
nvPrintStackTrace(trace, size, 1);
if (nvHasStackTrace())
{
void * trace[64];
int size = backtrace(trace, 64);
nvPrintStackTrace(trace, size, 1);
}
#endif
}

View File

@ -115,6 +115,7 @@ namespace nv
{
NVCORE_API void dumpInfo();
// These functions are not thread safe.
NVCORE_API void setMessageHandler( MessageHandler * messageHandler );
NVCORE_API void resetMessageHandler();

View File

@ -2,8 +2,7 @@
#error "Do not include this file directly."
#endif
#include <stdlib.h> // uint8_t, int8_t, ...
#include <stdint.h> // uint8_t, int8_t, ...
// Function linkage
#define DLL_IMPORT

View File

@ -19,7 +19,9 @@
// Set standard function names.
#define snprintf _snprintf
#define vsnprintf _vsnprintf
#if _MSC_VER < 1500
# define vsnprintf _vsnprintf
#endif
#define vsscanf _vsscanf
#define chdir _chdir
#define getcwd _getcwd
@ -70,8 +72,6 @@ typedef uint32 uint;
#pragma warning(disable : 4711) // function selected for automatic inlining
#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 : 4675) // resolved overload was found by argument-dependent lookup

41
src/nvcore/Library.cpp Normal file
View 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
View 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

View File

@ -24,7 +24,7 @@ __forceinline void nvPrefetch(const void * mem)
#else // NV_CC_MSVC
// do nothing in other case.
#define piPrefetch(ptr)
#define nvPrefetch(ptr)
#endif // NV_CC_MSVC

View File

@ -43,8 +43,11 @@ public:
/** Delete owned pointer and assign new one. */
void operator=( T * p ) {
delete m_ptr;
m_ptr = p;
if (p != m_ptr)
{
delete m_ptr;
m_ptr = p;
}
}
/** Member access. */
@ -249,14 +252,14 @@ public:
/** -> operator. */
BaseClass * operator -> () const
{
piCheck( m_ptr != NULL );
nvCheck( m_ptr != NULL );
return m_ptr;
}
/** * operator. */
BaseClass & operator*() const
{
piCheck( m_ptr != NULL );
nvCheck( m_ptr != NULL );
return *m_ptr;
}

View File

@ -47,25 +47,25 @@ public:
/** @name Stream implementation. */
//@{
virtual void seek( int pos )
virtual void seek( uint pos )
{
nvDebugCheck(m_fp != NULL);
nvDebugCheck(pos >= 0 && pos < size());
nvDebugCheck(pos < size());
fseek(m_fp, pos, SEEK_SET);
}
virtual int tell() const
virtual uint tell() const
{
nvDebugCheck(m_fp != NULL);
return ftell(m_fp);
}
virtual int size() const
virtual uint size() const
{
nvDebugCheck(m_fp != NULL);
int pos = ftell(m_fp);
uint pos = ftell(m_fp);
fseek(m_fp, 0, SEEK_END);
int end = ftell(m_fp);
uint end = ftell(m_fp);
fseek(m_fp, pos, SEEK_SET);
return end;
}
@ -117,11 +117,11 @@ public:
/** @name Stream implementation. */
//@{
/// Write data.
virtual void serialize( void * data, int len )
virtual uint serialize( void * data, uint len )
{
nvDebugCheck(data != NULL);
nvDebugCheck(m_fp != NULL);
fwrite(data, len, 1, m_fp);
return (uint)fwrite(data, 1, len, m_fp);
}
virtual bool isLoading() const
@ -156,11 +156,11 @@ public:
/** @name Stream implementation. */
//@{
/// Read data.
virtual void serialize( void * data, int len )
virtual uint serialize( void * data, uint len )
{
nvDebugCheck(data != NULL);
nvDebugCheck(m_fp != NULL);
fread(data, len, 1, m_fp);
return (uint)fread(data, 1, len, m_fp);
}
virtual bool isLoading() const
@ -184,33 +184,40 @@ class NVCORE_CLASS MemoryInputStream : public Stream
public:
/// Ctor.
MemoryInputStream( const uint8 * mem, int size ) :
MemoryInputStream( const uint8 * mem, uint size ) :
m_mem(mem), m_ptr(mem), m_size(size) { }
/** @name Stream implementation. */
//@{
/// Read data.
virtual void serialize( void * data, int len )
virtual uint serialize( void * data, uint len )
{
nvDebugCheck(data != NULL);
nvDebugCheck(!isError());
uint left = m_size - tell();
if (len > left) len = left;
memcpy( data, m_ptr, len );
m_ptr += len;
return len;
}
virtual void seek( int pos )
virtual void seek( uint pos )
{
nvDebugCheck(!isError());
m_ptr = m_mem + pos;
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;
}
@ -252,7 +259,7 @@ private:
const uint8 * m_mem;
const uint8 * m_ptr;
int m_size;
uint m_size;
};
@ -286,17 +293,19 @@ public:
/** @name Stream implementation. */
//@{
/// Read data.
virtual void serialize( void * data, int len )
virtual uint serialize( void * data, uint len )
{
nvDebugCheck(data != NULL);
m_s->serialize( data, len );
len = m_s->serialize( data, len );
if( m_s->isError() ) {
throw std::exception();
}
return len;
}
virtual void seek( int pos )
virtual void seek( uint pos )
{
m_s->seek( pos );
@ -305,12 +314,12 @@ public:
}
}
virtual int tell() const
virtual uint tell() const
{
return m_s->tell();
}
virtual int size() const
virtual uint size() const
{
return m_s->size();
}

View File

@ -209,48 +209,11 @@ StringBuilder::StringBuilder( const StringBuilder & s ) : m_size(0), m_str(NULL)
}
/** Copy string. */
StringBuilder::StringBuilder( const char * s )
StringBuilder::StringBuilder( const char * s ) : m_size(0), m_str(NULL)
{
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. */
StringBuilder::~StringBuilder()
{
@ -278,8 +241,7 @@ StringBuilder & StringBuilder::format( const char * fmt, ... )
/** Format a string safely. */
StringBuilder & StringBuilder::format( const char * fmt, va_list arg )
{
nvCheck(fmt != NULL);
nvCheck(m_size >= 0);
nvDebugCheck(fmt != NULL);
if( m_size == 0 ) {
m_size = 64;
@ -327,8 +289,7 @@ StringBuilder & StringBuilder::format( const char * fmt, va_list arg )
/** Append a string. */
StringBuilder & StringBuilder::append( const char * s )
{
nvCheck(s != NULL);
nvCheck(m_size >= 0);
nvDebugCheck(s != NULL);
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.
const char * Path::fileName() const
{
@ -609,8 +545,6 @@ const char * Path::extension(const char * str)
}
// static
String String::s_null(String::null);
/// Clone this string
String String::clone() const
@ -621,13 +555,13 @@ String String::clone() const
void String::setString(const char * str)
{
if( str == NULL ) {
data = s_null.data;
if (str == NULL) {
data = NULL;
}
else {
allocString( str );
addRef();
}
addRef();
}
void String::setString(const char * str, int length)
@ -640,11 +574,11 @@ void String::setString(const char * str, int length)
void String::setString(const StringBuilder & str)
{
if( str.str() == NULL ) {
data = s_null.data;
if (str.str() == NULL) {
data = NULL;
}
else {
allocString(str);
addRef();
}
addRef();
}

View File

@ -14,10 +14,10 @@ namespace nv
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)
{
uint i;
uint i = 0;
while(data[i] != 0) {
h = (33 * h) ^ uint(data[i]);
i++;
@ -47,9 +47,6 @@ namespace nv
explicit StringBuilder( int size_hint );
StringBuilder( const char * str );
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();
@ -120,18 +117,16 @@ namespace nv
char * m_str;
};
/// Path string.
/// Path string. @@ This should be called PathBuilder.
class NVCORE_CLASS Path : public StringBuilder
{
public:
Path() : StringBuilder() {}
explicit Path(int size_hint) : StringBuilder(size_hint) {}
Path(const StringBuilder & str) : StringBuilder(str) {}
Path(int size_hint, const StringBuilder & str) : StringBuilder(size_hint, str) {}
Path(const char * format, ...) __attribute__((format (printf, 2, 3)));
Path(int size_hint, const char * format, ...) __attribute__((format (printf, 3, 4)));
Path(const char * str) : StringBuilder(str) {}
Path(const Path & path) : StringBuilder(path) {}
const char * fileName() const;
const char * extension() const;
@ -140,7 +135,7 @@ namespace nv
void stripFileName();
void stripExtension();
// statics
NVCORE_API static char separator();
NVCORE_API static const char * fileName(const char *);
@ -156,15 +151,14 @@ namespace nv
/// Constructs a null string. @sa isNull()
String()
{
data = s_null.data;
addRef();
data = NULL;
}
/// Constructs a shared copy of str.
String(const String & str)
{
data = str.data;
addRef();
if (data != NULL) addRef();
}
/// Constructs a shared string from a standard string.
@ -188,7 +182,6 @@ namespace nv
/// Dtor.
~String()
{
nvDebugCheck(data != NULL);
release();
}
@ -213,52 +206,61 @@ namespace nv
/// Implement value semantics.
String & operator=( const String & str )
{
release();
data = str.data;
addRef();
if (str.data != data)
{
release();
data = str.data;
addRef();
}
return *this;
}
/// Equal operator.
bool operator==( const String & str ) const
{
nvDebugCheck(data != NULL);
nvDebugCheck(str.data != NULL);
if( str.data == data ) {
return true;
}
if ((data == NULL) != (str.data == NULL)) {
return false;
}
return strcmp(data, str.data) == 0;
}
/// Equal operator.
bool operator==( const char * str ) const
{
nvDebugCheck(data != NULL);
nvCheck(str != NULL); // Use isNull!
if (data == NULL) {
return false;
}
return strcmp(data, str) == 0;
}
/// Not equal operator.
bool operator!=( const String & str ) const
{
nvDebugCheck(data != NULL);
nvDebugCheck(str.data != NULL);
if( str.data == data ) {
return false;
}
if ((data == NULL) != (str.data == NULL)) {
return true;
}
return strcmp(data, str.data) != 0;
}
/// Not equal operator.
bool operator!=( const char * str ) const
{
nvDebugCheck(data != NULL);
nvCheck(str != NULL); // Use isNull!
if (data == NULL) {
return false;
}
return strcmp(data, str) != 0;
}
/// Returns true if this string is the null string.
bool isNull() const { nvDebugCheck(data != NULL); return data == s_null.data; }
bool isNull() const { return data == NULL; }
/// Return the exact length.
uint length() const { nvDebugCheck(data != NULL); return uint(strlen(data)); }
@ -267,44 +269,45 @@ namespace nv
uint hash() const { nvDebugCheck(data != NULL); return strHash(data); }
/// const char * cast operator.
operator const char * () const { nvDebugCheck(data != NULL); return data; }
operator const char * () const { return data; }
/// Get string pointer.
const char * str() const { nvDebugCheck(data != NULL); return data; }
const char * str() const { return data; }
private:
enum null_t { null };
// Private constructor for null string.
String(null_t) {
setString("");
}
// Add reference count.
void addRef() {
nvDebugCheck(data != NULL);
setRefCount(getRefCount() + 1);
}
// Decrease reference count.
void release() {
nvDebugCheck(data != NULL);
const uint16 count = getRefCount();
setRefCount(count - 1);
if( count - 1 == 0 ) {
mem::free(data - 2);
data = NULL;
void addRef()
{
if (data != NULL)
{
setRefCount(getRefCount() + 1);
}
}
uint16 getRefCount() const {
// Decrease reference count.
void release()
{
if (data != NULL)
{
const uint16 count = getRefCount();
setRefCount(count - 1);
if (count - 1 == 0) {
mem::free(data - 2);
data = NULL;
}
}
}
uint16 getRefCount() const
{
nvDebugCheck(data != NULL);
return *reinterpret_cast<const uint16 *>(data - 2);
}
void setRefCount(uint16 count) {
nvDebugCheck(data != NULL);
nvCheck(count < 0xFFFF);
*reinterpret_cast<uint16 *>(const_cast<char *>(data - 2)) = uint16(count);
}
@ -343,8 +346,6 @@ namespace nv
private:
NVCORE_API static String s_null;
const char * data;
};

View File

@ -41,17 +41,17 @@ public:
ByteOrder byteOrder() const { return m_byteOrder; }
/// Serialize the given data. @@ Should return bytes serialized?
virtual void serialize( void * data, int len ) = 0;
/// Serialize the given data.
virtual uint serialize( void * data, uint len ) = 0;
/// 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.
virtual int tell() const = 0;
virtual uint tell() const = 0;
/// Return the current size of the archive.
virtual int size() const = 0;
virtual uint size() const = 0;
/// Determine if there has been any error.
virtual bool isError() const = 0;
@ -136,13 +136,13 @@ public:
protected:
/// Serialize in the stream byte order.
Stream & byteOrderSerialize( void * v, int len ) {
Stream & byteOrderSerialize( void * v, uint len ) {
if( m_byteOrder == getSystemByteOrder() ) {
serialize( v, len );
}
else {
for( int i=len-1; i>=0; i-- ) {
serialize( (uint8 *)v + i, 1 );
for( uint i = len; i > 0; i-- ) {
serialize( (uint8 *)v + i - 1, 1 );
}
}
return *this;

View File

@ -53,6 +53,7 @@ ENDIF(OPENEXR_FOUND)
ADD_DEFINITIONS(-DNVIMAGE_EXPORTS)
IF(NVIMAGE_SHARED)
ADD_DEFINITIONS(-DNVIMAGE_SHARED=1)
ADD_LIBRARY(nvimage SHARED ${IMAGE_SRCS})
ELSE(NVIMAGE_SHARED)
ADD_LIBRARY(nvimage ${IMAGE_SRCS})

View File

@ -113,15 +113,18 @@ void ColorBlock::splatY()
/// Returns true if the block has a single color.
bool ColorBlock::isSingleColor() const
{
for(int i = 1; i < 16; i++)
{
if (m_color[0] != m_color[i])
{
return false;
}
}
return true;
Color32 mask(0xFF, 0xFF, 0xFF, 0x00);
uint u = m_color[0].u & mask.u;
for (int i = 1; i < 16; i++)
{
if (u != (m_color[i].u & mask.u))
{
return false;
}
}
return true;
}
/// Count number of unique colors in this color block.

View File

@ -532,7 +532,7 @@ DDSHeader::DDSHeader()
// Store version information on the reserved header attributes.
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) | (8); // major.minor.revision
this->pf.size = 32;
this->pf.flags = 0;
@ -989,10 +989,10 @@ void DirectDrawSurface::readLinearImage(Image * img)
stream->serialize(&c, byteCount);
Color32 pixel(0, 0, 0, 0xFF);
pixel.r = PixelFormat::convert(c >> rshift, rsize, 8);
pixel.g = PixelFormat::convert(c >> gshift, gsize, 8);
pixel.b = PixelFormat::convert(c >> bshift, bsize, 8);
pixel.a = PixelFormat::convert(c >> ashift, asize, 8);
pixel.r = PixelFormat::convert((c & header.pf.rmask) >> rshift, rsize, 8);
pixel.g = PixelFormat::convert((c & header.pf.gmask) >> gshift, gsize, 8);
pixel.b = PixelFormat::convert((c & header.pf.bmask) >> bshift, bsize, 8);
pixel.a = PixelFormat::convert((c & header.pf.amask) >> ashift, asize, 8);
img->pixel(x, y) = pixel;
}

View File

@ -33,11 +33,10 @@
* 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 <nvimage/Filter.h>
#include <nvcore/Containers.h> // swap
using namespace nv;
@ -504,7 +503,7 @@ void Kernel2::initBlendedSobel(const Vector4 & scale)
for (int i = 0; i < 7; i++) {
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 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 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;
}
}
}
PolyphaseKernel::~PolyphaseKernel()

View File

@ -11,16 +11,16 @@ namespace nv
class Vector4;
/// Base filter class.
class Filter
class NVIMAGE_CLASS Filter
{
public:
NVIMAGE_API Filter(float width);
NVIMAGE_API virtual ~Filter();
Filter(float width);
virtual ~Filter();
NVIMAGE_API float width() const { return m_width; }
NVIMAGE_API float sampleDelta(float x, float scale) const;
NVIMAGE_API float sampleBox(float x, float scale, int samples) const;
NVIMAGE_API float sampleTriangle(float x, float scale, int samples) const;
float width() const { return m_width; }
float sampleDelta(float x, float scale) const;
float sampleBox(float x, float scale, int samples) const;
float sampleTriangle(float x, float scale, int samples) const;
virtual float evaluate(float x) const = 0;
@ -29,56 +29,56 @@ namespace nv
};
// Box filter.
class BoxFilter : public Filter
class NVIMAGE_CLASS BoxFilter : public Filter
{
public:
NVIMAGE_API BoxFilter();
NVIMAGE_API BoxFilter(float width);
NVIMAGE_API virtual float evaluate(float x) const;
BoxFilter();
BoxFilter(float width);
virtual float evaluate(float x) const;
};
// Triangle (bilinear/tent) filter.
class TriangleFilter : public Filter
class NVIMAGE_CLASS TriangleFilter : public Filter
{
public:
NVIMAGE_API TriangleFilter();
NVIMAGE_API TriangleFilter(float width);
NVIMAGE_API virtual float evaluate(float x) const;
TriangleFilter();
TriangleFilter(float width);
virtual float evaluate(float x) const;
};
// Quadratic (bell) filter.
class QuadraticFilter : public Filter
class NVIMAGE_CLASS QuadraticFilter : public Filter
{
public:
NVIMAGE_API QuadraticFilter();
NVIMAGE_API virtual float evaluate(float x) const;
QuadraticFilter();
virtual float evaluate(float x) const;
};
// Cubic filter from Thatcher Ulrich.
class CubicFilter : public Filter
class NVIMAGE_CLASS CubicFilter : public Filter
{
public:
NVIMAGE_API CubicFilter();
NVIMAGE_API virtual float evaluate(float x) const;
CubicFilter();
virtual float evaluate(float x) const;
};
// Cubic b-spline filter from Paul Heckbert.
class BSplineFilter : public Filter
class NVIMAGE_CLASS BSplineFilter : public Filter
{
public:
NVIMAGE_API BSplineFilter();
NVIMAGE_API virtual float evaluate(float x) const;
BSplineFilter();
virtual float evaluate(float x) const;
};
/// Mitchell & Netravali's two-param cubic
/// @see "Reconstruction Filters in Computer Graphics", SIGGRAPH 88
class MitchellFilter : public Filter
class NVIMAGE_CLASS MitchellFilter : public Filter
{
public:
NVIMAGE_API MitchellFilter();
NVIMAGE_API virtual float evaluate(float x) const;
MitchellFilter();
virtual float evaluate(float x) const;
NVIMAGE_API void setParameters(float a, float b);
void setParameters(float b, float c);
private:
float p0, p2, p3;
@ -86,29 +86,29 @@ namespace nv
};
// Lanczos3 filter.
class LanczosFilter : public Filter
class NVIMAGE_CLASS LanczosFilter : public Filter
{
public:
NVIMAGE_API LanczosFilter();
NVIMAGE_API virtual float evaluate(float x) const;
LanczosFilter();
virtual float evaluate(float x) const;
};
// Sinc filter.
class SincFilter : public Filter
class NVIMAGE_CLASS SincFilter : public Filter
{
public:
NVIMAGE_API SincFilter(float w);
NVIMAGE_API virtual float evaluate(float x) const;
SincFilter(float w);
virtual float evaluate(float x) const;
};
// Kaiser filter.
class KaiserFilter : public Filter
class NVIMAGE_CLASS KaiserFilter : public Filter
{
public:
NVIMAGE_API KaiserFilter(float w);
NVIMAGE_API virtual float evaluate(float x) const;
KaiserFilter(float w);
virtual float evaluate(float x) const;
NVIMAGE_API void setParameters(float a, float stretch);
void setParameters(float a, float stretch);
private:
float alpha;
@ -118,12 +118,12 @@ namespace nv
/// A 1D kernel. Used to precompute filter weights.
class Kernel1
class NVIMAGE_CLASS Kernel1
{
NV_FORBID_COPY(Kernel1);
public:
NVIMAGE_API Kernel1(const Filter & f, int iscale, int samples = 32);
NVIMAGE_API ~Kernel1();
Kernel1(const Filter & f, int iscale, int samples = 32);
~Kernel1();
float valueAt(uint x) const {
nvDebugCheck(x < (uint)m_windowSize);
@ -138,7 +138,7 @@ namespace nv
return m_width;
}
NVIMAGE_API void debugPrint();
void debugPrint();
private:
int m_windowSize;
@ -148,15 +148,15 @@ namespace nv
/// A 2D kernel.
class Kernel2
class NVIMAGE_CLASS Kernel2
{
public:
NVIMAGE_API Kernel2(uint width);
NVIMAGE_API Kernel2(const Kernel2 & k);
NVIMAGE_API ~Kernel2();
Kernel2(uint width);
Kernel2(const Kernel2 & k);
~Kernel2();
NVIMAGE_API void normalize();
NVIMAGE_API void transpose();
void normalize();
void transpose();
float valueAt(uint x, uint y) const {
return m_data[y * m_windowSize + x];
@ -166,12 +166,12 @@ namespace nv
return m_windowSize;
}
NVIMAGE_API void initLaplacian();
NVIMAGE_API void initEdgeDetection();
NVIMAGE_API void initSobel();
NVIMAGE_API void initPrewitt();
void initLaplacian();
void initEdgeDetection();
void initSobel();
void initPrewitt();
NVIMAGE_API void initBlendedSobel(const Vector4 & scale);
void initBlendedSobel(const Vector4 & scale);
private:
const uint m_windowSize;
@ -180,12 +180,12 @@ namespace nv
/// A 1D polyphase kernel
class PolyphaseKernel
class NVIMAGE_CLASS PolyphaseKernel
{
NV_FORBID_COPY(PolyphaseKernel);
public:
NVIMAGE_API PolyphaseKernel(const Filter & f, uint srcLength, uint dstLength, int samples = 32);
NVIMAGE_API ~PolyphaseKernel();
PolyphaseKernel(const Filter & f, uint srcLength, uint dstLength, int samples = 32);
~PolyphaseKernel();
int windowSize() const {
return m_windowSize;
@ -205,7 +205,7 @@ namespace nv
return m_data[column * m_windowSize + x];
}
NVIMAGE_API void debugPrint() const;
void debugPrint() const;
private:
int m_windowSize;

View File

@ -1,16 +1,18 @@
// 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 "Filter.h"
#include "Image.h"
#include <nvmath/Color.h>
#include <nvmath/Matrix.h>
#include <nvcore/Containers.h>
#include <nvcore/Ptr.h>
#include <math.h>
using namespace nv;
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.
void FloatImage::allocate(uint c, uint w, uint h)
{
nvCheck(m_mem == NULL);
free();
m_width = w;
m_height = h;
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.
void FloatImage::free()
{
nvCheck(m_mem != NULL);
nv::mem::free( reinterpret_cast<void *>(m_mem) );
m_mem = NULL;
}
@ -549,6 +551,15 @@ FloatImage * FloatImage::downSample(const Filter & filter, WrapMode wm) const
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.
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();
}
/// 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.
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);
@ -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.
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);
@ -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.
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);
@ -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.
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 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.
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 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;
}

View File

@ -3,12 +3,20 @@
#ifndef NV_IMAGE_FLOATIMAGE_H
#define NV_IMAGE_FLOATIMAGE_H
#include <nvimage/nvimage.h>
#include <nvmath/Vector.h>
#include <nvcore/Debug.h>
#include <nvcore/Containers.h> // clamp
#include <nvimage/nvimage.h>
#include <stdlib.h> // abs
namespace nv
{
class Vector4;
class Matrix;
class Image;
class Filter;
class Kernel1;
@ -60,20 +68,22 @@ public:
NVIMAGE_API void toGamma(uint base_component, uint num, float gamma = 2.2f);
NVIMAGE_API void exponentiate(uint base_component, uint num, float power);
NVIMAGE_API FloatImage * fastDownSample() 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 * downSample(const Kernel1 & filter, WrapMode wm) const;
//NVIMAGE_API FloatImage * downSample(const Kernel1 & filter, uint w, uint h, WrapMode wm) const;
NVIMAGE_API FloatImage * resize(const Filter & filter, uint w, uint h, WrapMode wm, uint alpha) const;
//@}
NVIMAGE_API float applyKernel(const Kernel2 * k, int x, int y, int c, WrapMode wm) const;
NVIMAGE_API float applyKernelVertical(const Kernel1 * k, int x, int y, int c, WrapMode wm) const;
NVIMAGE_API float applyKernelHorizontal(const Kernel1 * k, int x, int y, int c, WrapMode wm) const;
NVIMAGE_API void applyKernelVertical(const PolyphaseKernel & k, int x, int c, WrapMode wm, float * output) const;
NVIMAGE_API void applyKernelHorizontal(const PolyphaseKernel & k, int y, int c, WrapMode wm, float * output) 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, uint 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, uint 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; }
@ -109,6 +119,9 @@ public:
float sampleLinearMirror(float x, float y, int c) const;
//@}
FloatImage* clone() const;
public:
uint index(uint x, uint y) const;
@ -234,7 +247,7 @@ inline uint FloatImage::indexMirror(int x, int y) const
}
if (m_height == 1) y = 0;
y = abs(y);
while (y >= m_height) {
y = abs(m_height + m_height - y - 2);

View File

@ -78,7 +78,7 @@ void Image::unwrap()
void Image::free()
{
::free(m_data);
nv::mem::free(m_data);
m_data = NULL;
}

View File

@ -21,15 +21,16 @@
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
// OTHER DEALINGS IN THE SOFTWARE.
#include <nvcore/Ptr.h>
#include <nvmath/Color.h>
#include <nvimage/NormalMap.h>
#include <nvimage/Filter.h>
#include <nvimage/FloatImage.h>
#include <nvimage/Image.h>
#include <nvmath/Color.h>
#include <nvcore/Ptr.h>
using namespace nv;
// Create normal map using the given kernels.

View File

@ -39,7 +39,7 @@ namespace nv
bool isSupported() const
{
if (version != 1) {
printf("*** bad version number %u\n", version);
nvDebug("*** bad version number %u\n", version);
return false;
}
if (channel_count > 4) {

View File

@ -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.
*/
#include <nvimage/Quantize.h>
#include <nvimage/Image.h>
#include <nvimage/PixelFormat.h>
#include <nvmath/Color.h>
#include <nvimage/Image.h>
#include <nvimage/Quantize.h>
#include <nvimage/PixelFormat.h>
#include <nvcore/Containers.h> // swap
using namespace nv;
@ -133,17 +136,17 @@ void nv::Quantize::Truncate(Image * image, uint rsize, uint gsize, uint bsize, u
Color32 pixel = image->pixel(x, y);
// Convert to our desired size, and reconstruct.
pixel.r = PixelFormat::convert(pixel.r, 8, rsize);
pixel.r = PixelFormat::convert(pixel.r, rsize, 8);
pixel.g = PixelFormat::convert(pixel.g, 8, gsize);
pixel.g = PixelFormat::convert(pixel.g, gsize, 8);
pixel.b = PixelFormat::convert(pixel.b, 8, bsize);
pixel.b = PixelFormat::convert(pixel.b, bsize, 8);
pixel.a = PixelFormat::convert(pixel.a, 8, asize);
pixel.a = PixelFormat::convert(pixel.a, asize, 8);
pixel.r = PixelFormat::convert(pixel.r, 8, rsize);
pixel.r = PixelFormat::convert(pixel.r, rsize, 8);
pixel.g = PixelFormat::convert(pixel.g, 8, gsize);
pixel.g = PixelFormat::convert(pixel.g, gsize, 8);
pixel.b = PixelFormat::convert(pixel.b, 8, bsize);
pixel.b = PixelFormat::convert(pixel.b, bsize, 8);
pixel.a = PixelFormat::convert(pixel.a, 8, asize);
pixel.a = PixelFormat::convert(pixel.a, asize, 8);
// Store color.
image->pixel(x, y) = pixel;
@ -152,65 +155,65 @@ void nv::Quantize::Truncate(Image * image, uint rsize, uint gsize, uint bsize, u
}
// Error diffusion. Floyd Steinberg.
void nv::Quantize::FloydSteinberg(Image * image, uint rsize, uint gsize, uint bsize, uint asize)
{
nvCheck(image != NULL);
const uint w = image->width();
const uint h = image->height();
Vector4 * row0 = new Vector4[w+2];
Vector4 * row1 = new Vector4[w+2];
memset(row0, 0, sizeof(Vector4)*(w+2));
memset(row1, 0, sizeof(Vector4)*(w+2));
for (uint y = 0; y < h; y++) {
for (uint x = 0; x < w; x++) {
Color32 pixel = image->pixel(x, y);
// Add error.
pixel.r = clamp(int(pixel.r) + int(row0[1+x].x()), 0, 255);
pixel.g = clamp(int(pixel.g) + int(row0[1+x].y()), 0, 255);
pixel.b = clamp(int(pixel.b) + int(row0[1+x].z()), 0, 255);
pixel.a = clamp(int(pixel.a) + int(row0[1+x].w()), 0, 255);
int r = pixel.r;
int g = pixel.g;
int b = pixel.b;
int a = pixel.a;
// Convert to our desired size, and reconstruct.
r = PixelFormat::convert(r, 8, rsize);
r = PixelFormat::convert(r, rsize, 8);
g = PixelFormat::convert(g, 8, gsize);
g = PixelFormat::convert(g, gsize, 8);
b = PixelFormat::convert(b, 8, bsize);
b = PixelFormat::convert(b, bsize, 8);
a = PixelFormat::convert(a, 8, asize);
a = PixelFormat::convert(a, asize, 8);
// Store color.
image->pixel(x, y) = Color32(r, g, b, a);
// Compute new error.
Vector4 diff(float(int(pixel.r) - r), float(int(pixel.g) - g), float(int(pixel.b) - b), float(int(pixel.a) - a));
// Propagate new error.
row0[1+x+1] += 7.0f / 16.0f * diff;
row1[1+x-1] += 3.0f / 16.0f * diff;
row1[1+x+0] += 5.0f / 16.0f * diff;
row1[1+x+1] += 1.0f / 16.0f * diff;
}
swap(row0, row1);
memset(row1, 0, sizeof(Vector4)*(w+2));
}
delete [] row0;
delete [] row1;
}
// Error diffusion. Floyd Steinberg.
void nv::Quantize::FloydSteinberg(Image * image, uint rsize, uint gsize, uint bsize, uint asize)
{
nvCheck(image != NULL);
const uint w = image->width();
const uint h = image->height();
Vector4 * row0 = new Vector4[w+2];
Vector4 * row1 = new Vector4[w+2];
memset(row0, 0, sizeof(Vector4)*(w+2));
memset(row1, 0, sizeof(Vector4)*(w+2));
for (uint y = 0; y < h; y++) {
for (uint x = 0; x < w; x++) {
Color32 pixel = image->pixel(x, y);
// Add error.
pixel.r = clamp(int(pixel.r) + int(row0[1+x].x()), 0, 255);
pixel.g = clamp(int(pixel.g) + int(row0[1+x].y()), 0, 255);
pixel.b = clamp(int(pixel.b) + int(row0[1+x].z()), 0, 255);
pixel.a = clamp(int(pixel.a) + int(row0[1+x].w()), 0, 255);
int r = pixel.r;
int g = pixel.g;
int b = pixel.b;
int a = pixel.a;
// Convert to our desired size, and reconstruct.
r = PixelFormat::convert(r, 8, rsize);
r = PixelFormat::convert(r, rsize, 8);
g = PixelFormat::convert(g, 8, gsize);
g = PixelFormat::convert(g, gsize, 8);
b = PixelFormat::convert(b, 8, bsize);
b = PixelFormat::convert(b, bsize, 8);
a = PixelFormat::convert(a, 8, asize);
a = PixelFormat::convert(a, asize, 8);
// Store color.
image->pixel(x, y) = Color32(r, g, b, a);
// Compute new error.
Vector4 diff(float(int(pixel.r) - r), float(int(pixel.g) - g), float(int(pixel.b) - b), float(int(pixel.a) - a));
// Propagate new error.
row0[1+x+1] += 7.0f / 16.0f * diff;
row1[1+x-1] += 3.0f / 16.0f * diff;
row1[1+x+0] += 5.0f / 16.0f * diff;
row1[1+x+1] += 1.0f / 16.0f * diff;
}
swap(row0, row1);
memset(row1, 0, sizeof(Vector4)*(w+2));
}
delete [] row0;
delete [] row1;
}

View File

@ -3,6 +3,9 @@
#ifndef NV_IMAGE_QUANTIZE_H
#define NV_IMAGE_QUANTIZE_H
#include <nvimage/nvimage.h>
namespace nv
{
class Image;

View File

@ -108,7 +108,7 @@ public:
float area() const
{
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.
@ -118,6 +118,14 @@ public:
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:
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

View File

@ -19,6 +19,7 @@ INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR})
ADD_DEFINITIONS(-DNVMATH_EXPORTS)
IF(NVMATH_SHARED)
ADD_DEFINITIONS(-DNVMATH_SHARED=1)
ADD_LIBRARY(nvmath SHARED ${MATH_SRCS})
ELSE(NVMATH_SHARED)
ADD_LIBRARY(nvmath ${MATH_SRCS})

View File

@ -332,7 +332,7 @@ inline Matrix transpose(Matrix::Arg m)
Matrix r;
for (int i = 0; i < 4; i++)
{
for (int j = 0; j < 4; i++)
for (int j = 0; j < 4; j++)
{
r(i, j) = m(j, i);
}

View File

@ -48,19 +48,37 @@
#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);
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);
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);
return asinf(f);
@ -68,11 +86,11 @@ inline float asin_assert(const float f)
// Replace default functions with asserting ones.
#define sqrt sqrt_assert
#define sqrtf sqrt_assert
#define sqrtf sqrtf_assert
#define acos acos_assert
#define acosf acos_assert
#define acosf acosf_assert
#define asin asin_assert
#define asinf asin_assert
#define asinf asinf_assert
#if NV_OS_WIN32
#include <float.h>
@ -136,6 +154,11 @@ inline float lerp(float f0, float f1, float t)
return f0 * s + f1 * t;
}
inline float square(float f)
{
return f * f;
}
} // nv
#endif // NV_MATH_H

View File

@ -43,8 +43,9 @@ INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR})
ADD_DEFINITIONS(-DNVTT_EXPORTS)
IF(NVTT_SHARED)
ADD_LIBRARY(nvtt SHARED ${DXT_SRCS})
IF(NVTT_SHARED)
ADD_DEFINITIONS(-DNVTT_SHARED=1)
ADD_LIBRARY(nvtt SHARED ${NVTT_SRCS})
ELSE(NVTT_SHARED)
ADD_LIBRARY(nvtt ${NVTT_SRCS})
ENDIF(NVTT_SHARED)

View File

@ -205,9 +205,9 @@ void nv::SlowCompressor::compressDXT1(const CompressionOptions::Private & compre
ColorBlock rgba;
BlockDXT1 block;
//squish::WeightedClusterFit fit;
squish::WeightedClusterFit fit;
//squish::ClusterFit fit;
squish::FastClusterFit fit;
//squish::FastClusterFit fit;
fit.SetMetric(compressionOptions.colorWeight.x(), compressionOptions.colorWeight.y(), compressionOptions.colorWeight.z());
for (uint y = 0; y < h; y += 4) {
@ -221,7 +221,7 @@ void nv::SlowCompressor::compressDXT1(const CompressionOptions::Private & compre
}
else
{
squish::ColourSet colours((uint8 *)rgba.colors(), 0);
squish::ColourSet colours((uint8 *)rgba.colors(), 0, true);
fit.SetColourSet(&colours, squish::kDxt1);
fit.Compress(&block);
}

View File

@ -53,7 +53,7 @@ using namespace nvtt;
namespace
{
static int blockSize(Format format)
{
if (format == Format_DXT1 || format == Format_DXT1a) {
@ -121,15 +121,13 @@ namespace nvtt
m_fixedImage = NULL;
m_floatImage = image;
}
// Convert linear float image to fixed image ready for compression.
void toFixedImage(const InputOptions::Private & inputOptions)
{
if (this->asFixedImage() == NULL)
if (m_floatImage != NULL) // apfaffe - We should check that we have a float image, if so convert it!
{
nvDebugCheck(m_floatImage != NULL);
if (inputOptions.isNormalMap || inputOptions.outputGamma == 1.0f)
{
m_fixedImage = m_floatImage->createImage();
@ -153,7 +151,7 @@ namespace nvtt
if (inputOptions.isNormalMap)
{
// Expand normals to [-1, 1] range.
// floatImage->expandNormals(0);
// floatImage->expandNormals(0);
}
else if (inputOptions.inputGamma != 1.0f)
{
@ -175,11 +173,12 @@ namespace nvtt
const Image * asFixedImage() const
{
if (m_inputImage != NULL)
// - apfaffe - switched logic to return the 'processed image' rather than the input!
if (m_fixedImage != NULL && m_fixedImage.ptr() != NULL)
{
return m_inputImage;
return m_fixedImage.ptr();
}
return m_fixedImage.ptr();
return m_inputImage;
}
Image * asMutableFixedImage()
@ -193,7 +192,7 @@ namespace nvtt
return m_fixedImage.ptr();
}
private:
const Image * m_inputImage;
AutoPtr<Image> m_fixedImage;
@ -207,22 +206,15 @@ Compressor::Compressor() : m(*new Compressor::Private())
{
// CUDA initialization.
m.cudaSupported = cuda::isHardwarePresent();
m.cudaEnabled = m.cudaSupported;
m.cudaEnabled = false;
m.cudaDevice = -1;
if (m.cudaEnabled)
{
m.cuda = new CudaCompressor();
if (!m.cuda->isValid())
{
m.cudaEnabled = false;
m.cuda = NULL;
}
}
enableCudaAcceleration(m.cudaSupported);
}
Compressor::~Compressor()
{
enableCudaAcceleration(false);
delete &m;
}
@ -232,17 +224,33 @@ void Compressor::enableCudaAcceleration(bool enable)
{
if (m.cudaSupported)
{
m.cudaEnabled = enable;
}
if (m.cudaEnabled && m.cuda == NULL)
{
m.cuda = new CudaCompressor();
if (!m.cuda->isValid())
if (m.cudaEnabled && !enable)
{
m.cudaEnabled = false;
m.cuda = NULL;
if (m.cudaDevice != -1)
{
// Exit device.
cuda::exitDevice();
}
}
else if (!m.cudaEnabled && enable)
{
// Init the CUDA device. This may return -1 if CUDA was already initialized by the app.
m.cudaEnabled = cuda::initDevice(&m.cudaDevice);
if (m.cudaEnabled)
{
// Create compressor if initialization succeeds.
m.cuda = new CudaCompressor();
// But cleanup if failed.
if (!m.cuda->isValid())
{
enableCudaAcceleration(false);
}
}
}
}
}
@ -283,9 +291,9 @@ bool Compressor::Private::compress(const InputOptions::Private & inputOptions, c
if (outputOptions.errorHandler) outputOptions.errorHandler->error(Error_FileOpen);
return false;
}
inputOptions.computeTargetExtents();
// Output DDS header.
if (!outputHeader(inputOptions, compressionOptions, outputOptions))
{
@ -301,7 +309,7 @@ bool Compressor::Private::compress(const InputOptions::Private & inputOptions, c
}
outputOptions.closeFile();
return true;
}
@ -316,15 +324,15 @@ bool Compressor::Private::outputHeader(const InputOptions::Private & inputOption
}
DDSHeader header;
header.setWidth(inputOptions.targetWidth);
header.setHeight(inputOptions.targetHeight);
int mipmapCount = inputOptions.realMipmapCount();
nvDebugCheck(mipmapCount > 0);
header.setMipmapCount(mipmapCount);
if (inputOptions.textureType == TextureType_2D) {
header.setTexture2D();
}
@ -332,10 +340,10 @@ bool Compressor::Private::outputHeader(const InputOptions::Private & inputOption
header.setTextureCube();
}
/*else if (inputOptions.textureType == TextureType_3D) {
header.setTexture3D();
header.setDepth(inputOptions.targetDepth);
header.setTexture3D();
header.setDepth(inputOptions.targetDepth);
}*/
if (compressionOptions.format == Format_RGBA)
{
header.setPitch(computePitch(inputOptions.targetWidth, compressionOptions.bitcount));
@ -344,7 +352,7 @@ bool Compressor::Private::outputHeader(const InputOptions::Private & inputOption
else
{
header.setLinearSize(computeImageSize(inputOptions.targetWidth, inputOptions.targetHeight, inputOptions.targetDepth, compressionOptions.bitcount, compressionOptions.format));
if (compressionOptions.format == Format_DXT1 || compressionOptions.format == Format_DXT1a) {
header.setFourCC('D', 'X', 'T', '1');
if (inputOptions.isNormalMap) header.setNormalFlag(true);
@ -367,10 +375,10 @@ bool Compressor::Private::outputHeader(const InputOptions::Private & inputOption
if (inputOptions.isNormalMap) header.setNormalFlag(true);
}
}
// Swap bytes if necessary.
header.swapBytes();
uint headerSize = 128;
if (header.hasDX10Header())
{
@ -383,7 +391,7 @@ bool Compressor::Private::outputHeader(const InputOptions::Private & inputOption
{
outputOptions.errorHandler->error(Error_FileWrite);
}
return writeSucceed;
}
@ -419,7 +427,7 @@ bool Compressor::Private::compressMipmaps(uint f, const InputOptions::Private &
return false;
}
}
quantizeMipmap(mipmap, compressionOptions);
compressMipmap(mipmap, inputOptions, compressionOptions, outputOptions);
@ -429,7 +437,7 @@ bool Compressor::Private::compressMipmaps(uint f, const InputOptions::Private &
h = max(1U, h / 2);
d = max(1U, d / 2);
}
return true;
}
@ -480,7 +488,7 @@ int Compressor::Private::findExactMipmap(const InputOptions::Private & inputOpti
{
int idx = f * inputOptions.mipmapCount + m;
const InputOptions::Private::InputImage & inputImage = inputOptions.images[idx];
if (inputImage.width == int(w) && inputImage.height == int(h) && inputImage.depth == int(d))
{
if (inputImage.data != NULL)
@ -535,7 +543,7 @@ void Compressor::Private::downsampleMipmap(Mipmap & mipmap, const InputOptions::
mipmap.toFloatImage(inputOptions);
const FloatImage * floatImage = mipmap.asFloatImage();
if (inputOptions.mipmapFilter == MipmapFilter_Box)
{
// Use fast downsample.
@ -553,7 +561,7 @@ void Compressor::Private::downsampleMipmap(Mipmap & mipmap, const InputOptions::
filter.setParameters(inputOptions.kaiserAlpha, inputOptions.kaiserStretch);
mipmap.setImage(floatImage->downSample(filter, (FloatImage::WrapMode)inputOptions.wrapMode));
}
// Normalize mipmap.
if ((inputOptions.isNormalMap || inputOptions.convertToNormalMap) && inputOptions.normalizeMipmaps)
{
@ -581,7 +589,7 @@ void Compressor::Private::processInputImage(Mipmap & mipmap, const InputOptions:
if (inputOptions.convertToNormalMap)
{
mipmap.toFixedImage(inputOptions);
Vector4 heightScale = inputOptions.heightFactors;
mipmap.setImage(createNormalMap(mipmap.asFixedImage(), (FloatImage::WrapMode)inputOptions.wrapMode, heightScale, inputOptions.bumpFrequencyScale));
}
@ -689,6 +697,7 @@ bool Compressor::Private::compressMipmap(const Mipmap & mipmap, const InputOptio
SlowCompressor slow;
slow.setImage(image, inputOptions.alphaMode);
const bool useCuda = cudaEnabled && image->width() * image->height() >= 512;
if (compressionOptions.format == Format_RGBA || compressionOptions.format == Format_RGB)
{
@ -705,29 +714,29 @@ bool Compressor::Private::compressMipmap(const Mipmap & mipmap, const InputOptio
#endif
#if defined(HAVE_ATITC)
if (compressionOptions.externalCompressor == "ati")
{
atiCompressDXT1(image, outputOptions);
}
else
#endif
if (compressionOptions.quality == Quality_Fastest)
{
fast.compressDXT1(outputOptions);
}
else
{
if (cudaEnabled)
if (compressionOptions.externalCompressor == "ati")
{
nvDebugCheck(cudaSupported);
cuda->setImage(image, inputOptions.alphaMode);
cuda->compressDXT1(compressionOptions, outputOptions);
atiCompressDXT1(image, outputOptions);
}
else
{
slow.compressDXT1(compressionOptions, outputOptions);
}
}
#endif
if (compressionOptions.quality == Quality_Fastest)
{
fast.compressDXT1(outputOptions);
}
else
{
if (useCuda)
{
nvDebugCheck(cudaSupported);
cuda->setImage(image, inputOptions.alphaMode);
cuda->compressDXT1(compressionOptions, outputOptions);
}
else
{
slow.compressDXT1(compressionOptions, outputOptions);
}
}
}
else if (compressionOptions.format == Format_DXT1a)
{
@ -737,7 +746,7 @@ bool Compressor::Private::compressMipmap(const Mipmap & mipmap, const InputOptio
}
else
{
if (cudaEnabled)
if (useCuda)
{
nvDebugCheck(cudaSupported);
/*cuda*/slow.compressDXT1a(compressionOptions, outputOptions);
@ -756,7 +765,7 @@ bool Compressor::Private::compressMipmap(const Mipmap & mipmap, const InputOptio
}
else
{
if (cudaEnabled)
if (useCuda)
{
nvDebugCheck(cudaSupported);
cuda->setImage(image, inputOptions.alphaMode);
@ -776,7 +785,7 @@ bool Compressor::Private::compressMipmap(const Mipmap & mipmap, const InputOptio
}
else
{
if (cudaEnabled)
if (useCuda)
{
nvDebugCheck(cudaSupported);
cuda->setImage(image, inputOptions.alphaMode);
@ -818,27 +827,27 @@ int Compressor::Private::estimateSize(const InputOptions::Private & inputOptions
const uint bitCount = compressionOptions.bitcount;
inputOptions.computeTargetExtents();
uint mipmapCount = inputOptions.realMipmapCount();
int size = 0;
for (uint f = 0; f < inputOptions.faceCount; f++)
{
uint w = inputOptions.targetWidth;
uint h = inputOptions.targetHeight;
uint d = inputOptions.targetDepth;
for (uint m = 0; m < mipmapCount; m++)
{
size += computeImageSize(w, h, d, bitCount, format);
// Compute extents of next mipmap:
w = max(1U, w / 2);
h = max(1U, h / 2);
d = max(1U, d / 2);
}
}
return size;
}

View File

@ -63,10 +63,12 @@ namespace nvtt
bool compressMipmap(const Mipmap & mipmap, const InputOptions::Private & inputOptions, const CompressionOptions::Private & compressionOptions, const OutputOptions::Private & outputOptions) const;
public:
bool cudaSupported;
bool cudaEnabled;
int cudaDevice;
nv::AutoPtr<nv::CudaCompressor> cuda;

View File

@ -94,7 +94,7 @@ void InputOptions::reset()
m.textureType = TextureType_2D;
m.inputFormat = InputFormat_BGRA_8UB;
m.alphaMode = AlphaMode_Transparency;
m.alphaMode = AlphaMode_None;
m.inputGamma = 2.2f;
m.outputGamma = 2.2f;

File diff suppressed because it is too large Load Diff

View File

@ -191,6 +191,9 @@ __device__ void loadColorBlock(const uint * image, float3 colors[16], float3 sum
*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);
#if __DEVICE_EMULATION__

View File

@ -37,7 +37,7 @@
#if defined HAVE_CUDA
#include <cuda_runtime.h>
#include <cuda_runtime_api.h>
#endif
#include <time.h>

View File

@ -127,8 +127,21 @@ inline __device__ __host__ float3 normalize(float3 v)
inline __device__ __host__ float3 firstEigenVector( float matrix[6] )
{
// 8 iterations seems to be more than enough.
float3 row0 = make_float3(matrix[0], matrix[1], matrix[2]);
float3 row1 = make_float3(matrix[1], matrix[3], matrix[4]);
float3 row2 = make_float3(matrix[2], matrix[4], matrix[5]);
float3 v = make_float3(1.0f, 1.0f, 1.0f);
float r0 = dot(row0, row0);
float r1 = dot(row1, row1);
float r2 = dot(row2, row2);
float3 v;
if (r0 > r1 && r0 > r2) v = row0;
else if (r1 > r2) v = row1;
else v = row2;
//float3 v = make_float3(1.0f, 1.0f, 1.0f);
for(int i = 0; i < 8; i++) {
float x = v.x * matrix[0] + v.y * matrix[1] + v.z * matrix[2];
float y = v.x * matrix[1] + v.y * matrix[3] + v.z * matrix[4];
@ -148,7 +161,7 @@ inline __device__ bool singleColor(const float3 * colors)
bool sameColor = false;
for (int i = 0; i < 16; i++)
{
sameColor &= (colors[idx] == colors[0]);
sameColor &= (colors[i] == colors[0]);
}
return sameColor;
#else

View File

@ -1,128 +1,300 @@
// Copyright NVIDIA Corporation 2007 -- Ignacio Castano <icastano@nvidia.com>
//
// 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 THE AUTHORS OR COPYRIGHT
// HOLDERS 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 <nvcore/Debug.h>
#include "CudaUtils.h"
#if defined HAVE_CUDA
#include <cuda_runtime.h>
#endif
using namespace nv;
using namespace cuda;
#if NV_OS_WIN32
#define WINDOWS_LEAN_AND_MEAN
#include <windows.h>
static bool isWindowsVista()
{
OSVERSIONINFO osvi;
osvi.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
::GetVersionEx(&osvi);
return osvi.dwMajorVersion >= 6;
}
typedef BOOL (WINAPI *LPFN_ISWOW64PROCESS) (HANDLE, PBOOL);
static bool isWow32()
{
LPFN_ISWOW64PROCESS fnIsWow64Process = (LPFN_ISWOW64PROCESS)GetProcAddress(GetModuleHandle("kernel32"), "IsWow64Process");
BOOL bIsWow64 = FALSE;
if (NULL != fnIsWow64Process)
{
if (!fnIsWow64Process(GetCurrentProcess(), &bIsWow64))
{
// Assume 32 bits.
return true;
}
}
return !bIsWow64;
}
#endif
/// Determine if CUDA is available.
bool nv::cuda::isHardwarePresent()
{
#if defined HAVE_CUDA
#if NV_OS_WIN32
//if (isWindowsVista()) return false;
//if (isWindowsVista() || !isWow32()) return false;
#endif
int count = deviceCount();
if (count == 1)
{
// Make sure it's not an emulation device.
cudaDeviceProp deviceProp;
cudaGetDeviceProperties(&deviceProp, 0);
// deviceProp.name != Device Emulation (CPU)
if (deviceProp.major == -1 || deviceProp.minor == -1)
{
return false;
}
// @@ Make sure that warp size == 32
}
return count > 0;
#else
return false;
#endif
}
/// Get number of CUDA enabled devices.
int nv::cuda::deviceCount()
{
#if defined HAVE_CUDA
int gpuCount = 0;
cudaError_t result = cudaGetDeviceCount(&gpuCount);
if (result == cudaSuccess)
{
return gpuCount;
}
#endif
return 0;
}
/// Activate the given devices.
bool nv::cuda::setDevice(int i)
{
nvCheck(i < deviceCount());
#if defined HAVE_CUDA
cudaError_t result = cudaSetDevice(i);
return result == cudaSuccess;
#else
return false;
#endif
}
// Copyright NVIDIA Corporation 2007 -- Ignacio Castano <icastano@nvidia.com>
//
// 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 THE AUTHORS OR COPYRIGHT
// HOLDERS 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 <nvcore/Debug.h>
#include <nvcore/Library.h>
#include "CudaUtils.h"
#if defined HAVE_CUDA
#include <cuda.h>
#include <cuda_runtime_api.h>
#endif
using namespace nv;
using namespace cuda;
/* @@ Move this to win32 utils or somewhere else.
#if NV_OS_WIN32
#define WINDOWS_LEAN_AND_MEAN
#include <windows.h>
static bool isWindowsVista()
{
OSVERSIONINFO osvi;
osvi.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
::GetVersionEx(&osvi);
return osvi.dwMajorVersion >= 6;
}
typedef BOOL (WINAPI *LPFN_ISWOW64PROCESS) (HANDLE, PBOOL);
static bool isWow32()
{
LPFN_ISWOW64PROCESS fnIsWow64Process = (LPFN_ISWOW64PROCESS)GetProcAddress(GetModuleHandle("kernel32"), "IsWow64Process");
BOOL bIsWow64 = FALSE;
if (NULL != fnIsWow64Process)
{
if (!fnIsWow64Process(GetCurrentProcess(), &bIsWow64))
{
// Assume 32 bits.
return true;
}
}
return !bIsWow64;
}
#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.
bool nv::cuda::isHardwarePresent()
{
#if defined HAVE_CUDA
// Make sure that CUDA driver matches CUDA runtime.
if (!isCudaDriverAvailable(CUDART_VERSION))
{
nvDebug("CUDA driver not available for CUDA runtime %d\n", CUDART_VERSION);
return false;
}
int count = deviceCount();
if (count == 1)
{
// Make sure it's not an emulation device.
cudaDeviceProp deviceProp;
cudaGetDeviceProperties(&deviceProp, 0);
// deviceProp.name != Device Emulation (CPU)
if (deviceProp.major == -1 || deviceProp.minor == -1)
{
return false;
}
}
// @@ Make sure that warp size == 32
// @@ Make sure available GPU is faster than the CPU.
return count > 0;
#else
return false;
#endif
}
/// Get number of CUDA enabled devices.
int nv::cuda::deviceCount()
{
#if defined HAVE_CUDA
int gpuCount = 0;
cudaError_t result = cudaGetDeviceCount(&gpuCount);
if (result == cudaSuccess)
{
return gpuCount;
}
#endif
return 0;
}
// Make sure device meets requirements:
// - Not an emulation device.
// - Not an integrated device?
// - Faster than CPU.
bool nv::cuda::isValidDevice(int i)
{
#if defined HAVE_CUDA
cudaDeviceProp device_properties;
cudaGetDeviceProperties(&device_properties, i);
int gflops = device_properties.multiProcessorCount * device_properties.clockRate;
if (device_properties.major == -1 || device_properties.minor == -1) {
// Emulation device.
return false;
}
#if CUDART_VERSION >= 2030 // 2.3
/*if (device_properties.integrated)
{
// Integrated devices.
return false;
}*/
#endif
return true;
#else
return false;
#endif
}
int nv::cuda::getFastestDevice()
{
int max_gflops_device = -1;
#if defined HAVE_CUDA
int max_gflops = 0;
const int device_count = deviceCount();
for (int i = 0; i < device_count; i++)
{
if (isValidDevice(i))
{
cudaDeviceProp device_properties;
cudaGetDeviceProperties(&device_properties, i);
int gflops = device_properties.multiProcessorCount * device_properties.clockRate;
if (gflops > max_gflops)
{
max_gflops = gflops;
max_gflops_device = i;
}
}
}
#endif
return max_gflops_device;
}
/// Activate the given devices.
bool nv::cuda::initDevice(int * device_ptr)
{
nvDebugCheck(device_ptr != NULL);
#if defined HAVE_CUDA
#if CUDART_VERSION >= 2030 // 2.3
// Set device flags to yield in order to play nice with other threads and to find out if CUDA was already active.
cudaError_t resul = cudaSetDeviceFlags(cudaDeviceScheduleYield);
#endif
int device = getFastestDevice();
if (device == -1)
{
// No device is fast enough.
*device_ptr = -1;
return false;
}
// Select CUDA device.
cudaError_t result = cudaSetDevice(device);
if (result == cudaErrorSetOnActiveProcess)
{
int device;
result = cudaGetDevice(&device);
*device_ptr = -1; // No device to cleanup.
return isValidDevice(device); // Return true if device is valid.
}
else if (result != cudaSuccess)
{
nvDebug("*** CUDA Error: %s\n", cudaGetErrorString(result));
*device_ptr = -1;
return false;
}
*device_ptr = device;
return true;
#else
return false;
#endif
}
void nv::cuda::exitDevice()
{
#if defined HAVE_CUDA
cudaError_t result = cudaThreadExit();
if (result != cudaSuccess) {
nvDebug("*** CUDA Error: %s\n", cudaGetErrorString(result));
}
#endif
}

View File

@ -31,7 +31,11 @@ namespace nv
{
bool isHardwarePresent();
int deviceCount();
bool setDevice(int i);
int getFastestDevice();
bool isValidDevice(int i);
bool initDevice(int * device_ptr);
void exitDevice();
};
} // nv namespace

View File

@ -73,7 +73,7 @@ namespace nvtt
Format_DXT1a, // DXT1 with binary alpha.
Format_DXT3,
Format_DXT5,
Format_DXT5n, // Compressed HILO: R=0, G=x, B=0, A=y
Format_DXT5n, // Compressed HILO: R=1, G=y, B=0, A=x
// DX10 formats.
Format_BC1 = Format_DXT1,
@ -194,7 +194,7 @@ namespace nvtt
// Describe the format of the input.
NVTT_API void setFormat(InputFormat format);
// Set the way the input alpha channel is interpreted. @@ Not implemented!
// Set the way the input alpha channel is interpreted.
NVTT_API void setAlphaMode(AlphaMode alphaMode);
// Set gamma settings.

View File

@ -1,13 +1,8 @@
PROJECT(squish)
ENABLE_TESTING()
INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR})
SET(SQUISH_SRCS
# alpha.cpp
# alpha.h
# clusterfit.cpp
# clusterfit.h
fastclusterfit.cpp
fastclusterfit.h
weightedclusterfit.cpp
@ -21,32 +16,13 @@ SET(SQUISH_SRCS
config.h
maths.cpp
maths.h
# rangefit.cpp
# rangefit.h
# singlecolourfit.cpp
# singlecolourfit.h
# singlecolourlookup.inl
# squish.cpp
# squish.h
simd.h
simd_sse.h
simd_ve.h)
ADD_LIBRARY(squish STATIC ${SQUISH_SRCS})
# libpng
#FIND_PACKAGE(PNG)
#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)
IF(CMAKE_COMPILER_IS_GNUCXX)
SET_TARGET_PROPERTIES(squish PROPERTIES COMPILE_FLAGS -fPIC)
ENDIF(CMAKE_COMPILER_IS_GNUCXX)

View File

@ -24,6 +24,7 @@
-------------------------------------------------------------------------- */
#include "maths.h"
#include "simd.h"
#include <cfloat>
namespace squish {
@ -60,12 +61,61 @@ Sym3x3 ComputeWeightedCovariance( int n, Vec3 const* points, float const* weight
}
static Vec3 EstimatePrincipleComponent( Sym3x3 const& matrix )
{
Vec3 const row0(matrix[0], matrix[1], matrix[2]);
Vec3 const row1(matrix[1], matrix[3], matrix[4]);
Vec3 const row2(matrix[2], matrix[4], matrix[5]);
float r0 = Dot(row0, row0);
float r1 = Dot(row1, row1);
float r2 = Dot(row2, row2);
if (r0 > r1 && r0 > r2) return row0;
if (r1 > r2) return row1;
return row2;
}
#define POWER_ITERATION_COUNT 8
#if SQUISH_USE_SIMD
Vec3 ComputePrincipleComponent( Sym3x3 const& matrix )
{
const int NUM = 8;
Vec4 const row0( matrix[0], matrix[1], matrix[2], 0.0f );
Vec4 const row1( matrix[1], matrix[3], matrix[4], 0.0f );
Vec4 const row2( matrix[2], matrix[4], matrix[5], 0.0f );
Vec3 v(1, 1, 1);
for(int i = 0; i < NUM; i++) {
//Vec4 v = VEC4_CONST( 1.0f );
//Vec4 v = row0; // row1, row2
Vec3 v3 = EstimatePrincipleComponent( matrix );
Vec4 v( v3.X(), v3.Y(), v3.Z(), 0.0f );
for( int i = 0; i < POWER_ITERATION_COUNT; ++i )
{
// matrix multiply
Vec4 w = row0*v.SplatX();
w = MultiplyAdd(row1, v.SplatY(), w);
w = MultiplyAdd(row2, v.SplatZ(), w);
// get max component from xyz in all channels
Vec4 a = Max(w.SplatX(), Max(w.SplatY(), w.SplatZ()));
// divide through and advance
v = w*Reciprocal(a);
}
return v.GetVec3();
}
#else
Vec3 ComputePrincipleComponent( Sym3x3 const& matrix )
{
Vec3 v = EstimatePrincipleComponent( matrix );
for (int i = 0; i < POWER_ITERATION_COUNT; i++)
{
float x = v.X() * matrix[0] + v.Y() * matrix[1] + v.Z() * matrix[2];
float y = v.X() * matrix[1] + v.Y() * matrix[3] + v.Z() * matrix[4];
float z = v.X() * matrix[2] + v.Y() * matrix[4] + v.Z() * matrix[5];
@ -82,5 +132,6 @@ Vec3 ComputePrincipleComponent( Sym3x3 const& matrix )
return v;
}
#endif
} // namespace squish

File diff suppressed because it is too large Load Diff

View File

@ -87,7 +87,10 @@ struct MyErrorHandler : public nvtt::ErrorHandler
{
virtual void error(nvtt::Error e)
{
#if _DEBUG
nvDebugBreak();
#endif
printf("Error: '%s'\n", nvtt::errorString(e));
}
};
@ -131,6 +134,7 @@ int main(int argc, char *argv[])
MyAssertHandler assertHandler;
MyMessageHandler messageHandler;
bool alpha = false;
bool normal = false;
bool color2normal = false;
bool wrapRepeat = false;
@ -154,6 +158,10 @@ int main(int argc, char *argv[])
if (strcmp("-color", argv[i]) == 0)
{
}
else if (strcmp("-alpha", argv[i]) == 0)
{
alpha = true;
}
else if (strcmp("-normal", argv[i]) == 0)
{
normal = true;
@ -254,7 +262,12 @@ int main(int argc, char *argv[])
}
}
printf("NVIDIA Texture Tools - Copyright NVIDIA Corporation 2007\n\n");
const uint version = nvtt::version();
const uint major = version / 100;
const uint minor = version % 100;
printf("NVIDIA Texture Tools %u.%u - Copyright NVIDIA Corporation 2007\n\n", major, minor);
if (input.isNull())
{
@ -262,6 +275,7 @@ int main(int argc, char *argv[])
printf("Input options:\n");
printf(" -color \tThe input image is a color map (default).\n");
printf(" -alpha \tThe input image has an alpha channel used for transparency.\n");
printf(" -normal \tThe input image is a normal map.\n");
printf(" -tonormal\tConvert input to normal map.\n");
printf(" -clamp \tClamp wrapping mode (default).\n");
@ -281,7 +295,7 @@ int main(int argc, char *argv[])
printf(" -bc4 \tBC4 format (ATI1)\n");
printf(" -bc5 \tBC5 format (3Dc/ATI2)\n\n");
return 1;
return EXIT_FAILURE;
}
// @@ Make sure input file exists.
@ -296,13 +310,13 @@ int main(int argc, char *argv[])
if (!dds.isValid())
{
fprintf(stderr, "The file '%s' is not a valid DDS file.\n", input.str());
return 1;
return EXIT_FAILURE;
}
if (!dds.isSupported() || dds.isTexture3D())
{
fprintf(stderr, "The file '%s' is not a supported DDS file.\n", input.str());
return 1;
return EXIT_FAILURE;
}
uint faceCount;
@ -339,7 +353,7 @@ int main(int argc, char *argv[])
if (!image.load(input))
{
fprintf(stderr, "The file '%s' is not a supported image type.\n", input.str());
return 1;
return EXIT_FAILURE;
}
inputOptions.setTextureLayout(nvtt::TextureType_2D, image.width(), image.height());
@ -355,6 +369,15 @@ int main(int argc, char *argv[])
inputOptions.setWrapMode(nvtt::WrapMode_Clamp);
}
if (alpha)
{
inputOptions.setAlphaMode(nvtt::AlphaMode_Transparency);
}
else
{
inputOptions.setAlphaMode(nvtt::AlphaMode_None);
}
if (normal)
{
setNormalMap(inputOptions);
@ -396,33 +419,28 @@ int main(int argc, char *argv[])
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;
MyOutputHandler outputHandler(output);
if (outputHandler.stream->isError())
{
fprintf(stderr, "Error opening '%s' for writting\n", output.str());
return 1;
return EXIT_FAILURE;
}
nvtt::Compressor compressor;
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.setDisplayProgress(!silent);
@ -435,27 +453,16 @@ int main(int argc, char *argv[])
// fflush(stdout);
// getchar();
/* LARGE_INTEGER temp;
QueryPerformanceFrequency((LARGE_INTEGER*) &temp);
double freq = ((double) temp.QuadPart) / 1000.0;
LARGE_INTEGER start_time;
QueryPerformanceCounter((LARGE_INTEGER*) &start_time);
*/
clock_t start = clock();
compressor.process(inputOptions, compressionOptions, outputOptions);
/*
LARGE_INTEGER end_time;
QueryPerformanceCounter((LARGE_INTEGER*) &end_time);
float diff_time = (float) (((double) end_time.QuadPart - (double) start_time.QuadPart) / freq);
printf("\rtime taken: %.3f seconds\n", diff_time/1000);
*/
if (!compressor.process(inputOptions, compressionOptions, outputOptions))
{
return EXIT_FAILURE;
}
clock_t end = clock();
printf("\rtime taken: %.3f seconds\n", float(end-start) / CLOCKS_PER_SEC);
return 0;
return EXIT_SUCCESS;
}

View File

@ -84,7 +84,7 @@ struct Error
{
mabse /= samples;
mse /= samples;
rmse = sqrt(mse);
rmse = sqrtf(mse);
psnr = (rmse == 0) ? 999.0f : 20.0f * log10(255.0f / rmse);
}
@ -134,7 +134,7 @@ struct NormalError
{
ade /= samples;
mse /= samples * 3;
rmse = sqrt(mse);
rmse = sqrtf(mse);
psnr = (rmse == 0) ? 999.0f : 20.0f * log10(255.0f / rmse);
}
}

View File

@ -113,7 +113,7 @@ int main(int argc, char *argv[])
((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;
i++;