Exemple #1
0
        public Bitmap GetBitmap(int subsample, int align)
        {
            if ((Width == 0) || (Height == 0))
            {
                throw new SystemException("Image can not create bitmap");
            }

            int swidth  = ((Width + subsample) - 1) / subsample;
            int sheight = ((Height + subsample) - 1) / subsample;
            int border  = (((swidth + align) - 1) & ~(align - 1)) - swidth;

            Bitmap bm = new Bitmap();

            bm.Init(sheight, swidth, border);
            bm.Grays = (1 + (subsample * subsample));

            //for (int blitno = 0; blitno < Blits.Count; blitno++)
            Parallel.For(
                0,
                Blits.Count,
                blitno =>
            {
                JB2Blit pblit   = GetBlit(blitno);
                JB2Shape pshape = GetShape(pblit.ShapeNumber);

                if (pshape.Bitmap != null)
                {
                    bm.Blit(pshape.Bitmap, pblit.Left, pblit.Bottom, subsample);
                }
            });

            return(bm);
        }
Exemple #2
0
        public Bitmap GetBitmap(Rectangle rect, int subsample, int align, int dispy)
        {
            if ((Width == 0) || (Height == 0))
            {
                throw new SystemException("Image can not create bitmap");
            }

            int rxmin   = rect.Right * subsample;
            int rymin   = rect.Bottom * subsample;
            int swidth  = rect.Width;
            int sheight = rect.Height;
            int border  = (((swidth + align) - 1) & ~(align - 1)) - swidth;

            Bitmap bm = new Bitmap();

            bm.Init(sheight, swidth, border);
            bm.Grays = (1 + (subsample * subsample));

            for (int blitno = 0; blitno < Blits.Count;)
            {
                JB2Blit  pblit  = GetBlit(blitno++);
                JB2Shape pshape = GetShape(pblit.ShapeNumber);

                if (pshape.Bitmap != null)
                {
                    bm.Blit(pshape.Bitmap, pblit.Left - rxmin, (dispy + pblit.Bottom) - rymin, subsample);
                }
            }

            return(bm);
        }
Exemple #3
0
        public virtual int AddShape(JB2Shape jb2Shape)
        {
            if (jb2Shape.Parent >= ShapeCount)
            {
                throw new ArgumentException("Image bad parent shape");
            }

            int retval = InheritedShapes + _Shapes.Count;

            _Shapes.Add(jb2Shape);
            return(retval);
        }
Exemple #4
0
        public virtual JB2Shape Duplicate()
        {
            JB2Shape retval = new JB2Shape
            {
                Bitmap   = Bitmap?.Duplicate(),
                Parent   = Parent,
                UserData = UserData
            };

            // TODO test bitmap copy logic

            return(retval);
        }
Exemple #5
0
        public virtual JB2Shape Duplicate()
        {
            JB2Shape retval = new JB2Shape {
                _bitmap = _bitmap, Bitmap = Bitmap, Parent = Parent, UserData = UserData
            };

            if (retval._bitmap != null)
            {
                retval._bitmap = retval._bitmap.Duplicate();
            }

            return(retval);
        }
Exemple #6
0
        protected virtual int AddLibrary(int shapeno, JB2Shape jshp)
        {
            int libno = Lib2Shape.Count;

            Lib2Shape.Add(shapeno);
            Shape2Lib(shapeno, libno);

            //final Rectangle r = new Rectangle();
            //libinfo.addElement(r);
            //jshp.getGBitmap().compute_bounding_box(r);
            _libinfo.Add(jshp.Bitmap.ComputeBoundingBox());

            return(libno);
        }
Exemple #7
0
        public virtual JB2Shape Duplicate()
        {
            JB2Shape retval = new JB2Shape
            {
                Bitmap   = Bitmap?.Duplicate(),
                Parent   = Parent,
                UserData = UserData
            };

            // TODO test bitmap copy logic

            //if (retval.Bitmap != null)
            //    retval.Bitmap = retval.Bitmap.Duplicate();

            return(retval);
        }
