diff options
| author | Jørgen P. Tjernø <[email protected]> | 2013-12-02 19:31:46 -0800 |
|---|---|---|
| committer | Jørgen P. Tjernø <[email protected]> | 2013-12-02 19:46:31 -0800 |
| commit | f56bb35301836e56582a575a75864392a0177875 (patch) | |
| tree | de61ddd39de3e7df52759711950b4c288592f0dc /mp/src/public/mathlib/quantize.h | |
| parent | Mark some more files as text. (diff) | |
| download | source-sdk-2013-f56bb35301836e56582a575a75864392a0177875.tar.xz source-sdk-2013-f56bb35301836e56582a575a75864392a0177875.zip | |
Fix line endings. WHAMMY.
Diffstat (limited to 'mp/src/public/mathlib/quantize.h')
| -rw-r--r-- | mp/src/public/mathlib/quantize.h | 282 |
1 files changed, 141 insertions, 141 deletions
diff --git a/mp/src/public/mathlib/quantize.h b/mp/src/public/mathlib/quantize.h index c43b1530..5e5b7423 100644 --- a/mp/src/public/mathlib/quantize.h +++ b/mp/src/public/mathlib/quantize.h @@ -1,141 +1,141 @@ -//========= Copyright Valve Corporation, All rights reserved. ============//
-//
-// Purpose:
-//
-// $NoKeywords: $
-//
-//=============================================================================//
-#ifndef QUANTIZE_H
-#define QUANTIZE_H
-
-#ifndef STRING_H
-#include <string.h>
-#endif
-
-#define MAXDIMS 768
-#define MAXQUANT 16000
-
-
-#include <tier0/platform.h>
-
-struct Sample;
-
-struct QuantizedValue {
- double MinError; // minimum possible error. used
- // for neighbor searches.
- struct QuantizedValue *Children[2]; // splits
- int32 value; // only exists for leaf nodes
- struct Sample *Samples; // every sample quantized into this
- // entry
- int32 NSamples; // how many were quantized to this.
- int32 TotSamples;
- double *ErrorMeasure; // variance measure for each dimension
- double TotalError; // sum of errors
- uint8 *Mean; // average value of each dimension
- uint8 *Mins; // min box for children and this
- uint8 *Maxs; // max box for children and this
- int NQuant; // the number of samples which were
- // quantzied to this node since the
- // last time OptimizeQuantizer()
- // was called.
- int *Sums; // sum used by OptimizeQuantizer
- int sortdim; // dimension currently sorted along.
-};
-
-struct Sample {
- int32 ID; // identifier of this sample. can
- // be used for any purpose.
- int32 Count; // number of samples this sample
- // represents
- int32 QNum; // what value this sample ended up quantized
- // to.
- struct QuantizedValue *qptr; // ptr to what this was quantized to.
- uint8 Value[1]; // array of values for multi-dimensional
- // variables.
-};
-
-void FreeQuantization(struct QuantizedValue *t);
-
-struct QuantizedValue *Quantize(struct Sample *s, int nsamples, int ndims,
- int nvalues, uint8 *weights, int value0=0);
-
-int CompressSamples(struct Sample *s, int nsamples, int ndims);
-
-struct QuantizedValue *FindMatch(uint8 const *sample,
- int ndims,uint8 *weights,
- struct QuantizedValue *QTable);
-void PrintSamples(struct Sample const *s, int nsamples, int ndims);
-
-struct QuantizedValue *FindQNode(struct QuantizedValue const *q, int32 code);
-
-inline struct Sample *NthSample(struct Sample *s, int i, int nd)
-{
- uint8 *r=(uint8 *) s;
- r+=i*(sizeof(*s)+(nd-1));
- return (struct Sample *) r;
-}
-
-inline struct Sample *AllocSamples(int ns, int nd)
-{
- size_t size5=(sizeof(struct Sample)+(nd-1))*ns;
- void *ret=new uint8[size5];
- memset(ret,0,size5);
- for(int i=0;i<ns;i++)
- NthSample((struct Sample *)ret,i,nd)->Count=1;
- return (struct Sample *) ret;
-}
-
-
-// MinimumError: what is the min error which will occur if quantizing
-// a sample to the given qnode? This is just the error if the qnode
-// is a leaf.
-double MinimumError(struct QuantizedValue const *q, uint8 const *sample,
- int ndims, uint8 const *weights);
-double MaximumError(struct QuantizedValue const *q, uint8 const *sample,
- int ndims, uint8 const *weights);
-
-void PrintQTree(struct QuantizedValue const *p,int idlevel=0);
-void OptimizeQuantizer(struct QuantizedValue *q, int ndims);
-
-// RecalculateVelues: update the means in a sample tree, based upon
-// the samples. can be used to reoptimize when samples are deleted,
-// for instance.
-
-void RecalculateValues(struct QuantizedValue *q, int ndims);
-
-extern double SquaredError; // may be reset and examined. updated by
- // FindMatch()
-
-
-
-
-// the routines below can be used for uniform quantization via dart-throwing.
-typedef void (*GENERATOR)(void *); // generate a random sample
-typedef double (*COMPARER)(void const *a, void const *b);
-
-void *DartThrow(int NResults, int NTries, size_t itemsize, GENERATOR gen,
- COMPARER cmp);
-void *FindClosestDart(void *items,int NResults, size_t itemsize,
- COMPARER cmp, void *lookfor, int *idx);
-
-
-
-
-// color quantization of 24 bit images
-#define QUANTFLAGS_NODITHER 1 // don't do Floyd-steinberg dither
-
-extern void ColorQuantize(
-uint8 const *pImage, // 4 byte pixels ARGB
-int nWidth,
-int nHeight,
-int nFlags, // QUANTFLAGS_xxx
-int nColors, // # of colors to fill in in palette
-uint8 *pOutPixels, // where to store resulting 8 bit pixels
-uint8 *pOutPalette, // where to store resulting 768-byte palette
-int nFirstColor); // first color to use in mapping
-
-
-
-
-
-#endif
+//========= Copyright Valve Corporation, All rights reserved. ============// +// +// Purpose: +// +// $NoKeywords: $ +// +//=============================================================================// +#ifndef QUANTIZE_H +#define QUANTIZE_H + +#ifndef STRING_H +#include <string.h> +#endif + +#define MAXDIMS 768 +#define MAXQUANT 16000 + + +#include <tier0/platform.h> + +struct Sample; + +struct QuantizedValue { + double MinError; // minimum possible error. used + // for neighbor searches. + struct QuantizedValue *Children[2]; // splits + int32 value; // only exists for leaf nodes + struct Sample *Samples; // every sample quantized into this + // entry + int32 NSamples; // how many were quantized to this. + int32 TotSamples; + double *ErrorMeasure; // variance measure for each dimension + double TotalError; // sum of errors + uint8 *Mean; // average value of each dimension + uint8 *Mins; // min box for children and this + uint8 *Maxs; // max box for children and this + int NQuant; // the number of samples which were + // quantzied to this node since the + // last time OptimizeQuantizer() + // was called. + int *Sums; // sum used by OptimizeQuantizer + int sortdim; // dimension currently sorted along. +}; + +struct Sample { + int32 ID; // identifier of this sample. can + // be used for any purpose. + int32 Count; // number of samples this sample + // represents + int32 QNum; // what value this sample ended up quantized + // to. + struct QuantizedValue *qptr; // ptr to what this was quantized to. + uint8 Value[1]; // array of values for multi-dimensional + // variables. +}; + +void FreeQuantization(struct QuantizedValue *t); + +struct QuantizedValue *Quantize(struct Sample *s, int nsamples, int ndims, + int nvalues, uint8 *weights, int value0=0); + +int CompressSamples(struct Sample *s, int nsamples, int ndims); + +struct QuantizedValue *FindMatch(uint8 const *sample, + int ndims,uint8 *weights, + struct QuantizedValue *QTable); +void PrintSamples(struct Sample const *s, int nsamples, int ndims); + +struct QuantizedValue *FindQNode(struct QuantizedValue const *q, int32 code); + +inline struct Sample *NthSample(struct Sample *s, int i, int nd) +{ + uint8 *r=(uint8 *) s; + r+=i*(sizeof(*s)+(nd-1)); + return (struct Sample *) r; +} + +inline struct Sample *AllocSamples(int ns, int nd) +{ + size_t size5=(sizeof(struct Sample)+(nd-1))*ns; + void *ret=new uint8[size5]; + memset(ret,0,size5); + for(int i=0;i<ns;i++) + NthSample((struct Sample *)ret,i,nd)->Count=1; + return (struct Sample *) ret; +} + + +// MinimumError: what is the min error which will occur if quantizing +// a sample to the given qnode? This is just the error if the qnode +// is a leaf. +double MinimumError(struct QuantizedValue const *q, uint8 const *sample, + int ndims, uint8 const *weights); +double MaximumError(struct QuantizedValue const *q, uint8 const *sample, + int ndims, uint8 const *weights); + +void PrintQTree(struct QuantizedValue const *p,int idlevel=0); +void OptimizeQuantizer(struct QuantizedValue *q, int ndims); + +// RecalculateVelues: update the means in a sample tree, based upon +// the samples. can be used to reoptimize when samples are deleted, +// for instance. + +void RecalculateValues(struct QuantizedValue *q, int ndims); + +extern double SquaredError; // may be reset and examined. updated by + // FindMatch() + + + + +// the routines below can be used for uniform quantization via dart-throwing. +typedef void (*GENERATOR)(void *); // generate a random sample +typedef double (*COMPARER)(void const *a, void const *b); + +void *DartThrow(int NResults, int NTries, size_t itemsize, GENERATOR gen, + COMPARER cmp); +void *FindClosestDart(void *items,int NResults, size_t itemsize, + COMPARER cmp, void *lookfor, int *idx); + + + + +// color quantization of 24 bit images +#define QUANTFLAGS_NODITHER 1 // don't do Floyd-steinberg dither + +extern void ColorQuantize( +uint8 const *pImage, // 4 byte pixels ARGB +int nWidth, +int nHeight, +int nFlags, // QUANTFLAGS_xxx +int nColors, // # of colors to fill in in palette +uint8 *pOutPixels, // where to store resulting 8 bit pixels +uint8 *pOutPalette, // where to store resulting 768-byte palette +int nFirstColor); // first color to use in mapping + + + + + +#endif |