2005-03-09 Lutz Mueller <lutz@users.sourceforge.net>
authorLutz Mueller <lutz.s.mueller@gmail.com>
Wed, 9 Mar 2005 20:49:30 +0000 (21:49 +0100)
committerLutz Mueller <lutz.s.mueller@gmail.com>
Wed, 9 Mar 2005 20:49:30 +0000 (21:49 +0100)
* libexif/exif-utils.[c,h] (exif_array_set_byte_order): New function.
* libexif/exif-data.c
* libexif/canon/exif-mnote-data-canon.c
* libexif/olympus/exif-mnote-data-olympus.c
* libexif/pentax/exif-mnote-data-pentax.c: Use new function.

ChangeLog
libexif/canon/exif-mnote-data-canon.c
libexif/exif-data.c
libexif/exif-utils.c
libexif/exif-utils.h
libexif/olympus/exif-mnote-data-olympus.c
libexif/pentax/exif-mnote-data-pentax.c

index bf68898..58402a4 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,11 @@
+2005-03-09  Lutz Mueller <lutz@users.sourceforge.net>
+
+       * libexif/exif-utils.[c,h] (exif_array_set_byte_order): New function.
+       * libexif/exif-data.c
+       * libexif/canon/exif-mnote-data-canon.c
+       * libexif/olympus/exif-mnote-data-olympus.c
+       * libexif/pentax/exif-mnote-data-pentax.c: Use new function.
+
 2005-03-09  Jan Patera <patera@users.sourceforge.net>
 
        * exif_data.c: Final fix of Ubuntu Security Notice USN-91-1
index ca73aa5..e54d978 100644 (file)
@@ -75,12 +75,7 @@ exif_mnote_data_canon_set_byte_order (ExifMnoteData *d, ExifByteOrder o)
 {
        ExifByteOrder o_orig;
        ExifMnoteDataCanon *n = (ExifMnoteDataCanon *) d;
-       unsigned int i, fs;
-       ExifShort s;
-       ExifLong l;
-       ExifSLong sl;
-       ExifRational r;
-       ExifSRational sr;
+       unsigned int i;
 
        if (!n) return;
 
@@ -88,55 +83,8 @@ exif_mnote_data_canon_set_byte_order (ExifMnoteData *d, ExifByteOrder o)
        n->order = o;
        for (i = 0; i < n->count; i++) {
                n->entries[i].order = o;
-               fs = exif_format_get_size (n->entries[i].format);
-               switch (n->entries[i].format) {
-               case EXIF_FORMAT_SHORT:
-                       for (i = 0; i < n->entries[i].components; i++) {
-                               s = exif_get_short (n->entries[i].data + (i*fs),
-                                                   o_orig);
-                               exif_set_short (n->entries[i].data + (i * fs),
-                                               o, s);
-                       }
-                       break;
-               case EXIF_FORMAT_LONG:
-                       for (i = 0; i < n->entries[i].components; i++) {
-                               l = exif_get_long (n->entries[i].data + (i*fs),
-                                                  o_orig);
-                               exif_set_long (n->entries[i].data + (i * fs),
-                                              o, l);
-                       }
-                       break;
-               case EXIF_FORMAT_RATIONAL:
-                       for (i = 0; i < n->entries[i].components; i++) {
-                               r = exif_get_rational (n->entries[i].data +
-                                                      (i * fs), o_orig);
-                               exif_set_rational (n->entries[i].data +
-                                       (i * fs), o, r);
-                       }
-                       break;
-               case EXIF_FORMAT_SLONG:
-                       for (i = 0; i < n->entries[i].components; i++) {
-                               sl = exif_get_slong (n->entries[i].data +
-                                               (i * fs), o_orig);
-                               exif_set_slong (n->entries[i].data +
-                                               (i * fs), o, sl);
-                       }
-                       break;
-               case EXIF_FORMAT_SRATIONAL:
-                       for (i = 0; i < n->entries[i].components; i++) {
-                               sr = exif_get_srational (n->entries[i].data +
-                                               (i * fs), o_orig);
-                               exif_set_srational (n->entries[i].data +
-                                               (i * fs), o, sr);
-                       }
-                       break;
-               case EXIF_FORMAT_UNDEFINED:
-               case EXIF_FORMAT_BYTE:
-               case EXIF_FORMAT_ASCII:
-               default:
-                       /* Nothing here. */
-                       break;
-               }
+               exif_array_set_byte_order (n->entries[i].format, n->entries[i].data,
+                               n->entries[i].components, o_orig, o);
        }
 }
 
