www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.announce - DMagick image processing with D.

reply Mike Wey <mike-wey example.com> writes:
I'm happy to announce the first DMagick release.

DMagick is an object-oriented D API to the ImageMagick image-processing 
library. With an interface inspired by Magick++ and RMagick.

DMagick requires a recent D2 compiler >= 2.054 and works with 
ImageMagick 6.6.0 and up.

DMagick can be found here: http://code.mikewey.eu/p/DMagick/

Downloads: http://code.mikewey.eu/p/DMagick/downloads/
Documentation: http://dmagick.mikewey.eu/docs/

-- 
Mike Wey
Nov 02 2011
next sibling parent reply bearophile <bearophileHUGS lycos.com> writes:
Mike Wey:

 I'm happy to announce the first DMagick release.

This looks like a quite useful package. Bye, bearophile
Nov 02 2011
next sibling parent Andrej Mitrovic <andrej.mitrovich gmail.com> writes:
Btw, with warnings turned on I get:
..\dmagick\Image.d(236): Warning: overrides base class function
object.Object.toString, but is not marked with 'override'
Nov 02 2011
prev sibling next sibling parent reply Andrej Mitrovic <andrej.mitrovich gmail.com> writes:
It would be easier not having to register on a custom website just to
issue reports. But anyway this line triggers a runtime exception:

Line 256, dmagick/Image.d:
result ~= std.string.format("%sx%s%+ld%+ld ",
				imageRef.page.width, imageRef.page.height,
				imageRef.page.x,     imageRef.page.y);

std.format.FormatException std\format.d(4094): formatArg

Personally, it's because of issues like this I never use any other
specifier but %s. It's hard to track this down with no line numbers,
and that exception message that points to internal code is completely
useless. Ah, phobos...
Nov 02 2011
parent Mike Wey <mike-wey example.com> writes:
On 11/03/2011 02:31 AM, Andrej Mitrovic wrote:
 It would be easier not having to register on a custom website just to
 issue reports. But anyway this line triggers a runtime exception:

I've thought about moving to Github, maybe i should finally look take the time to set things up. -- Mike Wey
Nov 03 2011
prev sibling next sibling parent Andrej Mitrovic <andrej.mitrovich gmail.com> writes:
I was trying to export pixels:
auto pixels = image.exportPixels!byte(area, "RGB");

But got:
..\dmagick\Image.d(1340): Error: cannot implicitly convert expression
(pixels) of type void[] to byte[]

I think you might need to change Line 1340, dmagick/Image.d:
return pixels;

to this:
return cast(typeof(return))pixels;

Still, with this change I get an access violation in the statement
before it that calls ExportImagePixels. Ddbg says:

Unhandled Exception: EXCEPTION_ACCESS_VIOLATION(0xc0000005) at
CORE_RL_magick_.dll (0x100c1267) thread(3440)

These were my calls:
    Image image = new Image("newbitmap.bmp");
    int x, y;
    auto area = Geometry(100, 100, x, y);
    auto pixels = image.exportPixels!byte(area, "RGB");

newbitmap.bmp is a 614x768x8bit bitmap.
Nov 02 2011
prev sibling next sibling parent Andrej Mitrovic <andrej.mitrovich gmail.com> writes:
On 11/3/11, Andrej Mitrovic <andrej.mitrovich gmail.com> wrote:
 Unhandled Exception: EXCEPTION_ACCESS_VIOLATION(0xc0000005) at
 CORE_RL_magick_.dll (0x100c1267) thread(3440)

I think I've found the issue: void[] pixels = new T[area.width*area.height]; Here you're allocating width*height, but you didn't take into account that each exported channel specified by map will need more width*height storage. Here's what I did to fix it: import std.utf; auto pixels = new T[]((area.width * area.height) * map.count); // call ExportImagePixels return pixels; I think the DLL tried to write to memory beyond what the GC allocated for the array, and hence the access violation.
Nov 02 2011
prev sibling next sibling parent Andrej Mitrovic <andrej.mitrovich gmail.com> writes:
Ok I'll stop spamming here and report on your site, here's issue 1:
http://code.mikewey.eu/p/DMagick/issues/1/
Nov 02 2011
prev sibling next sibling parent reply Andrej Mitrovic <andrej.mitrovich gmail.com> writes:
I've started a new repo where I'll be writing some DMagick (win32)
sample apps. I have a simple one now that loads an image to a
DibSection and blits it to the screen:

https://github.com/AndrejMitrovic/DMagickSamples

Note that I've had to add a couple of fixes to the library, so I'm
distributing it with the samples.
Nov 03 2011
parent Mike Wey <mike-wey example.com> writes:
On 11/03/2011 06:43 PM, Andrej Mitrovic wrote:
 I've started a new repo where I'll be writing some DMagick (win32)
 sample apps. I have a simple one now that loads an image to a
 DibSection and blits it to the screen:

 https://github.com/AndrejMitrovic/DMagickSamples

 Note that I've had to add a couple of fixes to the library, so I'm
 distributing it with the samples.

I've merged in the the fixes you added. I see that you have removed the shared static this from Image.d, is initializing ImageMagick unnecessary on Windows? I've never tested without initializing though. -- Mike Wey
Nov 03 2011
prev sibling next sibling parent reply Mike Wey <mike-wey example.com> writes:
On 11/03/2011 01:42 AM, Andrej Mitrovic wrote:
 sigmoidalContrast.d works, although draw.d doesn't:

 Magick: unable to read font ` ghostscript_font_path n019003l.pfb'  
 error/annotate.c/RenderFreetype/1120.
 Magick: unable to read font ` ghostscript_font_path n019003l.pfb'  
 error/annotate.c/RenderFreetype/1120.
 dmagick.Exception.XServerError dmagick\Image.d(1142): Magick: unable
 to open X server `'   error/display.c/DisplayImages/1662
 ----------------
 4C004C
 451F2B
 40CCF0
 415E4C
 415E90
 415A87
 52F2C5
 ----------------

 I guess displaying is only possible via X server? Otherwise I guess I
 could fetch the raw bytes of the image and display that via GDI/etc.
 I've seen a toBlob function in there somewhere, maybe I can use that.

 I've never used this lib before but it will definitely come in handy.
 Thanks for your hard work, Mike!

If you get displaying with GDI working it might be worth adding it to DMagick, so that every windows user can display images easily. -- Mike Wey
Nov 03 2011
parent reply Mike Wey <mike-wey example.com> writes:
On 11/03/2011 10:22 PM, Andrej Mitrovic wrote:
 On 11/3/11, Mike Wey<mike-wey example.com>  wrote:
 If you get displaying with GDI working it might be worth adding it to
 DMagick, so that every windows user can display images easily.

Yeah it is working, but I'll refactor it a little bit to make it more generic and to avoid buffer reallocations in the code. If you put your project on github I could make a pull, otherwise we can use your webby.

https://github.com/MikeWey/DMagick -- Mike Wey
Nov 04 2011
parent reply Mike Wey <mike-wey example.com> writes:
On 11/04/2011 08:15 PM, Andrej Mitrovic wrote:
 On 11/4/11, Mike Wey<mike-wey example.com>  wrote:
 On 11/03/2011 10:22 PM, Andrej Mitrovic wrote:
 On 11/3/11, Mike Wey<mike-wey example.com>   wrote:
 If you get displaying with GDI working it might be worth adding it to
 DMagick, so that every windows user can display images easily.

Yeah it is working, but I'll refactor it a little bit to make it more generic and to avoid buffer reallocations in the code. If you put your project on github I could make a pull, otherwise we can use your webby.

https://github.com/MikeWey/DMagick

Sweet! Btw, your copydll.bat script calls a "where" utility but I can't figure out where to download it (pardon the pun). I have a custom 'where' batch script from before but it doesn't work with copydll.bat.

I look like where is only included in recent Windows versions. I've changed the script so that it should also work on older Windows versions. -- Mike Wey
Nov 04 2011
parent reply nrgyzer <nrgyzer unknown.com> writes:
Thanks for DMagick... works great, except toBlob(). When I try the following:

Image example = new Image(Geometry(100, 100), new ColorRGB(0, 255, 0));
example.toBlob();

I get an access violation. Do I anything wrong or is it a bug? (I'm using
Imagick
6.7.6, DMD64 and CentOS)
Apr 08 2012
parent reply Mike Wey <mike-wey example.com> writes:
On 04/08/2012 06:19 PM, nrgyzer wrote:
 Thanks for DMagick... works great, except toBlob(). When I try the following:

 Image example = new Image(Geometry(100, 100), new ColorRGB(0, 255, 0));
 example.toBlob();

 I get an access violation. Do I anything wrong or is it a bug? (I'm using
Imagick
 6.7.6, DMD64 and CentOS)

It's a bug. -- Mike Wey
Apr 09 2012
parent Mike Wey <mike-wey example.com> writes:
On 04/09/2012 01:37 PM, Mike Wey wrote:
 On 04/08/2012 06:19 PM, nrgyzer wrote:
 Thanks for DMagick... works great, except toBlob(). When I try the
 following:

 Image example = new Image(Geometry(100, 100), new ColorRGB(0, 255, 0));
 example.toBlob();

 I get an access violation. Do I anything wrong or is it a bug? (I'm
 using Imagick
 6.7.6, DMD64 and CentOS)

It's a bug.

And fixed, but you will need to set Image.magick or pass it to toBlob to tell Imagemagick what kind of blob you want. -- Mike Wey
Apr 09 2012
prev sibling next sibling parent Andrej Mitrovic <andrej.mitrovich gmail.com> writes:
On 11/3/11, Mike Wey <mike-wey example.com> wrote:
 If you get displaying with GDI working it might be worth adding it to
 DMagick, so that every windows user can display images easily.

Yeah it is working, but I'll refactor it a little bit to make it more generic and to avoid buffer reallocations in the code. If you put your project on github I could make a pull, otherwise we can use your webby.
Nov 03 2011
prev sibling next sibling parent Andrej Mitrovic <andrej.mitrovich gmail.com> writes:
On 11/3/11, Mike Wey <mike-wey example.com> wrote:
 I've merged in the the fixes you added.

 I see that you have removed the shared static this from Image.d, is
 initializing ImageMagick unnecessary on Windows?

Well it causes access violations on application start like I've mentioned in the bug report. Without the calls the violations are gone and I can use ImageMagick, for now nothing seems to be wrong when I don't call those init functions.
Nov 03 2011
prev sibling parent Andrej Mitrovic <andrej.mitrovich gmail.com> writes:
On 11/4/11, Mike Wey <mike-wey example.com> wrote:
 On 11/03/2011 10:22 PM, Andrej Mitrovic wrote:
 On 11/3/11, Mike Wey<mike-wey example.com>  wrote:
 If you get displaying with GDI working it might be worth adding it to
 DMagick, so that every windows user can display images easily.

Yeah it is working, but I'll refactor it a little bit to make it more generic and to avoid buffer reallocations in the code. If you put your project on github I could make a pull, otherwise we can use your webby.

https://github.com/MikeWey/DMagick

Sweet! Btw, your copydll.bat script calls a "where" utility but I can't figure out where to download it (pardon the pun). I have a custom 'where' batch script from before but it doesn't work with copydll.bat.
Nov 04 2011
prev sibling parent Andrej Mitrovic <andrej.mitrovich gmail.com> writes:
sigmoidalContrast.d works, although draw.d doesn't:

Magick: unable to read font ` ghostscript_font_path n019003l.pfb'  
error/annotate.c/RenderFreetype/1120.
Magick: unable to read font ` ghostscript_font_path n019003l.pfb'  
error/annotate.c/RenderFreetype/1120.
dmagick.Exception.XServerError dmagick\Image.d(1142): Magick: unable
to open X server `'   error/display.c/DisplayImages/1662
----------------
4C004C
451F2B
40CCF0
415E4C
415E90
415A87
52F2C5
----------------

I guess displaying is only possible via X server? Otherwise I guess I
could fetch the raw bytes of the image and display that via GDI/etc.
I've seen a toBlob function in there somewhere, maybe I can use that.

I've never used this lib before but it will definitely come in handy.
Thanks for your hard work, Mike!
Nov 02 2011