示例#1
0
/*
  Returns 2048 samples of the palette.
  Each sample is (R'G'B'A float) or (Y'A float), depending on the drawable
 */
static gdouble *
get_samples_palette (gint32 drawable_id)
{
  gchar      *palette_name;
  GimpRGB     color_sample;
  gdouble    *d_samples, *d_samp;
  gboolean    is_rgb;
  gdouble     factor;
  gint        pal_entry, num_colors;
  gint        nb_color_chan, nb_chan, i;
  const Babl *format;

  palette_name = gimp_context_get_palette ();
  gimp_palette_get_info (palette_name, &num_colors);

  is_rgb = gimp_drawable_is_rgb (drawable_id);

  factor = ((double) num_colors) / NSAMPLES;
  format = is_rgb ? babl_format ("R'G'B'A double") : babl_format ("Y'A double");
  nb_color_chan = is_rgb ? 3 : 1;
  nb_chan = nb_color_chan + 1;

  d_samples = g_new (gdouble, NSAMPLES * nb_chan);

  for (i = 0; i < NSAMPLES; i++)
    {
      d_samp = &d_samples[i * nb_chan];
      pal_entry = CLAMP ((int)(i * factor), 0, num_colors - 1);

      gimp_palette_entry_get_color (palette_name, pal_entry, &color_sample);
      gimp_rgb_get_pixel (&color_sample,
                          format,
                          d_samp);
    }

  g_free (palette_name);
  return d_samples;
}
示例#2
0
bool loadPalette(Pentagram::Palette * pal, const ConvertShapeFormat * format)
{
	GimpRGB color;
	guchar palHack[2];
	palHack[1] = 255;
	bool newPal;
	const gchar * palName;

	for (int i = 0; i < 256; ++i)
	{
		palHack[0] = i;
		pal->native[i] = *((uint16 * ) palHack);
	}

	if (format == &PentagramShapeFormat)
	{
		palName = "Pentagram";
	}
	else if (format == &U8SKFShapeFormat)
	{
		palName = "U8SKF";
	}
	else if (format == &U8ShapeFormat)
	{
		palName = "Ultima8";
	}
	else if (format == &U82DShapeFormat)
	{
		palName = "Ultima8";
	}
	else if (format == &CrusaderShapeFormat)
	{
		palName = "Crusader";
	}
	else if (format == &Crusader2DShapeFormat)
	{
		palName = "Crusader";
	}
	else
	{
		return false;
	}

	newPal = ! gimp_context_set_palette(palName);
	if (newPal)
	{
		gint colors = 0;
		if (gimp_palette_get_info(palName, &colors))
		{
			newPal = false;
			if (colors != 256)
			{
				newPal = true;
				if (!gimp_palette_delete(palName))
					return false;
			}
		}
	}

	if (newPal)
	{
		if (g_ascii_strcasecmp(palName, gimp_palette_new(palName)))
			return false;
		if (!gimp_context_set_palette(palName))
			return false;

		IDataSource * ds = choosePalette();
		if (ds)
		{
			gint j = 0;
			ds->seek(4);
			pal->load(*ds);
			delete ds;
			for (gint i = 0; i < 256; ++i)
			{
				gimp_rgb_set_uchar(&color,
							pal->palette[i * 3],
							pal->palette[i * 3 + 1],
							pal->palette[i * 3 + 2]);
				gimp_palette_add_entry(palName, "Untitled", &color, &j);
				assert (j == i);
			}
		}
		else
		{
			return false;
		}
	}
	else
	{
		for (gint i = 0; i < 256; ++i)
		{
			gimp_palette_entry_get_color(palName, i, &color);
			gimp_rgb_get_uchar(&color,
						&(pal->palette[i * 3]),
						&(pal->palette[i * 3 + 1]),
						&(pal->palette[i * 3 + 2]));
		}
	}

	return true;
}