Jump to content

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

Include a bitmap in your uncompiled script!!!


  • Please log in to reply
84 replies to this topic
Veovis
  • Members
  • 389 posts
  • Last active: Mar 17 2009 12:24 AM
  • Joined: 13 Feb 2006

Foreword:

After Goyyah showed its possible to write a dynamic bitmap file using Laszlo's and PhiLho's Binary Read and Write Functions, i wondered if it would be possible to simply include a bitmap in hexadecimal form inside your script, write it, then display it. Heres what i got:

Application:

I took a 24 by 24 Bitmap and turned it into Hexadecimal by saving it and reading it with Laszlos BinRead

The BMP file was 2,784 bytes
in text file takes 5,568 bytes

It doubles the file size excactly because each byte in the .bmp (for example "0a") is represented by two ascii bytes, since each char takes one byte.

But then you exctract the bitmap, thus making the data again so we can conclude:

including bitmaps in your script triples the space they take up

but decreases cluttered and makes it possible to send files with your script.

Example:

The following script creates this gui
using no external files!(except that one that it writes of course)

Posted Image

#singleinstance force
#noenv
gosub, definepicture
WriteFile("logo.bmp",picture)
gui, add, pic,x100,logo.bmp
gui, add, text,xm,The Image above was created by the script.
gui, show,, by Veovis
return

WriteFile(file,data)
{
   Handle :=  DllCall("CreateFile","str",file,"Uint",0x40000000
                  ,"Uint",0,"UInt",0,"UInt",4,"Uint",0,"UInt",0)
   Loop
   { 
     if strlen(data) = 0
        break
     StringLeft, Hex, data, 2         
     StringTrimLeft, data, data, 2  
     Hex = 0x%Hex%
     DllCall("WriteFile","UInt", Handle,"UChar *", Hex
     ,"UInt",1,"UInt *",UnusedVariable,"UInt",0) 
    } 
  
   DllCall("CloseHandle", "Uint", Handle)
   return
}

