// setColors
//---------------------------------------------------------------------------
void Palette::setColors()
{
    Color::unitAqua        = findNearestColor(  0, 204, 255);
    Color::unitYellow      = findNearestColor(255, 255,   0);
    Color::unitRed         = findNearestColor(255,   0,   0);
    Color::unitBlue        = findNearestColor(  3,   3, 255);
    Color::unitDarkBlue    = findNearestColor(  0,   0, 128);
    Color::unitLightGreen  = findNearestColor(163, 214, 159);
    Color::unitGreen       = findNearestColor( 31, 166,  36);
    Color::unitBlueGray    = findNearestColor( 43,  85, 131);
    Color::unitDarkRed     = findNearestColor(150,   0,   0);
    Color::unitBlack       = findNearestColor(  6,   2,   2);
    Color::unitDarkGreen   = findNearestColor( 26,  88,  36);
    Color::unitWhite       = findNearestColor(250, 253, 248);
    Color::unitLightOrange = findNearestColor(246, 210,  99);
    Color::unitOrange      = findNearestColor(205, 144,   9);
    Color::unitGray        = findNearestColor(186, 186, 186);
    Color::unitDarkGray    = findNearestColor( 99, 100, 102);

    // Grays
    Color::black   = findNearestColor(  0,   0,   0, true);
    Color::gray32  = findNearestColor( 32,  32,  32);
    Color::gray64  = findNearestColor( 64,  64,  64);
    Color::gray96  = findNearestColor( 96,  96,  96);
    Color::gray128 = findNearestColor(128, 128, 128);
    Color::gray160 = findNearestColor(160, 160, 160);
    Color::gray192 = findNearestColor(192, 192, 192);
    Color::gray224 = findNearestColor(224, 224, 224);
    Color::white   = findNearestColor(255, 255, 255);

    // Dark Colors !FIXME!
    Color::darkGray    = Color::gray64;
    Color::darkRed     = findNearestColor(128,   0,   0); // fixed
    Color::darkGreen   = findNearestColor(  0, 128,   0); // fixed
    Color::darkBlue    = findNearestColor(  0,   0, 128); // fixed
    Color::darkYellow  = findNearestColor(255, 168,  18); // fixed
    Color::darkOrange  = findNearestColor(255, 140,   0); // fixed
    Color::darkMagenta = findNearestColor(148,   0, 211); // fixed
    Color::darkCyan    = findNearestColor(  0, 206, 209); // fixed

    // Normal Colors
    Color::gray    = Color::gray128;
    Color::red     = findNearestColor(255,   0,   0); // fixed
    Color::green   = findNearestColor(  0, 255,   0); // fixed
    Color::blue    = findNearestColor(  0,   0, 255); // fixed
    Color::yellow  = findNearestColor(255, 255,   0); // fixed
    Color::orange  = findNearestColor(255, 128,   0); // fixed
    Color::magenta = findNearestColor(255,   0, 255); // fixed
    Color::cyan    = findNearestColor(  0, 255, 255); // fixed
    Color::brown   = findNearestColor(128,  42,  42); // fixed

    //tan                   210 180 140   0.8235 0.7059 0.5490
    Color::tan            = findNearestColor(210, 180, 140); // fixed
    //chartreuse            127 255   0   0.4980 1.0000 0.0000
    Color::chartreuse     = findNearestColor(127, 255,   0); // fixed
    //cobalt_green           61 145  64   0.2400 0.5700 0.2500
    Color::cobaltGreen    = findNearestColor( 61, 145,  64); // fixed
    //emerald_green           0 201  87   0.0000 0.7900 0.3400
    Color::emeraldGreen   = findNearestColor(  0, 201,  87); // fixed
    //forest_green           34 139  34   0.1333 0.5451 0.1333
    Color::forestGreen    = findNearestColor( 34, 139,  34); // fixed
    //olive_green_dark       85 107  47   0.3333 0.4196 0.1843
    Color::darkOliveGreen = findNearestColor( 85, 107,  47); // fixed
    //terre_verte            56  94  15   0.2200 0.3700 0.0600
    Color::terreVerte     = findNearestColor( 56,  94,  15); // fixed

    // Normal Colors !FIXME!
    Color::lightGray    = Color::gray192;
    Color::lightRed     = findNearestColor(255, 160, 122); // fixed
    Color::lightGreen   = findNearestColor( 50, 205,  50); // fixed
    Color::lightBlue    = findNearestColor(135, 206, 250); // fixed
    Color::lightYellow  = findNearestColor(255, 255, 224); // fixed
    Color::lightOrange  = findNearestColor(237, 145,  33); // fixed
    Color::lightMagenta = findNearestColor(  0, 255, 255);
    Color::lightCyan    = findNearestColor(224, 255, 255); // fixed

} // end Palette::setColors
// setColorTables
//---------------------------------------------------------------------------
// Purpose: Creates some palettes which are specifically set to certain
//          best matched colors in the palette.
//---------------------------------------------------------------------------
void Palette::setColorTables()
{
    // 16 shades of fire.
    fire.init(16);
    fire.setColor( 0, findNearestColor(255, 252, 159));
    fire.setColor( 1, findNearestColor(255, 237, 146));
    fire.setColor( 2, findNearestColor(255, 229, 126));
    fire.setColor( 3, findNearestColor(255, 198, 130));
    fire.setColor( 4, findNearestColor(255, 213, 102));
    fire.setColor( 5, findNearestColor(255, 211,  68));
    fire.setColor( 6, findNearestColor(255, 191,  62));
    fire.setColor( 7, findNearestColor(253, 180,  42));
    fire.setColor( 8, findNearestColor(250, 160,  52));
    fire.setColor( 9, findNearestColor(251, 157,  12));
    fire.setColor(10, findNearestColor(243, 130,   3));
    fire.setColor(11, findNearestColor(229, 135,  34));
    fire.setColor(12, findNearestColor(238, 105,   1));
    fire.setColor(13, findNearestColor(221, 107,   6));
    fire.setColor(14, findNearestColor(222,  87,   3));
    fire.setColor(15, findNearestColor(223,  67,   0));
    //fire[ 9] = findNearestColor(SDL_Color(201,  53,   1));
    //fire[10] = findNearestColor(SDL_Color(171,  21,   0));
    //fire[11] = findNearestColor(SDL_Color(140,   3,   0));

    // 16 shades of gray.
    gray16.init(16);
    int num;
    for (num = 0; num < 16; num++)
        gray16.setColor(num, findNearestColor(16*(16-num)-1, 16*(16-num)-1, 16*(16-num)-1));

    // 64 shades of gray.
    gray64.init(64);
    for (num = 0; num < 64; num++) {
        gray64.setColor(num, findNearestColor(num*2, num*2, num*2));
    }
    // 128 shades of gray.
    gray128.init(128);
    int index;
    for (num = 0; num < 128; num++) {
        index = num * 2 + 1;
        gray128.setColor(num, findNearestColor(index, index, index));
    }

    // 256 shades of gray.
    gray256.init(256);
    for (num = 0; num < 256; num++) {
        int c = int(color[num].r+color[num].g+color[num].b)/3; //brightness
        int nearestColor = findNearestColor((int) (c * 1.2f),
                                            (int) (c * 1.2f),
                                            (int) (c * 1.2f));
        gray256.setColor(num, nearestColor);
    }

    // 256 shades of dark gray.
    darkGray256.init(256);
    for (num = 0; num < 256; num++) {
        int c = int(color[num].r+color[num].g+color[num].b)/3; //brightness
        int nearestColor = findNearestColor((int) (float(c) / 2.0f),
                                            (int) (float(c) / 2.0f),
                                            (int) (float(c) / 2.0f));
        darkGray256.setColor(num, nearestColor);
    }

    /*// 64 shades of gray.
    for (num = 0; num < 64; num++)
    {
    	grayLower64[num] = findNearestColor(SDL_Color(num, num, num));
    }
    // 64 shades of gray.
    for (num = 0; num < 64; num++)
    {
    	grayUpper64[num] = findNearestColor(SDL_Color(num*2, num*2, num*2));
    }
    */
    // 256 brightness values.
    brightness256.init(256);
    for (num = 0; num < 256; num++) {
        // this is brihtness int(color[num].r+color[num].g+color[num].b)/3;
        brightness256.setColor(num, int(color[num].r+color[num].g+color[num].b)/3);
    }

    // 32 shades of red.
    red32.init(32);
    for (num = 0; num < 31; num++) {
        red32.setColor(num, findNearestColor(num*8, 0, 0));
    }

    // 32 shades of green.
    green32.init(32);
    for (num = 0; num < 31; num++) {
        green32.setColor(num, findNearestColor(0, num*8, 0));
    }

    // 32 shades of blue.
    blue32.init(32);
    for (num = 0; num < 31; num++) {
        blue32.setColor(num, findNearestColor(0, 0, num*8));
    }

    // white 2 green
    {
        SDL_Color c[8];

        ramp(c, 0, 255, 255, 255, 7, 0, 255, 0);

        gradientWhite2Green.init(8);

        for (int i = 0; i < gradientWhite2Green.getColorCount(); i++)
        {
            gradientWhite2Green.setColor(i, findNearestColor(c[i].r, c[i].g, c[i].b, true));
        }
    }

    // white 2 blue
    {
        SDL_Color c[8];

        ramp(c, 0, 255, 255, 255, 7, 0, 0, 255);

        gradientWhite2Blue.init(8);

        for (int i = 0; i < gradientWhite2Blue.getColorCount(); i++)
        {
            gradientWhite2Blue.setColor(i, findNearestColor(c[i].r, c[i].g, c[i].b, true));
        }
    }

    // white 2 red
    {
        SDL_Color c[8];

        ramp(c, 0, 255, 255, 255, 7, 255, 0, 0);

        gradientWhite2Red.init(8);

        for (int i = 0; i < gradientWhite2Red.getColorCount(); i++)
        {
            gradientWhite2Red.setColor(i, findNearestColor(c[i].r, c[i].g, c[i].b, true));
        }
    }

    char tablePath[512];
    snprintf(tablePath, 512, "cache/colorfilters/%s", name.c_str());
    if(!filesystem::exists(tablePath)) {
        filesystem::mkdir(tablePath);
    }
    char strBuf[512];
    //progressView->scrollAndUpdate("");

    // Best color match.
    sprintf(strBuf, "%s/2080.tbl", tablePath);
    colorTable2080.create(20, 80, strBuf);

    sprintf(strBuf, "%s/4060.tbl", tablePath);
    colorTable4060.create(40, 60, strBuf);

    sprintf(strBuf, "%s/6040.tbl", tablePath);
    colorTable6040.create(60, 40, strBuf);

    sprintf(strBuf, "%s/8020.tbl", tablePath);
    colorTable8020.create(80, 20, strBuf);

    //sprintf(strBuf, "%sSolidTrans0", tablePath);
    //colorTableSolidTrans0.createTrans0(0, 100, strBuf);

    //sprintf(strBuf, "%sSolid", tablePath);
    //colorTableSolid.create(0, 100, strBuf);

    // Brighten.
    sprintf(strBuf, "%s/Brighten.tbl", tablePath);
    colorTableBrighten.createBrightenFilter(strBuf, 256);

    // Darken.
    sprintf(strBuf, "%s/DarkenALot.tbl", tablePath);
    colorTableDarkenALot.createDarkenFilter(strBuf, 0.5f);
    sprintf(strBuf, "%s/DarkenALittle.tbl", tablePath);
    colorTableDarkenALittle.createDarkenFilter(strBuf, 0.15f);

    sprintf(strBuf, "%s/LightDark.tbl", tablePath);
    colorTableLightDark.createLightDarkFilter(strBuf);
} // end setColorTables
Beispiel #3
0
void Convert2Tlv::doFill(TRasterCM32P &rout, const TRaster32P &rin)
{
	//prima passata: si filla  solo partendo da pixel senza inchiostro, senza antialiasing(tone==255)
	for (int i = 0; i < rin->getLy(); i++) {
		TPixel *pixin = rin->pixels(i);
		TPixelCM32 *pixout = rout->pixels(i);
		for (int j = 0; j < rin->getLx(); j++, pixin++, pixout++) {
			if (!(pixout->getTone() == 255 && pixout->getPaint() == 0 && pixin->m == 255))
				continue;

			std::map<TPixel, int>::const_iterator it;
			int paintIndex;
			if ((it = m_colorMap.find(*pixin)) == m_colorMap.end()) {
				if (m_colorTolerance > 0)
					it = findNearestColor(*pixin);
				// if (it==colorMap.end() && (int)colorMap.size()>origColorCount) //se non l'ho trovato tra i colori origari, lo cerco in quelli nuovi, ma in questo caso deve essere esattamente uguale(tolerance = 0)
				//	 it  = findNearestColor(*pixin, colorMap, colorTolerance, origColorCount, colorMap.size()-1);

				if (it == m_colorMap.end() && m_lastIndex < 4096) {
					m_colorMap[*pixin] = ++m_lastIndex;
					paintIndex = m_lastIndex;
				} else if (it != m_colorMap.end()) {
					m_colorMap[*pixin] = it->second;
					paintIndex = it->second;
				}
			} else
				paintIndex = it->second;
			FillParameters params;
			params.m_p = TPoint(j, i);
			params.m_styleId = paintIndex;
			params.m_emptyOnly = true;
			fill(rout, params);
			//if (*((ULONG *)rout->getRawData())!=0xff)
			//  {
			//  int cavolo=0;
			//  }
		}
	}

	//seconda passata: se son rimasti pixel antialiasati non fillati, si fillano, cercando nelle vicinanze un pixel di paint puro per capire il colore da usare
	for (int i = 0; i < rin->getLy(); i++) {
		TPixel *pixin = rin->pixels(i);
		TPixelCM32 *pixout = rout->pixels(i);
		for (int j = 0; j < rin->getLx(); j++, pixin++, pixout++) {
			if (!(pixout->getTone() > 0 && pixout->getTone() < 255 && pixout->getPaint() == 0 && pixin->m == 255))
				continue;

			TPoint p = getClosestPurePaint(rout, i, j);
			if (p.x == -1)
				continue;

			//pixout->setPaint( paintIndex);
			FillParameters params;
			params.m_p = TPoint(j, i);
			params.m_styleId = (rout->pixels(p.y) + p.x)->getPaint();
			params.m_emptyOnly = true;

			fill(rout, params);
		}
	}

	//infine, si filla di trasparente lo sfondo, percorrendo il bordo, nel caso di trasbordamenti di colore
	TPixelCM32 *pixCm;
	TPixel *pix;

	pixCm = rout->pixels(0);
	pix = rin->pixels(0);
	FillParameters params;
	params.m_styleId = 0;

	for (int i = 0; i < rout->getLx(); i++, pixCm++, pix++)
		if (pixCm->getTone() == 255 && pixCm->getPaint() != 0 && pix->m == 0) {
			params.m_p = TPoint(i, 0);
			fill(rout, params);
		}

	pixCm = rout->pixels(rout->getLy() - 1);
	pix = rin->pixels(rout->getLy() - 1);
	for (int i = 0; i < rout->getLx(); i++, pixCm++, pix++)
		if (pixCm->getTone() == 255 && pixCm->getPaint() != 0 && pix->m == 0) {
			params.m_p = TPoint(i, rout->getLy() - 1);
			fill(rout, params);
		}
	int wrapCM = rout->getWrap();
	int wrap = rin->getWrap();

	pixCm = rout->pixels(0);
	pix = rin->pixels(0);
	for (int i = 0; i < rin->getLy(); i++, pixCm += wrapCM, pix += wrap)
		if (pixCm->getTone() == 255 && pixCm->getPaint() != 0 && pix->m == 0) {
			params.m_p = TPoint(0, i);
			fill(rout, params);
		}
	pixCm = rout->pixels(0) + rout->getLx() - 1;
	pix = rin->pixels(0) + rin->getLx() - 1;
	for (int i = 0; i < rin->getLy(); i++, pixCm += wrapCM, pix += wrap)
		if (pixCm->getTone() == 255 && pixCm->getPaint() != 0 && pix->m == 0) {
			params.m_p = TPoint(rout->getLx() - 1, i);
			fill(rout, params);
		}
}
Beispiel #4
0
void Convert2Tlv::buildInks(TRasterCM32P &rout, const TRaster32P &rin)
{
	std::map<TPixel, int>::const_iterator it;
	TPixel curColor = TPixel::Transparent;
	int i, j;
	int curIndex;

	//prima passata: identifico i colori di inchiostro e metto in rout i pixel di inchiostro puro
	for (i = 0; i < rin->getLy(); i++) {
		TPixel *pixin = rin->pixels(i);
		TPixelCM32 *pixout = rout->pixels(i);
		for (j = 0; j < rin->getLx(); j++, pixin++, pixout++) {
			TPixel colorIn;

			if (pixin->m != 255)
				continue;

			if (curColor != *pixin) {
				curColor = *pixin;
				if ((it = m_colorMap.find(curColor)) == m_colorMap.end()) {
					if (m_colorTolerance > 0)
						it = findNearestColor(curColor);
					//if (it==colorMap.end() && (int)colorMap.size()>origColorCount)
					//	it  = findNearestColor(curColor, colorMap, colorTolerance, origColorCount, colorMap.size()-1);
					if (it == m_colorMap.end() && m_lastIndex < 4095) {
						m_colorMap[curColor] = ++m_lastIndex;
						curIndex = m_lastIndex;
					} else if (it != m_colorMap.end()) {
						m_colorMap[curColor] = it->second;
						curIndex = it->second;
					}
				} else
					curIndex = it->second;
			}
			*pixout = TPixelCM32(curIndex, 0, 0);
		}
	}

	//seconda  passata: metto gli inchiostri di antialiasing
	curColor = TPixel::Transparent;

	for (i = 0; i < rin->getLy(); i++) {
		TPixel *pixin = rin->pixels(i);
		TPixelCM32 *pixout = rout->pixels(i);
		for (j = 0; j < rin->getLx(); j++, pixin++, pixout++) {
			TPixel colorIn;
			if (pixin->m == 255) //gia' messo nel ciclo precedente
				continue;
			if (pixin->m == 0)
				continue;

			colorIn = unmultiply(*pixin); //findClosestOpaque(rin, i, j);

			if (curColor != colorIn) {
				curColor = colorIn;
				if ((it = m_colorMap.find(curColor)) != m_colorMap.end())
					curIndex = it->second;
				else
					curIndex = findClosest(m_colorMap, curColor);
			}
			*pixout = TPixelCM32(curIndex, 0, 255 - pixin->m);
		}
	}
}
// setColorTables
//---------------------------------------------------------------------------
// Purpose: Creates some palettes which are specifically set to certain 
//          best matched colors in the palette.
//---------------------------------------------------------------------------
void Palette::setColorTables()
{
	// 16 shades of fire.
	fire.init(16);
	fire.setColor( 0, findNearestColor(RGBColor(255, 252, 159)));
	fire.setColor( 1, findNearestColor(RGBColor(255, 237, 146)));
	fire.setColor( 2, findNearestColor(RGBColor(255, 229, 126)));
	fire.setColor( 3, findNearestColor(RGBColor(255, 198, 130)));
	fire.setColor( 4, findNearestColor(RGBColor(255, 213, 102)));
	fire.setColor( 5, findNearestColor(RGBColor(255, 211,  68)));
	fire.setColor( 6, findNearestColor(RGBColor(255, 191,  62)));
	fire.setColor( 7, findNearestColor(RGBColor(253, 180,  42)));
	fire.setColor( 8, findNearestColor(RGBColor(250, 160,  52)));
	fire.setColor( 9, findNearestColor(RGBColor(251, 157,  12)));
	fire.setColor(10, findNearestColor(RGBColor(243, 130,   3)));
	fire.setColor(11, findNearestColor(RGBColor(229, 135,  34)));
	fire.setColor(12, findNearestColor(RGBColor(238, 105,   1)));
	fire.setColor(13, findNearestColor(RGBColor(221, 107,   6)));
	fire.setColor(14, findNearestColor(RGBColor(222,  87,   3)));
	fire.setColor(15, findNearestColor(RGBColor(223,  67,   0)));
	//fire[ 9] = findNearestColor(RGBColor(201,  53,   1));
	//fire[10] = findNearestColor(RGBColor(171,  21,   0));
	//fire[11] = findNearestColor(RGBColor(140,   3,   0));

	// 16 shades of gray.
	gray16.init(16);
	int num;
	for (num = 0; num < 16; num++)
		gray16.setColor(num, findNearestColor(RGBColor(16*(16-num)-1, 16*(16-num)-1, 16*(16-num)-1)));

	// 64 shades of gray.
	gray64.init(64);
	for (num = 0; num < 64; num++)
	{
		gray64.setColor(num, findNearestColor(RGBColor(num*2, num*2, num*2)));
	}
	// 128 shades of gray.
	gray128.init(128);
	int index;
	for (num = 0; num < 128; num++)
	{
		index = num * 2 + 1;
		gray128.setColor(num, findNearestColor(RGBColor(index, index, index)));
	}
	
	// 256 shades of gray.
	gray256.init(256);
	for (num = 0; num < 256; num++)
	{
		int c            = color[num].getBrightnessInt();
		int nearestColor = findNearestColor(RGBColor((int) (c * 1.2f),
												     (int) (c * 1.2f),
													 (int) (c * 1.2f)));
		gray256.setColor(num, nearestColor);
	}
	
	// 256 shades of dark gray.
	darkGray256.init(256);
	for (num = 0; num < 256; num++)
	{
		int c            = color[num].getBrightnessInt();
		int nearestColor = findNearestColor(RGBColor((int) (float(c) / 2.0f),
													 (int) (float(c) / 2.0f),
													 (int) (float(c) / 2.0f)));
		darkGray256.setColor(num, nearestColor);
	}

	/*// 64 shades of gray.
	for (num = 0; num < 64; num++)
	{
		grayLower64[num] = findNearestColor(RGBColor(num, num, num));
	}
	// 64 shades of gray.
	for (num = 0; num < 64; num++)
	{
		grayUpper64[num] = findNearestColor(RGBColor(num*2, num*2, num*2));
	}
*/
	// 256 brightness values.
	brightness256.init(256);
	for (num = 0; num < 256; num++)
	{
		brightness256.setColor(num, color[num].getBrightnessInt());
	}
	
	// 32 shades of red.
	red32.init(32);
	for (num = 0; num < 31; num++)
	{
		red32.setColor(num, findNearestColor(RGBColor(num*8, 0, 0)));
	}

	// 32 shades of green.
	green32.init(32);
	for (num = 0; num < 31; num++)
	{
		green32.setColor(num, findNearestColor(RGBColor(0, num*8, 0)));
	}

	// 32 shades of blue.
	blue32.init(32);
	for (num = 0; num < 31; num++)
	{
		blue32.setColor(num, findNearestColor(RGBColor(0, 0, num*8)));
	}

	// white 2 green
	{
	RGBColor c[8];

	ramp(c, 0, 255, 255, 255, 7, 0, 255, 0);

	gradientWhite2Green.init(8);

	for (int i = 0; i < gradientWhite2Green.getColorCount(); i++)
	{
		gradientWhite2Green.setColor(i, findNearestColor(c[i], true));
	}
	}

	// white 2 blue
	{
	RGBColor c[8];

	ramp(c, 0, 255, 255, 255, 7, 0, 0, 255);

	gradientWhite2Blue.init(8);

	for (int i = 0; i < gradientWhite2Blue.getColorCount(); i++)
	{
		gradientWhite2Blue.setColor(i, findNearestColor(c[i], true));
	}
	}
	
	// white 2 red
	{
	RGBColor c[8];

	ramp(c, 0, 255, 255, 255, 7, 255, 0, 0);

	gradientWhite2Red.init(8);

	for (int i = 0; i < gradientWhite2Red.getColorCount(); i++)
	{
		gradientWhite2Red.setColor(i, findNearestColor(c[i], true));
	}
	}

	FileUtil::mkdir("pics");
	FileUtil::mkdir("pics/colorFilters");

	char strBuf[256];
	char tablePath[] = "pics/colorFilters/";

	//progressView->scrollAndUpdate("");

	// Best color match.
	//progressView->update("  col2575.tbl");
	sprintf(strBuf, "%s2080", tablePath);
	colorTable2080.create(20, 80, strBuf);

	//progressView->update("  col5050.tbl");
	sprintf(strBuf, "%s4060", tablePath);
	colorTable4060.create(40, 60, strBuf);

	//progressView->update("  col7525.tbl");
	sprintf(strBuf, "%s6040", tablePath);
	colorTable6040.create(60, 40, strBuf);

	//progressView->update("  col7525.tbl");
	sprintf(strBuf, "%s8020", tablePath);
	colorTable8020.create(80, 20, strBuf);

	//sprintf(strBuf, "%sSolidTrans0", tablePath);
	//colorTableSolidTrans0.createTrans0(0, 100, strBuf);

	//sprintf(strBuf, "%sSolid", tablePath);
	//colorTableSolid.create(0, 100, strBuf);

	// Brighten.
	sprintf(strBuf, "%sBrighten", tablePath);
	colorTableBrighten.createBrightenFilter(strBuf, 256);

	// Darken.
	sprintf(strBuf, "%sDarkenALot", tablePath);
	colorTableDarkenALot.createDarkenFilter(strBuf, 0.5f);
	sprintf(strBuf, "%sDarkenALittle", tablePath);
	colorTableDarkenALittle.createDarkenFilter(strBuf, 0.15f);

	//progressView->update("  litedark.tbl");
	sprintf(strBuf, "%sLightDark", tablePath);
	colorTableLightDark.createLightDarkFilter(strBuf);

	//progressView->update("  DONE.");

} // end setColorTables
Beispiel #6
0
// setColorTables
//---------------------------------------------------------------------------
// Purpose: Creates some palettes which are specifically set to certain
//          best matched colors in the palette.
//---------------------------------------------------------------------------
void Palette::setColorTables()
{
    // 16 shades of fire.
    fire.init(16);
    fire.setColor( 0, findNearestColor(255, 252, 159));
    fire.setColor( 1, findNearestColor(255, 237, 146));
    fire.setColor( 2, findNearestColor(255, 229, 126));
    fire.setColor( 3, findNearestColor(255, 198, 130));
    fire.setColor( 4, findNearestColor(255, 213, 102));
    fire.setColor( 5, findNearestColor(255, 211,  68));
    fire.setColor( 6, findNearestColor(255, 191,  62));
    fire.setColor( 7, findNearestColor(253, 180,  42));
    fire.setColor( 8, findNearestColor(250, 160,  52));
    fire.setColor( 9, findNearestColor(251, 157,  12));
    fire.setColor(10, findNearestColor(243, 130,   3));
    fire.setColor(11, findNearestColor(229, 135,  34));
    fire.setColor(12, findNearestColor(238, 105,   1));
    fire.setColor(13, findNearestColor(221, 107,   6));
    fire.setColor(14, findNearestColor(222,  87,   3));
    fire.setColor(15, findNearestColor(223,  67,   0));
    //fire[ 9] = findNearestColor(SDL_Color(201,  53,   1));
    //fire[10] = findNearestColor(SDL_Color(171,  21,   0));
    //fire[11] = findNearestColor(SDL_Color(140,   3,   0));

    // 16 shades of gray.
    gray16.init(16);
    int num;
    for (num = 0; num < 16; num++)
        gray16.setColor(num, findNearestColor(16*(16-num)-1, 16*(16-num)-1, 16*(16-num)-1));

    // 64 shades of gray.
    gray64.init(64);
    for (num = 0; num < 64; num++) {
        gray64.setColor(num, findNearestColor(num*2, num*2, num*2));
    }
    // 128 shades of gray.
    gray128.init(128);
    int index;
    for (num = 0; num < 128; num++) {
        index = num * 2 + 1;
        gray128.setColor(num, findNearestColor(index, index, index));
    }

    // 256 shades of gray.
    gray256.init(256);
    for (num = 0; num < 256; num++) {
        gray256.setColor(num, int(findNearestColor(color[num].r, color[num].r,color[num].r))); // gray
    }

    // 256 shades of dark gray.
    darkGray256.init(256);
    for (num = 0; num < 256; num++) {
        int c = color[num].r/3;// dark gray
        darkGray256.setColor(num, int(findNearestColor(c, c, c))); // dark gray
    }

    darkbrown256.init(256);
    for (num = 0; num < 256; num++) {
        // the magic values are for palete color 33
        int r = abs(color[num].r - 0x16)/4.5;
        int g = abs(color[num].g - 0x1a)/4.5;
        int b = abs(color[num].b - 0x19)/4.5;
        darkbrown256.setColor(num, int(findNearestColor(0x16 + r,0x1a + g,0x19 + b)));
    }

    red256.init(256);
    for (num = 0; num < 256; num++) {
        red256.setColor(num, int(findNearestColor(color[num].r, 0, 0))); 
    }
    
    blue256.init(256);
    for (num = 0; num < 256; num++) {
        blue256.setColor(num, int(findNearestColor(0,0,color[num].b)));
    }

    green256.init(256);
    for (num = 0; num < 256; num++) {
        // the magic values are for palete color 41
        int r = abs(color[num].r - 0x1b)/3;
        int g = abs(color[num].g - 0x3e)/3;
        int b = abs(color[num].b - 0x21)/3;
        green256.setColor(num, int(findNearestColor(0x1b + r,0x3e + g,0x21 + b)));
    }
    
    lightorange256.init(256);
    for (num = 0; num < 256; num++) {
        lightorange256.setColor(num, int(findNearestColor(color[num].r, color[num].r/1.1f,0)));
    }
    /*// 64 shades of gray.
    for (num = 0; num < 64; num++)
    {
    	grayLower64[num] = findNearestColor(SDL_Color(num, num, num));
    }
    // 64 shades of gray.
    for (num = 0; num < 64; num++)
    {
    	grayUpper64[num] = findNearestColor(SDL_Color(num*2, num*2, num*2));
    }
    */
    // 256 brightness values.
    brightness256.init(256);
    for (num = 0; num < 256; num++) {
        int c = color[num].r/1.3;// dark gray
        brightness256.setColor(num, int(findNearestColor(c, c, c))); // dark gray
    }

    // 32 shades of red.
    red32.init(32);
    for (num = 0; num < 31; num++) {
        red32.setColor(num, findNearestColor(num*8, 0, 0));
    }

    // 32 shades of green.
    green32.init(32);
    for (num = 0; num < 31; num++) {
        green32.setColor(num, findNearestColor(0, num*8, 0));
    }

    // 32 shades of blue.
    blue32.init(32);
    for (num = 0; num < 31; num++) {
        blue32.setColor(num, findNearestColor(0, 0, num*8));
    }

    // white 2 green
    {
        SDL_Color c[8];

        ramp(c, 0, 255, 255, 255, 7, 0, 255, 0);

        gradientWhite2Green.init(8);

        for (int i = 0; i < gradientWhite2Green.getColorCount(); i++)
        {
            gradientWhite2Green.setColor(i, findNearestColor(c[i].r, c[i].g, c[i].b, true));
        }
    }

    // white 2 blue
    {
        SDL_Color c[8];

        ramp(c, 0, 255, 255, 255, 7, 0, 0, 255);

        gradientWhite2Blue.init(8);

        for (int i = 0; i < gradientWhite2Blue.getColorCount(); i++)
        {
            gradientWhite2Blue.setColor(i, findNearestColor(c[i].r, c[i].g, c[i].b, true));
        }
    }

    // white 2 red
    {
        SDL_Color c[8];

        ramp(c, 0, 255, 255, 255, 7, 255, 0, 0);

        gradientWhite2Red.init(8);

        for (int i = 0; i < gradientWhite2Red.getColorCount(); i++)
        {
            gradientWhite2Red.setColor(i, findNearestColor(c[i].r, c[i].g, c[i].b, true));
        }
    }

    char tablePath[512];
    snprintf(tablePath, 512, "cache/colorfilters/%s", name.c_str());
    if(!filesystem::exists(tablePath)) {
        filesystem::mkdir(tablePath);
    }
    char strBuf[512];

    // Best color match.
    sprintf(strBuf, "%s/2080.tbl", tablePath);
    colorTable2080.create(20, 80, strBuf);

    sprintf(strBuf, "%s/4060.tbl", tablePath);
    colorTable4060.create(40, 60, strBuf);

    sprintf(strBuf, "%s/6040.tbl", tablePath);
    colorTable6040.create(60, 40, strBuf);

    sprintf(strBuf, "%s/8020.tbl", tablePath);
    colorTable8020.create(80, 20, strBuf);

    //sprintf(strBuf, "%sSolidTrans0", tablePath);
    //colorTableSolidTrans0.createTrans0(0, 100, strBuf);

    //sprintf(strBuf, "%sSolid", tablePath);
    //colorTableSolid.create(0, 100, strBuf);

    // Brighten.
    sprintf(strBuf, "%s/Brighten.tbl", tablePath);
    colorTableBrighten.createBrightenFilter(strBuf, 256);

    // Darken.
    sprintf(strBuf, "%s/DarkenALot.tbl", tablePath);
    colorTableDarkenALot.createDarkenFilter(strBuf, 0.5f);
    sprintf(strBuf, "%s/DarkenALittle.tbl", tablePath);
    colorTableDarkenALittle.createDarkenFilter(strBuf, 0.15f);

    sprintf(strBuf, "%s/LightDark.tbl", tablePath);
    colorTableLightDark.createLightDarkFilter(strBuf);
} // end setColorTables