private void ComputeEndPoints(SingleColourLookup[][] lookups) { // check each index combination (endpoint or intermediate) m_error = int.MaxValue; for (int index = 0; index < 2; ++index) { // check the error for this codebook index SourceBlock[] sources = new SourceBlock[3]; int error = 0; for( int channel = 0; channel < 3; ++channel ) { // grab the lookup table and index for this channel SingleColourLookup[] lookup = lookups[channel]; int target = m_colour[channel]; // store a pointer to the source for this channel sources[channel] = lookup[target].sources[index]/* + index*/; // accumulate the error int diff = sources[channel].error; error += diff * diff; } // keep it if the error is lower if (error < m_error) { m_start = new Vec3( (float)sources[0].start / 31.0f, (float)sources[1].start / 63.0f, (float)sources[2].start / 31.0f ); m_end = new Vec3( (float)sources[0].end / 31.0f, (float)sources[1].end / 63.0f, (float)sources[2].end / 31.0f ); m_index = (byte)(2 * index); m_error = error; } } }
private unsafe void ComputeEndPoints(SingleColourLookup[][] lookups) { // check each index combination (endpoint or intermediate) SourceBlock* sources = stackalloc SourceBlock[3]; _error = int.MaxValue; for (int index = 0; index < 2; ++index) { // check the error for this codebook index int error = 0; for (int channel = 0; channel < 3; ++channel) { // grab the lookup table and index for this channel SingleColourLookup[] lookup = lookups[channel]; int target = _colour[channel]; // store a pointer to the source for this channel sources[channel] = (index == 0) ? lookup[target].Sources0 : lookup[target].Sources1; // accumulate the error int diff = sources[channel].Error; error += diff * diff; } // keep it if the error is lower if (error < _error) { _start = new Vector3F( sources[0].Start / 31.0f, sources[1].Start / 63.0f, sources[2].Start / 31.0f ); _end = new Vector3F( sources[0].End / 31.0f, sources[1].End / 63.0f, sources[2].End / 31.0f ); _index = (byte)(2 * index); _error = error; } } }