672d163d8cf33a7dd778fae34616e7ea22a4a8cd
1 /* $Id: s_imaging.c,v 1.1 2000/10/31 18:00:04 keithw Exp $ */
4 * Mesa 3-D graphics library
7 * Copyright (C) 1999-2000 Brian Paul All Rights Reserved.
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:
16 * The above copyright notice and this permission notice shall be included
17 * in all copies or substantial portions of the Software.
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.
29 * Histogram, Min/max and convolution for GL_ARB_imaging subset
39 #include "s_imaging.h"
45 * Update the min/max values from an array of fragment colors.
48 _mesa_update_minmax(GLcontext
*ctx
, GLuint n
, const GLfloat rgba
[][4])
51 for (i
= 0; i
< n
; i
++) {
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
];
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
];
76 * Update the histogram values from an array of fragment colors.
79 _mesa_update_histogram(GLcontext
*ctx
, GLuint n
, const GLfloat rgba
[][4])
81 const GLint max
= ctx
->Histogram
.Width
- 1;
82 GLfloat w
= (GLfloat
) max
;
85 if (ctx
->Histogram
.Width
== 0)
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
]++;