• Home
  • History
  • Annotate
  • Line#
  • Navigate
  • Raw
  • Download
  • only in /netgear-WNDR4500v2-V1.0.0.60_1.0.38/ap/gpl/minidlna/libexif-0.6.19/contrib/examples/
1/***************************************************************************
2 *            cam_features.c
3 *
4 *  Wed Jul 27 11:25:09 2005
5 *  Copyright  2005  User: Naysawn Naderi
6 *  Email: ndn at xiphos dot ca
7 *
8 * Uses libdc1394 and libraw1394
9 ****************************************************************************/
10
11#include <stdio.h>
12#include <stdlib.h>
13#include <time.h>
14#include <sys/times.h>
15#include <errno.h>
16
17#include <libraw1394/raw1394.h>
18#include <libdc1394/dc1394_control.h>
19#include <libdc1394/dc1394_register.h>
20
21//EXIF includes
22#include <libexif/exif-data.h>
23#include <libexif/exif-ifd.h>
24#include <libexif/exif-loader.h>
25
26// Part of the exif command-line source package
27#include "libjpeg/jpeg-data.h"
28
29
30#define FILENAME "test.jpg"
31
32
33static int createEXIF(dc1394featureset_t *xFeatures, ExifData ** pParentEd);
34
35
36int main(int argc, char *argv[])
37{   dc1394camera_t *pCamera, **pCameras=NULL;
38    int iNumCameras;
39    dc1394featureset_t xFeatures;
40    int i;
41    int err=dc1394_find_cameras(&pCameras, &iNumCameras);
42
43    //EXIF STUFF
44    JPEGData *pData;
45    //float fOnefloat;
46    ExifData * pEd;
47
48
49    if (err!=DC1394_SUCCESS) {
50        fprintf( stderr, "Unable to look for cameras\n\n"
51            "Please check \n"
52            "  - if the kernel modules `ieee1394',`raw1394' and `ohci1394' are loaded \n"
53            "  - if you have read/write access to /dev/raw1394\n\n");
54        exit(1);
55    }
56
57
58    /*-----------------------------------------------------------------------
59     *  Initialize the camera
60     *-----------------------------------------------------------------------*/
61    if (iNumCameras<1) {
62        fprintf(stderr, "no cameras found :(\n");
63        exit(1);
64    }
65    pCamera=pCameras[0];
66    for (i=1;i<iNumCameras;i++)
67        dc1394_free_camera(pCameras[i]);
68    free(pCameras);
69
70    if(dc1394_get_camera_feature_set(pCamera, &xFeatures)!=DC1394_SUCCESS)
71            fprintf(stdout, "unable to get feature set\n");
72    else
73            printf("camera's feature set retrieved\n");
74
75    createEXIF(&xFeatures, &pEd);  //tag the file with the settings of the camera
76
77    //exif_data_dump (pEd);
78
79    //write the Exif data to a jpeg file
80    pData = jpeg_data_new_from_file (FILENAME);  //input data
81    if (!pData) {
82        printf ("Could not load '%s'!\n", FILENAME);
83        return (-1);
84    }
85
86    printf("Saving EXIF data to jpeg file\n");
87    jpeg_data_set_exif_data (pData, pEd);
88    printf("Set the data\n");
89    jpeg_data_save_file(pData, "foobar2.jpg");
90
91    return 0;
92
93}
94
95
96int createEXIF(dc1394featureset_t *xFeatures, ExifData ** pParentEd)
97{
98    ExifEntry *pE;
99    ExifData * pEd;
100    int i = !xFeatures->feature[DC1394_FEATURE_WHITE_BALANCE - DC1394_FEATURE_MIN].auto_active;
101
102    ExifSRational xR = {xFeatures->feature[DC1394_FEATURE_BRIGHTNESS - DC1394_FEATURE_MIN].value, xFeatures->feature[DC1394_FEATURE_BRIGHTNESS - DC1394_FEATURE_MIN].max};;
103
104    printf ("Creating EXIF data...\n");
105    pEd = exif_data_new ();
106
107    /*
108
109    Things to tag:
110
111    EXIF_TAG_MAKE               = 0x010f,
112    EXIF_TAG_MODEL              = 0x0110,
113    EXIF_TAG_EXPOSURE_TIME      = 0x829a,
114    EXIF_TAG_BRIGHTNESS_VALUE   = 0x9203,
115    EXIF_TAG_WHITE_BALANCE      = 0xa403,
116    EXIF_TAG_GAIN_CONTROL       = 0xa407,
117    EXIF_TAG_CONTRAST           = 0xa408,
118    EXIF_TAG_SATURATION         = 0xa409,
119    EXIF_TAG_SHARPNESS          = 0xa40a,
120    EXIF_TAG_USER_COMMENT
121    */
122
123    printf ("Adding a Make reference\n");
124    pE = exif_entry_new ();
125    exif_content_add_entry (pEd->ifd[EXIF_IFD_0], pE);
126    exif_entry_initialize (pE, EXIF_TAG_MAKE);
127    pE->data="AVT";
128    exif_entry_unref (pE);
129
130    printf ("Adding a Model reference\n");
131    pE = exif_entry_new ();
132    exif_content_add_entry (pEd->ifd[EXIF_IFD_0], pE);
133    exif_entry_initialize (pE, EXIF_TAG_MODEL);
134    pE->data="510c";
135    exif_entry_unref (pE);
136
137    printf ("Adding a Tag to reference # samples per pixel\n");
138    pE = exif_entry_new ();
139    exif_content_add_entry (pEd->ifd[EXIF_IFD_0], pE);
140    exif_entry_initialize (pE, EXIF_TAG_SAMPLES_PER_PIXEL); //by default is 3
141    exif_entry_unref (pE);
142
143    printf ("Adding a White Balance Reference\n");
144    pE = exif_entry_new ();
145    exif_content_add_entry (pEd->ifd[EXIF_IFD_0], pE);
146    exif_entry_initialize (pE, EXIF_TAG_WHITE_BALANCE);
147    exif_set_short(pE->data, exif_data_get_byte_order (pEd), i);  //0=auto white balance, 1 = manual white balance
148    exif_entry_unref (pE);
149
150    //need to create logic according to the value of the sharpness
151    printf ("Adding a Sharpness Reference\n");
152    pE = exif_entry_new ();
153    exif_content_add_entry (pEd->ifd[EXIF_IFD_0], pE);
154    exif_entry_initialize (pE, EXIF_TAG_SHARPNESS);
155    exif_set_short(pE->data, exif_data_get_byte_order (pEd), 0);
156    exif_entry_unref (pE);
157
158    printf ("Adding a Brightness reference\n");
159
160    //try to get brightness
161    //printf("Float Value: %i\n",xFeatures->feature[DC1394_FEATURE_BRIGHTNESS - DC1394_FEATURE_MIN].value);
162
163    pE = exif_entry_new ();
164    exif_content_add_entry (pEd->ifd[EXIF_IFD_0], pE);
165    exif_entry_initialize (pE, EXIF_TAG_BRIGHTNESS_VALUE);
166    exif_set_srational (pE->data, exif_data_get_byte_order (pEd), xR);
167
168
169    //exif_data_dump (ed);
170    //exif_data_dump (pEd);
171    *pParentEd = pEd;
172    printf("Done!\n");
173
174    return 0;
175}
176