vector<ossimImageCacheBase::ossimFrameEntryData> ossimImageCacheBase::getIntersectingEntries(const ossimIrect& rect) { vector<ossimFrameEntryData> result; // make sure we have the Toc entry to render if(!isOpen()) return result; ossimIrect imageRect = getImageRectangle(); if(rect.intersects(imageRect)) { ossimIrect clipRect = rect.clipToRect(imageRect); ossimIrect frameRect(clipRect.ul().x/m_frame_width, clipRect.ul().y/m_frame_height, clipRect.lr().x/m_frame_width, clipRect.lr().y/m_frame_height); for(ossim_int32 row = frameRect.ul().y; row <= frameRect.lr().y; ++row) { for(ossim_int32 col = frameRect.ul().x; col <= frameRect.lr().x; ++col) { ossimRpfFrameEntry tempEntry = m_frameEntryArray[row][col]; if(tempEntry.exists()) { result.push_back(ossimFrameEntryData(row, col, row*m_frame_height, col*m_frame_width, tempEntry)); } } } } return result; }
void ossimImageDataHelper::fill(T dummyVariable, const double* values, const ossimIrect& region, bool clipPoly) { if(clipPoly) { fill(dummyVariable, values, region.clipToRect(theImageData->getImageRectangle())); } else { fill(dummyVariable, values, region); } }
void ossimQtScrollingImageWidget::convertRequest(const ossimIrect& reqRect) { if(theRgbChain->getInput()) { QImage tempImage(theTileSize.x, theTileSize.y, 32); tempImage.fill(0); ossimIrect shiftedCacheRect = theBackingStoreCache.getCacheRect() - theShiftToZeroZero; ossimIrect tempRect = getAbsoluteViewportRect(); tempImage.setOffset(QPoint(theShiftToZeroZero.x + reqRect.ul().x, theShiftToZeroZero.y + reqRect.ul().y)); if(reqRect.intersects(shiftedCacheRect)) { if(reqRect.intersects(theBoundingRect)) { ossimRefPtr<ossimImageData> data = getTile(reqRect); if(data.valid() && data->getBuf() && (data->getDataObjectStatus()!=OSSIM_EMPTY)) { fillImage(data, &tempImage); } } } else { return; } theBackingStoreCache.addTile(tempImage); ossimIrect viewClip = reqRect.clipToRect(tempRect); viewClip = viewClip + theShiftToZeroZero; int xLoc = viewClip.ul().x; int yLoc = viewClip.ul().y; int xSize = theTileSize.x; int ySize = theTileSize.y; eraseCursor(); repaintContents(xLoc, yLoc, xSize, ySize, false); } }
ossimRefPtr<ossimImageData> ossimKakaduJ2kReader::getTile( const ossimIrect& rect, ossim_uint32 resLevel) { // This tile source bypassed, or invalid res level, return a blank tile. if(!isSourceEnabled() || !isOpen() || !isValidRLevel(resLevel)) { return ossimRefPtr<ossimImageData>(); } if (theTile.valid()) { // Rectangle must be set prior to getOverviewTile call. theTile->setImageRectangle(rect); if (resLevel) { if ( getOverviewTile(resLevel, theTile.get() ) == false ) { theTile->makeBlank(); } } else { //--- // See if the whole tile is going to be filled, if not, start out with // a blank tile so data from a previous load gets wiped out. //--- if ( !rect.completely_within(theImageRect) ) { // Start with a blank tile. theTile->makeBlank(); } //--- // See if any point of the requested tile is in the image. //--- if ( rect.intersects(theImageRect) ) { ossimIrect clipRect = rect.clipToRect(theImageRect); ossimIrect exandedRect = clipRect; //--- // Shift the upper left corner of the "clip_rect" to the an even // j2k tile boundry. //--- exandedRect.stretchToTileBoundary(ossimIpt(theTileSizeX, theTileSizeY)); // Vertical tile loop. ossim_int32 y = exandedRect.ul().y; while (y < exandedRect.lr().y) { // Horizontal tile loop. ossim_int32 x = exandedRect.ul().x; while (x < exandedRect.lr().x) { if ( loadTileFromCache(x, y, clipRect) == false ) { if ( loadTile(x, y) ) { //--- // Note: Clip the cache tile to the image clipRect // since there are j2k tiles that go beyond the image // dimensions, i.e., edge tiles. //--- ossimIrect cr = theCacheTile->getImageRectangle(). clipToRect(clipRect); theTile->loadTile(theCacheTile->getBuf(), theCacheTile->getImageRectangle(), cr, OSSIM_BSQ); } } x += theTileSizeX; // Go to next tile. } y += theTileSizeY; // Go to next row of tiles. } // Set the tile status. theTile->validate(); } // matches: if ( rect.intersects(theImageRect) ) } // r0 block } // matches: if (theTile.valid()) return theTile; }
//******************************************************************* // Private Method: //******************************************************************* bool ossimAdrgTileSource::fillBuffer(const ossimIrect& /* tile_rect */, const ossimIrect& clip_rect, ossimImageData* tile) { //*** // Shift the upper left corner of the "clip_rect" to the an even chunk // boundry. //*** ossimIpt tileOrigin = clip_rect.ul(); adjustToStartOfTile(tileOrigin); //*** // Calculate the number of tiles needed in the line/sample directions. //*** ossim_int32 size_in_x = clip_rect.lr().x - tileOrigin.x + 1; ossim_int32 size_in_y = clip_rect.lr().y - tileOrigin.y + 1; ossim_int32 tiles_in_x_dir = size_in_x / ADRG_TILE_WIDTH + (size_in_x % ADRG_TILE_WIDTH ? 1 : 0); ossim_int32 tiles_in_y_dir = size_in_y / ADRG_TILE_HEIGHT + (size_in_y % ADRG_TILE_HEIGHT ? 1 : 0); ossimIpt ulTilePt = tileOrigin; // Chunk loop in line direction. for (ossim_int32 y=0; y<tiles_in_y_dir; y++) { ulTilePt.x = tileOrigin.x; // Tile loop in sample direction. for (ossim_int32 x=0; x<tiles_in_x_dir; x++) { ossimIrect adrg_tile_rect(ulTilePt.x, ulTilePt.y, ulTilePt.x + ADRG_TILE_WIDTH- 1, ulTilePt.y + ADRG_TILE_HEIGHT - 1); if (adrg_tile_rect.intersects(clip_rect)) { ossimIrect tile_clip_rect = clip_rect.clipToRect(adrg_tile_rect); //--- // Some point in the chip intersect the tile so grab the // data. //--- ossim_int32 row = (ossim_int32) ulTilePt.y / ADRG_TILE_HEIGHT; ossim_int32 col = (ossim_int32) ulTilePt.x / ADRG_TILE_WIDTH; ossim_int32 tileOffset = m_AdrgHeader->tim(row, col); if(tileOffset != 0) { // Get the data. int seek_position = (tileOffset - 1) * 49152 + 2048; int band; // seek to start of chip m_FileStr.seekg(seek_position, ios::beg); for (band=0; band<3; band++) { //*** // Read the chip from the ccf file into the chunk buffer. // This will get all the bands. Bands are interleaved by // chip. //*** if (!m_FileStr.read((char*)m_TileBuffer, ADRG_TILE_SIZE)) { theErrorStatus = ossimErrorCodes::OSSIM_ERROR; return false; } tile->loadBand(m_TileBuffer, adrg_tile_rect, tile_clip_rect, band); } // End of band loop. } // End of if (tileOffset != 0) } // End of if (adrg_tile_rect.intersects(clip_rect)) ulTilePt.x += ADRG_TILE_WIDTH; } // End of tile loop in the sample direction. ulTilePt.y += ADRG_TILE_HEIGHT; } // End of tile loop in the line direction. return true; }
template <class T> void ossimWatermarkFilter::fill(T /* dummy */) { const ossimIrect TILE_RECT = theTile->getImageRectangle(); // We will only fill data within the input bounding rect. const ossimIrect CLIPPED_TILE_RECT = TILE_RECT.clipToRect(theInputBoundingRect); // Get the bounding rectangles. vector<ossimIrect> rects(0); getIntersectingRects(rects); if (rects.size() == 0) { return; } //--- // Have watermark rectangles that intersect this tile so we need to process. //--- ossim_uint32 band = 0; ossim_float64 inputPixWeight = 1.0 - theWatermarkWeight; // Get a pointers to the watermark buffers (wmBuf) and nulls wn. T** wmBuf = new T*[theWatermarkNumberOfBands]; for (band = 0; band < theWatermarkNumberOfBands; ++band) { wmBuf[band] = static_cast<T*>(theWatermark->getBuf(band)); } // Get a pointers to the output tile buffers and nulls in. T** otBuf = new T*[theInputNumberOfBands]; for (band = 0; band < theInputNumberOfBands; ++band) { otBuf[band] = static_cast<T*>(theTile->getBuf(band)); } // Get the width of the buffers for indexing. ossim_int32 wmWidth = static_cast<ossim_int32>(theWatermark->getWidth()); ossim_int32 otWidth = static_cast<ossim_int32>(theTile->getWidth()); const ossim_float64* wmNull = theWatermark->getNullPix(); const ossim_float64* otMin = theTile->getMinPix(); const ossim_float64* otMax = theTile->getMaxPix(); const ossim_float64* otNull = theTile->getNullPix(); // Control loop through intersecting rectangles. vector<ossimIrect>::const_iterator i = rects.begin(); while (i != rects.end()) { if ( (*i).intersects(CLIPPED_TILE_RECT) ) { //--- // This is the rectangle we want to fill relative to requesting // image space. //--- const ossimIrect CLIPPED_WATERMARRK_RECT = (*i).clipToRect(CLIPPED_TILE_RECT); ossim_int32 clipHeight = CLIPPED_WATERMARRK_RECT.height(); ossim_int32 clipWidth = CLIPPED_WATERMARRK_RECT.width(); // Compute the starting offset into the wmBuf and otBuf. ossim_int32 wmOffset = (CLIPPED_WATERMARRK_RECT.ul().y - (*i).ul().y) * wmWidth + CLIPPED_WATERMARRK_RECT.ul().x - (*i).ul().x; ossim_int32 otOffset = (CLIPPED_WATERMARRK_RECT.ul().y - TILE_RECT.ul().y)* otWidth + CLIPPED_WATERMARRK_RECT.ul().x - TILE_RECT.ul().x; // Line loop... for (ossim_int32 line = 0; line < clipHeight; ++line) { // Sample loop... for (ossim_int32 sample = 0; sample < clipWidth; ++sample) { // Output band control loop until all output bands are filled. ossim_uint32 otBand = 0; while (otBand < theInputNumberOfBands) { // Band loop through the watermark. for (ossim_uint32 wmBand = 0; wmBand < theWatermarkNumberOfBands; ++wmBand) { if (wmBuf[wmBand][wmOffset+sample] != wmNull[wmBand]) { // Apply the weight to the input pixel. ossim_float64 p1 = (otBuf[otBand][otOffset+sample] != otNull[otBand]) ? otBuf[otBand][otOffset+sample] * inputPixWeight : 0.0; // Apply the Weight to the watermark pixel. ossim_float64 p2 = wmBuf[wmBand][wmOffset+sample]*theWatermarkWeight; // Add them up. ossim_float64 p3 = p1 + p2; // Cast to output type with range checking. otBuf[otBand][otOffset+sample] = static_cast<T>( ( (p3 >= otMin[otBand]) ? (p3 < otMax[otBand] ? p3 : otMax[otBand]) : otNull[otBand]) ); } ++otBand; // We stop when we reach here. All output bands filled. if (otBand == theInputNumberOfBands) { break; } } // End of band through watermark. } // End of outer band loop. } // End of sample loop. wmOffset += wmWidth; otOffset += otWidth; } // End of line loop. } // End "if ( (*i).intersects(TILE_RECT) )" ++i; // Go to next rectangle to fill if any. } // End of "while (i != rects.end())" // Clean up. delete [] wmBuf; delete [] otBuf; theTile->validate(); }
ossimRefPtr<ossimImageData> ossimMrSidReader::getTile( const ossimIrect& rect, ossim_uint32 resLevel) { LT_STATUS sts = LT_STS_Uninit; // This tile source bypassed, or invalid res level, return null tile. if(!isSourceEnabled() || !isOpen() || !isValidRLevel(resLevel)) { return ossimRefPtr<ossimImageData>(); } ossimIrect imageBound = getBoundingRect(resLevel); if(!rect.intersects(imageBound)) { return ossimRefPtr<ossimImageData>(); } // Check for overview. if( resLevel > theMinDwtLevels ) { if(theOverview.valid()) { ossimRefPtr<ossimImageData> tileData = theOverview->getTile(rect, resLevel); tileData->setScalarType(getOutputScalarType()); return tileData; } } theTile->setImageRectangle(rect); // Compute clip rectangle with respect to the image bounds. ossimIrect clipRect = rect.clipToRect(imageBound); if (rect.completely_within(clipRect) == false) { // Not filling whole tile so blank it out first. theTile->makeBlank(); } lt_uint16 anOssimBandIndex = 0; LTIPixel pixel(theReader->getColorSpace(), theNumberOfBands, theReader->getDataType()); LTISceneBuffer sceneBuffer(pixel, clipRect.width(), clipRect.height(), NULL); if (!theGeometry.valid()) { theGeometry = getImageGeometry(); } double mag = theGeometry->decimationFactor(resLevel).lat; sts = theImageNavigator->setSceneAsULWH(clipRect.ul().x, clipRect.ul().y, clipRect.lr().x - clipRect.ul().x + 1, clipRect.lr().y - clipRect.ul().y + 1, mag); LTIScene scene = theImageNavigator->getScene(); sts = theReader->read(scene, sceneBuffer); if (LT_SUCCESS(sts) == true) { for(anOssimBandIndex = 0; anOssimBandIndex < theNumberOfBands; anOssimBandIndex++) { theTile->loadBand(sceneBuffer.getTotalBandData(anOssimBandIndex), clipRect, anOssimBandIndex); } } theTile->validate(); return theTile; }