2 * Mesa 3-D graphics library
5 * Copyright (C) 1999-2003 Brian Paul All Rights Reserved.
7 * Permission is hereby granted, free of charge, to any person obtaining a
8 * copy of this software and associated documentation files (the "Software"),
9 * to deal in the Software without restriction, including without limitation
10 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
11 * and/or sell copies of the Software, and to permit persons to whom the
12 * Software is furnished to do so, subject to the following conditions:
14 * The above copyright notice and this permission notice shall be included
15 * in all copies or substantial portions of the Software.
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
18 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
20 * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
21 * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
22 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
29 #include "histogram.h"
34 #include "s_context.h"
36 #include "s_pixeltex.h"
38 #include "s_stencil.h"
39 #include "s_texture.h"
45 * Determine if there's overlap in an image copy.
46 * This test also compensates for the fact that copies are done from
47 * bottom to top and overlaps can sometimes be handled correctly
48 * without making a temporary image copy.
51 regions_overlap(GLint srcx
, GLint srcy
,
52 GLint dstx
, GLint dsty
,
53 GLint width
, GLint height
,
54 GLfloat zoomX
, GLfloat zoomY
)
56 if (zoomX
== 1.0 && zoomY
== 1.0) {
58 if (srcx
>= dstx
+ width
|| (srcx
+ width
<= dstx
)) {
61 else if (srcy
< dsty
) { /* this is OK */
64 else if (srcy
> dsty
+ height
) {
72 /* add one pixel of slop when zooming, just to be safe */
73 if ((srcx
> dstx
+ (width
* zoomX
) + 1) || (srcx
+ width
+ 1 < dstx
)) {
76 else if ((srcy
< dsty
) && (srcy
+ height
< dsty
+ (height
* zoomY
))) {
79 else if ((srcy
> dsty
) && (srcy
+ height
> dsty
+ (height
* zoomY
))) {
91 * RGBA copypixels with convolution.
94 copy_conv_rgba_pixels(GLcontext
*ctx
, GLint srcx
, GLint srcy
,
95 GLint width
, GLint height
, GLint destx
, GLint desty
)
97 SWcontext
*swrast
= SWRAST_CONTEXT(ctx
);
100 GLboolean changeBuffer
;
101 const GLboolean zoom
= ctx
->Pixel
.ZoomX
!= 1.0F
|| ctx
->Pixel
.ZoomY
!= 1.0F
;
102 const GLuint transferOps
= ctx
->_ImageTransferState
;
103 GLfloat
*dest
, *tmpImage
, *convImage
;
106 INIT_SPAN(span
, GL_BITMAP
, 0, 0, SPAN_RGBA
);
109 _swrast_span_default_z(ctx
, &span
);
110 if (ctx
->Fog
.Enabled
)
111 _swrast_span_default_fog(ctx
, &span
);
114 if (SWRAST_CONTEXT(ctx
)->_RasterMask
== 0
117 && destx
+ width
<= (GLint
) ctx
->DrawBuffer
->Width
) {
118 quick_draw
= GL_TRUE
;
121 quick_draw
= GL_FALSE
;
124 /* If read and draw buffer are different we must do buffer switching */
125 changeBuffer
= ctx
->Pixel
.ReadBuffer
!= ctx
->Color
.DrawBuffer
126 || ctx
->DrawBuffer
!= ctx
->ReadBuffer
;
129 /* allocate space for GLfloat image */
130 tmpImage
= (GLfloat
*) MALLOC(width
* height
* 4 * sizeof(GLfloat
));
132 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glCopyPixels");
135 convImage
= (GLfloat
*) MALLOC(width
* height
* 4 * sizeof(GLfloat
));
138 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glCopyPixels");
145 /* choose the read buffer */
146 _swrast_use_read_buffer(ctx
);
149 /* read source image */
151 for (row
= 0; row
< height
; row
++) {
152 GLchan rgba
[MAX_WIDTH
][4];
154 _swrast_read_rgba_span(ctx
, ctx
->ReadBuffer
, width
, srcx
, srcy
+ row
, rgba
);
155 /* convert GLchan to GLfloat */
156 for (i
= 0; i
< width
; i
++) {
157 *dest
++ = (GLfloat
) rgba
[i
][RCOMP
] * (1.0F
/ CHAN_MAXF
);
158 *dest
++ = (GLfloat
) rgba
[i
][GCOMP
] * (1.0F
/ CHAN_MAXF
);
159 *dest
++ = (GLfloat
) rgba
[i
][BCOMP
] * (1.0F
/ CHAN_MAXF
);
160 *dest
++ = (GLfloat
) rgba
[i
][ACOMP
] * (1.0F
/ CHAN_MAXF
);
165 /* restore default src/dst buffer */
166 _swrast_use_draw_buffer(ctx
);
169 /* do image transfer ops up until convolution */
170 for (row
= 0; row
< height
; row
++) {
171 GLfloat (*rgba
)[4] = (GLfloat (*)[4]) (tmpImage
+ row
* width
* 4);
174 if (transferOps
& IMAGE_SCALE_BIAS_BIT
) {
175 _mesa_scale_and_bias_rgba(ctx
, width
, rgba
,
176 ctx
->Pixel
.RedScale
, ctx
->Pixel
.GreenScale
,
177 ctx
->Pixel
.BlueScale
, ctx
->Pixel
.AlphaScale
,
178 ctx
->Pixel
.RedBias
, ctx
->Pixel
.GreenBias
,
179 ctx
->Pixel
.BlueBias
, ctx
->Pixel
.AlphaBias
);
181 /* color map lookup */
182 if (transferOps
& IMAGE_MAP_COLOR_BIT
) {
183 _mesa_map_rgba(ctx
, width
, rgba
);
185 /* GL_COLOR_TABLE lookup */
186 if (transferOps
& IMAGE_COLOR_TABLE_BIT
) {
187 _mesa_lookup_rgba_float(&ctx
->ColorTable
, width
, rgba
);
192 if (ctx
->Pixel
.Convolution2DEnabled
) {
193 _mesa_convolve_2d_image(ctx
, &width
, &height
, tmpImage
, convImage
);
196 ASSERT(ctx
->Pixel
.Separable2DEnabled
);
197 _mesa_convolve_sep_image(ctx
, &width
, &height
, tmpImage
, convImage
);
201 /* do remaining image transfer ops */
202 for (row
= 0; row
< height
; row
++) {
203 GLfloat (*rgba
)[4] = (GLfloat (*)[4]) (convImage
+ row
* width
* 4);
205 /* GL_POST_CONVOLUTION_COLOR_TABLE lookup */
206 if (transferOps
& IMAGE_POST_CONVOLUTION_COLOR_TABLE_BIT
) {
207 _mesa_lookup_rgba_float(&ctx
->PostConvolutionColorTable
, width
, rgba
);
210 if (transferOps
& IMAGE_COLOR_MATRIX_BIT
) {
211 _mesa_transform_rgba(ctx
, width
, rgba
);
213 /* GL_POST_COLOR_MATRIX_COLOR_TABLE lookup */
214 if (transferOps
& IMAGE_POST_COLOR_MATRIX_COLOR_TABLE_BIT
) {
215 _mesa_lookup_rgba_float(&ctx
->PostColorMatrixColorTable
, width
, rgba
);
217 /* update histogram count */
218 if (transferOps
& IMAGE_HISTOGRAM_BIT
) {
219 _mesa_update_histogram(ctx
, width
, (CONST
GLfloat (*)[4]) rgba
);
222 if (transferOps
& IMAGE_MIN_MAX_BIT
) {
223 _mesa_update_minmax(ctx
, width
, (CONST
GLfloat (*)[4]) rgba
);
227 for (row
= 0; row
< height
; row
++) {
228 const GLfloat
*src
= convImage
+ row
* width
* 4;
231 /* clamp to [0,1] and convert float back to chan */
232 for (i
= 0; i
< width
; i
++) {
233 GLint r
= (GLint
) (src
[i
* 4 + RCOMP
] * CHAN_MAXF
);
234 GLint g
= (GLint
) (src
[i
* 4 + GCOMP
] * CHAN_MAXF
);
235 GLint b
= (GLint
) (src
[i
* 4 + BCOMP
] * CHAN_MAXF
);
236 GLint a
= (GLint
) (src
[i
* 4 + ACOMP
] * CHAN_MAXF
);
237 span
.array
->rgba
[i
][RCOMP
] = (GLchan
) CLAMP(r
, 0, CHAN_MAX
);
238 span
.array
->rgba
[i
][GCOMP
] = (GLchan
) CLAMP(g
, 0, CHAN_MAX
);
239 span
.array
->rgba
[i
][BCOMP
] = (GLchan
) CLAMP(b
, 0, CHAN_MAX
);
240 span
.array
->rgba
[i
][ACOMP
] = (GLchan
) CLAMP(a
, 0, CHAN_MAX
);
243 if (ctx
->Pixel
.PixelTextureEnabled
&& ctx
->Texture
._EnabledUnits
) {
245 _swrast_pixel_texture(ctx
, &span
);
248 /* write row to framebuffer */
251 if (quick_draw
&& dy
>= 0 && dy
< (GLint
) ctx
->DrawBuffer
->Height
) {
252 (*swrast
->Driver
.WriteRGBASpan
)( ctx
, width
, destx
, dy
,
253 (const GLchan (*)[4])span
.array
->rgba
, NULL
);
259 _swrast_write_zoomed_rgba_span(ctx
, &span
,
260 (CONST
GLchan (*)[4])span
.array
->rgba
,
267 _swrast_write_rgba_span(ctx
, &span
);
279 copy_rgba_pixels(GLcontext
*ctx
, GLint srcx
, GLint srcy
,
280 GLint width
, GLint height
, GLint destx
, GLint desty
)
282 SWcontext
*swrast
= SWRAST_CONTEXT(ctx
);
284 GLboolean quick_draw
;
285 GLint sy
, dy
, stepy
, j
;
286 GLboolean changeBuffer
;
287 const GLboolean zoom
= ctx
->Pixel
.ZoomX
!= 1.0F
|| ctx
->Pixel
.ZoomY
!= 1.0F
;
289 const GLuint transferOps
= ctx
->_ImageTransferState
;
292 INIT_SPAN(span
, GL_BITMAP
, 0, 0, SPAN_RGBA
);
294 if (ctx
->Pixel
.Convolution2DEnabled
|| ctx
->Pixel
.Separable2DEnabled
) {
295 copy_conv_rgba_pixels(ctx
, srcx
, srcy
, width
, height
, destx
, desty
);
299 /* Determine if copy should be done bottom-to-top or top-to-bottom */
301 /* top-down max-to-min */
302 sy
= srcy
+ height
- 1;
303 dy
= desty
+ height
- 1;
307 /* bottom-up min-to-max */
313 if (ctx
->DrawBuffer
== ctx
->ReadBuffer
) {
314 overlapping
= regions_overlap(srcx
, srcy
, destx
, desty
, width
, height
,
315 ctx
->Pixel
.ZoomX
, ctx
->Pixel
.ZoomY
);
318 overlapping
= GL_FALSE
;
322 _swrast_span_default_z(ctx
, &span
);
323 if (ctx
->Fog
.Enabled
)
324 _swrast_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 _swrast_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 ASSERT(width
< MAX_WIDTH
);
374 MEMCPY(span
.array
->rgba
, p
, width
* sizeof(GLchan
) * 4);
378 /* get from framebuffer */
380 _swrast_use_read_buffer(ctx
);
381 ASSERT(width
< MAX_WIDTH
);
382 _swrast_read_rgba_span( ctx
, ctx
->ReadBuffer
, width
, srcx
, sy
,
385 _swrast_use_draw_buffer(ctx
);
389 const GLfloat scale
= (1.0F
/ CHAN_MAXF
);
391 DEFMARRAY(GLfloat
, rgbaFloat
, MAX_WIDTH
, 4); /* mac 32k limitation */
392 CHECKARRAY(rgbaFloat
, return);
394 /* convert chan to float */
395 for (k
= 0; k
< width
; k
++) {
396 rgbaFloat
[k
][RCOMP
] = (GLfloat
) span
.array
->rgba
[k
][RCOMP
] * scale
;
397 rgbaFloat
[k
][GCOMP
] = (GLfloat
) span
.array
->rgba
[k
][GCOMP
] * scale
;
398 rgbaFloat
[k
][BCOMP
] = (GLfloat
) span
.array
->rgba
[k
][BCOMP
] * scale
;
399 rgbaFloat
[k
][ACOMP
] = (GLfloat
) span
.array
->rgba
[k
][ACOMP
] * scale
;
402 if (transferOps
& IMAGE_SCALE_BIAS_BIT
) {
403 _mesa_scale_and_bias_rgba(ctx
, width
, rgbaFloat
,
404 ctx
->Pixel
.RedScale
, ctx
->Pixel
.GreenScale
,
405 ctx
->Pixel
.BlueScale
, ctx
->Pixel
.AlphaScale
,
406 ctx
->Pixel
.RedBias
, ctx
->Pixel
.GreenBias
,
407 ctx
->Pixel
.BlueBias
, ctx
->Pixel
.AlphaBias
);
409 /* color map lookup */
410 if (transferOps
& IMAGE_MAP_COLOR_BIT
) {
411 _mesa_map_rgba(ctx
, width
, rgbaFloat
);
413 /* GL_COLOR_TABLE lookup */
414 if (transferOps
& IMAGE_COLOR_TABLE_BIT
) {
415 _mesa_lookup_rgba_float(&ctx
->ColorTable
, width
, rgbaFloat
);
418 if (transferOps
& IMAGE_CONVOLUTION_BIT
) {
419 _mesa_problem(ctx
, "Convolution should not be enabled in copy_rgba_pixels()");
422 /* GL_POST_CONVOLUTION_RED/GREEN/BLUE/ALPHA_SCALE/BIAS */
423 if (transferOps
& IMAGE_POST_CONVOLUTION_SCALE_BIAS
) {
424 _mesa_scale_and_bias_rgba(ctx
, width
, rgbaFloat
,
425 ctx
->Pixel
.PostConvolutionScale
[RCOMP
],
426 ctx
->Pixel
.PostConvolutionScale
[GCOMP
],
427 ctx
->Pixel
.PostConvolutionScale
[BCOMP
],
428 ctx
->Pixel
.PostConvolutionScale
[ACOMP
],
429 ctx
->Pixel
.PostConvolutionBias
[RCOMP
],
430 ctx
->Pixel
.PostConvolutionBias
[GCOMP
],
431 ctx
->Pixel
.PostConvolutionBias
[BCOMP
],
432 ctx
->Pixel
.PostConvolutionBias
[ACOMP
]);
434 /* GL_POST_CONVOLUTION_COLOR_TABLE lookup */
435 if (transferOps
& IMAGE_POST_CONVOLUTION_COLOR_TABLE_BIT
) {
436 _mesa_lookup_rgba_float(&ctx
->PostConvolutionColorTable
, width
, rgbaFloat
);
439 if (transferOps
& IMAGE_COLOR_MATRIX_BIT
) {
440 _mesa_transform_rgba(ctx
, width
, rgbaFloat
);
442 /* GL_POST_COLOR_MATRIX_COLOR_TABLE lookup */
443 if (transferOps
& IMAGE_POST_COLOR_MATRIX_COLOR_TABLE_BIT
) {
444 _mesa_lookup_rgba_float(&ctx
->PostColorMatrixColorTable
, width
, rgbaFloat
);
446 /* update histogram count */
447 if (transferOps
& IMAGE_HISTOGRAM_BIT
) {
448 _mesa_update_histogram(ctx
, width
, (CONST
GLfloat (*)[4]) rgbaFloat
);
451 if (transferOps
& IMAGE_MIN_MAX_BIT
) {
452 _mesa_update_minmax(ctx
, width
, (CONST
GLfloat (*)[4]) rgbaFloat
);
454 /* clamp to [0,1] and convert float back to chan */
455 for (k
= 0; k
< width
; k
++) {
456 GLint r
= (GLint
) (rgbaFloat
[k
][RCOMP
] * CHAN_MAXF
);
457 GLint g
= (GLint
) (rgbaFloat
[k
][GCOMP
] * CHAN_MAXF
);
458 GLint b
= (GLint
) (rgbaFloat
[k
][BCOMP
] * CHAN_MAXF
);
459 GLint a
= (GLint
) (rgbaFloat
[k
][ACOMP
] * CHAN_MAXF
);
460 span
.array
->rgba
[k
][RCOMP
] = (GLchan
) CLAMP(r
, 0, CHAN_MAX
);
461 span
.array
->rgba
[k
][GCOMP
] = (GLchan
) CLAMP(g
, 0, CHAN_MAX
);
462 span
.array
->rgba
[k
][BCOMP
] = (GLchan
) CLAMP(b
, 0, CHAN_MAX
);
463 span
.array
->rgba
[k
][ACOMP
] = (GLchan
) CLAMP(a
, 0, CHAN_MAX
);
465 UNDEFARRAY(rgbaFloat
); /* mac 32k limitation */
468 if (ctx
->Pixel
.PixelTextureEnabled
&& ctx
->Texture
._EnabledUnits
) {
470 _swrast_pixel_texture(ctx
, &span
);
473 /* Write color span */
474 if (quick_draw
&& dy
>= 0 && dy
< (GLint
) ctx
->DrawBuffer
->Height
) {
475 (*swrast
->Driver
.WriteRGBASpan
)( ctx
, width
, destx
, dy
,
476 (const GLchan (*)[4])span
.array
->rgba
, NULL
);
482 _swrast_write_zoomed_rgba_span(ctx
, &span
,
483 (CONST
GLchan (*)[4]) span
.array
->rgba
,
490 _swrast_write_rgba_span(ctx
, &span
);
500 copy_ci_pixels( GLcontext
*ctx
, GLint srcx
, GLint srcy
,
501 GLint width
, GLint height
,
502 GLint destx
, GLint desty
)
507 GLboolean changeBuffer
;
508 const GLboolean zoom
= ctx
->Pixel
.ZoomX
!= 1.0F
|| ctx
->Pixel
.ZoomY
!= 1.0F
;
509 const GLboolean shift_or_offset
= ctx
->Pixel
.IndexShift
|| ctx
->Pixel
.IndexOffset
;
513 INIT_SPAN(span
, GL_BITMAP
, 0, 0, SPAN_INDEX
);
515 /* Determine if copy should be bottom-to-top or top-to-bottom */
517 /* top-down max-to-min */
518 sy
= srcy
+ height
- 1;
519 dy
= desty
+ height
- 1;
523 /* bottom-up min-to-max */
529 if (ctx
->DrawBuffer
== ctx
->ReadBuffer
) {
530 overlapping
= regions_overlap(srcx
, srcy
, destx
, desty
, width
, height
,
531 ctx
->Pixel
.ZoomX
, ctx
->Pixel
.ZoomY
);
534 overlapping
= GL_FALSE
;
538 _swrast_span_default_z(ctx
, &span
);
539 if (ctx
->Fog
.Enabled
)
540 _swrast_span_default_fog(ctx
, &span
);
542 /* If read and draw buffer are different we must do buffer switching */
543 changeBuffer
= ctx
->Pixel
.ReadBuffer
!= ctx
->Color
.DrawBuffer
544 || ctx
->DrawBuffer
!= ctx
->ReadBuffer
;
548 tmpImage
= (GLuint
*) MALLOC(width
* height
* sizeof(GLuint
));
550 _mesa_error( ctx
, GL_OUT_OF_MEMORY
, "glCopyPixels" );
555 _swrast_use_read_buffer(ctx
);
558 for (j
= 0; j
< height
; j
++, ssy
+= stepy
) {
559 _swrast_read_index_span( ctx
, ctx
->ReadBuffer
, width
, srcx
, ssy
, p
);
563 /* restore to draw buffer */
565 _swrast_use_draw_buffer(ctx
);
566 changeBuffer
= GL_FALSE
;
570 tmpImage
= NULL
; /* silence compiler warning */
574 for (j
= 0; j
< height
; j
++, sy
+= stepy
, dy
+= stepy
) {
575 /* Get color indexes */
577 MEMCPY(span
.array
->index
, p
, width
* sizeof(GLuint
));
582 _swrast_use_read_buffer(ctx
);
583 _swrast_read_index_span( ctx
, ctx
->ReadBuffer
, width
, srcx
, sy
,
586 _swrast_use_draw_buffer(ctx
);
589 /* Apply shift, offset, look-up table */
590 if (shift_or_offset
) {
591 _mesa_shift_and_offset_ci( ctx
, width
, span
.array
->index
);
593 if (ctx
->Pixel
.MapColorFlag
) {
594 _mesa_map_ci( ctx
, width
, span
.array
->index
);
597 /* write color indexes */
602 _swrast_write_zoomed_index_span(ctx
, &span
, desty
, 0);
604 _swrast_write_index_span(ctx
, &span
);
617 copy_depth_pixels( GLcontext
*ctx
, GLint srcx
, GLint srcy
,
618 GLint width
, GLint height
,
619 GLint destx
, GLint desty
)
621 GLfloat
*p
, *tmpImage
;
624 const GLboolean zoom
= ctx
->Pixel
.ZoomX
!= 1.0F
|| ctx
->Pixel
.ZoomY
!= 1.0F
;
628 INIT_SPAN(span
, GL_BITMAP
, 0, 0, SPAN_Z
);
630 if (!ctx
->Visual
.depthBits
) {
631 _mesa_error( ctx
, GL_INVALID_OPERATION
, "glCopyPixels" );
635 /* Determine if copy should be bottom-to-top or top-to-bottom */
637 /* top-down max-to-min */
638 sy
= srcy
+ height
- 1;
639 dy
= desty
+ height
- 1;
643 /* bottom-up min-to-max */
649 if (ctx
->DrawBuffer
== ctx
->ReadBuffer
) {
650 overlapping
= regions_overlap(srcx
, srcy
, destx
, desty
, width
, height
,
651 ctx
->Pixel
.ZoomX
, ctx
->Pixel
.ZoomY
);
654 overlapping
= GL_FALSE
;
657 _swrast_span_default_color(ctx
, &span
);
658 if (ctx
->Fog
.Enabled
)
659 _swrast_span_default_fog(ctx
, &span
);
663 tmpImage
= (GLfloat
*) MALLOC(width
* height
* sizeof(GLfloat
));
665 _mesa_error( ctx
, GL_OUT_OF_MEMORY
, "glCopyPixels" );
669 for (j
= 0; j
< height
; j
++, ssy
+= stepy
) {
670 _swrast_read_depth_span_float(ctx
, width
, srcx
, ssy
, p
);
676 tmpImage
= NULL
; /* silence compiler warning */
680 for (j
= 0; j
< height
; j
++, sy
+= stepy
, dy
+= stepy
) {
681 GLfloat depth
[MAX_WIDTH
];
683 /* get depth values */
685 MEMCPY(depth
, p
, width
* sizeof(GLfloat
));
689 _swrast_read_depth_span_float(ctx
, width
, srcx
, sy
, depth
);
692 /* apply scale and bias */
693 for (i
= 0; i
< width
; i
++) {
694 GLfloat d
= depth
[i
] * ctx
->Pixel
.DepthScale
+ ctx
->Pixel
.DepthBias
;
695 span
.array
->z
[i
] = (GLdepth
) (CLAMP(d
, 0.0F
, 1.0F
) * ctx
->DepthMax
);
698 /* write depth values */
702 if (ctx
->Visual
.rgbMode
) {
704 _swrast_write_zoomed_rgba_span( ctx
, &span
,
705 (const GLchan (*)[4])span
.array
->rgba
, desty
, 0 );
707 _swrast_write_rgba_span(ctx
, &span
);
711 _swrast_write_zoomed_index_span( ctx
, &span
, desty
, 0 );
713 _swrast_write_index_span(ctx
, &span
);
724 copy_stencil_pixels( GLcontext
*ctx
, GLint srcx
, GLint srcy
,
725 GLint width
, GLint height
,
726 GLint destx
, GLint desty
)
730 GLstencil
*p
, *tmpImage
;
731 const GLboolean zoom
= ctx
->Pixel
.ZoomX
!= 1.0F
|| ctx
->Pixel
.ZoomY
!= 1.0F
;
732 const GLboolean shift_or_offset
= ctx
->Pixel
.IndexShift
|| ctx
->Pixel
.IndexOffset
;
735 if (!ctx
->Visual
.stencilBits
) {
736 _mesa_error( ctx
, GL_INVALID_OPERATION
, "glCopyPixels" );
740 /* Determine if copy should be bottom-to-top or top-to-bottom */
742 /* top-down max-to-min */
743 sy
= srcy
+ height
- 1;
744 dy
= desty
+ height
- 1;
748 /* bottom-up min-to-max */
754 if (ctx
->DrawBuffer
== ctx
->ReadBuffer
) {
755 overlapping
= regions_overlap(srcx
, srcy
, destx
, desty
, width
, height
,
756 ctx
->Pixel
.ZoomX
, ctx
->Pixel
.ZoomY
);
759 overlapping
= GL_FALSE
;
764 tmpImage
= (GLstencil
*) MALLOC(width
* height
* sizeof(GLstencil
));
766 _mesa_error( ctx
, GL_OUT_OF_MEMORY
, "glCopyPixels" );
770 for (j
= 0; j
< height
; j
++, ssy
+= stepy
) {
771 _swrast_read_stencil_span( ctx
, width
, srcx
, ssy
, p
);
777 tmpImage
= NULL
; /* silence compiler warning */
781 for (j
= 0; j
< height
; j
++, sy
+= stepy
, dy
+= stepy
) {
782 GLstencil stencil
[MAX_WIDTH
];
784 /* Get stencil values */
786 MEMCPY(stencil
, p
, width
* sizeof(GLstencil
));
790 _swrast_read_stencil_span( ctx
, width
, srcx
, sy
, stencil
);
793 /* Apply shift, offset, look-up table */
794 if (shift_or_offset
) {
795 _mesa_shift_and_offset_stencil( ctx
, width
, stencil
);
797 if (ctx
->Pixel
.MapStencilFlag
) {
798 _mesa_map_stencil( ctx
, width
, stencil
);
801 /* Write stencil values */
803 _swrast_write_zoomed_stencil_span( ctx
, width
, destx
, dy
,
807 _swrast_write_stencil_span( ctx
, width
, destx
, dy
, stencil
);
818 _swrast_CopyPixels( GLcontext
*ctx
,
819 GLint srcx
, GLint srcy
, GLsizei width
, GLsizei height
,
820 GLint destx
, GLint desty
,
823 SWcontext
*swrast
= SWRAST_CONTEXT(ctx
);
824 RENDER_START(swrast
,ctx
);
826 if (swrast
->NewState
)
827 _swrast_validate_derived( ctx
);
829 if (type
== GL_COLOR
&& ctx
->Visual
.rgbMode
) {
830 copy_rgba_pixels( ctx
, srcx
, srcy
, width
, height
, destx
, desty
);
832 else if (type
== GL_COLOR
&& !ctx
->Visual
.rgbMode
) {
833 copy_ci_pixels( ctx
, srcx
, srcy
, width
, height
, destx
, desty
);
835 else if (type
== GL_DEPTH
) {
836 copy_depth_pixels( ctx
, srcx
, srcy
, width
, height
, destx
, desty
);
838 else if (type
== GL_STENCIL
) {
839 copy_stencil_pixels( ctx
, srcx
, srcy
, width
, height
, destx
, desty
);
842 _mesa_error( ctx
, GL_INVALID_ENUM
, "glCopyPixels" );
845 RENDER_FINISH(swrast
,ctx
);