2012-11-15 17:51:55 +01:00
|
|
|
/* FasTC
|
2014-01-21 20:46:25 +01:00
|
|
|
* Copyright (c) 2014 University of North Carolina at Chapel Hill.
|
2013-08-26 22:11:39 +02:00
|
|
|
* All rights reserved.
|
2012-11-15 17:51:55 +01:00
|
|
|
*
|
2013-08-26 22:11:39 +02:00
|
|
|
* Permission to use, copy, modify, and distribute this software and its
|
|
|
|
* documentation for educational, research, and non-profit purposes, without
|
|
|
|
* fee, and without a written agreement is hereby granted, provided that the
|
|
|
|
* above copyright notice, this paragraph, and the following four paragraphs
|
|
|
|
* appear in all copies.
|
2012-11-15 17:51:55 +01:00
|
|
|
*
|
2013-08-26 22:11:39 +02:00
|
|
|
* Permission to incorporate this software into commercial products may be
|
|
|
|
* obtained by contacting the authors or the Office of Technology Development
|
|
|
|
* at the University of North Carolina at Chapel Hill <otd@unc.edu>.
|
2012-11-15 17:51:55 +01:00
|
|
|
*
|
2013-08-26 22:11:39 +02:00
|
|
|
* This software program and documentation are copyrighted by the University of
|
|
|
|
* North Carolina at Chapel Hill. The software program and documentation are
|
|
|
|
* supplied "as is," without any accompanying services from the University of
|
|
|
|
* North Carolina at Chapel Hill or the authors. The University of North
|
|
|
|
* Carolina at Chapel Hill and the authors do not warrant that the operation of
|
|
|
|
* the program will be uninterrupted or error-free. The end-user understands
|
|
|
|
* that the program was developed for research purposes and is advised not to
|
|
|
|
* rely exclusively on the program for any reason.
|
2012-11-15 17:51:55 +01:00
|
|
|
*
|
2013-08-26 22:11:39 +02:00
|
|
|
* IN NO EVENT SHALL THE UNIVERSITY OF NORTH CAROLINA AT CHAPEL HILL OR THE
|
|
|
|
* AUTHORS BE LIABLE TO ANY PARTY FOR DIRECT, INDIRECT, SPECIAL, INCIDENTAL,
|
|
|
|
* OR CONSEQUENTIAL DAMAGES, INCLUDING LOST PROFITS, ARISING OUT OF THE USE OF
|
|
|
|
* THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF THE UNIVERSITY OF NORTH CAROLINA
|
|
|
|
* AT CHAPEL HILL OR THE AUTHORS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH
|
|
|
|
* DAMAGE.
|
2012-11-15 17:51:55 +01:00
|
|
|
*
|
2013-08-26 22:11:39 +02:00
|
|
|
* THE UNIVERSITY OF NORTH CAROLINA AT CHAPEL HILL AND THE AUTHORS SPECIFICALLY
|
|
|
|
* DISCLAIM ANY WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
|
|
|
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE AND ANY
|
|
|
|
* STATUTORY WARRANTY OF NON-INFRINGEMENT. THE SOFTWARE PROVIDED HEREUNDER IS ON
|
|
|
|
* AN "AS IS" BASIS, AND THE UNIVERSITY OF NORTH CAROLINA AT CHAPEL HILL AND
|
|
|
|
* THE AUTHORS HAVE NO OBLIGATIONS TO PROVIDE MAINTENANCE, SUPPORT, UPDATES,
|
2012-11-15 17:51:55 +01:00
|
|
|
* ENHANCEMENTS, OR MODIFICATIONS.
|
|
|
|
*
|
|
|
|
* Please send all BUG REPORTS to <pavel@cs.unc.edu>.
|
|
|
|
*
|
|
|
|
* The authors may be contacted via:
|
|
|
|
*
|
|
|
|
* Pavel Krajcevski
|
|
|
|
* Dept of Computer Science
|
|
|
|
* 201 S Columbia St
|
|
|
|
* Frederick P. Brooks, Jr. Computer Science Bldg
|
|
|
|
* Chapel Hill, NC 27599-3175
|
|
|
|
* USA
|
|
|
|
*
|
|
|
|
* <http://gamma.cs.unc.edu/FasTC/>
|
|
|
|
*/
|
|
|
|
|
|
|
|
// The original lisence from the code available at the following location:
|
|
|
|
// http://software.intel.com/en-us/vcsource/samples/fast-texture-compression
|
|
|
|
//
|
|
|
|
// This code has been modified significantly from the original.
|
|
|
|
|
2013-08-26 22:11:39 +02:00
|
|
|
//------------------------------------------------------------------------------
|
2012-08-24 21:56:45 +02:00
|
|
|
// Copyright 2011 Intel Corporation
|
|
|
|
// All Rights Reserved
|
|
|
|
//
|
2013-08-26 22:11:39 +02:00
|
|
|
// Permission is granted to use, copy, distribute and prepare derivative works
|
|
|
|
// of this software for any purpose and without fee, provided, that the above
|
|
|
|
// copyright notice and this statement appear in all copies. Intel makes no
|
|
|
|
// representations about the suitability of this software for any purpose. THIS
|
|
|
|
// SOFTWARE IS PROVIDED "AS IS." INTEL SPECIFICALLY DISCLAIMS ALL WARRANTIES,
|
|
|
|
// EXPRESS OR IMPLIED, AND ALL LIABILITY, INCLUDING CONSEQUENTIAL AND OTHER
|
|
|
|
// INDIRECT DAMAGES, FOR THE USE OF THIS SOFTWARE, INCLUDING LIABILITY FOR
|
|
|
|
// INFRINGEMENT OF ANY PROPRIETARY RIGHTS, AND INCLUDING THE WARRANTIES OF
|
|
|
|
// MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. Intel does not assume
|
|
|
|
// any responsibility for any errors which may appear in this software nor any
|
2012-08-24 21:56:45 +02:00
|
|
|
// responsibility to update it.
|
|
|
|
//
|
2013-08-26 22:11:39 +02:00
|
|
|
//------------------------------------------------------------------------------
|
|
|
|
|
2014-01-21 20:46:25 +01:00
|
|
|
#ifndef BPTCENCODER_INCLUDE_BPTCCOMPRESSOR_H_
|
|
|
|
#define BPTCENCODER_INCLUDE_BPTCCOMPRESSOR_H_
|
2012-08-24 21:56:45 +02:00
|
|
|
|
2014-01-21 20:46:25 +01:00
|
|
|
#include "BPTCConfig.h"
|
2013-03-09 19:34:10 +01:00
|
|
|
#include "CompressionJob.h"
|
2012-09-13 23:43:58 +02:00
|
|
|
|
2013-09-14 01:36:37 +02:00
|
|
|
#include <iosfwd>
|
2012-10-07 04:25:49 +02:00
|
|
|
|
2014-01-21 20:46:25 +01:00
|
|
|
namespace BPTCC {
|
2014-03-21 17:45:47 +01:00
|
|
|
// The various available block modes that a BPTC compressor can choose from.
|
|
|
|
// The enum is specialized to be power-of-two values so that an EBlockMode
|
|
|
|
// variable can be used as a bit mask.
|
|
|
|
enum EBlockMode {
|
|
|
|
eBlockMode_Zero = 0,
|
|
|
|
eBlockMode_One = 1,
|
|
|
|
eBlockMode_Two = 2,
|
|
|
|
eBlockMode_Three = 4,
|
|
|
|
eBlockMode_Four = 8,
|
|
|
|
eBlockMode_Five = 16,
|
|
|
|
eBlockMode_Six = 32,
|
|
|
|
eBlockMode_Seven = 64
|
|
|
|
};
|
|
|
|
|
|
|
|
// A shape selection can influence the results of the compressor by choosing
|
|
|
|
// different modes to compress or not compress. The shape index is a value
|
|
|
|
// between zero and sixty-four that corresponds to one of the available
|
|
|
|
// partitioning schemes defined by the BPTC format.
|
|
|
|
struct ShapeSelection {
|
|
|
|
// This is the shape index to use when evaluating two-partition shapes.
|
|
|
|
uint32 m_TwoShapeIndex;
|
|
|
|
|
|
|
|
// This is the shape index to use when evaluating three-partition shapes.
|
|
|
|
uint32 m_ThreeShapeIndex;
|
|
|
|
|
|
|
|
// This is the additional mask to prevent modes once shape selection
|
|
|
|
// is done. This value is &-ed with m_BlockModes from CompressionSettings
|
|
|
|
// to determine what the final considered blocks are.
|
|
|
|
EBlockMode m_AdditionalModes;
|
|
|
|
};
|
|
|
|
|
|
|
|
// A shape selection function is one that selects a BPTC shape from a given
|
|
|
|
// block position and pixel array.
|
|
|
|
typedef ShapeSelection
|
|
|
|
(*ShapeSelectionFn)(uint32 x, uint32 y, uint32 pixels[16]);
|
|
|
|
|
|
|
|
// Compression parameters used to control the BPTC compressor. Each of the
|
|
|
|
// values has a default, so this is not strictly required to perform
|
|
|
|
// compression, but some aspects of the compressor can be user-defined or
|
|
|
|
// overridden.
|
|
|
|
struct CompressionSettings {
|
|
|
|
// The shape selection function to use during compression. The default (when
|
|
|
|
// this variable is set to NULL) is to use the diagonal of the axis-aligned
|
|
|
|
// bounding box of every partition to estimate the error using that
|
|
|
|
// partition would accrue. The shape with the least error is then chosen.
|
|
|
|
// This procedure is done for both two and three partition shapes, and then
|
|
|
|
// every block mode is still available.
|
|
|
|
ShapeSelectionFn m_ShapeSelectionFn;
|
|
|
|
|
|
|
|
// The block modes that the compressor will consider during compression.
|
|
|
|
// This variable is a bit mask of EBlockMode values and by default contains
|
|
|
|
// every mode. This setting can be used to further restrict the search space
|
|
|
|
// and increase compression times.
|
|
|
|
EBlockMode m_BlockModes;
|
|
|
|
|
|
|
|
CompressionSettings()
|
|
|
|
: m_ShapeSelectionFn(NULL)
|
|
|
|
, m_BlockModes(static_cast<EBlockMode>((1 << 7) - 1))
|
|
|
|
{ }
|
|
|
|
};
|
|
|
|
|
2013-03-21 04:30:23 +01:00
|
|
|
// This is the error metric that is applied to our error measurement algorithm
|
2013-08-26 22:11:39 +02:00
|
|
|
// in order to bias calculation towards results that are more in-line with
|
|
|
|
// how the Human Visual System works. Uniform error means that each color
|
|
|
|
// channel is treated equally. For a while, the widely accepted non-uniform
|
|
|
|
// metric has been to give red 30%, green 59% and blue 11% weight when
|
|
|
|
// computing the error between two pixels.
|
|
|
|
enum ErrorMetric {
|
|
|
|
eErrorMetric_Uniform, // Treats r, g, and b channels equally
|
|
|
|
eErrorMetric_Nonuniform, // { 0.3, 0.59, 0.11 }
|
|
|
|
|
2013-03-21 04:30:23 +01:00
|
|
|
kNumErrorMetrics
|
|
|
|
};
|
2012-08-24 21:56:45 +02:00
|
|
|
|
2013-03-21 04:30:23 +01:00
|
|
|
// Sets the error metric to be the one specified.
|
|
|
|
void SetErrorMetric(ErrorMetric e);
|
2012-08-24 21:56:45 +02:00
|
|
|
|
2013-08-26 22:11:39 +02:00
|
|
|
// Retreives a float4 pointer for the r, g, b, a weights for each color
|
|
|
|
// channel, in that order, based on the current error metric.
|
2013-03-21 04:30:23 +01:00
|
|
|
const float *GetErrorMetric();
|
2012-08-24 21:56:45 +02:00
|
|
|
|
2013-03-21 04:30:23 +01:00
|
|
|
// Returns the enumeration for the current error metric.
|
|
|
|
ErrorMetric GetErrorMetricEnum();
|
2012-08-24 21:56:45 +02:00
|
|
|
|
2013-08-26 22:11:39 +02:00
|
|
|
// Sets the number of steps that we use to perform simulated annealing. In
|
|
|
|
// general, a larger number produces better results. The default is set to 50.
|
|
|
|
// This metric works on a logarithmic scale -- twice the value will double the
|
|
|
|
// compute time, but only decrease the error by two times a factor.
|
2013-03-21 04:30:23 +01:00
|
|
|
void SetQualityLevel(int q);
|
|
|
|
int GetQualityLevel();
|
2012-08-24 21:56:45 +02:00
|
|
|
|
2014-01-21 20:46:25 +01:00
|
|
|
// Compress the image given as RGBA data to BPTC format. Width and Height are
|
2013-08-26 22:11:39 +02:00
|
|
|
// the dimensions of the image in pixels.
|
2014-03-21 17:45:47 +01:00
|
|
|
void Compress(const FasTC::CompressionJob &,
|
|
|
|
CompressionSettings settings = CompressionSettings());
|
2013-02-06 03:54:06 +01:00
|
|
|
|
2013-08-26 22:11:39 +02:00
|
|
|
// Perform a compression while recording all of the choices the compressor
|
|
|
|
// made into a list of statistics. We can use this to see whether or not
|
|
|
|
// certain heuristics are working, such as whether or not certain modes are
|
|
|
|
// being chosen more often than others, etc.
|
2014-03-21 17:45:47 +01:00
|
|
|
void CompressWithStats(const FasTC::CompressionJob &, std::ostream *logStream,
|
|
|
|
CompressionSettings settings = CompressionSettings());
|
2012-08-24 21:56:45 +02:00
|
|
|
|
2012-09-13 23:43:58 +02:00
|
|
|
#ifdef HAS_SSE_41
|
2014-01-21 20:46:25 +01:00
|
|
|
// Compress the image given as RGBA data to BPTC format using an algorithm
|
2013-08-26 22:11:39 +02:00
|
|
|
// optimized for SIMD enabled platforms. Width and Height are the dimensions
|
|
|
|
// of the image in pixels.
|
2014-01-21 20:46:25 +01:00
|
|
|
void CompressImageBPTCSIMD(const unsigned char* inBuf, unsigned char* outBuf,
|
2013-08-26 22:11:39 +02:00
|
|
|
unsigned int width, unsigned int height);
|
2012-09-13 23:43:58 +02:00
|
|
|
#endif
|
2012-08-24 21:56:45 +02:00
|
|
|
|
2013-03-07 00:47:15 +01:00
|
|
|
#ifdef HAS_ATOMICS
|
2013-08-26 22:11:39 +02:00
|
|
|
// This is a threadsafe version of the compression function that is designed
|
|
|
|
// to compress a list of textures. If this function is called with the same
|
|
|
|
// argument from multiple threads, they will work together to compress all of
|
|
|
|
// the images in the list.
|
2013-11-08 22:21:01 +01:00
|
|
|
void CompressAtomic(FasTC::CompressionJobList &);
|
2013-03-07 00:47:15 +01:00
|
|
|
#endif
|
|
|
|
|
2014-01-21 20:46:25 +01:00
|
|
|
#ifdef FOUND_NVTT_BPTC_EXPORT
|
2013-11-19 18:03:03 +01:00
|
|
|
// These functions take the same arguments as Compress and CompressWithStats,
|
|
|
|
// but they use the NVTT compressor if it was supplied to CMake.
|
|
|
|
void CompressNVTT(const FasTC::CompressionJob &);
|
|
|
|
void CompressNVTTWithStats(const FasTC::CompressionJob &,
|
|
|
|
std::ostream *logStream);
|
|
|
|
#endif
|
|
|
|
|
2014-03-21 17:45:47 +01:00
|
|
|
// Decompress the image given as BPTC data to R8G8B8A8 format.
|
2013-11-08 22:21:01 +01:00
|
|
|
void Decompress(const FasTC::DecompressionJob &);
|
2014-01-21 20:46:25 +01:00
|
|
|
} // namespace BPTCC
|
2013-08-26 22:11:39 +02:00
|
|
|
|
2014-01-21 20:46:25 +01:00
|
|
|
#endif // BPTCENCODER_INCLUDE_BPTCCOMPRESSOR_H_
|