private unsafe static void TransferData1(Pix pix, BitmapData imgData) { var imgFormat = imgData.PixelFormat; var height = imgData.Height; var width = imgData.Width; var pixData = pix.pixGetData(); var wpl = pix.Wpl; for (int y = 0; y < height; y++) { uint *pixLine = (uint *)pixData + (y * wpl); byte *imgLine = (byte *)imgData.Scan0.ToPointer(); for (int x = 0; x < width; x++) { var pixVal = (byte)~GetDataBit(pixLine, x); var index = y * imgData.Stride + (x >> 3); var mask = (byte)(0x80 >> (x & 0x7)); if (pixVal != 255) { imgLine[index] &= (byte)(mask ^ 0xff); } else { imgLine[index] |= mask; } } } }
private unsafe static void TransferData4(Pix pix, BitmapData imgData) { var imgFormat = imgData.PixelFormat; var height = imgData.Height; var width = imgData.Width; var pixData = pix.pixGetData(); var wpl = pix.Wpl; for (int y = 0; y < height; y++) { uint *pixLine = (uint *)pixData + (y * wpl); byte *imgLine = (byte *)imgData.Scan0.ToPointer(); for (int x = 0; x < width; x++) { var pixVal = (byte)GetDataQBit(pixLine, x); var index = (y * imgData.Stride) + (x >> 1); var curBy = ((byte *)imgData.Scan0)[index]; if ((x & 1) == 1) { curBy &= 0xf0; curBy |= (byte)(pixVal & 0x0f); } else { curBy &= 0x0f; curBy |= (byte)(pixVal << 4); } imgLine[index] = curBy; } } }
private unsafe static void TransferData32(Pix pix, BitmapData imgData, int alphaMask = 0) { var imgFormat = imgData.PixelFormat; var height = imgData.Height; var width = imgData.Width; var pixData = pix.pixGetData(); var wpl = pix.Wpl; for (int y = 0; y < height; y++) { byte *imgLine = (byte *)imgData.Scan0 + (y * imgData.Stride); uint *pixLine = (uint *)pixData + (y * wpl); for (int x = 0; x < width; x++) { //var pixVal = PixColor.FromRgba(pixLine[x]); var value = pixLine[x]; //byte* pixelPtr = imgLine + (x << 2); //pixelPtr[0] = pixVal.Blue; //pixelPtr[1] = pixVal.Green; //pixelPtr[2] = pixVal.Red; //pixelPtr[3] = (byte)(alphaMask | pixVal.Alpha); // Allow user to include alpha or not byte *pixelPtr = imgLine + (x << 2); // First Way pixelPtr[0] = (byte)((value >> 8) & 0xFF); //B pixelPtr[1] = (byte)((value >> 16) & 0xFF); //G pixelPtr[2] = (byte)((value >> 24) & 0xFF); //R pixelPtr[3] = (byte)((byte)(value & 0xFF) | alphaMask); //A //// Second Way //var col = ToArgb(value); //pixelPtr[0] = col.B; //pixelPtr[1] = col.G; //pixelPtr[2] = col.R; //pixelPtr[3] = (byte)(col.A | alphaMask); //// Third Way //var a = (value & 0xFF000000) >> 24; //var r = (value & 0x00FF0000) >> 16; //var g = (value & 0x0000FF00) >> 8; //var b = (value & 0x000000FF); //pixelPtr[0] = (byte)b; //pixelPtr[1] = (byte)g; //pixelPtr[2] = (byte)r; //pixelPtr[3] = (byte)((byte)a | alphaMask); //// First Way but clearer //var a = (byte)((byte)(value & 0xFF) | alphaMask); //A //var b = (byte)((value >> 8) & 0xFF); //B //var g = (byte)((value >> 16) & 0xFF); //G //var r = (byte)((value >> 24) & 0xFF); //R //pixelPtr[0] = b; //pixelPtr[1] = g; //pixelPtr[2] = r; //pixelPtr[3] = a; } } }
private unsafe static void TransferData8(Pix pix, BitmapData imgData) { var imgFormat = imgData.PixelFormat; var height = imgData.Height; var width = imgData.Width; var pixData = pix.pixGetData(); var wpl = pix.Wpl; for (int y = 0; y < height; y++) { uint *pixLine = (uint *)pixData + (y * wpl); byte *imgLine = (byte *)imgData.Scan0 + (y * imgData.Stride); for (int x = 0; x < width; x++) { var pixVal = (byte)GetDataByte(pixLine, x); imgLine[x] = pixVal; } } }