commit 5e80c35da373bb571b92614ea3e462ee39834c89
Author: David Sorber <david.sorber@gmail.com>
Date:   Sat Jul 14 21:19:40 2018 -0400

    Finished up packjpg_simple utility to demonstrate that the library
    works correctly.

diff --git a/software/packJPG_library/lib_src/bin/packjpg_simple.cc b/software/packJPG_library/lib_src/bin/packjpg_simple.cc
index 84adfa6..c53f605 100644
--- a/software/packJPG_library/lib_src/bin/packjpg_simple.cc
+++ b/software/packJPG_library/lib_src/bin/packjpg_simple.cc
@@ -1,6 +1,8 @@
 #include <cstdint>
+#include <cstring>
 #include <fstream>
 #include <iostream>
+#include <string>
 #include <vector>
 
 #include <boost/filesystem.hpp>
@@ -9,6 +11,9 @@
 
 namespace bfs = boost::filesystem;
 
+const std::string JPG_EXTENSION(".jpg");
+const std::string PJG_EXTENSION(".pjg");
+
 int main(int argc, char** argv)
 {
     std::cout << "packJPG Simple Test Utility" << std::endl;
@@ -30,22 +35,76 @@ int main(int argc, char** argv)
     }    
     
     uint32_t file_size = bfs::file_size(file_path);
-    std::cout << "File size: " << file_size << std::endl;
-    std::vector<char>* file_buffer = new std::vector<char>(file_size);
+    std::cout << "File size:      " << file_size << std::endl;
+    auto file_buffer = new std::vector<unsigned char>(file_size);
     
+    // Read in the input file
     std::ifstream input_stream(file_path, std::ios::binary | std::ios::in);
     if (! input_stream)
     {
-        std::cerr << "ERROR: unable to read from \"" << file_path << "\"" 
+        std::cerr << "ERROR: unable to read from \"" << file_path << "\"\n" 
                   << std::endl;
         return -1;
     }
     
-    input_stream.read(file_buffer->data(), file_size);
+    input_stream.read((char*)file_buffer->data(), file_size);
     input_stream.close();
     
-    //~ packJPG instance = packJPG();
+    // Determine input, and therefore output, filetype / extension
+    const std::string* output_file_extension = nullptr;
+    if ((file_buffer->at(0) == 0xFF) && (file_buffer->at(1) == 0xD8))
+    {
+        output_file_extension = &PJG_EXTENSION;
+    }
+    else if ((file_buffer->at(0) == packJPG::pjg_magic[0]) && 
+             (file_buffer->at(1) == packJPG::pjg_magic[1]))
+    {
+        output_file_extension = &JPG_EXTENSION;
+    }
+    else
+    {
+        std::cerr << "Input file does not appear to be valid\n" << std::endl;
+        return -1;
+    }
+    
+    // Setup packJPG instance
+    packJPG* instance = new packJPG();    
+    instance->pjglib_init_streams(file_buffer->data(), 1, file_size, nullptr, 1);
+    
+    // Do compression/decompression
+    unsigned char* out_buffer = nullptr;
+    uint32_t out_size = 0;
+    char message[MSG_SIZE];
+    std::memset(message, 0, MSG_SIZE);
+    
+    bool rc = instance->pjglib_convert_stream2mem(&out_buffer, &out_size, message);
+    if (!rc)
+    {
+        std::cout << "An error occurred during the compression/decompression "
+                  << "operation: " << message << "\n" << std::endl;
+        return -1;
+    }
+    
+    std::cout << "Status message: " << message << std::endl;
+    std::cout << "Output size:    " << out_size << std::endl;
+    
+    bfs::path out_path = bfs::path(file_path).replace_extension(*output_file_extension);
+    std::cout << "Output file:    " << out_path << std::endl;
+    
+    // Write output file
+    std::ofstream output_stream(out_path.string(), std::ios::binary | std::ios::out);
+    if (! input_stream)
+    {
+        std::cerr << "ERROR: unable to read from \"" << file_path << "\"" 
+                  << std::endl;
+        return -1;
+    }
+    output_stream.write((const char*)out_buffer, out_size);
+    output_stream.close();
     
+    // Clean up
+    std::free(out_buffer);
+    delete instance;
     delete file_buffer;
     
     return 0;
diff --git a/software/packJPG_library/lib_src/packjpg.h b/software/packJPG_library/lib_src/packjpg.h
index f721f76..fad9c2e 100644
--- a/software/packJPG_library/lib_src/packjpg.h
+++ b/software/packJPG_library/lib_src/packjpg.h
@@ -133,6 +133,17 @@ public:
     
     bool unpack_pjg(void);
     
+    /* -----------------------------------------------
+    global variables: info about program
+    ----------------------------------------------- */
+    static const unsigned char appversion;
+    static const char*  subversion;
+    static const char*  apptitle;
+    static const char*  appname;
+    static const char*  versiondate;
+    static const char*  author;
+    static const char   pjg_magic[2];
+    
 private:
 
     /**************************************************************************
@@ -528,18 +539,6 @@ private:
     
     unsigned char nois_trs[4];  // bit pattern noise threshold
     unsigned char segm_cnt[4];  // number of segments
-    
-    /* -----------------------------------------------
-    global variables: info about program
-    ----------------------------------------------- */
-    static const unsigned char appversion;
-    static const char*  subversion;
-    static const char*  apptitle;
-    static const char*  appname;
-    static const char*  versiondate;
-    static const char*  author;
-    static const char   pjg_magic[2];
-
 };
 
 
