diff options
author | Edgard Lima <edgard.lima@indt.org.br> | 2007-12-05 17:00:59 +0000 |
---|---|---|
committer | Edgard Lima <edgard.lima@indt.org.br> | 2007-12-05 17:00:59 +0000 |
commit | 8152bfe97270c3f59b94b7cee6ca78517b5cf1db (patch) | |
tree | 010367d661d4dd83c89e2471b7ca3479793cd355 /ext | |
parent | 3966e730c9a697e2dc66b1a613422aefe2214d9c (diff) | |
download | gst-plugins-bad-8152bfe97270c3f59b94b7cee6ca78517b5cf1db.tar.gz gst-plugins-bad-8152bfe97270c3f59b94b7cee6ca78517b5cf1db.tar.bz2 gst-plugins-bad-8152bfe97270c3f59b94b7cee6ca78517b5cf1db.zip |
Added some tags to exif parser.
Original commit message from CVS:
Added some tags to exif parser.
Diffstat (limited to 'ext')
-rw-r--r-- | ext/metadata/metadataexif.c | 138 | ||||
-rw-r--r-- | ext/metadata/metadataiptc.c | 7 | ||||
-rw-r--r-- | ext/metadata/metadatatags.c | 93 | ||||
-rw-r--r-- | ext/metadata/metadatatags.h | 19 | ||||
-rw-r--r-- | ext/metadata/metadataxmp.c | 6 |
5 files changed, 242 insertions, 21 deletions
diff --git a/ext/metadata/metadataexif.c b/ext/metadata/metadataexif.c index 4bc8d4bf..c45a93e4 100644 --- a/ext/metadata/metadataexif.c +++ b/ext/metadata/metadataexif.c @@ -55,11 +55,12 @@ metadataparse_exif_tag_list_add (GstTagList * taglist, GstTagMergeMode mode, GstAdapter * adapter, MetadataTagMapping mapping) { - GST_LOG ("EXIF not defined, here I should send just one tag as whole chunk"); - - if (mapping & METADATA_TAG_MAP_WHOLECHUNK) + if (mapping & METADATA_TAG_MAP_WHOLECHUNK) { + GST_LOG + ("EXIF not defined, here I should send just one tag as whole chunk"); metadataparse_util_tag_list_add_chunk (taglist, mode, GST_TAG_EXIF, adapter); + } } @@ -73,11 +74,13 @@ metadatamux_exif_create_chunk_from_tag_list (guint8 ** buf, guint32 * size, #else /* ifndef HAVE_EXIF */ #include <libexif/exif-data.h> +#include <stdlib.h> typedef struct _tag_MEUserData { GstTagList *taglist; GstTagMergeMode mode; + ExifShort resolution_unit; /* 2- inches (default), 3- cm */ } MEUserData; typedef struct _tag_MapIntStr @@ -96,10 +99,22 @@ const gchar * metadataparse_exif_get_tag_from_exif (ExifTag exif, GType * type) { /* FIXEME: sorted with binary search */ - static const MapIntStr array[] = { + static MapIntStr array[] = { {EXIF_TAG_MAKE, GST_TAG_DEVICE_MAKE, G_TYPE_STRING}, {EXIF_TAG_MODEL, GST_TAG_DEVICE_MODEL, G_TYPE_STRING}, - {0, NULL, G_TYPE_NONE} + {EXIF_TAG_SOFTWARE, GST_TAG_CREATOR_TOOL, G_TYPE_STRING}, + {EXIF_TAG_X_RESOLUTION, GST_TAG_IMAGE_XRESOLUTION, G_TYPE_FLOAT}, /* asure inches */ + {EXIF_TAG_Y_RESOLUTION, GST_TAG_IMAGE_YRESOLUTION, G_TYPE_FLOAT}, /* asure inches */ + {EXIF_TAG_EXPOSURE_TIME, GST_TAG_CAPTURE_EXPOSURE_TIME, G_TYPE_FLOAT}, + {EXIF_TAG_FNUMBER, GST_TAG_CAPTURE_FNUMBER, G_TYPE_FLOAT}, + {EXIF_TAG_EXPOSURE_PROGRAM, GST_TAG_CAPTURE_EXPOSURE_PROGRAM, G_TYPE_UINT}, + {EXIF_TAG_BRIGHTNESS_VALUE, GST_TAG_CAPTURE_BRIGHTNESS, G_TYPE_FLOAT}, + {EXIF_TAG_WHITE_BALANCE, GST_TAG_CAPTURE_WHITE_BALANCE, G_TYPE_UINT}, + {EXIF_TAG_DIGITAL_ZOOM_RATIO, GST_TAG_CAPTURE_DIGITAL_ZOOM, G_TYPE_FLOAT}, + {EXIF_TAG_GAIN_CONTROL, GST_TAG_CAPTURE_GAIN, G_TYPE_UINT}, + {EXIF_TAG_CONTRAST, GST_TAG_CAPTURE_CONTRAST, G_TYPE_UINT}, + {EXIF_TAG_SATURATION, GST_TAG_CAPTURE_SATURATION, G_TYPE_UINT}, + {0, NULL, G_TYPE_NONE, G_TYPE_UINT} }; int i = 0; @@ -121,7 +136,7 @@ metadataparse_exif_tag_list_add (GstTagList * taglist, GstTagMergeMode mode, const guint8 *buf; guint32 size; ExifData *exif = NULL; - MEUserData user_data = { taglist, mode }; + MEUserData user_data = { taglist, mode, 2 }; if (adapter == NULL || (size = gst_adapter_available (adapter)) == 0) { goto done; @@ -171,8 +186,111 @@ exif_content_foreach_entry_func (ExifEntry * entry, void *user_data) char buf[2048]; MEUserData *meudata = (MEUserData *) user_data; GType type; + ExifByteOrder byte_order; const gchar *tag = metadataparse_exif_get_tag_from_exif (entry->tag, &type); + /* We need the byte order */ + if (!entry || !entry->parent || !entry->parent->parent) + return; + byte_order = exif_data_get_byte_order (entry->parent->parent); + + if (entry->tag == EXIF_TAG_RESOLUTION_UNIT) { + meudata->resolution_unit = exif_get_short (entry->data, byte_order); + if (meudata->resolution_unit == 3) { + /* if [xy]resolution has alredy been add in cm, replace it in inches */ + gfloat value; + + if (gst_tag_list_get_float (meudata->taglist, GST_TAG_IMAGE_XRESOLUTION, + &value)) + gst_tag_list_add (meudata->taglist, GST_TAG_MERGE_REPLACE, + GST_TAG_IMAGE_XRESOLUTION, value * 0.4f, NULL); + if (gst_tag_list_get_float (meudata->taglist, GST_TAG_IMAGE_YRESOLUTION, + &value)) + gst_tag_list_add (meudata->taglist, GST_TAG_MERGE_REPLACE, + GST_TAG_IMAGE_YRESOLUTION, value * 0.4f, NULL); + } + goto done; + } + + if (tag) { + /* FIXME: create a generic function for this */ + /* could also be used with entry->format */ + switch (type) { + case G_TYPE_STRING: + gst_tag_list_add (meudata->taglist, meudata->mode, tag, + exif_entry_get_value (entry, buf, sizeof (buf)), NULL); + break; + case G_TYPE_FLOAT: + { + gfloat f_value; + ExifRational v_rat; + + switch (entry->format) { + case EXIF_FORMAT_RATIONAL: + v_rat = exif_get_rational (entry->data, byte_order); + if (v_rat.numerator == 0) + f_value = 0.0f; + else + f_value = (float) v_rat.numerator / (float) v_rat.denominator; + if (v_rat.numerator == 0xFFFFFFFF) { + if (entry->tag == GST_TAG_CAPTURE_BRIGHTNESS) { + f_value = 100.0f; + } + } + break; + default: + GST_ERROR ("Unexpected Tag Type"); + goto done; + break; + } + if (meudata->resolution_unit == 3) { + /* converts from cm to inches */ + if (entry->tag == EXIF_TAG_X_RESOLUTION + || entry->tag == EXIF_TAG_Y_RESOLUTION) { + f_value *= 0.4f; + } + } + gst_tag_list_add (meudata->taglist, meudata->mode, tag, f_value, NULL); + } + case G_TYPE_UINT: + { + ExifShort v_short; + + switch (entry->format) { + case EXIF_FORMAT_SHORT: + v_short = exif_get_short (entry->data, byte_order); + break; + default: + GST_ERROR ("Unexpected Tag Type"); + goto done; + break; + } + if (entry->tag == EXIF_TAG_CONTRAST || + entry->tag == EXIF_TAG_SATURATION) { + switch (v_short) { + case 0: + break; + case 1: + v_short = -67; + break; + case 2: + v_short = 66; + break; + default: + GST_ERROR ("Unexpected value"); + break; + } + } + gst_tag_list_add (meudata->taglist, meudata->mode, tag, v_short, NULL); + } + break; + default: + break; + } + } + +done: + GST_LOG ("\n Entry %p: %s (%s)\n" " Size, Comps: %d, %d\n" " Value: %s\n" @@ -187,13 +305,7 @@ exif_content_foreach_entry_func (ExifEntry * entry, void *user_data) exif_tag_get_title_in_ifd (entry->tag, EXIF_IFD_0), exif_tag_get_description_in_ifd (entry->tag, EXIF_IFD_0)); - if (tag) { - /* FIXME: create a generic function for this */ - /* could also be used with entry->format */ - if (type == G_TYPE_STRING) - gst_tag_list_add (meudata->taglist, meudata->mode, tag, - exif_entry_get_value (entry, buf, sizeof (buf)), NULL); - } + return; } diff --git a/ext/metadata/metadataiptc.c b/ext/metadata/metadataiptc.c index 7009cc04..1e570b5f 100644 --- a/ext/metadata/metadataiptc.c +++ b/ext/metadata/metadataiptc.c @@ -55,11 +55,12 @@ metadataparse_iptc_tag_list_add (GstTagList * taglist, GstTagMergeMode mode, GstAdapter * adapter, MetadataTagMapping mapping) { - GST_LOG ("IPTC not defined, here I should send just one tag as whole chunk"); - - if (mapping & METADATA_TAG_MAP_WHOLECHUNK) + if (mapping & METADATA_TAG_MAP_WHOLECHUNK) { + GST_LOG + ("IPTC not defined, here I should send just one tag as whole chunk"); metadataparse_util_tag_list_add_chunk (taglist, mode, GST_TAG_IPTC, adapter); + } } diff --git a/ext/metadata/metadatatags.c b/ext/metadata/metadatatags.c index ceb97070..45988922 100644 --- a/ext/metadata/metadatatags.c +++ b/ext/metadata/metadatatags.c @@ -83,6 +83,8 @@ metadata_tags_xmp_register (void) void metadata_tags_register (void) { + /* devices tags */ + gst_tag_register (GST_TAG_DEVICE_MAKE, GST_TAG_FLAG_META, G_TYPE_STRING, GST_TAG_DEVICE_MAKE, "The manufacturer of the recording equipment", NULL); @@ -90,6 +92,97 @@ metadata_tags_register (void) GST_TAG_DEVICE_MODEL, "The model name or model number of the equipment", NULL); + /* generic tags */ + + gst_tag_register (GST_TAG_CREATOR_TOOL, GST_TAG_FLAG_META, G_TYPE_STRING, + GST_TAG_CREATOR_TOOL, + "The name of the first known tool used to create the resource." + " Or firmware or driver version of device", NULL); + + /* image tags */ + + gst_tag_register (GST_TAG_IMAGE_XRESOLUTION, GST_TAG_FLAG_META, G_TYPE_FLOAT, + GST_TAG_IMAGE_XRESOLUTION, "Horizontal resolution in pixels per inch", + NULL); + gst_tag_register (GST_TAG_IMAGE_YRESOLUTION, GST_TAG_FLAG_META, G_TYPE_FLOAT, + GST_TAG_IMAGE_YRESOLUTION, "Vertical resolution in pixels per inch", + NULL); + + /* capture tags */ + + gst_tag_register (GST_TAG_CAPTURE_EXPOSURE_TIME, GST_TAG_FLAG_META, + G_TYPE_FLOAT, GST_TAG_CAPTURE_EXPOSURE_TIME, "Exposure time in seconds", + NULL); + gst_tag_register (GST_TAG_CAPTURE_FNUMBER, GST_TAG_FLAG_META, G_TYPE_FLOAT, + GST_TAG_CAPTURE_FNUMBER, "F number (focal ratio)", NULL); + /** + 0 - not defined + 1- Manual + 2- Normal program + 3- Aperture priority + 4- Shutter priority + 5- Creative program (biased toward death of field) + 6- Action program (biased toward fast shutter speed) + 7- Portrait mode (for closeup photos with the background out of focus) + 8- Landscape mode (for landscape photos with the background in focus) + *** exif is until here *** + 9- Night + 10- Back-light + 11- Spotlight + 12- Snow + 13- Beach + */ + gst_tag_register (GST_TAG_CAPTURE_EXPOSURE_PROGRAM, GST_TAG_FLAG_META, + G_TYPE_UINT, GST_TAG_CAPTURE_EXPOSURE_PROGRAM, + "Class of program used for exposure", NULL); + /** The unit is the APEX value. + Ordinarily it is given in the range of -99.99 to 99.99. + 100.0 mean unknown + */ + gst_tag_register (GST_TAG_CAPTURE_BRIGHTNESS, GST_TAG_FLAG_META, G_TYPE_FLOAT, + GST_TAG_CAPTURE_BRIGHTNESS, "Brightness (APEX from -99.99 to 99.99)", + NULL); + /** + 0- Auto + 1- Off + *** exif is until here *** + 2- Sunlight + 3- Cloudy + 4- Shade + 5- Tungsten + 6- Fluorescent + 7- Incandescent + 8- Flash + 9- Horizon (sun on the horizon) + */ + gst_tag_register (GST_TAG_CAPTURE_WHITE_BALANCE, GST_TAG_FLAG_META, + G_TYPE_UINT, GST_TAG_CAPTURE_WHITE_BALANCE, "White balance mode", NULL); + /** if Zero ZOOM not used + */ + gst_tag_register (GST_TAG_CAPTURE_DIGITAL_ZOOM, GST_TAG_FLAG_META, + G_TYPE_FLOAT, GST_TAG_CAPTURE_DIGITAL_ZOOM, "Digital zoom ratio", NULL); + /** + 0- None + 1- Low gain up + 2- High gain up + 3- Low gain down + 4- High gain down + */ + gst_tag_register (GST_TAG_CAPTURE_GAIN, GST_TAG_FLAG_META, G_TYPE_UINT, + GST_TAG_CAPTURE_GAIN, "", NULL); + /** + from -100 to 100 + *** exif is just 0, 1, 2 (normal, soft and hard) + */ + gst_tag_register (GST_TAG_CAPTURE_CONTRAST, GST_TAG_FLAG_META, G_TYPE_INT, + GST_TAG_CAPTURE_CONTRAST, "", NULL); + /** + from -100 to 100 + *** exif is just 0, 1, 2 (normal, low and high) + */ + gst_tag_register (GST_TAG_CAPTURE_SATURATION, GST_TAG_FLAG_META, G_TYPE_INT, + GST_TAG_CAPTURE_SATURATION, "", NULL); + metadata_tags_exif_register (); metadata_tags_iptc_register (); metadata_tags_xmp_register (); diff --git a/ext/metadata/metadatatags.h b/ext/metadata/metadatatags.h index 60dd0806..77a6c306 100644 --- a/ext/metadata/metadatatags.h +++ b/ext/metadata/metadatatags.h @@ -61,8 +61,23 @@ typedef enum { #define GST_TAG_XMP "xmp" -#define GST_TAG_DEVICE_MAKE "device-make" -#define GST_TAG_DEVICE_MODEL "device-model" +#define GST_TAG_DEVICE_MAKE "device-make" +#define GST_TAG_DEVICE_MODEL "device-model" + +#define GST_TAG_CREATOR_TOOL "creator-tool" + +#define GST_TAG_IMAGE_XRESOLUTION "image-xresolution" +#define GST_TAG_IMAGE_YRESOLUTION "image-yresolution" + +#define GST_TAG_CAPTURE_EXPOSURE_TIME "capture-exposute-time" +#define GST_TAG_CAPTURE_FNUMBER "captute-fnumber" +#define GST_TAG_CAPTURE_EXPOSURE_PROGRAM "capture-exposure-program" +#define GST_TAG_CAPTURE_BRIGHTNESS "capture-brightness" +#define GST_TAG_CAPTURE_WHITE_BALANCE "capture-white-balance" +#define GST_TAG_CAPTURE_DIGITAL_ZOOM "capture-digital-zoom" +#define GST_TAG_CAPTURE_GAIN "capture-gain" +#define GST_TAG_CAPTURE_CONTRAST "capture-contrast" +#define GST_TAG_CAPTURE_SATURATION "capture-saturation" extern void metadata_tags_register (void); diff --git a/ext/metadata/metadataxmp.c b/ext/metadata/metadataxmp.c index ba24d4a7..949300a0 100644 --- a/ext/metadata/metadataxmp.c +++ b/ext/metadata/metadataxmp.c @@ -55,10 +55,10 @@ metadataparse_xmp_tag_list_add (GstTagList * taglist, GstTagMergeMode mode, GstAdapter * adapter, MetadataTagMapping mapping) { - GST_LOG ("XMP not defined, here I should send just one tag as whole chunk"); - - if (mapping & METADATA_TAG_MAP_WHOLECHUNK) + if (mapping & METADATA_TAG_MAP_WHOLECHUNK) { + GST_LOG ("XMP not defined, here I should send just one tag as whole chunk"); metadataparse_util_tag_list_add_chunk (taglist, mode, GST_TAG_XMP, adapter); + } } |