1 /* $Id: s_copypix.c,v 1.40 2002/08/07 00:45:07 brianp Exp $ */
4 * Mesa 3-D graphics library
7 * Copyright (C) 1999-2002 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.
38 #include "s_context.h"
40 #include "s_histogram.h"
41 #include "s_pixeltex.h"
43 #include "s_stencil.h"
44 #include "s_texture.h"
50 * Determine if there's overlap in an image copy.
51 * This test also compensates for the fact that copies are done from
52 * bottom to top and overlaps can sometimes be handled correctly
53 * without making a temporary image copy.
56 regions_overlap(GLint srcx
, GLint srcy
,
57 GLint dstx
, GLint dsty
,
58 GLint width
, GLint height
,
59 GLfloat zoomX
, GLfloat zoomY
)
61 if (zoomX
== 1.0 && zoomY
== 1.0) {
63 if (srcx
>= dstx
+ width
|| (srcx
+ width
<= dstx
)) {
66 else if (srcy
< dsty
) { /* this is OK */
69 else if (srcy
> dsty
+ height
) {
77 /* add one pixel of slop when zooming, just to be safe */
78 if ((srcx
> dstx
+ (width
* zoomX
) + 1) || (srcx
+ width
+ 1 < dstx
)) {
81 else if ((srcy
< dsty
) && (srcy
+ height
< dsty
+ (height
* zoomY
))) {
84 else if ((srcy
> dsty
) && (srcy
+ height
> dsty
+ (height
* zoomY
))) {
96 * RGBA copypixels with convolution.
99 copy_conv_rgba_pixels(GLcontext
*ctx
, GLint srcx
, GLint srcy
,
100 GLint width
, GLint height
, GLint destx
, GLint desty
)
102 SWcontext
*swrast
= SWRAST_CONTEXT(ctx
);
103 GLboolean quick_draw
;
105 GLboolean changeBuffer
;
106 const GLboolean zoom
= ctx
->Pixel
.ZoomX
!= 1.0F
|| ctx
->Pixel
.ZoomY
!= 1.0F
;
107 const GLuint transferOps
= ctx
->_ImageTransferState
;
108 GLfloat
*dest
, *tmpImage
, *convImage
;
111 INIT_SPAN(span
, GL_BITMAP
, 0, 0, SPAN_RGBA
);
114 _mesa_span_default_z(ctx
, &span
);
115 if (ctx
->Fog
.Enabled
)
116 _mesa_span_default_fog(ctx
, &span
);
119 if (SWRAST_CONTEXT(ctx
)->_RasterMask
== 0
122 && destx
+ width
<= (GLint
) ctx
->DrawBuffer
->Width
) {
123 quick_draw
= GL_TRUE
;
126 quick_draw
= GL_FALSE
;
129 /* If read and draw buffer are different we must do buffer switching */
130 changeBuffer
= ctx
->Pixel
.ReadBuffer
!= ctx
->Color
.DrawBuffer
131 || ctx
->DrawBuffer
!= ctx
->ReadBuffer
;
134 /* allocate space for GLfloat image */
135 tmpImage
= (GLfloat
*) MALLOC(width
* height
* 4 * sizeof(GLfloat
));
137 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glCopyPixels");
140 convImage
= (GLfloat
*) MALLOC(width
* height
* 4 * sizeof(GLfloat
));
143 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glCopyPixels");
150 /* choose the read buffer */
151 _swrast_use_read_buffer(ctx
);
154 /* read source image */
156 for (row
= 0; row
< height
; row
++) {
157 GLchan rgba
[MAX_WIDTH
][4];
159 _mesa_read_rgba_span(ctx
, ctx
->ReadBuffer
, width
, srcx
, srcy
+ row
, rgba
);
160 /* convert GLchan to GLfloat */
161 for (i
= 0; i
< width
; i
++) {
162 *dest
++ = (GLfloat
) rgba
[i
][RCOMP
] * (1.0F
/ CHAN_MAXF
);
163 *dest
++ = (GLfloat
) rgba
[i
][GCOMP
] * (1.0F
/ CHAN_MAXF
);
164 *dest
++ = (GLfloat
) rgba
[i
][BCOMP
] * (1.0F
/ CHAN_MAXF
);
165 *dest
++ = (GLfloat
) rgba
[i
][ACOMP
] * (1.0F
/ CHAN_MAXF
);
170 /* restore default src/dst buffer */
171 _swrast_use_draw_buffer(ctx
);
174 /* do image transfer ops up until convolution */
175 for (row
= 0; row
< height
; row
++) {
176 GLfloat (*rgba
)[4] = (GLfloat (*)[4]) (tmpImage
+ row
* width
* 4);
179 if (transferOps
& IMAGE_SCALE_BIAS_BIT
) {
180 _mesa_scale_and_bias_rgba(ctx
, width
, rgba
,
181 ctx
->Pixel
.RedScale
, ctx
->Pixel
.GreenScale
,
182 ctx
->Pixel
.BlueScale
, ctx
->Pixel
.AlphaScale
,
183 ctx
->Pixel
.RedBias
, ctx
->Pixel
.GreenBias
,
184 ctx
->Pixel
.BlueBias
, ctx
->Pixel
.AlphaBias
);
186 /* color map lookup */
187 if (transferOps
& IMAGE_MAP_COLOR_BIT
) {
188 _mesa_map_rgba(ctx
, width
, rgba
);
190 /* GL_COLOR_TABLE lookup */
191 if (transferOps
& IMAGE_COLOR_TABLE_BIT
) {
192 _mesa_lookup_rgba(&ctx
->ColorTable
, width
, rgba
);
197 if (ctx
->Pixel
.Convolution2DEnabled
) {
198 _mesa_convolve_2d_image(ctx
, &width
, &height
, tmpImage
, convImage
);
201 ASSERT(ctx
->Pixel
.Separable2DEnabled
);
202 _mesa_convolve_sep_image(ctx
, &width
, &height
, tmpImage
, convImage
);
206 /* do remaining image transfer ops */
207 for (row
= 0; row
< height
; row
++) {
208 GLfloat (*rgba
)[4] = (GLfloat (*)[4]) (convImage
+ row
* width
* 4);
210 /* GL_POST_CONVOLUTION_COLOR_TABLE lookup */
211 if (transferOps
& IMAGE_POST_CONVOLUTION_COLOR_TABLE_BIT
) {
212 _mesa_lookup_rgba(&ctx
->PostConvolutionColorTable
, width
, rgba
);
215 if (transferOps
& IMAGE_COLOR_MATRIX_BIT
) {
216 _mesa_transform_rgba(ctx
, width
, rgba
);
218 /* GL_POST_COLOR_MATRIX_COLOR_TABLE lookup */
219 if (transferOps
& IMAGE_POST_COLOR_MATRIX_COLOR_TABLE_BIT
) {
220 _mesa_lookup_rgba(&ctx
->PostColorMatrixColorTable
, width
, rgba
);
222 /* update histogram count */
223 if (transferOps
& IMAGE_HISTOGRAM_BIT
) {
224 _mesa_update_histogram(ctx
, width
, (CONST
GLfloat (*)[4]) rgba
);
227 if (transferOps
& IMAGE_MIN_MAX_BIT
) {
228 _mesa_update_minmax(ctx
, width
, (CONST
GLfloat (*)[4]) rgba
);
232 for (row
= 0; row
< height
; row
++) {
233 const GLfloat
*src
= convImage
+ row
* width
* 4;
236 /* clamp to [0,1] and convert float back to chan */
237 for (i
= 0; i
< width
; i
++) {
238 GLint r
= (GLint
) (src
[i
* 4 + RCOMP
] * CHAN_MAXF
);
239 GLint g
= (GLint
) (src
[i
* 4 + GCOMP
] * CHAN_MAXF
);
240 GLint b
= (GLint
) (src
[i
* 4 + BCOMP
] * CHAN_MAXF
);
241 GLint a
= (GLint
) (src
[i
* 4 + ACOMP
] * CHAN_MAXF
);
242 span
.array
->rgba
[i
][RCOMP
] = (GLchan
) CLAMP(r
, 0, CHAN_MAX
);
243 span
.array
->rgba
[i
][GCOMP
] = (GLchan
) CLAMP(g
, 0, CHAN_MAX
);
244 span
.array
->rgba
[i
][BCOMP
] = (GLchan
) CLAMP(b
, 0, CHAN_MAX
);
245 span
.array
->rgba
[i
][ACOMP
] = (GLchan
) CLAMP(a
, 0, CHAN_MAX
);
248 if (ctx
->Pixel
.PixelTextureEnabled
&& ctx
->Texture
._EnabledUnits
) {
250 _swrast_pixel_texture(ctx
, &span
);
253 /* write row to framebuffer */
256 if (quick_draw
&& dy
>= 0 && dy
< (GLint
) ctx
->DrawBuffer
->Height
) {
257 (*swrast
->Driver
.WriteRGBASpan
)( ctx
, width
, destx
, dy
,
258 (const GLchan (*)[4])span
.array
->rgba
, NULL
);
264 _mesa_write_zoomed_rgba_span(ctx
, &span
,
265 (CONST
GLchan (*)[4])span
.array
->rgba
,
272 _mesa_write_rgba_span(ctx
, &span
);
284 copy_rgba_pixels(GLcontext
*ctx
, GLint srcx
, GLint srcy
,
285 GLint width
, GLint height
, GLint destx
, GLint desty
)
287 SWcontext
*swrast
= SWRAST_CONTEXT(ctx
);
289 GLboolean quick_draw
;
290 GLint sy
, dy
, stepy
, j
;
291 GLboolean changeBuffer
;
292 const GLboolean zoom
= ctx
->Pixel
.ZoomX
!= 1.0F
|| ctx
->Pixel
.ZoomY
!= 1.0F
;
294 const GLuint transferOps
= ctx
->_ImageTransferState
;
297 INIT_SPAN(span
, GL_BITMAP
, 0, 0, SPAN_RGBA
);
299 if (ctx
->Pixel
.Convolution2DEnabled
|| ctx
->Pixel
.Separable2DEnabled
) {
300 copy_conv_rgba_pixels(ctx
, srcx
, srcy
, width
, height
, destx
, desty
);
304 /* Determine if copy should be done bottom-to-top or top-to-bottom */
306 /* top-down max-to-min */
307 sy
= srcy
+ height
- 1;
308 dy
= desty
+ height
- 1;
312 /* bottom-up min-to-max */
318 overlapping
= regions_overlap(srcx
, srcy
, destx
, desty
, width
, height
,
319 ctx
->Pixel
.ZoomX
, ctx
->Pixel
.ZoomY
);
322 _mesa_span_default_z(ctx
, &span
);
323 if (ctx
->Fog
.Enabled
)
324 _mesa_span_default_fog(ctx
, &span
);
326 if (SWRAST_CONTEXT(ctx
)->_RasterMask
== 0
329 && destx
+ width
<= (GLint
) ctx
->DrawBuffer
->Width
) {
330 quick_draw
= GL_TRUE
;
333 quick_draw
= GL_FALSE
;
336 /* If read and draw buffer are different we must do buffer switching */
337 changeBuffer
= ctx
->Pixel
.ReadBuffer
!= ctx
->Color
.DrawBuffer
338 || ctx
->DrawBuffer
!= ctx
->ReadBuffer
;
342 tmpImage
= (GLchan
*) MALLOC(width
* height
* sizeof(GLchan
) * 4);
344 _mesa_error( ctx
, GL_OUT_OF_MEMORY
, "glCopyPixels" );
349 _swrast_use_read_buffer(ctx
);
350 /* read the source image */
352 for (j
= 0; j
< height
; j
++, ssy
+= stepy
) {
353 _mesa_read_rgba_span( ctx
, ctx
->ReadBuffer
, width
, srcx
, ssy
,
360 _swrast_use_draw_buffer(ctx
);
361 changeBuffer
= GL_FALSE
;
365 tmpImage
= NULL
; /* silence compiler warnings */
369 for (j
= 0; j
< height
; j
++, sy
+= stepy
, dy
+= stepy
) {
370 /* Get source pixels */
372 /* get from buffered image */
373 MEMCPY(span
.array
->rgba
, p
, width
* sizeof(GLchan
) * 4);
377 /* get from framebuffer */
379 _swrast_use_read_buffer(ctx
);
380 _mesa_read_rgba_span( ctx
, ctx
->ReadBuffer
, width
, srcx
, sy
,
383 _swrast_use_draw_buffer(ctx
);
387 const GLfloat scale
= (1.0F
/ CHAN_MAXF
);
389 DEFMARRAY(GLfloat
, rgbaFloat
, MAX_WIDTH
, 4); /* mac 32k limitation */
390 CHECKARRAY(rgbaFloat
, return);
392 /* convert chan to float */
393 for (k
= 0; k
< width
; k
++) {
394 rgbaFloat
[k
][RCOMP
] = (GLfloat
) span
.array
->rgba
[k
][RCOMP
] * scale
;
395 rgbaFloat
[k
][GCOMP
] = (GLfloat
) span
.array
->rgba
[k
][GCOMP
] * scale
;
396 rgbaFloat
[k
][BCOMP
] = (GLfloat
) span
.array
->rgba
[k
][BCOMP
] * scale
;
397 rgbaFloat
[k
][ACOMP
] = (GLfloat
) span
.array
->rgba
[k
][ACOMP
] * scale
;
400 if (transferOps
& IMAGE_SCALE_BIAS_BIT
) {
401 _mesa_scale_and_bias_rgba(ctx
, width
, rgbaFloat
,
402 ctx
->Pixel
.RedScale
, ctx
->Pixel
.GreenScale
,
403 ctx
->Pixel
.BlueScale
, ctx
->Pixel
.AlphaScale
,
404 ctx
->Pixel
.RedBias
, ctx
->Pixel
.GreenBias
,
405 ctx
->Pixel
.BlueBias
, ctx
->Pixel
.AlphaBias
);
407 /* color map lookup */
408 if (transferOps
& IMAGE_MAP_COLOR_BIT
) {
409 _mesa_map_rgba(ctx
, width
, rgbaFloat
);
411 /* GL_COLOR_TABLE lookup */
412 if (transferOps
& IMAGE_COLOR_TABLE_BIT
) {
413 _mesa_lookup_rgba(&ctx
->ColorTable
, width
, rgbaFloat
);
416 if (transferOps
& IMAGE_CONVOLUTION_BIT
) {
417 abort(); /* should never get here; caught at top of function */
419 /* GL_POST_CONVOLUTION_RED/GREEN/BLUE/ALPHA_SCALE/BIAS */
420 if (transferOps
& IMAGE_POST_CONVOLUTION_SCALE_BIAS
) {
421 _mesa_scale_and_bias_rgba(ctx
, width
, rgbaFloat
,
422 ctx
->Pixel
.PostConvolutionScale
[RCOMP
],
423 ctx
->Pixel
.PostConvolutionScale
[GCOMP
],
424 ctx
->Pixel
.PostConvolutionScale
[BCOMP
],
425 ctx
->Pixel
.PostConvolutionScale
[ACOMP
],
426 ctx
->Pixel
.PostConvolutionBias
[RCOMP
],
427 ctx
->Pixel
.PostConvolutionBias
[GCOMP
],
428 ctx
->Pixel
.PostConvolutionBias
[BCOMP
],
429 ctx
->Pixel
.PostConvolutionBias
[ACOMP
]);
431 /* GL_POST_CONVOLUTION_COLOR_TABLE lookup */
432 if (transferOps
& IMAGE_POST_CONVOLUTION_COLOR_TABLE_BIT
) {
433 _mesa_lookup_rgba(&ctx
->PostConvolutionColorTable
, width
, rgbaFloat
);
436 if (transferOps
& IMAGE_COLOR_MATRIX_BIT
) {
437 _mesa_transform_rgba(ctx
, width
, rgbaFloat
);
439 /* GL_POST_COLOR_MATRIX_COLOR_TABLE lookup */
440 if (transferOps
& IMAGE_POST_COLOR_MATRIX_COLOR_TABLE_BIT
) {
441 _mesa_lookup_rgba(&ctx
->PostColorMatrixColorTable
, width
, rgbaFloat
);
443 /* update histogram count */
444 if (transferOps
& IMAGE_HISTOGRAM_BIT
) {
445 _mesa_update_histogram(ctx
, width
, (CONST
GLfloat (*)[4]) rgbaFloat
);
448 if (transferOps
& IMAGE_MIN_MAX_BIT
) {
449 _mesa_update_minmax(ctx
, width
, (CONST
GLfloat (*)[4]) rgbaFloat
);
451 /* clamp to [0,1] and convert float back to chan */
452 for (k
= 0; k
< width
; k
++) {
453 GLint r
= (GLint
) (rgbaFloat
[k
][RCOMP
] * CHAN_MAXF
);
454 GLint g
= (GLint
) (rgbaFloat
[k
][GCOMP
] * CHAN_MAXF
);
455 GLint b
= (GLint
) (rgbaFloat
[k
][BCOMP
] * CHAN_MAXF
);
456 GLint a
= (GLint
) (rgbaFloat
[k
][ACOMP
] * CHAN_MAXF
);
457 span
.array
->rgba
[k
][RCOMP
] = (GLchan
) CLAMP(r
, 0, CHAN_MAX
);
458 span
.array
->rgba
[k
][GCOMP
] = (GLchan
) CLAMP(g
, 0, CHAN_MAX
);
459 span
.array
->rgba
[k
][BCOMP
] = (GLchan
) CLAMP(b
, 0, CHAN_MAX
);
460 span
.array
->rgba
[k
][ACOMP
] = (GLchan
) CLAMP(a
, 0, CHAN_MAX
);
462 UNDEFARRAY(rgbaFloat
); /* mac 32k limitation */
465 if (ctx
->Pixel
.PixelTextureEnabled
&& ctx
->Texture
._EnabledUnits
) {
467 _swrast_pixel_texture(ctx
, &span
);
470 if (quick_draw
&& dy
>= 0 && dy
< (GLint
) ctx
->DrawBuffer
->Height
) {
471 (*swrast
->Driver
.WriteRGBASpan
)( ctx
, width
, destx
, dy
,
472 (const GLchan (*)[4])span
.array
->rgba
, NULL
);
478 _mesa_write_zoomed_rgba_span(ctx
, &span
,
479 (CONST
GLchan (*)[4]) span
.array
->rgba
,
486 _mesa_write_rgba_span(ctx
, &span
);
495 static void copy_ci_pixels( GLcontext
*ctx
,
496 GLint srcx
, GLint srcy
, GLint width
, GLint height
,
497 GLint destx
, GLint desty
)
502 GLboolean changeBuffer
;
503 const GLboolean zoom
= ctx
->Pixel
.ZoomX
!= 1.0F
|| ctx
->Pixel
.ZoomY
!= 1.0F
;
504 const GLboolean shift_or_offset
= ctx
->Pixel
.IndexShift
|| ctx
->Pixel
.IndexOffset
;
508 INIT_SPAN(span
, GL_BITMAP
, 0, 0, SPAN_INDEX
);
510 /* Determine if copy should be bottom-to-top or top-to-bottom */
512 /* top-down max-to-min */
513 sy
= srcy
+ height
- 1;
514 dy
= desty
+ height
- 1;
518 /* bottom-up min-to-max */
524 overlapping
= regions_overlap(srcx
, srcy
, destx
, desty
, width
, height
,
525 ctx
->Pixel
.ZoomX
, ctx
->Pixel
.ZoomY
);
528 _mesa_span_default_z(ctx
, &span
);
529 if (ctx
->Fog
.Enabled
)
530 _mesa_span_default_fog(ctx
, &span
);
532 /* If read and draw buffer are different we must do buffer switching */
533 changeBuffer
= ctx
->Pixel
.ReadBuffer
!= ctx
->Color
.DrawBuffer
534 || ctx
->DrawBuffer
!= ctx
->ReadBuffer
;
538 tmpImage
= (GLuint
*) MALLOC(width
* height
* sizeof(GLuint
));
540 _mesa_error( ctx
, GL_OUT_OF_MEMORY
, "glCopyPixels" );
545 _swrast_use_read_buffer(ctx
);
548 for (j
= 0; j
< height
; j
++, ssy
+= stepy
) {
549 _mesa_read_index_span( ctx
, ctx
->ReadBuffer
, width
, srcx
, ssy
, p
);
553 /* restore to draw buffer */
555 _swrast_use_draw_buffer(ctx
);
556 changeBuffer
= GL_FALSE
;
560 tmpImage
= NULL
; /* silence compiler warning */
564 for (j
= 0; j
< height
; j
++, sy
+= stepy
, dy
+= stepy
) {
566 MEMCPY(span
.array
->index
, p
, width
* sizeof(GLuint
));
571 _swrast_use_read_buffer(ctx
);
572 _mesa_read_index_span( ctx
, ctx
->ReadBuffer
, width
, srcx
, sy
,
575 _swrast_use_draw_buffer(ctx
);
578 if (shift_or_offset
) {
579 _mesa_shift_and_offset_ci( ctx
, width
, span
.array
->index
);
581 if (ctx
->Pixel
.MapColorFlag
) {
582 _mesa_map_ci( ctx
, width
, span
.array
->index
);
589 _mesa_write_zoomed_index_span(ctx
, &span
, desty
);
591 _mesa_write_index_span(ctx
, &span
);
603 static void copy_depth_pixels( GLcontext
*ctx
, GLint srcx
, GLint srcy
,
604 GLint width
, GLint height
,
605 GLint destx
, GLint desty
)
607 GLfloat depth
[MAX_WIDTH
];
608 GLfloat
*p
, *tmpImage
;
611 const GLboolean zoom
= ctx
->Pixel
.ZoomX
!= 1.0F
|| ctx
->Pixel
.ZoomY
!= 1.0F
;
615 INIT_SPAN(span
, GL_BITMAP
, 0, 0, SPAN_Z
);
617 if (!ctx
->Visual
.depthBits
) {
618 _mesa_error( ctx
, GL_INVALID_OPERATION
, "glCopyPixels" );
622 /* Determine if copy should be bottom-to-top or top-to-bottom */
624 /* top-down max-to-min */
625 sy
= srcy
+ height
- 1;
626 dy
= desty
+ height
- 1;
630 /* bottom-up min-to-max */
636 overlapping
= regions_overlap(srcx
, srcy
, destx
, desty
, width
, height
,
637 ctx
->Pixel
.ZoomX
, ctx
->Pixel
.ZoomY
);
639 _mesa_span_default_color(ctx
, &span
);
640 if (ctx
->Fog
.Enabled
)
641 _mesa_span_default_fog(ctx
, &span
);
645 tmpImage
= (GLfloat
*) MALLOC(width
* height
* sizeof(GLfloat
));
647 _mesa_error( ctx
, GL_OUT_OF_MEMORY
, "glCopyPixels" );
651 for (j
= 0; j
< height
; j
++, ssy
+= stepy
) {
652 _mesa_read_depth_span_float(ctx
, width
, srcx
, ssy
, p
);
658 tmpImage
= NULL
; /* silence compiler warning */
662 for (j
= 0; j
< height
; j
++, sy
+= stepy
, dy
+= stepy
) {
664 MEMCPY(depth
, p
, width
* sizeof(GLfloat
));
668 _mesa_read_depth_span_float(ctx
, width
, srcx
, sy
, depth
);
671 for (i
= 0; i
< width
; i
++) {
672 GLfloat d
= depth
[i
] * ctx
->Pixel
.DepthScale
+ ctx
->Pixel
.DepthBias
;
673 span
.array
->z
[i
] = (GLdepth
) (CLAMP(d
, 0.0F
, 1.0F
) * ctx
->DepthMax
);
679 if (ctx
->Visual
.rgbMode
) {
681 _mesa_write_zoomed_rgba_span( ctx
, &span
,
682 (const GLchan (*)[4])span
.array
->rgba
,
685 _mesa_write_rgba_span(ctx
, &span
);
689 _mesa_write_zoomed_index_span( ctx
, &span
, desty
);
691 _mesa_write_index_span(ctx
, &span
);
701 static void copy_stencil_pixels( GLcontext
*ctx
, GLint srcx
, GLint srcy
,
702 GLint width
, GLint height
,
703 GLint destx
, GLint desty
)
707 GLstencil
*p
, *tmpImage
;
708 const GLboolean zoom
= ctx
->Pixel
.ZoomX
!= 1.0F
|| ctx
->Pixel
.ZoomY
!= 1.0F
;
709 const GLboolean shift_or_offset
= ctx
->Pixel
.IndexShift
|| ctx
->Pixel
.IndexOffset
;
712 if (!ctx
->Visual
.stencilBits
) {
713 _mesa_error( ctx
, GL_INVALID_OPERATION
, "glCopyPixels" );
717 /* Determine if copy should be bottom-to-top or top-to-bottom */
719 /* top-down max-to-min */
720 sy
= srcy
+ height
- 1;
721 dy
= desty
+ height
- 1;
725 /* bottom-up min-to-max */
731 overlapping
= regions_overlap(srcx
, srcy
, destx
, desty
, width
, height
,
732 ctx
->Pixel
.ZoomX
, ctx
->Pixel
.ZoomY
);
736 tmpImage
= (GLstencil
*) MALLOC(width
* height
* sizeof(GLstencil
));
738 _mesa_error( ctx
, GL_OUT_OF_MEMORY
, "glCopyPixels" );
742 for (j
= 0; j
< height
; j
++, ssy
+= stepy
) {
743 _mesa_read_stencil_span( ctx
, width
, srcx
, ssy
, p
);
749 tmpImage
= NULL
; /* silence compiler warning */
753 for (j
= 0; j
< height
; j
++, sy
+= stepy
, dy
+= stepy
) {
754 GLstencil stencil
[MAX_WIDTH
];
757 MEMCPY(stencil
, p
, width
* sizeof(GLstencil
));
761 _mesa_read_stencil_span( ctx
, width
, srcx
, sy
, stencil
);
764 if (shift_or_offset
) {
765 _mesa_shift_and_offset_stencil( ctx
, width
, stencil
);
767 if (ctx
->Pixel
.MapStencilFlag
) {
768 _mesa_map_stencil( ctx
, width
, stencil
);
772 _mesa_write_zoomed_stencil_span( ctx
, width
, destx
, dy
, stencil
, desty
);
775 _mesa_write_stencil_span( ctx
, width
, destx
, dy
, stencil
);
787 _swrast_CopyPixels( GLcontext
*ctx
,
788 GLint srcx
, GLint srcy
, GLsizei width
, GLsizei height
,
789 GLint destx
, GLint desty
,
792 SWcontext
*swrast
= SWRAST_CONTEXT(ctx
);
793 RENDER_START(swrast
,ctx
);
795 if (swrast
->NewState
)
796 _swrast_validate_derived( ctx
);
798 if (type
== GL_COLOR
&& ctx
->Visual
.rgbMode
) {
799 copy_rgba_pixels( ctx
, srcx
, srcy
, width
, height
, destx
, desty
);
801 else if (type
== GL_COLOR
&& !ctx
->Visual
.rgbMode
) {
802 copy_ci_pixels( ctx
, srcx
, srcy
, width
, height
, destx
, desty
);
804 else if (type
== GL_DEPTH
) {
805 copy_depth_pixels( ctx
, srcx
, srcy
, width
, height
, destx
, desty
);
807 else if (type
== GL_STENCIL
) {
808 copy_stencil_pixels( ctx
, srcx
, srcy
, width
, height
, destx
, desty
);
811 _mesa_error( ctx
, GL_INVALID_ENUM
, "glCopyPixels" );
814 RENDER_FINISH(swrast
,ctx
);