added SPAN_W
[mesa.git] / src / mesa / swrast / s_copypix.c
index 31fffff6270923b6cd9ed4a5f56a3a9fbb075f6f..0692adfbff96916d199f323a36c7619e1803a3b1 100644 (file)
@@ -1,10 +1,8 @@
-/* $Id: s_copypix.c,v 1.42 2002/10/30 20:16:43 brianp Exp $ */
-
 /*
  * Mesa 3-D graphics library
- * Version:  5.0
+ * Version:  5.1
  *
- * Copyright (C) 1999-2002  Brian Paul   All Rights Reserved.
+ * Copyright (C) 1999-2003  Brian Paul   All Rights Reserved.
  *
  * Permission is hereby granted, free of charge, to any person obtaining a
  * copy of this software and associated documentation files (the "Software"),
 
 
 #include "glheader.h"
-#include "colormac.h"
 #include "context.h"
 #include "convolve.h"
-#include "feedback.h"
+#include "histogram.h"
 #include "macros.h"
 #include "imports.h"
-#include "mmath.h"
 #include "pixel.h"
 
 #include "s_context.h"
 #include "s_depth.h"
-#include "s_histogram.h"
 #include "s_pixeltex.h"
 #include "s_span.h"
 #include "s_stencil.h"
@@ -111,9 +106,9 @@ copy_conv_rgba_pixels(GLcontext *ctx, GLint srcx, GLint srcy,
    INIT_SPAN(span, GL_BITMAP, 0, 0, SPAN_RGBA);
 
    if (ctx->Depth.Test)
-      _mesa_span_default_z(ctx, &span);
+      _swrast_span_default_z(ctx, &span);
    if (ctx->Fog.Enabled)
-      _mesa_span_default_fog(ctx, &span);
+      _swrast_span_default_fog(ctx, &span);
 
 
    if (SWRAST_CONTEXT(ctx)->_RasterMask == 0
@@ -156,7 +151,7 @@ copy_conv_rgba_pixels(GLcontext *ctx, GLint srcx, GLint srcy,
    for (row = 0; row < height; row++) {
       GLchan rgba[MAX_WIDTH][4];
       GLint i;
-      _mesa_read_rgba_span(ctx, ctx->ReadBuffer, width, srcx, srcy + row, rgba);
+      _swrast_read_rgba_span(ctx, ctx->ReadBuffer, width, srcx, srcy + row, rgba);
       /* convert GLchan to GLfloat */
       for (i = 0; i < width; i++) {
          *dest++ = (GLfloat) rgba[i][RCOMP] * (1.0F / CHAN_MAXF);
@@ -261,15 +256,15 @@ copy_conv_rgba_pixels(GLcontext *ctx, GLint srcx, GLint srcy,
          span.x = destx;
          span.y = dy;
          span.end = width;
-         _mesa_write_zoomed_rgba_span(ctx, &span, 
+         _swrast_write_zoomed_rgba_span(ctx, &span, 
                                      (CONST GLchan (*)[4])span.array->rgba,
-                                     desty);
+                                     desty, 0);
       }
       else {
          span.x = destx;
          span.y = dy;
          span.end = width;
-         _mesa_write_rgba_span(ctx, &span);
+         _swrast_write_rgba_span(ctx, &span);
       }
    }
 
@@ -315,13 +310,18 @@ copy_rgba_pixels(GLcontext *ctx, GLint srcx, GLint srcy,
       stepy = 1;
    }
 
-   overlapping = regions_overlap(srcx, srcy, destx, desty, width, height,
-                                 ctx->Pixel.ZoomX, ctx->Pixel.ZoomY);
+   if (ctx->DrawBuffer == ctx->ReadBuffer) {
+      overlapping = regions_overlap(srcx, srcy, destx, desty, width, height,
+                                    ctx->Pixel.ZoomX, ctx->Pixel.ZoomY);
+   }
+   else {
+      overlapping = GL_FALSE;
+   }
 
    if (ctx->Depth.Test)
-      _mesa_span_default_z(ctx, &span);
+      _swrast_span_default_z(ctx, &span);
    if (ctx->Fog.Enabled)
