Beispiel #1
0
 public JBIG2SymbolDict(uint segNumA, int sizeA) :
     base(segNumA)
 {
     m_size                  = sizeA;
     m_bitmaps               = new JBIG2Bitmap[m_size];
     m_genericRegionStats    = null;
     m_refinementRegionStats = null;
 }
Beispiel #2
0
 private JBIG2Bitmap(uint segNumA, JBIG2Bitmap bitmap)
     : base(segNumA)
 {
     m_w    = bitmap.m_w;
     m_h    = bitmap.m_h;
     m_line = bitmap.m_line;
     if (m_w <= 0 || m_h <= 0 || m_line <= 0 || m_h >= (Int32.MaxValue - 1) / m_line)
     {
         m_data = null;
         return;
     }
     // need to allocate one extra guard byte for use in combine()
     m_data = new byte[m_h * m_line + 1];
     Array.Copy(bitmap.m_data, m_data, m_h * m_line);
     m_data[m_h * m_line] = 0;
 }
Beispiel #3
0
        public JBIG2Bitmap GetSlice(uint x, uint y, uint wA, uint hA)
        {
            JBIG2Bitmap slice;
            uint        xx, yy;

            slice = new JBIG2Bitmap(0, (int)wA, (int)hA);
            slice.ClearToZero();
            for (yy = 0; yy < hA; ++yy)
            {
                for (xx = 0; xx < wA; ++xx)
                {
                    if (GetPixel((int)(x + xx), (int)(y + yy)) != 0)
                    {
                        slice.SetPixel((int)xx, (int)yy);
                    }
                }
            }
            return(slice);
        }
