commit 47c82dc5c5866e3cbbf2fe9131b55801ba516e78
Author: dsorber <david.sorber@gmail.com>
Date:   Thu May 25 17:57:04 2017 -0400

    Updated packJPG to latest merged version. Also updated PCA CMake to build packJPG as an external project.

diff --git a/software/photo_compress_archiver/CMakeLists.txt b/software/photo_compress_archiver/CMakeLists.txt
index af264a7..166075d 100644
--- a/software/photo_compress_archiver/CMakeLists.txt
+++ b/software/photo_compress_archiver/CMakeLists.txt
@@ -3,10 +3,6 @@ cmake_minimum_required(VERSION 2.8)
 
 include_directories(.)
 
-set(pca_sources
-    ../PhotoCompressArchiver.cc
-)
-
 set(EXTERNAL_LIBS)
 
 find_package(Threads)
@@ -17,9 +13,26 @@ if (Boost_FOUND)
    set(EXTERNAL_LIBS ${EXTERNAL_LIBS} ${Boost_LIBRARIES})
 endif()
 
-add_definitions("-std=c++11 -g")
 
+# build packJPG as an external project
+include(ExternalProject)
+ExternalProject_Add(packjpg
+    DOWNLOAD_COMMAND pwd # fake this out since we already have the source
+    SOURCE_DIR ../packJPG
+    BINARY_DIR ../packJPG/build
+    INSTALL_DIR ../
+    INSTALL_COMMAND pwd # also fake this out, we don't want to install either
+)
+
+# PCA sources
+set(pca_sources
+    ../PhotoCompressArchiver.cc
+)
+
+# Build the PCA executable
+add_definitions("-std=c++11 -g -O3 -march=native")
 add_executable(pca
     ${pca_sources}
     ../main.cc)
+add_dependencies(pca packjpg)
 target_link_libraries(pca ${CMAKE_THREAD_LIBS_INIT} ${EXTERNAL_LIBS})
