~ubuntu-branches/ubuntu/gutsy/vnc4/gutsy

« back to all changes in this revision

Viewing changes to unix/xc/extras/Mesa/src/texformat.c

  • Committer: Bazaar Package Importer
  • Author(s): Ola Lundqvist
  • Date: 2006-05-15 20:35:17 UTC
  • mfrom: (1.1.2 upstream)
  • Revision ID: james.westby@ubuntu.com-20060515203517-l4lre1ku942mn26k
Tags: 4.1.1+X4.3.0-10
* Correction of critical security issue. Thanks to Martin Kogler
  <e9925248@student.tuwien.ac.at> that informed me about the issue,
  and provided the patch.
  This flaw was originally found by Steve Wiseman of intelliadmin.com.
* Applied patch from Javier Kohen <jkohen@users.sourceforge.net> that
  inform the user that only 8 first characters of the password will
  actually be used when typing more than 8 characters, closes:
  #355619.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
 
 
2
/*
 
3
 * Mesa 3-D graphics library
 
4
 * Version:  4.0.4
 
5
 *
 
6
 * Copyright (C) 1999-2002  Brian Paul   All Rights Reserved.
 
7
 *
 
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:
 
14
 *
 
15
 * The above copyright notice and this permission notice shall be included
 
16
 * in all copies or substantial portions of the Software.
 
17
 *
 
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.
 
24
 *
 
25
 * Authors:
 
26
 *    Gareth Hughes <gareth@valinux.com>
 
27
 *    Brian Paul
 
28
 */
 
29
 
 
30
#ifdef PC_HEADER
 
31
#include "all.h"
 
32
#else
 
33
#include "glheader.h"
 
34
#include "colormac.h"
 
35
#include "context.h"
 
36
#include "image.h"
 
37
#include "mem.h"
 
38
#include "mmath.h"
 
39
#include "mtypes.h"
 
40
#include "texformat.h"
 
41
#include "teximage.h"
 
42
#include "texstate.h"
 
43
#include "swrast/s_span.h"
 
44
#endif
 
45
 
 
46
 
 
47
/* Texel fetch routines for all supported formats:
 
48
 */
 
49
#define DIM 1
 
50
#include "texformat_tmp.h"
 
51
 
 
52
#define DIM 2
 
53
#include "texformat_tmp.h"
 
54
 
 
55
#define DIM 3
 
56
#include "texformat_tmp.h"
 
57
 
 
58
/* Have to have this so the FetchTexel function pointer is never NULL.
 
59
 */
 
60
static void fetch_null_texel( const struct gl_texture_image *texImage,
 
61
                              GLint i, GLint j, GLint k, GLvoid *texel )
 
62
{
 
63
   GLchan *rgba = (GLchan *) texel;
 
64
   rgba[RCOMP] = 0;
 
65
   rgba[GCOMP] = 0;
 
66
   rgba[BCOMP] = 0;
 
67
   rgba[ACOMP] = 0;
 
68
}
 
69
 
 
70
 
 
71
/* =============================================================
 
72
 * Default GLchan-based formats:
 
73
 */
 
74
 
 
75
const struct gl_texture_format _mesa_texformat_rgba = {
 
76
   MESA_FORMAT_RGBA,                    /* MesaFormat */
 
77
   GL_RGBA,                             /* BaseFormat */
 
78
   CHAN_TYPE,                           /* Type */
 
79
   CHAN_BITS,                           /* RedBits */
 
80
   CHAN_BITS,                           /* GreenBits */
 
81
   CHAN_BITS,                           /* BlueBits */
 
82
   CHAN_BITS,                           /* AlphaBits */
 
83
   0,                                   /* LuminanceBits */
 
84
   0,                                   /* IntensityBits */
 
85
   0,                                   /* IndexBits */
 
86
   0,                                   /* DepthBits */
 
87
   4 * CHAN_BITS / 8,                   /* TexelBytes */
 
88
   fetch_1d_texel_rgba,                 /* FetchTexel1D */
 
89
   fetch_2d_texel_rgba,                 /* FetchTexel2D */
 
90
   fetch_3d_texel_rgba,                 /* FetchTexel3D */
 
91
};
 
