mnote-pentax-entry.c

Go to the documentation of this file.
00001 /* mnote-pentax-entry.c
00002  *
00003  * Copyright © 2002 Lutz Müller <lutz@users.sourceforge.net>
00004  *
00005  * This library is free software; you can redistribute it and/or
00006  * modify it under the terms of the GNU Lesser General Public
00007  * License as published by the Free Software Foundation; either
00008  * version 2 of the License, or (at your option) any later version.
00009  *
00010  * This library is distributed in the hope that it will be useful, 
00011  * but WITHOUT ANY WARRANTY; without even the implied warranty of 
00012  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00013  * Lesser General Public License for more details. 
00014  *
00015  * You should have received a copy of the GNU Lesser General Public
00016  * License along with this library; if not, write to the
00017  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
00018  * Boston, MA 02111-1307, USA.
00019  */
00020 
00021 #include <config.h>
00022 #include "mnote-pentax-entry.h"
00023 
00024 #include <libexif/i18n.h>
00025 
00026 #include <stdio.h>
00027 #include <stdlib.h>
00028 #include <string.h>
00029 
00030 #include <libexif/exif-format.h>
00031 #include <libexif/exif-utils.h>
00032 #include <libexif/exif-entry.h>
00033 
00034 
00035 #define CF(format,target,v,maxlen)                              \
00036 {                                                               \
00037         if (format != target) {                                 \
00038                 snprintf (v, maxlen,                            \
00039                         _("Invalid format '%s', "               \
00040                         "expected '%s'."),                      \
00041                         exif_format_get_name (format),          \
00042                         exif_format_get_name (target));         \
00043                 break;                                          \
00044         }                                                       \
00045 }
00046 
00047 #define CC(number,target,v,maxlen)                                      \
00048 {                                                                       \
00049         if (number != target) {                                         \
00050                 snprintf (v, maxlen,                                    \
00051                         _("Invalid number of components (%i, "          \
00052                         "expected %i)."), (int) number, (int) target);  \
00053                 break;                                                  \
00054         }                                                               \
00055 }
00056 
00057 static struct {
00058         ExifTag tag;
00059         struct {
00060                 int index;
00061                 const char *string;
00062         } elem[7];
00063 } items[] = {
00064   { MNOTE_PENTAX_TAG_MODE,
00065     { {0, N_("Auto")},
00066       {1, N_("Night-scene")},
00067       {2, N_("Manual")},
00068       {0, NULL}}},
00069   { MNOTE_PENTAX_TAG_QUALITY,
00070     { {0, N_("Good")},
00071       {1, N_("Better")},
00072       {2, N_("Best")},{0,NULL}}},
00073   { MNOTE_PENTAX_TAG_FOCUS,
00074     { {2, N_("Custom")},
00075       {3, N_("Auto")},
00076       {0, NULL}}},
00077   { MNOTE_PENTAX_TAG_FLASH,
00078     { {1, N_("Auto")},
00079       {2, N_("Flash on")},
00080       {4, N_("Flash off")},
00081       {6, N_("Red-eye Reduction")},
00082       {0, NULL}}},
00083   { MNOTE_PENTAX_TAG_WHITE_BALANCE,
00084     { {0, N_("Auto")},
00085       {1, N_("Daylight")},
00086       {2, N_("Shade")},
00087       {3, N_("Tungsten")},
00088       {4, N_("Fluorescent")},
00089       {5, N_("Manual")},
00090       {0, NULL}}},
00091   { MNOTE_PENTAX_TAG_SHARPNESS,
00092     { {0, N_("Normal")},
00093       {1, N_("Soft")},
00094       {2, N_("Hard")},
00095       {0, NULL}}},
00096   { MNOTE_PENTAX_TAG_CONTRAST,
00097     { {0, N_("Normal")},
00098       {1, N_("Low")},
00099       {2, N_("High")},
00100       {0, NULL}}},
00101   { MNOTE_PENTAX_TAG_SATURATION,
00102     { {0, N_("Normal")},
00103       {1, N_("Low")},
00104       {2, N_("High")},
00105       {0, NULL}}},
00106   { MNOTE_PENTAX_TAG_ISO_SPEED,
00107     { {10,  N_("100")},
00108       {16,  N_("200")},
00109       {100, N_("100")},
00110       {200, N_("200")},
00111       { 0,  NULL}}},
00112   { MNOTE_PENTAX_TAG_COLOR,
00113     { {1, N_("Full")},
00114       {2, N_("Black & White")},
00115       {3, N_("Sepia")},
00116       {0, NULL}}},
00117 };
00118 
00119 char *
00120 mnote_pentax_entry_get_value (MnotePentaxEntry *entry,
00121                               char *val, unsigned int maxlen)
00122 {
00123         ExifLong vl;
00124         ExifShort vs;
00125         int i = 0, j = 0;
00126 
00127         if (!entry) return (NULL);
00128 
00129         memset (val, 0, maxlen);
00130         maxlen--;
00131 
00132         switch (entry->tag) {
00133           case MNOTE_PENTAX_TAG_MODE:
00134           case MNOTE_PENTAX_TAG_QUALITY:
00135           case MNOTE_PENTAX_TAG_FOCUS:
00136           case MNOTE_PENTAX_TAG_FLASH:
00137           case MNOTE_PENTAX_TAG_WHITE_BALANCE:
00138           case MNOTE_PENTAX_TAG_SHARPNESS:
00139           case MNOTE_PENTAX_TAG_CONTRAST:
00140           case MNOTE_PENTAX_TAG_SATURATION:
00141           case MNOTE_PENTAX_TAG_ISO_SPEED:
00142           case MNOTE_PENTAX_TAG_COLOR:
00143                 CF (entry->format, EXIF_FORMAT_SHORT, val, maxlen);
00144                 CC (entry->components, 1, val, maxlen);
00145                 vs = exif_get_short (entry->data, entry->order);
00146 
00147                 /* search the tag */
00148                 for (i = 0; (items[i].tag && items[i].tag != entry->tag); i++);
00149                 if (!items[i].tag) {
00150                         strncpy (val, "Internal error", maxlen);
00151                         break;
00152                 }
00153 
00154                 /* find the value */
00155                 for (j = 0; items[i].elem[j].string &&
00156                             (items[i].elem[j].index < vs); j++);
00157                 if (items[i].elem[j].index != vs) {
00158                         snprintf (val, maxlen,
00159                                   "Internal error (unknown value %i)", vs);
00160                         break;
00161                 }
00162                 snprintf (val, maxlen, "%s", items[i].elem[j].string);
00163                 break;
00164 
00165         case MNOTE_PENTAX_TAG_ZOOM:
00166                 CF (entry->format, EXIF_FORMAT_LONG, val, maxlen);
00167                 CC (entry->components, 1, val, maxlen);
00168                 vl = exif_get_long (entry->data, entry->order);
00169                 snprintf (val, maxlen, "%li", (long int) vl);
00170                 break;
00171         case MNOTE_PENTAX_TAG_PRINTIM:
00172                 CF (entry->format, EXIF_FORMAT_UNDEFINED, val, maxlen);
00173                 CC (entry->components, 124, val, maxlen);
00174                 snprintf (val, maxlen, "%li bytes unknown data",
00175                           entry->components);
00176                 break;
00177         case MNOTE_PENTAX_TAG_TZ_CITY:
00178                 CF (entry->format, EXIF_FORMAT_UNDEFINED, val, maxlen);
00179                 CC (entry->components, 4, val, maxlen);
00180                 snprintf (val, entry->components, "%s", entry->data);
00181                 break;
00182         case MNOTE_PENTAX_TAG_TZ_DST:
00183                 CF (entry->format, EXIF_FORMAT_UNDEFINED, val, maxlen);
00184                 CC (entry->components, 4, val, maxlen);
00185                 snprintf (val, entry->components, "%s", entry->data);
00186                 break;
00187         default:
00188                 switch (entry->format) {
00189                 case EXIF_FORMAT_ASCII:
00190                   strncpy (val, (char *)entry->data, MIN(maxlen, entry->components));
00191                   break;
00192                 case EXIF_FORMAT_SHORT:
00193                   vs = exif_get_short (entry->data, entry->order);
00194                   snprintf (val, maxlen, "%i", vs);
00195                   break;
00196                 case EXIF_FORMAT_LONG:
00197                   vl = exif_get_long (entry->data, entry->order);
00198                   snprintf (val, maxlen, "%li", (long int) vl);
00199                   break;
00200                 case EXIF_FORMAT_UNDEFINED:
00201                 default:
00202                   snprintf (val, maxlen, "%li bytes unknown data",
00203                             entry->components);
00204                   break;
00205                 }
00206                 break;
00207         }
00208 
00209         return (val);
00210 }

Generated on Tue Dec 19 14:33:54 2006 for EXIF library (libexif) Internals by  doxygen 1.5.1