AutoHotkey Homepage AutoHotkey Community
Let's help each other out
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

GDI+ standard library 1.25 by tic
Goto page Previous  1, 2, 3, 4, 5, 6, 7, 8  Next
 
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Scripts & Functions
View previous topic :: View next topic  
Author Message
Drugwash



Joined: 07 Sep 2008
Posts: 56
Location: Ploiesti, RO

PostPosted: Sun Sep 28, 2008 10:43 pm    Post subject: Reply with quote

I tried out Bobo's code out of curiosity. With Size := 0.8 it created a 599kB PNG 1638x614. With Size := 1 it created a 187kB PNG of the same screen (fullscreen 2048x768 - dual monitor).
Why would a smaller image be that much larger after resize? It's also very slow (a few seconds on 700MHz CPU), compared to ScreenGrab also set to save PNG.

Tested in Win98SE.
_________________
Back to top
View user's profile Send private message AIM Address Yahoo Messenger
tic



Joined: 22 Apr 2007
Posts: 1375

PostPosted: Sun Sep 28, 2008 11:23 pm    Post subject: Reply with quote

Heh that stumped me for a bit, but I think I have figured out why. It's a bit weird though Razz Because of how a pngs compression works, the smaller resolution file is actually larger in filesize as it has more colours because when an image with a single black pixel on a white background is shrunk, then it becomes a black pixel with some shades of grey pixels round it on a white background. This makes sense to me but may not be the case (im just trying to explain it) as I have looked through the code and can see no reason why this would happen. They are both the same colour depth. When testing with an image format with no compression (bmp) you can clearly see the larger reolution is a proportionally larger filesize.

There are a number of reasons for potential slowness. As Bobo has put the whole image resizing and saving into a function then the bitmap needs to be created twice in memory every time, when only once is needed, and there should also be a check to make it so that it doesnt resize it if the size is set to 1. You probably already saw nut it also uploads it to the internet which cant be counted in the time taken. On a test on my comp it took 125ms to completely save the file to disk and I can see that actually writing to disk takes the largest chunk of time (all the rest takes around 40ms) so the disk is what is slowing it down. I actually think Bobo's script is quite nice now that I've tested it Smile but it could be optimized a tad

ps. The image at 1 had 3531 unique colours and the smaller 0.8 one had 5598
Back to top
View user's profile Send private message
Drugwash



Joined: 07 Sep 2008
Posts: 56
Location: Ploiesti, RO

PostPosted: Mon Sep 29, 2008 3:08 pm    Post subject: Reply with quote

Hi, thanks for replying.

I just checked and the 0.8 image has 34578 colors, while the 1 image has 5226, both at 32bpp. Quite a discrepancy, I'd say... Confused

As for the time taken, I should've mentioned I used the previous code, not the function one that also uploads it.

It seems to be the resizing that takes all that time and possibly the fact that the CPU is already ~70% busy. I added a check to skip resizing if size is 1 and it now saves it much faster, complete with timestamp watermarking.

All in all it's a nice and useful script and I may improve it a bit - if I manage to understand all of the tricks - especially in the timestamp area, which could use a semi-transparent background. But for now it's just an idea. Wink

Oh and I forgot to say: too bad your tutorial examples don't work in Win9x... Crying or Very sad Would've been really useful for me to learn all GDI+ functions. Maybe you could consider some non-layered examples, time allowing.
_________________
Back to top
View user's profile Send private message AIM Address Yahoo Messenger
tinku99



Joined: 03 Aug 2007
Posts: 35

PostPosted: Mon Sep 29, 2008 9:36 pm    Post subject: pgm to bitmap Reply with quote

Is there a way to convert a pgm image into a bitmap with gdiplus.ahk without having to loop with the setpixel function?
basically how do you get from a 2 dimensional array of 32bit integers (argb pixels) to a bitmap ?
I want to do something like this using just ahk:
http://www.codeguru.com/cpp/g-m/gdi/gdi/article.php/c3705
Thanks.
Back to top
View user's profile Send private message
tic



Joined: 22 Apr 2007
Posts: 1375

PostPosted: Mon Sep 29, 2008 11:12 pm    Post subject: Reply with quote

