[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [11363] branches/imgbrowser-elubie/source/ blender: == imagebrowser ==

Andrea Weikert elubie at gmx.net
Tue Jul 24 22:20:46 CEST 2007


Revision: 11363
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=11363
Author:   elubie
Date:     2007-07-24 22:20:46 +0200 (Tue, 24 Jul 2007)

Log Message:
-----------
== imagebrowser ==
new feature: thumbnail caching

Blender now shares thumbnails with GIMP and GNOME and KDE file browsers according to the following thumbnail spec:
http://jens.triq.net/thumbnail-spec/

* This prevents loading of large image files each time to generate the thumbnails.
* Code for MD5 hash and filename escaping taken from the gnome gthumb and glib libraries, details see code.
* The IMB API has been extended to manage and create thumbnails.
* A new internal IMB API to store image info (text strings) has been added. Implementation is done for png, code needs review here and possibly consolidation with the StampInfo plans.
* testing has been done on Windows and to a lesser extent on Linux (Ubuntu), please report any issues on other platforms.

other changes:
* filter buttons in imagebrowser header now only show when filtering is active.

Modified Paths:
--------------
    branches/imgbrowser-elubie/source/blender/blenlib/BLI_blenlib.h
    branches/imgbrowser-elubie/source/blender/blenlib/intern/util.c
    branches/imgbrowser-elubie/source/blender/imbuf/IMB_imbuf_types.h
    branches/imgbrowser-elubie/source/blender/imbuf/intern/allocimbuf.c
    branches/imgbrowser-elubie/source/blender/imbuf/intern/png.c
    branches/imgbrowser-elubie/source/blender/src/filelist.c
    branches/imgbrowser-elubie/source/blender/src/header_imasel.c

Added Paths:
-----------
    branches/imgbrowser-elubie/source/blender/imbuf/IMB_thumbs.h
    branches/imgbrowser-elubie/source/blender/imbuf/intern/IMB_imginfo.h
    branches/imgbrowser-elubie/source/blender/imbuf/intern/imginfo.c
    branches/imgbrowser-elubie/source/blender/imbuf/intern/md5.c
    branches/imgbrowser-elubie/source/blender/imbuf/intern/md5.h
    branches/imgbrowser-elubie/source/blender/imbuf/intern/thumbs.c

Modified: branches/imgbrowser-elubie/source/blender/blenlib/BLI_blenlib.h
===================================================================
--- branches/imgbrowser-elubie/source/blender/blenlib/BLI_blenlib.h	2007-07-24 19:01:30 UTC (rev 11362)
+++ branches/imgbrowser-elubie/source/blender/blenlib/BLI_blenlib.h	2007-07-24 20:20:46 UTC (rev 11363)
@@ -217,6 +217,11 @@
 	 */
 int BLI_strcaseeq(char *a, char *b);
 
+/* in util.c */
+#ifdef WITH_ICONV
+void BLI_string_to_utf8(char *original, char *utf_8, char *code);
+#endif
+
 	/**
 	 * Read a file as ASCII lines. An empty list is
 	 * returned if the file cannot be opened or read.

Modified: branches/imgbrowser-elubie/source/blender/blenlib/intern/util.c
===================================================================
--- branches/imgbrowser-elubie/source/blender/blenlib/intern/util.c	2007-07-24 19:01:30 UTC (rev 11362)
+++ branches/imgbrowser-elubie/source/blender/blenlib/intern/util.c	2007-07-24 20:20:46 UTC (rev 11363)
@@ -1491,6 +1491,38 @@
 	return 0;
 }
 
+
+#ifdef WITH_ICONV
+#include "iconv.h"
+#include "localcharset.h"
+
+void BLI_string_to_utf8(char *original, char *utf_8, char *code)
+{
+	size_t inbytesleft=strlen(original);
+	size_t outbytesleft=512;
+	size_t rv=0;
+	iconv_t cd;
+	
+	if (NULL == code) {
+		code = locale_charset();
+	}
+	cd=iconv_open("UTF-8", code);
+
+	if (cd == (iconv_t)(-1)) {
+		printf("iconv_open Error");
+		*utf_8='\0';
+		return ;
+	}
+	rv=iconv(cd, &original, &inbytesleft, &utf_8, &outbytesleft);
+	if (rv == (size_t) -1) {
+		printf("iconv Error\n");
+		return ;
+	}
+	*utf_8 = '\0';
+	iconv_close(cd);
+}
+#endif // WITH_ICONV
+
 void BLI_timestr(double time, char *str)
 {
 	/* format 00:00:00.00 (hr:min:sec) string has to be 12 long */

Modified: branches/imgbrowser-elubie/source/blender/imbuf/IMB_imbuf_types.h
===================================================================
--- branches/imgbrowser-elubie/source/blender/imbuf/IMB_imbuf_types.h	2007-07-24 19:01:30 UTC (rev 11362)
+++ branches/imgbrowser-elubie/source/blender/imbuf/IMB_imbuf_types.h	2007-07-24 20:20:46 UTC (rev 11363)
@@ -56,6 +56,8 @@
 struct _AviMovie;
 struct Mdec;
 
+struct ImgInfo;
+
 #define IB_MIPMAP_LEVELS	10
 
 /**
@@ -103,6 +105,7 @@
 	float dither;			/**< random dither value, for conversion from float -> byte rect */
 	
 	struct MEM_CacheLimiterHandle_s * c_handle; /**< handle for cache limiter */
+	struct ImgInfo * img_info;
 	int refcounter;			/**< Refcounter for multiple users */
 	int index;				/**< reference index for ImBuf lists */
 	
@@ -148,6 +151,7 @@
 #define IB_rectfloat	(1 << 15)
 #define IB_zbuffloat	(1 << 16)
 #define IB_multilayer	(1 << 17)
+#define IB_imginfo		(1 << 18)
 
 /*
  * The bit flag is stored in the ImBuf.ftype variable.

Added: branches/imgbrowser-elubie/source/blender/imbuf/IMB_thumbs.h
===================================================================
--- branches/imgbrowser-elubie/source/blender/imbuf/IMB_thumbs.h	                        (rev 0)
+++ branches/imgbrowser-elubie/source/blender/imbuf/IMB_thumbs.h	2007-07-24 20:20:46 UTC (rev 11363)
@@ -0,0 +1,73 @@
+/**
+ * $Id: $ 
+ *
+ * ***** BEGIN GPL LICENSE BLOCK *****
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version. 
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
+ *
+ * The Original Code is Copyright (C) 2007 Blender Foundation
+ * All rights reserved.
+ *
+ * The Original Code is: all of this file.
+ *
+ * Contributor(s): Andrea Weikert.
+ *
+ * ***** END GPL LICENSE BLOCK *****
+ */
+
+#ifndef _IMB_THUMBS_H
+#define _IMB_THUMBS_H
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+struct ImBuf;
+
+/** Thumbnail creation and retrieval according to the 'Thumbnail Management Standard'
+ * supported by Gimp, Gnome (Nautilus), KDE etc.
+ * Reference: http://jens.triq.net/thumbnail-spec/index.html
+ */
+
+
+typedef enum ThumbSize {
+	THB_NORMAL,
+	THB_LARGE,
+	THB_FAIL
+} ThumbSize;
+
+typedef enum ThumbSource {
+	THB_SOURCE_IMAGE,
+	THB_SOURCE_MOVIE
+} ThumbSource;
+
+// IB_imginfo
+
+/* create thumbnail for file and returns new imbuf for thumbnail */
+ImBuf* IMB_thumb_create(const char* dir, const char* file, ThumbSize size, ThumbSource source);
+
+/* read thumbnail for file and returns new imbuf for thumbnail */
+ImBuf* IMB_thumb_read(const char* dir, const char* file, ThumbSize size);
+
+/* delete all thumbs for the file */
+void IMB_thumb_delete(const char* dir, const char* file, ThumbSize size);
+
+/* return the state of the thumb, needed to determine how to manage the thumb */
+ImBuf* IMB_thumb_manage(const char* dir, const char* file, ThumbSize size, ThumbSource source);
+
+
+
+
+#endif /* _IMB_THUMBS_H */

Added: branches/imgbrowser-elubie/source/blender/imbuf/intern/IMB_imginfo.h
===================================================================
--- branches/imgbrowser-elubie/source/blender/imbuf/intern/IMB_imginfo.h	                        (rev 0)
+++ branches/imgbrowser-elubie/source/blender/imbuf/intern/IMB_imginfo.h	2007-07-24 20:20:46 UTC (rev 11363)
@@ -0,0 +1,78 @@
+/**
+ * $Id: $ 
+ *
+ * ***** BEGIN GPL LICENSE BLOCK *****
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version. 
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
+ *
+ * The Original Code is Copyright (C) 2005 Blender Foundation
+ * All rights reserved.
+ *
+ * The Original Code is: all of this file.
+ *
+ * Contributor(s): Austin Benesh. Ton Roosendaal.
+ *
+ * ***** END GPL LICENSE BLOCK *****
+ */
+
+#ifndef _IMB_IMGINFO_H
+#define _IMB_IMGINFO_H
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+struct ImBuf;
+
+typedef struct ImgInfo {
+	struct ImgInfo *next, *prev;
+	char* key;
+	char* value;
+	int len;
+} ImgInfo;
+
+/** The imginfo is a list of key/value pairs (both char*) that can me 
+    saved in the header of several image formats.
+	Apart from some common keys like 
+	'Software' and 'Description' (png standard) we'll use keys within the 
+	Blender namespace, so should be called 'Blender::StampInfo' or 'Blender::FrameNum'
+	etc... 
+*/
+
+
+/* free blender ImgInfo struct */
+void IMB_imginfo_free(struct ImBuf* img);
+
+/** read the field from the image info into the field 
+ *  @param img - the ImBuf that contains the image data
+ *  @param key - the key of the field
+ *  @param value - the data in the field, first one found with key is returned, 
+                  memory has to be allocated by user.
+ *  @param len - length of value buffer allocated by user.
+ *  @return    - 1 (true) if ImageInfo present and value for the key found, 0 (false) otherwise
+ */
+int IMB_imginfo_get_field(struct ImBuf* img, const char* key, char* value, int len);
+
+/** set user data in the ImgInfo struct, which has to be allocated with IMB_imginfo_create
+ *  before calling this function.
+ *  @param img - the ImBuf that contains the image data
+ *  @param key - the key of the field
+ *  @param value - the data to be written to the field. zero terminated string
+ *  @return    - 1 (true) if ImageInfo present, 0 (false) otherwise
+ */
+int IMB_imginfo_add_field(struct ImBuf* img, const char* key, const char* field);
+
+
+#endif /* _IMB_IMGINFO_H */

Modified: branches/imgbrowser-elubie/source/blender/imbuf/intern/allocimbuf.c
===================================================================
--- branches/imgbrowser-elubie/source/blender/imbuf/intern/allocimbuf.c	2007-07-24 19:01:30 UTC (rev 11362)
+++ branches/imgbrowser-elubie/source/blender/imbuf/intern/allocimbuf.c	2007-07-24 20:20:46 UTC (rev 11363)
@@ -43,6 +43,7 @@
 
 #include "IMB_divers.h"
 #include "IMB_allocimbuf.h"
+#include "IMB_imginfo.h"
 #include "MEM_CacheLimiterC-Api.h"
 
 static unsigned int dfltcmap[16] = {
@@ -163,6 +164,7 @@
 			IMB_freecmapImBuf(ibuf);
 			freeencodedbufferImBuf(ibuf);
 			IMB_cache_limiter_unmanage(ibuf);
+			IMB_imginfo_free(ibuf);
 			MEM_freeN(ibuf);
 		}
 	}
@@ -476,6 +478,9 @@
 	tbuf.mall		= ibuf2->mall;
 	tbuf.c_handle           = 0;
 
+	// for now don't duplicate image info
+	tbuf.img_info = 0;
+
 	*ibuf2 = tbuf;
 	
 	if (ibuf1->cmap){

Added: branches/imgbrowser-elubie/source/blender/imbuf/intern/imginfo.c
===================================================================
--- branches/imgbrowser-elubie/source/blender/imbuf/intern/imginfo.c	                        (rev 0)
+++ branches/imgbrowser-elubie/source/blender/imbuf/intern/imginfo.c	2007-07-24 20:20:46 UTC (rev 11363)
@@ -0,0 +1,108 @@
+/**
+ * $Id: $ 
+ *
+ * ***** BEGIN GPL LICENSE BLOCK *****
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version. 
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
+ *
+ * The Original Code is Copyright (C) 2005 Blender Foundation
+ * All rights reserved.
+ *

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list