tracker r2520 - in trunk: . src/tracker-extract
- From: mottela svn gnome org
- To: svn-commits-list gnome org
- Subject: tracker r2520 - in trunk: . src/tracker-extract
- Date: Tue, 18 Nov 2008 16:56:33 +0000 (UTC)
Author: mottela
Date: Tue Nov 18 16:56:33 2008
New Revision: 2520
URL: http://svn.gnome.org/viewvc/tracker?rev=2520&view=rev
Log:
Fixed png extractor to extract the whole file for metadata, not just header
Modified:
trunk/ChangeLog
trunk/src/tracker-extract/tracker-extract-png.c
Modified: trunk/src/tracker-extract/tracker-extract-png.c
==============================================================================
--- trunk/src/tracker-extract/tracker-extract-png.c (original)
+++ trunk/src/tracker-extract/tracker-extract-png.c Tue Nov 18 16:56:33 2008
@@ -81,6 +81,58 @@
}
static void
+read_metadata (png_structp png_ptr, png_infop info_ptr, GHashTable *metadata)
+{
+ gint num_text;
+ png_textp text_ptr;
+
+ if (png_get_text (png_ptr, info_ptr, &text_ptr, &num_text) > 0) {
+ gint i;
+ gint j;
+
+ for (i = 0; i < num_text; i++) {
+ if (!text_ptr[i].key) {
+ continue;
+ }
+
+#if defined(HAVE_EXEMPI) && defined(PNG_iTXt_SUPPORTED)
+ if (strcmp ("XML:com.adobe.xmp", text_ptr[i].key) == 0) {
+ tracker_read_xmp (text_ptr[i].text,
+ text_ptr[i].itxt_length,
+ metadata);
+ continue;
+ }
+#endif
+
+ for (j = 0; tag_processors[j].type; j++) {
+ if (strcasecmp (tag_processors[j].name, text_ptr[i].key) != 0) {
+ continue;
+ }
+
+ if (text_ptr[i].text && text_ptr[i].text[0] != '\0') {
+ if (tag_processors[j].post) {
+ gchar *str;
+
+ str = (*tag_processors[j].post) (text_ptr[i].text);
+ if (str) {
+ g_hash_table_insert (metadata,
+ g_strdup (tag_processors[j].type),
+ str);
+ }
+ } else {
+ g_hash_table_insert (metadata,
+ g_strdup (tag_processors[j].type),
+ g_strdup (text_ptr[i].text));
+ }
+
+ break;
+ }
+ }
+ }
+ }
+}
+
+static void
extract_png (const gchar *filename,
GHashTable *metadata)
{
@@ -88,9 +140,11 @@
FILE *png;
png_structp png_ptr;
png_infop info_ptr;
+ png_infop end_ptr;
+ png_bytepp row_pointers;
+ guint row;
+
png_uint_32 width, height;
- gint num_text;
- png_textp text_ptr;
gint bit_depth, color_type;
gint interlace_type, compression_type, filter_type;
@@ -119,74 +173,70 @@
return;
}
- png_init_io (png_ptr, png);
- png_read_info (png_ptr, info_ptr);
-
- if (png_get_text (png_ptr, info_ptr, &text_ptr, &num_text) > 0) {
- gint i;
- gint j;
-
- for (i = 0; i < num_text; i++) {
- if (!text_ptr[i].key) {
- continue;
- }
-
-#if defined(HAVE_EXEMPI) && defined(PNG_iTXt_SUPPORTED)
- if (strcmp ("XML:com.adobe.xmp", text_ptr[i].key) == 0) {
- tracker_read_xmp (text_ptr[i].text,
- text_ptr[i].itxt_length,
- metadata);
- continue;
- }
-#endif
+ end_ptr = png_create_info_struct (png_ptr);
+ if (!info_ptr) {
+ png_destroy_read_struct (&png_ptr, &info_ptr, NULL);
+ png_destroy_read_struct (&png_ptr, &end_ptr, NULL);
+ fclose (png);
+ return;
+ }
- for (j = 0; tag_processors[j].type; j++) {
- if (strcasecmp (tag_processors[j].name, text_ptr[i].key) != 0) {
- continue;
- }
+ if (setjmp(png_jmpbuf(png_ptr))) {
+ png_destroy_read_struct (&png_ptr, &info_ptr,
+ (png_infopp)NULL);
+ png_destroy_read_struct (&png_ptr, &end_ptr,
+ (png_infopp)NULL);
+ fclose (png);
+ return;
+ }
- if (text_ptr[i].text && text_ptr[i].text[0] != '\0') {
- if (tag_processors[j].post) {
- gchar *str;
-
- str = (*tag_processors[j].post) (text_ptr[i].text);
- if (str) {
- g_hash_table_insert (metadata,
- g_strdup (tag_processors[j].type),
- str);
- }
- } else {
- g_hash_table_insert (metadata,
- g_strdup (tag_processors[j].type),
- g_strdup (text_ptr[i].text));
- }
+ png_init_io (png_ptr, png);
+ png_read_info (png_ptr, info_ptr);
- break;
- }
- }
- }
+ if (!png_get_IHDR (png_ptr,
+ info_ptr,
+ &width,
+ &height,
+ &bit_depth,
+ &color_type,
+ &interlace_type,
+ &compression_type,
+ &filter_type)) {
+ png_destroy_read_struct (&png_ptr, &info_ptr, NULL);
+ png_destroy_read_struct (&png_ptr, &end_ptr, NULL);
+ fclose (png);
+ return;
}
-
- /* Read size from header. We want native have higher
- * priority than EXIF etc.
+
+ /* Read the image. FIXME We should be able to skip this step and
+ * just get the info from the end. This causes some errors atm.
*/
- if (png_get_IHDR (png_ptr,
- info_ptr,
- &width,
- &height,
- &bit_depth,
- &color_type,
- &interlace_type,
- &compression_type,
- &filter_type)) {
- g_hash_table_insert (metadata,
- g_strdup ("Image:Width"),
- g_strdup_printf ("%ld", width));
- g_hash_table_insert (metadata,
- g_strdup ("Image:Height"),
- g_strdup_printf ("%ld", height));
+ row_pointers = (png_bytepp)malloc(height * sizeof(png_bytep));
+ for (row = 0; row < height; row++) {
+ row_pointers[row] = png_malloc(png_ptr,
+ png_get_rowbytes(png_ptr,info_ptr));
+ }
+ png_read_image (png_ptr, row_pointers);
+ for (row = 0; row < height; row++) {
+ png_free (png_ptr, row_pointers[row]);
}
+ g_free (row_pointers);
+
+ png_read_end (png_ptr, end_ptr);
+
+ read_metadata (png_ptr, info_ptr, metadata);
+ read_metadata (png_ptr, end_ptr, metadata);
+
+ /* We want native have higher priority than XMP etc.
+ */
+ g_hash_table_insert (metadata,
+ g_strdup ("Image:Width"),
+ g_strdup_printf ("%ld", width));
+ g_hash_table_insert (metadata,
+ g_strdup ("Image:Height"),
+ g_strdup_printf ("%ld", height));
+
png_destroy_read_struct (&png_ptr, &info_ptr, NULL);
fclose (png);
} else {
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]