Esempio n. 1
0
void Convert2Tlv::buildInksFromGrayTones(TRasterCM32P &rout, const TRasterP &rin)
{
	int i, j;

	TRasterGR8P r8 = (TRasterGR8P)rin;
	TRaster32P r32 = (TRaster32P)rin;
	if (r8)
		for (i = 0; i < rin->getLy(); i++) {
			TPixelGR8 *pixin = r8->pixels(i);
			TPixelCM32 *pixout = rout->pixels(i);
			for (j = 0; j < rin->getLx(); j++, pixin++, pixout++)
				*pixout = TPixelCM32(1, 0, pixin->value);
		}
	else
		for (i = 0; i < rin->getLy(); i++) {
			TPixel *pixin = r32->pixels(i);
			TPixelCM32 *pixout = rout->pixels(i);
			for (j = 0; j < rin->getLx(); j++, pixin++, pixout++)
				*pixout = TPixelCM32(1, 0, TPixelGR8::from(*pixin).value);
		}
}
Esempio n. 2
0
void Convert2Tlv::buildInksForNAAImage(TRasterCM32P &rout, const TRaster32P &rin)
{
	std::map<TPixel, int>::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;

			/*- treat white/transparent pixels as transparent -*/
			if (*pixin == TPixel(255, 255, 255) || *pixin == TPixel::Transparent) {
				*pixout = TPixelCM32(0, 0, 255);
				continue;
			}

			if (curColor != *pixin) {
				curColor = *pixin;
				if ((it = m_colorMap.find(curColor)) == m_colorMap.end()) {
					if (m_lastIndex < 4095)
						m_colorMap[curColor] = ++m_lastIndex;
					curIndex = m_lastIndex;
				} else
					curIndex = it->second;
			}
			*pixout = TPixelCM32(curIndex, 0, 0);
		}
	}

	if (m_colorMap.empty())
		m_colorMap[TPixel::Black] = ++m_lastIndex;
}
Esempio n. 3
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);
		}
	}
}
Esempio n. 4
0
TToonzImageP Naa2TlvConverter::makeTlv(bool transparentSyntheticInks) {
  if (!m_valid || m_colors.empty() || m_regions.empty() || !m_regionRas)
    return TToonzImageP();
  int lx                = m_regionRas->getLx();
  int ly                = m_regionRas->getLy();
  TPalette *palette     = m_palette;
  if (!palette) palette = new TPalette();

  TRasterCM32P ras(lx, ly);

  QList<int> styleIds;

  for (int i = 0; i < m_colors.count() - 1; i++) {
    TPixel32 color  = m_colors.at(i);
    int styleId     = palette->getClosestStyle(color);
    TColorStyle *cs = styleId < 0 ? 0 : palette->getStyle(styleId);
    if (cs) {
      if (cs->getMainColor() != color) cs = 0;
    }
    if (cs == 0) {
      styleId = palette->getPage(0)->addStyle(color);
      cs      = palette->getStyle(styleId);
    }
    styleIds.append(styleId);
  }
  styleIds.append(0);  // syntetic ink

  // int synteticInkStyleId = palette->getPage(0)->addStyle(TPixel32(0,0,0,0));
  // styleIds.append(synteticInkStyleId);

  for (int y = 0; y < ly; y++) {
    unsigned short *workScanLine = m_regionRas->pixels(y);
    TPixelCM32 *outScanLine      = ras->pixels(y);
    for (int x = 0; x < lx; x++) {
      int c = workScanLine[x];
      Q_ASSERT(0 <= c && c < m_regions.count());

      int color = m_regions[c].colorIndex;
      Q_ASSERT(0 <= color && color < styleIds.count());

      int styleId = styleIds.at(color);

      RegionInfo::Type type = m_regions.at(c).type;
      if (type == RegionInfo::Background)
        outScanLine[x] = TPixelCM32();
      else if (type & RegionInfo::Ink)
        outScanLine[x] = TPixelCM32(styleId, 0, 0);
      else if (m_syntheticInkRas->pixels(y)[x] == 1)
        outScanLine[x] =
            TPixelCM32(transparentSyntheticInks ? 0 : styleId, styleId, 0);
      else
        outScanLine[x] = TPixelCM32(0, styleId, 255);
    }
  }

  TToonzImageP ti = new TToonzImage(ras, ras->getBounds());
  ti->setPalette(palette);
  ti->setDpi(72, 72);

  return ti;
}