コード例 #1
0
  //! Elimina i segmenti che non sono contenuti all'interno dello stroke!!!
  void checkSegments(std::vector<TAutocloser::Segment> &segments,
                     TStroke *stroke, const TRasterCM32P &ras,
                     const TPoint &delta) {
    TVectorImage vi;
    TStroke *app = new TStroke();
    *app         = *stroke;
    app->transform(TTranslation(convert(ras->getCenter())));
    vi.addStroke(app);
    vi.findRegions();
    std::vector<TAutocloser::Segment>::iterator it = segments.begin();
    for (; it < segments.end(); it++) {
      if (it == segments.end()) break;

      int i;
      bool isContained = false;
      for (i = 0; i < (int)vi.getRegionCount(); i++) {
        TRegion *reg = vi.getRegion(i);
        if (reg->contains(convert(it->first + delta)) &&
            reg->contains(convert(it->second + delta))) {
          isContained = true;
          break;
        }
      }
      if (!isContained) {
        it = segments.erase(it);
        if (it != segments.end() && it != segments.begin())
          it--;
        else if (it == segments.end())
          break;
      }
    }
  }
コード例 #2
0
/*-- (StylePickerTool内で)LineとAreaを切り替えてPickできる。mode: 0=Area, 1=Line, 2=Line&Areas(default)  --*/
int StylePicker::pickStyleId(const TPointD &pos, double radius2, int mode) const
{
	int styleId = 0;
	if (TToonzImageP ti = m_image) {
		TRasterCM32P ras = ti->getRaster();
		TPoint point = getRasterPoint(pos);
		if (!ras->getBounds().contains(point))
			return -1;
		TPixelCM32 col = ras->pixels(point.y)[point.x];

		switch (mode) {
		case 0: //AREAS
			styleId = col.getPaint();
			break;
		case 1: //LINES
			styleId = col.getInk();
			break;
		case 2: //ALL (Line & Area)
		default:
			styleId = col.isPurePaint() ? col.getPaint() : col.getInk();
			break;
		}
	} else if (TRasterImageP ri = m_image) {
		const TPalette *palette = m_palette.getPointer();
		if (!palette)
			return -1;
		TRaster32P ras = ri->getRaster();
		if (!ras)
			return -1;
		TPoint point = getRasterPoint(pos);
		if (!ras->getBounds().contains(point))
			return -1;
		TPixel32 col = ras->pixels(point.y)[point.x];
		styleId = palette->getClosestStyle(col);
	} else if (TVectorImageP vi = m_image) {
		// prima cerca lo stile della regione piu' vicina
		TRegion *r = vi->getRegion(pos);
		if (r)
			styleId = r->getStyle();
		// poi cerca quello della stroke, ma se prima aveva trovato una regione, richiede che
		// il click sia proprio sopra la stroke, altrimenti cerca la stroke piu' vicina (max circa 10 pixel)
		const double maxDist2 = (styleId == 0) ? 100.0 * radius2 : 0;
		bool strokeFound;
		double dist2, w, thick;
		UINT index;
		//!funzionerebbe ancora meglio con un getNearestStroke che considera
		//la thickness, cioe' la min distance dalla outline e non dalla centerLine
		strokeFound = vi->getNearestStroke(pos, w, index, dist2);
		if (strokeFound) {
			TStroke *stroke = vi->getStroke(index);
			thick = stroke->getThickPoint(w).thick;
			if (dist2 - thick * thick < maxDist2) {
				assert(stroke);
				styleId = stroke->getStyle();
			}
		}
	}
	return styleId;
}
コード例 #3
0
ファイル: WINS.CPP プロジェクト: cdaffara/symbiandump-os1
void RWindows::Update(const TRegion& aRgn,const TSize& aSize)
	{
	if(aRgn.CheckError())
		UpdateRect(TRect(aSize),aSize);
	else
		for(TInt count=0;count<aRgn.Count();count++)
			UpdateRect(aRgn[count],aSize);
	}
