2005-03-30 Lutz Mueller <lutz@users.sourceforge.net>
[platform/upstream/libexif.git] / libexif / exif-data.c
index b8e7441..92e5857 100644 (file)
@@ -27,8 +27,7 @@
 #include <libexif/exif-utils.h>
 #include <libexif/exif-loader.h>
 #include <libexif/exif-log.h>
-
-#include <libjpeg/jpeg-marker.h>
+#include <libexif/i18n.h>
 
 #include <libexif/olympus/exif-mnote-data-olympus.h>
 #include <libexif/canon/exif-mnote-data-canon.h>
 #      define strncasecmp strnicmp
 #endif
 
+#undef JPEG_MARKER_SOI
+#define JPEG_MARKER_SOI  0xd8
+#undef JPEG_MARKER_APP0
+#define JPEG_MARKER_APP0 0xe0
+#undef JPEG_MARKER_APP1
+#define JPEG_MARKER_APP1 0xe1
+
 static const unsigned char ExifHeader[] = {0x45, 0x78, 0x69, 0x66, 0x00, 0x00};
 
 struct _ExifDataPrivate
@@ -382,14 +388,14 @@ cmp_func (const unsigned char *p1, const unsigned char *p2, ExifByteOrder o)
 }
 
 static int
-cmp_be_func (const void *elem1, const void *elem2)
+cmp_func_intel (const void *elem1, const void *elem2)
 {
        return cmp_func ((const unsigned char *) elem1,
                        (const unsigned char *) elem2, EXIF_BYTE_ORDER_INTEL);
 }
 
 static int
-cmp_le_func (const void *elem1, const void *elem2)
+cmp_func_motorola (const void *elem1, const void *elem2)
 {
        return cmp_func ((const unsigned char *) elem1,
                        (const unsigned char *) elem2, EXIF_BYTE_ORDER_MOTOROLA);
@@ -576,7 +582,7 @@ exif_data_save_data_content (ExifData *data, ExifContent *ifd,
        /* Sort the directory according to TIFF specification */
        qsort (*d + 6 + offset - (ifd->count + n_ptr + n_thumb) * 12,
                        (ifd->count + n_ptr + n_thumb), 12,
-                       data->priv->order == EXIF_BYTE_ORDER_INTEL ? cmp_be_func : cmp_le_func);
+                       data->priv->order == EXIF_BYTE_ORDER_INTEL ? cmp_func_intel : cmp_func_motorola);
 
        /* Correctly terminate the directory */
        if (i == EXIF_IFD_0 && (data->ifd[EXIF_IFD_1]->count ||
@@ -636,6 +642,10 @@ exif_data_get_type_maker_note (ExifData *d)
        return EXIF_DATA_TYPE_MAKER_NOTE_NONE;
 }
 
+#define LOG_TOO_SMALL \
+exif_log (data->priv->log, EXIF_LOG_CODE_CORRUPT_DATA, "ExifData", \
+               _("Size of data too small to allow for EXIF data."));
+
 void
 exif_data_load_data (ExifData *data, const unsigned char *d_orig,
                     unsigned int ds_orig)
@@ -656,8 +666,7 @@ exif_data_load_data (ExifData *data, const unsigned char *d_orig,
         * not, search the EXIF marker.
         */
        if (ds < 6) {
-               exif_log (data->priv->log, EXIF_LOG_CODE_DEBUG, "ExifData",
-                         "Size too small.");
+               LOG_TOO_SMALL;
                return;
        }
        if (!memcmp (d, ExifHeader, 6)) {
@@ -694,15 +703,14 @@ exif_data_load_data (ExifData *data, const unsigned char *d_orig,
                                break;
 
                        /* Unknown marker or data. Give up. */
-                       exif_log (data->priv->log, EXIF_LOG_CODE_DEBUG,
-                                 "ExifData", "EXIF marker not found.");
+                       exif_log (data->priv->log, EXIF_LOG_CODE_CORRUPT_DATA,
+                                 "ExifData", _("EXIF marker not found."));
                        return;
                }
                d++;
                ds--;
                if (ds < 2) {
-                       exif_log (data->priv->log, EXIF_LOG_CODE_DEBUG,
-                                 "ExifData", "Size too small.");
+                       LOG_TOO_SMALL;
                        return;
                }
                len = (d[0] << 8) | d[1];
@@ -718,13 +726,12 @@ exif_data_load_data (ExifData *data, const unsigned char *d_orig,
         * (offset 2, length 6).
         */
        if (ds < 6) {
-               exif_log (data->priv->log, EXIF_LOG_CODE_DEBUG, "ExifData",
-                         "Size too small.");
+               LOG_TOO_SMALL;
                return;
        }
        if (memcmp (d, ExifHeader, 6)) {
-               exif_log (data->priv->log, EXIF_LOG_CODE_DEBUG, "ExifData",
-                         "EXIF header not found.");
+               exif_log (data->priv->log, EXIF_LOG_CODE_CORRUPT_DATA,
+                               "ExifData", _("EXIF header not found."));
                return;
        }
 
@@ -738,8 +745,11 @@ exif_data_load_data (ExifData *data, const unsigned char *d_orig,
                data->priv->order = EXIF_BYTE_ORDER_INTEL;
        else if (!memcmp (d + 6, "MM", 2))
                data->priv->order = EXIF_BYTE_ORDER_MOTOROLA;
-       else
+       else {
+               exif_log (data->priv->log, EXIF_LOG_CODE_CORRUPT_DATA,
+                               "ExifData", _("Unknown encoding."));
                return;
+       }
 
        /* Fixed value */
        if (exif_get_short (d + 8, data->priv->order) != 0x002a)
@@ -769,8 +779,8 @@ exif_data_load_data (ExifData *data, const unsigned char *d_orig,
 
                /* Sanity check. */
                if (offset > ds - 6) {
-                       exif_log (data->priv->log, EXIF_LOG_CODE_DEBUG, 
-                                 "ExifData", "Bogus offset!");
+                       exif_log (data->priv->log, EXIF_LOG_CODE_CORRUPT_DATA,
+                                 "ExifData", "Bogus offset.");
                        return;
                }