Page 1 of 1

A few questions about getting started - general advice neede

Posted: 2007-07-11T10:59:45-07:00
by Andromedus
Hello everyone - I have trawled through the forums here, but am still a bit lost as to where to start, so I hope someone can offer me a little advice.

I am writing a program using a language called Dark Basic Professional, (DBP) and need to do a number of image processing tasks which DBP cannot do itself. From what I have read, Imagemagick is perfect for doing this processing. However, as there is no Imagemagick interface for DBP, I'm trying to figure out what options I have. This is what I've tried so far:

Option 1: It is possible to execute a file with command line parameters from DBP, however when you do so, it opens up the nasty black ms-dos command line interface ..... not something I want the users of my program to see - so that's not really an option.

Option 2: It is also possible to call an external dll from DBP - like this:

Code: Select all


load dll "dllname",number 
result=CALL DLL(number,"functionname",parameter1,parameter2,parameter3......) 

My question is, is there a precompiled dll for Imagemagick which I could call in this way, and if so, is there a list of the function names and parameters they take? I have tried downloading the ImageMagick-6.3.5-Q16 static dll for windows, which contains various dll's, but I don't know which one to call or how to use it. I tried this:

Code: Select all


load dll "CORE_RL_Magick++_.dll",1
call dll 1,"image.read","logo.jpg"


and a few variations of it, without success - it just returns an error saying it could not call the dll function. Am I barking up the wrong tree here entirely?

Option 3: I could start my program again in a different language. I have done a tiny bit of C++ before, and have used Visual C++ 2005 express, and Dev C++. The problem here is that I can't find any evidence of anyone having used Imagemagick with either of these two compilers. I am reluctant to buy Visual Studio in order to use a free open source library like Imagemagick!

Option 4: I also read somewhere that Imagemagick could be used from the windows script host - and I can run that from DBP. Would that work? Does the interface for WSH have the full functionality of Imagemagick, and could I then redistribute my program, or would Imagemagick have to be installed on the end user's machine to work from a windows script like this?

Are there any other options I haven't considered?

Thanks in advance,

Ric.

Re: A few questions about getting started - general advice neede

Posted: 2007-07-11T19:12:05-07:00
by anthony
Andromedus wrote:Option 1: It is possible to execute a file with command line parameters from DBP, however when you do so, it opens up the nasty black ms-dos command line interface ..... not something I want the users of my program to see - so that's not really an option.
You should be able to run IM commands without that nasty black window.

Re: A few questions about getting started - general advice neede

Posted: 2007-07-11T20:53:52-07:00
by el_supremo
This kind of thing came up before but I can't find the thread.

Try calling the C MagickWand dll with a very simple test:

Code: Select all

load dll "CORE_RL_wand_.dll",1
call dll 1,"MagickWandGenesis"
call dll 1,"MagickWandTerminus"
If it can't find the dll, try running this test in the same directory as the dll files.

If this works you can then add further calls between Genesis and Terminus to see if it can read and write a file (for example).

Pete

Re: A few questions about getting started - general advice neede

Posted: 2007-07-12T04:31:14-07:00
by Andromedus
Thanks Pete, that works! I have managed to get it reading and writing images, so I'm assuming I now have access to the whole set of functions contained within magickwand in this way, which is great.

Cheers,

Ric.

Re: A few questions about getting started - general advice neede

Posted: 2007-07-12T21:05:16-07:00
by anthony
Andromedus

Can you provide a simple example program with image reads and writes.
I'll include it in the API section of IM examples.

Re: A few questions about getting started - general advice neede

Posted: 2007-07-13T06:18:56-07:00
by Andromedus
It may be a little too soon to adjust the help files just yet, as I'm still struggling to get expected results. That may well be down to my lack of understanding of how the Magickwand api works - apart from the list of the methods, there seems to be a lack of examples of them actually in use (unless there is some hidden goldmine of information I don't know about?), so I'm really just stabbing in the dark.

Here's where I'm at:

I am using the CORE_RL_wand_.dll found in the ImageMagick-6.3.5-Q16 folder (the download said this was the dll folder for windows).

