コード例 #1
0
ファイル: JB2Image.cs プロジェクト: fel88/CommonLibs
        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);
        }
コード例 #2
0
ファイル: JB2Image.cs プロジェクト: fel88/CommonLibs
        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);
        }
コード例 #3
0
        protected override void CodeAbsoluteLocation(JB2Blit jblt, int rows, int columns)
        {
            if (!_GotStartRecordP)
            {
                throw new DjvuFormatException("Image no start");
            }

            int left = CodeNum(1, _ImageColumns, _AbsLocX);
            int top  = CodeNum(1, _ImageRows, _AbsLocY);

            jblt.Bottom = top - rows;
            jblt.Left   = left - 1;
        }
コード例 #4
0
ファイル: JB2Image.cs プロジェクト: fel88/CommonLibs
        public virtual int AddBlit(JB2Blit jb2Blit)
        {
            if (jb2Blit.ShapeNumber >= ShapeCount)
            {
                throw new ArgumentException("Image bad shape");
            }

            int retval = _blits.Count;

            _blits.Add(jb2Blit);

            return(retval);
        }
コード例 #5
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);
        }
コード例 #6
0
ファイル: JB2Image.cs プロジェクト: rodrigoieh/DjvuNet
        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);
        }
コード例 #7
0
ファイル: JB2Image.cs プロジェクト: rodrigoieh/DjvuNet
        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);
        }
コード例 #8
0
        protected virtual void CodeRelativeLocation(JB2Blit jblt, int rows, int columns)
        {
            if (!GotStartRecordP)
            {
                throw new SystemException("Image no start");
            }

            int bottom = 0;
            int left   = 0;
            int top    = 0;
            int right  = 0;

            if (_encoding)
            {
                left   = jblt.Left + 1;
                bottom = jblt.Bottom + 1;
                right  = (left + columns) - 1;
                top    = (bottom + rows) - 1;
            }

            bool new_row = CodeBit((left < _lastLeft), _offsetTypeDist);

            if (new_row)
            {
                int x_diff = GetDiff(left - _lastRowLeft, rel_loc_x_last);
                int y_diff = GetDiff(top - _lastRowBottom, rel_loc_y_last);

                if (!_encoding)
                {
                    left   = _lastRowLeft + x_diff;
                    top    = _lastRowBottom + y_diff;
                    right  = (left + columns) - 1;
                    bottom = (top - rows) + 1;
                }

                _lastLeft   = _lastRowLeft = left;
                _lastRight  = right;
                _lastBottom = _lastRowBottom = bottom;
                FillShortList(bottom);
            }
            else
            {
                int x_diff = GetDiff(left - _lastRight, rel_loc_x_current);
                int y_diff = GetDiff(bottom - _lastBottom, rel_loc_y_current);

                if (!_encoding)
                {
                    left   = _lastRight + x_diff;
                    bottom = _lastBottom + y_diff;
                    right  = (left + columns) - 1;
                    top    = (bottom + rows) - 1;
                }

                _lastLeft   = left;
                _lastRight  = right;
                _lastBottom = UpdateShortList(bottom);
            }

            if (!_encoding)
            {
                jblt.Bottom = bottom - 1;
                jblt.Left   = left - 1;
            }
        }
コード例 #9
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);
        }
コード例 #10
0
 protected abstract void CodeAbsoluteLocation(JB2Blit jblt, int rows, int columns);
コード例 #11
0
ファイル: JB2Encoder.cs プロジェクト: sahwar/DjvuNet
 protected override void CodeAbsoluteLocation(JB2Blit jblt, int rows, int columns)
 {
     throw new NotImplementedException();
 }
コード例 #12
0
        protected virtual void CodeRelativeLocation(JB2Blit jblt, int rows, int columns)
        {
            if (!_GotStartRecordP)
            {
                throw new DjvuFormatException("Image no start");
            }

            int bottom = 0;
            int left   = 0;
            int top    = 0;
            int right  = 0;

            if (_Encoding)
            {
                left   = jblt.Left + 1;
                bottom = jblt.Bottom + 1;
                right  = (left + columns) - 1;
                top    = (bottom + rows) - 1;
            }

            bool new_row = CodeBit((left < _LastLeft), _OffsetTypeDist);

            if (new_row)
            {
                int x_diff = GetDiff(left - _LastRowLeft, _RelLocXLast);
                int y_diff = GetDiff(top - _LastRowBottom, _RelLocYLast);

                if (!_Encoding)
                {
                    left   = _LastRowLeft + x_diff;
                    top    = _LastRowBottom + y_diff;
                    right  = (left + columns) - 1;
                    bottom = (top - rows) + 1;
                }

                _LastLeft   = _LastRowLeft = left;
                _LastRight  = right;
                _LastBottom = _LastRowBottom = bottom;
                FillShortList(bottom);
            }
            else
            {
                int x_diff = GetDiff(left - _LastRight, _RelLocXCurrent);
                int y_diff = GetDiff(bottom - _LastBottom, _RelLocYCurrent);

                if (!_Encoding)
                {
                    left   = _LastRight + x_diff;
                    bottom = _LastBottom + y_diff;
                    right  = (left + columns) - 1;
                    top    = (bottom + rows) - 1;
                }

                _LastLeft   = left;
                _LastRight  = right;
                _LastBottom = UpdateShortList(bottom);
            }

            if (!_Encoding)
            {
                jblt.Bottom = bottom - 1;
                jblt.Left   = left - 1;
            }
        }