92
 
 
93
const struct gl_texture_format _mesa_texformat_rgb = {
 
94
   MESA_FORMAT_RGB,                     /* MesaFormat */
 
95
   GL_RGB,                              /* BaseFormat */
 
96
   CHAN_TYPE,                           /* Type */
 
97
   CHAN_BITS,                           /* RedBits */
 
98
   CHAN_BITS,                           /* GreenBits */
 
99
   CHAN_BITS,                           /* BlueBits */
 
100
   0,                                   /* AlphaBits */
 
101
   0,                                   /* LuminanceBits */
 
102
   0,                                   /* IntensityBits */
 
103
   0,                                   /* IndexBits */
 
104
   0,                                   /* DepthBits */
 
105
   3 * CHAN_BITS / 8,                   /* TexelBytes */
 
106
   fetch_1d_texel_rgb,                  /* FetchTexel1D */
 
107
   fetch_2d_texel_rgb,                  /* FetchTexel2D */
 
108
   fetch_3d_texel_rgb,                  /* FetchTexel3D */
 
109
};
 
110
 
 
111
const struct gl_texture_format _mesa_texformat_alpha = {
 
112
   MESA_FORMAT_ALPHA,                   /* MesaFormat */
 
113
   GL_ALPHA,                            /* BaseFormat */
 
114
   CHAN_TYPE,                           /* Type */
 
115
   0,                                   /* RedBits */
 
116
   0,                                   /* GreenBits */
 
117
   0,                                   /* BlueBits */
 
118
   CHAN_BITS,                           /* AlphaBits */
 
119
   0,                                   /* LuminanceBits */
 
120
   0,                                   /* IntensityBits */
 
121
   0,                                   /* IndexBits */
 
122
   0,                                   /* DepthBits */
 
123
   CHAN_BITS / 8,                       /* TexelBytes */
 
124
   fetch_1d_texel_alpha,                /* FetchTexel1D */
 
125
   fetch_2d_texel_alpha,                /* FetchTexel2D */
 
126
   fetch_3d_texel_alpha,                /* FetchTexel3D */
 
127
};
 
128
 
 
129
const struct gl_texture_format _mesa_texformat_luminance = {
 
130
   MESA_FORMAT_LUMINANCE,               /* MesaFormat */
 
131
   GL_LUMINANCE,                        /* BaseFormat */
 
132
   CHAN_TYPE,                           /* Type */
 
133
   0,                                   /* RedBits */
 
134
   0,                                   /* GreenBits */
 
135
   0,                                   /* BlueBits */
 
136
   0,                                   /* AlphaBits */
 
137
   CHAN_BITS,                           /* LuminanceBits */
 
138
   0,                                   /* IntensityBits */
 
139
   0,                                   /* IndexBits */
 
140
   0,                                   /* DepthBits */
 
141
   CHAN_BITS / 8,                       /* TexelBytes */
 
142
   fetch_1d_texel_luminance,            /* FetchTexel1D */
 
143
   fetch_2d_texel_luminance,            /* FetchTexel2D */
 
144
   fetch_3d_texel_luminance,            /* FetchTexel3D */
 
145
};
 
146
 
 
147
const struct gl_texture_format _mesa_texformat_luminance_alpha = {
 
148
   MESA_FORMAT_LUMINANCE_ALPHA,         /* MesaFormat */
 
149
   GL_LUMINANCE_ALPHA,                  /* BaseFormat */
 
150
   CHAN_TYPE,                           /* Type */
 
151
   0,                                   /* RedBits */
 
152
   0,                                   /* GreenBits */
 
153
   0,                                   /* BlueBits */
 
154
   CHAN_BITS,                           /* AlphaBits */
 
155
   CHAN_BITS,                           /* LuminanceBits */
 
156
   0,                                   /* IntensityBits */
 
157
   0,                                   /* IndexBits */
 
158
   0,                                   /* DepthBits */
 
159
   2 * CHAN_BITS / 8,                   /* TexelBytes */
 
160
   fetch_1d_texel_luminance_alpha,      /* FetchTexel1D */
 
161
   fetch_2d_texel_luminance_alpha,      /* FetchTexel2D */
 
162
   fetch_3d_texel_luminance_alpha,      /* FetchTexel3D */
 
163
};
 
164
 
 
165
const struct gl_texture_format _mesa_texformat_intensity = {
 
166
   MESA_FORMAT_INTENSITY,               /* MesaFormat */
 
167
   GL_INTENSITY,                        /* BaseFormat */
 
168
   CHAN_TYPE,                           /* Type */
 
169
   0,                                   /* RedBits */
 
170
   0,                                   /* GreenBits */
 
171
   0,                                   /* BlueBits */
 
172
   0,                                   /* AlphaBits */
 
173
   0,                                   /* LuminanceBits */
 
174
   CHAN_BITS,                           /* IntensityBits */
 
175
   0,                                   /* IndexBits */
 
176
   0,                                   /* DepthBits */
 
177
   CHAN_BITS / 8,                       /* TexelBytes */
 
178
   fetch_1d_texel_intensity,            /* FetchTexel1D */
 
179
   fetch_2d_texel_intensity,            /* FetchTexel2D */
 
180
   fetch_3d_texel_intensity,            /* FetchTexel3D */
 
181
};
 
