Esempio n. 1
0
TPixel32 TGenericColorFunction::operator()(const TPixel32 &color) const
{
	return TPixel32(tcrop(m_m[0] * color.r + m_c[0], 0.0, 255.0),
					tcrop(m_m[1] * color.g + m_c[1], 0.0, 255.0),
					tcrop(m_m[2] * color.b + m_c[2], 0.0, 255.0),
					tcrop(m_m[3] * color.m + m_c[3], 0.0, 255.0));
}
Esempio n. 2
0
  SquareBuilder(int cellLx, int cellLy, double radius, int wrap)
      : MaskCellBuilder<PIXEL, GRAY>(cellLx, cellLy, radius, wrap) {
    // Build the mask corresponding to a square of passed radius
    GRAY *pix, *pixRev, *line, *lineEnd, *lineRev;
    this->m_mask = TRasterPT<GRAY>(cellLx, cellLy);

    // For each pixel in the lower-left quadrant, fill in the corresponding mask
    // value.
    // The other ones are filled by mirroring.
    int i, j;
    double lxHalf = 0.5 * cellLx, lyHalf = 0.5 * cellLy;
    int lxHalfI = tceil(lxHalf), lyHalfI = tceil(lyHalf);
    double val, addValX = radius - lxHalf + 1, addValY = radius - lyHalf + 1;

    for (i = 0; i < lyHalfI; ++i) {
      line    = this->m_mask->pixels(i),
      lineRev = this->m_mask->pixels(cellLy - i - 1);
      lineEnd = line + cellLx;
      for (j = 0, pix = line, pixRev = lineEnd - 1; j < lxHalfI;
           ++j, ++pix, --pixRev) {
        val  = tcrop(addValX + i, 0.0, 1.0) * tcrop(addValY + j, 0.0, 1.0);
        *pix = *pixRev = val * GRAY::maxChannelValue;
      }

      memcpy(lineRev, line, cellLx * sizeof(GRAY));
    }
  }
