Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 2 additions & 4 deletions src/Tesseract/BitmapToPixConverter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,11 @@ public BitmapToPixConverter()
public Pix Convert(Bitmap img)
{
var pixDepth = GetPixDepth(img.PixelFormat);
var pix = Pix.Create(img.Width, img.Height, pixDepth);
var pix = Pix.Create(img, pixDepth);

BitmapData imgData = null;
PixData pixData = null;
try {
// TODO: Set X and Y resolution

if ((img.PixelFormat & PixelFormat.Indexed) == PixelFormat.Indexed) {
CopyColormap(img, pix);
}
Expand Down Expand Up @@ -164,4 +162,4 @@ private unsafe void TransferDataFormat8bppIndexed(BitmapData imgData, PixData pi
}
}
}
}
}
18 changes: 17 additions & 1 deletion src/Tesseract/Pix.cs
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,22 @@ private Pix(IntPtr handle)
}
}

public static Pix Create(Bitmap img, int depth)
{
if (!AllowedDepths.Contains(depth))
throw new ArgumentException("Depth must be 1, 2, 4, 8, 16, or 32 bits.", "depth");

if (img.Width <= 0) throw new ArgumentException("Width must be greater than zero", "width");
if (img.Height <= 0) throw new ArgumentException("Height must be greater than zero", "height");

var handle = Interop.LeptonicaApi.Native.pixCreate(img.Width, img.Height, depth);
if (handle == IntPtr.Zero) throw new InvalidOperationException("Failed to create pix, this normally occurs because the requested image size is too large, please check Standard Error Output.");
var pix = Create(handle);
Interop.LeptonicaApi.Native.pixSetResolution(pix.Handle, (int)img.HorizontalResolution, (int)img.VerticalResolution);

return pix;
}

public static Pix Create(int width, int height, int depth)
{
if (!AllowedDepths.Contains(depth))
Expand Down Expand Up @@ -639,4 +655,4 @@ protected override void Dispose(bool disposing)

#endregion Disposal
}
}
}