182
 
 
183
const struct gl_texture_format _mesa_texformat_color_index = {
 
184
   MESA_FORMAT_COLOR_INDEX,             /* MesaFormat */
 
185
   GL_COLOR_INDEX,                      /* BaseFormat */
 
186
   CHAN_TYPE,                           /* Type */
 
187
   0,                                   /* RedBits */
 
188
   0,                                   /* GreenBits */
 
189
   0,                                   /* BlueBits */
 
190
   0,                                   /* AlphaBits */
 
191
   0,                                   /* LuminanceBits */
 
192
   0,                                   /* IntensityBits */
 
193
   CHAN_BITS,                           /* IndexBits */
 
194
   0,                                   /* DepthBits */
 
195
   CHAN_BITS / 8,                       /* TexelBytes */
 
196
   fetch_1d_texel_color_index,          /* FetchTexel1D */
 
197
   fetch_2d_texel_color_index,          /* FetchTexel2D */
 
198
   fetch_3d_texel_color_index,          /* FetchTexel3D */
 
199
};
 
200
 
 
201
const struct gl_texture_format _mesa_texformat_depth_component = {
 
202
   MESA_FORMAT_DEPTH_COMPONENT,         /* MesaFormat */
 
203
   GL_DEPTH_COMPONENT,                  /* BaseFormat */
 
204
   GL_FLOAT,                            /* Type */
 
205
   0,                                   /* RedBits */
 
206
   0,                                   /* GreenBits */
 
207
   0,                                   /* BlueBits */
 
208
   0,                                   /* AlphaBits */
 
209
   0,                                   /* LuminanceBits */
 
210
   0,                                   /* IntensityBits */
 
211
   0,                                   /* IndexBits */
 
212
   sizeof(GLfloat) * 8,                 /* DepthBits */
 
213
   sizeof(GLfloat),                     /* TexelBytes */
 
214
   fetch_1d_texel_depth_component,      /* FetchTexel1D */
 
215
   fetch_2d_texel_depth_component,      /* FetchTexel2D */
 
216
   fetch_3d_texel_depth_component,      /* FetchTexel3D */
 
217
};
 
218
 
 
219
 
 
220
/* =============================================================
 
221
 * Hardware formats:
 
222
 */
 
223
 
 
224
const struct gl_texture_format _mesa_texformat_rgba8888 = {
 
225
   MESA_FORMAT_RGBA8888,                /* MesaFormat */
 
226
   GL_RGBA,                             /* BaseFormat */
 
227
   GL_UNSIGNED_INT_8_8_8_8,             /* Type */
 
228
   8,                                   /* RedBits */
 
229
   8,                                   /* GreenBits */
 
230
   8,                                   /* BlueBits */
 
231
   8,                                   /* AlphaBits */
 
232
   0,                                   /* LuminanceBits */
 
233
   0,                                   /* IntensityBits */
 
234
   0,                                   /* IndexBits */
 
235
   0,                                   /* DepthBits */
 
236
   4,                                   /* TexelBytes */
 
237
   fetch_1d_texel_rgba8888,             /* FetchTexel1D */
 
238
   fetch_2d_texel_rgba8888,             /* FetchTexel2D */
 
239
   fetch_3d_texel_rgba8888,             /* FetchTexel3D */
 
240
};
 
241
 
 
242
const struct gl_texture_format _mesa_texformat_argb8888 = {
 
243
   MESA_FORMAT_ARGB8888,                /* MesaFormat */
 
244
   GL_RGBA,                             /* BaseFormat */
 
245
   GL_UNSIGNED_INT_8_8_8_8_REV,         /* Type */
 
246
   8,                                   /* RedBits */
 
247
   8,                                   /* GreenBits */
 
248
   8,                                   /* BlueBits */
 
249
   8,                                   /* AlphaBits */
 
250
   0,                                   /* LuminanceBits */
 
251
   0,                                   /* IntensityBits */
 
252
   0,                                   /* IndexBits */
 
253
   0,                                   /* DepthBits */
 
254
   4,                                   /* TexelBytes */
 
255
   fetch_1d_texel_argb8888,             /* FetchTexel1D */
 
256
   fetch_2d_texel_argb8888,             /* FetchTexel2D */
 
257
   fetch_3d_texel_argb8888,             /* FetchTexel3D */
 
258
};
 
