1 /* $XFree86: xc/lib/GL/glx/compsize.c,v 1.6 2004/01/28 18:11:38 alanh Exp $ */
3 ** License Applicability. Except to the extent portions of this file are
4 ** made subject to an alternative license as permitted in the SGI Free
5 ** Software License B, Version 1.1 (the "License"), the contents of this
6 ** file are subject only to the provisions of the License. You may not use
7 ** this file except in compliance with the License. You may obtain a copy
8 ** of the License at Silicon Graphics, Inc., attn: Legal Services, 1600
9 ** Amphitheatre Parkway, Mountain View, CA 94043-1351, or at:
11 ** http://oss.sgi.com/projects/FreeB
13 ** Note that, as provided in the License, the Software is distributed on an
14 ** "AS IS" basis, with ALL EXPRESS AND IMPLIED WARRANTIES AND CONDITIONS
15 ** DISCLAIMED, INCLUDING, WITHOUT LIMITATION, ANY IMPLIED WARRANTIES AND
16 ** CONDITIONS OF MERCHANTABILITY, SATISFACTORY QUALITY, FITNESS FOR A
17 ** PARTICULAR PURPOSE, AND NON-INFRINGEMENT.
19 ** Original Code. The Original Code is: OpenGL Sample Implementation,
20 ** Version 1.2.1, released January 26, 2000, developed by Silicon Graphics,
21 ** Inc. The Original Code is Copyright (c) 1991-2000 Silicon Graphics, Inc.
22 ** Copyright in any portions created by third parties is as indicated
23 ** elsewhere herein. All Rights Reserved.
25 ** Additional Notice Provisions: The application programming interfaces
26 ** established by SGI in conjunction with the Original Code are The
27 ** OpenGL(R) Graphics System: A Specification (Version 1.2.1), released
28 ** April 1, 1999; The OpenGL(R) Graphics System Utility Library (Version
29 ** 1.3), released November 4, 1998; and OpenGL(R) Graphics with the X
30 ** Window System(R) (Version 1.3), released October 19, 1998. This software
31 ** was created using the OpenGL(R) version 1.2.1 Sample Implementation
32 ** published by SGI, but has not been independently verified as being
33 ** compliant with the OpenGL(R) version 1.2.1 Specification.
41 ** Return the number of elements per group of a specified format
43 GLint
__glElementsPerGroup(GLenum format
, GLenum type
)
46 ** To make row length computation valid for image extraction,
47 ** packed pixel types assume elements per group equals one.
50 case GL_UNSIGNED_BYTE_3_3_2
:
51 case GL_UNSIGNED_BYTE_2_3_3_REV
:
52 case GL_UNSIGNED_SHORT_5_6_5
:
53 case GL_UNSIGNED_SHORT_5_6_5_REV
:
54 case GL_UNSIGNED_SHORT_4_4_4_4
:
55 case GL_UNSIGNED_SHORT_4_4_4_4_REV
:
56 case GL_UNSIGNED_SHORT_5_5_5_1
:
57 case GL_UNSIGNED_SHORT_1_5_5_5_REV
:
58 case GL_UNSIGNED_SHORT_8_8_APPLE
:
59 case GL_UNSIGNED_SHORT_8_8_REV_APPLE
:
60 case GL_UNSIGNED_SHORT_15_1_MESA
:
61 case GL_UNSIGNED_SHORT_1_15_REV_MESA
:
62 case GL_UNSIGNED_INT_8_8_8_8
:
63 case GL_UNSIGNED_INT_8_8_8_8_REV
:
64 case GL_UNSIGNED_INT_10_10_10_2
:
65 case GL_UNSIGNED_INT_2_10_10_10_REV
:
66 case GL_UNSIGNED_INT_24_8_NV
:
67 case GL_UNSIGNED_INT_24_8_MESA
:
68 case GL_UNSIGNED_INT_8_24_REV_MESA
:
80 case GL_422_AVERAGE_EXT
:
81 case GL_422_REV_AVERAGE_EXT
:
82 case GL_YCBCR_422_APPLE
:
83 case GL_LUMINANCE_ALPHA
:
90 case GL_STENCIL_INDEX
:
91 case GL_DEPTH_COMPONENT
:
105 ** Return the number of bytes per element, based on the element type (other
108 GLint
__glBytesPerElement(GLenum type
)
111 case GL_UNSIGNED_SHORT
:
113 case GL_UNSIGNED_SHORT_5_6_5
:
114 case GL_UNSIGNED_SHORT_5_6_5_REV
:
115 case GL_UNSIGNED_SHORT_4_4_4_4
:
116 case GL_UNSIGNED_SHORT_4_4_4_4_REV
:
117 case GL_UNSIGNED_SHORT_5_5_5_1
:
118 case GL_UNSIGNED_SHORT_1_5_5_5_REV
:
119 case GL_UNSIGNED_SHORT_8_8_APPLE
:
120 case GL_UNSIGNED_SHORT_8_8_REV_APPLE
:
121 case GL_UNSIGNED_SHORT_15_1_MESA
:
122 case GL_UNSIGNED_SHORT_1_15_REV_MESA
:
124 case GL_UNSIGNED_BYTE
:
126 case GL_UNSIGNED_BYTE_3_3_2
:
127 case GL_UNSIGNED_BYTE_2_3_3_REV
:
130 case GL_UNSIGNED_INT
:
132 case GL_UNSIGNED_INT_8_8_8_8
:
133 case GL_UNSIGNED_INT_8_8_8_8_REV
:
134 case GL_UNSIGNED_INT_10_10_10_2
:
135 case GL_UNSIGNED_INT_2_10_10_10_REV
:
136 case GL_UNSIGNED_INT_24_8_NV
:
137 case GL_UNSIGNED_INT_24_8_MESA
:
138 case GL_UNSIGNED_INT_8_24_REV_MESA
:
146 ** Compute memory required for internal packed array of data of given type
149 GLint
__glImageSize(GLsizei width
, GLsizei height
, GLsizei depth
,
150 GLenum format
, GLenum type
)
155 if (width
< 0 || height
< 0 || depth
< 0) {
159 ** Zero is returned if either format or type are invalid.
161 components
= __glElementsPerGroup(format
,type
);
162 if (type
== GL_BITMAP
) {
163 if (format
== GL_COLOR_INDEX
|| format
== GL_STENCIL_INDEX
) {
164 bytes_per_row
= (width
+ 7) >> 3;
169 bytes_per_row
= __glBytesPerElement(type
) * width
;
171 return bytes_per_row
* height
* depth
* components
;