Beispiel #1
0
        public static void DMDFrameCopyPROCSubframes(ref DMDFrame frame, byte[] dots, int width, int height, int subframes, byte[] colorMap)
        {
            if (subframes != 4)
            {
                throw new Exception("ERROR in DMDFrameCopyPROCSubframes(): subframes must be 4");
            }
            byte[] defaultColorMap = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 };
            /* Color map specific to P-ROC */
            byte[] procColorMap = { 0, 2, 8, 10, 1, 3, 9, 11, 4, 6, 12, 14, 5, 7, 13, 15 };

            if (colorMap != null)
                colorMap = defaultColorMap;

            int row, col;

            for (row = 0; row < height; row++)
            {
                for (col = 0; col < width; col++)
                {
                    byte dot = DMDFrameGetDot(ref frame, DMDPointMake(col, row));
                    if (dot == 0)
                        continue;
                    else
                    {
                        dot &= 0x0f;
                        dot = colorMap[(int)dot];
                        dot = procColorMap[(int)dot];
                        if ((dot & 0x1) == 0x1) dots[0 * (width * height / 8) + ((row * width + col) / 8)] |= (byte)(1 << (int)(col % 8));
                        if ((dot & 0x2) == 0x2) dots[1 * (width * height / 8) + ((row * width + col) / 8)] |= (byte)(1 << (int)(col % 8));
                        if ((dot & 0x4) == 0x4) dots[2 * (width * height / 8) + ((row * width + col) / 8)] |= (byte)(1 << (int)(col % 8));
                        if ((dot & 0x8) == 0x8) dots[3 * (width * height / 8) + ((row * width + col) / 8)] |= (byte)(1 << (int)(col % 8));
                    }
                }
            }
        }
Beispiel #2
0
        public static DMDFrame DMDFrameCopy(ref DMDFrame frame)
        {
            DMDFrame result = DMDFrameCreate(frame.size);

            Array.Copy(frame.buffer, result.buffer, frame.buffer.Length);
            return(result);
        }
Beispiel #3
0
 public DMDBuffer(int width, int height)
 {
     frame = DMDGlobals.DMDFrameCreate(new DMDSize()
     {
         height = height, width = width
     });
 }
Beispiel #4
0
        public static DMDFrame DMDFrameCreate(DMDSize size)
        {
            DMDFrame result = new DMDFrame();

            result.buffer = new byte[size.width * size.height];
            result.size   = size;
            return(result);
        }
Beispiel #5
0
        public static void DMDFrameCopyPROCSubframes(ref DMDFrame frame, byte[] dots, int width, int height, int subframes, byte[] colorMap)
        {
            if (subframes != 4)
            {
                throw new Exception("ERROR in DMDFrameCopyPROCSubframes(): subframes must be 4");
            }
            byte[] defaultColorMap = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 };
            /* Color map specific to P-ROC */
            byte[] procColorMap = { 0, 2, 8, 10, 1, 3, 9, 11, 4, 6, 12, 14, 5, 7, 13, 15 };

            if (colorMap != null)
            {
                colorMap = defaultColorMap;
            }

            int row, col;

            for (row = 0; row < height; row++)
            {
                for (col = 0; col < width; col++)
                {
                    byte dot = DMDFrameGetDot(ref frame, DMDPointMake(col, row));
                    if (dot == 0)
                    {
                        continue;
                    }
                    else
                    {
                        dot &= 0x0f;
                        dot  = colorMap[(int)dot];
                        dot  = procColorMap[(int)dot];
                        if ((dot & 0x1) == 0x1)
                        {
                            dots[0 * (width * height / 8) + ((row * width + col) / 8)] |= (byte)(1 << (int)(col % 8));
                        }
                        if ((dot & 0x2) == 0x2)
                        {
                            dots[1 * (width * height / 8) + ((row * width + col) / 8)] |= (byte)(1 << (int)(col % 8));
                        }
                        if ((dot & 0x4) == 0x4)
                        {
                            dots[2 * (width * height / 8) + ((row * width + col) / 8)] |= (byte)(1 << (int)(col % 8));
                        }
                        if ((dot & 0x8) == 0x8)
                        {
                            dots[3 * (width * height / 8) + ((row * width + col) / 8)] |= (byte)(1 << (int)(col % 8));
                        }
                    }
                }
            }
        }
