void CoordinatedBackingStoreTile::swapBuffers(TextureMapper* textureMapper) { if (!m_surface) return; FloatRect tileRect(m_tileRect); tileRect.scale(1. / m_scale); bool shouldReset = false; if (tileRect != rect()) { setRect(tileRect); shouldReset = true; } RefPtr<BitmapTexture> texture = this->texture(); if (!texture) { texture = textureMapper->createTexture(); setTexture(texture.get()); shouldReset = true; } ASSERT(textureMapper->maxTextureSize().width() >= m_tileRect.size().width()); ASSERT(textureMapper->maxTextureSize().height() >= m_tileRect.size().height()); if (shouldReset) texture->reset(m_tileRect.size(), m_surface->supportsAlpha()); m_surface->copyToTexture(texture, m_sourceRect, m_surfaceOffset); m_surface.clear(); }
// Private Method(s) // Setup Tiles void Puzzle::setupTiles() { int tilesSquared = static_cast<int>(sqrt(mTiles.size())); int curCol = 0, curRow = 0; sf::FloatRect outlineRect = mGrid.getOutlineRect(); sf::Vector2f tileRect(outlineRect.width / tilesSquared, outlineRect.height / tilesSquared); sf::Vector2f textureSize(mTexture.getSize()); sf::Vector2f textureRect(textureSize.x / tilesSquared, textureSize.y / tilesSquared); sf::Vector2f scalingFactor(tileRect.x / textureRect.x, tileRect.y / textureRect.y); for (unsigned i = 0; i < mTiles.size(); i++) { mTiles[i].first->setTextureRect(static_cast<sf::IntRect> (sf::FloatRect(curCol * textureRect.x, curRow * textureRect.y, textureRect.x, textureRect.y))); mTiles[i].first->setTexture(mTexture); mTiles[i].first->scale(scalingFactor); mTiles[i].first->setPosition(mGrid.getTilePos(i)); curCol++; if (curCol % tilesSquared == 0) { curRow++; curCol = 0; } } }
ossimRefPtr<ossimImageData> ossimImageSourceSequencer::getNextTile( ossim_uint32 resLevel) { if(!theInputConnection) { return NULL; } ossimIpt origin; if(getTileOrigin(theCurrentTileNumber, origin)) { ++theCurrentTileNumber; ossimIrect tileRect(origin.x, origin.y, origin.x + (theTileSize.x - 1), origin.y + (theTileSize.y - 1)); ossimRefPtr<ossimImageData> data = theInputConnection->getTile(tileRect, resLevel); if(!data.valid()||!data->getBuf()) { theBlankTile->setImageRectangle(tileRect); return theBlankTile; } return data; } return ossimRefPtr<ossimImageData>(); }
void Image::drawTiled(GraphicsContext& ctxt, const FloatRect& destRect, const FloatPoint& srcPoint, const FloatSize& scaledTileSize, SkBlendMode op, const FloatSize& repeatSpacing) { FloatSize intrinsicTileSize = FloatSize(size()); if (hasRelativeSize()) { intrinsicTileSize.setWidth(scaledTileSize.width()); intrinsicTileSize.setHeight(scaledTileSize.height()); } FloatSize scale(scaledTileSize.width() / intrinsicTileSize.width(), scaledTileSize.height() / intrinsicTileSize.height()); const FloatRect oneTileRect = computeTileContaining( destRect.location(), scaledTileSize, srcPoint, repeatSpacing); // Check and see if a single draw of the image can cover the entire area we // are supposed to tile. if (oneTileRect.contains(destRect)) { const FloatRect visibleSrcRect = computeSubsetForTile(oneTileRect, destRect, intrinsicTileSize); ctxt.drawImage(this, destRect, &visibleSrcRect, op, DoNotRespectImageOrientation); return; } FloatRect tileRect(FloatPoint(), intrinsicTileSize); drawPattern(ctxt, tileRect, scale, oneTileRect.location(), op, destRect, repeatSpacing); startAnimation(); }
void Image::drawTiled(GraphicsContext* ctxt, const FloatRect& destRect, const FloatPoint& srcPoint, const FloatSize& scaledTileSize, SkXfermode::Mode op, const IntSize& repeatSpacing) { FloatSize intrinsicTileSize = size(); if (hasRelativeWidth()) intrinsicTileSize.setWidth(scaledTileSize.width()); if (hasRelativeHeight()) intrinsicTileSize.setHeight(scaledTileSize.height()); FloatSize scale(scaledTileSize.width() / intrinsicTileSize.width(), scaledTileSize.height() / intrinsicTileSize.height()); FloatSize actualTileSize(scaledTileSize.width() + repeatSpacing.width(), scaledTileSize.height() + repeatSpacing.height()); FloatRect oneTileRect; oneTileRect.setX(destRect.x() + fmodf(fmodf(-srcPoint.x(), actualTileSize.width()) - actualTileSize.width(), actualTileSize.width())); oneTileRect.setY(destRect.y() + fmodf(fmodf(-srcPoint.y(), actualTileSize.height()) - actualTileSize.height(), actualTileSize.height())); oneTileRect.setSize(scaledTileSize); // Check and see if a single draw of the image can cover the entire area we are supposed to tile. if (oneTileRect.contains(destRect)) { FloatRect visibleSrcRect; visibleSrcRect.setX((destRect.x() - oneTileRect.x()) / scale.width()); visibleSrcRect.setY((destRect.y() - oneTileRect.y()) / scale.height()); visibleSrcRect.setWidth(destRect.width() / scale.width()); visibleSrcRect.setHeight(destRect.height() / scale.height()); ctxt->drawImage(this, destRect, visibleSrcRect, op, DoNotRespectImageOrientation); return; } FloatRect tileRect(FloatPoint(), intrinsicTileSize); drawPattern(ctxt, tileRect, scale, oneTileRect.location(), op, destRect, repeatSpacing); startAnimation(); }
void KPrMatrixWipeStrategy::paintStep( QPainter &p, int currPos, const KPrPageEffect::Data &data ) { int width = data.m_widget->width(); int height = data.m_widget->height(); int curSquare = currPos / (m_smooth ? framesPerSquare : 1); for (int i = 0; i < m_squaresPerRow; ++i) { for (int j = 0; j < m_squaresPerCol; ++j) { QRect rect(floor(qreal(width) / m_squaresPerRow * i), floor(qreal(height) / m_squaresPerCol * j), ceil(qreal(width) / m_squaresPerRow), ceil(qreal(height) / m_squaresPerCol)); int square = squareIndex(i, j, m_squaresPerRow, m_squaresPerCol); if (square <= curSquare) { if (square == curSquare && m_smooth) { int squarePos = currPos % framesPerSquare; p.drawPixmap( rect.topLeft(), data.m_oldPage, rect ); rect = tileRect(squareDirection(i, j, m_squaresPerRow, m_squaresPerCol), squarePos, rect); if (rect.width() > 0 && rect.height() > 0) { p.drawPixmap( rect.topLeft(), data.m_newPage, rect ); } } else { p.drawPixmap( rect.topLeft(), data.m_newPage, rect ); } } else { p.drawPixmap( rect.topLeft(), data.m_oldPage, rect ); } } } }
void TextureMapperLayer::paintUsingOverlapRegions(const TextureMapperPaintOptions& options) { Region overlapRegion; Region nonOverlapRegion; computeOverlapRegions(overlapRegion, nonOverlapRegion, ResolveSelfOverlapAlways); if (overlapRegion.isEmpty()) { paintSelfAndChildrenWithReplica(options); return; } Vector<IntRect> rects; nonOverlapRegion.translate(options.offset); rects = nonOverlapRegion.rects(); for (size_t i = 0; i < rects.size(); ++i) { options.textureMapper->beginClip(TransformationMatrix(), rects[i]); paintSelfAndChildrenWithReplica(options); options.textureMapper->endClip(); } rects = overlapRegion.rects(); IntSize maxTextureSize = options.textureMapper->maxTextureSize(); IntRect rect; for (size_t i = 0; i < rects.size(); ++i) { rect = rects[i]; for (int x = rect.x(); x < rect.maxX(); x += maxTextureSize.width()) { for (int y = rect.y(); y < rect.maxY(); y += maxTextureSize.height()) { IntRect tileRect(IntPoint(x, y), maxTextureSize); tileRect.intersect(rect); paintWithIntermediateSurface(options, tileRect); } } } }
void building::updateTiles() { control* ctrl = control::getInstance(); rectangle tileRect(new point2d((int)location.getX(),(int)location.getY()),new point2d((int)(location.getX()+(size->getX()/100)),(int)(location.getY()+(size->getY()/100)))); vector<point2d*> tmpTiles = collision::checkTiles(tileRect); for(int a=0;a<tiles.size();a++) { ctrl->getColTree()->removeSpriteInTile(this); } tiles = tmpTiles; ctrl->getColTree()->addSpriteToTile(this); }
ossimRefPtr<ossimImageData> ossimImageSource::getTile(const ossimIpt& origin, ossim_uint32 resLevel) { ossimIrect tileRect(origin.x, origin.y, origin.x + getTileWidth() - 1, origin.y + getTileHeight() - 1); return getTile(tileRect, resLevel); }
rspfRefPtr<rspfImageData> rspfImageSource::getTile(const rspfIpt& origin, rspf_uint32 resLevel) { rspfIrect tileRect(origin.x, origin.y, origin.x + getTileWidth() - 1, origin.y + getTileHeight() - 1); return getTile(tileRect, resLevel); }
bool PhyTileEngine::IsRectCollidesTile(core::recti rect_, video::SColor blockType_, int tileX, int tileY) { const LayerTile* layerTile = m_physicLayerTile->GetLayerTile(tileX, tileY); if (layerTile->GetTilesetId() >= 0) { Tileset* tileset = m_tilemap->GetTileset( layerTile->GetTilesetId() ); video::ITexture* tilesetText = tileset->GetTexture( m_driver ); // Get intersection with physic layer image to be in bounds core::recti srcRect = rect_; core::recti tileRect( tileX * m_tilemap->GetTileWidth(), tileY * m_tilemap->GetTileHeight(), (tileX + 1) * m_tilemap->GetTileWidth(), (tileY + 1) * m_tilemap->GetTileHeight() ); //srcRect.clipAgainst(tileRect); srcRect.UpperLeftCorner.X = core::max_( rect_.UpperLeftCorner.X, tileRect.UpperLeftCorner.X); srcRect.LowerRightCorner.X = core::min_( rect_.LowerRightCorner.X, tileRect.LowerRightCorner.X); srcRect.UpperLeftCorner.Y = core::max_( rect_.UpperLeftCorner.Y, tileRect.UpperLeftCorner.Y); srcRect.LowerRightCorner.Y = core::min_( rect_.LowerRightCorner.Y, tileRect.LowerRightCorner.Y); // move to tileset coords s32 rectWidth = srcRect.getWidth(); s32 rectHeight = srcRect.getHeight(); srcRect.UpperLeftCorner.X = (srcRect.UpperLeftCorner.X % m_tilemap->GetTileWidth()) + tileset->GetTileX(layerTile->GetTileId()) * m_tilemap->GetTileWidth(); srcRect.UpperLeftCorner.Y = (srcRect.UpperLeftCorner.Y % m_tilemap->GetTileHeight()) + tileset->GetTileY(layerTile->GetTileId()) * m_tilemap->GetTileHeight(); srcRect.LowerRightCorner.X = srcRect.UpperLeftCorner.X + rectWidth; srcRect.LowerRightCorner.Y = srcRect.UpperLeftCorner.Y + rectHeight; u8* pixelData = static_cast<u8 *>( tilesetText->lock(true) ); core::dimension2du textSize = tilesetText->getSize(); u32 pixelSize = tilesetText->getPitch() / textSize.Width; bool isCollision = false; //!!!NOTE: suppose format video::ECOLOR_FORMAT::ECF_A8R8G8B8 for( s32 x = srcRect.UpperLeftCorner.X; x < srcRect.LowerRightCorner.X && !isCollision; ++x ) for( s32 y = srcRect.UpperLeftCorner.Y; y < srcRect.LowerRightCorner.Y && !isCollision; ++y ) { s32 index = y * tilesetText->getPitch() + x * pixelSize; video::SColor color( *((u32*)(pixelData + index)) ); if( color == blockType_ ) { isCollision = true; } } tilesetText->unlock(); return isCollision; } return false; }
bool ossimGui::StaticTileImageCache::addTile(const QImage& image) { OpenThreads::ScopedLock<OpenThreads::Mutex> lock(m_mutex); bool result = false; ossimIrect tileRect(image.offset().x(), image.offset().y(), image.offset().x() + (image.width()-1), image.offset().y() + (image.height()-1)); ossimIrect cacheRect = m_cacheRect; if(tileRect.intersects(cacheRect)) { ossimIrect clipRect = tileRect.clipToRect(cacheRect); // now fill the clipped rect ossim_uint32 srcY = clipRect.ul().y-tileRect.ul().y; ossim_uint32 srcX = clipRect.ul().x-tileRect.ul().x; ossim_uint32 destY = clipRect.ul().y-cacheRect.ul().y; ossim_uint32 destX = clipRect.ul().x-cacheRect.ul().x; ossimIpt offset = tileRect.ul() - cacheRect.ul(); ossim_uint32 x,y; for(y = 0; y < clipRect.height(); ++y) { ossim_uint32* cachePtr = ((ossim_uint32*)m_cache->scanLine(y+destY))+destX; ossim_uint32* tilePtr = ((ossim_uint32*)image.scanLine(y+srcY))+srcX; for(x = 0; x < clipRect.width(); ++x) { *cachePtr = *tilePtr; ++cachePtr; ++tilePtr; } } ossimIpt tilePoint(tileRect.ul()); for(y = 0; y < tileRect.height(); y+=m_tileSize.y) { tilePoint.x = tileRect.ul().x; for(x = 0; x < tileRect.width(); x+=m_tileSize.x) { ossim_int32 idx = getTileIndex(m_cacheRect, m_numberOfTiles, tilePoint); if(idx>=0) { m_validTileArray[idx] = true; } tilePoint.x+= m_tileSize.x; } tilePoint.y+=m_tileSize.y; } result = true; } return result; }
void TextureMapperLayer::paintUsingOverlapRegions(const TextureMapperPaintOptions& options) { Region overlapRegion; Region nonOverlapRegion; computeOverlapRegions(overlapRegion, nonOverlapRegion, ResolveSelfOverlapAlways); if (overlapRegion.isEmpty()) { paintSelfAndChildrenWithReplica(options); return; } // Having both overlap and non-overlap regions carries some overhead. Avoid it if the overlap area // is big anyway. if (overlapRegion.bounds().size().area() > nonOverlapRegion.bounds().size().area()) { overlapRegion.unite(nonOverlapRegion); nonOverlapRegion = Region(); } nonOverlapRegion.translate(options.offset); Vector<IntRect> rects = nonOverlapRegion.rects(); for (size_t i = 0; i < rects.size(); ++i) { IntRect rect = rects[i]; if (!rect.intersects(options.textureMapper->clipBounds())) continue; options.textureMapper->beginClip(TransformationMatrix(), rects[i]); paintSelfAndChildrenWithReplica(options); options.textureMapper->endClip(); } rects = overlapRegion.rects(); static const size_t OverlapRegionConsolidationThreshold = 4; if (nonOverlapRegion.isEmpty() && rects.size() > OverlapRegionConsolidationThreshold) { rects.clear(); rects.append(overlapRegion.bounds()); } IntSize maxTextureSize = options.textureMapper->maxTextureSize(); IntRect adjustedClipBounds(options.textureMapper->clipBounds()); adjustedClipBounds.move(-options.offset); for (size_t i = 0; i < rects.size(); ++i) { IntRect rect = rects[i]; for (int x = rect.x(); x < rect.maxX(); x += maxTextureSize.width()) { for (int y = rect.y(); y < rect.maxY(); y += maxTextureSize.height()) { IntRect tileRect(IntPoint(x, y), maxTextureSize); tileRect.intersect(rect); if (!tileRect.intersects(adjustedClipBounds)) continue; paintWithIntermediateSurface(options, tileRect); } } } }
bool Map::TileIsBehindActor(unsigned int tx, unsigned int ty, Actor* actor) { sf::IntRect tileRect(tx, ty, TILE_SIZE, TILE_SIZE); sf::IntRect actorRect(int(actor->GetPos().x) - actor->GetWidth() / 2, int(actor->GetPos().y) - actor->GetHeight(), actor->GetWidth(), actor->GetHeight() - TILE_SIZE / 2); if(actorRect.Intersects(tileRect)) { return true; } else { return false; } }
void SlippyMap::render(QPainter *p, const QRect &rect) { for (int x = 0; x <= m_tilesRect.width(); ++x) for (int y = 0; y <= m_tilesRect.height(); ++y) { QPoint tp(x + m_tilesRect.left(), y + m_tilesRect.top()); QRect box = tileRect(tp); if (rect.intersects(box)) { if (m_tilePixmaps.contains(tp)) p->drawPixmap(box, m_tilePixmaps.value(tp)); else p->drawPixmap(box, m_emptyTile); } } }
//! Copies the passed tile in the tile complex. The passed tile \b must //! possess integer geometry (ie tile.m_pos must have integer coordinates), //! otherwise this function is a no-op. bool TCacheResource::upload(const TPoint &pos, TRasterP ras) { int tileType; if (!checkRasterType(ras, tileType)) return false; if (m_tileType == NONE) m_tileType = tileType; //For all cells of the lattice which intersect the tile, upload the content in the //complex TRect tileRect(ras->getBounds() + pos); TPoint initialPos(getCellPos(tileRect.getP00())); //DIAGNOSTICS_NUMBEREDSTRSET(prefix + QString::number((UINT) this) + " | Stack | ", //"crStack", "upload", ::traduce(TRect(pos, ras->getSize()))); TPoint currPos; for (currPos.x = initialPos.x; currPos.x <= tileRect.x1; currPos.x += latticeStep) for (currPos.y = initialPos.y; currPos.y <= tileRect.y1; currPos.y += latticeStep) { //Copy tile's content into the cell's raster. TRect cellRect(currPos, TDimension(latticeStep, latticeStep)); TRect overlapRect(tileRect * cellRect); assert(!overlapRect.isEmpty()); PointLess cellIndex(getCellIndex(currPos)); std::pair<TRasterP, CellData *> cellInfos(touch(cellIndex)); TRasterP cellRas(cellInfos.first); TRect temp(overlapRect - currPos); TRasterP overlappingCellRas(cellRas->extract(temp)); temp = TRect(overlapRect - tileRect.getP00()); TRasterP overlappingTileRas(ras->extract(temp)); assert(overlappingCellRas->getBounds() == overlappingTileRas->getBounds()); TRop::copy(overlappingCellRas, overlappingTileRas); cellInfos.second->m_modified = true; } //Update the complex's content region m_region += toQRect(tileRect); return true; }
bool TCacheResource::downloadAll(const TPoint &pos, TRasterP ras) { int tileType; if (!checkRasterType(ras, tileType)) return false; //Build the tile's rect TRect tileRect(ras->getBounds() + pos); if (!contains(m_region, tileRect)) return false; //DIAGNOSTICS_NUMBEREDSTRSET(prefix + QString::number((UINT) this) + " | Stack | ", //"crStack", "downloadAll", ::traduce(TRect(pos, ras->getSize()))); //For all cells intersecting the tile's rect, copy all those intersecting the //complex's content region. TPoint initialPos(getCellPos(tileRect.getP00())); TPoint currPos; for (currPos.x = initialPos.x; currPos.x <= tileRect.x1; currPos.x += latticeStep) for (currPos.y = initialPos.y; currPos.y <= tileRect.y1; currPos.y += latticeStep) { TRect cellRect(currPos, TDimension(latticeStep, latticeStep)); TRect overlapRect(tileRect * cellRect); assert(!overlapRect.isEmpty()); QRect overlapQRect(toQRect(overlapRect)); if (m_region.intersects(overlapQRect)) { //Extract the associated rasters and perform the copy to the input tile. std::pair<TRasterP, CellData *> cellInfos(touch(getCellIndex(currPos))); TRasterP cellRas(cellInfos.first); TRect temp(overlapRect - currPos); TRasterP overlappingCellRas(cellRas->extract(temp)); temp = TRect(overlapRect - tileRect.getP00()); TRasterP overlappingTileRas(ras->extract(temp)); TRop::copy(overlappingTileRas, overlappingCellRas); } } return true; }
void Image::drawTiled(GraphicsContext* ctxt, const FloatRect& destRect, const FloatPoint& srcPoint, const FloatSize& scaledTileSize, ColorSpace styleColorSpace, CompositeOperator op) { if (mayFillWithSolidColor()) { fillWithSolidColor(ctxt, destRect, solidColor(), styleColorSpace, op); return; } // See <https://webkit.org/b/59043>. #if !PLATFORM(WX) ASSERT(!isBitmapImage() || notSolidColor()); #endif FloatSize intrinsicTileSize = size(); if (hasRelativeWidth()) intrinsicTileSize.setWidth(scaledTileSize.width()); if (hasRelativeHeight()) intrinsicTileSize.setHeight(scaledTileSize.height()); FloatSize scale(scaledTileSize.width() / intrinsicTileSize.width(), scaledTileSize.height() / intrinsicTileSize.height()); FloatRect oneTileRect; oneTileRect.setX(destRect.x() + fmodf(fmodf(-srcPoint.x(), scaledTileSize.width()) - scaledTileSize.width(), scaledTileSize.width())); oneTileRect.setY(destRect.y() + fmodf(fmodf(-srcPoint.y(), scaledTileSize.height()) - scaledTileSize.height(), scaledTileSize.height())); oneTileRect.setSize(scaledTileSize); // Check and see if a single draw of the image can cover the entire area we are supposed to tile. if (oneTileRect.contains(destRect)) { FloatRect visibleSrcRect; visibleSrcRect.setX((destRect.x() - oneTileRect.x()) / scale.width()); visibleSrcRect.setY((destRect.y() - oneTileRect.y()) / scale.height()); visibleSrcRect.setWidth(destRect.width() / scale.width()); visibleSrcRect.setHeight(destRect.height() / scale.height()); draw(ctxt, destRect, visibleSrcRect, styleColorSpace, op); return; } AffineTransform patternTransform = AffineTransform().scaleNonUniform(scale.width(), scale.height()); FloatRect tileRect(FloatPoint(), intrinsicTileSize); drawPattern(ctxt, tileRect, patternTransform, oneTileRect.location(), styleColorSpace, op, destRect); startAnimation(); }
void BackMap::Update(GFX::rect rect) { if (fImage == NULL) return; assert(fOverlays[0]); fImage->Clear(0); const uint16 firstTileX = rect.x / fTileWidth; const uint16 firstTileY = rect.y / fTileHeight; uint16 lastTileX = firstTileX + (rect.w / fTileWidth) + 2; uint16 lastTileY = firstTileY + (rect.h / fTileHeight) + 2; lastTileX = std::min(lastTileX, fMapWidth); lastTileY = std::min(lastTileY, fMapHeight); bool advance = true; //bool advance = Timer::Get("ANIMATEDTILES")->Expired(); GFX::rect tileRect(0, 0, fTileWidth, fTileHeight); for (uint16 y = 0; y < fMapHeight; y++) { tileRect.w = fTileWidth; tileRect.h = fTileHeight; tileRect.y = y * fTileHeight - rect.y; const uint32 tileNumY = y * fMapWidth; for (uint16 x = 0; x < fMapWidth; x++) { tileRect.w = fTileWidth; tileRect.x = x * fTileWidth - rect.x; TileCell* tile = TileAt(tileNumY, x); if (tile == NULL) { continue; } if (advance) tile->AdvanceFrame(); if (y >= firstTileY && y <= lastTileY && x >= firstTileX && x <= lastTileX) tile->Draw(fImage, &tileRect, false, true); } } }
bool ossimQtStaticTileImageCache::addTile(QImage& image) { bool result = false; if(((image.offset().x()%theTileSize.x)==0)&& ((image.offset().y()%theTileSize.y)==0)&& (image.width() == theTileSize.x)&& (image.height() == theTileSize.y)) { ossimIrect tileRect(image.offset().x(), image.offset().y(), image.offset().x() + (image.width()-1), image.offset().y() + (image.height()-1)); ossimIrect cacheRect = getCacheRect(); if(tileRect.completely_within(cacheRect)) { QRgb* tilePtr = (QRgb*)image.bits(); ossimIpt offset = tileRect.ul() - cacheRect.ul(); int x = 0; int y = 0; for(y = 0; y < theTileSize.y; ++y) { QRgb* cachePtr = ((QRgb*)theCache.scanLine(y+offset.y))+offset.x; for(x = 0; x < theTileSize.x; ++x) { *cachePtr = *tilePtr; ++cachePtr; ++tilePtr; } } ossim_int32 idx = getTileIndex(tileRect.ul()); theValidTileArray[idx] = true; result = true; } } return result; }
//! Fills the passed tile with the data contained in the complex, returning //! the copied region. //! The same restriction of the upload() method applies here. QRegion TCacheResource::download(const TPoint &pos, TRasterP ras) { int tileType; if (!checkRasterType(ras, tileType)) return QRegion(); //Build the tile's rect TRect tileRect(ras->getBounds() + pos); if (!m_region.intersects(toQRect(tileRect))) return QRegion(); //For all cells intersecting the tile's rect, copy all those intersecting the //complex's content region. TPoint initialPos(getCellPos(tileRect.getP00())); TPoint currPos; for (currPos.x = initialPos.x; currPos.x <= tileRect.x1; currPos.x += latticeStep) for (currPos.y = initialPos.y; currPos.y <= tileRect.y1; currPos.y += latticeStep) { TRect cellRect(currPos, TDimension(latticeStep, latticeStep)); TRect overlapRect(tileRect * cellRect); assert(!overlapRect.isEmpty()); QRect overlapQRect(toQRect(overlapRect)); if (m_region.intersects(overlapQRect)) { //Extract the associated rasters and perform the copy to the input tile. std::pair<TRasterP, CellData *> cellInfos(touch(getCellIndex(currPos))); TRasterP cellRas(cellInfos.first); TRect temp(overlapRect - currPos); TRasterP overlappingCellRas(cellRas->extract(temp)); temp = TRect(overlapRect - tileRect.getP00()); TRasterP overlappingTileRas(ras->extract(temp)); TRop::copy(overlappingTileRas, overlappingCellRas); } } return m_region.intersected(QRegion(toQRect(tileRect))); }
void Image::drawTiled(GraphicsContext* ctxt, const FloatRect& destRect, const FloatPoint& srcPoint, const FloatSize& scaledTileSize, CompositeOperator op, WebBlendMode blendMode, const IntSize& repeatSpacing) { if (mayFillWithSolidColor()) { fillWithSolidColor(ctxt, destRect, solidColor(), op); return; } // See <https://webkit.org/b/59043>. ASSERT(!isBitmapImage() || notSolidColor()); FloatSize intrinsicTileSize = size(); if (hasRelativeWidth()) intrinsicTileSize.setWidth(scaledTileSize.width()); if (hasRelativeHeight()) intrinsicTileSize.setHeight(scaledTileSize.height()); FloatSize scale(scaledTileSize.width() / intrinsicTileSize.width(), scaledTileSize.height() / intrinsicTileSize.height()); FloatSize actualTileSize(scaledTileSize.width() + repeatSpacing.width(), scaledTileSize.height() + repeatSpacing.height()); FloatRect oneTileRect; oneTileRect.setX(destRect.x() + fmodf(fmodf(-srcPoint.x(), actualTileSize.width()) - actualTileSize.width(), actualTileSize.width())); oneTileRect.setY(destRect.y() + fmodf(fmodf(-srcPoint.y(), actualTileSize.height()) - actualTileSize.height(), actualTileSize.height())); oneTileRect.setSize(scaledTileSize); // Check and see if a single draw of the image can cover the entire area we are supposed to tile. if (oneTileRect.contains(destRect)) { FloatRect visibleSrcRect; visibleSrcRect.setX((destRect.x() - oneTileRect.x()) / scale.width()); visibleSrcRect.setY((destRect.y() - oneTileRect.y()) / scale.height()); visibleSrcRect.setWidth(destRect.width() / scale.width()); visibleSrcRect.setHeight(destRect.height() / scale.height()); draw(ctxt, destRect, visibleSrcRect, op, blendMode); return; } FloatRect tileRect(FloatPoint(), intrinsicTileSize); drawPattern(ctxt, tileRect, scale, oneTileRect.location(), op, destRect, blendMode, repeatSpacing); startAnimation(); }
void Image::drawTiled(GraphicsContext* ctxt, const FloatRect& destRect, const FloatPoint& srcPoint, const FloatSize& scaledTileSize, ColorSpace styleColorSpace, CompositeOperator op, BlendMode blendMode) { if (mayFillWithSolidColor()) { fillWithSolidColor(ctxt, destRect, solidColor(), styleColorSpace, op); return; } ASSERT(!isBitmapImage() || notSolidColor()); FloatSize intrinsicTileSize = size(); if (hasRelativeWidth()) intrinsicTileSize.setWidth(scaledTileSize.width()); if (hasRelativeHeight()) intrinsicTileSize.setHeight(scaledTileSize.height()); FloatSize scale(scaledTileSize.width() / intrinsicTileSize.width(), scaledTileSize.height() / intrinsicTileSize.height()); FloatRect oneTileRect; FloatSize actualTileSize(scaledTileSize.width() + spaceSize().width(), scaledTileSize.height() + spaceSize().height()); oneTileRect.setX(destRect.x() + fmodf(fmodf(-srcPoint.x(), actualTileSize.width()) - actualTileSize.width(), actualTileSize.width())); oneTileRect.setY(destRect.y() + fmodf(fmodf(-srcPoint.y(), actualTileSize.height()) - actualTileSize.height(), actualTileSize.height())); oneTileRect.setSize(scaledTileSize); // Check and see if a single draw of the image can cover the entire area we are supposed to tile. if (oneTileRect.contains(destRect) && !ctxt->drawLuminanceMask()) { FloatRect visibleSrcRect; visibleSrcRect.setX((destRect.x() - oneTileRect.x()) / scale.width()); visibleSrcRect.setY((destRect.y() - oneTileRect.y()) / scale.height()); visibleSrcRect.setWidth(destRect.width() / scale.width()); visibleSrcRect.setHeight(destRect.height() / scale.height()); draw(ctxt, destRect, visibleSrcRect, styleColorSpace, op, blendMode, ImageOrientationDescription()); return; } AffineTransform patternTransform = AffineTransform().scaleNonUniform(scale.width(), scale.height()); FloatRect tileRect(FloatPoint(), intrinsicTileSize); drawPattern(ctxt, tileRect, patternTransform, oneTileRect.location(), styleColorSpace, op, destRect, blendMode); startAnimation(); }
void RoomContainer::_UpdateBaseMap(GFX::rect mapRect) { #if 0 MapOverlay *overlay = fOverlays[0]; if (overlay == NULL) { std::cerr << "Overlay 0 is NULL!!" << std::endl; return; } const uint16 overlayWidth = overlay->Width(); const uint16 firstTileX = fAreaOffset.x / TILE_WIDTH; const uint16 firstTileY = fAreaOffset.y / TILE_HEIGHT; uint16 lastTileX = firstTileX + (mapRect.w / TILE_WIDTH) + 2; uint16 lastTileY = firstTileY + (mapRect.h / TILE_HEIGHT) + 2; lastTileX = std::min(lastTileX, overlayWidth); lastTileY = std::min(lastTileY, overlay->Height()); bool advance = true; //bool advance = Timer::Get("ANIMATEDTILES")->Expired(); GFX::rect tileRect(0, 0, TILE_WIDTH, TILE_HEIGHT); for (uint16 y = 0; y < overlay->Height(); y++) { tileRect.w = TILE_WIDTH; tileRect.h = TILE_HEIGHT; tileRect.y = y * TILE_HEIGHT - fAreaOffset.y; const uint32 tileNumY = y * overlayWidth; for (uint16 x = 0; x < overlayWidth; x++) { tileRect.w = TILE_WIDTH; tileRect.x = x * TILE_WIDTH - fAreaOffset.x; TileCell* tile = TileAt(tileNumY, x); if (advance) tile->AdvanceFrame(); if (y >= firstTileY && y <= lastTileY && x >= firstTileX && x <= lastTileX) tile->Draw(fBackBitmap, &tileRect, false, fDrawOverlays); } } #endif }
void SlippyMap::handleNetworkData(QNetworkReply *reply) { QImage img; const QPoint tp = reply->request().attribute(QNetworkRequest::User).toPoint(); if (!reply->error()) if (!img.load(reply, 0)) img = QImage(); reply->deleteLater(); m_tilePixmaps[tp] = QPixmap::fromImage(img); if (img.isNull()) m_tilePixmaps[tp] = m_emptyTile; emit updated(tileRect(tp)); // purge unused spaces const QRect bound = m_tilesRect.adjusted(-2, -2, 2, 2); foreach(QPoint tp, m_tilePixmaps.keys()) if (!bound.contains(tp)) m_tilePixmaps.remove(tp); download(); }
void Image::drawTiled(GraphicsContext* ctxt, const FloatRect& destRect, const FloatPoint& srcPoint, const FloatSize& scaledTileSize, CompositeOperator op) { if (mayFillWithSolidColor()) { fillWithSolidColor(ctxt, destRect, solidColor(), op); return; } FloatSize intrinsicTileSize = size(); if (hasRelativeWidth()) intrinsicTileSize.setWidth(scaledTileSize.width()); if (hasRelativeHeight()) intrinsicTileSize.setHeight(scaledTileSize.height()); FloatSize scale(scaledTileSize.width() / intrinsicTileSize.width(), scaledTileSize.height() / intrinsicTileSize.height()); AffineTransform patternTransform = AffineTransform().scale(scale.width(), scale.height()); FloatRect oneTileRect; oneTileRect.setX(destRect.x() + fmodf(fmodf(-srcPoint.x(), scaledTileSize.width()) - scaledTileSize.width(), scaledTileSize.width())); oneTileRect.setY(destRect.y() + fmodf(fmodf(-srcPoint.y(), scaledTileSize.height()) - scaledTileSize.height(), scaledTileSize.height())); oneTileRect.setSize(scaledTileSize); // Check and see if a single draw of the image can cover the entire area we are supposed to tile. if (oneTileRect.contains(destRect)) { FloatRect visibleSrcRect; visibleSrcRect.setX((destRect.x() - oneTileRect.x()) / scale.width()); visibleSrcRect.setY((destRect.y() - oneTileRect.y()) / scale.height()); visibleSrcRect.setWidth(destRect.width() / scale.width()); visibleSrcRect.setHeight(destRect.height() / scale.height()); draw(ctxt, destRect, visibleSrcRect, op); return; } FloatRect tileRect(FloatPoint(), intrinsicTileSize); drawPatternCounter.startCounting(); drawPattern(ctxt, tileRect, patternTransform, oneTileRect.location(), op, destRect); drawPatternCounter.stopCounting(); startAnimation(); }
void TilesMap::paintEvent(QPaintEvent *event) { QPainter p; p.begin(this); QPixmap tile; QString key; for (int x = m_tilesRect.left(); x <= m_tilesRect.right(); x++) { for (int y = m_tilesRect.top(); y <= m_tilesRect.bottom(); y++) { QPoint tp(x, y); QRect box = tileRect(tp); if (event->rect().intersects(box)) { key.sprintf("tile.%d.%d.%d.%d", m_source->id(), m_zoom, x, y); if (QPixmapCache::find(key, tile)) { p.drawPixmap(box, tile); } else { bool drawn = false; for (int k = 2, z = m_zoom - 1; k <= 8; k *= 2, z--) { key.sprintf("tile.%d.%d.%d.%d", m_source->id(), z, x / k, y / k); if (QPixmapCache::find(key, tile)) { int s = TILE_SIZE / k; p.drawPixmap(box, tile, QRect((x % k) * s, (y % k) * s, s, s)); drawn = true; break; } } if (!drawn) { p.drawPixmap(box, m_emptyTile); } } } } } p.end(); }
void MapWidget::drawMapTiles(QPainter &p, const QRect &rect) { int tiles = std::pow(2, ZOOM); for (int x = 0; x <= tilesRect.width(); ++x) { for (int y = 0; y <= tilesRect.height(); ++y) { QPoint tp(x + tilesRect.left(), y + tilesRect.top()); QRect box = tileRect(tp); if (rect.intersects(box)) { tp.setX((tp.x() + tiles) % tiles); tp.setY((tp.y() + tiles) % tiles); if (tilePixmaps.contains(tp)) { p.drawPixmap(box, tilePixmaps.value(tp)); } } } } if (MapWidget::usingNightMode) { QPainter::CompositionMode compositionMode = p.compositionMode(); p.setCompositionMode(QPainter::CompositionMode_Difference); p.fillRect(rect, Qt::white); p.setCompositionMode(compositionMode); } }
void HexTileDecoder::decode(RfbInputGate *input, FrameBuffer *framebuffer, const Rect *dstRect) { // shorcut const int bytesPerPixel = framebuffer->getBytesPerPixel(); UINT32 background = 0; UINT32 foreground = 0; bool backgroundAccepted = false; for (int y = dstRect->top; y < dstRect->bottom; y += TILE_SIZE) for (int x = dstRect->left; x < dstRect->right; x += TILE_SIZE) { Rect tileRect(x, y, min(x + TILE_SIZE, dstRect->right), min(y + TILE_SIZE, dstRect->bottom)); if (!framebuffer->getDimension().getRect().intersection(&tileRect).isEqualTo(&tileRect)) throw Exception(_T("Error in protocol: incorrect size of tile in hextile-decoder")); UINT8 flags = input->readUInt8(); if (flags & 0x1) { for (int y = tileRect.top; y < tileRect.bottom; y++) input->readFully(framebuffer->getBufferPtr(tileRect.left, y), tileRect.getWidth() * bytesPerPixel); } else { if (flags & 0x2) { input->readFully(&background, bytesPerPixel); backgroundAccepted = true; } if (backgroundAccepted) framebuffer->fillRect(&tileRect, background); if (flags & 0x4) input->readFully(&foreground, bytesPerPixel); if (flags & 0x8) { UINT8 numberOfSubrectangles = input->readUInt8(); for (int i = 0; i < numberOfSubrectangles; i++) { if (flags & 0x10 && !(flags & 0x4)) input->readFully(&foreground, bytesPerPixel); UINT8 xy = input->readUInt8(); UINT8 wh = input->readUInt8(); int x = (xy >> 4) & 0xF; int y = xy & 0xF; int w = ((wh >> 4) & 0xF) + 1; int h = (wh & 0xF) + 1; Rect subRect(x, y, x + w, y + h); subRect.move(tileRect.left, tileRect.top); framebuffer->fillRect(&subRect, foreground); } } else { // exist subrect if (!backgroundAccepted) throw Exception(_T("Server error in HexTile encoding: background color not accepted")); } } // not raw
bool ossim::getCodestreamDimensions(kdu_core::kdu_codestream& codestream, std::vector<ossimIrect>& imageDims, std::vector<ossimIrect>& tileDims) { bool result = true; imageDims.clear(); tileDims.clear(); if ( codestream.exists() ) { kdu_core::kdu_coords tileIdx(0, 0); ossim_uint32 levels = codestream.get_min_dwt_levels(); for (ossim_uint32 level=0; level <= levels; ++level) { // Get the image dimensions. codestream.apply_input_restrictions( 0, // first_component 0, // max_components (0 = all remaining will appear) level, // highest resolution level 0, // max_layers (0 = all layers retained) NULL, // expanded out to block boundary. kdu_core::KDU_WANT_OUTPUT_COMPONENTS); kdu_core::kdu_dims dims; codestream.get_dims(0, dims); // Make the imageRect upper left relative to any sub image offset. ossimIrect imageRect; getRect(dims, imageRect); imageDims.push_back(imageRect); // Get the tile dimensions. kdu_core::kdu_dims mappedRegion; codestream.map_region(0, dims, mappedRegion, true); kdu_core::kdu_tile tile = codestream.open_tile(tileIdx); if ( tile.exists() ) { codestream.get_tile_dims( tile.get_tile_idx(), 0, dims ); // Make the tile rect zero based. ossimIrect tileRect(0, 0, dims.size.x-1, dims.size.y-1); tileDims.push_back(tileRect); // Every open has a close. tile.close(); } else { result = false; } } // matches: for (ossim_uint32 level=0; level <= levels; ++level) // Set things back to level 0. codestream.apply_input_restrictions( 0, // first_component 0, // max_components (0 = all remaining will appear) 0, // highest resolution level 0, // max_layers (0 = all layers retained) NULL, // expanded out to block boundary. kdu_core::KDU_WANT_OUTPUT_COMPONENTS); // Should be the same sizes as levels. if ( (imageDims.size() != tileDims.size()) || (tileDims.size() != levels+1) ) { result = false; } } else // codestream.exists() == false { result = false; } return result; }