void CNFORenderer::RenderBackgrounds(size_t a_rowStart, size_t a_rowEnd, double a_yBase, cairo_t* cr) const { cairo_save(cr); if(GetBackColor().A > 0) { cairo_set_source_rgba(cr, S_COLOR_T_CAIRO_A(GetBackColor())); cairo_paint(cr); } if(m_nfo->HasColorMap()) { double dbw = static_cast<double>(GetBlockWidth()); double dbh = static_cast<double>(GetBlockHeight()); uint32_t l_defaultColor = GetBackColor().AsWord(); for(size_t row = (a_rowStart == -1 ? 0 : a_rowStart); row <= a_rowEnd; row++) { std::vector<size_t> l_columns; std::vector<uint32_t> l_colors; if(!m_nfo->GetColorMap()->GetLineBackgrounds(row, l_defaultColor, m_gridData->GetCols(), l_columns, l_colors)) continue; _ASSERT(l_colors.size() == l_columns.size()); _ASSERT(l_columns.size() > 0); size_t col = 0; for(size_t section = 0; section < l_colors.size(); section++) { _ASSERT(l_columns[section] > 0); _ASSERT(l_columns[section] <= m_gridData->GetCols()); size_t col_to = col + l_columns[section]; _ASSERT(col_to > col); if(l_colors[section] != l_defaultColor) { double x_from = col * dbw, x_to = col_to * dbw; cairo_set_source_rgb(cr, S_COLOR_T_CAIRO(S_COLOR_T(l_colors[section]))); cairo_rectangle(cr, GetPadding() + x_from, a_yBase + GetPadding() + dbh * row, x_to - x_from, dbh); cairo_fill(cr); } col = col_to; } } } cairo_restore(cr); }
bool SysTestBase::DisConnectBlock(int nNum) { int nFirstHeight = 0; GetBlockHeight(nFirstHeight); if(nFirstHeight <=0) return false; BOOST_CHECK(nNum>0 && nNum<=nFirstHeight); string strNum = strprintf("%d",nNum); const char *argv[3] = { "rpctest", "disconnectblock", strNum.c_str()}; int argc = sizeof(argv) / sizeof(char*); Value value; if (CommandLineRPC_GetValue(argc, argv, value)) { int nHeightAfterDis =0; GetBlockHeight(nHeightAfterDis); BOOST_CHECK(nHeightAfterDis == nFirstHeight-nNum); return true; } return false; }
bool SysTestBase::GenerateOneBlock() { const char *argv[] = { "rpctest", "setgenerate", "true" ,"1"}; int argc = sizeof(argv) / sizeof(char*); int high= 0; GetBlockHeight(high); Value value; if (CommandLineRPC_GetValue(argc, argv, value)) { int nHeight = 0; int conter = 0; do{ MilliSleep(1000); GetBlockHeight(nHeight); if(conter++ > 80) { break; } }while(high+1 > nHeight); BOOST_CHECK(conter < 80); return true; } return false; }
void CNFORenderer::CalcStripeDimensions() { if(!m_nfo || !m_gridData) { return; } #ifndef COMPACT_RELEASE // 2 CPU cores <=> 2000 px stripe height // ==> 8 CPU cores <=> 250 // (= more threads) // but: never use less than 500px per stripe. size_t l_stripeHeightMaxForCores = std::max(2000 * 2 / omp_get_num_procs(), 500); #else size_t l_stripeHeightMaxForCores = 2000; #endif /* COMPACT_RELEASE */ size_t l_stripeHeightMax = std::max(l_stripeHeightMaxForCores, GetBlockHeight() * 2); // MUST not be smaller than one line's height, using two for sanity size_t l_numStripes = GetHeight() / l_stripeHeightMax; // implicit floor() if(l_numStripes == 0) l_numStripes = 1; size_t l_linesPerStripe = m_nfo->GetGridHeight() / l_numStripes; // implicit floor() while(l_linesPerStripe * l_numStripes < m_nfo->GetGridHeight()) { // correct rounding errors l_numStripes++; } // storing these three is a bit redundant, but saves code & calculations in other places: m_linesPerStripe = l_linesPerStripe; m_stripeHeight = static_cast<int>(l_linesPerStripe * GetBlockHeight()); m_numStripes = l_numStripes; _ASSERT(m_stripeHeight * m_numStripes + GetPadding() * 2 >= GetHeight()); }
void CNFORenderer::RenderBlocks(bool a_opaqueBg, bool a_gaussStep, cairo_t* a_context, size_t a_rowStart, size_t a_rowEnd, double a_xBase, double a_yBase) const { double l_off_x = GetPadding() + a_xBase, l_off_y = GetPadding() + a_yBase; size_t l_rowStart = 0, l_rowEnd = m_gridData->GetRows() - 1; if(a_rowStart != (size_t)-1) { l_rowStart = std::max(a_rowStart, l_rowStart); l_rowEnd = std::min(a_rowEnd, l_rowEnd); } cairo_t * const cr = a_context; cairo_save(cr); if(a_opaqueBg) { RenderBackgrounds(l_rowStart, l_rowEnd, a_yBase, cr); } cairo_set_antialias(cr, CAIRO_ANTIALIAS_SUBPIXEL); bool l_hasColorMap = m_nfo->HasColorMap(); int l_oldAlpha = 0; uint32_t l_oldColor = 0; bool l_first = true; // micro optimization const double bwd = static_cast<double>(GetBlockWidth()); const double bhd = static_cast<double>(GetBlockHeight()); const double bwd05 = bwd * 0.5; const double bhd05 = bhd * 0.5; for(size_t row = l_rowStart; row <= l_rowEnd; row++) { if(m_cancelRenderingImmediately) { break; } for(size_t col = 0; col < m_gridData->GetCols(); col++) { const CRenderGridBlock *l_block = &(*m_gridData)[row][col]; if(l_block->shape == RGS_NO_BLOCK || l_block->shape == RGS_WHITESPACE || l_block->shape == RGS_WHITESPACE_IN_TEXT) { continue; } S_COLOR_T l_drawingColor = a_gaussStep ? GetGaussColor() : GetArtColor(); if(l_hasColorMap) { uint32_t clr; m_nfo->GetColorMap()->GetForegroundColor(row, col, l_drawingColor.AsWord(), clr); l_drawingColor = S_COLOR_T(clr); } if(l_first || (l_block->alpha != l_oldAlpha) // R,G,B never change during the loop (unless there's a colormap) || (l_hasColorMap && l_drawingColor != l_oldColor) ) { cairo_fill(cr); // complete previous drawing operation(s) cairo_set_source_rgba(cr, S_COLOR_T_CAIRO(l_drawingColor), (l_block->alpha / 255.0) * (l_drawingColor.A / 255.0)); // known issue: Alpha from GetGauss/ArtColor is discarded if there's a colormap. l_oldAlpha = l_block->alpha; l_oldColor = l_drawingColor.AsWord(); l_first = false; } double l_pos_x = col * bwd, l_pos_y = row * bhd, l_width = bwd, l_height = bhd; switch(l_block->shape) { case RGS_BLOCK_LOWER_HALF: l_pos_y += bhd05; case RGS_BLOCK_UPPER_HALF: l_height = bhd05; break; case RGS_BLOCK_RIGHT_HALF: l_pos_x += bwd05; case RGS_BLOCK_LEFT_HALF: l_width = bwd05; break; case RGS_BLACK_SQUARE: l_width = l_height = bwd * 0.75; l_pos_y += bhd05 - l_height * 0.5; l_pos_x += bwd05 - l_width * 0.5; break; case RGS_BLACK_SMALL_SQUARE: l_width = l_height = bwd05; l_pos_y += bhd05 - l_height * 0.5; l_pos_x += bwd05 - l_width * 0.5; break; } cairo_rectangle(cr, l_off_x + l_pos_x, l_off_y + l_pos_y, l_width, l_height); } } cairo_fill(cr); // complete pending drawing operation(s) cairo_restore(cr); }
size_t CNFORenderer::GetStripeExtraLinesBottom(size_t a_stripe) const { if(IsClassicMode() || !GetEnableGaussShadow() || a_stripe == m_numStripes - 1) return 0; return static_cast<size_t>(ceil(static_cast<double>(GetGaussBlurRadius()) / static_cast<double>(GetBlockHeight()))); }
int CNFORenderer::GetStripeHeightExtraBottom(size_t a_stripe) const { return static_cast<int>(GetStripeExtraLinesBottom(a_stripe) * GetBlockHeight()); }