AutoHotkey Community

It is currently May 27th, 2012, 6:21 am

All times are UTC [ DST ]




Post new topic Reply to topic  [ 1000 posts ]  Go to page Previous  1 ... 35, 36, 37, 38, 39, 40, 41 ... 67  Next
Author Message
 Post subject:
PostPosted: November 23rd, 2010, 4:13 am 
Offline

Joined: April 22nd, 2007, 6:33 pm
Posts: 1833
rseding91 wrote:
I was wondering, could that be done the other way around? setting pixel colors with machine code instead of looking them up?


tutorial 12 does exactly that :wink:


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: November 23rd, 2010, 4:28 am 
Offline

Joined: June 7th, 2010, 3:40 pm
Posts: 553
Ah ok, i'll take a look at it.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: November 23rd, 2010, 5:47 am 
Offline

Joined: June 7th, 2010, 3:40 pm
Posts: 553
I looked at example 12 but it's about messing with a image - not creating one.

I'm wondering if there is a machine code way to do this function: Gdip_SetLockBitPixel()


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: November 23rd, 2010, 3:30 pm 
Offline

Joined: November 8th, 2010, 9:11 am
Posts: 12
Location: Australia
I'm trying to create a monochrome (binary) image using the GDI based on the method here: http://weblogs.foxite.com/vfpimaging/archive/2007/05/26/3857.aspx

Heres my code based on one of tics examples:
Code:
#SingleInstance, Force
#NoEnv
SetBatchLines, -1

#Include, Gdip.ahk

; Specify the file we are going to use
InFile = test.jpg
OutFile = testgs.jpg
OutFile2 = testmc.jpg

; Start gdi+
If !pToken := Gdip_Startup()
{
   MsgBox, 48, gdiplus error!, Gdiplus failed to start. Please ensure you have gdiplus on your system
   ExitApp
}

; Get a bitmap from the image
pBitmap := Gdip_CreateBitmapFromFile(InFile)

; Check to ensure we actually got a bitmap from the file, in case the file was corrupt or some other error occured
If !pBitmap
{
   MsgBox, 48, File loading error!, Could not load the image specified
   ExitApp
}

; Get the width and height of the bitmap we have just created from the file
; This will be the dimensions that the file is
Width := Gdip_GetImageWidth(pBitmap), Height := Gdip_GetImageHeight(pBitmap)

; Create a gdi+ bitmap (this will be the entire drawing area we have to play with)
pBitmap1 := Gdip_CreateBitmap(Width, Height)

; Get a pointer to the graphics of the bitmap, for use with drawing functions
G := Gdip_GraphicsFromImage(pBitmap1)

; Draw the 1st bitmap (1st image) onto our "canvas" (the graphics of the original bitmap we created) with the same height and same width
; at coordinates (25,30).....We will be ignoring the matrix parameter for now. This can be used to change opacity and colours when drawing
Matrix =
(
0.299|0.299|0.299|0|0|0.587|0.587|0.587|0|0|0.114|0.114|0.114|0|0|0|0|0|1|0|0|0|0|0|1
)
Gdip_DrawImage(G, pBitmap, 0, 0, Width, Height, 0, 0, Width, Height, Matrix)

; Dispose of the bitmap from the image on disk, as they are now been used...They are on
; the graphics of the bitmap of our created "canvas"
Gdip_DisposeImage(pBitmap)

; Save the greyscale bitmap to file extension can be .png,.bmp,.jpg,.tiff,.gif)
Gdip_SaveBitmapToFile(pBitmap1, OutFile)

;Take grayscale image and copy it into a new bitmap which is monochrome (1bpp)
pBitmap2:=DllCall("CopyImage",UInt, pBitmap1,UInt,0,Int,Width,Int,Height, UInt,0x00000001)

; Dispose of the grayscale bitmap as it has been used
Gdip_DisposeImage(pBitmap1)

