コード例 #1
0
ファイル: Pix.cs プロジェクト: tsudnevitz/HardyBits.Ocr
 internal Pix(IntPtr pointer)
     : base(pointer)
 {
     Width  = Leptonica5Pix.pixGetWidth(HandleRef);
     Height = Leptonica5Pix.pixGetHeight(HandleRef);
     Depth  = Leptonica5Pix.pixGetDepth(HandleRef);
 }
コード例 #2
0
ファイル: Pixa.cs プロジェクト: tsudnevitz/HardyBits.Ocr
 public void AddPix(IntPtr pixPointer)
 {
     if (Leptonica5Pix.pixaAddPix(HandleRef.Handle, pixPointer, 1) != 0)
     {
         throw new InvalidOperationException("Leptonica failed.");
     }
 }
コード例 #3
0
        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);
            }
        }
コード例 #4
0
ファイル: Boxa.cs プロジェクト: tsudnevitz/HardyBits.Ocr
 public void AddBox(IntPtr boxPointer)
 {
     if (Leptonica5Pix.boxaAddBox(HandleRef.Handle, boxPointer, 0) != 0)
     {
         throw new InvalidOperationException("Leptonica failed.");
     }
 }
コード例 #5
0
ファイル: Pix.cs プロジェクト: tsudnevitz/HardyBits.Ocr
 internal Pix(int imageWidth, int imageHeight, int imageDepth)
     : base(() => Leptonica5Pix.pixCreate(imageWidth, imageHeight, imageDepth))
 {
     Width  = imageWidth;
     Height = imageHeight;
     Depth  = imageDepth;
 }
コード例 #6
0
        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) });
            }
        }
コード例 #7
0
ファイル: Pix.cs プロジェクト: tsudnevitz/HardyBits.Ocr
 internal Pix(string imageFilePath)
     : base(() => Leptonica5Pix.pixRead(imageFilePath))
 {
     Width  = Leptonica5Pix.pixGetWidth(HandleRef);
     Height = Leptonica5Pix.pixGetHeight(HandleRef);
     Depth  = Leptonica5Pix.pixGetDepth(HandleRef);
 }
コード例 #8
0
 private static void Destroy(IEnumerable <Pix> pages)
 {
     foreach (var page in pages)
     {
         var pointer = page.HandleRef.Handle;
         Leptonica5Pix.pixDestroy(ref pointer);
     }
 }
コード例 #9
0
ファイル: PixData.cs プロジェクト: tsudnevitz/HardyBits.Ocr
        public PixData(Pix pix)
        {
            if (pix == null)
            {
                throw new ArgumentNullException(nameof(pix));
            }

            Data         = Leptonica5Pix.pixGetData(pix.HandleRef);
            WordsPerLine = Leptonica5Pix.pixGetWpl(pix.HandleRef);
        }
コード例 #10
0
        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);
        }
コード例 #11
0
        public ImageFileFormat GetFileFormat(ReadOnlySpan <byte> span)
        {
            fixed(byte *p = span)
            {
                if (Leptonica5Pix.findFileFormatBuffer(p, out var format) != 0)
                {
                    return(ImageFileFormat.Unknown);
                }

                return(format);
            }
        }
コード例 #12
0
ファイル: Pixa.cs プロジェクト: tsudnevitz/HardyBits.Ocr
        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.");
            }
        }
コード例 #13
0
        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) });
            }
        }
コード例 #14
0
ファイル: Boxa.cs プロジェクト: tsudnevitz/HardyBits.Ocr
 public Boxa(int initialPointersCount = 0)
     : base(() => Leptonica5Pix.boxaCreate(initialPointersCount))
 {
 }
コード例 #15
0
ファイル: Boxa.cs プロジェクト: tsudnevitz/HardyBits.Ocr
 protected override void DestroyObject(ref IntPtr pointer) => Leptonica5Pix.boxaDestroy(ref pointer);
コード例 #16
0
        private static unsafe IEnumerable <IPix> ReadTiff(void *nativePointer, int size)
        {
            var pointer = Leptonica5Pix.pixaReadMemMultipageTiff(nativePointer, size).GetPointerOrThrow();

            return(ReadTiff(pointer));
        }
コード例 #17
0
 public PixColormap(int depth)
     : base(() => Leptonica5Pix.pixcmapCreate(depth))
 {
 }
コード例 #18
0
        private static IEnumerable <IPix> ReadTiff(string filename)
        {
            var pointer = Leptonica5Pix.pixaReadMultipageTiff(filename).GetPointerOrThrow();

            return(ReadTiff(pointer));
        }
コード例 #19
0
        private static IPix ReadImage(string filename)
        {
            var pixPointer = Leptonica5Pix.pixRead(filename).GetPointerOrThrow();

            return(new Pix(pixPointer));
        }
コード例 #20
0
        private static unsafe IPix ReadImage(void *pointer, int size)
        {
            var pixPointer = Leptonica5Pix.pixReadMem(pointer, size).GetPointerOrThrow();

            return(new Pix(pixPointer));
        }
コード例 #21
0
 public bool AddColor(IPixColor color)
 {
     return(Leptonica5Pix.pixcmapAddColor(HandleRef, color.Red, color.Green, color.Blue) == 0);
 }
コード例 #22
0
 protected override void DestroyObject(ref IntPtr pointer)
 {
     Leptonica5Pix.pixcmapDestroy(ref pointer);
 }