Exemple #8
0
        public Bitmap GetBitmap(Rectangle rect, int subsample, int align, int dispy, List <int> components)
        {
            if (components == null)
            {
                return(GetBitmap(rect, subsample, align, dispy));
            }

            if ((Width == 0) || (Height == 0))
            {
                throw new DjvuFormatException(
                          $"Image is empty can not be used to create bitmap. Width: {Width}, Height {Height}");
            }

            Verify.SubsampleRange(subsample);

            int    rxmin   = rect.Right * subsample;
            int    rymin   = rect.Bottom * subsample;
            int    swidth  = rect.Width;
            int    sheight = rect.Height;
            int    border  = (((swidth + align) - 1) & ~(align - 1)) - swidth;
            Bitmap bm      = new Bitmap();

            bm.Init(sheight, swidth, border);
            bm.Grays = (1 + (subsample * subsample));

            for (int blitno = 0; blitno < Blits.Count;)
            {
                JB2Blit  pblit  = GetBlit(blitno++);
                JB2Shape pshape = GetShape(pblit.ShapeNumber);

                if (pshape.Bitmap != null)
                {
                    if (bm.Blit(pshape.Bitmap, pblit.Left - rxmin, (dispy + pblit.Bottom) - rymin, subsample))
                    {
                        components.Add((blitno - 1));
                    }
                }
            }

            return(bm);
        }
Exemple #9
0
        protected virtual void InitLibrary(JB2Dictionary jim)
        {
            int nshape = jim.InheritedShapes;

            shape2lib_Renamed_Field.Clear();
            Lib2Shape.Clear();
            _libinfo.Clear();

            for (int i = 0; i < nshape; i++)
            {
                int x = i;
                shape2lib_Renamed_Field.Add(x);
                Lib2Shape.Add(x);

                JB2Shape jshp = jim.GetShape(i);
                //final Rectangle  r = new Rectangle();
                //libinfo.addElement(r);
                //jshp.getGBitmap().compute_bounding_box(r);
                _libinfo.Add(jshp.Bitmap.ComputeBoundingBox());
            }
        }
Exemple #10
0
        public Bitmap GetBitmap(int subsample, int align)
        {
            Verify.SubsampleRange(subsample);

            if ((Width == 0) || (Height == 0))
            {
                throw new DjvuFormatException(
                          $"Image is empty and can not be used to create bitmap. Width: {Width}, Height {Height}");
            }

            int swidth  = ((Width + subsample) - 1) / subsample;
            int sheight = ((Height + subsample) - 1) / subsample;
            int border  = (((swidth + align) - 1) & ~(align - 1)) - swidth;

            Bitmap bm = new Bitmap();

            bm.Init(sheight, swidth, border);
            bm.Grays = (1 + (subsample * subsample));

            for (int blitno = 0; blitno < Blits.Count; blitno++)
            //Parallel.For(
            //    0,
            //    Blits.Count,
            //    blitno =>
            //    {
            {
                JB2Blit  pblit  = GetBlit(blitno);
                JB2Shape pshape = GetShape(pblit.ShapeNumber);

                if (pshape.Bitmap != null)
                {
                    bm.Blit(pshape.Bitmap, pblit.Left, pblit.Bottom, subsample);
                }
                //});
            }

            return(bm);
        }
Exemple #11
0
        public PixelMap GetPixelMap(ColorPalette palette, int subsample, int align)
        {
            Verify.SubsampleRange(subsample);

            if ((Width == 0) || (Height == 0))
            {
                throw new DjvuFormatException(
                          $"Image is empty and can not be used to create bitmap. Width: {Width}, Height {Height}");
            }

            int swidth  = ((Width + subsample) - 1) / subsample;
            int sheight = ((Height + subsample) - 1) / subsample;
            int border  = (((swidth + align) - 1) & ~(align - 1)) - swidth;

            PixelMap pixelMap = new PixelMap(new sbyte[swidth * sheight * 3], swidth, sheight);

            for (int blitno = 0; blitno < Blits.Count; blitno++)
            //Parallel.For(
            //    0,
            //    Blits.Count,
            //    blitno =>
            //    {
            {
                JB2Blit  pblit  = GetBlit(blitno);
                JB2Shape pshape = GetShape(pblit.ShapeNumber);
                Pixel    color  = palette.PaletteColors[palette.BlitColors[blitno]];

                if (pshape.Bitmap != null)
                {
                    pixelMap.Blit(pshape.Bitmap, pblit.Left, pblit.Bottom, color);
                }
                //});
            }

            return(pixelMap);
        }
