Skip to content

Commit 46e1970

Browse files
authored
patch to build with exiv 0.28 (#178)
1 parent 855a547 commit 46e1970

1 file changed

Lines changed: 141 additions & 0 deletions

File tree

extensions/exiv2_tools/exiv2-utils.cpp

Lines changed: 141 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -740,7 +740,11 @@ get_exif_default_category (const Exiv2::Exifdatum &md)
740740

741741

742742
static void
743+
#if EXIV2_TEST_VERSION(0,28,0)
744+
exiv2_read_metadata (Exiv2::Image::UniquePtr image,
745+
#else
743746
exiv2_read_metadata (Exiv2::Image::AutoPtr image,
747+
#endif
744748
GFileInfo *info,
745749
gboolean update_general_attributes)
746750
{
@@ -882,7 +886,11 @@ exiv2_read_metadata_from_file (GFile *file,
882886
return FALSE;
883887
}
884888

889+
#if EXIV2_TEST_VERSION(0,28,0)
890+
Exiv2::Image::UniquePtr image = Exiv2::ImageFactory::open(path);
891+
#else
885892
Exiv2::Image::AutoPtr image = Exiv2::ImageFactory::open(path);
893+
#endif
886894
g_free (path);
887895

888896
if (image.get() == 0) {
@@ -892,9 +900,17 @@ exiv2_read_metadata_from_file (GFile *file,
892900
}
893901
// Set the log level to only show errors (and suppress warnings, informational and debug messages)
894902
Exiv2::LogMsg::setLevel(Exiv2::LogMsg::error);
903+
#if EXIV2_TEST_VERSION(0,28,0)
904+
exiv2_read_metadata (std::move(image), info, update_general_attributes);
905+
#else
895906
exiv2_read_metadata (image, info, update_general_attributes);
907+
#endif
896908
}
909+
#if EXIV2_TEST_VERSION(0,28,0)
910+
catch (Exiv2::Error& e) {
911+
#else
897912
catch (Exiv2::AnyError& e) {
913+
#endif
898914
if (error != NULL)
899915
*error = g_error_new_literal (G_IO_ERROR, G_IO_ERROR_FAILED, e.what());
900916
return FALSE;
@@ -913,17 +929,29 @@ exiv2_read_metadata_from_buffer (void *buffer,
913929
GError **error)
914930
{
915931
try {
932+
#if EXIV2_TEST_VERSION(0,28,0)
933+
Exiv2::Image::UniquePtr image = Exiv2::ImageFactory::open ((Exiv2::byte*) buffer, buffer_size);
934+
#else
916935
Exiv2::Image::AutoPtr image = Exiv2::ImageFactory::open ((Exiv2::byte*) buffer, buffer_size);
936+
#endif
917937

918938
if (image.get() == 0) {
919939
if (error != NULL)
920940
*error = g_error_new_literal (G_IO_ERROR, G_IO_ERROR_FAILED, _("Invalid file format"));
921941
return FALSE;
922942
}
923943

944+
#if EXIV2_TEST_VERSION(0,28,0)
945+
exiv2_read_metadata (std::move(image), info, update_general_attributes);
946+
#else
924947
exiv2_read_metadata (image, info, update_general_attributes);
948+
#endif
925949
}
950+
#if EXIV2_TEST_VERSION(0,28,0)
951+
catch (Exiv2::Error& e) {
952+
#else
926953
catch (Exiv2::AnyError& e) {
954+
#endif
927955
if (error != NULL)
928956
*error = g_error_new_literal (G_IO_ERROR, G_IO_ERROR_FAILED, e.what());
929957
return FALSE;
@@ -972,7 +1000,11 @@ exiv2_read_sidecar (GFile *file,
9721000
g_free (path);
9731001

9741002
std::string xmpPacket;
1003+
#if EXIV2_TEST_VERSION(0,28,0)
1004+
xmpPacket.assign(reinterpret_cast<char*>(buf.data()), buf.size());
1005+
#else
9751006
xmpPacket.assign(reinterpret_cast<char*>(buf.pData_), buf.size_);
1007+
#endif
9761008
Exiv2::XmpData xmpData;
9771009

9781010
if (0 != Exiv2::XmpParser::decode(xmpData, xmpPacket))
@@ -1018,7 +1050,11 @@ exiv2_read_sidecar (GFile *file,
10181050

10191051
set_attributes_from_tagsets (info, update_general_attributes);
10201052
}
1053+
#if EXIV2_TEST_VERSION(0,28,0)
1054+
catch (Exiv2::Error& e) {
1055+
#else
10211056
catch (Exiv2::AnyError& e) {
1057+
#endif
10221058
std::cerr << "Caught Exiv2 exception '" << e << "'\n";
10231059
return FALSE;
10241060
}
@@ -1118,7 +1154,11 @@ dump_exif_data (Exiv2::ExifData &exifData,
11181154

11191155

11201156
static Exiv2::DataBuf
1157+
#if EXIV2_TEST_VERSION(0,28,0)
1158+
exiv2_write_metadata_private (Exiv2::Image::UniquePtr image,
1159+
#else
11211160
exiv2_write_metadata_private (Exiv2::Image::AutoPtr image,
1161+
#endif
11221162
GFileInfo *info,
11231163
GthImage *image_data)
11241164
{
@@ -1155,13 +1195,21 @@ exiv2_write_metadata_private (Exiv2::Image::AutoPtr image,
11551195
const char *value_type = gth_main_get_metadata_type (metadatum, attributes[i]);
11561196

11571197
if ((raw_value != NULL) && (strcmp (raw_value, "") != 0) && (value_type != NULL)) {
1198+
#if EXIV2_TEST_VERSION(0,28,0)
1199+
Exiv2::Value::UniquePtr value = Exiv2::Value::create (Exiv2::TypeInfo::typeId (value_type));
1200+
#else
11581201
Exiv2::Value::AutoPtr value = Exiv2::Value::create (Exiv2::TypeInfo::typeId (value_type));
1202+
#endif
11591203
value->read (raw_value);
11601204
Exiv2::ExifKey exif_key(key);
11611205
ed.add (exif_key, value.get());
11621206
}
11631207
}
1208+
#if EXIV2_TEST_VERSION(0,28,0)
1209+
catch (Exiv2::Error& e) {
1210+
#else
11641211
catch (Exiv2::AnyError& e) {
1212+
#endif
11651213
/* we don't care about invalid key errors */
11661214
g_warning ("%s", e.what());
11671215
}
@@ -1277,7 +1325,11 @@ exiv2_write_metadata_private (Exiv2::Image::AutoPtr image,
12771325
value_type = gth_main_get_metadata_type (metadatum, attributes[i]);
12781326
if (value_type != NULL) {
12791327
/* See the exif data code above for an explanation. */
1328+
#if EXIV2_TEST_VERSION(0,28,0)
1329+
Exiv2::Value::UniquePtr value = Exiv2::Value::create (Exiv2::TypeInfo::typeId (value_type));
1330+
#else
12801331
Exiv2::Value::AutoPtr value = Exiv2::Value::create (Exiv2::TypeInfo::typeId (value_type));
1332+
#endif
12811333
Exiv2::IptcKey iptc_key(key);
12821334

12831335
const char *raw_value;
@@ -1303,7 +1355,11 @@ exiv2_write_metadata_private (Exiv2::Image::AutoPtr image,
13031355
}
13041356
}
13051357
}
1358+
#if EXIV2_TEST_VERSION(0,28,0)
1359+
catch (Exiv2::Error& e) {
1360+
#else
13061361
catch (Exiv2::AnyError& e) {
1362+
#endif
13071363
/* we don't care about invalid key errors */
13081364
g_warning ("%s", e.what());
13091365
}
@@ -1327,7 +1383,11 @@ exiv2_write_metadata_private (Exiv2::Image::AutoPtr image,
13271383
value_type = gth_main_get_metadata_type (metadatum, attributes[i]);
13281384
if (value_type != NULL) {
13291385
/* See the exif data code above for an explanation. */
1386+
#if EXIV2_TEST_VERSION(0,28,0)
1387+
Exiv2::Value::UniquePtr value = Exiv2::Value::create (Exiv2::TypeInfo::typeId (value_type));
1388+
#else
13301389
Exiv2::Value::AutoPtr value = Exiv2::Value::create (Exiv2::TypeInfo::typeId (value_type));
1390+
#endif
13311391
Exiv2::XmpKey xmp_key(key);
13321392

13331393
const char *raw_value;
@@ -1353,7 +1413,11 @@ exiv2_write_metadata_private (Exiv2::Image::AutoPtr image,
13531413
}
13541414
}
13551415
}
1416+
#if EXIV2_TEST_VERSION(0,28,0)
1417+
catch (Exiv2::Error& e) {
1418+
#else
13561419
catch (Exiv2::AnyError& e) {
1420+
#endif
13571421
/* we don't care about invalid key errors */
13581422
g_warning ("%s", e.what());
13591423
}
@@ -1369,7 +1433,11 @@ exiv2_write_metadata_private (Exiv2::Image::AutoPtr image,
13691433
image->setXmpData(xd);
13701434
image->writeMetadata();
13711435
}
1436+
#if EXIV2_TEST_VERSION(0,28,0)
1437+
catch (Exiv2::Error& e) {
1438+
#else
13721439
catch (Exiv2::AnyError& e) {
1440+
#endif
13731441
g_warning ("%s", e.what());
13741442
}
13751443

@@ -1396,16 +1464,33 @@ exiv2_write_metadata (GthImageSaveData *data)
13961464
{
13971465
if (exiv2_supports_writes (data->mime_type) && (data->file_data != NULL)) {
13981466
try {
1467+
#if EXIV2_TEST_VERSION(0,28,0)
1468+
Exiv2::Image::UniquePtr image = Exiv2::ImageFactory::open ((Exiv2::byte*) data->buffer, data->buffer_size);
1469+
#else
13991470
Exiv2::Image::AutoPtr image = Exiv2::ImageFactory::open ((Exiv2::byte*) data->buffer, data->buffer_size);
1471+
#endif
14001472
g_assert (image.get() != 0);
14011473

1474+
#if EXIV2_TEST_VERSION(0,28,0)
1475+
Exiv2::DataBuf buf = exiv2_write_metadata_private (std::move(image), data->file_data->info, data->image);
1476+
#else
14021477
Exiv2::DataBuf buf = exiv2_write_metadata_private (image, data->file_data->info, data->image);
1478+
#endif
14031479

14041480
g_free (data->buffer);
1481+
#if EXIV2_TEST_VERSION(0,28,0)
1482+
data->buffer = g_memdup (buf.data(), buf.size());
1483+
data->buffer_size = buf.size();
1484+
#else
14051485
data->buffer = g_memdup (buf.pData_, buf.size_);
14061486
data->buffer_size = buf.size_;
1487+
#endif
14071488
}
1489+
#if EXIV2_TEST_VERSION(0,28,0)
1490+
catch (Exiv2::Error& e) {
1491+
#else
14081492
catch (Exiv2::AnyError& e) {
1493+
#endif
14091494
if (data->error != NULL)
14101495
*data->error = g_error_new_literal (G_IO_ERROR, G_IO_ERROR_FAILED, e.what());
14111496
g_warning ("%s\n", e.what());
@@ -1426,16 +1511,33 @@ exiv2_write_metadata_to_buffer (void **buffer,
14261511
GError **error)
14271512
{
14281513
try {
1514+
#if EXIV2_TEST_VERSION(0,28,0)
1515+
Exiv2::Image::UniquePtr image = Exiv2::ImageFactory::open ((Exiv2::byte*) *buffer, *buffer_size);
1516+
#else
14291517
Exiv2::Image::AutoPtr image = Exiv2::ImageFactory::open ((Exiv2::byte*) *buffer, *buffer_size);
1518+
#endif
14301519
g_assert (image.get() != 0);
14311520

1521+
#if EXIV2_TEST_VERSION(0,28,0)
1522+
Exiv2::DataBuf buf = exiv2_write_metadata_private (std::move(image), info, image_data);
1523+
#else
14321524
Exiv2::DataBuf buf = exiv2_write_metadata_private (image, info, image_data);
1525+
#endif
14331526

14341527
g_free (*buffer);
1528+
#if EXIV2_TEST_VERSION(0,28,0)
1529+
*buffer = g_memdup (buf.data(), buf.size());
1530+
*buffer_size = buf.size();
1531+
#else
14351532
*buffer = g_memdup (buf.pData_, buf.size_);
14361533
*buffer_size = buf.size_;
1534+
#endif
14371535
}
1536+
#if EXIV2_TEST_VERSION(0,28,0)
1537+
catch (Exiv2::Error& e) {
1538+
#else
14381539
catch (Exiv2::AnyError& e) {
1540+
#endif
14391541
if (error != NULL)
14401542
*error = g_error_new_literal (G_IO_ERROR, G_IO_ERROR_FAILED, e.what());
14411543
return FALSE;
@@ -1452,7 +1554,11 @@ exiv2_clear_metadata (void **buffer,
14521554
GError **error)
14531555
{
14541556
try {
1557+
#if EXIV2_TEST_VERSION(0,28,0)
1558+
Exiv2::Image::UniquePtr image = Exiv2::ImageFactory::open ((Exiv2::byte*) *buffer, *buffer_size);
1559+
#else
14551560
Exiv2::Image::AutoPtr image = Exiv2::ImageFactory::open ((Exiv2::byte*) *buffer, *buffer_size);
1561+
#endif
14561562

14571563
if (image.get() == 0) {
14581564
if (error != NULL)
@@ -1464,7 +1570,11 @@ exiv2_clear_metadata (void **buffer,
14641570
image->clearMetadata();
14651571
image->writeMetadata();
14661572
}
1573+
#if EXIV2_TEST_VERSION(0,28,0)
1574+
catch (Exiv2::Error& e) {
1575+
#else
14671576
catch (Exiv2::AnyError& e) {
1577+
#endif
14681578
g_warning ("%s", e.what());
14691579
}
14701580

@@ -1473,10 +1583,19 @@ exiv2_clear_metadata (void **buffer,
14731583
Exiv2::DataBuf buf = io.read(io.size());
14741584

14751585
g_free (*buffer);
1586+
#if EXIV2_TEST_VERSION(0,28,0)
1587+
*buffer = g_memdup (buf.data(), buf.size());
1588+
*buffer_size = buf.size();
1589+
#else
14761590
*buffer = g_memdup (buf.pData_, buf.size_);
14771591
*buffer_size = buf.size_;
1592+
#endif
14781593
}
1594+
#if EXIV2_TEST_VERSION(0,28,0)
1595+
catch (Exiv2::Error& e) {
1596+
#else
14791597
catch (Exiv2::AnyError& e) {
1598+
#endif
14801599
if (error != NULL)
14811600
*error = g_error_new_literal (G_IO_ERROR, G_IO_ERROR_FAILED, e.what());
14821601
return FALSE;
@@ -1509,26 +1628,44 @@ exiv2_generate_thumbnail (const char *uri,
15091628
if (path == NULL)
15101629
return NULL;
15111630

1631+
#if EXIV2_TEST_VERSION(0,28,0)
1632+
Exiv2::Image::UniquePtr image = Exiv2::ImageFactory::open (path);
1633+
#else
15121634
Exiv2::Image::AutoPtr image = Exiv2::ImageFactory::open (path);
1635+
#endif
15131636
image->readMetadata ();
15141637
Exiv2::ExifThumbC exifThumb (image->exifData ());
15151638
Exiv2::DataBuf thumb = exifThumb.copy ();
15161639

15171640
g_free (path);
15181641

1642+
#if EXIV2_TEST_VERSION(0,28,0)
1643+
if (thumb.data() == NULL)
1644+
#else
15191645
if (thumb.pData_ == NULL)
1646+
#endif
15201647
return NULL;
15211648

15221649
Exiv2::ExifData &ed = image->exifData();
15231650

1651+
#if EXIV2_TEST_VERSION(0,28,0)
1652+
long orientation = (ed["Exif.Image.Orientation"].count() > 0) ? ed["Exif.Image.Orientation"].toUint32() : 1;
1653+
long image_width = (ed["Exif.Photo.PixelXDimension"].count() > 0) ? ed["Exif.Photo.PixelXDimension"].toUint32() : -1;
1654+
long image_height = (ed["Exif.Photo.PixelYDimension"].count() > 0) ? ed["Exif.Photo.PixelYDimension"].toUint32() : -1;
1655+
#else
15241656
long orientation = (ed["Exif.Image.Orientation"].count() > 0) ? ed["Exif.Image.Orientation"].toLong() : 1;
15251657
long image_width = (ed["Exif.Photo.PixelXDimension"].count() > 0) ? ed["Exif.Photo.PixelXDimension"].toLong() : -1;
15261658
long image_height = (ed["Exif.Photo.PixelYDimension"].count() > 0) ? ed["Exif.Photo.PixelYDimension"].toLong() : -1;
1659+
#endif
15271660

15281661
if ((orientation != 1) || (image_width <= 0) || (image_height <= 0))
15291662
return NULL;
15301663

1664+
#if EXIV2_TEST_VERSION(0,28,0)
1665+
GInputStream *stream = g_memory_input_stream_new_from_data (thumb.data(), thumb.size(), NULL);
1666+
#else
15311667
GInputStream *stream = g_memory_input_stream_new_from_data (thumb.pData_, thumb.size_, NULL);
1668+
#endif
15321669
pixbuf = gdk_pixbuf_new_from_stream (stream, NULL, NULL);
15331670
g_object_unref (stream);
15341671

@@ -1582,7 +1719,11 @@ exiv2_generate_thumbnail (const char *uri,
15821719
gdk_pixbuf_set_option (pixbuf, "orientation", orientation_s);
15831720
g_free (orientation_s);
15841721
}
1722+
#if EXIV2_TEST_VERSION(0,28,0)
1723+
catch (Exiv2::Error& e) {
1724+
#else
15851725
catch (Exiv2::AnyError& e) {
1726+
#endif
15861727
}
15871728

15881729
return pixbuf;

0 commit comments

Comments
 (0)