Esempio n. 3
0
void ImageViewer::dragCompare(const QPoint &dp) {
  if (m_compareSettings.m_dragCompareX)
    m_compareSettings.m_compareX += ((double)dp.x()) / width();
  else if (m_compareSettings.m_dragCompareY)
    m_compareSettings.m_compareY -= ((double)dp.y()) / height();

  m_compareSettings.m_compareX = tcrop(m_compareSettings.m_compareX, 0.0, 1.0);
  m_compareSettings.m_compareY = tcrop(m_compareSettings.m_compareY, 0.0, 1.0);

  update();
}
Esempio n. 4
0
void TScanParam::update(const TScanParam &model) {
  m_supported = model.m_supported;
  m_min       = model.m_min;
  m_max       = model.m_max;
  m_def       = model.m_def;
  m_step      = model.m_step;
  m_value     = tcrop(m_value, m_min, m_max);
}
Esempio n. 5
0
double OnionSkinMask::getOnionSkinFade(int rowsDistance) {
  if (rowsDistance == 0) return 0.9;

  double fade =
      MINFADE +
      abs(rowsDistance) *
          getIncrement(Preferences::instance()->getOnionPaperThickness());
  return tcrop(fade, MINFADE, MAXFADE);
}
Esempio n. 6
0
void TPalette::movePage(Page *page, int dstPageIndex) {
  assert(page);
  assert(page->m_palette == this);
  dstPageIndex = tcrop(dstPageIndex, 0, getPageCount() - 1);
  if (dstPageIndex == page->getIndex()) return;
  m_pages.erase(m_pages.begin() + page->getIndex());
  m_pages.insert(m_pages.begin() + dstPageIndex, page);
  for (int i = 0; i < getPageCount(); i++) m_pages[i]->m_index = i;
  assert(page->getIndex() == dstPageIndex);
}
Esempio n. 7
0
void PlaneViewer::setViewZoom(double x, double y, double zoom) {
  zoom         = tcrop(zoom, m_zoomRange[0], m_zoomRange[1]);
  double delta = zoom / m_aff.a11;

  m_aff.a13 = x + delta * (m_aff.a13 - x);
  m_aff.a23 = y + delta * (m_aff.a23 - y);
  m_aff.a11 = m_aff.a22 = zoom;

  update();

#ifdef PRINT_AFF
  qDebug("zoom = %.4f;  pos = %.4f, %.4f", m_aff.a11, m_aff.a13, m_aff.a23);
#endif
}
Esempio n. 8
0
void blend(TToonzImageP ti, TRasterPT<PIXEL> rasOut,
           const std::vector<BlendParam> &params) {
  assert(ti->getRaster()->getSize() == rasOut->getSize());

  // Extract the interesting raster. It should be the savebox of passed cmap,
  // plus - if
  // some param has the 0 index as blending color - the intensity of that blend
  // param.
  unsigned int i, j;
  TRect saveBox(ti->getSavebox());

  int enlargement = 0;
  for (i = 0; i < params.size(); ++i)
    for (j = 0; j < params[i].colorsIndexes.size(); ++j)
      if (params[i].colorsIndexes[j] == 0)
        enlargement = std::max(enlargement, tceil(params[i].intensity));
  saveBox           = saveBox.enlarge(enlargement);

  TRasterCM32P cmIn(ti->getRaster()->extract(saveBox));
  TRasterPT<PIXEL> rasOutExtract = rasOut->extract(saveBox);

  // Ensure that cmIn and rasOut have the same size
  unsigned int lx = cmIn->getLx(), ly = cmIn->getLy();

  // Build the pure colors infos
  SelectionRaster selectionRaster(cmIn);

  // Now, build a little group of BlurPatterns - and for each, one for passed
  // param.
  // A small number of patterns per param is needed to make the pattern look not
  // ever the same.
  const int blurPatternsPerParam = 10;
  std::vector<BlurPatternContainer> blurGroup(params.size());

  for (i = 0; i < params.size(); ++i) {
    BlurPatternContainer &blurContainer = blurGroup[i];
    blurContainer.reserve(blurPatternsPerParam);

    for (j = 0; j < blurPatternsPerParam; ++j)
      blurContainer.push_back(BlurPattern(
          params[i].intensity, params[i].smoothness, params[i].stopAtCountour));
  }

  // Build the palette
  TPalette *palette = ti->getPalette();
  std::vector<TPixel32> paletteColors;
  paletteColors.resize(palette->getStyleCount());
  for (i             = 0; i < paletteColors.size(); ++i)
    paletteColors[i] = premultiply(palette->getStyle(i)->getAverageColor());

  // Build the 4 auxiliary rasters for the blending procedure: they are ink /
  // paint versus input / output in the blend.
  // The output raster is reused to spare some memory - it should be, say, the
  // inkLayer's second at the end of the overall
  // blending procedure. It could be the first, without the necessity of
  // clearing it before blending the layers, but things
  // get more complicated when PIXEL is TPixel64...
  RGBMRasterPair inkLayer, paintLayer;

  TRaster32P rasOut32P_1(lx, ly, lx, (TPixel32 *)rasOut->getRawData(), false);
  inkLayer.first  = (params.size() % 2) ? rasOut32P_1 : TRaster32P(lx, ly);
  inkLayer.second = (params.size() % 2) ? TRaster32P(lx, ly) : rasOut32P_1;

  if (PIXEL::maxChannelValue >= TPixel64::maxChannelValue) {
    TRaster32P rasOut32P_2(lx, ly, lx,
                           ((TPixel32 *)rasOut->getRawData()) + lx * ly, false);
    paintLayer.first  = (params.size() % 2) ? rasOut32P_2 : TRaster32P(lx, ly);
    paintLayer.second = (params.size() % 2) ? TRaster32P(lx, ly) : rasOut32P_2;
  } else {
    paintLayer.first  = TRaster32P(lx, ly);
    paintLayer.second = TRaster32P(lx, ly);
  }

  inkLayer.first->clear();
  inkLayer.second->clear();
  paintLayer.first->clear();
  paintLayer.second->clear();

  // Now, we have to perform the blur of each of the cm's pixels.
  cmIn->lock();
  rasOut->lock();

  inkLayer.first->lock();
  inkLayer.second->lock();
  paintLayer.first->lock();
  paintLayer.second->lock();

  // Convert the initial cmIn to fullcolor ink - paint layers
  buildLayers(cmIn, paletteColors, inkLayer.first, paintLayer.first);

  // Perform the blend on separated ink - paint layers
  for (i = 0; i < params.size(); ++i) {
    if (params[i].colorsIndexes.size() == 0) continue;

    selectionRaster.updateSelection(cmIn, params[i]);
    doBlend(cmIn, inkLayer, paintLayer, selectionRaster, blurGroup[i]);

    tswap(inkLayer.first, inkLayer.second);
    tswap(paintLayer.first, paintLayer.second);
  }

  // Release the unnecessary rasters
  inkLayer.second->unlock();
  paintLayer.second->unlock();
  inkLayer.second   = TRaster32P();
  paintLayer.second = TRaster32P();

  // Clear rasOut - since it was reused to spare space...
  rasOut->clear();

  // Add the ink & paint layers on the output raster
  double PIXELmaxChannelValue = PIXEL::maxChannelValue;
  double toPIXELFactor =
      PIXELmaxChannelValue / (double)TPixel32::maxChannelValue;
  double inkFactor, paintFactor;
  TPoint pos;

  PIXEL *outPix, *outBegin    = (PIXEL *)rasOutExtract->getRawData();
  TPixelCM32 *cmPix, *cmBegin = (TPixelCM32 *)cmIn->getRawData();
  int wrap = rasOutExtract->getWrap();

  TPixel32 *inkPix   = (TPixel32 *)inkLayer.first->getRawData();
  TPixel32 *paintPix = (TPixel32 *)paintLayer.first->getRawData();

  for (i = 0; i < ly; ++i) {
    outPix = outBegin + wrap * i;
    cmPix  = cmBegin + wrap * i;
    for (j = 0; j < lx; ++j, ++outPix, ++cmPix, ++inkPix, ++paintPix) {
      getFactors(cmPix->getTone(), inkFactor, paintFactor);

      outPix->r = tcrop(
          toPIXELFactor * (inkFactor * inkPix->r + paintFactor * paintPix->r),
          0.0, PIXELmaxChannelValue);
      outPix->g = tcrop(
          toPIXELFactor * (inkFactor * inkPix->g + paintFactor * paintPix->g),
          0.0, PIXELmaxChannelValue);
      outPix->b = tcrop(
          toPIXELFactor * (inkFactor * inkPix->b + paintFactor * paintPix->b),
          0.0, PIXELmaxChannelValue);
      outPix->m = tcrop(
          toPIXELFactor * (inkFactor * inkPix->m + paintFactor * paintPix->m),
          0.0, PIXELmaxChannelValue);
    }
  }

  inkLayer.first->unlock();
  paintLayer.first->unlock();

  cmIn->unlock();
  rasOut->unlock();

  // Destroy the auxiliary bitmaps
  selectionRaster.destroy();
}
Esempio n. 9
0
void TColorValue::setHsv(int h, int s, int v)
{
	int i;
	double p, q, t, f;
	double hue, sat, value;

	hue = h;
	sat = 0.01 * s;
	value = 0.01 * v;

	assert(0 <= hue && hue <= 360);
	assert(0 <= sat && sat <= 1);
	assert(0 <= value && value <= 1);

	if (sat == 0) {
		m_r = m_g = m_b = value;
	} else {
		if (hue == 360)
			hue = 0;

		hue = hue / 60;
		i = (int)hue;
		f = hue - i;
		p = tcrop(value * (1 - sat), 0., 1.);
		q = tcrop(value * (1 - (sat * f)), 0., 1.);
		t = tcrop(value * (1 - (sat * (1 - f))), 0., 1.);

		switch (i) {
		case 0:
			m_r = value;
			m_g = t;
			m_b = p;
			break;
		case 1:
			m_r = q;
			m_g = value;
			m_b = p;
			break;
		case 2:
			m_r = p;
			m_g = value;
			m_b = t;
			break;
		case 3:
			m_r = p;
			m_g = q;
			m_b = value;
			break;
		case 4:
			m_r = t;
			m_g = p;
			m_b = value;
			break;
		case 5:
			m_r = value;
			m_g = p;
			m_b = q;
			break;
		}
	}
}
Esempio n. 10
0
void TSceneProperties::setFieldGuideSize(int size)
{
	assert(1 <= size && size <= 100);
	m_fieldGuideSize = tcrop(size, 1, 100);
}
Esempio n. 11
0
void TSceneProperties::setTlvSubsampling(int s)
{
	assert(1 <= s && s <= 100);
	m_tlvSubsampling = tcrop(s, 1, 100);
}
Esempio n. 12
0
void TSceneProperties::setFullcolorSubsampling(int s)
{
	assert(1 <= s && s <= 100);
	m_fullcolorSubsampling = tcrop(s, 1, 100);
}