mnote-fuji-entry.c

Go to the documentation of this file.
00001 /* mnote-fuji-entry.c
00002  *
00003  * Copyright (c) 2002 Lutz Mueller <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., 51 Franklin Street, Fifth Floor,
00018  * Boston, MA  02110-1301  USA.
00019  */
00020 
00021 #include <stdlib.h>
00022 #include <stdio.h>
00023 #include <string.h>
00024 
00025 #include <config.h>
00026 
00027 #include <libexif/i18n.h>
00028 
00029 #include "mnote-fuji-entry.h"
00030 
00031 #define CF(format,target,v,maxlen)                              \
00032 {                                                               \
00033         if (format != target) {                                 \
00034                 snprintf (v, maxlen,                            \
00035                         _("Invalid format '%s', "               \
00036                         "expected '%s'."),                      \
00037                         exif_format_get_name (format),          \
00038                         exif_format_get_name (target));         \
00039                 break;                                          \
00040         }                                                       \
00041 }
00042 
00043 #define CC(number,target,v,maxlen)                                      \
00044 {                                                                       \
00045         if (number != target) {                                         \
00046                 snprintf (v, maxlen,                                    \
00047                         _("Invalid number of components (%i, "          \
00048                         "expected %i)."), (int) number, (int) target);  \
00049                 break;                                                  \
00050         }                                                               \
00051 }
00052 
00053 static const struct {
00054         ExifTag tag;
00055         struct {
00056                 int index;
00057                 const char *string;
00058         } elem[22];
00059 } items[] = {
00060 #ifndef NO_VERBOSE_TAG_DATA
00061   { MNOTE_FUJI_TAG_SHARPNESS,
00062     { {1, N_("Softest")},
00063       {2, N_("Soft")},
00064       {3, N_("Normal")},
00065       {4, N_("Hard")},
00066       {5, N_("Hardest")},
00067       {0x0082, N_("Medium soft")},
00068       {0x0084, N_("Medium hard")},
00069       {0x8000, N_("Film simulation mode")},
00070       {0xFFFF, N_("Off")},
00071       {0, NULL}}},
00072   { MNOTE_FUJI_TAG_WHITE_BALANCE,
00073     { {0, N_("Auto")},
00074       {0x100, N_("Daylight")},
00075       {0x200, N_("Cloudy")},
00076       {0x300, N_("Daylight fluorescent")},
00077       {0x301, N_("Day white fluorescent")},
00078       {0x302, N_("White fluorescent")},
00079       {0x400, N_("Incandescent")},
00080       {0x500, N_("Flash")},
00081       {0xF00, N_("Custom")},
00082       {0, NULL}}},
00083   { MNOTE_FUJI_TAG_COLOR,
00084     { {0, N_("Standard")},
00085       {0x0080, N_("Medium high")},
00086       {0x0100, N_("High")},
00087       {0x0180, N_("Medium low")},
00088       {0x0200, N_("Original")},
00089       {0x0300, N_("Black & white")},
00090       {0x8000, N_("Film simulation mode")},
00091       {0, NULL}}},
00092   { MNOTE_FUJI_TAG_TONE,
00093     { {0, N_("Standard")},
00094       {0x0080, N_("Medium hard")},
00095       {0x0100, N_("Hard")},
00096       {0x0180, N_("Medium soft")},
00097       {0x0200, N_("Original")},
00098       {0x8000, N_("Film simulation mode")},
00099       {0, NULL}}},
00100   { MNOTE_FUJI_TAG_FLASH_MODE,
00101     { {0, N_("Auto")},
00102       {1, N_("On")},
00103       {2, N_("Off")},
00104       {3, N_("Red-eye reduction")},
00105       {0, NULL}}},
00106   { MNOTE_FUJI_TAG_MACRO,
00107     { {0, N_("Off")},
00108       {1, N_("On")},
00109       {0, NULL}}},
00110   { MNOTE_FUJI_TAG_FOCUS_MODE,
00111     { {0, N_("Auto")},
00112       {1, N_("Manual")},
00113       {0, NULL}}},
00114   { MNOTE_FUJI_TAG_SLOW_SYNC,
00115     { {0, N_("Off")},
00116       {1, N_("On")},
00117       {0, NULL}}},
00118   { MNOTE_FUJI_TAG_PICTURE_MODE,
00119     { {0, N_("Auto")},
00120       {1, N_("Portrait")},
00121       {2, N_("Landscape")},
00122       {4, N_("Sports")},
00123       {5, N_("Night")},
00124       {6, N_("Program AE")},
00125       {7, N_("Natural photo")},
00126       {8, N_("Vibration reduction")},
00127       {0x000A, N_("Sunset")},
00128       {0x000B, N_("Museum")},
00129       {0x000C, N_("Party")},
00130       {0x000D, N_("Flower")},
00131       {0x000E, N_("Text")},
00132       {0x000F, N_("NP & flash")},
00133       {0x0010, N_("Beach")},
00134       {0x0011, N_("Snow")},
00135       {0x0012, N_("Fireworks")},
00136       {0x0013, N_("Underwater")},
00137       {0x0100, N_("Aperture priority AE")},
00138       {0x0200, N_("Shutter priority AE")},
00139       {0x0300, N_("Manual exposure")},
00140       {0, NULL}}},
00141   { MNOTE_FUJI_TAG_CONT_TAKING,
00142     { {0, N_("Off")},
00143       {1, N_("On")},
00144       {0, NULL}}},
00145   { MNOTE_FUJI_TAG_FINEPIX_COLOR,
00146     { {0x00, N_("F-Standard")},
00147       {0x10, N_("F-Chrome")},
00148       {0x30, N_("F-B&W")},
00149       {0, NULL}}},
00150   { MNOTE_FUJI_TAG_BLUR_CHECK,
00151     { {0, N_("No blur")},
00152       {1, N_("Blur warning")},
00153       {0, NULL}}},
00154   { MNOTE_FUJI_TAG_FOCUS_CHECK,
00155     { {0, N_("Focus good")},
00156       {1, N_("Out of focus")},
00157       {0, NULL}}},
00158   { MNOTE_FUJI_TAG_AUTO_EXPOSURE_CHECK,
00159     { {0, N_("AE good")},
00160       {1, N_("Over exposed")},
00161       {0, NULL}}},
00162   { MNOTE_FUJI_TAG_DYNAMIC_RANGE,
00163     { {1, N_("Standard")},
00164       {3, N_("Wide")},
00165       {0, NULL}}},
00166   { MNOTE_FUJI_TAG_FILM_MODE,
00167     { {0, N_("F0/Standard")},
00168       {0x0100, N_("F1/Studio portrait")},
00169       {0x0110, N_("F1a/Professional portrait")},
00170       {0x0120, N_("F1b/Professional portrait")},
00171       {0x0130, N_("F1c/Professional portrait")},
00172       {0x0200, N_("F2/Fujichrome")},
00173       {0x0300, N_("F3/Studio portrait Ex")},
00174       {0x0400, N_("F4/Velvia")},
00175       {0, NULL}}},
00176   { MNOTE_FUJI_TAG_DYNAMIC_RANGE_SETTING,
00177     { {0, N_("Auto (100-400%)")},
00178       {1, N_("RAW")},
00179       {0x0100, N_("Standard (100%)")},
00180       {0x0200, N_("Wide1 (230%)")},
00181       {0x0201, N_("Wide2 (400%)")},
00182       {0x8000, N_("Film simulation mode")},
00183       {0, NULL}}},
00184 #endif
00185   {0, {{0, NULL}}}
00186 };
00187 
00188 
00189 char *
00190 mnote_fuji_entry_get_value (MnoteFujiEntry *entry,
00191                               char *val, unsigned int maxlen)
00192 {
00193         ExifLong  vl;
00194         ExifSLong vsl;
00195         ExifShort vs, vs2;
00196         ExifRational vr;
00197         ExifSRational vsr;
00198         int i, j;
00199 
00200         if (!entry) return (NULL);
00201 
00202         memset (val, 0, maxlen);
00203         maxlen--;
00204 
00205         switch (entry->tag) {
00206           case MNOTE_FUJI_TAG_VERSION:
00207                 CF (entry->format, EXIF_FORMAT_UNDEFINED, val, maxlen);
00208                 CC (entry->components, 4, val, maxlen);
00209                 memcpy (val, entry->data, MIN(maxlen, entry->size));
00210                 break;
00211           case MNOTE_FUJI_TAG_SHARPNESS:
00212           case MNOTE_FUJI_TAG_WHITE_BALANCE:
00213           case MNOTE_FUJI_TAG_COLOR:
00214           case MNOTE_FUJI_TAG_TONE:
00215           case MNOTE_FUJI_TAG_FLASH_MODE:
00216           case MNOTE_FUJI_TAG_MACRO:
00217           case MNOTE_FUJI_TAG_FOCUS_MODE:
00218           case MNOTE_FUJI_TAG_SLOW_SYNC:
00219           case MNOTE_FUJI_TAG_PICTURE_MODE:
00220           case MNOTE_FUJI_TAG_CONT_TAKING:
00221           case MNOTE_FUJI_TAG_FINEPIX_COLOR:
00222           case MNOTE_FUJI_TAG_BLUR_CHECK:
00223           case MNOTE_FUJI_TAG_FOCUS_CHECK:
00224           case MNOTE_FUJI_TAG_AUTO_EXPOSURE_CHECK:
00225           case MNOTE_FUJI_TAG_DYNAMIC_RANGE:
00226           case MNOTE_FUJI_TAG_FILM_MODE:
00227           case MNOTE_FUJI_TAG_DYNAMIC_RANGE_SETTING:
00228                 CF (entry->format, EXIF_FORMAT_SHORT, val, maxlen);
00229                 CC (entry->components, 1, val, maxlen);
00230                 vs = exif_get_short (entry->data, entry->order);
00231 
00232                 /* search the tag */
00233                 for (i = 0; (items[i].tag && items[i].tag != entry->tag); i++);
00234                 if (!items[i].tag) {
00235                         snprintf (val, maxlen,
00236                                   _("Internal error (unknown value %i)"), vs);
00237                         break;
00238                 }
00239 
00240                 /* find the value */
00241                 for (j = 0; items[i].elem[j].string &&
00242                     (items[i].elem[j].index < vs); j++);
00243                 if (items[i].elem[j].index != vs) {
00244                         snprintf (val, maxlen,
00245                                   _("Internal error (unknown value %i)"), vs);
00246                         break;
00247                 }
00248                 strncpy (val, _(items[i].elem[j].string), maxlen);
00249                 break;
00250           case MNOTE_FUJI_TAG_FOCUS_POINT:
00251                 CF (entry->format, EXIF_FORMAT_SHORT, val, maxlen);
00252                 CC (entry->components, 2, val, maxlen);
00253                 vs = exif_get_short (entry->data, entry->order);
00254                 vs2 = exif_get_short (entry->data+2, entry->order);
00255                 snprintf (val, maxlen, "%i, %i", vs, vs2);
00256                 break;
00257           case MNOTE_FUJI_TAG_MIN_FOCAL_LENGTH:
00258           case MNOTE_FUJI_TAG_MAX_FOCAL_LENGTH:
00259                 CF (entry->format, EXIF_FORMAT_RATIONAL, val, maxlen);
00260                 CC (entry->components, 1, val, maxlen);
00261                 vr = exif_get_rational (entry->data, entry->order);
00262                 if (!vr.denominator) break;
00263                 snprintf (val, maxlen, _("%2.2f mm"), (double) vr.numerator /
00264                           vr.denominator);
00265                 break;
00266 
00267         default:
00268                 switch (entry->format) {
00269                 case EXIF_FORMAT_ASCII:
00270                   strncpy (val, (char *)entry->data, MIN(maxlen, entry->size));
00271                   break;
00272                 case EXIF_FORMAT_SHORT:
00273                   vs = exif_get_short (entry->data, entry->order);
00274                   snprintf (val, maxlen, "%i", vs);
00275                   break;
00276                 case EXIF_FORMAT_LONG:
00277                   vl = exif_get_long (entry->data, entry->order);
00278                   snprintf (val, maxlen, "%lu", (long unsigned) vl);
00279                   break;
00280                 case EXIF_FORMAT_SLONG:
00281                   vsl = exif_get_slong (entry->data, entry->order);
00282                   snprintf (val, maxlen, "%li", (long int) vsl);
00283                   break;
00284                 case EXIF_FORMAT_RATIONAL:
00285                   vr = exif_get_rational (entry->data, entry->order);
00286                   if (!vr.denominator) break;
00287                   snprintf (val, maxlen, "%2.4f", (double) vr.numerator /
00288                                                     vr.denominator);
00289                   break;
00290                 case EXIF_FORMAT_SRATIONAL:
00291                   vsr = exif_get_srational (entry->data, entry->order);
00292                   if (!vsr.denominator) break;
00293                   snprintf (val, maxlen, "%2.4f", (double) vsr.numerator /
00294                           vsr.denominator);
00295                   break;
00296                 case EXIF_FORMAT_UNDEFINED:
00297                 default:
00298                   snprintf (val, maxlen, _("%i bytes unknown data"),
00299                           entry->size);
00300                   break;
00301                 }
00302                 break;
00303         }
00304 
00305         return (val);
00306 }

SourceForge.net Logo Generated by doxygen