Sign in to follow this  
Followers 0
malu05

Fixing processing speed...

2 posts in this topic

Ok.

I made this program to view *.cws file Thumbnails.

Problem is that i seem to have made a big processing hole making the application damn slow.

The autoIt program reads the buttom of the *.cws file and replicates the data with "GuiCtrlCreateGraphic".

First here you can download a sample *.cws file;

http://files.filefront.com/cws_test_filera...;/fileinfo.html

And here is the code...

;CWS Thumbnail Viewer By Malu05
;Includes
#include <Array.au3>
#include <file.au3>
#include <GUIConstants.au3>
#include <string.au3>
#include <Color.au3>

;HotKey
HotkeySet("{ESC}","terminate")

;variables
Dim $bvalues[1]
Dim $DIF = "8.5"
dim $Cola[4]

;Initialize (select file)
$cwsfileloc = fileopendialog("Select CWS File",@DesktopDir, "Combustion Workspace (*.cws)", 1)

;Find Dimentions
Dim $aRecords, $afind = "TNInfo", $search = $cwsfileloc
If Not _FileReadToArray($search,$aRecords) Then
   MsgBox(4096,"Error", " Error reading log to Array     error:" & @error)
   Exit
EndIf
For $x = 1 to $aRecords[0]
    If StringInStr($aRecords[$x], $afind) Then 
    $avalues = StringSplit($aRecords[$x], " ")
    EndIf
Next

;Find Data
Dim $bRecords, $bfind = "TNData", $search = $cwsfileloc
If Not _FileReadToArray($search, $bRecords) Then
   MsgBox(4096,"Error", " Error reading log to Array     error:" & @error)
   Exit
EndIf
For $x = 1 to $bRecords[0]
    If StringInStr($bRecords[$x], $bfind) Then 
    _ArrayAdd( $bvalues,$bRecords[$x])
    EndIf
Next

;Split Color Data
;Msgbox(0,"Test", $test)
;Msgbox(0,"Test", $bvalues[2])

;Samplecode
$Hex = _ColorGetBlue (0xc0c0ff)
$Hex1 = _ColorGetRed (0xc0c0ff)
$Hex2 = _ColorGetGreen (0xc0c0ff)
$col = "0x" & Hex($Hex1, 2) & Hex($Hex2, 2) & Hex($Hex, 2)
CreateThumb()

;Draw Thumbnail 
Func CreateThumb()
$child=GUICreate("CWS Thumb",200,200)
$progressbar1 = GUICtrlCreateProgress (10,150,180,20)
$progressbar2 = GUICtrlCreateProgress (10,100,180,20)
GuiCtrlCreateGraphic(1, (1), ($avalues[2]), ($avalues[3]))
GUICtrlSetBkColor(-1,0x000000)
GUISetState (@SW_SHOW)


