From: Dan F. <dfa...@us...> - 2008-11-19 06:19:15
|
Update of /cvsroot/libexif/libexif/contrib/examples In directory ddv4jf1.ch3.sourceforge.com:/tmp/cvs-serv318 Modified Files: cam_features.c Log Message: Cleaned up the code a bit Index: cam_features.c =================================================================== RCS file: /cvsroot/libexif/libexif/contrib/examples/cam_features.c,v retrieving revision 1.1 retrieving revision 1.2 diff -u -p -d -r1.1 -r1.2 --- cam_features.c 18 Nov 2008 20:42:13 -0000 1.1 +++ cam_features.c 19 Nov 2008 06:19:10 -0000 1.2 @@ -4,29 +4,34 @@ * Wed Jul 27 11:25:09 2005 * Copyright 2005 User: Naysawn Naderi * Email: ndn at xiphos dot ca + * + * Uses libdc1394 and libraw1394 ****************************************************************************/ #include <stdio.h> -#include <libraw1394/raw1394.h> -#include <libdc1394/dc1394_control.h> -#include <libdc1394/dc1394_register.h> #include <stdlib.h> #include <time.h> #include <sys/times.h> #include <errno.h> +#include <libraw1394/raw1394.h> +#include <libdc1394/dc1394_control.h> +#include <libdc1394/dc1394_register.h> //EXIF includes -#include "config.h" +#include <libexif/exif-data.h> +#include <libexif/exif-ifd.h> +#include <libexif/exif-loader.h> + +// Part of the exif command-line source package #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); +#define FILENAME "test.jpg" +static int createEXIF(dc1394featureset_t *xFeatures, ExifData ** pParentEd); + int main(int argc, char *argv[]) { dc1394camera_t *pCamera, **pCameras=NULL; @@ -34,93 +39,75 @@ int main(int argc, char *argv[]) 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;i<iNumCameras;i++) - dc1394_free_camera(pCameras[i]); - free(pCameras); + 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); + } - if(dc1394_get_camera_feature_set(pCamera, &xFeatures)!=DC1394_SUCCESS) - fprintf(stdio, "unable to get feature set\n"); + + /*----------------------------------------------------------------------- + * Initialize the camera + *-----------------------------------------------------------------------*/ + if (iNumCameras<1) { + fprintf(stderr, "no cameras found :(\n"); + exit(1); + } + pCamera=pCameras[0]; + for (i=1;i<iNumCameras;i++) + dc1394_free_camera(pCameras[i]); + free(pCameras); + + if(dc1394_get_camera_feature_set(pCamera, &xFeatures)!=DC1394_SUCCESS) + fprintf(stdout, "unable to get feature set\n"); else printf("camera's feature set retrieved\n"); - + createEXIF(&xFeatures, &pEd); //tag the file with the settings of the camera - + //exif_data_dump (pEd); - + //write the Exif data to a jpeg file - pData = jpeg_data_new_from_file ("test.jpg"); //input data + pData = jpeg_data_new_from_file (FILENAME); //input data if (!pData) { - printf ("Could not load '%s'!\n", "test.jpg"); + printf ("Could not load '%s'!\n", FILENAME); 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; - + return 0; + } - + int createEXIF(dc1394featureset_t *xFeatures, ExifData ** pParentEd) { - - ExifEntry *pE; ExifData * pEd; - unsigned char *upcEb, ucpSize[2]; - unsigned int uiEbs; int i = !xFeatures->feature[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, @@ -130,35 +117,16 @@ int createEXIF(dc1394featureset_t *xFeat 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 + EXIF_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); @@ -177,7 +145,7 @@ int createEXIF(dc1394featureset_t *xFeat 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); + exif_entry_unref (pE); //need to create logic according to the value of the sharpness printf ("Adding a Sharpness Reference\n"); @@ -185,16 +153,13 @@ int createEXIF(dc1394featureset_t *xFeat 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); - - + 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); @@ -205,27 +170,6 @@ int createEXIF(dc1394featureset_t *xFeat //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; - - - - - - + return 0; } |