internal Pix(IntPtr pointer) : base(pointer) { Width = Leptonica5Pix.pixGetWidth(HandleRef); Height = Leptonica5Pix.pixGetHeight(HandleRef); Depth = Leptonica5Pix.pixGetDepth(HandleRef); }
public void AddPix(IntPtr pixPointer) { if (Leptonica5Pix.pixaAddPix(HandleRef.Handle, pixPointer, 1) != 0) { throw new InvalidOperationException("Leptonica failed."); } }
private static IEnumerable <IPix> ReadTiff(IntPtr pixaPointer) { try { var pagesCount = Leptonica5Pix.pixaGetCount(pixaPointer); if (pagesCount <= 0) { throw new InvalidOperationException("File has no pages."); } var pages = new List <Pix>(); for (var i = 0; i < pagesCount; i++) { try { var pagePointer = Leptonica5Pix.pixaGetPix(pixaPointer, i, 2).GetPointerOrThrow(); var page = new Pix(pagePointer); pages.Add(page); } catch { Destroy(pages); throw; } } return(pages); } finally { Leptonica5Pix.pixaDestroy(ref pixaPointer); } }
public void AddBox(IntPtr boxPointer) { if (Leptonica5Pix.boxaAddBox(HandleRef.Handle, boxPointer, 0) != 0) { throw new InvalidOperationException("Leptonica failed."); } }
internal Pix(int imageWidth, int imageHeight, int imageDepth) : base(() => Leptonica5Pix.pixCreate(imageWidth, imageHeight, imageDepth)) { Width = imageWidth; Height = imageHeight; Depth = imageDepth; }
public unsafe IEnumerable <IPix> Create(ReadOnlyMemory <byte> data) { using var pointer = data.Pin(); if (Leptonica5Pix.findFileFormatBuffer(pointer.Pointer, out var format) != 0) { throw new InvalidOperationException("File format not supported."); } var sizeInMemory = data.Length; switch (format) { case ImageFileFormat.Tiff: case ImageFileFormat.TiffPackbits: case ImageFileFormat.TiffRle: case ImageFileFormat.TiffG3: case ImageFileFormat.TiffG4: case ImageFileFormat.TiffLzw: case ImageFileFormat.TiffZip: return(ReadTiff(pointer.Pointer, sizeInMemory)); default: return(new [] { ReadImage(pointer.Pointer, sizeInMemory) }); } }
internal Pix(string imageFilePath) : base(() => Leptonica5Pix.pixRead(imageFilePath)) { Width = Leptonica5Pix.pixGetWidth(HandleRef); Height = Leptonica5Pix.pixGetHeight(HandleRef); Depth = Leptonica5Pix.pixGetDepth(HandleRef); }
private static void Destroy(IEnumerable <Pix> pages) { foreach (var page in pages) { var pointer = page.HandleRef.Handle; Leptonica5Pix.pixDestroy(ref pointer); } }
public PixData(Pix pix) { if (pix == null) { throw new ArgumentNullException(nameof(pix)); } Data = Leptonica5Pix.pixGetData(pix.HandleRef); WordsPerLine = Leptonica5Pix.pixGetWpl(pix.HandleRef); }
public ImageFileFormat GetFileFormat(ReadOnlyMemory <byte> memory) { using var pointer = memory.Pin(); if (Leptonica5Pix.findFileFormatBuffer(pointer.Pointer, out var format) != 0) { return(ImageFileFormat.Unknown); } return(format); }
public ImageFileFormat GetFileFormat(ReadOnlySpan <byte> span) { fixed(byte *p = span) { if (Leptonica5Pix.findFileFormatBuffer(p, out var format) != 0) { return(ImageFileFormat.Unknown); } return(format); } }
public void AddPix(IPix pix) { if (pix == null) { throw new ArgumentNullException(nameof(pix)); } if (Leptonica5Pix.pixaAddPix(HandleRef.Handle, pix.HandleRef.Handle, 1) != 0) { throw new InvalidOperationException("Leptonica failed."); } }
public IEnumerable <IPix> Create(string imageFilePath) { if (Leptonica5Pix.findFileFormat(imageFilePath, out var format) != 0) { throw new InvalidOperationException("File format not supported."); } switch (format) { case ImageFileFormat.Default: case ImageFileFormat.Tiff: case ImageFileFormat.TiffPackbits: case ImageFileFormat.TiffRle: case ImageFileFormat.TiffG3: case ImageFileFormat.TiffG4: case ImageFileFormat.TiffLzw: case ImageFileFormat.TiffZip: return(ReadTiff(imageFilePath)); default: return(new [] { ReadImage(imageFilePath) }); } }
public Boxa(int initialPointersCount = 0) : base(() => Leptonica5Pix.boxaCreate(initialPointersCount)) { }
protected override void DestroyObject(ref IntPtr pointer) => Leptonica5Pix.boxaDestroy(ref pointer);
private static unsafe IEnumerable <IPix> ReadTiff(void *nativePointer, int size) { var pointer = Leptonica5Pix.pixaReadMemMultipageTiff(nativePointer, size).GetPointerOrThrow(); return(ReadTiff(pointer)); }
public PixColormap(int depth) : base(() => Leptonica5Pix.pixcmapCreate(depth)) { }
private static IEnumerable <IPix> ReadTiff(string filename) { var pointer = Leptonica5Pix.pixaReadMultipageTiff(filename).GetPointerOrThrow(); return(ReadTiff(pointer)); }
private static IPix ReadImage(string filename) { var pixPointer = Leptonica5Pix.pixRead(filename).GetPointerOrThrow(); return(new Pix(pixPointer)); }
private static unsafe IPix ReadImage(void *pointer, int size) { var pixPointer = Leptonica5Pix.pixReadMem(pointer, size).GetPointerOrThrow(); return(new Pix(pixPointer)); }
public bool AddColor(IPixColor color) { return(Leptonica5Pix.pixcmapAddColor(HandleRef, color.Red, color.Green, color.Blue) == 0); }
protected override void DestroyObject(ref IntPtr pointer) { Leptonica5Pix.pixcmapDestroy(ref pointer); }