Beispiel #6
0
        public static void DMDFrameFillRect(ref DMDFrame frame, DMDRect rect, byte color)
        {
            rect = DMDRectIntersection(DMDFrameGetBounds(ref frame), rect);

            int maxX = DMDRectGetMaxX(rect);
            int maxY = DMDRectGetMaxY(rect);

            int x, y;

            for (x = DMDRectGetMinX(rect); x < maxX; x++)
            {
                for (y = DMDRectGetMinY(rect); y < maxY; y++)
                {
                    DMDFrameSetDot(ref frame, x, y, color);
                }
            }
        }
Beispiel #7
0
 public static void DMDFrameSetDot(ref DMDFrame frame, DMDPoint p, byte c)
 {
     frame.buffer[p.y * frame.size.width + p.x] = c;
 }
Beispiel #8
0
        public static void DMDFrameCopyRect(ref DMDFrame src, DMDRect srcRect, ref DMDFrame dst, DMDPoint dstPoint, DMDBlendMode blendMode)
        {
            //double startTime = tools.Time.GetTime();
            srcRect = DMDRectIntersection(DMDFrameGetBounds(ref src), srcRect);
            DMDRect dstRect = DMDRectIntersection(DMDFrameGetBounds(ref dst),
                                                  DMDRectMake(dstPoint.x, dstPoint.y, srcRect.size.width, srcRect.size.height));

            if (srcRect.size.width == 0 || srcRect.size.height == 0)
            {
                return; /* Nothing to do */
            }
            int  width = dstRect.size.width;
            int  height = dstRect.size.height;
            int  x, y;
            byte dot;

            if (blendMode == DMDBlendMode.DMDBlendModeCopy)
            {
                for (y = 0; y < height; y++)
                {
                    for (x = 0; x < width; x++)
                    {
                        dot = DMDFrameGetDot(ref src, srcRect.origin.x + x, srcRect.origin.y + y);
                        DMDFrameSetDot(ref dst, dstRect.origin.x + x, dstRect.origin.y + y,
                                       dot);
                    }
                }
            }
            else if (blendMode == DMDBlendMode.DMDBlendModeAdd)
            {
                for (y = 0; y < height; y++)
                {
                    for (x = 0; x < width; x++)
                    {
                        byte srcDot = DMDFrameGetDot(ref src, srcRect.origin.x, srcRect.origin.y + y);
                        byte dstDot = DMDFrameGetDot(ref dst, dstRect.origin.x, dstRect.origin.y + y);
                        DMDFrameSetDot(ref dst, dstRect.origin.x, dstRect.origin.y + y, (byte)Math.Min(srcDot + dstDot, 0xF));
                    }
                }
            }
            else if (blendMode == DMDBlendMode.DMDBlendModeBlackSource)
            {
                for (y = 0; y < height; y++)
                {
                    for (x = 0; x < width; x++)
                    {
                        byte srcDot = DMDFrameGetDot(ref src, srcRect.origin.x, srcRect.origin.y + y);
                        byte dstDot = DMDFrameGetDot(ref dst, dstRect.origin.x, dstRect.origin.y + y);
                        // Only write dots into black dots
                        if ((srcDot & 0xf) != 0)
                        {
                            DMDFrameSetDot(ref dst, dstRect.origin.x, dstRect.origin.y + y, (byte)((dstDot & 0xf0) | (srcDot & 0xf)));
                        }
                    }
                }
            }
            else if (blendMode == DMDBlendMode.DMDBlendModeSubtract)
            {
                for (y = 0; y < height; y++)
                {
                    for (x = 0; x < width; x++)
                    {
                        byte srcDot = DMDFrameGetDot(ref src, srcRect.origin.x, srcRect.origin.y + y);
                        byte dstDot = DMDFrameGetDot(ref dst, dstRect.origin.x, dstRect.origin.y + y);
                        DMDFrameSetDot(ref dst, dstRect.origin.x, dstRect.origin.y + y, (byte)Math.Max(srcDot + dstDot, 0xF));
                    }
                }
            }
            else if (blendMode == DMDBlendMode.DMDBlendModeAlpha)
            {
                byte[] alphaMap = DMDGetAlphaMap();

                for (y = 0; y < height; y++)
                {
                    for (x = 0; x < width; x++)
                    {
                        byte srcDot = DMDFrameGetDot(ref src, srcRect.origin.x, srcRect.origin.y + y);
                        byte dstDot = DMDFrameGetDot(ref dst, dstRect.origin.x, dstRect.origin.y + y);
                        byte v      = alphaMap[srcDot * 256 + (dstDot | 0xf0)];
                        DMDFrameSetDot(ref dst, dstRect.origin.x, dstRect.origin.y + y, (byte)((dstDot & 0xf0) | (v & 0x0f)));
                    }
                }
            }
            else if (blendMode == DMDBlendMode.DMDBlendModeAlphaBoth)
            {
                byte[] alphaMap = DMDGetAlphaMap();
                for (y = 0; y < height; y++)
                {
                    for (x = 0; x < width; x++)
                    {
                        byte dstValue = DMDFrameGetDot(ref dst, dstRect.origin.x, dstRect.origin.y + y);
                        byte srcValue = DMDFrameGetDot(ref src, srcRect.origin.x, srcRect.origin.y + y);

                        DMDFrameSetDot(ref dst, dstRect.origin.x, dstRect.origin.y + y, alphaMap[srcValue * 256 + dstValue]);
                    }
                }
            }
            //Console.WriteLine("     DMDFrameCopyRect total time: {0}ms", (tools.Time.GetTime() - startTime) * 1000);
        }
