PNM* MorphologicalOperator::transform()
{  
    int size  = getParameter("size").toInt();
    SE  shape = (MorphologicalOperator::SE) getParameter("shape").toInt();

    PNM* newImage = new PNM(image->width(), image->height(), QImage::Format_RGB32);

    int width = image->width();
    int height = image->height();

    math::matrix<bool> elementStrukturyzujacy = getSE(size, shape);


    for(int x = 0; x < width; x++)
        for(int y = 0; y < height; y++)
        {
            math::matrix<double> windowR = getWindow(x, y, size, RChannel, RepeatEdge);
            math::matrix<double> windowG = getWindow(x, y, size, GChannel, RepeatEdge);
            math::matrix<double> windowB = getWindow(x, y, size, BChannel, RepeatEdge);

            newImage->setPixel(x, y, qRgb(morph(windowR, elementStrukturyzujacy), morph(windowG, elementStrukturyzujacy), morph(windowB, elementStrukturyzujacy)));
        }

    return newImage;
}
Example #2
0
int main(int argc, char *argv[], char *envp[])
{
	morph();
	winmain();
	
	return 0;
}
cv::Mat MOG2ForegroundMaskCalculator::calculate(cv::Mat nextFrame) {
    cv::Mat mask;
    bgSub->apply(nextFrame, mask, 0.001);

    removeShadows(mask);
    morph(mask);

    return mask;
}
Example #4
0
int main (int argc, char *argv[]) {
	//~ test_bill_house();

	if (argc != 7) {
		fprintf(stderr, "Wrong number of arguments");
		return EXIT_FAILURE;
	}

	// setup
	char *src_path = argv[1];
	char *dst_path = argv[2];
	char *out_path = argv[3];
	char *segments_path = argv[4];
	int n_frames = atoi(argv[5]);
	int fps = atoi(argv[6]);

	FILE *segments_file = fopen(segments_path, "r");

	int n_segments;
	read_int(segments_file, &n_segments);

	segment src_segments[n_segments];
	segment dst_segments[n_segments];

	read_segments(segments_file, src_segments, n_segments);
	read_segments(segments_file, dst_segments, n_segments);

	fclose(segments_file);

	IplImage *src_image, *dst_image;

	if ((src_image = cvLoadImage(src_path, CV_LOAD_IMAGE_COLOR)) == 0) {
		fprintf(stderr, "Couldn't load source image\n");
		exit(EXIT_FAILURE);
	}

	if ((dst_image = cvLoadImage(dst_path, CV_LOAD_IMAGE_COLOR)) == 0) {
		fprintf(stderr, "Couldn't load destination image\n");
		exit(EXIT_FAILURE);
	}

	CvVideoWriter *writer = create_video_writer(out_path, src_image->width, src_image->height, fps);
	
	if(writer == NULL) {
        fprintf(stderr, "Cannot create video writer\n");
        exit(EXIT_FAILURE);
    }

    // morph
    morph(src_image, dst_image, src_segments, dst_segments, n_segments, n_frames, writer, ASM);

	cvReleaseImage(&src_image);
	cvReleaseImage(&dst_image);
	cvReleaseVideoWriter(&writer);

	return EXIT_SUCCESS;
}
Example #5
0
void  
MorphShape::display(Renderer& renderer, const Transform& base)
{
    morph();

    const Transform xform = base * transform();

    _def->display(renderer, _shape, xform); 
    clear_invalidated();
}
Example #6
0
int main(int argc, char *argv[], char *envp[])
{
    _envargs(&argc,&argv,"HANEDIT2OPT");
    argcheck(argc,argv);
#ifdef DEBUG
    morph();
#endif
    winmain();

    return 0;
}
/* sets the new target brightness of LEDs */
void setTarget2(float color[], int fadeMS)
{
    pauseLED=1;
    
    morph(origin); //seed origin with current colour
    copyColourArray(color,target); //seed target with passed colour

    stepIndex=0;
    stepCount=fadeMS/MORPH_TIMER_MS;
    pauseLED=0;
}
//morph images to fill the PsPdStore
int ImageHandler::fillPsPdStore(int N,const char* keypointfilename)
{
    int positionJ = 1;
    //bool incrementflag= false;
    for(int i = 0; i < N-1;i++)
    {
        //incrememnt flag  is for positionJ, only want to increment every other iteration
        //if(i%2 == 0) incrementflag = true;
       // else incrementflag = false;

        if(morph(sourceImage,PsPdStore.at(i), keypointfilename,positionJ,true)== -1)return -1;
        i++;
        if(morph(destImage,PsPdStore.at(i),keypointfilename,positionJ,false)==-1)return -1;
        //increment position J, refering to the jth keypoint every other iteration
        //if(incrementflag)
        positionJ++;
    }

    return 0;

}
//calculate led power usage
float getTotalLEDPower()
{   
    float v[LEDS];
    morph(v);
    
    float totalPower=0;
    float divisor=1.0f/256.0f;
    for (int i=0; i<LEDS; i++)
    {   totalPower += v[i]*(float)ledPowerMap[i]*divisor;
    }
    return totalPower;
}
Example #10
0
void    morph_ifs   ( void )
{
	FILE    *stream;
	stream= fopen( "hilist.dat", "rb" );
	while( fread( morph_list, 4, _MAX_POINT, stream ) == _MAX_POINT )
	{
		morph();
		chaos();
		wait_count( 70 * 1 );
	}

	fclose( stream );
}
Example #11
0
 virtual const char* next(){
     current.reset();
     const char * s = item.next();
     current.append_array(s, strlen(s) + 1);
     if  (last.content_size() == 0) {
         str.reset();
         last.reset();
         str.append_array(current, current.content_size());
         last.append_array(current, current.content_size());
     } else {
         morph();
     }
     return str;
 }
