[PATCH] Add glretrace option '--snapshot-format=MD5' that allow write

Meng, Mengmeng mengmeng.meng at intel.com
Wed Jan 15 19:05:02 PST 2014


Hi, it's the a patch for MD5. Limited to size, the thirdparty is attached.


Subject: [PATCH] Add glretrace option '--snapshot-format=MD5' that allow write image MD5 to a text format file.

Collecting MD5 is obtained based on raw buffer. Rendering results are reproducd accurately. Creating .txt in place of PNG Format, that would save more disk space and run faster.
Reference command: glretrace  --snapshot-format=MD5 -s  /tmp/MD5.log  smokinguns.trace.
---
CMakeLists.txt                |    5 +
image/CMakeLists.txt          |    3 +
image/image.hpp               |    6 +
image/image_md5.cpp           |   88 +++
retrace/retrace_main.cpp      |   25 +-
thirdparty/md5/CMakeLists.txt |    7 +
thirdparty/md5/index.html     |  242 +++++++++
thirdparty/md5/main.c         |  275 ++++++++++
thirdparty/md5/md5.c          |  255 +++++++++
thirdparty/md5/md5.h          |   52 ++
thirdparty/md5/md5.sln        |   21 +
thirdparty/md5/md5.vcproj     |  130 +++++
thirdparty/md5/rfc1321.html   | 1093 ++++++++++++++++++++++++++++++++++++++
thirdparty/md5/rfc1321.txt    | 1179 +++++++++++++++++++++++++++++++++++++++++
14 files changed, 3373 insertions(+), 8 deletions(-)
create mode 100644 image/image_md5.cpp
create mode 100644 thirdparty/md5/CMakeLists.txt
create mode 100644 thirdparty/md5/index.html
create mode 100644 thirdparty/md5/main.c
create mode 100644 thirdparty/md5/md5.c
create mode 100644 thirdparty/md5/md5.h
create mode 100644 thirdparty/md5/md5.sln
create mode 100644 thirdparty/md5/md5.vcproj
create mode 100644 thirdparty/md5/rfc1321.html
create mode 100644 thirdparty/md5/rfc1321.txt

diff --git a/CMakeLists.txt b/CMakeLists.txt
index 0775119..5af487d 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -290,6 +290,11 @@ endif ()
# also avoids missing/inconsistent declarations in system headers.
include_directories (BEFORE ${CMAKE_CURRENT_SOURCE_DIR}/thirdparty/khronos)

+# md5 implementation be added to the thirdparty tree
+set (MD5_INCLUDE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/thirdparty/md5)
+set (MD5_LIBRARIES md5_bundled)
+
+add_subdirectory (thirdparty/md5)

##############################################################################
# Common libraries / utilities
diff --git a/image/CMakeLists.txt b/image/CMakeLists.txt
index 51d7ed8..ea08074 100644
--- a/image/CMakeLists.txt
+++ b/image/CMakeLists.txt
@@ -1,5 +1,6 @@
include_directories (
     ${PNG_INCLUDE_DIR}
+    ${MD5_INCLUDE_DIR}
)

add_library (image STATIC
@@ -7,8 +8,10 @@ add_library (image STATIC
     image_png.cpp
     image_pnm.cpp
     image_raw.cpp
+    image_md5.cpp
)

target_link_libraries (image
     ${PNG_LIBRARIES}
+    ${MD5_LIBRARIES}
)
diff --git a/image/image.hpp b/image/image.hpp
index 7e13dd6..5398c9f 100644
--- a/image/image.hpp
+++ b/image/image.hpp
@@ -94,6 +94,12 @@ public:
         return true;
     }

+    void
+    writeMD5(std::ostream &os) const;
+
+    bool
+    writeMD5(const char *filename) const;
+
     bool
     writePNG(std::ostream &os) const;
diff --git a/retrace/retrace_main.cpp b/retrace/retrace_main.cpp
index bff8983..f81fefa 100644
--- a/retrace/retrace_main.cpp
+++ b/retrace/retrace_main.cpp
@@ -50,7 +50,8 @@ static bool loopOnFinish = false;
static const char *snapshotPrefix = NULL;
static enum {
     PNM_FMT,
-    RAW_RGB
+    RAW_RGB,
+    RAW_MD5
} snapshotFormat = PNM_FMT;

static trace::CallSet snapshotFrequency;
@@ -126,12 +127,18 @@ takeSnapshot(unsigned call_no) {
             else
                 src->writePNM(std::cout, comment);
         } else {
-            os::String filename = os::String::format("%s%010u.png",
-                                                     snapshotPrefix,
-                                                     useCallNos ? call_no : snapshot_no);
-            if (src->writePNG(filename) && retrace::verbosity >= 0) {
-                std::cout << "Wrote " << filename << "\n";
-            }
+            if (snapshotFormat == RAW_MD5) {
+                 os::String  filename = snapshotPrefix;
+                  src->writeMD5(filename);
+               }
+           else
+               {   os::String filename = os::String::format("%s%010u.png",
+                                                            snapshotPrefix,
+                                                            useCallNos ? call_no : snapshot_no);
+                   if (src->writePNG(filename) && retrace::verbosity >= 0) {
+                         std::cout << "Wrote " << filename << "\n";
+                           }
+               }
         }
     }

@@ -701,7 +708,9 @@ int main(int argc, char **argv)
        case SNAPSHOT_FORMAT_OPT:
             if (strcmp(optarg, "RGB") == 0)
                 snapshotFormat = RAW_RGB;
-            else
+            else if (strcmp(optarg, "MD5") == 0)
+               snapshotFormat = RAW_MD5;
+            else
                 snapshotFormat = PNM_FMT;
             break;
         case 'S':
diff --git a/image/image_md5.cpp b/image/image_md5.cpp
new file mode 100644
index 0000000..8dc777a
--- /dev/null
+++ b/image/image_md5.cpp
@@ -0,0 +1,88 @@
+/**************************************************************************
+ *
+ * Copyright (C) 2013 Intel Corporation. All rights reversed.
+ * Author: Meng Mengmeng <mengmeng.meng at intel.com>
+ * All Rights Reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ *
+ **************************************************************************/
+#include <fstream>
+#include <stdlib.h>
+#include <stdio.h>
+#include <assert.h>
+#include <stdint.h>
+#include <string.h>
+#include "image.hpp"
+
+extern "C"
+{
+  #include "md5.h"
+}
+using namespace std;
+namespace image {
+
+
+bool
+Image::writeMD5(const char *filename) const {
+        std::ofstream os(filename, std::ofstream::app);
+        if (!os) {
+            return false;
+        }
+         writeMD5(os);
+         return true;
+    }
+
+void
+Image::writeMD5(std::ostream &os) const {
+
+   const unsigned char * image_start_buff;
+   const unsigned char * image_end_buff;
+
+   const  char *hexfmt = "%02X";
+   unsigned  char signature[16];
+   char buf[3]={'\0'},csig[33]={'\0'};
+   struct MD5Context md5c;
+
+   image_start_buff = start();
+   image_end_buff = end();
+   unsigned long lenth =  image_start_buff - image_end_buff  ;
+
+   unsigned char * buffer=(unsigned char *)malloc(lenth * sizeof(char));
+   for(int i=0;i<height;i+=1){
+        memcpy(buffer+ (-stride())*i,(unsigned char *)(image_start_buff+stride()*i),-stride());
+   }
+
+   MD5Init(&md5c);
+   MD5Update(&md5c, buffer ,lenth);
+   MD5Final(signature,&md5c);
+   for(int i = 0; i < sizeof signature; i++){
+         sprintf(buf, hexfmt, signature[i]);
+         strcat(csig,buf);
+   }
+
+  free(buffer);
+
+  os.write((const char *)csig, strlen(csig));
+  os.write("\n", strlen("\n"));
+}
+
+
+} /* namespace image */
+

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freedesktop.org/archives/apitrace/attachments/20140116/e58e0d0a/attachment-0001.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 0001-Add-glretrace-option-snapshot-format-MD5-that-allow-.patch
Type: application/octet-stream
Size: 114719 bytes
Desc: 0001-Add-glretrace-option-snapshot-format-MD5-that-allow-.patch
URL: <http://lists.freedesktop.org/archives/apitrace/attachments/20140116/e58e0d0a/attachment-0001.obj>


More information about the apitrace mailing list