definepicture:
picture =
( join
424d000000000000000036000000280000001800000018000000010018000000000000000000000000000000000000000000
00000000c9c7c77d99776eae646baa6068a75d64a45961a1565d9d525a9a4f57974b5394475091444d8d404a8a3d46873943
84363f81323c7e2e397b2b3677275f7d57c8c6c5e3dfe0e3dfe077af6f74b46b71b1686eae646baa6068a75d64a45961a156
5d9d525a9a4f57974b5394475091444d8d404a8a3d4687394384363f81323c7e2e397a2a3677273b742ec8c6c5e3dfe07aba
7277b76e74b46b71b1686ead6468a55d629e585f9c55609f555d9d525a9a4f56974b5394475091444d8c4048863b42803641
7f343f80323c7e2e397a2a3677275f7d57e3dfe07ebd767aba7277b76e74b46b6dab655e95554f7e475182495c975260a055
5d9d525a9a4f56974b5394474d8c4242793738682e396e2e3f7d333f81323c7e2e397a2a367727e3dfe081c0797ebd757aba
7277b76e73a96ba6bca3758a713c603655884c619f5761a1565d9d525a9a4f56974b578e4c9bb1974f694a2d54253d773243
84363f81323c7e2e397a2ae3dfe085c37d81c0797ebd757aba72d0e1ceffffffffffff5a725651814964a05964a45961a156
5d9d525a9a4fc7d9c4fffffff1f3f12849213e74334687394384363f81323c7e2ee3dfe088c68085c37d81c0797ebd75dae7
d8ffffffffffff677e6453834c67a35c68a75d64a45961a1565d9d52d3e1d0ffffffffffff294a224176364a8a3d46873943
84363f8132e3dfe08bc98388c68085c37d81c079dce9daffffffffffff687f6556864f6aa6606baa6068a75d64a45961a156
d3e1d1ffffffffffff2b4c244379384d8d40498a3c468739438436e3dfe08ecd878bc98388c68085c37dddebdbffffffffff
ff677c644d78475f9558639b5a639d58629f58619f57d4e2d2ffffffffffff2c4e27467c3c5090434d8d40498a3c468739e3
dfe091d08b8ecd878bc98388c680c5dec2ffffffffffff62756038563442673d4870424b77454f7e47518449d2ddd0ffffff
ffffff2e4f29487f3f5394475090434d8d40498a3ce3dfe095d38e91d08b8ecd878bc983bedbbaffffffffffffffffffcbd1
cab1bab097a49564796159715534532fccd3caffffffffffff30512a4c814256974b5394475090434d8d40e3dfe098d69295
d38e91d08a8ecd87bfdcbcffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff31512b
4d82445a994f56974b539447509043e3dfe09cda9698d69295d38e91d08ac1debeffffffffffffdadfdaffffffffffffffff
ffffffffffffffffffffffffffffffffffffff31502c4d80445b9a505a9a4f56974b539447e3dfe09fdd999bd99598d69295
d38ec2dfbfffffffffffff6f856d64945e8cc085a4ce9ebad8b5c9dfc6dae8d8f5f8f4ffffffffffff4b66474d7e445d9a52
5d9d525a9a4e56974be3dfe0a2e09d9fdd999bd99598d692c4e1c1ffffffffffff70866e6796617fbb7781c0797dbd757aba
7177b76ed8e6d6ffffffffffff657b614e7e46609e5660a0555d9d52599a4ee3dfe0a5e3a1a2e09d9fdd999bd995c5e2c3ff
ffffffffff72886f69986383be7b84c37c81c0797dbd757aba71dae8d8ffffffffffff667c6351814963a05864a45960a055
5d9d52e3dfe0a8e6a4a5e3a1a2e09d9fdd99c7e3c4ffffffffffff7389706b9b6686c17e88c68084c37c81c0797dbd75dbe9
d9ffffffffffff677d6352804a66a25b67a75c64a45960a055e3dfe0aceaa8a8e6a4a5e3a1a2e09dc9e6c7ffffffffffff75
8c736fa06a89c6828bc98388c68084c37c81c079cbe1c8ffffffffffff677d6452804a68a35e6baa6067a75c64a459e3dfe0
afedabaceaa8a8e6a4a5e3a0cdeacaffffffffffff85a1827cb1778ecc878ecc868bc98388c68084c37cb7d9b2ffffffffff
ff96ab935b8d546ca8636ead646baa6067a65ce3dfe0b2f0aeafedababe9a7a8e6a4c0eabcfffffff7faf692c08e8fc98993
d28d91d08a8ecc868bc98388c6808bc684f6faf6ffffff95ba906ea96573b26a71b0676dad636aaa60e3dfe0b6f3b2b2f0ae
afedababe9a7a8e6a4b4e6b0abe0a69cd9969ad89498d69294d38e91d08a8ecc868bc98388c68093ca8c97c9907bb97379b9
7077b76e73b36a70b0676dad63e3dfe0b9f6b5b6f3b2b2f0aeafedababe9a7a8e6a4a5e3a0a2e09c9fdd999bd99598d69294
d38e91d08a8ecc868bc98387c67f84c37c81c0797dbd757aba7176b66d73b36a7c9977e3dfe0b3e8b0b9f6b5b6f3b2b2f0ae
afedababe9a7a8e6a4a5e3a0a2e09c9fdd999bd99598d69294d38e91d08a8ecc868bc98387c67f84c37c81bf797dbc757ab9
7176ae6ec9c6c6e3dfe0cac7c7a0bc9db9f6b5b6f3b2b2f0aeafedababe9a7a8e6a4a5e3a0a2e09c9fdd999bd99598d69294
d38e91d08a8ecc868bc98387c67f84c27c81bf79819f7dc9c6c6e3dfe0e3dfe052804a68a35e6baa6067a75c64a459e3dfe0
e3dfe0e3dfe0ff657b614e7e46609e5660a0555d9d52599a4ee3dfe0e3dfe0e3dfe0e3dfe0e3dfe0e3dfe0d1cbc49fdd999b
d995c5e2c3ffffffffffff72886f69986383be7b84c37c81c0797dbd757aba71dae8d8ffffffffffff667c6351814963a058
64a45960a0555d9d52e3dfe0e3dfe0e3dfe0e3dfe0e3dfe0e3dfe0d1cbc4a2e09d9fdd99c7e3c4ffffffffffff7389706b9b
6686c17e88c68084c37c81c0797dbd75dbe9d9ffffffffffff677d6352804a66a25b67a75c64a45960a055e3dfe0e3dfe0e3
dfe0e3dfe0e3dfe0e3dfe0d1cbc4a5e3a1a2e09dc9e6c7ffffffffffff758c736fa06a89c6828bc98388c68084c37c81c079
cbe1c8ffffffffffff677d6452804a68a35e6baa6067a75c64a459e3dfe0e3dfe0e3dfe0e3dfe0e3dfe0e3dfe0d1cbc4a8e6
a4a5e3a0cdeacaffffffffffff85a1827cb1778ecc878ecc868bc98388c68084c37cb7d9b2ffffffffffff96ab935b8d546c
a8636ead646baa6067a65ce3dfe0e3dfe0e3dfe0e3dfe0e3dfe0e3dfe0d1cbc4abe9a7a8e6a4c0eabcfffffff7faf692c08e
8fc98993d28d91d08a8ecc868bc98388c6808bc684f6faf6ffffff95ba906ea96573b26a71b0676dad636aaa60e3dfe0e3df
e0e3dfe0e3dfe0e3dfe0e3dfe0d1cbc4afedababe9a7a8e6a4b4e6b0abe0a69cd9969ad89498d69294d38e91d08a8ecc868b
c98388c68093ca8c97c9907bb97379b97077b76e73b36a70b0676dad63e3dfe0e3dfe0e3dfe0e3dfe0e3dfe0e3dfe0d1cbc4
b2f0aeafedababe9a7a8e6a4a5e3a0a2e09c9fdd999bd99598d69294d38e91d08a8ecc868bc98387c67f84c37c81c0797dbd
757aba7176b66d73b36a7c9977e3dfe0e3dfe0e3dfe0e3dfe0e3dfe0e3dfe0d1cbc4b6f3b2b2f0aeafedababe9a7a8e6a4a5
e3a0a2e09c9fdd999bd99598d69294d38e91d08a8ecc868bc98387c67f84c37c81bf797dbc757ab97176ae6ec9c6c6e3dfe0
e3dfe0e3dfe0e3dfe0e3dfe0e3dfe0d1cbc4b9f6b5b6f3b2b2f0aeafedababe9a7a8e6a4a5e3a0a2e09c9fdd999bd99598d6
9294d38e91d08a8ecc868bc98387c67f84c27c81bf79819f7dc9c6c6e3dfe0e3dfe0e3dfe0e3dfe0e3dfe0e3dfe0e3dfe0d1
cbc4cbc4b9f6b5b6f3b2b2f0aeafedababe9a7a8e6a4a5e3a0a2e09c9fdd999bd99598d69294d38e91d08a8ecc868bc98387
c67f84c37c81bf797dbc757ab97176ae6ec9c6c6e3dfe0e3dfe0e3dfe0e3dfe0e3dfe0e3dfe0d1cbc4d1cbc4a0bc9db9f6b5
b6f3b2b2f0aeafedababe9a7a8e6a4a5e3a0a2e09c9fdd999bd99598d69294d38e91d08a8ecc868bc98387c67f84c27c81bf
79819f7dc9c6c6e3dfe0e3dfe0e3dfe0e3dfe0e3dfe0e3dfe0e3dfe0d1cbc4d1cbc4
)
return