259
 
 
260
const struct gl_texture_format _mesa_texformat_rgb888 = {
 
261
   MESA_FORMAT_RGB888,                  /* MesaFormat */
 
262
   GL_RGB,                              /* BaseFormat */
 
263
   GL_UNSIGNED_BYTE,                    /* Type */
 
264
   8,                                   /* RedBits */
 
265
   8,                                   /* GreenBits */
 
266
   8,                                   /* BlueBits */
 
267
   0,                                   /* AlphaBits */
 
268
   0,                                   /* LuminanceBits */
 
269
   0,                                   /* IntensityBits */
 
270
   0,                                   /* IndexBits */
 
271
   0,                                   /* DepthBits */
 
272
   3,                                   /* TexelBytes */
 
273
   fetch_1d_texel_rgb888,               /* FetchTexel1D */
 
274
   fetch_2d_texel_rgb888,               /* FetchTexel2D */
 
275
   fetch_3d_texel_rgb888,               /* FetchTexel3D */
 
276
};
 
277
 
 
278
const struct gl_texture_format _mesa_texformat_rgb565 = {
 
279
   MESA_FORMAT_RGB565,                  /* MesaFormat */
 
280
   GL_RGB,                              /* BaseFormat */
 
281
   GL_UNSIGNED_SHORT_5_6_5,             /* Type */
 
282
   5,                                   /* RedBits */
 
283
   6,                                   /* GreenBits */
 
284
   5,                                   /* BlueBits */
 
285
   0,                                   /* AlphaBits */
 
286
   0,                                   /* LuminanceBits */
 
287
   0,                                   /* IntensityBits */
 
288
   0,                                   /* IndexBits */
 
289
   0,                                   /* DepthBits */
 
290
   2,                                   /* TexelBytes */
 
291
   fetch_1d_texel_rgb565,               /* FetchTexel1D */
 
292
   fetch_2d_texel_rgb565,               /* FetchTexel2D */
 
293
   fetch_3d_texel_rgb565,               /* FetchTexel3D */
 
294
};
 
295
 
 
296
const struct gl_texture_format _mesa_texformat_argb4444 = {
 
297
   MESA_FORMAT_ARGB4444,                /* MesaFormat */
 
298
   GL_RGBA,                             /* BaseFormat */
 
299
   GL_UNSIGNED_SHORT_4_4_4_4_REV,       /* Type */
 
300
   4,                                   /* RedBits */
 
301
   4,                                   /* GreenBits */
 
302
   4,                                   /* BlueBits */
 
303
   4,                                   /* AlphaBits */
 
304
   0,                                   /* LuminanceBits */
 
305
   0,                                   /* IntensityBits */
 
306
   0,                                   /* IndexBits */
 
307
   0,                                   /* DepthBits */
 
308
   2,                                   /* TexelBytes */
 
309
   fetch_1d_texel_argb4444,             /* FetchTexel1D */
 
310
   fetch_2d_texel_argb4444,             /* FetchTexel2D */
 
311
   fetch_3d_texel_argb4444,             /* FetchTexel3D */
 
312
};
 
313
 
 
314
const struct gl_texture_format _mesa_texformat_argb1555 = {
 
315
   MESA_FORMAT_ARGB1555,                /* MesaFormat */
 
316
   GL_RGBA,                             /* BaseFormat */
 
317
   GL_UNSIGNED_SHORT_1_5_5_5_REV,       /* Type */
 
318
   5,                                   /* RedBits */
 
319
   5,                                   /* GreenBits */
 
320
   5,                                   /* BlueBits */
 
321
   1,                                   /* AlphaBits */
 
322
   0,                                   /* LuminanceBits */
 
323
   0,                                   /* IntensityBits */
 
324
   0,                                   /* IndexBits */
 
325
   0,                                   /* DepthBits */
 
326
   2,                                   /* TexelBytes */
 
327
   fetch_1d_texel_argb1555,             /* FetchTexel1D */
 
328
   fetch_2d_texel_argb1555,             /* FetchTexel2D */
 
329
   fetch_3d_texel_argb1555,             /* FetchTexel3D */
 
330
};
 