diff --git a/software/photo_compress_archiver/Makefile b/software/photo_compress_archiver/Makefile
deleted file mode 100644
index 1a59317..0000000
--- a/software/photo_compress_archiver/Makefile
+++ /dev/null
@@ -1,32 +0,0 @@
-
-CXX=clang++
-#~ CXX=g++
-CXXFLAGS=-std=c++11 -g
-OBJECTS = main.o PhotoCompressArchiver.o
-
-LDFLAGS=-L/opt/local/lib -lboost_system-mt -lboost_filesystem-mt -lboost_program_options-mt -lboost_regex-mt
-
-NUM_CORES:=$(shell grep -c ^processor /proc/cpuinfo)
-
-PACKJPG_SRC   = $(wildcard packJPG/*.cpp packJPG/*.h)
-
-all: main
-
-packjpg: $(PACKJPG_SRC)
-	@echo $(PACKJPG_SRC)
-	cd packJPG/build; cmake ..; make -j $(NUM_CORES)
-	cp packJPG/build/packjpg .
-
-main: $(OBJECTS) packjpg
-	$(CXX) $(CXXFLAGS) $(LDFLAGS) -o pca $(OBJECTS) 
-
-%.o : %.cc
-	$(CXX) $(CXXFLAGS) -I/opt/local/include -c $< 
-
-clean_packjpg:
-	rm -f packjpg
-	rm -rf packJPG/build/*
-
-clean:
-	rm -f *.o
-	rm -f pca
diff --git a/software/photo_compress_archiver/packJPG/CMakeLists.txt b/software/photo_compress_archiver/packJPG/CMakeLists.txt
index d6bbbaf..f2a7a04 100644
--- a/software/photo_compress_archiver/packJPG/CMakeLists.txt
+++ b/software/photo_compress_archiver/packJPG/CMakeLists.txt
@@ -1,4 +1,4 @@
-project("packJPG_opt")
+project("packJPG")
 cmake_minimum_required(VERSION 2.8)
 
 include_directories(.)
@@ -8,12 +8,13 @@ set(packjpg_sources
     ../bitops.cpp
 )
 
-add_definitions("-std=c++1y -O3 -Wall -pedantic -DUNIX")
+add_definitions("-std=c++14 -O3 -Wall -pedantic -DUNIX")
 add_definitions("-funroll-loops -ffast-math -fomit-frame-pointer")
 add_definitions("-march=native")
 #~ -fsched-spec-load 
-#~ add_definitions("-static -static-libgcc -static-libstdc++")
 
 add_executable(packjpg
     ${packjpg_sources}
     ../packjpg.cpp)
+
+install(TARGETS packjpg DESTINATION .)
diff --git a/software/photo_compress_archiver/packJPG/README b/software/photo_compress_archiver/packJPG/README
new file mode 100644
index 0000000..35e6c8a
--- /dev/null
+++ b/software/photo_compress_archiver/packJPG/README
@@ -0,0 +1,281 @@
+===============================================================================
+DBS - 20170525
+
+packJPG source is current as of today.
+
+https://github.com/packjpg/packJPG
+
+===============================================================================
+
+
+
+
+
+packJPG v2.5k (01/22/2016)
+~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+packJPG is a compression program specially designed for further
+compression of JPEG images without causing any further loss. Typically
+it reduces the file size of a JPEG file by 20%.
+
+
+LGPL v3 license and special permissions
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+All programs in this package are free software; you can redistribute 
+them and/or modify them under the terms of the GNU Lesser General Public 
+License as published by the Free Software Foundation; either version 3 
+of the License, or (at your option) any later version. 
+
+The package 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 Lesser 
+General Public License for more details at 
+http://www.gnu.org/copyleft/lgpl.html. 
+
+If the LGPL v3 license is not compatible with your software project you 
+might contact us and ask for a special permission to use the packJPG 
+library under different conditions. In any case, usage of the packJPG 
+algorithm under the LGPL v3 or above is highly advised and special 
+permissions will only be given where necessary on a case by case basis. 
+This offer is aimed mainly at closed source freeware developers seeking 
+to add PJG support to their software projects. 
+
+Copyright 2006...2014 by HTW Aalen University and Matthias Stirner.
+
+
+Usage of packJPG
+~~~~~~~~~~~~~~~~
+
+JPEG files are compressed and PJG files are decompressed using this
+command:
+
+ "packJPG [file(s)]"
+
+packJPG recognizes file types on its own and decides whether to compress
+(JPG) or decompress (PJG). For unrecognized file types no action is
+taken. Files are recognized by content, not by extension.
+
+packJPG supports wildcards like "*.*" and drag and drop of multiple 
+files. Filenames for output files are created automatically. In default
+mode, files are never overwritten. If a filename is already in use,
+packJPG creates a new filename by adding underscores.
+
+If "-" is used as a filename input from stdin is assumed and output is
+written to stdout. This can be useful for example if jpegtran is to be
+used as a preprocessor.
+
+Usage examples:
+
+ "packJPG *.pjg"
+ "packJPG lena.jpg"
+ "packJPG kodim??.jpg"
+ "packJPG - < sail.pjg > sail.jpg"
+
+
+Command line switches
+~~~~~~~~~~~~~~~~~~~~~
+
+ -ver  verify files after processing
+ -v?   level of verbosity; 0,1 or 2 is allowed (default 0)
+ -np   no pause after processing files
+ -o    overwrite existing files
+ -p    proceed on warnings
+ -d    discard meta-info
+
+By default, compression is cancelled on warnings. If warnings are 
+skipped by using "-p", most files with warnings can also be compressed, 
+but JPEG files reconstructed from PJG files might not be bitwise 
+identical with the original JPEG files. There won't be any loss to 
+image data or quality however.
+
+Unnecessary meta information can be discarded using "-d". This reduces 
+compressed files' sizes. Be warned though, reconstructed files won't be 
+bitwise identical with the original files and meta information will be 
+lost forever. As with "-p" there won't be any loss to image data or 
+quality. 
+
+There is no known case in which a file compressed by packJPG (without 
+the "-p" option, see above) couldn't be reconstructed to exactly the 
+state it was before. If you want an additional layer of safety you can 
+also use the verify option "-ver". In this mode, files are compressed, 
+then decompressed and the decompressed file compared to the original 
+file. If this test doesn't pass there will be an error message and the 
+compressed file won't be written to the drive. 
+
+Please note that the "-ver" option should never be used in conjunction 
+with the "-d" and/or "-p" options. As stated above, the "-p" and "-d" 
+options will most likely lead to reconstructed JPG files not being 
+bitwise identical to the original JPG files. In turn, the verification 
+process may fail on various files although nothing actually went wrong. 
+
+Usage examples:
+
+ "packJPG -v1 -o baboon.pjg"
+ "packJPG -ver lena.jpg"
+ "packJPG -d tiffany.jpg"
+ "packJPG -p *.jpg"
+
+
+Known Limitations 
+~~~~~~~~~~~~~~~~~ 
+
+packJPG is a compression program specially for JPEG files, so it doesn't 
+compress other file types.
+
+packJPG has low error tolerance. JPEG files might not work with packJPG 
+even if they work perfectly with other image processing software. The 
+command line switch "-p" can be used to increase error tolerance and 
+compatibility.
+
+If you try to drag and drop to many files at once, there might be a 
+windowed error message about missing privileges. In that case you can 
+try it again with less files or consider using the command prompt. 
+packJPG has been tested to work perfectly with thousands of files from 
+the command line. This issue also happens with drag and drop in other 
+applications, so it might not be a limitation of packJPG but a 
+limitation of Windows.
+
+Compressed PJG files are not compatible between different packJPG 
+versions. You will get an error message if you try to decompress PJG 
+files with a different version than the one used for compression. You 
+may download older versions of packJPG from:
+http://www.elektronik.htw-aalen.de/packJPG/binaries/old/
+
+
+Open source release / developer info
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+The packJPG source codes is found inside the "source" subdirectory. 
+Additional documents aimed to developers, containing detailed 
+instructions on compiling the source code and using special 
+functionality, are included in the "packJPG" subdirectory. 
+ 
+
+History
+~~~~~~~
+
+v1.9a (04/20/2007) (non public)
+ - first released version
+ - only for testing purposes
+
+v2.0  (05/28/2007) (public)
+ - first public version of packJPG
+ - minor improvements to overall compression
+ - minor bugfixes
+
+v2.2  (08/05/2007) (public)
+ - around 40% faster compression & decompression
+ - major improvements to overall compression (around 2% on average)
+ - reading from stdin, writing to stdout
+ - smaller executable
+ - minor bugfixes
+ - various minor improvements
+ 
+v2.3  (09/18/2007) (public)
+ - compatibility with JPEG progressive mode
+ - compatibility with JPEG extended sequential mode
+ - compatibility with the CMYK color space
+ - compatibility with older CPUs
+ - around 15% faster compression & decompression 
+ - new switch: [-d] (discard meta-info)
+ - various bugfixes
+
+v2.3a (11/21/2007) (public)
+ - crash issue with certain images fixed
+ - compatibility with packJPG v2.3 maintained
+
+v2.3b (12/20/2007) (public)
+ - some minor errors in the packJPG library fixed
+ - compatibility with packJPG v2.3 maintained
+ 
+v2.4 (03/24/2010) (public)
+ - major improvements (1%...2%) to overall compression
+ - around 10% faster compression & decompression
+ - major improvements to JPG compatibility
+ - size of executable reduced to ~33%
+ - new switch: [-ver] (verify file after processing)
+ - new switch: [-np] (no pause after processing)
+ - new progress bar output mode
+ - arithmetic coding routines rewritten from scratch
+ - various smaller improvements to numerous to list here
+ - new SFX (self extracting) archive format
+ 
+v2.5 (11/11/2011) (public)
+ - improvements (~0.5%) to overall compression
+ - several minor bugfixes
+ - major code cleanup
+ - removed packJPX from the package
+ - added packARC to the package
+ - packJPG is now open source!
+ 
+v2.5a (11/21/11) (public)
+ - source code compatibility improvements (Gerhard Seelmann)
+ - avoid some compiler warnings (Gerhard Seelmann)
+ - source code clean up (Gerhard Seelmann)
+ 
+v2.5b (01/27/12) (public)
+ - further removal of redundant code
+ - some fixes for the packJPG static library
+ - compiler fix for Mac OS (thanks to Sergio Lopez)
+ - improved compression ratio calculation
+ - eliminated the need for temp files
+ 
+v2.5c (04/13/12) (public)
+ - various source code optimizations
+ 
+v2.5d (07/03/12) (public)
+ - fixed a rare bug with progressive JPEG
+ 
+v2.5e (07/03/12) (public)
+ - some minor source code optimizations
+ - changed packJPG licensing to LGPL
+ - moved packARC to a separate package
+ 
+v2.5f (02/24/13) (public)
+ - fixed a minor bug in the JPG parser (thanks to Stephan Busch)
+ 
+v2.5g (09/14/13) (public)
+ - fixed a rare crash bug with manipulated JPEG files
+ 
+v2.5h (12/07/13) (public)
+ - added a warning for inefficient huffman coding (thanks to Moinak Ghosh)
+ 
+v2.5i (12/26/13) (public)
+ - fixed possible crash with malformed JPEG (thanks to Moinak Ghosh)
+ 
+v2.5j (01/15/14) (public)
+ - various source code optimizations (using cppcheck)
+
+v2.5k (01/22/16) (public)
+ - Updated contact info
+ - fixed a minor bug
+
+
+Acknowledgements
+~~~~~~~~~~~~~~~~
+
+packJPG is the result of countless hours of research and development. It
+is part of my final year project for Hochschule Aalen.
+
+Prof. Dr. Gerhard Seelmann from Hochschule Aalen supported my
+development of packJPG with his extensive knowledge in the field of data
+compression. Without his advice, packJPG would not be possible.
+
+The official developer blog for packJPG is hosted by encode.ru.
+
+packJPG logo and icon are designed by Michael Kaufmann.
+
+
+Contact
+~~~~~~~
+
+The official developer blog for packJPG:
+ http://packjpg.encode.ru/
+ 
+For questions and bug reports:
+ packjpg (at) matthiasstirner.com
+
+
+____________________________________
+packJPG by Matthias Stirner, 01/2016
diff --git a/software/photo_compress_archiver/packJPG/Readme.txt b/software/photo_compress_archiver/packJPG/Readme.txt
deleted file mode 100644
index 181be72..0000000
--- a/software/photo_compress_archiver/packJPG/Readme.txt
+++ /dev/null
@@ -1,290 +0,0 @@
-===============================================================================
-DBS - 20170218
-
-NOTE: This is a branch of the original packJPG code base that contains some 
-improvements. It came from here:
-
-https://github.com/TarVanimelde/packJPG
-
-At time of writing these improvements have been submitted as a pull request, 
-but it has not (yet) been accepted. The associated description is:
-
-"Bitops and Aricoder Performance Enhancements, Visual Studio Compilation Fix"
-
-I have remove unnecssary files (icons, .spec file, etc.) and added a 
-CMakeLists.txt CMake configuration file in favor of the existing Makefile.
-
-===============================================================================
-
-
-
-
-
-packJPG v2.5k (01/22/2016)
-~~~~~~~~~~~~~~~~~~~~~~~~~~
-
-packJPG is a compression program specially designed for further
-compression of JPEG images without causing any further loss. Typically
-it reduces the file size of a JPEG file by 20%.
-
-
-LGPL v3 license and special permissions
-~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-
-All programs in this package are free software; you can redistribute 
-them and/or modify them under the terms of the GNU Lesser General Public 
-License as published by the Free Software Foundation; either version 3 
-of the License, or (at your option) any later version. 
-
-The package 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 Lesser 
-General Public License for more details at 
-http://www.gnu.org/copyleft/lgpl.html. 
-
-If the LGPL v3 license is not compatible with your software project you 
-might contact us and ask for a special permission to use the packJPG 
-library under different conditions. In any case, usage of the packJPG 
-algorithm under the LGPL v3 or above is highly advised and special 
-permissions will only be given where necessary on a case by case basis. 
-This offer is aimed mainly at closed source freeware developers seeking 
-to add PJG support to their software projects. 
-
-Copyright 2006...2014 by HTW Aalen University and Matthias Stirner.
-
-
-Usage of packJPG
-~~~~~~~~~~~~~~~~
-
-JPEG files are compressed and PJG files are decompressed using this
-command:
-
- "packJPG [file(s)]"
-
-packJPG recognizes file types on its own and decides whether to compress
-(JPG) or decompress (PJG). For unrecognized file types no action is
-taken. Files are recognized by content, not by extension.
-
-packJPG supports wildcards like "*.*" and drag and drop of multiple 
-files. Filenames for output files are created automatically. In default
-mode, files are never overwritten. If a filename is already in use,
-packJPG creates a new filename by adding underscores.
-
-If "-" is used as a filename input from stdin is assumed and output is
-written to stdout. This can be useful for example if jpegtran is to be
-used as a preprocessor.
-
-Usage examples:
-
- "packJPG *.pjg"
- "packJPG lena.jpg"
- "packJPG kodim??.jpg"
- "packJPG - < sail.pjg > sail.jpg"
-
-
-Command line switches
-~~~~~~~~~~~~~~~~~~~~~
-
- -ver  verify files after processing
- -v?   level of verbosity; 0,1 or 2 is allowed (default 0)
- -np   no pause after processing files
- -o    overwrite existing files
- -p    proceed on warnings
- -d    discard meta-info
-
-By default, compression is cancelled on warnings. If warnings are 
-skipped by using "-p", most files with warnings can also be compressed, 
-but JPEG files reconstructed from PJG files might not be bitwise 
-identical with the original JPEG files. There won't be any loss to 
-image data or quality however.
-
-Unnecessary meta information can be discarded using "-d". This reduces 
-compressed files' sizes. Be warned though, reconstructed files won't be 
-bitwise identical with the original files and meta information will be 
-lost forever. As with "-p" there won't be any loss to image data or 
-quality. 
-
-There is no known case in which a file compressed by packJPG (without 
-the "-p" option, see above) couldn't be reconstructed to exactly the 
-state it was before. If you want an additional layer of safety you can 
-also use the verify option "-ver". In this mode, files are compressed, 
-then decompressed and the decompressed file compared to the original 
-file. If this test doesn't pass there will be an error message and the 
-compressed file won't be written to the drive. 
-
-Please note that the "-ver" option should never be used in conjunction 
-with the "-d" and/or "-p" options. As stated above, the "-p" and "-d" 
-options will most likely lead to reconstructed JPG files not being 
-bitwise identical to the original JPG files. In turn, the verification 
-process may fail on various files although nothing actually went wrong. 
-
-Usage examples:
-
- "packJPG -v1 -o baboon.pjg"
- "packJPG -ver lena.jpg"
- "packJPG -d tiffany.jpg"
- "packJPG -p *.jpg"
-
-
-Known Limitations 
-~~~~~~~~~~~~~~~~~ 
-
-packJPG is a compression program specially for JPEG files, so it doesn't 
-compress other file types.
-
-packJPG has low error tolerance. JPEG files might not work with packJPG 
-even if they work perfectly with other image processing software. The 
-command line switch "-p" can be used to increase error tolerance and 
-compatibility.
-
-If you try to drag and drop to many files at once, there might be a 
-windowed error message about missing privileges. In that case you can 
-try it again with less files or consider using the command prompt. 
-packJPG has been tested to work perfectly with thousands of files from 
-the command line. This issue also happens with drag and drop in other 
-applications, so it might not be a limitation of packJPG but a 
-limitation of Windows.
-
-Compressed PJG files are not compatible between different packJPG 
-versions. You will get an error message if you try to decompress PJG 
-files with a different version than the one used for compression. You 
-may download older versions of packJPG from:
-http://www.elektronik.htw-aalen.de/packJPG/binaries/old/
-
-
-Open source release / developer info
-~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-
-The packJPG source codes is found inside the "source" subdirectory. 
-Additional documents aimed to developers, containing detailed 
-instructions on compiling the source code and using special 
-functionality, are included in the "packJPG" subdirectory. 
- 
-
-History
-~~~~~~~
-
-v1.9a (04/20/2007) (non public)
- - first released version
- - only for testing purposes
-
-v2.0  (05/28/2007) (public)
- - first public version of packJPG
- - minor improvements to overall compression
- - minor bugfixes
-
-v2.2  (08/05/2007) (public)
- - around 40% faster compression & decompression
- - major improvements to overall compression (around 2% on average)
- - reading from stdin, writing to stdout
- - smaller executable
- - minor bugfixes
- - various minor improvements
- 
-v2.3  (09/18/2007) (public)
- - compatibility with JPEG progressive mode
- - compatibility with JPEG extended sequential mode
- - compatibility with the CMYK color space
- - compatibility with older CPUs
- - around 15% faster compression & decompression 
- - new switch: [-d] (discard meta-info)
- - various bugfixes
-
-v2.3a (11/21/2007) (public)
- - crash issue with certain images fixed
- - compatibility with packJPG v2.3 maintained
-
-v2.3b (12/20/2007) (public)
- - some minor errors in the packJPG library fixed
- - compatibility with packJPG v2.3 maintained
- 
-v2.4 (03/24/2010) (public)
- - major improvements (1%...2%) to overall compression
- - around 10% faster compression & decompression
- - major improvements to JPG compatibility
- - size of executable reduced to ~33%
- - new switch: [-ver] (verify file after processing)
- - new switch: [-np] (no pause after processing)
- - new progress bar output mode
- - arithmetic coding routines rewritten from scratch
- - various smaller improvements to numerous to list here
- - new SFX (self extracting) archive format
- 
-v2.5 (11/11/2011) (public)
- - improvements (~0.5%) to overall compression
- - several minor bugfixes
- - major code cleanup
- - removed packJPX from the package
- - added packARC to the package
- - packJPG is now open source!
- 
-v2.5a (11/21/11) (public)
- - source code compatibility improvements (Gerhard Seelmann)
- - avoid some compiler warnings (Gerhard Seelmann)
- - source code clean up (Gerhard Seelmann)
- 
-v2.5b (01/27/12) (public)
- - further removal of redundant code
- - some fixes for the packJPG static library
- - compiler fix for Mac OS (thanks to Sergio Lopez)
- - improved compression ratio calculation
- - eliminated the need for temp files
- 
-v2.5c (04/13/12) (public)
- - various source code optimizations
- 
-v2.5d (07/03/12) (public)
- - fixed a rare bug with progressive JPEG
- 
-v2.5e (07/03/12) (public)
- - some minor source code optimizations
- - changed packJPG licensing to LGPL
- - moved packARC to a separate package
- 
-v2.5f (02/24/13) (public)
- - fixed a minor bug in the JPG parser (thanks to Stephan Busch)
- 
-v2.5g (09/14/13) (public)
- - fixed a rare crash bug with manipulated JPEG files
- 
-v2.5h (12/07/13) (public)
- - added a warning for inefficient huffman coding (thanks to Moinak Ghosh)
- 
-v2.5i (12/26/13) (public)
- - fixed possible crash with malformed JPEG (thanks to Moinak Ghosh)
- 
-v2.5j (01/15/14) (public)
- - various source code optimizations (using cppcheck)
-
-v2.5k (01/22/16) (public)
- - Updated contact info
- - fixed a minor bug
-
-
-Acknowledgements
-~~~~~~~~~~~~~~~~
-
-packJPG is the result of countless hours of research and development. It
-is part of my final year project for Hochschule Aalen.
-
-Prof. Dr. Gerhard Seelmann from Hochschule Aalen supported my
-development of packJPG with his extensive knowledge in the field of data
-compression. Without his advice, packJPG would not be possible.
-
-The official developer blog for packJPG is hosted by encode.ru.
-
-packJPG logo and icon are designed by Michael Kaufmann.
-
-
-Contact
-~~~~~~~
-
-The official developer blog for packJPG:
- http://packjpg.encode.ru/
- 
-For questions and bug reports:
- packjpg (at) matthiasstirner.com
-
-
-____________________________________
-packJPG by Matthias Stirner, 01/2016
diff --git a/software/photo_compress_archiver/packJPG/aricoder.cpp b/software/photo_compress_archiver/packJPG/aricoder.cpp
index 600f356..dfc18bf 100644
--- a/software/photo_compress_archiver/packJPG/aricoder.cpp
+++ b/software/photo_compress_archiver/packJPG/aricoder.cpp
@@ -14,7 +14,7 @@ aricoder::aricoder( iostream* stream, StreamMode iomode ) : sptr(stream), mode(i
 {
 	if ( mode == StreamMode::kRead) { // mode is reading / decoding
 		// code buffer has to be filled before starting decoding
-		for (uint32_t i = 0; i < CODER_USE_BITS; i++ )
+		for (int i = 0; i < CODER_USE_BITS; i++ )
 			ccode = ( ccode << 1 ) | read_bit();
 	} // mode is writing / encoding otherwise
 }
@@ -190,12 +190,10 @@ void aricoder::decode( symbol* s )
 		chigh_local++;
 		ccode_local <<= 1;
 		ccode_local |= read_bit();
-		nrbits = 0;
 	}
 	
 	// e3 scaling, to make sure that theres enough space between low and high
 	while ( (clow_local >= CODER_LIMIT025 ) && (chigh_local < CODER_LIMIT075 ) ) {
-		nrbits++;
 		clow_local &= CODER_LIMIT025 - 1;
 		chigh_local ^= CODER_LIMIT025 + CODER_LIMIT050;
 		// clow  -= CODER_LIMIT025;
@@ -455,7 +453,7 @@ int model_s::convert_symbol_to_int(uint32_t count, symbol *s)
 
 
 	// go through the totals table, search the symbol that matches the count
-	uint32_t c;
+	int c;
 	for (c = 1; c < totals.size(); c++) {
 		if (count >= totals[c]) {
 			break;
diff --git a/software/photo_compress_archiver/packJPG/bitops.cpp b/software/photo_compress_archiver/packJPG/bitops.cpp
index fff0983..01b9154 100644
--- a/software/photo_compress_archiver/packJPG/bitops.cpp
+++ b/software/photo_compress_archiver/packJPG/bitops.cpp
@@ -8,7 +8,7 @@ reading and writing of arrays
 #include <algorithm>
 #include <array>
 #include <cstdio>
-#include <cstdlib>
+#include <stdlib.h>
 #include <vector>
 
 #if defined(_WIN32) || defined(WIN32)
@@ -246,7 +246,7 @@ void abitwriter::write( unsigned int val, int nbits )
 			return;
 		}
 		dsize *= 2;
-		std::fill(data + cbyte + 1, data + dsize, 0);
+		std::fill(data + cbyte + 1, data + dsize, static_cast<unsigned char>(0));
 	}
 	
 	// write data
@@ -284,7 +284,7 @@ void abitwriter::write_bit( unsigned char bit )
 				return;
 			}
 			dsize *= 2;
-			std::fill(data + cbyte + 1, data + dsize, 0);
+			std::fill(data + cbyte + 1, data + dsize, static_cast<unsigned char>(0));
 		}
 		cbit = 8;
 	} 
diff --git a/software/photo_compress_archiver/packJPG/packjpg.cpp b/software/photo_compress_archiver/packJPG/packjpg.cpp
index 581ae3e..db56f9e 100644
--- a/software/photo_compress_archiver/packJPG/packjpg.cpp
+++ b/software/photo_compress_archiver/packJPG/packjpg.cpp
@@ -1028,7 +1028,7 @@ EXPORT void pjglib_init_streams( void* in_src, int in_type, int in_size, void* o
 	if ( pjgfilename != NULL ) free( pjgfilename ); pjgfilename = NULL;
 	
 	// check input stream
-	str_in->read( buffer, 1, 2 );
+	str_in->read( buffer, 2 );
 	if ( ( buffer[0] == 0xFF ) && ( buffer[1] == 0xD8 ) ) {
 		// file is JPEG
 		filetype = F_JPG;
@@ -2864,7 +2864,7 @@ INTERN bool recode_jpeg( void )
 						
 						// encode block
 						eob = jpg_encode_block_seq( huffw,
-							&(hcodes[ 0 ][ cmpnfo[cmp].huffac ]),
+							&(hcodes[ 0 ][ cmpnfo[cmp].huffdc ]),
 							&(hcodes[ 1 ][ cmpnfo[cmp].huffac ]),
 							block );
 						
@@ -2923,7 +2923,7 @@ INTERN bool recode_jpeg( void )
 						
 						// encode block
 						eob = jpg_encode_block_seq( huffw,
-							&(hcodes[ 0 ][ cmpnfo[cmp].huffac ]),
+							&(hcodes[ 0 ][ cmpnfo[cmp].huffdc ]),
 							&(hcodes[ 1 ][ cmpnfo[cmp].huffac ]),
 							block );
 						
