Example #1
0
        protected virtual void CodeBitmapDirectly(Bitmap bm)
        {
            lock (bm)
            {
                bm.MinimumBorder = 3;

                int dy = bm.ImageHeight - 1;
                CodeBitmapDirectly(bm, bm.ImageWidth, dy, bm.RowOffset(dy + 2), bm.RowOffset(dy + 1), bm.RowOffset(dy));
            }
        }
Example #2
0
        protected virtual void CodeBitmapByCrossCoding(Bitmap bm, Bitmap cbm, int libno)
        {
            // Bitmap cbm=new Bitmap();
            // synchronized(xcbm)
            // {
            //   cbm.init(xcbm);
            // }
            lock (bm)
            {
                int cw = cbm.ImageWidth;
                int dw = bm.ImageWidth;
                int dh = bm.ImageHeight;
                Rectangle lmatch = (Rectangle)_libinfo[libno];
                //int xd2c = ((1 + (dw / 2)) - dw) - ((((1 + lmatch.Left) - lmatch.Right) / 2) - lmatch.Left);
                //int yd2c = ((1 + (dh / 2)) - dh) - ((((1 + lmatch.Top) - lmatch.Bottom) / 2) - lmatch.Top);

                int xd2c = ((1 + (dw >> 1)) - dw) - ((((1 + lmatch.Left) - lmatch.Right) >> 1) - lmatch.Left);
                int yd2c = ((1 + (dh >> 1)) - dh) - ((((1 + lmatch.Top) - lmatch.Bottom) >> 1) - lmatch.Top);

                bm.MinimumBorder = 2;
                cbm.MinimumBorder = 2 - xd2c;
                cbm.MinimumBorder = (2 + dw + xd2c) - cw;

                int dy = dh - 1;
                int cy = dy + yd2c;
                CodeBitmapByCrossCoding(bm, cbm, xd2c, dw, dy, cy, bm.RowOffset(dy + 1), bm.RowOffset(dy),
                                            cbm.RowOffset(cy + 1) + xd2c, cbm.RowOffset(cy) + xd2c,
                                            cbm.RowOffset(cy - 1) + xd2c);
            }
        }
Example #3
0
 protected abstract void CodeBitmapDirectly(Bitmap bm, int dw, int dy, int up2, int up1, int up0);
Example #4
0
 /// <summary>
 /// Creates a new Shape object.
 /// </summary>
 public JB2Shape()
 {
     Parent = 0;
     _bitmap = null;
 }
Example #5
0
 protected abstract void CodeBitmapByCrossCoding(Bitmap bm, Bitmap cbm, int xd2c, int dw, int dy,
     int cy, int up1, int up0, int xup1, int xup0,
     int xdn1);
Example #6
0
 protected int GetCrossContext(Bitmap bm, Bitmap cbm, int up1, int up0, int xup1, int xup0, int xdn1,
     int column)
 {
     return ((bm.GetByteAt((up1 + column) - 1) << 10) | (bm.GetByteAt(up1 + column) << 9) |
             (bm.GetByteAt(up1 + column + 1) << 8) | (bm.GetByteAt((up0 + column) - 1) << 7) |
             (cbm.GetByteAt(xup1 + column) << 6) | (cbm.GetByteAt((xup0 + column) - 1) << 5) |
             (cbm.GetByteAt(xup0 + column) << 4) | (cbm.GetByteAt(xup0 + column + 1) << 3) |
             (cbm.GetByteAt((xdn1 + column) - 1) << 2) | (cbm.GetByteAt(xdn1 + column) << 1) |
             (cbm.GetByteAt(xdn1 + column + 1)));
 }
Example #7
0
 protected int ShiftCrossContext(Bitmap bm, Bitmap cbm, int context, int n, int up1, int up0,
     int xup1, int xup0, int xdn1, int column)
 {
     return (((context << 1) & 0x636) | (bm.GetByteAt(up1 + column + 1) << 8) |
             (cbm.GetByteAt(xup1 + column) << 6) | (cbm.GetByteAt(xup0 + column + 1) << 3) |
             (cbm.GetByteAt(xdn1 + column + 1)) | (n << 7));
 }
Example #8
0
        protected override void CodeBitmapDirectly(Bitmap bm, int dw, int dy, int up2, int up1, int up0)
        {
            while (dy >= 0)
            {
                int context = GetDirectContext(bm, up2, up1, up0, 0);

                for (int dx = 0; dx < dw; )
                {
                    int n = CodeBit(false, Bitdist, context);

                    bm.SetByteAt(up0 + dx++, n);
                    context = ShiftDirectContext(bm, context, n, up2, up1, up0, dx);
                }

                up2 = up1;
                up1 = up0;
                up0 = bm.RowOffset(--dy);
            }
        }