DrugWash:

might have fewer colours with a different interpolation mode:

Code:
Gdip_SetInterpolationMode(G, 7)


but wouldnt look as nice.

I don't know what you mean by a semi-transparent background. Do you mean foreground? It would not take long to help with something like this if you wanted.

I will post a few non layered examples shortly as it is quite useful, and I already use the library to replace controls. Buttons and progress bars etc. look superior with this method

tinku99:

What I wonder though is how would you be getting this array? Can you not just use a png or bitmap? You could even include it in your script if you really wanted, but basically let me know what you want to do with it and I may be able to help
Back to top
View user's profile Send private message
tinku99



Joined: 03 Aug 2007
Posts: 35

PostPosted: Tue Sep 30, 2008 12:03 am    Post subject: pgm to bitmap Reply with quote

I am doing some image manipulation: edge detection, segmentation. I need to be able to display binary images as well as gray scale images with different ranges for the pixel values. My images are in dicom, but i convert them to a 2d matrix for the image manipulation.

I am working with an ecl(lisp) dll under ahk.
works a lot like the ws4ahk.ahk for lisp.
i could write out my data to a file, convert to jpg and then use gdiplus, but thought i might skip the disk writing step.

Here is something close to what i want:

http://www.autohotkey.com/forum/viewtopic.php?t=14941&highlight=include+images

instead of this function:
CreateBitmapInMemory(_imageHexData, _guiID)
i want a similar curried function that takes a 2x2 array, and maybe three other arguments such as width, height, and pixel depth.tuch as width and height and pixel depth
Back to top
View user's profile Send private message
tinku99



Joined: 03 Aug 2007
Posts: 35

PostPosted: Tue Sep 30, 2008 12:20 am    Post subject: pgm to bitmap Reply with quote

http://www.autohotkey.com/forum/topic32225.html&highlight=bitmap

Figured it out... used your function in the link above combined with the above...
is kind of dirty, will try to clean it up later.

requires gdip.ahk and filehelper.ahk

Code:
; http://www.fortunecity.com/skyscraper/windows/364/bmpffrmt.html

VarSetCapacity( BMP, 62 )
NumPut( 19778, BMP, 0, "UShort" ) ; bfType - must always be set to 'BM' to declare that this is a .bmp-file.
NumPut(    62, BMP, 2, "UShort" ) ; bfSize - specifies the size of the file in bytes.
NumPut(     0, BMP, 6, "UInt"   ) ; reserved
NumPut(    54, BMP,10, "UInt"   ) ; bfOffBits - specifies the offset from the beginning of the file to the bitmap data.
NumPut(    40, BMP,14, "UInt"   ) ; biSize - 40 specifies the size of the BITMAPINFOHEADER structure, in bytes.
NumPut(     1, BMP,18, "UInt"   ) ; biWidth - specifies the width of the image, in pixels.
NumPut(     2, BMP,22, "UInt"   ) ; biHeight - specifies the height of the image, in pixels. 
NumPut(     1, BMP,26, "UShort" ) ; biPlanes - specifies the number of planes of the target device, must be set to zero.
NumPut(    24, BMP,28, "UShort" ) ; biBitCount - specifies the number of bits per pixel.
NumPut(     0, BMP,30, "UInt"   ) ; biCompression - Specifies the type of compression, usually set to zero (no compression).
NumPut(     8, BMP,34, "UInt"   ) ; biSizeImage - specifies the size of the image data, in bytes.
NumPut(     0, BMP,38, "UInt"   ) ; biXPelsPerMeter - specifies the the horizontal pixels per meter on the designated target device, usually set to zero.
NumPut(     0, BMP,42, "UInt"   ) ; biYPelsPerMeter - specifies the the horizontal pixels per meter on the designated target device, usually set to zero.
NumPut(     0, BMP,46, "UInt"   ) ; biClrUsed - specifies the number of colors used in the bitmap, if set to zero the number of colors is calculated using the biBitCount member.
NumPut(     0, BMP,50, "UInt"   ) ; biClrImportant - specifies the number of color that are 'important' for the bitmap, if set to zero, all colors are important

