Exemple #1
0
 virtual bool OffsetAlign(AddressType & addressOut, AddressType align,
                          AddressType offset, SizeType size) {
   FittingEnumerator callback(align, offset, size);
   if (addressedTree.Enumerate(callback)) {
     // The callback didn't find a suitable region
     return false;
   }
   addressedTree.Remove(callback.result);
   sizedTree.Remove(SizedRegion(callback.result));
   // Return the allocated address.
   addressOut = callback.result.address + callback.offset;
   // Split up the block as needed.
   if (callback.offset > 0) {
     // A sliver of free space remains at the beginning of the affected
     // region.
     AddRegion(FreeRegion(callback.result.address, 
                          (SizeType)callback.offset));
   }
   if (callback.offset + size < callback.result.size) {
     // A sliver of free space remains at the end of the affected region.
     
     // We can cast callback.offset to a SizeType in this case because we know
     // it is smaller than callback.result.size which *is* a SizeType.
     SizeType remainingSize = callback.result.size -
         (SizeType)(callback.offset + size);
     
     AddRegion(FreeRegion(addressOut + size, remainingSize));
   }
   return true;
 }
Exemple #2
0
 virtual void Dealloc(AddressType address, SizeType size) {
   AddressedRegion before, after;
   bool hasBefore = false, hasAfter = false;
   if (addressedTree.FindLT(before, AddressedRegion(address, size))) {
     if (before.address + before.size == address) {
       hasBefore = true;
     }
   }
   if (addressedTree.FindGT(after, AddressedRegion(address, size))) {
     if (address + size == after.address) {
       hasAfter = true;
     }
   }
   if (hasBefore && hasAfter) {
     // Remove both regions and join them all together
     addressedTree.Remove(before);
     addressedTree.Remove(after);
     sizedTree.Remove(SizedRegion(before));
     sizedTree.Remove(SizedRegion(after));
     AddRegion(FreeRegion(before.address, before.size + size + after.size));
   } else if (hasBefore) {
     // Remove the previous region and join it with the freed region
     addressedTree.Remove(before);
     sizedTree.Remove(SizedRegion(before));
     AddRegion(FreeRegion(before.address, before.size + size));
   } else if (hasAfter) {
     // Remove the next region and join it with the freed region
     addressedTree.Remove(after);
     sizedTree.Remove(SizedRegion(after));
     AddRegion(FreeRegion(address, after.size + size));
   } else {
     // Simple case: insert the free region
     AddRegion(FreeRegion(address, size));
   }
 }