Beispiel #9
0
 public static int DMDFrameGetBufferSize(ref DMDFrame frame)
 {
     return(frame.size.width * frame.size.height);
 }
Beispiel #10
0
 public static void DMDFrameDelete(ref DMDFrame frame)
 {
     frame.buffer = null;
 }
Beispiel #11
0
 public static DMDFrame DMDFrameCreate(DMDSize size)
 {
     DMDFrame result = new DMDFrame();
     result.buffer = new byte[size.width * size.height];
     result.size = size;
     return result;
 }
Beispiel #12
0
 public static void DMDFrameSetDot(ref DMDFrame frame, DMDPoint p, byte c)
 {
     frame.buffer[p.y * frame.size.width + p.x] = c;
 }
Beispiel #13
0
        public static void DMDFrameFillRect(ref DMDFrame frame, DMDRect rect, byte color)
        {
            rect = DMDRectIntersection(DMDFrameGetBounds(ref frame), rect);

            int maxX = DMDRectGetMaxX(rect);
            int maxY = DMDRectGetMaxY(rect);

            int x, y;
            for (x = DMDRectGetMinX(rect); x < maxX; x++)
                for (y = DMDRectGetMinY(rect); y < maxY; y++)
                    DMDFrameSetDot(ref frame, x, y, color);
        }
Beispiel #14
0
 public static byte DMDFrameGetDot(ref DMDFrame frame, DMDPoint p)
 {
     return(frame.buffer[p.y * frame.size.width + p.x]);
 }
Beispiel #15
0
 public static byte DMDFrameGetDot(ref DMDFrame frame, int x, int y)
 {
     return frame.buffer[y * frame.size.width + x];
 }
Beispiel #16
0
 public static byte DMDFrameGetDot(ref DMDFrame frame, DMDPoint p)
 {
     return frame.buffer[p.y * frame.size.width + p.x];
 }
Beispiel #17
0
 public static int DMDFrameGetBufferSize(ref DMDFrame frame)
 {
     return frame.size.width * frame.size.height;
 }
Beispiel #18
0
 public static DMDRect DMDFrameGetBounds(ref DMDFrame frame)
 {
     return DMDRectMake(0, 0, frame.size.width, frame.size.height);
 }
Beispiel #19
0
 public static byte DMDFrameGetDot(ref DMDFrame frame, int x, int y)
 {
     return(frame.buffer[y * frame.size.width + x]);
 }
Beispiel #20
0
 public static void DMDFrameSetDot(ref DMDFrame frame, int x, int y, byte c)
 {
     frame.buffer[y * frame.size.width + x] = c;
 }
Beispiel #21
0
 public static void DMDFrameSetDot(ref DMDFrame frame, int x, int y, byte c)
 {
     frame.buffer[y * frame.size.width + x] = c;
 }
