Main Page | Modules | Alphabetical List | Data Structures | File List | Data Fields | Globals

imaallo.c

Go to the documentation of this file.
00001 /************************************************************************* 00002 * $Id: imaallo.c,v 1.1 2005/09/09 08:22:44 bellet Exp $ 00003 ************************************************************************** 00004 This software is governed by the CeCILL license under French law and 00005 abiding by the rules of distribution of free software. You can use, 00006 modify and/ or redistribute the software under the terms of the CeCILL 00007 license as circulated by CEA, CNRS and INRIA at the following URL 00008 "http://www.cecill.info". 00009 00010 As a counterpart to the access to the source code and rights to copy, 00011 modify and redistribute granted by the license, users are provided only 00012 with a limited warranty and the software's author, the holder of the 00013 economic rights, and the successive licensors have only limited 00014 liability. 00015 00016 In this respect, the user's attention is drawn to the risks associated 00017 with loading, using, modifying and/or developing or reproducing the 00018 software by the user in light of its specific status of free software, 00019 that may mean that it is complicated to manipulate, and that also 00020 therefore means that it is reserved for developers and experienced 00021 professionals having in-depth computer knowledge. Users are therefore 00022 encouraged to load and test the software's suitability as regards their 00023 requirements in conditions enabling the security of their systems and/or 00024 data to be ensured and, more generally, to use and operate it in the 00025 same conditions as regards security. 00026 00027 The fact that you are presently reading this means that you have had 00028 knowledge of the CeCILL license and that you accept its terms. 00029 00030 Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de 00031 l'Image). All rights reserved. See License.txt for details. 00032 00033 Version 1.0 05/09/2005 00034 *************************************************************************/ 00035 00036 #include "idima.h" 00037 #include "idima-private.h" 00038 #include "iderr.h" 00039 #include "idprint.h" 00040 #include <stdlib.h> 00041 00042 void _IdFreeLinesOfPlane(void **pi, int n); 00043 00044 00045 /************************************************************************* 00046 * 00047 * Description : Dynamic allocatio/free of IMAGE object 00048 * 00049 **************************************************************************/ 00050 00051 void _IdFreePlanesOfBloc(void ***, int, int); 00052 00053 void _IdFreeLinesOfPlane(void **pi, int n) 00054 { 00055 #ifdef _TURBOC_ 00056 int i; 00057 for (i = 0; i < n; i++) 00058 if (pi[i]) { 00059 free(pi[i]); 00060 pi[i] = 0; 00061 } 00062 #else 00063 if (pi[0]) { 00064 free(pi[0]); 00065 pi[0] = 0; 00066 } 00067 #endif 00068 } 00069 00070 int _IdAllocLinesOfPlane(void *piv, int sx, int sy, int si) 00071 { 00072 00073 char **pi = (char **) piv; 00074 int i = 0; 00075 00076 #ifdef _TURBOC_ 00077 for (i = 0; i < sy; i++) { 00078 if ((pi[i] = (char *) calloc(1, sx * si)) == 0) { 00079 _IdFreeLinesOfPlane((void **) pi, sy); 00080 return 0; 00081 } 00082 } 00083 00084 #else 00085 /* 00086 * autres compilateurs sauf TURBOC ni _MSC_VER 00087 */ 00088 if ((pi[0] = (char *) calloc(1, sx * sy * si))) 00089 for (i = 1; i < sy; i++) 00090 pi[i] = pi[0] + sx * si * i; 00091 else { 00092 IdErrPrintf("EchecAlloc ligne %d (lgr %d : %d*%d*%d).", i, 00093 sx * sy * si, sx, sy, si); 00094 return 0; 00095 } 00096 00097 #endif 00098 return 1; 00099 } 00100 00101 void **_IdAllocPlan(int sx, int sy, int si) 00102 { 00103 char **pi; 00104 00105 pi = (char **) calloc(sy, sizeof(void *)); 00106 if (pi) { 00107 if (!_IdAllocLinesOfPlane(pi, sx, sy, si)) { 00108 IdErrPrintf 00109 ("Echec _IdAllocLinesOfPlane. Memoire saturee."); 00110 free(pi); 00111 pi = (char **) 0; 00112 } 00113 } 00114 return ((void **) pi); 00115 } 00116 00117 void _IdFreePlan(void **pi, int n) 00118 { 00119 if (pi) { 00120 _IdFreeLinesOfPlane(pi, n); 00121 free(pi); 00122 } 00123 } 00124 00125 // Special SEQUENCES 00126 static int _IdAllocPlanesOfBloc(void *piv, int sx, int sy, int sz, int si) 00127 { 00128 00129 char ***pi = (char ***) piv; 00130 int i; 00131 for (i = 0; i < sz; i++) { 00132 if (0 == (pi[i] = (char **) _IdAllocPlan(sx, sy, si))) { 00133 IdErrPrintf 00134 ("Echec Alloc Plan %d (sx %d sy %d si %d).", i, 00135 sx, sy, si); 00136 _IdFreePlanesOfBloc((void ***) pi, sz, sy); 00137 return 0; 00138 } 00139 } 00140 return 1; 00141 } 00142 00143 void _IdFreePlanesOfBloc(void ***pi, int nbp, int nbl) 00144 { 00145 int i; 00146 for (i = 0; i < nbp; i++) 00147 if (pi[i]) { 00148 _IdFreeLinesOfPlane(pi[i], nbl); 00149 pi[i] = 0; 00150 } 00151 } 00152 00153 00154 void ***_IdAllocBloc(int sx, int sy, int sz, int si) 00155 { 00156 char ***pi; 00157 00158 pi = (char ***) calloc(sz, sizeof(void **)); 00159 if (pi) { 00160 if (!_IdAllocPlanesOfBloc(pi, sx, sy, sz, si)) { 00161 IdErrPrintf 00162 ("Echec Alloc dans _IdAllocPlanesOfBloc (sx %d sy %d sz %d si %d", 00163 sx, sy, sz, si); 00164 free(pi); 00165 pi = (char ***) 0; 00166 } 00167 00168 } else 00169 IdErrPrintf("Echec Alloc tabPointeurs pour Bloc"); 00170 00171 return ((void ***) pi); 00172 } 00173 00174 00175 void _IdFreeBloc(void ***pi, int nbp, int nbl) 00176 { 00177 if (pi) { 00178 _IdFreePlanesOfBloc(pi, nbp, nbl); 00179 free(pi); 00180 } 00181 } 00182 00188 void _IdImaFree(PPIMAGE * pi) 00189 { 00190 if (*pi) { 00191 if (_IdImaPrivate(*pi)->subObject == 0) 00192 /* 00193 * On ne libere pas les lignes si sous-objet 00194 */ 00195 //_IdFreeLinesOfPlane(*pi, IdImaDimY(*pi)); 00196 free((*pi)[0]); // devrait aller + vite 00197 // revoir l'utilite de _IdFreeLinesOfPlane 00198 00199 if (_IdImaPrivate(*pi)->_message) 00200 free((_IdImaPrivate(*pi)->_message)); 00201 _IdImaPrivate(*pi)->_message = 0; 00202 if (_IdImaPrivate(*pi)->_fichier) 00203 free((_IdImaPrivate(*pi)->_fichier)); 00204 _IdImaPrivate(*pi)->_fichier = 0; 00205 free(_IdImaPrivate(*pi)); 00206 *pi = 0; 00207 } 00208 } 00209 00221 PPIMAGE IdImaAlloc(int sx, // Number of columns (width) 00222 int sy, // Number of lignes (height) 00223 int ty) 00224 { 00225 PRIVATE_IMAGE *si; 00226 PPIMAGE pi = NULL; 00227 if (!(ty & IDO_TYPE) == IMA) { 00228 IdErrPrintf 00229 ("Allocation impossible. Objet de type incompatible(%x)\n", 00230 ty); 00231 IdErrno = IDERR_WRONG_TYPE; 00232 return (PPIMAGE) 0; 00233 } 00234 si = 00235 (PRIVATE_IMAGE *) calloc(1, sizeof(PRIVATE_IMAGE) + 00236 sy * sizeof(void *)); 00237 if (si) { 00238 si->DimX = sx; 00239 si->DimY = sy; 00240 si->Type = ty; 00241 si->subObject = 0; 00242 si->UsedNbX = 0; 00243 si->UsedNbY = 0; 00244 si->_fichier = 0; 00245 si->_message = 0; 00246 pi = (PPIMAGE) & (si[1]); 00247 if (ty == IMA_BIT) { 00248 sx = (sx + 7) >> 3; 00249 ty = IMA_UCHAR; 00250 } 00251 if (!_IdAllocLinesOfPlane(pi, sx, sy, IdSizeOfType(pi))) { 00252 IdImaFree(pi); 00253 IdErrPrintf 00254 ("Echec d'allocation d'image. Memoire saturee."); 00255 IdErrno = IDERR_ALLOC_MEM; 00256 return (PPIMAGE) 0; 00257 } 00258 } else { 00259 IdErrPrintf 00260 ("Echec d'allocation PRIVATE_IMAGE. Memoire saturee."); 00261 } 00262 return (pi); 00263 } 00264 00275 PPIMAGE IdImaClone(PPIMAGE sim) 00276 { 00277 return IdImaAllocLikeImage(sim); 00278 } 00279 00290 PPIMAGE IdImaAllocLikeImage (void * sim) 00291 { 00292 if ( !sim ) { 00293 IdErrPrintf ("IdImaAllocLikeImage : can't clone NULL."); 00294 return (PPIMAGE)0; 00295 } 00296 return IdImaAlloc(IdImaDimX(sim), IdImaDimY(sim), IdImaType(sim)); 00297 }

Generated on Wed Oct 19 09:28:33 2005 for SIMRI3D by doxygen 1.3.7