JWS C Library
C language utility library
|
00001 /* 00002 * This work is licensed under a Creative Commons 00003 * Attribution-Noncommercial-Share Alike 3.0 United States License. 00004 * 00005 * http://creativecommons.org/licenses/by-nc-sa/3.0/us/ 00006 * 00007 * You are free: 00008 * 00009 * to Share - to copy, distribute, display, and perform the work 00010 * to Remix - to make derivative works 00011 * 00012 * Under the following conditions: 00013 * 00014 * Attribution. You must attribute the work in the manner specified by the 00015 * author or licensor (but not in any way that suggests that they endorse you 00016 * or your use of the work). 00017 * 00018 * Noncommercial. You may not use this work for commercial purposes. 00019 * 00020 * Share Alike. If you alter, transform, or build upon this work, you may 00021 * distribute the resulting work only under the same or similar license to 00022 * this one. 00023 * 00024 * For any reuse or distribution, you must make clear to others the license 00025 * terms of this work. The best way to do this is by including this header. 00026 * 00027 * Any of the above conditions can be waived if you get permission from the 00028 * copyright holder. 00029 * 00030 * Apart from the remix rights granted under this license, nothing in this 00031 * license impairs or restricts the author's moral rights. 00032 */ 00033 00034 00046 #include <jwsc/config.h> 00047 00048 #include <stdlib.h> 00049 #include <inttypes.h> 00050 #include <math.h> 00051 #include <assert.h> 00052 00053 #include "jwsc/matrix/matrix.h" 00054 00055 00072 Error* extend_matrix_f 00073 ( 00074 Matrix_f** mat_out, 00075 const Matrix_f* mat_in, 00076 uint32_t row_padding, 00077 uint32_t col_padding 00078 ) 00079 { 00080 uint32_t num_rows, num_cols; 00081 uint32_t num_prows, num_pcols; 00082 uint32_t prow, pcol; 00083 00084 Matrix_f* mat; 00085 00086 num_rows = mat_in->num_rows; 00087 num_cols = mat_in->num_cols; 00088 00089 num_prows = num_rows + 2*row_padding; 00090 num_pcols = num_cols + 2*col_padding; 00091 00092 mat = (*mat_out == mat_in) ? NULL : *mat_out; 00093 create_matrix_f(&mat, num_prows, num_pcols); 00094 00095 for (prow = 0; prow < (num_prows - row_padding); prow++) 00096 { 00097 if (prow < row_padding) 00098 { 00099 for (pcol = 0; pcol < col_padding; pcol++) 00100 { 00101 mat->elts[ prow ][ pcol ] 00102 = mat_in->elts[ 0 ][ 0 ]; 00103 00104 mat->elts[ prow ][ num_pcols-pcol-1 ] 00105 = mat_in->elts[ 0 ][ num_cols-1 ]; 00106 00107 mat->elts[ num_prows-prow-1 ][ pcol ] 00108 = mat_in->elts[ num_rows-1 ][ 0 ]; 00109 00110 mat->elts[ num_prows-prow-1 ][ num_pcols-pcol-1 ] 00111 = mat_in->elts[ num_rows-1 ][ num_cols-1 ]; 00112 } 00113 for (pcol = col_padding; pcol < (num_pcols-col_padding); pcol++) 00114 { 00115 mat->elts[ prow ][ pcol ] 00116 = mat_in->elts[ 0 ][ pcol-col_padding ]; 00117 mat->elts[ num_prows-prow-1 ][ pcol ] 00118 = mat_in->elts[ num_rows-1 ][ pcol-col_padding ]; 00119 } 00120 } 00121 else 00122 { 00123 for (pcol = 0; pcol < col_padding; pcol++) 00124 { 00125 mat->elts[ prow ][ pcol ] 00126 = mat_in->elts[ prow-row_padding ][ 0 ]; 00127 mat->elts[ prow ][ num_pcols-pcol-1 ] 00128 = mat_in->elts[ prow-row_padding ][ num_cols-1 ]; 00129 } 00130 for (pcol = col_padding; pcol < (num_pcols-col_padding); pcol++) 00131 { 00132 mat->elts[ prow ][ pcol ] 00133 = mat_in->elts[ prow-row_padding][ pcol-col_padding ]; 00134 } 00135 } 00136 } 00137 00138 *mat_out = mat; 00139 00140 return NULL; 00141 } 00142