Esempio n. 1
0
        public override void Decode(BinaryReader gbs, JB2Dictionary zdict)
        {
            Init();

            JB2Decoder codec = new JB2Decoder();
            codec.Init(gbs, zdict);
            codec.Code(this);
        }
Esempio n. 2
0
        private JB2.JB2Dictionary DecodeShapeDictionary()
        {
            using (DjvuReader reader = Reader.CloneReader(_dataLocation, Length))
            {
                JB2.JB2Dictionary dictionary = new JB2Dictionary();
                dictionary.Decode(reader);

                return(dictionary);
            }
        }
Esempio n. 3
0
        internal JB2.JB2Dictionary DecodeShapeDictionary()
        {
            using (IDjvuReader reader = Reader.CloneReaderToMemory(DataOffset, Length))
            {
                JB2.JB2Dictionary dictionary = new JB2Dictionary();
                dictionary.Decode(reader);

                return(dictionary);
            }
        }
Esempio n. 4
0
        public virtual void Code(JB2Dictionary jim)
        {
            int rectype = StartOfData;

            do
            {
                //Console.WriteLine("Jb2D c(d) rectype in: " + rectype);
                rectype = CodeRecordA(rectype, jim, null);
                //Console.WriteLine("Jb2D c(d) rectype out: " + rectype);
            } while (rectype != EndOfData);

            if (!GotStartRecordP)
            {
                throw new SystemException("Image no start");
            }
        }
Esempio n. 5
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());
            }
        }
Esempio n. 6
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;
        }
Esempio n. 7
0
 protected abstract int CodeMatchIndex(int index, JB2Dictionary jim);
Esempio n. 8
0
 protected abstract void CodeInheritedShapeCount(JB2Dictionary jim);
Esempio n. 9
0
 protected virtual void CodeImageSize(JB2Dictionary ignored)
 {
     _lastLeft = 1;
     _lastRowBottom = 0;
     _lastRowLeft = _lastRight = 0;
     FillShortList(_lastRowBottom);
     GotStartRecordP = true;
 }
Esempio n. 10
0
 public virtual void Init(BinaryReader gbs, JB2Dictionary zdict)
 {
     this._zdict = zdict;
     _zp = new ZPCodec(gbs.BaseStream);
 }
Esempio n. 11
0
        protected override int CodeMatchIndex(int index, JB2Dictionary ignored)
        {
            //Console.WriteLine("Jb2D cmi(i d) index: " + index);
            //Console.WriteLine("Jb2D cmi(i d) lib2shape.Count: " + lib2shape.Count);
            //Console.WriteLine("Jb2D cmi(i d) dist_match_index: " + dist_match_index.Value);

            int result = CodeNum(0, Lib2Shape.Count - 1, DistMatchIndex);

            //Console.WriteLine("Jb2D cmi(i d) result: " + result);
            return result;
        }
Esempio n. 12
0
        protected override void CodeInheritedShapeCount(JB2Dictionary jim)
        {
            //Console.WriteLine("Jb2D cisc(d) inherited_shape_count_dist: " + inherited_shape_count_dist.Value);

            int size = CodeNum(0, Bigpositive, InheritedShapeCountDist);

            //Console.WriteLine("Jb2D cisc(d) size: " + size);
            //Console.WriteLine("Jb2D cisc(d) inherited_shape_count_dist: " + inherited_shape_count_dist.Value);

            JB2Dictionary dict = jim.InheritedDictionary;

            //Console.WriteLine("Jb2D cisc(d) dictnull: " + dict == null);
            //Console.WriteLine("Jb2D cisc(d) zdictnull: " + zdict == null);

            if ((dict == null) && (size > 0))
            {
                if (_zdict != null)
                {
                    dict = _zdict;
                    jim.InheritedDictionary = dict;
                }
                else
                {
                    throw new SystemException("Image dictionary not provided");
                }
            }

            if ((dict != null) && (size != dict.ShapeCount))
            {
                throw new SystemException("Image dictionary is invalid");
            }
        }
Esempio n. 13
0
        protected override void CodeImageSize(JB2Dictionary jim)
        {
            //Console.WriteLine("Jb2D cis(d) image_size_dist: " + image_size_dist.Value);

            int w = CodeNum(0, Bigpositive, ImageSizeDist);
            int h = CodeNum(0, Bigpositive, ImageSizeDist);

            //Console.WriteLine("Jb2D cis(d) w: " + w);
            //Console.WriteLine("Jb2D cis(d) h: " + h);

            //Console.WriteLine("Jb2D cis(d) image_size_dist: " + image_size_dist.Value);

            if ((w != 0) || (h != 0))
            {
                throw new SystemException("Image bad dict 2");
            }

            base.CodeImageSize(jim);
        }
Esempio n. 14
0
        private JB2.JB2Dictionary DecodeShapeDictionary()
        {
            using (DjvuReader reader = Reader.CloneReader(_dataLocation, Length))
            {
                JB2.JB2Dictionary dictionary = new JB2Dictionary();
                dictionary.Decode(reader);

                return dictionary;
            }
        }