mirror of
https://github.com/davidgiven/fluxengine.git
synced 2025-10-31 11:17:01 -07:00
In fe-read, load the image before constructing the encoder, decoder etc so as
to allow the image reader to modify the config if necessary.
This commit is contained in:
@@ -16,7 +16,7 @@ public:
|
||||
ImageReader(config)
|
||||
{}
|
||||
|
||||
Image readImage()
|
||||
std::unique_ptr<Image> readImageImpl()
|
||||
{
|
||||
std::ifstream inputFile(_config.filename(), std::ios::in | std::ios::binary);
|
||||
if (!inputFile.is_open())
|
||||
@@ -53,7 +53,7 @@ public:
|
||||
return 17;
|
||||
};
|
||||
|
||||
Image image;
|
||||
std::unique_ptr<Image> image(new Image);
|
||||
for (int track = 0; track < 40; track++)
|
||||
{
|
||||
int numSectors = sectorsPerTrack(track);
|
||||
@@ -62,7 +62,7 @@ public:
|
||||
{
|
||||
for (int sectorId = 0; sectorId < numSectors; sectorId++)
|
||||
{
|
||||
const auto& sector = image.put(track, head, sectorId);
|
||||
const auto& sector = image->put(track, head, sectorId);
|
||||
if ((offset < inputFileSize))
|
||||
{ //still data available sector OK
|
||||
br.seek(offset);
|
||||
@@ -88,7 +88,7 @@ public:
|
||||
}
|
||||
}
|
||||
|
||||
image.calculateSize();
|
||||
image->calculateSize();
|
||||
return image;
|
||||
}
|
||||
};
|
||||
|
||||
@@ -20,7 +20,7 @@ public:
|
||||
ImageReader(config)
|
||||
{}
|
||||
|
||||
Image readImage()
|
||||
std::unique_ptr<Image> readImageImpl()
|
||||
{
|
||||
std::ifstream inputFile(_config.filename(), std::ios::in | std::ios::binary);
|
||||
if (!inputFile.is_open())
|
||||
@@ -64,7 +64,7 @@ public:
|
||||
break;
|
||||
}
|
||||
|
||||
Image image;
|
||||
std::unique_ptr<Image> image(new Image);
|
||||
int trackCount = 0;
|
||||
for (int track = 0; track < tracks; track++)
|
||||
{
|
||||
@@ -83,7 +83,7 @@ public:
|
||||
Bytes data(sectorSize);
|
||||
inputFile.read((char*) data.begin(), data.size());
|
||||
|
||||
const auto& sector = image.put(physicalCylinder, side, sectorId);
|
||||
const auto& sector = image->put(physicalCylinder, side, sectorId);
|
||||
sector->status = Sector::OK;
|
||||
sector->logicalTrack = track;
|
||||
sector->physicalCylinder = physicalCylinder;
|
||||
@@ -96,8 +96,8 @@ public:
|
||||
trackCount++;
|
||||
}
|
||||
|
||||
image.calculateSize();
|
||||
const Geometry& geometry = image.getGeometry();
|
||||
image->calculateSize();
|
||||
const Geometry& geometry = image->getGeometry();
|
||||
std::cout << fmt::format("DIM: read {} tracks, {} sides, {} kB total\n",
|
||||
geometry.numTracks, geometry.numSides,
|
||||
((int)inputFile.tellg() - 256) / 1024);
|
||||
|
||||
@@ -16,7 +16,7 @@ public:
|
||||
ImageReader(config)
|
||||
{}
|
||||
|
||||
Image readImage()
|
||||
std::unique_ptr<Image> readImageImpl()
|
||||
{
|
||||
std::ifstream inputFile(_config.filename(), std::ios::in | std::ios::binary);
|
||||
if (!inputFile.is_open())
|
||||
@@ -89,7 +89,7 @@ public:
|
||||
uint32_t dataPtr = 0x54;
|
||||
uint32_t tagPtr = dataPtr + dataSize;
|
||||
|
||||
Image image;
|
||||
std::unique_ptr<Image> image(new Image);
|
||||
for (int track = 0; track < numCylinders; track++)
|
||||
{
|
||||
int numSectors = sectorsPerTrack(track);
|
||||
@@ -105,7 +105,7 @@ public:
|
||||
Bytes tag = br.read(12);
|
||||
tagPtr += 12;
|
||||
|
||||
const auto& sector = image.put(track, head, sectorId);
|
||||
const auto& sector = image->put(track, head, sectorId);
|
||||
sector->status = Sector::OK;
|
||||
sector->logicalTrack = sector->physicalCylinder = track;
|
||||
sector->logicalSide = sector->physicalHead = head;
|
||||
@@ -115,7 +115,7 @@ public:
|
||||
}
|
||||
}
|
||||
|
||||
image.setGeometry({
|
||||
image->setGeometry({
|
||||
.numTracks = numCylinders,
|
||||
.numSides = numHeads,
|
||||
.numSectors = 12,
|
||||
|
||||
@@ -20,7 +20,7 @@ public:
|
||||
ImageReader(config)
|
||||
{}
|
||||
|
||||
Image readImage()
|
||||
std::unique_ptr<Image> readImageImpl()
|
||||
{
|
||||
std::ifstream inputFile(_config.filename(), std::ios::in | std::ios::binary);
|
||||
if (!inputFile.is_open())
|
||||
@@ -44,7 +44,7 @@ public:
|
||||
|
||||
inputFile.seekg(headerSize);
|
||||
|
||||
Image image;
|
||||
std::unique_ptr<Image> image(new Image);
|
||||
int trackCount = 0;
|
||||
for (int track = 0; track < tracks; track++)
|
||||
{
|
||||
@@ -63,7 +63,7 @@ public:
|
||||
Bytes data(sectorSize);
|
||||
inputFile.read((char*) data.begin(), data.size());
|
||||
|
||||
const auto& sector = image.put(physicalCylinder, side, sectorId);
|
||||
const auto& sector = image->put(physicalCylinder, side, sectorId);
|
||||
sector->status = Sector::OK;
|
||||
sector->logicalTrack = track;
|
||||
sector->physicalCylinder = physicalCylinder;
|
||||
@@ -76,8 +76,8 @@ public:
|
||||
trackCount++;
|
||||
}
|
||||
|
||||
image.calculateSize();
|
||||
const Geometry& geometry = image.getGeometry();
|
||||
image->calculateSize();
|
||||
const Geometry& geometry = image->getGeometry();
|
||||
std::cout << fmt::format("FDI: read {} tracks, {} sides, {} kB total\n",
|
||||
geometry.numTracks, geometry.numSides,
|
||||
((int)inputFile.tellg() - headerSize) / 1024);
|
||||
|
||||
@@ -82,6 +82,18 @@ ImageReader::ImageReader(const ImageReaderProto& config):
|
||||
_config(config)
|
||||
{}
|
||||
|
||||
const Image& ImageReader::readImage()
|
||||
{
|
||||
preloadImage();
|
||||
return *_image;
|
||||
}
|
||||
|
||||
void ImageReader::preloadImage()
|
||||
{
|
||||
if (!_image)
|
||||
_image = readImageImpl();
|
||||
}
|
||||
|
||||
void getTrackFormat(const ImgInputOutputProto& config,
|
||||
ImgInputOutputProto::TrackdataProto& trackdata, unsigned track, unsigned side)
|
||||
{
|
||||
|
||||
@@ -1,9 +1,10 @@
|
||||
#ifndef IMAGEREADER_H
|
||||
#define IMAGEREADER_H
|
||||
|
||||
#include "image.h"
|
||||
|
||||
class ImageSpec;
|
||||
class ImageReaderProto;
|
||||
class Image;
|
||||
|
||||
class ImageReader
|
||||
{
|
||||
@@ -27,10 +28,15 @@ public:
|
||||
static std::unique_ptr<ImageReader> createFdiImageReader(const ImageReaderProto& config);
|
||||
|
||||
public:
|
||||
virtual Image readImage() = 0;
|
||||
const Image& readImage();
|
||||
void preloadImage();
|
||||
|
||||
protected:
|
||||
virtual std::unique_ptr<Image> readImageImpl() = 0;
|
||||
|
||||
protected:
|
||||
const ImageReaderProto& _config;
|
||||
std::unique_ptr<Image> _image;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
@@ -89,7 +89,7 @@ public:
|
||||
ImageReader(config)
|
||||
{}
|
||||
|
||||
Image readImage()
|
||||
std::unique_ptr<Image> readImageImpl()
|
||||
/*
|
||||
IMAGE FILE FORMAT
|
||||
The overall layout of an ImageDisk .IMD image file is:
|
||||
@@ -121,7 +121,7 @@ public:
|
||||
Bytes data;
|
||||
data.writer() += inputFile;
|
||||
ByteReader br(data);
|
||||
Image image;
|
||||
std::unique_ptr<Image> image(new Image);
|
||||
TrackHeader header = {0, 0, 0, 0, 0};
|
||||
|
||||
unsigned n = 0;
|
||||
@@ -192,7 +192,7 @@ public:
|
||||
for (int s = 0; s < header.numSectors; s++)
|
||||
{
|
||||
Bytes sectordata;
|
||||
const auto& sector = image.put(header.track, header.Head, sector_map[s]);
|
||||
const auto& sector = image->put(header.track, header.Head, sector_map[s]);
|
||||
//read the status of the sector
|
||||
unsigned int Status_Sector = br.read_8();
|
||||
headerPtr++;
|
||||
@@ -259,7 +259,7 @@ public:
|
||||
}
|
||||
//Write format detected in IMD image to screen to help user set the right write parameters
|
||||
|
||||
image.setGeometry({
|
||||
image->setGeometry({
|
||||
.numTracks = header.track,
|
||||
.numSides = header.Head + 1U,
|
||||
.numSectors = header.numSectors,
|
||||
|
||||
@@ -17,7 +17,7 @@ public:
|
||||
ImageReader(config)
|
||||
{}
|
||||
|
||||
Image readImage()
|
||||
std::unique_ptr<Image> readImageImpl()
|
||||
{
|
||||
std::ifstream inputFile(_config.filename(), std::ios::in | std::ios::binary);
|
||||
if (!inputFile.is_open())
|
||||
@@ -26,7 +26,7 @@ public:
|
||||
if (!_config.img().tracks() || !_config.img().sides())
|
||||
Error() << "IMG: bad configuration; did you remember to set the tracks, sides and trackdata fields?";
|
||||
|
||||
Image image;
|
||||
std::unique_ptr<Image> image(new Image);
|
||||
int trackCount = 0;
|
||||
for (int track = 0; track < _config.img().tracks(); track++)
|
||||
{
|
||||
@@ -44,7 +44,7 @@ public:
|
||||
Bytes data(trackdata.sector_size());
|
||||
inputFile.read((char*) data.begin(), data.size());
|
||||
|
||||
const auto& sector = image.put(physicalCylinder, side, sectorId);
|
||||
const auto& sector = image->put(physicalCylinder, side, sectorId);
|
||||
sector->status = Sector::OK;
|
||||
sector->logicalTrack = track;
|
||||
sector->physicalCylinder = physicalCylinder;
|
||||
@@ -57,8 +57,8 @@ public:
|
||||
trackCount++;
|
||||
}
|
||||
|
||||
image.calculateSize();
|
||||
const Geometry& geometry = image.getGeometry();
|
||||
image->calculateSize();
|
||||
const Geometry& geometry = image->getGeometry();
|
||||
std::cout << fmt::format("IMG: read {} tracks, {} sides, {} kB total\n",
|
||||
geometry.numTracks, geometry.numSides,
|
||||
inputFile.tellg() / 1024);
|
||||
|
||||
@@ -81,7 +81,7 @@ public:
|
||||
ImageReader(config)
|
||||
{}
|
||||
|
||||
Image readImage()
|
||||
std::unique_ptr<Image> readImageImpl()
|
||||
{
|
||||
std::ifstream inputFile(_config.filename(), std::ios::in | std::ios::binary);
|
||||
if (!inputFile.is_open())
|
||||
@@ -90,7 +90,7 @@ public:
|
||||
inputFile.seekg( 0, std::ios::end);
|
||||
unsigned inputFileSize = inputFile.tellg();
|
||||
unsigned headerPtr = 0;
|
||||
Image image;
|
||||
std::unique_ptr<Image> image(new Image);
|
||||
for (;;)
|
||||
{
|
||||
unsigned dataPtr = headerPtr + 2901*3 + 1;
|
||||
@@ -110,7 +110,7 @@ public:
|
||||
inputFile.read((char*) data.begin(), sectorSize);
|
||||
|
||||
unsigned head = !!(header.flags & JV3_SIDE);
|
||||
const auto& sector = image.put(header.track, head, header.sector);
|
||||
const auto& sector = image->put(header.track, head, header.sector);
|
||||
sector->status = Sector::OK;
|
||||
sector->logicalTrack = sector->physicalCylinder = header.track;
|
||||
sector->logicalSide = sector->physicalHead = head;
|
||||
@@ -127,7 +127,7 @@ public:
|
||||
headerPtr = dataPtr;
|
||||
}
|
||||
|
||||
image.calculateSize();
|
||||
image->calculateSize();
|
||||
return image;
|
||||
}
|
||||
};
|
||||
|
||||
@@ -18,7 +18,7 @@ public:
|
||||
ImageReader(config)
|
||||
{}
|
||||
|
||||
Image readImage()
|
||||
std::unique_ptr<Image> readImageImpl()
|
||||
{
|
||||
std::ifstream inputFile(_config.filename(), std::ios::in | std::ios::binary);
|
||||
if (!inputFile.is_open())
|
||||
@@ -64,7 +64,7 @@ public:
|
||||
numCylinders * numHeads * trackSize / 1024)
|
||||
<< std::endl;
|
||||
|
||||
Image image;
|
||||
std::unique_ptr<Image> image(new Image);
|
||||
unsigned sectorFileOffset;
|
||||
|
||||
for (unsigned head = 0; head < numHeads; head++)
|
||||
@@ -87,7 +87,7 @@ public:
|
||||
Bytes data(sectorSize);
|
||||
inputFile.read((char*) data.begin(), sectorSize);
|
||||
|
||||
const auto& sector = image.put(track, head, sectorId);
|
||||
const auto& sector = image->put(track, head, sectorId);
|
||||
sector->status = Sector::OK;
|
||||
sector->logicalTrack = sector->physicalCylinder = track;
|
||||
sector->logicalSide = sector->physicalHead = head;
|
||||
@@ -97,7 +97,7 @@ public:
|
||||
}
|
||||
}
|
||||
|
||||
image.setGeometry({
|
||||
image->setGeometry({
|
||||
.numTracks = numCylinders,
|
||||
.numSides = numHeads,
|
||||
.numSectors = numSectors,
|
||||
|
||||
@@ -50,7 +50,7 @@ public:
|
||||
ImageReader(config)
|
||||
{}
|
||||
|
||||
Image readImage()
|
||||
std::unique_ptr<Image> readImageImpl()
|
||||
{
|
||||
std::ifstream inputFile(_config.filename(), std::ios::in | std::ios::binary);
|
||||
if (!inputFile.is_open())
|
||||
@@ -97,7 +97,7 @@ public:
|
||||
version / 10, version % 10, comment);
|
||||
|
||||
unsigned totalSize = 0;
|
||||
Image image;
|
||||
std::unique_ptr<Image> image(new Image);
|
||||
for (;;)
|
||||
{
|
||||
/* Read track header */
|
||||
@@ -177,7 +177,7 @@ public:
|
||||
}
|
||||
}
|
||||
|
||||
const auto& sector = image.put(logicalTrack, logicalSide, sectorId);
|
||||
const auto& sector = image->put(logicalTrack, logicalSide, sectorId);
|
||||
sector->status = Sector::OK;
|
||||
sector->physicalCylinder = physicalCylinder;
|
||||
sector->physicalHead = physicalHead;
|
||||
@@ -186,8 +186,8 @@ public:
|
||||
}
|
||||
}
|
||||
|
||||
image.calculateSize();
|
||||
const Geometry& geometry = image.getGeometry();
|
||||
image->calculateSize();
|
||||
const Geometry& geometry = image->getGeometry();
|
||||
std::cout << fmt::format("TD0: found {} tracks, {} sides, {} sectors, {} bytes per sector, {} kB total\n",
|
||||
geometry.numTracks, geometry.numSides, geometry.numSectors,
|
||||
geometry.sectorSize,
|
||||
|
||||
@@ -62,6 +62,8 @@ int mainWrite(int argc, const char* argv[])
|
||||
flags.parseFlagsWithConfigFiles(argc, argv, formats);
|
||||
|
||||
std::unique_ptr<ImageReader> reader(ImageReader::create(config.image_reader()));
|
||||
reader->preloadImage();
|
||||
|
||||
std::unique_ptr<AbstractEncoder> encoder(AbstractEncoder::create(config.encoder()));
|
||||
std::unique_ptr<FluxSink> fluxSink(FluxSink::create(config.flux_sink()));
|
||||
|
||||
|
||||
Reference in New Issue
Block a user