guiclose:
exitapp


An an easy way to retrieve the data from a bmp file:
Posted Image

gui, add, edit, w400 vFile,
gui, add, button, w100 gOpen x+10,Open File
gui, add, edit, r40 w510 vOutput xm
gui, show

Open:
gui, submit, nohide
BinRead(file,data)
Bin2Hex(h,data,res)
guicontrol,,output,%h%
return

Bin2Hex(ByRef h, ByRef b, n=0)      ; n bytes binary data -> stream of 2-digit hex
{                                   ; n = 0: all (SetCapacity can be larger than used!)
   format = %A_FormatInteger%       ; save original integer format
   SetFormat Integer, Hex           ; for converting bytes to hex

   m := VarSetCapacity(b)
   If (n < 1 or n > m)
       n := m
   Address := &b
   h =
   Loop %n%
   {
      x := *Address                 ; get byte in hex
      StringTrimLeft x, x, 2        ; remove 0x
      x = 0%x%                      ; pad left
      StringRight x, x, 2           ; 2 hex digits
      h = %h%%x%
      Address++
   }
   SetFormat Integer, %format%      ; restore original format
}

BinRead(file, ByRef data, n=0, offset=0)
{
   h := DllCall("CreateFile","Str",file,"Uint",0x80000000,"Uint",3,"UInt",0,"UInt",3,"Uint",0,"UInt",0)
   IfEqual h,-1, SetEnv, ErrorLevel, -1
   IfNotEqual ErrorLevel,0,Return,0 ; couldn't open the file

   m = 0                            ; seek to offset
   IfLess offset,0, SetEnv,m,2
   r := DllCall("SetFilePointerEx","Uint",h,"Int64",offset,"UInt *",p,"Int",m)
   IfEqual r,0, SetEnv, ErrorLevel, -3
   IfNotEqual ErrorLevel,0, {
      t = %ErrorLevel%              ; save ErrorLevel to be returned
      DllCall("CloseHandle", "Uint", h)
      ErrorLevel = %t%              ; return seek error
      Return 0
   }

   m := DllCall("GetFileSize","UInt",h,"Int64 *",r)
   If (n < 1 or n > m)
       n := m
   Granted := VarSetCapacity(data, n, 0)
   IfLess Granted,%n%, {
      ErrorLevel = Mem=%Granted%
      Return 0
   }

   result := DllCall("ReadFile","UInt",h,"Str",data,"UInt",n,"UInt *",Read,"UInt",0)

   if (!result or Read < n)
       t = -3
   IfNotEqual ErrorLevel,0, SetEnv,t,%ErrorLevel%

   h := DllCall("CloseHandle", "Uint", h)
   IfEqual h,-1, SetEnv, ErrorLevel, -2
   IfNotEqual t,,SetEnv, ErrorLevel, %t%-%ErrorLevel%

   Return Read
}


