Changeset 3598 for trunk/src/opengl/mesa/readpix.c
- Timestamp:
- May 23, 2000, 10:41:28 PM (25 years ago)
- 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:35jeroen Exp $ */1 /* $Id: readpix.c,v 1.3 2000-05-23 20:40:52 jeroen Exp $ */ 2 2 3 3 /* 4 4 * Mesa 3-D graphics library 5 * Version: 3. 15 * Version: 3.3 6 6 * 7 7 * Copyright (C) 1999 Brian Paul All Rights Reserved. … … 26 26 27 27 28 29 30 31 28 #ifdef PC_HEADER 32 29 #include "all.h" 33 30 #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" 41 32 #include "alphabuf.h" 42 33 #include "types.h" … … 50 41 #include "span.h" 51 42 #include "stencil.h" 43 #include "mem.h" 52 44 #endif 53 45 … … 61 53 GLint x, GLint y, 62 54 GLsizei width, GLsizei height, 63 55 GLenum type, GLvoid *pixels, 64 56 const struct gl_pixelstore_attrib *packing ) 65 57 { … … 72 64 } 73 65 74 (void) (*ctx->Driver.SetBuffer)( ctx, ctx->Pixel.DriverReadBuffer ); 66 ASSERT(ctx->Driver.SetReadBuffer); 67 (*ctx->Driver.SetReadBuffer)(ctx, ctx->ReadBuffer, ctx->Pixel.DriverReadBuffer); 75 68 76 69 readWidth = (width > MAX_WIDTH) ? MAX_WIDTH : width; … … 91 84 } 92 85 93 dest = gl_pixel_addr_in_image(packing, pixels,86 dest = _mesa_image_address(packing, pixels, 94 87 width, height, GL_COLOR_INDEX, type, 0, j, 0); 95 88 96 89 switch (type) { 97 98 90 case GL_UNSIGNED_BYTE: 91 { 99 92 GLubyte *dst = (GLubyte *) dest; 100 101 102 103 104 105 106 93 for (i=0;i<readWidth;i++) { 94 *dst++ = (GLubyte) index[i]; 95 } 96 } 97 break; 98 case GL_BYTE: 99 { 107 100 GLbyte *dst = (GLbyte *) dest; 108 109 110 111 112 113 114 101 for (i=0;i<readWidth;i++) { 102 dst[i] = (GLbyte) index[i]; 103 } 104 } 105 break; 106 case GL_UNSIGNED_SHORT: 107 { 115 108 GLushort *dst = (GLushort *) dest; 116 117 118 119 120 gl_swap2( (GLushort *) dst, readWidth );121 122 123 124 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 { 126 119 GLshort *dst = (GLshort *) dest; 127 128 129 130 131 gl_swap2( (GLushort *) dst, readWidth );132 133 134 135 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 { 137 130 GLuint *dst = (GLuint *) dest; 138 139 140 141 142 gl_swap4( (GLuint *) dst, readWidth );143 144 145 146 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 { 148 141 GLint *dst = (GLint *) dest; 149 150 151 152 153 gl_swap4( (GLuint *) dst, readWidth );154 155 156 157 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 { 159 152 GLfloat *dst = (GLfloat *) dest; 160 161 162 163 164 gl_swap4( (GLuint *) dst, readWidth );165 166 167 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; 168 161 default: 169 162 gl_error( ctx, GL_INVALID_ENUM, "glReadPixels(type)" ); … … 172 165 } 173 166 174 ( void) (*ctx->Driver.SetBuffer)( ctx, ctx->Color.DriverDrawBuffer);167 (*ctx->Driver.SetReadBuffer)(ctx, ctx->DrawBuffer, ctx->Color.DriverDrawBuffer); 175 168 } 176 169 … … 179 172 static void read_depth_pixels( GLcontext *ctx, 180 173 GLint x, GLint y, 181 182 174 GLsizei width, GLsizei height, 175 GLenum type, GLvoid *pixels, 183 176 const struct gl_pixelstore_attrib *packing ) 184 177 { … … 212 205 /* Special case: directly read 16-bit unsigned depth values. */ 213 206 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, 215 209 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 220 217 && !bias_or_scale && !packing->SwapBytes) { 221 218 /* 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 }229 219 for (j=0;j<height;j++,y++) { 230 GL uint *dst = (GLuint *) gl_pixel_addr_in_image( packing, pixels,220 GLdepth *dst = (GLdepth *) _mesa_image_address( packing, pixels, 231 221 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); 236 223 } 237 224 } … … 242 229 GLvoid *dest; 243 230 244 (*ctx->Driver.ReadDepthSpanFloat)( ctx, readWidth, x, y, depth);231 _mesa_read_depth_span_float(ctx, readWidth, x, y, depth); 245 232 246 233 if (bias_or_scale) { … … 252 239 } 253 240 254 dest = gl_pixel_addr_in_image(packing, pixels,241 dest = _mesa_image_address(packing, pixels, 255 242 width, height, GL_DEPTH_COMPONENT, type, 0, j, 0); 256 243 … … 279 266 } 280 267 if (packing->SwapBytes) { 281 gl_swap2( (GLushort *) dst, readWidth );268 _mesa_swap2( (GLushort *) dst, readWidth ); 282 269 } 283 270 } … … 290 277 } 291 278 if (packing->SwapBytes) { 292 gl_swap2( (GLushort *) dst, readWidth );279 _mesa_swap2( (GLushort *) dst, readWidth ); 293 280 } 294 281 } … … 301 288 } 302 289 if (packing->SwapBytes) { 303 gl_swap4( (GLuint *) dst, readWidth );290 _mesa_swap4( (GLuint *) dst, readWidth ); 304 291 } 305 292 } … … 312 299 } 313 300 if (packing->SwapBytes) { 314 gl_swap4( (GLuint *) dst, readWidth );301 _mesa_swap4( (GLuint *) dst, readWidth ); 315 302 } 316 303 } … … 323 310 } 324 311 if (packing->SwapBytes) { 325 gl_swap4( (GLuint *) dst, readWidth );312 _mesa_swap4( (GLuint *) dst, readWidth ); 326 313 } 327 314 } … … 339 326 static void read_stencil_pixels( GLcontext *ctx, 340 327 GLint x, GLint y, 341 342 328 GLsizei width, GLsizei height, 329 GLenum type, GLvoid *pixels, 343 330 const struct gl_pixelstore_attrib *packing ) 344 331 { … … 383 370 } 384 371 385 dest = gl_pixel_addr_in_image( packing, pixels,372 dest = _mesa_image_address( packing, pixels, 386 373 width, height, GL_STENCIL_INDEX, type, 0, j, 0 ); 387 374 388 375 switch (type) { 389 376 case GL_UNSIGNED_BYTE: 390 377 if (sizeof(GLstencil) == 8) { 391 378 MEMCPY( dest, stencil, readWidth ); … … 393 380 else { 394 381 GLubyte *dst = (GLubyte *) dest; 395 396 397 398 } 399 400 382 for (i=0;i<readWidth;i++) { 383 dst[i] = (GLubyte) stencil[i]; 384 } 385 } 386 break; 387 case GL_BYTE: 401 388 if (sizeof(GLstencil) == 8) { 402 389 MEMCPY( dest, stencil, readWidth ); … … 404 391 else { 405 392 GLbyte *dst = (GLbyte *) dest; 406 407 408 409 } 410 411 412 393 for (i=0;i<readWidth;i++) { 394 dst[i] = (GLbyte) stencil[i]; 395 } 396 } 397 break; 398 case GL_UNSIGNED_SHORT: 399 { 413 400 GLushort *dst = (GLushort *) dest; 414 415 416 417 418 gl_swap2( (GLushort *) dst, readWidth );419 420 421 422 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 { 424 411 GLshort *dst = (GLshort *) dest; 425 426 427 428 429 gl_swap2( (GLushort *) dst, readWidth );430 431 432 433 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 { 435 422 GLuint *dst = (GLuint *) dest; 436 437 438 439 440 gl_swap4( (GLuint *) dst, readWidth );441 442 443 444 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 { 446 433 GLint *dst = (GLint *) dest; 447 448 449 450 451 gl_swap4( (GLuint *) dst, readWidth );452 453 454 455 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 { 457 444 GLfloat *dst = (GLfloat *) dest; 458 459 460 461 462 gl_swap4( (GLuint *) dst, readWidth );463 464 465 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; 466 453 case GL_BITMAP: 467 454 if (packing->LsbFirst) { … … 538 525 539 526 /* 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); 547 534 if (readWidth <= 0) 548 535 return GL_TRUE; 549 536 550 537 /* 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); 558 545 if (readHeight <= 0) 559 546 return GL_TRUE; … … 602 589 GLint readWidth; 603 590 604 ( void) (*ctx->Driver.SetBuffer)( ctx, ctx->Pixel.DriverReadBuffer);591 (*ctx->Driver.SetReadBuffer)(ctx, ctx->ReadBuffer, ctx->Pixel.DriverReadBuffer); 605 592 606 593 /* Try optimized path first */ … … 608 595 format, type, pixels, packing )) { 609 596 610 ( void) (*ctx->Driver.SetBuffer)( ctx, ctx->Color.DriverDrawBuffer);597 (*ctx->Driver.SetReadBuffer)(ctx, ctx->DrawBuffer, ctx->Color.DriverDrawBuffer); 611 598 return; /* done! */ 612 599 } … … 642 629 } 643 630 644 if (! gl_is_legal_format_and_type(format, type)) {631 if (!_mesa_is_legal_format_and_type(format, type)) { 645 632 gl_error(ctx, GL_INVALID_OPERATION, "glReadPixels(format or type)"); 646 633 return; … … 653 640 GLvoid *dest; 654 641 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, 658 645 format, type, 0, j, 0); 659 646 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 ); 662 649 } 663 650 } … … 666 653 for (j=0;j<height;j++,y++) { 667 654 GLubyte rgba[MAX_WIDTH][4]; 668 655 GLuint index[MAX_WIDTH]; 669 656 GLvoid *dest; 670 657 671 672 673 658 (*ctx->Driver.ReadCI32Span)( ctx, readWidth, x, y, index ); 659 660 if (ctx->Pixel.IndexShift!=0 || ctx->Pixel.IndexOffset!=0) { 674 661 gl_map_ci( ctx, readWidth, index ); 675 662 } 676 663 677 664 gl_map_ci_to_rgba(ctx, readWidth, index, rgba ); 678 665 679 dest = gl_pixel_addr_in_image( packing, pixels, width, height,666 dest = _mesa_image_address( packing, pixels, width, height, 680 667 format, type, 0, j, 0); 681 668 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 ); 688 675 } 689 676 690 677 691 678 692 void gl_ReadPixels( GLcontext *ctx,693 694 679 void 680 _mesa_ReadPixels( GLint x, GLint y, GLsizei width, GLsizei height, 681 GLenum format, GLenum type, GLvoid *pixels ) 695 682 { 683 GET_CURRENT_CONTEXT(ctx); 696 684 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx, "glReadPixels"); 697 685 … … 701 689 } 702 690 691 if (ctx->Driver.ReadPixels && 692 (*ctx->Driver.ReadPixels)(ctx, x, y, width, height, 693 format, type, &ctx->Pack, pixels)) 694 return; 695 703 696 switch (format) { 704 697 case GL_COLOR_INDEX: 705 read_index_pixels( 706 698 read_index_pixels(ctx, x, y, width, height, type, pixels, &ctx->Pack ); 699 break; 707 700 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 ); 709 702 break; 710 703 case GL_DEPTH_COMPONENT: 711 read_depth_pixels(ctx, x, y, width, height, type, pixels, &ctx->Pack );712 704 read_depth_pixels(ctx, x, y, width, height, type, pixels, &ctx->Pack ); 705 break; 713 706 case GL_RED: 714 707 case GL_GREEN: … … 722 715 case GL_BGRA: 723 716 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; 726 720 default: 727 721 gl_error( ctx, GL_INVALID_ENUM, "glReadPixels(format)" ); 728 722 } 729 723 }
Note:
See TracChangeset
for help on using the changeset viewer.