Exemple #12
0
        protected virtual int CodeRecordB(int rectype, JB2Image jim, JB2Shape xjshp, JB2Blit xjblt)
        {
            Bitmap   bm      = null;
            int      shapeno = -1;
            JB2Shape jshp    = xjshp;
            JB2Blit  jblt    = xjblt;

            rectype = CodeRecordType(rectype);

            switch (rectype)
            {
            case NewMark:
            case NewMarkImageOnly:
            case MatchedRefine:
            case MatchedRefineImageOnly:
            case NonMarkData:
            {
                if (jblt == null)
                {
                    jblt = new JB2Blit();
                }

                // fall through
            }
                goto case NewMarkLibraryOnly;

            case NewMarkLibraryOnly:
            case MatchedRefineLibraryOnly:
            {
                if (!_encoding)
                {
                    jshp = new JB2Shape().Init((rectype == NonMarkData) ? (-2) : (-1));
                }
                else if (jshp == null)
                {
                    jshp = new JB2Shape();
                }

                bm = jshp.Bitmap;

                break;
            }

            case MatchedCopy:
            {
                if (jblt == null)
                {
                    jblt = new JB2Blit();
                }

                break;
            }
            }

            bool needAddLibrary = false;
            bool needAddBlit    = false;

            switch (rectype)
            {
            case StartOfData:
            {
                CodeImageSize(jim);
                CodeEventualLosslessRefinement();

                if (!_encoding)
                {
                    InitLibrary(jim);
                }

                break;
            }

            case NewMark:
            {
                needAddBlit = needAddLibrary = true;
                CodeAbsoluteMarkSize(bm, 4);
                CodeBitmapDirectly(bm);
                CodeRelativeLocation(jblt, bm.ImageHeight, bm.ImageWidth);

                break;
            }

            case NewMarkLibraryOnly:
            {
                needAddLibrary = true;
                CodeAbsoluteMarkSize(bm, 4);
                CodeBitmapDirectly(bm);

                break;
            }

            case NewMarkImageOnly:
            {
                needAddBlit = true;
                CodeAbsoluteMarkSize(bm, 3);
                CodeBitmapDirectly(bm);
                CodeRelativeLocation(jblt, bm.ImageHeight, bm.ImageWidth);

                break;
            }

            case MatchedRefine:
            {
                needAddBlit    = true;
                needAddLibrary = true;

                int match = CodeMatchIndex(jshp.Parent, jim);

                if (!_encoding)
                {
                    jshp.Parent = Convert.ToInt32((Lib2Shape[match]));
                }

                Bitmap    cbm    = jim.GetShape(jshp.Parent).Bitmap;
                Rectangle lmatch = (Rectangle)_libinfo[match];
                CodeRelativeMarkSize(bm, (1 + lmatch.Left) - lmatch.Right, (1 + lmatch.Top) - lmatch.Bottom, 4);

                //          verbose("2.d time="+System.currentTimeMillis()+",rectype="+rectype);
                CodeBitmapByCrossCoding(bm, cbm, match);

                //          verbose("2.e time="+System.currentTimeMillis()+",rectype="+rectype);
                CodeRelativeLocation(jblt, bm.ImageHeight, bm.ImageWidth);

                break;
            }

            case MatchedRefineLibraryOnly:
            {
                needAddLibrary = true;

                int match = CodeMatchIndex(jshp.Parent, jim);

                if (!_encoding)
                {
                    jshp.Parent = Convert.ToInt32((Lib2Shape[match]));
                }

                Bitmap    cbm    = jim.GetShape(jshp.Parent).Bitmap;
                Rectangle lmatch = (Rectangle)_libinfo[match];
                CodeRelativeMarkSize(bm, (1 + lmatch.Left) - lmatch.Right, (1 + lmatch.Top) - lmatch.Bottom, 4);

                break;
            }

            case MatchedRefineImageOnly:
            {
                needAddBlit = true;

                int match = CodeMatchIndex(jshp.Parent, jim);

                if (!_encoding)
                {
                    jshp.Parent = Convert.ToInt32((Lib2Shape[match]));
                }

                Bitmap    cbm    = jim.GetShape(jshp.Parent).Bitmap;
                Rectangle lmatch = (Rectangle)_libinfo[match];
                CodeRelativeMarkSize(bm, (1 + lmatch.Left) - lmatch.Right, (1 + lmatch.Top) - lmatch.Bottom, 4);
                CodeBitmapByCrossCoding(bm, cbm, match);
                CodeRelativeLocation(jblt, bm.ImageHeight, bm.ImageWidth);

                break;
            }

            case MatchedCopy:
            {
                int match = CodeMatchIndex(jblt.ShapeNumber, jim);

                if (!_encoding)
                {
                    jblt.ShapeNumber = Convert.ToInt32((Lib2Shape[match]));
                }

                bm = jim.GetShape(jblt.ShapeNumber).Bitmap;

                Rectangle lmatch = (Rectangle)_libinfo[match];
                jblt.Left   += lmatch.Right;
                jblt.Bottom += lmatch.Bottom;

                CodeRelativeLocation(jblt, (1 + lmatch.Top) - lmatch.Bottom,
                                     (1 + lmatch.Left) - lmatch.Right);

                jblt.Left   -= lmatch.Right;
                jblt.Bottom -= lmatch.Bottom;

                break;
            }

            case NonMarkData:
            {
                needAddBlit = true;
                CodeAbsoluteMarkSize(bm, 3);
                CodeBitmapDirectly(bm);
                CodeAbsoluteLocation(jblt, bm.ImageHeight, bm.ImageWidth);

                break;
            }

            case PreservedComment:
            {
                jim.Comment = CodeComment(jim.Comment);

                break;
            }

            case RequiredDictOrReset:
            {
                if (!GotStartRecordP)
                {
                    CodeInheritedShapeCount(jim);
                }
                else
                {
                    ResetNumcoder();
                }

                break;
            }

            case EndOfData:
                break;

            default:
                throw new ArgumentException("Image unknown type");
            }

            if (!_encoding)
            {
                switch (rectype)
                {
                case NewMark:
                case NewMarkLibraryOnly:
                case MatchedRefine:
                case MatchedRefineLibraryOnly:
                case NewMarkImageOnly:
                case MatchedRefineImageOnly:
                case NonMarkData:
                {
                    if (xjshp != null)
                    {
                        jshp = jshp.Duplicate();
                    }

                    shapeno = jim.AddShape(jshp);
                    Shape2Lib(shapeno, MinusOneObject);

                    if (needAddLibrary)
                    {
                        AddLibrary(shapeno, jshp);
                    }

                    if (needAddBlit)
                    {
                        jblt.ShapeNumber = shapeno;

                        if (xjblt != null)
                        {
                            jblt = (JB2Blit)xjblt.Duplicate();
                        }

                        jim.AddBlit(jblt);
                    }

                    break;
                }

                case MatchedCopy:
                {
                    if (xjblt != null)
                    {
                        jblt = (JB2Blit)xjblt.Duplicate();
                    }

                    jim.AddBlit(jblt);

                    break;
                }
                }
            }

            return(rectype);
        }
