1
/* $XFree86: xc/lib/GL/mesa/src/drv/mga/mgatexcnv.c,v 1.3 2002/10/30 12:51:36 alanh Exp $ */
3
* Copyright 2000-2001 VA Linux Systems, Inc.
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:
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
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.
26
* Keith Whitwell <keith@tungstengraphics.com>
35
#include "mgacontext.h"
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.
46
void mgaConvertTexture( GLuint *destPtr, int texelBytes,
47
struct gl_texture_image *image,
48
int x, int y, int width, int height )
55
fprintf(stderr, "texture image %p\n", image->Data);
60
/* FIXME: g400 luminance_alpha internal format */
63
switch (image->Format) {
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-- ) {
73
*destPtr++ = src[0] | ( src[1] << 8 ) | ( src[2] << 16 ) | ( src[3] << 24 );
84
switch (image->Format) {
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-- ) {
91
*destPtr++ = MGAPACKCOLOR565(src[0],src[1],src[2]) |
92
( MGAPACKCOLOR565(src[3],src[4],src[5]) << 16 );
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-- ) {
104
*destPtr++ = MGAPACKCOLOR4444(src[0],src[1],src[2],src[3]) |
105
( MGAPACKCOLOR4444(src[4],src[5],src[6],src[7]) << 16 );
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 );
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-- ) {
130
*destPtr++ = MGAPACKCOLOR4444(src[0],src[0],src[0],src[0]) |
131
( MGAPACKCOLOR4444(src[1],src[1],src[1],src[1]) << 16 );
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-- ) {
143
*destPtr++ = MGAPACKCOLOR4444(255,255,255,src[0]) |
144
( MGAPACKCOLOR4444(255,255,255,src[1]) << 16 );
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-- ) {
156
*destPtr++ = MGAPACKCOLOR4444(src[0],src[0],src[0],src[1]) |
157
( MGAPACKCOLOR4444(src[2],src[2],src[2],src[3]) << 16 );
168
switch (image->Format) {
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-- ) {
175
*destPtr++ = MGAPACKCOLOR8888(src[0],src[1],src[2], 255);
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-- ) {
187
*destPtr++ = MGAPACKCOLOR8888(src[0],src[1],src[2],src[3]);
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-- ) {
199
*destPtr++ = MGAPACKCOLOR8888(src[0],src[0],src[0], 255);
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-- ) {
211
*destPtr++ = MGAPACKCOLOR8888(src[0],src[0],src[0],src[0]);
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-- ) {
223
*destPtr++ = MGAPACKCOLOR8888(255,255,255,src[0]);
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-- ) {
235
*destPtr++ = MGAPACKCOLOR8888(src[0],src[0],
254
fprintf(stderr, "Unsupported texelBytes %i, image->Format %i\n",
255
(int)texelBytes, (int)image->Format );