int search(void){ state curr, next; curr.y = starty; curr.idx = findSegment(startx, starty); curr.steps = 0; push(curr); while (queueIsNotEmpty){ curr = pop(); if (allowed[curr.idx].r == endx && curr.y == endy) return curr.steps; int i; next.steps = curr.steps + 1; for (i = 0; i < DIR; i++){ int x = allowed[curr.idx].r + diffx[i], y = curr.y + diffy[i]; int idx = findSegment(x, y); if (idx != -1 && !visited[allowed[idx].vis + y - allowed[idx].a]){ visited[allowed[idx].vis + y - allowed[idx].a] = true; next.y = y; next.idx = idx; push(next); } } } return -1; }
void ImageBlocker::findSegmentRange(size_t startRow, size_t numRows, size_t& firstSegIdx, size_t& startBlockWithinFirstSeg, size_t& lastSegIdx, size_t& lastBlockWithinLastSeg) const { if (numRows == 0) { firstSegIdx = startBlockWithinFirstSeg = lastSegIdx = lastBlockWithinLastSeg = std::numeric_limits<size_t>::max(); } else { // Figure out which segment we're starting in size_t startRowWithinFirstSeg; findSegment(startRow, firstSegIdx, startRowWithinFirstSeg, startBlockWithinFirstSeg); if (!isFirstRowInBlock(startRowWithinFirstSeg)) { std::ostringstream ostr; ostr << "Start row " << startRow << " is local row " << startRowWithinFirstSeg << " within segment " << firstSegIdx << ". The local row must be a multiple of " << mNumRowsPerBlock << "."; throw except::Exception(Ctxt(ostr.str())); } // Figure out which segment we're ending in const size_t lastRow = startRow + numRows - 1; size_t lastRowWithinLastSeg; findSegment(lastRow, lastSegIdx, lastRowWithinLastSeg, lastBlockWithinLastSeg); const size_t endRowWithinLastSeg = lastRowWithinLastSeg + 1; // Make sure we're ending on a full block if (!(endRowWithinLastSeg == mNumRows[lastSegIdx] || isFirstRowInBlock(endRowWithinLastSeg))) { std::ostringstream ostr; ostr << "Last row " << lastRow << " is local row " << lastRowWithinLastSeg << " within segment " << lastSegIdx << ". This must land on a full block."; throw except::Exception(Ctxt(ostr.str())); } } }
virtual void putAttribute( const SegmenterPosition& segpos, std::size_t ofs, const std::string& name, const std::string& value) { try { typename SegmentMap::const_iterator segitr = findSegment( segpos); if (segitr == m_segmentmap.end()) { throw std::runtime_error( _TXT("segment with this position not defined or it cannot be used for markup because it is not of type content")); } std::size_t origpos = getOrigPosition( segpos, ofs); if (m_markups.size() && m_markups.back().origpos == origpos && (m_markups.back().type == MarkupElement::OpenTag || m_markups.back().type == MarkupElement::AttributeValue)) { m_markups.push_back( MarkupElement( MarkupElement::AttributeName, origpos, m_markups.size(), name)); m_markups.push_back( MarkupElement( MarkupElement::AttributeValue, origpos, m_markups.size(), value)); } else { m_markups.push_back( MarkupElement( MarkupElement::AttributeName, segitr->second.origpos, m_markups.size(), name)); m_markups.push_back( MarkupElement( MarkupElement::AttributeValue, segitr->second.origpos, m_markups.size(), value)); } } CATCH_ERROR_ARG1_MAP( _TXT("error in put attribute of '%s' segmenter markup context: %s"), "textwolf", *m_errorhnd); }
void InspectorReplayAgent::insertSessionSegment(ErrorString& errorString, Inspector::Protocol::Replay::SessionIdentifier sessionIdentifier, SegmentIdentifier segmentIdentifier, int segmentIndex) { ASSERT_ARG(sessionIdentifier, sessionIdentifier > 0); ASSERT_ARG(segmentIdentifier, segmentIdentifier > 0); ASSERT_ARG(segmentIndex, segmentIndex >= 0); RefPtr<ReplaySession> session = findSession(errorString, sessionIdentifier); RefPtr<ReplaySessionSegment> segment = findSegment(errorString, segmentIdentifier); if (!session || !segment) return; if (static_cast<size_t>(segmentIndex) > session->size()) { errorString = ASCIILiteral("Invalid segment index."); return; } if (session == m_page.replayController().loadedSession() && sessionState() != WebCore::SessionState::Inactive) { errorString = ASCIILiteral("Can't modify a loaded session unless the session is inactive."); return; } session->insertSegment(segmentIndex, WTF::move(segment)); sessionModified(WTF::move(session)); }
void hdPolyLineFigure::splitSegment(int posIdx, int x, int y) { int index = findSegment(posIdx, x, y); if(index != -1) { insertPointAt(posIdx, index, x, y); } }
void InspectorReplayAgent::getSegmentData(ErrorString& errorString, Inspector::Protocol::Replay::SegmentIdentifier identifier, RefPtr<Inspector::Protocol::Replay::SessionSegment>& serializedObject) { RefPtr<ReplaySessionSegment> segment = findSegment(errorString, identifier); if (!segment) { errorString = ASCIILiteral("Couldn't find the specified segment."); return; } serializedObject = buildInspectorObjectForSegment(WTF::move(segment)); }
SPixelPosition CRecognition::findSegment(Mat *image) { SPixelPosition pos; CRawImage img(image->cols, image->rows); img.from_mat(image); pos = findSegment(&img); img.to_mat(*image); return pos; }
VML::Vector3 Vec3Linear::Interpolate(float t) const { assert(IsReady()); processTime(t); size_t segm = findSegment(t); const SKeyframeVec3& p0 = mKeyframes[segm]; const SKeyframeVec3& p1 = mKeyframes[segm + 1]; float u = (t - p0.time) / (p1.time - p0.time); return (p1.data - p0.data) * u + p0.data; }
virtual int tagLevel( const SegmenterPosition& segpos) const { try { typename SegmentMap::const_iterator segitr = findSegment( segpos); if (segitr == m_segmentmap.end()) { throw std::runtime_error( _TXT("segment with this position not defined")); } else { return segitr->second.taglevel; } } CATCH_ERROR_ARG1_MAP_RETURN( _TXT("error in get tag hierarchy level of '%s' segmenter markup context: %s"), "textwolf", *m_errorhnd, 0); }
/*********************************************************************************************************** * Controls the scheduling of the IDs in the filter. * *********************************************************************************************************/ int16 getNextSequenceIndex(Uint16 mailbox_num){ int16 sequenceIndex_next = -1; boolean_t searchResult = FALSE; Uint16 segment; segment = findSegment(mailbox_num); if(updateSequenceRequired_G != RUN){ /* Reset sequencePointer to continue sequence after loading mailbox */ segments[segment].sequenceIndex = (segments[segment].sequenceEnd-1); sequenceIndex_next = segments[segment].sequenceIndex; } else{ /* Find next required CAN ID in sequence */ sequenceIndex_next = segments[segment].sequenceIndex; do{ /* Wrap search */ if(sequenceIndex_next < segments[segment].sequenceEnd){ sequenceIndex_next++; } else{ sequenceIndex_next = segments[segment].sequenceStart; } /* ID not already in mailbox, decrement 'schedule' timer (timer sits between -DUPLICATES ALLOWED and 0 while ID is in one or more mailboxes) */ if(CAN_RxMessages_G[sequenceIndex_next].timer > (0-DUPLICATES_LIMIT)){ CAN_RxMessages_G[sequenceIndex_next].timer--; /* ID ready to be inserted */ if(CAN_RxMessages_G[sequenceIndex_next].timer <= 0){ searchResult = TRUE; } else{ searchResult = FALSE; /* ET balancing */ } } else{ searchResult = FALSE; /* ET balancing */ } } /* Search will abort if all messages have been checked */ while((searchResult == FALSE)&&(sequenceIndex_next != segments[segment].sequenceIndex)); segments[segment].sequenceIndex = sequenceIndex_next; } return sequenceIndex_next; }
SysStatus HATDefaultBase<ALLOC>::mapPage(uval physAddr, uval virtAddr, uval len, AccessMode::pageFaultInfo pfinfo, AccessMode::mode access, VPNum vp, uval wasMapped, uval createIfNoSeg) { uval pte_index, page_index; SegmentHATRef segmentHATRef; SegmentHAT * segmentHAT; SysStatus rc = 0; SegmentTable* segp; // Segment table for this vp AutoLock<LockType> al(&(byVP[vp].lock)); // record current pp on every call - may change on migration byVP[vp].pp = Scheduler::GetVP(); if ((rc = getSegmentTable(vp, segp))) return rc; pte_index = virtAddr >> LOG_SEGMENT_SIZE; page_index = (virtAddr & (SEGMENT_SIZE-1))>>LOG_PAGE_SIZE; if ((rc=findSegment(virtAddr, segmentHATRef, vp, createIfNoSeg))) { return rc; } segmentHAT = DREF(segmentHATRef); /* * It is possible for the segment to be UNMAPPED even though * we don't have a segmentFault indication - in which case * there will ultimately be another fault with the indication on * We test the indicator to optimize the normal case - the segment * is mapped and we don't need to map it again */ if (AccessMode::isSegmentFault(pfinfo)) { rc = segmentHAT->mapSegment(segp, virtAddr, len, vp); tassertWrn(!rc,"mapSegment failed in HATDefault\n"); if (rc) return rc; } rc = segmentHAT -> mapPage(physAddr, virtAddr, len, pfinfo, access, vp, wasMapped); return rc; }
virtual std::string tagName( const SegmenterPosition& segpos) const { try { typename SegmentMap::const_iterator segitr = findSegment( segpos); if (segitr == m_segmentmap.end()) { throw std::runtime_error( _TXT("segment with this position not defined")); } else { std::size_t tagidx = segitr->second.tagidx; return std::string( m_strings.c_str()+tagidx); } } CATCH_ERROR_ARG1_MAP_RETURN( _TXT("error in get tag name of '%s' segmenter markup context: %s"), "textwolf", *m_errorhnd, std::string()); }
VML::Vector3 Vec3CubicSpline::Interpolate(float t) const { assert(IsReady()); processTime(t); size_t segm = findSegment(t); size_t n_ctrl = mKeyframes.size(); const SKeyframeVec3& p0 = mKeyframes[segm]; const SKeyframeVec3& p1 = mKeyframes[segm + 1]; const VML::Vector3& t0 = mTangents[segm]; const VML::Vector3& t1 = mTangents[segm+1]; float u = (t - p0.time) / (p1.time - p0.time), u2 = u*u, u3 = u2*u; VML::Vector3 pos = p0.data*(2.0f*u3 - 3.0f*u2 + 1.0f) + p1.data*(-2.0f*u3 + 3.0f*u2) + t0*(u3 - 2.0f*u2 + u) + t1*(u3 - u2); return pos; }
VML::Vector3 Vec3CatmullRom::Interpolate(float t) const { assert(IsReady()); processTime(t); size_t segm = findSegment(t); size_t n_ctrl = mKeyframes.size(); const VML::Vector3& p0 = mKeyframes[segm].data; const VML::Vector3& p1 = mKeyframes[segm + 1].data; float time0 = mKeyframes[segm].time; float time1 = mKeyframes[segm + 1].time; VML::Vector3 t0(0); VML::Vector3 t1(0); if(segm > 0 && segm < n_ctrl - 2) { t0 = (p1 - mKeyframes[segm - 1].data) * 0.5f; t1 = (mKeyframes[segm + 2].data - p0) * 0.5f; } else if(segm == 0 && n_ctrl > 2) { t0 = (p1 + p1 - mKeyframes[segm + 2].data - p0) * 0.5f; t1 = (mKeyframes[segm + 2].data - p0) * 0.5f; } else if (segm == n_ctrl - 2 && n_ctrl > 2) { t0 = (p1 - mKeyframes[segm - 1].data) * 0.5f; t1 = - (p0 + p0 - mKeyframes[segm - 1].data - p1) * 0.5f; } float u = (t - time0) / (time1 - time0), u2 = u*u, u3 = u2*u; VML::Vector3 pos = p0*(2.0f*u3 - 3.0f*u2 + 1.0f) + p1*(-2.0f*u3 + 3.0f*u2) + t0*(u3 - 2.0f*u2 + u) + t1*(u3 - u2); return pos; }
void MHL7Compare::compareHL7() { MString segExist, segNew; int rExist = getFirstSegment(mMsgExist, segExist); if (!rExist) { cout << "Cannot access the first segment of the existing message" << endl; return; } int rNew = getFirstSegment(mMsgNew, segNew); if (!rNew) { cout << "MHL7Compare: Cannot access the first segment of the new message" << endl; return; } if (mSegInfo.empty()) { // no initialize file was provided. // Compare all the fields of all the segments do { if (segExist != segNew) { cout << "MHL7Compare: segments not in proper order" << endl; DIFF diff; diff.fldNum = 0; diff.existValue = segExist; diff.newValue = segNew; diff.comment = "Segment order does not match"; mDiff.insert (MDiff::value_type (segExist, diff) ); mCount++; break; } // endif //cout << "Comparing segments: " << segExist << " " << segNew << endl; char *name = segNew.strData(); if (!strcmp(name, "MSH")) compareMesgHeaders(); else if (!strcmp(name, "EVN")) compareEVNs(); else compareFields(segExist); // applies to any segment rExist = getNextSegment(mMsgExist, segExist); rNew = getNextSegment(mMsgNew, segNew); if (rExist != rNew) { cout << "MHL7Compare: One message is shorter than the other" << endl; DIFF diff; diff.fldNum = 0; diff.existValue = segExist; diff.newValue = segNew; diff.comment = "One message is shorter than the other"; mDiff.insert (MDiff::value_type (segExist, diff) ); mCount++; } } while (rExist && rNew); } // endif mSegInfo.empty() else { for (MSegmentInfo::iterator i = mSegInfo.begin(); i != mSegInfo.end(); i++) { segExist = (*i).first; // Go to beginning of message, and restart search. rNew = getFirstSegment(mMsgNew, segNew); rExist = getFirstSegment(mMsgExist, segNew); if (segNew != segExist) { segNew = segExist; rExist = findSegment(mMsgExist, segExist); rNew = findSegment(mMsgNew, segNew); } // Check all instances of segExist in mMsgExist and mMsgNew // Note: if a segment mentioned in the .ini file does not // exist in the existing file, there is no error. while(rExist || rNew) { // If a segment is not found in the new message, that exists in the // existing file, generate a difference. if (rExist && !rNew) { DIFF diff; diff.fldNum = 0; diff.existValue = segExist; diff.newValue = segNew; diff.comment = "New message is missing this segment"; mDiff.insert (MDiff::value_type (segExist, diff) ); mCount++; rNew = rExist = false; continue; } // If a segment exists in the new message, but not in the existing, // then generate an appropriate difference. if (!rExist && rNew) { DIFF diff; diff.fldNum = 0; diff.existValue = segExist; diff.newValue = segNew; diff.comment = "New message has too many segments of this type"; mDiff.insert (MDiff::value_type (segExist, diff) ); mCount++; rNew = rExist = false; continue; } // Find the difference(s) within existing segments compareFieldValues(segExist, ((*i).second).fldNum, ((*i).second).compNum, ((*i).second).subCompNum ); rExist = findSegment(mMsgExist, segExist); rNew = findSegment(mMsgNew, segExist); } // endwhile } // endfor } // endelse mSegInfo.empty() }
static orl_return applyBakpats( omf_file_handle ofh ) { omf_sec_handle sh; orl_return err = ORL_OKAY; omf_tmp_bkfix tbf; uint_8 *pfix8; uint_16 *pfix16; uint_32 *pfix32; assert( ofh ); assert( ofh->bakpat ); ofh->bakpat->last_fixup = NULL; /* Go through all the backpatches and update the segment data. The BAKPATs * aren't normal fixups and may modify all sorts of instructions. */ while( ofh->bakpat->first_fixup ) { tbf = ofh->bakpat->first_fixup; ofh->bakpat->first_fixup = tbf->next; assert( tbf->segidx || tbf->symidx ); if( tbf->segidx ) sh = findSegment( ofh, tbf->segidx ); else sh = findComDatByName( ofh, tbf->symidx ); if( !sh ) { err = ORL_ERROR; break; } switch( tbf->reltype ) { case ORL_RELOC_TYPE_WORD_8: pfix8 = sh->contents + tbf->offset; *pfix8 += tbf->disp; break; case ORL_RELOC_TYPE_WORD_16: pfix16 = (uint_16 *)(sh->contents + tbf->offset); *pfix16 += tbf->disp; break; case ORL_RELOC_TYPE_WORD_32: pfix32 = (uint_32 *)(sh->contents + tbf->offset); *pfix32 += tbf->disp; break; default: assert( 0 ); err = ORL_ERROR; break; } if( err != ORL_OKAY ) break; _ClientFree( ofh, tbf ); } assert( !(ofh->status & OMF_STATUS_ADD_BAKPAT) ); /* Free the entire bakpat structure as well. */ _ClientFree( ofh, ofh->bakpat ); ofh->bakpat = NULL; return( err ); }
void fill(const TRaster32P &ras, const TRaster32P &ref, const FillParameters ¶ms, TTileSaverFullColor *saver) { TPixel32 *pix, *limit, *pix0, *oldpix; int oldy, xa, xb, xc, xd, dy; int oldxc, oldxd; int matte, oldMatte; int x = params.m_p.x, y = params.m_p.y; TRaster32P workRas = ref ? ref : ras; TRect bbbox = workRas->getBounds(); if (!bbbox.contains(params.m_p)) return; TPaletteP plt = params.m_palette; TPixel32 color = plt->getStyle(params.m_styleId)->getMainColor(); int fillDepth = params.m_shiftFill ? params.m_maxFillDepth : params.m_minFillDepth; assert(fillDepth >= 0 && fillDepth < 16); fillDepth = ((15 - fillDepth) << 4) | (15 - fillDepth); // looking for any pure transparent pixel along the border; if after filling // that pixel will be changed, // it means that I filled the bg and the savebox needs to be recomputed! TPixel32 borderIndex; TPixel32 *borderPix = 0; pix = workRas->pixels(0); int i; for (i = 0; i < workRas->getLx(); i++, pix++) // border down if (pix->m == 0) { borderIndex = *pix; borderPix = pix; break; } if (borderPix == 0) // not found in border down...try border up (avoid left // and right borders...so unlikely) { pix = workRas->pixels(workRas->getLy() - 1); for (i = 0; i < workRas->getLx(); i++, pix++) // border up if (pix->m == 0) { borderIndex = *pix; borderPix = pix; break; } } std::stack<FillSeed> seeds; std::map<int, std::vector<std::pair<int, int>>> segments; // fillRow(r, params.m_p, xa, xb, color ,saver); findSegment(workRas, params.m_p, xa, xb, color); segments[y].push_back(std::pair<int, int>(xa, xb)); seeds.push(FillSeed(xa, xb, y, 1)); seeds.push(FillSeed(xa, xb, y, -1)); while (!seeds.empty()) { FillSeed fs = seeds.top(); seeds.pop(); xa = fs.m_xa; xb = fs.m_xb; oldy = fs.m_y; dy = fs.m_dy; y = oldy + dy; if (y > bbbox.y1 || y < bbbox.y0) continue; pix = pix0 = workRas->pixels(y) + xa; limit = workRas->pixels(y) + xb; oldpix = workRas->pixels(oldy) + xa; x = xa; oldxd = (std::numeric_limits<int>::min)(); oldxc = (std::numeric_limits<int>::max)(); while (pix <= limit) { oldMatte = threshMatte(oldpix->m, fillDepth); matte = threshMatte(pix->m, fillDepth); bool test = false; if (segments.find(y) != segments.end()) test = isPixelInSegment(segments[y], x); if (*pix != color && !test && matte >= oldMatte && matte != 255) { findSegment(workRas, TPoint(x, y), xc, xd, color); // segments[y].push_back(std::pair<int,int>(xc, xd)); insertSegment(segments[y], std::pair<int, int>(xc, xd)); if (xc < xa) seeds.push(FillSeed(xc, xa - 1, y, -dy)); if (xd > xb) seeds.push(FillSeed(xb + 1, xd, y, -dy)); if (oldxd >= xc - 1) oldxd = xd; else { if (oldxd >= 0) seeds.push(FillSeed(oldxc, oldxd, y, dy)); oldxc = xc; oldxd = xd; } pix += xd - x + 1; oldpix += xd - x + 1; x += xd - x + 1; } else { pix++; oldpix++, x++; } } if (oldxd > 0) seeds.push(FillSeed(oldxc, oldxd, y, dy)); } std::map<int, std::vector<std::pair<int, int>>>::iterator it; for (it = segments.begin(); it != segments.end(); it++) { TPixel32 *line = ras->pixels(it->first); TPixel32 *refLine = 0; TPixel32 *refPix; if (ref) refLine = ref->pixels(it->first); std::vector<std::pair<int, int>> segmentVector = it->second; for (int i = 0; i < (int)segmentVector.size(); i++) { std::pair<int, int> segment = segmentVector[i]; if (segment.second >= segment.first) { pix = line + segment.first; if (ref) refPix = refLine + segment.first; int n; for (n = 0; n < segment.second - segment.first + 1; n++, pix++) { if (ref) { *pix = *refPix; refPix++; } else *pix = pix->m == 0 ? color : overPix(color, *pix); } } } } }