Exemplo n.º 1
0
        /// <summary>
        /// Calculate the the hash-code for a horizontal line
        /// </summary>
        /// <param name="y">int with y coordinate</param>
        /// <param name="right">optional x starting coordinate of the hash calculation</param>
        /// <param name="left">optional x ending coordinate of the hash calculation</param>
        /// <returns>uint with the hash</returns>
        public uint HorizontalHash(int y, int?right = null, int?left = null)
        {
            var offset = (left ?? Left) * BytesPerPixel + y * Stride;
            var length = (right ?? Right) - (left ?? Left) * BytesPerPixel;
            var hash   = new Murmur3(Seed, (uint)length);

            while (length >= 4)
            {
                hash.AddBytes(Pointer[offset++], Pointer[offset++], Pointer[offset++], Pointer[offset++]);
                length -= 4;
            }
            switch (length)
            {
            case 3:
                hash.AddTrailingBytes(Pointer[offset++], Pointer[offset++], Pointer[offset]);
                break;

            case 2:
                hash.AddTrailingBytes(Pointer[offset++], Pointer[offset]);
                break;

            case 1:
                hash.AddTrailingBytes(Pointer[offset]);
                break;
            }
            return(hash.CalculatedHash);
        }