1 /* $Id: s_copypix.c,v 1.42 2002/10/30 20:16:43 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 _mesa_problem(ctx
, "Convolution should not be enabled in copy_rgba_pixels()");
420 /* GL_POST_CONVOLUTION_RED/GREEN/BLUE/ALPHA_SCALE/BIAS */
421 if (transferOps
& IMAGE_POST_CONVOLUTION_SCALE_BIAS
) {
422 _mesa_scale_and_bias_rgba(ctx
, width
, rgbaFloat
,
423 ctx
->Pixel
.PostConvolutionScale
[RCOMP
],
424 ctx
->Pixel
.PostConvolutionScale
[GCOMP
],
425 ctx
->Pixel
.PostConvolutionScale
[BCOMP
],
426 ctx
->Pixel
.PostConvolutionScale
[ACOMP
],
427 ctx
->Pixel
.PostConvolutionBias
[RCOMP
],
428 ctx
->Pixel
.PostConvolutionBias
[GCOMP
],
429 ctx
->Pixel
.PostConvolutionBias
[BCOMP
],
430 ctx
->Pixel
.PostConvolutionBias
[ACOMP
]);
432 /* GL_POST_CONVOLUTION_COLOR_TABLE lookup */
433 if (transferOps
& IMAGE_POST_CONVOLUTION_COLOR_TABLE_BIT
) {
434 _mesa_lookup_rgba(&ctx
->PostConvolutionColorTable
, width
, rgbaFloat
);
437 if (transferOps
& IMAGE_COLOR_MATRIX_BIT
) {
438 _mesa_transform_rgba(ctx
, width
, rgbaFloat
);
440 /* GL_POST_COLOR_MATRIX_COLOR_TABLE lookup */
441 if (transferOps
& IMAGE_POST_COLOR_MATRIX_COLOR_TABLE_BIT
) {
442 _mesa_lookup_rgba(&ctx
->PostColorMatrixColorTable
, width
, rgbaFloat
);
444 /* update histogram count */
445 if (transferOps
& IMAGE_HISTOGRAM_BIT
) {
446 _mesa_update_histogram(ctx
, width
, (CONST
GLfloat (*)[4]) rgbaFloat
);
449 if (transferOps
& IMAGE_MIN_MAX_BIT
) {
450 _mesa_update_minmax(ctx
, width
, (CONST
GLfloat (*)[4]) rgbaFloat
);
452 /* clamp to [0,1] and convert float back to chan */
453 for (k
= 0; k
< width
; k
++) {
454 GLint r
= (GLint
) (rgbaFloat
[k
][RCOMP
] * CHAN_MAXF
);
455 GLint g
= (GLint
) (rgbaFloat
[k
][GCOMP
] * CHAN_MAXF
);
456 GLint b
= (GLint
) (rgbaFloat
[k
][BCOMP
] * CHAN_MAXF
);
457 GLint a
= (GLint
) (rgbaFloat
[k
][ACOMP
] * CHAN_MAXF
);
458 span
.array
->rgba
[k
][RCOMP
] = (GLchan
) CLAMP(r
, 0, CHAN_MAX
);
459 span
.array
->rgba
[k
][GCOMP
] = (GLchan
) CLAMP(g
, 0, CHAN_MAX
);
460 span
.array
->rgba
[k
][BCOMP
] = (GLchan
) CLAMP(b
, 0, CHAN_MAX
);
461 span
.array
->rgba
[k
][ACOMP
] = (GLchan
) CLAMP(a
, 0, CHAN_MAX
);
463 UNDEFARRAY(rgbaFloat
); /* mac 32k limitation */
466 if (ctx
->Pixel
.PixelTextureEnabled
&& ctx
->Texture
._EnabledUnits
) {
468 _swrast_pixel_texture(ctx
, &span
);
471 if (quick_draw
&& dy
>= 0 && dy
< (GLint
) ctx
->DrawBuffer
->Height
) {
472 (*swrast
->Driver
.WriteRGBASpan
)( ctx
, width
, destx
, dy
,
473 (const GLchan (*)[4])span
.array
->rgba
, NULL
);
479 _mesa_write_zoomed_rgba_span(ctx
, &span
,
480 (CONST
GLchan (*)[4]) span
.array
->rgba
,
487 _mesa_write_rgba_span(ctx
, &span
);
496 static void copy_ci_pixels( GLcontext
*ctx
,
497 GLint srcx
, GLint srcy
, GLint width
, GLint height
,
498 GLint destx
, GLint desty
)
503 GLboolean changeBuffer
;
504 const GLboolean zoom
= ctx
->Pixel
.ZoomX
!= 1.0F
|| ctx
->Pixel
.ZoomY
!= 1.0F
;
505 const GLboolean shift_or_offset
= ctx
->Pixel
.IndexShift
|| ctx
->Pixel
.IndexOffset
;
509 INIT_SPAN(span
, GL_BITMAP
, 0, 0, SPAN_INDEX
);
511 /* Determine if copy should be bottom-to-top or top-to-bottom */
513 /* top-down max-to-min */
514 sy
= srcy
+ height
- 1;
515 dy
= desty
+ height
- 1;
519 /* bottom-up min-to-max */
525 overlapping
= regions_overlap(srcx
, srcy
, destx
, desty
, width
, height
,
526 ctx
->Pixel
.ZoomX
, ctx
->Pixel
.ZoomY
);
529 _mesa_span_default_z(ctx
, &span
);
530 if (ctx
->Fog
.Enabled
)
531 _mesa_span_default_fog(ctx
, &span
);
533 /* If read and draw buffer are different we must do buffer switching */
534 changeBuffer
= ctx
->Pixel
.ReadBuffer
!= ctx
->Color
.DrawBuffer
535 || ctx
->DrawBuffer
!= ctx
->ReadBuffer
;
539 tmpImage
= (GLuint
*) MALLOC(width
* height
* sizeof(GLuint
));
541 _mesa_error( ctx
, GL_OUT_OF_MEMORY
, "glCopyPixels" );
546 _swrast_use_read_buffer(ctx
);
549 for (j
= 0; j
< height
; j
++, ssy
+= stepy
) {
550 _mesa_read_index_span( ctx
, ctx
->ReadBuffer
, width
, srcx
, ssy
, p
);
554 /* restore to draw buffer */
556 _swrast_use_draw_buffer(ctx
);
557 changeBuffer
= GL_FALSE
;
561 tmpImage
= NULL
; /* silence compiler warning */
565 for (j
= 0; j
< height
; j
++, sy
+= stepy
, dy
+= stepy
) {
567 MEMCPY(span
.array
->index
, p
, width
* sizeof(GLuint
));
572 _swrast_use_read_buffer(ctx
);
573 _mesa_read_index_span( ctx
, ctx
->ReadBuffer
, width
, srcx
, sy
,
576 _swrast_use_draw_buffer(ctx
);
579 if (shift_or_offset
) {
580 _mesa_shift_and_offset_ci( ctx
, width
, span
.array
->index
);
582 if (ctx
->Pixel
.MapColorFlag
) {
583 _mesa_map_ci( ctx
, width
, span
.array
->index
);
590 _mesa_write_zoomed_index_span(ctx
, &span
, desty
);
592 _mesa_write_index_span(ctx
, &span
);
604 static void copy_depth_pixels( GLcontext
*ctx
, GLint srcx
, GLint srcy
,
605 GLint width
, GLint height
,
606 GLint destx
, GLint desty
)
608 GLfloat depth
[MAX_WIDTH
];
609 GLfloat
*p
, *tmpImage
;
612 const GLboolean zoom
= ctx
->Pixel
.ZoomX
!= 1.0F
|| ctx
->Pixel
.ZoomY
!= 1.0F
;
616 INIT_SPAN(span
, GL_BITMAP
, 0, 0, SPAN_Z
);
618 if (!ctx
->Visual
.depthBits
) {
619 _mesa_error( ctx
, GL_INVALID_OPERATION
, "glCopyPixels" );
623 /* Determine if copy should be bottom-to-top or top-to-bottom */
625 /* top-down max-to-min */
626 sy
= srcy
+ height
- 1;
627 dy
= desty
+ height
- 1;
631 /* bottom-up min-to-max */
637 overlapping
= regions_overlap(srcx
, srcy
, destx
, desty
, width
, height
,
638 ctx
->Pixel
.ZoomX
, ctx
->Pixel
.ZoomY
);
640 _mesa_span_default_color(ctx
, &span
);
641 if (ctx
->Fog
.Enabled
)
642 _mesa_span_default_fog(ctx
, &span
);
646 tmpImage
= (GLfloat
*) MALLOC(width
* height
* sizeof(GLfloat
));
648 _mesa_error( ctx
, GL_OUT_OF_MEMORY
, "glCopyPixels" );
652 for (j
= 0; j
< height
; j
++, ssy
+= stepy
) {
653 _mesa_read_depth_span_float(ctx
, width
, srcx
, ssy
, p
);
659 tmpImage
= NULL
; /* silence compiler warning */
663 for (j
= 0; j
< height
; j
++, sy
+= stepy
, dy
+= stepy
) {
665 MEMCPY(depth
, p
, width
* sizeof(GLfloat
));
669 _mesa_read_depth_span_float(ctx
, width
, srcx
, sy
, depth
);
672 for (i
= 0; i
< width
; i
++) {
673 GLfloat d
= depth
[i
] * ctx
->Pixel
.DepthScale
+ ctx
->Pixel
.DepthBias
;
674 span
.array
->z
[i
] = (GLdepth
) (CLAMP(d
, 0.0F
, 1.0F
) * ctx
->DepthMax
);
680 if (ctx
->Visual
.rgbMode
) {
682 _mesa_write_zoomed_rgba_span( ctx
, &span
,
683 (const GLchan (*)[4])span
.array
->rgba
,
686 _mesa_write_rgba_span(ctx
, &span
);
690 _mesa_write_zoomed_index_span( ctx
, &span
, desty
);
692 _mesa_write_index_span(ctx
, &span
);
702 static void copy_stencil_pixels( GLcontext
*ctx
, GLint srcx
, GLint srcy
,
703 GLint width
, GLint height
,
704 GLint destx
, GLint desty
)
708 GLstencil
*p
, *tmpImage
;
709 const GLboolean zoom
= ctx
->Pixel
.ZoomX
!= 1.0F
|| ctx
->Pixel
.ZoomY
!= 1.0F
;
710 const GLboolean shift_or_offset
= ctx
->Pixel
.IndexShift
|| ctx
->Pixel
.IndexOffset
;
713 if (!ctx
->Visual
.stencilBits
) {
714 _mesa_error( ctx
, GL_INVALID_OPERATION
, "glCopyPixels" );
718 /* Determine if copy should be bottom-to-top or top-to-bottom */
720 /* top-down max-to-min */
721 sy
= srcy
+ height
- 1;
722 dy
= desty
+ height
- 1;
726 /* bottom-up min-to-max */
732 overlapping
= regions_overlap(srcx
, srcy
, destx
, desty
, width
, height
,
733 ctx
->Pixel
.ZoomX
, ctx
->Pixel
.ZoomY
);
737 tmpImage
= (GLstencil
*) MALLOC(width
* height
* sizeof(GLstencil
));
739 _mesa_error( ctx
, GL_OUT_OF_MEMORY
, "glCopyPixels" );
743 for (j
= 0; j
< height
; j
++, ssy
+= stepy
) {
744 _mesa_read_stencil_span( ctx
, width
, srcx
, ssy
, p
);
750 tmpImage
= NULL
; /* silence compiler warning */
754 for (j
= 0; j
< height
; j
++, sy
+= stepy
, dy
+= stepy
) {
755 GLstencil stencil
[MAX_WIDTH
];
758 MEMCPY(stencil
, p
, width
* sizeof(GLstencil
));
762 _mesa_read_stencil_span( ctx
, width
, srcx
, sy
, stencil
);
765 if (shift_or_offset
) {
766 _mesa_shift_and_offset_stencil( ctx
, width
, stencil
);
768 if (ctx
->Pixel
.MapStencilFlag
) {
769 _mesa_map_stencil( ctx
, width
, stencil
);
773 _mesa_write_zoomed_stencil_span( ctx
, width
, destx
, dy
, stencil
, desty
);
776 _mesa_write_stencil_span( ctx
, width
, destx
, dy
, stencil
);
788 _swrast_CopyPixels( GLcontext
*ctx
,
789 GLint srcx
, GLint srcy
, GLsizei width
, GLsizei height
,
790 GLint destx
, GLint desty
,
793 SWcontext
*swrast
= SWRAST_CONTEXT(ctx
);
794 RENDER_START(swrast
,ctx
);
796 if (swrast
->NewState
)
797 _swrast_validate_derived( ctx
);
799 if (type
== GL_COLOR
&& ctx
->Visual
.rgbMode
) {
800 copy_rgba_pixels( ctx
, srcx
, srcy
, width
, height
, destx
, desty
);
802 else if (type
== GL_COLOR
&& !ctx
->Visual
.rgbMode
) {
803 copy_ci_pixels( ctx
, srcx
, srcy
, width
, height
, destx
, desty
);
805 else if (type
== GL_DEPTH
) {
806 copy_depth_pixels( ctx
, srcx
, srcy
, width
, height
, destx
, desty
);
808 else if (type
== GL_STENCIL
) {
809 copy_stencil_pixels( ctx
, srcx
, srcy
, width
, height
, destx
, desty
);
812 _mesa_error( ctx
, GL_INVALID_ENUM
, "glCopyPixels" );
815 RENDER_FINISH(swrast
,ctx
);