OLD | NEW |
1 // Copyright 2014 PDFium Authors. All rights reserved. | 1 // Copyright 2014 PDFium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com | 5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com |
6 | 6 |
7 #include <limits.h> | 7 #include <limits.h> |
8 | 8 |
9 #include "core/fxcodec/jbig2/JBig2_Image.h" | 9 #include "core/fxcodec/jbig2/JBig2_Image.h" |
10 #include "core/include/fxcrt/fx_coordinates.h" | 10 #include "core/include/fxcrt/fx_coordinates.h" |
(...skipping 647 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
658 } | 658 } |
659 } | 659 } |
660 } | 660 } |
661 return 1; | 661 return 1; |
662 } | 662 } |
663 FX_BOOL CJBig2_Image::composeTo_opt2(CJBig2_Image* pDst, | 663 FX_BOOL CJBig2_Image::composeTo_opt2(CJBig2_Image* pDst, |
664 int32_t x, | 664 int32_t x, |
665 int32_t y, | 665 int32_t y, |
666 JBig2ComposeOp op, | 666 JBig2ComposeOp op, |
667 const FX_RECT* pSrcRect) { | 667 const FX_RECT* pSrcRect) { |
668 int32_t xs0, ys0, xs1, ys1, xd0, yd0, xd1, yd1, xx, yy, w, h, middleDwords, | |
669 lineLeft; | |
670 FX_DWORD s1, d1, d2, shift, shift1, shift2, tmp, tmp1, tmp2, maskL, maskR, | |
671 maskM; | |
672 uint8_t *lineSrc, *lineDst, *sp, *dp; | |
673 int32_t sw, sh; | |
674 if (!m_pData) { | 668 if (!m_pData) { |
675 return FALSE; | 669 return FALSE; |
676 } | 670 } |
| 671 // TODO(weili): Check whether the range check is correct. Should x>=1048576? |
677 if (x < -1048576 || x > 1048576 || y < -1048576 || y > 1048576) { | 672 if (x < -1048576 || x > 1048576 || y < -1048576 || y > 1048576) { |
678 return FALSE; | 673 return FALSE; |
679 } | 674 } |
680 sw = pSrcRect->Width(); | 675 int32_t sw = pSrcRect->Width(); |
681 sh = pSrcRect->Height(); | 676 int32_t sh = pSrcRect->Height(); |
682 if (y < 0) { | 677 int32_t ys0 = y < 0 ? -y : 0; |
683 ys0 = -y; | 678 int32_t ys1 = y + sh > pDst->m_nHeight ? pDst->m_nHeight - y : sh; |
684 } else { | 679 int32_t xs0 = x < 0 ? -x : 0; |
685 ys0 = 0; | 680 int32_t xs1 = x + sw > pDst->m_nWidth ? pDst->m_nWidth - x : sw; |
686 } | |
687 if (y + sh > pDst->m_nHeight) { | |
688 ys1 = pDst->m_nHeight - y; | |
689 } else { | |
690 ys1 = sh; | |
691 } | |
692 if (x < 0) { | |
693 xs0 = -x; | |
694 } else { | |
695 xs0 = 0; | |
696 } | |
697 if (x + sw > pDst->m_nWidth) { | |
698 xs1 = pDst->m_nWidth - x; | |
699 } else { | |
700 xs1 = sw; | |
701 } | |
702 if ((ys0 >= ys1) || (xs0 >= xs1)) { | 681 if ((ys0 >= ys1) || (xs0 >= xs1)) { |
703 return 0; | 682 return 0; |
704 } | 683 } |
705 w = xs1 - xs0; | 684 int32_t w = xs1 - xs0; |
706 h = ys1 - ys0; | 685 int32_t h = ys1 - ys0; |
707 if (y < 0) { | 686 int32_t yd0 = y < 0 ? 0 : y; |
708 yd0 = 0; | 687 int32_t xd0 = x < 0 ? 0 : x; |
709 } else { | 688 int32_t xd1 = xd0 + w; |
710 yd0 = y; | 689 int32_t yd1 = yd0 + h; |
711 } | 690 int32_t d1 = xd0 & 31; |
712 if (x < 0) { | 691 int32_t d2 = xd1 & 31; |
713 xd0 = 0; | 692 int32_t s1 = xs0 & 31; |
714 } else { | 693 int32_t maskL = 0xffffffff >> d1; |
715 xd0 = x; | 694 int32_t maskR = 0xffffffff << ((32 - (xd1 & 31)) % 32); |
716 } | 695 int32_t maskM = maskL & maskR; |
717 xd1 = xd0 + w; | 696 uint8_t* lineSrc = m_pData + (pSrcRect->top + ys0) * m_nStride + |
718 yd1 = yd0 + h; | 697 (((xs0 + pSrcRect->left) >> 5) << 2); |
719 d1 = xd0 & 31; | 698 int32_t lineLeft = m_nStride - ((xs0 >> 5) << 2); |
720 d2 = xd1 & 31; | 699 uint8_t* lineDst = pDst->m_pData + yd0 * pDst->m_nStride + ((xd0 >> 5) << 2); |
721 s1 = xs0 & 31; | |
722 maskL = 0xffffffff >> d1; | |
723 maskR = 0xffffffff << ((32 - (xd1 & 31)) % 32); | |
724 maskM = maskL & maskR; | |
725 lineSrc = m_pData + (pSrcRect->top + ys0) * m_nStride + | |
726 (((xs0 + pSrcRect->left) >> 5) << 2); | |
727 lineLeft = m_nStride - ((xs0 >> 5) << 2); | |
728 lineDst = pDst->m_pData + yd0 * pDst->m_nStride + ((xd0 >> 5) << 2); | |
729 if ((xd0 & ~31) == ((xd1 - 1) & ~31)) { | 700 if ((xd0 & ~31) == ((xd1 - 1) & ~31)) { |
730 if ((xs0 & ~31) == ((xs1 - 1) & ~31)) { | 701 if ((xs0 & ~31) == ((xs1 - 1) & ~31)) { |
731 if (s1 > d1) { | 702 if (s1 > d1) { |
732 shift = s1 - d1; | 703 FX_DWORD shift = s1 - d1; |
733 for (yy = yd0; yy < yd1; yy++) { | 704 for (int32_t yy = yd0; yy < yd1; yy++) { |
734 tmp1 = JBIG2_GETDWORD(lineSrc) << shift; | 705 FX_DWORD tmp1 = JBIG2_GETDWORD(lineSrc) << shift; |
735 tmp2 = JBIG2_GETDWORD(lineDst); | 706 FX_DWORD tmp2 = JBIG2_GETDWORD(lineDst); |
| 707 FX_DWORD tmp = 0; |
736 switch (op) { | 708 switch (op) { |
737 case JBIG2_COMPOSE_OR: | 709 case JBIG2_COMPOSE_OR: |
738 tmp = (tmp2 & ~maskM) | ((tmp1 | tmp2) & maskM); | 710 tmp = (tmp2 & ~maskM) | ((tmp1 | tmp2) & maskM); |
739 break; | 711 break; |
740 case JBIG2_COMPOSE_AND: | 712 case JBIG2_COMPOSE_AND: |
741 tmp = (tmp2 & ~maskM) | ((tmp1 & tmp2) & maskM); | 713 tmp = (tmp2 & ~maskM) | ((tmp1 & tmp2) & maskM); |
742 break; | 714 break; |
743 case JBIG2_COMPOSE_XOR: | 715 case JBIG2_COMPOSE_XOR: |
744 tmp = (tmp2 & ~maskM) | ((tmp1 ^ tmp2) & maskM); | 716 tmp = (tmp2 & ~maskM) | ((tmp1 ^ tmp2) & maskM); |
745 break; | 717 break; |
746 case JBIG2_COMPOSE_XNOR: | 718 case JBIG2_COMPOSE_XNOR: |
747 tmp = (tmp2 & ~maskM) | ((~(tmp1 ^ tmp2)) & maskM); | 719 tmp = (tmp2 & ~maskM) | ((~(tmp1 ^ tmp2)) & maskM); |
748 break; | 720 break; |
749 case JBIG2_COMPOSE_REPLACE: | 721 case JBIG2_COMPOSE_REPLACE: |
750 tmp = (tmp2 & ~maskM) | (tmp1 & maskM); | 722 tmp = (tmp2 & ~maskM) | (tmp1 & maskM); |
751 break; | 723 break; |
752 } | 724 } |
753 lineDst[0] = (uint8_t)(tmp >> 24); | 725 lineDst[0] = (uint8_t)(tmp >> 24); |
754 lineDst[1] = (uint8_t)(tmp >> 16); | 726 lineDst[1] = (uint8_t)(tmp >> 16); |
755 lineDst[2] = (uint8_t)(tmp >> 8); | 727 lineDst[2] = (uint8_t)(tmp >> 8); |
756 lineDst[3] = (uint8_t)tmp; | 728 lineDst[3] = (uint8_t)tmp; |
757 lineSrc += m_nStride; | 729 lineSrc += m_nStride; |
758 lineDst += pDst->m_nStride; | 730 lineDst += pDst->m_nStride; |
759 } | 731 } |
760 } else { | 732 } else { |
761 shift = d1 - s1; | 733 FX_DWORD shift = d1 - s1; |
762 for (yy = yd0; yy < yd1; yy++) { | 734 for (int32_t yy = yd0; yy < yd1; yy++) { |
763 tmp1 = JBIG2_GETDWORD(lineSrc) >> shift; | 735 FX_DWORD tmp1 = JBIG2_GETDWORD(lineSrc) >> shift; |
764 tmp2 = JBIG2_GETDWORD(lineDst); | 736 FX_DWORD tmp2 = JBIG2_GETDWORD(lineDst); |
| 737 FX_DWORD tmp = 0; |
765 switch (op) { | 738 switch (op) { |
766 case JBIG2_COMPOSE_OR: | 739 case JBIG2_COMPOSE_OR: |
767 tmp = (tmp2 & ~maskM) | ((tmp1 | tmp2) & maskM); | 740 tmp = (tmp2 & ~maskM) | ((tmp1 | tmp2) & maskM); |
768 break; | 741 break; |
769 case JBIG2_COMPOSE_AND: | 742 case JBIG2_COMPOSE_AND: |
770 tmp = (tmp2 & ~maskM) | ((tmp1 & tmp2) & maskM); | 743 tmp = (tmp2 & ~maskM) | ((tmp1 & tmp2) & maskM); |
771 break; | 744 break; |
772 case JBIG2_COMPOSE_XOR: | 745 case JBIG2_COMPOSE_XOR: |
773 tmp = (tmp2 & ~maskM) | ((tmp1 ^ tmp2) & maskM); | 746 tmp = (tmp2 & ~maskM) | ((tmp1 ^ tmp2) & maskM); |
774 break; | 747 break; |
775 case JBIG2_COMPOSE_XNOR: | 748 case JBIG2_COMPOSE_XNOR: |
776 tmp = (tmp2 & ~maskM) | ((~(tmp1 ^ tmp2)) & maskM); | 749 tmp = (tmp2 & ~maskM) | ((~(tmp1 ^ tmp2)) & maskM); |
777 break; | 750 break; |
778 case JBIG2_COMPOSE_REPLACE: | 751 case JBIG2_COMPOSE_REPLACE: |
779 tmp = (tmp2 & ~maskM) | (tmp1 & maskM); | 752 tmp = (tmp2 & ~maskM) | (tmp1 & maskM); |
780 break; | 753 break; |
781 } | 754 } |
782 lineDst[0] = (uint8_t)(tmp >> 24); | 755 lineDst[0] = (uint8_t)(tmp >> 24); |
783 lineDst[1] = (uint8_t)(tmp >> 16); | 756 lineDst[1] = (uint8_t)(tmp >> 16); |
784 lineDst[2] = (uint8_t)(tmp >> 8); | 757 lineDst[2] = (uint8_t)(tmp >> 8); |
785 lineDst[3] = (uint8_t)tmp; | 758 lineDst[3] = (uint8_t)tmp; |
786 lineSrc += m_nStride; | 759 lineSrc += m_nStride; |
787 lineDst += pDst->m_nStride; | 760 lineDst += pDst->m_nStride; |
788 } | 761 } |
789 } | 762 } |
790 } else { | 763 } else { |
791 shift1 = s1 - d1; | 764 FX_DWORD shift1 = s1 - d1; |
792 shift2 = 32 - shift1; | 765 FX_DWORD shift2 = 32 - shift1; |
793 for (yy = yd0; yy < yd1; yy++) { | 766 for (int32_t yy = yd0; yy < yd1; yy++) { |
794 tmp1 = (JBIG2_GETDWORD(lineSrc) << shift1) | | 767 FX_DWORD tmp1 = (JBIG2_GETDWORD(lineSrc) << shift1) | |
795 (JBIG2_GETDWORD(lineSrc + 4) >> shift2); | 768 (JBIG2_GETDWORD(lineSrc + 4) >> shift2); |
796 tmp2 = JBIG2_GETDWORD(lineDst); | 769 FX_DWORD tmp2 = JBIG2_GETDWORD(lineDst); |
| 770 FX_DWORD tmp = 0; |
797 switch (op) { | 771 switch (op) { |
798 case JBIG2_COMPOSE_OR: | 772 case JBIG2_COMPOSE_OR: |
799 tmp = (tmp2 & ~maskM) | ((tmp1 | tmp2) & maskM); | 773 tmp = (tmp2 & ~maskM) | ((tmp1 | tmp2) & maskM); |
800 break; | 774 break; |
801 case JBIG2_COMPOSE_AND: | 775 case JBIG2_COMPOSE_AND: |
802 tmp = (tmp2 & ~maskM) | ((tmp1 & tmp2) & maskM); | 776 tmp = (tmp2 & ~maskM) | ((tmp1 & tmp2) & maskM); |
803 break; | 777 break; |
804 case JBIG2_COMPOSE_XOR: | 778 case JBIG2_COMPOSE_XOR: |
805 tmp = (tmp2 & ~maskM) | ((tmp1 ^ tmp2) & maskM); | 779 tmp = (tmp2 & ~maskM) | ((tmp1 ^ tmp2) & maskM); |
806 break; | 780 break; |
807 case JBIG2_COMPOSE_XNOR: | 781 case JBIG2_COMPOSE_XNOR: |
808 tmp = (tmp2 & ~maskM) | ((~(tmp1 ^ tmp2)) & maskM); | 782 tmp = (tmp2 & ~maskM) | ((~(tmp1 ^ tmp2)) & maskM); |
809 break; | 783 break; |
810 case JBIG2_COMPOSE_REPLACE: | 784 case JBIG2_COMPOSE_REPLACE: |
811 tmp = (tmp2 & ~maskM) | (tmp1 & maskM); | 785 tmp = (tmp2 & ~maskM) | (tmp1 & maskM); |
812 break; | 786 break; |
813 } | 787 } |
814 lineDst[0] = (uint8_t)(tmp >> 24); | 788 lineDst[0] = (uint8_t)(tmp >> 24); |
815 lineDst[1] = (uint8_t)(tmp >> 16); | 789 lineDst[1] = (uint8_t)(tmp >> 16); |
816 lineDst[2] = (uint8_t)(tmp >> 8); | 790 lineDst[2] = (uint8_t)(tmp >> 8); |
817 lineDst[3] = (uint8_t)tmp; | 791 lineDst[3] = (uint8_t)tmp; |
818 lineSrc += m_nStride; | 792 lineSrc += m_nStride; |
819 lineDst += pDst->m_nStride; | 793 lineDst += pDst->m_nStride; |
820 } | 794 } |
821 } | 795 } |
822 } else { | 796 } else { |
823 if (s1 > d1) { | 797 if (s1 > d1) { |
824 shift1 = s1 - d1; | 798 FX_DWORD shift1 = s1 - d1; |
825 shift2 = 32 - shift1; | 799 FX_DWORD shift2 = 32 - shift1; |
826 middleDwords = (xd1 >> 5) - ((xd0 + 31) >> 5); | 800 int32_t middleDwords = (xd1 >> 5) - ((xd0 + 31) >> 5); |
827 for (yy = yd0; yy < yd1; yy++) { | 801 for (int32_t yy = yd0; yy < yd1; yy++) { |
828 sp = lineSrc; | 802 uint8_t* sp = lineSrc; |
829 dp = lineDst; | 803 uint8_t* dp = lineDst; |
830 if (d1 != 0) { | 804 if (d1 != 0) { |
831 tmp1 = (JBIG2_GETDWORD(sp) << shift1) | | 805 FX_DWORD tmp1 = (JBIG2_GETDWORD(sp) << shift1) | |
832 (JBIG2_GETDWORD(sp + 4) >> shift2); | 806 (JBIG2_GETDWORD(sp + 4) >> shift2); |
833 tmp2 = JBIG2_GETDWORD(dp); | 807 FX_DWORD tmp2 = JBIG2_GETDWORD(dp); |
| 808 FX_DWORD tmp = 0; |
834 switch (op) { | 809 switch (op) { |
835 case JBIG2_COMPOSE_OR: | 810 case JBIG2_COMPOSE_OR: |
836 tmp = (tmp2 & ~maskL) | ((tmp1 | tmp2) & maskL); | 811 tmp = (tmp2 & ~maskL) | ((tmp1 | tmp2) & maskL); |
837 break; | 812 break; |
838 case JBIG2_COMPOSE_AND: | 813 case JBIG2_COMPOSE_AND: |
839 tmp = (tmp2 & ~maskL) | ((tmp1 & tmp2) & maskL); | 814 tmp = (tmp2 & ~maskL) | ((tmp1 & tmp2) & maskL); |
840 break; | 815 break; |
841 case JBIG2_COMPOSE_XOR: | 816 case JBIG2_COMPOSE_XOR: |
842 tmp = (tmp2 & ~maskL) | ((tmp1 ^ tmp2) & maskL); | 817 tmp = (tmp2 & ~maskL) | ((tmp1 ^ tmp2) & maskL); |
843 break; | 818 break; |
844 case JBIG2_COMPOSE_XNOR: | 819 case JBIG2_COMPOSE_XNOR: |
845 tmp = (tmp2 & ~maskL) | ((~(tmp1 ^ tmp2)) & maskL); | 820 tmp = (tmp2 & ~maskL) | ((~(tmp1 ^ tmp2)) & maskL); |
846 break; | 821 break; |
847 case JBIG2_COMPOSE_REPLACE: | 822 case JBIG2_COMPOSE_REPLACE: |
848 tmp = (tmp2 & ~maskL) | (tmp1 & maskL); | 823 tmp = (tmp2 & ~maskL) | (tmp1 & maskL); |
849 break; | 824 break; |
850 } | 825 } |
851 dp[0] = (uint8_t)(tmp >> 24); | 826 dp[0] = (uint8_t)(tmp >> 24); |
852 dp[1] = (uint8_t)(tmp >> 16); | 827 dp[1] = (uint8_t)(tmp >> 16); |
853 dp[2] = (uint8_t)(tmp >> 8); | 828 dp[2] = (uint8_t)(tmp >> 8); |
854 dp[3] = (uint8_t)tmp; | 829 dp[3] = (uint8_t)tmp; |
855 sp += 4; | 830 sp += 4; |
856 dp += 4; | 831 dp += 4; |
857 } | 832 } |
858 for (xx = 0; xx < middleDwords; xx++) { | 833 for (int32_t xx = 0; xx < middleDwords; xx++) { |
859 tmp1 = (JBIG2_GETDWORD(sp) << shift1) | | 834 FX_DWORD tmp1 = (JBIG2_GETDWORD(sp) << shift1) | |
860 (JBIG2_GETDWORD(sp + 4) >> shift2); | 835 (JBIG2_GETDWORD(sp + 4) >> shift2); |
861 tmp2 = JBIG2_GETDWORD(dp); | 836 FX_DWORD tmp2 = JBIG2_GETDWORD(dp); |
| 837 FX_DWORD tmp = 0; |
862 switch (op) { | 838 switch (op) { |
863 case JBIG2_COMPOSE_OR: | 839 case JBIG2_COMPOSE_OR: |
864 tmp = tmp1 | tmp2; | 840 tmp = tmp1 | tmp2; |
865 break; | 841 break; |
866 case JBIG2_COMPOSE_AND: | 842 case JBIG2_COMPOSE_AND: |
867 tmp = tmp1 & tmp2; | 843 tmp = tmp1 & tmp2; |
868 break; | 844 break; |
869 case JBIG2_COMPOSE_XOR: | 845 case JBIG2_COMPOSE_XOR: |
870 tmp = tmp1 ^ tmp2; | 846 tmp = tmp1 ^ tmp2; |
871 break; | 847 break; |
872 case JBIG2_COMPOSE_XNOR: | 848 case JBIG2_COMPOSE_XNOR: |
873 tmp = ~(tmp1 ^ tmp2); | 849 tmp = ~(tmp1 ^ tmp2); |
874 break; | 850 break; |
875 case JBIG2_COMPOSE_REPLACE: | 851 case JBIG2_COMPOSE_REPLACE: |
876 tmp = tmp1; | 852 tmp = tmp1; |
877 break; | 853 break; |
878 } | 854 } |
879 dp[0] = (uint8_t)(tmp >> 24); | 855 dp[0] = (uint8_t)(tmp >> 24); |
880 dp[1] = (uint8_t)(tmp >> 16); | 856 dp[1] = (uint8_t)(tmp >> 16); |
881 dp[2] = (uint8_t)(tmp >> 8); | 857 dp[2] = (uint8_t)(tmp >> 8); |
882 dp[3] = (uint8_t)tmp; | 858 dp[3] = (uint8_t)tmp; |
883 sp += 4; | 859 sp += 4; |
884 dp += 4; | 860 dp += 4; |
885 } | 861 } |
886 if (d2 != 0) { | 862 if (d2 != 0) { |
887 tmp1 = | 863 FX_DWORD tmp1 = |
888 (JBIG2_GETDWORD(sp) << shift1) | | 864 (JBIG2_GETDWORD(sp) << shift1) | |
889 (((sp + 4) < lineSrc + lineLeft ? JBIG2_GETDWORD(sp + 4) : 0) >> | 865 (((sp + 4) < lineSrc + lineLeft ? JBIG2_GETDWORD(sp + 4) : 0) >> |
890 shift2); | 866 shift2); |
891 tmp2 = JBIG2_GETDWORD(dp); | 867 FX_DWORD tmp2 = JBIG2_GETDWORD(dp); |
| 868 FX_DWORD tmp = 0; |
892 switch (op) { | 869 switch (op) { |
893 case JBIG2_COMPOSE_OR: | 870 case JBIG2_COMPOSE_OR: |
894 tmp = (tmp2 & ~maskR) | ((tmp1 | tmp2) & maskR); | 871 tmp = (tmp2 & ~maskR) | ((tmp1 | tmp2) & maskR); |
895 break; | 872 break; |
896 case JBIG2_COMPOSE_AND: | 873 case JBIG2_COMPOSE_AND: |
897 tmp = (tmp2 & ~maskR) | ((tmp1 & tmp2) & maskR); | 874 tmp = (tmp2 & ~maskR) | ((tmp1 & tmp2) & maskR); |
898 break; | 875 break; |
899 case JBIG2_COMPOSE_XOR: | 876 case JBIG2_COMPOSE_XOR: |
900 tmp = (tmp2 & ~maskR) | ((tmp1 ^ tmp2) & maskR); | 877 tmp = (tmp2 & ~maskR) | ((tmp1 ^ tmp2) & maskR); |
901 break; | 878 break; |
902 case JBIG2_COMPOSE_XNOR: | 879 case JBIG2_COMPOSE_XNOR: |
903 tmp = (tmp2 & ~maskR) | ((~(tmp1 ^ tmp2)) & maskR); | 880 tmp = (tmp2 & ~maskR) | ((~(tmp1 ^ tmp2)) & maskR); |
904 break; | 881 break; |
905 case JBIG2_COMPOSE_REPLACE: | 882 case JBIG2_COMPOSE_REPLACE: |
906 tmp = (tmp2 & ~maskR) | (tmp1 & maskR); | 883 tmp = (tmp2 & ~maskR) | (tmp1 & maskR); |
907 break; | 884 break; |
908 } | 885 } |
909 dp[0] = (uint8_t)(tmp >> 24); | 886 dp[0] = (uint8_t)(tmp >> 24); |
910 dp[1] = (uint8_t)(tmp >> 16); | 887 dp[1] = (uint8_t)(tmp >> 16); |
911 dp[2] = (uint8_t)(tmp >> 8); | 888 dp[2] = (uint8_t)(tmp >> 8); |
912 dp[3] = (uint8_t)tmp; | 889 dp[3] = (uint8_t)tmp; |
913 } | 890 } |
914 lineSrc += m_nStride; | 891 lineSrc += m_nStride; |
915 lineDst += pDst->m_nStride; | 892 lineDst += pDst->m_nStride; |
916 } | 893 } |
917 } else if (s1 == d1) { | 894 } else if (s1 == d1) { |
918 middleDwords = (xd1 >> 5) - ((xd0 + 31) >> 5); | 895 int32_t middleDwords = (xd1 >> 5) - ((xd0 + 31) >> 5); |
919 for (yy = yd0; yy < yd1; yy++) { | 896 for (int32_t yy = yd0; yy < yd1; yy++) { |
920 sp = lineSrc; | 897 uint8_t* sp = lineSrc; |
921 dp = lineDst; | 898 uint8_t* dp = lineDst; |
922 if (d1 != 0) { | 899 if (d1 != 0) { |
923 tmp1 = JBIG2_GETDWORD(sp); | 900 FX_DWORD tmp1 = JBIG2_GETDWORD(sp); |
924 tmp2 = JBIG2_GETDWORD(dp); | 901 FX_DWORD tmp2 = JBIG2_GETDWORD(dp); |
| 902 FX_DWORD tmp = 0; |
925 switch (op) { | 903 switch (op) { |
926 case JBIG2_COMPOSE_OR: | 904 case JBIG2_COMPOSE_OR: |
927 tmp = (tmp2 & ~maskL) | ((tmp1 | tmp2) & maskL); | 905 tmp = (tmp2 & ~maskL) | ((tmp1 | tmp2) & maskL); |
928 break; | 906 break; |
929 case JBIG2_COMPOSE_AND: | 907 case JBIG2_COMPOSE_AND: |
930 tmp = (tmp2 & ~maskL) | ((tmp1 & tmp2) & maskL); | 908 tmp = (tmp2 & ~maskL) | ((tmp1 & tmp2) & maskL); |
931 break; | 909 break; |
932 case JBIG2_COMPOSE_XOR: | 910 case JBIG2_COMPOSE_XOR: |
933 tmp = (tmp2 & ~maskL) | ((tmp1 ^ tmp2) & maskL); | 911 tmp = (tmp2 & ~maskL) | ((tmp1 ^ tmp2) & maskL); |
934 break; | 912 break; |
935 case JBIG2_COMPOSE_XNOR: | 913 case JBIG2_COMPOSE_XNOR: |
936 tmp = (tmp2 & ~maskL) | ((~(tmp1 ^ tmp2)) & maskL); | 914 tmp = (tmp2 & ~maskL) | ((~(tmp1 ^ tmp2)) & maskL); |
937 break; | 915 break; |
938 case JBIG2_COMPOSE_REPLACE: | 916 case JBIG2_COMPOSE_REPLACE: |
939 tmp = (tmp2 & ~maskL) | (tmp1 & maskL); | 917 tmp = (tmp2 & ~maskL) | (tmp1 & maskL); |
940 break; | 918 break; |
941 } | 919 } |
942 dp[0] = (uint8_t)(tmp >> 24); | 920 dp[0] = (uint8_t)(tmp >> 24); |
943 dp[1] = (uint8_t)(tmp >> 16); | 921 dp[1] = (uint8_t)(tmp >> 16); |
944 dp[2] = (uint8_t)(tmp >> 8); | 922 dp[2] = (uint8_t)(tmp >> 8); |
945 dp[3] = (uint8_t)tmp; | 923 dp[3] = (uint8_t)tmp; |
946 sp += 4; | 924 sp += 4; |
947 dp += 4; | 925 dp += 4; |
948 } | 926 } |
949 for (xx = 0; xx < middleDwords; xx++) { | 927 for (int32_t xx = 0; xx < middleDwords; xx++) { |
950 tmp1 = JBIG2_GETDWORD(sp); | 928 FX_DWORD tmp1 = JBIG2_GETDWORD(sp); |
951 tmp2 = JBIG2_GETDWORD(dp); | 929 FX_DWORD tmp2 = JBIG2_GETDWORD(dp); |
| 930 FX_DWORD tmp = 0; |
952 switch (op) { | 931 switch (op) { |
953 case JBIG2_COMPOSE_OR: | 932 case JBIG2_COMPOSE_OR: |
954 tmp = tmp1 | tmp2; | 933 tmp = tmp1 | tmp2; |
955 break; | 934 break; |
956 case JBIG2_COMPOSE_AND: | 935 case JBIG2_COMPOSE_AND: |
957 tmp = tmp1 & tmp2; | 936 tmp = tmp1 & tmp2; |
958 break; | 937 break; |
959 case JBIG2_COMPOSE_XOR: | 938 case JBIG2_COMPOSE_XOR: |
960 tmp = tmp1 ^ tmp2; | 939 tmp = tmp1 ^ tmp2; |
961 break; | 940 break; |
962 case JBIG2_COMPOSE_XNOR: | 941 case JBIG2_COMPOSE_XNOR: |
963 tmp = ~(tmp1 ^ tmp2); | 942 tmp = ~(tmp1 ^ tmp2); |
964 break; | 943 break; |
965 case JBIG2_COMPOSE_REPLACE: | 944 case JBIG2_COMPOSE_REPLACE: |
966 tmp = tmp1; | 945 tmp = tmp1; |
967 break; | 946 break; |
968 } | 947 } |
969 dp[0] = (uint8_t)(tmp >> 24); | 948 dp[0] = (uint8_t)(tmp >> 24); |
970 dp[1] = (uint8_t)(tmp >> 16); | 949 dp[1] = (uint8_t)(tmp >> 16); |
971 dp[2] = (uint8_t)(tmp >> 8); | 950 dp[2] = (uint8_t)(tmp >> 8); |
972 dp[3] = (uint8_t)tmp; | 951 dp[3] = (uint8_t)tmp; |
973 sp += 4; | 952 sp += 4; |
974 dp += 4; | 953 dp += 4; |
975 } | 954 } |
976 if (d2 != 0) { | 955 if (d2 != 0) { |
977 tmp1 = JBIG2_GETDWORD(sp); | 956 FX_DWORD tmp1 = JBIG2_GETDWORD(sp); |
978 tmp2 = JBIG2_GETDWORD(dp); | 957 FX_DWORD tmp2 = JBIG2_GETDWORD(dp); |
| 958 FX_DWORD tmp = 0; |
979 switch (op) { | 959 switch (op) { |
980 case JBIG2_COMPOSE_OR: | 960 case JBIG2_COMPOSE_OR: |
981 tmp = (tmp2 & ~maskR) | ((tmp1 | tmp2) & maskR); | 961 tmp = (tmp2 & ~maskR) | ((tmp1 | tmp2) & maskR); |
982 break; | 962 break; |
983 case JBIG2_COMPOSE_AND: | 963 case JBIG2_COMPOSE_AND: |
984 tmp = (tmp2 & ~maskR) | ((tmp1 & tmp2) & maskR); | 964 tmp = (tmp2 & ~maskR) | ((tmp1 & tmp2) & maskR); |
985 break; | 965 break; |
986 case JBIG2_COMPOSE_XOR: | 966 case JBIG2_COMPOSE_XOR: |
987 tmp = (tmp2 & ~maskR) | ((tmp1 ^ tmp2) & maskR); | 967 tmp = (tmp2 & ~maskR) | ((tmp1 ^ tmp2) & maskR); |
988 break; | 968 break; |
989 case JBIG2_COMPOSE_XNOR: | 969 case JBIG2_COMPOSE_XNOR: |
990 tmp = (tmp2 & ~maskR) | ((~(tmp1 ^ tmp2)) & maskR); | 970 tmp = (tmp2 & ~maskR) | ((~(tmp1 ^ tmp2)) & maskR); |
991 break; | 971 break; |
992 case JBIG2_COMPOSE_REPLACE: | 972 case JBIG2_COMPOSE_REPLACE: |
993 tmp = (tmp2 & ~maskR) | (tmp1 & maskR); | 973 tmp = (tmp2 & ~maskR) | (tmp1 & maskR); |
994 break; | 974 break; |
995 } | 975 } |
996 dp[0] = (uint8_t)(tmp >> 24); | 976 dp[0] = (uint8_t)(tmp >> 24); |
997 dp[1] = (uint8_t)(tmp >> 16); | 977 dp[1] = (uint8_t)(tmp >> 16); |
998 dp[2] = (uint8_t)(tmp >> 8); | 978 dp[2] = (uint8_t)(tmp >> 8); |
999 dp[3] = (uint8_t)tmp; | 979 dp[3] = (uint8_t)tmp; |
1000 } | 980 } |
1001 lineSrc += m_nStride; | 981 lineSrc += m_nStride; |
1002 lineDst += pDst->m_nStride; | 982 lineDst += pDst->m_nStride; |
1003 } | 983 } |
1004 } else { | 984 } else { |
1005 shift1 = d1 - s1; | 985 FX_DWORD shift1 = d1 - s1; |
1006 shift2 = 32 - shift1; | 986 FX_DWORD shift2 = 32 - shift1; |
1007 middleDwords = (xd1 >> 5) - ((xd0 + 31) >> 5); | 987 int32_t middleDwords = (xd1 >> 5) - ((xd0 + 31) >> 5); |
1008 for (yy = yd0; yy < yd1; yy++) { | 988 for (int32_t yy = yd0; yy < yd1; yy++) { |
1009 sp = lineSrc; | 989 uint8_t* sp = lineSrc; |
1010 dp = lineDst; | 990 uint8_t* dp = lineDst; |
1011 if (d1 != 0) { | 991 if (d1 != 0) { |
1012 tmp1 = JBIG2_GETDWORD(sp) >> shift1; | 992 FX_DWORD tmp1 = JBIG2_GETDWORD(sp) >> shift1; |
1013 tmp2 = JBIG2_GETDWORD(dp); | 993 FX_DWORD tmp2 = JBIG2_GETDWORD(dp); |
| 994 FX_DWORD tmp = 0; |
1014 switch (op) { | 995 switch (op) { |
1015 case JBIG2_COMPOSE_OR: | 996 case JBIG2_COMPOSE_OR: |
1016 tmp = (tmp2 & ~maskL) | ((tmp1 | tmp2) & maskL); | 997 tmp = (tmp2 & ~maskL) | ((tmp1 | tmp2) & maskL); |
1017 break; | 998 break; |
1018 case JBIG2_COMPOSE_AND: | 999 case JBIG2_COMPOSE_AND: |
1019 tmp = (tmp2 & ~maskL) | ((tmp1 & tmp2) & maskL); | 1000 tmp = (tmp2 & ~maskL) | ((tmp1 & tmp2) & maskL); |
1020 break; | 1001 break; |
1021 case JBIG2_COMPOSE_XOR: | 1002 case JBIG2_COMPOSE_XOR: |
1022 tmp = (tmp2 & ~maskL) | ((tmp1 ^ tmp2) & maskL); | 1003 tmp = (tmp2 & ~maskL) | ((tmp1 ^ tmp2) & maskL); |
1023 break; | 1004 break; |
1024 case JBIG2_COMPOSE_XNOR: | 1005 case JBIG2_COMPOSE_XNOR: |
1025 tmp = (tmp2 & ~maskL) | ((~(tmp1 ^ tmp2)) & maskL); | 1006 tmp = (tmp2 & ~maskL) | ((~(tmp1 ^ tmp2)) & maskL); |
1026 break; | 1007 break; |
1027 case JBIG2_COMPOSE_REPLACE: | 1008 case JBIG2_COMPOSE_REPLACE: |
1028 tmp = (tmp2 & ~maskL) | (tmp1 & maskL); | 1009 tmp = (tmp2 & ~maskL) | (tmp1 & maskL); |
1029 break; | 1010 break; |
1030 } | 1011 } |
1031 dp[0] = (uint8_t)(tmp >> 24); | 1012 dp[0] = (uint8_t)(tmp >> 24); |
1032 dp[1] = (uint8_t)(tmp >> 16); | 1013 dp[1] = (uint8_t)(tmp >> 16); |
1033 dp[2] = (uint8_t)(tmp >> 8); | 1014 dp[2] = (uint8_t)(tmp >> 8); |
1034 dp[3] = (uint8_t)tmp; | 1015 dp[3] = (uint8_t)tmp; |
1035 dp += 4; | 1016 dp += 4; |
1036 } | 1017 } |
1037 for (xx = 0; xx < middleDwords; xx++) { | 1018 for (int32_t xx = 0; xx < middleDwords; xx++) { |
1038 tmp1 = (JBIG2_GETDWORD(sp) << shift2) | | 1019 FX_DWORD tmp1 = (JBIG2_GETDWORD(sp) << shift2) | |
1039 ((JBIG2_GETDWORD(sp + 4)) >> shift1); | 1020 ((JBIG2_GETDWORD(sp + 4)) >> shift1); |
1040 tmp2 = JBIG2_GETDWORD(dp); | 1021 FX_DWORD tmp2 = JBIG2_GETDWORD(dp); |
| 1022 FX_DWORD tmp = 0; |
1041 switch (op) { | 1023 switch (op) { |
1042 case JBIG2_COMPOSE_OR: | 1024 case JBIG2_COMPOSE_OR: |
1043 tmp = tmp1 | tmp2; | 1025 tmp = tmp1 | tmp2; |
1044 break; | 1026 break; |
1045 case JBIG2_COMPOSE_AND: | 1027 case JBIG2_COMPOSE_AND: |
1046 tmp = tmp1 & tmp2; | 1028 tmp = tmp1 & tmp2; |
1047 break; | 1029 break; |
1048 case JBIG2_COMPOSE_XOR: | 1030 case JBIG2_COMPOSE_XOR: |
1049 tmp = tmp1 ^ tmp2; | 1031 tmp = tmp1 ^ tmp2; |
1050 break; | 1032 break; |
1051 case JBIG2_COMPOSE_XNOR: | 1033 case JBIG2_COMPOSE_XNOR: |
1052 tmp = ~(tmp1 ^ tmp2); | 1034 tmp = ~(tmp1 ^ tmp2); |
1053 break; | 1035 break; |
1054 case JBIG2_COMPOSE_REPLACE: | 1036 case JBIG2_COMPOSE_REPLACE: |
1055 tmp = tmp1; | 1037 tmp = tmp1; |
1056 break; | 1038 break; |
1057 } | 1039 } |
1058 dp[0] = (uint8_t)(tmp >> 24); | 1040 dp[0] = (uint8_t)(tmp >> 24); |
1059 dp[1] = (uint8_t)(tmp >> 16); | 1041 dp[1] = (uint8_t)(tmp >> 16); |
1060 dp[2] = (uint8_t)(tmp >> 8); | 1042 dp[2] = (uint8_t)(tmp >> 8); |
1061 dp[3] = (uint8_t)tmp; | 1043 dp[3] = (uint8_t)tmp; |
1062 sp += 4; | 1044 sp += 4; |
1063 dp += 4; | 1045 dp += 4; |
1064 } | 1046 } |
1065 if (d2 != 0) { | 1047 if (d2 != 0) { |
1066 tmp1 = | 1048 FX_DWORD tmp1 = |
1067 (JBIG2_GETDWORD(sp) << shift2) | | 1049 (JBIG2_GETDWORD(sp) << shift2) | |
1068 (((sp + 4) < lineSrc + lineLeft ? JBIG2_GETDWORD(sp + 4) : 0) >> | 1050 (((sp + 4) < lineSrc + lineLeft ? JBIG2_GETDWORD(sp + 4) : 0) >> |
1069 shift1); | 1051 shift1); |
1070 tmp2 = JBIG2_GETDWORD(dp); | 1052 FX_DWORD tmp2 = JBIG2_GETDWORD(dp); |
| 1053 FX_DWORD tmp = 0; |
1071 switch (op) { | 1054 switch (op) { |
1072 case JBIG2_COMPOSE_OR: | 1055 case JBIG2_COMPOSE_OR: |
1073 tmp = (tmp2 & ~maskR) | ((tmp1 | tmp2) & maskR); | 1056 tmp = (tmp2 & ~maskR) | ((tmp1 | tmp2) & maskR); |
1074 break; | 1057 break; |
1075 case JBIG2_COMPOSE_AND: | 1058 case JBIG2_COMPOSE_AND: |
1076 tmp = (tmp2 & ~maskR) | ((tmp1 & tmp2) & maskR); | 1059 tmp = (tmp2 & ~maskR) | ((tmp1 & tmp2) & maskR); |
1077 break; | 1060 break; |
1078 case JBIG2_COMPOSE_XOR: | 1061 case JBIG2_COMPOSE_XOR: |
1079 tmp = (tmp2 & ~maskR) | ((tmp1 ^ tmp2) & maskR); | 1062 tmp = (tmp2 & ~maskR) | ((tmp1 ^ tmp2) & maskR); |
1080 break; | 1063 break; |
1081 case JBIG2_COMPOSE_XNOR: | 1064 case JBIG2_COMPOSE_XNOR: |
1082 tmp = (tmp2 & ~maskR) | ((~(tmp1 ^ tmp2)) & maskR); | 1065 tmp = (tmp2 & ~maskR) | ((~(tmp1 ^ tmp2)) & maskR); |
1083 break; | 1066 break; |
1084 case JBIG2_COMPOSE_REPLACE: | 1067 case JBIG2_COMPOSE_REPLACE: |
1085 tmp = (tmp2 & ~maskR) | (tmp1 & maskR); | 1068 tmp = (tmp2 & ~maskR) | (tmp1 & maskR); |
1086 break; | 1069 break; |
1087 } | 1070 } |
1088 dp[0] = (uint8_t)(tmp >> 24); | 1071 dp[0] = (uint8_t)(tmp >> 24); |
1089 dp[1] = (uint8_t)(tmp >> 16); | 1072 dp[1] = (uint8_t)(tmp >> 16); |
1090 dp[2] = (uint8_t)(tmp >> 8); | 1073 dp[2] = (uint8_t)(tmp >> 8); |
1091 dp[3] = (uint8_t)tmp; | 1074 dp[3] = (uint8_t)tmp; |
1092 } | 1075 } |
1093 lineSrc += m_nStride; | 1076 lineSrc += m_nStride; |
1094 lineDst += pDst->m_nStride; | 1077 lineDst += pDst->m_nStride; |
1095 } | 1078 } |
1096 } | 1079 } |
1097 } | 1080 } |
1098 return 1; | 1081 return 1; |
1099 } | 1082 } |
OLD | NEW |