Phreak87 / LeptonicaSharp

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

Pix data property #28

Closed fdncred closed 5 years ago

fdncred commented 5 years ago

I had to change this property because if you iterate data it takes way too long.

New Code:

    Dim _data As Byte()
    ReadOnly Property data As Byte()
        Get
            If (_data Is Nothing) Then
                Marshal.PtrToStructure(Pointer, Values)
                ReDim _data((w * h * (d / 8)) - 1)
                Marshal.Copy(Values.data, _data, 0, _data.Length)
                Return _data
            Else
                Return _data
            End If
        End Get
    End Property

It now has a backing property so each time you loop on the data property it doesn't try to marshal the entire data pointer.

Phreak87 commented 5 years ago

Very Dangerous! If you do something with pix over all_functions the byte() will Be not updated! I fix the getdata. This should be the safe way.

Phreak87 commented 5 years ago

Marshal.PtrToStructure(Pointer, Values) in the first line stands for update the values from memory for exactly this case. you can try with sarray to see what i mean: Create Sarray Object with ("1","2","3") Add "4" to the Array via _all and then look at the old Object (if marshal ... removed) you see exactly 1,2 and 3 ... not the 4. the same is with pix if you work with a backing property.

fdncred commented 5 years ago

I understand Marshal.PtrToStructure(). My point is that if you try and use the data property and iterate through it in a for loop, then every iteration will cause the entire image to be re-marshalled, which is a waste of time and terribly inefficient. For that reason, I'm keeping my backing property and if I want to make changes I can always use the Set on the data property. So, until the data property is fixed/changed this should stay open.

Phreak87 commented 5 years ago

Created additionally a DataStatic Property - which is the data of the first access if pix is changed (unsure if this ever occurs) this data stays old. (and will be also destroyed if pix is destroyed). for your cases its exactly what you need i think