/* called by timer every 20ms */
void adjustLights()
{
    if (!pauseLED)
    {   if (stepIndex<stepCount)
        {   stepIndex++;
            float v[LEDS];
            morph(v);
            for (int i=0; i<LEDS; i++)
            {   v[i]+=offset[i];
            }
            setLEDs(v);
        }
    }
}
Example #13
0
void Player::render()
{
	morph();
	glPushMatrix();
	//glTranslatef(position.X_Y_Z[0],position.X_Y_Z[1],position.X_Y_Z[2]);
	orientation.normalize();
	this->directionVec.multiplyVector(orientation);
	transform = Matrix44(position,orientation);
	transform.copyIntoSingleArray();
	glMultMatrixf(transform.OneDmat);
	glRotatef(90.f,0,0,1);
	glRotatef(90.f,1,0,0);
	

	glBindTexture(GL_TEXTURE_2D, this->modelTexture.texID);
	// Begin drawing of triangles.
	glmDraw(this->model, GLM_SMOOTH | GLM_TEXTURE);

	glPopMatrix();
}
    virtual void onDraw(SkCanvas* canvas) {
        if (!fInitialized) {
            this->make_bitmap();
            fInitialized = true;
        }
        canvas->clear(0x00000000);
        {
            SkAutoTUnref<SkImageFilter> bitmapSource(new SkBitmapSource(fBitmap));
            SkAutoTUnref<SkColorFilter> cf(SkColorFilter::CreateModeFilter(SK_ColorRED,
                                                         SkXfermode::kSrcIn_Mode));
            SkAutoTUnref<SkImageFilter> blur(new SkBlurImageFilter(4.0f, 4.0f, bitmapSource));
            SkAutoTUnref<SkImageFilter> erode(new SkErodeImageFilter(4, 4, blur));
            SkAutoTUnref<SkImageFilter> color(SkColorFilterImageFilter::Create(cf, erode));
            SkAutoTUnref<SkImageFilter> merge(new SkMergeImageFilter(blur, color));

            SkPaint paint;
            paint.setImageFilter(merge);
            canvas->drawPaint(paint);
        }
        {
            SkAutoTUnref<SkImageFilter> morph(new SkDilateImageFilter(5, 5));

            SkScalar matrix[20] = { SK_Scalar1, 0, 0, 0, 0,
                                    0, SK_Scalar1, 0, 0, 0,
                                    0, 0, SK_Scalar1, 0, 0,
                                    0, 0, 0, SkFloatToScalar(0.5f), 0 };

            SkAutoTUnref<SkColorFilter> matrixFilter(new SkColorMatrixFilter(matrix));
            SkAutoTUnref<SkImageFilter> colorMorph(SkColorFilterImageFilter::Create(matrixFilter, morph));
            SkAutoTUnref<SkXfermode> mode(SkXfermode::Create(SkXfermode::kSrcOver_Mode));
            SkAutoTUnref<SkImageFilter> blendColor(new SkXfermodeImageFilter(mode, colorMorph));

            SkPaint paint;
            paint.setImageFilter(blendColor);
            canvas->drawBitmap(fBitmap, 100, 0, &paint);
        }
    }
Example #15
0
/* This keeps the directory tree and the map geometry in sync
 * (expansion state vs. "deployment" value) */
