Scroom 0.14-48-ga0fee447
Loading...
Searching...
No Matches
Scroom::Tiff::Source Class Reference

#include <tiffsource.hh>

Inheritance diagram for Scroom::Tiff::Source:
Inheritance graph
Collaboration diagram for Scroom::Tiff::Source:
Collaboration graph

Public Types

using Ptr = std::shared_ptr< Source >
 
- Public Types inherited from SourcePresentation
using Ptr = std::shared_ptr< SourcePresentation >
 

Public Member Functions

bool reset ()
 
void fillTiles (int startLine, int lineCount, int tileWidth, int firstTile, std::vector< Tile::Ptr > &tiles) override
 
void done () override
 
std::string getName () override
 

Static Public Member Functions

static Ptr create (std::string fileName, TIFFPtr tif, BitmapMetaData bmd)
 

Private Member Functions

 Source (std::string fileName, TIFFPtr tif, BitmapMetaData bmd)
 

Private Attributes

std::string fileName
 
TIFFPtr preOpenedTif
 
TIFFPtr tif
 
BitmapMetaData bmd
 
Scroom::Logger logger
 

Member Typedef Documentation

◆ Ptr

using Scroom::Tiff::Source::Ptr = std::shared_ptr<Source>

Constructor & Destructor Documentation

◆ Source()

Scroom::Tiff::Source::Source ( std::string  fileName,
TIFFPtr  tif,
BitmapMetaData  bmd 
)
private
231 : fileName(std::move(fileName_))
232 , preOpenedTif(std::move(tif_))
233 , bmd(std::move(bmd_))
234 {
235 }
std::string fileName
Definition tiffsource.hh:39
BitmapMetaData bmd
Definition tiffsource.hh:42
TIFFPtr preOpenedTif
Definition tiffsource.hh:40

Member Function Documentation

◆ create()

Source::Ptr Scroom::Tiff::Source::create ( std::string  fileName,
TIFFPtr  tif,
BitmapMetaData  bmd 
)
static
226 {
227 return Ptr(new Source(std::move(fileName), std::move(tif), std::move(bmd)));
228 }
TIFFPtr tif
Definition tiffsource.hh:41
Source(std::string fileName, TIFFPtr tif, BitmapMetaData bmd)
Definition tiffsource.cc:230
std::shared_ptr< Source > Ptr
Definition tiffsource.hh:46

Referenced by Tiff::open().

Here is the caller graph for this function:

◆ done()

void Scroom::Tiff::Source::done ( )
overridevirtual

Done reading bitmap data

Any open files can be closed now

Implements SourcePresentation.

302{ tif.reset(); }

◆ fillTiles()

void Scroom::Tiff::Source::fillTiles ( int  startLine,
int  lineCount,
int  tileWidth,
int  firstTile,
std::vector< Tile::Ptr > &  tiles 
)
overridevirtual

Provide bitmap data

While the TiledBitmap is loaded, this function will be called several times. Each time, this function has to fill the provided tiles with bitmap data.

The given tiles are horizontally adjacent.

Parameters
startLiney coordinate of the first line in the set of tiles
lineCountThe number of lines that are to be filled. This equals the height of the tiles
tileWidthThe width of one tile
firstTileIndex of the first tile provided. This means that the first x coordinate is firsttile * tileWidth
tilesThe tiles that are to be filled.

Implements SourcePresentation.

267 {
268 auto spp = bmd.samplesPerPixel;
269 auto bps = bmd.bitsPerSample;
270
271 const auto startLine_ = static_cast<uint32_t>(startLine);
272 const auto firstTile_ = static_cast<size_t>(firstTile);
273 const auto scanLineSize = static_cast<size_t>(TIFFScanlineSize(tif.get()));
274 const auto tileStride = static_cast<size_t>(tileWidth * spp * bps / 8);
275 std::vector<byte> row(scanLineSize);
276
277 const size_t tileCount = tiles.size();
278 auto dataPtr = std::vector<byte*>(tileCount);
279 for(size_t tile = 0; tile < tileCount; tile++)
280 {
281 dataPtr[tile] = tiles[tile]->data.get();
282 }
283
284 for(size_t i = 0; i < static_cast<size_t>(lineCount); i++)
285 {
286 TIFFReadScanline(tif.get(), row.data(), static_cast<uint32_t>(i) + startLine_);
287
288 for(size_t tile = 0; tile < tileCount - 1; tile++)
289 {
290 memcpy(dataPtr[tile], row.data() + (firstTile_ + tile) * tileStride, tileStride);
291 dataPtr[tile] += tileStride;
292 }
293 memcpy(
294 dataPtr[tileCount - 1],
295 row.data() + (firstTile_ + tileCount - 1) * tileStride,
296 scanLineSize - (firstTile_ + tileCount - 1) * tileStride
297 );
298 dataPtr[tileCount - 1] += tileStride;
299 }
300 }
unsigned int bitsPerSample
Definition opentiledbitmapinterface.hh:45
unsigned int samplesPerPixel
Definition opentiledbitmapinterface.hh:46

◆ getName()

std::string Scroom::Tiff::Source::getName ( )
inlineoverridevirtual

Implements SourcePresentation.

55{ return fileName; }

◆ reset()

bool Scroom::Tiff::Source::reset ( )
238 {
240 preOpenedTif = nullptr;
241
242 if(!tif)
243 {
245 if(r && approx(std::get<0>(*r), bmd))
246 {
247 tif = std::get<1>(*r);
248 }
249 else
250 {
251 if(r)
252 {
253 logger->error("Can't reload. Bitmap changed too much");
254 logger->info("Previously: {}", to_string(bmd));
255 logger->info("Now: {}", to_string(std::get<0>(*r)));
256 }
257 // if (!r) then the error has already been reported by open()
258 return false;
259 }
260 }
261 ensure(tif);
262
263 return true;
264 }
#define ensure(expr)
Definition assertions.hh:35
Scroom::Logger logger
Definition tiffsource.hh:43
boost::optional< std::tuple< Scroom::TiledBitmap::BitmapMetaData, TIFFPtr > > open(const Scroom::Logger &logger, const std::string &fileName)
Definition tiffsource.cc:120
std::string to_string(const BitmapMetaData &bmd)
Definition layerspecforbitmap.cc:28
bool approx(const BitmapMetaData &left, const BitmapMetaData &right)
Definition pnmsource.cc:21
Scroom::Utils::Rectangle< double > const r
Definition transformpresentation_test.cc:65
Here is the call graph for this function:

Member Data Documentation

◆ bmd

BitmapMetaData Scroom::Tiff::Source::bmd
private

Referenced by create(), fillTiles(), and reset().

◆ fileName

std::string Scroom::Tiff::Source::fileName
private

Referenced by create(), getName(), and reset().

◆ logger

Scroom::Logger Scroom::Tiff::Source::logger
private

Referenced by reset().

◆ preOpenedTif

TIFFPtr Scroom::Tiff::Source::preOpenedTif
private

Referenced by reset().

◆ tif

TIFFPtr Scroom::Tiff::Source::tif
private

Referenced by create(), done(), fillTiles(), and reset().


The documentation for this class was generated from the following files: