Author Topic: Adaptive LZW packer/unpacker  (Read 14004 times)

0 Members and 1 Guest are viewing this topic.

Offline keybone

  • Forum Regular
  • Posts: 116
  • My name a Nursultan Tulyakbay.
    • View Profile
Re: Adaptive LZW packer/unpacker
« Reply #15 on: March 09, 2019, 05:48:45 pm »
I'm definately gonna find a good use for this in my gui project :)
I am from a Kazakhstan, we follow the hawk.

Offline euklides

  • Forum Regular
  • Posts: 128
    • View Profile
Re: Adaptive LZW packer/unpacker
« Reply #16 on: March 11, 2019, 06:18:02 am »
Thank you, it's a very usefull  program, RhoSigma !
Why not yes ?

Offline SpriggsySpriggs

  • Forum Resident
  • Posts: 1145
  • Larger than life
    • View Profile
    • GitHub
Re: Adaptive LZW packer/unpacker
« Reply #17 on: May 21, 2020, 12:05:23 pm »
I'm having issues using this program on PNG, ICO, and many other filetypes. Are there specific file types that it doesn't seem to like? Every time I try to compress one of those kinds of files it fails. I have tried many other file types with success on some all the way up to 79% compression. Attached is a screenshot from a program I made using your library. You can see in my results screen that it fails on the PNG but it succeeded on the first file in the list which is a BMP. The error that says "Try lowering the compression value" is just the generic output I made for files that fail.
 
QBZ archiver.png

The source code for my program is attached here:
 
I did edit your BM file for the LZW library so I could use a zip and unzip function that I made but I don't think that is what is causing the issue. I've even tried using the example you provide in the folder with my files and I get the same results. I'm not sure what could cause the failure.
Shuwatch!

Offline RhoSigma

  • QB64 Developer
  • Forum Resident
  • Posts: 565
    • View Profile
Re: Adaptive LZW packer/unpacker
« Reply #18 on: May 21, 2020, 01:31:09 pm »
How big are the file sizes of those failing files, you probably don't need to expect files < 100 bytes to compress.
PNG files are usually already compressed with zlib's deflate (same as _DEFLETE$ will use) and hence can't be compressed again.
My Projects:   https://qb64forum.alephc.xyz/index.php?topic=809
GuiTools - A graphic UI framework (can do multiple UI forms/windows in one program)
Libraries - ImageProcess, StringBuffers (virt. files), MD5/SHA2-Hash, LZW etc.
Bonus - Blankers, QB64/Notepad++ setup pack

Offline RhoSigma

  • QB64 Developer
  • Forum Resident
  • Posts: 565
    • View Profile
Re: Adaptive LZW packer/unpacker
« Reply #19 on: May 21, 2020, 02:40:22 pm »
I can't check your program, as the archive is missing the following files needed for compilation:

Open-SaveFile.bi
OpenFile.bm
Replace.bm
open-folder.png.MEM
zip-folder.png.MEM
delete.png.MEM

Once again, there's no restriction on any file formats. However, very small files or those already compressed will probably fail even with a given ratio of 0%.

I see also, that you will run the LzwPacked data thru _DEFLATE$, which is probably of less use either. If the data is once packed with my LZW routine, then another _DEFLATE$ call (which is nothing else than a LZW derivate) will probably don't do much, although I guess the LZW implementation used by _DEFLATE$ is a better optimized algorithm than mine and could squeeze out another percent or two.
My Projects:   https://qb64forum.alephc.xyz/index.php?topic=809
GuiTools - A graphic UI framework (can do multiple UI forms/windows in one program)
Libraries - ImageProcess, StringBuffers (virt. files), MD5/SHA2-Hash, LZW etc.
Bonus - Blankers, QB64/Notepad++ setup pack

Offline SpriggsySpriggs

  • Forum Resident
  • Posts: 1145
  • Larger than life
    • View Profile
    • GitHub
Re: Adaptive LZW packer/unpacker
« Reply #20 on: May 21, 2020, 02:52:46 pm »
So sorry for forgetting my includes! I always forget those!
Here is the new zipped folder with the full source. I was able to get a slightly smaller file when I used _DEFLATE$ in the sample you provided so I just decided to leave it in there. I appreciate you making these libraries available for everyone. It's really helping me to expand my programs.
 
« Last Edit: May 21, 2020, 02:55:46 pm by SpriggsySpriggs »
Shuwatch!

Offline RhoSigma

  • QB64 Developer
  • Forum Resident
  • Posts: 565
    • View Profile