; RGBQUAD - Data area
NumPut( 0x00000000, BMP,54, "UInt" ) ; Bottom Pixel Color - Black in BGR 
NumPut( 0x00FF0000, BMP,58, "UInt" ) ; Top Pixel Color - Red in BGR

; hFile := DllCall( "_lcreat", Str,"bg.bmp", Int,0 )
; DllCall( "_lwrite", UInt,hFile, Str,BMP, UInt, 62 )
; DllCall( "_lclose", UInt,hFile )
gosub second
return
 

GuiClose:
GuiEscape:
  ExitApp
 
#Include, Gdip.ahk
#Include FileHelper.ahk

second:
nSize := 62

Gui, +LastFound
Gui, Show, w800 h600 Center, Picture
hGui := WinExist()

; From here, the actually needed part
hData := DllCall("GlobalAlloc", "Uint", 2, "Uint", nSize)
pData := DllCall("GlobalLock", "Uint", hData)
DllCall("RtlMoveMemory", "Uint", pData, "Uint", &BMP, "Uint", nSize)
DllCall("GlobalUnlock", "Uint", hData)
DllCall("ole32\CreateStreamOnHGlobal", "Uint", hData, "int", True, "UintP", pStream)

pToken := Gdip_Startup()
DllCall("gdiplus\GdipCreateBitmapFromStream", "Uint", pStream, "UintP", pBitmap)
DllCall("gdiplus\GdipCreateHBITMAPFromBitmap", "Uint", pBitmap, "UintP", hBitmap, "Uint", 0)
DllCall("gdiplus\GdipGetImageWidth" , "Uint", pBitmap, "UintP", nW)
DllCall("gdiplus\GdipGetImageHeight", "Uint", pBitmap, "UintP", nH)

hDC := DllCall("GetDC", "Uint", hGui)
mDC := DllCall("CreateCompatibleDC", "Uint", hDC)
hBM := DllCall("SelectObject", "Uint", mDC, "Uint", hBitmap)

DllCall("SetStretchBltMode", "Uint", hDC, "int", 4)
DllCall("StretchBlt", "Uint", hDC, "int", 0, "int", 0, "int", 800, "int", 600, "Uint", mDC, "int", 0, "int", 0, "int", nW, "int", nH, "Uint", 0x00CC0020)

DllCall("SelectObject", "Uint", mDC, "Uint", hBM)
DllCall("DeleteDC", "Uint", mDC)
DllCall("ReleaseDC", "Uint", hGui, "Uint", hDC)
DllCall("DeleteObject", "Uint", hBitmap)
DllCall("gdiplus\GdipDisposeImage", "Uint", pBitmap)
pToken := Gdip_Shutdown(pToken)

DllCall(NumGet(NumGet(1*pStream)+8), "Uint", pStream)
Return
Back to top
View user's profile Send private message
Drugwash



Joined: 07 Sep 2008
Posts: 56
Location: Ploiesti, RO

PostPosted: Tue Sep 30, 2008 5:54 am    Post subject: Reply with quote

tic wrote:
Drugwash:

might have fewer colours with a different interpolation mode:

Code:
Gdip_SetInterpolationMode(G, 7)


but wouldnt look as nice.
The 0.8 resized version already makes use of that formula and indeed doesn't look too nice. I removed it for size 1.
Quote:
I don't know what you mean by a semi-transparent background. Do you mean foreground? It would not take long to help with something like this if you wanted.
I was referring to the text (timestamp) background color which is now non-existant and might make it hard to read in certain situations.
Quote:
I will post a few non layered examples shortly as it is quite useful, and I already use the library to replace controls. Buttons and progress bars etc. look superior with this method
Thank you, your efforts are greatly appreciated!
_________________
Back to top
View user's profile Send private message AIM Address Yahoo Messenger
tic



Joined: 22 Apr 2007
Posts: 1375

PostPosted: Tue Sep 30, 2008 5:56 pm    Post subject: Reply with quote

tinku99:

You'll see that I already had those functions, but for a different purpose in Gdip_BitmapFromBRA() which I have as of yet not told anyone how to use Razz
You do not need to numput all the header info into a bitmap to create a blank bitmap, just use Gdip_CreateBitmap()