コード例 #4
0
CHuiCanvasGc::TClipRectVisibility CHuiCanvasGc::IsClipped(const TRect& aRect, const TRegion& aClippingRegion) const
    {
    TClipRectVisibility isClipped = EFullyOutside;
    if (!aClippingRegion.Count())
        {
        return EFullyInside;
        }
    
    if (!aRect.IsEmpty() && aClippingRegion.Count())
        {    
#if 0            
        TBool test = EFalse;        
        if (test)
            {
            for (TInt i=0; i<aClippingRegion.Count(); i++)
                {
#ifdef _DEBUG
                RDebug::Print(_L("aClippingRegion Rect: %d %d %d %d"), 
                        aClippingRegion[i].iTl.iX, 
                        aClippingRegion[i].iTl.iY,
                        aClippingRegion[i].iBr.iX,
                        aClippingRegion[i].iBr.iY);
#endif
                }                            
            }
#endif        
        
        if (aClippingRegion.Intersects(aRect))
            {            
            iTempRegion.Clear();
            iTempRegion2.Clear();

            iTempRegion.AddRect(aRect);
            
            iTempRegion2.Intersection(aClippingRegion, iTempRegion);
            iTempRegion2.Tidy();
            
            // Assume it is only partially inside region -> Clipped
            isClipped = EPartialOverlap;
            
            if (iTempRegion2.Count() == 1)
                {
                if (iTempRegion2[0] == aRect)
                    {
                    // Fully inside region -> Not clipped
                    isClipped = EFullyInside;    
                    }                
                }
            
            }
        else
            {
            // No overlap -> aRect is completely outside region -> Clipped
            isClipped = EFullyOutside;    
            }                    
        }
    return isClipped;
    }
コード例 #5
0
ファイル: t_regn.cpp プロジェクト: kuailexs/symbiandump-os1
void TestRRegion::CheckRectRegion(const TRegion& region,const TRect& rect)
// Check the region matches the rectangle
	{
	const TRect* rlist;

	if (rect.IsEmpty())
		test(region.Count()==0);
	else
		{
		test(region.Count()==1);
		rlist=region.RectangleList();
		test(rlist[0]==rect);
		test(region[0]==rect);
		}
	}
コード例 #6
0
void CDataWrapperBase::LogRegion(const TDesC& aMessage, const TRegion& aRegion)
	{
	INFO_PRINTF2(KLogRegion, &aMessage);
	TInt	indCount = aRegion.Count();
	if ( indCount==0 )
		{
		INFO_PRINTF1(KLogEmpty);
		}
	else
		{
		const TRect*	rect=aRegion.RectangleList();
		for ( TInt index=0; index<indCount; ++index )
			{
			INFO_PRINTF6(KLogRegionsRect, index, rect[index].iTl.iX, rect[index].iTl.iY, rect[index].iBr.iX, rect[index].iBr.iY);
			}
		}
	}
コード例 #7
0
ファイル: decoder.cpp プロジェクト: kuailexs/symbiandump-os1
void CMMFTestVideoDecodeHwDevice::SetScreenClipRegion(const TRegion& aRegion)
	{
	TRect dsaRect(KTestDSARectA, KTestDSARectB, KTestDSARectC, KTestDSARectD);
	TRegionFix<1> dsaReg(dsaRect);

	__ASSERT_ALWAYS(dsaReg.BoundingRect() == aRegion.BoundingRect(), 
		DevVideoDecoderPanic(EDecoderPanicScreenClipRegion)); 
	}
コード例 #8
0
TBool CDataWrapperBase::GetRegionFromConfig(const TDesC& aSectName, const TDesC& aKeyName, TRegion& aResult)
	{
	TBuf<KMaxTestExecuteCommandLength>	tempStore;
	TRect								rect;

	aResult.Clear();
	TBool	moreData=ETrue;
	for ( TInt index=0; moreData; )
		{
		tempStore.Format(KFormatFieldNumber, &aKeyName, ++index);
		moreData=GetRectFromConfig(aSectName, tempStore, rect);
		if ( moreData )
			{
			aResult.AddRect(rect);
			}
		}

	return aResult.Count()>0;
	}
コード例 #9
0
ファイル: decoder.cpp プロジェクト: kuailexs/symbiandump-os1
void CMMFTestVideoDecodeHwDevice::StartDirectScreenAccessL(const TRect& aVideoRect, CFbsScreenDevice& /*aScreenDevice*/, const TRegion& aClipRegion)
	{
	TRect dsaRect(KTestDSARectA, KTestDSARectB, KTestDSARectC, KTestDSARectD);
	TRegionFix<1> dsaReg(dsaRect);

	// probably no need to check aScreenDevice
	if ( /*!(&aScreenDevice) || */!(dsaRect == aVideoRect) || 
		 !(dsaReg.BoundingRect() == aClipRegion.BoundingRect()) )
		 User::Leave(KErrNotSupported);
	}
コード例 #10
0
CHuiCanvasGc::TClipRectVisibility CHuiCanvasGc::IsClipped(const TPoint& aPoint, const TRegion& aClippingRegion) const
    {
    if (iClippingRegion.Count() && !aClippingRegion.Contains(aPoint))
        {
        return EFullyOutside;
        }
    else 
        {
        return EFullyInside;
        }
    }
