public void ReadScanline(byte[] scanline, Color2[] pixels, PngHeader header) { int offset; byte[] newScanline = ToArrayByBitsLength(scanline, header.BitDepth); if (useAlpha) { for (int x = 0; x < header.Width / 2; x++) { offset = row * header.Width + x; byte rgb = newScanline[x * 2]; byte a = newScanline[(x * 2) + 1]; Color2 color = Color2.FromArgb(a, rgb, rgb, rgb); pixels[offset] = color; } } else { for (int x = 0; x < header.Width; x++) { offset = row * header.Width + x; byte rgb = newScanline[x]; Color2 color = Color2.FromArgb(rgb, rgb, rgb); pixels[offset] = color; } } row++; }
private void ReadRgb16(Color2[] imageData, int width, int height, bool inverted) { // We divide here as we will store the colors in our floating point format. const int scaleR = 8; // 256/32 const int scaleG = 4; // 256/64 int alignment; byte[] data = GetImageArray(width, height, 2, out alignment); Parallel.For(0, height, Bootstrapper.instance.ParallelOptions, y => { int rowOffset = y * ((width * 2) + alignment); // Revert the y value, because bitmaps are saved from down to top int row = Invert(y, height, inverted); for (int x = 0; x < width; x++) { int offset = rowOffset + (x * 2); short temp = BitConverter.ToInt16(data, offset); byte r = (byte)(((temp & rgb16RMask) >> 11) * scaleR); byte g = (byte)(((temp & rgb16GMask) >> 5) * scaleG); byte b = (byte)((temp & rgb16BMask) * scaleR); int arrayOffset = row * width + x; // Stored in b-> g-> r order. Color2 packed = Color2.FromArgb(r, g, b); imageData[arrayOffset] = packed; } }); }
public NumericAxisView() { ForeColor = Color2.Black; IndicatorColor = Color2.FromArgb(30, 251, 173, 73); IsLogarithmic = false; Reverse = false; TotalMax = double.NaN; TotalMin = double.NaN; ZeroPoint = double.NaN; ZoomMax = double.NaN; ZoomMin = double.NaN; MaxNumIntegerDigits = 4; LineWidth = 1F; ZoomType = AxisZoomType.None; MinorTickLineWidth = 1; MajorTickLineWidth = 1; MinorTickLength = 3; MajorTickLength = 6; IsLogarithmic = false; ZoomMax = double.NaN; ZoomMin = double.NaN; TotalMax = double.NaN; TotalMin = double.NaN; MouseMode = AxisMouseMode.Zoom; }
public void ReadScanline(byte[] scanline, Color2[] pixels, PngHeader header) { int offset; byte[] newScanline = GrayscaleReader.ToArrayByBitsLength(scanline, header.BitDepth); if (useAlpha) { for (int x = 0; x < newScanline.Length; x += 4) { offset = row * header.Width + (x >> 2); byte r = newScanline[x]; byte g = newScanline[x + 1]; byte b = newScanline[x + 2]; byte a = newScanline[x + 3]; Color2 color = Color2.FromArgb(a, r, g, b); pixels[offset] = color; } } else { for (int x = 0; x < newScanline.Length / 3; x++) { offset = (row * header.Width) + x; int pixelOffset = x * 3; byte r = newScanline[pixelOffset]; byte g = newScanline[pixelOffset + 1]; byte b = newScanline[pixelOffset + 2]; Color2 color = Color2.FromArgb(r, g, b); pixels[offset] = color; } } row++; }
public override void OnPaintBackground(IGraphics g, int width, int height) { Brush2 b = new Brush2(Color2.FromArgb(236, 233, 216)); g.FillRectangle(b, 0, 0, width, height); Pen2 p = new Pen2(Color2.FromArgb(172, 168, 153)); g.DrawLine(p, 0, height - 1, width, height - 1); g.DrawLine(p, width - 1, 0, width - 1, height); }
private QuantizedImage GenerateResult(IPixelAccessor imagePixels, int colorCount, Box[] cube) { List <Color2> pallette = new List <Color2>(); byte[] pixels = new byte[imagePixels.Width * imagePixels.Height]; int transparentIndex = -1; int width = imagePixels.Width; int height = imagePixels.Height; for (int k = 0; k < colorCount; k++) { Mark(cube[k], (byte)k); double weight = Volume(cube[k], vwt); if (Math.Abs(weight) > Epsilon) { byte r = (byte)(Volume(cube[k], vmr) / weight); byte g = (byte)(Volume(cube[k], vmg) / weight); byte b = (byte)(Volume(cube[k], vmb) / weight); byte a = (byte)(Volume(cube[k], vma) / weight); Color2 color = Color2.FromArgb(a, r, g, b); if (color.Equals(default(Color2))) { transparentIndex = k; } pallette.Add(color); } else { pallette.Add(default(Color2)); transparentIndex = k; } } Parallel.For(0, height, Bootstrapper.instance.ParallelOptions, y => { for (int x = 0; x < width; x++) { // Expected order r->g->b->a byte[] color = imagePixels[x, y].ToBytes(); int r = color[0] >> (8 - IndexBits); int g = color[1] >> (8 - IndexBits); int b = color[2] >> (8 - IndexBits); int a = color[3] >> (8 - IndexAlphaBits); if (transparentIndex > -1 && color[3] <= Threshold) { pixels[(y * width) + x] = (byte)transparentIndex; continue; } int ind = GetPaletteIndex(r + 1, g + 1, b + 1, a + 1); pixels[(y * width) + x] = tag[ind]; } }); return(new QuantizedImage(width, height, pallette.ToArray(), pixels, transparentIndex)); }
private void CalcGradient(Color2 c1, Color2 c2, int a1, int a2) { for (int j = a1 + 1; j <= a2; j++) { double w1 = Math.Abs(a2 - j); double w2 = Math.Abs(j - a1); byte rr = (byte)Math.Round((c1.R * w1 + c2.R * w2) / (w1 + w2)); byte gg = (byte)Math.Round((c1.G * w1 + c2.G * w2) / (w1 + w2)); byte bb = (byte)Math.Round((c1.B * w1 + c2.B * w2) / (w1 + w2)); precalcColors[j] = Color2.FromArgb(rr, gg, bb); precalcPens[j] = new Pen2(precalcColors[j]); } }
public sealed override void OnPaintBackground(IGraphics g, int width, int height) { if (main == null) { return; } if (main.BackColor.IsEmpty || main.BackColor == Color.Transparent) { return; } Brush2 b = new Brush2(Color2.FromArgb(main.BackColor.A, main.BackColor.R, main.BackColor.G, main.BackColor.B)); g.FillRectangle(b, 0, 0, width, height); }
private static void ToYCbCr(IPixelAccessor pixels, int x, int y, Block yBlock, Block cbBlock, Block crBlock) { int xmax = pixels.Width - 1; int ymax = pixels.Height - 1; for (int j = 0; j < 8; j++){ for (int i = 0; i < 8; i++){ byte[] pixel = pixels[Math.Min(x + i, xmax), Math.Min(y + j, ymax)].ToBytes(); YCbCr2 color = Color2.FromArgb(pixel[3], pixel[0], pixel[1], pixel[2]); int index = 8*j + i; yBlock[index] = (int) color.Y; cbBlock[index] = (int) color.Cb; crBlock[index] = (int) color.Cr; } } }
public override void OnPaintBackground(IGraphics g, int width, int height) { Pen2 p = new Pen2(Color2.FromArgb(172, 168, 153)); g.DrawLine(p, width - 1, 0, width - 1, height); int[][] rgbs = GraphUtil.InterpolateRgb(243, 241, 236, 254, 254, 251, GraphUtil.scrollBarWidth - 2); for (int i = 0; i < GraphUtil.scrollBarWidth - 2; i++) { p = new Pen2(Color2.FromArgb(rgbs[0][i], rgbs[1][i], rgbs[2][i])); g.DrawLine(p, i + 1, 0, i + 1, height); } p = new Pen2(Color2.FromArgb(238, 237, 229)); g.DrawLine(p, 0, 0, 0, height); g.DrawLine(p, width - 2, 0, width - 2, height); }
public static Color2 ArgbToKnownColor(int targetArgb) { EnsureColorTable(); for (int index = 0; index < colorTable.Length; ++index) { int argb = colorTable[index]; if (argb == targetArgb) { Color2 color = Color2.FromKnownColor((KnownColor)index); if (!color.IsSystemColor) { return(color); } } } return(Color2.FromArgb(targetArgb)); }
private void ReadRgbPalette(Color2[] imageData, byte[] colors, int width, int height, int bits, bool inverted) { // Pixels per byte (bits per pixel) int ppb = 8 / bits; int arrayWidth = (width + ppb - 1) / ppb; // Bit mask int mask = 0xFF >> (8 - bits); byte[] data = new byte[arrayWidth * height]; currentStream.Read(data, 0, data.Length); // Rows are aligned on 4 byte boundaries int alignment = arrayWidth % 4; if (alignment != 0) { alignment = 4 - alignment; } Parallel.For(0, height, Bootstrapper.instance.ParallelOptions, y => { int rowOffset = y * (arrayWidth + alignment); for (int x = 0; x < arrayWidth; x++) { int offset = rowOffset + x; // Revert the y value, because bitmaps are saved from down to top int row = Invert(y, height, inverted); int colOffset = x * ppb; for (int shift = 0; shift < ppb && (colOffset + shift) < width; shift++) { if (offset >= data.Length) { continue; } int colorIndex = ((data[offset] >> (8 - bits - (shift * bits))) & mask) * 4; int arrayOffset = (row * width) + (colOffset + shift); // Stored in b-> g-> r order. Color2 packed = Color2.FromArgb(colors[colorIndex + 2], colors[colorIndex + 1], colors[colorIndex]); imageData[arrayOffset] = packed; } } }); }
public override void OnMouseIsUp(BasicMouseEventArgs e) { if (!hasMoved) { if (e.IsMainButton) { ColorDialog cd = new ColorDialog(); if (cd.ShowDialog() == DialogResult.OK) { if (mouseOverIndex != -1) { Colors[mouseOverIndex] = Color2.FromArgb(cd.Color.A, cd.Color.R, cd.Color.G, cd.Color.B); } else { Colors.Add(Color2.FromArgb(cd.Color.A, cd.Color.R, cd.Color.G, cd.Color.B)); Positions.Add(ViewToModel(Vertical ? e.Y : e.X, e.Width, e.Height)); } refreshColors = true; fireChange = true; Invalidate(); } } else { if (mouseOverIndex != -1 && Colors.Count > 2) { Colors.RemoveAt(mouseOverIndex); Positions.RemoveAt(mouseOverIndex); refreshColors = true; fireChange = true; Invalidate(); } } } else { FireColorChanged(); } mouseDragIndex = -1; }
private void ReadRgb32(Color2[] imageData, int width, int height, bool inverted) { int alignment; byte[] data = GetImageArray(width, height, 4, out alignment); Parallel.For(0, height, Bootstrapper.instance.ParallelOptions, y => { int rowOffset = y * ((width * 4) + alignment); // Revert the y value, because bitmaps are saved from down to top int row = Invert(y, height, inverted); for (int x = 0; x < width; x++) { int offset = rowOffset + (x * 4); int arrayOffset = ((row * width) + x); // Stored in b-> g-> r-> a order. Color2 packed = Color2.FromArgb(data[offset + 3], data[offset + 2], data[offset + 1], data[offset]); imageData[arrayOffset] = packed; } }); }
public void ConstructPalette(List <Color2> palette, ref int index) { if (leaf) { paletteIndex = index++; byte r = ToByte(red / pixelCount); byte g = ToByte(green / pixelCount); byte b = ToByte(blue / pixelCount); Color2 pixel = Color2.FromArgb(255, r, g, b); palette.Add(pixel); } else { for (int i = 0; i < 8; i++) { if (children[i] != null) { children[i].ConstructPalette(palette, ref index); } } } }
public void ReadScanline(byte[] scanline, Color2[] pixels, PngHeader header) { byte[] newScanline = GrayscaleReader.ToArrayByBitsLength(scanline, header.BitDepth); int offset, index; if (paletteAlpha != null && paletteAlpha.Length > 0) { for (int i = 0; i < header.Width; i++) { index = newScanline[i]; offset = (row * header.Width) + i; int pixelOffset = index * 3; byte r = palette[pixelOffset]; byte g = palette[pixelOffset + 1]; byte b = palette[pixelOffset + 2]; byte a = paletteAlpha.Length > index ? paletteAlpha[index] : (byte)255; Color2 color = Color2.FromArgb(a, r, g, b); pixels[offset] = color; } } else { for (int i = 0; i < header.Width; i++) { index = newScanline[i]; offset = (row * header.Width) + i; int pixelOffset = index * 3; byte r = palette[pixelOffset]; byte g = palette[pixelOffset + 1]; byte b = palette[pixelOffset + 2]; Color2 color = Color2.FromArgb(r, g, b); pixels[offset] = color; } } row++; }
public virtual void DoPaintBackground(IGraphics g) { g.FillRectangle(new Brush2(Color2.FromArgb(BackColor.A, BackColor.R, BackColor.G, BackColor.B)), 0, 0, Width, Height); }
private void ReadFrameColors(byte[] indices, byte[] colorTable, GifImageDescriptor descriptor) { int imageWidth = logicalScreenDescriptor.Width; int imageHeight = logicalScreenDescriptor.Height; if (currentFrame == null) { currentFrame = new Color2[imageWidth * imageHeight]; } Color2[] lastFrame = null; if (graphicsControlExtension != null && graphicsControlExtension.DisposalMethod == DisposalMethod.RestoreToPrevious) { lastFrame = new Color2[imageWidth * imageHeight]; Array.Copy(currentFrame, lastFrame, lastFrame.Length); } int offset, i = 0; int interlacePass = 0; // The interlace pass int interlaceIncrement = 8; // The interlacing line increment int interlaceY = 0; // The current interlaced line for (int y = descriptor.Top; y < descriptor.Top + descriptor.Height; y++) { // Check if this image is interlaced. int writeY; // the target y offset to write to if (descriptor.InterlaceFlag) { // If so then we read lines at predetermined offsets. // When an entire image height worth of offset lines has been read we consider this a pass. // With each pass the number of offset lines changes and the starting line changes. if (interlaceY >= descriptor.Height) { interlacePass++; switch (interlacePass) { case 1: interlaceY = 4; break; case 2: interlaceY = 2; interlaceIncrement = 4; break; case 3: interlaceY = 1; interlaceIncrement = 2; break; } } writeY = interlaceY + descriptor.Top; interlaceY += interlaceIncrement; } else { writeY = y; } for (int x = descriptor.Left; x < descriptor.Left + descriptor.Width; x++) { offset = (writeY * imageWidth) + x; int index = indices[i]; if (graphicsControlExtension == null || graphicsControlExtension.TransparencyFlag == false || graphicsControlExtension.TransparencyIndex != index) { // Stored in r-> g-> b-> a order. int indexOffset = index * 3; Color2 pixel = Color2.FromArgb(colorTable[indexOffset], colorTable[indexOffset + 1], colorTable[indexOffset + 2]); currentFrame[offset] = pixel; } i++; } } Color2[] pixels = new Color2[imageWidth * imageHeight]; Array.Copy(currentFrame, pixels, pixels.Length); ImageBase currentImage; if (decodedImage.Pixels == null) { currentImage = decodedImage; currentImage.SetPixels(imageWidth, imageHeight, pixels); currentImage.Quality = colorTable.Length / 3; if (graphicsControlExtension != null && graphicsControlExtension.DelayTime > 0) { decodedImage.FrameDelay = graphicsControlExtension.DelayTime; } } else { ImageFrame frame = new ImageFrame(); currentImage = frame; currentImage.SetPixels(imageWidth, imageHeight, pixels); currentImage.Quality = colorTable.Length / 3; if (graphicsControlExtension != null && graphicsControlExtension.DelayTime > 0) { currentImage.FrameDelay = graphicsControlExtension.DelayTime; } decodedImage.Frames.Add(frame); } if (graphicsControlExtension != null) { if (graphicsControlExtension.DisposalMethod == DisposalMethod.RestoreToBackground) { for (int y = descriptor.Top; y < descriptor.Top + descriptor.Height; y++) { for (int x = descriptor.Left; x < descriptor.Left + descriptor.Width; x++) { offset = (y * imageWidth) + x; // Stored in r-> g-> b-> a order. currentFrame[offset] = default(Color2); } } } else if (graphicsControlExtension.DisposalMethod == DisposalMethod.RestoreToPrevious) { currentFrame = lastFrame; } } }
public static Color2 ToColor2(Color c) { return(Color2.FromArgb(c.A, c.R, c.G, c.B)); }