I hope you all enjoy, and please give me feedback!
One thing im curious of is if its possible to compress the raw hex data of the picture.


Posted Image
"Power can be given overnight, but responsibility must be taught. Long years go into its making."

SKAN
  • Administrators
  • 9115 posts
  • Last active:
  • Joined: 26 Dec 2005
Nice work Veovis! :)

One thing im curious of is if its possible to compress the raw hex data of the picture.


Oh Yes! This has already been done by ... who else ... The mighty PhiLho :D.

A new encoding of binary files: pebwa! - Plain Encoding of Binary data to Windows Ansi.

Idea: How about creating a fully text based Installer script.. no binary! Just a single lloo...nngg text file!

Regards, :)
kWo4Lk1.png

Chris
  • Administrators
  • 10727 posts
  • Last active:
  • Joined: 02 Mar 2004
Great posts!

Laszlo
  • Moderators
  • 4713 posts
  • Last active: Mar 31 2012 03:17 AM
  • Joined: 14 Feb 2005
Nice idea! If you use base64 encoding (see here, you can save some space and time, and still be standard conform. With base 85, 128 etc. further insignificant memory savings are possible, but the data will be nonstandard. If you email a bitmap to yourself, you get the image converted to Base64, so you just copy and paste it to the script. Also, after converting the image to binary, you don't need the original, so the variable storing the encoded image can be erased and reused.

Laszlo
  • Moderators
  • 4713 posts
  • Last active: Mar 31 2012 03:17 AM
  • Joined: 14 Feb 2005
Here is a very simple script for compressing hex bitmaps of 256 colors. Often the same color repeats in many pixels in a raw. We count them, and keep only the first byte (2 hex digits), and attach the repetition count between pipe symbols "|".
Loop Parse, picture        ; COMPRESS
{
   If (A_Index & 1) {      ; Odd index...
      x = %A_LoopField%    ; Save first digit
      Continue             
   }                       ; Even index...
   x = %x%%A_LoopField%    ; Reconstruct byte
   IfEqual x,%p%, {        ; Repetition found
      c++                  ; ... this many times
      Continue             
   }                       ; Different byte...
   IfNotEqual c,, {        ; Prev was repeated
      o = %o%|%c%|         ; Append count
      c =                  ; Reset counter
  }                        ; Prev was single...
  p = %x%                  ; Save current
  o = %o%%x%               ; Attach current to output
}
IfNotEqual c,, SetEnv o,%o%|%c%| ; Append final count

MsgBox %o%

Loop Parse, o, |           ; DECOMPRESS
{
   If (A_Index & 1) {      ; Odd index...
      t = %t%%A_LoopField% ; Copy block to output
      Continue
   }                       ; Even index...
   StringRight r, t, 2     ; Get last byte
   Loop %A_LoopField%      ; Duplicate as needed
      t = %t%%r%
}

MsgBox %t%
MsgBox % StrLen(picture) " / " StrLen(o) " / " StrLen(t) "`nEqual = " (picture=t)
For test, copy over the picture assignment from the first post in this thread.

If the picture has fewer colors (16 or less), single hex digits have to be searched for repetition. If the picture has 64K colors, use 4 hex digits at a time, for 24-bit color, search blocks of 6 hex digits for repetition.

Laszlo
  • Moderators
  • 4713 posts
  • Last active: Mar 31 2012 03:17 AM
  • Joined: 14 Feb 2005
...also, the real work of the Bin2Hex function can be "compressed" into three lines:
Bin2Hex(ByRef b, n=0)            ; n bytes binary data -> stream of 2-digit hex

{                                ; n = 0: all (SetCapacity can be larger than used!)

   format = %A_FormatInteger%    ; save original integer format

   SetFormat Integer, Hex        ; for converting bytes to hex



   m := VarSetCapacity(b)

   If n not between 1 and %m%    ; invalid length -> all allocated

       n = %m%

   Loop %n%

      h := h 256+*(&b+A_Index-1) ; concatenate  0x1xx

   StringReplace h, h, 0x1,,All  ; remove every 0x1



   SetFormat Integer, %format%   ; restore original format

   Return h

}


SKAN
  • Administrators
  • 9115 posts
  • Last active:
  • Joined: 26 Dec 2005
Dear Laszlo, :)

