AutoHotkey Community

It is currently May 26th, 2012, 10:14 am

All times are UTC [ DST ]




Post new topic Reply to topic  [ 85 posts ]  Go to page Previous  1, 2, 3, 4, 5, 6
Author Message
 Post subject:
PostPosted: September 26th, 2007, 12:34 pm 
Offline

Joined: May 24th, 2006, 2:49 pm
Posts: 4511
Location: Belgrade
Yes, exaclty what GIF makesr do when you optimise the GIF.

_________________
Image


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: October 23rd, 2008, 4:10 pm 
Hi,

i think this si exactly what iam looking for.

is here something new? plz tell me how i can use a hex code for show pics in the script?

what funktion i need? Or ist there a GUI out for this?


thx


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: October 23rd, 2008, 5:32 pm 
sry for DP, its me again!


i love the code you post of the first page.

Plt can you say how i can do the same but with ico formats?

cause when i use bmp i have no transparency!


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: February 26th, 2009, 8:42 am 
Offline

Joined: November 21st, 2006, 9:00 pm
Posts: 210
I have a bitmap file (46.9k big)

When using this script, I get an error stating that the line is too long. Is there anyway to fix this?

I've already tried :

Code:
data =
( join
....
...
}

data = %data%`n
(
...
...
)


Each section contained no more than 14,000 characters and it still errors out on me.

Please help!


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: February 26th, 2009, 8:47 am 
ecksphore wrote:
Each section contained no more than 14,000 characters and it still errors out on me.

declare into a variable without section.






in other words: a single line.


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: May 21st, 2009, 5:46 am 
Hi, I am very worried with this routine below. I have been working on it for many nights, trying to figure out why it runs out of memory.

I think I am doing everything correctly... but cannot say for sure. I have looked at many examples in this thread, and other places... but nothing seems to jump out at me at what I might be missing.

I don't know if there are additional things I need to 'reset' or clear out before the loop restarts...., that might be causing the problem of the script eventually crashing.




Thank you for anyone who can figure this out! This has me really stumped. I am disposing the bitmap, ... however, you'll notice %COUNT_SUM_PDATA% grows over time until the script crashes. I had about 50 decent sized PNG images in the folder, and a crash eventually happens!


You need to run this script, with a_directory_with_some_pngfiles folder in the script directory. I threw about 3 dozen PNG image files that were between 250K-300K in size. The code loop below demonstrates processing of each image, from a file to a bitmap. Extra code comments are below.

Code:

; press a to test loop

a::

Loop
{
Gosub, PROCESS_IMAGE

Tooltip, LOOP DONE! <%COUNT_PROCESSED% PROCESSED>

}

Return

; ---------------------------------------------
; ---------------------------------------------

PROCESS_IMAGE:

; ----- setup test variables

COUNT_PROCESSED=0

COUNT_SUM_HDATA=0
COUNT_SUM_PDATA=0
COUNT_SUM_NSIZE=0

; ---------------------------------------------

Loop, a_directory_with_some_pngfiles\*.*
{

FileGetSize, dataSz , a_directory_with_some_pngfiles\%A_LoopFileName%
FileRead, BinData , a_directory_with_some_pngfiles\%A_LoopFileName%

hexData := Bin2Hex( &BinData, dataSz )

; ^ Convert Image To Hex Data

nSize := StrLen(hexData)//2
Hex2Bin(Buffer,hexData)

hData := DllCall("GlobalAlloc", UInt,2, UInt, nSize)
pData := DllCall("GlobalLock",  UInt,hData)
DllCall( "RtlMoveMemory", UInt,pData, UInt,&Buffer, UInt,nSize)
DllCall( "GlobalUnlock", UInt,hData)
DllCall( "ole32\CreateStreamOnHGlobal", UInt,hData, Int,True, UIntP,pStream)

DllCall( "LoadLibrary", Str,"gdiplus" )
VarSetCapacity(si, 16, 0), si := Chr(1)

DllCall( "gdiplus\GdiplusStartup", UIntP,pToken, UInt,&si, UInt,0 )
DllCall( "gdiplus\GdipCreateBitmapFromStream", UInt,pStream, UIntP,bitmap)

DllCall(NumGet(NumGet(1*pStream)+8),Uint,pStream)

GDIplus_GetImageDimension(bitmap, WIDTH_OF_IMAGE, HEIGHT_OF_IMAGE)

DllCall( "gdiplus\GdipDisposeImage", UInt,bitmap)

;FileAppend, %COUNT_PROCESSED% - %HDATA% | %PDATA% | %NSIZE% > %WIDTH_OF_IMAGE% x %HEIGHT_OF_IMAGE%`n,TESTING_OUTPUT.TXT

