Private Function MakeHash(ByVal rgba As Uinteger) As UInteger Try '1 rgba -= (rgba >> 13) Or (rgba << 19) '2 rgba -= (rgba >> 13) Or (rgba << 19) '3 rgba -= (rgba >> 13) Or (rgba << 19) rgba -= (rgba >> 13) Or (rgba << 19) rgba -= (rgba >> 13) Or (rgba << 19) rgba = rgba And (EXQ_HASH_SIZE - 1) Return rgba Catch ex As Exception MessageBox.Show("ExoQuant.MakeHash: " + ex.Message + " " + ex.StackTrace) Return 255 End Try End Function
Public Sub Feed(ByVal pData As Byte()) Dim channelMask As Byte = &HFF00 >> pExq.numBitsPerChannel Dim nPixels As Integer = Int(pData.Length / 4) For i As Integer = 0 To nPixels - 1 Dim r As Byte = pData(i * 4 + 0), g As Byte = pData(i * 4 + 1), b As Byte = pData(i * 4 + 2), a As Byte = pData(i * 4 + 3) 'If pdata(i * 4 + 3) = 0 Then ' a = 255 'Else ' a = pData(i * 4 + 3) 'End If Dim hash As UInteger = MakeHash(ToRGBA(r, g, b, a)) Dim pCur As ExqHistogramEntry = pExq.pHash(hash) While pCur IsNot Nothing AndAlso (pCur.ored <> r OrElse pCur.ogreen <> g OrElse pCur.oblue <> b OrElse pCur.oalpha <> a) pCur = pCur.pNextInHash End While If pCur IsNot Nothing Then pCur.num += 1 Else pCur = New ExqHistogramEntry() pCur.pNextInHash = pExq.pHash(hash) pExq.pHash(hash) = pCur pCur.ored = r pCur.ogreen = g pCur.oblue = b pCur.oalpha = a r = r And channelMask g = g And channelMask b = b And channelMask pCur.color.r = r / 255.0F * SCALE_R pCur.color.g = g / 255.0F * SCALE_G pCur.color.b = b / 255.0F * SCALE_B pCur.color.a = a / 255.0F * SCALE_A If pExq.transparency Then pCur.color.r *= pCur.color.a pCur.color.g *= pCur.color.a pCur.color.b *= pCur.color.a End If pCur.num = 1 pCur.palIndex = -1 pCur.ditherScale.r = -1 pCur.ditherScale.g = -1 pCur.ditherScale.b = -1 pCur.ditherScale.a = -1 pCur.ditherIndex(0) = -1 pCur.ditherIndex(1) = -1 pCur.ditherIndex(2) = -1 pCur.ditherIndex(3) = -1 End If Next End Sub
Private Function ToRGBA(ByVal r As UInteger, ByVal g As UInteger, ByVal b As UInteger, ByVal a As UInteger) As UInteger Return r Or (g << 8) Or (b << 16) Or (a << 24) End Function
rgba -= (rgba >> 13) Or (rgba << 19) rgba -= (rgba >> 13) Or (rgba << 19) rgba -= (rgba >> 13) Or (rgba << 19) ' blows up here value of rgba before this line is 61151760 rgba -= (rgba >> 13) Or (rgba << 19) rgba -= (rgba >> 13) Or (rgba << 19) rgba = rgba And (EXQ_HASH_SIZE - 1)
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)