void colorx_node_t::do_expression( const tbb::blocked_range<int>& range, const Imath::Box2i& area, const render::context_t& context) { std::string color_expr = get_value<std::string>( param( expr_param_name())); image_expression_t expr( color_expr, this, color_context); RAMEN_ASSERT( expr.isValid()); expr.setup_variables( this, context); image::const_image_view_t src = input_as<image_node_t>()->const_subimage_view( area); image::image_view_t dst = subimage_view( area); SeVec3d& cvar = expr.vec_vars["Cs"].val; double& avar = expr.vars["As"].val; double *out_avar = expr.get_local_var_ref( "Ao", &avar); for( int y = range.begin(); y < range.end(); ++y) { image::const_image_view_t::x_iterator src_it( src.row_begin( y)); image::image_view_t::x_iterator dst_it( dst.row_begin( y)); for( int x = 0, xe = src.width(); x < xe; ++x) { cvar[0] = boost::gil::get_color( *src_it, boost::gil::red_t()); cvar[1] = boost::gil::get_color( *src_it, boost::gil::green_t()); cvar[2] = boost::gil::get_color( *src_it, boost::gil::blue_t()); avar = boost::gil::get_color( *src_it, boost::gil::alpha_t()); SeVec3d result = expr.evaluate(); *dst_it++ = image::pixel_t( result[0], result[1], result[2], *out_avar); ++src_it; } } }
// Helper function to divide the input blobs over noise, small, medium // and large lists. Blobs small in height and (small in width or large in width) // go in the noise list. Dash (-) candidates go in the small list, and // medium and large are by height. // SIDE-EFFECT: reset all blobs to initial state by calling Init(). static void SizeFilterBlobs(int min_height, int max_height, BLOBNBOX_LIST* src_list, BLOBNBOX_LIST* noise_list, BLOBNBOX_LIST* small_list, BLOBNBOX_LIST* medium_list, BLOBNBOX_LIST* large_list) { BLOBNBOX_IT noise_it(noise_list); BLOBNBOX_IT small_it(small_list); BLOBNBOX_IT medium_it(medium_list); BLOBNBOX_IT large_it(large_list); for (BLOBNBOX_IT src_it(src_list); !src_it.empty(); src_it.forward()) { BLOBNBOX* blob = src_it.extract(); blob->ReInit(); int width = blob->bounding_box().width(); int height = blob->bounding_box().height(); if (height < min_height && (width < min_height || width > max_height)) noise_it.add_after_then_move(blob); else if (height > max_height) large_it.add_after_then_move(blob); else if (height < min_height) small_it.add_after_then_move(blob); else medium_it.add_after_then_move(blob); } }
void cineon_writer_t::write_pixels( std::ofstream& out, const image::const_image_view_t& view) const { std::vector<boost::uint32_t> buffer( view.width()); for( int y = 0; y < view.height(); ++y) { image::const_image_view_t::x_iterator src_it( view.row_begin( y)); for( int x = 0; x < view.width(); ++x) { boost::uint32_t pix = 0; float r = boost::gil::get_color( *src_it, boost::gil::red_t()); float g = boost::gil::get_color( *src_it, boost::gil::green_t()); float b = boost::gil::get_color( *src_it, boost::gil::blue_t()); boost::uint32_t ri = adobe::clamp( r, 0.0f, 1.0f) * 1023; boost::uint32_t gi = adobe::clamp( g, 0.0f, 1.0f) * 1023; boost::uint32_t bi = adobe::clamp( b, 0.0f, 1.0f) * 1023; pix = ( ri << 22) | ( gi << 12) | ( bi << 2); buffer[x] = IECore::asBigEndian( pix); ++src_it; } // write vector out.write( reinterpret_cast<char *>( &buffer[0]), view.width() * sizeof( boost::uint32_t)); if ( out.fail()) throw exception( "error while writting image"); } }
// Return a copy of this. If good_only will only copy the Good ColPartitions. ColPartitionSet* ColPartitionSet::Copy(bool good_only) { ColPartition_LIST copy_parts; ColPartition_IT src_it(&parts_); ColPartition_IT dest_it(©_parts); for (src_it.mark_cycle_pt(); !src_it.cycled_list(); src_it.forward()) { ColPartition* part = src_it.data(); if (BLOBNBOX::IsTextType(part->blob_type()) && (!good_only || part->good_width() || part->good_column())) dest_it.add_after_then_move(part->ShallowCopy()); } if (dest_it.empty()) return NULL; return new ColPartitionSet(©_parts); }
void orientation(const Image<Matrix<T,2,1> >& src, Image<T>& dst) { if (dst.sizes() != src.sizes()) dst.resize(src.sizes()); typedef typename Image<Matrix<T,2,1> >::const_iterator InputIterator; typedef typename Image<T>::iterator OutputIterator; InputIterator src_it(src.begin()); InputIterator src_it_end(src.end()); OutputIterator dst_it(dst.begin()); for ( ; src_it != src_it_end; ++src_it, ++dst_it) *dst_it = std::atan2(src_it->y(), src_it->x()); }
void stableNorm(Image<T, D>& dst, const Image<Matrix<T,M,N>, D>& src) { if (dst.sizes() != src.sizes()) dst.resize(src.sizes()); typedef typename Image<Matrix<T,M,N>, D>::const_iterator InputIterator; typedef typename Image<T, D>::iterator OutputIterator; InputIterator src_it(src.begin()); InputIterator src_it_end(src.end()); OutputIterator dst_it(dst.begin()); for ( ; src_it != src_it_end; ++src_it, ++dst_it) *dst_it = src_it->stableNorm(); }
void WERD::join_on(WERD* other) { C_BLOB_IT blob_it(&cblobs); C_BLOB_IT src_it(&other->cblobs); C_BLOB_IT rej_cblob_it(&rej_cblobs); C_BLOB_IT src_rej_it(&other->rej_cblobs); while (!src_it.empty()) { blob_it.add_to_end(src_it.extract()); src_it.forward(); } while (!src_rej_it.empty()) { rej_cblob_it.add_to_end(src_rej_it.extract()); src_rej_it.forward(); } }
void initialise_search(WERD_RES_LIST &src_list, WERD_RES_LIST &new_list) { WERD_RES_IT src_it(&src_list); WERD_RES_IT new_it(&new_list); WERD_RES *src_wd; WERD_RES *new_wd; for (src_it.mark_cycle_pt(); !src_it.cycled_list(); src_it.forward()) { src_wd = src_it.data(); if (!src_wd->combination) { new_wd = new WERD_RES(*src_wd); new_wd->combination = FALSE; new_wd->part_of_combo = FALSE; new_it.add_after_then_move(new_wd); } } }
// Static helper for C_BLOB::rotate to allow recursion of child outlines. void RotateOutlineList(const FCOORD& rotation, C_OUTLINE_LIST* outlines) { C_OUTLINE_LIST new_outlines; C_OUTLINE_IT src_it(outlines); C_OUTLINE_IT dest_it(&new_outlines); while (!src_it.empty()) { C_OUTLINE* old_outline = src_it.extract(); src_it.forward(); C_OUTLINE* new_outline = new C_OUTLINE(old_outline, rotation); if (!old_outline->child()->empty()) { RotateOutlineList(rotation, old_outline->child()); C_OUTLINE_IT child_it(new_outline->child()); child_it.add_list_after(old_outline->child()); } delete old_outline; dest_it.add_to_end(new_outline); } src_it.add_list_after(&new_outlines); }
void copy_bitmaps(Image* dst, const Image* src, gfx::Clip area) { if (!area.clip(dst->width(), dst->height(), src->width(), src->height())) return; // Copy process ImageConstIterator<BitmapTraits> src_it(src, area.srcBounds(), area.src.x, area.src.y); ImageIterator<BitmapTraits> dst_it(dst, area.dstBounds(), area.dst.x, area.dst.y); int end_x = area.dst.x+area.size.w; for (int end_y=area.dst.y+area.size.h; area.dst.y<end_y; ++area.dst.y, ++area.src.y) { for (int x=area.dst.x; x<end_x; ++x) { *dst_it = *src_it; ++src_it; ++dst_it; } } }
pixel_t bicubic_sampler_t::sample( const Imath::V2d& p) const { int x = IECore::fastFloatFloor( p.x); int y = IECore::fastFloatFloor( p.y); if( ( x < src_area_.min.x + 1) || ( x > src_area_.max.x - 2) || ( y < src_area_.min.y + 1) || ( y > src_area_.max.y - 2)) return bilinear_sampler_t::sample( p); float fractx = p.x - x; float fracty = p.y - y; float xweights[4], yweights[4]; weights( fractx, xweights); weights( fracty, yweights); image::pixel_t result( 0, 0, 0, 0); for( int j = -1; j <= 2; ++j) { image::const_image_view_t::x_iterator src_it( src_.row_begin( y - src_area_.min.y + j)); src_it += x - src_area_.min.x - 1; image::pixel_t row; for( int c = 0; c < 4; ++c) { row[c] = src_it[0][c] * xweights[0]; row[c] += src_it[1][c] * xweights[1]; row[c] += src_it[2][c] * xweights[2]; row[c] += src_it[3][c] * xweights[3]; result[c] += row[c] * yweights[j+1]; } } return result; }
// The column_set has changed. Close down all in-progress WorkingPartSets in // columns that do not match and start new ones for the new columns in this. // As ColPartitions are turned into BLOCKs, the used ones are put in // used_parts, as they still need to be referenced in the grid. void ColPartitionSet::ChangeWorkColumns(const ICOORD& bleft, const ICOORD& tright, int resolution, ColPartition_LIST* used_parts, WorkingPartSet_LIST* working_set_list) { // Move the input list to a temporary location so we can delete its elements // as we add them to the output working_set. WorkingPartSet_LIST work_src; WorkingPartSet_IT src_it(&work_src); src_it.add_list_after(working_set_list); src_it.move_to_first(); WorkingPartSet_IT dest_it(working_set_list); // Completed blocks and to_blocks are accumulated and given to the first new // one whenever we keep a column, or at the end. BLOCK_LIST completed_blocks; TO_BLOCK_LIST to_blocks; WorkingPartSet* first_new_set = NULL; WorkingPartSet* working_set = NULL; ColPartition_IT col_it(&parts_); for (col_it.mark_cycle_pt(); !col_it.cycled_list(); col_it.forward()) { ColPartition* column = col_it.data(); // Any existing column to the left of column is completed. while (!src_it.empty() && ((working_set = src_it.data())->column() == NULL || working_set->column()->right_key() <= column->left_key())) { src_it.extract(); working_set->ExtractCompletedBlocks(bleft, tright, resolution, used_parts, &completed_blocks, &to_blocks); delete working_set; src_it.forward(); } // Make a new between-column WorkingSet for before the current column. working_set = new WorkingPartSet(NULL); dest_it.add_after_then_move(working_set); if (first_new_set == NULL) first_new_set = working_set; // A matching column gets to stay, and first_new_set gets all the // completed_sets. working_set = src_it.empty() ? NULL : src_it.data(); if (working_set != NULL && working_set->column()->MatchingColumns(*column)) { working_set->set_column(column); dest_it.add_after_then_move(src_it.extract()); src_it.forward(); first_new_set->InsertCompletedBlocks(&completed_blocks, &to_blocks); first_new_set = NULL; } else { // Just make a new working set for the current column. working_set = new WorkingPartSet(column); dest_it.add_after_then_move(working_set); } } // Complete any remaining src working sets. while (!src_it.empty()) { working_set = src_it.extract(); working_set->ExtractCompletedBlocks(bleft, tright, resolution, used_parts, &completed_blocks, &to_blocks); delete working_set; src_it.forward(); } // Make a new between-column WorkingSet for after the last column. working_set = new WorkingPartSet(NULL); dest_it.add_after_then_move(working_set); if (first_new_set == NULL) first_new_set = working_set; // The first_new_set now gets any accumulated completed_parts/blocks. first_new_set->InsertCompletedBlocks(&completed_blocks, &to_blocks); }
void LayoutConfig::initUI() { const char *modelName = m_rules->models()[m_kxkbConfig.m_model]; if(modelName == NULL) modelName = DEFAULT_MODEL; widget->comboModel->setCurrentText(i18n(modelName)); QValueList< LayoutUnit > otherLayouts = m_kxkbConfig.m_layouts; widget->listLayoutsDst->clear(); // to optimize we should have gone from it.end to it.begin QValueList< LayoutUnit >::ConstIterator it; for(it = otherLayouts.begin(); it != otherLayouts.end(); ++it) { QListViewItemIterator src_it(widget->listLayoutsSrc); LayoutUnit layoutUnit = *it; for(; src_it.current(); ++src_it) { QListViewItem *srcItem = src_it.current(); if(layoutUnit.layout == src_it.current()->text(LAYOUT_COLUMN_MAP)) { // check if current config knows about this layout QListViewItem *newItem = copyLVI(srcItem, widget->listLayoutsDst); newItem->setText(LAYOUT_COLUMN_VARIANT, layoutUnit.variant); newItem->setText(LAYOUT_COLUMN_INCLUDE, layoutUnit.includeGroup); newItem->setText(LAYOUT_COLUMN_DISPLAY_NAME, layoutUnit.displayName); widget->listLayoutsDst->insertItem(newItem); newItem->moveItem(widget->listLayoutsDst->lastItem()); break; } } } // display KXKB switching options widget->chkShowSingle->setChecked(m_kxkbConfig.m_showSingle); widget->chkShowFlag->setChecked(m_kxkbConfig.m_showFlag); widget->chkEnableOptions->setChecked(m_kxkbConfig.m_enableXkbOptions); widget->checkResetOld->setChecked(m_kxkbConfig.m_resetOldOptions); switch(m_kxkbConfig.m_switchingPolicy) { default: case SWITCH_POLICY_GLOBAL: widget->grpSwitching->setButton(0); break; case SWITCH_POLICY_WIN_CLASS: widget->grpSwitching->setButton(1); break; case SWITCH_POLICY_WINDOW: widget->grpSwitching->setButton(2); break; } widget->chkEnableSticky->setChecked(m_kxkbConfig.m_stickySwitching); widget->spinStickyDepth->setEnabled(m_kxkbConfig.m_stickySwitching); widget->spinStickyDepth->setValue(m_kxkbConfig.m_stickySwitchingDepth); updateStickyLimit(); widget->chkEnable->setChecked(m_kxkbConfig.m_useKxkb); widget->grpLayouts->setEnabled(m_kxkbConfig.m_useKxkb); widget->optionsFrame->setEnabled(m_kxkbConfig.m_useKxkb); // display xkb options QStringList options = QStringList::split(',', m_kxkbConfig.m_options); for(QStringList::ConstIterator it = options.begin(); it != options.end(); ++it) { QString option = *it; QString optionKey = option.mid(0, option.find(':')); QString optionName = m_rules->options()[option]; OptionListItem *item = m_optionGroups[i18n(optionKey.latin1())]; if(item != NULL) { OptionListItem *child = item->findChildItem(option); if(child) child->setState(QCheckListItem::On); else kdDebug() << "load: Unknown option: " << option << endl; } else { kdDebug() << "load: Unknown option group: " << optionKey << " of " << option << endl; } } updateOptionsCommand(); emit KCModule::changed(false); }