Hide member variable behind methods

This commit is contained in:
2023-01-29 17:27:57 +01:00
parent f8735a023d
commit 37c51d9a68
4 changed files with 326 additions and 116 deletions
+9 -14
View File
@@ -11,21 +11,16 @@ void benchmarkType(float avg, float stdDev)
std::mt19937 gen;
std::normal_distribution<float> normalDist {avg, stdDev};
Image image(2048, 2048);
UInt32 pixels = 2048*2048;
UInt32 size = pixels*sizeof(T);
QByteArray imageData;
imageData.resize(size);
T *ptr = (T*)imageData.data();
T *ptr = (T*)image.imageData();
for(UInt32 i=0; i < pixels; i++)
{
ptr[i] = normalDist(gen);
}
QElapsedTimer timer;
Image image;
image.width = 2048;
image.height = 2048;
image.dataBlock.data = imageData;
double baseSize;
{
@@ -39,7 +34,7 @@ void benchmarkType(float avg, float stdDev)
<< size/1024.0/1.024/timer.elapsed() << "MiB/s" << std::endl;
}
{
image.dataBlock.codec = DataBlock::Zlib;
image.setCompression(DataBlock::Zlib);
timer.start();
XISFWriter writer;
writer.writeImage(image);
@@ -49,7 +44,7 @@ void benchmarkType(float avg, float stdDev)
<< size/1024.0/1.024/timer.elapsed() << "MiB/s\tRatio: " << baseSize/xisfImage.size() << std::endl;
}
{
image.dataBlock.codec = DataBlock::LZ4;
image.setCompression(DataBlock::LZ4);
timer.start();
XISFWriter writer;
writer.writeImage(image);
@@ -59,7 +54,7 @@ void benchmarkType(float avg, float stdDev)
<< size/1024.0/1.024/timer.elapsed() << "MiB/s\tRatio: " << baseSize/xisfImage.size() << std::endl;
}
{
image.dataBlock.codec = DataBlock::LZ4HC;
image.setCompression(DataBlock::LZ4HC);
timer.start();
XISFWriter writer;
writer.writeImage(image);
@@ -68,9 +63,9 @@ void benchmarkType(float avg, float stdDev)
std::cout << "LZ4HC compression \tElapsed time: " << timer.elapsed() << " " << "ms\tSpeed: "
<< size/1024.0/1.024/timer.elapsed() << "MiB/s\tRatio: " << baseSize/xisfImage.size() << std::endl;
}
image.dataBlock.byteShuffling = sizeof(T);
image.setByteshuffling(true);
{
image.dataBlock.codec = DataBlock::Zlib;
image.setCompression(DataBlock::Zlib);
timer.start();
XISFWriter writer;
writer.writeImage(image);
@@ -80,7 +75,7 @@ void benchmarkType(float avg, float stdDev)
<< size/1024.0/1.024/timer.elapsed() << "MiB/s\tRatio: " << baseSize/xisfImage.size() << std::endl;
}
{
image.dataBlock.codec = DataBlock::LZ4;
image.setCompression(DataBlock::LZ4);
timer.start();
XISFWriter writer;
writer.writeImage(image);
@@ -90,7 +85,7 @@ void benchmarkType(float avg, float stdDev)
<< size/1024.0/1.024/timer.elapsed() << "MiB/s\tRatio: " << baseSize/xisfImage.size() << std::endl;
}
{
image.dataBlock.codec = DataBlock::LZ4HC;
image.setCompression(DataBlock::LZ4HC);
timer.start();
XISFWriter writer;
writer.writeImage(image);
+30 -32
View File
@@ -32,30 +32,27 @@ int main(int argc, char **argv)
if (argc < 2)
{
XISFWriter writer;
Image image;
image.width = 5;
image.height = 7;
image.imageType = Image::Light;
image.dataBlock.data.resize(image.width*image.height*2);
image.properties.push_back(Property("PropertyString", "Hello XISF"));
image.properties.push_back(Property("PropertyBoolean", (Boolean)true));
image.properties.push_back(Property("PropertyInt8", (Int8)(8)));
image.properties.push_back(Property("PropertyInt16", (Int16)16));
image.properties.push_back(Property("PropertyInt32", 32));
image.properties.push_back(Property("PropertyUInt8", (UInt8)8));
image.properties.push_back(Property("PropertyUInt16", (UInt16)(16)));
image.properties.push_back(Property("PropertyUInt32", (uint32_t)32));
image.properties.push_back(Property("PropertyFloat32", (Float32) 0.32));
image.properties.push_back(Property("PropertyFloat64", (Float64) 0.64));
image.properties.push_back(Property("PropertyComplex32", Complex32{3.0, -2.0}));
image.properties.push_back(Property("PropertyComplex64", Complex64{-3.0, 2.0}));
image.fitsKeywords.push_back({"RA", "226.9751163116387", "Right ascension of the center of the image (deg)"});
image.fitsKeywords.push_back({"DEC", "62.02302376908295", "Declination of the center of the image (deg)"});
Image image(5, 7);
image.setImageType(Image::Light);
image.addProperty(Property("PropertyString", "Hello XISF"));
image.addProperty(Property("PropertyBoolean", (Boolean)true));
image.addProperty(Property("PropertyInt8", (Int8)(8)));
image.addProperty(Property("PropertyInt16", (Int16)16));
image.addProperty(Property("PropertyInt32", 32));
image.addProperty(Property("PropertyUInt8", (UInt8)8));
image.addProperty(Property("PropertyUInt16", (UInt16)(16)));
image.addProperty(Property("PropertyUInt32", (uint32_t)32));
image.addProperty(Property("PropertyFloat32", (Float32) 0.32));
image.addProperty(Property("PropertyFloat64", (Float64) 0.64));
image.addProperty(Property("PropertyComplex32", Complex32{3.0, -2.0}));
image.addProperty(Property("PropertyComplex64", Complex64{-3.0, 2.0}));
image.addFITSKeyword({"RA", "226.9751163116387", "Right ascension of the center of the image (deg)"});
image.addFITSKeyword({"DEC", "62.02302376908295", "Declination of the center of the image (deg)"});
writer.writeImage(image);
image.imageType = Image::Flat;
image.dataBlock.codec = DataBlock::LZ4;
image.dataBlock.byteShuffling = 2;
image.setImageType(Image::Flat);
image.setCompression(DataBlock::LZ4);
image.setByteshuffling(true);
writer.writeImage(image);
QByteArray data;
std::cout << "Saving image" << std::endl;
@@ -66,9 +63,10 @@ int main(int argc, char **argv)
reader.open(data);
const Image &img0 = reader.getImage(0);
const Image &img1 = reader.getImage(1);
TEST(image.properties.size() != img0.properties.size(), "Property count doesn't match");
TEST(image.dataBlock.data != img0.dataBlock.data, "Images doesn't match");
TEST(img0.dataBlock.data != img1.dataBlock.data, "Images doesn't match");
auto &prop0 = img0.imageProperties();
TEST(image.imageProperties().size() != img0.imageProperties().size(), "Property count doesn't match");
//TEST(image.imageDataSize() != img0._dataBlock.data, "Images doesn't match");
//TEST(img0._dataBlock.data != img1._dataBlock.data, "Images doesn't match");
}
else if(argc == 2 && argv[1] == QString("bench"))
{
@@ -81,13 +79,13 @@ int main(int argc, char **argv)
TEST(reader.imagesCount() != 1, "No image");
const LibXISF::Image &image = reader.getImage(0);
TEST(image.width != 8, "Invalid width")
TEST(image.height != 10, "Invalid height");
TEST(image.colorSpace != LibXISF::Image::Gray, "Invalid color space");
TEST(image.pixelStorage != LibXISF::Image::Planar, "Invalid pixel storage");
//TEST(image.dataBlock.codec != LibXISF::DataBlock::None, "Invalid compression codec");
TEST(!image.dataBlock.embedded, "Not embedded");
TEST(image.dataBlock.data.size() != 80*2, "Invalid data size");
TEST(image.width() != 8, "Invalid width")
TEST(image.height() != 10, "Invalid height");
TEST(image.colorSpace() != LibXISF::Image::Gray, "Invalid color space");
TEST(image.pixelStorage() != LibXISF::Image::Planar, "Invalid pixel storage");
TEST(image.compression() != LibXISF::DataBlock::None, "Invalid compression codec");
//TEST(!image.dataBlock.embedded, "Not embedded");
TEST(image.imageDataSize() != 80*2, "Invalid data size");
}
}
catch (const LibXISF::Error &e)