EXIF library (libexif) Internals 0.6.26
mnote-apple-entry.c
Go to the documentation of this file.
1/* mnote-apple-entry.c
2 *
3 * Copyright (c) 2018 zhanwang-sky <zhanwang_sky@163.com>
4 *
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.
9 *
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.
14 *
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., 51 Franklin Street, Fifth Floor,
18 * Boston, MA 02110-1301 USA.
19 *
20 * SPDX-License-Identifier: LGPL-2.0-or-later
21 */
22
23#include <config.h>
24#include "mnote-apple-entry.h"
25
26#include <stdio.h>
27#include <stdlib.h>
28#include <string.h>
29
30#include <libexif/exif-entry.h>
31#include <libexif/exif-format.h>
32#include <libexif/exif-utils.h>
33#include <libexif/i18n.h>
34
35char *
36mnote_apple_entry_get_value(MnoteAppleEntry *entry, char *v, unsigned int maxlen) {
37 ExifLong vl;
38 ExifSLong vsl;
39 ExifShort vs;
40 ExifSShort vss;
41 ExifRational vr;
42 ExifSRational vsr;
43 size_t size;
44 unsigned char *data;
45
46 if (!entry)
47 return NULL;
48 if (maxlen < 1)
49 return NULL;
50
51 memset(v, 0, maxlen);
52 maxlen--;
53
54 size = entry->size;
55 data = entry->data;
56 switch (entry->tag) {
58 if (size < 4) return NULL;
59 if (entry->format != EXIF_FORMAT_SLONG) return NULL;
60 if (entry->components != 1) return NULL;
61
62 vsl = exif_get_slong(data, entry->order);
63 snprintf(v, maxlen, "%d", vsl);
64 break;
68 if (entry->format != EXIF_FORMAT_ASCII) return NULL;
69 strncpy (v, (char *) data, MIN (maxlen-1, size));
70 v[MIN (maxlen-1, size)] = 0;
71 break;
72 default:
73 switch (entry->format) {
75 strncpy (v, (char *)data, MIN(maxlen, size));
76 break;
77 case EXIF_FORMAT_SHORT: {
78 size_t i, len = 0;
79
80 for(i=0; i<entry->components; i++) {
81 if (size < 2)
82 break;
83 if (len > maxlen)
84 break;
85 vs = exif_get_short (data, entry->order);
86 snprintf (v+len, maxlen-len, "%hu ", vs);
87 len = strlen(v);
88 data += 2;
89 size -= 2;
90 }
91 }
92 break;
93 case EXIF_FORMAT_SSHORT: {
94 size_t i, len = 0;
95 for(i=0; i<entry->components; i++) {
96 if (size < 2)
97 break;
98 if (len > maxlen)
99 break;
100 vss = exif_get_sshort (data, entry->order);
101 snprintf (v+len, maxlen-len, "%hi ", vss);
102 len = strlen(v);
103 data += 2;
104 size -= 2;
105 }
106 }
107 break;
108 case EXIF_FORMAT_LONG: {
109 size_t i, len = 0;
110 for(i=0; i<entry->components; i++) {
111 if (size < 4)
112 break;
113 if (len > maxlen)
114 break;
115 vl = exif_get_long (data, entry->order);
116 snprintf (v+len, maxlen-len, "%lu ", (long unsigned) vl);
117 len = strlen(v);
118 data += 4;
119 size -= 4;
120 }
121 }
122 break;
123 case EXIF_FORMAT_SLONG: {
124 size_t i, len = 0;
125 for(i=0; i<entry->components; i++) {
126 if (size < 4)
127 break;
128 if (len > maxlen)
129 break;
130 vsl = exif_get_slong (data, entry->order);
131 snprintf (v+len, maxlen-len, "%li ", (long int) vsl);
132 len = strlen(v);
133 data += 4;
134 size -= 4;
135 }
136 }
137 break;
140 if (entry->components < 1) return NULL; /* FIXME: could handle more than 1 too */
141 vr = exif_get_rational (data, entry->order);
142 if (!vr.denominator) break;
143 snprintf (v, maxlen, "%2.4f", (double) vr.numerator /
144 vr.denominator);
145 break;
148 if (entry->components < 1) return NULL; /* FIXME: could handle more than 1 too */
149 vsr = exif_get_srational (data, entry->order);
150 if (!vsr.denominator) break;
151 snprintf (v, maxlen, "%2.4f", (double) vsr.numerator /
152 vsr.denominator);
153 break;
155 default:
156 snprintf (v, maxlen, _("%i bytes unknown data"), entry->size);
157 break;
158 }
159 break;
160 }
161
162 return v;
163}
Handling EXIF entries.
unsigned char exif_format_get_size(ExifFormat format)
Return the raw size of the given EXIF data type.
Definition exif-format.c:68
unsigned char size
Definition exif-format.c:37
Handling native EXIF data types.
@ EXIF_FORMAT_SLONG
Definition exif-format.h:43
@ EXIF_FORMAT_RATIONAL
Definition exif-format.h:39
@ EXIF_FORMAT_SRATIONAL
Definition exif-format.h:44
@ EXIF_FORMAT_LONG
Definition exif-format.h:38
@ EXIF_FORMAT_UNDEFINED
Definition exif-format.h:41
@ EXIF_FORMAT_SHORT
Definition exif-format.h:37
@ EXIF_FORMAT_SSHORT
Definition exif-format.h:42
@ EXIF_FORMAT_ASCII
Definition exif-format.h:36
ExifRational exif_get_rational(const unsigned char *buf, ExifByteOrder order)
Retrieve an ExifRational value from memory.
Definition exif-utils.c:190
ExifLong exif_get_long(const unsigned char *buf, ExifByteOrder order)
Retrieve an ExifLong value from memory.
Definition exif-utils.c:167
ExifShort exif_get_short(const unsigned char *buf, ExifByteOrder order)
Retrieve an ExifShort value from memory.
Definition exif-utils.c:104
ExifSLong exif_get_slong(const unsigned char *b, ExifByteOrder order)
Retrieve an ExifSLong value from memory.
Definition exif-utils.c:132
ExifSShort exif_get_sshort(const unsigned char *buf, ExifByteOrder order)
Retrieve an ExifSShort value from memory.
Definition exif-utils.c:89
ExifSRational exif_get_srational(const unsigned char *buf, ExifByteOrder order)
Retrieve an ExifSRational value from memory.
Definition exif-utils.c:179
EXIF data manipulation functions and types.
uint32_t ExifLong
EXIF Unsigned Long data type.
Definition exif-utils.h:56
int32_t ExifSLong
EXIF Signed Long data type.
Definition exif-utils.h:59
uint16_t ExifShort
EXIF Unsigned Short data type.
Definition exif-utils.h:50
#define MIN(a, b)
Definition exif-utils.h:182
int16_t ExifSShort
EXIF Signed Short data type.
Definition exif-utils.h:53
#define _(String)
Definition i18n.h:50
char * mnote_apple_entry_get_value(MnoteAppleEntry *entry, char *v, unsigned int maxlen)
@ MNOTE_APPLE_TAG_MEDIA_GROUP_UUID
@ MNOTE_APPLE_TAG_IMAGE_UNIQUE_ID
@ MNOTE_APPLE_TAG_HDR
@ MNOTE_APPLE_TAG_BURST_UUID
EXIF Unsigned Rational data type.
Definition exif-utils.h:62
ExifLong denominator
Definition exif-utils.h:62
ExifLong numerator
Definition exif-utils.h:62
EXIF Signed Rational data type.
Definition exif-utils.h:67
ExifSLong numerator
Definition exif-utils.h:67
ExifSLong denominator
Definition exif-utils.h:67
unsigned char * data
unsigned long components
ExifByteOrder order

libexif Generated by doxygen