QPoint flag::CoordsFromSrvName(const QString & srv)
{
	QPoint p;
	int id = IdFromName(srv);
	if (id < 0)
		id = IdFromName("Germany");		// set default to the middle of Europe
	if (id > -1)
	{
		p.setX(gs_countries[id].x);
		p.setY(gs_countries[id].y);
	}
	return p;
}
QString flag::IconFromSrvName(const QString & srv)
{
	QString f = "_unknown";
	int id = IdFromName(srv);
	if (id > -1)
		f = gs_countries[id].flagpng;
	return f;
}
QString flag::ShortName(const QString & name)
{
	QString s;
	int id = IdFromName(name);
	if (id > -1)
	{
		s = gs_countries[id].shortname;
	}
	else
	{
		s = name;
		s.remove("Hub", Qt::CaseInsensitive);
		s.remove("Boost", Qt::CaseInsensitive);
		s = s.trimmed();
	}
	return HandleTypo(s);
}
Exemple #4
0
/**
 * @brief Given a transform string, returns a colortransform struct
 *
 * @param Trans a colortransform pointer to hold the transform
 * @param TransformString string specifying the transformations
 * @return 1 on success, 0 on failure
 *
 * This function provides a convenient interface to the collection of transform
 * functions in this file.  TransformString specifies the source and
 * destination color spaces,
 *    TransformString = "dest<-src"
 * or alternatively,
 *    TransformString = "src->dest".
 *
 * Supported color spaces are
 *    "RGB"             sRGB Red Green Blue (ITU-R BT.709 gamma-corrected),
 *    "YPbPr"           Luma (ITU-R BT.601) + Chroma,
 *    "YCbCr"           Luma + Chroma ("digitized" version of Y'PbPr),
 *    "JPEG-YCbCr"      Luma + Chroma space used in JFIF JPEG,
 *    "YUV"             NTSC PAL Y'UV Luma + Chroma,
 *    "YIQ"             NTSC Y'IQ Luma + Chroma,
 *    "YDbDr"           SECAM Y'DbDr Luma + Chroma,
 *    "HSV" or "HSB"    Hue Saturation Value/Brightness,
 *    "HSL" or "HLS"    Hue Saturation Luminance,
 *    "HSI"             Hue Saturation Intensity,
 *    "XYZ"             CIE XYZ,
 *    "Lab"             CIE L*a*b* (CIELAB),
 *    "Luv"             CIE L*u*v* (CIELUV),
 *    "LCH"             CIE L*C*H* (CIELCH),
 *    "CAT02 LMS"       CIE CAT02 LMS.
 * Color space names are case-insensitive and spaces are ignored.  When sRGB
 * is the source or destination, it can be omitted.  For example "yuv<-" is
 * short for "yuv<-rgb".
 *
 * The routine returns a colortransform structure representing the transform.
 * The transform is performed by calling GetColorTransform.  For example,
@code
       num S[3] = {173, 0.8, 0.5};
       num D[3];
       colortransform Trans;

       if(!(GetColorTransform(&Trans, "HSI -> Lab")))
       {
           printf("Invalid syntax or unknown color space\n");
           return;
       }

       ApplyColorTransform(Trans, &D[0], &D[1], &D[2], S[0], S[1], S[2]);
@endcode
 */
int GetColorTransform(colortransform *Trans, const char *TransformString)
{
	int LeftNumChars = 0, RightNumChars = 0, LeftSide = 1, LeftToRight = 0;
	int i, j, SrcSpaceId, DestSpaceId;
	char LeftSpace[16], RightSpace[16], c;


	Trans->NumStages = 0;
	Trans->Fun[0] = 0;
	Trans->Fun[1] = 0;

	/* Parse the transform string */
	while(1)
	{
		c = *(TransformString++);	/* Read the next character */

		if(!c)
			break;
		else if(c == '<')
		{
			LeftToRight = 0;
			LeftSide = 0;
		}
		else if(c == '>')
		{
			LeftToRight = 1;
			LeftSide = 0;
		}
		else if(c != ' ' && c != '-' && c != '=')
		{
			if(LeftSide)
			{	/* Append the character to LeftSpace */
				if(LeftNumChars < 15)
					LeftSpace[LeftNumChars++] = tolower(c);
			}
			else
			{	/* Append the character to RightSpace */
				if(RightNumChars < 15)
					RightSpace[RightNumChars++] = tolower(c);
			}
		}
	}

	/* Append null terminators on the LeftSpace and RightSpace strings */
	LeftSpace[LeftNumChars] = 0;
	RightSpace[RightNumChars] = 0;

	/* Convert names to colorspace enum */
	if(LeftToRight)
	{
		SrcSpaceId = IdFromName(LeftSpace);
		DestSpaceId = IdFromName(RightSpace);
	}
	else
	{
		SrcSpaceId = IdFromName(RightSpace);
		DestSpaceId = IdFromName(LeftSpace);
	}

	/* Is either space is unknown? (probably a parsing error) */
	if(SrcSpaceId == UNKNOWN_SPACE || DestSpaceId == UNKNOWN_SPACE)
		return 0;	/* Return failure */

	/* Is this an identity transform? */
	if(SrcSpaceId == DestSpaceId)
		return 1;	/* Return successfully */

	/* Search the TransformPair table for a direct transformation */
	for(i = 0; i < NUM_TRANSFORM_PAIRS; i++)
	{
		if(SrcSpaceId == TransformPair[i].Space[0]
			&& DestSpaceId == TransformPair[i].Space[1])
		{
			Trans->NumStages = 1;
			Trans->Fun[0] = TransformPair[i].Fun[0];
			return 1;
		}
		else if(DestSpaceId == TransformPair[i].Space[0]
			&& SrcSpaceId == TransformPair[i].Space[1])
		{
			Trans->NumStages = 1;
			Trans->Fun[0] = TransformPair[i].Fun[1];
			return 1;
		}
	}

	/* Search the TransformPair table for a two-stage transformation */
	for(i = 1; i < NUM_TRANSFORM_PAIRS; i++)
		if(SrcSpaceId == TransformPair[i].Space[1])
			for(j = 0; j < i; j++)
			{
				if(DestSpaceId == TransformPair[j].Space[1]
					&& TransformPair[i].Space[0] == TransformPair[j].Space[0])
				{
					Trans->NumStages = 2;
					Trans->Fun[0] = TransformPair[i].Fun[1];
					Trans->Fun[1] = TransformPair[j].Fun[0];
					return 1;
				}
			}
		else if(DestSpaceId == TransformPair[i].Space[1])
			for(j = 0; j < i; j++)
			{
				if(SrcSpaceId == TransformPair[j].Space[1]
					&& TransformPair[j].Space[0] == TransformPair[i].Space[0])
				{
					Trans->NumStages = 2;
					Trans->Fun[0] = TransformPair[j].Fun[1];
					Trans->Fun[1] = TransformPair[i].Fun[0];
					return 1;
				}
			}

	return 0;
}