| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1 | /* |
| 2 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 3 | % % |
| 4 | % % |
| 5 | % % |
| 6 | % M M AAA TTTTT RRRR IIIII X X % |
| 7 | % MM MM A A T R R I X X % |
| 8 | % M M M AAAAA T RRRR I X % |
| 9 | % M M A A T R R I X X % |
| 10 | % M M A A T R R IIIII X X % |
| 11 | % % |
| 12 | % % |
| 13 | % MagickCore Matrix Methods % |
| 14 | % % |
| 15 | % Software Design % |
| cristy | de984cd | 2013-12-01 14:49:27 +0000 | [diff] [blame] | 16 | % Cristy % |
| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 17 | % August 2007 % |
| 18 | % % |
| 19 | % % |
| cristy | b56bb24 | 2014-11-25 17:12:48 +0000 | [diff] [blame] | 20 | % Copyright 1999-2015 ImageMagick Studio LLC, a non-profit organization % |
| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 21 | % dedicated to making software imaging solutions freely available. % |
| 22 | % % |
| 23 | % You may not use this file except in compliance with the License. You may % |
| 24 | % obtain a copy of the License at % |
| 25 | % % |
| 26 | % http://www.imagemagick.org/script/license.php % |
| 27 | % % |
| 28 | % Unless required by applicable law or agreed to in writing, software % |
| 29 | % distributed under the License is distributed on an "AS IS" BASIS, % |
| 30 | % WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. % |
| 31 | % See the License for the specific language governing permissions and % |
| 32 | % limitations under the License. % |
| 33 | % % |
| 34 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 35 | % |
| 36 | % |
| 37 | */ |
| 38 | |
| 39 | /* |
| 40 | Include declarations. |
| 41 | */ |
| cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 42 | #include "MagickCore/studio.h" |
| cristy | 106efa1 | 2014-03-09 01:06:05 +0000 | [diff] [blame] | 43 | #include "MagickCore/blob.h" |
| 44 | #include "MagickCore/blob-private.h" |
| 45 | #include "MagickCore/cache.h" |
| 46 | #include "MagickCore/exception.h" |
| 47 | #include "MagickCore/exception-private.h" |
| dirk | 007e925 | 2015-01-15 21:02:57 +0000 | [diff] [blame] | 48 | #include "MagickCore/image-private.h" |
| cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 49 | #include "MagickCore/matrix.h" |
| 50 | #include "MagickCore/memory_.h" |
| cristy | 0f09a8c | 2014-04-23 00:20:40 +0000 | [diff] [blame] | 51 | #include "MagickCore/pixel-accessor.h" |
| cristy | 106efa1 | 2014-03-09 01:06:05 +0000 | [diff] [blame] | 52 | #include "MagickCore/pixel-private.h" |
| 53 | #include "MagickCore/resource_.h" |
| cristy | cba9e95 | 2014-03-30 23:17:57 +0000 | [diff] [blame] | 54 | #include "MagickCore/semaphore.h" |
| cristy | f3b58c5 | 2014-04-22 01:27:24 +0000 | [diff] [blame] | 55 | #include "MagickCore/thread-private.h" |
| cristy | 106efa1 | 2014-03-09 01:06:05 +0000 | [diff] [blame] | 56 | #include "MagickCore/utility.h" |
| 57 | |
| 58 | /* |
| 59 | Typedef declaration. |
| 60 | */ |
| 61 | struct _MatrixInfo |
| 62 | { |
| 63 | CacheType |
| 64 | type; |
| 65 | |
| 66 | size_t |
| 67 | columns, |
| 68 | rows, |
| 69 | stride; |
| 70 | |
| 71 | MagickSizeType |
| 72 | length; |
| 73 | |
| 74 | MagickBooleanType |
| cristy | c1712b2 | 2014-03-09 14:54:05 +0000 | [diff] [blame] | 75 | mapped, |
| 76 | synchronize; |
| cristy | 106efa1 | 2014-03-09 01:06:05 +0000 | [diff] [blame] | 77 | |
| 78 | char |
| cristy | 151b66d | 2015-04-15 10:50:31 +0000 | [diff] [blame] | 79 | path[MagickPathExtent]; |
| cristy | 106efa1 | 2014-03-09 01:06:05 +0000 | [diff] [blame] | 80 | |
| 81 | int |
| 82 | file; |
| 83 | |
| 84 | void |
| 85 | *elements; |
| 86 | |
| cristy | cba9e95 | 2014-03-30 23:17:57 +0000 | [diff] [blame] | 87 | SemaphoreInfo |
| 88 | *semaphore; |
| 89 | |
| cristy | 106efa1 | 2014-03-09 01:06:05 +0000 | [diff] [blame] | 90 | size_t |
| 91 | signature; |
| 92 | }; |
| 93 | |
| 94 | /* |
| 95 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 96 | % % |
| 97 | % % |
| 98 | % % |
| 99 | % A c q u i r e M a t r i x I n f o % |
| 100 | % % |
| 101 | % % |
| 102 | % % |
| 103 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 104 | % |
| cristy | c1712b2 | 2014-03-09 14:54:05 +0000 | [diff] [blame] | 105 | % AcquireMatrixInfo() allocates the ImageInfo structure. |
| cristy | 106efa1 | 2014-03-09 01:06:05 +0000 | [diff] [blame] | 106 | % |
| 107 | % The format of the AcquireMatrixInfo method is: |
| 108 | % |
| 109 | % MatrixInfo *AcquireMatrixInfo(const size_t columns,const size_t rows, |
| 110 | % const size_t stride,ExceptionInfo *exception) |
| 111 | % |
| 112 | % A description of each parameter follows: |
| 113 | % |
| 114 | % o columns: the matrix columns. |
| 115 | % |
| 116 | % o rows: the matrix rows. |
| 117 | % |
| 118 | % o stride: the matrix stride. |
| 119 | % |
| 120 | % o exception: return any errors or warnings in this structure. |
| 121 | % |
| 122 | */ |
| cristy | c1712b2 | 2014-03-09 14:54:05 +0000 | [diff] [blame] | 123 | |
| cristy | c1712b2 | 2014-03-09 14:54:05 +0000 | [diff] [blame] | 124 | #if defined(SIGBUS) |
| 125 | static void MatrixSignalHandler(int status) |
| 126 | { |
| 127 | ThrowFatalException(CacheFatalError,"UnableToExtendMatrixCache"); |
| 128 | } |
| 129 | #endif |
| 130 | |
| 131 | static inline MagickOffsetType WriteMatrixElements( |
| 132 | const MatrixInfo *restrict matrix_info,const MagickOffsetType offset, |
| 133 | const MagickSizeType length,const unsigned char *restrict buffer) |
| 134 | { |
| 135 | register MagickOffsetType |
| 136 | i; |
| 137 | |
| 138 | ssize_t |
| 139 | count; |
| 140 | |
| 141 | #if !defined(MAGICKCORE_HAVE_PWRITE) |
| cristy | 10c210e | 2014-03-30 23:27:24 +0000 | [diff] [blame] | 142 | LockSemaphoreInfo(matrix_info->semaphore); |
| cristy | c1712b2 | 2014-03-09 14:54:05 +0000 | [diff] [blame] | 143 | if (lseek(matrix_info->file,offset,SEEK_SET) < 0) |
| cristy | 10c210e | 2014-03-30 23:27:24 +0000 | [diff] [blame] | 144 | { |
| 145 | UnlockSemaphoreInfo(matrix_info->semaphore); |
| 146 | return((MagickOffsetType) -1); |
| 147 | } |
| cristy | c1712b2 | 2014-03-09 14:54:05 +0000 | [diff] [blame] | 148 | #endif |
| 149 | count=0; |
| 150 | for (i=0; i < (MagickOffsetType) length; i+=count) |
| 151 | { |
| 152 | #if !defined(MAGICKCORE_HAVE_PWRITE) |
| 153 | count=write(matrix_info->file,buffer+i,(size_t) MagickMin(length-i, |
| 154 | (MagickSizeType) SSIZE_MAX)); |
| 155 | #else |
| 156 | count=pwrite(matrix_info->file,buffer+i,(size_t) MagickMin(length-i, |
| 157 | (MagickSizeType) SSIZE_MAX),(off_t) (offset+i)); |
| 158 | #endif |
| 159 | if (count <= 0) |
| 160 | { |
| 161 | count=0; |
| 162 | if (errno != EINTR) |
| 163 | break; |
| 164 | } |
| 165 | } |
| cristy | 10c210e | 2014-03-30 23:27:24 +0000 | [diff] [blame] | 166 | #if !defined(MAGICKCORE_HAVE_PWRITE) |
| 167 | UnlockSemaphoreInfo(matrix_info->semaphore); |
| 168 | #endif |
| cristy | c1712b2 | 2014-03-09 14:54:05 +0000 | [diff] [blame] | 169 | return(i); |
| 170 | } |
| 171 | |
| 172 | static MagickBooleanType SetMatrixExtent(MatrixInfo *restrict matrix_info, |
| 173 | MagickSizeType length) |
| 174 | { |
| 175 | MagickOffsetType |
| 176 | count, |
| 177 | extent, |
| 178 | offset; |
| 179 | |
| 180 | if (length != (MagickSizeType) ((MagickOffsetType) length)) |
| 181 | return(MagickFalse); |
| 182 | offset=(MagickOffsetType) lseek(matrix_info->file,0,SEEK_END); |
| 183 | if (offset < 0) |
| 184 | return(MagickFalse); |
| 185 | if ((MagickSizeType) offset >= length) |
| 186 | return(MagickTrue); |
| 187 | extent=(MagickOffsetType) length-1; |
| 188 | count=WriteMatrixElements(matrix_info,extent,1,(const unsigned char *) ""); |
| 189 | #if defined(MAGICKCORE_HAVE_POSIX_FALLOCATE) |
| 190 | if (matrix_info->synchronize != MagickFalse) |
| cristy | bb380e7 | 2014-10-31 12:56:36 +0000 | [diff] [blame] | 191 | (void) posix_fallocate(matrix_info->file,offset+1,extent-offset); |
| cristy | c1712b2 | 2014-03-09 14:54:05 +0000 | [diff] [blame] | 192 | #endif |
| 193 | #if defined(SIGBUS) |
| 194 | (void) signal(SIGBUS,MatrixSignalHandler); |
| 195 | #endif |
| 196 | return(count != (MagickOffsetType) 1 ? MagickFalse : MagickTrue); |
| 197 | } |
| 198 | |
| cristy | 106efa1 | 2014-03-09 01:06:05 +0000 | [diff] [blame] | 199 | MagickExport MatrixInfo *AcquireMatrixInfo(const size_t columns, |
| 200 | const size_t rows,const size_t stride,ExceptionInfo *exception) |
| 201 | { |
| cristy | c1712b2 | 2014-03-09 14:54:05 +0000 | [diff] [blame] | 202 | char |
| 203 | *synchronize; |
| 204 | |
| cristy | 106efa1 | 2014-03-09 01:06:05 +0000 | [diff] [blame] | 205 | MagickBooleanType |
| 206 | status; |
| 207 | |
| 208 | MatrixInfo |
| 209 | *matrix_info; |
| 210 | |
| 211 | matrix_info=(MatrixInfo *) AcquireMagickMemory(sizeof(*matrix_info)); |
| 212 | if (matrix_info == (MatrixInfo *) NULL) |
| 213 | return((MatrixInfo *) NULL); |
| 214 | (void) ResetMagickMemory(matrix_info,0,sizeof(*matrix_info)); |
| cristy | e1c94d9 | 2015-06-28 12:16:33 +0000 | [diff] [blame] | 215 | matrix_info->signature=MagickCoreSignature; |
| cristy | 106efa1 | 2014-03-09 01:06:05 +0000 | [diff] [blame] | 216 | matrix_info->columns=columns; |
| 217 | matrix_info->rows=rows; |
| 218 | matrix_info->stride=stride; |
| cristy | cba9e95 | 2014-03-30 23:17:57 +0000 | [diff] [blame] | 219 | matrix_info->semaphore=AcquireSemaphoreInfo(); |
| cristy | c1712b2 | 2014-03-09 14:54:05 +0000 | [diff] [blame] | 220 | synchronize=GetEnvironmentValue("MAGICK_SYNCHRONIZE"); |
| 221 | if (synchronize != (const char *) NULL) |
| 222 | { |
| 223 | matrix_info->synchronize=IsStringTrue(synchronize); |
| 224 | synchronize=DestroyString(synchronize); |
| 225 | } |
| cristy | 106efa1 | 2014-03-09 01:06:05 +0000 | [diff] [blame] | 226 | matrix_info->length=(MagickSizeType) columns*rows*stride; |
| 227 | if (matrix_info->columns != (size_t) (matrix_info->length/rows/stride)) |
| 228 | { |
| 229 | (void) ThrowMagickException(exception,GetMagickModule(),CacheError, |
| 230 | "CacheResourcesExhausted","`%s'","matrix cache"); |
| 231 | return(DestroyMatrixInfo(matrix_info)); |
| 232 | } |
| 233 | matrix_info->type=MemoryCache; |
| 234 | status=AcquireMagickResource(AreaResource,matrix_info->length); |
| 235 | if ((status != MagickFalse) && |
| 236 | (matrix_info->length == (MagickSizeType) ((size_t) matrix_info->length))) |
| 237 | { |
| 238 | status=AcquireMagickResource(MemoryResource,matrix_info->length); |
| 239 | if (status != MagickFalse) |
| 240 | { |
| cristy | c1712b2 | 2014-03-09 14:54:05 +0000 | [diff] [blame] | 241 | matrix_info->mapped=MagickFalse; |
| cristy | 106efa1 | 2014-03-09 01:06:05 +0000 | [diff] [blame] | 242 | matrix_info->elements=AcquireMagickMemory((size_t) |
| 243 | matrix_info->length); |
| 244 | if (matrix_info->elements == NULL) |
| 245 | { |
| 246 | matrix_info->mapped=MagickTrue; |
| 247 | matrix_info->elements=MapBlob(-1,IOMode,0,(size_t) |
| 248 | matrix_info->length); |
| 249 | } |
| 250 | if (matrix_info->elements == (unsigned short *) NULL) |
| 251 | RelinquishMagickResource(MemoryResource,matrix_info->length); |
| 252 | } |
| 253 | } |
| 254 | matrix_info->file=(-1); |
| 255 | if (matrix_info->elements == (unsigned short *) NULL) |
| 256 | { |
| 257 | status=AcquireMagickResource(DiskResource,matrix_info->length); |
| 258 | if (status == MagickFalse) |
| 259 | { |
| 260 | (void) ThrowMagickException(exception,GetMagickModule(),CacheError, |
| 261 | "CacheResourcesExhausted","`%s'","matrix cache"); |
| 262 | return(DestroyMatrixInfo(matrix_info)); |
| 263 | } |
| 264 | matrix_info->type=DiskCache; |
| 265 | (void) AcquireMagickResource(MemoryResource,matrix_info->length); |
| 266 | matrix_info->file=AcquireUniqueFileResource(matrix_info->path); |
| 267 | if (matrix_info->file == -1) |
| 268 | return(DestroyMatrixInfo(matrix_info)); |
| 269 | status=AcquireMagickResource(MapResource,matrix_info->length); |
| 270 | if (status != MagickFalse) |
| 271 | { |
| cristy | c1712b2 | 2014-03-09 14:54:05 +0000 | [diff] [blame] | 272 | status=SetMatrixExtent(matrix_info,matrix_info->length); |
| cristy | 106efa1 | 2014-03-09 01:06:05 +0000 | [diff] [blame] | 273 | if (status != MagickFalse) |
| 274 | { |
| 275 | matrix_info->elements=(void *) MapBlob(matrix_info->file,IOMode,0, |
| 276 | (size_t) matrix_info->length); |
| 277 | if (matrix_info->elements != NULL) |
| 278 | matrix_info->type=MapCache; |
| 279 | else |
| 280 | RelinquishMagickResource(MapResource,matrix_info->length); |
| 281 | } |
| 282 | } |
| 283 | } |
| 284 | return(matrix_info); |
| 285 | } |
| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 286 | |
| 287 | /* |
| 288 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 289 | % % |
| 290 | % % |
| 291 | % % |
| 292 | % A c q u i r e M a g i c k M a t r i x % |
| 293 | % % |
| 294 | % % |
| 295 | % % |
| 296 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 297 | % |
| 298 | % AcquireMagickMatrix() allocates and returns a matrix in the form of an |
| 299 | % array of pointers to an array of doubles, with all values pre-set to zero. |
| 300 | % |
| cristy | 106efa1 | 2014-03-09 01:06:05 +0000 | [diff] [blame] | 301 | % This used to generate the two dimensional matrix, and vectors required |
| 302 | % for the GaussJordanElimination() method below, solving some system of |
| 303 | % simultanious equations. |
| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 304 | % |
| 305 | % The format of the AcquireMagickMatrix method is: |
| 306 | % |
| cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 307 | % double **AcquireMagickMatrix(const size_t number_rows, |
| 308 | % const size_t size) |
| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 309 | % |
| 310 | % A description of each parameter follows: |
| 311 | % |
| cristy | 74908cf | 2010-05-17 19:43:54 +0000 | [diff] [blame] | 312 | % o number_rows: the number pointers for the array of pointers |
| cristy | 1ad491d | 2010-05-17 19:45:27 +0000 | [diff] [blame] | 313 | % (first dimension). |
| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 314 | % |
| cristy | 1ad491d | 2010-05-17 19:45:27 +0000 | [diff] [blame] | 315 | % o size: the size of the array of doubles each pointer points to |
| 316 | % (second dimension). |
| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 317 | % |
| 318 | */ |
| cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 319 | MagickExport double **AcquireMagickMatrix(const size_t number_rows, |
| 320 | const size_t size) |
| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 321 | { |
| 322 | double |
| cristy | 74908cf | 2010-05-17 19:43:54 +0000 | [diff] [blame] | 323 | **matrix; |
| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 324 | |
| cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 325 | register ssize_t |
| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 326 | i, |
| 327 | j; |
| 328 | |
| cristy | 74908cf | 2010-05-17 19:43:54 +0000 | [diff] [blame] | 329 | matrix=(double **) AcquireQuantumMemory(number_rows,sizeof(*matrix)); |
| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 330 | if (matrix == (double **) NULL) |
| cristy | f432c63 | 2014-12-07 15:11:28 +0000 | [diff] [blame] | 331 | return((double **) NULL); |
| cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 332 | for (i=0; i < (ssize_t) number_rows; i++) |
| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 333 | { |
| 334 | matrix[i]=(double *) AcquireQuantumMemory(size,sizeof(*matrix[i])); |
| 335 | if (matrix[i] == (double *) NULL) |
| 336 | { |
| 337 | for (j=0; j < i; j++) |
| 338 | matrix[j]=(double *) RelinquishMagickMemory(matrix[j]); |
| 339 | matrix=(double **) RelinquishMagickMemory(matrix); |
| 340 | return((double **) NULL); |
| 341 | } |
| cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 342 | for (j=0; j < (ssize_t) size; j++) |
| cristy | 74908cf | 2010-05-17 19:43:54 +0000 | [diff] [blame] | 343 | matrix[i][j]=0.0; |
| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 344 | } |
| 345 | return(matrix); |
| 346 | } |
| 347 | |
| 348 | /* |
| 349 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 350 | % % |
| 351 | % % |
| 352 | % % |
| cristy | 106efa1 | 2014-03-09 01:06:05 +0000 | [diff] [blame] | 353 | % D e s t r o y M a t r i x I n f o % |
| 354 | % % |
| 355 | % % |
| 356 | % % |
| 357 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 358 | % |
| 359 | % DestroyMatrixInfo() dereferences a matrix, deallocating memory associated |
| 360 | % with the matrix. |
| 361 | % |
| 362 | % The format of the DestroyImage method is: |
| 363 | % |
| 364 | % MatrixInfo *DestroyMatrixInfo(MatrixInfo *matrix_info) |
| 365 | % |
| 366 | % A description of each parameter follows: |
| 367 | % |
| 368 | % o matrix_info: the matrix. |
| 369 | % |
| 370 | */ |
| 371 | MagickExport MatrixInfo *DestroyMatrixInfo(MatrixInfo *matrix_info) |
| 372 | { |
| 373 | assert(matrix_info != (MatrixInfo *) NULL); |
| cristy | e1c94d9 | 2015-06-28 12:16:33 +0000 | [diff] [blame] | 374 | assert(matrix_info->signature == MagickCoreSignature); |
| cristy | cba9e95 | 2014-03-30 23:17:57 +0000 | [diff] [blame] | 375 | LockSemaphoreInfo(matrix_info->semaphore); |
| cristy | 106efa1 | 2014-03-09 01:06:05 +0000 | [diff] [blame] | 376 | switch (matrix_info->type) |
| 377 | { |
| 378 | case MemoryCache: |
| 379 | { |
| 380 | if (matrix_info->mapped == MagickFalse) |
| 381 | matrix_info->elements=RelinquishMagickMemory(matrix_info->elements); |
| 382 | else |
| 383 | { |
| 384 | (void) UnmapBlob(matrix_info->elements,(size_t) matrix_info->length); |
| 385 | matrix_info->elements=(unsigned short *) NULL; |
| 386 | } |
| 387 | RelinquishMagickResource(MemoryResource,matrix_info->length); |
| 388 | break; |
| 389 | } |
| 390 | case MapCache: |
| 391 | { |
| 392 | (void) UnmapBlob(matrix_info->elements,(size_t) matrix_info->length); |
| 393 | matrix_info->elements=NULL; |
| 394 | RelinquishMagickResource(MapResource,matrix_info->length); |
| 395 | } |
| 396 | case DiskCache: |
| 397 | { |
| 398 | if (matrix_info->file != -1) |
| 399 | (void) close(matrix_info->file); |
| 400 | (void) RelinquishUniqueFileResource(matrix_info->path); |
| 401 | RelinquishMagickResource(DiskResource,matrix_info->length); |
| 402 | break; |
| 403 | } |
| 404 | default: |
| 405 | break; |
| 406 | } |
| cristy | cba9e95 | 2014-03-30 23:17:57 +0000 | [diff] [blame] | 407 | UnlockSemaphoreInfo(matrix_info->semaphore); |
| 408 | RelinquishSemaphoreInfo(&matrix_info->semaphore); |
| cristy | 106efa1 | 2014-03-09 01:06:05 +0000 | [diff] [blame] | 409 | return((MatrixInfo *) RelinquishMagickMemory(matrix_info)); |
| 410 | } |
| 411 | |
| 412 | /* |
| 413 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 414 | % % |
| 415 | % % |
| 416 | % % |
| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 417 | % G a u s s J o r d a n E l i m i n a t i o n % |
| 418 | % % |
| 419 | % % |
| 420 | % % |
| 421 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 422 | % |
| 423 | % GaussJordanElimination() returns a matrix in reduced row echelon form, |
| 424 | % while simultaneously reducing and thus solving the augumented results |
| 425 | % matrix. |
| 426 | % |
| 427 | % See also http://en.wikipedia.org/wiki/Gauss-Jordan_elimination |
| 428 | % |
| 429 | % The format of the GaussJordanElimination method is: |
| 430 | % |
| cristy | 7dbde21 | 2014-10-11 06:59:40 +0000 | [diff] [blame] | 431 | % MagickBooleanType GaussJordanElimination(double **matrix, |
| 432 | % double **vectors,const size_t rank,const size_t number_vectors) |
| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 433 | % |
| 434 | % A description of each parameter follows: |
| 435 | % |
| 436 | % o matrix: the matrix to be reduced, as an 'array of row pointers'. |
| 437 | % |
| 438 | % o vectors: the additional matrix argumenting the matrix for row reduction. |
| 439 | % Producing an 'array of column vectors'. |
| 440 | % |
| cristy | 106efa1 | 2014-03-09 01:06:05 +0000 | [diff] [blame] | 441 | % o rank: The size of the matrix (both rows and columns). |
| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 442 | % Also represents the number terms that need to be solved. |
| 443 | % |
| cristy | 74908cf | 2010-05-17 19:43:54 +0000 | [diff] [blame] | 444 | % o number_vectors: Number of vectors columns, argumenting the above matrix. |
| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 445 | % Usally 1, but can be more for more complex equation solving. |
| 446 | % |
| 447 | % Note that the 'matrix' is given as a 'array of row pointers' of rank size. |
| 448 | % That is values can be assigned as matrix[row][column] where 'row' is |
| 449 | % typically the equation, and 'column' is the term of the equation. |
| 450 | % That is the matrix is in the form of a 'row first array'. |
| 451 | % |
| 452 | % However 'vectors' is a 'array of column pointers' which can have any number |
| 453 | % of columns, with each column array the same 'rank' size as 'matrix'. |
| 454 | % |
| 455 | % This allows for simpler handling of the results, especially is only one |
| cristy | 106efa1 | 2014-03-09 01:06:05 +0000 | [diff] [blame] | 456 | % column 'vector' is all that is required to produce the desired solution. |
| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 457 | % |
| 458 | % For example, the 'vectors' can consist of a pointer to a simple array of |
| 459 | % doubles. when only one set of simultanious equations is to be solved from |
| 460 | % the given set of coefficient weighted terms. |
| 461 | % |
| 462 | % double **matrix = AcquireMagickMatrix(8UL,8UL); |
| 463 | % double coefficents[8]; |
| 464 | % ... |
| 465 | % GaussJordanElimination(matrix, &coefficents, 8UL, 1UL); |
| anthony | 34364f4 | 2011-10-21 05:31:53 +0000 | [diff] [blame] | 466 | % |
| cristy | 106efa1 | 2014-03-09 01:06:05 +0000 | [diff] [blame] | 467 | % However by specifing more 'columns' (as an 'array of vector columns', |
| 468 | % you can use this function to solve a set of 'separable' equations. |
| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 469 | % |
| 470 | % For example a distortion function where u = U(x,y) v = V(x,y) |
| 471 | % And the functions U() and V() have separate coefficents, but are being |
| 472 | % generated from a common x,y->u,v data set. |
| 473 | % |
| cristy | 7dbde21 | 2014-10-11 06:59:40 +0000 | [diff] [blame] | 474 | % Another example is generation of a color gradient from a set of colors at |
| 475 | % specific coordients, such as a list x,y -> r,g,b,a. |
| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 476 | % |
| 477 | % You can also use the 'vectors' to generate an inverse of the given 'matrix' |
| cristy | 106efa1 | 2014-03-09 01:06:05 +0000 | [diff] [blame] | 478 | % though as a 'column first array' rather than a 'row first array'. For |
| cristy | 7dbde21 | 2014-10-11 06:59:40 +0000 | [diff] [blame] | 479 | % details see http://en.wikipedia.org/wiki/Gauss-Jordan_elimination |
| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 480 | % |
| 481 | */ |
| cristy | 106efa1 | 2014-03-09 01:06:05 +0000 | [diff] [blame] | 482 | MagickExport MagickBooleanType GaussJordanElimination(double **matrix, |
| cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 483 | double **vectors,const size_t rank,const size_t number_vectors) |
| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 484 | { |
| 485 | #define GaussJordanSwap(x,y) \ |
| 486 | { \ |
| 487 | if ((x) != (y)) \ |
| 488 | { \ |
| 489 | (x)+=(y); \ |
| 490 | (y)=(x)-(y); \ |
| 491 | (x)=(x)-(y); \ |
| 492 | } \ |
| 493 | } |
| 494 | |
| 495 | double |
| 496 | max, |
| 497 | scale; |
| 498 | |
| cristy | 9d314ff | 2011-03-09 01:30:28 +0000 | [diff] [blame] | 499 | register ssize_t |
| 500 | i, |
| 501 | j, |
| 502 | k; |
| 503 | |
| cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 504 | ssize_t |
| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 505 | column, |
| 506 | *columns, |
| 507 | *pivots, |
| 508 | row, |
| 509 | *rows; |
| 510 | |
| cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 511 | columns=(ssize_t *) AcquireQuantumMemory(rank,sizeof(*columns)); |
| 512 | rows=(ssize_t *) AcquireQuantumMemory(rank,sizeof(*rows)); |
| 513 | pivots=(ssize_t *) AcquireQuantumMemory(rank,sizeof(*pivots)); |
| 514 | if ((rows == (ssize_t *) NULL) || (columns == (ssize_t *) NULL) || |
| 515 | (pivots == (ssize_t *) NULL)) |
| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 516 | { |
| cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 517 | if (pivots != (ssize_t *) NULL) |
| 518 | pivots=(ssize_t *) RelinquishMagickMemory(pivots); |
| 519 | if (columns != (ssize_t *) NULL) |
| 520 | columns=(ssize_t *) RelinquishMagickMemory(columns); |
| 521 | if (rows != (ssize_t *) NULL) |
| 522 | rows=(ssize_t *) RelinquishMagickMemory(rows); |
| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 523 | return(MagickFalse); |
| 524 | } |
| 525 | (void) ResetMagickMemory(columns,0,rank*sizeof(*columns)); |
| 526 | (void) ResetMagickMemory(rows,0,rank*sizeof(*rows)); |
| 527 | (void) ResetMagickMemory(pivots,0,rank*sizeof(*pivots)); |
| 528 | column=0; |
| 529 | row=0; |
| cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 530 | for (i=0; i < (ssize_t) rank; i++) |
| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 531 | { |
| 532 | max=0.0; |
| cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 533 | for (j=0; j < (ssize_t) rank; j++) |
| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 534 | if (pivots[j] != 1) |
| 535 | { |
| cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 536 | for (k=0; k < (ssize_t) rank; k++) |
| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 537 | if (pivots[k] != 0) |
| 538 | { |
| 539 | if (pivots[k] > 1) |
| 540 | return(MagickFalse); |
| 541 | } |
| 542 | else |
| 543 | if (fabs(matrix[j][k]) >= max) |
| 544 | { |
| 545 | max=fabs(matrix[j][k]); |
| 546 | row=j; |
| 547 | column=k; |
| 548 | } |
| 549 | } |
| 550 | pivots[column]++; |
| 551 | if (row != column) |
| 552 | { |
| cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 553 | for (k=0; k < (ssize_t) rank; k++) |
| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 554 | GaussJordanSwap(matrix[row][k],matrix[column][k]); |
| cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 555 | for (k=0; k < (ssize_t) number_vectors; k++) |
| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 556 | GaussJordanSwap(vectors[k][row],vectors[k][column]); |
| 557 | } |
| 558 | rows[i]=row; |
| 559 | columns[i]=column; |
| 560 | if (matrix[column][column] == 0.0) |
| cristy | 106efa1 | 2014-03-09 01:06:05 +0000 | [diff] [blame] | 561 | return(MagickFalse); /* sigularity */ |
| cristy | 3e3ec3a | 2012-11-03 23:11:06 +0000 | [diff] [blame] | 562 | scale=PerceptibleReciprocal(matrix[column][column]); |
| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 563 | matrix[column][column]=1.0; |
| cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 564 | for (j=0; j < (ssize_t) rank; j++) |
| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 565 | matrix[column][j]*=scale; |
| cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 566 | for (j=0; j < (ssize_t) number_vectors; j++) |
| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 567 | vectors[j][column]*=scale; |
| cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 568 | for (j=0; j < (ssize_t) rank; j++) |
| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 569 | if (j != column) |
| 570 | { |
| 571 | scale=matrix[j][column]; |
| 572 | matrix[j][column]=0.0; |
| cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 573 | for (k=0; k < (ssize_t) rank; k++) |
| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 574 | matrix[j][k]-=scale*matrix[column][k]; |
| cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 575 | for (k=0; k < (ssize_t) number_vectors; k++) |
| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 576 | vectors[k][j]-=scale*vectors[k][column]; |
| 577 | } |
| 578 | } |
| cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 579 | for (j=(ssize_t) rank-1; j >= 0; j--) |
| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 580 | if (columns[j] != rows[j]) |
| cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 581 | for (i=0; i < (ssize_t) rank; i++) |
| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 582 | GaussJordanSwap(matrix[i][rows[j]],matrix[i][columns[j]]); |
| cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 583 | pivots=(ssize_t *) RelinquishMagickMemory(pivots); |
| 584 | rows=(ssize_t *) RelinquishMagickMemory(rows); |
| 585 | columns=(ssize_t *) RelinquishMagickMemory(columns); |
| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 586 | return(MagickTrue); |
| 587 | } |
| 588 | |
| 589 | /* |
| 590 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 591 | % % |
| 592 | % % |
| 593 | % % |
| cristy | 106efa1 | 2014-03-09 01:06:05 +0000 | [diff] [blame] | 594 | % G e t M a t r i x C o l u m n s % |
| 595 | % % |
| 596 | % % |
| 597 | % % |
| 598 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 599 | % |
| 600 | % GetMatrixColumns() returns the number of columns in the matrix. |
| 601 | % |
| 602 | % The format of the GetMatrixColumns method is: |
| 603 | % |
| 604 | % size_t GetMatrixColumns(const MatrixInfo *matrix_info) |
| 605 | % |
| 606 | % A description of each parameter follows: |
| 607 | % |
| 608 | % o matrix_info: the matrix. |
| 609 | % |
| 610 | */ |
| 611 | MagickExport size_t GetMatrixColumns(const MatrixInfo *matrix_info) |
| 612 | { |
| 613 | assert(matrix_info != (MatrixInfo *) NULL); |
| cristy | e1c94d9 | 2015-06-28 12:16:33 +0000 | [diff] [blame] | 614 | assert(matrix_info->signature == MagickCoreSignature); |
| cristy | 106efa1 | 2014-03-09 01:06:05 +0000 | [diff] [blame] | 615 | return(matrix_info->columns); |
| 616 | } |
| 617 | |
| 618 | /* |
| 619 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 620 | % % |
| 621 | % % |
| 622 | % % |
| 623 | % G e t M a t r i x E l e m e n t % |
| 624 | % % |
| 625 | % % |
| 626 | % % |
| 627 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 628 | % |
| 629 | % GetMatrixElement() returns the specifed element in the matrix. |
| 630 | % |
| 631 | % The format of the GetMatrixElement method is: |
| 632 | % |
| 633 | % MagickBooleanType GetMatrixElement(const MatrixInfo *matrix_info, |
| 634 | % const ssize_t x,const ssize_t y,void *value) |
| 635 | % |
| 636 | % A description of each parameter follows: |
| 637 | % |
| 638 | % o matrix_info: the matrix columns. |
| 639 | % |
| 640 | % o x: the matrix x-offset. |
| 641 | % |
| 642 | % o y: the matrix y-offset. |
| 643 | % |
| 644 | % o value: return the matrix element in this buffer. |
| 645 | % |
| 646 | */ |
| 647 | |
| cristy | 6cccee4 | 2014-03-23 00:25:22 +0000 | [diff] [blame] | 648 | static inline ssize_t EdgeX(const ssize_t x,const size_t columns) |
| 649 | { |
| 650 | if (x < 0L) |
| 651 | return(0L); |
| 652 | if (x >= (ssize_t) columns) |
| 653 | return((ssize_t) (columns-1)); |
| 654 | return(x); |
| 655 | } |
| 656 | |
| 657 | static inline ssize_t EdgeY(const ssize_t y,const size_t rows) |
| 658 | { |
| 659 | if (y < 0L) |
| 660 | return(0L); |
| 661 | if (y >= (ssize_t) rows) |
| 662 | return((ssize_t) (rows-1)); |
| 663 | return(y); |
| 664 | } |
| 665 | |
| cristy | c1712b2 | 2014-03-09 14:54:05 +0000 | [diff] [blame] | 666 | static inline MagickOffsetType ReadMatrixElements( |
| 667 | const MatrixInfo *restrict matrix_info,const MagickOffsetType offset, |
| 668 | const MagickSizeType length,unsigned char *restrict buffer) |
| cristy | 106efa1 | 2014-03-09 01:06:05 +0000 | [diff] [blame] | 669 | { |
| cristy | c1712b2 | 2014-03-09 14:54:05 +0000 | [diff] [blame] | 670 | register MagickOffsetType |
| cristy | 106efa1 | 2014-03-09 01:06:05 +0000 | [diff] [blame] | 671 | i; |
| 672 | |
| 673 | ssize_t |
| 674 | count; |
| 675 | |
| cristy | c1712b2 | 2014-03-09 14:54:05 +0000 | [diff] [blame] | 676 | #if !defined(MAGICKCORE_HAVE_PREAD) |
| cristy | 10c210e | 2014-03-30 23:27:24 +0000 | [diff] [blame] | 677 | LockSemaphoreInfo(matrix_info->semaphore); |
| cristy | c1712b2 | 2014-03-09 14:54:05 +0000 | [diff] [blame] | 678 | if (lseek(matrix_info->file,offset,SEEK_SET) < 0) |
| cristy | 10c210e | 2014-03-30 23:27:24 +0000 | [diff] [blame] | 679 | { |
| 680 | UnlockSemaphoreInfo(matrix_info->semaphore); |
| 681 | return((MagickOffsetType) -1); |
| 682 | } |
| cristy | 106efa1 | 2014-03-09 01:06:05 +0000 | [diff] [blame] | 683 | #endif |
| cristy | c1712b2 | 2014-03-09 14:54:05 +0000 | [diff] [blame] | 684 | count=0; |
| 685 | for (i=0; i < (MagickOffsetType) length; i+=count) |
| cristy | 106efa1 | 2014-03-09 01:06:05 +0000 | [diff] [blame] | 686 | { |
| cristy | c1712b2 | 2014-03-09 14:54:05 +0000 | [diff] [blame] | 687 | #if !defined(MAGICKCORE_HAVE_PREAD) |
| 688 | count=read(matrix_info->file,buffer+i,(size_t) MagickMin(length-i, |
| 689 | (MagickSizeType) SSIZE_MAX)); |
| cristy | 106efa1 | 2014-03-09 01:06:05 +0000 | [diff] [blame] | 690 | #else |
| cristy | c1712b2 | 2014-03-09 14:54:05 +0000 | [diff] [blame] | 691 | count=pread(matrix_info->file,buffer+i,(size_t) MagickMin(length-i, |
| 692 | (MagickSizeType) SSIZE_MAX),(off_t) (offset+i)); |
| cristy | 106efa1 | 2014-03-09 01:06:05 +0000 | [diff] [blame] | 693 | #endif |
| cristy | c1712b2 | 2014-03-09 14:54:05 +0000 | [diff] [blame] | 694 | if (count <= 0) |
| 695 | { |
| 696 | count=0; |
| 697 | if (errno != EINTR) |
| 698 | break; |
| cristy | 106efa1 | 2014-03-09 01:06:05 +0000 | [diff] [blame] | 699 | } |
| 700 | } |
| cristy | 10c210e | 2014-03-30 23:27:24 +0000 | [diff] [blame] | 701 | #if !defined(MAGICKCORE_HAVE_PREAD) |
| 702 | UnlockSemaphoreInfo(matrix_info->semaphore); |
| 703 | #endif |
| cristy | 106efa1 | 2014-03-09 01:06:05 +0000 | [diff] [blame] | 704 | return(i); |
| 705 | } |
| 706 | |
| 707 | MagickExport MagickBooleanType GetMatrixElement(const MatrixInfo *matrix_info, |
| 708 | const ssize_t x,const ssize_t y,void *value) |
| 709 | { |
| 710 | MagickOffsetType |
| cristy | c1712b2 | 2014-03-09 14:54:05 +0000 | [diff] [blame] | 711 | count, |
| cristy | 106efa1 | 2014-03-09 01:06:05 +0000 | [diff] [blame] | 712 | i; |
| 713 | |
| cristy | 106efa1 | 2014-03-09 01:06:05 +0000 | [diff] [blame] | 714 | assert(matrix_info != (const MatrixInfo *) NULL); |
| cristy | e1c94d9 | 2015-06-28 12:16:33 +0000 | [diff] [blame] | 715 | assert(matrix_info->signature == MagickCoreSignature); |
| cristy | 6cccee4 | 2014-03-23 00:25:22 +0000 | [diff] [blame] | 716 | i=(MagickOffsetType) EdgeY(y,matrix_info->rows)*matrix_info->columns+ |
| 717 | EdgeX(x,matrix_info->columns); |
| cristy | 106efa1 | 2014-03-09 01:06:05 +0000 | [diff] [blame] | 718 | if (matrix_info->type != DiskCache) |
| 719 | { |
| cristy | 7a72951 | 2014-03-09 16:43:07 +0000 | [diff] [blame] | 720 | (void) memcpy(value,(unsigned char *) matrix_info->elements+i* |
| 721 | matrix_info->stride,matrix_info->stride); |
| cristy | 106efa1 | 2014-03-09 01:06:05 +0000 | [diff] [blame] | 722 | return(MagickTrue); |
| 723 | } |
| cristy | c1712b2 | 2014-03-09 14:54:05 +0000 | [diff] [blame] | 724 | count=ReadMatrixElements(matrix_info,i*matrix_info->stride, |
| cristy | 759ba91 | 2014-06-26 11:59:43 +0000 | [diff] [blame] | 725 | matrix_info->stride,(unsigned char *) value); |
| cristy | c1712b2 | 2014-03-09 14:54:05 +0000 | [diff] [blame] | 726 | if (count != (MagickOffsetType) matrix_info->stride) |
| cristy | 106efa1 | 2014-03-09 01:06:05 +0000 | [diff] [blame] | 727 | return(MagickFalse); |
| 728 | return(MagickTrue); |
| 729 | } |
| 730 | |
| 731 | /* |
| 732 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 733 | % % |
| 734 | % % |
| 735 | % % |
| 736 | % G e t M a t r i x R o w s % |
| 737 | % % |
| 738 | % % |
| 739 | % % |
| 740 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 741 | % |
| 742 | % GetMatrixRows() returns the number of rows in the matrix. |
| 743 | % |
| 744 | % The format of the GetMatrixRows method is: |
| 745 | % |
| 746 | % size_t GetMatrixRows(const MatrixInfo *matrix_info) |
| 747 | % |
| 748 | % A description of each parameter follows: |
| 749 | % |
| 750 | % o matrix_info: the matrix. |
| 751 | % |
| 752 | */ |
| 753 | MagickExport size_t GetMatrixRows(const MatrixInfo *matrix_info) |
| 754 | { |
| 755 | assert(matrix_info != (const MatrixInfo *) NULL); |
| cristy | e1c94d9 | 2015-06-28 12:16:33 +0000 | [diff] [blame] | 756 | assert(matrix_info->signature == MagickCoreSignature); |
| cristy | 106efa1 | 2014-03-09 01:06:05 +0000 | [diff] [blame] | 757 | return(matrix_info->rows); |
| 758 | } |
| 759 | |
| 760 | /* |
| 761 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 762 | % % |
| 763 | % % |
| 764 | % % |
| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 765 | % L e a s t S q u a r e s A d d T e r m s % |
| 766 | % % |
| 767 | % % |
| 768 | % % |
| 769 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 770 | % |
| 771 | % LeastSquaresAddTerms() adds one set of terms and associate results to the |
| 772 | % given matrix and vectors for solving using least-squares function fitting. |
| 773 | % |
| 774 | % The format of the AcquireMagickMatrix method is: |
| 775 | % |
| 776 | % void LeastSquaresAddTerms(double **matrix,double **vectors, |
| cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 777 | % const double *terms,const double *results,const size_t rank, |
| 778 | % const size_t number_vectors); |
| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 779 | % |
| 780 | % A description of each parameter follows: |
| 781 | % |
| 782 | % o matrix: the square matrix to add given terms/results to. |
| 783 | % |
| 784 | % o vectors: the result vectors to add terms/results to. |
| 785 | % |
| 786 | % o terms: the pre-calculated terms (without the unknown coefficent |
| cristy | 106efa1 | 2014-03-09 01:06:05 +0000 | [diff] [blame] | 787 | % weights) that forms the equation being added. |
| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 788 | % |
| 789 | % o results: the result(s) that should be generated from the given terms |
| cristy | 106efa1 | 2014-03-09 01:06:05 +0000 | [diff] [blame] | 790 | % weighted by the yet-to-be-solved coefficents. |
| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 791 | % |
| cristy | 106efa1 | 2014-03-09 01:06:05 +0000 | [diff] [blame] | 792 | % o rank: the rank or size of the dimensions of the square matrix. |
| 793 | % Also the length of vectors, and number of terms being added. |
| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 794 | % |
| cristy | 1ad491d | 2010-05-17 19:45:27 +0000 | [diff] [blame] | 795 | % o number_vectors: Number of result vectors, and number or results being |
| 796 | % added. Also represents the number of separable systems of equations |
| 797 | % that is being solved. |
| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 798 | % |
| 799 | % Example of use... |
| 800 | % |
| glennrp | 2489f53 | 2011-06-25 03:02:43 +0000 | [diff] [blame] | 801 | % 2 dimensional Affine Equations (which are separable) |
| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 802 | % c0*x + c2*y + c4*1 => u |
| 803 | % c1*x + c3*y + c5*1 => v |
| 804 | % |
| 805 | % double **matrix = AcquireMagickMatrix(3UL,3UL); |
| 806 | % double **vectors = AcquireMagickMatrix(2UL,3UL); |
| 807 | % double terms[3], results[2]; |
| 808 | % ... |
| 809 | % for each given x,y -> u,v |
| 810 | % terms[0] = x; |
| 811 | % terms[1] = y; |
| 812 | % terms[2] = 1; |
| 813 | % results[0] = u; |
| 814 | % results[1] = v; |
| 815 | % LeastSquaresAddTerms(matrix,vectors,terms,results,3UL,2UL); |
| 816 | % ... |
| 817 | % if ( GaussJordanElimination(matrix,vectors,3UL,2UL) ) { |
| 818 | % c0 = vectors[0][0]; |
| cristy | 106efa1 | 2014-03-09 01:06:05 +0000 | [diff] [blame] | 819 | % c2 = vectors[0][1]; |
| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 820 | % c4 = vectors[0][2]; |
| 821 | % c1 = vectors[1][0]; |
| cristy | 106efa1 | 2014-03-09 01:06:05 +0000 | [diff] [blame] | 822 | % c3 = vectors[1][1]; |
| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 823 | % c5 = vectors[1][2]; |
| 824 | % } |
| 825 | % else |
| 826 | % printf("Matrix unsolvable\n); |
| 827 | % RelinquishMagickMatrix(matrix,3UL); |
| 828 | % RelinquishMagickMatrix(vectors,2UL); |
| 829 | % |
| 830 | */ |
| cristy | 106efa1 | 2014-03-09 01:06:05 +0000 | [diff] [blame] | 831 | MagickExport void LeastSquaresAddTerms(double **matrix,double **vectors, |
| cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 832 | const double *terms,const double *results,const size_t rank, |
| 833 | const size_t number_vectors) |
| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 834 | { |
| cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 835 | register ssize_t |
| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 836 | i, |
| 837 | j; |
| 838 | |
| cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 839 | for (j=0; j < (ssize_t) rank; j++) |
| cristy | 74908cf | 2010-05-17 19:43:54 +0000 | [diff] [blame] | 840 | { |
| cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 841 | for (i=0; i < (ssize_t) rank; i++) |
| cristy | 74908cf | 2010-05-17 19:43:54 +0000 | [diff] [blame] | 842 | matrix[i][j]+=terms[i]*terms[j]; |
| cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 843 | for (i=0; i < (ssize_t) number_vectors; i++) |
| cristy | 74908cf | 2010-05-17 19:43:54 +0000 | [diff] [blame] | 844 | vectors[i][j]+=results[i]*terms[j]; |
| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 845 | } |
| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 846 | } |
| 847 | |
| 848 | /* |
| 849 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 850 | % % |
| 851 | % % |
| 852 | % % |
| cristy | f3b58c5 | 2014-04-22 01:27:24 +0000 | [diff] [blame] | 853 | % M a t r i x T o I m a g e % |
| 854 | % % |
| 855 | % % |
| 856 | % % |
| 857 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 858 | % |
| cristy | 0f09a8c | 2014-04-23 00:20:40 +0000 | [diff] [blame] | 859 | % MatrixToImage() returns a matrix as an image. The matrix elements must be |
| 860 | % of type double otherwise nonsense is returned. |
| cristy | f3b58c5 | 2014-04-22 01:27:24 +0000 | [diff] [blame] | 861 | % |
| 862 | % The format of the MatrixToImage method is: |
| 863 | % |
| 864 | % Image *MatrixToImage(const MatrixInfo *matrix_info, |
| 865 | % ExceptionInfo *exception) |
| 866 | % |
| 867 | % A description of each parameter follows: |
| 868 | % |
| 869 | % o matrix_info: the matrix. |
| 870 | % |
| 871 | % o exception: return any errors or warnings in this structure. |
| 872 | % |
| 873 | */ |
| 874 | MagickExport Image *MatrixToImage(const MatrixInfo *matrix_info, |
| 875 | ExceptionInfo *exception) |
| 876 | { |
| cristy | 0f09a8c | 2014-04-23 00:20:40 +0000 | [diff] [blame] | 877 | CacheView |
| 878 | *image_view; |
| 879 | |
| 880 | double |
| 881 | max_value, |
| 882 | min_value, |
| 883 | scale_factor, |
| 884 | value; |
| 885 | |
| 886 | Image |
| 887 | *image; |
| 888 | |
| 889 | MagickBooleanType |
| 890 | status; |
| 891 | |
| 892 | ssize_t |
| 893 | y; |
| 894 | |
| 895 | assert(matrix_info != (const MatrixInfo *) NULL); |
| cristy | e1c94d9 | 2015-06-28 12:16:33 +0000 | [diff] [blame] | 896 | assert(matrix_info->signature == MagickCoreSignature); |
| cristy | 0f09a8c | 2014-04-23 00:20:40 +0000 | [diff] [blame] | 897 | assert(exception != (ExceptionInfo *) NULL); |
| cristy | e1c94d9 | 2015-06-28 12:16:33 +0000 | [diff] [blame] | 898 | assert(exception->signature == MagickCoreSignature); |
| cristy | 0f09a8c | 2014-04-23 00:20:40 +0000 | [diff] [blame] | 899 | if (matrix_info->stride < sizeof(double)) |
| 900 | return((Image *) NULL); |
| 901 | /* |
| 902 | Determine range of matrix. |
| 903 | */ |
| 904 | (void) GetMatrixElement(matrix_info,0,0,&value); |
| 905 | min_value=value; |
| 906 | max_value=value; |
| 907 | for (y=0; y < (ssize_t) matrix_info->rows; y++) |
| 908 | { |
| 909 | register ssize_t |
| 910 | x; |
| 911 | |
| 912 | for (x=0; x < (ssize_t) matrix_info->columns; x++) |
| 913 | { |
| 914 | if (GetMatrixElement(matrix_info,x,y,&value) == MagickFalse) |
| 915 | continue; |
| 916 | if (value < min_value) |
| 917 | min_value=value; |
| 918 | else |
| 919 | if (value > max_value) |
| 920 | max_value=value; |
| 921 | } |
| 922 | } |
| 923 | if ((min_value == 0.0) && (max_value == 0.0)) |
| 924 | scale_factor=0; |
| 925 | else |
| 926 | if (min_value == max_value) |
| 927 | { |
| 928 | scale_factor=(double) QuantumRange/min_value; |
| 929 | min_value=0; |
| 930 | } |
| 931 | else |
| 932 | scale_factor=(double) QuantumRange/(max_value-min_value); |
| 933 | /* |
| 934 | Convert matrix to image. |
| 935 | */ |
| 936 | image=AcquireImage((ImageInfo *) NULL,exception); |
| 937 | image->columns=matrix_info->columns; |
| 938 | image->rows=matrix_info->rows; |
| 939 | image->colorspace=GRAYColorspace; |
| 940 | status=MagickTrue; |
| 941 | image_view=AcquireAuthenticCacheView(image,exception); |
| 942 | #if defined(MAGICKCORE_OPENMP_SUPPORT) |
| 943 | #pragma omp parallel for schedule(static,4) shared(status) \ |
| 944 | magick_threads(image,image,image->rows,1) |
| 945 | #endif |
| 946 | for (y=0; y < (ssize_t) image->rows; y++) |
| 947 | { |
| 948 | double |
| 949 | value; |
| 950 | |
| 951 | register Quantum |
| 952 | *q; |
| 953 | |
| 954 | register ssize_t |
| 955 | x; |
| 956 | |
| 957 | if (status == MagickFalse) |
| 958 | continue; |
| 959 | q=QueueCacheViewAuthenticPixels(image_view,0,y,image->columns,1,exception); |
| 960 | if (q == (Quantum *) NULL) |
| 961 | { |
| 962 | status=MagickFalse; |
| 963 | continue; |
| 964 | } |
| 965 | for (x=0; x < (ssize_t) image->columns; x++) |
| 966 | { |
| 967 | if (GetMatrixElement(matrix_info,x,y,&value) == MagickFalse) |
| 968 | continue; |
| 969 | value=scale_factor*(value-min_value); |
| 970 | *q=ClampToQuantum(value); |
| 971 | q+=GetPixelChannels(image); |
| 972 | } |
| 973 | if (SyncCacheViewAuthenticPixels(image_view,exception) == MagickFalse) |
| 974 | status=MagickFalse; |
| 975 | } |
| 976 | image_view=DestroyCacheView(image_view); |
| 977 | if (status == MagickFalse) |
| 978 | image=DestroyImage(image); |
| 979 | return(image); |
| cristy | f3b58c5 | 2014-04-22 01:27:24 +0000 | [diff] [blame] | 980 | } |
| 981 | |
| 982 | /* |
| 983 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 984 | % % |
| 985 | % % |
| 986 | % % |
| cristy | c1712b2 | 2014-03-09 14:54:05 +0000 | [diff] [blame] | 987 | % N u l l M a t r i x % |
| 988 | % % |
| 989 | % % |
| 990 | % % |
| 991 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 992 | % |
| 993 | % NullMatrix() sets all elements of the matrix to zero. |
| 994 | % |
| 995 | % The format of the ResetMagickMemory method is: |
| 996 | % |
| 997 | % MagickBooleanType *NullMatrix(MatrixInfo *matrix_info) |
| 998 | % |
| 999 | % A description of each parameter follows: |
| 1000 | % |
| 1001 | % o matrix_info: the matrix. |
| 1002 | % |
| 1003 | */ |
| 1004 | MagickExport MagickBooleanType NullMatrix(MatrixInfo *matrix_info) |
| 1005 | { |
| 1006 | register ssize_t |
| 1007 | x; |
| 1008 | |
| 1009 | ssize_t |
| 1010 | count, |
| 1011 | y; |
| 1012 | |
| 1013 | unsigned char |
| 1014 | value; |
| 1015 | |
| 1016 | assert(matrix_info != (const MatrixInfo *) NULL); |
| cristy | e1c94d9 | 2015-06-28 12:16:33 +0000 | [diff] [blame] | 1017 | assert(matrix_info->signature == MagickCoreSignature); |
| cristy | c1712b2 | 2014-03-09 14:54:05 +0000 | [diff] [blame] | 1018 | if (matrix_info->type != DiskCache) |
| 1019 | { |
| 1020 | (void) ResetMagickMemory(matrix_info->elements,0,(size_t) |
| 1021 | matrix_info->length); |
| 1022 | return(MagickTrue); |
| 1023 | } |
| 1024 | value=0; |
| 1025 | (void) lseek(matrix_info->file,0,SEEK_SET); |
| 1026 | for (y=0; y < (ssize_t) matrix_info->rows; y++) |
| 1027 | { |
| 1028 | for (x=0; x < (ssize_t) matrix_info->length; x++) |
| 1029 | { |
| 1030 | count=write(matrix_info->file,&value,sizeof(value)); |
| 1031 | if (count != (ssize_t) sizeof(value)) |
| 1032 | break; |
| 1033 | } |
| 1034 | if (x < (ssize_t) matrix_info->length) |
| 1035 | break; |
| 1036 | } |
| 1037 | return(y < (ssize_t) matrix_info->rows ? MagickFalse : MagickTrue); |
| 1038 | } |
| 1039 | |
| 1040 | /* |
| 1041 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 1042 | % % |
| 1043 | % % |
| 1044 | % % |
| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1045 | % R e l i n q u i s h M a g i c k M a t r i x % |
| 1046 | % % |
| 1047 | % % |
| 1048 | % % |
| 1049 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 1050 | % |
| 1051 | % RelinquishMagickMatrix() frees the previously acquired matrix (array of |
| 1052 | % pointers to arrays of doubles). |
| 1053 | % |
| 1054 | % The format of the RelinquishMagickMatrix method is: |
| 1055 | % |
| 1056 | % double **RelinquishMagickMatrix(double **matrix, |
| cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 1057 | % const size_t number_rows) |
| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1058 | % |
| 1059 | % A description of each parameter follows: |
| 1060 | % |
| 1061 | % o matrix: the matrix to relinquish |
| 1062 | % |
| cristy | 1ad491d | 2010-05-17 19:45:27 +0000 | [diff] [blame] | 1063 | % o number_rows: the first dimension of the acquired matrix (number of |
| 1064 | % pointers) |
| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1065 | % |
| 1066 | */ |
| 1067 | MagickExport double **RelinquishMagickMatrix(double **matrix, |
| cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 1068 | const size_t number_rows) |
| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1069 | { |
| cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 1070 | register ssize_t |
| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1071 | i; |
| 1072 | |
| 1073 | if (matrix == (double **) NULL ) |
| 1074 | return(matrix); |
| cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 1075 | for (i=0; i < (ssize_t) number_rows; i++) |
| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1076 | matrix[i]=(double *) RelinquishMagickMemory(matrix[i]); |
| 1077 | matrix=(double **) RelinquishMagickMemory(matrix); |
| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1078 | return(matrix); |
| 1079 | } |
| cristy | 106efa1 | 2014-03-09 01:06:05 +0000 | [diff] [blame] | 1080 | |
| 1081 | /* |
| 1082 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 1083 | % % |
| 1084 | % % |
| 1085 | % % |
| cristy | 106efa1 | 2014-03-09 01:06:05 +0000 | [diff] [blame] | 1086 | % S e t M a t r i x E l e m e n t % |
| 1087 | % % |
| 1088 | % % |
| 1089 | % % |
| 1090 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 1091 | % |
| 1092 | % SetMatrixElement() sets the specifed element in the matrix. |
| 1093 | % |
| 1094 | % The format of the SetMatrixElement method is: |
| 1095 | % |
| 1096 | % MagickBooleanType SetMatrixElement(const MatrixInfo *matrix_info, |
| 1097 | % const ssize_t x,const ssize_t y,void *value) |
| 1098 | % |
| 1099 | % A description of each parameter follows: |
| 1100 | % |
| 1101 | % o matrix_info: the matrix columns. |
| 1102 | % |
| 1103 | % o x: the matrix x-offset. |
| 1104 | % |
| 1105 | % o y: the matrix y-offset. |
| 1106 | % |
| 1107 | % o value: set the matrix element to this value. |
| 1108 | % |
| 1109 | */ |
| 1110 | |
| cristy | 106efa1 | 2014-03-09 01:06:05 +0000 | [diff] [blame] | 1111 | MagickExport MagickBooleanType SetMatrixElement(const MatrixInfo *matrix_info, |
| 1112 | const ssize_t x,const ssize_t y,const void *value) |
| 1113 | { |
| 1114 | MagickOffsetType |
| cristy | c1712b2 | 2014-03-09 14:54:05 +0000 | [diff] [blame] | 1115 | count, |
| cristy | 106efa1 | 2014-03-09 01:06:05 +0000 | [diff] [blame] | 1116 | i; |
| 1117 | |
| cristy | 106efa1 | 2014-03-09 01:06:05 +0000 | [diff] [blame] | 1118 | assert(matrix_info != (const MatrixInfo *) NULL); |
| cristy | e1c94d9 | 2015-06-28 12:16:33 +0000 | [diff] [blame] | 1119 | assert(matrix_info->signature == MagickCoreSignature); |
| cristy | 6cccee4 | 2014-03-23 00:25:22 +0000 | [diff] [blame] | 1120 | i=(MagickOffsetType) y*matrix_info->columns+x; |
| cristy | 106efa1 | 2014-03-09 01:06:05 +0000 | [diff] [blame] | 1121 | if ((i < 0) || |
| 1122 | ((MagickSizeType) (i*matrix_info->stride) >= matrix_info->length)) |
| 1123 | return(MagickFalse); |
| 1124 | if (matrix_info->type != DiskCache) |
| 1125 | { |
| cristy | 7a72951 | 2014-03-09 16:43:07 +0000 | [diff] [blame] | 1126 | (void) memcpy((unsigned char *) matrix_info->elements+i* |
| 1127 | matrix_info->stride,value,matrix_info->stride); |
| cristy | 106efa1 | 2014-03-09 01:06:05 +0000 | [diff] [blame] | 1128 | return(MagickTrue); |
| 1129 | } |
| cristy | c1712b2 | 2014-03-09 14:54:05 +0000 | [diff] [blame] | 1130 | count=WriteMatrixElements(matrix_info,i*matrix_info->stride, |
| cristy | 759ba91 | 2014-06-26 11:59:43 +0000 | [diff] [blame] | 1131 | matrix_info->stride,(unsigned char *) value); |
| cristy | c1712b2 | 2014-03-09 14:54:05 +0000 | [diff] [blame] | 1132 | if (count != (MagickOffsetType) matrix_info->stride) |
| cristy | 106efa1 | 2014-03-09 01:06:05 +0000 | [diff] [blame] | 1133 | return(MagickFalse); |
| 1134 | return(MagickTrue); |
| 1135 | } |