1 // BEGIN_COPYRIGHT -*- glean -*-
3 // Copyright (C) 2000 Allen Akin All Rights Reserved.
5 // Permission is hereby granted, free of charge, to any person
6 // obtaining a copy of this software and associated documentation
7 // files (the "Software"), to deal in the Software without
8 // restriction, including without limitation the rights to use,
9 // copy, modify, merge, publish, distribute, sublicense, and/or
10 // sell copies of the Software, and to permit persons to whom the
11 // Software is furnished to do so, subject to the following
14 // The above copyright notice and this permission notice shall be
15 // included in all copies or substantial portions of the
18 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY
19 // KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
20 // WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
21 // PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL ALLEN AKIN BE
22 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
23 // AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF
24 // OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
25 // DEALINGS IN THE SOFTWARE.
31 // codedid.h: tool to map integer IDs into colors, and vice-versa
33 // A note on principles of operation: The OpenGL spec normally allows
34 // a reasonable amount of slop when converting user-specified colors
35 // to a hardware-dependent representation in the framebuffer. One
36 // exception to this lenience is when lighting is disabled and the
37 // color is specified as an unsigned byte, short, or int. In this
38 // case the conversion from user-supplied color to hardware-determined
39 // color must be exact, up to the number of bits in the framebuffer or
40 // in the value supplied by the user (whichever is smaller). This is
41 // intended to allow object identification numbers to be encoded as
42 // colors, so that applications can implement object selection by
43 // drawing objects and reading back the image to determine the object
44 // ID of the closest visible object. glean uses this property in a
45 // number of cases, for example, where it needs to draw a large number
46 // of primitives and verify that all of them were actually drawn. See
47 // the OpenGL spec, version 1.2.1, section 2.13.9 (page 55) for the
48 // description of this convertibility requirement.
60 class Image
; // forward reference
63 int rBits
, gBits
, bBits
; // number of signif. bits in channels
64 int nsRBits
, nsGBits
, nsBBits
; // non-significant bits in each
65 int rMask
, gMask
, bMask
; // masks for significant bits in each
67 RGBCodedID(int r
, int g
, int b
);
70 // Return the maximum ID number that the caller can use:
73 // Map an ID number to an RGB triple:
74 void toRGB(int id
, GLubyte
& r
, GLubyte
& g
, GLubyte
& b
) const;
76 // Map an RGB triple to the equivalent ID number:
77 int toID(GLubyte r
, GLubyte g
, GLubyte b
) const;
79 // Histogram an UNSIGNED_BYTE RGB image:
80 void histogram(Image
& img
, vector
<int>& hist
) const;
82 // Are all of a range of IDs present in an RGB image?
83 bool allPresent(Image
& img
, int first
, int last
) const;
87 // XXX Might want an IndexCodedID class for use with color index drawing
88 // surfaces, even though such a class would be trivial.
92 #endif // __codedid_h__