GoRegion* GoRegionBoard::GenRegion(const SgPointSet& area,
                                        SgBlackWhite color)
{
    GoRegion* r = new GoRegion(Board(), area, color);
    AddRegion(r);
    return r;
}
void VSICurlStreamingHandle::PutRingBufferInCache()
{
    if (nRingBufferFileOffset >= BKGND_BUFFER_SIZE)
        return;

    AcquireMutex();

    /* Cache any remaining bytes available in the ring buffer */
    size_t nBufSize = oRingBuffer.GetSize();
    if ( nBufSize > 0 )
    {
        if (nRingBufferFileOffset + nBufSize > BKGND_BUFFER_SIZE)
            nBufSize = (size_t) (BKGND_BUFFER_SIZE - nRingBufferFileOffset);
        GByte* pabyTmp = (GByte*) CPLMalloc(nBufSize);
        oRingBuffer.Read(pabyTmp, nBufSize);

        /* Signal to the producer that we have ingested some bytes */
        CPLCondSignal(hCondConsumer);

        AddRegion(nRingBufferFileOffset, nBufSize, pabyTmp);
        nRingBufferFileOffset += nBufSize;
        CPLFree(pabyTmp);
    }

    ReleaseMutex();
}
  nsIntRegion ComputeChange(NotifySubDocInvalidationFunc aCallback)
  {
    bool transformChanged = !mTransform.FuzzyEqual(mLayer->GetTransform());
    Layer* otherMask = mLayer->GetMaskLayer();
    const nsIntRect* otherClip = mLayer->GetClipRect();
    nsIntRegion result;
    if ((mMaskLayer ? mMaskLayer->mLayer : nullptr) != otherMask ||
        (mUseClipRect != !!otherClip) ||
        mLayer->GetOpacity() != mOpacity ||
        transformChanged) 
    {
      result = OldTransformedBounds();
      if (transformChanged) {
        AddRegion(result, NewTransformedBounds());
      }

      // If we don't have to generate invalidations separately for child
      // layers then we can just stop here since we've already invalidated the entire
      // old and new bounds.
      if (!aCallback) {
        ClearInvalidations(mLayer);
        return result;
      }
    }

    nsIntRegion visible;
    visible.Xor(mVisibleRegion, mLayer->GetVisibleRegion());
    AddTransformedRegion(result, visible, mTransform);

    AddRegion(result, ComputeChangeInternal(aCallback));
    AddTransformedRegion(result, mLayer->GetInvalidRegion(), mTransform);

    if (mMaskLayer && otherMask) {
      AddTransformedRegion(result, mMaskLayer->ComputeChange(aCallback), mTransform);
    }

    if (mUseClipRect && otherClip) {
      if (!mClipRect.IsEqualInterior(*otherClip)) {
        nsIntRegion tmp; 
        tmp.Xor(mClipRect, *otherClip); 
        AddRegion(result, tmp);
      }
    }

    mLayer->ClearInvalidRect();
    return result;
  }
  nsIntRegion ComputeChange(NotifySubDocInvalidationFunc aCallback,
                            bool& aGeometryChanged)
  {
    bool transformChanged = !mTransform.FuzzyEqual(mLayer->GetLocalTransform()) ||
                            mLayer->GetPostXScale() != mPostXScale ||
                            mLayer->GetPostYScale() != mPostYScale;
    Layer* otherMask = mLayer->GetMaskLayer();
    const Maybe<ParentLayerIntRect>& otherClip = mLayer->GetClipRect();
    nsIntRegion result;
    if ((mMaskLayer ? mMaskLayer->mLayer : nullptr) != otherMask ||
        (mUseClipRect != !!otherClip) ||
        mLayer->GetLocalOpacity() != mOpacity ||
        transformChanged) 
    {
      aGeometryChanged = true;
      result = OldTransformedBounds();
      AddRegion(result, NewTransformedBounds());

      // We can't bail out early because we need to update mChildrenChanged.
    }

    AddRegion(result, ComputeChangeInternal(aCallback, aGeometryChanged));
    AddTransformedRegion(result, mLayer->GetInvalidRegion(), mTransform);

    if (mMaskLayer && otherMask) {
      AddTransformedRegion(result, mMaskLayer->ComputeChange(aCallback, aGeometryChanged),
                           mTransform);
    }

    if (mUseClipRect && otherClip) {
      if (!mClipRect.IsEqualInterior(*otherClip)) {
        aGeometryChanged = true;
        nsIntRegion tmp; 
        tmp.Xor(ParentLayerIntRect::ToUntyped(mClipRect), ParentLayerIntRect::ToUntyped(*otherClip)); 
        AddRegion(result, tmp);
      }
    }

    mLayer->ClearInvalidRect();
    return result;
  }
Exemple #7
0
 virtual bool Alloc(AddressType & addressOut, SizeType size) {
   SizedRegion sized;
   if (!sizedTree.FindGE(sized, SizedRegion(0, size), true)) {
     return false;
   }
   // [sized] is the lowest region whose size was >= [size]
   AddressedRegion addressed(sized);
   addressedTree.Remove(addressed);
   // The result is the beginning of this region
   addressOut = sized.address;
   if (size < sized.size) {
     // The free region has some excess; put it back in the trees.
     sized.size -= size;
     sized.address += size;
     return AddRegion(sized);
   }
   return true;
 }
