672d163d8cf33a7dd778fae34616e7ea22a4a8cd
[mesa.git] / src / mesa / swrast / s_imaging.c
1 /* $Id: s_imaging.c,v 1.1 2000/10/31 18:00:04 keithw Exp $ */
2
3 /*
4 * Mesa 3-D graphics library
5 * Version: 3.4
6 *
7 * Copyright (C) 1999-2000 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 /*
29 * Histogram, Min/max and convolution for GL_ARB_imaging subset
30 *
31 */
32
33
34 #include "glheader.h"
35 #include "colormac.h"
36 #include "image.h"
37 #include "mmath.h"
38
39 #include "s_imaging.h"
40 #include "s_span.h"
41
42
43
44 /*
45 * Update the min/max values from an array of fragment colors.
46 */
47 void
48 _mesa_update_minmax(GLcontext *ctx, GLuint n, const GLfloat rgba[][4])
49 {
50 GLuint i;
51 for (i = 0; i < n; i++) {
52 /* update mins */
53 if (rgba[i][RCOMP] < ctx->MinMax.Min[RCOMP])
54 ctx->MinMax.Min[RCOMP] = rgba[i][RCOMP];
55 if (rgba[i][GCOMP] < ctx->MinMax.Min[GCOMP])
56 ctx->MinMax.Min[GCOMP] = rgba[i][GCOMP];
57 if (rgba[i][BCOMP] < ctx->MinMax.Min[BCOMP])
58 ctx->MinMax.Min[BCOMP] = rgba[i][BCOMP];
59 if (rgba[i][ACOMP] < ctx->MinMax.Min[ACOMP])
60 ctx->MinMax.Min[ACOMP] = rgba[i][ACOMP];
61
62 /* update maxs */
63 if (rgba[i][RCOMP] > ctx->MinMax.Max[RCOMP])
64 ctx->MinMax.Max[RCOMP] = rgba[i][RCOMP];
65 if (rgba[i][GCOMP] > ctx->MinMax.Max[GCOMP])
66 ctx->MinMax.Max[GCOMP] = rgba[i][GCOMP];
67 if (rgba[i][BCOMP] > ctx->MinMax.Max[BCOMP])
68 ctx->MinMax.Max[BCOMP] = rgba[i][BCOMP];
69 if (rgba[i][ACOMP] > ctx->MinMax.Max[ACOMP])
70 ctx->MinMax.Max[ACOMP] = rgba[i][ACOMP];
71 }
72 }
73
74
75 /*
76 * Update the histogram values from an array of fragment colors.
77 */
78 void
79 _mesa_update_histogram(GLcontext *ctx, GLuint n, const GLfloat rgba[][4])
80 {
81 const GLint max = ctx->Histogram.Width - 1;
82 GLfloat w = (GLfloat) max;
83 GLuint i;
84
85 if (ctx->Histogram.Width == 0)
86 return;
87
88 for (i = 0; i < n; i++) {
89 GLint ri = (GLint) (rgba[i][RCOMP] * w + 0.5F);
90 GLint gi = (GLint) (rgba[i][GCOMP] * w + 0.5F);
91 GLint bi = (GLint) (rgba[i][BCOMP] * w + 0.5F);
92 GLint ai = (GLint) (rgba[i][ACOMP] * w + 0.5F);
93 ri = CLAMP(ri, 0, max);
94 gi = CLAMP(gi, 0, max);
95 bi = CLAMP(bi, 0, max);
96 ai = CLAMP(ai, 0, max);
97 ctx->Histogram.Count[ri][RCOMP]++;
98 ctx->Histogram.Count[gi][GCOMP]++;
99 ctx->Histogram.Count[bi][BCOMP]++;
100 ctx->Histogram.Count[ai][ACOMP]++;
101 }
102 }
103
104
105