From 3b75be0095ebbd703c43058f533f3e20a766f9cb Mon Sep 17 00:00:00 2001 From: Dan Fandrich Date: Tue, 18 Nov 2008 12:42:13 -0800 Subject: [PATCH] contrib/examples/*: Added a couple of simple example programs to show how to use libexif. One was written by Naysawn Naderi and the other one I wrote. Closes bug #1246824. --- ChangeLog | 3 + configure.ac | 1 + contrib/Makefile.am | 2 + contrib/examples/Makefile.am | 11 ++ contrib/examples/cam_features.c | 231 ++++++++++++++++++++++++++++++++++++++++ contrib/examples/thumbnail.c | 66 ++++++++++++ 6 files changed, 314 insertions(+) create mode 100644 contrib/examples/Makefile.am create mode 100644 contrib/examples/cam_features.c create mode 100644 contrib/examples/thumbnail.c diff --git a/ChangeLog b/ChangeLog index 0abb3ff..ea33a2c 100644 --- a/ChangeLog +++ b/ChangeLog @@ -4,6 +4,9 @@ to be more thread safe * po/nl.po: Updated Dutch translation by Erwin Poeze * po/pl.po: Updated Polish translation by Jakub Bogusz + * contrib/examples/*: Added a couple of simple example programs + to show how to use libexif. One was written by Naysawn Naderi + and the other one I wrote. Closes bug #1246824. 2008-11-06 Dan Fandrich diff --git a/configure.ac b/configure.ac index 3e71176..e6309de 100644 --- a/configure.ac +++ b/configure.ac @@ -204,6 +204,7 @@ AC_CONFIG_FILES([ po/Makefile.in libexif-uninstalled.pc binary/Makefile contrib/Makefile + contrib/examples/Makefile ]) AC_OUTPUT diff --git a/contrib/Makefile.am b/contrib/Makefile.am index 89e0d9f..7965c42 100644 --- a/contrib/Makefile.am +++ b/contrib/Makefile.am @@ -1,3 +1,5 @@ +SUBDIRS = examples + # The c++ and aolserver contrib directories are out of date and are # are pointless to distribute in the offical source release. diff --git a/contrib/examples/Makefile.am b/contrib/examples/Makefile.am new file mode 100644 index 0000000..dac4e0c --- /dev/null +++ b/contrib/examples/Makefile.am @@ -0,0 +1,11 @@ +# Simple example programs +check_PROGRAMS = thumbnail + +# Example programs with dependencies other than plain libexif +COMPLICATED_EXAMPLES = cam_features.c + +# Build just the simple examples as a sanity check, but include them all in +# the source archive + +EXTRA_DIST = $(COMPLICATED_EXAMPLES) +LDADD = $(top_builddir)/libexif/libexif.la diff --git a/contrib/examples/cam_features.c b/contrib/examples/cam_features.c new file mode 100644 index 0000000..0ca014d --- /dev/null +++ b/contrib/examples/cam_features.c @@ -0,0 +1,231 @@ +/*************************************************************************** + * cam_features.c + * + * Wed Jul 27 11:25:09 2005 + * Copyright 2005 User: Naysawn Naderi + * Email: ndn at xiphos dot ca + ****************************************************************************/ + +#include +#include +#include +#include +#include +#include +#include +#include + + +//EXIF includes +#include "config.h" +#include "libjpeg/jpeg-data.h" + +#include "libexif/exif-data.h" +#include "libexif/exif-ifd.h" +#include "libexif/exif-loader.h" + +int createEXIF(dc1394featureset_t *xFeatures, ExifData ** pParentEd); + + + +int main(int argc, char *argv[]) +{ dc1394camera_t *pCamera, **pCameras=NULL; + int iNumCameras; + dc1394featureset_t xFeatures; + int i; + int err=dc1394_find_cameras(&pCameras, &iNumCameras); + + //EXIF STUFF + char cJpegOutputname[] = "foobar2.jpg"; + JPEGData *pData; + //float fOnefloat; + ExifData * pEd; + + + if (err!=DC1394_SUCCESS) { + fprintf( stderr, "Unable to look for cameras\n\n" + "Please check \n" + " - if the kernel modules `ieee1394',`raw1394' and `ohci1394' are loaded \n" + " - if you have read/write access to /dev/raw1394\n\n"); + exit(1); + } + + + /*----------------------------------------------------------------------- + * Initialize the camera + *-----------------------------------------------------------------------*/ + if (iNumCameras<1) { + fprintf(stderr, "no cameras found :(\n"); + exit(1); + } + pCamera=pCameras[0]; + for (i=1;ifeature[DC1394_FEATURE_WHITE_BALANCE - DC1394_FEATURE_MIN].auto_active; + + ExifSRational xR = {xFeatures->feature[DC1394_FEATURE_BRIGHTNESS - DC1394_FEATURE_MIN].value, xFeatures->feature[DC1394_FEATURE_BRIGHTNESS - DC1394_FEATURE_MIN].max};; + JPEGData *pData; + +/* + if (argc <= 1) { + printf ("You need to specify a file!\n"); + return (1); + } + + data = jpeg_data_new_from_file ("foobar.jpg"); + if (!data) { + printf ("Could not load '%s'!\n", "foobar.jpg"); + return (1); + } +*/ + printf ("Creating EXIF data...\n"); + pEd = exif_data_new (); + + /* + + Things to tag: + + EXIF_TAG_MAKE = 0x010f, + EXIF_TAG_MODEL = 0x0110, + EXIF_TAG_EXPOSURE_TIME = 0x829a, + EXIF_TAG_BRIGHTNESS_VALUE = 0x9203, + EXIF_TAG_WHITE_BALANCE = 0xa403, + EXIF_TAG_GAIN_CONTROL = 0xa407, + EXIF_TAG_CONTRAST = 0xa408, + EXIF_TAG_SATURATION = 0xa409, + EXIF_TAG_SHARPNESS = 0xa40a, + EXIF printf ("Creating EXIF data...\n"); + pEd = exif_data_new (); +/_TAG_USER_COMMENT + */ + +/* + printf ("Creating EXIF entry...\n"); + pE = exif_entry_new (); + exif_content_add_entry (pEd->ifd[EXIF_IFD_0], pE); + exif_entry_initialize (pE, EXIF_TAG_EXIF_VERSION); + //exif_entry_unref (e); +*/ + +/* printf("Creating EXIF Entry with a value\n"); + + pE = exif_entry_new (); + exif_content_add_entry (pEd->ifd[EXIF_IFD_0], pE); + exif_entry_initialize (pE, EXIF_TAG_SHUTTER_SPEED_VALUE); + exif_set_srational (pE->data, exif_data_get_byte_order (pEd), xR); + //exif_entry_unref (pE); +*/ + + printf ("Adding a Make reference\n"); + pE = exif_entry_new (); + exif_content_add_entry (pEd->ifd[EXIF_IFD_0], pE); + exif_entry_initialize (pE, EXIF_TAG_MAKE); + pE->data="AVT"; + exif_entry_unref (pE); + + printf ("Adding a Model reference\n"); + pE = exif_entry_new (); + exif_content_add_entry (pEd->ifd[EXIF_IFD_0], pE); + exif_entry_initialize (pE, EXIF_TAG_MODEL); + pE->data="510c"; + exif_entry_unref (pE); + + printf ("Adding a Tag to reference # samples per pixel\n"); + pE = exif_entry_new (); + exif_content_add_entry (pEd->ifd[EXIF_IFD_0], pE); + exif_entry_initialize (pE, EXIF_TAG_SAMPLES_PER_PIXEL); //by default is 3 + exif_entry_unref (pE); + + printf ("Adding a White Balance Reference\n"); + pE = exif_entry_new (); + exif_content_add_entry (pEd->ifd[EXIF_IFD_0], pE); + exif_entry_initialize (pE, EXIF_TAG_WHITE_BALANCE); + exif_set_short(pE->data, exif_data_get_byte_order (pEd), i); //0=auto white balance, 1 = manual white balance + exif_entry_unref (pE); + + //need to create logic according to the value of the sharpness + printf ("Adding a Sharpness Reference\n"); + pE = exif_entry_new (); + exif_content_add_entry (pEd->ifd[EXIF_IFD_0], pE); + exif_entry_initialize (pE, EXIF_TAG_SHARPNESS); + exif_set_short(pE->data, exif_data_get_byte_order (pEd), 0); + exif_entry_unref (pE); + + + + + printf ("Adding a Brightness reference\n"); + + //try to get brightness + //printf("Float Value: %i\n",xFeatures->feature[DC1394_FEATURE_BRIGHTNESS - DC1394_FEATURE_MIN].value); + + pE = exif_entry_new (); + exif_content_add_entry (pEd->ifd[EXIF_IFD_0], pE); + exif_entry_initialize (pE, EXIF_TAG_BRIGHTNESS_VALUE); + exif_set_srational (pE->data, exif_data_get_byte_order (pEd), xR); + + + //exif_data_dump (ed); + //exif_data_dump (pEd); + *pParentEd = pEd; + printf("Done!\n"); + + + //write the Exif data to a jpeg file +/* + pData = jpeg_data_new_from_file ("test.jpg"); //input data + if (!pData) {//need to create logic according to the value of the sharpness + printf ("Could not load '%s'!\n", "test.jpg"); + return (1); + } + + printf("Saving EXIF data to jpeg file\n"); + jpeg_data_set_exif_data (pData, pEd); + printf("Set the data\n"); + jpeg_data_save_file(pData, "foobar2.jpg"); +*/ + return 0; + + + + + + + +} diff --git a/contrib/examples/thumbnail.c b/contrib/examples/thumbnail.c new file mode 100644 index 0000000..1750d5c --- /dev/null +++ b/contrib/examples/thumbnail.c @@ -0,0 +1,66 @@ +/* + * libexif example program to extract an EXIF thumbnail from an image + * and save it into a new file. + * + * Placed into the public domain by Dan Fandrich + */ + +#include +#include + +int main(int argc, char **argv) +{ + int rc = 1; + ExifLoader *l; + + if (argc < 2) { + printf("Usage: %s image.jpg\n", argv[0]); + printf("Extracts a thumbnail from the given EXIF image.\n"); + return rc; + } + + /* Create an ExifLoader object to manage the EXIF loading process */ + l = exif_loader_new(); + if (l) { + ExifData *ed; + + /* Load the EXIF data from the image file */ + exif_loader_write_file(l, argv[1]); + + /* Get a pointer to the EXIF data */ + ed = exif_loader_get_data(l); + + /* The loader is no longer needed--free it */ + exif_loader_unref(l); + l = NULL; + if (ed) { + /* Make sure the image had a thumbnail before trying to write it */ + if (ed->data && ed->size) { + FILE *thumb; + char thumb_name[1024]; + + /* Try to create a unique name for the thumbnail file */ + snprintf(thumb_name, sizeof(thumb_name), + "%s_thumb.jpg", argv[1]); + + thumb = fopen(thumb_name, "wb"); + if (thumb) { + /* Write the thumbnail image to the file */ + fwrite(ed->data, 1, ed->size, thumb); + fclose(thumb); + printf("Wrote thumbnail to %s\n", thumb_name); + rc = 0; + } else { + printf("Could not create file %s\n", thumb_name); + rc = 2; + } + } else { + printf("No EXIF thumbnail in file %s\n", argv[1]); + rc = 1; + } + /* Free the EXIF data */ + exif_data_unref(ed); + } + } + return rc; +} -- 2.7.4