Mercurial > geeqie.yaz
comparison src/exif.c @ 1010:82fe98d2cfdb
added new raw preview interface for legacy exif
author | nadvornik |
---|---|
date | Fri, 29 Aug 2008 09:59:20 +0000 |
parents | 3096a47232ec |
children | 448d174454e1 |
comparison
equal
deleted
inserted
replaced
1009:dd311dae857a | 1010:82fe98d2cfdb |
---|---|
1156 work = work->next; | 1156 work = work->next; |
1157 exif_item_free(item); | 1157 exif_item_free(item); |
1158 } | 1158 } |
1159 | 1159 |
1160 g_list_free(exif->items); | 1160 g_list_free(exif->items); |
1161 g_free(exif->path); | |
1161 g_free(exif); | 1162 g_free(exif); |
1162 } | 1163 } |
1163 | 1164 |
1164 ExifData *exif_read(gchar *path, gchar *sidecar_path) | 1165 ExifData *exif_read(gchar *path, gchar *sidecar_path) |
1165 { | 1166 { |
1179 g_free(pathl); | 1180 g_free(pathl); |
1180 | 1181 |
1181 exif = g_new0(ExifData, 1); | 1182 exif = g_new0(ExifData, 1); |
1182 exif->items = NULL; | 1183 exif->items = NULL; |
1183 exif->current = NULL; | 1184 exif->current = NULL; |
1185 exif->path = g_strdup(path); | |
1184 | 1186 |
1185 res = exif_jpeg_parse(exif, (guchar *)f, size, ExifKnownMarkersList); | 1187 res = exif_jpeg_parse(exif, (guchar *)f, size, ExifKnownMarkersList); |
1186 if (res == -2) | 1188 if (res == -2) |
1187 { | 1189 { |
1188 res = exif_tiff_parse(exif, (guchar *)f, size, ExifKnownMarkersList); | 1190 res = exif_tiff_parse(exif, (guchar *)f, size, ExifKnownMarkersList); |
1303 { | 1305 { |
1304 val = ((guchar *)data)[0]; | 1306 val = ((guchar *)data)[0]; |
1305 } | 1307 } |
1306 else | 1308 else |
1307 { | 1309 { |
1308 val = (guchar)(((signed gchar *)data)[0]); | 1310 val = (guchar)(((gchar *)data)[0]); |
1309 } | 1311 } |
1310 | 1312 |
1311 result = exif_text_list_find_value(marker->list, (guint)val); | 1313 result = exif_text_list_find_value(marker->list, (guint)val); |
1312 string = g_string_append(string, result); | 1314 string = g_string_append(string, result); |
1313 g_free(result); | 1315 g_free(result); |
1541 { | 1543 { |
1542 return 0; | 1544 return 0; |
1543 } | 1545 } |
1544 | 1546 |
1545 | 1547 |
1548 typedef struct _UnmapData UnmapData; | |
1549 struct _UnmapData | |
1550 { | |
1551 guchar *ptr; | |
1552 guchar *map_data; | |
1553 size_t map_len; | |
1554 }; | |
1555 | |
1556 static GList *exif_unmap_list = 0; | |
1557 | |
1558 guchar *exif_get_preview(ExifData *exif, guint *data_len) | |
1559 { | |
1560 int success; | |
1561 guint offset; | |
1562 const gchar* path; | |
1563 struct stat st; | |
1564 guchar *map_data; | |
1565 size_t map_len; | |
1566 int fd; | |
1567 | |
1568 if (!exif) return NULL; | |
1569 path = exif->path; | |
1570 | |
1571 fd = open(path, O_RDONLY); | |
1572 | |
1573 | |
1574 if (fd == -1) | |
1575 { | |
1576 return 0; | |
1577 } | |
1578 | |
1579 if (fstat(fd, &st) == -1) | |
1580 { | |
1581 close(fd); | |
1582 return 0; | |
1583 } | |
1584 map_len = st.st_size; | |
1585 map_data = (guchar *) mmap(0, map_len, PROT_READ, MAP_PRIVATE, fd, 0); | |
1586 close(fd); | |
1587 | |
1588 if (map_data == MAP_FAILED) | |
1589 { | |
1590 return 0; | |
1591 } | |
1592 | |
1593 if (format_raw_img_exif_offsets(map_data, map_len, &offset, NULL) && offset) | |
1594 { | |
1595 UnmapData *ud; | |
1596 | |
1597 DEBUG_1("%s: offset %lu", path, offset); | |
1598 | |
1599 *data_len = map_len - offset; | |
1600 ud = g_new(UnmapData, 1); | |
1601 ud->ptr = map_data + offset; | |
1602 ud->map_data = map_data; | |
1603 ud->map_len = map_len; | |
1604 | |
1605 exif_unmap_list = g_list_prepend(exif_unmap_list, ud); | |
1606 return ud->ptr; | |
1607 } | |
1608 | |
1609 munmap(map_data, map_len); | |
1610 return NULL; | |
1611 | |
1612 } | |
1613 | |
1614 void exif_free_preview(guchar *buf) | |
1615 { | |
1616 GList *work = exif_unmap_list; | |
1617 | |
1618 while (work) | |
1619 { | |
1620 UnmapData *ud = (UnmapData *)work->data; | |
1621 if (ud->ptr == buf) | |
1622 { | |
1623 exif_unmap_list = g_list_remove_link(exif_unmap_list, work); | |
1624 g_free(ud); | |
1625 return; | |
1626 } | |
1627 } | |
1628 g_assert_not_reached(); | |
1629 } | |
1630 | |
1546 | 1631 |
1547 #endif | 1632 #endif |
1548 /* not HAVE_EXIV2 */ | 1633 /* not HAVE_EXIV2 */ |