Beispiel #22
0
        public static void DMDFrameCopyRect(ref DMDFrame src, DMDRect srcRect, ref DMDFrame dst, DMDPoint dstPoint, DMDBlendMode blendMode)
        {
            //double startTime = tools.Time.GetTime();
            srcRect = DMDRectIntersection(DMDFrameGetBounds(ref src), srcRect);
            DMDRect dstRect = DMDRectIntersection(DMDFrameGetBounds(ref dst),
                                DMDRectMake(dstPoint.x, dstPoint.y, srcRect.size.width, srcRect.size.height));

            if (srcRect.size.width == 0 || srcRect.size.height == 0)
                return; /* Nothing to do */

            int width = dstRect.size.width;
            int height = dstRect.size.height;
            int x, y;
            byte dot;

            if (blendMode == DMDBlendMode.DMDBlendModeCopy)
            {
                for (y = 0; y < height; y++)
                {
                    for (x = 0; x < width; x++)
                    {
                        dot = DMDFrameGetDot(ref src, srcRect.origin.x + x, srcRect.origin.y + y);
                        DMDFrameSetDot(ref dst, dstRect.origin.x + x, dstRect.origin.y + y,
                            dot);
                    }
                }
            }
            else if (blendMode == DMDBlendMode.DMDBlendModeAdd)
            {
                for (y = 0; y < height; y++)
                {
                    for (x = 0; x < width; x++)
                    {
                        byte srcDot = DMDFrameGetDot(ref src, srcRect.origin.x, srcRect.origin.y + y);
                        byte dstDot = DMDFrameGetDot(ref dst, dstRect.origin.x, dstRect.origin.y + y);
                        DMDFrameSetDot(ref dst, dstRect.origin.x, dstRect.origin.y + y, (byte)Math.Min(srcDot + dstDot, 0xF));
                    }
                }
            }
            else if (blendMode == DMDBlendMode.DMDBlendModeBlackSource)
            {
                for (y = 0; y < height; y++)
                {
                    for (x = 0; x < width; x++)
                    {
                        byte srcDot = DMDFrameGetDot(ref src, srcRect.origin.x, srcRect.origin.y + y);
                        byte dstDot = DMDFrameGetDot(ref dst, dstRect.origin.x, dstRect.origin.y + y);
                        // Only write dots into black dots
                        if ((srcDot & 0xf) != 0)
                        {
                            DMDFrameSetDot(ref dst, dstRect.origin.x, dstRect.origin.y + y, (byte)((dstDot & 0xf0) | (srcDot & 0xf)));
                        }
                    }
                }
            }
            else if (blendMode == DMDBlendMode.DMDBlendModeSubtract)
            {
                for (y = 0; y < height; y++)
                {
                    for (x = 0; x < width; x++)
                    {
                        byte srcDot = DMDFrameGetDot(ref src, srcRect.origin.x, srcRect.origin.y + y);
                        byte dstDot = DMDFrameGetDot(ref dst, dstRect.origin.x, dstRect.origin.y + y);
                        DMDFrameSetDot(ref dst, dstRect.origin.x, dstRect.origin.y + y, (byte)Math.Max(srcDot + dstDot, 0xF));
                    }
                }
            }
            else if (blendMode == DMDBlendMode.DMDBlendModeAlpha)
            {
                byte[] alphaMap = DMDGetAlphaMap();

                for (y = 0; y < height; y++)
                {
                    for (x = 0; x < width; x++)
                    {
                        byte srcDot = DMDFrameGetDot(ref src, srcRect.origin.x, srcRect.origin.y + y);
                        byte dstDot = DMDFrameGetDot(ref dst, dstRect.origin.x, dstRect.origin.y + y);
                        byte v = alphaMap[srcDot * 256 + (dstDot | 0xf0)];
                        DMDFrameSetDot(ref dst, dstRect.origin.x, dstRect.origin.y + y, (byte)((dstDot & 0xf0) | (v & 0x0f)));
                    }
                }
            }
            else if (blendMode == DMDBlendMode.DMDBlendModeAlphaBoth)
            {
                byte[] alphaMap = DMDGetAlphaMap();
                for (y = 0; y < height; y++)
                {
                    for (x = 0; x < width; x++)
                    {
                        byte dstValue = DMDFrameGetDot(ref dst, dstRect.origin.x, dstRect.origin.y + y);
                        byte srcValue = DMDFrameGetDot(ref src, srcRect.origin.x, srcRect.origin.y + y);

                        DMDFrameSetDot(ref dst, dstRect.origin.x, dstRect.origin.y + y, alphaMap[srcValue * 256 + dstValue]);
                    }
                }
            }
            //Console.WriteLine("     DMDFrameCopyRect total time: {0}ms", (tools.Time.GetTime() - startTime) * 1000);
        }
Beispiel #23
0
 public static void DMDFrameDelete(ref DMDFrame frame)
 {
     frame.buffer = null;
 }
Beispiel #24
0
 public static DMDRect DMDFrameGetBounds(ref DMDFrame frame)
 {
     return(DMDRectMake(0, 0, frame.size.width, frame.size.height));
 }
Beispiel #25
0
 public DMDBuffer(int width, int height)
 {
     frame = DMDGlobals.DMDFrameCreate(new DMDSize() { height = height, width = width });
 }
Beispiel #26
0
 public static DMDFrame DMDFrameCopy(ref DMDFrame frame)
 {
     DMDFrame result = DMDFrameCreate(frame.size);
     Array.Copy(frame.buffer, result.buffer, frame.buffer.Length);
     return result;
 }