nvidia-texture-tools/src/nvtt/bc6h/tile.h
nathaniel.reed@gmail.com 474239c784 Add BC6 support to nvtt lib and utils.
- Use 3x3 eigensolver for initial fit in ZOH.  Slightly better perf and RMSE than power method.
- Remove use of double precision in ZOH - speeds up by 12%.
- Fixed RGBM encoding that was broken for HDR images.
- Use gamma-2.0 space for RGBM for HDR images (improves precision in darks).
- Use UNORM instead of TYPELESS formats when saving a DX10 .dds file.  The TYPELESS formats break most viewers.
- Cleaned up warnings in ZOH code.
- Command-line utils will warn if you give them an unrecognized parameter.
- Added VS2010 profiling results.
2013-10-25 17:30:55 +00:00

83 lines
2.3 KiB
C++

/*
Copyright 2007 nVidia, Inc.
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License.
You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS,
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 "utils.h"
#include "nvmath/Vector.h"
#include <math.h>
//#define USE_IMPORTANCE_MAP 1 // define this if you want to increase importance of some pixels in tile
class Tile
{
public:
// NOTE: this returns the appropriately-clamped BIT PATTERN of the half as an INTEGRAL float value
static float half2float(uint16 h)
{
return (float) Utils::ushort_to_format(h);
}
// NOTE: this is the inverse of the above operation
static uint16 float2half(float f)
{
return Utils::format_to_ushort((int)f);
}
// look for adjacent pixels that are identical. if there are enough of them, increase their importance
void generate_importance_map()
{
// initialize
for (int y=0; y<size_y; ++y)
for (int x=0; x<size_x; ++x)
{
// my importance is increased if I am identical to any of my 4-neighbors
importance_map[y][x] = match_4_neighbor(x,y) ? 5.0f : 1.0f;
}
}
bool is_equal(int x, int y, int xn, int yn)
{
if (xn < 0 || xn >= size_x || yn < 0 || yn >= size_y)
return false;
return( (data[y][x].x == data[yn][xn].x) &&
(data[y][x].y == data[yn][xn].y) &&
(data[y][x].z == data[yn][xn].z) );
}
#ifdef USE_IMPORTANCE_MAP
bool match_4_neighbor(int x, int y)
{
return is_equal(x,y,x-1,y) || is_equal(x,y,x+1,y) || is_equal(x,y,x,y-1) || is_equal(x,y,x,y+1);
}
#else
bool match_4_neighbor(int x, int y)
{
return false;
}
#endif
Tile() {};
~Tile(){};
Tile(int xs, int ys) {size_x = xs; size_y = ys;}
static const int TILE_H = 4;
static const int TILE_W = 4;
static const int TILE_TOTAL = TILE_H * TILE_W;
nv::Vector3 data[TILE_H][TILE_W];
float importance_map[TILE_H][TILE_W];
int size_x, size_y; // actual size of tile
};
#endif // _TILE_H