Exemple #8
0
void TextureAtlas::ParseAtlas(const char* atlasData)
{
	cJSON* root = cJSON_Parse(atlasData);
	cJSON* frames = cJSON_GetObjectItem(root, "frames");

	int numFrames = cJSON_GetArraySize(frames);
	for (int i = 0 ; i < numFrames ; i++)
	{
		cJSON* frameItem = cJSON_GetArrayItem(frames, i);
		cJSON* frame = cJSON_GetObjectItem(frameItem, "frame");

		const string name = static_cast<string>(cJSON_GetObjectItem(frameItem, "filename")->valuestring);
		int x = cJSON_GetObjectItem(frame, "x")->valueint;
		int y = cJSON_GetObjectItem(frame, "y")->valueint;
		int w = cJSON_GetObjectItem(frame, "w")->valueint;
		int h = cJSON_GetObjectItem(frame, "h")->valueint;
		
		AddRegion(name, Rectangle(x, y, w, h));
	}

	cJSON_Delete(root);
}
  virtual nsIntRegion ComputeChangeInternal(NotifySubDocInvalidationFunc aCallback,
                                            bool& aGeometryChanged)
  {
    ContainerLayer* container = mLayer->AsContainerLayer();
    nsIntRegion result;

    bool childrenChanged = false;

    if (mPreXScale != container->GetPreXScale() ||
        mPreYScale != container->GetPreYScale()) {
      aGeometryChanged = true;
      result = OldTransformedBounds();
      AddRegion(result, NewTransformedBounds());
      childrenChanged = true;

      // Can't bail out early, we need to update the child container layers
    }

    // A low frame rate is especially visible to users when scrolling, so we
    // particularly want to avoid unnecessary invalidation at that time. For us
    // here, that means avoiding unnecessary invalidation of child items when
    // other children are added to or removed from our container layer, since
    // that may be caused by children being scrolled in or out of view. We are
    // less concerned with children changing order.
    // TODO: Consider how we could avoid unnecessary invalidation when children
    // change order, and whether the overhead would be worth it.

    nsDataHashtable<nsPtrHashKey<Layer>, uint32_t> oldIndexMap(mChildren.Length());
    for (uint32_t i = 0; i < mChildren.Length(); ++i) {
      oldIndexMap.Put(mChildren[i]->mLayer, i);
    }

    uint32_t i = 0; // cursor into the old child list mChildren
    for (Layer* child = container->GetFirstChild(); child; child = child->GetNextSibling()) {
      bool invalidateChildsCurrentArea = false;
      if (i < mChildren.Length()) {
        uint32_t childsOldIndex;
        if (oldIndexMap.Get(child, &childsOldIndex)) {
          if (childsOldIndex >= i) {
            // Invalidate the old areas of layers that used to be between the
            // current |child| and the previous |child| that was also in the
            // old list mChildren (if any of those children have been reordered
            // rather than removed, we will invalidate their new area when we
            // encounter them in the new list):
            for (uint32_t j = i; j < childsOldIndex; ++j) {
              AddRegion(result, mChildren[j]->OldTransformedBounds());
              childrenChanged |= true;
            }
            // Invalidate any regions of the child that have changed:
            nsIntRegion region = mChildren[childsOldIndex]->ComputeChange(aCallback, aGeometryChanged);
            i = childsOldIndex + 1;
            if (!region.IsEmpty()) {
              AddRegion(result, region);
              childrenChanged |= true;
            }
          } else {
            // We've already seen this child in mChildren (which means it must
            // have been reordered) and invalidated its old area. We need to
            // invalidate its new area too:
            invalidateChildsCurrentArea = true;
          }
        } else {
          // |child| is new
          invalidateChildsCurrentArea = true;
        }
      } else {
        // |child| is new, or was reordered to a higher index
        invalidateChildsCurrentArea = true;
      }
      if (invalidateChildsCurrentArea) {
        aGeometryChanged = true;
        AddTransformedRegion(result, child->GetVisibleRegion(), child->GetLocalTransform());
        if (aCallback) {
          NotifySubdocumentInvalidationRecursive(child, aCallback);
        } else {
          ClearInvalidations(child);
        }
      }
      childrenChanged |= invalidateChildsCurrentArea;
    }

    // Process remaining removed children.
    while (i < mChildren.Length()) {
      childrenChanged |= true;
      AddRegion(result, mChildren[i]->OldTransformedBounds());
      i++;
    }

    if (aCallback) {
      aCallback(container, result);
    }

    if (childrenChanged) {
      container->SetChildrenChanged(true);
    }

    result.Transform(gfx::To3DMatrix(mLayer->GetLocalTransform()));

    return result;
  }