I am yet to try the code posted by you ..

Meanwhile -

Will it require a tough algorithm for converting a 32x32 256 Color bitmap to GreyScale?
.
.
.
if this is possible at all?

Regards, :)
kWo4Lk1.png

Laszlo
  • Moderators
  • 4713 posts
  • Last active: Mar 31 2012 03:17 AM
  • Joined: 14 Feb 2005
I think 256-color pictures include a palette, which lists the colors appearing in the picture, and they will be only referenced. If it was true, we have to create another palette, with the brightness values of the first one, and replace the bytes in the picture referencing the palette with the values in the second palette. It looks easy, once we know the data layout.

On the other hand, this conversion can be done lightning fast with many free utilities, like IrfanView, which can be controlled with command line parameters, so a single AHK run command suffices. If you want to distribute a single script, you can do it with MS Paint, which is normally installed with Windows.

SKAN
  • Administrators
  • 9115 posts
  • Last active:
  • Joined: 26 Dec 2005
Dear Laszlo, :)

Many thanks for the answer..

This idea was a part of my original idea of enabling some animation for a script's tray icon. This can be done with a timer and a series of semi-identical icons, but I thought manipulating a single image would be great.

Regards, :)
kWo4Lk1.png

Laszlo
  • Moderators
  • 4713 posts
  • Last active: Mar 31 2012 03:17 AM
  • Joined: 14 Feb 2005

some animation for a script's tray icon. This can be done with a timer and a series of semi-identical icons, but I thought manipulating a single image would be great.

This is what you mean (for 32x32 bmp icon)?
SetBatchLines -1

p =
( join
424d360800000000000036040000280000002000000020000000010008000000
0000000400000000000000000000000100000000000004020400949294000402
bc003436f40034363c00ccd2d4000402fc0000000000df017000da006d00d400
170077000000001c780000e86d000012170000000000c23478000787040018d4
000000770000013c54000009e600001b12000000000000823c00000009000000
1b000000000000003c000000e7000000120000000000000018000000ee000000
900000007c00644f7000e9e5050012d6910000777c00e302ff00ea00ff009000
ff007c00000018010000e9000000120000000000000018000000000000000000
000000000000588493009be819007f12910000007c008274000000d0000000d4
23000077000000d97800008b010000d41600007700000000380000f00c0000fd
0000007f00004f840000e5e80000d612160077000000745a2800e988e50012d4
120000770000b7441700b7e89c009112d4007c007700d52a6800b788e90091d4
12007c770000780018006d00ee001700900000007c00103c90000009b600ab1b
910000007c00e000ff003000ff008800ff007c00ff00a01486007900b6001700
910000007c00000198000000b2000000910000007c0000000000000000000000
160000000000700009006d00030017001000000000000010eb00000006001600
910000007c00120100009f0000000100000000000000780010006d0000001700
ab00000000000001e000000030001600880000007c0080000000e90000001200
0000000000000000b4000000e900000012000000000000384d0000e89d001612
d400000077008c007000e90002001200da0000007700abc8020037e87f009112
00007c000000c76788003704e70091d712007c770000083057000688080016d4
e3000077000010ff230000ff0400abff000000ff0000002a600000889d0000d4
d4000077770000c0000000b4000000d4000000770000c8000100e90000001200
000000000000fd4f000000e5000081d600007c770000053c000001090000811b
00007c000000a082000079000000170000000000000082007000000002008100
da007c0077000000020000007f000000000000000000106c0000009b0000ab7f
d4000000770009cb3c0003b4090000d41b000077000001c23c00000709000018
1b000000000098185000e9e960001212340000000000f800d000f700e7001200
120000000000f8002300f70036001204d70000005a00f3003c00990009008300
1b007c00000008ac010001e80000811200007c000000ff700000ff360000ff9b
0000ff12000005f8000001f70000811200007c000000d4673c000104090042d7
1b0000770000b0d04f00edb4e50016d4d600007777002fff2900feff4e0080ff
d7007cff5a0082cb3c0000b4090081d41b007c77000058bd0200d6da0000d4d4
0000777700008b584f00149be500d67fd6007700770001010000000000000000
0000000000000000000000000000000000000000000001010000000000000000
0000000000000000000000000000000000000000000005050505050505050505
0400000405050505040000040505050505050505000005050505050505050505
0000000005050505000000000505050505050505000005050505050505050306
0602000005050306060200000505050505050505000005050505050505050606
0606000005050606060600000505050505050505000005050505050504000606
0606000000000606060600000000000000040505000005050505050500000606
0606000000000606060600000000000000000505000005050505030606060606
0606060606060606060606060606060200000505000005050505060606060606
0606060606060606060606060606060600040505000005050505060606060606
0606060606060606060606060606060605050505000005050505030606060606
0606060606060606060606060606060305050505000005050505050505050606
0606000005050606060600000505050505050505000005050505050505050606
0606000405050606060600000505050505050505000005050505050505050606
0606050505050606060600000505050505050505000005050505050505050306
0603050505050606060600000505050505050505000005050505050505050505
0505050505050606060600000505050505050505000005050505050505050505
0505050505050606060600000505050505050505000005050505050505050505
0505050505050606060600000505050505050505000005050505050505050505
0505050505050606060600000505050505050505000005050505050505050505
0505050505050606060600000505050505050505000005050505050505050505
0505050505050606060600000505050505050505000005050505050505050505
0505050505050606060600000505050505050505000005050505050505050505
0505050505050606060600000505050505050505000005050505050505050505
0505050505050606060600000505050505050505000005050505050505050505
0505050505050606060600000505050505050505000005050505050505050505
0505050505050606060600000505050505050505000005050505050505050505
0505050505050606060600040505050505050505000005050505050505050505
0505050505050606060605050505050505050505000005050505050505050505
0505050505050306060305050505050505050505000005050505050505050505
0505050505050505050505050505050505050505010105050505050505050505
05050505050505050505050505050505050505050101
)