; Save the monochrome bitmap to file extension can be .png,.bmp,.jpg,.tiff,.gif)
Gdip_SaveBitmapToFile(pBitmap2, OutFile2)

; The bitmap can be deleted
Gdip_DisposeImage(pBitmap2)

; The graphics may now be deleted
Gdip_DeleteGraphics(G)

; ...and gdi+ may now be shutdown
Gdip_Shutdown(pToken)
ExitApp
Return


It correctly creates a grayscale image, but does not create the monchrome image called by this code:
Code:
;Take grayscale image and copy it into a new bitmap which is monochrome (1bpp)
pBitmap2:=DllCall("CopyImage",UInt, pBitmap1,UInt,0,Int,Width,Int,Height, UInt,0x00000001)


Any idea what I am doing wrong with the CopyImage?


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: November 23rd, 2010, 11:17 pm 
Offline

Joined: June 20th, 2008, 12:40 pm
Posts: 47
The present Gdip.ahk can't be used with x64 AHK_L, can it? I don't get error messages, but where images are supposed to show up, they don't.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: November 24th, 2010, 2:45 am 
Offline

Joined: April 22nd, 2007, 6:33 pm
Posts: 1833
rseding91

tutorial 12 does do that. it has to get the ARGB values of the pixels and then set them. in c++ you set a pixel like:

Code:
Bitmap[o] = ARGB;


where bitmap is the Scan0 obtained from locking the bitmap, this being a pointer in memory

freo

I cant think of an obvious way off the top of my head to create an accurate monochromatic image with inbuilt features. I would just use machine code......however, when I tried to compile it then it gave me unusable machine code and i cant be bothered to attempt writing it in asm :wink:

so you will need to compile it to dll as i have done for you here

you will need to use it as I have shown with a quick rewrite of tutorial 12 here

The c++ for the dll is below:

Code:
extern "C"
{
   __declspec(dllexport) int MonochromeBitmap(unsigned char * sBitmap, unsigned int * dBitmap, int w, int h, int Stride, int Factor)
   {
      int o, offset = Stride/4, A, R, G, B;
      for (int y = 0; y < h; ++y)
      {
         for (int x = 0; x < w; ++x)
         {
            o = (4*x)+(y*Stride);
            A = sBitmap[3+o];
            R = sBitmap[2+o];
            G = sBitmap[1+o];
            B = sBitmap[o];
            dBitmap[x+(y*offset)] = (A/255*(0.299*R + 0.587*G + 0.114*B) >= Factor) ? 0xffffffff : 0xff000000;
         }
      }
      return 1;
   }
}


maraskan_user

