News:

Masm32 SDK description, downloads and other helpful links
Message to All Guests
NB: Posting URL's See here: Posted URL Change

Main Menu

CD - Compress-Decompress Utility

Started by fearless, October 22, 2023, 02:13:10 AM

Previous topic - Next topic

fearless

CD - Compress-Decompress Utility using the Microsoft Compression API

You cannot view this attachment. You cannot view this attachment.

CD uses the Microsoft Compression API to compress or decompress data using one of the four supported compression algorithms: XPRESS, XPRESS with Huffman encoding, MSZIP or LZMS.

The files compressed by CD using those compression algorithms also store a signature DWORD value as the header at the start of the file. This is so that the appropriate compression algorithm can be used for the decompression.

CD also makes use of the Microsoft Compression API to store bitmap resources as LZMS compressed data. There are two ways in which CD uses that compressed bitmap data:

  • In the about box, by uncompressing the bitmap data before creating the bitmap in memory. The LZMS compressed bitmap data is stored as static hex bytes in the CD128x128x4.bmp.asm file.

  • Adding LZMS compressed bitmap files (*.lzms) as RC_DATA resources which are compiled into CD.exe. These resources are loaded into memory, and then uncompressed before creating the bitmaps in memory.

CD also allows an optional output of compressed data bytes as a masm .asm file with 'db' data defines, similar to bin2dbex.

Github Repository: https://github.com/mrfearless/CD

v1.0.0.2

  • Optimized assembler output to speed up process overall and to fix hangs (buffer overflows) for larger files (100K+)
  • Added checkbox option to specify .DATA segment or .CONST segment for masm output
  • Added Compress Text button and accelerators for it.
  • Increased the max text size in the input edit control in the compress text dialog to 256KB
  • Uploaded x64 version of CD


v1.0.0.1

  • Added compress text dialog box
  • Added more accelerators for some buttons on the main dialog and in the compress text dialog
  • Added CDCompressMem function
  • Changed CDDecompressMem to allocate 4 additional nulled bytes, for resources like ansi/unicode strings that required null bytes
  • Added compressed string example to About dialog box in an edit control using the MSZIP compressed text stored in infotext.asm


Note: the minimum version of windows to use for the Microsoft Compression API and thus to use the CD - Compress-Decompress Utility is Windows 8:

Biterider

Hi fearless
Very clever idea and good stuff (as always). :thumbsup:

The interface is clean and does what it should.  :cool:
I have tested the functionality a bit and need to integrate the code to handle decompression in my applications.

Chances are good that I will immediately add this tool to my tool set.
What I would like to see is a CL interface to call CD.exe from the tool chain.

Thanks for sharing!

Biterider


fearless

Thanks.

I had considered doing a console version similar to my snappy console application, with support for wildcards and switches for compress/decompress. I would need to add in switches/options for algorithm used and also the optional output to asm file. 

Probably:

/c | -c   Compress (using some default algo)
/d | -d   Decompress
/x | -x   Compress with XPRESS
/h | -h   Compress with XPRESS with Huffman
/m | -m   Compress with MSZIP 
/l | -l   Compress with LZMS
/a | -a   Asm output
/o | -o   Alternate asm output instead if not using /a | -a as a switch
/r | -r   Add .raw ext to decompressed file

Also have to consider overwriting existing files. So maybe the /r or -r for .raw extension instead for safety when decompressing.

So could look like:

CD -l -a *.bmp c:\temp
which would translate to: compress using lzms and output asm file for all bitmaps in current directory to c:\temp folder

Biterider

Quote from: fearless on October 22, 2023, 04:37:40 AMI would need to add in switches/options for algorithm used and also the optional output to asm file. 
That would be really good.

Biterider

greenozon

#4
@fearless
on the beginning of your asm module there is a statement
.XMM
https://github.com/mrfearless/CD/blob/ff2ef6236bad279c6cd92fa21643064fa4c4dab9/CD.asm#L102

have you tried the higher level, does MASM have .YMM, .ZMM?

Biterider

Hi fearless
I would like to give you feedback on my short journey using your code. 
I quickly managed to compress the bitmap I normally use as application background using various algos from your application (CD.exe).

In my particular case, I got the best result using the Huffman compression.

I replaced the reference to the compressed file in my .rc file and copy/pasted the CDBitmapCreateFromMem, CDDecompressMem and CDBitmapCreateFromCompressedRes procedures as well as some definitions and voilá... it worked out of the box.

I forgot to mention that I checked which include files were needed and luckily I had the compressapi.inc from a previous translation of "Windows Kits 10.0.22621.0".

I am very pleased with this development. Congratulations.  :thumbsup:
I will check what is necessary to compile for x64 as well. I am sure there are only minimal adjustments.  :cool:

Biterider

fearless

Nice. Glad to hear it all worked well. 

Yes some different algo's work better with different images. I opted for lzms for the resources in CD.exe mainly due to comparing the results of the output of all the files in one folder vs other folders for the other formats, found that the lzms slightly better for saving space for those images i used. But in most cases a mixture of the different algos for particular files would bring the best space savings.

I am in the middle of also adding an additional dialog to CD to allow compression of text strings to masm format, either as a block or each line separately, as it occurred to me that string resources could benefit in some cases from this. Also have a companion to the CDDecompressMem, a CDCompressMem function, which is used in the text string compression.

Also working on the console version of CD as well. 

I will probably add a few of the functions in CD to ModernUI at some point.

Cheers

Biterider

Hi fearless
Also multi-image icons also tend to be large and can benefit from this technique.

Biterider

2B||!2B

Really nice example fearless. Code is also clear  :thup:

jj2007

Hi fearless,

your program works fine :thumbsup:

What I miss is a programmatical solution to, for example, create a zip archive for \Masm32\examples\exampl01\qikpad, i.e. something like
invoke TheZipper, chr$("test.zip"), chr$("\Masm32\examples\exampl01\qikpad")

Vortex

Hi fearless,

Nice work. Notice that CD is a reserved keyword of the command prompt so you would like to rename the console version of your tool to avoid conflicts.

Keep up the good work :thumbsup:

Greenhorn

Quote from: Vortex on October 27, 2023, 04:17:53 AMHi fearless,

Nice work. Notice that CD is a reserved keyword of the command prompt so you would like to rename the console version of your tool to avoid conflicts.

Keep up the good work :thumbsup:

Maybe CoDe - Compress-Decompress Utility
Kole Feut un Nordenwind gift en krusen Büdel un en lütten Pint.

coaster

It fails under Win 7 32 => "The ordinal 43 could not be located in the dynamic link library Cabinet.dll." 
The version of cabinet.dll is 6.1.7601.1751.

fearless

Hi coaster, unfortunately the minimum version of windows to use for those functions is Windows 8:

Minimum supported clientWindows 8 [desktop apps | UWP apps]
Minimum supported serverWindows Server 2012 [desktop apps | UWP apps]
Target PlatformWindows
Headercompressapi.h
LibraryCabinet.lib
DLLCabinet.dll

fearless