lots of gl_*() to _mesa_*() namespace clean-up
[mesa.git] / src / mesa / main / histogram.c
1 /* $Id: histogram.c,v 1.9 2001/03/03 20:33:27 brianp 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 #ifdef PC_HEADER
29 #include "all.h"
30 #else
31 #include "glheader.h"
32 #include "colormac.h"
33 #include "context.h"
34 #include "image.h"
35 #include "histogram.h"
36 #include "mmath.h"
37 #endif
38
39
40 /*
41 * XXX the packed pixel formats haven't been tested.
42 */
43 static void
44 pack_histogram( GLcontext *ctx,
45 GLuint n, CONST GLuint rgba[][4],
46 GLenum format, GLenum type, GLvoid *destination,
47 const struct gl_pixelstore_attrib *packing )
48 {
49 const GLint comps = _mesa_components_in_format(format);
50 GLuint luminance[MAX_WIDTH];
51
52 if (format == GL_LUMINANCE || format == GL_LUMINANCE_ALPHA) {
53 GLuint i;
54 for (i = 0; i < n; i++) {
55 luminance[i] = rgba[i][RCOMP] + rgba[i][GCOMP] + rgba[i][BCOMP];
56 }
57 }
58
59 #define PACK_MACRO(TYPE) \
60 { \
61 GLuint i; \
62 switch (format) { \
63 case GL_RED: \
64 for (i=0;i<n;i++) \
65 dst[i] = (TYPE) rgba[i][RCOMP]; \
66 break; \
67 case GL_GREEN: \
68 for (i=0;i<n;i++) \
69 dst[i] = (TYPE) rgba[i][GCOMP]; \
70 break; \
71 case GL_BLUE: \
72 for (i=0;i<n;i++) \
73 dst[i] = (TYPE) rgba[i][BCOMP]; \
74 break; \
75 case GL_ALPHA: \
76 for (i=0;i<n;i++) \
77 dst[i] = (TYPE) rgba[i][ACOMP]; \
78 break; \
79 case GL_LUMINANCE: \
80 for (i=0;i<n;i++) \
81 dst[i] = (TYPE) luminance[i]; \
82 break; \
83 case GL_LUMINANCE_ALPHA: \
84 for (i=0;i<n;i++) { \
85 dst[i*2+0] = (TYPE) luminance[i]; \
86 dst[i*2+1] = (TYPE) rgba[i][ACOMP]; \
87 } \
88 break; \
89 case GL_RGB: \
90 for (i=0;i<n;i++) { \
91 dst[i*3+0] = (TYPE) rgba[i][RCOMP]; \
92 dst[i*3+1] = (TYPE) rgba[i][GCOMP]; \
93 dst[i*3+2] = (TYPE) rgba[i][BCOMP]; \
94 } \
95 break; \
96 case GL_RGBA: \
97 for (i=0;i<n;i++) { \
98 dst[i*4+0] = (TYPE) rgba[i][RCOMP]; \
99 dst[i*4+1] = (TYPE) rgba[i][GCOMP]; \
100 dst[i*4+2] = (TYPE) rgba[i][BCOMP]; \
101 dst[i*4+3] = (TYPE) rgba[i][ACOMP]; \
102 } \
103 break; \
104 case GL_BGR: \
105 for (i=0;i<n;i++) { \
106 dst[i*3+0] = (TYPE) rgba[i][BCOMP]; \
107 dst[i*3+1] = (TYPE) rgba[i][GCOMP]; \
108 dst[i*3+2] = (TYPE) rgba[i][RCOMP]; \
109 } \
110 break; \
111 case GL_BGRA: \
112 for (i=0;i<n;i++) { \
113 dst[i*4+0] = (TYPE) rgba[i][BCOMP]; \
114 dst[i*4+1] = (TYPE) rgba[i][GCOMP]; \
115 dst[i*4+2] = (TYPE) rgba[i][RCOMP]; \
116 dst[i*4+3] = (TYPE) rgba[i][ACOMP]; \
117 } \
118 break; \
119 case GL_ABGR_EXT: \
120 for (i=0;i<n;i++) { \
121 dst[i*4+0] = (TYPE) rgba[i][ACOMP]; \
122 dst[i*4+1] = (TYPE) rgba[i][BCOMP]; \
123 dst[i*4+2] = (TYPE) rgba[i][GCOMP]; \
124 dst[i*4+3] = (TYPE) rgba[i][RCOMP]; \
125 } \
126 break; \
127 default: \
128 _mesa_problem(ctx, "bad format in pack_histogram"); \
129 } \
130 }
131
132 switch (type) {
133 case GL_UNSIGNED_BYTE:
134 {
135 GLubyte *dst = (GLubyte *) destination;
136 PACK_MACRO(GLubyte);
137 }
138 break;
139 case GL_BYTE:
140 {
141 GLbyte *dst = (GLbyte *) destination;
142 PACK_MACRO(GLbyte);
143 }
144 break;
145 case GL_UNSIGNED_SHORT:
146 {
147 GLushort *dst = (GLushort *) destination;
148 PACK_MACRO(GLushort);
149 if (packing->SwapBytes) {
150 _mesa_swap2(dst, n * comps);
151 }
152 }
153 break;
154 case GL_SHORT:
155 {
156 GLshort *dst = (GLshort *) destination;
157 PACK_MACRO(GLshort);
158 if (packing->SwapBytes) {
159 _mesa_swap2((GLushort *) dst, n * comps);
160 }
161 }
162 break;
163 case GL_UNSIGNED_INT:
164 {
165 GLuint *dst = (GLuint *) destination;
166 PACK_MACRO(GLuint);
167 if (packing->SwapBytes) {
168 _mesa_swap4(dst, n * comps);
169 }
170 }
171 break;
172 case GL_INT:
173 {
174 GLint *dst = (GLint *) destination;
175 PACK_MACRO(GLint);
176 if (packing->SwapBytes) {
177 _mesa_swap4((GLuint *) dst, n * comps);
178 }
179 }
180 break;
181 case GL_FLOAT:
182 {
183 GLfloat *dst = (GLfloat *) destination;
184 PACK_MACRO(GLfloat);
185 if (packing->SwapBytes) {
186 _mesa_swap4((GLuint *) dst, n * comps);
187 }
188 }
189 break;
190 case GL_UNSIGNED_BYTE_3_3_2:
191 if (format == GL_RGB) {
192 GLubyte *dst = (GLubyte *) destination;
193 GLuint i;
194 for (i = 0; i < n; i++) {
195 dst[i] = ((rgba[i][RCOMP] & 0x7) << 5)
196 | ((rgba[i][GCOMP] & 0x7) << 2)
197 | ((rgba[i][BCOMP] & 0x3) );
198 }
199 }
200 else {
201 GLubyte *dst = (GLubyte *) destination;
202 GLuint i;
203 ASSERT(format == GL_BGR);
204 for (i = 0; i < n; i++) {
205 dst[i] = ((rgba[i][BCOMP] & 0x7) << 5)
206 | ((rgba[i][GCOMP] & 0x7) << 2)
207 | ((rgba[i][RCOMP] & 0x3) );
208 }
209 }
210 break;
211 case GL_UNSIGNED_BYTE_2_3_3_REV:
212 if (format == GL_RGB) {
213 GLubyte *dst = (GLubyte *) destination;
214 GLuint i;
215 for (i = 0; i < n; i++) {
216 dst[i] = ((rgba[i][RCOMP] & 0x3) << 6)
217 | ((rgba[i][GCOMP] & 0x7) << 3)
218 | ((rgba[i][BCOMP] & 0x7) );
219 }
220 }
221 else {
222 GLubyte *dst = (GLubyte *) destination;
223 GLuint i;
224 ASSERT(format == GL_BGR);
225 for (i = 0; i < n; i++) {
226 dst[i] = ((rgba[i][BCOMP] & 0x3) << 6)
227 | ((rgba[i][GCOMP] & 0x7) << 3)
228 | ((rgba[i][RCOMP] & 0x7) );
229 }
230 }
231 break;
232 case GL_UNSIGNED_SHORT_5_6_5:
233 if (format == GL_RGB) {
234 GLushort *dst = (GLushort *) destination;
235 GLuint i;
236 for (i = 0; i < n; i++) {
237 dst[i] = ((rgba[i][RCOMP] & 0x1f) << 11)
238 | ((rgba[i][GCOMP] & 0x3f) << 5)
239 | ((rgba[i][BCOMP] & 0x1f) );
240 }
241 }
242 else {
243 GLushort *dst = (GLushort *) destination;
244 GLuint i;
245 ASSERT(format == GL_BGR);
246 for (i = 0; i < n; i++) {
247 dst[i] = ((rgba[i][BCOMP] & 0x1f) << 11)
248 | ((rgba[i][GCOMP] & 0x3f) << 5)
249 | ((rgba[i][RCOMP] & 0x1f) );
250 }
251 }
252 break;
253 case GL_UNSIGNED_SHORT_5_6_5_REV:
254 if (format == GL_RGB) {
255 GLushort *dst = (GLushort *) destination;
256 GLuint i;
257 for (i = 0; i < n; i++) {
258 dst[i] = ((rgba[i][BCOMP] & 0x1f) << 11)
259 | ((rgba[i][GCOMP] & 0x3f) << 5)
260 | ((rgba[i][RCOMP] & 0x1f) );
261 }
262 }
263 else {
264 GLushort *dst = (GLushort *) destination;
265 GLuint i;
266 ASSERT(format == GL_BGR);
267 for (i = 0; i < n; i++) {
268 dst[i] = ((rgba[i][RCOMP] & 0x1f) << 11)
269 | ((rgba[i][GCOMP] & 0x3f) << 5)
270 | ((rgba[i][BCOMP] & 0x1f) );
271 }
272 }
273 break;
274 case GL_UNSIGNED_SHORT_4_4_4_4:
275 if (format == GL_RGBA) {
276 GLushort *dst = (GLushort *) destination;
277 GLuint i;
278 for (i = 0; i < n; i++) {
279 dst[i] = ((rgba[i][RCOMP] & 0xf) << 12)
280 | ((rgba[i][GCOMP] & 0xf) << 8)
281 | ((rgba[i][BCOMP] & 0xf) << 4)
282 | ((rgba[i][ACOMP] & 0xf) );
283 }
284 }
285 else if (format == GL_BGRA) {
286 GLushort *dst = (GLushort *) destination;
287 GLuint i;
288 for (i = 0; i < n; i++) {
289 dst[i] = ((rgba[i][BCOMP] & 0xf) << 12)
290 | ((rgba[i][GCOMP] & 0xf) << 8)
291 | ((rgba[i][RCOMP] & 0xf) << 4)
292 | ((rgba[i][ACOMP] & 0xf) );
293 }
294 }
295 else {
296 GLushort *dst = (GLushort *) destination;
297 GLuint i;
298 ASSERT(format == GL_ABGR_EXT);
299 for (i = 0; i < n; i++) {
300 dst[i] = ((rgba[i][ACOMP] & 0xf) << 12)
301 | ((rgba[i][BCOMP] & 0xf) << 8)
302 | ((rgba[i][GCOMP] & 0xf) << 4)
303 | ((rgba[i][RCOMP] & 0xf) );
304 }
305 }
306 break;
307 case GL_UNSIGNED_SHORT_4_4_4_4_REV:
308 if (format == GL_RGBA) {
309 GLushort *dst = (GLushort *) destination;
310 GLuint i;
311 for (i = 0; i < n; i++) {
312 dst[i] = ((rgba[i][ACOMP] & 0xf) << 12)
313 | ((rgba[i][BCOMP] & 0xf) << 8)
314 | ((rgba[i][GCOMP] & 0xf) << 4)
315 | ((rgba[i][RCOMP] & 0xf) );
316 }
317 }
318 else if (format == GL_BGRA) {
319 GLushort *dst = (GLushort *) destination;
320 GLuint i;
321 for (i = 0; i < n; i++) {
322 dst[i] = ((rgba[i][ACOMP] & 0xf) << 12)
323 | ((rgba[i][RCOMP] & 0xf) << 8)
324 | ((rgba[i][GCOMP] & 0xf) << 4)
325 | ((rgba[i][BCOMP] & 0xf) );
326 }
327 }
328 else {
329 GLushort *dst = (GLushort *) destination;
330 GLuint i;
331 ASSERT(format == GL_ABGR_EXT);
332 for (i = 0; i < n; i++) {
333 dst[i] = ((rgba[i][RCOMP] & 0xf) << 12)
334 | ((rgba[i][GCOMP] & 0xf) << 8)
335 | ((rgba[i][BCOMP] & 0xf) << 4)
336 | ((rgba[i][ACOMP] & 0xf) );
337 }
338 }
339 break;
340 case GL_UNSIGNED_SHORT_5_5_5_1:
341 if (format == GL_RGBA) {
342 GLushort *dst = (GLushort *) destination;
343 GLuint i;
344 for (i = 0; i < n; i++) {
345 dst[i] = ((rgba[i][RCOMP] & 0x1f) << 11)
346 | ((rgba[i][GCOMP] & 0x1f) << 6)
347 | ((rgba[i][BCOMP] & 0x1f) << 1)
348 | ((rgba[i][ACOMP] & 0x1) );
349 }
350 }
351 else if (format == GL_BGRA) {
352 GLushort *dst = (GLushort *) destination;
353 GLuint i;
354 for (i = 0; i < n; i++) {
355 dst[i] = ((rgba[i][BCOMP] & 0x1f) << 11)
356 | ((rgba[i][GCOMP] & 0x1f) << 6)
357 | ((rgba[i][RCOMP] & 0x1f) << 1)
358 | ((rgba[i][ACOMP] & 0x1) );
359 }
360 }
361 else {
362 GLushort *dst = (GLushort *) destination;
363 GLuint i;
364 ASSERT(format == GL_ABGR_EXT);
365 for (i = 0; i < n; i++) {
366 dst[i] = ((rgba[i][ACOMP] & 0x1f) << 11)
367 | ((rgba[i][BCOMP] & 0x1f) << 6)
368 | ((rgba[i][GCOMP] & 0x1f) << 1)
369 | ((rgba[i][RCOMP] & 0x1) );
370 }
371 }
372 break;
373 case GL_UNSIGNED_SHORT_1_5_5_5_REV:
374 if (format == GL_RGBA) {
375 GLushort *dst = (GLushort *) destination;
376 GLuint i;
377 for (i = 0; i < n; i++) {
378 dst[i] = ((rgba[i][ACOMP] & 0x1f) << 11)
379 | ((rgba[i][BCOMP] & 0x1f) << 6)
380 | ((rgba[i][GCOMP] & 0x1f) << 1)
381 | ((rgba[i][RCOMP] & 0x1) );
382 }
383 }
384 else if (format == GL_BGRA) {
385 GLushort *dst = (GLushort *) destination;
386 GLuint i;
387 for (i = 0; i < n; i++) {
388 dst[i] = ((rgba[i][ACOMP] & 0x1f) << 11)
389 | ((rgba[i][RCOMP] & 0x1f) << 6)
390 | ((rgba[i][GCOMP] & 0x1f) << 1)
391 | ((rgba[i][BCOMP] & 0x1) );
392 }
393 }
394 else {
395 GLushort *dst = (GLushort *) destination;
396 GLuint i;
397 ASSERT(format == GL_ABGR_EXT);
398 for (i = 0; i < n; i++) {
399 dst[i] = ((rgba[i][RCOMP] & 0x1f) << 11)
400 | ((rgba[i][GCOMP] & 0x1f) << 6)
401 | ((rgba[i][BCOMP] & 0x1f) << 1)
402 | ((rgba[i][ACOMP] & 0x1) );
403 }
404 }
405 break;
406 case GL_UNSIGNED_INT_8_8_8_8:
407 if (format == GL_RGBA) {
408 GLuint *dst = (GLuint *) destination;
409 GLuint i;
410 for (i = 0; i < n; i++) {
411 dst[i] = ((rgba[i][RCOMP] & 0xff) << 24)
412 | ((rgba[i][GCOMP] & 0xff) << 16)
413 | ((rgba[i][BCOMP] & 0xff) << 8)
414 | ((rgba[i][ACOMP] & 0xff) );
415 }
416 }
417 else if (format == GL_BGRA) {
418 GLuint *dst = (GLuint *) destination;
419 GLuint i;
420 for (i = 0; i < n; i++) {
421 dst[i] = ((rgba[i][BCOMP] & 0xff) << 24)
422 | ((rgba[i][GCOMP] & 0xff) << 16)
423 | ((rgba[i][RCOMP] & 0xff) << 8)
424 | ((rgba[i][ACOMP] & 0xff) );
425 }
426 }
427 else {
428 GLuint *dst = (GLuint *) destination;
429 GLuint i;
430 ASSERT(format == GL_ABGR_EXT);
431 for (i = 0; i < n; i++) {
432 dst[i] = ((rgba[i][ACOMP] & 0xff) << 24)
433 | ((rgba[i][BCOMP] & 0xff) << 16)
434 | ((rgba[i][GCOMP] & 0xff) << 8)
435 | ((rgba[i][RCOMP] & 0xff) );
436 }
437 }
438 break;
439 case GL_UNSIGNED_INT_8_8_8_8_REV:
440 if (format == GL_RGBA) {
441 GLuint *dst = (GLuint *) destination;
442 GLuint i;
443 for (i = 0; i < n; i++) {
444 dst[i] = ((rgba[i][ACOMP] & 0xff) << 24)
445 | ((rgba[i][BCOMP] & 0xff) << 16)
446 | ((rgba[i][GCOMP] & 0xff) << 8)
447 | ((rgba[i][RCOMP] & 0xff) );
448 }
449 }
450 else if (format == GL_BGRA) {
451 GLuint *dst = (GLuint *) destination;
452 GLuint i;
453 for (i = 0; i < n; i++) {
454 dst[i] = ((rgba[i][ACOMP] & 0xff) << 24)
455 | ((rgba[i][RCOMP] & 0xff) << 16)
456 | ((rgba[i][GCOMP] & 0xff) << 8)
457 | ((rgba[i][BCOMP] & 0xff) );
458 }
459 }
460 else {
461 GLuint *dst = (GLuint *) destination;
462 GLuint i;
463 ASSERT(format == GL_ABGR_EXT);
464 for (i = 0; i < n; i++) {
465 dst[i] = ((rgba[i][RCOMP] & 0xff) << 24)
466 | ((rgba[i][GCOMP] & 0xff) << 16)
467 | ((rgba[i][BCOMP] & 0xff) << 8)
468 | ((rgba[i][ACOMP] & 0xff) );
469 }
470 }
471 break;
472 case GL_UNSIGNED_INT_10_10_10_2:
473 if (format == GL_RGBA) {
474 GLuint *dst = (GLuint *) destination;
475 GLuint i;
476 for (i = 0; i < n; i++) {
477 dst[i] = ((rgba[i][RCOMP] & 0x3ff) << 22)
478 | ((rgba[i][GCOMP] & 0x3ff) << 12)
479 | ((rgba[i][BCOMP] & 0x3ff) << 2)
480 | ((rgba[i][ACOMP] & 0x3) );
481 }
482 }
483 else if (format == GL_BGRA) {
484 GLuint *dst = (GLuint *) destination;
485 GLuint i;
486 for (i = 0; i < n; i++) {
487 dst[i] = ((rgba[i][BCOMP] & 0x3ff) << 22)
488 | ((rgba[i][GCOMP] & 0x3ff) << 12)
489 | ((rgba[i][RCOMP] & 0x3ff) << 2)
490 | ((rgba[i][ACOMP] & 0x3) );
491 }
492 }
493 else {
494 GLuint *dst = (GLuint *) destination;
495 GLuint i;
496 ASSERT(format == GL_ABGR_EXT);
497 for (i = 0; i < n; i++) {
498 dst[i] = ((rgba[i][ACOMP] & 0x3ff) << 22)
499 | ((rgba[i][BCOMP] & 0x3ff) << 12)
500 | ((rgba[i][GCOMP] & 0x3ff) << 2)
501 | ((rgba[i][RCOMP] & 0x3) );
502 }
503 }
504 break;
505 case GL_UNSIGNED_INT_2_10_10_10_REV:
506 if (format == GL_RGBA) {
507 GLuint *dst = (GLuint *) destination;
508 GLuint i;
509 for (i = 0; i < n; i++) {
510 dst[i] = ((rgba[i][ACOMP] & 0x3ff) << 22)
511 | ((rgba[i][BCOMP] & 0x3ff) << 12)
512 | ((rgba[i][GCOMP] & 0x3ff) << 2)
513 | ((rgba[i][RCOMP] & 0x3) );
514 }
515 }
516 else if (format == GL_BGRA) {
517 GLuint *dst = (GLuint *) destination;
518 GLuint i;
519 for (i = 0; i < n; i++) {
520 dst[i] = ((rgba[i][ACOMP] & 0x3ff) << 22)
521 | ((rgba[i][RCOMP] & 0x3ff) << 12)
522 | ((rgba[i][GCOMP] & 0x3ff) << 2)
523 | ((rgba[i][BCOMP] & 0x3) );
524 }
525 }
526 else {
527 GLuint *dst = (GLuint *) destination;
528 GLuint i;
529 ASSERT(format == GL_ABGR_EXT);
530 for (i = 0; i < n; i++) {
531 dst[i] = ((rgba[i][RCOMP] & 0x3ff) << 22)
532 | ((rgba[i][GCOMP] & 0x3ff) << 12)
533 | ((rgba[i][BCOMP] & 0x3ff) << 2)
534 | ((rgba[i][ACOMP] & 0x3) );
535 }
536 }
537 break;
538 default:
539 _mesa_problem(ctx, "Bad type in pack_histogram");
540 }
541
542 #undef PACK_MACRO
543 }
544
545
546 /*
547 * Given an internalFormat token passed to glHistogram or glMinMax,
548 * return the corresponding base format.
549 * Return -1 if invalid token.
550 */
551 static GLint
552 base_histogram_format( GLenum format )
553 {
554 switch (format) {
555 case GL_ALPHA:
556 case GL_ALPHA4:
557 case GL_ALPHA8:
558 case GL_ALPHA12:
559 case GL_ALPHA16:
560 return GL_ALPHA;
561 case GL_LUMINANCE:
562 case GL_LUMINANCE4:
563 case GL_LUMINANCE8:
564 case GL_LUMINANCE12:
565 case GL_LUMINANCE16:
566 return GL_LUMINANCE;
567 case GL_LUMINANCE_ALPHA:
568 case GL_LUMINANCE4_ALPHA4:
569 case GL_LUMINANCE6_ALPHA2:
570 case GL_LUMINANCE8_ALPHA8:
571 case GL_LUMINANCE12_ALPHA4:
572 case GL_LUMINANCE12_ALPHA12:
573 case GL_LUMINANCE16_ALPHA16:
574 return GL_LUMINANCE_ALPHA;
575 case GL_RGB:
576 case GL_R3_G3_B2:
577 case GL_RGB4:
578 case GL_RGB5:
579 case GL_RGB8:
580 case GL_RGB10:
581 case GL_RGB12:
582 case GL_RGB16:
583 return GL_RGB;
584 case GL_RGBA:
585 case GL_RGBA2:
586 case GL_RGBA4:
587 case GL_RGB5_A1:
588 case GL_RGBA8:
589 case GL_RGB10_A2:
590 case GL_RGBA12:
591 case GL_RGBA16:
592 return GL_RGBA;
593 default:
594 return -1; /* error */
595 }
596 }
597
598
599 void
600 _mesa_GetMinmax(GLenum target, GLboolean reset, GLenum format, GLenum type, GLvoid *values)
601 {
602 GET_CURRENT_CONTEXT(ctx);
603 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx);
604
605 if (!ctx->Extensions.EXT_histogram && !ctx->Extensions.ARB_imaging) {
606 _mesa_error(ctx, GL_INVALID_OPERATION, "glGetMinmax");
607 return;
608 }
609
610 if (target != GL_MINMAX) {
611 _mesa_error(ctx, GL_INVALID_ENUM, "glGetMinmax(target)");
612 return;
613 }
614
615 if (!_mesa_is_legal_format_and_type(format, type)) {
616 _mesa_error(ctx, GL_INVALID_OPERATION, "glGetMinmax(format or type)");
617 return;
618 }
619
620 if (type != GL_UNSIGNED_BYTE &&
621 type != GL_BYTE &&
622 type != GL_UNSIGNED_SHORT &&
623 type != GL_SHORT &&
624 type != GL_UNSIGNED_INT &&
625 type != GL_INT &&
626 type != GL_FLOAT &&
627 type != GL_UNSIGNED_BYTE_3_3_2 &&
628 type != GL_UNSIGNED_BYTE_2_3_3_REV &&
629 type != GL_UNSIGNED_SHORT_5_6_5 &&
630 type != GL_UNSIGNED_SHORT_5_6_5_REV &&
631 type != GL_UNSIGNED_SHORT_4_4_4_4 &&
632 type != GL_UNSIGNED_SHORT_4_4_4_4_REV &&
633 type != GL_UNSIGNED_SHORT_5_5_5_1 &&
634 type != GL_UNSIGNED_SHORT_1_5_5_5_REV &&
635 type != GL_UNSIGNED_INT_8_8_8_8 &&
636 type != GL_UNSIGNED_INT_8_8_8_8_REV &&
637 type != GL_UNSIGNED_INT_10_10_10_2 &&
638 type != GL_UNSIGNED_INT_2_10_10_10_REV) {
639 _mesa_error(ctx, GL_INVALID_ENUM, "glGetMinmax(type)");
640 return;
641 }
642
643 if (!values)
644 return;
645
646 {
647 GLfloat minmax[2][4];
648 minmax[0][RCOMP] = CLAMP(ctx->MinMax.Min[RCOMP], 0.0F, 1.0F);
649 minmax[0][GCOMP] = CLAMP(ctx->MinMax.Min[GCOMP], 0.0F, 1.0F);
650 minmax[0][BCOMP] = CLAMP(ctx->MinMax.Min[BCOMP], 0.0F, 1.0F);
651 minmax[0][ACOMP] = CLAMP(ctx->MinMax.Min[ACOMP], 0.0F, 1.0F);
652 minmax[1][RCOMP] = CLAMP(ctx->MinMax.Max[RCOMP], 0.0F, 1.0F);
653 minmax[1][GCOMP] = CLAMP(ctx->MinMax.Max[GCOMP], 0.0F, 1.0F);
654 minmax[1][BCOMP] = CLAMP(ctx->MinMax.Max[BCOMP], 0.0F, 1.0F);
655 minmax[1][ACOMP] = CLAMP(ctx->MinMax.Max[ACOMP], 0.0F, 1.0F);
656 _mesa_pack_float_rgba_span(ctx, 2, (CONST GLfloat (*)[4]) minmax,
657 format, type, values, &ctx->Pack, 0);
658 }
659
660 if (reset) {
661 _mesa_ResetMinmax(GL_MINMAX);
662 }
663 }
664
665
666 void
667 _mesa_GetHistogram(GLenum target, GLboolean reset, GLenum format, GLenum type, GLvoid *values)
668 {
669 GET_CURRENT_CONTEXT(ctx);
670 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx);
671
672 if (!ctx->Extensions.EXT_histogram && !ctx->Extensions.ARB_imaging) {
673 _mesa_error(ctx, GL_INVALID_OPERATION, "glGetHistogram");
674 return;
675 }
676
677 if (target != GL_HISTOGRAM) {
678 _mesa_error(ctx, GL_INVALID_ENUM, "glGetHistogram(target)");
679 return;
680 }
681
682 if (!_mesa_is_legal_format_and_type(format, type)) {
683 _mesa_error(ctx, GL_INVALID_OPERATION, "glGetHistogram(format or type)");
684 return;
685 }
686
687 if (type != GL_UNSIGNED_BYTE &&
688 type != GL_BYTE &&
689 type != GL_UNSIGNED_SHORT &&
690 type != GL_SHORT &&
691 type != GL_UNSIGNED_INT &&
692 type != GL_INT &&
693 type != GL_FLOAT &&
694 type != GL_UNSIGNED_BYTE_3_3_2 &&
695 type != GL_UNSIGNED_BYTE_2_3_3_REV &&
696 type != GL_UNSIGNED_SHORT_5_6_5 &&
697 type != GL_UNSIGNED_SHORT_5_6_5_REV &&
698 type != GL_UNSIGNED_SHORT_4_4_4_4 &&
699 type != GL_UNSIGNED_SHORT_4_4_4_4_REV &&
700 type != GL_UNSIGNED_SHORT_5_5_5_1 &&
701 type != GL_UNSIGNED_SHORT_1_5_5_5_REV &&
702 type != GL_UNSIGNED_INT_8_8_8_8 &&
703 type != GL_UNSIGNED_INT_8_8_8_8_REV &&
704 type != GL_UNSIGNED_INT_10_10_10_2 &&
705 type != GL_UNSIGNED_INT_2_10_10_10_REV) {
706 _mesa_error(ctx, GL_INVALID_ENUM, "glGetHistogram(type)");
707 return;
708 }
709
710 if (!values)
711 return;
712
713 pack_histogram(ctx, ctx->Histogram.Width,
714 (CONST GLuint (*)[4]) ctx->Histogram.Count,
715 format, type, values, &ctx->Pack);
716
717 if (reset) {
718 GLuint i;
719 for (i = 0; i < HISTOGRAM_TABLE_SIZE; i++) {
720 ctx->Histogram.Count[i][0] = 0;
721 ctx->Histogram.Count[i][1] = 0;
722 ctx->Histogram.Count[i][2] = 0;
723 ctx->Histogram.Count[i][3] = 0;
724 }
725 }
726 }
727
728
729 void
730 _mesa_GetHistogramParameterfv(GLenum target, GLenum pname, GLfloat *params)
731 {
732 GET_CURRENT_CONTEXT(ctx);
733 ASSERT_OUTSIDE_BEGIN_END(ctx);
734
735 if (!ctx->Extensions.EXT_histogram && !ctx->Extensions.ARB_imaging) {
736 _mesa_error(ctx, GL_INVALID_OPERATION, "glGetHistogramParameterfv");
737 return;
738 }
739
740 if (target != GL_HISTOGRAM && target != GL_PROXY_HISTOGRAM) {
741 _mesa_error(ctx, GL_INVALID_ENUM, "glGetHistogramParameterfv(target)");
742 return;
743 }
744
745 switch (pname) {
746 case GL_HISTOGRAM_WIDTH:
747 *params = (GLfloat) ctx->Histogram.Width;
748 break;
749 case GL_HISTOGRAM_FORMAT:
750 *params = (GLfloat) ctx->Histogram.Format;
751 break;
752 case GL_HISTOGRAM_RED_SIZE:
753 *params = (GLfloat) ctx->Histogram.RedSize;
754 break;
755 case GL_HISTOGRAM_GREEN_SIZE:
756 *params = (GLfloat) ctx->Histogram.GreenSize;
757 break;
758 case GL_HISTOGRAM_BLUE_SIZE:
759 *params = (GLfloat) ctx->Histogram.BlueSize;
760 break;
761 case GL_HISTOGRAM_ALPHA_SIZE:
762 *params = (GLfloat) ctx->Histogram.AlphaSize;
763 break;
764 case GL_HISTOGRAM_LUMINANCE_SIZE:
765 *params = (GLfloat) ctx->Histogram.LuminanceSize;
766 break;
767 case GL_HISTOGRAM_SINK:
768 *params = (GLfloat) ctx->Histogram.Sink;
769 break;
770 default:
771 _mesa_error(ctx, GL_INVALID_ENUM, "glGetHistogramParameterfv(pname)");
772 }
773 }
774
775
776 void
777 _mesa_GetHistogramParameteriv(GLenum target, GLenum pname, GLint *params)
778 {
779 GET_CURRENT_CONTEXT(ctx);
780 ASSERT_OUTSIDE_BEGIN_END(ctx);
781
782 if (!ctx->Extensions.EXT_histogram && !ctx->Extensions.ARB_imaging) {
783 _mesa_error(ctx, GL_INVALID_OPERATION, "glGetHistogramParameteriv");
784 return;
785 }
786
787 if (target != GL_HISTOGRAM && target != GL_PROXY_HISTOGRAM) {
788 _mesa_error(ctx, GL_INVALID_ENUM, "glGetHistogramParameteriv(target)");
789 return;
790 }
791
792 switch (pname) {
793 case GL_HISTOGRAM_WIDTH:
794 *params = (GLint) ctx->Histogram.Width;
795 break;
796 case GL_HISTOGRAM_FORMAT:
797 *params = (GLint) ctx->Histogram.Format;
798 break;
799 case GL_HISTOGRAM_RED_SIZE:
800 *params = (GLint) ctx->Histogram.RedSize;
801 break;
802 case GL_HISTOGRAM_GREEN_SIZE:
803 *params = (GLint) ctx->Histogram.GreenSize;
804 break;
805 case GL_HISTOGRAM_BLUE_SIZE:
806 *params = (GLint) ctx->Histogram.BlueSize;
807 break;
808 case GL_HISTOGRAM_ALPHA_SIZE:
809 *params = (GLint) ctx->Histogram.AlphaSize;
810 break;
811 case GL_HISTOGRAM_LUMINANCE_SIZE:
812 *params = (GLint) ctx->Histogram.LuminanceSize;
813 break;
814 case GL_HISTOGRAM_SINK:
815 *params = (GLint) ctx->Histogram.Sink;
816 break;
817 default:
818 _mesa_error(ctx, GL_INVALID_ENUM, "glGetHistogramParameteriv(pname)");
819 }
820 }
821
822
823 void
824 _mesa_GetMinmaxParameterfv(GLenum target, GLenum pname, GLfloat *params)
825 {
826 GET_CURRENT_CONTEXT(ctx);
827 ASSERT_OUTSIDE_BEGIN_END(ctx);
828
829 if (!ctx->Extensions.EXT_histogram && !ctx->Extensions.ARB_imaging) {
830 _mesa_error(ctx, GL_INVALID_OPERATION, "glGetMinmaxParameterfv");
831 return;
832 }
833 if (target != GL_MINMAX) {
834 _mesa_error(ctx, GL_INVALID_ENUM, "glGetMinmaxParameterfv(target)");
835 return;
836 }
837 if (pname == GL_MINMAX_FORMAT) {
838 *params = (GLfloat) ctx->MinMax.Format;
839 }
840 else if (pname == GL_MINMAX_SINK) {
841 *params = (GLfloat) ctx->MinMax.Sink;
842 }
843 else {
844 _mesa_error(ctx, GL_INVALID_ENUM, "glGetMinMaxParameterfv(pname)");
845 }
846 }
847
848
849 void
850 _mesa_GetMinmaxParameteriv(GLenum target, GLenum pname, GLint *params)
851 {
852 GET_CURRENT_CONTEXT(ctx);
853 ASSERT_OUTSIDE_BEGIN_END(ctx);
854
855 if (!ctx->Extensions.EXT_histogram && !ctx->Extensions.ARB_imaging) {
856 _mesa_error(ctx, GL_INVALID_OPERATION, "glGetMinmaxParameteriv");
857 return;
858 }
859 if (target != GL_MINMAX) {
860 _mesa_error(ctx, GL_INVALID_ENUM, "glGetMinmaxParameteriv(target)");
861 return;
862 }
863 if (pname == GL_MINMAX_FORMAT) {
864 *params = (GLint) ctx->MinMax.Format;
865 }
866 else if (pname == GL_MINMAX_SINK) {
867 *params = (GLint) ctx->MinMax.Sink;
868 }
869 else {
870 _mesa_error(ctx, GL_INVALID_ENUM, "glGetMinMaxParameteriv(pname)");
871 }
872 }
873
874
875 void
876 _mesa_Histogram(GLenum target, GLsizei width, GLenum internalFormat, GLboolean sink)
877 {
878 GLuint i;
879 GLboolean error = GL_FALSE;
880 GET_CURRENT_CONTEXT(ctx);
881 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx); /* sideeffects */
882
883 if (!ctx->Extensions.EXT_histogram && !ctx->Extensions.ARB_imaging) {
884 _mesa_error(ctx, GL_INVALID_OPERATION, "glHistogram");
885 return;
886 }
887
888 if (target != GL_HISTOGRAM && target != GL_PROXY_HISTOGRAM) {
889 _mesa_error(ctx, GL_INVALID_ENUM, "glHistogram(target)");
890 return;
891 }
892
893 if (width < 0 || width > HISTOGRAM_TABLE_SIZE) {
894 if (target == GL_PROXY_HISTOGRAM) {
895 error = GL_TRUE;
896 }
897 else {
898 if (width < 0)
899 _mesa_error(ctx, GL_INVALID_VALUE, "glHistogram(width)");
900 else
901 _mesa_error(ctx, GL_TABLE_TOO_LARGE, "glHistogram(width)");
902 return;
903 }
904 }
905
906 if (width != 0 && _mesa_bitcount(width) != 1) {
907 if (target == GL_PROXY_HISTOGRAM) {
908 error = GL_TRUE;
909 }
910 else {
911 _mesa_error(ctx, GL_INVALID_VALUE, "glHistogram(width)");
912 return;
913 }
914 }
915
916 if (base_histogram_format(internalFormat) < 0) {
917 if (target == GL_PROXY_HISTOGRAM) {
918 error = GL_TRUE;
919 }
920 else {
921 _mesa_error(ctx, GL_INVALID_ENUM, "glHistogram(internalFormat)");
922 return;
923 }
924 }
925
926 /* reset histograms */
927 for (i = 0; i < HISTOGRAM_TABLE_SIZE; i++) {
928 ctx->Histogram.Count[i][0] = 0;
929 ctx->Histogram.Count[i][1] = 0;
930 ctx->Histogram.Count[i][2] = 0;
931 ctx->Histogram.Count[i][3] = 0;
932 }
933
934 if (error) {
935 ctx->Histogram.Width = 0;
936 ctx->Histogram.Format = 0;
937 ctx->Histogram.RedSize = 0;
938 ctx->Histogram.GreenSize = 0;
939 ctx->Histogram.BlueSize = 0;
940 ctx->Histogram.AlphaSize = 0;
941 ctx->Histogram.LuminanceSize = 0;
942 }
943 else {
944 ctx->Histogram.Width = width;
945 ctx->Histogram.Format = internalFormat;
946 ctx->Histogram.Sink = sink;
947 ctx->Histogram.RedSize = 8 * sizeof(GLuint);
948 ctx->Histogram.GreenSize = 8 * sizeof(GLuint);
949 ctx->Histogram.BlueSize = 8 * sizeof(GLuint);
950 ctx->Histogram.AlphaSize = 8 * sizeof(GLuint);
951 ctx->Histogram.LuminanceSize = 8 * sizeof(GLuint);
952 }
953
954 ctx->NewState |= _NEW_PIXEL;
955 }
956
957
958 void
959 _mesa_Minmax(GLenum target, GLenum internalFormat, GLboolean sink)
960 {
961 GET_CURRENT_CONTEXT(ctx);
962 ASSERT_OUTSIDE_BEGIN_END(ctx);
963
964 if (!ctx->Extensions.EXT_histogram && !ctx->Extensions.ARB_imaging) {
965 _mesa_error(ctx, GL_INVALID_OPERATION, "glMinmax");
966 return;
967 }
968
969 if (target != GL_MINMAX) {
970 _mesa_error(ctx, GL_INVALID_ENUM, "glMinMax(target)");
971 return;
972 }
973
974 if (base_histogram_format(internalFormat) < 0) {
975 _mesa_error(ctx, GL_INVALID_ENUM, "glMinMax(internalFormat)");
976 return;
977 }
978
979 if (ctx->MinMax.Sink == sink)
980 return;
981 FLUSH_VERTICES(ctx, _NEW_PIXEL);
982 ctx->MinMax.Sink = sink;
983 }
984
985
986 void
987 _mesa_ResetHistogram(GLenum target)
988 {
989 GLuint i;
990 GET_CURRENT_CONTEXT(ctx);
991 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx); /* sideeffects */
992
993 if (!ctx->Extensions.EXT_histogram && !ctx->Extensions.ARB_imaging) {
994 _mesa_error(ctx, GL_INVALID_OPERATION, "glResetHistogram");
995 return;
996 }
997
998 if (target != GL_HISTOGRAM) {
999 _mesa_error(ctx, GL_INVALID_ENUM, "glResetHistogram(target)");
1000 return;
1001 }
1002
1003 for (i = 0; i < HISTOGRAM_TABLE_SIZE; i++) {
1004 ctx->Histogram.Count[i][0] = 0;
1005 ctx->Histogram.Count[i][1] = 0;
1006 ctx->Histogram.Count[i][2] = 0;
1007 ctx->Histogram.Count[i][3] = 0;
1008 }
1009
1010 ctx->NewState |= _NEW_PIXEL;
1011 }
1012
1013
1014 void
1015 _mesa_ResetMinmax(GLenum target)
1016 {
1017 GET_CURRENT_CONTEXT(ctx);
1018 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx);
1019
1020 if (!ctx->Extensions.EXT_histogram && !ctx->Extensions.ARB_imaging) {
1021 _mesa_error(ctx, GL_INVALID_OPERATION, "glResetMinmax");
1022 return;
1023 }
1024
1025 if (target != GL_MINMAX) {
1026 _mesa_error(ctx, GL_INVALID_ENUM, "glResetMinMax(target)");
1027 return;
1028 }
1029
1030 ctx->MinMax.Min[RCOMP] = 1000; ctx->MinMax.Max[RCOMP] = -1000;
1031 ctx->MinMax.Min[GCOMP] = 1000; ctx->MinMax.Max[GCOMP] = -1000;
1032 ctx->MinMax.Min[BCOMP] = 1000; ctx->MinMax.Max[BCOMP] = -1000;
1033 ctx->MinMax.Min[ACOMP] = 1000; ctx->MinMax.Max[ACOMP] = -1000;
1034 ctx->NewState |= _NEW_PIXEL;
1035 }