protected virtual void CodeBitmapByCrossCoding(IBitmap bm, IBitmap cbm, int libno) { // Bitmap cbm=new Bitmap(); // synchronized(xcbm) // { // cbm.init(xcbm); // } lock (bm) { int cw = cbm.Width; int dw = bm.Width; int dh = bm.Height; 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); } }
protected virtual void CodeBitmapDirectly(IBitmap bm) { lock (bm) { bm.MinimumBorder = 3; int dy = bm.Height - 1; CodeBitmapDirectly(bm, bm.Width, dy, bm.RowOffset(dy + 2), bm.RowOffset(dy + 1), bm.RowOffset(dy)); } }
protected override void CodeBitmapDirectly(IBitmap 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++, (sbyte)n); context = ShiftDirectContext(bm, context, n, up2, up1, up0, dx); } up2 = up1; up1 = up0; up0 = bm.RowOffset(--dy); } }
protected override void CodeBitmapByCrossCoding(IBitmap bm, IBitmap 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++, (sbyte)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; } }