Phreak87 / LeptonicaSharp

Full featured wrapper for leptonica 1.77.0
Other
8 stars 5 forks source link

Bitonal Bitmap #24

Closed fdncred closed 5 years ago

fdncred commented 5 years ago

The ToBitmap() routine doesn't seem to work on 1-bpp bitonal images. All of these bitmaps silently fail. The function does not throw an exception but the bitmaps it creates are invalid.

static void Main(string[] args)
{
    Natives.Initialize();
    _AllFunctions.setLeptDebugOK(1);
    var pix = new Pix(file6);
    var b0 = pix.ToBitmap();
    var pixa = _AllFunctions.pixaCreate(0);
    _AllFunctions.pixGetRegionsBinary(pix, out Pix ppixhm, out Pix ppixtm, out Pix ppixtb, pixa);
    var b1 = ppixhm.ToBitmap();
    var b2 = ppixtm.ToBitmap();
    var b3 = ppixtb.ToBitmap();
}
Phreak87 commented 5 years ago

Oh, that's right. Bitmap does not support 1bit and the transfer is inmemory from writemem. The only way to handle is to convert to higher bpp and get the bitmap. Should be fixed in next release

Phreak87 commented 5 years ago

Additionally with this I removed all (1,2,4,8,16,32)to (1,2,4,8,16,32) functions and replaced it with the more global to(1,2,4,8,16,32) function. Fixed in next release

fdncred commented 5 years ago

I think it's a bad idea to convert 1-bpp to a higher bpp. People using this assembly will want to look at the data the way it is, not in a different format. We need a vb compatible version of what I already wrote in csharp. Just using marshalling instead of unsafe pointers.

Phreak87 commented 5 years ago

Sure, thats all right. But this data is primary for display and File-Saving (Converts up internally). For further working with leptonica the original pix is untouched 1Bpp. 2Bpp works also out of the box. the main problem is the Bitmap.FromStream function which is not working with 1Bpp. i Updated to convertto2 as smallest possible value for working with the direct FromStream function which is the fastest way.