AutoHotkey Community

It is currently May 27th, 2012, 10:34 am

All times are UTC [ DST ]




Post new topic Reply to topic  [ 53 posts ]  Go to page 1, 2, 3, 4  Next
Author Message
PostPosted: November 26th, 2007, 9:57 pm 
Offline

Joined: April 22nd, 2007, 6:33 pm
Posts: 1833
This script will create compatible icons to be used as tray icons or as pictures, showing bars in specified sizes, to be used as an updatable bar graph. Values may be added or shifted. Thanks to Laszlo for machine code binary write.

http://www.autohotkey.net/~tic/tic-MakeICOBars-1.10.zip

Usage is:

Code:
MakeICOBars(Numbers, Colours, FileName, BGColour, BGOpacity)


Example scripts are included in the zip. The function may be used as follows:

Code:
MakeICOBars("25|75", "000000", "BlackBars.ico", "000000", 100)      ; Create 2 bars. Both will be black. The background will also be black, but at opacity 100 out of 255 and will be saved to BlackBars.ico
MakeICOBars("25|50|75", "ff0000|00ff00|0000ff", "3Bars.ico", "ffffff", 25)    ; Create 3 bars in the colours red, green, blue respectively and have a partially visible white background saved into 3Bars.ico
MakeICOBars("<25", "ff0000", "Shift.ico") ; Shift previous call by 1 bar to the left, and add a new bar at 25 height on the right
MakeICOBars(">25|50", "ff0000|00ff00", "Shift.ico") ; Shift previous call by 2 bars to the right, and add 2 new bar at 25 and 50 height on the left
MakeICOBars("-25", "ff0000", "AddLeft.ico") ; Add new bar at 25 height to the left hand side
MakeICOBars("+50|75", "0000ff", "AddRight.ico") ; Add new bars at 50 and 75 height to the right hand side, both blue


Last edited by tic on January 17th, 2008, 5:17 am, edited 5 times in total.

Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: November 26th, 2007, 10:02 pm 
Offline

Joined: April 22nd, 2007, 6:33 pm
Posts: 1833
Ive found a bug with setting the background transparency below 15 (0x0f) but that will be very easy to fix. Ill do it when Im back later. In a rush out... :)

Edit: Had time to fix it and upload. Byee


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: November 26th, 2007, 11:04 pm 
Offline

Joined: May 24th, 2006, 2:49 pm
Posts: 4511
Location: Belgrade
This really rocks!!!

Thanks

What about histogram ?

_________________
Image


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: November 27th, 2007, 12:40 am 
Offline

Joined: April 22nd, 2007, 6:33 pm
Posts: 1833
I only looked at what a picture of a histogram looks like. whats the difference between it and a bar graph (sorry...cant be bothered to read ;))


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: November 27th, 2007, 12:42 am 
Offline

Joined: February 14th, 2005, 4:05 pm
Posts: 4710
Location: Boulder, CO
Histogram is a special bar graph. I think Majkinetor meant line graphs, like function curves.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: November 27th, 2007, 12:50 am 
Offline

Joined: April 22nd, 2007, 6:33 pm
Posts: 1833
Laszlo wrote:
Histogram is a special bar graph. I think Majkinetor meant line graphs, like function curves.


Heh. That will be more tricky (and slower) as antialising will be needed for lines or curves, so will be a bit annoying. i could definitely do it, but is it really needed? :D


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: November 27th, 2007, 12:56 am 
Offline

Joined: May 24th, 2006, 2:49 pm
Posts: 4511
Location: Belgrade
Quote:
I think Majkinetor meant line graphs, like function curves.

Yup. Sorry if I mistaked the therm. Its on the picture.


BTW, maybe you can see to optimise function later a bit. This code takes 15% CPU

Code:
loop, 50 {
   Sleep 500
   TrayHistogram(A_Index*2 "|" A_Index*4, "00ff00|0000ff", "ff0000", 0)
}


2 seconds sleep takes is 3.65% and 1s = 8% measuring on Intel 2.8Ghz

Common scenario for using this function will probably fall in 1s - 2s.

Other then that, I played with it for some time, and it really looks great, especialy with full opacity.

_________________
Image


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: November 27th, 2007, 12:58 am 
Offline

Joined: February 14th, 2005, 4:05 pm
Posts: 4710
Location: Boulder, CO
@tic: They will definitely look cool, as in maj’s screenshot in your other thread. A running CPU load curve, or Internet speed variations always visible in the lower right corner, but even stock prices are useful. If they are “really needed”? No. We can live long and prosper w/o them, but you could give us some fun toys…


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: November 27th, 2007, 1:03 am 
Offline

Joined: April 22nd, 2007, 6:33 pm
Posts: 1833
On my amd64 4000 @ 3.1GHz it never uses more than 10% with 500ms sleep.

I can optimise it speed wise a lot more but it will take up much more space. Is that a good trade off for you guys? In my example I genereally tended for lower size over faster speed. If you want speed and dont care so much about ram or the size of the script, i could make it much faster!


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: November 27th, 2007, 1:05 am 
Offline

