コード例 #1
0
bool PoissonBlendEx::init(Composite& rootNode) {

    ImageRGBA srcImg, tarImg;
    ReadImageFromFile(getFullPath("images/sfmarket.png"), srcImg);
    ReadImageFromFile(getFullPath("images/sfsunset.png"), tarImg);

    ConvertImage(srcImg, src);
    ConvertImage(tarImg, tar);

    ImageGlyphPtr srcGlyph = createImageGlyph(srcImg, false);
    ImageGlyphPtr tarGlyph = createImageGlyph(tarImg, false);
    ImageGlyphPtr resultGlyph = createImageGlyph(tarImg, false);

    GlyphRegionPtr srcRegion = MakeGlyphRegion(srcGlyph,
                               CoordPercent(0.05f, 0.0f), CoordPercent(0.4f, 0.3f),
                               AspectRule::FixedWidth, COLOR_NONE, COLOR_NONE,
                               Color(200, 200, 200, 255), UnitPX(1.0f));

    GlyphRegionPtr tarRegion = MakeGlyphRegion(tarGlyph,
                               CoordPercent(0.55f, 0.0f), CoordPercent(0.4f, 0.3f),
                               AspectRule::FixedWidth, COLOR_NONE, COLOR_NONE,
                               Color(200, 200, 200, 255), UnitPX(1.0f));

    TextLabelPtr textLabel = TextLabelPtr(
                                 new TextLabel("Solving Poisson Blend ...",
                                         CoordPercent(0.1f, 0.35f), CoordPercent(0.8f, 0.5f)));
    textLabel->fontSize = UnitPX(20.0f);
    textLabel->fontType = FontType::Bold;
    textLabel->fontStyle = FontStyle::Outline;

    GlyphRegionPtr resultRegion = MakeGlyphRegion(resultGlyph,
                                  CoordPercent(0.1f, 0.35f), CoordPercent(0.8f, 0.5f),
                                  AspectRule::FixedWidth, COLOR_NONE, COLOR_NONE,
                                  Color(200, 200, 200, 255), UnitPX(1.0f));

    rootNode.add(srcRegion);
    rootNode.add(tarRegion);
    rootNode.add(resultRegion);
    rootNode.add(textLabel);
    workerTask = WorkerTaskPtr(new Worker([=] {
        PoissonBlend(src, tar, 32, 6);
        ImageRGBA out;
        ConvertImage(tar,out);
        getContext()->addDeferredTask([=]() {
            resultGlyph->set(out,getContext().get());
            textLabel->setLabel("Finished!");
        });
    }));
    workerTask->execute(isForcedClose());
    return true;
}
コード例 #2
0
bool PoissonInpaintEx::init(Composite& rootNode) {

	ImageRGBA srcImg, tarImg, initImg;
	ReadImageFromFile(getFullPath("images/sfmarket.png"), srcImg);
	ReadImageFromFile(getFullPath("images/sfsunset.png"), tarImg);

	ConvertImage(srcImg, src);
	ConvertImage(tarImg, tar);

	int w = src.width;
	int h = src.height;
	float r = h * 0.4f;
	mask = tar;
	for (int i = 0; i < w; i++) {
		for (int j = 0; j < h; j++) {
			float diff = r
					- length(float2((float) (i - w / 2), (float) (j - h / 2)));
			float alpha = 1.0f - clamp(diff / 128, 0.0f, 1.0f);
			mask(i, j).w = alpha;
		}
	}
	ConvertImage(mask, initImg);
	ImageGlyphPtr srcGlyph = createImageGlyph(srcImg, false);
	ImageGlyphPtr tarGlyph = createImageGlyph(tarImg, false);
	ImageGlyphPtr resultGlyph = createImageGlyph(tarImg, false);

	GlyphRegionPtr srcRegion = MakeGlyphRegion(srcGlyph,
			CoordPercent(0.05f, 0.0f), CoordPercent(0.4f, 0.3f),
			AspectRule::FixedWidth, COLOR_NONE, COLOR_NONE,
			Color(200, 200, 200, 255), UnitPX(1.0f));

	GlyphRegionPtr tarRegion = MakeGlyphRegion(tarGlyph,
			CoordPercent(0.55f, 0.0f), CoordPercent(0.4f, 0.3f),
			AspectRule::FixedWidth, COLOR_NONE, COLOR_NONE,
			Color(200, 200, 200, 255), UnitPX(1.0f));

	TextLabelPtr textLabel = TextLabelPtr(
			new TextLabel("Solving Poisson Inpaint ...",
					CoordPercent(0.1f, 0.35f), CoordPercent(0.8f, 0.5f)));
	textLabel->fontSize = UnitPX(20.0f);
	textLabel->fontType = FontType::Bold;
	textLabel->fontStyle = FontStyle::Outline;

	GlyphRegionPtr resultRegion = MakeGlyphRegion(resultGlyph,
			CoordPercent(0.1f, 0.35f), CoordPercent(0.8f, 0.5f),
			AspectRule::FixedWidth, COLOR_NONE, COLOR_NONE,
			Color(200, 200, 200, 255), UnitPX(1.0f));

	rootNode.add(srcRegion);
	rootNode.add(tarRegion);
	rootNode.add(resultRegion);
	rootNode.add(textLabel);
	workerTask = WorkerTaskPtr(new Worker([=] {
		PoissonInpaint(mask,src, tar, 32, 6);
		ImageRGBA out;
		ConvertImage(tar,out);
		getContext()->addDeferredTask([=]() {
					resultGlyph->set(out,getContext().get());
					textLabel->label="Finished!";
				});
	}));
	workerTask->execute(isForcedClose());
	return true;
}