I do plan on supporting AHK_L x64 (and some things in the lib still dont work with AHK_L x86 but am still a little bit wary of it as I have encountered half a dozen errors with it (although most of these seem to have been fixed now). I need to test whether regex has been fixed


Edit:

I have updated the Monochrome code to allow a factor between 0-255 to determine the luminescence required to differentiate between white and black


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: November 25th, 2010, 3:17 am 
Offline

Joined: November 8th, 2010, 9:11 am
Posts: 12
Location: Australia
Thanks tic i'll give it a try


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: November 25th, 2010, 2:11 pm 
Offline

Joined: April 22nd, 2007, 6:33 pm
Posts: 1833
freo wrote:
Thanks tic i'll give it a try


I have reuploaded the dll as it didnt work in win7 when I tested it, but did work in winxp. i recompiled the same source in win7 and it now works on both


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: November 27th, 2010, 7:13 am 
Offline

Joined: June 7th, 2010, 3:40 pm
Posts: 553
I was wondering, in what format does the lock bits function store the pixel information?

I found this in the lock function: PixelFormat = 0x26200a but i'm confused as to how it works.

Thanks,
Robert


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: November 29th, 2010, 10:12 am 
Offline

Joined: October 17th, 2006, 4:15 pm
Posts: 7503
Location: Australia
In response to tic's post in the latest AutoHotkey_L thread:

To get example 11 fully working in the latest ANSI build, I did the following:
  • Copy BRA_ListFiles into the script.
  • Disable the following line in Gdip_TextToGraphics, which otherwise crashes the script:
    Code:
    if !Gdip_DeleteBrush(Gdip_CloneBrush(Colour2))
That's all. It looks like what you're trying to do is determine whether Colour2 is a pointer to a brush. The way you're going about it is dangerous. You cannot treat any arbitrary value as a pointer to memory (passing it to RtlMoveMemory) and expect the program to handle it safely. Furthermore, how do you know that a GDI+ Brush object is 288 bytes and that copying it is safe? I don't believe the internal structure of GDI+ objects is publicly defined; GDI+ object pointers must be treated opaquely, like handles.

Example 11 will not work as-is in the Unicode build as FileRead converts the BRA data from ANSI to Unicode; i.e. the binary data is corrupted. If you use the *c option this conversion does not occur, which means that the binary data is left intact and that the text data is left in ANSI form, which is not directly usable.

Here is what I would suggest:
  • Read the file data in without conversion, i.e. FileRead, BRA, *c Gdip.tutorial.file-fish.bra.
  • Don't treat BRA as text; instead, retrieve the text part of it with text := StrGet(&BRA, len, "CP0") where len is the length of the text part.

See also: the Reading Binary Data section of the FileRead documentation.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: November 29th, 2010, 2:59 pm 
Offline

Joined: April 22nd, 2007, 6:33 pm
Posts: 1833
Lexikos wrote:
Don't treat BRA as text; instead, retrieve the text part of it with text := StrGet(&BRA, len, "CP0") where len is the length of the text part.


Thanks very much for taking the time to take a look Lex

Im mot sure about that point as how would I know the length to read, if the information for that length to read is in the part i am trying to read :?:
....unless i just use an arbitrary number like 65:

Code:
|BRA!|1.01|20100102051136
000000002170|000000056086|000006826640


as i suppose that will always be 65, but then 2 StrGets will need to be performed. one to get that and then one to read all of the rest of the information

Quote:
GDI+ object pointers must be treated opaquely, like handles.


yeh i realised that was a bit dodge when i did it a while ago. how would you determine if it is a valid brush pointer?


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: November 30th, 2010, 4:28 am 
Offline

Joined: October 17th, 2006, 4:15 pm
Posts: 7503
Location: Australia
If the text part ends with a null (zero) byte, you can safely use text := StrGet(&BRA, "CP0").
tic wrote:
how would you determine if it is a valid brush pointer?
I wouldn't. You could try GdipGetBrushType, but it's not necessarily any safer. I suppose it's theoretically possible for a Brush pointer and colour to have the same numeric value, in which case the only safe option is to change the format of the options string so there is no ambiguity.


Report this post
Top
 Profile  
Reply with quote  
 Post subject: Throbber
PostPosted: December 8th, 2010, 8:51 pm 
This is too advanced for me to figure out, but maybe someone wants/likes to do it, something like this
http://greenbuilding.redvector.com/LMS2 ... robber.gif
but then with a transparent background.

possible?
Thanks anyway


Report this post
Top
  
Reply with quote  
 Post subject: Re: Throbber
PostPosted: December 9th, 2010, 2:24 pm 
Offline

Joined: April 30th, 2009, 12:35 pm
Posts: 29
Assange wrote:
This is too advanced for me to figure out, but maybe someone wants/likes to do it, something like this
http://greenbuilding.redvector.com/LMS2 ... robber.gif
but then with a transparent background.

possible?
Thanks anyway


Based on tutorial #1 and Mouse Spirograph

Code:
; gdi+ ahk tutorial 1 written by tic (Tariq Porter)
; Requires Gdip.ahk either in your Lib folder as standard library or using #Include
;
; Tutorial to draw a single ellipse and rectangle to the screen

#SingleInstance, Force
#NoEnv
SetBatchLines, -1

; Uncomment if Gdip.ahk is not in your standard library
;#Include, Gdip.ahk

; Start gdi+
If !pToken := Gdip_Startup()
{
   MsgBox, 48, gdiplus error!, Gdiplus failed to start. Please ensure you have gdiplus on your system
   ExitApp
}
OnExit, Exit

; Set the width and height we want as our drawing area, to draw everything in. This will be the dimensions of our bitmap
Width := A_ScreenWidth, Height := A_ScreenHeight

; Create a layered window (+E0x80000 : must be used for UpdateLayeredWindow to work!) that is always on top (+AlwaysOnTop), has no taskbar entry or caption
Gui, 1: -Caption +E0x80000 +LastFound +AlwaysOnTop +ToolWindow +OwnDialogs

; Show the window
Gui, 1: Show, NA

; Get a handle to this window we have created in order to update it later
hwnd1 := WinExist()

Start_Radius=0
Radius := 25
SetTimer,My_Timer,100

Return

My_Timer:
; Create a gdi bitmap with width and height of what we are going to draw into it. This is the entire drawing area for everything
hbm := CreateDIBSection(Width, Height)

; Get a device context compatible with the screen
hdc := CreateCompatibleDC()

; Select the bitmap into the device context
obm := SelectObject(hdc, hbm)

; Get a pointer to the graphics of the bitmap, for use with drawing functions
G := Gdip_GraphicsFromHDC(hdc)

; Set the smoothing mode to antialias = 4 to make shapes appear smother (only used for vector drawing and filling)
Gdip_SetSmoothingMode(G, 4)

; Create a fully opaque red brush (ARGB = Transparency, red, green, blue) to draw a circle
pBrush := Gdip_BrushCreateSolid(0xffff0000)

; Fill the graphics of the bitmap with an ellipse using the brush created
; Filling from coordinates (100,50) an ellipse of 200x300
MouseGetPos, Origin_X, Origin_Y
Start_Radius++
Loop,10
{
   Circle_Size := 1 * A_Index
   T := (Start_Radius + A_Index) / 0.01745329252 ; degrees->radians
   OX := Radius*Cos(T)
   OY := Radius*Sin(T)
   Gdip_FillEllipse(G, pBrush, Origin_X+OX, Origin_Y+OY, Circle_Size, Circle_Size)
}
; Delete the brush as it is no longer needed and wastes memory
Gdip_DeleteBrush(pBrush)

; Update the specified window we have created (hwnd1) with a handle to our bitmap (hdc), specifying the x,y,w,h we want it positioned on our screen
; So this will position our gui at (0,0) with the Width and Height specified earlier
UpdateLayeredWindow(hwnd1, hdc, 0, 0, Width, Height)

; Select the object back into the hdc
SelectObject(hdc, obm)

; Now the bitmap may be deleted
DeleteObject(hbm)

; Also the device context related to the bitmap may be deleted
DeleteDC(hdc)

; The graphics may now be deleted
Gdip_DeleteGraphics(G)
Return

;#######################################################################

Exit:
; gdi+ may now be shutdown on exiting the program
Gdip_Shutdown(pToken)
ExitApp
Return




Last edited by mrr19121970 on December 9th, 2010, 2:29 pm, edited 1 time in total.

Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: December 9th, 2010, 2:28 pm 
Offline

Joined: December 9th, 2010, 2:23 pm
Posts: 1
i am retarded

even if i SetFormat integer hex before your code, it still doesnt give me hex


Report this post
Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 1000 posts ]  Go to page Previous  1 ... 35, 36, 37, 38, 39, 40, 41 ... 67  Next

All times are UTC [ DST ]


Who is online

Users browsing this forum: Apollo, JamixZol, rbrtryn, Stigg and 19 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