From d02fd289f8c9eef3801ed9e4da9921c8a5c60bf9 Mon Sep 17 00:00:00 2001 From: Michael Uleysky Date: Tue, 4 Oct 2016 01:19:22 +1000 Subject: [PATCH] Gmt module: Functions ColorGray, ColorRGB, ColorHSV, ColorCMYK now using new parameter reading scheme and error reporting. --- modules/gmt/modgmt_func.cpp | 76 ++++++++++++++++++------------------- 1 file changed, 36 insertions(+), 40 deletions(-) diff --git a/modules/gmt/modgmt_func.cpp b/modules/gmt/modgmt_func.cpp index 2fe29cb..039b687 100644 --- a/modules/gmt/modgmt_func.cpp +++ b/modules/gmt/modgmt_func.cpp @@ -24,69 +24,65 @@ const ObjectBase* GMT_Footer(const ObjectList* input) const ObjectBase* GMT_ColorGray(const ObjectList* input) { struct gmt_color c; - bool suc=true; - Base2RGB g(input,0); - Base2Transp t(input,1); + RPosPar g("gray"); + OPosPar t("transparency",0.0); + + ParsePositionalParameters params(input,g,t); + if(!params) return new ObjectError("ColorGray",params.Error()); c.model=gmt_color::GRAY; - c.gray=g(&suc); - c.transparency=t(&suc); + c.gray=g; c.transparency=t; - if(suc) return new ObjectGMTColor(c); - else return 0; + return new ObjectGMTColor(c); } const ObjectBase* GMT_ColorRGB(const ObjectList* input) { struct gmt_color c; - bool suc=true; - Base2RGB r(input,0),g(input,1),b(input,2); - Base2Transp t(input,3); + + RPosPar r("red"),g("green"),b("blue"); + OPosPar t("transparency",0.0); + + ParsePositionalParameters params(input,r,g,b,t); + if(!params) return new ObjectError("ColorRGB",params.Error()); c.model=gmt_color::RGB; - c.r=r(&suc); - c.g=g(&suc); - c.b=b(&suc); - c.transparency=t(&suc); + c.r=r; c.g=g; c.b=b; c.transparency=t; - if(suc) return new ObjectGMTColor(c); - else return 0; + return new ObjectGMTColor(c); } const ObjectBase* GMT_ColorHSV(const ObjectList* input) { struct gmt_color c; - bool suc=true; - Base2Hue h(input,0); - Base2SV s(input,1),v(input,2); - Base2Transp t(input,3); + + RPosPar h("hue"); + RPosPar s("saturation"), v("value"); + OPosPar t("transparency",0.0); + + ParsePositionalParameters params(input,h,s,v,t); + if(!params) return new ObjectError("ColorHSV",params.Error()); c.model=gmt_color::HSV; - c.hue=h(&suc); - c.saturation=s(&suc); - c.value=v(&suc); - c.transparency=t(&suc); + c.hue=h; c.saturation=s; c.value=v; c.transparency=t; - if(suc) return new ObjectGMTColor(c); - else return 0; + return new ObjectGMTColor(c); } const ObjectBase* GMT_ColorCMYK(const ObjectList* input) { - struct gmt_color c; - bool suc=true; - Base2CMYK cyan(input,0),m(input,1),y(input,2),k(input,3); - Base2Transp t(input,4); - - c.model=gmt_color::CMYK; - c.cyan=cyan(&suc); - c.magenta=m(&suc); - c.yellow=y(&suc); - c.black=k(&suc); - c.transparency=t(&suc); - - if(suc) return new ObjectGMTColor(c); - else return 0; + struct gmt_color C; + + RPosPar c("cyan"),m("magenta"),y("yellow"),k("black"); + OPosPar t("transparency",0.0); + + ParsePositionalParameters params(input,c,m,y,k,t); + if(!params) return new ObjectError("ColorCMYK",params.Error()); + + C.model=gmt_color::CMYK; + C.cyan=c; C.magenta=m; C.yellow=y; C.black=k; C.transparency=t; + + return new ObjectGMTColor(C); } // Shifting layer