Remove CVS keywords.
[mesa.git] / src / glx / x11 / compsize.c
1 /*
2 ** License Applicability. Except to the extent portions of this file are
3 ** made subject to an alternative license as permitted in the SGI Free
4 ** Software License B, Version 1.1 (the "License"), the contents of this
5 ** file are subject only to the provisions of the License. You may not use
6 ** this file except in compliance with the License. You may obtain a copy
7 ** of the License at Silicon Graphics, Inc., attn: Legal Services, 1600
8 ** Amphitheatre Parkway, Mountain View, CA 94043-1351, or at:
9 **
10 ** http://oss.sgi.com/projects/FreeB
11 **
12 ** Note that, as provided in the License, the Software is distributed on an
13 ** "AS IS" basis, with ALL EXPRESS AND IMPLIED WARRANTIES AND CONDITIONS
14 ** DISCLAIMED, INCLUDING, WITHOUT LIMITATION, ANY IMPLIED WARRANTIES AND
15 ** CONDITIONS OF MERCHANTABILITY, SATISFACTORY QUALITY, FITNESS FOR A
16 ** PARTICULAR PURPOSE, AND NON-INFRINGEMENT.
17 **
18 ** Original Code. The Original Code is: OpenGL Sample Implementation,
19 ** Version 1.2.1, released January 26, 2000, developed by Silicon Graphics,
20 ** Inc. The Original Code is Copyright (c) 1991-2000 Silicon Graphics, Inc.
21 ** Copyright in any portions created by third parties is as indicated
22 ** elsewhere herein. All Rights Reserved.
23 **
24 ** Additional Notice Provisions: The application programming interfaces
25 ** established by SGI in conjunction with the Original Code are The
26 ** OpenGL(R) Graphics System: A Specification (Version 1.2.1), released
27 ** April 1, 1999; The OpenGL(R) Graphics System Utility Library (Version
28 ** 1.3), released November 4, 1998; and OpenGL(R) Graphics with the X
29 ** Window System(R) (Version 1.3), released October 19, 1998. This software
30 ** was created using the OpenGL(R) version 1.2.1 Sample Implementation
31 ** published by SGI, but has not been independently verified as being
32 ** compliant with the OpenGL(R) version 1.2.1 Specification.
33 **
34 */
35
36 #include <GL/gl.h>
37 #include "indirect_size.h"
38 #include "glxclient.h"
39
40 /*
41 ** Return the number of elements per group of a specified format
42 */
43 GLint __glElementsPerGroup(GLenum format, GLenum type)
44 {
45 /*
46 ** To make row length computation valid for image extraction,
47 ** packed pixel types assume elements per group equals one.
48 */
49 switch(type) {
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:
69 return 1;
70 default:
71 break;
72 }
73
74 switch(format) {
75 case GL_RGB:
76 case GL_BGR:
77 return 3;
78 case GL_422_EXT:
79 case GL_422_REV_EXT:
80 case GL_422_AVERAGE_EXT:
81 case GL_422_REV_AVERAGE_EXT:
82 case GL_YCBCR_422_APPLE:
83 case GL_LUMINANCE_ALPHA:
84 return 2;
85 case GL_RGBA:
86 case GL_BGRA:
87 case GL_ABGR_EXT:
88 return 4;
89 case GL_COLOR_INDEX:
90 case GL_STENCIL_INDEX:
91 case GL_DEPTH_COMPONENT:
92 case GL_RED:
93 case GL_GREEN:
94 case GL_BLUE:
95 case GL_ALPHA:
96 case GL_LUMINANCE:
97 case GL_INTENSITY:
98 return 1;
99 default:
100 return 0;
101 }
102 }
103
104 /*
105 ** Return the number of bytes per element, based on the element type (other
106 ** than GL_BITMAP).
107 */
108 GLint __glBytesPerElement(GLenum type)
109 {
110 switch(type) {
111 case GL_UNSIGNED_SHORT:
112 case GL_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:
123 return 2;
124 case GL_UNSIGNED_BYTE:
125 case GL_BYTE:
126 case GL_UNSIGNED_BYTE_3_3_2:
127 case GL_UNSIGNED_BYTE_2_3_3_REV:
128 return 1;
129 case GL_INT:
130 case GL_UNSIGNED_INT:
131 case GL_FLOAT:
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:
139 return 4;
140 default:
141 return 0;
142 }
143 }
144
145 /*
146 ** Compute memory required for internal packed array of data of given type
147 ** and format.
148 */
149 GLint __glImageSize(GLsizei width, GLsizei height, GLsizei depth,
150 GLenum format, GLenum type, GLenum target)
151 {
152 int bytes_per_row;
153 int components;
154
155 switch( target ) {
156 case GL_PROXY_TEXTURE_1D:
157 case GL_PROXY_TEXTURE_2D:
158 case GL_PROXY_TEXTURE_3D:
159 case GL_PROXY_TEXTURE_4D_SGIS:
160 case GL_PROXY_TEXTURE_CUBE_MAP:
161 case GL_PROXY_TEXTURE_RECTANGLE_ARB:
162 case GL_PROXY_HISTOGRAM:
163 case GL_PROXY_COLOR_TABLE:
164 case GL_PROXY_TEXTURE_COLOR_TABLE_SGI:
165 case GL_PROXY_POST_CONVOLUTION_COLOR_TABLE:
166 case GL_PROXY_POST_COLOR_MATRIX_COLOR_TABLE:
167 case GL_PROXY_POST_IMAGE_TRANSFORM_COLOR_TABLE_HP:
168 return 0;
169 }
170
171 if (width < 0 || height < 0 || depth < 0) {
172 return 0;
173 }
174
175 /*
176 ** Zero is returned if either format or type are invalid.
177 */
178 components = __glElementsPerGroup(format,type);
179 if (type == GL_BITMAP) {
180 if (format == GL_COLOR_INDEX || format == GL_STENCIL_INDEX) {
181 bytes_per_row = (width + 7) >> 3;
182 } else {
183 return 0;
184 }
185 } else {
186 bytes_per_row = __glBytesPerElement(type) * width;
187 }
188
189 return bytes_per_row * height * depth * components;
190 }