/// <summary> /// Replaces the pixels in the image based on the custom replacer handler /// </summary> /// <param name="icon">Image to replace</param> /// <param name="mask">Handler to replace which is called for each pixel</param> /// <returns>Resulting image</returns> protected Image ReplaceColor(Image icon, ColorMaskDelegate mask) { var maskImg = new Bitmap(icon); var rect = new Rectangle(0, 0, maskImg.Width, maskImg.Height); var bmpData = maskImg.LockBits(rect, ImageLockMode.ReadWrite, PixelFormat.Format32bppArgb); var ptr = bmpData.Scan0; var rgba = new byte[Math.Abs(bmpData.Stride) * maskImg.Height]; Marshal.Copy(ptr, rgba, 0, rgba.Length); for (int i = 0; i < rgba.Length; i += 4) { mask.Invoke(ref rgba[i + 2], ref rgba[i + 1], ref rgba[i], ref rgba[i + 3]); } Marshal.Copy(rgba, 0, bmpData.Scan0, rgba.Length); maskImg.UnlockBits(bmpData); return(maskImg); }
internal static void LoadEntryPoints() { if (Viewport == null) { Viewport = LoadFunction <ViewportDelegate>("glViewport"); } if (Scissor == null) { Scissor = LoadFunction <ScissorDelegate>("glScissor"); } //if (MakeCurrent == null) // MakeCurrent = LoadFunction<MakeCurrentDelegate>("glMakeCurrent"); GetError = LoadFunction <GetErrorDelegate>("glGetError"); EnableVertexAttribArray = LoadFunction <EnableVertexAttribArrayDelegate>("glEnableVertexAttribArray"); DisableVertexAttribArray = LoadFunction <DisableVertexAttribArrayDelegate>("glDisableVertexAttribArray"); _getStringInternal = LoadFunction <GetStringDelegate>("glGetString"); ClearDepth = LoadFunction <ClearDepthDelegate>("glClearDepth") ?? LoadFunction <ClearDepthDelegate>("glClearDepthf"); Clear = LoadFunction <ClearDelegate>("glClear"); ClearColor = LoadFunction <ClearColorDelegate>("glClearColor"); ClearStencil = LoadFunction <ClearStencilDelegate>("glClearStencil"); Enable = LoadFunction <EnableDelegate>("glEnable"); Disable = LoadFunction <DisableDelegate>("glDisable"); BindBuffer = LoadFunction <BindBufferDelegate>("glBindBuffer"); //DrawBuffers = LoadFunction<DrawBuffersDelegate>("glDrawBuffers"); //DrawElements = LoadFunction<DrawElementsDelegate>("glDrawElements"); DrawArrays = LoadFunction <DrawArraysDelegate>("glDrawArrays"); //Uniform1i = LoadFunction<Uniform1iDelegate>("glUniform1i"); //Uniform4fv = LoadFunction<Uniform4fvDelegate>("glUniform4fv"); //ReadPixelsInternal = LoadFunction<ReadPixelsDelegate>("glReadPixels"); CreateShader = LoadFunction <CreateShaderDelegate>("glCreateShader"); ShaderSourceInternal = LoadFunction <ShaderSourceDelegate>("glShaderSource"); CompileShader = LoadFunction <CompileShaderDelegate>("glCompileShader"); ColorMask = LoadFunction <ColorMaskDelegate>("glColorMask"); //TODO: DepthFunc = LoadFunction<DepthFuncDelegate>("glDepthFunc"); DepthMask = LoadFunction <DepthMaskDelegate>("glDepthMask"); StencilMask = LoadFunction <StencilMaskDelegate>("glStencilMask"); GenBuffers = LoadFunction <GenBuffersDelegate>("glGenBuffers"); BufferData = LoadFunction <BufferDataDelegate>("glBufferData"); //MapBuffer = LoadFunction<MapBufferDelegate>("glMapBuffer"); //UnmapBuffer = LoadFunction<UnmapBufferDelegate>("glUnmapBuffer"); BufferSubData = LoadFunction <BufferSubDataDelegate>("glBufferSubData"); //DeleteBuffers = LoadFunction<DeleteBuffersDelegate>("glDeleteBuffers"); VertexAttribPointer = LoadFunction <VertexAttribPointerDelegate>("glVertexAttribPointer"); }
protected virtual Image CreateImage(IXImage icon, Size size, ColorMaskDelegate mask, Color background) { var img = FromXImage(icon); if (mask != null) { img = ReplaceColor(img, mask); } else { void ConflictingBackgroundPixelMask(ref byte r, ref byte g, ref byte b, ref byte a) { if (r == background.R && g == background.G && b == background.B && a == background.A) { b = (byte)((b == 0) ? 1 : (b - 1)); } } img = ReplaceColor(img, ConflictingBackgroundPixelMask); } return(img); }
private void CreateBitmap(IXImage[] sourceIcons, string targetIcon, Size size, int offset, Color background, ColorMaskDelegate mask) { var width = size.Width * sourceIcons.Length; var height = size.Height; using (var bmp = new Bitmap(width, height, PixelFormat.Format24bppRgb)) { using (var graph = Graphics.FromImage(bmp)) { graph.InterpolationMode = InterpolationMode.HighQualityBicubic; graph.SmoothingMode = SmoothingMode.HighQuality; graph.PixelOffsetMode = PixelOffsetMode.HighQuality; using (var brush = new SolidBrush(background)) { graph.FillRectangle(brush, 0, 0, bmp.Width, bmp.Height); } for (int i = 0; i < sourceIcons.Length; i++) { var targSize = new Size(size.Width - offset * 2, size.Height - offset * 2); var sourceIcon = CreateImage(sourceIcons[i], targSize, mask, background); if (bmp.HorizontalResolution != sourceIcon.HorizontalResolution || bmp.VerticalResolution != sourceIcon.VerticalResolution) { bmp.SetResolution( sourceIcon.HorizontalResolution, sourceIcon.VerticalResolution); } var widthScale = (double)targSize.Width / (double)sourceIcon.Width; var heightScale = (double)targSize.Height / (double)sourceIcon.Height; var scale = Math.Min(widthScale, heightScale); if (scale < 0) { throw new Exception("Target size of the icon cannot be calculated due to offset constraint"); } var destX = (int)(size.Width - sourceIcon.Width * scale) / 2; var destY = (int)(size.Height - sourceIcon.Height * scale) / 2; int destWidth = (int)(sourceIcon.Width * scale); int destHeight = (int)(sourceIcon.Height * scale); destX += i * size.Width; graph.DrawImage(sourceIcon, new Rectangle(destX, destY, destWidth, destHeight), new Rectangle(0, 0, sourceIcon.Width, sourceIcon.Height), GraphicsUnit.Pixel); } } var dir = Path.GetDirectoryName(targetIcon); if (!Directory.Exists(dir)) { Directory.CreateDirectory(dir); } bmp.Save(targetIcon, ImageFormat.Bmp); } }
internal IconSpec(IXImage srcImage, Size targetSize, ColorMaskDelegate mask, int offset = 0, string baseName = "") : this(srcImage, targetSize, offset, baseName) { Mask = mask; }