Example #9
0
        protected override void CodeRelativeMarkSize(Bitmap bm, int cw, int ch, int border)
        {
            //Console.WriteLine("Jb2D crms(b i i i) cw: " + cw);
            //Console.WriteLine("Jb2D crms(b i i i) ch: " + ch);
            //Console.WriteLine("Jb2D crms(b i i i) border: " + border);

            //Console.WriteLine("Jb2D crms(b i i i) rel_size_x: " + rel_size_x.Value);
            //Console.WriteLine("Jb2D crms(b i i i) rel_size_y: " + rel_size_y.Value);

            int xdiff = CodeNum(Bignegative, Bigpositive, RelSizeX);
            int ydiff = CodeNum(Bignegative, Bigpositive, RelSizeY);

            //Console.WriteLine("Jb2D crms(b i i i) xdiff: " + xdiff);
            //Console.WriteLine("Jb2D crms(b i i i) ydiff: " + ydiff);

            int xsize = cw + xdiff;
            int ysize = ch + ydiff;

            //Console.WriteLine("Jb2D crms(b i i i) xsize: " + xsize);
            //Console.WriteLine("Jb2D crms(b i i i) ysize: " + ysize);

            if ((xsize != (0xffff & xsize)) || (ysize != (0xffff & ysize)))
            {
                throw new SystemException("Image image decoder value");
            }

            bm.Init(ysize, xsize, border);
        }
Example #10
0
 public GBitmap GetBitmap(GRect rect, int subsample, int align, GBitmap retval)
 {
     return GetBitmapList(rect, 1, 1, null);
 }
Example #11
0
        protected override void CodeBitmapByCrossCoding(Bitmap bm, Bitmap cbm, int xd2c, int dw, int dy,
            int cy, int up1, int up0, int xup1, int xup0,
            int xdn1)
        {
            while (dy >= 0)
            {
                int context = GetCrossContext(bm, cbm, up1, up0, xup1, xup0, xdn1, 0);

                for (int dx = 0; dx < dw; )
                {
                    int n = CodeBit(false, Cbitdist, context);
                    bm.SetByteAt(up0 + dx++, n);
                    context = ShiftCrossContext(bm, cbm, context, n, up1, up0, xup1, xup0, xdn1, dx);
                }

                up1 = up0;
                up0 = bm.RowOffset(--dy);
                xup1 = xup0;
                xup0 = xdn1;
                xdn1 = cbm.RowOffset((--cy) - 1) + xd2c;
            }
        }
Example #12
0
        private bool Stencil(PixelMap pm, Graphics.Rectangle rect, int subsample, double gamma)
        {
            if (Info == null)
            {
                return false;
            }

            int width = Info.Width;
            int height = Info.Height;

            if ((width <= 0) || (height <= 0))
            {
                return false;
            }

            double gamma_correction = 1.0D;

            if (gamma > 0.0D)
            {
                gamma_correction = gamma / Info.Gamma;
            }

            if (gamma_correction < 0.10000000000000001D)
            {
                gamma_correction = 0.10000000000000001D;
            }
            else if (gamma_correction > 10D)
            {
                gamma_correction = 10D;
            }

            JB2Image fgJb2 = ForegroundJB2Image;

            if (fgJb2 != null)
            {
                ColorPalette fgPalette = ForegroundPalette;

                if (fgPalette != null)
                {
                    List<int> components = new List<int>();
                    GBitmap bm = GetBitmapList(rect, subsample, 1, components);

                    if (fgJb2.Blits.Count != fgPalette.BlitColors.Length)
                    {
                        pm.Attenuate(bm, 0, 0);

                        return false;
                    }

                    GPixmap colors =
                      new GPixmap().Init(
                        1,
                        fgPalette.PaletteColors.Length,
                        null);
                    GPixelReference color = colors.CreateGPixelReference(0);

                    for (int i = 0; i < colors.ImageWidth; color.IncOffset())
                    {
                        fgPalette.index_to_color(i++, color);
                    }

                    colors.ApplyGammaCorrection(gamma_correction);

                    List<int> compset = new List<int>();

                    while (components.Count > 0)
                    {
                        int lastx = 0;
                        int colorindex = fgPalette.BlitColors[((int)components[0])];
                        GRect comprect = new GRect();
                        compset = new List<int>();

                        for (int pos = 0; pos < components.Count; )
                        {
                            int blitno = ((int)components[pos]);
                            JB2Blit pblit = fgJb2.Blits[blitno];

                            if (pblit.Left < lastx)
                            {
                                break;
                            }

                            lastx = pblit.Left;

                            if (fgPalette.BlitColors[blitno] == colorindex)
                            {
                                JB2Shape pshape = fgJb2.GetShape(pblit.ShapeNumber);
                                GRect xrect =
                                  new GRect(
                                    pblit.Left,
                                    pblit.Bottom,
                                    pshape.Bitmap.ImageWidth,
                                    pshape.Bitmap.ImageHeight);
                                comprect.Recthull(comprect, xrect);
                                compset.Add(components[pos]);
                                components.Remove(pos);
                            }
                            else
                            {
                                pos++;
                            }
                        }

                        comprect.XMin /= subsample;
                        comprect.YMin /= subsample;
                        comprect.XMax = ((comprect.XMax + subsample) - 1) / subsample;
                        comprect.YMax = ((comprect.YMax + subsample) - 1) / subsample;
                        comprect.Intersect(comprect, rect);

                        if (comprect.Empty)
                        {
                            continue;
                        }

                        //        bm   = getBitmap(comprect, subsample, 1);
                        bm = new GBitmap();
                        bm.Init(
                          comprect.Height,
                          comprect.Width,
                          0);
                        bm.Grays = 1 + (subsample * subsample);

                        int rxmin = comprect.XMin * subsample;
                        int rymin = comprect.YMin * subsample;

                        for (int pos = 0; pos < compset.Count; ++pos)
                        {
                            int blitno = ((int)compset[pos]);
                            JB2Blit pblit = fgJb2.Blits[blitno];
                            JB2Shape pshape = fgJb2.GetShape(pblit.ShapeNumber);
                            bm.Blit(
                              pshape.Bitmap,
                              pblit.Left - rxmin,
                              pblit.Bottom - rymin,
                              subsample);
                        }

                        color.SetOffset(colorindex);
                        pm.Blit(
                          bm,
                          comprect.XMin - rect.XMin,
                          comprect.YMin - rect.YMin,
                          color);
                    }

                    return true;
                }

                // Three layer model.
                IWPixelMap fgIWPixmap = ForegroundIWPixelMap;

                if (fgIWPixmap != null)
                {
                    GBitmap bm = GetBitmap(rect, subsample, 1, null);

                    if ((bm != null) && (pm != null))
                    {
                        GPixmap fgPixmap = ForegroundPixelMap;
                        int w = fgPixmap.ImageWidth;
                        int h = fgPixmap.ImageHeight;
                        int red = ComputeRed(width, height, w, h);

                        //          if((red < 1) || (red > 12))
                        if ((red < 1) || (red > 16))
                        {
                            return false;
                        }
                        //
                        //          int supersample = (red <= subsample)
                        //            ? 1
                        //            : (red / subsample);
                        //          int wantedred = supersample * subsample;
                        //
                        //          if(red == wantedred)
                        //          {
                        //            pm.stencil(bm, fgPixmap, supersample, rect, gamma_correction);
                        //
                        //            return 1;
                        //          }
                        pm.Stencil(bm, fgPixmap, red, subsample, rect, gamma_correction);
                        return true;
                    }
                }
            }

            return false;
        }
