public PixColor this[int index] { get { int color; if (Interop.LeptonicaApi.Native.pixcmapGetColor32(handle, index, out color) == 0) { return(PixColor.FromRgb((uint)color)); } else { throw new InvalidOperationException("Failed to retrieve color."); } } set { if (Interop.LeptonicaApi.Native.pixcmapResetColor(handle, index, value.Red, value.Green, value.Blue) != 0) { throw new InvalidOperationException("Failed to reset color."); } } }
private unsafe void TransferData32(PixData pixData, BitmapData imgData, int alphaMask) { var imgFormat = imgData.PixelFormat; var height = imgData.Height; var width = imgData.Width; for (int y = 0; y < height; y++) { byte *imgLine = (byte *)imgData.Scan0 + (y * imgData.Stride); uint *pixLine = (uint *)pixData.Data + (y * pixData.WordsPerLine); for (int x = 0; x < width; x++) { var pixVal = PixColor.FromRgba(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 } } }
public bool AddColor(PixColor color) { return(Interop.LeptonicaApi.Native.pixcmapAddColor(handle, color.Red, color.Green, color.Blue) == 0); }
public bool AddNearestColor(PixColor color, out int index) { return(Interop.LeptonicaApi.Native.pixcmapAddNearestColor(handle, color.Red, color.Green, color.Blue, out index) == 0); }