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

« back to all changes in this revision

Viewing changes to unix/xc/lib/GL/mesa/src/drv/mga/mgatexcnv.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
/* $XFree86: xc/lib/GL/mesa/src/drv/mga/mgatexcnv.c,v 1.3 2002/10/30 12:51:36 alanh Exp $ */
 
2
/*
 
3
 * Copyright 2000-2001 VA Linux Systems, Inc.
 
4
 * All Rights Reserved.
 
5
 *
 
6
 * Permission is hereby granted, free of charge, to any person obtaining a
 
7
 * copy of this software and associated documentation files (the "Software"),
 
8
 * to deal in the Software without restriction, including without limitation
 
9
 * on the rights to use, copy, modify, merge, publish, distribute, sub
 
10
 * license, and/or sell copies of the Software, and to permit persons to whom
 
11
 * the Software is furnished to do so, subject to the following conditions:
 
12
 *
 
13
 * The above copyright notice and this permission notice (including the next
 
14
 * paragraph) shall be included in all copies or substantial portions of the
 
15
 * Software.
 
16
 *
 
17
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 
18
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 
19
 * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.  IN NO EVENT SHALL
 
20
 * VA LINUX SYSTEMS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
 
21
 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
 
22
 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
 
23
 * OTHER DEALINGS IN THE SOFTWARE.
 
24
 *
 
25
 * Authors:
 
26
 *    Keith Whitwell <keith@tungstengraphics.com>
 
27
 */
 
28
 
 
29
#include <stdlib.h>
 
30
#include <stdio.h>
 
31
 
 
32
#include <GL/gl.h>
 
33
 
 
34
#include "mm.h"
 
35
#include "mgacontext.h"
 
36
#include "mgatex.h"
 
37
 
 
38
 
 
39
/*
 
40
 * mgaConvertTexture
 
41
 * Converts a mesa format texture to the apropriate hardware format
 
42
 * Note that sometimes width may be larger than the texture, like 64x1
 
43
 * for an 8x8 texture.  This happens when we have to crutch the pitch
 
44
 * limits of the mga by uploading a block of texels as a single line.
 
45
 */
 
46
void mgaConvertTexture( GLuint *destPtr, int texelBytes,
 
47
                        struct gl_texture_image *image,
 
48
                        int x, int y, int width, int height )
 