Exemple #13
0
        protected virtual int CodeRecordA(int rectype, JB2Dictionary jim, JB2Shape xjshp)
        {
            Bitmap bm      = null;
            int    shapeno = -1;

            rectype = CodeRecordType(rectype);

            JB2Shape jshp = xjshp;

            switch (rectype)
            {
            case NewMarkLibraryOnly:
            case MatchedRefineLibraryOnly:
            {
                if (!_encoding)
                {
                    jshp = new JB2Shape().Init(-1);
                }
                else if (jshp == null)
                {
                    jshp = new JB2Shape();
                }

                bm = jshp.Bitmap;

                break;
            }
            }

            switch (rectype)
            {
            case StartOfData:
            {
                CodeImageSize(jim);
                CodeEventualLosslessRefinement();

                if (!_encoding)
                {
                    InitLibrary(jim);
                }

                break;
            }

            case NewMarkLibraryOnly:
            {
                CodeAbsoluteMarkSize(bm, 4);
                CodeBitmapDirectly(bm);

                break;
            }

            case MatchedRefineLibraryOnly:
            {
                int match = CodeMatchIndex(jshp.Parent, jim);

                if (!_encoding)
                {
                    jshp.Parent = Convert.ToInt32((Lib2Shape[match]));
                }

                Bitmap    cbm    = jim.GetShape(jshp.Parent).Bitmap;
                Rectangle lmatch = (Rectangle)_libinfo[match];
                CodeRelativeMarkSize(bm, (1 + lmatch.Left) - lmatch.Right, (1 + lmatch.Top) - lmatch.Bottom, 4);
                CodeBitmapByCrossCoding(bm, cbm, jshp.Parent);

                break;
            }

            case PreservedComment:
            {
                jim.Comment = CodeComment(jim.Comment);

                break;
            }

            case RequiredDictOrReset:
            {
                if (!GotStartRecordP)
                {
                    CodeInheritedShapeCount(jim);
                }
                else
                {
                    ResetNumcoder();
                }

                break;
            }

            case EndOfData:
                break;

            default:
                throw new ArgumentException("Image bad type");
            }

            if (!_encoding)
            {
                switch (rectype)
                {
                case NewMarkLibraryOnly:
                case MatchedRefineLibraryOnly:
                {
                    if (xjshp != null)
                    {
                        jshp = jshp.Duplicate();
                    }

                    shapeno = jim.AddShape(jshp);
                    AddLibrary(shapeno, jshp);

                    break;
                }
                }
            }

            return(rectype);
        }