Beispiel #4
0
        public void Combine(JBIG2Bitmap bitmap, int x, int y,
                            uint combOp)
        {
            int x0, x1, y0, y1, xx, yy;

            byte[] srcPtr, destPtr;

            int  srcPtr_i = 0, destPtr_i = 0;
            uint src0, src1, src, dest, s1, s2, m1, m2, m3;
            bool oneByte;

            if (y < 0)
            {
                y0 = -y;
            }
            else
            {
                y0 = 0;
            }
            if (y + bitmap.m_h > m_h)
            {
                y1 = m_h - y;
            }
            else
            {
                y1 = bitmap.m_h;
            }
            if (y0 >= y1)
            {
                return;
            }

            if (x >= 0)
            {
                x0 = x & ~7;
            }
            else
            {
                x0 = 0;
            }
            x1 = x + bitmap.m_w;
            if (x1 > m_w)
            {
                x1 = m_w;
            }
            if (x0 >= x1)
            {
                return;
            }

            s1 = (uint)x & 7;
            s2 = 8 - s1;
            m1 = (uint)(0xff >> (x1 & 7));
            m2 = (uint)(0xff << (((x1 & 7) == 0) ? 0 : 8 - (x1 & 7)));
            m3 = (uint)((0xff >> (int)s1) & m2);

            oneByte = x0 == ((x1 - 1) & ~7);

            for (yy = y0; yy < y1; ++yy)
            {
                // one byte per line -- need to mask both left and right side
                if (oneByte)
                {
                    if (x >= 0)
                    {
                        destPtr   = m_data;
                        destPtr_i = (y + yy) * m_line + (x >> 3);

                        srcPtr   = bitmap.m_data;
                        srcPtr_i = yy * bitmap.m_line;
                        dest     = destPtr[destPtr_i];
                        src1     = srcPtr[srcPtr_i];
                        switch (combOp)
                        {
                        case 0:     // or
                            dest |= (src1 >> (int)s1) & m2;
                            break;

                        case 1:     // and
                            dest &= ((0xff00 | src1) >> (int)s1) | m1;
                            break;

                        case 2:     // xor
                            dest ^= (src1 >> (int)s1) & m2;
                            break;

                        case 3:     // xnor
                            dest ^= ((src1 ^ 0xff) >> (int)s1) & m2;
                            break;

                        case 4:     // replace
                            dest = (dest & ~m3) | ((src1 >> (int)s1) & m3);
                            break;
                        }
                        destPtr[destPtr_i] = (byte)dest;
                    }
                    else
                    {
                        destPtr = m_data; destPtr_i = (y + yy) * m_line;
                        srcPtr  = bitmap.m_data; srcPtr_i = yy * bitmap.m_line + (-x >> 3);
                        dest    = destPtr[destPtr_i];
                        src1    = srcPtr[srcPtr_i];
                        switch (combOp)
                        {
                        case 0:     // or
                            dest |= src1 & m2;
                            break;

                        case 1:     // and
                            dest &= src1 | m1;
                            break;

                        case 2:     // xor
                            dest ^= src1 & m2;
                            break;

                        case 3:     // xnor
                            dest ^= (src1 ^ 0xff) & m2;
                            break;

                        case 4:     // replace
                            dest = (src1 & m2) | (dest & m1);
                            break;
                        }
                        destPtr[destPtr_i] = (byte)dest;
                    }

                    // multiple bytes per line -- need to mask left side of left-most
                    // byte and right side of right-most byte
                }
                else
                {
                    // left-most byte
                    if (x >= 0)
                    {
                        destPtr = m_data; destPtr_i = (y + yy) * m_line + (x >> 3);
                        srcPtr  = bitmap.m_data; srcPtr_i = yy * bitmap.m_line;
                        src1    = srcPtr[srcPtr_i++];
                        dest    = destPtr[destPtr_i];
                        switch (combOp)
                        {
                        case 0:     // or
                            dest |= src1 >> (int)s1;
                            break;

                        case 1:     // and
                            dest &= (0xff00 | src1) >> (int)s1;
                            break;

                        case 2:     // xor
                            dest ^= src1 >> (int)s1;
                            break;

                        case 3:     // xnor
                            dest ^= (src1 ^ 0xff) >> (int)s1;
                            break;

                        case 4:     // replace
                            dest = (uint)(dest & (0xff << (int)s2)) | (src1 >> (int)s1);
                            break;
                        }
                        destPtr[destPtr_i++] = (byte)dest;
                        xx = x0 + 8;
                    }
                    else
                    {
                        destPtr = m_data; destPtr_i = (y + yy) * m_line;
                        srcPtr  = bitmap.m_data; srcPtr_i = yy * bitmap.m_line + (-x >> 3);
                        src1    = srcPtr[srcPtr_i++];
                        xx      = x0;
                    }

                    // middle bytes
                    for (; xx < x1 - 8; xx += 8)
                    {
                        dest = destPtr[destPtr_i];
                        src0 = src1;
                        src1 = srcPtr[srcPtr_i++];
                        src  = (((src0 << 8) | src1) >> (int)s1) & 0xff;
                        switch (combOp)
                        {
                        case 0:     // or
                            dest |= src;
                            break;

                        case 1:     // and
                            dest &= src;
                            break;

                        case 2:     // xor
                            dest ^= src;
                            break;

                        case 3:     // xnor
                            dest ^= src ^ 0xff;
                            break;

                        case 4:     // replace
                            dest = src;
                            break;
                        }
                        destPtr[destPtr_i++] = (byte)dest;
                    }

                    // right-most byte
                    // note: this last byte (src1) may not actually be used, depending
                    // on the values of s1, m1, and m2 - and in fact, it may be off
                    // the edge of the source bitmap, which means we need to allocate
                    // one extra guard byte at the end of each bitmap
                    dest = destPtr[destPtr_i];
                    src0 = src1;
                    src1 = srcPtr[srcPtr_i++];
                    src  = (((src0 << 8) | src1) >> (int)s1) & 0xff;
                    switch (combOp)
                    {
                    case 0:     // or
                        dest |= src & m2;
                        break;

                    case 1:     // and
                        dest &= src | m1;
                        break;

                    case 2:     // xor
                        dest ^= src & m2;
                        break;

                    case 3:     // xnor
                        dest ^= (src ^ 0xff) & m2;
                        break;

                    case 4:     // replace
                        dest = (src & m2) | (dest & m1);
                        break;
                    }
                    destPtr[destPtr_i] = (byte)dest;
                }
            }
        }
Beispiel #5
0
 public JBIG2PatternDict(uint segNumA, int sizeA) :
     base(segNumA)
 {
     m_size    = sizeA;
     m_bitmaps = new JBIG2Bitmap[m_size];
 }
Beispiel #6
0
 public void SetBitmap(int idx, JBIG2Bitmap bitmap)
 {
     m_bitmaps[idx] = bitmap;
 }