* 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 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
{
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;
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);
}
}
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
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)
{
#endif /* __cplusplus */
#include <libexif/exif-byte-order.h>
+#include <libexif/exif-format.h>
#include <libexif/_stdint.h>
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))
{
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;
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);
}
}
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 *