Example #1
0
        public virtual void SetInheritedDict(JB2Dictionary value, bool force)
        {
            if (value == null)
            {
                _inheritedDictionary = null;
                InheritedShapes      = 0;
                return;
            }

            if (force == false)
            {
                if (_Shapes.Count > 0)
                {
                    throw new DjvuFormatException("Can not set image.");
                }

                if (InheritedDictionary != null)
                {
                    throw new DjvuFormatException("Image can not be changed.");
                }
            }

            _inheritedDictionary = value;
            InheritedShapes      = value.ShapeCount;

            //    for (int i=0; i<inherited_shapes; i++)
            //    {
            //      Shape jshp = dict.get_shape(i);
            //      if (jshp.bits != null) jshp.bits.share();
            //    }
        }
Example #2
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");
            }
        }
Example #3
0
        public virtual void Decode(IBinaryReader gbs, JB2Dictionary zdict)
        {
            Init();
            JB2Decoder codec = new JB2Decoder();

            codec.Init(gbs, zdict);
            codec.Code(this);
        }
Example #4
0
 protected virtual void CodeImageSize(JB2Dictionary ignored)
 {
     _lastLeft      = 1;
     _lastRowBottom = 0;
     _lastRowLeft   = _lastRight = 0;
     FillShortList(_lastRowBottom);
     GotStartRecordP = true;
 }
Example #5
0
        public override void Decode(BinaryReader gbs, JB2Dictionary zdict)
        {
            Init();

            JB2Decoder codec = new JB2Decoder();

            codec.Init(gbs, zdict);
            codec.Code(this);
        }
Example #6
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);
        }
Example #7
0
        protected override void CodeImageSize(JB2Dictionary jim)
        {
            int w = CodeNum(0, Bigpositive, _ImageSizeDist);
            int h = CodeNum(0, Bigpositive, _ImageSizeDist);

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

            base.CodeImageSize(jim);
        }
Example #8
0
        public void Code(JB2Dictionary jim)
        {
            int rectype = StartOfData;

            do
            {
                rectype = CodeRecordA(rectype, jim, null);
            } while (rectype != EndOfData);

            if (!_GotStartRecordP)
            {
                throw new DjvuFormatException("Image has no start record");
            }
        }
Example #9
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");
            }
        }
Example #10
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);
        }
Example #11
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());
            }
        }
Example #12
0
        protected override void CodeInheritedShapeCount(JB2Dictionary jim)
        {
            int           size = CodeNum(0, Bigpositive, _InheritedShapeCountDist);
            JB2Dictionary dict = jim.InheritedDictionary;

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

            if ((dict != null) && (size != dict.ShapeCount))
            {
                throw new DjvuFormatException("Image dictionary is invalid");
            }
        }
Example #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);
        }
Example #14
0
 public virtual void Init(BinaryReader gbs, JB2Dictionary zdict)
 {
     this._zdict = zdict;
     _zp         = new ZPCodec(gbs.BaseStream);
 }
Example #15
0
 public void Init(IBinaryReader gbs, JB2Dictionary zdict)
 {
     this._ZDict = zdict;
     _Coder      = new ZPCodec(gbs.BaseStream);
 }
Example #16
0
 protected override void CodeInheritedShapeCount(JB2Dictionary jim)
 {
     throw new NotImplementedException();
 }
Example #17
0
        protected override int CodeMatchIndex(int index, JB2Dictionary ignored)
        {
            int result = CodeNum(0, _Lib2Shape.Count - 1, _DistMatchIndex);

            return(result);
        }
Example #18
0
 protected override int CodeMatchIndex(int index, JB2Dictionary jim)
 {
     throw new NotImplementedException();
 }
Example #19
0
 protected abstract int CodeMatchIndex(int index, JB2Dictionary jim);
Example #20
0
 protected abstract void CodeInheritedShapeCount(JB2Dictionary jim);