コード例 #11
0
ファイル: SPRITE.CPP プロジェクト: kuailexs/symbiandump-os1
void CWsSpriteBase::CalcRedrawRegion(const TRegion& aSourceRegion, TRegion& aTarget) const
	{
	aTarget.Copy(aSourceRegion);
	if (ClipSprite())
		{
		TPoint origin(0,0);
		if(iWin)
			origin = iWin->Origin();
		TRect rect(iBasePos + origin + iClipOffset, iClipSize);
		aTarget.ClipRect(rect);
		}
	aTarget.ClipRect(RootWindow()->Abs());

	// Only need to draw if the region being redrawn overlaps the sprite
	const TRect spriteRect(Pos(), iSize);
	STACK_REGION spriteRegion;
	spriteRegion.AddRect(spriteRect);
	aTarget.Intersect(spriteRegion);
	spriteRegion.Close();
	}
コード例 #12
0
void CWsWindow::RestartAnimations(const TRegion& aNewRegion)
	{
	 //When not ChangeTracking, restarting is handled by AddRedrawRegion (called from CWsWindow::SetVisibleRegion) and TWalkWindowTreeScheduleRegions
	WS_ASSERT_DEBUG(iScreen->ChangeTracking(),EWsPanicNoChangetracking);
	
	//Restart uncovered window animations 
	for (CWsAnim* anim = iAnimList; anim; anim = anim->Next())
		{
		if(!iScreen->IsScheduled(EWindowAnim, anim->BestRect(), this) && aNewRegion.Intersects(anim->BestRect()))
			{
			iScreen->ScheduleAnimation(EWindowAnim, anim->BestRect(), 0, 0, 0, this);
			}
		}
	//Restart uncovered sprite animations 
	for (CWsSpriteBase* sprite = iSpriteList; sprite; sprite = sprite->Next())
		{
		if(!iScreen->IsScheduled(ESpriteAnim, sprite->Rect(), sprite->Win()) && aNewRegion.Intersects(sprite->Rect()))
			{
			iScreen->ScheduleAnimation(ESpriteAnim, sprite->Rect(), 0, 0, 0, sprite->Win());
			}
		}
	}
コード例 #13
0
/** 
This function updates the window's dirty region and schedules a redraw if needed.
Only used when the screen is run in CHANGETRACKING mode. 
@param aRegion in window coordinates
*/
void CWsBackedUpWindow::MarkDirtyAndSchedule(const TRegion& aRegion)
	{
	WS_ASSERT_DEBUG(Screen()->ChangeTracking(),EWsPanicNoChangetracking);
	
	if(!aRegion.IsEmpty())
		{
		iWsWin->AddDirtyWindowRegion(aRegion);
		if (iWsWin->IsActive() && iWsWin->IsVisible())
			{
			Screen()->ScheduleWindow(iWsWin);
			}
		}
	}
コード例 #14
0
ファイル: SPRITE.CPP プロジェクト: kuailexs/symbiandump-os1
void CWsSpriteManager::CalcFloatingSpriteRgn( TRegion& aResultRgn, const TRect& aDefaultRect )
	{
	aResultRgn.Clear();
	for (TInt i=0 ; i<iFloatingSprites.Count() && !aResultRgn.CheckError(); i++)
		{
		CWsSpriteBase* sprite = iFloatingSprites[i]; 
		if ( sprite->CanBeSeen() && ( sprite->IsActive() || sprite->IsActivated() ) )
			{
			aResultRgn.AddRect( sprite->Rect() );
			}
		}
	aResultRgn.Tidy();
	if ( aResultRgn.CheckError() && iFloatingSprites.Count() > 0 )
		{
		aResultRgn.Clear();
		aResultRgn.AddRect( aDefaultRect );
		}
	}
コード例 #15
0
CHuiCanvasGc::TClipRectVisibility CHuiCanvasGc::IsClipped(const TRegion& aTestedRegion, const TRegion& aClippingRegion) const
    {
    TClipRectVisibility isWholeRegionClipped = EUnknown;
    TInt count = aTestedRegion.Count(); 
    
    if (count == 0)
        {
        isWholeRegionClipped = EFullyOutside;
        }
    
    for (TInt i=0; i<count; i++)
        {
        TClipRectVisibility isRectClipped = IsClipped(aTestedRegion[i], aClippingRegion);
        if (isWholeRegionClipped == EFullyInside)
            {
            if (isRectClipped == EFullyOutside ||
                isRectClipped == EPartialOverlap )
                {
                isWholeRegionClipped = EPartialOverlap;
                }            
            }
        else if (isWholeRegionClipped == EFullyOutside)
            {
            if (isRectClipped == EFullyInside ||
                isRectClipped == EPartialOverlap )
                {
                isWholeRegionClipped = EPartialOverlap;
                }                        
            }
        else if (isWholeRegionClipped == EPartialOverlap)
            {
            // No changes to isWholeRegionClipped in this case and no need to look further
            break;
            }
        else
            {
            isWholeRegionClipped = isRectClipped;
            }                   
        }
    return isWholeRegionClipped;
    }
