Closed fdncred closed 5 years ago
i work on a new implementation for ToBitmap based on the Leptonica Functions. and it works now out of the box (except some problems with 16bpp from 32BPP, but up from 1,2,4,8 works ...). Try Leptonicas Cat.007.jpg to see what i mean.
Public Function ToBitmap() As Image
Dim Size As Integer = 0
Dim Bytes As Byte() = Nothing
Dim PixU As Pix = Me
If Me.d = 1 Then PixU = Me.pixConvertTo16
_All.pixWriteMemBmp(Bytes, Size, Me)
Dim MemStrm As New IO.MemoryStream(Bytes)
Return New Bitmap(MemStrm, True)
End Function
I'll test it tomorrow. Mine matches Charles' Tesseract implementation and runs parallel. I'll be interested to see which is faster.
Yes, that's a good question. I like to keep things simple, because Keep that structure in mind is hard enough. Can you check also the cat007 image and colormaps.
Doesn't work on 1bpp images. I'm not sure why you'd convert a 1bpp to a 16bpp image anyway, especially when pixConvertTo16 doesn't allow depth 1-8 to be converted to 16bpp. I commented that conversion out.
Also, cat.007.jpg acts strangely. It seems to convert but I can't visualize it with my debugger visualizer, but I can save it. It doesn't have colormaps, so I'm not sure what you're talking about.
Pix conversion don't works from 32 to 16 but for 1,2,4,8 to 16 is fine. pix to Bmp dont works without conversation for 1bpp! thats why i convert. (its possible to convert to 8 too ...) TestApplication - TestDisplay generates a 1Bpp Image, saves it via leptonica, transfers to Bmp and saves it and can display in a image box. i think thats fine! from a 32Bpp to 16Bpp i have psychodelic colors inside. (the gray of cat.007 are terrible colored). but you are also right. theres a "<= smaller, bigger =>" issue in convertto16 which causes a error if i try to convert.
maybe exactly this was your problem too.
Yet another thing I disagree with you about. It's never a good idea to convert an image to a different format unless you can't display that format, such as a DPix or FPix.
i full agree with you! its no good idea - its not my favourite to do things like that. Your Idea is great too but also not the perfect way i think. my fav is to copy the memory to a streamreader. maybe leptonica provides a other function for this case or ... leptonica export is wrong if Bitmap is 1Bpp on windows. In this case its a leptonica problem to handle. i ask dan bloomberg why this occurs.
Lets wait for an answer: https://github.com/DanBloomberg/leptonica/issues/380#issue-366528322
Committed preliminary code for Convert() with 4b2494b91aea91acdfb238fea59672226adeb1e3
Oh. Please stop until we discussed about!
Darren Schroeder notifications@github.com schrieb am Do., 4. Okt. 2018, 14:32:
Committed preliminary code for Convert() with 4b2494b https://github.com/Phreak87/LeptonicaSharp/commit/4b2494b91aea91acdfb238fea59672226adeb1e3
— You are receiving this because you modified the open/close state. Reply to this email directly, view it on GitHub https://github.com/Phreak87/LeptonicaSharp/issues/30#issuecomment-427000991, or mute the thread https://github.com/notifications/unsubscribe-auth/AHvBIOhq7CupOk_ZNV43cwC3BZ50muJPks5uhf_ogaJpZM4XEzSv .
Lets get more descriptive:
Folder Extensions is a "User-Class-Folder". My generator will not touch files inside. i Updated my File with yours but uncommented the 2px conversion. with this your function is included but my version works too. Regions are now in english language. For more additions think about creating a FDNCRED.vb in this folder with your additions and changes like your ConvertTo-Function.
All files in Functions (e.g. Pageseg.vb) are generated from the builder. each change will be deleted with the next commit. Changes to this files should only occur in the wrappergen. Natives.vb, Functions.vb (Functions Folder in 1 File) structures.vb, structureextensions.vb and enumerations.vb is the same.
sln and vbproj are static files. changed to your version.
Thank you for providing your C# test-Application and changing my pix files to files of the image folder.
for changes in the most descriptive files (via wrappergen) please open a issue and i will change the generators base.
For this topic we wait for a answer of dan bloomberg. correct output from leptonica is the best way!
Don't use 1 to 2 bpp conversion. Use this adapted code from fdncred especially for 1 bpp and Return the bitmap directly
Public Function ConvertTo1BPPBMP(ByVal Pix As Pix) As Bitmap Dim pixelFormat As PixelFormat = pixelFormat.Format1bppIndexed Dim img As Bitmap = New Bitmap(Pix.w, Pix.h, pixelFormat) Using pixNew As Pix = _All.pixEndianByteSwapNew(Pix) Try Dim imgData As BitmapData = img.LockBits(New Rectangle(0, 0, img.Width, img.Height), 2, pixelFormat) For y = 0 To imgData.Height - 1 For x = 0 To imgData.Width - 1 Step 8 Dim index As Integer = (y pixNew.wpl 4) + (x >> 3) If index > pixNew.DataStatic.Count - 1 Then Continue For Marshal.WriteByte(imgData.Scan0, index, Not pixNew.DataStatic(index)) Next Next : img.UnlockBits(imgData) : Return img Catch ex As Exception img.Dispose() End Try End Using Return Nothing End Function
I rewrote most of this code to work in VB.Net. Just call pix.Convert() and you'll get a dotnet bitmap, unless it's 16bpp. I've tested it on 1bpp, 8bpp, 24bpp, 32bpp. 24bpp may not be quite right. I'm not sure. My intent was to use this to replace your ToBitmap().
Note: Updated Convert to use pixEndianByteSwapNew(pix) so it doesn't overwrite the original pix. Probably need to look at this closer from a memory cleanup perspective