GL_MESA_pack_invert
authorBrian Paul <brian.paul@tungstengraphics.com>
Sat, 21 Sep 2002 17:34:56 +0000 (17:34 +0000)
committerBrian Paul <brian.paul@tungstengraphics.com>
Sat, 21 Sep 2002 17:34:56 +0000 (17:34 +0000)
src/mesa/main/extensions.c
src/mesa/main/get.c
src/mesa/main/image.c
src/mesa/main/mtypes.h
src/mesa/main/pixel.c
src/mesa/swrast/s_readpix.c

index d7b311e8af1ccd2e958cf85df42c2323caf186bc..056039743194a8411e819361ee89df4d4a4f8974 100644 (file)
@@ -1,4 +1,4 @@
-/* $Id: extensions.c,v 1.79 2002/09/21 16:51:25 brianp Exp $ */
+/* $Id: extensions.c,v 1.80 2002/09/21 17:34:56 brianp Exp $ */
 
 /*
  * Mesa 3-D graphics library
@@ -111,6 +111,7 @@ static struct {
    { ON,  "GL_IBM_rasterpos_clip",             F(IBM_rasterpos_clip) },
    { OFF, "GL_IBM_texture_mirrored_repeat",    F(ARB_texture_mirrored_repeat)},
    { OFF, "GL_INGR_blend_func_separate",       F(INGR_blend_func_separate) },
+   { OFF, "GL_MESA_pack_invert",               F(MESA_pack_invert) },
    { OFF, "GL_MESA_packed_depth_stencil",      0 },
    { OFF, "GL_MESA_resize_buffers",            F(MESA_resize_buffers) },
    { OFF, "GL_MESA_ycbcr_texture",             F(MESA_ycbcr_texture) },
@@ -183,6 +184,7 @@ _mesa_enable_sw_extensions(GLcontext *ctx)
       "GL_HP_occlusion_test",
       "GL_IBM_texture_mirrored_repeat",
       "GL_INGR_blend_func_separate",
+      "GL_MESA_pack_invert",
       "GL_MESA_resize_buffers",
       "GL_MESA_ycbcr_texture",
       "GL_NV_blend_square",
index 115a4be85f82718094074fbcc5e2403392ea0e4f..4ccec6b9d81f7b484b49f9a62ce1cb0a622ea6d6 100644 (file)
@@ -1,4 +1,4 @@
-/* $Id: get.c,v 1.90 2002/09/06 13:00:50 brianp Exp $ */
+/* $Id: get.c,v 1.91 2002/09/21 17:34:56 brianp Exp $ */
 
 /*
  * Mesa 3-D graphics library
@@ -659,6 +659,9 @@ _mesa_GetBooleanv( GLenum pname, GLboolean *params )
       case GL_PACK_IMAGE_HEIGHT_EXT:
          *params = ctx->Pack.ImageHeight;
          break;
+      case GL_PACK_INVERT_MESA:
+         *params = ctx->Pack.Invert;
+         break;
       case GL_PERSPECTIVE_CORRECTION_HINT:
         *params = ENUM_TO_BOOL(ctx->Hint.PerspectiveCorrection);
         break;
@@ -2018,6 +2021,9 @@ _mesa_GetDoublev( GLenum pname, GLdouble *params )
       case GL_PACK_IMAGE_HEIGHT_EXT:
          *params = (GLdouble) ctx->Pack.ImageHeight;
          break;
+      case GL_PACK_INVERT_MESA:
+         *params = (GLdouble) ctx->Pack.Invert;
+         break;
       case GL_PERSPECTIVE_CORRECTION_HINT:
         *params = ENUM_TO_DOUBLE(ctx->Hint.PerspectiveCorrection);
         break;
@@ -3374,6 +3380,9 @@ _mesa_GetFloatv( GLenum pname, GLfloat *params )
       case GL_PACK_IMAGE_HEIGHT_EXT:
          *params = (GLfloat) ctx->Pack.ImageHeight;
          break;
+      case GL_PACK_INVERT_MESA:
+         *params = (GLfloat) ctx->Pack.Invert;
+         break;
       case GL_PERSPECTIVE_CORRECTION_HINT:
         *params = ENUM_TO_FLOAT(ctx->Hint.PerspectiveCorrection);
         break;
@@ -4707,6 +4716,9 @@ _mesa_GetIntegerv( GLenum pname, GLint *params )
       case GL_PACK_IMAGE_HEIGHT_EXT:
          *params = ctx->Pack.ImageHeight;
          break;
+      case GL_PACK_INVERT_MESA:
+         *params = ctx->Pack.Invert;
+         break;
       case GL_PERSPECTIVE_CORRECTION_HINT:
         *params = (GLint) ctx->Hint.PerspectiveCorrection;
         break;
index 71ed77fceabd946e04cf345545c0ef63c851a2b4..e881b79ca48542e51178e88b3ff398ebb91e0a66 100644 (file)
@@ -1,4 +1,4 @@
-/* $Id: image.c,v 1.67 2002/09/21 16:51:25 brianp Exp $ */
+/* $Id: image.c,v 1.68 2002/09/21 17:34:56 brianp Exp $ */
 
 /*
  * Mesa 3-D graphics library
@@ -58,7 +58,8 @@ const struct gl_pixelstore_attrib _mesa_native_packing = {
    0,            /* SkipImages */
    GL_FALSE,     /* SwapBytes */
    GL_FALSE,     /* LsbFirst */
-   GL_FALSE      /* ClientStorage */
+   GL_FALSE,     /* ClientStorage */
+   GL_FALSE      /* Invert */
 };
 
 