Exemple #14
0
        protected virtual int AddLibrary(int shapeno, JB2Shape jshp)
        {
            int libno = Lib2Shape.Count;
            Lib2Shape.Add(shapeno);
            Shape2Lib(shapeno, libno);

            //final Rectangle r = new Rectangle();
            //libinfo.addElement(r);
            //jshp.getGBitmap().compute_bounding_box(r);
            _libinfo.Add(jshp.Bitmap.ComputeBoundingBox());

            return libno;
        }
Exemple #15
0
        protected virtual int CodeRecordB(int rectype, JB2Image jim, JB2Shape xjshp, JB2Blit xjblt)
        {
            Bitmap bm = null;
            int shapeno = -1;
            JB2Shape jshp = xjshp;
            JB2Blit jblt = xjblt;
            rectype = CodeRecordType(rectype);

            switch (rectype)
            {
                case NewMark:
                case NewMarkImageOnly:
                case MatchedRefine:
                case MatchedRefineImageOnly:
                case NonMarkData:
                    {
                        if (jblt == null)
                        {
                            jblt = new JB2Blit();
                        }

                        // fall through
                    }
                    goto case NewMarkLibraryOnly;

                case NewMarkLibraryOnly:
                case MatchedRefineLibraryOnly:
                    {
                        if (!_encoding)
                        {
                            jshp = new JB2Shape().Init((rectype == NonMarkData) ? (-2) : (-1));
                        }
                        else if (jshp == null)
                        {
                            jshp = new JB2Shape();
                        }

                        bm = jshp.Bitmap;

                        break;
                    }

                case MatchedCopy:
                    {
                        if (jblt == null)
                        {
                            jblt = new JB2Blit();
                        }

                        break;
                    }
            }

            bool needAddLibrary = false;
            bool needAddBlit = false;

            switch (rectype)
            {
                case StartOfData:
                    {
                        CodeImageSize(jim);
                        CodeEventualLosslessRefinement();

                        if (!_encoding)
                        {
                            InitLibrary(jim);
                        }

                        break;
                    }

                case NewMark:
                    {
                        needAddBlit = needAddLibrary = true;
                        CodeAbsoluteMarkSize(bm, 4);
                        CodeBitmapDirectly(bm);
                        CodeRelativeLocation(jblt, bm.ImageHeight, bm.ImageWidth);

                        break;
                    }

                case NewMarkLibraryOnly:
                    {
                        needAddLibrary = true;
                        CodeAbsoluteMarkSize(bm, 4);
                        CodeBitmapDirectly(bm);

                        break;
                    }

                case NewMarkImageOnly:
                    {
                        needAddBlit = true;
                        CodeAbsoluteMarkSize(bm, 3);
                        CodeBitmapDirectly(bm);
                        CodeRelativeLocation(jblt, bm.ImageHeight, bm.ImageWidth);

                        break;
                    }

                case MatchedRefine:
                    {
                        needAddBlit = true;
                        needAddLibrary = true;

                        int match = CodeMatchIndex(jshp.Parent, jim);

                        if (!_encoding)
                        {
                            jshp.Parent = Convert.ToInt32((Lib2Shape[match]));
                        }

                        Bitmap cbm = jim.GetShape(jshp.Parent).Bitmap;
                        Rectangle lmatch = (Rectangle)_libinfo[match];
                        CodeRelativeMarkSize(bm, (1 + lmatch.Left) - lmatch.Right, (1 + lmatch.Top) - lmatch.Bottom, 4);

                        //          verbose("2.d time="+System.currentTimeMillis()+",rectype="+rectype);
                        CodeBitmapByCrossCoding(bm, cbm, match);

                        //          verbose("2.e time="+System.currentTimeMillis()+",rectype="+rectype);
                        CodeRelativeLocation(jblt, bm.ImageHeight, bm.ImageWidth);

                        break;
                    }

                case MatchedRefineLibraryOnly:
                    {
                        needAddLibrary = true;

                        int match = CodeMatchIndex(jshp.Parent, jim);

                        if (!_encoding)
                        {
                            jshp.Parent = Convert.ToInt32((Lib2Shape[match]));
                        }

                        Bitmap cbm = jim.GetShape(jshp.Parent).Bitmap;
                        Rectangle lmatch = (Rectangle)_libinfo[match];
                        CodeRelativeMarkSize(bm, (1 + lmatch.Left) - lmatch.Right, (1 + lmatch.Top) - lmatch.Bottom, 4);

                        break;
                    }

                case MatchedRefineImageOnly:
                    {
                        needAddBlit = true;

                        int match = CodeMatchIndex(jshp.Parent, jim);

                        if (!_encoding)
                        {
                            jshp.Parent = Convert.ToInt32((Lib2Shape[match]));
                        }

                        Bitmap cbm = jim.GetShape(jshp.Parent).Bitmap;
                        Rectangle lmatch = (Rectangle)_libinfo[match];
                        CodeRelativeMarkSize(bm, (1 + lmatch.Left) - lmatch.Right, (1 + lmatch.Top) - lmatch.Bottom, 4);
                        CodeBitmapByCrossCoding(bm, cbm, match);
                        CodeRelativeLocation(jblt, bm.ImageHeight, bm.ImageWidth);

                        break;
                    }

                case MatchedCopy:
                    {
                        int match = CodeMatchIndex(jblt.ShapeNumber, jim);

                        if (!_encoding)
                        {
                            jblt.ShapeNumber = Convert.ToInt32((Lib2Shape[match]));
                        }

                        bm = jim.GetShape(jblt.ShapeNumber).Bitmap;

                        Rectangle lmatch = (Rectangle)_libinfo[match];
                        jblt.Left += lmatch.Right;
                        jblt.Bottom += lmatch.Bottom;

                        CodeRelativeLocation(jblt, (1 + lmatch.Top) - lmatch.Bottom,
                                               (1 + lmatch.Left) - lmatch.Right);

                        jblt.Left -= lmatch.Right;
                        jblt.Bottom -= lmatch.Bottom;

                        break;
                    }

                case NonMarkData:
                    {
                        needAddBlit = true;
                        CodeAbsoluteMarkSize(bm, 3);
                        CodeBitmapDirectly(bm);
                        CodeAbsoluteLocation(jblt, bm.ImageHeight, bm.ImageWidth);

                        break;
                    }

                case PreservedComment:
                    {
                        jim.Comment = CodeComment(jim.Comment);

                        break;
                    }

                case RequiredDictOrReset:
                    {
                        if (!GotStartRecordP)
                        {
                            CodeInheritedShapeCount(jim);
                        }
                        else
                        {
                            ResetNumcoder();
                        }

                        break;
                    }

                case EndOfData:
                    break;

                default:
                    throw new ArgumentException("Image unknown type");
            }

            if (!_encoding)
            {
                switch (rectype)
                {
                    case NewMark:
                    case NewMarkLibraryOnly:
                    case MatchedRefine:
                    case MatchedRefineLibraryOnly:
                    case NewMarkImageOnly:
                    case MatchedRefineImageOnly:
                    case NonMarkData:
                        {
                            if (xjshp != null)
                            {
                                jshp = jshp.Duplicate();
                            }

                            shapeno = jim.AddShape(jshp);
                            Shape2Lib(shapeno, MinusOneObject);

                            if (needAddLibrary)
                            {
                                AddLibrary(shapeno, jshp);
                            }

                            if (needAddBlit)
                            {
                                jblt.ShapeNumber = shapeno;

                                if (xjblt != null)
                                {
                                    jblt = (JB2Blit)xjblt.Duplicate();
                                }

                                jim.AddBlit(jblt);
                            }

                            break;
                        }

                    case MatchedCopy:
                        {
                            if (xjblt != null)
                            {
                                jblt = (JB2Blit)xjblt.Duplicate();
                            }

                            jim.AddBlit(jblt);

                            break;
                        }
                }
            }

            return rectype;
        }