void
colexp( GNode *dnode, ColExpMesg mesg )
{
	static double colexp_time;
	static int depth = 0;
	static int max_depth;
	GNode *node;
	double wait_time;
	double pan_time;
	int wait_count = 0;
	boolean curnode_is_ancestor, curnode_is_descendant, curnode_is_equal;

	g_assert( NODE_IS_DIR(dnode) );

	if (depth == 0) {
#ifdef DEBUG
		if (mesg != COLEXP_EXPAND_ANY) {
			/* All ancestor directories must be expanded */
			node = dnode->parent;
			while (NODE_IS_DIR(node)) {
				g_assert( DIR_NODE_DESC(node)->deployment > (1.0 - EPSILON) );
				node = node->parent;
			}
		}
#endif

		/* Update ctree and determine maximum recursion depth */
		switch (mesg) {
			case COLEXP_COLLAPSE_RECURSIVE:
			dirtree_entry_collapse_recursive( dnode );
			max_depth = max_expanded_depth( dnode );
			break;

			case COLEXP_EXPAND:
			dirtree_entry_expand( dnode );
			max_depth = 0;
			break;

			case COLEXP_EXPAND_ANY:
			dirtree_entry_expand( dnode );
			max_depth = collapsed_depth( dnode );
			break;

			case COLEXP_EXPAND_RECURSIVE:
			dirtree_entry_expand_recursive( dnode );
			/* max_depth will be used as a high-water mark */
			max_depth = 0;
			break;

			SWITCH_FAIL
		}

		/* Make file list appropriately (in)accessible */
		filelist_reset_access( );

		gui_update( );

		/* Collapse/expand time for current visualization mode */
		switch (globals.fsv_mode) {
			case FSV_DISCV:
			colexp_time = DISCV_COLEXP_TIME;
			break;

			case FSV_MAPV:
			colexp_time = MAPV_COLEXP_TIME;
			break;

			case FSV_TREEV:
			colexp_time = TREEV_COLEXP_TIME;
			break;

                        SWITCH_FAIL
		}
	}

	morph_break( &DIR_NODE_DESC(dnode)->deployment );

	/* Determine time to wait before collapsing/expanding directory */
	switch (mesg) {
		case COLEXP_COLLAPSE_RECURSIVE:
		wait_count = max_depth - depth;
		break;

		case COLEXP_EXPAND_RECURSIVE:
		case COLEXP_EXPAND:
		wait_count = depth;
		break;

		case COLEXP_EXPAND_ANY:
		wait_count = max_depth - depth;
		break;

		SWITCH_FAIL
	}
	if (wait_count > 0) {
		wait_time = (double)wait_count * colexp_time;
		morph( &DIR_NODE_DESC(dnode)->deployment, MORPH_LINEAR, DIR_NODE_DESC(dnode)->deployment, wait_time );
	}

	/* Initiate collapse/expand */
	switch (mesg) {
		case COLEXP_COLLAPSE_RECURSIVE:
		morph_full( &DIR_NODE_DESC(dnode)->deployment, MORPH_QUADRATIC, 0.0, colexp_time, colexp_progress_cb, colexp_progress_cb, dnode );
		break;

		case COLEXP_EXPAND:
		case COLEXP_EXPAND_ANY:
		case COLEXP_EXPAND_RECURSIVE:
		morph_full( &DIR_NODE_DESC(dnode)->deployment, MORPH_INV_QUADRATIC, 1.0, colexp_time, colexp_progress_cb, colexp_progress_cb, dnode );
		break;

		SWITCH_FAIL
	}

	/* Recursion */
	/* geometry_colexp_initiated( ) is called at differing points below
	 * because (at least in TreeV mode) notification must always
	 * proceed from parent to children, and not the other way around */
	switch (mesg) {
		case COLEXP_EXPAND:
		/* Initial collapse/expand notify */
		geometry_colexp_initiated( dnode );
		/* EXPAND does not walk the tree */
		break;

		case COLEXP_EXPAND_ANY:
		/* Ensure that all parent directories are expanded */
		if (NODE_IS_DIR(dnode->parent)) {
			++depth;
			colexp( dnode->parent, COLEXP_EXPAND_ANY );
			--depth;
		}
		/* Initial collapse/expand notify */
		geometry_colexp_initiated( dnode );
		break;

		case COLEXP_COLLAPSE_RECURSIVE:
		case COLEXP_EXPAND_RECURSIVE:
		/* Initial collapse/expand notify */
		geometry_colexp_initiated( dnode );
		/* Perform action on subdirectories */
		++depth;
		node = dnode->children;
		while (node != NULL) {
			if (NODE_IS_DIR(node))
				colexp( node, mesg );
			else
				break;
			node = node->next;
		}
		--depth;
		break;

		SWITCH_FAIL
	}

	if (mesg == COLEXP_EXPAND_RECURSIVE) {
		/* Update high-water mark */
		max_depth = MAX(max_depth, depth);
	}

	if (depth == 0) {
		/* Determine position of current node w.r.t. the
		 * collapsing/expanding directory node */
		curnode_is_ancestor = g_node_is_ancestor( globals.current_node, dnode );
		curnode_is_equal = globals.current_node == dnode;
		curnode_is_descendant = g_node_is_ancestor( dnode, globals.current_node );

		/* Handle the camera semi-intelligently if it is not under
		 * manual control */
		if (!camera->manual_control) {
			switch (mesg) {
				case COLEXP_COLLAPSE_RECURSIVE:
				pan_time = (double)(max_depth + 1) * colexp_time;
				if (curnode_is_ancestor || curnode_is_equal)
					camera_look_at_full( globals.current_node, MORPH_LINEAR, pan_time );
				else if (curnode_is_descendant)
					camera_look_at_full( dnode, MORPH_LINEAR, pan_time );
				break;

				case COLEXP_EXPAND:
				case COLEXP_EXPAND_RECURSIVE:
				if (curnode_is_ancestor || curnode_is_equal) {
					pan_time = (double)(max_depth + 1) * colexp_time;
					camera_look_at_full( globals.current_node, MORPH_LINEAR, pan_time );
				}
				break;

				case COLEXP_EXPAND_ANY:
				/* Don't do anything. Something else
				 * should already be doing something
				 * with the camera */
				break;

				SWITCH_FAIL
			}
		}

		/* If, in TreeV mode, the current node is an ancestor of
		 * a collapsing/expanding directory, the scrollbars may
		 * need updating to reflect a new scroll range */
		scrollbars_colexp_adjust = FALSE;
		if (curnode_is_ancestor && (globals.fsv_mode == FSV_TREEV))
			scrollbars_colexp_adjust = TRUE;
	}
Example #16
0
    void onDraw(SkCanvas* canvas) override {
        canvas->clear(SK_ColorBLACK);
        {
            sk_sp<SkImageFilter> bitmapSource(SkImageSource::Make(fImage));
            sk_sp<SkColorFilter> cf(SkColorFilter::MakeModeFilter(SK_ColorRED,
                                                                  SkBlendMode::kSrcIn));
            sk_sp<SkImageFilter> blur(SkBlurImageFilter::Make(4.0f, 4.0f, std::move(bitmapSource)));
            sk_sp<SkImageFilter> erode(SkErodeImageFilter::Make(4, 4, blur));
            sk_sp<SkImageFilter> color(SkColorFilterImageFilter::Make(std::move(cf),
                                                                      std::move(erode)));
            sk_sp<SkImageFilter> merge(SkMergeImageFilter::Make(blur, color,
                                                                SkBlendMode::kSrcOver));

            SkPaint paint;
            paint.setImageFilter(std::move(merge));
            canvas->drawPaint(paint);
            canvas->translate(SkIntToScalar(100), 0);
        }
        {
            sk_sp<SkImageFilter> morph(SkDilateImageFilter::Make(5, 5, nullptr));

            SkScalar matrix[20] = { SK_Scalar1, 0, 0, 0, 0,
                                    0, SK_Scalar1, 0, 0, 0,
                                    0, 0, SK_Scalar1, 0, 0,
                                    0, 0, 0, 0.5f, 0 };

            sk_sp<SkColorFilter> matrixFilter(SkColorFilter::MakeMatrixFilterRowMajor255(matrix));
            sk_sp<SkImageFilter> colorMorph(SkColorFilterImageFilter::Make(std::move(matrixFilter),
                                                                           std::move(morph)));
            SkPaint paint;
            paint.setImageFilter(SkXfermodeImageFilter::Make(SkBlendMode::kSrcOver,
                                                             std::move(colorMorph)));

            DrawClippedImage(canvas, fImage.get(), paint);
            canvas->translate(SkIntToScalar(100), 0);
        }
        {
            SkScalar matrix[20] = { SK_Scalar1, 0, 0, 0, 0,
                                    0, SK_Scalar1, 0, 0, 0,
                                    0, 0, SK_Scalar1, 0, 0,
                                    0, 0, 0, 0.5f, 0 };
            sk_sp<SkColorFilter> matrixCF(SkColorFilter::MakeMatrixFilterRowMajor255(matrix));
            sk_sp<SkImageFilter> matrixFilter(SkColorFilterImageFilter::Make(std::move(matrixCF),
                                                                             nullptr));
            sk_sp<SkImageFilter> offsetFilter(SkOffsetImageFilter::Make(10.0f, 10.f,
                                                                        matrixFilter));

            SkPaint paint;
            paint.setImageFilter(
                SkXfermodeImageFilter::MakeArithmetic(0, 1, 1, 0, true,
                                            std::move(matrixFilter),
                                            std::move(offsetFilter),
                                            nullptr));

            DrawClippedImage(canvas, fImage.get(), paint);
            canvas->translate(SkIntToScalar(100), 0);
        }
        {
            sk_sp<SkImageFilter> blur(SkBlurImageFilter::Make(SkIntToScalar(10),
                                                              SkIntToScalar(10),
                                                              nullptr));

            SkImageFilter::CropRect cropRect(SkRect::MakeWH(SkIntToScalar(95), SkIntToScalar(100)));
            SkPaint paint;
            paint.setImageFilter(
                SkXfermodeImageFilter::Make(SkBlendMode::kSrcIn, std::move(blur), nullptr,
                                            &cropRect));
            DrawClippedImage(canvas, fImage.get(), paint);
            canvas->translate(SkIntToScalar(100), 0);
        }
        {
            // Dilate -> matrix convolution.
            // This tests that a filter using asFragmentProcessor (matrix
            // convolution) correctly handles a non-zero source offset
            // (supplied by the dilate).
            sk_sp<SkImageFilter> dilate(SkDilateImageFilter::Make(5, 5, nullptr));

            SkScalar kernel[9] = {
                SkIntToScalar(-1), SkIntToScalar( -1 ), SkIntToScalar(-1),
                SkIntToScalar(-1), SkIntToScalar(  7 ), SkIntToScalar(-1),
                SkIntToScalar(-1), SkIntToScalar( -1 ), SkIntToScalar(-1),
            };
            SkISize kernelSize = SkISize::Make(3, 3);
            SkScalar gain = 1.0f, bias = SkIntToScalar(0);
            SkIPoint kernelOffset = SkIPoint::Make(1, 1);
            auto tileMode = SkMatrixConvolutionImageFilter::kClamp_TileMode;
            bool convolveAlpha = false;
            sk_sp<SkImageFilter> convolve(SkMatrixConvolutionImageFilter::Make(kernelSize,
                                                                               kernel,
                                                                               gain,
                                                                               bias,
                                                                               kernelOffset,
                                                                               tileMode,
                                                                               convolveAlpha,
                                                                               std::move(dilate)));

            SkPaint paint;
            paint.setImageFilter(std::move(convolve));
            DrawClippedImage(canvas, fImage.get(), paint);
            canvas->translate(SkIntToScalar(100), 0);
        }
        {
            // Test that crop offsets are absolute, not relative to the parent's crop rect.
            sk_sp<SkColorFilter> cf1(SkColorFilter::MakeModeFilter(SK_ColorBLUE,
                                                                   SkBlendMode::kSrcIn));
            sk_sp<SkColorFilter> cf2(SkColorFilter::MakeModeFilter(SK_ColorGREEN,
                                                                   SkBlendMode::kSrcIn));
            SkImageFilter::CropRect outerRect(SkRect::MakeXYWH(SkIntToScalar(10), SkIntToScalar(10),
                                                               SkIntToScalar(80), SkIntToScalar(80)));
            SkImageFilter::CropRect innerRect(SkRect::MakeXYWH(SkIntToScalar(20), SkIntToScalar(20),
                                                               SkIntToScalar(60), SkIntToScalar(60)));
            sk_sp<SkImageFilter> color1(SkColorFilterImageFilter::Make(std::move(cf1),
                                                                       nullptr,
                                                                       &outerRect));
            sk_sp<SkImageFilter> color2(SkColorFilterImageFilter::Make(std::move(cf2),
                                                                       std::move(color1),
                                                                       &innerRect));

            SkPaint paint;
            paint.setImageFilter(std::move(color2));
            paint.setColor(SK_ColorRED);
            canvas->drawRect(SkRect::MakeXYWH(0, 0, 100, 100), paint);
            canvas->translate(SkIntToScalar(100), 0);
        }
    }
Example #17
0
void credits2(void)
{
    int i, ch;
    int p;
    int plast = -1;
    clrscr();

    centerprint(aa_imgwidth(context) / 2, aa_imgheight(context) / 3, 3, 128, "The", 0);
    centerprint(aa_imgwidth(context) / 2, 2 * aa_imgheight(context) / 3, 3, 128, "END", 0);
    drawptr = decrand;
    params->randomval = 50;
    timestuff(0, NULL, draw, 5000000);
    drawptr = NULL;
    params->randomval = 0;
    drawptr = pryc;
    timestuff(0, NULL, draw, MAXTIME);
    drawptr = NULL;
    clrscr();
    draw();
    load_song("bb3.s3m");
    bbupdate();
    starttime = endtime = TIME;
    play();
    bbwait(1);
    for (i = 0; i < LOGOHEIGHT; i++) {
	aa_puts(context, aa_scrwidth(context) / 2 - 2, LOGOY + i, AA_BOLD, "8  8");
	if (i)
	    aa_puts(context, aa_scrwidth(context) / 2 - 2, LOGOY + i - 1, AA_NORMAL, "8  8");
	bbflushwait(100000);
    }
    aa_puts(context, aa_scrwidth(context) / 2 - 2, LOGOY + i - 1, AA_NORMAL, "8  8");

#define LWIDTH

    for (i = aa_scrwidth(context) / 2; i; i--) {
	display8();
	displaya(i);
	bbflushwait(10000);
    }
    for (; i < 100; i++) {
	textclrscr();
	displaya(10 * sin(i * M_PI / 100));
	display8();
	bbflushwait(10000);
    }
    aa_puts(context, aa_scrwidth(context) / 2 - 9, LOGOY + 3, AA_DIM, "<PROJECT><PROJECT>");
    bbflushwait(100000);
    aa_puts(context, aa_scrwidth(context) / 2 - 9, LOGOY + 3, AA_NORMAL, "<PROJECT><PROJECT>");
    bbflushwait(100000);
    aa_puts(context, aa_scrwidth(context) / 2 - 9, LOGOY + 3, AA_BOLD, "<PROJECT><PROJECT>");
    bbflushwait(100000);
    aa_puts(context, aa_scrwidth(context) / 2 - 9, LOGOY + 3, AA_NORMAL, "<PROJECT><PROJECT>");
    bbflushwait(100000);
    bbwait(1000000);
    for (i = LOGOY; i > 1; i--) {
	textclrscr();
	displogo(i);
	bbflushwait(30000);
    }

    source = malloc(aa_imgwidth(context) * (aa_imgheight(context)));
    target = malloc(aa_imgwidth(context) * (aa_imgheight(context)));
    params->dither = AA_NONE;
    format(dual ? aa_scrwidth(context) / 2 : aa_scrwidth(context));
    p = 0;
    while (1) {
	if (p != plast) {
	    getsource();
	    displaytext(p);
	    gettarget();
	    morph();
	    displaytext(p);
	    aa_flush(context);
        emscripten_sleep(1);
	    plast = p;
	}
      again:
    emscripten_sleep(100);
#ifndef __DJGPP__
	//ch = aa_getkey(context, 100);
    ch = AA_NONE;
#else
	while ((ch = bbupdate()) == AA_NONE) ;
#endif

	switch (ch) {
	case '1':
	    load_song("bb.s3m");
	    bbupdate();
	    play();
	    break;
	case '2':
	    load_song("bb2.s3m");
	    bbupdate();
	    play();
	    break;
	case '3':
	    load_song("bb3.s3m");
	    bbupdate();
	    play();
	    break;

	case 'b':
	case 'k':
	case 'B':
	case 'K':
	case AA_BACKSPACE:
	case AA_UP:
	    p -= (aa_scrheight(context) - YSTART) / 2 * (dual + 1);
	    if (p < 0)
		p = 0;
	    break;
	case AA_DOWN:
	case AA_LEFT:
	case 'f':
	case 'F':
	case ' ':
	case 'j':
	case 'J':
	    p += (aa_scrheight(context) - YSTART) / 2 * (dual + 1);
	    if (p > textsize)
		p = textsize;
	    break;
	case 'q':
	case 'Q':
	case AA_ESC:
	    finish_stuff = 0;
	    backconvert(0, 0, aa_scrwidth(context), aa_scrheight(context));
	    bbupdate();
	    starttime = endtime = TIME;
	    drawptr = decbright;
	    timestuff(0, NULL, draw, 1000000);
	    textclrscr();
	    drawptr = NULL;
	    aa_flush(context);
        emscripten_sleep(1);
	    free(source);
	    free(target);
	    return;
	default:
	    goto again;
	}
	bbupdate();
	starttime = endtime = TIME;
    }
}
Example #18
0
SkPath TextArt::EnvelopeWarp::warp(const std::string& text, SkTypeface* typeface)
{
	SkPath				warpedPath;

	if (text.empty())
		return warpedPath;

	//prepare paint
	SkPaint paint;
	paint.setTextSize(SkIntToScalar(64));
	paint.setTypeface(typeface);
	paint.setTextAlign(SkPaint::kCenter_Align);

	//measure Bottom path to center text on it
	SkPathMeasure   bMeasure(bSkeleton_, false);
	SkScalar        hBOffset = 0;

    if (paint.getTextAlign() != SkPaint::kLeft_Align)
	{
        SkScalar pathLen = bMeasure.getLength();
        if (paint.getTextAlign() == SkPaint::kCenter_Align)
		{
            pathLen = SkScalarHalf(pathLen);
        }
        hBOffset += pathLen;
    }

	//get text boundaries on normal(non-warped) state
	{
		SkMatrix scaleMartix;
		scaleMartix.setIdentity();

		SkTextToPathIter	iter(text.c_str(), text.size(), paint, true);
		const SkPath*   glypthPath;
		SkScalar        xpos;

		SkScalar        scale = iter.getPathScale();
		scaleMartix.setScale(scale, scale);

		while (iter.next(&glypthPath, &xpos))
		{
			if (glypthPath)
			{
				//prepare resulting transformatiom Matrix
				SkMatrix	compositeMatrix(scaleMartix);
				compositeMatrix.postTranslate(xpos + hBOffset, 0);
				
				SkPath p;
				(*glypthPath).transform(compositeMatrix, &p);
				//get normal(without any warps) text boundaries
				boundsRect_.join( p.getBounds() );
			}
		}
	}

	//center text on Top skeleton
	SkPathMeasure   tMeasure(tSkeleton_, false);
	SkScalar        hTOffset = 0;	
	{
		if (paint.getTextAlign() != SkPaint::kLeft_Align)
		{
			SkScalar pathLen = tMeasure.getLength();
			if (paint.getTextAlign() == SkPaint::kCenter_Align)
			{
				pathLen = SkScalarHalf(pathLen);
			}
			hTOffset += pathLen;
		}
	}		
	
	//warp text on Bottom and Top skeletons
	{
		SkTextToPathIter	iter(text.c_str(), text.size(), paint, true);
		SkScalar        xpos;

		SkMatrix        scaleMartix;
		SkScalar        scale = iter.getPathScale();
		scaleMartix.setScale(scale, scale);

		SkPath line;
		line.lineTo(SkIntToScalar(100), SkIntToScalar(0));
		SkPathMeasure   lineMeasure(line, false);

		SkPathCrossing bCrossing(bSkeleton_);
		SkPathCrossing tCrossing(tSkeleton_);

		const SkPath*   glypthPathOrig;
		while (iter.next(&glypthPathOrig, &xpos))
		{
			if (glypthPathOrig)
			{
				SkPath glypthPath;
				SkRect glypthBound;
				glypthBound = (*glypthPathOrig).getBounds();
				glypthPathOrig->offset(-glypthBound.fLeft, 0, &glypthPath);

				morph(bSkeleton_, bMeasure, bCrossing,
						tSkeleton_, tMeasure, tCrossing,
						glypthPath, lineMeasure, scaleMartix,
						xpos, hBOffset, hTOffset, warpedPath);

			}
		}
	}
	
	return warpedPath;
}
Example #19
0
void test_bill_house() {
	char *src_path = "bill.bmp";
	char *dst_path = "house.bmp";
	char *out_path = "billhouse.avi";

	IplImage *src_image, *dst_image;

	if ((src_image = cvLoadImage(src_path, CV_LOAD_IMAGE_COLOR)) == 0) {
		fprintf(stderr, "Couldn't load source image\n");
		exit(EXIT_FAILURE);
	}

	if ((dst_image = cvLoadImage(dst_path, CV_LOAD_IMAGE_COLOR)) == 0) {
		fprintf(stderr, "Couldn't load destination image\n");
		exit(EXIT_FAILURE);
	}

	CvVideoWriter *writer = create_video_writer(out_path, src_image->width, src_image->height, 25);
	
	if(writer == NULL) {
        fprintf(stderr, "Cannot create video writer\n");
        exit(EXIT_FAILURE);
    }

	int n_segments = 24;

	segment src_segments[n_segments];
	src_segments[0].from.x = 233;
	src_segments[0].from.y = 249;
	src_segments[0].to.x = 269;
	src_segments[0].to.y = 342;

	src_segments[1].from.x = 275;
	src_segments[1].from.y = 359;
	src_segments[1].to.x = 324;
	src_segments[1].to.y = 415;

	src_segments[2].from.x = 344;
	src_segments[2].from.y = 428;
	src_segments[2].to.x = 394;
	src_segments[2].to.y = 444;

	src_segments[3].from.x = 397;
	src_segments[3].from.y = 445;
	src_segments[3].to.x = 439;
	src_segments[3].to.y = 424;

	src_segments[4].from.x = 449;
	src_segments[4].from.y = 406;
	src_segments[4].to.x = 513;
	src_segments[4].to.y = 327;

	src_segments[5].from.x = 520;
	src_segments[5].from.y = 311;
	src_segments[5].to.x = 542;
	src_segments[5].to.y = 221;

	src_segments[6].from.x = 227;
	src_segments[6].from.y = 212;
	src_segments[6].to.x = 242;
	src_segments[6].to.y = 107;

	src_segments[7].from.x = 251;
	src_segments[7].from.y = 84;
	src_segments[7].to.x = 351;
	src_segments[7].to.y = 30;

	src_segments[8].from.x = 373;
	src_segments[8].from.y = 28;
	src_segments[8].to.x = 487;
	src_segments[8].to.y = 70;

	src_segments[9].from.x = 497;
	src_segments[9].from.y = 92;
	src_segments[9].to.x = 543;
	src_segments[9].to.y = 192;

	src_segments[10].from.x = 306;
	src_segments[10].from.y = 432;
	src_segments[10].to.x = 277;
	src_segments[10].to.y = 477;

	src_segments[11].from.x = 263;
	src_segments[11].from.y = 482;
	src_segments[11].to.x = 60;
	src_segments[11].to.y = 575;

	src_segments[12].from.x = 518;
	src_segments[12].from.y = 396;
	src_segments[12].to.x = 561;
	src_segments[12].to.y = 440;

	src_segments[13].from.x = 580;
	src_segments[13].from.y = 441;
	src_segments[13].to.x = 793;
	src_segments[13].to.y = 493;

	src_segments[14].from.x = 283;
	src_segments[14].from.y = 201;
	src_segments[14].to.x = 344;
	src_segments[14].to.y = 193;

	src_segments[15].from.x = 401;
	src_segments[15].from.y = 188;
	src_segments[15].to.x = 458;
	src_segments[15].to.y = 186;

	src_segments[16].from.x = 299;
	src_segments[16].from.y = 220;
	src_segments[16].to.x = 337;
	src_segments[16].to.y = 221;

	src_segments[17].from.x = 415;
	src_segments[17].from.y = 215;
	src_segments[17].to.x = 465;
	src_segments[17].to.y = 210;

	src_segments[18].from.x = 378;
	src_segments[18].from.y = 223;
	src_segments[18].to.x = 381;
	src_segments[18].to.y = 293;

	src_segments[19].from.x = 332;
	src_segments[19].from.y = 285;
	src_segments[19].to.x = 298;
	src_segments[19].to.y = 326;

	src_segments[20].from.x = 434;
	src_segments[20].from.y = 273;
	src_segments[20].to.x = 475;
	src_segments[20].to.y = 307;

	src_segments[21].from.x = 322;
	src_segments[21].from.y = 332;
	src_segments[21].to.x = 453;
	src_segments[21].to.y = 326;

	src_segments[22].from.x = 321;
	src_segments[22].from.y = 341;
	src_segments[22].to.x = 388;
	src_segments[22].to.y = 364;

	src_segments[23].from.x = 389;
	src_segments[23].from.y = 363;
	src_segments[23].to.x = 449;
	src_segments[23].to.y = 335;


	segment dst_segments[n_segments];
	dst_segments[0].from.x = 283;
	dst_segments[0].from.y = 223;
	dst_segments[0].to.x = 307;
	dst_segments[0].to.y = 316;

	dst_segments[1].from.x = 317;
	dst_segments[1].from.y = 349;
	dst_segments[1].to.x = 356;
	dst_segments[1].to.y = 428;

	dst_segments[2].from.x = 366;
	dst_segments[2].from.y = 447;
	dst_segments[2].to.x = 412;
	dst_segments[2].to.y = 464;

	dst_segments[3].from.x = 420;
	dst_segments[3].from.y = 462;
	dst_segments[3].to.x = 465;
	dst_segments[3].to.y = 445;

	dst_segments[4].from.x = 482;
	dst_segments[4].from.y = 428;
	dst_segments[4].to.x = 530;
	dst_segments[4].to.y = 343;

	dst_segments[5].from.x = 536;
	dst_segments[5].from.y = 319;
	dst_segments[5].to.x = 573;
	dst_segments[5].to.y = 231;

	dst_segments[6].from.x = 286;
	dst_segments[6].from.y = 198;
	dst_segments[6].to.x = 302;
	dst_segments[6].to.y = 90;

	dst_segments[7].from.x = 314;
	dst_segments[7].from.y = 69;
	dst_segments[7].to.x = 414;
	dst_segments[7].to.y = 13;

	dst_segments[8].from.x = 434;
	dst_segments[8].from.y = 19;
	dst_segments[8].to.x = 527;
	dst_segments[8].to.y = 63;

	dst_segments[9].from.x = 542;
	dst_segments[9].from.y = 82;
	dst_segments[9].to.x = 571;
	dst_segments[9].to.y = 200;

	dst_segments[10].from.x = 320;
	dst_segments[10].from.y = 404;
	dst_segments[10].to.x = 281;
	dst_segments[10].to.y = 437;

	dst_segments[11].from.x = 265;
	dst_segments[11].from.y = 443;
	dst_segments[11].to.x = 92;
	dst_segments[11].to.y = 513;

	dst_segments[12].from.x = 524;
	dst_segments[12].from.y = 417;
	dst_segments[12].to.x = 562;
	dst_segments[12].to.y = 453;

	dst_segments[13].from.x = 572;
	dst_segments[13].from.y = 457;
	dst_segments[13].to.x = 725;
	dst_segments[13].to.y = 520;

	dst_segments[14].from.x = 323;
	dst_segments[14].from.y = 211;
	dst_segments[14].to.x = 395;
	dst_segments[14].to.y = 213;

	dst_segments[15].from.x = 445;
	dst_segments[15].from.y = 213;
	dst_segments[15].to.x = 506;
	dst_segments[15].to.y = 208;

	dst_segments[16].from.x = 336;
	dst_segments[16].from.y = 228;
	dst_segments[16].to.x = 383;
	dst_segments[16].to.y = 229;

	dst_segments[17].from.x = 456;
	dst_segments[17].from.y = 228;
	dst_segments[17].to.x = 500;
	dst_segments[17].to.y = 230;

	dst_segments[18].from.x = 417;
	dst_segments[18].from.y = 235;
	dst_segments[18].to.x = 417;
	dst_segments[18].to.y = 301;

	dst_segments[19].from.x = 378;
	dst_segments[19].from.y = 319;
	dst_segments[19].to.x = 349;
	dst_segments[19].to.y = 354;

	dst_segments[20].from.x = 460;
	dst_segments[20].from.y = 311;
	dst_segments[20].to.x = 489;
	dst_segments[20].to.y = 339;

	dst_segments[21].from.x = 374;
	dst_segments[21].from.y = 364;
	dst_segments[21].to.x = 461;
	dst_segments[21].to.y = 363;

	dst_segments[22].from.x = 372;
	dst_segments[22].from.y = 370;
	dst_segments[22].to.x = 421;
	dst_segments[22].to.y = 381;

	dst_segments[23].from.x = 422;
	dst_segments[23].from.y = 381;
	dst_segments[23].to.x = 460;
	dst_segments[23].to.y = 372;

	// apply morphing
	int n_frames = 100;

	//~ unsigned long long start, end;
	//~ START_CLOCK(start);
	morph(src_image, dst_image, src_segments, dst_segments, n_segments, n_frames, writer, ASM);
	//~ STOP_CLOCK(end);
	//~ printf("TSC: %llu\n", end - start);

	cvReleaseImage(&src_image);
	cvReleaseImage(&dst_image);
	cvReleaseVideoWriter(&writer);
}
Example #20
0
static void drawframe(dynamic_stuff *generate, Gfx **glistpParam,
		      float t) {
  Gfx   *glistp;
  Vtx   *valist[2]; /* Array of vertex lists */
  float weights[2]; /* Array of weights      */
  u16   perspnorm;
  int i;
  unsigned char a2;

  glistp = *glistpParam;  /* Copy to local var */
  /*
   * Set up matricies
   */
  /* Z-distance to force for faces */
#define ZDIST (700*4)

  guPerspective(&(generate->projection), &perspnorm,
		60.0, 320.0/240.0,
		ZDIST-500.0, ZDIST+500.0, 1.0);
  gSPPerspNormalize(glistp++, perspnorm);

  /* guRotate(&(generate->modeling_rotate1), 40.0, 1.0, 1.0, 1.0); */
  guTranslate(&(generate->modeling_translate), 0.0, 0.0, 0.0);  /* -... */
  
  gSPMatrix(glistp++, OS_K0_TO_PHYSICAL(&(generate->projection)),
	    G_MTX_PROJECTION|G_MTX_LOAD|G_MTX_NOPUSH);
  gSPMatrix(glistp++, OS_K0_TO_PHYSICAL(&(generate->modeling_translate)),
	    G_MTX_MODELVIEW|G_MTX_LOAD|G_MTX_NOPUSH);
  /* gSPMatrix(glistp++, OS_K0_TO_PHYSICAL(&(generate->modeling_rotate1)),
	    G_MTX_MODELVIEW|G_MTX_MUL|G_MTX_NOPUSH); */

  /*
   * Morph
   */
  valist[0]  = vface1;
  weights[0] = t;
  valist[1]  = vface2;
  weights[1] = 1.0 - t;
  /* Two sets of key verticies, tricnt*3 verticies per set, alpha = 255 */
  /* Texture coords come from vface1 */
  morph(valist, weights, 2, &(generate->tvface1[0]), tricnt*3, 255, -ZDIST);

  /*
   * 2nd set of verticies, same except for different alpha and s,t
   */
  a2 = 255*(1.0-t); /* alpha value */
  for (i=0; i<tricnt*3; i++) {
    generate->tvface2[i] = generate->tvface1[i];
    generate->tvface2[i].v.tc[0] = vface2[i].v.tc[0] << 6;
    generate->tvface2[i].v.tc[1] = vface2[i].v.tc[1] << 6;
    generate->tvface2[i].v.cn[3] = a2;
  } /* for i */

  /* Pass 1 -- opaque */
  gSPSetGeometryMode(glistp++, G_SHADE);
  gDPPipeSync(glistp++);
  gDPSetRenderMode(glistp++, G_RM_AA_ZB_OPA_SURF, G_RM_AA_ZB_OPA_SURF2);
  gSPDisplayList(glistp++, OS_K0_TO_PHYSICAL(dlist1));

  /* Pass 2 -- transparent */
  gSPSetGeometryMode(glistp++, G_SHADE);
  gDPPipeSync(glistp++);
  gDPSetRenderMode(glistp++, G_RM_AA_XLU_SURF, G_RM_AA_XLU_SURF2);
  gSPDisplayList(glistp++, OS_K0_TO_PHYSICAL(dlist2));

  *glistpParam = glistp;  /* Copy back from local var */
} /* drawframe */
PNM* MorphologicalOperator::transform()
{  
	int size  = getParameter("size").toInt();
	SE  shape = (MorphologicalOperator::SE) getParameter("shape").toInt();

	PNM* newImage = new PNM(image->width(), image->height(), QImage::Format_RGB32);
	
	math::matrix<bool> se(size,size);
	
	se = getSE(size,shape);
	
	int radius = size/2;

	if (image->format() == QImage::Format_Mono) {
	}
	else if (image->format() == QImage::Format_Indexed8) {
		// Iterate over image space
		for (int x=0; x<image->width(); x++) {
			for (int y=0; y<image->height(); y++) {
				math::matrix<double> window(size,size);
				int a=0;
				for (int i=(x-radius);i<(x+radius+1);i++) {
					int b=0;
					for (int j=(y-radius);j<(y+radius+1);j++) {
						QRgb pixel = getPixel (i,j, RepeatEdge);
						window(a,b) = qGray(pixel);
						b++;
					}
					a++;
				}
				int v = morph(window, se);
				
				newImage->setPixel(x,y, v);
			}
		}
	}
	else { //if (image->format() == QImage::Format_RGB32)
		// Iterate over image space
		for (int x=0; x<image->width(); x++) {
			for (int y=0; y<image->height(); y++){
				math::matrix<double> windowR(size,size);
				math::matrix<double> windowG(size,size);
				math::matrix<double> windowB(size,size);
				int a=0;
				for (int i=(x-radius);i<(x+radius+1);i++) {
					int b=0;
					for (int j=(y-radius);j<(y+radius+1);j++) {
						QRgb pixel = getPixel (i,j, RepeatEdge);
						windowR(a,b) = qRed(pixel);
						windowG(a,b) = qGreen(pixel);
						windowB(a,b) = qBlue(pixel);
						b++;
					}
					a++;
				}
				int r = morph(windowR, se);
				int g = morph(windowG, se);
				int b = morph(windowB, se);
				
				QColor newPixel = QColor(r,g,b);
				newImage->setPixel(x,y, newPixel.rgb());
			}
		}
	}

    return newImage;
}