index bd8d001..cc9c91b 100644 (file)
@@ -940,75 +940,11 @@ static void
 entry_set_byte_order (ExifEntry *e, void *data)
 {
        ByteOrderChangeData *d = data;
-       unsigned int i;
-       ExifShort s;
-       ExifLong l;
-       ExifSLong sl;
-       ExifRational r;
-       ExifSRational sr;
 
        if (!e)
                return;
 
-       switch (e->format) {
-       case EXIF_FORMAT_SHORT:
-               for (i = 0; i < e->components; i++) {
-                       s = exif_get_short (e->data +
-                               (i * exif_format_get_size (e->format)),
-                               d->old);
-                       exif_set_short (e->data +
-                               (i * exif_format_get_size (e->format)),
-                               d->new, s);
-               }
-               break;
-       case EXIF_FORMAT_LONG:
-               for (i = 0; i < e->components; i++) {
-                       l = exif_get_long (e->data +
-                               (i * exif_format_get_size (e->format)),
-                               d->old);
-                       exif_set_long (e->data +
-                               (i * exif_format_get_size (e->format)),
-                               d->new, l);
-               }
-               break;
-       case EXIF_FORMAT_RATIONAL:
-               for (i = 0; i < e->components; i++) {
-                       r = exif_get_rational (e->data +
-                               (i * exif_format_get_size (e->format)),
-                               d->old);
-                       exif_set_rational (e->data +
-                               (i * exif_format_get_size (e->format)),
-                               d->new, r);
-               }
-               break;
-       case EXIF_FORMAT_SLONG:
-               for (i = 0; i < e->components; i++) {
-                       sl = exif_get_slong (e->data +
-                               (i * exif_format_get_size (e->format)),
-                               d->old);
-                       exif_set_slong (e->data +
-                               (i * exif_format_get_size (e->format)),
-                               d->new, sl);
-               }
-               break;
-       case EXIF_FORMAT_SRATIONAL:
-               for (i = 0; i < e->components; i++) {
-                       sr = exif_get_srational (e->data +
-                               (i * exif_format_get_size (e->format)),
-                               d->old);
-                       exif_set_srational (e->data +
-                               (i * exif_format_get_size (e->format)),
-                               d->new, sr);
-               }
-               break;
-       case EXIF_FORMAT_UNDEFINED:
-       case EXIF_FORMAT_BYTE:
-       case EXIF_FORMAT_SBYTE:
-       case EXIF_FORMAT_ASCII:
-       default:
-               /* Nothing here. */
-               break;
-       }
+       exif_array_set_byte_order (e->format, e->data, e->components, d->old, d->new);
 }
 
 static void
index 384b56e..2a8a56f 100644 (file)
 
 typedef signed short ExifSShort;
 