331
 
 
332
const struct gl_texture_format _mesa_texformat_al88 = {
 
333
   MESA_FORMAT_AL88,                    /* MesaFormat */
 
334
   GL_LUMINANCE_ALPHA,                  /* BaseFormat */
 
335
   GL_UNSIGNED_BYTE,                    /* Type */
 
336
   0,                                   /* RedBits */
 
337
   0,                                   /* GreenBits */
 
338
   0,                                   /* BlueBits */
 
339
   8,                                   /* AlphaBits */
 
340
   8,                                   /* LuminanceBits */
 
341
   0,                                   /* IntensityBits */
 
342
   0,                                   /* IndexBits */
 
343
   0,                                   /* DepthBits */
 
344
   2,                                   /* TexelBytes */
 
345
   fetch_1d_texel_al88,                 /* FetchTexel1D */
 
346
   fetch_2d_texel_al88,                 /* FetchTexel2D */
 
347
   fetch_3d_texel_al88,                 /* FetchTexel3D */
 
348
};
 
349
 
 
350
const struct gl_texture_format _mesa_texformat_rgb332 = {
 
351
   MESA_FORMAT_RGB332,                  /* MesaFormat */
 
352
   GL_RGB,                              /* BaseFormat */
 
353
   GL_UNSIGNED_BYTE_3_3_2,              /* Type */
 
354
   3,                                   /* RedBits */
 
355
   3,                                   /* GreenBits */
 
356
   2,                                   /* BlueBits */
 
357
   0,                                   /* AlphaBits */
 
358
   0,                                   /* LuminanceBits */
 
359
   0,                                   /* IntensityBits */
 
360
   0,                                   /* IndexBits */
 
361
   0,                                   /* DepthBits */
 
362
   1,                                   /* TexelBytes */
 
363
   fetch_1d_texel_rgb332,               /* FetchTexel1D */
 
364
   fetch_2d_texel_rgb332,               /* FetchTexel2D */
 
365
   fetch_3d_texel_rgb332,               /* FetchTexel3D */
 
366
};
 
367
 
 
368
const struct gl_texture_format _mesa_texformat_a8 = {
 
369
   MESA_FORMAT_A8,                      /* MesaFormat */
 
370
   GL_ALPHA,                            /* BaseFormat */
 
371
   GL_UNSIGNED_BYTE,                    /* Type */
 
372
   0,                                   /* RedBits */
 
373
   0,                                   /* GreenBits */
 
374
   0,                                   /* BlueBits */
 
375
   8,                                   /* AlphaBits */
 
376
   0,                                   /* LuminanceBits */
 
377
   0,                                   /* IntensityBits */
 
378
   0,                                   /* IndexBits */
 
379
   0,                                   /* DepthBits */
 
380
   1,                                   /* TexelBytes */
 
381
   fetch_1d_texel_a8,                   /* FetchTexel1D */
 
382
   fetch_2d_texel_a8,                   /* FetchTexel2D */
 
383
   fetch_3d_texel_a8,                   /* FetchTexel3D */
 
384
};
 
385
 
 
386
const struct gl_texture_format _mesa_texformat_l8 = {
 
387
   MESA_FORMAT_L8,                      /* MesaFormat */
 
388
   GL_LUMINANCE,                        /* BaseFormat */
 
389
   GL_UNSIGNED_BYTE,                    /* Type */
 
390
   0,                                   /* RedBits */
 
391
   0,                                   /* GreenBits */
 
392
   0,                                   /* BlueBits */
 
393
   0,                                   /* AlphaBits */
 
394
   8,                                   /* LuminanceBits */
 
395
   0,                                   /* IntensityBits */
 
396
   0,                                   /* IndexBits */
 
397
   0,                                   /* DepthBits */
 
398
   1,                                   /* TexelBytes */
 
399
   fetch_1d_texel_l8,                   /* FetchTexel1D */
 
400
   fetch_2d_texel_l8,                   /* FetchTexel2D */
 
401
   fetch_3d_texel_l8,                   /* FetchTexel3D */
 
402
};
 
403
 
 
404
const struct gl_texture_format _mesa_texformat_i8 = {
 
405
   MESA_FORMAT_I8,                      /* MesaFormat */
 
406
   GL_INTENSITY,                        /* BaseFormat */
 
407
   GL_UNSIGNED_BYTE,                    /* Type */
 
408
   0,                                   /* RedBits */
 
409
   0,                                   /* GreenBits */
 
410
   0,                                   /* BlueBits */
 
411
   0,                                   /* AlphaBits */
 
412
   0,                                   /* LuminanceBits */
 
413
   8,                                   /* IntensityBits */
 
414
   0,                                   /* IndexBits */
 
415
   0,                                   /* DepthBits */
 
416
   1,                                   /* TexelBytes */
 
417
   fetch_1d_texel_i8,                   /* FetchTexel1D */
 
418
   fetch_2d_texel_i8,                   /* FetchTexel2D */
 
419
   fetch_3d_texel_i8,                   /* FetchTexel3D */
 
420
};
 