-      _mesa_span_default_fog(ctx, &span);
+      _swrast_span_default_fog(ctx, &span);
 
    if (SWRAST_CONTEXT(ctx)->_RasterMask == 0
        && !zoom
@@ -350,7 +350,7 @@ copy_rgba_pixels(GLcontext *ctx, GLint srcx, GLint srcy,
       /* read the source image */
       p = tmpImage;
       for (j = 0; j < height; j++, ssy += stepy) {
-         _mesa_read_rgba_span( ctx, ctx->ReadBuffer, width, srcx, ssy,
+         _swrast_read_rgba_span( ctx, ctx->ReadBuffer, width, srcx, ssy,
                             (GLchan (*)[4]) p );
          p += width * 4;
       }
@@ -370,6 +370,7 @@ copy_rgba_pixels(GLcontext *ctx, GLint srcx, GLint srcy,
       /* Get source pixels */
       if (overlapping) {
          /* get from buffered image */
+         ASSERT(width < MAX_WIDTH);
          MEMCPY(span.array->rgba, p, width * sizeof(GLchan) * 4);
          p += width * 4;
       }
@@ -377,7 +378,8 @@ copy_rgba_pixels(GLcontext *ctx, GLint srcx, GLint srcy,
          /* get from framebuffer */
          if (changeBuffer)
             _swrast_use_read_buffer(ctx);
-         _mesa_read_rgba_span( ctx, ctx->ReadBuffer, width, srcx, sy,
+         ASSERT(width < MAX_WIDTH);
+         _swrast_read_rgba_span( ctx, ctx->ReadBuffer, width, srcx, sy,
                                span.array->rgba );
          if (changeBuffer)
             _swrast_use_draw_buffer(ctx);
@@ -468,23 +470,24 @@ copy_rgba_pixels(GLcontext *ctx, GLint srcx, GLint srcy,
          _swrast_pixel_texture(ctx, &span);
       }
 
+      /* Write color span */
       if (quick_draw && dy >= 0 && dy < (GLint) ctx->DrawBuffer->Height) {
          (*swrast->Driver.WriteRGBASpan)( ctx, width, destx, dy,
-                                      (const GLchan (*)[4])span.array->rgba, NULL );
+                                 (const GLchan (*)[4])span.array->rgba, NULL );
       }
       else if (zoom) {
          span.x = destx;
          span.y = dy;
          span.end = width;
-         _mesa_write_zoomed_rgba_span(ctx, &span,
+         _swrast_write_zoomed_rgba_span(ctx, &span,
                                      (CONST GLchan (*)[4]) span.array->rgba,
-                                     desty);
+                                     desty, 0);
       }
       else {
          span.x = destx;
          span.y = dy;
          span.end = width;
-         _mesa_write_rgba_span(ctx, &span);
+         _swrast_write_rgba_span(ctx, &span);
       }
    }
 
@@ -493,9 +496,10 @@ copy_rgba_pixels(GLcontext *ctx, GLint srcx, GLint srcy,
 }
 
 
-static void copy_ci_pixels( GLcontext *ctx,
-                            GLint srcx, GLint srcy, GLint width, GLint height,
-                            GLint destx, GLint desty )
+static void
+copy_ci_pixels( GLcontext *ctx, GLint srcx, GLint srcy,
+                GLint width, GLint height,
+                GLint destx, GLint desty )
 {
    GLuint *tmpImage,*p;
    GLint sy, dy, stepy;
@@ -522,13 +526,18 @@ static void copy_ci_pixels( GLcontext *ctx,
       stepy = 1;
    }
 
-   overlapping = regions_overlap(srcx, srcy, destx, desty, width, height,
-                                 ctx->Pixel.ZoomX, ctx->Pixel.ZoomY);
+   if (ctx->DrawBuffer == ctx->ReadBuffer) {
+      overlapping = regions_overlap(srcx, srcy, destx, desty, width, height,
+                                    ctx->Pixel.ZoomX, ctx->Pixel.ZoomY);
+   }
+   else {
+      overlapping = GL_FALSE;
+   }
 
    if (ctx->Depth.Test)
-      _mesa_span_default_z(ctx, &span);
+      _swrast_span_default_z(ctx, &span);
    if (ctx->Fog.Enabled)
-      _mesa_span_default_fog(ctx, &span);
+      _swrast_span_default_fog(ctx, &span);
 
    /* If read and draw buffer are different we must do buffer switching */
    changeBuffer = ctx->Pixel.ReadBuffer != ctx->Color.DrawBuffer
@@ -547,7 +556,7 @@ static void copy_ci_pixels( GLcontext *ctx,
       /* read the image */
       p = tmpImage;
       for (j = 0; j < height; j++, ssy += stepy) {
-         _mesa_read_index_span( ctx, ctx->ReadBuffer, width, srcx, ssy, p );
+         _swrast_read_index_span( ctx, ctx->ReadBuffer, width, srcx, ssy, p );
          p += width;
       }
       p = tmpImage;
@@ -563,6 +572,7 @@ static void copy_ci_pixels( GLcontext *ctx,
    }
 
    for (j = 0; j < height; j++, sy += stepy, dy += stepy) {
+      /* Get color indexes */
       if (overlapping) {
          MEMCPY(span.array->index, p, width * sizeof(GLuint));
          p += width;
@@ -570,12 +580,13 @@ static void copy_ci_pixels( GLcontext *ctx,
       else {
          if (changeBuffer)
             _swrast_use_read_buffer(ctx);
-         _mesa_read_index_span( ctx, ctx->ReadBuffer, width, srcx, sy,
+         _swrast_read_index_span( ctx, ctx->ReadBuffer, width, srcx, sy,
                                 span.array->index );
          if (changeBuffer)
             _swrast_use_draw_buffer(ctx);
       }
 
+      /* Apply shift, offset, look-up table */
       if (shift_or_offset) {
          _mesa_shift_and_offset_ci( ctx, width, span.array->index );
       }
@@ -583,13 +594,14 @@ static void copy_ci_pixels( GLcontext *ctx,
          _mesa_map_ci( ctx, width, span.array->index );
       }
 
+      /* write color indexes */
       span.x = destx;
       span.y = dy;
       span.end = width;
       if (zoom)
-         _mesa_write_zoomed_index_span(ctx, &span, desty);
+         _swrast_write_zoomed_index_span(ctx, &span, desty, 0);
       else
-         _mesa_write_index_span(ctx, &span);
+         _swrast_write_index_span(ctx, &span);
    }
 
    if (overlapping)
@@ -601,11 +613,11 @@ static void copy_ci_pixels( GLcontext *ctx,
 /*
  * TODO: Optimize!!!!
  */
-static void copy_depth_pixels( GLcontext *ctx, GLint srcx, GLint srcy,
-                               GLint width, GLint height,
-                               GLint destx, GLint desty )
+static void
+copy_depth_pixels( GLcontext *ctx, GLint srcx, GLint srcy,
+                   GLint width, GLint height,
+                   GLint destx, GLint desty )
 {
-   GLfloat depth[MAX_WIDTH];
    GLfloat *p, *tmpImage;
    GLint sy, dy, stepy;
    GLint i, j;
@@ -634,12 +646,17 @@ static void copy_depth_pixels( GLcontext *ctx, GLint srcx, GLint srcy,
       stepy = 1;
    }
 
-   overlapping = regions_overlap(srcx, srcy, destx, desty, width, height,
-                                 ctx->Pixel.ZoomX, ctx->Pixel.ZoomY);
+   if (ctx->DrawBuffer == ctx->ReadBuffer) {
+      overlapping = regions_overlap(srcx, srcy, destx, desty, width, height,
+                                    ctx->Pixel.ZoomX, ctx->Pixel.ZoomY);
+   }
+   else {
+      overlapping = GL_FALSE;
+   }
 
-   _mesa_span_default_color(ctx, &span);
+   _swrast_span_default_color(ctx, &span);
    if (ctx->Fog.Enabled)
-      _mesa_span_default_fog(ctx, &span);
+      _swrast_span_default_fog(ctx, &span);
 
    if (overlapping) {
       GLint ssy = sy;
@@ -650,7 +667,7 @@ static void copy_depth_pixels( GLcontext *ctx, GLint srcx, GLint srcy,
       }
       p = tmpImage;
       for (j = 0; j < height; j++, ssy += stepy) {
-         _mesa_read_depth_span_float(ctx, width, srcx, ssy, p);
+         _swrast_read_depth_span_float(ctx, width, srcx, ssy, p);
          p += width;
       }
       p = tmpImage;
@@ -661,35 +678,39 @@ static void copy_depth_pixels( GLcontext *ctx, GLint srcx, GLint srcy,
    }
 
    for (j = 0; j < height; j++, sy += stepy, dy += stepy) {
+      GLfloat depth[MAX_WIDTH];
+
+      /* get depth values */
       if (overlapping) {
          MEMCPY(depth, p, width * sizeof(GLfloat));
          p += width;
       }
       else {
-         _mesa_read_depth_span_float(ctx, width, srcx, sy, depth);
+         _swrast_read_depth_span_float(ctx, width, srcx, sy, depth);
       }
 
+      /* apply scale and bias */
       for (i = 0; i < width; i++) {
          GLfloat d = depth[i] * ctx->Pixel.DepthScale + ctx->Pixel.DepthBias;
          span.array->z[i] = (GLdepth) (CLAMP(d, 0.0F, 1.0F) * ctx->DepthMax);
       }
 
+      /* write depth values */
       span.x = destx;
       span.y = dy;
       span.end = width;
       if (ctx->Visual.rgbMode) {
          if (zoom)
-            _mesa_write_zoomed_rgba_span( ctx, &span, 
-                                          (const GLchan (*)[4])span.array->rgba,
-                                          desty );
+            _swrast_write_zoomed_rgba_span( ctx, &span, 
+                            (const GLchan (*)[4])span.array->rgba, desty, 0 );
          else
-            _mesa_write_rgba_span(ctx, &span);
+            _swrast_write_rgba_span(ctx, &span);
       }
       else {
          if (zoom)
-            _mesa_write_zoomed_index_span( ctx, &span, desty );
+            _swrast_write_zoomed_index_span( ctx, &span, desty, 0 );
          else
-            _mesa_write_index_span(ctx, &span);
+            _swrast_write_index_span(ctx, &span);
       }
    }
 
@@ -699,9 +720,10 @@ static void copy_depth_pixels( GLcontext *ctx, GLint srcx, GLint srcy,
 
 
 
-static void copy_stencil_pixels( GLcontext *ctx, GLint srcx, GLint srcy,
-                                 GLint width, GLint height,
-                                 GLint destx, GLint desty )
+static void
+copy_stencil_pixels( GLcontext *ctx, GLint srcx, GLint srcy,
+                     GLint width, GLint height,
+                     GLint destx, GLint desty )
 {
    GLint sy, dy, stepy;
    GLint j;
@@ -729,8 +751,13 @@ static void copy_stencil_pixels( GLcontext *ctx, GLint srcx, GLint srcy,
       stepy = 1;
    }
 
-   overlapping = regions_overlap(srcx, srcy, destx, desty, width, height,
-                                 ctx->Pixel.ZoomX, ctx->Pixel.ZoomY);
+   if (ctx->DrawBuffer == ctx->ReadBuffer) {
+      overlapping = regions_overlap(srcx, srcy, destx, desty, width, height,
+                                    ctx->Pixel.ZoomX, ctx->Pixel.ZoomY);
+   }
+   else {
+      overlapping = GL_FALSE;
+   }
 
    if (overlapping) {
       GLint ssy = sy;
@@ -741,7 +768,7 @@ static void copy_stencil_pixels( GLcontext *ctx, GLint srcx, GLint srcy,
       }
       p = tmpImage;
       for (j = 0; j < height; j++, ssy += stepy) {
-         _mesa_read_stencil_span( ctx, width, srcx, ssy, p );
+         _swrast_read_stencil_span( ctx, width, srcx, ssy, p );
          p += width;
       }
       p = tmpImage;
@@ -754,14 +781,16 @@ static void copy_stencil_pixels( GLcontext *ctx, GLint srcx, GLint srcy,
    for (j = 0; j < height; j++, sy += stepy, dy += stepy) {
       GLstencil stencil[MAX_WIDTH];
 
+      /* Get stencil values */
       if (overlapping) {
          MEMCPY(stencil, p, width * sizeof(GLstencil));
          p += width;
       }
       else {
-         _mesa_read_stencil_span( ctx, width, srcx, sy, stencil );
+         _swrast_read_stencil_span( ctx, width, srcx, sy, stencil );
       }
 
+      /* Apply shift, offset, look-up table */
       if (shift_or_offset) {
          _mesa_shift_and_offset_stencil( ctx, width, stencil );
       }
@@ -769,11 +798,13 @@ static void copy_stencil_pixels( GLcontext *ctx, GLint srcx, GLint srcy,
          _mesa_map_stencil( ctx, width, stencil );
       }
 
+      /* Write stencil values */
       if (zoom) {
-         _mesa_write_zoomed_stencil_span( ctx, width, destx, dy, stencil, desty );
+         _swrast_write_zoomed_stencil_span( ctx, width, destx, dy,
+                                          stencil, desty, 0 );
       }
       else {
-         _mesa_write_stencil_span( ctx, width, destx, dy, stencil );
+         _swrast_write_stencil_span( ctx, width, destx, dy, stencil );
       }
    }
 
@@ -783,7 +814,6 @@ static void copy_stencil_pixels( GLcontext *ctx, GLint srcx, GLint srcy,
 
 
 
-
 void
 _swrast_CopyPixels( GLcontext *ctx,
                    GLint srcx, GLint srcy, GLsizei width, GLsizei height,