void FillTool::fillLine(int x, int y) { if ((x >= 0) && (x < m_image.width()) && (y >= 0) && (y < m_image.height())) { if (m_image.pixel(x, y) == m_oldRgb) { int x1, x2; x1 = x - 1; x2 = x + 1; while ((x1 >= 0) && (m_image.pixel(x1, y) == m_oldRgb)) { x1--; } while ((x2 < m_image.width()) && (m_image.pixel(x2, y) == m_oldRgb)) { x2++; } for (int i = x1 + 1; i < x2; i++) { m_image.setPixel(i, y, m_fillRgb); } for (int i = x1 + 1; i < x2; i++) { fillLine(i, y - 1); } for (int i = x1 + 1; i < x2; i++) { fillLine(i, y + 1); } } } }
void process() const { MedianWindow window(m_radius); /* prefill all lines except last */ for (int y = -m_radius; y < m_radius; ++y) fillLine(m_start.y() + y, window); int x = m_start.x(); int y = m_start.y(); for (int i = 0; i < m_height; ++i, ++y) { fillLine(y + m_radius, window); m_image.setPixel(x, y, setGray(m_orig.pixel(x, y), window.median())); } }
vector<string> fullJustify(vector<string> &words, int L) { int len = 0; vector<string> line; vector<string> result; for (int i = 0; i < words.size(); i++) { int wLen = words[i].length(); if (len + wLen > L) { result.push_back(fillLine(line, L, false)); line.clear(); len = 0; } line.push_back(words[i]); len += wLen + 1; } result.push_back(fillLine(line, L, true)); return result; }
void Tabuleiro::buildTabuleiro(string txt) { ifstream fiel; fiel.open(txt.c_str()); assert (fiel.is_open()); vector<Celula>* curVector; string curline; for (int i = 0; i < SIDELENGTH; ++i) //tabuleiro size == 15*15, SELECIONA vector { curVector = &TabuleiroCelulas[i]; getline(fiel, curline); fillLine(curVector, curline); } }
QPolygonF TupGraphicalAlgorithm::polygonFit(const QPolygonF &points) { QPolygonF lines; for (int i = 0; i < points.count(); i+=2) { if (i+1 >= points.count()) { lines << points[i]; break; } QPointF first = points[i]; QPointF second = points[i+1]; lines << fillLine(first, second); } return lines; }
void displayStatus(char status) { setPosition(0,0); sendLiteralBytes("stat:"); sendBinPad(status); fillLine(); if (runFlag == 0) { setPosition(0,15); sendLiteralBytes("_"); } runFlag = !runFlag; setPosition(1,0); if (status & 0b1000000) sendLiteralBytes("DR "); if (status & 0b100000) sendLiteralBytes("DS "); if (status & 0b10000) sendLiteralBytes("RT "); if (status & 0b1) sendLiteralBytes("TXF "); fill(); }
void FillTool::mousePressEvent(QMouseEvent* e) { int x = e->x(); int y = e->y(); m_image = m_pDrawPadCanvas->currentPage()->pixmap()->convertToImage(); if (m_image.depth() <= 8) { m_image = m_image.convertDepth(32); } m_fillRgb = m_pDrawPad->brush().color().rgb(); m_oldRgb = m_image.pixel(x, y); if (m_oldRgb != m_fillRgb) { m_pDrawPadCanvas->backupPage(); if (m_pDrawPad->antiAliasing()) { m_mask.create(m_image.width(), m_image.height(), 8, 2); m_mask.fill(0); fillMaskLine(x, y); for (int i = 0; i < m_image.width(); i++) { for (int j = 0; j < m_image.height(); j++) { if (m_mask.pixelIndex(i, j) == 1) { setInterpolatedPixel(i, j); } } } } else { fillLine(x, y); } m_pDrawPadCanvas->currentPage()->pixmap()->convertFromImage(m_image); m_pDrawPadCanvas->viewport()->update(); } }
int cmd_listProcs(tok_t arg[]) { process *curr = first_process; int i = 0; int printed = 0; int k; //Printing process structure while (curr->next != NULL) { fprintf(stdout, "|----------------------------------------------------------|\n"); if ( (curr->next->completed == 'Y') || (curr->next->stopped == 'Y') ) {fprintf(stdout, "|Process number %2d (Inactive) |\n", i);} else {fprintf(stdout, "|Process number %2d (Active) |\n", i);} fprintf(stdout, "|------------------+---------------------------------------|\n"); fprintf(stdout, "|PID: | %d%n", curr->next->pid, &printed); fillLine( (MAX_TABLE_WIDTH-printed)-1 ); /* --FOR PRINTING FILE DESCRIPTORS:-- fprintf(stdout, "|Stdin: | %d%n", curr->next->stdin, &printed); fillLine( (MAX_TABLE_WIDTH-printed)-1 ); fprintf(stdout, "|Stdout: | %d%n", curr->next->stdout, &printed); fillLine( (MAX_TABLE_WIDTH-printed)-1 ); fprintf(stdout, "|Stderr: | %d%n", curr->next->stderr, &printed); fillLine( (MAX_TABLE_WIDTH-printed)-1 ); */ fprintf(stdout, "|Completed: | %c%n", curr->next->completed, &printed); fillLine( (MAX_TABLE_WIDTH-printed)-1 ); fprintf(stdout, "|Stopped: | %c%n", curr->next->stopped, &printed); fillLine( (MAX_TABLE_WIDTH-printed)-1 ); fprintf(stdout, "|Background: | %c%n", curr->next->background, &printed); fillLine( (MAX_TABLE_WIDTH-printed)-1 ); fprintf(stdout, "|Arguments: | %d%n", curr->next->argc, &printed); fillLine( (MAX_TABLE_WIDTH-printed)-1 ); for (k = 0; k < curr->next->argc; k++) { fprintf(stdout, "|Arg number [%d]: | %s%n", k, curr->next->argv[k], &printed); fillLine( (MAX_TABLE_WIDTH-printed) - 1); } fprintf(stdout, "|------------------+---------------------------------------|\n\n"); curr = curr->next; i++; } return 1; }
void MESI_SMPCache::writeLine(uint32_t wrPC, uint32_t addr){ /*This method implements actions taken when instruction wrPC *writes to memory location addr*/ /*Find the line to which this address maps*/ MESI_SMPCacheState * st = (MESI_SMPCacheState *)cache->findLine(addr); /* *If the tags didn't match, or the line was invalid, it is a *write miss */ if(!st || (st && !(st->isValid())) ){ numWriteMisses++; if(st){ /*We're writing to an invalid line*/ numWriteOnInvalidMisses++; } /* * Let the other caches snoop this write access and update their * state accordingly. This action is effectively putting the write * on the bus. */ MESI_SMPCache::InvalidateReply inv_ack = writeRemoteAction(addr); numInvalidatesSent++; /*Fill the line with the new written block*/ fillLine(addr,MESI_MODIFIED); return; }else if(st->getState() == MESI_SHARED || st->getState() == MESI_EXCLUSIVE){ /* If the block is shared and we're writing, still count it as a cache hit, * but we need to invalidate all of the sharers' copies and upgrade to Modified * in order to write. */ numWriteHits++; if (st->getState() == MESI_SHARED){ /*Write-on-shared Coherence Misses*/ numWriteOnSharedMisses++; /*Let the other sharers snoop this write, and invalidate themselves*/ MESI_SMPCache::InvalidateReply inv_ack = writeRemoteAction(addr); numInvalidatesSent++; } /*Change the state of the line to Modified to reflect the write*/ st->changeStateTo(MESI_MODIFIED); return; }else{ //Write Hit /*Already have it writable: No coherence action required!*/ numWriteHits++; return; } }
void MESI_SMPCache::readLine(uint32_t rdPC, uint32_t addr){ /* *This method implements actions taken on a read access to address addr *at instruction rdPC */ /*Get the state of the line to which this address maps*/ MESI_SMPCacheState *st = (MESI_SMPCacheState *)cache->findLine(addr); /*Read Miss - tags didn't match, or line is invalid*/ if(!st || (st && !(st->isValid())) ){ /*Update event counter for read misses*/ numReadMisses++; if(st){ /*Tag matched, but state was invalid*/ numReadOnInvalidMisses++; } /*Make the other caches snoop this access *and get a remote read service object describing what happened. *This is effectively putting the access on the bus. */ MESI_SMPCache::RemoteReadService rrs = readRemoteAction(addr); numReadRequestsSent++; if(rrs.providedData){ /*If it was shared or modified elsewhere, *the line was provided by another cache. *Update these counters to reflect that */ numReadMissesServicedByOthers++; if(rrs.isShared){ numReadMissesServicedByShared++; }else if (!rrs.isExclusive){ numReadMissesServicedByModified++; } /*Fill the line*/ fillLine(addr,MESI_SHARED); } else { /* we directly got the data from memory since another cache didn't give it to us. this is exclusively ours */ //numReadMissesServicedByOthers++; fillLine(addr,MESI_EXCLUSIVE); } }else{ /*Read Hit - any state but Invalid*/ numReadHits++; return; } }
//****************** //****************** uint8_t vobSubRead(char *filename,int index,VobSubInfo **info) { FILE *file=NULL; uint32_t nb_lines; VobSubInfo *sub=NULL; uint8_t success=0; uint32_t line=0,l; char str[1024]; char *dup; int language=0; if(!filename) { printf("Null file ?\n"); return 0; } *info=NULL; file=fopen(filename,"rt"); if(!file) { printf("Could not open %s file\n",filename); return 0; } nb_lines=countLine(file,index); if(!nb_lines) { printf("Empty file\n"); goto subAbort; } // Try to read the file sub=new VobSubInfo; memset(sub,0,sizeof(VobSubInfo)); // sub->nbLines=nb_lines; sub->lines=new vobSubLine[nb_lines]; memset(sub->lines,0,sizeof(vobSubLine)*nb_lines); printf("Rebuilding %d lines of subs\n",nb_lines); while(line<nb_lines && !feof(file)) { fgets(str,1023,file); if(!strncmp(str,"palette:",7)) { fillPalette(str,sub); sub->hasPalette=1; } else { if(!strncmp(str,"timestamp: ",10) && language) { fillLine(str,sub,line); line++; } else { if(!strncmp(str,"id:",3)) // Catch language/index { int l; char s[50]; s[0]=0; l=999; sscanf(str,"id: %s index: %d",s,&l); printf("Found lang : %s index %d while searching %d\n",s,l,index); if(l==index) { language=1; printf("Match\n"); } else language=0; } else { if(!strncmp(str,"size:",5)) // Catch original screen dimension { sscanf(str,"size:%"SCNu32"x%"SCNu32"",&(sub->width),&(sub->height)); } } } } } subSuccess: success=1; if(!sub->hasPalette) { for(int j=0;j<16;j++) sub->Palette[j]=j; } subAbort: if(success) { *info=sub; } else { destroySubInfo( sub); } fclose(file); return success; }
GameUpdater::TileMap* GameUpdater::buildKnownTiles(int viewRange) const { TileMap* map = new TileMap(); float angle = std::atan2(relativeAim[0] , relativeAim[1]); angle *= (float)(180 / M_PI); std::cout << " angle: " << angle << std::endl; int targetX = Utils::round(playerPosition[0] + relativeAim[0]); int targetY = Utils::round(playerPosition[1] + relativeAim[1]); std::cout << targetX << ";" << targetY << std::endl; int x1 = Utils::round(playerPosition[0]); int y1 = Utils::round(playerPosition[1]); map = fillLine(x1, y1, targetX, targetY, map); map = fillLine(x1, y1, targetX, targetY + 1, map); map = fillLine(x1, y1, targetX, targetY + 2, map); map = fillLine(x1, y1, targetX, targetY + 3, map); map = fillLine(x1, y1, targetX, targetY + 4, map); map = fillLine(x1, y1, targetX, targetY - 1, map); map = fillLine(x1, y1, targetX, targetY - 2, map); map = fillLine(x1, y1, targetX, targetY - 3, map); //map = fillLine(x1, y1, targetX, targetY - 4, map); map = fillLine(x1, y1, targetX+1, targetY, map); map = fillLine(x1, y1, targetX+2, targetY, map); map = fillLine(x1, y1, targetX+3, targetY, map); map = fillLine(x1, y1, targetX+4, targetY, map); map = fillLine(x1, y1, targetX-1, targetY, map); map = fillLine(x1, y1, targetX-2, targetY, map); map = fillLine(x1, y1, targetX-3, targetY, map); //map = fillLine(x1, y1, targetX-4, targetY, map); map = fillLine(x1, y1, targetX + 1, targetY + 1, map); map = fillLine(x1, y1, targetX + 2, targetY + 2, map); map = fillLine(x1, y1, targetX + 3, targetY + 3, map); map = fillLine(x1, y1, targetX - 1, targetY - 1, map); map = fillLine(x1, y1, targetX - 2, targetY - 2, map); //map = fillLine(x1, y1, targetX - 3, targetY - 3, map); return map; return rec_buildKnownTiles(map, viewRange + 1, (int)Utils::round(playerPosition[0]), (int)Utils::round(playerPosition[1])); }