file = %A_ScriptDir%\LH.bmp

Loop {
   WriteFile(file,p)
   Menu Tray, Icon, %file%
   StringRight k, p, 2048
   StringTrimRight p, p, 2048
   StringRight r, k, 64
   StringTrimRight k, k, 64
   p = %p%%r%%k%
   Sleep 50
}

WriteFile(file,data)
{
   H:=DllCall("CreateFile",Str,file, Uint,0x40000000, Uint,0, UInt,0, UInt,4, Uint,0, UInt,0)
   Loop Parse, data
      If (A_Index & 1)
         hex = 0x%A_LoopField%
      Else {
         hex = %hex%%A_LoopField%
         DllCall("WriteFile",UInt,H, UCharP,Hex, UInt,1, UIntP,U, UInt,0)
      }
   DllCall("CloseHandle",Uint,H)
}
It is only a proof of concept. It could be much faster to read binary from the appropriate offset, and write pieces back to file.

SKAN
  • Administrators
  • 9115 posts
  • Last active:
  • Joined: 26 Dec 2005
:D :D :D :D

Excellent effect!

Thanks for demonstrating with an example.
Please edit your post to have a bold heading like: Animated Tray Icon - Example.

All the code you have provided will keep me very busy.. Thanks again :D

Regards, :)
kWo4Lk1.png

Laszlo
  • Moderators
  • 4713 posts
  • Last active: Mar 31 2012 03:17 AM
  • Joined: 14 Feb 2005

It could be much faster to read binary from the appropriate offset, and write pieces back to file.

This is what I meant (using the same p value as before):
file = %A_ScriptDir%\LH.bmp

HexWrite(file,p)

L := StrLen(p)//2



Loop {

   Menu Tray, Icon, %file%

   BinRead(file, D1, 992, -1024)

   BinRead(file, D2, 32, -32)

   BinWrite(file, D2, 32, -1024)

   BinWrite(file, D1, 992, -992)

   Sleep 50

}



HexWrite(file,data)

{

   H:=DllCall("CreateFile",Str,file, Uint,0x40000000, Uint,0, UInt,0, UInt,4, Uint,0, UInt,0)

   Loop Parse, data

      If (A_Index & 1)

         hex = 0x%A_LoopField%

      Else {

         hex = %hex%%A_LoopField%

         DllCall("WriteFile",UInt,H, UCharP,Hex, UInt,1, UIntP,U, UInt,0)

      }

   DllCall("CloseHandle",Uint,H)

}



BinWrite(file, ByRef data, n=0, offset=0)

{

   h := DllCall("CreateFile",Str,file,UInt,0x40000000,UInt,0,UInt,0,UInt,4,UInt,0,UInt,0)

   m = 0

   IfLess offset,0, SetEnv,m,2

   r := DllCall("SetFilePointerEx",UInt,h,Int64,offset,UIntP,p,Int,m)

   m := VarSetCapacity(data)

   If (n < 1 or n > m)

       n := m

   DllCall("WriteFile",UInt,h,Str,data,UInt,n,UIntP,W,UInt,0)

   DllCall("CloseHandle", UInt, h)

}



BinRead(file, ByRef data, n=0, offset=0)

