Commit: 01d802976fc89b97a5a67a0dacdaf414db2651ca
Author: Bastien Montagne
Date:   Fri Jun 20 16:18:26 2014 +0200
https://developer.blender.org/rB01d802976fc89b97a5a67a0dacdaf414db2651ca

BLI_md5: add a utility function to 'translate' raw 16bytes digest into a nice 
32chars hexadecimal string.

That kind of stuff belongs to BLI, not specialized code like thumbs.c

===================================================================

M       source/blender/blenlib/BLI_md5.h
M       source/blender/blenlib/intern/md5.c
M       source/blender/imbuf/intern/thumbs.c

===================================================================

diff --git a/source/blender/blenlib/BLI_md5.h b/source/blender/blenlib/BLI_md5.h
index 8ce479b..6a760f5 100644
--- a/source/blender/blenlib/BLI_md5.h
+++ b/source/blender/blenlib/BLI_md5.h
@@ -41,5 +41,7 @@ void *md5_buffer(const char *buffer, size_t len, void 
*resblock);
 
 int md5_stream(FILE *stream, void *resblock);
 
+char *md5_to_hexdigest(void *resblock, char r_hex_digest[33]);
+
 #endif
 
diff --git a/source/blender/blenlib/intern/md5.c 
b/source/blender/blenlib/intern/md5.c
index 4122f64..3d1a9cd 100644
--- a/source/blender/blenlib/intern/md5.c
+++ b/source/blender/blenlib/intern/md5.c
@@ -389,3 +389,20 @@ void *md5_buffer(const char *buffer, size_t len, void 
*resblock)
        /* Put result in desired memory area. */
        return md5_read_ctx(&ctx, resblock);
 }
+
+char *md5_to_hexdigest(void *resblock, char r_hex_digest[33])
+{
+       static const char hex_map[17] = "0123456789abcdef";
+       const unsigned char *p;
+       char *q;
+       short len;
+
+       for (q = r_hex_digest, p = (const unsigned char *)resblock, len = 0; 
len < 16; ++p, ++len) {
+               const unsigned char c = *p;
+               *q++ = hex_map[c >> 4];
+               *q++ = hex_map[c & 15];
+       }
+       *q = '\0';
+
+       return r_hex_digest;
+}
diff --git a/source/blender/imbuf/intern/thumbs.c 
b/source/blender/imbuf/intern/thumbs.c
index 236d410..41784b1 100644
--- a/source/blender/imbuf/intern/thumbs.c
+++ b/source/blender/imbuf/intern/thumbs.c
@@ -258,9 +258,7 @@ static void thumbname_from_uri(const char *uri, char 
*thumb, const int thumb_len
 
        md5_buffer(uri, strlen(uri), digest);
        hexdigest[0] = '\0';
-       to_hex_char(hexdigest, digest, 16);
-       hexdigest[32] = '\0';
-       BLI_snprintf(thumb, thumb_len, "%s.png", hexdigest);
+       BLI_snprintf(thumb, thumb_len, "%s.png", md5_to_hexdigest(digest, 
hexdigest));
 
        // printf("%s: '%s' --> '%s'\n", __func__, uri, thumb);
 }

_______________________________________________
Bf-blender-cvs mailing list
[email protected]
http://lists.blender.org/mailman/listinfo/bf-blender-cvs

Reply via email to