Exemplo n.º 1
0
static inkgroup_t *
load_inkgroup(const char *name)
{
  stp_list_t *dirlist = stpi_data_path();
  stp_list_item_t *item;
  inkgroup_t *igl = NULL;
  item = stp_list_get_start(dirlist);
  while (item)
    {
      const char *dn = (const char *) stp_list_item_get_data(item);
      char *ffn = stpi_path_merge(dn, name);
      stp_mxml_node_t *inkgroup =
	stp_mxmlLoadFromFile(NULL, ffn, STP_MXML_NO_CALLBACK);
      stp_free(ffn);
      if (inkgroup)
	{
	  int count = 0;
	  stp_mxml_node_t *node = stp_mxmlFindElement(inkgroup, inkgroup,
						      "escp2InkGroup", NULL,
						      NULL, STP_MXML_DESCEND);
	  if (node)
	    {
	      stp_mxml_node_t *child = node->child;
	      igl = stp_zalloc(sizeof(inkgroup_t));
	      while (child)
		{
		  if (child->type == STP_MXML_ELEMENT &&
		      !strcmp(child->value.element.name, "InkList"))
		    count++;
		  child = child->next;
		}
	      igl->n_inklists = count;
	      if (stp_mxmlElementGetAttr(node, "name"))
		igl->name = stp_strdup(stp_mxmlElementGetAttr(node, "name"));
	      else
		igl->name = stp_strdup(name);
	      igl->inklists = stp_zalloc(sizeof(inklist_t) * count);
	      child = node->child;
	      count = 0;
	      while (child)
		{
		  if (child->type == STP_MXML_ELEMENT &&
		      !strcmp(child->value.element.name, "InkList"))
		    load_inklist(child, node, &(igl->inklists[count++]));
		  child = child->next;
		}
	    }
	  stp_mxmlDelete(inkgroup);
	  break;
	}
      item = stp_list_item_next(item);
    }
  stp_list_destroy(dirlist);
  return igl;
}
Exemplo n.º 2
0
static void
load_shades(stp_mxml_node_t *node, stp_mxml_node_t *root, inklist_t *ikl)
{
  stp_mxml_node_t *child = node->child;
  int count = 0;

  while (child)
    {
      if (child->type == STP_MXML_ELEMENT &&
	  !strcmp(child->value.element.name, "shade"))
	count++;
      child = child->next;
    }
  ikl->n_shades = count;
  ikl->shades = stp_zalloc(sizeof(shade_t) * count);
  count = 0;
  child = node->child;
  while (child)
    {
      if (child->type == STP_MXML_ELEMENT &&
	  !strcmp(child->value.element.name, "shade"))
	{
	  if (stp_mxmlElementGetAttr(child, "count"))
	    {
	      unsigned nshades =
		stp_xmlstrtoul(stp_mxmlElementGetAttr(child, "count"));
	      ikl->shades[count].n_shades = nshades;
	      if (nshades > 0)
		{
		  char *endptr;
		  stp_mxml_node_t *cchild = child->child;
		  ikl->shades[count].shades = stp_zalloc(sizeof(double) * nshades);
		  nshades = 0;
		  while (cchild && nshades < ikl->shades[count].n_shades)
		    {
		      if (cchild->type == STP_MXML_TEXT)
			{
			  double val =
			    strtod(cchild->value.text.string, &endptr);
			  if (endptr)
			    ikl->shades[count].shades[nshades++] = val;
			}
		      cchild = cchild->next;
		    }
		}
	    }
	  count++;
	}
      child = child->next;
    }
}
stpi_escp2_printer_t *
stp_escp2_get_printer(const stp_vars_t *v)
{
  int model = stp_get_model_id(v);
  STPI_ASSERT(model >= 0, v);
  if (!escp2_model_capabilities)
    {
      escp2_model_capabilities =
	stp_zalloc(sizeof(stpi_escp2_printer_t) * (model + 1));
      escp2_model_count = model + 1;
    }
  else if (model >= escp2_model_count)
    {
      escp2_model_capabilities =
	stp_realloc(escp2_model_capabilities,
		    sizeof(stpi_escp2_printer_t) * (model + 1));
      (void) memset(escp2_model_capabilities + escp2_model_count, 0,
		    sizeof(stpi_escp2_printer_t) * (model + 1 - escp2_model_count));
      escp2_model_count = model + 1;
    }
  if (!(escp2_model_capabilities[model].active))
    {
#ifdef HAVE_LOCALE_H
      char *locale = stp_strdup(setlocale(LC_ALL, NULL));
      setlocale(LC_ALL, "C");
#endif
      escp2_model_capabilities[model].active = 1;
      stp_escp2_load_model(v, model);
#ifdef HAVE_LOCALE_H
      setlocale(LC_ALL, locale);
      stp_free(locale);
#endif
    }
  return &(escp2_model_capabilities[model]);
}
Exemplo n.º 4
0
static void
load_channel(stp_mxml_node_t *node, stp_mxml_node_t *root, ink_channel_t *icl)
{
  const char *name;
  stp_mxml_node_t *child = node->child;
  int count = 0;
  while (child)
    {
      if (child->type == STP_MXML_ELEMENT &&
	  !strcmp(child->value.element.name, "subchannel"))
	count++;
      child = child->next;
    }
  name = stp_mxmlElementGetAttr(node, "name");
  if (name)
    icl->name = stp_strdup(name);
  icl->n_subchannels = count;
  icl->subchannels = stp_zalloc(sizeof(physical_subchannel_t) * count);
  count = 0;
  child = node->child;
  while (child)
    {
      if (child->type == STP_MXML_ELEMENT)
	{
	  if (!strcmp(child->value.element.name, "subchannel"))
	    load_subchannel(child, root, &(icl->subchannels[count++]));
	  else if (!strcmp(child->value.element.name, "HueCurve"))
	    {
	      stp_mxml_node_t *cchild = child->child;
	      stp_curve_t *curve;
	      const char *cref = stp_mxmlElementGetAttr(child, "ref");
	      if (cref)
		{
		  cchild = stp_mxmlFindElement(root, root, "curve", "name",
					       cref, STP_MXML_DESCEND);
		  STPI_ASSERT(cchild, NULL);
		}
	      else
		{
		  while (cchild && cchild->type != STP_MXML_ELEMENT)
		    cchild = cchild->next;
		  STPI_ASSERT(cchild, NULL);
		}
	      curve = stp_curve_create_from_xmltree(cchild);
	      icl->hue_curve = curve;
	    }
	  else if (!strcmp(child->value.element.name, "HueCurveParam"))
	    {
	      name = stp_mxmlElementGetAttr(child, "name");
	      if (name)
		icl->hue_curve_name = stp_strdup(name);
	    }
	}
      child = child->next;
    }
}
Exemplo n.º 5
0
stp_curve_t *
stp_curve_create(stp_curve_wrap_mode_t wrap_mode)
{
  stp_curve_t *ret;
  if (wrap_mode != STP_CURVE_WRAP_NONE && wrap_mode != STP_CURVE_WRAP_AROUND)
    return NULL;
  ret = stp_zalloc(sizeof(stp_curve_t));
  stpi_curve_ctor(ret, wrap_mode);
  return ret;
}
Exemplo n.º 6
0
stp_array_t *
stp_array_create(int x_size, int y_size)
{
  stp_array_t *ret;
  ret = stp_zalloc(sizeof(stp_array_t));
  ret->x_size = x_size;
  ret->y_size = y_size;
  ret->data = NULL;
  array_ctor(ret);
  return ret;
}
Exemplo n.º 7
0
static void
load_inklist(stp_mxml_node_t *node, stp_mxml_node_t *root, inklist_t *ikl)
{
  const char *name;
  stp_mxml_node_t *child = node->child;
  int count = 0;

  while (child)
    {
      if (child->type == STP_MXML_ELEMENT)
	{
	  if (!strcmp(child->value.element.name, "InkName"))
	    count++;
	  else if (!strcmp(child->value.element.name, "initSequence") &&
		   child->child && child->child->type == STP_MXML_TEXT)
	    ikl->init_sequence = stp_xmlstrtoraw(child->child->value.text.string);
	  else if (!strcmp(child->value.element.name, "deinitSequence") &&
		   child->child && child->child->type == STP_MXML_TEXT)
	    ikl->deinit_sequence = stp_xmlstrtoraw(child->child->value.text.string);
	}
      child = child->next;
    }
  name = stp_mxmlElementGetAttr(node, "name");
  if (name)
    ikl->name = stp_strdup(name);
  name = stp_mxmlElementGetAttr(node, "text");
  if (name)
    ikl->text = stp_strdup(name);
  ikl->n_inks = count;
  ikl->inknames = stp_zalloc(sizeof(inkname_t) * count);
  count = 0;
  child = node->child;
  while (child)
    {
      if (child->type == STP_MXML_ELEMENT)
	{
	  if (!strcmp(child->value.element.name, "InkName"))
	    {
	      inkname_t *inl = &(ikl->inknames[count++]);
	      inl->init_sequence = ikl->init_sequence;
	      inl->deinit_sequence = ikl->deinit_sequence;
	      load_inkname(child, root, inl, ikl);
	    }
	  else if (!strcmp(child->value.element.name, "Shades"))
	    load_shades(child, root, ikl);
	}
      child = child->next;
    }
}
Exemplo n.º 8
0
void
stp_channel_add(stp_vars_t *v, unsigned channel, unsigned subchannel,
		double value)
{
  stpi_channel_group_t *cg = get_channel_group(v);
  stpi_channel_t *chan;
  stp_dprintf(STP_DBG_INK, v, "Add channel %d, %d, %f\n",
	      channel, subchannel, value);
  if (!cg)
    {
      cg = stp_zalloc(sizeof(stpi_channel_group_t));
      cg->black_channel = -1;
      cg->gloss_channel = -1;
      stp_allocate_component_data(v, "Channel", NULL, stpi_channel_free, cg);
      stp_dprintf(STP_DBG_INK, v, "*** Set up channel data ***\n");
    }
  if (channel >= cg->channel_count)
    {
      unsigned oc = cg->channel_count;
      cg->c = stp_realloc(cg->c, sizeof(stpi_channel_t) * (channel + 1));
      memset(cg->c + oc, 0, sizeof(stpi_channel_t) * (channel + 1 - oc));
      stp_dprintf(STP_DBG_INK, v, "*** Increment channel count from %d to %d\n",
		  oc, channel + 1);
      if (channel >= cg->channel_count)
	cg->channel_count = channel + 1;
    }
  chan = cg->c + channel;
  if (subchannel >= chan->subchannel_count)
    {
      unsigned oc = chan->subchannel_count;
      chan->sc =
	stp_realloc(chan->sc, sizeof(stpi_subchannel_t) * (subchannel + 1));
      (void) memset
	(chan->sc + oc, 0, sizeof(stpi_subchannel_t) * (subchannel + 1 - oc));
      chan->sc[subchannel].value = value;
      stp_dprintf(STP_DBG_INK, v,
		  "*** Increment subchannel count for %d from %d to %d\n",
		  channel, oc, subchannel + 1);
      if (subchannel >= chan->subchannel_count)
	chan->subchannel_count = subchannel + 1;
    }
  chan->sc[subchannel].value = value;
  chan->sc[subchannel].s_density = 65535;
  chan->sc[subchannel].cutoff = 0.75;
}
Exemplo n.º 9
0
static void
load_subchannel(stp_mxml_node_t *node, stp_mxml_node_t *root, physical_subchannel_t *icl)
{
  const char *name;
  stp_mxml_node_t *child = node->child;
  name = stp_mxmlElementGetAttr(node, "color");
  if (name)
    icl->color = stp_xmlstrtol(name);
  name = stp_mxmlElementGetAttr(node, "subchannel");
  if (name)
    icl->subchannel = stp_xmlstrtol(name);
  else
    icl->subchannel = -1;
  name = stp_mxmlElementGetAttr(node, "headOffset");
  if (name)
    icl->head_offset = stp_xmlstrtol(name);
  name = stp_mxmlElementGetAttr(node, "name");
  if (name)
    icl->name = stp_strdup(name);
  name = stp_mxmlElementGetAttr(node, "text");
  if (name)
    icl->text = stp_strdup(name);
  while (child)
    {
      if (child->type == STP_MXML_ELEMENT)
	{
	  const char *param = child->value.element.name;
	  name = stp_mxmlElementGetAttr(child, "name");
	  if (name && !strcmp(param, "ChannelDensityParam"))
	    icl->channel_density = stp_strdup(name);
	  else if (name && !strcmp(param, "SubchannelTransitionParam"))
	    icl->subchannel_transition = stp_strdup(name);
	  else if (name && !strcmp(param, "SubchannelValueParam"))
	    icl->subchannel_value = stp_strdup(name);
	  else if (name && !strcmp(param, "SubchannelScaleParam"))
	    icl->subchannel_scale = stp_strdup(name);
	  else if (!strcmp(param, "SplitChannels"))
	    {
	      if (stp_mxmlElementGetAttr(child, "count"))
		icl->split_channel_count =
		  stp_xmlstrtoul(stp_mxmlElementGetAttr(child, "count"));
	      if (icl->split_channel_count > 0)
		{
		  char *endptr;
		  int count = 0;
		  stp_mxml_node_t *cchild = child->child;
		  icl->split_channels =
		    stp_zalloc(sizeof(short) * icl->split_channel_count);
		  while (cchild && count < icl->split_channel_count)
		    {
		      if (cchild->type == STP_MXML_TEXT)
			{
			  unsigned val =
			    strtoul(cchild->value.text.string, &endptr, 0);
			  if (endptr)
			    icl->split_channels[count++] = val;
			}
		      cchild = cchild->next;
		    }
		}
	    }
	}
      child = child->next;
    }
}
Exemplo n.º 10
0
static void
load_inkname(stp_mxml_node_t *node, stp_mxml_node_t *root, inkname_t *inl,
	     inklist_t *ikl)
{
  const char *name;
  stp_mxml_node_t *child = node->child;
  int channel_count = 0;
  int aux_channel_count = 0;

  while (child)
    {
      if (child->type == STP_MXML_ELEMENT)
	{
	  if (!strcmp(child->value.element.name, "Channels"))
	    {
	      stp_mxml_node_t *cchild = child->child;
	      while (cchild)
		{
		  if (cchild->type == STP_MXML_ELEMENT &&
		      !strcmp(cchild->value.element.name, "channel"))
		    {
		      name = stp_mxmlElementGetAttr(cchild, "index");
		      if (name)
			{
			  unsigned idx = stp_xmlstrtoul(name);
			  if (idx + 1 > channel_count)
			    channel_count = idx + 1;
			}
		    }
		  cchild = cchild->next;
		}
	    }
	  else if (!strcmp(child->value.element.name, "AuxChannels"))
	    {
	      stp_mxml_node_t *cchild = child->child;
	      while (cchild)
		{
		  if (cchild->type == STP_MXML_ELEMENT &&
		      !strcmp(cchild->value.element.name, "channel"))
		    {
		      name = stp_mxmlElementGetAttr(cchild, "index");
		      if (name)
			{
			  unsigned idx = stp_xmlstrtoul(name);
			  if (idx + 1 > aux_channel_count)
			    aux_channel_count = idx + 1;
			}
		    }
		  cchild = cchild->next;
		}
	    }
	}
      child = child->next;
    }
  inl->channel_count = channel_count;
  if (channel_count > 0)
    inl->channels = stp_zalloc(sizeof(ink_channel_t) * channel_count);
  inl->aux_channel_count = aux_channel_count;
  if (aux_channel_count > 0)
    inl->aux_channels = stp_zalloc(sizeof(ink_channel_t) * aux_channel_count);
  name = stp_mxmlElementGetAttr(node, "name");
  if (name)
    inl->name = stp_strdup(name);
  name = stp_mxmlElementGetAttr(node, "text");
  if (name)
    inl->text = stp_strdup(name);
  name = stp_mxmlElementGetAttr(node, "InkID");
  if (name)
    {
      if (!strcmp(name, "CMYK"))
	inl->inkset = INKSET_CMYK;
      else if (!strcmp(name, "CcMmYK"))
	inl->inkset = INKSET_CcMmYK;
      else if (!strcmp(name, "CcMmYyK"))
	inl->inkset = INKSET_CcMmYyK;
      else if (!strcmp(name, "CcMmYKk"))
	inl->inkset = INKSET_CcMmYKk;
      else if (!strcmp(name, "Quadtone"))
	inl->inkset = INKSET_QUADTONE;
      else if (!strcmp(name, "Hextone"))
	inl->inkset = INKSET_HEXTONE;
      else if (!strcmp(name, "OTHER"))
	inl->inkset = INKSET_OTHER;
      else if (!strcmp(name, "Extended"))
	inl->inkset = INKSET_EXTENDED;
    }

  channel_count = 0;
  aux_channel_count = 0;
  child = node->child;
  while (child)
    {
      if (child->type == STP_MXML_ELEMENT)
	{
	  if (!strcmp(child->value.element.name, "Channels"))
	    {
	      stp_mxml_node_t *cchild = child->child;
	      while (cchild)
		{
		  if (cchild->type == STP_MXML_ELEMENT &&
		      !strcmp(cchild->value.element.name, "channel"))
		    {
		      name = stp_mxmlElementGetAttr(cchild, "index");
		      if (name)
			{
			  unsigned idx = stp_xmlstrtoul(name);
			  load_channel(cchild, root, &(inl->channels[idx]));
			}
		    }
		  cchild = cchild->next;
		}
	    }
	  else if (!strcmp(child->value.element.name, "AuxChannels"))
	    {
	      stp_mxml_node_t *cchild = child->child;
	      while (cchild)
		{
		  if (cchild->type == STP_MXML_ELEMENT &&
		      !strcmp(cchild->value.element.name, "channel"))
		    {
		      name = stp_mxmlElementGetAttr(cchild, "index");
		      if (name)
			{
			  unsigned idx = stp_xmlstrtoul(name);
			  load_channel(cchild, root, &(inl->aux_channels[idx]));
			}
		    }
		  cchild = cchild->next;
		}
	    }
	  else if (!strcmp(child->value.element.name, "initSequence") &&
		   child->child && child->child->type == STP_MXML_TEXT)
	    ikl->init_sequence = stp_xmlstrtoraw(child->child->value.text.string);
	  else if (!strcmp(child->value.element.name, "deinitSequence") &&
		   child->child && child->child->type == STP_MXML_TEXT)
	    ikl->deinit_sequence = stp_xmlstrtoraw(child->child->value.text.string);
	}
      child = child->next;
    }
}
Exemplo n.º 11
0
static void
et_setup(stpi_dither_t *d)
{
  int size = 2 * MAX_SPREAD + ((d->dst_width + 7) & ~7);
  static const int diff_factors[] = {1, 10, 16, 23, 32};
  eventone_t *et = stp_zalloc(sizeof(eventone_t));
  int xa, ya;
  int i;
  for (i = 0; i < CHANNEL_COUNT(d); i++) {
    CHANNEL(d, i).error_rows = 1;
    CHANNEL(d, i).errs = stp_zalloc(1 * sizeof(int *));
    CHANNEL(d, i).errs[0] = stp_zalloc(size * sizeof(int));
  }
  if (d->stpi_dither_type & D_UNITONE) {
    stpi_dither_channel_t *dc = stp_zalloc(sizeof(stpi_dither_channel_t));
    stp_dither_matrix_clone(&(d->dither_matrix), &(dc->dithermat), 0, 0);
    stp_dither_matrix_clone(&(d->transition_matrix), &(dc->pick), 0, 0);
    dc->error_rows = 1;
    dc->errs = stp_zalloc(1 * sizeof(int *));
    dc->errs[0] = stp_zalloc(size * sizeof(int));
    et->dummy_channel = dc;
  }

  xa = d->x_aspect / d->y_aspect;
  if (xa == 0)
    xa = 1;
  et->d_sq.dx = xa * xa;
  et->d2x = 2 * et->d_sq.dx;

  ya = d->y_aspect / d->x_aspect;
  if (ya == 0)
    ya = 1;
  et->d_sq.dy = ya * ya;
  et->d2y = 2 * et->d_sq.dy;

  et->aspect = EVEN_C2 / (xa * ya);
  et->unitone_aspect = UNITONE_C2 / (xa * ya);
  et->d_sq.r_sq = 0;

  for (i = 0; i < CHANNEL_COUNT(d); i++) {
    int x;
    shade_distance_t *shade = stp_zalloc(sizeof(shade_distance_t));
    shade->dis = et->d_sq;
    shade->et_dis = stp_malloc(sizeof(distance_t) * d->dst_width);
    if (CHANNEL(d, i).darkness > .1)
      shade->share_this_channel = 1;
    else
      shade->share_this_channel = 0;
    for (x = 0; x < d->dst_width; x++) {
      shade->et_dis[x] = et->d_sq;
    }
    CHANNEL(d, i).aux_data = shade;
  }
  if (et->dummy_channel) {
    int x;
    shade_distance_t *shade = stp_zalloc(sizeof(shade_distance_t));
    shade->dis = et->d_sq;
    shade->et_dis = stp_malloc(sizeof(distance_t) * d->dst_width);
    for (x = 0; x < d->dst_width; x++) {
      shade->et_dis[x] = et->d_sq;
    }
    et->dummy_channel->aux_data = shade;
  }

  et->physical_aspect = d->y_aspect / d->x_aspect;
  if (et->physical_aspect >= 4)
    et->physical_aspect = 4;
  else if (et->physical_aspect >= 2)
    et->physical_aspect = 2;
  else et->physical_aspect = 1;

  et->diff_factor = diff_factors[et->physical_aspect];

  d->aux_data = et;
  d->aux_freefunc = free_eventone_data;
}
Exemplo n.º 12
0
void
stp_channel_initialize(stp_vars_t *v, stp_image_t *image,
		       int input_channel_count)
{
  stpi_channel_group_t *cg = get_channel_group(v);
  int width = stp_image_width(image);
  int curve_count = 0;
  int i, j, k;
  if (!cg)
    {
      cg = stp_zalloc(sizeof(stpi_channel_group_t));
      cg->black_channel = -1;
      stp_allocate_component_data(v, "Channel", NULL, stpi_channel_free, cg);
    }
  if (cg->initialized)
    return;
  cg->initialized = 1;
  cg->max_density = 0;
  if (cg->black_channel < -1 || cg->black_channel >= cg->channel_count)
    cg->black_channel = -1;
  for (i = 0; i < cg->channel_count; i++)
    {
      stpi_channel_t *c = &(cg->c[i]);
      int sc = c->subchannel_count;
      if (c->curve)
	{
	  curve_count++;
	  stp_curve_resample(c->curve, 4096);
	  c->hue_map = stp_curve_get_data(c->curve, &(c->h_count));
	  cg->curve_count++;
	}
      if (sc > 1)
	{
	  int val = 0;
	  int next_breakpoint;
	  c->lut = stp_zalloc(sizeof(unsigned short) * sc * 65536);
	  next_breakpoint = c->sc[0].value * 65535 * c->sc[0].cutoff;
	  if (next_breakpoint > 65535)
	    next_breakpoint = 65535;
	  while (val <= next_breakpoint)
	    {
	      int value = (int) ((double) val / c->sc[0].value);
	      c->lut[val * sc + sc - 1] = value;
	      val++;
	    }

	  for (k = 0; k < sc - 1; k++)
	    {
	      double this_val = c->sc[k].value;
	      double next_val = c->sc[k + 1].value;
	      double this_cutoff = c->sc[k].cutoff;
	      double next_cutoff = c->sc[k + 1].cutoff;
	      int range;
	      int base = val;
	      double cutoff = sqrt(this_cutoff * next_cutoff);
	      next_breakpoint = next_val * 65535 * cutoff;
	      if (next_breakpoint > 65535)
		next_breakpoint = 65535;
	      range = next_breakpoint - val;
	      while (val <= next_breakpoint)
		{
		  double where = ((double) val - base) / (double) range;
		  double lower_val = base * (1.0 - where);
		  double lower_amount = lower_val / this_val;
		  double upper_amount = (val - lower_val) / next_val;
		  if (lower_amount > 65535.0)
		    lower_amount = 65535.0;
		  c->lut[val * sc + sc - k - 2] = upper_amount;
		  c->lut[val * sc + sc - k - 1] = lower_amount;
		  val++;
		}
	    }
	  while (val <= 65535)
	    {
	      c->lut[val * sc] = val / c->sc[sc - 1].value;
	      val++;
	    }
	}
      if (cg->gloss_channel != i && c->subchannel_count > 0)
	cg->aux_output_channels++;
      cg->total_channels += c->subchannel_count;
      for (j = 0; j < c->subchannel_count; j++)
	cg->max_density += c->sc[j].s_density;
    }
  if (cg->gloss_channel >= 0)
    {
      for (i = 0; i < cg->channel_count; i++)
	{
	  if (cg->gloss_channel == i)
	    break;
	  cg->gloss_physical_channel += cg->c[i].subchannel_count;
	}
    }
	  
  cg->input_channels = input_channel_count;
  cg->width = width;
  cg->alloc_data_1 =
    stp_malloc(sizeof(unsigned short) * cg->total_channels * width);
  cg->output_data = cg->alloc_data_1;
  if (curve_count == 0)
    {
      cg->gcr_channels = cg->input_channels;
      if (input_needs_splitting(v))
	{
	  cg->alloc_data_2 =
	    stp_malloc(sizeof(unsigned short) * cg->input_channels * width);
	  cg->input_data = cg->alloc_data_2;
	  cg->split_input = cg->input_data;
	  cg->gcr_data = cg->split_input;
	}
      else if (cg->gloss_channel != -1)
	{
	  cg->alloc_data_2 =
	    stp_malloc(sizeof(unsigned short) * cg->input_channels * width);
	  cg->input_data = cg->alloc_data_2;
	  cg->gcr_data = cg->output_data;
	  cg->gcr_channels = cg->total_channels;
	}
      else
	{
	  cg->input_data = cg->output_data;
	  cg->gcr_data = cg->output_data;
	}
      cg->aux_output_channels = cg->gcr_channels;
    }
  else
    {
      cg->alloc_data_2 =
	stp_malloc(sizeof(unsigned short) * cg->input_channels * width);
      cg->input_data = cg->alloc_data_2;
      if (input_needs_splitting(v))
	{
	  cg->alloc_data_3 =
	    stp_malloc(sizeof(unsigned short) * cg->aux_output_channels * width);
	  cg->multi_tmp = cg->alloc_data_3;
	  cg->split_input = cg->multi_tmp;
	  cg->gcr_data = cg->split_input;
	}
      else
	{
	  cg->multi_tmp = cg->alloc_data_1;
	  cg->gcr_data = cg->output_data;
	  cg->aux_output_channels = cg->total_channels;
	}
      cg->gcr_channels = cg->aux_output_channels;
    }
  cg->cyan_balance = stp_get_float_parameter(v, "CyanBalance");
  cg->magenta_balance = stp_get_float_parameter(v, "MagentaBalance");
  cg->yellow_balance = stp_get_float_parameter(v, "YellowBalance");
  stp_dprintf(STP_DBG_INK, v, "stp_channel_initialize:\n");
  stp_dprintf(STP_DBG_INK, v, "   channel_count  %d\n", cg->channel_count);
  stp_dprintf(STP_DBG_INK, v, "   total_channels %d\n", cg->total_channels);
  stp_dprintf(STP_DBG_INK, v, "   input_channels %d\n", cg->input_channels);
  stp_dprintf(STP_DBG_INK, v, "   aux_channels   %d\n", cg->aux_output_channels);
  stp_dprintf(STP_DBG_INK, v, "   gcr_channels   %d\n", cg->gcr_channels);
  stp_dprintf(STP_DBG_INK, v, "   width          %ld\n", (long)cg->width);
  stp_dprintf(STP_DBG_INK, v, "   ink_limit      %d\n", cg->ink_limit);
  stp_dprintf(STP_DBG_INK, v, "   gloss_limit    %d\n", cg->gloss_limit);
  stp_dprintf(STP_DBG_INK, v, "   max_density    %d\n", cg->max_density);
  stp_dprintf(STP_DBG_INK, v, "   curve_count    %d\n", cg->curve_count);
  stp_dprintf(STP_DBG_INK, v, "   black_channel  %d\n", cg->black_channel);
  stp_dprintf(STP_DBG_INK, v, "   gloss_channel  %d\n", cg->gloss_channel);
  stp_dprintf(STP_DBG_INK, v, "   gloss_physical %d\n", cg->gloss_physical_channel);
  stp_dprintf(STP_DBG_INK, v, "   cyan           %.3f\n", cg->cyan_balance);
  stp_dprintf(STP_DBG_INK, v, "   magenta        %.3f\n", cg->magenta_balance);
  stp_dprintf(STP_DBG_INK, v, "   yellow         %.3f\n", cg->yellow_balance);
  stp_dprintf(STP_DBG_INK, v, "   input_data     %p\n",
	      (void *) cg->input_data);
  stp_dprintf(STP_DBG_INK, v, "   multi_tmp      %p\n",
	      (void *) cg->multi_tmp);
  stp_dprintf(STP_DBG_INK, v, "   split_input    %p\n",
	      (void *) cg->split_input);
  stp_dprintf(STP_DBG_INK, v, "   output_data    %p\n",
	      (void *) cg->output_data);
  stp_dprintf(STP_DBG_INK, v, "   gcr_data       %p\n",
	      (void *) cg->gcr_data);
  stp_dprintf(STP_DBG_INK, v, "   alloc_data_1   %p\n",
	      (void *) cg->alloc_data_1);
  stp_dprintf(STP_DBG_INK, v, "   alloc_data_2   %p\n",
	      (void *) cg->alloc_data_2);
  stp_dprintf(STP_DBG_INK, v, "   alloc_data_3   %p\n",
	      (void *) cg->alloc_data_3);
  stp_dprintf(STP_DBG_INK, v, "   gcr_curve      %p\n",
	      (void *) cg->gcr_curve);
  for (i = 0; i < cg->channel_count; i++)
    {
      stp_dprintf(STP_DBG_INK, v, "   Channel %d:\n", i);
      for (j = 0; j < cg->c[i].subchannel_count; j++)
	{
	  stpi_subchannel_t *sch = &(cg->c[i].sc[j]);
	  stp_dprintf(STP_DBG_INK, v, "      Subchannel %d:\n", j);
	  stp_dprintf(STP_DBG_INK, v, "         value   %.3f:\n", sch->value);
	  stp_dprintf(STP_DBG_INK, v, "         lower   %.3f:\n", sch->lower);
	  stp_dprintf(STP_DBG_INK, v, "         upper   %.3f:\n", sch->upper);
	  stp_dprintf(STP_DBG_INK, v, "         cutoff  %.3f:\n", sch->cutoff);
	  stp_dprintf(STP_DBG_INK, v, "         density %d:\n", sch->s_density);
	}
    }
}
Exemplo n.º 13
0
static void
stpi_dither_set_ranges(stp_vars_t *v, int color, const stp_shade_t *shade,
		       double density, double darkness)
{
  stpi_dither_t *d = (stpi_dither_t *) stp_get_component_data(v, "Dither");
  stpi_dither_channel_t *dc = &(CHANNEL(d, color));
  const stp_dotsize_t *ranges = shade->dot_sizes;
  int nlevels = shade->numsizes;
  int i;

  STP_SAFE_FREE(dc->ranges);
  STP_SAFE_FREE(dc->ink_list);

  dc->nlevels = nlevels > 1 ? nlevels + 1 : nlevels;
  dc->ranges = (stpi_dither_segment_t *)
    stp_zalloc(dc->nlevels * sizeof(stpi_dither_segment_t));
  dc->ink_list = (stpi_ink_defn_t *)
    stp_zalloc((dc->nlevels + 1) * sizeof(stpi_ink_defn_t));
  dc->bit_max = 0;
  dc->density = density * 65535;
  dc->darkness = darkness;
  stp_init_debug_messages(v);
  stp_dprintf(STP_DBG_INK, v,
	      "stpi_dither_set_ranges channel %d nlevels %d density %f darkness %f\n",
	      color, nlevels, density, darkness);
  for (i = 0; i < nlevels; i++)
    stp_dprintf(STP_DBG_INK, v,
		"  level %d value %f pattern %x\n", i,
		ranges[i].value, ranges[i].bit_pattern);
  dc->ranges[0].lower = &dc->ink_list[0];
  dc->ranges[0].upper = &dc->ink_list[1];
  dc->ink_list[0].range = 0;
  dc->ink_list[0].value = 0;
  dc->ink_list[0].bits = 0;
  if (nlevels == 1)
    dc->ink_list[1].range = 65535;
  else
    dc->ink_list[1].range = ranges[0].value * 65535.0 * density;
  if (dc->ink_list[1].range > 65535)
    dc->ink_list[1].range = 65535;
  dc->ink_list[1].value = ranges[0].value * 65535.0;
  if (dc->ink_list[1].value > 65535)
    dc->ink_list[1].value = 65535;
  dc->ink_list[1].bits = ranges[0].bit_pattern;
  if (ranges[0].bit_pattern > dc->bit_max)
    dc->bit_max = ranges[0].bit_pattern;
  dc->ranges[0].range_span = dc->ranges[0].upper->range;
  dc->ranges[0].value_span = dc->ranges[0].upper->value;
  if (dc->nlevels > 1)
    {
      for (i = 1; i < nlevels; i++)
	{
	  int l = i + 1;
	  dc->ranges[i].lower = &dc->ink_list[i];
	  dc->ranges[i].upper = &dc->ink_list[l];

	  dc->ink_list[l].range =
	    (ranges[i].value + ranges[i].value) * 32768.0 * density;
	  if (dc->ink_list[l].range > 65535)
	    dc->ink_list[l].range = 65535;
	  dc->ink_list[l].value = ranges[i].value * 65535.0;
	  if (dc->ink_list[l].value > 65535)
	    dc->ink_list[l].value = 65535;
	  dc->ink_list[l].bits = ranges[i].bit_pattern;
	  if (ranges[i].bit_pattern > dc->bit_max)
	    dc->bit_max = ranges[i].bit_pattern;
	  dc->ranges[i].range_span =
	    dc->ink_list[l].range - dc->ink_list[i].range;
	  dc->ranges[i].value_span =
	    dc->ink_list[l].value - dc->ink_list[i].value;
	}
      dc->ranges[i].lower = &dc->ink_list[i];
      dc->ranges[i].upper = &dc->ink_list[i+1];
      dc->ink_list[i+1] = dc->ink_list[i];
      dc->ink_list[i+1].range = 65535;
      dc->ranges[i].range_span =
	dc->ink_list[i+1].range - dc->ink_list[i].range;
      dc->ranges[i].value_span =
	dc->ink_list[i+1].value - dc->ink_list[i].value;
    }
  stpi_dither_finalize_ranges(v, dc);
  stp_flush_debug_messages(v);
}