Exemple #16
0
        protected virtual int CodeRecordA(int rectype, JB2Dictionary jim, JB2Shape xjshp)
        {
            Bitmap bm = null;
            int shapeno = -1;
            rectype = CodeRecordType(rectype);

            JB2Shape jshp = xjshp;

            switch (rectype)
            {
                case NewMarkLibraryOnly:
                case MatchedRefineLibraryOnly:
                    {
                        if (!_encoding)
                        {
                            jshp = new JB2Shape().Init(-1);
                        }
                        else if (jshp == null)
                        {
                            jshp = new JB2Shape();
                        }

                        bm = jshp.Bitmap;

                        break;
                    }
            }

            switch (rectype)
            {
                case StartOfData:
                    {
                        CodeImageSize(jim);
                        CodeEventualLosslessRefinement();

                        if (!_encoding)
                        {
                            InitLibrary(jim);
                        }

                        break;
                    }

                case NewMarkLibraryOnly:
                    {
                        CodeAbsoluteMarkSize(bm, 4);
                        CodeBitmapDirectly(bm);

                        break;
                    }

                case MatchedRefineLibraryOnly:
                    {
                        int match = CodeMatchIndex(jshp.Parent, jim);

                        if (!_encoding)
                        {
                            jshp.Parent = Convert.ToInt32((Lib2Shape[match]));
                        }

                        Bitmap cbm = jim.GetShape(jshp.Parent).Bitmap;
                        Rectangle lmatch = (Rectangle)_libinfo[match];
                        CodeRelativeMarkSize(bm, (1 + lmatch.Left) - lmatch.Right, (1 + lmatch.Top) - lmatch.Bottom, 4);
                        CodeBitmapByCrossCoding(bm, cbm, jshp.Parent);

                        break;
                    }

                case PreservedComment:
                    {
                        jim.Comment = CodeComment(jim.Comment);

                        break;
                    }

                case RequiredDictOrReset:
                    {
                        if (!GotStartRecordP)
                        {
                            CodeInheritedShapeCount(jim);
                        }
                        else
                        {
                            ResetNumcoder();
                        }

                        break;
                    }

                case EndOfData:
                    break;

                default:
                    throw new ArgumentException("Image bad type");
            }

            if (!_encoding)
            {
                switch (rectype)
                {
                    case NewMarkLibraryOnly:
                    case MatchedRefineLibraryOnly:
                        {
                            if (xjshp != null)
                            {
                                jshp = jshp.Duplicate();
                            }

                            shapeno = jim.AddShape(jshp);
                            AddLibrary(shapeno, jshp);

                            break;
                        }
                }
            }

            return rectype;
        }
Exemple #17
0
        public virtual JB2Shape Duplicate()
        {
            JB2Shape retval = new JB2Shape { _bitmap = _bitmap, Bitmap = Bitmap, Parent = Parent, UserData = UserData };

            if (retval._bitmap != null)
            {
                retval._bitmap = retval._bitmap.Duplicate();
            }

            return retval;
        }