Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

OS agnostic #8

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ target_include_directories(${PROJECT_NAME} PUBLIC

# Link directories
link_directories(
${CMAKE_CURRENT_SOURCE_DIR}/lib # Default library directory
${CMAKE_BINARY_DIR}/lib # Modified library directory
${LIBTIFF_LIB_DIR} # Library directory for libtiff
)

Expand Down
5 changes: 4 additions & 1 deletion README.MD
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
## aseedb fork
introduces the possibility to compile under linux and macOS in addition to windows.

Eer File Format
===============

Expand All @@ -15,4 +18,4 @@ How To Build the example TestEerReader

3. Open the solution in Visual Studio and build the solution. This will create a .lib for the source code (in Build/lib/Debug) and an .exe for the test example (in Build/Debug).

4. To run the TestEerReader.exe use the --help or -h argument on command line to understand what arguments the test needs.
4. To run the TestEerReader.exe use the --help or -h argument on command line to understand what arguments the test needs.
10 changes: 6 additions & 4 deletions Test/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
project(TestEerReader)

set (CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR})
if(WIN32)
set (PROJECT_LINK_LIBS EERReaderLib.lib libtiff_static.lib)
else()
set (PROJECT_LINK_LIBS libEERReaderLib.a libtiff.a)
endif()

link_directories(${CMAKE_CURRENT_SOURCE_DIR}/../build/lib ${LIBTIFF_LIB_DIR})
set (PROJECT_LINK_LIBS EERReaderLib.lib libtiff_static.lib)
include_directories(${LIBTIFF_INCLUDE_DIR})
include_directories(${LIBTIFF_INCLUDE_DIR})

# Target definition
add_executable(TestEerReader TestEerReader.cpp)
Expand Down
50 changes: 50 additions & 0 deletions Test/TestEerReader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,25 @@ void SetTag(std::shared_ptr<TIFF> tiffFile, uint32_t tag, T value)
TIFFSetField(tiffFile.get(), tag, value);
}

#ifdef _WIN32
std::shared_ptr<TIFF> OpenFile(const std::wstring &filepath) {
auto tiffFile = TIFFOpenW(filepath.c_str(), "w");
if (tiffFile == nullptr) {
throw std::runtime_error("Could not write file");
}
return std::shared_ptr<TIFF>(tiffFile, [](TIFF *f) { TIFFClose(f); });
}
#else
std::shared_ptr<TIFF> OpenFile(const std::string &filepath) {
auto tiffFile = TIFFOpen(filepath.c_str(), "w");
if (tiffFile == nullptr) {
throw std::runtime_error("Could not write file");
}
return std::shared_ptr<TIFF>(tiffFile, [](TIFF *f) { TIFFClose(f); });
}
#endif

#ifdef _WIN32
void SaveTiff(const std::wstring &filepath, uint32_t width, uint32_t height,
std::vector<uint8_t> decompressedImage) {
auto tiffFile = OpenFile(filepath);
Expand All @@ -45,22 +56,56 @@ void SaveTiff(const std::wstring &filepath, uint32_t width, uint32_t height,
// http://www.libtiff.org/man/TIFFWriteDirectory.3t.html
TIFFWriteDirectory(tiffFile.get());
}
#else
void SaveTiff(const std::string &filepath, uint32_t width, uint32_t height,
std::vector<uint8_t> decompressedImage) {
auto tiffFile = OpenFile(filepath);

SetTag<uint32_t>(tiffFile, TIFFTAG_IMAGEWIDTH, width);
SetTag<uint32_t>(tiffFile, TIFFTAG_IMAGELENGTH, height);
SetTag<uint32_t>(tiffFile, TIFFTAG_ROWSPERSTRIP, height);
SetTag<uint16_t>(tiffFile, TIFFTAG_BITSPERSAMPLE, 8);
SetTag<uint16_t>(tiffFile, TIFFTAG_SAMPLEFORMAT, SAMPLEFORMAT_UINT);

SetTag<uint16_t>(tiffFile, TIFFTAG_SAMPLESPERPIXEL, 1);
SetTag<float>(tiffFile, TIFFTAG_XRESOLUTION, 1);
SetTag<float>(tiffFile, TIFFTAG_YRESOLUTION, 1);
SetTag<uint16_t>(tiffFile, TIFFTAG_RESOLUTIONUNIT, RESUNIT_NONE);

auto bufferSize = width * height;
TIFFWriteEncodedStrip(tiffFile.get(), 0, reinterpret_cast<void *>(decompressedImage.data()),
bufferSize);

TIFFWriteDirectory(tiffFile.get());
}
#endif

int main(int argc, char* argv[]) {
std::string inputFile;
#ifdef _WIN32
std::wstring outputFile;
#else
std::string outputFile;
#endif
int upscaleFactor;

if (argc == 4) {
inputFile = argv[1];
#ifdef _WIN32
outputFile = std::wstring(argv[2], argv[2] + strlen(argv[2]));
#else
outputFile = argv[2];
#endif
upscaleFactor = std::stoi(argv[3]);
}
else if (argc == 3)
{
inputFile = argv[1];
#ifdef _WIN32
outputFile = std::wstring(argv[2], argv[2] + strlen(argv[2]));
#else
outputFile = argv[2];
#endif
upscaleFactor = 1;
}
else if (argc == 2 && (strcmp(argv[1], "--help") == 0 ||
Expand Down Expand Up @@ -99,7 +144,12 @@ int main(int argc, char* argv[]) {
std::cout << "Number of electron hits: "
<< decompressor.getNElectronsCounted() << std::endl;
std::cout << "Saving output as Tiff image ..." << std::endl;
#ifdef _WIN32
SaveTiff(outputFile + L".Tiff", width, height, eerImage);
#else
std::string str(outputFile.begin(), outputFile.end());
SaveTiff(str + ".Tiff", width, height, eerImage);
#endif

return EXIT_SUCCESS;
}
2 changes: 2 additions & 0 deletions stdafx.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@

#pragma once

#ifdef _WIN32
#include "targetver.h"
#endif

#ifndef WIN32_LEAN_AND_MEAN
#define WIN32_LEAN_AND_MEAN // Exclude rarely-used stuff from Windows headers
Expand Down
2 changes: 2 additions & 0 deletions targetver.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,6 @@
// If you wish to build your application for a previous Windows platform, include WinSDKVer.h and
// set the _WIN32_WINNT macro to the platform you wish to support before including SDKDDKVer.h.

#ifdef _WIN32
#include <SDKDDKVer.h>
#endif