mnote-pentax-entry.c

Go to the documentation of this file.
00001 /* mnote-pentax-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 <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 #define CC2(number,t1,t2,v,maxlen)                                      \
00058 {                                                                       \
00059         if ((number != t1) && (number != t2)) {                         \
00060                 snprintf (v, maxlen,                                    \
00061                         _("Invalid number of components (%i, "          \
00062                         "expected %i or %i)."), (int) number,           \
00063                         (int) t1, (int) t2);                            \
00064                 break;                                                  \
00065         }                                                               \
00066 }
00067 
00068 static const struct {
00069         ExifTag tag;
00070         struct {
00071                 int index;
00072                 const char *string;
00073         } elem[33];
00074 } items[] = {
00075 #ifndef NO_VERBOSE_TAG_DATA
00076   { MNOTE_PENTAX_TAG_MODE,
00077     { {0, N_("Auto")},
00078       {1, N_("Night scene")},
00079       {2, N_("Manual")},
00080       {4, N_("Multi-exposure")},
00081       {0, NULL}}},
00082   { MNOTE_PENTAX_TAG_QUALITY,
00083     { {0, N_("Good")},
00084       {1, N_("Better")},
00085       {2, N_("Best")},{0,NULL}}},
00086   { MNOTE_PENTAX_TAG_FOCUS,
00087     { {2, N_("Custom")},
00088       {3, N_("Auto")},
00089       {0, NULL}}},
00090   { MNOTE_PENTAX_TAG_FLASH,
00091     { {1, N_("Auto")},
00092       {2, N_("Flash on")},
00093       {4, N_("Flash off")},
00094       {6, N_("Red-eye reduction")},
00095       {0, NULL}}},
00096   { MNOTE_PENTAX_TAG_WHITE_BALANCE,
00097     { {0, N_("Auto")},
00098       {1, N_("Daylight")},
00099       {2, N_("Shade")},
00100       {3, N_("Tungsten")},
00101       {4, N_("Fluorescent")},
00102       {5, N_("Manual")},
00103       {0, NULL}}},
00104   { MNOTE_PENTAX_TAG_SHARPNESS,
00105     { {0, N_("Normal")},
00106       {1, N_("Soft")},
00107       {2, N_("Hard")},
00108       {0, NULL}}},
00109   { MNOTE_PENTAX_TAG_CONTRAST,
00110     { {0, N_("Normal")},
00111       {1, N_("Low")},
00112       {2, N_("High")},
00113       {0, NULL}}},
00114   { MNOTE_PENTAX_TAG_SATURATION,
00115     { {0, N_("Normal")},
00116       {1, N_("Low")},
00117       {2, N_("High")},
00118       {0, NULL}}},
00119   { MNOTE_PENTAX_TAG_ISO_SPEED,
00120     { {10,  N_("100")},
00121       {16,  N_("200")},
00122       {100, N_("100")},
00123       {200, N_("200")},
00124       { 0,  NULL}}},
00125   { MNOTE_PENTAX_TAG_COLOR,
00126     { {1, N_("Full")},
00127       {2, N_("Black & white")},
00128       {3, N_("Sepia")},
00129       {0, NULL}}},
00130   { MNOTE_PENTAX2_TAG_MODE,
00131     { {0, N_("Auto")},
00132       {1, N_("Night scene")},
00133       {2, N_("Manual")},
00134       {4, N_("Multi-exposure")},
00135       {0, NULL}}},
00136   { MNOTE_PENTAX2_TAG_QUALITY,
00137     { {0, N_("Good")},
00138       {1, N_("Better")},
00139       {2, N_("Best")},
00140       {3, N_("TIFF")},
00141       {4, N_("RAW")},
00142       {0, NULL}}},
00143   { MNOTE_PENTAX2_TAG_IMAGE_SIZE,
00144     { {0, "640x480"},
00145       {1, N_("Full")},
00146       {2, "1024x768"},
00147       {3, "1280x960"},
00148       {4, "1600x1200"},
00149       {5, "2048x1536"},
00150       {8, N_("2560x1920 or 2304x1728")},
00151       {9, "3072x2304"},
00152       {10, "3264x2448"},
00153       {19, "320x240"},
00154       {20, "2288x1712"},
00155       {21, "2592x1944"},
00156       {22, N_("2304x1728 or 2592x1944")},
00157       {23, "3056x2296"},
00158       {25, N_("2816x2212 or 2816x2112")},
00159       {27, "3648x2736"},
00160       {36, "3008x2008"},
00161       {0, NULL}}},
00162   { MNOTE_PENTAX2_TAG_PICTURE_MODE,
00163     { {0, N_("Program")},
00164       {2, N_("Program AE")},
00165       {3, N_("Manual")},
00166       {5, N_("Portrait")},
00167       {6, N_("Landscape")},
00168       {8, N_("Sport")},
00169       {9, N_("Night scene")},
00170       {11, N_("Soft")},
00171       {12, N_("Surf & snow")},
00172       {13, N_("Sunset or candlelight")},
00173       {14, N_("Autumn")},
00174       {15, N_("Macro")},
00175       {17, N_("Fireworks")},
00176       {18, N_("Text")},
00177       {19, N_("Panorama")},
00178       {30, N_("Self portrait")},
00179       {31, N_("Illustrations")},
00180       {33, N_("Digital filter")},
00181       {37, N_("Museum")},
00182       {38, N_("Food")},
00183       {40, N_("Green mode")},
00184       {49, N_("Light pet")},
00185       {50, N_("Dark pet")},
00186       {51, N_("Medium pet")},
00187       {53, N_("Underwater")},
00188       {54, N_("Candlelight")},
00189       {55, N_("Natural skin tone")},
00190       {56, N_("Synchro sound record")},
00191       {58, N_("Frame composite")},
00192       {0, NULL}}},
00193   { MNOTE_PENTAX2_TAG_FLASH_MODE,
00194     { {0x0000, N_("Auto, did not fire")},
00195       {0x0001, N_("Off")},
00196       {0x0003, N_("Auto, did not fire, red-eye reduction")},
00197       {0x0100, N_("Auto, fired")},
00198       {0x0102, N_("On")},
00199       {0x0103, N_("Auto, fired, red-eye reduction")},
00200       {0x0104, N_("On, red-eye reduction")},
00201       {0x0105, N_("On, wireless")},
00202       {0x0108, N_("On, soft")},
00203       {0x0109, N_("On, slow-sync")},
00204       {0x010a, N_("On, slow-sync, red-eye reduction")},
00205       {0x010b, N_("On, trailing-curtain sync")},
00206       {0, NULL}}},
00207   { MNOTE_PENTAX2_TAG_FOCUS_MODE,
00208     { {0, N_("Normal")},
00209       {1, N_("Macro")},
00210       {2, N_("Infinity")},
00211       {3, N_("Manual")},
00212       {5, N_("Pan focus")},
00213       {16, N_("AF-S")},
00214       {17, N_("AF-C")},
00215       {0, NULL}}},
00216   { MNOTE_PENTAX2_TAG_AFPOINT_SELECTED,
00217     { {1, N_("Upper-left")},
00218       {2, N_("Top")},
00219       {3, N_("Upper-right")},
00220       {4, N_("Left")},
00221       {5, N_("Mid-left")},
00222       {6, N_("Center")},
00223       {7, N_("Mid-right")},
00224       {8, N_("Right")},
00225       {9, N_("Lower-left")},
00226       {10, N_("Bottom")},
00227       {11, N_("Lower-right")},
00228       {0xfffe, N_("Fixed center")},
00229       {0xffff, N_("Auto")},
00230       {0, NULL}}},
00231   { MNOTE_PENTAX2_TAG_AUTO_AFPOINT,
00232     { {0, N_("Multiple")},
00233       {1, N_("Top-left")},
00234       {2, N_("Top-center")},
00235       {3, N_("Top-right")},
00236       {4, N_("Left")},
00237       {5, N_("Center")},
00238       {6, N_("Right")},
00239       {7, N_("Bottom-left")},
00240       {8, N_("Bottom-center")},
00241       {9, N_("Bottom-right")},
00242       {0xffff, N_("None")},
00243       {0, NULL}}},
00244   { MNOTE_PENTAX2_TAG_WHITE_BALANCE,
00245     { {0, N_("Auto")},
00246       {1, N_("Daylight")},
00247       {2, N_("Shade")},
00248       {3, N_("Fluorescent")},
00249       {4, N_("Tungsten")},
00250       {5, N_("Manual")},
00251       {6, N_("Daylight fluorescent")},
00252       {7, N_("Day white fluorescent")},
00253       {8, N_("White fluorescent")},
00254       {9, N_("Flash")},
00255       {10, N_("Cloudy")},
00256       {0xfffe, N_("Unknown")},
00257       {0xffff, N_("User selected")},
00258       {0, NULL}}},
00259   {MNOTE_CASIO2_TAG_BESTSHOT_MODE, 
00260     { {0, N_("Off")},
00261       {1, N_("On")},
00262       {0, NULL}}},
00263 #endif
00264   {0, {{0, NULL}}}
00265 };
00266 
00267 /* Two-component values */
00268 static const struct {
00269         ExifTag tag;
00270         struct {
00271                 int index1, index2;
00272                 const char *string;
00273         } elem[39];
00274 } items2[] = {
00275 #ifndef NO_VERBOSE_TAG_DATA
00276   { MNOTE_PENTAX2_TAG_IMAGE_SIZE,
00277     { {0, 0, "2304x1728"},
00278       {4, 0, "1600x1200"},
00279       {5, 0, "2048x1536"},
00280       {8, 0, "2560x1920"},
00281       {34, 0, "1536x1024"},
00282       {36, 0, N_("3008x2008 or 3040x2024")},
00283       {37, 0, "3008x2000"},
00284       {35, 1, "2400x1600"},
00285       {32, 2, "960x480"},
00286       {33, 2, "1152x768"},
00287       {34, 2, "1536x1024"},
00288       {0,  0, NULL}}},
00289   { MNOTE_PENTAX2_TAG_PICTURE_MODE,
00290     { {0,   0, N_("Auto")},
00291       {5,   0, N_("Portrait")},
00292       {53,  0, N_("Underwater")},
00293       {255, 0, N_("Digital filter?")},
00294       {5,   1, N_("Portrait")},
00295       {9,   1, N_("Night scene")},
00296       {13,  1, N_("Candlelight")},
00297       {15,  1, N_("Macro")},
00298       {53,  1, N_("Underwater")},
00299       {0,   2, N_("Program AE")},
00300       {5,   2, N_("Portrait")},
00301       {6,   2, N_("Landscape")},
00302       {0,   0, NULL}}},
00303 #endif
00304   {0, {{0, 0, NULL}}}
00305 };
00306 
00307 char *
00308 mnote_pentax_entry_get_value (MnotePentaxEntry *entry,
00309                               char *val, unsigned int maxlen)
00310 {
00311         ExifLong vl;
00312         ExifShort vs, vs2;
00313         int i = 0, j = 0;
00314 
00315         if (!entry) return (NULL);
00316 
00317         memset (val, 0, maxlen);
00318         maxlen--;
00319 
00320         switch (entry->tag) {
00321           case MNOTE_PENTAX_TAG_MODE:
00322           case MNOTE_PENTAX_TAG_QUALITY:
00323           case MNOTE_PENTAX_TAG_FOCUS:
00324           case MNOTE_PENTAX_TAG_FLASH:
00325           case MNOTE_PENTAX_TAG_WHITE_BALANCE:
00326           case MNOTE_PENTAX_TAG_SHARPNESS:
00327           case MNOTE_PENTAX_TAG_CONTRAST:
00328           case MNOTE_PENTAX_TAG_SATURATION:
00329           case MNOTE_PENTAX_TAG_ISO_SPEED:
00330           case MNOTE_PENTAX_TAG_COLOR:
00331           case MNOTE_PENTAX2_TAG_MODE:
00332           case MNOTE_PENTAX2_TAG_QUALITY:
00333           case MNOTE_PENTAX2_TAG_FLASH_MODE:
00334           case MNOTE_PENTAX2_TAG_FOCUS_MODE:
00335           case MNOTE_PENTAX2_TAG_AFPOINT_SELECTED:
00336           case MNOTE_PENTAX2_TAG_AUTO_AFPOINT:
00337           case MNOTE_PENTAX2_TAG_WHITE_BALANCE:
00338           case MNOTE_PENTAX2_TAG_PICTURE_MODE:
00339           case MNOTE_PENTAX2_TAG_IMAGE_SIZE:
00340           case MNOTE_CASIO2_TAG_BESTSHOT_MODE:
00341                 CF (entry->format, EXIF_FORMAT_SHORT, val, maxlen);
00342                 CC2 (entry->components, 1, 2, val, maxlen);
00343                 if (entry->components == 1) {
00344                         vs = exif_get_short (entry->data, entry->order);
00345 
00346                         /* search the tag */
00347                         for (i = 0; (items[i].tag && items[i].tag != entry->tag); i++);
00348                         if (!items[i].tag) {
00349                                 snprintf (val, maxlen,
00350                                           _("Internal error (unknown value %i)"), vs);
00351                                 break;
00352                         }
00353 
00354                         /* find the value */
00355                         for (j = 0; items[i].elem[j].string &&
00356                             (items[i].elem[j].index < vs); j++);
00357                         if (items[i].elem[j].index != vs) {
00358                                 snprintf (val, maxlen,
00359                                           _("Internal error (unknown value %i)"), vs);
00360                                 break;
00361                         }
00362                         strncpy (val, _(items[i].elem[j].string), maxlen);
00363                 } else {
00364                         /* Two-component values */
00365                         CF (entry->format, EXIF_FORMAT_SHORT, val, maxlen);
00366                         CC2 (entry->components, 1, 2, val, maxlen);
00367                         vs = exif_get_short (entry->data, entry->order);
00368                         vs2 = exif_get_short (entry->data+2, entry->order) << 16;
00369 
00370                         /* search the tag */
00371                         for (i = 0; (items2[i].tag && items2[i].tag != entry->tag); i++);
00372                         if (!items2[i].tag) {
00373                                 snprintf (val, maxlen,
00374                                           _("Internal error (unknown value %i %i)"), vs, vs2);
00375                                 break;
00376                         }
00377 
00378                         /* find the value */
00379                         for (j = 0; items2[i].elem[j].string && ((items2[i].elem[j].index2 < vs2)
00380                                 || ((items2[i].elem[j].index2 == vs2) && (items2[i].elem[j].index1 < vs))); j++);
00381                         if ((items2[i].elem[j].index1 != vs) || (items2[i].elem[j].index2 != vs2)) {
00382                                 snprintf (val, maxlen,
00383                                           _("Internal error (unknown value %i %i)"), vs, vs2);
00384                                 break;
00385                         }
00386                         strncpy (val, _(items2[i].elem[j].string), maxlen);
00387                 }
00388                 break;
00389 
00390         case MNOTE_PENTAX_TAG_ZOOM:
00391                 CF (entry->format, EXIF_FORMAT_LONG, val, maxlen);
00392                 CC (entry->components, 1, val, maxlen);
00393                 vl = exif_get_long (entry->data, entry->order);
00394                 snprintf (val, maxlen, "%li", (long int) vl);
00395                 break;
00396         case MNOTE_PENTAX_TAG_PRINTIM:
00397                 CF (entry->format, EXIF_FORMAT_UNDEFINED, val, maxlen);
00398                 CC (entry->components, 124, val, maxlen);
00399                 snprintf (val, maxlen, _("%i bytes unknown data"),
00400                         entry->size);
00401                 break;
00402         case MNOTE_PENTAX_TAG_TZ_CITY:
00403         case MNOTE_PENTAX_TAG_TZ_DST:
00404                 CF (entry->format, EXIF_FORMAT_UNDEFINED, val, maxlen);
00405                 CC (entry->components, 4, val, maxlen);
00406                 strncpy (val, (char*)entry->data, MIN(maxlen, entry->size));
00407                 break;
00408         case MNOTE_PENTAX2_TAG_DATE:
00409                 CF (entry->format, EXIF_FORMAT_UNDEFINED, val, maxlen);
00410                 CC (entry->components, 4, val, maxlen);
00411                 /* Note: format is UNDEFINED, not SHORT -> order is fixed: MOTOROLA */
00412                 vs = exif_get_short (entry->data, EXIF_BYTE_ORDER_MOTOROLA);
00413                 snprintf (val, maxlen, "%i:%02i:%02i", vs, entry->data[2], entry->data[3]);
00414                 break;
00415         case MNOTE_PENTAX2_TAG_TIME:
00416                 CF (entry->format, EXIF_FORMAT_UNDEFINED, val, maxlen);
00417                 CC2 (entry->components, 3, 4, val, maxlen);
00418                 snprintf (val, maxlen, "%02i:%02i:%02i", entry->data[0], entry->data[1], entry->data[2]);
00419                 break;
00420         default:
00421                 switch (entry->format) {
00422                 case EXIF_FORMAT_ASCII:
00423                   strncpy (val, (char *)entry->data, MIN(maxlen, entry->size));
00424                   break;
00425                 case EXIF_FORMAT_SHORT:
00426                   {
00427                         const unsigned char *data = entry->data;
00428                         size_t k, len = strlen(val);
00429                         for(k=0; k<entry->components; k++) {
00430                                 vs = exif_get_short (data, entry->order);
00431                                 snprintf (val+len, maxlen-len, "%i ", vs);
00432                                 len = strlen(val);
00433                                 data += 2;
00434                         }
00435                   }
00436                   break;
00437                 case EXIF_FORMAT_LONG:
00438                   {
00439                         const unsigned char *data = entry->data;
00440                         size_t k, len = strlen(val);
00441                         for(k=0; k<entry->components; k++) {
00442                                 vl = exif_get_long (data, entry->order);
00443                                 snprintf (val+len, maxlen-len, "%li", (long int) vl);
00444                                 len = strlen(val);
00445                                 data += 4;
00446                         }
00447                   }
00448                   break;
00449                 case EXIF_FORMAT_UNDEFINED:
00450                 default:
00451                   snprintf (val, maxlen, _("%i bytes unknown data"),
00452                           entry->size);
00453                   break;
00454                 }
00455                 break;
00456         }
00457 
00458         return (val);
00459 }

SourceForge.net Logo Generated by doxygen