Blender V2.61 - r43446
|
00001 /* 00002 * ***** BEGIN GPL LICENSE BLOCK ***** 00003 * 00004 * This program is free software; you can redistribute it and/or 00005 * modify it under the terms of the GNU General Public License 00006 * as published by the Free Software Foundation; either version 2 00007 * of the License, or (at your option) any later version. 00008 * 00009 * This program is distributed in the hope that it will be useful, 00010 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00011 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00012 * GNU General Public License for more details. 00013 * 00014 * You should have received a copy of the GNU General Public License 00015 * along with this program; if not, write to the Free Software Foundation, 00016 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 00017 * 00018 * The Original Code is Copyright (C) 2005 Blender Foundation 00019 * All rights reserved. 00020 * 00021 * The Original Code is: all of this file. 00022 * 00023 * Contributor(s): Austin Benesh. Ton Roosendaal. 00024 * 00025 * ***** END GPL LICENSE BLOCK ***** 00026 */ 00027 00033 #include <stdlib.h> 00034 #include <string.h> 00035 00036 #include "BLI_blenlib.h" 00037 #include "MEM_guardedalloc.h" 00038 00039 #include "IMB_imbuf_types.h" 00040 #include "IMB_imbuf.h" 00041 00042 #include "IMB_metadata.h" 00043 00044 00045 00046 void IMB_metadata_free(struct ImBuf* img) 00047 { 00048 ImMetaData *info; 00049 00050 if (!img) 00051 return; 00052 if (!img->metadata) { 00053 return; 00054 } 00055 info = img->metadata; 00056 while (info) { 00057 ImMetaData* next = info->next; 00058 MEM_freeN(info->key); 00059 MEM_freeN(info->value); 00060 MEM_freeN(info); 00061 info = next; 00062 } 00063 } 00064 00065 int IMB_metadata_get_field(struct ImBuf* img, const char* key, char* field, int len) 00066 { 00067 ImMetaData *info; 00068 int retval = 0; 00069 00070 if (!img) 00071 return 0; 00072 if (!img->metadata) { 00073 return 0; 00074 } 00075 info = img->metadata; 00076 while (info) { 00077 if (strcmp(key, info->key) == 0) { 00078 BLI_strncpy(field, info->value, len); 00079 retval = 1; 00080 break; 00081 } 00082 info = info->next; 00083 } 00084 return retval; 00085 } 00086 00087 int IMB_metadata_add_field(struct ImBuf* img, const char* key, const char* field) 00088 { 00089 ImMetaData *info; 00090 ImMetaData *last; 00091 00092 if (!img) 00093 return 0; 00094 00095 if (!img->metadata) { 00096 img->metadata = MEM_callocN(sizeof(ImMetaData), "ImMetaData"); 00097 info = img->metadata; 00098 } else { 00099 info = img->metadata; 00100 last = info; 00101 while (info) { 00102 last = info; 00103 info = info->next; 00104 } 00105 info = MEM_callocN(sizeof(ImMetaData), "ImMetaData"); 00106 last->next = info; 00107 } 00108 info->key = BLI_strdup(key); 00109 info->value = BLI_strdup(field); 00110 return 1; 00111 } 00112 00113 int IMB_metadata_del_field(struct ImBuf *img, const char *key) 00114 { 00115 ImMetaData *p, *p1; 00116 00117 if ((!img) || (!img->metadata)) 00118 return (0); 00119 00120 p = img->metadata; 00121 p1 = NULL; 00122 while (p) { 00123 if (!strcmp (key, p->key)) { 00124 if (p1) 00125 p1->next = p->next; 00126 else 00127 img->metadata = p->next; 00128 00129 MEM_freeN(p->key); 00130 MEM_freeN(p->value); 00131 MEM_freeN(p); 00132 return (1); 00133 } 00134 p1 = p; 00135 p = p->next; 00136 } 00137 return (0); 00138 } 00139 00140 int IMB_metadata_change_field(struct ImBuf *img, const char *key, const char *field) 00141 { 00142 ImMetaData *p; 00143 00144 if (!img) 00145 return (0); 00146 00147 if (!img->metadata) 00148 return (IMB_metadata_add_field (img, key, field)); 00149 00150 p = img->metadata; 00151 while (p) { 00152 if (!strcmp (key, p->key)) { 00153 MEM_freeN (p->value); 00154 p->value = BLI_strdup (field); 00155 return (1); 00156 } 00157 p = p->next; 00158 } 00159 00160 return (IMB_metadata_add_field (img, key, field)); 00161 } 00162