From 3ed1fbe92d211db72fa22935d6208a84c4df1b40 Mon Sep 17 00:00:00 2001 From: Mike Wey Date: Sun, 20 Mar 2011 22:32:33 +0100 Subject: Make the getters const --- dmagick/Color.d | 69 +++++++++++++++++---------------- dmagick/Image.d | 90 +++++++++++++++++++++++++++++++------------ dmagick/Options.d | 112 +++++++++++++++++++++++++++--------------------------- 3 files changed, 158 insertions(+), 113 deletions(-) diff --git a/dmagick/Color.d b/dmagick/Color.d index 982be21..ddb4bbd 100644 --- a/dmagick/Color.d +++ b/dmagick/Color.d @@ -23,14 +23,14 @@ import dmagick.c.quantum; */ class Color { - PixelPacket* pixelPacket; + PixelPacket* packet; /** */ this() { - pixelPacket = new PixelPacket; + packet = new PixelPacket; - pixelPacket.opacity = TransparentOpacity; + packet.opacity = TransparentOpacity; } /** @@ -40,10 +40,10 @@ class Color { this(); - pixelPacket.red = red; - pixelPacket.green = green; - pixelPacket.blue = blue; - pixelPacket.opacity = opacity; + packet.red = red; + packet.green = green; + packet.blue = blue; + packet.opacity = opacity; } /** @@ -56,7 +56,7 @@ class Color ExceptionInfo* exception = AcquireExceptionInfo(); const(char)* name = toStringz(color); - QueryColorDatabase(name, pixelPacket, exception); + QueryColorDatabase(name, packet, exception); DMagickException.throwException(exception); DestroyExceptionInfo(exception); @@ -69,10 +69,10 @@ class Color { this(); - pixelPacket.red = packet.red; - pixelPacket.green = packet.green; - pixelPacket.blue = packet.blue; - pixelPacket.opacity = packet.opacity; + packet.red = packet.red; + packet.green = packet.green; + packet.blue = packet.blue; + packet.opacity = packet.opacity; } /** @@ -81,12 +81,17 @@ class Color */ this(PixelPacket* packet) { - pixelPacket = packet; + packet = packet; + } + + PixelPacket pixelPacket() + { + return *packet; } bool opEquals(Color color) { - return *pixelPacket == *(color.pixelPacket); + return pixelPacket == color.pixelPacket; } override string toString() @@ -98,12 +103,12 @@ class Color else string frm = "%08X"; - if ( pixelPacket.opacity == 0 ) + if ( packet.opacity == 0 ) frm = "#" ~ frm ~ frm ~ frm; else frm = "#" ~ frm ~ frm ~ frm ~ frm; - return format(frm, pixelPacket.red, pixelPacket.green, pixelPacket.blue, pixelPacket.opacity); + return format(frm, packet.red, packet.green, packet.blue, packet.opacity); } /** @@ -111,12 +116,12 @@ class Color */ void redQuantum(Quantum red) { - pixelPacket.red = red; + packet.red = red; } ///ditto Quantum redQuantum() { - return pixelPacket.red; + return packet.red; } /** @@ -124,12 +129,12 @@ class Color */ void greenQuantum(Quantum green) { - pixelPacket.green = green; + packet.green = green; } ///ditto Quantum greenQuantum() { - return pixelPacket.green; + return packet.green; } /** @@ -137,12 +142,12 @@ class Color */ void blueQuantum(Quantum blue) { - pixelPacket.blue = blue; + packet.blue = blue; } ///ditto Quantum blueQuantum() { - return pixelPacket.blue; + return packet.blue; } /** @@ -150,12 +155,12 @@ class Color */ void opacityByte(ubyte opacity) { - pixelPacket.opacity = ScaleCharToQuantum(opacity); + packet.opacity = ScaleCharToQuantum(opacity); } ///ditto ubyte opacityByte() { - return ScaleQuantumToChar(pixelPacket.opacity); + return ScaleQuantumToChar(packet.opacity); } /** @@ -163,12 +168,12 @@ class Color */ void opacityQuantum(Quantum opacity) { - pixelPacket.opacity = opacity; + packet.opacity = opacity; } ///ditto Quantum opacityQuantum() { - return pixelPacket.opacity; + return packet.opacity; } /** @@ -176,12 +181,12 @@ class Color */ void opacity(double opacity) { - pixelPacket.opacity = scaleDoubleToQuantum(opacity); + packet.opacity = scaleDoubleToQuantum(opacity); } ///ditto double opacity() { - return scaleQuantumToDouble(pixelPacket.opacity); + return scaleQuantumToDouble(packet.opacity); } /** @@ -192,7 +197,7 @@ class Color //The Constants used here are derived from BT.709 Which standardizes HDTV return scaleQuantumToDouble(cast(Quantum)( - 0.2126*pixelPacket.red+0.7152*pixelPacket.green+0.0722*pixelPacket.blue)); + 0.2126*packet.red+0.7152*packet.green+0.0722*packet.blue)); } /** @@ -200,7 +205,7 @@ class Color */ Color clone() { - return new Color(*pixelPacket); + return new Color(pixelPacket); } /** @@ -223,8 +228,8 @@ class Color MagickPixelPacket color = colorList[i].color; - if ( pixelPacket.red == color.red && pixelPacket.green == color.green - && pixelPacket.blue == color.blue && pixelPacket.opacity == color.opacity ) + if ( packet.red == color.red && packet.green == color.green + && packet.blue == color.blue && packet.opacity == color.opacity ) return to!(string)(colorList[i].name); } diff --git a/dmagick/Image.d b/dmagick/Image.d index ad99f09..7747d35 100644 --- a/dmagick/Image.d +++ b/dmagick/Image.d @@ -18,11 +18,15 @@ import dmagick.Utils; import dmagick.c.attribute; import dmagick.c.blob; import dmagick.c.constitute; +import dmagick.c.colormap; +import dmagick.c.colorspace; import dmagick.c.effect; import dmagick.c.exception; import dmagick.c.geometry; import dmagick.c.image; import dmagick.c.magickType; +import dmagick.c.memory; +import dmagick.c.pixel; import dmagick.c.resize; import dmagick.c.resource; @@ -322,7 +326,7 @@ class Image { imageRef.delay = delay; } - size_t annimationDelay() + size_t annimationDelay() const { return imageRef.delay; } @@ -331,7 +335,7 @@ class Image { imageRef.iterations = iterations; } - size_t animationIterations() + size_t animationIterations() const { return imageRef.iterations; } @@ -348,10 +352,10 @@ class Image { options.backgroundColor(color); - imageRef.background_color = *(color.pixelPacket); + imageRef.background_color = color.pixelPacket; } ///ditto - Color backgroundColor() + Color backgroundColor() //const { return options.backgroundColor; } @@ -368,15 +372,15 @@ class Image { options.borderColor = color; - imageRef.border_color = *(color.pixelPacket); + imageRef.border_color = color.pixelPacket; } ///ditto - Color borderColor() + Color borderColor() //const { return options.borderColor; } - Geometry boundingBox() + Geometry boundingBox() const { ExceptionInfo* exception = AcquireExceptionInfo(); RectangleInfo box = GetImageBoundingBox(imageRef, exception); @@ -397,7 +401,7 @@ class Image { SetImageChannelDepth(imageRef, channel, depth); } - size_t channelDepth(ChannelType channel) + size_t channelDepth(ChannelType channel) const { ExceptionInfo* exception = AcquireExceptionInfo(); size_t depth = GetImageChannelDepth(imageRef, channel, exception); @@ -412,7 +416,7 @@ class Image { imageRef.chromaticity = chroma; } - ChromaticityInfo chromaticity() + ChromaticityInfo chromaticity() const { return imageRef.chromaticity; } @@ -422,7 +426,7 @@ class Image { imageRef.storage_class = type; } - ClassType classType() + ClassType classType() const { return imageRef.storage_class; } @@ -441,7 +445,7 @@ class Image SetImageClipMask(imageRef, image.imageRef); } - Image clipMask() + Image clipMask() const { ExceptionInfo* exception = AcquireExceptionInfo(); MagickCoreImage* image = CloneImage(imageRef.clip_mask, 0, 0, true, exception); @@ -452,39 +456,66 @@ class Image return new Image(image); } - auto colorMap() + auto colormap() { - struct ColorMap + struct Colormap { + Image img; + + this(Image img) + { + this.img = img; + } + Color opIndex(uint index) { - if ( index >= colorMapSize ) + if ( index >= img.colormapSize ) throw new Exception("Index out of bounds"); - return new Color(imageRef.colormap[index]); + return new Color(img.imageRef.colormap[index]); } void opIndexAssign(Color value, uint index) { - if ( index > colorMapSize ) + if ( index >= img.colormapSize ) throw new Exception("Index out of bounds"); - if ( index == colorMapSize ) - colorMapSize = index + 1; + img.imageRef.colormap[index] = value.pixelPacket; + } + + void opOpAssign(string op)(Color color) if ( op == "~" ) + { + img.colormapSize = img.colormapSize + 1; - imageRef.colormap[index] = *(vaule.pixelPacket) + this[img.colormapSize] = color; } - size_t opDollar() + void opOpAssign(string op)(Color[] colors) if ( op == "~" ) { - return imageRef.colors; + uint oldSize = img.colormapSize; + + img.colormapSize = oldSize + colors.length; + + foreach ( i; oldSize..img.colormapSize) + { + this[i] = colors[i]; + } + } + + uint size() + { + return img.colormapSize; + } + void size(uint s) + { + img.colormapSize = s; } } - return ColorMap(); + return Colormap(this); } - void colorMapSize(uint size) + void colormapSize(uint size) { if ( size > MaxColormapSize ) throw new OptionException( @@ -512,11 +543,20 @@ class Image imageRef.colors = size; } - uint colorMapSize() const + uint colormapSize() const { return cast(uint)imageRef.colors; } + void colorspace(ColorspaceType type) + { + TransformImageColorspace(imageRef, type); + } + ColorspaceType colorspace() const + { + return imageRef.colorspace; + } + size_t columns() const { return imageRef.columns; @@ -534,7 +574,7 @@ class Image imageRef.fuzz = f; } ///ditto - double fuzz() + double fuzz() //const { return options.fuzz; } diff --git a/dmagick/Options.d b/dmagick/Options.d index 082e455..131b67f 100644 --- a/dmagick/Options.d +++ b/dmagick/Options.d @@ -80,7 +80,7 @@ class Options imageInfo.adjoin = flag; } ///ditto - bool adjoin() + bool adjoin() const { return imageInfo.adjoin == 1; } @@ -95,10 +95,10 @@ class Options ///ditto void backgroundColor(Color color) { - imageInfo.background_color = *(color.pixelPacket); + imageInfo.background_color = color.pixelPacket; } ///ditto - Color backgroundColor() + Color backgroundColor() const { return new Color(imageInfo.background_color); } @@ -113,7 +113,7 @@ class Options copyString(imageInfo.texture, str); } ///ditto - string backgroundTexture() + string backgroundTexture() const { return to!(string)(imageInfo.texture); } @@ -128,11 +128,11 @@ class Options ///ditto void borderColor(Color color) { - imageInfo.border_color = *(color.pixelPacket); - drawInfo.border_color = *(color.pixelPacket); + imageInfo.border_color = color.pixelPacket; + drawInfo.border_color = color.pixelPacket; } ///ditto - Color borderColor() + Color borderColor() const { return new Color(imageInfo.border_color); } @@ -145,7 +145,7 @@ class Options imageInfo.colorspace = space; } ///ditto - ColorspaceType colorspace() + ColorspaceType colorspace() const { return imageInfo.colorspace; } @@ -162,7 +162,7 @@ class Options imageInfo.compression = compress; } ///ditto - CompressionType compression() + CompressionType compression() const { return imageInfo.compression; } @@ -195,7 +195,7 @@ class Options density(geometry.toString()); } ///ditto - Geometry density() + Geometry density() const { return Geometry( to!(string)(imageInfo.density) ); } @@ -212,7 +212,7 @@ class Options imageInfo.depth = d; } ///ditto - size_t depth() + size_t depth() const { return imageInfo.depth; } @@ -232,7 +232,7 @@ class Options quantizeInfo.dither = d; } ///ditto - size_t dither() + size_t dither() const { return imageInfo.dither; } @@ -245,7 +245,7 @@ class Options imageInfo.endian = type; } ///ditto - EndianType endian() + EndianType endian() const { return imageInfo.endian; } @@ -271,7 +271,7 @@ class Options copyString(imageInfo.filename, str); } ///ditto - string filename() + string filename() const { return imageInfo.filename[0 .. strlen(imageInfo.filename.ptr)].idup; } @@ -293,7 +293,7 @@ class Options copyString(drawInfo.font, str); } ///ditto - string font() + string font() const { return to!(string)(drawInfo.font); } @@ -309,7 +309,7 @@ class Options imageInfo.fuzz = f; } ///ditto - double fuzz() + double fuzz() const { return imageInfo.fuzz; } @@ -329,7 +329,7 @@ class Options imageInfo.interlace = type; } ///ditto - InterlaceType interlace() + InterlaceType interlace() const { return imageInfo.interlace; } @@ -342,7 +342,7 @@ class Options copyString(imageInfo.magick, str); } ///ditto - string magick() + string magick() const { return imageInfo.magick[0 .. strlen(imageInfo.magick.ptr)].idup; } @@ -357,10 +357,10 @@ class Options ///ditto void matteColor(Color color) { - imageInfo.matte_color = *(color.pixelPacket); + imageInfo.matte_color = color.pixelPacket; } ///ditto - Color matteColor() + Color matteColor() const { return new Color(imageInfo.matte_color); } @@ -374,7 +374,7 @@ class Options imageInfo.monochrome = m; } ///ditto - bool monochrome() + bool monochrome() const { return imageInfo.monochrome == 1; } @@ -398,7 +398,7 @@ class Options page(geometry.toString()); } ///ditto - Geometry page() + Geometry page() const { return Geometry( to!(string)(imageInfo.page) ); } @@ -412,7 +412,7 @@ class Options drawInfo.pointsize = size; } ///ditto - double pointSize() + double pointSize() const { return drawInfo.pointsize; } @@ -427,7 +427,7 @@ class Options imageInfo.quality = q; } ///ditto - size_t quality() + size_t quality() const { return imageInfo.quality; } @@ -440,7 +440,7 @@ class Options imageInfo.units = type; } ///ditto - ResolutionType resolutionUnits() + ResolutionType resolutionUnits() const { return imageInfo.units; } @@ -461,7 +461,7 @@ class Options copyString(imageInfo.sampling_factor, str); } ///ditto - string samplingFactor() + string samplingFactor() const { return to!(string)(imageInfo.sampling_factor); } @@ -482,7 +482,7 @@ class Options size(geometry.toString()); } ///ditto - Geometry size() + Geometry size() const { return Geometry( to!(string)(imageInfo.size) ); } @@ -495,7 +495,7 @@ class Options imageInfo.scene = num; } ///ditto - size_t subImage() + size_t subImage() const { return imageInfo.scene; } @@ -508,7 +508,7 @@ class Options imageInfo.number_scenes = num; } ///ditto - size_t subRange() + size_t subRange() const { return imageInfo.number_scenes; } @@ -521,7 +521,7 @@ class Options imageInfo.type = t; } ///ditto - ImageType type() + ImageType type() const { return imageInfo.type; } @@ -534,7 +534,7 @@ class Options imageInfo.verbose = v; } ///ditto - bool verbose() + bool verbose() const { return imageInfo.verbose == 1; } @@ -547,7 +547,7 @@ class Options copyString(imageInfo.view, str); } ///ditto - string view() + string view() const { return to!(string)(imageInfo.view); } @@ -560,7 +560,7 @@ class Options imageInfo.virtual_pixel_method = method; } ///ditto - VirtualPixelMethod virtualPixelMethod() + VirtualPixelMethod virtualPixelMethod() const { return imageInfo.virtual_pixel_method; } @@ -574,7 +574,7 @@ class Options drawInfo.server_name = imageInfo.server_name; } ///ditto - string x11Display() + string x11Display() const { return to!(string)(imageInfo.server_name); } @@ -613,7 +613,7 @@ class Options { drawInfo.affine = affine; } - AffineMatrix affine() + AffineMatrix affine() const { return drawInfo.affine; } @@ -743,7 +743,7 @@ class Options drawInfo.text_antialias = antialias; } ///ditto - bool antialias() + bool antialias() const { return drawInfo.text_antialias == 1; } @@ -758,10 +758,10 @@ class Options ///ditto void boxColor(Color color) { - drawInfo.undercolor = *(color.pixelPacket); + drawInfo.undercolor = color.pixelPacket; } ///ditto - Color boxColor() + Color boxColor() const { return new Color(drawInfo.undercolor); } @@ -777,10 +777,10 @@ class Options ///ditto void fillColor(Color color) { - drawInfo.fill = *(color.pixelPacket); + drawInfo.fill = color.pixelPacket; } ///ditto - Color fillColor() + Color fillColor() const { return new Color(drawInfo.fill); } @@ -810,7 +810,7 @@ class Options drawInfo.fill_rule = rule; } ///ditto - FillRule fillRule() + FillRule fillRule() const { return drawInfo.fill_rule; } @@ -823,7 +823,7 @@ class Options drawInfo.stroke_antialias = antialias; } ///ditto - bool strokeAntialias() + bool strokeAntialias() const { return drawInfo.stroke_antialias == 1; } @@ -838,10 +838,10 @@ class Options ///ditto void strokeColor(Color color) { - drawInfo.stroke = *(color.pixelPacket); + drawInfo.stroke = color.pixelPacket; } ///ditto - Color strokeColor() + Color strokeColor() const { return new Color(imageInfo.background_color); } @@ -854,7 +854,7 @@ class Options drawInfo.dash_offset = offset; } ///ditto - double strokeDashOffset() + double strokeDashOffset() const { return drawInfo.dash_offset; } @@ -878,7 +878,7 @@ class Options drawInfo.dash_pattern[pattern.length] = 0.0; } ///ditto - double[] strokeDashPattern() + double[] strokeDashPattern() const { size_t x; for (x = 0; drawInfo.dash_pattern[x] == 0.0; x++ ) {} @@ -897,7 +897,7 @@ class Options drawInfo.linecap = cap; } ///ditto - LineCap lineCap() + LineCap lineCap() const { return drawInfo.linecap; } @@ -910,7 +910,7 @@ class Options drawInfo.linejoin = join; } ///ditto - LineJoin lineJoin() + LineJoin lineJoin() const { return drawInfo.linejoin; } @@ -928,7 +928,7 @@ class Options drawInfo.miterlimit = limit; } ///ditto - size_t strokeMiterlimit() + size_t strokeMiterlimit() const { return drawInfo.miterlimit; } @@ -945,7 +945,7 @@ class Options drawInfo.stroke_pattern = ReferenceImage(pattern.imageRef); } ///ditto - dmagick.Image.Image fillPattern() + dmagick.Image.Image strokePattern() { return new dmagick.Image.Image(ReferenceImage(drawInfo.stroke_pattern)); } @@ -958,7 +958,7 @@ class Options drawInfo.stroke_width = width; } ///ditto - double strokeWidth() + double strokeWidth() const { return drawInfo.stroke_width; } @@ -976,7 +976,7 @@ class Options textDensity(geometry.toString); } ///ditto - Geometry textDensity() + Geometry textDensity() const { return Geometry( to!(string)(imageInfo.density) ); } @@ -995,7 +995,7 @@ class Options copyString(drawInfo.encoding, str); } ///ditto - string textEncoding() + string textEncoding() const { return to!(string)(drawInfo.encoding); } @@ -1046,7 +1046,7 @@ class Options quantizeInfo.number_colors = colors; } ///ditto - size_t quantizeColors() + size_t quantizeColors() const { return quantizeInfo.number_colors; } @@ -1064,7 +1064,7 @@ class Options quantizeInfo.colorspace = type; } ///ditto - ColorspaceType quantizeColorSpace() + ColorspaceType quantizeColorSpace() const { return quantizeInfo.colorspace; } @@ -1080,7 +1080,7 @@ class Options quantizeInfo.tree_depth = depth; } ///ditto - size_t quantizeTreeDepth() + size_t quantizeTreeDepth() const { return quantizeInfo.tree_depth; } -- cgit v1.2.3