int main() { std::clock_t timer; timer = std::clock(); Image M; try { M = imProcess(IMAGE, COLORED); } catch (too_many_chars_per_pixel e) { std::cerr << "Too many chars per pixel\n"; exit(1); } catch (not_color_format e) { std::cerr << "Included XPM not in color format\n"; exit(1); } catch (std::out_of_range e) { std::cerr << "Pixel descriptor not in hash table\n"; exit(1); } // Problem: for some reason, the online xpm file converter only retains 256 colors, // diminishing image quality for color images Image sparseImage(M); makeSparse(sparseImage.R, 0.7); if (sparseImage.color) { makeSparse(sparseImage.G, 0.7); makeSparse(sparseImage.B, 0.7); } Image naiveRepair(sparseImage); naivenn(naiveRepair.R, 16); if (naiveRepair.color) { naivenn(naiveRepair.G, 16); naivenn(naiveRepair.B, 16); } std::ofstream f1, f2, f3; f1.open("./output/original.txt"); f2.open("./output/sparse.txt"); f3.open("./output/naiveRecon.txt"); printImage(f1, M); printImage(f2, sparseImage); printImage(f3, naiveRepair); f1.close(); f2.close(); f3.close(); timer = std::clock()-timer; std::cout << "Time elapsed: " << double(timer)/CLOCKS_PER_SEC << '\n'; return 0; }
int main (void) { int init[INIT], pixel[MAX][MAX], i, j, k; Shape shape[MAX]; scanf("%d %d %d", &init[0], &init[1], &init[2]); for (i = 0; i < init[0]; i++) { scanf(" %c %d %d %d %d %d %d", &shape[i].type, &shape[i].color, &shape[i].xoff, &shape[i].yoff, &shape[i].arg1, &shape[i].arg2, &shape[i].arg3); } for (i = 0; i < init[2]; i++) { for ( j = 0; j < init[1]; j++) { pixel[i][j] = BLACK; for (k = init[0] - 1; k >= 0; k--) { if(InObject(shape[k].type, j - shape[k].xoff, i-shape[k].yoff, shape[k].arg1, shape[k].arg2, shape[k].arg3) == 1) pixel[i][j] = shape[k].color; } } } printImage(init, pixel); return 0; }
void printImage_LinearConversion(const _myfloat *imageIn, int w, int h, const char *name) { _myfloat *imTemp = xmalloc(w*h*sizeof(_myfloat)); linear_conversion(imageIn, imTemp, w * h); // imTemp values are in [0,1] printImage(imTemp, w, h, name); xfree(imTemp); }
/** * @brief MapManager::setupRobotManagerThread esegue il setup del thread su cui gira la parte di controllo del robot */ void MapManager::setupRobotManagerThread() { //Creo l'istanza del thread secondario // QThread* robotManagerThread = new QThread(this); robotManagerThread = new QThread(this); // Sposto l'oggetto che controlla il robot nell'altro thread robotManager.moveToThread(robotManagerThread); //Connetto il signal che dichiara l'inizio dell'esecuzione del thread con lo slot che si occupa dell'inizializzazione della classe QObject::connect(robotManagerThread, SIGNAL(started()), &robotManager, SLOT(init())); // Connetto i signal della classe del robot a quelli della GUI, in modo da poterli usare da QML QObject::connect(&robotManager, SIGNAL(pointFound(QVariant,QVariant)), this, SIGNAL(pointFound(QVariant,QVariant))); QObject::connect(&robotManager, SIGNAL(victimFound(QVariant)), this, SIGNAL(victimFound(QVariant))); QObject::connect(&robotManager, SIGNAL(robotTurn(QVariant)), this, SIGNAL(robotTurn(QVariant))); QObject::connect(&robotManager, SIGNAL(generateStep()), this, SIGNAL(generateStep())); // Dato che uso signal che passano paremtri Mat di opencv, devo esplori al meta system delle Qt qRegisterMetaType< cv::Mat >("cv::Mat"); // Connetto i signal che inviano immagini da mostrare ai rispettivi slot QObject::connect(&robotManager, SIGNAL(newCameraImage(cv::Mat)), this, SLOT(printImage(cv::Mat))); QObject::connect(&robotManager, SIGNAL(victimImageFound(cv::Mat)), this, SLOT(printVictimImage(cv::Mat))); // Segnalo di terminare il thread alla chiusura della GUI (anche se non sembra far nulla) QObject::connect(this, SIGNAL(destroyed()), robotManagerThread, SLOT(quit())); // Avvio il thread robotManagerThread->start(); }
void operations(int op, FILE *stream, int row, int col, int grey_scale){ int mask_dim; int **conv_image; double **mask; char *mask_file; FILE *fp; switch(op) { case 1: //Produção do negativo. negativeTransform(stream, row, col, grey_scale); break; case 2: //Filtragem Espacial. mask_file = readLine(); //Lê o nome do arquivo de máscara. fp = fopen(mask_file, "r"); if(!fp) noFile(mask_file, fp); mask = readMask(fp, &mask_dim);//Armazena o seu conteúdo. //Recebe a imagem já com a filtragem espacial conv_image = convolution(stream, mask, row, col, grey_scale, mask_dim); //Libera o conteúdo relacionado com a máscara. freeMask(mask_dim, mask, mask_file, fp); printImage(row, col, grey_scale, conv_image); break; default: //Caso não seja digitado nenhum operador esperado printf("Unknown Operator.\n"); break; } }
void printImage_LinearConversion(double *imageIn, int w, int h, char *name){ double *imTemp = (double*)malloc(w*h*sizeof(double)); linear_conversion(imageIn, imTemp, w * h); //capped_linear_conversion(imageIn, imTemp, w * h, 0.00000001); linear_conversion(imageIn, imTemp, w * h); printImage(imTemp, w, h, name); free(imTemp); }
PPMImage PPMImage::apply_kernels(std::vector<PixelGrid<MonoPixel>> kernels){ PPMImage output = *this; for (int k = 0; k < kernels.size(); k++){ std::cout << "convolving with " << std::endl; printImage("K", kernels[k]); output = output.convolve(kernels[k]); } return output; }
void OPStructureImaging::ticker() { if (imageCount != 0) { --imageCount; printImage(); } }
void FaceDetectApp::refreshFrame() { cv::Mat singleFrame; capture >> singleFrame; if(oldFrame.empty()) { singleFrame.copyTo(oldFrame); } singleFrame.size; cv::Mat tmpI; cv::Size size(desktop->width() / 3 - 25, desktop->height() / 2 - 50); cv::resize(singleFrame, tmpI, size, 0, 0, cv::INTER_CUBIC); tmpI.copyTo(singleFrame); singleFrame.copyTo(currentFrame); MyQtGui* temp = resultPrinter.find(WEBCAM_RAW_WINDOW_TITLE)->second; /** std::vector<> zone_list;// = new std::vector<cv::Point>(); for (int i = 0 ; i < temp->getZoneList().size(); i++) { InterestZone t = temp->getZoneList()[i]; std::vector<cv::Point> point_list; point_list.push_back(t.p1); point_list.push_back(t.p2); zone_list.push_back(point_list); }*/ std::vector<InterestZone> tmp = temp->getZoneList(); if (!singleFrame.empty()) { //buildMenu(singleFrame); printImage(WEBCAM_DETECT_WINDOW, faceRecognizer.detect(singleFrame, list_inter_zone)); printImage(WEBCAM_COLOR_WINDOW, colorDetector.detect(singleFrame, list_inter_zone)); printImage(WEBCAM_CONTOUR_WINDOW, contourDetector.detect(singleFrame, list_inter_zone)); printImage(WEBCAM_MVT_WINDOW, mvt_detect.start(singleFrame, oldFrame, tmp)); printImage(WEBCAM_RAW_WINDOW_TITLE, gui.print(singleFrame,tmp, myServer)); } else { qDebug() << "The frame is empty!"; } singleFrame.copyTo(oldFrame); }
int main(int argc, char const *argv[]){ if(argc != 3){ cout << "Parameters should be: (i: input file), (o: output file)" << endl; return 0; } ifstream input(argv[1]); string inFileDir, line; int alpha; input >> inFileDir >> alpha; getline(input, line); getline(input, line); stringstream lineStream(line); DigitImages imagesTrain, imagesTest; Matrix eigenVectors(alpha, vector<double>(DEFAULT_IMAGE_SIZE)); vector<double> eigenValues(alpha); int niter = 1000; populateDigitImages(imagesTrain, imagesTest, inFileDir, lineStream); imagesTrain.getMeans(); imagesTrain.calculateCentralized(); // imagesTrain.calculateCovariances(); imagesTest.calculateCentralizedTest(imagesTrain.means, (int)imagesTrain.images.size()); // PCA(imagesTrain.covariances, eigenVectors, eigenValues, alpha, niter); PLSDA(imagesTrain, eigenVectors, eigenValues, alpha, niter); vector<double> aux(DEFAULT_IMAGE_SIZE); for (int k = 0; k < eigenVectors.size(); ++k){ ofstream output(argv[2] + to_string(k)); double max = eigenVectors[k][0], min = eigenVectors[k][0]; for (int i = 1; i < DEFAULT_IMAGE_SIZE; ++i){ if(eigenVectors[k][i] > max) max = eigenVectors[k][i]; else if(eigenVectors[k][i] < min) min = eigenVectors[k][i]; } for (int i = 0; i < DEFAULT_IMAGE_SIZE; ++i){ aux[i] = eigenVectors[k][i] - min; aux[i] *= 255; aux[i] /= (max - min); } printImage(aux, output); output.close(); } input.close(); return 0; }
static void printImageDifferences(Evas_Object* baselineImage, Evas_Object* actualImage) { RefPtr<Evas_Object> differenceImage; const float difference = calculateDifference(baselineImage, actualImage, differenceImage); if (difference > 0.0f) { if (differenceImage) printImage(differenceImage.get()); printf("diff: %01.2f%% failed\n", difference); } else printf("diff: %01.2f%% passed\n", difference); }
void GUIgestion::refresh() { cvReleaseImage(&displayedImage); displayedImage = cvCreateImage(cvSize(x, y), 8, 3 ); createBlankImage(displayedImage); for(int i =0; i<items.size(); i++) { GUIitem* it = items[i]; // cout << "Image en " <<it->posX <<", "<<it->posY<< endl; if(it->visible) printImage(displayedImage, it->im, (int)items[i]->posY, (int)items[i]->posX); } cvShowImage(name.c_str(), displayedImage); cvSetMouseCallback(name.c_str(),Wrapper_To_Mouse_Call,this); cvWaitKey(33); }
void print_sift_scalespace_gray(const struct sift_scalespace* scalespace, const char* basename) { char name[FILENAME_MAX]; int nOct = scalespace->nOct; for(int o = 0; o < nOct; o++){ const struct octa* octave = scalespace->octaves[o]; int nSca = octave->nSca; int w = octave->w; int h = octave->h; for(int s = 0; s < nSca; s++){ const _myfloat* image = &octave->imStack[s*w*h]; sprintf(name,"%s_o%03i_s%03i.png",basename,o,s); printImage(image, w,h, name); } } }
int main(int argc, char **argv) { printf("\n"); printf("Welcome to Rasterizer 3000.\n"); printf("===========================\n\n"); Config config; int rows, //9175, cols, //6814, i, j; calcImageSize(&config, &rows, &cols); Index index; index.nodes = malloc(rows*cols*sizeof(PointNode *)); index.config = &config; index.rows = rows; index.cols = cols; Image image; image.pixels = malloc(rows*cols*sizeof(float)); image.rows = rows; image.cols = cols; image.config = &config; // Initialize arrays for (j=0; j<rows; j++) { for (i=0; i<cols; i++) { *(index.nodes+(j*cols)+i) = 0; *(image.pixels+(j*cols)+i) = EMPTY_VAL; } } // data readPointsFromFile("sample.txt", &index); printIndexBins(&index); rasterize(&index, &image); printImage(&image); free(image.pixels); free(index.nodes); return 0; }
static void printCell(htmlcell_t * cp, int ind) { indent(ind); fprintf(stderr, "cell %d %d %d %d ", cp->cspan, cp->rspan, cp->col, cp->row); printData(&cp->data); fputs("\n", stderr); switch (cp->child.kind) { case HTML_TBL: printTbl(cp->child.u.tbl, ind + 1); break; case HTML_TEXT: printTxt(cp->child.u.txt, ind + 1); break; case HTML_IMAGE: printImage(cp->child.u.img, ind + 1); break; default: break; } }
void print_sift_scalespace_gray_nearestneighbor(const struct sift_scalespace* scalespace, const char* basename) { char name[FILENAME_MAX]; int wALL = scalespace->octaves[0]->w; int hALL = scalespace->octaves[0]->h; _myfloat* imtemp = xmalloc(wALL*hALL*sizeof(_myfloat)); int nOct = scalespace->nOct; for(int o = 0; o < nOct; o++){ const struct octa* octave = scalespace->octaves[o]; int nSca = octave->nSca; int w = octave->w; int h = octave->h; for(int s=0;s<nSca;s++){ const _myfloat* image = &octave->imStack[s*w*h]; nearestneighbor_interp(image,w,h, imtemp,wALL,hALL); sprintf(name,"%s_o%03i_s%03i.png",basename,o,s); printImage(imtemp, wALL,hALL, name); } } xfree(imtemp); }
//! [0] MainWindow::MainWindow() { //! [0] currentPath = QDir::homePath(); model = new ImageModel(this); QWidget *centralWidget = new QWidget; //! [1] view = new QTableView; view->setShowGrid(false); view->horizontalHeader()->hide(); view->verticalHeader()->hide(); view->horizontalHeader()->setMinimumSectionSize(1); view->verticalHeader()->setMinimumSectionSize(1); view->setModel(model); //! [1] //! [2] PixelDelegate *delegate = new PixelDelegate(this); view->setItemDelegate(delegate); //! [2] //! [3] QLabel *pixelSizeLabel = new QLabel(tr("Pixel size:")); QSpinBox *pixelSizeSpinBox = new QSpinBox; pixelSizeSpinBox->setMinimum(4); pixelSizeSpinBox->setMaximum(32); pixelSizeSpinBox->setValue(12); //! [3] QMenu *fileMenu = new QMenu(tr("&File"), this); QAction *openAction = fileMenu->addAction(tr("&Open...")); openAction->setShortcuts(QKeySequence::Open); printAction = fileMenu->addAction(tr("&Print...")); printAction->setEnabled(false); printAction->setShortcut(QKeySequence::Print); QAction *quitAction = fileMenu->addAction(tr("E&xit")); quitAction->setShortcuts(QKeySequence::Quit); QMenu *helpMenu = new QMenu(tr("&Help"), this); QAction *aboutAction = helpMenu->addAction(tr("&About")); menuBar()->addMenu(fileMenu); menuBar()->addSeparator(); menuBar()->addMenu(helpMenu); connect(openAction, SIGNAL(triggered()), this, SLOT(chooseImage())); connect(printAction, SIGNAL(triggered()), this, SLOT(printImage())); connect(quitAction, SIGNAL(triggered()), qApp, SLOT(quit())); connect(aboutAction, SIGNAL(triggered()), this, SLOT(showAboutBox())); //! [4] connect(pixelSizeSpinBox, SIGNAL(valueChanged(int)), delegate, SLOT(setPixelSize(int))); connect(pixelSizeSpinBox, SIGNAL(valueChanged(int)), this, SLOT(updateView())); //! [4] QHBoxLayout *controlsLayout = new QHBoxLayout; controlsLayout->addWidget(pixelSizeLabel); controlsLayout->addWidget(pixelSizeSpinBox); controlsLayout->addStretch(1); QVBoxLayout *mainLayout = new QVBoxLayout; mainLayout->addWidget(view); mainLayout->addLayout(controlsLayout); centralWidget->setLayout(mainLayout); setCentralWidget(centralWidget); setWindowTitle(tr("Pixelator")); resize(640, 480); //! [5] }
void ofxCUPS::printImage(string filename) { printImage(filename,false); }
// Main Linux program entry point int main(int argc, char *argv[]) { int opt; bool testFlag = false; bool paperFeedFlag = false; uint32_t paperFeedCount = 0; bool startLineFlag = false; uint32_t startLine = 0; bool endLineFlag = false; uint32_t endLine = 0; bool inverseFlag = false; bool waitFlag = false; // Parse the command line options and issue a simple help text in case // things don't match up. The columns behind the options denote that option // requires an argument. See getopt(3) for more info. while ((opt = getopt(argc, argv, "tf:s:e:iw")) != -1) { switch (opt) { case 't': testFlag = true; break; case 'f': paperFeedCount = atoi(optarg); paperFeedFlag = true; break; case 's': startLine = atoi(optarg); startLineFlag = true; break; case 'e': endLine = atoi(optarg); endLineFlag = true; break; case 'i': inverseFlag = true; break; case 'w': waitFlag = true; break; default: // getopt() will return '?' in case of a malformed command line in // which case we are printing the usage and exit the command. fprintf(stderr, USAGE_STRING, argv[0], argv[0], argv[0]); return EXIT_FAILURE; } } // Initialize the PRU and exit the program if that fails. Any errors that // may occur during that process will be output from within that function. if (!initPru()) { return EXIT_FAILURE; } // See if the test mode has been activated. If that's the case we will just // enter test mode right away. if (testFlag) { // Create a very simple print job that activates the test pattern // generation. Since this sub-function doesn't return within the PRU // firmware we don't need to bother trying to issue a halt command. initQueueJobItems(); addJobItemToQueue(PRINTER_CMD_TEST_SIGNALS, 0, NULL); addJobItemToQueue(PRINTER_CMD_EOS, 0, NULL); // The interrupt is mapped via INTC to channel 1 printf("Starting PRU GPIO test pattern generation\n"); prussdrv_pru_send_event(ARM_PRU1_INTERRUPT); } // See if the paper feed flag has been set AND no image filename was given. // Unlike other print-related flags we want to allow the user to feed paper // without needing to specify an image to print. else if (paperFeedFlag && (optind >= argc)) { // Go ahead and create a very simple print job that simply feeds the // paper by the specified number of steps. Any other print-related // command line option will be ignored. initQueueJobItems(); addJobItemToQueue(PRINTER_CMD_OPEN, 0, NULL); addJobItemToQueue(PRINTER_CMD_MOTOR_HALF_STEP, sizeof(uint32_t), (const uint8_t *)&paperFeedCount); addJobItemToQueue(PRINTER_CMD_CLOSE, 0, NULL); addJobItemToQueue(PRINTER_CMD_REQUEST_PRU_HALT, 0, NULL); addJobItemToQueue(PRINTER_CMD_EOS, 0, NULL); // The interrupt is mapped via INTC to channel 1 printf("Start feeding paper\n"); prussdrv_pru_send_event(ARM_PRU1_INTERRUPT); // Wait until PRU1 has finished execution and acknowledge the interrupt. // The INTC config maps PRU1_ARM_INTERRUPT to EVTOUT_1. printf("Waiting for paper feed completion...\n"); measureDurationPrintToConsole(true); prussdrv_pru_wait_event(PRU_EVTOUT_1); measureDurationPrintToConsole(false); prussdrv_pru_clear_event(PRU_EVTOUT_1, PRU1_ARM_INTERRUPT); // See if any errors occurred and output them to the console if any checkForPrinterErrorsPrintToConsole(); } // See if we are in the normal printer operating mode which means the user // has provided an image filename parameter. else if (optind < argc) { // Let's go ahead and print the image considering any of the other // command line flags that may have been set. const char *imageFile = argv[optind]; printf("Loading image %s\n", imageFile); if (!readPngImage(imageFile)) { return EXIT_FAILURE; } // Check if a start line was given and use it if it is a valid // parameter. Otherwise use the first line of the image. if (startLineFlag) { if ((startLine < 0) || (startLine >= pngImageHeight)) { fprintf(stderr, "Invalid start line!\n"); return EXIT_FAILURE; } } else { startLine = 0; } // Check if an end line was given and use it if it is a valid // parameter. Otherwise use the last line of the image. if (endLineFlag) { if ((endLine < 0) || (endLine >= pngImageHeight)) { fprintf(stderr, "Invalid end line!\n"); return EXIT_FAILURE; } } else { endLine = pngImageHeight - 1; } // Make sure the parameters actually make sense if (startLine > endLine) { fprintf(stderr, "The start line must not be larger than the end" \ " line!\n"); return EXIT_FAILURE; } // Check the width of the image. If it's too wide we'll continue with // printing anyways. We just won't output the full line. if (pngImageWidth > PRINTER_DOTS_PER_LINE) { printf("Image width exceeds the maximum number of dots allowed" \ " per line! Will only be printing the first %u pixels...", PRINTER_DOTS_PER_LINE); } printf("Processing image, transferring into PRU shared memory, and " \ "starting print job\n"); printImage(startLine, endLine, inverseFlag, paperFeedCount); // Free the PNG image from memory. It's no longer needed-- all relevant // data was transferred into the PRU shared memory. deallocPngImage(); // See if any errors occurred and output them to the console if any checkForPrinterErrorsPrintToConsole(); } // Looks like no command line parameters or an invalid combination thereof // was encountered... else { // Print the usage info to the console and exit with error fprintf(stderr, USAGE_STRING, argv[0], argv[0], argv[0]); return EXIT_FAILURE; } if (waitFlag) { printf("Press ENTER to disable the PRU and end the program...\n"); getchar(); } disablePru(); return EXIT_SUCCESS; }
// Main function int main( void ) { char command[MAXLENGTH]; char c; /******************************************************************** * YOU WILL NEED TO COMPLETE THE FOLLOWING SECTION FOR STAGES 2 - 5 * *******************************************************************/ printPrompt(); while( fgets( command, MAXLENGTH, stdin ) != NULL ) { int imgNum; char *p; if(( p=strrchr( command, '\n')) != NULL ) { *p = '\0'; // remove '\n' at end of line } // find the first non-space character in the command p = command; while(isspace(*p)) { p++; } c = tolower(*p); if( isdigit(c)) // Command k { if( sscanf( command, "%d", &imgNum ) == 1 ) { //Checks to see if there's images in the album. if(first != NULL) { //Retrieves the image. found = getCurrentImage(first); found2 = selectImage(found, imgNum); //Checks to see if the requested image exist in the album. if(found2 != NULL) { found->current = FALSE; found2->current = TRUE; printNodeInfos(found2); last_action = 'k'; location = found->index; //Index of the previous image found = NULL; found2 = NULL; } } } } else switch( c ) { case 'h': // help printf(" A - Add image\n" ); printf(" I - Index\n" ); printf(" P - Print image\n" ); printf(" F - Forward\n" ); printf(" B - Back\n" ); printf("<k>- make image number k the current image\n"); printf(" D - Delete image\n" ); printf(" L - Look for image\n" ); printf(" R - Rotate image counterclockwise\n" ); printf(" M - Mirror image (reflect vertically)\n" ); printf("NE - zoom into North East corner\n" ); printf("NW - zoom into North West corner\n" ); printf("SW - zoom into South West corner\n" ); printf("SE - zoom into South East corner\n" ); printf(" O - zoom Out\n" ); printf(" U - Undo\n" ); printf(" H - Help\n" ); printf(" Q - Quit\n" ); break; // INSERT CODE FOR OTHER COMMANDS case 'a': p++; //Moves cursor away from 'a' while(isspace(*p)) { p++; } int *dim; QTnode* qt = getImage(p, dim); if(qt != NULL) { insertNode(qt, dim, p); printNodeInfos(getCurrentImage(first)); //Whenever a node is added, it becomes the selected node } last_action = 'a'; break; case 'i': if(first != NULL) { printIndex(first); } break; case 'p': { ListNode* currentImage = getCurrentImage(first); if(currentImage != NULL) { printImage(currentImage->image, currentImage->size); } break; } case 'f': { ListNode* currentImage = getCurrentImage(first); if(currentImage != NULL && (currentImage->next != NULL)) { currentImage->current = FALSE; currentImage = currentImage->next; currentImage->current = TRUE; printNodeInfos(currentImage); last_action = 'f'; } break; } case 'b': { ListNode* currentImage = getCurrentImage(first); if(currentImage != NULL && (currentImage->previous != NULL)) { currentImage->current = FALSE; currentImage = currentImage->previous; currentImage->current = TRUE; printNodeInfos(currentImage); last_action = 'b'; } break; } //'K' command is treated in the upper portion of the code case 'd': removeNode(); if(first != NULL) { printNodeInfos(getCurrentImage(first)); } last_action = 'd'; break; case 'l': if(first != NULL) { p++; //Moves cursor away from 'a' while(isspace(*p)) { p++; } ListNode* foundImage = findBySubString(first, p); //Image with the substring was found if(foundImage != NULL) { ListNode* currentImage = getCurrentImage(first); currentImage->current = FALSE; foundImage->current = TRUE; printNodeInfos(getCurrentImage(first)); last_action = 'l'; location = currentImage->index; } } break; case 'r': { ListNode* currentImage = getCurrentImage(first); if(currentImage != NULL) { rotateImage(currentImage->image); printImage(currentImage->image, currentImage->size); } last_action = 'r'; break; } case 'm': { ListNode* currentImage = getCurrentImage(first); if(currentImage != NULL) { mirrorImage(currentImage->image); printImage(currentImage->image, currentImage->size); } last_action = 'm'; break; } case 'n': { ListNode* currentImage = getCurrentImage(first); if(currentImage == NULL) { break; } //This line gets the next character of the command, so it can be //treated accordingly. char c2 = *(++p); //Dereferencing the pointer and moving it to the next char of the string if(c2 == 'e') { if(currentImage->image->ne == NULL) { break; } currentImage->image = currentImage->image->ne; printImage(currentImage->image, currentImage->size); last_action = 'w'; //because "ne" does not work, find a letter that is not used location = 'w'; } else if(c2 == 'w') { if(currentImage->image->nw == NULL) { break; } currentImage->image = currentImage->image->nw; printImage(currentImage->image, currentImage->size); last_action = 'x'; location = 'x'; } break; } case 's': { ListNode* currentImage = getCurrentImage(first); if(currentImage == NULL) { break; } //This line gets the next character of the command, so it can be //treated accordingly. char c2 = *(++p); //Dereferencing the pointer and moving it to the next char of the string if(c2 == 'e') { if(currentImage->image->se == NULL) { break; } currentImage->image = currentImage->image->se; printImage(currentImage->image, currentImage->size); last_action = 'y'; location = 'y'; } else if(c2 == 'w') { if(currentImage->image->sw == NULL) { break; } currentImage->image = currentImage->image->sw; printImage(currentImage->image, currentImage->size); last_action = 'z'; location = 'z'; } break; } case 'o': { ListNode* currentImage = getCurrentImage(first); if(currentImage == NULL || (currentImage->image->out == NULL)) { break; } currentImage->image = currentImage->image->out; printImage(currentImage->image, currentImage->size); last_action = 'o'; break; } case 'u': if(last_action == 'm'){ ListNode* currentImage = getCurrentImage(first); if(currentImage != NULL) { mirrorImage(currentImage->image); printImage(currentImage->image, currentImage->size); } break; } else if(last_action == 'r'){ ListNode* currentImage = getCurrentImage(first); if(currentImage != NULL) { rotateImage(currentImage->image); rotateImage(currentImage->image); rotateImage(currentImage->image); printImage(currentImage->image, currentImage->size); break; } } else if(last_action == 'a'){ removeNode(); if(first != NULL) { printNodeInfos(getCurrentImage(first)); } break; } else if(last_action == 'd'){ //todo me no smart break; } else if(last_action == 'w' || (last_action == 'x') || (last_action == 'y') || (last_action == 'z')){ ListNode* currentImage = getCurrentImage(first); if(currentImage == NULL || (currentImage->image->out == NULL)) { break; } currentImage->image = currentImage->image->out; printImage(currentImage->image, currentImage->size); break; } else if(last_action == 'o'){ ListNode* currentImage = getCurrentImage(first); if(location == 'w') { if(currentImage->image->ne == NULL) { break; } currentImage->image = currentImage->image->ne; printImage(currentImage->image, currentImage->size); break; } else if(location == 'x') { if(currentImage->image->nw == NULL) { break; } currentImage->image = currentImage->image->nw; printImage(currentImage->image, currentImage->size); break; } else if(location == 'y') { if(currentImage->image->se == NULL) { break; } currentImage->image = currentImage->image->se; printImage(currentImage->image, currentImage->size); break; } else if(location == 'z') { if(currentImage->image->sw == NULL) { break; } currentImage->image = currentImage->image->sw; printImage(currentImage->image, currentImage->size); break; } } else if(last_action == 'b'){ ListNode* currentImage = getCurrentImage(first); if(currentImage != NULL && (currentImage->next != NULL)) { currentImage->current = FALSE; currentImage = currentImage->next; currentImage->current = TRUE; printNodeInfos(currentImage); } break; } else if(last_action == 'f'){ ListNode* currentImage = getCurrentImage(first); if(currentImage != NULL && (currentImage->previous != NULL)) { currentImage->current = FALSE; currentImage = currentImage->previous; currentImage->current = TRUE; printNodeInfos(currentImage); } break; } else if(last_action == 'k' || (last_action == 'l')){ //Retrieves the image. found = getCurrentImage(first); found2 = selectImage(found, location); //Checks to see if the requested image exist in the album. if(found2 != NULL) { found->current = FALSE; found2->current = TRUE; printNodeInfos(found2); found = NULL; found2 = NULL; } break; } case 'q': // quit program printf("Bye!\n"); return 0; break; default: printf("Unrecognized command: %s\n", command ); break; } printPrompt(); } return 0; }
void back_to_first_screen(void) { init_screen(); printImage(logo_final_dark,0,0,128,128); writeCommand(SSD1351_CMD_DISPLAYON); }
int do_pipes(int numProcesses, int level, int childNum, int** A, int color, int turn_pipe[2], int confirm_pipe[2]) { // child processes for pipe implementation // see report for pseudocode algorithm and reasoning // as this is a full binary tree, there are 2^level children int totalChildren = 1 << level; if (numProcesses <= totalChildren) { // compute filter int xStart = childNum * X / numProcesses; // start row int xEnd = (childNum + 1) * (X - 1) / numProcesses; // end row // run filter on just these rows colorFilter(A, xStart, xEnd, 0, Y-1, color); // rows // now this process waits until its turn to print is sent via turn_pipe int current_turn, confirm_message; while(1){ // loop indefinitely until its turn is over read(turn_pipe[0], ¤t_turn, sizeof(current_turn)); if (current_turn == childNum){ // it is this child's turn to print printf("Doing process %0.2d of %d.\n", childNum, numProcesses-1); printImage(A, xStart, xEnd, 0, Y-1); // send confirmation message to tell parent that it's done printing confirm_message = current_turn; write(confirm_pipe[1], &confirm_message, sizeof(confirm_message)); // now stop waiting to process/print as we are done break; } // write back turn for the next process to read write(turn_pipe[1], ¤t_turn, sizeof(current_turn)); } } else { // have not forked enough to create the necessary number of children // in our binary tree, so fork this process and recurse pid_t this_pid; int result; switch (this_pid = fork()) { case -1: perror("fork() failure"); exit(-1); break; case 0: // this is the child do_pipes(numProcesses, level + 1, childNum * 2, A, color, turn_pipe, confirm_pipe); break; default: // parent do_pipes(numProcesses, level + 1, childNum * 2 + 1, A, color, turn_pipe, confirm_pipe); break; } } wait(NULL); // reliquish control until all children have printed and have died return 0; }
void ShowFoto::slotFilePrint() { printImage(d->thumbBar->currentUrl()); }