Header file clean-up:
[mesa.git] / src / mesa / main / texcompress.c
1 /* $Id: texcompress.c,v 1.3 2002/10/24 23:57:21 brianp Exp $ */
2
3 /*
4 * Mesa 3-D graphics library
5 * Version: 4.1
6 *
7 * Copyright (C) 1999-2002 Brian Paul All Rights Reserved.
8 *
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:
15 *
16 * The above copyright notice and this permission notice shall be included
17 * in all copies or substantial portions of the Software.
18 *
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.
25 */
26
27
28 #include "glheader.h"
29 #include "imports.h"
30 #include "context.h"
31 #include "image.h"
32 #include "texcompress.h"
33 #include "texformat.h"
34
35
36 /**
37 * Get the list of supported internal compression formats.
38 * \param formats - the results list (may be NULL)
39 * \return number of formats.
40 */
41 GLuint
42 _mesa_get_compressed_formats( GLcontext *ctx, GLint *formats )
43 {
44 GLuint n = 0;
45 if (ctx->Extensions.ARB_texture_compression) {
46 if (ctx->Extensions.TDFX_texture_compression_FXT1) {
47 if (formats) {
48 formats[n++] = GL_COMPRESSED_RGB_FXT1_3DFX;
49 formats[n++] = GL_COMPRESSED_RGBA_FXT1_3DFX;
50 }
51 else {
52 n += 4;
53 }
54 }
55 }
56 return n;
57 }
58
59
60
61 /**
62 * Return bytes of storage needed for the given texture size and compressed
63 * format.
64 * \param width, height, depth - texture size in texels
65 * \param texFormat - one of the compressed format enums
66 * \return size in bytes, or zero if bad texFormat
67 */
68 GLuint
69 _mesa_compressed_texture_size( GLcontext *ctx,
70 GLsizei width, GLsizei height, GLsizei depth,
71 GLenum format )
72 {
73 GLuint size;
74
75 switch (format) {
76 case GL_COMPRESSED_RGB_FXT1_3DFX:
77 case GL_COMPRESSED_RGBA_FXT1_3DFX:
78 /* round up to multiple of 4 */
79 size = ((width + 7) / 8) * ((height + 3) / 4) * 16;
80 return size;
81 default:
82 _mesa_problem(ctx, "bad texformat in compressed_texture_size");
83 return 0;
84 }
85 }
86
87
88 /*
89 * Compute the bytes per row in a compressed texture image.
90 */
91 GLint
92 _mesa_compressed_row_stride(GLenum format, GLsizei width)
93 {
94 GLint bytesPerTile, stride;
95
96 switch (format) {
97 default:
98 return 0;
99 }
100
101 stride = ((width + 3) / 4) * bytesPerTile;
102 return stride;
103 }
104
105
106 /*
107 * Return the address of the pixel at (col, row, img) in a
108 * compressed texture image.
109 * \param col, row, img - image position (3D)
110 * \param format - compressed image format
111 * \param width - image width
112 * \param image - the image address
113 * \return address of pixel at (row, col)
114 */
115 GLubyte *
116 _mesa_compressed_image_address(GLint col, GLint row, GLint img,
117 GLenum format,
118 GLsizei width, const GLubyte *image)
119 {
120 GLint bytesPerTile, stride;
121 GLubyte *addr;
122
123 ASSERT((row & 3) == 0);
124 ASSERT((col & 3) == 0);
125 (void) img;
126
127 switch (format) {
128 default:
129 return 0;
130 }
131
132 stride = ((width + 3) / 4) * bytesPerTile;
133
134 addr = (GLubyte *) image + (row / 4) * stride + (col / 4) * bytesPerTile;
135 return addr;
136 }
137
138
139
140 /*
141 * \param srcRowStride - source stride, in pixels
142 */
143 void
144 _mesa_compress_teximage( GLcontext *ctx, GLsizei width, GLsizei height,
145 GLenum srcFormat, const GLchan *source,
146 GLint srcRowStride,
147 const struct gl_texture_format *dstFormat,
148 GLubyte *dest, GLint dstRowStride )
149 {
150 switch (dstFormat->MesaFormat) {
151 default:
152 _mesa_problem(ctx, "Bad dstFormat in _mesa_compress_teximage()");
153 return;
154 }
155 }