; ^ Uncomment To See Each File Processed - If processing correctly we should see a %WIDTH_OF_IMAGE% x %HEIGHT_OF_IMAGE%



; - end of loop

COUNT_SUM_HDATA:=COUNT_SUM_HDATA+HDATA
COUNT_SUM_PDATA:=COUNT_SUM_PDATA+PDATA
COUNT_SUM_NSIZE:=COUNT_SUM_NSIZE+NSIZE

COUNT_PROCESSED++

}

FileAppend, %COUNT_SUM_HDATA% | > why does this var grow over time, until script crashes? ---> %COUNT_SUM_PDATA% <--- | %COUNT_SUM_NSIZE%`n,TESTING_OUTPUT.TXT

; ^ test output data

return



Here are the extra stock functions which make it all work :)

Code:

GDIplus_GetImageDimension(_image, ByRef @imageWidth, ByRef @imageHeight)
{
   local r

   #GDIplus_lastError =
   r := DllCall("GDIplus.dll\GdipGetImageDimension"
         , "UInt", _image
         , "Float *", @imageWidth
         , "Float *", @imageHeight)
   If (r != #GDIplusOK)
   {
      #GDIplus_lastError := "GdipGetImageDimension (" . r . ": " . #GpStatus@%r% . ") " . ErrorLevel
   }
   @imageWidth := Floor(@imageWidth)
   @imageHeight := Floor(@imageHeight)
   Return r
}

/*

  Bin2Hex() and Hex2Bin()

  Machine code functions: Bit Wizardry [ By Laszlo Hars ]

  Topic : http://www.autohotkey.com/forum/viewtopic.php?t=21172
  Post  : http://www.autohotkey.com/forum/viewtopic.php?p=180469#180469

*/

Bin2Hex(addr,len) { ; Bin2HexGOLD(&x,4)

   Static fun
   If (fun = "")
      Hex2Bin(fun,"8B4C2404578B7C241085FF7E2F568B7424108A06C0E8042C0A8AD0C0EA05"
      . "2AC2044188018A06240F2C0A8AD0C0EA052AC2410441468801414F75D75EC601005FC3")
   VarSetCapacity(hex,2*len+1)
   dllcall(&fun, "uint",&hex, "uint",addr, "uint",len, "cdecl")
   VarSetCapacity(hex,-1) ; update StrLen
   Return hex
}

Hex2Bin(ByRef bin, hex) { ; Hex2Bin(fun,"8B4C24") = MCode(fun,"8B4C24")
   Static fun
   If (fun = "") {
      h:="568b74240c8a164684d2743b578b7c240c538ac2c0e806b109f6e98ac802cac0e104880f8"
       . "a164684d2741a8ac2c0e806b309f6eb80e20f02c20ac188078a16474684d275cd5b5f5ec3"
      VarSetCapacity(fun,StrLen(h)//2)
      Loop % StrLen(h)//2
         NumPut("0x" . SubStr(h,2*A_Index-1,2), fun, A_Index-1, "Char")
   }
   VarSetCapacity(bin,StrLen(hex)//2)
   dllcall(&fun, "uint",&bin, "Str",hex, "cdecl")
}



Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: August 7th, 2009, 7:37 pm 
Offline

Joined: August 21st, 2006, 7:07 pm
Posts: 2925
Location: The Shell
Anonymous wrote:
...declare into a variable without section.

in other words: a single line.

Had to bump this one.

I too am getting an error message that the line is too long on a single line binary string. It was generated from the converter on the 1st page.

I'm wondering, what is the exact max characters allowed??

Anyone know?

Thanks guys for this amazing (albeit old) work.

_________________
Imageparadigm.shift:=(•_•)┌П┐RTFM||^.*∞


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: August 15th, 2009, 11:18 pm 
Offline

Joined: August 21st, 2006, 7:07 pm
Posts: 2925
Location: The Shell
Ok I had a chance to put together a continuation section concatenater that works around the binary character limitation.
1st off I found out that each continuation section can contain 16371 characters max not 16383 as stated in the manual :roll: (not sure if this is a bug, something to do with a join continuation or the number needs to be changed in the manual).

This section of code creates the template script "NewBinaryFile.ahk" in its working directory. This is just a proof of concept version. Once I confirm everything is working I will add this to an updated version of BMP to Binary.
Code:
fileExt = jpg
fileName = Test
outputFile = %A_WorkingDir%\NewBinaryFile.ahk
mxLen := 16371
FileDelete, %outputFile%

    FileRead, bindat, %A_WorkingDir%\bindat.txt
    StringLen, bindatLen, bindat
    brkCount := Round(bindatLen /= mxLen)
        if brkCount = 0
   brkCount = 1

    Loop, %brkCount%
   {
   StringLeft, curBin, bindat, %mxLen%
   newBinBrk := "binaryData" A_index " =`n( join`n" curBin "`n)`n`n"
       FileAppend, %newBinBrk%, %outputFile%
       StringReplace, bindat, bindat, %curBin%,,
           contSects .= "binaryData" A_index " . "
   }
    StringTrimRight, contSects, contSects, 3
   
    contSects := "binData .= " contSects "`n`nReturn`n`ncloseOut:`nMsgbox, Conversion Complete!`nExitApp"
    FileAppend, %contSects%, %outputFile%