So far, I am able to read and write image files, convert between formats, and resize. That by itself is pretty useful. I seem to be able to use some of the 'image' functions that I have tried, like the oil painting filter seems to work, but others either do nothing or produce unexpected results. (eg. The blur filter does nothing, and the Guassian blur and emboss filters turn the entire image black).

As yet, I have not been able to use any of the 'Draw' functions - like drawing a simple rectangle, or annotating an image with text - they just do nothing.

This works, as an example of reading an image and writing it in a different format:

Code: Select all

load dll "CORE_RL_wand_.dll",1
call dll 1,"MagickWandGenesis"

magick_wand=call dll(1,"NewMagickWand")
result=call dll(1,"MagickReadImage",magick_wand,"logo.jpg")
result=call dll(1,"MagickWriteImage",magick_wand,"output.png")

call dll 1,"MagickWandTerminus"
(Note: the 'call dll' command can return a single result in the form of integer or string if you want it to just by adding 'result=' for an integer or 'result$=' for a string infront, and adding brackets around the list of parameters.)

This does not work - (I'm trying to draw a red rectangle onto an image) - perhaps I'm just going about it wrong, I don't know:

Code: Select all

load dll "CORE_RL_wand_.dll",1
call dll 1,"MagickWandGenesis"

magick_wand=call dll(1,"NewMagickWand")
drawing_wand=call dll(1,"NewDrawingWand")
pixel_wand=call dll(1,"NewPixelWand")

result=call dll(1,"MagickReadImage",magick_wand,"logo.jpg")
result=call dll(1,"PixelSetColor",pixel_wand,"rgb(255,0,0)")
result=call dll(1,"DrawSetStrokeColor",drawing_wand,pixel_wand)
result=call dll(1,"DrawSetFillColor",drawing_wand,pixel_wand)
result=call dll(1,"DrawRectangle",drawing_wand,10,10,100,100)


result=call dll(1,"DrawRender",drawing_wand)
result=call dll(1,"MagickDrawImage",magick_wand,drawing_wand)
result=call dll(1,"MagickWriteImage",magick_wand,"output.png")

call dll 1,"MagickWandTerminus"
I know it's finding the correct functions in the dll, because it runs without crashing .... it just doesn't do anything - I'm suspecting that the CORE_RL_wand_.dll is relying on other dll's that it can't find? For example, I know that to render text, Imagemagick uses the freetype2 dll - but where is it? I can't see it in the folder.

By the way, I found the thread that el supremo refered to - viewtopic.php?f=1&t=8313&view=previous. (As it happens, I know the poster of that thread from the forum for DBP, so I will contact him to see if he has got anywhere.)

Re: A few questions about getting started - general advice neede

Posted: 2007-07-13T09:14:18-07:00
by el_supremo
I tried your example, using "logo:" as the input file, and it works.
When you say your drawing example doesn't do anything do you mean that it doesn't create the output.png file, or that the output.png file doesn't have a red rectangle drawn on it?
A few notes:
- MagickReadImage and MagickWriteImage return a boolean result. It's best to test both of them to make sure the functions worked and it also doesn't hurt to make sure that the wands aren't null when you create them. If MagickWriteImage fails, for example, the original output.png will still be there and it will look as though the script finished normally but didn't do anything.
- You don't need DrawRender() in this case. MagickDrawImage() draws the drawing wand's contents on the magick wand.
- just before MagickWandTerminus(), you should destroy each of the wands that you've created. e.g.

Code: Select all

magick_wand = call dll(1,"DestroyMagickWand",magick_wand)
- You mentioned that DBP could return an integer or a string as a result - but can it pass floating point doubles as arguments? Both the oil painting filter and the blur functions require floating point doubles as arguments.
- if you can get scripts to work properly, you may find that the Q16 version of IM is overkill for your needs. Images take up twice as much memory as the Q8 version and the processing time is also a lot slower.

Pete

Re: A few questions about getting started - general advice neede

Posted: 2007-07-13T09:45:52-07:00
by el_supremo
Ahhh. DrawRectangle also requires that you can pass doubles! That may be the problem with all those functions.

Pete

Re: A few questions about getting started - general advice neede

Posted: 2007-07-14T01:12:15-07:00
by Andromedus
Ok - thanks for the information. I think it should be possible to pass doubles from DBP - this works to an extent:

Code: Select all

load dll "CORE_RL_wand_.dll",1
call dll 1,"MagickWandGenesis"

magick_wand=call dll(1,"NewMagickWand")
drawing_wand=call dll(1,"NewDrawingWand")
pixel_wand=call dll(1,"NewPixelWand")

result=call dll(1,"MagickReadImage",magick_wand,"logo:")
result=call dll(1,"PixelSetColor",pixel_wand,"rgb(255,0,0)")
result=call dll(1,"DrawSetStrokeColor",drawing_wand,pixel_wand)
result=call dll(1,"DrawSetFillColor",drawing_wand,pixel_wand)
x1 as double float
y1 as double float
x2 as double float
y2 as double float
x1=200
y1=100
x2=400
y2=200
result=call dll(1,"DrawRectangle",drawing_wand,x1,y1,x2,y2)
result=call dll(1,"MagickDrawImage",magick_wand,drawing_wand)
result=call dll(1,"MagickWriteImage",magick_wand,"output.png")

call dll 1,"MagickWandTerminus"
.... in that now, It does actually draw a red rectangle onto the image, whereas before the image was being written unchanged. However, the rectangle is not as I would have expected - it is a red rectangle of width 200 and height 100, starting at the top left of the image. I expected from the values I passed to get a rectangle starting at 200,100 from the top left, with width 400 and height 200. Either I have misunderstood the meaning of the parameters, or they are getting muddles/lost on the way from DBPro to IM.

I seem to have an even bigger problem now, though - it doesn't appear to be possible to redistribute my program. My program is in the IM intallation folder, and I imagined that if I copied the whole folder I would be able to move it to a different location or send it to a friend for testing. however, as soon as I move the folder, or even just change the name of the folder from 'ImageMagick-6.3.5-Q16' to anything else, the program stops working (it doesn't crash, it just does nothing). I don't understand how this could be - all the dll's are in the same relative positions within the folder - how can they know their absolute path? This problem means that the end user of my program would have to install IM first, and run my program from their installation folder - which is no good for my purposes.