Example #13
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;
        }
Example #14
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 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)
                {
                    if (bm.Blit(pshape.Bitmap, pblit.Left - rxmin, (dispy + pblit.Bottom) - rymin, subsample))
                    {
                        components.Add((blitno - 1));
                    }
                }
            }

            return bm;
        }
Example #15
0
 protected void CodeRelativeMarkSize(Bitmap bm, int cw, int ch)
 {
     CodeRelativeMarkSize(bm, cw, ch, 0);
 }
Example #16
0
        protected override void CodeAbsoluteMarkSize(Bitmap bm, int border)
        {
            int xsize = CodeNum(0, Bigpositive, AbsSizeX);
            int ysize = CodeNum(0, Bigpositive, AbsSizeY);

            if ((xsize != (0xffff & xsize)) || (ysize != (0xffff & ysize)))
            {
                throw new SystemException("Image bad number");
            }

            bm.Init(ysize, xsize, border);
        }
Example #17
0
 protected abstract void CodeRelativeMarkSize(Bitmap bm, int cw, int ch, int border);
Example #18
0
 protected void CodeAbsoluteMarkSize(Bitmap bm)
 {
     CodeAbsoluteMarkSize(bm, 0);
 }
Example #19
0
 protected int GetDirectContext(Bitmap bm, int up2, int up1, int up0, int column)
 {
     return ((bm.GetByteAt((up2 + column) - 1) << 9) | (bm.GetByteAt(up2 + column) << 8) |
             (bm.GetByteAt(up2 + column + 1) << 7) | (bm.GetByteAt((up1 + column) - 2) << 6) |
             (bm.GetByteAt((up1 + column) - 1) << 5) | (bm.GetByteAt(up1 + column) << 4) |
             (bm.GetByteAt(up1 + column + 1) << 3) | (bm.GetByteAt(up1 + column + 2) << 2) |
             (bm.GetByteAt((up0 + column) - 2) << 1) | (bm.GetByteAt((up0 + column) - 1)));
 }
Example #20
0
 protected abstract void CodeAbsoluteMarkSize(Bitmap bm, int border);
Example #21
0
 protected int ShiftDirectContext(Bitmap bm, int context, int next, int up2, int up1, int up0,
     int column)
 {
     return (((context << 1) & 0x37a) | (bm.GetByteAt(up1 + column + 2) << 2) |
             (bm.GetByteAt(up2 + column + 1) << 7) | next);
 }
Example #22
0
        public virtual JB2Shape Init(int parent)
        {
            this.Parent = parent;
            _bitmap = new Bitmap();

            return this;
        }