@@ -494,6 +495,7 @@ _mesa_image_address( const struct gl_pixelstore_attrib *packing,
    else {
       /* Non-BITMAP data */
       GLint bytes_per_pixel, bytes_per_row, remainder, bytes_per_image;
+      GLint topOfImage;
 
       bytes_per_pixel = _mesa_bytes_per_pixel( format, type );
 
@@ -509,9 +511,19 @@ _mesa_image_address( const struct gl_pixelstore_attrib *packing,
 
       bytes_per_image = bytes_per_row * rows_per_image;
 
+      if (packing->Invert) {
+         /* set pixel_addr to the last row */
+         topOfImage = bytes_per_row * (height - 1);
+         bytes_per_row = -bytes_per_row;
+      }
+      else {
+         topOfImage = 0;
+      }
+
       /* compute final pixel address */
       pixel_addr = (GLubyte *) image
                  + (skipimages + img) * bytes_per_image
+                 + topOfImage
                  + (skiprows + row) * bytes_per_row
                  + (skippixels + column) * bytes_per_pixel;
    }
@@ -532,14 +544,18 @@ _mesa_image_row_stride( const struct gl_pixelstore_attrib *packing,
    ASSERT(packing);
    if (type == GL_BITMAP) {
       /* BITMAP data */
+      GLint bytes;
       if (packing->RowLength == 0) {
-         GLint bytes = (width + 7) / 8;
-         return bytes;
+         bytes = (width + 7) / 8;
       }
       else {
-         GLint bytes = (packing->RowLength + 7) / 8;
-         return bytes;
+         bytes = (packing->RowLength + 7) / 8;
+      }
+      if (packing->Invert) {
+         /* negate the bytes per row (negative row stride) */
+         bytes = -bytes;
       }
+      return bytes;
    }
    else {
       /* Non-BITMAP data */
@@ -556,6 +572,8 @@ _mesa_image_row_stride( const struct gl_pixelstore_attrib *packing,
       remainder = bytesPerRow % packing->Alignment;
       if (remainder > 0)
          bytesPerRow += (packing->Alignment - remainder);
+      if (packing->Invert)
+         bytesPerRow = -bytesPerRow;
       return bytesPerRow;
    }
 }
index 9b6be650785c6cfcf7aa59e1a1a6307bbd840884..3b94967e08ec0f01227340e080e0d4e06f5ea3cd 100644 (file)
@@ -1,4 +1,4 @@
-/* $Id: mtypes.h,v 1.86 2002/09/21 16:51:25 brianp Exp $ */
+/* $Id: mtypes.h,v 1.87 2002/09/21 17:34:56 brianp Exp $ */
 
 /*
  * Mesa 3-D graphics library
@@ -1045,6 +1045,7 @@ struct gl_pixelstore_attrib {
    GLboolean SwapBytes;
    GLboolean LsbFirst;
    GLboolean ClientStorage; /* GL_APPLE_client_storage */
+   GLboolean Invert;        /* GL_MESA_pack_invert */
 };
 
 
@@ -1434,6 +1435,7 @@ struct gl_extensions {
    GLboolean HP_occlusion_test;
    GLboolean IBM_rasterpos_clip;
    GLboolean INGR_blend_func_separate;
+   GLboolean MESA_pack_invert;
    GLboolean MESA_window_pos;
    GLboolean MESA_resize_buffers;
    GLboolean MESA_ycbcr_texture;
index 852215730479ee8f3124d6de253b014ca8bc045b..ce1b2c57c2d1eca4085543117f625cf8386f8d4a 100644 (file)
@@ -1,4 +1,4 @@
-/* $Id: pixel.c,v 1.35 2002/09/21 16:51:25 brianp Exp $ */
+/* $Id: pixel.c,v 1.36 2002/09/21 17:34:56 brianp Exp $ */
 
 /*
  * Mesa 3-D graphics library
@@ -146,6 +146,17 @@ _mesa_PixelStorei( GLenum pname, GLint param )
         FLUSH_VERTICES(ctx, _NEW_PACKUNPACK);
         ctx->Pack.Alignment = param;
         break;
+      case GL_PACK_INVERT_MESA:
+         if (!ctx->Extensions.MESA_pack_invert) {
+            _mesa_error( ctx, GL_INVALID_ENUM, "glPixelstore(pname)" );
+            return;
+         }
+         if (ctx->Pack.Invert == param)
+            return;
+         FLUSH_VERTICES(ctx, _NEW_PACKUNPACK);
+         ctx->Pack.Invert = param;
+         break;
+
       case GL_UNPACK_SWAP_BYTES:
         if (param == (GLint)ctx->Unpack.SwapBytes)
            return;
index f925e7911624ee9fe6ecf8dcca0f0a19ab409ac1..562d87184630206e3f98d24b19723149415ad46b 100644 (file)
@@ -1,4 +1,4 @@
-/* $Id: s_readpix.c,v 1.15 2002/07/09 01:22:52 brianp Exp $ */
+/* $Id: s_readpix.c,v 1.16 2002/09/21 17:34:56 brianp Exp $ */
 
 /*
  * Mesa 3-D graphics library
@@ -279,8 +279,15 @@ read_fast_rgba_pixels( GLcontext *ctx,
       if (0) {
 #endif
          GLchan *dest = (GLchan *) pixels
-                         + (skipRows * rowLength + skipPixels) * 4;
+                      + (skipRows * rowLength + skipPixels) * 4;
          GLint row;
+
+         if (packing->Invert) {
+            /* start at top and go down */
+            dest += (readHeight - 1) * rowLength * 4;
+            rowLength = -rowLength;
+         }
+
          for (row=0; row<readHeight; row++) {
             (*swrast->Driver.ReadRGBASpan)(ctx, readWidth, srcX, srcY,
                                         (GLchan (*)[4]) dest);