Ignore:
Timestamp:
May 23, 2000, 10:41:28 PM (25 years ago)
Author:
jeroen
Message:

* empty log message *

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/opengl/mesa/readpix.c

    r2962 r3598  
    1 /* $Id: readpix.c,v 1.2 2000-03-01 18:49:35 jeroen Exp $ */
     1/* $Id: readpix.c,v 1.3 2000-05-23 20:40:52 jeroen Exp $ */
    22
    33/*
    44 * Mesa 3-D graphics library
    5  * Version:  3.1
     5 * Version:  3.3
    66 *
    77 * Copyright (C) 1999  Brian Paul   All Rights Reserved.
     
    2626
    2727
    28 
    29 
    30 
    3128#ifdef PC_HEADER
    3229#include "all.h"
    3330#else
    34 #ifndef XFree86Server
    35 #include <math.h>
    36 #include <stdlib.h>
    37 #include <string.h>
    38 #else
    39 #include "GL/xf86glx.h"
    40 #endif
     31#include "glheader.h"
    4132#include "alphabuf.h"
    4233#include "types.h"
     
    5041#include "span.h"
    5142#include "stencil.h"
     43#include "mem.h"
    5244#endif
    5345
     
    6153                               GLint x, GLint y,
    6254                               GLsizei width, GLsizei height,
    63                                GLenum type, GLvoid *pixels,
     55                               GLenum type, GLvoid *pixels,
    6456                               const struct gl_pixelstore_attrib *packing )
    6557{
     
    7264   }
    7365
    74    (void) (*ctx->Driver.SetBuffer)( ctx, ctx->Pixel.DriverReadBuffer );
     66   ASSERT(ctx->Driver.SetReadBuffer);
     67   (*ctx->Driver.SetReadBuffer)(ctx, ctx->ReadBuffer, ctx->Pixel.DriverReadBuffer);
    7568
    7669   readWidth = (width > MAX_WIDTH) ? MAX_WIDTH : width;
     
    9184      }
    9285
    93       dest = gl_pixel_addr_in_image(packing, pixels,
     86      dest = _mesa_image_address(packing, pixels,
    9487                         width, height, GL_COLOR_INDEX, type, 0, j, 0);
    9588
    9689      switch (type) {
    97         case GL_UNSIGNED_BYTE:
    98             {
     90        case GL_UNSIGNED_BYTE:
     91            {
    9992               GLubyte *dst = (GLubyte *) dest;
    100                for (i=0;i<readWidth;i++) {
    101                   *dst++ = (GLubyte) index[i];
    102                }
    103             }
    104             break;
    105         case GL_BYTE:
    106             {
     93               for (i=0;i<readWidth;i++) {
     94                  *dst++ = (GLubyte) index[i];
     95               }
     96            }
     97            break;
     98        case GL_BYTE:
     99            {
    107100               GLbyte *dst = (GLbyte *) dest;
    108                for (i=0;i<readWidth;i++) {
    109                   dst[i] = (GLbyte) index[i];
    110                }
    111             }
    112             break;
    113         case GL_UNSIGNED_SHORT:
    114             {
     101               for (i=0;i<readWidth;i++) {
     102                  dst[i] = (GLbyte) index[i];
     103               }
     104            }
     105            break;
     106        case GL_UNSIGNED_SHORT:
     107            {
    115108               GLushort *dst = (GLushort *) dest;
    116                for (i=0;i<readWidth;i++) {
    117                   dst[i] = (GLushort) index[i];
    118                }
    119                if (packing->SwapBytes) {
    120                   gl_swap2( (GLushort *) dst, readWidth );
    121                }
    122             }
    123             break;
    124         case GL_SHORT:
    125             {
     109               for (i=0;i<readWidth;i++) {
     110                  dst[i] = (GLushort) index[i];
     111               }
     112               if (packing->SwapBytes) {
     113                  _mesa_swap2( (GLushort *) dst, readWidth );
     114               }
     115            }
     116            break;
     117        case GL_SHORT:
     118            {
    126119               GLshort *dst = (GLshort *) dest;
    127                for (i=0;i<readWidth;i++) {
    128                   dst[i] = (GLshort) index[i];
    129                }
    130                if (packing->SwapBytes) {
    131                   gl_swap2( (GLushort *) dst, readWidth );
    132                }
    133             }
    134             break;
    135         case GL_UNSIGNED_INT:
    136             {
     120               for (i=0;i<readWidth;i++) {
     121                  dst[i] = (GLshort) index[i];
     122               }
     123               if (packing->SwapBytes) {
     124                  _mesa_swap2( (GLushort *) dst, readWidth );
     125               }
     126            }
     127            break;
     128        case GL_UNSIGNED_INT:
     129            {
    137130               GLuint *dst = (GLuint *) dest;
    138                for (i=0;i<readWidth;i++) {
    139                   dst[i] = (GLuint) index[i];
    140                }
    141                if (packing->SwapBytes) {
    142                   gl_swap4( (GLuint *) dst, readWidth );
    143                }
    144             }
    145             break;
    146         case GL_INT:
    147             {
     131               for (i=0;i<readWidth;i++) {
     132                  dst[i] = (GLuint) index[i];
     133               }
     134               if (packing->SwapBytes) {
     135                  _mesa_swap4( (GLuint *) dst, readWidth );
     136               }
     137            }
     138            break;
     139        case GL_INT:
     140            {
    148141               GLint *dst = (GLint *) dest;
    149                for (i=0;i<readWidth;i++) {
    150                   dst[i] = (GLint) index[i];
    151                }
    152                if (packing->SwapBytes) {
    153                   gl_swap4( (GLuint *) dst, readWidth );
    154                }
    155             }
    156             break;
    157         case GL_FLOAT:
    158             {
     142               for (i=0;i<readWidth;i++) {
     143                  dst[i] = (GLint) index[i];
     144               }
     145               if (packing->SwapBytes) {
     146                  _mesa_swap4( (GLuint *) dst, readWidth );
     147               }
     148            }
     149            break;
     150        case GL_FLOAT:
     151            {
    159152               GLfloat *dst = (GLfloat *) dest;
    160                for (i=0;i<readWidth;i++) {
    161                   dst[i] = (GLfloat) index[i];
    162                }
    163                if (packing->SwapBytes) {
    164                   gl_swap4( (GLuint *) dst, readWidth );
    165                }
    166             }
    167             break;
     153               for (i=0;i<readWidth;i++) {
     154                  dst[i] = (GLfloat) index[i];
     155               }
     156               if (packing->SwapBytes) {
     157                  _mesa_swap4( (GLuint *) dst, readWidth );
     158               }
     159            }
     160            break;
    168161         default:
    169162            gl_error( ctx, GL_INVALID_ENUM, "glReadPixels(type)" );
     
    172165   }
    173166
    174    (void) (*ctx->Driver.SetBuffer)( ctx, ctx->Color.DriverDrawBuffer );
     167   (*ctx->Driver.SetReadBuffer)(ctx, ctx->DrawBuffer, ctx->Color.DriverDrawBuffer);
    175168}
    176169
     
    179172static void read_depth_pixels( GLcontext *ctx,
    180173                               GLint x, GLint y,
    181                                GLsizei width, GLsizei height,
    182                                GLenum type, GLvoid *pixels,
     174                               GLsizei width, GLsizei height,
     175                               GLenum type, GLvoid *pixels,
    183176                               const struct gl_pixelstore_attrib *packing )
    184177{
     
    212205      /* Special case: directly read 16-bit unsigned depth values. */
    213206      for (j=0;j<height;j++,y++) {
    214          GLushort *dst = (GLushort*) gl_pixel_addr_in_image( packing, pixels,
     207         GLdepth depth[MAX_WIDTH];
     208         GLushort *dst = (GLushort*) _mesa_image_address( packing, pixels,
    215209                         width, height, GL_DEPTH_COMPONENT, type, 0, j, 0 );
    216          (*ctx->Driver.ReadDepthSpanInt)( ctx, width, x, y, (GLdepth*) dst);
    217       }
    218    }
    219    else if (type==GL_UNSIGNED_INT && sizeof(GLdepth)==sizeof(GLuint)
     210         GLint i;
     211         (*ctx->Driver.ReadDepthSpan)( ctx, width, x, y, depth);
     212         for (i = 0; i < width; i++)
     213            dst[i] = depth[i];
     214      }
     215   }
     216   else if (type==GL_UNSIGNED_INT && ctx->Visual->DepthBits == 32
    220217            && !bias_or_scale && !packing->SwapBytes) {
    221218      /* Special case: directly read 32-bit unsigned depth values. */
    222       /* Compute shift value to scale depth values up to 32-bit uints. */
    223       GLuint shift = 0;
    224       GLuint max = MAX_DEPTH;
    225       while ((max&0x80000000)==0) {
    226          max = max << 1;
    227          shift++;
    228       }
    229219      for (j=0;j<height;j++,y++) {
    230          GLuint *dst = (GLuint *) gl_pixel_addr_in_image( packing, pixels,
     220         GLdepth *dst = (GLdepth *) _mesa_image_address( packing, pixels,
    231221                         width, height, GL_DEPTH_COMPONENT, type, 0, j, 0 );
    232          (*ctx->Driver.ReadDepthSpanInt)( ctx, width, x, y, (GLdepth*) dst);
    233          for (i=0;i<width;i++) {
    234             dst[i] = dst[i] << shift;
    235          }
     222         (*ctx->Driver.ReadDepthSpan)( ctx, width, x, y, dst);
    236223      }
    237224   }
     
    242229         GLvoid *dest;
    243230
    244          (*ctx->Driver.ReadDepthSpanFloat)( ctx, readWidth, x, y, depth );
     231         _mesa_read_depth_span_float(ctx, readWidth, x, y, depth);
    245232
    246233         if (bias_or_scale) {
     
    252239         }
    253240
    254          dest = gl_pixel_addr_in_image(packing, pixels,
     241         dest = _mesa_image_address(packing, pixels,
    255242                         width, height, GL_DEPTH_COMPONENT, type, 0, j, 0);
    256243
     
    279266                  }
    280267                  if (packing->SwapBytes) {
    281                      gl_swap2( (GLushort *) dst, readWidth );
     268                     _mesa_swap2( (GLushort *) dst, readWidth );
    282269                  }
    283270               }
     
    290277                  }
    291278                  if (packing->SwapBytes) {
    292                      gl_swap2( (GLushort *) dst, readWidth );
     279                     _mesa_swap2( (GLushort *) dst, readWidth );
    293280                  }
    294281               }
     
    301288                  }
    302289                  if (packing->SwapBytes) {
    303                      gl_swap4( (GLuint *) dst, readWidth );
     290                     _mesa_swap4( (GLuint *) dst, readWidth );
    304291                  }
    305292               }
     
    312299                  }
    313300                  if (packing->SwapBytes) {
    314                      gl_swap4( (GLuint *) dst, readWidth );
     301                     _mesa_swap4( (GLuint *) dst, readWidth );
    315302                  }
    316303               }
     
    323310                  }
    324311                  if (packing->SwapBytes) {
    325                      gl_swap4( (GLuint *) dst, readWidth );
     312                     _mesa_swap4( (GLuint *) dst, readWidth );
    326313                  }
    327314               }
     
    339326static void read_stencil_pixels( GLcontext *ctx,
    340327                                 GLint x, GLint y,
    341                                 GLsizei width, GLsizei height,
    342                                 GLenum type, GLvoid *pixels,
     328                                GLsizei width, GLsizei height,
     329                                GLenum type, GLvoid *pixels,
    343330                                 const struct gl_pixelstore_attrib *packing )
    344331{
     
    383370      }
    384371
    385       dest = gl_pixel_addr_in_image( packing, pixels,
     372      dest = _mesa_image_address( packing, pixels,
    386373                          width, height, GL_STENCIL_INDEX, type, 0, j, 0 );
    387374
    388375      switch (type) {
    389         case GL_UNSIGNED_BYTE:
     376        case GL_UNSIGNED_BYTE:
    390377            if (sizeof(GLstencil) == 8) {
    391378               MEMCPY( dest, stencil, readWidth );
     
    393380            else {
    394381               GLubyte *dst = (GLubyte *) dest;
    395                for (i=0;i<readWidth;i++) {
    396                   dst[i] = (GLubyte) stencil[i];
    397                }
    398             }
    399             break;
    400         case GL_BYTE:
     382               for (i=0;i<readWidth;i++) {
     383                  dst[i] = (GLubyte) stencil[i];
     384               }
     385            }
     386            break;
     387        case GL_BYTE:
    401388            if (sizeof(GLstencil) == 8) {
    402389               MEMCPY( dest, stencil, readWidth );
     
    404391            else {
    405392               GLbyte *dst = (GLbyte *) dest;
    406                for (i=0;i<readWidth;i++) {
    407                   dst[i] = (GLbyte) stencil[i];
    408                }
    409             }
    410             break;
    411         case GL_UNSIGNED_SHORT:
    412             {
     393               for (i=0;i<readWidth;i++) {
     394                  dst[i] = (GLbyte) stencil[i];
     395               }
     396            }
     397            break;
     398        case GL_UNSIGNED_SHORT:
     399            {
    413400               GLushort *dst = (GLushort *) dest;
    414                for (i=0;i<readWidth;i++) {
    415                   dst[i] = (GLushort) stencil[i];
    416                }
    417                if (packing->SwapBytes) {
    418                   gl_swap2( (GLushort *) dst, readWidth );
    419                }
    420             }
    421             break;
    422         case GL_SHORT:
    423             {
     401               for (i=0;i<readWidth;i++) {
     402                  dst[i] = (GLushort) stencil[i];
     403               }
     404               if (packing->SwapBytes) {
     405                  _mesa_swap2( (GLushort *) dst, readWidth );
     406               }
     407            }
     408            break;
     409        case GL_SHORT:
     410            {
    424411               GLshort *dst = (GLshort *) dest;
    425                for (i=0;i<readWidth;i++) {
    426                   dst[i] = (GLshort) stencil[i];
    427                }
    428                if (packing->SwapBytes) {
    429                   gl_swap2( (GLushort *) dst, readWidth );
    430                }
    431             }
    432             break;
    433         case GL_UNSIGNED_INT:
    434             {
     412               for (i=0;i<readWidth;i++) {
     413                  dst[i] = (GLshort) stencil[i];
     414               }
     415               if (packing->SwapBytes) {
     416                  _mesa_swap2( (GLushort *) dst, readWidth );
     417               }
     418            }
     419            break;
     420        case GL_UNSIGNED_INT:
     421            {
    435422               GLuint *dst = (GLuint *) dest;
    436                for (i=0;i<readWidth;i++) {
    437                   dst[i] = (GLuint) stencil[i];
    438                }
    439                if (packing->SwapBytes) {
    440                   gl_swap4( (GLuint *) dst, readWidth );
    441                }
    442             }
    443             break;
    444         case GL_INT:
    445             {
     423               for (i=0;i<readWidth;i++) {
     424                  dst[i] = (GLuint) stencil[i];
     425               }
     426               if (packing->SwapBytes) {
     427                  _mesa_swap4( (GLuint *) dst, readWidth );
     428               }
     429            }
     430            break;
     431        case GL_INT:
     432            {
    446433               GLint *dst = (GLint *) dest;
    447                for (i=0;i<readWidth;i++) {
    448                   *dst++ = (GLint) stencil[i];
    449                }
    450                if (packing->SwapBytes) {
    451                   gl_swap4( (GLuint *) dst, readWidth );
    452                }
    453             }
    454             break;
    455         case GL_FLOAT:
    456             {
     434               for (i=0;i<readWidth;i++) {
     435                  *dst++ = (GLint) stencil[i];
     436               }
     437               if (packing->SwapBytes) {
     438                  _mesa_swap4( (GLuint *) dst, readWidth );
     439               }
     440            }
     441            break;
     442        case GL_FLOAT:
     443            {
    457444               GLfloat *dst = (GLfloat *) dest;
    458                for (i=0;i<readWidth;i++) {
    459                   dst[i] = (GLfloat) stencil[i];
    460                }
    461                if (packing->SwapBytes) {
    462                   gl_swap4( (GLuint *) dst, readWidth );
    463                }
    464             }
    465             break;
     445               for (i=0;i<readWidth;i++) {
     446                  dst[i] = (GLfloat) stencil[i];
     447               }
     448               if (packing->SwapBytes) {
     449                  _mesa_swap4( (GLuint *) dst, readWidth );
     450               }
     451            }
     452            break;
    466453         case GL_BITMAP:
    467454            if (packing->LsbFirst) {
     
    538525
    539526      /* horizontal clipping */
    540       if (srcX < ctx->Buffer->Xmin) {
    541          skipPixels += (ctx->Buffer->Xmin - srcX);
    542          readWidth  -= (ctx->Buffer->Xmin - srcX);
    543          srcX = ctx->Buffer->Xmin;
    544       }
    545       if (srcX + readWidth > ctx->Buffer->Xmax)
    546          readWidth -= (srcX + readWidth - ctx->Buffer->Xmax - 1);
     527      if (srcX < ctx->ReadBuffer->Xmin) {
     528         skipPixels += (ctx->ReadBuffer->Xmin - srcX);
     529         readWidth  -= (ctx->ReadBuffer->Xmin - srcX);
     530         srcX = ctx->ReadBuffer->Xmin;
     531      }
     532      if (srcX + readWidth > ctx->ReadBuffer->Xmax)
     533         readWidth -= (srcX + readWidth - ctx->ReadBuffer->Xmax - 1);
    547534      if (readWidth <= 0)
    548535         return GL_TRUE;
    549536
    550537      /* vertical clipping */
    551       if (srcY < ctx->Buffer->Ymin) {
    552          skipRows   += (ctx->Buffer->Ymin - srcY);
    553          readHeight -= (ctx->Buffer->Ymin - srcY);
    554          srcY = ctx->Buffer->Ymin;
    555       }
    556       if (srcY + readHeight > ctx->Buffer->Ymax)
    557          readHeight -= (srcY + readHeight - ctx->Buffer->Ymax - 1);
     538      if (srcY < ctx->ReadBuffer->Ymin) {
     539         skipRows   += (ctx->ReadBuffer->Ymin - srcY);
     540         readHeight -= (ctx->ReadBuffer->Ymin - srcY);
     541         srcY = ctx->ReadBuffer->Ymin;
     542      }
     543      if (srcY + readHeight > ctx->ReadBuffer->Ymax)
     544         readHeight -= (srcY + readHeight - ctx->ReadBuffer->Ymax - 1);
    558545      if (readHeight <= 0)
    559546         return GL_TRUE;
     
    602589   GLint readWidth;
    603590
    604    (void) (*ctx->Driver.SetBuffer)( ctx, ctx->Pixel.DriverReadBuffer );
     591   (*ctx->Driver.SetReadBuffer)(ctx, ctx->ReadBuffer, ctx->Pixel.DriverReadBuffer);
    605592
    606593   /* Try optimized path first */
     
    608595                              format, type, pixels, packing )) {
    609596
    610       (void) (*ctx->Driver.SetBuffer)( ctx, ctx->Color.DriverDrawBuffer );
     597      (*ctx->Driver.SetReadBuffer)(ctx, ctx->DrawBuffer, ctx->Color.DriverDrawBuffer);
    611598      return; /* done! */
    612599   }
     
    642629   }
    643630
    644    if (!gl_is_legal_format_and_type(format, type)) {
     631   if (!_mesa_is_legal_format_and_type(format, type)) {
    645632      gl_error(ctx, GL_INVALID_OPERATION, "glReadPixels(format or type)");
    646633      return;
     
    653640         GLvoid *dest;
    654641
    655          gl_read_rgba_span( ctx, readWidth, x, y, rgba );
    656 
    657          dest = gl_pixel_addr_in_image( packing, pixels, width, height,
     642         gl_read_rgba_span( ctx, ctx->ReadBuffer, readWidth, x, y, rgba );
     643
     644         dest = _mesa_image_address( packing, pixels, width, height,
    658645                                        format, type, 0, j, 0);
    659646
    660          gl_pack_rgba_span( ctx, readWidth, (const GLubyte (*)[4]) rgba,
    661                             format, type, dest, packing, GL_TRUE );
     647         _mesa_pack_rgba_span( ctx, readWidth, (const GLubyte (*)[4]) rgba,
     648                               format, type, dest, packing, GL_TRUE );
    662649      }
    663650   }
     
    666653      for (j=0;j<height;j++,y++) {
    667654         GLubyte rgba[MAX_WIDTH][4];
    668         GLuint index[MAX_WIDTH];
     655        GLuint index[MAX_WIDTH];
    669656         GLvoid *dest;
    670657
    671         (*ctx->Driver.ReadCI32Span)( ctx, readWidth, x, y, index );
    672 
    673         if (ctx->Pixel.IndexShift!=0 || ctx->Pixel.IndexOffset!=0) {
     658        (*ctx->Driver.ReadCI32Span)( ctx, readWidth, x, y, index );
     659
     660        if (ctx->Pixel.IndexShift!=0 || ctx->Pixel.IndexOffset!=0) {
    674661            gl_map_ci( ctx, readWidth, index );
    675         }
     662        }
    676663
    677664         gl_map_ci_to_rgba(ctx, readWidth, index, rgba );
    678665
    679          dest = gl_pixel_addr_in_image( packing, pixels, width, height,
     666         dest = _mesa_image_address( packing, pixels, width, height,
    680667                                        format, type, 0, j, 0);
    681668
    682          gl_pack_rgba_span( ctx, readWidth, (const GLubyte (*)[4]) rgba,
    683                             format, type, dest, packing, GL_TRUE );
    684       }
    685    }
    686 
    687    (void) (*ctx->Driver.SetBuffer)( ctx, ctx->Color.DriverDrawBuffer );
     669         _mesa_pack_rgba_span( ctx, readWidth, (const GLubyte (*)[4]) rgba,
     670                               format, type, dest, packing, GL_TRUE );
     671      }
     672   }
     673
     674   (*ctx->Driver.SetReadBuffer)( ctx, ctx->DrawBuffer, ctx->Color.DriverDrawBuffer );
    688675}
    689676
    690677
    691678
    692 void gl_ReadPixels( GLcontext *ctx,
    693                     GLint x, GLint y, GLsizei width, GLsizei height,
    694                     GLenum format, GLenum type, GLvoid *pixels )
     679void
     680_mesa_ReadPixels( GLint x, GLint y, GLsizei width, GLsizei height,
     681                  GLenum format, GLenum type, GLvoid *pixels )
    695682{
     683   GET_CURRENT_CONTEXT(ctx);
    696684   ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx, "glReadPixels");
    697685
     
    701689   }
    702690
     691   if (ctx->Driver.ReadPixels &&
     692       (*ctx->Driver.ReadPixels)(ctx, x, y, width, height,
     693                                 format, type, &ctx->Pack, pixels))
     694      return;
     695
    703696   switch (format) {
    704697      case GL_COLOR_INDEX:
    705          read_index_pixels( ctx, x, y, width, height, type, pixels, &ctx->Pack );
    706         break;
     698         read_index_pixels(ctx, x, y, width, height, type, pixels, &ctx->Pack );
     699        break;
    707700      case GL_STENCIL_INDEX:
    708          read_stencil_pixels( ctx, x, y, width, height, type, pixels, &ctx->Pack );
     701         read_stencil_pixels(ctx, x, y, width, height, type, pixels, &ctx->Pack );
    709702         break;
    710703      case GL_DEPTH_COMPONENT:
    711          read_depth_pixels( ctx, x, y, width, height, type, pixels, &ctx->Pack );
    712         break;
     704         read_depth_pixels(ctx, x, y, width, height, type, pixels, &ctx->Pack );
     705        break;
    713706      case GL_RED:
    714707      case GL_GREEN:
     
    722715      case GL_BGRA:
    723716      case GL_ABGR_EXT:
    724          read_rgba_pixels( ctx, x, y, width, height, format, type, pixels, &ctx->Pack );
    725          break;
     717         read_rgba_pixels(ctx, x, y, width, height,
     718                          format, type, pixels, &ctx->Pack );
     719         break;
    726720      default:
    727         gl_error( ctx, GL_INVALID_ENUM, "glReadPixels(format)" );
     721        gl_error( ctx, GL_INVALID_ENUM, "glReadPixels(format)" );
    728722   }
    729723}
Note: See TracChangeset for help on using the changeset viewer.