コード例 #16
0
ファイル: TCURSOR.CPP プロジェクト: kuailexs/symbiandump-os1
void RWsTextCursor::doDraw(CFbsBitGc* aGc, const TRegion& aRegion)
	{
	TRegionFix<1> justInCase;
	const TRegion *pr= &aRegion;
	if (aRegion.CheckError())
		{
		justInCase.AddRect(iWin->AbsRect());
		pr= &justInCase;
		}
	if (!pr->IsEmpty())
		{
		aGc->SetUserDisplayMode(iWin->DisplayMode());
		aGc->SetDitherOrigin(iWin->Origin());
		aGc->SetDrawMode(CGraphicsContext::EDrawModeXOR);
		switch (iType)
			{
			case TTextCursor::ETypeRectangle:
				{
				aGc->SetBrushStyle(CGraphicsContext::ESolidBrush);
				aGc->SetPenStyle(CGraphicsContext::ENullPen);
				aGc->SetBrushColor(iColor);
				}
				break;
			case TTextCursor::ETypeHollowRectangle:
				{
				aGc->SetBrushStyle(CGraphicsContext::ENullBrush);
				aGc->SetPenStyle(CGraphicsContext::ESolidPen);
				aGc->SetPenColor(iColor);
				}
				break;
			default:
				WS_PANIC_ALWAYS(EWsPanicInvalidCursorType);
			}
		aGc->SetClippingRegion(pr);
		aGc->DrawRect(RectRelativeToScreen());
		aGc->SetUserDisplayMode(ENone);

		TWindowServerEvent::NotifyScreenDrawingEvent(pr);
		}
	}
コード例 #17
0
ファイル: autofillpli.cpp プロジェクト: walkerka/opentoonz
void stroke_autofill_learn(const TVectorImageP &imgToLearn, TStroke *stroke) {
  if (!imgToLearn || !stroke || stroke->getControlPointCount() == 0) return;
  TVectorImage appImg;
  TStroke *appStroke = new TStroke(*stroke);
  appImg.addStroke(appStroke);
  appImg.findRegions();

  double pbx, pby;
  double totalArea = 0;
  pbx = pby = 0;

  if (!regionsReference.isEmpty()) regionsReference.clear();

  int i, j, index = 0;

  for (i = 0; i < (int)imgToLearn->getRegionCount(); i++) {
    TRegion *currentRegion = imgToLearn->getRegion(i);
    for (j = 0; j < (int)appImg.getRegionCount(); j++) {
      TRegion *region = appImg.getRegion(j);
      if (contains(region, currentRegion)) {
        scanRegion(currentRegion, index, regionsReference, region->getBBox());
        index++;
        int k, subRegionCount = currentRegion->getSubregionCount();
        for (k = 0; k < subRegionCount; k++) {
          TRegion *subRegion = currentRegion->getSubregion(k);
          if (contains(region, subRegion))
            scanSubRegion(subRegion, index, regionsReference,
                          region->getBBox());
        }
      }
    }
  }

  QMap<int, Region>::Iterator it;
  for (it = regionsReference.begin(); it != regionsReference.end(); it++) {
    pbx += it.value().m_barycentre.x;
    pby += it.value().m_barycentre.y;
    totalArea += it.value().m_area;
  }

  if (totalArea > 0)
    referenceB = TPointD(pbx / totalArea, pby / totalArea);
  else
    referenceB = TPointD(0.0, 0.0);
}
コード例 #18
0
ファイル: autofillpli.cpp プロジェクト: walkerka/opentoonz
void rect_autofill_learn(const TVectorImageP &imgToLearn, const TRectD &rect)

