void decodeGreaterLessThan(const std::vector<uint8_t>& frame, const Pal& pal, std::vector<Colour>& rawImage, bool lessThan) { #ifdef CEL_DEBUG std::cout << (lessThan ? "Less" : "Greater") << " than" << std::endl; #endif int framePos = 0; drawRow(0, 15, framePos, frame, pal, rawImage, lessThan); if((lessThan && lessThanSecond(frame)) || (!lessThan && greaterThanSecond(frame))) { drawRow(16, 33, framePos, frame, pal, rawImage, lessThan); } else { for(framePos = 256; framePos < frame.size(); framePos++) rawImage.push_back(pal[frame[framePos]]); } #ifdef CEL_DEBUG std::cout << (lessThan ? "LT" : "GT") << rawImage.size() << std::endl; #endif }
void drawFrame(COORD a, COORD b, char row, char col)//左上角坐标、右下角坐标、用row填充行、用col填充列 { drawRow(a.Y, a.X + 1, b.X - 1, row); drawRow(b.Y, a.X + 1, b.X - 1, row); drawCol(a.X, a.Y + 1, b.Y - 1, col); drawCol(b.X, a.Y + 1, b.Y - 1, col); }
void drawRow(COORD a, COORD b, char ch){//在a, b 纵坐标相同的前提下,把坐标 [a, b] 之间填充为 ch if (a.Y == b.Y) drawRow(a.Y, a.X, b.X, ch); else{ SetPos(0, 25); cout << "error code 01:无法填充行,因为两个坐标的纵坐标(x)不相等"; system("pause"); } }
bool SequenceAreaRenderer::drawContent(QPainter &painter, const U2Region ®ion, const QList<int> &seqIdx, int xStart, int yStart) const { CHECK(!region.isEmpty(), false); CHECK(!seqIdx.isEmpty(), false); MsaHighlightingScheme* highlightingScheme = seqAreaWgt->getCurrentHighlightingScheme(); MaEditor* editor = seqAreaWgt->getEditor(); painter.setPen(Qt::black); painter.setFont(editor->getFont()); MultipleAlignmentObject* maObj = editor->getMaObject(); SAFE_POINT(maObj != NULL, tr("Alignment object is NULL"), false); const MultipleAlignment ma = maObj->getMultipleAlignment(); //Use dots to draw regions, which are similar to reference sequence highlightingScheme->setUseDots(seqAreaWgt->getUseDotsCheckedState()); int rowHeight = 0; foreach (const int rowIndex, seqIdx) { rowHeight = drawRow(painter, ma, rowIndex, region, xStart, yStart); yStart += ui->getRowHeightController()->getRowHeight(rowIndex); }
void drawSingleTetrisBlock(int row, int col, const unsigned short* type) { for(int i = 0; i < 8; i ++) { drawRow(&type[OFFSET(i, 0, 8)], &videoBuffer[OFFSET(row + i, col, 240)], 8); } }
// This method takes an 8x8 matrix and a boolean (whether to calibrate levels) // and translates that into draw instructions for the device. void LED::draw(double* matrix, boolean calibrate_levels) { // internal counters int matrix_index; double pixel; double total_pixel_count; int total_cycle_count; int matrix_counter[64]; // total cycle counts is the number of times we will loop through a draw "cycle" // and determines the granularity we can rely on for our values. A higher cycle // count will allow for more granularity of values (and thus is good for fades) // but especially if the scene is complicated, too high of a cycle count can result // in flickering. So its a trade off. // // A solution to that tradeoff is to turn on and off calibration depending on what is // needed. if (calibrate_levels) { total_cycle_count = 4; //we need to lower our threshold to reduce flickering } else { total_cycle_count = 10; //no fancy pants math so we can have more levels of gradation for fading. } // initialize our matrix to write values to. for (int i =0;i<64;i++) { matrix_counter[i] = 0; } // loop for a certain cycle count, specified above. for (int cycle_count=0;cycle_count<total_cycle_count;cycle_count++) { // loop through each column. for (int col=0;col<8;col++) { total_pixel_count = 0; // counter to remember how many non-0 LED's we have in a column. // calculate our total LED's per row (but only if we are calibrating levels) if (calibrate_levels) { for (int row=0;row<8;row++) { matrix_index = row+(8*(col)); // go from the bottom up, based on the wiring of the board. pixel = matrix[matrix_index]; if (pixel > 0) { total_pixel_count += 1; // count the pixel if non-zero. } } } // now loop through each row in order to set the Pixel. for (int row=0;row<8;row++) { matrix_index = row+(8*(col)); // go from the bottom up, based on the wiring of the board. pixel = matrix[matrix_index]; if (calibrate_levels) { pixel = parsePixel(pixel,total_pixel_count,col); } current_row[row] = 0; int division = total_cycle_count; int mod_division = round(division * pixel); // this is a bit of a naive approach, but time limitations prevented // solution two from being implemented. // // In approach #1, we compare the current cycle count (which we are incrementing // a certain amount of times, as specified above) and if that remains below // mod_division, which is a threshold set according to the pixel value floating number, // then the pixel is on. Otherwise, it is off. // // This approximates the pixel having a variable brightness, at least at lower numbers // of cycles. if (1) { if (cycle_count % division < mod_division) { current_row[row] = 1; } // A better approach, detailed below but buggy, uses the same basic idea as above, // with the addition that it attempts to evenly space out the 1's and 0's over time. // theoretically this would allow us to use 255 cycle counts for a maximum amount of // granularity and a minimum of flickering. // // Unfortunately, bugs exist which I cannot fix. } else { int matrix_counter_index = row + (col*8); if (matrix_counter[matrix_counter_index]==1) { current_row[row] = 1; } matrix_counter[matrix_counter_index] += 1; float division_of_pixel; if (pixel > 0) { division_of_pixel = 1 / pixel; } else { division_of_pixel = 0; } if (matrix_counter[matrix_counter_index] >= division_of_pixel) { matrix_counter[matrix_counter_index] = 0; } } } drawRow(cols[col],current_row); // finally, we draw our current row. } } }
void render(Scene& scene, Texture& screen, int renderno = 0, int outof = 1) { char titlebuf[200]; if (settings.show_preview) { sprintf(titlebuf, "%s", TITLE); SDL_SetWindowTitle(window, titlebuf); } Vect4 color; bool exitflag = 0; int v; //Return value from threads RenderQueue rq(&scene, &screen); SDL_Thread** threads = new SDL_Thread* [settings.nworkers]; rq.pushRow(0); for (int i = 0; i < settings.nworkers; i++) threads[i] = SDL_CreateThread(&renderThread, NULL, &rq); for (int i = 0; i < settings.nworkers; i++) SDL_WaitThread(threads[i], &v); for (int r = 1; r < screen.height(); r++) { if (settings.show_preview) { SDL_Event event; while (SDL_PollEvent(&event)) if (event.type == SDL_QUIT || (event.type == SDL_KEYDOWN && event.key.keysym.sym == SDLK_ESCAPE)) exit(0); else if (event.type == SDL_KEYDOWN && event.key.keysym.sym == SDLK_RETURN) exitflag = 1; if (exitflag) break; } rq.pushRow(r); for (int i = 0; i < settings.nworkers; i++) threads[i] = SDL_CreateThread(&renderThread, NULL, &rq); if (settings.show_preview) { drawRow(screen, r - 1); px->redraw(); SDL_RenderPresent(px->getRenderer()); } for (int i = 0; i < settings.nworkers; i++) SDL_WaitThread(threads[i], &v); if (outof > 1) sprintf(titlebuf, "%s [%d / %d, %d of %d]",TITLE, r + 1, screen.height(), renderno, outof); else sprintf(titlebuf, "%s [%d / %d]", TITLE, r + 1, screen.height()); if (settings.show_preview) SDL_SetWindowTitle(window, titlebuf); else { printf("\r%s", titlebuf); fflush(0); } } if (settings.show_preview) { drawRow(screen, screen.height() - 1); px->redraw(); SDL_RenderPresent(px->getRenderer()); } else printf("\n"); if (!settings.aa_enabled) { delete [] threads; return; } Texture dmap = screen.differenceMap(); float d; for (int r = 1; r < screen.height() - 1; r++) { if (settings.show_preview) { SDL_Event event; while (SDL_PollEvent(&event)) if (event.type == SDL_QUIT || (event.type == SDL_KEYDOWN && event.key.keysym.sym == SDLK_ESCAPE)) exit(0); else if (event.type == SDL_KEYDOWN && event.key.keysym.sym == SDLK_RETURN) exitflag = 1; if (exitflag) break; } for (int c = 1; c < screen.width() - 1; c++) { d = dot(dmap.getColor(r, c), Vect4(1, 1, 1, 0)); if (d > settings.aa_threshold) rq.push(r, c); } for (int i = 0; i < settings.nworkers; i++) threads[i] = SDL_CreateThread(&renderThread_AA, NULL, &rq); if (settings.show_preview) { drawRow(screen, r - 1); px->redraw(); SDL_RenderPresent(px->getRenderer()); } for (int i = 0; i < settings.nworkers; i++) SDL_WaitThread(threads[i], &v); if (outof > 1) sprintf(titlebuf, "%s [AA: %d / %d, %d of %d]", TITLE, r + 2, screen.height(), renderno, outof); else sprintf(titlebuf, "%s [AA: %d / %d]",TITLE, r + 2, screen.height()); if (settings.show_preview) SDL_SetWindowTitle(window, titlebuf); else { printf("\r%s", titlebuf); fflush(0); } } delete [] threads; if (settings.show_preview) { drawRow(screen, screen.height() - 2); px->redraw(); SDL_RenderPresent(px->getRenderer()); SDL_SetWindowTitle(window, TITLE); } else printf("\n"); }