{

   h := DllCall("CreateFile",Str,file,UInt,0x80000000,UInt,3,UInt,0,UInt,3,UInt,0,UInt,0)

   m = 0

   IfLess offset,0, SetEnv,m,2

   r := DllCall("SetFilePointerEx",UInt,h,Int64,offset,UIntP,p,Int,m)

   m := DllCall("GetFileSize",UInt,h,Int64P,r)

   If (n < 1 or n > m)

       n := m

   VarSetCapacity(data, n, 0)

   DllCall("ReadFile",UInt,h,Str,data,UInt,n,UIntP,Read,UInt,0)

   DllCall("CloseHandle", UInt, h)

}


Veovis
  • Members
  • 389 posts
  • Last active: Mar 17 2009 12:24 AM
  • Joined: 13 Feb 2006
An update: I'm pretty sure that we can encode anyfile that we want. PhiLho did an ico, and i tried a jpg yesterday. So i will try to include things like dlls, and exes a little later today.

I want to make some kind of function or maybe a GUI that allows less knowledgable users to feed it a file and it will BinRead the file, Pebwa the file, then divide it into reasonably long lines and give them somethine like
file = 
( join
blah blahb albhlbalbhalab hlahb abl
alalbahlbahblhabhall lbah balh balb
albhlhabbhla balhbalbha abl abfb bl
.... etc.
)
and then give them a chunck of code with all the BinWrite and Pebwa and Bin2Hex and Quantity functions they need to past at the bottem of their script for everything to work right.

Also i tried experimenting with the Pebwa functions...and i guess im not smart enough cause i cant quite figure then out all the way... I was able to compress a string but i couldnt get it uncompressed.

Heres the code:
string := "fa789cdbe87912bde8ca8ecd"
msgbox, % "string to encode:`n'" string "'`nlength:" strlen(string)
hex2bin(bin,string)
len := Bin2Pebwa(data,bin)
msgbox, % "encoded string:`n'" data "'`nlength:" strlen(data)
len := Pebwa2Bin(out,data)
msgbox, % "decoded string:`n'" out "'`nlength:" strlen(out)

Bin2Pebwa(ByRef @pebwa, ByRef @bin, _byteNb=0)
{
...
}

Pebwa2Bin(ByRef @bin, _pebwa)
{
...
}

PEBWA_QTY_BASE = 188
PEBWA_MAX_LOWER_QTY = 93
PEBWA_LOW_QTY_OFFSET = 33
PEBWA_HIGH_QTY_OFFSET = 67

EncodeQuantity(_quantity)
{
...
}

DecodeQuantity(_quantity)
{
...
}

Bin2Hex(ByRef @hex, ByRef @bin, _byteNb=0)
{
...
}

Hex2Bin(ByRef @bin, _hex, _byteNb=0)
{
...
}

Posted Image
"Power can be given overnight, but responsibility must be taught. Long years go into its making."

SKAN
  • Administrators
  • 9115 posts
  • Last active:
  • Joined: 26 Dec 2005

This is what I meant:


BMP File I tried with : LH.BMP

:D :shock: :D :shock:

Animation is much more smoother
I do not see any CPU Usage at all! :shock:.
( Previous version was showing usage about 68-72 !!! )

Thank you very much ..

Regards, :)
kWo4Lk1.png

corrupt
  • Members
  • 2558 posts
  • Last active: Nov 01 2014 03:23 PM
  • Joined: 29 Dec 2004
Cool :!: Thanks :)
SetBatchLines -1 

Gui, Add, Text,, Interesting... Thanks :)
Gui, Add, Button, gB1,Stop/Start Animation
Gui, Show, w200 h200

Gosub, Init
file = %A_ScriptDir%\LH.bmp 
SetTimer, AnimateIcon, 50
Return

B1:
If (!TimerOn)
  SetTimer, AnimateIcon, Off
Else 
  SetTimer, AnimateIcon, 50
TimerOn := !TimerOn
Return

AnimateIcon: 
WriteFile(file,p) 
Menu Tray, Icon, %file% 
StringRight k, p, 2048 
StringTrimRight p, p, 2048 
StringRight r, k, 64 
StringTrimRight k, k, 64 
p = %p%%r%%k% 
Return

WriteFile(file,data) 
{ 
   H:=DllCall("CreateFile",Str,file, Uint,0x40000000, Uint,0, UInt,0, UInt,4, Uint,0, UInt,0) 
   Loop Parse, data 
      If (A_Index & 1) 
         hex = 0x%A_LoopField% 
      Else { 
         hex = %hex%%A_LoopField% 
         DllCall("WriteFile",UInt,H, UCharP,Hex, UInt,1, UIntP,U, UInt,0) 
      } 
   DllCall("CloseHandle",Uint,H) 
}