{
  if (rect.getLx() * rect.getLy() < MIN_SIZE) return;

  double pbx, pby;
  double totalArea = 0;
  pbx = pby = 0;

  if (!regionsReference.isEmpty()) regionsReference.clear();

  int i, index = 0, regionCount = imgToLearn->getRegionCount();
  for (i = 0; i < regionCount; i++) {
    TRegion *region = imgToLearn->getRegion(i);
    if (rect.contains(region->getBBox())) {
      scanRegion(region, index, regionsReference, rect);
      index++;
    }
    int j, subRegionCount = region->getSubregionCount();
    for (j = 0; j < subRegionCount; j++) {
      TRegion *subRegion = region->getSubregion(j);
      if (rect.contains(subRegion->getBBox()))
        scanSubRegion(subRegion, index, regionsReference, rect);
    }
  }

  QMap<int, Region>::Iterator it;
  for (it = regionsReference.begin(); it != regionsReference.end(); it++) {
    pbx += it.value().m_barycentre.x;
    pby += it.value().m_barycentre.y;
    totalArea += it.value().m_area;
  }

  if (totalArea > 0)
    referenceB = TPointD(pbx / totalArea, pby / totalArea);
  else
    referenceB = TPointD(0.0, 0.0);
}
コード例 #19
0
//!Converts a TVectorImage into a TRasterImage. The input vector image
//!is transformed through the passed affine \b aff, and put into a
//!TRasterImage strictly covering the bounding box of the transformed
//!vector image. The output image has its lower-left position in the
//!world reference specified by the \b pos parameter, which is granted to
//!be an integer displacement of the passed value. Additional parameters
//!include an integer \b enlarge by which the output image is enlarged with
//!respect to the transformed image's bbox, and the bool \b transformThickness
//!to specify whether the transformation should involve strokes' thickensses
//!or not.
TRasterImageP TRasterImageUtils::vectorToFullColorImage(
	const TVectorImageP &vimage, const TAffine &aff, TPalette *palette,
	const TPointD &outputPos, const TDimension &outputSize,
	const std::vector<TRasterFxRenderDataP> *fxs, bool transformThickness)
{
	if (!vimage || !palette)
		return 0;

	//Transform the vector image through aff
	TVectorImageP vi = vimage->clone();
	vi->transform(aff, transformThickness);

	//Allocate the output ToonzImage
	TRaster32P raster(outputSize.lx, outputSize.ly);
	raster->clear();
	TRasterImageP ri(raster);
	ri->setPalette(palette->clone());

	//Shift outputPos to the origin
	vi->transform(TTranslation(-outputPos));

	int strokeCount = vi->getStrokeCount();
	std::vector<int> strokeIndex(strokeCount);
	std::vector<TStroke *> strokes(strokeCount);
	int i;
	for (i = 0; i < strokeCount; ++i) {
		strokeIndex[i] = i;
		strokes[i] = vi->getStroke(i);
	}
	vi->notifyChangedStrokes(strokeIndex, strokes);

	int maxStyleId = palette->getStyleCount() - 1;
	for (i = 0; i < (int)vi->getRegionCount(); ++i) {
		TRegion *region = vi->getRegion(i);
		fastAddPaintRegion(ri, region, tmin(maxStyleId, region->getStyle()), maxStyleId);
	}

	set<int> colors;
	if (fxs) {
		for (i = 0; i < (int)fxs->size(); i++) {
			SandorFxRenderData *sandorData = dynamic_cast<SandorFxRenderData *>((*fxs)[i].getPointer());
			if (sandorData && sandorData->m_type == BlendTz) {
				std::string indexes = toString(sandorData->m_blendParams.m_colorIndex);
				std::vector<std::string> items;
				parseIndexes(indexes, items);
				PaletteFilterFxRenderData paletteFilterData;
				insertIndexes(items, &paletteFilterData);
				colors = paletteFilterData.m_colors;
				break;
			}
		}
	}

	for (i = 0; i < strokeCount; ++i) {
		TStroke *stroke = vi->getStroke(i);

		bool visible = false;
		int styleId = stroke->getStyle();
		TColorStyleP style = palette->getStyle(styleId);
		assert(style);
		int colorCount = style->getColorParamCount();
		if (colorCount == 0)
			visible = true;
		else {
			visible = false;
			for (int j = 0; j < style->getColorParamCount() && !visible; j++) {
				TPixel32 color = style->getColorParamValue(j);
				if (color.m != 0)
					visible = true;
			}
		}
		if (visible)
			fastAddInkStroke(ri, stroke, TRectD(), 1, true);
	}
	return ri;
}
コード例 #20
0
ファイル: autofillpli.cpp プロジェクト: walkerka/opentoonz
bool rect_autofill_apply(const TVectorImageP &imgToApply, const TRectD &rect,
                         bool selective) {
  if (rect.getLx() * rect.getLy() < MIN_SIZE) return false;

  if (regionsReference.size() <= 0) return false;

  double pbx, pby;
  double totalArea = 0;
  pbx = pby = 0.0;

  if (!regionsWork.isEmpty()) regionsWork.clear();

  int i, index = 0, regionCount = imgToApply->getRegionCount();
  for (i = 0; i < regionCount; i++) {
    TRegion *region = imgToApply->getRegion(i);
    TRectD bbox     = region->getBBox();
    if (rect.contains(bbox)) {
      scanRegion(region, index, regionsWork, rect);
      index++;
    }
    int j, subRegionCount = region->getSubregionCount();
    for (j = 0; j < subRegionCount; j++) {
      TRegion *subRegion = region->getSubregion(j);
      if (rect.contains(subRegion->getBBox()))
        scanSubRegion(subRegion, index, regionsWork, rect);
    }
  }

  if (regionsWork.size() <= 0) return false;

  QMap<int, Region>::Iterator it;
  for (it = regionsWork.begin(); it != regionsWork.end(); it++) {
    pbx += it.value().m_barycentre.x;
    pby += it.value().m_barycentre.y;
    totalArea += it.value().m_area;
  }

  workB = TPointD(pbx / totalArea, pby / totalArea);

  std::vector<MatchingProbs> probVector;

  RegionDataList::Iterator refIt, workIt;
  for (refIt = regionsReference.begin(); refIt != regionsReference.end();
       refIt++)
    for (workIt = regionsWork.begin(); workIt != regionsWork.end(); workIt++)
      assignProbs(probVector, refIt.value(), workIt.value(), refIt.key(),
                  workIt.key());

  bool filledRegions = false;
  for (refIt = regionsReference.begin(); refIt != regionsReference.end();
       refIt++) {
    int to = 0, from = 0;
    int valore = 0;
    do
      valore = match(probVector, from, to);
    while ((regionsWork[to].m_match != -1 ||
            regionsReference[from].m_match != -1) &&
           valore > 0);
    if (valore > AMB_TRESH) {
      regionsWork[to].m_match        = from;
      regionsReference[from].m_match = to;
      regionsWork[to].m_styleId      = regionsReference[from].m_styleId;
      TRegion *reg                   = regionsWork[to].m_region;
      if (reg && (!selective || selective && reg->getStyle() == 0)) {
        reg->setStyle(regionsWork[to].m_styleId);
        filledRegions = true;
      }
    }
  }
  return filledRegions;
}
コード例 #21
0
ファイル: autofillpli.cpp プロジェクト: walkerka/opentoonz
bool stroke_autofill_apply(const TVectorImageP &imgToApply, TStroke *stroke,
                           bool selective) {
  if (!imgToApply || !stroke || stroke->getControlPointCount() == 0)
    return false;
  TVectorImage appImg;
  TStroke *appStroke = new TStroke(*stroke);
  appImg.addStroke(appStroke);
  appImg.findRegions();

  if (regionsReference.size() <= 0) return false;

  double pbx, pby;
  double totalArea = 0;
  pbx = pby = 0.0;

  if (!regionsWork.isEmpty()) regionsWork.clear();

  int i, j, index = 0;

  for (i = 0; i < (int)imgToApply->getRegionCount(); i++) {
    TRegion *currentRegion = imgToApply->getRegion(i);
    for (j = 0; j < (int)appImg.getRegionCount(); j++) {
      TRegion *region = appImg.getRegion(j);
      if (contains(region, currentRegion)) {
        scanRegion(currentRegion, index, regionsWork, region->getBBox());
        index++;
        int k, subRegionCount = currentRegion->getSubregionCount();
        for (k = 0; k < subRegionCount; k++) {
          TRegion *subRegion = currentRegion->getSubregion(k);
          if (contains(region, subRegion))
            scanSubRegion(subRegion, index, regionsWork, region->getBBox());
        }
      }
    }
  }

  if (regionsWork.size() <= 0) return false;

  QMap<int, Region>::Iterator it;
  for (it = regionsWork.begin(); it != regionsWork.end(); it++) {
    pbx += it.value().m_barycentre.x;
    pby += it.value().m_barycentre.y;
    totalArea += it.value().m_area;
  }

  workB = TPointD(pbx / totalArea, pby / totalArea);

  std::vector<MatchingProbs> probVector;

  RegionDataList::Iterator refIt, workIt;
  for (refIt = regionsReference.begin(); refIt != regionsReference.end();
       refIt++)
    for (workIt = regionsWork.begin(); workIt != regionsWork.end(); workIt++)
      assignProbs(probVector, refIt.value(), workIt.value(), refIt.key(),
                  workIt.key());

  bool filledRegions = false;
  for (refIt = regionsReference.begin(); refIt != regionsReference.end();
       refIt++) {
    int to = 0, from = 0;
    int valore = 0;
    do
      valore = match(probVector, from, to);
    while ((regionsWork[to].m_match != -1 ||
            regionsReference[from].m_match != -1) &&
           valore > 0);
    if (valore > AMB_TRESH) {
      regionsWork[to].m_match        = from;
      regionsReference[from].m_match = to;
      regionsWork[to].m_styleId      = regionsReference[from].m_styleId;
      TRegion *reg                   = regionsWork[to].m_region;
      if (reg && (!selective || selective && reg->getStyle() == 0)) {
        reg->setStyle(regionsWork[to].m_styleId);
        filledRegions = true;
      }
    }
  }
  return filledRegions;
}
コード例 #22
0
// TODO: effect area should be reduced if aClipRegion is smaller than aDisplayRect.
TBool CHuiFxEffect::CachedDraw(CHuiGc& aGc, const TRect& aDisplayRect, TBool aRefreshCachedRenderTarget, TBool aOpaque, const TRegion& aClipRegion, TBool aHasSurface, TInt aAlpha)
    {
#ifdef HUIFX_TRACE    
    RDebug::Print(_L("CHuiFxEffect::CachedDraw - 0x%x"), this);
#endif    
    iFramesDrawn++;
    if (!CHuiStatic::Renderer().Allows(EHuiRenderPluginAllowVisualPBufferSurfaces))
        {
        return EFalse;
        }
            
    
    CHuiFxRenderbuffer* target = NULL;
    
    // Prepare all layers
    TRect displayArea = aGc.DisplayArea();
    TRect targetArea = aDisplayRect;
    targetArea.Intersection(displayArea);

    if (targetArea.Width() <= 0 || targetArea.Height() <= 0)
        {
        // Not visible
        return ETrue;
        }

    if (!iEngine || !iRoot)
        {
        return EFalse;
        }

    if (iEngine->LowMemoryState())
        {
        // No memory, no effects.
        return EFalse;
        }
    
    // Check if margins are allowed to be used for this effect
    if (EffectFlags() & KHuiFxEffectDisableMarginsFlag)
        {
        iRoot->EnableMargin(EFalse);
        }

    // Check if surface pixels are to be used for this effect in all layers.
    if (EffectFlags() & KHuiFxEnableBackgroundInAllLayers)
        {
        iRoot->SetAlwaysReadSurfacePixels(ETrue);
        }
    
    iRoot->SetTargetRect(targetArea);
    iRoot->SetSourceRect(targetArea);        
    iRoot->SetDisplayArea(displayArea);
    
    TRAPD(err, iRoot->PrepareDrawL(*iEngine));
    
    if (err != KErrNone)
        {
        return EFalse;
        }

    if (IsCachedRenderTargetSupported() && IsCachedRenderTargetPreferred())
        {
        // Background needs to be captured from surface if effect uses background AND 
        // Visual is transparent or margin is enabled AND
        // Background has not been disabled with a effect specific flag
        TBool enableBackground = IsAppliedToBackground() && (!aOpaque || iRoot->IsMarginEnabled()) && !(EffectFlags() & KHuiFxDisableBackground);
        
        if (EffectFlags() & KHuiFxEnableBackgroundInAllLayers)
            {
            enableBackground = ETrue;
            }
        
        TBool useFrozenBackground = (EffectFlags() & KHuiFxFrozenBackground);
        
        // Check if cache is up-to date or does it need to be refreshed
        TBool cachedRenderTargetNeedsRefresh = (iRoot->Changed() || aRefreshCachedRenderTarget || (enableBackground && !useFrozenBackground));
        if (!iCachedRenderTarget || (iCachedRenderTarget && iCachedRenderTarget->Size() !=  iRoot->VisualRect().Size())) 
            {
            cachedRenderTargetNeedsRefresh = ETrue;
            }

        // Try to apply also margins, we cannot just use aDisplayRect directly
        TRect targetRect = iRoot->VisualRect();
        
        // Size is always same as target rect. It contains margins if those are enabled.
        TSize cachedRenderTargetSize = targetRect.Size();        
                
        // Prepare cached offscreen render target
        PrepareCachedRenderTarget(targetRect.iTl, cachedRenderTargetSize, cachedRenderTargetNeedsRefresh, enableBackground);
        
        // If it is available, then lets do it 
        if (iCachedRenderTarget)
            {
            // Disable clipping, otherwise strange things happen.
            aGc.Disable(CHuiGc::EFeatureClipping);             
            if (cachedRenderTargetNeedsRefresh)
                {
                // Render to cached render target
                iRoot->Draw(*iEngine, aGc, *iCachedRenderTarget, *iCachedRenderTarget, aHasSurface);                
#ifdef HUIFX_TRACE    
                RDebug::Print(_L("CHuiFxEffect::CachedDraw - refreshed cached render buffer 0x%x"), this);
#endif
                }            

            if (aClipRegion.Count())
                {
                aGc.Enable(CHuiGc::EFeatureClipping);
                aGc.PushClip();
                aGc.Clip(aClipRegion);
                }
            
            // Write cached buffer to the display
           
	       iEngine->Composite(aGc, *iCachedRenderTarget, targetRect.iTl, aOpaque && !(EffectFlags() & KHuiFxAlwaysBlend), aAlpha);
           

            if (aClipRegion.Count())
                {
                aGc.PopClip();
                }
            
            aGc.Enable(CHuiGc::EFeatureClipping);
#ifdef HUIFX_TRACE    
            RDebug::Print(_L("CHuiFxEffect::CachedDraw - Cached render buffer drawn 0x%x"), this);
            RDebug::Print(_L("CHuiFxEffect::CachedDraw - displayrect: %i,%i, %i,%i "), 
                    aDisplayRect.iTl.iX,
                    aDisplayRect.iTl.iY,
                    aDisplayRect.iBr.iX,
                    aDisplayRect.iBr.iY);
#endif            
            }
        else
            {
            // It might not be available e.g. in low memory situations, just indiacte that we could not draw.
            return EFalse;
            }
        }
    else
        {
        // Release cached render target just in case it is reserved for some reason
        ReleaseCachedRenderTarget();

        // Use default onscreen render target
        if (!target)
            {
            target = iEngine->DefaultRenderbuffer();
            }
        
        if (!target)
            {
            return EFalse;
            }
        
        // Normal drawing
        iRoot->Draw(*iEngine, aGc, *target, *target, aHasSurface);
        }
                
    return ETrue;    
    }
