3 * Copyright © 2001 Lutz Müller <lutz@users.sourceforge.net>
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2 of the License, or (at your option) any later version.
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the
17 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 * Boston, MA 02111-1307, USA.
23 #include <libexif/exif-utils.h>
25 typedef signed short ExifSShort;
28 exif_get_sshort (const unsigned char *buf, ExifByteOrder order)
32 case EXIF_BYTE_ORDER_MOTOROLA:
33 return ((buf[0] << 8) | buf[1]);
34 case EXIF_BYTE_ORDER_INTEL:
35 return ((buf[1] << 8) | buf[0]);
38 /* Won't be reached */
43 exif_get_short (const unsigned char *buf, ExifByteOrder order)
45 return (exif_get_sshort (buf, order) & 0xffff);
49 exif_set_short (unsigned char *b, ExifByteOrder order, ExifShort value)
53 case EXIF_BYTE_ORDER_MOTOROLA:
54 b[0] = (unsigned char) (value >> 8);
55 b[1] = (unsigned char) value;
57 case EXIF_BYTE_ORDER_INTEL:
58 b[0] = (unsigned char) value;
59 b[1] = (unsigned char) (value >> 8);
65 exif_get_slong (const unsigned char *b, ExifByteOrder order)
69 case EXIF_BYTE_ORDER_MOTOROLA:
70 return ((b[0] << 24) | (b[1] << 16) | (b[2] << 8) | b[3]);
71 case EXIF_BYTE_ORDER_INTEL:
72 return ((b[3] << 24) | (b[2] << 16) | (b[1] << 8) | b[0]);
75 /* Won't be reached */
80 exif_set_slong (unsigned char *b, ExifByteOrder order, ExifSLong value)
84 case EXIF_BYTE_ORDER_MOTOROLA:
85 b[0] = (unsigned char) (value >> 24);
86 b[1] = (unsigned char) (value >> 16);
87 b[2] = (unsigned char) (value >> 8);
88 b[3] = (unsigned char) value;
90 case EXIF_BYTE_ORDER_INTEL:
91 b[3] = (unsigned char) (value >> 24);
92 b[2] = (unsigned char) (value >> 16);
93 b[1] = (unsigned char) (value >> 8);
94 b[0] = (unsigned char) value;
100 exif_get_long (const unsigned char *buf, ExifByteOrder order)
102 return (exif_get_slong (buf, order) & 0xffffffff);
106 exif_set_long (unsigned char *b, ExifByteOrder order, ExifLong value)
108 exif_set_slong (b, order, value);
112 exif_get_srational (const unsigned char *buf, ExifByteOrder order)
116 r.numerator = buf ? exif_get_slong (buf, order) : 0;
117 r.denominator = buf ? exif_get_slong (buf + 4, order) : 0;
123 exif_get_rational (const unsigned char *buf, ExifByteOrder order)
127 r.numerator = buf ? exif_get_long (buf, order) : 0;
128 r.denominator = buf ? exif_get_long (buf + 4, order) : 0;
134 exif_set_rational (unsigned char *buf, ExifByteOrder order,
138 exif_set_long (buf, order, value.numerator);
139 exif_set_long (buf + 4, order, value.denominator);
143 exif_set_srational (unsigned char *buf, ExifByteOrder order,
147 exif_set_slong (buf, order, value.numerator);
148 exif_set_slong (buf + 4, order, value.denominator);