gfx/qcms/transform_util.h

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/gfx/qcms/transform_util.h	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,93 @@
     1.4 +/* vim: set ts=8 sw=8 noexpandtab: */
     1.5 +//  qcms
     1.6 +//  Copyright (C) 2009 Mozilla Foundation
     1.7 +//  Copyright (C) 1998-2007 Marti Maria
     1.8 +//
     1.9 +// Permission is hereby granted, free of charge, to any person obtaining 
    1.10 +// a copy of this software and associated documentation files (the "Software"), 
    1.11 +// to deal in the Software without restriction, including without limitation 
    1.12 +// the rights to use, copy, modify, merge, publish, distribute, sublicense, 
    1.13 +// and/or sell copies of the Software, and to permit persons to whom the Software 
    1.14 +// is furnished to do so, subject to the following conditions:
    1.15 +//
    1.16 +// The above copyright notice and this permission notice shall be included in 
    1.17 +// all copies or substantial portions of the Software.
    1.18 +//
    1.19 +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 
    1.20 +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO 
    1.21 +// THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 
    1.22 +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 
    1.23 +// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 
    1.24 +// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 
    1.25 +// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
    1.26 +
    1.27 +#ifndef _QCMS_TRANSFORM_UTIL_H
    1.28 +#define _QCMS_TRANSFORM_UTIL_H
    1.29 +
    1.30 +#include <stdlib.h>
    1.31 +
    1.32 +#define CLU(table,x,y,z) table[(x*len + y*x_len + z*xy_len)*3]
    1.33 +
    1.34 +//XXX: could use a bettername
    1.35 +typedef uint16_t uint16_fract_t;
    1.36 +
    1.37 +float lut_interp_linear(double value, uint16_t *table, int length);
    1.38 +float lut_interp_linear_float(float value, float *table, int length);
    1.39 +uint16_t lut_interp_linear16(uint16_t input_value, uint16_t *table, int length);
    1.40 +
    1.41 +
    1.42 +static inline float lerp(float a, float b, float t)
    1.43 +{
    1.44 +        return a*(1.f-t) + b*t;
    1.45 +}
    1.46 +
    1.47 +static inline unsigned char clamp_u8(float v)
    1.48 +{
    1.49 +  if (v > 255.)
    1.50 +    return 255;
    1.51 +  else if (v < 0)
    1.52 +    return 0;
    1.53 +  else
    1.54 +    return floorf(v+.5);
    1.55 +}
    1.56 +
    1.57 +static inline float clamp_float(float a)
    1.58 +{
    1.59 +  /* One would naturally write this function as the following:
    1.60 +  if (a > 1.)
    1.61 +    return 1.;
    1.62 +  else if (a < 0)
    1.63 +    return 0;
    1.64 +  else
    1.65 +    return a;
    1.66 +
    1.67 +  However, that version will let NaNs pass through which is undesirable
    1.68 +  for most consumers.
    1.69 +  */
    1.70 +
    1.71 +  if (a > 1.)
    1.72 +    return 1.;
    1.73 +  else if (a >= 0)
    1.74 +    return a;
    1.75 +  else // a < 0 or a is NaN
    1.76 +    return 0;
    1.77 +}
    1.78 +
    1.79 +static inline float u8Fixed8Number_to_float(uint16_t x)
    1.80 +{
    1.81 +  // 0x0000 = 0.
    1.82 +  // 0x0100 = 1.
    1.83 +  // 0xffff = 255  + 255/256
    1.84 +  return x/256.;
    1.85 +}
    1.86 +
    1.87 +float *build_input_gamma_table(struct curveType *TRC);
    1.88 +struct matrix build_colorant_matrix(qcms_profile *p);
    1.89 +void build_output_lut(struct curveType *trc,
    1.90 +                      uint16_t **output_gamma_lut, size_t *output_gamma_lut_length);
    1.91 +
    1.92 +struct matrix matrix_invert(struct matrix mat);
    1.93 +qcms_bool compute_precache(struct curveType *trc, uint8_t *output);
    1.94 +
    1.95 +
    1.96 +#endif

mercurial