421
 
 
422
const struct gl_texture_format _mesa_texformat_ci8 = {
 
423
   MESA_FORMAT_CI8,                     /* MesaFormat */
 
424
   GL_COLOR_INDEX,                      /* BaseFormat */
 
425
   GL_UNSIGNED_BYTE,                    /* Type */
 
426
   0,                                   /* RedBits */
 
427
   0,                                   /* GreenBits */
 
428
   0,                                   /* BlueBits */
 
429
   0,                                   /* AlphaBits */
 
430
   0,                                   /* LuminanceBits */
 
431
   0,                                   /* IntensityBits */
 
432
   8,                                   /* IndexBits */
 
433
   0,                                   /* DepthBits */
 
434
   1,                                   /* TexelBytes */
 
435
   fetch_1d_texel_ci8,                  /* FetchTexel1D */
 
436
   fetch_2d_texel_ci8,                  /* FetchTexel2D */
 
437
   fetch_3d_texel_ci8,                  /* FetchTexel3D */
 
438
};
 
439
 
 
440
 
 
441
const struct gl_texture_format _mesa_texformat_ycbcr = {
 
442
   MESA_FORMAT_YCBCR,                   /* MesaFormat */
 
443
   GL_YCBCR_MESA,                       /* BaseFormat */
 
444
   GL_UNSIGNED_SHORT_8_8_MESA,          /* Type */
 
445
   0,                                   /* RedBits */
 
446
   0,                                   /* GreenBits */
 
447
   0,                                   /* BlueBits */
 
448
   0,                                   /* AlphaBits */
 
449
   0,                                   /* LuminanceBits */
 
450
   0,                                   /* IntensityBits */
 
451
   0,                                   /* IndexBits */
 
452
   0,                                   /* DepthBits */
 
453
   2,                                   /* TexelBytes */
 
454
   fetch_1d_texel_ycbcr,                /* FetchTexel1D */
 
455
   fetch_2d_texel_ycbcr,                /* FetchTexel2D */
 
456
   fetch_3d_texel_ycbcr,                /* FetchTexel3D */
 
457
};
 
458
 
 
459
 
 
460
const struct gl_texture_format _mesa_texformat_ycbcr_rev = {
 
461
   MESA_FORMAT_YCBCR_REV,               /* MesaFormat */
 
462
   GL_YCBCR_MESA,                       /* BaseFormat */
 
463
   GL_UNSIGNED_SHORT_8_8_REV_MESA,      /* Type */
 
464
   0,                                   /* RedBits */
 
465
   0,                                   /* GreenBits */
 
466
   0,                                   /* BlueBits */
 
467
   0,                                   /* AlphaBits */
 
468
   0,                                   /* LuminanceBits */
 
469
   0,                                   /* IntensityBits */
 
470
   0,                                   /* IndexBits */
 
471
   0,                                   /* DepthBits */
 
472
   2,                                   /* TexelBytes */
 
473
   fetch_1d_texel_ycbcr_rev,            /* FetchTexel1D */
 
474
   fetch_2d_texel_ycbcr_rev,            /* FetchTexel2D */
 
475
   fetch_3d_texel_ycbcr_rev,            /* FetchTexel3D */
 
476
};
 
477
 
 
478
 
 
479
 
 
480
/* =============================================================
 
481
 * Null format:
 
482
 */
 
483
 
 
484
const struct gl_texture_format _mesa_null_texformat = {
 
485
   -1,                                  /* MesaFormat */
 
486
   0,                                   /* BaseFormat */
 
487
   0,                                   /* Type */
 
488
   0,                                   /* RedBits */
 
489
   0,                                   /* GreenBits */
 
490
   0,                                   /* BlueBits */
 
491
   0,                                   /* AlphaBits */
 
492
   0,                                   /* LuminanceBits */
 
493
   0,                                   /* IntensityBits */
 
494
   0,                                   /* IndexBits */
 
495
   0,                                   /* DepthBits */
 
496
   0,                                   /* TexelBytes */
 
497
   fetch_null_texel,                    /* FetchTexel1D */
 
498
   fetch_null_texel,                    /* FetchTexel2D */
 
499
   fetch_null_texel,                    /* FetchTexel3D */
 
500
};
 