Re: Adaptive LZW packer/unpacker
« Reply #21 on: May 21, 2020, 03:19:40 pm »
:(  :(  :(   Nested includes ??? - Bad idea IMHO.

You quickly lose the overview what libraries/code snippets you finally use in your projects and what files you have to distribute when making your source available to others. This may discourage people, so they never take a look to your projects anymore. You should rather consider to make a dependency note in those include files, which need further files to be included, eg. as I did in my qbdebug.bm file, which also needs qbstdarg.bm and qbstdio.bm to work.

However, here is the next level of missing files (hopefully the last nesting level):
OpenFile.ps1.BM (included by OpenFile.BM)
My Projects:   https://qb64forum.alephc.xyz/index.php?topic=809
GuiTools - A graphic UI framework (can do multiple UI forms/windows in one program)
Libraries - ImageProcess, StringBuffers (virt. files), MD5/SHA2-Hash, LZW etc.
Bonus - Blankers, QB64/Notepad++ setup pack

Offline codeguy

  • Forum Regular
  • Posts: 174
    • View Profile
Re: Adaptive LZW packer/unpacker
« Reply #22 on: May 21, 2020, 03:27:29 pm »
My OpenInclude() recursive code merger might be of help if you want to make one large listing with all the $INCLUDE files in the proper place (even nested, which is when the recursive part is necessary). I believe it has been co-opted with my blessing for InForm and maybe even someone else's projects. Steal freely.
OpenInclude():https://www.qb64.org/forum/index.php?topic=106.msg596#msg596
Zom-B did something similar but his could not handle $INCLUDE within $INCLUDE. This situation does happen and I don't consider the practice highly unusual. Felipe seemed happy enough with it and I consider him a tough but fair customer.
« Last Edit: May 21, 2020, 03:34:45 pm by codeguy »

Offline SpriggsySpriggs

  • Forum Resident
  • Posts: 1145
  • Larger than life
    • View Profile
    • GitHub
Re: Adaptive LZW packer/unpacker
« Reply #23 on: May 22, 2020, 09:03:24 am »
Actually, that isn't a problem. I've moved on to using only _DEFLATE$ and had smaller files all around without need for anything but getting the file as a string, compressing it, and then using _INFLATE$ to decompress the contents. I store the filename in the compressed file so that when the file is unzipped later it can be renamed to the original filename. Thanks, though. As for the nested '$INCLUDE, it is only necessary if running in 64 bit. Hence the $ELSE in the $IF 32BIT block. Since the open file dialog only works in 32 bit I assumed you wouldn't have been needing to use that file since it calls a PowerShell script anyways and you would probably not trust running a stranger's PowerShell script. Anyways, _DEFLATE$ seems to be more efficient for me as it compresses the files to a fraction of your LzwPack function and hasn't failed on any files due to the nature of my zip and unzip functions that I've edited since my last message to you. I appreciate your time and effort assisting me in debugging my program.
« Last Edit: May 22, 2020, 09:28:59 am by SpriggsySpriggs »
Shuwatch!

Offline SpriggsySpriggs

  • Forum Resident
  • Posts: 1145
  • Larger than life
    • View Profile
    • GitHub
Re: Adaptive LZW packer/unpacker
« Reply #24 on: May 22, 2020, 09:59:58 am »
My OpenInclude() recursive code merger might be of help if you want to make one large listing with all the $INCLUDE files in the proper place (even nested, which is when the recursive part is necessary). I believe it has been co-opted with my blessing for InForm and maybe even someone else's projects. Steal freely.
OpenInclude():https://www.qb64.org/forum/index.php?topic=106.msg596#msg596
Zom-B did something similar but his could not handle $INCLUDE within $INCLUDE. This situation does happen and I don't consider the practice highly unusual. Felipe seemed happy enough with it and I consider him a tough but fair customer.
Excellent little program. Thank you for sharing. Definitely will help me distribute my applications easier and keep everything together so I don't annoy people.
Shuwatch!

Offline RhoSigma

  • QB64 Developer
  • Forum Resident
  • Posts: 565
    • View Profile
Re: Adaptive LZW packer/unpacker
« Reply #25 on: May 22, 2020, 10:54:08 am »
... Anyways, _DEFLATE$ seems to be more efficient for me as it compresses the files to a fraction of your LzwPack function ...

Of course _DEFLATE$ is much more efficient and absolutely worth to be used instead of my library, which was programmed when we had no native compression commands in QB64. However, my packing library comes still in handy, when programming with older QB64 versions without native compression support.

I appreciate your time and effort assisting me in debugging my program.

Don't worry, you're welcome...
My Projects:   https://qb64forum.alephc.xyz/index.php?topic=809
GuiTools - A graphic UI framework (can do multiple UI forms/windows in one program)
Libraries - ImageProcess, StringBuffers (virt. files), MD5/SHA2-Hash, LZW etc.
Bonus - Blankers, QB64/Notepad++ setup pack