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 DMDRect DMDRectMake(int x, int y, int w, int h) { DMDRect r = new DMDRect(); r.origin = new DMDPoint() { x = x, y = y }; r.size = new DMDSize() { width = w, height = h }; return(r); }
public static DMDRect DMDRectIntersection(DMDRect rect0, DMDRect rect1) { DMDRect result; if (DMDRectGetMaxX(rect0) <= DMDRectGetMinX(rect1) || DMDRectGetMinX(rect0) >= DMDRectGetMaxX(rect1) || DMDRectGetMaxY(rect0) <= DMDRectGetMinY(rect1) || DMDRectGetMinY(rect0) >= DMDRectGetMaxY(rect1)) { return(DMDRectMake(0, 0, 0, 0)); } result.origin.x = Math.Max(DMDRectGetMinX(rect0), DMDRectGetMinX(rect1)); result.origin.y = Math.Max(DMDRectGetMinY(rect0), DMDRectGetMinY(rect1)); result.size.width = Math.Min(DMDRectGetMaxX(rect0), DMDRectGetMaxX(rect1)) - result.origin.x; result.size.height = Math.Min(DMDRectGetMaxY(rect0), DMDRectGetMaxY(rect1)) - result.origin.y; return(result); }
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); } } }
public static int DMDRectGetMinY(DMDRect r) { return(r.origin.y); }
public static int DMDRectGetMinX(DMDRect r) { return(r.origin.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 int DMDRectGetMaxX(DMDRect r) { return r.origin.x + r.size.width; }
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 DMDRect DMDRectMake(int x, int y, int w, int h) { DMDRect r = new DMDRect(); r.origin = new DMDPoint() { x = x, y = y }; r.size = new DMDSize() { width = w, height = h }; return r; }
public static DMDRect DMDRectIntersection(DMDRect rect0, DMDRect rect1) { DMDRect result; if (DMDRectGetMaxX(rect0) <= DMDRectGetMinX(rect1) || DMDRectGetMinX(rect0) >= DMDRectGetMaxX(rect1) || DMDRectGetMaxY(rect0) <= DMDRectGetMinY(rect1) || DMDRectGetMinY(rect0) >= DMDRectGetMaxY(rect1)) return DMDRectMake(0, 0, 0, 0); result.origin.x = Math.Max(DMDRectGetMinX(rect0), DMDRectGetMinX(rect1)); result.origin.y = Math.Max(DMDRectGetMinY(rect0), DMDRectGetMinY(rect1)); result.size.width = Math.Min(DMDRectGetMaxX(rect0), DMDRectGetMaxX(rect1)) - result.origin.x; result.size.height = Math.Min(DMDRectGetMaxY(rect0), DMDRectGetMaxY(rect1)) - result.origin.y; return result; }
public static int DMDRectGetMinY(DMDRect r) { return r.origin.y; }
public static int DMDRectGetMinX(DMDRect r) { return r.origin.x; }
public static int DMDRectGetMaxY(DMDRect r) { return r.origin.y + r.size.height; }
public static int DMDRectGetMaxX(DMDRect r) { return(r.origin.x + r.size.width); }
public static int DMDRectGetMaxY(DMDRect r) { return(r.origin.y + r.size.height); }
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); }