コード例 #23
0
void CWsWindow::AreaCovered(TRegion &aRegion)
	{
	aRegion.Copy(WindowArea());
	}
コード例 #24
0
EXPORT_C void CHuiCanvasGc::ClipRegion(const TRegion& aClipRegion)
    {
    if (!iGc)
       {
       return;    
       }

    switch (iClipMode)
        {
        case EHuiCanvasClipModeNormal:
            {
            // If previous clipping region set, cancel it first.
            if (iClippingRegion.Count())
                {
                CancelClipping();    
                }
                
            // Set new region, ignore empty rects if any
            for (TInt i=0; i < aClipRegion.Count(); i++)
                {
                if (!aClipRegion[i].IsEmpty())
                    {
                    iClippingRegion.AddRect(aClipRegion[i]);    
                    }                                        
                }
            
            iClippingRegion.Tidy();
            
            if (iClippingRegion.Count() == 1)
                {
                // If only one rect, then do simple clipping...                    
                iGc->Enable(CHuiGc::EFeatureClipping);
                iGc->PushClip();
                iGc->Clip(iClippingRegion[0]);                
                }
            else if (iClippingRegion.Count() > 1)
                {
                // ...otherewise must do region clipping.
                iGc->Enable(CHuiGc::EFeatureClipping);
                iGc->PushClip();
                if (MaxNumberOfClipRects() > 1)
                    {
                    iGc->Clip(iClippingRegion);                    
                    }
                else
                    {
                    // region clipping is not available, try boundingrect
                    iGc->Clip(iClippingRegion.BoundingRect());                                        
                    }
                }
            else
                {
                // No clip rects set, do nothing here.    
                }                                
            break;
            }
        case EHuiCanvasClipModeDelayed:
            {
            // If previous clipping region set, cancel it first.
            if (iClippingRegion.Count())
                {
                CancelClipping();    
                }
                
            // Set new region, ignore empty rects if any
            for (TInt i=0; i < aClipRegion.Count(); i++)
                {
                if (!aClipRegion[i].IsEmpty())
                    {
                    iClippingRegion.AddRect(aClipRegion[i]);    
                    }                    
                }

            iClippingRegion.Tidy();
            break;    
            }
        case EHuiCanvasClipModeNone:
        default:
            {
            // Do nothing            
            break;    
            }
        }    
    }