Ejemplo n.º 1
0
        /// <summary>
        /// Overwrite frame data
        /// </summary>
        /// <param name="prev">Frame data to apply</param>
        public void Overwrite(PPMFrame prev) // Just use current frame
        {
            if ((_firstByteHeader & 0x80) != 0)
            {
                return;
            }
            // < There is NOT a mistake anywhere
            int  ld0 = ((_translateX >= 0) ? (_translateX >> 3) : 0);
            int  pi0 = (_translateX >= 0) ? 0 : ((-_translateX) >> 3);
            byte del = (byte)(_translateX >= 0 ? (_translateX & 7) : (((byte)(_translateX)) & 7));
            byte ndel = (byte)(8 - del);
            byte alpha = (byte)((1 << (8 - del)) - 1);            byte nalpha = (byte)~alpha;            int pi, ld;            if (_translateX >= 0)

            {
                for (int y = 0; y < 192; y++)
                {
                    if (y < _translateY)
                    {
                        continue;
                    }
                    if (y - _translateY >= 192)
                    {
                        break;
                    }
                    ld = (y << 5) + ld0;                    pi = ((y - _translateY) << 5) + pi0;                    Layer1[ld] ^= (byte)(prev.Layer1[pi] & alpha);                    Layer2[ld++] ^= (byte)(prev.Layer2[pi] & alpha);                    while ((ld & 31) < 31)
                    {
                        Layer1[ld] ^= (byte)(((prev.Layer1[pi] & nalpha) >> ndel) | ((prev.Layer1[pi + 1] & alpha) << del));                        Layer2[ld] ^= (byte)(((prev.Layer2[pi] & nalpha) >> ndel) | ((prev.Layer2[pi + 1] & alpha) << del));                                                ld++; pi++;
                    }
                    Layer1[ld] ^= (byte)((prev.Layer1[pi] & nalpha) | (prev.Layer1[pi + 1] & alpha));                    Layer2[ld] ^= (byte)((prev.Layer2[pi] & nalpha) | (prev.Layer2[pi + 1] & alpha));
                }
            }
            else
            {
                for (ushort y = 0; y < 192; y++)
                {
                    if (y < _translateY)
                    {
                        continue;
                    }
                    if (y - _translateY >= 192)
                    {
                        break;
                    }
                    ld = (y << 5) + ld0;                    pi = ((y - _translateY) << 5) + pi0;                    while ((pi & 31) < 31)
                    {
                        Layer1[ld] ^= (byte)(((prev.Layer1[pi] & nalpha) >> ndel) | ((prev.Layer1[pi + 1] & alpha) << del));                        Layer2[ld] ^= (byte)(((prev.Layer2[pi] & nalpha) >> ndel) | ((prev.Layer2[pi + 1] & alpha) << del));                        ld++; pi++;
                    }
                    Layer1[ld] ^= (byte)(prev.Layer1[pi] & nalpha);                    Layer2[ld] ^= (byte)(prev.Layer2[pi] & nalpha);
                }
            }
        }
Ejemplo n.º 2
0
        public static Image GetFrameBitmap(PPMFrame frame)
        {
            var bmp = new Image <Rgba32>(256, 192);

            var rect = new Rectangle(0, 0, 256, 192);

            byte[] bytes = new byte[(256 * 192) + 1];

            for (var y = 0; y <= 192; y++)
            {
                for (var x = 0; x <= 256; x++)
                {
                    if (frame.Layer1[y, x])
                    {
                        if (frame.Layer1.PenColor != PenColor.Inverted)
                        {
                            bmp[x, y] = frame.Layer1.PenColor == PenColor.Red ? Color.Red : Color.Blue;
                        }
                        else
                        {
                            bmp[x, y] = frame.PaperColor == PaperColor.Black ? Color.Black : Color.White;
                        }
                    }
                    else
                    {
                        if (frame.Layer2[y, x])
                        {
                            if (frame.Layer2.PenColor != PenColor.Inverted)
                            {
                                bmp[x, y] = frame.Layer2.PenColor == PenColor.Red ? Color.Red : Color.Blue;
                            }
                            else
                            {
                                bmp[x, y] = frame.PaperColor == PaperColor.Black ? Color.Black : Color.White;
                            }
                        }
                        else
                        {
                            bmp[x, y] = frame.PaperColor == PaperColor.White ? Color.White : Color.Black;
                        }
                    }
                }
            }
            return(bmp);
        }
Ejemplo n.º 3
0
        public PPMFrame CreateDiff0(PPMFrame prev)
        {
            var frame = new PPMFrame();

            frame._firstByteHeader = _firstByteHeader;
            //frame._firstByteHeader &= 0b00011111;
            //frame._firstByteHeader |= 0x80;
            for (int i = 0; i < 32 * 192; i++)
            {
                frame.Layer1[i] = (byte)(Layer1[i] ^ prev.Layer1[i]);
                frame.Layer2[i] = (byte)(Layer2[i] ^ prev.Layer2[i]);
            }
            for (int y = 0; y < 192; y++)
            {
                frame.Layer1.SetLineEncoding(y, frame.Layer1.ChooseLineEncoding(y));
                frame.Layer2.SetLineEncoding(y, frame.Layer1.ChooseLineEncoding(y));
            }
            // > TO DO : update line encodings
            return(frame);
        }