+void
+exif_array_set_byte_order (ExifFormat f, unsigned char *b, unsigned int n,
+               ExifByteOrder o_orig, ExifByteOrder o_new)
+{
+       unsigned int j;
+       unsigned int fs = exif_format_get_size (f);
+       ExifShort s;
+       ExifLong l;
+       ExifSLong sl;
+       ExifRational r;
+       ExifSRational sr;
+
+       if (!b || !n) return;
+
+       switch (f) {
+       case EXIF_FORMAT_SHORT:
+               for (j = 0; j < n; j++) {
+                       s = exif_get_short (b + j * fs, o_orig);
+                       exif_set_short (b + j * fs, o_new, s);
+               }
+               break;
+       case EXIF_FORMAT_LONG:
+               for (j = 0; j < n; j++) {
+                       l = exif_get_long (b + j * fs, o_orig);
+                       exif_set_long (b + j * fs, o_new, l);
+               }
+               break;
+       case EXIF_FORMAT_RATIONAL:
+               for (j = 0; j < n; j++) {
+                       r = exif_get_rational (b + j * fs, o_orig);
+                       exif_set_rational (b + j * fs, o_new, r);
+               }
+               break;
+       case EXIF_FORMAT_SLONG:
+               for (j = 0; j < n; j++) {
+                       sl = exif_get_slong (b + j * fs, o_orig);
+                       exif_set_slong (b + j * fs, o_new, sl);
+               }
+               break;
+       case EXIF_FORMAT_SRATIONAL:
+               for (j = 0; j < n; j++) {
+                       sr = exif_get_srational (b + j * fs, o_orig);
+                       exif_set_srational (b + j * fs, o_new, sr);
+               }
+               break;
+       case EXIF_FORMAT_UNDEFINED:
+       case EXIF_FORMAT_BYTE:
+       case EXIF_FORMAT_ASCII:
+       default:
+               /* Nothing here. */
+               break;
+       }
+}
+
 static ExifSShort
 exif_get_sshort (const unsigned char *buf, ExifByteOrder order)
 {
index 33a469f..3bc6ce0 100644 (file)
@@ -26,6 +26,7 @@ extern "C" {
 #endif /* __cplusplus */
 
 #include <libexif/exif-byte-order.h>
+#include <libexif/exif-format.h>
 #include <libexif/_stdint.h>
 
 
@@ -59,6 +60,10 @@ void exif_set_rational  (unsigned char *b, ExifByteOrder order,
 void exif_set_srational (unsigned char *b, ExifByteOrder order,
                         ExifSRational value);
 
+/* Please do not use this function outside of the library. */
+void exif_array_set_byte_order (ExifFormat, unsigned char *, unsigned int,
+               ExifByteOrder o_orig, ExifByteOrder o_new);
+
 #undef  MIN
 #define MIN(a, b)  (((a) < (b)) ? (a) : (b))
 
index d08f78f..02794c5 100644 (file)
@@ -355,12 +355,7 @@ exif_mnote_data_olympus_set_byte_order (ExifMnoteData *d, ExifByteOrder o)
 {
        ExifByteOrder o_orig;
        ExifMnoteDataOlympus *n = (ExifMnoteDataOlympus *) d;
-       unsigned int i, fs;
-       ExifShort s;
-       ExifLong l;
-       ExifSLong sl;
-       ExifRational r;
-       ExifSRational sr;
+       unsigned int i;
 
        if (!n) return;
 
@@ -368,55 +363,8 @@ exif_mnote_data_olympus_set_byte_order (ExifMnoteData *d, ExifByteOrder o)
        n->order = o;
        for (i = 0; i < n->count; i++) {
                n->entries[i].order = o;
-               fs = exif_format_get_size (n->entries[i].format);
-               switch (n->entries[i].format) {
-               case EXIF_FORMAT_SHORT:
-                       for (i = 0; i < n->entries[i].components; i++) {
-                               s = exif_get_short (n->entries[i].data + (i*fs),
-                                               o_orig);
-                               exif_set_short (n->entries[i].data + (i * fs),
-                                               o, s);
-                       }
-                       break;
-               case EXIF_FORMAT_LONG:
-                       for (i = 0; i < n->entries[i].components; i++) {
-                               l = exif_get_long (n->entries[i].data + (i*fs),
-                                               o_orig);
-                               exif_set_long (n->entries[i].data + (i * fs),
-                                               o, l);
-                       }
-                       break;
-               case EXIF_FORMAT_RATIONAL:
-                       for (i = 0; i < n->entries[i].components; i++) {
-                               r = exif_get_rational (n->entries[i].data +
-                                               (i * fs), o_orig);
-                               exif_set_rational (n->entries[i].data +
-                                               (i * fs), o, r);
-                       }
-                       break;
-               case EXIF_FORMAT_SLONG:
-                       for (i = 0; i < n->entries[i].components; i++) {
-                               sl = exif_get_slong (n->entries[i].data +
-                                               (i * fs), o_orig);
-                               exif_set_slong (n->entries[i].data +
-                                               (i * fs), o, sl);
-                       }
-                       break;
-               case EXIF_FORMAT_SRATIONAL:
-                       for (i = 0; i < n->entries[i].components; i++) {
-                               sr = exif_get_srational (n->entries[i].data +
-                                               (i * fs), o_orig);
-                               exif_set_srational (n->entries[i].data +
-                                               (i * fs), o, sr);
-                       }
-                       break;
-               case EXIF_FORMAT_UNDEFINED:
-               case EXIF_FORMAT_BYTE:
-               case EXIF_FORMAT_ASCII:
-               default:
-                       /* Nothing here. */
-                       break;
-               }
+               exif_array_set_byte_order (n->entries[i].format, n->entries[i].data,
+                               n->entries[i].components, o_orig, o);
        }
 }
 
index ca2ad45..cc2cc12 100644 (file)
@@ -167,69 +167,18 @@ static void
 exif_mnote_data_pentax_set_byte_order (ExifMnoteData *d, ExifByteOrder o)
 {
        ExifByteOrder o_orig;
-        ExifMnoteDataPentax *n = (ExifMnoteDataPentax *) d;
-        unsigned int i, fs;
-        ExifShort s;
-        ExifLong l;
-        ExifSLong sl;
-        ExifRational r;
-        ExifSRational sr;
-                                                                                
-        if (!n) return;
-                                                                                
-        o_orig = n->order;
-        n->order = o;
-        for (i = 0; i < n->count; i++) {
-                n->entries[i].order = o;
-                fs = exif_format_get_size (n->entries[i].format);
-                switch (n->entries[i].format) {
-                case EXIF_FORMAT_SHORT:
-                        for (i = 0; i < n->entries[i].components; i++) {
-                                s = exif_get_short (n->entries[i].data + (i*fs),                                                    o_orig);
-                                exif_set_short (n->entries[i].data + (i * fs),
-                                                o, s);
-                        }
-                        break;
-                case EXIF_FORMAT_LONG:
-                        for (i = 0; i < n->entries[i].components; i++) {
-                                l = exif_get_long (n->entries[i].data + (i*fs),
-                                                   o_orig);
-                                exif_set_long (n->entries[i].data + (i * fs),
-                                               o, l);
-                        }
-                        break;
-                case EXIF_FORMAT_RATIONAL:
-                        for (i = 0; i < n->entries[i].components; i++) {
-                                r = exif_get_rational (n->entries[i].data +
-                                                       (i * fs), o_orig);
-                                exif_set_rational (n->entries[i].data +
-                                        (i * fs), o, r);
-                        }
-                        break;
-                case EXIF_FORMAT_SLONG:
-                        for (i = 0; i < n->entries[i].components; i++) {
-                                sl = exif_get_slong (n->entries[i].data +
-                                                (i * fs), o_orig);
-                                exif_set_slong (n->entries[i].data +
-                                                (i * fs), o, sl);
-                        }
-                        break;
-                case EXIF_FORMAT_SRATIONAL:
-                        for (i = 0; i < n->entries[i].components; i++) {
-                                sr = exif_get_srational (n->entries[i].data +
-                                                (i * fs), o_orig);
-                                exif_set_srational (n->entries[i].data +
-                                                (i * fs), o, sr);
-                        }
-                        break;
-                case EXIF_FORMAT_UNDEFINED:
-                case EXIF_FORMAT_BYTE:
-                case EXIF_FORMAT_ASCII:
-                default:
-                        /* Nothing here. */
-                        break;
-                }
-        }
+       ExifMnoteDataPentax *n = (ExifMnoteDataPentax *) d;
+       unsigned int i;
+
+       if (!n) return;
+
+       o_orig = n->order;
+       n->order = o;
+       for (i = 0; i < n->count; i++) {
+               n->entries[i].order = o;
+               exif_array_set_byte_order (n->entries[i].format, n->entries[i].data,
+                               n->entries[i].components, o_orig, o);
+       }
 }
 
 ExifMnoteData *