3 * Mesa 3-D graphics library
6 * Copyright (C) 1999-2003 Brian Paul All Rights Reserved.
8 * Permission is hereby granted, free of charge, to any person obtaining a
9 * copy of this software and associated documentation files (the "Software"),
10 * to deal in the Software without restriction, including without limitation
11 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
12 * and/or sell copies of the Software, and to permit persons to whom the
13 * Software is furnished to do so, subject to the following conditions:
15 * The above copyright notice and this permission notice shall be included
16 * in all copies or substantial portions of the Software.
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
19 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
21 * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
22 * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
23 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
31 #include "histogram.h"
34 /**********************************************************************
40 * Update the min/max values from an array of fragment colors.
43 _mesa_update_minmax(GLcontext
*ctx
, GLuint n
, const GLfloat rgba
[][4])
46 for (i
= 0; i
< n
; i
++) {
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
];
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
];
71 * Update the histogram values from an array of fragment colors.
74 _mesa_update_histogram(GLcontext
*ctx
, GLuint n
, const GLfloat rgba
[][4])
76 const GLint max
= ctx
->Histogram
.Width
- 1;
77 GLfloat w
= (GLfloat
) max
;
80 if (ctx
->Histogram
.Width
== 0)
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
]++;
101 * XXX the packed pixel formats haven't been tested.
104 pack_histogram( GLcontext
*ctx
,
105 GLuint n
, CONST GLuint rgba
[][4],
106 GLenum format
, GLenum type
, GLvoid
*destination
,
107 const struct gl_pixelstore_attrib
*packing
)
109 const GLint comps
= _mesa_components_in_format(format
);
110 GLuint luminance
[MAX_WIDTH
];
112 if (format
== GL_LUMINANCE
|| format
== GL_LUMINANCE_ALPHA
) {
114 for (i
= 0; i
< n
; i
++) {
115 luminance
[i
] = rgba
[i
][RCOMP
] + rgba
[i
][GCOMP
] + rgba
[i
][BCOMP
];
119 #define PACK_MACRO(TYPE) \
125 dst[i] = (TYPE) rgba[i][RCOMP]; \
129 dst[i] = (TYPE) rgba[i][GCOMP]; \
133 dst[i] = (TYPE) rgba[i][BCOMP]; \
137 dst[i] = (TYPE) rgba[i][ACOMP]; \
141 dst[i] = (TYPE) luminance[i]; \
143 case GL_LUMINANCE_ALPHA: \
144 for (i=0;i<n;i++) { \
145 dst[i*2+0] = (TYPE) luminance[i]; \
146 dst[i*2+1] = (TYPE) rgba[i][ACOMP]; \
150 for (i=0;i<n;i++) { \
151 dst[i*3+0] = (TYPE) rgba[i][RCOMP]; \
152 dst[i*3+1] = (TYPE) rgba[i][GCOMP]; \
153 dst[i*3+2] = (TYPE) rgba[i][BCOMP]; \
157 for (i=0;i<n;i++) { \
158 dst[i*4+0] = (TYPE) rgba[i][RCOMP]; \
159 dst[i*4+1] = (TYPE) rgba[i][GCOMP]; \
160 dst[i*4+2] = (TYPE) rgba[i][BCOMP]; \
161 dst[i*4+3] = (TYPE) rgba[i][ACOMP]; \
165 for (i=0;i<n;i++) { \
166 dst[i*3+0] = (TYPE) rgba[i][BCOMP]; \
167 dst[i*3+1] = (TYPE) rgba[i][GCOMP]; \
168 dst[i*3+2] = (TYPE) rgba[i][RCOMP]; \
172 for (i=0;i<n;i++) { \
173 dst[i*4+0] = (TYPE) rgba[i][BCOMP]; \
174 dst[i*4+1] = (TYPE) rgba[i][GCOMP]; \
175 dst[i*4+2] = (TYPE) rgba[i][RCOMP]; \
176 dst[i*4+3] = (TYPE) rgba[i][ACOMP]; \
180 for (i=0;i<n;i++) { \
181 dst[i*4+0] = (TYPE) rgba[i][ACOMP]; \
182 dst[i*4+1] = (TYPE) rgba[i][BCOMP]; \
183 dst[i*4+2] = (TYPE) rgba[i][GCOMP]; \
184 dst[i*4+3] = (TYPE) rgba[i][RCOMP]; \
188 _mesa_problem(ctx, "bad format in pack_histogram"); \
193 case GL_UNSIGNED_BYTE
:
195 GLubyte
*dst
= (GLubyte
*) destination
;
201 GLbyte
*dst
= (GLbyte
*) destination
;
205 case GL_UNSIGNED_SHORT
:
207 GLushort
*dst
= (GLushort
*) destination
;
208 PACK_MACRO(GLushort
);
209 if (packing
->SwapBytes
) {
210 _mesa_swap2(dst
, n
* comps
);
216 GLshort
*dst
= (GLshort
*) destination
;
218 if (packing
->SwapBytes
) {
219 _mesa_swap2((GLushort
*) dst
, n
* comps
);
223 case GL_UNSIGNED_INT
:
225 GLuint
*dst
= (GLuint
*) destination
;
227 if (packing
->SwapBytes
) {
228 _mesa_swap4(dst
, n
* comps
);
234 GLint
*dst
= (GLint
*) destination
;
236 if (packing
->SwapBytes
) {
237 _mesa_swap4((GLuint
*) dst
, n
* comps
);
243 GLfloat
*dst
= (GLfloat
*) destination
;
245 if (packing
->SwapBytes
) {
246 _mesa_swap4((GLuint
*) dst
, n
* comps
);
250 case GL_UNSIGNED_BYTE_3_3_2
:
251 if (format
== GL_RGB
) {
252 GLubyte
*dst
= (GLubyte
*) destination
;
254 for (i
= 0; i
< n
; i
++) {
255 dst
[i
] = ((rgba
[i
][RCOMP
] & 0x7) << 5)
256 | ((rgba
[i
][GCOMP
] & 0x7) << 2)
257 | ((rgba
[i
][BCOMP
] & 0x3) );
261 GLubyte
*dst
= (GLubyte
*) destination
;
263 ASSERT(format
== GL_BGR
);
264 for (i
= 0; i
< n
; i
++) {
265 dst
[i
] = ((rgba
[i
][BCOMP
] & 0x7) << 5)
266 | ((rgba
[i
][GCOMP
] & 0x7) << 2)
267 | ((rgba
[i
][RCOMP
] & 0x3) );
271 case GL_UNSIGNED_BYTE_2_3_3_REV
:
272 if (format
== GL_RGB
) {
273 GLubyte
*dst
= (GLubyte
*) destination
;
275 for (i
= 0; i
< n
; i
++) {
276 dst
[i
] = ((rgba
[i
][RCOMP
] & 0x3) << 6)
277 | ((rgba
[i
][GCOMP
] & 0x7) << 3)
278 | ((rgba
[i
][BCOMP
] & 0x7) );
282 GLubyte
*dst
= (GLubyte
*) destination
;
284 ASSERT(format
== GL_BGR
);
285 for (i
= 0; i
< n
; i
++) {
286 dst
[i
] = ((rgba
[i
][BCOMP
] & 0x3) << 6)
287 | ((rgba
[i
][GCOMP
] & 0x7) << 3)
288 | ((rgba
[i
][RCOMP
] & 0x7) );
292 case GL_UNSIGNED_SHORT_5_6_5
:
293 if (format
== GL_RGB
) {
294 GLushort
*dst
= (GLushort
*) destination
;
296 for (i
= 0; i
< n
; i
++) {
297 dst
[i
] = ((rgba
[i
][RCOMP
] & 0x1f) << 11)
298 | ((rgba
[i
][GCOMP
] & 0x3f) << 5)
299 | ((rgba
[i
][BCOMP
] & 0x1f) );
303 GLushort
*dst
= (GLushort
*) destination
;
305 ASSERT(format
== GL_BGR
);
306 for (i
= 0; i
< n
; i
++) {
307 dst
[i
] = ((rgba
[i
][BCOMP
] & 0x1f) << 11)
308 | ((rgba
[i
][GCOMP
] & 0x3f) << 5)
309 | ((rgba
[i
][RCOMP
] & 0x1f) );
313 case GL_UNSIGNED_SHORT_5_6_5_REV
:
314 if (format
== GL_RGB
) {
315 GLushort
*dst
= (GLushort
*) destination
;
317 for (i
= 0; i
< n
; i
++) {
318 dst
[i
] = ((rgba
[i
][BCOMP
] & 0x1f) << 11)
319 | ((rgba
[i
][GCOMP
] & 0x3f) << 5)
320 | ((rgba
[i
][RCOMP
] & 0x1f) );
324 GLushort
*dst
= (GLushort
*) destination
;
326 ASSERT(format
== GL_BGR
);
327 for (i
= 0; i
< n
; i
++) {
328 dst
[i
] = ((rgba
[i
][RCOMP
] & 0x1f) << 11)
329 | ((rgba
[i
][GCOMP
] & 0x3f) << 5)
330 | ((rgba
[i
][BCOMP
] & 0x1f) );
334 case GL_UNSIGNED_SHORT_4_4_4_4
:
335 if (format
== GL_RGBA
) {
336 GLushort
*dst
= (GLushort
*) destination
;
338 for (i
= 0; i
< n
; i
++) {
339 dst
[i
] = ((rgba
[i
][RCOMP
] & 0xf) << 12)
340 | ((rgba
[i
][GCOMP
] & 0xf) << 8)
341 | ((rgba
[i
][BCOMP
] & 0xf) << 4)
342 | ((rgba
[i
][ACOMP
] & 0xf) );
345 else if (format
== GL_BGRA
) {
346 GLushort
*dst
= (GLushort
*) destination
;
348 for (i
= 0; i
< n
; i
++) {
349 dst
[i
] = ((rgba
[i
][BCOMP
] & 0xf) << 12)
350 | ((rgba
[i
][GCOMP
] & 0xf) << 8)
351 | ((rgba
[i
][RCOMP
] & 0xf) << 4)
352 | ((rgba
[i
][ACOMP
] & 0xf) );
356 GLushort
*dst
= (GLushort
*) destination
;
358 ASSERT(format
== GL_ABGR_EXT
);
359 for (i
= 0; i
< n
; i
++) {
360 dst
[i
] = ((rgba
[i
][ACOMP
] & 0xf) << 12)
361 | ((rgba
[i
][BCOMP
] & 0xf) << 8)
362 | ((rgba
[i
][GCOMP
] & 0xf) << 4)
363 | ((rgba
[i
][RCOMP
] & 0xf) );
367 case GL_UNSIGNED_SHORT_4_4_4_4_REV
:
368 if (format
== GL_RGBA
) {
369 GLushort
*dst
= (GLushort
*) destination
;
371 for (i
= 0; i
< n
; i
++) {
372 dst
[i
] = ((rgba
[i
][ACOMP
] & 0xf) << 12)
373 | ((rgba
[i
][BCOMP
] & 0xf) << 8)
374 | ((rgba
[i
][GCOMP
] & 0xf) << 4)
375 | ((rgba
[i
][RCOMP
] & 0xf) );
378 else if (format
== GL_BGRA
) {
379 GLushort
*dst
= (GLushort
*) destination
;
381 for (i
= 0; i
< n
; i
++) {
382 dst
[i
] = ((rgba
[i
][ACOMP
] & 0xf) << 12)
383 | ((rgba
[i
][RCOMP
] & 0xf) << 8)
384 | ((rgba
[i
][GCOMP
] & 0xf) << 4)
385 | ((rgba
[i
][BCOMP
] & 0xf) );
389 GLushort
*dst
= (GLushort
*) destination
;
391 ASSERT(format
== GL_ABGR_EXT
);
392 for (i
= 0; i
< n
; i
++) {
393 dst
[i
] = ((rgba
[i
][RCOMP
] & 0xf) << 12)
394 | ((rgba
[i
][GCOMP
] & 0xf) << 8)
395 | ((rgba
[i
][BCOMP
] & 0xf) << 4)
396 | ((rgba
[i
][ACOMP
] & 0xf) );
400 case GL_UNSIGNED_SHORT_5_5_5_1
:
401 if (format
== GL_RGBA
) {
402 GLushort
*dst
= (GLushort
*) destination
;
404 for (i
= 0; i
< n
; i
++) {
405 dst
[i
] = ((rgba
[i
][RCOMP
] & 0x1f) << 11)
406 | ((rgba
[i
][GCOMP
] & 0x1f) << 6)
407 | ((rgba
[i
][BCOMP
] & 0x1f) << 1)
408 | ((rgba
[i
][ACOMP
] & 0x1) );
411 else if (format
== GL_BGRA
) {
412 GLushort
*dst
= (GLushort
*) destination
;
414 for (i
= 0; i
< n
; i
++) {
415 dst
[i
] = ((rgba
[i
][BCOMP
] & 0x1f) << 11)
416 | ((rgba
[i
][GCOMP
] & 0x1f) << 6)
417 | ((rgba
[i
][RCOMP
] & 0x1f) << 1)
418 | ((rgba
[i
][ACOMP
] & 0x1) );
422 GLushort
*dst
= (GLushort
*) destination
;
424 ASSERT(format
== GL_ABGR_EXT
);
425 for (i
= 0; i
< n
; i
++) {
426 dst
[i
] = ((rgba
[i
][ACOMP
] & 0x1f) << 11)
427 | ((rgba
[i
][BCOMP
] & 0x1f) << 6)
428 | ((rgba
[i
][GCOMP
] & 0x1f) << 1)
429 | ((rgba
[i
][RCOMP
] & 0x1) );
433 case GL_UNSIGNED_SHORT_1_5_5_5_REV
:
434 if (format
== GL_RGBA
) {
435 GLushort
*dst
= (GLushort
*) destination
;
437 for (i
= 0; i
< n
; i
++) {
438 dst
[i
] = ((rgba
[i
][ACOMP
] & 0x1f) << 11)
439 | ((rgba
[i
][BCOMP
] & 0x1f) << 6)
440 | ((rgba
[i
][GCOMP
] & 0x1f) << 1)
441 | ((rgba
[i
][RCOMP
] & 0x1) );
444 else if (format
== GL_BGRA
) {
445 GLushort
*dst
= (GLushort
*) destination
;
447 for (i
= 0; i
< n
; i
++) {
448 dst
[i
] = ((rgba
[i
][ACOMP
] & 0x1f) << 11)
449 | ((rgba
[i
][RCOMP
] & 0x1f) << 6)
450 | ((rgba
[i
][GCOMP
] & 0x1f) << 1)
451 | ((rgba
[i
][BCOMP
] & 0x1) );
455 GLushort
*dst
= (GLushort
*) destination
;
457 ASSERT(format
== GL_ABGR_EXT
);
458 for (i
= 0; i
< n
; i
++) {
459 dst
[i
] = ((rgba
[i
][RCOMP
] & 0x1f) << 11)
460 | ((rgba
[i
][GCOMP
] & 0x1f) << 6)
461 | ((rgba
[i
][BCOMP
] & 0x1f) << 1)
462 | ((rgba
[i
][ACOMP
] & 0x1) );
466 case GL_UNSIGNED_INT_8_8_8_8
:
467 if (format
== GL_RGBA
) {
468 GLuint
*dst
= (GLuint
*) destination
;
470 for (i
= 0; i
< n
; i
++) {
471 dst
[i
] = ((rgba
[i
][RCOMP
] & 0xff) << 24)
472 | ((rgba
[i
][GCOMP
] & 0xff) << 16)
473 | ((rgba
[i
][BCOMP
] & 0xff) << 8)
474 | ((rgba
[i
][ACOMP
] & 0xff) );
477 else if (format
== GL_BGRA
) {
478 GLuint
*dst
= (GLuint
*) destination
;
480 for (i
= 0; i
< n
; i
++) {
481 dst
[i
] = ((rgba
[i
][BCOMP
] & 0xff) << 24)
482 | ((rgba
[i
][GCOMP
] & 0xff) << 16)
483 | ((rgba
[i
][RCOMP
] & 0xff) << 8)
484 | ((rgba
[i
][ACOMP
] & 0xff) );
488 GLuint
*dst
= (GLuint
*) destination
;
490 ASSERT(format
== GL_ABGR_EXT
);
491 for (i
= 0; i
< n
; i
++) {
492 dst
[i
] = ((rgba
[i
][ACOMP
] & 0xff) << 24)
493 | ((rgba
[i
][BCOMP
] & 0xff) << 16)
494 | ((rgba
[i
][GCOMP
] & 0xff) << 8)
495 | ((rgba
[i
][RCOMP
] & 0xff) );
499 case GL_UNSIGNED_INT_8_8_8_8_REV
:
500 if (format
== GL_RGBA
) {
501 GLuint
*dst
= (GLuint
*) destination
;
503 for (i
= 0; i
< n
; i
++) {
504 dst
[i
] = ((rgba
[i
][ACOMP
] & 0xff) << 24)
505 | ((rgba
[i
][BCOMP
] & 0xff) << 16)
506 | ((rgba
[i
][GCOMP
] & 0xff) << 8)
507 | ((rgba
[i
][RCOMP
] & 0xff) );
510 else if (format
== GL_BGRA
) {
511 GLuint
*dst
= (GLuint
*) destination
;
513 for (i
= 0; i
< n
; i
++) {
514 dst
[i
] = ((rgba
[i
][ACOMP
] & 0xff) << 24)
515 | ((rgba
[i
][RCOMP
] & 0xff) << 16)
516 | ((rgba
[i
][GCOMP
] & 0xff) << 8)
517 | ((rgba
[i
][BCOMP
] & 0xff) );
521 GLuint
*dst
= (GLuint
*) destination
;
523 ASSERT(format
== GL_ABGR_EXT
);
524 for (i
= 0; i
< n
; i
++) {
525 dst
[i
] = ((rgba
[i
][RCOMP
] & 0xff) << 24)
526 | ((rgba
[i
][GCOMP
] & 0xff) << 16)
527 | ((rgba
[i
][BCOMP
] & 0xff) << 8)
528 | ((rgba
[i
][ACOMP
] & 0xff) );
532 case GL_UNSIGNED_INT_10_10_10_2
:
533 if (format
== GL_RGBA
) {
534 GLuint
*dst
= (GLuint
*) destination
;
536 for (i
= 0; i
< n
; i
++) {
537 dst
[i
] = ((rgba
[i
][RCOMP
] & 0x3ff) << 22)
538 | ((rgba
[i
][GCOMP
] & 0x3ff) << 12)
539 | ((rgba
[i
][BCOMP
] & 0x3ff) << 2)
540 | ((rgba
[i
][ACOMP
] & 0x3) );
543 else if (format
== GL_BGRA
) {
544 GLuint
*dst
= (GLuint
*) destination
;
546 for (i
= 0; i
< n
; i
++) {
547 dst
[i
] = ((rgba
[i
][BCOMP
] & 0x3ff) << 22)
548 | ((rgba
[i
][GCOMP
] & 0x3ff) << 12)
549 | ((rgba
[i
][RCOMP
] & 0x3ff) << 2)
550 | ((rgba
[i
][ACOMP
] & 0x3) );
554 GLuint
*dst
= (GLuint
*) destination
;
556 ASSERT(format
== GL_ABGR_EXT
);
557 for (i
= 0; i
< n
; i
++) {
558 dst
[i
] = ((rgba
[i
][ACOMP
] & 0x3ff) << 22)
559 | ((rgba
[i
][BCOMP
] & 0x3ff) << 12)
560 | ((rgba
[i
][GCOMP
] & 0x3ff) << 2)
561 | ((rgba
[i
][RCOMP
] & 0x3) );
565 case GL_UNSIGNED_INT_2_10_10_10_REV
:
566 if (format
== GL_RGBA
) {
567 GLuint
*dst
= (GLuint
*) destination
;
569 for (i
= 0; i
< n
; i
++) {
570 dst
[i
] = ((rgba
[i
][ACOMP
] & 0x3ff) << 22)
571 | ((rgba
[i
][BCOMP
] & 0x3ff) << 12)
572 | ((rgba
[i
][GCOMP
] & 0x3ff) << 2)
573 | ((rgba
[i
][RCOMP
] & 0x3) );
576 else if (format
== GL_BGRA
) {
577 GLuint
*dst
= (GLuint
*) destination
;
579 for (i
= 0; i
< n
; i
++) {
580 dst
[i
] = ((rgba
[i
][ACOMP
] & 0x3ff) << 22)
581 | ((rgba
[i
][RCOMP
] & 0x3ff) << 12)
582 | ((rgba
[i
][GCOMP
] & 0x3ff) << 2)
583 | ((rgba
[i
][BCOMP
] & 0x3) );
587 GLuint
*dst
= (GLuint
*) destination
;
589 ASSERT(format
== GL_ABGR_EXT
);
590 for (i
= 0; i
< n
; i
++) {
591 dst
[i
] = ((rgba
[i
][RCOMP
] & 0x3ff) << 22)
592 | ((rgba
[i
][GCOMP
] & 0x3ff) << 12)
593 | ((rgba
[i
][BCOMP
] & 0x3ff) << 2)
594 | ((rgba
[i
][ACOMP
] & 0x3) );
599 _mesa_problem(ctx
, "Bad type in pack_histogram");
607 * Given an internalFormat token passed to glHistogram or glMinMax,
608 * return the corresponding base format.
609 * Return -1 if invalid token.
612 base_histogram_format( GLenum format
)
627 case GL_LUMINANCE_ALPHA
:
628 case GL_LUMINANCE4_ALPHA4
:
629 case GL_LUMINANCE6_ALPHA2
:
630 case GL_LUMINANCE8_ALPHA8
:
631 case GL_LUMINANCE12_ALPHA4
:
632 case GL_LUMINANCE12_ALPHA12
:
633 case GL_LUMINANCE16_ALPHA16
:
634 return GL_LUMINANCE_ALPHA
;
654 return -1; /* error */
660 /**********************************************************************
666 _mesa_GetMinmax(GLenum target
, GLboolean reset
, GLenum format
, GLenum type
, GLvoid
*values
)
668 GET_CURRENT_CONTEXT(ctx
);
669 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
671 if (!ctx
->Extensions
.EXT_histogram
&& !ctx
->Extensions
.ARB_imaging
) {
672 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glGetMinmax");
676 if (target
!= GL_MINMAX
) {
677 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetMinmax(target)");
681 if (!_mesa_is_legal_format_and_type(format
, type
)) {
682 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glGetMinmax(format or type)");
686 if (type
!= GL_UNSIGNED_BYTE
&&
688 type
!= GL_UNSIGNED_SHORT
&&
690 type
!= GL_UNSIGNED_INT
&&
693 type
!= GL_UNSIGNED_BYTE_3_3_2
&&
694 type
!= GL_UNSIGNED_BYTE_2_3_3_REV
&&
695 type
!= GL_UNSIGNED_SHORT_5_6_5
&&
696 type
!= GL_UNSIGNED_SHORT_5_6_5_REV
&&
697 type
!= GL_UNSIGNED_SHORT_4_4_4_4
&&
698 type
!= GL_UNSIGNED_SHORT_4_4_4_4_REV
&&
699 type
!= GL_UNSIGNED_SHORT_5_5_5_1
&&
700 type
!= GL_UNSIGNED_SHORT_1_5_5_5_REV
&&
701 type
!= GL_UNSIGNED_INT_8_8_8_8
&&
702 type
!= GL_UNSIGNED_INT_8_8_8_8_REV
&&
703 type
!= GL_UNSIGNED_INT_10_10_10_2
&&
704 type
!= GL_UNSIGNED_INT_2_10_10_10_REV
) {
705 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetMinmax(type)");
713 GLfloat minmax
[2][4];
714 minmax
[0][RCOMP
] = CLAMP(ctx
->MinMax
.Min
[RCOMP
], 0.0F
, 1.0F
);
715 minmax
[0][GCOMP
] = CLAMP(ctx
->MinMax
.Min
[GCOMP
], 0.0F
, 1.0F
);
716 minmax
[0][BCOMP
] = CLAMP(ctx
->MinMax
.Min
[BCOMP
], 0.0F
, 1.0F
);
717 minmax
[0][ACOMP
] = CLAMP(ctx
->MinMax
.Min
[ACOMP
], 0.0F
, 1.0F
);
718 minmax
[1][RCOMP
] = CLAMP(ctx
->MinMax
.Max
[RCOMP
], 0.0F
, 1.0F
);
719 minmax
[1][GCOMP
] = CLAMP(ctx
->MinMax
.Max
[GCOMP
], 0.0F
, 1.0F
);
720 minmax
[1][BCOMP
] = CLAMP(ctx
->MinMax
.Max
[BCOMP
], 0.0F
, 1.0F
);
721 minmax
[1][ACOMP
] = CLAMP(ctx
->MinMax
.Max
[ACOMP
], 0.0F
, 1.0F
);
722 _mesa_pack_float_rgba_span(ctx
, 2, (CONST
GLfloat (*)[4]) minmax
,
723 format
, type
, values
, &ctx
->Pack
, 0);
727 _mesa_ResetMinmax(GL_MINMAX
);
733 _mesa_GetHistogram(GLenum target
, GLboolean reset
, GLenum format
, GLenum type
, GLvoid
*values
)
735 GET_CURRENT_CONTEXT(ctx
);
736 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
738 if (!ctx
->Extensions
.EXT_histogram
&& !ctx
->Extensions
.ARB_imaging
) {
739 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glGetHistogram");
743 if (target
!= GL_HISTOGRAM
) {
744 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetHistogram(target)");
748 if (!_mesa_is_legal_format_and_type(format
, type
)) {
749 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glGetHistogram(format or type)");
753 if (type
!= GL_UNSIGNED_BYTE
&&
755 type
!= GL_UNSIGNED_SHORT
&&
757 type
!= GL_UNSIGNED_INT
&&
760 type
!= GL_UNSIGNED_BYTE_3_3_2
&&
761 type
!= GL_UNSIGNED_BYTE_2_3_3_REV
&&
762 type
!= GL_UNSIGNED_SHORT_5_6_5
&&
763 type
!= GL_UNSIGNED_SHORT_5_6_5_REV
&&
764 type
!= GL_UNSIGNED_SHORT_4_4_4_4
&&
765 type
!= GL_UNSIGNED_SHORT_4_4_4_4_REV
&&
766 type
!= GL_UNSIGNED_SHORT_5_5_5_1
&&
767 type
!= GL_UNSIGNED_SHORT_1_5_5_5_REV
&&
768 type
!= GL_UNSIGNED_INT_8_8_8_8
&&
769 type
!= GL_UNSIGNED_INT_8_8_8_8_REV
&&
770 type
!= GL_UNSIGNED_INT_10_10_10_2
&&
771 type
!= GL_UNSIGNED_INT_2_10_10_10_REV
) {
772 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetHistogram(type)");
779 pack_histogram(ctx
, ctx
->Histogram
.Width
,
780 (CONST
GLuint (*)[4]) ctx
->Histogram
.Count
,
781 format
, type
, values
, &ctx
->Pack
);
785 for (i
= 0; i
< HISTOGRAM_TABLE_SIZE
; i
++) {
786 ctx
->Histogram
.Count
[i
][0] = 0;
787 ctx
->Histogram
.Count
[i
][1] = 0;
788 ctx
->Histogram
.Count
[i
][2] = 0;
789 ctx
->Histogram
.Count
[i
][3] = 0;
796 _mesa_GetHistogramParameterfv(GLenum target
, GLenum pname
, GLfloat
*params
)
798 GET_CURRENT_CONTEXT(ctx
);
799 ASSERT_OUTSIDE_BEGIN_END(ctx
);
801 if (!ctx
->Extensions
.EXT_histogram
&& !ctx
->Extensions
.ARB_imaging
) {
802 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glGetHistogramParameterfv");
806 if (target
!= GL_HISTOGRAM
&& target
!= GL_PROXY_HISTOGRAM
) {
807 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetHistogramParameterfv(target)");
812 case GL_HISTOGRAM_WIDTH
:
813 *params
= (GLfloat
) ctx
->Histogram
.Width
;
815 case GL_HISTOGRAM_FORMAT
:
816 *params
= (GLfloat
) ctx
->Histogram
.Format
;
818 case GL_HISTOGRAM_RED_SIZE
:
819 *params
= (GLfloat
) ctx
->Histogram
.RedSize
;
821 case GL_HISTOGRAM_GREEN_SIZE
:
822 *params
= (GLfloat
) ctx
->Histogram
.GreenSize
;
824 case GL_HISTOGRAM_BLUE_SIZE
:
825 *params
= (GLfloat
) ctx
->Histogram
.BlueSize
;
827 case GL_HISTOGRAM_ALPHA_SIZE
:
828 *params
= (GLfloat
) ctx
->Histogram
.AlphaSize
;
830 case GL_HISTOGRAM_LUMINANCE_SIZE
:
831 *params
= (GLfloat
) ctx
->Histogram
.LuminanceSize
;
833 case GL_HISTOGRAM_SINK
:
834 *params
= (GLfloat
) ctx
->Histogram
.Sink
;
837 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetHistogramParameterfv(pname)");
843 _mesa_GetHistogramParameteriv(GLenum target
, GLenum pname
, GLint
*params
)
845 GET_CURRENT_CONTEXT(ctx
);
846 ASSERT_OUTSIDE_BEGIN_END(ctx
);
848 if (!ctx
->Extensions
.EXT_histogram
&& !ctx
->Extensions
.ARB_imaging
) {
849 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glGetHistogramParameteriv");
853 if (target
!= GL_HISTOGRAM
&& target
!= GL_PROXY_HISTOGRAM
) {
854 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetHistogramParameteriv(target)");
859 case GL_HISTOGRAM_WIDTH
:
860 *params
= (GLint
) ctx
->Histogram
.Width
;
862 case GL_HISTOGRAM_FORMAT
:
863 *params
= (GLint
) ctx
->Histogram
.Format
;
865 case GL_HISTOGRAM_RED_SIZE
:
866 *params
= (GLint
) ctx
->Histogram
.RedSize
;
868 case GL_HISTOGRAM_GREEN_SIZE
:
869 *params
= (GLint
) ctx
->Histogram
.GreenSize
;
871 case GL_HISTOGRAM_BLUE_SIZE
:
872 *params
= (GLint
) ctx
->Histogram
.BlueSize
;
874 case GL_HISTOGRAM_ALPHA_SIZE
:
875 *params
= (GLint
) ctx
->Histogram
.AlphaSize
;
877 case GL_HISTOGRAM_LUMINANCE_SIZE
:
878 *params
= (GLint
) ctx
->Histogram
.LuminanceSize
;
880 case GL_HISTOGRAM_SINK
:
881 *params
= (GLint
) ctx
->Histogram
.Sink
;
884 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetHistogramParameteriv(pname)");
890 _mesa_GetMinmaxParameterfv(GLenum target
, GLenum pname
, GLfloat
*params
)
892 GET_CURRENT_CONTEXT(ctx
);
893 ASSERT_OUTSIDE_BEGIN_END(ctx
);
895 if (!ctx
->Extensions
.EXT_histogram
&& !ctx
->Extensions
.ARB_imaging
) {
896 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glGetMinmaxParameterfv");
899 if (target
!= GL_MINMAX
) {
900 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetMinmaxParameterfv(target)");
903 if (pname
== GL_MINMAX_FORMAT
) {
904 *params
= (GLfloat
) ctx
->MinMax
.Format
;
906 else if (pname
== GL_MINMAX_SINK
) {
907 *params
= (GLfloat
) ctx
->MinMax
.Sink
;
910 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetMinMaxParameterfv(pname)");
916 _mesa_GetMinmaxParameteriv(GLenum target
, GLenum pname
, GLint
*params
)
918 GET_CURRENT_CONTEXT(ctx
);
919 ASSERT_OUTSIDE_BEGIN_END(ctx
);
921 if (!ctx
->Extensions
.EXT_histogram
&& !ctx
->Extensions
.ARB_imaging
) {
922 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glGetMinmaxParameteriv");
925 if (target
!= GL_MINMAX
) {
926 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetMinmaxParameteriv(target)");
929 if (pname
== GL_MINMAX_FORMAT
) {
930 *params
= (GLint
) ctx
->MinMax
.Format
;
932 else if (pname
== GL_MINMAX_SINK
) {
933 *params
= (GLint
) ctx
->MinMax
.Sink
;
936 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetMinMaxParameteriv(pname)");
942 _mesa_Histogram(GLenum target
, GLsizei width
, GLenum internalFormat
, GLboolean sink
)
945 GLboolean error
= GL_FALSE
;
946 GET_CURRENT_CONTEXT(ctx
);
947 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
); /* sideeffects */
949 if (!ctx
->Extensions
.EXT_histogram
&& !ctx
->Extensions
.ARB_imaging
) {
950 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glHistogram");
954 if (target
!= GL_HISTOGRAM
&& target
!= GL_PROXY_HISTOGRAM
) {
955 _mesa_error(ctx
, GL_INVALID_ENUM
, "glHistogram(target)");
959 if (width
< 0 || width
> HISTOGRAM_TABLE_SIZE
) {
960 if (target
== GL_PROXY_HISTOGRAM
) {
965 _mesa_error(ctx
, GL_INVALID_VALUE
, "glHistogram(width)");
967 _mesa_error(ctx
, GL_TABLE_TOO_LARGE
, "glHistogram(width)");
972 if (width
!= 0 && _mesa_bitcount(width
) != 1) {
973 if (target
== GL_PROXY_HISTOGRAM
) {
977 _mesa_error(ctx
, GL_INVALID_VALUE
, "glHistogram(width)");
982 if (base_histogram_format(internalFormat
) < 0) {
983 if (target
== GL_PROXY_HISTOGRAM
) {
987 _mesa_error(ctx
, GL_INVALID_ENUM
, "glHistogram(internalFormat)");
992 /* reset histograms */
993 for (i
= 0; i
< HISTOGRAM_TABLE_SIZE
; i
++) {
994 ctx
->Histogram
.Count
[i
][0] = 0;
995 ctx
->Histogram
.Count
[i
][1] = 0;
996 ctx
->Histogram
.Count
[i
][2] = 0;
997 ctx
->Histogram
.Count
[i
][3] = 0;
1001 ctx
->Histogram
.Width
= 0;
1002 ctx
->Histogram
.Format
= 0;
1003 ctx
->Histogram
.RedSize
= 0;
1004 ctx
->Histogram
.GreenSize
= 0;
1005 ctx
->Histogram
.BlueSize
= 0;
1006 ctx
->Histogram
.AlphaSize
= 0;
1007 ctx
->Histogram
.LuminanceSize
= 0;
1010 ctx
->Histogram
.Width
= width
;
1011 ctx
->Histogram
.Format
= internalFormat
;
1012 ctx
->Histogram
.Sink
= sink
;
1013 ctx
->Histogram
.RedSize
= 8 * sizeof(GLuint
);
1014 ctx
->Histogram
.GreenSize
= 8 * sizeof(GLuint
);
1015 ctx
->Histogram
.BlueSize
= 8 * sizeof(GLuint
);
1016 ctx
->Histogram
.AlphaSize
= 8 * sizeof(GLuint
);
1017 ctx
->Histogram
.LuminanceSize
= 8 * sizeof(GLuint
);
1020 ctx
->NewState
|= _NEW_PIXEL
;
1025 _mesa_Minmax(GLenum target
, GLenum internalFormat
, GLboolean sink
)
1027 GET_CURRENT_CONTEXT(ctx
);
1028 ASSERT_OUTSIDE_BEGIN_END(ctx
);
1030 if (!ctx
->Extensions
.EXT_histogram
&& !ctx
->Extensions
.ARB_imaging
) {
1031 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glMinmax");
1035 if (target
!= GL_MINMAX
) {
1036 _mesa_error(ctx
, GL_INVALID_ENUM
, "glMinMax(target)");
1040 if (base_histogram_format(internalFormat
) < 0) {
1041 _mesa_error(ctx
, GL_INVALID_ENUM
, "glMinMax(internalFormat)");
1045 if (ctx
->MinMax
.Sink
== sink
)
1047 FLUSH_VERTICES(ctx
, _NEW_PIXEL
);
1048 ctx
->MinMax
.Sink
= sink
;
1053 _mesa_ResetHistogram(GLenum target
)
1056 GET_CURRENT_CONTEXT(ctx
);
1057 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
); /* sideeffects */
1059 if (!ctx
->Extensions
.EXT_histogram
&& !ctx
->Extensions
.ARB_imaging
) {
1060 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glResetHistogram");
1064 if (target
!= GL_HISTOGRAM
) {
1065 _mesa_error(ctx
, GL_INVALID_ENUM
, "glResetHistogram(target)");
1069 for (i
= 0; i
< HISTOGRAM_TABLE_SIZE
; i
++) {
1070 ctx
->Histogram
.Count
[i
][0] = 0;
1071 ctx
->Histogram
.Count
[i
][1] = 0;
1072 ctx
->Histogram
.Count
[i
][2] = 0;
1073 ctx
->Histogram
.Count
[i
][3] = 0;
1076 ctx
->NewState
|= _NEW_PIXEL
;
1081 _mesa_ResetMinmax(GLenum target
)
1083 GET_CURRENT_CONTEXT(ctx
);
1084 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
1086 if (!ctx
->Extensions
.EXT_histogram
&& !ctx
->Extensions
.ARB_imaging
) {
1087 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glResetMinmax");
1091 if (target
!= GL_MINMAX
) {
1092 _mesa_error(ctx
, GL_INVALID_ENUM
, "glResetMinMax(target)");
1096 ctx
->MinMax
.Min
[RCOMP
] = 1000; ctx
->MinMax
.Max
[RCOMP
] = -1000;
1097 ctx
->MinMax
.Min
[GCOMP
] = 1000; ctx
->MinMax
.Max
[GCOMP
] = -1000;
1098 ctx
->MinMax
.Min
[BCOMP
] = 1000; ctx
->MinMax
.Max
[BCOMP
] = -1000;
1099 ctx
->MinMax
.Min
[ACOMP
] = 1000; ctx
->MinMax
.Max
[ACOMP
] = -1000;
1100 ctx
->NewState
|= _NEW_PIXEL
;