Ticket #37043: patch-ARB-glpng.c.diff
File patch-ARB-glpng.c.diff, 6.4 KB (added by mattcottrell, 12 years ago) |
---|
-
GL/glpng/glpng.c
old new 38 38 #include <png.h> 39 39 40 40 #if 0 41 #define PNG_CHECK_SIG(header,size) png_check_sig(header,size) // old libpng41 #define GLPNG_CHECK_SIG(header,size) png_check_sig(header,size) // old libpng 42 42 #else 43 #define PNG_CHECK_SIG(header,size) (png_sig_cmp(header,0,size)==0)43 #define GLPNG_CHECK_SIG(header,size) (png_sig_cmp(header,0,size)==0) 44 44 #endif 45 45 46 46 /* Used to decide if GL/gl.h supports the paletted extension */ … … 284 284 if (pinfo == NULL) return 0; 285 285 286 286 fread(header, 1, 8, fp); 287 if (! PNG_CHECK_SIG(header, 8)) return 0;287 if (!GLPNG_CHECK_SIG(header, 8)) return 0; 288 288 289 289 png = png_create_read_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL); 290 290 info = png_create_info_struct(png); 291 291 endinfo = png_create_info_struct(png); 292 292 293 293 // DH: added following lines 294 if (setjmp(png ->jmpbuf))294 if (setjmp(png_jmpbuf(png))) 295 295 { 296 296 png_destroy_read_struct(&png, &info, &endinfo); 297 297 return 0; … … 389 389 png_uint_32 i; 390 390 391 391 fread(header, 1, 8, fp); 392 if (! PNG_CHECK_SIG(header, 8)) return 0;392 if (!GLPNG_CHECK_SIG(header, 8)) return 0; 393 393 394 394 png = png_create_read_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL); 395 395 info = png_create_info_struct(png); … … 437 437 if (color == PNG_COLOR_TYPE_GRAY || color == PNG_COLOR_TYPE_GRAY_ALPHA) 438 438 png_set_gray_to_rgb(png); 439 439 440 if (color&PNG_COLOR_MASK_ALPHA && trans != PNG_ALPHA) {440 if (color&PNG_COLOR_MASK_ALPHA && trans != GLPNG_ALPHA) { 441 441 png_set_strip_alpha(png); 442 442 color &= ~PNG_COLOR_MASK_ALPHA; 443 443 } 444 444 445 if (!(PalettedTextures && mipmap >= 0 && trans == PNG_SOLID))445 if (!(PalettedTextures && mipmap >= 0 && trans == GLPNG_SOLID)) 446 446 if (color == PNG_COLOR_TYPE_PALETTE) 447 447 png_set_expand(png); 448 448 … … 493 493 glPixelStorei(GL_UNPACK_ALIGNMENT, 1); 494 494 495 495 #ifdef SUPPORTS_PALETTE_EXT 496 if (PalettedTextures && mipmap >= 0 && trans == PNG_SOLID && color == PNG_COLOR_TYPE_PALETTE) {496 if (PalettedTextures && mipmap >= 0 && trans == GLPNG_SOLID && color == PNG_COLOR_TYPE_PALETTE) { 497 497 png_colorp pal; 498 498 int cols; 499 499 GLint intf; … … 517 517 } 518 518 else 519 519 #endif 520 if (trans == PNG_SOLID || trans ==PNG_ALPHA || color == PNG_COLOR_TYPE_RGB_ALPHA || color == PNG_COLOR_TYPE_GRAY_ALPHA) {520 if (trans == GLPNG_SOLID || trans == GLPNG_ALPHA || color == PNG_COLOR_TYPE_RGB_ALPHA || color == PNG_COLOR_TYPE_GRAY_ALPHA) { 521 521 GLenum glformat; 522 522 GLint glcomponent; 523 523 … … 542 542 return 0; 543 543 } 544 544 545 if (mipmap == PNG_BUILDMIPMAPS)545 if (mipmap == GLPNG_BUILDMIPMAPS) 546 546 Build2DMipmaps(glcomponent, width, height, glformat, data, 1); 547 else if (mipmap == PNG_SIMPLEMIPMAPS)547 else if (mipmap == GLPNG_SIMPLEMIPMAPS) 548 548 Build2DMipmaps(glcomponent, width, height, glformat, data, 0); 549 549 else 550 550 glTexImage2D(GL_TEXTURE_2D, mipmap, glcomponent, width, height, 0, glformat, GL_UNSIGNED_BYTE, data); … … 574 574 #define ALPHA *q 575 575 576 576 switch (trans) { 577 case PNG_CALLBACK:577 case GLPNG_CALLBACK: 578 578 FORSTART 579 579 ALPHA = AlphaCallback((unsigned char) r, (unsigned char) g, (unsigned char) b); 580 580 FOREND 581 581 break; 582 582 583 case PNG_STENCIL:583 case GLPNG_STENCIL: 584 584 FORSTART 585 585 if (r == StencilRed && g == StencilGreen && b == StencilBlue) 586 586 ALPHA = 0; … … 589 589 FOREND 590 590 break; 591 591 592 case PNG_BLEND1:592 case GLPNG_BLEND1: 593 593 FORSTART 594 594 a = r+g+b; 595 595 if (a > 255) ALPHA = 255; else ALPHA = a; 596 596 FOREND 597 597 break; 598 598 599 case PNG_BLEND2:599 case GLPNG_BLEND2: 600 600 FORSTART 601 601 a = r+g+b; 602 602 if (a > 255*2) ALPHA = 255; else ALPHA = a/2; 603 603 FOREND 604 604 break; 605 605 606 case PNG_BLEND3:606 case GLPNG_BLEND3: 607 607 FORSTART 608 608 ALPHA = (r+g+b)/3; 609 609 FOREND 610 610 break; 611 611 612 case PNG_BLEND4:612 case GLPNG_BLEND4: 613 613 FORSTART 614 614 a = r*r+g*g+b*b; 615 615 if (a > 255) ALPHA = 255; else ALPHA = a; 616 616 FOREND 617 617 break; 618 618 619 case PNG_BLEND5:619 case GLPNG_BLEND5: 620 620 FORSTART 621 621 a = r*r+g*g+b*b; 622 622 if (a > 255*2) ALPHA = 255; else ALPHA = a/2; 623 623 FOREND 624 624 break; 625 625 626 case PNG_BLEND6:626 case GLPNG_BLEND6: 627 627 FORSTART 628 628 a = r*r+g*g+b*b; 629 629 if (a > 255*3) ALPHA = 255; else ALPHA = a/3; 630 630 FOREND 631 631 break; 632 632 633 case PNG_BLEND7:633 case GLPNG_BLEND7: 634 634 FORSTART 635 635 a = r*r+g*g+b*b; 636 636 if (a > 255*255) ALPHA = 255; else ALPHA = (int) sqrt(a); … … 642 642 #undef FOREND 643 643 #undef ALPHA 644 644 645 if (mipmap == PNG_BUILDMIPMAPS)645 if (mipmap == GLPNG_BUILDMIPMAPS) 646 646 Build2DMipmaps(4, width, height, GL_RGBA, data2, 1); 647 else if (mipmap == PNG_SIMPLEMIPMAPS)647 else if (mipmap == GLPNG_SIMPLEMIPMAPS) 648 648 Build2DMipmaps(4, width, height, GL_RGBA, data2, 0); 649 649 else 650 650 glTexImage2D(GL_TEXTURE_2D, mipmap, 4, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, data2);