1 /* $Id: texutil_tmp.h,v 1.3 2001/03/18 13:34:24 gareth Exp $ */
4 * Mesa 3-D graphics library
7 * Copyright (C) 1999-2001 Brian Paul All Rights Reserved.
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:
16 * The above copyright notice and this permission notice shall be included
17 * in all copies or substantial portions of the Software.
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.
27 * Gareth Hughes <gareth@valinux.com>
31 * NOTE: All 3D code is untested and most definitely broken...
34 #define DST_TEXEL_BYTES (4 / DST_TEXELS_PER_DWORD)
35 #define DST_ROW_WIDTH (convert->width * DST_TEXEL_BYTES)
36 #define DST_ROW_STRIDE (convert->imageWidth * DST_TEXEL_BYTES)
37 #define DST_IMG_STRIDE (convert->imageWidth * \
38 convert->imageHeight * DST_TEXEL_BYTES)
41 /* ================================================================
42 * PRE: No pixelstore attribs, width == imageWidth.
45 TAG(texsubimage2d
)( struct gl_texture_convert
*convert
)
47 const GLubyte
*src
= (const GLubyte
*)convert
->srcImage
;
48 GLuint
*dst
= (GLuint
*)((GLubyte
*)convert
->dstImage
+
49 (convert
->yoffset
* convert
->imageWidth
+
50 convert
->xoffset
) * DST_TEXEL_BYTES
);
52 (void) dwords
; (void) i
;
55 fprintf( stderr
, __FUNCTION__
"\n" );
58 MEMCPY( dst
, src
, convert
->height
* DST_ROW_WIDTH
);
60 dwords
= (convert
->width
* convert
->height
+
61 DST_TEXELS_PER_DWORD
- 1) / DST_TEXELS_PER_DWORD
;
63 for ( i
= 0 ; i
< dwords
; i
++ ) {
64 *dst
++ = CONVERT_TEXEL_DWORD( src
);
65 src
+= SRC_TEXEL_BYTES
* DST_TEXELS_PER_DWORD
;
72 /* PRE: As above, height == imageHeight also.
75 TAG(texsubimage3d
)( struct gl_texture_convert
*convert
)
77 const GLubyte
*src
= (const GLubyte
*)convert
->srcImage
;
78 GLuint
*dst
= (GLuint
*)((GLubyte
*)convert
->dstImage
+
79 ((convert
->zoffset
* convert
->height
+
80 convert
->yoffset
) * convert
->width
+
81 convert
->xoffset
) * DST_TEXEL_BYTES
);
83 (void) dwords
; (void) i
;
86 fprintf( stderr
, __FUNCTION__
"\n" );
89 MEMCPY( dst
, src
, convert
->depth
* convert
->height
* DST_ROW_WIDTH
);
91 dwords
= (convert
->width
* convert
->height
* convert
->depth
+
92 DST_TEXELS_PER_DWORD
- 1) / DST_TEXELS_PER_DWORD
;
94 for ( i
= 0 ; i
< dwords
; i
++ ) {
95 *dst
++ = CONVERT_TEXEL_DWORD( src
);
96 src
+= SRC_TEXEL_BYTES
* DST_TEXELS_PER_DWORD
;
105 /* ================================================================
106 * PRE: No pixelstore attribs, width != imageWidth.
109 TAG(texsubimage2d_stride
)( struct gl_texture_convert
*convert
)
111 const GLubyte
*src
= (const GLubyte
*)convert
->srcImage
;
112 DST_TYPE
*dst
= (DST_TYPE
*)((GLubyte
*)convert
->dstImage
+
113 (convert
->yoffset
* convert
->imageWidth
+
114 convert
->xoffset
) * DST_TEXEL_BYTES
);
118 adjust
= convert
->imageWidth
- convert
->width
;
121 fprintf( stderr
, __FUNCTION__
":\n" );
122 fprintf( stderr
, " x=%d y=%d w=%d h=%d s=%d\n",
123 convert
->xoffset
, convert
->yoffset
, convert
->width
,
124 convert
->height
, convert
->imageWidth
);
125 fprintf( stderr
, " adjust=%d\n", adjust
);
128 for ( row
= 0 ; row
< convert
->height
; row
++ ) {
129 for ( col
= 0 ; col
< convert
->width
; col
++ ) {
130 *dst
++ = CONVERT_TEXEL( src
);
131 src
+= SRC_TEXEL_BYTES
;
139 /* PRE: As above, or height != imageHeight also.
142 TAG(texsubimage3d_stride
)( struct gl_texture_convert
*convert
)
144 const GLubyte
*src
= (const GLubyte
*)convert
->srcImage
;
145 DST_TYPE
*dst
= (DST_TYPE
*)((GLubyte
*)convert
->dstImage
+
146 ((convert
->zoffset
* convert
->imageHeight
+
147 convert
->yoffset
) * convert
->imageWidth
+
148 convert
->xoffset
) * DST_TEXEL_BYTES
);
152 adjust
= convert
->imageWidth
- convert
->width
;
155 fprintf( stderr
, __FUNCTION__
":\n" );
156 fprintf( stderr
, " x=%d y=%d w=%d h=%d s=%d\n",
157 convert
->xoffset
, convert
->yoffset
, convert
->width
,
158 convert
->height
, convert
->imageWidth
);
159 fprintf( stderr
, " adjust=%d\n", adjust
);
162 for ( img
= 0 ; img
< convert
->depth
; img
++ ) {
163 for ( row
= 0 ; row
< convert
->height
; row
++ ) {
164 for ( col
= 0 ; col
< convert
->width
; col
++ ) {
165 *dst
++ = CONVERT_TEXEL( src
);
166 src
+= SRC_TEXEL_BYTES
;
178 /* ================================================================
179 * PRE: Require pixelstore attribs, width == imageWidth.
182 TAG(texsubimage2d_pack
)( struct gl_texture_convert
*convert
)
184 const GLubyte
*src
= (const GLubyte
*)
185 _mesa_image_address( convert
->packing
, convert
->srcImage
,
186 convert
->width
, convert
->height
,
187 convert
->format
, convert
->type
, 0, 0, 0 );
188 const GLint srcRowStride
=
189 _mesa_image_row_stride( convert
->packing
, convert
->width
,
190 convert
->format
, convert
->type
);
191 GLuint
*dst
= (GLuint
*)((GLubyte
*)convert
->dstImage
+
192 (convert
->yoffset
* convert
->width
+
193 convert
->xoffset
) * DST_TEXEL_BYTES
);
199 fprintf( stderr
, __FUNCTION__
"\n" );
201 width
= ((convert
->width
+ DST_TEXELS_PER_DWORD
- 1)
202 & ~(DST_TEXELS_PER_DWORD
- 1));
204 for ( row
= 0 ; row
< convert
->height
; row
++ ) {
205 #ifdef CONVERT_DIRECT
206 MEMCPY( dst
, src
, DST_ROW_STRIDE
);
208 dst
= (GLuint
*)((GLubyte
*)dst
+ DST_ROW_STRIDE
);
210 const GLubyte
*srcRow
= src
;
211 for ( col
= width
/ DST_TEXELS_PER_DWORD
; col
; col
-- ) {
212 *dst
++ = CONVERT_TEXEL_DWORD( src
);
213 src
+= SRC_TEXEL_BYTES
* DST_TEXELS_PER_DWORD
;
215 src
= srcRow
+ srcRowStride
;
222 /* PRE: as above, height == imageHeight also.
225 TAG(texsubimage3d_pack
)( struct gl_texture_convert
*convert
)
227 const GLubyte
*src
= (const GLubyte
*)
228 _mesa_image_address( convert
->packing
, convert
->srcImage
,
229 convert
->width
, convert
->height
,
230 convert
->format
, convert
->type
, 0, 0, 0 );
231 const GLint srcRowStride
=
232 _mesa_image_row_stride( convert
->packing
, convert
->width
,
233 convert
->format
, convert
->type
);
234 GLuint
*dst
= (GLuint
*)((GLubyte
*)convert
->dstImage
+
235 ((convert
->zoffset
* convert
->height
+
236 convert
->yoffset
) * convert
->width
+
237 convert
->xoffset
) * DST_TEXEL_BYTES
);
243 fprintf( stderr
, __FUNCTION__
"\n" );
245 width
= ((convert
->width
+ DST_TEXELS_PER_DWORD
- 1)
246 & ~(DST_TEXELS_PER_DWORD
- 1));
248 for ( img
= 0 ; img
< convert
->depth
; img
++ ) {
249 for ( row
= 0 ; row
< convert
->height
; row
++ ) {
250 #ifdef CONVERT_DIRECT
251 MEMCPY( dst
, src
, DST_ROW_STRIDE
);
253 dst
= (GLuint
*)((GLubyte
*)dst
+ DST_ROW_STRIDE
);
255 const GLubyte
*srcRow
= src
;
256 for ( col
= width
/ DST_TEXELS_PER_DWORD
; col
; col
-- ) {
257 *dst
++ = CONVERT_TEXEL_DWORD( src
);
258 src
+= SRC_TEXEL_BYTES
* DST_TEXELS_PER_DWORD
;
260 src
= srcRow
+ srcRowStride
;
270 /* ================================================================
271 * PRE: Require pixelstore attribs, width != imageWidth.
274 TAG(texsubimage2d_stride_pack
)( struct gl_texture_convert
*convert
)
276 const GLubyte
*src
= (const GLubyte
*)
277 _mesa_image_address( convert
->packing
, convert
->srcImage
,
278 convert
->width
, convert
->height
,
279 convert
->format
, convert
->type
, 0, 0, 0 );
280 const GLint srcRowStride
=
281 _mesa_image_row_stride( convert
->packing
, convert
->width
,
282 convert
->format
, convert
->type
);
283 DST_TYPE
*dst
= (DST_TYPE
*)((GLubyte
*)convert
->dstImage
+
284 (convert
->yoffset
* convert
->imageWidth
+
285 convert
->xoffset
) * DST_TEXEL_BYTES
);
290 adjust
= convert
->imageWidth
- convert
->width
;
293 fprintf( stderr
, __FUNCTION__
":\n" );
294 fprintf( stderr
, " x=%d y=%d w=%d h=%d s=%d\n",
295 convert
->xoffset
, convert
->yoffset
, convert
->width
,
296 convert
->height
, convert
->imageWidth
);
297 fprintf( stderr
, " adjust=%d\n", adjust
);
300 for ( row
= 0 ; row
< convert
->height
; row
++ ) {
301 #ifdef CONVERT_DIRECT
302 MEMCPY( dst
, src
, DST_ROW_WIDTH
);
304 dst
+= convert
->imageWidth
;
306 const GLubyte
*srcRow
= src
;
307 for ( col
= 0 ; col
< convert
->width
; col
++ ) {
308 *dst
++ = CONVERT_TEXEL( src
);
309 src
+= SRC_TEXEL_BYTES
;
311 src
= srcRow
+ srcRowStride
;
319 /* PRE: As above, or height != imageHeight also.
322 TAG(texsubimage3d_stride_pack
)( struct gl_texture_convert
*convert
)
324 const GLubyte
*src
= (const GLubyte
*)
325 _mesa_image_address( convert
->packing
, convert
->srcImage
,
326 convert
->width
, convert
->height
,
327 convert
->format
, convert
->type
, 0, 0, 0 );
328 const GLint srcRowStride
=
329 _mesa_image_row_stride( convert
->packing
, convert
->width
,
330 convert
->format
, convert
->type
);
331 DST_TYPE
*dst
= (DST_TYPE
*)((GLubyte
*)convert
->dstImage
+
332 ((convert
->zoffset
* convert
->imageHeight
+
333 convert
->yoffset
) * convert
->imageWidth
+
334 convert
->xoffset
) * DST_TEXEL_BYTES
);
339 adjust
= convert
->imageWidth
- convert
->width
;
342 fprintf( stderr
, __FUNCTION__
":\n" );
343 fprintf( stderr
, " x=%d y=%d w=%d h=%d s=%d\n",
344 convert
->xoffset
, convert
->yoffset
, convert
->width
,
345 convert
->height
, convert
->imageWidth
);
346 fprintf( stderr
, " adjust=%d\n", adjust
);
349 for ( img
= 0 ; img
< convert
->depth
; img
++ ) {
350 for ( row
= 0 ; row
< convert
->height
; row
++ ) {
351 #ifdef CONVERT_DIRECT
352 MEMCPY( dst
, src
, DST_ROW_WIDTH
);
354 dst
+= convert
->imageWidth
;
356 const GLubyte
*srcRow
= src
;
357 for ( col
= 0 ; col
< convert
->width
; col
++ ) {
358 *dst
++ = CONVERT_TEXEL( src
);
359 src
+= SRC_TEXEL_BYTES
;
361 src
= srcRow
+ srcRowStride
;
373 static convert_func
TAG(texsubimage2d_tab
)[] = {
375 TAG(texsubimage2d_stride
),
376 TAG(texsubimage2d_pack
),
377 TAG(texsubimage2d_stride_pack
),
380 static convert_func
TAG(texsubimage3d_tab
)[] = {
382 TAG(texsubimage3d_stride
),
383 TAG(texsubimage3d_pack
),
384 TAG(texsubimage3d_stride_pack
),
388 #ifndef PRESERVE_DST_TYPE
390 #undef DST_TEXELS_PER_DWORD
393 #undef SRC_TEXEL_BYTES
394 #undef DST_TEXEL_BYTES
396 #undef DST_ROW_STRIDE
399 #undef CONVERT_TEXEL_DWORD
400 #undef CONVERT_DIRECT
404 #undef PRESERVE_DST_TYPE