Exemple #10
0
void MythUIEditBar::AddRegion(long long start, long long end)
{
    AddRegion((double)start, (double)end);
}
void GoRegionBoard::OnUndoneMove()
// Called after a move has been undone. The board is guaranteed to be in
// a legal state.
{
    //SG_ASSERT(false); // incremental code is incomplete, do not call
    if (DEBUG_REGION_BOARD)
        SgDebug() << "OnUndoneMove " << '\n';

    const bool IS_UNDO = false;
    SgVectorOf<GoRegion> changed;

    for (int val = m_stack.PopEvent(); val != SG_NEXTMOVE;
         val = m_stack.PopEvent())
    {

        switch (val)
        {
            case REGION_REMOVE:
            {   GoRegion* r = static_cast<GoRegion*>(m_stack.PopPtr());
                AddRegion(r, IS_UNDO);
                changed.Insert(r);
            }
            break;
            case REGION_ADD:
            {   GoRegion* r = static_cast<GoRegion*>(m_stack.PopPtr());
                RemoveRegion(r, IS_UNDO);
            }
            break;
            case REGION_REMOVE_BLOCK:
            {   GoBlock* b = static_cast<GoBlock*>(m_stack.PopPtr());
                AddBlock(b, IS_UNDO);
                for (int nu = m_stack.PopInt(); nu > 0; --nu)
                {
                    GoRegion* r = static_cast<GoRegion*>(m_stack.PopPtr());
                    if (CHECK)
                        SG_ASSERT(! r->Blocks().Contains(b));
                    r->BlocksNonConst().PushBack(b);
                    changed.Insert(r);
                }
            }
            break;
            case REGION_ADD_BLOCK:
            {   GoBlock* b = static_cast<GoBlock*>(m_stack.PopPtr());
                RemoveBlock(b, IS_UNDO, true);
            }
            break;
            case REGION_ADD_STONE:
            {   GoRegion* r = static_cast<GoRegion*>(m_stack.PopPtr());
                SgPoint p = m_stack.PopInt();
                r->OnRemoveStone(p);
                m_region[r->Color()][p] = r;
                changed.Insert(r);
            }
            break;
            case REGION_ADD_STONE_TO_BLOCK:
            {   GoBlock* b = static_cast<GoBlock*>(m_stack.PopPtr());
                SgPoint p = m_stack.PopInt();
                b->RemoveStone(p);
                m_block[p] = 0;
            }
            break;
            default:
                SG_ASSERT(false);
        }
    }

    for (SgVectorIteratorOf<GoRegion> it(changed); it; ++it)
    {
        (*it)->ResetNonBlockFlags();
        (*it)->ComputeBasicFlags();
    }

    if (HEAVYCHECK)
    {
        for (SgBWIterator it; it; ++it)
        {
            SgBlackWhite color(*it);
            for (SgVectorIteratorOf<GoRegion> it(AllRegions(color)); it; ++it)
            {
                const GoRegion* r = *it;
                SG_UNUSED(r);
                SG_ASSERT(r->IsValid());
            }
        }
    }

    m_code = Board().GetHashCode();
    if (HEAVYCHECK)
        CheckConsistency();
}
size_t VSICurlStreamingHandle::Read( void *pBuffer, size_t nSize, size_t nMemb )
{
    GByte* pabyBuffer = (GByte*)pBuffer;
    size_t nBufferRequestSize = nSize * nMemb;
    if (nBufferRequestSize == 0)
        return 0;
    size_t nRemaining = nBufferRequestSize;

    AcquireMutex();
    int bHastComputedFileSizeLocal = bHastComputedFileSize;
    vsi_l_offset fileSizeLocal = fileSize;
    ReleaseMutex();

    if (bHastComputedFileSizeLocal && curOffset >= fileSizeLocal)
    {
        CPLDebug("VSICURL", "Read attempt beyond end of file");
        bEOF = TRUE;
    }
    if (bEOF)
        return 0;

    if (curOffset < nRingBufferFileOffset)
        PutRingBufferInCache();

    if (ENABLE_DEBUG)
        CPLDebug("VSICURL", "Read [" CPL_FRMT_GUIB ", " CPL_FRMT_GUIB "[ in %s",
                 curOffset, curOffset + nBufferRequestSize, pszURL);

#ifdef notdef
    if( pCachedData != NULL && nCachedSize >= 1024 &&
        nRecomputedChecksumOfFirst1024Bytes == 0 )
    {
        for(size_t i = 0; i < 1024 / sizeof(int); i ++)
        {
            int nVal;
            memcpy(&nVal, pCachedData + i * sizeof(int), sizeof(int));
            nRecomputedChecksumOfFirst1024Bytes += nVal;
        }

        if( bHastComputedFileSizeLocal )
        {
            poFS->AcquireMutex();
            CachedFileProp* cachedFileProp = poFS->GetCachedFileProp(pszURL);
            if( cachedFileProp->nChecksumOfFirst1024Bytes == 0 )
            {
                cachedFileProp->nChecksumOfFirst1024Bytes = nRecomputedChecksumOfFirst1024Bytes;
            }
            else if( nRecomputedChecksumOfFirst1024Bytes != cachedFileProp->nChecksumOfFirst1024Bytes )
            {
                CPLDebug("VSICURL", "Invalidating previously cached file size. First bytes of file have changed!");
                AcquireMutex();
                bHastComputedFileSize = FALSE;
                cachedFileProp->bHastComputedFileSize = FALSE;
                cachedFileProp->nChecksumOfFirst1024Bytes = 0;
                ReleaseMutex();
            }
            poFS->ReleaseMutex();
        }
    }
#endif

    /* Can we use the cache ? */
    if( pCachedData != NULL && curOffset < nCachedSize )
    {
        size_t nSz = MIN(nRemaining, (size_t)(nCachedSize - curOffset));
        if (ENABLE_DEBUG)
            CPLDebug("VSICURL", "Using cache for [%d, %d[ in %s",
                     (int)curOffset, (int)(curOffset + nSz), pszURL);
        memcpy(pabyBuffer, pCachedData + curOffset, nSz);
        pabyBuffer += nSz;
        curOffset += nSz;
        nRemaining -= nSz;
    }

    /* Is the request partially covered by the cache and going beyond file size ? */
    if ( pCachedData != NULL && bHastComputedFileSizeLocal &&
         curOffset <= nCachedSize &&
         curOffset + nRemaining > fileSizeLocal &&
         fileSize == nCachedSize )
    {
        size_t nSz = (size_t) (nCachedSize - curOffset);
        if (ENABLE_DEBUG && nSz != 0)
            CPLDebug("VSICURL", "Using cache for [%d, %d[ in %s",
                    (int)curOffset, (int)(curOffset + nSz), pszURL);
        memcpy(pabyBuffer, pCachedData + curOffset, nSz);
        pabyBuffer += nSz;
        curOffset += nSz;
        nRemaining -= nSz;
        bEOF = TRUE;
    }

    /* Has a Seek() being done since the last Read() ? */
    if (!bEOF && nRemaining > 0 && curOffset != nRingBufferFileOffset)
    {
        /* Backward seek : we need to restart the download from the start */
        if (curOffset < nRingBufferFileOffset)
            StopDownload();

        StartDownload();

#define SKIP_BUFFER_SIZE    32768
        GByte* pabyTmp = (GByte*)CPLMalloc(SKIP_BUFFER_SIZE);

        CPLAssert(curOffset >= nRingBufferFileOffset);
        vsi_l_offset nBytesToSkip = curOffset - nRingBufferFileOffset;
        while(nBytesToSkip > 0)
        {
            vsi_l_offset nBytesToRead = nBytesToSkip;

            AcquireMutex();
            if (nBytesToRead > oRingBuffer.GetSize())
                nBytesToRead = oRingBuffer.GetSize();
            if (nBytesToRead > SKIP_BUFFER_SIZE)
                nBytesToRead = SKIP_BUFFER_SIZE;
            oRingBuffer.Read(pabyTmp, (size_t)nBytesToRead);

            /* Signal to the producer that we have ingested some bytes */
            CPLCondSignal(hCondConsumer);
            ReleaseMutex();

            if (nBytesToRead)
                AddRegion(nRingBufferFileOffset, (size_t)nBytesToRead, pabyTmp);

            nBytesToSkip -= nBytesToRead;
            nRingBufferFileOffset += nBytesToRead;

            if (nBytesToRead == 0 && nBytesToSkip != 0)
            {
                if (ENABLE_DEBUG)
                    CPLDebug("VSICURL", "Waiting for writer to produce some bytes...");

                AcquireMutex();
                while(oRingBuffer.GetSize() == 0 && bDownloadInProgress)
                    CPLCondWait(hCondProducer, hRingBufferMutex);
                int bBufferEmpty = (oRingBuffer.GetSize() == 0);
                ReleaseMutex();

                if (bBufferEmpty && !bDownloadInProgress)
                    break;
            }
        }

        CPLFree(pabyTmp);

        if (nBytesToSkip != 0)
        {
            bEOF = TRUE;
            return 0;
        }
    }

    if (!bEOF && nRemaining > 0)
    {
        StartDownload();
        CPLAssert(curOffset == nRingBufferFileOffset);
    }

    /* Fill the destination buffer from the ring buffer */
    while(!bEOF && nRemaining > 0)
    {
        AcquireMutex();
        size_t nToRead = oRingBuffer.GetSize();
        if (nToRead > nRemaining)
            nToRead = nRemaining;
        oRingBuffer.Read(pabyBuffer, nToRead);

        /* Signal to the producer that we have ingested some bytes */
        CPLCondSignal(hCondConsumer);
        ReleaseMutex();

        if (nToRead)
            AddRegion(curOffset, nToRead, pabyBuffer);

        nRemaining -= nToRead;
        pabyBuffer += nToRead;
        curOffset += nToRead;
        nRingBufferFileOffset += nToRead;

        if (nToRead == 0 && nRemaining != 0)
        {
            if (ENABLE_DEBUG)
                CPLDebug("VSICURL", "Waiting for writer to produce some bytes...");

            AcquireMutex();
            while(oRingBuffer.GetSize() == 0 && bDownloadInProgress)
                CPLCondWait(hCondProducer, hRingBufferMutex);
            int bBufferEmpty = (oRingBuffer.GetSize() == 0);
            ReleaseMutex();

            if (bBufferEmpty && !bDownloadInProgress)
                break;
        }
    }

    if (ENABLE_DEBUG)
        CPLDebug("VSICURL", "Read(%d) = %d",
                (int)nBufferRequestSize, (int)(nBufferRequestSize - nRemaining));
    size_t nRet = (nBufferRequestSize - nRemaining) / nSize;
    if (nRet < nMemb)
        bEOF = TRUE;

    return nRet;
}
	bool TextureAtlas::ReloadTextureAtlas()
	{
		auto& renderer = Renderer::GetInstance();		
		tinyxml2::XMLDocument doc;
		doc.LoadFile(mPath.c_str());
		if (doc.Error()) {
			const char* errMsg = doc.GetErrorStr1();
			if (errMsg)
				Logger::Log(FB_ERROR_LOG_ARG, FormatString("texture atlas error : \t%s", errMsg).c_str());
			else
				Logger::Log(FB_ERROR_LOG_ARG, "ReloadTextureAtlas Failed");
			return false;
		}
		tinyxml2::XMLElement* pRoot = doc.FirstChildElement("TextureAtlas");
		if (!pRoot) {
			Logger::Log(FB_ERROR_LOG_ARG, "Invalid TextureAtlas format!");
			return false;
		}

		const char* szBuffer = pRoot->Attribute("file");
		TexturePtr texture;
		if (szBuffer) {
			mTexture = renderer.CreateTexture(szBuffer, true);
			if (!mTexture)
			{
				Logger::Log(FB_ERROR_LOG_ARG, FormatString("Texture %s not found.", szBuffer).c_str());
			}
		}
		else {
			Logger::Log(FB_ERROR_LOG_ARG, "Invalid TextureAtlas format! No Texture Defined.");
			return false;
		}

		Vec2I textureSize = mTexture->GetSize();
		if (textureSize.x != 0 && textureSize.y != 0) {
			tinyxml2::XMLElement* pRegionElem = pRoot->FirstChildElement("region");
			while (pRegionElem) {
				szBuffer = pRegionElem->Attribute("name");
				if (!szBuffer)
				{
					Logger::Log(FB_ERROR_LOG_ARG, "No name for texture atlas region");
					continue;
				}
				TextureAtlasRegionPtr region = AddRegion(szBuffer);
				if (!region)
				{
					continue;					
				}
				region->mID = pRegionElem->UnsignedAttribute("id");
				region->mStart.x = pRegionElem->IntAttribute("x");
				region->mStart.y = pRegionElem->IntAttribute("y");
				region->mSize.x = pRegionElem->IntAttribute("width");
				region->mSize.y = pRegionElem->IntAttribute("height");
				Vec2 start((float)region->mStart.x, (float)region->mStart.y);
				Vec2 end(start.x + region->mSize.x, start.y + region->mSize.y);
				region->mUVStart = start / textureSize;
				region->mUVEnd = end / textureSize;
				pRegionElem = pRegionElem->NextSiblingElement();
			}
			return true;
		}
		else {
			Logger::Log(FB_ERROR_LOG_ARG, "Texture size is 0,0");
			return false;
		}
	}
