public unsafe void SetAlpha(byte alpha) { Argb32 *start = (Argb32 *)this.Start; Argb32 *end = start + this.Length; while (start != end) { start->Alpha = alpha; start++; } }
public static unsafe void ToRgb24(Argb32 *from, Rgb24 *to, int length = 1) { if (length < 1) { return; } Argb32 *end = from + length; while (from != end) { *to = *((Rgb24 *)from); from++; to++; } }
public static unsafe void ToByte(Argb32 *from, byte *to, int length = 1) { if (length < 1) { return; } Argb32 *end = from + length; while (from != end) { *to = (Byte)(from->Blue * 0.114 + from->Green * 0.587 + from->Red * 0.299); from++; to++; } }
public unsafe ImageU8 ToGrayscaleImage(double rCoeff, double gCoeff, double bCoeff) { ImageU8 img = new ImageU8(this.Width, this.Height); Argb32 *p = Start; Byte * to = img.Start; Argb32 *end = p + Length; if (Length < 1024) { while (p != end) { *to = (Byte)(p->Red * rCoeff + p->Green * gCoeff + p->Blue * bCoeff); p++; to++; } } else { int *bCache = stackalloc int[256]; int *gCache = stackalloc int[256]; int *rCache = stackalloc int[256]; const int shift = 1 << 10; int rShift = (int)(rCoeff * shift); int gShift = (int)(gCoeff * shift); int bShift = shift - rShift - gShift; int r = 0, g = 0, b = 0; for (int i = 0; i < 256; i++) { bCache[i] = b; gCache[i] = g; rCache[i] = r; b += bShift; g += gShift; r += rShift; } while (p != end) { *to = (Byte)((bCache[p->Red] + gCache[p->Green] + rCache[p->Red]) >> 10); p++; to++; } } return(img); }
public static unsafe void ToArgb32(Rgb24 *from, Argb32 *to, int length = 1) { if (length < 1) { return; } Rgb24 *end = from + length; while (from != end) { to->Blue = from->Blue; to->Green = from->Green; to->Red = from->Red; to->Alpha = 255; from++; to++; } }
private static unsafe float[] Load(Image <Argb32> image) { int resolution = image.Height * image.Width; float[] sample = new float[resolution * 4]; fixed(Argb32 *p0 = &image.DangerousGetPinnableReferenceToPixelBuffer()) fixed(float *psample = sample) { for (int i = 0; i < resolution; i++) { Argb32 *pxy = p0 + i; psample[i] = pxy->A / 255f; psample[i + resolution] = pxy->R / 255f; psample[i + 2 * resolution] = pxy->G / 255f; psample[i + 3 * resolution] = pxy->B / 255f; } } return(sample); }
public static unsafe void ToArgb32(Byte *from, Argb32 *to, int length = 1) { if (length < 1) { return; } Byte *end = from + length; while (from != end) { Byte val = *from; to->Blue = val; to->Green = val; to->Red = val; to->Alpha = 255; from++; to++; } }
public static unsafe void ToLab24(Argb32 *from, Lab24 *to, int length = 1) { // 使用 OpenCV 中的算法实现 if (length < 1) { return; } Argb32 *end = from + length; int x, y, z; int l, a, b; bool flag; while (from != end) { Byte red = from->Red; Byte green = from->Green; Byte blue = from->Blue; x = blue * labXb + green * labXg + red * labXr; y = blue * labYb + green * labYg + red * labYr; z = blue * labZb + green * labZg + red * labZr; flag = x > labT; x = (((x) + (1 << ((lab_shift) - 1))) >> (lab_shift)); if (flag) { x = icvLabCubeRootTab[x]; } else { x = (((x * labSmallScale + labSmallShift) + (1 << ((lab_shift) - 1))) >> (lab_shift)); } flag = z > labT; z = (((z) + (1 << ((lab_shift) - 1))) >> (lab_shift)); if (flag == true) { z = icvLabCubeRootTab[z]; } else { z = (((z * labSmallScale + labSmallShift) + (1 << ((lab_shift) - 1))) >> (lab_shift)); } flag = y > labT; y = (((y) + (1 << ((lab_shift) - 1))) >> (lab_shift)); if (flag == true) { y = icvLabCubeRootTab[y]; l = (((y * labLScale - labLShift) + (1 << ((2 * lab_shift) - 1))) >> (2 * lab_shift)); } else { l = (((y * labLScale2) + (1 << ((lab_shift) - 1))) >> (lab_shift)); y = (((y * labSmallScale + labSmallShift) + (1 << ((lab_shift) - 1))) >> (lab_shift)); } a = (((500 * (x - y)) + (1 << ((lab_shift) - 1))) >> (lab_shift)) + 129; b = (((200 * (y - z)) + (1 << ((lab_shift) - 1))) >> (lab_shift)) + 128; l = l > 255 ? 255 : l < 0 ? 0 : l; a = a > 255 ? 255 : a < 0 ? 0 : a; b = b > 255 ? 255 : b < 0 ? 0 : b; to->L = (byte)l; to->A = (byte)a; to->B = (byte)b; from++; to++; } }
public unsafe void Copy(Argb32 *from, void *to, int length) { UnmanagedImageConverter.Copy((Byte *)from, (Byte *)to, length * 4); }
public unsafe void Copy(Argb32 *from, void *to, int length) { UnmanagedImageConverter.ToRgb24(from, (Rgb24 *)to, length); }
public unsafe void Copy(Argb32 *from, void *to, int length) { UnmanagedImageConverter.ToByte(from, (byte *)to, length); }