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