I think the best solution to all of this would be to create a dedicated wrapper for DBP - unfortunately I don't have the tools to do it so I'll see if anyone at the DBP forum is interested in picking up the challenge.

Re: A few questions about getting started - general advice neede

Posted: 2007-07-14T08:49:52-07:00
by el_supremo
it is a red rectangle of width 200 and height 100
correct
starting at the top left of the image
Nope. Obviously shouldn't be doing that.
For DrawRectangle, (x2,y2) are not width and height, they are the bottom right coordinate.
It does look like something's getting muddled along the way between IM and DBP but I can't see how it can get the width and height correct but put it in the wrong place.

how can they know their absolute path?
It sounds like they are getting their path from the MAGICK_HOME environment variable which must have been set when you installed IM. Perhaps Anthony or the Magickian could help you with that.

Pete

Re: A few questions about getting started - general advice neede

Posted: 2007-07-15T18:20:47-07:00
by anthony
More than likely it is a difference between API usage and MagickCore usage.

It may be that the draw rectangle take a geometry type of argument set rather than
coordinates. EG WxH+x+y

Is the rectangle in the right place?

Re: A few questions about getting started - general advice neede

Posted: 2007-07-16T08:14:39-07:00
by Andromedus
To answer your question, the rectangle is always positioned at the top left, and the first two parameters always determine the width and height. As far as I can tell, the second two parameters don't have any effect at all.

However - the problems of calling the dll directly look like they may not be an issue anymore, as someone from the DBP community who has the resources and the knowhow has kindly volunteered to create a dedicated api for DBP. This is great news for a lot of DBP users who will now be able to open up the potential of IM. :)

Thanks for your help in getting the ball rolling,

Cheers,

Ric.