Drugwash:

When I was referring to
Code:

Gdip_SetInterpolationMode(G, 7)


that function says how the image is resized, so 7 means HighQualityBicubic if you look in Gdip.ahk and so I was saying that if you chose LowQuality = 1 it would have fewer colours when resized but would not look as nice. Ill create a nice progress bar (superior to all on the forums Razz) for my 1st non-layered example
Back to top
View user's profile Send private message
Drugwash



Joined: 07 Sep 2008
Posts: 56
Location: Ploiesti, RO

PostPosted: Tue Sep 30, 2008 9:08 pm    Post subject: Reply with quote

Ah, I see. However, seeing that even level 7 kinda breaks the image, I couldn't imagine what level 2 or 1 would do to it.

I'll be around, waiting for that super-duper progressbar. Good luck with it! Wink

P.S. My Win98SE system is skinned with Tihiy's Uberskin and it takes over the regular progressbar's color. I'm curious if you can work around this. Cool
_________________
Back to top
View user's profile Send private message AIM Address Yahoo Messenger
tic



Joined: 22 Apr 2007
Posts: 1375

PostPosted: Sun Oct 05, 2008 10:59 pm    Post subject: Reply with quote

Example 9 uploaded. A quick demonstration to create new controls on a gui using the library (In this case a custom progress bar)
Back to top
View user's profile Send private message
Drugwash



Joined: 07 Sep 2008
Posts: 56
Location: Ploiesti, RO

PostPosted: Mon Oct 06, 2008 1:19 am    Post subject: Reply with quote

Thanks, it works... almost. Smile

The progress bar is correctly drawn - from what I can tell - but it appears at random times, after clicking and/or dragging the slider to various positions and it doesn't follow the correct position (percentage) of the slider.

Then when the window is sent to back and back to front (focus a bigger window that covers it and then refocus the example, the progress bar is simply not there; will appear after more clicking/dragging around.

Otherwise it's a neat example and I may consider using this technique with the toy I'm working on. Wink

Thanks again and have a great week ahead! Cool
_________________
Back to top
View user's profile Send private message AIM Address Yahoo Messenger
ewerybody



Joined: 18 Sep 2006
Posts: 20

PostPosted: Tue Oct 07, 2008 4:46 pm    Post subject: Reply with quote

Hey tic!
awesome work! Intense man!! Very Happy

I was just trying to do some image editing stuff but I need rotate and scale.
No examples yet? I'm crapping up getting it to work? reset what?? Sad

And hey Drugwash: lol! I know you frum miranda-forum. Thats how nerds meet ^^
Back to top
View user's profile Send private message
ewerybody



Joined: 18 Sep 2006
Posts: 20

PostPosted: Wed Oct 08, 2008 1:44 pm    Post subject: Reply with quote

still no success.
According to the header:
Gdip_RotateWorldTransform and Gdip_ScaleWorldTransform return
; InvalidParameter = 2

I don't know how the given picture or an angle value of maybe 90 can be invalid? Is the bitmap the wrong point to start? can I only rotate graphics (G)?

Someone else had success with rotating and scaling?

And can I flip an image via negative scale?
Back to top
View user's profile Send private message
tic



Joined: 22 Apr 2007
Posts: 1375

PostPosted: Wed Oct 08, 2008 4:00 pm    Post subject: Reply with quote

ewerybody wrote:
still no success.
According to the header:
Gdip_RotateWorldTransform and Gdip_ScaleWorldTransform return
; InvalidParameter = 2

I don't know how the given picture or an angle value of maybe 90 can be invalid? Is the bitmap the wrong point to start? can I only rotate graphics (G)?

Someone else had success with rotating and scaling?

And can I flip an image via negative scale?


I will make them my next examples when I have some free time (will do it very soon....dont think Im going out tonight)
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Scripts & Functions All times are GMT
Goto page Previous  1, 2, 3, 4, 5, 6, 7, 8  Next
Page 6 of 8

 
Jump to:  
You can post new topics in this forum
You can reply to topics in this forum


Powered by phpBB © 2001, 2005 phpBB Group