49
{
 
50
   register int         i, j;
 
51
   GLubyte              *src;
 
52
   int stride;
 
53
 
 
54
   if (0)
 
55
      fprintf(stderr, "texture image %p\n", image->Data);
 
56
 
 
57
   if (image->Data == 0)
 
58
      return;
 
59
 
 
60
   /* FIXME: g400 luminance_alpha internal format */
 
61
   switch (texelBytes) {
 
62
   case 1:
 
63
      switch (image->Format) {
 
64
      case GL_COLOR_INDEX:
 
65
      case GL_INTENSITY:
 
66
      case GL_LUMINANCE:
 
67
      case GL_ALPHA:
 
68
         src = (GLubyte *)image->Data + ( y * image->Width + x );
 
69
         stride = (image->Width - width);
 
70
         for ( i = height ; i ; i-- ) {
 
71
            for ( j = width >> 2  ; j ; j-- ) {
 
72
 
 
73
               *destPtr++ = src[0] | ( src[1] << 8 ) | ( src[2] << 16 ) | ( src[3] << 24 );
 
74
               src += 4;
 
75
            }
 
76
            src += stride;
 
77
         }
 
78
         break;
 
79
      default:
 
80
         goto format_error;
 
81
      }
 
82
      break;
 
83
   case 2:
 
84
      switch (image->Format) {
 
85
      case GL_RGB:
 
86
         src = (GLubyte *)image->Data + ( y * image->Width + x ) * 3;
 
87
         stride = (image->Width - width) * 3;
 
88
         for ( i = height ; i ; i-- ) {
 
89
            for ( j = width >> 1  ; j ; j-- ) {
 
90
 
 
91
               *destPtr++ = MGAPACKCOLOR565(src[0],src[1],src[2]) |
 
92
                  ( MGAPACKCOLOR565(src[3],src[4],src[5]) << 16 );
 
93
               src += 6;
 
94
            }
 
95
            src += stride;
 
96
         }
 
97
         break;
 
98
      case GL_RGBA:
 
99
         src = (GLubyte *)image->Data + ( y * image->Width + x ) * 4;
 
100
         stride = (image->Width - width) * 4;
 
101
         for ( i = height ; i ; i-- ) {
 
102
            for ( j = width >> 1  ; j ; j-- ) {
 
103
 
 
104
               *destPtr++ = MGAPACKCOLOR4444(src[0],src[1],src[2],src[3]) |
 
105
                  ( MGAPACKCOLOR4444(src[4],src[5],src[6],src[7]) << 16 );
 
106
               src += 8;
 
107
            }
 
108
            src += stride;
 
109
         }
 
110
         break;
 
111
      case GL_LUMINANCE:
 
112
         src = (GLubyte *)image->Data + ( y * image->Width + x );
 
113
         stride = (image->Width - width);
 
114
         for ( i = height ; i ; i-- ) {
 
115
            for ( j = width >> 1  ; j ; j-- ) {
 
116
               /* FIXME: should probably use 555 texture to get true grey */
 
117
               *destPtr++ = MGAPACKCOLOR565(src[0],src[0],src[0]) |
 
118
                  ( MGAPACKCOLOR565(src[1],src[1],src[1]) << 16 );
 
119
               src += 2;
 
120
            }
 
121
            src += stride;
 
122
         }
 
123
         break;
 
124
      case GL_INTENSITY:
 
125
         src = (GLubyte *)image->Data + ( y * image->Width + x );
 
126
         stride = (image->Width - width);
 
127
         for ( i = height ; i ; i-- ) {
 
128
            for ( j = width >> 1  ; j ; j-- ) {
 
129
 
 
130
               *destPtr++ = MGAPACKCOLOR4444(src[0],src[0],src[0],src[0]) |
 
131
                  ( MGAPACKCOLOR4444(src[1],src[1],src[1],src[1]) << 16 );
 
132
               src += 2;
 
133
            }
 
134
            src += stride;
 
135
         }
 
136
         break;
 
137
      case GL_ALPHA:
 
138
         src = (GLubyte *)image->Data + ( y * image->Width + x );
 
139
         stride = (image->Width - width);
 
140
         for ( i = height ; i ; i-- ) {
 
141
            for ( j = width >> 1  ; j ; j-- ) {
 
142
 
 
143
               *destPtr++ = MGAPACKCOLOR4444(255,255,255,src[0]) |
 
144
                  ( MGAPACKCOLOR4444(255,255,255,src[1]) << 16 );
 
145
               src += 2;
 
146
            }
 
147
            src += stride;
 
148
         }
 
149
         break;
 
150
      case GL_LUMINANCE_ALPHA:
 
151
         src = (GLubyte *)image->Data + ( y * image->Width + x ) * 2;
 
152
         stride = (image->Width - width) * 2;
 
153
         for ( i = height ; i ; i-- ) {
 
154
            for ( j = width >> 1  ; j ; j-- ) {
 
155
 
 
156
               *destPtr++ = MGAPACKCOLOR4444(src[0],src[0],src[0],src[1]) |
 
157
                  ( MGAPACKCOLOR4444(src[2],src[2],src[2],src[3]) << 16 );
 
158
               src += 4;
 
159
            }
 
160
            src += stride;
 
161
         }
 
162
         break;
 
163
      default:
 
164
         goto format_error;
 
165
      }
 
166
      break;
 
167
   case 4:
 
168
      switch (image->Format) {
 
169
      case GL_RGB:
 
170
         src = (GLubyte *)image->Data + (  y * image->Width + x ) * 3;
 
171
         stride = (image->Width - width) * 3;
 
172
         for ( i = height ; i ; i-- ) {
 
173
            for ( j = width ; j ; j-- ) {
 
174
 
 
175
               *destPtr++ = MGAPACKCOLOR8888(src[0],src[1],src[2], 255);
 
176
               src += 3;
 
177
            }
 
178
            src += stride;
 
179
         }
 
180
         break;
 
181
      case GL_RGBA:
 
182
         src = (GLubyte *)image->Data + (  y * image->Width + x ) * 4;
 
183
         stride = (image->Width - width) * 4;
 
184
         for ( i = height ; i ; i-- ) {
 
185
            for ( j = width  ; j ; j-- ) {
 
186
 
 
187
               *destPtr++ = MGAPACKCOLOR8888(src[0],src[1],src[2],src[3]);
 
188
               src += 4;
 
189
            }
 
190
            src += stride;
 
191
         }
 
192
         break;
 
193
      case GL_LUMINANCE:
 
194
         src = (GLubyte *)image->Data + ( y * image->Width + x );
 
195
         stride = (image->Width - width);
 
196
         for ( i = height ; i ; i-- ) {
 
197
            for ( j = width ; j ; j-- ) {
 
198
 
 
199
               *destPtr++ = MGAPACKCOLOR8888(src[0],src[0],src[0], 255);
 
200
               src += 1;
 
201
            }
 
202
            src += stride;
 
203
         }
 
204
         break;
 
205
      case GL_INTENSITY:
 
206
         src = (GLubyte *)image->Data + (  y * image->Width + x );
 
207
         stride = (image->Width - width);
 
208
         for ( i = height ; i ; i-- ) {
 
209
            for ( j = width ; j ; j-- ) {
 
210
 
 
211
               *destPtr++ = MGAPACKCOLOR8888(src[0],src[0],src[0],src[0]);
 
212
               src += 1;
 
213
            }
 
214
            src += stride;
 
215
         }
 
216
         break;
 
217
      case GL_ALPHA:
 
218
         src = (GLubyte *)image->Data + ( y * image->Width + x );
 
219
         stride = (image->Width - width);
 
220
         for ( i = height ; i ; i-- ) {
 
221
            for ( j = width ; j ; j-- ) {
 
222
 
 
223
               *destPtr++ = MGAPACKCOLOR8888(255,255,255,src[0]);
 
224
               src += 1;
 
225
            }
 
226
            src += stride;
 
227
         }
 
228
         break;
 
229
      case GL_LUMINANCE_ALPHA:
 
230
         src = (GLubyte *)image->Data + ( y * image->Width + x ) * 2;
 
231
         stride = (image->Width - width) * 2;
 
232
         for ( i = height ; i ; i-- ) {
 
233
            for ( j = width ; j ; j-- ) {
 
234
 
 
235
               *destPtr++ = MGAPACKCOLOR8888(src[0],src[0],
 
236
                                             src[0],src[1]);
 
237
               src += 2;
 
238
            }
 
239
            src += stride;
 
240
         }
 
241
         break;
 
242
      default:
 
243
         goto format_error;
 
244
      }
 
245
      break;
 
246
   default:
 
247
      goto format_error;
 
248
   }
 
249
 
 
250
   return;
 
251
 
 
252
 format_error:
 
253
 
 
254
   fprintf(stderr, "Unsupported texelBytes %i, image->Format %i\n",
 
255
           (int)texelBytes, (int)image->Format );
 
256
}