FileRead, newBinDat, %outputFile%
FileDelete, %outputFile%
    writeSect .= "fileLoc = " "%A_WorkingDir%\" fileName "." fileExt "`ngosub, defineFile`nWriteFile(fileLoc,binData)"

prependDat =
(
#SingleInstance Force
#NoEnv
OnExit, closeOut

%writeSect%

; CODE STARTS HERE

; CODE ENDS HERE

; Binary file conversion thanks to Veovis, Laszlo, PhiLho and I'm sure SKAN had something to do with it ;).
; Found here: http://www.autohotkey.com/forum/viewtopic.php?t=10957

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
}

defineFile:
)
    FileAppend ,%prependDat%`n%newBinDat%, %outputFile%

Exitapp


NewBinaryFile.ahk then reads the bindat.txt created from a mod'd version of BMP to Binary found on the 1st page of this thread). It can then be used as a template script that converts the binary to images and joins sections over the max char limt that can be used in a script. Simply edit NewBinaryFile.ahk to see how many sections are created and add your code to this section:
Quote:
; CODE STARTS HERE

; CODE ENDS HERE


For this example save bindat.txt to the same directory as NewBinaryFile.ahk

http://bdm08.zxq.net/bindat.txt

or

http://a.imagehost.org/download/0636/bindat.txt


When there are many continuation sections the conversion process is quite slow but it does work!

I'm going to integrate this into a mod'd version of BMP to Binary converter that will automatically create the script template. That way there will be no need for the external bindat.txt file.

Soon to come...


BTW just noticed that long binary sections actually break the forum (turns a post into blank). So the next question is what the max line length in a single post admins ? :lol:

_________________
Imageparadigm.shift:=(•_•)┌П┐RTFM||^.*∞


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: June 8th, 2010, 7:50 pm 
Offline

Joined: March 1st, 2010, 7:02 am
Posts: 43
I want to use Veovis's GUI from page 1 of this topic to have my .png files included in the compiled scripts, so I will have a single .exe.
But I want to use ImageSearch inside the script also. It works as long as I use the WriteFile function to read the image from disk, but it does not work for me if I call the %picture%
definepicture:
picture = (join...)

I searched deeper in the forum and I found this:

apignard
Guest
"is there a way to embedded image with imagesearch and compiled version as well ?"

SKAN Posted: Tue Aug 04, 2009 4:42 pm
"no"

Also I found a topic where someone suggested to write the images in a %TEMP% and delete them afterwards.

So if I am understanding right, we cannot use the ImageSearch function unless we WriteFile somewhere? Not following why since the image is in the memory already. Theres smth wrong in my code (hopefully) or it is not possible yet? Thanks.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: June 9th, 2010, 6:35 pm 
Offline

Joined: March 26th, 2010, 5:55 pm
Posts: 129
I was wanting to do the same thing, perhaps for the same reason ;)

I don't think it's possible to trick ImageSearch to use an image in memory or in the executable, but not too long ago I did manage to put together an alternative. It's somewhat involved, but it does work. I'll post it as a new thread.

edit: here it is


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

All times are UTC [ DST ]


Who is online

Users browsing this forum: xXDarknessXx 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