bool nsVoidArray::GrowArrayBy(int32_t aGrowBy) { // We have to grow the array. Grow by kMinGrowArrayBy slots if we're // smaller than kLinearThreshold bytes, or a power of two if we're // larger. This is much more efficient with most memory allocators, // especially if it's very large, or of the allocator is binned. if (aGrowBy < kMinGrowArrayBy) aGrowBy = kMinGrowArrayBy; uint32_t newCapacity = GetArraySize() + aGrowBy; // Minimum increase uint32_t newSize = SIZEOF_IMPL(newCapacity); if (newSize >= (uint32_t) kLinearThreshold) { // newCount includes enough space for at least kMinGrowArrayBy new // slots. Select the next power-of-two size in bytes above or // equal to that. // Also, limit the increase in size to about a VM page or two. if (GetArraySize() >= kMaxGrowArrayBy) { newCapacity = GetArraySize() + XPCOM_MAX(kMaxGrowArrayBy,aGrowBy); newSize = SIZEOF_IMPL(newCapacity); } else { newSize = mozilla::CeilingLog2(newSize); newCapacity = CAPACITYOF_IMPL(1u << newSize); } } // frees old mImpl IF this succeeds if (!SizeTo(newCapacity)) return false; return true; }
PRBool nsVoidArray::GrowArrayBy(PRInt32 aGrowBy) { // We have to grow the array. Grow by kMinGrowArrayBy slots if we're // smaller than kLinearThreshold bytes, or a power of two if we're // larger. This is much more efficient with most memory allocators, // especially if it's very large, or of the allocator is binned. if (aGrowBy < kMinGrowArrayBy) aGrowBy = kMinGrowArrayBy; PRUint32 newCapacity = GetArraySize() + aGrowBy; // Minimum increase PRUint32 newSize = SIZEOF_IMPL(newCapacity); if (newSize >= (PRUint32) kLinearThreshold) { // newCount includes enough space for at least kMinGrowArrayBy new // slots. Select the next power-of-two size in bytes above or // equal to that. // Also, limit the increase in size to about a VM page or two. if (GetArraySize() >= kMaxGrowArrayBy) { newCapacity = GetArraySize() + PR_MAX(kMaxGrowArrayBy,aGrowBy); newSize = SIZEOF_IMPL(newCapacity); } else { PR_CEILING_LOG2(newSize, newSize); newCapacity = CAPACITYOF_IMPL(PR_BIT(newSize)); } } // frees old mImpl IF this succeeds if (!SizeTo(newCapacity)) return PR_FALSE; return PR_TRUE; }
int SegForEachFromBG(IplImage* srcImage,int** regionindex,int BKGrayValue,int difference,vector<REGION>& vec) { int direction[8][2] = { {-1,0},{-1,1},{0,1},{1,1} ,{1,0},{1,-1},{0,-1},{-1,-1}}; // 在图像中顺时针旋转 int i,j,k; int delta=0; for(i=1;i<vec.size();++i) { if(vec[i].region.size()>75*75) continue; for(j=0;j<vec[i].contour.size();++j) { queue<CvPoint> q; q.push(vec[i].contour[j]); while (!q.empty()) { CvPoint pt=q.front(); q.pop(); for(k=0;k<GetArraySize(direction);k+=GetArraySize(direction)/4) { int m=pt.y+direction[k][0]; int n=pt.x+direction[k][1]; if(IsLegalCoordinate(m,n,srcImage) == false) continue; if(regionindex[m][n] != -1) continue; int val=(unsigned char)srcImage->imageData[m*srcImage->widthStep+n]; if(val>=BKGrayValue-difference) continue; vector<CvPoint> temp; SearchIllegalNearPoint(srcImage,regionindex,regionindex[pt.y][pt.x] ,BKGrayValue,difference,cvPoint(n,m),temp); if(temp.empty()) { ++delta; regionindex[m][n] = regionindex[pt.y][pt.x]; vec[regionindex[m][n]].region.push_back(cvPoint(n,m)); q.push(cvPoint(n,m)); } } } } } for(i=1;i<vec.size();++i) { vec[i].contour.clear(); FindRegionContour(regionindex,srcImage->height,srcImage->width, vec[i].region,vec[i].contour); } return delta; }
void GroupOfPlanes::RecalculateMVs(MVClip &mvClip, MVGroupOfFrames *pSrcGOF, MVGroupOfFrames *pRefGOF, SearchType searchType, int nSearchParam, int nLambda, int lsad, int pnew, int flags, int *out, short *outfilebuf, int fieldShift, int thSAD, DCTClass * _DCT, int smooth) { // int i; nFlags |= flags; // write group's size out[0] = GetArraySize(); // write validity : 1 in that case out[1] = 1; out += 2; int meanLumaChange = 0; // Search the motion vectors, for the low details interpolations first // Refining the search until we reach the highest detail interpolation. // DebugPrintf("SearchMV level %i", nLevelCount-1); planes[0]->RecalculateMVs(mvClip, pSrcGOF->GetFrame(0), pRefGOF->GetFrame(0), searchType, nSearchParam, nLambda, lsad, pnew, flags, out, outfilebuf, fieldShift, thSAD, _DCT, divideExtra, smooth); out += planes[0]->GetArraySize(divideExtra); }
void GroupOfPlanes::SearchMVs(MVGroupOfFrames *pSrcGOF, MVGroupOfFrames *pRefGOF, SearchType searchType, int nSearchParam, int nPelSearch, int nLambda, int lsad, int pnew, int plevel, bool global, int flags, int *out, short *outfilebuf, int fieldShift, DCTClass * _DCT, int pzero, int pglobal, int badSAD, int badrange) { int i; nFlags |= flags; // write group's size out[0] = GetArraySize(); // write validity : 1 in that case out[1] = 1; out += 2; int fieldShiftCur = (nLevelCount - 1 == 0) ? fieldShift : 0; // may be non zero for finest level only VECTOR globalMV; // create and init global motion vector as zero globalMV.x = zeroMV.x; globalMV.y = zeroMV.y; globalMV.sad = zeroMV.sad; if (!global) pglobal = pzero; int meanLumaChange = 0; // Search the motion vectors, for the low details interpolations first // Refining the search until we reach the highest detail interpolation. // DebugPrintf("SearchMV level %i", nLevelCount-1); planes[nLevelCount - 1]->SearchMVs(pSrcGOF->GetFrame(nLevelCount-1), pRefGOF->GetFrame(nLevelCount-1), searchType, nSearchParam, nLambda, lsad, pnew, plevel, flags, out, &globalMV, outfilebuf, fieldShiftCur, _DCT, &meanLumaChange, divideExtra, pzero, pglobal, badSAD, badrange); out += planes[nLevelCount - 1]->GetArraySize(divideExtra); for ( i = nLevelCount - 2; i >= 0; i-- ) { int nSearchParamLevel = (i==0) ? nPelSearch : nSearchParam; // special case for finest level PROFILE_START(MOTION_PROFILE_PREDICTION); if (global) { planes[i+1]->EstimateGlobalMVDoubled(&globalMV); // get updated global MV (doubled) // DebugPrintf("SearchMV globalMV %i, %i", globalMV.x, globalMV.y); } planes[i]->InterpolatePrediction(*(planes[i+1])); PROFILE_STOP(MOTION_PROFILE_PREDICTION); fieldShiftCur = (i == 0) ? fieldShift : 0; // may be non zero for finest level only // DebugPrintf("SearchMV level %i", i); planes[i]->SearchMVs(pSrcGOF->GetFrame(i), pRefGOF->GetFrame(i), searchType, nSearchParamLevel, nLambda, lsad, pnew, plevel, flags, out, &globalMV, outfilebuf, fieldShiftCur, _DCT, &meanLumaChange, divideExtra, pzero, pglobal, badSAD, badrange); out += planes[i]->GetArraySize(divideExtra); } }
//------------------------------------------------------------------- bool cpp_xloper::Transpose(void) { if(!IsType(xltypeMulti)) return false; WORD r, c, rows, columns; GetArraySize(rows, columns); xloper *new_array = (xloper *)malloc(sizeof(xloper) * rows * columns); xloper *p_source = m_Op.val.array.lparray; int new_index; for(r = 0; r < rows; r++) { new_index = r; for(c = 0; c < columns; c++, new_index += rows) { new_array[new_index] = *p_source++; } } r = m_Op.val.array.columns; m_Op.val.array.columns = m_Op.val.array.rows; m_Op.val.array.rows = r; memcpy(m_Op.val.array.lparray, new_array, sizeof(xloper) * rows * columns); free(new_array); return true; }
void SearchIllegalNearPoint(IplImage* srcImage,int** regionindex,int index,int BGvalue ,int difference,const CvPoint& pt,vector<CvPoint>& vec) { int i,j; int direction[8][2] = {{-1,0},{-1,1},{0,1},{1,1},{1,0},{1,-1},{0,-1},{-1,-1}}; // 在图像中顺时针旋转 for(int k=0;k<GetArraySize(direction);k+=GetArraySize(direction)/8) { i=pt.y + direction[k][0]; j=pt.x + direction[k][1]; if(IsLegalCoordinate(i,j,srcImage) == false) continue; int val2=(unsigned char)srcImage->imageData[i*srcImage->widthStep+j]; if(val2+difference >= BGvalue) continue; if(regionindex[i][j] != -1 && regionindex[i][j]!=index) vec.push_back(cvPoint(j,i)); } }
void FindRegionContour(IplImage* binaryimage,vector<REGION>& vec) { Deburr(binaryimage); int dir[4][2]={{1,0},{0,1},{-1,0},{0,-1}}; int i,j,k; bool** flag=new bool*[binaryimage->height]; for(i=0;i<binaryimage->height;++i) { flag[i]=new bool[binaryimage->width]; memset(flag[i],false,sizeof(false)*binaryimage->width); } for(i=0;i<binaryimage->height;++i) { for(j=0;j<binaryimage->width;++j) { if((unsigned char)binaryimage->imageData[i*binaryimage->widthStep+j]!=(unsigned char)0) continue; if(flag[i][j]) continue; queue<CvPoint> temp; REGION region; temp.push(cvPoint(j,i)); flag[i][j]=true; while (!temp.empty()) { CvPoint pt=temp.front(); temp.pop(); region.region.push_back(pt); for(k=0;k<GetArraySize(dir);++k) { int m=pt.y+dir[k][0]; int n=pt.x+dir[k][1]; if(m<0 || m>=binaryimage->height || n<0 || n>=binaryimage->width) continue; if((unsigned char)binaryimage->imageData[m*binaryimage->widthStep+n]!=0) continue; if(flag[m][n]) continue; temp.push(cvPoint(n,m)); flag[m][n]=true; } } int sumX=0,sumY=0; for(k=0;k<region.region.size();++k) if(IsBoundary(binaryimage,region.region[k])) { region.contour.push_back(region.region[k]); sumX+=region.region[k].x; sumY+=region.region[k].y; } region.centerpoint.x=sumX/region.contour.size(); region.centerpoint.y=sumY/region.contour.size(); vec.push_back(region); } } for(i=0;i<binaryimage->height;++i) delete [](flag[i]); delete []flag; }
void DeleteSmallBlackRegion(IplImage* sourceImage,size_t num) { int dir[4][2]={{1,0},{0,1},{-1,0},{0,-1}}; vector< vector<CvPoint> > regions; vector<CvPoint> temp; int i,j; bool** flag; // need to be released flag= new bool*[sourceImage->height]; for(i=0;i<sourceImage->height;++i) { flag[i]=new bool[sourceImage->width]; memset(flag[i],false,sizeof(bool)*sourceImage->width); } for(i=0;i<sourceImage->height;++i) for(j=0;j<sourceImage->width;++j) { if(flag[i][j]) continue; int val=(unsigned char)sourceImage->imageData[i*sourceImage->widthStep+j]; if(val == 255) continue; queue<CvPoint> q; flag[i][j]=true; q.push(cvPoint(j,i)); temp.clear(); while (!q.empty()) { CvPoint pt=q.front(); temp.push_back(pt); q.pop(); for(int k=0;k<GetArraySize(dir);++k) { int m=pt.y+dir[k][0]; int n=pt.x+dir[k][1]; if(m<0 || m>= sourceImage->height || n<0 || n>=sourceImage->width ) continue; int val=(unsigned char)sourceImage->imageData[m*sourceImage->widthStep+n]; if( flag[m][n] || val == 255 ) continue; flag[m][n]=true; q.push(cvPoint(n,m)); } } int sz=temp.size(); if( temp.size() < num ) regions.push_back(temp); } for(i=0;i<regions.size();++i) { for(j=0;j<regions[i].size();++j) sourceImage->imageData[regions[i][j].y * sourceImage->widthStep+regions[i][j].x]=(unsigned char)255; } for(i=0;i<sourceImage->height;++i) delete [] flag[i]; delete []flag; }
void Scr_AddArray() { scrVmPub_t* scrVmPub_t = scrVmPub; scrVmPub_t->top--; scrVmPub_t->inparamcount--; unsigned int parentId = scrVmPub_t->top->u.intValue; //the array parentId unsigned int id = GetNewArrayVariable(parentId, GetArraySize(parentId)); //not sure what that even does, I think it gets the next index in the array VariableValue* top = scrVmPub_t->top; SetNewVariableValue(parentId, id, top + 1); }
void FindRegionContour(int** regionindex,int ROW,int COL,const vector<CvPoint>& region,vector<CvPoint>& contour) { int direction[8][2] = {{-1,0},{-1,1},{0,1},{1,1},{1,0},{1,-1},{0,-1},{-1,-1}}; // 在图像中顺时针旋转 for(int k=0;k<region.size();++k) { CvPoint pt=region[k]; for(int dir=0;dir<GetArraySize(direction);dir+=GetArraySize(direction)/4) { int m=pt.y+direction[dir][0]; int n=pt.x+direction[dir][1]; if(m<0||n<0||m>=ROW||n>=COL) break; if(regionindex[m][n] != regionindex[pt.y][pt.x]) break; } if(dir<GetArraySize(direction)) contour.push_back(pt); } }
void nsVoidArray::Compact() { if (mImpl) { // XXX NOTE: this is quite inefficient in many cases if we're only // compacting by a little, but some callers care more about memory use. int32_t count = Count(); if (GetArraySize() > count) { SizeTo(Count()); } } }
void nsVoidArray::Clear() { if (mImpl) { mImpl->mCount = 0; // We don't have to free on Clear, but if we have a built-in buffer, // it's worth considering. if (HasAutoBuffer() && IsArrayOwner() && GetArraySize() > kAutoClearCompactSizeFactor * kAutoBufSize) { SizeTo(0); } } }
PRBool nsVoidArray::ReplaceElementAt(void* aElement, PRInt32 aIndex) { NS_ASSERTION(aIndex >= 0,"ReplaceElementAt(negative index)"); if (aIndex < 0) return PR_FALSE; // Unlike InsertElementAt, ReplaceElementAt can implicitly add more // than just the one element to the array. if (PRUint32(aIndex) >= PRUint32(GetArraySize())) { PRInt32 oldCount = Count(); PRInt32 requestedCount = aIndex + 1; PRInt32 growDelta = requestedCount - oldCount; // frees old mImpl IF this succeeds if (!GrowArrayBy(growDelta)) return PR_FALSE; } mImpl->mArray[aIndex] = aElement; if (aIndex >= mImpl->mCount) { // Make sure that any entries implicitly added to the array by this // ReplaceElementAt are cleared to 0. Some users of this assume that. // This code means we don't have to memset when we allocate an array. if (aIndex > mImpl->mCount) // note: not >= { // For example, if mCount is 2, and we do a ReplaceElementAt for // element[5], then we need to set three entries ([2], [3], and [4]) // to 0. memset(&mImpl->mArray[mImpl->mCount], 0, (aIndex - mImpl->mCount) * sizeof(mImpl->mArray[0])); } mImpl->mCount = aIndex + 1; #if DEBUG_VOIDARRAY if (mImpl->mCount > mMaxCount && mImpl->mCount < (PRInt32)(sizeof(MaxElements)/sizeof(MaxElements[0]))) { MaxElements[mImpl->mCount]++; MaxElements[mMaxCount]--; mMaxCount = mImpl->mCount; } #endif } return PR_TRUE; }
void GroupOfPlanes::WriteDefaultToArray(int *array) { // write group's size array[0] = GetArraySize(); // write validity : unvalid in that case array[1] = 0; array += 2; // write planes for (int i = nLevelCount - 1; i >= 0; --i ) { array += planes[i]->WriteDefaultToArray(array, divideExtra); } }
PRBool nsVoidArray::InsertElementsAt(const nsVoidArray& other, PRInt32 aIndex) { PRInt32 oldCount = Count(); PRInt32 otherCount = other.Count(); NS_ASSERTION(aIndex >= 0,"InsertElementsAt(negative index)"); if (PRUint32(aIndex) > PRUint32(oldCount)) { // An invalid index causes the insertion to fail // Invalid indexes are ones that are more than one entry past the end of // the array (i.e., they can append). return PR_FALSE; } if (oldCount + otherCount > GetArraySize()) { if (!GrowArrayBy(otherCount)) return PR_FALSE;; } // else the array is already large enough PRInt32 slide = oldCount - aIndex; if (0 != slide) { // Slide data over to make room for the insertion memmove(mImpl->mArray + aIndex + otherCount, mImpl->mArray + aIndex, slide * sizeof(mImpl->mArray[0])); } for (PRInt32 i = 0; i < otherCount; i++) { // copy all the elements (destroys aIndex) mImpl->mArray[aIndex++] = other.mImpl->mArray[i]; mImpl->mCount++; } #if DEBUG_VOIDARRAY if (mImpl->mCount > mMaxCount && mImpl->mCount < (PRInt32)(sizeof(MaxElements)/sizeof(MaxElements[0]))) { MaxElements[mImpl->mCount]++; MaxElements[mMaxCount]--; mMaxCount = mImpl->mCount; } #endif return PR_TRUE; }
bool IsBoundary(IplImage* srcImage,CvPoint pt) { int dir[4][2]={{1,0},{0,1},{-1,0},{0,-1}}; int val=(unsigned char)srcImage->imageData[pt.y*srcImage->widthStep+pt.x]; if(val == 255 ) return false; for(int i=0;i<GetArraySize(dir);++i) { int m=pt.y+dir[i][0]; int n=pt.x+dir[i][1]; if(m<0 || m>= srcImage->height || n<0 || n>=srcImage->width) // 下标不合法 return true; val=(unsigned char)srcImage->imageData[m*srcImage->widthStep+n]; if(val == 255) { return true;} } return false; }
//------------------------------------------------------------------------------ const Struct * ReflectedPropertyStruct::GetStructInArray( const void * object, size_t index ) const { // sanity checks ASSERT( IsArray() ); ASSERT( GetType() == PT_STRUCT ); ASSERT( index < GetArraySize( object ) ); // get the array const size_t elementSize = GetPropertySize(); const void * arrayBase = (const void *)( (size_t)object + m_Offset ); const Array< char > * array = static_cast< const Array< char > * >( arrayBase ); // calculate the element offset const size_t offset = ( index * elementSize ); return reinterpret_cast< Struct * >( array->Begin() + offset ); }
PRBool nsVoidArray::SetCount(PRInt32 aNewCount) { NS_ASSERTION(aNewCount >= 0,"SetCount(negative index)"); if (aNewCount < 0) return PR_FALSE; if (aNewCount == 0) { Clear(); return PR_TRUE; } if (PRUint32(aNewCount) > PRUint32(GetArraySize())) { PRInt32 oldCount = Count(); PRInt32 growDelta = aNewCount - oldCount; // frees old mImpl IF this succeeds if (!GrowArrayBy(growDelta)) return PR_FALSE; } if (aNewCount > mImpl->mCount) { // Make sure that new entries added to the array by this // SetCount are cleared to 0. Some users of this assume that. // This code means we don't have to memset when we allocate an array. memset(&mImpl->mArray[mImpl->mCount], 0, (aNewCount - mImpl->mCount) * sizeof(mImpl->mArray[0])); } mImpl->mCount = aNewCount; #if DEBUG_VOIDARRAY if (mImpl->mCount > mMaxCount && mImpl->mCount < (PRInt32)(sizeof(MaxElements)/sizeof(MaxElements[0]))) { MaxElements[mImpl->mCount]++; MaxElements[mMaxCount]--; mMaxCount = mImpl->mCount; } #endif return PR_TRUE; }
nsVoidArray& nsVoidArray::operator=(const nsVoidArray& other) { PRInt32 otherCount = other.Count(); PRInt32 maxCount = GetArraySize(); if (otherCount) { if (otherCount > maxCount) { // frees old mImpl IF this succeeds if (!GrowArrayBy(otherCount-maxCount)) return *this; // XXX The allocation failed - don't do anything memcpy(mImpl->mArray, other.mImpl->mArray, otherCount * sizeof(mImpl->mArray[0])); mImpl->mCount = otherCount; } else { // the old array can hold the new array memcpy(mImpl->mArray, other.mImpl->mArray, otherCount * sizeof(mImpl->mArray[0])); mImpl->mCount = otherCount; // if it shrank a lot, compact it anyways if ((otherCount*2) < maxCount && maxCount > 100) { Compact(); // shrank by at least 50 entries } } #if DEBUG_VOIDARRAY if (mImpl->mCount > mMaxCount && mImpl->mCount < (PRInt32)(sizeof(MaxElements)/sizeof(MaxElements[0]))) { MaxElements[mImpl->mCount]++; MaxElements[mMaxCount]--; mMaxCount = mImpl->mCount; } #endif } else { // Why do we drop the buffer here when we don't in Clear()? SizeTo(0); } return *this; }
PRBool nsVoidArray::InsertElementAt(void* aElement, PRInt32 aIndex) { PRInt32 oldCount = Count(); NS_ASSERTION(aIndex >= 0,"InsertElementAt(negative index)"); if (PRUint32(aIndex) > PRUint32(oldCount)) { // An invalid index causes the insertion to fail // Invalid indexes are ones that add more than one entry to the // array (i.e., they can append). return PR_FALSE; } if (oldCount >= GetArraySize()) { if (!GrowArrayBy(1)) return PR_FALSE; } // else the array is already large enough PRInt32 slide = oldCount - aIndex; if (0 != slide) { // Slide data over to make room for the insertion memmove(mImpl->mArray + aIndex + 1, mImpl->mArray + aIndex, slide * sizeof(mImpl->mArray[0])); } mImpl->mArray[aIndex] = aElement; mImpl->mCount++; #if DEBUG_VOIDARRAY if (mImpl->mCount > mMaxCount && mImpl->mCount < (PRInt32)(sizeof(MaxElements)/sizeof(MaxElements[0]))) { MaxElements[mImpl->mCount]++; MaxElements[mMaxCount]--; mMaxCount = mImpl->mCount; } #endif return PR_TRUE; }
nsSmallVoidArray& nsSmallVoidArray::operator=(nsSmallVoidArray& other) { PRInt32 count = other.Count(); switch (count) { case 0: Clear(); break; case 1: Clear(); AppendElement(other.ElementAt(0)); break; default: if (GetArraySize() >= count || SizeTo(count)) { *AsArray() = *other.AsArray(); } } return *this; }
void nsVoidArray::Compact() { if (mImpl) { // XXX NOTE: this is quite inefficient in many cases if we're only // compacting by a little, but some callers care more about memory use. PRInt32 count = Count(); if (HasAutoBuffer() && count <= kAutoBufSize) { Impl* oldImpl = mImpl; static_cast<nsAutoVoidArray*>(this)->ResetToAutoBuffer(); memcpy(mImpl->mArray, oldImpl->mArray, count * sizeof(mImpl->mArray[0])); free(reinterpret_cast<char *>(oldImpl)); } else if (GetArraySize() > count) { SizeTo(Count()); } } }
// Makes sure the array has enought capacity to hold at least size elements StaticArrayAdjuster& EnsureHasCapacityFor(size_t size) { if(size >= GetArraySize()) GrowArray(); return *this; }
static void InitTypeHandle( imp_image_handle *ii, imp_type_handle *it, location_context *lc ) { /***********************************************************************/ //Set type handle to the base state //If array poise at first index imp_type_handle sub; dr_array_info info; dr_handle btype; dr_array_stat stat; uint_32 base_stride; uint_32 n_el; if( it->state == DF_NOT ) { DRSetDebug( ii->dwarf->handle ); /* must do at each call into dwarf */ DRGetTypeInfo( it->type, &it->typeinfo ); it->state = DF_SET; it->sub_array = FALSE; if( it->typeinfo.kind == DR_TYPEK_ARRAY ) { if( it->typeinfo.size == 0 ) { btype = DRSkipTypeChain( it->type ); /* skip modifiers and typedefs */ stat = DRGetArrayInfo( btype, &info ); if( stat & DR_ARRAY_STRIDE_SIZE ) { base_stride = info.stride_size/8; } else { btype = DRGetTypeAT( btype ); /* get base type */ sub.type = btype; sub.im = it->im; sub.state = DF_NOT; InitTypeHandle( ii, &sub, lc ); base_stride = sub.typeinfo.size; } it->array.base_stride = base_stride; it->array.column_major = 0; /* 1 for fortran */ if( stat & DR_ARRAY_ORDERING ) { if( info.ordering == DW_ORD_col_major ) { it->array.column_major = 1; } } else if( IMH2MODI( ii, it->im )->lang == DR_LANG_FORTRAN ) { it->array.column_major = 1; } if( info.child == DR_HANDLE_NUL ) { // set info now it->array.dims = 1; it->array.low = 0; it->array.index = DR_HANDLE_NUL; if( stat & DR_ARRAY_COUNT ) { if( info.count == 0 ) { // ie char (*x)[] info.count = 1; } it->typeinfo.size = info.count * it->array.base_stride; it->array.num_elts= info.count; } else { it->typeinfo.size = it->array.base_stride; } if( !it->array.column_major ) { base_stride = it->typeinfo.size; n_el = it->array.num_elts; base_stride = n_el ? base_stride / n_el : 0; it->array.base_stride = base_stride; } it->array.is_set = TRUE; it->array.is_based = FALSE; it->sub_array = FALSE; } else { it->sub_array = TRUE; it->array.is_set = FALSE; it->array.index = GetArrayDim( info.child, 0 ); } } } else if( it->typeinfo.kind == DR_TYPEK_STRING ) { if( DRStringLengthAT( it->type ) ) { if( !GetStrLen( ii, it->type, lc, &it->typeinfo ) ) { it->typeinfo.size = 1; } } } } if( it->typeinfo.kind == DR_TYPEK_ARRAY ) { if( !it->array.is_set ) { GetArraySize( ii, it, lc ); } else if( it->array.is_based ) { GetArraySubSize( ii, it, lc ); } } }
void DeleteAll8TypeArea(IplImage* srcImage,IplImage* binaryImage,vector< vector<CvPoint> >& AllOutline) { int i,j,k,m,n; int direction[8][2] = {{-1,0},{-1,1},{0,1},{1,1},{1,0},{1,-1},{0,-1},{-1,-1}}; // 在图像中顺时针旋转 bool **flag; // need to be released flag=new bool*[binaryImage->height]; for(i=0;i<binaryImage->height;++i) { flag[i]=new bool[binaryImage->width]; memset(flag[i],false,sizeof(bool)*binaryImage->width); } for(i=0;i<binaryImage->height;++i) { for(j=0;j<binaryImage->width;++j) { int val=(byte)binaryImage->imageData[i*binaryImage->widthStep+j]; if(val!=0) continue; for(k=0;k<GetArraySize(direction);++k) { int m=i+direction[k][0]; int n=j+direction[k][1]; if(m<0||n<0||m>=binaryImage->height||n>=binaryImage->width) continue; val=(byte)binaryImage->imageData[m*binaryImage->widthStep+n]; if(val==0) break; } if(k==GetArraySize(direction)) binaryImage->imageData[i*binaryImage->widthStep+j]=(unsigned char)255; } } for(i=0;i<binaryImage->height;++i) for(j=0;j<binaryImage->width;++j) { if(IsBoundary(binaryImage,cvPoint(j,i)) == false ) continue; if(flag[i][j]) continue; vector<CvPoint> outline; outline.push_back(cvPoint(j,i)); flag[i][j] = true; CvPoint StartPoint=cvPoint(j,i); int preDir=0; while ( !outline.empty() ) { CvPoint pt=outline.back(); int times; for(k=preDir,times=0;times<GetArraySize(direction);k=(k+1)%GetArraySize(direction),++times) { m=pt.y+direction[k][0]; n=pt.x+direction[k][1]; if(m<0||m>=binaryImage->height || n<0 || n>= binaryImage->width) continue; int val=(unsigned char)binaryImage->imageData[m*binaryImage->widthStep+n]; if(val == 255) continue; if(flag[m][n] == false) { outline.push_back(cvPoint(n,m)); flag[m][n]=true; preDir=k-GetArraySize(direction)/4; preDir=(preDir+GetArraySize(direction))%GetArraySize(direction); break; } if( cvPoint(n,m)== StartPoint ) { AllOutline.push_back(outline); { for(int i=0;i<outline.size();++i) { CvPoint pt=outline[i]; srcImage->imageData[pt.y*srcImage->widthStep+pt.x]=0; } printf("first point:%d %d\n",outline[0].y,outline[0].x); cvShowImage("srcImage2",srcImage); cvWaitKey(); } outline.clear(); break; } else { vector<CvPoint> SmallOutline; CvPoint temp=outline.back(); vector<CvPoint>::reverse_iterator rit=outline.rbegin(); while (*rit != temp) ++rit; copy(outline.rbegin(),rit,back_insert_iterator< vector<CvPoint> >(SmallOutline)); if(SmallOutline.size()>1) { AllOutline.push_back(SmallOutline); for(int i=0;i<SmallOutline.size();++i) { CvPoint pt=SmallOutline[i]; srcImage->imageData[pt.y*srcImage->widthStep+pt.x]=0; } printf("first point:%d %d\n",SmallOutline[0].y,SmallOutline[0].x); cvShowImage("srcImage2",srcImage); cvWaitKey(); } outline.erase((++rit).base(),outline.end()); binaryImage->imageData[temp.y*binaryImage->widthStep+temp.x]=(unsigned char)255; break; } } } } for(i=0;i<binaryImage->height;++i) delete [](flag[i]); delete []flag; }
// Grows the array by 100% void GrowArray() { RellocArray(GetArraySize() * 2); }
// This does all allocation/reallocation of the array. // It also will compact down to N - good for things that might grow a lot // at times, but usually are smaller, like JS deferred GC releases. PRBool nsVoidArray::SizeTo(PRInt32 aSize) { PRUint32 oldsize = GetArraySize(); PRBool isOwner = IsArrayOwner(); PRBool hasAuto = HasAutoBuffer(); if (aSize == (PRInt32) oldsize) return PR_TRUE; // no change if (aSize <= 0) { // free the array if allocated if (mImpl) { if (isOwner) { free(reinterpret_cast<char *>(mImpl)); if (hasAuto) { static_cast<nsAutoVoidArray*>(this)->ResetToAutoBuffer(); } else { mImpl = nsnull; } } else { mImpl->mCount = 0; // nsAutoVoidArray } } return PR_TRUE; } if (mImpl && isOwner) { // We currently own an array impl. Resize it appropriately. if (aSize < mImpl->mCount) { // XXX Note: we could also just resize to mCount return PR_TRUE; // can't make it that small, ignore request } char* bytes = (char *) realloc(mImpl,SIZEOF_IMPL(aSize)); Impl* newImpl = reinterpret_cast<Impl*>(bytes); if (!newImpl) return PR_FALSE; #if DEBUG_VOIDARRAY if (mImpl == newImpl) ADD_TO_STATS(GrowInPlace,oldsize); ADD_TO_STATS(AllocedOfSize,SIZEOF_IMPL(aSize)); if (aSize > mMaxSize) { ADD_TO_STATS(NumberOfSize,SIZEOF_IMPL(aSize)); if (oldsize) SUB_FROM_STATS(NumberOfSize,oldsize); mMaxSize = aSize; if (mIsAuto) { ADD_TO_STATS(MaxAuto,SIZEOF_IMPL(aSize)); SUB_FROM_STATS(MaxAuto,oldsize); } } #endif SetArray(newImpl, aSize, newImpl->mCount, PR_TRUE, hasAuto); return PR_TRUE; } if ((PRUint32) aSize < oldsize) { // No point in allocating if it won't free the current Impl anyway. return PR_TRUE; } // just allocate an array // allocate the exact size requested char* bytes = (char *) malloc(SIZEOF_IMPL(aSize)); Impl* newImpl = reinterpret_cast<Impl*>(bytes); if (!newImpl) return PR_FALSE; #if DEBUG_VOIDARRAY ADD_TO_STATS(AllocedOfSize,SIZEOF_IMPL(aSize)); if (aSize > mMaxSize) { ADD_TO_STATS(NumberOfSize,SIZEOF_IMPL(aSize)); if (oldsize && !mImpl) SUB_FROM_STATS(NumberOfSize,oldsize); mMaxSize = aSize; } #endif if (mImpl) { #if DEBUG_VOIDARRAY ADD_TO_STATS(MaxAuto,SIZEOF_IMPL(aSize)); SUB_FROM_STATS(MaxAuto,0); SUB_FROM_STATS(NumberOfSize,0); mIsAuto = PR_TRUE; #endif // We must be growing an nsAutoVoidArray - copy since we didn't // realloc. memcpy(newImpl->mArray, mImpl->mArray, mImpl->mCount * sizeof(mImpl->mArray[0])); } SetArray(newImpl, aSize, mImpl ? mImpl->mCount : 0, PR_TRUE, hasAuto); // no memset; handled later in ReplaceElementAt if needed return PR_TRUE; }
// This does all allocation/reallocation of the array. // It also will compact down to N - good for things that might grow a lot // at times, but usually are smaller, like JS deferred GC releases. bool nsVoidArray::SizeTo(int32_t aSize) { uint32_t oldsize = GetArraySize(); if (aSize == (int32_t) oldsize) return true; // no change if (aSize <= 0) { // free the array if allocated if (mImpl) { free(reinterpret_cast<char *>(mImpl)); mImpl = nullptr; } return true; } if (mImpl) { // We currently own an array impl. Resize it appropriately. if (aSize < mImpl->mCount) { // XXX Note: we could also just resize to mCount return true; // can't make it that small, ignore request } char* bytes = (char *) realloc(mImpl,SIZEOF_IMPL(aSize)); Impl* newImpl = reinterpret_cast<Impl*>(bytes); if (!newImpl) return false; #if DEBUG_VOIDARRAY if (mImpl == newImpl) ADD_TO_STATS(GrowInPlace,oldsize); ADD_TO_STATS(AllocedOfSize,SIZEOF_IMPL(aSize)); if (aSize > mMaxSize) { ADD_TO_STATS(NumberOfSize,SIZEOF_IMPL(aSize)); if (oldsize) SUB_FROM_STATS(NumberOfSize,oldsize); mMaxSize = aSize; if (mIsAuto) { ADD_TO_STATS(MaxAuto,SIZEOF_IMPL(aSize)); SUB_FROM_STATS(MaxAuto,oldsize); } } #endif SetArray(newImpl, aSize, newImpl->mCount); return true; } if ((uint32_t) aSize < oldsize) { // No point in allocating if it won't free the current Impl anyway. return true; } // just allocate an array // allocate the exact size requested char* bytes = (char *) malloc(SIZEOF_IMPL(aSize)); Impl* newImpl = reinterpret_cast<Impl*>(bytes); if (!newImpl) return false; #if DEBUG_VOIDARRAY ADD_TO_STATS(AllocedOfSize,SIZEOF_IMPL(aSize)); if (aSize > mMaxSize) { ADD_TO_STATS(NumberOfSize,SIZEOF_IMPL(aSize)); if (oldsize && !mImpl) SUB_FROM_STATS(NumberOfSize,oldsize); mMaxSize = aSize; } #endif if (mImpl) { #if DEBUG_VOIDARRAY ADD_TO_STATS(MaxAuto,SIZEOF_IMPL(aSize)); SUB_FROM_STATS(MaxAuto,0); SUB_FROM_STATS(NumberOfSize,0); mIsAuto = true; #endif // We must be growing an nsAutoVoidArray - copy since we didn't // realloc. memcpy(newImpl->mArray, mImpl->mArray, mImpl->mCount * sizeof(mImpl->mArray[0])); } SetArray(newImpl, aSize, mImpl ? mImpl->mCount : 0); // no memset; handled later in ReplaceElementAt if needed return true; }