501
 
 
502
 
 
503
 
 
504
GLboolean
 
505
_mesa_is_hardware_tex_format( const struct gl_texture_format *format )
 
506
{
 
507
   return (format->MesaFormat < MESA_FORMAT_RGBA);
 
508
}
 
509
 
 
510
 
 
511
/* Given an internal texture format (or 1, 2, 3, 4) return a pointer
 
512
 * to a gl_texture_format which which to store the texture.
 
513
 * This is called via ctx->Driver.ChooseTextureFormat().
 
514
 * Hardware drivers should not use this function, but instead a 
 
515
 * specialized function.
 
516
 */
 
517
const struct gl_texture_format *
 
518
_mesa_choose_tex_format( GLcontext *ctx, GLint internalFormat,
 
519
                         GLenum format, GLenum type )
 
520
{
 
521
   (void) format;
 
522
   (void) type;
 
523
 
 
524
   switch ( internalFormat ) {
 
525
      /* GH: Bias towards GL_RGB, GL_RGBA texture formats.  This has
 
526
       * got to be better than sticking them way down the end of this
 
527
       * huge list.
 
528
       */
 
529
   case 4:                              /* Quake3 uses this... */
 
530
   case GL_RGBA:
 
531
      return &_mesa_texformat_rgba;
 
532
 
 
533
   case 3:                              /* ... and this. */
 
534
   case GL_RGB:
 
535
      return &_mesa_texformat_rgb;
 
536
 
 
537
      /* GH: Okay, keep checking as normal.  Still test for GL_RGB,
 
538
       * GL_RGBA formats first.
 
539
       */
 
540
   case GL_RGBA2:
 
541
   case GL_RGBA4:
 
542
   case GL_RGB5_A1:
 
543
   case GL_RGBA8:
 
544
   case GL_RGB10_A2:
 
545
   case GL_RGBA12:
 
546
   case GL_RGBA16:
 
547
      return &_mesa_texformat_rgba;
 
548
 
 
549
   case GL_R3_G3_B2:
 
550
   case GL_RGB4:
 
551
   case GL_RGB5:
 
552
   case GL_RGB8:
 
553
   case GL_RGB10:
 
554
   case GL_RGB12:
 
555
   case GL_RGB16:
 
556
      return &_mesa_texformat_rgb;
 
557
 
 
558
   case GL_ALPHA:
 
559
   case GL_ALPHA4:
 
560
   case GL_ALPHA8:
 
561
   case GL_ALPHA12:
 
562
   case GL_ALPHA16:
 
563
      return &_mesa_texformat_alpha;
 
564
 
 
565
   case 1:
 
566
   case GL_LUMINANCE:
 
567
   case GL_LUMINANCE4:
 
568
   case GL_LUMINANCE8:
 
569
   case GL_LUMINANCE12:
 
570
   case GL_LUMINANCE16:
 
571
      return &_mesa_texformat_luminance;
 
572
 
 
573
   case 2:
 
574
   case GL_LUMINANCE_ALPHA:
 
575
   case GL_LUMINANCE4_ALPHA4:
 
576
   case GL_LUMINANCE6_ALPHA2:
 
577
   case GL_LUMINANCE8_ALPHA8:
 
578
   case GL_LUMINANCE12_ALPHA4:
 
579
   case GL_LUMINANCE12_ALPHA12:
 
580
   case GL_LUMINANCE16_ALPHA16:
 
581
      return &_mesa_texformat_luminance_alpha;
 
582
 
 
583
   case GL_INTENSITY:
 
584
   case GL_INTENSITY4:
 
585
   case GL_INTENSITY8:
 
586
   case GL_INTENSITY12:
 
587
   case GL_INTENSITY16:
 
588
      return &_mesa_texformat_intensity;
 
589
 
 
590
   case GL_COLOR_INDEX:
 
591
   case GL_COLOR_INDEX1_EXT:
 
592
   case GL_COLOR_INDEX2_EXT:
 
593
   case GL_COLOR_INDEX4_EXT:
 
594
   case GL_COLOR_INDEX8_EXT:
 
595
   case GL_COLOR_INDEX12_EXT:
 
596
   case GL_COLOR_INDEX16_EXT:
 
597
      return &_mesa_texformat_color_index;
 
598
 
 
599
   case GL_DEPTH_COMPONENT:
 
600
   case GL_DEPTH_COMPONENT16_SGIX:
 
601
   case GL_DEPTH_COMPONENT24_SGIX:
 
602
   case GL_DEPTH_COMPONENT32_SGIX:
 
603
      if (!ctx->Extensions.SGIX_depth_texture)
 
604
         _mesa_problem(ctx, "depth format without GL_SGIX_depth_texture");
 
605
      return &_mesa_texformat_depth_component;
 
606
 
 
607
   case GL_COMPRESSED_ALPHA_ARB:
 
608
      if (!ctx->Extensions.ARB_texture_compression)
 
609
         _mesa_problem(ctx, "texture compression extension not enabled");
 
610
      return &_mesa_texformat_alpha;
 
611
   case GL_COMPRESSED_LUMINANCE_ARB:
 
612
      if (!ctx->Extensions.ARB_texture_compression)
 
613
         _mesa_problem(ctx, "texture compression extension not enabled");
 
614
      return &_mesa_texformat_luminance;
 
615
   case GL_COMPRESSED_LUMINANCE_ALPHA_ARB:
 
616
      if (!ctx->Extensions.ARB_texture_compression)
 
617
         _mesa_problem(ctx, "texture compression extension not enabled");
 
618
      return &_mesa_texformat_luminance_alpha;
 
619
   case GL_COMPRESSED_INTENSITY_ARB:
 
620
      if (!ctx->Extensions.ARB_texture_compression)
 
621
         _mesa_problem(ctx, "texture compression extension not enabled");
 
622
      return &_mesa_texformat_intensity;
 
623
   case GL_COMPRESSED_RGB_ARB:
 
624
      if (!ctx->Extensions.ARB_texture_compression)
 
625
         _mesa_problem(ctx, "texture compression extension not enabled");
 
626
      return &_mesa_texformat_rgb;
 
627
   case GL_COMPRESSED_RGBA_ARB:
 
628
      if (!ctx->Extensions.ARB_texture_compression)
 
629
         _mesa_problem(ctx, "texture compression extension not enabled");
 
630
      return &_mesa_texformat_rgba;
 
631
 
 
632
   case GL_YCBCR_MESA:
 
633
      if (type == GL_UNSIGNED_SHORT_8_8_MESA)
 
634
         return &_mesa_texformat_ycbcr;
 
635
      else
 
636
         return &_mesa_texformat_ycbcr_rev;
 
637
 
 
638
   default:
 
639
      _mesa_problem(ctx, "unexpected format in _mesa_choose_tex_format()");
 
640
      printf("intformat = %d %x\n", internalFormat, internalFormat);
 
641
      return NULL;
 
642
   }
 
643
}
 
