public void copy_to_rect(DMDBuffer dst, int dst_x, int dst_y, int src_x, int src_y, int width, int height, DMDBlendMode mode = DMDBlendMode.DMDBlendModeCopy) { DMDRect srcRect = DMDGlobals.DMDRectMake(src_x, src_y, width, height); DMDPoint dstPoint = DMDGlobals.DMDPointMake(dst_x, dst_y); DMDGlobals.DMDFrameCopyRect(ref frame, srcRect, ref dst.frame, dstPoint, mode); }
public static DMDPoint DMDPointMake(int x, int y) { DMDPoint p = new DMDPoint() { x = x, y = y }; return(p); }
public static void DMDFrameSetDot(ref DMDFrame frame, DMDPoint p, byte c) { frame.buffer[p.y * frame.size.width + p.x] = c; }
public static byte DMDFrameGetDot(ref DMDFrame frame, DMDPoint p) { return(frame.buffer[p.y * frame.size.width + p.x]); }
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); }
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); }
public static DMDPoint DMDPointMake(int x, int y) { DMDPoint p = new DMDPoint() { x = x, y = y }; return p; }
public static byte DMDFrameGetDot(ref DMDFrame frame, DMDPoint p) { return frame.buffer[p.y * frame.size.width + p.x]; }