GuiClose: 
ExitApp

Init:
p = 
( join 
424d360800000000000036040000280000002000000020000000010008000000 
0000000400000000000000000000000100000000000004020400949294000402 
bc003436f40034363c00ccd2d4000402fc0000000000df017000da006d00d400 
170077000000001c780000e86d000012170000000000c23478000787040018d4 
000000770000013c54000009e600001b12000000000000823c00000009000000 
1b000000000000003c000000e7000000120000000000000018000000ee000000 
900000007c00644f7000e9e5050012d6910000777c00e302ff00ea00ff009000 
ff007c00000018010000e9000000120000000000000018000000000000000000 
000000000000588493009be819007f12910000007c008274000000d0000000d4 
23000077000000d97800008b010000d41600007700000000380000f00c0000fd 
0000007f00004f840000e5e80000d612160077000000745a2800e988e50012d4 
120000770000b7441700b7e89c009112d4007c007700d52a6800b788e90091d4 
12007c770000780018006d00ee001700900000007c00103c90000009b600ab1b 
910000007c00e000ff003000ff008800ff007c00ff00a01486007900b6001700 
910000007c00000198000000b2000000910000007c0000000000000000000000 
160000000000700009006d00030017001000000000000010eb00000006001600 
910000007c00120100009f0000000100000000000000780010006d0000001700 
ab00000000000001e000000030001600880000007c0080000000e90000001200 
0000000000000000b4000000e900000012000000000000384d0000e89d001612 
d400000077008c007000e90002001200da0000007700abc8020037e87f009112 
00007c000000c76788003704e70091d712007c770000083057000688080016d4 
e3000077000010ff230000ff0400abff000000ff0000002a600000889d0000d4 
d4000077770000c0000000b4000000d4000000770000c8000100e90000001200 
000000000000fd4f000000e5000081d600007c770000053c000001090000811b 
00007c000000a082000079000000170000000000000082007000000002008100 
da007c0077000000020000007f000000000000000000106c0000009b0000ab7f 
d4000000770009cb3c0003b4090000d41b000077000001c23c00000709000018 
1b000000000098185000e9e960001212340000000000f800d000f700e7001200 
120000000000f8002300f70036001204d70000005a00f3003c00990009008300 
1b007c00000008ac010001e80000811200007c000000ff700000ff360000ff9b 
0000ff12000005f8000001f70000811200007c000000d4673c000104090042d7 
1b0000770000b0d04f00edb4e50016d4d600007777002fff2900feff4e0080ff 
d7007cff5a0082cb3c0000b4090081d41b007c77000058bd0200d6da0000d4d4 
0000777700008b584f00149be500d67fd6007700770001010000000000000000 
0000000000000000000000000000000000000000000001010000000000000000 
0000000000000000000000000000000000000000000005050505050505050505 
0400000405050505040000040505050505050505000005050505050505050505 
0000000005050505000000000505050505050505000005050505050505050306 
0602000005050306060200000505050505050505000005050505050505050606 
0606000005050606060600000505050505050505000005050505050504000606 
0606000000000606060600000000000000040505000005050505050500000606 
0606000000000606060600000000000000000505000005050505030606060606 
0606060606060606060606060606060200000505000005050505060606060606 
0606060606060606060606060606060600040505000005050505060606060606 
0606060606060606060606060606060605050505000005050505030606060606 
0606060606060606060606060606060305050505000005050505050505050606 
0606000005050606060600000505050505050505000005050505050505050606 
0606000405050606060600000505050505050505000005050505050505050606 
0606050505050606060600000505050505050505000005050505050505050306 
0603050505050606060600000505050505050505000005050505050505050505 
0505050505050606060600000505050505050505000005050505050505050505 
0505050505050606060600000505050505050505000005050505050505050505 
0505050505050606060600000505050505050505000005050505050505050505 
0505050505050606060600000505050505050505000005050505050505050505 
0505050505050606060600000505050505050505000005050505050505050505 
0505050505050606060600000505050505050505000005050505050505050505 
0505050505050606060600000505050505050505000005050505050505050505 
0505050505050606060600000505050505050505000005050505050505050505 
0505050505050606060600000505050505050505000005050505050505050505 
0505050505050606060600000505050505050505000005050505050505050505 
0505050505050606060600000505050505050505000005050505050505050505 
0505050505050606060600040505050505050505000005050505050505050505 
0505050505050606060605050505050505050505000005050505050505050505 
0505050505050306060305050505050505050505000005050505050505050505 
0505050505050505050505050505050505050505010105050505050505050505 
05050505050505050505050505050505050505050101 
) 
Return