422{
423 GLubyte alphabase[2], alphause[2];
425 GLuint alphablockerror1, alphablockerror2, alphablockerror3;
427 GLubyte alphaenc1[16], alphaenc2[16], alphaenc3[16];
431
432
433 alphabase[0] = 0xff; alphabase[1] = 0x0;
434 for (
j = 0;
j < numypixels;
j++) {
435 for (
i = 0;
i < numxpixels;
i++) {
436 if (srccolors[
j][
i][3] == 0)
438 else if (srccolors[
j][
i][3] == 255)
440 else {
441 if (srccolors[
j][
i][3] > alphabase[1])
442 alphabase[1] = srccolors[
j][
i][3];
443 if (srccolors[
j][
i][3] < alphabase[0])
444 alphabase[0] = srccolors[
j][
i][3];
445 }
446 }
447 }
448
449
450 if ((alphabase[0] > alphabase[1]) && !(alphaabsmin && alphaabsmax)) {
451
452
453
454
455 *blkaddr++ = srccolors[0][0][3];
456 blkaddr++;
457 *blkaddr++ = 0;
458 *blkaddr++ = 0;
459 *blkaddr++ = 0;
460 *blkaddr++ = 0;
461 *blkaddr++ = 0;
462 *blkaddr++ = 0;
463
464 return;
465 }
466
467
468
469 alphablockerror1 = 0x0;
470 alphablockerror2 = 0xffffffff;
471 alphablockerror3 = 0xffffffff;
472 if (alphaabsmin) alphause[0] = 0;
473 else alphause[0] = alphabase[0];
474 if (alphaabsmax) alphause[1] = 255;
475 else alphause[1] = alphabase[1];
476
477 for (aindex = 0; aindex < 7; aindex++) {
478
479 acutValues[aindex] = (alphause[0] * (2*aindex + 1) + alphause[1] * (14 - (2*aindex + 1))) / 14;
480 }
481
482 for (
j = 0;
j < numypixels;
j++) {
483 for (
i = 0;
i < numxpixels;
i++) {
484
485
486 if (srccolors[
j][
i][3] > acutValues[0]) {
487 alphaenc1[4*
j +
i] = 0;
488 alphadist = srccolors[
j][
i][3] - alphause[1];
489 }
490 else if (srccolors[
j][
i][3] > acutValues[1]) {
491 alphaenc1[4*
j +
i] = 2;
492 alphadist = srccolors[
j][
i][3] - (alphause[1] * 6 + alphause[0] * 1) / 7;
493 }
494 else if (srccolors[
j][
i][3] > acutValues[2]) {
495 alphaenc1[4*
j +
i] = 3;
496 alphadist = srccolors[
j][
i][3] - (alphause[1] * 5 + alphause[0] * 2) / 7;
497 }
498 else if (srccolors[
j][
i][3] > acutValues[3]) {
499 alphaenc1[4*
j +
i] = 4;
500 alphadist = srccolors[
j][
i][3] - (alphause[1] * 4 + alphause[0] * 3) / 7;
501 }
502 else if (srccolors[
j][
i][3] > acutValues[4]) {
503 alphaenc1[4*
j +
i] = 5;
504 alphadist = srccolors[
j][
i][3] - (alphause[1] * 3 + alphause[0] * 4) / 7;
505 }
506 else if (srccolors[
j][
i][3] > acutValues[5]) {
507 alphaenc1[4*
j +
i] = 6;
508 alphadist = srccolors[
j][
i][3] - (alphause[1] * 2 + alphause[0] * 5) / 7;
509 }
510 else if (srccolors[
j][
i][3] > acutValues[6]) {
511 alphaenc1[4*
j +
i] = 7;
512 alphadist = srccolors[
j][
i][3] - (alphause[1] * 1 + alphause[0] * 6) / 7;
513 }
514 else {
515 alphaenc1[4*
j +
i] = 1;
516 alphadist = srccolors[
j][
i][3] - alphause[0];
517 }
518 alphablockerror1 += alphadist * alphadist;
519 }
520 }
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538 if (alphablockerror1 >= 32) {
539
540
541
542 alphablockerror2 = 0;
543 for (aindex = 0; aindex < 5; aindex++) {
544
545 acutValues[aindex] = (alphabase[0] * (10 - (2*aindex + 1)) + alphabase[1] * (2*aindex + 1)) / 10;
546 }
547 for (
j = 0;
j < numypixels;
j++) {
548 for (
i = 0;
i < numxpixels;
i++) {
549
550
551 if (srccolors[
j][
i][3] == 0) {
552 alphaenc2[4*
j +
i] = 6;
553 alphadist = 0;
554 }
555 else if (srccolors[
j][
i][3] == 255) {
556 alphaenc2[4*
j +
i] = 7;
557 alphadist = 0;
558 }
559 else if (srccolors[
j][
i][3] <= acutValues[0]) {
560 alphaenc2[4*
j +
i] = 0;
561 alphadist = srccolors[
j][
i][3] - alphabase[0];
562 }
563 else if (srccolors[
j][
i][3] <= acutValues[1]) {
564 alphaenc2[4*
j +
i] = 2;
565 alphadist = srccolors[
j][
i][3] - (alphabase[0] * 4 + alphabase[1] * 1) / 5;
566 }
567 else if (srccolors[
j][
i][3] <= acutValues[2]) {
568 alphaenc2[4*
j +
i] = 3;
569 alphadist = srccolors[
j][
i][3] - (alphabase[0] * 3 + alphabase[1] * 2) / 5;
570 }
571 else if (srccolors[
j][
i][3] <= acutValues[3]) {
572 alphaenc2[4*
j +
i] = 4;
573 alphadist = srccolors[
j][
i][3] - (alphabase[0] * 2 + alphabase[1] * 3) / 5;
574 }
575 else if (srccolors[
j][
i][3] <= acutValues[4]) {
576 alphaenc2[4*
j +
i] = 5;
577 alphadist = srccolors[
j][
i][3] - (alphabase[0] * 1 + alphabase[1] * 4) / 5;
578 }
579 else {
580 alphaenc2[4*
j +
i] = 1;
581 alphadist = srccolors[
j][
i][3] - alphabase[1];
582 }
583 alphablockerror2 += alphadist * alphadist;
584 }
585 }
586
587
588
589
590 if ((alphablockerror2 > 96) && (alphablockerror1 > 96)) {
594 GLubyte nralphainrangehigh = 0;
595 alphatest[0] = 0xff;
596 alphatest[1] = 0x0;
597
598 for (
j = 0;
j < numypixels;
j++) {
599 for (
i = 0;
i < numxpixels;
i++) {
600 if ((srccolors[
j][
i][3] > alphatest[1]) && (srccolors[
j][
i][3] < (255 -(alphabase[1] - alphabase[0]) / 28)))
601 alphatest[1] = srccolors[
j][
i][3];
602 if ((srccolors[
j][
i][3] < alphatest[0]) && (srccolors[
j][
i][3] > (alphabase[1] - alphabase[0]) / 28))
603 alphatest[0] = srccolors[
j][
i][3];
604 }
605 }
606
607 if (alphatest[1] <= alphatest[0]) {
608 alphatest[0] = 1;
609 alphatest[1] = 254;
610
611 }
612 for (aindex = 0; aindex < 5; aindex++) {
613
614 acutValues[aindex] = (alphatest[0] * (10 - (2*aindex + 1)) + alphatest[1] * (2*aindex + 1)) / 10;
615 }
616
617
618
619
620
621
622
623
624 for (
j = 0;
j < numypixels;
j++) {
625 for (
i = 0;
i < numxpixels;
i++) {
626 if (srccolors[
j][
i][3] <= alphatest[0] / 2) {
627 }
628 else if (srccolors[
j][
i][3] > ((255 + alphatest[1]) / 2)) {
629 }
630 else if (srccolors[
j][
i][3] <= acutValues[0]) {
631 blockerrlin1 += (srccolors[
j][
i][3] - alphatest[0]);
632 nralphainrangelow += 1;
633 }
634 else if (srccolors[
j][
i][3] <= acutValues[1]) {
635 blockerrlin1 += (srccolors[
j][
i][3] - (alphatest[0] * 4 + alphatest[1] * 1) / 5);
636 blockerrlin2 += (srccolors[
j][
i][3] - (alphatest[0] * 4 + alphatest[1] * 1) / 5);
637 nralphainrangelow += 1;
638 nralphainrangehigh += 1;
639 }
640 else if (srccolors[
j][
i][3] <= acutValues[2]) {
641 blockerrlin1 += (srccolors[
j][
i][3] - (alphatest[0] * 3 + alphatest[1] * 2) / 5);
642 blockerrlin2 += (srccolors[
j][
i][3] - (alphatest[0] * 3 + alphatest[1] * 2) / 5);
643 nralphainrangelow += 1;
644 nralphainrangehigh += 1;
645 }
646 else if (srccolors[
j][
i][3] <= acutValues[3]) {
647 blockerrlin1 += (srccolors[
j][
i][3] - (alphatest[0] * 2 + alphatest[1] * 3) / 5);
648 blockerrlin2 += (srccolors[
j][
i][3] - (alphatest[0] * 2 + alphatest[1] * 3) / 5);
649 nralphainrangelow += 1;
650 nralphainrangehigh += 1;
651 }
652 else if (srccolors[
j][
i][3] <= acutValues[4]) {
653 blockerrlin1 += (srccolors[
j][
i][3] - (alphatest[0] * 1 + alphatest[1] * 4) / 5);
654 blockerrlin2 += (srccolors[
j][
i][3] - (alphatest[0] * 1 + alphatest[1] * 4) / 5);
655 nralphainrangelow += 1;
656 nralphainrangehigh += 1;
657 }
658 else {
659 blockerrlin2 += (srccolors[
j][
i][3] - alphatest[1]);
660 nralphainrangehigh += 1;
661 }
662 }
663 }
664
665 if (nralphainrangelow == 0) nralphainrangelow = 1;
666 if (nralphainrangehigh == 0) nralphainrangehigh = 1;
667 alphatest[0] = alphatest[0] + (blockerrlin1 / nralphainrangelow);
668
669
670
671 if (alphatest[0] < 0) {
672 alphatest[0] = 0;
673
674 }
675 alphatest[1] = alphatest[1] + (blockerrlin2 / nralphainrangehigh);
676 if (alphatest[1] > 255) {
677 alphatest[1] = 255;
678
679 }
680
681 alphablockerror3 = 0;
682 for (aindex = 0; aindex < 5; aindex++) {
683
684 acutValues[aindex] = (alphatest[0] * (10 - (2*aindex + 1)) + alphatest[1] * (2*aindex + 1)) / 10;
685 }
686 for (
j = 0;
j < numypixels;
j++) {
687 for (
i = 0;
i < numxpixels;
i++) {
688
689
690 if (srccolors[
j][
i][3] <= alphatest[0] / 2) {
691 alphaenc3[4*
j +
i] = 6;
692 alphadist = srccolors[
j][
i][3];
693 }
694 else if (srccolors[
j][
i][3] > ((255 + alphatest[1]) / 2)) {
695 alphaenc3[4*
j +
i] = 7;
696 alphadist = 255 - srccolors[
j][
i][3];
697 }
698 else if (srccolors[
j][
i][3] <= acutValues[0]) {
699 alphaenc3[4*
j +
i] = 0;
700 alphadist = srccolors[
j][
i][3] - alphatest[0];
701 }
702 else if (srccolors[
j][
i][3] <= acutValues[1]) {
703 alphaenc3[4*
j +
i] = 2;
704 alphadist = srccolors[
j][
i][3] - (alphatest[0] * 4 + alphatest[1] * 1) / 5;
705 }
706 else if (srccolors[
j][
i][3] <= acutValues[2]) {
707 alphaenc3[4*
j +
i] = 3;
708 alphadist = srccolors[
j][
i][3] - (alphatest[0] * 3 + alphatest[1] * 2) / 5;
709 }
710 else if (srccolors[
j][
i][3] <= acutValues[3]) {
711 alphaenc3[4*
j +
i] = 4;
712 alphadist = srccolors[
j][
i][3] - (alphatest[0] * 2 + alphatest[1] * 3) / 5;
713 }
714 else if (srccolors[
j][
i][3] <= acutValues[4]) {
715 alphaenc3[4*
j +
i] = 5;
716 alphadist = srccolors[
j][
i][3] - (alphatest[0] * 1 + alphatest[1] * 4) / 5;
717 }
718 else {
719 alphaenc3[4*
j +
i] = 1;
720 alphadist = srccolors[
j][
i][3] - alphatest[1];
721 }
722 alphablockerror3 += alphadist * alphadist;
723 }
724 }
725 }
726 }
727
728 if ((alphablockerror1 <= alphablockerror2) && (alphablockerror1 <= alphablockerror3)) {
729
731 }
732 else if (alphablockerror2 <= alphablockerror3) {
733
735 }
736 else {
737
739 }
740}
static void writedxt5encodedalphablock(GLubyte *blkaddr, GLubyte alphabase1, GLubyte alphabase2, GLubyte alphaenc[16])
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint GLint GLint j