diff --git a/src/nvtt/bc6h/bits.h b/src/nvtt/bc6h/bits.h index bf177ca..3da7d79 100644 --- a/src/nvtt/bc6h/bits.h +++ b/src/nvtt/bc6h/bits.h @@ -9,7 +9,7 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. */ - +#pragma once #ifndef _BITS_H #define _BITS_H @@ -70,4 +70,4 @@ private: } }; -#endif \ No newline at end of file +#endif diff --git a/src/nvtt/bc6h/shapes_two.h b/src/nvtt/bc6h/shapes_two.h index d9a52ef..9d2e6cb 100644 --- a/src/nvtt/bc6h/shapes_two.h +++ b/src/nvtt/bc6h/shapes_two.h @@ -9,7 +9,7 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. */ - +#pragma once #ifndef _SHAPES_TWO_H #define _SHAPES_TWO_H diff --git a/src/nvtt/bc6h/tile.h b/src/nvtt/bc6h/tile.h index e45011b..cf3e88a 100644 --- a/src/nvtt/bc6h/tile.h +++ b/src/nvtt/bc6h/tile.h @@ -9,19 +9,16 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. */ - +#pragma once #ifndef _TILE_H #define _TILE_H -//#include -//#include -//#include -#include -#include "nvmath/Vector.h" - #include "utils.h" -#define DBL_MAX (1.0e37) // doesn't have to be really dblmax, just bigger than any possible squared error +#include "nvmath/Vector.h" + +#include + //#define USE_IMPORTANCE_MAP 1 // define this if you want to increase importance of some pixels in tile class Tile @@ -81,32 +78,6 @@ public: Vector3 data[TILE_H][TILE_W]; float importance_map[TILE_H][TILE_W]; int size_x, size_y; // actual size of tile - - // pixels -> tile - /*void inline insert(const Array2D &pixels, int x, int y) - { - for (int y0=0; y0 pixels - void inline extract(Array2D &pixels, int x, int y) - { - for (int y0=0; y0 #include -#include static int denom7_weights_64[] = {0, 9, 18, 27, 37, 46, 55, 64}; // divided by 64 static int denom15_weights_64[] = {0, 4, 9, 13, 17, 21, 26, 30, 34, 38, 43, 47, 51, 55, 60, 64}; // divided by 64 int Utils::lerp(int a, int b, int i, int denom) { - assert (denom == 3 || denom == 7 || denom == 15); - assert (i >= 0 && i <= denom); + nvDebugCheck (denom == 3 || denom == 7 || denom == 15); + nvDebugCheck (i >= 0 && i <= denom); int round = 32, shift = 6, *weights; @@ -32,7 +30,7 @@ int Utils::lerp(int a, int b, int i, int denom) case 3: denom *= 5; i *= 5; // fall through to case 15 case 15: weights = denom15_weights_64; break; case 7: weights = denom7_weights_64; break; - default: assert(0); + default: nvDebugCheck(0); } return (a*weights[denom-i] +b*weights[i] + round) >> shift; @@ -40,8 +38,8 @@ int Utils::lerp(int a, int b, int i, int denom) Vector3 Utils::lerp(const Vector3& a, const Vector3 &b, int i, int denom) { - assert (denom == 3 || denom == 7 || denom == 15); - assert (i >= 0 && i <= denom); + nvDebugCheck (denom == 3 || denom == 7 || denom == 15); + nvDebugCheck (i >= 0 && i <= denom); int shift = 6, *weights; @@ -50,7 +48,7 @@ Vector3 Utils::lerp(const Vector3& a, const Vector3 &b, int i, int denom) case 3: denom *= 5; i *= 5; // fall through to case 15 case 15: weights = denom15_weights_64; break; case 7: weights = denom7_weights_64; break; - default: assert(0); + default: nvAssume(0); } // no need to round these as this is an exact division @@ -93,7 +91,7 @@ void Utils::clamp(Vector3 &v) break; default: - assert (0); + nvAssume (0); } } } @@ -132,12 +130,12 @@ unsigned short Utils::format_to_ushort(int input) switch (Utils::FORMAT) { case UNSIGNED_F16: - assert (input >= 0 && input <= F16MAX); + nvDebugCheck (input >= 0 && input <= F16MAX); out = input; break; case SIGNED_F16: - assert (input >= -F16MAX && input <= F16MAX); + nvDebugCheck (input >= -F16MAX && input <= F16MAX); // convert to sign-magnitude int s; if (input < 0) { s = F16S_MASK; input = -input; } @@ -153,7 +151,7 @@ int Utils::quantize(float value, int prec) { int q, ivalue, s; - assert (prec > 1); // didn't bother to make it work for 1 + nvDebugCheck (prec > 1); // didn't bother to make it work for 1 value = (float)floor(value + 0.5); @@ -162,14 +160,14 @@ int Utils::quantize(float value, int prec) switch (Utils::FORMAT) { case UNSIGNED_F16: - assert (value >= 0 && value <= F16MAX); + nvDebugCheck (value >= 0 && value <= F16MAX); ivalue = (int)value; q = ((ivalue << prec) + bias) / (F16MAX+1); - assert (q >= 0 && q < (1 << prec)); + nvDebugCheck (q >= 0 && q < (1 << prec)); break; case SIGNED_F16: - assert (value >= -F16MAX && value <= F16MAX); + nvDebugCheck (value >= -F16MAX && value <= F16MAX); // convert to sign-magnitude ivalue = (int)value; if (ivalue < 0) { s = 1; ivalue = -ivalue; } else s = 0; @@ -177,7 +175,7 @@ int Utils::quantize(float value, int prec) q = ((ivalue << (prec-1)) + bias) / (F16MAX+1); if (s) q = -q; - assert (q > -(1 << (prec-1)) && q < (1 << (prec-1))); + nvDebugCheck (q > -(1 << (prec-1)) && q < (1 << (prec-1))); break; } @@ -204,7 +202,7 @@ int Utils::unquantize(int q, int prec) { int unq, s; - assert (prec > 1); // not implemented for prec 1 + nvDebugCheck (prec > 1); // not implemented for prec 1 switch (Utils::FORMAT) { @@ -335,7 +333,7 @@ static void mpsnrmap(const Vector3 &in, int exposure, Vector3 &out) h = in.y; g = h; h = in.z; b = h; - assert (exposure > -32 && exposure < 32); + nvDebugCheck (exposure > -32 && exposure < 32); if (exposure > 0) { r *= 1 << exposure; @@ -419,13 +417,13 @@ void Utils::parse(const char *encoding, int &ptr, Field &field, int &endbit, int if (ptr <= 0) return; --ptr; if (encoding[ptr] == ',') --ptr; - assert (encoding[ptr] == ']'); + nvDebugCheck (encoding[ptr] == ']'); --ptr; endbit = 0; int scale = 1; while (encoding[ptr] != ':' && encoding[ptr] != '[') { - assert(encoding[ptr] >= '0' && encoding[ptr] <= '9'); + nvDebugCheck(encoding[ptr] >= '0' && encoding[ptr] <= '9'); endbit += (encoding[ptr--] - '0') * scale; scale *= 10; } @@ -437,7 +435,7 @@ void Utils::parse(const char *encoding, int &ptr, Field &field, int &endbit, int ptr--; while (encoding[ptr] != '[') { - assert(encoding[ptr] >= '0' && encoding[ptr] <= '9'); + nvDebugCheck(encoding[ptr] >= '0' && encoding[ptr] <= '9'); startbit += (encoding[ptr--] - '0') * scale; scale *= 10; } @@ -448,13 +446,13 @@ void Utils::parse(const char *encoding, int &ptr, Field &field, int &endbit, int else if (encoding[ptr] == 'd') field = FIELD_D; else { // it's wxyz - assert (encoding[ptr] >= 'w' && encoding[ptr] <= 'z'); + nvDebugCheck (encoding[ptr] >= 'w' && encoding[ptr] <= 'z'); int foo = encoding[ptr--] - 'w'; // now it is r g or b if (encoding[ptr] == 'r') foo += 10; else if (encoding[ptr] == 'g') foo += 20; else if (encoding[ptr] == 'b') foo += 30; - else assert(0); + else nvDebugCheck(0); field = (Field) foo; } } diff --git a/src/nvtt/bc6h/utils.h b/src/nvtt/bc6h/utils.h index 4b73937..9d276c9 100644 --- a/src/nvtt/bc6h/utils.h +++ b/src/nvtt/bc6h/utils.h @@ -70,4 +70,4 @@ public: static Vector3 lerp(const Vector3 & a, const Vector3 & b, int i, int denom); }; -#endif +#endif // _UTILS_H diff --git a/src/nvtt/bc6h/zoh.h b/src/nvtt/bc6h/zoh.h index e2169ff..0220706 100644 --- a/src/nvtt/bc6h/zoh.h +++ b/src/nvtt/bc6h/zoh.h @@ -9,16 +9,12 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. */ - +#pragma once #ifndef _ZOH_H #define _ZOH_H -//#include - #include "tile.h" -//using namespace std; - // UNUSED ZOH MODES are 0x13, 0x17, 0x1b, 0x1f #define EXTERNAL_RELEASE 1 // define this if we're releasing this code externally @@ -39,14 +35,14 @@ struct FltEndpts struct IntEndpts { - int A[NCHANNELS]; - int B[NCHANNELS]; + int A[NCHANNELS]; + int B[NCHANNELS]; }; struct ComprEndpts { - unsigned int A[NCHANNELS]; - unsigned int B[NCHANNELS]; + uint A[NCHANNELS]; + uint B[NCHANNELS]; }; class ZOH @@ -56,8 +52,6 @@ public: static const int BITSIZE=128; static Format FORMAT; - //static void compress(string inf, string zohf); - //static void decompress(string zohf, string outf); static void compress(const Tile &t, char *block); static void decompress(const char *block, Tile &t); @@ -75,4 +69,4 @@ public: static bool isone(const char *block); }; -#endif +#endif // _ZOH_H diff --git a/src/nvtt/bc6h/zohone.cpp b/src/nvtt/bc6h/zohone.cpp index 551ef44..183b763 100644 --- a/src/nvtt/bc6h/zohone.cpp +++ b/src/nvtt/bc6h/zohone.cpp @@ -20,7 +20,6 @@ See the License for the specific language governing permissions and limitations #include "nvmath/Fitting.h" -#include #include // strlen #include // FLT_MAX @@ -64,10 +63,10 @@ struct Pattern static Pattern patterns[NPATTERNS] = { - {{{16, 4}, {16, 4}, {16, 4}}, 1, 0x0f, 5, "bw[10],bw[11],bw[12],bw[13],bw[14],bw[15],bx[3:0],gw[10],gw[11],gw[12],gw[13],gw[14],gw[15],gx[3:0],rw[10],rw[11],rw[12],rw[13],rw[14],rw[15],rx[3:0],bw[9:0],gw[9:0],rw[9:0],m[4:0]"}, - {{{12, 8}, {12, 8}, {12, 8}}, 1, 0x0b, 5, "bw[10],bw[11],bx[7:0],gw[10],gw[11],gx[7:0],rw[10],rw[11],rx[7:0],bw[9:0],gw[9:0],rw[9:0],m[4:0]"}, - {{{11, 9}, {11, 9}, {11, 9}}, 1, 0x07, 5, "bw[10],bx[8:0],gw[10],gx[8:0],rw[10],rx[8:0],bw[9:0],gw[9:0],rw[9:0],m[4:0]"}, - {{{10,10}, {10,10}, {10,10}}, 0, 0x03, 5, "bx[9:0],gx[9:0],rx[9:0],bw[9:0],gw[9:0],rw[9:0],m[4:0]"}, + 16,4, 16,4, 16,4, 1, 0x0f, 5, "bw[10],bw[11],bw[12],bw[13],bw[14],bw[15],bx[3:0],gw[10],gw[11],gw[12],gw[13],gw[14],gw[15],gx[3:0],rw[10],rw[11],rw[12],rw[13],rw[14],rw[15],rx[3:0],bw[9:0],gw[9:0],rw[9:0],m[4:0]", + 12,8, 12,8, 12,8, 1, 0x0b, 5, "bw[10],bw[11],bx[7:0],gw[10],gw[11],gx[7:0],rw[10],rw[11],rx[7:0],bw[9:0],gw[9:0],rw[9:0],m[4:0]", + 11,9, 11,9, 11,9, 1, 0x07, 5, "bw[10],bx[8:0],gw[10],gx[8:0],rw[10],rx[8:0],bw[9:0],gw[9:0],rw[9:0],m[4:0]", + 10,10, 10,10, 10,10, 0, 0x03, 5, "bx[9:0],gx[9:0],rx[9:0],bw[9:0],gw[9:0],rw[9:0],m[4:0]", }; // mapping of mode to the corresponding index in pattern @@ -159,7 +158,7 @@ static void swap_indices(IntEndpts endpts[NREGIONS_ONE], int indices[Tile::TILE_ { int x = index_positions[region] & 3; int y = (index_positions[region] >> 2) & 3; - assert(REGION(x,y,shapeindex) == region); // double check the table + nvDebugCheck(REGION(x,y,shapeindex) == region); // double check the table if (indices[y][x] & HIGH_INDEXBIT) { // high bit is set, swap the endpts and indices for this region @@ -221,7 +220,7 @@ static void write_header(const ComprEndpts endpts[NREGIONS_ONE], const Pattern & case FIELD_GZ: case FIELD_BY: case FIELD_BZ: - default: assert(0); + default: nvAssume(0); } } } @@ -235,8 +234,8 @@ static void read_header(Bits &in, ComprEndpts endpts[NREGIONS_ONE], Pattern &p) int pat_index = mode_to_pat[mode]; - assert (pat_index >= 0 && pat_index < NPATTERNS); - assert (in.getptr() == patterns[pat_index].modebits); + nvDebugCheck (pat_index >= 0 && pat_index < NPATTERNS); + nvDebugCheck (in.getptr() == patterns[pat_index].modebits); p = patterns[pat_index]; @@ -276,11 +275,11 @@ static void read_header(Bits &in, ComprEndpts endpts[NREGIONS_ONE], Pattern &p) case FIELD_GZ: case FIELD_BY: case FIELD_BZ: - default: assert(0); + default: nvAssume(0); } } - assert (in.getptr() == 128 - 63); + nvDebugCheck (in.getptr() == 128 - 63); endpts[0].A[0] = rw; endpts[0].B[0] = rx; endpts[0].A[1] = gw; endpts[0].B[1] = gx; @@ -307,7 +306,7 @@ static void emit_block(const ComprEndpts endpts[NREGIONS_ONE], int shapeindex, c write_indices(indices, shapeindex, out); - assert(out.getptr() == ZOH::BITSIZE); + nvDebugCheck(out.getptr() == ZOH::BITSIZE); } static void generate_palette_quantized(const IntEndpts &endpts, int prec, Vector3 palette[NINDICES]) @@ -371,7 +370,7 @@ void ZOH::decompressone(const char *block, Tile &t) read_indices(in, shapeindex, indices); - assert(in.getptr() == ZOH::BITSIZE); + nvDebugCheck(in.getptr() == ZOH::BITSIZE); // lookup for (int y = 0; y < Tile::TILE_H; y++) @@ -627,7 +626,7 @@ double ZOH::refineone(const Tile &tile, int shapeindex_best, const FltEndpts end for (int sp = 0; sp < NPATTERNS; ++sp) { // precisions for all channels need to be the same - for (int i=1; i #include // strlen #include // FLT_MAX @@ -213,7 +212,7 @@ static void swap_indices(IntEndpts endpts[NREGIONS_TWO], int indices[Tile::TILE_ int x = POS_TO_X(position); int y = POS_TO_Y(position); - assert(REGION(x,y,shapeindex) == region); // double check the table + nvDebugCheck(REGION(x,y,shapeindex) == region); // double check the table if (indices[y][x] & HIGH_INDEXBIT) { // high bit is set, swap the endpts and indices for this region @@ -278,7 +277,7 @@ static void write_header(const ComprEndpts endpts[NREGIONS_TWO], int shapeindex, case FIELD_BX: out.write(bx >> endbit, len); break; case FIELD_BY: out.write(by >> endbit, len); break; case FIELD_BZ: out.write(bz >> endbit, len); break; - default: assert(0); + default: nvAssume(0); } } } @@ -295,8 +294,8 @@ static bool read_header(Bits &in, ComprEndpts endpts[NREGIONS_TWO], int &shapein if (pat_index == -2) return false; // reserved mode found - assert (pat_index >= 0 && pat_index < NPATTERNS); - assert (in.getptr() == patterns[pat_index].modebits); + nvDebugCheck (pat_index >= 0 && pat_index < NPATTERNS); + nvDebugCheck (in.getptr() == patterns[pat_index].modebits); p = patterns[pat_index]; @@ -335,11 +334,11 @@ static bool read_header(Bits &in, ComprEndpts endpts[NREGIONS_TWO], int &shapein case FIELD_BX: bx |= in.read(len) << endbit; break; case FIELD_BY: by |= in.read(len) << endbit; break; case FIELD_BZ: bz |= in.read(len) << endbit; break; - default: assert(0); + default: nvAssume(0); } } - assert (in.getptr() == 128 - 46); + nvDebugCheck (in.getptr() == 128 - 46); shapeindex = d; endpts[0].A[0] = rw; endpts[0].B[0] = rx; endpts[1].A[0] = ry; endpts[1].B[0] = rz; @@ -378,7 +377,7 @@ static void emit_block(const ComprEndpts compr_endpts[NREGIONS_TWO], int shapein write_indices(indices, shapeindex, out); - assert(out.getptr() == ZOH::BITSIZE); + nvDebugCheck(out.getptr() == ZOH::BITSIZE); } static void generate_palette_quantized(const IntEndpts &endpts, int prec, Vector3 palette[NINDICES]) @@ -458,7 +457,7 @@ void ZOH::decompresstwo(const char *block, Tile &t) read_indices(in, shapeindex, indices); - assert(in.getptr() == ZOH::BITSIZE); + nvDebugCheck(in.getptr() == ZOH::BITSIZE); // lookup for (int y = 0; y < Tile::TILE_H; y++) @@ -714,7 +713,7 @@ double ZOH::refinetwo(const Tile &tile, int shapeindex_best, const FltEndpts end for (int sp = 0; sp < NPATTERNS; ++sp) { // precisions for all channels need to be the same - for (int i=1; i