For $e = 1 to $avalues[3] Step +1
;$avalues[3] = hight
    $trashdata = 5
    For $i = 1 to $avalues[2] Step +1
    ;$avalues[2] = Width
        GUICtrlSetData ($progressbar1,($e/($avalues[3]/100)))
        GuiCtrlCreateGraphic($i, ($e), (2), (2))
        $trashdata = ($trashdata + 3)
        $test = StringMid($bvalues[$e], $trashdata, 10)
        $sepvalues = StringSplit($test, "")
            For $o = 1 to 3 Step +1
                GUICtrlSetData ($progressbar2,($i/($avalues[2]/100)))
                if $sepvalues[$o] = "0" then $Cola[$o] = 0  
                if $sepvalues[$o] = "1" then $Cola[$o] = $DIF
                if $sepvalues[$o] = "2" then $Cola[$o] = ($DIF *2)
                if $sepvalues[$o] = "3" then $Cola[$o] = ($DIF *3)
                if $sepvalues[$o] = "4" then $Cola[$o] = ($DIF *4)
                if $sepvalues[$o] = "5" then $Cola[$o] = ($DIF *5)
                if $sepvalues[$o] = "6" then $Cola[$o] = ($DIF *6)
                if $sepvalues[$o] = "7" then $Cola[$o] = ($DIF *7)
                if $sepvalues[$o] = "8" then $Cola[$o] = ($DIF *8)
                if $sepvalues[$o] = "9" then $Cola[$o] = ($DIF *9)
                if $sepvalues[$o] = ":" then $Cola[$o] = ($DIF *10)
                if $sepvalues[$o] = ";" then $Cola[$o] = ($DIF *11)
                if $sepvalues[$o] = "<" then $Cola[$o] = ($DIF *12)
                if $sepvalues[$o] = "=" then $Cola[$o] = ($DIF *13)
                if $sepvalues[$o] = "?" then $Cola[$o] = ($DIF *14)
                if $sepvalues[$o] = "@" then $Cola[$o] = ($DIF *15)
                if $sepvalues[$o] = "A" then $Cola[$o] = ($DIF *16)
                if $sepvalues[$o] = "B" then $Cola[$o] = ($DIF *17) 
                if $sepvalues[$o] = "C" then $Cola[$o] = ($DIF *18)
                if $sepvalues[$o] = "D" then $Cola[$o] = ($DIF *19)
                if $sepvalues[$o] = "E" then $Cola[$o] = ($DIF *20)
                if $sepvalues[$o] = "F" then $Cola[$o] = ($DIF *21)
                if $sepvalues[$o] = "G" then $Cola[$o] = ($DIF *22)
                if $sepvalues[$o] = "H" then $Cola[$o] = ($DIF *23)
                if $sepvalues[$o] = "I" then $Cola[$o] = ($DIF *24)
                if $sepvalues[$o] = "J" then $Cola[$o] = ($DIF *25)
                if $sepvalues[$o] = "K" then $Cola[$o] = ($DIF *26)
                if $sepvalues[$o] = "L" then $Cola[$o] = ($DIF *27)
                if $sepvalues[$o] = "M" then $Cola[$o] = ($DIF *28)
                if $sepvalues[$o] = "N" then $Cola[$o] = ($DIF *29)
                if $sepvalues[$o] = "O" then $Cola[$o] = ($DIF *30)
            Next
        $col = "0x" & Hex($Cola[1], 2) & Hex($Cola[2], 2) & Hex($Cola[3], 2)
        GUICtrlSetBkColor(-1,$col)
    Next
Next
Msgbox(0,"Stop", "Render Process Complete")

sleep(10000)
EndFunc ;==>CreateThumb
func terminate()
        exit 0
EndFunc ;==>Terminate

And my documentation;

(*(>--------------------------------<)*)
(*(>CWS Thumbnail Data Documentation<)*)
(*(>--------------------------------<)*)
(*(>By Malu05 aka Mads Hagbarth Lund<)*)
(*(>--------------------------------<)*)

The Thumbnail data is located at the buttom of every *.CWS (Combustion Workspace Storage) file marked "TNInfo" and "TNData".
;TNInfo; indicates the size with 2 x 3 byte ints. 
    -These values are seperated with empty 1 space

;TNData; contains the color data.
The data contains 3 values.
    "XYZ"
        X = RED
        Y = GREEN
        Z = BLUE

    -note; There is no space between the value sections.

The Values are defined from this table;

Value   Digt    Percentage (%)
0 =     0 =     0
1 =     1 =     3,33
2 =     2 =     6,66
3 =     3 =     9,99
4 =     4 =     13,33
5 =     5 =     16,66
6 =     6 =     19,99
7 =     7 =     23,33
8 =     8 =     26,66
9 =     9 =     29,99
: =     10 =    33,33
; =     11 =    36,66
< =     12 =    39,99
= =     13 =    43,33
? =     14 =    46,66
@ =     15 =    49,99
A =     16 =    53,33
B =     17 =    56,66
C =     18 =    59,99
D =     19 =    63,33
E =     20 =    66,66
F =     21 =    69,99
G =     22 =    73,33
H =     23 =    76,66
I =     24 =    79,99
J =     25 =    83,33
K =     26 =    86,66
L =     27 =    89,99
M =     28 =    93,33
N =     29 =    96,66
O =     30 =    100 (99,99)

---
Examples;
000 = Black
ooo = White
o00 = Pure Red
0o0 = Pure Green
00o = Pure Blue
AAA = Dark Grey

[center][u]WoW Machinima Tool[/u] (Tool for Machinima Artists) [/center]

Share this post


Link to post
Share on other sites



Even if i remove the

GuiCtrlCreateGraphic($i, ($e), (2), (2))

the process is tighten up and runs much faster.

-So is there a way to paint it in any other way?

The process is however still really slow.

-So is there any preformence leaks in the code that can be fixed?


[center][u]WoW Machinima Tool[/u] (Tool for Machinima Artists) [/center]

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0