1 /* $Id: s_copypix.c,v 1.43 2002/12/05 04:46:54 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.
35 #include "s_context.h"
37 #include "s_histogram.h"
38 #include "s_pixeltex.h"
40 #include "s_stencil.h"
41 #include "s_texture.h"
47 * Determine if there's overlap in an image copy.
48 * This test also compensates for the fact that copies are done from
49 * bottom to top and overlaps can sometimes be handled correctly
50 * without making a temporary image copy.
53 regions_overlap(GLint srcx
, GLint srcy
,
54 GLint dstx
, GLint dsty
,
55 GLint width
, GLint height
,
56 GLfloat zoomX
, GLfloat zoomY
)
58 if (zoomX
== 1.0 && zoomY
== 1.0) {
60 if (srcx
>= dstx
+ width
|| (srcx
+ width
<= dstx
)) {
63 else if (srcy
< dsty
) { /* this is OK */
66 else if (srcy
> dsty
+ height
) {
74 /* add one pixel of slop when zooming, just to be safe */
75 if ((srcx
> dstx
+ (width
* zoomX
) + 1) || (srcx
+ width
+ 1 < dstx
)) {
78 else if ((srcy
< dsty
) && (srcy
+ height
< dsty
+ (height
* zoomY
))) {
81 else if ((srcy
> dsty
) && (srcy
+ height
> dsty
+ (height
* zoomY
))) {
93 * RGBA copypixels with convolution.
96 copy_conv_rgba_pixels(GLcontext
*ctx
, GLint srcx
, GLint srcy
,
97 GLint width
, GLint height
, GLint destx
, GLint desty
)
99 SWcontext
*swrast
= SWRAST_CONTEXT(ctx
);
100 GLboolean quick_draw
;
102 GLboolean changeBuffer
;
103 const GLboolean zoom
= ctx
->Pixel
.ZoomX
!= 1.0F
|| ctx
->Pixel
.ZoomY
!= 1.0F
;
104 const GLuint transferOps
= ctx
->_ImageTransferState
;
105 GLfloat
*dest
, *tmpImage
, *convImage
;
108 INIT_SPAN(span
, GL_BITMAP
, 0, 0, SPAN_RGBA
);
111 _mesa_span_default_z(ctx
, &span
);
112 if (ctx
->Fog
.Enabled
)
113 _mesa_span_default_fog(ctx
, &span
);
116 if (SWRAST_CONTEXT(ctx
)->_RasterMask
== 0
119 && destx
+ width
<= (GLint
) ctx
->DrawBuffer
->Width
) {
120 quick_draw
= GL_TRUE
;
123 quick_draw
= GL_FALSE
;
126 /* If read and draw buffer are different we must do buffer switching */
127 changeBuffer
= ctx
->Pixel
.ReadBuffer
!= ctx
->Color
.DrawBuffer
128 || ctx
->DrawBuffer
!= ctx
->ReadBuffer
;
131 /* allocate space for GLfloat image */
132 tmpImage
= (GLfloat
*) MALLOC(width
* height
* 4 * sizeof(GLfloat
));
134 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glCopyPixels");
137 convImage
= (GLfloat
*) MALLOC(width
* height
* 4 * sizeof(GLfloat
));
140 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glCopyPixels");
147 /* choose the read buffer */
148 _swrast_use_read_buffer(ctx
);
151 /* read source image */
153 for (row
= 0; row
< height
; row
++) {
154 GLchan rgba
[MAX_WIDTH
][4];
156 _mesa_read_rgba_span(ctx
, ctx
->ReadBuffer
, width
, srcx
, srcy
+ row
, rgba
);
157 /* convert GLchan to GLfloat */
158 for (i
= 0; i
< width
; i
++) {
159 *dest
++ = (GLfloat
) rgba
[i
][RCOMP
] * (1.0F
/ CHAN_MAXF
);
160 *dest
++ = (GLfloat
) rgba
[i
][GCOMP
] * (1.0F
/ CHAN_MAXF
);
161 *dest
++ = (GLfloat
) rgba
[i
][BCOMP
] * (1.0F
/ CHAN_MAXF
);
162 *dest
++ = (GLfloat
) rgba
[i
][ACOMP
] * (1.0F
/ CHAN_MAXF
);
167 /* restore default src/dst buffer */
168 _swrast_use_draw_buffer(ctx
);
171 /* do image transfer ops up until convolution */
172 for (row
= 0; row
< height
; row
++) {
173 GLfloat (*rgba
)[4] = (GLfloat (*)[4]) (tmpImage
+ row
* width
* 4);
176 if (transferOps
& IMAGE_SCALE_BIAS_BIT
) {
177 _mesa_scale_and_bias_rgba(ctx
, width
, rgba
,
178 ctx
->Pixel
.RedScale
, ctx
->Pixel
.GreenScale
,
179 ctx
->Pixel
.BlueScale
, ctx
->Pixel
.AlphaScale
,
180 ctx
->Pixel
.RedBias
, ctx
->Pixel
.GreenBias
,
181 ctx
->Pixel
.BlueBias
, ctx
->Pixel
.AlphaBias
);
183 /* color map lookup */
184 if (transferOps
& IMAGE_MAP_COLOR_BIT
) {
185 _mesa_map_rgba(ctx
, width
, rgba
);
187 /* GL_COLOR_TABLE lookup */
188 if (transferOps
& IMAGE_COLOR_TABLE_BIT
) {
189 _mesa_lookup_rgba(&ctx
->ColorTable
, width
, rgba
);
194 if (ctx
->Pixel
.Convolution2DEnabled
) {
195 _mesa_convolve_2d_image(ctx
, &width
, &height
, tmpImage
, convImage
);
198 ASSERT(ctx
->Pixel
.Separable2DEnabled
);
199 _mesa_convolve_sep_image(ctx
, &width
, &height
, tmpImage
, convImage
);
203 /* do remaining image transfer ops */
204 for (row
= 0; row
< height
; row
++) {
205 GLfloat (*rgba
)[4] = (GLfloat (*)[4]) (convImage
+ row
* width
* 4);
207 /* GL_POST_CONVOLUTION_COLOR_TABLE lookup */
208 if (transferOps
& IMAGE_POST_CONVOLUTION_COLOR_TABLE_BIT
) {
209 _mesa_lookup_rgba(&ctx
->PostConvolutionColorTable
, width
, rgba
);
212 if (transferOps
& IMAGE_COLOR_MATRIX_BIT
) {
213 _mesa_transform_rgba(ctx
, width
, rgba
);
215 /* GL_POST_COLOR_MATRIX_COLOR_TABLE lookup */
216 if (transferOps
& IMAGE_POST_COLOR_MATRIX_COLOR_TABLE_BIT
) {
217 _mesa_lookup_rgba(&ctx
->PostColorMatrixColorTable
, width
, rgba
);
219 /* update histogram count */
220 if (transferOps
& IMAGE_HISTOGRAM_BIT
) {
221 _mesa_update_histogram(ctx
, width
, (CONST
GLfloat (*)[4]) rgba
);
224 if (transferOps
& IMAGE_MIN_MAX_BIT
) {
225 _mesa_update_minmax(ctx
, width
, (CONST
GLfloat (*)[4]) rgba
);
229 for (row
= 0; row
< height
; row
++) {
230 const GLfloat
*src
= convImage
+ row
* width
* 4;
233 /* clamp to [0,1] and convert float back to chan */
234 for (i
= 0; i
< width
; i
++) {
235 GLint r
= (GLint
) (src
[i
* 4 + RCOMP
] * CHAN_MAXF
);
236 GLint g
= (GLint
) (src
[i
* 4 + GCOMP
] * CHAN_MAXF
);
237 GLint b
= (GLint
) (src
[i
* 4 + BCOMP
] * CHAN_MAXF
);
238 GLint a
= (GLint
) (src
[i
* 4 + ACOMP
] * CHAN_MAXF
);
239 span
.array
->rgba
[i
][RCOMP
] = (GLchan
) CLAMP(r
, 0, CHAN_MAX
);
240 span
.array
->rgba
[i
][GCOMP
] = (GLchan
) CLAMP(g
, 0, CHAN_MAX
);
241 span
.array
->rgba
[i
][BCOMP
] = (GLchan
) CLAMP(b
, 0, CHAN_MAX
);
242 span
.array
->rgba
[i
][ACOMP
] = (GLchan
) CLAMP(a
, 0, CHAN_MAX
);
245 if (ctx
->Pixel
.PixelTextureEnabled
&& ctx
->Texture
._EnabledUnits
) {
247 _swrast_pixel_texture(ctx
, &span
);
250 /* write row to framebuffer */
253 if (quick_draw
&& dy
>= 0 && dy
< (GLint
) ctx
->DrawBuffer
->Height
) {
254 (*swrast
->Driver
.WriteRGBASpan
)( ctx
, width
, destx
, dy
,
255 (const GLchan (*)[4])span
.array
->rgba
, NULL
);
261 _mesa_write_zoomed_rgba_span(ctx
, &span
,
262 (CONST
GLchan (*)[4])span
.array
->rgba
,
269 _mesa_write_rgba_span(ctx
, &span
);
281 copy_rgba_pixels(GLcontext
*ctx
, GLint srcx
, GLint srcy
,
282 GLint width
, GLint height
, GLint destx
, GLint desty
)
284 SWcontext
*swrast
= SWRAST_CONTEXT(ctx
);
286 GLboolean quick_draw
;
287 GLint sy
, dy
, stepy
, j
;
288 GLboolean changeBuffer
;
289 const GLboolean zoom
= ctx
->Pixel
.ZoomX
!= 1.0F
|| ctx
->Pixel
.ZoomY
!= 1.0F
;
291 const GLuint transferOps
= ctx
->_ImageTransferState
;
294 INIT_SPAN(span
, GL_BITMAP
, 0, 0, SPAN_RGBA
);
296 if (ctx
->Pixel
.Convolution2DEnabled
|| ctx
->Pixel
.Separable2DEnabled
) {
297 copy_conv_rgba_pixels(ctx
, srcx
, srcy
, width
, height
, destx
, desty
);
301 /* Determine if copy should be done bottom-to-top or top-to-bottom */
303 /* top-down max-to-min */
304 sy
= srcy
+ height
- 1;
305 dy
= desty
+ height
- 1;
309 /* bottom-up min-to-max */
315 overlapping
= regions_overlap(srcx
, srcy
, destx
, desty
, width
, height
,
316 ctx
->Pixel
.ZoomX
, ctx
->Pixel
.ZoomY
);
319 _mesa_span_default_z(ctx
, &span
);
320 if (ctx
->Fog
.Enabled
)
321 _mesa_span_default_fog(ctx
, &span
);
323 if (SWRAST_CONTEXT(ctx
)->_RasterMask
== 0
326 && destx
+ width
<= (GLint
) ctx
->DrawBuffer
->Width
) {
327 quick_draw
= GL_TRUE
;
330 quick_draw
= GL_FALSE
;
333 /* If read and draw buffer are different we must do buffer switching */
334 changeBuffer
= ctx
->Pixel
.ReadBuffer
!= ctx
->Color
.DrawBuffer
335 || ctx
->DrawBuffer
!= ctx
->ReadBuffer
;
339 tmpImage
= (GLchan
*) MALLOC(width
* height
* sizeof(GLchan
) * 4);
341 _mesa_error( ctx
, GL_OUT_OF_MEMORY
, "glCopyPixels" );
346 _swrast_use_read_buffer(ctx
);
347 /* read the source image */
349 for (j
= 0; j
< height
; j
++, ssy
+= stepy
) {
350 _mesa_read_rgba_span( ctx
, ctx
->ReadBuffer
, width
, srcx
, ssy
,
357 _swrast_use_draw_buffer(ctx
);
358 changeBuffer
= GL_FALSE
;
362 tmpImage
= NULL
; /* silence compiler warnings */
366 for (j
= 0; j
< height
; j
++, sy
+= stepy
, dy
+= stepy
) {
367 /* Get source pixels */
369 /* get from buffered image */
370 ASSERT(width
< MAX_WIDTH
);
371 MEMCPY(span
.array
->rgba
, p
, width
* sizeof(GLchan
) * 4);
375 /* get from framebuffer */
377 _swrast_use_read_buffer(ctx
);
378 ASSERT(width
< MAX_WIDTH
);
379 _mesa_read_rgba_span( ctx
, ctx
->ReadBuffer
, width
, srcx
, sy
,
382 _swrast_use_draw_buffer(ctx
);
386 const GLfloat scale
= (1.0F
/ CHAN_MAXF
);
388 DEFMARRAY(GLfloat
, rgbaFloat
, MAX_WIDTH
, 4); /* mac 32k limitation */
389 CHECKARRAY(rgbaFloat
, return);
391 /* convert chan to float */
392 for (k
= 0; k
< width
; k
++) {
393 rgbaFloat
[k
][RCOMP
] = (GLfloat
) span
.array
->rgba
[k
][RCOMP
] * scale
;
394 rgbaFloat
[k
][GCOMP
] = (GLfloat
) span
.array
->rgba
[k
][GCOMP
] * scale
;
395 rgbaFloat
[k
][BCOMP
] = (GLfloat
) span
.array
->rgba
[k
][BCOMP
] * scale
;
396 rgbaFloat
[k
][ACOMP
] = (GLfloat
) span
.array
->rgba
[k
][ACOMP
] * scale
;
399 if (transferOps
& IMAGE_SCALE_BIAS_BIT
) {
400 _mesa_scale_and_bias_rgba(ctx
, width
, rgbaFloat
,
401 ctx
->Pixel
.RedScale
, ctx
->Pixel
.GreenScale
,
402 ctx
->Pixel
.BlueScale
, ctx
->Pixel
.AlphaScale
,
403 ctx
->Pixel
.RedBias
, ctx
->Pixel
.GreenBias
,
404 ctx
->Pixel
.BlueBias
, ctx
->Pixel
.AlphaBias
);
406 /* color map lookup */
407 if (transferOps
& IMAGE_MAP_COLOR_BIT
) {
408 _mesa_map_rgba(ctx
, width
, rgbaFloat
);
410 /* GL_COLOR_TABLE lookup */
411 if (transferOps
& IMAGE_COLOR_TABLE_BIT
) {
412 _mesa_lookup_rgba(&ctx
->ColorTable
, width
, rgbaFloat
);
415 if (transferOps
& IMAGE_CONVOLUTION_BIT
) {
416 _mesa_problem(ctx
, "Convolution should not be enabled in copy_rgba_pixels()");
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 /* Write color 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
);
497 copy_ci_pixels( GLcontext
*ctx
, GLint srcx
, GLint srcy
,
498 GLint width
, GLint height
,
499 GLint destx
, GLint desty
)
504 GLboolean changeBuffer
;
505 const GLboolean zoom
= ctx
->Pixel
.ZoomX
!= 1.0F
|| ctx
->Pixel
.ZoomY
!= 1.0F
;
506 const GLboolean shift_or_offset
= ctx
->Pixel
.IndexShift
|| ctx
->Pixel
.IndexOffset
;
510 INIT_SPAN(span
, GL_BITMAP
, 0, 0, SPAN_INDEX
);
512 /* Determine if copy should be bottom-to-top or top-to-bottom */
514 /* top-down max-to-min */
515 sy
= srcy
+ height
- 1;
516 dy
= desty
+ height
- 1;
520 /* bottom-up min-to-max */
526 overlapping
= regions_overlap(srcx
, srcy
, destx
, desty
, width
, height
,
527 ctx
->Pixel
.ZoomX
, ctx
->Pixel
.ZoomY
);
530 _mesa_span_default_z(ctx
, &span
);
531 if (ctx
->Fog
.Enabled
)
532 _mesa_span_default_fog(ctx
, &span
);
534 /* If read and draw buffer are different we must do buffer switching */
535 changeBuffer
= ctx
->Pixel
.ReadBuffer
!= ctx
->Color
.DrawBuffer
536 || ctx
->DrawBuffer
!= ctx
->ReadBuffer
;
540 tmpImage
= (GLuint
*) MALLOC(width
* height
* sizeof(GLuint
));
542 _mesa_error( ctx
, GL_OUT_OF_MEMORY
, "glCopyPixels" );
547 _swrast_use_read_buffer(ctx
);
550 for (j
= 0; j
< height
; j
++, ssy
+= stepy
) {
551 _mesa_read_index_span( ctx
, ctx
->ReadBuffer
, width
, srcx
, ssy
, p
);
555 /* restore to draw buffer */
557 _swrast_use_draw_buffer(ctx
);
558 changeBuffer
= GL_FALSE
;
562 tmpImage
= NULL
; /* silence compiler warning */
566 for (j
= 0; j
< height
; j
++, sy
+= stepy
, dy
+= stepy
) {
567 /* Get color indexes */
569 MEMCPY(span
.array
->index
, p
, width
* sizeof(GLuint
));
574 _swrast_use_read_buffer(ctx
);
575 _mesa_read_index_span( ctx
, ctx
->ReadBuffer
, width
, srcx
, sy
,
578 _swrast_use_draw_buffer(ctx
);
581 /* Apply shift, offset, look-up table */
582 if (shift_or_offset
) {
583 _mesa_shift_and_offset_ci( ctx
, width
, span
.array
->index
);
585 if (ctx
->Pixel
.MapColorFlag
) {
586 _mesa_map_ci( ctx
, width
, span
.array
->index
);
589 /* write color indexes */
594 _mesa_write_zoomed_index_span(ctx
, &span
, desty
, 0);
596 _mesa_write_index_span(ctx
, &span
);
609 copy_depth_pixels( GLcontext
*ctx
, GLint srcx
, GLint srcy
,
610 GLint width
, GLint height
,
611 GLint destx
, GLint desty
)
613 GLfloat
*p
, *tmpImage
;
616 const GLboolean zoom
= ctx
->Pixel
.ZoomX
!= 1.0F
|| ctx
->Pixel
.ZoomY
!= 1.0F
;
620 INIT_SPAN(span
, GL_BITMAP
, 0, 0, SPAN_Z
);
622 if (!ctx
->Visual
.depthBits
) {
623 _mesa_error( ctx
, GL_INVALID_OPERATION
, "glCopyPixels" );
627 /* Determine if copy should be bottom-to-top or top-to-bottom */
629 /* top-down max-to-min */
630 sy
= srcy
+ height
- 1;
631 dy
= desty
+ height
- 1;
635 /* bottom-up min-to-max */
641 overlapping
= regions_overlap(srcx
, srcy
, destx
, desty
, width
, height
,
642 ctx
->Pixel
.ZoomX
, ctx
->Pixel
.ZoomY
);
644 _mesa_span_default_color(ctx
, &span
);
645 if (ctx
->Fog
.Enabled
)
646 _mesa_span_default_fog(ctx
, &span
);
650 tmpImage
= (GLfloat
*) MALLOC(width
* height
* sizeof(GLfloat
));
652 _mesa_error( ctx
, GL_OUT_OF_MEMORY
, "glCopyPixels" );
656 for (j
= 0; j
< height
; j
++, ssy
+= stepy
) {
657 _mesa_read_depth_span_float(ctx
, width
, srcx
, ssy
, p
);
663 tmpImage
= NULL
; /* silence compiler warning */
667 for (j
= 0; j
< height
; j
++, sy
+= stepy
, dy
+= stepy
) {
668 GLfloat depth
[MAX_WIDTH
];
670 /* get depth values */
672 MEMCPY(depth
, p
, width
* sizeof(GLfloat
));
676 _mesa_read_depth_span_float(ctx
, width
, srcx
, sy
, depth
);
679 /* apply scale and bias */
680 for (i
= 0; i
< width
; i
++) {
681 GLfloat d
= depth
[i
] * ctx
->Pixel
.DepthScale
+ ctx
->Pixel
.DepthBias
;
682 span
.array
->z
[i
] = (GLdepth
) (CLAMP(d
, 0.0F
, 1.0F
) * ctx
->DepthMax
);
685 /* write depth values */
689 if (ctx
->Visual
.rgbMode
) {
691 _mesa_write_zoomed_rgba_span( ctx
, &span
,
692 (const GLchan (*)[4])span
.array
->rgba
, desty
, 0 );
694 _mesa_write_rgba_span(ctx
, &span
);
698 _mesa_write_zoomed_index_span( ctx
, &span
, desty
, 0 );
700 _mesa_write_index_span(ctx
, &span
);
711 copy_stencil_pixels( GLcontext
*ctx
, GLint srcx
, GLint srcy
,
712 GLint width
, GLint height
,
713 GLint destx
, GLint desty
)
717 GLstencil
*p
, *tmpImage
;
718 const GLboolean zoom
= ctx
->Pixel
.ZoomX
!= 1.0F
|| ctx
->Pixel
.ZoomY
!= 1.0F
;
719 const GLboolean shift_or_offset
= ctx
->Pixel
.IndexShift
|| ctx
->Pixel
.IndexOffset
;
722 if (!ctx
->Visual
.stencilBits
) {
723 _mesa_error( ctx
, GL_INVALID_OPERATION
, "glCopyPixels" );
727 /* Determine if copy should be bottom-to-top or top-to-bottom */
729 /* top-down max-to-min */
730 sy
= srcy
+ height
- 1;
731 dy
= desty
+ height
- 1;
735 /* bottom-up min-to-max */
741 overlapping
= regions_overlap(srcx
, srcy
, destx
, desty
, width
, height
,
742 ctx
->Pixel
.ZoomX
, ctx
->Pixel
.ZoomY
);
746 tmpImage
= (GLstencil
*) MALLOC(width
* height
* sizeof(GLstencil
));
748 _mesa_error( ctx
, GL_OUT_OF_MEMORY
, "glCopyPixels" );
752 for (j
= 0; j
< height
; j
++, ssy
+= stepy
) {
753 _mesa_read_stencil_span( ctx
, width
, srcx
, ssy
, p
);
759 tmpImage
= NULL
; /* silence compiler warning */
763 for (j
= 0; j
< height
; j
++, sy
+= stepy
, dy
+= stepy
) {
764 GLstencil stencil
[MAX_WIDTH
];
766 /* Get stencil values */
768 MEMCPY(stencil
, p
, width
* sizeof(GLstencil
));
772 _mesa_read_stencil_span( ctx
, width
, srcx
, sy
, stencil
);
775 /* Apply shift, offset, look-up table */
776 if (shift_or_offset
) {
777 _mesa_shift_and_offset_stencil( ctx
, width
, stencil
);
779 if (ctx
->Pixel
.MapStencilFlag
) {
780 _mesa_map_stencil( ctx
, width
, stencil
);
783 /* Write stencil values */
785 _mesa_write_zoomed_stencil_span( ctx
, width
, destx
, dy
,
789 _mesa_write_stencil_span( ctx
, width
, destx
, dy
, stencil
);
800 _swrast_CopyPixels( GLcontext
*ctx
,
801 GLint srcx
, GLint srcy
, GLsizei width
, GLsizei height
,
802 GLint destx
, GLint desty
,
805 SWcontext
*swrast
= SWRAST_CONTEXT(ctx
);
806 RENDER_START(swrast
,ctx
);
808 if (swrast
->NewState
)
809 _swrast_validate_derived( ctx
);
811 if (type
== GL_COLOR
&& ctx
->Visual
.rgbMode
) {
812 copy_rgba_pixels( ctx
, srcx
, srcy
, width
, height
, destx
, desty
);
814 else if (type
== GL_COLOR
&& !ctx
->Visual
.rgbMode
) {
815 copy_ci_pixels( ctx
, srcx
, srcy
, width
, height
, destx
, desty
);
817 else if (type
== GL_DEPTH
) {
818 copy_depth_pixels( ctx
, srcx
, srcy
, width
, height
, destx
, desty
);
820 else if (type
== GL_STENCIL
) {
821 copy_stencil_pixels( ctx
, srcx
, srcy
, width
, height
, destx
, desty
);
824 _mesa_error( ctx
, GL_INVALID_ENUM
, "glCopyPixels" );
827 RENDER_FINISH(swrast
,ctx
);