Subversion Repositories shark

Rev

Rev 57 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
57 pj 1
/* $Id: s_histogram.c,v 1.1 2003-02-28 11:49:42 pj Exp $ */
2
 
3
/*
4
 * Mesa 3-D graphics library
5
 * Version:  3.5
6
 *
7
 * Copyright (C) 1999-2001  Brian Paul   All Rights Reserved.
8
 *
9
 * Permission is hereby granted, free of charge, to any person obtaining a
10
 * copy of this software and associated documentation files (the "Software"),
11
 * to deal in the Software without restriction, including without limitation
12
 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
13
 * and/or sell copies of the Software, and to permit persons to whom the
14
 * Software is furnished to do so, subject to the following conditions:
15
 *
16
 * The above copyright notice and this permission notice shall be included
17
 * in all copies or substantial portions of the Software.
18
 *
19
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
20
 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
22
 * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
23
 * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
24
 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
25
 */
26
 
27
 
28
#include "glheader.h"
29
#include "colormac.h"
30
#include "image.h"
31
#include "mmath.h"
32
 
33
#include "s_context.h"
34
#include "s_histogram.h"
35
#include "s_span.h"
36
 
37
 
38
 
39
/*
40
 * Update the min/max values from an array of fragment colors.
41
 */
42
void
43
_mesa_update_minmax(GLcontext *ctx, GLuint n, const GLfloat rgba[][4])
44
{
45
   GLuint i;
46
   for (i = 0; i < n; i++) {
47
      /* update mins */
48
      if (rgba[i][RCOMP] < ctx->MinMax.Min[RCOMP])
49
         ctx->MinMax.Min[RCOMP] = rgba[i][RCOMP];
50
      if (rgba[i][GCOMP] < ctx->MinMax.Min[GCOMP])
51
         ctx->MinMax.Min[GCOMP] = rgba[i][GCOMP];
52
      if (rgba[i][BCOMP] < ctx->MinMax.Min[BCOMP])
53
         ctx->MinMax.Min[BCOMP] = rgba[i][BCOMP];
54
      if (rgba[i][ACOMP] < ctx->MinMax.Min[ACOMP])
55
         ctx->MinMax.Min[ACOMP] = rgba[i][ACOMP];
56
 
57
      /* update maxs */
58
      if (rgba[i][RCOMP] > ctx->MinMax.Max[RCOMP])
59
         ctx->MinMax.Max[RCOMP] = rgba[i][RCOMP];
60
      if (rgba[i][GCOMP] > ctx->MinMax.Max[GCOMP])
61
         ctx->MinMax.Max[GCOMP] = rgba[i][GCOMP];
62
      if (rgba[i][BCOMP] > ctx->MinMax.Max[BCOMP])
63
         ctx->MinMax.Max[BCOMP] = rgba[i][BCOMP];
64
      if (rgba[i][ACOMP] > ctx->MinMax.Max[ACOMP])
65
         ctx->MinMax.Max[ACOMP] = rgba[i][ACOMP];
66
   }
67
}
68
 
69
 
70
/*
71
 * Update the histogram values from an array of fragment colors.
72
 */
73
void
74
_mesa_update_histogram(GLcontext *ctx, GLuint n, const GLfloat rgba[][4])
75
{
76
   const GLint max = ctx->Histogram.Width - 1;
77
   GLfloat w = (GLfloat) max;
78
   GLuint i;
79
 
80
   if (ctx->Histogram.Width == 0)
81
      return;
82
 
83
   for (i = 0; i < n; i++) {
84
      GLint ri = IROUND(rgba[i][RCOMP] * w);
85
      GLint gi = IROUND(rgba[i][GCOMP] * w);
86
      GLint bi = IROUND(rgba[i][BCOMP] * w);
87
      GLint ai = IROUND(rgba[i][ACOMP] * w);
88
      ri = CLAMP(ri, 0, max);
89
      gi = CLAMP(gi, 0, max);
90
      bi = CLAMP(bi, 0, max);
91
      ai = CLAMP(ai, 0, max);
92
      ctx->Histogram.Count[ri][RCOMP]++;
93
      ctx->Histogram.Count[gi][GCOMP]++;
94
      ctx->Histogram.Count[bi][BCOMP]++;
95
      ctx->Histogram.Count[ai][ACOMP]++;
96
   }
97
}