void TidyLines::quicktidy(std::map<int,Line>& lines, const QtRegion& region) { m_region = region; double avglen = 0.0; for (auto line: lines) { avglen += line.second.length(); } avglen /= lines.size(); double tolerance = avglen * 10e-6; auto iter = lines.begin(), end = lines.end(); for(; iter != end; ) { if (iter->second.length() < tolerance) { iter = lines.erase(iter); } else { ++iter; } } // now load up m_lines... initLines(lines.size(),m_region.bottom_left,m_region.top_right); for (auto line: lines) { addLine(line.second); } sortPixelLines(); // and chop duplicate lines: std::vector<int> removelist; int i = -1; for (auto line: lines) { i++; PixelRef start = pixelate(line.second.start()); auto& pixel_lines = m_pixel_lines(static_cast<size_t>(start.y), static_cast<size_t>(start.x)); for (int k: pixel_lines) { if (k > int(i) && approxeq(m_lines[i].line.start(),m_lines[k].line.start(),tolerance)) { if (approxeq(m_lines[i].line.end(),m_lines[k].line.end(),tolerance)) { removelist.push_back(line.first); break; } } } } for(int remove: removelist) { lines.erase(remove); } removelist.clear(); // always clear this list, it's reused} }
void Minitel::refreshSettings() { // Common parameters serialprint7(_currentMode); textColor(_currentTextColor); bgColor(_currentBgColor); // Only in graphic mode ? blink(_currentBlink); cursor(_currentShowCursor); // Graphic mode specific parameters if (_currentMode == GRAPHIC_MODE) { pixelate(_currentUnderline); } // Text mode specific parameters if (_currentMode == TEXT_MODE) { video(_currentVideo); charSize(_currentSize); } }
void Effects::applyEffect(const string& fx) { if(fx == "flip") { flip(true); } else if(fx == "mirror") { mirror(true); } else if(fx == "invert") { invert(true); } else if(fx == "ripple") { ripple(true, 3.5); } else if(fx == "posterize") { posterize(true); } else if(fx == "pixelate") { pixelate(true, pixelate_x, pixelate_y); } else if(fx == "wave") { wave(true, wave_speed, wave_displace, wave_num); } else if(fx == "swirl") { swirl(true, swirl_radius, swirl_angle); } else if(fx == "shake") { shake(true, shake_duration, shake_number, shake_amplitude); } else if(fx == "reflect") { reflect(true); } else if(fx == "crack") { crack(true); } else if(fx == "love") { love(true); } }
/* *Contains algorithm to turn an image into ASCII art! *Parameters: *filename: the file to write our art to. *pixAmount: the amount of pixels per character (in a square) *img: a pointer to our image in memory. * *return 0 if no errors were encountered, 1 otherwise. */ int ascii(Image* img, char* filename, int pixAmount) { // if we don't have a file in memory, say so. if(img->data == NULL) { fprintf(stderr, "Error, no file currently in memory\n"); return 1; } //first we need to pixelate pixelate(img, pixAmount); //then turn it into grayscale toGrayscale(img); //our file to write to FILE* fout= fopen(filename, "w"); // our indicator of brightness int brightness = 0; //the character we want to use to write char c = ' '; //for each "square" of our image for(int j=0; j<(img->rowNum/pixAmount); j++) { for(int i=0; i<(img->colNum/pixAmount); i++) { //our brightness value is equal to the actual brightness over 8, because we're //using 31 different characters to create our image. brightness =(int)((img->data[pixAmount*((j*img->colNum)+i)].r)/(2.34375)); //mapping brightness to character c = toASCII(brightness); //printing the character twice so we can have a square image. fprintf(fout,"%c%c",c,c); } //print a line break. fprintf(fout,"\n"); } //close our file! fclose(fout); return 0; }
int main(int argc,char *argv[]) { //Handles user input if(argc<4 || argc>5) { printf("Incorrect number of arguments\n"); printf("Number of arguments: %d\n",argc); exit(1); } //const char *inputFilename=argv[1]; const char *inputFilename=argv[1]; printf("Inputfile: %s\n",inputFilename); const char *outputFilename=argv[2]; char garbage[2]; int command; double sigma=3; if(1!=sscanf(argv[3],"%d%1s",&command,garbage) || command<0 || command>11) { printf("Incorrect command\n"); exit(1); } if(command>0 && command<11 && argc==5) { printf("Incorrect number of arguments, exclude the sigma value"); exit(1); } if(((command==0 || command==11) && argc==5 && 1!=sscanf(argv[4],"%lf%1s",&sigma,garbage)) || sigma<0) { printf("Incorrect sigma value\n"); exit(1); } Filter *filters=initializeFilters(sigma); Image *inputImage=decode(inputFilename); printf("Width: %d, height: %d\n",inputImage->width,inputImage->height); Image *outputImage=generateOutput(inputImage); uint8_t *inRed=inputImage->redChannel; uint8_t *inBlue=inputImage->blueChannel; uint8_t *inGreen=inputImage->greenChannel; uint8_t *inAlpha=inputImage->alphaChannel; uint8_t *outRed=outputImage->redChannel; uint8_t *outBlue=outputImage->blueChannel; uint8_t *outGreen=outputImage->greenChannel; uint8_t *outAlpha=outputImage->alphaChannel; int height=inputImage->height; int width=inputImage->width; switch(command) { case(0): { convolveImage(inRed,inBlue,inGreen,inAlpha,outRed,outBlue,outGreen, outAlpha,filters[0].filter,filters[0].radius,width,height); break; } case(1): { convolveImage(inRed,inBlue,inGreen,inAlpha,outRed,outBlue,outGreen, outAlpha,filters[1].filter,filters[1].radius,width,height); break; } case(2): { convolveImage(inRed,inBlue,inGreen,inAlpha,outRed,outBlue,outGreen, outAlpha,filters[2].filter,filters[2].radius,width,height); break; } case(3): { convolveImage(inRed,inBlue,inGreen,inAlpha,outRed,outBlue,outGreen, outAlpha,filters[3].filter,filters[3].radius,width,height); break; } case(4): { convolveImage(inRed,inBlue,inGreen,inAlpha,outRed,outBlue,outGreen, outAlpha,filters[4].filter,filters[4].radius,width,height); break; } case(5): { convolveImage(inRed,inBlue,inGreen,inAlpha,outRed,outBlue,outGreen, outAlpha,filters[5].filter,filters[5].radius,width,height); break; } case(6): { convolveImage(inRed,inBlue,inGreen,inAlpha,outRed,outBlue,outGreen, outAlpha,filters[6].filter,filters[6].radius,width,height); break; } case(7): { convertToGray(inRed,inBlue,inGreen,inAlpha,outRed,outBlue,outGreen, outAlpha,gMonoMult,width,height); break; } case(8): { invertImage(inRed,inBlue,inGreen,inAlpha,outRed,outBlue,outGreen, outAlpha,width,height); break; } case(9): { flipImage(inRed,inBlue,inGreen,inAlpha,outRed,outBlue,outGreen, outAlpha,width,height); break; } case(10): { pixelate(inRed,inBlue,inGreen,inAlpha,outRed,outBlue,outGreen, outAlpha,8,8,width,height); break; } case(11): { Image *invImage=generateOutput(inputImage); Image *blurImage=generateOutput(inputImage); pencilSketch(inRed,inBlue,inGreen,inAlpha,invImage->redChannel, invImage->blueChannel,invImage->greenChannel, invImage->alphaChannel,blurImage->redChannel, blurImage->blueChannel,blurImage->greenChannel, blurImage->alphaChannel,outRed,outBlue,outGreen, outAlpha,filters[0].filter,filters[0].radius,width,height, gMonoMult); //NOTE THAT I NEED TO FREE EACH OF THE CHANNEL INDIVIDUALLY //MAKE A FREE IMAGE FUNCTION freeImage(invImage); freeImage(blurImage); break; } default: exit(1); } if(command!=12) encode(outputFilename,outputImage); free((double*)filters[0].filter); free(filters); freeImage(inputImage); freeImage(outputImage); return 0; }
void Minitel::noPixelate() { pixelate(false); }
void Minitel::pixelate() { pixelate(true); }
//-------------------------------------------------------------- void ofxImageTS::draw(ofPixels pixels,int ratio ,int x, int y, int width, int height,int form){ pixelate(pixels,ratio,x,y,width,height,form); }
void ofxImageTS::pixelate(ofImage image, int pixelRatio) { ofPixels R,G,B, copy; copy.allocate(image.getWidth(), image.getHeight(), OF_PIXELS_RGB); copy = image.getPixels(); pixelate(copy,pixelRatio); }
void ofxImageTS::pixelate(ofVideoPlayer video, int pixelRatio) { ofPixels R,G,B, copy; copy.allocate(video.getWidth(), video.getHeight(), OF_PIXELS_RGB); copy = video.getPixels(); pixelate(copy,pixelRatio); }
FrameAcquirer::FrameAcquirer(SinGen *s) { this->sg = s; // create all necessary instances cvNamedWindow (WINDOW_NAME, CV_WINDOW_AUTOSIZE); CvCapture * camera = cvCreateCameraCapture (CV_CAP_ANY); CvMemStorage* storage = cvCreateMemStorage(0); assert (storage); // you do own an iSight, don't you ?!? if (! camera) abort (); if(useMotion == false){ // get an initial frame and duplicate it for later work IplImage * current_frame = cvQueryFrame (camera); IplImage * gray_image = cvCreateImage(cvSize (current_frame->width, current_frame->height), IPL_DEPTH_8U, 1); IplImage * gray_image2 = cvCreateImage(cvSize (current_frame->width, current_frame->height), IPL_DEPTH_8U, 1); assert (current_frame && gray_image); // as long as there are images ... while (current_frame = cvQueryFrame (camera)) { // convert to gray and downsize cvCvtColor (current_frame, gray_image, CV_BGR2GRAY); cvConvert( gray_image, gray_image2); float vals[NUM_WAVES]; pixelate(gray_image,vals); this->sg->setAmplitudes(vals); // just show the image cvAddWeighted( gray_image2, 0.5, gray_image, 0.5, 0.5, gray_image); cvShowImage (WINDOW_NAME, gray_image); // cvShowImage (WINDOW_NAME, current_frame); // wait a tenth of a second for keypress and window drawing int key = cvWaitKey (30); if (key == 'q' || key == 'Q') break; } }else{ IplImage * current_frame = cvQueryFrame (camera); IplImage * gray_image = cvCreateImage(cvSize (current_frame->width, current_frame->height), IPL_DEPTH_8U, 1); IplImage * avg_img = cvCreateImage(cvSize (current_frame->width, current_frame->height), IPL_DEPTH_32F, 1); IplImage * gavg_img = cvCreateImage(cvSize (current_frame->width, current_frame->height), IPL_DEPTH_8U, 1); IplImage * diff_img = cvCreateImage(cvSize (current_frame->width, current_frame->height), IPL_DEPTH_8U, 1); IplImage * diff_img2 = cvCreateImage(cvSize (current_frame->width, current_frame->height), IPL_DEPTH_8U, 1); IplImage * diff_img3 = cvCreateImage(cvSize (current_frame->width, current_frame->height), IPL_DEPTH_8U, 1); // as long as there are images ... while (current_frame = cvQueryFrame (camera)) { // convert to gray and downsize cvCvtColor (current_frame, gray_image, CV_BGR2GRAY); cvSmooth( gray_image, gray_image); cvRunningAvg( gray_image, avg_img, .250, NULL); cvConvert( avg_img, gavg_img ); cvAbsDiff( gray_image, gavg_img, diff_img ); cvConvert( diff_img, diff_img2 ); float vals[NUM_WAVES]; pixelate(diff_img,vals); this->sg->setAmplitudes(vals); if(useMotionAndLight){ pixelate(gray_image,vals); for(int i = 0; i < NUM_WAVES; i++){ vals[i] *= C8; } this->sg->setFrequencies(vals); cvAddWeighted( diff_img2, 0.5, gray_image, 0.5, 0.5, diff_img); cvShowImage ( WINDOW_NAME, diff_img); }else{ cvAddWeighted( diff_img, 0.5, diff_img2, 0.5, 0.5, diff_img); cvShowImage ( WINDOW_NAME, diff_img); } int key = cvWaitKey (30); if (key == 'q' || key == 'Q') break; } } // be nice and return no error return; }