644
 
 
645
 
 
646
 
 
647
 
 
648
/*
 
649
 * Return the base texture format for the given compressed format
 
650
 * Called via ctx->Driver.BaseCompressedTexFormat().
 
651
 * This function is used by software rasterizers.  Hardware drivers
 
652
 * which support texture compression should not use this function but
 
653
 * a specialized function instead.
 
654
 */
 
655
GLint
 
656
_mesa_base_compressed_texformat(GLcontext *ctx, GLint intFormat)
 
657
{
 
658
   switch (intFormat) {
 
659
   case GL_COMPRESSED_ALPHA_ARB:
 
660
      return GL_ALPHA;
 
661
   case GL_COMPRESSED_LUMINANCE_ARB:
 
662
      return GL_LUMINANCE;
 
663
   case GL_COMPRESSED_LUMINANCE_ALPHA_ARB:
 
664
      return GL_LUMINANCE_ALPHA;
 
665
   case GL_COMPRESSED_INTENSITY_ARB:
 
666
      return GL_INTENSITY;
 
667
   case GL_COMPRESSED_RGB_ARB:
 
668
      return GL_RGB;
 
669
   case GL_COMPRESSED_RGBA_ARB:
 
670
      return GL_RGBA;
 
671
   default:
 
672
      return -1;  /* not a recognized compressed format */
 
673
   }
 
674
}
 
675
 
 
676
 
 
677
/*
 
678
 * Called via ctx->Driver.CompressedTextureSize().
 
679
 * This function is only used by software rasterizers.
 
680
 * Hardware drivers will have to implement a specialized function.
 
681
 */
 
682
GLint
 
683
_mesa_compressed_texture_size(GLcontext *ctx,
 
684
                              const struct gl_texture_image *texImage)
 
685
{
 
686
   GLint b;
 
687
   assert(texImage);
 
688
   assert(texImage->TexFormat);
 
689
 
 
690
   b = texImage->Width * texImage->Height * texImage->Depth *
 
691
      texImage->TexFormat->TexelBytes;
 
692
   assert(b > 0);
 
693
   return b;
 
694
}