Joined: February 14th, 2005, 4:05 pm
Posts: 4710
Location: Boulder, CO
Need for speed: when the functions get to their final form, we might be able to replace the loops with machine code functions. If you could keep those loops simple and separated from the more complex actions, the result could be fast and not too large. (Anything more than 1 or 2% CPU load is already too slow.)


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: November 27th, 2007, 2:37 am 
Offline

Joined: April 22nd, 2007, 6:33 pm
Posts: 1833
Ive just spent the last 40 minutes cutting the time down, and found it wasnt making much of a difference. Using strategic A_TickCounts I found the answer. You may not like it....

My code doesnt really need to be optimised. The entirity of my code actually only takes 5-22% of the time of the whole function. All the loops perform very quickly. On average 85% of the time is passed in the binwrite section at the end, and I only used the necessary parts. If you can speed that up, then the whole function will also speed up.

Code:
   Time1 := A_TickCount
   h := DllCall("CreateFile", "Str", "TrayHist.ico", "Uint", 0x40000000, "Uint", 0, "UInt", 0, "UInt", 4, "Uint", 0, "UInt", 0)
   r := DllCall("SetFilePointerEx","Uint",h,"Int64",offset,"UInt *",p,"Int",0)
   
   TotalWritten = 0
   m := Ceil(StrLen(Icon)/2)
   n := m
   Loop %n%
   {
      StringLeft c, Icon, 2         ; extract next byte
      StringTrimLeft Icon, Icon, 2  ; remove  used byte
      c = 0x%c%                     ; make it number
      Result := DllCall("WriteFile","UInt",h,"UChar *",c,"UInt",1,"UInt *",Written,"UInt",0)
      TotalWritten += Written       ; count written
      If (!result or Written < 1 or ErrorLevel)
      Break
   }
   h := DllCall("CloseHandle", "Uint", h)
   
   MsgBox, % A_TickCount - Time1
   Menu, Tray, Icon, TrayHist.ico
   FileDelete, TrayHist.ico


Edit:

I managed to cut the time down from around 10000ms for 100 cycles (standard settings and 0ms extra sleep) down to 9000, and believe I can cut it down another 500-1000, but as Ive just said, all the remaining time is spent in the binwrite. Perhaps the hIcon would be faster, with Shell_NotifyIcon, if anyone wants to write some tester code for me to add:

http://msdn2.microsoft.com/en-us/library/aa922175.aspx

and gets the pointer structure for me:

http://msdn2.microsoft.com/en-us/library/aa930660.aspx


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: November 27th, 2007, 3:31 am 
Offline

Joined: April 22nd, 2007, 6:33 pm
Posts: 1833
Ive significantly sped up the binwrite function (obviously without the extra stuff thats not needed for this task)

Code:
   h := DllCall("CreateFile", "Str", "TrayHist.ico", "Uint", 0x40000000, "Uint", 0, "UInt", 0, "UInt", 4, "Uint", 0, "UInt", 0)
   
   Start := 1
   Loop % Ceil(StrLen(Icon)/2)
   {
      Result := DllCall("WriteFile", "UInt", h, "UChar *", "0x" . SubStr(Icon, Start, 2), "UInt", 1, "UInt *", Written, "UInt", 0)
      Start += 2
      If !Result
      Break
   }
   h := DllCall("CloseHandle", "Uint", h)


At the moment for 100 cycles it is down from 10300ms average to 7719ms. (Code not posted yet). Ill continue to try cutting the time of the fcuntion.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: November 27th, 2007, 4:07 am 
Offline

Joined: April 22nd, 2007, 6:33 pm
Posts: 1833
Ok the code is updated so that the user can choose the priority it will run at, thus the cpu usage


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: November 27th, 2007, 4:26 am 
Offline

Joined: February 14th, 2005, 4:05 pm
Posts: 4710
Location: Boulder, CO
The above code writes each byte separately to the icon file, after converting it from hex form to binary. This is very slow. One solution was to work on binary buffers with NumPut/NumGet (or even with *address, or with RtlFillMemory dll calls), and then you don’t need hex-to-binary conversions, but write the whole buffer to the icon file with one dll call.

Another possibility is to keep working on hex data, but use a machine code function to convert the resulting hex stream to binary buffer. (The other direction is already done in Bit Wizardry: convert binary data to hex stream.) This should speed up the above loop hundred fold, and again, you only need one dll call to WriteFile.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: November 27th, 2007, 4:38 am 
Offline

Joined: April 22nd, 2007, 6:33 pm
Posts: 1833
Well if you or someone else could write me the machine code for hex to binary it would be much appreciated.

Also, what exactly do you want me to make a new function to do? curves, lines etc? And how would you want the input for how the curve is drawn (Im not gonna say this is gonna be easy, especially with all the antialising it will need)


Report this post
Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 53 posts ]  Go to page 1, 2, 3, 4  Next

All times are UTC [ DST ]


Who is online

Users browsing this forum: Bing [Bot] and 10 guests


You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Powered by phpBB® Forum Software © phpBB Group