Exemple #14
0
int
LoadRegions(char *pszRegionFile,	// csv file containing region loci
		int OfsLoci,				// offset region start loci by this many nt
		int DeltaLen,				// change region length by this many nt
		int TruncLength)			// truncate regions to this length
{
int Rslt;
int NumFields;
int NumProcessed;

int Len;
int SrcID;
char *pszElType;
char *pszRefSpecies;
char *pszChrom;
char *pszStrand;
int StartLoci;
int EndLoci;
bool bOnMinStrand;
int NumUnderlen;
int NumStartLess0;

if(pszRegionFile == NULL || pszRegionFile[0] == '\0')
	return(eBSFSuccess);

gDiagnostics.DiagOut(eDLInfo,gszProcName,"Loading regions from CSV loci file '%s'",pszRegionFile);

m_pCSV = new CCSVFile;
if(m_pCSV == NULL)
	{
	gDiagnostics.DiagOut(eDLFatal,gszProcName,"Unable to instantiate CCSVfile");
	return(eBSFerrObj);
	}

if((Rslt=m_pCSV->Open(pszRegionFile))!=eBSFSuccess)
	{
	while(m_pCSV->NumErrMsgs())
		gDiagnostics.DiagOut(eDLFatal,gszProcName,m_pCSV->GetErrMsg());
	gDiagnostics.DiagOut(eDLFatal,gszProcName,"Unable to open file: %s",pszRegionFile);
	Reset();
	return(Rslt);
	}

NumUnderlen = 0;
NumStartLess0 = 0;
NumProcessed = 0;
while((Rslt=m_pCSV->NextLine()) > 0)	// onto next line containing fields
	{
	NumFields = m_pCSV->GetCurFields();
	if(NumFields < 7)
		{
		gDiagnostics.DiagOut(eDLFatal,gszProcName,"Expected 7+ fields in '%s', GetCurFields() returned '%d'",pszRegionFile,NumFields);
		Rslt = eBSFerrFieldCnt;
		break;
		}
	if(!NumProcessed && m_pCSV->IsLikelyHeaderLine())
		continue;
	NumProcessed += 1;

	m_pCSV->GetInt(7,&Len);
	m_pCSV->GetInt(1,&SrcID);
	m_pCSV->GetText(2,&pszElType);
	m_pCSV->GetText(3,&pszRefSpecies);
	m_pCSV->GetText(4,&pszChrom);
	m_pCSV->GetInt(5,&StartLoci);
	m_pCSV->GetInt(6,&EndLoci);

	bOnMinStrand = false;
	if(NumFields >= 8)					// check if strand has been specified
		{
		m_pCSV->GetText(8,&pszStrand);
		if(pszStrand[0] == '-')		// assume anything other than '-' is on the plus strand
			bOnMinStrand = true;
		}

	if((Rslt = AdjLoci(bOnMinStrand,		// true if element is on '-' strand
		&StartLoci,		// starting loci on '+' strand
		&EndLoci,			// ending loci on '+' strand
		OfsLoci,			// offset loci by
		DeltaLen,			// adjust length by
		147,				// must be at least this length
		TruncLength)) < 1)	// truncate to this length
		{
		if(Rslt == -1)
			NumUnderlen += 1;
		else
			if(Rslt == -2)
				NumStartLess0 += 1;
		continue;
		}

	if((Rslt=AddRegion(SrcID,pszChrom,StartLoci,EndLoci))<0)
		{
		Reset();
		return(Rslt);
		}
	}
delete m_pCSV;
m_pCSV = NULL;
gDiagnostics.DiagOut(eDLInfo,gszProcName,"Accepted %d regions from %d loaded - %d too short, %d adjusted loci before chrom starts",m_NumRegions,NumProcessed,NumUnderlen,NumStartLess0);
if(m_NumRegions > 1)
	{
	gDiagnostics.DiagOut(eDLInfo,gszProcName,"Sorting regions...");
	qsort(m_pRegions,m_NumRegions,sizeof(tsRegion),SortRegions);
	gDiagnostics.DiagOut(eDLInfo,gszProcName,"Finished sorting regions...");
	}
return(Rslt);
}