|
|
@ -173,6 +173,7 @@ using Base2String=Base2Struct<std::string>; |
|
|
|
using Base2Coord =Base2Struct<struct gmt_coord>; |
|
|
|
using Base2Coord =Base2Struct<struct gmt_coord>; |
|
|
|
using Base2Region=Base2Struct<struct gmt_region>; |
|
|
|
using Base2Region=Base2Struct<struct gmt_region>; |
|
|
|
using Base2Proj =Base2Struct<struct gmt_projection>; |
|
|
|
using Base2Proj =Base2Struct<struct gmt_projection>; |
|
|
|
|
|
|
|
using Base2Color =Base2Struct<struct gmt_color>; |
|
|
|
|
|
|
|
|
|
|
|
// Simple aliases of convertors with default values
|
|
|
|
// Simple aliases of convertors with default values
|
|
|
|
using Base2StringD=Base2StructD<std::string>; |
|
|
|
using Base2StringD=Base2StructD<std::string>; |
|
|
@ -210,6 +211,44 @@ class Base2NonNeg: public Base2Double |
|
|
|
}; |
|
|
|
}; |
|
|
|
using Base2NonNegD=DefaultConverter<Base2NonNeg>; |
|
|
|
using Base2NonNegD=DefaultConverter<Base2NonNeg>; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Convertors for double values which must be in some interval
|
|
|
|
|
|
|
|
template<int32_t Min, int32_t Max> |
|
|
|
|
|
|
|
class Base2InRange: public Base2Double |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
public: |
|
|
|
|
|
|
|
double Convert(const ObjectBase* ob, bool* res, std::string& err) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
double t=Base2Double::Convert(ob,res,err); |
|
|
|
|
|
|
|
if(res && (t<Min || t>Max) ) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
*res=false; |
|
|
|
|
|
|
|
err="Value mast be in the interval from "+ToString(Min)+" to "+ToString(Max); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
return t; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
}; |
|
|
|
|
|
|
|
template<int32_t Min, int32_t Max> |
|
|
|
|
|
|
|
using Base2InRangeD=DefaultConverter<Base2InRange<Min,Max> >; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Definitions for colors
|
|
|
|
|
|
|
|
constexpr int32_t TransMax = 100; |
|
|
|
|
|
|
|
constexpr int32_t RGBMax = 255; |
|
|
|
|
|
|
|
constexpr int32_t HueMax = 360; |
|
|
|
|
|
|
|
constexpr int32_t SVMax = 1; |
|
|
|
|
|
|
|
constexpr int32_t CMYKMax = 100; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
using Base2Trans = Base2InRange <0,TransMax>; |
|
|
|
|
|
|
|
using Base2RGB = Base2InRange <0,RGBMax >; |
|
|
|
|
|
|
|
using Base2Hue = Base2InRange <0,HueMax >; |
|
|
|
|
|
|
|
using Base2SV = Base2InRange <0,SVMax >; |
|
|
|
|
|
|
|
using Base2CMYK = Base2InRange <0,CMYKMax >; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
using Base2TransD = Base2InRangeD<0,TransMax>; |
|
|
|
|
|
|
|
using Base2RGBD = Base2InRangeD<0,RGBMax >; |
|
|
|
|
|
|
|
using Base2HueD = Base2InRangeD<0,HueMax >; |
|
|
|
|
|
|
|
using Base2SVD = Base2InRangeD<0,SVMax >; |
|
|
|
|
|
|
|
using Base2CMYKD = Base2InRangeD<0,CMYKMax >; |
|
|
|
|
|
|
|
|
|
|
|
// Conversion from List to GMTRegion
|
|
|
|
// Conversion from List to GMTRegion
|
|
|
|
/*
|
|
|
|
/*
|
|
|
|
Input: |
|
|
|
Input: |
|
|
@ -663,19 +702,6 @@ class Convert2Struct<struct gmt_projection, ObjectList> |
|
|
|
} |
|
|
|
} |
|
|
|
}; |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
// Helper types
|
|
|
|
|
|
|
|
typedef SearchParameterWDefO<double,DoubleDefaultVal<>,false,PMin<0>,PMax<255> > Base2RGB; |
|
|
|
|
|
|
|
typedef SearchParameterWDefO<double,DoubleDefaultVal<>,false,PMin<0>,PMax<360> > Base2Hue; |
|
|
|
|
|
|
|
typedef SearchParameterWDefO<double,DoubleDefaultVal<>,false,PMin<0>,PMax<1 > > Base2SV; |
|
|
|
|
|
|
|
typedef SearchParameterWDefO<double,DoubleDefaultVal<>,false,PMin<0>,PMax<100> > Base2CMYK; |
|
|
|
|
|
|
|
typedef SearchParameterWDefO<double,DoubleDefaultVal<>,false,PMin<0>,PMax<100> > Base2Transp; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
typedef SearchParameter<double,false,PMin<0>,PMax<255> > BaseM2RGB; |
|
|
|
|
|
|
|
typedef SearchParameter<double,false,PMin<0>,PMax<360> > BaseM2Hue; |
|
|
|
|
|
|
|
typedef SearchParameter<double,false,PMin<0>,PMax<1 > > BaseM2SV; |
|
|
|
|
|
|
|
typedef SearchParameter<double,false,PMin<0>,PMax<100> > BaseM2CMYK; |
|
|
|
|
|
|
|
typedef SearchParameter<double,false,PMin<0>,PMax<100> > BaseM2Transp; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Converting List to GMTColor
|
|
|
|
// Converting List to GMTColor
|
|
|
|
/*
|
|
|
|
/*
|
|
|
|
Input: |
|
|
|
Input: |
|
|
@ -695,144 +721,119 @@ template<> |
|
|
|
class Convert2Struct<struct gmt_color, ObjectList> |
|
|
|
class Convert2Struct<struct gmt_color, ObjectList> |
|
|
|
{ |
|
|
|
{ |
|
|
|
public: |
|
|
|
public: |
|
|
|
struct gmt_color operator()(const ObjectList* input, bool* issuc) const |
|
|
|
struct gmt_color operator()(const ObjectList* input, bool* issuc, std::string& err) const |
|
|
|
{ |
|
|
|
{ |
|
|
|
struct gmt_color c; |
|
|
|
struct gmt_color C; |
|
|
|
auto size=input->Size(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if(1==size) // Cases 1, 2 and 4
|
|
|
|
if(1==input->Size()) // Cases 1, 2 and 4
|
|
|
|
{ |
|
|
|
{ |
|
|
|
Base2Color color(input,0); |
|
|
|
Base2Color color; |
|
|
|
bool suc=true; |
|
|
|
bool suc=true; |
|
|
|
c=color(&suc); |
|
|
|
C=color.Convert(input->At(0),&suc,err); |
|
|
|
if(!suc) goto fail; // Conversion failed
|
|
|
|
if(!suc) goto fail; // Conversion failed
|
|
|
|
return c; |
|
|
|
return C; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// Case 3
|
|
|
|
// Case 3
|
|
|
|
{ |
|
|
|
{ |
|
|
|
|
|
|
|
ONFPar<Base2Color,ObjectGMTColor> color("color"); |
|
|
|
|
|
|
|
ONPar<Base2TransD> trans("transparency",0); |
|
|
|
|
|
|
|
ONPar<Base2RGB> gray("gr(a|e)y"), r("red"), g("green"), b("blue"); |
|
|
|
|
|
|
|
ONPar<Base2Hue> h("hue"); |
|
|
|
|
|
|
|
ONPar<Base2SV> s("saturation"), v("value"); |
|
|
|
|
|
|
|
ONPar<Base2CMYK> c("cyan"), m("magenta"), y("yellow"), k("[blac]k"); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
{ParseNamedParameters params(input,color,trans,gray,r,g,b,h,s,v,c,m,y,k); if(!params) {err=params.Error(); goto fail;} } // Fail to parse by variant 3
|
|
|
|
|
|
|
|
|
|
|
|
bool cmodset=false; |
|
|
|
bool cmodset=false; |
|
|
|
bool upd; |
|
|
|
bool upd=color.Exist(); |
|
|
|
{ |
|
|
|
|
|
|
|
BaseMT2Color updarg(input,"color"); |
|
|
|
|
|
|
|
bool suc=true; |
|
|
|
|
|
|
|
c=updarg(&upd,&suc); |
|
|
|
|
|
|
|
if(upd && !suc) goto fail; // Conversion failed or too many arguments
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
if(!upd) |
|
|
|
if(!upd) |
|
|
|
{ |
|
|
|
{ |
|
|
|
// default color is black
|
|
|
|
// default color is black
|
|
|
|
c.transparency=0; |
|
|
|
C.transparency=trans; |
|
|
|
c.model=gmt_color::GRAY; |
|
|
|
C.model=gmt_color::GRAY; |
|
|
|
c.gray=0.0; |
|
|
|
C.gray=0.0; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
else C=color; |
|
|
|
|
|
|
|
|
|
|
|
{ |
|
|
|
if(trans.Exist()) C.transparency=trans; |
|
|
|
BaseM2Transp t(input,"t","transp","transparency"); |
|
|
|
|
|
|
|
if(t.Exist()) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
bool suc=true; |
|
|
|
|
|
|
|
c.transparency=t(&suc); |
|
|
|
|
|
|
|
if(!suc) goto fail; // Parsing error
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// GRAY
|
|
|
|
// GRAY
|
|
|
|
|
|
|
|
if(gray.Exist()) |
|
|
|
{ |
|
|
|
{ |
|
|
|
BaseM2RGB g(input,"gray","grey"); |
|
|
|
if(cmodset) {err="Can't select between different color models"; goto fail;} // Model already set
|
|
|
|
if(g.Exist()) |
|
|
|
C.model=gmt_color::GRAY; |
|
|
|
{ |
|
|
|
C.gray=gray; // Update mode ignored in this case
|
|
|
|
if(cmodset) goto fail; // Model already set
|
|
|
|
|
|
|
|
bool suc=true; |
|
|
|
|
|
|
|
c.model=gmt_color::GRAY; |
|
|
|
|
|
|
|
c.gray=g(&suc); // Update mode ignored in this case
|
|
|
|
|
|
|
|
if(!suc) goto fail; // Parsing error
|
|
|
|
|
|
|
|
cmodset=true; |
|
|
|
cmodset=true; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// RGB
|
|
|
|
// RGB
|
|
|
|
{ |
|
|
|
|
|
|
|
BaseM2RGB r(input,"r","red"), g(input,"g","green"), b(input,"b","blue"); |
|
|
|
|
|
|
|
if(r.Exist() || g.Exist() || b.Exist()) |
|
|
|
if(r.Exist() || g.Exist() || b.Exist()) |
|
|
|
{ |
|
|
|
{ |
|
|
|
if(cmodset) goto fail; // Model already set
|
|
|
|
if(cmodset) {err="Can't select between different color models"; goto fail;} // Model already set
|
|
|
|
bool suc=true; |
|
|
|
C.ToRGB(); |
|
|
|
c.ToRGB(); |
|
|
|
if(r.Exist()) C.r=r; |
|
|
|
if(r.Exist()) c.r=r(&suc); |
|
|
|
if(g.Exist()) C.g=g; |
|
|
|
if(g.Exist()) c.g=g(&suc); |
|
|
|
if(b.Exist()) C.b=b; |
|
|
|
if(b.Exist()) c.b=b(&suc); |
|
|
|
|
|
|
|
if(!suc) goto fail; // Parsing error
|
|
|
|
|
|
|
|
cmodset=true; |
|
|
|
cmodset=true; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// HSV
|
|
|
|
// HSV
|
|
|
|
{ |
|
|
|
|
|
|
|
BaseM2Hue h(input,"h","hue"); |
|
|
|
|
|
|
|
BaseM2SV s(input,"s","sat","saturation"), v(input,"v","val","value"); |
|
|
|
|
|
|
|
if(h.Exist() || s.Exist() || v.Exist()) |
|
|
|
if(h.Exist() || s.Exist() || v.Exist()) |
|
|
|
{ |
|
|
|
{ |
|
|
|
if(cmodset) goto fail; // Model already set
|
|
|
|
if(cmodset) {err="Can't select between different color models"; goto fail;} // Model already set
|
|
|
|
bool suc=true; |
|
|
|
C.ToHSV(); |
|
|
|
c.ToHSV(); |
|
|
|
if(h.Exist()) C.hue=h; |
|
|
|
if(h.Exist()) c.hue=h(&suc); |
|
|
|
if(s.Exist()) C.saturation=s; |
|
|
|
if(s.Exist()) c.saturation=s(&suc); |
|
|
|
if(v.Exist()) C.value=v; |
|
|
|
if(v.Exist()) c.value=v(&suc); |
|
|
|
|
|
|
|
if(!suc) goto fail; // Parsing error
|
|
|
|
|
|
|
|
cmodset=true; |
|
|
|
cmodset=true; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// CMYK
|
|
|
|
// CMYK
|
|
|
|
{ |
|
|
|
if(c.Exist() || m.Exist() || y.Exist() || k.Exist()) |
|
|
|
BaseM2CMYK cc(input,"c","cyan"), m(input,"m","magenta"), y(input,"y","yellow"), k(input,"k","black"); |
|
|
|
{ |
|
|
|
if(cc.Exist() || m.Exist() || y.Exist() || k.Exist()) |
|
|
|
if(cmodset) {err="Can't select between different color models"; goto fail;} // Model already set
|
|
|
|
{ |
|
|
|
C.ToCMYK(); |
|
|
|
if(cmodset) goto fail; // Model already set
|
|
|
|
if(c.Exist()) C.cyan=c; |
|
|
|
bool suc=true; |
|
|
|
if(m.Exist()) C.magenta=m; |
|
|
|
c.ToCMYK(); |
|
|
|
if(y.Exist()) C.yellow=y; |
|
|
|
if(cc.Exist()) c.cyan=cc(&suc); |
|
|
|
if(k.Exist()) C.black=k; |
|
|
|
if(m.Exist()) c.magenta=m(&suc); |
|
|
|
|
|
|
|
if(y.Exist()) c.yellow=y(&suc); |
|
|
|
|
|
|
|
if(k.Exist()) c.black=k(&suc); |
|
|
|
|
|
|
|
if(!suc) goto fail; // Parsing error
|
|
|
|
|
|
|
|
cmodset=true; |
|
|
|
cmodset=true; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
if(cmodset || upd) return c; // Color created or updated
|
|
|
|
if(cmodset || upd) return C; // Color created or updated
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// Case 5
|
|
|
|
// Case 5
|
|
|
|
if(3==size) |
|
|
|
if(3==input->Size()) |
|
|
|
{ |
|
|
|
{ |
|
|
|
Base2RGB r(input,0), g(input,1), b(input,2); |
|
|
|
RPosPar<Base2RGB> r("red"), g("green"), b("blue"); |
|
|
|
c.model=gmt_color::RGB; |
|
|
|
ParsePositionalParameters params(input,r,g,b); |
|
|
|
bool suc=true; |
|
|
|
|
|
|
|
c.r=r(&suc); |
|
|
|
if(!params) {err=params.Error(); goto fail;} // Fail to parse by variant 5
|
|
|
|
c.g=g(&suc); |
|
|
|
|
|
|
|
c.b=b(&suc); |
|
|
|
C.model=gmt_color::RGB; |
|
|
|
if(!suc) goto fail; // Parsing error
|
|
|
|
C.r=r; C.g=g; C.b=b; |
|
|
|
return c; |
|
|
|
return C; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// Case 6
|
|
|
|
// Case 6
|
|
|
|
if(4==size) |
|
|
|
if(4==input->Size()) |
|
|
|
{ |
|
|
|
{ |
|
|
|
Base2CMYK cc(input,0), m(input,1), y(input,2), k(input,3); |
|
|
|
RPosPar<Base2CMYK> c("cyan"), m("magenta"), y("yellow"), k("black"); |
|
|
|
c.model=gmt_color::CMYK; |
|
|
|
ParsePositionalParameters params(input,c,m,y,k); |
|
|
|
bool suc=true; |
|
|
|
|
|
|
|
c.cyan=cc(&suc); |
|
|
|
if(!params) {err=params.Error(); goto fail;} // Fail to parse by variant 6
|
|
|
|
c.magenta=m(&suc); |
|
|
|
C.model=gmt_color::CMYK; |
|
|
|
c.yellow=y(&suc); |
|
|
|
C.cyan=c; C.magenta=m; C.yellow=y; C.black=k; |
|
|
|
c.black=k(&suc); |
|
|
|
return C; |
|
|
|
if(!suc) goto fail; // Parsing error
|
|
|
|
|
|
|
|
return c; |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
err="Incorrect number of arguments"; |
|
|
|
|
|
|
|
|
|
|
|
fail: |
|
|
|
fail: |
|
|
|
*issuc=false; |
|
|
|
*issuc=false; |
|
|
|
return c; // Something go wrong
|
|
|
|
return C; // Something go wrong
|
|
|
|
} |
|
|
|
} |
|
|
|
}; |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|