Jump to content

Sky Slate Blueberry Blackcurrant Watermelon Strawberry Orange Banana Apple Emerald Chocolate
Photo

Efficient binary objects embedding in AHK code - ASCII 85


  • Please log in to reply
25 replies to this topic
Sarah
  • Members
  • 103 posts
  • Last active: Oct 12 2009 05:42 PM
  • Joined: 12 Jul 2007

I can't respond to you directly since I've not had time to dig into Skan's lib. Sorry :(


No worries & thank you! :D

Joy2DWorld
  • Members
  • 562 posts
  • Last active: Jun 30 2014 07:48 PM
  • Joined: 04 Dec 2006

majkinetor : looks like it's exactly the purpose of skan's AxC : Pack and Unpack Binary files which offers the following functionnality :

Not in the manner I proposed. Its completely different project, looking similar at first glance


your idea is good.

under 10 min. to code...


read file into var,
convert to ascii85

regex per my prev. posted code (mod to include ` and % options in concat)

wrap in function name to return val as bin...

done.


or so it seems if understood the idea...
Joyce Jamce

majkinetor
  • Moderators
  • 4512 posts
  • Last active: May 20 2019 07:41 AM
  • Joined: 24 May 2006
Yes, exactly.
I would go ahead and create file system structure if possible similar to ScriptMerge.

Acctually, the concept generaly doesn't have so much benefits unless something similar to RAM drives is used.

To clearify this: lets say you have several files each of differnet type, so you may have some pictures, some sounds, some arbitrary binary data, and in most of the time it will need to have location on the HD, i.e. path that it can be accessed. But then to use resource.ahk you would need to unpack it in temporrary folder (existing solution for bitmaps is clearly not enough) which defets the purpose great deal. I would like to use resource.ahk as a file system, without temporary files.

While this is possible to do with something similar to RAM drives, or maybe even virtual folders (maybe I say), I am not sure how it can be done nor how much complexity it involves.

Actually, this would be abstraction of ScriptMerge. It would let you include arbitrary files into your ahk file, and use the resources in memory. It would also be possible to unpack everything back if you want to speed up things.

Would be very valuable IMO.
Posted Image

Sarah
  • Members
  • 103 posts
  • Last active: Oct 12 2009 05:42 PM
  • Joined: 12 Jul 2007
Trying to stay on topic here --- but can this actually be used to embed a .wav file, for instance in my AHK program, and play such file runtime? If so, how would I approach that code wise? :) Thank you so much for this thread Azerty, Majkinetor, to make me understand :)

I guess what I am asking is..... can a .WAV be referenced like a Image... without regenerating it to a file which would be useless to me but useful in the sense you would be sort of encapsulating all of the data before running final product. Best wishes, Sarah. :D

i.e.

IMAGES > PNG, GIF, JPG >>> Display directly from binary without creating File

.EXE, other assets must be regenerated to a file

.WAVE??? sounds??? can they be just played directly from binary or am I way off base? :roll: :p

Laszlo
  • Moderators
  • 4713 posts
  • Last active: Mar 31 2012 03:17 AM
  • Joined: 14 Feb 2005
I wonder… If you embed hex encoded data in your AHK script instead of ascii85, when you compile it, the data gets compressed. Will it result in similar code sizes? Ascii85 could still have an advantage: less temporary memory.

Azerty
  • Members
  • 72 posts
  • Last active: Jan 16 2009 10:08 AM
  • Joined: 19 Dec 2006
sarah : using PlaySound() API through DllCall() should do the trick using SND_MEMORY flag. See here. As for JPeG, BMP & al, browsing through the forum should help you find the trick (look at samples like hardcopy scripts, for instance, to see how to manipulate images in memory).

Laszlo : it should be tested, since ASCII (charset of 85 chars) is also compressible (though might be slightly less than pure hexa). It probably depends on the complexity of the source binary data, and results might differ from one test to another.

majkinetor
  • Moderators
  • 4512 posts
  • Last active: May 20 2019 07:41 AM
  • Joined: 24 May 2006

Sarah : using PlaySound() API through DllCall() should do the trick using SND_MEMORY flag. See here. As for JPeG, BMP & al, browsing through the forum should help you find the trick (look at samples like hardcopy scripts, for instance, to see how to manipulate images in memory).

Ye, there are solutions to each multimedia type, but they are specific and not uniformed. I am more interested in finding general solution. I see that Azerty don't have any interest in that, so it would probably have to be done by somebody else. Laszo's ideas about comiled executable definitely gives more attention to such approach, as you would be able to pack any of your resources in the 1 exe file.
Posted Image

Azerty
  • Members
  • 72 posts
  • Last active: Jan 16 2009 10:08 AM
  • Joined: 19 Dec 2006
Majkinetor : yes, for now I'm not directly interested in this problem, since I've got my own, so I'm just trying to give useful clues to Sarah to help him (or perhaps her ?, sorry if I'm mistaken, you'll correct me in your next answer) find his way with the direct question he asks. As for most people here, I try to answer our direct needs and offer our solutions to the community

As for a general solution, I'm no expert in MM questions, but it looks to me like the only generic interface is MCI, which does not offer direct in-memory handling for now from what's I've rapidly browsed in MSDN.

Nonetheless, if you offer us a generic solution to handle in-memory MM data, we'll all be glad to use the library you might provide us if you've got a more profound interest in this precise topic.

edik76
  • Members
  • 8 posts
  • Last active: Nov 04 2015 08:37 PM
  • Joined: 16 Jul 2012
Hi Friends,

I am very beginner at AHK. What is the easiest way to safe the decoded BMP file? , something similar to

Decocede_BMP_File :=Ascii85_AhkDecoder(Logo, BinLogo)

FileAppend, %Decocede_BMP_File%, File.bmp

I have tryed %Decocede_BMP_File% and %BinLogo%, but I have just got bad results.

I tryed "BinReadWrite.ahk", but things got worse. :|

Thank you very much.

guest
  • Guests
  • Last active:
  • Joined: --

Hi Friends,

I am very beginner at AHK. What is the easiest way to safe the decoded BMP file? , something similar to

Decocede_BMP_File :=Ascii85_AhkDecoder(Logo, BinLogo)

FileAppend, %Decocede_BMP_File%, File.bmp

I have tryed %Decocede_BMP_File% and %BinLogo%, but I have just got bad results.

I tryed "BinReadWrite.ahk", but things got worse. :|

Thank you very much.



Try this: viewtopic.php?t=69372

dater
  • Members
  • 30 posts
  • Last active: Mar 29 2013 05:43 AM
  • Joined: 20 Apr 2007
Hi,
how can from Encode to Decode , and wirte to a file ?

Dater
;////
;////   --> EnCode the Picture
;////

LineLength=70
; read PNG
VarSetCapacity(Input, 100000)
h:=OpenFileForRead("bild.png") ; file taken at http://www.autohotkey.com/docs/images/AutoHotkey_logo.gif
BinarySize:=ReadFromFile(h, Input, 0, FILE_BEGIN)
CloseFile(h)
; convert it
OutputSize:=Ascii85_AhkEncoder(Input, BinarySize, Output, LineLength)
; convert to enable AHK inlining
Ascii85_AhkEmbedParser(Output, Output)
; Write ASCII85 conversion of png
FileDelete, logo.asc
FileAppend, %Output%, logo.asc


;////
;////   --> DeCode the Picture
;////
fileread,logo,logo.asc

NeededBytes:=Ascii85_DecoderSize(&logo, 0xFFFFFFFF) 

VarSetCapacity(BinLogo, NeededBytes)

DecodedBytes:=Ascii85_Decoder(&Logo, 0xFFFFFFFF, &BinLogo)

h2:=OpenFileForWrite("bild2.png")

WriteInFile(h2,BinLogo,NeededBytes)

closefile(h2)