diff options
| author | Mike Wey | 2011-01-16 23:38:30 +0100 |
|---|---|---|
| committer | Mike Wey | 2011-01-16 23:38:30 +0100 |
| commit | 5fb0b8af93eabceb03d4914de945f8f3a5ec2bf2 (patch) | |
| tree | 56f45702a054419f3ae263711a5c8d942febd3c9 | |
| parent | 22835c8eb5458d510f7765df88ce8c9b34af787e (diff) | |
Implement most of the ImageInfo properties
| -rw-r--r-- | dmagick/Options.d | 386 |
1 files changed, 382 insertions, 4 deletions
diff --git a/dmagick/Options.d b/dmagick/Options.d index 5896260..b01e62a 100644 --- a/dmagick/Options.d +++ b/dmagick/Options.d @@ -1,7 +1,20 @@ +/** + * A class to expose ImageInfo QuantizeInfo and DrawInfo + * + * Copyright: Mike Wey 2011 + * License: To be determined + * Authors: Mike Wey + */ + + module dmagick.Options; +import std.conv; +import core.stdc.string; + import dmagick.c.draw; import dmagick.c.image; +import dmagick.c.magickString; import dmagick.c.magickType; import dmagick.c.memory; import dmagick.c.quantize; @@ -34,12 +47,377 @@ class Options drawInfo = DestroyDrawInfo(drawInfo); } - private void copyString(ref char[MaxTextExtent] field, string str) + //ImageInfo fields + + void adjoin(bool flag) + { + imageInfo.adjoin = flag; + } + bool adjoin() + { + return imageInfo.adjoin; + } + + /** + * Set the image background color. The default is "white". + */ + //void backgroundColor(string color) + //{ + // + //} + //void backgroundColor(Color color) + //{ + // + //} + //Color backgroundColor() + //{ + // + //} + + /** + * Set a texture to tile onto the image background. + * Corresponds to the -texture option to ImageMagick's + * convert and mogrify commands. + */ + void backgroundTexture(string str) + { + copyString(imageInfo.texture, str); + } + string backgroundTexture() + { + return to!(string)(imageInfo.texture); + } + + //void borderColor(Color color) + //{ + // + //} + //Color borderColor() + //{ + // + //} + + /** + * Set the image border color. The default is "#dfdfdf". + */ + void colorspace(ColorspaceType space) + { + imageInfo.colorspace = space; + } + ColorspaceType colorspace() + { + return imageInfo.colorspace; + } + + void compression(CompressionType compress) + { + imageInfo.compression = compress; + } + CompressionType compression() + { + return imageInfo.compression; + } + + //void ddebug(bool d) + //{ + // + //} + //bool ddebug() + //{ + // + //} + + void density(string str) + { + copyString(imageInfo.density, str); + } + string density() + { + return to!(string)(imageInfo.density); + } + + void depth(size_t d) + { + imageInfo.depth = d; + } + size_t depth() + { + return imageInfo.depth; + } + + void dither(bool d) { - if ( str.length >= MaxTextExtent ) + imageInfo.dither = d; + } + size_t dither() + { + return imageInfo.dither; + } + + void endian(EndianType type) + { + imageInfo.endian = type; + } + EndianType endian() + { + return imageInfo.endian; + } + + void file(FILE* f) + { + imageInfo.file = f; + } + FILE* file() + { + return imageInfo.file; + } + + void filename(string str) + { + copyString(imageInfo.filename, str); + } + string filename() + { + return imageInfo.filename[0 .. strlen(imageInfo.filename.ptr)].idup; + } + + void font(string str) + { + copyString(imageInfo.font, str); + copyString(drawInfo.font, str); + } + string font() + { + return to!(string)(drawInfo.font); + } + + void fuzz(double f) + { + imageInfo.fuzz = f; + } + double fuzz() + { + return imageInfo.fuzz; + } + + void interlace(InterlaceType type) + { + imageInfo.interlace = type; + } + InterlaceType interlace() + { + return imageInfo.interlace; + } + + void magick(string str) + { + copyString(imageInfo.magick, str); + } + string magick() + { + return imageInfo.magick[0 .. strlen(imageInfo.magick.ptr)].idup; + } + + //void matteColor(Color color) + //{ + // + //} + //Color matteColor() + //{ + // + //} + + void monochrome(bool m) + { + imageInfo.monochrome = m; + } + bool monochrome() + { + return imageInfo.monochrome; + } + + void numberOfScenes(size_t num) + { + imageInfo.number_scenes = num; + } + size_t numberOfScenes() + { + return imageInfo.number_scenes; + } + + void page(string str) + { + copyString(imageInfo.page, str); + } + string page() + { + return to!(string)(imageInfo.page); + } + + void pointSize(double size) + { + imageInfo.pointsize = size; + drawInfo.pointsize = size; + } + double pointSize() + { + return drawInfo.pointsize; + } + + void quality(size_t q) + { + imageInfo.quality = q; + } + size_t quality() + { + return imageInfo.quality; + } + + void resolutionUnits(ResolutionType type) + { + imageInfo.units = type; + } + ResolutionType resolutionUnits() + { + return imageInfo.units; + } + + void samplingFactor(string str) + { + copyString(imageInfo.sampling_factor, str); + } + string samplingFactor() + { + return to!(string)(imageInfo.sampling_factor); + } + + void scene(size_t num) + { + imageInfo.scene = num; + } + size_t scene() + { + return imageInfo.scene; + } + + void size(string str) + { + copyString(imageInfo.size, str); + } + string size() + { + return to!(string)(imageInfo.size); + } + + void type(ImageType t) + { + imageInfo.type = t; + } + ImageType type() + { + return imageInfo.type; + } + + void verbose(bool v) + { + imageInfo.verbose = v; + } + bool verbose() + { + return imageInfo.verbose; + } + + void view(string str) + { + copyString(imageInfo.view, str); + } + string view() + { + return to!(string)(imageInfo.view); + } + + //TODO: Delegates? + void virtualPixelMethod(VirtualPixelMethod method) + { + imageInfo.virtual_pixel_method = method; + } + VirtualPixelMethod virtualPixelMethod() + { + return imageInfo.virtual_pixel_method; + } + + void x11Display(string str) + { + copyString(imageInfo.server_name, str); + } + string x11Display() + { + return to!(string)(imageInfo.server_name); + } + + ////OrientationType orientation; + ////MagickBooleanType temporary, + ////MagickBooleanType affirm, + ////MagickBooleanType antialias; + ////char* extract, + ////char* scenes; + ////size_t colors; + ////PreviewType preview_type; + ////ssize_t group; + ////MagickBooleanType ping, + ////char* authenticate; + ////ChannelType channel; + ////void* options; + ////MagickProgressMonitor progress_monitor; + ////void* client_data, + ////void* cache; + ////StreamHandler stream; + ////void* blob; + ////size_t length; + ////char[MaxTextExtent] unique, + ////char[MaxTextExtent] zero, + ////size_t signature; + ////PixelPacket transparent_color; + ////void* profile; + ////MagickBooleanType synchronize; + + private void copyString(ref char[MaxTextExtent] dest, string source) + { + if ( source.length < MaxTextExtent ) throw new Exception("text is to long"); //TODO: a proper exception. - field[0 .. str.length] = str; - field[str.length] = '\0'; + dest[0 .. source.length] = str; + dest[source.length] = '\0'; + } + + /** + * Using CloneString whould force us to append a \0 + * to the end of the string which might relocate the sting, + * and that is wastefull if we are just going to copy it. + */ + private void copyString(ref char* dest, string source) + { + if ( source is null ) + { + if ( dest !is null ) + DestroyString(dest); + return; + } + + if ( ~source.length < MaxTextExtent ) + throw new Exception("UnableToAcquireString"); //TODO: a proper exception. + + if ( dest is null ) + dest = cast(char*)AcquireQuantumMemory(dest, source.length+MaxTextExtent, dest.sizeof); + else + dest = cast(char*)ResizeQuantumMemory(dest, source.length+MaxTextExtent, dest.sizeof); + + if ( dest is null ) + throw new Exception("UnableToAcquireString"); //TODO: a proper exception. + + if ( source.length > 0 ) + dest[0 .. source.length] = str; + + dest[source.length] = '\0'; } } |
