示例#1
0
/* Uses Gauss-Jordan elimination.

   The elimination procedure works by applying elementary row
   operations to our input matrix until the input matrix is reduced to
   the identity matrix.
   Simultaneously, we apply the same elementary row operations to a
   separate identity matrix to produce the inverse matrix.
   If this makes no sense, read wikipedia on Gauss-Jordan elimination.
   
   This is not the fastest way to invert matrices, so this is quite
   possibly the bottleneck. */
int destructive_invert_matrix(const Matrix_t * input, const Matrix_t * output)
{
	uint8_t i,j,r;
	double scalar, shear_needed;
	set_identity_matrix(output);

	/*
		Convert input to the identity matrix via elementary row operations.
		The ith pass through this loop turns the element at i,i to a 1
		and turns all other elements in column i to a 0.
	*/
	for (i = 0; i < input->rows; ++i)
	{
		if (input->data[i][i] == 0.0)
		{
			/* We must swap rows to get a nonzero diagonal element. */
			for (r = i + 1; r < input->rows; ++r)
			{
				if (input->data[r][i] != 0.0)
					break;
			}
			if (r == input->rows)
				/* Every remaining element in this column is zero, so this
				matrix cannot be inverted. */
				return 0;
			swap_rows(input, i, r);
			swap_rows(output, i, r);
		}

		/*
			Scale this row to ensure a 1 along the diagonal.
			We might need to worry about overflow from a huge scalar here. */
		scalar = 1.0 / input->data[i][i];
		scale_row(input, i, scalar);
		scale_row(output, i, scalar);

		/* Zero out the other elements in this column. */
		for (j = 0; j < input->rows; ++j)
		{
			if (i == j)
				continue;
			shear_needed = -input->data[j][i];
			shear_row(input, j, i, shear_needed);
			shear_row(output, j, i, shear_needed);
		}
	}
	return 1;
}
void horiz_scale (filter_base* filter,uint8 *sdata, uint32 sw, uint32 sh, uint8 *ddata, uint32 dw, uint32 dh,uint32 spitch,uint32 dtype) 
{ 
    uint32  u ;
	line_contrib_type * contrib;
    if (dw == sw)
    {   // No scaling required, just copy
        if(dtype == DISPLAY_PIXEL_FORMAT_8888)
			memcpy (ddata, sdata, sizeof (uint32) * sw * sh);
		else
			memcpy (ddata, sdata, sizeof (uint16) * sw * sh);
    }
    // Allocate and calculate the contributions
    contrib = calc_contributions (filter, dw, sw, (double)dw / (double)sw); 
    for (u = 0; u < dh; u++)
    {   // Step through rows
		scale_row(sdata,sw,ddata,dw,u,contrib,spitch,dtype);
    }
    free_contributions (contrib);  // Free contributions structure
} 
示例#3
0
template <typename T, typename X>    void scaler<T, X>::scale_rows() {
    for (unsigned i = 0; i < m_A.row_count(); i++)
        scale_row(i);
}