1 /* $Id: histogram.c,v 1.5 2000/12/26 05:09:28 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.
35 #include "histogram.h"
41 * XXX the packed pixel formats haven't been tested.
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
)
49 const GLint comps
= _mesa_components_in_format(format
);
50 GLuint luminance
[MAX_WIDTH
];
52 if (format
== GL_LUMINANCE
|| format
== GL_LUMINANCE_ALPHA
) {
54 for (i
= 0; i
< n
; i
++) {
55 luminance
[i
] = rgba
[i
][RCOMP
] + rgba
[i
][GCOMP
] + rgba
[i
][BCOMP
];
59 #define PACK_MACRO(TYPE) \
65 dst[i] = (TYPE) rgba[i][RCOMP]; \
69 dst[i] = (TYPE) rgba[i][GCOMP]; \
73 dst[i] = (TYPE) rgba[i][BCOMP]; \
77 dst[i] = (TYPE) rgba[i][ACOMP]; \
81 dst[i] = (TYPE) luminance[i]; \
83 case GL_LUMINANCE_ALPHA: \
85 dst[i*2+0] = (TYPE) luminance[i]; \
86 dst[i*2+1] = (TYPE) rgba[i][ACOMP]; \
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]; \
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]; \
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]; \
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]; \
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]; \
128 gl_problem(ctx, "bad format in pack_histogram"); \
133 case GL_UNSIGNED_BYTE
:
135 GLubyte
*dst
= (GLubyte
*) destination
;
141 GLbyte
*dst
= (GLbyte
*) destination
;
145 case GL_UNSIGNED_SHORT
:
147 GLushort
*dst
= (GLushort
*) destination
;
148 PACK_MACRO(GLushort
);
149 if (packing
->SwapBytes
) {
150 _mesa_swap2(dst
, n
* comps
);
156 GLshort
*dst
= (GLshort
*) destination
;
158 if (packing
->SwapBytes
) {
159 _mesa_swap2((GLushort
*) dst
, n
* comps
);
163 case GL_UNSIGNED_INT
:
165 GLuint
*dst
= (GLuint
*) destination
;
167 if (packing
->SwapBytes
) {
168 _mesa_swap4(dst
, n
* comps
);
174 GLint
*dst
= (GLint
*) destination
;
176 if (packing
->SwapBytes
) {
177 _mesa_swap4((GLuint
*) dst
, n
* comps
);
183 GLfloat
*dst
= (GLfloat
*) destination
;
185 if (packing
->SwapBytes
) {
186 _mesa_swap4((GLuint
*) dst
, n
* comps
);
190 case GL_UNSIGNED_BYTE_3_3_2
:
191 if (format
== GL_RGB
) {
192 GLubyte
*dst
= (GLubyte
*) destination
;
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) );
201 GLubyte
*dst
= (GLubyte
*) destination
;
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) );
211 case GL_UNSIGNED_BYTE_2_3_3_REV
:
212 if (format
== GL_RGB
) {
213 GLubyte
*dst
= (GLubyte
*) destination
;
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) );
222 GLubyte
*dst
= (GLubyte
*) destination
;
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) );
232 case GL_UNSIGNED_SHORT_5_6_5
:
233 if (format
== GL_RGB
) {
234 GLushort
*dst
= (GLushort
*) destination
;
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) );
243 GLushort
*dst
= (GLushort
*) destination
;
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) );
253 case GL_UNSIGNED_SHORT_5_6_5_REV
:
254 if (format
== GL_RGB
) {
255 GLushort
*dst
= (GLushort
*) destination
;
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) );
264 GLushort
*dst
= (GLushort
*) destination
;
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) );
274 case GL_UNSIGNED_SHORT_4_4_4_4
:
275 if (format
== GL_RGBA
) {
276 GLushort
*dst
= (GLushort
*) destination
;
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) );
285 else if (format
== GL_BGRA
) {
286 GLushort
*dst
= (GLushort
*) destination
;
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) );
296 GLushort
*dst
= (GLushort
*) destination
;
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) );
307 case GL_UNSIGNED_SHORT_4_4_4_4_REV
:
308 if (format
== GL_RGBA
) {
309 GLushort
*dst
= (GLushort
*) destination
;
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) );
318 else if (format
== GL_BGRA
) {
319 GLushort
*dst
= (GLushort
*) destination
;
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) );
329 GLushort
*dst
= (GLushort
*) destination
;
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) );
340 case GL_UNSIGNED_SHORT_5_5_5_1
:
341 if (format
== GL_RGBA
) {
342 GLushort
*dst
= (GLushort
*) destination
;
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) );
351 else if (format
== GL_BGRA
) {
352 GLushort
*dst
= (GLushort
*) destination
;
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) );
362 GLushort
*dst
= (GLushort
*) destination
;
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) );
373 case GL_UNSIGNED_SHORT_1_5_5_5_REV
:
374 if (format
== GL_RGBA
) {
375 GLushort
*dst
= (GLushort
*) destination
;
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) );
384 else if (format
== GL_BGRA
) {
385 GLushort
*dst
= (GLushort
*) destination
;
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) );
395 GLushort
*dst
= (GLushort
*) destination
;
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) );
406 case GL_UNSIGNED_INT_8_8_8_8
:
407 if (format
== GL_RGBA
) {
408 GLuint
*dst
= (GLuint
*) destination
;
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) );
417 else if (format
== GL_BGRA
) {
418 GLuint
*dst
= (GLuint
*) destination
;
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) );
428 GLuint
*dst
= (GLuint
*) destination
;
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) );
439 case GL_UNSIGNED_INT_8_8_8_8_REV
:
440 if (format
== GL_RGBA
) {
441 GLuint
*dst
= (GLuint
*) destination
;
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) );
450 else if (format
== GL_BGRA
) {
451 GLuint
*dst
= (GLuint
*) destination
;
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) );
461 GLuint
*dst
= (GLuint
*) destination
;
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) );
472 case GL_UNSIGNED_INT_10_10_10_2
:
473 if (format
== GL_RGBA
) {
474 GLuint
*dst
= (GLuint
*) destination
;
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) );
483 else if (format
== GL_BGRA
) {
484 GLuint
*dst
= (GLuint
*) destination
;
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) );
494 GLuint
*dst
= (GLuint
*) destination
;
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) );
505 case GL_UNSIGNED_INT_2_10_10_10_REV
:
506 if (format
== GL_RGBA
) {
507 GLuint
*dst
= (GLuint
*) destination
;
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) );
516 else if (format
== GL_BGRA
) {
517 GLuint
*dst
= (GLuint
*) destination
;
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) );
527 GLuint
*dst
= (GLuint
*) destination
;
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) );
539 gl_problem(ctx
, "Bad type in pack_histogram");
547 * Given an internalFormat token passed to glHistogram or glMinMax,
548 * return the corresponding base format.
549 * Return -1 if invalid token.
552 base_histogram_format( GLenum format
)
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
;
594 return -1; /* error */
600 _mesa_GetMinmax(GLenum target
, GLboolean reset
, GLenum format
, GLenum type
, GLvoid
*values
)
602 GET_CURRENT_CONTEXT(ctx
);
603 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
605 if (!ctx
->Extensions
.EXT_histogram
) {
606 gl_error(ctx
, GL_INVALID_OPERATION
, "glGetMinmax");
610 if (target
!= GL_MINMAX
) {
611 gl_error(ctx
, GL_INVALID_ENUM
, "glGetMinmax(target)");
615 if (!_mesa_is_legal_format_and_type(format
, type
)) {
616 gl_error(ctx
, GL_INVALID_OPERATION
, "glGetMinmax(format or type)");
620 if (type
!= GL_UNSIGNED_BYTE
&&
622 type
!= GL_UNSIGNED_SHORT
&&
624 type
!= GL_UNSIGNED_INT
&&
627 gl_error(ctx
, GL_INVALID_ENUM
, "glGetMinmax(type)");
635 GLfloat minmax
[2][4];
636 minmax
[0][RCOMP
] = CLAMP(ctx
->MinMax
.Min
[RCOMP
], 0.0F
, 1.0F
);
637 minmax
[0][GCOMP
] = CLAMP(ctx
->MinMax
.Min
[GCOMP
], 0.0F
, 1.0F
);
638 minmax
[0][BCOMP
] = CLAMP(ctx
->MinMax
.Min
[BCOMP
], 0.0F
, 1.0F
);
639 minmax
[0][ACOMP
] = CLAMP(ctx
->MinMax
.Min
[ACOMP
], 0.0F
, 1.0F
);
640 minmax
[1][RCOMP
] = CLAMP(ctx
->MinMax
.Max
[RCOMP
], 0.0F
, 1.0F
);
641 minmax
[1][GCOMP
] = CLAMP(ctx
->MinMax
.Max
[GCOMP
], 0.0F
, 1.0F
);
642 minmax
[1][BCOMP
] = CLAMP(ctx
->MinMax
.Max
[BCOMP
], 0.0F
, 1.0F
);
643 minmax
[1][ACOMP
] = CLAMP(ctx
->MinMax
.Max
[ACOMP
], 0.0F
, 1.0F
);
644 _mesa_pack_float_rgba_span(ctx
, 2, (CONST
GLfloat (*)[4]) minmax
,
645 format
, type
, values
, &ctx
->Pack
, 0);
649 _mesa_ResetMinmax(GL_MINMAX
);
655 _mesa_GetHistogram(GLenum target
, GLboolean reset
, GLenum format
, GLenum type
, GLvoid
*values
)
657 GET_CURRENT_CONTEXT(ctx
);
658 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
660 if (!ctx
->Extensions
.EXT_histogram
) {
661 gl_error(ctx
, GL_INVALID_OPERATION
, "glGetHistogram");
665 if (target
!= GL_HISTOGRAM
) {
666 gl_error(ctx
, GL_INVALID_ENUM
, "glGetHistogram(target)");
670 if (!_mesa_is_legal_format_and_type(format
, type
)) {
671 gl_error(ctx
, GL_INVALID_OPERATION
, "glGetHistogram(format or type)");
675 if (type
!= GL_UNSIGNED_BYTE
&&
677 type
!= GL_UNSIGNED_SHORT
&&
679 type
!= GL_UNSIGNED_INT
&&
682 gl_error(ctx
, GL_INVALID_ENUM
, "glGetHistogram(type)");
689 pack_histogram(ctx
, ctx
->Histogram
.Width
,
690 (CONST
GLuint (*)[4]) ctx
->Histogram
.Count
,
691 format
, type
, values
, &ctx
->Pack
);
695 for (i
= 0; i
< HISTOGRAM_TABLE_SIZE
; i
++) {
696 ctx
->Histogram
.Count
[i
][0] = 0;
697 ctx
->Histogram
.Count
[i
][1] = 0;
698 ctx
->Histogram
.Count
[i
][2] = 0;
699 ctx
->Histogram
.Count
[i
][3] = 0;
706 _mesa_GetHistogramParameterfv(GLenum target
, GLenum pname
, GLfloat
*params
)
708 GET_CURRENT_CONTEXT(ctx
);
709 ASSERT_OUTSIDE_BEGIN_END(ctx
);
711 if (!ctx
->Extensions
.EXT_histogram
) {
712 gl_error(ctx
, GL_INVALID_OPERATION
, "glGetHistogramParameterfv");
716 if (target
!= GL_HISTOGRAM
&& target
!= GL_PROXY_HISTOGRAM
) {
717 gl_error(ctx
, GL_INVALID_ENUM
, "glGetHistogramParameterfv(target)");
722 case GL_HISTOGRAM_WIDTH
:
723 *params
= (GLfloat
) ctx
->Histogram
.Width
;
725 case GL_HISTOGRAM_FORMAT
:
726 *params
= (GLfloat
) ctx
->Histogram
.Format
;
728 case GL_HISTOGRAM_RED_SIZE
:
729 *params
= (GLfloat
) ctx
->Histogram
.RedSize
;
731 case GL_HISTOGRAM_GREEN_SIZE
:
732 *params
= (GLfloat
) ctx
->Histogram
.GreenSize
;
734 case GL_HISTOGRAM_BLUE_SIZE
:
735 *params
= (GLfloat
) ctx
->Histogram
.BlueSize
;
737 case GL_HISTOGRAM_ALPHA_SIZE
:
738 *params
= (GLfloat
) ctx
->Histogram
.AlphaSize
;
740 case GL_HISTOGRAM_LUMINANCE_SIZE
:
741 *params
= (GLfloat
) ctx
->Histogram
.LuminanceSize
;
743 case GL_HISTOGRAM_SINK
:
744 *params
= (GLfloat
) ctx
->Histogram
.Sink
;
747 gl_error(ctx
, GL_INVALID_ENUM
, "glGetHistogramParameterfv(pname)");
753 _mesa_GetHistogramParameteriv(GLenum target
, GLenum pname
, GLint
*params
)
755 GET_CURRENT_CONTEXT(ctx
);
756 ASSERT_OUTSIDE_BEGIN_END(ctx
);
758 if (!ctx
->Extensions
.EXT_histogram
) {
759 gl_error(ctx
, GL_INVALID_OPERATION
, "glGetHistogramParameteriv");
763 if (target
!= GL_HISTOGRAM
&& target
!= GL_PROXY_HISTOGRAM
) {
764 gl_error(ctx
, GL_INVALID_ENUM
, "glGetHistogramParameteriv(target)");
769 case GL_HISTOGRAM_WIDTH
:
770 *params
= (GLint
) ctx
->Histogram
.Width
;
772 case GL_HISTOGRAM_FORMAT
:
773 *params
= (GLint
) ctx
->Histogram
.Format
;
775 case GL_HISTOGRAM_RED_SIZE
:
776 *params
= (GLint
) ctx
->Histogram
.RedSize
;
778 case GL_HISTOGRAM_GREEN_SIZE
:
779 *params
= (GLint
) ctx
->Histogram
.GreenSize
;
781 case GL_HISTOGRAM_BLUE_SIZE
:
782 *params
= (GLint
) ctx
->Histogram
.BlueSize
;
784 case GL_HISTOGRAM_ALPHA_SIZE
:
785 *params
= (GLint
) ctx
->Histogram
.AlphaSize
;
787 case GL_HISTOGRAM_LUMINANCE_SIZE
:
788 *params
= (GLint
) ctx
->Histogram
.LuminanceSize
;
790 case GL_HISTOGRAM_SINK
:
791 *params
= (GLint
) ctx
->Histogram
.Sink
;
794 gl_error(ctx
, GL_INVALID_ENUM
, "glGetHistogramParameteriv(pname)");
800 _mesa_GetMinmaxParameterfv(GLenum target
, GLenum pname
, GLfloat
*params
)
802 GET_CURRENT_CONTEXT(ctx
);
803 ASSERT_OUTSIDE_BEGIN_END(ctx
);
805 if (!ctx
->Extensions
.EXT_histogram
) {
806 gl_error(ctx
, GL_INVALID_OPERATION
, "glGetMinmaxParameterfv");
809 if (target
!= GL_MINMAX
) {
810 gl_error(ctx
, GL_INVALID_ENUM
, "glGetMinmaxParameterfv(target)");
813 if (pname
== GL_MINMAX_FORMAT
) {
814 *params
= (GLfloat
) ctx
->MinMax
.Format
;
816 else if (pname
== GL_MINMAX_SINK
) {
817 *params
= (GLfloat
) ctx
->MinMax
.Sink
;
820 gl_error(ctx
, GL_INVALID_ENUM
, "glGetMinMaxParameterfv(pname)");
826 _mesa_GetMinmaxParameteriv(GLenum target
, GLenum pname
, GLint
*params
)
828 GET_CURRENT_CONTEXT(ctx
);
829 ASSERT_OUTSIDE_BEGIN_END(ctx
);
831 if (!ctx
->Extensions
.EXT_histogram
) {
832 gl_error(ctx
, GL_INVALID_OPERATION
, "glGetMinmaxParameteriv");
835 if (target
!= GL_MINMAX
) {
836 gl_error(ctx
, GL_INVALID_ENUM
, "glGetMinmaxParameteriv(target)");
839 if (pname
== GL_MINMAX_FORMAT
) {
840 *params
= (GLint
) ctx
->MinMax
.Format
;
842 else if (pname
== GL_MINMAX_SINK
) {
843 *params
= (GLint
) ctx
->MinMax
.Sink
;
846 gl_error(ctx
, GL_INVALID_ENUM
, "glGetMinMaxParameteriv(pname)");
852 _mesa_Histogram(GLenum target
, GLsizei width
, GLenum internalFormat
, GLboolean sink
)
855 GLboolean error
= GL_FALSE
;
856 GET_CURRENT_CONTEXT(ctx
);
857 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
); /* sideeffects */
859 if (!ctx
->Extensions
.EXT_histogram
) {
860 gl_error(ctx
, GL_INVALID_OPERATION
, "glHistogram");
864 if (target
!= GL_HISTOGRAM
&& target
!= GL_PROXY_HISTOGRAM
) {
865 gl_error(ctx
, GL_INVALID_ENUM
, "glHistogram(target)");
869 if (width
< 0 || width
> HISTOGRAM_TABLE_SIZE
) {
870 if (target
== GL_PROXY_HISTOGRAM
) {
875 gl_error(ctx
, GL_INVALID_VALUE
, "glHistogram(width)");
877 gl_error(ctx
, GL_TABLE_TOO_LARGE
, "glHistogram(width)");
882 if (width
!= 0 && _mesa_bitcount(width
) != 1) {
883 if (target
== GL_PROXY_HISTOGRAM
) {
887 gl_error(ctx
, GL_INVALID_VALUE
, "glHistogram(width)");
892 if (base_histogram_format(internalFormat
) < 0) {
893 if (target
== GL_PROXY_HISTOGRAM
) {
897 gl_error(ctx
, GL_INVALID_ENUM
, "glHistogram(internalFormat)");
902 /* reset histograms */
903 for (i
= 0; i
< HISTOGRAM_TABLE_SIZE
; i
++) {
904 ctx
->Histogram
.Count
[i
][0] = 0;
905 ctx
->Histogram
.Count
[i
][1] = 0;
906 ctx
->Histogram
.Count
[i
][2] = 0;
907 ctx
->Histogram
.Count
[i
][3] = 0;
911 ctx
->Histogram
.Width
= 0;
912 ctx
->Histogram
.Format
= 0;
913 ctx
->Histogram
.RedSize
= 0;
914 ctx
->Histogram
.GreenSize
= 0;
915 ctx
->Histogram
.BlueSize
= 0;
916 ctx
->Histogram
.AlphaSize
= 0;
917 ctx
->Histogram
.LuminanceSize
= 0;
920 ctx
->Histogram
.Width
= width
;
921 ctx
->Histogram
.Format
= internalFormat
;
922 ctx
->Histogram
.Sink
= sink
;
923 ctx
->Histogram
.RedSize
= 0xffffffff;
924 ctx
->Histogram
.GreenSize
= 0xffffffff;
925 ctx
->Histogram
.BlueSize
= 0xffffffff;
926 ctx
->Histogram
.AlphaSize
= 0xffffffff;
927 ctx
->Histogram
.LuminanceSize
= 0xffffffff;
930 ctx
->NewState
|= _NEW_PIXEL
;
935 _mesa_Minmax(GLenum target
, GLenum internalFormat
, GLboolean sink
)
937 GET_CURRENT_CONTEXT(ctx
);
938 ASSERT_OUTSIDE_BEGIN_END(ctx
);
940 if (!ctx
->Extensions
.EXT_histogram
) {
941 gl_error(ctx
, GL_INVALID_OPERATION
, "glMinmax");
945 if (target
!= GL_MINMAX
) {
946 gl_error(ctx
, GL_INVALID_ENUM
, "glMinMax(target)");
950 if (base_histogram_format(internalFormat
) < 0) {
951 gl_error(ctx
, GL_INVALID_ENUM
, "glMinMax(internalFormat)");
955 if (ctx
->MinMax
.Sink
== sink
)
957 FLUSH_VERTICES(ctx
, _NEW_PIXEL
);
958 ctx
->MinMax
.Sink
= sink
;
963 _mesa_ResetHistogram(GLenum target
)
966 GET_CURRENT_CONTEXT(ctx
);
967 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
); /* sideeffects */
969 if (!ctx
->Extensions
.EXT_histogram
) {
970 gl_error(ctx
, GL_INVALID_OPERATION
, "glResetHistogram");
974 if (target
!= GL_HISTOGRAM
) {
975 gl_error(ctx
, GL_INVALID_ENUM
, "glResetHistogram(target)");
979 for (i
= 0; i
< HISTOGRAM_TABLE_SIZE
; i
++) {
980 ctx
->Histogram
.Count
[i
][0] = 0;
981 ctx
->Histogram
.Count
[i
][1] = 0;
982 ctx
->Histogram
.Count
[i
][2] = 0;
983 ctx
->Histogram
.Count
[i
][3] = 0;
986 ctx
->NewState
|= _NEW_PIXEL
;
991 _mesa_ResetMinmax(GLenum target
)
993 GET_CURRENT_CONTEXT(ctx
);
994 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
996 if (!ctx
->Extensions
.EXT_histogram
) {
997 gl_error(ctx
, GL_INVALID_OPERATION
, "glResetMinmax");
1001 if (target
!= GL_MINMAX
) {
1002 gl_error(ctx
, GL_INVALID_ENUM
, "glResetMinMax(target)");
1006 ctx
->MinMax
.Min
[RCOMP
] = 1000; ctx
->MinMax
.Max
[RCOMP
] = -1000;
1007 ctx
->MinMax
.Min
[GCOMP
] = 1000; ctx
->MinMax
.Max
[GCOMP
] = -1000;
1008 ctx
->MinMax
.Min
[BCOMP
] = 1000; ctx
->MinMax
.Max
[BCOMP
] = -1000;
1009 ctx
->MinMax
.Min
[ACOMP
] = 1000; ctx
->MinMax
.Max
[ACOMP
] = -1000;
1010 ctx
->NewState
|= _NEW_PIXEL
;