├── .gitignore ├── LICENSE ├── Readme.txt └── source ├── build_packarc_linux.sh ├── build_packarc_msdos.bat ├── packANY ├── packANYlib │ ├── Makefile_dll │ ├── Makefile_lib │ ├── Makefile_lib_DM │ ├── Makefile_lib_Linux │ ├── Makefile_lib_Os │ ├── Makefile_lib_Os_Linux │ ├── Makefile_lib_VG │ ├── packANYdll.h │ └── packANYlib.h ├── packARI │ ├── Makefile │ ├── Makefile_dll │ ├── Makefile_lib │ ├── app_icon.ico │ ├── aricoder.cpp │ ├── aricoder.h │ ├── bitops.cpp │ ├── bitops.h │ ├── file_icon.ico │ ├── icons.rc │ ├── icons.res │ ├── packari.cpp │ ├── packaridll.h │ ├── packarilib.h │ └── paritbl.h ├── packJPG │ ├── Makefile │ ├── Makefile_dll │ ├── Makefile_lib │ ├── Makefile_linux │ ├── app_icon.ico │ ├── aricoder.cpp │ ├── aricoder.h │ ├── bitops.cpp │ ├── bitops.h │ ├── dct8x8.h │ ├── file_icon.ico │ ├── icons.rc │ ├── icons.res │ ├── packjpg.cpp │ ├── packjpgdll.h │ ├── packjpglib.h │ └── pjpgtbl.h ├── packMP3 │ ├── Makefile │ ├── Makefile_dll │ ├── Makefile_lib │ ├── app_icon.ico │ ├── aricoder.cpp │ ├── aricoder.h │ ├── bitops.cpp │ ├── bitops.h │ ├── file_icon.ico │ ├── huffmp3.cpp │ ├── huffmp3.h │ ├── huffmp3tbl.h │ ├── icons.rc │ ├── icons.res │ ├── packmp3.cpp │ ├── packmp3dll.h │ ├── packmp3lib.h │ ├── pmp3bitlen.h │ └── pmp3tbl.h └── packPNM │ ├── Makefile │ ├── Makefile_dll │ ├── Makefile_lib │ ├── app_icon.ico │ ├── aricoder.cpp │ ├── aricoder.h │ ├── bitops.cpp │ ├── bitops.h │ ├── file_icon.ico │ ├── icons.rc │ ├── icons.res │ ├── packpnm.cpp │ ├── packpnmdll.h │ ├── packpnmlib.h │ ├── ppnmbitlen.h │ └── ppnmtbl.h └── packARC ├── Makefile.linux ├── Makefile.win ├── Makefile_dm.win ├── Makefile_sfx_stub.linux ├── Makefile_sfx_stub.win ├── Makefile_sfx_stub_dm.win ├── alt_ico ├── app_icon.ico ├── app_icon_alt.ico ├── app_icon_blue.ico ├── app_icon_gray.ico ├── app_icon_green.ico ├── app_icon_red.ico ├── file_icon_blue.ico ├── file_icon_gray.ico ├── file_icon_green.ico ├── file_icon_red.ico ├── icons_app.rc ├── icons_app.res ├── png.zip ├── sfx_icon_blue.ico ├── sfx_icon_gray.ico ├── sfx_icon_green.ico └── sfx_icon_red.ico ├── app_icon.ico ├── file_icon.ico ├── frontend.cpp ├── helpers.cpp ├── helpers.h ├── icons_app.rc ├── icons_app.res ├── icons_sfx.rc ├── icons_sfx.res ├── lfs_supp.h ├── packANYlib.h ├── pja_archiver.cpp ├── pja_archiver.h ├── sfx_icon.ico └── sfxstub2h.c /.gitignore: -------------------------------------------------------------------------------- 1 | # Compiled Object files 2 | *.slo 3 | *.lo 4 | *.o 5 | *.obj 6 | 7 | # Precompiled Headers 8 | *.gch 9 | *.pch 10 | 11 | # Compiled Dynamic libraries 12 | *.so 13 | *.dylib 14 | *.dll 15 | 16 | # Fortran module files 17 | *.mod 18 | 19 | # Compiled Static libraries 20 | *.lai 21 | *.la 22 | *.a 23 | *.lib 24 | 25 | # Executables 26 | *.exe 27 | *.out 28 | *.app 29 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | GNU LESSER GENERAL PUBLIC LICENSE 2 | Version 3, 29 June 2007 3 | 4 | Copyright (C) 2007 Free Software Foundation, Inc. 5 | Everyone is permitted to copy and distribute verbatim copies 6 | of this license document, but changing it is not allowed. 7 | 8 | 9 | This version of the GNU Lesser General Public License incorporates 10 | the terms and conditions of version 3 of the GNU General Public 11 | License, supplemented by the additional permissions listed below. 12 | 13 | 0. Additional Definitions. 14 | 15 | As used herein, "this License" refers to version 3 of the GNU Lesser 16 | General Public License, and the "GNU GPL" refers to version 3 of the GNU 17 | General Public License. 18 | 19 | "The Library" refers to a covered work governed by this License, 20 | other than an Application or a Combined Work as defined below. 21 | 22 | An "Application" is any work that makes use of an interface provided 23 | by the Library, but which is not otherwise based on the Library. 24 | Defining a subclass of a class defined by the Library is deemed a mode 25 | of using an interface provided by the Library. 26 | 27 | A "Combined Work" is a work produced by combining or linking an 28 | Application with the Library. The particular version of the Library 29 | with which the Combined Work was made is also called the "Linked 30 | Version". 31 | 32 | The "Minimal Corresponding Source" for a Combined Work means the 33 | Corresponding Source for the Combined Work, excluding any source code 34 | for portions of the Combined Work that, considered in isolation, are 35 | based on the Application, and not on the Linked Version. 36 | 37 | The "Corresponding Application Code" for a Combined Work means the 38 | object code and/or source code for the Application, including any data 39 | and utility programs needed for reproducing the Combined Work from the 40 | Application, but excluding the System Libraries of the Combined Work. 41 | 42 | 1. Exception to Section 3 of the GNU GPL. 43 | 44 | You may convey a covered work under sections 3 and 4 of this License 45 | without being bound by section 3 of the GNU GPL. 46 | 47 | 2. Conveying Modified Versions. 48 | 49 | If you modify a copy of the Library, and, in your modifications, a 50 | facility refers to a function or data to be supplied by an Application 51 | that uses the facility (other than as an argument passed when the 52 | facility is invoked), then you may convey a copy of the modified 53 | version: 54 | 55 | a) under this License, provided that you make a good faith effort to 56 | ensure that, in the event an Application does not supply the 57 | function or data, the facility still operates, and performs 58 | whatever part of its purpose remains meaningful, or 59 | 60 | b) under the GNU GPL, with none of the additional permissions of 61 | this License applicable to that copy. 62 | 63 | 3. Object Code Incorporating Material from Library Header Files. 64 | 65 | The object code form of an Application may incorporate material from 66 | a header file that is part of the Library. You may convey such object 67 | code under terms of your choice, provided that, if the incorporated 68 | material is not limited to numerical parameters, data structure 69 | layouts and accessors, or small macros, inline functions and templates 70 | (ten or fewer lines in length), you do both of the following: 71 | 72 | a) Give prominent notice with each copy of the object code that the 73 | Library is used in it and that the Library and its use are 74 | covered by this License. 75 | 76 | b) Accompany the object code with a copy of the GNU GPL and this license 77 | document. 78 | 79 | 4. Combined Works. 80 | 81 | You may convey a Combined Work under terms of your choice that, 82 | taken together, effectively do not restrict modification of the 83 | portions of the Library contained in the Combined Work and reverse 84 | engineering for debugging such modifications, if you also do each of 85 | the following: 86 | 87 | a) Give prominent notice with each copy of the Combined Work that 88 | the Library is used in it and that the Library and its use are 89 | covered by this License. 90 | 91 | b) Accompany the Combined Work with a copy of the GNU GPL and this license 92 | document. 93 | 94 | c) For a Combined Work that displays copyright notices during 95 | execution, include the copyright notice for the Library among 96 | these notices, as well as a reference directing the user to the 97 | copies of the GNU GPL and this license document. 98 | 99 | d) Do one of the following: 100 | 101 | 0) Convey the Minimal Corresponding Source under the terms of this 102 | License, and the Corresponding Application Code in a form 103 | suitable for, and under terms that permit, the user to 104 | recombine or relink the Application with a modified version of 105 | the Linked Version to produce a modified Combined Work, in the 106 | manner specified by section 6 of the GNU GPL for conveying 107 | Corresponding Source. 108 | 109 | 1) Use a suitable shared library mechanism for linking with the 110 | Library. A suitable mechanism is one that (a) uses at run time 111 | a copy of the Library already present on the user's computer 112 | system, and (b) will operate properly with a modified version 113 | of the Library that is interface-compatible with the Linked 114 | Version. 115 | 116 | e) Provide Installation Information, but only if you would otherwise 117 | be required to provide such information under section 6 of the 118 | GNU GPL, and only to the extent that such information is 119 | necessary to install and execute a modified version of the 120 | Combined Work produced by recombining or relinking the 121 | Application with a modified version of the Linked Version. (If 122 | you use option 4d0, the Installation Information must accompany 123 | the Minimal Corresponding Source and Corresponding Application 124 | Code. If you use option 4d1, you must provide the Installation 125 | Information in the manner specified by section 6 of the GNU GPL 126 | for conveying Corresponding Source.) 127 | 128 | 5. Combined Libraries. 129 | 130 | You may place library facilities that are a work based on the 131 | Library side by side in a single library together with other library 132 | facilities that are not Applications and are not covered by this 133 | License, and convey such a combined library under terms of your 134 | choice, if you do both of the following: 135 | 136 | a) Accompany the combined library with a copy of the same work based 137 | on the Library, uncombined with any other library facilities, 138 | conveyed under the terms of this License. 139 | 140 | b) Give prominent notice with the combined library that part of it 141 | is a work based on the Library, and explaining where to find the 142 | accompanying uncombined form of the same work. 143 | 144 | 6. Revised Versions of the GNU Lesser General Public License. 145 | 146 | The Free Software Foundation may publish revised and/or new versions 147 | of the GNU Lesser General Public License from time to time. Such new 148 | versions will be similar in spirit to the present version, but may 149 | differ in detail to address new problems or concerns. 150 | 151 | Each version is given a distinguishing version number. If the 152 | Library as you received it specifies that a certain numbered version 153 | of the GNU Lesser General Public License "or any later version" 154 | applies to it, you have the option of following the terms and 155 | conditions either of that published version or of any later version 156 | published by the Free Software Foundation. If the Library as you 157 | received it does not specify a version number of the GNU Lesser 158 | General Public License, you may choose any version of the GNU Lesser 159 | General Public License ever published by the Free Software Foundation. 160 | 161 | If the Library as you received it specifies that a proxy can decide 162 | whether future versions of the GNU Lesser General Public License shall 163 | apply, that proxy's public statement of acceptance of any version is 164 | permanent authorization for you to choose that version for the 165 | Library. 166 | -------------------------------------------------------------------------------- /Readme.txt: -------------------------------------------------------------------------------- 1 | packARC v0.7RC18 (12/17/2014) 2 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 3 | 4 | packARC is an archiver program specially designed for lossless further 5 | compression of media files in the JPEG, MP3, BMP and PNM formats. It 6 | contains all of my latest developments, the packJPG, packMP3, packPNM 7 | and packARI algorithms with an easy to use command line interface. 8 | Typical further compression for JPEG is ~20%, for MP3 it is ~16% and for 9 | PNM, BMP and other file types it is highly dependent on the contents of 10 | the file. 11 | 12 | packARC creates .pja archives, which may contain several files of 13 | arbitrary file type. In general packARC is not as efficient as ZIP, RAR, 14 | or 7z when compressing generic files, but it performs very good for JPG, 15 | MP3, BMP and PNM-files. 16 | 17 | Besides the archiver program, packARC, this package also contains the 18 | source code for packJPG, packMP3, packPNM, and packARI. packJPG, 19 | packMP3, packPNM and packARI do not create archives, but compress JPG, 20 | MP3, PNM or, in the case of packARI, generic files on a file by file 21 | basis. 22 | 23 | 24 | LGPL v3 license and special permissions 25 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 26 | 27 | All programs in this package are free software; you can redistribute 28 | them and/or modify them under the terms of the GNU Lesser General Public 29 | License as published by the Free Software Foundation; either version 3 30 | of the License, or (at your option) any later version. 31 | 32 | The package is distributed in the hope that it will be useful, but 33 | WITHOUT ANY WARRANTY; without even the implied warranty of 34 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser 35 | General Public License for more details at 36 | http://www.gnu.org/copyleft/lgpl.html. 37 | 38 | If the LGPL v3 license is not compatible with your software project you 39 | might contact us and ask for a special permission to use packARC or the 40 | packANY library under different conditions. In any case, usage of the 41 | packARC algorithm under the LGPL v3 or above is highly advised and 42 | special permissions will only be given where necessary on a case by case 43 | basis. This offer is aimed mainly at closed source freeware developers 44 | seeking to add packARC support to their software projects. 45 | 46 | Copyright 2006...2016 by HTW Aalen University and Matthias Stirner. 47 | 48 | 49 | Compression algorithms and file types 50 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 51 | 52 | packARC contains four unique compression algorithms, packJPG, packMP3, 53 | packPNM and packARI in one easy to use command line interface. Files 54 | will be compressed into either the regular PJA (packJPG Archive) or SFX 55 | (self extracting archive) formats. SFX archives are executable files 56 | that extract their own contents upon execution. 57 | 58 | packARC will handle any type of file. Folders specified as file name are 59 | recursed and all contained files added to the archive while preserving 60 | relative folder structure. For regular files, the compression algorithm 61 | to use is decided on a per file base, automatically analyzing each file 62 | before adding it to the archive. 63 | 64 | The packJPG algorithm handles image files in the JPEG file format. 65 | Basically all types of JPEG files, baseline, extended sequential, 66 | progressive, CMYK and YCbCr are supported by packJPG. 67 | 68 | The packMP3 algorithm handles audio files in the MPEG-1 Audio Layer III 69 | format. Files in MPEG-2/2.5 Audio Layer III format are not supported. 70 | You may distinguish these from MPEG-1 Audio Layer III by their sample 71 | rates. Only MPEG-1 Audio Layer III supports sample rates of 32kHz and 72 | above. 73 | 74 | The packPNM algorithm handles image files in the BMP format and the PPM 75 | 8bit/16bit, PGM 8bit/16bit and PBM binary formats (the respective ASCII 76 | based formats are not supported). Unless the image file has structural 77 | errors it will always be compressed using the packPNM algorithm. 78 | 79 | All other and unrecognized files are handled by the packARI algorithm, 80 | which consists of arithmetic coding with a simple variable order 81 | statistical model. 82 | 83 | 84 | Usage of packARC 85 | ~~~~~~~~~~~~~~~~ 86 | 87 | The following paragraphs explain the general usage of packARC. In these 88 | praragraphs, [] is used for required paramters, <> is used for optional 89 | parameters. 90 | 91 | You may create a new PJA archive or add files to an existing archive 92 | using this command: 93 | 94 | "packARC a [name_of_archive] [file(s)_to_add]" 95 | 96 | When extracting, specifying files to extract is optional as indicated by 97 | the <>. If you leave it blank, all files inside the archive are 98 | extracted. To extract files from an existing archive use this command: 99 | 100 | "packARC x [name_of_archive] " 101 | 102 | packARC can extract archive contents to memory and compare extracted 103 | CRC32s with original CRCs, making sure that all files inside the archive 104 | are ok. To test archive integrity, use this command: 105 | 106 | "packARC t [name_of_archive]" 107 | 108 | To convert an existing regular archive to SFX (self extracting archive) 109 | format or to convert an SFX archive to regular archive format use the 110 | following command. packARC will automatically choose the direction of 111 | the conversion based on the format of the input archive. 112 | 113 | "packARC c [name_of_archive]" 114 | 115 | You may delete unwanted files from an archive using the delete command. 116 | Use this syntax: 117 | 118 | "packARC d [name_of_archive] [file(s)_to_delete]" 119 | 120 | To list the contents of an archive, use the list command: 121 | 122 | "packARC l [name_of_archive]" 123 | 124 | packARC handles SFX archives the same way as it handles regular 125 | archives. You may use all of the mentioned commands on either regular 126 | packARC archives or on packARC SFX archives created in any OS. packARC 127 | is also compatible with archives written using previous release 128 | versions. You can edit, extract, test, convert and add to archives 129 | created with older versions, too. 130 | 131 | packARC supports wildcards like "*.*" and drag and drop of multiple 132 | files. When dropping an archive file, that file is extracted in place. 133 | When dropping multiple files and/or non-archive files, a new SFX archive 134 | file is created using the name of the first file in the list and all 135 | files are added to it. Existing archive files won't be changed or 136 | overwritten in the process. 137 | 138 | In default mode, existing files are never overwritten, neither inside, 139 | nor outside the archive. packARC skips these files instead. You may 140 | configure this behaviour to your liking using command line switches 141 | "-o", "-s" and "-r" (see below). 142 | 143 | Usage examples: 144 | 145 | Add all files matching "*.jpg" to archive "image.pja": 146 | "packARC a images.pja *.jpg" 147 | 148 | Extract all files from archive "media.pja": 149 | "packARC x media.pja" 150 | 151 | Delete file "unneeded.txt" from archive "SFX.exe": 152 | "packARC d SFX.exe unneeded.txt" 153 | 154 | Convert archive "archive.pja" to SFX format: 155 | "packARC c archive.pja" 156 | 157 | List contents of archive "myfiles.exe": 158 | "packARC l myfiles.exe" 159 | 160 | 161 | Command line switches 162 | ~~~~~~~~~~~~~~~~~~~~~ 163 | 164 | -o overwrite existing files 165 | -s skip existing files (default) 166 | -r rename on existing files 167 | -i (with x) ignore crc errors 168 | -sfx (with a) create sfx archive 169 | -sl (with l) simple list format 170 | -csv (with l) CSV list format 171 | -np no pause after processing. 172 | 173 | 174 | When adding or extracting, existing files are skipped by default. If you 175 | want packARC to overwrite files, use "-o". If the command line parameter 176 | "-r" is used and a filename is already in use, packARC will create a new 177 | filename by adding underscores to the original filename instead. As an 178 | example, if "lena.jpg" already existed, the new file would be called 179 | "lena_.jpg when "-r" is used. 180 | 181 | By default, packARC checks extracted files using CRC32. If the check 182 | fails, packARC does not extract the file in question and moves on to the 183 | next file instead. In theory the check should never fail, but it may 184 | happen with corrupted archives. If you want to disable the CRC32 check 185 | for any reason use the parameter "-i". 186 | 187 | If you want to create a new SFX archive, you don't need to create a 188 | regular one first using "a", then convert it it using "c". Just use the 189 | switch "-sfx" in conjunction with "a" to create a SFX archive right 190 | away. 191 | 192 | You can change the format of the file listing with "l". For a simpler 193 | list format use switch "sl". For CSV compatible output use switch "csv". 194 | 195 | Usage examples: 196 | 197 | Add all files matching "newfile??.bin", overwriting existing files: 198 | "packARC a -o archive.pja newfile??.bin" 199 | 200 | Create new SFX archive adding all files matching "*.mp3": 201 | "packARC a -sfx music.exe *.mp3" 202 | 203 | Extract archive, skipping CRC32 check and renaming on existing files: 204 | "packARC x -r -i photos.pja" 205 | 206 | List contents of archive using the CSV list format: 207 | "packARC l -csv compressed.exe" 208 | 209 | 210 | Known Limitations 211 | ~~~~~~~~~~~~~~~~~ 212 | 213 | Although packARC can handle any type of file, it was mainly designed 214 | with media files MP3 and JPEG in mind. It will reasonably compress the 215 | occasional TXT, PDF, DOC or any other file, but it is not intended to be 216 | used for large files such as ISOs. If the files that you want to archive 217 | don't consist mainly of JPEGs or MP3s you might want to consider using 218 | something else, such as Matt Mahoney's excellent PAQ8 series of 219 | archivers from http://www.mattmahoney.net/dc/. 220 | 221 | There is low error tolerance for JPEG and MP3 files. Even if a file can 222 | be perfectly processed by image viewer or audio player software, it 223 | might not be standard compliant. If a file is not 100% standard 224 | compliant, it won't be processed with the appropriate media compression 225 | algorithm. The generic algorithm is used instead, thus generating output 226 | of bigger size than you might expect. You may check the archive file 227 | listing to see which algorithm was used for the file included in an 228 | archive. 229 | 230 | If you try to drag and drop too many files in Microsoft Windows at once, 231 | there might be a windowed error message about missing privileges. In 232 | that case you can try it again with less files or consider using the 233 | command prompt. packARC has been tested to work properly with thousands 234 | of files from the command line. This issue also happens with drag and 235 | drop in other applications, so it might not be a limitation of packARC 236 | but a limitation of Windows. 237 | 238 | Please note that, although being well-tested, packARC is still in an 239 | early stage and shouldn't be used for backup of important data! You 240 | should at least verify an archive before deleting your copies of the 241 | files inside. 242 | 243 | 244 | Developer Info / How To Compile 245 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 246 | 247 | The packARC and packANY library sources are provided "as is". Except for 248 | these notes and the inline comments you are on your own compiling and 249 | using the source code. Note that due to SFX support and the separate 250 | packANY library, packARC cannot be build by GCC "make" alone. 251 | 252 | That being said, compiling packARC is really not all too difficult, and 253 | there also several Makefiles for different OSes and use cases included 254 | as well as a Windows .BAT file - kindly provided by Prof. Dr. Gerhard 255 | Seelmann - to handle the whole process under Microsoft Windows. 256 | 257 | If you want full packARC support for your own software project, I 258 | suggest to take a look at the "pja_archiver.cpp" and "pja_archiver.h" 259 | source files first. These two include all the interfaces you will need. 260 | 261 | If you are only interested in specific compression functionality (f.e. 262 | packPNM), note that the respective sources can also be compiled 263 | standalone. 264 | 265 | 266 | History 267 | ~~~~~~~ 268 | 269 | v0.7beta18 (12/17/2014) (public) 270 | - fixed MultiArc friendly file list format 271 | 272 | v0.7beta17 (11/21/2014) (public) 273 | - updated packMP3 library to new version (now licensed under LGPL v3) 274 | - packARC is now open source under the terms of the LGPL v3 275 | - added MultiArc friendly file list format 276 | - some minor bugfixes 277 | 278 | v0.7beta16 (02/25/2014) (public) 279 | - improved/fixed temp file handling in Linux 280 | - fixed some more possible file name creation bugs 281 | 282 | v0.7beta15 (02/24/2014) (public) 283 | - improved Linux compilation script (actually working now) 284 | - added Linux 32bit executable ('packARC.lxe') 285 | - updated all compression libraries to their newest versions 286 | - fixed some Linux specific stuff 287 | - fixed a bug in SFX file name creation 288 | 289 | v0.7beta13 (01/13/2014) (public) 290 | - updated packJPG and packPNM libraries 291 | - fixed segmentation fault error 292 | - SFX archives may now have any extension 293 | - improved batch compilation script for MSDOS (thanks to Se) 294 | - added compilation script for Linux (thanks to Se) 295 | 296 | v0.7beta11 (12/07/2013) (public) 297 | - updated packJPG, packPNM and packMP3 libraries 298 | - packARC is now completely open source under the GPL v3 299 | 300 | v0.7beta (04/06/2013) (public) 301 | - packMP3 algorithm added 302 | - packPNM algorithm added (updated to v1.6) 303 | - packARI algorithm added 304 | - support for folder recursion 305 | - support for archives >2GB 306 | - backwards compatibility preserved 307 | - new icons for archiver, SFX and PJA files 308 | - several bugfixes and improvements 309 | 310 | v0.3 (11/11/2011) (public) 311 | - first release alongside packJPG v2.5 312 | - contains support for compressing JPEGs using the packJPG library 313 | - contains support for storing other files 314 | - all basic archiver functionality included 315 | - no support for directory recursion yet 316 | 317 | 318 | Acknowledgements 319 | ~~~~~~~~~~~~~~~~ 320 | 321 | packJPG, packMP3, packPNM, packARI and packARC are the result of 322 | countless hours of research and development. packJPG is part of my final 323 | year project for HTW Aalen University, packMP3 is part of my master 324 | thesis for Ratisbon University. 325 | 326 | Prof. Dr. Gerhard Seelmann from HTW Aalen University introduced me to 327 | the field of data compression when I was still studying in Aalen. He 328 | supported my development of packJPG and various other compression 329 | program with his extensive knowledge in the field of data compression. 330 | Without him, neither of my compression programs would have been 331 | possible. 332 | 333 | Prof. Dr. Christian Wolff supervised my master thesis at Ratisbon 334 | University. Thanks go to him for giving me such an interesting topic to 335 | work on and for all the helpful advice during my time working on the 336 | thesis. 337 | 338 | Thanks goes to Stephan Busch of SqueezeChart.com fame for spending many, 339 | many hours beta-testing packMP3 and several other of my compression 340 | programs. He's the one to thank for my software running smoothly and not 341 | causing you any trouble. 342 | 343 | The official developer blog for packJPG is hosted by encode.ru. 344 | 345 | packARC uses UPX compression for smaller executable sizes. UPX is freely 346 | available from http://upx.sourceforge.net/. 347 | 348 | Original packJPG logos and icons are designed by Michael Kaufmann. 349 | 350 | 351 | Contact 352 | ~~~~~~~ 353 | 354 | Matthias Stirner's official homepage: 355 | http://www.matthias.stirner.com 356 | 357 | The official home of packARC and packJPG: 358 | http://packjpg.encode.ru 359 | 360 | For questions and bug reports: 361 | packjpg (at) matthiasstirner.com 362 | 363 | 364 | ____________________________________ 365 | packMP3 by Matthias Stirner, 01/2016 366 | -------------------------------------------------------------------------------- /source/build_packarc_linux.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # 3 | # 12-06-17 Se 4 | 5 | cd ./packANY/packANYlib 6 | make -f Makefile_lib_Linux 7 | make -f Makefile_lib_Linux clean 8 | make -f Makefile_lib_Os_Linux 9 | make -f Makefile_lib_Os_Linux clean 10 | 11 | cd ../../packARC 12 | cp ../packANY/packANYlib/packANYlib*.a ./ 13 | rm ../packANY/packANYlib/packANYlib*.a ./ 14 | 15 | make -f Makefile_sfx_stub.linux 16 | make -f Makefile_sfx_stub.linux clean 17 | upx --best --lzma sfxstub 18 | 19 | gcc -o sfxstub2h sfxstub2h.c 20 | ./sfxstub2h 21 | make -f Makefile.linux 22 | make -f Makefile.linux clean 23 | upx --best --lzma packarc 24 | 25 | rm sfxstub.h sfxstub sfxstub2h packANYlib.a packANYlib_small.a 26 | 27 | cp ./packARC ../packARC.lxe 28 | rm ./packARC 29 | cd .. 30 | -------------------------------------------------------------------------------- /source/build_packarc_msdos.bat: -------------------------------------------------------------------------------- 1 | REM 12-06-17 Gerhard Seelmann 2 | REM 13-12-07 Matthias Stirner 3 | REM 4 | 5 | REM Set path to 'gcc'(V4), 'make', and 'upx' (V3.08 or above) 6 | REM Use short file names (w/o spaces), otherwise 'g++' failed for me 7 | 8 | @ECHO OFF 9 | 10 | SET GCC_BIN_DIR=C:\MinGW\bin 11 | SET UPX_BIN_DIR=C:\UPX 12 | SET OLDPATH=%PATH% 13 | SET PATH=%GCC_BIN_DIR%;%UPX_BIN_DIR%;%PATH% 14 | 15 | CD .\packANY\packANYlib 16 | make -f Makefile_lib 17 | make -f Makefile_lib clean 18 | make -f Makefile_lib_Os 19 | make -f Makefile_lib_Os clean 20 | 21 | CD ..\..\packARC 22 | MOVE ..\packANY\packANYlib\packANYlib.a .\ 23 | MOVE ..\packANY\packANYlib\packANYlib_small.a .\ 24 | 25 | make -f Makefile_sfx_stub.win 26 | make -f Makefile_sfx_stub.win clean 27 | upx --best --lzma sfxstub.exe 28 | 29 | gcc -o sfxstub2h.exe sfxstub2h.c 30 | .\sfxstub2h 31 | make -f Makefile.win 32 | make -f Makefile.win clean 33 | upx --best --lzma packARC.exe 34 | 35 | DEL sfxstub.h sfxstub.exe sfxstub2h.exe packANYlib.a packANYlib_small.a 36 | 37 | CD .. 38 | MOVE .\packARC\packARC.exe .\ 39 | 40 | set PATH=%OLDPATH% -------------------------------------------------------------------------------- /source/packANY/packANYlib/Makefile_dll: -------------------------------------------------------------------------------- 1 | # Project: packANY (JPG/MP3/ARI) static library 2 | # Makefile created by Matthias Stirner 01/30/2012 3 | # Working with GCC 4.6.0 4 | 5 | CC = gcc 6 | CPP = g++ 7 | RM = del 8 | CFLAGS = -I. -DBUILD_DLL -O2 -Wall -pedantic -funroll-loops -ffast-math -fsched-spec-load -fomit-frame-pointer 9 | LDFLAGS = -Wl,--out-implib,libpackANY.a -fvisibility=hidden -static-libgcc -static-libstdc++ 10 | DEPS = ..//packARI//aricoder.h ..//packARI//bitops.h ..//packARI//paritbl.h ..//packJPG//pjpgtbl.h ..//packJPG//dct8x8.h ..//packMP3//pmp3tbl.h ..//packMP3//pmp3bitlen.h ..//packMP3//huffmp3.h ..//packMP3//huffmp3tbl.h ..//packPNM//ppnmtbl.h ..//packPNM//ppnmbitlen.h 11 | OBJ = aricoder.o bitops.o packari.o packjpg.o packmp3.o huffmp3.o packpnm.o 12 | BIN = packANY.dll 13 | 14 | 15 | $(BIN): $(OBJ) 16 | $(CPP) -shared -o $@ $^ $(LDFLAGS) 17 | 18 | # Universal I/O, statistical model and arithmetic coding sources 19 | 20 | aricoder.o: ..//packARI//aricoder.cpp $(DEPS) 21 | $(CPP) -c -o $@ $< $(CFLAGS) 22 | 23 | bitops.o: ..//packARI//bitops.cpp $(DEPS) 24 | $(CPP) -c -o $@ $< $(CFLAGS) 25 | 26 | # packARI specific sources 27 | 28 | packari.o: ..//packARI//packari.cpp $(DEPS) 29 | $(CPP) -c -o $@ $< $(CFLAGS) 30 | 31 | # packJPG specific sources 32 | 33 | packjpg.o: ..//packJPG//packjpg.cpp $(DEPS) 34 | $(CPP) -c -o $@ $< $(CFLAGS) 35 | 36 | # packMP3 specific sources 37 | 38 | packmp3.o: ..//packMP3//packmp3.cpp $(DEPS) 39 | $(CPP) -c -o $@ $< $(CFLAGS) 40 | 41 | huffmp3.o: ..//packMP3//huffmp3.cpp $(DEPS) 42 | $(CPP) -c -o $@ $< $(CFLAGS) 43 | 44 | # packPNM specific sources 45 | 46 | packpnm.o: ..//packPNM//packpnm.cpp $(DEPS) 47 | $(CPP) -c -o $@ $< $(CFLAGS) 48 | 49 | 50 | # clean instructions 51 | 52 | clean: 53 | $(RM) *.o 54 | -------------------------------------------------------------------------------- /source/packANY/packANYlib/Makefile_lib: -------------------------------------------------------------------------------- 1 | # Project: packANY (JPG/MP3/ARI) static library 2 | # Makefile created by Matthias Stirner 01/30/2012 3 | # Working with GCC 4.6.0 4 | 5 | CC = gcc 6 | CPP = g++ 7 | AR = ar 8 | RM = del 9 | CFLAGS = -I. -DBUILD_LIB -O3 -Wall -pedantic -funroll-loops -ffast-math -fsched-spec-load -fomit-frame-pointer 10 | LDFLAGS = -fvisibility=hidden -static-libgcc -static-libstdc++ 11 | DEPS = ..//packARI//aricoder.h ..//packARI//bitops.h ..//packARI//paritbl.h ..//packJPG//pjpgtbl.h ..//packJPG//dct8x8.h ..//packMP3//pmp3tbl.h ..//packMP3//pmp3bitlen.h ..//packMP3//huffmp3.h ..//packMP3//huffmp3tbl.h ..//packPNM//ppnmtbl.h ..//packPNM//ppnmbitlen.h 12 | OBJ = aricoder.o bitops.o packari.o packjpg.o packmp3.o huffmp3.o packpnm.o 13 | BIN = packANYlib.a 14 | 15 | 16 | $(BIN): $(OBJ) 17 | ar r $(BIN) $(OBJ) 18 | ranlib $(BIN) 19 | 20 | # Universal I/O, statistical model and arithmetic coding sources 21 | 22 | aricoder.o: ..//packARI//aricoder.cpp $(DEPS) 23 | $(CPP) -c -o $@ $< $(CFLAGS) 24 | 25 | bitops.o: ..//packARI//bitops.cpp $(DEPS) 26 | $(CPP) -c -o $@ $< $(CFLAGS) 27 | 28 | # packARI specific sources 29 | 30 | packari.o: ..//packARI//packari.cpp $(DEPS) 31 | $(CPP) -c -o $@ $< $(CFLAGS) 32 | 33 | # packJPG specific sources 34 | 35 | packjpg.o: ..//packJPG//packjpg.cpp $(DEPS) 36 | $(CPP) -c -o $@ $< $(CFLAGS) 37 | 38 | # packMP3 specific sources 39 | 40 | packmp3.o: ..//packMP3//packmp3.cpp $(DEPS) 41 | $(CPP) -c -o $@ $< $(CFLAGS) 42 | 43 | huffmp3.o: ..//packMP3//huffmp3.cpp $(DEPS) 44 | $(CPP) -c -o $@ $< $(CFLAGS) 45 | 46 | # packPNM specific sources 47 | 48 | packpnm.o: ..//packPNM//packpnm.cpp $(DEPS) 49 | $(CPP) -c -o $@ $< $(CFLAGS) 50 | 51 | 52 | # clean instructions 53 | 54 | clean: 55 | $(RM) *.o 56 | -------------------------------------------------------------------------------- /source/packANY/packANYlib/Makefile_lib_DM: -------------------------------------------------------------------------------- 1 | # Project: packANY (JPG/MP3/ARI) static library 2 | # Makefile created by Matthias Stirner 01/30/2012 3 | # Working with GCC 4.6.0 4 | 5 | CC = gcc 6 | CPP = g++ 7 | AR = ar 8 | RM = del 9 | CFLAGS = -DBUILD_LIB 10 | LDFLAGS = -static-libgcc 11 | DEPS = ..//packARI//aricoder.h ..//packARI//bitops.h ..//packARI//paritbl.h ..//packJPG//pjpgtbl.h ..//packJPG//dct8x8.h ..//packMP3//pmp3tbl.h ..//packMP3//pmp3bitlen.h ..//packMP3//huffmp3.h ..//packMP3//huffmp3tbl.h ..//packPNM//ppnmtbl.h ..//packPNM//ppnmbitlen.h 12 | OBJ = aricoder.o bitops.o packari.o packjpg.o packmp3.o huffmp3.o packpnm.o 13 | BIN = packANYlib.a 14 | 15 | 16 | $(BIN): $(OBJ) 17 | ar r $(BIN) $(OBJ) 18 | ranlib $(BIN) 19 | 20 | # Universal I/O, statistical model and arithmetic coding sources 21 | 22 | aricoder.o: ..//packARI//aricoder.cpp $(DEPS) 23 | $(CPP) -c -ggdb -o $@ $< $(CFLAGS) 24 | 25 | bitops.o: ..//packARI//bitops.cpp $(DEPS) 26 | $(CPP) -c -ggdb -o $@ $< $(CFLAGS) 27 | 28 | # packARI specific sources 29 | 30 | packari.o: ..//packARI//packari.cpp $(DEPS) 31 | $(CPP) -c -ggdb -o $@ $< $(CFLAGS) 32 | 33 | # packJPG specific sources 34 | 35 | packjpg.o: ..//packJPG//packjpg.cpp $(DEPS) 36 | $(CPP) -c -ggdb -o $@ $< $(CFLAGS) 37 | 38 | # packMP3 specific sources 39 | 40 | packmp3.o: ..//packMP3//packmp3.cpp $(DEPS) 41 | $(CPP) -c -ggdb -o $@ $< $(CFLAGS) 42 | 43 | huffmp3.o: ..//packMP3//huffmp3.cpp $(DEPS) 44 | $(CPP) -c -ggdb -o $@ $< $(CFLAGS) 45 | 46 | # packPNM specific sources 47 | 48 | packpnm.o: ..//packPNM//packpnm.cpp $(DEPS) 49 | $(CPP) -c -ggdb -o $@ $< $(CFLAGS) 50 | 51 | 52 | # clean instructions 53 | 54 | clean: 55 | $(RM) *.o 56 | -------------------------------------------------------------------------------- /source/packANY/packANYlib/Makefile_lib_Linux: -------------------------------------------------------------------------------- 1 | # Project: packANY (JPG/MP3/ARI) static library 2 | # Makefile created by Matthias Stirner 01/30/2012 3 | # Working with GCC 4.6.0 4 | 5 | CC = gcc 6 | CPP = g++ 7 | AR = ar 8 | RM = rm 9 | CFLAGS = -I. -DBUILD_LIB -O3 -Wall -pedantic -funroll-loops -ffast-math -fsched-spec-load -fomit-frame-pointer 10 | LDFLAGS = -fvisibility=hidden -static-libgcc 11 | DEPS = ..//packARI//aricoder.h ..//packARI//bitops.h ..//packARI//paritbl.h ..//packJPG//pjpgtbl.h ..//packJPG//dct8x8.h ..//packMP3//pmp3tbl.h ..//packMP3//pmp3bitlen.h ..//packMP3//huffmp3.h ..//packMP3//huffmp3tbl.h ..//packPNM//ppnmtbl.h ..//packPNM//ppnmbitlen.h 12 | OBJ = aricoder.o bitops.o packari.o packjpg.o packmp3.o huffmp3.o packpnm.o 13 | BIN = packANYlib.a 14 | 15 | 16 | $(BIN): $(OBJ) 17 | ar r $(BIN) $(OBJ) 18 | ranlib $(BIN) 19 | 20 | # Universal I/O, statistical model and arithmetic coding sources 21 | 22 | aricoder.o: ..//packARI//aricoder.cpp $(DEPS) 23 | $(CPP) -c -o $@ $< $(CFLAGS) 24 | 25 | bitops.o: ..//packARI//bitops.cpp $(DEPS) 26 | $(CPP) -c -o $@ $< $(CFLAGS) 27 | 28 | # packARI specific sources 29 | 30 | packari.o: ..//packARI//packari.cpp $(DEPS) 31 | $(CPP) -c -o $@ $< $(CFLAGS) 32 | 33 | # packJPG specific sources 34 | 35 | packjpg.o: ..//packJPG//packjpg.cpp $(DEPS) 36 | $(CPP) -c -o $@ $< $(CFLAGS) 37 | 38 | # packMP3 specific sources 39 | 40 | packmp3.o: ..//packMP3//packmp3.cpp $(DEPS) 41 | $(CPP) -c -o $@ $< $(CFLAGS) 42 | 43 | huffmp3.o: ..//packMP3//huffmp3.cpp $(DEPS) 44 | $(CPP) -c -o $@ $< $(CFLAGS) 45 | 46 | # packPNM specific sources 47 | 48 | packpnm.o: ..//packPNM//packpnm.cpp $(DEPS) 49 | $(CPP) -c -o $@ $< $(CFLAGS) 50 | 51 | 52 | # clean instructions 53 | 54 | clean: 55 | $(RM) *.o 56 | -------------------------------------------------------------------------------- /source/packANY/packANYlib/Makefile_lib_Os: -------------------------------------------------------------------------------- 1 | # Project: packANY (JPG/MP3/ARI) static library 2 | # Makefile created by Matthias Stirner 01/30/2012 3 | # Working with GCC 4.6.0 4 | 5 | CC = gcc 6 | CPP = g++ 7 | AR = ar 8 | RM = del 9 | CFLAGS = -I. -DBUILD_LIB -Os -Wall -pedantic -ffast-math -fsched-spec-load -fomit-frame-pointer 10 | LDFLAGS = -fvisibility=hidden -static-libgcc -static-libstdc++ 11 | DEPS = ..//packARI//aricoder.h ..//packARI//bitops.h ..//packARI//paritbl.h ..//packJPG//pjpgtbl.h ..//packJPG//dct8x8.h ..//packMP3//pmp3tbl.h ..//packMP3//pmp3bitlen.h ..//packMP3//huffmp3.h ..//packMP3//huffmp3tbl.h ..//packPNM//ppnmtbl.h ..//packPNM//ppnmbitlen.h 12 | OBJ = aricoder.o bitops.o packari.o packjpg.o packmp3.o huffmp3.o packpnm.o 13 | BIN = packANYlib_small.a 14 | 15 | 16 | $(BIN): $(OBJ) 17 | ar r $(BIN) $(OBJ) 18 | ranlib $(BIN) 19 | 20 | # Universal I/O, statistical model and arithmetic coding sources 21 | 22 | aricoder.o: ..//packARI//aricoder.cpp $(DEPS) 23 | $(CPP) -c -o $@ $< $(CFLAGS) 24 | 25 | bitops.o: ..//packARI//bitops.cpp $(DEPS) 26 | $(CPP) -c -o $@ $< $(CFLAGS) 27 | 28 | # packARI specific sources 29 | 30 | packari.o: ..//packARI//packari.cpp $(DEPS) 31 | $(CPP) -c -o $@ $< $(CFLAGS) 32 | 33 | # packJPG specific sources 34 | 35 | packjpg.o: ..//packJPG//packjpg.cpp $(DEPS) 36 | $(CPP) -c -o $@ $< $(CFLAGS) 37 | 38 | # packMP3 specific sources 39 | 40 | packmp3.o: ..//packMP3//packmp3.cpp $(DEPS) 41 | $(CPP) -c -o $@ $< $(CFLAGS) 42 | 43 | huffmp3.o: ..//packMP3//huffmp3.cpp $(DEPS) 44 | $(CPP) -c -o $@ $< $(CFLAGS) 45 | 46 | # packPNM specific sources 47 | 48 | packpnm.o: ..//packPNM//packpnm.cpp $(DEPS) 49 | $(CPP) -c -o $@ $< $(CFLAGS) 50 | 51 | 52 | # clean instructions 53 | 54 | clean: 55 | $(RM) *.o 56 | -------------------------------------------------------------------------------- /source/packANY/packANYlib/Makefile_lib_Os_Linux: -------------------------------------------------------------------------------- 1 | # Project: packANY (JPG/MP3/ARI) static library 2 | # Makefile created by Matthias Stirner 01/30/2012 3 | # Working with GCC 4.6.0 4 | 5 | CC = gcc 6 | CPP = g++ 7 | AR = ar 8 | RM = rm 9 | CFLAGS = -I. -DBUILD_LIB -Os -Wall -pedantic -ffast-math -fsched-spec-load -fomit-frame-pointer 10 | LDFLAGS = -fvisibility=hidden -static-libgcc 11 | DEPS = ..//packARI//aricoder.h ..//packARI//bitops.h ..//packARI//paritbl.h ..//packJPG//pjpgtbl.h ..//packJPG//dct8x8.h ..//packMP3//pmp3tbl.h ..//packMP3//pmp3bitlen.h ..//packMP3//huffmp3.h ..//packMP3//huffmp3tbl.h ..//packPNM//ppnmtbl.h ..//packPNM//ppnmbitlen.h 12 | OBJ = aricoder.o bitops.o packari.o packjpg.o packmp3.o huffmp3.o packpnm.o 13 | BIN = packANYlib_small.a 14 | 15 | 16 | $(BIN): $(OBJ) 17 | ar r $(BIN) $(OBJ) 18 | ranlib $(BIN) 19 | 20 | # Universal I/O, statistical model and arithmetic coding sources 21 | 22 | aricoder.o: ..//packARI//aricoder.cpp $(DEPS) 23 | $(CPP) -c -o $@ $< $(CFLAGS) 24 | 25 | bitops.o: ..//packARI//bitops.cpp $(DEPS) 26 | $(CPP) -c -o $@ $< $(CFLAGS) 27 | 28 | # packARI specific sources 29 | 30 | packari.o: ..//packARI//packari.cpp $(DEPS) 31 | $(CPP) -c -o $@ $< $(CFLAGS) 32 | 33 | # packJPG specific sources 34 | 35 | packjpg.o: ..//packJPG//packjpg.cpp $(DEPS) 36 | $(CPP) -c -o $@ $< $(CFLAGS) 37 | 38 | # packMP3 specific sources 39 | 40 | packmp3.o: ..//packMP3//packmp3.cpp $(DEPS) 41 | $(CPP) -c -o $@ $< $(CFLAGS) 42 | 43 | huffmp3.o: ..//packMP3//huffmp3.cpp $(DEPS) 44 | $(CPP) -c -o $@ $< $(CFLAGS) 45 | 46 | # packPNM specific sources 47 | 48 | packpnm.o: ..//packPNM//packpnm.cpp $(DEPS) 49 | $(CPP) -c -o $@ $< $(CFLAGS) 50 | 51 | 52 | # clean instructions 53 | 54 | clean: 55 | $(RM) *.o 56 | -------------------------------------------------------------------------------- /source/packANY/packANYlib/Makefile_lib_VG: -------------------------------------------------------------------------------- 1 | # Project: packANY (JPG/MP3/ARI) static library 2 | # Makefile created by Matthias Stirner 01/30/2012 3 | # Working with GCC 4.6.0 4 | 5 | CC = gcc 6 | CPP = g++ 7 | AR = ar 8 | RM = rm 9 | CFLAGS = -DBUILD_LIB -O1 -g 10 | LDFLAGS = -fvisibility=hidden -static-libgcc 11 | DEPS = ..//packARI//aricoder.h ..//packARI//bitops.h ..//packARI//paritbl.h ..//packJPG//pjpgtbl.h ..//packJPG//dct8x8.h ..//packMP3//pmp3tbl.h ..//packMP3//pmp3bitlen.h ..//packMP3//huffmp3.h ..//packMP3//huffmp3tbl.h ..//packPNM//ppnmtbl.h ..//packPNM//ppnmbitlen.h 12 | OBJ = aricoder.o bitops.o packari.o packjpg.o packmp3.o huffmp3.o packpnm.o 13 | BIN = packANYlib.a 14 | 15 | 16 | $(BIN): $(OBJ) 17 | ar r $(BIN) $(OBJ) 18 | ranlib $(BIN) 19 | 20 | # Universal I/O, statistical model and arithmetic coding sources 21 | 22 | aricoder.o: ..//packARI//aricoder.cpp $(DEPS) 23 | $(CPP) -c -o $@ $< $(CFLAGS) 24 | 25 | bitops.o: ..//packARI//bitops.cpp $(DEPS) 26 | $(CPP) -c -o $@ $< $(CFLAGS) 27 | 28 | # packARI specific sources 29 | 30 | packari.o: ..//packARI//packari.cpp $(DEPS) 31 | $(CPP) -c -o $@ $< $(CFLAGS) 32 | 33 | # packJPG specific sources 34 | 35 | packjpg.o: ..//packJPG//packjpg.cpp $(DEPS) 36 | $(CPP) -c -o $@ $< $(CFLAGS) 37 | 38 | # packMP3 specific sources 39 | 40 | packmp3.o: ..//packMP3//packmp3.cpp $(DEPS) 41 | $(CPP) -c -o $@ $< $(CFLAGS) 42 | 43 | huffmp3.o: ..//packMP3//huffmp3.cpp $(DEPS) 44 | $(CPP) -c -o $@ $< $(CFLAGS) 45 | 46 | # packPNM specific sources 47 | 48 | packpnm.o: ..//packPNM//packpnm.cpp $(DEPS) 49 | $(CPP) -c -o $@ $< $(CFLAGS) 50 | 51 | 52 | # clean instructions 53 | 54 | clean: 55 | $(RM) *.o 56 | -------------------------------------------------------------------------------- /source/packANY/packANYlib/packANYdll.h: -------------------------------------------------------------------------------- 1 | // packANYdll.h - function declarations and reference for the packANY DLL 2 | #define IMPORT __declspec( dllimport ) 3 | 4 | 5 | /* suggested usage: 6 | 1.) init streams using xxxlib_init_streams() (see below) 7 | 2.) convert files using the xxxlib_convert_stream2stream() function 8 | ... or ... 9 | 1.) convert between files using xxxlib_convert_file2file() 10 | 11 | input/output stream types and setup for 12 | the xxxlib_init_streams() function: 13 | 14 | if input is file 15 | ---------------- 16 | in_scr -> name of input file 17 | in_type -> 0 18 | in_size -> ignore 19 | 20 | if input is memory 21 | ------------------ 22 | in_scr -> array containg data 23 | in_type -> 1 24 | in_size -> size of data array 25 | 26 | if input is *FILE (f.e. stdin) 27 | ------------------------------ 28 | in_src -> stream pointer 29 | in_type -> 2 30 | in_size -> ignore 31 | 32 | same for output streams! */ 33 | 34 | 35 | 36 | /* ----------------------------------------------- 37 | function declarations: packARI library 38 | ----------------------------------------------- */ 39 | 40 | IMPORT bool parlib_convert_stream2stream( char* msg ); 41 | IMPORT bool parlib_convert_file2file( char* in, char* out, char* msg ); 42 | IMPORT bool parlib_convert_stream2mem( unsigned char** out_file, unsigned int* out_size, char* msg ); 43 | IMPORT void parlib_init_streams( void* in_src, int in_type, int in_size, void* out_dest, int out_type ); 44 | IMPORT void parlib_force_encoding( bool setting ); 45 | IMPORT const char* parlib_version_info( void ); 46 | IMPORT const char* parlib_short_name( void ); 47 | 48 | 49 | /* ----------------------------------------------- 50 | function declarations: packJPG library 51 | ----------------------------------------------- */ 52 | 53 | IMPORT bool pjglib_convert_stream2stream( char* msg ); 54 | IMPORT bool pjglib_convert_file2file( char* in, char* out, char* msg ); 55 | IMPORT bool pjglib_convert_stream2mem( unsigned char** out_file, unsigned int* out_size, char* msg ); 56 | IMPORT void pjglib_init_streams( void* in_src, int in_type, int in_size, void* out_dest, int out_type ); 57 | IMPORT const char* pjglib_version_info( void ); 58 | IMPORT const char* pjglib_short_name( void ); 59 | 60 | 61 | /* ----------------------------------------------- 62 | function declarations: packMP3 library 63 | ----------------------------------------------- */ 64 | 65 | IMPORT bool pmplib_convert_stream2stream( char* msg ); 66 | IMPORT bool pmplib_convert_file2file( char* in, char* out, char* msg ); 67 | IMPORT bool pmplib_convert_stream2mem( unsigned char** out_file, unsigned int* out_size, char* msg ); 68 | IMPORT void pmplib_init_streams( void* in_src, int in_type, int in_size, void* out_dest, int out_type ); 69 | IMPORT const char* pmplib_version_info( void ); 70 | IMPORT const char* pmplib_short_name( void ); 71 | 72 | 73 | /* ----------------------------------------------- 74 | function declarations: packPNM library 75 | ----------------------------------------------- */ 76 | 77 | IMPORT bool ppnlib_convert_stream2stream( char* msg ); 78 | IMPORT bool ppnlib_convert_file2file( char* in, char* out, char* msg ); 79 | IMPORT bool ppnlib_convert_stream2mem( unsigned char** out_file, unsigned int* out_size, char* msg ); 80 | IMPORT void ppnlib_init_streams( void* in_src, int in_type, int in_size, void* out_dest, int out_type ); 81 | IMPORT const char* ppnlib_version_info( void ); 82 | IMPORT const char* ppnlib_short_name( void ); 83 | -------------------------------------------------------------------------------- /source/packANY/packANYlib/packANYlib.h: -------------------------------------------------------------------------------- 1 | // packANYlib.h - function declarations and reference for the packANY library 2 | #define EXPORT extern 3 | 4 | 5 | /* suggested usage: 6 | 1.) init streams using xxxlib_init_streams() (see below) 7 | 2.) convert files using the xxxlib_convert_stream2stream() function 8 | ... or ... 9 | 1.) convert between files using xxxlib_convert_file2file() 10 | 11 | input/output stream types and setup for 12 | the xxxlib_init_streams() function: 13 | 14 | if input is file 15 | ---------------- 16 | in_scr -> name of input file 17 | in_type -> 0 18 | in_size -> ignore 19 | 20 | if input is memory 21 | ------------------ 22 | in_scr -> array containg data 23 | in_type -> 1 24 | in_size -> size of data array 25 | 26 | if input is *FILE (f.e. stdin) 27 | ------------------------------ 28 | in_src -> stream pointer 29 | in_type -> 2 30 | in_size -> ignore 31 | 32 | same for output streams! */ 33 | 34 | 35 | 36 | /* ----------------------------------------------- 37 | function declarations: packARI library 38 | ----------------------------------------------- */ 39 | 40 | EXPORT bool parlib_convert_stream2stream( char* msg ); 41 | EXPORT bool parlib_convert_file2file( char* in, char* out, char* msg ); 42 | EXPORT bool parlib_convert_stream2mem( unsigned char** out_file, unsigned int* out_size, char* msg ); 43 | EXPORT void parlib_init_streams( void* in_src, int in_type, int in_size, void* out_dest, int out_type ); 44 | EXPORT void parlib_force_encoding( bool setting ); 45 | EXPORT const char* parlib_version_info( void ); 46 | EXPORT const char* parlib_short_name( void ); 47 | 48 | 49 | /* ----------------------------------------------- 50 | function declarations: packJPG library 51 | ----------------------------------------------- */ 52 | 53 | EXPORT bool pjglib_convert_stream2stream( char* msg ); 54 | EXPORT bool pjglib_convert_file2file( char* in, char* out, char* msg ); 55 | EXPORT bool pjglib_convert_stream2mem( unsigned char** out_file, unsigned int* out_size, char* msg ); 56 | EXPORT void pjglib_init_streams( void* in_src, int in_type, int in_size, void* out_dest, int out_type ); 57 | EXPORT const char* pjglib_version_info( void ); 58 | EXPORT const char* pjglib_short_name( void ); 59 | 60 | 61 | /* ----------------------------------------------- 62 | function declarations: packMP3 library 63 | ----------------------------------------------- */ 64 | 65 | EXPORT bool pmplib_convert_stream2stream( char* msg ); 66 | EXPORT bool pmplib_convert_file2file( char* in, char* out, char* msg ); 67 | EXPORT bool pmplib_convert_stream2mem( unsigned char** out_file, unsigned int* out_size, char* msg ); 68 | EXPORT void pmplib_init_streams( void* in_src, int in_type, int in_size, void* out_dest, int out_type ); 69 | EXPORT const char* pmplib_version_info( void ); 70 | EXPORT const char* pmplib_short_name( void ); 71 | 72 | 73 | /* ----------------------------------------------- 74 | function declarations: packPNM library 75 | ----------------------------------------------- */ 76 | 77 | EXPORT bool ppnlib_convert_stream2stream( char* msg ); 78 | EXPORT bool ppnlib_convert_file2file( char* in, char* out, char* msg ); 79 | EXPORT bool ppnlib_convert_stream2mem( unsigned char** out_file, unsigned int* out_size, char* msg ); 80 | EXPORT void ppnlib_init_streams( void* in_src, int in_type, int in_size, void* out_dest, int out_type ); 81 | EXPORT const char* ppnlib_version_info( void ); 82 | EXPORT const char* ppnlib_short_name( void ); 83 | -------------------------------------------------------------------------------- /source/packANY/packARI/Makefile: -------------------------------------------------------------------------------- 1 | # Project: packARI 2 | # Makefile created by Matthias Stirner 01/30/2012 3 | # Working with GCC 4.6.0 4 | 5 | CC = gcc 6 | CPP = g++ 7 | RC = windres -O coff 8 | RM = del 9 | CFLAGS = -DDEV_BUILD -I. -O3 -Wall -pedantic -funroll-loops -ffast-math -fsched-spec-load -fomit-frame-pointer 10 | LDFLAGS = -s -static-libgcc -static-libstdc++ 11 | DEPS = aricoder.h bitops.h paritbl.h Makefile 12 | OBJ = aricoder.o bitops.o packari.o 13 | RES = icons.res 14 | BIN = packARI 15 | 16 | %.o: %.cpp $(DEPS) 17 | $(CPP) -c -o $@ $< $(CFLAGS) 18 | 19 | %.res: %.rc 20 | $(RC) $< $@ 21 | 22 | $(BIN): $(OBJ) $(RES) 23 | $(CPP) -o $@ $^ $(LDFLAGS) 24 | 25 | clean: 26 | $(RM) *.o 27 | -------------------------------------------------------------------------------- /source/packANY/packARI/Makefile_dll: -------------------------------------------------------------------------------- 1 | # Project: packARI DLL 2 | # Makefile created by Matthias Stirner 01/30/2012 3 | # Working with GCC 4.6.0 4 | 5 | CC = gcc 6 | CPP = g++ 7 | RC = windres -O coff 8 | RM = del 9 | CFLAGS = -I. -DBUILD_DLL -O2 -Wall -pedantic -fsched-spec-load -fomit-frame-pointer 10 | LDFLAGS = -Wl,--out-implib,libpackARI.a -fvisibility=hidden -static-libgcc -static-libstdc++ 11 | DEPS = aricoder.h bitops.h paritbl.h Makefile 12 | OBJ = aricoder.o bitops.o packari.o 13 | RES = icons.res 14 | BIN = packARI.dll 15 | 16 | %.o: %.cpp $(DEPS) 17 | $(CPP) -c -o $@ $< $(CFLAGS) 18 | 19 | %.res: %.rc 20 | $(RC) $< $@ 21 | 22 | $(BIN): $(OBJ) $(RES) 23 | $(CPP) -shared -o $@ $^ $(LDFLAGS) 24 | 25 | clean: 26 | $(RM) *.o 27 | -------------------------------------------------------------------------------- /source/packANY/packARI/Makefile_lib: -------------------------------------------------------------------------------- 1 | # Project: packARI static library 2 | # Makefile created by Matthias Stirner 01/30/2012 3 | # Working with GCC 4.6.0 4 | 5 | CC = gcc 6 | CPP = g++ 7 | AR = ar 8 | RM = del 9 | CFLAGS = -I. -DBUILD_LIB -O2 -Wall -pedantic -fsched-spec-load -fomit-frame-pointer 10 | LDFLAGS = -fvisibility=hidden -static-libgcc -static-libstdc++ 11 | DEPS = aricoder.h bitops.h paritbl.h Makefile 12 | OBJ = aricoder.o bitops.o packari.o 13 | BIN = packARIlib.a 14 | 15 | %.o: %.cpp $(DEPS) 16 | $(CPP) -c -o $@ $< $(CFLAGS) 17 | 18 | $(BIN): $(OBJ) 19 | ar r $(BIN) $(OBJ) 20 | ranlib $(BIN) 21 | 22 | clean: 23 | $(RM) *.o 24 | -------------------------------------------------------------------------------- /source/packANY/packARI/app_icon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/packjpg/packARC/ed6ca67e0d6e0e20dafa7481cbecc7ff10fc00f4/source/packANY/packARI/app_icon.ico -------------------------------------------------------------------------------- /source/packANY/packARI/aricoder.h: -------------------------------------------------------------------------------- 1 | // defines for coder 2 | #define CODER_USE_BITS 31 // must never be above 31 3 | #define CODER_LIMIT100 ( (unsigned int) ( 1 << CODER_USE_BITS ) ) 4 | #define CODER_LIMIT025 ( ( CODER_LIMIT100 / 4 ) * 1 ) 5 | #define CODER_LIMIT050 ( ( CODER_LIMIT100 / 4 ) * 2 ) 6 | #define CODER_LIMIT075 ( ( CODER_LIMIT100 / 4 ) * 3 ) 7 | #define CODER_MAXSCALE CODER_LIMIT025 - 1 8 | #define ESCAPE_SYMBOL CODER_LIMIT025 9 | 10 | 11 | // symbol struct, used in arithmetic coding 12 | struct symbol { 13 | unsigned int low_count; 14 | unsigned int high_count; 15 | unsigned int scale; 16 | }; 17 | 18 | // table struct, used in in statistical models, 19 | // holding all info needed for one context 20 | struct table { 21 | // counts for each symbol contained in the table 22 | unsigned short* counts; 23 | // links to higher order contexts 24 | struct table** links; 25 | // link to lower order context 26 | struct table* lesser; 27 | // accumulated counts 28 | unsigned int scale; 29 | }; 30 | 31 | // special table struct, used in in model_s, 32 | // holding additional info for a speedier 'totalize_table' 33 | struct table_s { 34 | // counts for each symbol contained in the table 35 | unsigned short* counts; 36 | // links to higher order contexts 37 | struct table_s** links; 38 | // link to lower order context 39 | struct table_s* lesser; 40 | // speedup info 41 | unsigned short max_count; 42 | unsigned short max_symbol; 43 | // unsigned short esc_prob; 44 | }; 45 | 46 | 47 | /* ----------------------------------------------- 48 | class for arithmetic coding of data to/from iostream 49 | ----------------------------------------------- */ 50 | 51 | class aricoder 52 | { 53 | public: 54 | aricoder( iostream* stream, int iomode ); 55 | ~aricoder( void ); 56 | void encode( symbol* s ); 57 | unsigned int decode_count( symbol* s ); 58 | void decode( symbol* s ); 59 | 60 | private: 61 | // bitwise operations 62 | void write_bit( unsigned char bit ); 63 | unsigned char read_bit( void ); 64 | 65 | // i/o variables 66 | iostream* sptr; 67 | int mode; 68 | unsigned char bbyte; 69 | unsigned char cbit; 70 | 71 | // arithmetic coding variables 72 | unsigned int ccode; 73 | unsigned int clow; 74 | unsigned int chigh; 75 | unsigned int cstep; 76 | unsigned int nrbits; 77 | }; 78 | 79 | 80 | /* ----------------------------------------------- 81 | universal statistical model for arithmetic coding 82 | ----------------------------------------------- */ 83 | 84 | class model_s 85 | { 86 | public: 87 | 88 | model_s( int max_s, int max_c, int max_o, int c_lim ); 89 | ~model_s( void ); 90 | 91 | void update_model( int symbol ); 92 | void shift_context( int c ); 93 | void flush_model( int scale_factor ); 94 | void exclude_symbols( char rule, int c ); 95 | 96 | int convert_int_to_symbol( int c, symbol *s ); 97 | void get_symbol_scale( symbol *s ); 98 | int convert_symbol_to_int( int count, symbol *s ); 99 | 100 | bool error; 101 | 102 | 103 | private: 104 | 105 | // unsigned short* totals; 106 | unsigned int* totals; 107 | char* scoreboard; 108 | int sb0_count; 109 | table_s **contexts; 110 | table_s **storage; 111 | 112 | int max_symbol; 113 | int max_context; 114 | int current_order; 115 | int max_order; 116 | int max_count; 117 | 118 | inline void totalize_table(table_s* context ); 119 | inline void rescale_table(table_s* context, int scale_factor ); 120 | inline void recursive_flush(table_s* context, int scale_factor ); 121 | inline void recursive_cleanup(table_s* context ); 122 | }; 123 | 124 | 125 | /* ----------------------------------------------- 126 | binary statistical model for arithmetic coding 127 | ----------------------------------------------- */ 128 | 129 | class model_b 130 | { 131 | public: 132 | 133 | model_b( int max_c, int max_o, int c_lim ); 134 | ~model_b( void ); 135 | 136 | void update_model( int symbol ); 137 | void shift_context( int c ); 138 | void flush_model( int scale_factor ); 139 | 140 | int convert_int_to_symbol( int c, symbol *s ); 141 | void get_symbol_scale( symbol *s ); 142 | int convert_symbol_to_int( int count, symbol *s ); 143 | 144 | bool error; 145 | 146 | 147 | private: 148 | 149 | table **contexts; 150 | table **storage; 151 | 152 | int max_context; 153 | int max_order; 154 | int max_count; 155 | 156 | inline void check_counts( table *context ); 157 | inline void rescale_table( table* context, int scale_factor ); 158 | inline void recursive_flush( table* context, int scale_factor ); 159 | inline void recursive_cleanup( table *context ); 160 | }; 161 | 162 | 163 | /* ----------------------------------------------- 164 | shift context x2 model_s function 165 | ----------------------------------------------- */ 166 | static inline void shift_model( model_s* model, int ctx1, int ctx2 ) 167 | { 168 | model->shift_context( ctx1 ); 169 | model->shift_context( ctx2 ); 170 | } 171 | 172 | 173 | /* ----------------------------------------------- 174 | shift context x3 model_s function 175 | ----------------------------------------------- */ 176 | static inline void shift_model( model_s* model, int ctx1, int ctx2, int ctx3 ) 177 | { 178 | model->shift_context( ctx1 ); 179 | model->shift_context( ctx2 ); 180 | model->shift_context( ctx3 ); 181 | } 182 | 183 | 184 | /* ----------------------------------------------- 185 | shift context x2 model_b function 186 | ----------------------------------------------- */ 187 | static inline void shift_model( model_b* model, int ctx1, int ctx2 ) 188 | { 189 | model->shift_context( ctx1 ); 190 | model->shift_context( ctx2 ); 191 | } 192 | 193 | 194 | /* ----------------------------------------------- 195 | shift context x3 model_b function 196 | ----------------------------------------------- */ 197 | static inline void shift_model( model_b* model, int ctx1, int ctx2, int ctx3 ) 198 | { 199 | model->shift_context( ctx1 ); 200 | model->shift_context( ctx2 ); 201 | model->shift_context( ctx3 ); 202 | } 203 | 204 | 205 | /* ----------------------------------------------- 206 | generic model_s encoder function 207 | ----------------------------------------------- */ 208 | static inline void encode_ari( aricoder* encoder, model_s* model, int c ) 209 | { 210 | static symbol s; 211 | static int esc; 212 | 213 | do { 214 | esc = model->convert_int_to_symbol( c, &s ); 215 | encoder->encode( &s ); 216 | } while ( esc ); 217 | model->update_model( c ); 218 | } 219 | 220 | /* ----------------------------------------------- 221 | generic model_s decoder function 222 | ----------------------------------------------- */ 223 | static inline int decode_ari( aricoder* decoder, model_s* model ) 224 | { 225 | static symbol s; 226 | static unsigned int count; 227 | static int c; 228 | 229 | do{ 230 | model->get_symbol_scale( &s ); 231 | count = decoder->decode_count( &s ); 232 | c = model->convert_symbol_to_int( count, &s ); 233 | decoder->decode( &s ); 234 | } while ( c == ESCAPE_SYMBOL ); 235 | model->update_model( c ); 236 | 237 | return c; 238 | } 239 | 240 | /* ----------------------------------------------- 241 | generic model_b encoder function 242 | ----------------------------------------------- */ 243 | static inline void encode_ari( aricoder* encoder, model_b* model, int c ) 244 | { 245 | static symbol s; 246 | 247 | model->convert_int_to_symbol( c, &s ); 248 | encoder->encode( &s ); 249 | model->update_model( c ); 250 | } 251 | 252 | /* ----------------------------------------------- 253 | generic model_b decoder function 254 | ----------------------------------------------- */ 255 | static inline int decode_ari( aricoder* decoder, model_b* model ) 256 | { 257 | static symbol s; 258 | static unsigned int count; 259 | static int c; 260 | 261 | model->get_symbol_scale( &s ); 262 | count = decoder->decode_count( &s ); 263 | c = model->convert_symbol_to_int( count, &s ); 264 | decoder->decode( &s ); 265 | model->update_model( c ); 266 | 267 | return c; 268 | } 269 | -------------------------------------------------------------------------------- /source/packANY/packARI/bitops.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | This file contains special classes for bitwise 3 | reading and writing of arrays 4 | */ 5 | 6 | #include 7 | #include 8 | #include 9 | #include "bitops.h" 10 | 11 | #define BUFFER_SIZE 1024 * 1024 12 | 13 | 14 | // special realloc with guaranteed free() of previous memory 15 | static inline void* frealloc( void* ptr, size_t size ) { 16 | void* n_ptr = realloc( ptr, size ); 17 | if ( n_ptr == NULL ) free( ptr ); 18 | return n_ptr; 19 | } 20 | 21 | 22 | /* ----------------------------------------------- 23 | constructor for abitreader class 24 | ----------------------------------------------- */ 25 | 26 | abitreader::abitreader( unsigned char* array, int size ) 27 | { 28 | cbyte = 0; 29 | cbit = 8; 30 | peof = 0; 31 | eof = false; 32 | 33 | data = array; 34 | lbyte = size; 35 | } 36 | 37 | /* ----------------------------------------------- 38 | destructor for abitreader class 39 | ----------------------------------------------- */ 40 | 41 | abitreader::~abitreader( void ) 42 | { 43 | } 44 | 45 | /* ----------------------------------------------- 46 | reads n bits from abitreader 47 | ----------------------------------------------- */ 48 | 49 | unsigned int abitreader::read( int nbits ) 50 | { 51 | unsigned int retval = 0; 52 | 53 | // safety check for eof 54 | if ( eof ) { 55 | peof += nbits; 56 | return 0; 57 | } 58 | 59 | while ( nbits >= cbit ) { 60 | nbits -= cbit; 61 | retval |= ( RBITS( data[cbyte], cbit ) << nbits ); 62 | cbit = 8; 63 | if ( ++cbyte >= lbyte ) { 64 | peof = nbits; 65 | eof = true; 66 | return retval; 67 | } 68 | } 69 | 70 | if ( nbits > 0 ) { 71 | retval |= ( MBITS( data[cbyte], cbit, (cbit-nbits) ) ); 72 | cbit -= nbits; 73 | } 74 | 75 | return retval; 76 | } 77 | 78 | /* ----------------------------------------------- 79 | reads one bit from abitreader 80 | ----------------------------------------------- */ 81 | 82 | unsigned char abitreader::read_bit( void ) 83 | { 84 | unsigned char bit; 85 | 86 | // safety check for eof 87 | if (eof) { 88 | peof++; 89 | return 0; 90 | } 91 | 92 | // read one bit 93 | bit = BITN( data[cbyte], --cbit ); 94 | if ( cbit == 0 ) { 95 | if ( ++cbyte == lbyte ) eof = true; 96 | cbit = 8; 97 | } 98 | 99 | return bit; 100 | } 101 | 102 | /* ----------------------------------------------- 103 | to skip padding from current byte 104 | ----------------------------------------------- */ 105 | 106 | unsigned char abitreader::unpad( unsigned char fillbit ) 107 | { 108 | if ( ( cbit == 8 ) || eof ) return fillbit; 109 | else { 110 | fillbit = read( 1 ); 111 | while ( cbit != 8 ) read( 1 ); 112 | } 113 | 114 | return fillbit; 115 | } 116 | 117 | /* ----------------------------------------------- 118 | get current position in array 119 | ----------------------------------------------- */ 120 | 121 | int abitreader::getpos( void ) 122 | { 123 | return cbyte; 124 | } 125 | 126 | /* ----------------------------------------------- 127 | get current bit position 128 | ----------------------------------------------- */ 129 | 130 | int abitreader::getbitp( void ) 131 | { 132 | return cbit; 133 | } 134 | 135 | /* ----------------------------------------------- 136 | set byte and bit position 137 | ----------------------------------------------- */ 138 | 139 | void abitreader::setpos( int pbyte, int pbit ) 140 | { 141 | if ( pbyte < lbyte ) { 142 | // reset eof 143 | eof = false; 144 | // set positions 145 | cbyte = pbyte; 146 | cbit = pbit; 147 | } else { 148 | // set eof 149 | eof = true; 150 | // set positions 151 | cbyte = lbyte; 152 | cbit = 8; 153 | peof = ( ( pbyte - lbyte ) * 8 ) + 8 - pbit; 154 | } 155 | } 156 | 157 | /* ----------------------------------------------- 158 | rewind n bits 159 | ----------------------------------------------- */ 160 | 161 | void abitreader::rewind_bits( int nbits ) 162 | { 163 | if ( eof ) { 164 | if ( nbits > peof ) nbits -= peof; 165 | else { 166 | peof -= nbits; 167 | return; 168 | } 169 | eof = false; 170 | } 171 | for ( cbit += nbits; cbit > 8; cbyte--, cbit -= 8 ); 172 | if ( cbyte < 0 ) { 173 | cbyte = 0; 174 | cbit = 8; 175 | } 176 | } 177 | 178 | 179 | /* ----------------------------------------------- 180 | constructor for abitwriter class 181 | ----------------------------------------------- */ 182 | 183 | abitwriter::abitwriter( int size ) 184 | { 185 | fillbit = 1; 186 | adds = 65536; 187 | cbyte = 0; 188 | cbit = 8; 189 | 190 | error = false; 191 | fmem = true; 192 | 193 | dsize = ( size > 0 ) ? size : adds; 194 | data = ( unsigned char* ) malloc ( dsize ); 195 | if ( data == NULL ) { 196 | error = true; 197 | return; 198 | } 199 | 200 | // fill buffer with zeroes 201 | memset( data, 0, dsize * sizeof( char ) ); 202 | // for ( int i = 0; i < dsize; i++ ) data[i] = 0; 203 | } 204 | 205 | /* ----------------------------------------------- 206 | destructor for abitwriter class 207 | ----------------------------------------------- */ 208 | 209 | abitwriter::~abitwriter( void ) 210 | { 211 | // free memory if pointer was not given out 212 | if ( fmem ) free( data ); 213 | } 214 | 215 | /* ----------------------------------------------- 216 | writes n bits to abitwriter 217 | ----------------------------------------------- */ 218 | 219 | void abitwriter::write( unsigned int val, int nbits ) 220 | { 221 | // safety check for error 222 | if ( error ) return; 223 | 224 | // test if pointer beyond flush treshold 225 | if ( cbyte > ( dsize - 5 ) ) { 226 | dsize += adds; 227 | data = (unsigned char*) frealloc( data, dsize ); 228 | if ( data == NULL ) { 229 | error = true; 230 | return; 231 | } 232 | memset( ( data + cbyte + 1 ), 0, ( dsize - ( cbyte + 1 ) ) * sizeof( char ) ); 233 | } 234 | 235 | // write data 236 | while ( nbits >= cbit ) { 237 | data[cbyte] |= ( MBITS32(val, nbits, (nbits-cbit)) ); 238 | nbits -= cbit; 239 | cbyte++; 240 | cbit = 8; 241 | } 242 | 243 | if ( nbits > 0 ) { 244 | data[cbyte] |= ( (RBITS32(val, nbits)) << (cbit - nbits) ); 245 | cbit -= nbits; 246 | } 247 | } 248 | 249 | /* ----------------------------------------------- 250 | writes one bit to abitwriter 251 | ----------------------------------------------- */ 252 | 253 | void abitwriter::write_bit( unsigned char bit ) 254 | { 255 | // safety check for error 256 | if ( error ) return; 257 | 258 | // write data 259 | if ( bit ) data[cbyte] |= 0x1 << (--cbit); 260 | else --cbit; 261 | if ( cbit == 0 ) { 262 | // test if pointer beyond flush treshold 263 | if ( ++cbyte > ( dsize - 5 ) ) { 264 | dsize += adds; 265 | data = (unsigned char*) frealloc( data, dsize ); 266 | if ( data == NULL ) { 267 | error = true; 268 | return; 269 | } 270 | memset( ( data + cbyte + 1 ), 0, ( dsize - ( cbyte + 1 ) ) * sizeof( char ) ); 271 | } 272 | cbit = 8; 273 | } 274 | } 275 | 276 | /* ----------------------------------------------- 277 | pads data using fillbit 278 | ----------------------------------------------- */ 279 | 280 | void abitwriter::pad( unsigned char fillbit ) 281 | { 282 | while ( cbit < 8 ) 283 | write( fillbit, 1 ); 284 | } 285 | 286 | /* ----------------------------------------------- 287 | gets data array from abitwriter 288 | ----------------------------------------------- */ 289 | 290 | unsigned char* abitwriter::getptr( void ) 291 | { 292 | // data is padded here 293 | pad( fillbit ); 294 | // forbid freeing memory 295 | fmem = false; 296 | // realloc data 297 | data = (unsigned char*) frealloc( data, cbyte ); 298 | 299 | return data; 300 | } 301 | 302 | /* ----------------------------------------------- 303 | gets size of data array from abitwriter 304 | ----------------------------------------------- */ 305 | 306 | int abitwriter::getpos( void ) 307 | { 308 | return cbyte; 309 | } 310 | 311 | /* ----------------------------------------------- 312 | get current bit position 313 | ----------------------------------------------- */ 314 | 315 | int abitwriter::getbitp( void ) 316 | { 317 | return cbit; 318 | } 319 | 320 | 321 | /* ----------------------------------------------- 322 | constructor for abytewriter class 323 | ----------------------------------------------- */ 324 | 325 | abytereader::abytereader( unsigned char* array, int size ) 326 | { 327 | cbyte = 0; 328 | eof = false; 329 | 330 | data = array; 331 | lbyte = size; 332 | 333 | if ( ( data == NULL ) || ( lbyte == 0 ) ) 334 | eof = true; 335 | } 336 | 337 | /* ----------------------------------------------- 338 | destructor for abytewriter class 339 | ----------------------------------------------- */ 340 | 341 | abytereader::~abytereader( void ) 342 | { 343 | } 344 | 345 | /* ----------------------------------------------- 346 | reads 1 byte from abytereader 347 | ----------------------------------------------- */ 348 | 349 | int abytereader::read( unsigned char* byte ) 350 | { 351 | if ( cbyte >= lbyte ) { 352 | cbyte = lbyte; 353 | eof = true; 354 | return 0; 355 | } 356 | else { 357 | *byte = data[ cbyte++ ]; 358 | return 1; 359 | } 360 | } 361 | 362 | /* ----------------------------------------------- 363 | reads n bytes from abytereader 364 | ----------------------------------------------- */ 365 | 366 | int abytereader::read_n( unsigned char* byte, int n ) 367 | { 368 | int nl = lbyte - cbyte; 369 | int i; 370 | 371 | if ( nl < n ) { 372 | for ( i = 0; i < nl; i++ ) 373 | byte[ i ] = data[ cbyte + i ]; 374 | cbyte = lbyte; 375 | eof = true; 376 | return nl; 377 | } 378 | else { 379 | for ( i = 0; i < n; i++ ) 380 | byte[ i ] = data[ cbyte + i ]; 381 | cbyte += n; 382 | return n; 383 | } 384 | } 385 | 386 | /* ----------------------------------------------- 387 | go to position in data 388 | ----------------------------------------------- */ 389 | 390 | void abytereader::seek( int pos ) 391 | { 392 | if ( pos >= lbyte ) { 393 | cbyte = lbyte; 394 | eof = true; 395 | } 396 | else { 397 | cbyte = pos; 398 | eof = false; 399 | } 400 | } 401 | 402 | /* ----------------------------------------------- 403 | gets size of current data 404 | ----------------------------------------------- */ 405 | 406 | int abytereader::getsize( void ) 407 | { 408 | return lbyte; 409 | } 410 | 411 | /* ----------------------------------------------- 412 | gets current position from abytereader 413 | ----------------------------------------------- */ 414 | 415 | int abytereader::getpos( void ) 416 | { 417 | return cbyte; 418 | } 419 | 420 | 421 | /* ----------------------------------------------- 422 | constructor for abytewriter class 423 | ----------------------------------------------- */ 424 | 425 | abytewriter::abytewriter( int size ) 426 | { 427 | adds = 65536; 428 | cbyte = 0; 429 | 430 | error = false; 431 | fmem = true; 432 | 433 | dsize = ( size > 0 ) ? size : adds; 434 | data = (unsigned char*) malloc( dsize ); 435 | if ( data == NULL ) { 436 | error = true; 437 | return; 438 | } 439 | } 440 | 441 | /* ----------------------------------------------- 442 | destructor for abytewriter class 443 | ----------------------------------------------- */ 444 | 445 | abytewriter::~abytewriter( void ) 446 | { 447 | // free data if pointer is not read 448 | if ( fmem ) free( data ); 449 | } 450 | 451 | /* ----------------------------------------------- 452 | writes 1 byte to abytewriter 453 | ----------------------------------------------- */ 454 | 455 | void abytewriter::write( unsigned char byte ) 456 | { 457 | // safety check for error 458 | if ( error ) return; 459 | 460 | // test if pointer beyond flush threshold 461 | if ( cbyte >= ( dsize - 2 ) ) { 462 | dsize += adds; 463 | data = (unsigned char*) frealloc( data, dsize ); 464 | if ( data == NULL ) { 465 | error = true; 466 | return; 467 | } 468 | } 469 | 470 | // write data 471 | data[ cbyte++ ] = byte; 472 | } 473 | 474 | /* ----------------------------------------------- 475 | writes n byte to abytewriter 476 | ----------------------------------------------- */ 477 | 478 | void abytewriter::write_n( unsigned char* byte, int n ) 479 | { 480 | // safety check for error 481 | if ( error ) return; 482 | 483 | // make sure that pointer doesn't get beyond flush threshold 484 | while ( ( cbyte + n ) >= ( dsize - 2 ) ) { 485 | dsize += adds; 486 | data = (unsigned char*) frealloc( data, dsize ); 487 | if ( data == NULL ) { 488 | error = true; 489 | return; 490 | } 491 | } 492 | 493 | // copy data from array 494 | while ( n-- > 0 ) 495 | data[ cbyte++ ] = *(byte++); 496 | } 497 | 498 | /* ----------------------------------------------- 499 | gets data array from abytewriter 500 | ----------------------------------------------- */ 501 | 502 | unsigned char* abytewriter::getptr( void ) 503 | { 504 | // safety check for error 505 | if ( error ) return NULL; 506 | // forbid freeing memory 507 | fmem = false; 508 | // realloc data 509 | data = (unsigned char*) frealloc( data, cbyte ); 510 | 511 | return data; 512 | } 513 | 514 | /* ----------------------------------------------- 515 | peeks into data array from abytewriter 516 | ----------------------------------------------- */ 517 | 518 | unsigned char* abytewriter::peekptr( void ) 519 | { 520 | return data; 521 | } 522 | 523 | /* ----------------------------------------------- 524 | gets size of data array from abytewriter 525 | ----------------------------------------------- */ 526 | 527 | int abytewriter::getpos( void ) 528 | { 529 | return cbyte; 530 | } 531 | 532 | /* ----------------------------------------------- 533 | reset without realloc 534 | ----------------------------------------------- */ 535 | 536 | void abytewriter::reset( void ) 537 | { 538 | // set position of current byte 539 | cbyte = 0; 540 | } 541 | 542 | 543 | /* ----------------------------------------------- 544 | constructor for iostream class 545 | ----------------------------------------------- */ 546 | 547 | iostream::iostream( void* src, int srctype, int srcsize, int iomode ) 548 | { 549 | // locally copy source, source type # and io mode # 550 | source = src; 551 | srct = srctype; 552 | srcs = srcsize; 553 | mode = iomode; 554 | 555 | // don't free memory when reading - this will be useful if switching occurs 556 | free_mem_sw = false; 557 | 558 | // set binary mode for streams 559 | #if defined( _WIN32 ) 560 | setmode( fileno( stdin ), O_BINARY ); 561 | setmode( fileno( stdout ), O_BINARY ); 562 | #endif 563 | 564 | // open file/mem/stream 565 | switch ( srct ) 566 | { 567 | case 0: 568 | open_file(); 569 | break; 570 | 571 | case 1: 572 | open_mem(); 573 | break; 574 | 575 | case 2: 576 | open_stream(); 577 | break; 578 | 579 | default: 580 | break; 581 | } 582 | } 583 | 584 | /* ----------------------------------------------- 585 | destructor for iostream class 586 | ----------------------------------------------- */ 587 | 588 | iostream::~iostream( void ) 589 | { 590 | // if needed, write memory to stream or free memory from buffered stream 591 | if ( srct == 2 ) { 592 | if ( mode == 1 ) { 593 | if ( !(mwrt->error) ) { 594 | srcs = mwrt->getpos(); 595 | source = mwrt->getptr(); 596 | fwrite( source, sizeof( char ), srcs, stdout ); 597 | } 598 | } 599 | } 600 | 601 | // free all buffers 602 | if ( srct == 0 ) { 603 | if ( fptr != NULL ) { 604 | if ( mode == 1 ) fflush( fptr ); 605 | fclose( fptr ); 606 | } 607 | } 608 | else if ( mode == 0 ) { 609 | if ( free_mem_sw ) 610 | free( source ); 611 | delete( mrdr ); 612 | } 613 | else 614 | delete( mwrt ); 615 | } 616 | 617 | /* ----------------------------------------------- 618 | switches mode from reading to writing and vice versa 619 | ----------------------------------------------- */ 620 | 621 | void iostream::switch_mode( void ) 622 | { 623 | // return immediately if there's an error 624 | if ( chkerr() ) return; 625 | 626 | 627 | if ( mode == 0 ) { 628 | // WARNING: when switching from reading to writing, information might be lost forever 629 | switch ( srct ) { 630 | case 0: 631 | fclose( fptr ); 632 | fptr = fopen( ( char* ) source, "wb" ); 633 | break; 634 | case 1: 635 | case 2: 636 | delete( mrdr ); 637 | if ( free_mem_sw ) 638 | free( source ); // see? I've told you so :-) 639 | mwrt = new abytewriter( srcs ); 640 | break; 641 | default: 642 | break; 643 | } 644 | mode = 1; 645 | } 646 | else { 647 | // switching from writing to reading is a bit more complicated 648 | switch ( srct ) { 649 | case 0: 650 | fflush( fptr ); 651 | fclose( fptr ); 652 | fptr = fopen( ( char* ) source, "rb" ); 653 | break; 654 | case 1: 655 | case 2: 656 | source = mwrt->getptr(); 657 | srcs = mwrt->getpos(); 658 | delete( mwrt ); 659 | mrdr = new abytereader( ( unsigned char* ) source, srcs ); 660 | free_mem_sw = true; 661 | break; 662 | default: 663 | break; 664 | } 665 | mode = 0; 666 | } 667 | } 668 | 669 | /* ----------------------------------------------- 670 | generic read function 671 | ----------------------------------------------- */ 672 | 673 | int iostream::read( void* to, int tpsize, int dtsize ) 674 | { 675 | return ( srct == 0 ) ? read_file( to, tpsize, dtsize ) : read_mem( to, tpsize, dtsize ); 676 | } 677 | 678 | /* ----------------------------------------------- 679 | generic write function 680 | ----------------------------------------------- */ 681 | 682 | int iostream::write( void* from, int tpsize, int dtsize ) 683 | { 684 | return ( srct == 0 ) ? write_file( from, tpsize, dtsize ) : write_mem( from, tpsize, dtsize ); 685 | } 686 | 687 | /* ----------------------------------------------- 688 | flush function 689 | ----------------------------------------------- */ 690 | 691 | int iostream::flush( void ) 692 | { 693 | if ( srct == 0 ) 694 | fflush( fptr ); 695 | 696 | return getpos(); 697 | } 698 | 699 | /* ----------------------------------------------- 700 | rewind to beginning of stream 701 | ----------------------------------------------- */ 702 | 703 | int iostream::rewind( void ) 704 | { 705 | // WARNING: when writing, rewind might lose all your data 706 | if ( srct == 0 ) 707 | fseek( fptr, 0, SEEK_SET ); 708 | else if ( mode == 0 ) 709 | mrdr->seek( 0 ); 710 | else 711 | mwrt->reset(); 712 | 713 | return getpos(); 714 | } 715 | 716 | /* ----------------------------------------------- 717 | get current position in stream 718 | ----------------------------------------------- */ 719 | 720 | int iostream::getpos( void ) 721 | { 722 | int pos; 723 | 724 | if ( srct == 0 ) 725 | pos = ftell( fptr ); 726 | else if ( mode == 0 ) 727 | pos = mrdr->getpos(); 728 | else 729 | pos = mwrt->getpos(); 730 | 731 | return pos; 732 | } 733 | 734 | /* ----------------------------------------------- 735 | get size of file 736 | ----------------------------------------------- */ 737 | 738 | int iostream::getsize( void ) 739 | { 740 | int pos; 741 | int siz; 742 | 743 | if ( mode == 0 ) { 744 | if ( srct == 0 ) { 745 | pos = ftell( fptr ); 746 | fseek( fptr, 0, SEEK_END ); 747 | siz = ftell( fptr ); 748 | fseek( fptr, pos, SEEK_SET ); 749 | } 750 | else { 751 | siz = mrdr->getsize(); 752 | } 753 | } 754 | else { 755 | siz = getpos(); 756 | } 757 | 758 | return siz; 759 | } 760 | 761 | /* ----------------------------------------------- 762 | get data pointer (for mem io only) 763 | ----------------------------------------------- */ 764 | 765 | unsigned char* iostream::getptr( void ) 766 | { 767 | if ( srct == 1 ) 768 | return ( mode == 0 ) ? ( unsigned char* ) source : mwrt->getptr(); 769 | else 770 | return NULL; 771 | } 772 | 773 | /* ----------------------------------------------- 774 | check for errors 775 | ----------------------------------------------- */ 776 | 777 | bool iostream::chkerr( void ) 778 | { 779 | bool error = false; 780 | 781 | // check for user input errors 782 | if ( ( mode != 0 ) && ( mode != 1 ) ) 783 | error = true; 784 | if ( ( srct != 0 ) && ( srct != 1 ) && ( srct != 2 ) ) 785 | error = true; 786 | 787 | // check for io errors 788 | if ( srct == 0 ) { 789 | if ( fptr == NULL ) 790 | error = true; 791 | else if ( ferror( fptr ) ) 792 | error = true; 793 | } 794 | else if ( mode == 0 ) { 795 | if ( mrdr == NULL ) 796 | error = true; 797 | } 798 | else { 799 | if ( mwrt == NULL ) 800 | error = true; 801 | else if ( mwrt->error ) 802 | error = true; 803 | } 804 | 805 | return error; 806 | } 807 | 808 | /* ----------------------------------------------- 809 | check for eof (read only) 810 | ----------------------------------------------- */ 811 | 812 | bool iostream::chkeof( void ) 813 | { 814 | if ( mode == 0 ) 815 | return ( srct == 0 ) ? feof( fptr ) : mrdr->eof; 816 | else 817 | return false; 818 | } 819 | 820 | /* ----------------------------------------------- 821 | open function for files 822 | ----------------------------------------------- */ 823 | 824 | void iostream::open_file( void ) 825 | { 826 | char* fn = (char*) source; 827 | 828 | // open file for reading / writing 829 | fptr = fopen( fn, ( mode == 0 ) ? "rb" : "wb" ); 830 | } 831 | 832 | /* ----------------------------------------------- 833 | open function for memory 834 | ----------------------------------------------- */ 835 | 836 | void iostream::open_mem( void ) 837 | { 838 | if ( mode == 0 ) 839 | mrdr = new abytereader( ( unsigned char* ) source, srcs ); 840 | else 841 | mwrt = new abytewriter( srcs ); 842 | } 843 | 844 | /* ----------------------------------------------- 845 | open function for streams 846 | ----------------------------------------------- */ 847 | 848 | void iostream::open_stream( void ) 849 | { 850 | abytewriter* strwrt; 851 | unsigned char* buffer; 852 | int i; 853 | 854 | if ( mode == 0 ) { 855 | // read whole stream into memory buffer 856 | strwrt = new abytewriter( 0 ); 857 | buffer = ( unsigned char* ) calloc( BUFFER_SIZE, sizeof( char ) ); 858 | if ( buffer != NULL ) { 859 | while ( ( i = fread( buffer, sizeof( char ), BUFFER_SIZE, stdin ) ) > 0 ) 860 | strwrt->write_n( buffer, i ); 861 | } 862 | if ( strwrt->error ) { 863 | source = NULL; 864 | srcs = 0; 865 | } 866 | else { 867 | source = strwrt->getptr(); 868 | srcs = strwrt->getpos(); 869 | } 870 | delete ( strwrt ); 871 | free( buffer ); 872 | // free memory after done 873 | free_mem_sw = true; 874 | } 875 | 876 | // for writing: simply open new stream in mem writer 877 | // writing to stream will be done later 878 | open_mem(); 879 | } 880 | 881 | /* ----------------------------------------------- 882 | write function for files 883 | ----------------------------------------------- */ 884 | 885 | int iostream::write_file( void* from, int tpsize, int dtsize ) 886 | { 887 | return fwrite( from, tpsize, dtsize, fptr ); 888 | } 889 | 890 | /* ----------------------------------------------- 891 | read function for files 892 | ----------------------------------------------- */ 893 | 894 | int iostream::read_file( void* to, int tpsize, int dtsize ) 895 | { 896 | return fread( to, tpsize, dtsize, fptr ); 897 | } 898 | 899 | /* ----------------------------------------------- 900 | write function for memory 901 | ----------------------------------------------- */ 902 | 903 | int iostream::write_mem( void* from, int tpsize, int dtsize ) 904 | { 905 | int n = tpsize * dtsize; 906 | 907 | mwrt->write_n( ( unsigned char* ) from, n ); 908 | 909 | return ( mwrt->error ) ? 0 : n; 910 | } 911 | 912 | /* ----------------------------------------------- 913 | read function for memory 914 | ----------------------------------------------- */ 915 | 916 | int iostream::read_mem( void* to, int tpsize, int dtsize ) 917 | { 918 | int n = tpsize * dtsize; 919 | 920 | return ( mrdr->read_n( ( unsigned char* ) to, n ) ) / tpsize; 921 | } 922 | -------------------------------------------------------------------------------- /source/packANY/packARI/bitops.h: -------------------------------------------------------------------------------- 1 | #define RBITS( c, n ) ( c & ( 0xFF >> (8 - n) ) ) 2 | #define LBITS( c, n ) ( c >> (8 - n) ) 3 | #define MBITS( c, l, r ) ( RBITS( c,l ) >> r ) 4 | #define RBITS16( c, n ) ( c & ( 0xFFFFFFFF >> (16 - n) ) ) 5 | #define LBITS16( c, n ) ( c >> (16 - n) ) 6 | #define MBITS16( c, l, r ) ( RBITS16( c,l ) >> r ) 7 | #define RBITS32( c, n ) ( c & ( 0xFFFFFFFF >> (32 - n) ) ) 8 | #define LBITS32( c, n ) ( c >> (32 - n) ) 9 | #define MBITS32( c, l, r ) ( RBITS32( c,l ) >> r ) 10 | #define BITN( c, n ) ( (c >> n) & 0x1 ) 11 | #define BITLEN( l, v ) for ( l = 0; ( v >> l ) > 0; l++ ) 12 | #define FDIV2( v, p ) ( ( v < 0 ) ? -( (-v) >> p ) : ( v >> p ) ) 13 | 14 | #define TYPE_FILE 0 15 | #define TYPE_MEMORY 1 16 | #define TYPE_STREAM 2 17 | #define MODE_READ 0 18 | #define MODE_WRITE 1 19 | 20 | #define BTST_BUFF 1024 * 1024 21 | 22 | #include 23 | 24 | 25 | /* ----------------------------------------------- 26 | class to read arrays bitwise 27 | ----------------------------------------------- */ 28 | 29 | class abitreader 30 | { 31 | public: 32 | abitreader( unsigned char* array, int size ); 33 | ~abitreader( void ); 34 | unsigned int read( int nbits ); 35 | unsigned char read_bit( void ); 36 | unsigned char unpad( unsigned char fillbit ); 37 | int getpos( void ); 38 | int getbitp( void ); 39 | void setpos( int pbyte, int pbit ); 40 | void rewind_bits( int nbits ); 41 | bool eof; 42 | int peof; 43 | 44 | private: 45 | unsigned char* data; 46 | int lbyte; 47 | int cbyte; 48 | int cbit; 49 | }; 50 | 51 | 52 | /* ----------------------------------------------- 53 | class to write arrays bitwise 54 | ----------------------------------------------- */ 55 | 56 | class abitwriter 57 | { 58 | public: 59 | abitwriter( int size ); 60 | ~abitwriter( void ); 61 | void write( unsigned int val, int nbits ); 62 | void write_bit( unsigned char bit ); 63 | void pad ( unsigned char fillbit ); 64 | unsigned char* getptr( void ); 65 | int getpos( void ); 66 | int getbitp( void ); 67 | bool error; 68 | unsigned char fillbit; 69 | 70 | private: 71 | unsigned char* data; 72 | int dsize; 73 | int adds; 74 | int cbyte; 75 | int cbit; 76 | bool fmem; 77 | }; 78 | 79 | 80 | /* ----------------------------------------------- 81 | class to read arrays bytewise 82 | ----------------------------------------------- */ 83 | 84 | class abytereader 85 | { 86 | public: 87 | abytereader( unsigned char* array, int size ); 88 | ~abytereader( void ); 89 | int read( unsigned char* byte ); 90 | int read_n( unsigned char* byte, int n ); 91 | void seek( int pos ); 92 | int getsize( void ); 93 | int getpos( void ); 94 | bool eof; 95 | 96 | private: 97 | unsigned char* data; 98 | int lbyte; 99 | int cbyte; 100 | }; 101 | 102 | 103 | /* ----------------------------------------------- 104 | class to write arrays bytewise 105 | ----------------------------------------------- */ 106 | 107 | class abytewriter 108 | { 109 | public: 110 | abytewriter( int size ); 111 | ~abytewriter( void ); 112 | void write( unsigned char byte ); 113 | void write_n( unsigned char* byte, int n ); 114 | unsigned char* getptr( void ); 115 | unsigned char* peekptr( void ); 116 | int getpos( void ); 117 | void reset( void ); 118 | bool error; 119 | 120 | private: 121 | unsigned char* data; 122 | int dsize; 123 | int adds; 124 | int cbyte; 125 | bool fmem; 126 | }; 127 | 128 | 129 | /* ----------------------------------------------- 130 | class for input and output from file or memory 131 | ----------------------------------------------- */ 132 | 133 | class iostream 134 | { 135 | public: 136 | iostream( void* src, int srctype, int srcsize, int iomode ); 137 | ~iostream( void ); 138 | void switch_mode( void ); 139 | int read( void* to, int tpsize, int dtsize ); 140 | int write( void* from, int tpsize, int dtsize ); 141 | int flush( void ); 142 | int rewind( void ); 143 | int getpos( void ); 144 | int getsize( void ); 145 | unsigned char* getptr( void ); 146 | bool chkerr( void ); 147 | bool chkeof( void ); 148 | 149 | private: 150 | void open_file( void ); 151 | void open_mem( void ); 152 | void open_stream( void ); 153 | 154 | int write_file( void* from, int tpsize, int dtsize ); 155 | int read_file( void* to, int tpsize, int dtsize ); 156 | int write_mem( void* from, int tpsize, int dtsize ); 157 | int read_mem( void* to, int tpsize, int dtsize ); 158 | 159 | FILE* fptr; 160 | abytewriter* mwrt; 161 | abytereader* mrdr; 162 | 163 | bool free_mem_sw; 164 | void* source; 165 | int mode; 166 | int srct; 167 | int srcs; 168 | }; 169 | -------------------------------------------------------------------------------- /source/packANY/packARI/file_icon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/packjpg/packARC/ed6ca67e0d6e0e20dafa7481cbecc7ff10fc00f4/source/packANY/packARI/file_icon.ico -------------------------------------------------------------------------------- /source/packANY/packARI/icons.rc: -------------------------------------------------------------------------------- 1 | app ICON app_icon.ico 2 | ICONS1 ICON file_icon.ico -------------------------------------------------------------------------------- /source/packANY/packARI/icons.res: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/packjpg/packARC/ed6ca67e0d6e0e20dafa7481cbecc7ff10fc00f4/source/packANY/packARI/icons.res -------------------------------------------------------------------------------- /source/packANY/packARI/packaridll.h: -------------------------------------------------------------------------------- 1 | // packARIdll.h - function import declarations for the packARI DLL 2 | #define IMPORT __declspec( dllimport ) 3 | 4 | /* ----------------------------------------------- 5 | function declarations: library only functions 6 | ----------------------------------------------- */ 7 | 8 | IMPORT bool parlib_convert_stream2stream( char* msg ); 9 | IMPORT bool parlib_convert_file2file( char* in, char* out, char* msg ); 10 | IMPORT bool parlib_convert_stream2mem( unsigned char** out_file, unsigned int* out_size, char* msg ); 11 | IMPORT void parlib_init_streams( void* in_src, int in_type, int in_size, void* out_dest, int out_type ); 12 | IMPORT void parlib_force_encoding( bool setting ); 13 | IMPORT const char* parlib_version_info( void ); 14 | IMPORT const char* parlib_short_name( void ); 15 | 16 | /* a short reminder about input/output stream types 17 | for the parlib_init_streams() function 18 | 19 | if input is file 20 | ---------------- 21 | in_scr -> name of input file 22 | in_type -> 0 23 | in_size -> ignore 24 | 25 | if input is memory 26 | ------------------ 27 | in_scr -> array containg data 28 | in_type -> 1 29 | in_size -> size of data array 30 | 31 | if input is *FILE (f.e. stdin) 32 | ------------------------------ 33 | in_src -> stream pointer 34 | in_type -> 2 35 | in_size -> ignore 36 | 37 | vice versa for output streams! */ 38 | -------------------------------------------------------------------------------- /source/packANY/packARI/packarilib.h: -------------------------------------------------------------------------------- 1 | // packARIlib.h - function declarations for the packARI library 2 | #if defined BUILD_DLL 3 | #define EXPORT __declspec( dllexport ) 4 | #else 5 | #define EXPORT extern 6 | #endif 7 | 8 | /* ----------------------------------------------- 9 | function declarations: library only functions 10 | ----------------------------------------------- */ 11 | 12 | EXPORT bool parlib_convert_stream2stream( char* msg ); 13 | EXPORT bool parlib_convert_file2file( char* in, char* out, char* msg ); 14 | EXPORT bool parlib_convert_stream2mem( unsigned char** out_file, unsigned int* out_size, char* msg ); 15 | EXPORT void parlib_init_streams( void* in_src, int in_type, int in_size, void* out_dest, int out_type ); 16 | EXPORT void parlib_force_encoding( bool setting ); 17 | EXPORT const char* parlib_version_info( void ); 18 | EXPORT const char* parlib_short_name( void ); 19 | 20 | /* a short reminder about input/output stream types 21 | for the parlib_init_streams() function 22 | 23 | if input is file 24 | ---------------- 25 | in_scr -> name of input file 26 | in_type -> 0 27 | in_size -> ignore 28 | 29 | if input is memory 30 | ------------------ 31 | in_scr -> array containg data 32 | in_type -> 1 33 | in_size -> size of data array 34 | 35 | if input is *FILE (f.e. stdin) 36 | ------------------------------ 37 | in_src -> stream pointer 38 | in_type -> 2 39 | in_size -> ignore 40 | 41 | vice versa for output streams! */ 42 | -------------------------------------------------------------------------------- /source/packANY/packARI/paritbl.h: -------------------------------------------------------------------------------- 1 | /* ----------------------------------------------- 2 | setting for packARI 3 | ----------------------------------------------- */ 4 | 5 | // !EDIT WITH CAUTION! 6 | // each change may lead to incompatibilities with previous version 7 | 8 | // action defines 9 | #define A_COMPRESS 1 10 | 11 | // file type defines 12 | #define F_UNK 1 13 | #define F_PAR 2 14 | 15 | // compression parameters (tweaking possible) 16 | #define MAX_ORDER 3 17 | #define CHECK_BYTES ( 1 << 14 ) 18 | 19 | // other setting 20 | #define ANALYSIS_CSV "par_analysis.csv" 21 | 22 | 23 | /* ----------------------------------------------- 24 | pearson hashing table 25 | ----------------------------------------------- */ 26 | 27 | // copied from Table 1 in: 28 | // Pearson, Peter K. (June 1990), "Fast Hashing of Variable-Length Text Strings", 29 | // Communications of the ACM 33 (6): 677, doi:10.1145/78973.78978 30 | static int pearson_hash[ 256 ] = 31 | { 32 | 1, 87, 49, 12, 176, 178, 102, 166, 121, 193, 6, 84, 249, 230, 44, 163, 33 | 14, 197, 213, 181, 161, 85, 218, 80, 64, 239, 24, 226, 236, 142, 38, 200, 34 | 110, 177, 104, 103, 141, 253, 255, 50, 77, 101, 81, 18, 45, 96, 31, 222, 35 | 25, 107, 190, 70, 86, 237, 240, 34, 72, 242, 20, 214, 244, 227, 149, 235, 36 | 97, 234, 57, 22, 60, 250, 82, 175, 208, 5, 127, 199, 111, 62, 135, 248, 37 | 174, 169, 211, 58, 66, 154, 106, 195, 245, 171, 17, 187, 182, 179, 0, 243, 38 | 132, 56, 148, 75, 128, 133, 158, 100, 130, 126, 91, 13, 153, 246, 216, 219, 39 | 119, 68, 223, 78, 83, 88, 201, 99, 122, 11, 92, 32, 136, 114, 52, 10, 40 | 138, 30, 48, 183, 156, 35, 61, 26, 143, 74, 251, 94, 129, 162, 63, 152, 41 | 170, 7, 115, 167, 241, 206, 3, 150, 55, 59, 151, 220, 90, 53, 23, 131, 42 | 125, 173, 15, 238, 79, 95, 89, 16, 105, 137, 225, 224, 217, 160, 37, 123, 43 | 118, 73, 2, 157, 46, 116, 9, 145, 134, 228, 207, 212, 202, 215, 69, 229, 44 | 27, 188, 67, 124, 168, 252, 42, 4, 29, 108, 21, 247, 19, 205, 39, 203, 45 | 233, 40, 186, 147, 198, 192, 155, 33, 164, 191, 98, 204, 165, 180, 117, 76, 46 | 140, 36, 210, 172, 41, 54, 159, 8, 185, 232, 113, 196, 231, 47, 146, 120, 47 | 51, 65, 28, 144, 254, 221, 93, 189, 194, 139, 112, 43, 71, 109, 184, 209 48 | }; 49 | -------------------------------------------------------------------------------- /source/packANY/packJPG/Makefile: -------------------------------------------------------------------------------- 1 | # Project: packJPG 2 | # Makefile created by Matthias Stirner 01/30/2012 3 | # Working with GCC 4.6.0 4 | 5 | CC = gcc 6 | CPP = g++ 7 | RC = windres -O coff 8 | RM = del 9 | CFLAGS = -I. -DDEV_BUILD -O3 -Wall -pedantic -funroll-loops -ffast-math -fsched-spec-load -fomit-frame-pointer 10 | LDFLAGS = -s -static-libgcc -static-libstdc++ 11 | DEPS = bitops.h aricoder.h pjpgtbl.h dct8x8.h Makefile 12 | OBJ = bitops.o aricoder.o packjpg.o 13 | RES = icons.res 14 | BIN = packJPG 15 | 16 | %.o: %.cpp $(DEPS) 17 | $(CPP) -c -o $@ $< $(CFLAGS) 18 | 19 | %.res: %.rc 20 | $(RC) $< $@ 21 | 22 | $(BIN): $(OBJ) $(RES) 23 | $(CPP) -o $@ $^ $(LDFLAGS) 24 | 25 | clean: 26 | $(RM) *.o 27 | -------------------------------------------------------------------------------- /source/packANY/packJPG/Makefile_dll: -------------------------------------------------------------------------------- 1 | # Project: packJPG DLL 2 | # Makefile created by Matthias Stirner 01/30/2012 3 | # Working with GCC 4.6.0 4 | 5 | CC = gcc 6 | CPP = g++ 7 | RC = windres -O coff 8 | RM = del 9 | CFLAGS = -I. -DBUILD_DLL -O2 -Wall -pedantic -fsched-spec-load -fomit-frame-pointer 10 | LDFLAGS = -Wl,--out-implib,libpackJPG.a -fvisibility=hidden -static-libgcc -static-libstdc++ 11 | DEPS = bitops.h aricoder.h pjpgtbl.h dct8x8.h Makefile 12 | OBJ = bitops.o aricoder.o packjpg.o 13 | RES = icons.res 14 | BIN = packJPG.dll 15 | 16 | %.o: %.cpp $(DEPS) 17 | $(CPP) -c -o $@ $< $(CFLAGS) 18 | 19 | %.res: %.rc 20 | $(RC) $< $@ 21 | 22 | $(BIN): $(OBJ) $(RES) 23 | $(CPP) -shared -o $@ $^ $(LDFLAGS) 24 | 25 | clean: 26 | $(RM) *.o 27 | -------------------------------------------------------------------------------- /source/packANY/packJPG/Makefile_lib: -------------------------------------------------------------------------------- 1 | # Project: packJPG static library 2 | # Makefile created by Matthias Stirner 01/30/2012 3 | # Working with GCC 4.6.0 4 | 5 | CC = gcc 6 | CPP = g++ 7 | AR = ar 8 | RM = del 9 | CFLAGS = -I. -DBUILD_LIB -O2 -Wall -pedantic -fsched-spec-load -fomit-frame-pointer 10 | LDFLAGS = -fvisibility=hidden -static-libgcc -static-libstdc++ 11 | DEPS = bitops.h aricoder.h pjpgtbl.h dct8x8.h Makefile 12 | OBJ = bitops.o aricoder.o packjpg.o 13 | BIN = packJPGlib.a 14 | 15 | %.o: %.cpp $(DEPS) 16 | $(CPP) -c -o $@ $< $(CFLAGS) 17 | 18 | $(BIN): $(OBJ) 19 | ar r $(BIN) $(OBJ) 20 | ranlib $(BIN) 21 | 22 | clean: 23 | $(RM) *.o 24 | -------------------------------------------------------------------------------- /source/packANY/packJPG/Makefile_linux: -------------------------------------------------------------------------------- 1 | # Project: packJPG 2 | # Makefile created by Matthias Stirner 28.03.2007 3 | # Working with GCC v3.4.5 4 | 5 | CC = gcc 6 | CPP = g++ 7 | RC = windres 8 | CFLAGS = -I. -DUNIX -DDEV_BUILD -O3 -Wall -pedantic -funroll-loops -ffast-math -fsched-spec-load -fomit-frame-pointer 9 | LDFLAGS = -s -static-libgcc 10 | DEPS = bitops.h aricoder.h pjpgtbl.h dct8x8.h Makefile 11 | OBJ = bitops.o aricoder.o packjpg.o 12 | RES = icon.res 13 | BIN = packjpg 14 | 15 | %.o: %.cpp $(DEPS) 16 | $(CPP) -c -o $@ $< $(CFLAGS) 17 | 18 | $(BIN): $(OBJ) 19 | $(CPP) -o $@ $^ $(LDFLAGS) 20 | 21 | clean: 22 | $(RM) $(OBJ) 23 | -------------------------------------------------------------------------------- /source/packANY/packJPG/app_icon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/packjpg/packARC/ed6ca67e0d6e0e20dafa7481cbecc7ff10fc00f4/source/packANY/packJPG/app_icon.ico -------------------------------------------------------------------------------- /source/packANY/packJPG/aricoder.h: -------------------------------------------------------------------------------- 1 | // defines for coder 2 | #define CODER_USE_BITS 31 // must never be above 31 3 | #define CODER_LIMIT100 ( (unsigned int) ( 1 << CODER_USE_BITS ) ) 4 | #define CODER_LIMIT025 ( ( CODER_LIMIT100 / 4 ) * 1 ) 5 | #define CODER_LIMIT050 ( ( CODER_LIMIT100 / 4 ) * 2 ) 6 | #define CODER_LIMIT075 ( ( CODER_LIMIT100 / 4 ) * 3 ) 7 | #define CODER_MAXSCALE CODER_LIMIT025 - 1 8 | #define ESCAPE_SYMBOL CODER_LIMIT025 9 | 10 | 11 | // symbol struct, used in arithmetic coding 12 | struct symbol { 13 | unsigned int low_count; 14 | unsigned int high_count; 15 | unsigned int scale; 16 | }; 17 | 18 | // table struct, used in in statistical models, 19 | // holding all info needed for one context 20 | struct table { 21 | // counts for each symbol contained in the table 22 | unsigned short* counts; 23 | // links to higher order contexts 24 | struct table** links; 25 | // link to lower order context 26 | struct table* lesser; 27 | // accumulated counts 28 | unsigned int scale; 29 | }; 30 | 31 | // special table struct, used in in model_s, 32 | // holding additional info for a speedier 'totalize_table' 33 | struct table_s { 34 | // counts for each symbol contained in the table 35 | unsigned short* counts; 36 | // links to higher order contexts 37 | struct table_s** links; 38 | // link to lower order context 39 | struct table_s* lesser; 40 | // speedup info 41 | unsigned short max_count; 42 | unsigned short max_symbol; 43 | // unsigned short esc_prob; 44 | }; 45 | 46 | 47 | /* ----------------------------------------------- 48 | class for arithmetic coding of data to/from iostream 49 | ----------------------------------------------- */ 50 | 51 | class aricoder 52 | { 53 | public: 54 | aricoder( iostream* stream, int iomode ); 55 | ~aricoder( void ); 56 | void encode( symbol* s ); 57 | unsigned int decode_count( symbol* s ); 58 | void decode( symbol* s ); 59 | 60 | private: 61 | // bitwise operations 62 | void write_bit( unsigned char bit ); 63 | unsigned char read_bit( void ); 64 | 65 | // i/o variables 66 | iostream* sptr; 67 | int mode; 68 | unsigned char bbyte; 69 | unsigned char cbit; 70 | 71 | // arithmetic coding variables 72 | unsigned int ccode; 73 | unsigned int clow; 74 | unsigned int chigh; 75 | unsigned int cstep; 76 | unsigned int nrbits; 77 | }; 78 | 79 | 80 | /* ----------------------------------------------- 81 | universal statistical model for arithmetic coding 82 | ----------------------------------------------- */ 83 | 84 | class model_s 85 | { 86 | public: 87 | 88 | model_s( int max_s, int max_c, int max_o, int c_lim ); 89 | ~model_s( void ); 90 | 91 | void update_model( int symbol ); 92 | void shift_context( int c ); 93 | void flush_model( int scale_factor ); 94 | void exclude_symbols( char rule, int c ); 95 | 96 | int convert_int_to_symbol( int c, symbol *s ); 97 | void get_symbol_scale( symbol *s ); 98 | int convert_symbol_to_int( int count, symbol *s ); 99 | 100 | bool error; 101 | 102 | 103 | private: 104 | 105 | // unsigned short* totals; 106 | unsigned int* totals; 107 | char* scoreboard; 108 | int sb0_count; 109 | table_s **contexts; 110 | table_s **storage; 111 | 112 | int max_symbol; 113 | int max_context; 114 | int current_order; 115 | int max_order; 116 | int max_count; 117 | 118 | inline void totalize_table(table_s* context ); 119 | inline void rescale_table(table_s* context, int scale_factor ); 120 | inline void recursive_flush(table_s* context, int scale_factor ); 121 | inline void recursive_cleanup(table_s* context ); 122 | }; 123 | 124 | 125 | /* ----------------------------------------------- 126 | binary statistical model for arithmetic coding 127 | ----------------------------------------------- */ 128 | 129 | class model_b 130 | { 131 | public: 132 | 133 | model_b( int max_c, int max_o, int c_lim ); 134 | ~model_b( void ); 135 | 136 | void update_model( int symbol ); 137 | void shift_context( int c ); 138 | void flush_model( int scale_factor ); 139 | 140 | int convert_int_to_symbol( int c, symbol *s ); 141 | void get_symbol_scale( symbol *s ); 142 | int convert_symbol_to_int( int count, symbol *s ); 143 | 144 | bool error; 145 | 146 | 147 | private: 148 | 149 | table **contexts; 150 | table **storage; 151 | 152 | int max_context; 153 | int max_order; 154 | int max_count; 155 | 156 | inline void check_counts( table *context ); 157 | inline void rescale_table( table* context, int scale_factor ); 158 | inline void recursive_flush( table* context, int scale_factor ); 159 | inline void recursive_cleanup( table *context ); 160 | }; 161 | 162 | 163 | /* ----------------------------------------------- 164 | shift context x2 model_s function 165 | ----------------------------------------------- */ 166 | static inline void shift_model( model_s* model, int ctx1, int ctx2 ) 167 | { 168 | model->shift_context( ctx1 ); 169 | model->shift_context( ctx2 ); 170 | } 171 | 172 | 173 | /* ----------------------------------------------- 174 | shift context x3 model_s function 175 | ----------------------------------------------- */ 176 | static inline void shift_model( model_s* model, int ctx1, int ctx2, int ctx3 ) 177 | { 178 | model->shift_context( ctx1 ); 179 | model->shift_context( ctx2 ); 180 | model->shift_context( ctx3 ); 181 | } 182 | 183 | 184 | /* ----------------------------------------------- 185 | shift context x2 model_b function 186 | ----------------------------------------------- */ 187 | static inline void shift_model( model_b* model, int ctx1, int ctx2 ) 188 | { 189 | model->shift_context( ctx1 ); 190 | model->shift_context( ctx2 ); 191 | } 192 | 193 | 194 | /* ----------------------------------------------- 195 | shift context x3 model_b function 196 | ----------------------------------------------- */ 197 | static inline void shift_model( model_b* model, int ctx1, int ctx2, int ctx3 ) 198 | { 199 | model->shift_context( ctx1 ); 200 | model->shift_context( ctx2 ); 201 | model->shift_context( ctx3 ); 202 | } 203 | 204 | 205 | /* ----------------------------------------------- 206 | generic model_s encoder function 207 | ----------------------------------------------- */ 208 | static inline void encode_ari( aricoder* encoder, model_s* model, int c ) 209 | { 210 | static symbol s; 211 | static int esc; 212 | 213 | do { 214 | esc = model->convert_int_to_symbol( c, &s ); 215 | encoder->encode( &s ); 216 | } while ( esc ); 217 | model->update_model( c ); 218 | } 219 | 220 | /* ----------------------------------------------- 221 | generic model_s decoder function 222 | ----------------------------------------------- */ 223 | static inline int decode_ari( aricoder* decoder, model_s* model ) 224 | { 225 | static symbol s; 226 | static unsigned int count; 227 | static int c; 228 | 229 | do{ 230 | model->get_symbol_scale( &s ); 231 | count = decoder->decode_count( &s ); 232 | c = model->convert_symbol_to_int( count, &s ); 233 | decoder->decode( &s ); 234 | } while ( c == ESCAPE_SYMBOL ); 235 | model->update_model( c ); 236 | 237 | return c; 238 | } 239 | 240 | /* ----------------------------------------------- 241 | generic model_b encoder function 242 | ----------------------------------------------- */ 243 | static inline void encode_ari( aricoder* encoder, model_b* model, int c ) 244 | { 245 | static symbol s; 246 | 247 | model->convert_int_to_symbol( c, &s ); 248 | encoder->encode( &s ); 249 | model->update_model( c ); 250 | } 251 | 252 | /* ----------------------------------------------- 253 | generic model_b decoder function 254 | ----------------------------------------------- */ 255 | static inline int decode_ari( aricoder* decoder, model_b* model ) 256 | { 257 | static symbol s; 258 | static unsigned int count; 259 | static int c; 260 | 261 | model->get_symbol_scale( &s ); 262 | count = decoder->decode_count( &s ); 263 | c = model->convert_symbol_to_int( count, &s ); 264 | decoder->decode( &s ); 265 | model->update_model( c ); 266 | 267 | return c; 268 | } 269 | -------------------------------------------------------------------------------- /source/packANY/packJPG/bitops.h: -------------------------------------------------------------------------------- 1 | #define RBITS( c, n ) ( c & ( 0xFF >> (8 - n) ) ) 2 | #define LBITS( c, n ) ( c >> (8 - n) ) 3 | #define MBITS( c, l, r ) ( RBITS( c,l ) >> r ) 4 | #define RBITS16( c, n ) ( c & ( 0xFFFFFFFF >> (16 - n) ) ) 5 | #define LBITS16( c, n ) ( c >> (16 - n) ) 6 | #define MBITS16( c, l, r ) ( RBITS16( c,l ) >> r ) 7 | #define RBITS32( c, n ) ( c & ( 0xFFFFFFFF >> (32 - n) ) ) 8 | #define LBITS32( c, n ) ( c >> (32 - n) ) 9 | #define MBITS32( c, l, r ) ( RBITS32( c,l ) >> r ) 10 | #define BITN( c, n ) ( (c >> n) & 0x1 ) 11 | #define BITLEN( l, v ) for ( l = 0; ( v >> l ) > 0; l++ ) 12 | #define FDIV2( v, p ) ( ( v < 0 ) ? -( (-v) >> p ) : ( v >> p ) ) 13 | 14 | #define TYPE_FILE 0 15 | #define TYPE_MEMORY 1 16 | #define TYPE_STREAM 2 17 | #define MODE_READ 0 18 | #define MODE_WRITE 1 19 | 20 | #define BTST_BUFF 1024 * 1024 21 | 22 | #include 23 | 24 | 25 | /* ----------------------------------------------- 26 | class to read arrays bitwise 27 | ----------------------------------------------- */ 28 | 29 | class abitreader 30 | { 31 | public: 32 | abitreader( unsigned char* array, int size ); 33 | ~abitreader( void ); 34 | unsigned int read( int nbits ); 35 | unsigned char read_bit( void ); 36 | unsigned char unpad( unsigned char fillbit ); 37 | int getpos( void ); 38 | int getbitp( void ); 39 | void setpos( int pbyte, int pbit ); 40 | void rewind_bits( int nbits ); 41 | bool eof; 42 | int peof; 43 | 44 | private: 45 | unsigned char* data; 46 | int lbyte; 47 | int cbyte; 48 | int cbit; 49 | }; 50 | 51 | 52 | /* ----------------------------------------------- 53 | class to write arrays bitwise 54 | ----------------------------------------------- */ 55 | 56 | class abitwriter 57 | { 58 | public: 59 | abitwriter( int size ); 60 | ~abitwriter( void ); 61 | void write( unsigned int val, int nbits ); 62 | void write_bit( unsigned char bit ); 63 | void pad ( unsigned char fillbit ); 64 | unsigned char* getptr( void ); 65 | int getpos( void ); 66 | int getbitp( void ); 67 | bool error; 68 | unsigned char fillbit; 69 | 70 | private: 71 | unsigned char* data; 72 | int dsize; 73 | int adds; 74 | int cbyte; 75 | int cbit; 76 | bool fmem; 77 | }; 78 | 79 | 80 | /* ----------------------------------------------- 81 | class to read arrays bytewise 82 | ----------------------------------------------- */ 83 | 84 | class abytereader 85 | { 86 | public: 87 | abytereader( unsigned char* array, int size ); 88 | ~abytereader( void ); 89 | int read( unsigned char* byte ); 90 | int read_n( unsigned char* byte, int n ); 91 | void seek( int pos ); 92 | int getsize( void ); 93 | int getpos( void ); 94 | bool eof; 95 | 96 | private: 97 | unsigned char* data; 98 | int lbyte; 99 | int cbyte; 100 | }; 101 | 102 | 103 | /* ----------------------------------------------- 104 | class to write arrays bytewise 105 | ----------------------------------------------- */ 106 | 107 | class abytewriter 108 | { 109 | public: 110 | abytewriter( int size ); 111 | ~abytewriter( void ); 112 | void write( unsigned char byte ); 113 | void write_n( unsigned char* byte, int n ); 114 | unsigned char* getptr( void ); 115 | unsigned char* peekptr( void ); 116 | int getpos( void ); 117 | void reset( void ); 118 | bool error; 119 | 120 | private: 121 | unsigned char* data; 122 | int dsize; 123 | int adds; 124 | int cbyte; 125 | bool fmem; 126 | }; 127 | 128 | 129 | /* ----------------------------------------------- 130 | class for input and output from file or memory 131 | ----------------------------------------------- */ 132 | 133 | class iostream 134 | { 135 | public: 136 | iostream( void* src, int srctype, int srcsize, int iomode ); 137 | ~iostream( void ); 138 | void switch_mode( void ); 139 | int read( void* to, int tpsize, int dtsize ); 140 | int write( void* from, int tpsize, int dtsize ); 141 | int flush( void ); 142 | int rewind( void ); 143 | int getpos( void ); 144 | int getsize( void ); 145 | unsigned char* getptr( void ); 146 | bool chkerr( void ); 147 | bool chkeof( void ); 148 | 149 | private: 150 | void open_file( void ); 151 | void open_mem( void ); 152 | void open_stream( void ); 153 | 154 | int write_file( void* from, int tpsize, int dtsize ); 155 | int read_file( void* to, int tpsize, int dtsize ); 156 | int write_mem( void* from, int tpsize, int dtsize ); 157 | int read_mem( void* to, int tpsize, int dtsize ); 158 | 159 | FILE* fptr; 160 | abytewriter* mwrt; 161 | abytereader* mrdr; 162 | 163 | bool free_mem_sw; 164 | void* source; 165 | int mode; 166 | int srct; 167 | int srcs; 168 | }; 169 | -------------------------------------------------------------------------------- /source/packANY/packJPG/file_icon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/packjpg/packARC/ed6ca67e0d6e0e20dafa7481cbecc7ff10fc00f4/source/packANY/packJPG/file_icon.ico -------------------------------------------------------------------------------- /source/packANY/packJPG/icons.rc: -------------------------------------------------------------------------------- 1 | app ICON app_icon.ico 2 | ICONS1 ICON file_icon.ico -------------------------------------------------------------------------------- /source/packANY/packJPG/icons.res: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/packjpg/packARC/ed6ca67e0d6e0e20dafa7481cbecc7ff10fc00f4/source/packANY/packJPG/icons.res -------------------------------------------------------------------------------- /source/packANY/packJPG/packjpgdll.h: -------------------------------------------------------------------------------- 1 | // packJPGdll.h - function import declarations for the packJPG DLL 2 | #define IMPORT __declspec( dllimport ) 3 | 4 | /* ----------------------------------------------- 5 | function declarations: library only functions 6 | ----------------------------------------------- */ 7 | 8 | IMPORT bool pjglib_convert_stream2stream( char* msg ); 9 | IMPORT bool pjglib_convert_file2file( char* in, char* out, char* msg ); 10 | IMPORT bool pjglib_convert_stream2mem( unsigned char** out_file, unsigned int* out_size, char* msg ); 11 | IMPORT void pjglib_init_streams( void* in_src, int in_type, int in_size, void* out_dest, int out_type ); 12 | IMPORT const char* pjglib_version_info( void ); 13 | IMPORT const char* pjglib_short_name( void ); 14 | 15 | /* a short reminder about input/output stream types 16 | for the pjglib_init_streams() function 17 | 18 | if input is file 19 | ---------------- 20 | in_scr -> name of input file 21 | in_type -> 0 22 | in_size -> ignore 23 | 24 | if input is memory 25 | ------------------ 26 | in_scr -> array containg data 27 | in_type -> 1 28 | in_size -> size of data array 29 | 30 | if input is *FILE (f.e. stdin) 31 | ------------------------------ 32 | in_src -> stream pointer 33 | in_type -> 2 34 | in_size -> ignore 35 | 36 | vice versa for output streams! */ 37 | -------------------------------------------------------------------------------- /source/packANY/packJPG/packjpglib.h: -------------------------------------------------------------------------------- 1 | // packJPGlib.h - function declarations for the packJPG library 2 | #if defined BUILD_DLL 3 | #define EXPORT __declspec( dllexport ) 4 | #else 5 | #define EXPORT extern 6 | #endif 7 | 8 | /* ----------------------------------------------- 9 | function declarations: library only functions 10 | ----------------------------------------------- */ 11 | 12 | EXPORT bool pjglib_convert_stream2stream( char* msg ); 13 | EXPORT bool pjglib_convert_file2file( char* in, char* out, char* msg ); 14 | EXPORT bool pjglib_convert_stream2mem( unsigned char** out_file, unsigned int* out_size, char* msg ); 15 | EXPORT void pjglib_init_streams( void* in_src, int in_type, int in_size, void* out_dest, int out_type ); 16 | EXPORT const char* pjglib_version_info( void ); 17 | EXPORT const char* pjglib_short_name( void ); 18 | 19 | /* a short reminder about input/output stream types 20 | for the pjglib_init_streams() function 21 | 22 | if input is file 23 | ---------------- 24 | in_scr -> name of input file 25 | in_type -> 0 26 | in_size -> ignore 27 | 28 | if input is memory 29 | ------------------ 30 | in_scr -> array containg data 31 | in_type -> 1 32 | in_size -> size of data array 33 | 34 | if input is *FILE (f.e. stdin) 35 | ------------------------------ 36 | in_src -> stream pointer 37 | in_type -> 2 38 | in_size -> ignore 39 | 40 | vice versa for output streams! */ 41 | -------------------------------------------------------------------------------- /source/packANY/packMP3/Makefile: -------------------------------------------------------------------------------- 1 | # Project: packMP3 2 | # Makefile created by Matthias Stirner 01/30/2012 3 | # Working with GCC 4.6.0 4 | 5 | CC = gcc 6 | CPP = g++ 7 | RC = windres -O coff 8 | RM = del 9 | CFLAGS = -I. -DDEV_BUILD -O3 -Wall -pedantic -funroll-loops -ffast-math -fsched-spec-load -fomit-frame-pointer 10 | LDFLAGS = -s -static-libgcc -static-libstdc++ 11 | DEPS = aricoder.h bitops.h huffmp3.h huffmp3tbl.h pmp3tbl.h pmp3bitlen.h Makefile 12 | OBJ = aricoder.o bitops.o huffmp3.o packmp3.o 13 | RES = icons.res 14 | BIN = packMP3 15 | 16 | %.o: %.cpp $(DEPS) 17 | $(CPP) -c -o $@ $< $(CFLAGS) 18 | 19 | %.res: %.rc 20 | $(RC) $< $@ 21 | 22 | $(BIN): $(OBJ) $(RES) 23 | $(CPP) -o $@ $^ $(LDFLAGS) 24 | 25 | clean: 26 | $(RM) *.o 27 | -------------------------------------------------------------------------------- /source/packANY/packMP3/Makefile_dll: -------------------------------------------------------------------------------- 1 | # Project: packMP3 DLL 2 | # Makefile created by Matthias Stirner 01/30/2012 3 | # Working with GCC 4.6.0 4 | 5 | CC = gcc 6 | CPP = g++ 7 | RC = windres -O coff 8 | RM = del 9 | CFLAGS = -I. -DBUILD_DLL -O2 -Wall -pedantic -fsched-spec-load -fomit-frame-pointer 10 | LDFLAGS = -Wl,--out-implib,libpackMP3.a -fvisibility=hidden -static-libgcc -static-libstdc++ 11 | DEPS = aricoder.h bitops.h huffmp3.h huffmp3tbl.h pmp3tbl.h pmp3bitlen.h Makefile 12 | OBJ = aricoder.o bitops.o huffmp3.o packmp3.o 13 | RES = icons.res 14 | BIN = packMP3.dll 15 | 16 | %.o: %.cpp $(DEPS) 17 | $(CPP) -c -o $@ $< $(CFLAGS) 18 | 19 | %.res: %.rc 20 | $(RC) $< $@ 21 | 22 | $(BIN): $(OBJ) $(RES) 23 | $(CPP) -shared -o $@ $^ $(LDFLAGS) 24 | 25 | clean: 26 | $(RM) *.o 27 | -------------------------------------------------------------------------------- /source/packANY/packMP3/Makefile_lib: -------------------------------------------------------------------------------- 1 | # Project: packMP3 static library 2 | # Makefile created by Matthias Stirner 01/30/2012 3 | # Working with GCC 4.6.0 4 | 5 | CC = gcc 6 | CPP = g++ 7 | AR = ar 8 | RM = del 9 | CFLAGS = -I. -DBUILD_LIB -O2 -Wall -pedantic -fsched-spec-load -fomit-frame-pointer 10 | LDFLAGS = -fvisibility=hidden -static-libgcc -static-libstdc++ 11 | DEPS = aricoder.h bitops.h huffmp3.h huffmp3tbl.h pmp3tbl.h pmp3bitlen.h Makefile 12 | OBJ = aricoder.o bitops.o huffmp3.o packmp3.o 13 | BIN = packMP3lib.a 14 | 15 | %.o: %.cpp $(DEPS) 16 | $(CPP) -c -o $@ $< $(CFLAGS) 17 | 18 | $(BIN): $(OBJ) 19 | ar r $(BIN) $(OBJ) 20 | ranlib $(BIN) 21 | 22 | clean: 23 | $(RM) *.o 24 | -------------------------------------------------------------------------------- /source/packANY/packMP3/app_icon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/packjpg/packARC/ed6ca67e0d6e0e20dafa7481cbecc7ff10fc00f4/source/packANY/packMP3/app_icon.ico -------------------------------------------------------------------------------- /source/packANY/packMP3/aricoder.h: -------------------------------------------------------------------------------- 1 | // defines for coder 2 | #define CODER_USE_BITS 31 // must never be above 31 3 | #define CODER_LIMIT100 ( (unsigned int) ( 1 << CODER_USE_BITS ) ) 4 | #define CODER_LIMIT025 ( ( CODER_LIMIT100 / 4 ) * 1 ) 5 | #define CODER_LIMIT050 ( ( CODER_LIMIT100 / 4 ) * 2 ) 6 | #define CODER_LIMIT075 ( ( CODER_LIMIT100 / 4 ) * 3 ) 7 | #define CODER_MAXSCALE CODER_LIMIT025 - 1 8 | #define ESCAPE_SYMBOL CODER_LIMIT025 9 | 10 | 11 | // symbol struct, used in arithmetic coding 12 | struct symbol { 13 | unsigned int low_count; 14 | unsigned int high_count; 15 | unsigned int scale; 16 | }; 17 | 18 | // table struct, used in in statistical models, 19 | // holding all info needed for one context 20 | struct table { 21 | // counts for each symbol contained in the table 22 | unsigned short* counts; 23 | // links to higher order contexts 24 | struct table** links; 25 | // link to lower order context 26 | struct table* lesser; 27 | // accumulated counts 28 | unsigned int scale; 29 | }; 30 | 31 | // special table struct, used in in model_s, 32 | // holding additional info for a speedier 'totalize_table' 33 | struct table_s { 34 | // counts for each symbol contained in the table 35 | unsigned short* counts; 36 | // links to higher order contexts 37 | struct table_s** links; 38 | // link to lower order context 39 | struct table_s* lesser; 40 | // speedup info 41 | unsigned short max_count; 42 | unsigned short max_symbol; 43 | // unsigned short esc_prob; 44 | }; 45 | 46 | 47 | /* ----------------------------------------------- 48 | class for arithmetic coding of data to/from iostream 49 | ----------------------------------------------- */ 50 | 51 | class aricoder 52 | { 53 | public: 54 | aricoder( iostream* stream, int iomode ); 55 | ~aricoder( void ); 56 | void encode( symbol* s ); 57 | unsigned int decode_count( symbol* s ); 58 | void decode( symbol* s ); 59 | 60 | private: 61 | // bitwise operations 62 | void write_bit( unsigned char bit ); 63 | unsigned char read_bit( void ); 64 | 65 | // i/o variables 66 | iostream* sptr; 67 | int mode; 68 | unsigned char bbyte; 69 | unsigned char cbit; 70 | 71 | // arithmetic coding variables 72 | unsigned int ccode; 73 | unsigned int clow; 74 | unsigned int chigh; 75 | unsigned int cstep; 76 | unsigned int nrbits; 77 | }; 78 | 79 | 80 | /* ----------------------------------------------- 81 | universal statistical model for arithmetic coding 82 | ----------------------------------------------- */ 83 | 84 | class model_s 85 | { 86 | public: 87 | 88 | model_s( int max_s, int max_c, int max_o, int c_lim ); 89 | ~model_s( void ); 90 | 91 | void update_model( int symbol ); 92 | void shift_context( int c ); 93 | void flush_model( int scale_factor ); 94 | void exclude_symbols( char rule, int c ); 95 | 96 | int convert_int_to_symbol( int c, symbol *s ); 97 | void get_symbol_scale( symbol *s ); 98 | int convert_symbol_to_int( int count, symbol *s ); 99 | 100 | bool error; 101 | 102 | 103 | private: 104 | 105 | // unsigned short* totals; 106 | unsigned int* totals; 107 | char* scoreboard; 108 | int sb0_count; 109 | table_s **contexts; 110 | table_s **storage; 111 | 112 | int max_symbol; 113 | int max_context; 114 | int current_order; 115 | int max_order; 116 | int max_count; 117 | 118 | inline void totalize_table(table_s* context ); 119 | inline void rescale_table(table_s* context, int scale_factor ); 120 | inline void recursive_flush(table_s* context, int scale_factor ); 121 | inline void recursive_cleanup(table_s* context ); 122 | }; 123 | 124 | 125 | /* ----------------------------------------------- 126 | binary statistical model for arithmetic coding 127 | ----------------------------------------------- */ 128 | 129 | class model_b 130 | { 131 | public: 132 | 133 | model_b( int max_c, int max_o, int c_lim ); 134 | ~model_b( void ); 135 | 136 | void update_model( int symbol ); 137 | void shift_context( int c ); 138 | void flush_model( int scale_factor ); 139 | 140 | int convert_int_to_symbol( int c, symbol *s ); 141 | void get_symbol_scale( symbol *s ); 142 | int convert_symbol_to_int( int count, symbol *s ); 143 | 144 | bool error; 145 | 146 | 147 | private: 148 | 149 | table **contexts; 150 | table **storage; 151 | 152 | int max_context; 153 | int max_order; 154 | int max_count; 155 | 156 | inline void check_counts( table *context ); 157 | inline void rescale_table( table* context, int scale_factor ); 158 | inline void recursive_flush( table* context, int scale_factor ); 159 | inline void recursive_cleanup( table *context ); 160 | }; 161 | 162 | 163 | /* ----------------------------------------------- 164 | shift context x2 model_s function 165 | ----------------------------------------------- */ 166 | static inline void shift_model( model_s* model, int ctx1, int ctx2 ) 167 | { 168 | model->shift_context( ctx1 ); 169 | model->shift_context( ctx2 ); 170 | } 171 | 172 | 173 | /* ----------------------------------------------- 174 | shift context x3 model_s function 175 | ----------------------------------------------- */ 176 | static inline void shift_model( model_s* model, int ctx1, int ctx2, int ctx3 ) 177 | { 178 | model->shift_context( ctx1 ); 179 | model->shift_context( ctx2 ); 180 | model->shift_context( ctx3 ); 181 | } 182 | 183 | 184 | /* ----------------------------------------------- 185 | shift context x2 model_b function 186 | ----------------------------------------------- */ 187 | static inline void shift_model( model_b* model, int ctx1, int ctx2 ) 188 | { 189 | model->shift_context( ctx1 ); 190 | model->shift_context( ctx2 ); 191 | } 192 | 193 | 194 | /* ----------------------------------------------- 195 | shift context x3 model_b function 196 | ----------------------------------------------- */ 197 | static inline void shift_model( model_b* model, int ctx1, int ctx2, int ctx3 ) 198 | { 199 | model->shift_context( ctx1 ); 200 | model->shift_context( ctx2 ); 201 | model->shift_context( ctx3 ); 202 | } 203 | 204 | 205 | /* ----------------------------------------------- 206 | generic model_s encoder function 207 | ----------------------------------------------- */ 208 | static inline void encode_ari( aricoder* encoder, model_s* model, int c ) 209 | { 210 | static symbol s; 211 | static int esc; 212 | 213 | do { 214 | esc = model->convert_int_to_symbol( c, &s ); 215 | encoder->encode( &s ); 216 | } while ( esc ); 217 | model->update_model( c ); 218 | } 219 | 220 | /* ----------------------------------------------- 221 | generic model_s decoder function 222 | ----------------------------------------------- */ 223 | static inline int decode_ari( aricoder* decoder, model_s* model ) 224 | { 225 | static symbol s; 226 | static unsigned int count; 227 | static int c; 228 | 229 | do{ 230 | model->get_symbol_scale( &s ); 231 | count = decoder->decode_count( &s ); 232 | c = model->convert_symbol_to_int( count, &s ); 233 | decoder->decode( &s ); 234 | } while ( c == ESCAPE_SYMBOL ); 235 | model->update_model( c ); 236 | 237 | return c; 238 | } 239 | 240 | /* ----------------------------------------------- 241 | generic model_b encoder function 242 | ----------------------------------------------- */ 243 | static inline void encode_ari( aricoder* encoder, model_b* model, int c ) 244 | { 245 | static symbol s; 246 | 247 | model->convert_int_to_symbol( c, &s ); 248 | encoder->encode( &s ); 249 | model->update_model( c ); 250 | } 251 | 252 | /* ----------------------------------------------- 253 | generic model_b decoder function 254 | ----------------------------------------------- */ 255 | static inline int decode_ari( aricoder* decoder, model_b* model ) 256 | { 257 | static symbol s; 258 | static unsigned int count; 259 | static int c; 260 | 261 | model->get_symbol_scale( &s ); 262 | count = decoder->decode_count( &s ); 263 | c = model->convert_symbol_to_int( count, &s ); 264 | decoder->decode( &s ); 265 | model->update_model( c ); 266 | 267 | return c; 268 | } 269 | -------------------------------------------------------------------------------- /source/packANY/packMP3/bitops.h: -------------------------------------------------------------------------------- 1 | #define RBITS( c, n ) ( c & ( 0xFF >> (8 - n) ) ) 2 | #define LBITS( c, n ) ( c >> (8 - n) ) 3 | #define MBITS( c, l, r ) ( RBITS( c,l ) >> r ) 4 | #define RBITS16( c, n ) ( c & ( 0xFFFFFFFF >> (16 - n) ) ) 5 | #define LBITS16( c, n ) ( c >> (16 - n) ) 6 | #define MBITS16( c, l, r ) ( RBITS16( c,l ) >> r ) 7 | #define RBITS32( c, n ) ( c & ( 0xFFFFFFFF >> (32 - n) ) ) 8 | #define LBITS32( c, n ) ( c >> (32 - n) ) 9 | #define MBITS32( c, l, r ) ( RBITS32( c,l ) >> r ) 10 | #define BITN( c, n ) ( (c >> n) & 0x1 ) 11 | #define BITLEN( l, v ) for ( l = 0; ( v >> l ) > 0; l++ ) 12 | #define FDIV2( v, p ) ( ( v < 0 ) ? -( (-v) >> p ) : ( v >> p ) ) 13 | 14 | #define TYPE_FILE 0 15 | #define TYPE_MEMORY 1 16 | #define TYPE_STREAM 2 17 | #define MODE_READ 0 18 | #define MODE_WRITE 1 19 | 20 | #define BTST_BUFF 1024 * 1024 21 | 22 | #include 23 | 24 | 25 | /* ----------------------------------------------- 26 | class to read arrays bitwise 27 | ----------------------------------------------- */ 28 | 29 | class abitreader 30 | { 31 | public: 32 | abitreader( unsigned char* array, int size ); 33 | ~abitreader( void ); 34 | unsigned int read( int nbits ); 35 | unsigned char read_bit( void ); 36 | unsigned char unpad( unsigned char fillbit ); 37 | int getpos( void ); 38 | int getbitp( void ); 39 | void setpos( int pbyte, int pbit ); 40 | void rewind_bits( int nbits ); 41 | bool eof; 42 | int peof; 43 | 44 | private: 45 | unsigned char* data; 46 | int lbyte; 47 | int cbyte; 48 | int cbit; 49 | }; 50 | 51 | 52 | /* ----------------------------------------------- 53 | class to write arrays bitwise 54 | ----------------------------------------------- */ 55 | 56 | class abitwriter 57 | { 58 | public: 59 | abitwriter( int size ); 60 | ~abitwriter( void ); 61 | void write( unsigned int val, int nbits ); 62 | void write_bit( unsigned char bit ); 63 | void pad ( unsigned char fillbit ); 64 | unsigned char* getptr( void ); 65 | int getpos( void ); 66 | int getbitp( void ); 67 | bool error; 68 | unsigned char fillbit; 69 | 70 | private: 71 | unsigned char* data; 72 | int dsize; 73 | int adds; 74 | int cbyte; 75 | int cbit; 76 | bool fmem; 77 | }; 78 | 79 | 80 | /* ----------------------------------------------- 81 | class to read arrays bytewise 82 | ----------------------------------------------- */ 83 | 84 | class abytereader 85 | { 86 | public: 87 | abytereader( unsigned char* array, int size ); 88 | ~abytereader( void ); 89 | int read( unsigned char* byte ); 90 | int read_n( unsigned char* byte, int n ); 91 | void seek( int pos ); 92 | int getsize( void ); 93 | int getpos( void ); 94 | bool eof; 95 | 96 | private: 97 | unsigned char* data; 98 | int lbyte; 99 | int cbyte; 100 | }; 101 | 102 | 103 | /* ----------------------------------------------- 104 | class to write arrays bytewise 105 | ----------------------------------------------- */ 106 | 107 | class abytewriter 108 | { 109 | public: 110 | abytewriter( int size ); 111 | ~abytewriter( void ); 112 | void write( unsigned char byte ); 113 | void write_n( unsigned char* byte, int n ); 114 | unsigned char* getptr( void ); 115 | unsigned char* peekptr( void ); 116 | int getpos( void ); 117 | void reset( void ); 118 | bool error; 119 | 120 | private: 121 | unsigned char* data; 122 | int dsize; 123 | int adds; 124 | int cbyte; 125 | bool fmem; 126 | }; 127 | 128 | 129 | /* ----------------------------------------------- 130 | class for input and output from file or memory 131 | ----------------------------------------------- */ 132 | 133 | class iostream 134 | { 135 | public: 136 | iostream( void* src, int srctype, int srcsize, int iomode ); 137 | ~iostream( void ); 138 | void switch_mode( void ); 139 | int read( void* to, int tpsize, int dtsize ); 140 | int write( void* from, int tpsize, int dtsize ); 141 | int flush( void ); 142 | int rewind( void ); 143 | int getpos( void ); 144 | int getsize( void ); 145 | unsigned char* getptr( void ); 146 | bool chkerr( void ); 147 | bool chkeof( void ); 148 | 149 | private: 150 | void open_file( void ); 151 | void open_mem( void ); 152 | void open_stream( void ); 153 | 154 | int write_file( void* from, int tpsize, int dtsize ); 155 | int read_file( void* to, int tpsize, int dtsize ); 156 | int write_mem( void* from, int tpsize, int dtsize ); 157 | int read_mem( void* to, int tpsize, int dtsize ); 158 | 159 | FILE* fptr; 160 | abytewriter* mwrt; 161 | abytereader* mrdr; 162 | 163 | bool free_mem_sw; 164 | void* source; 165 | int mode; 166 | int srct; 167 | int srcs; 168 | }; 169 | -------------------------------------------------------------------------------- /source/packANY/packMP3/file_icon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/packjpg/packARC/ed6ca67e0d6e0e20dafa7481cbecc7ff10fc00f4/source/packANY/packMP3/file_icon.ico -------------------------------------------------------------------------------- /source/packANY/packMP3/huffmp3.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | #include "bitops.h" 5 | #include "huffmp3.h" 6 | 7 | // bit buffer size - careful changing this! 8 | // should not be smaller than 8 or HWIDTH_MAX 9 | #define BIT_BUFFER_SIZE 16 10 | 11 | 12 | /* ----------------------------------------------- 13 | small values quadruple conversion table (abs) 14 | ----------------------------------------------- */ 15 | static const unsigned char sv_qconv_abs[ 16 ][ 4 ] = { 16 | { 0, 0, 0, 0 }, // 0000 -> 0/0/0/0 17 | { 0, 0, 0, 1 }, // 0001 -> 0/0/0/1 18 | { 0, 0, 1, 0 }, // 0010 -> 0/0/1/0 19 | { 0, 0, 1, 1 }, // 0011 -> 0/0/1/1 20 | { 0, 1, 0, 0 }, // 0100 -> 0/1/0/0 21 | { 0, 1, 0, 1 }, // 0101 -> 0/1/0/1 22 | { 0, 1, 1, 0 }, // 0110 -> 0/1/1/0 23 | { 0, 1, 1, 1 }, // 0111 -> 0/1/1/1 24 | { 1, 0, 0, 0 }, // 1000 -> 1/0/0/0 25 | { 1, 0, 0, 1 }, // 1001 -> 1/0/0/1 26 | { 1, 0, 1, 0 }, // 1010 -> 1/0/1/0 27 | { 1, 0, 1, 1 }, // 1011 -> 1/0/1/1 28 | { 1, 1, 0, 0 }, // 1100 -> 1/1/0/0 29 | { 1, 1, 0, 1 }, // 1101 -> 1/1/0/1 30 | { 1, 1, 1, 0 }, // 1110 -> 1/1/1/0 31 | { 1, 1, 1, 1 }, // 1111 -> 1/1/1/1 32 | }; 33 | 34 | 35 | /* ----------------------------------------------- 36 | constructor for huffman reader class 37 | ----------------------------------------------- */ 38 | 39 | huffman_reader::huffman_reader( unsigned char* data, int size ) 40 | { 41 | // WARNING: NO error checks in this class! 42 | // init bitreader 43 | bit_reader = new abitreader( data, size ); 44 | // fill the bit buffer for the first time 45 | bit_buffer = bit_reader->read( BIT_BUFFER_SIZE ); 46 | // set count zero 47 | count = 0; 48 | } 49 | 50 | 51 | /* ----------------------------------------------- 52 | destructor for huffman reader class 53 | ----------------------------------------------- */ 54 | 55 | huffman_reader::~huffman_reader( void ) 56 | { 57 | // close bitreader 58 | delete( bit_reader ); 59 | } 60 | 61 | 62 | /* ----------------------------------------------- 63 | decode one big value pair 64 | ----------------------------------------------- */ 65 | 66 | void huffman_reader::decode_pair( huffman_conv_set* table, unsigned char* vals ) 67 | { 68 | huffman_conv* conv; 69 | int ext; 70 | 71 | 72 | for ( ext = 0; ext != -1; ext = conv->ext ) { 73 | conv = (table+ext)->h + ( bit_buffer >> ( BIT_BUFFER_SIZE - (table+ext)->hwidth ) ); 74 | advance_bitstream( conv->len ); 75 | } 76 | 77 | vals[ 0 ] = conv->v0; 78 | vals[ 1 ] = conv->v1; 79 | } 80 | 81 | 82 | /* ----------------------------------------------- 83 | decode one small value quadruple 84 | ----------------------------------------------- */ 85 | 86 | void huffman_reader::decode_quadruple( huffman_conv_set* table, unsigned char* vals ) 87 | { 88 | huffman_conv* conv; 89 | 90 | conv = table->h + ( bit_buffer >> ( BIT_BUFFER_SIZE - table->hwidth ) ); 91 | advance_bitstream( conv->len ); 92 | 93 | memcpy( vals, sv_qconv_abs[ conv->v0 ], sizeof( char ) * 4 ); 94 | } 95 | 96 | 97 | /* ----------------------------------------------- 98 | bit reader function for n bit 99 | ----------------------------------------------- */ 100 | 101 | unsigned int huffman_reader::read_bits( int n ) 102 | { 103 | unsigned int bits; 104 | 105 | // read bits 106 | bits = ( n <= BIT_BUFFER_SIZE ) ? 107 | bit_buffer >> (BIT_BUFFER_SIZE-n) : 108 | ( bit_buffer << (n-BIT_BUFFER_SIZE) ) | bit_reader->read( (n-BIT_BUFFER_SIZE) ); 109 | // refill the buffer 110 | advance_bitstream( n ); 111 | 112 | return bits; 113 | } 114 | 115 | 116 | /* ----------------------------------------------- 117 | bit reader function for one bit 118 | ----------------------------------------------- */ 119 | 120 | unsigned char huffman_reader::read_bit( void ) 121 | { 122 | unsigned char bit; 123 | 124 | // read one bit 125 | bit = bit_buffer >> (BIT_BUFFER_SIZE-1); 126 | // refill the buffer 127 | advance_bitstream_1(); 128 | 129 | return bit; 130 | } 131 | 132 | 133 | /* ----------------------------------------------- 134 | reset the internal bit counter 135 | ----------------------------------------------- */ 136 | 137 | void huffman_reader::reset_counter( void ) 138 | { 139 | count = 0; 140 | } 141 | 142 | 143 | /* ----------------------------------------------- 144 | get the internal bit count 145 | ----------------------------------------------- */ 146 | 147 | int huffman_reader::get_count( void ) 148 | { 149 | return count; 150 | } 151 | 152 | 153 | /* ----------------------------------------------- 154 | rewind n bits 155 | ----------------------------------------------- */ 156 | 157 | void huffman_reader::rewind_bits( int n ) 158 | { 159 | // rewind n bits 160 | bit_reader->rewind_bits( n + BIT_BUFFER_SIZE ); 161 | // fill the bit buffer 162 | bit_buffer = bit_reader->read( BIT_BUFFER_SIZE ); 163 | // set back the counter 164 | count = ( count > n ) ? count - n : 0; 165 | } 166 | 167 | 168 | /* ----------------------------------------------- 169 | set position in stream 170 | ----------------------------------------------- */ 171 | 172 | void huffman_reader::setpos( int pbyte, int pbit ) 173 | { 174 | // reposition the bit reader 175 | bit_reader->setpos( pbyte, pbit ); 176 | // fill the bit buffer 177 | bit_buffer = bit_reader->read( BIT_BUFFER_SIZE ); 178 | } 179 | 180 | 181 | /* ----------------------------------------------- 182 | return current byte position 183 | ----------------------------------------------- */ 184 | 185 | int huffman_reader::getpos( void ) 186 | { 187 | // ugly, but it works! 188 | return bit_reader->getpos() - ( BIT_BUFFER_SIZE + ( 8 - bit_reader->getbitp() ) ) / 8; 189 | } 190 | 191 | 192 | /* ----------------------------------------------- 193 | refill bit buffer utility function 194 | ----------------------------------------------- */ 195 | 196 | inline void huffman_reader::advance_bitstream( int n ) 197 | { 198 | // refill the buffer 199 | bit_buffer = ( n >= BIT_BUFFER_SIZE ) ? 200 | bit_reader->read( BIT_BUFFER_SIZE ) : 201 | ( ( bit_buffer << n ) | bit_reader->read( n ) ) & ( ( 1 << BIT_BUFFER_SIZE ) - 1 ); 202 | 203 | // record # of bits read 204 | count += n; 205 | } 206 | 207 | 208 | /* ----------------------------------------------- 209 | refill bit buffer utility function (1 bit) 210 | ----------------------------------------------- */ 211 | 212 | inline void huffman_reader::advance_bitstream_1( void ) 213 | { 214 | // refill the buffer 215 | bit_buffer = ( ( bit_buffer << 1 ) | bit_reader->read_bit() ) & 216 | ( ( 1 << BIT_BUFFER_SIZE ) - 1 ); 217 | 218 | // increment counter 219 | count++; 220 | } 221 | 222 | 223 | /* ----------------------------------------------- 224 | constructor for huffman writer class 225 | ----------------------------------------------- */ 226 | 227 | huffman_writer::huffman_writer( int adds ) 228 | { 229 | // WARNING: NO error checks in this class! 230 | // init bitwriter - recommended value: 5MB 231 | if ( adds == 0 ) adds = 5 * 1024 * 1024; 232 | bit_writer = new abitwriter( adds ); 233 | // set count zero 234 | count = 0; 235 | } 236 | 237 | 238 | /* ----------------------------------------------- 239 | destructor for huffman writer class 240 | ----------------------------------------------- */ 241 | 242 | huffman_writer::~huffman_writer( void ) 243 | { 244 | // close bitwriter 245 | delete( bit_writer ); 246 | } 247 | 248 | 249 | /* ----------------------------------------------- 250 | encode one big value pair 251 | ----------------------------------------------- */ 252 | 253 | void huffman_writer::encode_pair( huffman_code** hcodes, unsigned char* vals ) 254 | { 255 | huffman_code* hcode; 256 | 257 | // find correct code, encode absvals and signs 258 | hcode = &hcodes[vals[0]][vals[1]]; 259 | write_bits( hcode->code, hcode->len ); 260 | } 261 | 262 | 263 | /* ----------------------------------------------- 264 | encode one small value quadruple 265 | ----------------------------------------------- */ 266 | 267 | void huffman_writer::encode_quadruple( huffman_code* hcode, unsigned char* vals ) 268 | { 269 | int bits = 0; 270 | int i; 271 | 272 | 273 | // build bits unit 274 | for ( i = 0; i < 4; i++ ) { 275 | bits = bits << 1; 276 | if ( vals[i] ) bits |= 1; 277 | } 278 | 279 | // encode vals 280 | hcode += bits; 281 | write_bits( hcode->code, hcode->len ); 282 | } 283 | 284 | 285 | /* ----------------------------------------------- 286 | bit writer function for n bit 287 | ----------------------------------------------- */ 288 | 289 | void huffman_writer::write_bits( unsigned int bits, int n ) 290 | { 291 | // write bits 292 | bit_writer->write( bits, n ); 293 | // take count 294 | count += n; 295 | } 296 | 297 | 298 | /* ----------------------------------------------- 299 | bit writer function for 1 bit 300 | ----------------------------------------------- */ 301 | 302 | void huffman_writer::write_bit( unsigned char bit ) 303 | { 304 | // write bit 305 | bit_writer->write_bit( bit ); 306 | // increment counter 307 | count++; 308 | } 309 | 310 | 311 | /* ----------------------------------------------- 312 | reset the internal bit counter 313 | ----------------------------------------------- */ 314 | 315 | void huffman_writer::reset_counter( void ) 316 | { 317 | count = 0; 318 | } 319 | 320 | 321 | /* ----------------------------------------------- 322 | get the internal bit count 323 | ----------------------------------------------- */ 324 | 325 | int huffman_writer::get_count( void ) 326 | { 327 | return count; 328 | } 329 | 330 | 331 | /* ----------------------------------------------- 332 | return data pointer (when finished) 333 | ----------------------------------------------- */ 334 | 335 | unsigned char* huffman_writer::getptr( void ) 336 | { 337 | return bit_writer->getptr(); 338 | } 339 | 340 | 341 | /* ----------------------------------------------- 342 | return current byte position 343 | ----------------------------------------------- */ 344 | 345 | int huffman_writer::getpos( void ) 346 | { 347 | return bit_writer->getpos(); 348 | } 349 | -------------------------------------------------------------------------------- /source/packANY/packMP3/huffmp3.h: -------------------------------------------------------------------------------- 1 | /* ----------------------------------------------- 2 | struct declarations 3 | ----------------------------------------------- */ 4 | 5 | struct huffman_code { 6 | unsigned char len; 7 | unsigned int code; 8 | }; 9 | 10 | struct huffman_enc_table { 11 | huffman_code** h; 12 | int linbits; 13 | int max; 14 | }; 15 | 16 | struct huffman_conv { 17 | unsigned char len; 18 | int v0; 19 | int v1; 20 | int ext; 21 | }; 22 | 23 | struct huffman_conv_set { 24 | huffman_conv* h; 25 | int hwidth; 26 | }; 27 | 28 | struct huffman_dec_table { 29 | huffman_conv_set* h; 30 | int linbits; 31 | int max; 32 | }; 33 | 34 | 35 | /* ----------------------------------------------- 36 | class for huffman decoding/data reading 37 | ----------------------------------------------- */ 38 | 39 | class huffman_reader 40 | { 41 | public: 42 | huffman_reader( unsigned char* data, int size ); 43 | ~huffman_reader( void ); 44 | // public functions 45 | void decode_pair( huffman_conv_set* table, unsigned char* vals ); 46 | void decode_quadruple( huffman_conv_set* table, unsigned char* vals ); 47 | unsigned int read_bits( int n ); 48 | // not the fastest method to read single bits/bytes 49 | // luckily, we won't need it that often 50 | unsigned char read_bit( void ); 51 | void reset_counter( void ); 52 | int get_count( void ); 53 | void rewind_bits( int n ); 54 | void setpos( int pbyte, int pbit ); 55 | int getpos(); 56 | 57 | private: 58 | // utility functions 59 | inline void advance_bitstream( int n ); 60 | inline void advance_bitstream_1( void ); 61 | 62 | // storage 63 | abitreader* bit_reader; 64 | unsigned int bit_buffer; 65 | int count; 66 | }; 67 | 68 | 69 | /* ----------------------------------------------- 70 | class for huffman encoding/data writer 71 | ----------------------------------------------- */ 72 | 73 | class huffman_writer 74 | { 75 | public: 76 | huffman_writer( int adds ); 77 | ~huffman_writer( void ); 78 | // public functions 79 | void encode_pair( huffman_code** hcodes, unsigned char* vals ); 80 | void encode_quadruple( huffman_code* hcode, unsigned char* vals ); 81 | void write_bits( unsigned int bits, int n ); 82 | void write_bit( unsigned char bit ); 83 | void reset_counter( void ); 84 | int get_count( void ); 85 | unsigned char* getptr( void ); 86 | int getpos(); 87 | 88 | private: 89 | // storage 90 | abitwriter* bit_writer; 91 | int count; 92 | }; 93 | -------------------------------------------------------------------------------- /source/packANY/packMP3/icons.rc: -------------------------------------------------------------------------------- 1 | app ICON app_icon.ico 2 | ICONS1 ICON file_icon.ico -------------------------------------------------------------------------------- /source/packANY/packMP3/icons.res: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/packjpg/packARC/ed6ca67e0d6e0e20dafa7481cbecc7ff10fc00f4/source/packANY/packMP3/icons.res -------------------------------------------------------------------------------- /source/packANY/packMP3/packmp3dll.h: -------------------------------------------------------------------------------- 1 | // packMP3dll.h - function import declarations for the packMP3 DLL 2 | #define IMPORT __declspec( dllimport ) 3 | 4 | /* ----------------------------------------------- 5 | function declarations: library only functions 6 | ----------------------------------------------- */ 7 | 8 | IMPORT bool pmplib_convert_stream2stream( char* msg ); 9 | IMPORT bool pmplib_convert_file2file( char* in, char* out, char* msg ); 10 | IMPORT bool pmplib_convert_stream2mem( unsigned char** out_file, unsigned int* out_size, char* msg ); 11 | IMPORT void pmplib_init_streams( void* in_src, int in_type, int in_size, void* out_dest, int out_type ); 12 | IMPORT const char* pmplib_version_info( void ); 13 | IMPORT const char* pmplib_short_name( void ); 14 | 15 | /* a short reminder about input/output stream types 16 | for the pmplib_init_streams() function 17 | 18 | if input is file 19 | ---------------- 20 | in_scr -> name of input file 21 | in_type -> 0 22 | in_size -> ignore 23 | 24 | if input is memory 25 | ------------------ 26 | in_scr -> array containg data 27 | in_type -> 1 28 | in_size -> size of data array 29 | 30 | if input is *FILE (f.e. stdin) 31 | ------------------------------ 32 | in_src -> stream pointer 33 | in_type -> 2 34 | in_size -> ignore 35 | 36 | vice versa for output streams! */ 37 | -------------------------------------------------------------------------------- /source/packANY/packMP3/packmp3lib.h: -------------------------------------------------------------------------------- 1 | // packMP3lib.h - function declarations for the packMP3 library 2 | #if defined BUILD_DLL 3 | #define EXPORT __declspec( dllexport ) 4 | #else 5 | #define EXPORT extern 6 | #endif 7 | 8 | /* ----------------------------------------------- 9 | function declarations: library only functions 10 | ----------------------------------------------- */ 11 | 12 | EXPORT bool pmplib_convert_stream2stream( char* msg ); 13 | EXPORT bool pmplib_convert_file2file( char* in, char* out, char* msg ); 14 | EXPORT bool pmplib_convert_stream2mem( unsigned char** out_file, unsigned int* out_size, char* msg ); 15 | EXPORT void pmplib_init_streams( void* in_src, int in_type, int in_size, void* out_dest, int out_type ); 16 | EXPORT const char* pmplib_version_info( void ); 17 | EXPORT const char* pmplib_short_name( void ); 18 | 19 | /* a short reminder about input/output stream types 20 | for the pmplib_init_streams() function 21 | 22 | if input is file 23 | ---------------- 24 | in_scr -> name of input file 25 | in_type -> 0 26 | in_size -> ignore 27 | 28 | if input is memory 29 | ------------------ 30 | in_scr -> array containg data 31 | in_type -> 1 32 | in_size -> size of data array 33 | 34 | if input is *FILE (f.e. stdin) 35 | ------------------------------ 36 | in_src -> stream pointer 37 | in_type -> 2 38 | in_size -> ignore 39 | 40 | vice versa for output streams! */ 41 | -------------------------------------------------------------------------------- /source/packANY/packPNM/Makefile: -------------------------------------------------------------------------------- 1 | # Project: packPNM 2 | # Makefile created by Matthias Stirner 01/30/2012 3 | # Working with GCC 4.6.0 4 | 5 | CC = gcc 6 | CPP = g++ 7 | RC = windres -O coff 8 | RM = del 9 | CFLAGS = -DDEV_BUILD -I. -O3 -Wall -pedantic -funroll-loops -ffast-math -fsched-spec-load -fomit-frame-pointer 10 | LDFLAGS = -s -static-libgcc -static-libstdc++ 11 | DEPS = aricoder.h bitops.h ppnmtbl.h ppnmbitlen.h Makefile 12 | OBJ = aricoder.o bitops.o packpnm.o 13 | RES = icons.res 14 | BIN = packPNM 15 | 16 | %.o: %.cpp $(DEPS) 17 | $(CPP) -c -o $@ $< $(CFLAGS) 18 | 19 | %.res: %.rc 20 | $(RC) $< $@ 21 | 22 | $(BIN): $(OBJ) $(RES) 23 | $(CPP) -o $@ $^ $(LDFLAGS) 24 | 25 | clean: 26 | $(RM) *.o 27 | -------------------------------------------------------------------------------- /source/packANY/packPNM/Makefile_dll: -------------------------------------------------------------------------------- 1 | # Project: packPNM DLL 2 | # Makefile created by Matthias Stirner 01/30/2012 3 | # Working with GCC 4.6.0 4 | 5 | CC = gcc 6 | CPP = g++ 7 | RC = windres -O coff 8 | RM = del 9 | CFLAGS = -I. -DBUILD_DLL -O2 -Wall -pedantic -fsched-spec-load -fomit-frame-pointer 10 | LDFLAGS = -Wl,--out-implib,libpackARI.a -fvisibility=hidden -static-libgcc -static-libstdc++ 11 | DEPS = aricoder.h bitops.h ppnmtbl.h ppnmbitlen.h Makefile 12 | OBJ = aricoder.o bitops.o packpnm.o 13 | RES = icons.res 14 | BIN = packARI.dll 15 | 16 | %.o: %.cpp $(DEPS) 17 | $(CPP) -c -o $@ $< $(CFLAGS) 18 | 19 | %.res: %.rc 20 | $(RC) $< $@ 21 | 22 | $(BIN): $(OBJ) $(RES) 23 | $(CPP) -shared -o $@ $^ $(LDFLAGS) 24 | 25 | clean: 26 | $(RM) *.o 27 | -------------------------------------------------------------------------------- /source/packANY/packPNM/Makefile_lib: -------------------------------------------------------------------------------- 1 | # Project: packPNM static library 2 | # Makefile created by Matthias Stirner 01/30/2012 3 | # Working with GCC 4.6.0 4 | 5 | CC = gcc 6 | CPP = g++ 7 | AR = ar 8 | RM = del 9 | CFLAGS = -I. -DBUILD_LIB -O2 -Wall -pedantic -fsched-spec-load -fomit-frame-pointer 10 | LDFLAGS = -fvisibility=hidden -static-libgcc -static-libstdc++ 11 | DEPS = aricoder.h bitops.h ppnmtbl.h ppnmbitlen.h Makefile 12 | OBJ = aricoder.o bitops.o packpnm.o 13 | BIN = packARIlib.a 14 | 15 | %.o: %.cpp $(DEPS) 16 | $(CPP) -c -o $@ $< $(CFLAGS) 17 | 18 | $(BIN): $(OBJ) 19 | ar r $(BIN) $(OBJ) 20 | ranlib $(BIN) 21 | 22 | clean: 23 | $(RM) *.o 24 | -------------------------------------------------------------------------------- /source/packANY/packPNM/app_icon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/packjpg/packARC/ed6ca67e0d6e0e20dafa7481cbecc7ff10fc00f4/source/packANY/packPNM/app_icon.ico -------------------------------------------------------------------------------- /source/packANY/packPNM/aricoder.h: -------------------------------------------------------------------------------- 1 | // defines for coder 2 | #define CODER_USE_BITS 31 // must never be above 31 3 | #define CODER_LIMIT100 ( (unsigned int) ( 1 << CODER_USE_BITS ) ) 4 | #define CODER_LIMIT025 ( ( CODER_LIMIT100 / 4 ) * 1 ) 5 | #define CODER_LIMIT050 ( ( CODER_LIMIT100 / 4 ) * 2 ) 6 | #define CODER_LIMIT075 ( ( CODER_LIMIT100 / 4 ) * 3 ) 7 | #define CODER_MAXSCALE CODER_LIMIT025 - 1 8 | #define ESCAPE_SYMBOL CODER_LIMIT025 9 | 10 | 11 | // symbol struct, used in arithmetic coding 12 | struct symbol { 13 | unsigned int low_count; 14 | unsigned int high_count; 15 | unsigned int scale; 16 | }; 17 | 18 | // table struct, used in in statistical models, 19 | // holding all info needed for one context 20 | struct table { 21 | // counts for each symbol contained in the table 22 | unsigned short* counts; 23 | // links to higher order contexts 24 | struct table** links; 25 | // link to lower order context 26 | struct table* lesser; 27 | // accumulated counts 28 | unsigned int scale; 29 | }; 30 | 31 | // special table struct, used in in model_s, 32 | // holding additional info for a speedier 'totalize_table' 33 | struct table_s { 34 | // counts for each symbol contained in the table 35 | unsigned short* counts; 36 | // links to higher order contexts 37 | struct table_s** links; 38 | // link to lower order context 39 | struct table_s* lesser; 40 | // speedup info 41 | unsigned short max_count; 42 | unsigned short max_symbol; 43 | // unsigned short esc_prob; 44 | }; 45 | 46 | 47 | /* ----------------------------------------------- 48 | class for arithmetic coding of data to/from iostream 49 | ----------------------------------------------- */ 50 | 51 | class aricoder 52 | { 53 | public: 54 | aricoder( iostream* stream, int iomode ); 55 | ~aricoder( void ); 56 | void encode( symbol* s ); 57 | unsigned int decode_count( symbol* s ); 58 | void decode( symbol* s ); 59 | 60 | private: 61 | // bitwise operations 62 | void write_bit( unsigned char bit ); 63 | unsigned char read_bit( void ); 64 | 65 | // i/o variables 66 | iostream* sptr; 67 | int mode; 68 | unsigned char bbyte; 69 | unsigned char cbit; 70 | 71 | // arithmetic coding variables 72 | unsigned int ccode; 73 | unsigned int clow; 74 | unsigned int chigh; 75 | unsigned int cstep; 76 | unsigned int nrbits; 77 | }; 78 | 79 | 80 | /* ----------------------------------------------- 81 | universal statistical model for arithmetic coding 82 | ----------------------------------------------- */ 83 | 84 | class model_s 85 | { 86 | public: 87 | 88 | model_s( int max_s, int max_c, int max_o, int c_lim ); 89 | ~model_s( void ); 90 | 91 | void update_model( int symbol ); 92 | void shift_context( int c ); 93 | void flush_model( int scale_factor ); 94 | void exclude_symbols( char rule, int c ); 95 | 96 | int convert_int_to_symbol( int c, symbol *s ); 97 | void get_symbol_scale( symbol *s ); 98 | int convert_symbol_to_int( int count, symbol *s ); 99 | 100 | bool error; 101 | 102 | 103 | private: 104 | 105 | // unsigned short* totals; 106 | unsigned int* totals; 107 | char* scoreboard; 108 | int sb0_count; 109 | table_s **contexts; 110 | table_s **storage; 111 | 112 | int max_symbol; 113 | int max_context; 114 | int current_order; 115 | int max_order; 116 | int max_count; 117 | 118 | inline void totalize_table(table_s* context ); 119 | inline void rescale_table(table_s* context, int scale_factor ); 120 | inline void recursive_flush(table_s* context, int scale_factor ); 121 | inline void recursive_cleanup(table_s* context ); 122 | }; 123 | 124 | 125 | /* ----------------------------------------------- 126 | binary statistical model for arithmetic coding 127 | ----------------------------------------------- */ 128 | 129 | class model_b 130 | { 131 | public: 132 | 133 | model_b( int max_c, int max_o, int c_lim ); 134 | ~model_b( void ); 135 | 136 | void update_model( int symbol ); 137 | void shift_context( int c ); 138 | void flush_model( int scale_factor ); 139 | 140 | int convert_int_to_symbol( int c, symbol *s ); 141 | void get_symbol_scale( symbol *s ); 142 | int convert_symbol_to_int( int count, symbol *s ); 143 | 144 | bool error; 145 | 146 | 147 | private: 148 | 149 | table **contexts; 150 | table **storage; 151 | 152 | int max_context; 153 | int max_order; 154 | int max_count; 155 | 156 | inline void check_counts( table *context ); 157 | inline void rescale_table( table* context, int scale_factor ); 158 | inline void recursive_flush( table* context, int scale_factor ); 159 | inline void recursive_cleanup( table *context ); 160 | }; 161 | 162 | 163 | /* ----------------------------------------------- 164 | shift context x2 model_s function 165 | ----------------------------------------------- */ 166 | static inline void shift_model( model_s* model, int ctx1, int ctx2 ) 167 | { 168 | model->shift_context( ctx1 ); 169 | model->shift_context( ctx2 ); 170 | } 171 | 172 | 173 | /* ----------------------------------------------- 174 | shift context x3 model_s function 175 | ----------------------------------------------- */ 176 | static inline void shift_model( model_s* model, int ctx1, int ctx2, int ctx3 ) 177 | { 178 | model->shift_context( ctx1 ); 179 | model->shift_context( ctx2 ); 180 | model->shift_context( ctx3 ); 181 | } 182 | 183 | 184 | /* ----------------------------------------------- 185 | shift context x2 model_b function 186 | ----------------------------------------------- */ 187 | static inline void shift_model( model_b* model, int ctx1, int ctx2 ) 188 | { 189 | model->shift_context( ctx1 ); 190 | model->shift_context( ctx2 ); 191 | } 192 | 193 | 194 | /* ----------------------------------------------- 195 | shift context x3 model_b function 196 | ----------------------------------------------- */ 197 | static inline void shift_model( model_b* model, int ctx1, int ctx2, int ctx3 ) 198 | { 199 | model->shift_context( ctx1 ); 200 | model->shift_context( ctx2 ); 201 | model->shift_context( ctx3 ); 202 | } 203 | 204 | 205 | /* ----------------------------------------------- 206 | generic model_s encoder function 207 | ----------------------------------------------- */ 208 | static inline void encode_ari( aricoder* encoder, model_s* model, int c ) 209 | { 210 | static symbol s; 211 | static int esc; 212 | 213 | do { 214 | esc = model->convert_int_to_symbol( c, &s ); 215 | encoder->encode( &s ); 216 | } while ( esc ); 217 | model->update_model( c ); 218 | } 219 | 220 | /* ----------------------------------------------- 221 | generic model_s decoder function 222 | ----------------------------------------------- */ 223 | static inline int decode_ari( aricoder* decoder, model_s* model ) 224 | { 225 | static symbol s; 226 | static unsigned int count; 227 | static int c; 228 | 229 | do{ 230 | model->get_symbol_scale( &s ); 231 | count = decoder->decode_count( &s ); 232 | c = model->convert_symbol_to_int( count, &s ); 233 | decoder->decode( &s ); 234 | } while ( c == ESCAPE_SYMBOL ); 235 | model->update_model( c ); 236 | 237 | return c; 238 | } 239 | 240 | /* ----------------------------------------------- 241 | generic model_b encoder function 242 | ----------------------------------------------- */ 243 | static inline void encode_ari( aricoder* encoder, model_b* model, int c ) 244 | { 245 | static symbol s; 246 | 247 | model->convert_int_to_symbol( c, &s ); 248 | encoder->encode( &s ); 249 | model->update_model( c ); 250 | } 251 | 252 | /* ----------------------------------------------- 253 | generic model_b decoder function 254 | ----------------------------------------------- */ 255 | static inline int decode_ari( aricoder* decoder, model_b* model ) 256 | { 257 | static symbol s; 258 | static unsigned int count; 259 | static int c; 260 | 261 | model->get_symbol_scale( &s ); 262 | count = decoder->decode_count( &s ); 263 | c = model->convert_symbol_to_int( count, &s ); 264 | decoder->decode( &s ); 265 | model->update_model( c ); 266 | 267 | return c; 268 | } 269 | -------------------------------------------------------------------------------- /source/packANY/packPNM/bitops.h: -------------------------------------------------------------------------------- 1 | #define RBITS( c, n ) ( c & ( 0xFF >> (8 - n) ) ) 2 | #define LBITS( c, n ) ( c >> (8 - n) ) 3 | #define MBITS( c, l, r ) ( RBITS( c,l ) >> r ) 4 | #define RBITS16( c, n ) ( c & ( 0xFFFFFFFF >> (16 - n) ) ) 5 | #define LBITS16( c, n ) ( c >> (16 - n) ) 6 | #define MBITS16( c, l, r ) ( RBITS16( c,l ) >> r ) 7 | #define RBITS32( c, n ) ( c & ( 0xFFFFFFFF >> (32 - n) ) ) 8 | #define LBITS32( c, n ) ( c >> (32 - n) ) 9 | #define MBITS32( c, l, r ) ( RBITS32( c,l ) >> r ) 10 | #define BITN( c, n ) ( (c >> n) & 0x1 ) 11 | #define BITLEN( l, v ) for ( l = 0; ( v >> l ) > 0; l++ ) 12 | #define FDIV2( v, p ) ( ( v < 0 ) ? -( (-v) >> p ) : ( v >> p ) ) 13 | 14 | #define TYPE_FILE 0 15 | #define TYPE_MEMORY 1 16 | #define TYPE_STREAM 2 17 | #define MODE_READ 0 18 | #define MODE_WRITE 1 19 | 20 | #define BTST_BUFF 1024 * 1024 21 | 22 | #include 23 | 24 | 25 | /* ----------------------------------------------- 26 | class to read arrays bitwise 27 | ----------------------------------------------- */ 28 | 29 | class abitreader 30 | { 31 | public: 32 | abitreader( unsigned char* array, int size ); 33 | ~abitreader( void ); 34 | unsigned int read( int nbits ); 35 | unsigned char read_bit( void ); 36 | unsigned char unpad( unsigned char fillbit ); 37 | int getpos( void ); 38 | int getbitp( void ); 39 | void setpos( int pbyte, int pbit ); 40 | void rewind_bits( int nbits ); 41 | bool eof; 42 | int peof; 43 | 44 | private: 45 | unsigned char* data; 46 | int lbyte; 47 | int cbyte; 48 | int cbit; 49 | }; 50 | 51 | 52 | /* ----------------------------------------------- 53 | class to write arrays bitwise 54 | ----------------------------------------------- */ 55 | 56 | class abitwriter 57 | { 58 | public: 59 | abitwriter( int size ); 60 | ~abitwriter( void ); 61 | void write( unsigned int val, int nbits ); 62 | void write_bit( unsigned char bit ); 63 | void pad ( unsigned char fillbit ); 64 | unsigned char* getptr( void ); 65 | int getpos( void ); 66 | int getbitp( void ); 67 | bool error; 68 | unsigned char fillbit; 69 | 70 | private: 71 | unsigned char* data; 72 | int dsize; 73 | int adds; 74 | int cbyte; 75 | int cbit; 76 | bool fmem; 77 | }; 78 | 79 | 80 | /* ----------------------------------------------- 81 | class to read arrays bytewise 82 | ----------------------------------------------- */ 83 | 84 | class abytereader 85 | { 86 | public: 87 | abytereader( unsigned char* array, int size ); 88 | ~abytereader( void ); 89 | int read( unsigned char* byte ); 90 | int read_n( unsigned char* byte, int n ); 91 | void seek( int pos ); 92 | int getsize( void ); 93 | int getpos( void ); 94 | bool eof; 95 | 96 | private: 97 | unsigned char* data; 98 | int lbyte; 99 | int cbyte; 100 | }; 101 | 102 | 103 | /* ----------------------------------------------- 104 | class to write arrays bytewise 105 | ----------------------------------------------- */ 106 | 107 | class abytewriter 108 | { 109 | public: 110 | abytewriter( int size ); 111 | ~abytewriter( void ); 112 | void write( unsigned char byte ); 113 | void write_n( unsigned char* byte, int n ); 114 | unsigned char* getptr( void ); 115 | unsigned char* peekptr( void ); 116 | int getpos( void ); 117 | void reset( void ); 118 | bool error; 119 | 120 | private: 121 | unsigned char* data; 122 | int dsize; 123 | int adds; 124 | int cbyte; 125 | bool fmem; 126 | }; 127 | 128 | 129 | /* ----------------------------------------------- 130 | class for input and output from file or memory 131 | ----------------------------------------------- */ 132 | 133 | class iostream 134 | { 135 | public: 136 | iostream( void* src, int srctype, int srcsize, int iomode ); 137 | ~iostream( void ); 138 | void switch_mode( void ); 139 | int read( void* to, int tpsize, int dtsize ); 140 | int write( void* from, int tpsize, int dtsize ); 141 | int flush( void ); 142 | int rewind( void ); 143 | int getpos( void ); 144 | int getsize( void ); 145 | unsigned char* getptr( void ); 146 | bool chkerr( void ); 147 | bool chkeof( void ); 148 | 149 | private: 150 | void open_file( void ); 151 | void open_mem( void ); 152 | void open_stream( void ); 153 | 154 | int write_file( void* from, int tpsize, int dtsize ); 155 | int read_file( void* to, int tpsize, int dtsize ); 156 | int write_mem( void* from, int tpsize, int dtsize ); 157 | int read_mem( void* to, int tpsize, int dtsize ); 158 | 159 | FILE* fptr; 160 | abytewriter* mwrt; 161 | abytereader* mrdr; 162 | 163 | bool free_mem_sw; 164 | void* source; 165 | int mode; 166 | int srct; 167 | int srcs; 168 | }; 169 | -------------------------------------------------------------------------------- /source/packANY/packPNM/file_icon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/packjpg/packARC/ed6ca67e0d6e0e20dafa7481cbecc7ff10fc00f4/source/packANY/packPNM/file_icon.ico -------------------------------------------------------------------------------- /source/packANY/packPNM/icons.rc: -------------------------------------------------------------------------------- 1 | app ICON app_icon.ico 2 | ICONS1 ICON file_icon.ico -------------------------------------------------------------------------------- /source/packANY/packPNM/icons.res: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/packjpg/packARC/ed6ca67e0d6e0e20dafa7481cbecc7ff10fc00f4/source/packANY/packPNM/icons.res -------------------------------------------------------------------------------- /source/packANY/packPNM/packpnmdll.h: -------------------------------------------------------------------------------- 1 | // packPNMdll.h - function import declarations for the packPNM DLL 2 | #define IMPORT __declspec( dllimport ) 3 | 4 | /* ----------------------------------------------- 5 | function declarations: library only functions 6 | ----------------------------------------------- */ 7 | 8 | IMPORT bool ppnlib_convert_stream2stream( char* msg ); 9 | IMPORT bool ppnlib_convert_file2file( char* in, char* out, char* msg ); 10 | IMPORT bool ppnlib_convert_stream2mem( unsigned char** out_file, unsigned int* out_size, char* msg ); 11 | IMPORT void ppnlib_init_streams( void* in_src, int in_type, int in_size, void* out_dest, int out_type ); 12 | IMPORT const char* ppnlib_version_info( void ); 13 | IMPORT const char* ppnlib_short_name( void ); 14 | 15 | /* a short reminder about input/output stream types 16 | for the ppnlib_init_streams() function 17 | 18 | if input is file 19 | ---------------- 20 | in_scr -> name of input file 21 | in_type -> 0 22 | in_size -> ignore 23 | 24 | if input is memory 25 | ------------------ 26 | in_scr -> array containg data 27 | in_type -> 1 28 | in_size -> size of data array 29 | 30 | if input is *FILE (f.e. stdin) 31 | ------------------------------ 32 | in_src -> stream pointer 33 | in_type -> 2 34 | in_size -> ignore 35 | 36 | vice versa for output streams! */ 37 | -------------------------------------------------------------------------------- /source/packANY/packPNM/packpnmlib.h: -------------------------------------------------------------------------------- 1 | // packPNMlib.h - function declarations for the packPNM library 2 | #if defined BUILD_DLL 3 | #define EXPORT __declspec( dllexport ) 4 | #else 5 | #define EXPORT extern 6 | #endif 7 | 8 | /* ----------------------------------------------- 9 | function declarations: library only functions 10 | ----------------------------------------------- */ 11 | 12 | EXPORT bool ppnlib_convert_stream2stream( char* msg ); 13 | EXPORT bool ppnlib_convert_file2file( char* in, char* out, char* msg ); 14 | EXPORT bool ppnlib_convert_stream2mem( unsigned char** out_file, unsigned int* out_size, char* msg ); 15 | EXPORT void ppnlib_init_streams( void* in_src, int in_type, int in_size, void* out_dest, int out_type ); 16 | EXPORT const char* ppnlib_version_info( void ); 17 | EXPORT const char* ppnlib_short_name( void ); 18 | 19 | /* a short reminder about input/output stream types 20 | for the ppnlib_init_streams() function 21 | 22 | if input is file 23 | ---------------- 24 | in_scr -> name of input file 25 | in_type -> 0 26 | in_size -> ignore 27 | 28 | if input is memory 29 | ------------------ 30 | in_scr -> array containg data 31 | in_type -> 1 32 | in_size -> size of data array 33 | 34 | if input is *FILE (f.e. stdin) 35 | ------------------------------ 36 | in_src -> stream pointer 37 | in_type -> 2 38 | in_size -> ignore 39 | 40 | vice versa for output streams! */ 41 | -------------------------------------------------------------------------------- /source/packANY/packPNM/ppnmtbl.h: -------------------------------------------------------------------------------- 1 | /* ----------------------------------------------- 2 | defines for use in packPNM processing 3 | ----------------------------------------------- */ 4 | 5 | // action defines 6 | #define A_COMPRESS 1 7 | #define A_PGM_DUMP 2 8 | #define A_NFO_DUMP 3 9 | 10 | // file type defines 11 | #define F_PNM 1 12 | #define F_PPN 2 13 | #define F_UNK 0 14 | 15 | // sub type defines 16 | #define S_PBM 1 17 | #define S_PGM 2 18 | #define S_PPM 3 19 | #define S_BMP 4 20 | #define S_HDR 5 21 | #define S_UNK 0 22 | 23 | // color model defines 24 | #define C_MONO 1 25 | #define C_GRAY 2 26 | #define C_RGBA 3 27 | #define C_RGBE 4 28 | #define C_UNK 0 29 | 30 | // endianess defines 31 | #define E_BIG 0 // false 32 | #define E_LITTLE 1 // true 33 | -------------------------------------------------------------------------------- /source/packARC/Makefile.linux: -------------------------------------------------------------------------------- 1 | # Project: packARC 2 | # Makefile created by Matthias Stirner 01/30/2012 3 | # Working with GCC 4.6.0 4 | 5 | CC = gcc 6 | CPP = g++ 7 | RM = rm 8 | CFLAGS = -I. -O3 -Wall -pedantic -funroll-loops -ffast-math -fsched-spec-load -fomit-frame-pointer 9 | LDFLAGS = -s -static-libgcc 10 | DEPS = pja_archiver.h sfxstub.h helpers.h packANYlib.h packANYlib.a 11 | OBJ = pja_archiver.o helpers.o frontend.o packANYlib.a 12 | BIN = packARC 13 | 14 | %.o: %.cpp $(DEPS) 15 | $(CPP) -c -o $@ $< $(CFLAGS) 16 | 17 | $(BIN): $(OBJ) $(RES) 18 | $(CPP) -o $@ $^ $(LDFLAGS) 19 | 20 | clean: 21 | $(RM) *.o 22 | -------------------------------------------------------------------------------- /source/packARC/Makefile.win: -------------------------------------------------------------------------------- 1 | # Project: packARC 2 | # Makefile created by Matthias Stirner 01/30/2012 3 | # Working with GCC 4.6.0 4 | 5 | CC = gcc 6 | CPP = g++ 7 | RC = windres -O coff 8 | RM = del 9 | CFLAGS = -I. -O3 -Wall -pedantic -funroll-loops -ffast-math -fsched-spec-load -fomit-frame-pointer 10 | LDFLAGS = -s -static-libgcc -static-libstdc++ 11 | DEPS = pja_archiver.h sfxstub.h helpers.h packANYlib.h packANYlib.a 12 | OBJ = pja_archiver.o helpers.o frontend.o packANYlib.a 13 | RES = icons_app.res 14 | BIN = packARC 15 | 16 | %.o: %.cpp $(DEPS) 17 | $(CPP) -c -o $@ $< $(CFLAGS) 18 | 19 | %.res: %.rc 20 | $(RC) $< $@ 21 | 22 | $(BIN): $(OBJ) $(RES) 23 | $(CPP) -o $@ $^ $(LDFLAGS) 24 | 25 | clean: 26 | $(RM) *.o 27 | -------------------------------------------------------------------------------- /source/packARC/Makefile_dm.win: -------------------------------------------------------------------------------- 1 | # Project: packARC 2 | # Makefile created by Matthias Stirner 01/30/2012 3 | # Working with GCC 4.6.0 4 | 5 | CC = gcc 6 | CPP = g++ 7 | RM = del 8 | CFLAGS = 9 | LDFLAGS = -s -static-libgcc 10 | DEPS = pja_archiver.h sfxstub.h helpers.h packANYlib.h packANYlib.a 11 | OBJ = pja_archiver.o helpers.o frontend.o packANYlib.a 12 | BIN = packARCdm 13 | 14 | %.o: %.cpp $(DEPS) 15 | $(CPP) -c -ggdb -o $@ $< $(CFLAGS) 16 | 17 | $(BIN): $(OBJ) $(RES) 18 | $(CPP) -o $@ $^ $(LDFLAGS) 19 | 20 | clean: 21 | $(RM) *.o 22 | -------------------------------------------------------------------------------- /source/packARC/Makefile_sfx_stub.linux: -------------------------------------------------------------------------------- 1 | # Project: packARC SFX stub 2 | # Makefile created by Matthias Stirner 01/30/2012 3 | # Working with GCC 4.6.0 4 | 5 | CC = gcc 6 | CPP = g++ 7 | RM = rm 8 | CFLAGS = -Os -DSFX_STUB -Wall -pedantic -ffast-math -fsched-spec-load -fomit-frame-pointer 9 | LDFLAGS = -s -static-libgcc 10 | DEPS = pja_archiver.h helpers.h packANYlib.h packANYlib_small.a 11 | OBJ = pja_archiver.o helpers.o frontend.o packANYlib_small.a 12 | BIN = sfxstub 13 | 14 | %.o: %.cpp $(DEPS) 15 | $(CPP) -c -o $@ $< $(CFLAGS) 16 | 17 | $(BIN): $(OBJ) $(RES) 18 | $(CPP) -o $@ $^ $(LDFLAGS) 19 | 20 | clean: 21 | $(RM) *.o 22 | -------------------------------------------------------------------------------- /source/packARC/Makefile_sfx_stub.win: -------------------------------------------------------------------------------- 1 | # Project: packARC SFX stub 2 | # Makefile created by Matthias Stirner 01/30/2012 3 | # Working with GCC 4.6.0 4 | 5 | CC = gcc 6 | CPP = g++ 7 | RC = windres -O coff 8 | RM = del 9 | CFLAGS = -Os -DSFX_STUB -Wall -pedantic -ffast-math -fsched-spec-load -fomit-frame-pointer 10 | LDFLAGS = -s -static-libgcc -static-libstdc++ 11 | DEPS = pja_archiver.h helpers.h packANYlib.h packANYlib_small.a 12 | OBJ = pja_archiver.o helpers.o frontend.o packANYlib_small.a 13 | RES = icons_sfx.res 14 | BIN = sfxstub 15 | 16 | %.o: %.cpp $(DEPS) 17 | $(CPP) -c -o $@ $< $(CFLAGS) 18 | 19 | %.res: %.rc 20 | $(RC) $< $@ 21 | 22 | $(BIN): $(OBJ) $(RES) 23 | $(CPP) -o $@ $^ $(LDFLAGS) 24 | 25 | clean: 26 | $(RM) *.o 27 | 28 | -------------------------------------------------------------------------------- /source/packARC/Makefile_sfx_stub_dm.win: -------------------------------------------------------------------------------- 1 | # Project: packARC SFX stub 2 | # Makefile created by Matthias Stirner 01/30/2012 3 | # Working with GCC 4.6.0 4 | 5 | CC = gcc 6 | CPP = g++ 7 | RM = del 8 | CFLAGS = -DSFX_STUB 9 | LDFLAGS = -s -static-libgcc 10 | DEPS = pja_archiver.h helpers.h packANYlib.h packANYlib.a 11 | OBJ = pja_archiver.o helpers.o frontend.o packANYlib.a 12 | BIN = sfxstub 13 | 14 | %.o: %.cpp $(DEPS) 15 | $(CPP) -c -ggdb -o $@ $< $(CFLAGS) 16 | 17 | $(BIN): $(OBJ) $(RES) 18 | $(CPP) -o $@ $^ $(LDFLAGS) 19 | 20 | clean: 21 | $(RM) *.o 22 | -------------------------------------------------------------------------------- /source/packARC/alt_ico/app_icon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/packjpg/packARC/ed6ca67e0d6e0e20dafa7481cbecc7ff10fc00f4/source/packARC/alt_ico/app_icon.ico -------------------------------------------------------------------------------- /source/packARC/alt_ico/app_icon_alt.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/packjpg/packARC/ed6ca67e0d6e0e20dafa7481cbecc7ff10fc00f4/source/packARC/alt_ico/app_icon_alt.ico -------------------------------------------------------------------------------- /source/packARC/alt_ico/app_icon_blue.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/packjpg/packARC/ed6ca67e0d6e0e20dafa7481cbecc7ff10fc00f4/source/packARC/alt_ico/app_icon_blue.ico -------------------------------------------------------------------------------- /source/packARC/alt_ico/app_icon_gray.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/packjpg/packARC/ed6ca67e0d6e0e20dafa7481cbecc7ff10fc00f4/source/packARC/alt_ico/app_icon_gray.ico -------------------------------------------------------------------------------- /source/packARC/alt_ico/app_icon_green.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/packjpg/packARC/ed6ca67e0d6e0e20dafa7481cbecc7ff10fc00f4/source/packARC/alt_ico/app_icon_green.ico -------------------------------------------------------------------------------- /source/packARC/alt_ico/app_icon_red.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/packjpg/packARC/ed6ca67e0d6e0e20dafa7481cbecc7ff10fc00f4/source/packARC/alt_ico/app_icon_red.ico -------------------------------------------------------------------------------- /source/packARC/alt_ico/file_icon_blue.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/packjpg/packARC/ed6ca67e0d6e0e20dafa7481cbecc7ff10fc00f4/source/packARC/alt_ico/file_icon_blue.ico -------------------------------------------------------------------------------- /source/packARC/alt_ico/file_icon_gray.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/packjpg/packARC/ed6ca67e0d6e0e20dafa7481cbecc7ff10fc00f4/source/packARC/alt_ico/file_icon_gray.ico -------------------------------------------------------------------------------- /source/packARC/alt_ico/file_icon_green.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/packjpg/packARC/ed6ca67e0d6e0e20dafa7481cbecc7ff10fc00f4/source/packARC/alt_ico/file_icon_green.ico -------------------------------------------------------------------------------- /source/packARC/alt_ico/file_icon_red.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/packjpg/packARC/ed6ca67e0d6e0e20dafa7481cbecc7ff10fc00f4/source/packARC/alt_ico/file_icon_red.ico -------------------------------------------------------------------------------- /source/packARC/alt_ico/icons_app.rc: -------------------------------------------------------------------------------- 1 | app ICON app_icon.ico 2 | ICONS1 ICON app_icon_alt.ico 3 | ICONS2 ICON app_icon_red.ico 4 | ICONS3 ICON app_icon_green.ico 5 | ICONS4 ICON app_icon_gray.ico 6 | ICONS5 ICON app_icon_blue.ico 7 | ICONS6 ICON file_icon_red.ico 8 | ICONS7 ICON file_icon_green.ico 9 | ICONS8 ICON file_icon_gray.ico 10 | ICONS9 ICON file_icon_blue.ico 11 | ICONS10 ICON sfx_icon_red.ico 12 | ICONS11 ICON sfx_icon_green.ico 13 | ICONS12 ICON sfx_icon_gray.ico 14 | ICONS13 ICON sfx_icon_blue.ico -------------------------------------------------------------------------------- /source/packARC/alt_ico/icons_app.res: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/packjpg/packARC/ed6ca67e0d6e0e20dafa7481cbecc7ff10fc00f4/source/packARC/alt_ico/icons_app.res -------------------------------------------------------------------------------- /source/packARC/alt_ico/png.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/packjpg/packARC/ed6ca67e0d6e0e20dafa7481cbecc7ff10fc00f4/source/packARC/alt_ico/png.zip -------------------------------------------------------------------------------- /source/packARC/alt_ico/sfx_icon_blue.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/packjpg/packARC/ed6ca67e0d6e0e20dafa7481cbecc7ff10fc00f4/source/packARC/alt_ico/sfx_icon_blue.ico -------------------------------------------------------------------------------- /source/packARC/alt_ico/sfx_icon_gray.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/packjpg/packARC/ed6ca67e0d6e0e20dafa7481cbecc7ff10fc00f4/source/packARC/alt_ico/sfx_icon_gray.ico -------------------------------------------------------------------------------- /source/packARC/alt_ico/sfx_icon_green.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/packjpg/packARC/ed6ca67e0d6e0e20dafa7481cbecc7ff10fc00f4/source/packARC/alt_ico/sfx_icon_green.ico -------------------------------------------------------------------------------- /source/packARC/alt_ico/sfx_icon_red.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/packjpg/packARC/ed6ca67e0d6e0e20dafa7481cbecc7ff10fc00f4/source/packARC/alt_ico/sfx_icon_red.ico -------------------------------------------------------------------------------- /source/packARC/app_icon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/packjpg/packARC/ed6ca67e0d6e0e20dafa7481cbecc7ff10fc00f4/source/packARC/app_icon.ico -------------------------------------------------------------------------------- /source/packARC/file_icon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/packjpg/packARC/ed6ca67e0d6e0e20dafa7481cbecc7ff10fc00f4/source/packARC/file_icon.ico -------------------------------------------------------------------------------- /source/packARC/frontend.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | // #define SFX_STUB 6 | #include "pja_archiver.h" 7 | #include "helpers.h" 8 | 9 | #define OUTPUT_ENGINE_INFO 10 | 11 | #define BARLEN 36 12 | #define MSGOUT stderr 13 | 14 | // application info variables 15 | const unsigned char appversion = 7; // should be same as packARC library version 16 | static const char* subversion = "beta18"; 17 | #if !defined(SFX_STUB) 18 | static const char* apptitle = "packARC Frontend"; 19 | static const char* appname = "packARC"; 20 | #else 21 | static const char* apptitle = "packARC SFX Extractor"; 22 | //static const char* appname = "pjxstub"; 23 | #endif 24 | static const char* versiondate = "12/17/2014"; 25 | static const char* author = "Matthias Stirner / Se"; 26 | static const char* website = "http://www.elektronik.htw-aalen.de/packjpg/"; 27 | static const char* copyright = "2006-2014 HTW Aalen University & Matthias Stirner"; 28 | static const char* email = "packjpg (at) htw-aalen.de"; 29 | 30 | void process_files( char command, char* archive, int num_files, char** files ); 31 | void file_listing( void ); 32 | inline void progress_bar( int current, int last ); 33 | void show_help_exit( char* my_name ); 34 | 35 | int list_format = 0; 36 | #if !defined(SFX_STUB) 37 | bool make_sfx = false; 38 | #endif 39 | bool pause_f = true; 40 | 41 | /* ----------------------------------------------- 42 | main-function 43 | ----------------------------------------------- */ 44 | int main( int argc, char** argv ) 45 | { 46 | char command = '\0'; 47 | char* my_name = NULL; 48 | char* archive = NULL; 49 | int num_files = 0; 50 | char** filelist = NULL; 51 | 52 | // write program info to screen 53 | fprintf( MSGOUT, "\n--> %s v%i.%i%s (%s) by %s <--\n", 54 | apptitle, appversion / 10, appversion % 10, subversion, versiondate, author ); 55 | 56 | #if defined( OUTPUT_ENGINE_INFO ) 57 | // also output archiver library info 58 | fprintf( MSGOUT, "%s\n", pja_get_version_info() ); 59 | // ... and external libraries info 60 | fprintf( MSGOUT, "%s\n", pja_get_engine_info() ); 61 | #endif 62 | 63 | // copyright notice 64 | fprintf( MSGOUT, "Copyright %s\nAll rights reserved\n\n", copyright ); 65 | 66 | #if !defined(SFX_STUB) 67 | // name of this application (for help) 68 | my_name = clone_string( (char*) appname ); 69 | #else 70 | // name of this application (for help), archive 71 | my_name = create_filename( get_filename( (*argv) ), NULL ); 72 | archive = ( file_exists( (*argv) ) ) ? clone_string( (*argv) ) : 73 | create_filename( (*argv), PJA_SFX_EXT ); 74 | if ( !file_exists( archive ) ) { // safety check 75 | fprintf( MSGOUT, "incorrect usage of SFX executable!" ); 76 | return 0; 77 | } 78 | #endif 79 | 80 | // check number of parameters 81 | argc--; argv++; 82 | #if !defined(SFX_STUB) 83 | if ( argc == 0 ) show_help_exit( my_name ); 84 | /*else if ( argc == 1 ) { 85 | // special case: (frontend) 86 | // if only one parameter is given, we assume the parameter 87 | // to be the archives filename and the command to be 'l' 88 | command = 'l'; 89 | archive = argv[ 1 ]; 90 | }*/ 91 | else if ( ( strlen( (*argv) ) > 1 ) && 92 | ( ( file_exists( (*argv) ) ) || ( path_exists( (*argv) ) ) ) ) { 93 | // special case: (frontend) 94 | // if the first parameter is an existing file or path and is 95 | // longer than 1 char use drag and drop handling 96 | if ( argc == 1 ) { 97 | // if there is only one file, check if it is a proper 98 | // archive - use command 'x' if it is. 99 | if ( pja_open_archive( (*argv) ) ) { 100 | pja_close_archive(); 101 | command = 'x'; 102 | archive = (*argv); 103 | argc--; argv++; 104 | // set workpath (easier than properly giving absolute paths) 105 | set_containing_path( archive ); 106 | } 107 | } 108 | if ( argc > 0 ) { 109 | // if there is (still) more than one file, or the first file 110 | // is not a proper archive, create a new SFX archive 111 | command = 'a'; 112 | make_sfx = true; 113 | archive = unique_filename( (*argv), PJA_SFX_EXT ); 114 | // rest of parameters = filelist 115 | num_files = argc; 116 | filelist = argv; 117 | } 118 | } 119 | #else 120 | if ( argc == 0 ) { 121 | // special case: (sfx extractor) 122 | // if no parameter is given, we assume the command to be 'x' 123 | command = 'x'; 124 | } 125 | #endif 126 | else { // otherwise parse the command line 127 | // check first parameter (must be command) 128 | if ( strlen( (*argv) ) == 1 ) 129 | command = (*argv)[ 0 ]; 130 | else show_help_exit( my_name ); 131 | if ( // check for valid command 132 | #if !defined(SFX_STUB) 133 | ( command != 'a' ) && 134 | ( command != 'd' ) && 135 | ( command != 'c' ) && 136 | #endif 137 | ( command != 'x' ) && 138 | ( command != 't' ) && 139 | ( command != 'l' ) ) 140 | show_help_exit( my_name ); 141 | 142 | // check next parameters (switches) 143 | while ( --argc > 0 ) { 144 | argv++; 145 | if ( strcmp( (*argv), "--" ) == 0 ) 146 | break; 147 | else if ( strcmp( (*argv), "-i" ) == 0 ) 148 | pja_set_check_extracted_crc( false ); 149 | else if ( strcmp( (*argv), "-o" ) == 0 ) 150 | pja_set_existing_files_handling( 'o' ); 151 | else if ( strcmp( (*argv), "-s" ) == 0 ) 152 | pja_set_existing_files_handling( 's' ); 153 | else if ( strcmp( (*argv), "-r" ) == 0 ) 154 | pja_set_existing_files_handling( 'r' ); 155 | #if !defined(SFX_STUB) 156 | else if ( strcmp( (*argv), "-sfx" ) == 0 ) 157 | make_sfx = true; 158 | #endif 159 | else if ( strcmp( (*argv), "-sl" ) == 0 ) 160 | list_format = 1; 161 | else if ( strcmp( (*argv), "-csv" ) == 0 ) 162 | list_format = 2; 163 | else if ( strcmp( (*argv), "-sm" ) == 0 ) 164 | list_format = 3; 165 | else if ( strcmp( (*argv), "-np" ) == 0 ) 166 | pause_f = false; 167 | else break; 168 | } 169 | 170 | #if !defined(SFX_STUB) 171 | // check next parameter (must be name of archive for frontend) 172 | if ( argc == 0 ) show_help_exit( my_name ); 173 | archive = (*argv++); argc--; 174 | #endif 175 | 176 | // rest of parameters = filelist 177 | num_files = argc; 178 | filelist = argv; 179 | } 180 | 181 | // process command and filelist 182 | process_files( command, archive, num_files, filelist ); 183 | 184 | // pause before exit 185 | if ( pause_f ) { 186 | fprintf( MSGOUT, "\n\n< press ENTER >\n" ); 187 | fgetc( stdin ); 188 | } 189 | 190 | 191 | return 0; 192 | } 193 | 194 | /* ----------------------------------------------- 195 | process a list of files 196 | ----------------------------------------------- */ 197 | void process_files( char command, char* archive, int num_files, char** files ) { 198 | pja_archive_info* archive_info; 199 | char** file_status; 200 | bool process_all = false; 201 | int error_count = 0; 202 | int i; 203 | 204 | // open archive... 205 | if ( !pja_open_archive( archive ) ) { 206 | fprintf( MSGOUT, "could not open archive \"%s\" (%s)!\n\n", archive, pja_get_current_status() ); 207 | return; 208 | } 209 | 210 | // get pointer to archive info struct 211 | archive_info = pja_get_archive_info(); 212 | 213 | // handle num_files == 0 (in parameters) 214 | if ( num_files == 0 ) { 215 | if( ( command == 'x' ) || ( command == 't' ) ) { 216 | // testing or extracting with an empty filelist actually 217 | // means test/extract all files 218 | process_all = true; 219 | num_files = archive_info->num_files; 220 | files = ( char** ) calloc( num_files, sizeof( char* ) ); 221 | for ( i = 0; i < num_files; i++ ) 222 | files[ i ] = clone_string( archive_info->filelist[ i ]->filename ); 223 | } 224 | #if !defined(SFX_STUB) 225 | else if ( ( command == 'a' ) || ( command == 'd' ) ) { 226 | fprintf( MSGOUT, "nothing to do!\n\n" ); 227 | pja_close_archive(); 228 | return; 229 | } 230 | #endif 231 | } 232 | else { 233 | // for commands 'c' and 'l', num_files has to be 0 234 | // but we won't check this for now :-) 235 | } 236 | 237 | // handle num_file == 0 (in archive) 238 | if ( ( archive_info->num_files == 0 ) && ( command != 'a' ) ) { 239 | fprintf( MSGOUT, "archive \"%s\" does not exist!\n\n", archive_info->filename ); 240 | return; 241 | } 242 | 243 | // alloc memory for file status, preset with NULL 244 | file_status = ( char** ) calloc( num_files, sizeof( char* ) ); 245 | for ( i = 0; i < num_files; i++ ) 246 | file_status[ i ] = NULL; 247 | 248 | // main processing 249 | switch ( command ) 250 | { 251 | #if !defined(SFX_STUB) 252 | case 'a': 253 | char* common_path; 254 | int cp_len; 255 | if ( make_sfx ) { 256 | if ( !pja_convert_archive() ) { 257 | fprintf( MSGOUT, "error writing SFX stub to archive \"%s\"!\n", archive_info->filename ); 258 | break; 259 | } 260 | fprintf( MSGOUT, "adding files to SFX archive \"%s\"...\n", archive_info->filename ); 261 | } 262 | else { 263 | fprintf( MSGOUT, "adding files to PJA archive \"%s\"...\n", archive_info->filename ); 264 | } 265 | // expand filelist, get common path 266 | common_path = get_common_path( files, num_files ); 267 | cp_len = strlen( common_path ); 268 | files = expand_filelist( files, num_files ); 269 | // recalculate # of files, realloc file_status array 270 | for ( num_files = 0; files[ num_files ] != NULL; num_files++ ); 271 | file_status = ( char** ) realloc( file_status, num_files * sizeof( char* ) ); 272 | for ( i = 0; i < num_files; i++ ) file_status[ i ] = NULL; 273 | // process files 274 | for ( i = 0; i < num_files; i++ ) { 275 | // update progress message 276 | fprintf( MSGOUT, "processing file %2i of %2i ", i + 1, num_files ); 277 | progress_bar( i, num_files ); 278 | fprintf( MSGOUT, "\r" ); 279 | // add file to archive, store message if error 280 | if ( !pja_add_file_to_archive( files[ i ] + cp_len, files[ i ] ) ) { 281 | file_status[ i ] = clone_string( pja_get_current_status() ); 282 | error_count++; 283 | } 284 | } 285 | // update progress message one last time 286 | fprintf( MSGOUT, "processed %2i of %2i files ", num_files, num_files ); 287 | progress_bar( 1, 1 ); 288 | fprintf( MSGOUT, "\n" ); 289 | // close archive 290 | if ( !pja_close_archive() ) { 291 | fprintf( MSGOUT, "-> ERROR updating archive (%s)\n", pja_get_current_status() ); 292 | return; 293 | } 294 | else { 295 | // display summary 296 | #if !defined(CLASSIC_MODE) 297 | fprintf( MSGOUT, "-> added %i of %i files to the archive\n", num_files - error_count, num_files ); 298 | #else 299 | fprintf( MSGOUT, "-> compressed %i of %i files to the archive\n", num_files - error_count, num_files ); 300 | #endif 301 | } 302 | break; 303 | 304 | case 'd': 305 | fprintf( MSGOUT, "deleting files from PJA archive \"%s\"...\n", archive_info->filename ); 306 | for ( i = 0; i < num_files; i++ ) { 307 | // update progress message 308 | fprintf( MSGOUT, "processing file %2i of %2i ", i + 1, num_files ); 309 | progress_bar( i, num_files ); 310 | fprintf( MSGOUT, "\r" ); 311 | // add file to archive, store message if error 312 | if ( !pja_remove_file_from_archive( files[ i ] ) ) { 313 | file_status[ i ] = clone_string( pja_get_current_status() ); 314 | error_count++; 315 | } 316 | } 317 | // update progress message one last time 318 | fprintf( MSGOUT, "processed %2i of %2i files ", num_files, num_files ); 319 | progress_bar( 1, 1 ); 320 | fprintf( MSGOUT, "\n" ); 321 | // close archive 322 | if ( !pja_close_archive() ) { 323 | fprintf( MSGOUT, "-> ERROR updating archive! (%s)\n", pja_get_current_status() ); 324 | return; 325 | } 326 | else // display summary 327 | fprintf( MSGOUT, "-> deleted %i of %i files from the archive\n", num_files - error_count, num_files ); 328 | break; 329 | 330 | case 'c': 331 | fprintf( MSGOUT, "converting %s archive \"%s\" to %s...\n", 332 | ( archive_info->archive_type == 0 ) ? "PJA" : "SFX", 333 | archive_info->filename, 334 | ( archive_info->archive_type == 0 ) ? "SFX" : "PJA" ); 335 | while ( true ) { 336 | fprintf( MSGOUT, "converting archive " ); 337 | progress_bar( 0, 2 ); 338 | fprintf( MSGOUT, "\r" ); 339 | if ( !pja_convert_archive() ) { 340 | error_count = 1; break; 341 | } 342 | fprintf( MSGOUT, "updating archive " ); 343 | progress_bar( 1, 2 ); 344 | fprintf( MSGOUT, "\r" ); 345 | if ( !pja_close_archive() ) { 346 | error_count = 1; break; 347 | } 348 | fprintf( MSGOUT, "converted archive " ); 349 | progress_bar( 2, 2 ); 350 | fprintf( MSGOUT, "\n" ); 351 | break; 352 | } 353 | // display summary 354 | if ( error_count > 0 ) { 355 | fprintf( MSGOUT, "-> ERROR updating archive! (%s)\n", pja_get_current_status() ); 356 | return; 357 | } 358 | else fprintf( MSGOUT, "-> archive successfully converted\n" ); 359 | break; 360 | #endif 361 | 362 | case 'x': 363 | fprintf( MSGOUT, "extracting files from PJA archive \"%s\"...\n", archive_info->filename ); 364 | for ( i = 0; i < num_files; i++ ) { 365 | // update progress message 366 | fprintf( MSGOUT, "processing file %2i of %2i ", i + 1, num_files ); 367 | progress_bar( i, num_files ); 368 | fprintf( MSGOUT, "\r" ); 369 | // add file to archive, store message if error 370 | if ( !pja_extract_file_from_archive( files[ i ], files[ i ] ) ) { 371 | file_status[ i ] = clone_string( pja_get_current_status() ); 372 | error_count++; 373 | } 374 | } 375 | // update progress message one last time 376 | fprintf( MSGOUT, "processed %2i of %2i files ", num_files, num_files ); 377 | progress_bar( 1, 1 ); 378 | fprintf( MSGOUT, "\n" ); 379 | // close archive 380 | pja_close_archive(); 381 | // display summary 382 | if ( ( process_all ) && ( error_count == 0 ) ) 383 | fprintf( MSGOUT, "-> extracted all %i files from the archive\n", num_files ); 384 | else fprintf( MSGOUT, "-> extracted %i of %i files from the archive\n", num_files - error_count, num_files ); 385 | break; 386 | 387 | case 't': 388 | fprintf( MSGOUT, "verifiying files in PJA archive \"%s\"...\n", archive_info->filename ); 389 | for ( i = 0; i < num_files; i++ ) { 390 | // update progress message 391 | fprintf( MSGOUT, "processing file %2i of %2i ", i + 1, num_files ); 392 | progress_bar( i, num_files ); 393 | fprintf( MSGOUT, "\r" ); 394 | // add file to archive, store message if error 395 | if ( !pja_test_file_in_archive( files[ i ] ) ) { 396 | file_status[ i ] = clone_string( pja_get_current_status() ); 397 | error_count++; 398 | } 399 | } 400 | // update progress message one last time 401 | fprintf( MSGOUT, "processed %2i of %2i files ", num_files, num_files ); 402 | progress_bar( 1, 1 ); 403 | fprintf( MSGOUT, "\n" ); 404 | // close archive 405 | pja_close_archive(); 406 | // display summary 407 | if ( ( process_all ) && ( error_count == 0 ) ) 408 | fprintf( MSGOUT, "-> verified all %i files from the archive\n", num_files ); 409 | else fprintf( MSGOUT, "-> verified %i of %i files from the archive\n", num_files - error_count, num_files ); 410 | break; 411 | 412 | case 'l': 413 | // file listing, handled in the file_listing() function 414 | file_listing(); 415 | pja_close_archive(); 416 | return; 417 | 418 | default: 419 | fprintf( MSGOUT, "unknown command: '%c', application ERROR!\n", command ); 420 | pja_close_archive(); 421 | return ; 422 | } 423 | 424 | // list errors if any, otherwise we're done 425 | if ( error_count > 0 ) { 426 | fprintf( MSGOUT, "\n\n" ); 427 | fprintf( MSGOUT, "following files were not processed:\n" ); 428 | fprintf( MSGOUT, "-----------------------------------\n" ); 429 | for ( i = 0; i < num_files; i++ ) { 430 | if ( file_status[ i ] != NULL ) 431 | fprintf( MSGOUT, "%s (%s)\n", files[ i ], file_status[ i ] ); 432 | } 433 | } 434 | 435 | return; 436 | } 437 | 438 | /* ----------------------------------------------- 439 | output filelisting 440 | ----------------------------------------------- */ 441 | void file_listing( void ) { 442 | pja_archive_info* archive_info = pja_get_archive_info(); 443 | pja_file_info** filelist = archive_info->filelist; 444 | tm* time_info; 445 | char time_string[ 16 + 1 ]; 446 | int i; 447 | 448 | switch ( list_format ) { 449 | case 0: // verbose (standard) list format 450 | time_info = localtime( &(archive_info->last_changed) ); 451 | strftime( time_string, 16, "%d/%m/%y %H:%M", time_info ); 452 | fprintf( MSGOUT, "%s v%i.%i ARCHIVE \"%s\" (LAST CHANGED %s)\n", // archive info (title) 453 | ( archive_info->archive_type == 0 ) ? "PJA" : "SFX", 454 | archive_info->archive_version / 10, 455 | archive_info->archive_version % 10, 456 | archive_info->filename, 457 | time_string ); 458 | fprintf( MSGOUT, "-----------------------------------------------------------------------------\n" ); 459 | // collumn descriptions 460 | fprintf( MSGOUT, "%-24s %-15s %-4s %-8s %7s %7s %6s\n", 461 | "FILENAME", "LAST_CHANGED", "TYP", "CRC32", "SIZE(O)", "SIZE(C)", "RATIO" ); 462 | // process files one by one 463 | for ( i = 0; i < archive_info->num_files; i++ ) { 464 | time_info = localtime( &(filelist[i]->last_changed) ); 465 | strftime( time_string, 16, "%d/%m/%y %H:%M", time_info ); 466 | fprintf( MSGOUT, "%-24.24s %-15s %-4s %08X %7ld %7ld %6.2f\n", 467 | filelist[i]->filename, 468 | time_string, 469 | filelist[i]->compression_method, 470 | filelist[i]->file_crc, 471 | (long int) ( ( filelist[i]->file_size_original + 1023 ) / 1024 ), 472 | (long int) ( ( filelist[i]->file_size_compressed + 1023 ) / 1024 ), 473 | filelist[i]->compression_ratio * 100 ); 474 | } 475 | // archive info (footer) 476 | fprintf( MSGOUT, "-----------------------------------------------------------------------------\n" ); 477 | fprintf( MSGOUT, "TOTAL %i FILES, %ldkb COMPRESSED TO %ldkb (%.2f%%)\n", 478 | archive_info->num_files, 479 | (long int) (archive_info->file_size_extracted / 1024), 480 | (long int) (archive_info->file_size_archive / 1024), 481 | archive_info->compression_ratio * 100 ); 482 | break; 483 | 484 | case 1: // simple list format 485 | fprintf( MSGOUT, "<%s v%i.%i ARCHIVE \"%s\">\n", 486 | ( archive_info->archive_type == 0 ) ? "PJA" : "SFX", 487 | archive_info->archive_version / 10, 488 | archive_info->archive_version % 10, 489 | archive_info->filename ); 490 | for ( i = 0; i < archive_info->num_files; i++ ) 491 | fprintf( MSGOUT, "%s\n", filelist[i]->filename ); 492 | break; 493 | 494 | case 2: // csv list format 495 | time_info = localtime( &(archive_info->last_changed) ); 496 | strftime( time_string, 16, "%d/%m/%y %H:%M", time_info ); 497 | fprintf( MSGOUT, "%s v%i.%i ARCHIVE \"%s\" (LAST CHANGED %s)\n", // archive info (title) 498 | ( archive_info->archive_type == 0 ) ? "PJA" : "SFX", 499 | archive_info->archive_version / 10, 500 | archive_info->archive_version % 10, 501 | archive_info->filename, 502 | time_string ); 503 | // column titles 504 | fprintf( MSGOUT, "%s;%s;%s;%s;%s;%s;%s\n", 505 | "file name", 506 | "last changed", 507 | "compression method", 508 | "crc32", 509 | "original size", 510 | "compressed size", 511 | "compression ratio" ); 512 | // process files one by one 513 | for ( i = 0; i < archive_info->num_files; i++ ) { 514 | time_info = localtime( &(filelist[i]->last_changed) ); 515 | strftime( time_string, 16, "%d/%m/%y %H:%M", time_info ); 516 | fprintf( MSGOUT, "%s;%s;%s;%08X;%ld;%ld;%.2f%%\n", 517 | filelist[i]->filename, 518 | time_string, 519 | filelist[i]->compression_method, 520 | filelist[i]->file_crc, 521 | (long int) filelist[i]->file_size_original, 522 | (long int) filelist[i]->file_size_compressed, 523 | filelist[i]->compression_ratio * 100 ); 524 | } 525 | break; 526 | 527 | case 3: // multiarc friendly list format 528 | fprintf( MSGOUT, "[%s v%i.%i ARCHIVE \"%s\"]\n", 529 | ( archive_info->archive_type == 0 ) ? "PJA" : "SFX", 530 | archive_info->archive_version / 10, 531 | archive_info->archive_version % 10, 532 | archive_info->filename ); 533 | // process files one by one 534 | for ( i = 0; i < archive_info->num_files; i++ ) { 535 | time_info = localtime( &(filelist[i]->last_changed) ); 536 | strftime( time_string, 24, "%d-%m-%y %H:%M:%S", time_info ); 537 | fprintf( MSGOUT, "%s\n %s %14ld\n", 538 | filelist[i]->filename, 539 | time_string, 540 | (long int) filelist[i]->file_size_original ); 541 | } 542 | break; 543 | } 544 | } 545 | 546 | /* ----------------------------------------------- 547 | displays progress bar on screen 548 | ----------------------------------------------- */ 549 | inline void progress_bar( int current, int last ) 550 | { 551 | int barpos = ( ( current * BARLEN ) + ( last / 2 ) ) / last; 552 | int i; 553 | 554 | 555 | // generate progress bar 556 | fprintf( MSGOUT, "[" ); 557 | #if defined(_WIN32) 558 | for ( i = 0; i < barpos; i++ ) 559 | fprintf( MSGOUT, "\xFE" ); 560 | #else 561 | for ( i = 0; i < barpos; i++ ) 562 | fprintf( MSGOUT, "X" ); 563 | #endif 564 | for ( ; i < BARLEN; i++ ) 565 | fprintf( MSGOUT, " " ); 566 | fprintf( MSGOUT, "]" ); 567 | } 568 | 569 | /* ----------------------------------------------- 570 | show usage instructions and exit 571 | ----------------------------------------------- */ 572 | void show_help_exit( char* my_name ) { 573 | fprintf( MSGOUT, "Website: %s\n", website ); 574 | fprintf( MSGOUT, "Email : %s\n", email ); 575 | fprintf( MSGOUT, "\n\n" ); 576 | #if !defined(SFX_STUB) 577 | fprintf( MSGOUT, "usage: %s [command] [switches] [name of archive] [files to process]\n", my_name ); 578 | #else 579 | fprintf( MSGOUT, "usage: %s [command] [switches] [files to process]\n", my_name ); 580 | #endif 581 | fprintf( MSGOUT, "\n" ); 582 | fprintf( MSGOUT, "commands:\n" ); 583 | #if !defined(SFX_STUB) 584 | fprintf( MSGOUT, " a add/replace files\n" ); 585 | fprintf( MSGOUT, " d delete files from archive\n" ); 586 | fprintf( MSGOUT, " c convert archive to/from SFX\n" ); 587 | #endif 588 | fprintf( MSGOUT, " x extract files from archive\n" ); 589 | fprintf( MSGOUT, " t test archive integrity\n" ); 590 | fprintf( MSGOUT, " l list files in archive\n" ); 591 | fprintf( MSGOUT, "switches:\n" ); 592 | fprintf( MSGOUT, " -- stop processing switches\n" ); 593 | fprintf( MSGOUT, " -o overwrite existing files\n" ); 594 | fprintf( MSGOUT, " -s skip existing files (default)\n" ); 595 | fprintf( MSGOUT, " -r rename on existing files\n" ); 596 | fprintf( MSGOUT, " -i (with x) ignore crc errors\n" ); 597 | #if !defined(SFX_STUB) 598 | fprintf( MSGOUT, " -sfx (with a) create sfx archive\n" ); 599 | #endif 600 | fprintf( MSGOUT, " -sl (with l) simple list format\n" ); 601 | fprintf( MSGOUT, " -sm (with l) MultiArc list format\n" ); 602 | fprintf( MSGOUT, " -csv (with l) CSV list format\n" ); 603 | fprintf( MSGOUT, " -np no pause after after processing\n" ); 604 | fprintf( MSGOUT, "\n" ); 605 | #if !defined(SFX_STUB) 606 | fprintf( MSGOUT, "examples: %s a archive.%s *.jpg\n", my_name, PJA_ARC_EXT ); 607 | fprintf( MSGOUT, " %s x -o archive.%s lena.jpg\n", my_name, PJA_ARC_EXT ); 608 | fprintf( MSGOUT, " %s x -i archive.%s\n", my_name, PJA_SFX_EXT ); 609 | #else 610 | fprintf( MSGOUT, "examples: %s x lena.jpg\n", my_name ); 611 | fprintf( MSGOUT, " %s l\n", my_name ); 612 | #endif 613 | exit( 1 ); 614 | } 615 | -------------------------------------------------------------------------------- /source/packARC/helpers.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include "helpers.h" 7 | 8 | #if defined(_WIN32) // define manually if mkdir is not found 9 | #include 10 | #define MKDIR( dir ) mkdir( dir ) 11 | #else 12 | #include 13 | #include 14 | #define MKDIR( dir ) mkdir( dir, 0711 ) 15 | #endif 16 | 17 | #define DIR_SEPERATOR '/' // should be '/' 18 | #define PATH_BUFFER 128 // must be >= 1 ! 19 | 20 | 21 | /* ----------------------------------------------- 22 | clones a string 23 | ----------------------------------------------- */ 24 | char* clone_string( char* string ) { 25 | int len = strlen( string ) + 1; 26 | char* string_copy = (char*) calloc( len, sizeof( char ) ); 27 | 28 | // copy string 29 | if ( string_copy != NULL ) strcpy( string_copy, string ); 30 | 31 | return string_copy; 32 | } 33 | 34 | /* ----------------------------------------------- 35 | convert a string to lowercase 36 | ----------------------------------------------- */ 37 | void to_lowercase( char* string ) { 38 | for( ; (*string) != '\0'; string++ ) { 39 | if ( ( (*string) >= (unsigned char) 'A' ) && ( (*string) <= (unsigned char) 'Z' ) ) 40 | (*string) += ( (unsigned char) 'a' - (unsigned char) 'A' ); 41 | } 42 | } 43 | 44 | /* ----------------------------------------------- 45 | case-independent string compare 46 | ----------------------------------------------- */ 47 | int strcmp_ci( const char* str1, const char* str2 ) { 48 | // special letters such as german umlauts are still case dependent! 49 | int diff; 50 | 51 | do { 52 | diff = (*str1) - (*str2); 53 | if ( (*str1) == '\0' ) break; 54 | if ( diff == ( 'a' - 'A' ) ) { 55 | if ( ( (*str1) >= 'a' ) && ( (*str1) <= 'z' ) ) diff = 0; 56 | } else if ( diff == ( 'A' - 'a' ) ) { 57 | if ( ( (*str1) >= 'A' ) && ( (*str1) <= 'Z' ) ) diff = 0; 58 | } 59 | str1++; str2++; 60 | } while ( diff == 0 ); 61 | 62 | return diff; 63 | } 64 | 65 | /* ----------------------------------------------- 66 | creates filename, callocs memory for it 67 | ----------------------------------------------- */ 68 | char* create_filename( const char* base, const char* extension ) 69 | { 70 | int len = strlen( base ) + ( ( extension == NULL ) ? 0 : strlen( extension ) + 1 ) + 1; 71 | char* filename = (char*) calloc( len, sizeof( char ) ); 72 | 73 | // create a filename from base & extension 74 | strcpy( filename, base ); 75 | set_extension( filename, extension ); 76 | 77 | return filename; 78 | } 79 | 80 | /* ----------------------------------------------- 81 | creates filename, callocs memory for it 82 | ----------------------------------------------- */ 83 | char* unique_filename( const char* base, const char* extension ) { 84 | int len = strlen( base ) + ( ( extension == NULL ) ? 0 : strlen( extension ) + 1 ) + 1; 85 | char* filename = (char*) calloc( len, sizeof( char ) ); 86 | 87 | // create a unique filename using underscores 88 | strcpy( filename, base ); 89 | set_extension( filename, extension ); 90 | while ( file_exists( filename ) ) { 91 | len += sizeof( char ); 92 | filename = (char*) realloc( filename, len ); 93 | add_underscore( filename ); 94 | } 95 | 96 | return filename; 97 | } 98 | 99 | /* ----------------------------------------------- 100 | creates filename, callocs memory for it 101 | ----------------------------------------------- */ 102 | char* unique_tempname( const char* base, const char* extension ) { 103 | char* nbase = ( char* ) calloc ( strlen( base ) + 2, sizeof( char ) ); 104 | char* filename; 105 | 106 | // build new base: insert dot before filename 107 | strcpy( nbase, base ); 108 | filename = get_filename( nbase ); 109 | for ( char* fnptr = filename + strlen( filename ); fnptr >= filename; fnptr-- ) 110 | fnptr[1] = fnptr[0]; 111 | filename[0] = '.'; 112 | 113 | // build unique filename, discard base 114 | filename = unique_filename( nbase, extension ); 115 | free( nbase ); 116 | 117 | return filename; 118 | } 119 | 120 | /* ----------------------------------------------- 121 | adds underscore after filename 122 | ----------------------------------------------- */ 123 | void add_underscore( char* filename ) { 124 | char* tmpname = (char*) calloc( strlen( filename ) + 1, sizeof( char ) ); 125 | char* extstr; 126 | 127 | // copy filename to tmpname 128 | strcpy( tmpname, filename ); 129 | // search extension in filename 130 | extstr = get_extension( filename ); 131 | 132 | // add underscore before extension 133 | (*extstr++) = '_'; 134 | strcpy( extstr, get_extension( tmpname ) ); 135 | 136 | // free memory 137 | free( tmpname ); 138 | } 139 | 140 | /* ----------------------------------------------- 141 | returns extension of filename 142 | ----------------------------------------------- */ 143 | char* get_extension( char* filename ) { 144 | char* extstr; 145 | 146 | // find position of extension in filename 147 | extstr = strrchr( get_filename( filename ), '.' ); 148 | if ( ( extstr == NULL ) || ( extstr == get_filename( filename ) ) ) 149 | extstr = filename + strlen( filename ); 150 | 151 | // extstr = ( strrchr( filename, '.' ) == NULL ) ? 152 | // filename + strlen( filename ) : strrchr( filename, '.' ); 153 | 154 | return extstr; 155 | } 156 | 157 | /* ----------------------------------------------- 158 | changes extension of filename 159 | ----------------------------------------------- */ 160 | void set_extension( char* filename, const char* extension ) { 161 | char* extstr; 162 | 163 | // find position of extension in filename 164 | extstr = get_extension( filename ); 165 | 166 | // set new extension 167 | if ( extension != NULL ) { 168 | (*extstr++) = '.'; 169 | strcpy( extstr, extension ); 170 | } 171 | else 172 | (*extstr) = '\0'; 173 | } 174 | 175 | /* ----------------------------------------------- 176 | assure containing path exists 177 | ----------------------------------------------- */ 178 | bool assure_cpath_rec( char* filepath ) { 179 | char path_t[ MAX_PATH_LENGTH + 1 ]; 180 | int len; 181 | 182 | 183 | // find out length of containing path... 184 | for ( len = strlen( filepath ) - 1; len > 0; len-- ) 185 | if ( ( filepath[ len ] == '\\' ) || ( filepath[ len ] == '/' ) ) break; 186 | for ( ; len > 0; len-- ) 187 | if ( ( filepath[ len - 1 ] != '\\' ) && ( filepath[ len - 1 ] != '/' ) ) break; 188 | if ( len == 0 ) return true; // zero length paths exist by definition 189 | // if ( len > MAX_PATH_LENGTH ) return false; // too long paths are not allowed 190 | // ... and make a local copy 191 | strncpy( path_t, filepath, len ); 192 | path_t[ len ] = '\0'; 193 | 194 | // check if containing path exists 195 | if ( !path_exists( path_t ) ) { // directory is not there 196 | // get one level deeper... 197 | if ( !assure_cpath_rec( path_t ) ) return false; 198 | // ... then create the 'path_t' dir! 199 | if ( MKDIR( path_t ) == -1 ) return false; 200 | } 201 | 202 | 203 | return true; 204 | } 205 | 206 | /* ----------------------------------------------- 207 | assure containing path, open file 208 | ----------------------------------------------- */ 209 | FILE* fopen_filepath( char* filepath, const char* mode ) { 210 | // check length of path 211 | if ( strlen( filepath ) > MAX_PATH_LENGTH ) return NULL; 212 | // assure containing path 213 | if ( !assure_cpath_rec( filepath ) ) return NULL; 214 | 215 | return fopen( filepath, mode ); 216 | } 217 | 218 | /* ----------------------------------------------- 219 | expand filelist recursive helper function 220 | ----------------------------------------------- */ 221 | static bool expand_filelist_rec ( char* filepath, char*** exp_filelist, int* n ) { 222 | DIR *dp; 223 | struct dirent* entry; 224 | char* newpath; 225 | 226 | 227 | dp = opendir( filepath ); 228 | if ( dp != NULL ) { // this is a directory 229 | while ( ( entry = readdir( dp ) ) != NULL ) { 230 | if ( ( strcmp( entry->d_name, "." ) == 0 ) || ( strcmp( entry->d_name, ".." ) == 0 ) ) 231 | continue; // skip . and .. entries 232 | newpath = ( char* ) 233 | calloc( strlen( filepath ) + strlen( entry->d_name ) + 2, sizeof ( char ) ); 234 | sprintf( newpath, "%s%c%s", filepath, DIR_SEPERATOR, entry->d_name ); 235 | if ( expand_filelist_rec( newpath, exp_filelist, n ) ) free ( newpath ); 236 | } 237 | closedir( dp ); 238 | return true; 239 | } else { // this is not a directory - add filename to list 240 | if ( ( (*n) % PATH_BUFFER ) == 0 ) 241 | (*exp_filelist) = ( char** ) realloc( (*exp_filelist), ( (*n) + PATH_BUFFER + 1 ) * sizeof( char* ) ); 242 | (*exp_filelist)[ (*n)++ ] = filepath; 243 | return false; 244 | } 245 | 246 | 247 | return false; 248 | } 249 | 250 | /* ----------------------------------------------- 251 | collect filenames in directories 252 | ----------------------------------------------- */ 253 | char** expand_filelist( char** filelist, int len ) { 254 | char** exp_filelist = ( char** ) calloc ( 1, sizeof( char* ) ); 255 | int exp_len = 0; 256 | char* filepath; 257 | int i; 258 | 259 | 260 | // recursively collect filenames 261 | for ( i = 0; i < len; i++ ) { 262 | filepath = clone_string( filelist[i] ); 263 | if ( expand_filelist_rec( filepath, &exp_filelist, &exp_len ) ) free( filepath ); 264 | } 265 | exp_filelist = ( char** ) realloc( exp_filelist, ( exp_len + 1 ) * sizeof( char* ) ); 266 | exp_filelist[ exp_len ] = NULL; 267 | 268 | 269 | return exp_filelist; 270 | } 271 | 272 | /* ----------------------------------------------- 273 | returns filename (without path) 274 | ----------------------------------------------- */ 275 | char* get_filename( char* file_string ) { 276 | char* filename = ( strrchr( file_string, '\\' ) == NULL ) ? 277 | strrchr( file_string, '/' ) : strrchr( file_string, '\\' ); 278 | 279 | return ( filename == NULL ) ? file_string : filename + 1; 280 | } 281 | 282 | /* ----------------------------------------------- 283 | get common path for a list of files 284 | ----------------------------------------------- */ 285 | char* get_common_path( char** filelist, int len ) { 286 | char* path; 287 | int plen; 288 | 289 | 290 | // make sure the filelist is not empty 291 | if ( len == 0 ) return NULL; 292 | 293 | // get path and basepath length for first entry 294 | path = clone_string( filelist[0] ); 295 | for ( plen = strlen( path ) + 1; plen > 0; plen-- ) 296 | if ( ( path[ plen - 1 ] == '\\' ) || ( path[ plen - 1 ] == '/' ) ) break; 297 | path[ plen ] = '\0'; 298 | 299 | // iterate through all entries of the filelist 300 | for ( int i = 1; i < len; i++ ) { 301 | while ( ( plen > 0 ) && ( strncmp( filelist[i], path, plen ) != 0 ) ) { 302 | for ( ; plen > 0; plen-- ) 303 | if ( ( path[ plen - 1 ] != '\\' ) && ( path[ plen - 1 ] != '/' ) ) break; 304 | for ( ; plen > 0; plen-- ) 305 | if ( ( path[ plen - 1 ] == '\\' ) || ( path[ plen - 1 ] == '/' ) ) break; 306 | path[ plen ] = '\0'; 307 | } 308 | } 309 | 310 | // don't waste precious memory 311 | path = ( char* ) realloc( path, ( strlen( path ) + 1 ) * sizeof( char ) ); 312 | 313 | 314 | return path; 315 | } 316 | 317 | /* ----------------------------------------------- 318 | create a standardized version of the filepath 319 | ----------------------------------------------- */ 320 | void normalize_filepath( char* filepath ) { 321 | char* in_ptr = filepath; 322 | char* out_ptr = filepath; 323 | 324 | 325 | // double slashes at path begin are allowed (but nowhere else) 326 | if ( (*in_ptr) == DIR_SEPERATOR ) { 327 | in_ptr++; 328 | out_ptr++; 329 | } 330 | 331 | // replace all '\\' and multiple slashes with '/' 332 | do { 333 | if ( ( (*in_ptr) == '\\' ) || ( (*in_ptr) == '/' ) ) { 334 | in_ptr++; 335 | while ( (*in_ptr == '\\' ) || ( (*in_ptr) == '/' ) ) in_ptr++; 336 | (*out_ptr++) = DIR_SEPERATOR; 337 | } 338 | (*out_ptr++) = (*in_ptr); 339 | } while ( (*in_ptr++) != '\0' ); 340 | 341 | 342 | return; 343 | } 344 | 345 | /* ----------------------------------------------- 346 | create a standardized version of the filepath 347 | ----------------------------------------------- */ 348 | bool set_containing_path( char* filepath ) 349 | { 350 | char path[ MAX_PATH_LENGTH + 1 ]; 351 | int len; 352 | 353 | // find out length of containing path... 354 | for ( len = strlen( filepath ) - 1; len > 0; len-- ) 355 | if ( ( filepath[ len ] == '\\' ) || ( filepath[ len ] == '/' ) ) break; 356 | for ( ; len > 0; len-- ) 357 | if ( ( filepath[ len - 1 ] != '\\' ) && ( filepath[ len - 1 ] != '/' ) ) break; 358 | if ( len > MAX_PATH_LENGTH ) return false; 359 | 360 | // copy containing path 361 | strncpy( path, filepath, len ); 362 | path[ len ] = '\0'; 363 | 364 | // set path and return 365 | return ( chdir( path ) != -1 ); 366 | } 367 | 368 | /* ----------------------------------------------- 369 | checks if a file exists 370 | ----------------------------------------------- */ 371 | bool file_exists( const char* filename ) { 372 | // needed for both, executable and library 373 | FILE* fp = fopen( filename, "rb" ); 374 | 375 | if ( fp == NULL ) return false; 376 | else { 377 | fclose( fp ); 378 | return true; 379 | } 380 | } 381 | 382 | /* ----------------------------------------------- 383 | checks if a path exists 384 | ----------------------------------------------- */ 385 | bool path_exists( const char* filename ) { 386 | DIR* dp = opendir( filename ); 387 | 388 | if ( dp == NULL ) return false; 389 | else { 390 | closedir( dp ); 391 | return true; 392 | } 393 | } 394 | 395 | /* ----------------------------------------------- 396 | returns size of file if possible 397 | ----------------------------------------------- */ 398 | off_t file_size( const char* filename ) { 399 | FILE* fp; 400 | off_t size; 401 | 402 | fp = fopen( filename, "rb" ); 403 | if ( fp != NULL ) { 404 | fseek( fp, 0, SEEK_END ); 405 | size = ftell( fp ); 406 | fclose( fp ); 407 | } else size = 0; 408 | 409 | return size; 410 | } 411 | 412 | /* ----------------------------------------------- 413 | realloc alternative 414 | ----------------------------------------------- */ 415 | void* frealloc( void* ptr, size_t size ) { 416 | void* n_ptr = frealloc( ptr, size ); 417 | if ( n_ptr == NULL ) free( ptr ); 418 | return n_ptr; 419 | } 420 | -------------------------------------------------------------------------------- /source/packARC/helpers.h: -------------------------------------------------------------------------------- 1 | #include "lfs_supp.h" 2 | #define MAX_PATH_LENGTH 260 3 | 4 | /* ----------------------------------------------- 5 | helper functions (*: used in frontend) 6 | ----------------------------------------------- */ 7 | 8 | // generic string manipulation 9 | char* clone_string( char* string ); // * 10 | void to_lowercase( char* string ); 11 | int strcmp_ci( const char* str1, const char* str2 ); 12 | 13 | // filename specific manipulation 14 | char* create_filename( const char* base, const char* extension ); 15 | char* unique_filename( const char* base, const char* extension ); 16 | char* unique_tempname( const char* base, const char* extension ); 17 | void add_underscore( char* filename ); 18 | char* get_extension( char* filename ); 19 | void set_extension( char* filename, const char* extension ); 20 | 21 | // path name specific manipulation 22 | char* get_filename( char* file_string ); // * 23 | bool assure_cpath_rec( char* filepath ); 24 | FILE* fopen_filepath( char* filepath, const char* mode ); 25 | char** expand_filelist( char** filelist, int len ); // * 26 | char* get_common_path( char** filelist, int len ); // * 27 | void normalize_filepath( char* filepath ); 28 | bool set_containing_path( char* filepath ); // * 29 | 30 | // file existing / size checks 31 | bool file_exists( const char* filename ); // * 32 | bool path_exists( const char* filename ); 33 | off_t file_size( const char* filename ); 34 | 35 | // alternative realloc 36 | void* frealloc( void* ptr, size_t size ); 37 | -------------------------------------------------------------------------------- /source/packARC/icons_app.rc: -------------------------------------------------------------------------------- 1 | app ICON app_icon.ico 2 | ICONS1 ICON app_icon_old.ico 3 | ICONS2 ICON file_icon.ico 4 | ICONS3 ICON sfx_icon.ico -------------------------------------------------------------------------------- /source/packARC/icons_app.res: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/packjpg/packARC/ed6ca67e0d6e0e20dafa7481cbecc7ff10fc00f4/source/packARC/icons_app.res -------------------------------------------------------------------------------- /source/packARC/icons_sfx.rc: -------------------------------------------------------------------------------- 1 | app ICON sfx_icon.ico -------------------------------------------------------------------------------- /source/packARC/icons_sfx.res: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/packjpg/packARC/ed6ca67e0d6e0e20dafa7481cbecc7ff10fc00f4/source/packARC/icons_sfx.res -------------------------------------------------------------------------------- /source/packARC/lfs_supp.h: -------------------------------------------------------------------------------- 1 | // careful enabling this! 2 | #define ENABLE_LFS 1 3 | 4 | #if defined (ENABLE_LFS) 5 | #define ftell ftello64 6 | #define fseek fseeko64 7 | #define fopen fopen64 8 | #define off_t off64_t 9 | #else 10 | #define off_t long int 11 | #endif 12 | -------------------------------------------------------------------------------- /source/packARC/packANYlib.h: -------------------------------------------------------------------------------- 1 | // packANYlib.h - function declarations and reference for the packANY library 2 | #define EXPORT extern 3 | 4 | 5 | /* suggested usage: 6 | 1.) init streams using xxxlib_init_streams() (see below) 7 | 2.) convert files using the xxxlib_convert_stream2stream() function 8 | ... or ... 9 | 1.) convert between files using xxxlib_convert_file2file() 10 | 11 | input/output stream types and setup for 12 | the xxxlib_init_streams() function: 13 | 14 | if input is file 15 | ---------------- 16 | in_scr -> name of input file 17 | in_type -> 0 18 | in_size -> ignore 19 | 20 | if input is memory 21 | ------------------ 22 | in_scr -> array containg data 23 | in_type -> 1 24 | in_size -> size of data array 25 | 26 | if input is *FILE (f.e. stdin) 27 | ------------------------------ 28 | in_src -> stream pointer 29 | in_type -> 2 30 | in_size -> ignore 31 | 32 | same for output streams! */ 33 | 34 | 35 | 36 | /* ----------------------------------------------- 37 | function declarations: packARI library 38 | ----------------------------------------------- */ 39 | 40 | EXPORT bool parlib_convert_stream2stream( char* msg ); 41 | EXPORT bool parlib_convert_file2file( char* in, char* out, char* msg ); 42 | EXPORT bool parlib_convert_stream2mem( unsigned char** out_file, unsigned int* out_size, char* msg ); 43 | EXPORT void parlib_init_streams( void* in_src, int in_type, int in_size, void* out_dest, int out_type ); 44 | EXPORT void parlib_force_encoding( bool setting ); 45 | EXPORT const char* parlib_version_info( void ); 46 | EXPORT const char* parlib_short_name( void ); 47 | 48 | 49 | /* ----------------------------------------------- 50 | function declarations: packJPG library 51 | ----------------------------------------------- */ 52 | 53 | EXPORT bool pjglib_convert_stream2stream( char* msg ); 54 | EXPORT bool pjglib_convert_file2file( char* in, char* out, char* msg ); 55 | EXPORT bool pjglib_convert_stream2mem( unsigned char** out_file, unsigned int* out_size, char* msg ); 56 | EXPORT void pjglib_init_streams( void* in_src, int in_type, int in_size, void* out_dest, int out_type ); 57 | EXPORT const char* pjglib_version_info( void ); 58 | EXPORT const char* pjglib_short_name( void ); 59 | 60 | 61 | /* ----------------------------------------------- 62 | function declarations: packMP3 library 63 | ----------------------------------------------- */ 64 | 65 | EXPORT bool pmplib_convert_stream2stream( char* msg ); 66 | EXPORT bool pmplib_convert_file2file( char* in, char* out, char* msg ); 67 | EXPORT bool pmplib_convert_stream2mem( unsigned char** out_file, unsigned int* out_size, char* msg ); 68 | EXPORT void pmplib_init_streams( void* in_src, int in_type, int in_size, void* out_dest, int out_type ); 69 | EXPORT const char* pmplib_version_info( void ); 70 | EXPORT const char* pmplib_short_name( void ); 71 | 72 | 73 | /* ----------------------------------------------- 74 | function declarations: packPNM library 75 | ----------------------------------------------- */ 76 | 77 | EXPORT bool ppnlib_convert_stream2stream( char* msg ); 78 | EXPORT bool ppnlib_convert_file2file( char* in, char* out, char* msg ); 79 | EXPORT bool ppnlib_convert_stream2mem( unsigned char** out_file, unsigned int* out_size, char* msg ); 80 | EXPORT void ppnlib_init_streams( void* in_src, int in_type, int in_size, void* out_dest, int out_type ); 81 | EXPORT const char* ppnlib_version_info( void ); 82 | EXPORT const char* ppnlib_short_name( void ); 83 | -------------------------------------------------------------------------------- /source/packARC/pja_archiver.h: -------------------------------------------------------------------------------- 1 | #include 2 | #include "lfs_supp.h" 3 | #include "helpers.h" 4 | 5 | // only suggestions! 6 | #define PJA_ARC_EXT "pja" 7 | #if defined(_WIN32) 8 | #define PJA_SFX_EXT "exe" 9 | #else 10 | #define PJA_SFX_EXT "sfx" 11 | #endif 12 | 13 | 14 | struct pja_file_info { 15 | // compressed file information 16 | char filename[ MAX_PATH_LENGTH + 1 ]; 17 | char compression_method[ 3 + 1 ]; 18 | unsigned int file_crc; 19 | off_t file_size_original; 20 | off_t file_size_compressed; 21 | float compression_ratio; 22 | time_t last_changed; 23 | }; 24 | 25 | struct pja_archive_info { 26 | // archive file information 27 | char* filename; 28 | char archive_type; 29 | unsigned char archive_version; 30 | int num_files; 31 | pja_file_info** filelist; 32 | off_t file_size_archive; 33 | off_t file_size_extracted; 34 | float compression_ratio; 35 | time_t last_changed; 36 | }; 37 | 38 | // functions for use by frontend 39 | bool pja_open_archive( char* filename ); 40 | bool pja_update_archive( void ); 41 | bool pja_close_archive( void ); 42 | bool pja_add_file_to_archive( char* filename_int, char* filename_ext ); 43 | bool pja_extract_file_from_archive( char* filename_int, char* filename_ext ); 44 | bool pja_remove_file_from_archive( char* filename ); 45 | bool pja_test_file_in_archive( char* filename ); 46 | bool pja_convert_archive( void ); 47 | void pja_set_existing_files_handling( char setting ); 48 | void pja_set_check_extracted_crc( bool setting ); 49 | pja_archive_info* pja_get_archive_info( void ); 50 | char* pja_get_current_status( void ); 51 | char* pja_get_version_info( void ); 52 | char* pja_get_engine_info( void ); 53 | -------------------------------------------------------------------------------- /source/packARC/sfx_icon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/packjpg/packARC/ed6ca67e0d6e0e20dafa7481cbecc7ff10fc00f4/source/packARC/sfx_icon.ico -------------------------------------------------------------------------------- /source/packARC/sfxstub2h.c: -------------------------------------------------------------------------------- 1 | /* "sfxstub2h.c" 2 | Converts "sfxstub.exe" to .h-file, which can be included in "packarc.c" 3 | 11-12-20 Se (after "file2array.c" by Matthias Stirner) 4 | */ 5 | 6 | #include 7 | #include 8 | #include 9 | 10 | #define PROGNAME "sfxstub2h" 11 | 12 | #if defined WIN32 13 | #define INFILE "sfxstub.exe" 14 | #define PLATFORM "WIN32" 15 | #else 16 | #define INFILE "sfxstub" 17 | #define PLATFORM "unknown" 18 | #endif 19 | #define OUTFILE "sfxstub.h" 20 | 21 | #define ARRAYNAME "pjxstub" 22 | #define CHARS_PER_LINE 16 23 | 24 | 25 | int main( int argc, char** argv ) { 26 | 27 | FILE *fip, *fop; 28 | unsigned char cbyte; 29 | int i = 0; 30 | 31 | /* check input, open files */ 32 | if ( argc != 1 ) { 33 | fprintf(stderr, "\nUsage: %s\n", argv[0]); 34 | exit(EXIT_FAILURE); 35 | } 36 | 37 | fip = fopen( INFILE, "rb" ); 38 | if ( fip == NULL ) { 39 | fprintf(stderr, "\n%s: Error opening input file \"%s\"\n", PROGNAME, INFILE); 40 | perror(PROGNAME); 41 | exit(EXIT_FAILURE); 42 | } 43 | 44 | fop = fopen( OUTFILE, "wt" ); 45 | if ( fop == NULL ) { 46 | fprintf(stderr, "\n%s: Error opening output file \"%s\"\n", PROGNAME, OUTFILE); 47 | perror(PROGNAME); 48 | exit(EXIT_FAILURE); 49 | } 50 | 51 | /* write to output file */ 52 | fprintf( fop, "/* '%s' converted from '%s' by '%s' */\n", OUTFILE, INFILE, PROGNAME ); 53 | fprintf( fop, "/* for platform: '%s' on %s */\n\n", PLATFORM, __DATE__ ); 54 | fprintf( fop, "unsigned char %s[] = {", ARRAYNAME ); 55 | while ( fread( &cbyte, 1, 1, fip ) == 1 ) { 56 | if ( i++ % CHARS_PER_LINE == 0 ) fprintf( fop, "\n\t\"" ); 57 | fprintf( fop, "\\x%02X", cbyte ); 58 | if ( i % CHARS_PER_LINE == 0 ) fprintf( fop, "\"" ); 59 | } 60 | if ( i % CHARS_PER_LINE != 0 ) fprintf( fop, "\"" ); 61 | fprintf( fop, "\n};\n\n" ); 62 | fprintf( fop, "unsigned int %s_size = sizeof(%s);\n", ARRAYNAME, ARRAYNAME ); 63 | 64 | /* close files */ 65 | fclose( fip ); 66 | fclose( fop ); 67 | 68 | fprintf(stderr, "%s-info: %d characters read and converted.", PROGNAME, i); 69 | 70 | exit(EXIT_SUCCESS); 71 | } 72 | --------------------------------------------------------------------------------